@prisma-next/sql-contract 0.12.0-dev.78 → 0.12.0-dev.79

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.
@@ -6,12 +6,15 @@ interface ResolvedStorageTable {
6
6
  readonly table: StorageTable;
7
7
  }
8
8
  /**
9
- * Resolve a bare storage table name to its namespace coordinate and table IR by
10
- * scanning the contract's namespaces. For the single-namespace contracts in
11
- * scope the scan is exact; cross-namespace bare-name collisions are selected
12
- * explicitly (TML-2550).
9
+ * Resolve a bare storage table name to its namespace coordinate and table IR.
10
+ *
11
+ * When `namespaceId` is supplied, the table is resolved strictly within that
12
+ * namespace (no scan). When omitted, a bare name unique across namespaces
13
+ * resolves to its sole namespace; a bare name declared in more than one
14
+ * namespace throws a fail-fast diagnostic naming the candidate namespaces
15
+ * rather than silently selecting the first match.
13
16
  */
14
- declare function resolveStorageTable(storage: SqlStorage, tableName: string): ResolvedStorageTable | undefined;
17
+ declare function resolveStorageTable(storage: SqlStorage, tableName: string, namespaceId?: string): ResolvedStorageTable | undefined;
15
18
  //#endregion
16
19
  export { type ResolvedStorageTable, resolveStorageTable };
17
20
  //# sourceMappingURL=resolve-storage-table.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;UAGiB,oBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,YAAY;AAAA;;;;;;AAAA;iBAuBd,mBAAA,CACd,OAAA,EAAS,UAAA,EACT,SAAA,WACC,oBAAoB"}
1
+ {"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;UAGiB,oBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,YAAY;AAAA;;;;;;AAAA;AA0B9B;;;iBAAgB,mBAAA,CACd,OAAA,EAAS,UAAA,EACT,SAAA,UACA,WAAA,YACC,oBAAoB"}
@@ -6,19 +6,35 @@ function tableInNamespace(namespace, tableName) {
6
6
  return tables[tableName];
7
7
  }
8
8
  /**
9
- * Resolve a bare storage table name to its namespace coordinate and table IR by
10
- * scanning the contract's namespaces. For the single-namespace contracts in
11
- * scope the scan is exact; cross-namespace bare-name collisions are selected
12
- * explicitly (TML-2550).
9
+ * Resolve a bare storage table name to its namespace coordinate and table IR.
10
+ *
11
+ * When `namespaceId` is supplied, the table is resolved strictly within that
12
+ * namespace (no scan). When omitted, a bare name unique across namespaces
13
+ * resolves to its sole namespace; a bare name declared in more than one
14
+ * namespace throws a fail-fast diagnostic naming the candidate namespaces
15
+ * rather than silently selecting the first match.
13
16
  */
