@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.
Files changed (100) hide show
  1. package/dist/build/compile-entry.d.ts +2 -1
  2. package/dist/build/compile-entry.ts +17 -13
  3. package/dist/build/elysia-aot.d.ts +9 -0
  4. package/dist/build/entry-template.d.ts +5 -1
  5. package/dist/build/entry-template.ts +24 -5
  6. package/dist/build/index.js +753 -453
  7. package/dist/build/server-app-entry.d.ts +12 -0
  8. package/dist/cache.d.ts +1 -0
  9. package/dist/cache.js +185 -0
  10. package/dist/cli/index.js +766 -466
  11. package/dist/client/internal/runtime-types.d.ts +8 -1
  12. package/dist/client/link.js +221 -11
  13. package/dist/client/sync.d.ts +1 -0
  14. package/dist/config.d.ts +22 -21
  15. package/dist/config.js +1 -1
  16. package/dist/define-route.d.ts +273 -1009
  17. package/dist/furin.d.ts +20 -5
  18. package/dist/furin.js +6222 -5383
  19. package/dist/plugin/routes.d.ts +6 -0
  20. package/dist/server/assets/production.d.ts +3 -0
  21. package/dist/server/auto-invalidate/plugin.d.ts +8 -24
  22. package/dist/server/auto-invalidate/runtime.d.ts +2 -2
  23. package/dist/server/cache/invalidation.d.ts +1 -1
  24. package/dist/server/cache/page-cache-state.d.ts +5 -0
  25. package/dist/server/cache/page-cache.d.ts +53 -0
  26. package/dist/server/cache/redis/index.d.ts +39 -0
  27. package/dist/server/cache/redis/index.js +396 -0
  28. package/dist/server/cache/redis/scripts.d.ts +6 -0
  29. package/dist/server/context-logger.d.ts +2 -2
  30. package/dist/server/dev/runtime.production.d.ts +1 -0
  31. package/dist/server/dev-page-plugin.d.ts +7 -0
  32. package/dist/server/evlog.d.ts +14 -0
  33. package/dist/server/internal.d.ts +6 -0
  34. package/dist/server/internal.js +2537 -0
  35. package/dist/server/render/not-found.d.ts +1 -1
  36. package/dist/server/render/ssg.d.ts +5 -0
  37. package/dist/server/render/static-params.d.ts +4 -0
  38. package/dist/server/router/defined-route.d.ts +1 -1
  39. package/dist/server/router/schemas.d.ts +1 -0
  40. package/dist/server/sync/index.js +794 -116
  41. package/dist/server/sync/plugin.d.ts +31 -158
  42. package/dist/server/sync/stream.d.ts +34 -49
  43. package/dist/shared/elysia-contract.d.ts +8 -14
  44. package/package.json +13 -7
  45. package/src/adapter/README.md +9 -2
  46. package/src/adapter/bun.ts +73 -27
  47. package/src/adapter/package.ts +6 -2
  48. package/src/adapter/runtime-build.ts +11 -4
  49. package/src/adapter/static.ts +8 -6
  50. package/src/adapter/vercel.ts +49 -30
  51. package/src/build/client.ts +18 -1
  52. package/src/build/compile-entry.ts +17 -13
  53. package/src/build/elysia-aot.ts +102 -0
  54. package/src/build/entry-template.ts +24 -5
  55. package/src/build/index.ts +0 -5
  56. package/src/build/production-instrumentation.ts +2 -2
  57. package/src/build/server-app-entry.ts +60 -0
  58. package/src/build/shared.ts +3 -1
  59. package/src/build/ssg-cache.ts +5 -10
  60. package/src/build/virtual-entry.ts +5 -4
  61. package/src/cache.ts +12 -0
  62. package/src/cli/config.ts +3 -3
  63. package/src/cli/index.ts +5 -2
  64. package/src/client/internal/runtime-types.ts +10 -1
  65. package/src/client/sync.ts +1 -0
  66. package/src/config.ts +3 -2
  67. package/src/define-route.ts +266 -128
  68. package/src/furin.ts +138 -149
  69. package/src/plugin/route-config-autofix.ts +11 -2
  70. package/src/plugin/routes.ts +85 -29
  71. package/src/server/assets/production.ts +99 -0
  72. package/src/server/auto-invalidate/plugin.ts +4 -4
  73. package/src/server/auto-invalidate/runtime.ts +74 -42
  74. package/src/server/browser-events/plugin.ts +6 -1
  75. package/src/server/cache/invalidation.ts +61 -20
  76. package/src/server/cache/page-cache-state.ts +22 -0
  77. package/src/server/cache/page-cache.ts +300 -0
  78. package/src/server/cache/redis/index.ts +350 -0
  79. package/src/server/cache/redis/scripts.ts +160 -0
  80. package/src/server/context-logger.ts +5 -5
  81. package/src/server/dev/runtime.production.ts +4 -0
  82. package/src/server/dev-page-plugin.ts +54 -10
  83. package/src/server/evlog.ts +99 -0
  84. package/src/server/internal.ts +7 -0
  85. package/src/server/render/isr.ts +480 -132
  86. package/src/server/render/loaders.ts +18 -12
  87. package/src/server/render/not-found.ts +4 -4
  88. package/src/server/render/ppr-document.ts +2 -2
  89. package/src/server/render/ppr-route.ts +193 -7
  90. package/src/server/render/ssg.ts +148 -4
  91. package/src/server/render/ssr.ts +4 -6
  92. package/src/server/render/static-params.ts +174 -0
  93. package/src/server/router/defined-route.ts +2 -1
  94. package/src/server/router/hmr.ts +2 -0
  95. package/src/server/router/plugin.ts +44 -35
  96. package/src/server/router/schema-merge.ts +1 -1
  97. package/src/server/router/schemas.ts +174 -61
  98. package/src/server/sync/plugin.ts +14 -10
  99. package/src/server/sync/response.ts +3 -3
  100. 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
- runInvalidationRules(invalidate);
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, ElysiaCustomStatusResponse, StatusMap } from "elysia";
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 ElysiaCustomStatusResponse)) {
36
+ if (!(value instanceof ElysiaStatus)) {
37
37
  return;
38
38
  }
39
- return { status: value.code, value: value.response };
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 { getSchemaValidator as elysiaGetSchemaValidator } from "elysia";
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) => 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
- interface FurinSchemaValidatorOptions {
32
- coerce?: boolean;
33
- dynamic?: boolean;
34
- }
35
-
36
- export function getSchemaValidator(
37
- schema: FurinSchema,
38
- options: FurinSchemaValidatorOptions
39
- ): FurinSchemaValidator | undefined {
40
- return elysiaGetSchemaValidator(schema, options) as FurinSchemaValidator | undefined;
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 SchemaObject {
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 candidate[TYPEBOX_KIND] === "Object" || candidate["~kind"] === "Object";
56
+ return (
57
+ (candidate[TYPEBOX_KIND] === "Object" || candidate["~kind"] === "Object") &&
58
+ candidate.properties !== null &&
59
+ typeof candidate.properties === "object"
60
+ );
63
61
  }