hekireki 0.23.0 → 0.30.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 (62) hide show
  1. package/dist/bin/hekireki.js +25 -21
  2. package/dist/index.d.ts +5 -5
  3. package/dist/studio/assets/chip-BasDLVHw.js +1 -0
  4. package/dist/studio/assets/client-Cml1DF4R.js +2 -0
  5. package/dist/studio/assets/{code-block-BjrKQVTG.js → code-block-ON7BoQW2.js} +1 -1
  6. package/dist/studio/assets/confirm-dialog-IdKC4Tr2.js +1 -0
  7. package/dist/studio/assets/copy-D3Vc_bt4.js +1 -0
  8. package/dist/studio/assets/copy-button-CbaXuxba.js +1 -0
  9. package/dist/studio/assets/dist-DmM7_t8o.js +13 -0
  10. package/dist/studio/assets/{docs-CkqYk8Me.js → docs-ExwrGDZu.js} +1 -1
  11. package/dist/studio/assets/editor.worker-BbVB3hfz.js +33 -0
  12. package/dist/studio/assets/{enums._name-Bgr8KpI7.js → enums._name-C9BGV9--.js} +1 -1
  13. package/dist/studio/assets/hooks-B5oExX5W.js +55 -0
  14. package/dist/studio/assets/index-6aoNJjln.css +2 -0
  15. package/dist/studio/assets/index-ClVBmPHO.js +16 -0
  16. package/dist/studio/assets/labels-C7nHuKvb.js +1 -0
  17. package/dist/studio/assets/lazyRouteComponent-CDmLrXMS.js +1 -0
  18. package/dist/studio/assets/lu-BrVGIhAn.js +7 -0
  19. package/dist/studio/assets/marked-text-BRnsKz9k.js +3 -0
  20. package/dist/studio/assets/models._name-ByPeXRmm.js +1 -0
  21. package/dist/studio/assets/{monaco-gMjyryJ5.js → monaco-DbPgUJqj.js} +45 -45
  22. package/dist/studio/assets/monaco-GJe6VaZ-.js +11 -0
  23. package/dist/studio/assets/{not-found-CeYHDNqo.js → not-found-yBWFg0rP.js} +1 -1
  24. package/dist/studio/assets/{prisma-BO0BCCER.js → prisma-BnoDMkaK.js} +2 -2
  25. package/dist/studio/assets/result-table-CpErC1Pk.js +1 -0
  26. package/dist/studio/assets/routes-CKzRT8uT.js +1 -0
  27. package/dist/studio/assets/{schema-gate-CsCy68T_.js → schema-gate-B50_6S0h.js} +1 -1
  28. package/dist/studio/assets/schema-view-fqeCWRR2.js +9 -0
  29. package/dist/studio/assets/sql-CRhtXB4v.js +6 -0
  30. package/dist/studio/assets/table-Rze42PM3.js +1 -0
  31. package/dist/studio/assets/tabs-ClImdGQ1.js +1 -0
  32. package/dist/studio/assets/useFormValidation-Bgjs6o3Q.js +1 -0
  33. package/dist/studio/assets/useMatch-DMTwaRaz.js +1 -0
  34. package/dist/studio/assets/useMultipleSelectionState-DUiRXMUh.js +1 -0
  35. package/dist/studio/assets/{useOverlayTriggerState-vyNglC3z.js → useOverlayTriggerState-2DwfYtnL.js} +1 -1
  36. package/dist/studio/index.html +10 -10
  37. package/package.json +37 -37
  38. package/dist/studio/assets/chip-DktDoVzE.js +0 -1
  39. package/dist/studio/assets/client-Dr3jviL4.js +0 -2
  40. package/dist/studio/assets/confirm-dialog-DyTVsQSX.js +0 -1
  41. package/dist/studio/assets/copy-BiNLD_lP.js +0 -1
  42. package/dist/studio/assets/copy-button-BVg2tjZ8.js +0 -1
  43. package/dist/studio/assets/dist-B67qd3Zz.js +0 -13
  44. package/dist/studio/assets/editor.worker-D9zwrD0f.js +0 -30
  45. package/dist/studio/assets/hooks-D5FHpZ7j.js +0 -50
  46. package/dist/studio/assets/index-DOc026EB.css +0 -2
  47. package/dist/studio/assets/index-S7nroM-z.js +0 -16
  48. package/dist/studio/assets/labels-BNvY0cN5.js +0 -1
  49. package/dist/studio/assets/lazyRouteComponent-CAes9Xsr.js +0 -1
  50. package/dist/studio/assets/lu-d7uRxrOD.js +0 -7
  51. package/dist/studio/assets/marked-text-BdD2j0fn.js +0 -3
  52. package/dist/studio/assets/models._name-D4_ZANEh.js +0 -1
  53. package/dist/studio/assets/monaco-DcZOWb7S.js +0 -11
  54. package/dist/studio/assets/result-table-88RDb-mF.js +0 -1
  55. package/dist/studio/assets/routes-CcWfWQAl.js +0 -1
  56. package/dist/studio/assets/schema-view-nvsbR-7o.js +0 -8
  57. package/dist/studio/assets/sql-Dz7KO9RT.js +0 -6
  58. package/dist/studio/assets/table-Dh7RyVup.js +0 -1
  59. package/dist/studio/assets/tabs-Den1DTwv.js +0 -1
  60. package/dist/studio/assets/useFormValidation-DYw-_Bbl.js +0 -1
  61. package/dist/studio/assets/useMatch-Bfhrp9go.js +0 -1
  62. package/dist/studio/assets/useMultipleSelectionState-7x90tUim.js +0 -1
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { t as exists } from "../file-BPNqvwXD.js";
3
3
  import { NodeRuntime, NodeServices } from "@effect/platform-node";
4
- import { Config, Console, Data, Effect, Option, Schema, Stdio } from "effect";
4
+ import { Console, Data, Effect, Option, Schema, Stdio } from "effect";
5
5
  import path from "node:path";
6
6
  import { CliError, Command, Flag } from "effect/unstable/cli";
7
7
  //#region package.json
8
- var version = "0.23.0";
8
+ var version = "0.30.0";
9
9
  //#endregion
10
10
  //#region src/studio/server/constants/index.ts
11
11
  /** Studio only listens on loopback: the API serves the raw schema and runs SQL without authentication. */
@@ -70,10 +70,14 @@ function studioBanner(options) {
70
70
  ...options.error === null ? [] : [` Schema has errors, fix them and Studio will reload:\n${options.error}`]
71
71
  ].join("\n");
72
72
  }
