prisma-sql 1.2.0 → 1.3.0

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/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
- import { ParamMap, DirectiveProps } from '@dee-wan/schema-parser';
1
+ import { ParamMap, DirectiveProps, Model as Model$1 } from '@dee-wan/schema-parser';
2
+ export { convertDMMFToModels } from '@dee-wan/schema-parser';
2
3
 
3
4
  type SqlDialect = 'postgres' | 'sqlite';
4
5
  declare function setGlobalDialect(dialect: SqlDialect): void;
@@ -62,9 +63,9 @@ interface SqlResult {
62
63
  interface SpeedExtensionConfig {
63
64
  postgres?: any;
64
65
  sqlite?: any;
65
- dmmf?: any;
66
+ models: Model$1[];
66
67
  debug?: boolean;
67
- models?: string[];
68
+ allowedModels?: string[];
68
69
  onQuery?: (info: QueryInfo) => void;
69
70
  }
70
71
  interface QueryInfo {
@@ -75,10 +76,10 @@ interface QueryInfo {
75
76
  duration: number;
76
77
  }
77
78
  declare function speedExtension(config: SpeedExtensionConfig): (prisma: any) => any;
78
- declare function createToSQL(dmmf: any, dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
79
+ declare function createToSQL(models: Model$1[], dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
79
80
  interface PrismaSQLConfig<TClient> {
80
81
  client: TClient;
81
- dmmf: any;
82
+ models: Model$1[];
82
83
  dialect: SqlDialect;
83
84
  execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
84
85
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { ParamMap, DirectiveProps } from '@dee-wan/schema-parser';
1
+ import { ParamMap, DirectiveProps, Model as Model$1 } from '@dee-wan/schema-parser';
2
+ export { convertDMMFToModels } from '@dee-wan/schema-parser';
2
3
 
3
4
  type SqlDialect = 'postgres' | 'sqlite';
4
5
  declare function setGlobalDialect(dialect: SqlDialect): void;
@@ -62,9 +63,9 @@ interface SqlResult {
62
63
  interface SpeedExtensionConfig {
63
64
  postgres?: any;
64
65
  sqlite?: any;
65
- dmmf?: any;
66
+ models: Model$1[];
66
67
  debug?: boolean;
67
- models?: string[];
68
+ allowedModels?: string[];
68
69
  onQuery?: (info: QueryInfo) => void;
69
70
  }
70
71
  interface QueryInfo {
@@ -75,10 +76,10 @@ interface QueryInfo {
75
76
  duration: number;
76
77
  }
77
78
  declare function speedExtension(config: SpeedExtensionConfig): (prisma: any) => any;
78
- declare function createToSQL(dmmf: any, dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
79
+ declare function createToSQL(models: Model$1[], dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
79
80
  interface PrismaSQLConfig<TClient> {
80
81
  client: TClient;
81
- dmmf: any;
82
+ models: Model$1[];
82
83
  dialect: SqlDialect;
83
84
  execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
84
85
  }
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { convertDMMFToModels, isDynamicParameter, extractDynamicName } from '@dee-wan/schema-parser';
2
+ export { convertDMMFToModels } from '@dee-wan/schema-parser';
2
3
 
3
4
  var __defProp = Object.defineProperty;
4
5
  var __defProps = Object.defineProperties;
@@ -4295,8 +4296,6 @@ function transformQueryResults(method, results) {
4295
4296
  const transformer = RESULT_TRANSFORMERS[method];
4296
4297
  return transformer ? transformer(results) : results;
4297
4298
  }
4298
-
4299
- // src/index.ts
4300
4299
  var ACCELERATED_METHODS = /* @__PURE__ */ new Set([
4301
4300
  "findMany",
4302
4301
  "findFirst",
@@ -4496,9 +4495,9 @@ function speedExtension(config) {
4496
4495
  const {
4497
4496
  postgres,
4498
4497
  sqlite,
4499
- dmmf: providedDmmf,
4498
+ models,
4500
4499
  debug = false,
4501
- models: allowedModels,
4500
+ allowedModels,
4502
4501
  onQuery
4503
4502
  } = config;
4504
4503
  if (!postgres && !sqlite) {
@@ -4509,29 +4508,23 @@ function speedExtension(config) {
4509
4508
  "speedExtension cannot use both postgres and sqlite clients"
4510
4509
  );
4511
4510
  }
4511
+ if (!models || !Array.isArray(models) || models.length === 0) {
4512
+ throw new Error(
4513
+ "speedExtension requires models parameter. Convert DMMF first: speedExtension({ models: convertDMMFToModels(Prisma.dmmf.datamodel) })"
4514
+ );
4515
+ }
4512
4516
  const dialect = postgres ? "postgres" : "sqlite";
4513
4517
  const client = postgres || sqlite;
4514
4518
  setGlobalDialect(dialect);
4515
4519
  return (prisma) => {
4516
- var _a;
4517
- let dmmf = providedDmmf;
4518
- if (!dmmf) {
4519
- dmmf = prisma._dmmf || ((_a = prisma._engineConfig) == null ? void 0 : _a.document) || prisma._baseDmmf;
4520
- if (!(dmmf == null ? void 0 : dmmf.datamodel)) {
4521
- throw new Error(
4522
- "Cannot access Prisma DMMF. Please provide dmmf in config: speedExtension({ postgres: sql, dmmf: Prisma.dmmf })"
4523
- );
4524
- }
4525
- }
4526
- const allModels = convertDMMFToModels(dmmf.datamodel);
4527
- const modelMap = new Map(allModels.map((m) => [m.name, m]));
4520
+ const modelMap = new Map(models.map((m) => [m.name, m]));
4528
4521
  const executeQuery = createExecuteQuery(client, dialect);
4529
4522
  const deps = {
4530
4523
  dialect,
4531
4524
  debug,
4532
4525
  onQuery,
4533
4526
  allowedModels,
4534
- allModels,
4527
+ allModels: models,
4535
4528
  modelMap,
4536
4529
  executeQuery
4537
4530
  };
@@ -4558,6 +4551,9 @@ function speedExtension(config) {
4558
4551
  };
4559
4552
  }
4560
4553
  function createToSQLFunction(models, dialect) {
4554
+ if (!models || !Array.isArray(models) || models.length === 0) {
4555
+ throw new Error("createToSQL requires non-empty models array");
4556
+ }
4561
4557
  const modelMap = new Map(models.map((m) => [m.name, m]));
4562
4558
  setGlobalDialect(dialect);
4563
4559
  return function toSQL(model, method, args = {}) {
@@ -4570,13 +4566,14 @@ function createToSQLFunction(models, dialect) {
4570
4566
  return buildSQL(m, models, method, args, dialect);
4571
4567
  };
4572
4568
  }
4573
- function createToSQL(dmmf, dialect) {
4574
- const models = convertDMMFToModels(dmmf.datamodel);
4569
+ function createToSQL(models, dialect) {
4575
4570
  return createToSQLFunction(models, dialect);
4576
4571
  }
4577
4572
  function createPrismaSQL(config) {
4578
- const { client, dmmf, dialect, execute } = config;
4579
- const models = convertDMMFToModels(dmmf.datamodel);
4573
+ const { client, models, dialect, execute } = config;
4574
+ if (!models || !Array.isArray(models) || models.length === 0) {
4575
+ throw new Error("createPrismaSQL requires non-empty models array");
4576
+ }
4580
4577
  const toSQL = createToSQLFunction(models, dialect);
4581
4578
  function query(_0, _1) {
4582
4579
  return __async(this, arguments, function* (model, method, args = {}) {