@prisma-next/contract 0.16.0-dev.3 → 0.16.0-dev.31

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.
Files changed (49) hide show
  1. package/README.md +1 -1
  2. package/dist/apply-specifier-default-control-policy.d.mts +1 -1
  3. package/dist/{canonicalization-lc9irAy3.d.mts → canonicalization-CHtjytMX.d.mts} +2 -2
  4. package/dist/{canonicalization-lc9irAy3.d.mts.map → canonicalization-CHtjytMX.d.mts.map} +1 -1
  5. package/dist/{contract-types-BVJDOpEC.d.mts → contract-types-CkdMH7F7.d.mts} +3 -3
  6. package/dist/contract-types-CkdMH7F7.d.mts.map +1 -0
  7. package/dist/contract-validation-error-DEiWp_EI.mjs +14 -0
  8. package/dist/contract-validation-error-DEiWp_EI.mjs.map +1 -0
  9. package/dist/contract-validation-error.d.mts +10 -2
  10. package/dist/contract-validation-error.d.mts.map +1 -0
  11. package/dist/contract-validation-error.mjs +2 -2
  12. package/dist/{default-namespace-rpdJeUMq.mjs → default-namespace-Z7Meqbw0.mjs} +13 -5
  13. package/dist/default-namespace-Z7Meqbw0.mjs.map +1 -0
  14. package/dist/default-namespace.mjs +1 -1
  15. package/dist/{domain-envelope-CXbPct2s.d.mts → domain-envelope-D6Wn9AmZ.d.mts} +4 -4
  16. package/dist/{domain-envelope-CXbPct2s.d.mts.map → domain-envelope-D6Wn9AmZ.d.mts.map} +1 -1
  17. package/dist/enum-accessor.d.mts +2 -2
  18. package/dist/hashing-utils.d.mts +1 -1
  19. package/dist/hashing.d.mts +2 -2
  20. package/dist/hashing.mjs +7 -7
  21. package/dist/hashing.mjs.map +1 -1
  22. package/dist/{resolve-domain-model-CfMSnbL2.d.mts → resolve-domain-model-BVSb5wS5.d.mts} +2 -2
  23. package/dist/resolve-domain-model-BVSb5wS5.d.mts.map +1 -0
  24. package/dist/resolve-domain-model.d.mts +1 -1
  25. package/dist/types.d.mts +4 -5
  26. package/dist/types.d.mts.map +1 -1
  27. package/dist/types.mjs +6 -4
  28. package/dist/types.mjs.map +1 -1
  29. package/dist/validate-domain.d.mts +1 -1
  30. package/dist/validate-domain.mjs +1 -1
  31. package/package.json +4 -4
  32. package/schemas/data-contract-document-v1.json +3 -3
  33. package/src/canonicalization.ts +5 -5
  34. package/src/contract-errors.ts +14 -0
  35. package/src/contract-types.ts +1 -1
  36. package/src/contract-validation-error.ts +0 -7
  37. package/src/default-namespace.ts +7 -3
  38. package/src/domain-namespace-access.ts +4 -2
  39. package/src/exports/contract-validation-error.ts +0 -1
  40. package/src/exports/types.ts +0 -1
  41. package/src/hashing.ts +2 -2
  42. package/src/types.ts +3 -3
  43. package/dist/contract-types-BVJDOpEC.d.mts.map +0 -1
  44. package/dist/contract-validation-error-BFA66rwU.mjs +0 -20
  45. package/dist/contract-validation-error-BFA66rwU.mjs.map +0 -1
  46. package/dist/contract-validation-error-D7g0kmcc.d.mts +0 -13
  47. package/dist/contract-validation-error-D7g0kmcc.d.mts.map +0 -1
  48. package/dist/default-namespace-rpdJeUMq.mjs.map +0 -1
  49. package/dist/resolve-domain-model-CfMSnbL2.d.mts.map +0 -1
package/README.md CHANGED
@@ -44,7 +44,7 @@ Reference the appropriate JSON schema in your `contract.json` files to enable ID
44
44
  "schemaVersion": "1",
45
45
  "target": "mongodb",
46
46
  "targetFamily": "document",
47
- "storageHash": "sha256:..."
47
+ "storageHash": "..."
48
48
  }
49
49
  ```
50
50
 
@@ -1,4 +1,4 @@
1
- import { i as ControlPolicy, t as Contract } from "./contract-types-BVJDOpEC.mjs";
1
+ import { i as ControlPolicy, t as Contract } from "./contract-types-CkdMH7F7.mjs";
2
2
  //#region src/apply-specifier-default-control-policy.d.ts
3
3
  declare function applySpecifierDefaultControlPolicy(contract: Contract, specifierDefault: ControlPolicy | undefined): Contract;
4
4
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as Contract } from "./contract-types-BVJDOpEC.mjs";
1
+ import { t as Contract } from "./contract-types-CkdMH7F7.mjs";
2
2
  import { JsonObject } from "@prisma-next/utils/json";
3
3
  //#region src/canonicalization.d.ts
4
4
  /**
@@ -65,4 +65,4 @@ declare function canonicalizeContractToObject(contract: Contract, options: Canon
65
65
  declare function canonicalizeContract(contract: Contract, options: CanonicalizeContractOptions): string;
66
66
  //#endregion
67
67
  export { canonicalizeContract as a, StorageSort as i, PreserveEmptyPredicate as n, canonicalizeContractToObject as o, SerializeContract as r, CanonicalizeContractOptions as t };
68
- //# sourceMappingURL=canonicalization-lc9irAy3.d.mts.map
68
+ //# sourceMappingURL=canonicalization-CHtjytMX.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"canonicalization-lc9irAy3.d.mts","names":[],"sources":["../src/canonicalization.ts"],"mappings":";;;;;;;;;;;KAcY,qBAAqB,UAAU,aAAa;;;;;;;;;KAU5C,0BAA0B;;;;;;;;KAS1B,eAAe;UAqLV;WACN;;;;;;;;;;;WAWA,mBAAmB;;;;;;;WAOnB,sBAAsB;;;;;;;;WAQtB,cAAc;;;;;;;iBAQT,6BACd,UAAU,UACV,SAAS,8BACR;iBA2Ba,qBACd,UAAU,UACV,SAAS"}
1
+ {"version":3,"file":"canonicalization-CHtjytMX.d.mts","names":[],"sources":["../src/canonicalization.ts"],"mappings":";;;;;;;;;;;KAcY,qBAAqB,UAAU,aAAa;;;;;;;;;KAU5C,0BAA0B;;;;;;;;KAS1B,eAAe;UAqLV;WACN;;;;;;;;;;;WAWA,mBAAmB;;;;;;;WAOnB,sBAAsB;;;;;;;;WAQtB,cAAc;;;;;;;iBAQT,6BACd,UAAU,UACV,SAAS,8BACR;iBA2Ba,qBACd,UAAU,UACV,SAAS"}
@@ -1,4 +1,4 @@
1
- import { F as ExecutionMutationDefault, J as StorageBase, K as ProfileHashBase, P as ExecutionHashBase, _ as ContractValueObject, it as CrossReference, t as ApplicationDomain } from "./domain-envelope-CXbPct2s.mjs";
1
+ import { F as ExecutionMutationDefault, J as StorageBase, K as ProfileHashBase, P as ExecutionHashBase, _ as ContractValueObject, it as CrossReference, t as ApplicationDomain } from "./domain-envelope-D6Wn9AmZ.mjs";
2
2
  //#region src/control-policy.d.ts
3
3
  /**
4
4
  * Governance posture for a storage-plane node or for the contract as a whole.
@@ -59,7 +59,7 @@ interface Contract<TStorage extends StorageBase = StorageBase> {
59
59
  readonly domain: ApplicationDomain;
60
60
  readonly storage: TStorage;
61
61
  readonly capabilities: Record<string, Record<string, boolean>>;
62
- readonly extensionPacks: Record<string, unknown>;
62
+ readonly extensions: Record<string, unknown>;
63
63
  readonly execution?: ContractExecutionSection;
64
64
  readonly profileHash: ProfileHashBase<string>;
65
65
  readonly meta: Record<string, unknown>;
@@ -73,4 +73,4 @@ type NamespaceValueObjectsOf<TNamespace> = TNamespace extends {
73
73
  type ContractValueObjectDefinitions<TContract extends Contract> = NamespaceValueObjectsOf<TContract['domain']['namespaces'][ExactlyOneNamespace<TContract['domain']['namespaces']>]> extends (infer Projected) ? Projected extends Record<string, ContractValueObject> ? Projected : Record<never, never> : Record<never, never>;
74
74
  //#endregion
75
75
  export { effectiveControlPolicy as a, ControlPolicy as i, ContractExecutionSection as n, ContractValueObjectDefinitions as r, Contract as t };
76
- //# sourceMappingURL=contract-types-BVJDOpEC.d.mts.map
76
+ //# sourceMappingURL=contract-types-CkdMH7F7.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-types-CkdMH7F7.d.mts","names":[],"sources":["../src/control-policy.ts","../src/contract-types.ts"],"mappings":";;;;;;;;;;;KASY;;;;;;;;;iBAUI,uBACd,aAAa,2BACb,sBAAsB,4BACrB;;;;;;;;;;;;KCFS,yBAAyB;WAC1B,eAAe,kBAAkB;WACjC;aACE,UAAU,cAAc;;;;;;;;;;;;;;;;UAiBpB,SAAS,iBAAiB,cAAc;WAC9C;WACA;WACA,OAAO,eAAe;;;;WAItB,QAAQ;WACR,SAAS;WACT,cAAc,eAAe;WAC7B,YAAY;WACZ,YAAY;WACZ,aAAa;WACb,MAAM;WACN,uBAAuB;;KAG7B,oBAAoB,UAAU,iCAAiC,iBAAgB,mBAC5E,YACG,YAAY,QACjB;KAID,wBAAwB,cAAc;WAChC,qBAAqB;IAE5B,WAAW,eAAe,uBACxB,KACA,uBACF;;KAGQ,+BAA+B,kBAAkB,YAC3D,wBACE,kCAAkC,oBAAoB,oDACxC,aACZ,kBAAkB,eAAe,uBAC/B,YACA,uBACF"}
@@ -0,0 +1,14 @@
1
+ //#region src/contract-validation-error.ts
2
+ var ContractValidationError = class extends Error {
3
+ code = "CONTRACT.VALIDATION_FAILED";
4
+ phase;
5
+ constructor(message, phase) {
6
+ super(message);
7
+ this.name = "ContractValidationError";
8
+ this.phase = phase;
9
+ }
10
+ };
11
+ //#endregion
12
+ export { ContractValidationError as t };
13
+
14
+ //# sourceMappingURL=contract-validation-error-DEiWp_EI.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-validation-error-DEiWp_EI.mjs","names":[],"sources":["../src/contract-validation-error.ts"],"sourcesContent":["export type ContractValidationPhase = 'structural' | 'domain' | 'storage';\n\nexport class ContractValidationError extends Error {\n readonly code = 'CONTRACT.VALIDATION_FAILED';\n readonly phase: ContractValidationPhase;\n\n constructor(message: string, phase: ContractValidationPhase) {\n super(message);\n this.name = 'ContractValidationError';\n this.phase = phase;\n }\n}\n"],"mappings":";AAEA,IAAa,0BAAb,cAA6C,MAAM;CACjD,OAAgB;CAChB;CAEA,YAAY,SAAiB,OAAgC;EAC3D,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF"}
@@ -1,2 +1,10 @@
1
- import { n as ContractValidationPhase, r as DomainNamespaceResolutionError, t as ContractValidationError } from "./contract-validation-error-D7g0kmcc.mjs";
2
- export { ContractValidationError, type ContractValidationPhase, DomainNamespaceResolutionError };
1
+ //#region src/contract-validation-error.d.ts
2
+ type ContractValidationPhase = 'structural' | 'domain' | 'storage';
3
+ declare class ContractValidationError extends Error {
4
+ readonly code = "CONTRACT.VALIDATION_FAILED";
5
+ readonly phase: ContractValidationPhase;
6
+ constructor(message: string, phase: ContractValidationPhase);
7
+ }
8
+ //#endregion
9
+ export { ContractValidationError, type ContractValidationPhase };
10
+ //# sourceMappingURL=contract-validation-error.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-validation-error.d.mts","names":[],"sources":["../src/contract-validation-error.ts"],"mappings":";KAAY;cAEC,gCAAgC;WAClC;WACA,OAAO;cAEJ,iBAAiB,OAAO"}
@@ -1,2 +1,2 @@
1
- import { n as DomainNamespaceResolutionError, t as ContractValidationError } from "./contract-validation-error-BFA66rwU.mjs";
2
- export { ContractValidationError, DomainNamespaceResolutionError };
1
+ import { t as ContractValidationError } from "./contract-validation-error-DEiWp_EI.mjs";
2
+ export { ContractValidationError };
@@ -1,4 +1,9 @@
1
- import { n as DomainNamespaceResolutionError } from "./contract-validation-error-BFA66rwU.mjs";
1
+ import { structuredError } from "@prisma-next/utils/structured-error";
2
+ //#region src/contract-errors.ts
3
+ function contractError(code, message, options) {
4
+ return structuredError(code, message, options);
5
+ }
6
+ //#endregion
2
7
  //#region src/default-namespace.ts
3
8
  /**
4
9
  * Reserved sentinel domain namespace id for the late-bound application-domain
@@ -20,14 +25,17 @@ const UNBOUND_DOMAIN_NAMESPACE_ID = "__unbound__";
20
25
  */
21
26
  function soleDomainNamespaceId(domain) {
22
27
  const [soleNamespaceId, ...rest] = Object.keys(domain.namespaces);
23
- if (soleNamespaceId === void 0) throw new DomainNamespaceResolutionError("domain has no namespaces");
28
+ if (soleNamespaceId === void 0) throw contractError("CONTRACT.NAMESPACE_INVALID", "domain has no namespaces", { meta: { reason: "no-domain-namespaces" } });
24
29
  if (rest.length > 0) {
25
30
  const all = [soleNamespaceId, ...rest];
26
- throw new DomainNamespaceResolutionError(`bare-name resolution requires exactly one domain namespace, found ${all.length} (${all.join(", ")}); select a namespace explicitly`);
31
+ throw contractError("CONTRACT.NAMESPACE_INVALID", `bare-name resolution requires exactly one domain namespace, found ${all.length} (${all.join(", ")}); select a namespace explicitly`, { meta: {
32
+ reason: "multiple-domain-namespaces",
33
+ namespaceIds: all
34
+ } });
27
35
  }
28
36
  return soleNamespaceId;
29
37
  }
30
38
  //#endregion
31
- export { soleDomainNamespaceId as n, UNBOUND_DOMAIN_NAMESPACE_ID as t };
39
+ export { soleDomainNamespaceId as n, contractError as r, UNBOUND_DOMAIN_NAMESPACE_ID as t };
32
40
 
33
- //# sourceMappingURL=default-namespace-rpdJeUMq.mjs.map
41
+ //# sourceMappingURL=default-namespace-Z7Meqbw0.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-namespace-Z7Meqbw0.mjs","names":[],"sources":["../src/contract-errors.ts","../src/default-namespace.ts"],"sourcesContent":["import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\nexport type ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'NAMESPACE_INVALID';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n","import { contractError } from './contract-errors';\n\n/**\n * Reserved sentinel domain namespace id for the late-bound application-domain\n * slot — the namespace a model lands in when it is authored without an explicit\n * namespace. This is target-agnostic: targets that allow un-namespaced\n * authoring (e.g. Mongo, SQLite) declare this id as their default on the target\n * descriptor; the framework names the sentinel, never a target. Mirrors\n * storage's `UNBOUND_NAMESPACE_ID` on the domain plane.\n */\nexport const UNBOUND_DOMAIN_NAMESPACE_ID = '__unbound__' as const;\n\n/**\n * Resolve the single domain namespace of a single-namespace contract.\n *\n * Bare-name access (`db.User`) reads \"the contract's one namespace\". Every\n * contract in scope today declares exactly one domain namespace, so this is\n * exact — there is nothing to infer. A contract that declares more than one\n * namespace is ambiguous for a bare name, so rather than silently pick one this\n * throws; cross-namespace selection is made explicit (TML-2550).\n */\nexport function soleDomainNamespaceId(domain: {\n readonly namespaces: Readonly<Record<string, unknown>>;\n}): string {\n const [soleNamespaceId, ...rest] = Object.keys(domain.namespaces);\n if (soleNamespaceId === undefined) {\n throw contractError('CONTRACT.NAMESPACE_INVALID', 'domain has no namespaces', {\n meta: { reason: 'no-domain-namespaces' },\n });\n }\n if (rest.length > 0) {\n const all = [soleNamespaceId, ...rest];\n throw contractError(\n 'CONTRACT.NAMESPACE_INVALID',\n `bare-name resolution requires exactly one domain namespace, found ${all.length} (${all.join(', ')}); select a namespace explicitly`,\n { meta: { reason: 'multiple-domain-namespaces', namespaceIds: all } },\n );\n }\n return soleNamespaceId;\n}\n"],"mappings":";;AAOA,SAAgB,cACd,MACA,SACA,SACiB;CACjB,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC/C;;;;;;;;;;;ACHA,MAAa,8BAA8B;;;;;;;;;;AAW3C,SAAgB,sBAAsB,QAE3B;CACT,MAAM,CAAC,iBAAiB,GAAG,QAAQ,OAAO,KAAK,OAAO,UAAU;CAChE,IAAI,oBAAoB,KAAA,GACtB,MAAM,cAAc,8BAA8B,4BAA4B,EAC5E,MAAM,EAAE,QAAQ,uBAAuB,EACzC,CAAC;CAEH,IAAI,KAAK,SAAS,GAAG;EACnB,MAAM,MAAM,CAAC,iBAAiB,GAAG,IAAI;EACrC,MAAM,cACJ,8BACA,qEAAqE,IAAI,OAAO,IAAI,IAAI,KAAK,IAAI,EAAE,mCACnG,EAAE,MAAM;GAAE,QAAQ;GAA8B,cAAc;EAAI,EAAE,CACtE;CACF;CACA,OAAO;AACT"}
@@ -1,2 +1,2 @@
1
- import { n as soleDomainNamespaceId, t as UNBOUND_DOMAIN_NAMESPACE_ID } from "./default-namespace-rpdJeUMq.mjs";
1
+ import { n as soleDomainNamespaceId, t as UNBOUND_DOMAIN_NAMESPACE_ID } from "./default-namespace-Z7Meqbw0.mjs";
2
2
  export { UNBOUND_DOMAIN_NAMESPACE_ID, soleDomainNamespaceId };
@@ -35,13 +35,13 @@ type Brand<TKey extends string | number | symbol, TValue = true> = {
35
35
  /**
36
36
  * Base type for storage contract hashes.
37
37
  * Emitted contract.d.ts files use this with the hash value as a type parameter:
38
- * `type StorageHash = StorageHashBase<'sha256:abc123...'>`
38
+ * `type StorageHash = StorageHashBase<'abc123...'>`
39
39
  */
40
40
  type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;
41
41
  /**
42
42
  * Base type for execution contract hashes.
43
43
  * Emitted contract.d.ts files use this with the hash value as a type parameter:
44
- * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`
44
+ * `type ExecutionHash = ExecutionHashBase<'def456...'>`
45
45
  */
