@prisma/migrate 6.5.0-dev.1 → 6.5.0-dev.3

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.
Files changed (102) hide show
  1. package/dist/CLI.js +3 -4
  2. package/dist/Migrate.js +6 -7
  3. package/dist/SchemaEngine.js +6 -7
  4. package/dist/bin.js +116 -146
  5. package/dist/{chunk-WOOPRG54.js → chunk-255BRND3.js} +7 -14
  6. package/dist/{chunk-75EIHNAH.js → chunk-2NMFKGXM.js} +5 -6
  7. package/dist/chunk-3WC4XD74.js +98 -0
  8. package/dist/chunk-4EV2RVXY.js +226 -0
  9. package/dist/{chunk-YWWOSXMY.js → chunk-4JQIX6O7.js} +7 -15
  10. package/dist/{chunk-M5YNQ2NP.js → chunk-6DFJIBJX.js} +5 -12
  11. package/dist/{chunk-SGCF5OHF.js → chunk-7CQBDP4H.js} +6 -13
  12. package/dist/{chunk-7IT2ZO3D.js → chunk-AHJ2N6BJ.js} +3 -9
  13. package/dist/chunk-C2PR6JQR.js +266 -0
  14. package/dist/chunk-CTPONE6G.js +65 -0
  15. package/dist/{chunk-DUCG3NRP.js → chunk-D74DU52C.js} +633 -806
  16. package/dist/{chunk-UVNSK22K.js → chunk-DDHPSYC4.js} +122 -130
  17. package/dist/{chunk-CUDKD32S.js → chunk-DIAO4W7O.js} +11 -17
  18. package/dist/{chunk-XJQP3B4W.js → chunk-DJMFXNR4.js} +7 -15
  19. package/dist/{chunk-V5LEZ5BX.js → chunk-DY3QUOB7.js} +634 -807
  20. package/dist/{chunk-YD7GG4WS.js → chunk-FRTPDRF2.js} +66 -74
  21. package/dist/chunk-HIFVDK2U.js +96 -0
  22. package/dist/chunk-I4EY55DC.js +195 -0
  23. package/dist/{chunk-WLJHGKMK.js → chunk-IHDN3L3R.js} +7 -8
  24. package/dist/{chunk-INC2OACE.js → chunk-JFKDSUIE.js} +3 -9
  25. package/dist/{chunk-V7DE6JTG.js → chunk-JZ75RIMZ.js} +3 -9
  26. package/dist/{chunk-AAATUOV6.js → chunk-L6KOIJJ5.js} +53 -59
  27. package/dist/{chunk-GN5BY5N2.js → chunk-LGYRZ6CV.js} +4 -10
  28. package/dist/chunk-LVLRGTYH.js +148 -0
  29. package/dist/{chunk-CQQQ436N.js → chunk-MATFO4ZW.js} +186 -200
  30. package/dist/{chunk-IFCV5MY4.js → chunk-OCQGHQED.js} +5 -11
  31. package/dist/chunk-ORL3LJOT.js +470 -0
  32. package/dist/{chunk-Q7ACZDDT.js → chunk-QOPTDDIH.js} +5 -12
  33. package/dist/chunk-QTAIWPLH.js +78 -0
  34. package/dist/{chunk-35LAJN5S.js → chunk-RP2N6UXA.js} +23 -29
  35. package/dist/chunk-RQFGRXJI.js +174 -0
  36. package/dist/{chunk-QBK5XTJE.js → chunk-RR6BKMNO.js} +3 -9
  37. package/dist/{chunk-ILJRJJ3S.js → chunk-RTGQXNX6.js} +3 -9
  38. package/dist/chunk-SKRR5WT4.js +76 -0
  39. package/dist/chunk-TM3ETZES.js +153 -0
  40. package/dist/{chunk-KPUNMK5W.js → chunk-TWPTG4XS.js} +5 -12
  41. package/dist/{chunk-6QFE3AWR.js → chunk-UP6FVCDK.js} +6 -13
  42. package/dist/{chunk-YKUZUAXA.js → chunk-V3ZMNXZC.js} +16 -23
  43. package/dist/chunk-WLPX3672.js +365 -0
  44. package/dist/chunk-WNH2ACJS.js +122 -0
  45. package/dist/chunk-XSNOKQTD.js +347 -0
  46. package/dist/{chunk-X6XGFLEF.js → chunk-YZVZCC3I.js} +25 -30
  47. package/dist/commands/DbCommand.js +3 -4
  48. package/dist/commands/DbDrop.js +9 -9
  49. package/dist/commands/DbExecute.js +7 -8
  50. package/dist/commands/DbPull.js +18 -19
  51. package/dist/commands/DbPush.js +12 -13
  52. package/dist/commands/DbSeed.js +4 -5
  53. package/dist/commands/MigrateCommand.js +3 -4
  54. package/dist/commands/MigrateDeploy.js +13 -14
  55. package/dist/commands/MigrateDev.js +17 -18
  56. package/dist/commands/MigrateDiff.js +8 -9
  57. package/dist/commands/MigrateReset.js +15 -16
  58. package/dist/commands/MigrateResolve.js +11 -12
  59. package/dist/commands/MigrateStatus.js +11 -12
  60. package/dist/index.js +60 -77
  61. package/dist/{multipart-parser-73VM3J4A.js → multipart-parser-NDLECNMN.js} +527 -561
  62. package/dist/utils/byline.js +5 -6
  63. package/dist/utils/captureStdout.js +2 -3
  64. package/dist/utils/countModelsAndTypes.js +2 -3
  65. package/dist/utils/ensureDatabaseExists.js +8 -9
  66. package/dist/utils/errors.js +8 -9
  67. package/dist/utils/flagErrors.js +5 -5
  68. package/dist/utils/getDatabaseVersionSafe.js +6 -7
  69. package/dist/utils/getSchemaPathAndPrint.js +4 -5
  70. package/dist/utils/handleEvaluateDataloss.js +3 -4
  71. package/dist/utils/introspectSql.js +6 -6
  72. package/dist/utils/isSchemaEmpty.js +2 -3
  73. package/dist/utils/printDatasource.js +3 -4
  74. package/dist/utils/printDatasources.js +3 -4
  75. package/dist/utils/printFiles.js +5 -6
  76. package/dist/utils/printIntrospectedSchema.js +2 -3
  77. package/dist/utils/printMigrationId.js +4 -5
  78. package/dist/utils/promptForMigrationName.js +2 -3
  79. package/dist/utils/removeSchemaFiles.js +2 -3
  80. package/dist/utils/replaceOrAddDatasource.js +2 -3
  81. package/dist/utils/replaceOrAddDatasource.test.js +7 -8
  82. package/dist/utils/saveSchemaFiles.js +2 -3
  83. package/dist/utils/seed.js +6 -7
  84. package/dist/utils/spinner.js +2 -3
  85. package/dist/utils/unixSocket.js +2 -3
  86. package/dist/views/handleViewsIO.js +2 -3
  87. package/package.json +6 -6
  88. package/dist/chunk-26XQQ4AG.js +0 -386
  89. package/dist/chunk-2RSEPJFX.js +0 -165
  90. package/dist/chunk-4B2LXK4R.js +0 -207
  91. package/dist/chunk-4UJBOCZJ.js +0 -130
  92. package/dist/chunk-5HZLCY6X.js +0 -161
  93. package/dist/chunk-6TE2RIPN.js +0 -80
  94. package/dist/chunk-7S3Q4MCN.js +0 -480
  95. package/dist/chunk-AOX7CJAS.js +0 -234
  96. package/dist/chunk-FF3526PX.js +0 -279
  97. package/dist/chunk-FUSFURVP.js +0 -86
  98. package/dist/chunk-GCTCQLOF.js +0 -365
  99. package/dist/chunk-K44VNAFW.js +0 -189
  100. package/dist/chunk-O4BT6W33.js +0 -104
  101. package/dist/chunk-TKAGMA5K.js +0 -72
  102. package/dist/chunk-U374EXYQ.js +0 -106
