@prisma-next/family-sql 0.16.0-dev.30 → 0.16.0-dev.32

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.
@@ -1 +1 @@
1
- {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/control-target-descriptor.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/control-policy.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/native-type-expander.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;UAuLU;WACC;WACA;WACA;WACA;;KAGN,0BAA0B,YAAY;UAEjC;WACC,kBAAkB,cAAc;WAChC,cAAc;WACd,sBAAsB;;UAGhB,iCACP,6BAA6B,kBACnC,kBAAkB,kBAClB,wBAAwB,kBACxB,yBACA;;;;;;;;;EASF,oBAAoB,wBAAwB;EAE5C,OAAO;aACI,QAAQ;aACR;aACA;aACA;aACA;MACP,QAAQ;;;;;;;;;;EAWZ,aAAa;aACF;aACA,QAAQ;aACR;aACA,qBAAqB,cAAc;MAC1C;;;;;;;;;;EAWJ,2BAA2B,OAAO,kBAAkB;;;;;;;;EASpD,mBAAmB,OAAO;EAE1B,KAAK;aACM,QAAQ;aACR;aACA;aACA;MACP,QAAQ;EAEZ,WAAW;aACA,QAAQ;aACR;MACP,QAAQ;EAEZ,iBAAiB,UAAU,kBAAkB;EAE7C,SACE,KAAK,cAAc,SACnB,SAAS,0BACR,QAAQ;;;;;;EAOX,WAAW;aACA,QAAQ;aACR;aACA;eACE;eACA;eACA;;MAET;;;;;EAMJ,aAAa;aACF,QAAQ;aACR;aACA;aACA;eACE;eACA;eACA;;MAET;;;;;EAMJ,iBAAiB;aACN,QAAQ;aACR;aACA;eACE;eACA;eACA;eACA;eACA;eACA;eACA;;MAET;EAEJ,yCAAyC;E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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsE3C,uCACR,8BACA,2BACN;WAAkB,SAAS;WAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsB3C,0BACR,8BACA,2BACN;WAAkB,SAAS;WAAkB,YAAY"}
1
+ {"version":3,"file":"control.d.mts","names":[],"sources":["../src/core/control-instance.ts","../src/core/control-descriptor.ts","../src/core/assembly.ts","../src/core/control-target-descriptor.ts","../src/core/migrations/contract-to-schema-ir.ts","../src/core/migrations/control-policy.ts","../src/core/migrations/field-event-planner.ts","../src/core/migrations/native-type-expander.ts","../src/core/migrations/plan-helpers.ts","../src/core/migrations/policies.ts","../src/core/timestamp-now-generator.ts","../src/exports/control.ts"],"mappings":";;;;;;;;;;;;;;UAsMU;WACC;WACA;WACA;WACA;;KAGN,0BAA0B,YAAY;UAEjC;WACC,kBAAkB,cAAc;WAChC,cAAc;WACd,sBAAsB;;UAGhB,iCACP,6BAA6B,kBACnC,kBAAkB,kBAClB,wBAAwB,kBACxB,yBACA;;;;;;;;;EASF,oBAAoB,wBAAwB;EAE5C,OAAO;aACI,QAAQ;aACR;aACA;aACA;aACA;MACP,QAAQ;;;;;;;;;;EAWZ,aAAa;aACF;aACA,QAAQ;aACR;aACA,qBAAqB,cAAc;MAC1C;;;;;;;;;;EAWJ,2BAA2B,OAAO,kBAAkB;;;;;;;;EASpD,mBAAmB,OAAO;EAE1B,KAAK;aACM,QAAQ;aACR;aACA;aACA;MACP,QAAQ;EAEZ,WAAW;aACA,QAAQ;aACR;MACP,QAAQ;EAEZ,iBAAiB,UAAU,kBAAkB;EAE7C,SACE,KAAK,cAAc,SACnB,SAAS,0BACR,QAAQ;;;;;;EAOX,WAAW;aACA,QAAQ;aACR;aACA;eACE;eACA;eACA;;MAET;;;;;EAMJ,aAAa;aACF,QAAQ;aACR;aACA;aACA;eACE;eACA;eACA;;MAET;;;;;EAMJ,iB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CsBnB,iCAAiC;;;;;;;;;;;iBAqBjC,+BACR,8BACA,2BACN;WAAkB,SAAS;WAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsE3C,uCACR,8BACA,2BACN;WAAkB,SAAS;WAAkB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsB3C,0BACR,8BACA,2BACN;WAAkB,SAAS;WAAkB,YAAY"}
package/dist/control.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { i as sqlFamilyPslBlockDescriptors, n as sqlFamilyAuthoringFieldPresets, r as sqlFamilyEntityTypes, t as sqlFamilyAuthoringTypes } from "./authoring-type-constructors-CXd-8ydc.mjs";
2
2
  import { n as classifyDiffSubjectGranularity, o as verifySqlSchemaByDiff, s as extractCodecControlHooks, t as classifyDiffEntityKind } from "./schema-verify-DY21bMwy.mjs";
3
- import { t as SqlContractSerializer } from "./sql-contract-serializer-C75cfMSS.mjs";
4
- import { t as collectSupportedCodecTypeIds } from "./verify-C-G0obRm.mjs";
3
+ import { t as sqlFamilyError } from "./errors-ZGKTAYsm.mjs";
4
+ import { t as SqlContractSerializer } from "./sql-contract-serializer-othnJUZ_.mjs";
5
+ import { t as collectSupportedCodecTypeIds } from "./verify-DuuJFiTm.mjs";
5
6
  import { a as timestampNowControlDescriptor, i as temporalCodecPresetWithPrecision, n as temporalAuthoringPresets, r as temporalCodecPreset } from "./timestamp-now-generator-DRXygu32.mjs";
6
7
  import { sqlEmission } from "@prisma-next/sql-contract-emitter";
7
8
  import { blindCast } from "@prisma-next/utils/casts";
@@ -10,6 +11,7 @@ import { isPlainRecord } from "@prisma-next/framework-components/ir";
10
11
  import { assertDescriptorSelfConsistency } from "@prisma-next/migration-tools/spaces";
11
12
  import { sqlContractCanonicalizationHooks } from "@prisma-next/sql-contract/canonicalization-hooks";
12
13
  import { ifDefined } from "@prisma-next/utils/defined";
14
+ import { InternalError } from "@prisma-next/utils/internal-error";
13
15
  import { effectiveControlPolicy } from "@prisma-next/contract/types";
14
16
  import { StorageTable, isStorageTypeInstance } from "@prisma-next/sql-contract/types";
15
17
  import { RelationalSchemaNodeKind, SqlSchemaIR, SqlTableIR } from "@prisma-next/sql-schema-ir/types";
@@ -48,6 +50,16 @@ function sqlOperationsToPreview(operations) {
48
50
  }
49
51
  //#endregion
50
52
  //#region src/core/control-instance.ts
53
+ function missingDescriptorOperationError(targetId, operation) {
54
+ return sqlFamilyError("CONTRACT.PACK_CONTRIBUTION_INVALID", `SQL target "${targetId}" is missing the required ${operation} descriptor operation`, {
55
+ why: `The target descriptor does not contribute the ${operation} operation the SQL family requires for this call.`,
56
+ fix: `Use a target package whose control descriptor implements ${operation}.`,
57
+ meta: {
58
+ targetId,
59
+ operation
60
+ }
61
+ });
62
+ }
51
63
  function extractCodecTypeIdsFromContract(contract) {
52
64
  const typeIds = /* @__PURE__ */ new Set();
53
65
  if (typeof contract === "object" && contract !== null && "storage" in contract && typeof contract.storage === "object" && contract.storage !== null && "namespaces" in contract.storage && typeof contract.storage.namespaces === "object" && contract.storage.namespaces !== null) {
@@ -176,7 +188,14 @@ function assertNoCrossSpaceFkReverseReferences(extensions) {
176
188
  if (target["spaceId"] === void 0) continue;
177
189
  const targetSpaceId = target["spaceId"];
178
190
  if (typeof targetSpaceId !== "string") continue;
179
- if (dependsOnMap.get(targetSpaceId)?.has(ext.id)) throw new Error(`Cross-space FK reverse-reference detected: extension "${ext.id}" has a cross-space FK targeting space "${targetSpaceId}", but "${targetSpaceId}" depends on "${ext.id}". Cross-space FKs must follow the dependency direction (a space can only reference spaces it depends on, not spaces that depend on it).`);
191
+ if (dependsOnMap.get(targetSpaceId)?.has(ext.id)) throw sqlFamilyError("CONTRACT.FOREIGN_KEY_INVALID", `Cross-space FK reverse-reference detected: extension "${ext.id}" has a cross-space FK targeting space "${targetSpaceId}", but "${targetSpaceId}" depends on "${ext.id}". Cross-space FKs must follow the dependency direction (a space can only reference spaces it depends on, not spaces that depend on it).`, {
192
+ why: "The foreign key points against the contract-space dependency direction.",
193
+ fix: "Move the foreign key to the depending space, or restructure the extension dependencies so the referencing space depends on the referenced one.",
194
+ meta: {
195
+ extensionId: ext.id,
196
+ targetSpaceId
197
+ }
198
+ });
180
199
  }
181
200
  }
182
201
  }
@@ -184,7 +203,7 @@ function assertNoCrossSpaceFkReverseReferences(extensions) {
184
203
  }
185
204
  }
