@graview/ship 0.1.38 → 0.1.40

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 (66) hide show
  1. package/README.md +38 -3
  2. package/dist/browser-adapter.d.ts +73 -16
  3. package/dist/browser-adapter.d.ts.map +1 -1
  4. package/dist/browser-adapter.js +425 -24
  5. package/dist/browser-adapter.js.map +1 -1
  6. package/dist/browser.d.ts +2 -1
  7. package/dist/browser.d.ts.map +1 -1
  8. package/dist/browser.js +1 -1
  9. package/dist/browser.js.map +1 -1
  10. package/dist/cli.d.ts +3 -3
  11. package/dist/cli.d.ts.map +1 -1
  12. package/dist/cli.js +125 -36
  13. package/dist/cli.js.map +1 -1
  14. package/dist/dev.d.ts +2 -0
  15. package/dist/dev.d.ts.map +1 -1
  16. package/dist/dev.js +1 -0
  17. package/dist/dev.js.map +1 -1
  18. package/dist/index.d.ts +6 -4
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +4 -3
  21. package/dist/index.js.map +1 -1
  22. package/dist/indexed-entries.d.ts +54 -0
  23. package/dist/indexed-entries.d.ts.map +1 -0
  24. package/dist/indexed-entries.js +60 -0
  25. package/dist/indexed-entries.js.map +1 -0
  26. package/dist/open-store.d.ts +21 -2
  27. package/dist/open-store.d.ts.map +1 -1
  28. package/dist/open-store.js +86 -9
  29. package/dist/open-store.js.map +1 -1
  30. package/dist/photos.d.ts +4 -3
  31. package/dist/photos.d.ts.map +1 -1
  32. package/dist/photos.js +4 -3
  33. package/dist/photos.js.map +1 -1
  34. package/dist/preview-app.d.ts +38 -0
  35. package/dist/preview-app.d.ts.map +1 -0
  36. package/dist/preview-app.js +54 -0
  37. package/dist/preview-app.js.map +1 -0
  38. package/dist/runtime.d.ts +2 -2
  39. package/dist/runtime.d.ts.map +1 -1
  40. package/dist/runtime.js +1 -1
  41. package/dist/runtime.js.map +1 -1
  42. package/dist/serve-preview.d.ts +24 -3
  43. package/dist/serve-preview.d.ts.map +1 -1
  44. package/dist/serve-preview.js +22 -11
  45. package/dist/serve-preview.js.map +1 -1
  46. package/dist/serve.d.ts +11 -1
  47. package/dist/serve.d.ts.map +1 -1
  48. package/dist/serve.js +31 -4
  49. package/dist/serve.js.map +1 -1
  50. package/dist/shots.d.ts +3 -1
  51. package/dist/shots.d.ts.map +1 -1
  52. package/dist/shots.js +16 -6
  53. package/dist/shots.js.map +1 -1
  54. package/dist/source-aliases.d.ts +57 -0
  55. package/dist/source-aliases.d.ts.map +1 -0
  56. package/dist/source-aliases.js +82 -0
  57. package/dist/source-aliases.js.map +1 -0
  58. package/dist/store-hold.d.ts +4 -0
  59. package/dist/store-hold.d.ts.map +1 -1
  60. package/dist/store-hold.js +12 -0
  61. package/dist/store-hold.js.map +1 -1
  62. package/dist/sync-seed.d.ts +21 -0
  63. package/dist/sync-seed.d.ts.map +1 -1
  64. package/dist/sync-seed.js +57 -2
  65. package/dist/sync-seed.js.map +1 -1
  66. package/package.json +2 -2
package/README.md CHANGED
@@ -13,8 +13,11 @@ declaration plus one persistence adapter is a running deployment.
13
13
  - **`createFileAdapter(root)`** — persistence a person can read: `snapshot.json`,
14
14
  append-only `log.jsonl`, `meta.json` with the stored schema version. The core's sqlite
15
15
  adapter is the scale answer; this is the "where is my data" answer.
16
- - **`createBrowserAdapter()`** — the same three things in `localStorage`, for an app that
17
- runs in the page with no server: the sample apps remember their edits through it,
16
+ - **`createBrowserAdapter()`** — the same three things in IndexedDB, for an app that
17
+ runs in the page with no server (a store kept in `localStorage` before is carried forward on
18
+ its first open, and `localStorage` is used only where IndexedDB will not open). An edit is
19
+ kept when `apply` returns: a journal in `localStorage` holds what IndexedDB has not committed
20
+ yet, and the next open puts it back, so a page left at once loses nothing. The sample apps remember their edits through it,
18
21
  attributed and undoable, migrations included. Import from `@graview/ship/browser` in a