46
46
  type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;
47
47
  declare function executionHash<const T extends string>(value: T): ExecutionHashBase<T>;
@@ -49,7 +49,7 @@ declare function coreHash<const T extends string>(value: T): StorageHashBase<T>;
49
49
  /**
50
50
  * Base type for profile contract hashes.
51
51
  * Emitted contract.d.ts files use this with the hash value as a type parameter:
52
- * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`
52
+ * `type ProfileHash = ProfileHashBase<'def456...'>`
53
53
  */
54
54
  type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;
55
55
  declare function profileHash<const T extends string>(value: T): ProfileHashBase<T>;
@@ -355,4 +355,4 @@ type ContractWithDomain = {
355
355
  };
356
356
  //#endregion
357
357
  export { executionHash as $, ColumnDefaultLiteralValue as A, FieldType as B, UnionFieldType as C, Brand as D, $ as E, ExecutionMutationDefault as F, PlanMeta as G, JsonPrimitive as H, ExecutionMutationDefaultPhases as I, StorageBase as J, ProfileHashBase as K, ExecutionMutationDefaultValue as L, DocCollection as M, DocIndex as N, ColumnDefault as O, ExecutionHashBase as P, coreHash as Q, ExecutionSection as R, ScalarFieldType as S, ValueSetRef as T, JsonValue as U, GeneratedValueSpec as V, LedgerEntryRecord as W, StorageHashBase as X, StorageEntitySlot as Y, StorageNamespace as Z, ContractValueObject as _, ContractEmbedRelation as a, CrossReferenceSchema as at, ModelStorageBase as b, ContractFieldType as c, asNamespaceId as ct, ContractModelBase as d, isColumnDefault as et, ContractNonJunctionRelation as f, ContractRelationThrough as g, ContractRelationOn as h, ContractDiscriminator as i, CrossReference as it, ContractMarkerRecord as j, ColumnDefaultLiteralInputValue as k, ContractManyToManyRelation as l, ContractRelation as m, ApplicationDomainNamespace as n, isExecutionMutationDefaultValue as nt, ContractEnum as o, crossRef as ot, ContractReferenceRelation as p, Source as q, ContractWithDomain as r, profileHash as rt, ContractField as s, NamespaceId as st, ApplicationDomain as t, isColumnDefaultLiteralInputValue as tt, ContractModel as u, ContractVariantEntry as v, ValueObjectFieldType as w, ReferenceRelationKeys as x, EmbedRelationKeys as y, Expr as z };
358
- //# sourceMappingURL=domain-envelope-CXbPct2s.d.mts.map
358
+ //# sourceMappingURL=domain-envelope-D6Wn9AmZ.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"domain-envelope-CXbPct2s.d.mts","names":[],"sources":["../src/namespace-id.ts","../src/cross-reference.ts","../src/types.ts","../src/value-set-ref.ts","../src/domain-types.ts","../src/domain-envelope.ts"],"mappings":";KAEY;WAAkC;;iBAE9B,cAAc,gBAAgB;;;UCA7B;WACN,WAAW;WACX;;;;;;WAMA;;cAGE,oEAAoB,WAAA;iBAcjB,SACd,eACA,oBACA,iBACC;;;;;;cC9BU;;;;;;;KAQD,MAAM,uCAAuC;GACtD,OACE,KAAK,OAAO;;;;;;;KASL,gBAAgB,wBAAwB,QAAQ;;;;;;KAOhD,kBAAkB,wBAAwB,QAAQ;iBAE9C,oBAAoB,kBAAkB,OAAO,IAAI,kBAAkB;iBAInE,eAAe,kBAAkB,OAAO,IAAI,gBAAgB;;;;;;KAShE,gBAAgB,wBAAwB,QAAQ;iBAE5C,kBAAkB,kBAAkB,OAAO,IAAI,gBAAgB;;;;;;KASnE,oBAAoB,SAAS;;;;;;;UAQxB;WACN;WACA,SAAS,SAAS,eAAe;;;;;;;;;;;UAY3B,YAAY;WAClB,aAAa,gBAAgB;WAC7B,YAAY,SAAS,eAAe;;UAG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;KAGC,4BAA4B,6BAA6B;KAEzD;WACD,IAAI;WACJ;;KAGC,mBAAmB,4BAA4B;KAE/C;WACD;;KAGC;WACD;;KAGC;WACD,QAAQ,eAAe;;KAGtB,mBAAmB,SAAS;UAEvB,kBAAkB,sBAAsB,mBAAmB;WACjE,QAAQ,eAAe;WACvB,WAAW,eAAe;WAC1B,SAAS;WACT,gBAAgB;WAChB,WAAW,eAAe;WAC1B,OAAO;WACP;;UAGM,cAAc,sBAAsB,mBAAmB,0BAC9D,kBAAkB;WACjB,QAAQ,eAAe;;KAKtB,sBACV,gBAAgB;WAA0B,WAAW,eAAe;IACpE,iCAAiC,cAEhC,WAAW,QAAQ,0BAA0B,QAAQ,wBAAwB,WAAW,4BACrF,mBAEE,QAAQ;KAEJ,kBACV,gBAAgB;WAA0B,WAAW,eAAe;IACpE,iCAAiC,cAEhC,WAAW,QAAQ,0BAA0B,QAAQ,wBAAwB,WAAW,oCAErF,WACE,QAAQ;;;;;;;UCnHC;WACN,QAAQ,eAAe;WACvB,eAAe,eAAe;WAC9B,OAAO,eAAe;;;;;;UAOhB;WACN,YAAY,SAAS,eAAe;;KAGnC;WACD,QAAQ"}
1
+ {"version":3,"file":"domain-envelope-D6Wn9AmZ.d.mts","names":[],"sources":["../src/namespace-id.ts","../src/cross-reference.ts","../src/types.ts","../src/value-set-ref.ts","../src/domain-types.ts","../src/domain-envelope.ts"],"mappings":";KAEY;WAAkC;;iBAE9B,cAAc,gBAAgB;;;UCA7B;WACN,WAAW;WACX;;;;;;WAMA;;cAGE,oEAAoB,WAAA;iBAcjB,SACd,eACA,oBACA,iBACC;;;;;;cC9BU;;;;;;;KAQD,MAAM,uCAAuC;GACtD,OACE,KAAK,OAAO;;;;;;;KASL,gBAAgB,wBAAwB,QAAQ;;;;;;KAOhD,kBAAkB,wBAAwB,QAAQ;iBAE9C,oBAAoB,kBAAkB,OAAO,IAAI,kBAAkB;iBAInE,eAAe,kBAAkB,OAAO,IAAI,gBAAgB;;;;;;KA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WACD;WACA,MAAM;WACN;WACA;WACA,WAAW;;;;;;;KAQV;WACD;WACA;aAA6B;aAAuB,OAAO;;;KAG1D;WACD;WACA;;KAGC;WACD;WACA;WACA;WACA;WACA;;KAGC;WACD,IAAI;WACJ;WACA,IAAI;WACJ,SAAS;;KAGR;WACD,IAAI;WACJ;WACA,IAAI;WACJ;;KAGC,4BAA4B,6BAA6B;KAEzD;WACD,IAAI;WACJ;;KAGC,mBAAmB,4BAA4B;KAE/C;WACD;;KAGC;WACD;;KAGC;WACD,QAAQ,eAAe;;KAGtB,mBAAmB,SAAS;UAEvB,kBAAkB,sBAAsB,mBAAmB;WACjE,QAAQ,eAAe;WACvB,WAAW,eAAe;WAC1B,SAAS;WACT,gBAAgB;WAChB,WAAW,eAAe;WAC1B,OAAO;WACP;;UAGM,cAAc,sBAAsB,mBAAmB,0BAC9D,kBAAkB;WACjB,QAAQ,eAAe;;KAKtB,sBACV,gBAAgB;WAA0B,WAAW,eAAe;IACpE,iCAAiC,cAEhC,WAAW,QAAQ,0BAA0B,QAAQ,wBAAwB,WAAW,4BACrF,mBAEE,QAAQ;KAEJ,kBACV,gBAAgB;WAA0B,WAAW,eAAe;IACpE,iCAAiC,cAEhC,WAAW,QAAQ,0BAA0B,QAAQ,wBAAwB,WAAW,oCAErF,WACE,QAAQ;;;;;;;UCnHC;WACN,QAAQ,eAAe;WACvB,eAAe,eAAe;WAC9B,OAAO,eAAe;;;;;;UAOhB;WACN,YAAY,SAAS,eAAe;;KAGnC;WACD,QAAQ"}
@@ -1,5 +1,5 @@
1
- import { t as Contract } from "./contract-types-BVJDOpEC.mjs";
2
- import { U as JsonValue, o as ContractEnum } from "./domain-envelope-CXbPct2s.mjs";
1
+ import { t as Contract } from "./contract-types-CkdMH7F7.mjs";
2
+ import { U as JsonValue, o as ContractEnum } from "./domain-envelope-D6Wn9AmZ.mjs";
3
3
  //#region src/enum-accessor.d.ts
