nowity 1.0.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 +751 -0
- package/dist/api/contract.d.ts +186 -0
- package/dist/api/contract.d.ts.map +1 -0
- package/dist/api/contract.js +251 -0
- package/dist/api/errors.d.ts +50 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +50 -0
- package/dist/api/index.d.ts +13 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +32 -0
- package/dist/client/confirmed-store.d.ts +33 -0
- package/dist/client/confirmed-store.d.ts.map +1 -0
- package/dist/client/confirmed-store.js +123 -0
- package/dist/client/connection.d.ts +102 -0
- package/dist/client/connection.d.ts.map +1 -0
- package/dist/client/connection.js +285 -0
- package/dist/client/list.d.ts +102 -0
- package/dist/client/list.d.ts.map +1 -0
- package/dist/client/list.js +257 -0
- package/dist/client/live-query.d.ts +153 -0
- package/dist/client/live-query.d.ts.map +1 -0
- package/dist/client/live-query.js +244 -0
- package/dist/client/nowity-client.d.ts +188 -0
- package/dist/client/nowity-client.d.ts.map +1 -0
- package/dist/client/nowity-client.js +580 -0
- package/dist/client/null-transport.d.ts +16 -0
- package/dist/client/null-transport.d.ts.map +1 -0
- package/dist/client/null-transport.js +17 -0
- package/dist/client/overlay.d.ts +44 -0
- package/dist/client/overlay.d.ts.map +1 -0
- package/dist/client/overlay.js +90 -0
- package/dist/client/query-source.d.ts +78 -0
- package/dist/client/query-source.d.ts.map +1 -0
- package/dist/client/query-source.js +57 -0
- package/dist/client/ssr-source.d.ts +70 -0
- package/dist/client/ssr-source.d.ts.map +1 -0
- package/dist/client/ssr-source.js +134 -0
- package/dist/client/transport.d.ts +19 -0
- package/dist/client/transport.d.ts.map +1 -0
- package/dist/client/transport.js +2 -0
- package/dist/client/ws-transport.d.ts +30 -0
- package/dist/client/ws-transport.d.ts.map +1 -0
- package/dist/client/ws-transport.js +89 -0
- package/dist/client.d.ts +47 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +80 -0
- package/dist/core/diff.d.ts +14 -0
- package/dist/core/diff.d.ts.map +1 -0
- package/dist/core/diff.js +56 -0
- package/dist/core/normalize.d.ts +16 -0
- package/dist/core/normalize.d.ts.map +1 -0
- package/dist/core/normalize.js +67 -0
- package/dist/core/protocol.d.ts +215 -0
- package/dist/core/protocol.d.ts.map +1 -0
- package/dist/core/protocol.js +14 -0
- package/dist/core/ssr-bridge.d.ts +69 -0
- package/dist/core/ssr-bridge.d.ts.map +1 -0
- package/dist/core/ssr-bridge.js +40 -0
- package/dist/core/types.d.ts +96 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +17 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +98 -0
- package/dist/ironbean/client.d.ts +7 -0
- package/dist/ironbean/client.d.ts.map +1 -0
- package/dist/ironbean/client.js +38 -0
- package/dist/ironbean/server.d.ts +42 -0
- package/dist/ironbean/server.d.ts.map +1 -0
- package/dist/ironbean/server.js +62 -0
- package/dist/ironbean/tokens.d.ts +26 -0
- package/dist/ironbean/tokens.d.ts.map +1 -0
- package/dist/ironbean/tokens.js +23 -0
- package/dist/next/config.d.ts +7 -0
- package/dist/next/config.d.ts.map +1 -0
- package/dist/next/config.js +77 -0
- package/dist/next/live.d.ts +69 -0
- package/dist/next/live.d.ts.map +1 -0
- package/dist/next/live.js +70 -0
- package/dist/next/serve.d.ts +44 -0
- package/dist/next/serve.d.ts.map +1 -0
- package/dist/next/serve.js +107 -0
- package/dist/next/server.d.ts +62 -0
- package/dist/next/server.d.ts.map +1 -0
- package/dist/next/server.js +127 -0
- package/dist/react/connection-context.d.ts +4 -0
- package/dist/react/connection-context.d.ts.map +1 -0
- package/dist/react/connection-context.js +28 -0
- package/dist/react/grid-list.d.ts +34 -0
- package/dist/react/grid-list.d.ts.map +1 -0
- package/dist/react/grid-list.js +62 -0
- package/dist/react/hydrate.d.ts +22 -0
- package/dist/react/hydrate.d.ts.map +1 -0
- package/dist/react/hydrate.js +18 -0
- package/dist/react/index.d.ts +35 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +51 -0
- package/dist/react/list.d.ts +31 -0
- package/dist/react/list.d.ts.map +1 -0
- package/dist/react/list.js +35 -0
- package/dist/react/prerendered.d.ts +33 -0
- package/dist/react/prerendered.d.ts.map +1 -0
- package/dist/react/prerendered.js +165 -0
- package/dist/react/provider.d.ts +64 -0
- package/dist/react/provider.d.ts.map +1 -0
- package/dist/react/provider.js +130 -0
- package/dist/react/refusals.d.ts +31 -0
- package/dist/react/refusals.d.ts.map +1 -0
- package/dist/react/refusals.js +51 -0
- package/dist/react/restricted.d.ts +76 -0
- package/dist/react/restricted.d.ts.map +1 -0
- package/dist/react/restricted.js +126 -0
- package/dist/react/use-list.d.ts +42 -0
- package/dist/react/use-list.d.ts.map +1 -0
- package/dist/react/use-list.js +56 -0
- package/dist/react/use-query.d.ts +66 -0
- package/dist/react/use-query.d.ts.map +1 -0
- package/dist/react/use-query.js +126 -0
- package/dist/react/virtual.d.ts +60 -0
- package/dist/react/virtual.d.ts.map +1 -0
- package/dist/react/virtual.js +131 -0
- package/dist/server/api/auth.d.ts +37 -0
- package/dist/server/api/auth.d.ts.map +1 -0
- package/dist/server/api/auth.js +54 -0
- package/dist/server/api/bridge.d.ts +28 -0
- package/dist/server/api/bridge.d.ts.map +1 -0
- package/dist/server/api/bridge.js +330 -0
- package/dist/server/api/collector.d.ts +25 -0
- package/dist/server/api/collector.d.ts.map +1 -0
- package/dist/server/api/collector.js +184 -0
- package/dist/server/api/configure.d.ts +31 -0
- package/dist/server/api/configure.d.ts.map +1 -0
- package/dist/server/api/configure.js +67 -0
- package/dist/server/api/execution.d.ts +77 -0
- package/dist/server/api/execution.d.ts.map +1 -0
- package/dist/server/api/execution.js +97 -0
- package/dist/server/api/list.d.ts +141 -0
- package/dist/server/api/list.d.ts.map +1 -0
- package/dist/server/api/list.js +281 -0
- package/dist/server/api/prerender.d.ts +32 -0
- package/dist/server/api/prerender.d.ts.map +1 -0
- package/dist/server/api/prerender.js +69 -0
- package/dist/server/api/read-keys.d.ts +128 -0
- package/dist/server/api/read-keys.d.ts.map +1 -0
- package/dist/server/api/read-keys.js +464 -0
- package/dist/server/api/read-set.d.ts +103 -0
- package/dist/server/api/read-set.d.ts.map +1 -0
- package/dist/server/api/read-set.js +210 -0
- package/dist/server/api/runtime.d.ts +36 -0
- package/dist/server/api/runtime.d.ts.map +1 -0
- package/dist/server/api/runtime.js +49 -0
- package/dist/server/api/tracked-client.d.ts +6 -0
- package/dist/server/api/tracked-client.d.ts.map +1 -0
- package/dist/server/api/tracked-client.js +56 -0
- package/dist/server/change-source/change-source.d.ts +41 -0
- package/dist/server/change-source/change-source.d.ts.map +1 -0
- package/dist/server/change-source/change-source.js +2 -0
- package/dist/server/change-source/outbox-change-source.d.ts +106 -0
- package/dist/server/change-source/outbox-change-source.d.ts.map +1 -0
- package/dist/server/change-source/outbox-change-source.js +237 -0
- package/dist/server/change-source/wal-change-source.d.ts +85 -0
- package/dist/server/change-source/wal-change-source.d.ts.map +1 -0
- package/dist/server/change-source/wal-change-source.js +193 -0
- package/dist/server/db.d.ts +51 -0
- package/dist/server/db.d.ts.map +1 -0
- package/dist/server/db.js +53 -0
- package/dist/server/evaluate.d.ts +39 -0
- package/dist/server/evaluate.d.ts.map +1 -0
- package/dist/server/evaluate.js +61 -0
- package/dist/server/invalidation-index.d.ts +64 -0
- package/dist/server/invalidation-index.d.ts.map +1 -0
- package/dist/server/invalidation-index.js +0 -0
- package/dist/server/mutator.d.ts +59 -0
- package/dist/server/mutator.d.ts.map +1 -0
- package/dist/server/mutator.js +77 -0
- package/dist/server/query.d.ts +113 -0
- package/dist/server/query.d.ts.map +1 -0
- package/dist/server/query.js +35 -0
- package/dist/server/setup.d.ts +30 -0
- package/dist/server/setup.d.ts.map +1 -0
- package/dist/server/setup.js +107 -0
- package/dist/server/sql/setup.sql +215 -0
- package/dist/server/ssr.d.ts +29 -0
- package/dist/server/ssr.d.ts.map +1 -0
- package/dist/server/ssr.js +43 -0
- package/dist/server/sync-engine.d.ts +256 -0
- package/dist/server/sync-engine.d.ts.map +1 -0
- package/dist/server/sync-engine.js +805 -0
- package/dist/server/ws-server.d.ts +56 -0
- package/dist/server/ws-server.d.ts.map +1 -0
- package/dist/server/ws-server.js +241 -0
- package/package.json +81 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API contract: what the server implements and what the client calls.
|
|
3
|
+
*
|
|
4
|
+
* A contract is an abstract class in code shared by both sides. On the server an
|
|
5
|
+
* implementation extends it; on the client the container binds a proxy to the
|
|
6
|
+
* same class. `container.getBean(DocumentApi)` is therefore literally the same
|
|
7
|
+
* line on both sides — the class *is* the dependency token (Ironbean's
|
|
8
|
+
* `Dependency<T>` accepts any class, abstract included).
|
|
9
|
+
*
|
|
10
|
+
* Nothing here may import `pg`, `mobx`, `ws` or `@prisma/client`: this file ends
|
|
11
|
+
* up in the browser bundle, and `test/scenarios/16` asserts that server code
|
|
12
|
+
* never follows it there.
|
|
13
|
+
*/
|
|
14
|
+
import "reflect-metadata";
|
|
15
|
+
export type EndpointKind = "query" | "mutation" | "list";
|
|
16
|
+
/** Options for `@query`, for the cases the read-set tracker cannot cover. */
|
|
17
|
+
export interface QueryOptions {
|
|
18
|
+
/**
|
|
19
|
+
* Tables this method reads, when it reads them in a way the tracker cannot
|
|
20
|
+
* see (raw SQL, an outside service, a cache).
|
|
21
|
+
*
|
|
22
|
+
* Declaring them *adds* to what the tracker finds, it never replaces it. A
|
|
23
|
+
* method whose read set ends up empty is revalidated on every transaction —
|
|
24
|
+
* correct but slow, and it warns in development.
|
|
25
|
+
*/
|
|
26
|
+
tables?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Entity name the returned rows are stored under in the client identity map.
|
|
29
|
+
* Derived from the Prisma model when the tracker can see it.
|
|
30
|
+
*/
|
|
31
|
+
entity?: string;
|
|
32
|
+
/** Field carrying the identity of a returned row. Default `id`. */
|
|
33
|
+
idField?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for `@list`. The same ones a query takes, for the same reasons.
|
|
37
|
+
*
|
|
38
|
+
* There is deliberately nothing about paging here: a list endpoint states what
|
|
39
|
+
* the collection *is*, and where a viewport happens to be is the browser's
|
|
40
|
+
* business, not the endpoint's.
|
|
41
|
+
*/
|
|
42
|
+
export type ListOptions = QueryOptions;
|
|
43
|
+
export interface MutationOptions {
|
|
44
|
+
/** Purely descriptive; mutations declare no read dependencies. */
|
|
45
|
+
description?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface EndpointMeta {
|
|
48
|
+
method: string;
|
|
49
|
+
kind: EndpointKind;
|
|
50
|
+
query?: QueryOptions;
|
|
51
|
+
mutation?: MutationOptions;
|
|
52
|
+
}
|
|
53
|
+
export interface ContractMeta {
|
|
54
|
+
/** Wire name. Explicit, because minifiers rename classes in the browser. */
|
|
55
|
+
name: string;
|
|
56
|
+
/** The token both halves resolve. Created by {@link contract}. */
|
|
57
|
+
contract: Function;
|
|
58
|
+
/** The class carrying the decorated methods. */
|
|
59
|
+
impl?: Function;
|
|
60
|
+
endpoints: Map<string, EndpointMeta>;
|
|
61
|
+
}
|
|
62
|
+
/** One endpoint as announced to the client in the handshake manifest. */
|
|
63
|
+
export interface ManifestEndpoint {
|
|
64
|
+
method: string;
|
|
65
|
+
kind: EndpointKind;
|
|
66
|
+
}
|
|
67
|
+
export interface ManifestContract {
|
|
68
|
+
name: string;
|
|
69
|
+
endpoints: ManifestEndpoint[];
|
|
70
|
+
}
|
|
71
|
+
/** The server's API shape, sent at handshake so the proxy knows what is what. */
|
|
72
|
+
export interface ApiManifest {
|
|
73
|
+
contracts: ManifestContract[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The token both halves resolve, and the only thing the browser needs to know
|
|
77
|
+
* about a service.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* // shared
|
|
81
|
+
* export const DocumentApi = contract<DocumentApiImpl>("documents");
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* A real class at runtime, so it works as an Ironbean token exactly as a
|
|
85
|
+
* hand-written abstract class would — and the implementation's own type at
|
|
86
|
+
* compile time, so the signatures live in one place. Writing them out a second
|
|
87
|
+
* time would only create somewhere for them to drift.
|
|
88
|
+
*
|
|
89
|
+
* `DocumentApiImpl` is imported *as a type*. That import is erased, so nothing
|
|
90
|
+
* of the server follows it into the browser bundle; `test/scenarios/16` exists to
|
|
91
|
+
* keep that true.
|
|
92
|
+
*
|
|
93
|
+
* The name is explicit because it is the wire identity of the service, and a
|
|
94
|
+
* class name does not survive a production browser build.
|
|
95
|
+
*/
|
|
96
|
+
export declare function contract<T>(name: string): abstract new (...args: any[]) => T;
|
|
97
|
+
/**
|
|
98
|
+
* Say which service a class implements.
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* @api(DocumentApi)
|
|
102
|
+
* @component
|
|
103
|
+
* export class DocumentApiImpl {
|
|
104
|
+
* @query() byProject(projectId: string) { … }
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* The token, not its name: the name is written once, where the token is
|
|
109
|
+
* declared, and everything else refers to the token — so a typo is a compile
|
|
110
|
+
* error rather than a subscription the server never answers.
|
|
111
|
+
*
|
|
112
|
+
* The token is imported as a value here while the token's own module imports
|
|
113
|
+
* this class as a *type*. That is not a cycle at runtime: a type-only import is
|
|
114
|
+
* erased.
|
|
115
|
+
*/
|
|
116
|
+
export declare function api(service: string | Function): ClassDecorator;
|
|
117
|
+
/**
|
|
118
|
+
* Mark a method as a live query.
|
|
119
|
+
*
|
|
120
|
+
* The method must only read. It is re-executed whenever a table it read changes,
|
|
121
|
+
* so a write inside it would run again on every invalidation — the recording
|
|
122
|
+
* client refuses one outright rather than letting that happen quietly.
|
|
123
|
+
*/
|
|
124
|
+
export declare function query(options?: QueryOptions): MethodDecorator;
|
|
125
|
+
/**
|
|
126
|
+
* Mark a method as a live *collection*.
|
|
127
|
+
*
|
|
128
|
+
* ```ts
|
|
129
|
+
* @list()
|
|
130
|
+
* async all(projectId: string) {
|
|
131
|
+
* await this.assertMember(projectId);
|
|
132
|
+
* return this.db.document.findMany({ where: { projectId }, orderBy: … });
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* The same method a `@query` would be, with no `skip`, no `take` and no cursor —
|
|
137
|
+
* because a collection of a hundred thousand rows and a collection of nine are
|
|
138
|
+
* the same statement about what the caller may see, and only the browser knows
|
|
139
|
+
* which forty of them are on the screen right now.
|
|
140
|
+
*
|
|
141
|
+
* So the endpoint says what the collection is and the framework pages it: the
|
|
142
|
+
* browser subscribes to the windows its viewport covers, and each of those is an
|
|
143
|
+
* ordinary live query — the method run again with a `LIMIT` and an `OFFSET`
|
|
144
|
+
* pushed into its last `findMany`. Rows outside the viewport cost nothing, and
|
|
145
|
+
* the ones inside it are as live as any other query's.
|
|
146
|
+
*
|
|
147
|
+
* Read it with `useList`, which hands back the store `<GridList>` scrolls.
|
|
148
|
+
*/
|
|
149
|
+
export declare function list(options?: ListOptions): MethodDecorator;
|
|
150
|
+
/** Mark a method as a write. It runs inside one transaction, attributed to the caller. */
|
|
151
|
+
export declare function mutation(options?: MutationOptions): MethodDecorator;
|
|
152
|
+
/**
|
|
153
|
+
* Resolve every implementation to its contract.
|
|
154
|
+
*
|
|
155
|
+
* The link is inheritance: an implementation registers itself by carrying
|
|
156
|
+
* decorated methods, and its contract is the nearest ancestor marked with
|
|
157
|
+
* `@api`. That is why nothing has to be listed anywhere — importing the module
|
|
158
|
+
* is the registration.
|
|
159
|
+
*/
|
|
160
|
+
export declare function resolveContracts(): ContractMeta[];
|
|
161
|
+
/** Contracts known to this process, whether implemented or not (the client's case). */
|
|
162
|
+
export declare function knownContracts(): ContractMeta[];
|
|
163
|
+
export declare function contractOf(target: Function): ContractMeta | undefined;
|
|
164
|
+
/** The wire name of a service, from its token or from the name itself. */
|
|
165
|
+
export declare function contractNameOf(target: string | Function): string;
|
|
166
|
+
/** Wire name of one endpoint: `contract.method`. */
|
|
167
|
+
export declare function endpointName(contract: string, method: string): string;
|
|
168
|
+
/**
|
|
169
|
+
* The two live queries a `@list` endpoint is served through.
|
|
170
|
+
*
|
|
171
|
+
* A list is not one subscription but a family of them — one per window the
|
|
172
|
+
* viewport covers, plus one for how many rows there are at all — and both halves
|
|
173
|
+
* have to agree on their names without either telling the other. So the names
|
|
174
|
+
* are derived, here, from the endpoint's own: the manifest announces the
|
|
175
|
+
* endpoint once, and the browser builds the same strings the server registered.
|
|
176
|
+
*
|
|
177
|
+
* The `#` is not decoration. It cannot occur in a method name, so a derived
|
|
178
|
+
* query can never collide with a declared one.
|
|
179
|
+
*/
|
|
180
|
+
export declare function pageQuery(endpoint: string): string;
|
|
181
|
+
/** How many rows the collection has, as a live query of its own. */
|
|
182
|
+
export declare function countQuery(endpoint: string): string;
|
|
183
|
+
export declare function buildManifest(contracts: ContractMeta[]): ApiManifest;
|
|
184
|
+
/** Test seam: forget every registered contract. */
|
|
185
|
+
export declare function resetContracts(): void;
|
|
186
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/api/contract.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contract = contract;
|
|
4
|
+
exports.api = api;
|
|
5
|
+
exports.query = query;
|
|
6
|
+
exports.list = list;
|
|
7
|
+
exports.mutation = mutation;
|
|
8
|
+
exports.resolveContracts = resolveContracts;
|
|
9
|
+
exports.knownContracts = knownContracts;
|
|
10
|
+
exports.contractOf = contractOf;
|
|
11
|
+
exports.contractNameOf = contractNameOf;
|
|
12
|
+
exports.endpointName = endpointName;
|
|
13
|
+
exports.pageQuery = pageQuery;
|
|
14
|
+
exports.countQuery = countQuery;
|
|
15
|
+
exports.buildManifest = buildManifest;
|
|
16
|
+
exports.resetContracts = resetContracts;
|
|
17
|
+
/**
|
|
18
|
+
* The API contract: what the server implements and what the client calls.
|
|
19
|
+
*
|
|
20
|
+
* A contract is an abstract class in code shared by both sides. On the server an
|
|
21
|
+
* implementation extends it; on the client the container binds a proxy to the
|
|
22
|
+
* same class. `container.getBean(DocumentApi)` is therefore literally the same
|
|
23
|
+
* line on both sides — the class *is* the dependency token (Ironbean's
|
|
24
|
+
* `Dependency<T>` accepts any class, abstract included).
|
|
25
|
+
*
|
|
26
|
+
* Nothing here may import `pg`, `mobx`, `ws` or `@prisma/client`: this file ends
|
|
27
|
+
* up in the browser bundle, and `test/scenarios/16` asserts that server code
|
|
28
|
+
* never follows it there.
|
|
29
|
+
*/
|
|
30
|
+
require("reflect-metadata");
|
|
31
|
+
const ironbean_1 = require("ironbean");
|
|
32
|
+
const contractsByName = new Map();
|
|
33
|
+
const contractsByClass = new Map();
|
|
34
|
+
/** Endpoints collected from implementation prototypes, keyed by the impl class. */
|
|
35
|
+
const endpointsByImpl = new Map();
|
|
36
|
+
function metaFor(name) {
|
|
37
|
+
let meta = contractsByName.get(name);
|
|
38
|
+
if (!meta) {
|
|
39
|
+
meta = { name, contract: undefined, endpoints: new Map() };
|
|
40
|
+
contractsByName.set(name, meta);
|
|
41
|
+
}
|
|
42
|
+
return meta;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The token both halves resolve, and the only thing the browser needs to know
|
|
46
|
+
* about a service.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* // shared
|
|
50
|
+
* export const DocumentApi = contract<DocumentApiImpl>("documents");
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* A real class at runtime, so it works as an Ironbean token exactly as a
|
|
54
|
+
* hand-written abstract class would — and the implementation's own type at
|
|
55
|
+
* compile time, so the signatures live in one place. Writing them out a second
|
|
56
|
+
* time would only create somewhere for them to drift.
|
|
57
|
+
*
|
|
58
|
+
* `DocumentApiImpl` is imported *as a type*. That import is erased, so nothing
|
|
59
|
+
* of the server follows it into the browser bundle; `test/scenarios/16` exists to
|
|
60
|
+
* keep that true.
|
|
61
|
+
*
|
|
62
|
+
* The name is explicit because it is the wire identity of the service, and a
|
|
63
|
+
* class name does not survive a production browser build.
|
|
64
|
+
*/
|
|
65
|
+
function contract(name) {
|
|
66
|
+
const meta = metaFor(name);
|
|
67
|
+
if (!meta.contract) {
|
|
68
|
+
const token = class {
|
|
69
|
+
};
|
|
70
|
+
Object.defineProperty(token, "name", { value: name });
|
|
71
|
+
meta.contract = token;
|
|
72
|
+
contractsByClass.set(token, meta);
|
|
73
|
+
(0, ironbean_1.component)(token);
|
|
74
|
+
}
|
|
75
|
+
return meta.contract;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Say which service a class implements.
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* @api(DocumentApi)
|
|
82
|
+
* @component
|
|
83
|
+
* export class DocumentApiImpl {
|
|
84
|
+
* @query() byProject(projectId: string) { … }
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* The token, not its name: the name is written once, where the token is
|
|
89
|
+
* declared, and everything else refers to the token — so a typo is a compile
|
|
90
|
+
* error rather than a subscription the server never answers.
|
|
91
|
+
*
|
|
92
|
+
* The token is imported as a value here while the token's own module imports
|
|
93
|
+
* this class as a *type*. That is not a cycle at runtime: a type-only import is
|
|
94
|
+
* erased.
|
|
95
|
+
*/
|
|
96
|
+
function api(service) {
|
|
97
|
+
return (target) => {
|
|
98
|
+
const cls = target;
|
|
99
|
+
const name = contractNameOf(service);
|
|
100
|
+
const meta = metaFor(name);
|
|
101
|
+
if (meta.impl && meta.impl !== cls) {
|
|
102
|
+
throw new Error(`API "${name}" is implemented twice: "${meta.impl.name}" and "${cls.name}".`);
|
|
103
|
+
}
|
|
104
|
+
meta.impl = cls;
|
|
105
|
+
// Resolvable by its own class too, so a server component can ask for the
|
|
106
|
+
// implementation directly and a browser can ask for the name.
|
|
107
|
+
contractsByClass.set(cls, meta);
|
|
108
|
+
for (const [method, endpoint] of endpointsByImpl.get(cls) ?? []) {
|
|
109
|
+
meta.endpoints.set(method, endpoint);
|
|
110
|
+
}
|
|
111
|
+
return target;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Mark a method as a live query.
|
|
116
|
+
*
|
|
117
|
+
* The method must only read. It is re-executed whenever a table it read changes,
|
|
118
|
+
* so a write inside it would run again on every invalidation — the recording
|
|
119
|
+
* client refuses one outright rather than letting that happen quietly.
|
|
120
|
+
*/
|
|
121
|
+
function query(options = {}) {
|
|
122
|
+
return (target, propertyKey) => {
|
|
123
|
+
defineEndpoint(target, String(propertyKey), { kind: "query", query: options });
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Mark a method as a live *collection*.
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* @list()
|
|
131
|
+
* async all(projectId: string) {
|
|
132
|
+
* await this.assertMember(projectId);
|
|
133
|
+
* return this.db.document.findMany({ where: { projectId }, orderBy: … });
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* The same method a `@query` would be, with no `skip`, no `take` and no cursor —
|
|
138
|
+
* because a collection of a hundred thousand rows and a collection of nine are
|
|
139
|
+
* the same statement about what the caller may see, and only the browser knows
|
|
140
|
+
* which forty of them are on the screen right now.
|
|
141
|
+
*
|
|
142
|
+
* So the endpoint says what the collection is and the framework pages it: the
|
|
143
|
+
* browser subscribes to the windows its viewport covers, and each of those is an
|
|
144
|
+
* ordinary live query — the method run again with a `LIMIT` and an `OFFSET`
|
|
145
|
+
* pushed into its last `findMany`. Rows outside the viewport cost nothing, and
|
|
146
|
+
* the ones inside it are as live as any other query's.
|
|
147
|
+
*
|
|
148
|
+
* Read it with `useList`, which hands back the store `<GridList>` scrolls.
|
|
149
|
+
*/
|
|
150
|
+
function list(options = {}) {
|
|
151
|
+
return (target, propertyKey) => {
|
|
152
|
+
defineEndpoint(target, String(propertyKey), { kind: "list", query: options });
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/** Mark a method as a write. It runs inside one transaction, attributed to the caller. */
|
|
156
|
+
function mutation(options = {}) {
|
|
157
|
+
return (target, propertyKey) => {
|
|
158
|
+
defineEndpoint(target, String(propertyKey), { kind: "mutation", mutation: options });
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function defineEndpoint(prototype, method, partial) {
|
|
162
|
+
const impl = prototype.constructor;
|
|
163
|
+
let endpoints = endpointsByImpl.get(impl);
|
|
164
|
+
if (!endpoints) {
|
|
165
|
+
endpoints = new Map();
|
|
166
|
+
endpointsByImpl.set(impl, endpoints);
|
|
167
|
+
}
|
|
168
|
+
endpoints.set(method, { method, ...partial });
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Resolve every implementation to its contract.
|
|
172
|
+
*
|
|
173
|
+
* The link is inheritance: an implementation registers itself by carrying
|
|
174
|
+
* decorated methods, and its contract is the nearest ancestor marked with
|
|
175
|
+
* `@api`. That is why nothing has to be listed anywhere — importing the module
|
|
176
|
+
* is the registration.
|
|
177
|
+
*/
|
|
178
|
+
function resolveContracts() {
|
|
179
|
+
for (const [impl, endpoints] of endpointsByImpl) {
|
|
180
|
+
const meta = [...contractsByName.values()].find((m) => m.impl === impl);
|
|
181
|
+
if (!meta) {
|
|
182
|
+
throw new Error(`Class "${impl.name}" has @query/@mutation methods but no @api("name") ` +
|
|
183
|
+
`to say which service it implements.`);
|
|
184
|
+
}
|
|
185
|
+
for (const [method, endpoint] of endpoints) {
|
|
186
|
+
if (!meta.endpoints.has(method))
|
|
187
|
+
meta.endpoints.set(method, endpoint);
|
|
188
|
+
}
|
|
189
|
+
// Server-only services need no shared token: the implementation is one.
|
|
190
|
+
if (!meta.contract) {
|
|
191
|
+
meta.contract = impl;
|
|
192
|
+
contractsByClass.set(impl, meta);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return [...contractsByName.values()];
|
|
196
|
+
}
|
|
197
|
+
/** Contracts known to this process, whether implemented or not (the client's case). */
|
|
198
|
+
function knownContracts() {
|
|
199
|
+
return [...contractsByName.values()];
|
|
200
|
+
}
|
|
201
|
+
function contractOf(target) {
|
|
202
|
+
return contractsByClass.get(target);
|
|
203
|
+
}
|
|
204
|
+
/** The wire name of a service, from its token or from the name itself. */
|
|
205
|
+
function contractNameOf(target) {
|
|
206
|
+
if (typeof target === "string")
|
|
207
|
+
return target;
|
|
208
|
+
const meta = contractsByClass.get(target);
|
|
209
|
+
if (!meta) {
|
|
210
|
+
throw new Error(`${target.name} is not an API. Mark the implementation with @api("name"), ` +
|
|
211
|
+
`or pass the name directly.`);
|
|
212
|
+
}
|
|
213
|
+
return meta.name;
|
|
214
|
+
}
|
|
215
|
+
/** Wire name of one endpoint: `contract.method`. */
|
|
216
|
+
function endpointName(contract, method) {
|
|
217
|
+
return `${contract}.${method}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The two live queries a `@list` endpoint is served through.
|
|
221
|
+
*
|
|
222
|
+
* A list is not one subscription but a family of them — one per window the
|
|
223
|
+
* viewport covers, plus one for how many rows there are at all — and both halves
|
|
224
|
+
* have to agree on their names without either telling the other. So the names
|
|
225
|
+
* are derived, here, from the endpoint's own: the manifest announces the
|
|
226
|
+
* endpoint once, and the browser builds the same strings the server registered.
|
|
227
|
+
*
|
|
228
|
+
* The `#` is not decoration. It cannot occur in a method name, so a derived
|
|
229
|
+
* query can never collide with a declared one.
|
|
230
|
+
*/
|
|
231
|
+
function pageQuery(endpoint) {
|
|
232
|
+
return `${endpoint}#page`;
|
|
233
|
+
}
|
|
234
|
+
/** How many rows the collection has, as a live query of its own. */
|
|
235
|
+
function countQuery(endpoint) {
|
|
236
|
+
return `${endpoint}#count`;
|
|
237
|
+
}
|
|
238
|
+
function buildManifest(contracts) {
|
|
239
|
+
return {
|
|
240
|
+
contracts: contracts.map((meta) => ({
|
|
241
|
+
name: meta.name,
|
|
242
|
+
endpoints: [...meta.endpoints.values()].map(({ method, kind }) => ({ method, kind })),
|
|
243
|
+
})),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
/** Test seam: forget every registered contract. */
|
|
247
|
+
function resetContracts() {
|
|
248
|
+
contractsByName.clear();
|
|
249
|
+
contractsByClass.clear();
|
|
250
|
+
endpointsByImpl.clear();
|
|
251
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReadKeySet } from "../core/types";
|
|
2
|
+
/**
|
|
3
|
+
* The two ways an endpoint can say no.
|
|
4
|
+
*
|
|
5
|
+
* Both are *outcomes*, not failures: they travel to the client as a decision, and
|
|
6
|
+
* the engine does not report them through `onError`.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* "You may not see this."
|
|
10
|
+
*
|
|
11
|
+
* Thrown from a `@query`, it revokes the subscription instead of leaving the
|
|
12
|
+
* client with an empty result — the difference between "no documents" and "no
|
|
13
|
+
* access", which a filtered-to-nothing query cannot express.
|
|
14
|
+
*
|
|
15
|
+
* The subscription stays registered and denied, so *gaining* access later still
|
|
16
|
+
* wakes it up (nothing in the data changes when someone is added to a project,
|
|
17
|
+
* so the invalidation is the only thing that can).
|
|
18
|
+
*/
|
|
19
|
+
export declare class Forbidden extends Error {
|
|
20
|
+
readonly nowity: "forbidden";
|
|
21
|
+
/**
|
|
22
|
+
* Tables the refused execution managed to read before it gave up.
|
|
23
|
+
*
|
|
24
|
+
* Filled in by the API layer, and it matters: a denied subscription still
|
|
25
|
+
* needs to know what to watch, or being *granted* access would never wake it
|
|
26
|
+
* up. The permission table it consulted on the way to saying no is exactly
|
|
27
|
+
* the right thing to watch.
|
|
28
|
+
*/
|
|
29
|
+
tables?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* The same reads, narrowed to rows where the refused execution's own filters
|
|
32
|
+
* said which ones — so a denied subscription watches the membership row that
|
|
33
|
+
* would grant it access, not the whole table.
|
|
34
|
+
*/
|
|
35
|
+
keys?: ReadKeySet;
|
|
36
|
+
constructor(message?: string);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* "This write is refused."
|
|
40
|
+
*
|
|
41
|
+
* Thrown from a `@mutation`, it rolls the transaction back and rejects the
|
|
42
|
+
* client's promise; the optimistic effect on the client is rebased away.
|
|
43
|
+
*/
|
|
44
|
+
export declare class Rejected extends Error {
|
|
45
|
+
readonly nowity: "rejected";
|
|
46
|
+
constructor(message: string);
|
|
47
|
+
}
|
|
48
|
+
export declare function isForbidden(err: unknown): err is Forbidden;
|
|
49
|
+
export declare function isRejected(err: unknown): err is Rejected;
|
|
50
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;GAKG;AAEH;;;;;;;;;;GAUG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAChC,QAAQ,CAAC,MAAM,EAAG,WAAW,CAAU;IACvC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;gBAEN,OAAO,SAAmB;CAIzC;AAED;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAC/B,QAAQ,CAAC,MAAM,EAAG,UAAU,CAAU;gBAE1B,OAAO,EAAE,MAAM;CAI9B;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAE1D;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,QAAQ,CAExD"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Rejected = exports.Forbidden = void 0;
|
|
4
|
+
exports.isForbidden = isForbidden;
|
|
5
|
+
exports.isRejected = isRejected;
|
|
6
|
+
/**
|
|
7
|
+
* The two ways an endpoint can say no.
|
|
8
|
+
*
|
|
9
|
+
* Both are *outcomes*, not failures: they travel to the client as a decision, and
|
|
10
|
+
* the engine does not report them through `onError`.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* "You may not see this."
|
|
14
|
+
*
|
|
15
|
+
* Thrown from a `@query`, it revokes the subscription instead of leaving the
|
|
16
|
+
* client with an empty result — the difference between "no documents" and "no
|
|
17
|
+
* access", which a filtered-to-nothing query cannot express.
|
|
18
|
+
*
|
|
19
|
+
* The subscription stays registered and denied, so *gaining* access later still
|
|
20
|
+
* wakes it up (nothing in the data changes when someone is added to a project,
|
|
21
|
+
* so the invalidation is the only thing that can).
|
|
22
|
+
*/
|
|
23
|
+
class Forbidden extends Error {
|
|
24
|
+
constructor(message = "Not authorized") {
|
|
25
|
+
super(message);
|
|
26
|
+
this.nowity = "forbidden";
|
|
27
|
+
this.name = "Forbidden";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Forbidden = Forbidden;
|
|
31
|
+
/**
|
|
32
|
+
* "This write is refused."
|
|
33
|
+
*
|
|
34
|
+
* Thrown from a `@mutation`, it rolls the transaction back and rejects the
|
|
35
|
+
* client's promise; the optimistic effect on the client is rebased away.
|
|
36
|
+
*/
|
|
37
|
+
class Rejected extends Error {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.nowity = "rejected";
|
|
41
|
+
this.name = "Rejected";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Rejected = Rejected;
|
|
45
|
+
function isForbidden(err) {
|
|
46
|
+
return err instanceof Error && err.nowity === "forbidden";
|
|
47
|
+
}
|
|
48
|
+
function isRejected(err) {
|
|
49
|
+
return err instanceof Error && err.nowity === "rejected";
|
|
50
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contracts, as both entry points re-export them.
|
|
3
|
+
*
|
|
4
|
+
* They live in code that the browser bundles and the server runs, so this module
|
|
5
|
+
* is deliberately tiny and imports nothing but `ironbean` and `reflect-metadata`.
|
|
6
|
+
* Importing anything from `nowity` proper here would drag `pg` into the browser,
|
|
7
|
+
* which `test/scenarios/16` exists to prevent.
|
|
8
|
+
*
|
|
9
|
+
* Internal: an application imports from `nowity` or `nowity/client`.
|
|
10
|
+
*/
|
|
11
|
+
export { api, contract, query, list, mutation, knownContracts, contractOf, resolveContracts, resetContracts, endpointName, pageQuery, countQuery, buildManifest, type ApiManifest, type ContractMeta, type EndpointKind, type EndpointMeta, type ListOptions, type ManifestContract, type ManifestEndpoint, type MutationOptions, type QueryOptions, } from "./contract";
|
|
12
|
+
export { Forbidden, Rejected, isForbidden, isRejected } from "./errors";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,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,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRejected = exports.isForbidden = exports.Rejected = exports.Forbidden = exports.buildManifest = exports.countQuery = exports.pageQuery = exports.endpointName = exports.resetContracts = exports.resolveContracts = exports.contractOf = exports.knownContracts = exports.mutation = exports.list = exports.query = exports.contract = exports.api = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Contracts, as both entry points re-export them.
|
|
6
|
+
*
|
|
7
|
+
* They live in code that the browser bundles and the server runs, so this module
|
|
8
|
+
* is deliberately tiny and imports nothing but `ironbean` and `reflect-metadata`.
|
|
9
|
+
* Importing anything from `nowity` proper here would drag `pg` into the browser,
|
|
10
|
+
* which `test/scenarios/16` exists to prevent.
|
|
11
|
+
*
|
|
12
|
+
* Internal: an application imports from `nowity` or `nowity/client`.
|
|
13
|
+
*/
|
|
14
|
+
var contract_1 = require("./contract");
|
|
15
|
+
Object.defineProperty(exports, "api", { enumerable: true, get: function () { return contract_1.api; } });
|
|
16
|
+
Object.defineProperty(exports, "contract", { enumerable: true, get: function () { return contract_1.contract; } });
|
|
17
|
+
Object.defineProperty(exports, "query", { enumerable: true, get: function () { return contract_1.query; } });
|
|
18
|
+
Object.defineProperty(exports, "list", { enumerable: true, get: function () { return contract_1.list; } });
|
|
19
|
+
Object.defineProperty(exports, "mutation", { enumerable: true, get: function () { return contract_1.mutation; } });
|
|
20
|
+
Object.defineProperty(exports, "knownContracts", { enumerable: true, get: function () { return contract_1.knownContracts; } });
|
|
21
|
+
Object.defineProperty(exports, "contractOf", { enumerable: true, get: function () { return contract_1.contractOf; } });
|
|
22
|
+
Object.defineProperty(exports, "resolveContracts", { enumerable: true, get: function () { return contract_1.resolveContracts; } });
|
|
23
|
+
Object.defineProperty(exports, "resetContracts", { enumerable: true, get: function () { return contract_1.resetContracts; } });
|
|
24
|
+
Object.defineProperty(exports, "endpointName", { enumerable: true, get: function () { return contract_1.endpointName; } });
|
|
25
|
+
Object.defineProperty(exports, "pageQuery", { enumerable: true, get: function () { return contract_1.pageQuery; } });
|
|
26
|
+
Object.defineProperty(exports, "countQuery", { enumerable: true, get: function () { return contract_1.countQuery; } });
|
|
27
|
+
Object.defineProperty(exports, "buildManifest", { enumerable: true, get: function () { return contract_1.buildManifest; } });
|
|
28
|
+
var errors_1 = require("./errors");
|
|
29
|
+
Object.defineProperty(exports, "Forbidden", { enumerable: true, get: function () { return errors_1.Forbidden; } });
|
|
30
|
+
Object.defineProperty(exports, "Rejected", { enumerable: true, get: function () { return errors_1.Rejected; } });
|
|
31
|
+
Object.defineProperty(exports, "isForbidden", { enumerable: true, get: function () { return errors_1.isForbidden; } });
|
|
32
|
+
Object.defineProperty(exports, "isRejected", { enumerable: true, get: function () { return errors_1.isRejected; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { EntityId, Row, RowPatch } from "../core/types";
|
|
2
|
+
/**
|
|
3
|
+
* The server-authoritative state of the client, as plain data.
|
|
4
|
+
*
|
|
5
|
+
* This is deliberately *not* the MobX layer. Optimistic mutations are replayed on
|
|
6
|
+
* top of this on every rebase, so it has to stay untouched by local writes —
|
|
7
|
+
* otherwise a rejected mutation could never be undone.
|
|
8
|
+
*
|
|
9
|
+
* Rows are shared between subscriptions and reference-counted: two live queries
|
|
10
|
+
* returning the same document hold one row, and the row survives until the last
|
|
11
|
+
* of them stops referencing it.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ConfirmedStore {
|
|
14
|
+
private readonly rows;
|
|
15
|
+
private readonly refs;
|
|
16
|
+
/** subId → entity → referenced ids, so a snapshot can release the old set. */
|
|
17
|
+
private readonly bySub;
|
|
18
|
+
entities(): string[];
|
|
19
|
+
rowsOf(entity: string): Map<EntityId, Row>;
|
|
20
|
+
get(entity: string, id: EntityId): Row | undefined;
|
|
21
|
+
/** Replace everything `subId` holds for `entity`. */
|
|
22
|
+
setSnapshot(subId: string, entity: string, rows: Row[], idField: string): void;
|
|
23
|
+
applyUpsert(subId: string, entity: string, patches: RowPatch[]): void;
|
|
24
|
+
applyRemove(subId: string, entity: string, ids: EntityId[]): void;
|
|
25
|
+
/** Drop every row held only by this subscription. */
|
|
26
|
+
releaseSub(subId: string): void;
|
|
27
|
+
clear(): void;
|
|
28
|
+
private rowMap;
|
|
29
|
+
private subEntity;
|
|
30
|
+
private retain;
|
|
31
|
+
private release;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=confirmed-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmed-store.d.ts","sourceRoot":"","sources":["../../src/client/confirmed-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAyC;IAC9D,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiD;IACtE,8EAA8E;IAC9E,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiD;IAEvE,QAAQ,IAAI,MAAM,EAAE;IAIpB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC;IAI1C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,GAAG,GAAG,SAAS;IAIlD,qDAAqD;IACrD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAgB9E,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,IAAI;IASrE,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI;IAIjE,qDAAqD;IACrD,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAS/B,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,MAAM;IAed,OAAO,CAAC,OAAO;CAUlB"}
|