@prisma-next/utils 0.3.0-dev.9 → 0.3.0-pr.100.2
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/{array-equal.d.ts → array-equal.d.mts} +5 -2
- package/dist/array-equal.d.mts.map +1 -0
- package/dist/array-equal.mjs +26 -0
- package/dist/array-equal.mjs.map +1 -0
- package/dist/assertions.d.mts +30 -0
- package/dist/assertions.d.mts.map +1 -0
- package/dist/assertions.mjs +35 -0
- package/dist/assertions.mjs.map +1 -0
- package/dist/defined-BuK2JPgV.mjs +30 -0
- package/dist/defined-BuK2JPgV.mjs.map +1 -0
- package/dist/{defined.d.ts → defined.d.mts} +5 -4
- package/dist/defined.d.mts.map +1 -0
- package/dist/defined.mjs +3 -0
- package/dist/redact-db-url.d.mts +21 -0
- package/dist/redact-db-url.d.mts.map +1 -0
- package/dist/redact-db-url.mjs +27 -0
- package/dist/redact-db-url.mjs.map +1 -0
- package/dist/{result.d.ts → result.d.mts} +18 -15
- package/dist/result.d.mts.map +1 -0
- package/dist/result.mjs +79 -0
- package/dist/result.mjs.map +1 -0
- package/package.json +18 -24
- package/src/assertions.ts +35 -0
- package/src/exports/assertions.ts +1 -0
- package/dist/array-equal.d.ts.map +0 -1
- package/dist/chunk-ZDWVVJU6.js +0 -9
- package/dist/chunk-ZDWVVJU6.js.map +0 -1
- package/dist/defined.d.ts.map +0 -1
- package/dist/exports/array-equal.d.ts +0 -2
- package/dist/exports/array-equal.d.ts.map +0 -1
- package/dist/exports/array-equal.js +0 -16
- package/dist/exports/array-equal.js.map +0 -1
- package/dist/exports/defined.d.ts +0 -2
- package/dist/exports/defined.d.ts.map +0 -1
- package/dist/exports/defined.js +0 -7
- package/dist/exports/defined.js.map +0 -1
- package/dist/exports/redact-db-url.d.ts +0 -3
- package/dist/exports/redact-db-url.d.ts.map +0 -1
- package/dist/exports/redact-db-url.js +0 -23
- package/dist/exports/redact-db-url.js.map +0 -1
- package/dist/exports/result.d.ts +0 -3
- package/dist/exports/result.d.ts.map +0 -1
- package/dist/exports/result.js +0 -75
- package/dist/exports/result.js.map +0 -1
- package/dist/redact-db-url.d.ts +0 -18
- package/dist/redact-db-url.d.ts.map +0 -1
- package/dist/result.d.ts.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/array-equal.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Checks if two arrays are equal using Object.is() for element comparison.
|
|
3
4
|
* Arrays are considered equal if they have the same length and each element
|
|
@@ -14,5 +15,7 @@
|
|
|
14
15
|
* isArrayEqual([0], [-0]); // false (Object.is distinguishes +0 and -0)
|
|
15
16
|
* ```
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
//#
|
|
18
|
+
declare function isArrayEqual<T>(a: readonly T[], b: readonly T[]): boolean;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isArrayEqual };
|
|
21
|
+
//# sourceMappingURL=array-equal.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-equal.d.mts","names":[],"sources":["../src/array-equal.ts"],"sourcesContent":[],"mappings":";;AAgBA;;;;;;;;;;;;;;;iBAAgB,4BAA4B,iBAAiB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/array-equal.ts
|
|
2
|
+
/**
|
|
3
|
+
* Checks if two arrays are equal using Object.is() for element comparison.
|
|
4
|
+
* Arrays are considered equal if they have the same length and each element
|
|
5
|
+
* at corresponding indices is equal according to Object.is().
|
|
6
|
+
*
|
|
7
|
+
* @param a - First array to compare
|
|
8
|
+
* @param b - Second array to compare
|
|
9
|
+
* @returns true if arrays are equal, false otherwise
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* isArrayEqual(['a', 'b'], ['a', 'b']); // true
|
|
14
|
+
* isArrayEqual(['a'], ['a', 'b']); // false
|
|
15
|
+
* isArrayEqual([0], [-0]); // false (Object.is distinguishes +0 and -0)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function isArrayEqual(a, b) {
|
|
19
|
+
if (a.length !== b.length) return false;
|
|
20
|
+
for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { isArrayEqual };
|
|
26
|
+
//# sourceMappingURL=array-equal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-equal.mjs","names":[],"sources":["../src/array-equal.ts"],"sourcesContent":["/**\n * Checks if two arrays are equal using Object.is() for element comparison.\n * Arrays are considered equal if they have the same length and each element\n * at corresponding indices is equal according to Object.is().\n *\n * @param a - First array to compare\n * @param b - Second array to compare\n * @returns true if arrays are equal, false otherwise\n *\n * @example\n * ```typescript\n * isArrayEqual(['a', 'b'], ['a', 'b']); // true\n * isArrayEqual(['a'], ['a', 'b']); // false\n * isArrayEqual([0], [-0]); // false (Object.is distinguishes +0 and -0)\n * ```\n */\nexport function isArrayEqual<T>(a: readonly T[], b: readonly T[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (!Object.is(a[i], b[i])) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAgBA,SAAgB,aAAgB,GAAiB,GAA0B;AACzE,KAAI,EAAE,WAAW,EAAE,OACjB,QAAO;AAET,MAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,IAC5B,KAAI,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,GAAG,CACxB,QAAO;AAGX,QAAO"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/defined.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns an object with the key/value if value is defined, otherwise an empty object.
|
|
4
|
+
*
|
|
5
|
+
* Use with spread to conditionally include optional properties while satisfying
|
|
6
|
+
* exactOptionalPropertyTypes. This is explicit about which properties are optional
|
|
7
|
+
* and won't inadvertently strip other undefined values.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Instead of:
|
|
12
|
+
* const obj = {
|
|
13
|
+
* required: 'value',
|
|
14
|
+
* ...(optional ? { optional } : {}),
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* // Use:
|
|
18
|
+
* const obj = {
|
|
19
|
+
* required: 'value',
|
|
20
|
+
* ...ifDefined('optional', optional),
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function ifDefined(key, value) {
|
|
25
|
+
return value !== void 0 ? { [key]: value } : {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ifDefined as t };
|
|
30
|
+
//# sourceMappingURL=defined-BuK2JPgV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/defined.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Returns an object with the key/value if value is defined, otherwise an empty object.
|
|
3
4
|
*
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
* };
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=defined.d.
|
|
24
|
+
declare function ifDefined<K extends string, V>(key: K, value: V | undefined): Record<never, never> | { [P in K]: V };
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ifDefined };
|
|
27
|
+
//# sourceMappingURL=defined.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defined.d.mts","names":[],"sources":["../src/defined.ts"],"sourcesContent":[],"mappings":";;AAsBA;;;;;;;;;;;;;;;;;;;;;iBAAgB,oCACT,UACE,gBACN,+BAA+B,IAAI"}
|
package/dist/defined.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/redact-db-url.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Minimal metadata extracted from a database URL for logging or error output.
|
|
4
|
+
* Sensitive fields (password, full URL) are never returned.
|
|
5
|
+
*/
|
|
6
|
+
interface RedactedDatabaseUrl {
|
|
7
|
+
readonly host?: string;
|
|
8
|
+
readonly port?: string;
|
|
9
|
+
readonly database?: string;
|
|
10
|
+
readonly username?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Redacts a database connection URL to a minimal metadata object.
|
|
14
|
+
*
|
|
15
|
+
* Parsing errors are ignored and result in an empty object so callers never
|
|
16
|
+
* leak raw URLs when the input is malformed.
|
|
17
|
+
*/
|
|
18
|
+
declare function redactDatabaseUrl(url: string): RedactedDatabaseUrl;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { type RedactedDatabaseUrl, redactDatabaseUrl };
|
|
21
|
+
//# sourceMappingURL=redact-db-url.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact-db-url.d.mts","names":[],"sources":["../src/redact-db-url.ts"],"sourcesContent":[],"mappings":";;AAMA;AAaA;;UAbiB,mBAAA;;;;;;;;;;;;iBAaD,iBAAA,eAAgC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { t as ifDefined } from "./defined-BuK2JPgV.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/redact-db-url.ts
|
|
4
|
+
/**
|
|
5
|
+
* Redacts a database connection URL to a minimal metadata object.
|
|
6
|
+
*
|
|
7
|
+
* Parsing errors are ignored and result in an empty object so callers never
|
|
8
|
+
* leak raw URLs when the input is malformed.
|
|
9
|
+
*/
|
|
10
|
+
function redactDatabaseUrl(url) {
|
|
11
|
+
try {
|
|
12
|
+
const parsed = new URL(url);
|
|
13
|
+
const database = parsed.pathname?.replace(/^\//, "") || void 0;
|
|
14
|
+
return {
|
|
15
|
+
...ifDefined("host", parsed.hostname || void 0),
|
|
16
|
+
...ifDefined("port", parsed.port || void 0),
|
|
17
|
+
...ifDefined("database", database),
|
|
18
|
+
...ifDefined("username", parsed.username || void 0)
|
|
19
|
+
};
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { redactDatabaseUrl };
|
|
27
|
+
//# sourceMappingURL=redact-db-url.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redact-db-url.mjs","names":[],"sources":["../src/redact-db-url.ts"],"sourcesContent":["import { ifDefined } from './defined';\n\n/**\n * Minimal metadata extracted from a database URL for logging or error output.\n * Sensitive fields (password, full URL) are never returned.\n */\nexport interface RedactedDatabaseUrl {\n readonly host?: string;\n readonly port?: string;\n readonly database?: string;\n readonly username?: string;\n}\n\n/**\n * Redacts a database connection URL to a minimal metadata object.\n *\n * Parsing errors are ignored and result in an empty object so callers never\n * leak raw URLs when the input is malformed.\n */\nexport function redactDatabaseUrl(url: string): RedactedDatabaseUrl {\n try {\n const parsed = new URL(url);\n const database = parsed.pathname?.replace(/^\\//, '') || undefined;\n return {\n ...ifDefined('host', parsed.hostname || undefined),\n ...ifDefined('port', parsed.port || undefined),\n ...ifDefined('database', database),\n ...ifDefined('username', parsed.username || undefined),\n };\n } catch {\n // Ignore parsing errors; return empty metadata\n return {};\n }\n}\n"],"mappings":";;;;;;;;;AAmBA,SAAgB,kBAAkB,KAAkC;AAClE,KAAI;EACF,MAAM,SAAS,IAAI,IAAI,IAAI;EAC3B,MAAM,WAAW,OAAO,UAAU,QAAQ,OAAO,GAAG,IAAI;AACxD,SAAO;GACL,GAAG,UAAU,QAAQ,OAAO,YAAY,OAAU;GAClD,GAAG,UAAU,QAAQ,OAAO,QAAQ,OAAU;GAC9C,GAAG,UAAU,YAAY,SAAS;GAClC,GAAG,UAAU,YAAY,OAAO,YAAY,OAAU;GACvD;SACK;AAEN,SAAO,EAAE"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/result.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Generic Result type for representing success or failure outcomes.
|
|
3
4
|
*
|
|
@@ -12,20 +13,20 @@
|
|
|
12
13
|
/**
|
|
13
14
|
* Represents a successful result containing a value.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
interface Ok<T> {
|
|
17
|
+
readonly ok: true;
|
|
18
|
+
readonly value: T;
|
|
19
|
+
assertOk(): T;
|
|
20
|
+
assertNotOk(): never;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* Represents an unsuccessful result containing failure details.
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
interface NotOk<F> {
|
|
26
|
+
readonly ok: false;
|
|
27
|
+
readonly failure: F;
|
|
28
|
+
assertOk(): never;
|
|
29
|
+
assertNotOk(): F;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* A discriminated union representing either success (Ok) or failure (NotOk).
|
|
@@ -33,18 +34,20 @@ export interface NotOk<F> {
|
|
|
33
34
|
* @typeParam T - The success value type
|
|
34
35
|
* @typeParam F - The failure details type
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
+
type Result<T, F> = Ok<T> | NotOk<F>;
|
|
37
38
|
/**
|
|
38
39
|
* Creates a successful result.
|
|
39
40
|
*/
|
|
40
|
-
|
|
41
|
+
declare function ok<T>(value: T): Ok<T>;
|
|
41
42
|
/**
|
|
42
43
|
* Creates an unsuccessful result.
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
declare function notOk<F>(failure: F): NotOk<F>;
|
|
45
46
|
/**
|
|
46
47
|
* Returns a successful void result.
|
|
47
48
|
* Use this for validation checks that don't produce a value.
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
-
//#
|
|
50
|
+
declare function okVoid(): Ok<void>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { type NotOk, type Ok, type Result, notOk, ok, okVoid };
|
|
53
|
+
//# sourceMappingURL=result.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.d.mts","names":[],"sources":["../src/result.ts"],"sourcesContent":[],"mappings":";;AAeA;AAUA;AAaA;;;;;;AAgFA;;;;;AAOgB,UA9GC,EA8GI,CAAA,CAAA,CAAA,CAAA;EAAa,SAAA,EAAA,EAAA,IAAA;EAAU,SAAA,KAAA,EA5G1B,CA4G0B;EAAN,QAAA,EAAA,EA3GxB,CA2GwB;EAAK,WAAA,EAAA,EAAA,KAAA;AAc3C;;;;UAlHiB;;oBAEG;;iBAEH;;;;;;;;KASL,eAAe,GAAG,KAAK,MAAM;;;;iBAgFzB,aAAa,IAAI,GAAG;;;;iBAOpB,kBAAkB,IAAI,MAAM;;;;;iBAc5B,MAAA,CAAA,GAAU"}
|
package/dist/result.mjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/result.ts
|
|
2
|
+
/**
|
|
3
|
+
* Result class that implements both Ok and NotOk variants.
|
|
4
|
+
*/
|
|
5
|
+
var ResultImpl = class ResultImpl {
|
|
6
|
+
ok;
|
|
7
|
+
_value;
|
|
8
|
+
_failure;
|
|
9
|
+
constructor(ok$1, valueOrFailure) {
|
|
10
|
+
this.ok = ok$1;
|
|
11
|
+
if (ok$1) this._value = valueOrFailure;
|
|
12
|
+
else this._failure = valueOrFailure;
|
|
13
|
+
Object.freeze(this);
|
|
14
|
+
}
|
|
15
|
+
get value() {
|
|
16
|
+
if (!this.ok) throw new Error("Cannot access value on NotOk result");
|
|
17
|
+
return this._value;
|
|
18
|
+
}
|
|
19
|
+
get failure() {
|
|
20
|
+
if (this.ok) throw new Error("Cannot access failure on Ok result");
|
|
21
|
+
return this._failure;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a successful result.
|
|
25
|
+
*/
|
|
26
|
+
static ok(value) {
|
|
27
|
+
return new ResultImpl(true, value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates an unsuccessful result.
|
|
31
|
+
*/
|
|
32
|
+
static notOk(failure) {
|
|
33
|
+
return new ResultImpl(false, failure);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Asserts that this result is Ok and returns the value.
|
|
37
|
+
* Throws if the result is NotOk.
|
|
38
|
+
*/
|
|
39
|
+
assertOk() {
|
|
40
|
+
if (!this.ok) throw new Error("Expected Ok result but got NotOk");
|
|
41
|
+
return this.value;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Asserts that this result is NotOk and returns the failure.
|
|
45
|
+
* Throws if the result is Ok.
|
|
46
|
+
*/
|
|
47
|
+
assertNotOk() {
|
|
48
|
+
if (this.ok) throw new Error("Expected NotOk result but got Ok");
|
|
49
|
+
return this.failure;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Creates a successful result.
|
|
54
|
+
*/
|
|
55
|
+
function ok(value) {
|
|
56
|
+
return ResultImpl.ok(value);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates an unsuccessful result.
|
|
60
|
+
*/
|
|
61
|
+
function notOk(failure) {
|
|
62
|
+
return ResultImpl.notOk(failure);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Singleton for void success results.
|
|
66
|
+
* Use this for validation checks that don't produce a value.
|
|
67
|
+
*/
|
|
68
|
+
const OK_VOID = ResultImpl.ok(void 0);
|
|
69
|
+
/**
|
|
70
|
+
* Returns a successful void result.
|
|
71
|
+
* Use this for validation checks that don't produce a value.
|
|
72
|
+
*/
|
|
73
|
+
function okVoid() {
|
|
74
|
+
return OK_VOID;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { notOk, ok, okVoid };
|
|
79
|
+
//# sourceMappingURL=result.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.mjs","names":["ok","OK_VOID: Ok<void>"],"sources":["../src/result.ts"],"sourcesContent":["/**\n * Generic Result type for representing success or failure outcomes.\n *\n * This is the standard way to return \"expected failures\" as values rather than\n * throwing exceptions. See docs/Error Handling.md for the full taxonomy.\n *\n * Naming rationale:\n * - `Ok<T>` / `NotOk<F>` mirror the `ok: true/false` discriminator\n * - `NotOk` avoids collision with domain types like \"Failure\" or \"Error\"\n * - `failure` property distinguishes from JS Error semantics\n */\n\n/**\n * Represents a successful result containing a value.\n */\nexport interface Ok<T> {\n readonly ok: true;\n readonly value: T;\n assertOk(): T;\n assertNotOk(): never;\n}\n\n/**\n * Represents an unsuccessful result containing failure details.\n */\nexport interface NotOk<F> {\n readonly ok: false;\n readonly failure: F;\n assertOk(): never;\n assertNotOk(): F;\n}\n\n/**\n * A discriminated union representing either success (Ok) or failure (NotOk).\n *\n * @typeParam T - The success value type\n * @typeParam F - The failure details type\n */\nexport type Result<T, F> = Ok<T> | NotOk<F>;\n\n/**\n * Result class that implements both Ok and NotOk variants.\n */\nclass ResultImpl<T, F> {\n readonly ok: boolean;\n private readonly _value?: T;\n private readonly _failure?: F;\n\n private constructor(ok: boolean, valueOrFailure: T | F) {\n this.ok = ok;\n if (ok) {\n this._value = valueOrFailure as T;\n } else {\n this._failure = valueOrFailure as F;\n }\n Object.freeze(this);\n }\n\n get value(): T {\n if (!this.ok) {\n throw new Error('Cannot access value on NotOk result');\n }\n // biome-ignore lint/style/noNonNullAssertion: must be present if ok is true\n return this._value!;\n }\n\n get failure(): F {\n if (this.ok) {\n throw new Error('Cannot access failure on Ok result');\n }\n // biome-ignore lint/style/noNonNullAssertion: must be present if ok is false\n return this._failure!;\n }\n\n /**\n * Creates a successful result.\n */\n static ok<T, F = never>(value: T): Ok<T> {\n // TypeScript cannot express discriminated return types for a single implementation.\n // Cast is safe: ok=true guarantees this is an Ok<T> at runtime.\n return new ResultImpl<T, F>(true, value) as unknown as Ok<T>;\n }\n\n /**\n * Creates an unsuccessful result.\n */\n static notOk<T = never, F = unknown>(failure: F): NotOk<F> {\n // TypeScript cannot express discriminated return types for a single implementation.\n // Cast is safe: ok=false guarantees this is a NotOk<F> at runtime.\n return new ResultImpl<T, F>(false, failure) as unknown as NotOk<F>;\n }\n\n /**\n * Asserts that this result is Ok and returns the value.\n * Throws if the result is NotOk.\n */\n assertOk(this: Result<T, F>): T {\n if (!this.ok) {\n throw new Error('Expected Ok result but got NotOk');\n }\n return this.value;\n }\n\n /**\n * Asserts that this result is NotOk and returns the failure.\n * Throws if the result is Ok.\n */\n assertNotOk(this: Result<T, F>): F {\n if (this.ok) {\n throw new Error('Expected NotOk result but got Ok');\n }\n return this.failure;\n }\n}\n\n/**\n * Creates a successful result.\n */\nexport function ok<T>(value: T): Ok<T> {\n return ResultImpl.ok(value);\n}\n\n/**\n * Creates an unsuccessful result.\n */\nexport function notOk<F>(failure: F): NotOk<F> {\n return ResultImpl.notOk(failure);\n}\n\n/**\n * Singleton for void success results.\n * Use this for validation checks that don't produce a value.\n */\nconst OK_VOID: Ok<void> = ResultImpl.ok<void>(undefined);\n\n/**\n * Returns a successful void result.\n * Use this for validation checks that don't produce a value.\n */\nexport function okVoid(): Ok<void> {\n return OK_VOID;\n}\n"],"mappings":";;;;AA2CA,IAAM,aAAN,MAAM,WAAiB;CACrB,AAAS;CACT,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,YAAY,MAAa,gBAAuB;AACtD,OAAK,KAAKA;AACV,MAAIA,KACF,MAAK,SAAS;MAEd,MAAK,WAAW;AAElB,SAAO,OAAO,KAAK;;CAGrB,IAAI,QAAW;AACb,MAAI,CAAC,KAAK,GACR,OAAM,IAAI,MAAM,sCAAsC;AAGxD,SAAO,KAAK;;CAGd,IAAI,UAAa;AACf,MAAI,KAAK,GACP,OAAM,IAAI,MAAM,qCAAqC;AAGvD,SAAO,KAAK;;;;;CAMd,OAAO,GAAiB,OAAiB;AAGvC,SAAO,IAAI,WAAiB,MAAM,MAAM;;;;;CAM1C,OAAO,MAA8B,SAAsB;AAGzD,SAAO,IAAI,WAAiB,OAAO,QAAQ;;;;;;CAO7C,WAAgC;AAC9B,MAAI,CAAC,KAAK,GACR,OAAM,IAAI,MAAM,mCAAmC;AAErD,SAAO,KAAK;;;;;;CAOd,cAAmC;AACjC,MAAI,KAAK,GACP,OAAM,IAAI,MAAM,mCAAmC;AAErD,SAAO,KAAK;;;;;;AAOhB,SAAgB,GAAM,OAAiB;AACrC,QAAO,WAAW,GAAG,MAAM;;;;;AAM7B,SAAgB,MAAS,SAAsB;AAC7C,QAAO,WAAW,MAAM,QAAQ;;;;;;AAOlC,MAAMC,UAAoB,WAAW,GAAS,OAAU;;;;;AAMxD,SAAgB,SAAmB;AACjC,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,43 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/utils",
|
|
3
|
-
"version": "0.3.0-
|
|
3
|
+
"version": "0.3.0-pr.100.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Shared utility functions for Prisma Next",
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"
|
|
9
|
-
"tsup": "8.5.1",
|
|
8
|
+
"tsdown": "0.18.4",
|
|
10
9
|
"typescript": "5.9.3",
|
|
11
|
-
"vitest": "4.0.16"
|
|
10
|
+
"vitest": "4.0.16",
|
|
11
|
+
"@prisma-next/tsdown": "0.0.0",
|
|
12
|
+
"@prisma-next/tsconfig": "0.0.0"
|
|
12
13
|
},
|
|
13
14
|
"files": [
|
|
14
15
|
"dist",
|
|
15
16
|
"src"
|
|
16
17
|
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=20"
|
|
20
|
+
},
|
|
17
21
|
"exports": {
|
|
18
|
-
"./array-equal":
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"./
|
|
23
|
-
|
|
24
|
-
"import": "./dist/exports/defined.js"
|
|
25
|
-
},
|
|
26
|
-
"./result": {
|
|
27
|
-
"types": "./dist/exports/result.d.ts",
|
|
28
|
-
"import": "./dist/exports/result.js"
|
|
29
|
-
},
|
|
30
|
-
"./redact-db-url": {
|
|
31
|
-
"types": "./dist/exports/redact-db-url.d.ts",
|
|
32
|
-
"import": "./dist/exports/redact-db-url.js"
|
|
33
|
-
}
|
|
22
|
+
"./array-equal": "./dist/array-equal.mjs",
|
|
23
|
+
"./assertions": "./dist/assertions.mjs",
|
|
24
|
+
"./defined": "./dist/defined.mjs",
|
|
25
|
+
"./redact-db-url": "./dist/redact-db-url.mjs",
|
|
26
|
+
"./result": "./dist/result.mjs",
|
|
27
|
+
"./package.json": "./package.json"
|
|
34
28
|
},
|
|
35
29
|
"scripts": {
|
|
36
|
-
"build": "
|
|
30
|
+
"build": "tsdown",
|
|
37
31
|
"test": "vitest run",
|
|
38
32
|
"test:coverage": "vitest run --coverage",
|
|
39
|
-
"typecheck": "tsc --
|
|
40
|
-
"lint": "biome check . --
|
|
41
|
-
"clean": "
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "biome check . --error-on-warnings",
|
|
35
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
42
36
|
}
|
|
43
37
|
}
|
|
@@ -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';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array-equal.d.ts","sourceRoot":"","sources":["../src/array-equal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,GAAG,OAAO,CAUzE"}
|
package/dist/chunk-ZDWVVJU6.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"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":";AAsBO,SAAS,UACd,KACA,OACwC;AACxC,SAAO,UAAU,SAAa,EAAE,CAAC,GAAG,GAAG,MAAM,IAAwB,CAAC;AACxE;","names":[]}
|
package/dist/defined.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defined.d.ts","sourceRoot":"","sources":["../src/defined.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAC3C,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,CAAC,GAAG,SAAS,GACnB,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC;CAAE,CAExC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array-equal.d.ts","sourceRoot":"","sources":["../../src/exports/array-equal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/array-equal.ts
|
|
2
|
-
function isArrayEqual(a, b) {
|
|
3
|
-
if (a.length !== b.length) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
for (let i = 0; i < a.length; i++) {
|
|
7
|
-
if (!Object.is(a[i], b[i])) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
export {
|
|
14
|
-
isArrayEqual
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=array-equal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array-equal.ts"],"sourcesContent":["/**\n * Checks if two arrays are equal using Object.is() for element comparison.\n * Arrays are considered equal if they have the same length and each element\n * at corresponding indices is equal according to Object.is().\n *\n * @param a - First array to compare\n * @param b - Second array to compare\n * @returns true if arrays are equal, false otherwise\n *\n * @example\n * ```typescript\n * isArrayEqual(['a', 'b'], ['a', 'b']); // true\n * isArrayEqual(['a'], ['a', 'b']); // false\n * isArrayEqual([0], [-0]); // false (Object.is distinguishes +0 and -0)\n * ```\n */\nexport function isArrayEqual<T>(a: readonly T[], b: readonly T[]): boolean {\n if (a.length !== b.length) {\n return false;\n }\n for (let i = 0; i < a.length; i++) {\n if (!Object.is(a[i], b[i])) {\n return false;\n }\n }\n return true;\n}\n"],"mappings":";AAgBO,SAAS,aAAgB,GAAiB,GAA0B;AACzE,MAAI,EAAE,WAAW,EAAE,QAAQ;AACzB,WAAO;AAAA,EACT;AACA,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG;AAC1B,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defined.d.ts","sourceRoot":"","sources":["../../src/exports/defined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/exports/defined.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redact-db-url.d.ts","sourceRoot":"","sources":["../../src/exports/redact-db-url.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ifDefined
|
|
3
|
-
} from "../chunk-ZDWVVJU6.js";
|
|
4
|
-
|
|
5
|
-
// src/redact-db-url.ts
|
|
6
|
-
function redactDatabaseUrl(url) {
|
|
7
|
-
try {
|
|
8
|
-
const parsed = new URL(url);
|
|
9
|
-
const database = parsed.pathname?.replace(/^\//, "") || void 0;
|
|
10
|
-
return {
|
|
11
|
-
...ifDefined("host", parsed.hostname || void 0),
|
|
12
|
-
...ifDefined("port", parsed.port || void 0),
|
|
13
|
-
...ifDefined("database", database),
|
|
14
|
-
...ifDefined("username", parsed.username || void 0)
|
|
15
|
-
};
|
|
16
|
-
} catch {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export {
|
|
21
|
-
redactDatabaseUrl
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=redact-db-url.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/redact-db-url.ts"],"sourcesContent":["import { ifDefined } from './defined';\n\n/**\n * Minimal metadata extracted from a database URL for logging or error output.\n * Sensitive fields (password, full URL) are never returned.\n */\nexport interface RedactedDatabaseUrl {\n readonly host?: string;\n readonly port?: string;\n readonly database?: string;\n readonly username?: string;\n}\n\n/**\n * Redacts a database connection URL to a minimal metadata object.\n *\n * Parsing errors are ignored and result in an empty object so callers never\n * leak raw URLs when the input is malformed.\n */\nexport function redactDatabaseUrl(url: string): RedactedDatabaseUrl {\n try {\n const parsed = new URL(url);\n const database = parsed.pathname?.replace(/^\\//, '') || undefined;\n return {\n ...ifDefined('host', parsed.hostname || undefined),\n ...ifDefined('port', parsed.port || undefined),\n ...ifDefined('database', database),\n ...ifDefined('username', parsed.username || undefined),\n };\n } catch {\n // Ignore parsing errors; return empty metadata\n return {};\n }\n}\n"],"mappings":";;;;;AAmBO,SAAS,kBAAkB,KAAkC;AAClE,MAAI;AACF,UAAM,SAAS,IAAI,IAAI,GAAG;AAC1B,UAAM,WAAW,OAAO,UAAU,QAAQ,OAAO,EAAE,KAAK;AACxD,WAAO;AAAA,MACL,GAAG,UAAU,QAAQ,OAAO,YAAY,MAAS;AAAA,MACjD,GAAG,UAAU,QAAQ,OAAO,QAAQ,MAAS;AAAA,MAC7C,GAAG,UAAU,YAAY,QAAQ;AAAA,MACjC,GAAG,UAAU,YAAY,OAAO,YAAY,MAAS;AAAA,IACvD;AAAA,EACF,QAAQ;AAEN,WAAO,CAAC;AAAA,EACV;AACF;","names":[]}
|
package/dist/exports/result.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/exports/result.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/exports/result.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// src/result.ts
|
|
2
|
-
var ResultImpl = class _ResultImpl {
|
|
3
|
-
ok;
|
|
4
|
-
_value;
|
|
5
|
-
_failure;
|
|
6
|
-
constructor(ok2, valueOrFailure) {
|
|
7
|
-
this.ok = ok2;
|
|
8
|
-
if (ok2) {
|
|
9
|
-
this._value = valueOrFailure;
|
|
10
|
-
} else {
|
|
11
|
-
this._failure = valueOrFailure;
|
|
12
|
-
}
|
|
13
|
-
Object.freeze(this);
|
|
14
|
-
}
|
|
15
|
-
get value() {
|
|
16
|
-
if (!this.ok) {
|
|
17
|
-
throw new Error("Cannot access value on NotOk result");
|
|
18
|
-
}
|
|
19
|
-
return this._value;
|
|
20
|
-
}
|
|
21
|
-
get failure() {
|
|
22
|
-
if (this.ok) {
|
|
23
|
-
throw new Error("Cannot access failure on Ok result");
|
|
24
|
-
}
|
|
25
|
-
return this._failure;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Creates a successful result.
|
|
29
|
-
*/
|
|
30
|
-
static ok(value) {
|
|
31
|
-
return new _ResultImpl(true, value);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Creates an unsuccessful result.
|
|
35
|
-
*/
|
|
36
|
-
static notOk(failure) {
|
|
37
|
-
return new _ResultImpl(false, failure);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Asserts that this result is Ok and returns the value.
|
|
41
|
-
* Throws if the result is NotOk.
|
|
42
|
-
*/
|
|
43
|
-
assertOk() {
|
|
44
|
-
if (!this.ok) {
|
|
45
|
-
throw new Error("Expected Ok result but got NotOk");
|
|
46
|
-
}
|
|
47
|
-
return this.value;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Asserts that this result is NotOk and returns the failure.
|
|
51
|
-
* Throws if the result is Ok.
|
|
52
|
-
*/
|
|
53
|
-
assertNotOk() {
|
|
54
|
-
if (this.ok) {
|
|
55
|
-
throw new Error("Expected NotOk result but got Ok");
|
|
56
|
-
}
|
|
57
|
-
return this.failure;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
function ok(value) {
|
|
61
|
-
return ResultImpl.ok(value);
|
|
62
|
-
}
|
|
63
|
-
function notOk(failure) {
|
|
64
|
-
return ResultImpl.notOk(failure);
|
|
65
|
-
}
|
|
66
|
-
var OK_VOID = ResultImpl.ok(void 0);
|
|
67
|
-
function okVoid() {
|
|
68
|
-
return OK_VOID;
|
|
69
|
-
}
|
|
70
|
-
export {
|
|
71
|
-
notOk,
|
|
72
|
-
ok,
|
|
73
|
-
okVoid
|
|
74
|
-
};
|
|
75
|
-
//# sourceMappingURL=result.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/result.ts"],"sourcesContent":["/**\n * Generic Result type for representing success or failure outcomes.\n *\n * This is the standard way to return \"expected failures\" as values rather than\n * throwing exceptions. See docs/Error Handling.md for the full taxonomy.\n *\n * Naming rationale:\n * - `Ok<T>` / `NotOk<F>` mirror the `ok: true/false` discriminator\n * - `NotOk` avoids collision with domain types like \"Failure\" or \"Error\"\n * - `failure` property distinguishes from JS Error semantics\n */\n\n/**\n * Represents a successful result containing a value.\n */\nexport interface Ok<T> {\n readonly ok: true;\n readonly value: T;\n assertOk(): T;\n assertNotOk(): never;\n}\n\n/**\n * Represents an unsuccessful result containing failure details.\n */\nexport interface NotOk<F> {\n readonly ok: false;\n readonly failure: F;\n assertOk(): never;\n assertNotOk(): F;\n}\n\n/**\n * A discriminated union representing either success (Ok) or failure (NotOk).\n *\n * @typeParam T - The success value type\n * @typeParam F - The failure details type\n */\nexport type Result<T, F> = Ok<T> | NotOk<F>;\n\n/**\n * Result class that implements both Ok and NotOk variants.\n */\nclass ResultImpl<T, F> {\n readonly ok: boolean;\n private readonly _value?: T;\n private readonly _failure?: F;\n\n private constructor(ok: boolean, valueOrFailure: T | F) {\n this.ok = ok;\n if (ok) {\n this._value = valueOrFailure as T;\n } else {\n this._failure = valueOrFailure as F;\n }\n Object.freeze(this);\n }\n\n get value(): T {\n if (!this.ok) {\n throw new Error('Cannot access value on NotOk result');\n }\n // biome-ignore lint/style/noNonNullAssertion: must be present if ok is true\n return this._value!;\n }\n\n get failure(): F {\n if (this.ok) {\n throw new Error('Cannot access failure on Ok result');\n }\n // biome-ignore lint/style/noNonNullAssertion: must be present if ok is false\n return this._failure!;\n }\n\n /**\n * Creates a successful result.\n */\n static ok<T, F = never>(value: T): Ok<T> {\n // TypeScript cannot express discriminated return types for a single implementation.\n // Cast is safe: ok=true guarantees this is an Ok<T> at runtime.\n return new ResultImpl<T, F>(true, value) as unknown as Ok<T>;\n }\n\n /**\n * Creates an unsuccessful result.\n */\n static notOk<T = never, F = unknown>(failure: F): NotOk<F> {\n // TypeScript cannot express discriminated return types for a single implementation.\n // Cast is safe: ok=false guarantees this is a NotOk<F> at runtime.\n return new ResultImpl<T, F>(false, failure) as unknown as NotOk<F>;\n }\n\n /**\n * Asserts that this result is Ok and returns the value.\n * Throws if the result is NotOk.\n */\n assertOk(this: Result<T, F>): T {\n if (!this.ok) {\n throw new Error('Expected Ok result but got NotOk');\n }\n return this.value;\n }\n\n /**\n * Asserts that this result is NotOk and returns the failure.\n * Throws if the result is Ok.\n */\n assertNotOk(this: Result<T, F>): F {\n if (this.ok) {\n throw new Error('Expected NotOk result but got Ok');\n }\n return this.failure;\n }\n}\n\n/**\n * Creates a successful result.\n */\nexport function ok<T>(value: T): Ok<T> {\n return ResultImpl.ok(value);\n}\n\n/**\n * Creates an unsuccessful result.\n */\nexport function notOk<F>(failure: F): NotOk<F> {\n return ResultImpl.notOk(failure);\n}\n\n/**\n * Singleton for void success results.\n * Use this for validation checks that don't produce a value.\n */\nconst OK_VOID: Ok<void> = ResultImpl.ok<void>(undefined);\n\n/**\n * Returns a successful void result.\n * Use this for validation checks that don't produce a value.\n */\nexport function okVoid(): Ok<void> {\n return OK_VOID;\n}\n"],"mappings":";AA2CA,IAAM,aAAN,MAAM,YAAiB;AAAA,EACZ;AAAA,EACQ;AAAA,EACA;AAAA,EAET,YAAYA,KAAa,gBAAuB;AACtD,SAAK,KAAKA;AACV,QAAIA,KAAI;AACN,WAAK,SAAS;AAAA,IAChB,OAAO;AACL,WAAK,WAAW;AAAA,IAClB;AACA,WAAO,OAAO,IAAI;AAAA,EACpB;AAAA,EAEA,IAAI,QAAW;AACb,QAAI,CAAC,KAAK,IAAI;AACZ,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,UAAa;AACf,QAAI,KAAK,IAAI;AACX,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AAEA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,GAAiB,OAAiB;AAGvC,WAAO,IAAI,YAAiB,MAAM,KAAK;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,MAA8B,SAAsB;AAGzD,WAAO,IAAI,YAAiB,OAAO,OAAO;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAgC;AAC9B,QAAI,CAAC,KAAK,IAAI;AACZ,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACpD;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,cAAmC;AACjC,QAAI,KAAK,IAAI;AACX,YAAM,IAAI,MAAM,kCAAkC;AAAA,IACpD;AACA,WAAO,KAAK;AAAA,EACd;AACF;AAKO,SAAS,GAAM,OAAiB;AACrC,SAAO,WAAW,GAAG,KAAK;AAC5B;AAKO,SAAS,MAAS,SAAsB;AAC7C,SAAO,WAAW,MAAM,OAAO;AACjC;AAMA,IAAM,UAAoB,WAAW,GAAS,MAAS;AAMhD,SAAS,SAAmB;AACjC,SAAO;AACT;","names":["ok"]}
|
package/dist/redact-db-url.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal metadata extracted from a database URL for logging or error output.
|
|
3
|
-
* Sensitive fields (password, full URL) are never returned.
|
|
4
|
-
*/
|
|
5
|
-
export interface RedactedDatabaseUrl {
|
|
6
|
-
readonly host?: string;
|
|
7
|
-
readonly port?: string;
|
|
8
|
-
readonly database?: string;
|
|
9
|
-
readonly username?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Redacts a database connection URL to a minimal metadata object.
|
|
13
|
-
*
|
|
14
|
-
* Parsing errors are ignored and result in an empty object so callers never
|
|
15
|
-
* leak raw URLs when the input is malformed.
|
|
16
|
-
*/
|
|
17
|
-
export declare function redactDatabaseUrl(url: string): RedactedDatabaseUrl;
|
|
18
|
-
//# sourceMappingURL=redact-db-url.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"redact-db-url.d.ts","sourceRoot":"","sources":["../src/redact-db-url.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAclE"}
|
package/dist/result.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../src/result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,WAAW,EAAE,CAAC,CAAC;IACnB,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,QAAQ,IAAI,CAAC,CAAC;IACd,WAAW,IAAI,KAAK,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,QAAQ,IAAI,KAAK,CAAC;IAClB,WAAW,IAAI,CAAC,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AA6E5C;;GAEG;AACH,wBAAgB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAErC;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAE7C;AAQD;;;GAGG;AACH,wBAAgB,MAAM,IAAI,EAAE,CAAC,IAAI,CAAC,CAEjC"}
|