@relate/contrib-web 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +242 -2
- package/conformance/example-site/blank.html +2 -0
- package/conformance/example-site/broken.html +35 -0
- package/conformance/example-site/index.html +35 -0
- package/conformance/example-site/notes.html +35 -0
- package/conformance/example-site/page-1.html +35 -0
- package/conformance/example-site/page-2.html +35 -0
- package/conformance/example-site/public/descriptor-b.json +16 -0
- package/conformance/example-site/public/descriptor-broken.json +16 -0
- package/conformance/example-site/public/descriptor-mismatch.json +16 -0
- package/conformance/example-site/public/descriptor.json +16 -0
- package/conformance/example-site/public/graph-b.json +14408 -0
- package/conformance/example-site/public/graph.json +10808 -0
- package/conformance/example-site/rel-page.ts +147 -0
- package/conformance/example-site/vite.config.ts +23 -0
- package/conformance/make-example.ts +22 -0
- package/conformance/run.ts +152 -0
- package/conformance/scenarios.ts +285 -0
- package/package.json +81 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 The Relate Authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,243 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @relate/contrib-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The name follows the `@relate` namespace; see `design/notes/2026-11-08-relate-contrib-rename.md`.
|
|
4
|
+
|
|
5
|
+
Hosts a small embedded graph database (the engine's browser build, `@relate/relate-wasm`) in a web page. The database runs in a
|
|
6
|
+
dedicated worker behind a client, so loading and querying never block the page. A crash, a timeout or a
|
|
7
|
+
failed load is contained: the worker is replaced, subscriptions re-run, and after three failed attempts the
|
|
8
|
+
client reports `failed` and the page keeps working. The package is framework-agnostic; a framework adapter
|
|
9
|
+
only wires it into that framework's build and rendering.
|
|
10
|
+
|
|
11
|
+
Decisions behind it: `design/adr/ADR-001` (worker hosting, two navigation profiles), `ADR-002` (the graph data
|
|
12
|
+
format), `ADR-003` (the graph descriptor). The specification and plan are in `specs/001-core-package/`.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pnpm add @relate/contrib-web @relate/relate-wasm
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`@relate/relate-wasm` is a peer dependency. Until it is published to npm this repository vendors a
|
|
21
|
+
pinned build (see `vendor/README.md`). The package has no other runtime dependency.
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import engineUrl from "@relate/relate-wasm/relate_bg.wasm?url"; // the bundler places the binary
|
|
27
|
+
import { createSiteClient, attachView } from "@relate/contrib-web";
|
|
28
|
+
|
|
29
|
+
const client = createSiteClient({
|
|
30
|
+
engineUrl, // where the engine's binary is served from
|
|
31
|
+
graph: { descriptor: "/graph/descriptor.json" }, // or { document } for a graph given as data
|
|
32
|
+
navigation: "client-routing", // or "multi-page"
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Components subscribe; there is no retry code. The listener hears the status, the generation and the rows.
|
|
36
|
+
client.subscribe("MATCH (p:Page) RETURN count(p) AS pages", null, ({ status, rows }) => {
|
|
37
|
+
if (rows) show(rows[0].pages); else showPlaceholder(status);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Data that belongs to one page view: added on arrival, dropped on departure, added again after a replacement.
|
|
41
|
+
const view = attachView(client, { version: 1, nodes: [{ id: "note", labels: ["Note"] }], links: [] });
|
|
42
|
+
// ...on leaving the page:
|
|
43
|
+
await view.detach();
|
|
44
|
+
|
|
45
|
+
// A statement typed by a visitor has a timeout and a stop control.
|
|
46
|
+
const run = client.run(statementFromTheBox);
|
|
47
|
+
stopButton.onclick = () => run.stop();
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A page's first render must not depend on the instance, and navigation must work without it. Results are the
|
|
51
|
+
engine's JSON envelope, unaltered (`columns`, `rows`, `stats`, `error`, ...); an engine error arrives in
|
|
52
|
+
`error`, it does not throw.
|
|
53
|
+
|
|
54
|
+
## Navigation profiles
|
|
55
|
+
|
|
56
|
+
| `navigation` | Profile | Instance | Store |
|
|
57
|
+
|---|---|---|---|
|
|
58
|
+
| `client-routing` | persistent | one for the visit, held in module state | off unless `store: true` |
|
|
59
|
+
| `multi-page` | per-page | one per page, started by that page | on when the graph has a descriptor |
|
|
60
|
+
|
|
61
|
+
`createSiteClient` returns the visit's one client under `client-routing` and a new client per call under
|
|
62
|
+
`multi-page`. `createClient` always makes a new, independent client (a page may have several).
|
|
63
|
+
|
|
64
|
+
## Graph data
|
|
65
|
+
|
|
66
|
+
- **Data document** (`graph-data.schema.json`): `{ version: 1, nodes: [{ id, labels?, properties? }], links: [{ source, target, type, properties? }] }`.
|
|
67
|
+
Properties live only under `properties`. Validate in a build step with `import { validate } from "@relate/contrib-web/validate"`.
|
|
68
|
+
- **Descriptor** (`graph-descriptor.schema.json`): `{ version: 1, id, revision, data: { url, nodes, links }, indexes? }`, served beside the
|
|
69
|
+
data. With a descriptor, a store can be restored without fetching the data when the `revision` has not
|
|
70
|
+
changed (the cache's record is its entry in the catalog, below). Without one there is no store and no revision.
|
|
71
|
+
|
|
72
|
+
## Failure
|
|
73
|
+
|
|
74
|
+
`client.status` is `loading`, `ready`, `recovering` or `failed`. In `failed`, `client.diagnostic` says why,
|
|
75
|
+
`client.failureMessage()` gives wording that suggests reporting an issue (at `issueUrl` if you set it; nothing is
|
|
76
|
+
sent by the package), and `client.retry()` starts again.
|
|
77
|
+
|
|
78
|
+
## Application graphs
|
|
79
|
+
|
|
80
|
+
A graph the visitor writes (an admin tool's records, a notes editor, a game save) is an *application graph*: one
|
|
81
|
+
named, durable graph in the browser, seeded once and carried forward by migrations. It is a different mode of
|
|
82
|
+
`createClient`, with its own store (`app-<name>`). Decided in ADR-009; the record of what the store holds is a catalog
|
|
83
|
+
entry (ADR-010, below); the tests are in `tests/application/` and `tests/catalog/`.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { createClient, inRanges } from "@relate/contrib-web";
|
|
87
|
+
|
|
88
|
+
const client = createClient({
|
|
89
|
+
engineUrl,
|
|
90
|
+
navigation: "client-routing", // or "multi-page"; application mode does not depend on it
|
|
91
|
+
application: {
|
|
92
|
+
name: "notes", // [A-Za-z0-9_-]{1,60}; two applications on one origin must not share a name
|
|
93
|
+
version: 2, // the schema version this code expects; a positive integer
|
|
94
|
+
seed: seedDocumentOrDescriptorOrUrl, // loaded once, on first run, never over stored data
|
|
95
|
+
indexes: [{ label: "Note", property: "title" }], // for a plain-document seed; created on first run only
|
|
96
|
+
migrations: { // target version -> ordered steps; keys are 2..version, consecutive
|
|
97
|
+
2: [
|
|
98
|
+
inRanges({
|
|
99
|
+
label: "Note", property: "n", step: 500,
|
|
100
|
+
statement: "MATCH (x:Note) WHERE x.n >= $from AND x.n < $to AND x.slug IS NULL SET x.slug = toLower(x.title)",
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
// onUnavailable: "memory" | "fail" (default "memory") no browser store
|
|
105
|
+
// onError: "fail" | "memory" (default "fail") the store could not be opened
|
|
106
|
+
// whenLocked: "wait" | "memory" (default "wait") another tab holds the store
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Options are checked when the client is created; a bad name, version, migration key or step throws and starts
|
|
112
|
+
nothing. Query results are the engine's envelope, unaltered.
|
|
113
|
+
|
|
114
|
+
**What the store holds.** The graph holds only your data: no bookkeeping node, so a count of all nodes is the seed's plus
|
|
115
|
+
the visitor's. The core records the application's schema version and state in its entry in the catalog (see *The
|
|
116
|
+
catalog*), written before data changes and confirmed after, so an interrupted first run, migration, import or reset is
|
|
117
|
+
recognised on the next open.
|
|
118
|
+
|
|
119
|
+
**Failures.** The client is `failed` with `client.diagnostic.reason` one of these, and the stored data is left as it is:
|
|
120
|
+
|
|
121
|
+
| Reason | Meaning |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `store-unmarked` | data with no catalog entry (not created by this application, or its entry was removed); a node labelled `_RelateApplication`, the record an earlier form kept in the graph, is named in the message |
|
|
124
|
+
| `store-newer` | written by a newer version than this code, or the catalog is of a newer format |
|
|
125
|
+
| `import-interrupted` | an import did not finish |
|
|
126
|
+
| `store-lost` | the entry says the store was filled and it is empty: its data is gone |
|
|
127
|
+
| `store-unreadable` | the store could not be opened, or the catalog does not parse, or this application's entry is malformed; for a catalog, see `resetCatalog()` |
|
|
128
|
+
| `unavailable` | no browser store (or no Web Locks) and `onUnavailable: "fail"` |
|
|
129
|
+
| `migration-failed` | a step failed or a version has no migration; the message names the version, and the store is at the last completed version |
|
|
130
|
+
|
|
131
|
+
None of them is retried automatically. `client.resetApplication()` discards the stored data and seeds again; it is
|
|
132
|
+
the only call that does (besides the recovery of a first run or reset that never finished). Offer an export before it.
|
|
133
|
+
A catalog that does not parse, or is of a newer format, is never written over, so `resetApplication()` cannot recover
|
|
134
|
+
from it either: use `resetCatalog()` for a catalog that does not parse (see below). An application whose seed had no
|
|
135
|
+
nodes records that, and its empty store is valid; it cannot notice that the records the visitor added are gone.
|
|
136
|
+
|
|
137
|
+
**Storage.** `client.storage` is `{ kind, reason?, persisted }` and `client.on("storage", fn)` hears changes.
|
|
138
|
+
`durable`: writes reach the store. `waiting` with reason `locked`: another tab holds the store; the client stays
|
|
139
|
+
`loading`, retries every second and keeps queries pending (before the first report `kind` is `waiting` with no reason:
|
|
140
|
+
nothing has been opened yet). `memory` with reason `unavailable`, `locked` or `error`: the data is not stored; a
|
|
141
|
+
client in memory never becomes durable. `persisted` is the browser's `navigator.storage.persisted()` or `null`.
|
|
142
|
+
The core never asks for persistent storage: call `client.requestPersistence()` from a user action (Chromium and
|
|
143
|
+
WebKit refused it, and Firefox shows a prompt that can leave the promise pending in the tests' browsers). `client.storageEstimate()`
|
|
144
|
+
returns `{ usage, quota }`. A page ends its worker on `pagehide`, so the next page of a multi-page site finds the store free.
|
|
145
|
+
|
|
146
|
+
**Export and import.** `await client.exportApplication({ allowLoss })` returns `{ envelope, losses }`; the envelope is
|
|
147
|
+
`{ format: "relate-application-export", version: 1, application: { name, version }, document }` with the graph data
|
|
148
|
+
format's document, sorted so that export, import and export agree. The format cannot carry everything the engine
|
|
149
|
+
stores, so the report counts, by kind: `integer-beyond-2^53` (written as the nearest number), `whole-number-float`
|
|
150
|
+
(written as an integer), `date` and `duration` (written as text), `point` and `empty-list` (left out) and
|
|
151
|
+
`node-without-string-id` (the node and its relationships are left out; `droppedLinks` counts them). Without
|
|
152
|
+
`allowLoss: true` the call rejects with a `GraphError` of reason `export-loss` that carries the report. `await
|
|
153
|
+
client.importApplication(envelope)` rejects an envelope for another name or a newer version, validates the whole
|
|
154
|
+
document, then marks the store `importing`, resets it, loads the document, marks it `ready` and migrates. It does not
|
|
155
|
+
export first, and the core never calls it. A page stopped between the reset and the load leaves `importing`, so the next
|
|
156
|
+
open fails `import-interrupted` and never seeds over the emptied store.
|
|
157
|
+
|
|
158
|
+
**The rule for migrations.** The core cannot make a migration atomic: a statement over many nodes can be partly applied
|
|
159
|
+
if the worker is stopped. Write each step bounded, each safe to run again (a `WHERE` that skips what is done), and rely
|
|
160
|
+
on the core to record the version after each version's last step. `inRanges` runs your statement over windows
|
|
161
|
+
`[$from, $to)` of a numeric property; the statement must carry its own filter. A failing step leaves the store at the last
|
|
162
|
+
completed version and the next load resumes there. Every version from the stored one up to the application's needs an
|
|
163
|
+
entry: a missing one fails with `migration-failed` naming the version, and the version is not advanced. The core keeps
|
|
164
|
+
nothing in the graph, so a statement that reaches every node, such as `MATCH (n) SET …`, is valid as it stands.
|
|
165
|
+
|
|
166
|
+
**A content graph and an application graph on one page** use two clients, each with its own worker and store; no
|
|
167
|
+
statement spans them.
|
|
168
|
+
|
|
169
|
+
## The catalog
|
|
170
|
+
|
|
171
|
+
The core keeps one record per persisted graph, content caches and application graphs alike, in one file,
|
|
172
|
+
`relate-web/catalog.json`, beside the engine's `relate/` directory (ADR-010). Every read and write takes the Web Lock
|
|
173
|
+
`relate-web:catalog` (shared to read, exclusive to write), so several tabs lose no update. A browser with the file storage
|
|
174
|
+
but no Web Locks counts as having no storage. An entry has a `kind` (`application` or `cache`), a `name`, a `state`
|
|
175
|
+
(`ready`, or `seeding`, `migrating`, `importing`, `resetting`, `loading` or `removing` for an operation started and not yet
|
|
176
|
+
confirmed), `updatedAt`, and, for an application, `version` and `seeded`, or, for a cache, `revision`. A cache restores only
|
|
177
|
+
from a `ready` entry at the descriptor's revision over a store with all its nodes; anything else rebuilds, and a catalog that
|
|
178
|
+
cannot be used never fails the page: the cache is loaded in memory, leaving the durable store and the catalog as they were. The core removes only a stale cache's contents and a
|
|
179
|
+
leftover `relate-web/<id>.json`; it never removes an application graph.
|
|
180
|
+
|
|
181
|
+
Three calls are exported. None opens a store, and each needs the origin-private storage and Web Locks (`CatalogError` with
|
|
182
|
+
reason `unavailable` otherwise).
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { listGraphs, removeGraph, resetCatalog } from "@relate/contrib-web";
|
|
186
|
+
|
|
187
|
+
const { catalog, items } = await listGraphs({ sizes: true });
|
|
188
|
+
// catalog: "ok" | "missing" | "unreadable" | "newer"
|
|
189
|
+
// each item: { store, kind?, name?, state?, version? | revision?, registered, present, status, size?, modified? }
|
|
190
|
+
// status: "ok" | "unregistered" (a directory with no entry) | "missing" (an entry with no directory)
|
|
191
|
+
|
|
192
|
+
await removeGraph("app-notes", { kind: "application" }); // discards the visitor's data: say so
|
|
193
|
+
await resetCatalog(); // deletes the file; no store is touched
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`listGraphs` works while another tab holds a store; sizes and modification times cost a file read per slot file, so ask for
|
|
197
|
+
them only when needed (about 6 ms per store in Chromium, 20 ms in Firefox and WebKit, in the spike's runs). `removeGraph`
|
|
198
|
+
refuses a name that is not an `app-<name>` or `rel-<id>` store (`not-a-store`), a `kind` that disagrees with the store's name or is
|
|
199
|
+
missing (`kind-mismatch`: removing an application graph always takes an explicit `application`), and a store another tab holds (`locked`, with its entry left as its holder wrote it). Removing a
|
|
200
|
+
graph the catalog does not know (`unregistered`) needs only its name and kind. Two removals of one store never overlap, in one tab or several. `resetCatalog()` is the way out of a catalog that
|
|
201
|
+
does not parse; afterwards a store with data and no entry fails `store-unmarked` until you import an export or call
|
|
202
|
+
`resetApplication()`.
|
|
203
|
+
|
|
204
|
+
**What a clear looks like to a page.** Clearing a site's storage, or the browser evicting it, removes the stores and the
|
|
205
|
+
catalog together, and the browser gives no signal. A page that starts cold then sees no entry and no data, the same as a first
|
|
206
|
+
visit, and applies the seed. A client that already held a store sees a storage error instead. An application that cannot
|
|
207
|
+
afford silent loss needs a copy outside the origin (an export, a server record).
|
|
208
|
+
|
|
209
|
+
**Not measured:** power loss and system crashes, Firefox and WebKit beyond the sizes in `reports/`, a write that
|
|
210
|
+
exceeds the browser's quota, the time to migrate a large store, and the cause of the occasional write stalls seen in
|
|
211
|
+
SPIKE-008. The figures in ADR-009 §6 are single runs on one machine.
|
|
212
|
+
|
|
213
|
+
## Supported browsers
|
|
214
|
+
|
|
215
|
+
Tested, in the package's own suite: current Chromium, Firefox and WebKit on desktop. Mobile and older browsers
|
|
216
|
+
are not measured. WebKit needs a persistent profile for the origin-private file system (as Playwright's
|
|
217
|
+
default WebKit context is not); where the store is unavailable the package loads the graph in memory.
|
|
218
|
+
|
|
219
|
+
## Conformance check for adapters
|
|
220
|
+
|
|
221
|
+
`@relate/contrib-web/conformance` exports `runConformance({ baseUrl, profile, browser })` and the scenarios. Serve the
|
|
222
|
+
example pages (`conformance/example-site/`) through your adapter and run it for each profile and browser; a failure
|
|
223
|
+
names the broken behavior. Playwright is an optional peer dependency used by the runner. The contract is in
|
|
224
|
+
`specs/001-core-package/contracts/conformance.md`.
|
|
225
|
+
|
|
226
|
+
## Develop
|
|
227
|
+
|
|
228
|
+
```sh
|
|
229
|
+
pnpm run build:wasm # build the vendored engine (needs Rust, wasm-bindgen-cli, binaryen)
|
|
230
|
+
pnpm install
|
|
231
|
+
pnpm --filter @relate/contrib-web build
|
|
232
|
+
pnpm --filter @relate/contrib-web test:unit
|
|
233
|
+
pnpm --filter @relate/contrib-web test:browsers # Chromium, Firefox and WebKit
|
|
234
|
+
pnpm --filter @relate/contrib-web test:conformance
|
|
235
|
+
pnpm --filter @relate/contrib-web test:package # packs the core and installs it in a clean project
|
|
236
|
+
pnpm --filter @relate/contrib-web test:trace # every requirement has a passing, tagged test
|
|
237
|
+
pnpm --filter @relate/contrib-web test:application # application graphs: unit tests against the real engine in Node
|
|
238
|
+
pnpm --filter @relate/contrib-web test:application-browsers # Chromium, Firefox and WebKit
|
|
239
|
+
pnpm --filter @relate/contrib-web test:application-trace # every requirement of specs/006 has a passing, tagged test
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Load-time baselines are in `tests/baselines/` (one file per browser and environment; `REL_ENV` names the
|
|
243
|
+
environment, `REL_UPDATE_BASELINE=1` rewrites them). A run fails when a time is more than twice its baseline.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Example site: broken graph</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body data-rel-variant="broken">
|
|
9
|
+
<main>
|
|
10
|
+
<h1 data-rel-title>Example site: broken graph</h1>
|
|
11
|
+
<nav>
|
|
12
|
+
<a data-rel-link href="/index.html">Home</a>
|
|
13
|
+
<a data-rel-link href="/page-1.html">Page 1</a>
|
|
14
|
+
<a data-rel-link href="/page-2.html">Page 2</a>
|
|
15
|
+
<a data-rel-link href="/notes.html">Notes</a>
|
|
16
|
+
<a data-rel-link href="/broken.html">Broken</a>
|
|
17
|
+
</nav>
|
|
18
|
+
<p>The graph on this page cannot be loaded; the page still works.</p>
|
|
19
|
+
<section>
|
|
20
|
+
<p>Status: <span data-rel-status>loading</span> · generation <span data-rel-generation>0</span> ·
|
|
21
|
+
profile <span data-rel-profile></span> · instance <span data-rel-instance></span> ·
|
|
22
|
+
restored <span data-rel-restored>unknown</span></p>
|
|
23
|
+
<p>Pages in the graph: <span data-rel-count>…</span> · updates <span data-rel-updates>0</span> ·
|
|
24
|
+
last error <span data-rel-last-error></span></p>
|
|
25
|
+
<p data-rel-failure></p>
|
|
26
|
+
<p data-rel-notes-row hidden>Notes: <span data-rel-notes>…</span></p>
|
|
27
|
+
<p>
|
|
28
|
+
<button type="button" data-rel-action="trap">Run a statement that crashes the engine</button>
|
|
29
|
+
<button type="button" data-rel-action="timeout">Run a statement that never ends (0.4 s timeout)</button>
|
|
30
|
+
</p>
|
|
31
|
+
</section>
|
|
32
|
+
</main>
|
|
33
|
+
<script type="module" src="./rel-page.ts"></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Example site: home</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main>
|
|
10
|
+
<h1 data-rel-title>Example site: home</h1>
|
|
11
|
+
<nav>
|
|
12
|
+
<a data-rel-link href="/index.html">Home</a>
|
|
13
|
+
<a data-rel-link href="/page-1.html">Page 1</a>
|
|
14
|
+
<a data-rel-link href="/page-2.html">Page 2</a>
|
|
15
|
+
<a data-rel-link href="/notes.html">Notes</a>
|
|
16
|
+
<a data-rel-link href="/broken.html">Broken</a>
|
|
17
|
+
</nav>
|
|
18
|
+
<p>A small site whose pages share one graph of pages and links.</p>
|
|
19
|
+
<section>
|
|
20
|
+
<p>Status: <span data-rel-status>loading</span> · generation <span data-rel-generation>0</span> ·
|
|
21
|
+
profile <span data-rel-profile></span> · instance <span data-rel-instance></span> ·
|
|
22
|
+
restored <span data-rel-restored>unknown</span></p>
|
|
23
|
+
<p>Pages in the graph: <span data-rel-count>…</span> · updates <span data-rel-updates>0</span> ·
|
|
24
|
+
last error <span data-rel-last-error></span></p>
|
|
25
|
+
<p data-rel-failure></p>
|
|
26
|
+
<p data-rel-notes-row hidden>Notes: <span data-rel-notes>…</span></p>
|
|
27
|
+
<p>
|
|
28
|
+
<button type="button" data-rel-action="trap">Run a statement that crashes the engine</button>
|
|
29
|
+
<button type="button" data-rel-action="timeout">Run a statement that never ends (0.4 s timeout)</button>
|
|
30
|
+
</p>
|
|
31
|
+
</section>
|
|
32
|
+
</main>
|
|
33
|
+
<script type="module" src="./rel-page.ts"></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Example site: notes</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body data-rel-notes-page>
|
|
9
|
+
<main>
|
|
10
|
+
<h1 data-rel-title>Example site: notes</h1>
|
|
11
|
+
<nav>
|
|
12
|
+
<a data-rel-link href="/index.html">Home</a>
|
|
13
|
+
<a data-rel-link href="/page-1.html">Page 1</a>
|
|
14
|
+
<a data-rel-link href="/page-2.html">Page 2</a>
|
|
15
|
+
<a data-rel-link href="/notes.html">Notes</a>
|
|
16
|
+
<a data-rel-link href="/broken.html">Broken</a>
|
|
17
|
+
</nav>
|
|
18
|
+
<p>This page adds two notes of its own and drops them when you leave.</p>
|
|
19
|
+
<section>
|
|
20
|
+
<p>Status: <span data-rel-status>loading</span> · generation <span data-rel-generation>0</span> ·
|
|
21
|
+
profile <span data-rel-profile></span> · instance <span data-rel-instance></span> ·
|
|
22
|
+
restored <span data-rel-restored>unknown</span></p>
|
|
23
|
+
<p>Pages in the graph: <span data-rel-count>…</span> · updates <span data-rel-updates>0</span> ·
|
|
24
|
+
last error <span data-rel-last-error></span></p>
|
|
25
|
+
<p data-rel-failure></p>
|
|
26
|
+
<p data-rel-notes-row hidden>Notes: <span data-rel-notes>…</span></p>
|
|
27
|
+
<p>
|
|
28
|
+
<button type="button" data-rel-action="trap">Run a statement that crashes the engine</button>
|
|
29
|
+
<button type="button" data-rel-action="timeout">Run a statement that never ends (0.4 s timeout)</button>
|
|
30
|
+
</p>
|
|
31
|
+
</section>
|
|
32
|
+
</main>
|
|
33
|
+
<script type="module" src="./rel-page.ts"></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Example site: page 1</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main>
|
|
10
|
+
<h1 data-rel-title>Example site: page 1</h1>
|
|
11
|
+
<nav>
|
|
12
|
+
<a data-rel-link href="/index.html">Home</a>
|
|
13
|
+
<a data-rel-link href="/page-1.html">Page 1</a>
|
|
14
|
+
<a data-rel-link href="/page-2.html">Page 2</a>
|
|
15
|
+
<a data-rel-link href="/notes.html">Notes</a>
|
|
16
|
+
<a data-rel-link href="/broken.html">Broken</a>
|
|
17
|
+
</nav>
|
|
18
|
+
<p>The first content page runs a query over the shared graph.</p>
|
|
19
|
+
<section>
|
|
20
|
+
<p>Status: <span data-rel-status>loading</span> · generation <span data-rel-generation>0</span> ·
|
|
21
|
+
profile <span data-rel-profile></span> · instance <span data-rel-instance></span> ·
|
|
22
|
+
restored <span data-rel-restored>unknown</span></p>
|
|
23
|
+
<p>Pages in the graph: <span data-rel-count>…</span> · updates <span data-rel-updates>0</span> ·
|
|
24
|
+
last error <span data-rel-last-error></span></p>
|
|
25
|
+
<p data-rel-failure></p>
|
|
26
|
+
<p data-rel-notes-row hidden>Notes: <span data-rel-notes>…</span></p>
|
|
27
|
+
<p>
|
|
28
|
+
<button type="button" data-rel-action="trap">Run a statement that crashes the engine</button>
|
|
29
|
+
<button type="button" data-rel-action="timeout">Run a statement that never ends (0.4 s timeout)</button>
|
|
30
|
+
</p>
|
|
31
|
+
</section>
|
|
32
|
+
</main>
|
|
33
|
+
<script type="module" src="./rel-page.ts"></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Example site: page 2</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<main>
|
|
10
|
+
<h1 data-rel-title>Example site: page 2</h1>
|
|
11
|
+
<nav>
|
|
12
|
+
<a data-rel-link href="/index.html">Home</a>
|
|
13
|
+
<a data-rel-link href="/page-1.html">Page 1</a>
|
|
14
|
+
<a data-rel-link href="/page-2.html">Page 2</a>
|
|
15
|
+
<a data-rel-link href="/notes.html">Notes</a>
|
|
16
|
+
<a data-rel-link href="/broken.html">Broken</a>
|
|
17
|
+
</nav>
|
|
18
|
+
<p>The second content page runs the same query.</p>
|
|
19
|
+
<section>
|
|
20
|
+
<p>Status: <span data-rel-status>loading</span> · generation <span data-rel-generation>0</span> ·
|
|
21
|
+
profile <span data-rel-profile></span> · instance <span data-rel-instance></span> ·
|
|
22
|
+
restored <span data-rel-restored>unknown</span></p>
|
|
23
|
+
<p>Pages in the graph: <span data-rel-count>…</span> · updates <span data-rel-updates>0</span> ·
|
|
24
|
+
last error <span data-rel-last-error></span></p>
|
|
25
|
+
<p data-rel-failure></p>
|
|
26
|
+
<p data-rel-notes-row hidden>Notes: <span data-rel-notes>…</span></p>
|
|
27
|
+
<p>
|
|
28
|
+
<button type="button" data-rel-action="trap">Run a statement that crashes the engine</button>
|
|
29
|
+
<button type="button" data-rel-action="timeout">Run a statement that never ends (0.4 s timeout)</button>
|
|
30
|
+
</p>
|
|
31
|
+
</section>
|
|
32
|
+
</main>
|
|
33
|
+
<script type="module" src="./rel-page.ts"></script>
|
|
34
|
+
</body>
|
|
35
|
+
</html>
|