@prisma-next/contract 0.13.0-dev.1 → 0.13.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { d as ContractModelBase, t as ApplicationDomain } from "./domain-envelope-OkWsysCY.mjs";
1
+ import { d as ContractModelBase, t as ApplicationDomain } from "./domain-envelope-DKOnhO5d.mjs";
2
2
 
3
3
  //#region src/resolve-domain-model.d.ts
4
4
  interface ResolvedDomainModel {
@@ -14,4 +14,4 @@ interface ResolvedDomainModel {
14
14
  declare function resolveDomainModel(domain: ApplicationDomain, modelName: string): ResolvedDomainModel | undefined;
15
15
  //#endregion
16
16
  export { resolveDomainModel as n, ResolvedDomainModel as t };
17
- //# sourceMappingURL=resolve-domain-model-BhAr8VRJ.d.mts.map
17
+ //# sourceMappingURL=resolve-domain-model-CSEqpByI.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-domain-model-BhAr8VRJ.d.mts","names":[],"sources":["../src/resolve-domain-model.ts"],"mappings":";;;UAGiB,mBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,iBAAiB;AAAA;;;;;;AAAA;iBASnB,kBAAA,CACd,MAAA,EAAQ,iBAAA,EACR,SAAA,WACC,mBAAmB"}
1
+ {"version":3,"file":"resolve-domain-model-CSEqpByI.d.mts","names":[],"sources":["../src/resolve-domain-model.ts"],"mappings":";;;UAGiB,mBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,iBAAiB;AAAA;;;;;;AAAA;iBASnB,kBAAA,CACd,MAAA,EAAQ,iBAAA,EACR,SAAA,WACC,mBAAmB"}
@@ -1,2 +1,2 @@
1
- import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-BhAr8VRJ.mjs";
1
+ import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-CSEqpByI.mjs";
2
2
  export { type ResolvedDomainModel, resolveDomainModel };
package/dist/types.d.mts CHANGED
@@ -1,8 +1,8 @@
1
- import { A as StorageNamespace, C as LedgerEntryRecord, D as StorageBase, E as Source, F as isExecutionMutationDefaultValue, I as profileHash, L as ControlPolicy, M as executionHash, N as isColumnDefault, O as StorageEntitySlot, P as isColumnDefaultLiteralInputValue, R as effectiveControlPolicy, S as JsonValue, T as ProfileHashBase, _ as ExecutionSection, a as $, b as GeneratedValueSpec, c as ColumnDefaultLiteralInputValue, d as DocCollection, f as DocIndex, g as ExecutionMutationDefaultValue, h as ExecutionMutationDefaultPhases, i as ContractValueObjectDefinitions, j as coreHash, k as StorageHashBase, l as ColumnDefaultLiteralValue, m as ExecutionMutationDefault, n as ContractExecutionSection, o as Brand, p as ExecutionHashBase, r as ContractModelDefinitions, s as ColumnDefault, t as Contract, u as ContractMarkerRecord, v as Expr, w as PlanMeta, x as JsonPrimitive, y as FieldType } from "./contract-types-CBbD-VV1.mjs";
2
- import { A as asNamespaceId, C as UnionFieldType, D as CrossReferenceSchema, E as CrossReference, O as crossRef, S as ScalarFieldType, T as ValueSetRef, _ as ContractValueObject, a as ContractEmbedRelation, b as ModelStorageBase, c as ContractFieldType, d as ContractModelBase, f as ContractNonJunctionRelation, g as ContractRelationThrough, h as ContractRelationOn, i as ContractDiscriminator, k as NamespaceId, l as ContractManyToManyRelation, m as ContractRelation, n as ApplicationDomainNamespace, o as ContractEnum, p as ContractReferenceRelation, r as ContractWithDomain, s as ContractField, t as ApplicationDomain, u as ContractModel, v as ContractVariantEntry, w as ValueObjectFieldType, x as ReferenceRelationKeys, y as EmbedRelationKeys } from "./domain-envelope-OkWsysCY.mjs";
1
+ import { a as ControlPolicy, i as ContractValueObjectDefinitions, n as ContractExecutionSection, o as effectiveControlPolicy, r as ContractModelDefinitions, t as Contract } from "./contract-types-CtIh62PH.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-DKOnhO5d.mjs";
3
3
  import { n as soleDomainNamespaceId, t as UNBOUND_DOMAIN_NAMESPACE_ID } from "./default-namespace-D5X_k6hJ.mjs";
4
4
  import { r as DomainNamespaceResolutionError } from "./contract-validation-error-D7g0kmcc.mjs";
5
- import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-BhAr8VRJ.mjs";
5
+ import { n as resolveDomainModel, t as ResolvedDomainModel } from "./resolve-domain-model-CSEqpByI.mjs";
6
6
 
7
7
  //#region src/domain-namespace-access.d.ts
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { E as CrossReference, r as ContractWithDomain } from "./domain-envelope-OkWsysCY.mjs";
1
+ import { it as CrossReference, r as ContractWithDomain } from "./domain-envelope-DKOnhO5d.mjs";
2
2
 
3
3
  //#region src/validate-domain.d.ts
4
4
  interface DomainModelShape {
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@prisma-next/contract",
3
- "version": "0.13.0-dev.1",
3
+ "version": "0.13.0-dev.10",
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.13.0-dev.1",
9
+ "@prisma-next/utils": "0.13.0-dev.10",
10
10
  "@standard-schema/spec": "^1.1.0",
11
11
  "arktype": "^2.2.0"
12
12
  },
13
13
  "devDependencies": {
14
- "@prisma-next/tsconfig": "0.13.0-dev.1",
15
- "@prisma-next/tsdown": "0.13.0-dev.1",
14
+ "@prisma-next/tsconfig": "0.13.0-dev.10",
15
+ "@prisma-next/tsdown": "0.13.0-dev.10",
16
16
  "tsdown": "0.22.1",
17
17
  "typescript": "5.9.3",
18
18
  "vitest": "4.1.8"
@@ -34,6 +34,7 @@
34
34
  "./apply-specifier-default-control-policy": "./dist/apply-specifier-default-control-policy.mjs",
35
35
  "./contract-validation-error": "./dist/contract-validation-error.mjs",
36
36
  "./default-namespace": "./dist/default-namespace.mjs",
37
+ "./enum-accessor": "./dist/enum-accessor.mjs",
37
38
  "./hashing": "./dist/hashing.mjs",
38
39
  "./hashing-utils": "./dist/hashing-utils.mjs",
39
40
  "./resolve-domain-model": "./dist/resolve-domain-model.mjs",
@@ -1,4 +1,5 @@
1
1
  import type { CrossReference } from './cross-reference';
2
+ import type { JsonValue } from './types';
2
3
  import type { ValueSetRef } from './value-set-ref';
3
4
 
4
5
  export type ScalarFieldType = {
@@ -34,7 +35,7 @@ export type ContractField = {
34
35
  */
35
36
  export type ContractEnum = {
36
37
  readonly codecId: string;
37
- readonly members: readonly { readonly name: string; readonly value: string }[];
38
+ readonly members: readonly { readonly name: string; readonly value: JsonValue }[];
38
39
  };
39
40
 
40
41
  export type ContractRelationOn = {
@@ -0,0 +1,173 @@
1
+ import type { Contract } from './contract-types';
2
+ import type { ContractEnum } from './domain-types';
3
+ import type { JsonValue } from './types';
4
+
5
+ /**
6
+ * Runtime view of a domain enum, built at the client from the emitted
7
+ * `ContractEnum` JSON (codec-encoded `JsonValue` members, literal types erased).
8
+ *
9
+ * This deliberately mirrors the accessor shape of the authoring-time
10
+ * `EnumTypeHandle` (in `contract-ts`) rather than reusing it: that handle carries
11
+ * the literal value generics and lives in the authoring layer, which the
12
+ * foundation layer cannot depend on. The two are the same surface seen from the
13
+ * two planes — authoring (typed) and runtime (validated JSON).
14
+ */
15
+ export interface EnumAccessor {
16
+ readonly values: readonly JsonValue[];
17
+ readonly names: readonly string[];
18
+ readonly members: Readonly<Record<string, JsonValue>>;
19
+ has(v: JsonValue): boolean;
20
+ nameOf(v: JsonValue): string | undefined;
21
+ ordinalOf(v: JsonValue): number;
22
+ }
23
+
24
+ export function createEnumAccessor(contractEnum: ContractEnum): EnumAccessor {
25
+ const values = Object.freeze(contractEnum.members.map((m) => m.value));
26
+ const names = Object.freeze(contractEnum.members.map((m) => m.name));
27
+ const members: Readonly<Record<string, JsonValue>> = Object.freeze(
28
+ Object.fromEntries(contractEnum.members.map((m) => [m.name, m.value])),
29
+ );
30
+
31
+ const valueSet = new Set(values);
32
+ const valueToName = new Map(contractEnum.members.map((m) => [m.value, m.name]));
33
+ const valueToOrdinal = new Map(values.map((v, i) => [v, i]));
34
+
35
+ return {
36
+ values,
37
+ names,
38
+ members,
39
+ has: (v: JsonValue) => valueSet.has(v),
40
+ nameOf: (v: JsonValue) => valueToName.get(v),
41
+ ordinalOf: (v: JsonValue) => valueToOrdinal.get(v) ?? -1,
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Build the enum-accessor map for a single namespace, keyed by enum name.
47
+ * Each namespace facet exposes only its own enums — the IR keys enums under
48
+ * `domain.namespaces[ns].enum`, so the same name in two namespaces resolves
49
+ * independently rather than colliding in one flat map.
50
+ */
51
+ export function buildEnumsMapForNamespace(
52
+ domain: {
53
+ readonly namespaces: Readonly<
54
+ Record<string, { readonly enum?: Readonly<Record<string, ContractEnum>> }>
55
+ >;
56
+ },
57
+ namespaceId: string,
58
+ ): Record<string, EnumAccessor> {
59
+ const result: Record<string, EnumAccessor> = {};
60
+ const namespace = domain.namespaces[namespaceId];
61
+ if (namespace?.enum) {
62
+ for (const [name, contractEnum] of Object.entries(namespace.enum)) {
63
+ result[name] = createEnumAccessor(contractEnum);
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+
69
+ /**
70
+ * Build the enum-accessor map for every namespace of a domain, keyed by
71
+ * namespace id then enum name. This is the lane-agnostic enum surface the
72
+ * `db.enums` facade member exposes: enums are contract metadata, the same
73
+ * whether reached through the sql lane or the orm lane, so the facade builds
74
+ * this once and projects it per target.
75
+ */
76
+ export function buildNamespacedEnums(domain: {
77
+ readonly namespaces: Readonly<
78
+ Record<string, { readonly enum?: Readonly<Record<string, ContractEnum>> }>
79
+ >;
80
+ }): Record<string, Record<string, EnumAccessor>> {
81
+ const result: Record<string, Record<string, EnumAccessor>> = {};
82
+ for (const namespaceId of Object.keys(domain.namespaces)) {
83
+ result[namespaceId] = buildEnumsMapForNamespace(domain, namespaceId);
84
+ }
85
+ return result;
86
+ }
87
+
88
+ // ---------------------------------------------------------------------------
89
+ // Type-level projection of the namespaced enum surface.
90
+ //
91
+ // These types derive the literal-preserving accessor shape from the contract,
92
+ // hung off the `db.enums` facade map (`db.enums.<ns>.<Name>`). They are the
93
+ // same accessors the runtime builds above, but typed from the two emission
94
+ // paths:
95
+ // - Emitted contracts carry the literal enum entries under
96
+ // `domain.namespaces[ns].enum`; each maps to a `ContractEnumAccessor`.
97
+ // - The no-emit (built) contract carries them flat on `enumAccessors`
98
+ // (already accessor-shaped, literal-preserving), since its built domain
99
+ // type does not narrow `namespaces[ns].enum`. All authored enums land in
100
+ // the single built namespace, so exposing the flat map per namespace is
101
+ // correct there.
102
+ // Only `SqlContractResult` carries `enumAccessors`; emitted contracts never
103
+ // do, so the two carriers never overlap.
104
+ // ---------------------------------------------------------------------------
105
+
106
+ type Present<T> = Exclude<T, undefined>;
107
+
108
+ // A domain enum entry as carried in `domain.namespaces[ns].enum[name]`: an
109
+ // ordered member tuple. The no-emit (built) path preserves the literal member
110
+ // values so the derived accessor keeps its literal `values`/`names`/`members`.
111
+ type EnumMemberEntry = { readonly name: string; readonly value: unknown };
112
+ type EnumEntry = { readonly members: readonly EnumMemberEntry[] };
113
+
114
+ type EnumEntryValues<Entry extends EnumEntry> = {
115
+ readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry
116
+ ? Entry['members'][I]['value']
117
+ : never;
118
+ };
119
+
120
+ type EnumEntryNames<Entry extends EnumEntry> = {
121
+ readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry
122
+ ? Entry['members'][I]['name']
123
+ : never;
124
+ };
125
+
126
+ type EnumEntryMembers<Entry extends EnumEntry> = {
127
+ readonly [M in Entry['members'][number] as M['name']]: M['value'];
128
+ };
129
+
130
+ // The runtime accessor shape for one enum, with literal `values`/`names`/
131
+ // `members` derived from the entry's member tuple. Mirrors `EnumAccessor`'s
132
+ // runtime surface and the authoring `EnumTypeHandle` accessor.
133
+ export type ContractEnumAccessor<Entry extends EnumEntry> = {
134
+ readonly values: EnumEntryValues<Entry>;
135
+ readonly names: EnumEntryNames<Entry>;
136
+ readonly members: EnumEntryMembers<Entry>;
137
+ has(v: EnumEntryValues<Entry>[number]): boolean;
138
+ nameOf(v: EnumEntryValues<Entry>[number]): string | undefined;
139
+ ordinalOf(v: EnumEntryValues<Entry>[number]): number;
140
+ };
141
+
142
+ type EnumEntriesToAccessors<Enums> = {
143
+ readonly [K in keyof Enums]: Enums[K] extends EnumEntry ? ContractEnumAccessor<Enums[K]> : never;
144
+ };
145
+
146
+ type BuiltEnumAccessorsOf<TContract> = TContract extends {
147
+ readonly enumAccessors: infer A;
148
+ }
149
+ ? A
150
+ : Record<never, never>;
151
+
152
+ type NamespaceEnumEntries<TNamespace> = TNamespace extends {
153
+ readonly enum?: infer E;
154
+ }
155
+ ? unknown extends E
156
+ ? Record<never, never>
157
+ : Present<E>
158
+ : Record<never, never>;
159
+
160
+ // The per-namespace enum accessors. Each namespace exposes only its own enums
161
+ // (the IR's `domain.namespaces[ns].enum`), so the same enum name in two
162
+ // namespaces resolves to each namespace's own accessor.
163
+ export type NamespaceEnumAccessors<
164
+ TContract extends Contract,
165
+ NsId extends keyof TContract['domain']['namespaces'],
166
+ > = EnumEntriesToAccessors<NamespaceEnumEntries<TContract['domain']['namespaces'][NsId]>> &
167
+ BuiltEnumAccessorsOf<TContract>;
168
+
169
+ // The lane-agnostic enum surface exposed on the `db.enums` facade member: a
170
+ // namespace-keyed map projected per target exactly like `db.sql` / `db.orm`.
171
+ export type NamespacedEnums<TContract extends Contract> = {
172
+ readonly [Ns in keyof TContract['domain']['namespaces']]: NamespaceEnumAccessors<TContract, Ns>;
173
+ };
@@ -0,0 +1,11 @@
1
+ export type {
2
+ ContractEnumAccessor,
3
+ EnumAccessor,
4
+ NamespacedEnums,
5
+ NamespaceEnumAccessors,
6
+ } from '../enum-accessor';
7
+ export {
8
+ buildEnumsMapForNamespace,
9
+ buildNamespacedEnums,
10
+ createEnumAccessor,
11
+ } from '../enum-accessor';
@@ -1,271 +0,0 @@
1
- import { E as CrossReference, _ as ContractValueObject, d as ContractModelBase, t as ApplicationDomain } from "./domain-envelope-OkWsysCY.mjs";
2
-
3
- //#region src/control-policy.d.ts
4
- /**
5
- * Governance posture for a storage-plane node or for the contract as a whole.
6
- *
7
- * - `managed` — Prisma Next owns the full lifecycle (DDL, migrations, verification).
8
- * - `tolerated` — node was found in the database but is not schema-managed; Prisma Next
9
- * leaves it untouched while tracking its existence.
10
- * - `external` — node is owned by an external system; Prisma Next never emits DDL for it.
11
- * - `observed` — read-only access; Prisma Next does not write to or migrate the node.
12
- */
13
- type ControlPolicy = 'managed' | 'tolerated' | 'external' | 'observed';
14
- /**
15
- * Resolves the effective control policy for a storage-plane node.
16
- *
17
- * Precedence: node-level value → contract default → `'managed'`.
18
- *
19
- * Both parameters are optional raw values so this function stays node-type-agnostic
20
- * and can be called by any consumer (verifier, planner, etc.) without importing IR classes.
21
- */
22
- declare function effectiveControlPolicy(nodeControl: ControlPolicy | undefined, defaultControlPolicy: ControlPolicy | undefined): ControlPolicy;
23
- //#endregion
24
- //#region src/types.d.ts
25
- /**
26
- * Unique symbol used as the key for branding types.
27
- */
28
- declare const $: unique symbol;
29
- /**
30
- * A helper type to brand a given type with a unique identifier.
31
- *
32
- * @template TKey Text used as the brand key.
33
- * @template TValue Optional value associated with the brand key. Defaults to `true`.
34
- */
35
- type Brand<TKey extends string | number | symbol, TValue = true> = {
36
- [$]: { [K in TKey]: TValue };
37
- };
38
- /**
39
- * Base type for storage contract hashes.
40
- * Emitted contract.d.ts files use this with the hash value as a type parameter:
41
- * `type StorageHash = StorageHashBase<'sha256:abc123...'>`
42
- */
43
- type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;
44
- /**
45
- * Base type for execution contract hashes.
46
- * Emitted contract.d.ts files use this with the hash value as a type parameter:
47
- * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`
48
- */
49
- type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;
50
- declare function executionHash<const T extends string>(value: T): ExecutionHashBase<T>;
51
- declare function coreHash<const T extends string>(value: T): StorageHashBase<T>;
52
- /**
53
- * Base type for profile contract hashes.
54
- * Emitted contract.d.ts files use this with the hash value as a type parameter:
55
- * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`
56
- */
57
- type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;
58
- declare function profileHash<const T extends string>(value: T): ProfileHashBase<T>;
59
- /**
60
- * One entity-kind slot in a namespace — a map of entity name to entry.
61
- * Values are opaque at the foundation layer; family and target concretions
62
- * refine them to typed IR classes.
63
- */
64
- type StorageEntitySlot = Readonly<Record<string, unknown>>;
65
- /**
66
- * Plain-data namespace entry in a storage block. Every hydrated contract
67
- * carries at least `id` plus entity-kind slot maps under `entries`
68
- * (`table`, `collection`, …). Foundation declares only this shape — no IR
69
- * machinery.
70
- */
71
- interface StorageNamespace {
72
- readonly id: string;
73
- readonly entries: Readonly<Record<string, StorageEntitySlot>>;
74
- }
75
- /**
76
- * Base type for family-specific storage blocks.
77
- * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the
78
- * storage hash alongside family-specific data (tables, collections, etc.).
79
- *
80
- * The `namespaces` map is carried by every hydrated storage block. Serialized
81
- * envelope shape is target-owned; this types the in-memory contract after
82
- * `deserializeContract`.
83
- */
84
- interface StorageBase<THash extends string = string> {
85
- readonly storageHash: StorageHashBase<THash>;
86
- readonly namespaces: Readonly<Record<string, StorageNamespace>>;
87
- }
88
- interface FieldType {
89
- readonly type: string;
90
- readonly nullable: boolean;
91
- readonly items?: FieldType;
92
- readonly properties?: Record<string, FieldType>;
93
- }
94
- type GeneratedValueSpec = {
95
- readonly id: string;
96
- readonly params?: Record<string, unknown>;
97
- };
98
- type JsonPrimitive = string | number | boolean | null;
99
- type JsonValue = JsonPrimitive | {
100
- readonly [key: string]: JsonValue;
101
- } | readonly JsonValue[];
102
- type ColumnDefaultLiteralValue = JsonValue;
103
- type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | Date;
104
- /**
105
- * Runtime predicate for `ColumnDefaultLiteralInputValue`. Authoring layers
106
- * resolve template values from caller-supplied args (typed `unknown` at the
107
- * boundary) and need to validate before constructing a `ColumnDefault`.
108
- * Accepts JSON primitives, plain arrays/objects of JSON values, and `Date`
109
- * instances. Rejects functions, class instances (other than `Date`),
110
- * `undefined`, `bigint`, `symbol`, and arrays/objects containing those.
111
- */
112
- declare function isColumnDefaultLiteralInputValue(value: unknown): value is ColumnDefaultLiteralInputValue;
113
- type ColumnDefault = {
114
- readonly kind: 'literal';
115
- readonly value: ColumnDefaultLiteralInputValue;
116
- } | {
117
- readonly kind: 'function';
118
- readonly expression: string;
119
- };
120
- declare function isColumnDefault(value: unknown): value is ColumnDefault;
121
- type ExecutionMutationDefaultValue = {
122
- readonly kind: 'generator';
123
- readonly id: GeneratedValueSpec['id'];
124
- readonly params?: Record<string, unknown>;
125
- };
126
- declare function isExecutionMutationDefaultValue(value: unknown): value is ExecutionMutationDefaultValue;
127
- type ExecutionMutationDefault = {
128
- readonly ref: {
129
- readonly table: string;
130
- readonly column: string;
131
- };
132
- readonly onCreate?: ExecutionMutationDefaultValue;
133
- readonly onUpdate?: ExecutionMutationDefaultValue;
134
- };
135
- /**
136
- * `ExecutionMutationDefault` minus its `ref` — the per-field phases value
137
- * authoring layers attach to a column before the column ref is known.
138
- */
139
- type ExecutionMutationDefaultPhases = Omit<ExecutionMutationDefault, 'ref'>;
140
- type ExecutionSection<THash extends string = string> = {
141
- readonly executionHash: ExecutionHashBase<THash>;
142
- readonly mutations: {
143
- readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
144
- };
145
- };
146
- interface Source {
147
- readonly readOnly: boolean;
148
- readonly projection: Record<string, FieldType>;
149
- readonly origin?: Record<string, unknown>;
150
- readonly capabilities?: Record<string, boolean>;
151
- }
152
- interface DocIndex {
153
- readonly name: string;
154
- readonly keys: Record<string, 'asc' | 'desc'>;
155
- readonly unique?: boolean;
156
- readonly where?: Expr;
157
- }
158
- type Expr = {
159
- readonly kind: 'eq';
160
- readonly path: ReadonlyArray<string>;
161
- readonly value: unknown;
162
- } | {
163
- readonly kind: 'exists';
164
- readonly path: ReadonlyArray<string>;
165
- };
166
- interface DocCollection {
167
- readonly name: string;
168
- readonly id?: {
169
- readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';
170
- };
171
- readonly fields: Record<string, FieldType>;
172
- readonly indexes?: ReadonlyArray<DocIndex>;
173
- readonly readOnly?: boolean;
174
- }
175
- interface PlanMeta {
176
- readonly target: string;
177
- readonly targetFamily?: string;
178
- readonly storageHash: string;
179
- readonly profileHash?: string;
180
- readonly lane: string;
181
- readonly annotations?: {
182
- readonly [key: string]: unknown;
183
- };
184
- }
185
- /**
186
- * Contract marker record stored in the database.
187
- * Represents the current contract identity for a database.
188
- */
189
- interface ContractMarkerRecord {
190
- readonly storageHash: string;
191
- readonly profileHash: string;
192
- readonly contractJson: unknown | null;
193
- readonly canonicalVersion: number | null;
194
- readonly updatedAt: Date;
195
- readonly appTag: string | null;
196
- readonly meta: Record<string, unknown>;
197
- readonly invariants: readonly string[];
198
- }
199
- /**
200
- * One applied migration edge from the per-space ledger journal.
201
- * Returned by `readLedger` in append (apply) order.
202
- */
203
- interface LedgerEntryRecord {
204
- readonly space: string;
205
- readonly migrationName: string;
206
- readonly migrationHash: string;
207
- readonly from: string | null;
208
- readonly to: string;
209
- readonly appliedAt: Date;
210
- readonly operationCount: number;
211
- }
212
- //#endregion
213
- //#region src/contract-types.d.ts
214
- /**
215
- * Execution section for the unified contract (ADR 182).
216
- *
217
- * Unlike the legacy {@link import('./types').ExecutionSection}, this type
218
- * requires `executionHash` — when an execution section is present, its
219
- * hash must be too (consistent with `StorageBase.storageHash`).
220
- *
221
- * @template THash Literal hash string type for type-safe hash tracking.
222
- */
223
- type ContractExecutionSection<THash extends string = string> = {
224
- readonly executionHash: ExecutionHashBase<THash>;
225
- readonly mutations: {
226
- readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
227
- };
228
- };
229
- /**
230
- * Unified contract representation (ADR 182).
231
- *
232
- * A `Contract` is the canonical in-memory representation of a data contract.
233
- * It is model-first (domain models carry their own storage bridge) and
234
- * family-parameterized (SQL, Mongo, etc. specialize via `TStorage` and model
235
- * storage generics on `ContractModel`).
236
- *
237
- * JSON persistence fields (`schemaVersion`, `sources`) are not represented
238
- * here — they are handled at the serialization boundary.
239
- *
240
- * @template TStorage Family-specific storage block (extends {@link StorageBase}).
241
- * @template TModels Record of model name → {@link ContractModel} with
242
- * family-specific model storage.
243
- */
244
- interface Contract<TStorage extends StorageBase = StorageBase, TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>> {
245
- readonly target: string;
246
- readonly targetFamily: string;
247
- readonly roots: Record<string, CrossReference>;
248
- /**
249
- * Application plane (ADR 221): `domain.namespaces.<nsId>.{ models, valueObjects }`.
250
- * `TModels` types the union of model entries across namespaces for family DSL inference.
251
- */
252
- readonly domain: ApplicationDomain<TModels>;
253
- readonly storage: TStorage;
254
- readonly capabilities: Record<string, Record<string, boolean>>;
255
- readonly extensionPacks: Record<string, unknown>;
256
- readonly execution?: ContractExecutionSection;
257
- readonly profileHash: ProfileHashBase<string>;
258
- readonly meta: Record<string, unknown>;
259
- readonly defaultControlPolicy?: ControlPolicy;
260
- }
261
- /** Model definitions union carried on a {@link Contract}'s `TModels` type parameter. */
262
- type ContractModelDefinitions<TContract extends Contract> = TContract extends Contract<StorageBase, infer TModels> ? TModels : never;
263
- type ExactlyOneNamespace<T extends Record<string, unknown>> = keyof T extends infer Only extends keyof T ? [keyof T] extends [Only] ? Only : never : never;
264
- type NamespaceValueObjectsOf<TNamespace> = TNamespace extends {
265
- readonly valueObjects?: infer VO;
266
- } ? VO extends Record<string, ContractValueObject> ? VO : Record<never, never> : Record<never, never>;
267
- /** Value-object map when the contract declares exactly one domain namespace. */
268
- 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>;
269
- //#endregion
270
- export { StorageNamespace as A, LedgerEntryRecord as C, StorageBase as D, Source as E, isExecutionMutationDefaultValue as F, profileHash as I, ControlPolicy as L, executionHash as M, isColumnDefault as N, StorageEntitySlot as O, isColumnDefaultLiteralInputValue as P, effectiveControlPolicy as R, JsonValue as S, ProfileHashBase as T, ExecutionSection as _, $ as a, GeneratedValueSpec as b, ColumnDefaultLiteralInputValue as c, DocCollection as d, DocIndex as f, ExecutionMutationDefaultValue as g, ExecutionMutationDefaultPhases as h, ContractValueObjectDefinitions as i, coreHash as j, StorageHashBase as k, ColumnDefaultLiteralValue as l, ExecutionMutationDefault as m, ContractExecutionSection as n, Brand as o, ExecutionHashBase as p, ContractModelDefinitions as r, ColumnDefault as s, Contract as t, ContractMarkerRecord as u, Expr as v, PlanMeta as w, JsonPrimitive as x, FieldType as y };
271
- //# sourceMappingURL=contract-types-CBbD-VV1.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-types-CBbD-VV1.d.mts","names":[],"sources":["../src/control-policy.ts","../src/types.ts","../src/contract-types.ts"],"mappings":";;;;;;AASA;;;;AAAyB;AAUzB;KAVY,aAAA;;;;;;;;;iBAUI,sBAAA,CACd,WAAA,EAAa,aAAA,cACb,oBAAA,EAAsB,aAAA,eACrB,aAAA;;;;;;cCnBU,CAAA;;;;ADMY;AAUzB;;KCRY,KAAA;EAAA,CACT,CAAA,WACO,IAAA,GAAO,MAAA;AAAA;;;;;;KASL,eAAA,yBAAwC,KAAA,GAAQ,KAAK;;ADAjD;;;;KCOJ,iBAAA,yBAA0C,KAAA,GAAQ,KAAK;AAAA,iBAEnD,aAAA,yBAAsC,KAAA,EAAO,CAAA,GAAI,iBAAA,CAAkB,CAAA;AAAA,iBAInE,QAAA,yBAAiC,KAAA,EAAO,CAAA,GAAI,eAAA,CAAgB,CAAA;;AAhCb;AAQ/D;;;KAiCY,eAAA,yBAAwC,KAAA,GAAQ,KAAK;AAAA,iBAEjD,WAAA,yBAAoC,KAAA,EAAO,CAAA,GAAI,eAAA,CAAgB,CAAA;;;;;;KASnE,iBAAA,GAAoB,QAAQ,CAAC,MAAA;;;;;AA1ClB;AASvB;UAyCiB,gBAAA;EAAA,SACN,EAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,iBAAA;AAAA;;;;AA3CqB;AAOjE;;;;;UAgDiB,WAAA;EAAA,SACN,WAAA,EAAa,eAAA,CAAgB,KAAA;EAAA,SAC7B,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,gBAAA;AAAA;AAAA,UAG9B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