@prisma-next/emitter 0.3.0-pr.93.5 → 0.3.0-pr.94.2
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/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/test/utils.d.mts +19 -0
- 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 +17 -15
- package/dist/exports/index.d.ts +0 -4
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/exports/index.js +0 -6
- package/dist/exports/index.js.map +0 -1
- package/dist/target-family.d.ts +0 -2
- package/dist/target-family.d.ts.map +0 -1
- package/dist/test/utils.js +0 -78
- package/dist/test/utils.js.map +0 -1
- package/test/canonicalization.test.ts +0 -210
- package/test/emitter.integration.test.ts +0 -274
- package/test/emitter.roundtrip.test.ts +0 -370
- package/test/emitter.test.ts +0 -650
- package/test/factories.test.ts +0 -274
- package/test/hashing.test.ts +0 -59
- package/test/tsconfig.json +0 -4
package/test/factories.test.ts
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
import { contractIR, irHeader, irMeta } from '@prisma-next/contract/ir';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
describe('emitter factories', () => {
|
|
5
|
-
describe('irHeader', () => {
|
|
6
|
-
it('creates header with required fields', () => {
|
|
7
|
-
const header = irHeader({
|
|
8
|
-
target: 'postgres',
|
|
9
|
-
targetFamily: 'sql',
|
|
10
|
-
coreHash: 'sha256:abc123',
|
|
11
|
-
});
|
|
12
|
-
expect(header).toEqual({
|
|
13
|
-
schemaVersion: '1',
|
|
14
|
-
target: 'postgres',
|
|
15
|
-
targetFamily: 'sql',
|
|
16
|
-
coreHash: 'sha256:abc123',
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('creates header with profileHash', () => {
|
|
21
|
-
const header = irHeader({
|
|
22
|
-
target: 'postgres',
|
|
23
|
-
targetFamily: 'sql',
|
|
24
|
-
coreHash: 'sha256:abc123',
|
|
25
|
-
profileHash: 'sha256:def456',
|
|
26
|
-
});
|
|
27
|
-
expect(header).toEqual({
|
|
28
|
-
schemaVersion: '1',
|
|
29
|
-
target: 'postgres',
|
|
30
|
-
targetFamily: 'sql',
|
|
31
|
-
coreHash: 'sha256:abc123',
|
|
32
|
-
profileHash: 'sha256:def456',
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('creates header for different target families', () => {
|
|
37
|
-
const header = irHeader({
|
|
38
|
-
target: 'mongodb',
|
|
39
|
-
targetFamily: 'document',
|
|
40
|
-
coreHash: 'sha256:xyz789',
|
|
41
|
-
});
|
|
42
|
-
expect(header.targetFamily).toBe('document');
|
|
43
|
-
expect(header.target).toBe('mongodb');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('irMeta', () => {
|
|
48
|
-
it('creates empty meta when no options provided', () => {
|
|
49
|
-
const meta = irMeta({});
|
|
50
|
-
expect(meta).toEqual({
|
|
51
|
-
capabilities: {},
|
|
52
|
-
extensionPacks: {},
|
|
53
|
-
meta: {},
|
|
54
|
-
sources: {},
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('creates meta with capabilities', () => {
|
|
59
|
-
const meta = irMeta({
|
|
60
|
-
capabilities: {
|
|
61
|
-
postgres: {
|
|
62
|
-
returning: true,
|
|
63
|
-
lateral: true,
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
expect(meta.capabilities).toEqual({
|
|
68
|
-
postgres: {
|
|
69
|
-
returning: true,
|
|
70
|
-
lateral: true,
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
expect(meta.extensionPacks).toEqual({});
|
|
74
|
-
expect(meta.meta).toEqual({});
|
|
75
|
-
expect(meta.sources).toEqual({});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('creates meta with extension packs', () => {
|
|
79
|
-
const meta = irMeta({
|
|
80
|
-
extensionPacks: {
|
|
81
|
-
postgres: {
|
|
82
|
-
id: 'postgres',
|
|
83
|
-
version: '0.0.1',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
expect(meta.extensionPacks).toEqual({
|
|
88
|
-
postgres: {
|
|
89
|
-
id: 'postgres',
|
|
90
|
-
version: '0.0.1',
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('creates meta with custom meta', () => {
|
|
96
|
-
const meta = irMeta({
|
|
97
|
-
meta: {
|
|
98
|
-
generated: true,
|
|
99
|
-
timestamp: '2024-01-01T00:00:00Z',
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
expect(meta.meta).toEqual({
|
|
103
|
-
generated: true,
|
|
104
|
-
timestamp: '2024-01-01T00:00:00Z',
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('creates meta with sources', () => {
|
|
109
|
-
const meta = irMeta({
|
|
110
|
-
sources: {
|
|
111
|
-
userView: {
|
|
112
|
-
kind: 'view',
|
|
113
|
-
sql: 'SELECT * FROM "user"',
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
expect(meta.sources).toEqual({
|
|
118
|
-
userView: {
|
|
119
|
-
kind: 'view',
|
|
120
|
-
sql: 'SELECT * FROM "user"',
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('creates meta with all fields', () => {
|
|
126
|
-
const meta = irMeta({
|
|
127
|
-
capabilities: {
|
|
128
|
-
postgres: { returning: true },
|
|
129
|
-
},
|
|
130
|
-
extensionPacks: {
|
|
131
|
-
postgres: { id: 'postgres', version: '0.0.1' },
|
|
132
|
-
},
|
|
133
|
-
meta: { generated: true },
|
|
134
|
-
sources: { userView: { kind: 'view' } },
|
|
135
|
-
});
|
|
136
|
-
expect(meta.capabilities).toEqual({
|
|
137
|
-
postgres: { returning: true },
|
|
138
|
-
});
|
|
139
|
-
expect(meta.extensionPacks).toEqual({
|
|
140
|
-
postgres: { id: 'postgres', version: '0.0.1' },
|
|
141
|
-
});
|
|
142
|
-
expect(meta.meta).toEqual({ generated: true });
|
|
143
|
-
expect(meta.sources).toEqual({ userView: { kind: 'view' } });
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('contractIR', () => {
|
|
148
|
-
it('creates complete ContractIR from header, meta, and family sections', () => {
|
|
149
|
-
const header = irHeader({
|
|
150
|
-
target: 'postgres',
|
|
151
|
-
targetFamily: 'sql',
|
|
152
|
-
coreHash: 'sha256:abc123',
|
|
153
|
-
});
|
|
154
|
-
const meta = irMeta({
|
|
155
|
-
capabilities: {
|
|
156
|
-
postgres: { returning: true },
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
const storage = { tables: { user: { columns: {} } } };
|
|
160
|
-
const models = { User: { storage: { table: 'user' }, fields: {} } };
|
|
161
|
-
const relations = {};
|
|
162
|
-
|
|
163
|
-
const ir = contractIR({
|
|
164
|
-
header,
|
|
165
|
-
meta,
|
|
166
|
-
storage,
|
|
167
|
-
models,
|
|
168
|
-
relations,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(ir.schemaVersion).toBe('1');
|
|
172
|
-
expect(ir.target).toBe('postgres');
|
|
173
|
-
expect(ir.targetFamily).toBe('sql');
|
|
174
|
-
// Note: coreHash is not part of ContractIR (it's computed by emitter)
|
|
175
|
-
expect(ir.storage).toEqual(storage);
|
|
176
|
-
expect(ir.models).toEqual(models);
|
|
177
|
-
expect(ir.relations).toEqual(relations);
|
|
178
|
-
expect(ir.capabilities).toEqual({
|
|
179
|
-
postgres: { returning: true },
|
|
180
|
-
});
|
|
181
|
-
expect(ir.extensionPacks).toEqual({});
|
|
182
|
-
expect(ir.meta).toEqual({});
|
|
183
|
-
expect(ir.sources).toEqual({});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('creates ContractIR with profileHash in header', () => {
|
|
187
|
-
const header = irHeader({
|
|
188
|
-
target: 'postgres',
|
|
189
|
-
targetFamily: 'sql',
|
|
190
|
-
coreHash: 'sha256:abc123',
|
|
191
|
-
profileHash: 'sha256:def456',
|
|
192
|
-
});
|
|
193
|
-
const meta = irMeta({});
|
|
194
|
-
const storage = { tables: {} };
|
|
195
|
-
const models = {};
|
|
196
|
-
const relations = {};
|
|
197
|
-
|
|
198
|
-
const ir = contractIR({
|
|
199
|
-
header,
|
|
200
|
-
meta,
|
|
201
|
-
storage,
|
|
202
|
-
models,
|
|
203
|
-
relations,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// Note: profileHash is not part of ContractIR (it's computed by emitter)
|
|
207
|
-
// The header contains it, but it's not included in the ContractIR
|
|
208
|
-
expect(header.profileHash).toBe('sha256:def456');
|
|
209
|
-
expect(ir.target).toBe('postgres');
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('creates ContractIR with all meta fields', () => {
|
|
213
|
-
const header = irHeader({
|
|
214
|
-
target: 'postgres',
|
|
215
|
-
targetFamily: 'sql',
|
|
216
|
-
coreHash: 'sha256:abc123',
|
|
217
|
-
});
|
|
218
|
-
const meta = irMeta({
|
|
219
|
-
capabilities: {
|
|
220
|
-
postgres: { returning: true },
|
|
221
|
-
},
|
|
222
|
-
extensionPacks: {
|
|
223
|
-
postgres: { id: 'postgres', version: '0.0.1' },
|
|
224
|
-
},
|
|
225
|
-
meta: { generated: true },
|
|
226
|
-
sources: { userView: { kind: 'view' } },
|
|
227
|
-
});
|
|
228
|
-
const storage = { tables: {} };
|
|
229
|
-
const models = {};
|
|
230
|
-
const relations = {};
|
|
231
|
-
|
|
232
|
-
const ir = contractIR({
|
|
233
|
-
header,
|
|
234
|
-
meta,
|
|
235
|
-
storage,
|
|
236
|
-
models,
|
|
237
|
-
relations,
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
expect(ir.capabilities).toEqual({
|
|
241
|
-
postgres: { returning: true },
|
|
242
|
-
});
|
|
243
|
-
expect(ir.extensionPacks).toEqual({
|
|
244
|
-
postgres: { id: 'postgres', version: '0.0.1' },
|
|
245
|
-
});
|
|
246
|
-
expect(ir.meta).toEqual({ generated: true });
|
|
247
|
-
expect(ir.sources).toEqual({ userView: { kind: 'view' } });
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it('creates ContractIR for document family', () => {
|
|
251
|
-
const header = irHeader({
|
|
252
|
-
target: 'mongodb',
|
|
253
|
-
targetFamily: 'document',
|
|
254
|
-
coreHash: 'sha256:xyz789',
|
|
255
|
-
});
|
|
256
|
-
const meta = irMeta({});
|
|
257
|
-
const storage = { document: { collections: {} } };
|
|
258
|
-
const models = {};
|
|
259
|
-
const relations = {};
|
|
260
|
-
|
|
261
|
-
const ir = contractIR({
|
|
262
|
-
header,
|
|
263
|
-
meta,
|
|
264
|
-
storage,
|
|
265
|
-
models,
|
|
266
|
-
relations,
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
expect(ir.targetFamily).toBe('document');
|
|
270
|
-
expect(ir.target).toBe('mongodb');
|
|
271
|
-
expect(ir.storage).toEqual(storage);
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
});
|
package/test/hashing.test.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { computeCoreHash, computeProfileHash } from '@prisma-next/core-control-plane/emission';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
describe('hashing', () => {
|
|
5
|
-
it('computes core hash', () => {
|
|
6
|
-
const contract = {
|
|
7
|
-
schemaVersion: '1',
|
|
8
|
-
targetFamily: 'sql',
|
|
9
|
-
target: 'postgres',
|
|
10
|
-
models: {},
|
|
11
|
-
relations: {},
|
|
12
|
-
storage: { tables: {} },
|
|
13
|
-
extensionPacks: {},
|
|
14
|
-
capabilities: {},
|
|
15
|
-
meta: {},
|
|
16
|
-
sources: {},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const hash = computeCoreHash(contract);
|
|
20
|
-
expect(hash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('computes profile hash', () => {
|
|
24
|
-
const contract = {
|
|
25
|
-
schemaVersion: '1',
|
|
26
|
-
targetFamily: 'sql',
|
|
27
|
-
target: 'postgres',
|
|
28
|
-
models: {},
|
|
29
|
-
relations: {},
|
|
30
|
-
storage: { tables: {} },
|
|
31
|
-
extensionPacks: {},
|
|
32
|
-
capabilities: { postgres: { jsonAgg: true } },
|
|
33
|
-
meta: {},
|
|
34
|
-
sources: {},
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const hash = computeProfileHash(contract);
|
|
38
|
-
expect(hash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('produces stable hashes for identical input', () => {
|
|
42
|
-
const contract = {
|
|
43
|
-
schemaVersion: '1',
|
|
44
|
-
targetFamily: 'sql',
|
|
45
|
-
target: 'postgres',
|
|
46
|
-
models: {},
|
|
47
|
-
relations: {},
|
|
48
|
-
storage: { tables: {} },
|
|
49
|
-
extensionPacks: {},
|
|
50
|
-
capabilities: {},
|
|
51
|
-
meta: {},
|
|
52
|
-
sources: {},
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const hash1 = computeCoreHash(contract);
|
|
56
|
-
const hash2 = computeCoreHash(contract);
|
|
57
|
-
expect(hash1).toBe(hash2);
|
|
58
|
-
});
|
|
59
|
-
});
|
package/test/tsconfig.json
DELETED