hekireki 0.47.0 → 0.49.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.
Files changed (38) hide show
  1. package/dist/bin/activerecord.js +1 -1
  2. package/dist/bin/ajv.js +1 -1
  3. package/dist/bin/arktype.js +1 -1
  4. package/dist/bin/atlas.js +1 -1
  5. package/dist/bin/django.js +1 -1
  6. package/dist/bin/docs.js +1 -1
  7. package/dist/bin/drizzle.js +1 -1
  8. package/dist/bin/ecto.js +1 -1
  9. package/dist/bin/efcore.js +1 -1
  10. package/dist/bin/effect.js +1 -1
  11. package/dist/bin/eloquent.js +1 -1
  12. package/dist/bin/er.js +1 -1
  13. package/dist/bin/exposed.js +1 -1
  14. package/dist/bin/gorm.js +1 -1
  15. package/dist/bin/hekireki.js +17 -5
  16. package/dist/bin/kysely.js +1 -1
  17. package/dist/bin/openapi.js +1 -1
  18. package/dist/bin/pydantic.js +1 -1
  19. package/dist/bin/sea-orm.js +1 -1
  20. package/dist/bin/seed.js +1 -1
  21. package/dist/bin/sqlalchemy.js +1 -1
  22. package/dist/bin/typebox.js +1 -1
  23. package/dist/bin/valibot.js +1 -1
  24. package/dist/bin/zod.js +1 -1
  25. package/dist/{bin-CeA8S_Qj.js → bin-BwEbmAZJ.js} +22 -11
  26. package/dist/{discover-kVbu9DxT.js → discover-Cl2bvBbf.js} +2 -2
  27. package/dist/{emit-DF8ehOFH.js → emit-B34moVCH.js} +1 -1
  28. package/dist/errors-fAN1Og-7.js +217 -0
  29. package/dist/{migrate-U9pCkJTm.js → migrate-Br4Ihwix.js} +4 -4
  30. package/dist/native-engine-Chz7hHRS.js +1481 -0
  31. package/dist/{plan-ChzbNv7_.js → plan-D02O7uP9.js} +130 -1702
  32. package/dist/{run-Caiu7ebD.js → run-C1XOA4x-.js} +4 -4
  33. package/dist/{schema-DzF7tKzG.js → schema-E_PyiUp_.js} +1 -1
  34. package/dist/{sql-DciD3-lE.js → sql-U9Fo2g8L.js} +1 -1
  35. package/dist/{start-C1n6SWZ3.js → start-Dez8JNe5.js} +5231 -1436
  36. package/package.json +1 -1
  37. package/dist/errors-0PjX4y1Z.js +0 -1050
  38. package/dist/native-engine-D1iZDp41.js +0 -537
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/activerecord.ts
4
4
  registerGenerator("activerecord");
5
5
  export {};
package/dist/bin/ajv.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/ajv.ts
4
4
  registerGenerator("ajv");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/arktype.ts
4
4
  registerGenerator("arktype");
5
5
  export {};
package/dist/bin/atlas.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/atlas.ts
4
4
  registerGenerator("atlas");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/django.ts
4
4
  registerGenerator("django");
5
5
  export {};
package/dist/bin/docs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/docs.ts
4
4
  registerGenerator("docs");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/drizzle.ts
4
4
  registerGenerator("drizzle");
5
5
  export {};
package/dist/bin/ecto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/ecto.ts
4
4
  registerGenerator("ecto");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/efcore.ts
4
4
  registerGenerator("efcore");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/effect.ts
4
4
  registerGenerator("effect");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/eloquent.ts
4
4
  registerGenerator("eloquent");
5
5
  export {};
package/dist/bin/er.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/er.ts
4
4
  registerGenerator("er");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/exposed.ts
4
4
  registerGenerator("exposed");
5
5
  export {};
package/dist/bin/gorm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/gorm.ts
4
4
  registerGenerator("gorm");
5
5
  export {};
@@ -6,7 +6,7 @@ import { Console, Data, Effect, Schema } from "effect";
6
6
  import path from "node:path";
7
7
  import { CliError, Command, Flag } from "effect/cli";
8
8
  // package.json
9
- var version = "0.47.0";
9
+ var version = "0.49.0";
10
10
  // src/schema/path.ts
11
11
  /** Where Prisma looks for a schema when neither the command nor prisma.config.ts names one. */
