@supacloud/elysia 0.37.0 → 0.38.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 CHANGED
@@ -8,11 +8,11 @@ is a separately authorized business command, never an assumed rollback.
8
8
 
9
9
  ## Compatibility and Acceptance Boundary
10
10
 
11
- The Elysia peer and development dependency are pinned to `2.0.0-rc.0`.
11
+ The Elysia peer and development dependency are pinned to `2.0.0-rc.1`.
12
12
  The runtime adapter pins Effect `4.0.5` and consumes its `Exit`-based
13
13
  execution boundary.
14
14
  `compatibility.json` records the acceptance target: Bun 1.4.4, Elysia
15
- 2.0.0-rc.0, Effect 4.0.5, `typebox` 1.4.3, `exact-mirror` 1.2.6,
15
+ 2.0.0-rc.1, Effect 4.0.5, `typebox` 1.4.3, `exact-mirror` 1.2.6,
16
16
  TypeScript CLI 7.0.2 and the compiler's separate TypeScript 6 semantic API 6.0.2.
17
17
  The matrix is a
18
18
  required target, not proof of an execution. See the dated, commit-specific
@@ -327,7 +327,7 @@ Runtime adapter that turns `@supacloud/compiler` output into a production-ready
327
327
  ## Installation
328
328
 
329
329
  ```bash
330
- bun add --exact @supacloud/elysia elysia@2.0.0-rc.0
330
+ bun add --exact @supacloud/elysia elysia@2.0.0-rc.1
331
331
  ```
332
332
 