186
205
  function createSqlFamilyInstance(stack) {
187
- if (!stack.adapter) throw new Error("SQL family requires an adapter descriptor in ControlStack");
206
+ if (!stack.adapter) throw new InternalError("SQL family requires an adapter descriptor in ControlStack");
188
207
  const target = stack.target;
189
208
  const adapter = stack.adapter;
190
209
  const extensions = stack.extensions;
@@ -323,8 +342,8 @@ function createSqlFamilyInstance(stack) {
323
342
  },
324
343
  verifySchema(options) {
325
344
  const contract = deserializeWithTargetSerializer(options.contract);
326
- if (!diffSchema) throw new Error(`SQL target "${target.targetId}" is missing the required diffSchema descriptor operation`);
327
- if (!targetGranularityOf) throw new Error(`SQL target "${target.targetId}" is missing the required classifySubjectGranularity descriptor operation`);
345
+ if (!diffSchema) throw missingDescriptorOperationError(target.targetId, "diffSchema");
346
+ if (!targetGranularityOf) throw missingDescriptorOperationError(target.targetId, "classifySubjectGranularity");
328
347
  return verifySqlSchemaByDiff({
329
348
  contract,
330
349
  schema: options.schema,
@@ -344,7 +363,7 @@ function createSqlFamilyInstance(stack) {
344
363
  * cannot read; nothing is stamped on the issue or the node.
345
364
  */
346
365
  classifySubjectGranularity(issue) {
347
- if (!targetGranularityOf) throw new Error(`SQL target "${target.targetId}" is missing the required classifySubjectGranularity descriptor operation`);
366
+ if (!targetGranularityOf) throw missingDescriptorOperationError(target.targetId, "classifySubjectGranularity");
348
367
  return classifyDiffSubjectGranularity(issue, targetGranularityOf);
349
368
  },
350
369
  /**
@@ -355,7 +374,7 @@ function createSqlFamilyInstance(stack) {
355
374
  * capability.
356
375
  */
357
376
  classifyEntityKind(issue) {
358
- if (!targetEntityKindOf) throw new Error(`SQL target "${target.targetId}" is missing the required classifyEntityKind descriptor operation`);
377
+ if (!targetEntityKindOf) throw missingDescriptorOperationError(target.targetId, "classifyEntityKind");
359
378
  return classifyDiffEntityKind(issue, targetEntityKindOf);
360
379
  },
361
380
  async sign(options) {
@@ -392,7 +411,11 @@ function createSqlFamilyInstance(stack) {
392
411
  if (!await controlAdapter.updateMarker(driver, APP_SPACE_ID, existingStorageHash, {
393
412
  storageHash: contractStorageHash,
394
413
  profileHash: contractProfileHash
395
- })) throw new Error("CAS conflict: marker was modified by another process during sign");
414
+ })) throw sqlFamilyError("MIGRATION.MARKER_CAS_FAILURE", "CAS conflict: marker was modified by another process during sign", {
415
+ why: "Another process updated the contract marker between the read and the compare-and-swap write.",
416
+ fix: "Re-run the sign command; if it keeps failing, make sure only one migration process runs at a time.",
417
+ meta: { space: APP_SPACE_ID }
418
+ });
396
419
  markerUpdated = true;
397
420
  }
398
421
  }
@@ -446,7 +469,11 @@ function createSqlFamilyInstance(stack) {
446
469
  return getControlAdapter().introspect(options.driver, options.contract);
447
470
  },
448
471
  inferPslContract(schemaIR) {
449
- if (!targetInferPslContract) throw new Error(`Target "${target.targetId}" does not support contract infer (no inferPslContract on its descriptor).`);
472
+ if (!targetInferPslContract) throw sqlFamilyError("CONTRACT.INFER_UNSUPPORTED", `Target "${target.targetId}" does not support contract infer (no inferPslContract on its descriptor).`, {
473
+ why: "The target descriptor does not provide the inferPslContract hook, so a PSL contract cannot be inferred from the database schema.",
474
+ fix: "Use a target package that supports contract infer, or author the contract instead of inferring it.",
475
+ meta: { targetId: target.targetId }
476
+ });
450
477
  return targetInferPslContract(schemaIR, describedContracts);
451
478
  },
452
479
  lowerAst(ast, context) {
@@ -613,13 +640,17 @@ function buildColumnCodecRef(resolved, many) {
613
640
  function resolveColumnTypeMetadata(column, storageTypes) {
614
641
  if (!column.typeRef) return column;
615
642
  const referenced = storageTypes[column.typeRef];
616
- if (!referenced) throw new Error(`Column references storage type "${column.typeRef}" but it is not defined in storage.types.`);
643
+ if (!referenced) throw sqlFamilyError("CONTRACT.TYPE_UNKNOWN", `Column references storage type "${column.typeRef}" but it is not defined in storage.types.`, {
644
+ why: "The column typeRef does not resolve to any entry in the contract storage.types map.",
645
+ fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
646
+ meta: { typeRef: column.typeRef }
647
+ });
617
648
  if (isStorageTypeInstance(referenced)) return {
618
649
  codecId: referenced.codecId,
619
650
  nativeType: referenced.nativeType,
620
651
  typeParams: referenced.typeParams
621
652
  };
622
- throw new Error(`Storage type "${column.typeRef}" has an unknown polymorphic kind; expected a codec-typed StorageTypeInstance.`);
653
+ throw new InternalError(`Storage type "${column.typeRef}" has an unknown polymorphic kind; expected a codec-typed StorageTypeInstance.`);
623
654
  }
624
655
  /**
625
656
  * Resolves a `ValueSetRef` to its permitted values from the contract storage.
@@ -636,11 +667,34 @@ function allStrings(values) {
636
667
  }
637
668
  function resolveValueSetValues(ref, storage, contextLabel) {
638
669
  const ns = storage.namespaces[ref.namespaceId];
639
- if (!ns) throw new Error(`resolveValueSetValues: namespace "${ref.namespaceId}" not found in storage (${contextLabel})`);
670
+ if (!ns) throw sqlFamilyError("CONTRACT.NAMESPACE_UNKNOWN", `resolveValueSetValues: namespace "${ref.namespaceId}" not found in storage (${contextLabel})`, {
671
+ why: "A value-set reference names a namespace the contract storage does not declare.",
672
+ fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
673
+ meta: {
674
+ namespaceId: ref.namespaceId,
675
+ context: contextLabel
676
+ }
677
+ });
640
678
  const valueSet = ns.entries.valueSet?.[ref.entityName];
641
- if (!valueSet) throw new Error(`resolveValueSetValues: value-set "${ref.entityName}" not found in namespace "${ref.namespaceId}" (${contextLabel})`);
679
+ if (!valueSet) throw sqlFamilyError("CONTRACT.ENUM_UNKNOWN", `resolveValueSetValues: value-set "${ref.entityName}" not found in namespace "${ref.namespaceId}" (${contextLabel})`, {
680
+ why: "A value-set reference names an entry its namespace does not declare.",
681
+ fix: "Regenerate the contract from its authoring source; do not hand-edit contract JSON.",
682
+ meta: {
683
+ valueSet: ref.entityName,
684
+ namespaceId: ref.namespaceId,
685
+ context: contextLabel
686
+ }
687
+ });
642
688
  const values = valueSet.values;
643
- if (!allStrings(values)) throw new Error(`resolveValueSetValues: value-set "${ref.entityName}" in namespace "${ref.namespaceId}" has a non-string value; numeric-enum CHECK constraints are not yet supported (${contextLabel})`);
689
+ if (!allStrings(values)) throw sqlFamilyError("CONTRACT.ENUM_INVALID", `resolveValueSetValues: value-set "${ref.entityName}" in namespace "${ref.namespaceId}" has a non-string value; numeric-enum CHECK constraints are not yet supported (${contextLabel})`, {
690
+ why: "Only string value-sets can be rendered as CHECK constraints; this value-set carries a non-string value.",
691
+ fix: "Use string enum values, or drop the CHECK-constrained enum until numeric enums are supported.",
692
+ meta: {
693
+ valueSet: ref.entityName,
694
+ namespaceId: ref.namespaceId,
695
+ context: contextLabel
696
+ }
697
+ });
644
698
  return values;
645
699
  }
646
700
  /**
@@ -844,7 +898,11 @@ function detectDestructiveChanges(from, to) {
844
898
  * per-table fields.
845
899
  */
846
900
  function contractNamespaceToSchemaIR(storage, namespaceId, options) {
847
- if (options.annotationNamespace.length === 0) throw new Error("annotationNamespace must be a non-empty string");
901
+ if (options.annotationNamespace.length === 0) throw sqlFamilyError("CONTRACT.PACK_CONTRIBUTION_INVALID", "annotationNamespace must be a non-empty string", {
902
+ why: "The calling target pack passed an empty annotationNamespace to the contract-to-schema-IR projection.",
903
+ fix: "Fix the target pack to pass its non-empty annotation namespace (e.g. \"pg\").",
904
+ meta: { option: "annotationNamespace" }
905
+ });
848
906
  const namespace = storage.namespaces[namespaceId];
849
907
  if (!namespace) return new SqlSchemaIR({ tables: {} });
850
908
  const storageTypes = { ...storage.types ?? {} };
@@ -856,7 +914,11 @@ function contractNamespaceToSchemaIR(storage, namespaceId, options) {
856
914
  return new SqlSchemaIR({ tables });
857
915
  }
858
916
  function contractToSchemaIR(contract, options) {
859
- if (options.annotationNamespace.length === 0) throw new Error("annotationNamespace must be a non-empty string");
917
+ if (options.annotationNamespace.length === 0) throw sqlFamilyError("CONTRACT.PACK_CONTRIBUTION_INVALID", "annotationNamespace must be a non-empty string", {
918
+ why: "The calling target pack passed an empty annotationNamespace to the contract-to-schema-IR projection.",
919
+ fix: "Fix the target pack to pass its non-empty annotation namespace (e.g. \"pg\").",
920
+ meta: { option: "annotationNamespace" }
921
+ });
860
922
  if (!contract) return new SqlSchemaIR({ tables: {} });
861
923
  const storage = contract.storage;
862
924
  const storageTypes = { ...storage.types ?? {} };
@@ -864,7 +926,11 @@ function contractToSchemaIR(contract, options) {
864
926
  for (const ns of Object.values(storage.namespaces)) for (const [tableName, tableDefRaw] of Object.entries(ns.entries.table ?? {})) {
865
927
  StorageTable.assert(tableDefRaw, `namespaces.${ns.id}.entries.table.${tableName}`);
866
928
  const tableDef = tableDefRaw;
867
- if (tables[tableName] !== void 0) throw new Error(`contractToSchemaIR: duplicate SQL table name "${tableName}" across namespaces (ambiguous for flat SqlSchemaIR.tables).`);
929
+ if (tables[tableName] !== void 0) throw sqlFamilyError("CONTRACT.TABLE_AMBIGUOUS", `contractToSchemaIR: duplicate SQL table name "${tableName}" across namespaces (ambiguous for flat SqlSchemaIR.tables).`, {
930
+ why: "Two namespaces declare a table with the same name, which is ambiguous for the flat schema-IR table map.",
931
+ fix: "Rename one of the tables so every table name is unique across namespaces.",
932
+ meta: { table: tableName }
933
+ });
868
934
  tables[tableName] = convertTable(tableName, tableDef, storageTypes, options.expandNativeType, options.renderDefault, options.resolveDefault, storage);
869
935
  }
870
936
  return new SqlSchemaIR({