@prisma-next/emitter 0.3.0-dev.46 → 0.3.0-dev.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/emitter",
3
- "version": "0.3.0-dev.46",
3
+ "version": "0.3.0-dev.48",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -10,16 +10,16 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "arktype": "^2.0.0",
13
- "@prisma-next/core-control-plane": "0.3.0-dev.46",
14
- "@prisma-next/contract": "0.3.0-dev.46"
13
+ "@prisma-next/contract": "0.3.0-dev.48",
14
+ "@prisma-next/core-control-plane": "0.3.0-dev.48"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/node": "24.10.4",
18
18
  "tsdown": "0.18.4",
19
19
  "typescript": "5.9.3",
20
20
  "vitest": "4.0.17",
21
+ "@prisma-next/operations": "0.3.0-dev.48",
21
22
  "@prisma-next/test-utils": "0.0.1",
22
- "@prisma-next/operations": "0.3.0-dev.46",
23
23
  "@prisma-next/tsconfig": "0.0.0",
24
24
  "@prisma-next/tsdown": "0.0.0"
25
25
  },
@@ -6,7 +6,7 @@ describe('canonicalization', () => {
6
6
  it('orders top-level sections correctly', () => {
7
7
  const ir = createContractIR({
8
8
  capabilities: { postgres: { jsonAgg: true } },
9
- meta: { source: 'test' },
9
+ meta: { emitterVersion: 'test' },
10
10
  });
11
11
 
12
12
  const result = canonicalizeContract(ir);
@@ -17,6 +17,7 @@ describe('canonicalization', () => {
17
17
  const targetFamilyIndex = keys.indexOf('targetFamily');
18
18
  const targetIndex = keys.indexOf('target');
19
19
  const modelsIndex = keys.indexOf('models');
20
+ const relationsIndex = keys.indexOf('relations');
20
21
  const storageIndex = keys.indexOf('storage');
21
22
  const capabilitiesIndex = keys.indexOf('capabilities');
22
23
  const metaIndex = keys.indexOf('meta');
@@ -24,6 +25,8 @@ describe('canonicalization', () => {
24
25
  expect(schemaVersionIndex).toBeLessThan(targetFamilyIndex);
25
26
  expect(targetFamilyIndex).toBeLessThan(targetIndex);
26
27
  expect(targetIndex).toBeLessThan(modelsIndex);
28
+ expect(modelsIndex).toBeLessThan(relationsIndex);
29
+ expect(relationsIndex).toBeLessThan(storageIndex);
27
30
  expect(modelsIndex).toBeLessThan(storageIndex);
28
31
  expect(storageIndex).toBeLessThan(capabilitiesIndex);
29
32
  expect(capabilitiesIndex).toBeLessThan(metaIndex);
@@ -133,14 +136,12 @@ describe('canonicalization', () => {
133
136
  tables: expect.anything(),
134
137
  },
135
138
  });
136
- // Required top-level fields (capabilities, extensionPacks, meta, relations, sources) are preserved even when empty
137
- // because they are required by ContractIR and needed for round-trip tests
139
+ // Required top-level fields (capabilities, extensionPacks, meta, relations) are preserved even when empty.
138
140
  expect(parsed).toMatchObject({
139
141
  capabilities: expect.anything(),
140
142
  extensionPacks: expect.anything(),
141
143
  meta: expect.anything(),
142
144
  relations: expect.anything(),
143
- sources: expect.anything(),
144
145
  });
145
146
  });
146
147
 
@@ -572,10 +572,12 @@ describe('emitter', () => {
572
572
  await expect(emit(ir, options, mockSqlHook)).rejects.toThrow('ContractIR must have meta');
573
573
  });
574
574
 
575
- it('throws error when sources is missing', async () => {
575
+ it('omits sources from emitted contract artifact', async () => {
576
576
  const ir = createContractIR({
577
- sources: undefined as unknown as Record<string, unknown>,
578
- }) as ContractIR;
577
+ sources: {
578
+ schema: { sourceId: 'schema.prisma' },
579
+ },
580
+ });
579
581
 
580
582
  const operationRegistry = createOperationRegistry();
581
583
  const options: EmitOptions = {
@@ -586,24 +588,68 @@ describe('emitter', () => {
586
588
  extensionIds: [],
587
589
  };
588
590
 
589
- await expect(emit(ir, options, mockSqlHook)).rejects.toThrow('ContractIR must have sources');
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');
590
594
  });
591
595
 
592
- it('throws error when sources is not an object', async () => {
596
+ it('accepts meta keys when family validation allows them', async () => {
593
597
  const ir = createContractIR({
594
- sources: 'not-an-object' as unknown as Record<string, unknown>,
595
- }) as ContractIR;
598
+ meta: {
599
+ sourceId: 'schema.prisma',
600
+ schemaPath: '/tmp/schema.prisma',
601
+ source: 'psl',
602
+ },
603
+ });
596
604
 
597
- const operationRegistry = createOperationRegistry();
598
605
  const options: EmitOptions = {
599
606
  outputDir: '',
600
- operationRegistry,
607
+ operationRegistry: createOperationRegistry(),
601
608
  codecTypeImports: [],
602
609
  operationTypeImports: [],
603
610
  extensionIds: [],
604
611
  };
605
612
 
606
- await expect(emit(ir, options, mockSqlHook)).rejects.toThrow('ContractIR must have sources');
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(),
644
+ codecTypeImports: [],
645
+ operationTypeImports: [],
646
+ extensionIds: [],
647
+ };
648
+
649
+ await expect(emit(ir, options, mockSqlHook)).resolves.toMatchObject({
650
+ contractJson: expect.any(String),
651
+ contractDts: expect.any(String),
652
+ });
607
653
  });
608
654
 
609
655
  it('emits contract even when extensionIds are not in contract.extensionPacks', async () => {