73
+ const Port = Schema.Int.check(Schema.isBetween({
74
+ minimum: 1,
75
+ maximum: 65535
76
+ }));
73
77
  const studioFlags = {
74
- port: Flag.integer("port").pipe(Flag.withAlias("p"), Flag.withSchema(Config.Port), Flag.withDescription(`Port to listen on (default: ${DEFAULT_PORT})`), Flag.withMetavar("port"), Flag.withDefault(DEFAULT_PORT)),
75
- schema: Flag.string("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.optional),
76
- url: Flag.string("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL for browsing and editing data (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.optional)
78
+ port: Flag.Int("port").pipe(Flag.withAlias("p"), Flag.withSchema(Port), Flag.withDescription(`Port to listen on (default: ${DEFAULT_PORT})`), Flag.withMetavar("port"), Flag.withDefault(DEFAULT_PORT)),
79
+ schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.optional),
80
+ url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL for browsing and editing data (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.optional)
77
81
  };
78
82
  function runStudio(args) {
79
83
  return Effect.gen(function* () {
@@ -113,14 +117,14 @@ const studio = Command.make("studio", studioFlags, runStudio).pipe(Command.withD
113
117
  }
114
118
  ]));
115
119
  const seedFlags = {
116
- config: Flag.string("config").pipe(Flag.withAlias("c"), Flag.withDescription("Path to the config, a TypeScript file (default: hekireki.config.ts in the working directory)"), Flag.withMetavar("hekireki.config.ts"), Flag.optional),
117
- schema: Flag.string("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: \`schema\` in the config, then ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.optional),
118
- url: Flag.string("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to insert into (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.optional),
119
- sql: Flag.string("sql").pipe(Flag.withDescription("Write the rows to this SQL file instead of inserting them"), Flag.withMetavar("seed.sql"), Flag.optional),
120
- seed: Flag.integer("seed").pipe(Flag.withDescription("The faker seed; the same seed always gives the same rows (left out: every run differs)"), Flag.withMetavar("n"), Flag.optional),
121
- count: Flag.integer("count").pipe(Flag.withAlias("n"), Flag.withDescription("Rows for every faker model, over the per-model counts of the config; models given as data keep their rows (left out: the config decides, and only the configured models are seeded)"), Flag.withMetavar("rows"), Flag.optional),
122
- locale: Flag.string("locale").pipe(Flag.withAlias("l"), Flag.withDescription("Faker locale, or a comma-separated list tried in order (left out: faker's English)"), Flag.withMetavar("ja,en"), Flag.optional),
123
- reset: Flag.boolean("reset").pipe(Flag.withDescription("Delete every row of the seeded tables before inserting"), Flag.withDefault(false))
120
+ config: Flag.String("config").pipe(Flag.withAlias("c"), Flag.withDescription("Path to the config, a TypeScript file (default: hekireki.config.ts in the working directory)"), Flag.withMetavar("hekireki.config.ts"), Flag.optional),
121
+ schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to schema.prisma or a directory of .prisma files (default: \`schema\` in the config, then ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.optional),
122
+ url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to insert into (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.optional),
123
+ sql: Flag.String("sql").pipe(Flag.withDescription("Write the rows to this SQL file instead of inserting them"), Flag.withMetavar("seed.sql"), Flag.optional),
124
+ seed: Flag.Int("seed").pipe(Flag.withDescription("The faker seed; the same seed always gives the same rows (left out: every run differs)"), Flag.withMetavar("n"), Flag.optional),
125
+ count: Flag.Int("count").pipe(Flag.withAlias("n"), Flag.withDescription("Rows for every faker model, over the per-model counts of the config; models given as data keep their rows (left out: the config decides, and only the configured models are seeded)"), Flag.withMetavar("rows"), Flag.optional),
126
+ locale: Flag.String("locale").pipe(Flag.withAlias("l"), Flag.withDescription("Faker locale, or a comma-separated list tried in order (left out: faker's English)"), Flag.withMetavar("ja,en"), Flag.optional),
127
+ reset: Flag.Boolean("reset").pipe(Flag.withDescription("Delete every row of the seeded tables before inserting"), Flag.withDefault(false))
124
128
  };
125
129
  function runSeedCommand(args) {
126
130
  return Effect.gen(function* () {
@@ -157,11 +161,11 @@ const seed = Command.make("seed", seedFlags, runSeedCommand).pipe(Command.withDe
157
161
  }
158
162
  ]));
159
163
  const migrateCheckFlags = {
160
- schema: Flag.string("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to the schema about to be migrated: schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.optional),
161
- url: Flag.string("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to check, read only (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.optional),
162
- decisions: Flag.string("decisions").pipe(Flag.withAlias("d"), Flag.withDescription("Path to the decisions made on the Migrate page of `hekireki studio`: what becomes of the rows that stand in the way (default: .hekireki/migrate.json beside the schema)"), Flag.withMetavar("migrate.json"), Flag.optional),
163
- timeout: Flag.integer("timeout").pipe(Flag.withDescription("How long one query may run, in milliseconds, on PostgreSQL and MySQL (default: no limit)"), Flag.withMetavar("ms"), Flag.optional),
164
- json: Flag.boolean("json").pipe(Flag.withDescription("Print the report as JSON, every check with its count and SQL"), Flag.withDefault(false))
164
+ schema: Flag.String("schema").pipe(Flag.withAlias("s"), Flag.withDescription(`Path to the schema about to be migrated: schema.prisma or a directory of .prisma files (default: ${DEFAULT_SCHEMA_PATHS.join(", then ")})`), Flag.withMetavar("schema.prisma|dir"), Flag.optional),
165
+ url: Flag.String("url").pipe(Flag.withAlias("u"), Flag.withSchema(DatabaseUrl), Flag.withDescription("Database connection URL to check, read only (default: `url` in hekireki.config.ts, then the variable datasource.url names in prisma.config.ts or the schema, read from the environment or .env; DATABASE_URL when it names none)"), Flag.withMetavar("connection-string"), Flag.optional),
166
+ decisions: Flag.String("decisions").pipe(Flag.withAlias("d"), Flag.withDescription("Path to the decisions made on the Migrate page of `hekireki studio`: what becomes of the rows that stand in the way (default: .hekireki/migrate.json beside the schema)"), Flag.withMetavar("migrate.json"), Flag.optional),
167
+ timeout: Flag.Int("timeout").pipe(Flag.withDescription("How long one query may run, in milliseconds, on PostgreSQL and MySQL (default: no limit)"), Flag.withMetavar("ms"), Flag.optional),
168
+ json: Flag.Boolean("json").pipe(Flag.withDescription("Print the report as JSON, every check with its count and SQL"), Flag.withDefault(false))
165
169
  };
166
170
  /** The command line of `migrate check` as the runner reads it. */
167
171
  function migrateInput(args, schemaPath) {
@@ -215,9 +219,9 @@ const migratePlanFlags = {
215
219
  url: migrateCheckFlags.url,
216
220
  decisions: migrateCheckFlags.decisions,
217
221
  timeout: migrateCheckFlags.timeout,
218
- migration: Flag.string("migration").pipe(Flag.withAlias("m"), Flag.withDescription("The migration.sql Prisma wrote for the schema (`prisma migrate dev --create-only`): the plan is then the whole migration, the fixes first and what the migration itself has to do written into Prisma's statements"), Flag.withMetavar("migration.sql"), Flag.optional),
219
- batch: Flag.integer("batch").pipe(Flag.withDescription("Run a fix over more rows than this that many at a time, one statement after another, so none holds its locks for the whole table (default: every fix in one statement; no effect inside the one DO block of PostgreSQL)"), Flag.withMetavar("rows"), Flag.optional),
220
- output: Flag.string("output").pipe(Flag.withAlias("o"), Flag.withDescription("Write the SQL to this file and print the report (default: the SQL to stdout)"), Flag.withMetavar("fixes.sql"), Flag.optional)
222
+ migration: Flag.String("migration").pipe(Flag.withAlias("m"), Flag.withDescription("The migration.sql Prisma wrote for the schema (`prisma migrate dev --create-only`): the plan is then the whole migration, the fixes first and what the migration itself has to do written into Prisma's statements"), Flag.withMetavar("migration.sql"), Flag.optional),
223
+ batch: Flag.Int("batch").pipe(Flag.withDescription("Run a fix over more rows than this that many at a time, one statement after another, so none holds its locks for the whole table (default: every fix in one statement; no effect inside the one DO block of PostgreSQL)"), Flag.withMetavar("rows"), Flag.optional),
224
+ output: Flag.String("output").pipe(Flag.withAlias("o"), Flag.withDescription("Write the SQL to this file and print the report (default: the SQL to stdout)"), Flag.withMetavar("fixes.sql"), Flag.optional)
221
225
  };
222
226
  function runMigratePlanCommand(args) {
223
227
  return Effect.gen(function* () {
package/dist/index.d.ts CHANGED
@@ -43,7 +43,7 @@ type SeedSchema = {
43
43
  readonly enums: readonly SeedEnumInfo[];
44
44
  };
45
45
  /** Keeps every model, field and enum member name of the generated schema module as a literal type. */
46
- declare function defineSchema<const S extends SeedSchema>(schema: S): S;
46
+ export declare function defineSchema<const S extends SeedSchema>(schema: S): S;
47
47
  type ModelNamed<S extends SeedSchema, M> = Extract<S['models'][number], {
48
48
  readonly name: M;
49
49
  }>;
@@ -143,7 +143,7 @@ type Data<S extends SeedSchema, M extends ModelName<S>, Filled extends string =
143
143
  * file: `export const users = defineData(schema, 'User', [{ email: '...', name: '...' }])`. The
144
144
  * rows are returned as they are; the check is the same one `defineConfig` makes.
145
145
  */
146
- declare function defineData<const S extends SeedSchema, M extends ModelName<S>>(schema: S, model: M, rows: NoInfer<Data<S, M>>): Data<S, M, never>;
146
+ export declare function defineData<const S extends SeedSchema, M extends ModelName<S>>(schema: S, model: M, rows: NoInfer<Data<S, M>>): Data<S, M, never>;
147
147
  /**
148
148
  * How one field is filled: a function of the seeded faker and the row so far, or bounds that fit
149
149
  * the field's type. `value` fixes it, `values` draws from a list (enum members by Prisma name).
@@ -261,7 +261,7 @@ type SeedConfig = CommonOptions & {
261
261
  * and bound is checked against the Prisma schema and rule functions know the row they see.
262
262
  * Without one, any model and field name is accepted.
263
263
  */
264
- declare function defineConfig<const S extends SeedSchema>(schema: S, config: NoInfer<TypedSeedConfig<S>>): SeedConfig;
265
- declare function defineConfig(config: SeedConfig): SeedConfig;
264
+ export declare function defineConfig<const S extends SeedSchema>(schema: S, config: NoInfer<TypedSeedConfig<S>>): SeedConfig;
265
+ export declare function defineConfig(config: SeedConfig): SeedConfig;
266
266
  //#endregion
267
- export { type Data, type DataRow, type FieldRule, type FieldValue, type JsonValue, type KeyOf, type LooseFieldRule, type LooseModelRule, type ModelName, type ModelRule, type RelationRule, type Row, type RowOf, type SeedConfig, type SeedEnumInfo, type SeedFieldInfo, type SeedModelInfo, type SeedRow, type SeedSchema, type SeedValue, type TypedSeedConfig, defineConfig, defineData, defineSchema };
267
+ export type { Data, DataRow, FieldRule, FieldValue, JsonValue, KeyOf, LooseFieldRule, LooseModelRule, ModelName, ModelRule, RelationRule, Row, RowOf, SeedConfig, SeedEnumInfo, SeedFieldInfo, SeedModelInfo, SeedRow, SeedSchema, SeedValue, TypedSeedConfig };
@@ -0,0 +1 @@
1
+ import{Ft as e,Gt as t,It as n,Jt as r,Pt as i,St as a}from"./hooks-B5oExX5W.js";var o=i({defaultVariants:{color:`default`,variant:`secondary`},slots:{base:`chip`,label:`chip__label`},variants:{color:{accent:{base:`chip--accent`},danger:{base:`chip--danger`},default:{base:`chip--default`},success:{base:`chip--success`},warning:{base:`chip--warning`}},size:{lg:{base:`chip--lg`},md:{base:`chip--md`},sm:{base:`chip--sm`}},variant:{primary:{base:`chip--primary`},secondary:{base:`chip--secondary`},soft:{base:`chip--soft`},tertiary:{base:`chip--tertiary`}}}}),s=r(t(),1),c=n(),l=(0,s.createContext)({}),u=({children:t,className:n,color:r,size:i,variant:u,...f})=>{let p=s.useMemo(()=>o({color:r,size:i,variant:u}),[r,i,u]),m=s.useMemo(()=>typeof t==`string`||typeof t==`number`?(0,c.jsx)(d,{children:t}):t,[t]),h=s.useMemo(()=>({slots:p}),[p]);return(0,c.jsx)(l,{value:h,children:(0,c.jsx)(e.span,{...f,className:a(p.base,n),"data-slot":`chip`,children:m})})},d=({children:t,className:n,...r})=>{let{slots:i}=(0,s.use)(l);return(0,c.jsx)(e.span,{className:a(i?.label,n),"data-slot":`chip-label`,...r,children:t})},f=Object.assign(u,{Root:u,Label:d});export{f as t};
@@ -0,0 +1,2 @@
1
+ import{Gt as e,It as t,Jt as n,N as r,P as i,bt as a,c as o,l as s,nt as c,p as l,t as u,tt as d,v as f,y as p}from"./hooks-B5oExX5W.js";import{B as m,W as h,Y as g,d as _,j as v,ut as y}from"./lu-BrVGIhAn.js";import{t as ee}from"./confirm-dialog-IdKC4Tr2.js";import{d as te}from"./marked-text-BRnsKz9k.js";import{t as b}from"./tabs-ClImdGQ1.js";import{a as ne}from"./labels-C7nHuKvb.js";import{n as re}from"./copy-D3Vc_bt4.js";import{c as x,i as S,o as C,u as w}from"./monaco-DbPgUJqj.js";import{u as ie}from"./index-ClVBmPHO.js";import{n as ae,r as oe,t as se}from"./result-table-CpErC1Pk.js";import{t as ce}from"./schema-view-fqeCWRR2.js";import{a as T,s as E,t as le,u as D}from"./monaco-GJe6VaZ-.js";import{t as O}from"./code-block-ON7BoQW2.js";import{t as k}from"./copy-button-CbaXuxba.js";var A=n(e(),1),j={models:[],typesAvailable:!1};function M(e,t){let n=e.getPositionAt(t.start),r=e.getPositionAt(t.end);return new C(n.lineNumber,n.column,r.lineNumber,r.column)}function N(e,t){let n=e.getWordUntilPosition(t);return new C(t.lineNumber,n.startColumn,t.lineNumber,n.endColumn)}var P={findMany:{write:!1,detail:`every matching row`,args:[`where`,`select`,`include`,`omit`,`orderBy`,`cursor`,`take`,`skip`,`distinct`]},findFirst:{write:!1,detail:`the first matching row, or null`,args:[`where`,`select`,`include`,`omit`,`orderBy`,`cursor`,`take`,`skip`,`distinct`]},findFirstOrThrow:{write:!1,detail:`the first matching row, or an error`,args:[`where`,`select`,`include`,`omit`,`orderBy`,`cursor`,`take`,`skip`,`distinct`]},findUnique:{write:!1,detail:`the row with this unique key, or null`,args:[`where`,`select`,`include`,`omit`]},findUniqueOrThrow:{write:!1,detail:`the row with this unique key, or an error`,args:[`where`,`select`,`include`,`omit`]},count:{write:!1,detail:`how many rows match`,args:[`where`,`select`,`orderBy`,`cursor`,`take`,`skip`]},aggregate:{write:!1,detail:`_count, _avg, _sum, _min, _max`,args:[`where`,`orderBy`,`cursor`,`take`,`skip`,`_count`,`_avg`,`_sum`,`_min`,`_max`]},groupBy:{write:!1,detail:`aggregates per group`,args:[`by`,`where`,`orderBy`,`having`,`take`,`skip`,`_count`,`_avg`,`_sum`,`_min`,`_max`]},create:{write:!0,detail:`insert one row`,args:[`data`,`select`,`include`,`omit`]},createMany:{write:!0,detail:`insert rows`,args:[`data`,`skipDuplicates`]},createManyAndReturn:{write:!0,detail:`insert rows and return them`,args:[`data`,`select`,`include`,`omit`,`skipDuplicates`]},update:{write:!0,detail:`change one row`,args:[`where`,`data`,`select`,`include`,`omit`]},updateMany:{write:!0,detail:`change every matching row`,args:[`where`,`data`,`limit`]},updateManyAndReturn:{write:!0,detail:`change matching rows and return them`,args:[`where`,`data`,`select`,`include`,`omit`,`limit`]},upsert:{write:!0,detail:`update one row, or create it`,args:[`where`,`create`,`update`,`select`,`include`,`omit`]},delete:{write:!0,detail:`delete one row`,args:[`where`,`select`,`include`,`omit`]},deleteMany:{write:!0,detail:`delete every matching row`,args:[`where`,`limit`]}};function F(e){return`${e.charAt(0).toLowerCase()}${e.slice(1)}`}var I={kind:`none`},L=[`select`,`include`,`omit`,`where`,`orderBy`,`cursor`,`take`,`skip`,`distinct`],R=new Set([`Int`,`BigInt`,`Float`,`Decimal`,`DateTime`]);function z(e,t,n){if(e.kind===`none`||e.kind===`filter`)return e.kind===`filter`&&t===`not`?e:I;let{model:r}=e,i=r.fields.find(e=>e.name===t),a=i?.kind===`object`?n.find(e=>e.name===i.type):void 0,o=e=>({kind:e,model:r});switch(e.kind){case`args`:case`relation`:case`nested`:return t===`where`||t===`having`||t===`cursor`?o(`where`):t===`select`||t===`include`||t===`omit`||t===`orderBy`?o(t):t===`data`||t===`create`||t===`update`?o(`data`):t===`_count`?e.kind===`args`&&e.operation!==`count`?o(`fields`):I:t===`_avg`||t===`_sum`||t===`_min`||t===`_max`?o(`fields`):I;case`where`:case`isIsNot`:return t===`AND`||t===`OR`||t===`NOT`||e.kind===`isIsNot`&&(t===`is`||t===`isNot`)?o(`where`):a!==void 0&&i!==void 0?{kind:i.isList?`someEveryNone`:`isIsNot`,model:a}:i===void 0?I:{kind:`filter`,field:i};case`someEveryNone`:return t===`some`||t===`every`||t===`none`?o(`where`):I;case`select`:case`include`:return t===`_count`?{kind:`count`,model:r}:a!==void 0&&i!==void 0?{kind:`relation`,model:a,list:i.isList}:I;case`count`:return t===`select`?{kind:`countFields`,model:r}:I;case`orderBy`:return a===void 0||i===void 0?I:i.isList?{kind:`fields`,model:a}:{kind:`orderBy`,model:a};case`data`:return a!==void 0&&i!==void 0?{kind:`write`,model:a,list:i.isList}:I;case`write`:return t===`create`?{kind:`data`,model:r}:t===`createMany`||t===`connectOrCreate`||t===`upsert`||t===`updateMany`?{kind:`nested`,model:r}:t===`update`?e.list?{kind:`nested`,model:r}:{kind:`data`,model:r}:[`connect`,`disconnect`,`set`,`delete`,`deleteMany`].includes(t)?{kind:`where`,model:r}:I;case`omit`:case`fields`:case`countFields`:return I;default:return e}}function B(e,t){return{label:e,detail:t,kind:`argument`}}function V(e){return{label:e.name,detail:`${e.type}${e.isList?`[]`:``}`,kind:`field`}}function H(e,t){if(e.kind===`delegate`)return[...t.map(e=>({label:F(e.name),detail:`model ${e.name}`,kind:`model`})),{label:`$transaction`,detail:`run several calls as one batch`,kind:`operation`}];let n=t.find(t=>F(t.name)===e.delegate);if(n===void 0)return[];if(e.kind===`operation`)return Object.entries(P).map(([e,t])=>({label:e,detail:`${t.write?`write`:`read`} · ${t.detail}`,kind:`operation`}));let r=e.path.reduce((e,n)=>z(e,n,t),{kind:`args`,model:n,operation:e.operation});if(r.kind===`none`)return[];if(r.kind===`filter`){let{field:e}=r;return(e.isList?[`has`,`hasEvery`,`hasSome`,`isEmpty`,`equals`]:e.kind===`enum`?[`equals`,`not`,`in`,`notIn`]:e.type===`String`?[`equals`,`not`,`in`,`notIn`,`contains`,`startsWith`,`endsWith`,`mode`,`lt`,`lte`,`gt`,`gte`]:R.has(e.type)?[`equals`,`not`,`in`,`notIn`,`lt`,`lte`,`gt`,`gte`]:e.type===`Json`?[`equals`,`not`,`path`,`string_contains`,`array_contains`]:[`equals`,`not`]).map(t=>B(t,`${e.type} filter`))}let{model:i}=r,a=i.fields.filter(e=>e.kind!==`object`),o=i.fields.filter(e=>e.kind===`object`);switch(r.kind){case`args`:return(P[r.operation]?.args??[]).map(e=>B(e,`${i.name}.${r.operation}`));case`where`:return[...i.fields.map(V),...[`AND`,`OR`,`NOT`].map(e=>B(e,`${i.name}WhereInput`))];case`isIsNot`:return[...[`is`,`isNot`].map(e=>B(e,`${i.name}WhereInput`)),...i.fields.map(V)];case`someEveryNone`:return[`some`,`every`,`none`].map(e=>B(e,`${i.name}WhereInput`));case`select`:return[...i.fields.map(V),B(`_count`,`relation counts`)];case`include`:return[...o.map(V),B(`_count`,`relation counts`)];case`relation`:return(r.list?L:[`select`,`include`,`omit`]).map(e=>B(e,i.name));case`count`:return[B(`select`,`the relations to count`)];case`countFields`:return o.filter(e=>e.isList).map(V);case`omit`:case`fields`:return a.map(V);case`orderBy`:case`data`:return i.fields.map(V);case`write`:return(r.list?[`create`,`createMany`,`connect`,`connectOrCreate`,`disconnect`,`set`,`delete`,`deleteMany`,`update`,`updateMany`,`upsert`]:[`create`,`connect`,`connectOrCreate`,`disconnect`,`delete`,`update`,`upsert`]).map(e=>B(e,`nested write to ${i.name}`));case`nested`:return[`where`,`create`,`update`,`data`,`skipDuplicates`].map(e=>B(e,i.name));default:return r}}var U=/\/\/[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?|`(?:[^`\\]|\\[\s\S])*`?|[A-Za-z_$][\w$]*|\d[\w.]*|\S/gu,W=/^[A-Za-z_$][\w$]*$/u;function G(e){let t=e.text[0]??``;return e.text.startsWith(`/*`)?!e.text.endsWith(`*/`)||e.text.length<4:e.text.startsWith(`//`)?!0:`"'\``.includes(t)&&(e.text.length<2||!e.text.endsWith(t))}function K(e){return e.reduce((t,n,r)=>{let i=e[r-1]?.text??``;if(n.text===`:`&&(W.test(i)||/^["']/u.test(i)))return{...t,key:i.replaceAll(/^["']|["']$/gu,``)};if(n.text===`{`||n.text===`[`){let e=n.text===`{`?`object`:`array`;return{frames:[...t.frames,{kind:e,key:t.key}],key:null}}if(n.text===`(`){let[n,i,a,o,s]=e.slice(r-5,r),c=n!==void 0&&W.test(n.text)&&i?.text===`.`&&a!==void 0&&W.test(a.text)&&o?.text===`.`&&s!==void 0&&W.test(s.text)&&!a.text.startsWith(`$`)?{kind:`call`,delegate:a.text,operation:s.text}:{kind:`paren`};return{frames:[...t.frames,c],key:null}}return n.text===`}`||n.text===`]`||n.text===`)`?{frames:t.frames.slice(0,-1),key:null}:n.text===`,`?{...t,key:null}:t},{frames:[],key:null})}function q(e,t){let n=[...e.slice(0,t).matchAll(U)].map(e=>({text:e[0],start:e.index,end:e.index+e[0].length})),r=n.at(-1),i=r?.end===t?r:null;if(i!==null&&G(i))return null;let a=i!==null&&W.test(i.text)?i:null,o=a?.start??t,s=(a===null?n:n.slice(0,-1)).filter(e=>!e.text.startsWith(`//`)&&!e.text.startsWith(`/*`)),[c,l,u,d]=s.slice(-4);if(d?.text===`.`&&u!==void 0&&W.test(u.text))return l?.text===`.`&&c!==void 0&&W.test(c.text)?{kind:`operation`,delegate:u.text,from:o}:null;let f=s.at(-1);if(f?.text===`.`){let e=s.at(-2),t=s.at(-3);return e!==void 0&&W.test(e.text)&&t?.text!==`.`?{kind:`delegate`,from:o}:null}if(f?.text!==`{`&&f?.text!==`,`)return null;let{frames:p}=K(s);if(p.at(-1)?.kind!==`object`)return null;let m=p.findLastIndex(e=>e.kind===`call`),h=p[m];if(h?.kind!==`call`)return null;let g=p.slice(m+1);if(g.some(e=>e.kind===`paren`||e.kind===`call`))return null;let _=g.flatMap(e=>(e.kind===`object`||e.kind===`array`)&&e.key!==null?[e.key]:[]);return{kind:`key`,delegate:h.delegate,operation:h.operation,path:_,from:o}}var J=new Map([[`method`,`Method`],[`function`,`Function`],[`local function`,`Function`],[`construct`,`Constructor`],[`constructor`,`Constructor`],[`property`,`Property`],[`getter`,`Property`],[`setter`,`Property`],[`var`,`Variable`],[`let`,`Variable`],[`const`,`Constant`],[`local var`,`Variable`],[`parameter`,`Variable`],[`alias`,`Variable`],[`class`,`Class`],[`local class`,`Class`],[`interface`,`Interface`],[`type`,`Struct`],[`primitive type`,`Struct`],[`type parameter`,`TypeParameter`],[`enum`,`Enum`],[`enum member`,`EnumMember`],[`module`,`Module`],[`external_module`,`Module`],[`keyword`,`Keyword`],[`string`,`Text`],[`directory`,`Folder`],[`script`,`File`]]);function ue(e){return J.get(e)??`Text`}var Y=new WeakMap;function X(){return{triggerCharacters:[`.`,`{`,`,`,`"`,`'`],provideCompletionItems:async(e,t)=>{let n=e.getValue(),a=e.getOffsetAt(t),o=N(e,t);if(!j.typesAvailable){let e=q(n,a);return e===null?null:{suggestions:H(e,j.models).map(e=>({label:e.label,detail:e.detail,kind:w.CompletionItemKind[e.kind===`model`?`Class`:e.kind===`operation`?`Method`:e.kind===`argument`?`Keyword`:`Property`],insertText:e.label,range:o}))}}if(n.trim()===``)return null;let s=await i(r.client.complete.$post({json:{query:n,offset:a}})).catch(()=>null);return s===null?null:{suggestions:s.items.map(e=>{let t={label:e.label,kind:w.CompletionItemKind[ue(e.kind)],insertText:e.insertText??e.label,sortText:e.sortText,range:o};return Y.set(t,{query:n,offset:a}),t})}},resolveCompletionItem:async e=>{let t=Y.get(e);if(t===void 0)return e;let n=typeof e.label==`string`?e.label:e.label.label,a=await i(r.client.complete.detail.$post({json:{...t,name:n}})).catch(()=>null);return a===null?e:{...e,detail:a.detail??void 0,documentation:a.documentation===null?void 0:{value:a.documentation}}}}}function de(){return{displayName:`TypeScript`,provideDocumentFormattingEdits:async e=>{let t=e.getValue();if(t.trim()===``)return[];let n=await i(r.client.format.$post({json:{query:t}})).catch(()=>null);return n===null||n.text===t?[]:[{range:e.getFullModelRange(),text:n.text}]}}}function fe(){return{provideHover:async(e,t)=>{if(!j.typesAvailable)return null;let n=e.getValue();if(n.trim()===``)return null;let a=await i(r.client.hover.$post({json:{query:n,offset:e.getOffsetAt(t)}})).catch(()=>null);return a?.contents===null||a?.contents===void 0?null:{contents:[{value:a.contents}],range:a.range===null?N(e,t):M(e,a.range)}}}}var Z=`prisma-client-query`,pe={defaultToken:``,tokenPostfix:`.query`,keywords:[`await`,`new`,`async`,`const`,`let`,`return`,`typeof`],literals:[`true`,`false`,`null`,`undefined`],brackets:[{open:`{`,close:`}`,token:`delimiter.curly`},{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`}],tokenizer:{root:[[/\/\/.*$/u,`comment`],[/\/\*/u,`comment`,`@comment`],[/(\.)(\$?[A-Za-z_][\w$]*)(?=\s*\()/u,[`delimiter`,`function`]],[/(\.)(\$?[A-Za-z_][\w$]*)/u,[`delimiter`,`member`]],[/[A-Za-z_$][\w$]*(?=\s*:)/u,`key`],[/(["'])(?:(?!\1)[^\\\n]|\\.)*\1(?=\s*:)/u,`key`],[/[A-Z][\w$]*/u,`type.identifier`],[/[A-Za-z_$][\w$]*/u,{cases:{prisma:`variable.predefined`,"@keywords":`keyword`,"@literals":`keyword.literal`,"@default":`identifier`}}],[/0[xX][\da-fA-F_]+n?|0[bB][01_]+n?|0[oO][0-7_]+n?/u,`number`],[/(?:\d[\d_]*(?:\.[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?\d+)?n?/u,`number`],[/"([^"\\]|\\.)*$/u,`string.invalid`],[/'([^'\\]|\\.)*$/u,`string.invalid`],[/"/u,{token:`string.quote`,next:`@stringDouble`}],[/'/u,{token:`string.quote`,next:`@stringSingle`}],[/`/u,{token:`string.quote`,next:`@template`}],[/[{}()[\]]/u,`@brackets`],[/[=]>|\.\.\./u,`operator`],[/[,:;.]/u,`delimiter`],[/[-+*/%=<>!&|?]+/u,`operator`],[/\s+/u,`white`]],comment:[[/[^*/]+/u,`comment`],[/\*\//u,`comment`,`@pop`],[/[*/]/u,`comment`]],stringDouble:[[/[^\\"]+/u,`string`],[/\\./u,`string.escape`],[/"/u,{token:`string.quote`,next:`@pop`}]],stringSingle:[[/[^\\']+/u,`string`],[/\\./u,`string.escape`],[/'/u,{token:`string.quote`,next:`@pop`}]],template:[[/\$\{/u,{token:`string.invalid`,next:`@pop`}],[/[^\\`$]+/u,`string`],[/\\./u,`string.escape`],[/`/u,{token:`string.quote`,next:`@pop`}],[/\$/u,`string`]]}},me={comments:{lineComment:`//`,blockComment:[`/*`,`*/`]},brackets:[[`{`,`}`],[`[`,`]`],[`(`,`)`]],autoClosingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`,notIn:[`string`]},{open:`'`,close:`'`,notIn:[`string`]},{open:"`",close:"`",notIn:[`string`]}],surroundingPairs:[{open:`{`,close:`}`},{open:`[`,close:`]`},{open:`(`,close:`)`},{open:`"`,close:`"`},{open:`'`,close:`'`}],wordPattern:/-?\d*\.\d\w*|\$?[A-Za-z_][\w$]*/u};function he(){return{signatureHelpTriggerCharacters:[`(`,`,`],signatureHelpRetriggerCharacters:[`)`],provideSignatureHelp:async(e,t)=>{if(!j.typesAvailable)return null;let n=e.getValue();if(n.trim()===``)return null;let a=await i(r.client.signature.$post({json:{query:n,offset:e.getOffsetAt(t)}})).catch(()=>null);return a===null||a.signatures.length===0?null:{value:{signatures:a.signatures.map(e=>({label:e.label,documentation:e.documentation===null?void 0:{value:e.documentation},parameters:e.parameters.map(e=>({label:e.label,documentation:e.documentation===null?void 0:{value:e.documentation}}))})),activeSignature:a.activeSignature,activeParameter:a.activeParameter},dispose:()=>void 0}}}}var ge=`hekireki-client`,_e={error:S.Error,warning:S.Warning,info:S.Info};function ve(e,t){let n=e.getValueLength();x.setModelMarkers(e,ge,t.map(t=>{let r=Math.max(0,Math.min(t.range.start,n)),i=Math.max(r,Math.min(t.range.end,n)),a=M(e,i>r?{start:r,end:i}:{start:Math.max(0,r-1),end:Math.max(r,1)});return{message:t.message,severity:_e[t.severity],startLineNumber:a.startLineNumber,startColumn:a.startColumn,endLineNumber:a.endLineNumber,endColumn:a.endColumn}}))}var ye={ready:!1};function be(){ye.ready||(ye.ready=!0,w.register({id:Z}),w.setMonarchTokensProvider(Z,pe),w.setLanguageConfiguration(Z,me),w.registerCompletionItemProvider(Z,X()),w.registerHoverProvider(Z,fe()),w.registerSignatureHelpProvider(Z,he()),w.registerDocumentFormattingEditProvider(Z,de()))}var Q=t(),xe=`file:///hekireki-studio-query.ts`;function Se({value:e,onChange:t,onRun:n,onReady:r,models:i,typesAvailable:a,markers:o,selection:s}){let c=T();be();let l=p(e=>e.theme),u=(0,A.useRef)(null),d=(0,A.useRef)({onChange:t,onRun:n});return(0,A.useEffect)(()=>{d.current={onChange:t,onRun:n}}),(0,A.useEffect)(()=>{j.models=i,j.typesAvailable=a},[i,a]),(0,A.useEffect)(()=>{let e=u.current?.getModel();e&&ve(e,o)},[o]),(0,A.useEffect)(()=>{let e=u.current;if(e===null||s===null)return;let t=e.getModel();if(!t)return;let n=t.getPositionAt(s.start),r=t.getPositionAt(s.end);e.setSelection(new c.Range(n.lineNumber,n.column,r.lineNumber,r.column)),e.revealPositionInCenterIfOutsideViewport(n),e.focus()},[s,c]),(0,Q.jsx)(D,{path:xe,language:Z,value:e,theme:E(l),options:le,keepCurrentModel:!0,loading:(0,Q.jsx)(`div`,{className:`p-4 text-code text-muted`,children:`Loading editor…`}),onMount:e=>{u.current=e,e.addCommand(c.KeyMod.CtrlCmd|c.KeyCode.Enter,()=>{d.current.onRun()}),e.addCommand(c.KeyMod.Shift|c.KeyMod.Alt|c.KeyCode.KeyF,()=>{e.getAction(`editor.action.formatDocument`)?.run()}),r(e);let t=e.getModel();t&&ve(t,o),e.focus()},onChange:e=>{e!==void 0&&d.current.onChange(e)}})}function Ce(e){return d({queryKey:[...u(),`/client/analyze`,e],queryFn:({signal:t})=>i(r.client.analyze.$post({json:{query:e}},{init:{signal:t}}))})}async function we(e,t){try{return await e.query(Ce(t))}catch{return null}}function Te(e){return c({...Ce(e),enabled:e.trim()!==``,placeholderData:e=>e})}function Ee(e,t){return c({queryKey:[...u(),`/client/preview`,e],queryFn:({signal:t})=>i(r.client.preview.$post({json:{query:e}},{init:{signal:t}})),enabled:t&&e.trim()!==``,placeholderData:e=>e,staleTime:1/0,retry:!1})}function De(e,t){return c({queryKey:[...u(),`/client/check`,e],queryFn:({signal:t})=>i(r.client.check.$post({json:{query:e}},{init:{signal:t}})),enabled:t&&e.trim()!==``,placeholderData:e=>e})}function Oe({modes:e,selected:t,onSelect:n}){return(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:e.map(e=>(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":e===t,className:`pill ${e===t?`border-accent bg-accent-soft text-accent-text`:`border-line bg-canvas text-muted hover:border-accent`}`,onClick:()=>{n(e)},children:e},e))})}function $(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ke(e){let t=Array.isArray(e)?e:[e];if(t.length===0||!t.every($))return null;let n=[...new Set(t.flatMap(e=>Object.keys(e)))];return{columns:n,rows:t.map(e=>Object.fromEntries(n.map(t=>{let n=e[t];return n==null?[t,null]:typeof n==`string`||typeof n==`number`||typeof n==`boolean`?[t,n]:[t,JSON.stringify(n)]})))}}function Ae(e){if(!(e instanceof Error))return`The query could not be run.`;let t=Reflect.get(e,`detail`),n=$(t)?t.data:void 0;try{let t=typeof n==`string`?JSON.parse(n):n;return $(t)&&typeof t.detail==`string`?t.detail:e.message}catch{return e.message}}function je({queries:e,dialect:t,asSent:n,onOpen:r}){return e.length===0?(0,Q.jsx)(`div`,{className:`p-6 text-muted`,children:`The call sent no statement to the database.`}):(0,Q.jsx)(`ol`,{className:`m-0 min-h-0 flex-1 list-none overflow-auto p-0`,children:e.map((e,i)=>(0,Q.jsxs)(`li`,{className:`border-b border-line px-4 py-3`,children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2 text-code text-muted`,children:[(0,Q.jsxs)(`span`,{className:`font-bold text-ink`,children:[`#`,i+1]}),(0,Q.jsxs)(`span`,{children:[e.durationMs,` ms`]}),e.params.length>0?(0,Q.jsxs)(`span`,{children:[e.params.length,` `,e.params.length===1?`parameter`:`parameters`]}):null,(0,Q.jsxs)(`span`,{className:`ml-auto flex items-center gap-1`,children:[(0,Q.jsx)(k,{text:n?e.sql:e.formatted,what:`statement ${i+1}`}),(0,Q.jsxs)(y,{variant:`ghost`,size:`sm`,onPress:()=>{r(e)},children:[(0,Q.jsx)(m,{size:14}),`Open in SQL`]})]})]}),n?(0,Q.jsx)(O,{code:e.sql,language:`sql`,className:`break-all whitespace-pre-wrap`}):(0,Q.jsx)(O,{code:e.formatted,language:`sql`}),e.params.length>0?(0,Q.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5 font-mono text-caption`,children:e.params.map((e,n)=>(0,Q.jsxs)(`span`,{className:`pill gap-1.5 border-line bg-canvas text-muted`,children:[(0,Q.jsx)(`span`,{className:`text-ink`,children:t===`postgresql`?`$${n+1}`:`?${n+1}`}),(0,Q.jsx)(`span`,{className:`max-w-[320px] truncate`,children:JSON.stringify(e)})]},n))}):null]},i))})}function Me({tab:e,onTab:t,result:n,running:r,error:i,asJson:a,onAsJson:o,sql:s,asSent:c,onAsSent:l,dialect:u,onOpen:d}){let f=(0,A.useMemo)(()=>n===null?null:ke(n.result),[n]),p=Array.isArray(n?.result)?n.result.length:1,m=n?.rowCount??null,h=m===null?`one value`:`${m.toLocaleString()} ${m===1?`row`:`rows`}`,g=m!==null&&p<m?`first ${p.toLocaleString()} of ${h}`:h,_=s.error!==null&&s.error!==void 0,v=(s.note===null||s.stale)&&!_?s.data:null;return(0,Q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-b border-line bg-surface px-4 py-1.5 text-code`,children:[(0,Q.jsx)(b,{selectedKey:e,onSelectionChange:e=>{t(e===`sql`?`sql`:`result`)},children:(0,Q.jsx)(b.ListContainer,{className:`w-fit`,children:(0,Q.jsxs)(b.List,{"aria-label":`Views of the call`,children:[(0,Q.jsx)(b.Tab,{id:`result`,children:`Result`}),(0,Q.jsxs)(b.Tab,{id:`sql`,className:`whitespace-nowrap`,children:[`SQL`,v===null?``:` · ${v.queries.length}`]})]})})}),e===`result`?(0,Q.jsxs)(Q.Fragment,{children:[f===null?null:(0,Q.jsx)(Oe,{modes:[`Table`,`JSON`],selected:a?`JSON`:`Table`,onSelect:e=>{o(e===`JSON`)}}),(0,Q.jsx)(`output`,{"aria-label":`Run status`,className:`ml-auto text-faint`,children:r?`Running…`:n===null?``:`${g} · ${n.durationMs} ms · ${n.queries.length} ${n.queries.length===1?`statement`:`statements`}`})]}):(0,Q.jsxs)(Q.Fragment,{children:[v===null?null:(0,Q.jsx)(Oe,{modes:[`Formatted`,`As sent`],selected:c?`As sent`:`Formatted`,onSelect:e=>{l(e===`As sent`)}}),(0,Q.jsx)(`output`,{"aria-label":`SQL status`,className:`ml-auto text-faint`,children:s.updating?`Updating…`:v===null||s.stale?``:`${v.queries.length} ${v.queries.length===1?`statement`:`statements`} · ${v.durationMs} ms`})]})]}),e===`sql`?v===null?s.note===null?_?(0,Q.jsx)(`pre`,{className:`error-box m-4 whitespace-pre-wrap`,children:Ae(s.error)}):null:(0,Q.jsx)(`div`,{className:`p-6 text-muted`,children:s.note}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[s.stale&&s.note!==null?(0,Q.jsx)(`div`,{className:`border-b border-line bg-surface-2 px-4 py-1.5 text-code text-muted`,children:s.note}):null,(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col transition-opacity ${s.stale?`opacity-50`:``}`,children:(0,Q.jsx)(je,{queries:v.queries,dialect:u,asSent:c,onOpen:d})})]}):i==null?n===null?(0,Q.jsx)(`div`,{className:`p-6 text-muted`,children:`Run the call to see what it returns.`}):f!==null&&!a?(0,Q.jsx)(se,{columns:f.columns,rows:f.rows}):(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:(0,Q.jsx)(O,{code:JSON.stringify(n.result,null,2)})}):(0,Q.jsx)(`pre`,{className:`error-box m-4 whitespace-pre-wrap`,children:Ae(i)})]})}function Ne(e,t){let n=e.flatMap(({model:e,fields:n})=>{let r=t.find(t=>t.name===e);if(r===void 0)return[];let i=n.map(e=>(r.fields.find(t=>t.name===e)?.dbName??e).toLowerCase());return[[(r.dbName??r.name).toLowerCase(),new Set(i)]]});return n.length===0?null:new Map(n)}var Pe=`hekireki-studio:client-panes`,Fe=`hekireki-studio:client-editor-height`,Ie=250;function Le(){let e=a(),t=g(),n=s().data??null,r=f().data?.schema??null,i=o().data??null,[c,u]=(0,A.useState)(``),[d,p]=(0,A.useState)(`result`),[m,b]=(0,A.useState)(!1),[x,S]=(0,A.useState)(!1),[C,w]=(0,A.useState)(null),[se,T]=(0,A.useState)(null),{copied:E,copy:le}=re(),D=te(c,Ie),O=Te(D),k=O.data?.calls??[],[j,M]=(0,A.useState)(null),N=(0,A.useMemo)(()=>O.data?.diagnostics??[],[O.data]),P=i?.typescript!==null&&i?.typescript!==void 0,F=De(D,P),I=D!==c,L=(0,A.useMemo)(()=>[...N.map(e=>({...e,severity:`error`})),...I?[]:F.data?.diagnostics??[]],[N,F.data,I]),R=l({mutation:{onSuccess:()=>e.invalidateQueries({queryKey:[`db`,`/db/rows/:modelName`]})}}),z=R.data??null,B=z!==null&&R.variables?.json.query===D,V=I||O.isFetching||F.isFetching,H=k.some(e=>e.write),U=L.length>0,W=i?.available===!0?k.length===0&&!U?`Type a call to see the SQL it sends.`:U?`Fix the problems to update the SQL: this is what the call last sent.`:H?`A write shows its SQL when it is run.`:null:`The Prisma Client is not available.`,G=Ee(D,!B&&!V&&W===null),K=c.trim()===``?``:O.isError?`The analysis failed.`:I||O.isFetching?`Analyzing…`:F.isFetching?`Checking types…`:U?`${L.length} ${L.length===1?`problem`:`problems`}`:`No problems`,q=(0,A.useMemo)(()=>r===null||D.trim()===``?null:Ne(O.data?.touched??[],r.models),[r,D,O.data]),J=(0,A.useMemo)(()=>(r?.models??[]).map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type,kind:e.kind,isList:e.isList}))})),[r]),ue=(0,A.useCallback)(e=>{u(e),p(`sql`)},[]),Y=(0,A.useCallback)(()=>{R.mutate({json:{query:c}}),p(`result`)},[R,c]),X=(0,A.useCallback)(async()=>{if(R.isPending||c.trim()===``||i?.available!==!0)return;let t=(await we(e,c))?.calls.filter(e=>e.write)??[];if(t.length>0){M(t);return}Y()},[R.isPending,c,i,e,Y]),de=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Se,{value:c,onChange:ue,onRun:()=>{X()},onReady:T,models:J,typesAvailable:P,markers:L,selection:C})}),K===``?null:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-t border-line bg-surface-2 px-4 py-1.5 text-code`,children:[k.length>0?(0,Q.jsx)(`span`,{className:`heading mb-0`,children:O.data?.transaction?`$transaction`:`Call`}):null,k.map(e=>(0,Q.jsxs)(`span`,{className:`pill ${e.write?`border-warn text-warn`:`border-line bg-canvas text-muted`}`,children:[e.model,`.`,e.operation,e.write?` · write`:``]},`${e.range.start}-${e.range.end}`)),(0,Q.jsx)(`output`,{"aria-label":`Editor status`,className:`ml-auto text-faint`,children:K})]}),(0,Q.jsx)(oe,{diagnostics:L,onPick:w})]}),fe=(0,Q.jsx)(Me,{tab:d,onTab:p,result:z,running:R.isPending,error:R.isError?R.error:null,asJson:m,onAsJson:b,sql:{data:B?z:G.data??null,error:B||!G.isError?null:G.error,note:B?null:W,stale:!B&&U,updating:!B&&(V||G.isFetching)},asSent:x,onAsSent:S,dialect:n?.dialect??null,onOpen:e=>{t({to:`/sql`,search:{sql:x?e.sql:e.formatted,params:[...e.params]}})}}),Z=(0,Q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-line bg-surface px-4 py-2 text-code text-muted`,children:[(0,Q.jsx)(`span`,{className:`heading mb-0`,children:`Schema`}),(0,Q.jsx)(`span`,{className:`truncate`,children:q===null?`Every model; the ones a call touches light up as you type.`:`${q.size} ${q.size===1?`model`:`models`} touched · the fields the call names are marked`})]}),r===null?null:r.models.length===0?(0,Q.jsx)(`div`,{className:`p-6 text-muted`,children:`No models in the schema.`}):(0,Q.jsx)(ce,{schema:r,focus:null,touched:q,compact:!0})]}),pe=(0,Q.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-col`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-wrap items-center gap-3.5 border-b border-line bg-surface px-6 py-3`,children:[(0,Q.jsx)(`h1`,{className:`page-title`,children:`Prisma Client`}),(0,Q.jsxs)(`span`,{className:`min-w-0 text-lead [overflow-wrap:anywhere] text-muted`,children:[c.split(`
2
+ `).length,` lines`,i===null?` · loading the Prisma Client…`:i.available?` · ${i.source??`generated`} · ${n?.dialect??``} ${n?.url??``}`.trimEnd():` · Prisma Client not available`]}),(0,Q.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-code text-faint`,children:[(0,Q.jsx)(ie,{children:`⌘/Ctrl`}),(0,Q.jsx)(ie,{children:`Enter`}),`to run`]}),(0,Q.jsxs)(ne,{children:[(0,Q.jsxs)(y,{variant:`ghost`,onPress:()=>{se?.getAction(`editor.action.formatDocument`)?.run()},children:[(0,Q.jsx)(h,{size:15}),`Format`]}),(0,Q.jsx)(ne.Content,{children:`Format with the TypeScript formatter (Shift+Alt+F)`})]}),(0,Q.jsxs)(y,{variant:`ghost`,onPress:()=>{le(c)},children:[(0,Q.jsx)(_,{size:15}),E?`Copied`:`Copy`]}),(0,Q.jsxs)(y,{variant:`primary`,isDisabled:R.isPending||i?.available!==!0,onPress:()=>{X()},children:[(0,Q.jsx)(v,{size:14}),`Run`]})]}),i!==null&&!i.available?(0,Q.jsx)(`pre`,{className:`error-box m-4 whitespace-pre-wrap`,children:i.error}):null,(0,Q.jsx)(ae,{direction:`column`,storageKey:Fe,defaultRatio:.4,label:`Resize the editor`,first:de,second:fe})]});return(0,Q.jsxs)(`section`,{className:`flex min-h-0 flex-1 overflow-hidden`,children:[(0,Q.jsx)(ae,{direction:`row`,storageKey:Pe,defaultRatio:.58,min:.3,max:.8,label:`Resize the schema`,first:pe,second:Z}),(0,Q.jsx)(ee,{isOpen:j!==null,title:`Run ${j?.length===1?`a write`:`${j?.length??0} writes`}?`,detail:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`span`,{children:`This changes the database through the Prisma Client:`}),(0,Q.jsx)(`ul`,{className:`m-0 list-disc pl-5 font-mono text-code`,children:(j??[]).map(e=>(0,Q.jsxs)(`li`,{children:[e.model,`.`,e.operation]},`${e.range.start}-${e.range.end}`))})]}),confirmLabel:`Run`,isPending:R.isPending,onConfirm:()=>{M(null),Y()},onOpenChange:e=>{e||M(null)}})]})}var Re=Le;export{Re as component};