omni-rest 0.2.3 → 0.2.5

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
@@ -554,9 +554,14 @@ Please check that the path is correct and the file is readable.`
554
554
  }
555
555
  let current = path__namespace.resolve(startDir);
556
556
  while (true) {
557
- const candidate = path__namespace.join(current, "schema.prisma");
558
- if (fs3__namespace.existsSync(candidate)) {
559
- return candidate;
557
+ const candidates = [
558
+ path__namespace.join(current, "prisma", "schema.prisma"),
559
+ path__namespace.join(current, "schema.prisma")
560
+ ];
561
+ for (const candidate of candidates) {
562
+ if (fs3__namespace.existsSync(candidate)) {
563
+ return candidate;
564
+ }
560
565
  }
561
566
  const parent = path__namespace.dirname(current);
562
567
  if (parent === current) {
@@ -1536,14 +1541,11 @@ function createPrismaClient() {
1536
1541
  if (standardPrismaClient) return standardPrismaClient;
1537
1542
  try {
1538
1543
  const clientPath = __require.resolve("@prisma/client", { paths: [cwd] });
1544
+ const textResult = extractRuntimeDataModelFromFile(clientPath);
1545
+ if (textResult) return textResult;
1539
1546
  const mod = __require(clientPath);
1540
1547
  const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
1541
1548
  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
1549
  return new PrismaClient();
1548
1550
  } catch {
1549
1551
  throw new Error(
@@ -1564,32 +1566,8 @@ function tryLoadFromSchemaOutput() {
1564
1566
  if (!match) continue;
1565
1567
  const outputDir = path__namespace.default.resolve(path__namespace.default.dirname(schemaPath), match[1]);
1566
1568
  const indexPath = path__namespace.default.join(outputDir, "index.js");
1567
- if (!fs3__namespace.default.existsSync(indexPath)) continue;
1568
- const mod = __require(indexPath);
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
- }
1569
+ const result = extractRuntimeDataModelFromFile(indexPath);
1570
+ if (result) return result;
1593
1571
  } catch {
1594
1572
  continue;
1595
1573
  }
@@ -1599,20 +1577,39 @@ function tryLoadFromSchemaOutput() {
1599
1577
  function tryLoadFromStandardOutput() {
1600
1578
  const candidates = [
1601
1579
  path__namespace.default.resolve(cwd, "node_modules/.prisma/client/index.js"),
1602
- path__namespace.default.resolve(cwd, "node_modules/.prisma/client/default.js")
1580
+ path__namespace.default.resolve(cwd, "node_modules/@prisma/client/index.js")
1603
1581
  ];
1604
1582
  for (const clientPath of candidates) {
1605
- if (!fs3__namespace.default.existsSync(clientPath)) continue;
1606
- try {
1607
- const mod = __require(clientPath);
1608
- const runtimeDataModel = mod?.Prisma?.runtimeDataModel ?? mod?.Prisma?._runtimeDataModel;
1583
+ const result = extractRuntimeDataModelFromFile(clientPath);
1584
+ if (result) return result;
1585
+ }
1586
+ return null;
1587
+ }
1588
+ function extractRuntimeDataModelFromFile(filePath) {
1589
+ if (!fs3__namespace.default.existsSync(filePath)) return null;
1590
+ try {
1591
+ const src = fs3__namespace.default.readFileSync(filePath, "utf-8");
1592
+ const match = src.match(/config\.runtimeDataModel\s*=\s*JSON\.parse\("((?:[^"\\]|\\.)*)"\)/);
1593
+ if (match) {
1594
+ const json = match[1].replace(/\\"/g, '"').replace(/\\\\/g, "\\");
1595
+ const runtimeDataModel = JSON.parse(json);
1609
1596
  if (runtimeDataModel?.models) {
1610
1597
  return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
1611
1598
  } };
1612
1599
  }
1613
- } catch {
1614
- continue;
1615
1600
  }
1601
+ const match2 = src.match(/runtimeDataModel\s*=\s*(\{[\s\S]*?"models"\s*:\s*\{[\s\S]*?\}\s*\})/);
1602
+ if (match2) {
1603
+ try {
1604
+ const runtimeDataModel = JSON.parse(match2[1]);
1605
+ if (runtimeDataModel?.models) {
1606
+ return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
1607
+ } };
1608
+ }
1609
+ } catch {
1610
+ }
1611
+ }
1612
+ } catch {
1616
1613
  }
1617
1614
  return null;
1618
1615
  }