@kellanjs/actioncraft 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/actioncraft.d.ts +89 -0
- package/dist/actioncraft.js +344 -0
- package/dist/actioncraft.js.map +1 -0
- package/dist/core/callbacks.d.ts +6 -0
- package/dist/core/callbacks.js +20 -0
- package/dist/core/callbacks.js.map +1 -0
- package/dist/core/errors.d.ts +28 -0
- package/dist/core/errors.js +101 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/logging.d.ts +6 -0
- package/dist/core/logging.js +8 -0
- package/dist/core/logging.js.map +1 -0
- package/dist/core/transformation.d.ts +17 -0
- package/dist/core/transformation.js +43 -0
- package/dist/core/transformation.js.map +1 -0
- package/dist/core/validation.d.ts +16 -0
- package/dist/core/validation.js +70 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/error.d.ts +16 -0
- package/dist/error.js +22 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/standard-schema.d.ts +71 -0
- package/dist/standard-schema.js +16 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/types/actions.d.ts +120 -0
- package/dist/types/actions.js +2 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/config.d.ts +80 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/errors.d.ts +207 -0
- package/dist/types/errors.js +21 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/inference.d.ts +20 -0
- package/dist/types/inference.js +2 -0
- package/dist/types/inference.js.map +1 -0
- package/dist/types/result.d.ts +72 -0
- package/dist/types/result.js +62 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/schemas.d.ts +33 -0
- package/dist/types/schemas.js +2 -0
- package/dist/types/schemas.js.map +1 -0
- package/dist/types/shared.d.ts +75 -0
- package/dist/types/shared.js +2 -0
- package/dist/types/shared.js.map +1 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +44 -0
- package/dist/utils.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/core/logging.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,GAAG,CACjB,MAA+B,EAC/B,KAAuB,EACvB,OAAe,EACf,OAAiB;IAEjB,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,MAAM,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACzB,IAAI,EAAE;QAAE,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InferSerializedErrorValues } from "../types/actions.js";
|
|
2
|
+
import type { CrafterSchemas } from "../types/config.js";
|
|
3
|
+
import type { CrafterConfig, CrafterErrors } from "../types/config.js";
|
|
4
|
+
import type { PossibleErrors, AllPossibleErrors } from "../types/errors.js";
|
|
5
|
+
import type { InferRawInput, InferValidatedInput } from "../types/schemas.js";
|
|
6
|
+
/**
|
|
7
|
+
* Converts input to a serializable format for the `values` field in action results.
|
|
8
|
+
*
|
|
9
|
+
* If the input is `FormData`, it is flattened into a plain object so that it can
|
|
10
|
+
* be safely JSON-serialized. Otherwise, the input is returned as-is.
|
|
11
|
+
*/
|
|
12
|
+
export declare function serializeRawInput<TSchemas extends CrafterSchemas>(input: InferRawInput<TSchemas> | InferValidatedInput<TSchemas> | undefined): InferSerializedErrorValues<TSchemas>;
|
|
13
|
+
/**
|
|
14
|
+
* Converts internal error objects into client-facing errors, hiding
|
|
15
|
+
* implementation details that should not leak outside the server.
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertToClientError<TErrors extends CrafterErrors, TConfig extends CrafterConfig, TSchemas extends CrafterSchemas>(internalError: AllPossibleErrors<TErrors, TConfig, TSchemas>): PossibleErrors<TErrors, TConfig, TSchemas>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { INTERNAL_ERROR_TYPES } from "../types/errors.js";
|
|
2
|
+
import { UNHANDLED_ERROR } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts input to a serializable format for the `values` field in action results.
|
|
5
|
+
*
|
|
6
|
+
* If the input is `FormData`, it is flattened into a plain object so that it can
|
|
7
|
+
* be safely JSON-serialized. Otherwise, the input is returned as-is.
|
|
8
|
+
*/
|
|
9
|
+
export function serializeRawInput(input) {
|
|
10
|
+
if (input instanceof FormData) {
|
|
11
|
+
const valueMap = new Map();
|
|
12
|
+
for (const [key, value] of input.entries()) {
|
|
13
|
+
// Ignore React server-action meta-fields
|
|
14
|
+
if (key.startsWith("$ACTION"))
|
|
15
|
+
continue;
|
|
16
|
+
const stringValue = typeof value === "string" ? value : value.name || "[File]";
|
|
17
|
+
if (!valueMap.has(key))
|
|
18
|
+
valueMap.set(key, []);
|
|
19
|
+
valueMap.get(key).push(stringValue);
|
|
20
|
+
}
|
|
21
|
+
// Collapse single-item arrays
|
|
22
|
+
const serialized = {};
|
|
23
|
+
for (const [key, values] of valueMap.entries()) {
|
|
24
|
+
serialized[key] = values.length === 1 ? values[0] : values;
|
|
25
|
+
}
|
|
26
|
+
return serialized;
|
|
27
|
+
}
|
|
28
|
+
// Non-FormData inputs are assumed to already be serialisable
|
|
29
|
+
return input;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts internal error objects into client-facing errors, hiding
|
|
33
|
+
* implementation details that should not leak outside the server.
|
|
34
|
+
*/
|
|
35
|
+
export function convertToClientError(internalError) {
|
|
36
|
+
if (internalError.type === INTERNAL_ERROR_TYPES.IMPLICIT_RETURN ||
|
|
37
|
+
internalError.type === INTERNAL_ERROR_TYPES.OUTPUT_VALIDATION ||
|
|
38
|
+
internalError.type === INTERNAL_ERROR_TYPES.INTERNAL_LOGIC) {
|
|
39
|
+
return UNHANDLED_ERROR;
|
|
40
|
+
}
|
|
41
|
+
return internalError;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=transformation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation.js","sourceRoot":"","sources":["../../src/core/transformation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAA0E;IAE1E,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAoB,CAAC;QAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC3C,yCAAyC;YACzC,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;gBAAE,SAAS;YAExC,MAAM,WAAW,GACf,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,QAAQ,CAAC;YAE7D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC9C,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACvC,CAAC;QAED,8BAA8B;QAC9B,MAAM,UAAU,GAAsC,EAAE,CAAC;QACzD,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;YAC/C,UAAU,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,MAAM,CAAC;QAC9D,CAAC;QAED,OAAO,UAAkD,CAAC;IAC5D,CAAC;IAED,6DAA6D;IAC7D,OAAO,KAA6C,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAKlC,aAA4D;IAE5D,IACE,aAAa,CAAC,IAAI,KAAK,oBAAoB,CAAC,eAAe;QAC3D,aAAa,CAAC,IAAI,KAAK,oBAAoB,CAAC,iBAAiB;QAC7D,aAAa,CAAC,IAAI,KAAK,oBAAoB,CAAC,cAAc,EAC1D,CAAC;QACD,OAAO,eAA6D,CAAC;IACvE,CAAC;IACD,OAAO,aAA2D,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CrafterConfig, CrafterSchemas, CrafterErrors } from "../types/config.js";
|
|
2
|
+
import type { AllPossibleErrors } from "../types/errors.js";
|
|
3
|
+
import type { Result } from "../types/result.js";
|
|
4
|
+
import type { InferValidatedInput, InferRawInput, InferValidatedBindArgs, InferRawBindArgs } from "../types/schemas.js";
|
|
5
|
+
/**
|
|
6
|
+
* Validate input using the configured input schema.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateInput<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors>(schemas: TSchemas, config: TConfig, rawInput: InferRawInput<TSchemas> | undefined): Promise<Result<InferValidatedInput<TSchemas>, AllPossibleErrors<TErrors, TConfig, TSchemas>>>;
|
|
9
|
+
/**
|
|
10
|
+
* Validate bound arguments using configured bind schemas.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateBindArgs<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors>(schemas: TSchemas, config: TConfig, bindArgs: InferRawBindArgs<TSchemas>): Promise<Result<InferValidatedBindArgs<TSchemas>, AllPossibleErrors<TErrors, TConfig, TSchemas>>>;
|
|
13
|
+
/**
|
|
14
|
+
* Validate action output using configured output schema.
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateOutput<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData>(schemas: TSchemas, config: TConfig, data: TData): Promise<Result<TData, AllPossibleErrors<TErrors, TConfig, TSchemas>>>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { standardParse } from "../standard-schema.js";
|
|
2
|
+
import { INTERNAL_ERROR_TYPES, EXTERNAL_ERROR_TYPES } from "../types/errors.js";
|
|
3
|
+
import { ok, err } from "../types/result.js";
|
|
4
|
+
import { createValidationError, createInternalLogicError, formatValidationIssues, } from "./errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Validate input using the configured input schema.
|
|
7
|
+
*/
|
|
8
|
+
export async function validateInput(schemas, config, rawInput) {
|
|
9
|
+
if (!schemas.inputSchema) {
|
|
10
|
+
return ok(undefined);
|
|
11
|
+
}
|
|
12
|
+
const result = await standardParse(schemas.inputSchema, rawInput);
|
|
13
|
+
if (Array.isArray(result.issues) && result.issues.length > 0) {
|
|
14
|
+
const format = config.validationErrorFormat ?? "flattened";
|
|
15
|
+
const baseError = formatValidationIssues(result.issues, format);
|
|
16
|
+
const inputValidationError = createValidationError(EXTERNAL_ERROR_TYPES.INPUT_VALIDATION, "Input validation failed", baseError);
|
|
17
|
+
return err(inputValidationError);
|
|
18
|
+
}
|
|
19
|
+
if (!result.issues && "value" in result) {
|
|
20
|
+
return ok(result.value);
|
|
21
|
+
}
|
|
22
|
+
// Should never happen
|
|
23
|
+
const logicErr = createInternalLogicError("Unexpected validation state in input validation: neither success nor failure");
|
|
24
|
+
return err(logicErr);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate bound arguments using configured bind schemas.
|
|
28
|
+
*/
|
|
29
|
+
export async function validateBindArgs(schemas, config, bindArgs) {
|
|
30
|
+
if (!schemas.bindSchemas) {
|
|
31
|
+
return ok([]);
|
|
32
|
+
}
|
|
33
|
+
const validated = [];
|
|
34
|
+
for (let i = 0; i < schemas.bindSchemas.length; i++) {
|
|
35
|
+
const schema = schemas.bindSchemas[i];
|
|
36
|
+
const arg = bindArgs[i];
|
|
37
|
+
const result = await standardParse(schema, arg);
|
|
38
|
+
if (Array.isArray(result.issues) && result.issues.length > 0) {
|
|
39
|
+
const format = config.validationErrorFormat ?? "flattened";
|
|
40
|
+
const baseError = formatValidationIssues(result.issues, format);
|
|
41
|
+
const bindError = createValidationError(EXTERNAL_ERROR_TYPES.BIND_ARGS_VALIDATION, "Bind arguments validation failed", baseError);
|
|
42
|
+
return err(bindError);
|
|
43
|
+
}
|
|
44
|
+
if ("value" in result) {
|
|
45
|
+
validated.push(result.value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return ok(validated);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate action output using configured output schema.
|
|
52
|
+
*/
|
|
53
|
+
export async function validateOutput(schemas, config, data) {
|
|
54
|
+
if (!schemas.outputSchema) {
|
|
55
|
+
return ok(data);
|
|
56
|
+
}
|
|
57
|
+
const result = await standardParse(schemas.outputSchema, data);
|
|
58
|
+
if (Array.isArray(result.issues) && result.issues.length > 0) {
|
|
59
|
+
const format = config.validationErrorFormat ?? "flattened";
|
|
60
|
+
const baseError = formatValidationIssues(result.issues, format);
|
|
61
|
+
const outputError = createValidationError(INTERNAL_ERROR_TYPES.OUTPUT_VALIDATION, "Output validation failed", baseError);
|
|
62
|
+
return err(outputError);
|
|
63
|
+
}
|
|
64
|
+
if (!result.issues && "value" in result) {
|
|
65
|
+
return ok(result.value);
|
|
66
|
+
}
|
|
67
|
+
const logicErr = createInternalLogicError("Unexpected validation state in output validation: neither success nor failure");
|
|
68
|
+
return err(logicErr);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAMtD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAQhF,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAO7C,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAKjC,OAAiB,EACjB,MAAe,EACf,QAA6C;IAO7C,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC,SAA0C,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAElE,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,MAAM,MAAM,GAAG,MAAM,CAAC,qBAAqB,IAAI,WAAW,CAAC;QAC3D,MAAM,SAAS,GAAG,sBAAsB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEhE,MAAM,oBAAoB,GAAG,qBAAqB,CAGhD,oBAAoB,CAAC,gBAAgB,EACrC,yBAAyB,EACzB,SAAS,CACV,CAAC;QAEF,OAAO,GAAG,CAAC,oBAAoB,CAG9B,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAsC,CAAC,CAAC;IAC3D,CAAC;IAED,sBAAsB;IACtB,MAAM,QAAQ,GAAG,wBAAwB,CACvC,8EAA8E,CAC/E,CAAC;IACF,OAAO,GAAG,CAAC,QAAQ,CAGlB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAKpC,OAAiB,EACjB,MAAe,EACf,QAAoC;IAOpC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC,EAAsC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,SAAS,GAAc,EAAE,CAAC;IAEhC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QACvC,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEhD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC7D,MAAM,MAAM,GAAG,MAAM,CAAC,qBAAqB,IAAI,WAAW,CAAC;YAC3D,MAAM,SAAS,GAAG,sBAAsB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAEhE,MAAM,SAAS,GAAG,qBAAqB,CAGrC,oBAAoB,CAAC,oBAAoB,EACzC,kCAAkC,EAClC,SAAS,CACV,CAAC;YAEF,OAAO,GAAG,CAAC,SAAS,CAGnB,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;YACtB,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC,SAA6C,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAMlC,OAAiB,EACjB,MAAe,EACf,IAAW;IAEX,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAE/D,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,MAAM,MAAM,GAAG,MAAM,CAAC,qBAAqB,IAAI,WAAW,CAAC;QAC3D,MAAM,SAAS,GAAG,sBAAsB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAEhE,MAAM,WAAW,GAAG,qBAAqB,CAGvC,oBAAoB,CAAC,iBAAiB,EACtC,0BAA0B,EAC1B,SAAS,CACV,CAAC;QAEF,OAAO,GAAG,CAAC,WAAW,CAGrB,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAc,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,QAAQ,GAAG,wBAAwB,CACvC,+EAA+E,CAChF,CAAC;IACF,OAAO,GAAG,CAAC,QAAQ,CAGlB,CAAC;AACJ,CAAC"}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CraftedAction } from "./types/actions.js";
|
|
2
|
+
import type { BaseError } from "./types/errors.js";
|
|
3
|
+
import type { InferErrors } from "./types/inference.js";
|
|
4
|
+
/**
|
|
5
|
+
* Error wrapper that provides standard Error semantics while preserving
|
|
6
|
+
* the original ActionCraft error data in the cause property.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ActionCraftError<TErrorData extends BaseError = BaseError> extends Error {
|
|
9
|
+
readonly cause: TErrorData;
|
|
10
|
+
constructor(errorData: TErrorData);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Type guard to check if an error is an ActionCraftError with the action's error types.
|
|
14
|
+
* The action parameter is used purely for type inference.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isActionCraftError<TAction extends CraftedAction<any, any, any, any>>(error: unknown, _action: TAction): error is ActionCraftError<InferErrors<TAction>>;
|
package/dist/error.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error wrapper that provides standard Error semantics while preserving
|
|
3
|
+
* the original ActionCraft error data in the cause property.
|
|
4
|
+
*/
|
|
5
|
+
export class ActionCraftError extends Error {
|
|
6
|
+
cause;
|
|
7
|
+
constructor(errorData) {
|
|
8
|
+
super(`ActionCraft Error: ${errorData.type}${"message" in errorData ? ` - ${errorData.message}` : ""}`);
|
|
9
|
+
this.name = "ActionCraftError";
|
|
10
|
+
this.cause = errorData;
|
|
11
|
+
// Ensure proper prototype chain for instanceof checks
|
|
12
|
+
Object.setPrototypeOf(this, ActionCraftError.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type guard to check if an error is an ActionCraftError with the action's error types.
|
|
17
|
+
* The action parameter is used purely for type inference.
|
|
18
|
+
*/
|
|
19
|
+
export function isActionCraftError(error, _action) {
|
|
20
|
+
return error instanceof ActionCraftError;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,gBAEX,SAAQ,KAAK;IACY,KAAK,CAAa;IAE3C,YAAY,SAAqB;QAC/B,KAAK,CACH,sBAAsB,SAAS,CAAC,IAAI,GAClC,SAAS,IAAI,SAAS,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EACvD,EAAE,CACH,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QAEvB,sDAAsD;QACtD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAIhC,KAAc,EACd,OAAgB;IAEhB,OAAO,KAAK,YAAY,gBAAgB,CAAC;AAC3C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { create, initial } from "./actioncraft.js";
|
|
2
|
+
export { unwrap, throwable } from "./utils.js";
|
|
3
|
+
export { ActionCraftError, isActionCraftError } from "./error.js";
|
|
4
|
+
export type { Result, Ok, Err } from "./types/result.js";
|
|
5
|
+
export { isOk, isErr, ok, err } from "./types/result.js";
|
|
6
|
+
export type { InferInput, InferResult, InferData, InferErrors, } from "./types/inference.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// PUBLIC API EXPORTS
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// Core Functions
|
|
5
|
+
export { create, initial } from "./actioncraft.js";
|
|
6
|
+
export { unwrap, throwable } from "./utils.js";
|
|
7
|
+
export { ActionCraftError, isActionCraftError } from "./error.js";
|
|
8
|
+
export { isOk, isErr, ok, err } from "./types/result.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,iBAAiB;AACjB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAIlE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** The Standard Schema interface. */
|
|
2
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
|
+
/** The Standard Schema properties. */
|
|
4
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace StandardSchemaV1 {
|
|
7
|
+
/** The Standard Schema properties interface. */
|
|
8
|
+
interface Props<Input = unknown, Output = Input> {
|
|
9
|
+
/** The version number of the standard. */
|
|
10
|
+
readonly version: 1;
|
|
11
|
+
/** The vendor name of the schema library. */
|
|
12
|
+
readonly vendor: string;
|
|
13
|
+
/** Validates unknown input values. */
|
|
14
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The result interface of the validate function. */
|
|
19
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
20
|
+
/** The result interface if validation succeeds. */
|
|
21
|
+
interface SuccessResult<Output> {
|
|
22
|
+
/** The typed output value. */
|
|
23
|
+
readonly value: Output;
|
|
24
|
+
/** The non-existent issues. */
|
|
25
|
+
readonly issues?: undefined;
|
|
26
|
+
}
|
|
27
|
+
/** The result interface if validation fails. */
|
|
28
|
+
interface FailureResult {
|
|
29
|
+
/** The issues of failed validation. */
|
|
30
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
31
|
+
}
|
|
32
|
+
/** The issue interface of the failure output. */
|
|
33
|
+
interface Issue {
|
|
34
|
+
/** The error message of the issue. */
|
|
35
|
+
readonly message: string;
|
|
36
|
+
/** The path of the issue, if any. */
|
|
37
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
38
|
+
}
|
|
39
|
+
/** The path segment interface of the issue. */
|
|
40
|
+
interface PathSegment {
|
|
41
|
+
/** The key representing a path segment. */
|
|
42
|
+
readonly key: PropertyKey;
|
|
43
|
+
}
|
|
44
|
+
/** The Standard Schema types interface. */
|
|
45
|
+
interface Types<Input = unknown, Output = Input> {
|
|
46
|
+
/** The input type of the schema. */
|
|
47
|
+
readonly input: Input;
|
|
48
|
+
/** The output type of the schema. */
|
|
49
|
+
readonly output: Output;
|
|
50
|
+
}
|
|
51
|
+
/** Infers the input type of a Standard Schema. */
|
|
52
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
53
|
+
/** Infers the output type of a Standard Schema. */
|
|
54
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
55
|
+
}
|
|
56
|
+
/** Infer the input type of a Standard Schema, or a default type if the schema is undefined. */
|
|
57
|
+
export type InferInputOrDefault<MaybeSchema, Default> = MaybeSchema extends StandardSchemaV1 ? StandardSchemaV1.InferInput<MaybeSchema> : Default;
|
|
58
|
+
/** Infer the output type of a Standard Schema, or a default type if the schema is undefined. */
|
|
59
|
+
export type InferOutputOrDefault<MaybeSchema, Default> = MaybeSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<MaybeSchema> : Default;
|
|
60
|
+
/** Infer the input type of an array of Standard Schemas. */
|
|
61
|
+
export type InferInputArray<Schemas extends readonly StandardSchemaV1[]> = {
|
|
62
|
+
[K in keyof Schemas]: StandardSchemaV1.InferInput<Schemas[K]>;
|
|
63
|
+
};
|
|
64
|
+
/** Infer the output type of an array of Standard Schemas. */
|
|
65
|
+
export type InferOutputArray<Schemas extends readonly StandardSchemaV1[]> = {
|
|
66
|
+
[K in keyof Schemas]: StandardSchemaV1.InferOutput<Schemas[K]>;
|
|
67
|
+
};
|
|
68
|
+
/** Helper function to validate input using a Standard Schema. */
|
|
69
|
+
export declare function standardParse<Output>(schema: StandardSchemaV1<unknown, Output>, value: unknown): Promise<StandardSchemaV1.Result<Output>>;
|
|
70
|
+
/** Type guard to check if a value is a Standard Schema. */
|
|
71
|
+
export declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// RUNTIME HELPERS
|
|
3
|
+
// ============================================================================
|
|
4
|
+
/** Helper function to validate input using a Standard Schema. */
|
|
5
|
+
export async function standardParse(schema, value) {
|
|
6
|
+
return schema["~standard"].validate(value);
|
|
7
|
+
}
|
|
8
|
+
/** Type guard to check if a value is a Standard Schema. */
|
|
9
|
+
export function isStandardSchema(value) {
|
|
10
|
+
return (typeof value === "object" &&
|
|
11
|
+
value !== null &&
|
|
12
|
+
"~standard" in value &&
|
|
13
|
+
typeof value["~standard"] === "object" &&
|
|
14
|
+
value["~standard"].version === 1);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=standard-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-schema.js","sourceRoot":"","sources":["../src/standard-schema.ts"],"names":[],"mappings":"AAkGA,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAyC,EACzC,KAAc;IAEd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,WAAW,IAAI,KAAK;QACpB,OAAQ,KAA0B,CAAC,WAAW,CAAC,KAAK,QAAQ;QAC3D,KAA0B,CAAC,WAAW,CAAC,CAAC,OAAO,KAAK,CAAC,CACvD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "../standard-schema.js";
|
|
2
|
+
import type { CrafterConfig, CrafterSchemas, CrafterErrors } from "./config.js";
|
|
3
|
+
import type { ErrorFunctions, InferUserDefinedErrorTypes, PossibleErrors } from "./errors.js";
|
|
4
|
+
import type { Result, Ok, Err } from "./result.js";
|
|
5
|
+
import type { InferValidatedInput, InferRawBindArgs, InferValidatedBindArgs, InferRawInputTuple } from "./schemas.js";
|
|
6
|
+
import type { ApiResult, ActionImplMetadata, StatefulApiResult } from "./shared.js";
|
|
7
|
+
/**
|
|
8
|
+
* Extracts the success data type from an action implementation function.
|
|
9
|
+
*/
|
|
10
|
+
export type InferDataFromActionImpl<TFn> = TFn extends (...args: any[]) => any ? Awaited<ReturnType<TFn>> extends infer TReturn ? TReturn extends Ok<infer U> ? U : TReturn extends Err<unknown> | undefined ? never : TReturn : never : never;
|
|
11
|
+
/**
|
|
12
|
+
* Parameters passed to action implementation functions.
|
|
13
|
+
*/
|
|
14
|
+
export type ActionImplParams<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = {
|
|
15
|
+
/** Validated input data after schema validation */
|
|
16
|
+
input: InferValidatedInput<TSchemas>;
|
|
17
|
+
/** Validated bind arguments after schema validation */
|
|
18
|
+
bindArgs: InferValidatedBindArgs<TSchemas>;
|
|
19
|
+
/** Helper functions for returning typed errors */
|
|
20
|
+
errors: ErrorFunctions<TErrors>;
|
|
21
|
+
/** Action metadata for debugging and logging */
|
|
22
|
+
metadata: ActionImplMetadata<TConfig, TSchemas, TErrors, TData>;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Action implementation function signature.
|
|
26
|
+
* Can return ok(data), errors.yourError(), raw data, or null.
|
|
27
|
+
* Returning undefined is treated as an error.
|
|
28
|
+
*/
|
|
29
|
+
export type ActionImpl<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = (params: ActionImplParams<TConfig, TSchemas, TErrors, TData>) => Promise<Result<TData, InferUserDefinedErrorTypes<TErrors>> | TData | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Arguments that the action implementation accepts.
|
|
32
|
+
* Differs based on useActionState configuration.
|
|
33
|
+
*/
|
|
34
|
+
export type InferActionImplArgs<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = TConfig extends {
|
|
35
|
+
useActionState: true;
|
|
36
|
+
} ? StatefulActionArgs<TConfig, TSchemas, TErrors, TData> : StatelessActionArgs<TSchemas>;
|
|
37
|
+
/**
|
|
38
|
+
* Action compatible with React's useActionState hook.
|
|
39
|
+
*/
|
|
40
|
+
export type StatefulAction<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = (...args: StatefulActionArgs<TConfig, TSchemas, TErrors, TData>) => Promise<InferCraftedActionResult<TConfig, TSchemas, TErrors, TData>>;
|
|
41
|
+
/**
|
|
42
|
+
* Arguments for stateful actions: bind args, previous state, then input.
|
|
43
|
+
*/
|
|
44
|
+
export type StatefulActionArgs<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = [
|
|
45
|
+
...InferRawBindArgs<TSchemas>,
|
|
46
|
+
InferPrevStateArg<TConfig, TSchemas, TErrors, TData>,
|
|
47
|
+
...InferRawInputTuple<TSchemas>
|
|
48
|
+
];
|
|
49
|
+
/**
|
|
50
|
+
* Previous state parameter for useActionState.
|
|
51
|
+
*/
|
|
52
|
+
export type InferPrevStateArg<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = TConfig extends {
|
|
53
|
+
useActionState: true;
|
|
54
|
+
} ? StatefulApiResult<TData, PossibleErrors<TErrors, TConfig, TSchemas>, InferSerializedSuccessValues<TSchemas>, InferSerializedErrorValues<TSchemas>> : never;
|
|
55
|
+
/**
|
|
56
|
+
* Extracts object-like types from a union, excluding primitives
|
|
57
|
+
*/
|
|
58
|
+
type _UnionObjectLike<T> = Extract<T, Record<string, unknown>>;
|
|
59
|
+
/**
|
|
60
|
+
* Excludes iterable types like arrays and FormData
|
|
61
|
+
*/
|
|
62
|
+
type _ExcludeIterable<T> = T extends {
|
|
63
|
+
[Symbol.iterator](): Iterator<unknown>;
|
|
64
|
+
} ? never : T;
|
|
65
|
+
/**
|
|
66
|
+
* Gets plain objects only, excluding arrays and iterables
|
|
67
|
+
*/
|
|
68
|
+
type _PlainObjectLike<T> = _ExcludeIterable<_UnionObjectLike<T>>;
|
|
69
|
+
/**
|
|
70
|
+
* Ensures never types fall back to empty object
|
|
71
|
+
*/
|
|
72
|
+
type _SafePlainObjectLike<T> = [_PlainObjectLike<T>] extends [never] ? Record<string, never> : _PlainObjectLike<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a type is exactly unknown
|
|
75
|
+
*/
|
|
76
|
+
type _IsExactlyUnknown<T> = unknown extends T ? [T] extends [unknown] ? true : false : false;
|
|
77
|
+
/**
|
|
78
|
+
* Converts unknown fields to serialized form values.
|
|
79
|
+
*/
|
|
80
|
+
type _ValuesWithFallback<T> = {
|
|
81
|
+
[K in keyof T]: _IsExactlyUnknown<T[K]> extends true ? string | string[] | undefined : T[K];
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Form values available when an action succeeds.
|
|
85
|
+
*/
|
|
86
|
+
export type InferSerializedSuccessValues<TSchemas extends CrafterSchemas> = TSchemas extends {
|
|
87
|
+
inputSchema: StandardSchemaV1;
|
|
88
|
+
} ? StandardSchemaV1.InferOutput<TSchemas["inputSchema"]> extends Record<string, unknown> ? Record<string, string | string[]> & _ValuesWithFallback<_SafePlainObjectLike<StandardSchemaV1.InferOutput<TSchemas["inputSchema"]>>> : StandardSchemaV1.InferOutput<TSchemas["inputSchema"]> : unknown;
|
|
89
|
+
/**
|
|
90
|
+
* Form values available when an action fails.
|
|
91
|
+
*/
|
|
92
|
+
export type InferSerializedErrorValues<TSchemas extends CrafterSchemas> = TSchemas extends {
|
|
93
|
+
inputSchema: StandardSchemaV1;
|
|
94
|
+
} ? Record<string, string | string[]> & _ValuesWithFallback<_SafePlainObjectLike<StandardSchemaV1.InferInput<TSchemas["inputSchema"]>>> : Record<string, string | string[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Regular server action that doesn't use useActionState.
|
|
97
|
+
*/
|
|
98
|
+
export type StatelessAction<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = (...args: StatelessActionArgs<TSchemas>) => Promise<InferCraftedActionResult<TConfig, TSchemas, TErrors, TData>>;
|
|
99
|
+
/**
|
|
100
|
+
* Arguments for stateless actions: bind args followed by input.
|
|
101
|
+
*/
|
|
102
|
+
export type StatelessActionArgs<TSchemas extends CrafterSchemas> = [
|
|
103
|
+
...InferRawBindArgs<TSchemas>,
|
|
104
|
+
...InferRawInputTuple<TSchemas>
|
|
105
|
+
];
|
|
106
|
+
/**
|
|
107
|
+
* Final action function returned by .craft().
|
|
108
|
+
*/
|
|
109
|
+
export type CraftedAction<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = TConfig extends {
|
|
110
|
+
useActionState: true;
|
|
111
|
+
} ? StatefulAction<TConfig, TSchemas, TErrors, TData> : StatelessAction<TConfig, TSchemas, TErrors, TData>;
|
|
112
|
+
/**
|
|
113
|
+
* Result returned when calling a crafted action.
|
|
114
|
+
*/
|
|
115
|
+
export type InferCraftedActionResult<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = TConfig extends {
|
|
116
|
+
useActionState: true;
|
|
117
|
+
} ? StatefulApiResult<TData, PossibleErrors<TErrors, TConfig, TSchemas>, InferSerializedSuccessValues<TSchemas>, InferSerializedErrorValues<TSchemas>> : TConfig extends {
|
|
118
|
+
resultFormat: "functional";
|
|
119
|
+
} ? Result<TData, PossibleErrors<TErrors, TConfig, TSchemas>> : ApiResult<TData, PossibleErrors<TErrors, TConfig, TSchemas>>;
|
|
120
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/types/actions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "../standard-schema.js";
|
|
2
|
+
import type { InferCraftedActionResult } from "./actions.js";
|
|
3
|
+
import type { AllPossibleErrors, BaseError, ErrorDefinition } from "./errors.js";
|
|
4
|
+
import type { CallbackMetadata } from "./shared.js";
|
|
5
|
+
/**
|
|
6
|
+
* Custom logging interface for ActionCraft.
|
|
7
|
+
*/
|
|
8
|
+
export type CrafterLogger = {
|
|
9
|
+
/** Called when callback functions fail */
|
|
10
|
+
error?: (message: string, error: unknown) => void;
|
|
11
|
+
/** Called when ActionCraft detects internal bugs */
|
|
12
|
+
warn?: (message: string, details?: unknown) => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Configuration options for building actions.
|
|
16
|
+
*/
|
|
17
|
+
export type CrafterConfig = {
|
|
18
|
+
/**
|
|
19
|
+
* Result format returned by actions.
|
|
20
|
+
* "api" returns {success, data/error}, "functional" returns {type, value/error}.
|
|
21
|
+
* Ignored when useActionState is enabled.
|
|
22
|
+
*/
|
|
23
|
+
resultFormat?: "api" | "functional";
|
|
24
|
+
/**
|
|
25
|
+
* Validation error structure.
|
|
26
|
+
* "flattened" returns array of {path, message}, "nested" groups by field.
|
|
27
|
+
*/
|
|
28
|
+
validationErrorFormat?: "flattened" | "nested";
|
|
29
|
+
/**
|
|
30
|
+
* Enables React useActionState compatibility.
|
|
31
|
+
* Action accepts prevState parameter and returns a stateful result.
|
|
32
|
+
*/
|
|
33
|
+
useActionState?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Custom handler for unexpected thrown errors.
|
|
36
|
+
* Transforms exceptions into structured error objects.
|
|
37
|
+
*/
|
|
38
|
+
handleThrownError?: (error: unknown) => BaseError;
|
|
39
|
+
/**
|
|
40
|
+
* Logger for ActionCraft internal events.
|
|
41
|
+
*/
|
|
42
|
+
logger?: CrafterLogger;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Schema definitions for validating inputs and outputs.
|
|
46
|
+
*/
|
|
47
|
+
export type CrafterSchemas = {
|
|
48
|
+
/** Validates input values passed to the action */
|
|
49
|
+
inputSchema?: StandardSchemaV1;
|
|
50
|
+
/** Validates success data returned from the action */
|
|
51
|
+
outputSchema?: StandardSchemaV1;
|
|
52
|
+
/** Array of schemas for validating bound arguments */
|
|
53
|
+
bindSchemas?: readonly StandardSchemaV1[];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Custom error types that actions can return.
|
|
57
|
+
* Each property is a function that creates a typed error object.
|
|
58
|
+
*/
|
|
59
|
+
export type CrafterErrors = Record<string, ErrorDefinition>;
|
|
60
|
+
/**
|
|
61
|
+
* Lifecycle hooks that run during action execution.
|
|
62
|
+
* Callback errors are logged but do not affect action results.
|
|
63
|
+
*/
|
|
64
|
+
export type CrafterCallbacks<TConfig extends CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData> = {
|
|
65
|
+
/** Called when action fails. */
|
|
66
|
+
onError?: (params: {
|
|
67
|
+
error: AllPossibleErrors<TErrors, TConfig, TSchemas>;
|
|
68
|
+
metadata: CallbackMetadata<TConfig, TSchemas, TErrors, TData>;
|
|
69
|
+
}) => Promise<void> | void;
|
|
70
|
+
/** Called when action succeeds. */
|
|
71
|
+
onSuccess?: (params: {
|
|
72
|
+
data: TData;
|
|
73
|
+
metadata: CallbackMetadata<TConfig, TSchemas, TErrors, TData>;
|
|
74
|
+
}) => Promise<void> | void;
|
|
75
|
+
/** Called after action finishes, regardless of success or failure. */
|
|
76
|
+
onSettled?: (params: {
|
|
77
|
+
result: InferCraftedActionResult<TConfig, TSchemas, TErrors, TData>;
|
|
78
|
+
metadata: CallbackMetadata<TConfig, TSchemas, TErrors, TData>;
|
|
79
|
+
}) => Promise<void> | void;
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
|