@prisma-next/config 0.0.1

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/src/types.ts ADDED
@@ -0,0 +1,316 @@
1
+ import type {
2
+ AdapterDescriptor,
3
+ AdapterInstance,
4
+ DriverDescriptor,
5
+ DriverInstance,
6
+ ExtensionDescriptor,
7
+ ExtensionInstance,
8
+ FamilyDescriptor,
9
+ FamilyInstance,
10
+ TargetBoundComponentDescriptor,
11
+ TargetDescriptor,
12
+ TargetInstance,
13
+ } from '@prisma-next/contract/framework-components';
14
+ import type { ContractIR } from '@prisma-next/contract/ir';
15
+ import type { ContractMarkerRecord, TargetFamilyHook } from '@prisma-next/contract/types';
16
+
17
+ export type SchemaNodeKind =
18
+ | 'root'
19
+ | 'namespace'
20
+ | 'collection'
21
+ | 'entity'
22
+ | 'field'
23
+ | 'index'
24
+ | 'extension';
25
+
26
+ export interface SchemaTreeNode {
27
+ readonly kind: SchemaNodeKind;
28
+ readonly id: string;
29
+ readonly label: string;
30
+ readonly meta?: Record<string, unknown>;
31
+ readonly children?: readonly SchemaTreeNode[];
32
+ }
33
+
34
+ export interface CoreSchemaView {
35
+ readonly root: SchemaTreeNode;
36
+ }
37
+
38
+ export interface ControlFamilyInstance<TFamilyId extends string, TSchemaIR = unknown>
39
+ extends FamilyInstance<TFamilyId> {
40
+ validateContractIR(contractJson: unknown): ContractIR;
41
+
42
+ verify(options: {
43
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
44
+ readonly contractIR: unknown;
45
+ readonly expectedTargetId: string;
46
+ readonly contractPath: string;
47
+ readonly configPath?: string;
48
+ }): Promise<VerifyDatabaseResult>;
49
+
50
+ schemaVerify(options: {
51
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
52
+ readonly contractIR: unknown;
53
+ readonly strict: boolean;
54
+ readonly contractPath: string;
55
+ readonly configPath?: string;
56
+ readonly frameworkComponents: ReadonlyArray<TargetBoundComponentDescriptor<TFamilyId, string>>;
57
+ }): Promise<VerifyDatabaseSchemaResult>;
58
+
59
+ sign(options: {
60
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
61
+ readonly contractIR: unknown;
62
+ readonly contractPath: string;
63
+ readonly configPath?: string;
64
+ }): Promise<SignDatabaseResult>;
65
+
66
+ readMarker(options: {
67
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
68
+ }): Promise<ContractMarkerRecord | null>;
69
+
70
+ introspect(options: {
71
+ readonly driver: ControlDriverInstance<TFamilyId, string>;
72
+ readonly contractIR?: unknown;
73
+ }): Promise<TSchemaIR>;
74
+
75
+ toSchemaView?(schema: TSchemaIR): CoreSchemaView;
76
+
77
+ emitContract(options: { readonly contractIR: unknown }): Promise<EmitContractResult>;
78
+ }
79
+
80
+ export interface ControlTargetInstance<TFamilyId extends string, TTargetId extends string>
81
+ extends TargetInstance<TFamilyId, TTargetId> {}
82
+
83
+ export interface ControlAdapterInstance<TFamilyId extends string, TTargetId extends string>
84
+ extends AdapterInstance<TFamilyId, TTargetId> {}
85
+
86
+ export interface ControlDriverInstance<TFamilyId extends string, TTargetId extends string>
87
+ extends DriverInstance<TFamilyId, TTargetId> {
88
+ query<Row = Record<string, unknown>>(
89
+ sql: string,
90
+ params?: readonly unknown[],
91
+ ): Promise<{ readonly rows: Row[] }>;
92
+ close(): Promise<void>;
93
+ }
94
+
95
+ export interface ControlExtensionInstance<TFamilyId extends string, TTargetId extends string>
96
+ extends ExtensionInstance<TFamilyId, TTargetId> {}
97
+
98
+ export interface ControlPlaneStack<TFamilyId extends string, TTargetId extends string> {
99
+ readonly target: ControlTargetDescriptor<TFamilyId, TTargetId>;
100
+ readonly adapter: ControlAdapterDescriptor<TFamilyId, TTargetId>;
101
+ readonly driver: ControlDriverDescriptor<TFamilyId, TTargetId> | undefined;
102
+ readonly extensionPacks: readonly ControlExtensionDescriptor<TFamilyId, TTargetId>[];
103
+ }
104
+
105
+ export interface ControlFamilyDescriptor<
106
+ TFamilyId extends string,
107
+ TFamilyInstance extends ControlFamilyInstance<TFamilyId> = ControlFamilyInstance<TFamilyId>,
108
+ > extends FamilyDescriptor<TFamilyId> {
109
+ readonly hook: TargetFamilyHook;
110
+ create<TTargetId extends string>(stack: ControlPlaneStack<TFamilyId, TTargetId>): TFamilyInstance;
111
+ }
112
+
113
+ export interface ControlTargetDescriptor<
114
+ TFamilyId extends string,
115
+ TTargetId extends string,
116
+ TTargetInstance extends ControlTargetInstance<TFamilyId, TTargetId> = ControlTargetInstance<
117
+ TFamilyId,
118
+ TTargetId
119
+ >,
120
+ > extends TargetDescriptor<TFamilyId, TTargetId> {
121
+ create(): TTargetInstance;
122
+ }
123
+
124
+ export interface ControlAdapterDescriptor<
125
+ TFamilyId extends string,
126
+ TTargetId extends string,
127
+ TAdapterInstance extends ControlAdapterInstance<TFamilyId, TTargetId> = ControlAdapterInstance<
128
+ TFamilyId,
129
+ TTargetId
130
+ >,
131
+ > extends AdapterDescriptor<TFamilyId, TTargetId> {
132
+ create(): TAdapterInstance;
133
+ }
134
+
135
+ export interface ControlDriverDescriptor<
136
+ TFamilyId extends string,
137
+ TTargetId extends string,
138
+ TDriverInstance extends ControlDriverInstance<TFamilyId, TTargetId> = ControlDriverInstance<
139
+ TFamilyId,
140
+ TTargetId
141
+ >,
142
+ TConnection = string,
143
+ > extends DriverDescriptor<TFamilyId, TTargetId> {
144
+ create(connection: TConnection): Promise<TDriverInstance>;
145
+ }
146
+
147
+ export interface ControlExtensionDescriptor<
148
+ TFamilyId extends string,
149
+ TTargetId extends string,
150
+ TExtensionInstance extends ControlExtensionInstance<
151
+ TFamilyId,
152
+ TTargetId
153
+ > = ControlExtensionInstance<TFamilyId, TTargetId>,
154
+ > extends ExtensionDescriptor<TFamilyId, TTargetId> {
155
+ create(): TExtensionInstance;
156
+ }
157
+
158
+ export interface OperationContext {
159
+ readonly contractPath?: string;
160
+ readonly configPath?: string;
161
+ readonly meta?: Readonly<Record<string, unknown>>;
162
+ }
163
+
164
+ export interface VerifyDatabaseResult {
165
+ readonly ok: boolean;
166
+ readonly code?: string;
167
+ readonly summary: string;
168
+ readonly contract: {
169
+ readonly storageHash: string;
170
+ readonly profileHash?: string;
171
+ };
172
+ readonly marker?: {
173
+ readonly storageHash?: string;
174
+ readonly profileHash?: string;
175
+ };
176
+ readonly target: {
177
+ readonly expected: string;
178
+ readonly actual?: string;
179
+ };
180
+ readonly missingCodecs?: readonly string[];
181
+ readonly codecCoverageSkipped?: boolean;
182
+ readonly meta?: {
183
+ readonly configPath?: string;
184
+ readonly contractPath: string;
185
+ };
186
+ readonly timings: {
187
+ readonly total: number;
188
+ };
189
+ }
190
+
191
+ export interface SchemaIssue {
192
+ readonly kind:
193
+ | 'missing_table'
194
+ | 'missing_column'
195
+ | 'extra_table'
196
+ | 'extra_column'
197
+ | 'extra_primary_key'
198
+ | 'extra_foreign_key'
199
+ | 'extra_unique_constraint'
200
+ | 'extra_index'
201
+ | 'type_mismatch'
202
+ | 'type_missing'
203
+ | 'type_values_mismatch'
204
+ | 'nullability_mismatch'
205
+ | 'primary_key_mismatch'
206
+ | 'foreign_key_mismatch'
207
+ | 'unique_constraint_mismatch'
208
+ | 'index_mismatch'
209
+ | 'extension_missing'
210
+ | 'default_missing'
211
+ | 'default_mismatch';
212
+ readonly table: string;
213
+ readonly column?: string;
214
+ readonly indexOrConstraint?: string;
215
+ readonly typeName?: string;
216
+ readonly expected?: string;
217
+ readonly actual?: string;
218
+ readonly message: string;
219
+ }
220
+
221
+ export interface SchemaVerificationNode {
222
+ readonly status: 'pass' | 'warn' | 'fail';
223
+ readonly kind: string;
224
+ readonly name: string;
225
+ readonly contractPath: string;
226
+ readonly code: string;
227
+ readonly message: string;
228
+ readonly expected: unknown;
229
+ readonly actual: unknown;
230
+ readonly children: readonly SchemaVerificationNode[];
231
+ }
232
+
233
+ export interface VerifyDatabaseSchemaResult {
234
+ readonly ok: boolean;
235
+ readonly code?: string;
236
+ readonly summary: string;
237
+ readonly contract: {
238
+ readonly storageHash: string;
239
+ readonly profileHash?: string;
240
+ };
241
+ readonly target: {
242
+ readonly expected: string;
243
+ readonly actual?: string;
244
+ };
245
+ readonly schema: {
246
+ readonly issues: readonly SchemaIssue[];
247
+ readonly root: SchemaVerificationNode;
248
+ readonly counts: {
249
+ readonly pass: number;
250
+ readonly warn: number;
251
+ readonly fail: number;
252
+ readonly totalNodes: number;
253
+ };
254
+ };
255
+ readonly meta?: {
256
+ readonly configPath?: string;
257
+ readonly contractPath?: string;
258
+ readonly strict: boolean;
259
+ };
260
+ readonly timings: {
261
+ readonly total: number;
262
+ };
263
+ }
264
+
265
+ export interface EmitContractResult {
266
+ readonly contractJson: string;
267
+ readonly contractDts: string;
268
+ readonly storageHash: string;
269
+ readonly executionHash?: string;
270
+ readonly profileHash: string;
271
+ }
272
+
273
+ export interface IntrospectSchemaResult<TSchemaIR> {
274
+ readonly ok: true;
275
+ readonly summary: string;
276
+ readonly target: {
277
+ readonly familyId: string;
278
+ readonly id: string;
279
+ };
280
+ readonly schema: TSchemaIR;
281
+ readonly meta?: {
282
+ readonly configPath?: string;
283
+ readonly dbUrl?: string;
284
+ };
285
+ readonly timings: {
286
+ readonly total: number;
287
+ };
288
+ }
289
+
290
+ export interface SignDatabaseResult {
291
+ readonly ok: boolean;
292
+ readonly summary: string;
293
+ readonly contract: {
294
+ readonly storageHash: string;
295
+ readonly profileHash?: string;
296
+ };
297
+ readonly target: {
298
+ readonly expected: string;
299
+ readonly actual?: string;
300
+ };
301
+ readonly marker: {
302
+ readonly created: boolean;
303
+ readonly updated: boolean;
304
+ readonly previous?: {
305
+ readonly storageHash?: string;
306
+ readonly profileHash?: string;
307
+ };
308
+ };
309
+ readonly meta?: {
310
+ readonly configPath?: string;
311
+ readonly contractPath: string;
312
+ };
313
+ readonly timings: {
314
+ readonly total: number;
315
+ };
316
+ }