@tinkered/core 0.27.0 → 0.27.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkered/core",
3
- "version": "0.27.0",
3
+ "version": "0.27.2",
4
4
  "description": "Tinkered core: a small, fast reactive/graph dependency engine.",
5
5
  "keywords": [
6
6
  "tanstack-intent"
@@ -14,7 +14,7 @@ metadata:
14
14
  task skill to load next.
15
15
  type: core
16
16
  library: '@tinkered/core'
17
- library_version: '0.27.0'
17
+ library_version: '0.27.2'
18
18
  sources:
19
19
  - 'lagz0ne/tinkered:packages/core/src/main.ts'
20
20
  - 'lagz0ne/tinkered:docs/best-practices.md'
@@ -13,7 +13,7 @@ metadata:
13
13
  binding only.
14
14
  type: sub-skill
15
15
  library: '@tinkered/core'
16
- library_version: '0.27.0'
16
+ library_version: '0.27.2'
17
17
  requires:
18
18
  - core
19
19
  sources:
@@ -13,7 +13,7 @@ metadata:
13
13
  cell read only.
14
14
  type: sub-skill
15
15
  library: '@tinkered/core'
16
- library_version: '0.27.0'
16
+ library_version: '0.27.2'
17
17
  requires:
18
18
  - core
19
19
  sources:
@@ -13,7 +13,7 @@ metadata:
13
13
  allowed in app code.
14
14
  type: sub-skill
15
15
  library: '@tinkered/core'
16
- library_version: '0.27.0'
16
+ library_version: '0.27.2'
17
17
  requires:
18
18
  - core
19
19
  sources:
@@ -13,7 +13,7 @@ metadata:
13
13
  on the client with remote data.
14
14
  type: sub-skill
15
15
  library: '@tinkered/core'
16
- library_version: '0.27.0'
16
+ library_version: '0.27.2'
17
17
  requires:
18
18
  - core
19
19
  - capsule
@@ -153,6 +153,59 @@ const list = useData(
153
153
  mutation. To see your own write at once, run
154
154
  `board.invalidate` on its part after the call.
155
155
 
156
+ ### Guard a call or a read
157
+
158
+ A guard is an operation with the input
159
+ `transport.hook.start`. It runs before each call
160
+ or each read of the service it is on.
161
+
162
+ ```ts no-check
163
+ // src/sea/ops.server.ts
164
+ import { operation, tag, transport } from "@tinkered/core";
165
+
166
+ const viewer = tag<string>({ label: "sea.viewer" });
167
+
168
+ export const signedIn = operation({
169
+ label: "sea.signedIn",
170
+ input: transport.hook.start,
171
+ run: (_, { input }) => {
172
+ const who = input.meta.who;
173
+ return who
174
+ ? { tags: [viewer(who)] }
175
+ : input.refuse({ signIn: true });
176
+ },
177
+ });
178
+
179
+ export const inRoom = operation({
180
+ label: "sea.inRoom",
181
+ input: transport.hook.start,
182
+ depends: { me: viewer.required },
183
+ run: ({ me }, { input }) => {
184
+ const room = seaBoard.part(input)?.room ?? "";
185
+ if (!me.startsWith(room)) {
186
+ return input.refuse({ notIn: room });
187
+ }
188
+ },
189
+ });
190
+
191
+ // cmds/server.ts
192
+ sea.board({ serve: true, onStart: [signedIn, inRoom] }),
193
+ sea.api({ implement: seaOps, onStart: [signedIn] }),
194
+ ```
195
+
196
+ - `input.meta` is what the client's backend sent
197
+ with the message: `ws.client({ url, meta })`.
198
+ - `input.refuse(payload)` ends the call. The
199
+ client gets a `refused` fault with the payload.
200
+ - A returned `{ tags }` binds each tag for the
201
+ later guards and for the operation. They take
202
+ it with `depends: { me: viewer.required }`.
203
+ - No return lets the call go on.
204
+ - The guards in `onStart` run in order.
205
+ - On a read, `board.part(input)` gives the key of
206
+ the part the client asks for. Do not read
207
+ `input.input` by hand.
208
+
156
209
  ### Handle a fault
157
210
 
158
211
  A failed call is a fault from a fixed set:
@@ -12,7 +12,7 @@ metadata:
12
12
  and join two scopes with the memory backend.
13
13
  type: sub-skill
14
14
  library: '@tinkered/core'
15
- library_version: '0.27.0'
15
+ library_version: '0.27.2'
16
16
  requires:
17
17
  - core
18
18
  sources: