nowity 1.2.1 → 1.5.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.
Files changed (57) hide show
  1. package/README.md +316 -3
  2. package/dist/client/connection.d.ts +2 -0
  3. package/dist/client/connection.d.ts.map +1 -1
  4. package/dist/client/connection.js +13 -0
  5. package/dist/client/nowity-client.d.ts +23 -0
  6. package/dist/client/nowity-client.d.ts.map +1 -1
  7. package/dist/client/nowity-client.js +29 -1
  8. package/dist/client/overlay.d.ts +52 -2
  9. package/dist/client/overlay.d.ts.map +1 -1
  10. package/dist/client/overlay.js +43 -0
  11. package/dist/client.d.ts +1 -1
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/core/protocol.d.ts +20 -1
  14. package/dist/core/protocol.d.ts.map +1 -1
  15. package/dist/index.d.ts +5 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +12 -1
  18. package/dist/server/api/collector.d.ts.map +1 -1
  19. package/dist/server/api/collector.js +4 -1
  20. package/dist/server/api/configure.d.ts +24 -0
  21. package/dist/server/api/configure.d.ts.map +1 -1
  22. package/dist/server/api/configure.js +51 -1
  23. package/dist/server/api/execution.d.ts +9 -0
  24. package/dist/server/api/execution.d.ts.map +1 -1
  25. package/dist/server/api/execution.js +19 -0
  26. package/dist/server/api/presence.d.ts +66 -0
  27. package/dist/server/api/presence.d.ts.map +1 -0
  28. package/dist/server/api/presence.js +181 -0
  29. package/dist/server/api/read-keys.d.ts +6 -0
  30. package/dist/server/api/read-keys.d.ts.map +1 -1
  31. package/dist/server/api/read-keys.js +12 -0
  32. package/dist/server/api/runtime.d.ts.map +1 -1
  33. package/dist/server/api/runtime.js +12 -0
  34. package/dist/server/api/scheduler.d.ts +122 -0
  35. package/dist/server/api/scheduler.d.ts.map +1 -0
  36. package/dist/server/api/scheduler.js +217 -0
  37. package/dist/server/change-source/wal-change-source.d.ts.map +1 -1
  38. package/dist/server/change-source/wal-change-source.js +10 -1
  39. package/dist/server/leader.d.ts +138 -0
  40. package/dist/server/leader.d.ts.map +1 -0
  41. package/dist/server/leader.js +342 -0
  42. package/dist/server/presence.d.ts +217 -0
  43. package/dist/server/presence.d.ts.map +1 -0
  44. package/dist/server/presence.js +428 -0
  45. package/dist/server/scheduler.d.ts +195 -0
  46. package/dist/server/scheduler.d.ts.map +1 -0
  47. package/dist/server/scheduler.js +432 -0
  48. package/dist/server/setup-sql.d.ts +1 -1
  49. package/dist/server/setup-sql.d.ts.map +1 -1
  50. package/dist/server/setup-sql.js +547 -0
  51. package/dist/server/sync-engine.d.ts +22 -1
  52. package/dist/server/sync-engine.d.ts.map +1 -1
  53. package/dist/server/sync-engine.js +30 -1
  54. package/dist/server/ws-server.d.ts +22 -0
  55. package/dist/server/ws-server.d.ts.map +1 -1
  56. package/dist/server/ws-server.js +81 -1
  57. package/package.json +1 -1
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Presence = exports.PRESENCE_TABLE = void 0;
10
+ exports.bindPresenceReader = bindPresenceReader;
11
+ /**
12
+ * Presence, as an endpoint reads it.
13
+ *
14
+ * Injectable like `Session` and `Db`, and ambient in the same way: inside a
15
+ * `@query` every read goes through the execution's own snapshot and is recorded
16
+ * in its read set, keyed by user — so a query that asked whether Alice is online
17
+ * is recomputed when Alice comes or goes, and not when Bob does. Outside an
18
+ * execution (a script, a background job, a server component) it reads the
19
+ * database directly.
20
+ *
21
+ * What is read is `nowity.nowity_presence`, which only changes on transitions:
22
+ * a user opening a second tab, or reloading inside the grace period, produces no
23
+ * change here and therefore no recomputation anywhere.
24
+ *
25
+ * Works in a process without a socket of its own — the Next half — because it
26
+ * is only ever reading; the sync processes are what keep the table current.
27
+ */
28
+ const ironbean_1 = require("ironbean");
29
+ const execution_1 = require("./execution");
30
+ /** The table queries reading presence are invalidated by, as change events name it. */
31
+ exports.PRESENCE_TABLE = "nowity_presence";
32
+ /** Keyed by this column, so a change to one user wakes only that user's readers. */
33
+ const USER_COLUMN = "user_id";
34
+ let fallbackReader = null;
35
+ /** Where reads outside an execution go. Set by the runtime. */
36
+ function bindPresenceReader(reader) {
37
+ fallbackReader = reader;
38
+ }
39
+ let Presence = class Presence {
40
+ constructor() {
41
+ this.handlers = new Set();
42
+ }
43
+ /** Whether the user has a connection open (or had one within the grace period). */
44
+ async isOnline(userId) {
45
+ const rows = await this.read(`SELECT online FROM nowity.nowity_presence WHERE user_id = $1`, [userId], [userId]);
46
+ return rows[0]?.online === true;
47
+ }
48
+ /** Which of the given users are online. */
49
+ async online(userIds) {
50
+ const ids = unique(userIds);
51
+ if (ids.length === 0)
52
+ return new Set();
53
+ const rows = await this.read(`SELECT user_id FROM nowity.nowity_presence
54
+ WHERE online AND user_id IN (${placeholders(ids.length)})`, ids, ids);
55
+ return new Set(rows.map((row) => row.user_id));
56
+ }
57
+ /**
58
+ * Every online user. Watches the whole table, so a query built on it is
59
+ * recomputed on every transition of anyone — fine for an admin page, not
60
+ * for something every visitor has open.
61
+ */
62
+ async onlineAll() {
63
+ const rows = await this.read(`SELECT user_id FROM nowity.nowity_presence WHERE online ORDER BY user_id`, [], null);
64
+ return rows.map((row) => row.user_id);
65
+ }
66
+ /**
67
+ * What each of the given users' connections said they were looking at
68
+ * (`NowityClient.setContext`), deduplicated. A user who is offline, or set
69
+ * nothing, has an empty list.
70
+ */
71
+ async contexts(userIds) {
72
+ const ids = unique(userIds);
73
+ const out = new Map();
74
+ for (const id of ids)
75
+ out.set(id, []);
76
+ if (ids.length === 0)
77
+ return out;
78
+ const rows = await this.read(`SELECT user_id, contexts FROM nowity.nowity_presence
79
+ WHERE online AND user_id IN (${placeholders(ids.length)})`, ids, ids);
80
+ for (const row of rows) {
81
+ const contexts = typeof row.contexts === "string" ? JSON.parse(row.contexts) : row.contexts;
82
+ out.set(row.user_id, Array.isArray(contexts) ? contexts : []);
83
+ }
84
+ return out;
85
+ }
86
+ /**
87
+ * Who is online and since when, what they look at and what their newest
88
+ * connection stored as `meta` — for operator pages, which should not read
89
+ * Nowity's tables themselves. Longest online first. With `userIds` only
90
+ * those (and the read is keyed by them); without, everyone online — which
91
+ * watches the whole table like `onlineAll`, so cap it with `limit`.
92
+ *
93
+ * `meta` comes from `nowity_connection`, which does not reach the outbox: a
94
+ * query is recomputed on the user's transitions and context changes, not
95
+ * on a new connection with different meta.
96
+ */
97
+ async details(userIds, options = {}) {
98
+ const ids = userIds ? unique(userIds) : null;
99
+ if (ids && ids.length === 0)
100
+ return [];
101
+ const values = ids ? [...ids] : [];
102
+ const where = ids ? `AND p.user_id IN (${placeholders(ids.length)})` : "";
103
+ let limit = "";
104
+ if (options.limit !== undefined) {
105
+ values.push(Math.max(0, Math.floor(options.limit)));
106
+ limit = `LIMIT $${values.length}`;
107
+ }
108
+ const rows = await this.read(`SELECT p.user_id, COALESCE(p.online_since, p.updated_at) AS since, p.contexts, c.meta
109
+ FROM nowity.nowity_presence p
110
+ LEFT JOIN LATERAL (
111
+ SELECT meta FROM nowity.nowity_connection
112
+ WHERE user_id = p.user_id ORDER BY connected_at DESC LIMIT 1
113
+ ) c ON true
114
+ WHERE p.online ${where}
115
+ ORDER BY since ASC, p.user_id ASC
116
+ ${limit}`, values, ids);
117
+ return rows.map((row) => {
118
+ const contexts = parseJson(row.contexts);
119
+ const meta = parseJson(row.meta);
120
+ return {
121
+ userId: row.user_id,
122
+ since: row.since instanceof Date ? row.since : new Date(row.since),
123
+ contexts: Array.isArray(contexts) ? contexts : [],
124
+ meta: meta && typeof meta === "object" && !Array.isArray(meta) ? meta : {},
125
+ };
126
+ });
127
+ }
128
+ /**
129
+ * Be called after a user goes offline — at least once per transition, by
130
+ * whichever sync process leads. **The handler must be idempotent**; see
131
+ * `OfflineHandler`. Register it before the server starts, on every sync
132
+ * process. Returns the unsubscribe.
133
+ */
134
+ onOffline(handler) {
135
+ this.handlers.add(handler);
136
+ return () => {
137
+ this.handlers.delete(handler);
138
+ };
139
+ }
140
+ /** The registered handlers. For the presence tracker. */
141
+ offlineHandlers() {
142
+ return [...this.handlers];
143
+ }
144
+ /**
145
+ * Run one read, recording it when inside a query.
146
+ *
147
+ * `keys` are the user ids the read is confined to, or null for a read of the
148
+ * whole table.
149
+ */
150
+ async read(text, values, keys) {
151
+ const execution = (0, execution_1.peekExecution)();
152
+ if (execution) {
153
+ if (execution.kind === "query") {
154
+ execution.reads.add(exports.PRESENCE_TABLE);
155
+ execution.keys?.recordRows(exports.PRESENCE_TABLE, USER_COLUMN, keys);
156
+ }
157
+ const client = execution.prisma;
158
+ return (0, execution_1.runUntracked)(execution, async () => (await client.$queryRawUnsafe(text, ...values)));
159
+ }
160
+ if (!fallbackReader) {
161
+ throw new Error("Presence was read outside a @query or @mutation before any Nowity runtime " +
162
+ "was created, so there is no database to read it from.");
163
+ }
164
+ return (await fallbackReader.query(text, values)).rows;
165
+ }
166
+ };
167
+ exports.Presence = Presence;
168
+ exports.Presence = Presence = __decorate([
169
+ ironbean_1.component
170
+ ], Presence);
171
+ function unique(ids) {
172
+ return [...new Set(ids)];
173
+ }
174
+ function parseJson(value) {
175
+ return typeof value === "string" ? JSON.parse(value) : value;
176
+ }
177
+ function placeholders(count) {
178
+ // Explicit placeholders rather than `= ANY($1)`: array parameters are not
179
+ // portable across the adapters this runs on (pg vs Prisma raw).
180
+ return Array.from({ length: count }, (_, index) => `$${index + 1}`).join(", ");
181
+ }
@@ -86,6 +86,12 @@ export declare class KeyCollector {
86
86
  record(model: string | undefined, args: unknown): void;
87
87
  /** Everything read so far, collapsed to keys per table. */
88
88
  result(): ReadKeySet;
89
+ /**
90
+ * Record a read of a table that is not a Prisma model — one of Nowity's
91
+ * own — whose rows were selected by `column IN values`. `null` for values
92
+ * means the read was not narrowed at all.
93
+ */
94
+ recordRows(table: string, column: string, values: readonly KeyValue[] | null): void;
89
95
  /** Mark a model's table as read without knowing anything about which rows. */
90
96
  widen(model: string): void;
91
97
  private push;
@@ -1 +1 @@
1
- {"version":3,"file":"read-keys.d.ts","sourceRoot":"","sources":["../../../src/server/api/read-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,OAAO,EAAY,KAAK,QAAQ,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAY,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAEzD,mDAAmD;AACnD,eAAO,MAAM,GAAG,OAAW,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,GACb;IAAE,IAAI,EAAE,KAAK,CAAA;CAAE,GACf;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,EAAE,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAmDzC,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,cAAc,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAY;IACrB,yEAAyE;IACzE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0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AE,MAAM,GAAG,SAAS,CAmB3F;AAsFD,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAarE"}
@@ -138,6 +138,18 @@ class KeyCollector {
138
138
  }
139
139
  return out;
140
140
  }
141
+ /**
142
+ * Record a read of a table that is not a Prisma model — one of Nowity's
143
+ * own — whose rows were selected by `column IN values`. `null` for values
144
+ * means the read was not narrowed at all.
145
+ */
146
+ recordRows(table, column, values) {
147
+ if (values === null || values.length === 0 || values.length > MAX_IN) {
148
+ this.push(table, ANY_EXPR);
149
+ return;
150
+ }
151
+ this.push(table, some(values.map((value) => ({ kind: "eq", column, value }))));
152
+ }
141
153
  /** Mark a model's table as read without knowing anything about which rows. */
142
154
  widen(model) {
143
155
  this.push(model, ANY_EXPR);
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/server/api/runtime.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAe,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGzE,MAAM,WAAW,mBAAmB;IAChC,uCAAuC;IACvC,MAAM,EAAE,GAAG,CAAC;IACZ,gDAAgD;IAChD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;;;OAKG;IACH,EAAE,CAAC,EAAE,QAAQ,CAAC;IACd;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,oBAAoB,CAAC;IAChC,2EAA2E;IAC3E,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;CAC3B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAgC9E"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/server/api/runtime.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAkB,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,UAAU,CAAC;AAInD,OAAO,EAAE,cAAc,EAAe,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAGzE,MAAM,WAAW,mBAAmB;IAChC,uCAAuC;IACvC,MAAM,EAAE,GAAG,CAAC;IACZ,gDAAgD;IAChD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;;;OAKG;IACH,EAAE,CAAC,EAAE,QAAQ,CAAC;IACd;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,oBAAoB,CAAC;IAChC,2EAA2E;IAC3E,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;CAC3B;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CA0C9E"}
@@ -20,11 +20,23 @@ const auth_1 = require("./auth");
20
20
  const db_1 = require("../db");
21
21
  const bridge_1 = require("./bridge");
22
22
  const execution_1 = require("./execution");
23
+ const presence_1 = require("./presence");
24
+ const scheduler_1 = require("./scheduler");
23
25
  const read_set_1 = require("./read-set");
24
26
  const tracked_client_1 = require("./tracked-client");
25
27
  function createNowityRuntime(config) {
26
28
  const tracker = new read_set_1.ReadSetTracker(config.datamodel ?? (0, read_set_1.datamodelOf)(config.prisma));
27
29
  const prisma = (0, tracked_client_1.trackReads)(config.prisma, tracker);
30
+ // Outside an execution the tracking client passes straight through, so it
31
+ // is as good a reader as the raw one — and, for the scheduler, writer — and
32
+ // keeps a single client in play.
33
+ const direct = {
34
+ query: async (text, values) => ({
35
+ rows: (await prisma.$queryRawUnsafe(text, ...(values ?? []))),
36
+ }),
37
+ };
38
+ (0, presence_1.bindPresenceReader)(direct);
39
+ (0, scheduler_1.bindSchedulerExecutor)(direct);
28
40
  if (config.db)
29
41
  (0, ironbean_1.take)(config.db).setFactory(() => (0, execution_1.ambientPrisma)());
30
42
  (0, ironbean_1.take)(auth_1.Authenticator).bindTo((config.auth ?? auth_1.AnonymousAuthenticator));
@@ -0,0 +1,122 @@
1
+ import type { Queryable } from "../db";
2
+ import { type JobHandler, type JobHandlerOptions, type RegisteredJobHandler, type SchedulerStats, type SchedulerWorker } from "../scheduler";
3
+ /** Where a job is written: a Prisma client or transaction client, or a `pg` client or pool. */
4
+ export type SchedulerExecutor = Queryable | {
5
+ $queryRawUnsafe(query: string, ...values: unknown[]): Promise<unknown>;
6
+ };
7
+ export interface SchedulerWriteOptions {
8
+ /** Write inside this transaction rather than the ambient one, or on its own. */
9
+ tx?: SchedulerExecutor;
10
+ }
11
+ export interface ScheduleRequest<P = unknown> {
12
+ /**
13
+ * What the job is. Scheduling under a key that exists replaces that job —
14
+ * its time, handler and payload — and starts its attempts over.
15
+ */
16
+ key: string;
17
+ /** Name of the handler to run it, as registered with `handle` on the sync processes. */
18
+ handler: string;
19
+ /** When to run it, by the database clock. A time in the past means now. */
20
+ runAt: Date | number;
21
+ /** Stored as JSON. */
22
+ payload?: P;
23
+ /** Attempts before the job is `failed`; the handler's, or the scheduler's, unless set. */
24
+ maxAttempts?: number;
25
+ }
26
+ export type JobState = "pending" | "running" | "failed";
27
+ export interface JobInfo {
28
+ key: string;
29
+ handler: string;
30
+ payload: unknown;
31
+ state: JobState;
32
+ /** When it was due. */
33
+ runAt: Date;
34
+ /** When it may next be attempted — later than `runAt` after a failed attempt. */
35
+ nextAt: Date;
36
+ attempts: number;
37
+ maxAttempts: number | null;
38
+ /** Set for a job made with `every`. */
39
+ intervalMs: number | null;
40
+ /** Until when a running attempt holds it. */
41
+ lockedUntil: Date | null;
42
+ lastError: string | null;
43
+ createdAt: Date;
44
+ }
45
+ export interface JobFilter {
46
+ handler?: string;
47
+ state?: JobState | JobState[];
48
+ /** A hundred unless set. */
49
+ limit?: number;
50
+ }
51
+ export interface SchedulerMetrics {
52
+ /** What is in the table, across every process. */
53
+ jobs: {
54
+ pending: number;
55
+ /** Pending and due now: what the leader has yet to get to. */
56
+ due: number;
57
+ running: number;
58
+ failed: number;
59
+ /** How long the most overdue job has been waiting; 0 when none is. */
60
+ lagMs: number;
61
+ };
62
+ /** What this process ran, when it runs a scheduler. */
63
+ process: SchedulerStats | null;
64
+ }
65
+ /** Where writes outside a transaction go. Set by the runtime. */
66
+ export declare function bindSchedulerExecutor(executor: Queryable | null): void;
67
+ export declare class Scheduler {
68
+ private readonly handlers;
69
+ private readonly periodic;
70
+ private worker;
71
+ /**
72
+ * Register the handler jobs name. On every sync process that may lead —
73
+ * in practice, everywhere — before the server starts. **The handler must
74
+ * be idempotent**; see `JobHandler`. Returns the unregister.
75
+ *
76
+ * Jobs of a handler that is not registered are not claimed: they wait for
77
+ * a leader that knows it.
78
+ */
79
+ handle<P = unknown>(name: string, handler: JobHandler<P>, options?: JobHandlerOptions): () => void;
80
+ /**
81
+ * Run `handler` every `intervalMs`, on one process at a time, for as long
82
+ * as any process registers it.
83
+ *
84
+ * Stored like any job — under the key `every:<name>` — so it survives
85
+ * restarts and is not run again just because a process started. The first
86
+ * run is as soon as the leader sees it. A run that fails is retried like
87
+ * any job; once its attempts are used up the job waits for its next
88
+ * interval instead of becoming `failed`. Returns the unregister; the row
89
+ * stays until `cancel("every:<name>")`, and `schedule` refuses that key.
90
+ */
91
+ every(name: string, intervalMs: number, handler: JobHandler<null>, options?: JobHandlerOptions): () => void;
92
+ /**
93
+ * Schedule a job, or schedule it again: an upsert by key, one statement.
94
+ * Wakes the leader when the job is the earliest one pending.
95
+ */
96
+ schedule<P>(request: ScheduleRequest<P>, options?: SchedulerWriteOptions): Promise<void>;
97
+ /** Move a job to another time. A `failed` one is tried again. False when there is no such job. */
98
+ reschedule(key: string, runAt: Date | number, options?: SchedulerWriteOptions): Promise<boolean>;
99
+ /**
100
+ * Drop a job. False when there was none. An attempt already running is
101
+ * not stopped; its outcome is simply not recorded anywhere.
102
+ *
103
+ * A periodic job (`every:<name>`) still registered on this process is
104
+ * written again by its next round; on another process that registers it,
105
+ * once that process restarts. To be rid of one, stop registering it, then
106
+ * cancel it.
107
+ */
108
+ cancel(key: string, options?: SchedulerWriteOptions): Promise<boolean>;
109
+ /** Jobs, soonest first. Read directly, never as part of a live query. */
110
+ list(filter?: JobFilter): Promise<JobInfo[]>;
111
+ /** Counts across every process, and what this one ran. Scans the table; not for a hot path. */
112
+ metrics(): Promise<SchedulerMetrics>;
113
+ /** The registered handlers. For the scheduler worker. */
114
+ registeredHandlers(): ReadonlyMap<string, RegisteredJobHandler>;
115
+ /** The periodic jobs, handler name to interval. For the scheduler worker. */
116
+ periodicJobs(): ReadonlyMap<string, number>;
117
+ /** This process's scheduler, whose counters `metrics` reports. Set by the server. */
118
+ bindWorker(worker: SchedulerWorker | null): void;
119
+ private write;
120
+ private read;
121
+ }
122
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/server/api/scheduler.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAEH,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,e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BAA0B,GACpC,OAAO,CAAC,OAAO,CAAC;IASnB;;;;;;;;OAQG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,OAAO,CAAC;IAUhF,yEAAyE;IACnE,IAAI,CAAC,MAAM,GAAE,SAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IA4BtD,+FAA+F;IACzF,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAwB1C,yDAAyD;IACzD,kBAAkB,IAAI,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAI/D,6EAA6E;IAC7E,YAAY,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;IAI3C,qFAAqF;IACrF,UAAU,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI;YAIlC,KAAK;YAgBL,IAAI;CASrB"}
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Scheduler = void 0;
10
+ exports.bindSchedulerExecutor = bindSchedulerExecutor;
11
+ /**
12
+ * The scheduler, as application code uses it.
13
+ *
14
+ * Injectable like `Presence`, and usable from any process: scheduling is a
15
+ * write to `nowity.nowity_job`, which needs no socket and no worker. Only
16
+ * running jobs is the sync processes' — the ones started with `scheduler` in
17
+ * their config — and only the one that leads runs them.
18
+ *
19
+ * A write goes, in order of preference, through the transaction it is given
20
+ * (`{ tx }`: a Prisma interactive transaction client, or anything with a
21
+ * `pg`-style `query`), through the write transaction of the `@mutation` it is
22
+ * called from, or on its own. The first two make the job part of the change it
23
+ * belongs to: a turn deadline moved in the same transaction as the move.
24
+ */
25
+ const ironbean_1 = require("ironbean");
26
+ const scheduler_1 = require("../scheduler");
27
+ const execution_1 = require("./execution");
28
+ let fallbackExecutor = null;
29
+ /** Where writes outside a transaction go. Set by the runtime. */
30
+ function bindSchedulerExecutor(executor) {
31
+ fallbackExecutor = executor;
32
+ }
33
+ let Scheduler = class Scheduler {
34
+ constructor() {
35
+ this.handlers = new Map();
36
+ this.periodic = new Map();
37
+ this.worker = null;
38
+ }
39
+ /**
40
+ * Register the handler jobs name. On every sync process that may lead —
41
+ * in practice, everywhere — before the server starts. **The handler must
42
+ * be idempotent**; see `JobHandler`. Returns the unregister.
43
+ *
44
+ * Jobs of a handler that is not registered are not claimed: they wait for
45
+ * a leader that knows it.
46
+ */
47
+ handle(name, handler, options = {}) {
48
+ if (!name)
49
+ throw new Error("A job handler needs a name");
50
+ if (this.handlers.has(name))
51
+ throw new Error(`Job handler "${name}" is already registered`);
52
+ const registered = { ...options, run: handler };
53
+ this.handlers.set(name, registered);
54
+ return () => {
55
+ if (this.handlers.get(name) === registered)
56
+ this.handlers.delete(name);
57
+ };
58
+ }
59
+ /**
60
+ * Run `handler` every `intervalMs`, on one process at a time, for as long
61
+ * as any process registers it.
62
+ *
63
+ * Stored like any job — under the key `every:<name>` — so it survives
64
+ * restarts and is not run again just because a process started. The first
65
+ * run is as soon as the leader sees it. A run that fails is retried like
66
+ * any job; once its attempts are used up the job waits for its next
67
+ * interval instead of becoming `failed`. Returns the unregister; the row
68
+ * stays until `cancel("every:<name>")`, and `schedule` refuses that key.
69
+ */
70
+ every(name, intervalMs, handler, options = {}) {
71
+ if (!(intervalMs > 0))
72
+ throw new Error(`The interval of "${name}" has to be positive`);
73
+ const unregister = this.handle(name, handler, options);
74
+ this.periodic.set(name, Math.round(intervalMs));
75
+ return () => {
76
+ unregister();
77
+ this.periodic.delete(name);
78
+ };
79
+ }
80
+ /**
81
+ * Schedule a job, or schedule it again: an upsert by key, one statement.
82
+ * Wakes the leader when the job is the earliest one pending.
83
+ */
84
+ async schedule(request, options = {}) {
85
+ if (!request.key)
86
+ throw new Error("A job needs a key");
87
+ if (!request.handler)
88
+ throw new Error(`Job "${request.key}" needs a handler`);
89
+ if (request.key.startsWith(scheduler_1.PERIODIC_KEY_PREFIX)) {
90
+ throw new Error(`"${request.key}": keys starting with "${scheduler_1.PERIODIC_KEY_PREFIX}" belong to periodic jobs; use every()`);
91
+ }
92
+ await this.write(`SELECT nowity.nowity_job_schedule($1, $2, $3::jsonb, $4::timestamptz, $5::int) AS notified`, [
93
+ request.key,
94
+ request.handler,
95
+ request.payload === undefined ? null : JSON.stringify(request.payload),
96
+ timestamp(request.runAt, request.key),
97
+ request.maxAttempts ?? null,
98
+ ], options);
99
+ }
100
+ /** Move a job to another time. A `failed` one is tried again. False when there is no such job. */
101
+ async reschedule(key, runAt, options = {}) {
102
+ const rows = await this.write(`SELECT nowity.nowity_job_reschedule($1, $2::timestamptz) AS found`, [key, timestamp(runAt, key)], options);
103
+ return rows[0]?.found === true;
104
+ }
105
+ /**
106
+ * Drop a job. False when there was none. An attempt already running is
107
+ * not stopped; its outcome is simply not recorded anywhere.
108
+ *
109
+ * A periodic job (`every:<name>`) still registered on this process is
110
+ * written again by its next round; on another process that registers it,
111
+ * once that process restarts. To be rid of one, stop registering it, then
112
+ * cancel it.
113
+ */
114
+ async cancel(key, options = {}) {
115
+ const rows = await this.write(`DELETE FROM nowity.nowity_job WHERE key = $1 RETURNING key`, [key], options);
116
+ this.worker?.forgetPeriodic(key);
117
+ return rows.length > 0;
118
+ }
119
+ /** Jobs, soonest first. Read directly, never as part of a live query. */
120
+ async list(filter = {}) {
121
+ const states = filter.state === undefined ? null : [filter.state].flat();
122
+ const rows = await this.read(`SELECT key, handler, payload, state, run_at, next_at, attempts, max_attempts,
123
+ interval_ms::float8 AS interval_ms, locked_until, last_error, created_at
124
+ FROM nowity.nowity_job
125
+ WHERE ($1::text IS NULL OR handler = $1)
126
+ AND ($2::jsonb IS NULL OR state IN (SELECT jsonb_array_elements_text($2::jsonb)))
127
+ ORDER BY next_at, key
128
+ LIMIT $3::int`, [filter.handler ?? null, states && JSON.stringify(states), filter.limit ?? 100]);
129
+ return rows.map((row) => ({
130
+ key: row.key,
131
+ handler: row.handler,
132
+ payload: row.payload ?? null,
133
+ state: row.state,
134
+ runAt: new Date(row.run_at),
135
+ nextAt: new Date(row.next_at),
136
+ attempts: Number(row.attempts),
137
+ maxAttempts: row.max_attempts ?? null,
138
+ intervalMs: row.interval_ms ?? null,
139
+ lockedUntil: row.locked_until ? new Date(row.locked_until) : null,
140
+ lastError: row.last_error ?? null,
141
+ createdAt: new Date(row.created_at),
142
+ }));
143
+ }
144
+ /** Counts across every process, and what this one ran. Scans the table; not for a hot path. */
145
+ async metrics() {
146
+ const rows = await this.read(`SELECT count(*) FILTER (WHERE state = 'pending')::int AS pending,
147
+ count(*) FILTER (WHERE state = 'pending' AND next_at <= now())::int AS due,
148
+ count(*) FILTER (WHERE state = 'running')::int AS running,
149
+ count(*) FILTER (WHERE state = 'failed')::int AS failed,
150
+ COALESCE(EXTRACT(EPOCH FROM now() - min(next_at)
151
+ FILTER (WHERE state = 'pending' AND next_at <= now())) * 1000, 0)::float8 AS lag_ms
152
+ FROM nowity.nowity_job`, []);
153
+ const row = rows[0];
154
+ return {
155
+ jobs: {
156
+ pending: row.pending,
157
+ due: row.due,
158
+ running: row.running,
159
+ failed: row.failed,
160
+ lagMs: row.lag_ms,
161
+ },
162
+ process: this.worker && { ...this.worker.stats },
163
+ };
164
+ }
165
+ /** The registered handlers. For the scheduler worker. */
166
+ registeredHandlers() {
167
+ return this.handlers;
168
+ }
169
+ /** The periodic jobs, handler name to interval. For the scheduler worker. */
170
+ periodicJobs() {
171
+ return this.periodic;
172
+ }
173
+ /** This process's scheduler, whose counters `metrics` reports. Set by the server. */
174
+ bindWorker(worker) {
175
+ this.worker = worker;
176
+ }
177
+ async write(text, values, options) {
178
+ if (options.tx)
179
+ return run(options.tx, text, values);
180
+ const execution = (0, execution_1.peekExecution)();
181
+ if (execution) {
182
+ if (execution.kind === "query") {
183
+ throw new Error("A @query cannot schedule: it is re-run whenever what it read changes. " +
184
+ "Schedule from a @mutation, or pass { tx }.");
185
+ }
186
+ const client = execution.prisma;
187
+ return (0, execution_1.runUntracked)(execution, () => run(client, text, values));
188
+ }
189
+ return this.read(text, values);
190
+ }
191
+ async read(text, values) {
192
+ if (!fallbackExecutor) {
193
+ throw new Error("The scheduler was used outside a @mutation, and without { tx }, before any " +
194
+ "Nowity runtime was created, so there is no database to write to.");
195
+ }
196
+ return run(fallbackExecutor, text, values);
197
+ }
198
+ };
199
+ exports.Scheduler = Scheduler;
200
+ exports.Scheduler = Scheduler = __decorate([
201
+ ironbean_1.component
202
+ ], Scheduler);
203
+ async function run(executor, text, values) {
204
+ if ("$queryRawUnsafe" in executor)
205
+ return (await executor.$queryRawUnsafe(text, ...values));
206
+ return (await executor.query(text, values)).rows;
207
+ }
208
+ /**
209
+ * As text, so it reaches the database the same way through every adapter, and
210
+ * keeps its milliseconds.
211
+ */
212
+ function timestamp(value, key) {
213
+ const date = typeof value === "number" ? new Date(value) : value;
214
+ if (Number.isNaN(date.getTime()))
215
+ throw new Error(`Job "${key}" has no valid runAt`);
216
+ return date.toISOString();
217
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"wal-change-source.d.ts","sourceRoot":"","sources":["../../../src/server/change-source/wal-change-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAI/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,WAAW,sBAAsB;IACnC,0DAA0D;IAC1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;;OAQG;IACG,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAU3D;;;;;;;OAOG;YACW,qBAAqB;YAUrB,UAAU;IAQlB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCzD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,OAAO;IAoCf,OAAO,CAAC,IAAI;CAUf"}
@@ -3,7 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WalChangeSource = void 0;
4
4
  const pg_logical_replication_1 = require("pg-logical-replication");
5
5
  const normalize_1 = require("../../core/normalize");
6
- const ALWAYS_EXCLUDED = ["nowity_outbox", "nowity_scope_epoch", "nowity_consumer", "nowity_client"];
6
+ const ALWAYS_EXCLUDED = [
7
+ "nowity_outbox",
8
+ "nowity_scope_epoch",
9
+ "nowity_consumer",
10
+ "nowity_client",
11
+ // Presence bookkeeping. `nowity_presence` itself is streamed: it is what
12
+ // queries reading presence are invalidated by.
13
+ "nowity_connection",
14
+ "nowity_node",
15
+ ];
7
16
  /**
8
17
  * Change source built on PostgreSQL logical replication + wal2json.
9
18
  *