prisma-sql 1.2.0 → 1.4.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;
@@ -10,7 +11,6 @@ interface SQLDirective {
10
11
  staticParams: any[];
11
12
  dynamicKeys: string[];
12
13
  paramMappings: readonly ParamMap[];
13
- cache: DirectiveProps['cache'];
14
14
  originalDirective: DirectiveProps;
15
15
  }
16
16
 
@@ -62,9 +62,9 @@ interface SqlResult {
62
62
  interface SpeedExtensionConfig {
63
63
  postgres?: any;
64
64
  sqlite?: any;
65
- dmmf?: any;
65
+ models: Model$1[];
66
66
  debug?: boolean;
67
- models?: string[];
67
+ allowedModels?: string[];
68
68
  onQuery?: (info: QueryInfo) => void;
69
69
  }
70
70
  interface QueryInfo {
@@ -75,10 +75,10 @@ interface QueryInfo {
75
75
  duration: number;
76
76
  }
77
77
  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;
78
+ declare function createToSQL(models: Model$1[], dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
79
79
  interface PrismaSQLConfig<TClient> {
80
80
  client: TClient;
81
- dmmf: any;
81
+ models: Model$1[];
82
82
  dialect: SqlDialect;
83
83
  execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
84
84
  }
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;
@@ -10,7 +11,6 @@ interface SQLDirective {
10
11
  staticParams: any[];
11
12
  dynamicKeys: string[];
12
13
  paramMappings: readonly ParamMap[];
13
- cache: DirectiveProps['cache'];
14
14
  originalDirective: DirectiveProps;
15
15
  }
16
16
 
@@ -62,9 +62,9 @@ interface SqlResult {
62
62
  interface SpeedExtensionConfig {
63
63
  postgres?: any;
64
64
  sqlite?: any;
65
- dmmf?: any;
65
+ models: Model$1[];
66
66
  debug?: boolean;
67
- models?: string[];
67
+ allowedModels?: string[];
68
68
  onQuery?: (info: QueryInfo) => void;
69
69
  }
70
70
  interface QueryInfo {
@@ -75,10 +75,10 @@ interface QueryInfo {
75
75
  duration: number;
76
76
  }
77
77
  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;
78
+ declare function createToSQL(models: Model$1[], dialect: SqlDialect): (model: string, method: PrismaMethod, args?: Record<string, unknown>) => SqlResult;
79
79
  interface PrismaSQLConfig<TClient> {
80
80
  client: TClient;
81
- dmmf: any;
81
+ models: Model$1[];
82
82
  dialect: SqlDialect;
83
83
  execute: (client: TClient, sql: string, params: unknown[]) => Promise<unknown[]>;
84
84
  }
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;
@@ -4226,7 +4227,6 @@ function finalizeDirective(args) {
4226
4227
  staticParams,
4227
4228
  dynamicKeys,
4228
4229
  paramMappings: normalizedMappings,
4229
- cache: directive.cache,
4230
4230
  originalDirective: directive
4231
4231
  };
4232
4232
  }
@@ -4295,8 +4295,6 @@ function transformQueryResults(method, results) {
4295
4295
  const transformer = RESULT_TRANSFORMERS[method];
4296
4296
  return transformer ? transformer(results) : results;
4297
4297
  }
4298
-
4299
- // src/index.ts
4300
4298
  var ACCELERATED_METHODS = /* @__PURE__ */ new Set([
4301
4299
  "findMany",
4302
4300
  "findFirst",
@@ -4496,9 +4494,9 @@ function speedExtension(config) {
4496
4494
  const {
4497
4495
  postgres,
4498
4496
  sqlite,
4499
- dmmf: providedDmmf,
4497
+ models,
4500
4498
  debug = false,
4501
- models: allowedModels,
4499
+ allowedModels,
4502
4500
  onQuery
4503
4501
  } = config;
4504
4502
  if (!postgres && !sqlite) {
@@ -4509,29 +4507,23 @@ function speedExtension(config) {
4509
4507
  "speedExtension cannot use both postgres and sqlite clients"
4510
4508
  );
4511
4509
  }
4510
+ if (!models || !Array.isArray(models) || models.length === 0) {
4511
+ throw new Error(
4512
+ "speedExtension requires models parameter. Convert DMMF first: speedExtension({ models: convertDMMFToModels(Prisma.dmmf.datamodel) })"
4513
+ );
4514
+ }
4512
4515
  const dialect = postgres ? "postgres" : "sqlite";
4513
4516
  const client = postgres || sqlite;
4514
4517
  setGlobalDialect(dialect);
4515
4518
  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]));
4519
+ const modelMap = new Map(models.map((m) => [m.name, m]));
4528
4520
  const executeQuery = createExecuteQuery(client, dialect);
4529
4521
  const deps = {
4530
4522
  dialect,
4531
4523
  debug,
4532
4524
  onQuery,
4533
4525
  allowedModels,
4534
- allModels,
4526
+ allModels: models,
4535
4527
  modelMap,
4536
4528
  executeQuery
4537
4529
  };
@@ -4558,6 +4550,9 @@ function speedExtension(config) {
4558
4550
  };
4559
4551
  }
4560
4552
  function createToSQLFunction(models, dialect) {
4553
+ if (!models || !Array.isArray(models) || models.length === 0) {
4554
+ throw new Error("createToSQL requires non-empty models array");
4555
+ }
4561
4556
  const modelMap = new Map(models.map((m) => [m.name, m]));
4562
4557
  setGlobalDialect(dialect);
4563
4558
  return function toSQL(model, method, args = {}) {
@@ -4570,13 +4565,14 @@ function createToSQLFunction(models, dialect) {
4570
4565
  return buildSQL(m, models, method, args, dialect);
4571
4566
  };
4572
4567
  }
4573
- function createToSQL(dmmf, dialect) {
4574
- const models = convertDMMFToModels(dmmf.datamodel);
4568
+ function createToSQL(models, dialect) {
4575
4569
  return createToSQLFunction(models, dialect);
4576
4570
  }
4577
4571
  function createPrismaSQL(config) {
4578
- const { client, dmmf, dialect, execute } = config;
4579
- const models = convertDMMFToModels(dmmf.datamodel);
4572
+ const { client, models, dialect, execute } = config;
4573
+ if (!models || !Array.isArray(models) || models.length === 0) {
4574
+ throw new Error("createPrismaSQL requires non-empty models array");
4575
+ }
4580
4576
  const toSQL = createToSQLFunction(models, dialect);
4581
4577
  function query(_0, _1) {
4582
4578
  return __async(this, arguments, function* (model, method, args = {}) {