@enbox/api 0.2.3 → 0.3.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 +235 -35
- package/dist/browser.mjs +13 -13
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/dwn-api.js +24 -10
- package/dist/esm/dwn-api.js.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/live-query.js +34 -5
- package/dist/esm/live-query.js.map +1 -1
- package/dist/esm/permission-grant.js +3 -6
- package/dist/esm/permission-grant.js.map +1 -1
- package/dist/esm/permission-request.js +4 -7
- package/dist/esm/permission-request.js.map +1 -1
- package/dist/esm/record-data.js +131 -0
- package/dist/esm/record-data.js.map +1 -0
- package/dist/esm/record-types.js +9 -0
- package/dist/esm/record-types.js.map +1 -0
- package/dist/esm/record.js +58 -184
- package/dist/esm/record.js.map +1 -1
- package/dist/esm/repository-types.js +13 -0
- package/dist/esm/repository-types.js.map +1 -0
- package/dist/esm/repository.js +347 -0
- package/dist/esm/repository.js.map +1 -0
- package/dist/esm/typed-live-query.js +129 -0
- package/dist/esm/typed-live-query.js.map +1 -0
- package/dist/esm/typed-record.js +227 -0
- package/dist/esm/typed-record.js.map +1 -0
- package/dist/esm/typed-web5.js +134 -23
- package/dist/esm/typed-web5.js.map +1 -1
- package/dist/esm/web5.js +83 -22
- package/dist/esm/web5.js.map +1 -1
- package/dist/types/dwn-api.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/live-query.d.ts +43 -4
- package/dist/types/live-query.d.ts.map +1 -1
- package/dist/types/permission-grant.d.ts +1 -1
- package/dist/types/permission-grant.d.ts.map +1 -1
- package/dist/types/permission-request.d.ts +1 -1
- package/dist/types/permission-request.d.ts.map +1 -1
- package/dist/types/record-data.d.ts +49 -0
- package/dist/types/record-data.d.ts.map +1 -0
- package/dist/types/record-types.d.ts +145 -0
- package/dist/types/record-types.d.ts.map +1 -0
- package/dist/types/record.d.ts +13 -144
- package/dist/types/record.d.ts.map +1 -1
- package/dist/types/repository-types.d.ts +137 -0
- package/dist/types/repository-types.d.ts.map +1 -0
- package/dist/types/repository.d.ts +59 -0
- package/dist/types/repository.d.ts.map +1 -0
- package/dist/types/typed-live-query.d.ts +111 -0
- package/dist/types/typed-live-query.d.ts.map +1 -0
- package/dist/types/typed-record.d.ts +179 -0
- package/dist/types/typed-record.d.ts.map +1 -0
- package/dist/types/typed-web5.d.ts +55 -24
- package/dist/types/typed-web5.d.ts.map +1 -1
- package/dist/types/web5.d.ts +54 -4
- package/dist/types/web5.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/dwn-api.ts +30 -13
- package/src/index.ts +6 -0
- package/src/live-query.ts +71 -7
- package/src/permission-grant.ts +2 -3
- package/src/permission-request.ts +3 -4
- package/src/record-data.ts +155 -0
- package/src/record-types.ts +188 -0
- package/src/record.ts +86 -389
- package/src/repository-types.ts +249 -0
- package/src/repository.ts +391 -0
- package/src/typed-live-query.ts +200 -0
- package/src/typed-record.ts +309 -0
- package/src/typed-web5.ts +202 -49
- package/src/web5.ts +162 -27
package/src/live-query.ts
CHANGED
|
@@ -67,6 +67,21 @@ export type LiveQueryOptions = {
|
|
|
67
67
|
subscription: DwnMessageSubscription;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Catch-all event type that fires for any record change (create, update, or delete).
|
|
72
|
+
*/
|
|
73
|
+
export type RecordCatchAllEvent = 'change';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Lifecycle event type for connection state changes.
|
|
77
|
+
*/
|
|
78
|
+
export type LiveQueryLifecycleEvent = 'disconnected' | 'reconnecting' | 'reconnected' | 'eose';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Union of all event types emitted by {@link LiveQuery}.
|
|
82
|
+
*/
|
|
83
|
+
export type LiveQueryEventType = RecordChangeType | RecordCatchAllEvent | LiveQueryLifecycleEvent;
|
|
84
|
+
|
|
70
85
|
/**
|
|
71
86
|
* A live query that combines an initial snapshot of matching records with a
|
|
72
87
|
* real-time stream of deduplicated, semantically-typed change events.
|
|
@@ -84,6 +99,10 @@ export type LiveQueryOptions = {
|
|
|
84
99
|
* | `update` | {@link RecordChange} | An existing record was updated |
|
|
85
100
|
* | `delete` | {@link RecordChange} | A record was deleted |
|
|
86
101
|
* | `change` | {@link RecordChange} | Catch-all for any of the above |
|
|
102
|
+
* | `disconnected` | — | Transport connection lost |
|
|
103
|
+
* | `reconnecting` | `{ attempt: number }` | Reconnection attempt in progress |
|
|
104
|
+
* | `reconnected` | — | Connection restored, subscription resubscribed |
|
|
105
|
+
* | `eose` | — | End-of-stored-events: catch-up replay complete, events are now live |
|
|
87
106
|
*
|
|
88
107
|
* @example
|
|
89
108
|
* ```ts
|
|
@@ -106,10 +125,10 @@ export type LiveQueryOptions = {
|
|
|
106
125
|
* liveQuery.on('update', (record) => refreshMessage(record));
|
|
107
126
|
* liveQuery.on('delete', (record) => removeMessage(record));
|
|
108
127
|
*
|
|
109
|
-
* //
|
|
110
|
-
* liveQuery.on('
|
|
111
|
-
*
|
|
112
|
-
*
|
|
128
|
+
* // Connection lifecycle
|
|
129
|
+
* liveQuery.on('disconnected', () => showOfflineIndicator());
|
|
130
|
+
* liveQuery.on('reconnected', () => hideOfflineIndicator());
|
|
131
|
+
* liveQuery.on('eose', () => console.log('catch-up complete'));
|
|
113
132
|
*
|
|
114
133
|
* // Cleanup
|
|
115
134
|
* await liveQuery.close();
|
|
@@ -139,6 +158,9 @@ export class LiveQuery extends EventTarget {
|
|
|
139
158
|
/** Whether the live query has been closed. */
|
|
140
159
|
private _closed = false;
|
|
141
160
|
|
|
161
|
+
/** Whether the transport connection is currently active. */
|
|
162
|
+
private _connected = true;
|
|
163
|
+
|
|
142
164
|
constructor(options: LiveQueryOptions) {
|
|
143
165
|
super();
|
|
144
166
|
|
|
@@ -174,6 +196,11 @@ export class LiveQuery extends EventTarget {
|
|
|
174
196
|
}
|
|
175
197
|
}
|
|
176
198
|
|
|
199
|
+
/** Whether the transport connection is currently active. */
|
|
200
|
+
public get isConnected(): boolean {
|
|
201
|
+
return this._connected;
|
|
202
|
+
}
|
|
203
|
+
|
|
177
204
|
/**
|
|
178
205
|
* Process an incoming live event from the DWN subscription.
|
|
179
206
|
* Deduplicates against the initial snapshot and classifies the change type.
|
|
@@ -217,6 +244,31 @@ export class LiveQuery extends EventTarget {
|
|
|
217
244
|
this.dispatchEvent(new CustomEvent('change', { detail: change }));
|
|
218
245
|
}
|
|
219
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Handle a transport lifecycle event (disconnected, reconnecting, reconnected)
|
|
249
|
+
* or an EOSE marker from the subscription.
|
|
250
|
+
*
|
|
251
|
+
* @internal — Called by `DwnApi.records.subscribe()` when the handler receives
|
|
252
|
+
* non-record subscription messages.
|
|
253
|
+
*/
|
|
254
|
+
public handleLifecycleEvent(type: 'disconnected'): void;
|
|
255
|
+
public handleLifecycleEvent(type: 'reconnecting', detail: { attempt: number }): void;
|
|
256
|
+
public handleLifecycleEvent(type: 'reconnected'): void;
|
|
257
|
+
public handleLifecycleEvent(type: 'eose'): void;
|
|
258
|
+
public handleLifecycleEvent(type: LiveQueryLifecycleEvent, detail?: { attempt: number }): void {
|
|
259
|
+
if (this._closed) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (type === 'disconnected') {
|
|
264
|
+
this._connected = false;
|
|
265
|
+
} else if (type === 'reconnected') {
|
|
266
|
+
this._connected = true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
this.dispatchEvent(new CustomEvent(type, { detail }));
|
|
270
|
+
}
|
|
271
|
+
|
|
220
272
|
/**
|
|
221
273
|
* Register a typed event handler. Returns an unsubscribe function.
|
|
222
274
|
*
|
|
@@ -234,13 +286,25 @@ export class LiveQuery extends EventTarget {
|
|
|
234
286
|
on(event: 'create', handler: (record: Record) => void): () => void;
|
|
235
287
|
on(event: 'update', handler: (record: Record) => void): () => void;
|
|
236
288
|
on(event: 'delete', handler: (record: Record) => void): () => void;
|
|
237
|
-
on(event: '
|
|
289
|
+
on(event: 'disconnected', handler: () => void): () => void;
|
|
290
|
+
on(event: 'reconnecting', handler: (detail: { attempt: number }) => void): () => void;
|
|
291
|
+
on(event: 'reconnected', handler: () => void): () => void;
|
|
292
|
+
on(event: 'eose', handler: () => void): () => void;
|
|
293
|
+
on(
|
|
294
|
+
event: LiveQueryEventType,
|
|
295
|
+
handler: ((change: RecordChange) => void) | ((record: Record) => void) | ((detail: { attempt: number }) => void) | (() => void),
|
|
296
|
+
): () => void {
|
|
238
297
|
const wrapper = (e: Event): void => {
|
|
239
|
-
const detail = (e as CustomEvent
|
|
298
|
+
const detail = (e as CustomEvent).detail;
|
|
240
299
|
if (event === 'change') {
|
|
241
300
|
(handler as (change: RecordChange) => void)(detail);
|
|
242
|
-
} else {
|
|
301
|
+
} else if (event === 'create' || event === 'update' || event === 'delete') {
|
|
243
302
|
(handler as (record: Record) => void)(detail.record);
|
|
303
|
+
} else if (event === 'reconnecting') {
|
|
304
|
+
(handler as (detail: { attempt: number }) => void)(detail);
|
|
305
|
+
} else {
|
|
306
|
+
// disconnected, reconnected, eose — no payload
|
|
307
|
+
(handler as () => void)();
|
|
244
308
|
}
|
|
245
309
|
};
|
|
246
310
|
|
package/src/permission-grant.ts
CHANGED
|
@@ -120,9 +120,8 @@ export class PermissionGrant implements PermissionGrantModel {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/** parses the grant given an agent, connectedDid and data encoded records write message */
|
|
123
|
-
static
|
|
124
|
-
|
|
125
|
-
const grant = await DwnPermissionGrant.parse(options.message);
|
|
123
|
+
static parse(options: PermissionGrantOptions): PermissionGrant {
|
|
124
|
+
const grant = DwnPermissionGrant.parse(options.message);
|
|
126
125
|
const api = new AgentPermissionsApi({ agent: options.agent });
|
|
127
126
|
return new PermissionGrant({ ...options, grant, api });
|
|
128
127
|
}
|
|
@@ -84,13 +84,12 @@ export class PermissionRequest implements PermissionRequestModel {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/** parses the request given an agent, connectedDid and data encoded records write message */
|
|
87
|
-
static
|
|
87
|
+
static parse({ connectedDid, agent, message }:{
|
|
88
88
|
connectedDid: string;
|
|
89
89
|
agent: Web5Agent;
|
|
90
90
|
message: DwnDataEncodedRecordsWriteMessage;
|
|
91
|
-
}):
|
|
92
|
-
|
|
93
|
-
const request = await DwnPermissionRequest.parse(message);
|
|
91
|
+
}): PermissionRequest {
|
|
92
|
+
const request = DwnPermissionRequest.parse(message);
|
|
94
93
|
const api = new AgentPermissionsApi({ agent });
|
|
95
94
|
return new PermissionRequest({ api, connectedDid, message, request });
|
|
96
95
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data-access helpers for the {@link Record} class.
|
|
3
|
+
*
|
|
4
|
+
* `RecordData` is the object returned by `Record.data`. It wraps a lazily
|
|
5
|
+
* evaluated `stream()` function with convenience accessors that mirror the
|
|
6
|
+
* Fetch `Response` API (`blob()`, `bytes()`, `json()`, `text()`).
|
|
7
|
+
*
|
|
8
|
+
* Extracted from `record.ts` so the convenience-method boilerplate lives in
|
|
9
|
+
* its own module while the stream-resolution logic (which is tightly coupled
|
|
10
|
+
* to `Record` internals) stays inside the `Record` class.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Stream } from '@enbox/common';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A thenable data accessor returned by {@link Record.data}.
|
|
19
|
+
*
|
|
20
|
+
* Provides convenience methods for consuming the record's data in various
|
|
21
|
+
* formats, plus `then`/`catch` so the object can be awaited directly to
|
|
22
|
+
* obtain the underlying `ReadableStream`.
|
|
23
|
+
*
|
|
24
|
+
* @beta
|
|
25
|
+
*/
|
|
26
|
+
export type RecordData = {
|
|
27
|
+
/** Consume the data as a `Blob`. */
|
|
28
|
+
blob: () => Promise<Blob>;
|
|
29
|
+
/** Consume the data as raw bytes. */
|
|
30
|
+
bytes: () => Promise<Uint8Array>;
|
|
31
|
+
/** Parse the data as JSON. */
|
|
32
|
+
json: <T = unknown>() => Promise<T>;
|
|
33
|
+
/** Consume the data as a UTF-8 string. */
|
|
34
|
+
text: () => Promise<string>;
|
|
35
|
+
/** Obtain the underlying Web `ReadableStream`. */
|
|
36
|
+
stream: () => Promise<ReadableStream>;
|
|
37
|
+
/** Proxy for `stream().then(...)` so the object is directly awaitable. */
|
|
38
|
+
then: (
|
|
39
|
+
onFulfilled?: (value: ReadableStream) => ReadableStream | PromiseLike<ReadableStream>,
|
|
40
|
+
onRejected?: (reason: any) => PromiseLike<never>,
|
|
41
|
+
) => Promise<ReadableStream>;
|
|
42
|
+
/** Proxy for `stream().catch(...)`. */
|
|
43
|
+
catch: (onRejected?: (reason: any) => PromiseLike<never>) => Promise<ReadableStream>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a {@link RecordData} wrapper around a `stream` provider function.
|
|
48
|
+
*
|
|
49
|
+
* @param streamFn - A function that returns a `Promise<ReadableStream>` for the record data.
|
|
50
|
+
* @param dataFormat - The MIME type used when constructing Blobs.
|
|
51
|
+
* @returns A {@link RecordData} object with convenience accessors.
|
|
52
|
+
*
|
|
53
|
+
* @beta
|
|
54
|
+
*/
|
|
55
|
+
export function createRecordData(streamFn: () => Promise<ReadableStream>, dataFormat: string | undefined): RecordData {
|
|
56
|
+
const dataObj: RecordData = {
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the data of the current record as a `Blob`.
|
|
60
|
+
*
|
|
61
|
+
* @returns A promise that resolves to a Blob containing the record's data.
|
|
62
|
+
* @throws If the record data is not available or cannot be converted to a `Blob`.
|
|
63
|
+
*
|
|
64
|
+
* @beta
|
|
65
|
+
*/
|
|
66
|
+
async blob(): Promise<Blob> {
|
|
67
|
+
return new Blob([await Stream.consumeToBytes({ readableStream: await this.stream() })], { type: dataFormat });
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Returns the data of the current record as a `Uint8Array`.
|
|
72
|
+
*
|
|
73
|
+
* @returns A Promise that resolves to a `Uint8Array` containing the record's data bytes.
|
|
74
|
+
* @throws If the record data is not available or cannot be converted to a byte array.
|
|
75
|
+
*
|
|
76
|
+
* @beta
|
|
77
|
+
*/
|
|
78
|
+
async bytes(): Promise<Uint8Array> {
|
|
79
|
+
return await Stream.consumeToBytes({ readableStream: await this.stream() });
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parses the data of the current record as JSON and returns it as a JavaScript object.
|
|
84
|
+
*
|
|
85
|
+
* @returns A Promise that resolves to a JavaScript object parsed from the record's JSON data.
|
|
86
|
+
* @throws If the record data is not available, not in JSON format, or cannot be parsed.
|
|
87
|
+
*
|
|
88
|
+
* @beta
|
|
89
|
+
*/
|
|
90
|
+
async json<T = unknown>(): Promise<T> {
|
|
91
|
+
return await Stream.consumeToJson({ readableStream: await this.stream() }) as T;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Returns the data of the current record as a `string`.
|
|
96
|
+
*
|
|
97
|
+
* @returns A promise that resolves to a `string` containing the record's text data.
|
|
98
|
+
* @throws If the record data is not available or cannot be converted to text.
|
|
99
|
+
*
|
|
100
|
+
* @beta
|
|
101
|
+
*/
|
|
102
|
+
async text(): Promise<string> {
|
|
103
|
+
return await Stream.consumeToText({ readableStream: await this.stream() });
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Provides a Web `ReadableStream` containing the record's data.
|
|
108
|
+
*
|
|
109
|
+
* Uses the standard Web Streams API for cross-platform compatibility across
|
|
110
|
+
* browsers, Node.js, Bun, and Deno.
|
|
111
|
+
*
|
|
112
|
+
* @returns A promise that resolves to a Web `ReadableStream` of the record's data.
|
|
113
|
+
* @throws If the record data is not available in-memory and cannot be fetched.
|
|
114
|
+
*
|
|
115
|
+
* @beta
|
|
116
|
+
*/
|
|
117
|
+
stream: streamFn,
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Attaches callbacks for the resolution and/or rejection of the `Promise` returned by
|
|
121
|
+
* `stream()`.
|
|
122
|
+
*
|
|
123
|
+
* This method is a proxy to the `then` method of the `Promise` returned by `stream()`,
|
|
124
|
+
* allowing for a seamless integration with promise-based workflows.
|
|
125
|
+
* @param onFulfilled - A function to asynchronously execute when the `stream()` promise
|
|
126
|
+
* becomes fulfilled.
|
|
127
|
+
* @param onRejected - A function to asynchronously execute when the `stream()` promise
|
|
128
|
+
* becomes rejected.
|
|
129
|
+
* @returns A `Promise` for the completion of which ever callback is executed.
|
|
130
|
+
*/
|
|
131
|
+
then(
|
|
132
|
+
onFulfilled?: (value: ReadableStream) => ReadableStream | PromiseLike<ReadableStream>,
|
|
133
|
+
onRejected?: (reason: any) => PromiseLike<never>,
|
|
134
|
+
): Promise<ReadableStream> {
|
|
135
|
+
return this.stream().then(onFulfilled, onRejected);
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Attaches a rejection handler callback to the `Promise` returned by the `stream()` method.
|
|
140
|
+
* This method is a shorthand for `.then(undefined, onRejected)`, specifically designed for handling
|
|
141
|
+
* rejection cases in the promise chain initiated by accessing the record's data. It ensures that
|
|
142
|
+
* errors during data retrieval or processing can be caught and handled appropriately.
|
|
143
|
+
*
|
|
144
|
+
* @param onRejected - A function to asynchronously execute when the `stream()` promise
|
|
145
|
+
* becomes rejected.
|
|
146
|
+
* @returns A `Promise` that resolves to the value of the callback if it is called, or to its
|
|
147
|
+
* original fulfillment value if the promise is instead fulfilled.
|
|
148
|
+
*/
|
|
149
|
+
catch(onRejected?: (reason: any) => PromiseLike<never>): Promise<ReadableStream> {
|
|
150
|
+
return this.stream().catch(onRejected);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
return dataObj;
|
|
155
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the {@link Record} class.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from `record.ts` to keep the main module focused on behaviour.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
DwnMessage,
|
|
11
|
+
DwnMessageDescriptor,
|
|
12
|
+
} from '@enbox/agent';
|
|
13
|
+
|
|
14
|
+
import type { DwnInterface } from '@enbox/agent';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents Immutable Record properties that cannot be changed after the record is created.
|
|
18
|
+
*
|
|
19
|
+
* @beta
|
|
20
|
+
* */
|
|
21
|
+
export type ImmutableRecordProperties =
|
|
22
|
+
Pick<DwnMessageDescriptor[DwnInterface.RecordsWrite], 'dateCreated' | 'parentId' | 'protocol' | 'protocolPath' | 'recipient' | 'schema'>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Represents Optional Record properties that depend on the Record's current state.
|
|
26
|
+
*
|
|
27
|
+
* @beta
|
|
28
|
+
*/
|
|
29
|
+
export type OptionalRecordProperties =
|
|
30
|
+
Pick<DwnMessage[DwnInterface.RecordsWrite], 'authorization' | 'attestation' | 'encryption' | 'contextId' > &
|
|
31
|
+
Pick<DwnMessageDescriptor[DwnInterface.RecordsWrite], 'dataFormat' | 'dataCid' | 'dataSize' | 'datePublished' | 'published' | 'tags'>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Represents the structured data model of a record, encapsulating the essential fields that define
|
|
35
|
+
* the record's metadata and payload within a Decentralized Web Node (DWN).
|
|
36
|
+
*
|
|
37
|
+
* @beta
|
|
38
|
+
*/
|
|
39
|
+
export type RecordModel = ImmutableRecordProperties & OptionalRecordProperties & {
|
|
40
|
+
|
|
41
|
+
/** The logical author of the record. */
|
|
42
|
+
author: string;
|
|
43
|
+
|
|
44
|
+
/** The unique identifier of the record. */
|
|
45
|
+
recordId?: string;
|
|
46
|
+
|
|
47
|
+
/** The message timestamp (time of creation, most recent update, or deletion). */
|
|
48
|
+
timestamp?: string;
|
|
49
|
+
|
|
50
|
+
/** The protocol role under which this record is written. */
|
|
51
|
+
protocolRole?: RecordOptions['protocolRole'];
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Options for configuring a {@link Record} instance, extending the base `RecordsWriteMessage` with
|
|
56
|
+
* additional properties.
|
|
57
|
+
*
|
|
58
|
+
* This type combines the standard fields required for writing DWN records with additional metadata
|
|
59
|
+
* and configuration options used specifically in the {@link Record} class.
|
|
60
|
+
*
|
|
61
|
+
* @beta
|
|
62
|
+
*/
|
|
63
|
+
export type RecordOptions = DwnMessage[DwnInterface.RecordsWrite | DwnInterface.RecordsDelete] & {
|
|
64
|
+
/** The DID that signed the record. */
|
|
65
|
+
author: string;
|
|
66
|
+
|
|
67
|
+
/** The attestation signature(s) for the record. */
|
|
68
|
+
attestation?: DwnMessage[DwnInterface.RecordsWrite]['attestation'];
|
|
69
|
+
|
|
70
|
+
/** The encryption information for the record. */
|
|
71
|
+
encryption?: DwnMessage[DwnInterface.RecordsWrite]['encryption'];
|
|
72
|
+
|
|
73
|
+
/** The contextId associated with the record. */
|
|
74
|
+
contextId?: string;
|
|
75
|
+
|
|
76
|
+
/** The unique identifier of the record */
|
|
77
|
+
recordId?: string;
|
|
78
|
+
|
|
79
|
+
/** The DID of the DWN tenant under which record operations are being performed. */
|
|
80
|
+
connectedDid: string;
|
|
81
|
+
|
|
82
|
+
/** The optional DID that will sign the records on behalf of the connectedDid */
|
|
83
|
+
delegateDid?: string;
|
|
84
|
+
|
|
85
|
+
/** The data of the record, either as a Base64 URL encoded string or a Blob. */
|
|
86
|
+
encodedData?: string | Blob;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A stream of data, conforming to the Web `ReadableStream` interface, providing a mechanism
|
|
90
|
+
* to read the record's data sequentially. This is particularly useful for handling large
|
|
91
|
+
* datasets that should not be loaded entirely in memory, allowing for efficient, chunked
|
|
92
|
+
* processing of the record's data.
|
|
93
|
+
*
|
|
94
|
+
* The DWN SDK now returns Web `ReadableStream` natively, so no conversion is needed.
|
|
95
|
+
*/
|
|
96
|
+
data?: ReadableStream;
|
|
97
|
+
|
|
98
|
+
/** The initial `RecordsWriteMessage` that represents the initial state/version of the record. */
|
|
99
|
+
initialWrite?: DwnMessage[DwnInterface.RecordsWrite];
|
|
100
|
+
|
|
101
|
+
/** The protocol role under which this record is written. */
|
|
102
|
+
protocolRole?: string;
|
|
103
|
+
|
|
104
|
+
/** The remote tenant DID if the record was queried or read from a remote DWN. */
|
|
105
|
+
remoteOrigin?: string;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Parameters for updating a DWN record.
|
|
110
|
+
*
|
|
111
|
+
* This type specifies the set of properties that can be updated on an existing record. It is used
|
|
112
|
+
* to convey the new state or changes to be applied to the record.
|
|
113
|
+
*
|
|
114
|
+
* @beta
|
|
115
|
+
*/
|
|
116
|
+
export type RecordUpdateParams = {
|
|
117
|
+
/**
|
|
118
|
+
* The new data for the record, which can be of any type. This data will replace the existing
|
|
119
|
+
* data of the record. It's essential to ensure that this data is compatible with the record's
|
|
120
|
+
* schema or data format expectations.
|
|
121
|
+
*/
|
|
122
|
+
data?: unknown;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The Content Identifier (CID) of the data. Updating this value changes the reference to the data
|
|
126
|
+
* associated with the record.
|
|
127
|
+
*/
|
|
128
|
+
dataCid?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['dataCid'];
|
|
129
|
+
|
|
130
|
+
/** Whether or not to store the updated message. */
|
|
131
|
+
store?: boolean;
|
|
132
|
+
|
|
133
|
+
/** The data format/MIME type of the supplied data */
|
|
134
|
+
dataFormat?: string;
|
|
135
|
+
|
|
136
|
+
/** The size of the data in bytes. */
|
|
137
|
+
dataSize?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['dataSize'];
|
|
138
|
+
|
|
139
|
+
/** The timestamp of the update message. */
|
|
140
|
+
timestamp?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['messageTimestamp'];
|
|
141
|
+
|
|
142
|
+
/** The timestamp indicating when the record was published. */
|
|
143
|
+
datePublished?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['datePublished'];
|
|
144
|
+
|
|
145
|
+
/** The protocol role under which this record is written. */
|
|
146
|
+
protocolRole?: RecordOptions['protocolRole'];
|
|
147
|
+
|
|
148
|
+
/** The published status of the record. */
|
|
149
|
+
published?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['published'];
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/** The tags associated with the updated record */
|
|
153
|
+
tags?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['tags'];
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Controls whether the updated record should be auto-encrypted.
|
|
157
|
+
*
|
|
158
|
+
* If omitted, auto-detected from the original record: if the record was
|
|
159
|
+
* originally encrypted, the update is automatically re-encrypted with a
|
|
160
|
+
* fresh DEK. Set to `false` explicitly to skip encryption on the update.
|
|
161
|
+
*/
|
|
162
|
+
encryption?: boolean;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Parameters for deleting a DWN record.
|
|
167
|
+
*
|
|
168
|
+
* This type specifies the set of properties that are used when deleting an existing record. It is used
|
|
169
|
+
* to convey the new state or changes to be applied to the record.
|
|
170
|
+
*
|
|
171
|
+
* @beta
|
|
172
|
+
*/
|
|
173
|
+
export type RecordDeleteParams = {
|
|
174
|
+
/** Whether or not to store the message. */
|
|
175
|
+
store?: boolean;
|
|
176
|
+
|
|
177
|
+
/** Whether or not to sign the delete as an owner in order to import it. */
|
|
178
|
+
signAsOwner?: boolean;
|
|
179
|
+
|
|
180
|
+
/** Whether or not to prune any children this record may have. */
|
|
181
|
+
prune?: DwnMessageDescriptor[DwnInterface.RecordsDelete]['prune'];
|
|
182
|
+
|
|
183
|
+
/** The timestamp of the delete message. */
|
|
184
|
+
timestamp?: DwnMessageDescriptor[DwnInterface.RecordsDelete]['messageTimestamp'];
|
|
185
|
+
|
|
186
|
+
/** The protocol role under which this record will be deleted. */
|
|
187
|
+
protocolRole?: string;
|
|
188
|
+
};
|