@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/actioncraft.js
DELETED
|
@@ -1,613 +0,0 @@
|
|
|
1
|
-
import { safeExecuteCallback } from "./core/callbacks.js";
|
|
2
|
-
import { createUnhandledErrorResult, createImplicitReturnErrorResult, } from "./core/errors.js";
|
|
3
|
-
import { log } from "./core/logging.js";
|
|
4
|
-
import { serializeRawInput, convertToClientError, } from "./core/transformation.js";
|
|
5
|
-
import { validateInput, validateBindArgs, validateOutput, } from "./core/validation.js";
|
|
6
|
-
import { EXTERNAL_ERROR_TYPES, } from "./types/errors.js";
|
|
7
|
-
import { err, isOk, isResultOk, isResultErr, isErr } from "./types/result.js";
|
|
8
|
-
import { unstable_rethrow } from "next/navigation.js";
|
|
9
|
-
// ============================================================================
|
|
10
|
-
// CRAFTER CLASS - Configure and define your action
|
|
11
|
-
// ============================================================================
|
|
12
|
-
const INTERNAL = Symbol("INTERNAL");
|
|
13
|
-
class Crafter {
|
|
14
|
-
_config;
|
|
15
|
-
_schemas;
|
|
16
|
-
_errors;
|
|
17
|
-
_callbacks;
|
|
18
|
-
_handler;
|
|
19
|
-
constructor(config, schemas, errors, callbacks, handler) {
|
|
20
|
-
this._config = config;
|
|
21
|
-
this._schemas = schemas;
|
|
22
|
-
this._errors = errors;
|
|
23
|
-
this._callbacks = callbacks;
|
|
24
|
-
this._handler = handler;
|
|
25
|
-
}
|
|
26
|
-
// --------------------------------------------------------------------------
|
|
27
|
-
// FLUENT API METHODS
|
|
28
|
-
// --------------------------------------------------------------------------
|
|
29
|
-
/**
|
|
30
|
-
* Defines configuration options for the action.
|
|
31
|
-
* Resets previously defined handler and callbacks.
|
|
32
|
-
*/
|
|
33
|
-
config(config) {
|
|
34
|
-
return new Crafter(config, this._schemas, this._errors, {}, undefined);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
38
|
-
* Resets previously defined handler and callbacks.
|
|
39
|
-
*/
|
|
40
|
-
schemas(schemas) {
|
|
41
|
-
return new Crafter(this._config, schemas, this._errors, {}, undefined);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Defines error functions for returning typed errors from the handler.
|
|
45
|
-
* Resets previously defined handler and callbacks.
|
|
46
|
-
*/
|
|
47
|
-
errors(errors) {
|
|
48
|
-
return new Crafter(this._config, this._schemas, errors, {}, undefined);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Defines the handler function containing the server action's business logic.
|
|
52
|
-
* Resets previously defined callbacks.
|
|
53
|
-
*/
|
|
54
|
-
handler(fn) {
|
|
55
|
-
return new Crafter(this._config, this._schemas, this._errors, {}, fn);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
59
|
-
* Must be called after handler() for correct type inference.
|
|
60
|
-
*/
|
|
61
|
-
callbacks(callbacks) {
|
|
62
|
-
return new Crafter(this._config, this._schemas, this._errors, callbacks, this._handler);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* @returns Internal properties of the Crafter instance
|
|
66
|
-
*/
|
|
67
|
-
[INTERNAL]() {
|
|
68
|
-
return {
|
|
69
|
-
config: this._config,
|
|
70
|
-
schemas: this._schemas,
|
|
71
|
-
errors: this._errors,
|
|
72
|
-
callbacks: this._callbacks,
|
|
73
|
-
handler: this._handler,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// ============================================================================
|
|
78
|
-
// EXECUTOR CLASS - Build and execute your action
|
|
79
|
-
// ============================================================================
|
|
80
|
-
class Executor {
|
|
81
|
-
_config;
|
|
82
|
-
_schemas;
|
|
83
|
-
_errors;
|
|
84
|
-
_callbacks;
|
|
85
|
-
_handler;
|
|
86
|
-
_actionId;
|
|
87
|
-
constructor(crafter) {
|
|
88
|
-
this._config = crafter[INTERNAL]().config;
|
|
89
|
-
this._schemas = crafter[INTERNAL]().schemas;
|
|
90
|
-
this._errors = crafter[INTERNAL]().errors;
|
|
91
|
-
this._callbacks = crafter[INTERNAL]().callbacks;
|
|
92
|
-
this._handler = crafter[INTERNAL]().handler;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Builds and returns the final executable server action.
|
|
96
|
-
*/
|
|
97
|
-
craft() {
|
|
98
|
-
if (!this._handler) {
|
|
99
|
-
throw new Error("A handler implementation is required");
|
|
100
|
-
}
|
|
101
|
-
// Generate a unique ID for this action instance
|
|
102
|
-
this._actionId = this._generateActionId();
|
|
103
|
-
const craftedAction = (...args) => {
|
|
104
|
-
return this._runAction(args);
|
|
105
|
-
};
|
|
106
|
-
// Attach the action's config and ID for runtime inspection
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
-
craftedAction.__ac_config = this._config;
|
|
109
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
-
craftedAction.__ac_id = this._actionId;
|
|
111
|
-
return craftedAction;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Generates a unique identifier for this action instance.
|
|
115
|
-
*/
|
|
116
|
-
_generateActionId() {
|
|
117
|
-
return crypto.randomUUID();
|
|
118
|
-
}
|
|
119
|
-
// --------------------------------------------------------------------------
|
|
120
|
-
// ACTION EXECUTION
|
|
121
|
-
// --------------------------------------------------------------------------
|
|
122
|
-
/**
|
|
123
|
-
* Orchestrates action execution (validation, business logic, callbacks, and result formatting.)
|
|
124
|
-
*/
|
|
125
|
-
async _runAction(args) {
|
|
126
|
-
// We know these exist because craft() creates/verifies them
|
|
127
|
-
const handler = this._handler;
|
|
128
|
-
const actionId = this._actionId;
|
|
129
|
-
// Extract bindArgs, prevState, and input from the raw args
|
|
130
|
-
const { bindArgs: rawBindArgs, prevState, input: rawInput, } = this._extractActionArgs(args);
|
|
131
|
-
// Check for custom error handler
|
|
132
|
-
const handleThrownErrorFn = this._config.handleThrownError
|
|
133
|
-
? (error) => err(this._config.handleThrownError(error), actionId)
|
|
134
|
-
: null;
|
|
135
|
-
// Track validation state for error handling
|
|
136
|
-
let validatedInput = undefined;
|
|
137
|
-
let validatedBindArgs = undefined;
|
|
138
|
-
try {
|
|
139
|
-
// Execute onStart callback before any processing
|
|
140
|
-
await this._executeOnStartCallback({
|
|
141
|
-
rawInput,
|
|
142
|
-
rawBindArgs,
|
|
143
|
-
prevState,
|
|
144
|
-
validatedInput: undefined,
|
|
145
|
-
validatedBindArgs: undefined,
|
|
146
|
-
actionId,
|
|
147
|
-
});
|
|
148
|
-
// Validate input and return on failure
|
|
149
|
-
const inputValidation = await this._validateInput(rawInput);
|
|
150
|
-
if (!isOk(inputValidation)) {
|
|
151
|
-
await this._executeResultCallbacks(inputValidation, {
|
|
152
|
-
rawInput,
|
|
153
|
-
rawBindArgs,
|
|
154
|
-
prevState,
|
|
155
|
-
validatedInput,
|
|
156
|
-
validatedBindArgs,
|
|
157
|
-
actionId,
|
|
158
|
-
});
|
|
159
|
-
return this._toActionResult(inputValidation, rawInput);
|
|
160
|
-
}
|
|
161
|
-
// Update validation state
|
|
162
|
-
validatedInput = inputValidation.value;
|
|
163
|
-
// Validate bound arguments and return on failure
|
|
164
|
-
const bindArgsValidation = await this._validateBindArgs(rawBindArgs);
|
|
165
|
-
if (!isOk(bindArgsValidation)) {
|
|
166
|
-
await this._executeResultCallbacks(bindArgsValidation, {
|
|
167
|
-
rawInput,
|
|
168
|
-
rawBindArgs,
|
|
169
|
-
prevState,
|
|
170
|
-
validatedInput,
|
|
171
|
-
validatedBindArgs,
|
|
172
|
-
actionId,
|
|
173
|
-
});
|
|
174
|
-
return this._toActionResult(bindArgsValidation, rawInput);
|
|
175
|
-
}
|
|
176
|
-
// Update validation state
|
|
177
|
-
validatedBindArgs = bindArgsValidation.value;
|
|
178
|
-
// Execute the user's action handler
|
|
179
|
-
const handlerResult = await handler({
|
|
180
|
-
input: inputValidation.value,
|
|
181
|
-
bindArgs: bindArgsValidation.value,
|
|
182
|
-
errors: this._buildErrorFunctions(),
|
|
183
|
-
metadata: {
|
|
184
|
-
rawInput,
|
|
185
|
-
rawBindArgs,
|
|
186
|
-
prevState,
|
|
187
|
-
actionId,
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
// Return on `undefined` (implicit return error)
|
|
191
|
-
if (handlerResult === undefined) {
|
|
192
|
-
const implicitReturnError = createImplicitReturnErrorResult(actionId);
|
|
193
|
-
await this._executeResultCallbacks(implicitReturnError, {
|
|
194
|
-
rawInput,
|
|
195
|
-
rawBindArgs,
|
|
196
|
-
prevState,
|
|
197
|
-
validatedInput,
|
|
198
|
-
validatedBindArgs,
|
|
199
|
-
actionId,
|
|
200
|
-
});
|
|
201
|
-
return this._toActionResult(implicitReturnError, rawInput);
|
|
202
|
-
}
|
|
203
|
-
let finalResult;
|
|
204
|
-
// Process different return types from the action
|
|
205
|
-
if (isResultErr(handlerResult)) {
|
|
206
|
-
// Ensure error result has correct action ID
|
|
207
|
-
finalResult = this._ensureResultActionId(handlerResult);
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
const outputData = isResultOk(handlerResult)
|
|
211
|
-
? handlerResult.value
|
|
212
|
-
: handlerResult;
|
|
213
|
-
finalResult = await this._validateOutput(outputData);
|
|
214
|
-
}
|
|
215
|
-
// Execute callbacks and return final result
|
|
216
|
-
await this._executeResultCallbacks(finalResult, {
|
|
217
|
-
rawInput,
|
|
218
|
-
rawBindArgs,
|
|
219
|
-
prevState,
|
|
220
|
-
validatedInput,
|
|
221
|
-
validatedBindArgs,
|
|
222
|
-
actionId,
|
|
223
|
-
});
|
|
224
|
-
// Use validated input for the values field on a successful run
|
|
225
|
-
const inputForValues = isOk(finalResult)
|
|
226
|
-
? this._schemas.inputSchema
|
|
227
|
-
? inputValidation.value
|
|
228
|
-
: rawInput
|
|
229
|
-
: rawInput;
|
|
230
|
-
return this._toActionResult(finalResult, inputForValues);
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
// Re-throw Next.js framework errors
|
|
234
|
-
unstable_rethrow(error);
|
|
235
|
-
// Handle unexpected thrown errors
|
|
236
|
-
try {
|
|
237
|
-
const errorResult = this._handleThrownError(error, handleThrownErrorFn);
|
|
238
|
-
await this._executeResultCallbacks(errorResult, {
|
|
239
|
-
rawInput,
|
|
240
|
-
rawBindArgs,
|
|
241
|
-
prevState,
|
|
242
|
-
validatedInput,
|
|
243
|
-
validatedBindArgs,
|
|
244
|
-
actionId,
|
|
245
|
-
});
|
|
246
|
-
return this._toActionResult(errorResult, rawInput);
|
|
247
|
-
}
|
|
248
|
-
catch (handlerError) {
|
|
249
|
-
// If we catch another error here, then we're done
|
|
250
|
-
log(this._config.logger, "warn", "Error handling failure - both primary error and error handler threw", { primaryError: error, handlerError });
|
|
251
|
-
return this._toActionResult(createUnhandledErrorResult(actionId), rawInput);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Extracts bind arguments, previous state, and input from raw action arguments.
|
|
257
|
-
*/
|
|
258
|
-
_extractActionArgs(args) {
|
|
259
|
-
const numBindSchemas = this._schemas.bindSchemas?.length ?? 0;
|
|
260
|
-
if (this._config.useActionState) {
|
|
261
|
-
return {
|
|
262
|
-
bindArgs: args.slice(0, numBindSchemas),
|
|
263
|
-
prevState: args[numBindSchemas],
|
|
264
|
-
input: args[numBindSchemas + 1],
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
// For regular actions (non-useActionState), the input is the first argument after bind args
|
|
268
|
-
// If there are no bind schemas, the input is the first argument (args[0])
|
|
269
|
-
return {
|
|
270
|
-
bindArgs: args.slice(0, numBindSchemas),
|
|
271
|
-
// When useActionState is disabled the prevState parameter is never
|
|
272
|
-
// present, so we cast to never (or undefined) to satisfy the type.
|
|
273
|
-
prevState: undefined,
|
|
274
|
-
input: args[numBindSchemas],
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
// --------------------------------------------------------------------------
|
|
278
|
-
// RESULT TRANSFORMATION
|
|
279
|
-
// --------------------------------------------------------------------------
|
|
280
|
-
/**
|
|
281
|
-
* Transforms internal Result objects to client-facing action result format.
|
|
282
|
-
*/
|
|
283
|
-
_toActionResult(result, inputForValues) {
|
|
284
|
-
// Convert internal errors to client-facing errors
|
|
285
|
-
const clientResult = isOk(result)
|
|
286
|
-
? result
|
|
287
|
-
: err(convertToClientError(result.error), this._actionId);
|
|
288
|
-
// Handle useActionState format (always returns StatefulApiResult)
|
|
289
|
-
if (this._config.useActionState) {
|
|
290
|
-
if (isOk(clientResult)) {
|
|
291
|
-
const successValues = this._schemas.inputSchema
|
|
292
|
-
? inputForValues
|
|
293
|
-
: serializeRawInput(inputForValues);
|
|
294
|
-
return {
|
|
295
|
-
success: true,
|
|
296
|
-
data: clientResult.value,
|
|
297
|
-
values: successValues,
|
|
298
|
-
__ac_id: this._actionId,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
return {
|
|
302
|
-
success: false,
|
|
303
|
-
error: clientResult.error,
|
|
304
|
-
values: serializeRawInput(inputForValues),
|
|
305
|
-
__ac_id: this._actionId,
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
const format = this._config.resultFormat ?? "api";
|
|
309
|
-
// Return functional format if configured
|
|
310
|
-
if (format === "functional") {
|
|
311
|
-
return clientResult;
|
|
312
|
-
}
|
|
313
|
-
// Default API format
|
|
314
|
-
if (isOk(clientResult)) {
|
|
315
|
-
return {
|
|
316
|
-
success: true,
|
|
317
|
-
data: clientResult.value,
|
|
318
|
-
__ac_id: this._actionId,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
success: false,
|
|
323
|
-
error: clientResult.error,
|
|
324
|
-
__ac_id: this._actionId,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
// --------------------------------------------------------------------------
|
|
328
|
-
// ERROR HANDLING
|
|
329
|
-
// --------------------------------------------------------------------------
|
|
330
|
-
/**
|
|
331
|
-
* Handles uncaught exceptions during action execution.
|
|
332
|
-
*/
|
|
333
|
-
_handleThrownError(error, customHandler) {
|
|
334
|
-
const caughtErrorResult = customHandler
|
|
335
|
-
? customHandler(error)
|
|
336
|
-
: createUnhandledErrorResult(this._actionId);
|
|
337
|
-
return caughtErrorResult;
|
|
338
|
-
}
|
|
339
|
-
// --------------------------------------------------------------------------
|
|
340
|
-
// VALIDATION
|
|
341
|
-
// --------------------------------------------------------------------------
|
|
342
|
-
/**
|
|
343
|
-
* Validates input using the shared helper.
|
|
344
|
-
*/
|
|
345
|
-
_validateInput(rawInput) {
|
|
346
|
-
return validateInput(this._schemas, this._config, rawInput, this._actionId);
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* Validates bound arguments using the configured bind schemas.
|
|
350
|
-
*/
|
|
351
|
-
_validateBindArgs(bindArgs) {
|
|
352
|
-
return validateBindArgs(this._schemas, this._config, bindArgs, this._actionId);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Validates output data using the configured output schema.
|
|
356
|
-
*/
|
|
357
|
-
_validateOutput(data) {
|
|
358
|
-
return validateOutput(this._schemas, this._config, data, this._actionId);
|
|
359
|
-
}
|
|
360
|
-
// --------------------------------------------------------------------------
|
|
361
|
-
// CALLBACKS
|
|
362
|
-
// --------------------------------------------------------------------------
|
|
363
|
-
/**
|
|
364
|
-
* Executes the onStart callback if defined.
|
|
365
|
-
*/
|
|
366
|
-
async _executeOnStartCallback(metadata) {
|
|
367
|
-
const callbacks = this._callbacks;
|
|
368
|
-
if (callbacks.onStart) {
|
|
369
|
-
await safeExecuteCallback(() => callbacks.onStart({ metadata }), "onStart", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Executes result-based lifecycle callbacks (onSuccess, onError, onSettled).
|
|
374
|
-
*/
|
|
375
|
-
async _executeResultCallbacks(result, metadata) {
|
|
376
|
-
const callbacks = this._callbacks;
|
|
377
|
-
// Success path
|
|
378
|
-
if (isOk(result)) {
|
|
379
|
-
await safeExecuteCallback(callbacks.onSuccess
|
|
380
|
-
? () => callbacks.onSuccess({ data: result.value, metadata })
|
|
381
|
-
: undefined, "onSuccess", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
382
|
-
}
|
|
383
|
-
// Error path
|
|
384
|
-
if (isErr(result)) {
|
|
385
|
-
await safeExecuteCallback(callbacks.onError
|
|
386
|
-
? () => callbacks.onError({ error: result.error, metadata })
|
|
387
|
-
: undefined, "onError", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
388
|
-
}
|
|
389
|
-
// onSettled always runs, regardless of result
|
|
390
|
-
const finalResult = this._toActionResult(result);
|
|
391
|
-
await safeExecuteCallback(callbacks.onSettled
|
|
392
|
-
? () => callbacks.onSettled({ result: finalResult, metadata })
|
|
393
|
-
: undefined, "onSettled", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
394
|
-
}
|
|
395
|
-
// --------------------------------------------------------------------------
|
|
396
|
-
// UTILITY METHODS
|
|
397
|
-
// --------------------------------------------------------------------------
|
|
398
|
-
/**
|
|
399
|
-
* Ensures a Result object has the correct action ID.
|
|
400
|
-
*/
|
|
401
|
-
_ensureResultActionId(result) {
|
|
402
|
-
if (!result.__ac_id || result.__ac_id === "unknown") {
|
|
403
|
-
return {
|
|
404
|
-
...result,
|
|
405
|
-
__ac_id: this._actionId,
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
return result;
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Creates error functions that return a Result object when called by the action handler.
|
|
412
|
-
*/
|
|
413
|
-
_buildErrorFunctions() {
|
|
414
|
-
const errorFns = {};
|
|
415
|
-
for (const [key, errorDefFn] of Object.entries(this._errors)) {
|
|
416
|
-
errorFns[key] = ((...args) => err(errorDefFn(...args), this._actionId));
|
|
417
|
-
}
|
|
418
|
-
return errorFns;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
// ============================================================================
|
|
422
|
-
// ACTION BUILDER CLASS - Alternative fluent API syntax ending with craft()
|
|
423
|
-
// ============================================================================
|
|
424
|
-
class ActionBuilder {
|
|
425
|
-
_config;
|
|
426
|
-
_schemas;
|
|
427
|
-
_errors;
|
|
428
|
-
_callbacks;
|
|
429
|
-
_handler;
|
|
430
|
-
constructor(config, schemas, errors, callbacks, handler) {
|
|
431
|
-
this._config = config;
|
|
432
|
-
this._schemas = schemas;
|
|
433
|
-
this._errors = errors;
|
|
434
|
-
this._callbacks = callbacks;
|
|
435
|
-
this._handler = handler;
|
|
436
|
-
}
|
|
437
|
-
// --------------------------------------------------------------------------
|
|
438
|
-
// FLUENT API METHODS (same as Crafter)
|
|
439
|
-
// --------------------------------------------------------------------------
|
|
440
|
-
/**
|
|
441
|
-
* Defines configuration options for the action.
|
|
442
|
-
* Resets previously defined handler and callbacks.
|
|
443
|
-
*/
|
|
444
|
-
config(config) {
|
|
445
|
-
return new ActionBuilder(config, this._schemas, this._errors, {}, undefined);
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* Defines validation schemas for input, output, and bind arguments.
|
|
449
|
-
* Resets previously defined handler and callbacks.
|
|
450
|
-
*/
|
|
451
|
-
schemas(schemas) {
|
|
452
|
-
return new ActionBuilder(this._config, schemas, this._errors, {}, undefined);
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Defines error functions for returning typed errors from the handler.
|
|
456
|
-
* Resets previously defined handler and callbacks.
|
|
457
|
-
*/
|
|
458
|
-
errors(errors) {
|
|
459
|
-
return new ActionBuilder(this._config, this._schemas, errors, {}, undefined);
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Defines the handler function containing the server action's business logic.
|
|
463
|
-
* Resets previously defined callbacks.
|
|
464
|
-
*/
|
|
465
|
-
handler(fn) {
|
|
466
|
-
return new ActionBuilder(this._config, this._schemas, this._errors, {}, fn);
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Defines lifecycle callbacks to be triggered during the exection of an action.
|
|
470
|
-
* Must be called after handler() for correct type inference.
|
|
471
|
-
*/
|
|
472
|
-
callbacks(callbacks) {
|
|
473
|
-
return new ActionBuilder(this._config, this._schemas, this._errors, callbacks, this._handler);
|
|
474
|
-
}
|
|
475
|
-
// --------------------------------------------------------------------------
|
|
476
|
-
// CRAFT METHOD - Final step to create the action
|
|
477
|
-
// --------------------------------------------------------------------------
|
|
478
|
-
/**
|
|
479
|
-
* Builds and returns the final executable server action.
|
|
480
|
-
* This is the terminal method for the ActionBuilder fluent API.
|
|
481
|
-
*/
|
|
482
|
-
craft() {
|
|
483
|
-
// Convert ActionBuilder to Crafter and use existing Executor logic
|
|
484
|
-
const crafter = new Crafter(this._config, this._schemas, this._errors, this._callbacks, this._handler);
|
|
485
|
-
const executor = new Executor(crafter);
|
|
486
|
-
return executor.craft();
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* One of two entry points to the Actioncraft system.
|
|
491
|
-
* It provides you with an empty Crafter instance on which you can call any of the fluent
|
|
492
|
-
* Crafter methods to configure and define your action.
|
|
493
|
-
*
|
|
494
|
-
* Example Usage:
|
|
495
|
-
* ```ts
|
|
496
|
-
* const myAction = craft(async (action) => {
|
|
497
|
-
* return action
|
|
498
|
-
* .config(...)
|
|
499
|
-
* .schemas(...)
|
|
500
|
-
* .errors(...)
|
|
501
|
-
* .handler(...)
|
|
502
|
-
* .callbacks(...)
|
|
503
|
-
* });
|
|
504
|
-
* ```
|
|
505
|
-
*
|
|
506
|
-
* @param craftFn - The function that the user passes to `craft()` in order to build an action.
|
|
507
|
-
* @returns The fully-typed server action function that can be used in your app.
|
|
508
|
-
*/
|
|
509
|
-
export function craft(craftFn) {
|
|
510
|
-
const crafter = craftFn(new Crafter({}, {}, {}, {}, undefined));
|
|
511
|
-
// Handle async crafter functions
|
|
512
|
-
if (crafter instanceof Promise) {
|
|
513
|
-
return _craftAsync(crafter);
|
|
514
|
-
}
|
|
515
|
-
// Handle sync crafter functions
|
|
516
|
-
const executor = new Executor(crafter);
|
|
517
|
-
const craftedAction = executor.craft();
|
|
518
|
-
return craftedAction;
|
|
519
|
-
}
|
|
520
|
-
/**
|
|
521
|
-
* Internal helper function to handle async craft functions.
|
|
522
|
-
* Encapsulates the logic for creating async actions and preserving metadata.
|
|
523
|
-
*/
|
|
524
|
-
function _craftAsync(crafterPromise) {
|
|
525
|
-
// Resolve the crafter once and cache the resulting action to ensure consistent IDs
|
|
526
|
-
const actionPromise = crafterPromise.then((resolvedCrafter) => {
|
|
527
|
-
const executor = new Executor(resolvedCrafter);
|
|
528
|
-
return executor.craft();
|
|
529
|
-
});
|
|
530
|
-
// For async craft functions, we need to return an async action
|
|
531
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
532
|
-
const asyncAction = (async (...args) => {
|
|
533
|
-
// Wait for the cached action to be ready
|
|
534
|
-
const craftedAction = await actionPromise;
|
|
535
|
-
// Call the action with the user's arguments
|
|
536
|
-
return craftedAction(...args);
|
|
537
|
-
});
|
|
538
|
-
// We need to preserve the config and ID for the initial() function to work
|
|
539
|
-
// We'll use the same cached action to ensure consistent metadata
|
|
540
|
-
actionPromise.then((craftedAction) => {
|
|
541
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
542
|
-
asyncAction.__ac_config = craftedAction.__ac_config;
|
|
543
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
544
|
-
asyncAction.__ac_id = craftedAction.__ac_id;
|
|
545
|
-
});
|
|
546
|
-
return asyncAction;
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* One of two entry points to the Actioncraft system.
|
|
550
|
-
* Creates a new ActionBuilder instance for the fluent API that ends with craft().
|
|
551
|
-
* This provides an alternative syntax for building your server actions.
|
|
552
|
-
*
|
|
553
|
-
* Example Usage:
|
|
554
|
-
* ```ts
|
|
555
|
-
* const myAction = action()
|
|
556
|
-
* .config(...)
|
|
557
|
-
* .schemas(...)
|
|
558
|
-
* .errors(...)
|
|
559
|
-
* .handler(...)
|
|
560
|
-
* .callbacks(...)
|
|
561
|
-
* .craft();
|
|
562
|
-
* ```
|
|
563
|
-
*
|
|
564
|
-
* @returns A new ActionBuilder instance to start building your action.
|
|
565
|
-
*/
|
|
566
|
-
export function action() {
|
|
567
|
-
return new ActionBuilder({}, {}, {}, {}, undefined);
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Creates an appropriate initial state for any action based on its configuration.
|
|
571
|
-
* The initial state uses the action's real ID for consistency with actual results.
|
|
572
|
-
*
|
|
573
|
-
* For useActionState actions: returns StatefulApiResult with error and values
|
|
574
|
-
* For functional format actions: returns Result.err() with error
|
|
575
|
-
* For regular actions: returns ApiResult with error
|
|
576
|
-
*
|
|
577
|
-
* Usage:
|
|
578
|
-
* - useActionState: const [state, action] = useActionState(myAction, initial(myAction))
|
|
579
|
-
* - useState: const [state, setState] = useState(initial(myAction))
|
|
580
|
-
*/
|
|
581
|
-
export function initial(action) {
|
|
582
|
-
const error = {
|
|
583
|
-
type: EXTERNAL_ERROR_TYPES.INITIAL_STATE,
|
|
584
|
-
message: "Action has not been executed yet",
|
|
585
|
-
};
|
|
586
|
-
// Attempt to read the action ID created during craft()
|
|
587
|
-
const actionId =
|
|
588
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
589
|
-
action?.__ac_id ?? "unknown";
|
|
590
|
-
// Attempt to read the Actioncraft config attached during craft()
|
|
591
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
592
|
-
const cfg = action?.__ac_config;
|
|
593
|
-
// Functional format -> Result<_, _>
|
|
594
|
-
if (cfg?.resultFormat === "functional") {
|
|
595
|
-
return err(error, actionId);
|
|
596
|
-
}
|
|
597
|
-
// useActionState enabled -> StatefulApiResult
|
|
598
|
-
if (cfg?.useActionState) {
|
|
599
|
-
return {
|
|
600
|
-
success: false,
|
|
601
|
-
error,
|
|
602
|
-
values: undefined,
|
|
603
|
-
__ac_id: actionId,
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
// Default ApiResult shape
|
|
607
|
-
return {
|
|
608
|
-
success: false,
|
|
609
|
-
error,
|
|
610
|
-
__ac_id: actionId,
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
//# sourceMappingURL=actioncraft.js.map
|
package/dist/actioncraft.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actioncraft.js","sourceRoot":"","sources":["../src/actioncraft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAIL,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAQ9E,OAAO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