@prisma-next/sql-contract 0.14.0-dev.4 → 0.14.0-dev.40
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.
- package/dist/contract-view.d.mts +61 -0
- package/dist/contract-view.d.mts.map +1 -0
- package/dist/contract-view.mjs +39 -0
- package/dist/contract-view.mjs.map +1 -0
- package/dist/entity-kinds-CHiydmat.mjs +131 -0
- package/dist/entity-kinds-CHiydmat.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +1 -1
- package/dist/entity-kinds.mjs +1 -1
- package/dist/factories.d.mts +5 -3
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +5 -4
- package/dist/factories.mjs.map +1 -1
- package/dist/index-type-validation.d.mts +1 -1
- package/dist/resolve-storage-table.d.mts +2 -2
- package/dist/{sql-storage-Dga0jwP2.d.mts → sql-storage-Dc1Dy3Vb.d.mts} +60 -19
- package/dist/sql-storage-Dc1Dy3Vb.d.mts.map +1 -0
- package/dist/{entity-kinds-Cl36zL5j.mjs → storage-value-set-C4XInPlX.mjs} +21 -128
- package/dist/storage-value-set-C4XInPlX.mjs.map +1 -0
- package/dist/{storage-value-set-WnYsIFM8.d.mts → storage-value-set-DXL-7PYo.d.mts} +14 -2
- package/dist/storage-value-set-DXL-7PYo.d.mts.map +1 -0
- package/dist/{types-B1N8w0I2.d.mts → types-ChH7hULD.d.mts} +24 -54
- package/dist/types-ChH7hULD.d.mts.map +1 -0
- package/dist/types-KiOT4SAV.mjs +114 -0
- package/dist/types-KiOT4SAV.mjs.map +1 -0
- package/dist/types.d.mts +10 -4
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +3 -3
- package/dist/validators.d.mts +9 -6
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +109 -17
- package/dist/validators.mjs.map +1 -1
- package/package.json +8 -7
- package/src/column-type-resolution.ts +26 -0
- package/src/contract-view.ts +98 -0
- package/src/exports/contract-view.ts +11 -0
- package/src/exports/types.ts +17 -4
- package/src/factories.ts +12 -2
- package/src/ir/sql-storage.ts +80 -17
- package/src/ir/storage-column.ts +3 -0
- package/src/ir/storage-entry-schemas.ts +1 -0
- package/src/ir/storage-table.ts +21 -0
- package/src/ir/storage-value-set.ts +5 -0
- package/src/types.ts +51 -8
- package/src/validators.ts +215 -40
- package/dist/entity-kinds-Cl36zL5j.mjs.map +0 -1
- package/dist/sql-storage-Dga0jwP2.d.mts.map +0 -1
- package/dist/storage-value-set-WnYsIFM8.d.mts.map +0 -1
- package/dist/types-B-eiQXff.mjs +0 -191
- package/dist/types-B-eiQXff.mjs.map +0 -1
- package/dist/types-B1N8w0I2.d.mts.map +0 -1
- package/src/ir/build-sql-namespace.ts +0 -110
- package/src/ir/sql-unbound-namespace.ts +0 -74
package/src/validators.ts
CHANGED
|
@@ -10,13 +10,11 @@ import {
|
|
|
10
10
|
type AnyEntityKindDescriptor,
|
|
11
11
|
isPlainRecord,
|
|
12
12
|
type Namespace,
|
|
13
|
-
UNBOUND_NAMESPACE_ID,
|
|
14
13
|
} from '@prisma-next/framework-components/ir';
|
|
15
14
|
import { blindCast } from '@prisma-next/utils/casts';
|
|
16
15
|
import { ifDefined } from '@prisma-next/utils/defined';
|
|
17
16
|
import { type Type, type } from 'arktype';
|
|
18
17
|
import { composeSqlEntityKinds } from './entity-kinds';
|
|
19
|
-
import { buildSqlNamespaceMap } from './ir/build-sql-namespace';
|
|
20
18
|
|
|
21
19
|
export {
|
|
22
20
|
CheckConstraintSchema,
|
|
@@ -32,13 +30,12 @@ export {
|
|
|
32
30
|
StorageValueSetSchema,
|
|
33
31
|
} from './ir/storage-entry-schemas';
|
|
34
32
|
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
type SqlModelStorage,
|
|
33
|
+
import type {
|
|
34
|
+
SqlModelStorage,
|
|
38
35
|
SqlStorage,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
StorageColumn,
|
|
37
|
+
StorageTable,
|
|
38
|
+
StorageTypeInstanceInput,
|
|
42
39
|
} from './types';
|
|
43
40
|
|
|
44
41
|
const generatorKindSchema = type("'generator'");
|
|
@@ -192,9 +189,8 @@ export function createSqlStorageSchema(
|
|
|
192
189
|
'types?': type({ '[string]': DocumentScopedStorageTypeSchema }),
|
|
193
190
|
// `__unbound__` is NOT required here: cross-namespace contracts can
|
|
194
191
|
// declare only named namespaces (see cross-namespace FK fixtures). The
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
// (see `validateStorage` / `hydrateSqlStorage`), not by structural require.
|
|
192
|
+
// unbound slot is injected when absent by `ensureUnboundNamespaceSlot`
|
|
193
|
+
// in `build-contract.ts`, not enforced here structurally.
|
|
198
194
|
'namespaces?': type({ '[string]': namespaceEntry }),
|
|
199
195
|
}) as Type<unknown>;
|
|
200
196
|
}
|
|
@@ -368,45 +364,21 @@ export function createSqlContractSchema(
|
|
|
368
364
|
|
|
369
365
|
const SqlContractSchema = createSqlContractSchema(DEFAULT_SQL_KINDS);
|
|
370
366
|
|
|
371
|
-
// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()
|
|
372
|
-
// instead of type.declare<T>().type() because the ColumnDefault union's value field
|
|
373
|
-
// includes bigint | Date (runtime-only types after decoding) which cannot be expressed
|
|
374
|
-
// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges
|
|
375
|
-
// the gap between the JSON-safe Arktype output and the runtime TypeScript type.
|
|
376
|
-
|
|
377
367
|
/**
|
|
378
|
-
* Validates the structural shape of SqlStorage using Arktype.
|
|
368
|
+
* Validates the structural shape of SqlStorage using Arktype. Pure
|
|
369
|
+
* structural check: namespace IR is never materialized here (that needs
|
|
370
|
+
* a target concretion via the serializer hydration path), so this throws
|
|
371
|
+
* on invalid input and constructs nothing.
|
|
379
372
|
*
|
|
380
373
|
* @param value - The storage value to validate
|
|
381
|
-
* @returns The validated storage if structure is valid
|
|
382
374
|
* @throws Error if the storage structure is invalid
|
|
383
375
|
*/
|
|
384
|
-
export function validateStorage(value: unknown):
|
|
376
|
+
export function validateStorage(value: unknown): void {
|
|
385
377
|
const result = StorageSchema(value);
|
|
386
378
|
if (result instanceof type.errors) {
|
|
387
379
|
const messages = result.map((p: { message: string }) => p.message).join('; ');
|
|
388
380
|
throw new Error(`Storage validation failed: ${messages}`);
|
|
389
381
|
}
|
|
390
|
-
// Arktype validates the JSON-safe envelope, but the `ColumnDefault`
|
|
391
|
-
// union carries runtime-only `bigint | Date` that the validation DSL
|
|
392
|
-
// can't express (see NOTE above), so bridge the validated shape to the
|
|
393
|
-
// input type. Construction below re-materialises nested IR fields.
|
|
394
|
-
const validated = blindCast<
|
|
395
|
-
SqlStorageInput & { readonly namespaces?: SqlStorageInput['namespaces'] },
|
|
396
|
-
'arktype validated the JSON envelope but its output type is unknown (ColumnDefault carries runtime-only bigint|Date); bridge to the input shape'
|
|
397
|
-
>(result);
|
|
398
|
-
const namespaces = buildSqlNamespaceMap(validated.namespaces ?? {});
|
|
399
|
-
// Compatibility shim: inject the empty unbound singleton when absent so that
|
|
400
|
-
// production code paths which address __unbound__ for table metadata have a
|
|
401
|
-
// slot to read or write into. The `SqlStorageInput['namespaces']` type no
|
|
402
|
-
// longer requires __unbound__, so this is a runtime convenience, not a type
|
|
403
|
-
// invariant.
|
|
404
|
-
const unbound = namespaces[UNBOUND_NAMESPACE_ID] ?? SqlUnboundNamespace.instance;
|
|
405
|
-
return new SqlStorage({
|
|
406
|
-
storageHash: validated.storageHash,
|
|
407
|
-
...ifDefined('types', validated.types),
|
|
408
|
-
namespaces: { ...namespaces, [UNBOUND_NAMESPACE_ID]: unbound },
|
|
409
|
-
});
|
|
410
382
|
}
|
|
411
383
|
|
|
412
384
|
export function validateModel(value: unknown): unknown {
|
|
@@ -846,5 +818,208 @@ export function validateSqlContractFully<T extends Contract<SqlStorage>>(
|
|
|
846
818
|
);
|
|
847
819
|
}
|
|
848
820
|
validateModelStorageReferences(validated);
|
|
821
|
+
validateRelationThroughConsistency(validated);
|
|
849
822
|
return validated;
|
|
850
823
|
}
|
|
824
|
+
|
|
825
|
+
/** Storage column lookup for through-consistency validation. */
|
|
826
|
+
function lookupStorageColumn(
|
|
827
|
+
contract: Contract<SqlStorage>,
|
|
828
|
+
namespaceId: string,
|
|
829
|
+
tableName: string,
|
|
830
|
+
columnName: string,
|
|
831
|
+
): StorageColumn | undefined {
|
|
832
|
+
const rawTable = contract.storage.namespaces[namespaceId]?.entries.table?.[tableName];
|
|
833
|
+
if (rawTable === undefined) {
|
|
834
|
+
return undefined;
|
|
835
|
+
}
|
|
836
|
+
const table = blindCast<StorageTable, 'structurally validated storage table'>(rawTable);
|
|
837
|
+
return table.columns[columnName];
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Two storage columns share a type when their `nativeType` and `typeParams`
|
|
842
|
+
* match. The contract is canonicalized, so `typeParams` key order is stable and
|
|
843
|
+
* a JSON comparison is exact. `codecId` and `nullable` are intentionally not
|
|
844
|
+
* compared: they do not change the database-level type that governs a join.
|
|
845
|
+
*/
|
|
846
|
+
function sameStorageType(a: StorageColumn, b: StorageColumn): boolean {
|
|
847
|
+
return (
|
|
848
|
+
a.nativeType === b.nativeType &&
|
|
849
|
+
JSON.stringify(a.typeParams ?? null) === JSON.stringify(b.typeParams ?? null)
|
|
850
|
+
);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function describeColumnType(column: StorageColumn): string {
|
|
854
|
+
return column.typeParams === undefined
|
|
855
|
+
? column.nativeType
|
|
856
|
+
: `${column.nativeType} ${JSON.stringify(column.typeParams)}`;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Validates one side of an N:M join: the junction columns and the model
|
|
861
|
+
* columns they pair against positionally must be equal in number, exist in
|
|
862
|
+
* their tables, and share the same storage type (`nativeType` + `typeParams`).
|
|
863
|
+
* The junction's storage foreign keys already guarantee this for user-declared
|
|
864
|
+
* FK constraints, but `through` is a logical descriptor never tied to them by
|
|
865
|
+
* the rest of validation — and the TS builder accepts explicit join columns
|
|
866
|
+
* without requiring a junction FK at all — so this checks the columns directly
|
|
867
|
+
* against storage, one path regardless of how the junction was authored.
|
|
868
|
+
*
|
|
869
|
+
* Joined columns must be the *same* storage type, not merely compatible:
|
|
870
|
+
* relying on implicit conversion (e.g. `text`↔`character`) is unsafe on writes
|
|
871
|
+
* — `character(n)` space-padding makes such coercions non-associative — and no
|
|
872
|
+
* ADR sanctions heterogeneous junction columns. Equality is the conservative
|
|
873
|
+
* default; it can be relaxed deliberately if a real use case ever appears.
|
|
874
|
+
*/
|
|
875
|
+
function validateThroughJoinSide(input: {
|
|
876
|
+
readonly contract: Contract<SqlStorage>;
|
|
877
|
+
readonly qualifiedName: string;
|
|
878
|
+
readonly modelColumns: readonly string[];
|
|
879
|
+
readonly modelColumnsLabel: string;
|
|
880
|
+
/**
|
|
881
|
+
* The model side of the join, when resolvable. Absent for a cross-space
|
|
882
|
+
* target whose storage lives in another contract: the length and
|
|
883
|
+
* junction-column-existence checks still run, but the target-column
|
|
884
|
+
* existence and type checks are skipped because the target table is not
|
|
885
|
+
* available here. `fieldToColumn` is present when `modelColumns` are domain
|
|
886
|
+
* field names (the `on.*Fields` arrays), absent when they are already storage
|
|
887
|
+
* column names (the `through.*Columns` arrays).
|
|
888
|
+
*/
|
|
889
|
+
readonly model?: {
|
|
890
|
+
readonly namespaceId: string;
|
|
891
|
+
readonly table: string;
|
|
892
|
+
readonly fieldToColumn?: Readonly<Record<string, { readonly column: string }>>;
|
|
893
|
+
};
|
|
894
|
+
readonly junctionColumns: readonly string[];
|
|
895
|
+
readonly junctionColumnsLabel: string;
|
|
896
|
+
readonly junctionNamespaceId: string;
|
|
897
|
+
readonly junctionTable: string;
|
|
898
|
+
}): void {
|
|
899
|
+
const fail = (detail: string): ContractValidationError =>
|
|
900
|
+
new ContractValidationError(
|
|
901
|
+
`Many-to-many relation "${input.qualifiedName}" ${detail}`,
|
|
902
|
+
'storage',
|
|
903
|
+
);
|
|
904
|
+
if (input.junctionColumns.length !== input.modelColumns.length) {
|
|
905
|
+
throw fail(
|
|
906
|
+
`pairs ${input.junctionColumnsLabel} (${input.junctionColumns.length}) with ${input.modelColumnsLabel} (${input.modelColumns.length}) of differing length; they join positionally and must match.`,
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
for (const [index, junctionColumnName] of input.junctionColumns.entries()) {
|
|
910
|
+
const modelColumnRef = input.modelColumns[index];
|
|
911
|
+
if (modelColumnRef === undefined) {
|
|
912
|
+
continue;
|
|
913
|
+
}
|
|
914
|
+
const junctionColumn = lookupStorageColumn(
|
|
915
|
+
input.contract,
|
|
916
|
+
input.junctionNamespaceId,
|
|
917
|
+
input.junctionTable,
|
|
918
|
+
junctionColumnName,
|
|
919
|
+
);
|
|
920
|
+
if (junctionColumn === undefined) {
|
|
921
|
+
throw fail(
|
|
922
|
+
`${input.junctionColumnsLabel} references column "${junctionColumnName}" absent from junction table "${input.junctionNamespaceId}.${input.junctionTable}".`,
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
// Cross-space target: its storage lives in another contract, so the target
|
|
926
|
+
// column's existence and type cannot be checked here. Length and
|
|
927
|
+
// junction-column existence have already been validated above.
|
|
928
|
+
const model = input.model;
|
|
929
|
+
if (model === undefined) {
|
|
930
|
+
continue;
|
|
931
|
+
}
|
|
932
|
+
let modelColumnName = modelColumnRef;
|
|
933
|
+
if (model.fieldToColumn !== undefined) {
|
|
934
|
+
const mapped = model.fieldToColumn[modelColumnRef];
|
|
935
|
+
if (mapped === undefined) {
|
|
936
|
+
throw fail(
|
|
937
|
+
`${input.modelColumnsLabel} references field "${modelColumnRef}" absent from model on table "${model.namespaceId}.${model.table}".`,
|
|
938
|
+
);
|
|
939
|
+
}
|
|
940
|
+
modelColumnName = mapped.column;
|
|
941
|
+
}
|
|
942
|
+
const modelColumn = lookupStorageColumn(
|
|
943
|
+
input.contract,
|
|
944
|
+
model.namespaceId,
|
|
945
|
+
model.table,
|
|
946
|
+
modelColumnName,
|
|
947
|
+
);
|
|
948
|
+
if (modelColumn === undefined) {
|
|
949
|
+
throw fail(
|
|
950
|
+
`${input.modelColumnsLabel} references column "${modelColumnName}" absent from table "${model.namespaceId}.${model.table}".`,
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
if (!sameStorageType(junctionColumn, modelColumn)) {
|
|
954
|
+
throw fail(
|
|
955
|
+
`joins "${input.junctionTable}.${junctionColumnName}" (${describeColumnType(junctionColumn)}) with "${model.table}.${modelColumnName}" (${describeColumnType(modelColumn)}) of differing storage type; junction columns must match the type of the column they reference.`,
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Validates that every N:M relation's `through` descriptor is consistent with
|
|
963
|
+
* the storage columns it joins: both join sides match in column count,
|
|
964
|
+
* reference columns that exist in their tables, and pair columns of the same
|
|
965
|
+
* storage type. Without this, a `through` that disagrees with storage surfaces
|
|
966
|
+
* as a silently wrong JOIN at query time rather than a validation error here.
|
|
967
|
+
*/
|
|
968
|
+
function validateRelationThroughConsistency(contract: Contract<SqlStorage>): void {
|
|
969
|
+
for (const [namespaceId, namespace] of Object.entries(contract.domain.namespaces)) {
|
|
970
|
+
for (const [modelName, model] of Object.entries(namespace.models)) {
|
|
971
|
+
for (const [relationName, relation] of Object.entries(model.relations)) {
|
|
972
|
+
if (relation.cardinality !== 'N:M') continue;
|
|
973
|
+
const qualifiedName = `${namespaceId}.${modelName}.${relationName}`;
|
|
974
|
+
const { on, through } = relation;
|
|
975
|
+
const modelStorage = blindCast<SqlModelStorage, 'SQL contract model storage'>(
|
|
976
|
+
model.storage,
|
|
977
|
+
);
|
|
978
|
+
// Parent side: the owning model's localFields (domain field names) join
|
|
979
|
+
// the junction's parentColumns (storage columns).
|
|
980
|
+
validateThroughJoinSide({
|
|
981
|
+
contract,
|
|
982
|
+
qualifiedName,
|
|
983
|
+
modelColumns: on.localFields,
|
|
984
|
+
modelColumnsLabel: 'on.localFields',
|
|
985
|
+
model: {
|
|
986
|
+
namespaceId,
|
|
987
|
+
table: modelStorage.table,
|
|
988
|
+
fieldToColumn: modelStorage.fields,
|
|
989
|
+
},
|
|
990
|
+
junctionColumns: through.parentColumns,
|
|
991
|
+
junctionColumnsLabel: 'through.parentColumns',
|
|
992
|
+
junctionNamespaceId: through.namespaceId,
|
|
993
|
+
junctionTable: through.table,
|
|
994
|
+
});
|
|
995
|
+
// Child side: the junction's childColumns join the target model's
|
|
996
|
+
// targetColumns. Length and junction-column existence are checked
|
|
997
|
+
// regardless; a cross-space target lives in another contract, so its
|
|
998
|
+
// column existence and type are checked only when it is resolvable here.
|
|
999
|
+
const targetModel =
|
|
1000
|
+
relation.to.space === undefined
|
|
1001
|
+
? contract.domain.namespaces[relation.to.namespace]?.models[relation.to.model]
|
|
1002
|
+
: undefined;
|
|
1003
|
+
const targetModelSide =
|
|
1004
|
+
targetModel === undefined
|
|
1005
|
+
? undefined
|
|
1006
|
+
: {
|
|
1007
|
+
namespaceId: relation.to.namespace,
|
|
1008
|
+
table: blindCast<SqlModelStorage, 'SQL contract model storage'>(targetModel.storage)
|
|
1009
|
+
.table,
|
|
1010
|
+
};
|
|
1011
|
+
validateThroughJoinSide({
|
|
1012
|
+
contract,
|
|
1013
|
+
qualifiedName,
|
|
1014
|
+
modelColumns: through.targetColumns,
|
|
1015
|
+
modelColumnsLabel: 'through.targetColumns',
|
|
1016
|
+
...ifDefined('model', targetModelSide),
|
|
1017
|
+
junctionColumns: through.childColumns,
|
|
1018
|
+
junctionColumnsLabel: 'through.childColumns',
|
|
1019
|
+
junctionNamespaceId: through.namespaceId,
|
|
1020
|
+
junctionTable: through.table,
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entity-kinds-Cl36zL5j.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts","../src/entity-kinds.ts"],"sourcesContent":["import { type Type, type } from 'arktype';\nimport type { ForeignKeyInput, ReferentialAction } from './foreign-key';\nimport type { ForeignKeyReferenceInput } from './foreign-key-reference';\nimport type { PrimaryKeyInput } from './primary-key';\nimport type { UniqueConstraintInput } from './unique-constraint';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\n\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst ControlPolicySchema = type(\"'managed' | 'tolerated' | 'external' | 'observed'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst StorageValueSetRefSchema = type({\n plane: \"'storage'\",\n namespaceId: 'string',\n entityKind: \"'valueSet'\",\n entityName: 'string',\n 'spaceId?': 'string',\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n 'control?': ControlPolicySchema,\n 'valueSet?': StorageValueSetRefSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\n/**\n * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.\n * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an\n * ordered `values` array of codec-encoded permitted values.\n */\nexport const StorageValueSetSchema = type({\n kind: \"'valueSet'\",\n values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')\n .array()\n .readonly(),\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKeyInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraintInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'type?': 'string',\n 'options?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferenceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n 'spaceId?': 'string',\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ForeignKeySourceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKeyInput>().type({\n source: ForeignKeySourceSchema,\n target: ForeignKeyReferenceSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nexport const CheckConstraintSchema = type({\n '+': 'reject',\n name: 'string',\n column: 'string',\n valueSet: StorageValueSetRefSchema,\n});\n\nexport const StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n 'control?': ControlPolicySchema,\n 'checks?': CheckConstraintSchema.array().readonly(),\n});\n","import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. StorageValueSet)\n // can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import type { ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration.\n *\n * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\n readonly constraint: boolean;\n readonly index: boolean;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\n this.constraint = input.constraint;\n this.index = input.index;\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import type { ColumnDefault, ControlPolicy, ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent namespace's `tables: Record<string, StorageTable>` map.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n}\n","import type { JsonValue } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageValueSet}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface StorageValueSetInput {\n readonly kind: 'valueSet';\n /** Ordered permitted values, codec-encoded. Declaration order is preserved. */\n readonly values: readonly JsonValue[];\n}\n\n/**\n * SQL Contract IR node for a value-set entry in a namespace's `valueSet`\n * map (`SqlNamespace.entries.valueSet`).\n *\n * A value-set records the ordered set of permitted codec-encoded values for\n * an enum-like column restriction. It does not carry a `codecId` — the\n * column that references it already holds the codec; the value-set holds\n * only the permitted values.\n *\n * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope\n * carries the discriminator and the serializer hydration walker can\n * dispatch on it. This follows the per-leaf enumerable-kind convention\n * established in the SQL-node comment (future polymorphic dispatch on\n * namespace entries needs the discriminator in JSON).\n *\n * The entry's name is not on the class — value-sets are keyed by name in\n * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.\n */\nexport class StorageValueSet extends SqlNode {\n override readonly kind = 'valueSet' as const;\n readonly values: readonly JsonValue[];\n\n constructor(input: StorageValueSetInput) {\n super();\n this.values = Object.freeze([...input.values]);\n freezeNode(this);\n }\n}\n","import type {\n AnyEntityKindDescriptor,\n EntityKindDescriptor,\n} from '@prisma-next/framework-components/ir';\nimport { StorageTableSchema, StorageValueSetSchema } from './ir/storage-entry-schemas';\nimport { StorageTable, type StorageTableInput } from './ir/storage-table';\nimport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\n\nexport const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable> = {\n kind: 'table',\n schema: StorageTableSchema,\n construct: (input) => new StorageTable(input),\n};\n\nexport const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet> = {\n kind: 'valueSet',\n schema: StorageValueSetSchema,\n construct: (input) => new StorageValueSet(input),\n};\n\n/**\n * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in\n * `table` and `valueSet` kinds plus any target `packKinds`. This builds the\n * lookup table — it does not touch contract data. `hydrateNamespaceEntities`\n * later consumes this registry to turn a namespace's raw entries into IR\n * instances, and `createSqlContractSchema` derives validation from the same\n * registry. Throws on a duplicate kind.\n */\nexport function composeSqlEntityKinds(\n packKinds: readonly AnyEntityKindDescriptor[] = [],\n): ReadonlyMap<string, AnyEntityKindDescriptor> {\n const kinds = new Map<string, AnyEntityKindDescriptor>([\n ['table', tableEntityKind],\n ['valueSet', valueSetEntityKind],\n ]);\n for (const descriptor of packKinds) {\n if (kinds.has(descriptor.kind)) {\n throw new Error(\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n );\n }\n kinds.set(descriptor.kind, descriptor);\n }\n return kinds;\n}\n"],"mappings":";;;;AAYA,MAAM,oBAAoB,KAAK,WAAW;AAC1C,MAAM,qBAAqB,KAAK,YAAY;AAC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@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage-value-set-WnYsIFM8.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts","../src/ir/storage-value-set.ts"],"mappings":";;;;;;AASA;;;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAW;AAAA;;AAAA;AAiBhC;;;;;;;;;;;;cAAa,eAAA,SAAwB,OAAA;EAAA,SAC1B,IAAA;EAAA,SACA,MAAA;EAAA,SACA,QAAA,EAAU,WAAA;cAEP,KAAA,EAAO,oBAAA;AAAA;;;UC/BJ,eAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAI;AAAA;;;;cAMF,UAAA,SAAmB,OAAO;EAAA,SAC5B,OAAA;EAAA,SACQ,IAAA;cAEL,KAAA,EAAO,eAAA;AAAA;;;UCZJ,UAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;;;;;;;AFKK;AAiBhC;cEXa,KAAA,SAAc,OAAA;EAAA,SAChB,OAAA;EAAA,SACQ,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;cAEf,KAAA,EAAO,UAAA;AAAA;;;;;AFfrB;;;;;;;;UGKiB,kBAAA;EAAA,SACN,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA,GAAa,MAAA;EAAA,SACb,OAAA;EAAA,SACA,OAAA,GAAU,aAAA;EAAA,SACV,OAAA,GAAU,aAAA;EAAA,SACV,QAAA,GAAW,WAAA;AAAA;;;;;;;;;;AHYmB;;;;cGI5B,aAAA,SAAsB,OAAA;EAAA,SACxB,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAAA,SACQ,UAAA,GAAa,MAAA;EAAA,SACb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A;AAAA"}
|
package/dist/types-B-eiQXff.mjs
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { p as SqlNode, t as composeSqlEntityKinds } from "./entity-kinds-Cl36zL5j.mjs";
|
|
2
|
-
import { NamespaceBase, UNBOUND_NAMESPACE_ID, freezeNode, hydrateNamespaceEntities } from "@prisma-next/framework-components/ir";
|
|
3
|
-
import { blindCast } from "@prisma-next/utils/casts";
|
|
4
|
-
//#region src/ir/sql-unbound-namespace.ts
|
|
5
|
-
/**
|
|
6
|
-
* Family-layer placeholder for the SQL unbound-namespace singleton —
|
|
7
|
-
* the late-bound slot whose binding the target resolves at connection
|
|
8
|
-
* time rather than at authoring time.
|
|
9
|
-
*
|
|
10
|
-
* SQL contracts honour the framework `Storage.namespaces` invariant from
|
|
11
|
-
* the moment they appear in the IR. Today `SqlStorage` is family-shared
|
|
12
|
-
* (Postgres + SQLite consume the same class); a per-target namespace
|
|
13
|
-
* concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)
|
|
14
|
-
* earns its existence when each target's namespace shape lands. Until
|
|
15
|
-
* then the family ships a single placeholder singleton so the JSON
|
|
16
|
-
* envelope and runtime walk are honest at every layer.
|
|
17
|
-
*
|
|
18
|
-
* The `kind` discriminator is installed as a non-enumerable own property
|
|
19
|
-
* so the JSON envelope reads `{ "id": "__unbound__", "entries": { … } }`
|
|
20
|
-
* — symmetric with the family-level non-enumerable `kind` on `SqlNode`
|
|
21
|
-
* and bounded to the minimum data the framework `Namespace` interface
|
|
22
|
-
* promises.
|
|
23
|
-
*
|
|
24
|
-
* **Freeze-trap warning.** The leaf constructor calls
|
|
25
|
-
* `freezeNode(this)` after installing `kind`. The leaf-class shape
|
|
26
|
-
* works today only because `NamespaceBase` does NOT freeze in its
|
|
27
|
-
* constructor — the `Object.defineProperty(this, 'kind', …)` call after
|
|
28
|
-
* `super()` succeeds because the instance is still mutable at that
|
|
29
|
-
* point. Subclasses that add instance fields will still hit the freeze
|
|
30
|
-
* trap once leaf-class `freezeNode(this)` runs; and if a future
|
|
31
|
-
* framework change lifts the freeze to `NamespaceBase`, even the
|
|
32
|
-
* `defineProperty` here would silently fail. To add subclass instance
|
|
33
|
-
* fields safely, lift `freezeNode` to a leaf-class `seal()` hook each
|
|
34
|
-
* leaf calls explicitly at the end of its own constructor.
|
|
35
|
-
*/
|
|
36
|
-
var SqlUnboundNamespace = class SqlUnboundNamespace extends NamespaceBase {
|
|
37
|
-
static instance = new SqlUnboundNamespace();
|
|
38
|
-
id = UNBOUND_NAMESPACE_ID;
|
|
39
|
-
entries = Object.freeze({ table: blindCast(Object.freeze({})) });
|
|
40
|
-
constructor() {
|
|
41
|
-
super();
|
|
42
|
-
Object.defineProperty(this, "kind", {
|
|
43
|
-
value: "sql-namespace",
|
|
44
|
-
writable: false,
|
|
45
|
-
enumerable: false,
|
|
46
|
-
configurable: true
|
|
47
|
-
});
|
|
48
|
-
freezeNode(this);
|
|
49
|
-
}
|
|
50
|
-
get table() {
|
|
51
|
-
return blindCast(this.entries["table"]);
|
|
52
|
-
}
|
|
53
|
-
qualifyTable(tableName) {
|
|
54
|
-
return `"${tableName}"`;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/ir/build-sql-namespace.ts
|
|
59
|
-
const SQL_NAMESPACE_KIND = "sql-namespace";
|
|
60
|
-
function isMaterializedSqlNamespace(ns) {
|
|
61
|
-
if (typeof ns !== "object" || ns === null) return false;
|
|
62
|
-
const proto = Object.getPrototypeOf(ns);
|
|
63
|
-
if (proto === Object.prototype || proto === null) return false;
|
|
64
|
-
return ns.kind === SQL_NAMESPACE_KIND;
|
|
65
|
-
}
|
|
66
|
-
var SqlBoundNamespace = class SqlBoundNamespace extends NamespaceBase {
|
|
67
|
-
id;
|
|
68
|
-
entries;
|
|
69
|
-
static fromTablesInput(input) {
|
|
70
|
-
const tableKind = input.entries["table"];
|
|
71
|
-
const tableCount = tableKind !== void 0 ? Object.keys(tableKind).length : 0;
|
|
72
|
-
const valueSetKind = input.entries["valueSet"];
|
|
73
|
-
const hasValueSets = valueSetKind !== void 0 && Object.keys(valueSetKind).length > 0;
|
|
74
|
-
const hasUnknownKinds = Object.keys(input.entries).some((kind) => kind !== "table" && kind !== "valueSet");
|
|
75
|
-
if (input.id === UNBOUND_NAMESPACE_ID && tableCount === 0 && !hasValueSets && !hasUnknownKinds) return SqlUnboundNamespace.instance;
|
|
76
|
-
return new SqlBoundNamespace(input);
|
|
77
|
-
}
|
|
78
|
-
constructor(input) {
|
|
79
|
-
super();
|
|
80
|
-
this.id = input.id;
|
|
81
|
-
const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), "carry");
|
|
82
|
-
this.entries = Object.freeze(blindCast(dispatched));
|
|
83
|
-
Object.defineProperty(this, "kind", {
|
|
84
|
-
value: SQL_NAMESPACE_KIND,
|
|
85
|
-
writable: false,
|
|
86
|
-
enumerable: false,
|
|
87
|
-
configurable: true
|
|
88
|
-
});
|
|
89
|
-
freezeNode(this);
|
|
90
|
-
}
|
|
91
|
-
get table() {
|
|
92
|
-
return this.entries.table ?? Object.freeze({});
|
|
93
|
-
}
|
|
94
|
-
get valueSet() {
|
|
95
|
-
return this.entries.valueSet;
|
|
96
|
-
}
|
|
97
|
-
qualifyTable(tableName) {
|
|
98
|
-
if (this.id === UNBOUND_NAMESPACE_ID) return `"${tableName}"`;
|
|
99
|
-
return `"${this.id}"."${tableName}"`;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
function buildSqlNamespace(input) {
|
|
103
|
-
return SqlBoundNamespace.fromTablesInput(input);
|
|
104
|
-
}
|
|
105
|
-
function buildSqlNamespaceMap(namespaces) {
|
|
106
|
-
return Object.fromEntries(Object.entries(namespaces).map(([nsKey, ns]) => [nsKey, isMaterializedSqlNamespace(ns) ? ns : SqlBoundNamespace.fromTablesInput(blindCast(ns))]));
|
|
107
|
-
}
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region src/ir/storage-type-instance.ts
|
|
110
|
-
/**
|
|
111
|
-
* Sentinel kind for the legacy codec-triple shape persisted under
|
|
112
|
-
* `SqlStorage.types`. Plain JSON-clean object literals carry this
|
|
113
|
-
* discriminator so the polymorphic slot dispatch can route them down
|
|
114
|
-
* the codec path while target-specific IR class instances (e.g. the
|
|
115
|
-
* Postgres enum class) keep their own narrower `kind` literal.
|
|
116
|
-
*/
|
|
117
|
-
const CODEC_INSTANCE_KIND = "codec-instance";
|
|
118
|
-
/**
|
|
119
|
-
* Stamp the codec-instance `kind` discriminator on a caller-supplied
|
|
120
|
-
* codec triple. Idempotent: input that already carries the discriminator
|
|
121
|
-
* passes through unchanged. Missing `typeParams` is normalised to `{}`.
|
|
122
|
-
*/
|
|
123
|
-
function toStorageTypeInstance(input) {
|
|
124
|
-
return {
|
|
125
|
-
kind: CODEC_INSTANCE_KIND,
|
|
126
|
-
codecId: input.codecId,
|
|
127
|
-
nativeType: input.nativeType,
|
|
128
|
-
typeParams: input.typeParams ?? {}
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Type-guard for codec-typed entries on the polymorphic
|
|
133
|
-
* `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from
|
|
134
|
-
* any class-instance kinds a target pack contributes.
|
|
135
|
-
*/
|
|
136
|
-
function isStorageTypeInstance(value) {
|
|
137
|
-
if (typeof value !== "object" || value === null) return false;
|
|
138
|
-
return value.kind === CODEC_INSTANCE_KIND;
|
|
139
|
-
}
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/ir/sql-storage.ts
|
|
142
|
-
var SqlStorage = class extends SqlNode {
|
|
143
|
-
storageHash;
|
|
144
|
-
namespaces;
|
|
145
|
-
constructor(input) {
|
|
146
|
-
super();
|
|
147
|
-
this.storageHash = input.storageHash;
|
|
148
|
-
this.namespaces = Object.freeze(input.namespaces);
|
|
149
|
-
if (input.types !== void 0) this.types = Object.freeze(Object.fromEntries(Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)])));
|
|
150
|
-
freezeNode(this);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
/**
|
|
154
|
-
* Strict polymorphic-slot dispatch for `SqlStorage.types` entries.
|
|
155
|
-
* Every entry must carry a `kind: 'codec-instance'` discriminator or
|
|
156
|
-
* be an already-constructed `StorageTypeInstance`. Untagged or
|
|
157
|
-
* unrecognised inputs throw a diagnostic naming the entry and its
|
|
158
|
-
* `kind`, so format drift surfaces loudly at the deserializer
|
|
159
|
-
* boundary instead of slipping past the seam and corrupting
|
|
160
|
-
* downstream IR walks.
|
|
161
|
-
*
|
|
162
|
-
* Codec-triple authors that have an untagged shape on hand can call
|
|
163
|
-
* `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`
|
|
164
|
-
* discriminator) before constructing `SqlStorage`. On-disk reads
|
|
165
|
-
* cross `familyInstance.deserializeContract` first; the structural
|
|
166
|
-
* arktype schema rejects untagged entries earlier, so this throw
|
|
167
|
-
* only fires for in-memory authoring bugs.
|
|
168
|
-
*/
|
|
169
|
-
function normaliseTypeEntry(name, entry) {
|
|
170
|
-
if (isStorageTypeInstance(entry)) {
|
|
171
|
-
if ("typeParams" in entry) return entry;
|
|
172
|
-
return toStorageTypeInstance(entry);
|
|
173
|
-
}
|
|
174
|
-
const rawKind = entry.kind;
|
|
175
|
-
const kindDescription = rawKind === void 0 ? "missing `kind` discriminator" : `unrecognised \`kind\` discriminator ${JSON.stringify(rawKind)}`;
|
|
176
|
-
throw new Error(`storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify("codec-instance")}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`);
|
|
177
|
-
}
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region src/types.ts
|
|
180
|
-
const DEFAULT_FK_CONSTRAINT = true;
|
|
181
|
-
const DEFAULT_FK_INDEX = true;
|
|
182
|
-
function applyFkDefaults(fk, overrideDefaults) {
|
|
183
|
-
return {
|
|
184
|
-
constraint: fk.constraint ?? overrideDefaults?.constraint ?? true,
|
|
185
|
-
index: fk.index ?? overrideDefaults?.index ?? true
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
//#endregion
|
|
189
|
-
export { CODEC_INSTANCE_KIND as a, buildSqlNamespace as c, SqlStorage as i, buildSqlNamespaceMap as l, DEFAULT_FK_INDEX as n, isStorageTypeInstance as o, applyFkDefaults as r, toStorageTypeInstance as s, DEFAULT_FK_CONSTRAINT as t, SqlUnboundNamespace as u };
|
|
190
|
-
|
|
191
|
-
//# sourceMappingURL=types-B-eiQXff.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-B-eiQXff.mjs","names":[],"sources":["../src/ir/sql-unbound-namespace.ts","../src/ir/build-sql-namespace.ts","../src/ir/storage-type-instance.ts","../src/ir/sql-storage.ts","../src/types.ts"],"sourcesContent":["import {\n freezeNode,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport type { SqlNamespaceEntries } from './sql-storage';\nimport type { StorageTable } from './storage-table';\n\n/**\n * Family-layer placeholder for the SQL unbound-namespace singleton —\n * the late-bound slot whose binding the target resolves at connection\n * time rather than at authoring time.\n *\n * SQL contracts honour the framework `Storage.namespaces` invariant from\n * the moment they appear in the IR. Today `SqlStorage` is family-shared\n * (Postgres + SQLite consume the same class); a per-target namespace\n * concretion (`PostgresSchema.unbound`, `SqliteUnboundDatabase.instance`)\n * earns its existence when each target's namespace shape lands. Until\n * then the family ships a single placeholder singleton so the JSON\n * envelope and runtime walk are honest at every layer.\n *\n * The `kind` discriminator is installed as a non-enumerable own property\n * so the JSON envelope reads `{ \"id\": \"__unbound__\", \"entries\": { … } }`\n * — symmetric with the family-level non-enumerable `kind` on `SqlNode`\n * and bounded to the minimum data the framework `Namespace` interface\n * promises.\n *\n * **Freeze-trap warning.** The leaf constructor calls\n * `freezeNode(this)` after installing `kind`. The leaf-class shape\n * works today only because `NamespaceBase` does NOT freeze in its\n * constructor — the `Object.defineProperty(this, 'kind', …)` call after\n * `super()` succeeds because the instance is still mutable at that\n * point. Subclasses that add instance fields will still hit the freeze\n * trap once leaf-class `freezeNode(this)` runs; and if a future\n * framework change lifts the freeze to `NamespaceBase`, even the\n * `defineProperty` here would silently fail. To add subclass instance\n * fields safely, lift `freezeNode` to a leaf-class `seal()` hook each\n * leaf calls explicitly at the end of its own constructor.\n */\nexport class SqlUnboundNamespace extends NamespaceBase {\n static readonly instance: SqlUnboundNamespace = new SqlUnboundNamespace();\n\n readonly id = UNBOUND_NAMESPACE_ID;\n readonly entries: SqlNamespaceEntries = Object.freeze({\n table: blindCast<\n Readonly<Record<string, StorageTable>>,\n 'empty frozen map is a valid Readonly<Record<string, StorageTable>>'\n >(Object.freeze({})),\n });\n declare readonly kind: string;\n\n private constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql-namespace',\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return blindCast<\n Readonly<Record<string, StorageTable>>,\n 'entries[table] holds only StorageTable by construction'\n >(this.entries['table']);\n }\n\n qualifyTable(tableName: string): string {\n return `\"${tableName}\"`;\n }\n}\n","import {\n freezeNode,\n hydrateNamespaceEntities,\n type Namespace,\n NamespaceBase,\n UNBOUND_NAMESPACE_ID,\n} from '@prisma-next/framework-components/ir';\nimport { blindCast } from '@prisma-next/utils/casts';\nimport { composeSqlEntityKinds } from '../entity-kinds';\nimport type { SqlNamespace, SqlNamespaceEntries, SqlNamespaceTablesInput } from './sql-storage';\nimport { SqlUnboundNamespace } from './sql-unbound-namespace';\nimport type { StorageTable } from './storage-table';\nimport type { StorageValueSet } from './storage-value-set';\n\nconst SQL_NAMESPACE_KIND = 'sql-namespace' as const;\n\nfunction isMaterializedSqlNamespace(ns: Namespace | SqlNamespaceTablesInput): ns is SqlNamespace {\n if (typeof ns !== 'object' || ns === null) {\n return false;\n }\n const proto = Object.getPrototypeOf(ns);\n if (proto === Object.prototype || proto === null) {\n return false;\n }\n return (ns as Namespace).kind === SQL_NAMESPACE_KIND;\n}\n\nclass SqlBoundNamespace extends NamespaceBase {\n declare readonly kind: string;\n\n readonly id: string;\n readonly entries: SqlNamespaceEntries;\n\n static fromTablesInput(input: SqlNamespaceTablesInput): SqlNamespace {\n const tableKind = input.entries['table'];\n const tableCount = tableKind !== undefined ? Object.keys(tableKind).length : 0;\n const valueSetKind = input.entries['valueSet'];\n const hasValueSets = valueSetKind !== undefined && Object.keys(valueSetKind).length > 0;\n const hasUnknownKinds = Object.keys(input.entries).some(\n (kind) => kind !== 'table' && kind !== 'valueSet',\n );\n if (\n input.id === UNBOUND_NAMESPACE_ID &&\n tableCount === 0 &&\n !hasValueSets &&\n !hasUnknownKinds\n ) {\n return SqlUnboundNamespace.instance;\n }\n return new SqlBoundNamespace(input);\n }\n\n private constructor(input: SqlNamespaceTablesInput) {\n super();\n this.id = input.id;\n\n const dispatched = hydrateNamespaceEntities(input.entries, composeSqlEntityKinds(), 'carry');\n\n this.entries = Object.freeze(\n blindCast<\n SqlNamespaceEntries,\n 'composeSqlEntityKinds() supplies table→StorageTable and valueSet→StorageValueSet descriptors, so this open-dict result holds exactly the typed members SqlNamespaceEntries declares; the descriptor Map erases those per-kind Node types from the return.'\n >(dispatched),\n );\n Object.defineProperty(this, 'kind', {\n value: SQL_NAMESPACE_KIND,\n writable: false,\n enumerable: false,\n configurable: true,\n });\n freezeNode(this);\n }\n\n get table(): Readonly<Record<string, StorageTable>> {\n return this.entries.table ?? Object.freeze({});\n }\n\n get valueSet(): Readonly<Record<string, StorageValueSet>> | undefined {\n return this.entries.valueSet;\n }\n\n qualifyTable(tableName: string): string {\n if (this.id === UNBOUND_NAMESPACE_ID) {\n return `\"${tableName}\"`;\n }\n return `\"${this.id}\".\"${tableName}\"`;\n }\n}\n\nexport function buildSqlNamespace(input: SqlNamespaceTablesInput): SqlNamespace {\n return SqlBoundNamespace.fromTablesInput(input);\n}\n\nexport function buildSqlNamespaceMap(\n namespaces: Readonly<Record<string, Namespace | SqlNamespaceTablesInput>>,\n): Readonly<Record<string, SqlNamespace>> {\n return Object.fromEntries(\n Object.entries(namespaces).map(([nsKey, ns]) => [\n nsKey,\n isMaterializedSqlNamespace(ns)\n ? ns\n : SqlBoundNamespace.fromTablesInput(\n blindCast<\n SqlNamespaceTablesInput,\n 'non-materialized SQL namespace map entry is a SqlNamespaceTablesInput'\n >(ns),\n ),\n ]),\n );\n}\n","import type { StorageType } from '@prisma-next/framework-components/ir';\n\n/**\n * Sentinel kind for the legacy codec-triple shape persisted under\n * `SqlStorage.types`. Plain JSON-clean object literals carry this\n * discriminator so the polymorphic slot dispatch can route them down\n * the codec path while target-specific IR class instances (e.g. the\n * Postgres enum class) keep their own narrower `kind` literal.\n */\nexport const CODEC_INSTANCE_KIND = 'codec-instance' as const;\n\n/**\n * Structural sub-interface of {@link StorageType} for codec-typed entries\n * in `SqlStorage.types`. These are plain object literals — there is no\n * runtime IR class, the JSON envelope round-trips through the slot\n * unchanged. The `kind: 'codec-instance'` discriminator is the dispatch\n * key that distinguishes codec-typed entries from any class-instance\n * kinds a target pack contributes to the polymorphic slot.\n */\nexport interface StorageTypeInstance extends StorageType {\n readonly kind: typeof CODEC_INSTANCE_KIND;\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n}\n\n/**\n * Construction-time input for a codec-triple entry. Symmetric with the\n * structural runtime shape minus the `kind` discriminator — callers may\n * omit `kind`; the helper {@link toStorageTypeInstance} stamps it on.\n * `typeParams` may be omitted on input; the constructor normalises a\n * missing value to `{}` so the in-memory shape is always present.\n */\nexport interface StorageTypeInstanceInput {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams?: Record<string, unknown>;\n}\n\n/**\n * Stamp the codec-instance `kind` discriminator on a caller-supplied\n * codec triple. Idempotent: input that already carries the discriminator\n * passes through unchanged. Missing `typeParams` is normalised to `{}`.\n */\nexport function toStorageTypeInstance(input: StorageTypeInstanceInput): StorageTypeInstance {\n return {\n kind: CODEC_INSTANCE_KIND,\n codecId: input.codecId,\n nativeType: input.nativeType,\n typeParams: input.typeParams ?? {},\n };\n}\n\n/**\n * Type-guard for codec-typed entries on the polymorphic\n * `SqlStorage.types` slot. Distinguishes `StorageTypeInstance` from\n * any class-instance kinds a target pack contributes.\n */\nexport function isStorageTypeInstance(value: unknown): value is StorageTypeInstance {\n if (typeof value !== 'object' || value === null) return false;\n return (value as { kind?: unknown }).kind === CODEC_INSTANCE_KIND;\n}\n","import type { StorageHashBase } from '@prisma-next/contract/types';\nimport { freezeNode, type Namespace, type Storage } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\nimport type { StorageTable } from './storage-table';\nimport {\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './storage-type-instance';\nimport type { StorageValueSet } from './storage-value-set';\n\n/**\n * Polymorphic value type for document-scoped `SqlStorage.types` entries\n * (codec aliases / parameterised native type registrations).\n *\n * Postgres native enum registrations live under the postgres-specific\n * `entries.type` slot on `PostgresSchema` (target layer), not here.\n */\nexport type SqlStorageTypeEntry = StorageTypeInstance | StorageTypeInstanceInput;\n\nexport interface SqlNamespaceTablesInput {\n readonly id: string;\n readonly entries: Readonly<Record<string, Readonly<Record<string, unknown>>>>;\n}\n\nexport interface SqlStorageInput<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n readonly types?: Record<string, SqlStorageTypeEntry>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n}\n\n/**\n * SQL Contract IR root node for the `storage` field.\n *\n * Single concrete family-shared class — both Postgres and SQLite\n * consume this class today. Per-target storage subclasses are\n * introduced when each target's namespace shape earns its\n * target-specific concretion (target-specific derived fields,\n * target-specific storage extensions).\n *\n * Honours the framework `Storage` interface: every SQL IR carries a\n * `namespaces` map keyed by namespace id. Callers must supply fully\n * constructed `Namespace` instances — construction discipline lives\n * in the authoring builders and deserializer hydration paths.\n *\n * The constructor normalises optional `types` into class instances.\n * `types` is polymorphic per Decision 18 Option B: codec-triple inputs\n * are stamped with `kind: 'codec-instance'`; hydration of raw JSON\n * class-instance entries (carrying their narrower `kind` literal) is\n * the per-target serializer's responsibility (so the family base does\n * not import target-specific subclasses).\n */\n/**\n * The typed `entries` shape for SQL family namespaces. The open dictionary\n * is intersected with optional known-kind maps so that `ns.entries.table`\n * and `ns.entries.valueSet` resolve without a cast, while unknown pack-\n * contributed kinds remain valid (the `Record` part allows any string key).\n */\nexport type SqlNamespaceEntries = Readonly<Record<string, Readonly<Record<string, unknown>>>> & {\n readonly table?: Readonly<Record<string, StorageTable>>;\n readonly valueSet?: Readonly<Record<string, StorageValueSet>>;\n};\n\n/**\n * SQL family namespace. `entries` is the open ADR 224 dictionary —\n * `entries[entityKind][entityName]` addresses any entity. Emitted\n * contract literals satisfy this structurally (no prototype getters\n * needed). For typed access to specific kinds, use the class getters\n * on the concretion or `ns.entries.table` / `ns.entries.valueSet` directly.\n */\nexport type SqlNamespace = Namespace & {\n readonly entries: SqlNamespaceEntries;\n /**\n * Render a dialect-qualified table reference for runtime SQL emission.\n * Present on materialised target concretions (`PostgresSchema`,\n * `SqliteDatabase`, …) and family placeholders; omitted on emitted\n * contract structural namespace literals (methods are not serialised).\n */\n qualifyTable?(tableName: string): string;\n};\n\nexport class SqlStorage<THash extends string = string> extends SqlNode implements Storage {\n readonly storageHash: StorageHashBase<THash>;\n readonly namespaces: Readonly<Record<string, SqlNamespace>>;\n declare readonly types?: Readonly<Record<string, StorageTypeInstance>>;\n\n constructor(input: SqlStorageInput<THash>) {\n super();\n this.storageHash = input.storageHash;\n this.namespaces = Object.freeze(input.namespaces);\n if (input.types !== undefined) {\n this.types = Object.freeze(\n Object.fromEntries(\n Object.entries(input.types).map(([name, ti]) => [name, normaliseTypeEntry(name, ti)]),\n ),\n );\n }\n freezeNode(this);\n }\n}\n\n/**\n * Strict polymorphic-slot dispatch for `SqlStorage.types` entries.\n * Every entry must carry a `kind: 'codec-instance'` discriminator or\n * be an already-constructed `StorageTypeInstance`. Untagged or\n * unrecognised inputs throw a diagnostic naming the entry and its\n * `kind`, so format drift surfaces loudly at the deserializer\n * boundary instead of slipping past the seam and corrupting\n * downstream IR walks.\n *\n * Codec-triple authors that have an untagged shape on hand can call\n * `toStorageTypeInstance(...)` (which stamps the `'codec-instance'`\n * discriminator) before constructing `SqlStorage`. On-disk reads\n * cross `familyInstance.deserializeContract` first; the structural\n * arktype schema rejects untagged entries earlier, so this throw\n * only fires for in-memory authoring bugs.\n */\nfunction normaliseTypeEntry(name: string, entry: SqlStorageTypeEntry): StorageTypeInstance {\n if (isStorageTypeInstance(entry)) {\n // Normalise on-disk objects that omit `typeParams` (the canonical on-disk\n // form strips empty typeParams to keep JSON compact). The in-memory invariant\n // is always `typeParams: {}` when empty — never `undefined`. Only create a\n // new object when necessary to preserve identity-equality for callers that\n // hold a reference to an already-correct in-memory entry.\n if ('typeParams' in entry) {\n return entry;\n }\n return toStorageTypeInstance(entry);\n }\n const rawKind = (entry as { kind?: unknown }).kind;\n const kindDescription =\n rawKind === undefined\n ? 'missing `kind` discriminator'\n : `unrecognised \\`kind\\` discriminator ${JSON.stringify(rawKind)}`;\n throw new Error(\n `storage.types[${JSON.stringify(name)}] has ${kindDescription}; expected ${JSON.stringify('codec-instance')}. Untagged codec triples should be wrapped with toStorageTypeInstance(...) before construction.`,\n );\n}\n","import type { CodecTrait } from '@prisma-next/framework-components/codec';\nimport type { ControlDriverInstance } from '@prisma-next/framework-components/control';\nimport type { ReferentialAction } from './ir/foreign-key';\n\nexport interface SqlControlDriverInstance<T extends string = string>\n extends ControlDriverInstance<'sql', T> {\n query<Row = Record<string, unknown>>(\n sql: string,\n params?: readonly unknown[],\n ): Promise<{ readonly rows: Row[] }>;\n}\n\nexport { buildSqlNamespace, buildSqlNamespaceMap } from './ir/build-sql-namespace';\nexport { CheckConstraint, type CheckConstraintInput } from './ir/check-constraint';\nexport {\n ForeignKey,\n type ForeignKeyInput,\n type ReferentialAction,\n} from './ir/foreign-key';\nexport {\n ForeignKeyReference,\n type ForeignKeyReferenceInput,\n} from './ir/foreign-key-reference';\nexport { PrimaryKey, type PrimaryKeyInput } from './ir/primary-key';\nexport { Index, type IndexInput } from './ir/sql-index';\nexport { SqlNode } from './ir/sql-node';\nexport {\n type SqlNamespace,\n type SqlNamespaceEntries,\n type SqlNamespaceTablesInput,\n SqlStorage,\n type SqlStorageInput,\n type SqlStorageTypeEntry,\n} from './ir/sql-storage';\nexport { SqlUnboundNamespace } from './ir/sql-unbound-namespace';\nexport { StorageColumn, type StorageColumnInput } from './ir/storage-column';\nexport { StorageTable, type StorageTableInput } from './ir/storage-table';\nexport {\n CODEC_INSTANCE_KIND,\n isStorageTypeInstance,\n type StorageTypeInstance,\n type StorageTypeInstanceInput,\n toStorageTypeInstance,\n} from './ir/storage-type-instance';\nexport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\nexport {\n UniqueConstraint,\n type UniqueConstraintInput,\n} from './ir/unique-constraint';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly namespaceId: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\n// Field-type maps nested by namespace coordinate: `[namespaceId][model][field]`.\n// Shared by the output and input field-type maps and their extractors.\nexport type NamespacedFieldTypeMap = Record<string, Record<string, Record<string, unknown>>>;\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n TFieldInputTypes extends NamespacedFieldTypeMap = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends NamespacedFieldTypeMap\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,sBAAb,MAAa,4BAA4B,cAAc;CACrD,OAAgB,WAAgC,IAAI,oBAAoB;CAExE,KAAc;CACd,UAAwC,OAAO,OAAO,EACpD,OAAO,UAGL,OAAO,OAAO,CAAC,CAAC,CAAC,EACrB,CAAC;CAGD,cAAsB;EACpB,MAAM;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