@prisma-next/contract 0.3.0-dev.139 → 0.3.0-dev.140

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 (38) hide show
  1. package/dist/hashing-CVS9sXxd.mjs +215 -0
  2. package/dist/hashing-CVS9sXxd.mjs.map +1 -0
  3. package/dist/hashing.d.mts +38 -0
  4. package/dist/hashing.d.mts.map +1 -0
  5. package/dist/hashing.mjs +3 -0
  6. package/dist/testing.d.mts +28 -0
  7. package/dist/testing.d.mts.map +1 -0
  8. package/dist/testing.mjs +56 -0
  9. package/dist/testing.mjs.map +1 -0
  10. package/dist/{contract-types-C0y-Bn8M.d.mts → types-D-iOS0Ks.d.mts} +52 -53
  11. package/dist/types-D-iOS0Ks.d.mts.map +1 -0
  12. package/dist/types-DokLaU9G.mjs +30 -0
  13. package/dist/types-DokLaU9G.mjs.map +1 -0
  14. package/dist/types.d.mts +1 -1
  15. package/dist/types.mjs +2 -29
  16. package/dist/validate-contract.d.mts +1 -1
  17. package/dist/validate-contract.mjs +1 -1
  18. package/dist/{validate-domain-WfuBWGsF.mjs → validate-domain-CTQiBiei.mjs} +1 -1
  19. package/dist/{validate-domain-WfuBWGsF.mjs.map → validate-domain-CTQiBiei.mjs.map} +1 -1
  20. package/dist/validate-domain.mjs +1 -1
  21. package/package.json +8 -7
  22. package/schemas/data-contract-document-v1.json +0 -5
  23. package/src/canonicalization.ts +286 -0
  24. package/src/contract-types.ts +1 -1
  25. package/src/exports/hashing.ts +6 -0
  26. package/src/exports/testing.ts +1 -0
  27. package/src/hashing.ts +69 -0
  28. package/src/testing-factories.ts +93 -0
  29. package/src/types.ts +7 -7
  30. package/dist/contract-types-C0y-Bn8M.d.mts.map +0 -1
  31. package/dist/ir-BPkihpFL.d.mts +0 -86
  32. package/dist/ir-BPkihpFL.d.mts.map +0 -1
  33. package/dist/ir.d.mts +0 -2
  34. package/dist/ir.mjs +0 -52
  35. package/dist/ir.mjs.map +0 -1
  36. package/dist/types.mjs.map +0 -1
  37. package/src/exports/ir.ts +0 -1
  38. package/src/ir.ts +0 -131
@@ -0,0 +1,93 @@
1
+ import type { Contract } from './contract-types';
2
+ import type { ContractModel, ModelStorageBase } from './domain-types';
3
+ import { computeExecutionHash, computeProfileHash, computeStorageHash } from './hashing';
4
+ import type { ExecutionSection, ProfileHashBase, StorageBase } from './types';
5
+ import { coreHash } from './types';
6
+
7
+ type ContractOverrides<
8
+ TStorage extends StorageBase = StorageBase,
9
+ TModels extends Record<string, ContractModel> = Record<string, ContractModel>,
10
+ > = {
11
+ target?: string;
12
+ targetFamily?: string;
13
+ roots?: Record<string, string>;
14
+ models?: TModels;
15
+ storage?: Omit<TStorage, 'storageHash'>;
16
+ capabilities?: Record<string, Record<string, boolean>>;
17
+ extensionPacks?: Record<string, unknown>;
18
+ execution?: ExecutionSection;
19
+ profileHash?: ProfileHashBase<string>;
20
+ meta?: Record<string, unknown>;
21
+ };
22
+
23
+ const DUMMY_HASH = coreHash('sha256:test');
24
+
25
+ export function createContract<
26
+ TStorage extends StorageBase = StorageBase,
27
+ TModels extends Record<string, ContractModel> = Record<string, ContractModel>,
28
+ >(overrides: ContractOverrides<TStorage, TModels> = {}): Contract<TStorage, TModels> {
29
+ const target = overrides.target ?? 'postgres';
30
+ const targetFamily = overrides.targetFamily ?? 'sql';
31
+ const capabilities = overrides.capabilities ?? {};
32
+
33
+ const rawStorage =
34
+ overrides.storage ?? ({ tables: {} } as unknown as Omit<TStorage, 'storageHash'>);
35
+
36
+ const storageHash = computeStorageHash({
37
+ target,
38
+ targetFamily,
39
+ storage: rawStorage as Record<string, unknown>,
40
+ });
41
+
42
+ const storage = {
43
+ ...rawStorage,
44
+ storageHash,
45
+ } as TStorage;
46
+
47
+ const computedProfileHash =
48
+ overrides.profileHash ?? computeProfileHash({ target, targetFamily, capabilities });
49
+
50
+ return {
51
+ target,
52
+ targetFamily,
53
+ roots: overrides.roots ?? {},
54
+ models: (overrides.models ?? {}) as TModels,
55
+ storage,
56
+ capabilities,
57
+ extensionPacks: overrides.extensionPacks ?? {},
58
+ ...(overrides.execution !== undefined
59
+ ? {
60
+ execution: {
61
+ ...overrides.execution,
62
+ executionHash: computeExecutionHash({
63
+ target,
64
+ targetFamily,
65
+ execution: overrides.execution,
66
+ }),
67
+ },
68
+ }
69
+ : {}),
70
+ profileHash: computedProfileHash,
71
+ meta: overrides.meta ?? {},
72
+ };
73
+ }
74
+
75
+ type SqlStorageLike = StorageBase & {
76
+ readonly tables: Record<string, unknown>;
77
+ readonly types?: Record<string, unknown>;
78
+ };
79
+
80
+ type SqlModelLike = ContractModel<ModelStorageBase & { table: string }>;
81
+
82
+ export function createSqlContract(
83
+ overrides: ContractOverrides<SqlStorageLike, Record<string, SqlModelLike>> = {},
84
+ ): Contract<SqlStorageLike, Record<string, SqlModelLike>> {
85
+ return createContract<SqlStorageLike, Record<string, SqlModelLike>>({
86
+ target: 'postgres',
87
+ targetFamily: 'sql',
88
+ storage: overrides.storage ?? { tables: {} },
89
+ ...overrides,
90
+ });
91
+ }
92
+
93
+ export { DUMMY_HASH };
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { OperationRegistry } from '@prisma-next/operations';
2
+ import type { Contract } from './contract-types';
2
3
  import type { DomainModel } from './domain-types';
