@prisma/cli-init 0.2.0 → 0.4.0
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/{_-O567UZLT.js → _-WIN5AVS3.js} +3 -1
- package/dist/accelerate-GABM6I4V.js +221 -0
- package/dist/chunk-ASMCGOOW.js +1286 -0
- package/dist/{chunk-CMRCQXCF.js → chunk-SORRSNB3.js} +5 -6
- package/dist/chunk-YX4UTTNJ.js +44 -0
- package/dist/index.js +3114 -43
- package/dist/utility-W6LOZZIT.js +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,1286 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.8.3/node_modules/valibot/dist/index.js
|
|
4
|
+
var store;
|
|
5
|
+
// @__NO_SIDE_EFFECTS__
|
|
6
|
+
function getGlobalConfig(config2) {
|
|
7
|
+
return {
|
|
8
|
+
lang: config2?.lang ?? store?.lang,
|
|
9
|
+
message: config2?.message,
|
|
10
|
+
abortEarly: config2?.abortEarly ?? store?.abortEarly,
|
|
11
|
+
abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
var store2;
|
|
15
|
+
// @__NO_SIDE_EFFECTS__
|
|
16
|
+
function getGlobalMessage(lang) {
|
|
17
|
+
return store2?.get(lang);
|
|
18
|
+
}
|
|
19
|
+
var store3;
|
|
20
|
+
// @__NO_SIDE_EFFECTS__
|
|
21
|
+
function getSchemaMessage(lang) {
|
|
22
|
+
return store3?.get(lang);
|
|
23
|
+
}
|
|
24
|
+
var store4;
|
|
25
|
+
// @__NO_SIDE_EFFECTS__
|
|
26
|
+
function getSpecificMessage(reference, lang) {
|
|
27
|
+
return store4?.get(reference)?.get(lang);
|
|
28
|
+
}
|
|
29
|
+
// @__NO_SIDE_EFFECTS__
|
|
30
|
+
function _stringify(input) {
|
|
31
|
+
const type = typeof input;
|
|
32
|
+
if (type === "string") {
|
|
33
|
+
return `"${input}"`;
|
|
34
|
+
}
|
|
35
|
+
if (type === "number" || type === "bigint" || type === "boolean") {
|
|
36
|
+
return `${input}`;
|
|
37
|
+
}
|
|
38
|
+
if (type === "object" || type === "function") {
|
|
39
|
+
return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
|
|
40
|
+
}
|
|
41
|
+
return type;
|
|
42
|
+
}
|
|
43
|
+
function _addIssue(context, label, dataset, config2, other) {
|
|
44
|
+
const input = other && "input" in other ? other.input : dataset.value;
|
|
45
|
+
const expected = other?.expected ?? context.expects ?? null;
|
|
46
|
+
const received = other?.received ?? /* @__PURE__ */ _stringify(input);
|
|
47
|
+
const issue = {
|
|
48
|
+
kind: context.kind,
|
|
49
|
+
type: context.type,
|
|
50
|
+
input,
|
|
51
|
+
expected,
|
|
52
|
+
received,
|
|
53
|
+
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
|
|
54
|
+
requirement: context.requirement,
|
|
55
|
+
path: other?.path,
|
|
56
|
+
issues: other?.issues,
|
|
57
|
+
lang: config2.lang,
|
|
58
|
+
abortEarly: config2.abortEarly,
|
|
59
|
+
abortPipeEarly: config2.abortPipeEarly
|
|
60
|
+
};
|
|
61
|
+
const isSchema = context.kind === "schema";
|
|
62
|
+
const message2 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
|
|
63
|
+
if (message2 !== void 0) {
|
|
64
|
+
issue.message = typeof message2 === "function" ? (
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
message2(issue)
|
|
67
|
+
) : message2;
|
|
68
|
+
}
|
|
69
|
+
if (isSchema) {
|
|
70
|
+
dataset.typed = false;
|
|
71
|
+
}
|
|
72
|
+
if (dataset.issues) {
|
|
73
|
+
dataset.issues.push(issue);
|
|
74
|
+
} else {
|
|
75
|
+
dataset.issues = [issue];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// @__NO_SIDE_EFFECTS__
|
|
79
|
+
function _getStandardProps(context) {
|
|
80
|
+
return {
|
|
81
|
+
version: 1,
|
|
82
|
+
vendor: "valibot",
|
|
83
|
+
validate(value2) {
|
|
84
|
+
return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// @__NO_SIDE_EFFECTS__
|
|
89
|
+
function _isValidObjectKey(object2, key) {
|
|
90
|
+
return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
|
|
91
|
+
}
|
|
92
|
+
// @__NO_SIDE_EFFECTS__
|
|
93
|
+
function _joinExpects(values2, separator) {
|
|
94
|
+
const list = [...new Set(values2)];
|
|
95
|
+
if (list.length > 1) {
|
|
96
|
+
return `(${list.join(` ${separator} `)})`;
|
|
97
|
+
}
|
|
98
|
+
return list[0] ?? "never";
|
|
99
|
+
}
|
|
100
|
+
// @__NO_SIDE_EFFECTS__
|
|
101
|
+
function integer(message2) {
|
|
102
|
+
return {
|
|
103
|
+
kind: "validation",
|
|
104
|
+
type: "integer",
|
|
105
|
+
reference: integer,
|
|
106
|
+
async: false,
|
|
107
|
+
expects: null,
|
|
108
|
+
requirement: Number.isInteger,
|
|
109
|
+
message: message2,
|
|
110
|
+
"~run"(dataset, config2) {
|
|
111
|
+
if (dataset.typed && !this.requirement(dataset.value)) {
|
|
112
|
+
_addIssue(this, "integer", dataset, config2);
|
|
113
|
+
}
|
|
114
|
+
return dataset;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// @__NO_SIDE_EFFECTS__
|
|
119
|
+
function minLength(requirement, message2) {
|
|
120
|
+
return {
|
|
121
|
+
kind: "validation",
|
|
122
|
+
type: "min_length",
|
|
123
|
+
reference: minLength,
|
|
124
|
+
async: false,
|
|
125
|
+
expects: `>=${requirement}`,
|
|
126
|
+
requirement,
|
|
127
|
+
message: message2,
|
|
128
|
+
"~run"(dataset, config2) {
|
|
129
|
+
if (dataset.typed && dataset.value.length < this.requirement) {
|
|
130
|
+
_addIssue(this, "length", dataset, config2, {
|
|
131
|
+
received: `${dataset.value.length}`
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
return dataset;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// @__NO_SIDE_EFFECTS__
|
|
139
|
+
function minValue(requirement, message2) {
|
|
140
|
+
return {
|
|
141
|
+
kind: "validation",
|
|
142
|
+
type: "min_value",
|
|
143
|
+
reference: minValue,
|
|
144
|
+
async: false,
|
|
145
|
+
expects: `>=${requirement instanceof Date ? requirement.toJSON() : /* @__PURE__ */ _stringify(requirement)}`,
|
|
146
|
+
requirement,
|
|
147
|
+
message: message2,
|
|
148
|
+
"~run"(dataset, config2) {
|
|
149
|
+
if (dataset.typed && !(dataset.value >= this.requirement)) {
|
|
150
|
+
_addIssue(this, "value", dataset, config2, {
|
|
151
|
+
received: dataset.value instanceof Date ? dataset.value.toJSON() : /* @__PURE__ */ _stringify(dataset.value)
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return dataset;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// @__NO_SIDE_EFFECTS__
|
|
159
|
+
function parseJson(config2, message2) {
|
|
160
|
+
return {
|
|
161
|
+
kind: "transformation",
|
|
162
|
+
type: "parse_json",
|
|
163
|
+
reference: parseJson,
|
|
164
|
+
config: config2,
|
|
165
|
+
message: message2,
|
|
166
|
+
async: false,
|
|
167
|
+
"~run"(dataset, config3) {
|
|
168
|
+
try {
|
|
169
|
+
dataset.value = JSON.parse(dataset.value, this.config?.reviver);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error instanceof Error) {
|
|
172
|
+
_addIssue(this, "JSON", dataset, config3, {
|
|
173
|
+
received: `"${error.message}"`
|
|
174
|
+
});
|
|
175
|
+
dataset.typed = false;
|
|
176
|
+
} else {
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return dataset;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// @__NO_SIDE_EFFECTS__
|
|
185
|
+
function regex(requirement, message2) {
|
|
186
|
+
return {
|
|
187
|
+
kind: "validation",
|
|
188
|
+
type: "regex",
|
|
189
|
+
reference: regex,
|
|
190
|
+
async: false,
|
|
191
|
+
expects: `${requirement}`,
|
|
192
|
+
requirement,
|
|
193
|
+
message: message2,
|
|
194
|
+
"~run"(dataset, config2) {
|
|
195
|
+
if (dataset.typed && !this.requirement.test(dataset.value)) {
|
|
196
|
+
_addIssue(this, "format", dataset, config2);
|
|
197
|
+
}
|
|
198
|
+
return dataset;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
// @__NO_SIDE_EFFECTS__
|
|
203
|
+
function url(message2) {
|
|
204
|
+
return {
|
|
205
|
+
kind: "validation",
|
|
206
|
+
type: "url",
|
|
207
|
+
reference: url,
|
|
208
|
+
async: false,
|
|
209
|
+
expects: null,
|
|
210
|
+
requirement(input) {
|
|
211
|
+
try {
|
|
212
|
+
new URL(input);
|
|
213
|
+
return true;
|
|
214
|
+
} catch {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
message: message2,
|
|
219
|
+
"~run"(dataset, config2) {
|
|
220
|
+
if (dataset.typed && !this.requirement(dataset.value)) {
|
|
221
|
+
_addIssue(this, "URL", dataset, config2);
|
|
222
|
+
}
|
|
223
|
+
return dataset;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// @__NO_SIDE_EFFECTS__
|
|
228
|
+
function getFallback(schema, dataset, config2) {
|
|
229
|
+
return typeof schema.fallback === "function" ? (
|
|
230
|
+
// @ts-expect-error
|
|
231
|
+
schema.fallback(dataset, config2)
|
|
232
|
+
) : (
|
|
233
|
+
// @ts-expect-error
|
|
234
|
+
schema.fallback
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
// @__NO_SIDE_EFFECTS__
|
|
238
|
+
function getDefault(schema, dataset, config2) {
|
|
239
|
+
return typeof schema.default === "function" ? (
|
|
240
|
+
// @ts-expect-error
|
|
241
|
+
schema.default(dataset, config2)
|
|
242
|
+
) : (
|
|
243
|
+
// @ts-expect-error
|
|
244
|
+
schema.default
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
// @__NO_SIDE_EFFECTS__
|
|
248
|
+
function array(item, message2) {
|
|
249
|
+
return {
|
|
250
|
+
kind: "schema",
|
|
251
|
+
type: "array",
|
|
252
|
+
reference: array,
|
|
253
|
+
expects: "Array",
|
|
254
|
+
async: false,
|
|
255
|
+
item,
|
|
256
|
+
message: message2,
|
|
257
|
+
get "~standard"() {
|
|
258
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
259
|
+
},
|
|
260
|
+
"~run"(dataset, config2) {
|
|
261
|
+
const input = dataset.value;
|
|
262
|
+
if (Array.isArray(input)) {
|
|
263
|
+
dataset.typed = true;
|
|
264
|
+
dataset.value = [];
|
|
265
|
+
for (let key = 0; key < input.length; key++) {
|
|
266
|
+
const value2 = input[key];
|
|
267
|
+
const itemDataset = this.item["~run"]({ value: value2 }, config2);
|
|
268
|
+
if (itemDataset.issues) {
|
|
269
|
+
const pathItem = {
|
|
270
|
+
type: "array",
|
|
271
|
+
origin: "value",
|
|
272
|
+
input,
|
|
273
|
+
key,
|
|
274
|
+
value: value2
|
|
275
|
+
};
|
|
276
|
+
for (const issue of itemDataset.issues) {
|
|
277
|
+
if (issue.path) {
|
|
278
|
+
issue.path.unshift(pathItem);
|
|
279
|
+
} else {
|
|
280
|
+
issue.path = [pathItem];
|
|
281
|
+
}
|
|
282
|
+
dataset.issues?.push(issue);
|
|
283
|
+
}
|
|
284
|
+
if (!dataset.issues) {
|
|
285
|
+
dataset.issues = itemDataset.issues;
|
|
286
|
+
}
|
|
287
|
+
if (config2.abortEarly) {
|
|
288
|
+
dataset.typed = false;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!itemDataset.typed) {
|
|
293
|
+
dataset.typed = false;
|
|
294
|
+
}
|
|
295
|
+
dataset.value.push(itemDataset.value);
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
_addIssue(this, "type", dataset, config2);
|
|
299
|
+
}
|
|
300
|
+
return dataset;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
// @__NO_SIDE_EFFECTS__
|
|
305
|
+
function literal(literal_, message2) {
|
|
306
|
+
return {
|
|
307
|
+
kind: "schema",
|
|
308
|
+
type: "literal",
|
|
309
|
+
reference: literal,
|
|
310
|
+
expects: /* @__PURE__ */ _stringify(literal_),
|
|
311
|
+
async: false,
|
|
312
|
+
literal: literal_,
|
|
313
|
+
message: message2,
|
|
314
|
+
get "~standard"() {
|
|
315
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
316
|
+
},
|
|
317
|
+
"~run"(dataset, config2) {
|
|
318
|
+
if (dataset.value === this.literal) {
|
|
319
|
+
dataset.typed = true;
|
|
320
|
+
} else {
|
|
321
|
+
_addIssue(this, "type", dataset, config2);
|
|
322
|
+
}
|
|
323
|
+
return dataset;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
// @__NO_SIDE_EFFECTS__
|
|
328
|
+
function looseObject(entries2, message2) {
|
|
329
|
+
return {
|
|
330
|
+
kind: "schema",
|
|
331
|
+
type: "loose_object",
|
|
332
|
+
reference: looseObject,
|
|
333
|
+
expects: "Object",
|
|
334
|
+
async: false,
|
|
335
|
+
entries: entries2,
|
|
336
|
+
message: message2,
|
|
337
|
+
get "~standard"() {
|
|
338
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
339
|
+
},
|
|
340
|
+
"~run"(dataset, config2) {
|
|
341
|
+
const input = dataset.value;
|
|
342
|
+
if (input && typeof input === "object") {
|
|
343
|
+
dataset.typed = true;
|
|
344
|
+
dataset.value = {};
|
|
345
|
+
for (const key in this.entries) {
|
|
346
|
+
const valueSchema = this.entries[key];
|
|
347
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error
|
|
348
|
+
valueSchema.default !== void 0) {
|
|
349
|
+
const value2 = key in input ? (
|
|
350
|
+
// @ts-expect-error
|
|
351
|
+
input[key]
|
|
352
|
+
) : /* @__PURE__ */ getDefault(valueSchema);
|
|
353
|
+
const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
|
|
354
|
+
if (valueDataset.issues) {
|
|
355
|
+
const pathItem = {
|
|
356
|
+
type: "object",
|
|
357
|
+
origin: "value",
|
|
358
|
+
input,
|
|
359
|
+
key,
|
|
360
|
+
value: value2
|
|
361
|
+
};
|
|
362
|
+
for (const issue of valueDataset.issues) {
|
|
363
|
+
if (issue.path) {
|
|
364
|
+
issue.path.unshift(pathItem);
|
|
365
|
+
} else {
|
|
366
|
+
issue.path = [pathItem];
|
|
367
|
+
}
|
|
368
|
+
dataset.issues?.push(issue);
|
|
369
|
+
}
|
|
370
|
+
if (!dataset.issues) {
|
|
371
|
+
dataset.issues = valueDataset.issues;
|
|
372
|
+
}
|
|
373
|
+
if (config2.abortEarly) {
|
|
374
|
+
dataset.typed = false;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (!valueDataset.typed) {
|
|
379
|
+
dataset.typed = false;
|
|
380
|
+
}
|
|
381
|
+
dataset.value[key] = valueDataset.value;
|
|
382
|
+
} else if (valueSchema.fallback !== void 0) {
|
|
383
|
+
dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
384
|
+
} else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
385
|
+
_addIssue(this, "key", dataset, config2, {
|
|
386
|
+
input: void 0,
|
|
387
|
+
expected: `"${key}"`,
|
|
388
|
+
path: [
|
|
389
|
+
{
|
|
390
|
+
type: "object",
|
|
391
|
+
origin: "key",
|
|
392
|
+
input,
|
|
393
|
+
key,
|
|
394
|
+
// @ts-expect-error
|
|
395
|
+
value: input[key]
|
|
396
|
+
}
|
|
397
|
+
]
|
|
398
|
+
});
|
|
399
|
+
if (config2.abortEarly) {
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (!dataset.issues || !config2.abortEarly) {
|
|
405
|
+
for (const key in input) {
|
|
406
|
+
if (/* @__PURE__ */ _isValidObjectKey(input, key) && !(key in this.entries)) {
|
|
407
|
+
dataset.value[key] = input[key];
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
} else {
|
|
412
|
+
_addIssue(this, "type", dataset, config2);
|
|
413
|
+
}
|
|
414
|
+
return dataset;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
// @__NO_SIDE_EFFECTS__
|
|
419
|
+
function number(message2) {
|
|
420
|
+
return {
|
|
421
|
+
kind: "schema",
|
|
422
|
+
type: "number",
|
|
423
|
+
reference: number,
|
|
424
|
+
expects: "number",
|
|
425
|
+
async: false,
|
|
426
|
+
message: message2,
|
|
427
|
+
get "~standard"() {
|
|
428
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
429
|
+
},
|
|
430
|
+
"~run"(dataset, config2) {
|
|
431
|
+
if (typeof dataset.value === "number" && !isNaN(dataset.value)) {
|
|
432
|
+
dataset.typed = true;
|
|
433
|
+
} else {
|
|
434
|
+
_addIssue(this, "type", dataset, config2);
|
|
435
|
+
}
|
|
436
|
+
return dataset;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
// @__NO_SIDE_EFFECTS__
|
|
441
|
+
function object(entries2, message2) {
|
|
442
|
+
return {
|
|
443
|
+
kind: "schema",
|
|
444
|
+
type: "object",
|
|
445
|
+
reference: object,
|
|
446
|
+
expects: "Object",
|
|
447
|
+
async: false,
|
|
448
|
+
entries: entries2,
|
|
449
|
+
message: message2,
|
|
450
|
+
get "~standard"() {
|
|
451
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
452
|
+
},
|
|
453
|
+
"~run"(dataset, config2) {
|
|
454
|
+
const input = dataset.value;
|
|
455
|
+
if (input && typeof input === "object") {
|
|
456
|
+
dataset.typed = true;
|
|
457
|
+
dataset.value = {};
|
|
458
|
+
for (const key in this.entries) {
|
|
459
|
+
const valueSchema = this.entries[key];
|
|
460
|
+
if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && // @ts-expect-error
|
|
461
|
+
valueSchema.default !== void 0) {
|
|
462
|
+
const value2 = key in input ? (
|
|
463
|
+
// @ts-expect-error
|
|
464
|
+
input[key]
|
|
465
|
+
) : /* @__PURE__ */ getDefault(valueSchema);
|
|
466
|
+
const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
|
|
467
|
+
if (valueDataset.issues) {
|
|
468
|
+
const pathItem = {
|
|
469
|
+
type: "object",
|
|
470
|
+
origin: "value",
|
|
471
|
+
input,
|
|
472
|
+
key,
|
|
473
|
+
value: value2
|
|
474
|
+
};
|
|
475
|
+
for (const issue of valueDataset.issues) {
|
|
476
|
+
if (issue.path) {
|
|
477
|
+
issue.path.unshift(pathItem);
|
|
478
|
+
} else {
|
|
479
|
+
issue.path = [pathItem];
|
|
480
|
+
}
|
|
481
|
+
dataset.issues?.push(issue);
|
|
482
|
+
}
|
|
483
|
+
if (!dataset.issues) {
|
|
484
|
+
dataset.issues = valueDataset.issues;
|
|
485
|
+
}
|
|
486
|
+
if (config2.abortEarly) {
|
|
487
|
+
dataset.typed = false;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
if (!valueDataset.typed) {
|
|
492
|
+
dataset.typed = false;
|
|
493
|
+
}
|
|
494
|
+
dataset.value[key] = valueDataset.value;
|
|
495
|
+
} else if (valueSchema.fallback !== void 0) {
|
|
496
|
+
dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
|
|
497
|
+
} else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
|
|
498
|
+
_addIssue(this, "key", dataset, config2, {
|
|
499
|
+
input: void 0,
|
|
500
|
+
expected: `"${key}"`,
|
|
501
|
+
path: [
|
|
502
|
+
{
|
|
503
|
+
type: "object",
|
|
504
|
+
origin: "key",
|
|
505
|
+
input,
|
|
506
|
+
key,
|
|
507
|
+
// @ts-expect-error
|
|
508
|
+
value: input[key]
|
|
509
|
+
}
|
|
510
|
+
]
|
|
511
|
+
});
|
|
512
|
+
if (config2.abortEarly) {
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
} else {
|
|
518
|
+
_addIssue(this, "type", dataset, config2);
|
|
519
|
+
}
|
|
520
|
+
return dataset;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
// @__NO_SIDE_EFFECTS__
|
|
525
|
+
function optional(wrapped, default_) {
|
|
526
|
+
return {
|
|
527
|
+
kind: "schema",
|
|
528
|
+
type: "optional",
|
|
529
|
+
reference: optional,
|
|
530
|
+
expects: `(${wrapped.expects} | undefined)`,
|
|
531
|
+
async: false,
|
|
532
|
+
wrapped,
|
|
533
|
+
default: default_,
|
|
534
|
+
get "~standard"() {
|
|
535
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
536
|
+
},
|
|
537
|
+
"~run"(dataset, config2) {
|
|
538
|
+
if (dataset.value === void 0) {
|
|
539
|
+
if (this.default !== void 0) {
|
|
540
|
+
dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
|
|
541
|
+
}
|
|
542
|
+
if (dataset.value === void 0) {
|
|
543
|
+
dataset.typed = true;
|
|
544
|
+
return dataset;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return this.wrapped["~run"](dataset, config2);
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
// @__NO_SIDE_EFFECTS__
|
|
552
|
+
function string(message2) {
|
|
553
|
+
return {
|
|
554
|
+
kind: "schema",
|
|
555
|
+
type: "string",
|
|
556
|
+
reference: string,
|
|
557
|
+
expects: "string",
|
|
558
|
+
async: false,
|
|
559
|
+
message: message2,
|
|
560
|
+
get "~standard"() {
|
|
561
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
562
|
+
},
|
|
563
|
+
"~run"(dataset, config2) {
|
|
564
|
+
if (typeof dataset.value === "string") {
|
|
565
|
+
dataset.typed = true;
|
|
566
|
+
} else {
|
|
567
|
+
_addIssue(this, "type", dataset, config2);
|
|
568
|
+
}
|
|
569
|
+
return dataset;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
// @__NO_SIDE_EFFECTS__
|
|
574
|
+
function _subIssues(datasets) {
|
|
575
|
+
let issues;
|
|
576
|
+
if (datasets) {
|
|
577
|
+
for (const dataset of datasets) {
|
|
578
|
+
if (issues) {
|
|
579
|
+
issues.push(...dataset.issues);
|
|
580
|
+
} else {
|
|
581
|
+
issues = dataset.issues;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return issues;
|
|
586
|
+
}
|
|
587
|
+
// @__NO_SIDE_EFFECTS__
|
|
588
|
+
function union(options, message2) {
|
|
589
|
+
return {
|
|
590
|
+
kind: "schema",
|
|
591
|
+
type: "union",
|
|
592
|
+
reference: union,
|
|
593
|
+
expects: /* @__PURE__ */ _joinExpects(
|
|
594
|
+
options.map((option) => option.expects),
|
|
595
|
+
"|"
|
|
596
|
+
),
|
|
597
|
+
async: false,
|
|
598
|
+
options,
|
|
599
|
+
message: message2,
|
|
600
|
+
get "~standard"() {
|
|
601
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
602
|
+
},
|
|
603
|
+
"~run"(dataset, config2) {
|
|
604
|
+
let validDataset;
|
|
605
|
+
let typedDatasets;
|
|
606
|
+
let untypedDatasets;
|
|
607
|
+
for (const schema of this.options) {
|
|
608
|
+
const optionDataset = schema["~run"]({ value: dataset.value }, config2);
|
|
609
|
+
if (optionDataset.typed) {
|
|
610
|
+
if (optionDataset.issues) {
|
|
611
|
+
if (typedDatasets) {
|
|
612
|
+
typedDatasets.push(optionDataset);
|
|
613
|
+
} else {
|
|
614
|
+
typedDatasets = [optionDataset];
|
|
615
|
+
}
|
|
616
|
+
} else {
|
|
617
|
+
validDataset = optionDataset;
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
if (untypedDatasets) {
|
|
622
|
+
untypedDatasets.push(optionDataset);
|
|
623
|
+
} else {
|
|
624
|
+
untypedDatasets = [optionDataset];
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (validDataset) {
|
|
629
|
+
return validDataset;
|
|
630
|
+
}
|
|
631
|
+
if (typedDatasets) {
|
|
632
|
+
if (typedDatasets.length === 1) {
|
|
633
|
+
return typedDatasets[0];
|
|
634
|
+
}
|
|
635
|
+
_addIssue(this, "type", dataset, config2, {
|
|
636
|
+
issues: /* @__PURE__ */ _subIssues(typedDatasets)
|
|
637
|
+
});
|
|
638
|
+
dataset.typed = true;
|
|
639
|
+
} else if (untypedDatasets?.length === 1) {
|
|
640
|
+
return untypedDatasets[0];
|
|
641
|
+
} else {
|
|
642
|
+
_addIssue(this, "type", dataset, config2, {
|
|
643
|
+
issues: /* @__PURE__ */ _subIssues(untypedDatasets)
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
return dataset;
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
// @__NO_SIDE_EFFECTS__
|
|
651
|
+
function pipe(...pipe2) {
|
|
652
|
+
return {
|
|
653
|
+
...pipe2[0],
|
|
654
|
+
pipe: pipe2,
|
|
655
|
+
get "~standard"() {
|
|
656
|
+
return /* @__PURE__ */ _getStandardProps(this);
|
|
657
|
+
},
|
|
658
|
+
"~run"(dataset, config2) {
|
|
659
|
+
for (const item of pipe2) {
|
|
660
|
+
if (item.kind !== "metadata") {
|
|
661
|
+
if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
|
|
662
|
+
dataset.typed = false;
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) {
|
|
666
|
+
dataset = item["~run"](dataset, config2);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return dataset;
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
// @__NO_SIDE_EFFECTS__
|
|
675
|
+
function safeParse(schema, input, config2) {
|
|
676
|
+
const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
|
|
677
|
+
return {
|
|
678
|
+
typed: dataset.typed,
|
|
679
|
+
success: !dataset.issues,
|
|
680
|
+
output: dataset.value,
|
|
681
|
+
issues: dataset.issues
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// ../../dev/server/src/api-key.ts
|
|
686
|
+
var POSTGRES_PROTOCOL_REGEX = /^(postgres|postgresql):\/\//;
|
|
687
|
+
var decodedAPIKeySchema = pipe(
|
|
688
|
+
string(),
|
|
689
|
+
parseJson(),
|
|
690
|
+
object({
|
|
691
|
+
databaseUrl: pipe(string(), url(), regex(POSTGRES_PROTOCOL_REGEX)),
|
|
692
|
+
name: optional(pipe(string(), minLength(1))),
|
|
693
|
+
shadowDatabaseUrl: pipe(string(), url(), regex(POSTGRES_PROTOCOL_REGEX))
|
|
694
|
+
})
|
|
695
|
+
);
|
|
696
|
+
function encodeAPIKey(payload) {
|
|
697
|
+
return Buffer.from(
|
|
698
|
+
// we sort the keys to ensure consistent encoding
|
|
699
|
+
JSON.stringify(Object.fromEntries(Object.entries(payload).sort(([[key0], [key1]]) => key0.localeCompare(key1)))),
|
|
700
|
+
"utf8"
|
|
701
|
+
).toString("base64url");
|
|
702
|
+
}
|
|
703
|
+
function decodeAPIKey(apiKey) {
|
|
704
|
+
const serialized = Buffer.from(apiKey, "base64url").toString("utf8");
|
|
705
|
+
const { issues, output, success } = safeParse(decodedAPIKeySchema, serialized, { abortEarly: true });
|
|
706
|
+
if (!success) {
|
|
707
|
+
return [issues];
|
|
708
|
+
}
|
|
709
|
+
return [null, output];
|
|
710
|
+
}
|
|
711
|
+
var apiKeyValidator = async (value, ctx) => {
|
|
712
|
+
const { authorization } = value;
|
|
713
|
+
const { HTTPException } = await import("hono/http-exception");
|
|
714
|
+
if (!authorization) {
|
|
715
|
+
throw new HTTPException(401, { message: "Missing API Key" });
|
|
716
|
+
}
|
|
717
|
+
const [keyType, apiKey = "", extras] = authorization.split(" ");
|
|
718
|
+
if (keyType !== "Bearer" || extras) {
|
|
719
|
+
throw new HTTPException(401, { message: "Invalid API Key" });
|
|
720
|
+
}
|
|
721
|
+
const [issues, decodedAPIKey] = decodeAPIKey(apiKey);
|
|
722
|
+
if (issues) {
|
|
723
|
+
throw new HTTPException(401, { message: "Invalid API Key", cause: issues.join(", ") });
|
|
724
|
+
}
|
|
725
|
+
const { databaseUrl, name, shadowDatabaseUrl } = decodedAPIKey;
|
|
726
|
+
const { name: expectedName } = ctx.get("serverState");
|
|
727
|
+
if (!name) {
|
|
728
|
+
throw new HTTPException(401, {
|
|
729
|
+
message: `Wrong API Key; The Prisma Dev server running at port ${ctx.get("port")} requires an API Key from a newer version of \`prisma dev\`. Check the "${expectedName}" server's output for the updated \`DATABASE_URL\` value.`
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
if (name !== expectedName) {
|
|
733
|
+
throw new HTTPException(401, {
|
|
734
|
+
message: `Wrong API Key; The Prisma Dev server running at port ${ctx.get("port")} is named "${expectedName}", but the API Key is for "${name}"`
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
const { hostname, port } = new URL(databaseUrl);
|
|
738
|
+
const { port: expectedPort } = ctx.get("db");
|
|
739
|
+
const { hostname: shadowHostname, port: shadowPort } = new URL(shadowDatabaseUrl);
|
|
740
|
+
const expectedShadowPort = ctx.get("shadowDBPort");
|
|
741
|
+
if (hostname !== "localhost" || Number(port) !== expectedPort || shadowHostname !== "localhost" || Number(shadowPort) !== expectedShadowPort) {
|
|
742
|
+
throw new HTTPException(401, {
|
|
743
|
+
message: "Wrong API Key; Check your Prisma schema's `provider.url` value (probably defined in `.env`'s `DATABASE_URL` environment variable) is aligned with `prisma dev`'s output"
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
return { decodedAPIKey };
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// ../../dev/server/src/engine.ts
|
|
750
|
+
import { spawn } from "child_process";
|
|
751
|
+
import { once } from "events";
|
|
752
|
+
import { mkdir as mkdir2 } from "fs/promises";
|
|
753
|
+
import { join } from "path";
|
|
754
|
+
import { setTimeout } from "timers/promises";
|
|
755
|
+
|
|
756
|
+
// ../../common/stuff/with-resolvers.ts
|
|
757
|
+
function withResolvers(options) {
|
|
758
|
+
let succeed, fail;
|
|
759
|
+
const promise = new Promise((resolve, reject) => {
|
|
760
|
+
succeed = resolve;
|
|
761
|
+
fail = reject;
|
|
762
|
+
});
|
|
763
|
+
let failOnce = (reason) => {
|
|
764
|
+
failOnce = succeedOnce = null;
|
|
765
|
+
fail(reason);
|
|
766
|
+
options?.onRejected?.(reason);
|
|
767
|
+
options?.onFulfilled?.();
|
|
768
|
+
};
|
|
769
|
+
let succeedOnce = (value) => {
|
|
770
|
+
succeedOnce = failOnce = null;
|
|
771
|
+
succeed(value);
|
|
772
|
+
options?.onResolved?.(value);
|
|
773
|
+
options?.onFulfilled?.();
|
|
774
|
+
};
|
|
775
|
+
return {
|
|
776
|
+
isFulfilled: () => succeedOnce === failOnce,
|
|
777
|
+
promise,
|
|
778
|
+
reject: (reason) => failOnce?.(reason),
|
|
779
|
+
resolve: (value) => succeedOnce?.(value)
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
// ../../node_modules/.pnpm/std-env@3.9.0/node_modules/std-env/dist/index.mjs
|
|
784
|
+
var r = /* @__PURE__ */ Object.create(null);
|
|
785
|
+
var i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis);
|
|
786
|
+
var o = new Proxy(r, { get(e, s) {
|
|
787
|
+
return i()[s] ?? r[s];
|
|
788
|
+
}, has(e, s) {
|
|
789
|
+
const E = i();
|
|
790
|
+
return s in E || s in r;
|
|
791
|
+
}, set(e, s, E) {
|
|
792
|
+
const B = i(true);
|
|
793
|
+
return B[s] = E, true;
|
|
794
|
+
}, deleteProperty(e, s) {
|
|
795
|
+
if (!s)
|
|
796
|
+
return false;
|
|
797
|
+
const E = i(true);
|
|
798
|
+
return delete E[s], true;
|
|
799
|
+
}, ownKeys() {
|
|
800
|
+
const e = i(true);
|
|
801
|
+
return Object.keys(e);
|
|
802
|
+
} });
|
|
803
|
+
var t = typeof process < "u" && process.env && process.env.NODE_ENV || "";
|
|
804
|
+
var f = [["APPVEYOR"], ["AWS_AMPLIFY", "AWS_APP_ID", { ci: true }], ["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"], ["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"], ["APPCIRCLE", "AC_APPCIRCLE"], ["BAMBOO", "bamboo_planKey"], ["BITBUCKET", "BITBUCKET_COMMIT"], ["BITRISE", "BITRISE_IO"], ["BUDDY", "BUDDY_WORKSPACE_ID"], ["BUILDKITE"], ["CIRCLE", "CIRCLECI"], ["CIRRUS", "CIRRUS_CI"], ["CLOUDFLARE_PAGES", "CF_PAGES", { ci: true }], ["CLOUDFLARE_WORKERS", "WORKERS_CI", { ci: true }], ["CODEBUILD", "CODEBUILD_BUILD_ARN"], ["CODEFRESH", "CF_BUILD_ID"], ["DRONE"], ["DRONE", "DRONE_BUILD_EVENT"], ["DSARI"], ["GITHUB_ACTIONS"], ["GITLAB", "GITLAB_CI"], ["GITLAB", "CI_MERGE_REQUEST_ID"], ["GOCD", "GO_PIPELINE_LABEL"], ["LAYERCI"], ["HUDSON", "HUDSON_URL"], ["JENKINS", "JENKINS_URL"], ["MAGNUM"], ["NETLIFY"], ["NETLIFY", "NETLIFY_LOCAL", { ci: false }], ["NEVERCODE"], ["RENDER"], ["SAIL", "SAILCI"], ["SEMAPHORE"], ["SCREWDRIVER"], ["SHIPPABLE"], ["SOLANO", "TDDIUM"], ["STRIDER"], ["TEAMCITY", "TEAMCITY_VERSION"], ["TRAVIS"], ["VERCEL", "NOW_BUILDER"], ["VERCEL", "VERCEL", { ci: false }], ["VERCEL", "VERCEL_ENV", { ci: false }], ["APPCENTER", "APPCENTER_BUILD_ID"], ["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }], ["CODESANDBOX", "CODESANDBOX_HOST", { ci: false }], ["STACKBLITZ"], ["STORMKIT"], ["CLEAVR"], ["ZEABUR"], ["CODESPHERE", "CODESPHERE_APP_ID", { ci: true }], ["RAILWAY", "RAILWAY_PROJECT_ID"], ["RAILWAY", "RAILWAY_SERVICE_ID"], ["DENO-DEPLOY", "DENO_DEPLOYMENT_ID"], ["FIREBASE_APP_HOSTING", "FIREBASE_APP_HOSTING", { ci: true }]];
|
|
805
|
+
function b() {
|
|
806
|
+
if (globalThis.process?.env)
|
|
807
|
+
for (const e of f) {
|
|
808
|
+
const s = e[1] || e[0];
|
|
809
|
+
if (globalThis.process?.env[s])
|
|
810
|
+
return { name: e[0].toLowerCase(), ...e[2] };
|
|
811
|
+
}
|
|
812
|
+
return globalThis.process?.env?.SHELL === "/bin/jsh" && globalThis.process?.versions?.webcontainer ? { name: "stackblitz", ci: false } : { name: "", ci: false };
|
|
813
|
+
}
|
|
814
|
+
var l = b();
|
|
815
|
+
var p = l.name;
|
|
816
|
+
function n(e) {
|
|
817
|
+
return e ? e !== "false" : false;
|
|
818
|
+
}
|
|
819
|
+
var I = globalThis.process?.platform || "";
|
|
820
|
+
var T = n(o.CI) || l.ci !== false;
|
|
821
|
+
var R = n(globalThis.process?.stdout && globalThis.process?.stdout.isTTY);
|
|
822
|
+
var d = n(o.DEBUG);
|
|
823
|
+
var a = t === "test" || n(o.TEST);
|
|
824
|
+
var v = n(o.MINIMAL) || T || a || !R;
|
|
825
|
+
var A = /^win/i.test(I);
|
|
826
|
+
var M = /^linux/i.test(I);
|
|
827
|
+
var m = /^darwin/i.test(I);
|
|
828
|
+
var Y = !n(o.NO_COLOR) && (n(o.FORCE_COLOR) || (R || A) && o.TERM !== "dumb" || T);
|
|
829
|
+
var C = (globalThis.process?.versions?.node || "").replace(/^v/, "") || null;
|
|
830
|
+
var V = Number(C?.split(".")[0]) || null;
|
|
831
|
+
var W = globalThis.process || /* @__PURE__ */ Object.create(null);
|
|
832
|
+
var _ = { versions: {} };
|
|
833
|
+
var y = new Proxy(W, { get(e, s) {
|
|
834
|
+
if (s === "env")
|
|
835
|
+
return o;
|
|
836
|
+
if (s in e)
|
|
837
|
+
return e[s];
|
|
838
|
+
if (s in _)
|
|
839
|
+
return _[s];
|
|
840
|
+
} });
|
|
841
|
+
var O = globalThis.process?.release?.name === "node";
|
|
842
|
+
var c = !!globalThis.Bun || !!globalThis.process?.versions?.bun;
|
|
843
|
+
var D = !!globalThis.Deno;
|
|
844
|
+
var L = !!globalThis.fastly;
|
|
845
|
+
var S = !!globalThis.Netlify;
|
|
846
|
+
var u = !!globalThis.EdgeRuntime;
|
|
847
|
+
var N = globalThis.navigator?.userAgent === "Cloudflare-Workers";
|
|
848
|
+
var F = [[S, "netlify"], [u, "edge-light"], [N, "workerd"], [L, "fastly"], [D, "deno"], [c, "bun"], [O, "node"]];
|
|
849
|
+
function G() {
|
|
850
|
+
const e = F.find((s) => s[0]);
|
|
851
|
+
if (e)
|
|
852
|
+
return { name: e[1] };
|
|
853
|
+
}
|
|
854
|
+
var P = G();
|
|
855
|
+
var K = P?.name || "";
|
|
856
|
+
|
|
857
|
+
// ../../dev/server/src/filesystem.ts
|
|
858
|
+
import { createWriteStream, WriteStream } from "fs";
|
|
859
|
+
import { access, chmod, constants, mkdir, readdir, readFile, writeFile } from "fs/promises";
|
|
860
|
+
import { promisify } from "util";
|
|
861
|
+
import { unzip } from "zlib";
|
|
862
|
+
|
|
863
|
+
// ../../node_modules/.pnpm/env-paths@3.0.0/node_modules/env-paths/index.js
|
|
864
|
+
import path from "path";
|
|
865
|
+
import os from "os";
|
|
866
|
+
import process2 from "process";
|
|
867
|
+
var homedir = os.homedir();
|
|
868
|
+
var tmpdir = os.tmpdir();
|
|
869
|
+
var { env } = process2;
|
|
870
|
+
var macos = (name) => {
|
|
871
|
+
const library = path.join(homedir, "Library");
|
|
872
|
+
return {
|
|
873
|
+
data: path.join(library, "Application Support", name),
|
|
874
|
+
config: path.join(library, "Preferences", name),
|
|
875
|
+
cache: path.join(library, "Caches", name),
|
|
876
|
+
log: path.join(library, "Logs", name),
|
|
877
|
+
temp: path.join(tmpdir, name)
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
var windows = (name) => {
|
|
881
|
+
const appData = env.APPDATA || path.join(homedir, "AppData", "Roaming");
|
|
882
|
+
const localAppData = env.LOCALAPPDATA || path.join(homedir, "AppData", "Local");
|
|
883
|
+
return {
|
|
884
|
+
// Data/config/cache/log are invented by me as Windows isn't opinionated about this
|
|
885
|
+
data: path.join(localAppData, name, "Data"),
|
|
886
|
+
config: path.join(appData, name, "Config"),
|
|
887
|
+
cache: path.join(localAppData, name, "Cache"),
|
|
888
|
+
log: path.join(localAppData, name, "Log"),
|
|
889
|
+
temp: path.join(tmpdir, name)
|
|
890
|
+
};
|
|
891
|
+
};
|
|
892
|
+
var linux = (name) => {
|
|
893
|
+
const username = path.basename(homedir);
|
|
894
|
+
return {
|
|
895
|
+
data: path.join(env.XDG_DATA_HOME || path.join(homedir, ".local", "share"), name),
|
|
896
|
+
config: path.join(env.XDG_CONFIG_HOME || path.join(homedir, ".config"), name),
|
|
897
|
+
cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, ".cache"), name),
|
|
898
|
+
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
|
|
899
|
+
log: path.join(env.XDG_STATE_HOME || path.join(homedir, ".local", "state"), name),
|
|
900
|
+
temp: path.join(tmpdir, username, name)
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
function envPaths(name, { suffix = "nodejs" } = {}) {
|
|
904
|
+
if (typeof name !== "string") {
|
|
905
|
+
throw new TypeError(`Expected a string, got ${typeof name}`);
|
|
906
|
+
}
|
|
907
|
+
if (suffix) {
|
|
908
|
+
name += `-${suffix}`;
|
|
909
|
+
}
|
|
910
|
+
if (process2.platform === "darwin") {
|
|
911
|
+
return macos(name);
|
|
912
|
+
}
|
|
913
|
+
if (process2.platform === "win32") {
|
|
914
|
+
return windows(name);
|
|
915
|
+
}
|
|
916
|
+
return linux(name);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
// ../../dev/server/src/filesystem.ts
|
|
920
|
+
var GLOBAL_DIR_ROOT_PATH = envPaths("prisma-dev");
|
|
921
|
+
var unzipAsync = promisify(unzip);
|
|
922
|
+
function getEngineCacheDirPath(version, commitHash) {
|
|
923
|
+
return `${GLOBAL_DIR_ROOT_PATH.cache}/engine/${version}/${commitHash}`;
|
|
924
|
+
}
|
|
925
|
+
function getDataDirPath(name) {
|
|
926
|
+
return `${GLOBAL_DIR_ROOT_PATH.data}/${name}`;
|
|
927
|
+
}
|
|
928
|
+
async function checkFileExists(filePath) {
|
|
929
|
+
try {
|
|
930
|
+
await access(filePath, constants.F_OK);
|
|
931
|
+
return true;
|
|
932
|
+
} catch (error) {
|
|
933
|
+
if (isFileNotFoundError(error)) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
throw error;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
async function writeBinaryFile(buffer, path2) {
|
|
940
|
+
const result = await unzipAsync(buffer);
|
|
941
|
+
await writeFile(path2, result);
|
|
942
|
+
await chmod(path2, "755");
|
|
943
|
+
}
|
|
944
|
+
async function streamAsTextTo(file, path2) {
|
|
945
|
+
await file.stream().pipeTo(WriteStream.toWeb(createWriteStream(path2, { encoding: "utf-8" })));
|
|
946
|
+
}
|
|
947
|
+
function isFileNotFoundError(error) {
|
|
948
|
+
return error != null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
949
|
+
}
|
|
950
|
+
async function readFileAsText(path2) {
|
|
951
|
+
try {
|
|
952
|
+
return await readFile(path2, { encoding: "utf-8" });
|
|
953
|
+
} catch (error) {
|
|
954
|
+
if (isFileNotFoundError(error)) {
|
|
955
|
+
return null;
|
|
956
|
+
}
|
|
957
|
+
throw error;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
async function ensureDirectory(path2) {
|
|
961
|
+
await mkdir(path2, { recursive: true });
|
|
962
|
+
}
|
|
963
|
+
async function readDirectoryNames(path2) {
|
|
964
|
+
try {
|
|
965
|
+
const dirents = await readdir(path2, { withFileTypes: true });
|
|
966
|
+
return dirents.reduce((names, dirent) => {
|
|
967
|
+
if (dirent.isDirectory() && !dirent.name.startsWith(".")) {
|
|
968
|
+
names.push(dirent.name);
|
|
969
|
+
}
|
|
970
|
+
return names;
|
|
971
|
+
}, []);
|
|
972
|
+
} catch (error) {
|
|
973
|
+
if (isFileNotFoundError(error)) {
|
|
974
|
+
return [];
|
|
975
|
+
}
|
|
976
|
+
throw error;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// ../../dev/server/src/engine.ts
|
|
981
|
+
var {
|
|
982
|
+
PRISMA_DEV_FORCE_ENGINE_BINARY_DOWNLOAD,
|
|
983
|
+
PRISMA_DEV_FORCE_ENGINE_BINARY_PATH,
|
|
984
|
+
PRISMA_DEV_FORCE_NETWORK_DELAY_MS
|
|
985
|
+
} = y.env;
|
|
986
|
+
var Engine = class _Engine {
|
|
987
|
+
static #enginesBySchemaAndClientVersion = /* @__PURE__ */ new Map();
|
|
988
|
+
#options;
|
|
989
|
+
#session;
|
|
990
|
+
constructor(options) {
|
|
991
|
+
this.#options = options;
|
|
992
|
+
this.#session = null;
|
|
993
|
+
}
|
|
994
|
+
static async get(options) {
|
|
995
|
+
const { debug } = options;
|
|
996
|
+
const engineId = `${options.schemaHash}:${options.clientVersion}`;
|
|
997
|
+
try {
|
|
998
|
+
const engine = _Engine.#enginesBySchemaAndClientVersion.get(engineId);
|
|
999
|
+
if (engine) {
|
|
1000
|
+
return engine;
|
|
1001
|
+
}
|
|
1002
|
+
const newEngine = new _Engine(options);
|
|
1003
|
+
_Engine.#enginesBySchemaAndClientVersion.set(engineId, newEngine);
|
|
1004
|
+
if (debug) {
|
|
1005
|
+
console.debug("[Query Engine] starting...", options);
|
|
1006
|
+
}
|
|
1007
|
+
await newEngine.start();
|
|
1008
|
+
if (debug) {
|
|
1009
|
+
console.debug("[Query Engine] started!");
|
|
1010
|
+
}
|
|
1011
|
+
return newEngine;
|
|
1012
|
+
} finally {
|
|
1013
|
+
void _Engine.stopAll(engineId);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
static async stopAll(excludingEngineId) {
|
|
1017
|
+
const results = await Promise.allSettled(
|
|
1018
|
+
Array.from(_Engine.#enginesBySchemaAndClientVersion.entries()).filter(([engineId]) => engineId !== excludingEngineId).map(async ([engineId, engine]) => {
|
|
1019
|
+
try {
|
|
1020
|
+
await engine.stop();
|
|
1021
|
+
} finally {
|
|
1022
|
+
_Engine.#enginesBySchemaAndClientVersion.delete(engineId);
|
|
1023
|
+
}
|
|
1024
|
+
})
|
|
1025
|
+
);
|
|
1026
|
+
const errors = results.filter((result) => result.status === "rejected").map((result) => result.reason);
|
|
1027
|
+
if (errors.length > 0) {
|
|
1028
|
+
throw new AggregateError(errors, "Failed to stop engines");
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
async commitTransaction(transactionId, headers) {
|
|
1032
|
+
return await this.#commitOrRollbackTransaction(transactionId, headers, "commit");
|
|
1033
|
+
}
|
|
1034
|
+
async request(body, headers) {
|
|
1035
|
+
const { url: url2 } = await this.start();
|
|
1036
|
+
const sanitizedHeaders = this.#sanitizeHeaders(headers);
|
|
1037
|
+
const response = await fetch(url2, {
|
|
1038
|
+
body: typeof body === "string" ? body : JSON.stringify(body),
|
|
1039
|
+
headers: { ...sanitizedHeaders, "Content-Type": "application/json" },
|
|
1040
|
+
method: "POST"
|
|
1041
|
+
});
|
|
1042
|
+
if (!response.ok) {
|
|
1043
|
+
throw await EngineHttpError.fromResponse(response);
|
|
1044
|
+
}
|
|
1045
|
+
return await response.text();
|
|
1046
|
+
}
|
|
1047
|
+
async rollbackTransaction(transactionId, headers) {
|
|
1048
|
+
return await this.#commitOrRollbackTransaction(transactionId, headers, "rollback");
|
|
1049
|
+
}
|
|
1050
|
+
async startTransaction(options, headers) {
|
|
1051
|
+
const { url: url2 } = await this.start();
|
|
1052
|
+
const sanitizedHeaders = this.#sanitizeHeaders(headers);
|
|
1053
|
+
const response = await fetch(`${url2}/transaction/start`, {
|
|
1054
|
+
body: JSON.stringify(options),
|
|
1055
|
+
headers: { ...sanitizedHeaders, "Content-Type": "application/json" },
|
|
1056
|
+
method: "POST"
|
|
1057
|
+
});
|
|
1058
|
+
if (!response.ok) {
|
|
1059
|
+
throw await EngineHttpError.fromResponse(response);
|
|
1060
|
+
}
|
|
1061
|
+
return await response.json();
|
|
1062
|
+
}
|
|
1063
|
+
async start() {
|
|
1064
|
+
if (this.#session != null) {
|
|
1065
|
+
return await this.#session;
|
|
1066
|
+
}
|
|
1067
|
+
const { promise: session, reject, resolve } = withResolvers();
|
|
1068
|
+
this.#session = session;
|
|
1069
|
+
const engineBinaryPath = PRISMA_DEV_FORCE_ENGINE_BINARY_PATH || await this.#getEngineBinaryPath();
|
|
1070
|
+
if (this.#options.debug) {
|
|
1071
|
+
console.debug("[Query Engine] spinning up at path...", engineBinaryPath);
|
|
1072
|
+
}
|
|
1073
|
+
const { proxySignals } = await import("foreground-child/proxy-signals");
|
|
1074
|
+
const childProcess = spawn(
|
|
1075
|
+
engineBinaryPath,
|
|
1076
|
+
["--enable-raw-queries", "--enable-telemetry-in-response", "--port", "0"],
|
|
1077
|
+
{
|
|
1078
|
+
env: {
|
|
1079
|
+
LOG_QUERIES: "y",
|
|
1080
|
+
PRISMA_DML: this.#options.base64Schema,
|
|
1081
|
+
QE_LOG_LEVEL: "TRACE",
|
|
1082
|
+
RUST_BACKTRACE: "1",
|
|
1083
|
+
RUST_LOG: "info"
|
|
1084
|
+
},
|
|
1085
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1086
|
+
windowsHide: true
|
|
1087
|
+
}
|
|
1088
|
+
);
|
|
1089
|
+
proxySignals(childProcess);
|
|
1090
|
+
childProcess.stderr.setEncoding("utf8");
|
|
1091
|
+
childProcess.stdout.setEncoding("utf8");
|
|
1092
|
+
const waitForListening = (data) => {
|
|
1093
|
+
const readyMessage = data.split("\n").find((line) => line.includes("Started query engine http server"));
|
|
1094
|
+
if (!readyMessage) {
|
|
1095
|
+
return;
|
|
1096
|
+
}
|
|
1097
|
+
childProcess.stdout.removeListener("data", waitForListening);
|
|
1098
|
+
const { fields } = JSON.parse(readyMessage);
|
|
1099
|
+
if (fields == null) {
|
|
1100
|
+
return reject(new Error(`Unexpected data during initialization, "fields" are missing: ${data}`));
|
|
1101
|
+
}
|
|
1102
|
+
const { ip, port } = fields;
|
|
1103
|
+
if (ip == null || port == null) {
|
|
1104
|
+
return reject(
|
|
1105
|
+
new Error(
|
|
1106
|
+
`This version of query-engine is not compatible with minippg, "ip" and "port" are missing in the startup log entry.
|
|
1107
|
+
Received data: ${data}`
|
|
1108
|
+
)
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1111
|
+
resolve({ childProcess, url: `http://${ip}:${port}` });
|
|
1112
|
+
};
|
|
1113
|
+
const errorListener = (error) => {
|
|
1114
|
+
this.#session = null;
|
|
1115
|
+
reject(new EngineStartError(String(error)));
|
|
1116
|
+
childProcess.removeListener("exit", exitListener);
|
|
1117
|
+
childProcess.kill();
|
|
1118
|
+
};
|
|
1119
|
+
childProcess.once("error", errorListener);
|
|
1120
|
+
const exitListener = (code, signal) => {
|
|
1121
|
+
this.#session = null;
|
|
1122
|
+
reject(new EngineStartError(`Query Engine exited with code ${code} and signal ${signal}`));
|
|
1123
|
+
};
|
|
1124
|
+
childProcess.once("exit", exitListener);
|
|
1125
|
+
childProcess.stdout.on("data", waitForListening);
|
|
1126
|
+
if (this.#options.debug) {
|
|
1127
|
+
childProcess.stderr.on("data", console.error.bind(console, "[Query Engine]"));
|
|
1128
|
+
childProcess.stdout.on("data", console.debug.bind(console, "[Query Engine]"));
|
|
1129
|
+
}
|
|
1130
|
+
return await this.#session;
|
|
1131
|
+
}
|
|
1132
|
+
async stop() {
|
|
1133
|
+
if (this.#session == null) {
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
const { childProcess } = await this.#session;
|
|
1137
|
+
const isStillRunning = childProcess.exitCode == null && childProcess.signalCode == null;
|
|
1138
|
+
if (!isStillRunning) {
|
|
1139
|
+
return;
|
|
1140
|
+
}
|
|
1141
|
+
this.#session = null;
|
|
1142
|
+
childProcess.kill();
|
|
1143
|
+
await once(childProcess, "exit");
|
|
1144
|
+
}
|
|
1145
|
+
async #getEngineBinaryPath() {
|
|
1146
|
+
if (this.#options.debug) {
|
|
1147
|
+
console.debug(`[Query Engine] getting engine commit hash...`);
|
|
1148
|
+
}
|
|
1149
|
+
const commitHash = await this.#getEngineCommitHash();
|
|
1150
|
+
if (this.#options.debug) {
|
|
1151
|
+
console.debug("[Query Engine] got engine commit hash", commitHash);
|
|
1152
|
+
}
|
|
1153
|
+
const cacheDirectoryPath = getEngineCacheDirPath(this.#options.clientVersion, commitHash);
|
|
1154
|
+
if (this.#options.debug) {
|
|
1155
|
+
console.debug("[Query Engine] cache directory path", cacheDirectoryPath);
|
|
1156
|
+
}
|
|
1157
|
+
await mkdir2(cacheDirectoryPath, { recursive: true });
|
|
1158
|
+
const { platform } = this.#options.platform;
|
|
1159
|
+
const extension = platform === "windows" ? ".exe" : "";
|
|
1160
|
+
const engineBinaryPath = join(cacheDirectoryPath, `query-engine-${platform}${extension}`);
|
|
1161
|
+
if (this.#options.debug) {
|
|
1162
|
+
console.debug("[Query Engine] binary path", engineBinaryPath);
|
|
1163
|
+
}
|
|
1164
|
+
const shouldDownloadEngine = PRISMA_DEV_FORCE_ENGINE_BINARY_DOWNLOAD === "1" || await checkFileExists(engineBinaryPath) === false;
|
|
1165
|
+
if (shouldDownloadEngine) {
|
|
1166
|
+
await this.#downloadEngineBinary({ commitHash, extension, engineBinaryPath });
|
|
1167
|
+
}
|
|
1168
|
+
return engineBinaryPath;
|
|
1169
|
+
}
|
|
1170
|
+
async #getEngineCommitHash() {
|
|
1171
|
+
const response = await fetch(`https://registry.npmjs.org/@prisma/client/${this.#options.clientVersion}`);
|
|
1172
|
+
if (!response.ok) {
|
|
1173
|
+
throw new Error(`Couldn't fetch package.json from npm registry, status code: ${response.status}`);
|
|
1174
|
+
}
|
|
1175
|
+
const pkg = await response.json();
|
|
1176
|
+
const enginesVersion = pkg.devDependencies?.["@prisma/engines-version"];
|
|
1177
|
+
if (!enginesVersion) {
|
|
1178
|
+
throw new Error(`Couldn't find engines version in package.json`);
|
|
1179
|
+
}
|
|
1180
|
+
const commitHash = enginesVersion.split(".").at(-1);
|
|
1181
|
+
if (!commitHash) {
|
|
1182
|
+
throw new Error(`Couldn't find commit hash in engines version`);
|
|
1183
|
+
}
|
|
1184
|
+
return commitHash;
|
|
1185
|
+
}
|
|
1186
|
+
async #downloadEngineBinary(options) {
|
|
1187
|
+
const { commitHash, extension, engineBinaryPath } = options;
|
|
1188
|
+
const { binaryTarget } = this.#options.platform;
|
|
1189
|
+
const url2 = `https://binaries.prisma.sh/all_commits/${commitHash}/${binaryTarget}/query-engine${extension}.gz`;
|
|
1190
|
+
if (this.#options.debug) {
|
|
1191
|
+
console.debug("[Query Engine] downloading engine from url", url2);
|
|
1192
|
+
}
|
|
1193
|
+
const response = await fetch(url2);
|
|
1194
|
+
if (!response.ok) {
|
|
1195
|
+
throw new Error(`Couldn't download engine. URL: ${url2}, status code: ${response.status}`);
|
|
1196
|
+
}
|
|
1197
|
+
if (PRISMA_DEV_FORCE_NETWORK_DELAY_MS) {
|
|
1198
|
+
await setTimeout(Number(PRISMA_DEV_FORCE_NETWORK_DELAY_MS));
|
|
1199
|
+
}
|
|
1200
|
+
await writeBinaryFile(await response.arrayBuffer(), engineBinaryPath);
|
|
1201
|
+
if (this.#options.debug) {
|
|
1202
|
+
console.debug("[Query Engine] downloaded and saved at", engineBinaryPath);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
#sanitizeHeaders(headers) {
|
|
1206
|
+
const sanitizedHeaders = {};
|
|
1207
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
1208
|
+
if (value != null) {
|
|
1209
|
+
sanitizedHeaders[key] = value;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
return sanitizedHeaders;
|
|
1213
|
+
}
|
|
1214
|
+
async #commitOrRollbackTransaction(transactionId, headers, action) {
|
|
1215
|
+
const { url: url2 } = await this.#session;
|
|
1216
|
+
const sanitizedHeaders = this.#sanitizeHeaders(headers);
|
|
1217
|
+
const response = await fetch(`${url2}/transaction/${transactionId}/${action}`, {
|
|
1218
|
+
headers: { ...sanitizedHeaders, "Content-Type": "application/json" },
|
|
1219
|
+
method: "POST"
|
|
1220
|
+
});
|
|
1221
|
+
if (!response.ok) {
|
|
1222
|
+
throw await EngineHttpError.fromResponse(response);
|
|
1223
|
+
}
|
|
1224
|
+
try {
|
|
1225
|
+
return await response.json();
|
|
1226
|
+
} catch {
|
|
1227
|
+
return {};
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
function handleEngineError(error, ctx) {
|
|
1232
|
+
console.error(error);
|
|
1233
|
+
if (error instanceof EngineStartError) {
|
|
1234
|
+
return ctx.json({ EngineNotStarted: { reason: { EngineStartupError: { logs: [], msg: error.message } } } }, 500);
|
|
1235
|
+
}
|
|
1236
|
+
if (error instanceof EngineHttpError) {
|
|
1237
|
+
return ctx.text(error.responseBody, error.statusCode);
|
|
1238
|
+
}
|
|
1239
|
+
return ctx.body(null, 500);
|
|
1240
|
+
}
|
|
1241
|
+
var EngineStartError = class extends Error {
|
|
1242
|
+
name = "EngineStartError";
|
|
1243
|
+
};
|
|
1244
|
+
var EngineHttpError = class _EngineHttpError extends Error {
|
|
1245
|
+
constructor(action, statusCode, responseBody) {
|
|
1246
|
+
super(`${action}: Query Engine response status ${statusCode}, body: ${responseBody}`);
|
|
1247
|
+
this.action = action;
|
|
1248
|
+
this.statusCode = statusCode;
|
|
1249
|
+
this.responseBody = responseBody;
|
|
1250
|
+
}
|
|
1251
|
+
name = "EngineHttpError";
|
|
1252
|
+
static async fromResponse(response) {
|
|
1253
|
+
const url2 = new URL(response.url);
|
|
1254
|
+
const responseBody = await response.text();
|
|
1255
|
+
return new _EngineHttpError(url2.pathname, response.status, responseBody);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
|
|
1259
|
+
export {
|
|
1260
|
+
integer,
|
|
1261
|
+
minLength,
|
|
1262
|
+
minValue,
|
|
1263
|
+
parseJson,
|
|
1264
|
+
url,
|
|
1265
|
+
array,
|
|
1266
|
+
literal,
|
|
1267
|
+
looseObject,
|
|
1268
|
+
number,
|
|
1269
|
+
object,
|
|
1270
|
+
optional,
|
|
1271
|
+
string,
|
|
1272
|
+
union,
|
|
1273
|
+
pipe,
|
|
1274
|
+
safeParse,
|
|
1275
|
+
encodeAPIKey,
|
|
1276
|
+
apiKeyValidator,
|
|
1277
|
+
getDataDirPath,
|
|
1278
|
+
streamAsTextTo,
|
|
1279
|
+
readFileAsText,
|
|
1280
|
+
ensureDirectory,
|
|
1281
|
+
readDirectoryNames,
|
|
1282
|
+
withResolvers,
|
|
1283
|
+
y,
|
|
1284
|
+
Engine,
|
|
1285
|
+
handleEngineError
|
|
1286
|
+
};
|