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 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 { PrismaClient } = __require(clientPath);
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
- if (!fs3__namespace.default.existsSync(indexPath)) continue;
1559
- const mod = __require(indexPath);
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 getDummyUrl(provider) {
1577
- switch (provider) {
1578
- case "mysql":
1579
- return "mysql://root:root@localhost:3306/dummy";
1580
- case "sqlite":
1581
- return "file:./dummy.db";
1582
- case "sqlserver":
1583
- return "sqlserver://localhost:1433;database=dummy;user=sa;password=dummy";
1584
- case "mongodb":
1585
- return "mongodb://localhost:27017/dummy";
1586
- case "cockroachdb":
1587
- return "postgresql://root@localhost:26257/dummy";
1588
- default:
1589
- return "postgresql://postgres:postgres@localhost:5432/dummy";
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: