Skip to content

Commit ab86a76

Browse files
authored
move w3ds file URI docs into the docusaurus docs site (#966)
1 parent 0c93740 commit ab86a76

5 files changed

Lines changed: 126 additions & 97 deletions

File tree

docs/docs/Infrastructure/Web3-Adapter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Every piece of data has an "owner" — the [eName](/docs/W3DS%20Basics/W3ID) of
4141

4242
### 3. Bidirectional mapping and ID mapping
4343

44-
- **Field mapping**: `localToUniversalMap` defines how each local field maps to a global field (including relations and special functions like `__date`, `__calc`). The same map is used in both directions: `toGlobal` for outbound, `fromGlobal` for inbound.
44+
- **Field mapping**: `localToUniversalMap` defines how each local field maps to a global field (including relations and special functions like `__date`, `__calc`, `__file`). The same map is used in both directions: `toGlobal` for outbound, `fromGlobal` for inbound.
4545
- **ID mapping**: A separate store (e.g. SQLite `MappingDatabase`) holds `(globalId, localId)`. When syncing out, after a successful `storeMetaEnvelope` the adapter stores the new global ID against the local ID. When a webhook arrives, the adapter looks up the global ID to decide whether to create or update the local entity and then stores or updates the mapping. Without this, the same logical entity could be duplicated or never linked across platforms. When consuming our TypeScript implementation of the Web3 Adapter, this is already taken care of.
4646

4747
### 4. Change detection on the platform side
@@ -119,7 +119,7 @@ graph TB
119119

120120
### Mapping configuration (IMapping)
121121

122-
Mapping configs define how local fields map to the global ontology. For the full syntax (direct fields, relations, arrays, `__date`, `__calc`, owner path), see the [Mapping Rules](/docs/Post%20Platform%20Guide/mapping-rules) or the repository at `infrastructure/web3-adapter/MAPPING_RULES.md`.
122+
Mapping configs define how local fields map to the global ontology. For the full syntax (direct fields, relations, arrays, `__date`, `__calc`, `__file`, owner path), see the [Mapping Rules](/docs/Post%20Platform%20Guide/mapping-rules) or the repository at `infrastructure/web3-adapter/MAPPING_RULES.md`. File fields use the `__file` directive backed by the [`w3ds://file` URI scheme](/docs/W3DS%20Protocol/File-URIs).
123123

124124
Each mapping is a JSON file with:
125125

docs/docs/Post Platform Guide/mapping-rules.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@ Performs mathematical calculations using field values.
9292
- Can reference other fields in the same entity
9393
- Automatically resolves field values before calculation
9494

95+
### File Referencing (`__file`)
96+
97+
Uploads inline file payloads to the owner eVault's object storage and replaces
98+
them with a stable [`w3ds://file`](/docs/W3DS%20Protocol/File-URIs) URI. On the
99+
way back, the URI is dereferenced to the file's public URL.
100+
101+
Same global field name as the local field:
102+
103+
```json
104+
"avatar": "__file(avatar)"
105+
```
106+
107+
Different global field name (via a `,alias` suffix):
108+
109+
```json
110+
"avatar": "__file(avatar),avatarUri"
111+
```
112+
113+
- The inner path (`avatar`) points to the field holding the file value.
114+
- An optional `,alias` sets the global field name (defaults to the inner path).
115+
- The value may be a single file or an **array** of files. Array paths such as
116+
`__file(images[].src)` are supported and each item is referenced/dereferenced.
117+
- **`toGlobal`**: a `data:` URI value is uploaded and replaced with a
118+
`w3ds://file?id=@<ename>/<meta-envelope-id>` URI. Values that are already
119+
`w3ds://file` URIs, plain URLs, or empty are passed through unchanged.
120+
- **`fromGlobal`**: a `w3ds://file` URI is dereferenced to the file's public
121+
object-storage URL; other values pass through unchanged.
122+
95123
## Owner Path
96124

97125
The `ownerEnamePath` defines how to determine which [eVault](/docs/Infrastructure/eVault) owns the data (via the owner's [eName](/docs/W3DS%20Basics/W3ID)):
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# File URIs
6+
7+
This document explains the `w3ds://file` URI scheme — a standardised,
8+
human-readable way to reference and dereference files across the MetaState
9+
ecosystem. A file attached to or described by a [Meta Envelope](/docs/Infrastructure/eVault)
10+
can be uniquely addressed and resolved with a consistent URI tied to a user's
11+
entity name (`ename`) and the envelope's identifier.
12+
13+
## Format
14+
15+
```text
16+
w3ds://file?id=@<user-ename>/<meta-envelope-id>
17+
```
18+
19+
| Component | Description |
20+
| -------------------- | ------------------------------------------------------------ |
21+
| `w3ds://` | The scheme. Always lowercase. |
22+
| `file` | The resource host. Identifies the URI as addressing a file. |
23+
| `id` | Required query parameter carrying the file's address. |
24+
| `@<user-ename>` | The owning user's entity name (`ename`), always `@`-prefixed.|
25+
| `<meta-envelope-id>` | The ID of the Meta Envelope describing the file. |
26+
27+
Example:
28+
29+
```text
30+
w3ds://file?id=@alice/envelope-abc123
31+
```
32+
33+
## How files are stored
34+
35+
A file uploaded to an [eVault](/docs/Infrastructure/eVault) is:
36+
37+
1. Streamed to object storage (DigitalOcean Spaces, S3-compatible) as a
38+
`public-read` object.
39+
2. Recorded as a **File Meta Envelope** (ontology `w3ds-file-v1`) with payload:
40+
`{ filename, contentType, size, blobKey, publicUrl, uploadedAt }`.
41+
3. Addressed by a `w3ds://file` URI built from the owner `ename` and the
42+
Meta Envelope ID.
43+
44+
Uploads are performed through the eVault `uploadFile` GraphQL mutation, which
45+
takes base64 content and returns the `w3ds://file` URI, the Meta Envelope ID,
46+
and the public object-storage URL.
47+
48+
## Resolving (dereferencing) a URI
49+
50+
There are two dereferencers.
51+
52+
### HTTP — eVault core
53+
54+
```http
55+
GET /files/:metaEnvelopeId (header: X-ENAME: @<user-ename>)
56+
```
57+
58+
Resolves the File Meta Envelope and responds with a **302 redirect** to the
59+
file's public object-storage URL. The redirect target is validated to be
60+
`http(s)` only.
61+
62+
- `400` — missing `X-ENAME` header, malformed ID, or an unsafe stored URL scheme.
63+
- `404` — no File Meta Envelope for that ID, or it has no public URL.
64+
65+
### Programmatic — web3-adapter
66+
67+
```ts
68+
import { dereferenceFileUri } from "@web3-adapter/w3ds/resolver";
69+
70+
const file = await dereferenceFileUri(
71+
"w3ds://file?id=@alice/abc123",
72+
evaultClient,
73+
);
74+
// => { uri, ename, metaEnvelopeId, publicUrl, filename, contentType, size }
75+
```
76+
77+
## Error handling
78+
79+
`parseFileUri` / `dereferenceFileUri` throw a descriptive `InvalidW3dsUriError`
80+
or `Error` for:
81+
82+
- Malformed URIs (not parseable, empty input).
83+
- Wrong scheme (not `w3ds:`) or wrong host (not `file`).
84+
- Missing `id` query parameter.
85+
- `id` missing the `@<ename>` prefix or the `/<meta-envelope-id>` segment.
86+
- Empty `ename` or `meta-envelope-id`.
87+
- A non-existent `ename` (eVault cannot be resolved).
88+
- A non-existent or non-file Meta Envelope.
89+
90+
## Mapper integration
91+
92+
The [Web3 Adapter](/docs/Infrastructure/Web3-Adapter) exposes a `__file()`
93+
mapping directive that automatically references files on `toGlobal` and
94+
dereferences them on `fromGlobal`. See
95+
[Mapping Rules → File Referencing](/docs/Post%20Platform%20Guide/mapping-rules).

infrastructure/web3-adapter/MAPPING_RULES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Different global field name (via a `,alias` suffix):
117117
object-storage URL; other values pass through unchanged.
118118

119119
Requires an `EVaultClient` to be supplied to the mapper — the `Web3Adapter`
120-
wires this automatically. See [`W3DS_URI.md`](./W3DS_URI.md) for the URI scheme.
120+
wires this automatically. See the **File URIs** doc (`docs/docs/W3DS Protocol/File-URIs.md`) for the `w3ds://file` URI scheme.
121121

122122
## Owner Path
123123

infrastructure/web3-adapter/W3DS_URI.md

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)