prisma-swagger-autogen 1.0.0 → 1.0.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.
@@ -2,7 +2,7 @@
2
2
  import fs from "fs";
3
3
  import path from "path";
4
4
  import { globSync } from "glob";
5
- import { execSync } from "child_process";
5
+ import { createRequire } from "module";
6
6
  var CONFIG = {
7
7
  projectRoot: process.cwd(),
8
8
  controllersGlob: "./src/web/api/controllers/**/*.ts",
@@ -168,24 +168,29 @@ function attachExample(schema, components) {
168
168
  }
169
169
  return s;
170
170
  }
171
- async function loadDmmfFromProject() {
171
+ function loadDmmfFromProject() {
172
172
  const schemaPath = path.resolve(process.cwd(), "prisma/schema.prisma");
173
173
  if (!fs.existsSync(schemaPath)) {
174
174
  throw new Error(`Prisma schema not found at: ${schemaPath}`);
175
175
  }
176
- const cmd = `npx prisma generate --schema "${schemaPath}" --print`;
177
- const stdout = execSync(cmd, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
178
- const firstBrace = stdout.indexOf("{");
179
- const lastBrace = stdout.lastIndexOf("}");
180
- if (firstBrace === -1 || lastBrace === -1) {
181
- throw new Error(`Failed to parse Prisma DMMF from: ${cmd}`);
182
- }
183
- const jsonText = stdout.slice(firstBrace, lastBrace + 1);
184
- const parsed = JSON.parse(jsonText);
185
- const dmmf = parsed?.dmmf ?? parsed;
186
- if (!dmmf?.datamodel?.models) {
187
- throw new Error(`Prisma DMMF not found in prisma output. Got keys: ${Object.keys(parsed || {})}`);
176
+ const datamodel = fs.readFileSync(schemaPath, "utf8");
177
+ const require2 = createRequire(import.meta.url);
178
+ const tryLoad = (id) => {
179
+ try {
180
+ return require2(id);
181
+ } catch {
182
+ return null;
183
+ }
184
+ };
185
+ const runtime = tryLoad("@prisma/client/runtime/library") ?? tryLoad("@prisma/client/runtime");
186
+ if (!runtime || typeof runtime.getDMMF !== "function") {
187
+ throw new Error(
188
+ `Unable to load Prisma runtime getDMMF(). Ensure @prisma/client is installed in the target project.
189
+ Tried: @prisma/client/runtime/library and @prisma/client/runtime`
190
+ );
188
191
  }
192
+ const dmmf = runtime.getDMMF({ datamodel });
193
+ if (!dmmf?.datamodel?.models) throw new Error("Failed to load Prisma DMMF (unexpected structure).");
189
194
  return dmmf;
190
195
  }
191
196
  function buildSchemasFromDmmf(dmmf) {
@@ -324,7 +329,7 @@ swaggerAutogen('${ensurePosix(CONFIG.openapiOut)}', routes, docs)
324
329
  fs.writeFileSync(outPath, fileContent, "utf8");
325
330
  }
326
331
  async function run(_args) {
327
- const dmmf = await loadDmmfFromProject();
332
+ const dmmf = loadDmmfFromProject();
328
333
  const schemas = buildSchemasFromDmmf(dmmf);
329
334
  generateSwaggerConfigJs(schemas);
330
335
  }
package/dist/cli.cjs CHANGED
@@ -27,7 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var import_node_fs = __toESM(require("fs"), 1);
28
28
  var import_node_path = __toESM(require("path"), 1);
29
29
  var import_glob = require("glob");
30
- var import_node_child_process = require("child_process");
30
+ var import_node_module = require("module");
31
+ var import_meta = {};
31
32
  var CONFIG = {
32
33
  projectRoot: process.cwd(),
33
34
  controllersGlob: "./src/web/api/controllers/**/*.ts",
@@ -193,24 +194,29 @@ function attachExample(schema, components) {
193
194
  }
194
195
  return s;
195
196
  }
196
- async function loadDmmfFromProject() {
197
+ function loadDmmfFromProject() {
197
198
  const schemaPath = import_node_path.default.resolve(process.cwd(), "prisma/schema.prisma");
198
199
  if (!import_node_fs.default.existsSync(schemaPath)) {
199
200
  throw new Error(`Prisma schema not found at: ${schemaPath}`);
200
201
  }
201
- const cmd = `npx prisma generate --schema "${schemaPath}" --print`;
202
- const stdout = (0, import_node_child_process.execSync)(cmd, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
203
- const firstBrace = stdout.indexOf("{");
204
- const lastBrace = stdout.lastIndexOf("}");
205
- if (firstBrace === -1 || lastBrace === -1) {
206
- throw new Error(`Failed to parse Prisma DMMF from: ${cmd}`);
207
- }
208
- const jsonText = stdout.slice(firstBrace, lastBrace + 1);
209
- const parsed = JSON.parse(jsonText);
210
- const dmmf = parsed?.dmmf ?? parsed;
211
- if (!dmmf?.datamodel?.models) {
212
- throw new Error(`Prisma DMMF not found in prisma output. Got keys: ${Object.keys(parsed || {})}`);
202
+ const datamodel = import_node_fs.default.readFileSync(schemaPath, "utf8");
203
+ const require2 = (0, import_node_module.createRequire)(import_meta.url);
204
+ const tryLoad = (id) => {
205
+ try {
206
+ return require2(id);
207
+ } catch {
208
+ return null;
209
+ }
210
+ };
211
+ const runtime = tryLoad("@prisma/client/runtime/library") ?? tryLoad("@prisma/client/runtime");
212
+ if (!runtime || typeof runtime.getDMMF !== "function") {
213
+ throw new Error(
214
+ `Unable to load Prisma runtime getDMMF(). Ensure @prisma/client is installed in the target project.
215
+ Tried: @prisma/client/runtime/library and @prisma/client/runtime`
216
+ );
213
217
  }
218
+ const dmmf = runtime.getDMMF({ datamodel });
219
+ if (!dmmf?.datamodel?.models) throw new Error("Failed to load Prisma DMMF (unexpected structure).");
214
220
  return dmmf;
215
221
  }
216
222
  function buildSchemasFromDmmf(dmmf) {
@@ -349,7 +355,7 @@ swaggerAutogen('${ensurePosix(CONFIG.openapiOut)}', routes, docs)
349
355
  import_node_fs.default.writeFileSync(outPath, fileContent, "utf8");
350
356
  }
351
357
  async function run(_args) {
352
- const dmmf = await loadDmmfFromProject();
358
+ const dmmf = loadDmmfFromProject();
353
359
  const schemas = buildSchemasFromDmmf(dmmf);
354
360
  generateSwaggerConfigJs(schemas);
355
361
  }
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  run
4
- } from "./chunk-SNNQZQLO.js";
4
+ } from "./chunk-B6OADLRN.js";
5
5
 
6
6
  // src/cli.ts
7
7
  run(process.argv.slice(2)).catch((e) => {
package/dist/index.cjs CHANGED
@@ -36,7 +36,8 @@ module.exports = __toCommonJS(index_exports);
36
36
  var import_node_fs = __toESM(require("fs"), 1);
37
37
  var import_node_path = __toESM(require("path"), 1);
38
38
  var import_glob = require("glob");
39
- var import_node_child_process = require("child_process");
39
+ var import_node_module = require("module");
40
+ var import_meta = {};
40
41
  var CONFIG = {
41
42
  projectRoot: process.cwd(),
42
43
  controllersGlob: "./src/web/api/controllers/**/*.ts",
@@ -202,24 +203,29 @@ function attachExample(schema, components) {
202
203
  }
203
204
  return s;
204
205
  }
205
- async function loadDmmfFromProject() {
206
+ function loadDmmfFromProject() {
206
207
  const schemaPath = import_node_path.default.resolve(process.cwd(), "prisma/schema.prisma");
207
208
  if (!import_node_fs.default.existsSync(schemaPath)) {
208
209
  throw new Error(`Prisma schema not found at: ${schemaPath}`);
209
210
  }
210
- const cmd = `npx prisma generate --schema "${schemaPath}" --print`;
211
- const stdout = (0, import_node_child_process.execSync)(cmd, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
212
- const firstBrace = stdout.indexOf("{");
213
- const lastBrace = stdout.lastIndexOf("}");
214
- if (firstBrace === -1 || lastBrace === -1) {
215
- throw new Error(`Failed to parse Prisma DMMF from: ${cmd}`);
216
- }
217
- const jsonText = stdout.slice(firstBrace, lastBrace + 1);
218
- const parsed = JSON.parse(jsonText);
219
- const dmmf = parsed?.dmmf ?? parsed;
220
- if (!dmmf?.datamodel?.models) {
221
- throw new Error(`Prisma DMMF not found in prisma output. Got keys: ${Object.keys(parsed || {})}`);
211
+ const datamodel = import_node_fs.default.readFileSync(schemaPath, "utf8");
212
+ const require2 = (0, import_node_module.createRequire)(import_meta.url);
213
+ const tryLoad = (id) => {
214
+ try {
215
+ return require2(id);
216
+ } catch {
217
+ return null;
218
+ }
219
+ };
220
+ const runtime = tryLoad("@prisma/client/runtime/library") ?? tryLoad("@prisma/client/runtime");
221
+ if (!runtime || typeof runtime.getDMMF !== "function") {
222
+ throw new Error(
223
+ `Unable to load Prisma runtime getDMMF(). Ensure @prisma/client is installed in the target project.
224
+ Tried: @prisma/client/runtime/library and @prisma/client/runtime`
225
+ );
222
226
  }
227
+ const dmmf = runtime.getDMMF({ datamodel });
228
+ if (!dmmf?.datamodel?.models) throw new Error("Failed to load Prisma DMMF (unexpected structure).");
223
229
  return dmmf;
224
230
  }
225
231
  function buildSchemasFromDmmf(dmmf) {
@@ -358,7 +364,7 @@ swaggerAutogen('${ensurePosix(CONFIG.openapiOut)}', routes, docs)
358
364
  import_node_fs.default.writeFileSync(outPath, fileContent, "utf8");
359
365
  }
360
366
  async function run(_args) {
361
- const dmmf = await loadDmmfFromProject();
367
+ const dmmf = loadDmmfFromProject();
362
368
  const schemas = buildSchemasFromDmmf(dmmf);
363
369
  generateSwaggerConfigJs(schemas);
364
370
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  run
3
- } from "./chunk-SNNQZQLO.js";
3
+ } from "./chunk-B6OADLRN.js";
4
4
  export {
5
5
  run
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prisma-swagger-autogen",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Generate swagger-autogen config + Prisma DMMF schemas and fix swagger-autogen output.",
5
5
  "license": "MIT",
6
6
  "author": "Joyce Marvin Rafflenbeul",
@@ -44,7 +44,6 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@prisma/client": ">=4",
47
- "prisma": ">=4",
48
47
  "glob": ">=10",
49
48
  "swagger-autogen": ">=2"
50
49
  },