12
12
  const DEFAULT_SCHEMA_PATHS = ["prisma/schema.prisma", "schema.prisma"];
@@ -75,17 +75,29 @@ const PRISMA_FILE_URI = "file:///schema.prisma";
75
75
  /** How often the migrations directory is read for a change. */
76
76
  const MIGRATIONS_POLL_MS = 1e3;
77
77
  // src/studio/server/errors/index.ts
78
+ /** A model name the schema does not hold; raised by the database usecases before they touch a table. */
78
79
  var UnknownModelError = class extends Data.TaggedError("UnknownModelError") {};
80
+ /** A path that is not one of the schema's files; raised by the schema usecase before it writes. */
79
81
  var UnknownFileError = class extends Data.TaggedError("UnknownFileError") {};
82
+ /** A schema file could not be written; raised by `writeSchemaFile`. */
80
83
  var FileWriteError = class extends Data.TaggedError("FileWriteError") {};
84
+ /** No database to talk to (no URL, no driver installed, or the connection refused); raised by the database services when they open one. */
81
85
  var DatabaseUnavailableError = class extends Data.TaggedError("DatabaseUnavailableError") {};
86
+ /** A statement the database driver rejected; raised by the database services and worded by the database usecases. */
82
87
  var DatabaseError = class extends Data.TaggedError("DatabaseError") {};
88
+ /** The project's Prisma Client (or TypeScript, to check a query) could not be found or loaded; raised by the client and TypeScript services. */
83
89
  var ClientUnavailableError = class extends Data.TaggedError("ClientUnavailableError") {};
90
+ /** A query the project's Prisma Client rejected or threw on; raised by the client service. */
84
91
  var ClientQueryError = class extends Data.TaggedError("ClientQueryError") {};
92
+ /** A request field that cannot be run as given (an empty `where` or `values`, SQL with no statement, a client query that does not parse or that writes); raised by the client and database usecases. */
85
93
  var InvalidInputError = class extends Data.TaggedError("InvalidInputError") {};
94
+ /** The Prisma language server could not format the schema; raised by `formatSchema`. */
86
95
  var FormatError = class extends Data.TaggedError("FormatError") {};
96
+ /** The schema file or directory could not be read; raised by the schema loader. */
87
97
  var SchemaLoadError = class extends Data.TaggedError("SchemaLoadError") {};
98
+ /** The schema could not be parsed into its models; raised by the schema loader, with the language server's diagnostics. */
88
99
  var SchemaParseError = class extends Data.TaggedError("SchemaParseError") {};
100
+ /** Studio's HTTP server could not listen on its port; raised when the server starts. */
89
101
  var ServerListenError = class extends Data.TaggedError("ServerListenError") {};
90
102
  // src/cli/index.ts
91
103
  const COMMAND_NAME = "hekireki";
