@enbox/api 0.3.2 → 0.4.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.
- package/README.md +63 -0
- package/dist/browser.mjs +11 -28
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/advanced.js +1 -1
- package/dist/esm/define-protocol.js +3 -3
- package/dist/esm/did-api.js +1 -1
- package/dist/esm/did-api.js.map +1 -1
- package/dist/esm/dwn-api.js +6 -6
- package/dist/esm/dwn-api.js.map +1 -1
- package/dist/esm/dwn-reader-api.js +2 -2
- package/dist/esm/enbox.js +205 -0
- package/dist/esm/enbox.js.map +1 -0
- package/dist/esm/index.js +16 -15
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/protocol.js +2 -2
- package/dist/esm/protocol.js.map +1 -1
- package/dist/esm/record-data.js +79 -5
- package/dist/esm/record-data.js.map +1 -1
- package/dist/esm/record.js +49 -10
- package/dist/esm/record.js.map +1 -1
- package/dist/esm/repository.js +7 -7
- package/dist/esm/repository.js.map +1 -1
- package/dist/esm/typed-enbox.js +583 -0
- package/dist/esm/typed-enbox.js.map +1 -0
- package/dist/esm/typed-live-query.js +1 -1
- package/dist/esm/typed-record.js +370 -46
- package/dist/esm/typed-record.js.map +1 -1
- package/dist/esm/utils.js +25 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/vc-api.js.map +1 -1
- package/dist/types/advanced.d.ts +1 -1
- package/dist/types/define-protocol.d.ts +3 -3
- package/dist/types/did-api.d.ts +4 -4
- package/dist/types/did-api.d.ts.map +1 -1
- package/dist/types/dwn-api.d.ts +12 -7
- package/dist/types/dwn-api.d.ts.map +1 -1
- package/dist/types/dwn-reader-api.d.ts +2 -2
- package/dist/types/enbox.d.ts +202 -0
- package/dist/types/enbox.d.ts.map +1 -0
- package/dist/types/grant-revocation.d.ts +2 -2
- package/dist/types/grant-revocation.d.ts.map +1 -1
- package/dist/types/index.d.ts +16 -15
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/live-query.d.ts +2 -2
- package/dist/types/live-query.d.ts.map +1 -1
- package/dist/types/permission-grant.d.ts +2 -2
- package/dist/types/permission-grant.d.ts.map +1 -1
- package/dist/types/permission-request.d.ts +2 -2
- package/dist/types/permission-request.d.ts.map +1 -1
- package/dist/types/protocol-types.d.ts +2 -2
- package/dist/types/protocol.d.ts +7 -7
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/record-data.d.ts +17 -0
- package/dist/types/record-data.d.ts.map +1 -1
- package/dist/types/record.d.ts +24 -10
- package/dist/types/record.d.ts.map +1 -1
- package/dist/types/repository-types.d.ts +19 -11
- package/dist/types/repository-types.d.ts.map +1 -1
- package/dist/types/repository.d.ts +7 -7
- package/dist/types/repository.d.ts.map +1 -1
- package/dist/types/typed-enbox.d.ts +613 -0
- package/dist/types/typed-enbox.d.ts.map +1 -0
- package/dist/types/typed-live-query.d.ts +1 -1
- package/dist/types/typed-record.d.ts +427 -53
- package/dist/types/typed-record.d.ts.map +1 -1
- package/dist/types/utils.d.ts +23 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/vc-api.d.ts +3 -3
- package/dist/types/vc-api.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/advanced.ts +1 -1
- package/src/define-protocol.ts +3 -3
- package/src/did-api.ts +5 -5
- package/src/dwn-api.ts +22 -17
- package/src/dwn-reader-api.ts +2 -2
- package/src/enbox.ts +281 -0
- package/src/grant-revocation.ts +3 -3
- package/src/index.ts +17 -16
- package/src/live-query.ts +2 -2
- package/src/permission-grant.ts +4 -4
- package/src/permission-request.ts +3 -3
- package/src/protocol-types.ts +2 -2
- package/src/protocol.ts +8 -8
- package/src/record-data.ts +86 -5
- package/src/record.ts +54 -13
- package/src/repository-types.ts +19 -7
- package/src/repository.ts +15 -15
- package/src/typed-enbox.ts +1169 -0
- package/src/typed-live-query.ts +1 -1
- package/src/typed-record.ts +431 -53
- package/src/utils.ts +27 -0
- package/src/vc-api.ts +4 -4
- package/dist/esm/typed-web5.js +0 -339
- package/dist/esm/typed-web5.js.map +0 -1
- package/dist/esm/web5.js +0 -410
- package/dist/esm/web5.js.map +0 -1
- package/dist/types/typed-web5.d.ts +0 -221
- package/dist/types/typed-web5.d.ts.map +0 -1
- package/dist/types/web5.d.ts +0 -351
- package/dist/types/web5.d.ts.map +0 -1
- package/src/typed-web5.ts +0 -598
- package/src/web5.ts +0 -762
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A protocol-scoped API returned by {@link Enbox.using}.
|
|
3
|
+
*
|
|
4
|
+
* `TypedEnbox` is the **primary developer interface** for interacting with
|
|
5
|
+
* protocol-backed records. It auto-injects the protocol URI, protocolPath,
|
|
6
|
+
* and schema into every operation, and provides compile-time path
|
|
7
|
+
* autocompletion plus typed data payloads via the schema map.
|
|
8
|
+
*
|
|
9
|
+
* All record-returning methods wrap the underlying `Record` instances in
|
|
10
|
+
* {@link TypedRecord} so that type information flows through reads, queries,
|
|
11
|
+
* updates, and subscriptions without manual casts.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const social = enbox.using(SocialProtocol);
|
|
16
|
+
*
|
|
17
|
+
* // Install the protocol
|
|
18
|
+
* await social.configure();
|
|
19
|
+
*
|
|
20
|
+
* // Create — path and data type are checked at compile time
|
|
21
|
+
* const { record } = await social.records.create('thread', {
|
|
22
|
+
* data: { title: 'Hello World', body: '...' },
|
|
23
|
+
* });
|
|
24
|
+
* // record is TypedRecord<ThreadData>
|
|
25
|
+
*
|
|
26
|
+
* const data = await record.data.json(); // ThreadData — no cast needed
|
|
27
|
+
*
|
|
28
|
+
* // Query — protocol and protocolPath are auto-injected
|
|
29
|
+
* const { records } = await social.records.query('thread');
|
|
30
|
+
* // records is TypedRecord<ThreadData>[]
|
|
31
|
+
*
|
|
32
|
+
* // Subscribe — real-time changes via TypedLiveQuery
|
|
33
|
+
* const { liveQuery } = await social.records.subscribe('thread/reply');
|
|
34
|
+
* liveQuery.on('create', (record) => {
|
|
35
|
+
* // record is TypedRecord<ReplyData>
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
40
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
41
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
42
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
43
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
44
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
45
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
+
var t = {};
|
|
50
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
+
t[p] = s[p];
|
|
52
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
+
t[p[i]] = s[p[i]];
|
|
56
|
+
}
|
|
57
|
+
return t;
|
|
58
|
+
};
|
|
59
|
+
import { TypedLiveQuery } from './typed-live-query.js';
|
|
60
|
+
import { TypedRecord } from './typed-record.js';
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// TypedEnbox class
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
/**
|
|
65
|
+
* A protocol-scoped API that auto-injects `protocol`, `protocolPath`, and
|
|
66
|
+
* `schema` into every DWN operation.
|
|
67
|
+
*
|
|
68
|
+
* All record-returning methods wrap results in {@link TypedRecord} so that
|
|
69
|
+
* the data type `T` (resolved from the schema map) flows end-to-end — from
|
|
70
|
+
* write through read, query, update, and subscribe — without manual casts.
|
|
71
|
+
*
|
|
72
|
+
* Obtain an instance via `enbox.using(typedProtocol)`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const social = enbox.using(SocialProtocol);
|
|
77
|
+
*
|
|
78
|
+
* await social.configure();
|
|
79
|
+
*
|
|
80
|
+
* const { record } = await social.records.create('friend', {
|
|
81
|
+
* data: { did: 'did:example:alice', alias: 'Alice' },
|
|
82
|
+
* });
|
|
83
|
+
* const data = await record.data.json(); // FriendData — no cast
|
|
84
|
+
*
|
|
85
|
+
* const { records } = await social.records.query('friend', {
|
|
86
|
+
* filter: { tags: { did: 'did:example:alice' } },
|
|
87
|
+
* });
|
|
88
|
+
* for (const r of records) {
|
|
89
|
+
* const d = await r.data.json(); // FriendData
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export class TypedEnbox {
|
|
94
|
+
/**
|
|
95
|
+
* @internal Create a new `TypedEnbox` instance. Use `enbox.using(protocol)` instead.
|
|
96
|
+
* @param dwn - The underlying DWN API instance.
|
|
97
|
+
* @param protocol - The typed protocol containing the definition and schema map.
|
|
98
|
+
*/
|
|
99
|
+
constructor(dwn, protocol) {
|
|
100
|
+
/** @internal */
|
|
101
|
+
this._configured = false;
|
|
102
|
+
/** @internal */
|
|
103
|
+
this._ensureReadyPromise = null;
|
|
104
|
+
this._dwn = dwn;
|
|
105
|
+
this._definition = protocol.definition;
|
|
106
|
+
this._validPaths = collectPaths(this._definition.structure);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The protocol URI string (e.g. `'https://example.com/social'`).
|
|
110
|
+
*
|
|
111
|
+
* This is the globally unique identifier for the protocol and is
|
|
112
|
+
* auto-injected into every record operation.
|
|
113
|
+
*/
|
|
114
|
+
get protocol() {
|
|
115
|
+
return this._definition.protocol;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The raw protocol definition object.
|
|
119
|
+
*
|
|
120
|
+
* Contains the full `protocol`, `types`, and `structure` that define
|
|
121
|
+
* the protocol's schema and permission rules.
|
|
122
|
+
*/
|
|
123
|
+
get definition() {
|
|
124
|
+
return this._definition;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Configures (installs) this protocol on the local DWN.
|
|
128
|
+
*
|
|
129
|
+
* If the protocol is already installed with an identical definition,
|
|
130
|
+
* this is a no-op and returns the existing protocol with status `200`.
|
|
131
|
+
* If the definition has changed (e.g. new types, modified structure),
|
|
132
|
+
* the protocol is re-configured with the updated definition and returns
|
|
133
|
+
* status `202`.
|
|
134
|
+
*
|
|
135
|
+
* **Must be called before any record operations.** Methods like
|
|
136
|
+
* `records.create()`, `records.query()`, etc. will throw if the protocol
|
|
137
|
+
* has not been configured.
|
|
138
|
+
*
|
|
139
|
+
* @param options - Optional configuration overrides.
|
|
140
|
+
* @param options.encryption - Whether to enable auto-encryption for the
|
|
141
|
+
* protocol. If omitted, follows the protocol definition defaults.
|
|
142
|
+
* @returns The DWN response status and the installed protocol object.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* const proto = enbox.using(NotebookProtocol);
|
|
147
|
+
*
|
|
148
|
+
* const { status, protocol } = await proto.configure();
|
|
149
|
+
* console.log(status.code); // 202 (first install) or 200 (already installed)
|
|
150
|
+
*
|
|
151
|
+
* // Now you can use records.create(), records.query(), etc.
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
configure(options) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
// Query for an existing installation of this protocol.
|
|
157
|
+
const { protocols } = yield this._dwn.protocols.query({
|
|
158
|
+
filter: { protocol: this._definition.protocol },
|
|
159
|
+
});
|
|
160
|
+
// If already installed with the same definition, return it as-is.
|
|
161
|
+
if (protocols.length > 0) {
|
|
162
|
+
const existing = protocols[0];
|
|
163
|
+
if (definitionsEqual(existing.definition, this._definition)) {
|
|
164
|
+
this._configured = true;
|
|
165
|
+
return { status: { code: 200, detail: 'OK' }, protocol: existing };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Not installed or definition has changed — configure the new version.
|
|
169
|
+
const result = yield this._dwn.protocols.configure({
|
|
170
|
+
definition: this._definition,
|
|
171
|
+
encryption: options === null || options === void 0 ? void 0 : options.encryption,
|
|
172
|
+
});
|
|
173
|
+
if (result.status.code === 202) {
|
|
174
|
+
this._configured = true;
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Whether the protocol has been configured (installed) on the local DWN.
|
|
181
|
+
*
|
|
182
|
+
* Returns `true` after a successful call to {@link TypedEnbox.configure | configure()}.
|
|
183
|
+
* Record operations will throw if this is `false`.
|
|
184
|
+
*/
|
|
185
|
+
get isConfigured() {
|
|
186
|
+
return this._configured;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Validates that the path is recognized.
|
|
190
|
+
* Throws a descriptive error if the path is not a valid protocol path.
|
|
191
|
+
*/
|
|
192
|
+
_assertValidPath(path) {
|
|
193
|
+
if (!this._validPaths.has(path)) {
|
|
194
|
+
throw new Error(`TypedEnbox: invalid protocol path '${path}'. ` +
|
|
195
|
+
`Valid paths are: ${[...this._validPaths].join(', ')}.`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Ensures the protocol is configured before performing record operations.
|
|
200
|
+
*
|
|
201
|
+
* On first call, queries for an existing protocol installation:
|
|
202
|
+
* - If found with an identical definition → marks as configured.
|
|
203
|
+
* - If found with a different definition → marks as configured but warns
|
|
204
|
+
* that the local definition differs from the installed one.
|
|
205
|
+
* - If not found → installs the protocol via `protocols.configure()`.
|
|
206
|
+
*
|
|
207
|
+
* Concurrent calls are deduplicated via a shared Promise so the network
|
|
208
|
+
* call only happens once.
|
|
209
|
+
*/
|
|
210
|
+
_ensureReady(path) {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
if (this._configured) {
|
|
213
|
+
this._assertValidPath(path);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (this._ensureReadyPromise === null) {
|
|
217
|
+
this._ensureReadyPromise = this._autoConfigureOnce();
|
|
218
|
+
}
|
|
219
|
+
yield this._ensureReadyPromise;
|
|
220
|
+
this._assertValidPath(path);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Performs the one-time auto-configuration check. Called at most once;
|
|
225
|
+
* subsequent calls reuse the same Promise via `_ensureReadyPromise`.
|
|
226
|
+
*/
|
|
227
|
+
_autoConfigureOnce() {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const { protocols } = yield this._dwn.protocols.query({
|
|
230
|
+
filter: { protocol: this._definition.protocol },
|
|
231
|
+
});
|
|
232
|
+
if (protocols.length > 0) {
|
|
233
|
+
const existing = protocols[0];
|
|
234
|
+
if (definitionsEqual(existing.definition, this._definition)) {
|
|
235
|
+
this._configured = true;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// Installed but definitions differ — allow operations but warn.
|
|
239
|
+
console.warn(`TypedEnbox: installed protocol '${this._definition.protocol}' differs from the provided definition. ` +
|
|
240
|
+
'Call configure() to update it.');
|
|
241
|
+
this._configured = true;
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
// Not installed — configure it now.
|
|
245
|
+
const result = yield this._dwn.protocols.configure({
|
|
246
|
+
definition: this._definition,
|
|
247
|
+
});
|
|
248
|
+
if (result.status.code === 202) {
|
|
249
|
+
this._configured = true;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Protocol-scoped record operations.
|
|
255
|
+
*
|
|
256
|
+
* Every method auto-injects the `protocol`, `protocolPath`, and `schema`
|
|
257
|
+
* from the protocol definition — you never need to specify them manually.
|
|
258
|
+
* Path parameters provide **compile-time autocompletion** via
|
|
259
|
+
* `ProtocolPaths<D>`, and data types are resolved from the schema map.
|
|
260
|
+
*
|
|
261
|
+
* All methods return {@link TypedRecord} or {@link TypedLiveQuery} instances
|
|
262
|
+
* that carry the resolved data type from the schema map, providing
|
|
263
|
+
* end-to-end type safety.
|
|
264
|
+
*
|
|
265
|
+
* Available methods:
|
|
266
|
+
* - {@link TypedEnbox.records.create | create(path, request)} — Create a new record
|
|
267
|
+
* - {@link TypedEnbox.records.query | query(path, request?)} — Query records with filters
|
|
268
|
+
* - {@link TypedEnbox.records.read | read(path, request)} — Read a single record
|
|
269
|
+
* - {@link TypedEnbox.records.delete | delete(path, request)} — Delete a record by ID
|
|
270
|
+
* - {@link TypedEnbox.records.subscribe | subscribe(path, request?)} — Real-time subscription
|
|
271
|
+
*/
|
|
272
|
+
get records() {
|
|
273
|
+
if (this._records !== undefined) {
|
|
274
|
+
return this._records;
|
|
275
|
+
}
|
|
276
|
+
const cached = {
|
|
277
|
+
/**
|
|
278
|
+
* Create a new record at the given protocol path.
|
|
279
|
+
*
|
|
280
|
+
* The `protocol`, `protocolPath`, and `schema` are auto-injected from
|
|
281
|
+
* the protocol definition. The `data` field is type-checked against
|
|
282
|
+
* the schema map for the given path.
|
|
283
|
+
*
|
|
284
|
+
* @param path - The protocol path (e.g. `'notebook'`, `'notebook/page'`).
|
|
285
|
+
* Provides compile-time autocompletion for valid paths.
|
|
286
|
+
* @param request - Create options including the typed `data` payload
|
|
287
|
+
* and optional fields like `parentContextId`, `tags`, `recipient`.
|
|
288
|
+
* @returns A {@link TypedCreateResponse} containing the DWN response
|
|
289
|
+
* `status` and the created {@link TypedRecord}.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* const { status, record } = await proto.records.create('notebook', {
|
|
294
|
+
* data: { name: 'My Notebook' },
|
|
295
|
+
* });
|
|
296
|
+
*
|
|
297
|
+
* // Create a child page under the notebook's context
|
|
298
|
+
* const { record: page } = await proto.records.create('notebook/page', {
|
|
299
|
+
* data: { title: 'First Page', body: '' },
|
|
300
|
+
* parentContextId: record.contextId,
|
|
301
|
+
* });
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
create: (path, request) => __awaiter(this, void 0, void 0, function* () {
|
|
305
|
+
var _a, _b;
|
|
306
|
+
const normalizedPath = normalizePath(path);
|
|
307
|
+
yield this._ensureReady(normalizedPath);
|
|
308
|
+
const typeName = lastSegment(normalizedPath);
|
|
309
|
+
const typeEntry = this._definition.types[typeName];
|
|
310
|
+
const { status, record } = yield this._dwn.records.write(Object.assign(Object.assign({ data: request.data, store: request.store, encryption: request.encryption, parentContextId: request.parentContextId, published: request.published, datePublished: request.datePublished, recipient: request.recipient, protocolRole: request.protocolRole, tags: request.tags, protocol: this._definition.protocol, protocolPath: normalizedPath }, ((typeEntry === null || typeEntry === void 0 ? void 0 : typeEntry.schema) !== undefined ? { schema: typeEntry.schema } : {})), { dataFormat: (_a = request.dataFormat) !== null && _a !== void 0 ? _a : (_b = typeEntry === null || typeEntry === void 0 ? void 0 : typeEntry.dataFormats) === null || _b === void 0 ? void 0 : _b[0] }));
|
|
311
|
+
return {
|
|
312
|
+
status,
|
|
313
|
+
record: record ? new TypedRecord(record) : undefined,
|
|
314
|
+
};
|
|
315
|
+
}),
|
|
316
|
+
/**
|
|
317
|
+
* Query records at the given protocol path.
|
|
318
|
+
*
|
|
319
|
+
* Returns all matching records as an array of typed records, with
|
|
320
|
+
* an optional pagination cursor for fetching additional pages.
|
|
321
|
+
*
|
|
322
|
+
* @param path - The protocol path to query (e.g. `'notebook'`,
|
|
323
|
+
* `'notebook/page'`).
|
|
324
|
+
* @param request - Optional filter, sort, and pagination options.
|
|
325
|
+
* Omit entirely to return all records at the path.
|
|
326
|
+
* @returns A {@link TypedQueryResponse} containing `status`, `records`
|
|
327
|
+
* (as {@link TypedRecord | TypedRecord<T>[]}), and an optional
|
|
328
|
+
* `cursor` for pagination.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```ts
|
|
332
|
+
* // Query all notebooks
|
|
333
|
+
* const { records } = await proto.records.query('notebook');
|
|
334
|
+
*
|
|
335
|
+
* // Query pages under a specific notebook
|
|
336
|
+
* const { records: pages } = await proto.records.query('notebook/page', {
|
|
337
|
+
* filter: { parentId: notebook.contextId },
|
|
338
|
+
* });
|
|
339
|
+
*
|
|
340
|
+
* for (const page of pages) {
|
|
341
|
+
* const data = await page.data.json(); // PageData
|
|
342
|
+
* }
|
|
343
|
+
*
|
|
344
|
+
* // Paginated query
|
|
345
|
+
* const { records: batch, cursor } = await proto.records.query('notebook', {
|
|
346
|
+
* pagination: { limit: 10 },
|
|
347
|
+
* dateSort: DateSort.CreatedDescending,
|
|
348
|
+
* });
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
query: (path, request) => __awaiter(this, void 0, void 0, function* () {
|
|
352
|
+
const normalizedPath = normalizePath(path);
|
|
353
|
+
yield this._ensureReady(normalizedPath);
|
|
354
|
+
const typeName = lastSegment(normalizedPath);
|
|
355
|
+
const typeEntry = this._definition.types[typeName];
|
|
356
|
+
const queryFilter = mapParentContextId(request === null || request === void 0 ? void 0 : request.filter);
|
|
357
|
+
const { status, records, cursor } = yield this._dwn.records.query({
|
|
358
|
+
from: request === null || request === void 0 ? void 0 : request.from,
|
|
359
|
+
encryption: request === null || request === void 0 ? void 0 : request.encryption,
|
|
360
|
+
filter: Object.assign(Object.assign(Object.assign({}, queryFilter), { protocol: this._definition.protocol, protocolPath: normalizedPath }), ((typeEntry === null || typeEntry === void 0 ? void 0 : typeEntry.schema) !== undefined ? { schema: typeEntry.schema } : {})),
|
|
361
|
+
dateSort: request === null || request === void 0 ? void 0 : request.dateSort,
|
|
362
|
+
pagination: request === null || request === void 0 ? void 0 : request.pagination,
|
|
363
|
+
protocolRole: request === null || request === void 0 ? void 0 : request.protocolRole,
|
|
364
|
+
});
|
|
365
|
+
return {
|
|
366
|
+
status,
|
|
367
|
+
records: records.map((r) => new TypedRecord(r)),
|
|
368
|
+
cursor,
|
|
369
|
+
};
|
|
370
|
+
}),
|
|
371
|
+
/**
|
|
372
|
+
* Read a single record at the given protocol path.
|
|
373
|
+
*
|
|
374
|
+
* Unlike `query()`, which returns an array, `read()` returns exactly
|
|
375
|
+
* one record. Use `filter.recordId` to target a specific record.
|
|
376
|
+
*
|
|
377
|
+
* @param path - The protocol path to read from.
|
|
378
|
+
* @param request - Read options including a `filter` to identify the
|
|
379
|
+
* record. See {@link TypedReadRequest} for details.
|
|
380
|
+
* @returns A {@link TypedReadResponse} containing `status` and the
|
|
381
|
+
* matching {@link TypedRecord}.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* const { record } = await proto.records.read('notebook', {
|
|
386
|
+
* filter: { recordId: notebookId },
|
|
387
|
+
* });
|
|
388
|
+
*
|
|
389
|
+
* const data = await record.data.json(); // NotebookData
|
|
390
|
+
* console.log(data.name);
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
read: (path, request) => __awaiter(this, void 0, void 0, function* () {
|
|
394
|
+
const normalizedPath = normalizePath(path);
|
|
395
|
+
yield this._ensureReady(normalizedPath);
|
|
396
|
+
const typeName = lastSegment(normalizedPath);
|
|
397
|
+
const typeEntry = this._definition.types[typeName];
|
|
398
|
+
const readFilter = mapParentContextId(request.filter);
|
|
399
|
+
const { status, record } = yield this._dwn.records.read({
|
|
400
|
+
from: request.from,
|
|
401
|
+
encryption: request.encryption,
|
|
402
|
+
protocol: this._definition.protocol,
|
|
403
|
+
filter: Object.assign(Object.assign(Object.assign({}, readFilter), { protocol: this._definition.protocol, protocolPath: normalizedPath }), ((typeEntry === null || typeEntry === void 0 ? void 0 : typeEntry.schema) !== undefined ? { schema: typeEntry.schema } : {})),
|
|
404
|
+
});
|
|
405
|
+
return {
|
|
406
|
+
status,
|
|
407
|
+
record: record ? new TypedRecord(record) : undefined,
|
|
408
|
+
};
|
|
409
|
+
}),
|
|
410
|
+
/**
|
|
411
|
+
* Delete a record at the given protocol path.
|
|
412
|
+
*
|
|
413
|
+
* The path is used for protocol validation and permission scoping,
|
|
414
|
+
* while the actual record is identified by `recordId`.
|
|
415
|
+
*
|
|
416
|
+
* @param path - The protocol path (used for permission scoping and
|
|
417
|
+
* path validation).
|
|
418
|
+
* @param request - Delete options. `recordId` is required; `from` is
|
|
419
|
+
* optional for remote deletes.
|
|
420
|
+
* @returns The DWN response status.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* const { status } = await proto.records.delete('notebook', {
|
|
425
|
+
* recordId: notebook.id,
|
|
426
|
+
* });
|
|
427
|
+
*
|
|
428
|
+
* if (status.code === 202) {
|
|
429
|
+
* console.log('Notebook deleted');
|
|
430
|
+
* }
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
delete: (_path, request) => __awaiter(this, void 0, void 0, function* () {
|
|
434
|
+
yield this._ensureReady(normalizePath(_path));
|
|
435
|
+
return this._dwn.records.delete({
|
|
436
|
+
from: request.from,
|
|
437
|
+
protocol: this._definition.protocol,
|
|
438
|
+
recordId: request.recordId,
|
|
439
|
+
});
|
|
440
|
+
}),
|
|
441
|
+
/**
|
|
442
|
+
* Subscribe to real-time changes at the given protocol path.
|
|
443
|
+
*
|
|
444
|
+
* Returns a {@link TypedLiveQuery} that atomically provides an initial
|
|
445
|
+
* snapshot and a real-time stream of deduplicated change events, with
|
|
446
|
+
* all records typed as `TypedRecord<T>`.
|
|
447
|
+
*
|
|
448
|
+
* @param path - The protocol path to subscribe to.
|
|
449
|
+
* @param request - Optional filter and role. Use `filter.parentId`
|
|
450
|
+
* to scope the subscription to children of a specific parent.
|
|
451
|
+
* @returns A {@link TypedSubscribeResponse} containing `status` and
|
|
452
|
+
* a {@link TypedLiveQuery} for receiving events.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* const { liveQuery } = await proto.records.subscribe('notebook/page', {
|
|
457
|
+
* filter: { parentId: notebook.contextId },
|
|
458
|
+
* });
|
|
459
|
+
*
|
|
460
|
+
* liveQuery.on('create', (record) => {
|
|
461
|
+
* // record is TypedRecord<PageData>
|
|
462
|
+
* console.log('New page created');
|
|
463
|
+
* });
|
|
464
|
+
*
|
|
465
|
+
* liveQuery.on('update', (record) => {
|
|
466
|
+
* const data = await record.data.json(); // PageData
|
|
467
|
+
* });
|
|
468
|
+
*
|
|
469
|
+
* liveQuery.on('delete', (record) => {
|
|
470
|
+
* console.log('Page deleted:', record.id);
|
|
471
|
+
* });
|
|
472
|
+
*
|
|
473
|
+
* // Stop listening
|
|
474
|
+
* liveQuery.close();
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
subscribe: (path, request) => __awaiter(this, void 0, void 0, function* () {
|
|
478
|
+
const normalizedPath = normalizePath(path);
|
|
479
|
+
yield this._ensureReady(normalizedPath);
|
|
480
|
+
const typeName = lastSegment(normalizedPath);
|
|
481
|
+
const typeEntry = this._definition.types[typeName];
|
|
482
|
+
const subFilter = mapParentContextId(request === null || request === void 0 ? void 0 : request.filter);
|
|
483
|
+
const { status, liveQuery } = yield this._dwn.records.subscribe({
|
|
484
|
+
from: request === null || request === void 0 ? void 0 : request.from,
|
|
485
|
+
filter: Object.assign(Object.assign(Object.assign({}, subFilter), { protocol: this._definition.protocol, protocolPath: normalizedPath }), ((typeEntry === null || typeEntry === void 0 ? void 0 : typeEntry.schema) !== undefined ? { schema: typeEntry.schema } : {})),
|
|
486
|
+
protocolRole: request === null || request === void 0 ? void 0 : request.protocolRole,
|
|
487
|
+
});
|
|
488
|
+
return {
|
|
489
|
+
status,
|
|
490
|
+
liveQuery: liveQuery ? new TypedLiveQuery(liveQuery) : undefined,
|
|
491
|
+
};
|
|
492
|
+
}),
|
|
493
|
+
};
|
|
494
|
+
this._records = cached;
|
|
495
|
+
return cached;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
// Helpers
|
|
500
|
+
// ---------------------------------------------------------------------------
|
|
501
|
+
/**
|
|
502
|
+
* Maps the `parentContextId` alias to the underlying `parentId` field
|
|
503
|
+
* expected by the DWN SDK. If both are provided, `parentId` takes precedence.
|
|
504
|
+
* Returns a new object (or `undefined` if the input was `undefined`).
|
|
505
|
+
*/
|
|
506
|
+
function mapParentContextId(filter) {
|
|
507
|
+
if (!filter) {
|
|
508
|
+
return undefined;
|
|
509
|
+
}
|
|
510
|
+
const _a = filter, { parentContextId } = _a, rest = __rest(_a, ["parentContextId"]);
|
|
511
|
+
if (parentContextId !== undefined && rest.parentId === undefined) {
|
|
512
|
+
rest.parentId = parentContextId;
|
|
513
|
+
}
|
|
514
|
+
return rest;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Compares two protocol definitions for deep equality using deterministic
|
|
518
|
+
* JSON serialization.
|
|
519
|
+
*
|
|
520
|
+
* Keys are sorted recursively so that semantically identical definitions
|
|
521
|
+
* with different key ordering are treated as equal.
|
|
522
|
+
*/
|
|
523
|
+
function definitionsEqual(a, b) {
|
|
524
|
+
return stableStringify(a) === stableStringify(b);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Strips leading and trailing slashes from a path.
|
|
528
|
+
*
|
|
529
|
+
* `'friend/'` → `'friend'`, `'/group/member/'` → `'group/member'`.
|
|
530
|
+
*/
|
|
531
|
+
function normalizePath(path) {
|
|
532
|
+
return path.replace(/^\/+|\/+$/g, '');
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Returns the last segment of a slash-delimited path.
|
|
536
|
+
*/
|
|
537
|
+
function lastSegment(path) {
|
|
538
|
+
const parts = path.split('/');
|
|
539
|
+
return parts[parts.length - 1];
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Recursively collects all valid protocol path strings from a structure object.
|
|
543
|
+
*
|
|
544
|
+
* Given `{ foo: { bar: { $actions: [...] } } }`, returns `Set(['foo', 'foo/bar'])`.
|
|
545
|
+
* Keys starting with `$` are skipped.
|
|
546
|
+
*/
|
|
547
|
+
function collectPaths(structure, prefix = '') {
|
|
548
|
+
const paths = new Set();
|
|
549
|
+
for (const key of Object.keys(structure)) {
|
|
550
|
+
if (key.startsWith('$')) {
|
|
551
|
+
continue;
|
|
552
|
+
}
|
|
553
|
+
const fullPath = prefix ? `${prefix}/${key}` : key;
|
|
554
|
+
paths.add(fullPath);
|
|
555
|
+
const child = structure[key];
|
|
556
|
+
if (child !== null && typeof child === 'object') {
|
|
557
|
+
for (const nested of collectPaths(child, fullPath)) {
|
|
558
|
+
paths.add(nested);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return paths;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Deterministic JSON serialization with sorted keys.
|
|
566
|
+
*/
|
|
567
|
+
function stableStringify(value) {
|
|
568
|
+
if (value === null || value === undefined || typeof value !== 'object') {
|
|
569
|
+
return JSON.stringify(value);
|
|
570
|
+
}
|
|
571
|
+
if (Array.isArray(value)) {
|
|
572
|
+
return '[' + value.map((item) => stableStringify(item)).join(',') + ']';
|
|
573
|
+
}
|
|
574
|
+
const keys = Object.keys(value).sort();
|
|
575
|
+
const pairs = keys.map((key) => JSON.stringify(key) + ':' + stableStringify(value[key]));
|
|
576
|
+
return '{' + pairs.join(',') + '}';
|
|
577
|
+
}
|
|
578
|
+
// ---------------------------------------------------------------------------
|
|
579
|
+
// Deprecated alias — migration aid
|
|
580
|
+
// ---------------------------------------------------------------------------
|
|
581
|
+
/** @deprecated Use {@link TypedEnbox} instead. Will be removed in a future version. */
|
|
582
|
+
export const TypedWeb5 = TypedEnbox;
|
|
583
|
+
//# sourceMappingURL=typed-enbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed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AAC,EAAE,CAAC;QACzB,OAAO,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAC1E,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAA2C,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAC7B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,eAAe,CAAE,KAA4C,CAAC,GAAG,CAAC,CAAC,CAChG,CAAC;IACF,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACrC,CAAC;AAED,8EAA8E;AAC9E,mCAAmC;AACnC,8EAA8E;AAE9E,uFAAuF;AACvF,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC"}
|
|
@@ -45,7 +45,7 @@ import { TypedRecord } from './typed-record.js';
|
|
|
45
45
|
* A type-safe wrapper around {@link LiveQuery} that preserves the data type `T`
|
|
46
46
|
* through the initial snapshot and all subsequent change events.
|
|
47
47
|
*
|
|
48
|
-
* Obtain instances through `
|
|
48
|
+
* Obtain instances through `TypedEnbox.records.subscribe()` — never construct
|
|
49
49
|
* directly.
|
|
50
50
|
*/
|
|
51
51
|
export class TypedLiveQuery {
|