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.
- package/README.md +316 -3
- package/dist/client/connection.d.ts +2 -0
- package/dist/client/connection.d.ts.map +1 -1
- package/dist/client/connection.js +13 -0
- package/dist/client/nowity-client.d.ts +23 -0
- package/dist/client/nowity-client.d.ts.map +1 -1
- package/dist/client/nowity-client.js +29 -1
- package/dist/client/overlay.d.ts +52 -2
- package/dist/client/overlay.d.ts.map +1 -1
- package/dist/client/overlay.js +43 -0
- package/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/core/protocol.d.ts +20 -1
- package/dist/core/protocol.d.ts.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/server/api/collector.d.ts.map +1 -1
- package/dist/server/api/collector.js +4 -1
- package/dist/server/api/configure.d.ts +24 -0
- package/dist/server/api/configure.d.ts.map +1 -1
- package/dist/server/api/configure.js +51 -1
- package/dist/server/api/execution.d.ts +9 -0
- package/dist/server/api/execution.d.ts.map +1 -1
- package/dist/server/api/execution.js +19 -0
- package/dist/server/api/presence.d.ts +66 -0
- package/dist/server/api/presence.d.ts.map +1 -0
- package/dist/server/api/presence.js +181 -0
- package/dist/server/api/read-keys.d.ts +6 -0
- package/dist/server/api/read-keys.d.ts.map +1 -1
- package/dist/server/api/read-keys.js +12 -0
- package/dist/server/api/runtime.d.ts.map +1 -1
- package/dist/server/api/runtime.js +12 -0
- package/dist/server/api/scheduler.d.ts +122 -0
- package/dist/server/api/scheduler.d.ts.map +1 -0
- package/dist/server/api/scheduler.js +217 -0
- package/dist/server/change-source/wal-change-source.d.ts.map +1 -1
- package/dist/server/change-source/wal-change-source.js +10 -1
- package/dist/server/leader.d.ts +138 -0
- package/dist/server/leader.d.ts.map +1 -0
- package/dist/server/leader.js +342 -0
- package/dist/server/presence.d.ts +217 -0
- package/dist/server/presence.d.ts.map +1 -0
- package/dist/server/presence.js +428 -0
- package/dist/server/scheduler.d.ts +195 -0
- package/dist/server/scheduler.d.ts.map +1 -0
- package/dist/server/scheduler.js +432 -0
- package/dist/server/setup-sql.d.ts +1 -1
- package/dist/server/setup-sql.d.ts.map +1 -1
- package/dist/server/setup-sql.js +547 -0
- package/dist/server/sync-engine.d.ts +22 -1
- package/dist/server/sync-engine.d.ts.map +1 -1
- package/dist/server/sync-engine.js +30 -1
- package/dist/server/ws-server.d.ts +22 -0
- package/dist/server/ws-server.d.ts.map +1 -1
- package/dist/server/ws-server.js +81 -1
- package/package.json +1 -1
package/dist/client/overlay.js
CHANGED
|
@@ -18,6 +18,7 @@ class Overlay {
|
|
|
18
18
|
}
|
|
19
19
|
tx() {
|
|
20
20
|
return {
|
|
21
|
+
of: ((entity) => this.entityTx(entity)),
|
|
21
22
|
get: (entity, id) => this.get(entity, id),
|
|
22
23
|
all: (entity) => [...this.merged(entity).values()],
|
|
23
24
|
update: (entity, id, fields) => {
|
|
@@ -33,6 +34,48 @@ class Overlay {
|
|
|
33
34
|
remove: (entity, id) => this.stage(entity, id, null),
|
|
34
35
|
};
|
|
35
36
|
}
|
|
37
|
+
entityTx(entity) {
|
|
38
|
+
return {
|
|
39
|
+
get: (id) => (this.get(entity, id) ? this.draft(entity, id) : undefined),
|
|
40
|
+
all: () => [...this.merged(entity).keys()].map((id) => this.draft(entity, id)),
|
|
41
|
+
create: (row) => this.stage(entity, String(row[this.idFieldOf(entity)]), { ...row }),
|
|
42
|
+
remove: (id) => this.stage(entity, id, null),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A view of one row that reads through to the overlay on every access, so
|
|
47
|
+
* it stays right as later writes land and a row removed meanwhile reads as
|
|
48
|
+
* empty. Writes to a row that is gone are dropped, like `update` on one that
|
|
49
|
+
* is not loaded.
|
|
50
|
+
*/
|
|
51
|
+
draft(entity, id) {
|
|
52
|
+
const current = () => this.get(entity, id);
|
|
53
|
+
return new Proxy({}, {
|
|
54
|
+
get: (_, key) => (typeof key === "string" ? current()?.[key] : undefined),
|
|
55
|
+
has: (_, key) => typeof key === "string" && current() !== undefined && key in current(),
|
|
56
|
+
set: (_, key, value) => {
|
|
57
|
+
const row = current();
|
|
58
|
+
if (row && typeof key === "string")
|
|
59
|
+
this.stage(entity, id, { ...row, [key]: value });
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
deleteProperty: (_, key) => {
|
|
63
|
+
const row = current();
|
|
64
|
+
if (row && typeof key === "string") {
|
|
65
|
+
const { [key]: _removed, ...rest } = row;
|
|
66
|
+
this.stage(entity, id, rest);
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
ownKeys: () => Object.keys(current() ?? {}),
|
|
71
|
+
getOwnPropertyDescriptor: (_, key) => {
|
|
72
|
+
const row = current();
|
|
73
|
+
if (!row || typeof key !== "string" || !(key in row))
|
|
74
|
+
return undefined;
|
|
75
|
+
return { value: row[key], writable: true, enumerable: true, configurable: true };
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
36
79
|
get(entity, id) {
|
|
37
80
|
const staged = this.changes.get(entity);
|
|
38
81
|
if (staged?.has(id))
|
package/dist/client.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export type { QueryEntry, QueryError, QuerySource } from "./client/query-source"
|
|
|
38
38
|
* has answered states its effect here.
|
|
39
39
|
*/
|
|
40
40
|
export type { ClientMutatorDef } from "./client/nowity-client";
|
|
41
|
-
export type { LocalTx } from "./client/overlay";
|
|
41
|
+
export type { Draft, EntityTx, LocalEntities, LocalTx } from "./client/overlay";
|
|
42
42
|
export { WebSocketTransport, type WebSocketTransportOptions } from "./client/ws-transport";
|
|
43
43
|
export { configureNowityClient, type NowityClientContainerConfig } from "./ironbean/client";
|
|
44
44
|
export { NowityClientToken } from "./ironbean/tokens";
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EACH,GAAG,EACH,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,SAAS,EACT,UAAU,EACV,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,YAAY,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAQ5E,OAAO,EACH,QAAQ,EACR,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,cAAc;AACd;;;;;GAKG;AACH,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,mBAAmB,GAC3B,MAAM,eAAe,CAAC;AAGvB,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,uBAAuB,GAC/B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACjF;;;;;GAKG;AACH,YAAY,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,YAAY,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","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,MAAM,uBAAuB,CAAC;AAC3F,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGtD,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/core/protocol.d.ts
CHANGED
|
@@ -14,6 +14,13 @@ export interface ClientHello {
|
|
|
14
14
|
t: "hello";
|
|
15
15
|
v: number;
|
|
16
16
|
clientId: string;
|
|
17
|
+
/**
|
|
18
|
+
* The connection's context ({@link ClientContext}), when it has one. Sent
|
|
19
|
+
* with the hello rather than after it so that a reconnect restores it in
|
|
20
|
+
* the same write that records the connection — a reload is then no change
|
|
21
|
+
* at all for anyone reading presence.
|
|
22
|
+
*/
|
|
23
|
+
context?: Record<string, unknown> | null;
|
|
17
24
|
}
|
|
18
25
|
export interface ClientSubscribe {
|
|
19
26
|
t: "subscribe";
|
|
@@ -31,7 +38,19 @@ export interface ClientMutate {
|
|
|
31
38
|
name: string;
|
|
32
39
|
args: unknown;
|
|
33
40
|
}
|
|
34
|
-
|
|
41
|
+
/**
|
|
42
|
+
* What this connection is looking at — a path, a game — for presence readers.
|
|
43
|
+
*
|
|
44
|
+
* Not a mutation: it has no sequence number and no answer, and after a
|
|
45
|
+
* reconnect it travels in the hello instead, because it describes the socket
|
|
46
|
+
* rather than the data. `null` clears it. A server without presence ignores it,
|
|
47
|
+
* and so does a server older than it.
|
|
48
|
+
*/
|
|
49
|
+
export interface ClientContext {
|
|
50
|
+
t: "context";
|
|
51
|
+
context: Record<string, unknown> | null;
|
|
52
|
+
}
|
|
53
|
+
export type ClientMessage = ClientHello | ClientSubscribe | ClientUnsubscribe | ClientMutate | ClientContext;
|
|
35
54
|
/**
|
|
36
55
|
* A query result rendered on the server for the first paint.
|
|
37
56
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/core/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;GASG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAIlC,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/core/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;GASG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAIlC,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,MAAM,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,eAAe;IAC5B,CAAC,EAAE,WAAW,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAC9B,CAAC,EAAE,aAAa,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IACzB,CAAC,EAAE,QAAQ,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC1B,CAAC,EAA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CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IACxB,CAAC,EAAE,OAAO,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,aAAa,GACnB,aAAa,GACb,cAAc,GACd,QAAQ,GACR,oBAAoB,GACpB,WAAW,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ export { Forbidden, Rejected, isForbidden, isRejected } from "./api/errors";
|
|
|
24
24
|
export { createNowityServer, type NowityServer, type NowityServerConfig, type DefaultOutboxOptions, DEFAULT_PRUNE_INTERVAL_MS, } from "./server/api/configure";
|
|
25
25
|
export { createNowityRuntime, type NowityRuntime, type NowityRuntimeConfig, } from "./server/api/runtime";
|
|
26
26
|
export { Session } from "./server/api/execution";
|
|
27
|
+
export { Presence, type PresenceDetail } from "./server/api/presence";
|
|
28
|
+
export { PresenceTracker, type OfflineEvent, type OfflineHandler, type PresenceContext, type PresenceOptions, } from "./server/presence";
|
|
29
|
+
export { Scheduler, type JobFilter, type JobInfo, type JobState, type ScheduleRequest, type SchedulerExecutor, type SchedulerMetrics, type SchedulerWriteOptions, } from "./server/api/scheduler";
|
|
30
|
+
export { SchedulerWorker, type JobHandler, type JobHandlerOptions, type RetryOptions, type ScheduledJob, type SchedulerOptions, type SchedulerStats, } from "./server/scheduler";
|
|
31
|
+
export { LeaderElection, PeriodicTask, type LeaderElectionOptions, type PeriodicTaskOptions, } from "./server/leader";
|
|
27
32
|
export { Authenticator, AnonymousAuthenticator } from "./server/api/auth";
|
|
28
33
|
export type { AuthRequest, AuthResult } from "./server/ws-server";
|
|
29
34
|
export type { SessionInfo } from "./server/query";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src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
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.WebSocketTransport = exports.currentConnection = exports.activeConnection = exports.NowityConnection = exports.configureNowityServer = exports.withNowity = exports.serveNext = exports.Live = exports.currentNextNowity = exports.createNextNowity = exports.NOWITY_SETUP_SQL = exports.setReplicaIdentityFull = exports.untrackTable = exports.trackTable = exports.setupNowity = exports.WalChangeSource = exports.OutboxChangeSource = exports.prerender = exports.AnonymousAuthenticator = exports.Authenticator = exports.Session = exports.createNowityRuntime = exports.DEFAULT_PRUNE_INTERVAL_MS = exports.createNowityServer = exports.isRejected = exports.isForbidden = exports.Rejected = exports.Forbidden = exports.countQuery = exports.pageQuery = exports.endpointName = exports.contractOf = exports.mutation = exports.list = exports.query = exports.contract = exports.api = void 0;
|
|
38
|
+
exports.WebSocketTransport = exports.currentConnection = exports.activeConnection = exports.NowityConnection = exports.configureNowityServer = exports.withNowity = exports.serveNext = exports.Live = exports.currentNextNowity = exports.createNextNowity = exports.NOWITY_SETUP_SQL = exports.setReplicaIdentityFull = exports.untrackTable = exports.trackTable = exports.setupNowity = exports.WalChangeSource = exports.OutboxChangeSource = exports.prerender = exports.AnonymousAuthenticator = exports.Authenticator = exports.PeriodicTask = exports.LeaderElection = exports.SchedulerWorker = exports.Scheduler = exports.PresenceTracker = exports.Presence = exports.Session = exports.createNowityRuntime = exports.DEFAULT_PRUNE_INTERVAL_MS = exports.createNowityServer = exports.isRejected = exports.isForbidden = exports.Rejected = exports.Forbidden = exports.countQuery = exports.pageQuery = exports.endpointName = exports.contractOf = exports.mutation = exports.list = exports.query = exports.contract = exports.api = void 0;
|
|
39
39
|
// ------------------------------------------------------------------- contracts
|
|
40
40
|
var contract_1 = require("./api/contract");
|
|
41
41
|
Object.defineProperty(exports, "api", { enumerable: true, get: function () { return contract_1.api; } });
|
|
@@ -60,6 +60,17 @@ var runtime_1 = require("./server/api/runtime");
|
|
|
60
60
|
Object.defineProperty(exports, "createNowityRuntime", { enumerable: true, get: function () { return runtime_1.createNowityRuntime; } });
|
|
61
61
|
var execution_1 = require("./server/api/execution");
|
|
62
62
|
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return execution_1.Session; } });
|
|
63
|
+
var presence_1 = require("./server/api/presence");
|
|
64
|
+
Object.defineProperty(exports, "Presence", { enumerable: true, get: function () { return presence_1.Presence; } });
|
|
65
|
+
var presence_2 = require("./server/presence");
|
|
66
|
+
Object.defineProperty(exports, "PresenceTracker", { enumerable: true, get: function () { return presence_2.PresenceTracker; } });
|
|
67
|
+
var scheduler_1 = require("./server/api/scheduler");
|
|
68
|
+
Object.defineProperty(exports, "Scheduler", { enumerable: true, get: function () { return scheduler_1.Scheduler; } });
|
|
69
|
+
var scheduler_2 = require("./server/scheduler");
|
|
70
|
+
Object.defineProperty(exports, "SchedulerWorker", { enumerable: true, get: function () { return scheduler_2.SchedulerWorker; } });
|
|
71
|
+
var leader_1 = require("./server/leader");
|
|
72
|
+
Object.defineProperty(exports, "LeaderElection", { enumerable: true, get: function () { return leader_1.LeaderElection; } });
|
|
73
|
+
Object.defineProperty(exports, "PeriodicTask", { enumerable: true, get: function () { return leader_1.PeriodicTask; } });
|
|
63
74
|
var auth_1 = require("./server/api/auth");
|
|
64
75
|
Object.defineProperty(exports, "Authenticator", { enumerable: true, get: function () { return auth_1.Authenticator; } });
|
|
65
76
|
Object.defineProperty(exports, "AnonymousAuthenticator", { enumerable: true, get: function () { return auth_1.AnonymousAuthenticator; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../../../src/server/api/collector.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EAAkD,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvG,OAAO,KA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IAAI,CAAC,CAAC;CAC1B;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,WAAW,GAAG,YAAY,CAyH3F"}
|
|
@@ -115,7 +115,10 @@ function openSsrCollector(deps, session) {
|
|
|
115
115
|
async function collected() {
|
|
116
116
|
for (let settled = 0; settled < 20 && !closed;) {
|
|
117
117
|
const before = payloads.length;
|
|
118
|
-
|
|
118
|
+
// A timer, not an immediate: Next 16.4 Cache Components (dev staged render) runs immediates
|
|
119
|
+
// queued during a render stage as "fast immediates" ahead of I/O, so an immediate-polling
|
|
120
|
+
// loop waiting for a database read starves the very I/O it waits for and spins forever.
|
|
121
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
119
122
|
settled = pending === 0 && payloads.length === before ? settled + 1 : 0;
|
|
120
123
|
if (settled >= 2)
|
|
121
124
|
break;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ChangeSource } from "../change-source/change-source";
|
|
2
2
|
import { SyncEngine } from "../sync-engine";
|
|
3
3
|
import { NowitySyncServer, type NowitySyncServerOptions } from "../ws-server";
|
|
4
|
+
import { PresenceTracker, type PresenceOptions } from "../presence";
|
|
5
|
+
import { SchedulerWorker, type SchedulerOptions } from "../scheduler";
|
|
4
6
|
import { type NowityRuntime, type NowityRuntimeConfig } from "./runtime";
|
|
5
7
|
export interface NowityServerConfig extends NowityRuntimeConfig {
|
|
6
8
|
/**
|
|
@@ -20,6 +22,24 @@ export interface NowityServerConfig extends NowityRuntimeConfig {
|
|
|
20
22
|
syncServer?: Omit<NowitySyncServerOptions, "engine">;
|
|
21
23
|
/** See {@link SyncEngineOptions.narrowInvalidation}. On unless set. */
|
|
22
24
|
narrowInvalidation?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Record who is connected, so endpoints can read it through the injectable
|
|
27
|
+
* {@link Presence} and react to users going offline (`Presence.onOffline`).
|
|
28
|
+
*
|
|
29
|
+
* Off unless set — `presence: {}` turns it on with the defaults. Off, the
|
|
30
|
+
* server writes nothing about connections; `Presence` still reads, and
|
|
31
|
+
* finds nobody online.
|
|
32
|
+
*/
|
|
33
|
+
presence?: PresenceOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Run the jobs scheduled through the injectable {@link Scheduler}, on
|
|
36
|
+
* whichever sync process leads.
|
|
37
|
+
*
|
|
38
|
+
* Off unless set — `scheduler: {}` turns it on with the defaults. Off,
|
|
39
|
+
* nothing here runs jobs; `Scheduler` still schedules them, for a process
|
|
40
|
+
* that has it on.
|
|
41
|
+
*/
|
|
42
|
+
scheduler?: SchedulerOptions;
|
|
23
43
|
onError?: (err: Error) => void;
|
|
24
44
|
}
|
|
25
45
|
export interface DefaultOutboxOptions {
|
|
@@ -39,6 +59,10 @@ export declare const DEFAULT_PRUNE_INTERVAL_MS = 60000;
|
|
|
39
59
|
export interface NowityServer extends NowityRuntime {
|
|
40
60
|
engine: SyncEngine;
|
|
41
61
|
server: NowitySyncServer;
|
|
62
|
+
/** This process's half of presence, when it is on. */
|
|
63
|
+
presence: PresenceTracker | null;
|
|
64
|
+
/** This process's half of the scheduler, when it is on. */
|
|
65
|
+
scheduler: SchedulerWorker | null;
|
|
42
66
|
/** Start the change stream and the socket; resolves with the port. */
|
|
43
67
|
start(): Promise<number>;
|
|
44
68
|
stop(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../../src/server/api/configure.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,UAAU,EAA0B,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,KAAK,uBAAuB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../../src/server/api/configure.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAA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;IACzB,sDAAsD;IACtD,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,2DAA2D;IAC3D,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,sEAAsE;IACtE,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAoBD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CA4D3E"}
|
|
@@ -16,7 +16,11 @@ const outbox_change_source_1 = require("../change-source/outbox-change-source");
|
|
|
16
16
|
const mutator_1 = require("../mutator");
|
|
17
17
|
const sync_engine_1 = require("../sync-engine");
|
|
18
18
|
const ws_server_1 = require("../ws-server");
|
|
19
|
+
const presence_1 = require("../presence");
|
|
20
|
+
const scheduler_1 = require("../scheduler");
|
|
19
21
|
const auth_1 = require("./auth");
|
|
22
|
+
const presence_2 = require("./presence");
|
|
23
|
+
const scheduler_2 = require("./scheduler");
|
|
20
24
|
const runtime_1 = require("./runtime");
|
|
21
25
|
/** How often the default outbox prunes. */
|
|
22
26
|
exports.DEFAULT_PRUNE_INTERVAL_MS = 60000;
|
|
@@ -40,7 +44,10 @@ function resolveChangeSource(config) {
|
|
|
40
44
|
}
|
|
41
45
|
function createNowityServer(config) {
|
|
42
46
|
const runtime = (0, runtime_1.createNowityRuntime)(config);
|
|
43
|
-
const
|
|
47
|
+
const context = (0, ironbean_1.getBaseApplicationContext)();
|
|
48
|
+
const authenticator = context.getBean(auth_1.Authenticator);
|
|
49
|
+
const presence = config.presence ? createPresence(config, runtime, context.getBean(presence_2.Presence)) : null;
|
|
50
|
+
const scheduler = config.scheduler ? createScheduler(config, runtime, context.getBean(scheduler_2.Scheduler)) : null;
|
|
44
51
|
const engine = new sync_engine_1.SyncEngine({
|
|
45
52
|
snapshots: runtime.snapshots,
|
|
46
53
|
writes: new mutator_1.PrismaWriteRunner(runtime.prisma),
|
|
@@ -49,10 +56,14 @@ function createNowityServer(config) {
|
|
|
49
56
|
mutators: runtime.api.mutators,
|
|
50
57
|
api: { contracts: runtime.api.manifest.contracts, entities: runtime.api.entities },
|
|
51
58
|
narrowInvalidation: config.narrowInvalidation,
|
|
59
|
+
...(presence ? { presence } : {}),
|
|
52
60
|
onError: config.onError,
|
|
53
61
|
});
|
|
54
62
|
const server = new ws_server_1.NowitySyncServer({
|
|
55
63
|
...config.syncServer,
|
|
64
|
+
// A connection whose peer vanished is someone shown online, so with
|
|
65
|
+
// presence on, the heartbeat is too. Without it nothing changes.
|
|
66
|
+
heartbeat: config.syncServer?.heartbeat ?? (presence ? {} : false),
|
|
56
67
|
engine,
|
|
57
68
|
authenticate: (request) => authenticator.authenticate(request),
|
|
58
69
|
onError: config.onError,
|
|
@@ -61,13 +72,52 @@ function createNowityServer(config) {
|
|
|
61
72
|
...runtime,
|
|
62
73
|
engine,
|
|
63
74
|
server,
|
|
75
|
+
presence,
|
|
76
|
+
scheduler,
|
|
64
77
|
async start() {
|
|
65
78
|
await engine.start();
|
|
79
|
+
// Before the socket: the node's lease has to exist before the first
|
|
80
|
+
// connection names it.
|
|
81
|
+
await presence?.start();
|
|
82
|
+
scheduler?.start();
|
|
66
83
|
return server.listen();
|
|
67
84
|
},
|
|
68
85
|
async stop() {
|
|
86
|
+
// Before any of the below: the scheduler needs nothing from the
|
|
87
|
+
// sockets, and stopping it first hands its lead on while they drain.
|
|
88
|
+
await scheduler?.stop();
|
|
89
|
+
// Presence stops writing first, then the socket stops accepting and
|
|
90
|
+
// closes everything it has, and only then is this node's departure
|
|
91
|
+
// recorded — in one statement rather than a disconnect per socket,
|
|
92
|
+
// and after the last socket, so nothing it accepted is left out.
|
|
93
|
+
// The users get the grace period to land on another node.
|
|
94
|
+
presence?.drain();
|
|
69
95
|
await server.close();
|
|
96
|
+
await presence?.stop();
|
|
70
97
|
await engine.stop();
|
|
71
98
|
},
|
|
72
99
|
};
|
|
73
100
|
}
|
|
101
|
+
function createPresence(config, runtime, service) {
|
|
102
|
+
const options = config.presence;
|
|
103
|
+
return new presence_1.PresenceTracker({
|
|
104
|
+
...options,
|
|
105
|
+
databaseUrl: options.databaseUrl ?? config.databaseUrl ?? process.env.DATABASE_URL,
|
|
106
|
+
writes: new mutator_1.PrismaWriteRunner(runtime.prisma),
|
|
107
|
+
handlers: () => service.offlineHandlers(),
|
|
108
|
+
onError: config.onError,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function createScheduler(config, runtime, service) {
|
|
112
|
+
const options = config.scheduler;
|
|
113
|
+
const worker = new scheduler_1.SchedulerWorker({
|
|
114
|
+
...options,
|
|
115
|
+
databaseUrl: options.databaseUrl ?? config.databaseUrl ?? process.env.DATABASE_URL,
|
|
116
|
+
writes: new mutator_1.PrismaWriteRunner(runtime.prisma),
|
|
117
|
+
handlers: () => service.registeredHandlers(),
|
|
118
|
+
periodic: () => service.periodicJobs(),
|
|
119
|
+
onError: config.onError,
|
|
120
|
+
});
|
|
121
|
+
service.bindWorker(worker);
|
|
122
|
+
return worker;
|
|
123
|
+
}
|
|
@@ -51,6 +51,15 @@ export interface Execution {
|
|
|
51
51
|
list?: ListExecution;
|
|
52
52
|
}
|
|
53
53
|
export declare function runInExecution<T>(execution: Execution, fn: () => Promise<T>): Promise<T>;
|
|
54
|
+
/**
|
|
55
|
+
* Run `fn` where the tracking client cannot see it.
|
|
56
|
+
*
|
|
57
|
+
* For Nowity's own reads inside an endpoint — presence, say — which record
|
|
58
|
+
* their read set themselves, precisely, and must not have the raw SQL they run
|
|
59
|
+
* mark the whole execution as untracked. The frame is a copy whose recorders go
|
|
60
|
+
* nowhere; the snapshot and the session are the execution's own.
|
|
61
|
+
*/
|
|
62
|
+
export declare function runUntracked<T>(execution: Execution, fn: () => Promise<T>): Promise<T>;
|
|
54
63
|
export declare function currentExecution(): Execution;
|
|
55
64
|
export declare function peekExecution(): Execution | undefined;
|
|
56
65
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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;;;GAKG;AACH,qBACa,OAAO;IAChB,IAAI,QAAQ,IAAI,MAAM,CAIrB;IAED,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,CAE1B;IAED,qDAAqD;IACrD,IAAI,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElC;IAED,uEAAuE;IACvE,aAAa,IAAI,MAAM;CAK1B;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,KAAK,CAAC,CAcnD"}
|
|
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.Session = void 0;
|
|
10
10
|
exports.runInExecution = runInExecution;
|
|
11
|
+
exports.runUntracked = runUntracked;
|
|
11
12
|
exports.currentExecution = currentExecution;
|
|
12
13
|
exports.peekExecution = peekExecution;
|
|
13
14
|
exports.ambientPrisma = ambientPrisma;
|
|
@@ -35,6 +36,24 @@ function runInExecution(execution, fn) {
|
|
|
35
36
|
// nothing at all.
|
|
36
37
|
return storage.run(execution, async () => await fn());
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Run `fn` where the tracking client cannot see it.
|
|
41
|
+
*
|
|
42
|
+
* For Nowity's own reads inside an endpoint — presence, say — which record
|
|
43
|
+
* their read set themselves, precisely, and must not have the raw SQL they run
|
|
44
|
+
* mark the whole execution as untracked. The frame is a copy whose recorders go
|
|
45
|
+
* nowhere; the snapshot and the session are the execution's own.
|
|
46
|
+
*/
|
|
47
|
+
function runUntracked(execution, fn) {
|
|
48
|
+
const shadow = {
|
|
49
|
+
...execution,
|
|
50
|
+
reads: new Set(),
|
|
51
|
+
keys: undefined,
|
|
52
|
+
untracked: false,
|
|
53
|
+
list: undefined,
|
|
54
|
+
};
|
|
55
|
+
return storage.run(shadow, async () => await fn());
|
|
56
|
+
}
|
|
38
57
|
function currentExecution() {
|
|
39
58
|
const execution = storage.getStore();
|
|
40
59
|
if (!execution) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Queryable } from "../db";
|
|
2
|
+
import type { OfflineHandler, PresenceContext } from "../presence";
|
|
3
|
+
/** One online user as `Presence.details` describes them. */
|
|
4
|
+
export interface PresenceDetail {
|
|
5
|
+
userId: string;
|
|
6
|
+
/** When the current online period began. */
|
|
7
|
+
since: Date;
|
|
8
|
+
/** What their connections said they were looking at, deduplicated. */
|
|
9
|
+
contexts: PresenceContext[];
|
|
10
|
+
/** The `meta` of their newest connection (`presence.meta`); empty if none was stored. */
|
|
11
|
+
meta: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/** The table queries reading presence are invalidated by, as change events name it. */
|
|
14
|
+
export declare const PRESENCE_TABLE = "nowity_presence";
|
|
15
|
+
/** Where reads outside an execution go. Set by the runtime. */
|
|
16
|
+
export declare function bindPresenceReader(reader: Queryable | null): void;
|
|
17
|
+
export declare class Presence {
|
|
18
|
+
private readonly handlers;
|
|
19
|
+
/** Whether the user has a connection open (or had one within the grace period). */
|
|
20
|
+
isOnline(userId: string): Promise<boolean>;
|
|
21
|
+
/** Which of the given users are online. */
|
|
22
|
+
online(userIds: readonly string[]): Promise<Set<string>>;
|
|
23
|
+
/**
|
|
24
|
+
* Every online user. Watches the whole table, so a query built on it is
|
|
25
|
+
* recomputed on every transition of anyone — fine for an admin page, not
|
|
26
|
+
* for something every visitor has open.
|
|
27
|
+
*/
|
|
28
|
+
onlineAll(): Promise<string[]>;
|
|
29
|
+
/**
|
|
30
|
+
* What each of the given users' connections said they were looking at
|
|
31
|
+
* (`NowityClient.setContext`), deduplicated. A user who is offline, or set
|
|
32
|
+
* nothing, has an empty list.
|
|
33
|
+
*/
|
|
34
|
+
contexts(userIds: readonly string[]): Promise<Map<string, PresenceContext[]>>;
|
|
35
|
+
/**
|
|
36
|
+
* Who is online and since when, what they look at and what their newest
|
|
37
|
+
* connection stored as `meta` — for operator pages, which should not read
|
|
38
|
+
* Nowity's tables themselves. Longest online first. With `userIds` only
|
|
39
|
+
* those (and the read is keyed by them); without, everyone online — which
|
|
40
|
+
* watches the whole table like `onlineAll`, so cap it with `limit`.
|
|
41
|
+
*
|
|
42
|
+
* `meta` comes from `nowity_connection`, which does not reach the outbox: a
|
|
43
|
+
* query is recomputed on the user's transitions and context changes, not
|
|
44
|
+
* on a new connection with different meta.
|
|
45
|
+
*/
|
|
46
|
+
details(userIds?: readonly string[], options?: {
|
|
47
|
+
limit?: number;
|
|
48
|
+
}): Promise<PresenceDetail[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Be called after a user goes offline — at least once per transition, by
|
|
51
|
+
* whichever sync process leads. **The handler must be idempotent**; see
|
|
52
|
+
* `OfflineHandler`. Register it before the server starts, on every sync
|
|
53
|
+
* process. Returns the unsubscribe.
|
|
54
|
+
*/
|
|
55
|
+
onOffline(handler: OfflineHandler): () => void;
|
|
56
|
+
/** The registered handlers. For the presence tracker. */
|
|
57
|
+
offlineHandlers(): OfflineHandler[];
|
|
58
|
+
/**
|
|
59
|
+
* Run one read, recording it when inside a query.
|
|
60
|
+
*
|
|
61
|
+
* `keys` are the user ids the read is confined to, or null for a read of the
|
|
62
|
+
* whole table.
|
|
63
|
+
*/
|
|
64
|
+
private read;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../../../src/server/api/presence.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnE,4DAA4D;AAC5D,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,KAAK,EAAE,IAAI,CAAC;IACZ,sEAAsE;IACtE,QAAQ,EAAE,eAAe,EAAE,CAAC;I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