@prisma-next/utils 0.3.0-dev.24 → 0.3.0-dev.25
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/assertions.d.ts +27 -0
- package/dist/assertions.d.ts.map +1 -0
- package/dist/exports/assertions.d.ts +2 -0
- package/dist/exports/assertions.d.ts.map +1 -0
- package/dist/exports/assertions.js +16 -0
- package/dist/exports/assertions.js.map +1 -0
- package/package.json +5 -1
- package/src/assertions.ts +35 -0
- package/src/exports/assertions.ts +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
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 declare function assertDefined<T>(value: T | null | undefined, message: string): asserts value is T;
|
|
15
|
+
/**
|
|
16
|
+
* Asserts that a condition is true.
|
|
17
|
+
* Use for invariants that should always hold at runtime.
|
|
18
|
+
*
|
|
19
|
+
* @throws Error if condition is false
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* invariant(columns.length > 0, 'Primary key must have at least one column');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function invariant(condition: boolean, message: string): asserts condition;
|
|
27
|
+
//# sourceMappingURL=assertions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAIjG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAIhF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../../src/exports/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/assertions.ts
|
|
2
|
+
function assertDefined(value, message) {
|
|
3
|
+
if (value === null || value === void 0) {
|
|
4
|
+
throw new Error(message);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function invariant(condition, message) {
|
|
8
|
+
if (!condition) {
|
|
9
|
+
throw new Error(message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
assertDefined,
|
|
14
|
+
invariant
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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":";AAaO,SAAS,cAAiB,OAA6B,SAAqC;AACjG,MAAI,UAAU,QAAQ,UAAU,QAAW;AACzC,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;AAaO,SAAS,UAAU,WAAoB,SAAoC;AAChF,MAAI,CAAC,WAAW;AACd,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/utils",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Shared utility functions for Prisma Next",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"types": "./dist/exports/array-equal.d.ts",
|
|
20
20
|
"import": "./dist/exports/array-equal.js"
|
|
21
21
|
},
|
|
22
|
+
"./assertions": {
|
|
23
|
+
"types": "./dist/exports/assertions.d.ts",
|
|
24
|
+
"import": "./dist/exports/assertions.js"
|
|
25
|
+
},
|
|
22
26
|
"./defined": {
|
|
23
27
|
"types": "./dist/exports/defined.d.ts",
|
|
24
28
|
"import": "./dist/exports/defined.js"
|
|
@@ -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';
|