@prisma-next/utils 0.3.0-dev.9 → 0.3.0-dev.90
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/LICENSE +201 -0
- package/dist/abortable.d.mts +28 -0
- package/dist/abortable.d.mts.map +1 -0
- package/dist/abortable.mjs +39 -0
- package/dist/abortable.mjs.map +1 -0
- 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-BSROFTyI.mjs +30 -0
- package/dist/defined-BSROFTyI.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 +24 -24
- package/src/abortable.ts +40 -0
- package/src/assertions.ts +35 -0
- package/src/exports/abortable.ts +1 -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
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Prisma Data, Inc]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/abortable.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Allows aborting an async operation by returning a Promise which rejects if
|
|
4
|
+
* the provided AbortSignal aborts and otherwise resolves with the result of
|
|
5
|
+
* the async operation.
|
|
6
|
+
*
|
|
7
|
+
* Throws immediately if the signal is already aborted.
|
|
8
|
+
* When the signal is aborted later, any wrapped promise will reject with
|
|
9
|
+
* the signal's reason (or a default DOMException).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const { signal = new AbortController().signal } = options;
|
|
14
|
+
* const unlessAborted = abortable(signal);
|
|
15
|
+
*
|
|
16
|
+
* // Any of these will reject if signal is aborted
|
|
17
|
+
* await unlessAborted(asyncOperation());
|
|
18
|
+
* await unlessAborted(fetch(url));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param signal - The AbortSignal to race against
|
|
22
|
+
* @returns A function that wraps promises to be cancelable
|
|
23
|
+
* @throws If signal is already aborted
|
|
24
|
+
*/
|
|
25
|
+
declare function abortable(signal: AbortSignal): <T>(promise: Promise<T>) => Promise<T>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { abortable };
|
|
28
|
+
//# sourceMappingURL=abortable.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abortable.d.mts","names":[],"sources":["../src/abortable.ts"],"sourcesContent":[],"mappings":";;AAuBA;;;;;;;;;;;;;;;;;;;;;;iBAAgB,SAAA,SAAkB,2BAA2B,QAAQ,OAAO,QAAQ"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/abortable.ts
|
|
2
|
+
/**
|
|
3
|
+
* Allows aborting an async operation by returning a Promise which rejects if
|
|
4
|
+
* the provided AbortSignal aborts and otherwise resolves with the result of
|
|
5
|
+
* the async operation.
|
|
6
|
+
*
|
|
7
|
+
* Throws immediately if the signal is already aborted.
|
|
8
|
+
* When the signal is aborted later, any wrapped promise will reject with
|
|
9
|
+
* the signal's reason (or a default DOMException).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const { signal = new AbortController().signal } = options;
|
|
14
|
+
* const unlessAborted = abortable(signal);
|
|
15
|
+
*
|
|
16
|
+
* // Any of these will reject if signal is aborted
|
|
17
|
+
* await unlessAborted(asyncOperation());
|
|
18
|
+
* await unlessAborted(fetch(url));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param signal - The AbortSignal to race against
|
|
22
|
+
* @returns A function that wraps promises to be cancelable
|
|
23
|
+
* @throws If signal is already aborted
|
|
24
|
+
*/
|
|
25
|
+
function abortable(signal) {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
const abortPromise = new Promise((_resolve, reject) => {
|
|
28
|
+
signal.addEventListener("abort", () => {
|
|
29
|
+
reject(signal.reason ?? new DOMException("Operation cancelled"));
|
|
30
|
+
}, { once: true });
|
|
31
|
+
});
|
|
32
|
+
return (operation) => {
|
|
33
|
+
return Promise.race([operation, abortPromise]);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { abortable };
|
|
39
|
+
//# sourceMappingURL=abortable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abortable.mjs","names":[],"sources":["../src/abortable.ts"],"sourcesContent":["/**\n * Allows aborting an async operation by returning a Promise which rejects if\n * the provided AbortSignal aborts and otherwise resolves with the result of\n * the async operation.\n *\n * Throws immediately if the signal is already aborted.\n * When the signal is aborted later, any wrapped promise will reject with\n * the signal's reason (or a default DOMException).\n *\n * @example\n * ```typescript\n * const { signal = new AbortController().signal } = options;\n * const unlessAborted = abortable(signal);\n *\n * // Any of these will reject if signal is aborted\n * await unlessAborted(asyncOperation());\n * await unlessAborted(fetch(url));\n * ```\n *\n * @param signal - The AbortSignal to race against\n * @returns A function that wraps promises to be cancelable\n * @throws If signal is already aborted\n */\nexport function abortable(signal: AbortSignal): <T>(promise: Promise<T>) => Promise<T> {\n signal.throwIfAborted();\n\n const abortPromise = new Promise<never>((_resolve, reject) => {\n signal.addEventListener(\n 'abort',\n () => {\n reject(signal.reason ?? new DOMException('Operation cancelled'));\n },\n { once: true },\n );\n });\n\n return <T>(operation: Promise<T>): Promise<T> => {\n return Promise.race([operation, abortPromise]);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,UAAU,QAA6D;AACrF,QAAO,gBAAgB;CAEvB,MAAM,eAAe,IAAI,SAAgB,UAAU,WAAW;AAC5D,SAAO,iBACL,eACM;AACJ,UAAO,OAAO,UAAU,IAAI,aAAa,sBAAsB,CAAC;KAElE,EAAE,MAAM,MAAM,CACf;GACD;AAEF,SAAW,cAAsC;AAC/C,SAAO,QAAQ,KAAK,CAAC,WAAW,aAAa,CAAC"}
|
|
@@ -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-BSROFTyI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defined-BSROFTyI.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-BSROFTyI.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,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/utils",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.90",
|
|
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.
|
|
10
|
+
"vitest": "4.0.17",
|
|
11
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
12
|
+
"@prisma-next/tsdown": "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
|
-
"./
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"./
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"./redact-db-url": {
|
|
31
|
-
"types": "./dist/exports/redact-db-url.d.ts",
|
|
32
|
-
"import": "./dist/exports/redact-db-url.js"
|
|
33
|
-
}
|
|
22
|
+
"./abortable": "./dist/abortable.mjs",
|
|
23
|
+
"./array-equal": "./dist/array-equal.mjs",
|
|
24
|
+
"./assertions": "./dist/assertions.mjs",
|
|
25
|
+
"./defined": "./dist/defined.mjs",
|
|
26
|
+
"./redact-db-url": "./dist/redact-db-url.mjs",
|
|
27
|
+
"./result": "./dist/result.mjs",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
33
|
+
"directory": "packages/1-framework/1-core/shared/utils"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "
|
|
36
|
+
"build": "tsdown",
|
|
37
37
|
"test": "vitest run",
|
|
38
38
|
"test:coverage": "vitest run --coverage",
|
|
39
|
-
"typecheck": "tsc --
|
|
40
|
-
"lint": "biome check . --
|
|
41
|
-
"clean": "
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"lint": "biome check . --error-on-warnings",
|
|
41
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/abortable.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows aborting an async operation by returning a Promise which rejects if
|
|
3
|
+
* the provided AbortSignal aborts and otherwise resolves with the result of
|
|
4
|
+
* the async operation.
|
|
5
|
+
*
|
|
6
|
+
* Throws immediately if the signal is already aborted.
|
|
7
|
+
* When the signal is aborted later, any wrapped promise will reject with
|
|
8
|
+
* the signal's reason (or a default DOMException).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const { signal = new AbortController().signal } = options;
|
|
13
|
+
* const unlessAborted = abortable(signal);
|
|
14
|
+
*
|
|
15
|
+
* // Any of these will reject if signal is aborted
|
|
16
|
+
* await unlessAborted(asyncOperation());
|
|
17
|
+
* await unlessAborted(fetch(url));
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @param signal - The AbortSignal to race against
|
|
21
|
+
* @returns A function that wraps promises to be cancelable
|
|
22
|
+
* @throws If signal is already aborted
|
|
23
|
+
*/
|
|
24
|
+
export function abortable(signal: AbortSignal): <T>(promise: Promise<T>) => Promise<T> {
|
|
25
|
+
signal.throwIfAborted();
|
|
26
|
+
|
|
27
|
+
const abortPromise = new Promise<never>((_resolve, reject) => {
|
|
28
|
+
signal.addEventListener(
|
|
29
|
+
'abort',
|
|
30
|
+
() => {
|
|
31
|
+
reject(signal.reason ?? new DOMException('Operation cancelled'));
|
|
32
|
+
},
|
|
33
|
+
{ once: true },
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return <T>(operation: Promise<T>): Promise<T> => {
|
|
38
|
+
return Promise.race([operation, abortPromise]);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -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 { abortable } from '../abortable';
|
|
@@ -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"}
|