14
- function resolveStorageTable(storage, tableName) {
15
- for (const namespaceId of Object.keys(storage.namespaces)) {
17
+ function resolveStorageTable(storage, tableName, namespaceId) {
18
+ if (namespaceId !== void 0) {
16
19
  const table = tableInNamespace(storage.namespaces[namespaceId], tableName);
17
- if (table !== void 0) return {
20
+ return table === void 0 ? void 0 : {
18
21
  namespaceId,
19
22
  table
20
23
  };
21
24
  }
25
+ const matches = [];
26
+ for (const candidateNamespaceId of Object.keys(storage.namespaces)) {
27
+ const table = tableInNamespace(storage.namespaces[candidateNamespaceId], tableName);
28
+ if (table !== void 0) matches.push({
29
+ namespaceId: candidateNamespaceId,
30
+ table
31
+ });
32
+ }
33
+ if (matches.length > 1) {
34
+ const candidates = matches.map((match) => match.namespaceId).sort().join(", ");
35
+ throw new Error(`Storage table "${tableName}" is ambiguous across namespaces [${candidates}]; qualify it with a namespace coordinate.`);
36
+ }
37
+ return matches[0];
22
38
  }
23
39
  //#endregion
24
40
  export { resolveStorageTable };
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import type { SqlNamespace, SqlStorage } from './ir/sql-storage';\nimport type { StorageTable } from './ir/storage-table';\n\nexport interface ResolvedStorageTable {\n readonly namespaceId: string;\n readonly table: StorageTable;\n}\n\nfunction tableInNamespace(\n namespace: SqlNamespace | undefined,\n tableName: string,\n): StorageTable | undefined {\n if (namespace === undefined) {\n return undefined;\n }\n const tables = namespace.entries.table;\n if (!Object.hasOwn(tables, tableName)) {\n return undefined;\n }\n return tables[tableName];\n}\n\n/**\n * Resolve a bare storage table name to its namespace coordinate and table IR by\n * scanning the contract's namespaces. For the single-namespace contracts in\n * scope the scan is exact; cross-namespace bare-name collisions are selected\n * explicitly (TML-2550).\n */\nexport function resolveStorageTable(\n storage: SqlStorage,\n tableName: string,\n): ResolvedStorageTable | undefined {\n for (const namespaceId of Object.keys(storage.namespaces)) {\n const table = tableInNamespace(storage.namespaces[namespaceId], tableName);\n if (table !== undefined) {\n return { namespaceId, table };\n }\n }\n\n return undefined;\n}\n"],"mappings":";AAQA,SAAS,iBACP,WACA,WAC0B;CAC1B,IAAI,cAAc,KAAA,GAChB;CAEF,MAAM,SAAS,UAAU,QAAQ;CACjC,IAAI,CAAC,OAAO,OAAO,QAAQ,SAAS,GAClC;CAEF,OAAO,OAAO;AAChB;;;;;;;AAQA,SAAgB,oBACd,SACA,WACkC;CAClC,KAAK,MAAM,eAAe,OAAO,KAAK,QAAQ,UAAU,GAAG;EACzD,MAAM,QAAQ,iBAAiB,QAAQ,WAAW,cAAc,SAAS;EACzE,IAAI,UAAU,KAAA,GACZ,OAAO;GAAE;GAAa;EAAM;CAEhC;AAGF"}
1
+ {"version":3,"file":"resolve-storage-table.mjs","names":[],"sources":["../src/resolve-storage-table.ts"],"sourcesContent":["import type { SqlNamespace, SqlStorage } from './ir/sql-storage';\nimport type { StorageTable } from './ir/storage-table';\n\nexport interface ResolvedStorageTable {\n readonly namespaceId: string;\n readonly table: StorageTable;\n}\n\nfunction tableInNamespace(\n namespace: SqlNamespace | undefined,\n tableName: string,\n): StorageTable | undefined {\n if (namespace === undefined) {\n return undefined;\n }\n const tables = namespace.entries.table;\n if (!Object.hasOwn(tables, tableName)) {\n return undefined;\n }\n return tables[tableName];\n}\n\n/**\n * Resolve a bare storage table name to its namespace coordinate and table IR.\n *\n * When `namespaceId` is supplied, the table is resolved strictly within that\n * namespace (no scan). When omitted, a bare name unique across namespaces\n * resolves to its sole namespace; a bare name declared in more than one\n * namespace throws a fail-fast diagnostic naming the candidate namespaces\n * rather than silently selecting the first match.\n */\nexport function resolveStorageTable(\n storage: SqlStorage,\n tableName: string,\n namespaceId?: string,\n): ResolvedStorageTable | undefined {\n if (namespaceId !== undefined) {\n const table = tableInNamespace(storage.namespaces[namespaceId], tableName);\n return table === undefined ? undefined : { namespaceId, table };\n }\n\n const matches: ResolvedStorageTable[] = [];\n for (const candidateNamespaceId of Object.keys(storage.namespaces)) {\n const table = tableInNamespace(storage.namespaces[candidateNamespaceId], tableName);\n if (table !== undefined) {\n matches.push({ namespaceId: candidateNamespaceId, table });\n }\n }\n\n if (matches.length > 1) {\n const candidates = matches\n .map((match) => match.namespaceId)\n .sort()\n .join(', ');\n throw new Error(\n `Storage table \"${tableName}\" is ambiguous across namespaces [${candidates}]; qualify it with a namespace coordinate.`,\n );\n }\n\n return matches[0];\n}\n"],"mappings":";AAQA,SAAS,iBACP,WACA,WAC0B;CAC1B,IAAI,cAAc,KAAA,GAChB;CAEF,MAAM,SAAS,UAAU,QAAQ;CACjC,IAAI,CAAC,OAAO,OAAO,QAAQ,SAAS,GAClC;CAEF,OAAO,OAAO;AAChB;;;;;;;;;;AAWA,SAAgB,oBACd,SACA,WACA,aACkC;CAClC,IAAI,gBAAgB,KAAA,GAAW;EAC7B,MAAM,QAAQ,iBAAiB,QAAQ,WAAW,cAAc,SAAS;EACzE,OAAO,UAAU,KAAA,IAAY,KAAA,IAAY;GAAE;GAAa;EAAM;CAChE;CAEA,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,wBAAwB,OAAO,KAAK,QAAQ,UAAU,GAAG;EAClE,MAAM,QAAQ,iBAAiB,QAAQ,WAAW,uBAAuB,SAAS;EAClF,IAAI,UAAU,KAAA,GACZ,QAAQ,KAAK;GAAE,aAAa;GAAsB;EAAM,CAAC;CAE7D;CAEA,IAAI,QAAQ,SAAS,GAAG;EACtB,MAAM,aAAa,QAChB,KAAK,UAAU,MAAM,WAAW,CAAC,CACjC,KAAK,CAAC,CACN,KAAK,IAAI;EACZ,MAAM,IAAI,MACR,kBAAkB,UAAU,oCAAoC,WAAW,2CAC7E;CACF;CAEA,OAAO,QAAQ;AACjB"}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract",
3
- "version": "0.12.0-dev.78",
3
+ "version": "0.12.0-dev.79",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "description": "SQL contract types, validators, and IR factories for Prisma Next",
8
8
  "dependencies": {
9
- "@prisma-next/contract": "0.12.0-dev.78",
10
- "@prisma-next/framework-components": "0.12.0-dev.78",
11
- "@prisma-next/utils": "0.12.0-dev.78",
9
+ "@prisma-next/contract": "0.12.0-dev.79",
10
+ "@prisma-next/framework-components": "0.12.0-dev.79",
11
+ "@prisma-next/utils": "0.12.0-dev.79",
12
12
  "arktype": "^2.2.0"
13
13
  },
14
14
  "devDependencies": {
15
- "@prisma-next/test-utils": "0.12.0-dev.78",
16
- "@prisma-next/tsconfig": "0.12.0-dev.78",
17
- "@prisma-next/tsdown": "0.12.0-dev.78",
15
+ "@prisma-next/test-utils": "0.12.0-dev.79",
16
+ "@prisma-next/tsconfig": "0.12.0-dev.79",
17
+ "@prisma-next/tsdown": "0.12.0-dev.79",
18
18
  "tsdown": "0.22.1",
19
19
  "typescript": "5.9.3",
20
20
  "vitest": "4.1.8"
@@ -21,21 +21,41 @@ function tableInNamespace(
21
21
  }
22
22
 
23
23
  /**
24
- * Resolve a bare storage table name to its namespace coordinate and table IR by
25
- * scanning the contract's namespaces. For the single-namespace contracts in
26
- * scope the scan is exact; cross-namespace bare-name collisions are selected
27
- * explicitly (TML-2550).
24
+ * Resolve a bare storage table name to its namespace coordinate and table IR.
25
+ *
26
+ * When `namespaceId` is supplied, the table is resolved strictly within that
27
+ * namespace (no scan). When omitted, a bare name unique across namespaces
28
+ * resolves to its sole namespace; a bare name declared in more than one
29
+ * namespace throws a fail-fast diagnostic naming the candidate namespaces
30
+ * rather than silently selecting the first match.
28
31
  */
29
32
  export function resolveStorageTable(
30
33
  storage: SqlStorage,
31
34
  tableName: string,
35
+ namespaceId?: string,
32
36
  ): ResolvedStorageTable | undefined {
33
- for (const namespaceId of Object.keys(storage.namespaces)) {
37
+ if (namespaceId !== undefined) {
34
38
  const table = tableInNamespace(storage.namespaces[namespaceId], tableName);
39
+ return table === undefined ? undefined : { namespaceId, table };
40
+ }
41
+
42
+ const matches: ResolvedStorageTable[] = [];
43
+ for (const candidateNamespaceId of Object.keys(storage.namespaces)) {
44
+ const table = tableInNamespace(storage.namespaces[candidateNamespaceId], tableName);
35
45
  if (table !== undefined) {
36
- return { namespaceId, table };
46
+ matches.push({ namespaceId: candidateNamespaceId, table });
37
47
  }
38
48
  }
39
49
 
40
- return undefined;
50
+ if (matches.length > 1) {
51
+ const candidates = matches
52
+ .map((match) => match.namespaceId)
53
+ .sort()
54
+ .join(', ');
55
+ throw new Error(
56
+ `Storage table "${tableName}" is ambiguous across namespaces [${candidates}]; qualify it with a namespace coordinate.`,
57
+ );
58
+ }
59
+
60
+ return matches[0];
41
61
  }