4
4
  /**
5
5
  * Runtime view of a domain enum, built at the client from the emitted
@@ -1,4 +1,4 @@
1
- import { i as StorageSort, n as PreserveEmptyPredicate } from "./canonicalization-lc9irAy3.mjs";
1
+ import { i as StorageSort, n as PreserveEmptyPredicate } from "./canonicalization-CHtjytMX.mjs";
2
2
  //#region src/canonicalization-path-match.d.ts
3
3
  type PathSegment = string | '*' | readonly string[];
4
4
  type PathPattern = readonly PathSegment[];
@@ -1,5 +1,5 @@
1
- import { K as ProfileHashBase, P as ExecutionHashBase, X as StorageHashBase } from "./domain-envelope-CXbPct2s.mjs";
2
- import { a as canonicalizeContract, i as StorageSort, n as PreserveEmptyPredicate, o as canonicalizeContractToObject, r as SerializeContract, t as CanonicalizeContractOptions } from "./canonicalization-lc9irAy3.mjs";
1
+ import { K as ProfileHashBase, P as ExecutionHashBase, X as StorageHashBase } from "./domain-envelope-D6Wn9AmZ.mjs";
2
+ import { a as canonicalizeContract, i as StorageSort, n as PreserveEmptyPredicate, o as canonicalizeContractToObject, r as SerializeContract, t as CanonicalizeContractOptions } from "./canonicalization-CHtjytMX.mjs";
3
3
  //#region src/hashing.d.ts
4
4
  type ComputeStorageHashArgs = {
5
5
  target: string;
package/dist/hashing.mjs CHANGED
@@ -49,7 +49,7 @@ const TOP_LEVEL_ORDER = [
49
49
  "storage",
50
50
  "execution",
51
51
  "capabilities",
52
- "extensionPacks",
52
+ "extensions",
53
53
  "defaultControlPolicy",
54
54
  "meta"
55
55
  ];
@@ -76,7 +76,7 @@ function omitDefaults(obj, path, shouldPreserveEmpty) {
76
76
  const isRequiredStorageNamespaces = isArrayEqual(currentPath, ["storage", "namespaces"]);
77
77
  const isStorageNamespaceEntries = matchesPathPattern(currentPath, STORAGE_NAMESPACE_ENTRIES_PATTERN);
78
78
  const isRequiredRoots = isArrayEqual(currentPath, ["roots"]);
79
- const isRequiredExtensionPacks = isArrayEqual(currentPath, ["extensionPacks"]);
79
+ const isRequiredExtensions = isArrayEqual(currentPath, ["extensions"]);
80
80
  const isRequiredCapabilities = isArrayEqual(currentPath, ["capabilities"]);
81
81
  const isRequiredMeta = isArrayEqual(currentPath, ["meta"]);
82
82
  const isRequiredExecutionDefaults = isArrayEqual(currentPath, [
@@ -84,12 +84,12 @@ function omitDefaults(obj, path, shouldPreserveEmpty) {
84
84
  "mutations",
85
85
  "defaults"
86
86
  ]);
87
- const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === "extensionPacks";
87
+ const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === "extensions";
88
88
  const isModelRelations = matchesPathPattern(currentPath, DOMAIN_MODEL_RELATIONS_PATTERN);
89
89
  const isModelStorage = matchesPathPattern(currentPath, DOMAIN_MODEL_STORAGE_PATTERN);
90
90
  const isNullableField = key === "nullable";
91
91
  const isFamilyPreserved = shouldPreserveEmpty?.(currentPath) ?? false;
92
- if (!isRequiredDomainNamespaces && !isDomainNamespaceSlot && !isRequiredDomainModels && !isRequiredStorageNamespaces && !isStorageNamespaceEntries && !isRequiredRoots && !isRequiredExtensionPacks && !isRequiredCapabilities && !isRequiredMeta && !isRequiredExecutionDefaults && !isExtensionNamespace && !isModelRelations && !isModelStorage && !isNullableField && !isFamilyPreserved) continue;
92
+ if (!isRequiredDomainNamespaces && !isDomainNamespaceSlot && !isRequiredDomainModels && !isRequiredStorageNamespaces && !isStorageNamespaceEntries && !isRequiredRoots && !isRequiredExtensions && !isRequiredCapabilities && !isRequiredMeta && !isRequiredExecutionDefaults && !isExtensionNamespace && !isModelRelations && !isModelStorage && !isNullableField && !isFamilyPreserved) continue;
93
93
  }
94
94
  result[key] = omitDefaults(value, currentPath, shouldPreserveEmpty);
95
95
  }
@@ -129,7 +129,7 @@ function canonicalizeContractToObject(contract, options) {
129
129
  domain: serialized["domain"],
130
130
  storage: serialized["storage"],
131
131
  ...ifDefined("execution", serialized["execution"]),
132
- extensionPacks: serialized["extensionPacks"],
132
+ extensions: serialized["extensions"],
133
133
  capabilities: serialized["capabilities"],
134
134
  ...ifDefined("defaultControlPolicy", serialized["defaultControlPolicy"]),
135
135
  meta: serialized["meta"]
@@ -162,7 +162,7 @@ function omitNamespaceKindsForHash(storage) {
162
162
  function sha256(content) {
163
163
  const hash = createHash("sha256");
164
164
  hash.update(content);
165
- return `sha256:${hash.digest("hex")}`;
165
+ return hash.digest("hex");
166
166
  }
167
167
  function hashContract(section) {
168
168
  const { shouldPreserveEmpty, sortStorage, ...sectionData } = section;
@@ -173,7 +173,7 @@ function hashContract(section) {
173
173
  roots: {},
174
174
  domain: { namespaces: {} },
175
175
  execution: sectionData["execution"],
176
- extensionPacks: {},
176
+ extensions: {},
177
177
  capabilities: sectionData["capabilities"] ?? {},
178
178
  meta: {},
179
179
  profileHash: "",
@@ -1 +1 @@
1
- {"version":3,"file":"hashing.mjs","names":[],"sources":["../src/canonicalization.ts","../src/hashing.ts"],"sourcesContent":["import { isArrayEqual } from '@prisma-next/utils/array-equal';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport { matchesPathPattern, type PathPattern } from './canonicalization-path-match';\nimport type { Contract } from './contract-types';\n\n/**\n * Per-target contract serializer hook. The framework canonicalizer uses\n * this to convert an in-memory contract (which may carry class-instance\n * IR nodes whose runtime-only fields must not appear in the on-disk\n * envelope) into a plain JsonObject before applying the family-agnostic\n * canonical-key ordering / default-omission / sort steps. Targets whose\n * contract is JSON-clean by construction return the contract unchanged.\n */\nexport type SerializeContract = (contract: Contract) => JsonObject;\n\n/**\n * Family-contributed predicate for the default-omission walk. Called when\n * a value at `path` is a default (empty object/array or `false`); if this\n * returns `true` the value is kept rather than stripped.\n *\n * The framework only calls the predicate inside the `isDefaultValue` branch,\n * so there is no need to guard against non-default values.\n */\nexport type PreserveEmptyPredicate = (path: readonly string[]) => boolean;\n\n/**\n * Family-contributed storage sort. Applied to the serialized `storage`\n * subtree after the default-omission walk; the result replaces the\n * `storage` field before the final key sort. Use to establish a\n * deterministic order for storage arrays (indexes, uniques) that the\n * family-agnostic `sortObjectKeys` pass cannot handle.\n */\nexport type StorageSort = (storage: unknown) => unknown;\n\nconst DOMAIN_NAMESPACE_SLOT_PATTERN = ['domain', 'namespaces', '*'] as const satisfies PathPattern;\nconst DOMAIN_MODELS_CONTAINER_PATTERN = [\n 'domain',\n 'namespaces',\n '*',\n 'models',\n] as const satisfies PathPattern;\nconst DOMAIN_MODEL_RELATIONS_PATTERN = [\n 'domain',\n 'namespaces',\n '*',\n 'models',\n '*',\n 'relations',\n] as const satisfies PathPattern;\nconst DOMAIN_MODEL_STORAGE_PATTERN = [\n 'domain',\n 'namespaces',\n '*',\n 'models',\n '*',\n 'storage',\n] as const satisfies PathPattern;\nconst STORAGE_NAMESPACE_ENTRIES_PATTERN = [\n 'storage',\n 'namespaces',\n '*',\n 'entries',\n] as const satisfies PathPattern;\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'profileHash',\n 'roots',\n 'domain',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensionPacks',\n 'defaultControlPolicy',\n 'meta',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(\n obj: unknown,\n path: readonly string[],\n shouldPreserveEmpty: PreserveEmptyPredicate | undefined,\n): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path, shouldPreserveEmpty));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredDomainNamespaces = isArrayEqual(currentPath, ['domain', 'namespaces']);\n const isDomainNamespaceSlot = matchesPathPattern(currentPath, DOMAIN_NAMESPACE_SLOT_PATTERN);\n const isRequiredDomainModels = matchesPathPattern(\n currentPath,\n DOMAIN_MODELS_CONTAINER_PATTERN,\n );\n const isRequiredStorageNamespaces = isArrayEqual(currentPath, ['storage', 'namespaces']);\n const isStorageNamespaceEntries = matchesPathPattern(\n currentPath,\n STORAGE_NAMESPACE_ENTRIES_PATTERN,\n );\n const isRequiredRoots = isArrayEqual(currentPath, ['roots']);\n const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';\n const isModelRelations = matchesPathPattern(currentPath, DOMAIN_MODEL_RELATIONS_PATTERN);\n const isModelStorage = matchesPathPattern(currentPath, DOMAIN_MODEL_STORAGE_PATTERN);\n\n const isNullableField = key === 'nullable';\n\n const isFamilyPreserved = shouldPreserveEmpty?.(currentPath) ?? false;\n\n if (\n !isRequiredDomainNamespaces &&\n !isDomainNamespaceSlot &&\n !isRequiredDomainModels &&\n !isRequiredStorageNamespaces &&\n !isStorageNamespaceEntries &&\n !isRequiredRoots &&\n !isRequiredExtensionPacks &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isModelStorage &&\n !isNullableField &&\n !isFamilyPreserved\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath, shouldPreserveEmpty);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\nexport function orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport interface CanonicalizeContractOptions {\n readonly schemaVersion?: string;\n /**\n * Per-target hook that converts the in-memory contract (which may\n * carry class-instance IR nodes) into a plain JsonObject before the\n * family-agnostic canonicalization steps run.\n *\n * Routing through the hook is what lets each target decide which\n * fields appear in the on-disk envelope; runtime-only class API\n * fields stay invisible to the canonicalization walk by virtue of\n * the per-target serializer not putting them in the JSON shape.\n */\n readonly serializeContract: SerializeContract;\n /**\n * Family-contributed preserve-empty predicate. When the walk encounters a\n * default value (empty object/array or `false`) at `path`, calling this\n * with the full path allows the family to veto the omission. If absent,\n * only the framework's family-agnostic required-slot rules apply.\n */\n readonly shouldPreserveEmpty?: PreserveEmptyPredicate;\n /**\n * Family-contributed storage sort. Applied to the serialized `storage`\n * subtree after the default-omission walk, before the final key sort.\n * SQL family uses this to impose a deterministic order on `indexes` and\n * `uniques` arrays within each namespace table. Families that require no\n * special storage ordering omit this hook.\n */\n readonly sortStorage?: StorageSort;\n}\n\n/**\n * Object-form variant of {@link canonicalizeContract}. Exported because the\n * emitter writes the canonical contract through a separate JSON-stringify\n * pass and consumes the structured object directly.\n */\nexport function canonicalizeContractToObject(\n contract: Contract,\n options: CanonicalizeContractOptions,\n): Record<string, unknown> {\n const serialized = options.serializeContract(contract);\n const normalized: Record<string, unknown> = {\n ...ifDefined('schemaVersion', options.schemaVersion),\n targetFamily: serialized['targetFamily'],\n target: serialized['target'],\n profileHash: serialized['profileHash'],\n roots: serialized['roots'],\n domain: serialized['domain'],\n storage: serialized['storage'],\n ...ifDefined('execution', serialized['execution']),\n extensionPacks: serialized['extensionPacks'],\n capabilities: serialized['capabilities'],\n ...ifDefined('defaultControlPolicy', serialized['defaultControlPolicy']),\n meta: serialized['meta'],\n };\n const withDefaultsOmitted = omitDefaults(normalized, [], options.shouldPreserveEmpty) as Record<\n string,\n unknown\n >;\n const withSortedStorage = options.sortStorage\n ? { ...withDefaultsOmitted, storage: options.sortStorage(withDefaultsOmitted['storage']) }\n : withDefaultsOmitted;\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n return orderTopLevel(withSortedKeys);\n}\n\nexport function canonicalizeContract(\n contract: Contract,\n options: CanonicalizeContractOptions,\n): string {\n return JSON.stringify(canonicalizeContractToObject(contract, options), null, 2);\n}\n","import { createHash } from 'node:crypto';\nimport { blindCast, castAs } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport {\n canonicalizeContract,\n type PreserveEmptyPredicate,\n type StorageSort,\n} from './canonicalization';\nimport type { Contract } from './contract-types';\nimport { isPlainRecord } from './is-plain-record';\nimport type { ExecutionHashBase, ProfileHashBase, StorageHashBase } from './types';\n\nconst SCHEMA_VERSION = '1';\n\n// Storage hashes fingerprint table/column layout, not which target pack emitted a\n// namespace. Persisted contract.json carries namespace `kind` discriminators;\n// authoring-time hashes never included them (IR `kind` is non-enumerable).\nfunction omitNamespaceKindsForHash(storage: unknown): unknown {\n if (!isPlainRecord(storage)) {\n return storage;\n }\n const namespaces = storage['namespaces'];\n if (!isPlainRecord(namespaces)) {\n return storage;\n }\n const stripped: Record<string, unknown> = {};\n for (const [nsId, ns] of Object.entries(namespaces)) {\n if (isPlainRecord(ns)) {\n const { kind: _kind, ...rest } = ns;\n stripped[nsId] = rest;\n } else {\n stripped[nsId] = ns;\n }\n }\n return { ...storage, namespaces: stripped };\n}\n\nfunction sha256(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return `sha256:${hash.digest('hex')}`;\n}\n\ntype HashContractSection = Record<string, unknown> & {\n readonly shouldPreserveEmpty?: PreserveEmptyPredicate;\n readonly sortStorage?: StorageSort;\n};\n\nfunction hashContract(section: HashContractSection): string {\n const { shouldPreserveEmpty, sortStorage, ...sectionData } = section;\n const storageForHash = omitNamespaceKindsForHash(sectionData['storage'] ?? {});\n const contract = blindCast<Contract, 'hash-only partial contract for canonicalizeContract'>({\n targetFamily: sectionData['targetFamily'],\n target: sectionData['target'],\n roots: {},\n domain: { namespaces: {} },\n execution: sectionData['execution'],\n extensionPacks: {},\n capabilities: sectionData['capabilities'] ?? {},\n meta: {},\n profileHash: '',\n ...sectionData,\n storage: storageForHash,\n });\n return canonicalizeContract(contract, {\n schemaVersion: SCHEMA_VERSION,\n serializeContract: (c) => castAs<JsonObject>(JSON.parse(JSON.stringify(c))),\n ...ifDefined('shouldPreserveEmpty', shouldPreserveEmpty),\n ...ifDefined('sortStorage', sortStorage),\n });\n}\n\nexport type ComputeStorageHashArgs = {\n target: string;\n targetFamily: string;\n storage: Record<string, unknown>;\n readonly shouldPreserveEmpty?: PreserveEmptyPredicate;\n readonly sortStorage?: StorageSort;\n};\n\nexport function computeStorageHash(args: ComputeStorageHashArgs): StorageHashBase<string> {\n return blindCast<StorageHashBase<string>, 'sha256 digest of canonicalized storage'>(\n sha256(hashContract(args)),\n );\n}\n\nexport function computeExecutionHash(args: {\n target: string;\n targetFamily: string;\n execution: Record<string, unknown>;\n}): ExecutionHashBase<string> {\n return blindCast<ExecutionHashBase<string>, 'sha256 digest of canonicalized execution'>(\n sha256(hashContract(args)),\n );\n}\n\nexport function computeProfileHash(args: {\n target: string;\n targetFamily: string;\n capabilities: Record<string, Record<string, boolean>>;\n}): ProfileHashBase<string> {\n return blindCast<ProfileHashBase<string>, 'sha256 digest of canonicalized profile'>(\n sha256(hashContract(args)),\n );\n}\n"],"mappings":";;;;;;;AAmCA,MAAM,gCAAgC;CAAC;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C5C;AAEA,SAAS,OAAO,SAAyB;CACvC,MAAM,OAAO,WAAW,QAAQ;CAChC,KAAK,OAAO,OAAO;CACnB,OAAO,UAAU,KAAK,OAAO,KAAK;AACpC;AAOA,SAAS,aAAa,SAAsC;CAC1D,MAAM,EAAE,qBAAqB,aAAa,GAAG,gBAAgB;CAC7D,MAAM,iBAAiB,0BAA0B,YAAY,cAAc,CAAC,CAAC;CAc7E,OAAO,qBAbU,UAA2E;EAC1F,cAAc,YAAY;EAC1B,QAAQ,YAAY;EACpB,OAAO,CAAC;EACR,QAAQ,EAAE,YAAY,CAAC,EAAE;EACzB,WAAW,YAAY;EACvB,gBAAgB,CAAC;EACjB,cAAc,YAAY,mBAAmB,CAAC;EAC9C,MAAM,CAAC;EACP,aAAa;EACb,GAAG;EACH,SAAS;CACX,CACmC,GAAG;EACpC,eAAe;EACf,oBAAoB,MAAM,OAAmB,KAAK,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC;EAC1E,GAAG,UAAU,uBAAuB,mBAAmB;EACvD,GAAG,UAAU,eAAe,WAAW;CACzC,CAAC;AACH;AAUA,SAAgB,mBAAmB,MAAuD;CACxF,OAAO,UACL,OAAO,aAAa,IAAI,CAAC,CAC3B;AACF;AAEA,SAAgB,qBAAqB,MAIP;CAC5B,OAAO,UACL,OAAO,aAAa,IAAI,CAAC,CAC3B;AACF;AAEA,SAAgB,mBAAmB,MAIP;CAC1B,OAAO,UACL,OAAO,aAAa,IAAI,CAAC,CAC3B;AACF"}
1
+ {"version":3,"file":"hashing.mjs","names":[],"sources":["../src/canonicalization.ts","../src/hashing.ts"],"sourcesContent":["import { isArrayEqual } from '@prisma-next/utils/array-equal';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport { matchesPathPattern, type PathPattern } from './canonicalization-path-match';\nimport type { Contract } from './contract-types';\n\n/**\n * Per-target contract serializer hook. The framework canonicalizer uses\n * this to convert an in-memory contract (which may carry class-instance\n * IR nodes whose runtime-only fields must not appear in the on-disk\n * envelope) into a plain JsonObject before applying the family-agnostic\n * canonical-key ordering / default-omission / sort steps. Targets whose\n * contract is JSON-clean by construction return the contract unchanged.\n */\nexport type SerializeContract = (contract: Contract) => JsonObject;\n\n/**\n * Family-contributed predicate for the default-omission walk. Called when\n * a value at `path` is a default (empty object/array or `false`); if this\n * returns `true` the value is kept rather than stripped.\n *\n * The framework only calls the predicate inside the `isDefaultValue` branch,\n * so there is no need to guard against non-default values.\n */\nexport type PreserveEmptyPredicate = (path: readonly string[]) => boolean;\n\n/**\n * Family-contributed storage sort. Applied to the serialized `storage`\n * subtree after the default-omission walk; the result replaces the\n * `storage` field before the final key sort. Use to establish a\n * deterministic order for storage arrays (indexes, uniques) that the\n * family-agnostic `sortObjectKeys` pass cannot handle.\n */\nexport type StorageSort = (storage: unknown) => unknown;\n\nconst DOMAIN_NAMESPACE_SLOT_PATTERN = ['domain', 'namespaces', '*'] as const satisfies PathPattern;\nconst DOMAIN_MODELS_CONTAINER_PATTERN = [\n 'domain',\n 'namespaces',\n '*',\n 'models',\n] as const satisfies PathPattern;\nconst DOMAIN_MODEL_RELATIONS_PATTERN = [\n 'domain',\n 'namespaces',\n '*',\n 'models',\n '*',\n 'relations',\n] as const satisfies PathPattern;\nconst DOMAIN_MODEL_STORAGE_PATTERN = [\n 'domain',\n 'namespaces',\n '*',\n 'models',\n '*',\n 'storage',\n] as const satisfies PathPattern;\nconst STORAGE_NAMESPACE_ENTRIES_PATTERN = [\n 'storage',\n 'namespaces',\n '*',\n 'entries',\n] as const satisfies PathPattern;\n\nconst TOP_LEVEL_ORDER = [\n 'schemaVersion',\n 'canonicalVersion',\n 'targetFamily',\n 'target',\n 'profileHash',\n 'roots',\n 'domain',\n 'storage',\n 'execution',\n 'capabilities',\n 'extensions',\n 'defaultControlPolicy',\n 'meta',\n] as const;\n\nfunction isDefaultValue(value: unknown): boolean {\n if (value === false) return true;\n if (value === null) return false;\n if (Array.isArray(value) && value.length === 0) return true;\n if (typeof value === 'object' && value !== null) {\n const keys = Object.keys(value);\n return keys.length === 0;\n }\n return false;\n}\n\nfunction omitDefaults(\n obj: unknown,\n path: readonly string[],\n shouldPreserveEmpty: PreserveEmptyPredicate | undefined,\n): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => omitDefaults(item, path, shouldPreserveEmpty));\n }\n\n const result: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const currentPath = [...path, key];\n\n if (key === '_generated') {\n continue;\n }\n\n if (key === 'generated' && value === false) {\n continue;\n }\n\n if ((key === 'onDelete' || key === 'onUpdate') && value === 'noAction') {\n continue;\n }\n\n if (isDefaultValue(value)) {\n const isRequiredDomainNamespaces = isArrayEqual(currentPath, ['domain', 'namespaces']);\n const isDomainNamespaceSlot = matchesPathPattern(currentPath, DOMAIN_NAMESPACE_SLOT_PATTERN);\n const isRequiredDomainModels = matchesPathPattern(\n currentPath,\n DOMAIN_MODELS_CONTAINER_PATTERN,\n );\n const isRequiredStorageNamespaces = isArrayEqual(currentPath, ['storage', 'namespaces']);\n const isStorageNamespaceEntries = matchesPathPattern(\n currentPath,\n STORAGE_NAMESPACE_ENTRIES_PATTERN,\n );\n const isRequiredRoots = isArrayEqual(currentPath, ['roots']);\n const isRequiredExtensions = isArrayEqual(currentPath, ['extensions']);\n const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);\n const isRequiredMeta = isArrayEqual(currentPath, ['meta']);\n const isRequiredExecutionDefaults = isArrayEqual(currentPath, [\n 'execution',\n 'mutations',\n 'defaults',\n ]);\n const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensions';\n const isModelRelations = matchesPathPattern(currentPath, DOMAIN_MODEL_RELATIONS_PATTERN);\n const isModelStorage = matchesPathPattern(currentPath, DOMAIN_MODEL_STORAGE_PATTERN);\n\n const isNullableField = key === 'nullable';\n\n const isFamilyPreserved = shouldPreserveEmpty?.(currentPath) ?? false;\n\n if (\n !isRequiredDomainNamespaces &&\n !isDomainNamespaceSlot &&\n !isRequiredDomainModels &&\n !isRequiredStorageNamespaces &&\n !isStorageNamespaceEntries &&\n !isRequiredRoots &&\n !isRequiredExtensions &&\n !isRequiredCapabilities &&\n !isRequiredMeta &&\n !isRequiredExecutionDefaults &&\n !isExtensionNamespace &&\n !isModelRelations &&\n !isModelStorage &&\n !isNullableField &&\n !isFamilyPreserved\n ) {\n continue;\n }\n }\n\n result[key] = omitDefaults(value, currentPath, shouldPreserveEmpty);\n }\n\n return result;\n}\n\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj).sort();\n for (const key of keys) {\n sorted[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n }\n\n return sorted;\n}\n\nexport function orderTopLevel(obj: Record<string, unknown>): Record<string, unknown> {\n const ordered: Record<string, unknown> = {};\n const remaining = new Set(Object.keys(obj));\n\n for (const key of TOP_LEVEL_ORDER) {\n if (remaining.has(key)) {\n ordered[key] = obj[key];\n remaining.delete(key);\n }\n }\n\n for (const key of Array.from(remaining).sort()) {\n ordered[key] = obj[key];\n }\n\n return ordered;\n}\n\nexport interface CanonicalizeContractOptions {\n readonly schemaVersion?: string;\n /**\n * Per-target hook that converts the in-memory contract (which may\n * carry class-instance IR nodes) into a plain JsonObject before the\n * family-agnostic canonicalization steps run.\n *\n * Routing through the hook is what lets each target decide which\n * fields appear in the on-disk envelope; runtime-only class API\n * fields stay invisible to the canonicalization walk by virtue of\n * the per-target serializer not putting them in the JSON shape.\n */\n readonly serializeContract: SerializeContract;\n /**\n * Family-contributed preserve-empty predicate. When the walk encounters a\n * default value (empty object/array or `false`) at `path`, calling this\n * with the full path allows the family to veto the omission. If absent,\n * only the framework's family-agnostic required-slot rules apply.\n */\n readonly shouldPreserveEmpty?: PreserveEmptyPredicate;\n /**\n * Family-contributed storage sort. Applied to the serialized `storage`\n * subtree after the default-omission walk, before the final key sort.\n * SQL family uses this to impose a deterministic order on `indexes` and\n * `uniques` arrays within each namespace table. Families that require no\n * special storage ordering omit this hook.\n */\n readonly sortStorage?: StorageSort;\n}\n\n/**\n * Object-form variant of {@link canonicalizeContract}. Exported because the\n * emitter writes the canonical contract through a separate JSON-stringify\n * pass and consumes the structured object directly.\n */\nexport function canonicalizeContractToObject(\n contract: Contract,\n options: CanonicalizeContractOptions,\n): Record<string, unknown> {\n const serialized = options.serializeContract(contract);\n const normalized: Record<string, unknown> = {\n ...ifDefined('schemaVersion', options.schemaVersion),\n targetFamily: serialized['targetFamily'],\n target: serialized['target'],\n profileHash: serialized['profileHash'],\n roots: serialized['roots'],\n domain: serialized['domain'],\n storage: serialized['storage'],\n ...ifDefined('execution', serialized['execution']),\n extensions: serialized['extensions'],\n capabilities: serialized['capabilities'],\n ...ifDefined('defaultControlPolicy', serialized['defaultControlPolicy']),\n meta: serialized['meta'],\n };\n const withDefaultsOmitted = omitDefaults(normalized, [], options.shouldPreserveEmpty) as Record<\n string,\n unknown\n >;\n const withSortedStorage = options.sortStorage\n ? { ...withDefaultsOmitted, storage: options.sortStorage(withDefaultsOmitted['storage']) }\n : withDefaultsOmitted;\n const withSortedKeys = sortObjectKeys(withSortedStorage) as Record<string, unknown>;\n return orderTopLevel(withSortedKeys);\n}\n\nexport function canonicalizeContract(\n contract: Contract,\n options: CanonicalizeContractOptions,\n): string {\n return JSON.stringify(canonicalizeContractToObject(contract, options), null, 2);\n}\n","import { createHash } from 'node:crypto';\nimport { blindCast, castAs } from '@prisma-next/utils/casts';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport type { JsonObject } from '@prisma-next/utils/json';\nimport {\n canonicalizeContract,\n type PreserveEmptyPredicate,\n type StorageSort,\n} from './canonicalization';\nimport type { Contract } from './contract-types';\nimport { isPlainRecord } from './is-plain-record';\nimport type { ExecutionHashBase, ProfileHashBase, StorageHashBase } from './types';\n\nconst SCHEMA_VERSION = '1';\n\n// Storage hashes fingerprint table/column layout, not which target pack emitted a\n// namespace. Persisted contract.json carries namespace `kind` discriminators;\n// authoring-time hashes never included them (IR `kind` is non-enumerable).\nfunction omitNamespaceKindsForHash(storage: unknown): unknown {\n if (!isPlainRecord(storage)) {\n return storage;\n }\n const namespaces = storage['namespaces'];\n if (!isPlainRecord(namespaces)) {\n return storage;\n }\n const stripped: Record<string, unknown> = {};\n for (const [nsId, ns] of Object.entries(namespaces)) {\n if (isPlainRecord(ns)) {\n const { kind: _kind, ...rest } = ns;\n stripped[nsId] = rest;\n } else {\n stripped[nsId] = ns;\n }\n }\n return { ...storage, namespaces: stripped };\n}\n\nfunction sha256(content: string): string {\n const hash = createHash('sha256');\n hash.update(content);\n return hash.digest('hex');\n}\n\ntype HashContractSection = Record<string, unknown> & {\n readonly shouldPreserveEmpty?: PreserveEmptyPredicate;\n readonly sortStorage?: StorageSort;\n};\n\nfunction hashContract(section: HashContractSection): string {\n const { shouldPreserveEmpty, sortStorage, ...sectionData } = section;\n const storageForHash = omitNamespaceKindsForHash(sectionData['storage'] ?? {});\n const contract = blindCast<Contract, 'hash-only partial contract for canonicalizeContract'>({\n targetFamily: sectionData['targetFamily'],\n target: sectionData['target'],\n roots: {},\n domain: { namespaces: {} },\n execution: sectionData['execution'],\n extensions: {},\n capabilities: sectionData['capabilities'] ?? {},\n meta: {},\n profileHash: '',\n ...sectionData,\n storage: storageForHash,\n });\n return canonicalizeContract(contract, {\n schemaVersion: SCHEMA_VERSION,\n serializeContract: (c) => castAs<JsonObject>(JSON.parse(JSON.stringify(c))),\n ...ifDefined('shouldPreserveEmpty', shouldPreserveEmpty),\n ...ifDefined('sortStorage', sortStorage),\n });\n}\n\nexport type ComputeStorageHashArgs = {\n target: string;\n targetFamily: string;\n storage: Record<string, unknown>;\n readonly shouldPreserveEmpty?: PreserveEmptyPredicate;\n readonly sortStorage?: StorageSort;\n};\n\nexport function computeStorageHash(args: ComputeStorageHashArgs): StorageHashBase<string> {\n return blindCast<StorageHashBase<string>, 'sha256 digest of canonicalized storage'>(\n sha256(hashContract(args)),\n );\n}\n\nexport function computeExecutionHash(args: {\n target: string;\n targetFamily: string;\n execution: Record<string, unknown>;\n}): ExecutionHashBase<string> {\n return blindCast<ExecutionHashBase<string>, 'sha256 digest of canonicalized execution'>(\n sha256(hashContract(args)),\n );\n}\n\nexport function computeProfileHash(args: {\n target: string;\n targetFamily: string;\n capabilities: Record<string, Record<string, boolean>>;\n}): ProfileHashBase<string> {\n return blindCast<ProfileHashBase<string>, 'sha256 digest of canonicalized profile'>(\n sha256(hashContract(args)),\n );\n}\n"],"mappings":";;;;;;;AAmCA,MAAM,gCAAgC;CAAC;CAAU;CAAc;AAAG;AAClE,MAAM,kCAAkC;CACtC;CACA;CACA;CACA;AACF;AACA,MAAM,iCAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,+BAA+B;CACnC;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,oCAAoC;CACxC;CACA;CACA;CACA;AACF;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,eAAe,OAAyB;CAC/C,IAAI,UAAU,OAAO,OAAO;CAC5B,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,GAAG,OAAO;CACvD,IAAI,OAAO,UAAU,YAAY,UAAU,MAEzC,OADa,OAAO,KAAK,KACf,CAAC,CAAC,WAAW;CAEzB,OAAO;AACT;AAEA,SAAS,aACP,KACA,MACA,qBACS;CACT,IAAI,QAAQ,QAAQ,OAAO,QAAQ,UACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,GAAG,GACnB,OAAO,IAAI,KAAK,SAAS,aAAa,MAAM,MAAM,mBAAmB,CAAC;CAGxE,MAAM,SAA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,SAAgB,qBAAqB,MAIP;CAC5B,OAAO,UACL,OAAO,aAAa,IAAI,CAAC,CAC3B;AACF;AAEA,SAAgB,mBAAmB,MAIP;CAC1B,OAAO,UACL,OAAO,aAAa,IAAI,CAAC,CAC3B;AACF"}
@@ -1,4 +1,4 @@
1
- import { d as ContractModelBase, t as ApplicationDomain } from "./domain-envelope-CXbPct2s.mjs";
1
+ import { d as ContractModelBase, t as ApplicationDomain } from "./domain-envelope-D6Wn9AmZ.mjs";
2
2
  //#region src/resolve-domain-model.d.ts
