logic-sdk 0.6.2 → 0.6.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "logic-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Queries, mutations, actions and events for TypeScript apps. Transactions, after-commit events and scopes, on any runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"actions",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"drizzle-orm": ">=1.0.0-rc.6 <2",
|
|
114
114
|
"pg-boss": ">=12.39.0 <13",
|
|
115
115
|
"ai": ">=7 <8",
|
|
116
|
-
"@logic-sdk/cli": ">=0.6.
|
|
116
|
+
"@logic-sdk/cli": ">=0.6.3 <0.7.0"
|
|
117
117
|
},
|
|
118
118
|
"peerDependenciesMeta": {
|
|
119
119
|
"@orpc/server": {
|
|
@@ -22,7 +22,7 @@ src/
|
|
|
22
22
|
actions.ts action({...}) network calls: payments, email, AI, webhooks out
|
|
23
23
|
events.ts event({...}) things that happened
|
|
24
24
|
listeners.ts listener({...}) reacting to OTHER modules' events
|
|
25
|
-
data.ts private: helpers taking ctx (findBooking(ctx, id)), can* record checks, and functions
|
|
25
|
+
data.ts private: helpers taking ctx (findBooking(ctx, id)), can* record checks, and private functions two files share. The index never re-exports it; other modules never import it.
|
|
26
26
|
schema.ts tables this module owns. Other modules never read them.
|
|
27
27
|
<module>.test.ts
|
|
28
28
|
```
|
|
@@ -64,7 +64,7 @@ export const cancel = mutation({
|
|
|
64
64
|
1. **Pick the kind by what it touches.** Only reads: `query`. Writes to our database: `mutation`. Talks to the network: `action`. Reacts to another module: `listener`.
|
|
65
65
|
2. **Never put side effects in a mutation or query.** No email, HTTP or payments. They don't have `services` on purpose. Emit an event and react in a listener, or write an action that runs the mutation.
|
|
66
66
|
3. **Call other modules only with `run(otherModule.fn, input)`.** Import them as `import * as availability from "../availability"`. Never import their `data.ts` or `schema.ts`, from a module or from routes and pages.
|
|
67
|
-
4. **Within a module, use helpers.** Shared logic is a plain function in `data.ts` taking `ctx`. `ctx.run` your own module's function only when you want its `authorize`, validation and tracing. When an action must write,
|
|
67
|
+
4. **Within a module, use helpers.** Shared logic is a plain function in `data.ts` taking `ctx`. `ctx.run` your own module's function only when you want its `authorize`, validation and tracing. When an action must write, define the mutation in the action's own file without `export` and `ctx.run` it: nothing outside the file can reach it, so nothing can skip the action's checks. When two files need the same one, put it in `data.ts`, never in `mutations.ts`: exporting it from there for the other file makes `export * from "./mutations"` publish it. A private function can't be scheduled, run by a cron, published or run from a test: test it through the action.
|
|
68
68
|
5. **Always filter by `ctx.scope.accountId`** in `data.ts` helpers, writes included. Loading helpers throw `ctx.errors.notFound()`. Scope is who and where (actor, account, locale); input is what.
|
|
69
69
|
6. **Authorize every function a user, client or AI tool may call.** `authorize: member` (a policy from `policies.ts`) says who may call it: sync, reads only scope, runs on every call including nested ones. Publish a function by listing it in `src/rpc.ts` (`toORPCProcedure(fn)`) or an agent's tools (`toAITool(caller, fn)`); both refuse one without `authorize`. A hand-written route or Server Action can `caller.run` anything, nothing stops it: only call functions that have `authorize` from them. Give published functions an `output` so nothing unintended leaves.
|
|
70
70
|
7. **Record rules are `can*` predicates.** Load through a scoped helper, then `if (!canX(ctx.scope.actor, record)) throw ctx.errors.deny();`. `can*` is sync, its result is always used, and the same predicate feeds UI flags in list queries: `can: { cancel: canCancel(actor, b) }`. A rule that must hold at commit goes in the write's `WHERE` or a `FOR UPDATE` re-select.
|