nowity 1.6.0 → 1.7.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 +58 -0
- package/dist/api/contract.d.ts +11 -0
- package/dist/api/contract.d.ts.map +1 -1
- package/dist/api/contract.js +5 -1
- package/dist/client/confirmed-store.d.ts +2 -11
- package/dist/client/confirmed-store.d.ts.map +1 -1
- package/dist/client/confirmed-store.js +5 -0
- package/dist/client/nowity-client.d.ts +85 -0
- package/dist/client/nowity-client.d.ts.map +1 -1
- package/dist/client/nowity-client.js +213 -14
- package/dist/client/overlay.d.ts +2 -0
- package/dist/client/overlay.d.ts.map +1 -1
- package/dist/client/overlay.js +4 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/core/derived.d.ts +96 -0
- package/dist/core/derived.d.ts.map +1 -0
- package/dist/core/derived.js +127 -0
- package/dist/core/protocol.d.ts +23 -1
- package/dist/core/protocol.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/server/api/bridge.d.ts +8 -0
- package/dist/server/api/bridge.d.ts.map +1 -1
- package/dist/server/api/bridge.js +20 -1
- package/dist/server/api/configure.d.ts.map +1 -1
- package/dist/server/api/configure.js +1 -0
- package/dist/server/api/derived.d.ts +143 -0
- package/dist/server/api/derived.d.ts.map +1 -0
- package/dist/server/api/derived.js +377 -0
- package/dist/server/api/execution.d.ts +6 -0
- package/dist/server/api/execution.d.ts.map +1 -1
- package/dist/server/api/execution.js +1 -0
- package/dist/server/api/read-keys.d.ts +20 -0
- package/dist/server/api/read-keys.d.ts.map +1 -1
- package/dist/server/api/read-keys.js +103 -0
- package/dist/server/api/runtime.d.ts +10 -0
- package/dist/server/api/runtime.d.ts.map +1 -1
- package/dist/server/api/runtime.js +1 -0
- package/dist/server/api/tracked-client.d.ts.map +1 -1
- package/dist/server/api/tracked-client.js +9 -0
- package/dist/server/evaluate.d.ts +2 -0
- package/dist/server/evaluate.d.ts.map +1 -1
- package/dist/server/evaluate.js +1 -0
- package/dist/server/mutator.d.ts +2 -0
- package/dist/server/mutator.d.ts.map +1 -1
- package/dist/server/query.d.ts +6 -0
- package/dist/server/query.d.ts.map +1 -1
- package/dist/server/sync-engine.d.ts +21 -0
- package/dist/server/sync-engine.d.ts.map +1 -1
- package/dist/server/sync-engine.js +74 -1
- package/package.json +1 -1
package/dist/core/protocol.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DerivedMutator } from "./derived";
|
|
1
2
|
import type { EntityId, Row, RowPatch } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* Wire protocol between the sync server and the client.
|
|
@@ -144,6 +145,7 @@ export interface ServerWelcome {
|
|
|
144
145
|
endpoints: Array<{
|
|
145
146
|
method: string;
|
|
146
147
|
kind: string;
|
|
148
|
+
dedupe?: boolean;
|
|
147
149
|
}>;
|
|
148
150
|
}>;
|
|
149
151
|
entities?: Record<string, WireEntity>;
|
|
@@ -182,6 +184,11 @@ export interface SubSnapshot {
|
|
|
182
184
|
scope: string | null;
|
|
183
185
|
epoch: number;
|
|
184
186
|
reason: SnapshotReason;
|
|
187
|
+
/**
|
|
188
|
+
* Client mutators derived for this subscription (see `core/derived`).
|
|
189
|
+
* Absent = none. Replaced, never merged, by a later `mutators` list.
|
|
190
|
+
*/
|
|
191
|
+
mutators?: DerivedMutator[];
|
|
185
192
|
}
|
|
186
193
|
export interface ServerSnapshot extends SubSnapshot {
|
|
187
194
|
t: "snapshot";
|
|
@@ -224,6 +231,21 @@ export interface ServerTx {
|
|
|
224
231
|
snapshots?: SubSnapshot[];
|
|
225
232
|
/** Subscriptions the client may no longer hold. */
|
|
226
233
|
revoked?: SubRevoked[];
|
|
234
|
+
/** Subscriptions whose derived mutators changed, with the whole new list. */
|
|
235
|
+
mutators?: SubMutators[];
|
|
236
|
+
}
|
|
237
|
+
/** The derived mutators of one subscription, replacing whatever it had. */
|
|
238
|
+
export interface SubMutators {
|
|
239
|
+
subId: string;
|
|
240
|
+
mutators: DerivedMutator[];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Derived mutators changed without any data changing — a mutation was just
|
|
244
|
+
* learned, or demoted to the fallback.
|
|
245
|
+
*/
|
|
246
|
+
export interface ServerMutators {
|
|
247
|
+
t: "mutators";
|
|
248
|
+
subs: SubMutators[];
|
|
227
249
|
}
|
|
228
250
|
export interface ServerMutationResult {
|
|
229
251
|
t: "mutation-result";
|
|
@@ -240,5 +262,5 @@ export interface ServerError {
|
|
|
240
262
|
code: string;
|
|
241
263
|
message: string;
|
|
242
264
|
}
|
|
243
|
-
export type ServerMessage = ServerWelcome | ServerSnapshot | ServerTx | ServerMutationResult | ServerError;
|
|
265
|
+
export type ServerMessage = ServerWelcome | ServerSnapshot | ServerTx | ServerMutationResult | ServerMutators | ServerError;
|
|
244
266
|
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -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;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,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;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACrB,CAAC,EAAE,IAAI,CAAC;IACR,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAC1B,mDAAmD;IACnD,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;CAC5B;AAED,2EAA2E;AAC3E,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC3B,CAAC,EAAE,UAAU,CAAC;IACd,IAAI,EAAE,WAAW,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACjC,CAAC,EAAE,iBAAiB,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,KAAK,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,cAAc,GACd,WAAW,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -50,4 +50,6 @@ export { NowityConnection, activeConnection, currentConnection, type NowityConne
|
|
|
50
50
|
export { WebSocketTransport, type WebSocketTransportOptions } from "./client/ws-transport";
|
|
51
51
|
export type { EntityId, Row } from "./core/types";
|
|
52
52
|
export type { HydrationPayload } from "./core/protocol";
|
|
53
|
+
export type { DerivedMutator, DerivedValue, DerivedWrite } from "./core/derived";
|
|
54
|
+
export { DerivedMutators, type DerivedStatus } from "./server/api/derived";
|
|
53
55
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EACH,GAAG,EACH,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,YAAY,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG5E,OAAO,EACH,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,yBAAyB,GAC5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,mBAAmB,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EACH,eAAe,EACf,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACH,SAAS,EACT,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,eAAe,EAC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Aa,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EACH,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,WAAW,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGlE,OAAO,EAAE,qBAAqB,EAAE,KAAK,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAC5F,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,KAAK,UAAU,GAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAG3F,YAAY,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
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.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;
|
|
38
|
+
exports.DerivedMutators = 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; } });
|
|
@@ -110,3 +110,5 @@ Object.defineProperty(exports, "activeConnection", { enumerable: true, get: func
|
|
|
110
110
|
Object.defineProperty(exports, "currentConnection", { enumerable: true, get: function () { return connection_1.currentConnection; } });
|
|
111
111
|
var ws_transport_1 = require("./client/ws-transport");
|
|
112
112
|
Object.defineProperty(exports, "WebSocketTransport", { enumerable: true, get: function () { return ws_transport_1.WebSocketTransport; } });
|
|
113
|
+
var derived_1 = require("./server/api/derived");
|
|
114
|
+
Object.defineProperty(exports, "DerivedMutators", { enumerable: true, get: function () { return derived_1.DerivedMutators; } });
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ApiManifest, type ContractMeta } from "../../api/contract";
|
|
2
2
|
import { MutatorRegistry } from "../mutator";
|
|
3
3
|
import { QueryRegistry } from "../query";
|
|
4
|
+
import { DerivedMutators } from "./derived";
|
|
4
5
|
import type { ReadSetTracker } from "./read-set";
|
|
5
6
|
/** Entity metadata the client needs, derived from the schema rather than configured. */
|
|
6
7
|
export interface EntityDescriptorWire {
|
|
@@ -13,6 +14,8 @@ export interface EntityDescriptorWire {
|
|
|
13
14
|
export interface BuiltApi {
|
|
14
15
|
queries: QueryRegistry;
|
|
15
16
|
mutators: MutatorRegistry;
|
|
17
|
+
/** Client mutators learned from what the mutations write. */
|
|
18
|
+
derived: DerivedMutators;
|
|
16
19
|
manifest: ApiManifest;
|
|
17
20
|
/** Entity shapes for the client identity map, keyed by entity name. */
|
|
18
21
|
entities: Record<string, EntityDescriptorWire>;
|
|
@@ -22,6 +25,11 @@ export interface BuildApiOptions {
|
|
|
22
25
|
tracker: ReadSetTracker;
|
|
23
26
|
/** How to obtain the implementation instance — the DI container's `getBean`. */
|
|
24
27
|
resolve: (contract: Function) => any;
|
|
28
|
+
/**
|
|
29
|
+
* Learn client mutators from what mutations write and send them with the
|
|
30
|
+
* live queries they affect. On unless `false`; see `DerivedMutators`.
|
|
31
|
+
*/
|
|
32
|
+
derivedMutators?: boolean;
|
|
25
33
|
onWarning?: (message: string) => void;
|
|
26
34
|
}
|
|
27
35
|
export declare function buildApi(options: BuildApiOptions): BuiltApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/server/api/bridge.ts"],"names":[],"mappings":"AAWA,OAAO,EAKH,KAAK,WAAW,EAChB,KAAK,YAAY,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAoB,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAuC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../../src/server/api/bridge.ts"],"names":[],"mappings":"AAWA,OAAO,EAKH,KAAK,WAAW,EAChB,KAAK,YAAY,EAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAoB,eAAe,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAuC,MAAM,UAAU,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAgB,MAAM,WAAW,CAAC;AAY1D,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAE/D,wFAAwF;AACxF,MAAM,WAAW,oBAAoB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,QAAQ;IACrB,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,eAAe,CAAC;IAC1B,6DAA6D;IAC7D,OAAO,EAAE,eAAe,CAAC;IACzB,QAAQ,EAAE,WAAW,CAAC;IACtB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;CAClD;AAED,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,gFAAgF;IAChF,OAAO,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,GAAG,CAAC;IACrC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,QAAQ,CAsH3D"}
|
|
@@ -15,6 +15,7 @@ const errors_1 = require("../../api/errors");
|
|
|
15
15
|
const contract_1 = require("../../api/contract");
|
|
16
16
|
const mutator_1 = require("../mutator");
|
|
17
17
|
const query_1 = require("../query");
|
|
18
|
+
const derived_1 = require("./derived");
|
|
18
19
|
const execution_1 = require("./execution");
|
|
19
20
|
const list_1 = require("./list");
|
|
20
21
|
const read_keys_1 = require("./read-keys");
|
|
@@ -23,6 +24,10 @@ function buildApi(options) {
|
|
|
23
24
|
const warn = options.onWarning ?? ((message) => console.warn("[nowity/api]", message));
|
|
24
25
|
const queries = new query_1.QueryRegistry();
|
|
25
26
|
const mutators = new mutator_1.MutatorRegistry();
|
|
27
|
+
const derived = new derived_1.DerivedMutators(tracker, {
|
|
28
|
+
enabled: options.derivedMutators ?? true,
|
|
29
|
+
onWarning: warn,
|
|
30
|
+
});
|
|
26
31
|
for (const contract of contracts) {
|
|
27
32
|
if (!contract.impl) {
|
|
28
33
|
throw new Error(`API contract "${contract.name}" has no implementation in this process. ` +
|
|
@@ -90,9 +95,20 @@ function buildApi(options) {
|
|
|
90
95
|
reads: new Set(),
|
|
91
96
|
untracked: false,
|
|
92
97
|
mutationId: ctx.mutationId,
|
|
98
|
+
...(derived.isEnabled ? { writes: (0, derived_1.newRecording)() } : {}),
|
|
93
99
|
};
|
|
94
100
|
try {
|
|
95
|
-
|
|
101
|
+
const value = await call(execution, args);
|
|
102
|
+
// What the code did, learned only from writes that stuck.
|
|
103
|
+
const writes = execution.writes;
|
|
104
|
+
if (writes) {
|
|
105
|
+
const learn = () => derived.observe(name, args, writes, ctx.session);
|
|
106
|
+
if (ctx.afterCommit)
|
|
107
|
+
ctx.afterCommit(learn);
|
|
108
|
+
else
|
|
109
|
+
learn();
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
96
112
|
}
|
|
97
113
|
catch (err) {
|
|
98
114
|
// The engine already knows how to treat a refused write;
|
|
@@ -108,6 +124,7 @@ function buildApi(options) {
|
|
|
108
124
|
return {
|
|
109
125
|
queries,
|
|
110
126
|
mutators,
|
|
127
|
+
derived,
|
|
111
128
|
manifest: (0, contract_1.buildManifest)(contracts),
|
|
112
129
|
entities: entityDescriptors(tracker),
|
|
113
130
|
};
|
|
@@ -278,6 +295,7 @@ function shape(returned, execution, options, tracker, name) {
|
|
|
278
295
|
const idField = options.idField ?? (model ? tracker.idField(model) : undefined);
|
|
279
296
|
const tables = readSetOf(execution, options);
|
|
280
297
|
const keys = tables ? keySetOf(execution, options) : undefined;
|
|
298
|
+
const filterColumns = keys ? execution.keys.columns() : undefined;
|
|
281
299
|
const single = !Array.isArray(returned);
|
|
282
300
|
const rows = toRows(returned, name);
|
|
283
301
|
const extra = {};
|
|
@@ -293,6 +311,7 @@ function shape(returned, execution, options, tracker, name) {
|
|
|
293
311
|
...(idField ? { idField } : {}),
|
|
294
312
|
...(tables ? { tables } : {}),
|
|
295
313
|
...(keys ? { keys } : {}),
|
|
314
|
+
...(filterColumns ? { filterColumns } : {}),
|
|
296
315
|
...(entity ? { entity } : {}),
|
|
297
316
|
...(single ? { single: true } : {}),
|
|
298
317
|
};
|
|
@@ -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;AAC9E,OAAO,EAAE,eAAe,EAAE,KAAK,e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e,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,2CAA2C;AAC3C,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAEhD,MAAM,WAAW,YAAa,SAAQ,aAAa;IAC/C,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,gBAAgB,CAAC;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,CA6D3E"}
|
|
@@ -54,6 +54,7 @@ function createNowityServer(config) {
|
|
|
54
54
|
source: resolveChangeSource(config),
|
|
55
55
|
queries: runtime.api.queries,
|
|
56
56
|
mutators: runtime.api.mutators,
|
|
57
|
+
derived: runtime.api.derived,
|
|
57
58
|
api: { contracts: runtime.api.manifest.contracts, entities: runtime.api.entities },
|
|
58
59
|
narrowInvalidation: config.narrowInvalidation,
|
|
59
60
|
...(presence ? { presence } : {}),
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client mutators derived from what mutations write.
|
|
3
|
+
*
|
|
4
|
+
* Every `@mutation` runs over the tracking client, which records each model
|
|
5
|
+
* write it makes (`WriteRecord`). After a mutation succeeds its writes are
|
|
6
|
+
* matched against its arguments: a written value equal to an argument is that
|
|
7
|
+
* argument, a value equal to the caller's own user id is the session's, a value
|
|
8
|
+
* found nowhere is a constant. Two calls must agree on all of it — the same
|
|
9
|
+
* writes in the same shape, every constant the same — and a call that does not
|
|
10
|
+
* agree with the ones before demotes the mutation to the fallback for good.
|
|
11
|
+
*
|
|
12
|
+
* The result is the mutation's *write fingerprint*: which rows of which model
|
|
13
|
+
* it writes, which fields, and from where. A live query receives the
|
|
14
|
+
* fingerprints whose model rows it holds and whose writes cannot move a row in
|
|
15
|
+
* or out of it — the intersection of what the query read with what the
|
|
16
|
+
* mutation writes.
|
|
17
|
+
*
|
|
18
|
+
* Anything that does not fit the shape stays a fallback: the mutation is sent
|
|
19
|
+
* and the query waits for the server, exactly as without this feature.
|
|
20
|
+
*
|
|
21
|
+
* - an insert, an upsert, a write to many rows (`createMany`, `updateMany`, …),
|
|
22
|
+
* a raw `$executeRaw` — ids, defaults and membership only the database knows;
|
|
23
|
+
* - a write whose row is not named by its id;
|
|
24
|
+
* - a value computed from something the mutation read, or from the clock —
|
|
25
|
+
* it differs between two calls in a way no argument explains;
|
|
26
|
+
* - nested relation writes, JSON columns;
|
|
27
|
+
* - side effects outside the database, which nothing here can see.
|
|
28
|
+
*/
|
|
29
|
+
import type { DerivedMutator } from "../../core/derived";
|
|
30
|
+
import type { RowFilter } from "../../core/protocol";
|
|
31
|
+
import type { ReadKeySet } from "../../core/types";
|
|
32
|
+
import type { SessionInfo } from "../query";
|
|
33
|
+
import type { ReadSetTracker } from "./read-set";
|
|
34
|
+
/** One model-level write, as the tracking client saw it. */
|
|
35
|
+
export interface WriteRecord {
|
|
36
|
+
model: string;
|
|
37
|
+
operation: string;
|
|
38
|
+
args: unknown;
|
|
39
|
+
}
|
|
40
|
+
/** What a mutation's writes looked like to the tracking client, for one call. */
|
|
41
|
+
export interface WriteRecording {
|
|
42
|
+
writes: WriteRecord[];
|
|
43
|
+
/** Something wrote through raw SQL, so the list above may be incomplete. */
|
|
44
|
+
raw: boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function newRecording(): WriteRecording;
|
|
47
|
+
/** Where one mutation stands. */
|
|
48
|
+
export type DerivedStatus =
|
|
49
|
+
/** Seen, but not often enough to tell an argument or a constant from a coincidence. */
|
|
50
|
+
{
|
|
51
|
+
state: "learning";
|
|
52
|
+
observations: number;
|
|
53
|
+
} | {
|
|
54
|
+
state: "derived";
|
|
55
|
+
observations: number;
|
|
56
|
+
} | {
|
|
57
|
+
state: "fallback";
|
|
58
|
+
reason: string;
|
|
59
|
+
};
|
|
60
|
+
/** A subscription, as far as deciding which fingerprints it gets is concerned. */
|
|
61
|
+
export interface DerivedSubscription {
|
|
62
|
+
/** Tables it read; `null` = not known, which gets nothing. */
|
|
63
|
+
tables: Set<string> | null;
|
|
64
|
+
/** Rows it read, per table; `null` = not known. */
|
|
65
|
+
keys: ReadKeySet | null;
|
|
66
|
+
/**
|
|
67
|
+
* Columns its `where` and `orderBy` mentioned, per table; `null` = not
|
|
68
|
+
* known, which gets nothing.
|
|
69
|
+
*/
|
|
70
|
+
filterColumns: Map<string, Set<string>> | null;
|
|
71
|
+
/** Entities whose rows it holds in the client store. */
|
|
72
|
+
entities: string[];
|
|
73
|
+
/** Its collection filter, when it has one. */
|
|
74
|
+
filter?: RowFilter | null;
|
|
75
|
+
}
|
|
76
|
+
export interface DerivedMutatorsOptions {
|
|
77
|
+
/** Off (the default): nothing is learned and no query gets a fingerprint. */
|
|
78
|
+
enabled?: boolean;
|
|
79
|
+
onWarning?: (message: string) => void;
|
|
80
|
+
}
|
|
81
|
+
type Shaped = {
|
|
82
|
+
ok: true;
|
|
83
|
+
writes: ObservedWrite[];
|
|
84
|
+
} | {
|
|
85
|
+
ok: false;
|
|
86
|
+
reason: string;
|
|
87
|
+
};
|
|
88
|
+
interface ObservedWrite {
|
|
89
|
+
entity: string;
|
|
90
|
+
op: "update" | "delete";
|
|
91
|
+
id: unknown;
|
|
92
|
+
set: Record<string, unknown>;
|
|
93
|
+
inc: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export declare class DerivedMutators {
|
|
96
|
+
private readonly tracker;
|
|
97
|
+
private readonly learned;
|
|
98
|
+
private readonly listeners;
|
|
99
|
+
private readonly enabled;
|
|
100
|
+
private readonly warn;
|
|
101
|
+
/** Bumped whenever what any query should get may have changed. */
|
|
102
|
+
version: number;
|
|
103
|
+
constructor(tracker: ReadSetTracker, options?: DerivedMutatorsOptions);
|
|
104
|
+
get isEnabled(): boolean;
|
|
105
|
+
/** Told after every successful call of a mutation. */
|
|
106
|
+
observe(name: string, args: unknown, recording: WriteRecording, session: SessionInfo): void;
|
|
107
|
+
status(name: string): DerivedStatus | undefined;
|
|
108
|
+
/** Every mutation seen so far and where it stands — for an operator, or a test. */
|
|
109
|
+
report(): Record<string, DerivedStatus>;
|
|
110
|
+
onChange(listener: () => void): () => void;
|
|
111
|
+
/**
|
|
112
|
+
* The fingerprints one live query gets.
|
|
113
|
+
*
|
|
114
|
+
* Per subscription — per query *and* arguments — because two instances of
|
|
115
|
+
* one query can read different rows under different filters, and only the
|
|
116
|
+
* intersection with what this instance read says whether the write can be
|
|
117
|
+
* shown here without asking the server.
|
|
118
|
+
*/
|
|
119
|
+
forSubscription(sub: DerivedSubscription, session: SessionInfo): DerivedMutator[];
|
|
120
|
+
/**
|
|
121
|
+
* The writes of one fingerprint as this subscription gets them, or null if
|
|
122
|
+
* the fingerprint is not for it.
|
|
123
|
+
*
|
|
124
|
+
* All writes or none: a mutator applied halfway would show a state the
|
|
125
|
+
* server never produces.
|
|
126
|
+
*/
|
|
127
|
+
private affecting;
|
|
128
|
+
/**
|
|
129
|
+
* Whether writing these fields can never move a row in, out of or along
|
|
130
|
+
* the query.
|
|
131
|
+
*
|
|
132
|
+
* Every column the query's `where` or `orderBy` mentioned, by any
|
|
133
|
+
* operator, through any relation: a write to one of them could make a row
|
|
134
|
+
* leave, arrive or move, and where to is the server's to say.
|
|
135
|
+
*/
|
|
136
|
+
private membershipStable;
|
|
137
|
+
private demote;
|
|
138
|
+
private store;
|
|
139
|
+
}
|
|
140
|
+
/** Reduce what the tracking client saw to rows written by id — or say why not. */
|
|
141
|
+
export declare function shapeWrites(writes: WriteRecord[], tracker: ReadSetTracker): Shaped;
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=derived.d.ts.map
|
|
@@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