@prisma-next/contract 0.13.0-dev.9 → 0.14.0-dev.1

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/dist/apply-specifier-default-control-policy.d.mts +1 -1
  2. package/dist/{canonicalization-ChdV0ueh.d.mts → canonicalization-05YMFrf7.d.mts} +2 -2
  3. package/dist/{canonicalization-ChdV0ueh.d.mts.map → canonicalization-05YMFrf7.d.mts.map} +1 -1
  4. package/dist/contract-types-DrjCtVOs.d.mts +77 -0
  5. package/dist/contract-types-DrjCtVOs.d.mts.map +1 -0
  6. package/dist/domain-envelope-Bj-zQbVU.d.mts +358 -0
  7. package/dist/domain-envelope-Bj-zQbVU.d.mts.map +1 -0
  8. package/dist/enum-accessor.d.mts +93 -0
  9. package/dist/enum-accessor.d.mts.map +1 -0
  10. package/dist/enum-accessor.mjs +47 -0
  11. package/dist/enum-accessor.mjs.map +1 -0
  12. package/dist/hashing-utils.d.mts +1 -1
  13. package/dist/hashing-utils.d.mts.map +1 -1
  14. package/dist/hashing-utils.mjs +1 -3
  15. package/dist/hashing-utils.mjs.map +1 -1
  16. package/dist/hashing.d.mts +2 -2
  17. package/dist/hashing.d.mts.map +1 -1
  18. package/dist/hashing.mjs +1 -3
  19. package/dist/hashing.mjs.map +1 -1
  20. package/dist/is-plain-record-CUofyVQ7.mjs +16 -0
  21. package/dist/is-plain-record-CUofyVQ7.mjs.map +1 -0
  22. package/dist/is-plain-record.d.mts +11 -0
  23. package/dist/is-plain-record.d.mts.map +1 -0
  24. package/dist/is-plain-record.mjs +2 -0
  25. package/dist/{resolve-domain-model-BhAr8VRJ.d.mts → resolve-domain-model-5aHgzqTD.d.mts} +2 -2
  26. package/dist/{resolve-domain-model-BhAr8VRJ.d.mts.map → resolve-domain-model-5aHgzqTD.d.mts.map} +1 -1
  27. package/dist/resolve-domain-model.d.mts +1 -1
  28. package/dist/types.d.mts +6 -6
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs.map +1 -1
  31. package/dist/validate-domain.d.mts +1 -1
  32. package/package.json +6 -4
  33. package/src/canonicalization-storage-sort.ts +1 -4
  34. package/src/contract-types.ts +3 -13
  35. package/src/domain-envelope.ts +4 -8
  36. package/src/domain-namespace-access.ts +6 -6
  37. package/src/domain-types.ts +2 -1
  38. package/src/enum-accessor.ts +191 -0
  39. package/src/exports/enum-accessor.ts +13 -0
  40. package/src/exports/is-plain-record.ts +1 -0
  41. package/src/exports/types.ts +0 -1
  42. package/src/hashing.ts +1 -4
  43. package/src/is-plain-record.ts +11 -0
  44. package/src/types.ts +1 -1
  45. package/src/value-set-ref.ts +20 -15
  46. package/dist/contract-types-CBbD-VV1.d.mts +0 -271
  47. package/dist/contract-types-CBbD-VV1.d.mts.map +0 -1
  48. package/dist/domain-envelope-OkWsysCY.d.mts +0 -163
  49. package/dist/domain-envelope-OkWsysCY.d.mts.map +0 -1
