@tinkered/core 0.27.0 → 0.27.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/package.json
CHANGED
package/skills/core/SKILL.md
CHANGED
package/skills/core/rpc/SKILL.md
CHANGED
|
@@ -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.
|
|
16
|
+
library_version: '0.27.1'
|
|
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:
|