3
3
  interface ResolvedDomainModel {
4
4
  readonly namespaceId: string;
@@ -13,4 +13,4 @@ interface ResolvedDomainModel {
13
13
  declare function resolveDomainModel(domain: ApplicationDomain, modelName: string): ResolvedDomainModel | undefined;
14
14
  //#endregion
15
15
  export { resolveDomainModel as n, ResolvedDomainModel as t };
16
- //# sourceMappingURL=resolve-domain-model-CfMSnbL2.d.mts.map
16
+ //# sourceMappingURL=resolve-domain-model-BVSb5wS5.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-domain-model-BVSb5wS5.d.mts","names":[],"sources":["../src/resolve-domain-model.ts"],"mappings":";;UAGiB;WACN;WACA,OAAO;;;;;;;;iBASF,mBACd,QAAQ,mBACR,oBACC"}
@@ -1,2 +1,2 @@
1
- import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-CfMSnbL2.mjs";
1
+ import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-BVSb5wS5.mjs";
2
2
  export { type ResolvedDomainModel, resolveDomainModel };
package/dist/types.d.mts CHANGED
@@ -1,8 +1,7 @@
1
- import { a as effectiveControlPolicy, i as ControlPolicy, n as ContractExecutionSection, r as ContractValueObjectDefinitions, t as Contract } from "./contract-types-BVJDOpEC.mjs";
2
- import { $ as executionHash, A as ColumnDefaultLiteralValue, B as FieldType, C as UnionFieldType, D as Brand, E as $, F as ExecutionMutationDefault, G as PlanMeta, H as JsonPrimitive, I as ExecutionMutationDefaultPhases, J as StorageBase, K as ProfileHashBase, L as ExecutionMutationDefaultValue, M as DocCollection, N as DocIndex, O as ColumnDefault, P as ExecutionHashBase, Q as coreHash, R as ExecutionSection, S as ScalarFieldType, T as ValueSetRef, U as JsonValue, V as GeneratedValueSpec, W as LedgerEntryRecord, X as StorageHashBase, Y as StorageEntitySlot, Z as StorageNamespace, _ as ContractValueObject, a as ContractEmbedRelation, at as CrossReferenceSchema, b as ModelStorageBase, c as ContractFieldType, ct as asNamespaceId, d as ContractModelBase, et as isColumnDefault, f as ContractNonJunctionRelation, g as ContractRelationThrough, h as ContractRelationOn, i as ContractDiscriminator, it as CrossReference, j as ContractMarkerRecord, k as ColumnDefaultLiteralInputValue, l as ContractManyToManyRelation, m as ContractRelation, n as ApplicationDomainNamespace, nt as isExecutionMutationDefaultValue, o as ContractEnum, ot as crossRef, p as ContractReferenceRelation, q as Source, r as ContractWithDomain, rt as profileHash, s as ContractField, st as NamespaceId, t as ApplicationDomain, tt as isColumnDefaultLiteralInputValue, u as ContractModel, v as ContractVariantEntry, w as ValueObjectFieldType, x as ReferenceRelationKeys, y as EmbedRelationKeys, z as Expr } from "./domain-envelope-CXbPct2s.mjs";
1
+ import { a as effectiveControlPolicy, i as ControlPolicy, n as ContractExecutionSection, r as ContractValueObjectDefinitions, t as Contract } from "./contract-types-CkdMH7F7.mjs";
2
+ import { $ as executionHash, A as ColumnDefaultLiteralValue, B as FieldType, C as UnionFieldType, D as Brand, E as $, F as ExecutionMutationDefault, G as PlanMeta, H as JsonPrimitive, I as ExecutionMutationDefaultPhases, J as StorageBase, K as ProfileHashBase, L as ExecutionMutationDefaultValue, M as DocCollection, N as DocIndex, O as ColumnDefault, P as ExecutionHashBase, Q as coreHash, R as ExecutionSection, S as ScalarFieldType, T as ValueSetRef, U as JsonValue, V as GeneratedValueSpec, W as LedgerEntryRecord, X as StorageHashBase, Y as StorageEntitySlot, Z as StorageNamespace, _ as ContractValueObject, a as ContractEmbedRelation, at as CrossReferenceSchema, b as ModelStorageBase, c as ContractFieldType, ct as asNamespaceId, d as ContractModelBase, et as isColumnDefault, f as ContractNonJunctionRelation, g as ContractRelationThrough, h as ContractRelationOn, i as ContractDiscriminator, it as CrossReference, j as ContractMarkerRecord, k as ColumnDefaultLiteralInputValue, l as ContractManyToManyRelation, m as ContractRelation, n as ApplicationDomainNamespace, nt as isExecutionMutationDefaultValue, o as ContractEnum, ot as crossRef, p as ContractReferenceRelation, q as Source, r as ContractWithDomain, rt as profileHash, s as ContractField, st as NamespaceId, t as ApplicationDomain, tt as isColumnDefaultLiteralInputValue, u as ContractModel, v as ContractVariantEntry, w as ValueObjectFieldType, x as ReferenceRelationKeys, y as EmbedRelationKeys, z as Expr } from "./domain-envelope-D6Wn9AmZ.mjs";
3
3
  import { n as soleDomainNamespaceId, t as UNBOUND_DOMAIN_NAMESPACE_ID } from "./default-namespace-D5X_k6hJ.mjs";
4
- import { r as DomainNamespaceResolutionError } from "./contract-validation-error-D7g0kmcc.mjs";
5
- import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-CfMSnbL2.mjs";
4
+ import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-BVSb5wS5.mjs";
6
5
  //#region src/domain-namespace-access.d.ts
7
6
  /**
8
7
  * Models map for the contract's single domain namespace. Throws when the
@@ -16,5 +15,5 @@ declare function domainModelsAtDefaultNamespace(domain: ApplicationDomain): Reco
16
15
  */
17
16
  declare function domainValueObjectsAtDefaultNamespace(domain: ApplicationDomain): Record<string, ContractValueObject> | undefined;
18
17
  //#endregion
19
- export { type $, type ApplicationDomain, type ApplicationDomainNamespace, type Brand, type ColumnDefault, type ColumnDefaultLiteralInputValue, type ColumnDefaultLiteralValue, type Contract, type ContractDiscriminator, type ContractEmbedRelation, type ContractEnum, type ContractExecutionSection, type ContractField, type ContractFieldType, type ContractManyToManyRelation, type ContractMarkerRecord, type ContractModel, type ContractModelBase, type ContractNonJunctionRelation, type ContractReferenceRelation, type ContractRelation, type ContractRelationOn, type ContractRelationThrough, type ContractValueObject, type ContractValueObjectDefinitions, type ContractVariantEntry, type ContractWithDomain, type ControlPolicy, type CrossReference, CrossReferenceSchema, type DocCollection, type DocIndex, DomainNamespaceResolutionError, type EmbedRelationKeys, type ExecutionHashBase, type ExecutionMutationDefault, type ExecutionMutationDefaultPhases, type ExecutionMutationDefaultValue, type ExecutionSection, type Expr, type FieldType, type GeneratedValueSpec, type JsonPrimitive, type JsonValue, type LedgerEntryRecord, type ModelStorageBase, type NamespaceId, type PlanMeta, type ProfileHashBase, type ReferenceRelationKeys, type ResolvedDomainModel, type ScalarFieldType, type Source, type StorageBase, type StorageEntitySlot, type StorageHashBase, type StorageNamespace, UNBOUND_DOMAIN_NAMESPACE_ID, type UnionFieldType, type ValueObjectFieldType, type ValueSetRef, asNamespaceId, coreHash, crossRef, domainModelsAtDefaultNamespace, domainValueObjectsAtDefaultNamespace, effectiveControlPolicy, executionHash, isColumnDefault, isColumnDefaultLiteralInputValue, isExecutionMutationDefaultValue, profileHash, resolveDomainModel, soleDomainNamespaceId };
18
+ export { type $, type ApplicationDomain, type ApplicationDomainNamespace, type Brand, type ColumnDefault, type ColumnDefaultLiteralInputValue, type ColumnDefaultLiteralValue, type Contract, type ContractDiscriminator, type ContractEmbedRelation, type ContractEnum, type ContractExecutionSection, type ContractField, type ContractFieldType, type ContractManyToManyRelation, type ContractMarkerRecord, type ContractModel, type ContractModelBase, type ContractNonJunctionRelation, type ContractReferenceRelation, type ContractRelation, type ContractRelationOn, type ContractRelationThrough, type ContractValueObject, type ContractValueObjectDefinitions, type ContractVariantEntry, type ContractWithDomain, type ControlPolicy, type CrossReference, CrossReferenceSchema, type DocCollection, type DocIndex, type EmbedRelationKeys, type ExecutionHashBase, type ExecutionMutationDefault, type ExecutionMutationDefaultPhases, type ExecutionMutationDefaultValue, type ExecutionSection, type Expr, type FieldType, type GeneratedValueSpec, type JsonPrimitive, type JsonValue, type LedgerEntryRecord, type ModelStorageBase, type NamespaceId, type PlanMeta, type ProfileHashBase, type ReferenceRelationKeys, type ResolvedDomainModel, type ScalarFieldType, type Source, type StorageBase, type StorageEntitySlot, type StorageHashBase, type StorageNamespace, UNBOUND_DOMAIN_NAMESPACE_ID, type UnionFieldType, type ValueObjectFieldType, type ValueSetRef, asNamespaceId, coreHash, crossRef, domainModelsAtDefaultNamespace, domainValueObjectsAtDefaultNamespace, effectiveControlPolicy, executionHash, isColumnDefault, isColumnDefaultLiteralInputValue, isExecutionMutationDefaultValue, profileHash, resolveDomainModel, soleDomainNamespaceId };
20
19
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","names":[],"sources":["../src/domain-namespace-access.ts"],"mappings":";;;;;;;;;;;iBAUgB,+BACd,QAAQ,oBACP,eAAe;;;;;iBAeF,qCACd,QAAQ,oBACP,eAAe"}
1
+ {"version":3,"file":"types.d.mts","names":[],"sources":["../src/domain-namespace-access.ts"],"mappings":";;;;;;;;;;iBAUgB,+BACd,QAAQ,oBACP,eAAe;;;;;iBAiBF,qCACd,QAAQ,oBACP,eAAe"}
package/dist/types.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { n as DomainNamespaceResolutionError } from "./contract-validation-error-BFA66rwU.mjs";
2
- import { n as soleDomainNamespaceId, t as UNBOUND_DOMAIN_NAMESPACE_ID } from "./default-namespace-rpdJeUMq.mjs";
1
+ import { n as soleDomainNamespaceId, r as contractError, t as UNBOUND_DOMAIN_NAMESPACE_ID } from "./default-namespace-Z7Meqbw0.mjs";
3
2
  import { t as resolveDomainModel } from "./resolve-domain-model-BovPAsW2.mjs";
4
3
  import { t as asNamespaceId } from "./namespace-id-CUxYd4KL.mjs";
5
4
  import { blindCast } from "@prisma-next/utils/casts";
@@ -42,7 +41,10 @@ function crossRef(model, namespace = DEFAULT_CROSS_REF_NAMESPACE, space) {
42
41
  function domainModelsAtDefaultNamespace(domain) {
43
42
  const namespaceId = soleDomainNamespaceId(domain);
44
43
  const domainNamespace = domain.namespaces[namespaceId];
45
- if (domainNamespace === void 0) throw new DomainNamespaceResolutionError(`domain namespace "${namespaceId}" is not present on the contract`);
44
+ if (domainNamespace === void 0) throw contractError("CONTRACT.NAMESPACE_INVALID", `domain namespace "${namespaceId}" is not present on the contract`, { meta: {
45
+ reason: "domain-namespace-missing",
46
+ namespaceId
47
+ } });
46
48
  return domainNamespace.models;
47
49
  }
48
50
  /**
@@ -96,6 +98,6 @@ function isExecutionMutationDefaultValue(value) {
96
98
  return true;
97
99
  }
98
100
  //#endregion
99
- export { CrossReferenceSchema, DomainNamespaceResolutionError, UNBOUND_DOMAIN_NAMESPACE_ID, asNamespaceId, coreHash, crossRef, domainModelsAtDefaultNamespace, domainValueObjectsAtDefaultNamespace, effectiveControlPolicy, executionHash, isColumnDefault, isColumnDefaultLiteralInputValue, isExecutionMutationDefaultValue, profileHash, resolveDomainModel, soleDomainNamespaceId };
101
+ export { CrossReferenceSchema, UNBOUND_DOMAIN_NAMESPACE_ID, asNamespaceId, coreHash, crossRef, domainModelsAtDefaultNamespace, domainValueObjectsAtDefaultNamespace, effectiveControlPolicy, executionHash, isColumnDefault, isColumnDefaultLiteralInputValue, isExecutionMutationDefaultValue, profileHash, resolveDomainModel, soleDomainNamespaceId };
100
102
 
101
103
  //# sourceMappingURL=types.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/control-policy.ts","../src/cross-reference.ts","../src/domain-namespace-access.ts","../src/types.ts"],"sourcesContent":["/**\n * Governance posture for a storage-plane node or for the contract as a whole.\n *\n * - `managed` — Prisma Next owns the full lifecycle (DDL, migrations, verification).\n * - `tolerated` — node was found in the database but is not schema-managed; Prisma Next\n * leaves it untouched while tracking its existence.\n * - `external` — node is owned by an external system; Prisma Next never emits DDL for it.\n * - `observed` — read-only access; Prisma Next does not write to or migrate the node.\n */\nexport type ControlPolicy = 'managed' | 'tolerated' | 'external' | 'observed';\n\n/**\n * Resolves the effective control policy for a storage-plane node.\n *\n * Precedence: node-level value → contract default → `'managed'`.\n *\n * Both parameters are optional raw values so this function stays node-type-agnostic\n * and can be called by any consumer (verifier, planner, etc.) without importing IR classes.\n */\nexport function effectiveControlPolicy(\n nodeControl: ControlPolicy | undefined,\n defaultControlPolicy: ControlPolicy | undefined,\n): ControlPolicy {\n return nodeControl ?? defaultControlPolicy ?? 'managed';\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport { type Type, type } from 'arktype';\nimport { asNamespaceId, type NamespaceId } from './namespace-id';\n\nexport interface CrossReference {\n readonly namespace: NamespaceId;\n readonly model: string;\n /**\n * Contract-space identity for cross-space relations. When present, the\n * referenced model lives in a different contract space. Absent for local\n * (same-space) relations.\n */\n readonly space?: string;\n}\n\nexport const CrossReferenceSchema = /* @__PURE__ */ blindCast<\n Type<CrossReference>,\n 'namespace is validated as string at runtime and branded to NamespaceId by asNamespaceId in crossRef(); the schema accepts plain strings but the public type reflects the branded shape'\n>(\n /* @__PURE__ */ type({\n '+': 'reject',\n namespace: 'string',\n model: 'string',\n 'space?': 'string',\n }),\n);\n\nconst DEFAULT_CROSS_REF_NAMESPACE = '__unbound__';\n\nexport function crossRef(\n model: string,\n namespace: string = DEFAULT_CROSS_REF_NAMESPACE,\n space?: string,\n): CrossReference {\n return {\n namespace: asNamespaceId(namespace),\n model,\n ...(space !== undefined ? { space } : {}),\n };\n}\n","import { DomainNamespaceResolutionError } from './contract-validation-error';\nimport { soleDomainNamespaceId } from './default-namespace';\nimport type { ApplicationDomain } from './domain-envelope';\nimport type { ContractModelBase, ContractValueObject } from './domain-types';\n\n/**\n * Models map for the contract's single domain namespace. Throws when the\n * contract does not declare exactly one namespace — bare-name access is\n * ambiguous across namespaces and must be qualified explicitly (TML-2550).\n */\nexport function domainModelsAtDefaultNamespace(\n domain: ApplicationDomain,\n): Record<string, ContractModelBase> {\n const namespaceId = soleDomainNamespaceId(domain);\n const domainNamespace = domain.namespaces[namespaceId];\n if (domainNamespace === undefined) {\n throw new DomainNamespaceResolutionError(\n `domain namespace \"${namespaceId}\" is not present on the contract`,\n );\n }\n return domainNamespace.models;\n}\n\n/**\n * Value objects for the contract's single domain namespace, when present.\n * Throws when the contract does not declare exactly one namespace.\n */\nexport function domainValueObjectsAtDefaultNamespace(\n domain: ApplicationDomain,\n): Record<string, ContractValueObject> | undefined {\n return domain.namespaces[soleDomainNamespaceId(domain)]?.valueObjects;\n}\n","/**\n * Unique symbol used as the key for branding types.\n */\nexport const $: unique symbol = Symbol('__prisma_next_brand__');\n\n/**\n * A helper type to brand a given type with a unique identifier.\n *\n * @template TKey Text used as the brand key.\n * @template TValue Optional value associated with the brand key. Defaults to `true`.\n */\nexport type Brand<TKey extends string | number | symbol, TValue = true> = {\n [$]: {\n [K in TKey]: TValue;\n };\n};\n\n/**\n * Base type for storage contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type StorageHash = StorageHashBase<'sha256:abc123...'>`\n */\nexport type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;\n\n/**\n * Base type for execution contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`\n */\nexport type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;\n\nexport function executionHash<const T extends string>(value: T): ExecutionHashBase<T> {\n return value as ExecutionHashBase<T>;\n}\n\nexport function coreHash<const T extends string>(value: T): StorageHashBase<T> {\n return value as StorageHashBase<T>;\n}\n\n/**\n * Base type for profile contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`\n */\nexport type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;\n\nexport function profileHash<const T extends string>(value: T): ProfileHashBase<T> {\n return value as ProfileHashBase<T>;\n}\n\n/**\n * One entity-kind slot in a namespace — a map of entity name to entry.\n * Values are opaque at the foundation layer; family and target concretions\n * refine them to typed IR classes.\n */\nexport type StorageEntitySlot = Readonly<Record<string, unknown>>;\n\n/**\n * Plain-data namespace entry in a storage block. Every hydrated contract\n * carries at least `id` plus entity-kind slot maps under `entries`\n * (`table`, `collection`, …). Foundation declares only this shape — no IR\n * machinery.\n */\nexport interface StorageNamespace {\n readonly id: string;\n readonly entries: Readonly<Record<string, StorageEntitySlot>>;\n}\n\n/**\n * Base type for family-specific storage blocks.\n * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the\n * storage hash alongside family-specific data (tables, collections, etc.).\n *\n * The `namespaces` map is carried by every hydrated storage block. Serialized\n * envelope shape is target-owned; this types the in-memory contract after\n * `deserializeContract`.\n */\nexport interface StorageBase<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, StorageNamespace>>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport type GeneratedValueSpec = {\n readonly id: string;\n readonly params?: Record<string, unknown>;\n};\n\nexport type JsonPrimitive = string | number | boolean | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | { readonly [key: string]: JsonValue }\n | readonly JsonValue[];\n\nexport type ColumnDefaultLiteralValue = JsonValue;\n\nexport type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | Date;\n\n/**\n * Runtime predicate for `ColumnDefaultLiteralInputValue`. Authoring layers\n * resolve template values from caller-supplied args (typed `unknown` at the\n * boundary) and need to validate before constructing a `ColumnDefault`.\n * Accepts JSON primitives, plain arrays/objects of JSON values, and `Date`\n * instances. Rejects functions, class instances (other than `Date`),\n * `undefined`, `bigint`, `symbol`, and arrays/objects containing those.\n */\nexport function isColumnDefaultLiteralInputValue(\n value: unknown,\n): value is ColumnDefaultLiteralInputValue {\n if (value === null) return true;\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') return true;\n if (value instanceof Date) return true;\n if (Array.isArray(value)) return value.every(isColumnDefaultLiteralInputValue);\n if (t === 'object' && Object.getPrototypeOf(value) === Object.prototype) {\n return Object.values(value as Record<string, unknown>).every(isColumnDefaultLiteralInputValue);\n }\n return false;\n}\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly value: ColumnDefaultLiteralInputValue;\n }\n | { readonly kind: 'function'; readonly expression: string };\n\nexport function isColumnDefault(value: unknown): value is ColumnDefault {\n if (typeof value !== 'object' || value === null) return false;\n const kind = (value as { kind?: unknown }).kind;\n if (kind === 'literal') {\n return 'value' in value;\n }\n if (kind === 'function') {\n return typeof (value as { expression?: unknown }).expression === 'string';\n }\n return false;\n}\n\nexport type ExecutionMutationDefaultValue = {\n readonly kind: 'generator';\n readonly id: GeneratedValueSpec['id'];\n readonly params?: Record<string, unknown>;\n};\n\nexport function isExecutionMutationDefaultValue(\n value: unknown,\n): value is ExecutionMutationDefaultValue {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as {\n kind?: unknown;\n id?: unknown;\n params?: unknown;\n };\n if (candidate.kind !== 'generator') return false;\n if (typeof candidate.id !== 'string') return false;\n if (\n candidate.params !== undefined &&\n (typeof candidate.params !== 'object' ||\n candidate.params === null ||\n Array.isArray(candidate.params))\n ) {\n return false;\n }\n return true;\n}\n\nexport type ExecutionMutationDefault = {\n readonly ref: { readonly namespace: string; readonly table: string; readonly column: string };\n readonly onCreate?: ExecutionMutationDefaultValue;\n readonly onUpdate?: ExecutionMutationDefaultValue;\n};\n\n/**\n * `ExecutionMutationDefault` minus its `ref` — the per-field phases value\n * authoring layers attach to a column before the column ref is known.\n */\nexport type ExecutionMutationDefaultPhases = Omit<ExecutionMutationDefault, 'ref'>;\n\nexport type ExecutionSection<THash extends string = string> = {\n readonly executionHash: ExecutionHashBase<THash>;\n readonly mutations: {\n readonly defaults: ReadonlyArray<ExecutionMutationDefault>;\n };\n};\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly storageHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n readonly [key: string]: unknown;\n };\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n readonly invariants: readonly string[];\n}\n\n/**\n * One applied migration edge from the per-space ledger journal.\n * Returned by `readLedger` in append (apply) order.\n */\nexport interface LedgerEntryRecord {\n readonly space: string;\n readonly migrationName: string;\n readonly migrationHash: string;\n readonly from: string | null;\n readonly to: string;\n readonly appliedAt: Date;\n readonly operationCount: number;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,uBACd,aACA,sBACe;CACf,OAAO,eAAe,wBAAwB;AAChD;;;ACTA,MAAa,uBAAuC,0BAIlC,qBAAK;CACnB,KAAK;CACL,WAAW;CACX,OAAO;CACP,UAAU;AACZ,CAAC,CACH;AAEA,MAAM,8BAA8B;AAEpC,SAAgB,SACd,OACA,YAAoB,6BACpB,OACgB;CAChB,OAAO;EACL,WAAW,cAAc,SAAS;EAClC;EACA,GAAI,UAAU,KAAA,IAAY,EAAE,MAAM,IAAI,CAAC;CACzC;AACF;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AC3B,UAAU,WAAW,QACrB,MAAM,QAAQ,UAAU,MAAM,IAEhC,OAAO;CAET,OAAO;AACT"}
1
+ {"version":3,"file":"types.mjs","names":[],"sources":["../src/control-policy.ts","../src/cross-reference.ts","../src/domain-namespace-access.ts","../src/types.ts"],"sourcesContent":["/**\n * Governance posture for a storage-plane node or for the contract as a whole.\n *\n * - `managed` — Prisma Next owns the full lifecycle (DDL, migrations, verification).\n * - `tolerated` — node was found in the database but is not schema-managed; Prisma Next\n * leaves it untouched while tracking its existence.\n * - `external` — node is owned by an external system; Prisma Next never emits DDL for it.\n * - `observed` — read-only access; Prisma Next does not write to or migrate the node.\n */\nexport type ControlPolicy = 'managed' | 'tolerated' | 'external' | 'observed';\n\n/**\n * Resolves the effective control policy for a storage-plane node.\n *\n * Precedence: node-level value → contract default → `'managed'`.\n *\n * Both parameters are optional raw values so this function stays node-type-agnostic\n * and can be called by any consumer (verifier, planner, etc.) without importing IR classes.\n */\nexport function effectiveControlPolicy(\n nodeControl: ControlPolicy | undefined,\n defaultControlPolicy: ControlPolicy | undefined,\n): ControlPolicy {\n return nodeControl ?? defaultControlPolicy ?? 'managed';\n}\n","import { blindCast } from '@prisma-next/utils/casts';\nimport { type Type, type } from 'arktype';\nimport { asNamespaceId, type NamespaceId } from './namespace-id';\n\nexport interface CrossReference {\n readonly namespace: NamespaceId;\n readonly model: string;\n /**\n * Contract-space identity for cross-space relations. When present, the\n * referenced model lives in a different contract space. Absent for local\n * (same-space) relations.\n */\n readonly space?: string;\n}\n\nexport const CrossReferenceSchema = /* @__PURE__ */ blindCast<\n Type<CrossReference>,\n 'namespace is validated as string at runtime and branded to NamespaceId by asNamespaceId in crossRef(); the schema accepts plain strings but the public type reflects the branded shape'\n>(\n /* @__PURE__ */ type({\n '+': 'reject',\n namespace: 'string',\n model: 'string',\n 'space?': 'string',\n }),\n);\n\nconst DEFAULT_CROSS_REF_NAMESPACE = '__unbound__';\n\nexport function crossRef(\n model: string,\n namespace: string = DEFAULT_CROSS_REF_NAMESPACE,\n space?: string,\n): CrossReference {\n return {\n namespace: asNamespaceId(namespace),\n model,\n ...(space !== undefined ? { space } : {}),\n };\n}\n","import { contractError } from './contract-errors';\nimport { soleDomainNamespaceId } from './default-namespace';\nimport type { ApplicationDomain } from './domain-envelope';\nimport type { ContractModelBase, ContractValueObject } from './domain-types';\n\n/**\n * Models map for the contract's single domain namespace. Throws when the\n * contract does not declare exactly one namespace — bare-name access is\n * ambiguous across namespaces and must be qualified explicitly (TML-2550).\n */\nexport function domainModelsAtDefaultNamespace(\n domain: ApplicationDomain,\n): Record<string, ContractModelBase> {\n const namespaceId = soleDomainNamespaceId(domain);\n const domainNamespace = domain.namespaces[namespaceId];\n if (domainNamespace === undefined) {\n throw contractError(\n 'CONTRACT.NAMESPACE_INVALID',\n `domain namespace \"${namespaceId}\" is not present on the contract`,\n { meta: { reason: 'domain-namespace-missing', namespaceId } },\n );\n }\n return domainNamespace.models;\n}\n\n/**\n * Value objects for the contract's single domain namespace, when present.\n * Throws when the contract does not declare exactly one namespace.\n */\nexport function domainValueObjectsAtDefaultNamespace(\n domain: ApplicationDomain,\n): Record<string, ContractValueObject> | undefined {\n return domain.namespaces[soleDomainNamespaceId(domain)]?.valueObjects;\n}\n","/**\n * Unique symbol used as the key for branding types.\n */\nexport const $: unique symbol = Symbol('__prisma_next_brand__');\n\n/**\n * A helper type to brand a given type with a unique identifier.\n *\n * @template TKey Text used as the brand key.\n * @template TValue Optional value associated with the brand key. Defaults to `true`.\n */\nexport type Brand<TKey extends string | number | symbol, TValue = true> = {\n [$]: {\n [K in TKey]: TValue;\n };\n};\n\n/**\n * Base type for storage contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type StorageHash = StorageHashBase<'abc123...'>`\n */\nexport type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;\n\n/**\n * Base type for execution contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ExecutionHash = ExecutionHashBase<'def456...'>`\n */\nexport type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;\n\nexport function executionHash<const T extends string>(value: T): ExecutionHashBase<T> {\n return value as ExecutionHashBase<T>;\n}\n\nexport function coreHash<const T extends string>(value: T): StorageHashBase<T> {\n return value as StorageHashBase<T>;\n}\n\n/**\n * Base type for profile contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ProfileHash = ProfileHashBase<'def456...'>`\n */\nexport type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;\n\nexport function profileHash<const T extends string>(value: T): ProfileHashBase<T> {\n return value as ProfileHashBase<T>;\n}\n\n/**\n * One entity-kind slot in a namespace — a map of entity name to entry.\n * Values are opaque at the foundation layer; family and target concretions\n * refine them to typed IR classes.\n */\nexport type StorageEntitySlot = Readonly<Record<string, unknown>>;\n\n/**\n * Plain-data namespace entry in a storage block. Every hydrated contract\n * carries at least `id` plus entity-kind slot maps under `entries`\n * (`table`, `collection`, …). Foundation declares only this shape — no IR\n * machinery.\n */\nexport interface StorageNamespace {\n readonly id: string;\n readonly entries: Readonly<Record<string, StorageEntitySlot>>;\n}\n\n/**\n * Base type for family-specific storage blocks.\n * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the\n * storage hash alongside family-specific data (tables, collections, etc.).\n *\n * The `namespaces` map is carried by every hydrated storage block. Serialized\n * envelope shape is target-owned; this types the in-memory contract after\n * `deserializeContract`.\n */\nexport interface StorageBase<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, StorageNamespace>>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport type GeneratedValueSpec = {\n readonly id: string;\n readonly params?: Record<string, unknown>;\n};\n\nexport type JsonPrimitive = string | number | boolean | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | { readonly [key: string]: JsonValue }\n | readonly JsonValue[];\n\nexport type ColumnDefaultLiteralValue = JsonValue;\n\nexport type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | Date;\n\n/**\n * Runtime predicate for `ColumnDefaultLiteralInputValue`. Authoring layers\n * resolve template values from caller-supplied args (typed `unknown` at the\n * boundary) and need to validate before constructing a `ColumnDefault`.\n * Accepts JSON primitives, plain arrays/objects of JSON values, and `Date`\n * instances. Rejects functions, class instances (other than `Date`),\n * `undefined`, `bigint`, `symbol`, and arrays/objects containing those.\n */\nexport function isColumnDefaultLiteralInputValue(\n value: unknown,\n): value is ColumnDefaultLiteralInputValue {\n if (value === null) return true;\n const t = typeof value;\n if (t === 'string' || t === 'number' || t === 'boolean') return true;\n if (value instanceof Date) return true;\n if (Array.isArray(value)) return value.every(isColumnDefaultLiteralInputValue);\n if (t === 'object' && Object.getPrototypeOf(value) === Object.prototype) {\n return Object.values(value as Record<string, unknown>).every(isColumnDefaultLiteralInputValue);\n }\n return false;\n}\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly value: ColumnDefaultLiteralInputValue;\n }\n | { readonly kind: 'function'; readonly expression: string };\n\nexport function isColumnDefault(value: unknown): value is ColumnDefault {\n if (typeof value !== 'object' || value === null) return false;\n const kind = (value as { kind?: unknown }).kind;\n if (kind === 'literal') {\n return 'value' in value;\n }\n if (kind === 'function') {\n return typeof (value as { expression?: unknown }).expression === 'string';\n }\n return false;\n}\n\nexport type ExecutionMutationDefaultValue = {\n readonly kind: 'generator';\n readonly id: GeneratedValueSpec['id'];\n readonly params?: Record<string, unknown>;\n};\n\nexport function isExecutionMutationDefaultValue(\n value: unknown,\n): value is ExecutionMutationDefaultValue {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as {\n kind?: unknown;\n id?: unknown;\n params?: unknown;\n };\n if (candidate.kind !== 'generator') return false;\n if (typeof candidate.id !== 'string') return false;\n if (\n candidate.params !== undefined &&\n (typeof candidate.params !== 'object' ||\n candidate.params === null ||\n Array.isArray(candidate.params))\n ) {\n return false;\n }\n return true;\n}\n\nexport type ExecutionMutationDefault = {\n readonly ref: { readonly namespace: string; readonly table: string; readonly column: string };\n readonly onCreate?: ExecutionMutationDefaultValue;\n readonly onUpdate?: ExecutionMutationDefaultValue;\n};\n\n/**\n * `ExecutionMutationDefault` minus its `ref` — the per-field phases value\n * authoring layers attach to a column before the column ref is known.\n */\nexport type ExecutionMutationDefaultPhases = Omit<ExecutionMutationDefault, 'ref'>;\n\nexport type ExecutionSection<THash extends string = string> = {\n readonly executionHash: ExecutionHashBase<THash>;\n readonly mutations: {\n readonly defaults: ReadonlyArray<ExecutionMutationDefault>;\n };\n};\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly storageHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n readonly [key: string]: unknown;\n };\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n readonly invariants: readonly string[];\n}\n\n/**\n * One applied migration edge from the per-space ledger journal.\n * Returned by `readLedger` in append (apply) order.\n */\nexport interface LedgerEntryRecord {\n readonly space: string;\n readonly migrationName: string;\n readonly migrationHash: string;\n readonly from: string | null;\n readonly to: string;\n readonly appliedAt: Date;\n readonly operationCount: number;\n}\n"],"mappings":";;;;;;;;;;;;;;AAmBA,SAAgB,uBACd,aACA,sBACe;CACf,OAAO,eAAe,wBAAwB;AAChD;;;ACTA,MAAa,uBAAuC,0BAIlC,qBAAK;CACnB,KAAK;CACL,WAAW;CACX,OAAO;CACP,UAAU;AACZ,CAAC,CACH;AAEA,MAAM,8BAA8B;AAEpC,SAAgB,SACd,OACA,YAAoB,6BACpB,OACgB;CAChB,OAAO;EACL,WAAW,cAAc,SAAS;EAClC;EACA,GAAI,UAAU,KAAA,IAAY,EAAE,MAAM,IAAI,CAAC;CACzC;AACF;;;;;;;;AC7BA,SAAgB,+BACd,QACmC;CACnC,MAAM,cAAc,sBAAsB,MAAM;CAChD,MAAM,kBAAkB,OAAO,WAAW;CAC1C,IAAI,oBAAoB,KAAA,GACtB,MAAM,cACJ,8BACA,qBAAqB,YAAY,mCACjC,EAAE,MAAM;EAAE,QAAQ;EAA4B;CAAY,EAAE,CAC9D;CAEF,OAAO,gBAAgB;AACzB;;;;;AAMA,SAAgB,qCACd,QACiD;CACjD,OAAO,OAAO,WAAW,sBAAsB,MAAM,EAAE,EAAE;AAC3D;;;ACFA,SAAgB,cAAsC,OAAgC;CACpF,OAAO;AACT;AAEA,SAAgB,SAAiC,OAA8B;CAC7E,OAAO;AACT;AASA,SAAgB,YAAoC,OAA8B;CAChF,OAAO;AACT;;;;;;;;;AAiEA,SAAgB,iCACd,OACyC;CACzC,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,IAAI,OAAO;CACjB,IAAI,MAAM,YAAY,MAAM,YAAY,MAAM,WAAW,OAAO;CAChE,IAAI,iBAAiB,MAAM,OAAO;CAClC,IAAI,MAAM,QAAQ,KAAK,GAAG,OAAO,MAAM,MAAM,gCAAgC;CAC7E,IAAI,MAAM,YAAY,OAAO,eAAe,KAAK,MAAM,OAAO,WAC5D,OAAO,OAAO,OAAO,KAAgC,CAAC,CAAC,MAAM,gCAAgC;CAE/F,OAAO;AACT;AASA,SAAgB,gBAAgB,OAAwC;CACtE,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,OAAQ,MAA6B;CAC3C,IAAI,SAAS,WACX,OAAO,WAAW;CAEpB,IAAI,SAAS,YACX,OAAO,OAAQ,MAAmC,eAAe;CAEnE,OAAO;AACT;AAQA,SAAgB,gCACd,OACwC;CACxC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,MAAM,YAAY;CAKlB,IAAI,UAAU,SAAS,aAAa,OAAO;CAC3C,IAAI,OAAO,UAAU,OAAO,UAAU,OAAO;CAC7C,IACE,UAAU,WAAW,KAAA,MACpB,OAAO,UAAU,WAAW,YAC3B,UAAU,WAAW,QACrB,MAAM,QAAQ,UAAU,MAAM,IAEhC,OAAO;CAET,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { it as CrossReference, r as ContractWithDomain } from "./domain-envelope-CXbPct2s.mjs";
1
+ import { it as CrossReference, r as ContractWithDomain } from "./domain-envelope-D6Wn9AmZ.mjs";
2
2
  //#region src/validate-domain.d.ts
3
3
  interface DomainModelShape {
4
4
  readonly fields: Record<string, unknown>;
@@ -1,5 +1,5 @@
1
- import { t as ContractValidationError } from "./contract-validation-error-BFA66rwU.mjs";
2
1
  import { t as asNamespaceId } from "./namespace-id-CUxYd4KL.mjs";
2
+ import { t as ContractValidationError } from "./contract-validation-error-DEiWp_EI.mjs";
3
3
  //#region src/validate-domain.ts
4
4
  function indexDomainModels(contract) {
5
5
  const index = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.16.0-dev.3",
3
+ "version": "0.16.0-dev.31",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "Data contract type definitions and JSON schema for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/utils": "0.16.0-dev.3",
9
+ "@prisma-next/utils": "0.16.0-dev.31",
10
10
  "@standard-schema/spec": "^1.1.0",
11
11
  "arktype": "^2.2.2"
12
12
  },
13
13
  "devDependencies": {
14
- "@prisma-next/tsconfig": "0.16.0-dev.3",
15
- "@prisma-next/tsdown": "0.16.0-dev.3",
14
+ "@prisma-next/tsconfig": "0.16.0-dev.31",
15
+ "@prisma-next/tsdown": "0.16.0-dev.31",
16
16
  "tsdown": "0.22.8",
17
17
  "typescript": "5.9.3",
18
18
  "vitest": "4.1.10"
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "storageHash": {
28
28
  "type": "string",
29
- "pattern": "^sha256:[a-f0-9]{64}$",
29
+ "pattern": "^[a-f0-9]{64}$",
30
30
  "description": "SHA-256 hash of the storage section (DB-satisfied expectations)"
31
31
  },
32
32
  "profileHash": {
33
33
  "type": "string",
34
- "pattern": "^sha256:[a-f0-9]{64}$",
34
+ "pattern": "^[a-f0-9]{64}$",
35
35
  "description": "SHA-256 hash of the pinned capability profile (capability keys/variants and adapter pins)"
36
36
  },
37
37
  "capabilities": {
@@ -44,7 +44,7 @@
44
44
  }
45
45
  }
46
46
  },
47
- "extensionPacks": {
47
+ "extensions": {
48
48
  "type": "object",
49
49
  "description": "Extension packs and their configuration",
50
50
  "additionalProperties": true
@@ -74,7 +74,7 @@ const TOP_LEVEL_ORDER = [
74
74
  'storage',
75
75
  'execution',
76
76
  'capabilities',
77
- 'extensionPacks',
77
+ 'extensions',
78
78
  'defaultControlPolicy',
79
79
  'meta',
80
80
  ] as const;
@@ -133,7 +133,7 @@ function omitDefaults(
133
133
  STORAGE_NAMESPACE_ENTRIES_PATTERN,
134
134
  );
135
135
  const isRequiredRoots = isArrayEqual(currentPath, ['roots']);
136
- const isRequiredExtensionPacks = isArrayEqual(currentPath, ['extensionPacks']);
136
+ const isRequiredExtensions = isArrayEqual(currentPath, ['extensions']);
137
137
  const isRequiredCapabilities = isArrayEqual(currentPath, ['capabilities']);
138
138
  const isRequiredMeta = isArrayEqual(currentPath, ['meta']);
139
139
  const isRequiredExecutionDefaults = isArrayEqual(currentPath, [
@@ -141,7 +141,7 @@ function omitDefaults(
141
141
  'mutations',
142
142
  'defaults',
143
143
  ]);
144
- const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensionPacks';
144
+ const isExtensionNamespace = currentPath.length === 2 && currentPath[0] === 'extensions';
145
145
  const isModelRelations = matchesPathPattern(currentPath, DOMAIN_MODEL_RELATIONS_PATTERN);
146
146
  const isModelStorage = matchesPathPattern(currentPath, DOMAIN_MODEL_STORAGE_PATTERN);
147
147
 
@@ -156,7 +156,7 @@ function omitDefaults(
156
156
  !isRequiredStorageNamespaces &&
157
157
  !isStorageNamespaceEntries &&
158
158
  !isRequiredRoots &&
159
- !isRequiredExtensionPacks &&
159
+ !isRequiredExtensions &&
160
160
  !isRequiredCapabilities &&
161
161
  !isRequiredMeta &&
162
162
  !isRequiredExecutionDefaults &&
@@ -261,7 +261,7 @@ export function canonicalizeContractToObject(
261
261
  domain: serialized['domain'],
262
262
  storage: serialized['storage'],
263
263
  ...ifDefined('execution', serialized['execution']),
264
- extensionPacks: serialized['extensionPacks'],
264
+ extensions: serialized['extensions'],
265
265
  capabilities: serialized['capabilities'],
266
266
  ...ifDefined('defaultControlPolicy', serialized['defaultControlPolicy']),
267
267
  meta: serialized['meta'],
@@ -0,0 +1,14 @@
1
+ import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';
2
+ import { structuredError } from '@prisma-next/utils/structured-error';
3
+
4
+ export type ContractCode = `CONTRACT.${ContractSubcode}`;
5
+
6
+ type ContractSubcode = 'NAMESPACE_INVALID';
7
+
8
+ export function contractError(
9
+ code: ContractCode,
10
+ message: string,
11
+ options?: StructuredErrorOptions,
12
+ ): StructuredError {
13
+ return structuredError(code, message, options);
14
+ }
@@ -48,7 +48,7 @@ export interface Contract<TStorage extends StorageBase = StorageBase> {
48
48
  readonly domain: ApplicationDomain;
49
49
  readonly storage: TStorage;
50
50
  readonly capabilities: Record<string, Record<string, boolean>>;
51
- readonly extensionPacks: Record<string, unknown>;
51
+ readonly extensions: Record<string, unknown>;
52
52
  readonly execution?: ContractExecutionSection;
53
53
  readonly profileHash: ProfileHashBase<string>;
54
54
  readonly meta: Record<string, unknown>;
@@ -10,10 +10,3 @@ export class ContractValidationError extends Error {
10
10
  this.phase = phase;
11
11
  }
12
12
  }
13
-
14
- export class DomainNamespaceResolutionError extends Error {
15
- constructor(message: string) {
16
- super(message);
17
- this.name = 'DomainNamespaceResolutionError';
18
- }
19
- }
@@ -1,4 +1,4 @@
1
- import { DomainNamespaceResolutionError } from './contract-validation-error';
1
+ import { contractError } from './contract-errors';
2
2
 
3
3
  /**
4
4
  * Reserved sentinel domain namespace id for the late-bound application-domain
@@ -24,12 +24,16 @@ export function soleDomainNamespaceId(domain: {
24
24
  }): string {
25
25
  const [soleNamespaceId, ...rest] = Object.keys(domain.namespaces);
26
26
  if (soleNamespaceId === undefined) {
27
- throw new DomainNamespaceResolutionError('domain has no namespaces');
27
+ throw contractError('CONTRACT.NAMESPACE_INVALID', 'domain has no namespaces', {
28
+ meta: { reason: 'no-domain-namespaces' },
29
+ });
28
30
  }
29
31
  if (rest.length > 0) {
30
32
  const all = [soleNamespaceId, ...rest];
31
- throw new DomainNamespaceResolutionError(
33
+ throw contractError(
34
+ 'CONTRACT.NAMESPACE_INVALID',
32
35
  `bare-name resolution requires exactly one domain namespace, found ${all.length} (${all.join(', ')}); select a namespace explicitly`,
36
+ { meta: { reason: 'multiple-domain-namespaces', namespaceIds: all } },
33
37
  );
34
38
  }
35
39
  return soleNamespaceId;
@@ -1,4 +1,4 @@
1
- import { DomainNamespaceResolutionError } from './contract-validation-error';
1
+ import { contractError } from './contract-errors';
2
2
  import { soleDomainNamespaceId } from './default-namespace';
3
3
  import type { ApplicationDomain } from './domain-envelope';
4
4
  import type { ContractModelBase, ContractValueObject } from './domain-types';
@@ -14,8 +14,10 @@ export function domainModelsAtDefaultNamespace(
14
14
  const namespaceId = soleDomainNamespaceId(domain);
15
15
  const domainNamespace = domain.namespaces[namespaceId];
16
16
  if (domainNamespace === undefined) {
17
- throw new DomainNamespaceResolutionError(
17
+ throw contractError(
18
+ 'CONTRACT.NAMESPACE_INVALID',
18
19
  `domain namespace "${namespaceId}" is not present on the contract`,
20
+ { meta: { reason: 'domain-namespace-missing', namespaceId } },
19
21
  );
20
22
  }
21
23
  return domainNamespace.models;
@@ -1,5 +1,4 @@
1
1
  export {
2
2
  ContractValidationError,
3
3
  type ContractValidationPhase,
4
- DomainNamespaceResolutionError,
5
4
  } from '../contract-validation-error';
@@ -3,7 +3,6 @@ export type {
3
3
  ContractExecutionSection,
4
4
  ContractValueObjectDefinitions,
5
5
  } from '../contract-types';
6
- export { DomainNamespaceResolutionError } from '../contract-validation-error';
7
6
  export type { ControlPolicy } from '../control-policy';
8
7
  export { effectiveControlPolicy } from '../control-policy';
9
8
  export type { CrossReference } from '../cross-reference';
package/src/hashing.ts CHANGED
@@ -39,7 +39,7 @@ function omitNamespaceKindsForHash(storage: unknown): unknown {
39
39
  function sha256(content: string): string {
40
40
  const hash = createHash('sha256');
41
41
  hash.update(content);
42
- return `sha256:${hash.digest('hex')}`;
42
+ return hash.digest('hex');
43
43
  }
44
44
 
45
45
  type HashContractSection = Record<string, unknown> & {
@@ -56,7 +56,7 @@ function hashContract(section: HashContractSection): string {
56
56
  roots: {},
57
57
  domain: { namespaces: {} },
58
58
  execution: sectionData['execution'],
59
- extensionPacks: {},
59
+ extensions: {},
60
60
  capabilities: sectionData['capabilities'] ?? {},
61
61
  meta: {},
62
62
  profileHash: '',
package/src/types.ts CHANGED
@@ -18,14 +18,14 @@ export type Brand<TKey extends string | number | symbol, TValue = true> = {
18
18
  /**
19
19
  * Base type for storage contract hashes.
20
20
  * Emitted contract.d.ts files use this with the hash value as a type parameter:
21
- * `type StorageHash = StorageHashBase<'sha256:abc123...'>`
21
+ * `type StorageHash = StorageHashBase<'abc123...'>`
22
22
  */
23
23
  export type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;
24
24
 
25
25
  /**
26
26
  * Base type for execution contract hashes.
27
27
  * Emitted contract.d.ts files use this with the hash value as a type parameter:
28
- * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`
28
+ * `type ExecutionHash = ExecutionHashBase<'def456...'>`
29
29
  */
30
30
  export type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;
31
31
 
@@ -40,7 +40,7 @@ export function coreHash<const T extends string>(value: T): StorageHashBase<T> {
40
40
  /**
41
41
  * Base type for profile contract hashes.
42
42
  * Emitted contract.d.ts files use this with the hash value as a type parameter:
43
- * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`
43
+ * `type ProfileHash = ProfileHashBase<'def456...'>`
44
44
  */
45
45
  export type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;
46
46
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-types-BVJDOpEC.d.mts","names":[],"sources":["../src/control-policy.ts","../src/contract-types.ts"],"mappings":";;;;;;;;;;;KASY;;;;;;;;;iBAUI,uBACd,aAAa,2BACb,sBAAsB,4BACrB;;;;;;;;;;;;KCFS,yBAAyB;WAC1B,eAAe,kBAAkB;WACjC;aACE,UAAU,cAAc;;;;;;;;;;;;;;;;UAiBpB,SAAS,iBAAiB,cAAc;WAC9C;WACA;WACA,OAAO,eAAe;;;;WAItB,QAAQ;WACR,SAAS;WACT,cAAc,eAAe;WAC7B,gBAAgB;WAChB,YAAY;WACZ,aAAa;WACb,MAAM;WACN,uBAAuB;;KAG7B,oBAAoB,UAAU,iCAAiC,iBAAgB,mBAC5E,YACG,YAAY,QACjB;KAID,wBAAwB,cAAc;WAChC,qBAAqB;IAE5B,WAAW,eAAe,uBACxB,KACA,uBACF;;KAGQ,+BAA+B,kBAAkB,YAC3D,wBACE,kCAAkC,oBAAoB,oDACxC,aACZ,kBAAkB,eAAe,uBAC/B,YACA,uBACF"}
@@ -1,20 +0,0 @@
1
- //#region src/contract-validation-error.ts
2
- var ContractValidationError = class extends Error {
3
- code = "CONTRACT.VALIDATION_FAILED";
4
- phase;
5
- constructor(message, phase) {
6
- super(message);
7
- this.name = "ContractValidationError";
8
- this.phase = phase;
9
- }
10
- };
11
- var DomainNamespaceResolutionError = class extends Error {
12
- constructor(message) {
13
- super(message);
14
- this.name = "DomainNamespaceResolutionError";
15
- }
16
- };
17
- //#endregion
18
- export { DomainNamespaceResolutionError as n, ContractValidationError as t };
19
-
20
- //# sourceMappingURL=contract-validation-error-BFA66rwU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-validation-error-BFA66rwU.mjs","names":[],"sources":["../src/contract-validation-error.ts"],"sourcesContent":["export type ContractValidationPhase = 'structural' | 'domain' | 'storage';\n\nexport class ContractValidationError extends Error {\n readonly code = 'CONTRACT.VALIDATION_FAILED';\n readonly phase: ContractValidationPhase;\n\n constructor(message: string, phase: ContractValidationPhase) {\n super(message);\n this.name = 'ContractValidationError';\n this.phase = phase;\n }\n}\n\nexport class DomainNamespaceResolutionError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'DomainNamespaceResolutionError';\n }\n}\n"],"mappings":";AAEA,IAAa,0BAAb,cAA6C,MAAM;CACjD,OAAgB;CAChB;CAEA,YAAY,SAAiB,OAAgC;EAC3D,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,QAAQ;CACf;AACF;AAEA,IAAa,iCAAb,cAAoD,MAAM;CACxD,YAAY,SAAiB;EAC3B,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF"}
@@ -1,13 +0,0 @@
1
- //#region src/contract-validation-error.d.ts
2
- type ContractValidationPhase = 'structural' | 'domain' | 'storage';
3
- declare class ContractValidationError extends Error {
4
- readonly code = "CONTRACT.VALIDATION_FAILED";
5
- readonly phase: ContractValidationPhase;
6
- constructor(message: string, phase: ContractValidationPhase);
7
- }
8
- declare class DomainNamespaceResolutionError extends Error {
9
- constructor(message: string);
10
- }
11
- //#endregion
12
- export { ContractValidationPhase as n, DomainNamespaceResolutionError as r, ContractValidationError as t };
13
- //# sourceMappingURL=contract-validation-error-D7g0kmcc.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-validation-error-D7g0kmcc.d.mts","names":[],"sources":["../src/contract-validation-error.ts"],"mappings":";KAAY;cAEC,gCAAgC;WAClC;WACA,OAAO;cAEJ,iBAAiB,OAAO;;cAOzB,uCAAuC;cACtC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"default-namespace-rpdJeUMq.mjs","names":[],"sources":["../src/default-namespace.ts"],"sourcesContent":["import { DomainNamespaceResolutionError } from './contract-validation-error';\n\n/**\n * Reserved sentinel domain namespace id for the late-bound application-domain\n * slot — the namespace a model lands in when it is authored without an explicit\n * namespace. This is target-agnostic: targets that allow un-namespaced\n * authoring (e.g. Mongo, SQLite) declare this id as their default on the target\n * descriptor; the framework names the sentinel, never a target. Mirrors\n * storage's `UNBOUND_NAMESPACE_ID` on the domain plane.\n */\nexport const UNBOUND_DOMAIN_NAMESPACE_ID = '__unbound__' as const;\n\n/**\n * Resolve the single domain namespace of a single-namespace contract.\n *\n * Bare-name access (`db.User`) reads \"the contract's one namespace\". Every\n * contract in scope today declares exactly one domain namespace, so this is\n * exact — there is nothing to infer. A contract that declares more than one\n * namespace is ambiguous for a bare name, so rather than silently pick one this\n * throws; cross-namespace selection is made explicit (TML-2550).\n */\nexport function soleDomainNamespaceId(domain: {\n readonly namespaces: Readonly<Record<string, unknown>>;\n}): string {\n const [soleNamespaceId, ...rest] = Object.keys(domain.namespaces);\n if (soleNamespaceId === undefined) {\n throw new DomainNamespaceResolutionError('domain has no namespaces');\n }\n if (rest.length > 0) {\n const all = [soleNamespaceId, ...rest];\n throw new DomainNamespaceResolutionError(\n `bare-name resolution requires exactly one domain namespace, found ${all.length} (${all.join(', ')}); select a namespace explicitly`,\n );\n }\n return soleNamespaceId;\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAa,8BAA8B;;;;;;;;;;AAW3C,SAAgB,sBAAsB,QAE3B;CACT,MAAM,CAAC,iBAAiB,GAAG,QAAQ,OAAO,KAAK,OAAO,UAAU;CAChE,IAAI,oBAAoB,KAAA,GACtB,MAAM,IAAI,+BAA+B,0BAA0B;CAErE,IAAI,KAAK,SAAS,GAAG;EACnB,MAAM,MAAM,CAAC,iBAAiB,GAAG,IAAI;EACrC,MAAM,IAAI,+BACR,qEAAqE,IAAI,OAAO,IAAI,IAAI,KAAK,IAAI,EAAE,iCACrG;CACF;CACA,OAAO;AACT"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-domain-model-CfMSnbL2.d.mts","names":[],"sources":["../src/resolve-domain-model.ts"],"mappings":";;UAGiB;WACN;WACA,OAAO;;;;;;;;iBASF,mBACd,QAAQ,mBACR,oBACC"}