@shirudo/ddd-kit 0.9.8 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,204 @@
1
+ import { R as Result } from './result-jCwPSjFa.js';
2
+ export { E as Err, O as Ok, a as andThen, e as err, i as isErr, b as isOk, m as map, c as mapErr, d as match, f as matchAsync, g as matchResult, o as ok, p as pipe, t as tryCatch, h as tryCatchAsync, u as unwrapOr, j as unwrapOrElse } from './result-jCwPSjFa.js';
3
+
4
+ /**
5
+ * Base class for Result with method chaining support.
6
+ * Provides common methods for both Ok and Err classes.
7
+ */
8
+ declare abstract class ResultBase<T, E> {
9
+ protected readonly _result: Result<T, E>;
10
+ protected constructor(result: Result<T, E>);
11
+ /**
12
+ * Returns the value if Ok, otherwise throws an error.
13
+ * If error is an Error instance, throws it directly.
14
+ * Otherwise, wraps the error in a new Error.
15
+ *
16
+ * @throws Error if the result is Err
17
+ */
18
+ unwrap(): T;
19
+ /**
20
+ * Returns the value if Ok, otherwise returns the default value.
21
+ */
22
+ unwrapOr(defaultValue: T): T;
23
+ /**
24
+ * Returns the value if Ok, otherwise computes default from error.
25
+ */
26
+ unwrapOrElse(fn: (error: E) => T): T;
27
+ /**
28
+ * Pattern matching for Result.
29
+ * Applies one function if Ok, another if Err.
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * outcome.match(
34
+ * value => `Success: ${value}`,
35
+ * error => `Error: ${error}`
36
+ * );
37
+ * ```
38
+ *
39
+ * @example Using object syntax
40
+ * ```typescript
41
+ * outcome.match({
42
+ * ok: value => `Success: ${value}`,
43
+ * err: error => `Error: ${error}`
44
+ * });
45
+ * ```
46
+ */
47
+ match<R>(onOk: (value: T) => R, onErr: (error: E) => R): R;
48
+ match<R>(handlers: {
49
+ ok: (value: T) => R;
50
+ err: (error: E) => R;
51
+ }): R;
52
+ /**
53
+ * Async pattern matching for Result.
54
+ * Applies one async function if Ok, another if Err.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * await outcome.matchAsync(
59
+ * async (value) => `Success: ${value}`,
60
+ * async (error) => `Error: ${error}`
61
+ * );
62
+ * ```
63
+ *
64
+ * @example Using object syntax
65
+ * ```typescript
66
+ * await outcome.matchAsync({
67
+ * ok: async (value) => `Success: ${value}`,
68
+ * err: async (error) => `Error: ${error}`
69
+ * });
70
+ * ```
71
+ */
72
+ matchAsync<R>(onOk: (value: T) => Promise<R>, onErr: (error: E) => Promise<R>): Promise<R>;
73
+ matchAsync<R>(handlers: {
74
+ ok: (value: T) => Promise<R>;
75
+ err: (error: E) => Promise<R>;
76
+ }): Promise<R>;
77
+ /**
78
+ * Type guard to check if the result is Ok.
79
+ */
80
+ isOk(): this is Success<T>;
81
+ /**
82
+ * Type guard to check if the result is Err.
83
+ */
84
+ isErr(): this is Erroneous<E>;
85
+ /**
86
+ * Gets the underlying Result value.
87
+ */
88
+ get result(): Result<T, E>;
89
+ }
90
+ /**
91
+ * Class representing a successful result with method chaining support.
92
+ * Use this for class-based API with method chaining.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const okResult = Ok(1);
97
+ * const doubled = okResult.map(x => x * 2).unwrap(); // 2
98
+ *
99
+ * const chained = Ok(5)
100
+ * .andThen(x => Ok(x * 2))
101
+ * .map(x => x + 1)
102
+ * .unwrap(); // 11
103
+ * ```
104
+ */
105
+ declare class Success<T> extends ResultBase<T, never> {
106
+ constructor(value: T);
107
+ /**
108
+ * Factory function to create an Ok instance.
109
+ * Can be called with or without `new`.
110
+ */
111
+ static of<T>(value: T): Success<T>;
112
+ /**
113
+ * Chains Result operations (flatMap/bind).
114
+ * If the result is Ok, applies the function to the value.
115
+ * If Err, returns the error unchanged.
116
+ */
117
+ andThen<U, E>(fn: (value: T) => Result<U, E>): Success<U> | Erroneous<E>;
118
+ /**
119
+ * Transforms the Ok value using a function.
120
+ * If the result is Err, returns the error unchanged.
121
+ */
122
+ map<U>(fn: (value: T) => U): Success<U>;
123
+ /**
124
+ * Transforms the Err value using a function.
125
+ * If the result is Ok, returns the value unchanged.
126
+ */
127
+ mapErr<F>(_fn: (error: never) => F): Success<T>;
128
+ }
129
+
130
+ /**
131
+ * Class representing an erroneous result with method chaining support.
132
+ * Use this for class-based API with method chaining.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const errResult = Err(new Error("error"));
137
+ * errResult.map(x => x * 2).unwrap(); // throws Error("error")
138
+ *
139
+ * const mapped = Err("original")
140
+ * .mapErr(e => `Error: ${e}`)
141
+ * .unwrap(); // throws Error("Error: original")
142
+ * ```
143
+ */
144
+ declare class Erroneous<E> extends ResultBase<never, E> {
145
+ constructor(error: E);
146
+ /**
147
+ * Factory function to create an Err instance.
148
+ * Can be called with or without `new`.
149
+ */
150
+ static of<E>(error: E): Erroneous<E>;
151
+ /**
152
+ * Chains Result operations (flatMap/bind).
153
+ * If the result is Ok, applies the function to the value.
154
+ * If Err, returns the error unchanged.
155
+ */
156
+ andThen<U>(_fn: (value: never) => Result<U, E>): Erroneous<E>;
157
+ /**
158
+ * Transforms the Ok value using a function.
159
+ * If the result is Err, returns the error unchanged.
160
+ */
161
+ map<U>(_fn: (value: never) => U): Erroneous<E>;
162
+ /**
163
+ * Transforms the Err value using a function.
164
+ * If the result is Ok, returns the value unchanged.
165
+ */
166
+ mapErr<F>(fn: (error: E) => F): Erroneous<F>;
167
+ }
168
+
169
+ /**
170
+ * Class-based API for Result with method chaining support.
171
+ * Provides an object-oriented alternative to the functional Result type.
172
+ * Use `Outcome.from()` to wrap an existing Result, or `Outcome.ok()` / `Outcome.err()` to create new instances.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * // Wrap an existing Result
177
+ * const result = Outcome.from(ok(1));
178
+ * const doubled = result.map(x => x * 2).unwrap(); // 2
179
+ *
180
+ * // Create directly
181
+ * const outcome = Outcome.ok(42);
182
+ * const value = outcome.map(x => x + 1).unwrap(); // 43
183
+ * ```
184
+ */
185
+ declare class Outcome<T, E> extends ResultBase<T, E> {
186
+ private constructor();
187
+ /**
188
+ * Creates an Outcome from an Ok value.
189
+ */
190
+ static ok<T>(value: T): Success<T>;
191
+ /**
192
+ * Creates an Outcome from an Err value.
193
+ */
194
+ static err<E>(error: E): Erroneous<E>;
195
+ /**
196
+ * Creates an Outcome from a Result.
197
+ */
198
+ static from<T, E>(result: Result<T, E>): Outcome<T, E>;
199
+ andThen<U>(fn: (value: T) => Result<U, E>): Outcome<U, E>;
200
+ map<U>(fn: (value: T) => U): Outcome<U, E>;
201
+ mapErr<F>(fn: (error: E) => F): Outcome<T, F>;
202
+ }
203
+
204
+ export { Erroneous, Outcome, Result, Success };
package/dist/result.js ADDED
@@ -0,0 +1,2 @@
1
+ var x=Object.defineProperty;var o=(e,r)=>x(e,"name",{value:r,configurable:true});function n(e){return {ok:true,value:e}}o(n,"ok");function u(e){return {ok:false,error:e}}o(u,"err");function p(e){return e.ok===true}o(p,"isOk");function f(e){return e.ok===false}o(f,"isErr");function i(e,r){return e.ok?r(e.value):e}o(i,"andThen");function c(e,r){return e.ok?n(r(e.value)):e}o(c,"map");function T(e,r){return e.ok?e:u(r(e.error))}o(T,"mapErr");function m(e,r){return e.ok?e.value:r}o(m,"unwrapOr");function h(e,r){return e.ok?e.value:r(e.error)}o(h,"unwrapOrElse");function a(e,r,t){return typeof r=="function"?e.ok?r(e.value):t(e.error):e.ok?r.ok(e.value):r.err(e.error)}o(a,"match");async function l(e,r,t){return typeof r=="function"?e.ok?r(e.value):t(e.error):e.ok?r.ok(e.value):r.err(e.error)}o(l,"matchAsync");function U(e,r,t){return typeof r=="function"?e.ok?r(e.value):t(e.error):e.ok?r.ok(e.value):r.err(e.error)}o(U,"matchResult");function y(e,...r){let t=e;for(let k of r)if(t=k(t),!t.ok)return t;return t}o(y,"pipe");function w(e,r){try{return n(e())}catch(t){return u(r?r(t):t instanceof Error?t:new Error(String(t)))}}o(w,"tryCatch");async function F(e,r){try{let t=await e();return n(t)}catch(t){return u(r?r(t):t instanceof Error?t:new Error(String(t)))}}o(F,"tryCatchAsync");var s=class{static{o(this,"ResultBase");}_result;constructor(r){this._result=r;}unwrap(){if(this._result.ok)return this._result.value;throw this._result.error instanceof Error?this._result.error:new Error(String(this._result.error))}unwrapOr(r){return m(this._result,r)}unwrapOrElse(r){return h(this._result,r)}match(r,t){return typeof r=="function"?a(this._result,r,t):a(this._result,r)}async matchAsync(r,t){return typeof r=="function"?l(this._result,r,t):l(this._result,r)}isOk(){return p(this._result)}isErr(){return f(this._result)}get result(){return this._result}},R=class e extends s{static{o(this,"Success");}constructor(r){super(n(r));}static of(r){return new e(r)}andThen(r){let t=i(this._result,r);return t.ok?new e(t.value):new E(t.error)}map(r){let t=c(this._result,r);if(t.ok)return new e(t.value);throw new Error("Unexpected error in Success.map")}mapErr(r){return this}};var E=class e extends s{static{o(this,"Erroneous");}constructor(r){super(u(r));}static of(r){return new e(r)}andThen(r){return this}map(r){return this}mapErr(r){let t=T(this._result,r);if(!t.ok)return new e(t.error);throw new Error("Unexpected ok in Erroneous.mapErr")}};var v=class e extends s{static{o(this,"Outcome");}constructor(r){super(r);}static ok(r){return new R(r)}static err(r){return new E(r)}static from(r){return new e(r)}andThen(r){return e.from(i(this._result,r))}map(r){return e.from(c(this._result,r))}mapErr(r){return e.from(T(this._result,r))}};export{E as Erroneous,v as Outcome,R as Success,i as andThen,u as err,f as isErr,p as isOk,c as map,T as mapErr,a as match,l as matchAsync,U as matchResult,n as ok,y as pipe,w as tryCatch,F as tryCatchAsync,m as unwrapOr,h as unwrapOrElse};//# sourceMappingURL=result.js.map
2
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/result/result.ts","../src/core/result/outcome.ts"],"names":["ok","value","__name","err","error","isOk","result","isErr","andThen","fn","map","mapErr","unwrapOr","defaultValue","unwrapOrElse","match","onOkOrHandlers","onErr","matchAsync","matchResult","pipe","initial","fns","current","tryCatch","errorMapper","tryCatchAsync","ResultBase","Success","_Success","Erroneous","_fn","_Errone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AAAA,CAAO,EAAA,CACX,OAAO,IAAI0B,CAAAA,CAAU1B,EAAO,KAAK,CAAA,CAGlC,MAAM,IAAI,KAAA,CAAM,mCAAmC,CACpD,CACD,EAsCO,IAAM2B,EAAN,MAAMC,CAAAA,SAAsBP,CAAiB,CA1TpD,OA0ToDzB,CAAAA,CAAA,iBAC3C,WAAA,CAAYI,CAAAA,CAAsB,CACzC,KAAA,CAAMA,CAAM,EACb,CAKA,OAAO,EAAA,CAAML,CAAAA,CAAsB,CAClC,OAAO,IAAI2B,EAAQ3B,CAAK,CACzB,CAKA,OAAO,GAAA,CAAOG,EAAwB,CACrC,OAAO,IAAI0B,CAAAA,CAAU1B,CAAK,CAC3B,CAKA,OAAO,KAAWE,CAAAA,CAAqC,CACtD,OAAO,IAAI4B,EAAQ5B,CAAM,CAC1B,CAEA,OAAA,CAAWG,CAAAA,CAA+C,CACzD,OAAOyB,CAAAA,CAAQ,KAAK1B,CAAAA,CAAQ,IAAA,CAAK,QAASC,CAAE,CAAC,CAC9C,CAEA,GAAA,CAAOA,EAAoC,CAC1C,OAAOyB,CAAAA,CAAQ,IAAA,CAAKxB,EAAI,IAAA,CAAK,OAAA,CAASD,CAAE,CAAC,CAC1C,CAEA,MAAA,CAAUA,CAAAA,CAAoC,CAC7C,OAAOyB,CAAAA,CAAQ,KAAKvB,CAAAA,CAAO,IAAA,CAAK,QAASF,CAAE,CAAC,CAC7C,CACD","file":"result.js","sourcesContent":["export type Ok<T> = { ok: true; value: T };\nexport type Err<E> = { ok: false; error: E };\nexport type Result<T, E> = Ok<T> | Err<E>;\n\n/**\n * Creates an Ok result with a value.\n *\n * @param value - The success value\n * @returns An Ok result containing the value\n *\n * @example\n * ```typescript\n * const result = ok(42);\n * // result is Ok<number>\n * ```\n */\nexport function ok<T>(value: T): Ok<T>;\n\n/**\n * Creates an Ok result with void (no value).\n *\n * @returns An Ok<void> result\n *\n * @example\n * ```typescript\n * const result = ok();\n * // result is Ok<void>\n * ```\n */\nexport function ok(): Ok<void>;\n\nexport function ok<T>(value?: T): Ok<T> {\n\treturn { ok: true, value: value as T };\n}\n\n/**\n * Creates an Err result with an error.\n *\n * @param error - The error value\n * @returns An Err result containing the error\n *\n * @example\n * ```typescript\n * const result = err(\"Something went wrong\");\n * // result is Err<string>\n * ```\n */\nexport function err<E>(error: E): Err<E>;\n\n/**\n * Creates an Err result with void (no error value).\n *\n * @returns An Err<void> result\n *\n * @example\n * ```typescript\n * const result = err();\n * // result is Err<void>\n * ```\n */\nexport function err(): Err<void>;\n\nexport function err<E>(error?: E): Err<E> {\n\treturn { ok: false, error: error as E };\n}\n\n/**\n * Type guard to check if a Result is Ok.\n * Narrows the type to Ok<T> when returning true.\n *\n * @param result - The result to check\n * @returns true if the result is Ok, false otherwise\n *\n * @example\n * ```typescript\n * const result = voWithValidation(data, validator);\n * if (isOk(result)) {\n * // TypeScript knows result is Ok<VO<T>>\n * console.log(result.value);\n * }\n * ```\n */\nexport function isOk<T, E>(result: Result<T, E>): result is Ok<T> {\n\treturn result.ok === true;\n}\n\n/**\n * Type guard to check if a Result is Err.\n * Narrows the type to Err<E> when returning true.\n *\n * @param result - The result to check\n * @returns true if the result is Err, false otherwise\n *\n * @example\n * ```typescript\n * const result = voWithValidation(data, validator);\n * if (isErr(result)) {\n * // TypeScript knows result is Err<string>\n * console.error(result.error);\n * }\n * ```\n */\nexport function isErr<T, E>(result: Result<T, E>): result is Err<E> {\n\treturn result.ok === false;\n}\n\n/**\n * Chains Result operations (flatMap/bind).\n * If the result is Ok, applies the function to the value.\n * If Err, returns the error unchanged.\n *\n * @param result - The result to chain\n * @param fn - Function that takes the Ok value and returns a new Result\n * @returns A new Result\n *\n * @example\n * ```typescript\n * const result = validateUserId(\"123\")\n * .andThen(userId => validateEmail(\"test@example.com\")\n * .map(email => ({ id: userId, email }))\n * );\n * ```\n */\nexport function andThen<T, E, U>(\n\tresult: Result<T, E>,\n\tfn: (value: T) => Result<U, E>,\n): Result<U, E> {\n\tif (result.ok) {\n\t\treturn fn(result.value);\n\t}\n\treturn result;\n}\n\n/**\n * Transforms the Ok value using a function.\n * If the result is Err, returns the error unchanged.\n *\n * @param result - The result to transform\n * @param fn - Function to transform the Ok value\n * @returns A new Result with transformed value\n *\n * @example\n * ```typescript\n * const result = ok(5);\n * const doubled = map(result, x => x * 2); // Ok<10>\n * ```\n */\nexport function map<T, E, U>(\n\tresult: Result<T, E>,\n\tfn: (value: T) => U,\n): Result<U, E> {\n\tif (result.ok) {\n\t\treturn ok(fn(result.value));\n\t}\n\treturn result;\n}\n\n/**\n * Transforms the Err value using a function.\n * If the result is Ok, returns the value unchanged.\n *\n * @param result - The result to transform\n * @param fn - Function to transform the Err value\n * @returns A new Result with transformed error\n *\n * @example\n * ```typescript\n * const result = err(\"not found\");\n * const mapped = mapErr(result, e => `Error: ${e}`); // Err<\"Error: not found\">\n * ```\n */\nexport function mapErr<T, E, F>(\n\tresult: Result<T, E>,\n\tfn: (error: E) => F,\n): Result<T, F> {\n\tif (result.ok) {\n\t\treturn result;\n\t}\n\treturn err(fn(result.error));\n}\n\n/**\n * Returns the value if Ok, otherwise returns the default value.\n *\n * @param result - The result to unwrap\n * @param defaultValue - Default value to return if Err\n * @returns The Ok value or the default value\n *\n * @example\n * ```typescript\n * const result = validateUserId(\"123\");\n * const userId = unwrapOr(result, \"default-id\");\n * ```\n */\nexport function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T {\n\treturn result.ok ? result.value : defaultValue;\n}\n\n/**\n * Returns the value if Ok, otherwise computes default from error.\n *\n * @param result - The result to unwrap\n * @param fn - Function to compute default from error\n * @returns The Ok value or computed default\n *\n * @example\n * ```typescript\n * const result = validateUserId(\"\");\n * const userId = unwrapOrElse(result, err => `fallback-${Date.now()}`);\n * ```\n */\nexport function unwrapOrElse<T, E>(\n\tresult: Result<T, E>,\n\tfn: (error: E) => T,\n): T {\n\treturn result.ok ? result.value : fn(result.error);\n}\n\n/**\n * Pattern matching for Result.\n * Applies one function if Ok, another if Err.\n *\n * @param result - The result to match\n * @param onOk - Function to apply if Ok\n * @param onErr - Function to apply if Err\n * @returns The result of applying the appropriate function\n *\n * @example\n * ```typescript\n * const message = match(result,\n * value => `Success: ${value}`,\n * error => `Error: ${error}`\n * );\n * ```\n *\n * @example Using object syntax\n * ```typescript\n * const message = match(result, {\n * ok: value => `Success: ${value}`,\n * err: error => `Error: ${error}`\n * });\n * ```\n */\nexport function match<T, E, R>(\n\tresult: Result<T, E>,\n\tonOk: (value: T) => R,\n\tonErr: (error: E) => R,\n): R;\nexport function match<T, E, R>(\n\tresult: Result<T, E>,\n\thandlers: { ok: (value: T) => R; err: (error: E) => R },\n): R;\nexport function match<T, E, R>(\n\tresult: Result<T, E>,\n\tonOkOrHandlers: ((value: T) => R) | { ok: (value: T) => R; err: (error: E) => R },\n\tonErr?: (error: E) => R,\n): R {\n\tif (typeof onOkOrHandlers === \"function\") {\n\t\t// Function syntax: match(result, onOk, onErr)\n\t\treturn result.ok ? onOkOrHandlers(result.value) : onErr!(result.error);\n\t}\n\t// Object syntax: match(result, { ok: ..., err: ... })\n\treturn result.ok\n\t\t? onOkOrHandlers.ok(result.value)\n\t\t: onOkOrHandlers.err(result.error);\n}\n\n/**\n * Async pattern matching for Result.\n * Applies one async function if Ok, another if Err.\n * Both handlers must return Promises.\n *\n * @param result - The result to match\n * @param onOk - Async function to apply if Ok\n * @param onErr - Async function to apply if Err\n * @returns Promise resolving to the result of applying the appropriate function\n *\n * @example\n * ```typescript\n * const message = await matchAsync(result,\n * async (value) => `Success: ${value}`,\n * async (error) => `Error: ${error}`\n * );\n * ```\n *\n * @example Using object syntax\n * ```typescript\n * const message = await matchAsync(result, {\n * ok: async (value) => `Success: ${value}`,\n * err: async (error) => `Error: ${error}`\n * });\n * ```\n */\nexport async function matchAsync<T, E, R>(\n\tresult: Result<T, E>,\n\tonOk: (value: T) => Promise<R>,\n\tonErr: (error: E) => Promise<R>,\n): Promise<R>;\nexport async function matchAsync<T, E, R>(\n\tresult: Result<T, E>,\n\thandlers: { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n): Promise<R>;\nexport async function matchAsync<T, E, R>(\n\tresult: Result<T, E>,\n\tonOkOrHandlers:\n\t\t| ((value: T) => Promise<R>)\n\t\t| { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n\tonErr?: (error: E) => Promise<R>,\n): Promise<R> {\n\tif (typeof onOkOrHandlers === \"function\") {\n\t\t// Function syntax: matchAsync(result, onOk, onErr)\n\t\treturn result.ok\n\t\t\t? onOkOrHandlers(result.value)\n\t\t\t: onErr!(result.error);\n\t}\n\t// Object syntax: matchAsync(result, { ok: ..., err: ... })\n\treturn result.ok\n\t\t? onOkOrHandlers.ok(result.value)\n\t\t: onOkOrHandlers.err(result.error);\n}\n\n/**\n * Pattern matching for Result that returns a Result.\n * Both handlers must return a Result, allowing you to transform\n * both the success and error cases while staying in Result context.\n *\n * @param result - The result to match\n * @param handlers - Object with ok and err handlers, both returning Result\n * @returns A new Result from the appropriate handler\n *\n * @example\n * ```typescript\n * const result = await fetchUser(id);\n * return matchResult(result, {\n * ok: (user) => ok(transformUser(user)),\n * err: (error) => err(mapToAppError(error))\n * });\n * ```\n */\nexport function matchResult<T, E, U, F>(\n\tresult: Result<T, E>,\n\thandlers: {\n\t\tok: (value: T) => Result<U, F>;\n\t\terr: (error: E) => Result<U, F>;\n\t},\n): Result<U, F>;\nexport function matchResult<T, E, U, F>(\n\tresult: Result<T, E>,\n\tonOk: (value: T) => Result<U, F>,\n\tonErr: (error: E) => Result<U, F>,\n): Result<U, F>;\nexport function matchResult<T, E, U, F>(\n\tresult: Result<T, E>,\n\tonOkOrHandlers:\n\t\t| ((value: T) => Result<U, F>)\n\t\t| { ok: (value: T) => Result<U, F>; err: (error: E) => Result<U, F> },\n\tonErr?: (error: E) => Result<U, F>,\n): Result<U, F> {\n\tif (typeof onOkOrHandlers === \"function\") {\n\t\treturn result.ok ? onOkOrHandlers(result.value) : onErr!(result.error);\n\t}\n\treturn result.ok\n\t\t? onOkOrHandlers.ok(result.value)\n\t\t: onOkOrHandlers.err(result.error);\n}\n\n/**\n * Pipes a Result through multiple operations.\n * Each function receives the previous Result and returns a new Result.\n * Stops on first error.\n *\n * @param initial - The initial Result value\n * @param fns - Array of functions that take the previous Result and return a new Result\n * @returns The final Result after all operations\n *\n * @example\n * ```typescript\n * // Instead of nested andThen calls:\n * andThen(\n * updateCountryCode(code),\n * () => andThen(updateCurrencyCode(currency), () => updateLanguageCode(lang))\n * )\n *\n * // Use pipe (cleaner and more readable):\n * pipe(\n * updateCountryCode(code),\n * () => updateCurrencyCode(currency),\n * () => updateLanguageCode(lang)\n * )\n * ```\n *\n * @example With void results\n * ```typescript\n * setInitialData(initialData: JobConfigProps[\"initialData\"]): Result<void, JobDomainError> {\n * return pipe(\n * this.updateCountryCode(initialData.countryCode),\n * () => this.updateCurrencyCode(initialData.currencyCode),\n * () => this.updateLanguageCode(initialData.languageCode)\n * );\n * }\n * ```\n */\nexport function pipe<T, E>(\n\tinitial: Result<T, E>,\n\t...fns: Array<(prev: Result<T, E>) => Result<T, E>>\n): Result<T, E> {\n\tlet current = initial;\n\tfor (const fn of fns) {\n\t\tcurrent = fn(current);\n\t\tif (!current.ok) {\n\t\t\treturn current;\n\t\t}\n\t}\n\treturn current;\n}\n\n/**\n * Wraps a function that may throw exceptions into a Result type.\n * Catches any thrown exceptions and converts them to Err results.\n *\n * @param fn - Function that may throw exceptions\n * @param errorMapper - Optional function to transform the caught error\n * @returns A Result containing the function's return value or error\n *\n * @example\n * ```typescript\n * function riskyOperation(): string {\n * if (Math.random() > 0.5) {\n * throw new Error(\"Something went wrong\");\n * }\n * return \"success\";\n * }\n *\n * const result = tryCatch(() => riskyOperation());\n * if (result.ok) {\n * console.log(result.value); // \"success\"\n * } else {\n * console.error(result.error.message); // \"Something went wrong\"\n * }\n * ```\n *\n * @example With custom error mapper\n * ```typescript\n * const result = tryCatch(\n * () => riskyOperation(),\n * (error) => `Custom: ${error instanceof Error ? error.message : String(error)}`\n * );\n * ```\n */\nexport function tryCatch<T, E = Error>(\n\tfn: () => T,\n\terrorMapper?: (error: unknown) => E,\n): Result<T, E> {\n\ttry {\n\t\treturn ok(fn());\n\t} catch (error) {\n\t\tif (errorMapper) {\n\t\t\treturn err(errorMapper(error));\n\t\t}\n\t\treturn err((error instanceof Error ? error : new Error(String(error))) as E);\n\t}\n}\n\n/**\n * Wraps an async function that may throw exceptions into a Promise<Result>.\n * Catches any thrown exceptions and converts them to Err results.\n *\n * @param fn - Async function that may throw exceptions\n * @param errorMapper - Optional function to transform the caught error\n * @returns A Promise resolving to a Result containing the function's return value or error\n *\n * @example\n * ```typescript\n * async function riskyAsyncOperation(): Promise<string> {\n * if (Math.random() > 0.5) {\n * throw new Error(\"Something went wrong\");\n * }\n * return \"success\";\n * }\n *\n * const result = await tryCatchAsync(() => riskyAsyncOperation());\n * if (result.ok) {\n * console.log(result.value); // \"success\"\n * } else {\n * console.error(result.error.message); // \"Something went wrong\"\n * }\n * ```\n */\nexport async function tryCatchAsync<T, E = Error>(\n\tfn: () => Promise<T>,\n\terrorMapper?: (error: unknown) => E,\n): Promise<Result<T, E>> {\n\ttry {\n\t\tconst value = await fn();\n\t\treturn ok(value);\n\t} catch (error) {\n\t\tif (errorMapper) {\n\t\t\treturn err(errorMapper(error));\n\t\t}\n\t\treturn err((error instanceof Error ? error : new Error(String(error))) as E);\n\t}\n}\n\n","import {\n andThen,\n err,\n isErr,\n isOk,\n map,\n mapErr,\n match,\n matchAsync,\n ok,\n type Result,\n unwrapOr,\n unwrapOrElse,\n} from \"./result\";\n\n/**\n * Base class for Result with method chaining support.\n * Provides common methods for both Ok and Err classes.\n */\nabstract class ResultBase<T, E> {\n\tprotected readonly _result: Result<T, E>;\n\n\tprotected constructor(result: Result<T, E>) {\n\t\tthis._result = result;\n\t}\n\n\t/**\n\t * Returns the value if Ok, otherwise throws an error.\n\t * If error is an Error instance, throws it directly.\n\t * Otherwise, wraps the error in a new Error.\n\t *\n\t * @throws Error if the result is Err\n\t */\n\tunwrap(): T {\n\t\tif (this._result.ok) {\n\t\t\treturn this._result.value;\n\t\t}\n\t\tif (this._result.error instanceof Error) {\n\t\t\tthrow this._result.error;\n\t\t}\n\t\tthrow new Error(String(this._result.error));\n\t}\n\n\t/**\n\t * Returns the value if Ok, otherwise returns the default value.\n\t */\n\tunwrapOr(defaultValue: T): T {\n\t\treturn unwrapOr(this._result, defaultValue);\n\t}\n\n\t/**\n\t * Returns the value if Ok, otherwise computes default from error.\n\t */\n\tunwrapOrElse(fn: (error: E) => T): T {\n\t\treturn unwrapOrElse(this._result, fn);\n\t}\n\n\t/**\n\t * Pattern matching for Result.\n\t * Applies one function if Ok, another if Err.\n\t *\n\t * @example\n\t * ```typescript\n\t * outcome.match(\n\t * value => `Success: ${value}`,\n\t * error => `Error: ${error}`\n\t * );\n\t * ```\n\t *\n\t * @example Using object syntax\n\t * ```typescript\n\t * outcome.match({\n\t * ok: value => `Success: ${value}`,\n\t * err: error => `Error: ${error}`\n\t * });\n\t * ```\n\t */\n\tmatch<R>(\n\t\tonOk: (value: T) => R,\n\t\tonErr: (error: E) => R,\n\t): R;\n\tmatch<R>(\n\t\thandlers: { ok: (value: T) => R; err: (error: E) => R },\n\t): R;\n\tmatch<R>(\n\t\tonOkOrHandlers: ((value: T) => R) | { ok: (value: T) => R; err: (error: E) => R },\n\t\tonErr?: (error: E) => R,\n\t): R {\n\t\tif (typeof onOkOrHandlers === \"function\") {\n\t\t\treturn match(this._result, onOkOrHandlers, onErr!);\n\t\t}\n\t\treturn match(this._result, onOkOrHandlers);\n\t}\n\n\t/**\n\t * Async pattern matching for Result.\n\t * Applies one async function if Ok, another if Err.\n\t *\n\t * @example\n\t * ```typescript\n\t * await outcome.matchAsync(\n\t * async (value) => `Success: ${value}`,\n\t * async (error) => `Error: ${error}`\n\t * );\n\t * ```\n\t *\n\t * @example Using object syntax\n\t * ```typescript\n\t * await outcome.matchAsync({\n\t * ok: async (value) => `Success: ${value}`,\n\t * err: async (error) => `Error: ${error}`\n\t * });\n\t * ```\n\t */\n\tmatchAsync<R>(\n\t\tonOk: (value: T) => Promise<R>,\n\t\tonErr: (error: E) => Promise<R>,\n\t): Promise<R>;\n\tmatchAsync<R>(\n\t\thandlers: { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n\t): Promise<R>;\n\tasync matchAsync<R>(\n\t\tonOkOrHandlers:\n\t\t\t| ((value: T) => Promise<R>)\n\t\t\t| { ok: (value: T) => Promise<R>; err: (error: E) => Promise<R> },\n\t\tonErr?: (error: E) => Promise<R>,\n\t): Promise<R> {\n\t\tif (typeof onOkOrHandlers === \"function\") {\n\t\t\treturn matchAsync(this._result, onOkOrHandlers, onErr!);\n\t\t}\n\t\treturn matchAsync(this._result, onOkOrHandlers);\n\t}\n\n\t/**\n\t * Type guard to check if the result is Ok.\n\t */\n\tisOk(): this is Success<T> {\n\t\treturn isOk(this._result);\n\t}\n\n\t/**\n\t * Type guard to check if the result is Err.\n\t */\n\tisErr(): this is Erroneous<E> {\n\t\treturn isErr(this._result);\n\t}\n\n\t/**\n\t * Gets the underlying Result value.\n\t */\n\tget result(): Result<T, E> {\n\t\treturn this._result;\n\t}\n}\n\n/**\n * Class representing a successful result with method chaining support.\n * Use this for class-based API with method chaining.\n *\n * @example\n * ```typescript\n * const okResult = Ok(1);\n * const doubled = okResult.map(x => x * 2).unwrap(); // 2\n *\n * const chained = Ok(5)\n * .andThen(x => Ok(x * 2))\n * .map(x => x + 1)\n * .unwrap(); // 11\n * ```\n */\nclass Success<T> extends ResultBase<T, never> {\n\tconstructor(value: T) {\n\t\tsuper(ok(value));\n\t}\n\n\t/**\n\t * Factory function to create an Ok instance.\n\t * Can be called with or without `new`.\n\t */\n\tstatic of<T>(value: T): Success<T> {\n\t\treturn new Success(value);\n\t}\n\n\t/**\n\t * Chains Result operations (flatMap/bind).\n\t * If the result is Ok, applies the function to the value.\n\t * If Err, returns the error unchanged.\n\t */\n\tandThen<U, E>(fn: (value: T) => Result<U, E>): Success<U> | Erroneous<E> {\n\t\tconst result = andThen(this._result, fn);\n\t\tif (result.ok) {\n\t\t\treturn new Success(result.value);\n\t\t}\n\t\treturn new Erroneous(result.error);\n\t}\n\n\t/**\n\t * Transforms the Ok value using a function.\n\t * If the result is Err, returns the error unchanged.\n\t */\n\tmap<U>(fn: (value: T) => U): Success<U> {\n\t\tconst result = map(this._result, fn);\n\t\tif (result.ok) {\n\t\t\treturn new Success(result.value);\n\t\t}\n\t\t// This should never happen for Success, but TypeScript needs it\n\t\tthrow new Error(\"Unexpected error in Success.map\");\n\t}\n\n\t/**\n\t * Transforms the Err value using a function.\n\t * If the result is Ok, returns the value unchanged.\n\t */\n\tmapErr<F>(_fn: (error: never) => F): Success<T> {\n\t\treturn this;\n\t}\n}\n\nexport { Success };\n\n/**\n * Class representing an erroneous result with method chaining support.\n * Use this for class-based API with method chaining.\n *\n * @example\n * ```typescript\n * const errResult = Err(new Error(\"error\"));\n * errResult.map(x => x * 2).unwrap(); // throws Error(\"error\")\n *\n * const mapped = Err(\"original\")\n * .mapErr(e => `Error: ${e}`)\n * .unwrap(); // throws Error(\"Error: original\")\n * ```\n */\nclass Erroneous<E> extends ResultBase<never, E> {\n\tconstructor(error: E) {\n\t\tsuper(err(error));\n\t}\n\n\t/**\n\t * Factory function to create an Err instance.\n\t * Can be called with or without `new`.\n\t */\n\tstatic of<E>(error: E): Erroneous<E> {\n\t\treturn new Erroneous(error);\n\t}\n\n\t/**\n\t * Chains Result operations (flatMap/bind).\n\t * If the result is Ok, applies the function to the value.\n\t * If Err, returns the error unchanged.\n\t */\n\tandThen<U>(_fn: (value: never) => Result<U, E>): Erroneous<E> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Transforms the Ok value using a function.\n\t * If the result is Err, returns the error unchanged.\n\t */\n\tmap<U>(_fn: (value: never) => U): Erroneous<E> {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Transforms the Err value using a function.\n\t * If the result is Ok, returns the value unchanged.\n\t */\n\tmapErr<F>(fn: (error: E) => F): Erroneous<F> {\n\t\tconst result = mapErr(this._result, fn);\n\t\tif (!result.ok) {\n\t\t\treturn new Erroneous(result.error);\n\t\t}\n\t\t// This should never happen for Erroneous, but TypeScript needs it\n\t\tthrow new Error(\"Unexpected ok in Erroneous.mapErr\");\n\t}\n}\n\nexport { Erroneous };\n\n/**\n * Factory functions for creating Ok and Err instances.\n * These can be called without `new` for a more functional style.\n *\n * @example\n * ```typescript\n * const okResult = Ok(1);\n * const errResult = Err(\"error\");\n * ```\n */\nexport function Ok<T>(value: T): Success<T> {\n\treturn new Success(value);\n}\n\nexport function Err<E>(error: E): Erroneous<E> {\n\treturn new Erroneous(error);\n}\n\n/**\n * Class-based API for Result with method chaining support.\n * Provides an object-oriented alternative to the functional Result type.\n * Use `Outcome.from()` to wrap an existing Result, or `Outcome.ok()` / `Outcome.err()` to create new instances.\n *\n * @example\n * ```typescript\n * // Wrap an existing Result\n * const result = Outcome.from(ok(1));\n * const doubled = result.map(x => x * 2).unwrap(); // 2\n *\n * // Create directly\n * const outcome = Outcome.ok(42);\n * const value = outcome.map(x => x + 1).unwrap(); // 43\n * ```\n */\nexport class Outcome<T, E> extends ResultBase<T, E> {\n\tprivate constructor(result: Result<T, E>) {\n\t\tsuper(result);\n\t}\n\n\t/**\n\t * Creates an Outcome from an Ok value.\n\t */\n\tstatic ok<T>(value: T): Success<T> {\n\t\treturn new Success(value);\n\t}\n\n\t/**\n\t * Creates an Outcome from an Err value.\n\t */\n\tstatic err<E>(error: E): Erroneous<E> {\n\t\treturn new Erroneous(error);\n\t}\n\n\t/**\n\t * Creates an Outcome from a Result.\n\t */\n\tstatic from<T, E>(result: Result<T, E>): Outcome<T, E> {\n\t\treturn new Outcome(result);\n\t}\n\n\tandThen<U>(fn: (value: T) => Result<U, E>): Outcome<U, E> {\n\t\treturn Outcome.from(andThen(this._result, fn));\n\t}\n\n\tmap<U>(fn: (value: T) => U): Outcome<U, E> {\n\t\treturn Outcome.from(map(this._result, fn));\n\t}\n\n\tmapErr<F>(fn: (error: E) => F): Outcome<T, F> {\n\t\treturn Outcome.from(mapErr(this._result, fn));\n\t}\n}\n\n"]}
@@ -0,0 +1,47 @@
1
+ export { a as DeepEqualExceptOptions, D as DeepOmitOptions, K as Key, P as PathSegment, b as deepEqualExcept, d as deepOmit } from './deep-equal-except-C8yoSk4L.js';
2
+
3
+ /**
4
+ * Performs a deep equality check between two values.
5
+ *
6
+ * This function compares values recursively, handling:
7
+ * - Primitives (with special handling for NaN)
8
+ * - Arrays (nested arrays supported)
9
+ * - Objects (plain objects and class instances)
10
+ * - TypedArrays (Uint8Array, Int32Array, etc.)
11
+ * - DataView
12
+ * - Maps and Sets
13
+ * - Dates and RegExp
14
+ * - Wrapper objects (Boolean, Number, String)
15
+ * - Circular references (detected and handled)
16
+ *
17
+ * @param a - The first value to compare
18
+ * @param b - The second value to compare
19
+ * @returns `true` if the values are deeply equal, `false` otherwise
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * deepEqual([1, 2, 3], [1, 2, 3]); // true
24
+ * deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }); // true
25
+ * deepEqual(NaN, NaN); // true
26
+ * deepEqual([1, 2], [1, 2, 3]); // false
27
+ * ```
28
+ */
29
+ declare function deepEqual(a: unknown, b: unknown): boolean;
30
+
31
+ /**
32
+ * Checks if an object is a built-in JavaScript type that should be treated atomically.
33
+ * This function automatically detects built-ins without requiring manual maintenance.
34
+ *
35
+ * Detection strategy:
36
+ * 1. TypedArrays: Check if tag ends with "Array]" (covers all current and future TypedArrays)
37
+ * 2. ArrayBuffer views: Use ArrayBuffer.isView() (covers DataView and all TypedArrays)
38
+ * 3. Built-in constructors: Check if constructor exists in global scope and matches known patterns
39
+ * 4. Tag-based: Fallback to tag matching for known built-ins
40
+ *
41
+ * @param obj - The object to check
42
+ * @param tag - The result of `Object.prototype.toString.call(obj)`
43
+ * @returns `true` if the object is a built-in type, `false` otherwise
44
+ */
45
+ declare function isBuiltInObject(obj: object, tag: string): boolean;
46
+
47
+ export { deepEqual, isBuiltInObject };
@@ -0,0 +1,2 @@
1
+ var K=Object.defineProperty;var l=(t,o)=>K(t,"name",{value:o,configurable:true});function j(t,o){if(o.endsWith("Array]")||ArrayBuffer.isView(t)||o==="[object ArrayBuffer]"||o==="[object SharedArrayBuffer]")return true;let n=t.constructor;if(n&&typeof n=="function"){let y=n.name;if(y&&typeof globalThis<"u"&&y in globalThis&&globalThis[y]===n){let e=Object.getPrototypeOf(t);if(e!==Object.prototype&&e!==null)return true}}return new Set(["[object Date]","[object RegExp]","[object Map]","[object Set]","[object WeakMap]","[object WeakSet]","[object Promise]","[object Error]","[object Boolean]","[object Number]","[object String]"]).has(o)}l(j,"isBuiltInObject");var d=Object.prototype,O=d.toString,P=d.hasOwnProperty;function x(t,o){return m(t,o,new WeakMap)}l(x,"deepEqual");function m(t,o,n){if(t===o)return true;let i=typeof t,y=typeof o;if(i!=="object"||t===null||y!=="object"||o===null)return i==="number"&&y==="number"?Number.isNaN(t)&&Number.isNaN(o):false;let e=t,r=o,g=n.get(e);if(g!==void 0)return g===r;if(n.set(e,r),ArrayBuffer.isView(e)||ArrayBuffer.isView(r)){if(!ArrayBuffer.isView(e)||!ArrayBuffer.isView(r))return false;let a=O.call(e),c=O.call(r);if(a!==c)return false;if(a==="[object DataView]"){let p=e,h=r;if(p.byteLength!==h.byteLength)return false;let S=p.byteLength;for(let k=0;k<S;k++)if(p.getUint8(k)!==h.getUint8(k))return false;return true}let s=e,f=r,u=s.length;if(u!==f.length)return false;for(let p=0;p<u;p++)if(s[p]!==f[p])return false;return true}let b=O.call(e),w=O.call(r);if(b!==w)return false;switch(b){case "[object Array]":{let a=e,c=r,s=a.length;if(s!==c.length)return false;for(let f=0;f<s;f++)if(!m(a[f],c[f],n))return false;return true}case "[object Map]":{let a=e,c=r;if(a.size!==c.size)return false;for(let[s,f]of a){if(!c.has(s))return false;let u=c.get(s);if(!m(f,u,n))return false}return true}case "[object Set]":{let a=e,c=r;if(a.size!==c.size)return false;for(let s of a)if(!c.has(s))return false;return true}case "[object Date]":{let a=e.getTime(),c=r.getTime();return a===c}case "[object RegExp]":{let a=e,c=r;return a.source===c.source&&a.flags===c.flags}case "[object Boolean]":case "[object Number]":case "[object String]":return e.valueOf()===r.valueOf();default:{if(j(e,b)&&j(r,w))return e===r;let a=Object.keys(e),c=Object.keys(r),s=Object.getOwnPropertySymbols(e),f=Object.getOwnPropertySymbols(r);if(a.length!==c.length||s.length!==f.length)return false;for(let u of a)if(!P.call(r,u))return false;for(let u of s)if(!Object.getOwnPropertySymbols(r).includes(u))return false;for(let u of a)if(!m(e[u],r[u],n))return false;for(let u of s)if(!m(e[u],r[u],n))return false;return true}}}l(m,"deepEqualInner");function A(t,o){return B(t,o,[],new WeakMap)}l(A,"deepOmit");function B(t,o,n,i){if(t===null||typeof t!=="object")return t;let e=t,r=i.get(e);if(r!==void 0)return r;let g=Object.prototype.toString.call(e);if(g==="[object Array]"){let s=e,f=new Array(s.length);i.set(e,f);for(let u=0;u<s.length;u++)n.push(u),f[u]=B(s[u],o,n,i),n.pop();return f}if(j(e,g))return t;let b=Object.create(Object.getPrototypeOf(e));i.set(e,b);let w=Object.keys(e),a=Object.getOwnPropertySymbols(e),c=[...w,...a];for(let s of c)D(s,n,o)||(n.push(s),b[s]=B(e[s],o,n,i),n.pop());return b}l(B,"omitInternal");function D(t,o,n){return !!(n.ignoreKeys?.includes(t)||n.ignoreKeyPredicate?.(t,o))}l(D,"shouldIgnoreKey");function U(t,o,n){let i=A(t,n),y=A(o,n);return x(i,y)}l(U,"deepEqualExcept");export{x as deepEqual,U as deepEqualExcept,A as deepOmit,j as isBuiltInObject};//# sourceMappingURL=utils-array.js.map
2
+ //# sourceMappingURL=utils-array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/array/is-built-in.ts","../src/utils/array/deep-equal.ts","../src/utils/array/deep-omit.ts","../src/utils/array/deep-equal-except.ts"],"names":["isBuiltInObject","obj","tag","objConstructor","constructorName","proto","__name","objProto","objToString","objHasOwn","deepEqual","a","b","deepEqualInner","visited","typeA","typeB","objA","objB","cached","tagA","tagB","viewA","viewB","len","i","arrA","arrB","mapA","mapB","key","valA","valB","setA","setB","value","timeA","timeB","regA","regB","stringKeysA","stringKeysB","symbolKeysA","symbolKeysB","deepOmit","options","omitInternal","path","arr","clone","stringKeys","symbolKeys","keys","shouldIgnoreKey","deepEqualExcept","prunedA","prunedB"],"mappings":"iFAcO,SAASA,CAAAA,CAAgBC,EAAaC,CAAAA,CAAsB,CAYlE,GAVIA,CAAAA,CAAI,QAAA,CAAS,QAAQ,CAAA,EAKrB,WAAA,CAAY,OAAOD,CAAG,CAAA,EAKtBC,IAAQ,sBAAA,EAA0BA,CAAAA,GAAQ,6BAC7C,OAAO,KAAA,CAIR,IAAMC,CAAAA,CAAkBF,CAAAA,CAAkC,WAAA,CAC1D,GAAIE,CAAAA,EAAkB,OAAOA,GAAmB,UAAA,CAAY,CAC3D,IAAMC,CAAAA,CAAkBD,CAAAA,CAAe,KAGvC,GACCC,CAAAA,EACA,OAAO,UAAA,CAAe,GAAA,EACtBA,KAAmB,UAAA,EAClB,UAAA,CAAuCA,CAAe,CAAA,GAAMD,CAAAA,CAC5D,CAGD,IAAME,CAAAA,CAAQ,MAAA,CAAO,eAAeJ,CAAG,CAAA,CACvC,GAAII,CAAAA,GAAU,MAAA,CAAO,WAAaA,CAAAA,GAAU,IAAA,CAC3C,OAAO,KAET,CACD,CAiBA,OAdyB,IAAI,IAAI,CAChC,eAAA,CACA,kBACA,cAAA,CACA,cAAA,CACA,kBAAA,CACA,kBAAA,CACA,kBAAA,CACA,gBAAA,CACA,mBACA,iBAAA,CACA,iBACD,CAAC,CAAA,CAEuB,GAAA,CAAIH,CAAG,CAChC,CArDgBI,EAAAN,CAAAA,CAAA,iBAAA,CAAA,CCZhB,IAAMO,CAAAA,CAAW,MAAA,CAAO,UAClBC,CAAAA,CA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,CAAAA,CAAY,GAAGC,CAAU,CAAA,CAEjD,IAAA,IAAWrB,CAAAA,IAAOsB,CAAAA,CACbC,CAAAA,CAAgBvB,CAAAA,CAAKiB,EAAMF,CAAO,CAAA,GAEtCE,EAAK,IAAA,CAAKjB,CAAG,EACZmB,CAAAA,CAAuCnB,CAAG,EAAIgB,CAAAA,CAC7C7C,CAAAA,CAAqC6B,CAAG,CAAA,CACzCe,CAAAA,CACAE,EACAjC,CACD,CAAA,CACAiC,EAAK,GAAA,EAAI,CAAA,CAGV,OAAOE,CACR,CAhES3C,CAAAA,CAAAwC,EAAA,cAAA,CAAA,CAkET,SAASO,EACRvB,CAAAA,CACAiB,CAAAA,CACAF,EACU,CAIV,OAHI,GAAAA,CAAAA,CAAQ,UAAA,EAAY,SAASf,CAAG,CAAA,EAGhCe,EAAQ,kBAAA,GAAqBf,CAAAA,CAAKiB,CAAI,CAAA,CAI3C,CAZSzC,CAAAA,CAAA+C,CAAAA,CAAA,iBAAA,CAAA,CCvFF,SAASC,EACf3C,CAAAA,CACAC,CAAAA,CACAiC,EACU,CACV,IAAMU,EAAUX,CAAAA,CAASjC,CAAAA,CAAGkC,CAAO,CAAA,CAC7BW,CAAAA,CAAUZ,EAAShC,CAAAA,CAAGiC,CAAO,EACnC,OAAOnC,CAAAA,CAAU6C,EAASC,CAAO,CAClC,CARgBlD,CAAAA,CAAAgD,CAAAA,CAAA,iBAAA,CAAA","file":"utils-array.js","sourcesContent":["/**\n * Checks if an object is a built-in JavaScript type that should be treated atomically.\n * This function automatically detects built-ins without requiring manual maintenance.\n *\n * Detection strategy:\n * 1. TypedArrays: Check if tag ends with \"Array]\" (covers all current and future TypedArrays)\n * 2. ArrayBuffer views: Use ArrayBuffer.isView() (covers DataView and all TypedArrays)\n * 3. Built-in constructors: Check if constructor exists in global scope and matches known patterns\n * 4. Tag-based: Fallback to tag matching for known built-ins\n *\n * @param obj - The object to check\n * @param tag - The result of `Object.prototype.toString.call(obj)`\n * @returns `true` if the object is a built-in type, `false` otherwise\n */\nexport function isBuiltInObject(obj: object, tag: string): boolean {\n\t// 1. TypedArrays: all end with \"Array]\" - future-proof for new TypedArrays\n\tif (tag.endsWith(\"Array]\")) {\n\t\treturn true;\n\t}\n\n\t// 2. ArrayBuffer views: covers DataView and all TypedArrays (future-proof)\n\tif (ArrayBuffer.isView(obj)) {\n\t\treturn true;\n\t}\n\n\t// 3. ArrayBuffer and SharedArrayBuffer\n\tif (tag === \"[object ArrayBuffer]\" || tag === \"[object SharedArrayBuffer]\") {\n\t\treturn true;\n\t}\n\n\t// 4. Check if constructor exists in global scope (future-proof for new globals)\n\tconst objConstructor = (obj as { constructor?: unknown }).constructor;\n\tif (objConstructor && typeof objConstructor === \"function\") {\n\t\tconst constructorName = objConstructor.name;\n\t\t// Check if it's a known global constructor\n\t\t// This covers: Date, RegExp, Map, Set, WeakMap, WeakSet, Promise, Error, etc.\n\t\tif (\n\t\t\tconstructorName &&\n\t\t\ttypeof globalThis !== \"undefined\" &&\n\t\t\tconstructorName in globalThis &&\n\t\t\t(globalThis as Record<string, unknown>)[constructorName] === objConstructor\n\t\t) {\n\t\t\t// Additional check: ensure it's not a user-defined class with same name\n\t\t\t// Built-ins typically have non-enumerable properties and specific prototypes\n\t\t\tconst proto = Object.getPrototypeOf(obj);\n\t\t\tif (proto !== Object.prototype && proto !== null) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\t// 5. Tag-based fallback for known built-ins (covers edge cases)\n\tconst knownBuiltInTags = new Set([\n\t\t\"[object Date]\",\n\t\t\"[object RegExp]\",\n\t\t\"[object Map]\",\n\t\t\"[object Set]\",\n\t\t\"[object WeakMap]\",\n\t\t\"[object WeakSet]\",\n\t\t\"[object Promise]\",\n\t\t\"[object Error]\",\n\t\t\"[object Boolean]\",\n\t\t\"[object Number]\",\n\t\t\"[object String]\",\n\t]);\n\n\treturn knownBuiltInTags.has(tag);\n}\n\n","import { isBuiltInObject } from \"./is-built-in\";\n\nconst objProto = Object.prototype;\nconst objToString = objProto.toString;\nconst objHasOwn = objProto.hasOwnProperty;\n\n/**\n * Performs a deep equality check between two values.\n *\n * This function compares values recursively, handling:\n * - Primitives (with special handling for NaN)\n * - Arrays (nested arrays supported)\n * - Objects (plain objects and class instances)\n * - TypedArrays (Uint8Array, Int32Array, etc.)\n * - DataView\n * - Maps and Sets\n * - Dates and RegExp\n * - Wrapper objects (Boolean, Number, String)\n * - Circular references (detected and handled)\n *\n * @param a - The first value to compare\n * @param b - The second value to compare\n * @returns `true` if the values are deeply equal, `false` otherwise\n *\n * @example\n * ```ts\n * deepEqual([1, 2, 3], [1, 2, 3]); // true\n * deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] }); // true\n * deepEqual(NaN, NaN); // true\n * deepEqual([1, 2], [1, 2, 3]); // false\n * ```\n */\nexport function deepEqual(a: unknown, b: unknown): boolean {\n\treturn deepEqualInner(a, b, new WeakMap<object, object>());\n}\n\n/**\n * Internal recursive function for deep equality comparison.\n * Tracks visited objects to detect and handle circular references.\n *\n * @param a - The first value to compare\n * @param b - The second value to compare\n * @param visited - WeakMap to track visited object pairs and detect cycles\n * @returns `true` if the values are deeply equal, `false` otherwise\n * @internal\n */\nfunction deepEqualInner(\n\ta: unknown,\n\tb: unknown,\n\tvisited: WeakMap<object, object>\n): boolean {\n\t// 1. Fast path: reference equality\n\tif (a === b) return true;\n\n\tconst typeA = typeof a;\n\tconst typeB = typeof b;\n\n\t// 2. If one is not an object → primitive / function\n\tif (typeA !== \"object\" || a === null || typeB !== \"object\" || b === null) {\n\t\t// Special case: NaN should be equal\n\t\tif (typeA === \"number\" && typeB === \"number\") {\n\t\t\treturn Number.isNaN(a as number) && Number.isNaN(b as number);\n\t\t}\n\t\t// Everything else is directly unequal with !== (including functions)\n\t\treturn false;\n\t}\n\n\t// From here on: both are non-null objects\n\n\tconst objA = a as object;\n\tconst objB = b as object;\n\n\t// 3. Cycles: already seen pair?\n\tconst cached = visited.get(objA);\n\tif (cached !== undefined) {\n\t\t// If we already paired this A with a different B → unequal\n\t\treturn cached === objB;\n\t}\n\tvisited.set(objA, objB);\n\n\t// 4. Handle Typed Arrays / DataView first\n\tif (ArrayBuffer.isView(objA) || ArrayBuffer.isView(objB)) {\n\t\tif (!ArrayBuffer.isView(objA) || !ArrayBuffer.isView(objB)) return false;\n\n\t\tconst tagA = objToString.call(objA);\n\t\tconst tagB = objToString.call(objB);\n\t\tif (tagA !== tagB) return false;\n\n\t\t// DataView: compare byte by byte\n\t\tif (tagA === \"[object DataView]\") {\n\t\t\tconst viewA = objA as DataView;\n\t\t\tconst viewB = objB as DataView;\n\t\t\tif (viewA.byteLength !== viewB.byteLength) return false;\n\n\t\t\tconst len = viewA.byteLength;\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\tif (viewA.getUint8(i) !== viewB.getUint8(i)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\t// Typed Arrays: element by element\n\t\tconst arrA = objA as unknown as ArrayLike<unknown>;\n\t\tconst arrB = objB as unknown as ArrayLike<unknown>;\n\n\t\tconst len = arrA.length;\n\t\tif (len !== arrB.length) return false;\n\n\t\tfor (let i = 0; i < len; i++) {\n\t\t\tif ((arrA as any)[i] !== (arrB as any)[i]) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t// 5. Tag-based type detection (robust across realms)\n\tconst tagA = objToString.call(objA);\n\tconst tagB = objToString.call(objB);\n\tif (tagA !== tagB) return false;\n\n\tswitch (tagA) {\n\t\tcase \"[object Array]\": {\n\t\t\tconst arrA = objA as unknown[];\n\t\t\tconst arrB = objB as unknown[];\n\t\t\tconst len = arrA.length;\n\t\t\tif (len !== arrB.length) return false;\n\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\tif (!deepEqualInner(arrA[i], arrB[i], visited)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tcase \"[object Map]\": {\n\t\t\tconst mapA = objA as Map<unknown, unknown>;\n\t\t\tconst mapB = objB as Map<unknown, unknown>;\n\n\t\t\tif (mapA.size !== mapB.size) return false;\n\n\t\t\tfor (const [key, valA] of mapA) {\n\t\t\t\t// Map keys according to JS semantics: reference / SameValueZero\n\t\t\t\tif (!mapB.has(key)) return false;\n\t\t\t\tconst valB = mapB.get(key);\n\t\t\t\tif (!deepEqualInner(valA, valB, visited)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tcase \"[object Set]\": {\n\t\t\tconst setA = objA as Set<unknown>;\n\t\t\tconst setB = objB as Set<unknown>;\n\n\t\t\tif (setA.size !== setB.size) return false;\n\n\t\t\t// Set elements: same reference (JS semantics)\n\t\t\tfor (const value of setA) {\n\t\t\t\tif (!setB.has(value)) return false;\n\t\t\t}\n\t\t\treturn true;\n\t\t}\n\n\t\tcase \"[object Date]\": {\n\t\t\tconst timeA = (objA as Date).getTime();\n\t\t\tconst timeB = (objB as Date).getTime();\n\t\t\treturn timeA === timeB;\n\t\t}\n\n\t\tcase \"[object RegExp]\": {\n\t\t\tconst regA = objA as RegExp;\n\t\t\tconst regB = objB as RegExp;\n\t\t\treturn regA.source === regB.source && regA.flags === regB.flags;\n\t\t}\n\n\t\tcase \"[object Boolean]\":\n\t\tcase \"[object Number]\":\n\t\tcase \"[object String]\": {\n\t\t\t// Wrapper objects (new Boolean/Number/String)\n\t\t\treturn (objA as any).valueOf() === (objB as any).valueOf();\n\t\t}\n\n\t\tdefault: {\n\t\t\t// 6. Check if this is an unhandled built-in type (future-proof)\n\t\t\t// If both are built-ins but not handled above, they should be compared by reference\n\t\t\t// (since we don't know their internal structure)\n\t\t\tif (isBuiltInObject(objA, tagA) && isBuiltInObject(objB, tagB)) {\n\t\t\t\t// Unhandled built-in types: compare by reference as fallback\n\t\t\t\t// This ensures new built-ins don't fall through to plain object comparison\n\t\t\t\treturn objA === objB;\n\t\t\t}\n\n\t\t\t// 7. Fallback: plain / custom objects → compare own enumerable keys + values\n\t\t\tconst stringKeysA = Object.keys(objA as any);\n\t\t\tconst stringKeysB = Object.keys(objB as any);\n\t\t\tconst symbolKeysA = Object.getOwnPropertySymbols(objA as any);\n\t\t\tconst symbolKeysB = Object.getOwnPropertySymbols(objB as any);\n\n\t\t\t// Compare string keys count\n\t\t\tif (stringKeysA.length !== stringKeysB.length) return false;\n\t\t\t// Compare symbol keys count\n\t\t\tif (symbolKeysA.length !== symbolKeysB.length) return false;\n\n\t\t\t// Check all string keys exist in both objects\n\t\t\tfor (const key of stringKeysA) {\n\t\t\t\tif (!objHasOwn.call(objB, key)) return false;\n\t\t\t}\n\n\t\t\t// Check all symbol keys exist in both objects\n\t\t\tfor (const key of symbolKeysA) {\n\t\t\t\tif (!Object.getOwnPropertySymbols(objB as any).includes(key)) return false;\n\t\t\t}\n\n\t\t\t// Compare string key values\n\t\t\tfor (const key of stringKeysA) {\n\t\t\t\tif (!deepEqualInner((objA as any)[key], (objB as any)[key], visited)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Compare symbol key values\n\t\t\tfor (const key of symbolKeysA) {\n\t\t\t\tif (!deepEqualInner((objA as any)[key], (objB as any)[key], visited)) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn true;\n\t\t}\n\t}\n}\n","import { isBuiltInObject } from \"./is-built-in\";\n\nexport type Key = string | symbol;\nexport type PathSegment = string | number | symbol;\n\nexport interface DeepOmitOptions {\n\t/**\n\t * Keys to ignore everywhere in the object tree.\n\t * Only applies to object properties, not Map/Set/TypedArray contents.\n\t */\n\treadonly ignoreKeys?: readonly Key[];\n\n\t/**\n\t * Fine-grained control: Key + path (without current key).\n\t * Example path: [\"user\", \"meta\", 0, \"data\"]\n\t */\n\treadonly ignoreKeyPredicate?: (\n\t\tkey: Key,\n\t\tpath: readonly PathSegment[],\n\t) => boolean;\n}\n\n/**\n * Creates a deep copy of `value` with certain keys removed according to the provided rules.\n *\n * This function recursively traverses the object tree and removes keys that match\n * the criteria specified in `options`. Built-in types (Date, Map, Set, TypedArrays, etc.)\n * are treated atomically and not modified.\n *\n * @param value - The value to create a deep copy from\n * @param options - Options specifying which keys to ignore\n * @returns A deep copy of `value` with specified keys removed\n *\n * @example\n * ```ts\n * const obj = { a: 1, b: { c: 2, d: 3 } };\n * const result = deepOmit(obj, { ignoreKeys: ['d'] });\n * // result: { a: 1, b: { c: 2 } }\n * ```\n */\nexport function deepOmit<T>(value: T, options: DeepOmitOptions): T {\n\tconst visited = new WeakMap<object, unknown>();\n\treturn omitInternal(value, options, [], visited) as T;\n}\n\nfunction omitInternal(\n\tvalue: unknown,\n\toptions: DeepOmitOptions,\n\tpath: PathSegment[],\n\tvisited: WeakMap<object, unknown>,\n): unknown {\n\tif (value === null) return value;\n\tconst type = typeof value;\n\n\t// Primitives and functions are passed through unchanged\n\tif (type !== \"object\") return value;\n\n\tconst obj = value as object;\n\n\t// Cycles: return cached value if already visited\n\tconst cached = visited.get(obj);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst tag = Object.prototype.toString.call(obj);\n\n\t// Arrays: recursively process elements\n\tif (tag === \"[object Array]\") {\n\t\tconst arr = obj as unknown[];\n\t\tconst clone: unknown[] = new Array(arr.length);\n\t\tvisited.set(obj, clone);\n\n\t\tfor (let i = 0; i < arr.length; i++) {\n\t\t\tpath.push(i);\n\t\t\tclone[i] = omitInternal(arr[i], options, path, visited);\n\t\t\tpath.pop();\n\t\t}\n\t\treturn clone;\n\t}\n\n\t// Built-ins: treat atomically, no key filtering inside\n\t// Future-proof detection: check if object is a built-in type\n\tif (isBuiltInObject(obj, tag)) {\n\t\treturn value;\n\t}\n\n\t// Plain / Custom Objects: filter keys, recursively process values\n\tconst clone = Object.create(Object.getPrototypeOf(obj));\n\tvisited.set(obj, clone);\n\n\tconst stringKeys = Object.keys(obj);\n\tconst symbolKeys = Object.getOwnPropertySymbols(obj);\n\tconst keys: Key[] = [...stringKeys, ...symbolKeys];\n\n\tfor (const key of keys) {\n\t\tif (shouldIgnoreKey(key, path, options)) continue;\n\n\t\tpath.push(key);\n\t\t(clone as Record<PropertyKey, unknown>)[key] = omitInternal(\n\t\t\t(obj as Record<PropertyKey, unknown>)[key],\n\t\t\toptions,\n\t\t\tpath,\n\t\t\tvisited,\n\t\t);\n\t\tpath.pop();\n\t}\n\n\treturn clone;\n}\n\nfunction shouldIgnoreKey(\n\tkey: Key,\n\tpath: readonly PathSegment[],\n\toptions: DeepOmitOptions,\n): boolean {\n\tif (options.ignoreKeys?.includes(key)) {\n\t\treturn true;\n\t}\n\tif (options.ignoreKeyPredicate?.(key, path)) {\n\t\treturn true;\n\t}\n\treturn false;\n}\n","import { deepEqual } from \"./deep-equal\";\nimport { type DeepOmitOptions, deepOmit } from \"./deep-omit\";\n\nexport type DeepEqualExceptOptions = DeepOmitOptions;\n\n/**\n * Performs a deep equality comparison between two values after omitting specified keys.\n * \n * This function first removes the specified keys from both values using `deepOmit`,\n * then performs a deep equality check using `deepEqual`.\n * \n * @param a - The first value to compare\n * @param b - The second value to compare\n * @param options - Options specifying which keys to omit before comparison\n * @returns `true` if the values are deeply equal after omitting specified keys, `false` otherwise\n * \n * @example\n * ```ts\n * const obj1 = { id: 1, name: \"Alice\", updatedAt: \"2024-01-01\" };\n * const obj2 = { id: 2, name: \"Alice\", updatedAt: \"2024-01-02\" };\n * \n * deepEqualExcept(obj1, obj2, { ignoreKeys: [\"id\", \"updatedAt\"] }); // true\n * ```\n */\nexport function deepEqualExcept(\n\ta: unknown,\n\tb: unknown,\n\toptions: DeepEqualExceptOptions,\n): boolean {\n\tconst prunedA = deepOmit(a, options);\n\tconst prunedB = deepOmit(b, options);\n\treturn deepEqual(prunedA, prunedB);\n}\n"]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/utils.js ADDED
@@ -0,0 +1,2 @@
1
+ //# sourceMappingURL=utils.js.map
2
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@shirudo/ddd-kit",
3
- "version": "0.9.8",
3
+ "version": "0.10.0",
4
4
  "description": "Composable TypeScript toolkit for tactical DDD",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/shi-rudo/ddd-kit-ts.git"
8
+ "url": "git+https://github.com/shi-rudo/ddd-kit-ts.git"
9
9
  },
10
10
  "main": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -63,4 +63,4 @@
63
63
  "bugs": {
64
64
  "url": "https://github.com/shi-rudo/ddd-kit-ts/issues"
65
65
  }
66
- }
66
+ }