zitejs 0.9.145 → 0.9.147

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.
@@ -116,11 +116,11 @@ export type ZiteDatabaseTriggerInput<TRecord extends Record<string, unknown> = R
116
116
  event: ZiteDatabaseTriggerEvent;
117
117
  table: string;
118
118
  recordId: string;
119
- /** Null if it was deleted before the run read it; on `"deleted"`, the record as it was. */
119
+ /** Null on `"deleted"`, which leaves only `recordId`, and if it was deleted before the run read it. */
120
120
  record: TRecord | null;
121
121
  /** The record before an `"updated"`; null otherwise, and on a very large bulk write. */
122
122
  previous: TRecord | null;
123
- /** What an `"updated"` changed. */
123
+ /** What an `"updated"` changed; on a very large bulk write, what the write changed across its records. */
124
124
  changedFields: string[];
125
125
  };
126
126
  /**
@@ -307,7 +307,9 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
307
307
  * its result is saved before anything after it executes, and when a
308
308
  * failed run is resumed, completed steps return their saved results
309
309
  * instead of re-running their side effects. Names must be unique within
310
- * a run, and results must be plain JSON data under 256KB.
310
+ * a run, and results must be plain JSON data under 256KB. In a run
311
+ * fired by a schedule, webhook or trigger, `step.sleep` pauses the run
312
+ * and a failed step is tried again.
311
313
  */
312
314
  step: ZiteStep;
313
315
  context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;
@@ -326,8 +328,32 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
326
328
  * it would matter, and give a step inside a loop the item's id in its name.
327
329
  */
328
330
  export interface ZiteStep {
329
- run<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
331
+ /**
332
+ * In a run fired by a schedule, webhook or trigger, a step that throws is
333
+ * tried again `retries` more times (default 3, at most 10), 30 seconds,
334
+ * 2 minutes, then 10 minutes apart. Elsewhere its error fails the request.
335
+ */
336
+ run<T>(name: string, fn: () => Promise<T> | T, options?: ZiteStepOptions): Promise<T>;
337
+ /**
338
+ * Pause the run for `duration`: `"30s"`, `"15m"`, `"2h"`, `"3d"`, `"1w"`,
339
+ * or milliseconds, at most 30 days. Only a run fired by a schedule, webhook
340
+ * or trigger can wait; an editor test run goes straight past, and a request
341
+ * from the app throws.
342
+ *
343
+ * The run continues in a later call, which runs `execute` again from the
344
+ * top: finished steps return their saved results, and code outside a step
345
+ * runs again, so keep side effects inside steps.
346
+ */
347
+ sleep(name: string, duration: ZiteStepDuration): Promise<void>;
348
+ /** Pause the run until `when`, at most 30 days ahead. See {@link ZiteStep.sleep}. */
349
+ sleepUntil(name: string, when: Date | string): Promise<void>;
350
+ }
351
+ export interface ZiteStepOptions {
352
+ /** How many more times to try the step after it throws: 0 to 10, default 3. */
353
+ retries?: number;
330
354
  }
355
+ /** Milliseconds, or a number with a unit: `ms`, `s`, `m`, `h`, `d` or `w`. */
356
+ export type ZiteStepDuration = number | `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`;
331
357
  /**
332
358
  * Create an endpoint definition, parsing `input` against `inputSchema` before
333
359
  * `execute` runs. Nothing downstream parses it — the worker calls `execute` on
@@ -8,6 +8,8 @@ const requestContext = { user: { id: "u1", email: "a@b.c", roles: [] } };
8
8
  // Direct execute() calls need the step surface the runtime always provides.
9
9
  const stepStub = {
10
10
  run: async (_name, fn) => await fn(),
11
+ sleep: async () => { },
12
+ sleepUntil: async () => { },
11
13
  };
12
14
  (0, vitest_1.afterEach)(() => {
13
15
  vitest_1.vi.unstubAllGlobals();
@@ -1331,7 +1331,7 @@ function generateBackendWrapperTs(envVarNames = []) {
1331
1331
  " execute: (",
1332
1332
  " params: {",
1333
1333
  " input: ZiteEndpointInput<TInput, TTrigger>;",
1334
- " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. Provided by the platform; never define a local stand-in. */",
1334
+ " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, \"2d\") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */",
1335
1335
  " step: ZiteStep;",
1336
1336
  " context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
1337
1337
  // Mirrors the base module: a trigger's run gets `trigger`.
@@ -116,11 +116,11 @@ export type ZiteDatabaseTriggerInput<TRecord extends Record<string, unknown> = R
116
116
  event: ZiteDatabaseTriggerEvent;
117
117
  table: string;
118
118
  recordId: string;
