omni-rest 0.2.3 → 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 +30 -38
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +30 -38
- package/dist/cli.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1536,14 +1536,11 @@ function createPrismaClient() {
|
|
|
1536
1536
|
if (standardPrismaClient) return standardPrismaClient;
|
|
1537
1537
|
try {
|
|
1538
1538
|
const clientPath = __require.resolve("@prisma/client", { paths: [cwd] });
|
|
1539
|
+
const textResult = extractRuntimeDataModelFromFile(clientPath);
|
|
1540
|
+
if (textResult) return textResult;
|
|
1539
1541
|
const mod = __require(clientPath);
|
|
1540
1542
|
const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
1541
1543
|
if (!PrismaClient) throw new Error("PrismaClient not found in @prisma/client");
|
|
1542
|
-
const runtimeDataModel = mod?.Prisma?.runtimeDataModel ?? mod?.Prisma?._runtimeDataModel;
|
|
1543
|
-
if (runtimeDataModel?.models) {
|
|
1544
|
-
return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
|
|
1545
|
-
} };
|
|
1546
|
-
}
|
|
1547
1544
|
return new PrismaClient();
|
|
1548
1545
|
} catch {
|
|
1549
1546
|
throw new Error(
|
|
@@ -1564,32 +1561,8 @@ function tryLoadFromSchemaOutput() {
|
|
|
1564
1561
|
if (!match) continue;
|
|
1565
1562
|
const outputDir = path__namespace.default.resolve(path__namespace.default.dirname(schemaPath), match[1]);
|
|
1566
1563
|
const indexPath = path__namespace.default.join(outputDir, "index.js");
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
const runtimeDataModel = mod?.Prisma?.runtimeDataModel ?? mod?.Prisma?._runtimeDataModel;
|
|
1570
|
-
if (runtimeDataModel?.models) {
|
|
1571
|
-
return {
|
|
1572
|
-
_runtimeDataModel: runtimeDataModel,
|
|
1573
|
-
$disconnect: async () => {
|
|
1574
|
-
}
|
|
1575
|
-
};
|
|
1576
|
-
}
|
|
1577
|
-
const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
|
|
1578
|
-
if (!PrismaClient) continue;
|
|
1579
|
-
try {
|
|
1580
|
-
return new PrismaClient();
|
|
1581
|
-
} catch {
|
|
1582
|
-
for (const opt of [
|
|
1583
|
-
{ datasourceUrl: "postgresql://x:x@localhost/x" },
|
|
1584
|
-
{ datasources: { db: { url: "postgresql://x:x@localhost/x" } } }
|
|
1585
|
-
]) {
|
|
1586
|
-
try {
|
|
1587
|
-
return new PrismaClient(opt);
|
|
1588
|
-
} catch {
|
|
1589
|
-
continue;
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1564
|
+
const result = extractRuntimeDataModelFromFile(indexPath);
|
|
1565
|
+
if (result) return result;
|
|
1593
1566
|
} catch {
|
|
1594
1567
|
continue;
|
|
1595
1568
|
}
|
|
@@ -1599,20 +1572,39 @@ function tryLoadFromSchemaOutput() {
|
|
|
1599
1572
|
function tryLoadFromStandardOutput() {
|
|
1600
1573
|
const candidates = [
|
|
1601
1574
|
path__namespace.default.resolve(cwd, "node_modules/.prisma/client/index.js"),
|
|
1602
|
-
path__namespace.default.resolve(cwd, "node_modules
|
|
1575
|
+
path__namespace.default.resolve(cwd, "node_modules/@prisma/client/index.js")
|
|
1603
1576
|
];
|
|
1604
1577
|
for (const clientPath of candidates) {
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
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);
|
|
1609
1591
|
if (runtimeDataModel?.models) {
|
|
1610
1592
|
return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
|
|
1611
1593
|
} };
|
|
1612
1594
|
}
|
|
1613
|
-
} catch {
|
|
1614
|
-
continue;
|
|
1615
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 {
|
|
1616
1608
|
}
|
|
1617
1609
|
return null;
|
|
1618
1610
|
}
|