@ghentcdh/crouton-prisma 0.0.1-alpha.73 → 0.0.1-alpha.76

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.
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ "use strict";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __export = (target, all) => {
4
5
  for (var name in all)
@@ -6,7 +7,7 @@ var __export = (target, all) => {
6
7
  };
7
8
 
8
9
  // src/generator.ts
9
- import { generatorHandler } from "@prisma/generator-helper";
10
+ var import_generator_helper = require("@prisma/generator-helper");
10
11
 
11
12
  // ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
12
13
  var external_exports = {};
@@ -14802,13 +14803,13 @@ var ColumnTypeShorthandSchema = external_exports.enum([
14802
14803
  ]);
14803
14804
  var JsonSchemaFragmentSchema = external_exports.lazy(
14804
14805
  () => external_exports.object({
14805
- type: external_exports.union([external_exports.string(), external_exports.array(external_exports.string())]).optional(),
14806
+ type: external_exports.union([external_exports.string(), external_exports.array(external_exports.string()), external_exports.lazy(() => JsonSchemaFragmentSchema)]).optional(),
14806
14807
  format: external_exports.string().optional(),
14807
14808
  enum: external_exports.array(external_exports.unknown()).optional(),
14808
14809
  const: external_exports.unknown().optional(),
14809
14810
  nullable: external_exports.boolean().optional(),
14810
14811
  properties: external_exports.record(external_exports.string(), JsonSchemaFragmentSchema).optional(),
14811
- required: external_exports.array(external_exports.string()).optional(),
14812
+ required: external_exports.union([external_exports.array(external_exports.string()), external_exports.boolean()]).optional(),
14812
14813
  items: JsonSchemaFragmentSchema.optional(),
14813
14814
  additionalProperties: external_exports.union([external_exports.boolean(), JsonSchemaFragmentSchema]).optional(),
14814
14815
  title: external_exports.string().optional(),
@@ -15558,18 +15559,18 @@ var TranslationBundleSchema = external_exports.object({
15558
15559
  }).passthrough();
15559
15560
 
15560
15561
  // ../crouton-codegen/src/util.ts
15561
- import { access } from "fs/promises";
15562
+ var import_promises = require("fs/promises");
15562
15563
 
15563
15564
  // ../crouton-codegen/src/serialize.ts
15564
15565
  var RESOURCE_SCHEMA_URL = `https://ghentcdh.github.io/crouton/schema/v${CURRENT_RESOURCE_VERSION}/resource.schema.json`;
15565
15566
 
15566
15567
  // ../crouton-codegen/src/commit.ts
15567
- import { mkdir, writeFile } from "fs/promises";
15568
- import { dirname } from "path";
15568
+ var import_promises2 = require("fs/promises");
15569
+ var import_node_path = require("path");
15569
15570
 
15570
15571
  // ../crouton-codegen/src/config.ts
15571
- import { readFile, readdir } from "fs/promises";
15572
- import { dirname as dirname2, isAbsolute, join, resolve } from "path";
15572
+ var import_promises3 = require("fs/promises");
15573
+ var import_node_path2 = require("path");
15573
15574
 
15574
15575
  // ../../node_modules/.pnpm/zod@4.5.4/node_modules/zod/v4/classic/external.js
15575
15576
  var external_exports2 = {};
@@ -34438,43 +34439,43 @@ function date8(params) {
34438
34439
  }
34439
34440
 
34440
34441
  // ../crouton-codegen/src/scaffold.ts
34441
- import { readFile as readFile2, readdir as readdir2 } from "fs/promises";
34442
- import { dirname as dirname3, join as join2 } from "path";
34442
+ var import_promises4 = require("fs/promises");
34443
+ var import_node_path3 = require("path");
34443
34444
  var ScallfoldDatasourceSchema = DataSourceShape.extend({
34444
34445
  /** Folder name under `dataSourcesDir`. */
34445
34446
  folder: external_exports2.string().default("default")
34446
34447
  }).transform(transformDataSource);
34447
34448
 
34448
34449
  // ../crouton-codegen/src/datasource-scaffold.ts
34449
- import { dirname as dirname4, posix, relative } from "path";
34450
+ var import_node_path4 = require("path");
34450
34451
 
34451
34452
  // ../crouton-codegen/src/project.ts
34452
- import { readFile as readFile3, readdir as readdir3 } from "fs/promises";
34453
- import { join as join3 } from "path";
34453
+ var import_promises5 = require("fs/promises");
34454
+ var import_node_path5 = require("path");
34454
34455
 
34455
34456
  // ../crouton-codegen/src/prisma-shell.ts
34456
- import { spawn } from "child_process";
34457
- import { existsSync, readdirSync } from "fs";
34458
- import { copyFile, readFile as readFile4, readdir as readdir4, writeFile as writeFile2 } from "fs/promises";
34459
- import { createRequire } from "module";
34460
- import { dirname as dirname5, join as join4 } from "path";
34457
+ var import_node_child_process = require("child_process");
34458
+ var import_node_fs = require("fs");
34459
+ var import_promises6 = require("fs/promises");
34460
+ var import_node_module = require("module");
34461
+ var import_node_path6 = require("path");
34461
34462
  var fixZodImports = async (zodOutputDir) => {
34462
34463
  let fixed = 0;
34463
34464
  const walk = async (dir) => {
34464
34465
  let entries;
34465
34466
  try {
34466
- entries = await readdir4(dir, { withFileTypes: true });
34467
+ entries = await (0, import_promises6.readdir)(dir, { withFileTypes: true });
34467
34468
  } catch {
34468
34469
  return;
34469
34470
  }
34470
34471
  for (const entry of entries) {
34471
- const full = join4(dir, entry.name);
34472
+ const full = (0, import_node_path6.join)(dir, entry.name);
34472
34473
  if (entry.isDirectory()) {
34473
34474
  await walk(full);
34474
34475
  } else if (entry.name.endsWith(".ts")) {
34475
- const src = await readFile4(full, "utf-8");
34476
+ const src = await (0, import_promises6.readFile)(full, "utf-8");
34476
34477
  if (src.includes("z.") && !src.includes("from 'zod'") && !src.includes('from "zod"')) {
34477
- await writeFile2(full, `import { z } from 'zod';
34478
+ await (0, import_promises6.writeFile)(full, `import { z } from 'zod';
34478
34479
  ${src}`, "utf-8");
34479
34480
  fixed++;
34480
34481
  }
@@ -34485,13 +34486,13 @@ ${src}`, "utf-8");
34485
34486
  return fixed;
34486
34487
  };
34487
34488
  var normalizeSchema = async (schemaPath, configDir) => {
34488
- const dir = configDir ?? dirname5(schemaPath);
34489
- const configPath = join4(dir, "normalize-schema.json");
34490
- if (!existsSync(configPath)) return { renamed: 0 };
34489
+ const dir = configDir ?? (0, import_node_path6.dirname)(schemaPath);
34490
+ const configPath = (0, import_node_path6.join)(dir, "normalize-schema.json");
34491
+ if (!(0, import_node_fs.existsSync)(configPath)) return { renamed: 0 };
34491
34492
  const config3 = JSON.parse(
34492
- await readFile4(configPath, "utf-8")
34493
+ await (0, import_promises6.readFile)(configPath, "utf-8")
34493
34494
  );
34494
- let schema = await readFile4(schemaPath, "utf-8");
34495
+ let schema = await (0, import_promises6.readFile)(schemaPath, "utf-8");
34495
34496
  let renamed = 0;
34496
34497
  for (const [modelName, fields] of Object.entries(config3.renames)) {
34497
34498
  const modelRe = new RegExp(
@@ -34511,18 +34512,18 @@ var normalizeSchema = async (schemaPath, configDir) => {
34511
34512
  });
34512
34513
  }
34513
34514
  if (renamed > 0) {
34514
- await writeFile2(schemaPath, schema, "utf-8");
34515
+ await (0, import_promises6.writeFile)(schemaPath, schema, "utf-8");
34515
34516
  }
34516
34517
  return { renamed };
34517
34518
  };
34518
34519
 
34519
34520
  // src/generator.ts
34520
- import { spawn as spawn2 } from "child_process";
34521
- import { existsSync as existsSync2 } from "fs";
34522
- import { readFile as readFile5, rm, writeFile as writeFile3 } from "fs/promises";
34523
- import { dirname as dirname6, join as join5, resolve as resolve2 } from "path";
34521
+ var import_node_child_process2 = require("child_process");
34522
+ var import_node_fs2 = require("fs");
34523
+ var import_promises7 = require("fs/promises");
34524
+ var import_node_path7 = require("path");
34524
34525
  var run = (cmd, args, cwd) => new Promise((res) => {
34525
- const child = spawn2(cmd, args, { cwd, shell: process.platform === "win32" });
34526
+ const child = (0, import_node_child_process2.spawn)(cmd, args, { cwd, shell: process.platform === "win32" });
34526
34527
  let out = "";
34527
34528
  child.stdout?.on("data", (d) => out += d);
34528
34529
  child.stderr?.on("data", (d) => out += d);
@@ -34532,16 +34533,16 @@ var run = (cmd, args, cwd) => new Promise((res) => {
34532
34533
  var resolveBin = (name, cwd) => {
34533
34534
  let d = cwd;
34534
34535
  for (let i = 0; i < 6; i++) {
34535
- const bin = join5(d, "node_modules", ".bin", name);
34536
- if (existsSync2(bin)) return [bin, []];
34537
- const parent = dirname6(d);
34536
+ const bin = (0, import_node_path7.join)(d, "node_modules", ".bin", name);
34537
+ if ((0, import_node_fs2.existsSync)(bin)) return [bin, []];
34538
+ const parent = (0, import_node_path7.dirname)(d);
34538
34539
  if (parent === d) break;
34539
34540
  d = parent;
34540
34541
  }
34541
34542
  return ["npx", [name]];
34542
34543
  };
34543
34544
  var stripGenerators = (schema) => schema.replace(/^generator\s+\w+\s*\{[^}]*\}/gms, "").replace(/\n{3,}/g, "\n\n").trim();
34544
- generatorHandler({
34545
+ (0, import_generator_helper.generatorHandler)({
34545
34546
  onManifest() {
34546
34547
  return {
34547
34548
  prettyName: "Crouton",
@@ -34552,12 +34553,12 @@ generatorHandler({
34552
34553
  async onGenerate(options) {
34553
34554
  const { config: config3 } = options.generator;
34554
34555
  const schemaPath = options.schemaPath;
34555
- const schemaDir = dirname6(schemaPath);
34556
+ const schemaDir = (0, import_node_path7.dirname)(schemaPath);
34556
34557
  const zodOutput = config3["zodOutput"];
34557
34558
  if (!zodOutput) throw new Error("[crouton-prisma] zodOutput is required in generator config");
34558
- const absZodOutput = resolve2(schemaDir, zodOutput);
34559
+ const absZodOutput = (0, import_node_path7.resolve)(schemaDir, zodOutput);
34559
34560
  await normalizeSchema(schemaPath);
34560
- const normalized = await readFile5(schemaPath, "utf-8");
34561
+ const normalized = await (0, import_promises7.readFile)(schemaPath, "utf-8");
34561
34562
  const modelsOnly = stripGenerators(normalized);
34562
34563
  const zodBlock = `generator zod {
34563
34564
  provider = "zod-prisma-types"
@@ -34574,8 +34575,8 @@ generatorHandler({
34574
34575
 
34575
34576
  ${modelsOnly}
34576
34577
  `;
34577
- const tmpSchemaPath = join5(schemaDir, ".crouton-gen-tmp.prisma");
34578
- await writeFile3(tmpSchemaPath, tmpSchema, "utf-8");
34578
+ const tmpSchemaPath = (0, import_node_path7.join)(schemaDir, ".crouton-gen-tmp.prisma");
34579
+ await (0, import_promises7.writeFile)(tmpSchemaPath, tmpSchema, "utf-8");
34579
34580
  try {
34580
34581
  const [bin, prefix] = resolveBin("prisma", schemaDir);
34581
34582
  const result = await run(bin, [...prefix, "generate", "--schema", tmpSchemaPath], schemaDir);
@@ -34584,7 +34585,7 @@ ${modelsOnly}
34584
34585
  ${result.out}`);
34585
34586
  }
34586
34587
  } finally {
34587
- await rm(tmpSchemaPath, { force: true });
34588
+ await (0, import_promises7.rm)(tmpSchemaPath, { force: true });
34588
34589
  }
34589
34590
  await fixZodImports(absZodOutput);
34590
34591
  }
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "@ghentcdh/crouton-prisma",
3
- "version": "0.0.1-alpha.73",
3
+ "version": "0.0.1-alpha.76",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/GhentCDH/crouton",
7
+ "directory": "packages/crouton-prisma"
8
+ },
4
9
  "publishConfig": {
5
10
  "access": "public"
6
11
  },
@@ -9,15 +14,11 @@
9
14
  "crouton-prisma": "dist/generator.js"
10
15
  },
11
16
  "exports": {
12
- ".": "./dist/generator.js"
17
+ ".": "./dist/generator.cjs"
13
18
  },
14
19
  "files": [
15
20
  "dist"
16
21
  ],
17
- "scripts": {
18
- "build": "tsup",
19
- "typecheck": "tsc --noEmit -p tsconfig.json"
20
- },
21
22
  "dependencies": {
22
23
  "@prisma/generator-helper": "^7.8.0"
23
24
  },
@@ -26,9 +27,13 @@
26
27
  "zod-prisma-types": ">=3.0.0"
27
28
  },
28
29
  "devDependencies": {
29
- "@ghentcdh/crouton-codegen": "workspace:*",
30
- "@ghentcdh/crouton-core": "workspace:*",
31
30
  "tsup": "^8.0.0",
32
- "typescript": "^5.0.0"
31
+ "typescript": "^5.0.0",
32
+ "@ghentcdh/crouton-codegen": "0.0.1",
33
+ "@ghentcdh/crouton-core": "0.0.1-alpha.76"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "typecheck": "tsc --noEmit -p tsconfig.json"
33
38
  }
34
- }
39
+ }