@kellanjs/actioncraft 0.2.0 → 0.3.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.
- package/README.md +47 -68
- package/dist/classes/{action-builder.d.ts → builder.d.ts} +20 -16
- package/dist/classes/{action-builder.js → builder.js} +34 -25
- package/dist/classes/builder.js.map +1 -0
- package/dist/classes/executor/executor.d.ts +3 -3
- package/dist/classes/executor/executor.js +1 -1
- package/dist/classes/executor/executor.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/standard-schema.js +2 -1
- package/dist/standard-schema.js.map +1 -1
- package/package.json +16 -13
- package/dist/actioncraft-error.d.ts +0 -23
- package/dist/actioncraft-error.js +0 -60
- package/dist/actioncraft-error.js.map +0 -1
- package/dist/actioncraft-prev.d.ts +0 -93
- package/dist/actioncraft-prev.js +0 -387
- package/dist/actioncraft-prev.js.map +0 -1
- package/dist/actioncraft.d.ts +0 -143
- package/dist/actioncraft.js +0 -613
- package/dist/actioncraft.js.map +0 -1
- package/dist/api.d.ts +0 -49
- package/dist/api.js +0 -84
- package/dist/api.js.map +0 -1
- package/dist/classes/action-builder.js.map +0 -1
- package/dist/classes/craft-builder.d.ts +0 -66
- package/dist/classes/craft-builder.js +0 -129
- package/dist/classes/craft-builder.js.map +0 -1
- package/dist/classes/crafter.d.ts +0 -66
- package/dist/classes/crafter.js +0 -129
- package/dist/classes/crafter.js.map +0 -1
- package/dist/classes/executor.d.ts +0 -64
- package/dist/classes/executor.js +0 -354
- package/dist/classes/executor.js.map +0 -1
- package/dist/core/callbacks.d.ts +0 -6
- package/dist/core/callbacks.js +0 -20
- package/dist/core/callbacks.js.map +0 -1
- package/dist/core/errors.d.ts +0 -28
- package/dist/core/errors.js +0 -101
- package/dist/core/errors.js.map +0 -1
- package/dist/core/logging.d.ts +0 -6
- package/dist/core/logging.js +0 -8
- package/dist/core/logging.js.map +0 -1
- package/dist/core/transformation.d.ts +0 -17
- package/dist/core/transformation.js +0 -43
- package/dist/core/transformation.js.map +0 -1
- package/dist/core/validation.d.ts +0 -16
- package/dist/core/validation.js +0 -70
- package/dist/core/validation.js.map +0 -1
- package/dist/craft.d.ts +0 -29
- package/dist/craft.js +0 -62
- package/dist/craft.js.map +0 -1
- package/dist/error.d.ts +0 -31
- package/dist/error.js +0 -71
- package/dist/error.js.map +0 -1
- package/dist/initial.d.ts +0 -14
- package/dist/initial.js +0 -47
- package/dist/initial.js.map +0 -1
- package/dist/types/config.d.ts +0 -84
- package/dist/types/config.js +0 -2
- package/dist/types/config.js.map +0 -1
- package/dist/types/crafter.d.ts +0 -87
- package/dist/types/crafter.js +0 -2
- package/dist/types/crafter.js.map +0 -1
package/dist/api.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ActionBuilder } from "./classes/action-builder.js";
|
|
2
|
-
import { Crafter } from "./classes/crafter.js";
|
|
3
|
-
import type { CraftedAction } from "./types/actions.js";
|
|
4
|
-
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "./types/crafter.js";
|
|
5
|
-
/**
|
|
6
|
-
* Represents the function that the user passes to `craft()` in order to build an action.
|
|
7
|
-
*/
|
|
8
|
-
type CraftFn<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> = (crafter: Crafter<CrafterConfig, Record<string, never>, Record<string, never>, Record<string, never>, unknown>) => Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData> | Promise<Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData>>;
|
|
9
|
-
/**
|
|
10
|
-
* One of two entry points to the Actioncraft system.
|
|
11
|
-
* It provides you with an empty Crafter instance on which you can call any of the fluent
|
|
12
|
-
* Crafter methods to configure and define your action.
|
|
13
|
-
*
|
|
14
|
-
* Example Usage:
|
|
15
|
-
* ```ts
|
|
16
|
-
* const myAction = craft(async (action) => {
|
|
17
|
-
* return action
|
|
18
|
-
* .config(...)
|
|
19
|
-
* .schemas(...)
|
|
20
|
-
* .errors(...)
|
|
21
|
-
* .handler(...)
|
|
22
|
-
* .callbacks(...)
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
27
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
28
|
-
*/
|
|
29
|
-
export declare function craft<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData>(craftFn: CraftFn<TConfig, TSchemas, TErrors, TCallbacks, TData>): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
30
|
-
/**
|
|
31
|
-
* One of two entry points to the Actioncraft system.
|
|
32
|
-
* Creates a new ActionBuilder instance for the fluent API that ends with craft().
|
|
33
|
-
* This provides an alternative syntax for building your server actions.
|
|
34
|
-
*
|
|
35
|
-
* Example Usage:
|
|
36
|
-
* ```ts
|
|
37
|
-
* const myAction = action()
|
|
38
|
-
* .config(...)
|
|
39
|
-
* .schemas(...)
|
|
40
|
-
* .errors(...)
|
|
41
|
-
* .handler(...)
|
|
42
|
-
* .callbacks(...)
|
|
43
|
-
* .craft();
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @returns A new ActionBuilder instance to start building your action.
|
|
47
|
-
*/
|
|
48
|
-
export declare function action(): ActionBuilder<Record<string, never>, Record<string, never>, Record<string, never>, Record<string, never>, unknown>;
|
|
49
|
-
export {};
|
package/dist/api.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ActionBuilder } from "./classes/action-builder.js";
|
|
2
|
-
import { Crafter } from "./classes/crafter.js";
|
|
3
|
-
import { Executor } from "./classes/executor.js";
|
|
4
|
-
/**
|
|
5
|
-
* One of two entry points to the Actioncraft system.
|
|
6
|
-
* It provides you with an empty Crafter instance on which you can call any of the fluent
|
|
7
|
-
* Crafter methods to configure and define your action.
|
|
8
|
-
*
|
|
9
|
-
* Example Usage:
|
|
10
|
-
* ```ts
|
|
11
|
-
* const myAction = craft(async (action) => {
|
|
12
|
-
* return action
|
|
13
|
-
* .config(...)
|
|
14
|
-
* .schemas(...)
|
|
15
|
-
* .errors(...)
|
|
16
|
-
* .handler(...)
|
|
17
|
-
* .callbacks(...)
|
|
18
|
-
* });
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
22
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
23
|
-
*/
|
|
24
|
-
export function craft(craftFn) {
|
|
25
|
-
const crafter = craftFn(new Crafter({}, {}, {}, {}, undefined));
|
|
26
|
-
// Handle async crafter functions
|
|
27
|
-
if (crafter instanceof Promise) {
|
|
28
|
-
return _craftAsync(crafter);
|
|
29
|
-
}
|
|
30
|
-
// Handle sync crafter functions
|
|
31
|
-
const executor = new Executor(crafter);
|
|
32
|
-
const craftedAction = executor.craft();
|
|
33
|
-
return craftedAction;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Internal helper function to handle async craft functions.
|
|
37
|
-
* Encapsulates the logic for creating async actions and preserving metadata.
|
|
38
|
-
*/
|
|
39
|
-
function _craftAsync(crafterPromise) {
|
|
40
|
-
// Resolve the crafter once and cache the resulting action to ensure consistent IDs
|
|
41
|
-
const actionPromise = crafterPromise.then((resolvedCrafter) => {
|
|
42
|
-
const executor = new Executor(resolvedCrafter);
|
|
43
|
-
return executor.craft();
|
|
44
|
-
});
|
|
45
|
-
// For async craft functions, we need to return an async action
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
const asyncAction = (async (...args) => {
|
|
48
|
-
// Wait for the cached action to be ready
|
|
49
|
-
const craftedAction = await actionPromise;
|
|
50
|
-
// Call the action with the user's arguments
|
|
51
|
-
return craftedAction(...args);
|
|
52
|
-
});
|
|
53
|
-
// We need to preserve the config and ID for the initial() function to work
|
|
54
|
-
// We'll use the same cached action to ensure consistent metadata
|
|
55
|
-
actionPromise.then((craftedAction) => {
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
asyncAction.__ac_config = craftedAction.__ac_config;
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
-
asyncAction.__ac_id = craftedAction.__ac_id;
|
|
60
|
-
});
|
|
61
|
-
return asyncAction;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* One of two entry points to the Actioncraft system.
|
|
65
|
-
* Creates a new ActionBuilder instance for the fluent API that ends with craft().
|
|
66
|
-
* This provides an alternative syntax for building your server actions.
|
|
67
|
-
*
|
|
68
|
-
* Example Usage:
|
|
69
|
-
* ```ts
|
|
70
|
-
* const myAction = action()
|
|
71
|
-
* .config(...)
|
|
72
|
-
* .schemas(...)
|
|
73
|
-
* .errors(...)
|
|
74
|
-
* .handler(...)
|
|
75
|
-
* .callbacks(...)
|
|
76
|
-
* .craft();
|
|
77
|
-
* ```
|
|
78
|
-
*
|
|
79
|
-
* @returns A new ActionBuilder instance to start building your action.
|
|
80
|
-
*/
|
|
81
|
-
export function action() {
|
|
82
|
-
return new ActionBuilder({}, {}, {}, {}, undefined);
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAkCjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,KAAK,CAOnB,OAA+D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M,CACJ,MAAkB;QAQlB,OAAO,IAAI,aAAa,CACtB,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,QAAQ,EACb,MAAM,EACN,EAA2B,EAC3B,SAAS,CACV,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,OAAO,CAKL,EAAO;QAQP,OAAO,IAAI,aAAa,CACtB,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,OAAO,EACZ,EAA2B,EAC3B,EAAoE,CACrE,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,SAAS,CACP,SAAwB;QAExB,OAAO,IAAI,aAAa,CACtB,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,OAAO,EACZ,SAAS,EACT,IAAI,CAAC,QAAQ,CACd,CAAC;IACJ,CAAC;IAED,6EAA6E;IAC7E,iDAAiD;IACjD,6EAA6E;IAE7E;;;OAGG;IACH,KAAK;QACH,wEAAwE;QACxE,MAAM,OAAO,GAAG,IAAI,YAAY,CAC9B,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,QAAQ,CACd,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AAED,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM;IAOpB,OAAO,IAAI,aAAa,CACtB,EAA2B,EAC3B,EAA2B,EAC3B,EAA2B,EAC3B,EAA2B,EAC3B,SAAS,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { Handler, InferDataFromHandler, HandlerParams, CraftedAction } from "../types/actions.js";
|
|
2
|
-
import type { Config, Schemas, Errors, Callbacks } from "../types/builder.js";
|
|
3
|
-
import { INTERNAL, type CrafterInternals } from "./internal.js";
|
|
4
|
-
export declare class CraftBuilder<TConfig extends Config, TSchemas extends Schemas, TErrors extends Errors, TCallbacks extends Callbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
5
|
-
private readonly _config;
|
|
6
|
-
private readonly _schemas;
|
|
7
|
-
private readonly _errors;
|
|
8
|
-
private readonly _callbacks;
|
|
9
|
-
private readonly _handler?;
|
|
10
|
-
constructor(config: TConfig, schemas: TSchemas, errors: TErrors, callbacks: TCallbacks, handler?: Handler<TConfig, TSchemas, TErrors, TData>);
|
|
11
|
-
/**
|
|
12
|
-
* Defines configuration options for the action.
|
|
13
|
-
* Resets previously defined handler and callbacks.
|
|
14
|
-
*/
|
|
15
|
-
config<TNewConfig extends Config>(config: TNewConfig): CraftBuilder<TNewConfig, TSchemas, TErrors, Record<string, never>, unknown>;
|
|
16
|
-
/**
|
|
17
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
18
|
-
* Resets previously defined handler and callbacks.
|
|
19
|
-
*/
|
|
20
|
-
schemas<TNewSchemas extends Schemas>(schemas: TNewSchemas): CraftBuilder<TConfig, TNewSchemas, TErrors, Record<string, never>, unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Defines error functions for returning typed errors from the handler.
|
|
23
|
-
* Resets previously defined handler and callbacks.
|
|
24
|
-
*/
|
|
25
|
-
errors<const TNewErrors extends Errors>(errors: TNewErrors): CraftBuilder<TConfig, TSchemas, TNewErrors, Record<string, never>, unknown>;
|
|
26
|
-
/**
|
|
27
|
-
* Defines the handler function containing the server action's business logic.
|
|
28
|
-
* Resets previously defined callbacks.
|
|
29
|
-
*/
|
|
30
|
-
handler<TFn extends (params: HandlerParams<TConfig, TSchemas, TErrors, TData>) => Promise<unknown>>(fn: TFn): CraftBuilder<TConfig, TSchemas, TErrors, Record<string, never>, InferDataFromHandler<TFn>>;
|
|
31
|
-
/**
|
|
32
|
-
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
33
|
-
* Must be called after handler() for correct type inference.
|
|
34
|
-
*/
|
|
35
|
-
callbacks<TNewCallbacks extends Callbacks<TConfig, TSchemas, TErrors, TData>>(callbacks: TNewCallbacks): CraftBuilder<TConfig, TSchemas, TErrors, TNewCallbacks, TData>;
|
|
36
|
-
/**
|
|
37
|
-
* @returns Internal properties of the CraftBuilder instance
|
|
38
|
-
*/
|
|
39
|
-
[INTERNAL](): CrafterInternals<TConfig, TSchemas, TErrors, TCallbacks, TData>;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Represents the function that the user passes to `craft()` in order to build an action.
|
|
43
|
-
*/
|
|
44
|
-
type CraftFn<TConfig extends Config, TSchemas extends Schemas, TErrors extends Errors, TCallbacks extends Callbacks<TConfig, TSchemas, TErrors, TData>, TData> = (builder: CraftBuilder<Config, Record<string, never>, Record<string, never>, Record<string, never>, unknown>) => CraftBuilder<TConfig, TSchemas, TErrors, TCallbacks, TData> | Promise<CraftBuilder<TConfig, TSchemas, TErrors, TCallbacks, TData>>;
|
|
45
|
-
/**
|
|
46
|
-
* One of two entry points to the Actioncraft system.
|
|
47
|
-
* It provides you with an empty CraftBuilder instance on which you can call any of the fluent
|
|
48
|
-
* CraftBuilder methods to configure and define your action.
|
|
49
|
-
*
|
|
50
|
-
* Example Usage:
|
|
51
|
-
* ```ts
|
|
52
|
-
* const myAction = craft(async (action) => {
|
|
53
|
-
* return action
|
|
54
|
-
* .config(...)
|
|
55
|
-
* .schemas(...)
|
|
56
|
-
* .errors(...)
|
|
57
|
-
* .handler(...)
|
|
58
|
-
* .callbacks(...)
|
|
59
|
-
* });
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
63
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
64
|
-
*/
|
|
65
|
-
export declare function craft<TConfig extends Config, TSchemas extends Schemas, TErrors extends Errors, TCallbacks extends Callbacks<TConfig, TSchemas, TErrors, TData>, TData>(craftFn: CraftFn<TConfig, TSchemas, TErrors, TCallbacks, TData>): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
66
|
-
export {};
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Executor } from "./executor/executor.js";
|
|
2
|
-
import { INTERNAL } from "./internal.js";
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// CRAFT BUILDER CLASS - Configure and define your action
|
|
5
|
-
// ============================================================================
|
|
6
|
-
export class CraftBuilder {
|
|
7
|
-
_config;
|
|
8
|
-
_schemas;
|
|
9
|
-
_errors;
|
|
10
|
-
_callbacks;
|
|
11
|
-
_handler;
|
|
12
|
-
constructor(config, schemas, errors, callbacks, handler) {
|
|
13
|
-
this._config = config;
|
|
14
|
-
this._schemas = schemas;
|
|
15
|
-
this._errors = errors;
|
|
16
|
-
this._callbacks = callbacks;
|
|
17
|
-
this._handler = handler;
|
|
18
|
-
}
|
|
19
|
-
// --------------------------------------------------------------------------
|
|
20
|
-
// FLUENT API METHODS
|
|
21
|
-
// --------------------------------------------------------------------------
|
|
22
|
-
/**
|
|
23
|
-
* Defines configuration options for the action.
|
|
24
|
-
* Resets previously defined handler and callbacks.
|
|
25
|
-
*/
|
|
26
|
-
config(config) {
|
|
27
|
-
return new CraftBuilder(config, this._schemas, this._errors, {}, undefined);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
31
|
-
* Resets previously defined handler and callbacks.
|
|
32
|
-
*/
|
|
33
|
-
schemas(schemas) {
|
|
34
|
-
return new CraftBuilder(this._config, schemas, this._errors, {}, undefined);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Defines error functions for returning typed errors from the handler.
|
|
38
|
-
* Resets previously defined handler and callbacks.
|
|
39
|
-
*/
|
|
40
|
-
errors(errors) {
|
|
41
|
-
return new CraftBuilder(this._config, this._schemas, errors, {}, undefined);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Defines the handler function containing the server action's business logic.
|
|
45
|
-
* Resets previously defined callbacks.
|
|
46
|
-
*/
|
|
47
|
-
handler(fn) {
|
|
48
|
-
return new CraftBuilder(this._config, this._schemas, this._errors, {}, fn);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
52
|
-
* Must be called after handler() for correct type inference.
|
|
53
|
-
*/
|
|
54
|
-
callbacks(callbacks) {
|
|
55
|
-
return new CraftBuilder(this._config, this._schemas, this._errors, callbacks, this._handler);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @returns Internal properties of the CraftBuilder instance
|
|
59
|
-
*/
|
|
60
|
-
[INTERNAL]() {
|
|
61
|
-
return {
|
|
62
|
-
config: this._config,
|
|
63
|
-
schemas: this._schemas,
|
|
64
|
-
errors: this._errors,
|
|
65
|
-
callbacks: this._callbacks,
|
|
66
|
-
handler: this._handler,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* One of two entry points to the Actioncraft system.
|
|
72
|
-
* It provides you with an empty CraftBuilder instance on which you can call any of the fluent
|
|
73
|
-
* CraftBuilder methods to configure and define your action.
|
|
74
|
-
*
|
|
75
|
-
* Example Usage:
|
|
76
|
-
* ```ts
|
|
77
|
-
* const myAction = craft(async (action) => {
|
|
78
|
-
* return action
|
|
79
|
-
* .config(...)
|
|
80
|
-
* .schemas(...)
|
|
81
|
-
* .errors(...)
|
|
82
|
-
* .handler(...)
|
|
83
|
-
* .callbacks(...)
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
88
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
89
|
-
*/
|
|
90
|
-
export function craft(craftFn) {
|
|
91
|
-
const builder = craftFn(new CraftBuilder({}, {}, {}, {}, undefined));
|
|
92
|
-
// Handle async builder functions
|
|
93
|
-
if (builder instanceof Promise) {
|
|
94
|
-
return _craftAsync(builder);
|
|
95
|
-
}
|
|
96
|
-
// Handle sync builder functions
|
|
97
|
-
const executor = new Executor(builder);
|
|
98
|
-
const craftedAction = executor.craft();
|
|
99
|
-
return craftedAction;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Internal helper function to handle async craft functions.
|
|
103
|
-
* Encapsulates the logic for creating async actions and preserving metadata.
|
|
104
|
-
*/
|
|
105
|
-
function _craftAsync(builderPromise) {
|
|
106
|
-
// Resolve the builder once and cache the resulting action to ensure consistent IDs
|
|
107
|
-
const actionPromise = builderPromise.then((resolvedBuilder) => {
|
|
108
|
-
const executor = new Executor(resolvedBuilder);
|
|
109
|
-
return executor.craft();
|
|
110
|
-
});
|
|
111
|
-
// For async craft functions, we need to return an async action
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
-
const asyncAction = (async (...args) => {
|
|
114
|
-
// Wait for the cached action to be ready
|
|
115
|
-
const craftedAction = await actionPromise;
|
|
116
|
-
// Call the action with the user's arguments
|
|
117
|
-
return craftedAction(...args);
|
|
118
|
-
});
|
|
119
|
-
// We need to preserve the config and ID for the initial() function to work
|
|
120
|
-
// We'll use the same cached action to ensure consistent metadata
|
|
121
|
-
actionPromise.then((craftedAction) => {
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
asyncAction.__ac_config = craftedAction.__ac_config;
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
-
asyncAction.__ac_id = craftedAction.__ac_id;
|
|
126
|
-
});
|
|
127
|
-
return asyncAction;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=craft-builder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"craft-builder.js","sourceRoot":"","sources":["../../src/classes/craft-builder.ts"],"names":[],"mappings":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K,EAAE,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,+DAA+D;IAC/D,8DAA8D;IAC9D,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;QAC5C,yCAAyC;QACzC,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC;QAE1C,4CAA4C;QAC5C,OAAO,aAAa,CAAC,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC,CAAqD,CAAC;IAEvD,2EAA2E;IAC3E,iEAAiE;IACjE,aAAa,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE;QACnC,8DAA8D;QAC7D,WAAmB,CAAC,WAAW,GAAI,aAAqB,CAAC,WAAW,CAAC;QACtE,8DAA8D;QAC7D,WAAmB,CAAC,OAAO,GAAI,aAAqB,CAAC,OAAO,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import type { Handler, InferDataFromHandler, HandlerParams, CraftedAction } from "../types/actions.js";
|
|
2
|
-
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "../types/crafter.js";
|
|
3
|
-
import { INTERNAL, type CrafterInternals } from "./internal.js";
|
|
4
|
-
export declare class Crafter<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
5
|
-
private readonly _config;
|
|
6
|
-
private readonly _schemas;
|
|
7
|
-
private readonly _errors;
|
|
8
|
-
private readonly _callbacks;
|
|
9
|
-
private readonly _handler?;
|
|
10
|
-
constructor(config: TConfig, schemas: TSchemas, errors: TErrors, callbacks: TCallbacks, handler?: Handler<TConfig, TSchemas, TErrors, TData>);
|
|
11
|
-
/**
|
|
12
|
-
* Defines configuration options for the action.
|
|
13
|
-
* Resets previously defined handler and callbacks.
|
|
14
|
-
*/
|
|
15
|
-
config<TNewConfig extends CrafterConfig>(config: TNewConfig): Crafter<TNewConfig, TSchemas, TErrors, Record<string, never>, unknown>;
|
|
16
|
-
/**
|
|
17
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
18
|
-
* Resets previously defined handler and callbacks.
|
|
19
|
-
*/
|
|
20
|
-
schemas<TNewSchemas extends CrafterSchemas>(schemas: TNewSchemas): Crafter<TConfig, TNewSchemas, TErrors, Record<string, never>, unknown>;
|
|
21
|
-
/**
|
|
22
|
-
* Defines error functions for returning typed errors from the handler.
|
|
23
|
-
* Resets previously defined handler and callbacks.
|
|
24
|
-
*/
|
|
25
|
-
errors<const TNewErrors extends CrafterErrors>(errors: TNewErrors): Crafter<TConfig, TSchemas, TNewErrors, Record<string, never>, unknown>;
|
|
26
|
-
/**
|
|
27
|
-
* Defines the handler function containing the server action's business logic.
|
|
28
|
-
* Resets previously defined callbacks.
|
|
29
|
-
*/
|
|
30
|
-
handler<TFn extends (params: HandlerParams<TConfig, TSchemas, TErrors, TData>) => Promise<unknown>>(fn: TFn): Crafter<TConfig, TSchemas, TErrors, Record<string, never>, InferDataFromHandler<TFn>>;
|
|
31
|
-
/**
|
|
32
|
-
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
33
|
-
* Must be called after handler() for correct type inference.
|
|
34
|
-
*/
|
|
35
|
-
callbacks<TNewCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>>(callbacks: TNewCallbacks): Crafter<TConfig, TSchemas, TErrors, TNewCallbacks, TData>;
|
|
36
|
-
/**
|
|
37
|
-
* @returns Internal properties of the Crafter instance
|
|
38
|
-
*/
|
|
39
|
-
[INTERNAL](): CrafterInternals<TConfig, TSchemas, TErrors, TCallbacks, TData>;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Represents the function that the user passes to `craft()` in order to build an action.
|
|
43
|
-
*/
|
|
44
|
-
type CraftFn<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> = (crafter: Crafter<CrafterConfig, Record<string, never>, Record<string, never>, Record<string, never>, unknown>) => Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData> | Promise<Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData>>;
|
|
45
|
-
/**
|
|
46
|
-
* One of two entry points to the Actioncraft system.
|
|
47
|
-
* It provides you with an empty Crafter instance on which you can call any of the fluent
|
|
48
|
-
* Crafter methods to configure and define your action.
|
|
49
|
-
*
|
|
50
|
-
* Example Usage:
|
|
51
|
-
* ```ts
|
|
52
|
-
* const myAction = craft(async (action) => {
|
|
53
|
-
* return action
|
|
54
|
-
* .config(...)
|
|
55
|
-
* .schemas(...)
|
|
56
|
-
* .errors(...)
|
|
57
|
-
* .handler(...)
|
|
58
|
-
* .callbacks(...)
|
|
59
|
-
* });
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
63
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
64
|
-
*/
|
|
65
|
-
export declare function craft<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData>(craftFn: CraftFn<TConfig, TSchemas, TErrors, TCallbacks, TData>): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
66
|
-
export {};
|
package/dist/classes/crafter.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { Executor } from "./executor/executor.js";
|
|
2
|
-
import { INTERNAL } from "./internal.js";
|
|
3
|
-
// ============================================================================
|
|
4
|
-
// CRAFTER CLASS - Configure and define your action
|
|
5
|
-
// ============================================================================
|
|
6
|
-
export class Crafter {
|
|
7
|
-
_config;
|
|
8
|
-
_schemas;
|
|
9
|
-
_errors;
|
|
10
|
-
_callbacks;
|
|
11
|
-
_handler;
|
|
12
|
-
constructor(config, schemas, errors, callbacks, handler) {
|
|
13
|
-
this._config = config;
|
|
14
|
-
this._schemas = schemas;
|
|
15
|
-
this._errors = errors;
|
|
16
|
-
this._callbacks = callbacks;
|
|
17
|
-
this._handler = handler;
|
|
18
|
-
}
|
|
19
|
-
// --------------------------------------------------------------------------
|
|
20
|
-
// FLUENT API METHODS
|
|
21
|
-
// --------------------------------------------------------------------------
|
|
22
|
-
/**
|
|
23
|
-
* Defines configuration options for the action.
|
|
24
|
-
* Resets previously defined handler and callbacks.
|
|
25
|
-
*/
|
|
26
|
-
config(config) {
|
|
27
|
-
return new Crafter(config, this._schemas, this._errors, {}, undefined);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
31
|
-
* Resets previously defined handler and callbacks.
|
|
32
|
-
*/
|
|
33
|
-
schemas(schemas) {
|
|
34
|
-
return new Crafter(this._config, schemas, this._errors, {}, undefined);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Defines error functions for returning typed errors from the handler.
|
|
38
|
-
* Resets previously defined handler and callbacks.
|
|
39
|
-
*/
|
|
40
|
-
errors(errors) {
|
|
41
|
-
return new Crafter(this._config, this._schemas, errors, {}, undefined);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Defines the handler function containing the server action's business logic.
|
|
45
|
-
* Resets previously defined callbacks.
|
|
46
|
-
*/
|
|
47
|
-
handler(fn) {
|
|
48
|
-
return new Crafter(this._config, this._schemas, this._errors, {}, fn);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
52
|
-
* Must be called after handler() for correct type inference.
|
|
53
|
-
*/
|
|
54
|
-
callbacks(callbacks) {
|
|
55
|
-
return new Crafter(this._config, this._schemas, this._errors, callbacks, this._handler);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* @returns Internal properties of the Crafter instance
|
|
59
|
-
*/
|
|
60
|
-
[INTERNAL]() {
|
|
61
|
-
return {
|
|
62
|
-
config: this._config,
|
|
63
|
-
schemas: this._schemas,
|
|
64
|
-
errors: this._errors,
|
|
65
|
-
callbacks: this._callbacks,
|
|
66
|
-
handler: this._handler,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* One of two entry points to the Actioncraft system.
|
|
72
|
-
* It provides you with an empty Crafter instance on which you can call any of the fluent
|
|
73
|
-
* Crafter methods to configure and define your action.
|
|
74
|
-
*
|
|
75
|
-
* Example Usage:
|
|
76
|
-
* ```ts
|
|
77
|
-
* const myAction = craft(async (action) => {
|
|
78
|
-
* return action
|
|
79
|
-
* .config(...)
|
|
80
|
-
* .schemas(...)
|
|
81
|
-
* .errors(...)
|
|
82
|
-
* .handler(...)
|
|
83
|
-
* .callbacks(...)
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
88
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
89
|
-
*/
|
|
90
|
-
export function craft(craftFn) {
|
|
91
|
-
const crafter = craftFn(new Crafter({}, {}, {}, {}, undefined));
|
|
92
|
-
// Handle async crafter functions
|
|
93
|
-
if (crafter instanceof Promise) {
|
|
94
|
-
return _craftAsync(crafter);
|
|
95
|
-
}
|
|
96
|
-
// Handle sync crafter functions
|
|
97
|
-
const executor = new Executor(crafter);
|
|
98
|
-
const craftedAction = executor.craft();
|
|
99
|
-
return craftedAction;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Internal helper function to handle async craft functions.
|
|
103
|
-
* Encapsulates the logic for creating async actions and preserving metadata.
|
|
104
|
-
*/
|
|
105
|
-
function _craftAsync(crafterPromise) {
|
|
106
|
-
// Resolve the crafter once and cache the resulting action to ensure consistent IDs
|
|
107
|
-
const actionPromise = crafterPromise.then((resolvedCrafter) => {
|
|
108
|
-
const executor = new Executor(resolvedCrafter);
|
|
109
|
-
return executor.craft();
|
|
110
|
-
});
|
|
111
|
-
// For async craft functions, we need to return an async action
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
113
|
-
const asyncAction = (async (...args) => {
|
|
114
|
-
// Wait for the cached action to be ready
|
|
115
|
-
const craftedAction = await actionPromise;
|
|
116
|
-
// Call the action with the user's arguments
|
|
117
|
-
return craftedAction(...args);
|
|
118
|
-
});
|
|
119
|
-
// We need to preserve the config and ID for the initial() function to work
|
|
120
|
-
// We'll use the same cached action to ensure consistent metadata
|
|
121
|
-
actionPromise.then((craftedAction) => {
|
|
122
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
asyncAction.__ac_config = craftedAction.__ac_config;
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
-
asyncAction.__ac_id = craftedAction.__ac_id;
|
|
126
|
-
});
|
|
127
|
-
return asyncAction;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=crafter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crafter.js","sourceRoot":"","sources":["../../src/classes/crafter.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAEhE,+EAA+E;AAC/E,mDAAmD;AACnD,+EAA+E;AAE/E,MAAM,OAAO,OAAO;IAOD,OAAO,CAAU;IACjB,QAAQ,CAAW;IACnB,OAAO,CAAU;IACjB,UAAU,CAAa;IACvB,QAAQ,CAA8C;IAEvE,YACE,MAAe,EACf,OAAiB,EACjB,MAAe,EACf,SAAqB,EACrB,OAAoD;QAEpD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,G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,aAAqB,CAAC,OAAO,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { CraftedAction } from "../types/actions.js";
|
|
2
|
-
import type { CrafterConfig, CrafterSchemas, CrafterErrors, CrafterCallbacks } from "../types/crafter.js";
|
|
3
|
-
import type { Crafter } from "./crafter.js";
|
|
4
|
-
export declare class Executor<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TCallbacks extends CrafterCallbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
5
|
-
private readonly _config;
|
|
6
|
-
private readonly _schemas;
|
|
7
|
-
private readonly _errors;
|
|
8
|
-
private readonly _callbacks;
|
|
9
|
-
private readonly _handler?;
|
|
10
|
-
private _actionId?;
|
|
11
|
-
constructor(crafter: Crafter<TConfig, TSchemas, TErrors, TCallbacks, TData>);
|
|
12
|
-
/**
|
|
13
|
-
* Builds and returns the final executable server action.
|
|
14
|
-
*/
|
|
15
|
-
craft(): CraftedAction<TConfig, TSchemas, TErrors, TData>;
|
|
16
|
-
/**
|
|
17
|
-
* Generates a unique identifier for this action instance.
|
|
18
|
-
*/
|
|
19
|
-
private _generateActionId;
|
|
20
|
-
/**
|
|
21
|
-
* Orchestrates action execution (validation, business logic, callbacks, and result formatting.)
|
|
22
|
-
*/
|
|
23
|
-
private _runAction;
|
|
24
|
-
/**
|
|
25
|
-
* Extracts bind arguments, previous state, and input from raw action arguments.
|
|
26
|
-
*/
|
|
27
|
-
private _extractActionArgs;
|
|
28
|
-
/**
|
|
29
|
-
* Transforms internal Result objects to client-facing action result format.
|
|
30
|
-
*/
|
|
31
|
-
private _toActionResult;
|
|
32
|
-
/**
|
|
33
|
-
* Handles uncaught exceptions during action execution.
|
|
34
|
-
*/
|
|
35
|
-
private _handleThrownError;
|
|
36
|
-
/**
|
|
37
|
-
* Validates input using the shared helper.
|
|
38
|
-
*/
|
|
39
|
-
private _validateInput;
|
|
40
|
-
/**
|
|
41
|
-
* Validates bound arguments using the configured bind schemas.
|
|
42
|
-
*/
|
|
43
|
-
private _validateBindArgs;
|
|
44
|
-
/**
|
|
45
|
-
* Validates output data using the configured output schema.
|
|
46
|
-
*/
|
|
47
|
-
private _validateOutput;
|
|
48
|
-
/**
|
|
49
|
-
* Executes the onStart callback if defined.
|
|
50
|
-
*/
|
|
51
|
-
private _executeOnStartCallback;
|
|
52
|
-
/**
|
|
53
|
-
* Executes result-based lifecycle callbacks (onSuccess, onError, onSettled).
|
|
54
|
-
*/
|
|
55
|
-
private _executeResultCallbacks;
|
|
56
|
-
/**
|
|
57
|
-
* Ensures a Result object has the correct action ID.
|
|
58
|
-
*/
|
|
59
|
-
private _ensureResultActionId;
|
|
60
|
-
/**
|
|
61
|
-
* Creates error functions that return a Result object when called by the action handler.
|
|
62
|
-
*/
|
|
63
|
-
private _buildErrorFunctions;
|
|
64
|
-
}
|