@webiny/feature 0.0.0-unstable.6f45466a1d → 0.0.0-unstable.7be00a75a9
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/Brand.js +0 -3
- package/admin/BaseError.js +7 -6
- package/admin/BaseError.js.map +1 -1
- package/admin/createFeature.js +7 -8
- package/admin/createFeature.js.map +1 -1
- package/admin/index.js +0 -2
- package/api/BaseError.js +7 -6
- package/api/BaseError.js.map +1 -1
- package/api/Result.js +40 -134
- package/api/Result.js.map +1 -1
- package/api/ResultAsync.js +42 -65
- package/api/ResultAsync.js.map +1 -1
- package/api/createFeature.d.ts +6 -6
- package/api/createFeature.js +8 -7
- package/api/createFeature.js.map +1 -1
- package/api/index.js +0 -2
- package/createAbstraction.js +3 -2
- package/createAbstraction.js.map +1 -1
- package/exports/admin.js +1 -3
- package/exports/api.js +1 -3
- package/package.json +8 -9
- package/Brand.js.map +0 -1
- package/admin/index.js.map +0 -1
- package/api/index.js.map +0 -1
- package/exports/admin.js.map +0 -1
- package/exports/api.js.map +0 -1
package/Brand.js
CHANGED
package/admin/BaseError.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
class BaseError extends Error {
|
|
2
|
+
constructor(input, options){
|
|
3
|
+
super(input.message);
|
|
4
|
+
this.stack = options?.stack;
|
|
5
|
+
this.data = input.data;
|
|
6
|
+
}
|
|
7
7
|
}
|
|
8
|
+
export { BaseError };
|
|
8
9
|
|
|
9
10
|
//# sourceMappingURL=BaseError.js.map
|
package/admin/BaseError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"admin/BaseError.js","sources":["../../src/admin/BaseError.ts"],"sourcesContent":["export interface IErrorOptions {\n stack?: string;\n}\n\ntype ErrorDataWithOptionalData<TData> = TData extends void\n ? { message: string; data?: never }\n : { message: string; data: TData };\n\nexport abstract class BaseError<TData = void> extends Error {\n public abstract readonly code: string;\n public readonly data: TData extends void ? undefined : TData;\n\n protected constructor(input: ErrorDataWithOptionalData<TData>, options?: IErrorOptions) {\n super(input.message);\n this.stack = options?.stack;\n this.data = input.data as any;\n }\n}\n\nexport namespace BaseError {\n export type ErrorOptions = IErrorOptions;\n}\n"],"names":["BaseError","Error","input","options"],"mappings":"AAQO,MAAeA,kBAAgCC;IAIlD,YAAsBC,KAAuC,EAAEC,OAAuB,CAAE;QACpF,KAAK,CAACD,MAAM,OAAO;QACnB,IAAI,CAAC,KAAK,GAAGC,SAAS;QACtB,IAAI,CAAC,IAAI,GAAGD,MAAM,IAAI;IAC1B;AACJ"}
|
package/admin/createFeature.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
};
|
|
1
|
+
function createFeature(def) {
|
|
2
|
+
return {
|
|
3
|
+
name: def.name,
|
|
4
|
+
register: def.register,
|
|
5
|
+
resolve: (container)=>def.resolve ? def.resolve(container) : void 0
|
|
6
|
+
};
|
|
9
7
|
}
|
|
8
|
+
export { createFeature };
|
|
10
9
|
|
|
11
10
|
//# sourceMappingURL=createFeature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"admin/createFeature.js","sources":["../../src/admin/createFeature.ts"],"sourcesContent":["import { Container } from \"@webiny/di\";\n\nexport interface FeatureDefinition<TExports = any, TParams extends any[] = []> {\n name: string;\n register: (container: Container, ...args: TParams) => void;\n resolve: (container: Container) => TExports;\n}\n\nexport function createFeature<\n TExports = any,\n TParams extends any[] = [] // tuple for extra args\n>(def: {\n name: string;\n register: (container: Container, ...args: TParams) => void;\n resolve?: (container: Container) => TExports;\n}): FeatureDefinition<TExports, TParams> {\n return {\n name: def.name,\n register: def.register,\n resolve: (container: Container): TExports => {\n return (def.resolve ? def.resolve(container) : undefined) as TExports;\n }\n };\n}\n"],"names":["createFeature","def","container","undefined"],"mappings":"AAQO,SAASA,cAGdC,GAID;IACG,OAAO;QACH,MAAMA,IAAI,IAAI;QACd,UAAUA,IAAI,QAAQ;QACtB,SAAS,CAACC,YACED,IAAI,OAAO,GAAGA,IAAI,OAAO,CAACC,aAAaC;IAEvD;AACJ"}
|
package/admin/index.js
CHANGED
package/api/BaseError.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
class BaseError extends Error {
|
|
2
|
+
constructor(input, options){
|
|
3
|
+
super(input.message);
|
|
4
|
+
this.stack = options?.stack;
|
|
5
|
+
this.data = input.data;
|
|
6
|
+
}
|
|
7
7
|
}
|
|
8
|
+
export { BaseError };
|
|
8
9
|
|
|
9
10
|
//# sourceMappingURL=BaseError.js.map
|
package/api/BaseError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/BaseError.js","sources":["../../src/api/BaseError.ts"],"sourcesContent":["export interface ErrorOptions {\n stack?: string;\n}\n\ntype ErrorDataWithOptionalData<TData> = TData extends void\n ? { message: string; data?: never }\n : { message: string; data: TData };\n\nexport abstract class BaseError<TData = void> extends Error {\n public abstract readonly code: string;\n public readonly data: TData extends void ? undefined : TData;\n\n protected constructor(input: ErrorDataWithOptionalData<TData>, options?: ErrorOptions) {\n super(input.message);\n this.stack = options?.stack;\n this.data = input.data as any;\n }\n}\n"],"names":["BaseError","Error","input","options"],"mappings":"AAQO,MAAeA,kBAAgCC;IAIlD,YAAsBC,KAAuC,EAAEC,OAAsB,CAAE;QACnF,KAAK,CAACD,MAAM,OAAO;QACnB,IAAI,CAAC,KAAK,GAAGC,SAAS;QACtB,IAAI,CAAC,IAAI,GAAGD,MAAM,IAAI;IAC1B;AACJ"}
|
package/api/Result.js
CHANGED
|
@@ -1,143 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @template TError - The type of the error value.
|
|
7
|
-
*/
|
|
8
|
-
export class Result {
|
|
9
|
-
constructor(isOk, value, error) {
|
|
10
|
-
this._isOk = isOk;
|
|
11
|
-
this._value = value;
|
|
12
|
-
this._error = error;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Creates a successful `Result` containing the provided value.
|
|
17
|
-
* If no value is provided, returns Result<void, never>.
|
|
18
|
-
*
|
|
19
|
-
* @param value - The value to wrap in a successful result (optional).
|
|
20
|
-
* @returns A `Result` instance with the value.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
static ok(value) {
|
|
24
|
-
return new Result(true, value);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Creates a failed `Result` containing the provided error.
|
|
29
|
-
*
|
|
30
|
-
* @param error - The error to wrap in a failed result.
|
|
31
|
-
* @returns A `Result` instance with the error.
|
|
32
|
-
*/
|
|
33
|
-
static fail(error) {
|
|
34
|
-
return new Result(false, undefined, error);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Checks whether the result is successful.
|
|
39
|
-
*
|
|
40
|
-
* @returns `true` if the result is `ok`, otherwise `false`.
|
|
41
|
-
* Acts as a type guard to narrow the type to a successful result.
|
|
42
|
-
*/
|
|
43
|
-
isOk() {
|
|
44
|
-
return this._isOk;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Checks whether the result is a failure.
|
|
49
|
-
*
|
|
50
|
-
* @returns `true` if the result is `fail`, otherwise `false`.
|
|
51
|
-
* Acts as a type guard to narrow the type to a failed result.
|
|
52
|
-
*/
|
|
53
|
-
isFail() {
|
|
54
|
-
return !this._isOk;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Gets the value inside a successful result.
|
|
59
|
-
*
|
|
60
|
-
* @throws If the result is a failure.
|
|
61
|
-
* @returns The success value.
|
|
62
|
-
*/
|
|
63
|
-
get value() {
|
|
64
|
-
if (!this._isOk) {
|
|
65
|
-
console.error(this.error);
|
|
66
|
-
throw new Error("Tried to get value from a failed Result.");
|
|
1
|
+
class Result {
|
|
2
|
+
constructor(isOk, value, error){
|
|
3
|
+
this._isOk = isOk;
|
|
4
|
+
this._value = value;
|
|
5
|
+
this._error = error;
|
|
67
6
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Gets the error inside a failed result.
|
|
73
|
-
*
|
|
74
|
-
* @throws If the result is successful.
|
|
75
|
-
* @returns The error value.
|
|
76
|
-
*/
|
|
77
|
-
get error() {
|
|
78
|
-
if (this._isOk) {
|
|
79
|
-
throw new Error("Tried to get error from a successful Result.");
|
|
7
|
+
static ok(value) {
|
|
8
|
+
return new Result(true, value);
|
|
80
9
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Transforms the success value using the provided mapping function.
|
|
86
|
-
*
|
|
87
|
-
* @template U - The type of the new success value.
|
|
88
|
-
* @param fn - Function to apply to the value if the result is successful.
|
|
89
|
-
* @returns A new `Result` containing the mapped value, or the original error if failed.
|
|
90
|
-
*/
|
|
91
|
-
map(fn) {
|
|
92
|
-
if (this.isOk()) {
|
|
93
|
-
return Result.ok(fn(this._value));
|
|
10
|
+
static fail(error) {
|
|
11
|
+
return new Result(false, void 0, error);
|
|
94
12
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Transforms the error value using the provided mapping function.
|
|
100
|
-
*
|
|
101
|
-
* @template F - The type of the new error.
|
|
102
|
-
* @param fn - Function to apply to the error if the result is a failure.
|
|
103
|
-
* @returns A new `Result` containing the original value or the mapped error.
|
|
104
|
-
*/
|
|
105
|
-
mapError(fn) {
|
|
106
|
-
if (this.isFail()) {
|
|
107
|
-
return Result.fail(fn(this._error));
|
|
13
|
+
isOk() {
|
|
14
|
+
return this._isOk;
|
|
108
15
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Chains another `Result`-producing function onto this result.
|
|
114
|
-
* If this result is successful, the function is applied to the value.
|
|
115
|
-
* If this result is a failure, the original error is returned.
|
|
116
|
-
*
|
|
117
|
-
* @template U - The type of the next success value.
|
|
118
|
-
* @param fn - A function that takes the current value and returns another `Result`.
|
|
119
|
-
* @returns A new `Result` from applying the function or the original failure.
|
|
120
|
-
*/
|
|
121
|
-
flatMap(fn) {
|
|
122
|
-
if (this.isOk()) {
|
|
123
|
-
return fn(this._value);
|
|
16
|
+
isFail() {
|
|
17
|
+
return !this._isOk;
|
|
124
18
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
19
|
+
get value() {
|
|
20
|
+
if (!this._isOk) {
|
|
21
|
+
console.error(this.error);
|
|
22
|
+
throw new Error("Tried to get value from a failed Result.");
|
|
23
|
+
}
|
|
24
|
+
return this._value;
|
|
25
|
+
}
|
|
26
|
+
get error() {
|
|
27
|
+
if (this._isOk) throw new Error("Tried to get error from a successful Result.");
|
|
28
|
+
return this._error;
|
|
29
|
+
}
|
|
30
|
+
map(fn) {
|
|
31
|
+
if (this.isOk()) return Result.ok(fn(this._value));
|
|
32
|
+
return Result.fail(this._error);
|
|
33
|
+
}
|
|
34
|
+
mapError(fn) {
|
|
35
|
+
if (this.isFail()) return Result.fail(fn(this._error));
|
|
36
|
+
return Result.ok(this._value);
|
|
37
|
+
}
|
|
38
|
+
flatMap(fn) {
|
|
39
|
+
if (this.isOk()) return fn(this._value);
|
|
40
|
+
return Result.fail(this._error);
|
|
41
|
+
}
|
|
42
|
+
match(handlers) {
|
|
43
|
+
if (this.isOk()) return handlers.ok(this._value);
|
|
44
|
+
return handlers.fail(this._error);
|
|
138
45
|
}
|
|
139
|
-
return handlers.fail(this._error);
|
|
140
|
-
}
|
|
141
46
|
}
|
|
47
|
+
export { Result };
|
|
142
48
|
|
|
143
49
|
//# sourceMappingURL=Result.js.map
|
package/api/Result.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/Result.js","sources":["../../src/api/Result.ts"],"sourcesContent":["/**\n * A container type that represents either a successful result (`ok`) or a failure (`fail`).\n * Inspired by functional programming constructs like `Either` or `Result` in other languages.\n *\n * @template TValue - The type of the success value.\n * @template TError - The type of the error value.\n */\nexport class Result<TValue, TError = never> {\n protected readonly _isOk: boolean;\n protected readonly _value?: TValue;\n protected readonly _error?: TError;\n\n private constructor(isOk: boolean, value?: TValue, error?: TError) {\n this._isOk = isOk;\n this._value = value;\n this._error = error;\n }\n\n /**\n * Creates a successful `Result` containing the provided value.\n * If no value is provided, returns Result<void, never>.\n *\n * @param value - The value to wrap in a successful result (optional).\n * @returns A `Result` instance with the value.\n */\n public static ok<T>(value: T): Result<T, never>;\n public static ok(): Result<void, never>;\n public static ok<T>(value?: T): Result<T | void, never> {\n return new Result<T | void, never>(true, value);\n }\n\n /**\n * Creates a failed `Result` containing the provided error.\n *\n * @param error - The error to wrap in a failed result.\n * @returns A `Result` instance with the error.\n */\n public static fail<E>(error: E): Result<never, E> {\n return new Result<never, E>(false, undefined, error);\n }\n\n /**\n * Checks whether the result is successful.\n *\n * @returns `true` if the result is `ok`, otherwise `false`.\n * Acts as a type guard to narrow the type to a successful result.\n */\n public isOk(): this is { _value: TValue } & Result<TValue, TError> {\n return this._isOk;\n }\n\n /**\n * Checks whether the result is a failure.\n *\n * @returns `true` if the result is `fail`, otherwise `false`.\n * Acts as a type guard to narrow the type to a failed result.\n */\n public isFail(): this is { _error: TError } & Result<TValue, TError> {\n return !this._isOk;\n }\n\n /**\n * Gets the value inside a successful result.\n *\n * @throws If the result is a failure.\n * @returns The success value.\n */\n public get value(): TValue {\n if (!this._isOk) {\n console.error(this.error);\n throw new Error(\"Tried to get value from a failed Result.\");\n }\n\n return this._value as TValue;\n }\n\n /**\n * Gets the error inside a failed result.\n *\n * @throws If the result is successful.\n * @returns The error value.\n */\n public get error(): TError {\n if (this._isOk) {\n throw new Error(\"Tried to get error from a successful Result.\");\n }\n\n return this._error as TError;\n }\n\n /**\n * Transforms the success value using the provided mapping function.\n *\n * @template U - The type of the new success value.\n * @param fn - Function to apply to the value if the result is successful.\n * @returns A new `Result` containing the mapped value, or the original error if failed.\n */\n public map<U>(fn: (value: TValue) => U): Result<U, TError> {\n if (this.isOk()) {\n return Result.ok(fn(this._value as TValue));\n }\n\n return Result.fail(this._error as TError);\n }\n\n /**\n * Transforms the error value using the provided mapping function.\n *\n * @template F - The type of the new error.\n * @param fn - Function to apply to the error if the result is a failure.\n * @returns A new `Result` containing the original value or the mapped error.\n */\n public mapError<F>(fn: (error: TError) => F): Result<TValue, F> {\n if (this.isFail()) {\n return Result.fail(fn(this._error as TError));\n }\n\n return Result.ok(this._value as TValue);\n }\n\n /**\n * Chains another `Result`-producing function onto this result.\n * If this result is successful, the function is applied to the value.\n * If this result is a failure, the original error is returned.\n *\n * @template U - The type of the next success value.\n * @param fn - A function that takes the current value and returns another `Result`.\n * @returns A new `Result` from applying the function or the original failure.\n */\n public flatMap<U>(fn: (value: TValue) => Result<U, TError>): Result<U, TError> {\n if (this.isOk()) {\n return fn(this._value as TValue);\n }\n\n return Result.fail(this._error as TError);\n }\n\n /**\n * Pattern-matches the result to handle both success and failure cases.\n *\n * @template U - The return type of both match functions.\n * @param handlers - An object containing `ok` and `fail` handlers.\n * @returns The return value from the corresponding handler.\n */\n public match<U>(handlers: { ok: (value: TValue) => U; fail: (error: TError) => U }): U {\n if (this.isOk()) {\n return handlers.ok(this._value as TValue);\n }\n\n return handlers.fail(this._error as TError);\n }\n}\n\nexport namespace Result {\n export type UnwrapResult<T> = Awaited<T> extends Result<infer Ok, any> ? Ok : never;\n export type UnwrapError<T> = Awaited<T> extends Result<any, infer Err> ? Err : never;\n}\n"],"names":["Result","isOk","value","error","undefined","console","Error","fn","handlers"],"mappings":"AAOO,MAAMA;IAKT,YAAoBC,IAAa,EAAEC,KAAc,EAAEC,KAAc,CAAE;QAC/D,IAAI,CAAC,KAAK,GAAGF;QACb,IAAI,CAAC,MAAM,GAAGC;QACd,IAAI,CAAC,MAAM,GAAGC;IAClB;IAWA,OAAc,GAAMD,KAAS,EAA2B;QACpD,OAAO,IAAIF,OAAwB,MAAME;IAC7C;IAQA,OAAc,KAAQC,KAAQ,EAAoB;QAC9C,OAAO,IAAIH,OAAiB,OAAOI,QAAWD;IAClD;IAQO,OAA4D;QAC/D,OAAO,IAAI,CAAC,KAAK;IACrB;IAQO,SAA8D;QACjE,OAAO,CAAC,IAAI,CAAC,KAAK;IACtB;IAQA,IAAW,QAAgB;QACvB,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACbE,QAAQ,KAAK,CAAC,IAAI,CAAC,KAAK;YACxB,MAAM,IAAIC,MAAM;QACpB;QAEA,OAAO,IAAI,CAAC,MAAM;IACtB;IAQA,IAAW,QAAgB;QACvB,IAAI,IAAI,CAAC,KAAK,EACV,MAAM,IAAIA,MAAM;QAGpB,OAAO,IAAI,CAAC,MAAM;IACtB;IASO,IAAOC,EAAwB,EAAqB;QACvD,IAAI,IAAI,CAAC,IAAI,IACT,OAAOP,OAAO,EAAE,CAACO,GAAG,IAAI,CAAC,MAAM;QAGnC,OAAOP,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM;IAClC;IASO,SAAYO,EAAwB,EAAqB;QAC5D,IAAI,IAAI,CAAC,MAAM,IACX,OAAOP,OAAO,IAAI,CAACO,GAAG,IAAI,CAAC,MAAM;QAGrC,OAAOP,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM;IAChC;IAWO,QAAWO,EAAwC,EAAqB;QAC3E,IAAI,IAAI,CAAC,IAAI,IACT,OAAOA,GAAG,IAAI,CAAC,MAAM;QAGzB,OAAOP,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM;IAClC;IASO,MAASQ,QAAkE,EAAK;QACnF,IAAI,IAAI,CAAC,IAAI,IACT,OAAOA,SAAS,EAAE,CAAC,IAAI,CAAC,MAAM;QAGlC,OAAOA,SAAS,IAAI,CAAC,IAAI,CAAC,MAAM;IACpC;AACJ"}
|
package/api/ResultAsync.js
CHANGED
|
@@ -1,70 +1,47 @@
|
|
|
1
1
|
import { Result } from "./Result.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
return Result.ok(res.value);
|
|
45
|
-
});
|
|
46
|
-
return new ResultAsync(newPromise);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Chain another async Result.
|
|
50
|
-
flatMapAsync(fn) {
|
|
51
|
-
const newPromise = this.promise.then(async res => {
|
|
52
|
-
if (res.isFail()) {
|
|
53
|
-
return Result.fail(res.error);
|
|
54
|
-
}
|
|
55
|
-
return await fn(res.value).unwrap();
|
|
56
|
-
});
|
|
57
|
-
return new ResultAsync(newPromise);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Match success/failure (like sync Result).
|
|
61
|
-
async match(handlers) {
|
|
62
|
-
const result = await this.unwrap();
|
|
63
|
-
if (result.isOk()) {
|
|
64
|
-
return handlers.ok(result.value);
|
|
2
|
+
class ResultAsync {
|
|
3
|
+
constructor(promise){
|
|
4
|
+
this.promise = promise;
|
|
5
|
+
}
|
|
6
|
+
static from(fn) {
|
|
7
|
+
return new ResultAsync(fn());
|
|
8
|
+
}
|
|
9
|
+
static ok(value) {
|
|
10
|
+
return new ResultAsync(Promise.resolve(Result.ok(value)));
|
|
11
|
+
}
|
|
12
|
+
static fail(error) {
|
|
13
|
+
return new ResultAsync(Promise.resolve(Result.fail(error)));
|
|
14
|
+
}
|
|
15
|
+
async unwrap() {
|
|
16
|
+
return this.promise;
|
|
17
|
+
}
|
|
18
|
+
mapAsync(fn) {
|
|
19
|
+
const newPromise = this.promise.then(async (res)=>{
|
|
20
|
+
if (res.isOk()) return Result.ok(await fn(res.value));
|
|
21
|
+
return Result.fail(res.error);
|
|
22
|
+
});
|
|
23
|
+
return new ResultAsync(newPromise);
|
|
24
|
+
}
|
|
25
|
+
mapErrorAsync(fn) {
|
|
26
|
+
const newPromise = this.promise.then(async (res)=>{
|
|
27
|
+
if (res.isFail()) return Result.fail(await fn(res.error));
|
|
28
|
+
return Result.ok(res.value);
|
|
29
|
+
});
|
|
30
|
+
return new ResultAsync(newPromise);
|
|
31
|
+
}
|
|
32
|
+
flatMapAsync(fn) {
|
|
33
|
+
const newPromise = this.promise.then(async (res)=>{
|
|
34
|
+
if (res.isFail()) return Result.fail(res.error);
|
|
35
|
+
return await fn(res.value).unwrap();
|
|
36
|
+
});
|
|
37
|
+
return new ResultAsync(newPromise);
|
|
38
|
+
}
|
|
39
|
+
async match(handlers) {
|
|
40
|
+
const result = await this.unwrap();
|
|
41
|
+
if (result.isOk()) return handlers.ok(result.value);
|
|
42
|
+
return handlers.fail(result.error);
|
|
65
43
|
}
|
|
66
|
-
return handlers.fail(result.error);
|
|
67
|
-
}
|
|
68
44
|
}
|
|
45
|
+
export { ResultAsync };
|
|
69
46
|
|
|
70
47
|
//# sourceMappingURL=ResultAsync.js.map
|
package/api/ResultAsync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/ResultAsync.js","sources":["../../src/api/ResultAsync.ts"],"sourcesContent":["import { Result } from \"./Result.js\";\n\nexport class ResultAsync<TValue, TError = never> {\n constructor(private readonly promise: Promise<Result<TValue, TError>>) {}\n\n // Wrap a function returning a Promise<Result<T, E>>.\n public static from<T, E>(fn: () => Promise<Result<T, E>>): ResultAsync<T, E> {\n return new ResultAsync(fn());\n }\n\n // Wrap a successful value.\n public static ok<T>(value: T): ResultAsync<T, never> {\n return new ResultAsync(Promise.resolve(Result.ok(value)));\n }\n\n // Wrap a failure.\n public static fail<E>(error: E): ResultAsync<never, E> {\n return new ResultAsync(Promise.resolve(Result.fail(error)));\n }\n\n // Await the wrapped result.\n public async unwrap(): Promise<Result<TValue, TError>> {\n return this.promise;\n }\n\n // Transform the success value.\n public mapAsync<U>(fn: (value: TValue) => U | Promise<U>): ResultAsync<U, TError> {\n const newPromise = this.promise.then(async res => {\n if (res.isOk()) {\n return Result.ok(await fn(res.value));\n }\n\n return Result.fail(res.error);\n });\n\n return new ResultAsync(newPromise);\n }\n\n // Transform the error value.\n public mapErrorAsync<F>(fn: (error: TError) => F | Promise<F>): ResultAsync<TValue, F> {\n const newPromise = this.promise.then(async res => {\n if (res.isFail()) {\n return Result.fail(await fn(res.error));\n }\n\n return Result.ok(res.value);\n });\n\n return new ResultAsync(newPromise);\n }\n\n // Chain another async Result.\n public flatMapAsync<U>(fn: (value: TValue) => ResultAsync<U, TError>): ResultAsync<U, TError> {\n const newPromise = this.promise.then(async res => {\n if (res.isFail()) {\n return Result.fail(res.error);\n }\n\n return await fn(res.value).unwrap();\n });\n\n return new ResultAsync(newPromise);\n }\n\n // Match success/failure (like sync Result).\n public async match<U>(handlers: {\n ok: (value: TValue) => U;\n fail: (error: TError) => U;\n }): Promise<U> {\n const result = await this.unwrap();\n\n if (result.isOk()) {\n return handlers.ok(result.value);\n }\n\n return handlers.fail(result.error);\n }\n}\n"],"names":["ResultAsync","promise","fn","value","Promise","Result","error","newPromise","res","handlers","result"],"mappings":";AAEO,MAAMA;IACT,YAA6BC,OAAwC,CAAE;aAA1CA,OAAO,GAAPA;IAA2C;IAGxE,OAAc,KAAWC,EAA+B,EAAqB;QACzE,OAAO,IAAIF,YAAYE;IAC3B;IAGA,OAAc,GAAMC,KAAQ,EAAyB;QACjD,OAAO,IAAIH,YAAYI,QAAQ,OAAO,CAACC,OAAO,EAAE,CAACF;IACrD;IAGA,OAAc,KAAQG,KAAQ,EAAyB;QACnD,OAAO,IAAIN,YAAYI,QAAQ,OAAO,CAACC,OAAO,IAAI,CAACC;IACvD;IAGA,MAAa,SAA0C;QACnD,OAAO,IAAI,CAAC,OAAO;IACvB;IAGO,SAAYJ,EAAqC,EAA0B;QAC9E,MAAMK,aAAa,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAMC;YACvC,IAAIA,IAAI,IAAI,IACR,OAAOH,OAAO,EAAE,CAAC,MAAMH,GAAGM,IAAI,KAAK;YAGvC,OAAOH,OAAO,IAAI,CAACG,IAAI,KAAK;QAChC;QAEA,OAAO,IAAIR,YAAYO;IAC3B;IAGO,cAAiBL,EAAqC,EAA0B;QACnF,MAAMK,aAAa,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAMC;YACvC,IAAIA,IAAI,MAAM,IACV,OAAOH,OAAO,IAAI,CAAC,MAAMH,GAAGM,IAAI,KAAK;YAGzC,OAAOH,OAAO,EAAE,CAACG,IAAI,KAAK;QAC9B;QAEA,OAAO,IAAIR,YAAYO;IAC3B;IAGO,aAAgBL,EAA6C,EAA0B;QAC1F,MAAMK,aAAa,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAMC;YACvC,IAAIA,IAAI,MAAM,IACV,OAAOH,OAAO,IAAI,CAACG,IAAI,KAAK;YAGhC,OAAO,MAAMN,GAAGM,IAAI,KAAK,EAAE,MAAM;QACrC;QAEA,OAAO,IAAIR,YAAYO;IAC3B;IAGA,MAAa,MAASE,QAGrB,EAAc;QACX,MAAMC,SAAS,MAAM,IAAI,CAAC,MAAM;QAEhC,IAAIA,OAAO,IAAI,IACX,OAAOD,SAAS,EAAE,CAACC,OAAO,KAAK;QAGnC,OAAOD,SAAS,IAAI,CAACC,OAAO,KAAK;IACrC;AACJ"}
|
package/api/createFeature.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Container } from "@webiny/di";
|
|
2
|
-
export
|
|
2
|
+
export type FeatureDefinition<TRegister = void> = [TRegister] extends [void] ? {
|
|
3
3
|
name: string;
|
|
4
|
-
register(container: Container
|
|
5
|
-
}
|
|
6
|
-
export declare function createFeature<TRegister>(def: {
|
|
4
|
+
register(container: Container): void;
|
|
5
|
+
} : {
|
|
7
6
|
name: string;
|
|
8
|
-
register(container: Container, context
|
|
9
|
-
}
|
|
7
|
+
register(container: Container, context: TRegister): void;
|
|
8
|
+
};
|
|
9
|
+
export declare function createFeature<TRegister = void>(def: FeatureDefinition<TRegister>): FeatureDefinition<TRegister>;
|
package/api/createFeature.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
function createFeature(def) {
|
|
2
|
+
const feature = {
|
|
3
|
+
name: def.name,
|
|
4
|
+
register: def.register
|
|
5
|
+
};
|
|
6
|
+
Reflect.defineMetadata("wby:isFeature", true, feature);
|
|
7
|
+
return feature;
|
|
8
8
|
}
|
|
9
|
+
export { createFeature };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=createFeature.js.map
|
package/api/createFeature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"api/createFeature.js","sources":["../../src/api/createFeature.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\n\nexport type FeatureDefinition<TRegister = void> = [TRegister] extends [void]\n ? {\n name: string;\n register(container: Container): void;\n }\n : {\n name: string;\n register(container: Container, context: TRegister): void;\n };\n\nexport function createFeature<TRegister = void>(\n def: FeatureDefinition<TRegister>\n): FeatureDefinition<TRegister> {\n const feature = {\n name: def.name,\n register: def.register\n };\n\n Reflect.defineMetadata(\"wby:isFeature\", true, feature);\n\n return feature as FeatureDefinition<TRegister>;\n}\n"],"names":["createFeature","def","feature","Reflect"],"mappings":"AAYO,SAASA,cACZC,GAAiC;IAEjC,MAAMC,UAAU;QACZ,MAAMD,IAAI,IAAI;QACd,UAAUA,IAAI,QAAQ;IAC1B;IAEAE,QAAQ,cAAc,CAAC,iBAAiB,MAAMD;IAE9C,OAAOA;AACX"}
|
package/api/index.js
CHANGED
package/createAbstraction.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Abstraction } from "@webiny/di";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
function createAbstraction(name) {
|
|
3
|
+
return new Abstraction(name);
|
|
4
4
|
}
|
|
5
|
+
export { createAbstraction };
|
|
5
6
|
|
|
6
7
|
//# sourceMappingURL=createAbstraction.js.map
|
package/createAbstraction.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"createAbstraction.js","sources":["../src/createAbstraction.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\nexport function createAbstraction<T>(name: string) {\n return new Abstraction<T>(name);\n}\n"],"names":["createAbstraction","name","Abstraction"],"mappings":";AAEO,SAASA,kBAAqBC,IAAY;IAC7C,OAAO,IAAIC,YAAeD;AAC9B"}
|
package/exports/admin.js
CHANGED
package/exports/api.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/feature",
|
|
3
3
|
"description": "A small utility library to build application features in a Webiny project.",
|
|
4
|
-
"version": "0.0.0-unstable.
|
|
4
|
+
"version": "0.0.0-unstable.7be00a75a9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -34,18 +34,17 @@
|
|
|
34
34
|
"BaseError"
|
|
35
35
|
]
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
},
|
|
38
|
+
"publishFrom": "dist"
|
|
38
39
|
},
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@webiny/di": "0.
|
|
41
|
+
"@webiny/di": "0.0.0-unstable.7be00a75a9"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
44
|
-
"typescript": "
|
|
44
|
+
"@webiny/build-tools": "0.0.0-unstable.7be00a75a9",
|
|
45
|
+
"typescript": "6.0.3"
|
|
45
46
|
},
|
|
46
47
|
"publishConfig": {
|
|
47
|
-
"access": "public"
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
"gitHead": "6f45466a1d9fb94f6156923501eb90ac303b81a5"
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
51
50
|
}
|
package/Brand.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["Brand.ts"],"sourcesContent":["declare const brand: unique symbol;\n\nexport type Brand<T, B extends string> = T & { [brand]: B };\n"],"mappings":"","ignoreList":[]}
|
package/admin/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createDecorator","createImplementation","createFeature","BaseError","createAbstraction"],"sources":["index.ts"],"sourcesContent":["export { createDecorator, createImplementation } from \"@webiny/di\";\nexport { createFeature } from \"./createFeature.js\";\nexport type { FeatureDefinition } from \"./createFeature.js\";\nexport { BaseError } from \"./BaseError.js\";\nexport { createAbstraction } from \"../createAbstraction.js\";\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,oBAAoB,QAAQ,YAAY;AAClE,SAASC,aAAa;AAEtB,SAASC,SAAS;AAClB,SAASC,iBAAiB","ignoreList":[]}
|
package/api/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createDecorator","createImplementation","createFeature","createAbstraction","Result","ResultAsync","BaseError"],"sources":["index.ts"],"sourcesContent":["export { createDecorator, createImplementation } from \"@webiny/di\";\nexport { createFeature } from \"./createFeature.js\";\nexport { createAbstraction } from \"../createAbstraction.js\";\nexport { Result } from \"./Result.js\";\nexport { ResultAsync } from \"./ResultAsync.js\";\nexport { BaseError } from \"./BaseError.js\";\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,oBAAoB,QAAQ,YAAY;AAClE,SAASC,aAAa;AACtB,SAASC,iBAAiB;AAC1B,SAASC,MAAM;AACf,SAASC,WAAW;AACpB,SAASC,SAAS","ignoreList":[]}
|
package/exports/admin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","createAbstraction","BaseError"],"sources":["admin.ts"],"sourcesContent":["export { createFeature, createAbstraction, BaseError } from \"~/admin/index.js\";\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,iBAAiB,EAAEC,SAAS","ignoreList":[]}
|
package/exports/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","createAbstraction","Result","BaseError"],"sources":["api.ts"],"sourcesContent":["export { createFeature, createAbstraction, Result, BaseError } from \"~/api/index.js\";\n"],"mappings":"AAAA,SAASA,aAAa,EAAEC,iBAAiB,EAAEC,MAAM,EAAEC,SAAS","ignoreList":[]}
|