@@ -1,480 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_7S3Q4MCN_exports = {};
30
- __export(chunk_7S3Q4MCN_exports, {
31
- EngineError: () => EngineError,
32
- SchemaEngine: () => SchemaEngine,
33
- init_SchemaEngine: () => init_SchemaEngine
34
- });
35
- module.exports = __toCommonJS(chunk_7S3Q4MCN_exports);
36
- var import_chunk_CQQQ436N = require("./chunk-CQQQ436N.js");
37
- var import_chunk_AAATUOV6 = require("./chunk-AAATUOV6.js");
38
- var import_chunk_6TE2RIPN = require("./chunk-6TE2RIPN.js");
39
- var import_chunk_WWAWV7DQ = require("./chunk-WWAWV7DQ.js");
40
- var import_node_path = __toESM(require("node:path"));
41
- var import_debug = __toESM(require("@prisma/debug"));
42
- var import_internals = require("@prisma/internals");
43
- var import_child_process = require("child_process");
44
- function serializePanic(log) {
45
- return `${(0, import_chunk_6TE2RIPN.red)((0, import_chunk_6TE2RIPN.bold)("Error in Schema engine.\nReason: "))}${log}
46
- `;
47
- }
48
- var debugRpc, debugStderr, debugStdin, EngineError, messageId, SchemaEngine;
49
- var init_SchemaEngine = (0, import_chunk_WWAWV7DQ.__esm)({
50
- "src/SchemaEngine.ts"() {
51
- (0, import_chunk_6TE2RIPN.init_colors)();
52
- (0, import_chunk_AAATUOV6.init_byline)();
53
- (0, import_chunk_CQQQ436N.init_handleViewsIO)();
54
- debugRpc = (0, import_debug.default)("prisma:schemaEngine:rpc");
55
- debugStderr = (0, import_debug.default)("prisma:schemaEngine:stderr");
56
- debugStdin = (0, import_debug.default)("prisma:schemaEngine:stdin");
57
- EngineError = class extends Error {
58
- constructor(message, code) {
59
- super(message);
60
- this.code = code;
61
- }
62
- };
63
- (0, import_internals.setClassName)(EngineError, "EngineError");
64
- messageId = 1;
65
- SchemaEngine = class {
66
- constructor({ debug = false, schemaPath, enabledPreviewFeatures }) {
67
- this.listeners = {};
68
- this.messages = [];
69
- this.lastError = null;
70
- this.isRunning = false;
71
- this.schemaPath = schemaPath;
72
- if (debug) {
73
- import_debug.default.enable("SchemaEngine*");
74
- }
75
- this.debug = debug;
76
- this.enabledPreviewFeatures = enabledPreviewFeatures;
77
- }
78
- //
79
- // See JSON-RPC API definition:
80
- // https://prisma.github.io/prisma-engines/doc/migration_core/json_rpc/index.html
81
- //
82
- /**
83
- * Apply the migrations from the migrations directory to the database.
84
- * This is the command behind prisma migrate deploy.
85
- */
86
- applyMigrations(args) {
87
- return this.runCommand(this.getRPCPayload("applyMigrations", args));
88
- }
89
- /**
90
- * Create the logical database from the Prisma schema.
91
- */
92
- createDatabase(args) {
93
- return this.runCommand(this.getRPCPayload("createDatabase", args));
94
- }
95
- /**
96
- * Create the next migration in the migrations history.
97
- * If draft is false and there are no unexecutable steps, it will also apply the newly created migration.
98
- * Note: This will use the shadow database on the connectors where we need one.
99
- */
100
- createMigration(args) {
101
- return this.runCommand(this.getRPCPayload("createMigration", args));
102
- }
103
- /**
104
- * Execute a database script directly on the specified live database.
105
- * Note that this may not be defined on all connectors.
106
- */
107
- dbExecute(args) {
108
- return this.runCommand(this.getRPCPayload("dbExecute", args));
109
- }
110
- /**
111
- * Make the Schema engine panic. Only useful to test client error handling.
112
- */
113
- debugPanic() {
114
- return this.runCommand(this.getRPCPayload("debugPanic", void 0));
115
- }
116
- /**
117
- * The method called at the beginning of migrate dev to decide the course of action,
118
- * based on the current state of the workspace.
119
- * It acts as a wrapper around diagnoseMigrationHistory.
120
- * Its role is to interpret the diagnostic output,
121
- * and translate it to a concrete action to be performed by the CLI.
122
- */
123
- devDiagnostic(args) {
124
- return this.runCommand(this.getRPCPayload("devDiagnostic", args));
125
- }
126
- /**
127
- * Read the contents of the migrations directory and the migrations table, and returns their relative statuses.
128
- * At this stage, the Schema engine only reads,
129
- * it does not write to the database nor the migrations directory, nor does it use a shadow database.
130
- */
131
- diagnoseMigrationHistory(args) {
132
- return this.runCommand(this.getRPCPayload("diagnoseMigrationHistory", args));
133
- }
134
- /**
135
- * Make sure the Schema engine can connect to the database from the Prisma schema.
136
- */
137
- ensureConnectionValidity(args) {
138
- return this.runCommand(this.getRPCPayload("ensureConnectionValidity", args));
139
- }
140
- /**
141
- * Development command for migrations.
142
- * Evaluate the data loss induced by the next migration the engine would generate on the main database.
143
- */
144
- evaluateDataLoss(args) {
145
- return this.runCommand(this.getRPCPayload("evaluateDataLoss", args));
146
- }
147
- getDatabaseDescription(schema) {
148
- return this.runCommand(this.getRPCPayload("getDatabaseDescription", { schema }));
149
- }
150
- /**
151
- * Get the database version for error reporting.
152
- * If no argument is given, the version of the database associated to the Prisma schema provided
153
- * in the constructor will be returned.
154
- */
155
- getDatabaseVersion(args) {
156
- return this.runCommand(this.getRPCPayload("getDatabaseVersion", args));
157
- }
158
- /**
159
- * Given a Prisma schema, introspect the database definitions and update the schema with the results.
160
- * `compositeTypeDepth` is optional, and only required for MongoDB.
161
- */
162
- async introspect({
163
- schema,
164
- force = false,
165
- baseDirectoryPath,
166
- compositeTypeDepth = -1,
167
- // cannot be undefined
168
- namespaces
169
- }) {
170
- this.latestSchema = schema;
171
- try {
172
- const introspectResult = await this.runCommand(
173
- this.getRPCPayload("introspect", { schema, force, compositeTypeDepth, namespaces, baseDirectoryPath })
174
- );
175
- const { views } = introspectResult;
176
- if (views) {
177
- const schemaPath = this.schemaPath ?? import_node_path.default.join(process.cwd(), "prisma");
178
- await (0, import_chunk_CQQQ436N.handleViewsIO)({ views, schemaPath });
179
- }
180
- return introspectResult;
181
- } finally {
182
- this.stop();
183
- }
184
- }
185
- /**
186
- * Compares two databases schemas from two arbitrary sources,
187
- * and display the difference as either a human-readable summary,
188
- * or an executable script that can be passed to dbExecute.
189
- * Connection to a shadow database is only necessary when either the from or the to params is a migrations directory.
190
- * Diffs have a direction. Which source is from and which is to matters.
191
- * The resulting diff should be thought of as a migration from the schema in `args.from` to the schema in `args.to`.
192
- * By default, we output a human-readable diff. If you want an executable script, pass the "script": true param.
193
- */
194
- migrateDiff(args) {
195
- return this.runCommand(this.getRPCPayload("diff", args));
196
- }
197
- /**
198
- * List the names of the migrations in the migrations directory.
199
- */
200
- listMigrationDirectories(args) {
201
- return this.runCommand(this.getRPCPayload("listMigrationDirectories", args));
202
- }
203
- /**
204
- * Mark a migration as applied in the migrations table.
205
- * There are two possible outcomes:
206
- * - The migration is already in the table, but in a failed state. In this case, we will mark it as rolled back, then create a new entry.
207
- * - The migration is not in the table. We will create a new entry in the migrations table. The started_at and finished_at will be the same.
208
- * If it is already applied, we return a user-facing error.
209
- */
210
- markMigrationApplied(args) {
211
- return this.runCommand(this.getRPCPayload("markMigrationApplied", args));
212
- }
213
- /**
214
- * Mark an existing failed migration as rolled back in the migrations table. It will still be there, but ignored for all purposes except as audit trail.
215
- */
216
- markMigrationRolledBack(args) {
217
- return this.runCommand(this.getRPCPayload("markMigrationRolledBack", args));
218
- }
219
- /**
220
- * Try to make the database empty: no data and no schema.
221
- * On most connectors, this is implemented by dropping and recreating the database.
222
- * If that fails (most likely because of insufficient permissions),
223
- * the engine attempts a “best effort reset” by inspecting the contents of the database and dropping them individually.
224
- * Drop and recreate the database. The migrations will not be applied, as it would overlap with applyMigrations.
225
- */
226
- reset() {
227
- return this.runCommand(this.getRPCPayload("reset", void 0));
228
- }
229
- /**
230
- * The command behind db push.
231
- */
232
- schemaPush(args) {
233
- return this.runCommand(this.getRPCPayload("schemaPush", args));
234
- }
235
- /**
236
- * SQL introspection that powers TypedSQL feature
237
- * @param args
238
- * @returns
239
- */
240
- introspectSql(args) {
241
- return this.runCommand(this.getRPCPayload("introspectSql", args));
242
- }
243
- stop() {
244
- if (this.child) {
245
- this.child.kill();
246
- this.isRunning = false;
247
- }
248
- }
249
- rejectAll(err) {
250
- Object.entries(this.listeners).map(([id, listener]) => {
251
- listener(null, err);
252
- delete this.listeners[id];
253
- });
254
- }
255
- registerCallback(id, callback) {
256
- this.listeners[id] = callback;
257
- }
258
- handleResponse(response) {
259
- let result;
260
- try {
261
- result = JSON.parse(response);
262
- } catch (e) {
263
- console.error(`Could not parse Schema engine response: ${response.slice(0, 200)}. Error: ${e.message}`);
264
- }
265
- if (result) {
266
- if (result.id && (result.result !== void 0 || result.error !== void 0)) {
267
- if (!this.listeners[result.id]) {
268
- console.error(`Got result for unknown id ${result.id}`);
269
- }
270
- if (this.listeners[result.id]) {
271
- this.listeners[result.id](result);
272
- delete this.listeners[result.id];
273
- }
274
- } else if (result.method) {
275
- if (result.id !== void 0) {
276
- if (result.method === "print" && result.params?.content !== void 0) {
277
- process.stdout.write(result.params.content + "\n");
278
- const response2 = {
279
- id: result.id,
280
- jsonrpc: "2.0",
281
- result: {}
282
- };
283
- this.child.stdin.write(JSON.stringify(response2) + "\n");
284
- }
285
- }
286
- }
287
- }
288
- }
289
- init() {
290
- if (!this.initPromise) {
291
- this.initPromise = this.internalInit();
292
- }
293
- return this.initPromise;
294
- }
295
- internalInit() {
296
- return new Promise(async (resolve, reject) => {
297
- try {
298
- const { PWD, ...processEnv } = process.env;
299
- const binaryPath = await (0, import_internals.resolveBinary)(import_internals.BinaryType.SchemaEngineBinary);
300
- debugRpc("starting Schema engine with binary: " + binaryPath);
301
- const args = [];
302
- let projectDir = process.cwd();
303
- if (this.schemaPath) {
304
- const schema = await (0, import_internals.getSchema)(this.schemaPath);
305
- const config = await (0, import_internals.getConfig)({ datamodel: schema });
306
- projectDir = (0, import_internals.getMigrateConfigDir)(config, this.schemaPath);
307
- const schemaArgs = schema.flatMap(([path2]) => ["-d", path2]);
308
- args.push(...schemaArgs);
309
- }
310
- if (this.enabledPreviewFeatures && Array.isArray(this.enabledPreviewFeatures) && this.enabledPreviewFeatures.length > 0) {
311
- args.push(...["--enabled-preview-features", this.enabledPreviewFeatures.join(",")]);
312
- }
313
- this.child = (0, import_child_process.spawn)(binaryPath, args, {
314
- cwd: projectDir,
315
- stdio: ["pipe", "pipe", this.debug ? process.stderr : "pipe"],
316
- env: {
317
- // The following environment variables can be overridden by the user.
318
- RUST_LOG: "info",
319
- RUST_BACKTRACE: "1",
320
- // Take env values from process.env (will override values set before)
321
- ...processEnv
322
- }
323
- });
324
- this.isRunning = true;
325
- this.child.on("error", (err) => {
326
- console.error("[schema-engine] error: %s", err);
327
- this.rejectAll(err);
328
- reject(err);
329
- });
330
- this.child.on("exit", (code) => {
331
- const exitWithErr = (err) => {
332
- this.rejectAll(err);
333
- reject(err);
334
- };
335
- const processMessages = this.messages.join("\n");
336
- const engineMessage = this.lastError?.message || processMessages;
337
- const handlePanic = () => {
338
- const stackTrace = `[EXIT_PANIC]
339
- ${processMessages}
340
- ${this.lastError?.backtrace ?? ""}`;
341
- exitWithErr(
342
- new import_internals.RustPanic(
343
- serializePanic(engineMessage),
344
- stackTrace,
345
- this.lastRequest,
346
- import_internals.ErrorArea.LIFT_CLI,
347
- /* schemaPath */
348
- this.schemaPath,
349
- /* schema */
350
- this.latestSchema?.files.map((schema) => [schema.path, schema.content])
351
- )
352
- );
353
- };
354
- switch (code) {
355
- case import_internals.SchemaEngineExitCode.Success:
356
- break;
357
- case import_internals.SchemaEngineExitCode.Error:
358
- exitWithErr(new Error(`Error in Schema engine: ${engineMessage}`));
359
- break;
360
- case import_internals.SchemaEngineExitCode.Panic:
361
- handlePanic();
362
- break;
363
- // treat unknown error codes as panics
364
- default:
365
- handlePanic();
366
- }
367
- });
368
- this.child.stdin.on("error", (err) => {
369
- debugStdin(err);
370
- });
371
- (0, import_chunk_AAATUOV6.byline)(this.child.stderr).on("data", (msg) => {
372
- const data = String(msg);
373
- debugStderr(data);
374
- try {
375
- const json = JSON.parse(data);
376
- this.messages.push(json.fields.message);
377
- if (json.level === "ERROR") {
378
- this.lastError = json.fields;
379
- }
380
- } catch (e) {
381
- }
382
- });
383
- (0, import_chunk_AAATUOV6.byline)(this.child.stdout).on("data", (line) => {
384
- this.handleResponse(String(line));
385
- });
386
- setImmediate(() => {
387
- resolve();
388
- });
389
- } catch (e) {
390
- reject(e);
391
- }
392
- });
393
- }
394
- async runCommand(request) {
395
- if (process.env.FORCE_PANIC_SCHEMA_ENGINE && request.method !== "getDatabaseVersion") {
396
- request = this.getRPCPayload("debugPanic", void 0);
397
- }
398
- await this.init();
399
- if (this.child?.killed) {
400
- throw new Error(`Can't execute ${JSON.stringify(request)} because Schema engine already exited.`);
401
- }
402
- return new Promise((resolve, reject) => {
403
- this.registerCallback(request.id, (response, err) => {
404
- if (err) {
405
- return reject(err);
406
- }
407
- if (response.result !== void 0) {
408
- resolve(response.result);
409
- } else {
410
- if (response.error) {
411
- debugRpc(response);
412
- if (response.error.data?.is_panic) {
413
- const message = response.error.data?.error?.message ?? response.error.message;
414
- const stackTrace = `[RESPONSE_ERROR_PANIC]
415
- ${response.error.data?.message ?? ""}`;
416
- reject(
417
- // Handle error and displays the interactive dialog to send panic error
418
- new import_internals.RustPanic(
419
- message,
420
- stackTrace,
421
- this.lastRequest,
422
- import_internals.ErrorArea.LIFT_CLI,
423
- /* schemaPath */
424
- this.schemaPath,
425
- /* schema */
426
- this.latestSchema?.files.map((schema) => [schema.path, schema.content])
427
- )
428
- );
429
- } else if (response.error.data?.message) {
430
- let message = `${(0, import_chunk_6TE2RIPN.red)((0, import_internals.relativizePathInPSLError)(response.error.data.message))}
431
- `;
432
- if (response.error.data?.error_code) {
433
- message = (0, import_chunk_6TE2RIPN.red)(`${response.error.data.error_code}
434
-
435
- `) + message;
436
- reject(new EngineError(message, response.error.data.error_code));
437
- } else {
438
- reject(new Error(message));
439
- }
440
- } else {
441
- reject(
442
- new Error(
443
- `${(0, import_chunk_6TE2RIPN.red)("Error in RPC")}
444
- Request: ${JSON.stringify(request, null, 2)}
445
- Response: ${JSON.stringify(
446
- response,
447
- null,
448
- 2
449
- )}
450
- ${response.error.message}
451
- `
452
- )
453
- );
454
- }
455
- } else {
456
- reject(new Error(`Got invalid RPC response without .result property: ${JSON.stringify(response)}`));
457
- }
458
- }
459
- });
460
- if (this.child.stdin.destroyed) {
461
- throw new Error(`Can't execute ${JSON.stringify(request)} because Schema engine is destroyed.`);
462
- }
463
- debugRpc("SENDING RPC CALL", JSON.stringify(request));
464
- this.child.stdin.write(JSON.stringify(request) + "\n");
465
- this.lastRequest = request;
466
- });
467
- }
468
- getRPCPayload(method, params) {
469
- return {
470
- id: messageId++,
471
- jsonrpc: "2.0",
472
- method,
473
- params: params ? {
474
- ...params
475
- } : void 0
476
- };
477
- }
478
- };
479
- }
480
- });