{"id":17458124,"url":"https://github.com/pocesar/js-async-atomic-store","last_synced_at":"2026-04-26T23:31:56.394Z","repository":{"id":57185465,"uuid":"236268606","full_name":"pocesar/js-async-atomic-store","owner":"pocesar","description":"An agnostic little store abstraction for reading, writing and appending on the same data from multiple sources in a locking manner, that allows concurrent/parallel (like from many async sources) write, append and read.","archived":false,"fork":false,"pushed_at":"2020-02-08T21:49:00.000Z","size":111,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-09T01:44:43.907Z","etag":null,"topics":["agnostic","array","async","async-sources","asynchronous","atomic","javascript","lock","map","object","parallel","race-conditions","read","storage","typescript","write"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pocesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-26T04:54:31.000Z","updated_at":"2024-01-08T21:18:42.000Z","dependencies_parsed_at":"2022-09-06T04:02:19.306Z","dependency_job_id":null,"html_url":"https://github.com/pocesar/js-async-atomic-store","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pocesar/js-async-atomic-store","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fjs-async-atomic-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fjs-async-atomic-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fjs-async-atomic-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fjs-async-atomic-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pocesar","download_url":"https://codeload.github.com/pocesar/js-async-atomic-store/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fjs-async-atomic-store/sbom","scorecard":{"id":739298,"data":{"date":"2025-08-11","repo":{"name":"github.com/pocesar/js-async-atomic-store","commit":"eff954fd6cab3c00449c7802be8acf9bc26c4069"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/8 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T16:55:57.227Z","repository_id":57185465,"created_at":"2025-08-22T16:55:57.227Z","updated_at":"2025-08-22T16:55:57.227Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32317163,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"ssl_error","status_checked_at":"2026-04-26T23:26:25.802Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["agnostic","array","async","async-sources","asynchronous","atomic","javascript","lock","map","object","parallel","race-conditions","read","storage","typescript","write"],"created_at":"2024-10-18T03:54:58.103Z","updated_at":"2026-04-26T23:31:56.372Z","avatar_url":"https://github.com/pocesar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM](https://img.shields.io/npm/l/async-atomic-store)](https://www.npmjs.com/package/async-atomic-store)\n[![npm](https://img.shields.io/npm/v/async-atomic-store)](https://www.npmjs.com/package/async-atomic-store)\n[![npm](https://img.shields.io/npm/types/async-atomic-store)](https://www.npmjs.com/package/async-atomic-store)\n[![Travis (.org)](https://img.shields.io/travis/pocesar/js-async-atomic-store)](https://travis-ci.org/pocesar/js-async-atomic-store)\n[![Coverage Status](https://coveralls.io/repos/github/pocesar/js-async-atomic-store/badge.svg?branch=master)](https://coveralls.io/github/pocesar/js-async-atomic-store?branch=master)\n\n# async-atomic-store\n\nAn agnostic little store abstraction for reading, writing and appending on the same data from multiple sources in a locking manner, that allows concurrent/parallel (like from many async sources) write, append and read.\n\n## API\n\nThe interface is simple, you provide your `read`, `write` and `data` methods, and it outputs an async-locking `write`, `read`, `append`, `lock` and `data` methods.\n\nAll those methods are async (return a promise), even if they have non-async data underneath, because of the async locking mechanism, which is similar to a `LOCK TABLE` and not `LOCK ROW`. This does not use loops or saturate the event loop.\n\nIf any method `throw`, the lock will be released and no changes are made.\n\n```ts\nconst store = AsyncAtomicStore\u003cKEY_OR_ID, TYPE_OR_SHAPE_OF_VALUE, TYPE_OF_STORAGE\u003e({\n  data: async () =\u003e { /* your underlying data */ },\n  read: async (key) =\u003e { /* query a database, read from your datasource */ },\n  write: async (key, value) =\u003e { /* writes in a atomic locking manner */ }\n});\n\n// guaranteed to return that point-in-time value\nconst value = await store.read(\"id\");\n\n// at this exact point, \"id\" will be \"my value\"\nawait store.write(\"id\", \"my value\");\n\n// passes the current value to the callback, modify it then write at the same key.\n// transformedValue = \"my value + my value\"\nconst transformedValue = await store.append(\"id\", async (currentValue) =\u003e {\n  return `${currentValue} + ${currentValue}`;\n});\n\n// locks everything, passes the current point-in-time datasource, and return an arbitrary value.\n// This exists for everything that isn't covered by the other \"keyed\" methods, but you need to\n// do some async work before returning a value\n// value = \"ok\"\nconst value = await store.lock(async (datasource) =\u003e {\n  datasource[42] = \"the answer\";\n  return \"ok\";\n});\n```\n\nProvides the following type-safe adapters for your data:\n\n### AsyncArray\n\n```ts\nimport { AsyncArray } from 'async-atomic-store'\n\nconst myArray = [];\nconst store = AsyncArray(myArray);\nawait store.write(0, \"ok\");\nawait store.lock(async (arr) =\u003e {\n  arr.push(\"item\"); // there's no other way to manipulate an array other than using lock()\n});\n\nmyArray[0] === \"ok\";\nmyArray[1] === \"item\";\n```\n\n### AsyncMap\n\n```ts\nimport { AsyncMap } from 'async-atomic-store'\n\nconst myMap = new Map\u003cstring, string\u003e();\nconst store = AsyncMap(myMap);\nawait store.write(\"str\", \"ing\");\n\nmyMap.get(\"str\") === \"ing\";\n```\n\n### AsyncObject\n\n```ts\nimport { AsyncObject } from 'async-atomic-store'\n\nconst myObj = Object.create(null);\nconst store = AsyncObject(myObj);\nawait store.lock(async (obj) =\u003e {\n  obj.goCrazy = {\n    with: {\n      it: true\n    }\n  }\n});\n\nmyObj.goCrazy.with.it === true;\n```\n\n## Examples\n\nExplicit implementations of different data sources\n\nUsing `Map`\n\n```ts\nimport { AsyncAtomicStore } from 'async-atomic-store'\n\nconst lockingMap = () =\u003e {\n  const map = new Map\u003cnumber, DeepObject\u003e()\n\n  return AsyncAtomicStore\u003cnumber, DeepObject | undefined, typeof map\u003e({\n    data: async () =\u003e map,\n    read: async (key) =\u003e map.get(key),\n    write: async (key, value) =\u003e map.set(key, value!)\n  })\n}\n\nconst store = lockingMap()\n\nfor (let i = 0; i \u003c 10; i++) {\n  // don't await\n  setTimeout(() =\u003e {\n    store.append(1, (value) =\u003e {\n      return {\n        ...value,\n        deep: {\n          object: {\n            1: (value ? value.deep.object[1] : 0) + i\n            // the first lock will initialize the value to 0\n            // all subsequent writes will use the current value,\n          }\n        }\n      }\n    })\n  }, Math.round(Math.random() * 2))\n}\n\nassert(\n  (await store.data()).get(1)!.deep.object[1] === 45,\n  'Object value should always be 45'\n)\n```\n\nUsing `Set`:\n\n```ts\nconst setStore = () =\u003e {\n  const set = new Set\u003cstring\u003e()\n\n  return AsyncAtomicStore\u003cnumber, string | undefined, string[]\u003e({\n    read: async (index) =\u003e index ? [...set.values()][index] : undefined,\n    write: async (index, value) =\u003e {\n      const kvs = [...set.values()]\n      set.clear() // set needs to be recreated each time\n      kvs[index] = value!\n      kvs.forEach((v) =\u003e set.add(v))\n      await sleep(2)\n    },\n    data: async () =\u003e [...set.values()]\n  })\n}\n\nconst store = setStore()\n\nawait Promise.all([\n  store.write(0, '0'),\n  store.write(1, '5'),\n  store.write(1, '1'),\n  store.write(2, '7'),\n  store.write(2, '2'),\n  store.write(3, '3'),\n])\n\nconst data = await store.data()\n\nassert(\n  data.join('') === '0123',\n  'set should be exactly 0123'\n)\n```\n\nRedundantly using `Atomics` and `SharedArrayBuffer`:\n\n```ts\nimport { AsyncAtomicStore } from 'async-atomic-store'\n\nconst uint8Array = () =\u003e {\n  const buffer = new SharedArrayBuffer(16)\n  const uint8 = new Uint8Array(buffer)\n\n  return AsyncAtomicStore\u003cnumber, number, Uint8Array\u003e({\n    read: async (index) =\u003e Atomics.load(uint8, index),\n    write: async (index, value) =\u003e Atomics.store(uint8, index, value),\n    data: async () =\u003e uint8\n  })\n}\n\nconst store = uint8Array()\n\nfor (let i = 0; i \u003c 16; i++) {\n  setTimeout(async () =\u003e {\n    store.append(1, (currentValue) =\u003e {\n      return currentValue + i\n    })\n  }, Math.round(Math.random() * 2))\n}\n\nstore.append(1, (currentValue) =\u003e currentValue + 1)\n\nconst currentData = await store.data()\n\nassert(\n  currentData[1] === 121,\n  'Index 1 should be 121'\n)\n```\n\n## License\n\nMIT\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocesar%2Fjs-async-atomic-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpocesar%2Fjs-async-atomic-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocesar%2Fjs-async-atomic-store/lists"}