@byline/db-mysql 6.8.0 → 6.9.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.
@@ -23,6 +23,7 @@
23
23
  * `implements IDocumentQueries`.
24
24
  */
25
25
  import type { CollectionDefinition, DocumentFilter, FieldFilterOperator, FieldSort, FlattenedStore, ICollectionQueries, IDocumentQueries, LocaleVisibility, MissingLocalePolicy, ReadMode } from '@byline/core';
26
+ import { type UnavailableBlock } from '@byline/core';
26
27
  import type { MySql2Database } from 'drizzle-orm/mysql2';
27
28
  import { DocumentPublishScheduleQueries } from './publish-schedules.js';
28
29
  import type * as schema from '../../database/schema/index.js';
@@ -334,6 +335,7 @@ export declare class DocumentQueries implements IDocumentQueries {
334
335
  availableLocales: string[];
335
336
  _availableVersionLocales: string[];
336
337
  _localeAgnostic: boolean;
338
+ unavailableBlocks?: UnavailableBlock[] | undefined;
337
339
  restoreWarnings?: string[] | undefined;
338
340
  } | {
339
341
  document_version_id: string;
@@ -377,11 +379,8 @@ export declare class DocumentQueries implements IDocumentQueries {
377
379
  availableLocales: string[];
378
380
  _availableVersionLocales: string[];
379
381
  _localeAgnostic: boolean;
382
+ unavailableBlocks?: UnavailableBlock[] | undefined;
380
383
  } | {
381
- resolved_locale?: undefined;
382
- availableLocales?: undefined;
383
- _availableVersionLocales?: undefined;
384
- _localeAgnostic?: undefined;
385
384
  document_version_id: string;
386
385
  document_id: string;
387
386
  path: string;
@@ -512,7 +512,7 @@ export class DocumentQueries {
512
512
  * _id and _type for blocks and array items inline. Pure JS/core-delegate
513
513
  * code — ports unchanged from pg.
514
514
  */
515
- reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, lenient = false, onMissingLocale, sourceLocale, localeContext) {
515
+ reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, lenient = false, onMissingLocale, sourceLocale, localeContext, identity) {
516
516
  const flattenedData = unifiedFieldValues.map((row) => extractFlattenedFieldValue(row));
517
517
  if (metaRows) {
518
518
  for (const meta of metaRows) {
@@ -561,14 +561,20 @@ export class DocumentQueries {
561
561
  rows = flattenedData.filter((row) => row.locale === 'all' || row.field_type === 'meta');
562
562
  }
563
563
  }
564
- const { data, warnings } = restoreFieldSetData(definition.fields, rows, resolveLocale);
564
+ const { data, warnings, unavailableBlocks } = restoreFieldSetData(definition.fields, rows, resolveLocale, identity ? { collectionPath: definition.path, ...identity } : undefined);
565
565
  if (!lenient && warnings.length > 0) {
566
566
  throw ERR_DATABASE({
567
567
  message: `document reconstruction failed with ${warnings.length} warnings`,
568
568
  details: { warnings },
569
569
  }).log(getLogger());
570
570
  }
571
- return { fields: data, warnings, resolvedLocale, localeAgnostic: ledger.localeAgnostic };
571
+ return {
572
+ fields: data,
573
+ warnings,
574
+ unavailableBlocks,
575
+ resolvedLocale,
576
+ localeAgnostic: ledger.localeAgnostic,
577
+ };
572
578
  }
573
579
  /**
574
580
  * getCurrentVersionMetadata — narrow metadata fetch for the current version.
@@ -686,7 +692,7 @@ export class DocumentQueries {
686
692
  .where(eq(metaStore.document_version_id, document.id));
687
693
  const availability = (await this.getAvailableLocalesByVersion([document.id])).get(document.id);
688
694
  const advertised = (await this.getAdvertisedLocalesByDocument([document.document_id])).get(document.document_id);
689
- const { fields, warnings, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, lenient, onMissingLocale, document.source_locale, { visibility: localeVisibility, ledger: availability, availableLocales: advertised });
695
+ const { fields, warnings, unavailableBlocks, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, lenient, onMissingLocale, document.source_locale, { visibility: localeVisibility, ledger: availability, availableLocales: advertised }, { documentId: document.document_id, versionId: document.id });
690
696
  return {
691
697
  document_version_id: document.id,
692
698
  document_id: document.document_id,
@@ -702,6 +708,7 @@ export class DocumentQueries {
702
708
  availableLocales: advertised ?? [],
703
709
  _availableVersionLocales: availability?.availableLocales ?? [],
704
710
  _localeAgnostic: localeAgnostic,
711
+ ...(unavailableBlocks.length > 0 ? { unavailableBlocks } : {}),
705
712
  ...(lenient && warnings.length > 0 ? { restoreWarnings: warnings } : {}),
706
713
  };
707
714
  }
@@ -781,7 +788,7 @@ export class DocumentQueries {
781
788
  .where(eq(metaStore.document_version_id, document.id));
782
789
  const availability = (await this.getAvailableLocalesByVersion([document.id])).get(document.id);
783
790
  const advertised = (await this.getAdvertisedLocalesByDocument([document.document_id])).get(document.document_id);
784
- const { fields, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, false, onMissingLocale, document.source_locale, { visibility: localeVisibility, ledger: availability, availableLocales: advertised });
791
+ const { fields, unavailableBlocks, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, false, onMissingLocale, document.source_locale, { visibility: localeVisibility, ledger: availability, availableLocales: advertised }, { documentId: document.document_id, versionId: document.id });
785
792
  return {
786
793
  document_version_id: document.id,
787
794
  document_id: document.document_id,
@@ -797,6 +804,7 @@ export class DocumentQueries {
797
804
  availableLocales: advertised ?? [],
798
805
  _availableVersionLocales: availability?.availableLocales ?? [],
799
806
  _localeAgnostic: localeAgnostic,
807
+ ...(unavailableBlocks.length > 0 ? { unavailableBlocks } : {}),
800
808
  };
801
809
  }
802
810
  const fieldValues = this.convertUnionRowToFlattenedStores(unifiedFieldValues);
@@ -853,7 +861,7 @@ export class DocumentQueries {
853
861
  .from(metaStore)
854
862
  .where(eq(metaStore.document_version_id, document.id));
855
863
  const ledger = (await this.getAvailableLocalesByVersion([document.id])).get(document.id);
856
- const { fields, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, false, undefined, document.source_locale, { ledger });
864
+ const { fields, unavailableBlocks, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(unifiedFieldValues, definition, locale, metaRows, false, undefined, document.source_locale, { ledger }, { documentId: document.document_id, versionId: document.id });
857
865
  return {
858
866
  document_version_id: document.id,
859
867
  document_id: document.document_id,
@@ -865,6 +873,7 @@ export class DocumentQueries {
865
873
  fields,
866
874
  resolved_locale: resolvedLocale,
867
875
  _localeAgnostic: localeAgnostic,
876
+ ...(unavailableBlocks.length > 0 ? { unavailableBlocks } : {}),
868
877
  };
869
878
  }
870
879
  /**
@@ -1429,11 +1438,11 @@ export class DocumentQueries {
1429
1438
  for (const doc of docs) {
1430
1439
  const versionFieldValues = fieldValuesByVersion.get(doc.id) || [];
1431
1440
  const docMetaRows = (metaByVersion.get(doc.id) ?? []);
1432
- const { fields, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(versionFieldValues, definition, locale, docMetaRows, false, onMissingLocale, doc.source_locale, {
1441
+ const { fields, unavailableBlocks, resolvedLocale, localeAgnostic } = this.reconstructFromUnifiedRows(versionFieldValues, definition, locale, docMetaRows, false, onMissingLocale, doc.source_locale, {
1433
1442
  visibility: localeVisibility,
1434
1443
  ledger: versionLedgers?.get(doc.id),
1435
1444
  availableLocales: documentAdvertised?.get(doc.document_id),
1436
- });
1445
+ }, { documentId: doc.document_id, versionId: doc.id });
1437
1446
  // When specific fields were requested, trim the reconstructed object
1438
1447
  // to only those fields. Store-level filtering avoids querying unused
1439
1448
  // tables, but fields sharing a store (e.g. price + views in numeric)
@@ -1454,6 +1463,7 @@ export class DocumentQueries {
1454
1463
  fields: trimmedFields,
1455
1464
  resolved_locale: resolvedLocale,
1456
1465
  _localeAgnostic: localeAgnostic,
1466
+ ...(unavailableBlocks.length > 0 ? { unavailableBlocks } : {}),
1457
1467
  };
1458
1468
  result.push(documentWithFields);
1459
1469
  }
@@ -216,7 +216,7 @@ describe('fallback locale selection under a changed default (mysql, live databas
216
216
  const listed = documents.find((d) => d.document_id === id);
217
217
  expect(byPath?.fields.title).toBe(byId?.fields.title);
218
218
  expect(listed?.fields.title).toBe(byId?.fields.title);
219
- expect(byPath?.resolved_locale).toBe(byId?.resolved_locale);
219
+ expect(byPath && 'resolved_locale' in byPath ? byPath.resolved_locale : undefined).toBe(byId?.resolved_locale);
220
220
  expect(listed?.resolved_locale).toBe(byId?.resolved_locale);
221
221
  }
222
222
  });
@@ -326,7 +326,7 @@ describe('fallback locale selection under a changed default (mysql, live databas
326
326
  });
327
327
  expect(byPath?.document_id).toBe(id);
328
328
  expect(byPath?.fields.title, 'the incomplete translation is not delivered').toBe('Slug EN');
329
- expect(byPath?.resolved_locale).toBe('en');
329
+ expect(byPath && 'resolved_locale' in byPath ? byPath.resolved_locale : undefined).toBe('en');
330
330
  });
331
331
  it('a projected list falls back to the document source, not the changed default', async () => {
332
332
  const richText = (text) => ({
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": "6.8.0",
5
+ "version": "6.9.0",
6
6
  "engines": {
7
7
  "node": ">=22.22.2"
8
8
  },
@@ -47,16 +47,16 @@
47
47
  "dist"
48
48
  ],
49
49
  "dependencies": {
50
- "@byline/admin": "6.8.0",
51
- "@byline/core": "6.8.0",
50
+ "@byline/admin": "6.9.0",
51
+ "@byline/core": "6.9.0",
52
52
  "drizzle-orm": "^0.45.4",
53
53
  "mysql2": "^3.24.6",
54
54
  "uuid": "^14.0.3"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@biomejs/biome": "2.5.15",
58
- "@byline/auth": "6.8.0",
59
- "@byline/client": "6.8.0",
58
+ "@byline/auth": "6.9.0",
59
+ "@byline/client": "6.9.0",
60
60
  "@byline/db-conformance": "0.0.10",
61
61
  "@types/node": "^26.6.5",
62
62
  "chokidar": "^5.0.0",