@molecule/api-resource-follow 1.0.10 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-21T18:17:13.993Z
6
+ Generated: 2026-11-12T13:52:29.784Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-follow
@@ -12,6 +12,10 @@ Follow/unfollow resource for molecule.dev.
12
12
 
13
13
  Polymorphic follow system for users or any resource type. Supports
14
14
  followers list, following list, and follow status checks.
15
+ Use `getFollowedIds(viewerId, targetType, ids)` once per displayed collection, then
16
+ `followed.has(id)` for each item. It uses one query with no pagination truncation,
17
+ deduplicates ids, and does no I/O for an empty page or an absent viewer. It works for
18
+ any target type, including documents, topics and users. Use `isFollowing` for one target.
15
19
 
16
20
  > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
17
21
  > It is written to be read by coding agents as much as by people, and is generated from this
@@ -233,6 +237,28 @@ function isFollowing(followerId: string, targetType: string, targetId: string):
233
237
 
234
238
  **Returns:** `true` if following.
235
239
 
240
+ #### `getFollowedIds(followerId, targetType, targetIds)`
241
+
242
+ Load a viewer's follow state for a collection in one query, rather than one per item.
243
+
244
+ Targets are canonical ids, exactly as with `follow` and `isFollowing`. Repeated ids are
245
+ deduplicated. An absent viewer or empty collection does no I/O. There is no cross-call cache.
246
+ The result contains only followed ids from this collection, for this viewer and target type.
247
+
248
+ ```typescript
249
+ function getFollowedIds(
250
+ followerId: string | null | undefined,
251
+ targetType: string,
252
+ targetIds: readonly string[],
253
+ ): Promise<Set<string>>
254
+ ```
255
+
256
+ - `followerId` — The viewer's user id, or no viewer for public content.
257
+ - `targetType` — The resource type being followed.
258
+ - `targetIds` — Canonical ids referenced by the collection.
259
+
260
+ **Returns:** The subset of target ids this viewer follows.
261
+
236
262
  #### `getFollowerCount(targetType, targetId)`
237
263
 
238
264
  Gets the follower count for a target.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,10 @@
3
3
  *
4
4
  * Polymorphic follow system for users or any resource type. Supports
5
5
  * followers list, following list, and follow status checks.
6
+ * Use `getFollowedIds(viewerId, targetType, ids)` once per displayed collection, then
7
+ * `followed.has(id)` for each item. It uses one query with no pagination truncation,
8
+ * deduplicates ids, and does no I/O for an empty page or an absent viewer. It works for
9
+ * any target type, including documents, topics and users. Use `isFollowing` for one target.
6
10
  *
7
11
  * @module
8
12
  * @example
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -3,6 +3,10 @@
3
3
  *
4
4
  * Polymorphic follow system for users or any resource type. Supports
5
5
  * followers list, following list, and follow status checks.
6
+ * Use `getFollowedIds(viewerId, targetType, ids)` once per displayed collection, then
7
+ * `followed.has(id)` for each item. It uses one query with no pagination truncation,
8
+ * deduplicates ids, and does no I/O for an empty page or an absent viewer. It works for
9
+ * any target type, including documents, topics and users. Use `isFollowing` for one target.
6
10
  *
7
11
  * @module
8
12
  * @example
package/dist/service.d.ts CHANGED
@@ -57,6 +57,19 @@ export declare function getFollowing(userId: string, options?: PaginationOptions
57
57
  * @returns `true` if following.
58
58
  */
59
59
  export declare function isFollowing(followerId: string, targetType: string, targetId: string): Promise<boolean>;
60
+ /**
61
+ * Load a viewer's follow state for a collection in one query, rather than one per item.
62
+ *
63
+ * Targets are canonical ids, exactly as with `follow` and `isFollowing`. Repeated ids are
64
+ * deduplicated. An absent viewer or empty collection does no I/O. There is no cross-call cache.
65
+ * The result contains only followed ids from this collection, for this viewer and target type.
66
+ *
67
+ * @param followerId - The viewer's user id, or no viewer for public content.
68
+ * @param targetType - The resource type being followed.
69
+ * @param targetIds - Canonical ids referenced by the collection.
70
+ * @returns The subset of target ids this viewer follows.
71
+ */
72
+ export declare function getFollowedIds(followerId: string | null | undefined, targetType: string, targetIds: readonly string[]): Promise<Set<string>>;
60
73
  /**
61
74
  * Gets the follower count for a target.
62
75
  *
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAI5E;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,MAAM,CAC1B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,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;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAoBlC;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAiBlC;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAYtB;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK5F;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEvE"}
package/dist/service.js CHANGED
@@ -112,6 +112,32 @@ export async function isFollowing(followerId, targetType, targetId) {
112
112
  ]);
113
113
  return existing !== null;
114
114
  }
115
+ /**
116
+ * Load a viewer's follow state for a collection in one query, rather than one per item.
117
+ *
118
+ * Targets are canonical ids, exactly as with `follow` and `isFollowing`. Repeated ids are
119
+ * deduplicated. An absent viewer or empty collection does no I/O. There is no cross-call cache.
120
+ * The result contains only followed ids from this collection, for this viewer and target type.
121
+ *
122
+ * @param followerId - The viewer's user id, or no viewer for public content.
123
+ * @param targetType - The resource type being followed.
124
+ * @param targetIds - Canonical ids referenced by the collection.
125
+ * @returns The subset of target ids this viewer follows.
126
+ */
127
+ export async function getFollowedIds(followerId, targetType, targetIds) {
128
+ const ids = [...new Set(targetIds)];
129
+ if (!followerId || ids.length === 0)
130
+ return new Set();
131
+ const rows = await findMany(TABLE, {
132
+ where: [
133
+ { field: 'followerId', operator: '=', value: followerId },
134
+ { field: 'targetType', operator: '=', value: targetType },
135
+ { field: 'targetId', operator: 'in', value: ids },
136
+ ],
137
+ select: ['targetId'],
138
+ });
139
+ return new Set(rows.map((row) => row.targetId));
140
+ }
115
141
  /**
116
142
  * Gets the follower count for a target.
117
143
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-follow",
3
- "version": "1.0.10",
3
+ "version": "1.1.0",
4
4
  "description": "Follow/unfollow users or any resource with polymorphic targeting",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -40,15 +40,6 @@
40
40
  "@molecule/api-resource": "^1.0.1"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
- "@molecule/api-database": {
44
- "optional": true
45
- },
46
- "@molecule/api-i18n": {
47
- "optional": true
48
- },
49
- "@molecule/api-logger": {
50
- "optional": true
51
- },
52
43
  "@molecule/api-resource": {
53
44
  "optional": true
54
45
  }