@@ -0,0 +1,191 @@
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
+ hasName(name: string): boolean;
21
+ nameOf(v: JsonValue): string | undefined;
22
+ ordinalOf(v: JsonValue): number;
23
+ }
24
+
25
+ export function createEnumAccessor(contractEnum: ContractEnum): EnumAccessor {
26
+ const values = Object.freeze(contractEnum.members.map((m) => m.value));
27
+ const names = Object.freeze(contractEnum.members.map((m) => m.name));
28
+ const members: Readonly<Record<string, JsonValue>> = Object.freeze(
29
+ Object.fromEntries(contractEnum.members.map((m) => [m.name, m.value])),
30
+ );
31
+
32
+ const valueSet = new Set(values);
33
+ const nameSet = Object.freeze(new Set(names));
34
+ const valueToName = new Map(contractEnum.members.map((m) => [m.value, m.name]));
35
+ const valueToOrdinal = new Map(values.map((v, i) => [v, i]));
36
+
37
+ return {
38
+ values,
39
+ names,
40
+ members,
41
+ has: (v: JsonValue) => valueSet.has(v),
42
+ hasName: (name: string) => nameSet.has(name),
43
+ nameOf: (v: JsonValue) => valueToName.get(v),
44
+ ordinalOf: (v: JsonValue) => valueToOrdinal.get(v) ?? -1,
45
+ };
46
+ }
47
+
48
+ /**
49
+ * Build the enum-accessor map for a single namespace, keyed by enum name.
50
+ * Each namespace facet exposes only its own enums — the IR keys enums under
51
+ * `domain.namespaces[ns].enum`, so the same name in two namespaces resolves
52
+ * independently rather than colliding in one flat map.
53
+ */
54
+ export function buildEnumsMapForNamespace(
55
+ domain: {
56
+ readonly namespaces: Readonly<
57
+ Record<string, { readonly enum?: Readonly<Record<string, ContractEnum>> }>
58
+ >;
59
+ },
60
+ namespaceId: string,
61
+ ): Record<string, EnumAccessor> {
62
+ const result: Record<string, EnumAccessor> = {};
63
+ const namespace = domain.namespaces[namespaceId];
64
+ if (namespace?.enum) {
65
+ for (const [name, contractEnum] of Object.entries(namespace.enum)) {
66
+ result[name] = createEnumAccessor(contractEnum);
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+
72
+ /**
73
+ * Build the enum-accessor map for every namespace of a domain, keyed by
74
+ * namespace id then enum name. This is the lane-agnostic enum surface the
75
+ * `db.enums` facade member exposes: enums are contract metadata, the same
76
+ * whether reached through the sql lane or the orm lane, so the facade builds
77
+ * this once and projects it per target.
78
+ */
79
+ export function buildNamespacedEnums(domain: {
80
+ readonly namespaces: Readonly<
81
+ Record<string, { readonly enum?: Readonly<Record<string, ContractEnum>> }>
82
+ >;
83
+ }): Record<string, Record<string, EnumAccessor>> {
84
+ const result: Record<string, Record<string, EnumAccessor>> = {};
85
+ for (const namespaceId of Object.keys(domain.namespaces)) {
86
+ result[namespaceId] = buildEnumsMapForNamespace(domain, namespaceId);
87
+ }
88
+ return result;
89
+ }
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Type-level projection of the namespaced enum surface.
93
+ //
94
+ // These types derive the literal-preserving accessor shape from the contract,
95
+ // hung off the `db.enums` facade map (`db.enums.<ns>.<Name>`). They are the
96
+ // same accessors the runtime builds above, but typed from the two emission
97
+ // paths:
98
+ // - Emitted contracts carry the literal enum entries under
99
+ // `domain.namespaces[ns].enum`; each maps to a `ContractEnumAccessor`.
100
+ // - The no-emit (built) contract carries them flat on `enumAccessors`
101
+ // (already accessor-shaped, literal-preserving), since its built domain
102
+ // type does not narrow `namespaces[ns].enum`. All authored enums land in
103
+ // the single built namespace, so exposing the flat map per namespace is
104
+ // correct there.
105
+ // Only `SqlContractResult` carries `enumAccessors`; emitted contracts never
106
+ // do, so the two carriers never overlap.
107
+ // ---------------------------------------------------------------------------
108
+
109
+ type Present<T> = Exclude<T, undefined>;
110
+
111
+ // A domain enum entry as carried in `domain.namespaces[ns].enum[name]`: an
112
+ // ordered member tuple. The no-emit (built) path preserves the literal member
113
+ // values so the derived accessor keeps its literal `values`/`names`/`members`.
114
+ type EnumMemberEntry = { readonly name: string; readonly value: JsonValue };
115
+ type EnumEntry = { readonly members: readonly EnumMemberEntry[] };
116
+
117
+ type EnumEntryValues<Entry extends EnumEntry> = {
118
+ readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry
119
+ ? Entry['members'][I]['value']
120
+ : never;
121
+ };
122
+
123
+ type EnumEntryNames<Entry extends EnumEntry> = {
124
+ readonly [I in keyof Entry['members']]: Entry['members'][I] extends EnumMemberEntry
125
+ ? Entry['members'][I]['name']
126
+ : never;
127
+ };
128
+
129
+ type EnumEntryMembers<Entry extends EnumEntry> = {
130
+ readonly [M in Entry['members'][number] as M['name']]: M['value'];
131
+ };
132
+
133
+ // The runtime accessor shape for one enum, with literal `values`/`names`/
134
+ // `members` derived from the entry's member tuple. Mirrors `EnumAccessor`'s
135
+ // runtime surface and the authoring `EnumTypeHandle` accessor.
136
+ export type ContractEnumAccessor<Entry extends EnumEntry> = {
137
+ readonly values: EnumEntryValues<Entry>;
138
+ readonly names: EnumEntryNames<Entry>;
139
+ readonly members: EnumEntryMembers<Entry>;
140
+ /** Returns true and narrows `v` to the enum's value union when `v` is a declared member value. */
141
+ has(v: JsonValue): v is EnumEntryValues<Entry>[number];
142
+ /** Returns true and narrows `name` to the enum's member-name union when `name` is a declared member name. */
143
+ hasName(name: string): name is Extract<EnumEntryNames<Entry>[number], string>;
144
+ nameOf(v: EnumEntryValues<Entry>[number]): string | undefined;
145
+ ordinalOf(v: EnumEntryValues<Entry>[number]): number;
146
+ };
147
+
148
+ /**
149
+ * The value union for a `ContractEnumAccessor`.
150
+ * Use in function signatures to accept any declared enum value without re-exporting
151
+ * the member type alias from the accessor's generic entry.
152
+ */
153
+ export type EnumValues<A> = A extends { readonly values: ReadonlyArray<infer V> } ? V : never;
154
+
155
+ /**
156
+ * The member-name union for a `ContractEnumAccessor`.
157
+ */
158
+ export type EnumMemberNames<A> = A extends { readonly names: ReadonlyArray<infer N> } ? N : never;
159
+
160
+ type EnumEntriesToAccessors<Enums> = {
161
+ readonly [K in keyof Enums]: Enums[K] extends EnumEntry ? ContractEnumAccessor<Enums[K]> : never;
162
+ };
163
+
164
+ type BuiltEnumAccessorsOf<TContract> = TContract extends {
165
+ readonly enumAccessors: infer A;
166
+ }
167
+ ? A
168
+ : Record<never, never>;
169
+
170
+ type NamespaceEnumEntries<TNamespace> = TNamespace extends {
171
+ readonly enum?: infer E;
172
+ }
173
+ ? unknown extends E
174
+ ? Record<never, never>
175
+ : Present<E>
176
+ : Record<never, never>;
177
+
178
+ // The per-namespace enum accessors. Each namespace exposes only its own enums
179
+ // (the IR's `domain.namespaces[ns].enum`), so the same enum name in two
180
+ // namespaces resolves to each namespace's own accessor.
181
+ export type NamespaceEnumAccessors<
182
+ TContract extends Contract,
183
+ NsId extends keyof TContract['domain']['namespaces'],
184
+ > = EnumEntriesToAccessors<NamespaceEnumEntries<TContract['domain']['namespaces'][NsId]>> &
185
+ BuiltEnumAccessorsOf<TContract>;
186
+
187
+ // The lane-agnostic enum surface exposed on the `db.enums` facade member: a
188
+ // namespace-keyed map projected per target exactly like `db.sql` / `db.orm`.
189
+ export type NamespacedEnums<TContract extends Contract> = {
190
+ readonly [Ns in keyof TContract['domain']['namespaces']]: NamespaceEnumAccessors<TContract, Ns>;
191
+ };
@@ -0,0 +1,13 @@
1
+ export type {
2
+ ContractEnumAccessor,
3
+ EnumAccessor,
4
+ EnumMemberNames,
5
+ EnumValues,
6
+ NamespacedEnums,
7
+ NamespaceEnumAccessors,
8
+ } from '../enum-accessor';
9
+ export {
10
+ buildEnumsMapForNamespace,
11
+ buildNamespacedEnums,
12
+ createEnumAccessor,
13
+ } from '../enum-accessor';
@@ -0,0 +1 @@
1
+ export { isPlainRecord } from '../is-plain-record';
@@ -1,7 +1,6 @@
1
1
  export type {
2
2
  Contract,
3
3
  ContractExecutionSection,
4
- ContractModelDefinitions,
5
4
  ContractValueObjectDefinitions,
6
5
  } from '../contract-types';
7
6
  export { DomainNamespaceResolutionError } from '../contract-validation-error';
package/src/hashing.ts CHANGED
@@ -8,14 +8,11 @@ import {
8
8
  type StorageSort,
9
9
  } from './canonicalization';
10
10
  import type { Contract } from './contract-types';
11
+ import { isPlainRecord } from './is-plain-record';
11
12
  import type { ExecutionHashBase, ProfileHashBase, StorageHashBase } from './types';
12
13
 
13
14
  const SCHEMA_VERSION = '1';
14
15
 
15
- function isPlainRecord(value: unknown): value is Record<string, unknown> {
16
- return value !== null && typeof value === 'object' && !Array.isArray(value);
17
- }
18
-
19
16
  // Storage hashes fingerprint table/column layout, not which target pack emitted a
20
17
  // namespace. Persisted contract.json carries namespace `kind` discriminators;
21
18
  // authoring-time hashes never included them (IR `kind` is non-enumerable).
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Strict plain-object guard: accepts only objects with `Object.prototype`
3
+ * or `null` as their prototype. Rejects arrays, class instances, and other
4
+ * non-plain objects. Used to distinguish raw-data records from IR class
5
+ * instances in validation and hydration paths.
6
+ */
7
+ export function isPlainRecord(value: unknown): value is Readonly<Record<string, unknown>> {
8
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;
9
+ const proto: unknown = Object.getPrototypeOf(value);
10
+ return proto === Object.prototype || proto === null;
11
+ }
package/src/types.ts CHANGED
@@ -173,7 +173,7 @@ export function isExecutionMutationDefaultValue(
173
173
  }
174
174
 
175
175
  export type ExecutionMutationDefault = {
176
- readonly ref: { readonly table: string; readonly column: string };
176
+ readonly ref: { readonly namespace: string; readonly table: string; readonly column: string };
177
177
  readonly onCreate?: ExecutionMutationDefaultValue;
178
178
  readonly onUpdate?: ExecutionMutationDefaultValue;
179
179
  };
@@ -1,26 +1,31 @@
1
1
  /**
2
- * Space-aware reference coordinate for a domain enum or storage value-set.
2
+ * Entity coordinate for a domain enum or storage value-set reference.
3
3
  *
4
- * `plane` names the contract plane the referenced entity lives in:
5
- * - `'domain'` — the entity lives in the domain plane's `enum` slot.
6
- * - `'storage'` the entity lives in the storage plane's `valueSet` slot.
4
+ * Field-name identity with the framework's `EntityCoordinate` type
5
+ * (packages/1-framework/1-core/framework-components/src/ir/storage.ts).
6
+ * Foundation-contract cannot import framework-components (dependency points
7
+ * the other way), so this is a standalone mirror of that shape plus the
8
+ * cross-space discriminator.
7
9
  *
8
- * `entityKind` names the source entity-kind:
9
- * - `'enum'` — the referenced entity is a domain enum.
10
- * - `'value-set'` the referenced entity is a storage value-set.
10
+ * One-vocabulary rule (ADR 224): `entityKind` is equal to the entries slot
11
+ * key the referenced entity lives under — `'enum'` for domain's `enum` slot,
12
+ * `'valueSet'` for storage's `entries.valueSet` slot. No consumer-side
13
+ * translation between the kind string and the slot key.
11
14
  *
12
- * `namespaceId` admits the `UNBOUND_NAMESPACE_ID` (`__unbound__`) sentinel for
13
- * single-namespace (unbound) references.
15
+ * Every `valueSet` reference is intra-plane (domain field → domain enum;
16
+ * storage column/check → storage value-set). The directional invariant:
17
+ * domain may reference storage; storage may never reference domain.
14
18
  *
15
- * Cross-space discrimination is presence-based: when `spaceId` is absent the
16
- * reference is local (same contract-space); when `spaceId` is present the
17
- * reference is cross-space. This mirrors the `ForeignKeyReference` carrier
18
- * convention no separate tag field so local refs are JSON-minimal.
19
+ * `namespaceId` admits the `UNBOUND_NAMESPACE_ID` (`__unbound__`) sentinel
20
+ * for single-namespace (unbound) references.
21
+ *
22
+ * `spaceId` is the cross-space discriminator: absent local (same
23
+ * contract-space); present ⇒ cross-space. No separate tag field.
19
24
  */
20
25
  export interface ValueSetRef {
21
26
  readonly plane: 'domain' | 'storage';
22
27
  readonly namespaceId: string;
23
- readonly entityKind: 'enum' | 'value-set';
24
- readonly name: string;
28
+ readonly entityKind: 'enum' | 'valueSet';
29
+ readonly entityName: string;
25
30
  readonly spaceId?: string;
26
31
  }
@@ -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,SAAA;EAAA,SACN,IAAA;EAAA,SACA,QAAA;EAAA,SACA,KAAA,GAAQ,SAA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