@weaveprotocol/core 0.2.2 → 0.2.4

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.
Files changed (70) hide show
  1. package/README.md +8 -3
  2. package/dist/index.d.ts +2 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/network/peer-auth.d.ts +19 -0
  7. package/dist/network/peer-auth.d.ts.map +1 -1
  8. package/dist/network/peer-auth.js +22 -8
  9. package/dist/network/peer-auth.js.map +1 -1
  10. package/dist/node/actions.d.ts.map +1 -1
  11. package/dist/node/actions.js +19 -4
  12. package/dist/node/actions.js.map +1 -1
  13. package/dist/node/carrier.d.ts +16 -0
  14. package/dist/node/carrier.d.ts.map +1 -1
  15. package/dist/node/carrier.js +12 -0
  16. package/dist/node/carrier.js.map +1 -1
  17. package/dist/node/index.d.ts +2 -2
  18. package/dist/node/index.d.ts.map +1 -1
  19. package/dist/node/space-runtime.d.ts.map +1 -1
  20. package/dist/node/space-runtime.js +9 -1
  21. package/dist/node/space-runtime.js.map +1 -1
  22. package/dist/node/types.d.ts +4 -0
  23. package/dist/node/types.d.ts.map +1 -1
  24. package/dist/records/describe.d.ts +2 -0
  25. package/dist/records/describe.d.ts.map +1 -1
  26. package/dist/records/describe.js +5 -0
  27. package/dist/records/describe.js.map +1 -1
  28. package/dist/schema/collection-def.d.ts +16 -0
  29. package/dist/schema/collection-def.d.ts.map +1 -1
  30. package/dist/schema/collection-def.js +30 -0
  31. package/dist/schema/collection-def.js.map +1 -1
  32. package/dist/schemas/apps.d.ts +16 -1
  33. package/dist/schemas/apps.d.ts.map +1 -1
  34. package/dist/schemas/apps.js +41 -2
  35. package/dist/schemas/apps.js.map +1 -1
  36. package/dist/schemas/index.d.ts +2 -2
  37. package/dist/schemas/index.d.ts.map +1 -1
  38. package/dist/schemas/index.js +2 -2
  39. package/dist/schemas/index.js.map +1 -1
  40. package/dist/schemas/screens.d.ts +16 -4
  41. package/dist/schemas/screens.d.ts.map +1 -1
  42. package/dist/schemas/screens.js +49 -6
  43. package/dist/schemas/screens.js.map +1 -1
  44. package/dist/session/auth.d.ts +17 -1
  45. package/dist/session/auth.d.ts.map +1 -1
  46. package/dist/session/auth.js +72 -0
  47. package/dist/session/auth.js.map +1 -1
  48. package/dist/session/connect.d.ts +57 -3
  49. package/dist/session/connect.d.ts.map +1 -1
  50. package/dist/session/connect.js +47 -4
  51. package/dist/session/connect.js.map +1 -1
  52. package/dist/session/connection.d.ts +8 -1
  53. package/dist/session/connection.d.ts.map +1 -1
  54. package/dist/session/connection.js +6 -1
  55. package/dist/session/connection.js.map +1 -1
  56. package/dist/session/index.d.ts +3 -3
  57. package/dist/session/index.d.ts.map +1 -1
  58. package/dist/session/index.js +1 -1
  59. package/dist/session/index.js.map +1 -1
  60. package/dist/space/notify.d.ts +58 -0
  61. package/dist/space/notify.d.ts.map +1 -1
  62. package/dist/space/notify.js +91 -0
  63. package/dist/space/notify.js.map +1 -1
  64. package/docs/README.md +49 -0
  65. package/docs/agents.md +59 -0
  66. package/docs/building-an-app.md +162 -0
  67. package/docs/collections.md +151 -0
  68. package/docs/records-and-queries.md +125 -0
  69. package/docs/screens-and-apps.md +129 -0
  70. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"notify.js","sourceRoot":"","sources":["../../src/space/notify.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEvE,wFAAwF;AACxF,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAC9C,uGAAuG;AACvG,MAAM,CAAC,MAAM,uBAAuB,GAAG,kBAAkB,CAAC;AAsC1D,MAAM,UAAU,GAAG,kCAAkC,CAAC;AAEtD,gDAAgD;AAChD,MAAM,UAAU,WAAW,CAAC,I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AAU,KAAK,GAAG,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IACtE,IAAI,OAAO,CAAC,GAAG,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IACvD,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,OAAO,GAAG,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACnH,IAAI,GAAG,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAC5D,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAC1F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/docs/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Building on Weave
2
+
3
+ Short guides for building an app with `@weaveprotocol/core`. They ship in the
4
+ package, so they always match the version installed: an agent working in an
5
+ app's repository finds them at `node_modules/@weaveprotocol/core/docs/`.
6
+
7
+ The package README, one folder up, covers every module in depth. The protocol
8
+ itself (what goes over the wire, what is signed, what every peer checks) is
9
+ specified in `spec/` in the repository: https://github.com/leifriksheim/weave/tree/main/spec
10
+
11
+ ## The model in ten lines
12
+
13
+ - An **account** is a seed the person keeps. Apps never need it.
14
+ - A **node** (`createNode`) is the whole stack in one object: it signs, stores,
15
+ encrypts, checks and syncs. Everything below goes through it.
16
+ - A **space** is a shared place: its members, their roles, and its data.
17
+ Private spaces are encrypted end to end.
18
+ - A **collection** is a named kind of record in a space, like `app.todo.item`.
19
+ Its definition (a JSON Schema, links, rules) is stored in the space itself.
20
+ - A **record** is a signed JSON body with a key that stays the same across
21
+ edits. Every edit is a new version.
22
+ - **Rules** say who may create, edit and delete. Every device checks every
23
+ record that arrives against them, so there is no server to write.
24
+ - **Queries** are plain JSON: Mongo-style filters, sorting, paging, and
25
+ `include` to follow links.
26
+
27
+ ## Guides
28
+
29
+ | Guide | Read it to |
30
+ |---|---|
31
+ | [building-an-app.md](building-an-app.md) | Get a node: sign-in, the account home, React |
32
+ | [collections.md](collections.md) | Say what your data is and who may do what with it |
33
+ | [records-and-queries.md](records-and-queries.md) | Write, edit, delete, query and watch records |
34
+ | [screens-and-apps.md](screens-and-apps.md) | Ship a small app inside a space, with no deploy |
35
+ | [agents.md](agents.md) | Let an agent read and write as the person, from a terminal or MCP |
36
+
37
+ ## Rules of thumb
38
+
39
+ - Import only from the package's entry points: `@weaveprotocol/core`, and
40
+ `/react`, `/session`, `/schemas`, `/elements`, `/calls` for those parts.
41
+ - Name your collections reverse-DNS style, `app.<yours>.<thing>`. `sys.*` is
42
+ the protocol's own, and `std.*` is the shared library in `/schemas`.
43
+ - Check the standard library (`@weaveprotocol/core/schemas`) before defining a
44
+ reaction, comment, tag, message, task or poll of your own. Using the same
45
+ one is how two apps see each other's data.
46
+ - Never keep state outside records if other people should see it. Records are
47
+ what syncs.
48
+ - A refused write throws with the reason in plain words. Show it, or check
49
+ first with `node.records.can` and hide the button.
package/docs/agents.md ADDED
@@ -0,0 +1,59 @@
1
+ # Agents
2
+
3
+ An agent reads and writes as the person, with a note from their account that
4
+ every peer checks. What it writes shows as theirs, "via agent", everywhere.
5
+ It never gets the seed, and it can't do what needs a person: define
6
+ collections, change roles, invite, join or leave spaces.
7
+
8
+ ## Every operation, described once
9
+
10
+ Every node operation is in `NODE_ACTIONS`: a name, a sentence and a JSON
11
+ Schema for its input. The CLI, the MCP server and the browser's WebMCP tools
12
+ are all generated from it.
13
+
14
+ ```typescript
15
+ import { NODE_ACTIONS, runAction } from '@weaveprotocol/core';
16
+
17
+ await runAction(node, 'records_put', { space, collection: 'app.todo.item', body: { text: 'milk' } });
18
+ ```
19
+
20
+ `records_query` takes the same plain-JSON query as `node.records.query`
21
+ ([records-and-queries.md](records-and-queries.md)).
22
+
23
+ ## Connecting an agent to someone's account
24
+
25
+ From `@weaveprotocol/cli`, the `weave` command:
26
+
27
+ ```bash
28
+ npx @weaveprotocol/cli connect wv_… # the code from "Connect an agent" in an app
29
+ ```
30
+
31
+ It makes a key for this computer's agent, waits while the person allows it at
32
+ their account home, and adds `weave mcp` to Claude Code, Claude Desktop and
33
+ Cursor where it finds them. The agent is then a node of its own: it follows
34
+ the account's spaces and keeps working with every tab closed.
35
+
36
+ ## Tools an agent gets
37
+
38
+ `node_info`, `spaces_list`, `spaces_status`, `spaces_preview_invite`, `spaces_access`, `spaces_profiles`,
39
+ `collections_list`, `records_query`, `records_list`, `records_get`,
40
+ `records_linked`, `records_history`, `records_can`, `records_put`,
41
+ `records_update`, `records_delete`, and for new tools: `apps_list`,
42
+ `apps_propose`, `apps_screen_guide`.
43
+
44
+ To make something new, an agent proposes an app (`apps_propose`): the
45
+ collections it needs and, optionally, a screen for each. The person reads what
46
+ it would do and adds it. See [screens-and-apps.md](screens-and-apps.md).
47
+
48
+ ## In your own code
49
+
50
+ `node.asAgent({ keys, note })` gives the same node acting as an agent, from an
51
+ agent's note issued by the account home. Everything it writes is signed under
52
+ that note.
53
+
54
+ ## Working on a Weave app with a coding agent
55
+
56
+ These guides ship inside the package so an agent in your repository can read
57
+ them at `node_modules/@weaveprotocol/core/docs/`, matched to the installed
58
+ version. A line in your project's `AGENTS.md` or `CLAUDE.md` pointing there is
59
+ enough.
@@ -0,0 +1,162 @@
1
+ # Building an app
2
+
3
+ An app needs a node. There are two ways to get one, and they end in the same
4
+ place: a `P2PNode` you read and write through.
5
+
6
+ ## Connect to the person's account home (recommended)
7
+
8
+ The app never sees the account's seed. It asks the person's account home for
9
+ access, the person picks which spaces it gets, and the home signs a note from
10
+ the account to a key the app made for itself. Every peer checks that note, so
11
+ the app cannot write anywhere it was not given.
12
+
13
+ ```tsx
14
+ import { createWeaveConnection } from '@weaveprotocol/core/session';
15
+ import { WeaveProvider, useConnection } from '@weaveprotocol/core/react';
16
+
17
+ const connection = createWeaveConnection({
18
+ home: 'https://weave-home.netlify.app/connect', // a suggestion: the person may use their own
19
+ request: {
20
+ name: 'Todo',
21
+ access: 'write', // or 'read'
22
+ scope: 'spaces', // or 'account', for every space
23
+ create: [{ name: 'Todos', visibility: 'private' }],
24
+ },
25
+ network: { relays: ['wss://p2p-web-relay.fly.dev'] },
26
+ });
27
+
28
+ createRoot(root).render(
29
+ <WeaveProvider connection={connection}>
30
+ <App />
31
+ </WeaveProvider>,
32
+ );
33
+
34
+ function App() {
35
+ const { connection, state } = useConnection();
36
+ if (state.status !== 'ready') return <button onClick={() => connection.connect()}>Connect with Weave</button>;
37
+ return <Todos />;
38
+ }
39
+ ```
40
+
41
+ - The grant lasts seven days and is remembered between visits. When it runs
42
+ out, `state.status` is `expired`, and connecting again renews it.
43
+ - `scope: 'spaces'` gives the spaces the person picks, plus any the app asked
44
+ to `create`. `scope: 'account'` gives every space, and lets the app make and
45
+ join spaces. Ask for the narrower one unless the app is a view onto
46
+ everything.
47
+ - Without React: `connectToHome`, `startConnectedNode` and `grantStore` from
48
+ `@weaveprotocol/core/session`.
49
+
50
+ ## Sign in inside the app
51
+
52
+ For an app that holds the account itself. The flow (where data lives, which
53
+ account, password or passkey, creating one, pairing a phone) ships as an
54
+ element and as a React component.
55
+
56
+ ```html
57
+ <weave-auth app-name="Todo" relays="wss://p2p-web-relay.fly.dev"></weave-auth>
58
+ <script type="module">
59
+ import '@weaveprotocol/core/elements';
60
+ document.querySelector('weave-auth').addEventListener('weave-session', (event) => {
61
+ const session = event.detail.session; // { account, did, sessionDid, node }, or null
62
+ if (session) start(session.node);
63
+ });
64
+ </script>
65
+ ```
66
+
67
+ ```tsx
68
+ import { createWeaveAuth } from '@weaveprotocol/core/session';
69
+ import { WeaveProvider, WeaveAuth, useWeave } from '@weaveprotocol/core/react';
70
+
71
+ const auth = createWeaveAuth({ appName: 'Todo', network: { relays: ['wss://p2p-web-relay.fly.dev'] } });
72
+
73
+ function App() {
74
+ const { state } = useWeave();
75
+ if (state?.stage !== 'ready') return <WeaveAuth />;
76
+ return <Todos />;
77
+ }
78
+
79
+ createRoot(root).render(<WeaveProvider auth={auth}><App /></WeaveProvider>);
80
+ ```
81
+
82
+ ## A node by hand
83
+
84
+ For scripts, tests and servers:
85
+
86
+ ```typescript
87
+ import { createNode, createIdentityManager, createLocalRootSigner, indexedDBStores, rolePresets } from '@weaveprotocol/core';
88
+
89
+ const manager = createIdentityManager();
90
+ const me = await manager.fromRecoveryCode(code);
91
+
92
+ const node = await createNode({
93
+ signer: createLocalRootSigner(me, manager.getProvider()),
94
+ stores: indexedDBStores('my-app'),
95
+ network: { relays: ['wss://p2p-web-relay.fly.dev'] },
96
+ });
97
+ ```
98
+
99
+ Leave out `network` to stay offline. Call `node.close()` when done.
100
+
101
+ ## Spaces
102
+
103
+ ```typescript
104
+ const space = await node.spaces.create({ name: 'Groceries', visibility: 'private', ...rolePresets.team });
105
+
106
+ const invite = await node.spaces.invite(space.id); // a link-safe string; treat it as a secret
107
+ const view = await node.spaces.invite(space.id, { write: false }); // read-only
108
+ await node.spaces.join(invite); // on the friend's side
109
+ await node.spaces.closeInvite(space.id, invite); // nobody else joins with it
110
+ ```
111
+
112
+ - `rolePresets`: `solo` (just you; invites are view-only), `team` (everyone
113
+ invited can write, invite and add collections), `community` (admins,
114
+ moderators, members). Or pass your own `roles`.
115
+ - A private invite carries the space key. Anyone holding it can read the
116
+ space, so don't log it or put it in a URL a server sees (use the fragment,
117
+ `#invite=…`).
118
+ - `node.spaces.list()` gives every space this node has, with `readable`,
119
+ `writable` and `role`.
120
+
121
+ ## React hooks
122
+
123
+ All from `@weaveprotocol/core/react`, below a `WeaveProvider`:
124
+
125
+ | Hook | Gives |
126
+ |---|---|
127
+ | `useNode()` | The node, to write with |
128
+ | `useSpaces()` | The spaces, kept current, with `create`, `join`, `leave` |
129
+ | `useQuery(space, query)` | `{ result, error }`, re-run as records change here or arrive from peers |
130
+ | `useRecord(space, key)` / `useLinked(space, key)` | One record; the records pointing at it |
131
+ | `useCollections(space)` / `useProfiles(space)` / `useAccess(space)` | What a space holds; who is in it; roles and members |
132
+ | `useSpaceStatus(space)` | Connection and peers |
133
+ | `useCan(space, action, target)` | Whether to show an edit or delete button |
134
+ | `useHoldSpace(space)` | Keeps a space syncing while the view is on screen |
135
+ | `useLive(space, load, deps)` | Anything else, reloaded as the space changes |
136
+
137
+ ```tsx
138
+ function Todos({ space }: { space: string }) {
139
+ const node = useNode();
140
+ const { result } = useQuery(space, { collection: todos, sort: { '@createdAt': 'asc' } });
141
+ if (!result) return null;
142
+ if (!result.complete && result.records.length === 0) return <p>Loading…</p>;
143
+ return result.records.map((todo) => <Todo key={todo.key} todo={todo} />);
144
+ }
145
+ ```
146
+
147
+ `result.complete` is false while an app that holds only part of a space is
148
+ still fetching a collection. Show "Loading…", not "Nothing here".
149
+
150
+ ## Live messages
151
+
152
+ For things that should reach whoever is connected now and be kept nowhere,
153
+ like typing or presence:
154
+
155
+ ```typescript
156
+ await node.spaces.send(space.id, { type: 'typing' });
157
+ node.subscribe((event) => {
158
+ if (event.type === 'message') console.log(event.from, event.message); // from: the sender's account
159
+ });
160
+ ```
161
+
162
+ At most 64 KB each. Someone who isn't connected misses it.
@@ -0,0 +1,151 @@
1
+ # Collections
2
+
3
+ A collection is a named kind of record in a space. Its definition is stored in
4
+ the space as a signed record, so another app, or an agent, can open the space
5
+ and know what its data means without your code.
6
+
7
+ ```typescript
8
+ import * as z from 'zod'; // or Valibot, ArkType, or plain JSON Schema
9
+ import { collection } from '@weaveprotocol/core';
10
+
11
+ const Poll = z.object({
12
+ question: z.string().min(1).max(500),
13
+ options: z.array(z.string().min(1)).min(2).max(10),
14
+ });
15
+
16
+ export const polls = collection({
17
+ name: 'app.poll',
18
+ title: 'Poll',
19
+ schema: Poll,
20
+ permissions: ['moderate'],
21
+ rules: {
22
+ edit: 'creator',
23
+ delete: ['creator', 'can:moderate'],
24
+ fixed: ['options'],
25
+ },
26
+ });
27
+
28
+ await node.collections.define(space.id, polls);
29
+ ```
30
+
31
+ `collection(…)` only keeps the definition's types, so queries and writes that
32
+ name `polls` are typed from the schema. Pass it where a collection name goes.
33
+
34
+ ## Names
35
+
36
+ Reverse-DNS, lower case, at least two parts: `app.poll`, `com.example.recipe`.
37
+ Letters, digits and `-` in each part. `sys.*` is the protocol's own and
38
+ `std.*` is the standard library.
39
+
40
+ ## Schemas
41
+
42
+ What gets stored is JSON Schema, in a small subset every app agrees on:
43
+
44
+ `type`, `properties`, `required`, `items`, `enum`, `const`, `minimum`,
45
+ `maximum`, `minLength`, `maxLength`, `minItems`, `maxItems`,
46
+ `additionalProperties` (true or false), `title`, `description`
47
+
48
+ and two that say what a value means, so any app can show it well:
49
+
50
+ - `oneOf: [{ const, title }]`: fixed choices with labels.
51
+ - `x-choicesFrom: { rel, field }`: the value picks from a list in the record
52
+ this one links to. A vote's `choice` picks from its poll's `options`.
53
+
54
+ Anything else, like `pattern` or `format`, is refused when you define the
55
+ collection, with the reason. A Zod `.regex()` or `.email()` fails for that
56
+ reason. Validators that can describe themselves as JSON Schema work directly:
57
+ Zod 4.2+, ArkType 2.1.28+, Valibot with `toStandardJsonSchema`.
58
+
59
+ A record that doesn't fit the schema is still kept and synced, and comes back
60
+ with `conforms: false`. Shape is checked when you write, not enforced on
61
+ arrival, because two peers may have seen different versions of a definition.
62
+ Rules, below, are enforced everywhere.
63
+
64
+ ## Links
65
+
66
+ Records point at each other with links: `{ rel: 'about', to: <record key> }`.
67
+ A definition declares the roles its records may carry:
68
+
69
+ ```typescript
70
+ links: {
71
+ about: { to: ['app.poll'], cardinality: 'one' }, // only at polls, at most one
72
+ mentions: { to: '*' }, // at anything, many
73
+ },
74
+ ```
75
+
76
+ A link role is lower camel case. Queries follow links with `include`
77
+ ([records-and-queries.md](records-and-queries.md)).
78
+
79
+ ## Rules
80
+
81
+ | Rule | Means | Default |
82
+ |---|---|---|
83
+ | `create` | Who may create a record | `member` |
84
+ | `edit` | Who may write later versions | `member` |
85
+ | `delete` | Who may delete | same as `edit` |
86
+ | `onePer` | At most one record per combination of these | none |
87
+ | `fixed` | Fields that keep the value the record was created with | none |
88
+
89
+ Who is one of these, or a list meaning any of them:
90
+
91
+ - `member`: anyone holding a role in the space.
92
+ - `creator`: whoever wrote the record's first version. Not allowed for `create`.
93
+ - `can:<permission>`: someone whose role holds a permission the collection
94
+ declares in `permissions`. `can:moderate` in `app.poll` is the permission
95
+ `app.poll/moderate`.
96
+
97
+ `onePer` names `@author` (the writer), `link:<rel>` (the record a link points
98
+ at) or a body field. It works by construction: the record's key is derived
99
+ from those values, so a second vote from the same person on the same poll is
100
+ the first vote's next version, not a new record.
101
+
102
+ ```typescript
103
+ rules: { edit: 'creator', delete: 'creator', onePer: ['@author', 'link:about'] } // one vote per person per poll
104
+ ```
105
+
106
+ ## Roles
107
+
108
+ Roles live in the space, not in your code. Each has a name, a rank and a list
109
+ of permissions:
110
+
111
+ ```typescript
112
+ await node.spaces.putRole(space.id, {
113
+ name: 'host', title: 'Host', rank: 50,
114
+ permissions: ['invite', 'app.poll/moderate'],
115
+ });
116
+ await node.spaces.setMember(space.id, did, 'host');
117
+ ```
118
+
119
+ - `*` alone is every permission. `*/*` is every permission any collection
120
+ declares, so a moderator can moderate every app in the space.
121
+ - Space permissions include `invite`, `define` (add or change collections)
122
+ and `manage`.
123
+ - You can only change people and roles ranked below your own.
124
+
125
+ ## Other options
126
+
127
+ - `history: 'all'` keeps every version of every record, hash-linked
128
+ (`node.records.history`). The default, `latest`, keeps the current one.
129
+ - `topics: ['channel']` lets a node that can't read the space still match
130
+ records by that field's value, for notifications. At most 8.
131
+ - `screen`: a small UI for the collection's records. See
132
+ [screens-and-apps.md](screens-and-apps.md).
133
+ - `version`: defining again bumps it. Records keep the version they were
134
+ written under.
135
+
136
+ ## The standard library
137
+
138
+ ```typescript
139
+ import { reaction, comment, poll, vote, useSchemas } from '@weaveprotocol/core/schemas';
140
+
141
+ await useSchemas(node, space.id, [poll, vote, reaction, comment]); // defines only what the space is missing
142
+ ```
143
+
144
+ Annotations that attach to any record: `reaction`, `comment`, `tag`,
145
+ `attachment`, `reference`. Common nouns: `message`, `column`, `task`, `poll`,
146
+ `vote`, `call`. They are ordinary collections. Using the same one is how two
147
+ apps agree: a poll asked in one can be voted on in another.
148
+
149
+ Hand-made order (cards on a board) uses a `position` string.
150
+ `positionBetween(before, after)` makes one that sorts between two others, so
151
+ moving a card rewrites only that card.
@@ -0,0 +1,125 @@
1
+ # Records and queries
2
+
3
+ A record is a JSON body in a collection of a space, signed by whoever wrote
4
+ it. Its `key` stays the same across edits, and links point at the key. Every
5
+ edit is a new version.
6
+
7
+ ## Writing
8
+
9
+ ```typescript
10
+ const todo = await node.records.put(space.id, todos, { text: 'milk', done: false });
11
+
12
+ await node.records.update(space.id, todo.key, { text: 'milk', done: true }); // the whole body, not a patch
13
+ await node.records.delete(space.id, todo.key);
14
+ ```
15
+
16
+ - `put` makes a new record with a random key, unless you give one
17
+ (`{ key }`). A chosen key suits a record there is one of by nature, like a
18
+ settings record.
19
+ - `update` takes the whole next body. Links carry over unless you pass new
20
+ ones.
21
+ - `delete` writes a version marked deleted, which syncs like any other.
22
+ - Pass a definition made with `collection(…)` instead of a name, and the body
23
+ is type-checked as you write it.
24
+ - A write this account isn't allowed to make throws, with the reason in plain
25
+ words. Nothing is signed. `node.records.can(space, 'edit', key)` asks first.
26
+
27
+ Which version wins is decided by `seq` (one higher each edit), then by version
28
+ id, never by a clock. Two devices that edited apart agree on the same winner.
29
+ Merging edits inside one record is not built yet, so design records so that
30
+ people edit different ones: one record per vote, per card, per reaction.
31
+
32
+ ## Links
33
+
34
+ ```typescript
35
+ await node.records.put(space.id, votes, { choice: 0 }, {
36
+ links: [{ rel: 'about', to: poll.key }],
37
+ });
38
+
39
+ const all = await node.records.linked(space.id, poll.key, { rel: 'about' });
40
+ ```
41
+
42
+ The roles a record may carry are declared on its collection
43
+ ([collections.md](collections.md)).
44
+
45
+ ## What a record looks like
46
+
47
+ ```typescript
48
+ {
49
+ key, version, seq, space, collection,
50
+ body, // null when encrypted and this node has no key
51
+ links, // [{ rel, to }]
52
+ root, // the account that wrote this version
53
+ createdBy, // the account that created the record
54
+ createdAt, updatedAt, // the writer's clock: for display only
55
+ verified, // signature, delegation and shape check out
56
+ conforms, // fits the collection's schema (null when there is none)
57
+ viaAgent, // true when an agent wrote it for the account
58
+ }
59
+ ```
60
+
61
+ Show `root` or `createdBy` as the author, not `author`, which is the session
62
+ key that signed. `node.spaces.profiles(space)` maps accounts to names.
63
+
64
+ ## Queries
65
+
66
+ A query is plain JSON, so an agent can write one, and it can cross a wire.
67
+
68
+ ```typescript
69
+ const { records, cursor, complete } = await node.records.query(space.id, {
70
+ collection: polls,
71
+ where: { closed: { $ne: true }, question: { $contains: 'may' } },
72
+ sort: { '@createdAt': 'desc' },
73
+ limit: 20,
74
+ include: {
75
+ votes: { rel: 'about', from: votes }, // records linking to each poll
76
+ reactions: { rel: 'about', from: 'std.reaction', count: true },
77
+ },
78
+ });
79
+ ```
80
+
81
+ - **Fields.** A bare name is a field of the body (`done`, `address.city`). A
82
+ name starting with `@` is about the record: `@key`, `@author`, `@root`,
83
+ `@createdBy`, `@createdAt`, `@updatedAt`, `@seq`.
84
+ - **Operators.** `$eq`, `$ne` (true for a missing field too), `$gt`, `$gte`,
85
+ `$lt`, `$lte`, `$in`, `$nin`, `$exists`, `$contains` (a case-insensitive
86
+ substring, or an element of a list). Combine with `$and`, `$or`, `$not`. A
87
+ bare value means `$eq`.
88
+ - **Sort** by several fields in order. Ties break on the key.
89
+ - **Paging.** Pass the `cursor` back to get the next page. It is null on the
90
+ last one.
91
+ - **Include** follows links. `direction: 'in'` (the default) finds records
92
+ linking to this one, `'out'` the ones it links to. Each include takes its own
93
+ `where`, `limit`, nested `include`, or `count: true` for just the number.
94
+ What it finds is on each record's `included`.
95
+ - Name collections by their definitions and the results are typed, includes
96
+ too.
97
+ - `complete` is false while a node that holds only part of a space is still
98
+ fetching a collection the query needs. Show "Loading…", not "Nothing here".
99
+ - A malformed query throws, saying what to fix.
100
+
101
+ This is not full-text search: `$contains` is a substring match.
102
+
103
+ ## Watching
104
+
105
+ ```typescript
106
+ const stop = node.records.watch(space.id, query, (result) => render(result));
107
+ stop();
108
+ ```
109
+
110
+ It runs now and again whenever the space's records change, here or from a
111
+ peer. In React, `useQuery(space, query)` does the same.
112
+
113
+ For anything else, subscribe to the node's events:
114
+
115
+ ```typescript
116
+ const unsubscribe = node.subscribe((event) => {
117
+ if (event.type === 'records') reload(event.space);
118
+ });
119
+ ```
120
+
121
+ ## History
122
+
123
+ `node.records.history(space, key)` gives the versions this node keeps, newest
124
+ first: the current one and the first one, or every one in a collection defined
125
+ with `history: 'all'`.