3
- import type { ContractIR } from './ir';
4
4
 
5
5
  /**
6
6
  * Unique symbol used as the key for branding types.
@@ -383,20 +383,20 @@ export interface TargetFamilyHook {
383
383
 
384
384
  /**
385
385
  * Validates that all type IDs in the contract come from referenced extension packs.
386
- * @param ir - Contract IR to validate
386
+ * @param contract - Contract to validate
387
387
  * @param ctx - Validation context with operation registry and extension IDs
388
388
  */
389
- validateTypes(ir: ContractIR, ctx: ValidationContext): void;
389
+ validateTypes(contract: Contract, ctx: ValidationContext): void;
390
390
 
391
391
  /**
392
392
  * Validates family-specific contract structure.
393
- * @param ir - Contract IR to validate
393
+ * @param contract - Contract to validate
394
394
  */
395
- validateStructure(ir: ContractIR): void;
395
+ validateStructure(contract: Contract): void;
396
396
 
397
397
  /**
398
398
  * Generates contract.d.ts file content.
399
- * @param ir - Contract IR
399
+ * @param contract - Contract
400
400
  * @param codecTypeImports - Array of codec type import specs
401
401
  * @param operationTypeImports - Array of operation type import specs
402
402
  * @param hashes - Contract hash values (storageHash, executionHash, profileHash)
@@ -404,7 +404,7 @@ export interface TargetFamilyHook {
404
404
  * @returns Generated TypeScript type definitions as string
405
405
  */
