omni-rest 0.2.1 → 0.2.3

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,18 @@ 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 mod = __require(clientPath);
1540
+ const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
1541
+ 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
+ }
1538
1547
  return new PrismaClient();
1539
1548
  } catch {
1540
1549
  throw new Error(
@@ -1557,9 +1566,50 @@ function tryLoadFromSchemaOutput() {
1557
1566
  const indexPath = path__namespace.default.join(outputDir, "index.js");
1558
1567
  if (!fs3__namespace.default.existsSync(indexPath)) continue;
1559
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
+ }
1560
1577
  const PrismaClient = mod.PrismaClient ?? mod.default?.PrismaClient;
1561
1578
  if (!PrismaClient) continue;
1562
- return new PrismaClient();
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
+ }
1593
+ } catch {
1594
+ continue;
1595
+ }
1596
+ }
1597
+ return null;
1598
+ }
1599
+ function tryLoadFromStandardOutput() {
1600
+ const candidates = [
1601
+ path__namespace.default.resolve(cwd, "node_modules/.prisma/client/index.js"),
1602
+ path__namespace.default.resolve(cwd, "node_modules/.prisma/client/default.js")
1603
+ ];
1604
+ 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;
1609
+ if (runtimeDataModel?.models) {
1610
+ return { _runtimeDataModel: runtimeDataModel, $disconnect: async () => {
1611
+ } };
1612
+ }
1563
1613
  } catch {
1564
1614
  continue;
1565
1615
  }