@prisma-next/utils 0.3.0-pr.103.17 → 0.3.0-pr.103.18

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.
@@ -0,0 +1,30 @@
1
+ //#region src/assertions.d.ts
2
+ /**
3
+ * Asserts that a value is defined (not null or undefined).
4
+ * Use for invariants where the value should always exist at runtime.
5
+ *
6
+ * @throws Error if value is null or undefined
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const table = storage.tables[tableName];
11
+ * assertDefined(table, `Table "${tableName}" not found`);
12
+ * // table is now narrowed to non-nullable
13
+ * ```
14
+ */
15
+ declare function assertDefined<T>(value: T | null | undefined, message: string): asserts value is T;
16
+ /**
17
+ * Asserts that a condition is true.
18
+ * Use for invariants that should always hold at runtime.
19
+ *
20
+ * @throws Error if condition is false
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * invariant(columns.length > 0, 'Primary key must have at least one column');
25
+ * ```
26
+ */
27
+ declare function invariant(condition: boolean, message: string): asserts condition;
28
+ //#endregion
29
+ export { assertDefined, invariant };
30
+ //# sourceMappingURL=assertions.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.d.mts","names":[],"sources":["../src/assertions.ts"],"sourcesContent":[],"mappings":";;AAaA;AAiBA;;;;;;;;;;;iBAjBgB,wBAAwB,yDAAyD;;;;;;;;;;;;iBAiBjF,SAAA"}
@@ -0,0 +1,35 @@
1
+ //#region src/assertions.ts
2
+ /**
3
+ * Asserts that a value is defined (not null or undefined).
4
+ * Use for invariants where the value should always exist at runtime.
5
+ *
6
+ * @throws Error if value is null or undefined
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const table = storage.tables[tableName];
11
+ * assertDefined(table, `Table "${tableName}" not found`);
12
+ * // table is now narrowed to non-nullable
13
+ * ```
14
+ */
15
+ function assertDefined(value, message) {
16
+ if (value === null || value === void 0) throw new Error(message);
17
+ }
18
+ /**
19
+ * Asserts that a condition is true.
20
+ * Use for invariants that should always hold at runtime.
21
+ *
22
+ * @throws Error if condition is false
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * invariant(columns.length > 0, 'Primary key must have at least one column');
27
+ * ```
28
+ */
29
+ function invariant(condition, message) {
30
+ if (!condition) throw new Error(message);
31
+ }
32
+
33
+ //#endregion
34
+ export { assertDefined, invariant };
35
+ //# sourceMappingURL=assertions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.mjs","names":[],"sources":["../src/assertions.ts"],"sourcesContent":["/**\n * Asserts that a value is defined (not null or undefined).\n * Use for invariants where the value should always exist at runtime.\n *\n * @throws Error if value is null or undefined\n *\n * @example\n * ```typescript\n * const table = storage.tables[tableName];\n * assertDefined(table, `Table \"${tableName}\" not found`);\n * // table is now narrowed to non-nullable\n * ```\n */\nexport function assertDefined<T>(value: T | null | undefined, message: string): asserts value is T {\n if (value === null || value === undefined) {\n throw new Error(message);\n }\n}\n\n/**\n * Asserts that a condition is true.\n * Use for invariants that should always hold at runtime.\n *\n * @throws Error if condition is false\n *\n * @example\n * ```typescript\n * invariant(columns.length > 0, 'Primary key must have at least one column');\n * ```\n */\nexport function invariant(condition: boolean, message: string): asserts condition {\n if (!condition) {\n throw new Error(message);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,cAAiB,OAA6B,SAAqC;AACjG,KAAI,UAAU,QAAQ,UAAU,OAC9B,OAAM,IAAI,MAAM,QAAQ;;;;;;;;;;;;;AAe5B,SAAgB,UAAU,WAAoB,SAAoC;AAChF,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,QAAQ"}
@@ -27,4 +27,4 @@ function ifDefined(key, value) {
27
27
 
28
28
  //#endregion
29
29
  export { ifDefined as t };
30
- //# sourceMappingURL=defined-Be_l0Ts1.mjs.map
30
+ //# sourceMappingURL=defined-BuK2JPgV.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"defined-Be_l0Ts1.mjs","names":[],"sources":["../src/defined.ts"],"sourcesContent":["/**\n * Returns an object with the key/value if value is defined, otherwise an empty object.\n *\n * Use with spread to conditionally include optional properties while satisfying\n * exactOptionalPropertyTypes. This is explicit about which properties are optional\n * and won't inadvertently strip other undefined values.\n *\n * @example\n * ```typescript\n * // Instead of:\n * const obj = {\n * required: 'value',\n * ...(optional ? { optional } : {}),\n * };\n *\n * // Use:\n * const obj = {\n * required: 'value',\n * ...ifDefined('optional', optional),\n * };\n * ```\n */\nexport function ifDefined<K extends string, V>(\n key: K,\n value: V | undefined,\n): Record<never, never> | { [P in K]: V } {\n return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UACd,KACA,OACwC;AACxC,QAAO,UAAU,SAAa,GAAG,MAAM,OAAO,GAAuB,EAAE"}
1
+ {"version":3,"file":"defined-BuK2JPgV.mjs","names":[],"sources":["../src/defined.ts"],"sourcesContent":["/**\n * Returns an object with the key/value if value is defined, otherwise an empty object.\n *\n * Use with spread to conditionally include optional properties while satisfying\n * exactOptionalPropertyTypes. This is explicit about which properties are optional\n * and won't inadvertently strip other undefined values.\n *\n * @example\n * ```typescript\n * // Instead of:\n * const obj = {\n * required: 'value',\n * ...(optional ? { optional } : {}),\n * };\n *\n * // Use:\n * const obj = {\n * required: 'value',\n * ...ifDefined('optional', optional),\n * };\n * ```\n */\nexport function ifDefined<K extends string, V>(\n key: K,\n value: V | undefined,\n): Record<never, never> | { [P in K]: V } {\n return value !== undefined ? ({ [key]: value } as { [P in K]: V }) : {};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,UACd,KACA,OACwC;AACxC,QAAO,UAAU,SAAa,GAAG,MAAM,OAAO,GAAuB,EAAE"}
package/dist/defined.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { t as ifDefined } from "./defined-Be_l0Ts1.mjs";
1
+ import { t as ifDefined } from "./defined-BuK2JPgV.mjs";
2
2
 
3
3
  export { ifDefined };
@@ -1,4 +1,4 @@
1
- import { t as ifDefined } from "./defined-Be_l0Ts1.mjs";
1
+ import { t as ifDefined } from "./defined-BuK2JPgV.mjs";
2
2
 
3
3
  //#region src/redact-db-url.ts
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma-next/utils",
3
- "version": "0.3.0-pr.103.17",
3
+ "version": "0.3.0-pr.103.18",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Shared utility functions for Prisma Next",
@@ -20,6 +20,7 @@
20
20
  },
21
21
  "exports": {
22
22
  "./array-equal": "./dist/array-equal.mjs",
23
+ "./assertions": "./dist/assertions.mjs",
23
24
  "./defined": "./dist/defined.mjs",
24
25
  "./redact-db-url": "./dist/redact-db-url.mjs",
25
26
  "./result": "./dist/result.mjs",
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Asserts that a value is defined (not null or undefined).
3
+ * Use for invariants where the value should always exist at runtime.
4
+ *
5
+ * @throws Error if value is null or undefined
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const table = storage.tables[tableName];
10
+ * assertDefined(table, `Table "${tableName}" not found`);
11
+ * // table is now narrowed to non-nullable
12
+ * ```
13
+ */
14
+ export function assertDefined<T>(value: T | null | undefined, message: string): asserts value is T {
15
+ if (value === null || value === undefined) {
16
+ throw new Error(message);
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Asserts that a condition is true.
22
+ * Use for invariants that should always hold at runtime.
23
+ *
24
+ * @throws Error if condition is false
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * invariant(columns.length > 0, 'Primary key must have at least one column');
29
+ * ```
30
+ */
31
+ export function invariant(condition: boolean, message: string): asserts condition {
32
+ if (!condition) {
33
+ throw new Error(message);
34
+ }
35
+ }
@@ -0,0 +1 @@
1
+ export { assertDefined, invariant } from '../assertions';