@webiny/feature 0.0.0-unstable.61c048f412
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.d.ts +5 -0
- package/Brand.js +3 -0
- package/Brand.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/admin/BaseError.d.ts +19 -0
- package/admin/BaseError.js +9 -0
- package/admin/BaseError.js.map +1 -0
- package/admin/createFeature.d.ts +11 -0
- package/admin/createFeature.js +11 -0
- package/admin/createFeature.js.map +1 -0
- package/admin/index.d.ts +5 -0
- package/admin/index.js +6 -0
- package/admin/index.js.map +1 -0
- package/api/BaseError.d.ts +16 -0
- package/api/BaseError.js +9 -0
- package/api/BaseError.js.map +1 -0
- package/api/Result.d.ts +102 -0
- package/api/Result.js +143 -0
- package/api/Result.js.map +1 -0
- package/api/ResultAsync.d.ts +16 -0
- package/api/ResultAsync.js +70 -0
- package/api/ResultAsync.js.map +1 -0
- package/api/createFeature.d.ts +9 -0
- package/api/createFeature.js +10 -0
- package/api/createFeature.js.map +1 -0
- package/api/index.d.ts +6 -0
- package/api/index.js +8 -0
- package/api/index.js.map +1 -0
- package/createAbstraction.d.ts +2 -0
- package/createAbstraction.js +6 -0
- package/createAbstraction.js.map +1 -0
- package/exports/admin.d.ts +1 -0
- package/exports/admin.js +3 -0
- package/exports/admin.js.map +1 -0
- package/exports/api.d.ts +1 -0
- package/exports/api.js +3 -0
- package/exports/api.js.map +1 -0
- package/package.json +51 -0
package/Brand.d.ts
ADDED
package/Brand.js
ADDED
package/Brand.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @webiny/feature
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface IErrorOptions {
|
|
2
|
+
stack?: string;
|
|
3
|
+
}
|
|
4
|
+
type ErrorDataWithOptionalData<TData> = TData extends void ? {
|
|
5
|
+
message: string;
|
|
6
|
+
data?: never;
|
|
7
|
+
} : {
|
|
8
|
+
message: string;
|
|
9
|
+
data: TData;
|
|
10
|
+
};
|
|
11
|
+
export declare abstract class BaseError<TData = void> extends Error {
|
|
12
|
+
abstract readonly code: string;
|
|
13
|
+
readonly data: TData extends void ? undefined : TData;
|
|
14
|
+
protected constructor(input: ErrorDataWithOptionalData<TData>, options?: IErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
export declare namespace BaseError {
|
|
17
|
+
type ErrorOptions = IErrorOptions;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BaseError","Error","constructor","input","options","message","stack","data"],"sources":["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"],"mappings":"AAQA,OAAO,MAAeA,SAAS,SAAuBC,KAAK,CAAC;EAI9CC,WAAWA,CAACC,KAAuC,EAAEC,OAAuB,EAAE;IACpF,KAAK,CAACD,KAAK,CAACE,OAAO,CAAC;IACpB,IAAI,CAACC,KAAK,GAAGF,OAAO,EAAEE,KAAK;IAC3B,IAAI,CAACC,IAAI,GAAGJ,KAAK,CAACI,IAAW;EACjC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Container } from "@webiny/di";
|
|
2
|
+
export interface FeatureDefinition<TExports = any, TParams extends any[] = []> {
|
|
3
|
+
name: string;
|
|
4
|
+
register: (container: Container, ...args: TParams) => void;
|
|
5
|
+
resolve: (container: Container) => TExports;
|
|
6
|
+
}
|
|
7
|
+
export declare function createFeature<TExports = any, TParams extends any[] = []>(def: {
|
|
8
|
+
name: string;
|
|
9
|
+
register: (container: Container, ...args: TParams) => void;
|
|
10
|
+
resolve?: (container: Container) => TExports;
|
|
11
|
+
}): FeatureDefinition<TExports, TParams>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","def","name","register","resolve","container","undefined"],"sources":["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"],"mappings":"AAQA,OAAO,SAASA,aAAaA,CAG3BC,GAID,EAAwC;EACrC,OAAO;IACHC,IAAI,EAAED,GAAG,CAACC,IAAI;IACdC,QAAQ,EAAEF,GAAG,CAACE,QAAQ;IACtBC,OAAO,EAAGC,SAAoB,IAAe;MACzC,OAAQJ,GAAG,CAACG,OAAO,GAAGH,GAAG,CAACG,OAAO,CAACC,SAAS,CAAC,GAAGC,SAAS;IAC5D;EACJ,CAAC;AACL","ignoreList":[]}
|
package/admin/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createDecorator, createImplementation } from "@webiny/di";
|
|
2
|
+
export { createFeature } from "./createFeature.js";
|
|
3
|
+
export type { FeatureDefinition } from "./createFeature.js";
|
|
4
|
+
export { BaseError } from "./BaseError.js";
|
|
5
|
+
export { createAbstraction } from "../createAbstraction.js";
|
package/admin/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ErrorOptions {
|
|
2
|
+
stack?: string;
|
|
3
|
+
}
|
|
4
|
+
type ErrorDataWithOptionalData<TData> = TData extends void ? {
|
|
5
|
+
message: string;
|
|
6
|
+
data?: never;
|
|
7
|
+
} : {
|
|
8
|
+
message: string;
|
|
9
|
+
data: TData;
|
|
10
|
+
};
|
|
11
|
+
export declare abstract class BaseError<TData = void> extends Error {
|
|
12
|
+
abstract readonly code: string;
|
|
13
|
+
readonly data: TData extends void ? undefined : TData;
|
|
14
|
+
protected constructor(input: ErrorDataWithOptionalData<TData>, options?: ErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
export {};
|
package/api/BaseError.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BaseError","Error","constructor","input","options","message","stack","data"],"sources":["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"],"mappings":"AAQA,OAAO,MAAeA,SAAS,SAAuBC,KAAK,CAAC;EAI9CC,WAAWA,CAACC,KAAuC,EAAEC,OAAsB,EAAE;IACnF,KAAK,CAACD,KAAK,CAACE,OAAO,CAAC;IACpB,IAAI,CAACC,KAAK,GAAGF,OAAO,EAAEE,KAAK;IAC3B,IAAI,CAACC,IAAI,GAAGJ,KAAK,CAACI,IAAW;EACjC;AACJ","ignoreList":[]}
|
package/api/Result.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A container type that represents either a successful result (`ok`) or a failure (`fail`).
|
|
3
|
+
* Inspired by functional programming constructs like `Either` or `Result` in other languages.
|
|
4
|
+
*
|
|
5
|
+
* @template TValue - The type of the success value.
|
|
6
|
+
* @template TError - The type of the error value.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Result<TValue, TError = never> {
|
|
9
|
+
protected readonly _isOk: boolean;
|
|
10
|
+
protected readonly _value?: TValue;
|
|
11
|
+
protected readonly _error?: TError;
|
|
12
|
+
private constructor();
|
|
13
|
+
/**
|
|
14
|
+
* Creates a successful `Result` containing the provided value.
|
|
15
|
+
* If no value is provided, returns Result<void, never>.
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to wrap in a successful result (optional).
|
|
18
|
+
* @returns A `Result` instance with the value.
|
|
19
|
+
*/
|
|
20
|
+
static ok<T>(value: T): Result<T, never>;
|
|
21
|
+
static ok(): Result<void, never>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a failed `Result` containing the provided error.
|
|
24
|
+
*
|
|
25
|
+
* @param error - The error to wrap in a failed result.
|
|
26
|
+
* @returns A `Result` instance with the error.
|
|
27
|
+
*/
|
|
28
|
+
static fail<E>(error: E): Result<never, E>;
|
|
29
|
+
/**
|
|
30
|
+
* Checks whether the result is successful.
|
|
31
|
+
*
|
|
32
|
+
* @returns `true` if the result is `ok`, otherwise `false`.
|
|
33
|
+
* Acts as a type guard to narrow the type to a successful result.
|
|
34
|
+
*/
|
|
35
|
+
isOk(): this is {
|
|
36
|
+
_value: TValue;
|
|
37
|
+
} & Result<TValue, TError>;
|
|
38
|
+
/**
|
|
39
|
+
* Checks whether the result is a failure.
|
|
40
|
+
*
|
|
41
|
+
* @returns `true` if the result is `fail`, otherwise `false`.
|
|
42
|
+
* Acts as a type guard to narrow the type to a failed result.
|
|
43
|
+
*/
|
|
44
|
+
isFail(): this is {
|
|
45
|
+
_error: TError;
|
|
46
|
+
} & Result<TValue, TError>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the value inside a successful result.
|
|
49
|
+
*
|
|
50
|
+
* @throws If the result is a failure.
|
|
51
|
+
* @returns The success value.
|
|
52
|
+
*/
|
|
53
|
+
get value(): TValue;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the error inside a failed result.
|
|
56
|
+
*
|
|
57
|
+
* @throws If the result is successful.
|
|
58
|
+
* @returns The error value.
|
|
59
|
+
*/
|
|
60
|
+
get error(): TError;
|
|
61
|
+
/**
|
|
62
|
+
* Transforms the success value using the provided mapping function.
|
|
63
|
+
*
|
|
64
|
+
* @template U - The type of the new success value.
|
|
65
|
+
* @param fn - Function to apply to the value if the result is successful.
|
|
66
|
+
* @returns A new `Result` containing the mapped value, or the original error if failed.
|
|
67
|
+
*/
|
|
68
|
+
map<U>(fn: (value: TValue) => U): Result<U, TError>;
|
|
69
|
+
/**
|
|
70
|
+
* Transforms the error value using the provided mapping function.
|
|
71
|
+
*
|
|
72
|
+
* @template F - The type of the new error.
|
|
73
|
+
* @param fn - Function to apply to the error if the result is a failure.
|
|
74
|
+
* @returns A new `Result` containing the original value or the mapped error.
|
|
75
|
+
*/
|
|
76
|
+
mapError<F>(fn: (error: TError) => F): Result<TValue, F>;
|
|
77
|
+
/**
|
|
78
|
+
* Chains another `Result`-producing function onto this result.
|
|
79
|
+
* If this result is successful, the function is applied to the value.
|
|
80
|
+
* If this result is a failure, the original error is returned.
|
|
81
|
+
*
|
|
82
|
+
* @template U - The type of the next success value.
|
|
83
|
+
* @param fn - A function that takes the current value and returns another `Result`.
|
|
84
|
+
* @returns A new `Result` from applying the function or the original failure.
|
|
85
|
+
*/
|
|
86
|
+
flatMap<U>(fn: (value: TValue) => Result<U, TError>): Result<U, TError>;
|
|
87
|
+
/**
|
|
88
|
+
* Pattern-matches the result to handle both success and failure cases.
|
|
89
|
+
*
|
|
90
|
+
* @template U - The return type of both match functions.
|
|
91
|
+
* @param handlers - An object containing `ok` and `fail` handlers.
|
|
92
|
+
* @returns The return value from the corresponding handler.
|
|
93
|
+
*/
|
|
94
|
+
match<U>(handlers: {
|
|
95
|
+
ok: (value: TValue) => U;
|
|
96
|
+
fail: (error: TError) => U;
|
|
97
|
+
}): U;
|
|
98
|
+
}
|
|
99
|
+
export declare namespace Result {
|
|
100
|
+
type UnwrapResult<T> = Awaited<T> extends Result<infer Ok, any> ? Ok : never;
|
|
101
|
+
type UnwrapError<T> = Awaited<T> extends Result<any, infer Err> ? Err : never;
|
|
102
|
+
}
|
package/api/Result.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A container type that represents either a successful result (`ok`) or a failure (`fail`).
|
|
3
|
+
* Inspired by functional programming constructs like `Either` or `Result` in other languages.
|
|
4
|
+
*
|
|
5
|
+
* @template TValue - The type of the success value.
|
|
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.");
|
|
67
|
+
}
|
|
68
|
+
return this._value;
|
|
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.");
|
|
80
|
+
}
|
|
81
|
+
return this._error;
|
|
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));
|
|
94
|
+
}
|
|
95
|
+
return Result.fail(this._error);
|
|
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));
|
|
108
|
+
}
|
|
109
|
+
return Result.ok(this._value);
|
|
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);
|
|
124
|
+
}
|
|
125
|
+
return Result.fail(this._error);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Pattern-matches the result to handle both success and failure cases.
|
|
130
|
+
*
|
|
131
|
+
* @template U - The return type of both match functions.
|
|
132
|
+
* @param handlers - An object containing `ok` and `fail` handlers.
|
|
133
|
+
* @returns The return value from the corresponding handler.
|
|
134
|
+
*/
|
|
135
|
+
match(handlers) {
|
|
136
|
+
if (this.isOk()) {
|
|
137
|
+
return handlers.ok(this._value);
|
|
138
|
+
}
|
|
139
|
+
return handlers.fail(this._error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//# sourceMappingURL=Result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","constructor","isOk","value","error","_isOk","_value","_error","ok","fail","undefined","isFail","console","Error","map","fn","mapError","flatMap","match","handlers"],"sources":["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"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,MAAM,CAAyB;EAKhCC,WAAWA,CAACC,IAAa,EAAEC,KAAc,EAAEC,KAAc,EAAE;IAC/D,IAAI,CAACC,KAAK,GAAGH,IAAI;IACjB,IAAI,CAACI,MAAM,GAAGH,KAAK;IACnB,IAAI,CAACI,MAAM,GAAGH,KAAK;EACvB;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;;EAGI,OAAcI,EAAEA,CAAIL,KAAS,EAA2B;IACpD,OAAO,IAAIH,MAAM,CAAkB,IAAI,EAAEG,KAAK,CAAC;EACnD;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACI,OAAcM,IAAIA,CAAIL,KAAQ,EAAoB;IAC9C,OAAO,IAAIJ,MAAM,CAAW,KAAK,EAAEU,SAAS,EAAEN,KAAK,CAAC;EACxD;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACWF,IAAIA,CAAA,EAAwD;IAC/D,OAAO,IAAI,CAACG,KAAK;EACrB;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACWM,MAAMA,CAAA,EAAwD;IACjE,OAAO,CAAC,IAAI,CAACN,KAAK;EACtB;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACI,IAAWF,KAAKA,CAAA,EAAW;IACvB,IAAI,CAAC,IAAI,CAACE,KAAK,EAAE;MACbO,OAAO,CAACR,KAAK,CAAC,IAAI,CAACA,KAAK,CAAC;MACzB,MAAM,IAAIS,KAAK,CAAC,0CAA0C,CAAC;IAC/D;IAEA,OAAO,IAAI,CAACP,MAAM;EACtB;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACI,IAAWF,KAAKA,CAAA,EAAW;IACvB,IAAI,IAAI,CAACC,KAAK,EAAE;MACZ,MAAM,IAAIQ,KAAK,CAAC,8CAA8C,CAAC;IACnE;IAEA,OAAO,IAAI,CAACN,MAAM;EACtB;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACWO,GAAGA,CAAIC,EAAwB,EAAqB;IACvD,IAAI,IAAI,CAACb,IAAI,CAAC,CAAC,EAAE;MACb,OAAOF,MAAM,CAACQ,EAAE,CAACO,EAAE,CAAC,IAAI,CAACT,MAAgB,CAAC,CAAC;IAC/C;IAEA,OAAON,MAAM,CAACS,IAAI,CAAC,IAAI,CAACF,MAAgB,CAAC;EAC7C;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACWS,QAAQA,CAAID,EAAwB,EAAqB;IAC5D,IAAI,IAAI,CAACJ,MAAM,CAAC,CAAC,EAAE;MACf,OAAOX,MAAM,CAACS,IAAI,CAACM,EAAE,CAAC,IAAI,CAACR,MAAgB,CAAC,CAAC;IACjD;IAEA,OAAOP,MAAM,CAACQ,EAAE,CAAC,IAAI,CAACF,MAAgB,CAAC;EAC3C;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACWW,OAAOA,CAAIF,EAAwC,EAAqB;IAC3E,IAAI,IAAI,CAACb,IAAI,CAAC,CAAC,EAAE;MACb,OAAOa,EAAE,CAAC,IAAI,CAACT,MAAgB,CAAC;IACpC;IAEA,OAAON,MAAM,CAACS,IAAI,CAAC,IAAI,CAACF,MAAgB,CAAC;EAC7C;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;EACWW,KAAKA,CAAIC,QAAkE,EAAK;IACnF,IAAI,IAAI,CAACjB,IAAI,CAAC,CAAC,EAAE;MACb,OAAOiB,QAAQ,CAACX,EAAE,CAAC,IAAI,CAACF,MAAgB,CAAC;IAC7C;IAEA,OAAOa,QAAQ,CAACV,IAAI,CAAC,IAAI,CAACF,MAAgB,CAAC;EAC/C;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Result } from "./Result.js";
|
|
2
|
+
export declare class ResultAsync<TValue, TError = never> {
|
|
3
|
+
private readonly promise;
|
|
4
|
+
constructor(promise: Promise<Result<TValue, TError>>);
|
|
5
|
+
static from<T, E>(fn: () => Promise<Result<T, E>>): ResultAsync<T, E>;
|
|
6
|
+
static ok<T>(value: T): ResultAsync<T, never>;
|
|
7
|
+
static fail<E>(error: E): ResultAsync<never, E>;
|
|
8
|
+
unwrap(): Promise<Result<TValue, TError>>;
|
|
9
|
+
mapAsync<U>(fn: (value: TValue) => U | Promise<U>): ResultAsync<U, TError>;
|
|
10
|
+
mapErrorAsync<F>(fn: (error: TError) => F | Promise<F>): ResultAsync<TValue, F>;
|
|
11
|
+
flatMapAsync<U>(fn: (value: TValue) => ResultAsync<U, TError>): ResultAsync<U, TError>;
|
|
12
|
+
match<U>(handlers: {
|
|
13
|
+
ok: (value: TValue) => U;
|
|
14
|
+
fail: (error: TError) => U;
|
|
15
|
+
}): Promise<U>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Result } from "./Result.js";
|
|
2
|
+
export class ResultAsync {
|
|
3
|
+
constructor(promise) {
|
|
4
|
+
this.promise = promise;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Wrap a function returning a Promise<Result<T, E>>.
|
|
8
|
+
static from(fn) {
|
|
9
|
+
return new ResultAsync(fn());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Wrap a successful value.
|
|
13
|
+
static ok(value) {
|
|
14
|
+
return new ResultAsync(Promise.resolve(Result.ok(value)));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Wrap a failure.
|
|
18
|
+
static fail(error) {
|
|
19
|
+
return new ResultAsync(Promise.resolve(Result.fail(error)));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Await the wrapped result.
|
|
23
|
+
async unwrap() {
|
|
24
|
+
return this.promise;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Transform the success value.
|
|
28
|
+
mapAsync(fn) {
|
|
29
|
+
const newPromise = this.promise.then(async res => {
|
|
30
|
+
if (res.isOk()) {
|
|
31
|
+
return Result.ok(await fn(res.value));
|
|
32
|
+
}
|
|
33
|
+
return Result.fail(res.error);
|
|
34
|
+
});
|
|
35
|
+
return new ResultAsync(newPromise);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Transform the error value.
|
|
39
|
+
mapErrorAsync(fn) {
|
|
40
|
+
const newPromise = this.promise.then(async res => {
|
|
41
|
+
if (res.isFail()) {
|
|
42
|
+
return Result.fail(await fn(res.error));
|
|
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);
|
|
65
|
+
}
|
|
66
|
+
return handlers.fail(result.error);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=ResultAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Result","ResultAsync","constructor","promise","from","fn","ok","value","Promise","resolve","fail","error","unwrap","mapAsync","newPromise","then","res","isOk","mapErrorAsync","isFail","flatMapAsync","match","handlers","result"],"sources":["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"],"mappings":"AAAA,SAASA,MAAM;AAEf,OAAO,MAAMC,WAAW,CAAyB;EAC7CC,WAAWA,CAAkBC,OAAwC,EAAE;IAAA,KAA1CA,OAAwC,GAAxCA,OAAwC;EAAG;;EAExE;EACA,OAAcC,IAAIA,CAAOC,EAA+B,EAAqB;IACzE,OAAO,IAAIJ,WAAW,CAACI,EAAE,CAAC,CAAC,CAAC;EAChC;;EAEA;EACA,OAAcC,EAAEA,CAAIC,KAAQ,EAAyB;IACjD,OAAO,IAAIN,WAAW,CAACO,OAAO,CAACC,OAAO,CAACT,MAAM,CAACM,EAAE,CAACC,KAAK,CAAC,CAAC,CAAC;EAC7D;;EAEA;EACA,OAAcG,IAAIA,CAAIC,KAAQ,EAAyB;IACnD,OAAO,IAAIV,WAAW,CAACO,OAAO,CAACC,OAAO,CAACT,MAAM,CAACU,IAAI,CAACC,KAAK,CAAC,CAAC,CAAC;EAC/D;;EAEA;EACA,MAAaC,MAAMA,CAAA,EAAoC;IACnD,OAAO,IAAI,CAACT,OAAO;EACvB;;EAEA;EACOU,QAAQA,CAAIR,EAAqC,EAA0B;IAC9E,MAAMS,UAAU,GAAG,IAAI,CAACX,OAAO,CAACY,IAAI,CAAC,MAAMC,GAAG,IAAI;MAC9C,IAAIA,GAAG,CAACC,IAAI,CAAC,CAAC,EAAE;QACZ,OAAOjB,MAAM,CAACM,EAAE,CAAC,MAAMD,EAAE,CAACW,GAAG,CAACT,KAAK,CAAC,CAAC;MACzC;MAEA,OAAOP,MAAM,CAACU,IAAI,CAACM,GAAG,CAACL,KAAK,CAAC;IACjC,CAAC,CAAC;IAEF,OAAO,IAAIV,WAAW,CAACa,UAAU,CAAC;EACtC;;EAEA;EACOI,aAAaA,CAAIb,EAAqC,EAA0B;IACnF,MAAMS,UAAU,GAAG,IAAI,CAACX,OAAO,CAACY,IAAI,CAAC,MAAMC,GAAG,IAAI;MAC9C,IAAIA,GAAG,CAACG,MAAM,CAAC,CAAC,EAAE;QACd,OAAOnB,MAAM,CAACU,IAAI,CAAC,MAAML,EAAE,CAACW,GAAG,CAACL,KAAK,CAAC,CAAC;MAC3C;MAEA,OAAOX,MAAM,CAACM,EAAE,CAACU,GAAG,CAACT,KAAK,CAAC;IAC/B,CAAC,CAAC;IAEF,OAAO,IAAIN,WAAW,CAACa,UAAU,CAAC;EACtC;;EAEA;EACOM,YAAYA,CAAIf,EAA6C,EAA0B;IAC1F,MAAMS,UAAU,GAAG,IAAI,CAACX,OAAO,CAACY,IAAI,CAAC,MAAMC,GAAG,IAAI;MAC9C,IAAIA,GAAG,CAACG,MAAM,CAAC,CAAC,EAAE;QACd,OAAOnB,MAAM,CAACU,IAAI,CAACM,GAAG,CAACL,KAAK,CAAC;MACjC;MAEA,OAAO,MAAMN,EAAE,CAACW,GAAG,CAACT,KAAK,CAAC,CAACK,MAAM,CAAC,CAAC;IACvC,CAAC,CAAC;IAEF,OAAO,IAAIX,WAAW,CAACa,UAAU,CAAC;EACtC;;EAEA;EACA,MAAaO,KAAKA,CAAIC,QAGrB,EAAc;IACX,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACX,MAAM,CAAC,CAAC;IAElC,IAAIW,MAAM,CAACN,IAAI,CAAC,CAAC,EAAE;MACf,OAAOK,QAAQ,CAAChB,EAAE,CAACiB,MAAM,CAAChB,KAAK,CAAC;IACpC;IAEA,OAAOe,QAAQ,CAACZ,IAAI,CAACa,MAAM,CAACZ,KAAK,CAAC;EACtC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
export interface FeatureDefinition<TRegister> {
|
|
3
|
+
name: string;
|
|
4
|
+
register(container: Container, context?: TRegister): void;
|
|
5
|
+
}
|
|
6
|
+
export declare function createFeature<TRegister>(def: {
|
|
7
|
+
name: string;
|
|
8
|
+
register(container: Container, context?: TRegister): void;
|
|
9
|
+
}): FeatureDefinition<TRegister>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","def","feature","name","register","Reflect","defineMetadata"],"sources":["createFeature.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\n\nexport interface FeatureDefinition<TRegister> {\n name: string;\n register(container: Container, context?: TRegister): void;\n}\n\nexport function createFeature<TRegister>(def: {\n name: string;\n register(container: Container, context?: TRegister): void;\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"],"mappings":"AAOA,OAAO,SAASA,aAAaA,CAAYC,GAGxC,EAAgC;EAC7B,MAAMC,OAAO,GAAG;IACZC,IAAI,EAAEF,GAAG,CAACE,IAAI;IACdC,QAAQ,EAAEH,GAAG,CAACG;EAClB,CAAC;EAEDC,OAAO,CAACC,cAAc,CAAC,eAAe,EAAE,IAAI,EAAEJ,OAAO,CAAC;EAEtD,OAAOA,OAAO;AAClB","ignoreList":[]}
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDecorator, createImplementation } from "@webiny/di";
|
|
2
|
+
export { createFeature } from "./createFeature.js";
|
|
3
|
+
export { createAbstraction } from "../createAbstraction.js";
|
|
4
|
+
export { Result } from "./Result.js";
|
|
5
|
+
export { ResultAsync } from "./ResultAsync.js";
|
|
6
|
+
export { BaseError } from "./BaseError.js";
|
package/api/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createDecorator, createImplementation } from "@webiny/di";
|
|
2
|
+
export { createFeature } from "./createFeature.js";
|
|
3
|
+
export { createAbstraction } from "../createAbstraction.js";
|
|
4
|
+
export { Result } from "./Result.js";
|
|
5
|
+
export { ResultAsync } from "./ResultAsync.js";
|
|
6
|
+
export { BaseError } from "./BaseError.js";
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Abstraction","createAbstraction","name"],"sources":["createAbstraction.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\nexport function createAbstraction<T>(name: string) {\n return new Abstraction<T>(name);\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,YAAY;AAExC,OAAO,SAASC,iBAAiBA,CAAIC,IAAY,EAAE;EAC/C,OAAO,IAAIF,WAAW,CAAIE,IAAI,CAAC;AACnC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createFeature, createAbstraction, BaseError } from "../admin/index.js";
|
package/exports/admin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createFeature, createAbstraction, Result, BaseError } from "../api/index.js";
|
package/exports/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/feature",
|
|
3
|
+
"description": "A small utility library to build application features in a Webiny project.",
|
|
4
|
+
"version": "0.0.0-unstable.61c048f412",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
9
|
+
},
|
|
10
|
+
"author": "Webiny LTD",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"exports": {
|
|
13
|
+
"./api": "./api/index.js",
|
|
14
|
+
"./admin": "./admin/index.js",
|
|
15
|
+
"./*": "./*"
|
|
16
|
+
},
|
|
17
|
+
"webiny": {
|
|
18
|
+
"exports": {
|
|
19
|
+
"./api/index.ts": {
|
|
20
|
+
"exportPath": "./api",
|
|
21
|
+
"namedExports": [
|
|
22
|
+
"createFeature",
|
|
23
|
+
"createAbstraction",
|
|
24
|
+
"BaseError",
|
|
25
|
+
"Result",
|
|
26
|
+
"ResultAsync"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"./admin/index.ts": {
|
|
30
|
+
"exportPath": "./admin",
|
|
31
|
+
"namedExports": [
|
|
32
|
+
"createFeature",
|
|
33
|
+
"createAbstraction",
|
|
34
|
+
"BaseError"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@webiny/di": "0.2.3"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@webiny/build-tools": "0.0.0-unstable.61c048f412",
|
|
44
|
+
"typescript": "5.9.3"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"directory": "dist"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "61c048f412d6b4aa70c1d105aab21e3fa69730f3"
|
|
51
|
+
}
|