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.
- package/dist/{chunk-SNNQZQLO.js → chunk-B6OADLRN.js} +20 -15
- package/dist/cli.cjs +21 -15
- package/dist/cli.js +1 -1
- package/dist/index.cjs +21 -15
- package/dist/index.js +1 -1
- package/package.json +1 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { globSync } from "glob";
|
|
5
|
-
import {
|
|
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
|
-
|
|
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
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
if (!
|
|
187
|
-
throw new Error(
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
if (!
|
|
212
|
-
throw new Error(
|
|
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 =
|
|
358
|
+
const dmmf = loadDmmfFromProject();
|
|
353
359
|
const schemas = buildSchemasFromDmmf(dmmf);
|
|
354
360
|
generateSwaggerConfigJs(schemas);
|
|
355
361
|
}
|
package/dist/cli.js
CHANGED
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
|
|
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
|
-
|
|
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
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
if (!
|
|
221
|
-
throw new Error(
|
|
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 =
|
|
367
|
+
const dmmf = loadDmmfFromProject();
|
|
362
368
|
const schemas = buildSchemasFromDmmf(dmmf);
|
|
363
369
|
generateSwaggerConfigJs(schemas);
|
|
364
370
|
}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prisma-swagger-autogen",
|
|
3
|
-
"version": "1.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
|
},
|