hekireki 0.52.0 → 0.52.2

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 (66) hide show
  1. package/README.md +8 -0
  2. package/dist/bin/activerecord.js +1 -1
  3. package/dist/bin/ajv.js +1 -1
  4. package/dist/bin/arktype.js +1 -1
  5. package/dist/bin/atlas.js +1 -1
  6. package/dist/bin/django.js +1 -1
  7. package/dist/bin/docs.js +1 -1
  8. package/dist/bin/drizzle.js +1 -1
  9. package/dist/bin/ecto.js +1 -1
  10. package/dist/bin/efcore.js +1 -1
  11. package/dist/bin/effect.js +1 -1
  12. package/dist/bin/eloquent.js +1 -1
  13. package/dist/bin/er.js +1 -1
  14. package/dist/bin/exposed.js +1 -1
  15. package/dist/bin/gorm.js +1 -1
  16. package/dist/bin/hekireki.js +5 -5
  17. package/dist/bin/kysely.js +1 -1
  18. package/dist/bin/openapi.js +1 -1
  19. package/dist/bin/pydantic.js +1 -1
  20. package/dist/bin/sea-orm.js +1 -1
  21. package/dist/bin/seed.js +1 -1
  22. package/dist/bin/sqlalchemy.js +1 -1
  23. package/dist/bin/typebox.js +1 -1
  24. package/dist/bin/valibot.js +1 -1
  25. package/dist/bin/zod-openapi-hono.js +1 -1
  26. package/dist/bin/zod.js +1 -1
  27. package/dist/{bin-BcqPhgiX.js → bin-i7iQQ-V-.js} +3295 -2428
  28. package/dist/case-D3JCqTLI.js +54 -0
  29. package/dist/{discover-BKlX-LLS.js → discover-CLLycWcR.js} +3 -3
  30. package/dist/{emit-BSQAIFiF.js → emit-DsCT5gLu.js} +5 -2
  31. package/dist/{errors-fAN1Og-7.js → errors-CRIxtr-P.js} +88 -26
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/{migrate-BS6d_8aA.js → migrate-1xVrRUlb.js} +77 -21
  35. package/dist/{native-engine-DcZUEqO8.js → native-engine-DeQEnJxi.js} +145 -30
  36. package/dist/{plan-BMypogKp.js → plan-8rsBBJcs.js} +1294 -768
  37. package/dist/{run-BYq7BEVd.js → run-DbZYkHVI.js} +235 -128
  38. package/dist/{schema-B7beUJic.js → schema-CyJTUCF1.js} +54 -182
  39. package/dist/{sql-BwL2BncN.js → sql-LMMCiAlf.js} +48 -19
  40. package/dist/{start-s1j4PqUM.js → start-Ba8wQAD1.js} +1304 -929
  41. package/dist/studio/assets/client-8R97eV42.js +2 -0
  42. package/dist/studio/assets/{confirm-dialog-CKCkchiq.js → confirm-dialog-BfMzwGyk.js} +1 -1
  43. package/dist/studio/assets/docs-C7FtC4KG.js +1 -0
  44. package/dist/studio/assets/enums._name-DLAiEdMc.js +1 -0
  45. package/dist/studio/assets/{field-icon-C1wSRFKO.js → field-icon-LVK7vIIn.js} +1 -1
  46. package/dist/studio/assets/index-T46k2NyA.js +15 -0
  47. package/dist/studio/assets/{labels-B5gZ2suK.js → labels-Bn-KWaMa.js} +2 -2
  48. package/dist/studio/assets/{marked-text-B27DfhKS.js → marked-text-BdU5_qSK.js} +1 -1
  49. package/dist/studio/assets/models._name-BKzAVcW3.js +1 -0
  50. package/dist/studio/assets/{monaco-DRYJTcJl.js → monaco-33yj-p0X.js} +1 -1
  51. package/dist/studio/assets/prisma-DqpMbUwJ.js +2 -0
  52. package/dist/studio/assets/result-table-PN64JbsN.js +1 -0
  53. package/dist/studio/assets/{routes-Bl7HRpBJ.js → routes-C1Aze5QM.js} +1 -1
  54. package/dist/studio/assets/{schema-view-BEdx0cC2.js → schema-view-Bq2_9B5a.js} +4 -4
  55. package/dist/studio/assets/sql-FZV6GAdV.js +6 -0
  56. package/dist/studio/assets/{tabs-BpZ0hh1V.js → tabs-GBri63Xo.js} +1 -1
  57. package/dist/studio/index.html +2 -2
  58. package/package.json +12 -5
  59. package/dist/studio/assets/client-C-v3Paav.js +0 -2
  60. package/dist/studio/assets/docs-CXORFY0Y.js +0 -1
  61. package/dist/studio/assets/enums._name-BUBU_WMt.js +0 -1
  62. package/dist/studio/assets/index-DzCcMC-d.js +0 -15
  63. package/dist/studio/assets/models._name-CQFgPD0T.js +0 -1
  64. package/dist/studio/assets/prisma-1nDx08Wb.js +0 -2
  65. package/dist/studio/assets/result-table-0P18Nywh.js +0 -1
  66. package/dist/studio/assets/sql-GBZZtEKI.js +0 -6
