attodo-sync 0.0.0-stage → 0.1.0

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.
Binary file
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/package.json CHANGED
@@ -1,6 +1,57 @@
1
1
  {
2
2
  "name": "attodo-sync",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "The attodo sync engine for JavaScript: to-dos on atproto permissioned spaces, compiled from Rust to WebAssembly",
5
+ "keywords": [
6
+ "atproto",
7
+ "sync",
8
+ "todo",
9
+ "crdt",
10
+ "wasm"
11
+ ],
12
+ "license": "MIT OR Apache-2.0",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/orta/todos.at.git",
16
+ "directory": "rust/attodo-wasm/npm"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "node": {
21
+ "types": "./node/attodo_sync.d.ts",
22
+ "default": "./node/attodo_sync.js"
23
+ },
24
+ "default": {
25
+ "types": "./web/index.d.ts",
26
+ "default": "./web/index.js"
27
+ }
28
+ },
29
+ "./web": {
30
+ "types": "./web/attodo_sync.d.ts",
31
+ "default": "./web/attodo_sync.js"
32
+ },
33
+ "./package.json": "./package.json"
34
+ },
35
+ "main": "./node/attodo_sync.js",
36
+ "types": "./node/attodo_sync.d.ts",
37
+ "files": [
38
+ "README.md",
39
+ "node/attodo_sync.d.ts",
40
+ "node/attodo_sync.js",
41
+ "node/attodo_sync_bg.wasm",
42
+ "node/package.json",
43
+ "web/attodo_sync.d.ts",
44
+ "web/attodo_sync.js",
45
+ "web/attodo_sync_bg.wasm",
46
+ "web/index.d.ts",
47
+ "web/index.js",
48
+ "web/package.json"
49
+ ],
50
+ "engines": {
51
+ "node": ">=22"
52
+ },
53
+ "scripts": {
54
+ "build": "node build.mjs",
55
+ "prepack": "node -e \"require('fs').accessSync('node/attodo_sync_bg.wasm'); require('fs').accessSync('web/attodo_sync_bg.wasm')\""
56
+ }
57
+ }
@@ -0,0 +1,368 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /** Where a new to-do goes, or when to do one (SPEC §6.1). In a shared list, `inbox` means `anytime`. */
5
+ export type When = 'inbox' | 'today' | 'evening' | 'tomorrow' | 'anytime' | 'someday'
6
+ export type SpaceKind = 'personal' | 'shared'
7
+ /** A record value in the data model's JSON form (`$link`, `$bytes`), as `@atproto/lex-json` reads and writes it. */
8
+ export type JsonValue = null | boolean | number | string | JsonValue[] | { [key: string]: JsonValue | undefined }
9
+
10
+ /** A to-do or project. `space` is a space reference (`at:space/…`), `collection` an NSID. */
11
+ export type ObjectRef = { space: string; collection: string; id: string }
12
+ /** An object in a list, with the date (`YYYY-MM-DD`) that placed it there, if any. */
13
+ export type Listed = { object: ObjectRef; date?: string }
14
+ /** The lists of SPEC §6. `today` includes `evening`. */
15
+ export type Lists = {
16
+ inbox: Listed[]; today: Listed[]; evening: Listed[]; upcoming: Listed[]
17
+ anytime: Listed[]; someday: Listed[]; logbook: Listed[]; trash: Listed[]
18
+ }
19
+ /** What a list shows for one to-do or project. */
20
+ export type Row = {
21
+ object: ObjectRef
22
+ title: string
23
+ notes?: string
24
+ /** `open`, `completed` or `canceled`. */
25
+ state: string
26
+ /** The date that placed it in the list, or else its scheduled date. */
27
+ date?: string
28
+ deadline?: string
29
+ evening: boolean
30
+ trashed: boolean
31
+ /** Its project's title. */
32
+ project?: string
33
+ /** The list's title, for a to-do in a shared list. */
34
+ spaceTitle?: string
35
+ }
36
+ /** A space this device syncs. `readOnly`: the user lost access; what was synced is kept. */
37
+ export type SpaceInfo = { space: string; kind: SpaceKind; title: string; readOnly: boolean }
38
+
39
+ /** A problem: a stable name (`Transport:Network`, `AccessLost:SpaceDeleted`, `Pull:Gap`…) and a description. */
40
+ export type Problem = { name: string; message: string }
41
+ /** What one `syncSpace` did. Nothing in it needs handling: it's for showing. */
42
+ export type SyncReport = {
43
+ pull: {
44
+ pulled: string[]
45
+ /** Repos re-read from a verified snapshot, and why. */
46
+ resynced: { repo: string; reason: Problem }[]
47
+ /** Repos that couldn't be read this time. */
48
+ failed: { repo: string; error: Problem }[]
49
+ }
50
+ flush: {
51
+ written: number
52
+ /** Writes the host refused (§8.5): dropped, and kept on the device for the user to see. */
53
+ rejected: { path: RecordPath; error: string; title?: string }[]
54
+ /** Records too large to write: they stay unsent. */
55
+ oversized: RecordPath[]
56
+ /** Background writes held back to keep the rate-limit reserve for edits. */
57
+ deferred: number
58
+ /** Why the flush stopped early, if it did. Unsent changes go next time. */
59
+ stopped?: Problem
60
+ }
61
+ }
62
+
63
+ export type RecordPath = { collection: string; rkey: string }
64
+ export type TransportError =
65
+ /** No response: the request may or may not have been applied. */
66
+ | { kind: 'network'; message: string }
67
+ /** A 5xx response, or one that doesn't parse or verify. */
68
+ | { kind: 'server'; status: number; message: string }
69
+ /** A 429: wait at least this long. */
70
+ | { kind: 'rateLimited'; retryAfterMs: number }
71
+ /** Any other XRPC error, by name (`RecordNotFound`, `InvalidRecord`, `SpaceDeleted`…). */
72
+ | { kind: 'xrpc'; status: number; error: string; message: string }
73
+ export type Result<T> = { ok: true; value: T } | { ok: false; error: TransportError }
74
+ /** An entry of `listWriters`; `repoRev` is absent for `repoRemoved`. TIDs are strings. */
75
+ export type WriterEntry = { repo: string; spaceRev: string; repoRev?: string }
76
+ export type WritersPage = { entries: WriterEntry[]; cursor?: string }
77
+ /** `com.atproto.space.defs#commit`, in its JSON form. */
78
+ export type Commit = { ver: number; repo: string; space: string; rev: string; data: { $bytes: string } }
79
+ /** `com.atproto.space.listRepoOps#opEntry`. CIDs are strings. */
80
+ export type OpEntry = { rev: string; path: RecordPath; cid?: string; prev?: string; value?: JsonValue }
81
+ export type OpsPage = { ops: OpEntry[]; commit: Commit; cursor?: string }
82
+ /** Every record of a repo, and the commit they should match. */
83
+ export type Snapshot = { commit: Commit; records: { path: RecordPath; cid: string; value: JsonValue }[] }
84
+ export type Write =
85
+ | { action: 'create' | 'update'; path: RecordPath; value: JsonValue }
86
+ | { action: 'delete'; path: RecordPath }
87
+ /** `RateLimit-*` headers; `resetMs` is epoch milliseconds. */
88
+ export type RateLimit = { limit: number; remaining: number; resetMs: number }
89
+ export type WriteOk = { rateLimit?: RateLimit }
90
+
91
+ /**
92
+ * The hosts, as the engine calls them (SPEC §8.2). An app implements this
93
+ * over its atproto client: it routes each call to the right host and
94
+ * handles OAuth, space credentials, request signatures and response MACs.
95
+ * Answer with a `Result`; a method that throws counts as a network error.
96
+ */
97
+ export interface Transport {
98
+ /** `listWriters` at the space host. `since` is a space revision. */
99
+ listWriters(space: string, since: string | undefined, cursor: string | undefined): Result<WritersPage> | Promise<Result<WritersPage>>
100
+ /** `listRepoOps` at the writer's PDS, its commit's MAC already checked. */
101
+ listRepoOps(space: string, repo: string, since: string, cursor: string | undefined): Result<OpsPage> | Promise<Result<OpsPage>>
102
+ /** `getRecord`: `value` absent for `RecordNotFound`. */
103
+ getRecord(space: string, repo: string, path: RecordPath): Result<{ cid: string; value: JsonValue } | undefined> | Promise<Result<{ cid: string; value: JsonValue } | undefined>>
104
+ /** A full copy of a repo (`getRepo`, or `listRecords` with `getLatestCommit`). */
105
+ getSnapshot(space: string, repo: string): Result<Snapshot> | Promise<Result<Snapshot>>
106
+ /** `applyWrites` to the user's own repo, as one atomic batch. */
107
+ applyWrites(space: string, writes: Write[]): Result<WriteOk> | Promise<Result<WriteOk>>
108
+ }
109
+
110
+ export type SavedOwnState = { record: JsonValue } | { exact: JsonValue } | 'delete'
111
+ export type SavedWriter = {
112
+ status: 'active' | { removed: { adoptAfterMs: number } }
113
+ listedRev?: string
114
+ /** The last verified commit: its rev, and the LtHash state (base64). */
115
+ head?: { rev: string; state: string }
116
+ /** By `collection/rkey`. */
117
+ records: { [path: string]: { cid: string; value: JsonValue } }
118
+ inactive?: string
119
+ }
120
+ /** A saved device (`Device.toJson`): plain JSON, to store as it is. */
121
+ export type DeviceJson = {
122
+ format: 1
123
+ me: string
124
+ clockId: number
125
+ /** A u64, in decimal. */
126
+ seed: string
127
+ budget: { blockedUntilMs: number; last?: RateLimit }
128
+ spaces: {
129
+ space: string
130
+ kind: SpaceKind
131
+ spaceRev?: string
132
+ access: 'readWrite' | { lost: { reason: string; retryAtMs: number } }
133
+ unlisted: boolean
134
+ writers: { [did: string]: SavedWriter }
135
+ own: { [path: string]: { state: SavedOwnState; userEdit: boolean } }
136
+ rejected: { [path: string]: { state: SavedOwnState; error: string } }
137
+ }[]
138
+ }
139
+
140
+ /** Thrown by an edit the engine refuses. `code`: `ReadOnly`, `NotFound`, `Deleted`, `TooLarge`, `InvalidValue`, `UnknownSpace`… */
141
+ export interface EditFailure extends Error { name: 'EditFailure'; code: string }
142
+ /** How `syncSpace` rejects when it can't sync the space at all. `code` is a `Problem` name. */
143
+ export interface SyncFailure extends Error { name: 'SyncFailure'; code: string }
144
+
145
+
146
+
147
+ /**
148
+ * One device's replica of the user's spaces.
149
+ */
150
+ export class Device {
151
+ free(): void;
152
+ [Symbol.dispose](): void;
153
+ /**
154
+ * Starts syncing a space; nothing if it's already synced.
155
+ */
156
+ addSpace(space: string, kind: SpaceKind): void;
157
+ /**
158
+ * Adds a to-do, with a fresh id from this device's clock.
159
+ */
160
+ addTodo(space: string, title: string, when: When, today: string, nowMicros: number): ObjectRef;
161
+ /**
162
+ * Deletes for good: every app stops showing it.
163
+ */
164
+ deleteForever(object: ObjectRef, nowMicros: number): void;
165
+ /**
166
+ * A device `toJson` saved. Throws on anything that doesn't read back
167
+ * exactly, rather than half-loading it.
168
+ */
169
+ static fromJson(saved: DeviceJson): Device;
170
+ /**
171
+ * The lists (SPEC §6) on `today` (`YYYY-MM-DD`, the user's local date).
172
+ */
173
+ lists(today: string): Lists;
174
+ /**
175
+ * A new device for the account `me`. `clockId` (0–1023) is this
176
+ * install's TID clock id, chosen at random once; `seed` seeds the
177
+ * jitter of its retries.
178
+ */
179
+ constructor(me: string, clockId: number, seed: bigint);
180
+ /**
181
+ * How many of the user's records have changes not yet on the hosts.
182
+ */
183
+ pending(): number;
184
+ personalSpace(): string | undefined;
185
+ /**
186
+ * What a list shows for each of `listed`.
187
+ */
188
+ rows(listed: Listed[], today: string): Row[];
189
+ /**
190
+ * When to do something: its own schedule in the personal space; in a
191
+ * shared list, the user's plan for it, which the others don't see.
192
+ */
193
+ schedule(object: ObjectRef, when: When, today: string, nowMicros: number): void;
194
+ /**
195
+ * Sets the notes; empty notes clear them.
196
+ */
197
+ setNotes(object: ObjectRef, notes: string, nowMicros: number): void;
198
+ setTitle(object: ObjectRef, title: string, nowMicros: number): void;
199
+ /**
200
+ * Every active to-do and project of one space, projects first, each in
201
+ * its order: a shared list's own list.
202
+ */
203
+ spaceList(space: string): Listed[];
204
+ /**
205
+ * "Personal", a shared list's title, or else its key.
206
+ */
207
+ spaceTitle(space: string): string;
208
+ /**
209
+ * Every space this device syncs.
210
+ */
211
+ spaces(): SpaceInfo[];
212
+ /**
213
+ * Syncs one space: pulls every writer, then sends the user's changes.
214
+ * Rejects with a `SyncFailure` only if the space couldn't be synced at
215
+ * all; problems with single repos or writes are in the report. Edits
216
+ * made meanwhile apply at once and are kept.
217
+ */
218
+ syncSpace(transport: Transport, space: string, nowMicros: number): Promise<SyncReport>;
219
+ /**
220
+ * The device's state, to keep between runs.
221
+ */
222
+ toJson(): DeviceJson;
223
+ /**
224
+ * Completes an open to-do, or reopens a closed one.
225
+ */
226
+ toggleDone(object: ObjectRef, nowMicros: number): void;
227
+ /**
228
+ * Moves to the Trash, or (`trashed: false`) puts back.
229
+ */
230
+ trash(object: ObjectRef, trashed: boolean, nowMicros: number): void;
231
+ readonly clockId: number;
232
+ /**
233
+ * The account's DID.
234
+ */
235
+ readonly me: string;
236
+ /**
237
+ * Whether a `syncSpace` is running.
238
+ */
239
+ readonly syncing: boolean;
240
+ }
241
+
242
+ /**
243
+ * An in-memory atproto network: a PDS per account and a space host,
244
+ * behaving as the reference implementations do. For demos and tests.
245
+ */
246
+ export class SimNetwork {
247
+ free(): void;
248
+ [Symbol.dispose](): void;
249
+ /**
250
+ * Lets `did` write to the space again.
251
+ */
252
+ allowWriter(space: string, did: string): void;
253
+ /**
254
+ * A transport for the account `did`.
255
+ */
256
+ client(did: string): SimTransport;
257
+ /**
258
+ * A space; `writers` and `readers` are the DIDs allowed (omitted:
259
+ * anyone, as for a personal space, which only its owner writes).
260
+ */
261
+ createSpace(space: string, writers?: string[] | null, readers?: string[] | null): void;
262
+ /**
263
+ * Fails a call `did` makes with `error`, unapplied: the next one, or
264
+ * the one after `skip` more have gone through.
265
+ */
266
+ fail(did: string, error: TransportError, skip?: number | null): void;
267
+ /**
268
+ * Applies the next `applyWrites` by `did`, but loses its response.
269
+ */
270
+ loseResponse(did: string): void;
271
+ constructor();
272
+ /**
273
+ * Takes `did` out of the space's writers.
274
+ */
275
+ removeWriter(space: string, did: string): void;
276
+ }
277
+
278
+ /**
279
+ * One account's view of a `SimNetwork`: a `Transport`. It answers through
280
+ * the same JSON boundary a real transport does.
281
+ */
282
+ export class SimTransport {
283
+ private constructor();
284
+ free(): void;
285
+ [Symbol.dispose](): void;
286
+ applyWrites(space: string, writes: Write[]): Promise<Result<WriteOk>>;
287
+ getRecord(space: string, repo: string, path: RecordPath): Promise<Result<{ cid: string; value: JsonValue } | undefined>>;
288
+ getSnapshot(space: string, repo: string): Promise<Result<Snapshot>>;
289
+ listRepoOps(space: string, repo: string, since: string, cursor?: string | null): Promise<Result<OpsPage>>;
290
+ listWriters(space: string, since?: string | null, cursor?: string | null): Promise<Result<WritersPage>>;
291
+ }
292
+
293
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
294
+
295
+ export interface InitOutput {
296
+ readonly memory: WebAssembly.Memory;
297
+ readonly __wbg_device_free: (a: number, b: number) => void;
298
+ readonly __wbg_simnetwork_free: (a: number, b: number) => void;
299
+ readonly __wbg_simtransport_free: (a: number, b: number) => void;
300
+ readonly device_addSpace: (a: number, b: number, c: number, d: number, e: number) => [number, number];
301
+ readonly device_addTodo: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number];
302
+ readonly device_clockId: (a: number) => [number, number, number];
303
+ readonly device_deleteForever: (a: number, b: any, c: number) => [number, number];
304
+ readonly device_fromJson: (a: any) => [number, number, number];
305
+ readonly device_lists: (a: number, b: number, c: number) => [number, number, number];
306
+ readonly device_me: (a: number) => [number, number, number, number];
307
+ readonly device_new: (a: number, b: number, c: number, d: bigint) => [number, number, number];
308
+ readonly device_pending: (a: number) => [number, number, number];
309
+ readonly device_personalSpace: (a: number) => [number, number, number, number];
310
+ readonly device_rows: (a: number, b: any, c: number, d: number) => [number, number, number];
311
+ readonly device_schedule: (a: number, b: any, c: number, d: number, e: number, f: number, g: number) => [number, number];
312
+ readonly device_setNotes: (a: number, b: any, c: number, d: number, e: number) => [number, number];
313
+ readonly device_setTitle: (a: number, b: any, c: number, d: number, e: number) => [number, number];
314
+ readonly device_spaceList: (a: number, b: number, c: number) => [number, number, number];
315
+ readonly device_spaceTitle: (a: number, b: number, c: number) => [number, number, number, number];
316
+ readonly device_spaces: (a: number) => [number, number, number];
317
+ readonly device_syncSpace: (a: number, b: any, c: number, d: number, e: number) => any;
318
+ readonly device_syncing: (a: number) => number;
319
+ readonly device_toJson: (a: number) => [number, number, number];
320
+ readonly device_toggleDone: (a: number, b: any, c: number) => [number, number];
321
+ readonly device_trash: (a: number, b: any, c: number, d: number) => [number, number];
322
+ readonly simnetwork_allowWriter: (a: number, b: number, c: number, d: number, e: number) => [number, number];
323
+ readonly simnetwork_client: (a: number, b: number, c: number) => number;
324
+ readonly simnetwork_createSpace: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
325
+ readonly simnetwork_fail: (a: number, b: number, c: number, d: any, e: number) => [number, number];
326
+ readonly simnetwork_loseResponse: (a: number, b: number, c: number) => void;
327
+ readonly simnetwork_new: () => number;
328
+ readonly simnetwork_removeWriter: (a: number, b: number, c: number, d: number, e: number) => [number, number];
329
+ readonly simtransport_applyWrites: (a: number, b: number, c: number, d: any) => [number, number, number];
330
+ readonly simtransport_getRecord: (a: number, b: number, c: number, d: number, e: number, f: any) => [number, number, number];
331
+ readonly simtransport_getSnapshot: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
332
+ readonly simtransport_listRepoOps: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number, number];
333
+ readonly simtransport_listWriters: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
334
+ readonly wasm_bindgen__convert__closures_____invoke__h0cf8a5a2756bd9cd: (a: number, b: number, c: any, d: any) => void;
335
+ readonly wasm_bindgen__convert__closures_____invoke__hd6da796ca7e1484e: (a: number, b: number, c: any) => [number, number];
336
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
337
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
338
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
339
+ readonly __wbindgen_exn_store: (a: number) => void;
340
+ readonly __externref_table_alloc: () => number;
341
+ readonly __wbindgen_externrefs: WebAssembly.Table;
342
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
343
+ readonly __externref_table_dealloc: (a: number) => void;
344
+ readonly __externref_drop_slice: (a: number, b: number) => void;
345
+ readonly __wbindgen_start: () => void;
346
+ }
347
+
348
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
349
+
350
+ /**
351
+ * Instantiates the given `module`, which can either be bytes or
352
+ * a precompiled `WebAssembly.Module`.
353
+ *
354
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
355
+ *
356
+ * @returns {InitOutput}
357
+ */
358
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
359
+
360
+ /**
361
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
362
+ * for everything else, calls `WebAssembly.instantiate` directly.
363
+ *
364
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
365
+ *
366
+ * @returns {Promise<InitOutput>}
367
+ */
368
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;