@shivaedev/contract 0.57.0 → 0.58.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/CHANGELOG.md +8 -0
- package/README.md +8 -8
- package/dist/clientContract.d.ts +2 -15
- package/dist/clientContract.d.ts.map +1 -1
- package/dist/clientContract.js +6 -11
- package/dist/clientContract.js.map +1 -1
- package/package.json +6 -6
- package/src/clientContract.ts +12 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.58.0 - 2026-11-21
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- a browser contract built by `clientContract` carries no keys. Its definition names the module's queries and commands as lists, `queries: ["list"]` and `commands: ["create"]`, in place of records holding each query's `reads` and `readsCollections` and each command's `invalidates`, so `ClientContractDefinition`'s `queries` and `commands` are now `readonly string[]`. The host serves the module, whose keys decide which open queries a change reaches, and the browser's queries refresh from the server's announcements. An application runs `pnpm generate` and deletes nothing by hand; only a hand-written `clientContract` call changes, by replacing each record with the list of its operation names.
|
|
8
|
+
- `makeClient`'s `bearerToken` is an `Effect.Effect<string | null>` that the client runs each time its socket connects, instead of a fixed string. A credential Effect that answers `null` connects without the authentication frame. Replace `bearerToken: token` with `bearerToken: Effect.succeed(token)`; a native shell passes `Effect.provide(storedCredential, credentialLayer)` from identity.
|
|
9
|
+
- `authenticateSocket` from `@shivaedev/contract/socketAuthentication.ts` takes the socket URL, the credential Effect and optional upgrade headers and opens the WebSocket itself, adding `auth=frame` when a credential is sent. Replace `Layer.effect(Socket.Socket, authenticateSocket(token)).pipe(Layer.provide(Socket.layerWebSocket(framedUrl)))` with `Layer.effect(Socket.Socket, authenticateSocket(url, Effect.succeed(token)))` on the URL without `auth=frame`, provided with a `WebSocketConstructor`.
|
|
10
|
+
|
|
3
11
|
## 0.57.0 - 2026-11-21
|
|
4
12
|
|
|
5
13
|
### Fixed
|
package/README.md
CHANGED
|
@@ -202,7 +202,7 @@ Each operation runs in a span named after the module and the operation, such as
|
|
|
202
202
|
|
|
203
203
|
Types are erased, so the success schema and rejection classes the server encodes with and the browser decodes with must exist as values. [`@shivaedev/build`](https://github.com/ShivaeDev/platform/tree/main/packages/build) writes them from each module's `run` types into one file per module under `src/generated/`, which stays out of Git; an application runs it as `pnpm generate`. The module file passes its wire, as `Notes` does above, and every operation is served with its wire entry's success and rejections, plus `InternalServerError` and `ServiceUnavailable`. A wire entry's success describes only the shape: its RPC carries `GeneratedSuccess` from `@shivaedev/errors/GeneratedSuccess.ts`, so the host neither collects sensitive names from it nor treats its fields as public. Mark a sensitive field on the server's model instead, as the [errors README](https://github.com/ShivaeDev/platform/tree/main/packages/errors#masking-secrets-in-failures) describes.
|
|
204
204
|
|
|
205
|
-
The file the generator writes exports the wire, the browser's contract built by `clientContract` from the wire, the
|
|
205
|
+
The file the generator writes exports the wire, the browser's contract built by `clientContract` from the wire, the names of the module's queries and commands, the copied payloads, and the module's name, middleware, subject and key scope, and it ends with a type-level assertion that the browser's contract and the server module have the same RPCs:
|
|
206
206
|
|
|
207
207
|
```ts
|
|
208
208
|
import { Schema } from "effect";
|
|
@@ -210,7 +210,7 @@ import { Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
|
210
210
|
import { clientContract } from "@shivaedev/contract/clientContract.ts";
|
|
211
211
|
import type { ClientMatchesModule } from "@shivaedev/contract/clientMatchesModule.ts";
|
|
212
212
|
import type { Notes as NotesModule } from "#modules/notes/Notes.ts";
|
|
213
|
-
import { Caller, NoteFields,
|
|
213
|
+
import { Caller, NoteFields, TitleTaken } from "#modules/notes/model.ts";
|
|
214
214
|
|
|
215
215
|
const Note = Schema.Struct({ createdAt: Schema.Date, id: Schema.Number, title: Schema.String });
|
|
216
216
|
|
|
@@ -220,24 +220,24 @@ export const notesWire = {
|
|
|
220
220
|
} as const;
|
|
221
221
|
|
|
222
222
|
export const Notes = clientContract({
|
|
223
|
-
commands:
|
|
223
|
+
commands: ["create"],
|
|
224
224
|
middleware: Caller,
|
|
225
225
|
name: "notes",
|
|
226
226
|
payloads: { create: NoteFields },
|
|
227
|
-
queries:
|
|
227
|
+
queries: ["list"],
|
|
228
228
|
wire: notesWire,
|
|
229
229
|
});
|
|
230
230
|
|
|
231
231
|
export const notesMatchModule: ClientMatchesModule<typeof Notes, typeof NotesModule> = true;
|
|
232
232
|
```
|
|
233
233
|
|
|
234
|
-
`clientContract` requires a wire entry for every query and command it
|
|
234
|
+
`clientContract` requires a wire entry for every query and command it names. The browser imports `Notes` from that file and puts it in its client's record like any contract; it carries no `run`, read policy, key or service, and its import graph reaches no server code. Its queries read no keys and its commands invalidate none: the host serves the module, whose keys decide which open queries each change reaches, and the browser's queries refresh from the server's announcements. Over RPC's JSON serialization, a `Schema.Date` field arrives as a `Date` equal to the one `run` returned, and a rejection the wire lists arrives as its class. Neither the browser's contract nor an operation without a read policy can be served: `contract()` requires one on every query, and a host refuses a query without one at start-up.
|
|
235
235
|
|
|
236
236
|
The compiler compares the wire with `run` on every type check, and a stale file is an error on the module's `name` line that names the operation, one problem per operation: `WireSuccessStale` when the entry's success differs from what `run` returns, `WireRejectionsStale` when its rejection tags or classes differ from what `run` and a query's read policy raise, other than infrastructure failures, and `OperationMissingFromWire` when an operation has no entry and its `run` returns a value or raises a rejection. A success differs when its type and `run`'s return type are not mutually assignable; when they differ only in array mutability, because `Schema.Array` decodes a readonly array; when an object that `run` returns and a `Schema.Struct` that the success holds in the same position, at the top or in an array, struct field, tuple, record, union or `Option`, have different keys, such as an optional property only one of them has, which the `Struct` would drop or never send; and when the success holds a `Schema.Class` in such a position and `run` returns something other than that class there, such as an object literal of its fields, which fails to encode. Rejections differ when `run` raises a tag the entry does not list, the entry lists a tag nothing raises or one of the automatic two, or a listed class and the class `run` raises under the same tag differ in shape, such as a local `NotFound` with other fields than the shared one.
|
|
237
237
|
|
|
238
238
|
TypeScript compares classes by shape, so two cases still compile: a rejection class whose twin of the same shape is what `run` raises, and a helper typed to return a readonly interface of the same shape where the success is a `Schema.Class`. Neither is silent at run time: the twin is not the listed class, so the boundary answers `InternalServerError` and reports it, and the plain object fails to encode. The generator resolves both by declaration. A `Schema.Struct` behind another schema, such as a transformation, a brand or `Schema.suspend`, is compared with `run` only by mutual assignability, so an optional property that only one side has still compiles there and is dropped or never sent.
|
|
239
239
|
|
|
240
|
-
The browser's assertion fails with `ClientDiffersFromModule`, naming the operations whose RPCs differ. `ClientMatchesModule` compares the operations
|
|
240
|
+
The browser's assertion fails with `ClientDiffersFromModule`, naming the operations whose RPCs differ. `ClientMatchesModule` compares the operations, their kinds and their payloads, successes and rejections, so a browser contract that leaves out an operation, declares a command as a query or carries a stale payload fails. A stale key scope in the generated file still compiles; the generator keeps it current, because a change to it makes `shivaedev-build generate --check` report the file stale. A stale wire and a stale browser contract read:
|
|
241
241
|
|
|
242
242
|
```
|
|
243
243
|
src/test-support/fixtures/invalid/moduleStaleRejection.ts(9,2): error TS2322: Type '"staleRejection"' is not assignable to type '"staleRejection" & NoInfer<WireRejectionsStale<"create", "the generated file is stale; run pnpm generate", "TitleTaken" | "Unauthorized", "Unauthorized">>'.
|
|
@@ -569,7 +569,7 @@ const move = ({ id, household }) =>
|
|
|
569
569
|
|
|
570
570
|
Here `audienceFor` reads household members and people who ate from the pot from the application's database, `movePot` performs the write, and `pots` declares a `viewerId` bucket. Read the audience after the write to include new readers, and retain the old audience when the write removes access. Each viewer's list reads its own bucket. Keep these reads and the write in the same transaction when they must describe one change.
|
|
571
571
|
|
|
572
|
-
Use this helper in hosts from `@shivaedev/server`, or a native RPC host wired with `guardCommands` and `commandGuardLayer`. Keys are isolated per command, deduplicated with declared keys, and published through the existing `@shivaedev/changes` command publication boundary after success. A failed handler discards them. They
|
|
572
|
+
Use this helper in hosts from `@shivaedev/server`, or a native RPC host wired with `guardCommands` and `commandGuardLayer`. Keys are isolated per command, deduplicated with declared keys, and published through the existing `@shivaedev/changes` command publication boundary after success. A failed handler discards them. They are published only on the server and never reach the browser; live subscriptions receive the server’s changed query results.
|
|
573
573
|
|
|
574
574
|
#### When a command's change is on the screen
|
|
575
575
|
|
|
@@ -775,7 +775,7 @@ The application supplies the permission checker through `permissionReadPolicy(pe
|
|
|
775
775
|
|
|
776
776
|
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`; record and bucket reads also use plain server keys. They add no wildcard matching or write-side work. Every committed repository insert, update, delete, upsert and bulk write already publishes that key. Generated-id inserts also publish the bare collection key alongside their generated record key, so `publishes` stories that check exact published keys must allow the bare key today. For a table named `notes`, that is `"notes"` alongside `"notes:<id>"` and any affected bucket keys. Mounting a collection subscriber adds **zero PostgreSQL NOTIFY messages per write**: it consumes the existing payloads. It adds a normal query subscription and an authorized reread when the collection changes.
|
|
777
777
|
|
|
778
|
-
For dependencies that need server data, add `serverReads(payload, viewer)`, an Effect returning extra keys.
|
|
778
|
+
For dependencies that need server data, add `serverReads(payload, viewer)`, an Effect returning extra keys. `reads` holds the keys that follow from the payload and the viewer alone, or returns `[]`; `serverReads` holds the keys that need server data. The server checks every referenced query's policy before it runs any `serverReads`, and resolves it with the owning query handler's services. Declare its failures in the query's `rejections`, as with policy failures. A denied subscription never runs the resolver.
|
|
779
779
|
|
|
780
780
|
```ts
|
|
781
781
|
import { Context, Effect, Schema } from "effect";
|
package/dist/clientContract.d.ts
CHANGED
|
@@ -17,15 +17,6 @@ type Payloads<TWire> = {
|
|
|
17
17
|
};
|
|
18
18
|
type PayloadOf<TPayloads, TOperation> = PayloadSchema<TOperation extends keyof TPayloads ? NonNullable<TPayloads[TOperation]> : Schema.Void>;
|
|
19
19
|
type EntryOf<TWire, TOperation> = TOperation extends keyof TWire ? (TWire[TOperation] extends WireEntry ? TWire[TOperation] : never) : never;
|
|
20
|
-
interface QueryKeys<TPayload> {
|
|
21
|
-
readonly reads: (payload: TPayload, viewer: Option.Option<Viewer>) => readonly Key[];
|
|
22
|
-
readonly readsCollections?: readonly {
|
|
23
|
-
readonly name: string;
|
|
24
|
-
}[];
|
|
25
|
-
}
|
|
26
|
-
interface CommandKeys<TPayload> {
|
|
27
|
-
readonly invalidates?: (payload: TPayload, viewer?: Option.Option<Viewer>) => readonly Key[];
|
|
28
|
-
}
|
|
29
20
|
type ClientQueries<TWire, TPayloads, TQueries extends string> = {
|
|
30
21
|
readonly [TOperation in TQueries]: ClientQuery<TOperation, PayloadOf<TPayloads, TOperation>, EntryOf<TWire, TOperation>["success"], SpecsOf<EntryOf<TWire, TOperation>["rejections"]>>;
|
|
31
22
|
}[TQueries];
|
|
@@ -33,16 +24,12 @@ type ClientCommands<TWire, TPayloads, TCommands extends string> = {
|
|
|
33
24
|
readonly [TOperation in TCommands]: Command<TOperation, PayloadOf<TPayloads, TOperation>, EntryOf<TWire, TOperation>["success"], SpecsOf<EntryOf<TWire, TOperation>["rejections"]>>;
|
|
34
25
|
}[TCommands];
|
|
35
26
|
export interface ClientContractDefinition<TName extends string, TWire extends Wire, TPayloads extends Payloads<TWire>, TQueries extends keyof TWire & string, TCommands extends keyof TWire & string, TMiddleware extends RpcMiddleware.AnyService, TSubject extends SubjectDeclaration | undefined, TScope extends "session" | undefined> {
|
|
36
|
-
readonly commands?:
|
|
37
|
-
readonly [TOperation in TCommands]: CommandKeys<PayloadOf<TPayloads, TOperation>["Type"]>;
|
|
38
|
-
};
|
|
27
|
+
readonly commands?: readonly TCommands[];
|
|
39
28
|
readonly keyScope?: TScope;
|
|
40
29
|
readonly middleware?: TMiddleware;
|
|
41
30
|
readonly name: TName;
|
|
42
31
|
readonly payloads?: TPayloads;
|
|
43
|
-
readonly queries?:
|
|
44
|
-
readonly [TOperation in TQueries]: QueryKeys<PayloadOf<TPayloads, TOperation>["Type"]>;
|
|
45
|
-
};
|
|
32
|
+
readonly queries?: readonly TQueries[];
|
|
46
33
|
readonly subject?: TSubject;
|
|
47
34
|
readonly wire: TWire;
|
|
48
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1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KAAK,GAAG,MAAM,GAAG,KAAK,EAC7C,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,GAAG,KAAK,EAC9C,WAAW,SAAS,aAAa,CAAC,UAAU,GAAG,KAAK,EACpD,KAAK,CAAC,QAAQ,SAAS,kBAAkB,GAAG,SAAS,GAAG,SAAS,EACjE,KAAK,CAAC,MAAM,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS,EAEtD,UAAU,EAAE,wBAAwB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,GAC/G,cAAc,CAChB,KAAK,EACL,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,EACpG,WAAW,EACX,QAAQ,EACR,MAAM,CACN,CAAC"}
|
package/dist/clientContract.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { declaredGroup } from "#contract.ts";
|
|
2
2
|
import { operation } from "#operationDeclaration.ts";
|
|
3
3
|
import { wireRejections } from "#wire.ts";
|
|
4
|
+
function noKeys() {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
4
7
|
export function clientContract(definition) {
|
|
5
8
|
function declared(name) {
|
|
6
9
|
const entry = definition.wire[name];
|
|
@@ -10,17 +13,9 @@ export function clientContract(definition) {
|
|
|
10
13
|
...(entry === undefined ? {} : { rejections: wireRejections(entry.rejections), success: entry.success }),
|
|
11
14
|
};
|
|
12
15
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
...operation("query", name, declared(name)),
|
|
17
|
-
reads: (payload, viewer) => [...reads(payload, viewer), ...collections],
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
const commands = Object.entries(definition.commands ?? {}).map(([name, { invalidates }]) => ({
|
|
21
|
-
...operation("command", name, declared(name)),
|
|
22
|
-
invalidates: (payload, _result, viewer) => invalidates?.(payload, viewer) ?? [],
|
|
23
|
-
}));
|
|
16
|
+
// The server's module declares the keys and announces the changes; an operation's shape still names them, so the browser's are empty.
|
|
17
|
+
const queries = (definition.queries ?? []).map((name) => ({ ...operation("query", name, declared(name)), reads: noKeys }));
|
|
18
|
+
const commands = (definition.commands ?? []).map((name) => ({ ...operation("command", name, declared(name)), invalidates: noKeys }));
|
|
24
19
|
const group = declaredGroup(definition.name, {
|
|
25
20
|
commands,
|
|
26
21
|
queries,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientContract.js","sourceRoot":"","sources":["../src/clientContract.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAKrD,OAAO,EAA6B,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"clientContract.js","sourceRoot":"","sources":["../src/clientContract.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAKrD,OAAO,EAA6B,cAAc,EAAE,MAAM,UAAU,CAAC;AAkDrE,SAAS,MAAM;IACd,OAAO,EAAE,CAAC;AACX,CAAC;AAqBD,MAAM,UAAU,cAAc,CAAC,UAS9B;IACA,SAAS,QAAQ,CAAC,IAAY;QAC7B,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO;YACN,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC;YAC7C,GAAG,CAAC,KAAK,KAAK,SAA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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.0",
|
|
4
4
|
"description": "Typed query and command contracts over native Effect RPC and reactivity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@effect/platform-node": "4.1.4",
|
|
53
53
|
"@effect/vitest": "4.1.4",
|
|
54
|
-
"@shivaedev/identity": "0.
|
|
55
|
-
"@shivaedev/quality": "0.83.
|
|
56
|
-
"@shivaedev/server": "0.
|
|
54
|
+
"@shivaedev/identity": "0.39.0",
|
|
55
|
+
"@shivaedev/quality": "0.83.3",
|
|
56
|
+
"@shivaedev/server": "0.42.0",
|
|
57
57
|
"@shivaedev/sql": "0.54.0",
|
|
58
|
-
"@shivaedev/test-kits": "0.16.
|
|
58
|
+
"@shivaedev/test-kits": "0.16.4",
|
|
59
59
|
"@shivaedev/test-sql": "0.26.0",
|
|
60
|
-
"@shivaedev/test-story": "0.52.
|
|
60
|
+
"@shivaedev/test-story": "0.52.4",
|
|
61
61
|
"@types/node": "24.19.2",
|
|
62
62
|
"effect": "4.1.4",
|
|
63
63
|
"fake-indexeddb": "6.2.8",
|
package/src/clientContract.ts
CHANGED
|
@@ -21,15 +21,6 @@ type Payloads<TWire> = { readonly [TOperation in keyof TWire]?: Schema.Top | Sch
|
|
|
21
21
|
type PayloadOf<TPayloads, TOperation> = PayloadSchema<TOperation extends keyof TPayloads ? NonNullable<TPayloads[TOperation]> : Schema.Void>;
|
|
22
22
|
type EntryOf<TWire, TOperation> = TOperation extends keyof TWire ? (TWire[TOperation] extends WireEntry ? TWire[TOperation] : never) : never;
|
|
23
23
|
|
|
24
|
-
interface QueryKeys<TPayload> {
|
|
25
|
-
readonly reads: (payload: TPayload, viewer: Option.Option<Viewer>) => readonly Key[];
|
|
26
|
-
readonly readsCollections?: readonly { readonly name: string }[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface CommandKeys<TPayload> {
|
|
30
|
-
readonly invalidates?: (payload: TPayload, viewer?: Option.Option<Viewer>) => readonly Key[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
24
|
type ClientQueries<TWire, TPayloads, TQueries extends string> = {
|
|
34
25
|
readonly [TOperation in TQueries]: ClientQuery<
|
|
35
26
|
TOperation,
|
|
@@ -58,19 +49,21 @@ export interface ClientContractDefinition<
|
|
|
58
49
|
TSubject extends SubjectDeclaration | undefined,
|
|
59
50
|
TScope extends "session" | undefined,
|
|
60
51
|
> {
|
|
61
|
-
readonly commands?:
|
|
62
|
-
readonly [TOperation in TCommands]: CommandKeys<PayloadOf<TPayloads, TOperation>["Type"]>;
|
|
63
|
-
};
|
|
52
|
+
readonly commands?: readonly TCommands[];
|
|
64
53
|
readonly keyScope?: TScope;
|
|
65
54
|
readonly middleware?: TMiddleware;
|
|
66
55
|
readonly name: TName;
|
|
67
56
|
readonly payloads?: TPayloads;
|
|
68
|
-
readonly queries?:
|
|
57
|
+
readonly queries?: readonly TQueries[];
|
|
69
58
|
readonly subject?: TSubject;
|
|
70
59
|
readonly wire: TWire;
|
|
71
60
|
}
|
|
72
61
|
|
|
73
|
-
|
|
62
|
+
function noKeys(): readonly Key[] {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Written by the generator: what the browser needs of a module as values, without its run, read policy, keys or services.
|
|
74
67
|
export function clientContract<
|
|
75
68
|
const TName extends string,
|
|
76
69
|
const TWire extends Wire,
|
|
@@ -90,12 +83,12 @@ export function clientContract<
|
|
|
90
83
|
TScope
|
|
91
84
|
>;
|
|
92
85
|
export function clientContract(definition: {
|
|
93
|
-
readonly commands?:
|
|
86
|
+
readonly commands?: readonly string[];
|
|
94
87
|
readonly keyScope?: "session";
|
|
95
88
|
readonly middleware?: RpcMiddleware.AnyService;
|
|
96
89
|
readonly name: string;
|
|
97
90
|
readonly payloads?: { readonly [operation: string]: Schema.Top | Schema.Struct.Fields | undefined };
|
|
98
|
-
readonly queries?:
|
|
91
|
+
readonly queries?: readonly string[];
|
|
99
92
|
readonly subject?: SubjectDeclaration;
|
|
100
93
|
readonly wire: Wire;
|
|
101
94
|
}): unknown {
|
|
@@ -107,17 +100,9 @@ export function clientContract(definition: {
|
|
|
107
100
|
...(entry === undefined ? {} : { rejections: wireRejections(entry.rejections), success: entry.success }),
|
|
108
101
|
};
|
|
109
102
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
...operation("query", name, declared(name)),
|
|
114
|
-
reads: (payload: unknown, viewer: Option.Option<Viewer>) => [...reads(payload, viewer), ...collections],
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
const commands = Object.entries(definition.commands ?? {}).map(([name, { invalidates }]) => ({
|
|
118
|
-
...operation("command", name, declared(name)),
|
|
119
|
-
invalidates: (payload: unknown, _result: unknown, viewer?: Option.Option<Viewer>) => invalidates?.(payload, viewer) ?? [],
|
|
120
|
-
}));
|
|
103
|
+
// The server's module declares the keys and announces the changes; an operation's shape still names them, so the browser's are empty.
|
|
104
|
+
const queries = (definition.queries ?? []).map((name) => ({ ...operation("query", name, declared(name)), reads: noKeys }));
|
|
105
|
+
const commands = (definition.commands ?? []).map((name) => ({ ...operation("command", name, declared(name)), invalidates: noKeys }));
|
|
121
106
|
const group = declaredGroup(definition.name, {
|
|
122
107
|
commands,
|
|
123
108
|
queries,
|