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.js
CHANGED
|
@@ -1532,9 +1532,15 @@ function write(filePath, content) {
|
|
|
1532
1532
|
function createPrismaClient() {
|
|
1533
1533
|
const customClient = tryLoadFromSchemaOutput();
|
|
1534
1534
|
if (customClient) return customClient;
|
|
1535
|
+
const standardPrismaClient = tryLoadFromStandardOutput();
|
|
1536
|
+
if (standardPrismaClient) return standardPrismaClient;
|
|
1535
1537
|
try {
|
|
1536
1538
|
const clientPath = __require.resolve("@prisma/client", { paths: [cwd] });
|
|
1537
|
-
const
|
|
1539
|
+
const textResult = extractRuntimeDataModelFromFile(clientPath);
|
|
1540
|
+
if (textResult) return textResult;
|
|
1541
|
+
const mod = __require(clientPath);
|
|
1542
|
+
const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
1543
|
+
if (!PrismaClient) throw new Error("PrismaClient not found in @prisma/client");
|
|
1538
1544
|
return new PrismaClient();
|
|
1539
1545
|
} catch {
|
|
1540
1546
|
throw new Error(
|
|
@@ -1555,39 +1561,52 @@ function tryLoadFromSchemaOutput() {
|
|
|
1555
1561
|
if (!match) continue;
|
|
1556
1562
|
const outputDir = path__namespace.default.resolve(path__namespace.default.dirname(schemaPath), match[1]);
|
|
1557
1563
|
const indexPath = path__namespace.default.join(outputDir, "index.js");
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
1561
|
-
if (!PrismaClient) continue;
|
|
1562
|
-
const providerMatch = schema.match(/provider\s*=\s*["']([^"']+)["']/);
|
|
1563
|
-
const provider = providerMatch?.[1] ?? "postgresql";
|
|
1564
|
-
const dummyUrl = getDummyUrl(provider);
|
|
1565
|
-
try {
|
|
1566
|
-
return new PrismaClient({ datasourceUrl: dummyUrl });
|
|
1567
|
-
} catch {
|
|
1568
|
-
return new PrismaClient();
|
|
1569
|
-
}
|
|
1564
|
+
const result = extractRuntimeDataModelFromFile(indexPath);
|
|
1565
|
+
if (result) return result;
|
|
1570
1566
|
} catch {
|
|
1571
1567
|
continue;
|
|
1572
1568
|
}
|
|
1573
1569
|
}
|
|
1574
1570
|
return null;
|
|
1575
1571
|
}
|
|
1576
|
-
function
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1572
|
+
function tryLoadFromStandardOutput() {
|
|
1573
|
+
const candidates = [
|
|
1574
|
+
path__namespace.default.resolve(cwd, "node_modules/.prisma/client/index.js"),
|
|
1575
|
+
path__namespace.default.resolve(cwd, "node_modules/@prisma/client/index.js")
|
|
1576
|
+
];
|
|
1577
|
+
for (const clientPath of candidates) {
|
|
1578
|
+
const result = extractRuntimeDataModelFromFile(clientPath);
|
|
1579
|
+
if (result) return result;
|
|
1580
|
+
}
|
|
1581
|
+
return null;
|
|
1582
|
+
}
|
|
1583
|
+
function extractRuntimeDataModelFromFile(filePath) {
|
|
1584
|
+
if (!fs3__namespace.default.existsSync(filePath)) return null;
|
|
1585
|
+
try {
|
|
1586
|
+
const src = fs3__namespace.default.readFileSync(filePath, "utf-8");
|
|
1587
|
+
const match = src.match(/config\.runtimeDataModel\s*=\s*JSON\.parse\("((?:[^"\\]|\\.)*)"\)/);
|
|
1588
|
+
if (match) {
|
|
1589
|
+
const json = match[1].replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
1590
|
+
const runtimeDataModel = JSON.parse(json);
|
|
1591
|
+
if (runtimeDataModel?.models) {
|
|
1592
|
+
return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
|
|
1593
|
+
} };
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
const match2 = src.match(/runtimeDataModel\s*=\s*(\{[\s\S]*?"models"\s*:\s*\{[\s\S]*?\}\s*\})/);
|
|
1597
|
+
if (match2) {
|
|
1598
|
+
try {
|
|
1599
|
+
const runtimeDataModel = JSON.parse(match2[1]);
|
|
1600
|
+
if (runtimeDataModel?.models) {
|
|
1601
|
+
return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
|
|
1602
|
+
} };
|
|
1603
|
+
}
|
|
1604
|
+
} catch {
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
} catch {
|
|
1590
1608
|
}
|
|
1609
|
+
return null;
|
|
1591
1610
|
}
|
|
1592
1611
|
var USAGE = `
|
|
1593
1612
|
Usage:
|