@prisma-next/emitter 0.3.0-dev.9 → 0.3.0-dev.91
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/LICENSE +201 -0
- package/README.md +7 -5
- package/dist/exports/index.d.mts +3 -0
- package/dist/exports/index.mjs +3 -0
- package/dist/test/{utils.d.ts → utils.d.mts} +10 -5
- package/dist/test/utils.d.mts.map +1 -0
- package/dist/test/utils.mjs +59 -0
- package/dist/test/utils.mjs.map +1 -0
- package/package.json +22 -16
- package/test/canonicalization.test.ts +127 -5
- package/test/emitter.integration.test.ts +65 -61
- package/test/emitter.roundtrip.test.ts +4 -4
- package/test/emitter.test.ts +116 -15
- package/test/factories.test.ts +10 -10
- package/test/hashing.test.ts +5 -5
- package/test/utils.ts +9 -9
- package/dist/exports/index.js +0 -6
- package/dist/exports/index.js.map +0 -1
- package/dist/src/exports/index.d.ts +0 -4
- package/dist/src/exports/index.d.ts.map +0 -1
- package/dist/src/target-family.d.ts +0 -2
- package/dist/src/target-family.d.ts.map +0 -1
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js +0 -78
- package/dist/test/utils.js.map +0 -1
|
@@ -128,7 +128,7 @@ describe('emitter integration', () => {
|
|
|
128
128
|
|
|
129
129
|
const result = await emit(ir, options, mockSqlHook);
|
|
130
130
|
|
|
131
|
-
expect(result.
|
|
131
|
+
expect(result.storageHash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
132
132
|
expect(result.contractDts).toContain('export type Contract');
|
|
133
133
|
expect(result.contractDts).toContain('CodecTypes');
|
|
134
134
|
expect(result.contractDts).toContain('LaneCodecTypes');
|
|
@@ -138,7 +138,7 @@ describe('emitter integration', () => {
|
|
|
138
138
|
schemaVersion: '1',
|
|
139
139
|
targetFamily: 'sql',
|
|
140
140
|
target: 'postgres',
|
|
141
|
-
|
|
141
|
+
storageHash: result.storageHash,
|
|
142
142
|
storage: {
|
|
143
143
|
tables: {
|
|
144
144
|
user: expect.anything(),
|
|
@@ -197,78 +197,82 @@ describe('emitter integration', () => {
|
|
|
197
197
|
const result1 = await emit(ir, options, mockSqlHook);
|
|
198
198
|
const result2 = await emit(ir, options, mockSqlHook);
|
|
199
199
|
|
|
200
|
-
expect(result1.
|
|
200
|
+
expect(result1.storageHash).toBe(result2.storageHash);
|
|
201
201
|
expect(result1.contractDts).toBe(result2.contractDts);
|
|
202
202
|
expect(result1.contractJson).toBe(result2.contractJson);
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
-
it(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
it(
|
|
206
|
+
'round-trip: IR → JSON → parse JSON → compare',
|
|
207
|
+
async () => {
|
|
208
|
+
const ir = createContractIR({
|
|
209
|
+
models: {
|
|
210
|
+
User: {
|
|
211
|
+
storage: { table: 'user' },
|
|
212
|
+
fields: {
|
|
213
|
+
id: { column: 'id' },
|
|
214
|
+
email: { column: 'email' },
|
|
215
|
+
},
|
|
216
|
+
relations: {},
|
|
213
217
|
},
|
|
214
|
-
relations: {},
|
|
215
218
|
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
219
|
+
storage: {
|
|
220
|
+
tables: {
|
|
221
|
+
user: {
|
|
222
|
+
columns: {
|
|
223
|
+
id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
|
|
224
|
+
email: { codecId: 'pg/text@1', nativeType: 'text', nullable: false },
|
|
225
|
+
},
|
|
226
|
+
primaryKey: { columns: ['id'] },
|
|
227
|
+
uniques: [],
|
|
228
|
+
indexes: [],
|
|
229
|
+
foreignKeys: [],
|
|
223
230
|
},
|
|
224
|
-
primaryKey: { columns: ['id'] },
|
|
225
|
-
uniques: [],
|
|
226
|
-
indexes: [],
|
|
227
|
-
foreignKeys: [],
|
|
228
231
|
},
|
|
229
232
|
},
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
233
|
+
extensionPacks: {
|
|
234
|
+
postgres: {
|
|
235
|
+
version: '0.0.1',
|
|
236
|
+
},
|
|
237
|
+
pg: {},
|
|
234
238
|
},
|
|
235
|
-
|
|
236
|
-
},
|
|
237
|
-
});
|
|
239
|
+
});
|
|
238
240
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
241
|
+
// Create minimal test data (emitter tests don't load packs)
|
|
242
|
+
const operationRegistry = createOperationRegistry();
|
|
243
|
+
const codecTypeImports: TypesImportSpec[] = [];
|
|
244
|
+
const operationTypeImports: TypesImportSpec[] = [];
|
|
245
|
+
const extensionIds = ['postgres', 'pg'];
|
|
246
|
+
const options: EmitOptions = {
|
|
247
|
+
outputDir: '',
|
|
248
|
+
operationRegistry,
|
|
249
|
+
codecTypeImports,
|
|
250
|
+
operationTypeImports,
|
|
251
|
+
extensionIds,
|
|
252
|
+
};
|
|
251
253
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
const result1 = await emit(ir, options, mockSqlHook);
|
|
255
|
+
const contractJson1 = JSON.parse(result1.contractJson) as Record<string, unknown>;
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
257
|
+
const ir2 = createContractIR({
|
|
258
|
+
schemaVersion: contractJson1['schemaVersion'] as string,
|
|
259
|
+
targetFamily: contractJson1['targetFamily'] as string,
|
|
260
|
+
target: contractJson1['target'] as string,
|
|
261
|
+
models: contractJson1['models'] as Record<string, unknown>,
|
|
262
|
+
relations: (contractJson1['relations'] as Record<string, unknown>) || {},
|
|
263
|
+
storage: contractJson1['storage'] as Record<string, unknown>,
|
|
264
|
+
extensionPacks: contractJson1['extensionPacks'] as Record<string, unknown>,
|
|
265
|
+
capabilities:
|
|
266
|
+
(contractJson1['capabilities'] as Record<string, Record<string, boolean>>) || {},
|
|
267
|
+
meta: (contractJson1['meta'] as Record<string, unknown>) || {},
|
|
268
|
+
sources: (contractJson1['sources'] as Record<string, unknown>) || {},
|
|
269
|
+
});
|
|
268
270
|
|
|
269
|
-
|
|
271
|
+
const result2 = await emit(ir2, options, mockSqlHook);
|
|
270
272
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
expect(result1.contractJson).toBe(result2.contractJson);
|
|
274
|
+
expect(result1.storageHash).toBe(result2.storageHash);
|
|
275
|
+
},
|
|
276
|
+
timeouts.typeScriptCompilation,
|
|
277
|
+
);
|
|
274
278
|
});
|
|
@@ -133,7 +133,7 @@ describe('emitter round-trip', () => {
|
|
|
133
133
|
const result2 = await emit(ir2, options, mockSqlHook);
|
|
134
134
|
|
|
135
135
|
expect(result1.contractJson).toBe(result2.contractJson);
|
|
136
|
-
expect(result1.
|
|
136
|
+
expect(result1.storageHash).toBe(result2.storageHash);
|
|
137
137
|
},
|
|
138
138
|
timeouts.typeScriptCompilation,
|
|
139
139
|
);
|
|
@@ -230,7 +230,7 @@ describe('emitter round-trip', () => {
|
|
|
230
230
|
const result2 = await emit(ir2, options, mockSqlHook);
|
|
231
231
|
|
|
232
232
|
expect(result1.contractJson).toBe(result2.contractJson);
|
|
233
|
-
expect(result1.
|
|
233
|
+
expect(result1.storageHash).toBe(result2.storageHash);
|
|
234
234
|
});
|
|
235
235
|
|
|
236
236
|
it('round-trip with nullable fields', async () => {
|
|
@@ -289,7 +289,7 @@ describe('emitter round-trip', () => {
|
|
|
289
289
|
const result2 = await emit(ir2, options, mockSqlHook);
|
|
290
290
|
|
|
291
291
|
expect(result1.contractJson).toBe(result2.contractJson);
|
|
292
|
-
expect(result1.
|
|
292
|
+
expect(result1.storageHash).toBe(result2.storageHash);
|
|
293
293
|
|
|
294
294
|
const parsed2 = JSON.parse(result2.contractJson) as Record<string, unknown>;
|
|
295
295
|
const storage = parsed2['storage'] as Record<string, unknown>;
|
|
@@ -364,7 +364,7 @@ describe('emitter round-trip', () => {
|
|
|
364
364
|
const result2 = await emit(ir2, options, mockSqlHook);
|
|
365
365
|
|
|
366
366
|
expect(result1.contractJson).toBe(result2.contractJson);
|
|
367
|
-
expect(result1.
|
|
367
|
+
expect(result1.storageHash).toBe(result2.storageHash);
|
|
368
368
|
expect(result1.profileHash).toBe(result2.profileHash);
|
|
369
369
|
});
|
|
370
370
|
});
|
package/test/emitter.test.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ContractIR } from '@prisma-next/contract/ir';
|
|
2
2
|
import type {
|
|
3
|
+
GenerateContractTypesOptions,
|
|
3
4
|
TargetFamilyHook,
|
|
5
|
+
TypeRenderEntry,
|
|
4
6
|
TypesImportSpec,
|
|
5
|
-
ValidationContext,
|
|
6
7
|
} from '@prisma-next/contract/types';
|
|
7
8
|
import type { EmitOptions } from '@prisma-next/core-control-plane/emission';
|
|
8
9
|
import { emit } from '@prisma-next/core-control-plane/emission';
|
|
@@ -13,7 +14,7 @@ import { createContractIR } from './utils';
|
|
|
13
14
|
|
|
14
15
|
const mockSqlHook: TargetFamilyHook = {
|
|
15
16
|
id: 'sql',
|
|
16
|
-
validateTypes: (ir: ContractIR
|
|
17
|
+
validateTypes: (ir: ContractIR) => {
|
|
17
18
|
const storage = ir.storage as
|
|
18
19
|
| { tables?: Record<string, { columns?: Record<string, { codecId?: string }> }> }
|
|
19
20
|
| undefined;
|
|
@@ -45,11 +46,12 @@ const mockSqlHook: TargetFamilyHook = {
|
|
|
45
46
|
throw new Error(`Expected targetFamily "sql", got "${ir.targetFamily}"`);
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
|
-
generateContractTypes: (ir: ContractIR, _codecTypeImports, _operationTypeImports) => {
|
|
49
|
+
generateContractTypes: (ir: ContractIR, _codecTypeImports, _operationTypeImports, _hashes) => {
|
|
49
50
|
// Access ir properties to satisfy lint rules, but we don't use them in the mock
|
|
50
51
|
void ir;
|
|
51
52
|
void _codecTypeImports;
|
|
52
53
|
void _operationTypeImports;
|
|
54
|
+
void _hashes;
|
|
53
55
|
return `// Generated contract types
|
|
54
56
|
export type CodecTypes = Record<string, never>;
|
|
55
57
|
export type LaneCodecTypes = CodecTypes;
|
|
@@ -109,7 +111,7 @@ describe('emitter', () => {
|
|
|
109
111
|
};
|
|
110
112
|
|
|
111
113
|
const result = await emit(ir, options, mockSqlHook);
|
|
112
|
-
expect(result.
|
|
114
|
+
expect(result.storageHash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
113
115
|
expect(result.contractDts).toContain('export type Contract');
|
|
114
116
|
expect(result.contractDts).toContain('CodecTypes');
|
|
115
117
|
|
|
@@ -570,10 +572,12 @@ describe('emitter', () => {
|
|
|
570
572
|
await expect(emit(ir, options, mockSqlHook)).rejects.toThrow('ContractIR must have meta');
|
|
571
573
|
});
|
|
572
574
|
|
|
573
|
-
it('
|
|
575
|
+
it('omits sources from emitted contract artifact', async () => {
|
|
574
576
|
const ir = createContractIR({
|
|
575
|
-
sources:
|
|
576
|
-
|
|
577
|
+
sources: {
|
|
578
|
+
schema: { sourceId: 'schema.prisma' },
|
|
579
|
+
},
|
|
580
|
+
});
|
|
577
581
|
|
|
578
582
|
const operationRegistry = createOperationRegistry();
|
|
579
583
|
const options: EmitOptions = {
|
|
@@ -584,24 +588,68 @@ describe('emitter', () => {
|
|
|
584
588
|
extensionIds: [],
|
|
585
589
|
};
|
|
586
590
|
|
|
587
|
-
await
|
|
591
|
+
const result = await emit(ir, options, mockSqlHook);
|
|
592
|
+
const contractJson = JSON.parse(result.contractJson) as Record<string, unknown>;
|
|
593
|
+
expect(contractJson).not.toHaveProperty('sources');
|
|
588
594
|
});
|
|
589
595
|
|
|
590
|
-
it('
|
|
596
|
+
it('accepts meta keys when family validation allows them', async () => {
|
|
591
597
|
const ir = createContractIR({
|
|
592
|
-
|
|
593
|
-
|
|
598
|
+
meta: {
|
|
599
|
+
sourceId: 'schema.prisma',
|
|
600
|
+
schemaPath: '/tmp/schema.prisma',
|
|
601
|
+
source: 'psl',
|
|
602
|
+
},
|
|
603
|
+
});
|
|
594
604
|
|
|
595
|
-
const operationRegistry = createOperationRegistry();
|
|
596
605
|
const options: EmitOptions = {
|
|
597
606
|
outputDir: '',
|
|
598
|
-
operationRegistry,
|
|
607
|
+
operationRegistry: createOperationRegistry(),
|
|
608
|
+
codecTypeImports: [],
|
|
609
|
+
operationTypeImports: [],
|
|
610
|
+
extensionIds: [],
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
await expect(emit(ir, options, mockSqlHook)).resolves.toMatchObject({
|
|
614
|
+
contractJson: expect.any(String),
|
|
615
|
+
contractDts: expect.any(String),
|
|
616
|
+
});
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
it('accepts canonical section keys when family validation allows them', async () => {
|
|
620
|
+
const ir = createContractIR({
|
|
621
|
+
storage: {
|
|
622
|
+
tables: {
|
|
623
|
+
user: {
|
|
624
|
+
columns: {
|
|
625
|
+
id: {
|
|
626
|
+
codecId: 'pg/int4@1',
|
|
627
|
+
nativeType: 'int4',
|
|
628
|
+
nullable: false,
|
|
629
|
+
sourceId: 'schema.prisma',
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
primaryKey: { columns: ['id'] },
|
|
633
|
+
uniques: [],
|
|
634
|
+
indexes: [],
|
|
635
|
+
foreignKeys: [],
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
} as unknown as Record<string, unknown>,
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
const options: EmitOptions = {
|
|
642
|
+
outputDir: '',
|
|
643
|
+
operationRegistry: createOperationRegistry(),
|
|
599
644
|
codecTypeImports: [],
|
|
600
645
|
operationTypeImports: [],
|
|
601
646
|
extensionIds: [],
|
|
602
647
|
};
|
|
603
648
|
|
|
604
|
-
await expect(emit(ir, options, mockSqlHook)).
|
|
649
|
+
await expect(emit(ir, options, mockSqlHook)).resolves.toMatchObject({
|
|
650
|
+
contractJson: expect.any(String),
|
|
651
|
+
contractDts: expect.any(String),
|
|
652
|
+
});
|
|
605
653
|
});
|
|
606
654
|
|
|
607
655
|
it('emits contract even when extensionIds are not in contract.extensionPacks', async () => {
|
|
@@ -623,9 +671,10 @@ describe('emitter', () => {
|
|
|
623
671
|
throw new Error(`Expected targetFamily "sql", got "${ir.targetFamily}"`);
|
|
624
672
|
}
|
|
625
673
|
},
|
|
626
|
-
generateContractTypes: (_ir, _codecTypeImports, _operationTypeImports) => {
|
|
674
|
+
generateContractTypes: (_ir, _codecTypeImports, _operationTypeImports, _hashes) => {
|
|
627
675
|
void _codecTypeImports;
|
|
628
676
|
void _operationTypeImports;
|
|
677
|
+
void _hashes;
|
|
629
678
|
return `// Generated contract types
|
|
630
679
|
export type CodecTypes = Record<string, never>;
|
|
631
680
|
export type LaneCodecTypes = CodecTypes;
|
|
@@ -647,4 +696,56 @@ export type Contract = unknown;
|
|
|
647
696
|
expect(result.contractJson).toBeDefined();
|
|
648
697
|
expect(result.contractDts).toBeDefined();
|
|
649
698
|
});
|
|
699
|
+
|
|
700
|
+
it('passes parameterizedRenderers to generateContractTypes options', async () => {
|
|
701
|
+
const ir = createContractIR({
|
|
702
|
+
storage: {
|
|
703
|
+
tables: {},
|
|
704
|
+
},
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
let receivedOptions: GenerateContractTypesOptions | undefined;
|
|
708
|
+
|
|
709
|
+
const mockHookCapturingOptions: TargetFamilyHook = {
|
|
710
|
+
id: 'sql',
|
|
711
|
+
validateTypes: () => {},
|
|
712
|
+
validateStructure: () => {},
|
|
713
|
+
generateContractTypes: (_ir, _codecTypeImports, _operationTypeImports, _hashes, options) => {
|
|
714
|
+
receivedOptions = options;
|
|
715
|
+
return `// Generated contract types
|
|
716
|
+
export type CodecTypes = Record<string, never>;
|
|
717
|
+
export type LaneCodecTypes = CodecTypes;
|
|
718
|
+
export type Contract = unknown;
|
|
719
|
+
`;
|
|
720
|
+
},
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
const vectorRenderer: TypeRenderEntry = {
|
|
724
|
+
codecId: 'pg/vector@1',
|
|
725
|
+
render: (params) => `Vector<${params['length']}>`,
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
const parameterizedRenderers = new Map<string, TypeRenderEntry>();
|
|
729
|
+
parameterizedRenderers.set('pg/vector@1', vectorRenderer);
|
|
730
|
+
|
|
731
|
+
const options: EmitOptions = {
|
|
732
|
+
outputDir: '',
|
|
733
|
+
operationRegistry: createOperationRegistry(),
|
|
734
|
+
codecTypeImports: [],
|
|
735
|
+
operationTypeImports: [],
|
|
736
|
+
extensionIds: [],
|
|
737
|
+
parameterizedRenderers,
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
await emit(ir, options, mockHookCapturingOptions);
|
|
741
|
+
|
|
742
|
+
expect(receivedOptions).toBeDefined();
|
|
743
|
+
expect(receivedOptions?.parameterizedRenderers).toBeDefined();
|
|
744
|
+
expect(receivedOptions?.parameterizedRenderers?.size).toBe(1);
|
|
745
|
+
|
|
746
|
+
const entry = receivedOptions?.parameterizedRenderers?.get('pg/vector@1');
|
|
747
|
+
expect(entry).toBeDefined();
|
|
748
|
+
expect(entry?.codecId).toBe('pg/vector@1');
|
|
749
|
+
expect(entry?.render({ length: 1536 }, { codecTypesName: 'CodecTypes' })).toBe('Vector<1536>');
|
|
750
|
+
});
|
|
650
751
|
});
|
package/test/factories.test.ts
CHANGED
|
@@ -7,13 +7,13 @@ describe('emitter factories', () => {
|
|
|
7
7
|
const header = irHeader({
|
|
8
8
|
target: 'postgres',
|
|
9
9
|
targetFamily: 'sql',
|
|
10
|
-
|
|
10
|
+
storageHash: 'sha256:abc123',
|
|
11
11
|
});
|
|
12
12
|
expect(header).toEqual({
|
|
13
13
|
schemaVersion: '1',
|
|
14
14
|
target: 'postgres',
|
|
15
15
|
targetFamily: 'sql',
|
|
16
|
-
|
|
16
|
+
storageHash: 'sha256:abc123',
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
|
|
@@ -21,14 +21,14 @@ describe('emitter factories', () => {
|
|
|
21
21
|
const header = irHeader({
|
|
22
22
|
target: 'postgres',
|
|
23
23
|
targetFamily: 'sql',
|
|
24
|
-
|
|
24
|
+
storageHash: 'sha256:abc123',
|
|
25
25
|
profileHash: 'sha256:def456',
|
|
26
26
|
});
|
|
27
27
|
expect(header).toEqual({
|
|
28
28
|
schemaVersion: '1',
|
|
29
29
|
target: 'postgres',
|
|
30
30
|
targetFamily: 'sql',
|
|
31
|
-
|
|
31
|
+
storageHash: 'sha256:abc123',
|
|
32
32
|
profileHash: 'sha256:def456',
|
|
33
33
|
});
|
|
34
34
|
});
|
|
@@ -37,7 +37,7 @@ describe('emitter factories', () => {
|
|
|
37
37
|
const header = irHeader({
|
|
38
38
|
target: 'mongodb',
|
|
39
39
|
targetFamily: 'document',
|
|
40
|
-
|
|
40
|
+
storageHash: 'sha256:xyz789',
|
|
41
41
|
});
|
|
42
42
|
expect(header.targetFamily).toBe('document');
|
|
43
43
|
expect(header.target).toBe('mongodb');
|
|
@@ -149,7 +149,7 @@ describe('emitter factories', () => {
|
|
|
149
149
|
const header = irHeader({
|
|
150
150
|
target: 'postgres',
|
|
151
151
|
targetFamily: 'sql',
|
|
152
|
-
|
|
152
|
+
storageHash: 'sha256:abc123',
|
|
153
153
|
});
|
|
154
154
|
const meta = irMeta({
|
|
155
155
|
capabilities: {
|
|
@@ -171,7 +171,7 @@ describe('emitter factories', () => {
|
|
|
171
171
|
expect(ir.schemaVersion).toBe('1');
|
|
172
172
|
expect(ir.target).toBe('postgres');
|
|
173
173
|
expect(ir.targetFamily).toBe('sql');
|
|
174
|
-
// Note:
|
|
174
|
+
// Note: storageHash is not part of ContractIR (it's computed by emitter)
|
|
175
175
|
expect(ir.storage).toEqual(storage);
|
|
176
176
|
expect(ir.models).toEqual(models);
|
|
177
177
|
expect(ir.relations).toEqual(relations);
|
|
@@ -187,7 +187,7 @@ describe('emitter factories', () => {
|
|
|
187
187
|
const header = irHeader({
|
|
188
188
|
target: 'postgres',
|
|
189
189
|
targetFamily: 'sql',
|
|
190
|
-
|
|
190
|
+
storageHash: 'sha256:abc123',
|
|
191
191
|
profileHash: 'sha256:def456',
|
|
192
192
|
});
|
|
193
193
|
const meta = irMeta({});
|
|
@@ -213,7 +213,7 @@ describe('emitter factories', () => {
|
|
|
213
213
|
const header = irHeader({
|
|
214
214
|
target: 'postgres',
|
|
215
215
|
targetFamily: 'sql',
|
|
216
|
-
|
|
216
|
+
storageHash: 'sha256:abc123',
|
|
217
217
|
});
|
|
218
218
|
const meta = irMeta({
|
|
219
219
|
capabilities: {
|
|
@@ -251,7 +251,7 @@ describe('emitter factories', () => {
|
|
|
251
251
|
const header = irHeader({
|
|
252
252
|
target: 'mongodb',
|
|
253
253
|
targetFamily: 'document',
|
|
254
|
-
|
|
254
|
+
storageHash: 'sha256:xyz789',
|
|
255
255
|
});
|
|
256
256
|
const meta = irMeta({});
|
|
257
257
|
const storage = { document: { collections: {} } };
|
package/test/hashing.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computeProfileHash, computeStorageHash } from '@prisma-next/core-control-plane/emission';
|
|
2
2
|
import { describe, expect, it } from 'vitest';
|
|
3
3
|
|
|
4
4
|
describe('hashing', () => {
|
|
5
|
-
it('computes
|
|
5
|
+
it('computes storage hash', () => {
|
|
6
6
|
const contract = {
|
|
7
7
|
schemaVersion: '1',
|
|
8
8
|
targetFamily: 'sql',
|
|
@@ -16,7 +16,7 @@ describe('hashing', () => {
|
|
|
16
16
|
sources: {},
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const hash =
|
|
19
|
+
const hash = computeStorageHash(contract);
|
|
20
20
|
expect(hash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
21
21
|
});
|
|
22
22
|
|
|
@@ -52,8 +52,8 @@ describe('hashing', () => {
|
|
|
52
52
|
sources: {},
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const hash1 =
|
|
56
|
-
const hash2 =
|
|
55
|
+
const hash1 = computeStorageHash(contract);
|
|
56
|
+
const hash2 = computeStorageHash(contract);
|
|
57
57
|
expect(hash1).toBe(hash2);
|
|
58
58
|
});
|
|
59
59
|
});
|
package/test/utils.ts
CHANGED
|
@@ -9,12 +9,12 @@ import { type ContractIR, irHeader, irMeta } from '@prisma-next/contract/ir';
|
|
|
9
9
|
* from the result (useful for testing validation of missing fields).
|
|
10
10
|
*/
|
|
11
11
|
export function createContractIR(
|
|
12
|
-
overrides: Partial<ContractIR> & {
|
|
12
|
+
overrides: Partial<ContractIR> & { storageHash?: string; profileHash?: string } = {},
|
|
13
13
|
): ContractIR {
|
|
14
14
|
// Check if fields are explicitly undefined (not just missing)
|
|
15
15
|
const hasTarget = 'target' in overrides;
|
|
16
16
|
const hasTargetFamily = 'targetFamily' in overrides;
|
|
17
|
-
const
|
|
17
|
+
const hasStorageHash = 'storageHash' in overrides;
|
|
18
18
|
const hasSchemaVersion = 'schemaVersion' in overrides;
|
|
19
19
|
const hasModels = 'models' in overrides;
|
|
20
20
|
const hasRelations = 'relations' in overrides;
|
|
@@ -28,7 +28,7 @@ export function createContractIR(
|
|
|
28
28
|
const headerOpts: {
|
|
29
29
|
target?: string;
|
|
30
30
|
targetFamily?: string;
|
|
31
|
-
|
|
31
|
+
storageHash?: string;
|
|
32
32
|
profileHash?: string;
|
|
33
33
|
} = {};
|
|
34
34
|
|
|
@@ -44,10 +44,10 @@ export function createContractIR(
|
|
|
44
44
|
headerOpts.targetFamily = 'sql';
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
if (
|
|
48
|
-
headerOpts.
|
|
49
|
-
} else if (!
|
|
50
|
-
headerOpts.
|
|
47
|
+
if (hasStorageHash && overrides.storageHash !== undefined) {
|
|
48
|
+
headerOpts.storageHash = overrides.storageHash;
|
|
49
|
+
} else if (!hasStorageHash) {
|
|
50
|
+
headerOpts.storageHash = 'sha256:test';
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// profileHash is not part of ContractIR, but we can accept it for header creation
|
|
@@ -59,7 +59,7 @@ export function createContractIR(
|
|
|
59
59
|
headerOpts as {
|
|
60
60
|
target: string;
|
|
61
61
|
targetFamily: string;
|
|
62
|
-
|
|
62
|
+
storageHash: string;
|
|
63
63
|
profileHash?: string;
|
|
64
64
|
},
|
|
65
65
|
);
|
|
@@ -99,7 +99,7 @@ export function createContractIR(
|
|
|
99
99
|
|
|
100
100
|
const meta = irMeta(Object.keys(metaOpts).length > 0 ? metaOpts : undefined);
|
|
101
101
|
|
|
102
|
-
// Build result by constructing the object directly (ContractIR doesn't include
|
|
102
|
+
// Build result by constructing the object directly (ContractIR doesn't include storageHash/profileHash)
|
|
103
103
|
// When fields are explicitly undefined, include them as undefined (tests use type assertions to bypass TS)
|
|
104
104
|
const result = {
|
|
105
105
|
schemaVersion:
|
package/dist/exports/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/index.ts"],"sourcesContent":["// Re-export types from @prisma-next/contract for backward compatibility\nexport type {\n TargetFamilyHook,\n TypesImportSpec,\n ValidationContext,\n} from '@prisma-next/contract/types';\nexport type { EmitOptions, EmitResult } from '@prisma-next/core-control-plane/emission';\n// Re-export emit function and types from core-control-plane\nexport { emit } from '@prisma-next/core-control-plane/emission';\n"],"mappings":";AAQA,SAAS,YAAY;","names":[]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { TargetFamilyHook, TypesImportSpec, ValidationContext, } from '@prisma-next/contract/types';
|
|
2
|
-
export type { EmitOptions, EmitResult } from '@prisma-next/core-control-plane/emission';
|
|
3
|
-
export { emit } from '@prisma-next/core-control-plane/emission';
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exports/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAExF,OAAO,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"target-family.d.ts","sourceRoot":"","sources":["../../src/target-family.ts"],"names":[],"mappings":"AAEA,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,GAClB,MAAM,6BAA6B,CAAC"}
|
package/dist/test/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAoB,MAAM,0BAA0B,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,GAAE,OAAO,CAAC,UAAU,CAAC,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GAChF,UAAU,CAyJZ"}
|