{"_id":"@darksoil-studio/holochain-signals","name":"@darksoil-studio/holochain-signals","dist-tags":{"latest":"0.500.0"},"versions":{"0.500.0":{"name":"@darksoil-studio/holochain-signals","version":"0.500.0","description":"Holochain async-signals to build reusable holochain modules","author":{"name":"guillem.cordoba@gmail.com"},"main":"dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","repository":{"type":"git","url":"git+https://github.com/darksoil-studio/holochain-utils.git"},"exports":{".":"./dist/index.js","./dist/*":"./dist/*"},"dependencies":{"@darksoil-studio/holochain-utils":"^0.500.0","@holochain/client":"^0.19.0","@msgpack/msgpack":"^2.8.0","async-signals":"^0.1.10","lodash-es":"^4.17.21","lit-signal-watcher":"^0.1.1","signal-polyfill":"^0.1.1"},"devDependencies":{"@types/lodash-es":"^4.17.6","js-base64":"^3.7.7","typescript":"^5.4.0","vite":"^4.1.1","vitest":"^1.5.0"},"publishConfig":{"access":"public"},"type":"module","scripts":{"start":"vite --open","build":"pnpm lint && tsc","lint":"eslint src","test":"vitest run"},"_id":"@darksoil-studio/holochain-signals@0.500.0","bugs":{"url":"https://github.com/darksoil-studio/holochain-utils/issues"},"homepage":"https://github.com/darksoil-studio/holochain-utils#readme","_integrity":"sha512-qMv9lxT2Ll4boP/xoFoAgB3p6wsFA+qqGwmI0MNOpyQu3Raaw3lkOizOg9wP942gWFT2GTwiwbVl0R8IarbVlw==","_resolved":"/tmp/160f7ab8e4e15156962d997845d97150/darksoil-studio-holochain-signals-0.500.0.tgz","_from":"file:darksoil-studio-holochain-signals-0.500.0.tgz","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-qMv9lxT2Ll4boP/xoFoAgB3p6wsFA+qqGwmI0MNOpyQu3Raaw3lkOizOg9wP942gWFT2GTwiwbVl0R8IarbVlw==","shasum":"52bd8aa116b1f4a244e62337a8040684b738e471","tarball":"https://registry.npmjs.org/@darksoil-studio/holochain-signals/-/holochain-signals-0.500.0.tgz","fileCount":27,"unpackedSize":209916,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBUqcukpWPKFy/HXMgJJ9GwWoWD/8a25QnQ55/ymihsbAiBS72ZHrg2tuzSMaEXnmhjdu5fKCfflLEWLFVsmTON6Ww=="}]},"_npmUser":{"name":"guillem.cordoba","email":"guillem.cordoba@gmail.com"},"directories":{},"maintainers":[{"name":"guillem.cordoba","email":"guillem.cordoba@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/holochain-signals_0.500.0_1745402006902_0.7838739890237847"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-23T09:53:26.807Z","0.500.0":"2025-04-23T09:53:27.096Z","modified":"2025-04-23T09:53:27.397Z"},"maintainers":[{"name":"guillem.cordoba","email":"guillem.cordoba@gmail.com"}],"description":"Holochain async-signals to build reusable holochain modules","homepage":"https://github.com/darksoil-studio/holochain-utils#readme","repository":{"type":"git","url":"git+https://github.com/darksoil-studio/holochain-utils.git"},"author":{"name":"guillem.cordoba@gmail.com"},"bugs":{"url":"https://github.com/darksoil-studio/holochain-utils/issues"},"readme":"# @darksoil-studio/holochain-signals\n\nRe-export of [`signal-polyfill`](https://www.npmjs.com/package/signal-polyfill) and [`async-signals`](https://www.npmjs.com/package/async-signals), with some additional utilities targeted to build holochain apps on top of it.\n\nThese are the additional utilities added by this package:\n\n### immutableEntrySignal\n\nFetches the given entry, retrying if there is a failure.\n\nMakes requests only the first time it is watched, and will stop after it succeeds in fetching the entry.\n\nWhenever it succeeds, it caches the value so that any subsequent requests are cached.\n\nUseful for entries that can't be updated.\n\n```ts\nimport { Link } from '@holochain/client';\nimport { MemoHoloHashMap, EntryRecord } from '@darksoil-studio/holochain-utils';\nimport { AsyncSignal, immutableEntrySignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\nimport { Post } from './types.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  posts: MemoHoloHashMap<ActionHash, EntryRecord<Post>> = new MemoHoloHashMap((postHash: ActionHash) => \n    immutableEntrySignal(() => this.postsClient.getPost(postHash))\n  );\n}\n```\n\n### latestVersionOfEntrySignal\n\nKeeps an up to date copy of the latest version of an entry, making requests only while it has some watcher.\n\nWill do so by calling the given every 20 seconds calling the given fetch function, and listening to `EntryUpdated` signals.\n\nUseful for entries that can be updated.\n\n```ts\nimport { Link } from '@holochain/client';\nimport { MemoHoloHashMap, EntryRecord } from '@darksoil-studio/holochain-utils';\nimport { AsyncSignal, latestVersionOfEntrySignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\nimport { Post } from './types.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  posts: MemoHoloHashMap<ActionHash, EntryRecord<Post>> = new MemoHoloHashMap((postHash: ActionHash) => \n    latestVersionOfEntrySignal(\n      this.postsClient, // Give the client so that it can listen to the `EntryUpdated` signal\n      () => this.postsClient.getLatestPost(postHash)), // Fetch the latest version of the post\n  );\n}\n```\n\n### allRevisionsOfEntrySignal\n\nKeeps an up to date list of all the revisions for an entry, making requests only while it has some subscriber.\n\nWill do so by calling the given every 20 seconds calling the given fetch function, and listening to `EntryUpdated` signals.\n\nUseful for entries that can be updated.\n\n```ts\nimport { Link } from '@holochain/client';\nimport { MemoHoloHashMap, EntryRecord } from '@darksoil-studio/holochain-utils';\nimport { AsyncSignal, allRevisionsOfEntrySignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\nimport { Post } from './types.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  posts: MemoHoloHashMap<ActionHash, Array<EntryRecord<Post>>> = new MemoHoloHashMap((postHash: ActionHash) => \n    allRevisionsOfEntrySignal(\n      this.postsClient, // Give the client so that it can listen to the `EntryUpdated` signal\n      () => this.postsClient.getAllRevisionsForPost(postHash)), // Fetch all the revisions for the post\n  );\n}\n```\n\n### deletesForEntrySignal\n\nKeeps an up to date list of the deletes for an entry, making requests only while it has some subscriber.\n\nWill do so by calling the given every 20 seconds calling the given fetch function, and listening to `EntryDeleted` signals.\n\nUseful for entries that can be deleted.\n\n```ts\nimport { Link } from '@holochain/client';\nimport { MemoHoloHashMap, EntryRecord } from '@darksoil-studio/holochain-utils';\nimport { AsyncSignal, deletesForEntrySignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\nimport { Post } from './types.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  posts: MemoHoloHashMap<ActionHash, Array<SignedActionHashed<Delete>>> = new MemoHoloHashMap((postHash: ActionHash) => \n    deletesForEntrySignal(\n      this.postsClient, // Give the client so that it can listen to the `EntryDeleted` signal\n      postHash, // Hash of the original `Create` action\n      () => this.postsClient.getAllDeletesForPost(postHash)), // Fetch all the delete actions for the post\n  );\n}\n```\n\n\n### collectionSignal\n\nKeeps an up to date list of the targets for the non-deleted links for the given collection in this DHT, making requests only while it has some subscriber.\n\nWill do so by calling the given every 20 seconds calling the given fetch function, and listening to `LinkCreated` and `LinkDeleted` signals.\n\nUseful for collections\n\n```ts\nimport { Link } from '@holochain/client';\nimport { AsyncSignal, collectionSignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  allPostsSignal: AsyncSignal<Array<Link>> = collectionSignal(\n    this.postsClient,\n    async () => this.postsClient.getAllPosts(), // Request to fetch the initial list of posts\n    \"AllPosts\", // Link type for the collection\n  );\n}\n```\n\n### liveLinksSignal\n\nKeeps an up to date list of the links for the non-deleted links in this DHT, making requests only while it has some subscriber.\n\nWill do so by calling the given fetch callback every 20 seconds, and listening to `LinkCreated` and `LinkDeleted` signals.\n\nUseful for link types.\n\n```ts\nimport { Link } from '@holochain/client';\nimport { AsyncSignal, collectionSignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  myPostsSignal: AsyncSignal<Array<Link>> = liveLinksSignal(\n    this.postsClient,\n    this.postsClient.client.myPubKey, // Base address for the links\n    () => this.postsClient.getMyPosts(), // Fetch the live links\n    'AuthorToPosts', // Link type\n  );\n}\n```\n\n### deletedLinksSignal\n\nKeeps an up to date list of the targets for the deleted links in this DHT, making requests only while it has some subscriber.\n\nWill do so by calling the given every 20 seconds calling the given fetch function, and listening to `LinkDeleted` signals.\n\nUseful for link types and collections with some form of archive retrieving functionality\n\n```ts\nimport { Link } from '@holochain/client';\nimport { AsyncSignal, collectionSignal } from '@darksoil-studio/holochain-signals';\n\nimport { PostsClient } from './posts-client.js';\n\nexport class PostsStore {\n\n  constructor(public postsClient: PostsClient) {}\n\n  myDeletedPostsSignal: AsyncSignal<Array<[SignedActionHashed<CreateLink>, Array<SignedActionHashed<DeleteLink>>]>> = deletedLinksSignal(\n    this.postsClient,\n    this.postsClient.client.myPubKey, // Base address for the links\n    () => this.postsClient.getMyDeletedPosts(), // Fetch the deleted links \n    'AuthorToPosts', // Link type\n  );\n}\n```\n","readmeFilename":"README.md","_rev":"1-751e2283f38a068c5794baf36e58f3d0"}