@shivaedev/contract 0.30.0 → 0.30.1
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 +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +6 -5
- package/dist/contract.js.map +1 -1
- package/dist/internal/declarationError.d.ts +3 -0
- package/dist/internal/declarationError.d.ts.map +1 -0
- package/dist/internal/declarationError.js +12 -0
- package/dist/internal/declarationError.js.map +1 -0
- package/package.json +8 -8
- package/src/contract.ts +6 -5
- package/src/internal/declarationError.ts +15 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -502,7 +502,7 @@ const AllNotes = query("allNotes", {
|
|
|
502
502
|
});
|
|
503
503
|
```
|
|
504
504
|
|
|
505
|
-
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 changed hints are delivered. `readsCollections` requires this policy at declaration: a `signedIn` or ordinary boolean policy fails TypeScript checking. The server also refuses
|
|
505
|
+
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 changed hints are delivered. `readsCollections` requires this policy at declaration: a `signedIn` or ordinary boolean policy fails TypeScript checking, and building an untyped contract with that declaration throws an error explaining the required permission policy. The server also refuses collection queries changed to an ordinary policy after construction as `QueryReadDenied`. Tenant-facing queries use `notes.bucket.userId(viewerId)` instead.
|
|
506
506
|
|
|
507
507
|
Collection reads reuse the bare repository table key, the same key as `notes.list`, even when the contract uses `keyScope: "session"`; ordinary reads keep their session scope. 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.
|
|
508
508
|
|
package/dist/contract.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAE/E,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAkC,MAAM,oBAAoB,CAAC;AAEhF,MAAM,MAAM,GAAG,CAAC,SAAS,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,IAAI,GAAG,SAAS,IAAI,KAAK,EAAE,CAAC;AAE1F,MAAM,MAAM,aAAa,CAAC,MAAM,IAAI,MAAM,SAAS,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE5F,KAAK,cAAc,CAAC,UAAU,SAAS,cAAc,IAAI,UAAU,SAAS,UAAU,GACnF,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CA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AAC"}
|
package/dist/contract.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Rpc, RpcGroup } from "effect/rpc";
|
|
3
|
+
import { declarationError } from "#internal/declarationError.ts";
|
|
3
4
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
4
5
|
import { changesRpc, KeyScope, operationAnnotations } from "#serverMetadata.ts";
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
8
|
-
throw new Error(
|
|
6
|
+
function assertValid(name, operations) {
|
|
7
|
+
const error = declarationError(name, operations);
|
|
8
|
+
if (error !== undefined) {
|
|
9
|
+
throw new Error(error);
|
|
9
10
|
}
|
|
10
11
|
}
|
|
11
12
|
function withDeclaration(group, application, declaration) {
|
|
@@ -18,7 +19,7 @@ function withDeclaration(group, application, declaration) {
|
|
|
18
19
|
}
|
|
19
20
|
export function contract(name, operations) {
|
|
20
21
|
const { queries = [], commands = [], streams = [], keyScope } = operations;
|
|
21
|
-
|
|
22
|
+
assertValid(name, [...queries, ...commands, ...streams]);
|
|
22
23
|
const rpcs = [...queries, ...commands, ...streams].map((operation) => Rpc.make(`${name}.${operation.name}`, {
|
|
23
24
|
error: operation.kind === "query" ? Schema.Union([operation.error, QueryReadDenied]) : operation.error,
|
|
24
25
|
payload: operation.payload,
|
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,EAAsC,MAAM,YAAY,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,EAAsC,MAAM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C,IAAI,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC,IAAI,EAAE,EAAE;QACrC,KAAK,EAAE,SAAS,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK;QACtG,OAAO,EAAE,SAAS,CAAC,OAAO;QAC1B,MAAM,EAAE,SAAS,CAAC,IAAI,KAAK,QAAQ;QACnC,OAAO,EAAE,SAAS,CAAC,OAAO;KAC1B,CAAC,CAAC,aAAa,CAAC,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAC3D,CAAC;IACF,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAC3C,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,eAAe,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,WAAW,EAAE;QAC7H,QAAQ;QACR,QAAQ;QACR,IAAI;QACJ,OAAO;QACP,OAAO;KACP,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
2
|
+
export declare function declarationError(contractName: string, operations: readonly (QueryShape | CommandShape | StreamShape)[]): string | undefined;
|
|
3
|
+
//# sourceMappingURL=declarationError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarationError.d.ts","sourceRoot":"","sources":["../../src/internal/declarationError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG3E,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,YAAY,GAAG,WAAW,CAAC,EAAE,GAAG,MAAM,GAAG,SAAS,CAW3I"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isPermissionReadPolicy } from "#permissionReadPolicy.ts";
|
|
2
|
+
export function declarationError(contractName, operations) {
|
|
3
|
+
const duplicated = operations.map(({ name }) => name).filter((name, index, names) => names.indexOf(name) !== index);
|
|
4
|
+
if (duplicated.length > 0) {
|
|
5
|
+
return `Operation names must be unique; duplicated: ${[...new Set(duplicated)].join(", ")}`;
|
|
6
|
+
}
|
|
7
|
+
const member = operations.find((operation) => operation.kind === "query" && operation.readsCollections !== undefined && !isPermissionReadPolicy(operation.readPolicy));
|
|
8
|
+
return member === undefined
|
|
9
|
+
? undefined
|
|
10
|
+
: `Collection reads require a permission policy on query ${contractName}.${member.name}; use permissionReadPolicy instead of a member policy`;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=declarationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarationError.js","sourceRoot":"","sources":["../../src/internal/declarationError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,UAAU,gBAAgB,CAAC,YAAoB,EAAE,UAAgE;IACtH,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;IACpH,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,OAAO,+CAA+C,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC7F,CAAC;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAC7B,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,OAAO,IAAI,SAAS,CAAC,gBAAgB,KAAK,SAAS,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,UAAU,CAAC,CACtI,CAAC;IACF,OAAO,MAAM,KAAK,SAAS;QAC1B,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,yDAAyD,YAAY,IAAI,MAAM,CAAC,IAAI,uDAAuD,CAAC;AAChJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/contract",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Typed query and command contracts over native Effect RPC and reactivity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -50,14 +50,14 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@effect/platform-node": "4.0.6",
|
|
52
52
|
"@effect/vitest": "4.0.6",
|
|
53
|
-
"@shivaedev/errors": "0.4.
|
|
54
|
-
"@shivaedev/identity": "0.
|
|
55
|
-
"@shivaedev/quality": "0.
|
|
56
|
-
"@shivaedev/server": "0.
|
|
57
|
-
"@shivaedev/sql": "0.
|
|
53
|
+
"@shivaedev/errors": "0.4.1",
|
|
54
|
+
"@shivaedev/identity": "0.16.0",
|
|
55
|
+
"@shivaedev/quality": "0.53.1",
|
|
56
|
+
"@shivaedev/server": "0.16.1",
|
|
57
|
+
"@shivaedev/sql": "0.30.0",
|
|
58
58
|
"@shivaedev/test": "0.12.0",
|
|
59
|
-
"@shivaedev/test-sql": "0.15.
|
|
60
|
-
"@shivaedev/test-story": "0.31.
|
|
59
|
+
"@shivaedev/test-sql": "0.15.3",
|
|
60
|
+
"@shivaedev/test-story": "0.31.4",
|
|
61
61
|
"@types/node": "24.19.2",
|
|
62
62
|
"effect": "4.0.6",
|
|
63
63
|
"esbuild": "0.28.2",
|
package/src/contract.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Rpc, RpcGroup, type RpcMiddleware, type RpcSchema } from "effect/rpc";
|
|
3
|
+
import { declarationError } from "#internal/declarationError.ts";
|
|
3
4
|
import type { CommandShape, OperationShape, QueryShape, StreamShape } from "#operation.ts";
|
|
4
5
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
5
6
|
import { changesRpc, KeyScope, operationAnnotations } from "#serverMetadata.ts";
|
|
@@ -65,10 +66,10 @@ type Unique<TOperations extends readonly OperationShape[]> = [Duplicated<TOperat
|
|
|
65
66
|
? unknown
|
|
66
67
|
: `Operation names must be unique; duplicated: ${Duplicated<TOperations>}`;
|
|
67
68
|
|
|
68
|
-
function
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
throw new Error(
|
|
69
|
+
function assertValid(name: string, operations: readonly (QueryShape | CommandShape | StreamShape)[]) {
|
|
70
|
+
const error = declarationError(name, operations);
|
|
71
|
+
if (error !== undefined) {
|
|
72
|
+
throw new Error(error);
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -125,7 +126,7 @@ export function contract(
|
|
|
125
126
|
},
|
|
126
127
|
): DeclaredGroup {
|
|
127
128
|
const { queries = [], commands = [], streams = [], keyScope } = operations;
|
|
128
|
-
|
|
129
|
+
assertValid(name, [...queries, ...commands, ...streams]);
|
|
129
130
|
const rpcs = [...queries, ...commands, ...streams].map((operation) =>
|
|
130
131
|
Rpc.make(`${name}.${operation.name}`, {
|
|
131
132
|
error: operation.kind === "query" ? Schema.Union([operation.error, QueryReadDenied]) : operation.error,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
2
|
+
import { isPermissionReadPolicy } from "#permissionReadPolicy.ts";
|
|
3
|
+
|
|
4
|
+
export function declarationError(contractName: string, operations: readonly (QueryShape | CommandShape | StreamShape)[]): string | undefined {
|
|
5
|
+
const duplicated = operations.map(({ name }) => name).filter((name, index, names) => names.indexOf(name) !== index);
|
|
6
|
+
if (duplicated.length > 0) {
|
|
7
|
+
return `Operation names must be unique; duplicated: ${[...new Set(duplicated)].join(", ")}`;
|
|
8
|
+
}
|
|
9
|
+
const member = operations.find(
|
|
10
|
+
(operation) => operation.kind === "query" && operation.readsCollections !== undefined && !isPermissionReadPolicy(operation.readPolicy),
|
|
11
|
+
);
|
|
12
|
+
return member === undefined
|
|
13
|
+
? undefined
|
|
14
|
+
: `Collection reads require a permission policy on query ${contractName}.${member.name}; use permissionReadPolicy instead of a member policy`;
|
|
15
|
+
}
|