@teyik0/furin 0.4.0-alpha.2 → 0.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/compile-entry.d.ts +2 -1
- package/dist/build/compile-entry.ts +17 -13
- package/dist/build/elysia-aot.d.ts +9 -0
- package/dist/build/entry-template.d.ts +5 -1
- package/dist/build/entry-template.ts +24 -5
- package/dist/build/index.js +753 -453
- package/dist/build/server-app-entry.d.ts +12 -0
- package/dist/cache.d.ts +1 -0
- package/dist/cache.js +185 -0
- package/dist/cli/index.js +766 -466
- package/dist/client/internal/runtime-types.d.ts +8 -1
- package/dist/client/link.js +221 -11
- package/dist/client/sync.d.ts +1 -0
- package/dist/config.d.ts +22 -21
- package/dist/config.js +1 -1
- package/dist/define-route.d.ts +273 -1009
- package/dist/furin.d.ts +20 -5
- package/dist/furin.js +6222 -5383
- package/dist/plugin/routes.d.ts +6 -0
- package/dist/server/assets/production.d.ts +3 -0
- package/dist/server/auto-invalidate/plugin.d.ts +8 -24
- package/dist/server/auto-invalidate/runtime.d.ts +2 -2
- package/dist/server/cache/invalidation.d.ts +1 -1
- package/dist/server/cache/page-cache-state.d.ts +5 -0
- package/dist/server/cache/page-cache.d.ts +53 -0
- package/dist/server/cache/redis/index.d.ts +39 -0
- package/dist/server/cache/redis/index.js +396 -0
- package/dist/server/cache/redis/scripts.d.ts +6 -0
- package/dist/server/context-logger.d.ts +2 -2
- package/dist/server/dev/runtime.production.d.ts +1 -0
- package/dist/server/dev-page-plugin.d.ts +7 -0
- package/dist/server/evlog.d.ts +14 -0
- package/dist/server/internal.d.ts +6 -0
- package/dist/server/internal.js +2537 -0
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ssg.d.ts +5 -0
- package/dist/server/render/static-params.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +1 -1
- package/dist/server/router/schemas.d.ts +1 -0
- package/dist/server/sync/index.js +794 -116
- package/dist/server/sync/plugin.d.ts +31 -158
- package/dist/server/sync/stream.d.ts +34 -49
- package/dist/shared/elysia-contract.d.ts +8 -14
- package/package.json +13 -7
- package/src/adapter/README.md +9 -2
- package/src/adapter/bun.ts +73 -27
- package/src/adapter/package.ts +6 -2
- package/src/adapter/runtime-build.ts +11 -4
- package/src/adapter/static.ts +8 -6
- package/src/adapter/vercel.ts +49 -30
- package/src/build/client.ts +18 -1
- package/src/build/compile-entry.ts +17 -13
- package/src/build/elysia-aot.ts +102 -0
- package/src/build/entry-template.ts +24 -5
- package/src/build/index.ts +0 -5
- package/src/build/production-instrumentation.ts +2 -2
- package/src/build/server-app-entry.ts +60 -0
- package/src/build/shared.ts +3 -1
- package/src/build/ssg-cache.ts +5 -10
- package/src/build/virtual-entry.ts +5 -4
- package/src/cache.ts +12 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +5 -2
- package/src/client/internal/runtime-types.ts +10 -1
- package/src/client/sync.ts +1 -0
- package/src/config.ts +3 -2
- package/src/define-route.ts +266 -128
- package/src/furin.ts +138 -149
- package/src/plugin/route-config-autofix.ts +11 -2
- package/src/plugin/routes.ts +85 -29
- package/src/server/assets/production.ts +99 -0
- package/src/server/auto-invalidate/plugin.ts +4 -4
- package/src/server/auto-invalidate/runtime.ts +74 -42
- package/src/server/browser-events/plugin.ts +6 -1
- package/src/server/cache/invalidation.ts +61 -20
- package/src/server/cache/page-cache-state.ts +22 -0
- package/src/server/cache/page-cache.ts +300 -0
- package/src/server/cache/redis/index.ts +350 -0
- package/src/server/cache/redis/scripts.ts +160 -0
- package/src/server/context-logger.ts +5 -5
- package/src/server/dev/runtime.production.ts +4 -0
- package/src/server/dev-page-plugin.ts +54 -10
- package/src/server/evlog.ts +99 -0
- package/src/server/internal.ts +7 -0
- package/src/server/render/isr.ts +480 -132
- package/src/server/render/loaders.ts +18 -12
- package/src/server/render/not-found.ts +4 -4
- package/src/server/render/ppr-document.ts +2 -2
- package/src/server/render/ppr-route.ts +193 -7
- package/src/server/render/ssg.ts +148 -4
- package/src/server/render/ssr.ts +4 -6
- package/src/server/render/static-params.ts +174 -0
- package/src/server/router/defined-route.ts +2 -1
- package/src/server/router/hmr.ts +2 -0
- package/src/server/router/plugin.ts +44 -35
- package/src/server/router/schema-merge.ts +1 -1
- package/src/server/router/schemas.ts +174 -61
- package/src/server/sync/plugin.ts +14 -10
- package/src/server/sync/response.ts +3 -3
- package/src/shared/elysia-contract.ts +23 -25
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "../auto-invalidate/runtime.ts";
|
|
7
7
|
import type { InvalidationInput } from "../auto-invalidate/types.ts";
|
|
8
8
|
import { peekPendingInvalidations } from "../cache/invalidation.ts";
|
|
9
|
+
import { getLogger } from "../context-logger.ts";
|
|
9
10
|
import type { MutationLease, SyncInvalidation, SyncRuntimeOptions } from "./adapter.ts";
|
|
10
11
|
import { createMutationFingerprint } from "./fingerprint.ts";
|
|
11
12
|
import { mergeStoredResponseHeaders, replayResponse, storeResponse } from "./response.ts";
|
|
@@ -41,11 +42,7 @@ interface MutationContext {
|
|
|
41
42
|
|
|
42
43
|
type TransportHook<TContext> = (context: TContext) => Promise<void>;
|
|
43
44
|
|
|
44
|
-
type CompletionContext = MutationContext &
|
|
45
|
-
Pick<Context, "set"> & {
|
|
46
|
-
response?: unknown;
|
|
47
|
-
responseValue?: unknown;
|
|
48
|
-
};
|
|
45
|
+
type CompletionContext = MutationContext & Parameters<typeof isSuccessfulMutationResponse>[0];
|
|
49
46
|
type PathInvalidation = Extract<SyncInvalidation, { kind: "path" }>;
|
|
50
47
|
|
|
51
48
|
const routeMetadata = new WeakMap<Request, RouteSyncMetadata>();
|
|
@@ -213,8 +210,15 @@ export function furinSync(options: SyncRuntimeOptions) {
|
|
|
213
210
|
const result = await storeResponse(ctx.responseValue, ctx.set);
|
|
214
211
|
const manualPending = peekPendingInvalidations();
|
|
215
212
|
const invalidate = routeMetadata.get(ctx.request)?.invalidate;
|
|
213
|
+
const logger = getLogger();
|
|
216
214
|
if (invalidate) {
|
|
217
|
-
|
|
215
|
+
try {
|
|
216
|
+
await runInvalidationRules(invalidate);
|
|
217
|
+
} catch {
|
|
218
|
+
logger.warn(
|
|
219
|
+
"Sync cache invalidation failed after mutation; preserving the idempotent result"
|
|
220
|
+
);
|
|
221
|
+
}
|
|
218
222
|
}
|
|
219
223
|
const pending = appendPendingInvalidationHeader(ctx.set);
|
|
220
224
|
if (pending.length > 0) {
|
|
@@ -277,6 +281,9 @@ export function furinSync(options: SyncRuntimeOptions) {
|
|
|
277
281
|
const finishMutationHook = hideTransportResponse(finishMutation);
|
|
278
282
|
|
|
279
283
|
return new Elysia({ name: "furin-sync" })
|
|
284
|
+
.beforeHandle("global", beginMutationHook)
|
|
285
|
+
.afterHandle("global", finishMutationHook)
|
|
286
|
+
.error("global", ({ request }) => abortMutation(request))
|
|
280
287
|
.macro({
|
|
281
288
|
sync(input: SyncRouteOption) {
|
|
282
289
|
return {
|
|
@@ -290,8 +297,5 @@ export function furinSync(options: SyncRuntimeOptions) {
|
|
|
290
297
|
},
|
|
291
298
|
};
|
|
292
299
|
},
|
|
293
|
-
})
|
|
294
|
-
.onBeforeHandle({ as: "global" }, beginMutationHook)
|
|
295
|
-
.onAfterHandle({ as: "global" }, finishMutationHook)
|
|
296
|
-
.onError({ as: "global" }, ({ request }) => abortMutation(request));
|
|
300
|
+
});
|
|
297
301
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Context,
|
|
1
|
+
import { type Context, ElysiaStatus, StatusMap } from "elysia";
|
|
2
2
|
import type { StoredResponse } from "./adapter.ts";
|
|
3
3
|
|
|
4
4
|
const NON_REPLAYABLE_HEADERS = new Set([
|
|
@@ -33,10 +33,10 @@ function statusCode(status: Context["set"]["status"]): number {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function unwrapStatusResponse(value: unknown): { status: number; value: unknown } | undefined {
|
|
36
|
-
if (!(value instanceof
|
|
36
|
+
if (!(value instanceof ElysiaStatus)) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
return { status: value.
|
|
39
|
+
return { status: value.status, value: value.response };
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function responseHeaders(headers: Context["set"]["headers"]): Headers {
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
parseQueryFromURL as elysiaParseQueryFromURL,
|
|
4
|
-
parseQueryStandardSchema as elysiaParseQueryStandardSchema,
|
|
5
|
-
} from "elysia/parse-query";
|
|
6
|
-
import { TypeCompiler as ElysiaTypeCompiler } from "elysia/type-system";
|
|
7
|
-
import type { AnySchema, UnwrapSchema } from "elysia/types";
|
|
8
|
-
|
|
9
|
-
export const parseQueryFromURL = elysiaParseQueryFromURL;
|
|
10
|
-
export const parseQueryStandardSchema = elysiaParseQueryStandardSchema;
|
|
11
|
-
export const TypeCompiler = ElysiaTypeCompiler;
|
|
1
|
+
import { type AnySchema, type UnwrapSchema, Validator } from "elysia";
|
|
12
2
|
|
|
13
3
|
interface SchemaObject {
|
|
14
4
|
[key: string]: unknown;
|
|
15
5
|
}
|
|
16
6
|
|
|
7
|
+
interface TypeBoxObjectSchema extends SchemaObject {
|
|
8
|
+
properties: SchemaObject;
|
|
9
|
+
}
|
|
10
|
+
|
|
17
11
|
const TYPEBOX_KIND = Symbol.for("TypeBox.Kind");
|
|
18
12
|
|
|
19
13
|
/**
|
|
@@ -23,21 +17,21 @@ const TYPEBOX_KIND = Symbol.for("TypeBox.Kind");
|
|
|
23
17
|
export type FurinSchema = AnySchema;
|
|
24
18
|
|
|
25
19
|
interface FurinSchemaValidator {
|
|
26
|
-
Check: (value: unknown) =>
|
|
20
|
+
Check: (value: unknown) => boolean;
|
|
27
21
|
Errors: (value: unknown) => Iterable<unknown>;
|
|
28
|
-
parse: (value: unknown) => unknown
|
|
22
|
+
parse: (value: unknown, type: "params" | "query") => Promise<unknown>;
|
|
29
23
|
}
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
export function getSchemaValidator(schema: FurinSchema): FurinSchemaValidator | undefined {
|
|
26
|
+
const validator = Validator.create(schema);
|
|
27
|
+
if (validator === undefined) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
Check: (value) => validator.Check(value),
|
|
32
|
+
Errors: (value) => validator.Errors(value),
|
|
33
|
+
parse: async (value, type) => (validator.From ? await validator.From(value, type) : value),
|
|
34
|
+
};
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
export type FurinUnwrap<Schema extends FurinSchema | undefined> = UnwrapSchema<Schema>;
|
|
@@ -54,10 +48,14 @@ export type ElysiaRouteParams<Leaf> = Leaf extends { params: infer Params } ? Pa
|
|
|
54
48
|
|
|
55
49
|
export type ElysiaRouteQuery<Leaf> = Leaf extends { query: infer Query } ? Query : never;
|
|
56
50
|
|
|
57
|
-
export function isTypeBoxObjectSchema(schema: unknown): schema is
|
|
51
|
+
export function isTypeBoxObjectSchema(schema: unknown): schema is TypeBoxObjectSchema {
|
|
58
52
|
if (schema === null || typeof schema !== "object") {
|
|
59
53
|
return false;
|
|
60
54
|
}
|
|
61
55
|
const candidate = schema as SchemaObject & { [key: symbol]: unknown };
|
|
62
|
-
return
|
|
56
|
+
return (
|
|
57
|
+
(candidate[TYPEBOX_KIND] === "Object" || candidate["~kind"] === "Object") &&
|
|
58
|
+
candidate.properties !== null &&
|
|
59
|
+
typeof candidate.properties === "object"
|
|
60
|
+
);
|
|
63
61
|
}
|