@prisma-next/emitter 0.5.0-dev.4 → 0.5.0-dev.41
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/domain-type-generation.d.mts +18 -5
- package/dist/domain-type-generation.d.mts.map +1 -1
- package/dist/domain-type-generation.mjs +10 -9
- package/dist/domain-type-generation.mjs.map +1 -1
- package/dist/exports/index.mjs +6 -1
- package/dist/exports/index.mjs.map +1 -1
- package/package.json +6 -7
- package/src/domain-type-generation.ts +36 -5
- package/src/generate-contract-dts.ts +9 -0
- package/test/canonicalization.test.ts +0 -387
- package/test/domain-type-generation.test.ts +0 -997
- package/test/emitter.integration.test.ts +0 -219
- package/test/emitter.roundtrip.test.ts +0 -296
- package/test/emitter.test.ts +0 -367
- package/test/hashing.test.ts +0 -34
- package/test/mock-spi.ts +0 -18
- package/test/type-expression-safety.test.ts +0 -34
- package/test/utils.ts +0 -31
package/test/emitter.test.ts
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
import type { TypesImportSpec } from '@prisma-next/framework-components/emission';
|
|
2
|
-
import { timeouts } from '@prisma-next/test-utils';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
import type { EmitStackInput } from '../src/exports';
|
|
5
|
-
import { emit, getEmittedArtifactPaths } from '../src/exports';
|
|
6
|
-
import { createMockSpi } from './mock-spi';
|
|
7
|
-
import { createTestContract } from './utils';
|
|
8
|
-
|
|
9
|
-
const mockSqlHook = createMockSpi();
|
|
10
|
-
|
|
11
|
-
describe('emitter', () => {
|
|
12
|
-
it('derives colocated artifact paths from contract.json output', () => {
|
|
13
|
-
expect(getEmittedArtifactPaths('/abs/contract.json')).toEqual({
|
|
14
|
-
jsonPath: '/abs/contract.json',
|
|
15
|
-
dtsPath: '/abs/contract.d.ts',
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('rejects non-json output paths when deriving artifact paths', () => {
|
|
20
|
-
expect(() => getEmittedArtifactPaths('/abs/contract.ts')).toThrow(
|
|
21
|
-
'Contract output path must end with .json',
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it(
|
|
26
|
-
'rejects non-json output paths when emit receives an output path',
|
|
27
|
-
async () => {
|
|
28
|
-
const ir = createTestContract();
|
|
29
|
-
const options: EmitStackInput = {
|
|
30
|
-
codecTypeImports: [],
|
|
31
|
-
operationTypeImports: [],
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
await expect(
|
|
35
|
-
emit(ir, options, mockSqlHook, {
|
|
36
|
-
outputJsonPath: '/abs/contract.ts',
|
|
37
|
-
}),
|
|
38
|
-
).rejects.toThrow('Contract output path must end with .json');
|
|
39
|
-
},
|
|
40
|
-
timeouts.typeScriptCompilation,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
it(
|
|
44
|
-
'emits contract.json and contract.d.ts',
|
|
45
|
-
async () => {
|
|
46
|
-
const ir = createTestContract({
|
|
47
|
-
models: {
|
|
48
|
-
User: {
|
|
49
|
-
storage: {
|
|
50
|
-
table: 'user',
|
|
51
|
-
fields: {
|
|
52
|
-
id: { column: 'id' },
|
|
53
|
-
email: { column: 'email' },
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
fields: {
|
|
57
|
-
id: { type: { kind: 'scalar', codecId: 'pg/int4@1' }, nullable: false },
|
|
58
|
-
email: { type: { kind: 'scalar', codecId: 'pg/text@1' }, nullable: false },
|
|
59
|
-
},
|
|
60
|
-
relations: {},
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
storage: {
|
|
64
|
-
tables: {
|
|
65
|
-
user: {
|
|
66
|
-
columns: {
|
|
67
|
-
id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
|
|
68
|
-
email: { codecId: 'pg/text@1', nativeType: 'text', nullable: false },
|
|
69
|
-
},
|
|
70
|
-
primaryKey: { columns: ['id'] },
|
|
71
|
-
uniques: [],
|
|
72
|
-
indexes: [],
|
|
73
|
-
foreignKeys: [],
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
extensionPacks: {
|
|
78
|
-
postgres: {
|
|
79
|
-
version: '0.0.1',
|
|
80
|
-
},
|
|
81
|
-
pg: {},
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const codecTypeImports: TypesImportSpec[] = [];
|
|
86
|
-
const operationTypeImports: TypesImportSpec[] = [];
|
|
87
|
-
const extensionIds = ['postgres', 'pg'];
|
|
88
|
-
const options: EmitStackInput = {
|
|
89
|
-
codecTypeImports,
|
|
90
|
-
operationTypeImports,
|
|
91
|
-
extensionIds,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
95
|
-
expect(result.storageHash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
96
|
-
expect(result.contractDts).toContain('export type Contract');
|
|
97
|
-
expect(result.contractDts).toContain('CodecTypes');
|
|
98
|
-
|
|
99
|
-
const contractJson = JSON.parse(result.contractJson) as Record<string, unknown>;
|
|
100
|
-
const storage = contractJson['storage'] as Record<string, unknown>;
|
|
101
|
-
const tables = storage['tables'] as Record<string, unknown>;
|
|
102
|
-
expect(tables).toBeDefined();
|
|
103
|
-
},
|
|
104
|
-
timeouts.typeScriptCompilation,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
it('emits contract even when extension pack namespace does not match extensionIds', async () => {
|
|
108
|
-
const ir = createTestContract({
|
|
109
|
-
storage: {
|
|
110
|
-
tables: {
|
|
111
|
-
user: {
|
|
112
|
-
columns: {
|
|
113
|
-
id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
|
|
114
|
-
},
|
|
115
|
-
uniques: [],
|
|
116
|
-
indexes: [],
|
|
117
|
-
foreignKeys: [],
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const options: EmitStackInput = {
|
|
124
|
-
codecTypeImports: [],
|
|
125
|
-
operationTypeImports: [],
|
|
126
|
-
extensionIds: [],
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
130
|
-
expect(result.contractJson).toBeDefined();
|
|
131
|
-
expect(result.contractDts).toBeDefined();
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('tolerates codec namespaces not registered in extensionIds', async () => {
|
|
135
|
-
const ir = createTestContract({
|
|
136
|
-
storage: {
|
|
137
|
-
tables: {
|
|
138
|
-
data: {
|
|
139
|
-
columns: {
|
|
140
|
-
id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
|
|
141
|
-
value: { codecId: 'unknown/type@1', nativeType: 'custom', nullable: false },
|
|
142
|
-
},
|
|
143
|
-
uniques: [],
|
|
144
|
-
indexes: [],
|
|
145
|
-
foreignKeys: [],
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const options: EmitStackInput = {
|
|
152
|
-
codecTypeImports: [],
|
|
153
|
-
operationTypeImports: [],
|
|
154
|
-
extensionIds: ['some-other-extension'],
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
158
|
-
expect(result.contractJson).toBeDefined();
|
|
159
|
-
expect(result.contractDts).toBeDefined();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('handles missing extensionPacks field', async () => {
|
|
163
|
-
const ir = createTestContract({
|
|
164
|
-
storage: {
|
|
165
|
-
tables: {
|
|
166
|
-
user: {
|
|
167
|
-
columns: {
|
|
168
|
-
id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
|
|
169
|
-
},
|
|
170
|
-
uniques: [],
|
|
171
|
-
indexes: [],
|
|
172
|
-
foreignKeys: [],
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const options: EmitStackInput = {
|
|
179
|
-
codecTypeImports: [],
|
|
180
|
-
operationTypeImports: [],
|
|
181
|
-
extensionIds: [],
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
185
|
-
expect(result.contractJson).toBeDefined();
|
|
186
|
-
expect(result.contractDts).toBeDefined();
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it('handles empty packs array', async () => {
|
|
190
|
-
const ir = createTestContract({
|
|
191
|
-
storage: {
|
|
192
|
-
tables: {
|
|
193
|
-
user: {
|
|
194
|
-
columns: {
|
|
195
|
-
id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false },
|
|
196
|
-
},
|
|
197
|
-
uniques: [],
|
|
198
|
-
indexes: [],
|
|
199
|
-
foreignKeys: [],
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const options: EmitStackInput = {
|
|
206
|
-
codecTypeImports: [],
|
|
207
|
-
operationTypeImports: [],
|
|
208
|
-
extensionIds: [],
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
212
|
-
expect(result.contractJson).toBeDefined();
|
|
213
|
-
expect(result.contractDts).toBeDefined();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it(
|
|
217
|
-
'omits sources from emitted contract artifact',
|
|
218
|
-
async () => {
|
|
219
|
-
const ir = createTestContract({
|
|
220
|
-
sources: {
|
|
221
|
-
schema: { sourceId: 'schema.prisma' },
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const options: EmitStackInput = {
|
|
226
|
-
codecTypeImports: [],
|
|
227
|
-
operationTypeImports: [],
|
|
228
|
-
extensionIds: [],
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
232
|
-
const contractJson = JSON.parse(result.contractJson) as Record<string, unknown>;
|
|
233
|
-
expect(contractJson).not.toHaveProperty('sources');
|
|
234
|
-
},
|
|
235
|
-
timeouts.typeScriptCompilation,
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
it('accepts meta keys when family validation allows them', async () => {
|
|
239
|
-
const ir = createTestContract({
|
|
240
|
-
meta: {
|
|
241
|
-
sourceId: 'schema.prisma',
|
|
242
|
-
schemaPath: '/tmp/schema.prisma',
|
|
243
|
-
source: 'psl',
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
const options: EmitStackInput = {
|
|
248
|
-
codecTypeImports: [],
|
|
249
|
-
operationTypeImports: [],
|
|
250
|
-
extensionIds: [],
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
await expect(emit(ir, options, mockSqlHook)).resolves.toMatchObject({
|
|
254
|
-
contractJson: expect.any(String),
|
|
255
|
-
contractDts: expect.any(String),
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('accepts canonical section keys when family validation allows them', async () => {
|
|
260
|
-
const ir = createTestContract({
|
|
261
|
-
storage: {
|
|
262
|
-
tables: {
|
|
263
|
-
user: {
|
|
264
|
-
columns: {
|
|
265
|
-
id: {
|
|
266
|
-
codecId: 'pg/int4@1',
|
|
267
|
-
nativeType: 'int4',
|
|
268
|
-
nullable: false,
|
|
269
|
-
sourceId: 'schema.prisma',
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
primaryKey: { columns: ['id'] },
|
|
273
|
-
uniques: [],
|
|
274
|
-
indexes: [],
|
|
275
|
-
foreignKeys: [],
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
} as unknown as Record<string, unknown>,
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
const options: EmitStackInput = {
|
|
282
|
-
codecTypeImports: [],
|
|
283
|
-
operationTypeImports: [],
|
|
284
|
-
extensionIds: [],
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
await expect(emit(ir, options, mockSqlHook)).resolves.toMatchObject({
|
|
288
|
-
contractJson: expect.any(String),
|
|
289
|
-
contractDts: expect.any(String),
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('emits contract even when extensionIds are not in contract.extensionPacks', async () => {
|
|
294
|
-
const ir = createTestContract({
|
|
295
|
-
storage: {
|
|
296
|
-
tables: {},
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
|
|
300
|
-
const mockHookNoTypeValidation = createMockSpi();
|
|
301
|
-
|
|
302
|
-
const options: EmitStackInput = {
|
|
303
|
-
codecTypeImports: [],
|
|
304
|
-
operationTypeImports: [],
|
|
305
|
-
extensionIds: ['postgres'],
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
const result = await emit(ir, options, mockHookNoTypeValidation);
|
|
309
|
-
expect(result.contractJson).toBeDefined();
|
|
310
|
-
expect(result.contractDts).toBeDefined();
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it('defaults codecTypeImports and operationTypeImports to empty arrays when omitted', async () => {
|
|
314
|
-
const ir = createTestContract({
|
|
315
|
-
storage: { tables: {} },
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
const options: EmitStackInput = {
|
|
319
|
-
extensionIds: [],
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
323
|
-
expect(result.contractDts).toContain('export type CodecTypes');
|
|
324
|
-
expect(result.contractDts).toContain('export type OperationTypes');
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it('passes parameterizedTypeImports and queryOperationTypeImports to generateContractDts', async () => {
|
|
328
|
-
const ir = createTestContract({
|
|
329
|
-
storage: { tables: {} },
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
const queryOperationTypeImports: TypesImportSpec[] = [
|
|
333
|
-
{ package: '@ext/query', named: 'QueryOperationTypes', alias: 'ExtQueryOpTypes' },
|
|
334
|
-
];
|
|
335
|
-
|
|
336
|
-
const options: EmitStackInput = {
|
|
337
|
-
codecTypeImports: [],
|
|
338
|
-
operationTypeImports: [],
|
|
339
|
-
extensionIds: [],
|
|
340
|
-
queryOperationTypeImports,
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
344
|
-
expect(result.contractDts).toContain("from '@ext/query'");
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it('emits execution clause when contract has execution section', async () => {
|
|
348
|
-
const ir = createTestContract({
|
|
349
|
-
storage: { tables: {} },
|
|
350
|
-
execution: {
|
|
351
|
-
executionHash: 'sha256:abc123',
|
|
352
|
-
operations: {},
|
|
353
|
-
},
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
const options: EmitStackInput = {
|
|
357
|
-
codecTypeImports: [],
|
|
358
|
-
operationTypeImports: [],
|
|
359
|
-
extensionIds: [],
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
const result = await emit(ir, options, mockSqlHook);
|
|
363
|
-
expect(result.contractDts).toContain('readonly execution:');
|
|
364
|
-
expect(result.contractDts).toContain('readonly executionHash: ExecutionHash');
|
|
365
|
-
expect(result.executionHash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
366
|
-
});
|
|
367
|
-
});
|
package/test/hashing.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { computeProfileHash, computeStorageHash } from '@prisma-next/contract/hashing';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
|
|
4
|
-
describe('hashing', () => {
|
|
5
|
-
it('computes storage hash', () => {
|
|
6
|
-
const hash = computeStorageHash({
|
|
7
|
-
targetFamily: 'sql',
|
|
8
|
-
target: 'postgres',
|
|
9
|
-
storage: { tables: {} },
|
|
10
|
-
});
|
|
11
|
-
expect(hash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('computes profile hash', () => {
|
|
15
|
-
const hash = computeProfileHash({
|
|
16
|
-
targetFamily: 'sql',
|
|
17
|
-
target: 'postgres',
|
|
18
|
-
capabilities: { postgres: { jsonAgg: true } },
|
|
19
|
-
});
|
|
20
|
-
expect(hash).toMatch(/^sha256:[a-f0-9]{64}$/);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('produces stable hashes for identical input', () => {
|
|
24
|
-
const args = {
|
|
25
|
-
targetFamily: 'sql',
|
|
26
|
-
target: 'postgres',
|
|
27
|
-
storage: { tables: {} },
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const hash1 = computeStorageHash(args);
|
|
31
|
-
const hash2 = computeStorageHash(args);
|
|
32
|
-
expect(hash1).toBe(hash2);
|
|
33
|
-
});
|
|
34
|
-
});
|
package/test/mock-spi.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { EmissionSpi } from '@prisma-next/framework-components/emission';
|
|
2
|
-
|
|
3
|
-
export function createMockSpi(overrides: Partial<EmissionSpi> = {}): EmissionSpi {
|
|
4
|
-
return {
|
|
5
|
-
id: 'sql',
|
|
6
|
-
generateStorageType: () =>
|
|
7
|
-
'{ readonly tables: Record<string, never>; readonly types: Record<string, never>; readonly storageHash: StorageHash }',
|
|
8
|
-
generateModelStorageType: () => 'Record<string, never>',
|
|
9
|
-
getFamilyImports: () => [
|
|
10
|
-
"import type { ContractWithTypeMaps, TypeMaps as TypeMapsType } from '@prisma-next/sql-contract/types';",
|
|
11
|
-
],
|
|
12
|
-
getFamilyTypeAliases: () => 'export type LaneCodecTypes = CodecTypes;',
|
|
13
|
-
getTypeMapsExpression: () => 'TypeMapsType<CodecTypes, OperationTypes>',
|
|
14
|
-
getContractWrapper: (base, tm) =>
|
|
15
|
-
`export type Contract = ContractWithTypeMaps<${base}, ${tm}>;`,
|
|
16
|
-
...overrides,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { isSafeTypeExpression } from '../src/type-expression-safety';
|
|
3
|
-
|
|
4
|
-
describe('isSafeTypeExpression', () => {
|
|
5
|
-
it('accepts normal type expressions', () => {
|
|
6
|
-
expect(isSafeTypeExpression('Char<36>')).toBe(true);
|
|
7
|
-
expect(isSafeTypeExpression('Vector<1536>')).toBe(true);
|
|
8
|
-
expect(isSafeTypeExpression("'USER' | 'ADMIN'")).toBe(true);
|
|
9
|
-
expect(isSafeTypeExpression('{ name: string; age: number }')).toBe(true);
|
|
10
|
-
expect(isSafeTypeExpression('Numeric<10, 2>')).toBe(true);
|
|
11
|
-
expect(isSafeTypeExpression('Timestamp<3>')).toBe(true);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('rejects import expressions', () => {
|
|
15
|
-
expect(isSafeTypeExpression('import("fs")')).toBe(false);
|
|
16
|
-
expect(isSafeTypeExpression('import ("fs")')).toBe(false);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('rejects require expressions', () => {
|
|
20
|
-
expect(isSafeTypeExpression('require("fs")')).toBe(false);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('rejects declare statements', () => {
|
|
24
|
-
expect(isSafeTypeExpression('declare module "foo"')).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('rejects export statements', () => {
|
|
28
|
-
expect(isSafeTypeExpression('export default 42')).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('rejects eval expressions', () => {
|
|
32
|
-
expect(isSafeTypeExpression('eval("code")')).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
});
|
package/test/utils.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { createContract } from '@prisma-next/contract/testing';
|
|
2
|
-
import type { Contract } from '@prisma-next/contract/types';
|
|
3
|
-
|
|
4
|
-
type TestContractOverrides = {
|
|
5
|
-
target?: string;
|
|
6
|
-
targetFamily?: string;
|
|
7
|
-
roots?: Record<string, string>;
|
|
8
|
-
models?: Record<string, unknown>;
|
|
9
|
-
storage?: Record<string, unknown>;
|
|
10
|
-
capabilities?: Record<string, Record<string, boolean>>;
|
|
11
|
-
extensionPacks?: Record<string, unknown>;
|
|
12
|
-
execution?: Record<string, unknown>;
|
|
13
|
-
meta?: Record<string, unknown>;
|
|
14
|
-
storageHash?: string;
|
|
15
|
-
schemaVersion?: string;
|
|
16
|
-
sources?: Record<string, unknown>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function createTestContract(overrides: TestContractOverrides = {}): Contract {
|
|
20
|
-
const { storageHash: _sh, schemaVersion: _sv, sources: _src, storage, ...rest } = overrides;
|
|
21
|
-
const cleanStorage = storage
|
|
22
|
-
? (() => {
|
|
23
|
-
const { storageHash: _innerSh, ...storageRest } = storage as Record<string, unknown>;
|
|
24
|
-
return storageRest;
|
|
25
|
-
})()
|
|
26
|
-
: undefined;
|
|
27
|
-
return createContract({
|
|
28
|
-
...rest,
|
|
29
|
-
...(cleanStorage ? { storage: cleanStorage } : {}),
|
|
30
|
-
} as Parameters<typeof createContract>[0]);
|
|
31
|
-
}
|