{"id":25175021,"url":"https://github.com/mediafellows/chipmunk","last_synced_at":"2025-04-04T00:44:45.010Z","repository":{"id":37861303,"uuid":"252699700","full_name":"mediafellows/chipmunk","owner":"mediafellows","description":"same breed, different species.","archived":false,"fork":false,"pushed_at":"2025-03-31T13:49:26.000Z","size":317,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-31T14:54:24.072Z","etag":null,"topics":["frontend","library"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mediafellows.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-03T10:23:02.000Z","updated_at":"2025-03-31T13:49:30.000Z","dependencies_parsed_at":"2024-12-10T18:30:56.864Z","dependency_job_id":"0de777ec-dab3-4060-ba9a-adf942f64498","html_url":"https://github.com/mediafellows/chipmunk","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediafellows%2Fchipmunk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediafellows%2Fchipmunk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediafellows%2Fchipmunk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mediafellows%2Fchipmunk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mediafellows","download_url":"https://codeload.github.com/mediafellows/chipmunk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247103300,"owners_count":20884023,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["frontend","library"],"created_at":"2025-02-09T12:28:40.601Z","updated_at":"2025-04-04T00:44:44.990Z","avatar_url":"https://github.com/mediafellows.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CHIPMUNK\n\n## main goals\n\n* slim \u0026 simple compared to _chinchilla_\n* better suited for react apps\n* functional with hopefully no memory leaks\n* tested\n\n## interface\n\n### setup, run blocks (always use run blocks!)\n\n```javascript\nconst chipmunk = createChipmunk({\n  errorInterceptor: (err) =\u003e true,\n  headers: { 'Affiliation-Id': 'mpx' }\n})\n\n// to change config\nchipmunk.updateConfig({ headers: { 'Session-Id': '345dfgsdfgw43..' } })\n\nchipmunk.run(async (ch) =\u003e {\n  // requests.. e.g.\n  await ch.context('um.user')\n\n  // an error happens\n  throw new Error('foo')\n}, (err) =\u003e {\n  // error handler is optional\n  console.log(err.message) // would print 'foo'\n})\n\n```\n\n### optional configuration options\n\n*verbose mode*\n\n```javascript\nch.updateConfig({ verbose: true })\n```\n\n### contexts\n\n```javascript\n// get context\nawait ch.context('um.user')\n```\n\n### JSON schemas (mm3 models)\n\n```javascript\n// get context\nawait ch.spec('mm3:pm.product')\n```\n\n### actions\n\n#### examples\n\n```javascript\n// get user, default method\nawait ch.action('um.user', 'get', { params: { user_id: 3 } })\n\n// get mm3 product\nawait ch.action('mm3:pm.product', 'get', { params: { product_ids: 5 } })\n```\n\n```javascript\n// get user with associations resolved \u0026 limited attribute set\nawait ch.action('um.user', 'get', {\n  params: { user_id: 3 },\n  schema: `\n    id, first_name,\n    organization { name },\n  `\n})\n```\n\n```javascript\n// get user with associations resolved \u0026 limited attribute set\n// proxied through tuco (node server) -\u003e only one request, better performance\n// will throw if no schema was provided\nawait ch.action('um.user', 'get', {\n  params: { user_id: 3 },\n  proxy: true,\n  schema: `\n    id, first_name,\n    organization { name },\n  `\n})\n```\n\n```javascript\n// create new user\nawait ch.action('um.user', 'create', {\n  body: {\n    first_name: 'john',\n    last_name: 'doe',\n    ...rest,\n  }\n})\n```\n\n```javascript\n// update existing user\nawait ch.action('um.user', 'update', {\n  params: { user_id: 3 },\n  body: {\n    first_name: 'johnny',\n  }\n})\n\n// update existing users\nawait ch.action('um.user', 'update', {\n  body: [\n    { id: 3, first_name: 'johnny' },\n    { id: 5, first_name: 'hermine' },\n  ]\n})\n```\n\n#### optional action options\n\n```javascript\n// convert to Ruby on Rails compatible 'accepts nested attributes' body\nawait ch.action('um.user', 'update', {\n  params: { user_id: 3 },\n  ROR: true,\n  body: {\n    first_name: 'johnny',\n    organization: {\n      name: 'walker'\n    }\n  }\n})\n// =\u003e converts to\n// {\n//   first_name: 'johnny',\n//   organization_attributes: {\n//     name: 'walker'\n//   }\n// }\n\n// convert to 'multi' update format body (our backends support)\nawait ch.action('um.user', 'update', {\n  multi: true,\n  body: [\n    { id: 3, first_name: 'johnny' },\n    { id: 5, first_name: 'hermine' },\n  ]\n})\n// converts to:\n// {\n//   '3': { id: 3, first_name: 'johnny' },\n//   '5': { id: 5, first_name: 'hermine' },\n// }\n\n// return RAW results\n// this does not move association references nor does it support resolving a schema\nawait ch.action('um.user', 'query', {\n  raw: true,\n})\n```\n\n### cache\n\nby default, chipmunk prefixes all cache keys with\n- affiliation-id and role-id, if present\n- role-id only, if present\n- session-id only, if present\n- 'anonymous', if none of the above\n\n```javascript\n// use 'runtime' cache\nch.updateConfig({ cache: { enabled: true, engine: 'runtime' } })\n\n// use 'storage' cache\nch.updateConfig({ cache: { enabled: true, engine: 'storage' } })\n\n// EXAMPLE 1, write to cache for current user role\nch.updateConfig({ headers: { 'Role-Id': 5 }, cache: { enabled: true, engine: 'storage' } })\nch.cache.set('foo', 'bar')\nch.cache.get('foo') // =\u003e bar\n\nch.updateConfig({ headers: { 'Role-Id': 8 } })\nch.cache.get('foo') // =\u003e null\n\n// EXAMPLE 2, write to cache, ignoring session id, role or affiliation, using runtime cache\nch.updateConfig({ headers: { 'Role-Id': 5 } })\nch.cache.set('foo', 'bar', { noPrefix: true, engine: 'runtime' })\nch.cache.get('foo', { noPrefix: true, engine: 'runtime' }) // =\u003e bar\nch.cache.get('foo', { engine: 'runtime' }) // =\u003e null\n\nch.updateConfig({ headers: { 'Role-Id': 8 } })\nch.cache.get('foo', { noPrefix: true, engine: 'runtime' }) // =\u003e bar\n```\n\n### 'perform later' jobs\n\nchipmunk (as chinchilla did previously) offers convenience functionality to run second level priority code after the important stuff has been processed.\nthis allows for example to lazy load less important data after all important data has been gathered.\n\nan example:\n\n```javascript\nconst notImportant = () =\u003e {\n  console.log('this really was not that important')\n}\n\nch.performLater(notImportant)\n\nconst users = (await ch.action('um.user', 'query')).objects\nconsole.log(users)\n\n// =\u003e [user1, user2, ...]\n// =\u003e this really was not that important\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediafellows%2Fchipmunk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediafellows%2Fchipmunk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediafellows%2Fchipmunk/lists"}