@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/classes/executor.js
DELETED
|
@@ -1,354 +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 {} from "../types/errors.js";
|
|
7
|
-
import { err, isOk, isResultOk, isResultErr, isErr } from "../types/result.js";
|
|
8
|
-
import { INTERNAL } from "./internal.js";
|
|
9
|
-
import { unstable_rethrow } from "next/navigation.js";
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// EXECUTOR CLASS - Build and execute your action
|
|
12
|
-
// ============================================================================
|
|
13
|
-
export class Executor {
|
|
14
|
-
_config;
|
|
15
|
-
_schemas;
|
|
16
|
-
_errors;
|
|
17
|
-
_callbacks;
|
|
18
|
-
_handler;
|
|
19
|
-
_actionId;
|
|
20
|
-
constructor(crafter) {
|
|
21
|
-
this._config = crafter[INTERNAL]().config;
|
|
22
|
-
this._schemas = crafter[INTERNAL]().schemas;
|
|
23
|
-
this._errors = crafter[INTERNAL]().errors;
|
|
24
|
-
this._callbacks = crafter[INTERNAL]().callbacks;
|
|
25
|
-
this._handler = crafter[INTERNAL]().handler;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Builds and returns the final executable server action.
|
|
29
|
-
*/
|
|
30
|
-
craft() {
|
|
31
|
-
if (!this._handler) {
|
|
32
|
-
throw new Error("A handler implementation is required");
|
|
33
|
-
}
|
|
34
|
-
// Generate a unique ID for this action instance
|
|
35
|
-
this._actionId = this._generateActionId();
|
|
36
|
-
const craftedAction = (...args) => {
|
|
37
|
-
return this._runAction(args);
|
|
38
|
-
};
|
|
39
|
-
// Attach the action's config and ID for runtime inspection
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
craftedAction.__ac_config = this._config;
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
craftedAction.__ac_id = this._actionId;
|
|
44
|
-
return craftedAction;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Generates a unique identifier for this action instance.
|
|
48
|
-
*/
|
|
49
|
-
_generateActionId() {
|
|
50
|
-
return crypto.randomUUID();
|
|
51
|
-
}
|
|
52
|
-
// --------------------------------------------------------------------------
|
|
53
|
-
// ACTION EXECUTION
|
|
54
|
-
// --------------------------------------------------------------------------
|
|
55
|
-
/**
|
|
56
|
-
* Orchestrates action execution (validation, business logic, callbacks, and result formatting.)
|
|
57
|
-
*/
|
|
58
|
-
async _runAction(args) {
|
|
59
|
-
// We know these exist because craft() creates/verifies them
|
|
60
|
-
const handler = this._handler;
|
|
61
|
-
const actionId = this._actionId;
|
|
62
|
-
// Extract bindArgs, prevState, and input from the raw args
|
|
63
|
-
const { bindArgs: rawBindArgs, prevState, input: rawInput, } = this._extractActionArgs(args);
|
|
64
|
-
// Check for custom error handler
|
|
65
|
-
const handleThrownErrorFn = this._config.handleThrownError
|
|
66
|
-
? (error) => err(this._config.handleThrownError(error), actionId)
|
|
67
|
-
: null;
|
|
68
|
-
// Track validation state for error handling
|
|
69
|
-
let validatedInput = undefined;
|
|
70
|
-
let validatedBindArgs = undefined;
|
|
71
|
-
try {
|
|
72
|
-
// Execute onStart callback before any processing
|
|
73
|
-
await this._executeOnStartCallback({
|
|
74
|
-
rawInput,
|
|
75
|
-
rawBindArgs,
|
|
76
|
-
prevState,
|
|
77
|
-
validatedInput: undefined,
|
|
78
|
-
validatedBindArgs: undefined,
|
|
79
|
-
actionId,
|
|
80
|
-
});
|
|
81
|
-
// Validate input and return on failure
|
|
82
|
-
const inputValidation = await this._validateInput(rawInput);
|
|
83
|
-
if (!isOk(inputValidation)) {
|
|
84
|
-
await this._executeResultCallbacks(inputValidation, {
|
|
85
|
-
rawInput,
|
|
86
|
-
rawBindArgs,
|
|
87
|
-
prevState,
|
|
88
|
-
validatedInput,
|
|
89
|
-
validatedBindArgs,
|
|
90
|
-
actionId,
|
|
91
|
-
});
|
|
92
|
-
return this._toActionResult(inputValidation, rawInput);
|
|
93
|
-
}
|
|
94
|
-
// Update validation state
|
|
95
|
-
validatedInput = inputValidation.value;
|
|
96
|
-
// Validate bound arguments and return on failure
|
|
97
|
-
const bindArgsValidation = await this._validateBindArgs(rawBindArgs);
|
|
98
|
-
if (!isOk(bindArgsValidation)) {
|
|
99
|
-
await this._executeResultCallbacks(bindArgsValidation, {
|
|
100
|
-
rawInput,
|
|
101
|
-
rawBindArgs,
|
|
102
|
-
prevState,
|
|
103
|
-
validatedInput,
|
|
104
|
-
validatedBindArgs,
|
|
105
|
-
actionId,
|
|
106
|
-
});
|
|
107
|
-
return this._toActionResult(bindArgsValidation, rawInput);
|
|
108
|
-
}
|
|
109
|
-
// Update validation state
|
|
110
|
-
validatedBindArgs = bindArgsValidation.value;
|
|
111
|
-
// Execute the user's action handler
|
|
112
|
-
const handlerResult = await handler({
|
|
113
|
-
input: inputValidation.value,
|
|
114
|
-
bindArgs: bindArgsValidation.value,
|
|
115
|
-
errors: this._buildErrorFunctions(),
|
|
116
|
-
metadata: {
|
|
117
|
-
rawInput,
|
|
118
|
-
rawBindArgs,
|
|
119
|
-
prevState,
|
|
120
|
-
actionId,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
// Return on `undefined` (implicit return error)
|
|
124
|
-
if (handlerResult === undefined) {
|
|
125
|
-
const implicitReturnError = createImplicitReturnErrorResult(actionId);
|
|
126
|
-
await this._executeResultCallbacks(implicitReturnError, {
|
|
127
|
-
rawInput,
|
|
128
|
-
rawBindArgs,
|
|
129
|
-
prevState,
|
|
130
|
-
validatedInput,
|
|
131
|
-
validatedBindArgs,
|
|
132
|
-
actionId,
|
|
133
|
-
});
|
|
134
|
-
return this._toActionResult(implicitReturnError, rawInput);
|
|
135
|
-
}
|
|
136
|
-
let finalResult;
|
|
137
|
-
// Process different return types from the action
|
|
138
|
-
if (isResultErr(handlerResult)) {
|
|
139
|
-
// Ensure error result has correct action ID
|
|
140
|
-
finalResult = this._ensureResultActionId(handlerResult);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
const outputData = isResultOk(handlerResult)
|
|
144
|
-
? handlerResult.value
|
|
145
|
-
: handlerResult;
|
|
146
|
-
finalResult = await this._validateOutput(outputData);
|
|
147
|
-
}
|
|
148
|
-
// Execute callbacks and return final result
|
|
149
|
-
await this._executeResultCallbacks(finalResult, {
|
|
150
|
-
rawInput,
|
|
151
|
-
rawBindArgs,
|
|
152
|
-
prevState,
|
|
153
|
-
validatedInput,
|
|
154
|
-
validatedBindArgs,
|
|
155
|
-
actionId,
|
|
156
|
-
});
|
|
157
|
-
// Use validated input for the values field on a successful run
|
|
158
|
-
const inputForValues = isOk(finalResult)
|
|
159
|
-
? this._schemas.inputSchema
|
|
160
|
-
? inputValidation.value
|
|
161
|
-
: rawInput
|
|
162
|
-
: rawInput;
|
|
163
|
-
return this._toActionResult(finalResult, inputForValues);
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
// Re-throw Next.js framework errors
|
|
167
|
-
unstable_rethrow(error);
|
|
168
|
-
// Handle unexpected thrown errors
|
|
169
|
-
try {
|
|
170
|
-
const errorResult = this._handleThrownError(error, handleThrownErrorFn);
|
|
171
|
-
await this._executeResultCallbacks(errorResult, {
|
|
172
|
-
rawInput,
|
|
173
|
-
rawBindArgs,
|
|
174
|
-
prevState,
|
|
175
|
-
validatedInput,
|
|
176
|
-
validatedBindArgs,
|
|
177
|
-
actionId,
|
|
178
|
-
});
|
|
179
|
-
return this._toActionResult(errorResult, rawInput);
|
|
180
|
-
}
|
|
181
|
-
catch (handlerError) {
|
|
182
|
-
// If we catch another error here, then we're done
|
|
183
|
-
log(this._config.logger, "warn", "Error handling failure - both primary error and error handler threw", { primaryError: error, handlerError });
|
|
184
|
-
return this._toActionResult(createUnhandledErrorResult(actionId), rawInput);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Extracts bind arguments, previous state, and input from raw action arguments.
|
|
190
|
-
*/
|
|
191
|
-
_extractActionArgs(args) {
|
|
192
|
-
const numBindSchemas = this._schemas.bindSchemas?.length ?? 0;
|
|
193
|
-
if (this._config.useActionState) {
|
|
194
|
-
return {
|
|
195
|
-
bindArgs: args.slice(0, numBindSchemas),
|
|
196
|
-
prevState: args[numBindSchemas],
|
|
197
|
-
input: args[numBindSchemas + 1],
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
// For regular actions (non-useActionState), the input is the first argument after bind args
|
|
201
|
-
// If there are no bind schemas, the input is the first argument (args[0])
|
|
202
|
-
return {
|
|
203
|
-
bindArgs: args.slice(0, numBindSchemas),
|
|
204
|
-
// When useActionState is disabled the prevState parameter is never
|
|
205
|
-
// present, so we cast to never (or undefined) to satisfy the type.
|
|
206
|
-
prevState: undefined,
|
|
207
|
-
input: args[numBindSchemas],
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
// --------------------------------------------------------------------------
|
|
211
|
-
// RESULT TRANSFORMATION
|
|
212
|
-
// --------------------------------------------------------------------------
|
|
213
|
-
/**
|
|
214
|
-
* Transforms internal Result objects to client-facing action result format.
|
|
215
|
-
*/
|
|
216
|
-
_toActionResult(result, inputForValues) {
|
|
217
|
-
// Convert internal errors to client-facing errors
|
|
218
|
-
const clientResult = isOk(result)
|
|
219
|
-
? result
|
|
220
|
-
: err(convertToClientError(result.error), this._actionId);
|
|
221
|
-
// Handle useActionState format (always returns StatefulApiResult)
|
|
222
|
-
if (this._config.useActionState) {
|
|
223
|
-
if (isOk(clientResult)) {
|
|
224
|
-
const successValues = this._schemas.inputSchema
|
|
225
|
-
? inputForValues
|
|
226
|
-
: serializeRawInput(inputForValues);
|
|
227
|
-
return {
|
|
228
|
-
success: true,
|
|
229
|
-
data: clientResult.value,
|
|
230
|
-
values: successValues,
|
|
231
|
-
__ac_id: this._actionId,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
return {
|
|
235
|
-
success: false,
|
|
236
|
-
error: clientResult.error,
|
|
237
|
-
values: serializeRawInput(inputForValues),
|
|
238
|
-
__ac_id: this._actionId,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
const format = this._config.resultFormat ?? "api";
|
|
242
|
-
// Return functional format if configured
|
|
243
|
-
if (format === "functional") {
|
|
244
|
-
return clientResult;
|
|
245
|
-
}
|
|
246
|
-
// Default API format
|
|
247
|
-
if (isOk(clientResult)) {
|
|
248
|
-
return {
|
|
249
|
-
success: true,
|
|
250
|
-
data: clientResult.value,
|
|
251
|
-
__ac_id: this._actionId,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
return {
|
|
255
|
-
success: false,
|
|
256
|
-
error: clientResult.error,
|
|
257
|
-
__ac_id: this._actionId,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
// --------------------------------------------------------------------------
|
|
261
|
-
// ERROR HANDLING
|
|
262
|
-
// --------------------------------------------------------------------------
|
|
263
|
-
/**
|
|
264
|
-
* Handles uncaught exceptions during action execution.
|
|
265
|
-
*/
|
|
266
|
-
_handleThrownError(error, customHandler) {
|
|
267
|
-
const caughtErrorResult = customHandler
|
|
268
|
-
? customHandler(error)
|
|
269
|
-
: createUnhandledErrorResult(this._actionId);
|
|
270
|
-
return caughtErrorResult;
|
|
271
|
-
}
|
|
272
|
-
// --------------------------------------------------------------------------
|
|
273
|
-
// VALIDATION
|
|
274
|
-
// --------------------------------------------------------------------------
|
|
275
|
-
/**
|
|
276
|
-
* Validates input using the shared helper.
|
|
277
|
-
*/
|
|
278
|
-
_validateInput(rawInput) {
|
|
279
|
-
return validateInput(this._schemas, this._config, rawInput, this._actionId);
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Validates bound arguments using the configured bind schemas.
|
|
283
|
-
*/
|
|
284
|
-
_validateBindArgs(bindArgs) {
|
|
285
|
-
return validateBindArgs(this._schemas, this._config, bindArgs, this._actionId);
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Validates output data using the configured output schema.
|
|
289
|
-
*/
|
|
290
|
-
_validateOutput(data) {
|
|
291
|
-
return validateOutput(this._schemas, this._config, data, this._actionId);
|
|
292
|
-
}
|
|
293
|
-
// --------------------------------------------------------------------------
|
|
294
|
-
// CALLBACKS
|
|
295
|
-
// --------------------------------------------------------------------------
|
|
296
|
-
/**
|
|
297
|
-
* Executes the onStart callback if defined.
|
|
298
|
-
*/
|
|
299
|
-
async _executeOnStartCallback(metadata) {
|
|
300
|
-
const callbacks = this._callbacks;
|
|
301
|
-
if (callbacks.onStart) {
|
|
302
|
-
await safeExecuteCallback(() => callbacks.onStart({ metadata }), "onStart", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Executes result-based lifecycle callbacks (onSuccess, onError, onSettled).
|
|
307
|
-
*/
|
|
308
|
-
async _executeResultCallbacks(result, metadata) {
|
|
309
|
-
const callbacks = this._callbacks;
|
|
310
|
-
// Success path
|
|
311
|
-
if (isOk(result)) {
|
|
312
|
-
await safeExecuteCallback(callbacks.onSuccess
|
|
313
|
-
? () => callbacks.onSuccess({ data: result.value, metadata })
|
|
314
|
-
: undefined, "onSuccess", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
315
|
-
}
|
|
316
|
-
// Error path
|
|
317
|
-
if (isErr(result)) {
|
|
318
|
-
await safeExecuteCallback(callbacks.onError
|
|
319
|
-
? () => callbacks.onError({ error: result.error, metadata })
|
|
320
|
-
: undefined, "onError", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
321
|
-
}
|
|
322
|
-
// onSettled always runs, regardless of result
|
|
323
|
-
const finalResult = this._toActionResult(result);
|
|
324
|
-
await safeExecuteCallback(callbacks.onSettled
|
|
325
|
-
? () => callbacks.onSettled({ result: finalResult, metadata })
|
|
326
|
-
: undefined, "onSettled", (level, msg, details) => log(this._config.logger, level, msg, details));
|
|
327
|
-
}
|
|
328
|
-
// --------------------------------------------------------------------------
|
|
329
|
-
// UTILITY METHODS
|
|
330
|
-
// --------------------------------------------------------------------------
|
|
331
|
-
/**
|
|
332
|
-
* Ensures a Result object has the correct action ID.
|
|
333
|
-
*/
|
|
334
|
-
_ensureResultActionId(result) {
|
|
335
|
-
if (!result.__ac_id || result.__ac_id === "unknown") {
|
|
336
|
-
return {
|
|
337
|
-
...result,
|
|
338
|
-
__ac_id: this._actionId,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
return result;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Creates error functions that return a Result object when called by the action handler.
|
|
345
|
-
*/
|
|
346
|
-
_buildErrorFunctions() {
|
|
347
|
-
const errorFns = {};
|
|
348
|
-
for (const [key, errorDefFn] of Object.entries(this._errors)) {
|
|
349
|
-
errorFns[key] = ((...args) => err(errorDefFn(...args), this._actionId));
|
|
350
|
-
}
|
|
351
|
-
return errorFns;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
//# sourceMappingURL=executor.js.map
|
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U,CAAC,GAAG,IAAI,CAAC,EACnB,IAAI,CAAC,SAAU,CAChB,CAA2C,CAAC;QACjD,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
package/dist/core/callbacks.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executes a callback function safely.
|
|
3
|
-
* Any error thrown by the callback is caught and logged (if a logFn is supplied)
|
|
4
|
-
* so that it never interrupts the main action flow.
|
|
5
|
-
*/
|
|
6
|
-
export declare function safeExecuteCallback(callback: (() => Promise<void> | void) | undefined, callbackName: string, logFn?: (level: "error" | "warn", message: string, details?: unknown) => void): Promise<void>;
|
package/dist/core/callbacks.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Executes a callback function safely.
|
|
3
|
-
* Any error thrown by the callback is caught and logged (if a logFn is supplied)
|
|
4
|
-
* so that it never interrupts the main action flow.
|
|
5
|
-
*/
|
|
6
|
-
export async function safeExecuteCallback(callback, callbackName,
|
|
7
|
-
// Logger accepts (level, message, details?)
|
|
8
|
-
logFn) {
|
|
9
|
-
if (!callback)
|
|
10
|
-
return;
|
|
11
|
-
try {
|
|
12
|
-
await callback();
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
if (logFn) {
|
|
16
|
-
logFn("error", `Error in ${callbackName} callback`, error);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=callbacks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"callbacks.js","sourceRoot":"","sources":["../../src/core/callbacks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAkD,EAClD,YAAoB;AACpB,4CAA4C;AAC5C,KAA6E;IAE7E,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEtB,IAAI,CAAC;QACH,MAAM,QAAQ,EAAE,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,OAAO,EAAE,YAAY,YAAY,WAAW,EAAE,KAAK,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/core/errors.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from "../standard-schema.js";
|
|
2
|
-
import { EXTERNAL_ERROR_TYPES, INTERNAL_ERROR_TYPES } from "../types/errors.js";
|
|
3
|
-
import type { UnhandledError, ImplicitReturnError, InternalLogicError, ValidationErrorFormat } from "../types/errors.js";
|
|
4
|
-
import type { Result } from "../types/result.js";
|
|
5
|
-
export declare const UNHANDLED_ERROR: UnhandledError;
|
|
6
|
-
export declare const IMPLICIT_RETURN_ERROR: ImplicitReturnError;
|
|
7
|
-
/**
|
|
8
|
-
* Creates internal logic errors with custom messages.
|
|
9
|
-
*/
|
|
10
|
-
export declare const createInternalLogicError: (message: string) => InternalLogicError;
|
|
11
|
-
/**
|
|
12
|
-
* Creates Result objects for unhandled errors.
|
|
13
|
-
*/
|
|
14
|
-
export declare function createUnhandledErrorResult<TData = never, TError = UnhandledError>(actionId: string): Result<TData, TError>;
|
|
15
|
-
/**
|
|
16
|
-
* Creates Result objects for implicit return errors.
|
|
17
|
-
*/
|
|
18
|
-
export declare function createImplicitReturnErrorResult<TData = never, TError = ImplicitReturnError>(actionId: string): Result<TData, TError>;
|
|
19
|
-
/**
|
|
20
|
-
* Formats validation issues into structured error objects based on the configured format.
|
|
21
|
-
*/
|
|
22
|
-
export declare function formatValidationIssues(issues: readonly StandardSchemaV1.Issue[], format: "flattened" | "nested"): ValidationErrorFormat;
|
|
23
|
-
type ValidationErrorType = typeof EXTERNAL_ERROR_TYPES.INPUT_VALIDATION | typeof EXTERNAL_ERROR_TYPES.BIND_ARGS_VALIDATION | typeof INTERNAL_ERROR_TYPES.OUTPUT_VALIDATION;
|
|
24
|
-
/**
|
|
25
|
-
* Creates validation error objects.
|
|
26
|
-
*/
|
|
27
|
-
export declare function createValidationError<TError>(type: ValidationErrorType, message: string, errorStructure: ValidationErrorFormat): TError;
|
|
28
|
-
export {};
|
package/dist/core/errors.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { EXTERNAL_ERROR_TYPES, INTERNAL_ERROR_TYPES } from "../types/errors.js";
|
|
2
|
-
import { err } from "../types/result.js";
|
|
3
|
-
// ===========================================================================
|
|
4
|
-
// CONSTANTS
|
|
5
|
-
// ===========================================================================
|
|
6
|
-
export const UNHANDLED_ERROR = {
|
|
7
|
-
type: EXTERNAL_ERROR_TYPES.UNHANDLED,
|
|
8
|
-
message: "An unhandled error occurred",
|
|
9
|
-
};
|
|
10
|
-
export const IMPLICIT_RETURN_ERROR = {
|
|
11
|
-
type: INTERNAL_ERROR_TYPES.IMPLICIT_RETURN,
|
|
12
|
-
message: "Action handler must return a value",
|
|
13
|
-
};
|
|
14
|
-
// ===========================================================================
|
|
15
|
-
// FACTORY HELPERS
|
|
16
|
-
// ===========================================================================
|
|
17
|
-
/**
|
|
18
|
-
* Creates internal logic errors with custom messages.
|
|
19
|
-
*/
|
|
20
|
-
export const createInternalLogicError = (message) => ({
|
|
21
|
-
type: INTERNAL_ERROR_TYPES.INTERNAL_LOGIC,
|
|
22
|
-
message,
|
|
23
|
-
});
|
|
24
|
-
/**
|
|
25
|
-
* Creates Result objects for unhandled errors.
|
|
26
|
-
*/
|
|
27
|
-
export function createUnhandledErrorResult(actionId) {
|
|
28
|
-
return err({ ...UNHANDLED_ERROR }, actionId);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Creates Result objects for implicit return errors.
|
|
32
|
-
*/
|
|
33
|
-
export function createImplicitReturnErrorResult(actionId) {
|
|
34
|
-
return err({ ...IMPLICIT_RETURN_ERROR }, actionId);
|
|
35
|
-
}
|
|
36
|
-
// ===========================================================================
|
|
37
|
-
// VALIDATION-ERROR STRUCTURING HELPERS
|
|
38
|
-
// ===========================================================================
|
|
39
|
-
/**
|
|
40
|
-
* Normalises Standard Schema path segments to string|number for serialization.
|
|
41
|
-
*/
|
|
42
|
-
function _normalisePath(path) {
|
|
43
|
-
if (!path)
|
|
44
|
-
return [];
|
|
45
|
-
return path
|
|
46
|
-
.map((segment) => {
|
|
47
|
-
if (typeof segment === "symbol")
|
|
48
|
-
return undefined;
|
|
49
|
-
if (typeof segment === "object" && segment !== null && "key" in segment) {
|
|
50
|
-
const key = segment.key;
|
|
51
|
-
return typeof key === "symbol" ? undefined : key;
|
|
52
|
-
}
|
|
53
|
-
return segment;
|
|
54
|
-
})
|
|
55
|
-
.filter((p) => p !== undefined);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Formats validation issues into structured error objects based on the configured format.
|
|
59
|
-
*/
|
|
60
|
-
export function formatValidationIssues(issues, format) {
|
|
61
|
-
if (format === "nested") {
|
|
62
|
-
const formErrors = [];
|
|
63
|
-
const fieldErrors = {};
|
|
64
|
-
for (const issue of issues) {
|
|
65
|
-
const currentPath = _normalisePath(issue.path);
|
|
66
|
-
if (currentPath.length === 0) {
|
|
67
|
-
formErrors.push(issue.message);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const pathKey = currentPath.join(".");
|
|
71
|
-
if (!fieldErrors[pathKey])
|
|
72
|
-
fieldErrors[pathKey] = [];
|
|
73
|
-
fieldErrors[pathKey].push(issue.message);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return { formErrors, fieldErrors };
|
|
77
|
-
}
|
|
78
|
-
// Default to 'flattened'
|
|
79
|
-
return {
|
|
80
|
-
issues: issues.map(({ path, message }) => ({
|
|
81
|
-
path: _normalisePath(path),
|
|
82
|
-
message,
|
|
83
|
-
})),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
function _buildFlattenedValidationError(type, message, issues) {
|
|
87
|
-
return { type, message, issues };
|
|
88
|
-
}
|
|
89
|
-
function _buildNestedValidationError(type, message, formErrors, fieldErrors) {
|
|
90
|
-
return { type, message, formErrors, fieldErrors };
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Creates validation error objects.
|
|
94
|
-
*/
|
|
95
|
-
export function createValidationError(type, message, errorStructure) {
|
|
96
|
-
if ("issues" in errorStructure) {
|
|
97
|
-
return _buildFlattenedValidationError(type, message, errorStructure.issues);
|
|
98
|
-
}
|
|
99
|
-
return _buildNestedValidationError(type, message, errorStructure.formErrors, errorStructure.fieldErrors);
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/core/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAQhF,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAEzC,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,CAAC,MAAM,eAAe,GAAmB;IAC7C,IAAI,EAAE,oBAAoB,CAAC,SAAS;IACpC,OAAO,EAAE,6BAA6B;CAC9B,CAAC;AAEX,MAAM,CAAC,MAAM,qBAAqB,GAAwB;IACxD,IAAI,EAAE,oBAAoB,CAAC,eAAe;IAC1C,OAAO,EAAE,oCAAoC;CACrC,CAAC;AAEX,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,OAAe,EACK,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,oBAAoB,CAAC,cAAc;IACzC,OAAO;CACR,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,0BAA0B,CAGxC,QAAgB;IAChB,OAAO,GAAG,CAAC,EAAE,GAAG,eAAe,EAAE,EAAE,QAAQ,CAA0B,CAA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type { CrafterConfig } from "../types/crafter.js";
|
|
2
|
-
/**
|
|
3
|
-
* Lightweight wrapper around the optional logger in `CrafterConfig`.
|
|
4
|
-
*/
|
|
5
|
-
export type Logger = NonNullable<CrafterConfig["logger"]>;
|
|
6
|
-
export declare function log(logger: CrafterConfig["logger"], level: "error" | "warn", message: string, details?: unknown): void;
|
package/dist/core/logging.js
DELETED
package/dist/core/logging.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { InferSerializedErrorValues } from "../types/actions.js";
|
|
2
|
-
import type { CrafterSchemas } from "../types/crafter.js";
|
|
3
|
-
import type { CrafterConfig, CrafterErrors } from "../types/crafter.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>;
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { CrafterConfig, CrafterSchemas, CrafterErrors } from "../types/crafter.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, actionId: 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 CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors>(schemas: TSchemas, config: TConfig, bindArgs: InferRawBindArgs<TSchemas>, actionId: 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 CrafterConfig, TSchemas extends CrafterSchemas, TErrors extends CrafterErrors, TData>(schemas: TSchemas, config: TConfig, data: TData, actionId: string): Promise<Result<TData, AllPossibleErrors<TErrors, TConfig, TSchemas>>>;
|