@suss/contract-prisma 0.34.0 → 0.34.1

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.cjs CHANGED
@@ -31,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  prismaSchemaFileToSummaries: () => prismaSchemaFileToSummaries,
34
- prismaSchemaToSummaries: () => prismaSchemaToSummaries
34
+ prismaSchemaToSummaries: () => prismaSchemaToSummaries,
35
+ prismaStorageSystem: () => prismaStorageSystem
35
36
  });
36
37
  module.exports = __toCommonJS(index_exports);
37
38
  var import_node_fs = __toESM(require("fs"), 1);
@@ -60,7 +61,7 @@ function prismaSchemaToSummaries(source, options = {}) {
60
61
  const list = ast.list;
61
62
  const modelNames = /* @__PURE__ */ new Set();
62
63
  const enumNames = /* @__PURE__ */ new Set();
63
- let storageSystem = null;
64
+ const storageSystem = storageSystemIn(list);
64
65
  for (const node of list) {
65
66
  const n = node;
66
67
  if (n.type === "model" || n.type === "view") {
@@ -71,12 +72,6 @@ function prismaSchemaToSummaries(source, options = {}) {
71
72
  if (typeof n.name === "string") {
72
73
  enumNames.add(n.name);
73
74
  }
74
- } else if (n.type === "datasource") {
75
- const ds = node;
76
- const provider = readProviderString(ds);
77
- if (provider !== null && provider in PROVIDER_TO_SYSTEM) {
78
- storageSystem = PROVIDER_TO_SYSTEM[provider];
79
- }
80
75
  }
81
76
  }
82
77
  if (storageSystem === null) {
@@ -441,6 +436,25 @@ function arrayNames(value) {
441
436
  }
442
437
  return out;
443
438
  }
439
+ function prismaStorageSystem(source) {
440
+ try {
441
+ return storageSystemIn((0, import_prisma_ast.getSchema)(source).list);
442
+ } catch {
443
+ return null;
444
+ }
445
+ }
446
+ function storageSystemIn(list) {
447
+ for (const node of list) {
448
+ if (node.type !== "datasource") {
449
+ continue;
450
+ }
451
+ const provider = readProviderString(node);
452
+ if (provider !== null && provider in PROVIDER_TO_SYSTEM) {
453
+ return PROVIDER_TO_SYSTEM[provider];
454
+ }
455
+ }
456
+ return null;
457
+ }
444
458
  function readProviderString(ds) {
445
459
  for (const a of ds.assignments) {
446
460
  if (a.key !== "provider") {
@@ -455,5 +469,6 @@ function readProviderString(ds) {
455
469
  // Annotate the CommonJS export names for ESM import in node:
456
470
  0 && (module.exports = {
457
471
  prismaSchemaFileToSummaries,
458
- prismaSchemaToSummaries
472
+ prismaSchemaToSummaries,
473
+ prismaStorageSystem
459
474
  });
package/dist/index.d.cts CHANGED
@@ -29,5 +29,11 @@ declare function prismaSchemaToSummaries(source: string, options?: PrismaSchemaT
29
29
  * not exist.
30
30
  */
31
31
  declare function prismaSchemaFileToSummaries(schemaPath: string, options?: PrismaSchemaToSummariesOptions): BehavioralSummary[];
32
+ type PrismaStorageSystem = "postgresql" | "mysql" | "sqlite";
33
+ /**
34
+ * The storage system the datasource provider says, or null for MongoDB or
35
+ * a file with no datasource. The client pack binds its calls with this.
36
+ */
37
+ declare function prismaStorageSystem(source: string): PrismaStorageSystem | null;
32
38
 
33
- export { type PrismaSchemaToSummariesOptions, prismaSchemaFileToSummaries, prismaSchemaToSummaries };
39
+ export { type PrismaSchemaToSummariesOptions, type PrismaStorageSystem, prismaSchemaFileToSummaries, prismaSchemaToSummaries, prismaStorageSystem };
package/dist/index.d.ts CHANGED
@@ -29,5 +29,11 @@ declare function prismaSchemaToSummaries(source: string, options?: PrismaSchemaT
29
29
  * not exist.
30
30
  */
31
31
  declare function prismaSchemaFileToSummaries(schemaPath: string, options?: PrismaSchemaToSummariesOptions): BehavioralSummary[];
32
+ type PrismaStorageSystem = "postgresql" | "mysql" | "sqlite";
33
+ /**
34
+ * The storage system the datasource provider says, or null for MongoDB or
35
+ * a file with no datasource. The client pack binds its calls with this.
36
+ */
37
+ declare function prismaStorageSystem(source: string): PrismaStorageSystem | null;
32
38
 
33
- export { type PrismaSchemaToSummariesOptions, prismaSchemaFileToSummaries, prismaSchemaToSummaries };
39
+ export { type PrismaSchemaToSummariesOptions, type PrismaStorageSystem, prismaSchemaFileToSummaries, prismaSchemaToSummaries, prismaStorageSystem };
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ function prismaSchemaToSummaries(source, options = {}) {
25
25
  const list = ast.list;
26
26
  const modelNames = /* @__PURE__ */ new Set();
27
27
  const enumNames = /* @__PURE__ */ new Set();
28
- let storageSystem = null;
28
+ const storageSystem = storageSystemIn(list);
29
29
  for (const node of list) {
30
30
  const n = node;
31
31
  if (n.type === "model" || n.type === "view") {
@@ -36,12 +36,6 @@ function prismaSchemaToSummaries(source, options = {}) {
36
36
  if (typeof n.name === "string") {
37
37
  enumNames.add(n.name);
38
38
  }
39
- } else if (n.type === "datasource") {
40
- const ds = node;
41
- const provider = readProviderString(ds);
42
- if (provider !== null && provider in PROVIDER_TO_SYSTEM) {
43
- storageSystem = PROVIDER_TO_SYSTEM[provider];
44
- }
45
39
  }
46
40
  }
47
41
  if (storageSystem === null) {
@@ -406,6 +400,25 @@ function arrayNames(value) {
406
400
  }
407
401
  return out;
408
402
  }
403
+ function prismaStorageSystem(source) {
404
+ try {
405
+ return storageSystemIn(getSchema(source).list);
406
+ } catch {
407
+ return null;
408
+ }
409
+ }
410
+ function storageSystemIn(list) {
411
+ for (const node of list) {
412
+ if (node.type !== "datasource") {
413
+ continue;
414
+ }
415
+ const provider = readProviderString(node);
416
+ if (provider !== null && provider in PROVIDER_TO_SYSTEM) {
417
+ return PROVIDER_TO_SYSTEM[provider];
418
+ }
419
+ }
420
+ return null;
421
+ }
409
422
  function readProviderString(ds) {
410
423
  for (const a of ds.assignments) {
411
424
  if (a.key !== "provider") {
@@ -419,5 +432,6 @@ function readProviderString(ds) {
419
432
  }
420
433
  export {
421
434
  prismaSchemaFileToSummaries,
422
- prismaSchemaToSummaries
435
+ prismaSchemaToSummaries,
436
+ prismaStorageSystem
423
437
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suss/contract-prisma",
3
- "version": "0.34.0",
3
+ "version": "0.34.1",
4
4
  "type": "module",
5
5
  "description": "Turn a Prisma schema into a suss contract and check it against the queries your code runs on those tables.",
6
6
  "keywords": [
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@mrleebo/prisma-ast": "^0.15.0",
51
- "@suss/behavioral-ir": "0.34.0"
51
+ "@suss/behavioral-ir": "0.34.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "tsup": "*",