@molecule/api-resource-article 1.0.4 → 1.0.6

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-16T01:58:33.609Z
6
+ Generated: 2026-10-16T11:26:11.412Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-article
@@ -613,11 +613,20 @@ Peer dependencies:
613
613
  - `@molecule/api-slug`
614
614
  - `zod`
615
615
 
616
- - **Migration required.** `src/__setup__/articles.sql` creates `articles` and
617
- `article_tags`; the reaction and follow packages bring `reactions` and
618
- `follows`. Scaffolded apps apply all of them on boot.
619
- `src/__setup__/articles_position.sql` adds `article_tags.position` to a
620
- database whose table predates the column.
616
+ - **Migration required: this package ships every table it reads, four in
617
+ all.** `articles.sql` creates the `articles` and `article_tags` tables;
618
+ `articles_position.sql` adds the `position` column to a database whose
619
+ `article_tags` predates it; `reactions.sql` and `follows.sql` create the
620
+ `reactions` and `follows` tables, which this package reads directly by name
621
+ on every response (favorites) and on its feed (who a reader follows). Those
622
+ last two are copies of `@molecule/api-resource-reaction`'s and
623
+ `@molecule/api-resource-follow`'s own setup files, statement for statement,
624
+ and each creates its table only if it is not there yet, so an app that also
625
+ installs those packages runs both copies harmlessly. A scaffold copies the
626
+ tables a package's registry entry declares, and this one declares all four,
627
+ so a project that installs only this package gets every table its endpoints
628
+ need. Applying `articles.sql` alone leaves every article response failing
629
+ with `no such table: reactions`.
621
630
  - **`article_tags` keeps the order the tags were given in**, in its `position`
622
631
  column (0-based). An app that reads the join table itself must order by
623
632
  `position` — a submission-order assertion (`tagList[0]`, `tagList[1]`) reads
package/dist/index.d.ts CHANGED
@@ -41,11 +41,20 @@
41
41
  * ```
42
42
  *
43
43
  * @remarks
44
- * - **Migration required.** `src/__setup__/articles.sql` creates `articles` and
45
- * `article_tags`; the reaction and follow packages bring `reactions` and
46
- * `follows`. Scaffolded apps apply all of them on boot.
47
- * `src/__setup__/articles_position.sql` adds `article_tags.position` to a
48
- * database whose table predates the column.
44
+ * - **Migration required: this package ships every table it reads, four in
45
+ * all.** `articles.sql` creates the `articles` and `article_tags` tables;
46
+ * `articles_position.sql` adds the `position` column to a database whose
47
+ * `article_tags` predates it; `reactions.sql` and `follows.sql` create the
48
+ * `reactions` and `follows` tables, which this package reads directly by name
49
+ * on every response (favorites) and on its feed (who a reader follows). Those
50
+ * last two are copies of `@molecule/api-resource-reaction`'s and
51
+ * `@molecule/api-resource-follow`'s own setup files, statement for statement,
52
+ * and each creates its table only if it is not there yet, so an app that also
53
+ * installs those packages runs both copies harmlessly. A scaffold copies the
54
+ * tables a package's registry entry declares, and this one declares all four,
55
+ * so a project that installs only this package gets every table its endpoints
56
+ * need. Applying `articles.sql` alone leaves every article response failing
57
+ * with `no such table: reactions`.
49
58
  * - **`article_tags` keeps the order the tags were given in**, in its `position`
50
59
  * column (0-based). An app that reads the join table itself must order by
51
60
  * `position` — a submission-order assertion (`tagList[0]`, `tagList[1]`) reads
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;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;AAC1B,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;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;AAC1B,cAAc,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -41,11 +41,20 @@
41
41
  * ```
42
42
  *
43
43
  * @remarks
44
- * - **Migration required.** `src/__setup__/articles.sql` creates `articles` and
45
- * `article_tags`; the reaction and follow packages bring `reactions` and
46
- * `follows`. Scaffolded apps apply all of them on boot.
47
- * `src/__setup__/articles_position.sql` adds `article_tags.position` to a
48
- * database whose table predates the column.
44
+ * - **Migration required: this package ships every table it reads, four in
45
+ * all.** `articles.sql` creates the `articles` and `article_tags` tables;
46
+ * `articles_position.sql` adds the `position` column to a database whose
47
+ * `article_tags` predates it; `reactions.sql` and `follows.sql` create the
48
+ * `reactions` and `follows` tables, which this package reads directly by name
49
+ * on every response (favorites) and on its feed (who a reader follows). Those
50
+ * last two are copies of `@molecule/api-resource-reaction`'s and
51
+ * `@molecule/api-resource-follow`'s own setup files, statement for statement,
52
+ * and each creates its table only if it is not there yet, so an app that also
53
+ * installs those packages runs both copies harmlessly. A scaffold copies the
54
+ * tables a package's registry entry declares, and this one declares all four,
55
+ * so a project that installs only this package gets every table its endpoints
56
+ * need. Applying `articles.sql` alone leaves every article response failing
57
+ * with `no such table: reactions`.
49
58
  * - **`article_tags` keeps the order the tags were given in**, in its `position`
