@kellanjs/actioncraft 0.1.0 → 0.2.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/README.md +411 -302
- package/dist/classes/action-builder.d.ts +59 -0
- package/dist/classes/action-builder.js +95 -0
- package/dist/classes/action-builder.js.map +1 -0
- package/dist/classes/craft-builder.d.ts +66 -0
- package/dist/classes/craft-builder.js +129 -0
- package/dist/classes/craft-builder.js.map +1 -0
- package/dist/classes/error.d.ts +23 -0
- package/dist/classes/error.js +60 -0
- package/dist/classes/error.js.map +1 -0
- package/dist/classes/executor/callbacks.js.map +1 -0
- package/dist/{core → classes/executor}/errors.d.ts +8 -7
- package/dist/{core → classes/executor}/errors.js +23 -10
- package/dist/classes/executor/errors.js.map +1 -0
- package/dist/classes/executor/executor.d.ts +68 -0
- package/dist/{actioncraft.js → classes/executor/executor.js} +135 -131
- package/dist/classes/executor/executor.js.map +1 -0
- package/dist/classes/executor/logging.d.ts +2 -0
- package/dist/classes/executor/logging.js.map +1 -0
- package/dist/classes/executor/transformation.d.ts +17 -0
- package/dist/{core → classes/executor}/transformation.js +1 -1
- package/dist/classes/executor/transformation.js.map +1 -0
- package/dist/classes/executor/validation.d.ts +16 -0
- package/dist/{core → classes/executor}/validation.js +20 -20
- package/dist/classes/executor/validation.js.map +1 -0
- package/dist/classes/internal.d.ts +10 -0
- package/dist/classes/internal.js +5 -0
- package/dist/classes/internal.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/types/actions.d.ts +67 -25
- package/dist/types/{config.d.ts → builder.d.ts} +18 -10
- package/dist/types/builder.js +2 -0
- package/dist/types/builder.js.map +1 -0
- package/dist/types/errors.d.ts +25 -17
- package/dist/types/inference.d.ts +41 -8
- package/dist/types/result.d.ts +8 -14
- package/dist/types/result.js +36 -4
- package/dist/types/result.js.map +1 -1
- package/dist/types/schemas.d.ts +7 -7
- package/dist/types/shared.d.ts +14 -6
- package/dist/utils.d.ts +30 -6
- package/dist/utils.js +68 -8
- package/dist/utils.js.map +1 -1
- package/package.json +11 -11
- package/dist/actioncraft.d.ts +0 -93
- package/dist/actioncraft.js.map +0 -1
- package/dist/core/callbacks.js.map +0 -1
- package/dist/core/errors.js.map +0 -1
- package/dist/core/logging.d.ts +0 -6
- package/dist/core/logging.js.map +0 -1
- package/dist/core/transformation.d.ts +0 -17
- package/dist/core/transformation.js.map +0 -1
- package/dist/core/validation.d.ts +0 -16
- package/dist/core/validation.js.map +0 -1
- package/dist/error.d.ts +0 -16
- package/dist/error.js +0 -22
- package/dist/error.js.map +0 -1
- package/dist/types/config.js +0 -2
- package/dist/types/config.js.map +0 -1
- /package/dist/{core → classes/executor}/callbacks.d.ts +0 -0
- /package/dist/{core → classes/executor}/callbacks.js +0 -0
- /package/dist/{core → classes/executor}/logging.js +0 -0
|
@@ -1,105 +1,96 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import {} from "../../types/errors.js";
|
|
2
|
+
import { err, isOk, isResultOk, isResultErr, isErr, } from "../../types/result.js";
|
|
3
|
+
import { INTERNAL } from "../internal.js";
|
|
4
|
+
import { safeExecuteCallback } from "./callbacks.js";
|
|
5
|
+
import { createUnhandledErrorResult, createImplicitReturnErrorResult, NO_INPUT_SCHEMA_ERROR, } from "./errors.js";
|
|
6
|
+
import { log } from "./logging.js";
|
|
7
|
+
import { serializeRawInput, convertToClientError } from "./transformation.js";
|
|
8
|
+
import { validateInput, validateBindArgs, validateOutput, } from "./validation.js";
|
|
8
9
|
import { unstable_rethrow } from "next/navigation.js";
|
|
9
10
|
// ============================================================================
|
|
10
|
-
//
|
|
11
|
+
// EXECUTOR CLASS - Build and execute your action
|
|
11
12
|
// ============================================================================
|
|
12
|
-
|
|
13
|
-
* Builder class for creating type-safe server actions with validation, error handling, and callbacks.
|
|
14
|
-
*/
|
|
15
|
-
class Crafter {
|
|
13
|
+
export class Executor {
|
|
16
14
|
_config;
|
|
17
15
|
_schemas;
|
|
18
16
|
_errors;
|
|
19
17
|
_callbacks;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
// --------------------------------------------------------------------------
|
|
29
|
-
// FLUENT API METHODS
|
|
30
|
-
// --------------------------------------------------------------------------
|
|
31
|
-
/**
|
|
32
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
33
|
-
* Resets previously defined actions and callbacks.
|
|
34
|
-
*/
|
|
35
|
-
schemas(schemas) {
|
|
36
|
-
return new Crafter(this._config, schemas, this._errors, {}, undefined);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Defines error functions for returning typed errors from actions.
|
|
40
|
-
* Resets previously defined actions and callbacks.
|
|
41
|
-
*/
|
|
42
|
-
errors(errors) {
|
|
43
|
-
return new Crafter(this._config, this._schemas, errors, {}, undefined);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Defines the action implementation function containing business logic.
|
|
47
|
-
* Resets previously defined callbacks.
|
|
48
|
-
*/
|
|
49
|
-
action(fn) {
|
|
50
|
-
return new Crafter(this._config, this._schemas, this._errors, {}, fn);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Defines lifecycle callbacks for action execution.
|
|
54
|
-
* Must be called after action() for correct type inference.
|
|
55
|
-
*/
|
|
56
|
-
callbacks(callbacks) {
|
|
57
|
-
return new Crafter(this._config, this._schemas, this._errors, callbacks, this._actionImpl);
|
|
18
|
+
_handler;
|
|
19
|
+
_actionId;
|
|
20
|
+
constructor(builder) {
|
|
21
|
+
this._config = builder[INTERNAL]().config;
|
|
22
|
+
this._schemas = builder[INTERNAL]().schemas;
|
|
23
|
+
this._errors = builder[INTERNAL]().errors;
|
|
24
|
+
this._callbacks = builder[INTERNAL]().callbacks;
|
|
25
|
+
this._handler = builder[INTERNAL]().handler;
|
|
58
26
|
}
|
|
59
27
|
/**
|
|
60
|
-
* Builds and returns the final executable action
|
|
28
|
+
* Builds and returns the final executable server action.
|
|
61
29
|
*/
|
|
62
30
|
craft() {
|
|
63
|
-
if (!this.
|
|
64
|
-
throw new Error("
|
|
31
|
+
if (!this._handler) {
|
|
32
|
+
throw new Error("A handler implementation is required");
|
|
65
33
|
}
|
|
34
|
+
// Generate a unique ID for this action instance
|
|
35
|
+
this._actionId = this._generateActionId();
|
|
66
36
|
const craftedAction = (...args) => {
|
|
67
37
|
return this._runAction(args);
|
|
68
38
|
};
|
|
69
|
-
// Attach the action
|
|
39
|
+
// Attach $validate method to the action for simple client-side validation
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
craftedAction.$validate = async (input) => {
|
|
42
|
+
return this._validateInputOnly(input);
|
|
43
|
+
};
|
|
44
|
+
// Attach the action's config and ID for runtime inspection
|
|
70
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
46
|
craftedAction.__ac_config = this._config;
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
craftedAction.__ac_id = this._actionId;
|
|
72
49
|
return craftedAction;
|
|
73
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Generates a unique identifier for this action instance.
|
|
53
|
+
*/
|
|
54
|
+
_generateActionId() {
|
|
55
|
+
return crypto.randomUUID();
|
|
56
|
+
}
|
|
74
57
|
// --------------------------------------------------------------------------
|
|
75
58
|
// ACTION EXECUTION
|
|
76
59
|
// --------------------------------------------------------------------------
|
|
77
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Orchestrates action execution (validation, business logic, callbacks, and result formatting.)
|
|
62
|
+
*/
|
|
78
63
|
async _runAction(args) {
|
|
79
|
-
// We know
|
|
80
|
-
const
|
|
64
|
+
// We know these exist because craft() creates/verifies them
|
|
65
|
+
const handler = this._handler;
|
|
66
|
+
const actionId = this._actionId;
|
|
67
|
+
const actionName = this._config.actionName;
|
|
81
68
|
// Extract bindArgs, prevState, and input from the raw args
|
|
82
69
|
const { bindArgs: rawBindArgs, prevState, input: rawInput, } = this._extractActionArgs(args);
|
|
83
70
|
// Check for custom error handler
|
|
84
71
|
const handleThrownErrorFn = this._config.handleThrownError
|
|
85
|
-
? (error) => err(this._config.handleThrownError(error))
|
|
72
|
+
? (error) => err(this._config.handleThrownError(error), actionId)
|
|
86
73
|
: null;
|
|
87
|
-
// Execute onStart callback before any processing
|
|
88
|
-
await this._executeOnStartCallback({
|
|
89
|
-
rawInput,
|
|
90
|
-
rawBindArgs,
|
|
91
|
-
prevState,
|
|
92
|
-
validatedInput: undefined,
|
|
93
|
-
validatedBindArgs: undefined,
|
|
94
|
-
});
|
|
95
74
|
// Track validation state for error handling
|
|
96
75
|
let validatedInput = undefined;
|
|
97
76
|
let validatedBindArgs = undefined;
|
|
98
77
|
try {
|
|
78
|
+
// Execute onStart callback before any processing
|
|
79
|
+
await this._executeOnStartCallback({
|
|
80
|
+
actionId,
|
|
81
|
+
actionName,
|
|
82
|
+
rawInput,
|
|
83
|
+
rawBindArgs,
|
|
84
|
+
prevState,
|
|
85
|
+
validatedInput: undefined,
|
|
86
|
+
validatedBindArgs: undefined,
|
|
87
|
+
});
|
|
99
88
|
// Validate input and return on failure
|
|
100
89
|
const inputValidation = await this._validateInput(rawInput);
|
|
101
90
|
if (!isOk(inputValidation)) {
|
|
102
91
|
await this._executeResultCallbacks(inputValidation, {
|
|
92
|
+
actionId,
|
|
93
|
+
actionName,
|
|
103
94
|
rawInput,
|
|
104
95
|
rawBindArgs,
|
|
105
96
|
prevState,
|
|
@@ -114,6 +105,8 @@ class Crafter {
|
|
|
114
105
|
const bindArgsValidation = await this._validateBindArgs(rawBindArgs);
|
|
115
106
|
if (!isOk(bindArgsValidation)) {
|
|
116
107
|
await this._executeResultCallbacks(bindArgsValidation, {
|
|
108
|
+
actionId,
|
|
109
|
+
actionName,
|
|
117
110
|
rawInput,
|
|
118
111
|
rawBindArgs,
|
|
119
112
|
prevState,
|
|
@@ -124,17 +117,25 @@ class Crafter {
|
|
|
124
117
|
}
|
|
125
118
|
// Update validation state
|
|
126
119
|
validatedBindArgs = bindArgsValidation.value;
|
|
127
|
-
// Execute the user's action
|
|
128
|
-
const
|
|
120
|
+
// Execute the user's action handler
|
|
121
|
+
const handlerResult = await handler({
|
|
129
122
|
input: inputValidation.value,
|
|
130
123
|
bindArgs: bindArgsValidation.value,
|
|
131
124
|
errors: this._buildErrorFunctions(),
|
|
132
|
-
metadata: {
|
|
125
|
+
metadata: {
|
|
126
|
+
actionId,
|
|
127
|
+
actionName,
|
|
128
|
+
rawInput,
|
|
129
|
+
rawBindArgs,
|
|
130
|
+
prevState,
|
|
131
|
+
},
|
|
133
132
|
});
|
|
134
133
|
// Return on `undefined` (implicit return error)
|
|
135
|
-
if (
|
|
136
|
-
const implicitReturnError = createImplicitReturnErrorResult();
|
|
134
|
+
if (handlerResult === undefined) {
|
|
135
|
+
const implicitReturnError = createImplicitReturnErrorResult(actionId, actionName);
|
|
137
136
|
await this._executeResultCallbacks(implicitReturnError, {
|
|
137
|
+
actionId,
|
|
138
|
+
actionName,
|
|
138
139
|
rawInput,
|
|
139
140
|
rawBindArgs,
|
|
140
141
|
prevState,
|
|
@@ -145,17 +146,20 @@ class Crafter {
|
|
|
145
146
|
}
|
|
146
147
|
let finalResult;
|
|
147
148
|
// Process different return types from the action
|
|
148
|
-
if (isResultErr(
|
|
149
|
-
|
|
149
|
+
if (isResultErr(handlerResult)) {
|
|
150
|
+
// Ensure error result has correct action ID
|
|
151
|
+
finalResult = this._ensureResultActionId(handlerResult);
|
|
150
152
|
}
|
|
151
153
|
else {
|
|
152
|
-
const outputData = isResultOk(
|
|
153
|
-
?
|
|
154
|
-
:
|
|
154
|
+
const outputData = isResultOk(handlerResult)
|
|
155
|
+
? handlerResult.value
|
|
156
|
+
: handlerResult;
|
|
155
157
|
finalResult = await this._validateOutput(outputData);
|
|
156
158
|
}
|
|
157
159
|
// Execute callbacks and return final result
|
|
158
160
|
await this._executeResultCallbacks(finalResult, {
|
|
161
|
+
actionId,
|
|
162
|
+
actionName,
|
|
159
163
|
rawInput,
|
|
160
164
|
rawBindArgs,
|
|
161
165
|
prevState,
|
|
@@ -177,6 +181,8 @@ class Crafter {
|
|
|
177
181
|
try {
|
|
178
182
|
const errorResult = this._handleThrownError(error, handleThrownErrorFn);
|
|
179
183
|
await this._executeResultCallbacks(errorResult, {
|
|
184
|
+
actionId,
|
|
185
|
+
actionName,
|
|
180
186
|
rawInput,
|
|
181
187
|
rawBindArgs,
|
|
182
188
|
prevState,
|
|
@@ -188,7 +194,7 @@ class Crafter {
|
|
|
188
194
|
catch (handlerError) {
|
|
189
195
|
// If we catch another error here, then we're done
|
|
190
196
|
log(this._config.logger, "warn", "Error handling failure - both primary error and error handler threw", { primaryError: error, handlerError });
|
|
191
|
-
return this._toActionResult(createUnhandledErrorResult(), rawInput);
|
|
197
|
+
return this._toActionResult(createUnhandledErrorResult(actionId, actionName), rawInput);
|
|
192
198
|
}
|
|
193
199
|
}
|
|
194
200
|
}
|
|
@@ -204,6 +210,8 @@ class Crafter {
|
|
|
204
210
|
input: args[numBindSchemas + 1],
|
|
205
211
|
};
|
|
206
212
|
}
|
|
213
|
+
// For regular actions (non-useActionState), the input is the first argument after bind args
|
|
214
|
+
// If there are no bind schemas, the input is the first argument (args[0])
|
|
207
215
|
return {
|
|
208
216
|
bindArgs: args.slice(0, numBindSchemas),
|
|
209
217
|
// When useActionState is disabled the prevState parameter is never
|
|
@@ -220,7 +228,9 @@ class Crafter {
|
|
|
220
228
|
*/
|
|
221
229
|
_toActionResult(result, inputForValues) {
|
|
222
230
|
// Convert internal errors to client-facing errors
|
|
223
|
-
const clientResult = isOk(result)
|
|
231
|
+
const clientResult = isOk(result)
|
|
232
|
+
? result
|
|
233
|
+
: err(convertToClientError(result.error), this._actionId);
|
|
224
234
|
// Handle useActionState format (always returns StatefulApiResult)
|
|
225
235
|
if (this._config.useActionState) {
|
|
226
236
|
if (isOk(clientResult)) {
|
|
@@ -231,12 +241,14 @@ class Crafter {
|
|
|
231
241
|
success: true,
|
|
232
242
|
data: clientResult.value,
|
|
233
243
|
values: successValues,
|
|
244
|
+
__ac_id: this._actionId,
|
|
234
245
|
};
|
|
235
246
|
}
|
|
236
247
|
return {
|
|
237
248
|
success: false,
|
|
238
249
|
error: clientResult.error,
|
|
239
250
|
values: serializeRawInput(inputForValues),
|
|
251
|
+
__ac_id: this._actionId,
|
|
240
252
|
};
|
|
241
253
|
}
|
|
242
254
|
const format = this._config.resultFormat ?? "api";
|
|
@@ -249,11 +261,13 @@ class Crafter {
|
|
|
249
261
|
return {
|
|
250
262
|
success: true,
|
|
251
263
|
data: clientResult.value,
|
|
264
|
+
__ac_id: this._actionId,
|
|
252
265
|
};
|
|
253
266
|
}
|
|
254
267
|
return {
|
|
255
268
|
success: false,
|
|
256
269
|
error: clientResult.error,
|
|
270
|
+
__ac_id: this._actionId,
|
|
257
271
|
};
|
|
258
272
|
}
|
|
259
273
|
// --------------------------------------------------------------------------
|
|
@@ -265,7 +279,7 @@ class Crafter {
|
|
|
265
279
|
_handleThrownError(error, customHandler) {
|
|
266
280
|
const caughtErrorResult = customHandler
|
|
267
281
|
? customHandler(error)
|
|
268
|
-
: createUnhandledErrorResult();
|
|
282
|
+
: createUnhandledErrorResult(this._actionId, this._config.actionName);
|
|
269
283
|
return caughtErrorResult;
|
|
270
284
|
}
|
|
271
285
|
// --------------------------------------------------------------------------
|
|
@@ -275,19 +289,43 @@ class Crafter {
|
|
|
275
289
|
* Validates input using the shared helper.
|
|
276
290
|
*/
|
|
277
291
|
_validateInput(rawInput) {
|
|
278
|
-
return validateInput(this._schemas, this._config, rawInput);
|
|
292
|
+
return validateInput(this._schemas, this._config, rawInput, this._actionId, this._config.actionName);
|
|
279
293
|
}
|
|
280
294
|
/**
|
|
281
295
|
* Validates bound arguments using the configured bind schemas.
|
|
282
296
|
*/
|
|
283
297
|
_validateBindArgs(bindArgs) {
|
|
284
|
-
return validateBindArgs(this._schemas, this._config, bindArgs);
|
|
298
|
+
return validateBindArgs(this._schemas, this._config, bindArgs, this._actionId, this._config.actionName);
|
|
285
299
|
}
|
|
286
300
|
/**
|
|
287
301
|
* Validates output data using the configured output schema.
|
|
288
302
|
*/
|
|
289
303
|
_validateOutput(data) {
|
|
290
|
-
return validateOutput(this._schemas, this._config, data);
|
|
304
|
+
return validateOutput(this._schemas, this._config, data, this._actionId, this._config.actionName);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Validates input data only (used by the $validate method).
|
|
308
|
+
*/
|
|
309
|
+
async _validateInputOnly(input) {
|
|
310
|
+
// If no input schema, return error indicating validation cannot be performed
|
|
311
|
+
if (!this._schemas.inputSchema) {
|
|
312
|
+
return {
|
|
313
|
+
success: false,
|
|
314
|
+
error: NO_INPUT_SCHEMA_ERROR,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const validationResult = await this._validateInput(input);
|
|
318
|
+
if (isOk(validationResult)) {
|
|
319
|
+
return {
|
|
320
|
+
success: true,
|
|
321
|
+
data: validationResult.value,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
// Convert internal error to client-facing error
|
|
326
|
+
const clientError = convertToClientError(validationResult.error);
|
|
327
|
+
return { success: false, error: clientError };
|
|
328
|
+
}
|
|
291
329
|
}
|
|
292
330
|
// --------------------------------------------------------------------------
|
|
293
331
|
// CALLBACKS
|
|
@@ -328,60 +366,26 @@ class Crafter {
|
|
|
328
366
|
// UTILITY METHODS
|
|
329
367
|
// --------------------------------------------------------------------------
|
|
330
368
|
/**
|
|
331
|
-
*
|
|
369
|
+
* Ensures a Result object has the correct action ID.
|
|
370
|
+
*/
|
|
371
|
+
_ensureResultActionId(result) {
|
|
372
|
+
if (!result.__ac_id || result.__ac_id === "unknown") {
|
|
373
|
+
return {
|
|
374
|
+
...result,
|
|
375
|
+
__ac_id: this._actionId,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Creates error functions that return a Result object when called by the action handler.
|
|
332
382
|
*/
|
|
333
383
|
_buildErrorFunctions() {
|
|
334
384
|
const errorFns = {};
|
|
335
385
|
for (const [key, errorDefFn] of Object.entries(this._errors)) {
|
|
336
|
-
errorFns[key] = ((...args) => err(errorDefFn(...args)));
|
|
386
|
+
errorFns[key] = ((...args) => err(errorDefFn(...args), this._actionId));
|
|
337
387
|
}
|
|
338
388
|
return errorFns;
|
|
339
389
|
}
|
|
340
390
|
}
|
|
341
|
-
|
|
342
|
-
// PUBLIC API EXPORTS
|
|
343
|
-
// ============================================================================
|
|
344
|
-
/**
|
|
345
|
-
* Creates a new Crafter instance for building type-safe server actions.
|
|
346
|
-
*/
|
|
347
|
-
export function create(config) {
|
|
348
|
-
return new Crafter(config ?? {}, {}, {}, {}, undefined);
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Creates an appropriate initial state for any action based on its configuration.
|
|
352
|
-
*
|
|
353
|
-
* For useActionState actions: returns StatefulApiResult with error and values
|
|
354
|
-
* For functional format actions: returns Result.err() with error
|
|
355
|
-
* For regular actions: returns ApiResult with error
|
|
356
|
-
*
|
|
357
|
-
* Usage:
|
|
358
|
-
* - useActionState: const [state, action] = useActionState(myAction, initial(myAction))
|
|
359
|
-
* - useState: const [state, setState] = useState(initial(myAction))
|
|
360
|
-
*/
|
|
361
|
-
export function initial(action) {
|
|
362
|
-
const error = {
|
|
363
|
-
type: EXTERNAL_ERROR_TYPES.INITIAL_STATE,
|
|
364
|
-
message: "Action has not been executed yet",
|
|
365
|
-
};
|
|
366
|
-
// Attempt to read the ActionCraft config attached during craft()
|
|
367
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
368
|
-
const cfg = action?.__ac_config;
|
|
369
|
-
// Functional format -> Result<_, _>
|
|
370
|
-
if (cfg?.resultFormat === "functional") {
|
|
371
|
-
return err(error);
|
|
372
|
-
}
|
|
373
|
-
// useActionState enabled -> StatefulApiResult
|
|
374
|
-
if (cfg?.useActionState) {
|
|
375
|
-
return {
|
|
376
|
-
success: false,
|
|
377
|
-
error,
|
|
378
|
-
values: undefined,
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
// Default ApiResult shape
|
|
382
|
-
return {
|
|
383
|
-
success: false,
|
|
384
|
-
error,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
//# sourceMappingURL=actioncraft.js.map
|
|
391
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/classes/executor/executor.ts"],"names":[],"mappings":"AAeA,OAAO,EAIN,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,GAAG,EACH,IAAI,EACJ,UAAU,EACV,WAAW,EACX,KAAK,GACN,MAAM,uBAAuB,CAAC;AAS/B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,+EAA+E;AAC/E,iDAAiD;AACjD,+EAA+E;AAE/E,MAAM,OAAO,QAAQ;IAOF,OAAO,CAAU;IACjB,QAAQ,CAAW;IACnB,OAA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ACzB,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,MAAM,QAAQ,GAAG,EAA6B,CAAC;QAE/C,KAAK,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7D,QAAQ,CAAC,GAAoB,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAC5C,GAAG,CACD,UAAU,CAAC,GAAG,IAAI,CAAC,EACnB,IAAI,CAAC,SAAU,CAChB,CAA2C,CAAC;QACjD,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../src/classes/executor/logging.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,GAAG,CACjB,MAAwB,EACxB,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 { Schemas } from "../../types/builder.js";
|
|
3
|
+
import type { Config, Errors } from "../../types/builder.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 Schemas>(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 Errors, TConfig extends Config, TSchemas extends Schemas>(internalError: AllPossibleErrors<TErrors, TConfig, TSchemas>): PossibleErrors<TErrors, TConfig, TSchemas>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation.js","sourceRoot":"","sources":["../../../src/classes/executor/transformation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAK7D,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 { Config, Schemas, Errors } from "../../types/builder.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 Config, TSchemas extends Schemas, TErrors extends Errors>(schemas: TSchemas, config: TConfig, rawInput: InferRawInput<TSchemas> | undefined, actionId: string, actionName?: string): 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 Config, TSchemas extends Schemas, TErrors extends Errors>(schemas: TSchemas, config: TConfig, bindArgs: InferRawBindArgs<TSchemas>, actionId: string, actionName?: string): 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 Config, TSchemas extends Schemas, TErrors extends Errors, TData>(schemas: TSchemas, config: TConfig, data: TData, actionId: string, actionName?: string): Promise<Result<TData, AllPossibleErrors<TErrors, TConfig, TSchemas>>>;
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { standardParse } from "
|
|
2
|
-
import { INTERNAL_ERROR_TYPES, EXTERNAL_ERROR_TYPES } from "
|
|
3
|
-
import { ok, err } from "
|
|
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
4
|
import { createValidationError, createInternalLogicError, formatValidationIssues, } from "./errors.js";
|
|
5
5
|
/**
|
|
6
6
|
* Validate input using the configured input schema.
|
|
7
7
|
*/
|
|
8
|
-
export async function validateInput(schemas, config, rawInput) {
|
|
8
|
+
export async function validateInput(schemas, config, rawInput, actionId, actionName) {
|
|
9
9
|
if (!schemas.inputSchema) {
|
|
10
|
-
return ok(undefined);
|
|
10
|
+
return ok(undefined, actionId);
|
|
11
11
|
}
|
|
12
12
|
const result = await standardParse(schemas.inputSchema, rawInput);
|
|
13
13
|
if (Array.isArray(result.issues) && result.issues.length > 0) {
|
|
14
14
|
const format = config.validationErrorFormat ?? "flattened";
|
|
15
15
|
const baseError = formatValidationIssues(result.issues, format);
|
|
16
|
-
const inputValidationError = createValidationError(EXTERNAL_ERROR_TYPES.INPUT_VALIDATION, "Input validation failed", baseError);
|
|
17
|
-
return err(inputValidationError);
|
|
16
|
+
const inputValidationError = createValidationError(EXTERNAL_ERROR_TYPES.INPUT_VALIDATION, "Input validation failed", baseError, actionName);
|
|
17
|
+
return err(inputValidationError, actionId);
|
|
18
18
|
}
|
|
19
19
|
if (!result.issues && "value" in result) {
|
|
20
|
-
return ok(result.value);
|
|
20
|
+
return ok(result.value, actionId);
|
|
21
21
|
}
|
|
22
22
|
// Should never happen
|
|
23
23
|
const logicErr = createInternalLogicError("Unexpected validation state in input validation: neither success nor failure");
|
|
24
|
-
return err(logicErr);
|
|
24
|
+
return err(logicErr, actionId);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Validate bound arguments using configured bind schemas.
|
|
28
28
|
*/
|
|
29
|
-
export async function validateBindArgs(schemas, config, bindArgs) {
|
|
29
|
+
export async function validateBindArgs(schemas, config, bindArgs, actionId, actionName) {
|
|
30
30
|
if (!schemas.bindSchemas) {
|
|
31
|
-
return ok([]);
|
|
31
|
+
return ok([], actionId);
|
|
32
32
|
}
|
|
33
33
|
const validated = [];
|
|
34
34
|
for (let i = 0; i < schemas.bindSchemas.length; i++) {
|
|
@@ -38,33 +38,33 @@ export async function validateBindArgs(schemas, config, bindArgs) {
|
|
|
38
38
|
if (Array.isArray(result.issues) && result.issues.length > 0) {
|
|
39
39
|
const format = config.validationErrorFormat ?? "flattened";
|
|
40
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);
|
|
41
|
+
const bindError = createValidationError(EXTERNAL_ERROR_TYPES.BIND_ARGS_VALIDATION, "Bind arguments validation failed", baseError, actionName);
|
|
42
|
+
return err(bindError, actionId);
|
|
43
43
|
}
|
|
44
44
|
if ("value" in result) {
|
|
45
45
|
validated.push(result.value);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
return ok(validated);
|
|
48
|
+
return ok(validated, actionId);
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Validate action output using configured output schema.
|
|
52
52
|
*/
|
|
53
|
-
export async function validateOutput(schemas, config, data) {
|
|
53
|
+
export async function validateOutput(schemas, config, data, actionId, actionName) {
|
|
54
54
|
if (!schemas.outputSchema) {
|
|
55
|
-
return ok(data);
|
|
55
|
+
return ok(data, actionId);
|
|
56
56
|
}
|
|
57
57
|
const result = await standardParse(schemas.outputSchema, data);
|
|
58
58
|
if (Array.isArray(result.issues) && result.issues.length > 0) {
|
|
59
59
|
const format = config.validationErrorFormat ?? "flattened";
|
|
60
60
|
const baseError = formatValidationIssues(result.issues, format);
|
|
61
|
-
const outputError = createValidationError(INTERNAL_ERROR_TYPES.OUTPUT_VALIDATION, "Output validation failed", baseError);
|
|
62
|
-
return err(outputError);
|
|
61
|
+
const outputError = createValidationError(INTERNAL_ERROR_TYPES.OUTPUT_VALIDATION, "Output validation failed", baseError, actionName);
|
|
62
|
+
return err(outputError, actionId);
|
|
63
63
|
}
|
|
64
64
|
if (!result.issues && "value" in result) {
|
|
65
|
-
return ok(result.value);
|
|
65
|
+
return ok(result.value, actionId);
|
|
66
66
|
}
|
|
67
67
|
const logicErr = createInternalLogicError("Unexpected validation state in output validation: neither success nor failure");
|
|
68
|
-
return err(logicErr);
|
|
68
|
+
return err(logicErr, actionId);
|
|
69
69
|
}
|
|
70
70
|
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/classes/executor/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAQ/B,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAOhD,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,aA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AE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC5B,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,EACT,UAAU,CACX,CAAC;QAEF,OAAO,GAAG,CAAC,WAAW,EAAE,QAAQ,CAG/B,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;QACxC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAc,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,QAAQ,GAAG,wBAAwB,CACvC,+EAA+E,CAChF,CAAC;IACF,OAAO,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAG5B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Handler } from "../types/actions.js";
|
|
2
|
+
import type { Config, Schemas, Errors, Callbacks } from "../types/builder.js";
|
|
3
|
+
export declare const INTERNAL: unique symbol;
|
|
4
|
+
export interface CrafterInternals<TConfig extends Config, TSchemas extends Schemas, TErrors extends Errors, TCallbacks extends Callbacks<TConfig, TSchemas, TErrors, TData>, TData> {
|
|
5
|
+
config: TConfig;
|
|
6
|
+
schemas: TSchemas;
|
|
7
|
+
errors: TErrors;
|
|
8
|
+
callbacks: TCallbacks;
|
|
9
|
+
handler?: Handler<TConfig, TSchemas, TErrors, TData>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// INTERNAL INTERFACE FOR CRAFTER-EXECUTOR COMMUNICATION
|
|
3
|
+
// ============================================================================
|
|
4
|
+
export const INTERNAL = Symbol("INTERNAL");
|
|
5
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/classes/internal.ts"],"names":[],"mappings":"AAGA,+EAA+E;AAC/E,wDAAwD;AACxD,+EAA+E;AAE/E,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { craft } from "./classes/craft-builder.js";
|
|
2
|
+
export { action } from "./classes/action-builder.js";
|
|
3
|
+
export { unwrap, throwable, initial, getActionId } from "./utils.js";
|
|
4
|
+
export { ActioncraftError, isActioncraftError } from "./classes/error.js";
|
|
4
5
|
export type { Result, Ok, Err } from "./types/result.js";
|
|
5
6
|
export { isOk, isErr, ok, err } from "./types/result.js";
|
|
6
7
|
export type { InferInput, InferResult, InferData, InferErrors, } from "./types/inference.js";
|