omni-rest 0.2.2 → 0.2.4
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/cli.js +46 -27
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +46 -27
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1510,9 +1510,15 @@ function write(filePath, content) {
|
|
|
1510
1510
|
function createPrismaClient() {
|
|
1511
1511
|
const customClient = tryLoadFromSchemaOutput();
|
|
1512
1512
|
if (customClient) return customClient;
|
|
1513
|
+
const standardPrismaClient = tryLoadFromStandardOutput();
|
|
1514
|
+
if (standardPrismaClient) return standardPrismaClient;
|
|
1513
1515
|
try {
|
|
1514
1516
|
const clientPath = __require.resolve("@prisma/client", { paths: [cwd] });
|
|
1515
|
-
const
|
|
1517
|
+
const textResult = extractRuntimeDataModelFromFile(clientPath);
|
|
1518
|
+
if (textResult) return textResult;
|
|
1519
|
+
const mod = __require(clientPath);
|
|
1520
|
+
const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
1521
|
+
if (!PrismaClient) throw new Error("PrismaClient not found in @prisma/client");
|
|
1516
1522
|
return new PrismaClient();
|
|
1517
1523
|
} catch {
|
|
1518
1524
|
throw new Error(
|
|
@@ -1533,39 +1539,52 @@ function tryLoadFromSchemaOutput() {
|
|
|
1533
1539
|
if (!match) continue;
|
|
1534
1540
|
const outputDir = path__default.resolve(path__default.dirname(schemaPath), match[1]);
|
|
1535
1541
|
const indexPath = path__default.join(outputDir, "index.js");
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
1539
|
-
if (!PrismaClient) continue;
|
|
1540
|
-
const providerMatch = schema.match(/provider\s*=\s*["']([^"']+)["']/);
|
|
1541
|
-
const provider = providerMatch?.[1] ?? "postgresql";
|
|
1542
|
-
const dummyUrl = getDummyUrl(provider);
|
|
1543
|
-
try {
|
|
1544
|
-
return new PrismaClient({ datasourceUrl: dummyUrl });
|
|
1545
|
-
} catch {
|
|
1546
|
-
return new PrismaClient();
|
|
1547
|
-
}
|
|
1542
|
+
const result = extractRuntimeDataModelFromFile(indexPath);
|
|
1543
|
+
if (result) return result;
|
|
1548
1544
|
} catch {
|
|
1549
1545
|
continue;
|
|
1550
1546
|
}
|
|
1551
1547
|
}
|
|
1552
1548
|
return null;
|
|
1553
1549
|
}
|
|
1554
|
-
function
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1550
|
+
function tryLoadFromStandardOutput() {
|
|
1551
|
+
const candidates = [
|
|
1552
|
+
path__default.resolve(cwd, "node_modules/.prisma/client/index.js"),
|
|
1553
|
+
path__default.resolve(cwd, "node_modules/@prisma/client/index.js")
|
|
1554
|
+
];
|
|
1555
|
+
for (const clientPath of candidates) {
|
|
1556
|
+
const result = extractRuntimeDataModelFromFile(clientPath);
|
|
1557
|
+
if (result) return result;
|
|
1558
|
+
}
|
|
1559
|
+
return null;
|
|
1560
|
+
}
|
|
1561
|
+
function extractRuntimeDataModelFromFile(filePath) {
|
|
1562
|
+
if (!fs3__default.existsSync(filePath)) return null;
|
|
1563
|
+
try {
|
|
1564
|
+
const src = fs3__default.readFileSync(filePath, "utf-8");
|
|
1565
|
+
const match = src.match(/config\.runtimeDataModel\s*=\s*JSON\.parse\("((?:[^"\\]|\\.)*)"\)/);
|
|
1566
|
+
if (match) {
|
|
1567
|
+
const json = match[1].replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
1568
|
+
const runtimeDataModel = JSON.parse(json);
|
|
1569
|
+
if (runtimeDataModel?.models) {
|
|
1570
|
+
return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
|
|
1571
|
+
} };
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
const match2 = src.match(/runtimeDataModel\s*=\s*(\{[\s\S]*?"models"\s*:\s*\{[\s\S]*?\}\s*\})/);
|
|
1575
|
+
if (match2) {
|
|
1576
|
+
try {
|
|
1577
|
+
const runtimeDataModel = JSON.parse(match2[1]);
|
|
1578
|
+
if (runtimeDataModel?.models) {
|
|
1579
|
+
return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
|
|
1580
|
+
} };
|
|
1581
|
+
}
|
|
1582
|
+
} catch {
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
} catch {
|
|
1568
1586
|
}
|
|
1587
|
+
return null;
|
|
1569
1588
|
}
|
|
1570
1589
|
var USAGE = `
|
|
1571
1590
|
Usage:
|