119
- /** Null if it was deleted before the run read it; on `"deleted"`, the record as it was. */
119
+ /** Null on `"deleted"`, which leaves only `recordId`, and if it was deleted before the run read it. */
120
120
  record: TRecord | null;
121
121
  /** The record before an `"updated"`; null otherwise, and on a very large bulk write. */
122
122
  previous: TRecord | null;
123
- /** What an `"updated"` changed. */
123
+ /** What an `"updated"` changed; on a very large bulk write, what the write changed across its records. */
124
124
  changedFields: string[];
125
125
  };
126
126
  /**
@@ -307,7 +307,9 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
307
307
  * its result is saved before anything after it executes, and when a
308
308
  * failed run is resumed, completed steps return their saved results
309
309
  * instead of re-running their side effects. Names must be unique within
310
- * a run, and results must be plain JSON data under 256KB.
310
+ * a run, and results must be plain JSON data under 256KB. In a run
311
+ * fired by a schedule, webhook or trigger, `step.sleep` pauses the run
312
+ * and a failed step is tried again.
311
313
  */
312
314
  step: ZiteStep;
313
315
  context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;
@@ -326,8 +328,32 @@ export interface EndpointConfig<TInput = unknown, TOutput = unknown, TStream ext
326
328
  * it would matter, and give a step inside a loop the item's id in its name.
327
329
  */
328
330
  export interface ZiteStep {
329
- run<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
331
+ /**
332
+ * In a run fired by a schedule, webhook or trigger, a step that throws is
333
+ * tried again `retries` more times (default 3, at most 10), 30 seconds,
334
+ * 2 minutes, then 10 minutes apart. Elsewhere its error fails the request.
335
+ */
336
+ run<T>(name: string, fn: () => Promise<T> | T, options?: ZiteStepOptions): Promise<T>;
337
+ /**
338
+ * Pause the run for `duration`: `"30s"`, `"15m"`, `"2h"`, `"3d"`, `"1w"`,
339
+ * or milliseconds, at most 30 days. Only a run fired by a schedule, webhook
340
+ * or trigger can wait; an editor test run goes straight past, and a request
341
+ * from the app throws.
342
+ *
343
+ * The run continues in a later call, which runs `execute` again from the
344
+ * top: finished steps return their saved results, and code outside a step
345
+ * runs again, so keep side effects inside steps.
346
+ */
347
+ sleep(name: string, duration: ZiteStepDuration): Promise<void>;
348
+ /** Pause the run until `when`, at most 30 days ahead. See {@link ZiteStep.sleep}. */
349
+ sleepUntil(name: string, when: Date | string): Promise<void>;
350
+ }
351
+ export interface ZiteStepOptions {
352
+ /** How many more times to try the step after it throws: 0 to 10, default 3. */
353
+ retries?: number;
330
354
  }
355
+ /** Milliseconds, or a number with a unit: `ms`, `s`, `m`, `h`, `d` or `w`. */
356
+ export type ZiteStepDuration = number | `${number}${"ms" | "s" | "m" | "h" | "d" | "w"}`;
331
357
  /**
332
358
  * Create an endpoint definition, parsing `input` against `inputSchema` before
333
359
  * `execute` runs. Nothing downstream parses it — the worker calls `execute` on
@@ -6,6 +6,8 @@ const requestContext = { user: { id: "u1", email: "a@b.c", roles: [] } };
6
6
  // Direct execute() calls need the step surface the runtime always provides.
7
7
  const stepStub = {
8
8
  run: async (_name, fn) => await fn(),
9
+ sleep: async () => { },
10
+ sleepUntil: async () => { },
9
11
  };
10
12
  afterEach(() => {
11
13
  vi.unstubAllGlobals();
@@ -1316,7 +1316,7 @@ export function generateBackendWrapperTs(envVarNames = []) {
1316
1316
  " execute: (",
1317
1317
  " params: {",
1318
1318
  " input: ZiteEndpointInput<TInput, TTrigger>;",
1319
- " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. Provided by the platform; never define a local stand-in. */",
1319
+ " /** Durable steps: step.run(name, fn) runs fn once per logical run — its result is saved before anything after it executes, and a resumed run replays completed steps from their saved results. In a run fired by a schedule, webhook or trigger, step.sleep(name, \"2d\") pauses the run and a failed step is tried again. Provided by the platform; never define a local stand-in. */",
1320
1320
  " step: ZiteStep;",
1321
1321
  " context: TSchedule extends ZiteSchedule ? ZiteRequestContext | ZiteScheduledContext : TWebhook extends ZiteWebhook ? ZiteRequestContext | ZiteScheduledContext : TTrigger extends ZiteTrigger ? ZiteRequestContext | ZiteScheduledContext : ZiteRequestContext;",
1322
1322
  // Mirrors the base module: a trigger's run gets `trigger`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.145",
3
+ "version": "0.9.147",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "sideEffects": false,