333
333
  ## Usage
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "bun": "1.4.4",
3
3
  "packages": {
4
- "elysia": "2.0.0-rc.0",
4
+ "elysia": "2.0.0-rc.1",
5
5
  "effect": "4.0.5",
6
6
  "typescript": "7.0.2",
7
7
  "typebox": "1.4.3",
package/dist/effect.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * The only production Effect interpreter.
3
+ *
4
+ * Application code returns an Effect program. This adapter owns timeout,
5
+ * the transient-failure allow-list, and the Exit-to-HTTP mapping. It does not
6
+ * replace command receipts, idempotency or durable job retry.
7
+ */
1
8
  import { Effect, Exit } from "effect";
2
9
  import type * as Layer from "effect/Layer";
3
10
  export interface CompiledEffectError {
@@ -5,7 +12,16 @@ export interface CompiledEffectError {
5
12
  readonly status: number;
6
13
  readonly code: string;
7
14
  readonly message?: string;
15
+ readonly codeFromError?: boolean;
16
+ readonly messageFromError?: boolean;
17
+ readonly statusFromError?: boolean;
18
+ /** Framework may retry this declared 5xx failure. Outcome-unknown failures must not set this. */
19
+ readonly retryable?: boolean;
20
+ /** The write may already have happened. Never retried, even when retry is explicit. */
21
+ readonly outcomeUnknown?: boolean;
8
22
  }
23
+ /** An omitted retry policy means no retry; it never enables explicit retry. */
24
+ export declare const DEFAULT_EFFECT_RETRY: "none";
9
25
  export interface CompiledEffectDescriptor {
10
26
  readonly required: true;
11
27
  readonly errors?: readonly CompiledEffectError[];
package/dist/index.js CHANGED
@@ -1016,7 +1016,8 @@ function createDocumentationPlugin(options = {}) {
1016
1016
  }
1017
1017
 
1018
1018
  // src/effect.ts
1019
- import { Cause, Duration, Effect, Exit, ManagedRuntime, Schedule } from "effect";
1019
+ import { Cause, Duration, Effect, Exit, ManagedRuntime } from "effect";
1020
+ var DEFAULT_EFFECT_RETRY = "none";
1020
1021
 
1021
1022
  class EffectApplicationError extends Error {
1022
1023
  status;
@@ -1060,11 +1061,36 @@ function effectErrorTag(error) {
1060
1061
  return error.constructor.name;
1061
1062
  return;
1062
1063
  }
1064
+ function boundedString(value, key, maxLength) {
1065
+ if (!isRecord(value))
1066
+ return;
1067
+ const candidate = value[key];
1068
+ if (typeof candidate !== "string")
1069
+ return;
1070
+ const trimmed = candidate.trim();
1071
+ return trimmed.length === 0 ? undefined : trimmed.slice(0, maxLength);
1072
+ }
1073
+ function boundedStatus(value) {
1074
+ if (!isRecord(value))
1075
+ return;
1076
+ const candidate = value["status"];
1077
+ return typeof candidate === "number" && Number.isInteger(candidate) && candidate >= 400 && candidate <= 599 ? candidate : undefined;
1078
+ }
1079
+ function isFrameworkRetryable(error, descriptor) {
1080
+ const tag = effectErrorTag(error);
1081
+ if (!tag)
1082
+ return false;
1083
+ const mapping = descriptor.errors?.find((entry) => entry.tag === tag);
1084
+ return mapping?.retryable === true && mapping.outcomeUnknown !== true && mapping.statusFromError !== true && mapping.status >= 500 && mapping.status <= 599;
1085
+ }
1063
1086
  function mapEffectFailure(error, descriptor) {
1064
1087
  const tag = effectErrorTag(error);
1065
1088
  const mapping = tag && descriptor?.errors?.find((entry) => entry.tag === tag);
1066
1089
  if (mapping) {
1067
- return new EffectApplicationError(mapping.message ?? mapping.code, mapping.status, mapping.code);
1090
+ const instanceCode = mapping.codeFromError ? boundedString(error, "code", 120) : undefined;
1091
+ const instanceMessage = mapping.messageFromError ? boundedString(error, "message", 500) : undefined;
1092
+ const instanceStatus = mapping.statusFromError ? boundedStatus(error) : undefined;
1093
+ return new EffectApplicationError(instanceMessage ?? mapping.message ?? mapping.code, instanceStatus ?? mapping.status, instanceCode ?? mapping.code);
1068
1094
  }
1069
1095
  if (tag === "TimeoutException" || tag === "TimeoutError") {
1070
1096
  return new EffectApplicationError("Effect execution timed out", 504, "EFFECT_TIMEOUT");
@@ -1082,8 +1108,13 @@ async function runCompiledEffect(value, descriptor, runtime = createDefaultEffec
1082
1108
  if (descriptor?.timeoutMs !== undefined) {
1083
1109
  program = Effect.timeout(program, Duration.millis(descriptor.timeoutMs));
1084
1110
  }
1085
- if (descriptor?.retry === "explicit" && descriptor.maxAttempts !== undefined && descriptor.maxAttempts > 1) {
1086
- program = Effect.retry(program, Schedule.recurs(descriptor.maxAttempts - 1));
1111
+ const retry = descriptor?.retry ?? DEFAULT_EFFECT_RETRY;
1112
+ const maxAttempts = descriptor?.maxAttempts;
1113
+ if (retry === "explicit" && maxAttempts !== undefined && maxAttempts > 1 && descriptor) {
1114
+ program = Effect.retry(program, {
1115
+ times: maxAttempts - 1,
1116
+ while: (error) => isFrameworkRetryable(error, descriptor)
1117
+ });
1087
1118
  }
1088
1119
  const exit = await runtime.run(program);
1089
1120
  if (Exit.isSuccess(exit))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/elysia",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "description": "Elysia runtime adapter for SupaCloud compiled modules: application/request scopes, route registration and validation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,7 +49,7 @@
49
49
  "directory": "packages/elysia"
50
50
  },
51
51
  "dependencies": {
52
- "@supacloud/app": "0.35.0",
52
+ "@supacloud/app": "0.36.0",
53
53
  "@supacloud/commands": "0.11.2",
54
54
  "@supacloud/contracts": "0.15.2",
55
55
  "effect": "4.0.5",
@@ -58,20 +58,20 @@
58
58
  "typebox": "1.4.3"
59
59
  },
60
60
  "overrides": {
61
- "@supacloud/delivery": "0.23.1",
61
+ "@supacloud/delivery": "0.24.0",
62
62
  "@supacloud/contracts": "0.15.2",
63
63
  "@supacloud/commands": "0.11.2",
64
64
  "@graphql-tools/utils": "^12.0.4"
65
65
  },
66
66
  "peerDependencies": {
67
- "elysia": "2.0.0-rc.0"
67
+ "elysia": "2.0.0-rc.1"
68
68
  },
69
69
  "devDependencies": {
70
- "@supacloud/compiler": "0.52.2",
71
- "@supacloud/delivery": "0.23.1",
72
- "@supacloud/db": "0.20.3",
70
+ "@supacloud/compiler": "0.54.0",
71
+ "@supacloud/delivery": "0.24.0",
72
+ "@supacloud/db": "0.20.4",
73
73
  "@types/bun": "^1.4.4",
74
- "elysia": "2.0.0-rc.0",
74
+ "elysia": "2.0.0-rc.1",
75
75
  "typescript": "^7.0.2"
76
76
  }
77
77
  }