@trysqless/node 0.2.0 → 0.2.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/README.md CHANGED
@@ -87,6 +87,8 @@ const { eventIds } = await db.executeWithEvents(
87
87
 
88
88
  Webhooks accept public HTTP and HTTPS URLs. The default method is `POST`. Supported methods are `GET`, `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE` and `OPTIONS`. Supply `payload` for JSON, `body` for raw UTF-8 text, or omit both for an empty request. Put query parameters in the URL. Use `headers` for application headers and content types. Header names and values total at most 32 KiB per event. Use HTTPS for credentials.
89
89
 
90
+ Use an RFC 3339 timestamp in `startedAt` to schedule the first attempt. For example, `startedAt: new Date(Date.now() + 300_000).toISOString()` schedules delivery in five minutes. The initial pending event reports this time in `nextAttemptAt`. The scheduled-event wire operation is `execute_with_scheduled_events`, with native HTTP endpoint `POST /api/v1/sql/scheduled-events`.
91
+
90
92
  SQLess sends the saved request after commit, and reuses it for retries. Deliveries can be duplicated and can arrive in any order. Return 2xx after recording the stable `Idempotency-Key` and processing the request. SQLess supplies `Idempotency-Key`, `X-SQLess-Event-ID` and transport headers such as `Host` and `Content-Length`. Failed attempts back off exponentially for 30 minutes, then retry hourly for up to 24 hours from the first failure. The database task queue records the final outcome. Clients implementing the wire protocol directly can use `execute_with_http_events` over WebSocket or `POST /api/v1/sql/http-events` on a native database endpoint so older peers reject an unsupported request before executing SQL.
91
93
 
92
94
  Concurrent `execute()` calls share one authenticated WebSocket and a bounded
package/index.d.ts CHANGED
@@ -17,6 +17,8 @@ export interface StatementResult {
17
17
  export type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
18
18
  export type WebhookEvent = {
19
19
  webhook: string;
20
+ /** Earliest delivery time, in RFC 3339 format. */
21
+ startedAt?: string;
20
22
  method?: 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
21
23
  headers?: Record<string, string>;
22
24
  } & ({ payload?: JSONValue; body?: never } | { body: string; payload?: never });
package/index.js CHANGED
@@ -8,6 +8,7 @@ function execution(options) {
8
8
  if (options?.events === undefined) return { op: 'execute' };
9
9
  const { events } = options;
10
10
  if (!Array.isArray(events) || !events.length) throw new TypeError('events must be a nonempty array');
11
+ if (events.some(e => e.startedAt != null)) return { op: 'execute_with_scheduled_events', events };
11
12
  const extended = events.some(e => e.method != null || Object.keys(e.headers ?? {}).length > 0 ||
12
13
  e.body != null || e.payload === undefined || !e.webhook.startsWith('https://'));
13
14
  return { op: extended ? 'execute_with_http_events' : 'execute_with_events', events };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trysqless/node",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Method-based Node.js SDK for SQLess over authenticated WebSocket",
5
5
  "repository": {
6
6
  "type": "git",
package/transport.js CHANGED
@@ -66,7 +66,7 @@ class Session {
66
66
  this.chunks = []; this.bytes = 0; this.expected = null;
67
67
  const pending = this.pending;
68
68
  if (response.version !== 1 || response.id !== pending.id) throw new Error('SQLess response identity mismatch');
69
- if (pending.op === 'execute' || pending.op === 'execute_with_events' || pending.op === 'execute_with_http_events' || response.sessionState === 'closed') this.state = response.sessionState;
69
+ if (pending.op === 'execute' || pending.op === 'execute_with_events' || pending.op === 'execute_with_http_events' || pending.op === 'execute_with_scheduled_events' || response.sessionState === 'closed') this.state = response.sessionState;
70
70
  this.pending = null; clearTimeout(pending.timer);
71
71
  if (response.error) pending.reject(new SQLessError(response)); else pending.resolve(response);
72
72
  if (response.sessionState === 'closed') this.close(new Error('SQLess session closed'));