@@ -1,6 +1,6 @@
1
1
  import { a as readBytes, o as readDirectory, t as exists } from "./file-DOGnu_Q2.js";
2
- import { U as isAnnotationLine, Z as parseRelation, h as backRelation, s as environmentVariable } from "./schema-B7beUJic.js";
3
- import { a as splitStatements, c as sqliteAffinity, r as MigrateEngineError } from "./errors-fAN1Og-7.js";
2
+ import { h as backRelation, s as environmentVariable } from "./schema-CyJTUCF1.js";
3
+ import { a as splitStatements, c as sqliteAffinity, r as MigrateEngineError } from "./errors-CRIxtr-P.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { Effect, Semaphore, Stream } from "effect";
6
6
  import path from "node:path";
@@ -10,22 +10,111 @@ import { spawn } from "node:child_process";
10
10
  import { createInterface } from "node:readline";
11
11
  import { text } from "node:stream/consumers";
12
12
  import { getEnginesPath } from "@prisma/engines";
13
- // src/utils/relation.ts
13
+ // src/annotation/index.ts
14
+ function parseRelation(line) {
15
+ const match = line.trim().match(/^@relation\s+(\w+)\.(\w+)\s+(\w+)\.(\w+)\s+(\w+-to-\w+)$/u);
16
+ if (!match) return null;
17
+ const [, fromModel = "", fromField = "", toModel = "", toField = "", type = ""] = match;
18
+ return {
19
+ fromModel,
20
+ fromField,
21
+ toModel,
22
+ toField,
23
+ type
24
+ };
25
+ }
26
+ function makeValidationExtractor(annotationPrefix) {
27
+ const escaped = annotationPrefix.replaceAll(/[.*+?^${}()|[\]\\]/gu, "\\$&");
28
+ const regex = new RegExp(`${escaped}(.+?)(?:\\n|$)`, "u");
29
+ return function extractValidation(documentation) {
30
+ if (documentation === void 0 || documentation === "") return null;
31
+ return documentation.match(regex)?.[1]?.trim() ?? null;
32
+ };
33
+ }
34
+ const ANNOTATION_PREFIXES = [
35
+ "@z.",
36
+ "@v.",
37
+ "@a.",
38
+ "@e.",
39
+ "@t.",
40
+ "@j.",
41
+ "@p.",
42
+ "@ar.",
43
+ "@ecto.",
44
+ "@api.",
45
+ "@relation"
46
+ ];
47
+ const ANNOTATION_EXACT = /* @__PURE__ */ new Set([
48
+ "@z",
49
+ "@v",
50
+ "@a",
51
+ "@e",
52
+ "@t",
53
+ "@j",
54
+ "@p",
55
+ "@ar",
56
+ "@ecto"
57
+ ]);
58
+ function isAnnotationLine(line) {
59
+ const trimmed = line.trim();
60
+ return ANNOTATION_PREFIXES.some((p) => trimmed.startsWith(p)) || ANNOTATION_EXACT.has(trimmed);
61
+ }
62
+ function stripAnnotations(doc) {
63
+ const result = documentationLines(doc).join("\n").trim();
64
+ return result.length > 0 ? result : void 0;
65
+ }
66
+ /**
67
+ * The prose of a `///` comment as a JSDoc comment (also KDoc and PHPDoc) at `indent`: no lines
68
+ * when there is none, one line `/** … *\/` for one line of prose, and a block for more. A `*\/` in
69
+ * the text cannot close the comment early.
70
+ *
71
+ * @param text - the prose, as {@link stripAnnotations} returns it
72
+ * @param indent - the indentation of the commented line
73
+ * @returns the lines of the block
74
+ */
75
+ function docBlockLines(text, indent) {
76
+ if (text === void 0) return [];
77
+ const lines = text.replaceAll("*/", "*\\/").split("\n");
78
+ if (lines.length === 1) return [`${indent}/** ${lines[0]} */`];
79
+ const body = lines.map((line) => line === "" ? `${indent} *` : `${indent} * ${line}`);
80
+ return [
81
+ `${indent}/**`,
82
+ ...body,
83
+ `${indent} */`
84
+ ];
85
+ }
86
+ /** The lines of a doc comment that are prose: annotation lines are dropped. */
87
+ function documentationLines(doc) {
88
+ return (doc ?? "").split("\n").map((line) => line.trim()).filter((line) => !isAnnotationLine(line));
89
+ }
90
+ function extractObjectType(documentation, prefix) {
91
+ if (documentation === void 0 || documentation === "") return void 0;
92
+ const prefixWithoutAt = prefix.slice(1);
93
+ const match = documentation.split("\n").map((l) => l.trim()).find((line) => line.includes(`${prefixWithoutAt}strictObject`) || line.includes(`${prefixWithoutAt}looseObject`));
94
+ if (match === void 0) return void 0;
95
+ if (match.includes("strictObject")) return "strict";
96
+ return "loose";
97
+ }
98
+ // src/prisma/relation.ts
14
99
  function isCardinality(value) {
15
100
  return value === "zero-one" || value === "one" || value === "zero-many" || value === "many";
16
101
  }