19
22
  bundle (the root entry carries the file adapter's `node:fs`). Conventions the helpers
20
23
  read: `?fresh=1` returns to the seed (`openStore({ fresh })`), and a driven browser
@@ -42,7 +45,7 @@ declaration plus one persistence adapter is a running deployment.
42
45
  `Response`, for any runtime: a Cloudflare Worker or Durable Object, Deno, Bun. `serveStore`
43
46
  is a thin `node:http` wrapper around it. Import it from `@graview/ship/runtime`, the entry
44
47
  that reaches no `node:` builtin: the store, migrations, the handler and `openRemote`, without
45
- the file adapter or the page's localStorage. A host that opens, migrates and heals its own
48
+ the file adapter or the page's own storage. A host that opens, migrates and heals its own
46
49
  `Store` hands it over instead of an adapter: `createStoreHandler({ app, store, seatOf, flush })`.
47
50
  - **Content moves as steps.** The step DSL (`stepsMigration`) has five content steps beside
48
51
  the schema ones — `put-node`, `patch-node`, `drop-node`, `put-edge`, `drop-edge` — each
@@ -469,6 +472,38 @@ the rules broken after. It writes, logs and tells nothing, and spends no id the
469
472
  const would = store.previewAll(calls, { author: seat, via, admit: (planned) => caps(seat, planned) });
470
473
  ```
471
474
 
475
+ ## The framework from its sources
476
+
477
+ An app that runs Graview from a checkout in development — the framework's own
478
+ apps, or a product linked to a sibling checkout by path — points its bundler at
479
+ each package's `src`, so an edit to the framework is live without a build.
480
+ `sourceAliases(root?)` on `@graview/ship/dev` reads those aliases from every
481
+ package's own `exports`, one per entry point, so a new subpath export reaches
482
+ every such app without a line in its config:
483
+
484
+ ```ts
485
+ import { sourceAliases } from "@graview/ship/dev";
486
+ import { fileURLToPath } from "node:url";
487
+
488
+ export default defineConfig({
489
+ resolve: {
490
+ dedupe: ["react", "react-dom", "react-router-dom"],
491
+ // The sibling checkout; left out, the one this @graview/ship was loaded from.
492
+ alias: sourceAliases(fileURLToPath(new URL("../graview", import.meta.url))),
493
+ },
494
+ });
495
+ ```
496
+
497
+ Each export of `./dist/<path>.js` is aliased to `src/<path>.ts` (or `.tsx`),
498
+ and a file shipped as it is (`@graview/guest/client.js`, the primitives' fonts)
499
+ to that file. Each alias matches its specifier exactly, so `@graview/core`
500
+ never swallows `@graview/core/words`; a built file with no source
501
+ (`@graview/core/document.schema.json`) is left to ordinary resolution. It is an
502
+ array, so an app's own aliases follow it: `[...sourceAliases(), { find, replacement }]`.
503
+ `sourceEntries(root?)` lists the same exports with the file each runs from.
504
+ It is for development only: an installed `@graview/ship` carries no `src`, and
505
+ `sourceAliases` throws there rather than answer an empty list.
506
+
472
507
  ## The hosted-store contract
473
508
 
474
509
  A third party stands up their own host — a file store or SQLite, `graview serve`,
@@ -1,5 +1,6 @@
1
- import type { PersistenceAdapter, Principal } from "@graview/core";
1
+ import type { Operation, PersistenceAdapter, Principal } from "@graview/core";
2
2
  import type { StoredMeta } from "./meta.js";
3
+ import { type IDBFactoryLike } from "./indexed-entries.js";
3
4
  /**
4
5
  * The slice of `Storage` this adapter needs — `localStorage` in a browser,
5
6
  * a `Map` dressed as one in a test or a node rehearsal. Declared here rather
@@ -11,36 +12,92 @@ export interface StorageLike {
11
12
  removeItem(key: string): void;
12
13
  }
13
14
  export interface BrowserAdapter extends PersistenceAdapter<string> {
14
- loadMeta(scope: string): StoredMeta | null;
15
- saveMeta(scope: string, meta: StoredMeta): void;
16
- /** The storage keys this scope occupies — for a person or a test to look. */
15
+ loadMeta(scope: string): Promise<StoredMeta | null>;
16
+ saveMeta(scope: string, meta: StoredMeta): Promise<void>;
17
+ /**
18
+ * The keys this scope occupies — for a person or a test to look. In
19
+ * IndexedDB they are keys of the `entries` store of the `graview`
20
+ * database, and the log is kept in pieces: `log` holds how many, and
21
+ * `log:0`, `log:1`, … each hold the ops one write appended.
22
+ */
17
23
  keysFor(scope: string): {
18
24
  snapshot: string;
19
25
  log: string;
20
26
  meta: string;
27
+ through: string;
28
+ journal: string;
21
29
  };
30
+ /**
31
+ * THE WRITE-AHEAD JOURNAL, under `journal` in localStorage: the ops
32
+ * applied whose IndexedDB write has not committed yet, written
33
+ * synchronously the moment they are applied (`openStore` calls this
34
+ * inside the apply). IndexedDB's own write lands a transaction later,
35
+ * and a page that navigates or closes first would lose it. An op is let
36
+ * go of once the log has committed it and a snapshot that reflects it
37
+ * has (the snapshot is kept with `through`, the seq of the last op it
38
+ * reflects). Throws when localStorage refuses even that, and `openStore`
39
+ * reports it. Absent where the store is kept in localStorage alone.
40
+ */
41
+ journal?(scope: string, ops: readonly Operation[]): void;
42
+ /** What the journal holds for a scope, and the seq of the last op the stored snapshot reflects (-1: none), for `openStore` to replay. */
43
+ loadJournal?(scope: string): Promise<{
44
+ ops: readonly Operation[];
45
+ through: number;
46
+ }>;
47
+ /** Where this adapter keeps a store: IndexedDB, or localStorage where IndexedDB would not open or would not take it. */
48
+ keptIn(): Promise<"indexedDB" | "localStorage">;
22
49
  }
23
50
  export interface BrowserAdapterOptions {
24
- /** Defaults to the page's `localStorage`. */
51
+ /**
52
+ * The localStorage a store kept before IndexedDB is read from, and the
53
+ * one a store is kept in where IndexedDB would not open. Defaults to the
54
+ * page's `localStorage`. Passed WITHOUT `indexedDB`, it is the only
55
+ * storage: a `Map` dressed as one in a test or a node rehearsal.
56
+ */
25
57
  readonly storage?: StorageLike;
58
+ /** Defaults to the page's `indexedDB`, unless `storage` alone was passed. */
59
+ readonly indexedDB?: IDBFactoryLike;
26
60
  /** Key prefix, so two apps on one origin do not read each other's graph. */
27
61
  readonly prefix?: string;
28
62
  }
63
+ /** The IndexedDB database every scope is kept in, its keys the same as localStorage's were. */
64
+ export declare const BROWSER_DATABASE = "graview";
29
65
  /**
30
66
  * Persistence in the browser itself: the SAME things the file adapter
31
67
  * writes — the snapshot, the append-only log, the stored schema version —
32
- * as three `localStorage` entries per scope. Not the epochs (FR-27): each
33
- * keeps a whole copy of the graph as its base, and a second copy in a few
34
- * megabytes ran a two-thousand-talk program out of room; a page's store
35
- * is verified by the host it is served from, not in the page. It slots into `openStore` unchanged, migrations included, so a
36
- * sample app that remembers is the
37
- * same lifecycle as a deployment that does, minus the server.
68
+ * kept in IndexedDB. Not the epochs (FR-27): each keeps a whole copy of
69
+ * the graph as its base, and a page's store is verified by the host it is
70
+ * served from, not in the page. It slots into `openStore` unchanged,
71
+ * migrations included, so a sample app that remembers is the same
72
+ * lifecycle as a deployment that does, minus the server.
38
73
  *
39
- * `localStorage` is synchronous and small (a few megabytes an origin), which
40
- * is exactly right for a demo or a single person's graph and exactly wrong
41
- * for a shared deployment — that is what the file and sqlite adapters are
42
- * for. If a log outgrows it the honest next step is IndexedDB behind this
43
- * same interface, not a bigger string.
74
+ * INDEXEDDB, BECAUSE A STORE OUTGROWS LOCALSTORAGE. localStorage is a few
75
+ * megabytes an origin, and WebKit counts each character twice: the
76
+ * gauntlet's 2.8 MB seed did not fit in Safari, so the store opened and
77
+ * kept nothing. IndexedDB holds hundreds of megabytes in every engine, and
78
+ * an append writes the ops it appends rather than the whole log again. It
79
+ * is the default rather than where a store spills when localStorage is
80
+ * full, so where a store is kept never depends on how big it once grew.
81
+ *
82
+ * A STORE KEPT IN LOCALSTORAGE IS CARRIED FORWARD, not lost: the first
83
+ * time a scope is read, what localStorage holds for it is written into
84
+ * IndexedDB in one transaction, and only once that transaction has
85
+ * committed is it removed from localStorage. When the write fails, the
86
+ * store stays where it was and this adapter keeps it there; when IndexedDB
87
+ * will not open at all (a locked-down browser), it is localStorage as
88
+ * before.
89
+ *
90
+ * The database opens on the first read, not when the adapter is made, and
91
+ * every read and write waits for the ones asked for before it.
92
+ *
93
+ * A WRITE IS KEPT WHEN `apply` RETURNS, not when IndexedDB commits it: an
94
+ * IndexedDB write lands a transaction later, and a person who changed
95
+ * something and left the page at once lost it. `openStore` writes each op
96
+ * to a journal in localStorage (`<prefix>:<scope>:journal`) inside the
97
+ * apply, synchronously; the journal holds only the ops IndexedDB has not
98
+ * committed yet, and the next open puts back what it holds, each op once
99
+ * (the snapshot is kept with `<prefix>:<scope>:through`, the seq of the
100
+ * last op it reflects).
44
101
  *
45
102
  * A write that fails (quota, a locked-down browser) THROWS, and `openStore`
46
103
  * reports it: an app that believes it remembered and did not is the worst
@@ -1 +1 @@
1
- {"version":3,"file":"browser-adapter.d.ts","sourceRoot":"","sources":["../src/browser-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa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