@prisma-next/contract 0.13.0-dev.2 → 0.13.0-dev.21

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 { L as ControlPolicy, t as Contract } from "./contract-types-CBbD-VV1.mjs";
1
+ import { a as ControlPolicy, t as Contract } from "./contract-types-ci3TUzpo.mjs";
2
2
 
3
3
  //#region src/apply-specifier-default-control-policy.d.ts
4
4
  declare function applySpecifierDefaultControlPolicy(contract: Contract, specifierDefault: ControlPolicy | undefined): Contract;
@@ -1,4 +1,4 @@
1
- import { t as Contract } from "./contract-types-CBbD-VV1.mjs";
1
+ import { t as Contract } from "./contract-types-ci3TUzpo.mjs";
2
2
  import { JsonObject } from "@prisma-next/utils/json";
3
3
 
4
4
  //#region src/canonicalization.d.ts
@@ -66,4 +66,4 @@ declare function canonicalizeContractToObject(contract: Contract, options: Canon
66
66
  declare function canonicalizeContract(contract: Contract, options: CanonicalizeContractOptions): string;
67
67
  //#endregion
68
68
  export { canonicalizeContract as a, StorageSort as i, PreserveEmptyPredicate as n, canonicalizeContractToObject as o, SerializeContract as r, CanonicalizeContractOptions as t };
69
- //# sourceMappingURL=canonicalization-ChdV0ueh.d.mts.map
69
+ //# sourceMappingURL=canonicalization-C2ecs9k1.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"canonicalization-ChdV0ueh.d.mts","names":[],"sources":["../src/canonicalization.ts"],"mappings":";;;;;;AAcA;;;;;;KAAY,iBAAA,IAAqB,QAAA,EAAU,QAAA,KAAa,UAAU;;AAAA;AAUlE;;;;AAA6D;AAS7D;KATY,sBAAA,IAA0B,IAAuB;;;AASlB;AAqL3C;;;;KArLY,WAAA,IAAe,OAAgB;AAAA,UAqL1B,2BAAA;EAAA,SACN,aAAA;EAAA;;;;;;;;AA0ByB;AAQpC;EAlCW,SAWA,iBAAA,EAAmB,iBAAA;;;;;;;WAOnB,mBAAA,GAAsB,sBAAA;EAiB/B;;;;;AAEO;AA2BT;EA7BE,SATS,WAAA,GAAc,WAAA;AAAA;;;;;;iBAQT,4BAAA,CACd,QAAA,EAAU,QAAA,EACV,OAAA,EAAS,2BAAA,GACR,MAAA;AAAA,iBA2Ba,oBAAA,CACd,QAAA,EAAU,QAAA,EACV,OAAA,EAAS,2BAA2B"}
1
+ {"version":3,"file":"canonicalization-C2ecs9k1.d.mts","names":[],"sources":["../src/canonicalization.ts"],"mappings":";;;;;;AAcA;;;;;;KAAY,iBAAA,IAAqB,QAAA,EAAU,QAAA,KAAa,UAAU;;AAAA;AAUlE;;;;AAA6D;AAS7D;KATY,sBAAA,IAA0B,IAAuB;;;AASlB;AAqL3C;;;;KArLY,WAAA,IAAe,OAAgB;AAAA,UAqL1B,2BAAA;EAAA,SACN,aAAA;EAAA;;;;;;;;AA0ByB;AAQpC;EAlCW,SAWA,iBAAA,EAAmB,iBAAA;;;;;;;WAOnB,mBAAA,GAAsB,sBAAA;EAiB/B;;;;;AAEO;AA2BT;EA7BE,SATS,WAAA,GAAc,WAAA;AAAA;;;;;;iBAQT,4BAAA,CACd,QAAA,EAAU,QAAA,EACV,OAAA,EAAS,2BAAA,GACR,MAAA;AAAA,iBA2Ba,oBAAA,CACd,QAAA,EAAU,QAAA,EACV,OAAA,EAAS,2BAA2B"}
@@ -0,0 +1,82 @@
1
+ import { F as ExecutionMutationDefault, J as StorageBase, K as ProfileHashBase, P as ExecutionHashBase, _ as ContractValueObject, d as ContractModelBase, it as CrossReference, t as ApplicationDomain } from "./domain-envelope-Czz8UMhU.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/contract-types.d.ts
25
+ /**
26
+ * Execution section for the unified contract (ADR 182).
27
+ *
28
+ * Unlike the legacy {@link import('./types').ExecutionSection}, this type
29
+ * requires `executionHash` — when an execution section is present, its
30
+ * hash must be too (consistent with `StorageBase.storageHash`).
31
+ *
32
+ * @template THash Literal hash string type for type-safe hash tracking.
33
+ */
34
+ type ContractExecutionSection<THash extends string = string> = {
35
+ readonly executionHash: ExecutionHashBase<THash>;
36
+ readonly mutations: {
37
+ readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
38
+ };
39
+ };
40
+ /**
41
+ * Unified contract representation (ADR 182).
42
+ *
43
+ * A `Contract` is the canonical in-memory representation of a data contract.
44
+ * It is model-first (domain models carry their own storage bridge) and
45
+ * family-parameterized (SQL, Mongo, etc. specialize via `TStorage` and model
46
+ * storage generics on `ContractModel`).
47
+ *
48
+ * JSON persistence fields (`schemaVersion`, `sources`) are not represented
49
+ * here — they are handled at the serialization boundary.
50
+ *
51
+ * @template TStorage Family-specific storage block (extends {@link StorageBase}).
52
+ * @template TModels Record of model name → {@link ContractModel} with
53
+ * family-specific model storage.
54
+ */
55
+ interface Contract<TStorage extends StorageBase = StorageBase, TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>> {
56
+ readonly target: string;
57
+ readonly targetFamily: string;
58
+ readonly roots: Record<string, CrossReference>;
59
+ /**
60
+ * Application plane (ADR 221): `domain.namespaces.<nsId>.{ models, valueObjects }`.
61
+ * `TModels` types the union of model entries across namespaces for family DSL inference.
62
+ */
63
+ readonly domain: ApplicationDomain<TModels>;
64
+ readonly storage: TStorage;
65
+ readonly capabilities: Record<string, Record<string, boolean>>;
66
+ readonly extensionPacks: Record<string, unknown>;
67
+ readonly execution?: ContractExecutionSection;
68
+ readonly profileHash: ProfileHashBase<string>;
69
+ readonly meta: Record<string, unknown>;
70
+ readonly defaultControlPolicy?: ControlPolicy;
71
+ }
72
+ /** Model definitions union carried on a {@link Contract}'s `TModels` type parameter. */
73
+ type ContractModelDefinitions<TContract extends Contract> = TContract extends Contract<StorageBase, infer TModels> ? TModels : never;
74
+ type ExactlyOneNamespace<T extends Record<string, unknown>> = keyof T extends infer Only extends keyof T ? [keyof T] extends [Only] ? Only : never : never;
75
+ type NamespaceValueObjectsOf<TNamespace> = TNamespace extends {
76
+ readonly valueObjects?: infer VO;
77
+ } ? VO extends Record<string, ContractValueObject> ? VO : Record<never, never> : Record<never, never>;
78
+ /** Value-object map when the contract declares exactly one domain namespace. */
79
+ 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>;
80
+ //#endregion
81
+ export { ControlPolicy as a, ContractValueObjectDefinitions as i, ContractExecutionSection as n, effectiveControlPolicy as o, ContractModelDefinitions as r, Contract as t };
82
+ //# sourceMappingURL=contract-types-ci3TUzpo.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-types-ci3TUzpo.d.mts","names":[],"sources":["../src/control-policy.ts","../src/contract-types.ts"],"mappings":";;;;;;AASA;;;;AAAyB;AAUzB;KAVY,aAAA;;;;;;;;;iBAUI,sBAAA,CACd,WAAA,EAAa,aAAA,cACb,oBAAA,EAAsB,aAAA,eACrB,aAAA;;;;;AAbsB;AAUzB;;;;;;KCCY,wBAAA;EAAA,SACD,aAAA,EAAe,iBAAA,CAAkB,KAAA;EAAA,SACjC,SAAA;IAAA,SACE,QAAA,EAAU,aAAA,CAAc,wBAAA;EAAA;AAAA;;;ADDrB;;;;ACFhB;;;;;;;;;UAsBiB,QAAA,kBACE,WAAA,GAAc,WAAA,kBACf,MAAA,SAAe,iBAAA,IAAqB,MAAA,SAAe,iBAAA;EAAA,SAE1D,MAAA;EAAA,SACA,YAAA;EAAA,SACA,KAAA,EAAO,MAAA,SAAe,cAAA;EA1BtB;;;;EAAA,SA+BA,MAAA,EAAQ,iBAAA,CAAkB,OAAA;EAAA,SAC1B,OAAA,EAAS,QAAA;EAAA,SACT,YAAA,EAAc,MAAA,SAAe,MAAA;EAAA,SAC7B,cAAA,EAAgB,MAAA;EAAA,SAChB,SAAA,GAAY,wBAAA;EAAA,SACZ,WAAA,EAAa,eAAA;EAAA,SACb,IAAA,EAAM,MAAA;EAAA,SACN,oBAAA,GAAuB,aAAA;AAAA;;KAItB,wBAAA,mBAA2C,QAAA,IACrD,SAAA,SAAkB,QAAA,CAAS,WAAA,mBAA8B,OAAA;AAAA,KAEtD,mBAAA,WAA8B,MAAA,2BAAiC,CAAA,kCAC5D,CAAA,UACG,CAAA,WAAY,IAAA,IACjB,IAAA;AAAA,KAID,uBAAA,eAAsC,UAAA;EAAA,SAChC,YAAA;AAAA,IAEP,EAAA,SAAW,MAAA,SAAe,mBAAA,IACxB,EAAA,GACA,MAAA,iBACF,MAAA;;KAGQ,8BAAA,mBAAiD,QAAA,IAC3D,uBAAA,CACE,SAAA,yBAAkC,mBAAA,CAAoB,SAAA,sDAEpD,SAAA,SAAkB,MAAA,SAAe,mBAAA,IAC/B,SAAA,GACA,MAAA,iBACF,MAAA"}
@@ -0,0 +1,357 @@
1
+ //#region src/namespace-id.d.ts
2
+ type NamespaceId = string & {
3
+ readonly __brand: 'NamespaceId';
4
+ };
5
+ declare function asNamespaceId(value: string): NamespaceId;
6
+ //#endregion
7
+ //#region src/cross-reference.d.ts
8
+ interface CrossReference {
9
+ readonly namespace: NamespaceId;
10
+ readonly model: string;
11
+ /**
12
+ * Contract-space identity for cross-space relations. When present, the
13
+ * referenced model lives in a different contract space. Absent for local
14
+ * (same-space) relations.
15
+ */
16
+ readonly space?: string;
17
+ }
18
+ declare const CrossReferenceSchema: import("arktype/internal/variants/object.ts").ObjectType<CrossReference, {}>;
19
+ declare function crossRef(model: string, namespace?: string, space?: string): CrossReference;
20
+ //#endregion
21
+ //#region src/types.d.ts
22
+ /**
23
+ * Unique symbol used as the key for branding types.
24
+ */
25
+ declare const $: unique symbol;
26
+ /**
27
+ * A helper type to brand a given type with a unique identifier.
28
+ *
29
+ * @template TKey Text used as the brand key.
30
+ * @template TValue Optional value associated with the brand key. Defaults to `true`.
31
+ */
32
+ type Brand<TKey extends string | number | symbol, TValue = true> = {
33
+ [$]: { [K in TKey]: TValue };
34
+ };
35
+ /**
36
+ * Base type for storage contract hashes.
37
+ * Emitted contract.d.ts files use this with the hash value as a type parameter:
38
+ * `type StorageHash = StorageHashBase<'sha256:abc123...'>`
39
+ */
40
+ type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;
41
+ /**
42
+ * Base type for execution contract hashes.
43
+ * Emitted contract.d.ts files use this with the hash value as a type parameter:
44
+ * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`
45
+ */
46
+ type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;
47
+ declare function executionHash<const T extends string>(value: T): ExecutionHashBase<T>;
48
+ declare function coreHash<const T extends string>(value: T): StorageHashBase<T>;
49
+ /**
50
+ * Base type for profile contract hashes.
51
+ * Emitted contract.d.ts files use this with the hash value as a type parameter:
52
+ * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`
53
+ */
54
+ type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;
55
+ declare function profileHash<const T extends string>(value: T): ProfileHashBase<T>;
56
+ /**
57
+ * One entity-kind slot in a namespace — a map of entity name to entry.
58
+ * Values are opaque at the foundation layer; family and target concretions
59
+ * refine them to typed IR classes.
60
+ */
61
+ type StorageEntitySlot = Readonly<Record<string, unknown>>;
62
+ /**
63
+ * Plain-data namespace entry in a storage block. Every hydrated contract
64
+ * carries at least `id` plus entity-kind slot maps under `entries`
65
+ * (`table`, `collection`, …). Foundation declares only this shape — no IR
66
+ * machinery.
67
+ */
68
+ interface StorageNamespace {
69
+ readonly id: string;
70
+ readonly entries: Readonly<Record<string, StorageEntitySlot>>;
71
+ }
72
+ /**
73
+ * Base type for family-specific storage blocks.
74
+ * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the
75
+ * storage hash alongside family-specific data (tables, collections, etc.).
76
+ *
77
+ * The `namespaces` map is carried by every hydrated storage block. Serialized
78
+ * envelope shape is target-owned; this types the in-memory contract after
79
+ * `deserializeContract`.
80
+ */
81
+ interface StorageBase<THash extends string = string> {
82
+ readonly storageHash: StorageHashBase<THash>;
83
+ readonly namespaces: Readonly<Record<string, StorageNamespace>>;
84
+ }
85
+ interface FieldType {
86
+ readonly type: string;
87
+ readonly nullable: boolean;
88
+ readonly items?: FieldType;
89
+ readonly properties?: Record<string, FieldType>;
90
+ }
91
+ type GeneratedValueSpec = {
92
+ readonly id: string;
93
+ readonly params?: Record<string, unknown>;
94
+ };
95
+ type JsonPrimitive = string | number | boolean | null;
96
+ type JsonValue = JsonPrimitive | {
97
+ readonly [key: string]: JsonValue;
98
+ } | readonly JsonValue[];
99
+ type ColumnDefaultLiteralValue = JsonValue;
100
+ type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | Date;
101
+ /**
102
+ * Runtime predicate for `ColumnDefaultLiteralInputValue`. Authoring layers
103
+ * resolve template values from caller-supplied args (typed `unknown` at the
104
+ * boundary) and need to validate before constructing a `ColumnDefault`.
105
+ * Accepts JSON primitives, plain arrays/objects of JSON values, and `Date`
106
+ * instances. Rejects functions, class instances (other than `Date`),
107
+ * `undefined`, `bigint`, `symbol`, and arrays/objects containing those.
108
+ */
109
+ declare function isColumnDefaultLiteralInputValue(value: unknown): value is ColumnDefaultLiteralInputValue;
110
+ type ColumnDefault = {
111
+ readonly kind: 'literal';
112
+ readonly value: ColumnDefaultLiteralInputValue;
113
+ } | {
114
+ readonly kind: 'function';
115
+ readonly expression: string;
116
+ };
117
+ declare function isColumnDefault(value: unknown): value is ColumnDefault;
118
+ type ExecutionMutationDefaultValue = {
119
+ readonly kind: 'generator';
120
+ readonly id: GeneratedValueSpec['id'];
121
+ readonly params?: Record<string, unknown>;
122
+ };
123
+ declare function isExecutionMutationDefaultValue(value: unknown): value is ExecutionMutationDefaultValue;
124
+ type ExecutionMutationDefault = {
125
+ readonly ref: {
126
+ readonly table: string;
127
+ readonly column: string;
128
+ };
129
+ readonly onCreate?: ExecutionMutationDefaultValue;
130
+ readonly onUpdate?: ExecutionMutationDefaultValue;
131
+ };
132
+ /**
133
+ * `ExecutionMutationDefault` minus its `ref` — the per-field phases value
134
+ * authoring layers attach to a column before the column ref is known.
135
+ */
136
+ type ExecutionMutationDefaultPhases = Omit<ExecutionMutationDefault, 'ref'>;
137
+ type ExecutionSection<THash extends string = string> = {
138
+ readonly executionHash: ExecutionHashBase<THash>;
139
+ readonly mutations: {
140
+ readonly defaults: ReadonlyArray<ExecutionMutationDefault>;
141
+ };
142
+ };
143
+ interface Source {
144
+ readonly readOnly: boolean;
145
+ readonly projection: Record<string, FieldType>;
146
+ readonly origin?: Record<string, unknown>;
147
+ readonly capabilities?: Record<string, boolean>;
148
+ }
149
+ interface DocIndex {
150
+ readonly name: string;
151
+ readonly keys: Record<string, 'asc' | 'desc'>;
152
+ readonly unique?: boolean;
153
+ readonly where?: Expr;
154
+ }
155
+ type Expr = {
156
+ readonly kind: 'eq';
157
+ readonly path: ReadonlyArray<string>;
158
+ readonly value: unknown;
159
+ } | {
160
+ readonly kind: 'exists';
161
+ readonly path: ReadonlyArray<string>;
162
+ };
163
+ interface DocCollection {
164
+ readonly name: string;
165
+ readonly id?: {
166
+ readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';
167
+ };
168
+ readonly fields: Record<string, FieldType>;
169
+ readonly indexes?: ReadonlyArray<DocIndex>;
170
+ readonly readOnly?: boolean;
171
+ }
172
+ interface PlanMeta {
173
+ readonly target: string;
174
+ readonly targetFamily?: string;
175
+ readonly storageHash: string;
176
+ readonly profileHash?: string;
177
+ readonly lane: string;
178
+ readonly annotations?: {
179
+ readonly [key: string]: unknown;
180
+ };
181
+ }
182
+ /**
183
+ * Contract marker record stored in the database.
184
+ * Represents the current contract identity for a database.
185
+ */
186
+ interface ContractMarkerRecord {
187
+ readonly storageHash: string;
188
+ readonly profileHash: string;
189
+ readonly contractJson: unknown | null;
190
+ readonly canonicalVersion: number | null;
191
+ readonly updatedAt: Date;
192
+ readonly appTag: string | null;
193
+ readonly meta: Record<string, unknown>;
194
+ readonly invariants: readonly string[];
195
+ }
196
+ /**
197
+ * One applied migration edge from the per-space ledger journal.
198
+ * Returned by `readLedger` in append (apply) order.
199
+ */
200
+ interface LedgerEntryRecord {
201
+ readonly space: string;
202
+ readonly migrationName: string;
203
+ readonly migrationHash: string;
204
+ readonly from: string | null;
205
+ readonly to: string;
206
+ readonly appliedAt: Date;
207
+ readonly operationCount: number;
208
+ }
209
+ //#endregion
210
+ //#region src/value-set-ref.d.ts
211
+ /**
212
+ * Entity coordinate for a domain enum or storage value-set reference.
213
+ *
214
+ * Field-name identity with the framework's `EntityCoordinate` type
215
+ * (packages/1-framework/1-core/framework-components/src/ir/storage.ts).
216
+ * Foundation-contract cannot import framework-components (dependency points
217
+ * the other way), so this is a standalone mirror of that shape plus the
218
+ * cross-space discriminator.
219
+ *
220
+ * One-vocabulary rule (ADR 224): `entityKind` is equal to the entries slot
221
+ * key the referenced entity lives under — `'enum'` for domain's `enum` slot,
222
+ * `'valueSet'` for storage's `entries.valueSet` slot. No consumer-side
223
+ * translation between the kind string and the slot key.
224
+ *
225
+ * Every `valueSet` reference is intra-plane (domain field → domain enum;
226
+ * storage column/check → storage value-set). The directional invariant:
227
+ * domain may reference storage; storage may never reference domain.
228
+ *
229
+ * `namespaceId` admits the `UNBOUND_NAMESPACE_ID` (`__unbound__`) sentinel
230
+ * for single-namespace (unbound) references.
231
+ *
232
+ * `spaceId` is the cross-space discriminator: absent ⇒ local (same
233
+ * contract-space); present ⇒ cross-space. No separate tag field.
234
+ */
235
+ interface ValueSetRef {
236
+ readonly plane: 'domain' | 'storage';
237
+ readonly namespaceId: string;
238
+ readonly entityKind: 'enum' | 'valueSet';
239
+ readonly entityName: string;
240
+ readonly spaceId?: string;
241
+ }
242
+ //#endregion
243
+ //#region src/domain-types.d.ts
244
+ type ScalarFieldType = {
245
+ readonly kind: 'scalar';
246
+ readonly codecId: string;
247
+ readonly typeParams?: Record<string, unknown>;
248
+ };
249
+ type ValueObjectFieldType = {
250
+ readonly kind: 'valueObject';
251
+ readonly name: string;
252
+ };
253
+ type UnionFieldType = {
254
+ readonly kind: 'union';
255
+ readonly members: ReadonlyArray<ScalarFieldType | ValueObjectFieldType>;
256
+ };
257
+ type ContractFieldType = ScalarFieldType | ValueObjectFieldType | UnionFieldType;
258
+ type ContractField = {
259
+ readonly nullable: boolean;
260
+ readonly type: ContractFieldType;
261
+ readonly many?: true;
262
+ readonly dict?: true;
263
+ readonly valueSet?: ValueSetRef;
264
+ };
265
+ /**
266
+ * A domain enum: an ordered set of named members, each with a codec-encoded
267
+ * value. The `codecId` identifies the codec used to encode member values in
268
+ * storage. The `members` array is ordered (declaration order is preserved).
269
+ */
270
+ type ContractEnum = {
271
+ readonly codecId: string;
272
+ readonly members: readonly {
273
+ readonly name: string;
274
+ readonly value: JsonValue;
275
+ }[];
276
+ };
277
+ type ContractRelationOn = {
278
+ readonly localFields: readonly string[];
279
+ readonly targetFields: readonly string[];
280
+ };
281
+ type ContractRelationThrough = {
282
+ readonly table: string;
283
+ readonly namespaceId: string;
284
+ readonly parentColumns: readonly string[];
285
+ readonly childColumns: readonly string[];
286
+ readonly targetColumns: readonly string[];
287
+ };
288
+ type ContractManyToManyRelation = {
289
+ readonly to: CrossReference;
290
+ readonly cardinality: 'N:M';
291
+ readonly on: ContractRelationOn;
292
+ readonly through: ContractRelationThrough;
293
+ };
294
+ type ContractNonJunctionRelation = {
295
+ readonly to: CrossReference;
296
+ readonly cardinality: '1:1' | '1:N' | 'N:1';
297
+ readonly on: ContractRelationOn;
298
+ readonly through?: never;
299
+ };
300
+ type ContractReferenceRelation = ContractManyToManyRelation | ContractNonJunctionRelation;
301
+ type ContractEmbedRelation = {
302
+ readonly to: CrossReference;
303
+ readonly cardinality: '1:1' | '1:N';
304
+ };
305
+ type ContractRelation = ContractReferenceRelation | ContractEmbedRelation;
306
+ type ContractDiscriminator = {
307
+ readonly field: string;
308
+ };
309
+ type ContractVariantEntry = {
310
+ readonly value: string;
311
+ };
312
+ type ContractValueObject = {
313
+ readonly fields: Record<string, ContractField>;
314
+ };
315
+ type ModelStorageBase = Readonly<Record<string, unknown>>;
316
+ interface ContractModelBase<TModelStorage extends ModelStorageBase = ModelStorageBase> {
317
+ readonly fields: Record<string, ContractField>;
318
+ readonly relations: Record<string, ContractRelation>;
319
+ readonly storage: TModelStorage;
320
+ readonly discriminator?: ContractDiscriminator;
321
+ readonly variants?: Record<string, ContractVariantEntry>;
322
+ readonly base?: CrossReference;
323
+ readonly owner?: string;
324
+ }
325
+ interface ContractModel<TModelStorage extends ModelStorageBase = ModelStorageBase> extends ContractModelBase<TModelStorage> {
326
+ readonly fields: Record<string, ContractField>;
327
+ }
328
+ type ReferenceRelationKeys<TModels extends Record<string, {
329
+ readonly relations: Record<string, ContractRelation>;
330
+ }>, ModelName extends string & keyof TModels> = { [K in keyof TModels[ModelName]['relations']]: TModels[ModelName]['relations'][K] extends ContractReferenceRelation ? K : never }[keyof TModels[ModelName]['relations']];
331
+ type EmbedRelationKeys<TModels extends Record<string, {
332
+ readonly relations: Record<string, ContractRelation>;
333
+ }>, ModelName extends string & keyof TModels> = { [K in keyof TModels[ModelName]['relations']]: TModels[ModelName]['relations'][K] extends ContractReferenceRelation ? never : K }[keyof TModels[ModelName]['relations']];
334
+ //#endregion
335
+ //#region src/domain-envelope.d.ts
336
+ /**
337
+ * One namespace's application-domain entities — models and optional value
338
+ * objects keyed by entity name within that namespace coordinate.
339
+ */
340
+ interface ApplicationDomainNamespace<TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>> {
341
+ readonly models: TModels;
342
+ readonly valueObjects?: Record<string, ContractValueObject>;
343
+ readonly enum?: Record<string, ContractEnum>;
344
+ }
345
+ /**
346
+ * Application-domain envelope: entity content keyed by namespace id.
347
+ * Mirrors the storage plane's `namespaces` segment (ADR 221).
348
+ */
349
+ interface ApplicationDomain<TModels extends Record<string, ContractModelBase> = Record<string, ContractModelBase>> {
350
+ readonly namespaces: Readonly<Record<string, ApplicationDomainNamespace<TModels>>>;
351
+ }
352
+ type ContractWithDomain = {
353
+ readonly domain: ApplicationDomain;
354
+ };
355
+ //#endregion
356
+ 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 };
357
+ //# sourceMappingURL=domain-envelope-Czz8UMhU.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-envelope-Czz8UMhU.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,WAAA;EAAA,SAAkC,OAAO;AAAA;AAAA,iBAErC,aAAA,CAAc,KAAA,WAAgB,WAAW;;;UCAxC,cAAA;EAAA,SACN,SAAA,EAAW,WAAW;EAAA,SACtB,KAAA;EDJ0C;AAAA;AAErD;;;EAFqD,SCU1C,KAAA;AAAA;AAAA,cAGE,oBAAA,gDAAoB,UAAA,CAAA,cAAA;AAAA,iBAcjB,QAAA,CACd,KAAA,UACA,SAAA,WACA,KAAA,YACC,cAAc;;;;AD/BjB;;cECa,CAAA;;AFDwC;AAErD;;;;KEOY,KAAA;EAAA,CACT,CAAA,WACO,IAAA,GAAO,MAAA;AAAA;;;;;;KASL,eAAA,yBAAwC,KAAA,GAAQ,KAAK;;;ADVjD;AAGhB;;KCcY,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;ADN5E;;;;;AAAA,KCeY,eAAA,yBAAwC,KAAA,GAAQ,KAAK;AAAA,iBAEjD,WAAA,yBAAoC,KAAA,EAAO,CAAA,GAAI,eAAA,CAAgB,CAAA;;;ADb9D;;;KCsBL,iBAAA,GAAoB,QAAQ,CAAC,MAAA;AApDzC;;;;AAA+D;AAQ/D;AAR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AAA,SACR,YAAA,GAAe,MAAA,SAAe,mBAAA;EAAA,SAC9B,IAAA,GAAO,MAAA,SAAe,YAAA;AAAA;;;;AJTjC;UIgBiB,iBAAA,iBACC,MAAA,SAAe,iBAAA,IAAqB,MAAA,SAAe,iBAAA;EAAA,SAE1D,UAAA,EAAY,QAAA,CAAS,MAAA,SAAe,0BAAA,CAA2B,OAAA;AAAA;AAAA,KAG9D,kBAAA;EAAA,SACD,MAAA,EAAQ,iBAAiB;AAAA"}
@@ -0,0 +1,93 @@
1
+ import { t as Contract } from "./contract-types-ci3TUzpo.mjs";
2
+ import { U as JsonValue, o as ContractEnum } from "./domain-envelope-Czz8UMhU.mjs";
3
+
4
+ //#region src/enum-accessor.d.ts
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
+ 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
+ hasName(name: string): boolean;
21
+ nameOf(v: JsonValue): string | undefined;
22
+ ordinalOf(v: JsonValue): number;
23
+ }
24
+ declare function createEnumAccessor(contractEnum: ContractEnum): EnumAccessor;
25
+ /**
26
+ * Build the enum-accessor map for a single namespace, keyed by enum name.
27
+ * Each namespace facet exposes only its own enums — the IR keys enums under
28
+ * `domain.namespaces[ns].enum`, so the same name in two namespaces resolves
29
+ * independently rather than colliding in one flat map.
30
+ */
31
+ declare function buildEnumsMapForNamespace(domain: {
32
+ readonly namespaces: Readonly<Record<string, {
33
+ readonly enum?: Readonly<Record<string, ContractEnum>>;
34
+ }>>;
35
+ }, namespaceId: string): Record<string, EnumAccessor>;
36
+ /**
37
+ * Build the enum-accessor map for every namespace of a domain, keyed by
38
+ * namespace id then enum name. This is the lane-agnostic enum surface the
39
+ * `db.enums` facade member exposes: enums are contract metadata, the same
40
+ * whether reached through the sql lane or the orm lane, so the facade builds
41
+ * this once and projects it per target.
42
+ */
43
+ declare function buildNamespacedEnums(domain: {
44
+ readonly namespaces: Readonly<Record<string, {
45
+ readonly enum?: Readonly<Record<string, ContractEnum>>;
46
+ }>>;
47
+ }): Record<string, Record<string, EnumAccessor>>;
48
+ type Present<T> = Exclude<T, undefined>;
49
+ type EnumMemberEntry = {
50
+ readonly name: string;
51
+ readonly value: JsonValue;
52
+ };
53
+ type EnumEntry = {
54
+ readonly members: readonly EnumMemberEntry[];
55
+ };
56
+ type EnumEntryValues<Entry extends EnumEntry> = { readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry ? Entry['members'][I]['value'] : never };
57
+ type EnumEntryNames<Entry extends EnumEntry> = { readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry ? Entry['members'][I]['name'] : never };
58
+ type EnumEntryMembers<Entry extends EnumEntry> = { readonly [M in Entry['members'][number] as M['name']]: M['value'] };
59
+ type ContractEnumAccessor<Entry extends EnumEntry> = {
60
+ readonly values: EnumEntryValues<Entry>;
61
+ readonly names: EnumEntryNames<Entry>;
62
+ readonly members: EnumEntryMembers<Entry>; /** Returns true and narrows `v` to the enum's value union when `v` is a declared member value. */
63
+ has(v: JsonValue): v is EnumEntryValues<Entry>[number]; /** Returns true and narrows `name` to the enum's member-name union when `name` is a declared member name. */
64
+ hasName(name: string): name is Extract<EnumEntryNames<Entry>[number], string>;
65
+ nameOf(v: EnumEntryValues<Entry>[number]): string | undefined;
66
+ ordinalOf(v: EnumEntryValues<Entry>[number]): number;
67
+ };
68
+ /**
69
+ * The value union for a `ContractEnumAccessor`.
70
+ * Use in function signatures to accept any declared enum value without re-exporting
71
+ * the member type alias from the accessor's generic entry.
72
+ */
73
+ type EnumValues<A> = A extends {
74
+ readonly values: ReadonlyArray<infer V>;
75
+ } ? V : never;
76
+ /**
77
+ * The member-name union for a `ContractEnumAccessor`.
78
+ */
79
+ type EnumMemberNames<A> = A extends {
80
+ readonly names: ReadonlyArray<infer N>;
81
+ } ? N : never;
82
+ type EnumEntriesToAccessors<Enums> = { readonly [K in keyof Enums]: Enums[K] extends EnumEntry ? ContractEnumAccessor<Enums[K]> : never };
83
+ type BuiltEnumAccessorsOf<TContract> = TContract extends {
84
+ readonly enumAccessors: infer A;
85
+ } ? A : Record<never, never>;
86
+ type NamespaceEnumEntries<TNamespace> = TNamespace extends {
87
+ readonly enum?: infer E;
88
+ } ? unknown extends E ? Record<never, never> : Present<E> : Record<never, never>;
89
+ type NamespaceEnumAccessors<TContract extends Contract, NsId extends keyof TContract['domain']['namespaces']> = EnumEntriesToAccessors<NamespaceEnumEntries<TContract['domain']['namespaces'][NsId]>> & BuiltEnumAccessorsOf<TContract>;
90
+ type NamespacedEnums<TContract extends Contract> = { readonly [Ns in keyof TContract['domain']['namespaces']]: NamespaceEnumAccessors<TContract, Ns> };
91
+ //#endregion
92
+ export { type ContractEnumAccessor, type EnumAccessor, type EnumMemberNames, type EnumValues, type NamespaceEnumAccessors, type NamespacedEnums, buildEnumsMapForNamespace, buildNamespacedEnums, createEnumAccessor };
93
+ //# sourceMappingURL=enum-accessor.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-accessor.d.mts","names":[],"sources":["../src/enum-accessor.ts"],"mappings":";;;;;AAcA;;;;;;;;;UAAiB,YAAA;EAAA,SACN,MAAA,WAAiB,SAAA;EAAA,SACjB,KAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA,SAAe,SAAA;EAC1C,GAAA,CAAI,CAAA,EAAG,SAAA;EACP,OAAA,CAAQ,IAAA;EACR,MAAA,CAAO,CAAA,EAAG,SAAA;EACV,SAAA,CAAU,CAAA,EA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Q,cAAA,CAAe,KAAA;EACtD,MAAA,CAAO,CAAA,EAAG,eAAA,CAAgB,KAAA;EAC1B,SAAA,CAAU,CAAA,EAAG,eAAA,CAAgB,KAAA;AAAA;;;;;;KAQnB,UAAA,MAAgB,CAAA;EAAA,SAAqB,MAAA,EAAQ,aAAa;AAAA,IAAc,CAAA;;;;KAKxE,eAAA,MAAqB,CAAA;EAAA,SAAqB,KAAA,EAAO,aAAa;AAAA,IAAc,CAAA;AAAA,KAEnF,sBAAA,iCACkB,KAAA,GAAQ,KAAA,CAAM,CAAA,UAAW,SAAA,GAAY,oBAAA,CAAqB,KAAA,CAAM,CAAA;AAAA,KAGlF,oBAAA,cAAkC,SAAA;EAAA,SAC5B,aAAA;AAAA,IAEP,CAAA,GACA,MAAM;AAAA,KAEL,oBAAA,eAAmC,UAAA;EAAA,SAC7B,IAAA;AAAA,oBAES,CAAA,GACd,MAAA,iBACA,OAAA,CAAQ,CAAA,IACV,MAAA;AAAA,KAKQ,sBAAA,mBACQ,QAAA,qBACC,SAAA,4BACjB,sBAAA,CAAuB,oBAAA,CAAqB,SAAA,yBAAkC,IAAA,MAChF,oBAAA,CAAqB,SAAA;AAAA,KAIX,eAAA,mBAAkC,QAAA,4BACtB,SAAA,2BAAoC,sBAAA,CAAuB,SAAA,EAAW,EAAA"}
@@ -0,0 +1,47 @@
1
+ //#region src/enum-accessor.ts
2
+ function createEnumAccessor(contractEnum) {
3
+ const values = Object.freeze(contractEnum.members.map((m) => m.value));
4
+ const names = Object.freeze(contractEnum.members.map((m) => m.name));
5
+ const members = Object.freeze(Object.fromEntries(contractEnum.members.map((m) => [m.name, m.value])));
6
+ const valueSet = new Set(values);
7
+ const nameSet = Object.freeze(new Set(names));
8
+ const valueToName = new Map(contractEnum.members.map((m) => [m.value, m.name]));
9
+ const valueToOrdinal = new Map(values.map((v, i) => [v, i]));
10
+ return {
11
+ values,
12
+ names,
13
+ members,
14
+ has: (v) => valueSet.has(v),
15
+ hasName: (name) => nameSet.has(name),
16
+ nameOf: (v) => valueToName.get(v),
17
+ ordinalOf: (v) => valueToOrdinal.get(v) ?? -1
18
+ };
19
+ }
20
+ /**
21
+ * Build the enum-accessor map for a single namespace, keyed by enum name.
22
+ * Each namespace facet exposes only its own enums — the IR keys enums under
23
+ * `domain.namespaces[ns].enum`, so the same name in two namespaces resolves
24
+ * independently rather than colliding in one flat map.
25
+ */
26
+ function buildEnumsMapForNamespace(domain, namespaceId) {
27
+ const result = {};
28
+ const namespace = domain.namespaces[namespaceId];
29
+ if (namespace?.enum) for (const [name, contractEnum] of Object.entries(namespace.enum)) result[name] = createEnumAccessor(contractEnum);
30
+ return result;
31
+ }
32
+ /**
33
+ * Build the enum-accessor map for every namespace of a domain, keyed by
34
+ * namespace id then enum name. This is the lane-agnostic enum surface the
35
+ * `db.enums` facade member exposes: enums are contract metadata, the same
36
+ * whether reached through the sql lane or the orm lane, so the facade builds
37
+ * this once and projects it per target.
38
+ */
39
+ function buildNamespacedEnums(domain) {
40
+ const result = {};
41
+ for (const namespaceId of Object.keys(domain.namespaces)) result[namespaceId] = buildEnumsMapForNamespace(domain, namespaceId);
42
+ return result;
43
+ }
44
+ //#endregion
45
+ export { buildEnumsMapForNamespace, buildNamespacedEnums, createEnumAccessor };
46
+
47
+ //# sourceMappingURL=enum-accessor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum-accessor.mjs","names":[],"sources":["../src/enum-accessor.ts"],"sourcesContent":["import type { Contract } from './contract-types';\nimport type { ContractEnum } from './domain-types';\nimport type { JsonValue } from './types';\n\n/**\n * Runtime view of a domain enum, built at the client from the emitted\n * `ContractEnum` JSON (codec-encoded `JsonValue` members, literal types erased).\n *\n * This deliberately mirrors the accessor shape of the authoring-time\n * `EnumTypeHandle` (in `contract-ts`) rather than reusing it: that handle carries\n * the literal value generics and lives in the authoring layer, which the\n * foundation layer cannot depend on. The two are the same surface seen from the\n * two planes — authoring (typed) and runtime (validated JSON).\n */\nexport interface EnumAccessor {\n readonly values: readonly JsonValue[];\n readonly names: readonly string[];\n readonly members: Readonly<Record<string, JsonValue>>;\n has(v: JsonValue): boolean;\n hasName(name: string): boolean;\n nameOf(v: JsonValue): string | undefined;\n ordinalOf(v: JsonValue): number;\n}\n\nexport function createEnumAccessor(contractEnum: ContractEnum): EnumAccessor {\n const values = Object.freeze(contractEnum.members.map((m) => m.value));\n const names = Object.freeze(contractEnum.members.map((m) => m.name));\n const members: Readonly<Record<string, JsonValue>> = Object.freeze(\n Object.fromEntries(contractEnum.members.map((m) => [m.name, m.value])),\n );\n\n const valueSet = new Set(values);\n const nameSet = Object.freeze(new Set(names));\n const valueToName = new Map(contractEnum.members.map((m) => [m.value, m.name]));\n const valueToOrdinal = new Map(values.map((v, i) => [v, i]));\n\n return {\n values,\n names,\n members,\n has: (v: JsonValue) => valueSet.has(v),\n hasName: (name: string) => nameSet.has(name),\n nameOf: (v: JsonValue) => valueToName.get(v),\n ordinalOf: (v: JsonValue) => valueToOrdinal.get(v) ?? -1,\n };\n}\n\n/**\n * Build the enum-accessor map for a single namespace, keyed by enum name.\n * Each namespace facet exposes only its own enums — the IR keys enums under\n * `domain.namespaces[ns].enum`, so the same name in two namespaces resolves\n * independently rather than colliding in one flat map.\n */\nexport function buildEnumsMapForNamespace(\n domain: {\n readonly namespaces: Readonly<\n Record<string, { readonly enum?: Readonly<Record<string, ContractEnum>> }>\n >;\n },\n namespaceId: string,\n): Record<string, EnumAccessor> {\n const result: Record<string, EnumAccessor> = {};\n const namespace = domain.namespaces[namespaceId];\n if (namespace?.enum) {\n for (const [name, contractEnum] of Object.entries(namespace.enum)) {\n result[name] = createEnumAccessor(contractEnum);\n }\n }\n return result;\n}\n\n/**\n * Build the enum-accessor map for every namespace of a domain, keyed by\n * namespace id then enum name. This is the lane-agnostic enum surface the\n * `db.enums` facade member exposes: enums are contract metadata, the same\n * whether reached through the sql lane or the orm lane, so the facade builds\n * this once and projects it per target.\n */\nexport function buildNamespacedEnums(domain: {\n readonly namespaces: Readonly<\n Record<string, { readonly enum?: Readonly<Record<string, ContractEnum>> }>\n >;\n}): Record<string, Record<string, EnumAccessor>> {\n const result: Record<string, Record<string, EnumAccessor>> = {};\n for (const namespaceId of Object.keys(domain.namespaces)) {\n result[namespaceId] = buildEnumsMapForNamespace(domain, namespaceId);\n }\n return result;\n}\n\n// ---------------------------------------------------------------------------\n// Type-level projection of the namespaced enum surface.\n//\n// These types derive the literal-preserving accessor shape from the contract,\n// hung off the `db.enums` facade map (`db.enums.<ns>.<Name>`). They are the\n// same accessors the runtime builds above, but typed from the two emission\n// paths:\n// - Emitted contracts carry the literal enum entries under\n// `domain.namespaces[ns].enum`; each maps to a `ContractEnumAccessor`.\n// - The no-emit (built) contract carries them flat on `enumAccessors`\n// (already accessor-shaped, literal-preserving), since its built domain\n// type does not narrow `namespaces[ns].enum`. All authored enums land in\n// the single built namespace, so exposing the flat map per namespace is\n// correct there.\n// Only `SqlContractResult` carries `enumAccessors`; emitted contracts never\n// do, so the two carriers never overlap.\n// ---------------------------------------------------------------------------\n\ntype Present<T> = Exclude<T, undefined>;\n\n// A domain enum entry as carried in `domain.namespaces[ns].enum[name]`: an\n// ordered member tuple. The no-emit (built) path preserves the literal member\n// values so the derived accessor keeps its literal `values`/`names`/`members`.\ntype EnumMemberEntry = { readonly name: string; readonly value: JsonValue };\ntype EnumEntry = { readonly members: readonly EnumMemberEntry[] };\n\ntype EnumEntryValues<Entry extends EnumEntry> = {\n readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry\n ? Entry['members'][I]['value']\n : never;\n};\n\ntype EnumEntryNames<Entry extends EnumEntry> = {\n readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry\n ? Entry['members'][I]['name']\n : never;\n};\n\ntype EnumEntryMembers<Entry extends EnumEntry> = {\n readonly [M in Entry['members'][number] as M['name']]: M['value'];\n};\n\n// The runtime accessor shape for one enum, with literal `values`/`names`/\n// `members` derived from the entry's member tuple. Mirrors `EnumAccessor`'s\n// runtime surface and the authoring `EnumTypeHandle` accessor.\nexport type ContractEnumAccessor<Entry extends EnumEntry> = {\n readonly values: EnumEntryValues<Entry>;\n readonly names: EnumEntryNames<Entry>;\n readonly members: EnumEntryMembers<Entry>;\n /** Returns true and narrows `v` to the enum's value union when `v` is a declared member value. */\n has(v: JsonValue): v is EnumEntryValues<Entry>[number];\n /** Returns true and narrows `name` to the enum's member-name union when `name` is a declared member name. */\n hasName(name: string): name is Extract<EnumEntryNames<Entry>[number], string>;\n nameOf(v: EnumEntryValues<Entry>[number]): string | undefined;\n ordinalOf(v: EnumEntryValues<Entry>[number]): number;\n};\n\n/**\n * The value union for a `ContractEnumAccessor`.\n * Use in function signatures to accept any declared enum value without re-exporting\n * the member type alias from the accessor's generic entry.\n */\nexport type EnumValues<A> = A extends { readonly values: ReadonlyArray<infer V> } ? V : never;\n\n/**\n * The member-name union for a `ContractEnumAccessor`.\n */\nexport type EnumMemberNames<A> = A extends { readonly names: ReadonlyArray<infer N> } ? N : never;\n\ntype EnumEntriesToAccessors<Enums> = {\n readonly [K in keyof Enums]: Enums[K] extends EnumEntry ? ContractEnumAccessor<Enums[K]> : never;\n};\n\ntype BuiltEnumAccessorsOf<TContract> = TContract extends {\n readonly enumAccessors: infer A;\n}\n ? A\n : Record<never, never>;\n\ntype NamespaceEnumEntries<TNamespace> = TNamespace extends {\n readonly enum?: infer E;\n}\n ? unknown extends E\n ? Record<never, never>\n : Present<E>\n : Record<never, never>;\n\n// The per-namespace enum accessors. Each namespace exposes only its own enums\n// (the IR's `domain.namespaces[ns].enum`), so the same enum name in two\n// namespaces resolves to each namespace's own accessor.\nexport type NamespaceEnumAccessors<\n TContract extends Contract,\n NsId extends keyof TContract['domain']['namespaces'],\n> = EnumEntriesToAccessors<NamespaceEnumEntries<TContract['domain']['namespaces'][NsId]>> &\n BuiltEnumAccessorsOf<TContract>;\n\n// The lane-agnostic enum surface exposed on the `db.enums` facade member: a\n// namespace-keyed map projected per target exactly like `db.sql` / `db.orm`.\nexport type NamespacedEnums<TContract extends Contract> = {\n readonly [Ns in keyof TContract['domain']['namespaces']]: NamespaceEnumAccessors<TContract, Ns>;\n};\n"],"mappings":";AAwBA,SAAgB,mBAAmB,cAA0C;CAC3E,MAAM,SAAS,OAAO,OAAO,aAAa,QAAQ,KAAK,MAAM,EAAE,KAAK,CAAC;CACrE,MAAM,QAAQ,OAAO,OAAO,aAAa,QAAQ,KAAK,MAAM,EAAE,IAAI,CAAC;CACnE,MAAM,UAA+C,OAAO,OAC1D,OAAO,YAAY,aAAa,QAAQ,KAAK,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CACvE;CAEA,MAAM,WAAW,IAAI,IAAI,MAAM;CAC/B,MAAM,UAAU,OAAO,OAAO,IAAI,IAAI,KAAK,CAAC;CAC5C,MAAM,cAAc,IAAI,IAAI,aAAa,QAAQ,KAAK,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;CAC9E,MAAM,iBAAiB,IAAI,IAAI,OAAO,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;CAE3D,OAAO;EACL;EACA;EACA;EACA,MAAM,MAAiB,SAAS,IAAI,CAAC;EACrC,UAAU,SAAiB,QAAQ,IAAI,IAAI;EAC3C,SAAS,MAAiB,YAAY,IAAI,CAAC;EAC3C,YAAY,MAAiB,eAAe,IAAI,CAAC,KAAK;CACxD;AACF;;;;;;;AAQA,SAAgB,0BACd,QAKA,aAC8B;CAC9B,MAAM,SAAuC,CAAC;CAC9C,MAAM,YAAY,OAAO,WAAW;CACpC,IAAI,WAAW,MACb,KAAK,MAAM,CAAC,MAAM,iBAAiB,OAAO,QAAQ,UAAU,IAAI,GAC9D,OAAO,QAAQ,mBAAmB,YAAY;CAGlD,OAAO;AACT;;;;;;;;AASA,SAAgB,qBAAqB,QAIY;CAC/C,MAAM,SAAuD,CAAC;CAC9D,KAAK,MAAM,eAAe,OAAO,KAAK,OAAO,UAAU,GACrD,OA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