17
102
  function erKey(relation) {
18
103
  return `${relation.from.model}.${relation.from.field}->${relation.to.model}.${relation.to.field}`;
19
104
  }
105
+ function childCardinality(inverse) {
106
+ if (inverse?.isList === true) return "zero-many";
107
+ return inverse?.isRequired === true ? "one" : "zero-one";
108
+ }
20
109
  function inferredERRelations(models) {
21
- return models.flatMap((model) => model.fields.filter((field) => field.kind === "object" && field.relationFromFields && field.relationFromFields.length > 0).map((field) => {
110
+ return models.flatMap((model) => model.fields.filter((field) => field.kind === "object" && (field.relationFromFields ?? []).length > 0).map((field) => {
22
111
  const toModel = model.name;
23
112
  const fromModel = field.type;
24
113
  const toField = field.relationFromFields?.[0] ?? "";
25
114
  const fromField = field.relationToFields?.[0] ?? "id";
26
115
  const inverseField = backRelation(field, model, models);
27
116
  const fromCardinality = field.isRequired ? "one" : "zero-one";
28
- const toCardinality = inverseField?.isList ? "zero-many" : inverseField?.isRequired ? "one" : "zero-one";
117
+ const toCardinality = childCardinality(inverseField);
29
118
  return {
30
119
  name: field.relationName ?? null,
31
120
  from: {
@@ -67,10 +156,11 @@ function annotatedERRelations(models) {
67
156
  }));
68
157
  }
69
158
  function implicitManyToManyERRelations(models) {
159
+ const byName = new Map(models.map((m) => [m.name, m]));
70
160
  return models.flatMap((model) => model.fields.filter((f) => f.kind === "object" && f.isList && (f.relationFromFields ?? []).length === 0).flatMap((field) => {
71
- const other = models.find((m) => m.name === field.type);
161
+ const other = byName.get(field.type);
72
162
  const inverse = backRelation(field, model, models);
73
- if (!(other && inverse?.isList)) return [];
163
+ if (other === void 0 || inverse?.isList !== true) return [];
74
164
  if (`${model.name}.${field.name}` > `${other.name}.${inverse.name}`) return [];
75
165
  return [{
76
166
  name: field.relationName ?? null,
@@ -290,6 +380,13 @@ const DefaultList = z.array(z.union([
290
380
  z.number(),
291
381
  z.boolean()
292
382
  ])).meta({ description: "A `@default([...])` list value as DMMF encodes it" });
383
+ function scalarText(item, kind) {
384
+ if (typeof item !== "string") return String(item);
385
+ return kind === "enum" ? item : JSON.stringify(item);
386
+ }
387
+ function isFilled(text) {
388
+ return text !== null && text !== void 0 && text !== "";
389
+ }
293
390
  /**
294
391
  * Renders a field default the way it is written in a Prisma schema: `now()`, `"anonymous"`, `VIEWER`.
295
392
  *
@@ -303,7 +400,7 @@ const DefaultList = z.array(z.union([
303
400
  function makeDefaultText(input) {
304
401
  const value = input.default;
305
402
  if (value === void 0) return null;
306
- const scalar = (item) => typeof item === "string" ? input.kind === "enum" ? item : JSON.stringify(item) : String(item);
403
+ const scalar = (item) => scalarText(item, input.kind);
307
404
  const result = z.union([DefaultCall, DefaultList]).safeParse(value);
308
405
  if (!result.success) return typeof value === "object" ? JSON.stringify(value) : scalar(value);
309
406
  if (Array.isArray(result.data)) return `[${result.data.map(scalar).join(", ")}]`;
@@ -380,14 +477,14 @@ z.object({
380
477
  function makeRelationAttribute(input) {
381
478
  const { field, modelName } = input;
382
479
  if (field.kind !== "object") return null;
383
- const customName = field.relationName && field.relationName !== makeRelationName({
480
+ const customName = isFilled(field.relationName) && field.relationName !== makeRelationName({
384
481
  a: modelName,
385
482
  b: field.type
386
483
  }) ? [JSON.stringify(field.relationName)] : [];
387
484
  const fromFields = field.relationFromFields ?? [];
388
485
  const toFields = field.relationToFields ?? [];
389
486
  const fk = fromFields.length > 0 ? [`fields: [${fromFields.join(", ")}]`, `references: [${toFields.join(", ")}]`] : [];
390
- const actions = [...field.relationOnDelete ? [`onDelete: ${field.relationOnDelete}`] : [], ...field.relationOnUpdate ? [`onUpdate: ${field.relationOnUpdate}`] : []];
487
+ const actions = [...isFilled(field.relationOnDelete) ? [`onDelete: ${field.relationOnDelete}`] : [], ...isFilled(field.relationOnUpdate) ? [`onUpdate: ${field.relationOnUpdate}`] : []];
391
488
  const parts = [
392
489
  ...customName,
393
490
  ...fk,
@@ -441,8 +538,8 @@ function makeIndexAttribute(input) {
441
538
  fulltext: "@@fulltext"
442
539
  }[index.type]}(${[
443
540
  `[${index.fields.map((f) => f.name).join(", ")}]`,
444
- ...index.name ? [`name: ${JSON.stringify(index.name)}`] : [],
445
- ...index.dbName ? [`map: ${JSON.stringify(index.dbName)}`] : []
541
+ ...isFilled(index.name) ? [`name: ${JSON.stringify(index.name)}`] : [],
542
+ ...isFilled(index.dbName) ? [`map: ${JSON.stringify(index.dbName)}`] : []
446
543
  ].join(", ")})`;
447
544
  }
448
545
  z.object({ index: Index }).readonly().meta({ description: "A DMMF index" });
@@ -470,6 +567,16 @@ z.object({
470
567
  }),
471
568
  foreignKeys: z.set(z.string()).meta({ description: "The names of the fields that hold a foreign key." })
472
569
  }).readonly().meta({ description: "A DMMF field with its model name and the model foreign-key field names" });
570
+ function relationOf(field) {
571
+ if (field.kind !== "object" || !isFilled(field.relationName)) return null;
572
+ return {
573
+ name: field.relationName,
574
+ fromFields: [...field.relationFromFields ?? []],
575
+ toFields: [...field.relationToFields ?? []],
576
+ onDelete: field.relationOnDelete ?? null,
577
+ onUpdate: field.relationOnUpdate ?? null
578
+ };
579
+ }
473
580
  /** Maps a DMMF field to the studio contract, rendering its attributes as Prisma writes them. */
474
581
  function makeField(input) {
475
582
  const { field, modelName, foreignKeys } = input;
@@ -487,18 +594,12 @@ function makeField(input) {
487
594
  ...field.isId ? ["@id"] : [],
488
595
  ...field.isUnique ? ["@unique"] : [],
489
596
  ...defaultValue === null ? [] : [`@default(${defaultValue})`],
490
- ...field.isUpdatedAt ? ["@updatedAt"] : [],
491
- ...field.dbName ? [`@map(${JSON.stringify(field.dbName)})`] : [],
597
+ ...field.isUpdatedAt === true ? ["@updatedAt"] : [],
598
+ ...isFilled(field.dbName) ? [`@map(${JSON.stringify(field.dbName)})`] : [],
492
599
  ...nativeType === null ? [] : [nativeType],
493
600
  ...relationAttribute === null ? [] : [relationAttribute]
494
601
  ];
495
- const relation = field.kind === "object" && field.relationName ? {
496
- name: field.relationName,
497
- fromFields: [...field.relationFromFields ?? []],
498
- toFields: [...field.relationToFields ?? []],
499
- onDelete: field.relationOnDelete ?? null,
500
- onUpdate: field.relationOnUpdate ?? null
501
- } : null;
602
+ const relation = relationOf(field);
502
603
  return {
503
604
  name: field.name,
504
605
  dbName: field.dbName ?? null,
@@ -639,8 +740,8 @@ function makeModel(input) {
639
740
  indexes: blockIndexes,
640
741
  attributes: [
641
742
  ...blockIndexes.map((i) => i.attribute),
642
- ...model.dbName ? [`@@map(${JSON.stringify(model.dbName)})`] : [],
643
- ...model.schema ? [`@@schema(${JSON.stringify(model.schema)})`] : []
743
+ ...isFilled(model.dbName) ? [`@@map(${JSON.stringify(model.dbName)})`] : [],
744
+ ...isFilled(model.schema) ? [`@@schema(${JSON.stringify(model.schema)})`] : []
644
745
  ],
645
746
  location: makeLocation({
646
747
  blocks,
@@ -1161,6 +1262,21 @@ function runForEngine(dialect, operation) {
1161
1262
  onSuccess: (value) => engineSuccess(value)
1162
1263
  })));
1163
1264
  }
1265
+ /** No value seen yet in a column. */
1266
+ const UNSEEN = Symbol("unseen");
1267
+ /**
1268
+ * A raw statement of the engine. The engine replays a migration file into a shadow database as
1269
+ * one raw statement. A driver prepares one statement at a time and would run only the first of
1270
+ * the file, so a statement with no arguments that is several is run as the script it is.
1271
+ */
1272
+ function executeForEngine(driver, query) {
1273
+ if (driver.dialect === "sqlite" && EXCLUSIVE_LOCK.test(query.sql)) return Promise.resolve(engineSuccess(0));
1274
+ if (query.args.length === 0 && splitStatements(query.sql).filter((statement) => statement.trim() !== "").length > 1) return runForEngine(driver.dialect, driver.executeScript(query.sql).pipe(Effect.as(0)));
1275
+ return runForEngine(driver.dialect, driver.executeRaw({
1276
+ sql: query.sql,
1277
+ params: query.args
1278
+ }));
1279
+ }
1164
1280
  /**
1165
1281
  * The open connection the engine sends its statements through. Only `queryRaw`, `executeRaw` and
1166
1282
  * `executeScript` are ever reached for: the schema engine reads catalogues and runs DDL, and does
@@ -1174,10 +1290,12 @@ function connection(driver, dispose = () => Promise.resolve(engineSuccess(void 0
1174
1290
  sql: query.sql,
1175
1291
  params: query.args
1176
1292
  }).pipe(Effect.map((rows) => {
1293
+ const firstValues = rows.rows.reduce((found, row) => found.map((value, index) => value === UNSEEN && row[index] !== null ? row[index] : value), rows.columns.map(() => UNSEEN));
1177
1294
  const columnTypes = rows.columns.map((column, index) => {
1178
1295
  const declared = columnTypeOfNative(driver.dialect, column.nativeType);
1179
1296
  if (declared !== null) return declared;
1180
- return columnTypeOfValue(rows.rows.find((candidate) => candidate[index] !== null)?.[index] ?? null);
1297
+ const first = firstValues[index];
1298
+ return columnTypeOfValue(first === UNSEEN ? null : first ?? null);
1181
1299
  });
1182
1300
  return {
1183
1301
  columnNames: rows.columns.map((column) => column.name),
@@ -1188,10 +1306,7 @@ function connection(driver, dispose = () => Promise.resolve(engineSuccess(void 0
1188
1306
  }))
1189
1307
  };
1190
1308
  }))),
1191
- executeRaw: (query) => driver.dialect === "sqlite" && EXCLUSIVE_LOCK.test(query.sql) ? Promise.resolve(engineSuccess(0)) : query.args.length === 0 && splitStatements(query.sql).filter((statement) => statement.trim() !== "").length > 1 ? runForEngine(driver.dialect, driver.executeScript(query.sql).pipe(Effect.as(0))) : runForEngine(driver.dialect, driver.executeRaw({
1192
- sql: query.sql,
1193
- params: query.args
1194
- })),
1309
+ executeRaw: (query) => executeForEngine(driver, query),
1195
1310
  executeScript: (script) => runForEngine(driver.dialect, driver.executeScript(script)),
1196
1311
  dispose
1197
1312
  };
@@ -1282,7 +1397,7 @@ function instantiate() {
1282
1397
  return yield* Effect.try({
1283
1398
  try: () => {
1284
1399
  const instance = new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.from(bytes)), { "./schema_engine_bg.js": bindings });
1285
- const result = WasmStart.safeParse(instance.exports.__wbindgen_start);
1400
+ const result = WasmStart.safeParse(instance.exports["__wbindgen_start"]);
1286
1401
  if (!result.success) throw new TypeError("The engine module exports no __wbindgen_start.");
1287
1402
  bindings.__wbg_set_wasm(instance.exports);
1288
1403
  result.data();
@@ -1478,4 +1593,4 @@ function openNativeSchemaEngine(input) {
1478
1593
  }
1479
1594
  };
1480
1595
  }
1481
- export { makeOfflineSchemaEngineAdapter as a, makeSchema as c, erRelations as d, inferredERRelations as f, openSchemaEngine as i, annotatedERRelations as l, openNativeSchemaEngine as n, makeSchemaEngineAdapter as o, engineCommand as r, makeAnalysisSchema as s, findSchemaEngineBinary as t, erKey as u };
1596
+ export { stripAnnotations as _, makeOfflineSchemaEngineAdapter as a, makeSchema as c, erRelations as d, inferredERRelations as f, makeValidationExtractor as g, isAnnotationLine as h, openSchemaEngine as i, annotatedERRelations as l, extractObjectType as m, openNativeSchemaEngine as n, makeSchemaEngineAdapter as o, docBlockLines as p, engineCommand as r, makeAnalysisSchema as s, findSchemaEngineBinary as t, erKey as u };