50
59
  * column (0-based). An app that reads the join table itself must order by
51
60
  * `position` — a submission-order assertion (`tagList[0]`, `tagList[1]`) reads
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.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AC,OAAO,CAAC,CAAC,CAkBhC;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAW7F;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAOzB;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAYjE"}
package/dist/service.js CHANGED
@@ -46,6 +46,18 @@ const nextCreatedAt = () => {
46
46
  lastCreatedMs = Math.max(Date.now(), lastCreatedMs + 1);
47
47
  return new Date(lastCreatedMs).toISOString();
48
48
  };
49
+ /**
50
+ * An update time strictly later than the row's last one: an edit in the same
51
+ * millisecond (or the same second, on a store that keeps seconds) as the create
52
+ * must still show a changed `updatedAt`.
53
+ *
54
+ * @param previous - The row's current `updatedAt`, as stored.
55
+ * @returns The ISO time.
56
+ */
57
+ const nextUpdatedAt = (previous) => {
58
+ const before = previous instanceof Date ? previous.getTime() : Date.parse(String(previous ?? ''));
59
+ return new Date(Math.max(Date.now(), Number.isFinite(before) ? before + 1 : 0)).toISOString();
60
+ };
49
61
  /** Largest page a list returns. */
50
62
  export const MAX_ARTICLES_PAGE = 100;
51
63
  const pageOf = (options) => ({
@@ -281,7 +293,7 @@ export async function updateArticle(slug, userId, input) {
281
293
  return { status: 'not_found' };
282
294
  if (row.authorId !== userId)
283
295
  return { status: 'forbidden' };
284
- const patch = { updatedAt: new Date().toISOString() };
296
+ const patch = { updatedAt: nextUpdatedAt(row.updatedAt) };
285
297
  if (input.title !== undefined && input.title !== row.title) {
286
298
  patch.title = input.title;
287
299
  patch.slug = await articleSlug(input.title, row.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-article",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Articles and blog posts: unique slugs, tags, favorites, a followed-authors feed, and filtered, paginated lists",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,10 +33,10 @@
33
33
  ],
34
34
  "license": "Apache-2.0",
35
35
  "devDependencies": {
36
- "@molecule/api-database": "1.1.1",
37
- "@molecule/api-database-sqlite": "1.2.1",
38
- "@molecule/api-resource-follow": "1.0.6",
39
- "@molecule/api-resource-reaction": "1.0.3",
36
+ "@molecule/api-database": "1.1.3",
37
+ "@molecule/api-database-sqlite": "1.2.4",
38
+ "@molecule/api-resource-follow": "1.0.7",
39
+ "@molecule/api-resource-reaction": "1.0.4",
40
40
  "@molecule/api-slug": "1.0.1",
41
41
  "@types/node": "26.1.2",
42
42
  "typescript": "6.0.3",
@@ -0,0 +1,12 @@
1
+ CREATE TABLE IF NOT EXISTS "follows" (
2
+ "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
3
+ "followerId" UUID NOT NULL,
4
+ "targetType" VARCHAR(255) NOT NULL,
5
+ "targetId" VARCHAR(255) NOT NULL,
6
+ "createdAt" TIMESTAMPTZ NOT NULL DEFAULT now(),
7
+ "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT now(),
8
+ UNIQUE ("followerId", "targetType", "targetId")
9
+ );
10
+
11
+ CREATE INDEX IF NOT EXISTS "idx_follows_follower" ON "follows" ("followerId");
12
+ CREATE INDEX IF NOT EXISTS "idx_follows_target" ON "follows" ("targetType", "targetId");
@@ -0,0 +1,13 @@
1
+ CREATE TABLE IF NOT EXISTS "reactions" (
2
+ "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
3
+ "resourceType" VARCHAR(255) NOT NULL,
4
+ "resourceId" VARCHAR(255) NOT NULL,
5
+ "userId" UUID NOT NULL,
6
+ "type" VARCHAR(50) NOT NULL,
7
+ "createdAt" TIMESTAMPTZ NOT NULL DEFAULT now(),
8
+ "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT now(),
9
+ UNIQUE ("resourceType", "resourceId", "userId", "type")
10
+ );
11
+
12
+ CREATE INDEX IF NOT EXISTS "idx_reactions_resource" ON "reactions" ("resourceType", "resourceId");
13
+ CREATE INDEX IF NOT EXISTS "idx_reactions_user" ON "reactions" ("userId");