@byline/db-mysql 4.17.0 → 4.19.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.
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * Copyright (c) Infonomic Company Limited
7
7
  */
8
- import { DbErrorCodes, ERR_CONFLICT, ERR_NOT_FOUND, ERR_VALIDATION, flattenFieldSetData, generateKeyBetween, isSingleton, TREE_PLACEMENT_STALE_MARKER, } from '@byline/core';
8
+ import { assertDocumentVersionParent, DbErrorCodes, ERR_CONFLICT, ERR_NOT_FOUND, ERR_VALIDATION, flattenFieldSetData, generateKeyBetween, isSingleton, TREE_PLACEMENT_STALE_MARKER, } from '@byline/core';
9
9
  import { and, desc, eq, inArray, ne, notInArray, sql } from 'drizzle-orm';
10
10
  import { v7 as uuidv7 } from 'uuid';
11
11
  import { booleanStore, collections, currentDocumentsView, datetimeStore, documentAvailableLocales, documentPaths, documentRelationships, documents, documentVersions, fileStore, jsonStore, metaStore, numericStore, relationStore, textStore, } from '../../database/schema/index.js';
@@ -221,6 +221,12 @@ export class DocumentCommands {
221
221
  details: { documentId },
222
222
  });
223
223
  }
224
+ assertDocumentVersionParent({
225
+ documentId,
226
+ locale: params.locale,
227
+ previousVersionId: params.previousVersionId,
228
+ currentVersionId: versionLiveness.currentVersionId,
229
+ });
224
230
  sourceLocale = existing.source_locale ?? this.defaultContentLocale;
225
231
  }
226
232
  // 2. Create the document version. The id is minted here (app-side
@@ -833,10 +839,12 @@ export class DocumentCommands {
833
839
  }
834
840
  async readDocumentVersionLiveness(tx, documentId) {
835
841
  // Match the live views: only explicit `false` is live; legacy `NULL` is not.
842
+ // Their current version is likewise the greatest live UUIDv7 id.
836
843
  return tx
837
844
  .select({
838
845
  total: sql `CAST(COUNT(*) AS SIGNED)`,
839
846
  live: sql `CAST(COUNT(CASE WHEN ${documentVersions.is_deleted} = false THEN 1 END) AS SIGNED)`,
847
+ currentVersionId: sql `MAX(CASE WHEN ${documentVersions.is_deleted} = false THEN ${documentVersions.id} ELSE NULL END)`,
840
848
  })
841
849
  .from(documentVersions)
842
850
  .where(eq(documentVersions.document_id, documentId))
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@byline/db-mysql",
3
3
  "private": false,
4
4
  "license": "MPL-2.0",
5
- "version": "4.17.0",
5
+ "version": "4.19.0",
6
6
  "engines": {
7
7
  "node": ">=20.9.0"
8
8
  },
@@ -50,8 +50,8 @@
50
50
  "drizzle-orm": "^0.45.2",
51
51
  "mysql2": "^3.24.2",
52
52
  "uuid": "^14.0.2",
53
- "@byline/admin": "4.17.0",
54
- "@byline/core": "4.17.0"
53
+ "@byline/admin": "4.19.0",
54
+ "@byline/core": "4.19.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@biomejs/biome": "2.5.10",
@@ -64,9 +64,9 @@
64
64
  "tsc-alias": "^1.9.2",
65
65
  "typescript": "^7.0.2",
66
66
  "vitest": "^4.1.11",
67
- "@byline/auth": "4.17.0",
68
- "@byline/db-conformance": "0.0.10",
69
- "@byline/client": "4.17.0"
67
+ "@byline/auth": "4.19.0",
68
+ "@byline/client": "4.19.0",
69
+ "@byline/db-conformance": "0.0.10"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public",