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

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