@@ -135,7 +147,7 @@ const studioFlags = {
135
147
  function runStudio(args) {
136
148
  return Effect.gen(function* () {
137
149
  const schemaPath = yield* resolveSchemaPath(args.schema, [COMMAND_NAME, "studio"]);
138
- const { startStudioServer } = yield* Effect.promise(() => import("../start-C1n6SWZ3.js"));
150
+ const { startStudioServer } = yield* Effect.promise(() => import("../start-Dez8JNe5.js"));
139
151
  const started = yield* startStudioServer({
140
152
  schemaPath,
141
153
  port: args.port,
@@ -183,7 +195,7 @@ const seedFlags = {
183
195
  };
184
196
  function runSeedCommand(args) {
185
197
  return Effect.gen(function* () {
186
- const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-Caiu7ebD.js"));
198
+ const { runSeed, seedBanner } = yield* Effect.promise(() => import("../run-C1XOA4x-.js"));
187
199
  const report = yield* runSeed(args, process.cwd()).pipe(Effect.mapError((error) => new CliError.UserError({ cause: error.message })));
188
200
  yield* Console.log(seedBanner(report));
189
201
  });
@@ -226,7 +238,7 @@ function runMigrateCheckCommand(args) {
226
238
  "migrate",
227
239
  "check"
228
240
  ]);
229
- const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-U9pCkJTm.js"));
241
+ const { checkBanner, checkJson, runMigrateCheck, summarize } = yield* Effect.promise(() => import("../migrate-Br4Ihwix.js"));
230
242
  const report = yield* runMigrateCheck({
231
243
  ...args,
232
244
  schemaPath,
@@ -273,7 +285,7 @@ function runMigratePlanCommand(args) {
273
285
  "migrate",
274
286
  "plan"
275
287
  ]);
276
- const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-U9pCkJTm.js"));
288
+ const { checkBanner, planSql, readMigration, runMigrateCheck, summarize, writePlan } = yield* Effect.promise(() => import("../migrate-Br4Ihwix.js"));
277
289
  const report = yield* runMigrateCheck({
278
290
  ...args,
279
291
  schemaPath,
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/kysely.ts
4
4
  registerGenerator("kysely");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/openapi.ts
4
4
  registerGenerator("openapi");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/pydantic.ts
4
4
  registerGenerator("pydantic");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/sea-orm.ts
4
4
  registerGenerator("sea-orm");
5
5
  export {};
package/dist/bin/seed.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/seed.ts
4
4
  registerGenerator("seed");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/sqlalchemy.ts
4
4
  registerGenerator("sqlalchemy");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/typebox.ts
4
4
  registerGenerator("typebox");
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/valibot.ts
4
4
  registerGenerator("valibot");
5
5
  export {};
package/dist/bin/zod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as registerGenerator } from "../bin-CeA8S_Qj.js";
2
+ import { t as registerGenerator } from "../bin-BwEbmAZJ.js";
3
3
  // src/bin/zod.ts
4
4
  registerGenerator("zod");
5
5
  export {};
@@ -1,8 +1,8 @@
1
1
  import { c as removePath, o as readDirectory, t as exists } from "./file-BAVQ-zst.js";
2
- import { A as tableName, B as isAnnotationLine, C as isUlidDefault, D as referentialActions, E as primaryKeyFields$1, F as getBool, G as makePascalCase, I as getString, K as makeSnakeCase, L as getStrings, N as constraintName, O as relationEnds, P as extractObjectType, Q as fmtMarkdown, R as groupByModel, S as isNowDefault$1, T as manyToManyRelations, U as isSameList, V as isFields, W as lowerFirst, X as stripAnnotations, Y as schemaFromFields, _ as isAutoincrement, b as isJoinSideA, f as formatSql, g as implicitJoinTables, h as fieldColumn, i as schemaText, j as uuidDefaultVersion, k as scalarFields, m as columnName, p as backRelation, q as makeValidationExtractor, r as readSchemaFiles, t as dialectOf, v as isFunctionDefault, w as lengthArg, x as isListDefault, y as isImplicitManyToMany, z as indexPrefix } from "./schema-DzF7tKzG.js";
3
- import { n as emitMany, r as emitRaw, t as emit } from "./emit-DF8ehOFH.js";
4
- import { a as splitStatements, d as makeSchema, f as annotatedERRelations, h as inferredERRelations, m as erRelations, p as erKey, t as MigrateConfigError } from "./errors-0PjX4y1Z.js";
5
- import { a as makeOfflineSchemaEngineAdapter, i as openSchemaEngine, n as openNativeSchemaEngine, r as engineCommand, t as findSchemaEngineBinary } from "./native-engine-D1iZDp41.js";
2
+ import { $ as fmtMarkdown, A as scalarFields, B as indexPrefix, C as isNowDefault$1, D as primaryKeyFields$1, E as manyToManyRelations, F as extractObjectType, G as lowerFirst, H as isFields, I as getBool, J as makeValidationExtractor, K as makePascalCase, L as getString, M as uuidDefaultVersion, O as referentialActions, P as constraintName, R as getStrings, S as isListDefault, T as lengthArg, V as isAnnotationLine, W as isSameList, X as schemaFromFields, Z as stripAnnotations, _ as implicitJoinTables, a as schemaText, b as isImplicitManyToMany, g as fieldColumn, h as columnName, i as readSchemaFiles, j as tableName, k as relationEnds, m as backRelation, p as formatSql, q as makeSnakeCase, t as dialectOf, v as isAutoincrement, w as isUlidDefault, x as isJoinSideA, y as isFunctionDefault, z as groupByModel } from "./schema-E_PyiUp_.js";
3
+ import { n as emitMany, r as emitRaw, t as emit } from "./emit-B34moVCH.js";
4
+ import { a as makeOfflineSchemaEngineAdapter, c as makeSchema, d as erRelations, f as inferredERRelations, i as openSchemaEngine, l as annotatedERRelations, n as openNativeSchemaEngine, r as engineCommand, t as findSchemaEngineBinary, u as erKey } from "./native-engine-Chz7hHRS.js";
5
+ import { a as splitStatements, t as MigrateConfigError } from "./errors-fAN1Og-7.js";
6
6
  import { createRequire } from "node:module";
7
7
  import { Data, Effect } from "effect";
8
8
  import path from "node:path";
@@ -5617,7 +5617,8 @@ function entriesOf(fields, enums) {
5617
5617
  */
5618
5618
  function uniqueWhere(model, enums) {
5619
5619
  const single = model.fields.find((f) => f.isId) ?? model.fields.find((f) => f.isUnique);
5620
- const compound = model.primaryKey ?? (single === void 0 ? model.uniqueIndexes[0] ?? null : null);
5620
+ const key = model.primaryKey ?? (single === void 0 ? model.uniqueIndexes[0] ?? null : null);
5621
+ const compound = key !== null && key.fields.length > 1 ? key : null;
5621
5622
  if (compound === null) {
5622
5623
  const entries = single === void 0 ? null : entriesOf([single], enums);
5623
5624
  return single === void 0 || entries === null ? null : {
@@ -5642,13 +5643,18 @@ function uniqueWhere(model, enums) {
5642
5643
  * Each model's queries as the docs show them: every row, how many, the rows with their relations
5643
5644
  * (for a model with one), one row by what is unique to it, and a create, update and delete, with a
5644
5645
  * value of each field's type. A query the model cannot take (no unique field to find one row by,
5645
- * a required field of a type with no value to write) is left out.
5646
+ * a required field of a type with no value to write) is left out, and so is one Prisma Client
5647
+ * does not give it: a view is read and not written.
5646
5648
  *
5647
- * @param datamodel - the models and enums Prisma parsed
5649
+ * @param document.datamodel - the models and enums Prisma parsed
5650
+ * @param document.mappings - the operations Prisma Client gives each model
5648
5651
  * @returns the queries, model by model
5649
5652
  */
5650
- function queryExamples(datamodel) {
5653
+ function queryExamples(document) {
5654
+ const { datamodel } = document;
5651
5655
  return datamodel.models.flatMap((model) => {
5656
+ const mapping = document.mappings.modelOperations.find((m) => m.model === model.name);
5657
+ const actions = new Set(Object.entries(mapping ?? {}).flatMap(([action, name]) => typeof name === "string" && action !== "model" && action !== "plural" ? [action] : []));
5652
5658
  const client = `prisma.${lowerFirst(model.name)}`;
5653
5659
  const example = (name, description, code, action, query) => ({
5654
5660
  model: model.name,
@@ -5716,7 +5722,7 @@ function queryExamples(datamodel) {
5716
5722
  arguments: { where: where.json },
5717
5723
  selection: SCALARS
5718
5724
  })]
5719
- ];
5725
+ ].filter((query) => actions.has(query.request.action));
5720
5726
  });
5721
5727
  }
5722
5728
  const Fragment = z.discriminatedUnion("type", [
@@ -5995,6 +6001,10 @@ const WasmModule = z.object({ wasm: z.string().meta({
5995
6001
  example: "AGFzbQ=="
5996
6002
  }) }).meta({ description: "The query compiler as @prisma/client ships it, the module in base64" });
5997
6003
  const WasmStart = z.custom((value) => typeof value === "function").meta({ description: "The start hook wasm-bindgen puts on the instantiated module." });
6004
+ const CompilerFailure = z.object({ message: z.string().meta({
6005
+ description: "Why it failed.",
6006
+ example: "Operation 'createOne' for model 'V' does not match any query."
6007
+ }) }).meta({ description: "What the compiler throws: an Error, or a plain object with a message" });
5998
6008
  /** Where a panic in the compiler writes its message before the WebAssembly trap unwinds. */
5999
6009
  const panics = { message: null };
6000
6010
  /**
@@ -6005,7 +6015,8 @@ const loaded = /* @__PURE__ */ new Map();
6005
6015
  function compilerError(error) {
6006
6016
  const { message } = panics;
6007
6017
  panics.message = null;
6008
- return new QueryCompilerError({ message: message ?? (error instanceof Error ? error.message : String(error)) });
6018
+ const result = CompilerFailure.safeParse(error);
6019
+ return new QueryCompilerError({ message: message ?? (result.success ? result.data.message : String(error)) });
6009
6020
  }
6010
6021
  /**
6011
6022
  * The query compiler of the project's own `@prisma/client`, for one database: the one the client
@@ -6117,7 +6128,7 @@ function docs(options) {
6117
6128
  dialect,
6118
6129
  cwd: process.cwd()
6119
6130
  });
6120
- const examples = queryExamples(options.dmmf.datamodel);
6131
+ const examples = queryExamples(options.dmmf);
6121
6132
  const compiled = dialect === null ? null : yield* compileQueries({
6122
6133
  schemaPath: options.schemaPath,
6123
6134
  datamodel: schemaText(files),
@@ -1,5 +1,5 @@
1
- import { d as makeSqliteFilePath, l as makePostgresSchema } from "./schema-DzF7tKzG.js";
2
- import { u as SeedDatabaseError } from "./sql-DciD3-lE.js";
1
+ import { f as makeSqliteFilePath, u as makePostgresSchema } from "./schema-E_PyiUp_.js";
2
+ import { u as SeedDatabaseError } from "./sql-U9Fo2g8L.js";
3
3
  import { createRequire } from "node:module";
4
4
  import { Effect } from "effect";
5
5
  import path from "node:path";
@@ -1,5 +1,5 @@
1
1
  import { i as makeDirectory, u as writeFile } from "./file-BAVQ-zst.js";
2
- import { Z as fmt } from "./schema-DzF7tKzG.js";
2
+ import { Q as fmt } from "./schema-E_PyiUp_.js";
3
3
  import { Effect } from "effect";
4
4
  import path from "node:path";
5
5
  // src/emit/index.ts
@@ -0,0 +1,217 @@
1
+ import { Data } from "effect";
2
+ // src/sql/types.ts
3
+ /**
4
+ * The affinity SQLite gives a declared type by what its name holds
5
+ * (https://www.sqlite.org/datatype3.html#affname), in the order the rules are tried: INTEGER
6
+ * for `INT` anywhere in it, TEXT for `CHAR`, `CLOB` or `TEXT`, REAL for `REAL`, `FLOA` or
7
+ * `DOUB`; null for a name those rules say nothing about, which every reader decides for itself.
8
+ *
9
+ * @param upper - the declared type in upper case, as `sqlite_master` and `PRAGMA table_info` spell it
10
+ */
11
+ function sqliteAffinity(upper) {
12
+ if (upper.includes("INT")) return "integer";
13
+ if (upper.includes("CHAR") || upper.includes("CLOB") || upper.includes("TEXT")) return "text";
14
+ if (upper.includes("REAL") || upper.includes("FLOA") || upper.includes("DOUB")) return "real";
15
+ return null;
16
+ }
17
+ /** SQLite's type affinity rules, plus the conventional date/time and JSON spellings that store text. */
18
+ function sqliteTsType(dataType) {
19
+ const upper = dataType.toUpperCase();
20
+ if (upper === "") return "unknown";
21
+ const affinity = sqliteAffinity(upper);
22
+ if (affinity === "integer") return "number";
23
+ if (affinity === "text") return "string";
24
+ if (upper.includes("BLOB")) return "Uint8Array";
25
+ if (affinity === "real") return "number";
26
+ if (upper.includes("BOOL")) return "number";
27
+ if (upper.includes("DATE") || upper.includes("TIME") || upper.includes("JSON")) return "string";
28
+ if (upper.includes("DEC") || upper.includes("NUM")) return "number";
29
+ return "number";
30
+ }
31
+ const POSTGRES_TYPES = {
32
+ int2: "number",
33
+ smallint: "number",
34
+ int4: "number",
35
+ int: "number",
36
+ integer: "number",
37
+ serial: "number",
38
+ serial4: "number",
39
+ smallserial: "number",
40
+ float4: "number",
41
+ real: "number",
42
+ float8: "number",
43
+ "double precision": "number",
44
+ oid: "number",
45
+ int8: "string",
46
+ bigint: "string",
47
+ bigserial: "string",
48
+ serial8: "string",
49
+ numeric: "string",
50
+ decimal: "string",
51
+ money: "string",
52
+ text: "string",
53
+ varchar: "string",
54
+ "character varying": "string",
55
+ bpchar: "string",
56
+ char: "string",
57
+ character: "string",
58
+ name: "string",
59
+ citext: "string",
60
+ uuid: "string",
61
+ time: "string",
62
+ timetz: "string",
63
+ "time without time zone": "string",
64
+ "time with time zone": "string",
65
+ interval: "string",
66
+ inet: "string",
67
+ cidr: "string",
68
+ macaddr: "string",
69
+ xml: "string",
70
+ tsvector: "string",
71
+ tsquery: "string",
72
+ bit: "string",
73
+ varbit: "string",
74
+ bool: "boolean",
75
+ boolean: "boolean",
76
+ date: "Date",
77
+ timestamp: "Date",
78
+ timestamptz: "Date",
79
+ "timestamp without time zone": "Date",
80
+ "timestamp with time zone": "Date",
81
+ bytea: "Uint8Array",
82
+ json: "unknown",
83
+ jsonb: "unknown"
84
+ };
85
+ function postgresTsType(dataType) {
86
+ const lower = dataType.toLowerCase().trim();
87
+ if (lower.endsWith("[]")) return `${postgresTsType(lower.slice(0, -2))}[]`;
88
+ if (lower.startsWith("_")) return `${postgresTsType(lower.slice(1))}[]`;
89
+ const base = lower.replace(/\(.*\)$/u, "").trim();
90
+ return POSTGRES_TYPES[base] ?? "unknown";
91
+ }
92
+ const MYSQL_TYPES = {
93
+ tinyint: "number",
94
+ smallint: "number",
95
+ mediumint: "number",
96
+ int: "number",
97
+ integer: "number",
98
+ bigint: "number",
99
+ year: "number",
100
+ float: "number",
101
+ double: "number",
102
+ real: "number",
103
+ decimal: "string",
104
+ numeric: "string",
105
+ varchar: "string",
106
+ char: "string",
107
+ text: "string",
108
+ tinytext: "string",
109
+ mediumtext: "string",
110
+ longtext: "string",
111
+ enum: "string",
112
+ set: "string",
113
+ time: "string",
114
+ date: "Date",
115
+ datetime: "Date",
116
+ timestamp: "Date",
117
+ bit: "Uint8Array",
118
+ binary: "Uint8Array",
119
+ varbinary: "Uint8Array",
120
+ blob: "Uint8Array",
121
+ tinyblob: "Uint8Array",
122
+ mediumblob: "Uint8Array",
123
+ longblob: "Uint8Array",
124
+ geometry: "Uint8Array",
125
+ json: "unknown",
126
+ boolean: "number",
127
+ bool: "number"
128
+ };
129
+ function mysqlTsType(dataType) {
130
+ const base = dataType.toLowerCase().replace(/\(.*\)$/u, "").replace(/\s+unsigned$/u, "").trim();
131
+ return MYSQL_TYPES[base] ?? "unknown";
132
+ }
133
+ /** The TypeScript type a driver hands back for a column of the declared type. */
134
+ function toTsType(dialect, dataType) {
135
+ switch (dialect) {
136
+ case "sqlite": return sqliteTsType(dataType);
137
+ case "postgresql": return postgresTsType(dataType);
138
+ case "mysql": return mysqlTsType(dataType);
139
+ default: return "unknown";
140
+ }
141
+ }
142
+ /** The declared type a literal of the expression kind would have in the dialect, for the type column of the picture. */
143
+ function literalDataType(dialect, kind) {
144
+ if (kind === "string") return dialect === "sqlite" ? "TEXT" : dialect === "mysql" ? "varchar" : "text";
145
+ if (kind === "number") return dialect === "sqlite" ? "INTEGER" : dialect === "mysql" ? "int" : "int4";
146
+ return dialect === "postgresql" ? "bool" : dialect === "mysql" ? "tinyint" : "INTEGER";
147
+ }
148
+ // src/sql/split.ts
149
+ /**
150
+ * Splits SQL text into statements at the `;` that sit outside quotes and comments. A driver runs
151
+ * one statement per call, and the result a console shows belongs to the last one.
152
+ */
153
+ function splitStatements(text) {
154
+ const ends = [];
155
+ let mode = "code";
156
+ let quote = "";
157
+ for (let index = 0; index < text.length; index += 1) {
158
+ const char = text[index] ?? "";
159
+ const next = text[index + 1] ?? "";
160
+ if (mode === "line-comment") {
161
+ if (char === "\n") mode = "code";
162
+ } else if (mode === "block-comment") {
163
+ if (char === "*" && next === "/") {
164
+ mode = "code";
165
+ index += 1;
166
+ }
167
+ } else if (mode === "quoted") {
168
+ if (char === quote) {
169
+ if (next === quote) index += 1;
170
+ else {
171
+ mode = "code";
172
+ quote = "";
173
+ }
174
+ }
175
+ } else if (char === "-" && next === "-") mode = "line-comment";
176
+ else if (char === "/" && next === "*") mode = "block-comment";
177
+ else if (char === "'" || char === "\"" || char === "`") {
178
+ mode = "quoted";
179
+ quote = char;
180
+ } else if (char === ";") ends.push(index);
181
+ }
182
+ const bounds = [...ends, text.length];
183
+ return bounds.map((end, index) => text.slice(index === 0 ? 0 : (bounds[index - 1] ?? 0) + 1, end).trim()).filter((statement) => statement !== "");
184
+ }
185
+ /**
186
+ * Splits at the commas outside parentheses and quotes: the clauses of an ALTER TABLE, the items
187
+ * of a list.
188
+ */
189
+ function splitTopLevel(text) {
190
+ const parts = [];
191
+ let current = "";
192
+ let depth = 0;
193
+ let quote = "";
194
+ for (const char of text) {
195
+ current += char;
196
+ if (quote !== "") {
197
+ if (char === quote) quote = "";
198
+ } else if (char === "'" || char === "\"" || char === "`") quote = char;
199
+ else if (char === "(") depth += 1;
200
+ else if (char === ")") depth -= 1;
201
+ else if (char === "," && depth === 0) {
202
+ parts.push(current.slice(0, -1).trim());
203
+ current = "";
204
+ }
205
+ }
206
+ return [...parts, current.trim()].filter((part) => part !== "");
207
+ }
208
+ // src/migrate/errors.ts
209
+ /** The schema cannot be read, or the command line names something the check cannot use. */
210
+ var MigrateConfigError = class extends Data.TaggedError("MigrateConfigError") {};
211
+ /** The database could not be opened, or refused one of the check's queries. */
212
+ var MigrateDatabaseError = class extends Data.TaggedError("MigrateDatabaseError") {};
213
+ /** The migrations directory holds no migration of the name asked for. */
214
+ var MigrationNotFoundError = class extends Data.TaggedError("MigrationNotFoundError") {};
215
+ /** The Prisma schema engine could not be started, or refused a command. */
216
+ var MigrateEngineError = class extends Data.TaggedError("MigrateEngineError") {};
217
+ export { splitStatements as a, sqliteAffinity as c, MigrationNotFoundError as i, toTsType as l, MigrateDatabaseError as n, splitTopLevel as o, MigrateEngineError as r, literalDataType as s, MigrateConfigError as t };
@@ -1,8 +1,8 @@
1
1
  import { s as readFile } from "./file-BAVQ-zst.js";
2
- import "./schema-DzF7tKzG.js";
3
- import { r as emitRaw } from "./emit-DF8ehOFH.js";
4
- import { a as splitStatements, t as MigrateConfigError } from "./errors-0PjX4y1Z.js";
5
- import { i as lostInRebuild, l as runMigrateCheck, n as isDestructiveStep, o as BLOCK_QUOTE, r as isLossyFix, s as rewriteMigration, t as batchedStatements } from "./plan-ChzbNv7_.js";
2
+ import "./schema-E_PyiUp_.js";
3
+ import { r as emitRaw } from "./emit-B34moVCH.js";
4
+ import { a as splitStatements, t as MigrateConfigError } from "./errors-fAN1Og-7.js";
5
+ import { i as lostInRebuild, l as runMigrateCheck, n as isDestructiveStep, o as BLOCK_QUOTE, r as isLossyFix, s as rewriteMigration, t as batchedStatements } from "./plan-D02O7uP9.js";
6
6
  import { Effect } from "effect";
7
7
  import path from "node:path";
8
8
  // src/migrate/adapter/plan-file.ts