@pylonsync/functions 0.3.289 → 0.3.291

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.3.289",
3
+ "version": "0.3.291",
4
4
  "description": "TypeScript function runtime for pylon — defines server-side queries, mutations, and actions.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/define.ts CHANGED
@@ -52,6 +52,21 @@ interface CommonDef {
52
52
  * own gate.
53
53
  */
54
54
  internal?: boolean;
55
+ /**
56
+ * Max wall-clock SECONDS this function may run before the runtime
57
+ * recycles its worker as wedged. Defaults to `PYLON_FN_CALL_TIMEOUT`
58
+ * (30s). Raise it for legitimately long-running work — heavy renders,
59
+ * big batch jobs, slow external calls — so the call isn't force-killed
60
+ * mid-flight. This also lifts the runtime's wedge backstop for the
61
+ * worker while such a call is in flight, so a busy-but-progressing
62
+ * worker (e.g. one doing synchronous canvas/image work that blocks the
63
+ * event loop) isn't respawned out from under the work.
64
+ *
65
+ * Keep it as small as the work honestly needs: a genuinely stuck call
66
+ * still ties up its worker until this deadline. Prefer offloading very
67
+ * heavy CPU work to a dedicated service over setting a huge timeout.
68
+ */
69
+ timeout?: number;
55
70
  }
56
71
 
57
72
  interface QueryDefRequired<TArgs, TReturn> extends CommonDef {
@@ -152,6 +167,7 @@ export function query<TArgs, TReturn>(
152
167
  handler: def.handler as FnDefinition<TArgs, TReturn>["handler"],
153
168
  internal: def.internal,
154
169
  auth: def.auth ?? DEFAULT_AUTH,
170
+ timeout: def.timeout,
155
171
  };
156
172
  }
157
173
 
@@ -201,6 +217,7 @@ export function mutation<TArgs, TReturn>(
201
217
  handler: def.handler as FnDefinition<TArgs, TReturn>["handler"],
202
218
  internal: def.internal,
203
219
  auth: def.auth ?? DEFAULT_AUTH,
220
+ timeout: def.timeout,
204
221
  };
205
222
  }
206
223
 
@@ -265,5 +282,6 @@ export function action<TArgs, TReturn>(
265
282
  handler: def.handler as FnDefinition<TArgs, TReturn>["handler"],
266
283
  internal: def.internal,
267
284
  auth: def.auth ?? DEFAULT_AUTH,
285
+ timeout: def.timeout,
268
286
  };
269
287
  }
package/src/runtime.ts CHANGED
@@ -1046,6 +1046,13 @@ async function main() {
1046
1046
  // it — secure by default. See `packages/functions/src/define.ts`
1047
1047
  // for the developer-facing AuthMode docs.
1048
1048
  auth: def.auth ?? "user",
1049
+ // Per-function call deadline in seconds. Null → the host uses its
1050
+ // global PYLON_FN_CALL_TIMEOUT default. Drives both the call deadline
1051
+ // and the wedge backstop for this function's worker.
1052
+ timeout_secs:
1053
+ typeof def.timeout === "number" && def.timeout > 0
1054
+ ? Math.floor(def.timeout)
1055
+ : null,
1049
1056
  }));
1050
1057
  send({ type: "ready", functions });
1051
1058
 
package/src/types.ts CHANGED
@@ -645,6 +645,13 @@ export interface FnDefinition<TArgs = unknown, TReturn = unknown> {
645
645
  * unless explicitly opted out via `auth: "public"`. See [`AuthMode`].
646
646
  */
647
647
  auth?: AuthMode;
648
+ /**
649
+ * Max wall-clock seconds this function may run before the runtime
650
+ * recycles its worker. Defaults to `PYLON_FN_CALL_TIMEOUT` (30s).
651
+ * Raise for legitimately long-running work; also lifts the wedge
652
+ * backstop while the call is in flight. See the `timeout` option docs.
653
+ */
654
+ timeout?: number;
648
655
  }
649
656
 
650
657
  // ---------------------------------------------------------------------------