406
406
  generateContractTypes(
407
- ir: ContractIR,
407
+ contract: Contract,
408
408
  codecTypeImports: ReadonlyArray<TypesImportSpec>,
409
409
  operationTypeImports: ReadonlyArray<TypesImportSpec>,
410
410
  hashes: {
@@ -1 +0,0 @@
1
- {"version":3,"file":"contract-types-C0y-Bn8M.d.mts","names":[],"sources":["../src/domain-types.ts","../src/types.ts","../src/contract-types.ts"],"sourcesContent":[],"mappings":";;;;KAAY,aAAA;;;;AAAA,KAKA,kBAAA,GALa;EAKb,SAAA,WAAA,EAAkB,SAAA,MAAA,EAAA;EAKlB,SAAA,YAAA,EAAA,SAAyB,MAAA,EAGtB;AAGf,CAAA;AAKY,KAXA,yBAAA,GAWmB;EAEnB,SAAA,EAAA,EAAA,MAAA;EAIA,SAAA,WAAA,EAAA,KAAoB,GAAA,KAAA,GAAA,KAAA;EAIpB,SAAA,EAAA,EAlBG,kBAkByB;AAExC,CAAA;AAAqD,KAjBzC,qBAAA,GAiByC;EAAmB,SAAA,EAAA,EAAA,MAAA;EACtC,SAAA,WAAA,EAAA,KAAA,GAAA,KAAA;CAAf;AACkB,KAdzB,gBAAA,GAAmB,yBAcM,GAdsB,qBActB;AAAf,KAZV,qBAAA,GAYU;EACF,SAAA,KAAA,EAAA,MAAA;CACO;AACU,KAXzB,oBAAA,GAWyB;EAAf,SAAA,KAAA,EAAA,MAAA;CAAM;AAQhB,KAfA,gBAAA,GAAmB,QAeL,CAfc,MAeD,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAE3B,UAfK,aAeW,CAAA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AAA;EAAuB,SAAA,SAAA,EAAA;IAAmB,SAAA,QAAA,EEbjD,aFaiD,CEbnC,wBFamC,CAAA;EACtC,CAAA;CAAf;;;;;;;;AAYnB;AAEA;AAEA;AAEA;AAEA;AAEA;AAEA;AAEA;AAIK,UEzBY,QFyBZ,CAAA,iBExBc,WFwBQ,GExBM,WFwBN,EAAA,gBEvBT,MFuBS,CAAA,MAAA,EEvBM,aFuBN,CAAA,GEvBuB,MFuBvB,CAAA,MAAA,EEvBsC,aFuBtC,CAAA,CAAA,CAAA;EAC4C,SAAA,MAAA,EAAA,MAAA;EAAf,SAAA,YAAA,EAAA,MAAA;EAArC,SAAA,KAAA,EEpBD,MFoBC,CAAA,MAAA,EAAA,MAAA,CAAA;EAAM,SAAA,MAAA,EEnBN,OFmBM;EAGb,SAAA,OAAA,EErBQ,QFqBa;EACb,SAAA,YAAA,EErBK,MFqBL,CAAA,MAAA,EErBoB,MFqBpB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EACe,SAAA,cAAA,EErBR,MFqBQ,CAAA,MAAA,EAAA,OAAA,CAAA;EAErB,SAAA,SAAA,CAAA,EEtBS,wBFsBT;EAAoB,SAAA,WAAA,CAAA,EErBT,eFqBS,CAAA,MAAA,CAAA;EAA0B,SAAA,IAAA,EEpB3C,MFoB2C,CAAA,MAAA,EAAA,OAAA,CAAA"}
@@ -1,86 +0,0 @@
1
- //#region src/ir.d.ts
2
- /**
3
- * ContractIR types and factories for building contract intermediate representation.
4
- * ContractIR is family-agnostic and used by authoring, emitter, and no-emit runtime.
5
- */
6
- /**
7
- * ContractIR represents the intermediate representation of a contract.
8
- * It is family-agnostic and contains generic storage, models, and relations.
9
- * Note: storageHash/executionHash and profileHash are computed by the emitter, not part of the IR.
10
- */
11
- interface ContractIR<TStorage extends Record<string, unknown> = Record<string, unknown>, TModels extends Record<string, unknown> = Record<string, unknown>, TRelations extends Record<string, unknown> = Record<string, unknown>, TExecution extends Record<string, unknown> = Record<string, unknown>> {
12
- readonly schemaVersion: string;
13
- readonly targetFamily: string;
14
- readonly target: string;
15
- readonly roots?: Record<string, string>;
16
- readonly models: TModels;
17
- readonly relations?: TRelations;
18
- readonly storage: TStorage;
19
- readonly execution?: TExecution;
20
- readonly extensionPacks: Record<string, unknown>;
21
- readonly capabilities: Record<string, Record<string, boolean>>;
22
- readonly meta: Record<string, unknown>;
23
- readonly sources: Record<string, unknown>;
24
- }
25
- /**
26
- * Creates the header portion of a ContractIR.
27
- * Contains schema version, target, target family, storage hash, and optional profile hash.
28
- */
29
- declare function irHeader(opts: {
30
- target: string;
31
- targetFamily: string;
32
- storageHash: string;
33
- executionHash?: string | undefined;
34
- profileHash?: string | undefined;
35
- }): {
36
- readonly schemaVersion: string;
37
- readonly target: string;
38
- readonly targetFamily: string;
39
- readonly storageHash: string;
40
- readonly executionHash?: string | undefined;
41
- readonly profileHash?: string | undefined;
42
- };
43
- /**
44
- * Creates the meta portion of a ContractIR.
45
- * Contains capabilities, extensionPacks, meta, and sources with empty object defaults.
46
- * If a field is explicitly `undefined`, it will be omitted (for testing validation).
47
- */
48
- declare function irMeta(opts?: {
49
- capabilities?: Record<string, Record<string, boolean>> | undefined;
50
- extensionPacks?: Record<string, unknown> | undefined;
51
- meta?: Record<string, unknown> | undefined;
52
- sources?: Record<string, unknown> | undefined;
53
- }): {
54
- readonly capabilities: Record<string, Record<string, boolean>>;
55
- readonly extensionPacks: Record<string, unknown>;
56
- readonly meta: Record<string, unknown>;
57
- readonly sources: Record<string, unknown>;
58
- };
59
- /**
60
- * Creates a complete ContractIR by combining header, meta, and family-specific sections.
61
- * This is a family-agnostic factory that accepts generic storage, models, and relations.
62
- */
63
- declare function contractIR<TStorage extends Record<string, unknown>, TModels extends Record<string, unknown>, TRelations extends Record<string, unknown>, TExecution extends Record<string, unknown>>(opts: {
64
- header: {
65
- readonly schemaVersion: string;
66
- readonly target: string;
67
- readonly targetFamily: string;
68
- readonly storageHash: string;
69
- readonly executionHash?: string | undefined;
70
- readonly profileHash?: string | undefined;
71
- };
72
- meta: {
73
- readonly capabilities: Record<string, Record<string, boolean>>;
74
- readonly extensionPacks: Record<string, unknown>;
75
- readonly meta: Record<string, unknown>;
76
- readonly sources: Record<string, unknown>;
77
- };
78
- roots?: Record<string, string>;
79
- storage: TStorage;
80
- models: TModels;
81
- relations?: TRelations;
82
- execution?: TExecution;
83
- }): ContractIR<TStorage, TModels, TRelations, TExecution>;
84
- //#endregion
85
- export { irMeta as i, contractIR as n, irHeader as r, ContractIR as t };
86
- //# sourceMappingURL=ir-BPkihpFL.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ir-BPkihpFL.d.mts","names":[],"sources":["../src/ir.ts"],"sourcesContent":[],"mappings":";;AAiBA;;;;;;;;AAI+C,UAJ9B,UAI8B,CAAA,iBAH5B,MAG4B,CAAA,MAAA,EAAA,OAAA,CAAA,GAHF,MAGE,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,gBAF7B,MAE6B,CAAA,MAAA,EAAA,OAAA,CAAA,GAFH,MAEG,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,mBAD1B,MAC0B,CAAA,MAAA,EAAA,OAAA,CAAA,GADA,MACA,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,mBAA1B,MAA0B,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA;EAK5B,SAAA,aAAA,EAAA,MAAA;EACA,SAAA,YAAA,EAAA,MAAA;EACI,SAAA,MAAA,EAAA,MAAA;EACH,SAAA,KAAA,CAAA,EAHD,MAGC,CAAA,MAAA,EAAA,MAAA,CAAA;EACG,SAAA,MAAA,EAHJ,OAGI;EACI,SAAA,SAAA,CAAA,EAHJ,UAGI;EACa,SAAA,OAAA,EAHpB,QAGoB;EAAf,SAAA,SAAA,CAAA,EAFF,UAEE;EACR,SAAA,cAAA,EAFU,MAEV,CAAA,MAAA,EAAA,OAAA,CAAA;EACG,SAAA,YA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AxCG,MAwCH,CAAA,MAAA,EAAA,OAAA,CAAA;oBAvCM;;;;;;iBAcJ,4BACG,yCACD,4CACG,4CACA;;;;;;;;;;2BAWM,eAAe;6BACb;mBACV;sBACG;;UAEZ;WACC;UACD;cACI;cACA;IACV,WAAW,UAAU,SAAS,YAAY"}
package/dist/ir.d.mts DELETED
@@ -1,2 +0,0 @@
1
- import { i as irMeta, n as contractIR, r as irHeader, t as ContractIR } from "./ir-BPkihpFL.mjs";
2
- export { ContractIR, contractIR, irHeader, irMeta };
package/dist/ir.mjs DELETED
@@ -1,52 +0,0 @@
1
- //#region src/ir.ts
2
- function ifDefined(key, value) {
3
- return value !== void 0 ? { [key]: value } : {};
4
- }
5
- /**
6
- * Creates the header portion of a ContractIR.
7
- * Contains schema version, target, target family, storage hash, and optional profile hash.
8
- */
9
- function irHeader(opts) {
10
- return {
11
- schemaVersion: "1",
12
- target: opts.target,
13
- targetFamily: opts.targetFamily,
14
- storageHash: opts.storageHash,
15
- ...ifDefined("executionHash", opts.executionHash),
16
- ...ifDefined("profileHash", opts.profileHash)
17
- };
18
- }
19
- /**
20
- * Creates the meta portion of a ContractIR.
21
- * Contains capabilities, extensionPacks, meta, and sources with empty object defaults.
22
- * If a field is explicitly `undefined`, it will be omitted (for testing validation).
23
- */
24
- function irMeta(opts) {
25
- return {
26
- capabilities: opts?.capabilities ?? {},
27
- extensionPacks: opts?.extensionPacks ?? {},
28
- meta: opts?.meta ?? {},
29
- sources: opts?.sources ?? {}
30
- };
31
- }
32
- /**
33
- * Creates a complete ContractIR by combining header, meta, and family-specific sections.
34
- * This is a family-agnostic factory that accepts generic storage, models, and relations.
35
- */
36
- function contractIR(opts) {
37
- return {
38
- schemaVersion: opts.header.schemaVersion,
39
- target: opts.header.target,
40
- targetFamily: opts.header.targetFamily,
41
- ...opts.meta,
42
- ...ifDefined("roots", opts.roots),
43
- storage: opts.storage,
44
- models: opts.models,
45
- ...ifDefined("relations", opts.relations),
46
- ...ifDefined("execution", opts.execution)
47
- };
48
- }
49
-
50
- //#endregion
51
- export { contractIR, irHeader, irMeta };
52
- //# sourceMappingURL=ir.mjs.map
package/dist/ir.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ir.mjs","names":[],"sources":["../src/ir.ts"],"sourcesContent":["function ifDefined<K extends string, V>(\n key: K,\n value: V | undefined,\n): Record<never, never> | { [P in K]: V } {\n return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};\n}\n\n/**\n * ContractIR types and factories for building contract intermediate representation.\n * ContractIR is family-agnostic and used by authoring, emitter, and no-emit runtime.\n */\n\n/**\n * ContractIR represents the intermediate representation of a contract.\n * It is family-agnostic and contains generic storage, models, and relations.\n * Note: storageHash/executionHash and profileHash are computed by the emitter, not part of the IR.\n */\nexport interface ContractIR<\n TStorage extends Record<string, unknown> = Record<string, unknown>,\n TModels extends Record<string, unknown> = Record<string, unknown>,\n TRelations extends Record<string, unknown> = Record<string, unknown>,\n TExecution extends Record<string, unknown> = Record<string, unknown>,\n> {\n readonly schemaVersion: string;\n readonly targetFamily: string;\n readonly target: string;\n readonly roots?: Record<string, string>;\n readonly models: TModels;\n readonly relations?: TRelations;\n readonly storage: TStorage;\n readonly execution?: TExecution;\n readonly extensionPacks: Record<string, unknown>;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n}\n\n/**\n * Creates the header portion of a ContractIR.\n * Contains schema version, target, target family, storage hash, and optional profile hash.\n */\nexport function irHeader(opts: {\n target: string;\n targetFamily: string;\n storageHash: string;\n executionHash?: string | undefined;\n profileHash?: string | undefined;\n}): {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly storageHash: string;\n readonly executionHash?: string | undefined;\n readonly profileHash?: string | undefined;\n} {\n return {\n schemaVersion: '1',\n target: opts.target,\n targetFamily: opts.targetFamily,\n storageHash: opts.storageHash,\n ...ifDefined('executionHash', opts.executionHash),\n ...ifDefined('profileHash', opts.profileHash),\n };\n}\n\n/**\n * Creates the meta portion of a ContractIR.\n * Contains capabilities, extensionPacks, meta, and sources with empty object defaults.\n * If a field is explicitly `undefined`, it will be omitted (for testing validation).\n */\nexport function irMeta(opts?: {\n capabilities?: Record<string, Record<string, boolean>> | undefined;\n extensionPacks?: Record<string, unknown> | undefined;\n meta?: Record<string, unknown> | undefined;\n sources?: Record<string, unknown> | undefined;\n}): {\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n} {\n return {\n capabilities: opts?.capabilities ?? {},\n extensionPacks: opts?.extensionPacks ?? {},\n meta: opts?.meta ?? {},\n sources: opts?.sources ?? {},\n };\n}\n\n/**\n * Creates a complete ContractIR by combining header, meta, and family-specific sections.\n * This is a family-agnostic factory that accepts generic storage, models, and relations.\n */\nexport function contractIR<\n TStorage extends Record<string, unknown>,\n TModels extends Record<string, unknown>,\n TRelations extends Record<string, unknown>,\n TExecution extends Record<string, unknown>,\n>(opts: {\n header: {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly storageHash: string;\n readonly executionHash?: string | undefined;\n readonly profileHash?: string | undefined;\n };\n meta: {\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, unknown>;\n };\n roots?: Record<string, string>;\n storage: TStorage;\n models: TModels;\n relations?: TRelations;\n execution?: TExecution;\n}): ContractIR<TStorage, TModels, TRelations, TExecution> {\n return {\n schemaVersion: opts.header.schemaVersion,\n target: opts.header.target,\n targetFamily: opts.header.targetFamily,\n ...opts.meta,\n ...ifDefined('roots', opts.roots),\n storage: opts.storage,\n models: opts.models,\n ...ifDefined('relations', opts.relations),\n ...ifDefined('execution', opts.execution),\n };\n}\n"],"mappings":";AAAA,SAAS,UACP,KACA,OACwC;AACxC,QAAO,UAAU,SAAa,GAAG,MAAM,OAAO,GAAuB,EAAE;;;;;;AAqCzE,SAAgB,SAAS,MAavB;AACA,QAAO;EACL,eAAe;EACf,QAAQ,KAAK;EACb,cAAc,KAAK;EACnB,aAAa,KAAK;EAClB,GAAG,UAAU,iBAAiB,KAAK,cAAc;EACjD,GAAG,UAAU,eAAe,KAAK,YAAY;EAC9C;;;;;;;AAQH,SAAgB,OAAO,MAUrB;AACA,QAAO;EACL,cAAc,MAAM,gBAAgB,EAAE;EACtC,gBAAgB,MAAM,kBAAkB,EAAE;EAC1C,MAAM,MAAM,QAAQ,EAAE;EACtB,SAAS,MAAM,WAAW,EAAE;EAC7B;;;;;;AAOH,SAAgB,WAKd,MAoBwD;AACxD,QAAO;EACL,eAAe,KAAK,OAAO;EAC3B,QAAQ,KAAK,OAAO;EACpB,cAAc,KAAK,OAAO;EAC1B,GAAG,KAAK;EACR,GAAG,UAAU,SAAS,KAAK,MAAM;EACjC,SAAS,KAAK;EACd,QAAQ,KAAK;EACb,GAAG,UAAU,aAAa,KAAK,UAAU;EACzC,GAAG,UAAU,aAAa,KAAK,UAAU;EAC1C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { OperationRegistry } from '@prisma-next/operations';\nimport type { DomainModel } from './domain-types';\nimport type { ContractIR } from './ir';\n\n/**\n * Unique symbol used as the key for branding types.\n */\nexport const $: unique symbol = Symbol('__prisma_next_brand__');\n\n/**\n * A helper type to brand a given type with a unique identifier.\n *\n * @template TKey Text used as the brand key.\n * @template TValue Optional value associated with the brand key. Defaults to `true`.\n */\nexport type Brand<TKey extends string | number | symbol, TValue = true> = {\n [$]: {\n [K in TKey]: TValue;\n };\n};\n\n/**\n * Context passed to type renderers during contract.d.ts generation.\n */\nexport interface RenderTypeContext {\n /** The name of the CodecTypes type alias (typically 'CodecTypes') */\n readonly codecTypesName: string;\n}\n\n/**\n * Base type for storage contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type StorageHash = StorageHashBase<'sha256:abc123...'>`\n */\nexport type StorageHashBase<THash extends string> = THash & Brand<'StorageHash'>;\n\n/**\n * Base type for execution contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ExecutionHash = ExecutionHashBase<'sha256:def456...'>`\n */\nexport type ExecutionHashBase<THash extends string> = THash & Brand<'ExecutionHash'>;\n\nexport function coreHash<const T extends string>(value: T): StorageHashBase<T> {\n return value as StorageHashBase<T>;\n}\n\n/**\n * Base type for profile contract hashes.\n * Emitted contract.d.ts files use this with the hash value as a type parameter:\n * `type ProfileHash = ProfileHashBase<'sha256:def456...'>`\n */\nexport type ProfileHashBase<THash extends string> = THash & Brand<'ProfileHash'>;\n\nexport function profileHash<const T extends string>(value: T): ProfileHashBase<T> {\n return value as ProfileHashBase<T>;\n}\n\n/**\n * Base type for family-specific storage blocks.\n * Family storage types (SqlStorage, MongoStorage, etc.) extend this to carry the\n * storage hash alongside family-specific data (tables, collections, etc.).\n */\nexport interface StorageBase<THash extends string = string> {\n readonly storageHash: StorageHashBase<THash>;\n}\n\nexport interface ContractBase<\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n> {\n readonly schemaVersion: string;\n readonly target: string;\n readonly targetFamily: string;\n readonly storageHash: TStorageHash;\n readonly executionHash?: TExecutionHash | undefined;\n readonly profileHash?: TProfileHash | undefined;\n readonly capabilities: Record<string, Record<string, boolean>>;\n readonly extensionPacks: Record<string, unknown>;\n readonly meta: Record<string, unknown>;\n readonly sources: Record<string, Source>;\n readonly execution?: ExecutionSection;\n readonly roots: Record<string, string>;\n readonly models: Record<string, DomainModel>;\n}\n\nexport interface FieldType {\n readonly type: string;\n readonly nullable: boolean;\n readonly items?: FieldType;\n readonly properties?: Record<string, FieldType>;\n}\n\nexport type GeneratedValueSpec = {\n readonly id: string;\n readonly params?: Record<string, unknown>;\n};\n\nexport type JsonPrimitive = string | number | boolean | null;\n\nexport type JsonValue =\n | JsonPrimitive\n | { readonly [key: string]: JsonValue }\n | readonly JsonValue[];\n\nexport type TaggedBigInt = { readonly $type: 'bigint'; readonly value: string };\n\nexport function isTaggedBigInt(value: unknown): value is TaggedBigInt {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { $type?: unknown }).$type === 'bigint' &&\n typeof (value as { value?: unknown }).value === 'string'\n );\n}\n\nexport function bigintJsonReplacer(_key: string, value: unknown): unknown {\n if (typeof value === 'bigint') {\n return { $type: 'bigint', value: value.toString() } satisfies TaggedBigInt;\n }\n return value;\n}\n\nexport type TaggedRaw = { readonly $type: 'raw'; readonly value: JsonValue };\n\nexport function isTaggedRaw(value: unknown): value is TaggedRaw {\n return (\n typeof value === 'object' &&\n value !== null &&\n (value as { $type?: unknown }).$type === 'raw' &&\n 'value' in (value as object)\n );\n}\n\nexport type TaggedLiteralValue = TaggedBigInt | TaggedRaw;\n\nexport type ColumnDefaultLiteralValue = JsonValue | TaggedLiteralValue;\n\nexport type ColumnDefaultLiteralInputValue = ColumnDefaultLiteralValue | bigint | Date;\n\nexport type ColumnDefault =\n | {\n readonly kind: 'literal';\n readonly value: ColumnDefaultLiteralInputValue;\n }\n | { readonly kind: 'function'; readonly expression: string };\n\nexport type ExecutionMutationDefaultValue = {\n readonly kind: 'generator';\n readonly id: GeneratedValueSpec['id'];\n readonly params?: Record<string, unknown>;\n};\n\nexport type ExecutionMutationDefault = {\n readonly ref: { readonly table: string; readonly column: string };\n readonly onCreate?: ExecutionMutationDefaultValue;\n readonly onUpdate?: ExecutionMutationDefaultValue;\n};\n\nexport type ExecutionSection = {\n readonly mutations: {\n readonly defaults: ReadonlyArray<ExecutionMutationDefault>;\n };\n};\n\nexport interface Source {\n readonly readOnly: boolean;\n readonly projection: Record<string, FieldType>;\n readonly origin?: Record<string, unknown>;\n readonly capabilities?: Record<string, boolean>;\n}\n\n// Document family types\nexport interface DocIndex {\n readonly name: string;\n readonly keys: Record<string, 'asc' | 'desc'>;\n readonly unique?: boolean;\n readonly where?: Expr;\n}\n\nexport type Expr =\n | { readonly kind: 'eq'; readonly path: ReadonlyArray<string>; readonly value: unknown }\n | { readonly kind: 'exists'; readonly path: ReadonlyArray<string> };\n\nexport interface DocCollection {\n readonly name: string;\n readonly id?: {\n readonly strategy: 'auto' | 'client' | 'uuid' | 'objectId';\n };\n readonly fields: Record<string, FieldType>;\n readonly indexes?: ReadonlyArray<DocIndex>;\n readonly readOnly?: boolean;\n}\n\nexport interface DocumentStorage {\n readonly document: {\n readonly collections: Record<string, DocCollection>;\n };\n}\n\nexport interface DocumentContract<\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n> extends ContractBase<TStorageHash, TExecutionHash, TProfileHash> {\n // Accept string to work with JSON imports; runtime validation ensures 'document'\n readonly targetFamily: string;\n readonly storage: DocumentStorage;\n}\n\n// Plan types - target-family agnostic execution types\nexport interface ParamDescriptor {\n readonly index?: number;\n readonly name?: string;\n readonly codecId?: string;\n readonly nativeType?: string;\n readonly nullable?: boolean;\n readonly source: 'dsl' | 'raw' | 'lane';\n readonly refs?: { table: string; column: string };\n}\n\nexport interface PlanRefs {\n readonly tables?: readonly string[];\n readonly columns?: ReadonlyArray<{ table: string; column: string }>;\n readonly indexes?: ReadonlyArray<{\n readonly table: string;\n readonly columns: ReadonlyArray<string>;\n readonly name?: string;\n }>;\n}\n\nexport interface PlanMeta {\n readonly target: string;\n readonly targetFamily?: string;\n readonly storageHash: string;\n readonly profileHash?: string;\n readonly lane: string;\n readonly annotations?: {\n codecs?: Record<string, string>; // alias/param → codec id ('ns/name@v')\n [key: string]: unknown;\n };\n readonly paramDescriptors: ReadonlyArray<ParamDescriptor>;\n readonly refs?: PlanRefs;\n readonly projection?: Record<string, string> | ReadonlyArray<string>;\n /**\n * Optional mapping of projection alias → column type ID (fully qualified ns/name@version).\n * Used for codec resolution when AST+refs don't provide enough type info.\n */\n readonly projectionTypes?: Record<string, string>;\n}\n\n/**\n * Canonical execution plan shape used by runtimes.\n *\n * - Row is the inferred result row type (TypeScript-only).\n * - Ast is the optional, family-specific AST type (e.g. SQL QueryAst).\n *\n * The payload executed by the runtime is represented by the sql + params pair\n * for now; future families can specialize this via Ast or additional metadata.\n */\nexport interface ExecutionPlan<Row = unknown, Ast = unknown> {\n readonly sql: string;\n readonly params: readonly unknown[];\n readonly ast?: Ast;\n readonly meta: PlanMeta;\n /**\n * Phantom property to carry the Row generic for type-level utilities.\n * Not set at runtime; used only for ResultType extraction.\n */\n readonly _row?: Row;\n}\n\n/**\n * Utility type to extract the Row type from an ExecutionPlan.\n * Example: `type Row = ResultType<typeof plan>`\n *\n * Works with both ExecutionPlan and SqlQueryPlan (SQL query plans before lowering).\n * SqlQueryPlan includes a phantom `_Row` property to preserve the generic parameter\n * for type extraction.\n */\nexport type ResultType<P> =\n P extends ExecutionPlan<infer R, unknown> ? R : P extends { readonly _Row?: infer R } ? R : never;\n\n/**\n * Type guard to check if a contract is a Document contract\n */\nexport function isDocumentContract(contract: unknown): contract is DocumentContract {\n return (\n typeof contract === 'object' &&\n contract !== null &&\n 'targetFamily' in contract &&\n contract.targetFamily === 'document'\n );\n}\n\n/**\n * Contract marker record stored in the database.\n * Represents the current contract identity for a database.\n */\nexport interface ContractMarkerRecord {\n readonly storageHash: string;\n readonly profileHash: string;\n readonly contractJson: unknown | null;\n readonly canonicalVersion: number | null;\n readonly updatedAt: Date;\n readonly appTag: string | null;\n readonly meta: Record<string, unknown>;\n}\n\n// Emitter types - moved from @prisma-next/emitter to shared location\n/**\n * Specifies how to import TypeScript types from a package.\n * Used in extension pack manifests to declare codec and operation type imports.\n */\nexport interface TypesImportSpec {\n readonly package: string;\n readonly named: string;\n readonly alias: string;\n}\n\n/**\n * Validation context passed to TargetFamilyHook.validateTypes().\n * Contains pre-assembled operation registry, type imports, and extension IDs.\n */\nexport interface ValidationContext {\n readonly operationRegistry?: OperationRegistry;\n readonly codecTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly operationTypeImports?: ReadonlyArray<TypesImportSpec>;\n readonly extensionIds?: ReadonlyArray<string>;\n /**\n * Parameterized codec descriptors collected from adapters and extensions.\n * Map of codecId → descriptor for quick lookup during type generation.\n */\n readonly parameterizedCodecs?: Map<string, ParameterizedCodecDescriptor>;\n}\n\n/**\n * Context for rendering parameterized types during contract.d.ts generation.\n * Passed to type renderers so they can reference CodecTypes by name.\n */\nexport interface TypeRenderContext {\n readonly codecTypesName: string;\n}\n\n/**\n * A normalized type renderer for parameterized codecs.\n * This is the interface expected by TargetFamilyHook.generateContractTypes.\n */\nexport interface TypeRenderEntry {\n readonly codecId: string;\n readonly render: (params: Record<string, unknown>, ctx: TypeRenderContext) => string;\n}\n\n/**\n * Additional options for generateContractTypes.\n */\nexport interface GenerateContractTypesOptions {\n /**\n * Normalized parameterized type renderers, keyed by codecId.\n * When a column has typeParams and a renderer exists for its codecId,\n * the renderer is called to produce the TypeScript type expression.\n */\n readonly parameterizedRenderers?: Map<string, TypeRenderEntry>;\n /**\n * Type imports for parameterized codecs.\n * These are merged with codec and operation type imports in contract.d.ts.\n */\n readonly parameterizedTypeImports?: ReadonlyArray<TypesImportSpec>;\n /**\n * Query operation type imports for the query builder.\n * Flat operation signatures keyed by operation name, emitted as standalone QueryOperationTypes.\n */\n readonly queryOperationTypeImports?: ReadonlyArray<TypesImportSpec>;\n}\n\n/**\n * SPI interface for target family hooks that extend emission behavior.\n * Implemented by family-specific emitter hooks (e.g., SQL family).\n */\nexport interface TargetFamilyHook {\n readonly id: string;\n\n /**\n * Validates that all type IDs in the contract come from referenced extension packs.\n * @param ir - Contract IR to validate\n * @param ctx - Validation context with operation registry and extension IDs\n */\n validateTypes(ir: ContractIR, ctx: ValidationContext): void;\n\n /**\n * Validates family-specific contract structure.\n * @param ir - Contract IR to validate\n */\n validateStructure(ir: ContractIR): void;\n\n /**\n * Generates contract.d.ts file content.\n * @param ir - Contract IR\n * @param codecTypeImports - Array of codec type import specs\n * @param operationTypeImports - Array of operation type import specs\n * @param hashes - Contract hash values (storageHash, executionHash, profileHash)\n * @param options - Additional options including parameterized type renderers\n * @returns Generated TypeScript type definitions as string\n */\n generateContractTypes(\n ir: ContractIR,\n codecTypeImports: ReadonlyArray<TypesImportSpec>,\n operationTypeImports: ReadonlyArray<TypesImportSpec>,\n hashes: {\n readonly storageHash: string;\n readonly executionHash?: string;\n readonly profileHash: string;\n },\n options?: GenerateContractTypesOptions,\n ): string;\n}\n\n// ============================================================================\n// Parameterized Codec Descriptor Types\n// ============================================================================\n//\n// Types for codecs that support type parameters (e.g., Vector<1536>, Decimal<2>).\n// These enable precise TypeScript types for parameterized columns without\n// coupling the SQL family emitter to specific adapter codec IDs.\n//\n// ============================================================================\n\n/**\n * Declarative type renderer that produces a TypeScript type expression.\n *\n * Renderers can be:\n * - A template string with `{{paramName}}` placeholders (e.g., `Vector<{{length}}>`)\n * - A function that receives typeParams and context and returns a type expression\n *\n * **Prefer template strings** for most cases:\n * - Templates are JSON-serializable (safe for pack-ref metadata)\n * - Templates can be statically analyzed by tooling\n *\n * Function renderers are allowed but have tradeoffs:\n * - Require runtime execution during emission (the emitter runs code)\n * - Not JSON-serializable (can't be stored in contract.json)\n * - The emitted artifacts (contract.json, contract.d.ts) still contain no\n * executable code - this constraint applies to outputs, not the emission process\n */\nexport type TypeRenderer =\n | string\n | ((params: Record<string, unknown>, ctx: RenderTypeContext) => string);\n\n/**\n * Descriptor for a codec that supports type parameters.\n *\n * Parameterized codecs allow columns to carry additional metadata (typeParams)\n * that affects the generated TypeScript types. For example:\n * - A vector codec can use `{ length: 1536 }` to generate `Vector<1536>`\n * - A decimal codec can use `{ precision: 10, scale: 2 }` to generate `Decimal<10, 2>`\n *\n * The SQL family emitter uses these descriptors to generate precise types\n * without hard-coding knowledge of specific codec IDs.\n *\n * @example\n * ```typescript\n * const vectorCodecDescriptor: ParameterizedCodecDescriptor = {\n * codecId: 'pg/vector@1',\n * outputTypeRenderer: 'Vector<{{length}}>',\n * // Optional: paramsSchema for runtime validation\n * };\n * ```\n */\nexport interface ParameterizedCodecDescriptor {\n /** The codec ID this descriptor applies to (e.g., 'pg/vector@1') */\n readonly codecId: string;\n\n /**\n * Renderer for the output (read) type.\n * Can be a template string or function.\n *\n * This is the primary renderer used by SQL emission to generate\n * model field types in contract.d.ts.\n */\n readonly outputTypeRenderer: TypeRenderer;\n\n /**\n * Optional renderer for the input (write) type.\n * If not provided, outputTypeRenderer is used for both.\n *\n * **Reserved for future use**: Currently, SQL emission only uses\n * outputTypeRenderer. This field is defined for future support of\n * asymmetric codecs where input and output types differ (e.g., a\n * codec that accepts `string | number` but always returns `number`).\n */\n readonly inputTypeRenderer?: TypeRenderer;\n\n /**\n * Optional import spec for types used by this codec's renderers.\n * The emitter will add this import to contract.d.ts.\n */\n readonly typesImport?: TypesImportSpec;\n}\n"],"mappings":";AA2CA,SAAgB,SAAiC,OAA8B;AAC7E,QAAO;;AAUT,SAAgB,YAAoC,OAA8B;AAChF,QAAO;;AAqDT,SAAgB,eAAe,OAAuC;AACpE,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA8B,UAAU,YACzC,OAAQ,MAA8B,UAAU;;AAIpD,SAAgB,mBAAmB,MAAc,OAAyB;AACxE,KAAI,OAAO,UAAU,SACnB,QAAO;EAAE,OAAO;EAAU,OAAO,MAAM,UAAU;EAAE;AAErD,QAAO;;AAKT,SAAgB,YAAY,OAAoC;AAC9D,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA8B,UAAU,SACzC,WAAY;;;;;AA4JhB,SAAgB,mBAAmB,UAAiD;AAClF,QACE,OAAO,aAAa,YACpB,aAAa,QACb,kBAAkB,YAClB,SAAS,iBAAiB"}
package/src/exports/ir.ts DELETED
@@ -1 +0,0 @@
1
- export * from '../ir';
package/src/ir.ts DELETED
@@ -1,131 +0,0 @@
1
- function ifDefined<K extends string, V>(
2
- key: K,
3
- value: V | undefined,
4
- ): Record<never, never> | { [P in K]: V } {
5
- return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};
6
- }
7
-
8
- /**
9
- * ContractIR types and factories for building contract intermediate representation.
10
- * ContractIR is family-agnostic and used by authoring, emitter, and no-emit runtime.
11
- */
12
-
13
- /**
14
- * ContractIR represents the intermediate representation of a contract.
15
- * It is family-agnostic and contains generic storage, models, and relations.
16
- * Note: storageHash/executionHash and profileHash are computed by the emitter, not part of the IR.
17
- */
18
- export interface ContractIR<
19
- TStorage extends Record<string, unknown> = Record<string, unknown>,
20
- TModels extends Record<string, unknown> = Record<string, unknown>,
21
- TRelations extends Record<string, unknown> = Record<string, unknown>,
22
- TExecution extends Record<string, unknown> = Record<string, unknown>,
23
- > {
24
- readonly schemaVersion: string;
25
- readonly targetFamily: string;
26
- readonly target: string;
27
- readonly roots?: Record<string, string>;
28
- readonly models: TModels;
29
- readonly relations?: TRelations;
30
- readonly storage: TStorage;
31
- readonly execution?: TExecution;
32
- readonly extensionPacks: Record<string, unknown>;
33
- readonly capabilities: Record<string, Record<string, boolean>>;
34
- readonly meta: Record<string, unknown>;
35
- readonly sources: Record<string, unknown>;
36
- }
37
-
38
- /**
39
- * Creates the header portion of a ContractIR.
40
- * Contains schema version, target, target family, storage hash, and optional profile hash.
41
- */
42
- export function irHeader(opts: {
43
- target: string;
44
- targetFamily: string;
45
- storageHash: string;
46
- executionHash?: string | undefined;
47
- profileHash?: string | undefined;
48
- }): {
49
- readonly schemaVersion: string;
50
- readonly target: string;
51
- readonly targetFamily: string;
52
- readonly storageHash: string;
53
- readonly executionHash?: string | undefined;
54
- readonly profileHash?: string | undefined;
55
- } {
56
- return {
57
- schemaVersion: '1',
58
- target: opts.target,
59
- targetFamily: opts.targetFamily,
60
- storageHash: opts.storageHash,
61
- ...ifDefined('executionHash', opts.executionHash),
62
- ...ifDefined('profileHash', opts.profileHash),
63
- };
64
- }
65
-
66
- /**
67
- * Creates the meta portion of a ContractIR.
68
- * Contains capabilities, extensionPacks, meta, and sources with empty object defaults.
69
- * If a field is explicitly `undefined`, it will be omitted (for testing validation).
70
- */
71
- export function irMeta(opts?: {
72
- capabilities?: Record<string, Record<string, boolean>> | undefined;
73
- extensionPacks?: Record<string, unknown> | undefined;
74
- meta?: Record<string, unknown> | undefined;
75
- sources?: Record<string, unknown> | undefined;
76
- }): {
77
- readonly capabilities: Record<string, Record<string, boolean>>;
78
- readonly extensionPacks: Record<string, unknown>;
79
- readonly meta: Record<string, unknown>;
80
- readonly sources: Record<string, unknown>;
81
- } {
82
- return {
83
- capabilities: opts?.capabilities ?? {},
84
- extensionPacks: opts?.extensionPacks ?? {},
85
- meta: opts?.meta ?? {},
86
- sources: opts?.sources ?? {},
87
- };
88
- }
89
-
90
- /**
91
- * Creates a complete ContractIR by combining header, meta, and family-specific sections.
92
- * This is a family-agnostic factory that accepts generic storage, models, and relations.
93
- */
94
- export function contractIR<
95
- TStorage extends Record<string, unknown>,
96
- TModels extends Record<string, unknown>,
97
- TRelations extends Record<string, unknown>,
98
- TExecution extends Record<string, unknown>,
99
- >(opts: {
100
- header: {
101
- readonly schemaVersion: string;
102
- readonly target: string;
103
- readonly targetFamily: string;
104
- readonly storageHash: string;
105
- readonly executionHash?: string | undefined;
106
- readonly profileHash?: string | undefined;
107
- };
108
- meta: {
109
- readonly capabilities: Record<string, Record<string, boolean>>;
110
- readonly extensionPacks: Record<string, unknown>;
111
- readonly meta: Record<string, unknown>;
112
- readonly sources: Record<string, unknown>;
113
- };
114
- roots?: Record<string, string>;
115
- storage: TStorage;
116
- models: TModels;
117
- relations?: TRelations;
118
- execution?: TExecution;
119
- }): ContractIR<TStorage, TModels, TRelations, TExecution> {
120
- return {
121
- schemaVersion: opts.header.schemaVersion,
122
- target: opts.header.target,
123
- targetFamily: opts.header.targetFamily,
124
- ...opts.meta,
125
- ...ifDefined('roots', opts.roots),
126
- storage: opts.storage,
127
- models: opts.models,
128
- ...ifDefined('relations', opts.relations),
129
- ...ifDefined('execution', opts.execution),
130
- };
131
- }