@flight-framework/core 0.6.5 → 0.6.6
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/dist/actions/index.d.ts +1 -58
- package/dist/actions/index.js +1 -1
- package/dist/{chunk-XGP3C2ZE.js → chunk-3QP3E7HS.js} +4 -112
- package/dist/chunk-3QP3E7HS.js.map +1 -0
- package/dist/chunk-PL37KFRJ.js +3 -0
- package/dist/chunk-PL37KFRJ.js.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.js +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +28 -83
- package/dist/utils/index.js +1 -1
- package/package.json +3 -13
- package/dist/chunk-J7WEZXWH.js +0 -14
- package/dist/chunk-J7WEZXWH.js.map +0 -1
- package/dist/chunk-MFUJN7RV.js +0 -20
- package/dist/chunk-MFUJN7RV.js.map +0 -1
- package/dist/chunk-WF46NESN.js +0 -67
- package/dist/chunk-WF46NESN.js.map +0 -1
- package/dist/chunk-XGP3C2ZE.js.map +0 -1
- package/dist/env-9do2c6yn.d.ts +0 -42
- package/dist/plugins/env-plugin.d.ts +0 -47
- package/dist/plugins/env-plugin.js +0 -3
- package/dist/plugins/env-plugin.js.map +0 -1
- package/dist/plugins/index.d.ts +0 -221
- package/dist/plugins/index.js +0 -192
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/server-boundary-plugin.d.ts +0 -40
- package/dist/plugins/server-boundary-plugin.js +0 -3
- package/dist/plugins/server-boundary-plugin.js.map +0 -1
package/dist/actions/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @flight-framework/core - Action Middleware
|
|
5
3
|
*
|
|
@@ -635,61 +633,6 @@ declare function createQueueManager(options: {
|
|
|
635
633
|
retryFailed: () => Promise<void>;
|
|
636
634
|
};
|
|
637
635
|
|
|
638
|
-
/**
|
|
639
|
-
* @flight-framework/core - Server Actions Vite Plugin
|
|
640
|
-
*
|
|
641
|
-
* Transforms files with 'use server' directive.
|
|
642
|
-
* Similar to React 19 / Next.js server actions compilation.
|
|
643
|
-
*/
|
|
644
|
-
|
|
645
|
-
interface ServerActionsPluginOptions {
|
|
646
|
-
/** Include patterns */
|
|
647
|
-
include?: string[];
|
|
648
|
-
/** Exclude patterns */
|
|
649
|
-
exclude?: string[];
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Vite plugin for server actions transformation
|
|
653
|
-
*
|
|
654
|
-
* @example
|
|
655
|
-
* ```typescript
|
|
656
|
-
* // vite.config.ts
|
|
657
|
-
* import { serverActionsPlugin } from '@flight-framework/core/actions';
|
|
658
|
-
*
|
|
659
|
-
* export default {
|
|
660
|
-
* plugins: [serverActionsPlugin()],
|
|
661
|
-
* };
|
|
662
|
-
* ```
|
|
663
|
-
*/
|
|
664
|
-
declare function serverActionsPlugin(options?: ServerActionsPluginOptions): Plugin;
|
|
665
|
-
/**
|
|
666
|
-
* Create a client-side action caller
|
|
667
|
-
*
|
|
668
|
-
* @example
|
|
669
|
-
* ```typescript
|
|
670
|
-
* // In client component
|
|
671
|
-
* import { createActionCaller } from '@flight-framework/core/actions';
|
|
672
|
-
*
|
|
673
|
-
* const submitForm = createActionCaller('action_abc123');
|
|
674
|
-
*
|
|
675
|
-
* // Usage
|
|
676
|
-
* const result = await submitForm({ name: 'John' });
|
|
677
|
-
* ```
|
|
678
|
-
*/
|
|
679
|
-
declare function createActionCaller<TArgs extends unknown[], TResult>(actionId: string): (...args: TArgs) => Promise<TResult>;
|
|
680
|
-
/**
|
|
681
|
-
* Create a form action for HTML forms
|
|
682
|
-
*
|
|
683
|
-
* @example
|
|
684
|
-
* ```tsx
|
|
685
|
-
* <form action={formAction('action_abc123')}>
|
|
686
|
-
* <input name="email" />
|
|
687
|
-
* <button type="submit">Submit</button>
|
|
688
|
-
* </form>
|
|
689
|
-
* ```
|
|
690
|
-
*/
|
|
691
|
-
declare function formAction(actionId: string): string;
|
|
692
|
-
|
|
693
636
|
/**
|
|
694
637
|
* @flight-framework/core - Server Actions
|
|
695
638
|
*
|
|
@@ -797,4 +740,4 @@ declare function createActionReference(actionId: string): string;
|
|
|
797
740
|
*/
|
|
798
741
|
declare function handleActionRequest(request: Request): Promise<Response>;
|
|
799
742
|
|
|
800
|
-
export { type Action, type ActionContext, type ActionMiddleware, type ActionMiddlewareHandler, type ActionNext, type ActionResult, type CookieOptions, type CreateMiddlewareOptions, type FormActionData, type QueueStatus, type QueueStorageAdapter, type QueuedAction, type QueuedActionEntry, type QueuedActionOptions, type QueuedActionResult, RedirectError, type RetryStrategy, type ServerAction, type
|
|
743
|
+
export { type Action, type ActionContext, type ActionMiddleware, type ActionMiddlewareHandler, type ActionNext, type ActionResult, type CookieOptions, type CreateMiddlewareOptions, type FormActionData, type QueueStatus, type QueueStorageAdapter, type QueuedAction, type QueuedActionEntry, type QueuedActionOptions, type QueuedActionResult, RedirectError, type RetryStrategy, type ServerAction, type StreamController, type StreamItem, type StreamProgress, type StreamResult, type StreamableAction, type StreamableActionOptions, type StreamableGenerator, clearActions, collectStream, cookies, createActionContext, createActionMiddleware, createActionReference, createLoggingMiddleware, createMemoryAdapter, createProgressReporter, createQueueManager, createQueuedAction, createRetryMiddleware, createStreamableAction, createTimingMiddleware, defaultRetryStrategy, executeAction, executeFormAction, executeWithMiddleware, exponentialBackoff, fixedDelay, generateActionId, getAction, getAllActions, handleActionRequest, isRedirectError, parseFormData, pipeline, redirect, registerAction, responseToStream, streamToResponse };
|
package/dist/actions/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { RedirectError, clearActions, collectStream, cookies,
|
|
1
|
+
export { RedirectError, clearActions, collectStream, cookies, createActionContext, createActionMiddleware, createActionReference, createLoggingMiddleware, createMemoryAdapter, createProgressReporter, createQueueManager, createQueuedAction, createRetryMiddleware, createStreamableAction, createTimingMiddleware, defaultRetryStrategy, executeAction, executeFormAction, executeWithMiddleware, exponentialBackoff, fixedDelay, generateActionId, getAction, getAllActions, handleActionRequest, isRedirectError, parseFormData, pipeline, redirect, registerAction, responseToStream, streamToResponse } from '../chunk-3QP3E7HS.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -520,117 +520,9 @@ function createQueueManager(options) {
|
|
|
520
520
|
};
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
-
// src/actions/plugin.ts
|
|
524
|
-
function serverActionsPlugin(options = {}) {
|
|
525
|
-
const {
|
|
526
|
-
include = ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"],
|
|
527
|
-
exclude = ["**/node_modules/**"]
|
|
528
|
-
} = options;
|
|
529
|
-
return {
|
|
530
|
-
name: "flight:server-actions",
|
|
531
|
-
async transform(code, id) {
|
|
532
|
-
if (exclude.some((pattern) => id.includes(pattern.replace("**/", "")))) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
if (!hasUseServerDirective(code)) {
|
|
536
|
-
return null;
|
|
537
|
-
}
|
|
538
|
-
const transformed = transformServerActions(code, id);
|
|
539
|
-
return {
|
|
540
|
-
code: transformed,
|
|
541
|
-
map: null
|
|
542
|
-
// TODO: Generate source map
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
var USE_SERVER_REGEX = /^(['"])use server\1;?\s*$/m;
|
|
548
|
-
var FUNCTION_REGEX = /^(export\s+)?(async\s+)?function\s+(\w+)/gm;
|
|
549
|
-
var ARROW_FUNCTION_REGEX = /^(export\s+)?(const|let)\s+(\w+)\s*=\s*(async\s+)?\(/gm;
|
|
550
|
-
function hasUseServerDirective(code) {
|
|
551
|
-
return USE_SERVER_REGEX.test(code);
|
|
552
|
-
}
|
|
553
|
-
function transformServerActions(code, filePath) {
|
|
554
|
-
const isFileLevel = code.trim().startsWith("'use server'") || code.trim().startsWith('"use server"');
|
|
555
|
-
if (isFileLevel) {
|
|
556
|
-
return transformFileLevelActions(code, filePath);
|
|
557
|
-
}
|
|
558
|
-
return transformInlineActions(code, filePath);
|
|
559
|
-
}
|
|
560
|
-
function transformFileLevelActions(code, filePath) {
|
|
561
|
-
const transformed = code.replace(USE_SERVER_REGEX, "");
|
|
562
|
-
const functions = [];
|
|
563
|
-
let match;
|
|
564
|
-
FUNCTION_REGEX.lastIndex = 0;
|
|
565
|
-
while ((match = FUNCTION_REGEX.exec(code)) !== null) {
|
|
566
|
-
functions.push({
|
|
567
|
-
name: match[3],
|
|
568
|
-
isExported: !!match[1],
|
|
569
|
-
isAsync: !!match[2]
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
ARROW_FUNCTION_REGEX.lastIndex = 0;
|
|
573
|
-
while ((match = ARROW_FUNCTION_REGEX.exec(code)) !== null) {
|
|
574
|
-
functions.push({
|
|
575
|
-
name: match[3],
|
|
576
|
-
isExported: !!match[1],
|
|
577
|
-
isAsync: !!match[4]
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
const registrations = functions.filter((fn) => fn.isExported).map((fn) => {
|
|
581
|
-
const actionId = generateActionId(fn.name, filePath);
|
|
582
|
-
return `__flight_registerAction({ id: "${actionId}", name: "${fn.name}", filePath: "${filePath}", fn: ${fn.name} });`;
|
|
583
|
-
}).join("\n");
|
|
584
|
-
const imports = `import { registerAction as __flight_registerAction } from '@flight-framework/core/actions';
|
|
585
|
-
`;
|
|
586
|
-
return imports + transformed + "\n\n// Server action registrations\n" + registrations;
|
|
587
|
-
}
|
|
588
|
-
function transformInlineActions(code, filePath) {
|
|
589
|
-
const inlineServerRegex = /((async\s+)?function\s+(\w+)\s*\([^)]*\)\s*\{)\s*(['"])use server\4;?/g;
|
|
590
|
-
let transformed = code;
|
|
591
|
-
let match;
|
|
592
|
-
const actionsToRegister = [];
|
|
593
|
-
while ((match = inlineServerRegex.exec(code)) !== null) {
|
|
594
|
-
const functionName = match[3];
|
|
595
|
-
const actionId = generateActionId(functionName, filePath);
|
|
596
|
-
transformed = transformed.replace(match[0], match[1]);
|
|
597
|
-
actionsToRegister.push(
|
|
598
|
-
`__flight_registerAction({ id: "${actionId}", name: "${functionName}", filePath: "${filePath}", fn: ${functionName} });`
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
if (actionsToRegister.length > 0) {
|
|
602
|
-
const imports = `import { registerAction as __flight_registerAction } from '@flight-framework/core/actions';
|
|
603
|
-
`;
|
|
604
|
-
return imports + transformed + "\n\n// Server action registrations\n" + actionsToRegister.join("\n");
|
|
605
|
-
}
|
|
606
|
-
return transformed;
|
|
607
|
-
}
|
|
608
|
-
function createActionCaller(actionId) {
|
|
609
|
-
return async (...args) => {
|
|
610
|
-
const response = await fetch(`/__flight_action/${actionId}`, {
|
|
611
|
-
method: "POST",
|
|
612
|
-
headers: {
|
|
613
|
-
"Content-Type": "application/json"
|
|
614
|
-
},
|
|
615
|
-
body: JSON.stringify(args)
|
|
616
|
-
});
|
|
617
|
-
if (!response.ok) {
|
|
618
|
-
throw new Error(`Action failed: ${response.statusText}`);
|
|
619
|
-
}
|
|
620
|
-
const result = await response.json();
|
|
621
|
-
if (!result.success) {
|
|
622
|
-
throw new Error(result.error || "Action failed");
|
|
623
|
-
}
|
|
624
|
-
return result.data;
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
function formAction(actionId) {
|
|
628
|
-
return `/__flight_action/${actionId}`;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
523
|
// src/actions/index.ts
|
|
632
524
|
var actionRegistry = /* @__PURE__ */ new Map();
|
|
633
|
-
function
|
|
525
|
+
function registerAction(action) {
|
|
634
526
|
actionRegistry.set(action.id, action);
|
|
635
527
|
}
|
|
636
528
|
function getAction(id) {
|
|
@@ -770,6 +662,6 @@ async function handleActionRequest(request) {
|
|
|
770
662
|
}
|
|
771
663
|
}
|
|
772
664
|
|
|
773
|
-
export { RedirectError, clearActions, collectStream, cookies,
|
|
774
|
-
//# sourceMappingURL=chunk-
|
|
775
|
-
//# sourceMappingURL=chunk-
|
|
665
|
+
export { RedirectError, clearActions, collectStream, cookies, createActionContext, createActionMiddleware, createActionReference, createLoggingMiddleware, createMemoryAdapter, createProgressReporter, createQueueManager, createQueuedAction, createRetryMiddleware, createStreamableAction, createTimingMiddleware, defaultRetryStrategy, executeAction, executeFormAction, executeWithMiddleware, exponentialBackoff, fixedDelay, generateActionId, getAction, getAllActions, handleActionRequest, isRedirectError, parseFormData, pipeline, redirect, registerAction, responseToStream, streamToResponse };
|
|
666
|
+
//# sourceMappingURL=chunk-3QP3E7HS.js.map
|
|
667
|
+
//# sourceMappingURL=chunk-3QP3E7HS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/actions/middleware.ts","../src/actions/streaming.ts","../src/actions/queue.ts","../src/actions/index.ts"],"names":[],"mappings":";AAgHO,SAAS,oBAAoB,OAAA,EAMlB;AACd,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAqB;AAEvC,EAAA,OAAO;AAAA,IACH,SAAS,OAAA,CAAQ,OAAA;AAAA,IACjB,SAAS,OAAA,CAAQ,OAAA,IAAW,QAAQ,OAAA,EAAS,OAAA,IAAW,IAAI,OAAA,EAAQ;AAAA,IACpE,UAAU,OAAA,CAAQ,QAAA;AAAA,IAClB,MAAM,OAAA,CAAQ,IAAA;AAAA,IACd,QAAQ,OAAA,CAAQ,MAAA;AAAA,IAEhB,IAAiB,GAAA,EAA4B;AACzC,MAAA,OAAO,KAAA,CAAM,IAAI,GAAG,CAAA;AAAA,IACxB,CAAA;AAAA,IAEA,GAAA,CAAiB,KAAa,KAAA,EAAgB;AAC1C,MAAA,KAAA,CAAM,GAAA,CAAI,KAAK,KAAK,CAAA;AAAA,IACxB;AAAA,GACJ;AACJ;AAMA,IAAI,iBAAA,GAAoB,CAAA;AAmCjB,SAAS,sBAAA,CACZ,OAAA,EACA,OAA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A,GAAS,MAAM,iBAAA,CAAkB,QAAA,EAAU,QAAQ,CAAA;AAAA,IACvD,CAAA,MAAO;AACH,MAAA,MAAM,IAAA,GAAO,MAAM,OAAA,CAAQ,IAAA,EAAK;AAChC,MAAA,MAAA,GAAS,MAAM,aAAA,CAAc,QAAA,EAAU,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,GAAI,IAAA,GAAO,CAAC,IAAI,CAAC,CAAA;AAAA,IAC9E;AAEA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA,EAAG;AAAA,MACxC,MAAA,EAAQ,MAAA,CAAO,OAAA,GAAU,GAAA,GAAM,GAAA;AAAA,MAC/B,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA;AAAmB,KACjD,CAAA;AAAA,EACL,SAAS,KAAA,EAAO;AACZ,IAAA,IAAI,eAAA,CAAgB,KAAK,CAAA,EAAG;AACxB,MAAA,OAAO,IAAI,SAAS,IAAA,EAAM;AAAA,QACtB,MAAA,EAAQ,GAAA;AAAA,QACR,OAAA,EAAS,EAAE,QAAA,EAAU,KAAA,CAAM,GAAA;AAAI,OAClC,CAAA;AAAA,IACL;AAEA,IAAA,OAAO,IAAI,QAAA,CAAS,IAAA,CAAK,SAAA,CAAU;AAAA,MAC/B,OAAA,EAAS,KAAA;AAAA,MACT,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU;AAAA,KACnD,CAAA,EAAG;AAAA,MACA,MAAA,EAAQ,GAAA;AAAA,MACR,OAAA,EAAS,EAAE,cAAA,EAAgB,kBAAA;AAAmB,KACjD,CAAA;AAAA,EACL;AACJ","file":"chunk-3QP3E7HS.js","sourcesContent":["/**\r\n * @flight-framework/core - Action Middleware\r\n * \r\n * Agnostic middleware system for Server Actions.\r\n * Flight provides the PRIMITIVES, you build YOUR solution.\r\n * \r\n * @example\r\n * ```typescript\r\n * // Create your own auth middleware (Flight doesn't impose any auth provider)\r\n * const withAuth = createActionMiddleware(async (ctx, next) => {\r\n * const session = await yourAuthProvider.getSession(ctx.headers);\r\n * if (!session) {\r\n * return { success: false, error: 'UNAUTHORIZED' };\r\n * }\r\n * ctx.set('session', session);\r\n * return next();\r\n * });\r\n * \r\n * // Create your own rate limiter (Flight doesn't impose any rate limit provider)\r\n * const withRateLimit = createActionMiddleware(async (ctx, next) => {\r\n * const allowed = await yourRateLimiter.check(ctx.get('session').userId);\r\n * if (!allowed) {\r\n * return { success: false, error: 'RATE_LIMITED' };\r\n * }\r\n * return next();\r\n * });\r\n * \r\n * // Compose them\r\n * const protectedAction = pipeline(withAuth, withRateLimit)(myAction);\r\n * ```\r\n */\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/**\r\n * Action context - holds request data and middleware-set values\r\n */\r\nexport interface ActionContext {\r\n /** Original request (if available) */\r\n readonly request?: Request;\r\n /** Request headers */\r\n readonly headers: Headers;\r\n /** Action ID being executed */\r\n readonly actionId: string;\r\n /** Action arguments */\r\n readonly args: unknown[];\r\n /** Abort signal for cancellation */\r\n readonly signal?: AbortSignal;\r\n\r\n /** Get a value set by previous middleware */\r\n get<T = unknown>(key: string): T | undefined;\r\n /** Set a value for subsequent middleware/action */\r\n set<T = unknown>(key: string, value: T): void;\r\n}\r\n\r\n/**\r\n * Action result following Flight conventions\r\n */\r\nexport interface ActionResult<T = unknown> {\r\n success: boolean;\r\n data?: T;\r\n error?: string;\r\n code?: string;\r\n}\r\n\r\n/**\r\n * Next function to call the next middleware or action\r\n */\r\nexport type ActionNext<T = unknown> = () => Promise<ActionResult<T>>;\r\n\r\n/**\r\n * Middleware handler function\r\n */\r\nexport type ActionMiddlewareHandler<TContext extends ActionContext = ActionContext> = (\r\n ctx: TContext,\r\n next: ActionNext\r\n) => Promise<ActionResult> | ActionResult;\r\n\r\n/**\r\n * A middleware instance\r\n */\r\nexport interface ActionMiddleware {\r\n /** Unique name for debugging */\r\n readonly name: string;\r\n /** The handler function */\r\n readonly handler: ActionMiddlewareHandler;\r\n}\r\n\r\n/**\r\n * An action function\r\n */\r\nexport type Action<TInput = unknown, TOutput = unknown> = (\r\n ...args: TInput extends unknown[] ? TInput : [TInput]\r\n) => Promise<ActionResult<TOutput>>;\r\n\r\n/**\r\n * Options for creating middleware\r\n */\r\nexport interface CreateMiddlewareOptions {\r\n /** Name for debugging/logging */\r\n name?: string;\r\n}\r\n\r\n// ============================================================================\r\n// Action Context Implementation\r\n// ============================================================================\r\n\r\n/**\r\n * Create an action context from request or minimal data\r\n */\r\nexport function createActionContext(options: {\r\n request?: Request;\r\n headers?: Headers;\r\n actionId: string;\r\n args: unknown[];\r\n signal?: AbortSignal;\r\n}): ActionContext {\r\n const store = new Map<string, unknown>();\r\n\r\n return {\r\n request: options.request,\r\n headers: options.headers ?? options.request?.headers ?? new Headers(),\r\n actionId: options.actionId,\r\n args: options.args,\r\n signal: options.signal,\r\n\r\n get<T = unknown>(key: string): T | undefined {\r\n return store.get(key) as T | undefined;\r\n },\r\n\r\n set<T = unknown>(key: string, value: T): void {\r\n store.set(key, value);\r\n },\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Middleware Creation\r\n// ============================================================================\r\n\r\nlet middlewareCounter = 0;\r\n\r\n/**\r\n * Create a reusable action middleware.\r\n * \r\n * Flight provides this PRIMITIVE - you define WHAT the middleware does.\r\n * \r\n * @example\r\n * ```typescript\r\n * // Authentication middleware (you choose the auth provider)\r\n * const withAuth = createActionMiddleware(async (ctx, next) => {\r\n * const token = ctx.headers.get('Authorization');\r\n * const user = await myAuthLib.verify(token); // YOUR auth library\r\n * \r\n * if (!user) {\r\n * return { success: false, error: 'Unauthorized', code: 'AUTH_ERROR' };\r\n * }\r\n * \r\n * ctx.set('user', user);\r\n * return next();\r\n * });\r\n * \r\n * // Validation middleware (you choose the validator)\r\n * const withValidation = (schema: ZodSchema) => createActionMiddleware(\r\n * async (ctx, next) => {\r\n * const result = schema.safeParse(ctx.args[0]);\r\n * if (!result.success) {\r\n * return { success: false, error: 'Validation failed', code: 'VALIDATION_ERROR' };\r\n * }\r\n * return next();\r\n * },\r\n * { name: 'validation' }\r\n * );\r\n * ```\r\n */\r\nexport function createActionMiddleware(\r\n handler: ActionMiddlewareHandler,\r\n options: CreateMiddlewareOptions = {}\r\n): ActionMiddleware {\r\n const name = options.name ?? `middleware_${++middlewareCounter}`;\r\n\r\n return {\r\n name,\r\n handler,\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Pipeline Composition\r\n// ============================================================================\r\n\r\n/**\r\n * Compose multiple middleware into a pipeline that wraps an action.\r\n * \r\n * Middleware executes in order: first middleware runs first.\r\n * Each middleware can:\r\n * - Short-circuit by returning a result without calling next()\r\n * - Transform context for subsequent middleware\r\n * - Wrap the next() call for timing/logging\r\n * \r\n * @example\r\n * ```typescript\r\n * const protectedAction = pipeline(\r\n * withAuth,\r\n * withRateLimit,\r\n * withValidation(UserSchema),\r\n * )(createUserAction);\r\n * \r\n * // Now protectedAction has auth, rate-limit, and validation\r\n * const result = await protectedAction(userData);\r\n * ```\r\n */\r\nexport function pipeline<TInput, TOutput>(\r\n ...middlewares: ActionMiddleware[]\r\n): (action: Action<TInput, TOutput>) => Action<TInput, TOutput> {\r\n return (action: Action<TInput, TOutput>): Action<TInput, TOutput> => {\r\n return async (...args: TInput extends unknown[] ? TInput : [TInput]): Promise<ActionResult<TOutput>> => {\r\n // Create context for this execution\r\n const ctx = createActionContext({\r\n actionId: action.name || 'anonymous',\r\n args: args as unknown[],\r\n });\r\n\r\n // Build the middleware chain\r\n let index = -1;\r\n\r\n const dispatch = async (i: number): Promise<ActionResult<TOutput>> => {\r\n if (i <= index) {\r\n throw new Error('next() called multiple times');\r\n }\r\n index = i;\r\n\r\n if (i < middlewares.length) {\r\n // Execute middleware\r\n const middleware = middlewares[i]!;\r\n return middleware.handler(ctx, () => dispatch(i + 1)) as Promise<ActionResult<TOutput>>;\r\n } else {\r\n // Execute the actual action\r\n return action(...args);\r\n }\r\n };\r\n\r\n return dispatch(0);\r\n };\r\n };\r\n}\r\n\r\n/**\r\n * Execute an action with middleware, providing custom context.\r\n * \r\n * Use this when you need to provide request context (headers, etc.)\r\n * \r\n * @example\r\n * ```typescript\r\n * const result = await executeWithMiddleware(\r\n * myAction,\r\n * [arg1, arg2],\r\n * [withAuth, withRateLimit],\r\n * { request: incomingRequest }\r\n * );\r\n * ```\r\n */\r\nexport async function executeWithMiddleware<TInput extends unknown[], TOutput>(\r\n action: (...args: TInput) => Promise<ActionResult<TOutput>>,\r\n args: TInput,\r\n middlewares: ActionMiddleware[],\r\n options: {\r\n request?: Request;\r\n headers?: Headers;\r\n signal?: AbortSignal;\r\n } = {}\r\n): Promise<ActionResult<TOutput>> {\r\n // Create context with request info\r\n const ctx = createActionContext({\r\n request: options.request,\r\n headers: options.headers,\r\n actionId: action.name || 'anonymous',\r\n args: args as unknown[],\r\n signal: options.signal,\r\n });\r\n\r\n // Build the middleware chain\r\n let index = -1;\r\n\r\n const dispatch = async (i: number): Promise<ActionResult<TOutput>> => {\r\n // Check for abort\r\n if (options.signal?.aborted) {\r\n return { success: false, error: 'Aborted', code: 'ABORTED' };\r\n }\r\n\r\n if (i <= index) {\r\n throw new Error('next() called multiple times');\r\n }\r\n index = i;\r\n\r\n if (i < middlewares.length) {\r\n const middleware = middlewares[i]!;\r\n return middleware.handler(ctx, () => dispatch(i + 1)) as Promise<ActionResult<TOutput>>;\r\n } else {\r\n return action(...args);\r\n }\r\n };\r\n\r\n return dispatch(0);\r\n}\r\n\r\n// ============================================================================\r\n// Utility Middleware Factories\r\n// ============================================================================\r\n\r\n/**\r\n * Create a timing middleware for observability.\r\n * \r\n * You provide the reporter - Flight doesn't impose any observability provider.\r\n * \r\n * @example\r\n * ```typescript\r\n * const withTiming = createTimingMiddleware((actionId, durationMs) => {\r\n * myMetricsService.histogram('action.duration', durationMs, { actionId });\r\n * });\r\n * ```\r\n */\r\nexport function createTimingMiddleware(\r\n reporter: (actionId: string, durationMs: number, result: ActionResult) => void\r\n): ActionMiddleware {\r\n return createActionMiddleware(\r\n async (ctx, next) => {\r\n const start = performance.now();\r\n const result = await next();\r\n const duration = performance.now() - start;\r\n reporter(ctx.actionId, duration, result);\r\n return result;\r\n },\r\n { name: 'timing' }\r\n );\r\n}\r\n\r\n/**\r\n * Create a logging middleware.\r\n * \r\n * You provide the logger - Flight doesn't impose any logging library.\r\n * \r\n * @example\r\n * ```typescript\r\n * const withLogging = createLoggingMiddleware({\r\n * onStart: (ctx) => console.log(`[${ctx.actionId}] Starting...`),\r\n * onComplete: (ctx, result, ms) => console.log(`[${ctx.actionId}] ${result.success ? 'OK' : 'FAIL'} in ${ms}ms`),\r\n * });\r\n * ```\r\n */\r\nexport function createLoggingMiddleware(options: {\r\n onStart?: (ctx: ActionContext) => void;\r\n onComplete?: (ctx: ActionContext, result: ActionResult, durationMs: number) => void;\r\n onError?: (ctx: ActionContext, error: Error) => void;\r\n}): ActionMiddleware {\r\n return createActionMiddleware(\r\n async (ctx, next) => {\r\n options.onStart?.(ctx);\r\n const start = performance.now();\r\n\r\n try {\r\n const result = await next();\r\n const duration = performance.now() - start;\r\n options.onComplete?.(ctx, result, duration);\r\n return result;\r\n } catch (error) {\r\n options.onError?.(ctx, error as Error);\r\n throw error;\r\n }\r\n },\r\n { name: 'logging' }\r\n );\r\n}\r\n\r\n/**\r\n * Create a retry middleware.\r\n * \r\n * @example\r\n * ```typescript\r\n * const withRetry = createRetryMiddleware({\r\n * maxAttempts: 3,\r\n * delay: (attempt) => Math.pow(2, attempt) * 100, // Exponential backoff\r\n * shouldRetry: (result) => result.code === 'TEMPORARY_ERROR',\r\n * });\r\n * ```\r\n */\r\nexport function createRetryMiddleware(options: {\r\n maxAttempts: number;\r\n delay?: (attempt: number) => number;\r\n shouldRetry?: (result: ActionResult) => boolean;\r\n}): ActionMiddleware {\r\n const {\r\n maxAttempts,\r\n delay = () => 0,\r\n shouldRetry = (result) => !result.success,\r\n } = options;\r\n\r\n return createActionMiddleware(\r\n async (ctx, next) => {\r\n let lastResult: ActionResult = { success: false, error: 'No attempts made' };\r\n\r\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\r\n if (attempt > 0) {\r\n const delayMs = delay(attempt);\r\n if (delayMs > 0) {\r\n await new Promise(resolve => setTimeout(resolve, delayMs));\r\n }\r\n }\r\n\r\n lastResult = await next();\r\n\r\n if (!shouldRetry(lastResult)) {\r\n return lastResult;\r\n }\r\n }\r\n\r\n return lastResult;\r\n },\r\n { name: 'retry' }\r\n );\r\n}\r\n","/**\r\n * @flight-framework/core - Action Streaming\r\n * \r\n * Streamable actions using async generators.\r\n * Flight provides the PRIMITIVES, you choose the transport.\r\n * \r\n * @example\r\n * ```typescript\r\n * // Create a streamable action for long-running operations\r\n * const generateReport = createStreamableAction(async function* (params: ReportParams) {\r\n * yield { type: 'progress', message: 'Fetching data...', progress: 0 };\r\n * const data = await fetchData(params);\r\n * \r\n * yield { type: 'progress', message: 'Processing...', progress: 33 };\r\n * const processed = await processData(data);\r\n * \r\n * yield { type: 'progress', message: 'Generating PDF...', progress: 66 };\r\n * const pdf = await generatePDF(processed);\r\n * \r\n * yield { type: 'progress', message: 'Complete!', progress: 100 };\r\n * return { success: true, data: pdf };\r\n * });\r\n * \r\n * // Client consumption\r\n * for await (const update of generateReport(params)) {\r\n * if (update.type === 'progress') {\r\n * setProgress(update.progress);\r\n * } else if (update.type === 'result') {\r\n * handleResult(update.data);\r\n * }\r\n * }\r\n * ```\r\n */\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/**\r\n * Progress update yielded during streaming\r\n */\r\nexport interface StreamProgress<TYield = unknown> {\r\n type: 'progress';\r\n data: TYield;\r\n}\r\n\r\n/**\r\n * Final result of a streaming action\r\n */\r\nexport interface StreamResult<TReturn = unknown> {\r\n type: 'result';\r\n success: boolean;\r\n data?: TReturn;\r\n error?: string;\r\n}\r\n\r\n/**\r\n * Union type for stream items\r\n */\r\nexport type StreamItem<TYield, TReturn> = StreamProgress<TYield> | StreamResult<TReturn>;\r\n\r\n/**\r\n * Streamable action generator function\r\n */\r\nexport type StreamableGenerator<TInput, TYield, TReturn> = (\r\n input: TInput,\r\n signal?: AbortSignal\r\n) => AsyncGenerator<TYield, TReturn>;\r\n\r\n/**\r\n * Options for creating a streamable action\r\n */\r\nexport interface StreamableActionOptions {\r\n /** Name for debugging */\r\n name?: string;\r\n /** Timeout in milliseconds */\r\n timeout?: number;\r\n}\r\n\r\n/**\r\n * Controller for a running stream\r\n */\r\nexport interface StreamController<TYield, TReturn> {\r\n /** Async iterator for consuming the stream */\r\n [Symbol.asyncIterator](): AsyncIterator<StreamItem<TYield, TReturn>>;\r\n /** Abort the stream */\r\n abort(): void;\r\n /** Promise that resolves when stream completes */\r\n done: Promise<StreamResult<TReturn>>;\r\n}\r\n\r\n/**\r\n * A streamable action function\r\n */\r\nexport type StreamableAction<TInput, TYield, TReturn> = (\r\n input: TInput\r\n) => StreamController<TYield, TReturn>;\r\n\r\n// ============================================================================\r\n// Streamable Action Creation\r\n// ============================================================================\r\n\r\n/**\r\n * Create a streamable action from an async generator.\r\n * \r\n * Flight provides this PRIMITIVE - you define the generator logic\r\n * and choose how to transport the stream (HTTP, WebSocket, etc.)\r\n * \r\n * @example\r\n * ```typescript\r\n * // AI streaming response\r\n * const streamChat = createStreamableAction(async function* (message: string) {\r\n * const stream = await openai.chat.completions.create({\r\n * model: 'gpt-4',\r\n * messages: [{ role: 'user', content: message }],\r\n * stream: true,\r\n * });\r\n * \r\n * let fullResponse = '';\r\n * for await (const chunk of stream) {\r\n * const text = chunk.choices[0]?.delta?.content || '';\r\n * fullResponse += text;\r\n * yield { text, partial: true };\r\n * }\r\n * \r\n * return { text: fullResponse, partial: false };\r\n * });\r\n * ```\r\n */\r\nexport function createStreamableAction<TInput, TYield, TReturn>(\r\n generator: StreamableGenerator<TInput, TYield, TReturn>,\r\n options: StreamableActionOptions = {}\r\n): StreamableAction<TInput, TYield, TReturn> {\r\n const actionName = options.name ?? generator.name ?? 'streamable_action';\r\n\r\n return (input: TInput): StreamController<TYield, TReturn> => {\r\n const abortController = new AbortController();\r\n let completed = false;\r\n let finalResult: StreamResult<TReturn> | null = null;\r\n\r\n // Create done promise\r\n let resolveDone: (result: StreamResult<TReturn>) => void;\r\n const done = new Promise<StreamResult<TReturn>>((resolve) => {\r\n resolveDone = resolve;\r\n });\r\n\r\n // Setup timeout if specified\r\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\r\n if (options.timeout) {\r\n timeoutId = setTimeout(() => {\r\n abortController.abort();\r\n }, options.timeout);\r\n }\r\n\r\n // Create the async iterator\r\n async function* iterate(): AsyncGenerator<StreamItem<TYield, TReturn>> {\r\n try {\r\n const gen = generator(input, abortController.signal);\r\n\r\n while (true) {\r\n if (abortController.signal.aborted) {\r\n const abortResult: StreamResult<TReturn> = {\r\n type: 'result',\r\n success: false,\r\n error: 'Stream aborted',\r\n };\r\n finalResult = abortResult;\r\n resolveDone!(abortResult);\r\n yield abortResult;\r\n return;\r\n }\r\n\r\n const next = await gen.next();\r\n\r\n if (next.done) {\r\n // Generator returned - this is the final value\r\n const successResult: StreamResult<TReturn> = {\r\n type: 'result',\r\n success: true,\r\n data: next.value,\r\n };\r\n finalResult = successResult;\r\n completed = true;\r\n resolveDone!(successResult);\r\n yield successResult;\r\n return;\r\n } else {\r\n // Generator yielded - this is a progress update\r\n yield {\r\n type: 'progress',\r\n data: next.value,\r\n };\r\n }\r\n }\r\n } catch (error) {\r\n const errorResult: StreamResult<TReturn> = {\r\n type: 'result',\r\n success: false,\r\n error: error instanceof Error ? error.message : 'Unknown error',\r\n };\r\n finalResult = errorResult;\r\n resolveDone!(errorResult);\r\n yield errorResult;\r\n } finally {\r\n if (timeoutId) {\r\n clearTimeout(timeoutId);\r\n }\r\n }\r\n }\r\n\r\n const iterator = iterate();\r\n\r\n return {\r\n [Symbol.asyncIterator]() {\r\n return iterator;\r\n },\r\n abort() {\r\n abortController.abort();\r\n },\r\n done,\r\n };\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// HTTP Transport Adapter\r\n// ============================================================================\r\n\r\n/**\r\n * Convert a streamable action result to an HTTP streaming response.\r\n * \r\n * This is ONE transport option - you can create others (WebSocket, SSE, etc.)\r\n * \r\n * @example\r\n * ```typescript\r\n * // In your API route\r\n * export async function POST(request: Request) {\r\n * const body = await request.json();\r\n * const stream = generateReport(body);\r\n * return streamToResponse(stream);\r\n * }\r\n * ```\r\n */\r\nexport function streamToResponse<TYield, TReturn>(\r\n controller: StreamController<TYield, TReturn>,\r\n options: {\r\n headers?: Record<string, string>;\r\n } = {}\r\n): Response {\r\n const encoder = new TextEncoder();\r\n\r\n const stream = new ReadableStream({\r\n async start(streamController) {\r\n try {\r\n for await (const item of controller) {\r\n const chunk = JSON.stringify(item) + '\\n';\r\n streamController.enqueue(encoder.encode(chunk));\r\n\r\n if (item.type === 'result') {\r\n break;\r\n }\r\n }\r\n } catch (error) {\r\n const errorChunk = JSON.stringify({\r\n type: 'result',\r\n success: false,\r\n error: error instanceof Error ? error.message : 'Stream error',\r\n }) + '\\n';\r\n streamController.enqueue(encoder.encode(errorChunk));\r\n } finally {\r\n streamController.close();\r\n }\r\n },\r\n cancel() {\r\n controller.abort();\r\n },\r\n });\r\n\r\n return new Response(stream, {\r\n status: 200,\r\n headers: {\r\n 'Content-Type': 'application/x-ndjson',\r\n 'Transfer-Encoding': 'chunked',\r\n 'Cache-Control': 'no-cache',\r\n 'Connection': 'keep-alive',\r\n ...options.headers,\r\n },\r\n });\r\n}\r\n\r\n/**\r\n * Parse an HTTP streaming response back to a stream controller (client-side).\r\n * \r\n * @example\r\n * ```typescript\r\n * // Client-side consumption\r\n * const response = await fetch('/api/generate-report', {\r\n * method: 'POST',\r\n * body: JSON.stringify(params),\r\n * });\r\n * \r\n * const stream = responseToStream<Progress, Report>(response);\r\n * \r\n * for await (const item of stream) {\r\n * if (item.type === 'progress') {\r\n * setProgress(item.data);\r\n * } else {\r\n * setReport(item.data);\r\n * }\r\n * }\r\n * ```\r\n */\r\nexport function responseToStream<TYield, TReturn>(\r\n response: Response\r\n): AsyncGenerator<StreamItem<TYield, TReturn>> {\r\n const reader = response.body?.getReader();\r\n const decoder = new TextDecoder();\r\n\r\n if (!reader) {\r\n throw new Error('Response body is not readable');\r\n }\r\n\r\n return (async function* () {\r\n let buffer = '';\r\n\r\n try {\r\n while (true) {\r\n const { done, value } = await reader.read();\r\n\r\n if (done) {\r\n break;\r\n }\r\n\r\n buffer += decoder.decode(value, { stream: true });\r\n\r\n // Process complete lines\r\n const lines = buffer.split('\\n');\r\n buffer = lines.pop() || ''; // Keep incomplete line in buffer\r\n\r\n for (const line of lines) {\r\n if (line.trim()) {\r\n try {\r\n const item = JSON.parse(line) as StreamItem<TYield, TReturn>;\r\n yield item;\r\n } catch {\r\n // Skip malformed JSON\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Process remaining buffer\r\n if (buffer.trim()) {\r\n try {\r\n const item = JSON.parse(buffer) as StreamItem<TYield, TReturn>;\r\n yield item;\r\n } catch {\r\n // Skip malformed JSON\r\n }\r\n }\r\n } finally {\r\n reader.releaseLock();\r\n }\r\n })();\r\n}\r\n\r\n// ============================================================================\r\n// Utility Functions\r\n// ============================================================================\r\n\r\n/**\r\n * Collect all items from a stream into an array.\r\n * \r\n * Useful for testing or when you want to wait for completion.\r\n */\r\nexport async function collectStream<TYield, TReturn>(\r\n controller: StreamController<TYield, TReturn>\r\n): Promise<{ items: StreamItem<TYield, TReturn>[]; result: StreamResult<TReturn> }> {\r\n const items: StreamItem<TYield, TReturn>[] = [];\r\n let result: StreamResult<TReturn> | null = null;\r\n\r\n for await (const item of controller) {\r\n items.push(item);\r\n if (item.type === 'result') {\r\n result = item;\r\n }\r\n }\r\n\r\n if (!result) {\r\n result = { type: 'result', success: false, error: 'No result received' };\r\n }\r\n\r\n return { items, result };\r\n}\r\n\r\n/**\r\n * Create a simple progress reporter for streams.\r\n * \r\n * @example\r\n * ```typescript\r\n * const onProgress = createProgressReporter<MyProgress>((data) => {\r\n * console.log(`Progress: ${data.percent}%`);\r\n * });\r\n * \r\n * for await (const item of myStream) {\r\n * onProgress(item);\r\n * }\r\n * ```\r\n */\r\nexport function createProgressReporter<TYield, TReturn = unknown>(\r\n onProgress: (data: TYield) => void,\r\n onComplete?: (result: StreamResult<TReturn>) => void\r\n): (item: StreamItem<TYield, TReturn>) => void {\r\n return (item: StreamItem<TYield, TReturn>) => {\r\n if (item.type === 'progress') {\r\n onProgress(item.data);\r\n } else {\r\n onComplete?.(item);\r\n }\r\n };\r\n}\r\n","/**\r\n * @flight-framework/core - Action Queue\r\n * \r\n * Offline-first action queuing with pluggable storage.\r\n * Flight provides the PRIMITIVES and INTERFACE, you choose the storage.\r\n * \r\n * @example\r\n * ```typescript\r\n * // 1. Use a storage adapter (install separately or create your own)\r\n * import { indexedDBAdapter } from '@flight-framework/queue-indexeddb';\r\n * // OR create your own:\r\n * const myAdapter: QueueStorageAdapter = { ... };\r\n * \r\n * // 2. Create a queued action\r\n * const saveNote = createQueuedAction(\r\n * async (note: Note) => {\r\n * await api.saveNote(note);\r\n * return { success: true };\r\n * },\r\n * {\r\n * storage: indexedDBAdapter({ dbName: 'myapp' }),\r\n * retryStrategy: exponentialBackoff({ maxAttempts: 5 }),\r\n * onStatusChange: (status) => console.log('Queue status:', status),\r\n * }\r\n * );\r\n * \r\n * // 3. Use it - works offline!\r\n * await saveNote({ title: 'My Note', content: '...' });\r\n * // If offline: queued and synced later\r\n * // If online: executed immediately\r\n * ```\r\n */\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/**\r\n * A queued action entry\r\n */\r\nexport interface QueuedActionEntry<TInput = unknown> {\r\n /** Unique ID for this entry */\r\n id: string;\r\n /** Action identifier */\r\n actionId: string;\r\n /** Action arguments */\r\n input: TInput;\r\n /** When the action was queued */\r\n queuedAt: number;\r\n /** Number of execution attempts */\r\n attempts: number;\r\n /** Last error message if failed */\r\n lastError?: string;\r\n /** Status */\r\n status: 'pending' | 'processing' | 'failed';\r\n /** Optional metadata */\r\n meta?: Record<string, unknown>;\r\n}\r\n\r\n/**\r\n * Queue storage adapter interface.\r\n * \r\n * Flight does NOT provide storage implementations - you choose:\r\n * - @flight-framework/queue-indexeddb (browser)\r\n * - @flight-framework/queue-sqlite (mobile/desktop)\r\n * - @flight-framework/queue-memory (testing)\r\n * - Your own implementation\r\n */\r\nexport interface QueueStorageAdapter {\r\n /** Add an action to the queue */\r\n enqueue<TInput>(entry: QueuedActionEntry<TInput>): Promise<void>;\r\n\r\n /** Get and remove the next pending action */\r\n dequeue(): Promise<QueuedActionEntry | null>;\r\n\r\n /** Get all pending actions without removing */\r\n peek(): Promise<QueuedActionEntry[]>;\r\n\r\n /** Update an existing entry */\r\n update(id: string, updates: Partial<QueuedActionEntry>): Promise<void>;\r\n\r\n /** Remove an entry by ID */\r\n remove(id: string): Promise<void>;\r\n\r\n /** Clear all entries */\r\n clear(): Promise<void>;\r\n\r\n /** Get queue length */\r\n length(): Promise<number>;\r\n}\r\n\r\n/**\r\n * Retry strategy function\r\n */\r\nexport type RetryStrategy = (\r\n entry: QueuedActionEntry,\r\n error: Error\r\n) => { shouldRetry: boolean; delayMs: number };\r\n\r\n/**\r\n * Queue status for observability\r\n */\r\nexport interface QueueStatus {\r\n /** Whether the queue processor is running */\r\n isProcessing: boolean;\r\n /** Number of pending actions */\r\n pendingCount: number;\r\n /** Number of failed actions */\r\n failedCount: number;\r\n /** Whether online */\r\n isOnline: boolean;\r\n}\r\n\r\n/**\r\n * Options for creating a queued action\r\n */\r\nexport interface QueuedActionOptions {\r\n /** Storage adapter (required - Flight doesn't provide default) */\r\n storage: QueueStorageAdapter;\r\n /** Custom action ID */\r\n actionId?: string;\r\n /** Retry strategy */\r\n retryStrategy?: RetryStrategy;\r\n /** Check if online (default: navigator.onLine on browser) */\r\n isOnline?: () => boolean | Promise<boolean>;\r\n /** Called when queue status changes */\r\n onStatusChange?: (status: QueueStatus) => void;\r\n /** Called when an action is successfully processed */\r\n onSuccess?: (entry: QueuedActionEntry, result: unknown) => void;\r\n /** Called when an action fails permanently */\r\n onFailure?: (entry: QueuedActionEntry, error: Error) => void;\r\n}\r\n\r\n/**\r\n * Action result for queued actions\r\n */\r\nexport interface QueuedActionResult<TOutput = unknown> {\r\n /** Whether immediately executed or queued */\r\n queued: boolean;\r\n /** Queue entry ID if queued */\r\n entryId?: string;\r\n /** Result if immediately executed */\r\n result?: { success: boolean; data?: TOutput; error?: string };\r\n}\r\n\r\n/**\r\n * A queued action function\r\n */\r\nexport type QueuedAction<TInput, TOutput> = (\r\n input: TInput\r\n) => Promise<QueuedActionResult<TOutput>>;\r\n\r\n// ============================================================================\r\n// Queue Creation\r\n// ============================================================================\r\n\r\nlet entryCounter = 0;\r\n\r\nfunction generateEntryId(): string {\r\n return `${Date.now()}_${++entryCounter}_${Math.random().toString(36).substring(2, 9)}`;\r\n}\r\n\r\n/**\r\n * Create an offline-capable queued action.\r\n * \r\n * Flight provides this PRIMITIVE - you provide the storage adapter.\r\n * \r\n * @example\r\n * ```typescript\r\n * // Create with your storage adapter\r\n * const syncData = createQueuedAction(\r\n * async (data: MyData) => {\r\n * await api.sync(data);\r\n * return { success: true };\r\n * },\r\n * {\r\n * storage: myStorageAdapter,\r\n * retryStrategy: exponentialBackoff(),\r\n * }\r\n * );\r\n * \r\n * // Use it - works offline automatically\r\n * const result = await syncData({ items: [...] });\r\n * \r\n * if (result.queued) {\r\n * console.log('Queued for later sync:', result.entryId);\r\n * } else {\r\n * console.log('Synced immediately:', result.result);\r\n * }\r\n * ```\r\n */\r\nexport function createQueuedAction<TInput, TOutput>(\r\n action: (input: TInput) => Promise<{ success: boolean; data?: TOutput; error?: string }>,\r\n options: QueuedActionOptions\r\n): QueuedAction<TInput, TOutput> {\r\n const {\r\n storage,\r\n actionId = action.name || `action_${Date.now()}`,\r\n retryStrategy = defaultRetryStrategy,\r\n isOnline = defaultIsOnline,\r\n onStatusChange,\r\n onSuccess,\r\n onFailure,\r\n } = options;\r\n\r\n // Queue processor state\r\n let isProcessing = false;\r\n let processorRunning = false;\r\n\r\n // Start background processor\r\n startProcessor();\r\n\r\n async function startProcessor() {\r\n if (processorRunning) return;\r\n processorRunning = true;\r\n\r\n // Process queue periodically\r\n while (processorRunning) {\r\n await processQueue();\r\n await sleep(1000); // Check every second\r\n }\r\n }\r\n\r\n async function processQueue() {\r\n // Check if online\r\n const online = await isOnline();\r\n if (!online) {\r\n return;\r\n }\r\n\r\n // Get next entry\r\n const entry = await storage.dequeue();\r\n if (!entry) {\r\n if (isProcessing) {\r\n isProcessing = false;\r\n await notifyStatus();\r\n }\r\n return;\r\n }\r\n\r\n isProcessing = true;\r\n await notifyStatus();\r\n\r\n // Update status to processing\r\n await storage.update(entry.id, { status: 'processing' });\r\n\r\n try {\r\n // Execute the action\r\n const result = await action(entry.input as TInput);\r\n\r\n // Success - remove from queue\r\n await storage.remove(entry.id);\r\n onSuccess?.(entry, result);\r\n } catch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n\r\n // Check retry strategy\r\n const { shouldRetry, delayMs } = retryStrategy(entry, err);\r\n\r\n if (shouldRetry) {\r\n // Re-queue with updated attempts\r\n await storage.update(entry.id, {\r\n status: 'pending',\r\n attempts: entry.attempts + 1,\r\n lastError: err.message,\r\n });\r\n\r\n // Wait before next attempt\r\n if (delayMs > 0) {\r\n await sleep(delayMs);\r\n }\r\n } else {\r\n // Mark as failed\r\n await storage.update(entry.id, {\r\n status: 'failed',\r\n lastError: err.message,\r\n });\r\n onFailure?.(entry, err);\r\n }\r\n }\r\n }\r\n\r\n async function notifyStatus() {\r\n if (!onStatusChange) return;\r\n\r\n const entries = await storage.peek();\r\n const status: QueueStatus = {\r\n isProcessing,\r\n pendingCount: entries.filter(e => e.status === 'pending').length,\r\n failedCount: entries.filter(e => e.status === 'failed').length,\r\n isOnline: await isOnline(),\r\n };\r\n onStatusChange(status);\r\n }\r\n\r\n // Return the queued action function\r\n return async (input: TInput): Promise<QueuedActionResult<TOutput>> => {\r\n const online = await isOnline();\r\n\r\n if (online) {\r\n // Try to execute immediately\r\n try {\r\n const result = await action(input);\r\n return { queued: false, result };\r\n } catch {\r\n // Fall through to queue\r\n }\r\n }\r\n\r\n // Queue for later\r\n const entry: QueuedActionEntry<TInput> = {\r\n id: generateEntryId(),\r\n actionId,\r\n input,\r\n queuedAt: Date.now(),\r\n attempts: 0,\r\n status: 'pending',\r\n };\r\n\r\n await storage.enqueue(entry);\r\n await notifyStatus();\r\n\r\n return { queued: true, entryId: entry.id };\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Built-in Retry Strategies\r\n// ============================================================================\r\n\r\n/**\r\n * Default retry strategy: 3 attempts with 1 second delay\r\n */\r\nexport const defaultRetryStrategy: RetryStrategy = (entry) => ({\r\n shouldRetry: entry.attempts < 3,\r\n delayMs: 1000,\r\n});\r\n\r\n/**\r\n * Create an exponential backoff retry strategy.\r\n * \r\n * @example\r\n * ```typescript\r\n * const retry = exponentialBackoff({\r\n * maxAttempts: 5,\r\n * baseDelayMs: 1000,\r\n * maxDelayMs: 30000,\r\n * });\r\n * ```\r\n */\r\nexport function exponentialBackoff(options: {\r\n maxAttempts?: number;\r\n baseDelayMs?: number;\r\n maxDelayMs?: number;\r\n} = {}): RetryStrategy {\r\n const {\r\n maxAttempts = 5,\r\n baseDelayMs = 1000,\r\n maxDelayMs = 30000,\r\n } = options;\r\n\r\n return (entry) => {\r\n const shouldRetry = entry.attempts < maxAttempts;\r\n const delayMs = Math.min(\r\n baseDelayMs * Math.pow(2, entry.attempts),\r\n maxDelayMs\r\n );\r\n\r\n return { shouldRetry, delayMs };\r\n };\r\n}\r\n\r\n/**\r\n * Create a fixed delay retry strategy.\r\n */\r\nexport function fixedDelay(options: {\r\n maxAttempts?: number;\r\n delayMs?: number;\r\n} = {}): RetryStrategy {\r\n const { maxAttempts = 3, delayMs = 1000 } = options;\r\n\r\n return (entry) => ({\r\n shouldRetry: entry.attempts < maxAttempts,\r\n delayMs,\r\n });\r\n}\r\n\r\n// ============================================================================\r\n// In-Memory Storage Adapter (for testing only)\r\n// ============================================================================\r\n\r\n/**\r\n * In-memory queue storage adapter.\r\n * \r\n * ⚠️ FOR TESTING ONLY - data is lost on page refresh.\r\n * \r\n * For production, use:\r\n * - @flight-framework/queue-indexeddb (browser)\r\n * - @flight-framework/queue-sqlite (native apps)\r\n * - Your own implementation\r\n */\r\nexport function createMemoryAdapter(): QueueStorageAdapter {\r\n const store = new Map<string, QueuedActionEntry>();\r\n\r\n return {\r\n async enqueue(entry) {\r\n store.set(entry.id, entry);\r\n },\r\n\r\n async dequeue() {\r\n for (const [id, entry] of store.entries()) {\r\n if (entry.status === 'pending') {\r\n store.delete(id);\r\n return entry;\r\n }\r\n }\r\n return null;\r\n },\r\n\r\n async peek() {\r\n return Array.from(store.values());\r\n },\r\n\r\n async update(id, updates) {\r\n const entry = store.get(id);\r\n if (entry) {\r\n store.set(id, { ...entry, ...updates });\r\n }\r\n },\r\n\r\n async remove(id) {\r\n store.delete(id);\r\n },\r\n\r\n async clear() {\r\n store.clear();\r\n },\r\n\r\n async length() {\r\n return store.size;\r\n },\r\n };\r\n}\r\n\r\n// ============================================================================\r\n// Utility Functions\r\n// ============================================================================\r\n\r\nfunction sleep(ms: number): Promise<void> {\r\n return new Promise(resolve => setTimeout(resolve, ms));\r\n}\r\n\r\nfunction defaultIsOnline(): boolean {\r\n if (typeof navigator !== 'undefined' && 'onLine' in navigator) {\r\n return navigator.onLine;\r\n }\r\n // Assume online in non-browser environments\r\n return true;\r\n}\r\n\r\n/**\r\n * Create a queue manager to control multiple queued actions.\r\n * \r\n * @example\r\n * ```typescript\r\n * const queueManager = createQueueManager({\r\n * storage: myStorageAdapter,\r\n * });\r\n * \r\n * // Pause all processing\r\n * queueManager.pause();\r\n * \r\n * // Resume\r\n * queueManager.resume();\r\n * \r\n * // Get status\r\n * const status = await queueManager.getStatus();\r\n * ```\r\n */\r\nexport function createQueueManager(options: {\r\n storage: QueueStorageAdapter;\r\n}): {\r\n pause: () => void;\r\n resume: () => void;\r\n getStatus: () => Promise<QueueStatus>;\r\n clearFailed: () => Promise<void>;\r\n retryFailed: () => Promise<void>;\r\n} {\r\n let paused = false;\r\n\r\n return {\r\n pause() {\r\n paused = true;\r\n },\r\n\r\n resume() {\r\n paused = false;\r\n },\r\n\r\n async getStatus() {\r\n const entries = await options.storage.peek();\r\n return {\r\n isProcessing: !paused,\r\n pendingCount: entries.filter(e => e.status === 'pending').length,\r\n failedCount: entries.filter(e => e.status === 'failed').length,\r\n isOnline: defaultIsOnline(),\r\n };\r\n },\r\n\r\n async clearFailed() {\r\n const entries = await options.storage.peek();\r\n for (const entry of entries) {\r\n if (entry.status === 'failed') {\r\n await options.storage.remove(entry.id);\r\n }\r\n }\r\n },\r\n\r\n async retryFailed() {\r\n const entries = await options.storage.peek();\r\n for (const entry of entries) {\r\n if (entry.status === 'failed') {\r\n await options.storage.update(entry.id, {\r\n status: 'pending',\r\n attempts: 0,\r\n lastError: undefined,\r\n });\r\n }\r\n }\r\n },\r\n };\r\n}\r\n","/**\r\n * @flight-framework/core - Server Actions\r\n * \r\n * Implementation of React 19 style Server Actions.\r\n * Functions marked with 'use server' run on the server.\r\n */\r\n\r\n// ============================================================================\r\n// Types\r\n// ============================================================================\r\n\r\n/**\r\n * Server action metadata\r\n */\r\nexport interface ServerAction {\r\n /** Unique action ID */\r\n id: string;\r\n /** Original function name */\r\n name: string;\r\n /** File path where action is defined */\r\n filePath: string;\r\n /** The actual action function */\r\n fn: (...args: unknown[]) => Promise<unknown>;\r\n}\r\n\r\n/**\r\n * Server action result\r\n */\r\nexport interface ActionResult<T = unknown> {\r\n success: boolean;\r\n data?: T;\r\n error?: string;\r\n}\r\n\r\n/**\r\n * Form action data\r\n */\r\nexport interface FormActionData {\r\n actionId: string;\r\n formData: FormData;\r\n}\r\n\r\n// ============================================================================\r\n// Action Registry\r\n// ============================================================================\r\n\r\nconst actionRegistry = new Map<string, ServerAction>();\r\n\r\n/**\r\n * Register a server action\r\n */\r\nexport function registerAction(action: ServerAction): void {\r\n actionRegistry.set(action.id, action);\r\n}\r\n\r\n/**\r\n * Get a registered action by ID\r\n */\r\nexport function getAction(id: string): ServerAction | undefined {\r\n return actionRegistry.get(id);\r\n}\r\n\r\n/**\r\n * Get all registered actions\r\n */\r\nexport function getAllActions(): ServerAction[] {\r\n return Array.from(actionRegistry.values());\r\n}\r\n\r\n/**\r\n * Clear all registered actions (useful for testing)\r\n */\r\nexport function clearActions(): void {\r\n actionRegistry.clear();\r\n}\r\n\r\n// ============================================================================\r\n// Action Execution\r\n// ============================================================================\r\n\r\n/**\r\n * Execute a server action\r\n */\r\nexport async function executeAction<T = unknown>(\r\n actionId: string,\r\n args: unknown[]\r\n): Promise<ActionResult<T>> {\r\n const action = getAction(actionId);\r\n\r\n if (!action) {\r\n return {\r\n success: false,\r\n error: `Action not found: ${actionId}`,\r\n };\r\n }\r\n\r\n try {\r\n const result = await action.fn(...args);\r\n return {\r\n success: true,\r\n data: result as T,\r\n };\r\n } catch (error) {\r\n // Re-throw RedirectError so handleActionRequest can return 303\r\n if (isRedirectError(error)) {\r\n throw error;\r\n }\r\n console.error(`[Flight] Action error (${actionId}):`, error);\r\n return {\r\n success: false,\r\n error: error instanceof Error ? error.message : 'Unknown error',\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Execute a form action\r\n */\r\nexport async function executeFormAction<T = unknown>(\r\n actionId: string,\r\n formData: FormData\r\n): Promise<ActionResult<T>> {\r\n return executeAction<T>(actionId, [formData]);\r\n}\r\n\r\n// ============================================================================\r\n// Action ID Generation\r\n// ============================================================================\r\n\r\nlet actionCounter = 0;\r\n\r\n/**\r\n * Generate a unique action ID\r\n */\r\nexport function generateActionId(name: string, filePath: string): string {\r\n const hash = simpleHash(`${filePath}:${name}`);\r\n return `action_${hash}_${actionCounter++}`;\r\n}\r\n\r\n/**\r\n * Simple hash function for action IDs\r\n */\r\nfunction simpleHash(str: string): string {\r\n let hash = 0;\r\n for (let i = 0; i < str.length; i++) {\r\n const char = str.charCodeAt(i);\r\n hash = ((hash << 5) - hash) + char;\r\n hash = hash & hash; // Convert to 32bit integer\r\n }\r\n return Math.abs(hash).toString(36);\r\n}\r\n\r\n// ============================================================================\r\n// Action Helpers (for use inside actions)\r\n// ============================================================================\r\n\r\n/**\r\n * Get cookies in server action context\r\n */\r\nexport function cookies(): {\r\n get: (name: string) => string | undefined;\r\n set: (name: string, value: string, options?: CookieOptions) => void;\r\n delete: (name: string) => void;\r\n} {\r\n // This will be populated by the runtime\r\n const cookieStore = (globalThis as any).__flightCookies;\r\n\r\n if (!cookieStore) {\r\n console.warn('[Flight] Cookies not available outside of action context');\r\n return {\r\n get: () => undefined,\r\n set: () => { },\r\n delete: () => { },\r\n };\r\n }\r\n\r\n return cookieStore;\r\n}\r\n\r\nexport interface CookieOptions {\r\n maxAge?: number;\r\n expires?: Date;\r\n path?: string;\r\n domain?: string;\r\n secure?: boolean;\r\n httpOnly?: boolean;\r\n sameSite?: 'strict' | 'lax' | 'none';\r\n}\r\n\r\n/**\r\n * Redirect in server action context\r\n */\r\nexport function redirect(url: string): never {\r\n throw new RedirectError(url);\r\n}\r\n\r\n/**\r\n * Special error for redirects\r\n */\r\nexport class RedirectError extends Error {\r\n public readonly url: string;\r\n\r\n constructor(url: string) {\r\n super(`Redirect to ${url}`);\r\n this.name = 'RedirectError';\r\n this.url = url;\r\n }\r\n}\r\n\r\n/**\r\n * Check if error is a redirect\r\n */\r\nexport function isRedirectError(error: unknown): error is RedirectError {\r\n return error instanceof RedirectError;\r\n}\r\n\r\n// ============================================================================\r\n// Form Helpers\r\n// ============================================================================\r\n\r\n/**\r\n * Parse form data to typed object\r\n */\r\nexport function parseFormData<T extends Record<string, string>>(\r\n formData: FormData\r\n): T {\r\n const result: Record<string, string> = {};\r\n\r\n formData.forEach((value, key) => {\r\n result[key] = String(value);\r\n });\r\n\r\n return result as T;\r\n}\r\n\r\n/**\r\n * Create action reference for form action attribute\r\n */\r\nexport function createActionReference(actionId: string): string {\r\n return `/__flight_action/${actionId}`;\r\n}\r\n\r\n// ============================================================================\r\n// Action Handler (for HTTP endpoint)\r\n// ============================================================================\r\n\r\n/**\r\n * Handle action request from client\r\n */\r\nexport async function handleActionRequest(\r\n request: Request\r\n): Promise<Response> {\r\n const url = new URL(request.url);\r\n const actionPath = url.pathname;\r\n\r\n // Extract action ID from path: /__flight_action/{actionId}\r\n const match = actionPath.match(/^\\/__flight_action\\/(.+)$/);\r\n\r\n if (!match) {\r\n return new Response(JSON.stringify({ error: 'Invalid action path' }), {\r\n status: 400,\r\n headers: { 'Content-Type': 'application/json' },\r\n });\r\n }\r\n\r\n const actionId = match[1];\r\n\r\n if (!actionId) {\r\n return new Response(JSON.stringify({ error: 'Missing action ID' }), {\r\n status: 400,\r\n headers: { 'Content-Type': 'application/json' },\r\n });\r\n }\r\n\r\n try {\r\n let result: ActionResult;\r\n\r\n // Check content type for form vs JSON\r\n const contentType = request.headers.get('content-type') || '';\r\n\r\n if (contentType.includes('application/x-www-form-urlencoded') ||\r\n contentType.includes('multipart/form-data')) {\r\n const formData = await request.formData();\r\n result = await executeFormAction(actionId, formData);\r\n } else {\r\n const args = await request.json();\r\n result = await executeAction(actionId, Array.isArray(args) ? args : [args]);\r\n }\r\n\r\n return new Response(JSON.stringify(result), {\r\n status: result.success ? 200 : 400,\r\n headers: { 'Content-Type': 'application/json' },\r\n });\r\n } catch (error) {\r\n if (isRedirectError(error)) {\r\n return new Response(null, {\r\n status: 303,\r\n headers: { Location: error.url },\r\n });\r\n }\r\n\r\n return new Response(JSON.stringify({\r\n success: false,\r\n error: error instanceof Error ? error.message : 'Unknown error',\r\n }), {\r\n status: 500,\r\n headers: { 'Content-Type': 'application/json' },\r\n });\r\n }\r\n}\r\n\r\n// ============================================================================\r\n// Re-export New Modules\r\n// ============================================================================\r\n\r\n// Action Middleware - composable middleware for actions\r\nexport * from './middleware.js';\r\n\r\n// Action Streaming - async generator-based streaming actions\r\nexport * from './streaming.js';\r\n\r\n// Action Queue - offline-first action queuing\r\nexport * from './queue.js';\r\n\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-PL37KFRJ.js"}
|
package/dist/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { Middleware, MiddlewareContext, MiddlewareNext, createMiddlewareChain }
|
|
|
5
5
|
export { CustomHydrationTrigger, HydrateOptions, HydrationTrigger, IslandConfig, hydrateIslands, registerFlightIslandElement } from './islands/index.js';
|
|
6
6
|
export { BuiltInCondition, DEFAULT_BOT_PATTERNS, StreamingCondition, isBot, isSlowConnection, prefersNoStream, supportsStreaming } from './streaming/conditional.js';
|
|
7
7
|
export { BadRequestError, ErrorBoundaryOptions, FlightError, FlightErrorOptions, FlightErrorProps, ForbiddenError, InternalError, NotFoundError, ResetDetails, UnauthorizedError, clearError, createError, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError } from './errors/index.js';
|
|
8
|
-
export {
|
|
8
|
+
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './utils/index.js';
|
|
9
9
|
import './render/index.js';
|
|
10
10
|
import './adapters/index.js';
|
|
11
11
|
|
package/dist/client.js
CHANGED
|
@@ -3,7 +3,7 @@ export { hydrateIslands, registerFlightIslandElement } from './chunk-WFAWAHJH.js
|
|
|
3
3
|
export { createMiddlewareChain } from './chunk-OYF2OAKS.js';
|
|
4
4
|
import './chunk-IXMD5QH2.js';
|
|
5
5
|
export { BadRequestError, FlightError, ForbiddenError, InternalError, NotFoundError, UnauthorizedError, clearError, createError, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError } from './chunk-FSJNOPYE.js';
|
|
6
|
-
import './chunk-
|
|
6
|
+
import './chunk-PL37KFRJ.js';
|
|
7
7
|
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './chunk-YHEVHRLH.js';
|
|
8
8
|
export { createRouter } from './chunk-GCQZ4FHI.js';
|
|
9
9
|
export { cacheKey, cached, createCache, dedupe, jsonSerializer, memory } from './chunk-R7SQAREQ.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,7 @@ export { ServerContext as RSCServerContext, createServerContext, isNotFoundError
|
|
|
20
20
|
export { BoundaryType as RSCBoundaryType, detectBoundaryType, hasUseClientDirective, hasUseServerDirective } from './rsc/boundaries.js';
|
|
21
21
|
export { ClientComponent, ComponentType as RSCComponentType, RenderContext as RSCRenderContext, ServerComponent, composeComponents, createAsyncComponent, createClientBoundary, createRenderContext, deserializeProps, executeServerComponent, revalidatePath as rscRevalidatePath, revalidateTag as rscRevalidateTag, serializeProps, serverFetch, withErrorBoundary } from './rsc/legacy.js';
|
|
22
22
|
export { BadRequestError, ErrorBoundaryOptions, FlightError, FlightErrorOptions, FlightErrorProps, ForbiddenError, InternalError, NotFoundError, ResetDetails, UnauthorizedError, clearError, createError, createErrorResponse, forbidden as createForbidden, notFound as createNotFound, unauthorized as createUnauthorized, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError, wrapWithDigest } from './errors/index.js';
|
|
23
|
-
export {
|
|
24
|
-
export { assertClient, assertServer, getEnv, requireEnv } from './utils/index.js';
|
|
25
|
-
import 'vite';
|
|
23
|
+
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './utils/index.js';
|
|
26
24
|
|
|
27
25
|
/**
|
|
28
26
|
* @flight-framework/core - Route Rules Configuration
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { detectBoundaryType, hasUseClientDirective, hasUseServerDirective } from
|
|
|
18
18
|
import './chunk-77MJZCYD.js';
|
|
19
19
|
export { createServer } from './chunk-EGB7C73X.js';
|
|
20
20
|
export { createFileRouter, loadRoutes, scanRoutes } from './chunk-3KRBRSRJ.js';
|
|
21
|
-
export { RedirectError, redirect as actionRedirect, cookies, executeAction, executeFormAction, getAction, handleActionRequest, isRedirectError, parseFormData, registerAction } from './chunk-
|
|
21
|
+
export { RedirectError, redirect as actionRedirect, cookies, executeAction, executeFormAction, getAction, handleActionRequest, isRedirectError, parseFormData, registerAction } from './chunk-3QP3E7HS.js';
|
|
22
22
|
export { createRouteContext, error, json, parseBody, redirect } from './chunk-W6D62JCI.js';
|
|
23
23
|
export { createLazyContent, createStreamingResponse, createStreamingSSR, renderWithStreaming, streamParallel, streamSequential } from './chunk-RSVA2EYO.js';
|
|
24
24
|
export { DEFAULT_BOT_PATTERNS, addStreamingHeaders, createConditionalStreamer, createStreamingResponse as createConditionalStreamingResponse, createStaticResponse, isBot, isSlowConnection, prefersNoStream, streamIf, supportsStreaming } from './chunk-XOIYNY4I.js';
|
|
@@ -26,7 +26,7 @@ export { createIslandRegistry, createPreactIslandAdapter, createReactIslandAdapt
|
|
|
26
26
|
export { createMiddlewareChain } from './chunk-OYF2OAKS.js';
|
|
27
27
|
export { defineConfig } from './chunk-IXMD5QH2.js';
|
|
28
28
|
export { BadRequestError, FlightError, ForbiddenError, InternalError, NotFoundError, UnauthorizedError, clearError, createError, createErrorResponse, forbidden as createForbidden, notFound as createNotFound, unauthorized as createUnauthorized, getError, getErrorStatusCode, isFlightError, isForbiddenError as isForbidden, isNotFoundError as isNotFound, isUnauthorizedError as isUnauthorized, showError, wrapWithDigest } from './chunk-FSJNOPYE.js';
|
|
29
|
-
|
|
29
|
+
import './chunk-PL37KFRJ.js';
|
|
30
30
|
export { getEnvironment, isBrowser, isDevelopment, isProduction, isServer, isTest } from './chunk-YHEVHRLH.js';
|
|
31
31
|
export { createRouter } from './chunk-GCQZ4FHI.js';
|
|
32
32
|
import './chunk-ZVC3ZWLM.js';
|