@shivaedev/contract 0.43.2 → 0.43.3
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 +6 -0
- package/README.md +2 -2
- package/dist/automaticLive.d.ts +1 -1
- package/dist/automaticLive.d.ts.map +1 -1
- package/dist/automaticLive.js +11 -13
- package/dist/automaticLive.js.map +1 -1
- package/dist/automaticQuery.d.ts +4 -4
- package/dist/automaticQuery.d.ts.map +1 -1
- package/dist/automaticQuery.js +7 -2
- package/dist/automaticQuery.js.map +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +5 -7
- package/dist/contract.js.map +1 -1
- package/dist/declarationError.d.ts +2 -0
- package/dist/declarationError.d.ts.map +1 -1
- package/dist/declarationError.js +2 -0
- package/dist/declarationError.js.map +1 -1
- package/dist/prependMiddleware.d.ts +2 -8
- package/dist/prependMiddleware.d.ts.map +1 -1
- package/dist/prependMiddleware.js +25 -8
- package/dist/prependMiddleware.js.map +1 -1
- package/dist/validateReadPolicies.d.ts.map +1 -1
- package/dist/validateReadPolicies.js +5 -0
- package/dist/validateReadPolicies.js.map +1 -1
- package/package.json +8 -9
- package/src/automaticLive.ts +16 -13
- package/src/automaticQuery.ts +8 -5
- package/src/contract.ts +5 -7
- package/src/declarationError.ts +3 -0
- package/src/prependMiddleware.ts +28 -11
- package/src/validateReadPolicies.ts +5 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ Save this module as `notes.ts`. The payload can be struct fields, as in `Get`, o
|
|
|
86
86
|
|
|
87
87
|
The collection's ID schema gives `item` its ID type. Here, `notes.item` takes a number. Query and command callbacks retain their payload and result types, including when the operations are declared inline inside `contract`.
|
|
88
88
|
|
|
89
|
-
Operation names must differ within a contract, including across queries, commands and streams. Literal duplicate declarations fail compilation. If the compiler cannot see the names in an array,
|
|
89
|
+
Operation names must differ within a contract, including across queries, commands and streams. Literal duplicate declarations fail compilation. If the compiler cannot see the names in an array, the server reports duplicate names as an Effect defect while validating the contract during host startup.
|
|
90
90
|
|
|
91
91
|
The native RPC mapping types `OperationRpc` and `Tag` are exported from `@shivaedev/contract/operationRpc.ts`.
|
|
92
92
|
|
|
@@ -483,7 +483,7 @@ const AllNotes = query("allNotes", {
|
|
|
483
483
|
});
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
-
The application supplies the permission checker through `permissionReadPolicy(permission, check)`; `check` receives that permission and the current viewer, and must check the viewer's grant using server services. Its failures and service requirements flow through the query like any other read policy. Supply `SessionUser` with the application's identity middleware. The policy guards both calls and subscriptions, and runs again before queries rerun. `readsCollections` requires this policy at declaration: a `signedIn` or ordinary boolean policy fails TypeScript checking, and
|
|
486
|
+
The application supplies the permission checker through `permissionReadPolicy(permission, check)`; `check` receives that permission and the current viewer, and must check the viewer's grant using server services. Its failures and service requirements flow through the query like any other read policy. Supply `SessionUser` with the application's identity middleware. The policy guards both calls and subscriptions, and runs again before queries rerun. `readsCollections` requires this policy at declaration: a `signedIn` or ordinary boolean policy fails TypeScript checking, and the server reports an untyped declaration with that policy as an Effect defect during host startup. The server also refuses collection queries changed to an ordinary policy after construction as `QueryReadDenied`. Tenant-facing queries use `notes.bucket.userId(viewerId)` instead.
|
|
487
487
|
|
|
488
488
|
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.
|
|
489
489
|
|
package/dist/automaticLive.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type ChangesClient = AtomRpc.AtomRpcClient<unknown, string, Rpc.Rpc<`${st
|
|
|
26
26
|
}>>;
|
|
27
27
|
}>, RpcSchema.Stream<Schema.Schema<QueryUpdate>, Schema.Unknown>, Schema.Never>>;
|
|
28
28
|
export declare function automaticLive(service: ChangesClient, name: string, owner?: BindingOwner, resume?: ResumeSource, enabled?: boolean, resumeWindow?: ResumeWindow): {
|
|
29
|
-
query: <A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, reference: QueryReference, keys: readonly Key[], equivalent: (left: A, right: A) => boolean, decode: (value: unknown) => A, reactive: (source: Atom.Atom<AsyncResult.AsyncResult<A, E>>) => Atom.Atom<AsyncResult.AsyncResult<A, E>>, headers?: Headers.Input) =>
|
|
29
|
+
query: <A, E>(atom: Atom.Atom<AsyncResult.AsyncResult<A, E>>, reference: QueryReference, keys: readonly Key[], equivalent: (left: A, right: A) => boolean, decode: (value: unknown) => A, reactive: (source: Atom.Atom<AsyncResult.AsyncResult<A, E>>) => Atom.Atom<AsyncResult.AsyncResult<A, E>>, headers?: Headers.Input) => any;
|
|
30
30
|
subscription: {
|
|
31
31
|
connection: Atom.Atom<LiveStatus<unknown>>;
|
|
32
32
|
identity: Atom.Writable<string | undefined, string | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticLive.d.ts","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"automaticLive.d.ts","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,MAAM,EAAU,MAAM,QAAQ,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,KAAK,OAAO,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS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AW,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,EAC5D,MAAM,CAAC,KAAK,CACZ,CACD,CAAC;AAEF,wBAAgB,aAAa,CAC5B,OAAO,EAAE,aAAa,EACtB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,OAAO,UAAO,EACd,YAAY,CAAC,EAAE,YAAY;YAkBZ,CAAC,EAAE,CAAC,QACZ,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aACnC,cAAc,QACnB,SAAS,GAAG,EAAE,cACR,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,UAClC,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,YACnB,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAC9F,OAAO,CAAC,KAAK;;;;;;;EAuCxB"}
|
package/dist/automaticLive.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Stream } from "effect";
|
|
1
|
+
import { Cause, Effect, Option, Stream } from "effect";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
3
|
import { aggregateLiveStatus } from "#aggregateLiveStatus.ts";
|
|
4
4
|
import { automaticQuery } from "#automaticQuery.ts";
|
|
@@ -12,10 +12,8 @@ import { socketIdentity } from "#rpcClient.ts";
|
|
|
12
12
|
export const LiveConnection = Symbol.for("@shivaedev/contract/LiveConnection");
|
|
13
13
|
const pausedByRuntime = Atom.family((_runtime) => Atom.keepAlive(Atom.make(false)));
|
|
14
14
|
export function automaticLive(service, name, owner, resume, enabled = true, resumeWindow) {
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
throw new Error("A session-scoped query belongs to its binding registry");
|
|
18
|
-
}
|
|
15
|
+
function ownerFailure(get) {
|
|
16
|
+
return owner !== undefined && owner.registry !== get.registry ? new Error("A session-scoped query belongs to its binding registry") : undefined;
|
|
19
17
|
}
|
|
20
18
|
const paused = pausedByRuntime(service.runtime);
|
|
21
19
|
const statuses = Atom.make(new Map());
|
|
@@ -23,7 +21,10 @@ export function automaticLive(service, name, owner, resume, enabled = true, resu
|
|
|
23
21
|
const target = resumeWindow ?? (typeof window === "undefined" ? undefined : window);
|
|
24
22
|
const signal = resumeSignal({ ...(target === undefined ? {} : { window: target }), ...(resume === undefined ? {} : { native: resume }) });
|
|
25
23
|
const connection = Atom.make((get) => {
|
|
26
|
-
|
|
24
|
+
const error = ownerFailure(get);
|
|
25
|
+
if (error !== undefined) {
|
|
26
|
+
return { connection: "failed", failure: Option.some(Cause.die(error)), needsResync: true, pending: 0 };
|
|
27
|
+
}
|
|
27
28
|
get.mount(service.runtime);
|
|
28
29
|
return get(status);
|
|
29
30
|
}).pipe(Atom.setIdleTTL(0));
|
|
@@ -42,9 +43,9 @@ export function automaticLive(service, name, owner, resume, enabled = true, resu
|
|
|
42
43
|
stream: Stream.unwrap(service.use((client) => Effect.succeed(client(`${name}.$changes`, { queries: [reference] }, { headers })))).pipe(delivery.stream),
|
|
43
44
|
});
|
|
44
45
|
const gated = automaticQuery({
|
|
45
|
-
assertOwner,
|
|
46
46
|
clientStatuses: clientActivities.get(service)?.statuses,
|
|
47
47
|
equivalent,
|
|
48
|
+
ownerFailure,
|
|
48
49
|
paused,
|
|
49
50
|
ready,
|
|
50
51
|
signals,
|
|
@@ -53,12 +54,9 @@ export function automaticLive(service, name, owner, resume, enabled = true, resu
|
|
|
53
54
|
subscription,
|
|
54
55
|
subscriptionVersion: delivery.updates,
|
|
55
56
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Object.assign(gated, { [Atom.SerializableTypeId]: atom[Atom.SerializableTypeId] });
|
|
60
|
-
}
|
|
61
|
-
return gated;
|
|
57
|
+
const result = Object.assign(Object.create(Object.getPrototypeOf(gated)), gated, { initialValueTarget: atom }, Atom.isSerializable(atom) ? { [Atom.SerializableTypeId]: atom[Atom.SerializableTypeId] } : {});
|
|
58
|
+
shareQuerySignals(result, atom);
|
|
59
|
+
return result;
|
|
62
60
|
}
|
|
63
61
|
return { query, subscription: { connection, identity: socketIdentity, paused, status } };
|
|
64
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticLive.js","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"automaticLive.js","sourceRoot":"","sources":["../src/automaticLive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGpE,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAK/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAmB,IAAI,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAwC,YAAY,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAK/C,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AAU/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AAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CACrI,QAAQ,CAAC,MAAM,CACf;SACD,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,cAAc,CAAC;YAC5B,cAAc,EAAE,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,QAAQ;YACvD,UAAU;YACV,YAAY;YACZ,MAAM;YACN,KAAK;YACL,OAAO;YACP,MAAM;YACN,QAAQ;YACR,YAAY;YACZ,mBAAmB,EAAE,QAAQ,CAAC,OAAO;SACrC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAC3B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAC3C,KAAK,EACL,EAAE,kBAAkB,EAAE,IAAI,EAAE,EAC5B,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAC7F,CAAC;QACF,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;AAC1F,CAAC"}
|
package/dist/automaticQuery.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
2
2
|
import * as Atom from "effect/reactivity/Atom";
|
|
3
3
|
import type { AutomaticQueryOptions } from "#AutomaticQueryOptions.ts";
|
|
4
|
-
|
|
5
|
-
readonly
|
|
6
|
-
}
|
|
7
|
-
export declare function automaticQuery<A, E>({
|
|
4
|
+
type GateOptions<A, E> = AutomaticQueryOptions<A, E> & {
|
|
5
|
+
readonly ownerFailure: (get: Atom.AtomContext) => Error | undefined;
|
|
6
|
+
};
|
|
7
|
+
export declare function automaticQuery<A, E>({ clientStatuses, equivalent, ownerFailure, paused, ready, signals, source, statuses, subscription, subscriptionVersion, }: GateOptions<A, E>): Atom.Atom<AsyncResult.Failure<unknown, never> | AsyncResult.AsyncResult<A, E>>;
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=automaticQuery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticQuery.d.ts","sourceRoot":"","sources":["../src/automaticQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAKvE,
|
|
1
|
+
{"version":3,"file":"automaticQuery.d.ts","sourceRoot":"","sources":["../src/automaticQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAKvE,KAAK,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,KAAK,KAAK,GAAG,SAAS,CAAA;CAAE,CAAC;AAC/H,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,EACpC,cAAc,EACd,UAAU,EACV,YAAY,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,YAAY,EACZ,mBAAmB,GACnB,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,kFAiHnB"}
|
package/dist/automaticQuery.js
CHANGED
|
@@ -3,10 +3,15 @@ import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import { recordCompletion, recordSubscription } from "#queryProgress.ts";
|
|
5
5
|
import { queryResult } from "#queryResult.ts";
|
|
6
|
-
export function automaticQuery({
|
|
6
|
+
export function automaticQuery({ clientStatuses, equivalent, ownerFailure, paused, ready, signals, source, statuses, subscription, subscriptionVersion, }) {
|
|
7
7
|
const gated = Atom.readable((get) => {
|
|
8
|
-
assertOwner(get);
|
|
9
8
|
get.mount(signals);
|
|
9
|
+
const error = ownerFailure(get);
|
|
10
|
+
if (error !== undefined) {
|
|
11
|
+
const failure = AsyncResult.failure(Cause.die(error));
|
|
12
|
+
get.set(signals, recordCompletion(get.once(signals), failure));
|
|
13
|
+
return failure;
|
|
14
|
+
}
|
|
10
15
|
get.mount(subscriptionVersion);
|
|
11
16
|
const openingVersion = get.once(subscriptionVersion);
|
|
12
17
|
get.refresh(subscription.connection);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automaticQuery.js","sourceRoot":"","sources":["../src/automaticQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAC7D,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAG/C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"automaticQuery.js","sourceRoot":"","sources":["../src/automaticQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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AC,CAAC,CAAC;IAC3B,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAsC,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAkC,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAGnE,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI,MAAM,SAAS,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE5F,MAAM,WAAW,QAAQ,CACxB,KAAK,SAAS,MAAM,EACpB,QAAQ,SAAS,SAAS,UAAU,EAAE,EACtC,SAAS,SAAS,SAAS,YAAY,EAAE,EACzC,QAAQ,SAAS,SAAS,WAAW,EAAE,GAAG,SAAS,EAAE,EACrD,MAAM,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS;IAEhD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAA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"effect";
|
|
2
2
|
import { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
-
import { declarationError } from "#declarationError.ts";
|
|
3
|
+
import { DeclarationError, declarationError } from "#declarationError.ts";
|
|
4
4
|
import { ReadPolicyGuard } from "#ReadPolicyGuard.ts";
|
|
5
5
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
6
6
|
import { changesRpc, KeyScope, operationAnnotations } from "#serverMetadata.ts";
|
|
7
7
|
import { subjectMiddleware } from "#subjectMiddleware.ts";
|
|
8
8
|
function assertValid(name, operations) {
|
|
9
|
-
|
|
10
|
-
if (error !== undefined) {
|
|
11
|
-
throw new Error(error);
|
|
12
|
-
}
|
|
9
|
+
return declarationError(name, operations);
|
|
13
10
|
}
|
|
14
11
|
function withDeclaration(group, application, declaration) {
|
|
15
12
|
const nativeMiddleware = group.middleware.bind(group);
|
|
@@ -21,7 +18,7 @@ function withDeclaration(group, application, declaration) {
|
|
|
21
18
|
}
|
|
22
19
|
export function contract(name, operations) {
|
|
23
20
|
const { queries = [], commands = [], streams = [], keyScope } = operations;
|
|
24
|
-
assertValid(name, [...queries, ...commands, ...streams]);
|
|
21
|
+
const error = assertValid(name, [...queries, ...commands, ...streams]);
|
|
25
22
|
const rpcs = [...queries, ...commands, ...streams].map((operation) => {
|
|
26
23
|
const rpc = Rpc.make(`${name}.${operation.name}`, {
|
|
27
24
|
error: operation.kind === "query" ? Schema.Union([operation.error, QueryReadDenied]) : operation.error,
|
|
@@ -35,7 +32,8 @@ export function contract(name, operations) {
|
|
|
35
32
|
const application = RpcGroup.make(...rpcs);
|
|
36
33
|
const changes = changesRpc(name, queries).middleware(ReadPolicyGuard);
|
|
37
34
|
const subjectChanges = operations.subject === undefined ? changes : changes.middleware(subjectMiddleware(`${name}.$changes`, operations.subject));
|
|
38
|
-
const
|
|
35
|
+
const built = application.add(keyScope === undefined ? subjectChanges : subjectChanges.annotate(KeyScope, keyScope));
|
|
36
|
+
const group = error === undefined ? built : built.annotate(DeclarationError, error);
|
|
39
37
|
return withDeclaration(group, application, {
|
|
40
38
|
commands,
|
|
41
39
|
keyScope,
|
package/dist/contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAe,MAAM,sBAAsB,CAAC;AAGvF,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAmC1D,SAAS,WAAW,CAAC,IAAY,EAAE,UAAgE;IAClG,OAAO,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAC3C,CAAC;AAaD,SAAS,eAAe,CAAC,KAAY,EAAE,WAAkB,EAAE,WAAwB;IAClF,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtD,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QAC3B,WAAW;QACX,WAAW;QACX,UAAU,EAAE,CAAC,UAAoC,EAAE,EAAE,CACpD,eAAe,CAAC,gBAAgB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,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAC5I,CAAC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;IACtE,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,IAAI,WAAW,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;IAClJ,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IACrH,MAAM,KAAK,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;IACpF,OAAO,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE;QAC1C,QAAQ;QACR,QAAQ;QACR,IAAI;QACJ,OAAO;QACP,OAAO;KACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
1
2
|
import type { CommandShape, OperationShape, QueryShape, StreamShape } from "#operation.ts";
|
|
3
|
+
export declare const DeclarationError: Context.Reference<string | undefined>;
|
|
2
4
|
type Duplicated<TOperations extends readonly OperationShape[], TSeen extends string = never> = TOperations extends readonly [
|
|
3
5
|
infer THead extends OperationShape,
|
|
4
6
|
...infer TTail extends readonly OperationShape[]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarationError.d.ts","sourceRoot":"","sources":["../src/declarationError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3F,KAAK,UAAU,CAAC,WAAW,SAAS,SAAS,cAAc,EAAE,EAAE,KAAK,SAAS,MAAM,GAAG,KAAK,IAAI,WAAW,SAAS,SAAS;IAC3H,MAAM,KAAK,SAAS,cAAc;IAClC,GAAG,MAAM,KAAK,SAAS,SAAS,cAAc,EAAE;CAChD,GACE,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAChG,KAAK,CAAC;AAET,MAAM,MAAM,MAAM,CAAC,WAAW,SAAS,SAAS,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1G,OAAO,GACP,+CAA+C,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;AAE5E,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,YAAY,GAAG,WAAW,CAAC,EAAE,GAAG,MAAM,GAAG,SAAS,CAc3I"}
|
|
1
|
+
{"version":3,"file":"declarationError.d.ts","sourceRoot":"","sources":["../src/declarationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3F,eAAO,MAAM,gBAAgB,uCAAmH,CAAC;AAEjJ,KAAK,UAAU,CAAC,WAAW,SAAS,SAAS,cAAc,EAAE,EAAE,KAAK,SAAS,MAAM,GAAG,KAAK,IAAI,WAAW,SAAS,SAAS;IAC3H,MAAM,KAAK,SAAS,cAAc;IAClC,GAAG,MAAM,KAAK,SAAS,SAAS,cAAc,EAAE;CAChD,GACE,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAChG,KAAK,CAAC;AAET,MAAM,MAAM,MAAM,CAAC,WAAW,SAAS,SAAS,cAAc,EAAE,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAC1G,OAAO,GACP,+CAA+C,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;AAE5E,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,YAAY,GAAG,WAAW,CAAC,EAAE,GAAG,MAAM,GAAG,SAAS,CAc3I"}
|
package/dist/declarationError.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
1
2
|
import { isPermissionReadPolicy } from "#permissionReadPolicy.ts";
|
|
3
|
+
export const DeclarationError = Context.Reference("@shivaedev/contract/DeclarationError", { defaultValue: () => undefined });
|
|
2
4
|
export function declarationError(contractName, operations) {
|
|
3
5
|
if (operations.some(({ name }) => name === "$changes")) {
|
|
4
6
|
return `Operation name $changes is reserved for the built-in changes stream on contract ${contractName}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarationError.js","sourceRoot":"","sources":["../src/declarationError.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"declarationError.js","sourceRoot":"","sources":["../src/declarationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAA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|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
readonly middlewares: ReadonlySet<{
|
|
5
|
-
readonly key: string;
|
|
6
|
-
}>;
|
|
7
|
-
};
|
|
8
|
-
export declare const prependMiddleware: <R extends WithMiddlewares>(group: RpcGroup.RpcGroup<R>, key: string) => Effect.Effect<RpcGroup.RpcGroup<R>, never, never>;
|
|
9
|
-
export {};
|
|
2
|
+
import { RpcGroup, type Rpc as RpcType } from "effect/rpc";
|
|
3
|
+
export declare function prependMiddleware<R extends RpcType.Any>(group: RpcGroup.RpcGroup<R>, key: string): Effect.Effect<RpcGroup.RpcGroup<R>>;
|
|
10
4
|
//# sourceMappingURL=prependMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prependMiddleware.d.ts","sourceRoot":"","sources":["../src/prependMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prependMiddleware.d.ts","sourceRoot":"","sources":["../src/prependMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAO,QAAQ,EAAiC,KAAK,GAAG,IAAI,OAAO,EAAE,MAAM,YAAY,CAAC;AAuB/F,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { Rpc, RpcGroup, RpcSchema } from "effect/rpc";
|
|
3
|
+
function hasNativeProps(rpc) {
|
|
4
|
+
return "payloadSchema" in rpc && "successSchema" in rpc && "errorSchema" in rpc && "defectSchema" in rpc && "middlewares" in rpc;
|
|
5
|
+
}
|
|
6
|
+
function rebuild(rpc, key) {
|
|
7
|
+
const stream = RpcSchema.isStreamSchema(rpc.successSchema) ? rpc.successSchema : undefined;
|
|
8
|
+
let rebuilt = Rpc.make(rpc._tag, {
|
|
9
|
+
defect: rpc.defectSchema,
|
|
10
|
+
error: stream?.error ?? rpc.errorSchema,
|
|
11
|
+
payload: rpc.payloadSchema,
|
|
12
|
+
...(stream === undefined ? {} : { stream: true }),
|
|
13
|
+
success: stream?.success ?? rpc.successSchema,
|
|
14
|
+
});
|
|
15
|
+
rebuilt = rebuilt.annotateMerge(rpc.annotations);
|
|
16
|
+
const middlewares = [...rpc.middlewares].sort((left, right) => Number(right.key === key) - Number(left.key === key));
|
|
17
|
+
for (const middleware of middlewares) {
|
|
18
|
+
rebuilt = rebuilt.middleware(middleware);
|
|
19
|
+
}
|
|
20
|
+
return rebuilt;
|
|
21
|
+
}
|
|
22
|
+
export function prependMiddleware(group, key) {
|
|
23
|
+
return Effect.sync(() => {
|
|
4
24
|
// Native middleware runs in reverse order; identity must supply the viewer before this guard runs.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.assign(rpc, { middlewares: new Set(middlewares) });
|
|
8
|
-
}
|
|
9
|
-
return group;
|
|
25
|
+
const requests = [...group.requests.values()].map((rpc) => (hasNativeProps(rpc) ? rebuild(rpc, key) : rpc));
|
|
26
|
+
return RpcGroup.make(...requests).annotateMerge(group.annotations);
|
|
10
27
|
});
|
|
11
|
-
}
|
|
28
|
+
}
|
|
12
29
|
//# sourceMappingURL=prependMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prependMiddleware.js","sourceRoot":"","sources":["../src/prependMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prependMiddleware.js","sourceRoot":"","sources":["../src/prependMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,M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O,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAGD,MAAM,UAAU,iBAAiB,CAAC,KAAqC,EAAE,GAAW;IACnF,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;QACvB,mGAAmG;QACnG,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5G,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateReadPolicies.d.ts","sourceRoot":"","sources":["../src/validateReadPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAU,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"validateReadPolicies.d.ts","sourceRoot":"","sources":["../src/validateReadPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAU,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAG3D,eAAO,MAAM,oBAAoB,GAAgC,CAAC,SAAS,GAAG,CAAC,GAAG,sFAwBhF,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { Context, Effect, Option } from "effect";
|
|
2
|
+
import { DeclarationError } from "#declarationError.ts";
|
|
2
3
|
import { MissingReadPolicies } from "#readPolicyErrors.ts";
|
|
3
4
|
import { ChangesQueries, QueryDefinition } from "#serverMetadata.ts";
|
|
4
5
|
export const validateReadPolicies = Effect.fnUntraced(function* (group) {
|
|
6
|
+
const declarationFailure = Context.get(group.annotations, DeclarationError);
|
|
7
|
+
if (declarationFailure !== undefined) {
|
|
8
|
+
return yield* Effect.die(new Error(declarationFailure));
|
|
9
|
+
}
|
|
5
10
|
const missing = new Set();
|
|
6
11
|
for (const rpc of group.requests.values()) {
|
|
7
12
|
const query = Context.getOption(rpc.annotations, QueryDefinition);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateReadPolicies.js","sourceRoot":"","sources":["../src/validateReadPolicies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErE,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAqB,KAA2B;IAC9G,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QAClE,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7E,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,MAAM,OAAO,GAA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C,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9E,OAAO,KAAK,CAAC,CAAC,IAAI,mBAAmB,CAAC,EAAE,OAAO,EAAE,oCAAoC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IACvH,CAAC;AACF,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/contract",
|
|
3
|
-
"version": "0.43.
|
|
3
|
+
"version": "0.43.3",
|
|
4
4
|
"description": "Typed query and command contracts over native Effect RPC and reactivity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -51,16 +51,15 @@
|
|
|
51
51
|
"@effect/platform-node": "4.1.1",
|
|
52
52
|
"@effect/vitest": "4.1.1",
|
|
53
53
|
"@shivaedev/errors": "0.10.1",
|
|
54
|
-
"@shivaedev/identity": "0.30.
|
|
55
|
-
"@shivaedev/quality": "0.
|
|
56
|
-
"@shivaedev/server": "0.
|
|
57
|
-
"@shivaedev/sql": "0.46.
|
|
58
|
-
"@shivaedev/test-kits": "0.10.
|
|
59
|
-
"@shivaedev/test-sql": "0.24.
|
|
60
|
-
"@shivaedev/test-story": "0.45.
|
|
54
|
+
"@shivaedev/identity": "0.30.5",
|
|
55
|
+
"@shivaedev/quality": "0.74.0",
|
|
56
|
+
"@shivaedev/server": "0.33.0",
|
|
57
|
+
"@shivaedev/sql": "0.46.3",
|
|
58
|
+
"@shivaedev/test-kits": "0.10.6",
|
|
59
|
+
"@shivaedev/test-sql": "0.24.7",
|
|
60
|
+
"@shivaedev/test-story": "0.45.5",
|
|
61
61
|
"@types/node": "24.19.2",
|
|
62
62
|
"effect": "4.1.1",
|
|
63
|
-
"esbuild": "0.28.2",
|
|
64
63
|
"happy-dom": "21.0.4",
|
|
65
64
|
"typescript": "7.0.2",
|
|
66
65
|
"vitest": "5.0.5"
|
package/src/automaticLive.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, type Schema, Stream } from "effect";
|
|
1
|
+
import { Cause, Effect, Option, type Schema, Stream } from "effect";
|
|
2
2
|
import type { Headers } from "effect/http";
|
|
3
3
|
import type * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
4
4
|
import * as Atom from "effect/reactivity/Atom";
|
|
@@ -51,10 +51,8 @@ export function automaticLive(
|
|
|
51
51
|
enabled = true,
|
|
52
52
|
resumeWindow?: ResumeWindow,
|
|
53
53
|
) {
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
throw new Error("A session-scoped query belongs to its binding registry");
|
|
57
|
-
}
|
|
54
|
+
function ownerFailure(get: Atom.AtomContext) {
|
|
55
|
+
return owner !== undefined && owner.registry !== get.registry ? new Error("A session-scoped query belongs to its binding registry") : undefined;
|
|
58
56
|
}
|
|
59
57
|
const paused = pausedByRuntime(service.runtime);
|
|
60
58
|
const statuses = Atom.make<ReadonlyMap<object, LiveStatus<unknown>>>(new Map());
|
|
@@ -62,7 +60,10 @@ export function automaticLive(
|
|
|
62
60
|
const target = resumeWindow ?? (typeof window === "undefined" ? undefined : window);
|
|
63
61
|
const signal = resumeSignal({ ...(target === undefined ? {} : { window: target }), ...(resume === undefined ? {} : { native: resume }) });
|
|
64
62
|
const connection = Atom.make((get) => {
|
|
65
|
-
|
|
63
|
+
const error = ownerFailure(get);
|
|
64
|
+
if (error !== undefined) {
|
|
65
|
+
return { connection: "failed", failure: Option.some(Cause.die(error)), needsResync: true, pending: 0 } as const;
|
|
66
|
+
}
|
|
66
67
|
get.mount(service.runtime);
|
|
67
68
|
return get(status);
|
|
68
69
|
}).pipe(Atom.setIdleTTL(0));
|
|
@@ -91,9 +92,9 @@ export function automaticLive(
|
|
|
91
92
|
),
|
|
92
93
|
});
|
|
93
94
|
const gated = automaticQuery({
|
|
94
|
-
assertOwner,
|
|
95
95
|
clientStatuses: clientActivities.get(service)?.statuses,
|
|
96
96
|
equivalent,
|
|
97
|
+
ownerFailure,
|
|
97
98
|
paused,
|
|
98
99
|
ready,
|
|
99
100
|
signals,
|
|
@@ -102,12 +103,14 @@ export function automaticLive(
|
|
|
102
103
|
subscription,
|
|
103
104
|
subscriptionVersion: delivery.updates,
|
|
104
105
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
const result = Object.assign(
|
|
107
|
+
Object.create(Object.getPrototypeOf(gated)),
|
|
108
|
+
gated,
|
|
109
|
+
{ initialValueTarget: atom },
|
|
110
|
+
Atom.isSerializable(atom) ? { [Atom.SerializableTypeId]: atom[Atom.SerializableTypeId] } : {},
|
|
111
|
+
);
|
|
112
|
+
shareQuerySignals(result, atom);
|
|
113
|
+
return result;
|
|
111
114
|
}
|
|
112
115
|
return { query, subscription: { connection, identity: socketIdentity, paused, status } };
|
|
113
116
|
}
|
package/src/automaticQuery.ts
CHANGED
|
@@ -6,13 +6,11 @@ import type { LiveStatus } from "#live.ts";
|
|
|
6
6
|
import { recordCompletion, recordSubscription } from "#queryProgress.ts";
|
|
7
7
|
import { queryResult } from "#queryResult.ts";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
readonly assertOwner: (get: Atom.AtomContext) => void;
|
|
11
|
-
}
|
|
9
|
+
type GateOptions<A, E> = AutomaticQueryOptions<A, E> & { readonly ownerFailure: (get: Atom.AtomContext) => Error | undefined };
|
|
12
10
|
export function automaticQuery<A, E>({
|
|
13
|
-
assertOwner,
|
|
14
11
|
clientStatuses,
|
|
15
12
|
equivalent,
|
|
13
|
+
ownerFailure,
|
|
16
14
|
paused,
|
|
17
15
|
ready,
|
|
18
16
|
signals,
|
|
@@ -23,8 +21,13 @@ export function automaticQuery<A, E>({
|
|
|
23
21
|
}: GateOptions<A, E>) {
|
|
24
22
|
const gated = Atom.readable(
|
|
25
23
|
(get) => {
|
|
26
|
-
assertOwner(get);
|
|
27
24
|
get.mount(signals);
|
|
25
|
+
const error = ownerFailure(get);
|
|
26
|
+
if (error !== undefined) {
|
|
27
|
+
const failure = AsyncResult.failure(Cause.die(error));
|
|
28
|
+
get.set(signals, recordCompletion(get.once(signals), failure));
|
|
29
|
+
return failure;
|
|
30
|
+
}
|
|
28
31
|
get.mount(subscriptionVersion);
|
|
29
32
|
const openingVersion = get.once(subscriptionVersion);
|
|
30
33
|
get.refresh(subscription.connection);
|
package/src/contract.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Rpc, RpcGroup, type RpcMiddleware } from "effect/rpc";
|
|
3
|
-
import { declarationError, type Unique } from "#declarationError.ts";
|
|
3
|
+
import { DeclarationError, declarationError, type Unique } from "#declarationError.ts";
|
|
4
4
|
import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
5
5
|
import type { OperationRpc } from "#operationRpc.ts";
|
|
6
6
|
import { ReadPolicyGuard } from "#ReadPolicyGuard.ts";
|
|
@@ -43,10 +43,7 @@ export interface Contract<
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function assertValid(name: string, operations: readonly (QueryShape | CommandShape | StreamShape)[]) {
|
|
46
|
-
|
|
47
|
-
if (error !== undefined) {
|
|
48
|
-
throw new Error(error);
|
|
49
|
-
}
|
|
46
|
+
return declarationError(name, operations);
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
type AnyDeclared = Declared<string, readonly QueryShape[], readonly CommandShape[], readonly StreamShape[], "session" | undefined>;
|
|
@@ -109,7 +106,7 @@ export function contract(
|
|
|
109
106
|
},
|
|
110
107
|
): DeclaredGroup {
|
|
111
108
|
const { queries = [], commands = [], streams = [], keyScope } = operations;
|
|
112
|
-
assertValid(name, [...queries, ...commands, ...streams]);
|
|
109
|
+
const error = assertValid(name, [...queries, ...commands, ...streams]);
|
|
113
110
|
const rpcs = [...queries, ...commands, ...streams].map((operation) => {
|
|
114
111
|
const rpc = Rpc.make(`${name}.${operation.name}`, {
|
|
115
112
|
error: operation.kind === "query" ? Schema.Union([operation.error, QueryReadDenied]) : operation.error,
|
|
@@ -123,7 +120,8 @@ export function contract(
|
|
|
123
120
|
const application = RpcGroup.make(...rpcs);
|
|
124
121
|
const changes = changesRpc(name, queries).middleware(ReadPolicyGuard);
|
|
125
122
|
const subjectChanges = operations.subject === undefined ? changes : changes.middleware(subjectMiddleware(`${name}.$changes`, operations.subject));
|
|
126
|
-
const
|
|
123
|
+
const built = application.add(keyScope === undefined ? subjectChanges : subjectChanges.annotate(KeyScope, keyScope));
|
|
124
|
+
const group = error === undefined ? built : built.annotate(DeclarationError, error);
|
|
127
125
|
return withDeclaration(group, application, {
|
|
128
126
|
commands,
|
|
129
127
|
keyScope,
|
package/src/declarationError.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Context } from "effect";
|
|
1
2
|
import type { CommandShape, OperationShape, QueryShape, StreamShape } from "#operation.ts";
|
|
2
3
|
import { isPermissionReadPolicy } from "#permissionReadPolicy.ts";
|
|
3
4
|
|
|
5
|
+
export const DeclarationError = Context.Reference<string | undefined>("@shivaedev/contract/DeclarationError", { defaultValue: () => undefined });
|
|
6
|
+
|
|
4
7
|
type Duplicated<TOperations extends readonly OperationShape[], TSeen extends string = never> = TOperations extends readonly [
|
|
5
8
|
infer THead extends OperationShape,
|
|
6
9
|
...infer TTail extends readonly OperationShape[],
|
package/src/prependMiddleware.ts
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import
|
|
1
|
+
import { Effect, type Schema } from "effect";
|
|
2
|
+
import { Rpc, RpcGroup, type RpcMiddleware, RpcSchema, type Rpc as RpcType } from "effect/rpc";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function hasNativeProps(rpc: RpcType.Any): rpc is RpcType.AnyWithProps & { readonly defectSchema: RpcType.DefectSchema } {
|
|
5
|
+
return "payloadSchema" in rpc && "successSchema" in rpc && "errorSchema" in rpc && "defectSchema" in rpc && "middlewares" in rpc;
|
|
6
|
+
}
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
function rebuild(rpc: RpcType.AnyWithProps & { readonly defectSchema: RpcType.DefectSchema }, key: string): RpcType.Any {
|
|
9
|
+
const stream = RpcSchema.isStreamSchema(rpc.successSchema) ? rpc.successSchema : undefined;
|
|
10
|
+
let rebuilt: RpcType.Rpc<string, Schema.Top, Schema.Top, Schema.Top, RpcMiddleware.AnyService, unknown> = Rpc.make(rpc._tag, {
|
|
11
|
+
defect: rpc.defectSchema,
|
|
12
|
+
error: stream?.error ?? rpc.errorSchema,
|
|
13
|
+
payload: rpc.payloadSchema,
|
|
14
|
+
...(stream === undefined ? {} : { stream: true as const }),
|
|
15
|
+
success: stream?.success ?? rpc.successSchema,
|
|
16
|
+
});
|
|
17
|
+
rebuilt = rebuilt.annotateMerge(rpc.annotations);
|
|
18
|
+
const middlewares = [...rpc.middlewares].sort((left, right) => Number(right.key === key) - Number(left.key === key));
|
|
19
|
+
for (const middleware of middlewares) {
|
|
20
|
+
rebuilt = rebuilt.middleware(middleware);
|
|
21
|
+
}
|
|
22
|
+
return rebuilt;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function prependMiddleware<R extends RpcType.Any>(group: RpcGroup.RpcGroup<R>, key: string): Effect.Effect<RpcGroup.RpcGroup<R>>;
|
|
26
|
+
export function prependMiddleware(group: RpcGroup.RpcGroup<RpcType.Any>, key: string): Effect.Effect<RpcGroup.RpcGroup<RpcType.Any>> {
|
|
27
|
+
return Effect.sync(() => {
|
|
8
28
|
// Native middleware runs in reverse order; identity must supply the viewer before this guard runs.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.assign(rpc, { middlewares: new Set(middlewares) });
|
|
12
|
-
}
|
|
13
|
-
return group;
|
|
29
|
+
const requests = [...group.requests.values()].map((rpc) => (hasNativeProps(rpc) ? rebuild(rpc, key) : rpc));
|
|
30
|
+
return RpcGroup.make(...requests).annotateMerge(group.annotations);
|
|
14
31
|
});
|
|
15
|
-
}
|
|
32
|
+
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Context, Effect, Option } from "effect";
|
|
2
2
|
import type { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
+
import { DeclarationError } from "#declarationError.ts";
|
|
3
4
|
import { MissingReadPolicies } from "#readPolicyErrors.ts";
|
|
4
5
|
import { ChangesQueries, QueryDefinition } from "#serverMetadata.ts";
|
|
5
6
|
|
|
6
7
|
export const validateReadPolicies = Effect.fnUntraced(function* <R extends Rpc.Any>(group: RpcGroup.RpcGroup<R>) {
|
|
8
|
+
const declarationFailure = Context.get(group.annotations, DeclarationError);
|
|
9
|
+
if (declarationFailure !== undefined) {
|
|
10
|
+
return yield* Effect.die(new Error(declarationFailure));
|
|
11
|
+
}
|
|
7
12
|
const missing = new Set<string>();
|
|
8
13
|
for (const rpc of group.requests.values()) {
|
|
9
14
|
const query = Context.getOption(rpc.annotations, QueryDefinition);
|