@enbox/api 0.2.3 → 0.2.4
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 +101 -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 +78 -20
- 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 +86 -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 +47 -2
- 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 +156 -0
- package/src/typed-record.ts +309 -0
- package/src/typed-web5.ts +202 -49
- package/src/web5.ts +150 -23
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type-safe wrapper around {@link LiveQuery} that carries the data type `T`
|
|
3
|
+
* through initial snapshot records and real-time change events.
|
|
4
|
+
*
|
|
5
|
+
* `TypedLiveQuery<T>` wraps a `LiveQuery` so that:
|
|
6
|
+
* - `.records` returns `TypedRecord<T>[]` instead of `Record[]`.
|
|
7
|
+
* - `.on('create', handler)` provides `TypedRecord<T>` in the callback.
|
|
8
|
+
* - `.on('change', handler)` provides `TypedRecordChange<T>` in the callback.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const { liveQuery } = await typed.records.subscribe('friend');
|
|
13
|
+
* // liveQuery is TypedLiveQuery<FriendData>
|
|
14
|
+
*
|
|
15
|
+
* for (const record of liveQuery.records) {
|
|
16
|
+
* const data = await record.data.json(); // FriendData
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* liveQuery.on('create', async (record) => {
|
|
20
|
+
* const data = await record.data.json(); // FriendData
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { PaginationCursor } from '@enbox/dwn-sdk-js';
|
|
26
|
+
import type { LiveQuery, RecordChange } from './live-query.js';
|
|
27
|
+
|
|
28
|
+
import { TypedRecord } from './typed-record.js';
|
|
29
|
+
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Typed change event
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Describes a change to a record in a {@link TypedLiveQuery}.
|
|
36
|
+
*
|
|
37
|
+
* Same shape as {@link RecordChange} but with the record wrapped
|
|
38
|
+
* in a {@link TypedRecord}.
|
|
39
|
+
*/
|
|
40
|
+
export type TypedRecordChange<T> = {
|
|
41
|
+
/** Whether the record was created, updated, or deleted. */
|
|
42
|
+
type: RecordChange['type'];
|
|
43
|
+
|
|
44
|
+
/** The typed record affected by the change. */
|
|
45
|
+
record: TypedRecord<T>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// TypedLiveQuery class
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A type-safe wrapper around {@link LiveQuery} that preserves the data type `T`
|
|
54
|
+
* through the initial snapshot and all subsequent change events.
|
|
55
|
+
*
|
|
56
|
+
* Obtain instances through `TypedWeb5.records.subscribe()` — never construct
|
|
57
|
+
* directly.
|
|
58
|
+
*/
|
|
59
|
+
export class TypedLiveQuery<T> {
|
|
60
|
+
/** The underlying untyped LiveQuery instance. */
|
|
61
|
+
private _liveQuery: LiveQuery;
|
|
62
|
+
|
|
63
|
+
/** Cached typed record array, built lazily from the underlying records. */
|
|
64
|
+
private _typedRecords?: TypedRecord<T>[];
|
|
65
|
+
|
|
66
|
+
constructor(liveQuery: LiveQuery) {
|
|
67
|
+
this._liveQuery = liveQuery;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// -------------------------------------------------------------------------
|
|
71
|
+
// Escape hatch
|
|
72
|
+
// -------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
/** Access the underlying untyped {@link LiveQuery} for advanced use cases. */
|
|
75
|
+
public get rawLiveQuery(): LiveQuery {
|
|
76
|
+
return this._liveQuery;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// -------------------------------------------------------------------------
|
|
80
|
+
// Typed initial snapshot
|
|
81
|
+
// -------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
/** The initial snapshot of matching records, typed as `TypedRecord<T>[]`. */
|
|
84
|
+
public get records(): TypedRecord<T>[] {
|
|
85
|
+
if (!this._typedRecords) {
|
|
86
|
+
this._typedRecords = this._liveQuery.records.map(
|
|
87
|
+
(record) => new TypedRecord<T>(record),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return this._typedRecords;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Pagination cursor for fetching the next page of initial results.
|
|
95
|
+
*
|
|
96
|
+
* `undefined` when there are no more results.
|
|
97
|
+
*/
|
|
98
|
+
public get cursor(): PaginationCursor | undefined {
|
|
99
|
+
return this._liveQuery.cursor;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// -------------------------------------------------------------------------
|
|
103
|
+
// Typed event handlers
|
|
104
|
+
// -------------------------------------------------------------------------
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Register a typed event handler. Returns an unsubscribe function.
|
|
108
|
+
*
|
|
109
|
+
* @param event - The event type to listen for.
|
|
110
|
+
* @param handler - The handler function with typed record(s).
|
|
111
|
+
* @returns A function that removes the handler when called.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const off = liveQuery.on('create', (record) => {
|
|
116
|
+
* // record is TypedRecord<T>
|
|
117
|
+
* });
|
|
118
|
+
* off(); // stop listening
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
public on(event: 'change', handler: (change: TypedRecordChange<T>) => void): () => void;
|
|
122
|
+
public on(event: 'create', handler: (record: TypedRecord<T>) => void): () => void;
|
|
123
|
+
public on(event: 'update', handler: (record: TypedRecord<T>) => void): () => void;
|
|
124
|
+
public on(event: 'delete', handler: (record: TypedRecord<T>) => void): () => void;
|
|
125
|
+
public on(
|
|
126
|
+
event: 'change' | 'create' | 'update' | 'delete',
|
|
127
|
+
handler: ((change: TypedRecordChange<T>) => void) | ((record: TypedRecord<T>) => void),
|
|
128
|
+
): () => void {
|
|
129
|
+
if (event === 'change') {
|
|
130
|
+
return this._liveQuery.on('change', (change: RecordChange): void => {
|
|
131
|
+
(handler as (change: TypedRecordChange<T>) => void)({
|
|
132
|
+
type : change.type,
|
|
133
|
+
record : new TypedRecord<T>(change.record),
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// For create/update/delete, the underlying LiveQuery handler receives a Record.
|
|
139
|
+
// Cast event to 'create' to satisfy the overload resolver — the actual value
|
|
140
|
+
// is always one of 'create' | 'update' | 'delete' at this point.
|
|
141
|
+
return this._liveQuery.on(event as 'create', (record): void => {
|
|
142
|
+
(handler as (record: TypedRecord<T>) => void)(new TypedRecord<T>(record));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// -------------------------------------------------------------------------
|
|
147
|
+
// Lifecycle
|
|
148
|
+
// -------------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Close the underlying subscription and stop dispatching events.
|
|
152
|
+
*/
|
|
153
|
+
public async close(): Promise<void> {
|
|
154
|
+
return this._liveQuery.close();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type-safe wrapper around {@link Record} that carries the data type `T`
|
|
3
|
+
* through its entire lifecycle — from write to read, query, update, and
|
|
4
|
+
* subscribe.
|
|
5
|
+
*
|
|
6
|
+
* `TypedRecord<T>` uses composition (not inheritance) to wrap the underlying
|
|
7
|
+
* untyped `Record` class. All read-only getters and lifecycle methods are
|
|
8
|
+
* forwarded, while data-access and mutation methods are enhanced with the
|
|
9
|
+
* generic `T`:
|
|
10
|
+
*
|
|
11
|
+
* - `.data.json()` returns `Promise<T>` instead of `Promise<unknown>`.
|
|
12
|
+
* - `.update({ data })` accepts `Partial<T>` for the data payload.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { record } = await typed.records.write('friend', {
|
|
17
|
+
* data: { did: 'did:example:alice', alias: 'Alice' },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // record is TypedRecord<FriendData>
|
|
21
|
+
* const data = await record.data.json(); // FriendData — no manual cast
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type { Record } from './record.js';
|
|
26
|
+
import type { RecordData } from './record-data.js';
|
|
27
|
+
import type { DwnDateSort, DwnMessage, DwnPaginationCursor, DwnResponseStatus } from '@enbox/agent';
|
|
28
|
+
import type { RecordDeleteParams, RecordModel, RecordUpdateParams } from './record-types.js';
|
|
29
|
+
|
|
30
|
+
import type { DwnInterface } from '@enbox/agent';
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Typed data accessor
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A data accessor that preserves the record's type parameter `T` on
|
|
38
|
+
* the `json()` method.
|
|
39
|
+
*
|
|
40
|
+
* All other methods (`blob`, `bytes`, `text`, `stream`, `then`, `catch`)
|
|
41
|
+
* are forwarded unchanged from the underlying {@link RecordData}.
|
|
42
|
+
*/
|
|
43
|
+
export type TypedRecordData<T> = Omit<RecordData, 'json'> & {
|
|
44
|
+
/** Parse the data as JSON, returning the typed data shape `T`. */
|
|
45
|
+
json: () => Promise<T>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Typed update params
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Update parameters for a {@link TypedRecord}.
|
|
54
|
+
*
|
|
55
|
+
* Extends the base `RecordUpdateParams` but narrows `data` from `unknown`
|
|
56
|
+
* to `Partial<T>`.
|
|
57
|
+
*/
|
|
58
|
+
export type TypedRecordUpdateParams<T> = Omit<RecordUpdateParams, 'data'> & {
|
|
59
|
+
/** The new data for the record. Type-checked against the schema map. */
|
|
60
|
+
data?: Partial<T>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Typed update / delete results
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Result of a {@link TypedRecord.update} operation.
|
|
69
|
+
*/
|
|
70
|
+
export type TypedRecordUpdateResult<T> = DwnResponseStatus & {
|
|
71
|
+
/** The updated record, carrying the same type parameter. */
|
|
72
|
+
record: TypedRecord<T>;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Result of a {@link TypedRecord.delete} operation.
|
|
77
|
+
*/
|
|
78
|
+
export type TypedRecordDeleteResult<T> = DwnResponseStatus & {
|
|
79
|
+
/** The deleted record, carrying the same type parameter. */
|
|
80
|
+
record: TypedRecord<T>;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// TypedRecord class
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A type-safe wrapper around {@link Record} that preserves the data type `T`.
|
|
89
|
+
*
|
|
90
|
+
* Obtain instances through `TypedWeb5.records.write()`, `.query()`, `.read()`,
|
|
91
|
+
* or `.subscribe()` — never construct directly.
|
|
92
|
+
*/
|
|
93
|
+
export class TypedRecord<T> {
|
|
94
|
+
/** The underlying untyped Record instance. */
|
|
95
|
+
private _record: Record;
|
|
96
|
+
|
|
97
|
+
constructor(record: Record) {
|
|
98
|
+
this._record = record;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// -------------------------------------------------------------------------
|
|
102
|
+
// Escape hatch
|
|
103
|
+
// -------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
/** Access the underlying untyped {@link Record} for advanced use cases. */
|
|
106
|
+
public get rawRecord(): Record {
|
|
107
|
+
return this._record;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// -------------------------------------------------------------------------
|
|
111
|
+
// Typed data accessor
|
|
112
|
+
// -------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns the data of the current record with type-safe accessors.
|
|
116
|
+
*
|
|
117
|
+
* The `json()` method returns `Promise<T>` — no manual generic needed.
|
|
118
|
+
*
|
|
119
|
+
* @throws `Error` if the record has been deleted.
|
|
120
|
+
*/
|
|
121
|
+
public get data(): TypedRecordData<T> {
|
|
122
|
+
const underlying = this._record.data;
|
|
123
|
+
return {
|
|
124
|
+
blob : (): Promise<Blob> => underlying.blob(),
|
|
125
|
+
bytes : (): Promise<Uint8Array> => underlying.bytes(),
|
|
126
|
+
json : (): Promise<T> => underlying.json<T>(),
|
|
127
|
+
text : (): Promise<string> => underlying.text(),
|
|
128
|
+
stream : (): Promise<ReadableStream> => underlying.stream(),
|
|
129
|
+
then : underlying.then.bind(underlying),
|
|
130
|
+
catch : underlying.catch.bind(underlying),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// -------------------------------------------------------------------------
|
|
135
|
+
// Typed mutation methods
|
|
136
|
+
// -------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Update the current record on the DWN.
|
|
140
|
+
*
|
|
141
|
+
* @param params - Parameters including the typed `data` payload.
|
|
142
|
+
* @returns The status and an updated {@link TypedRecord}.
|
|
143
|
+
* @throws `Error` if the record has been deleted.
|
|
144
|
+
*/
|
|
145
|
+
public async update(params: TypedRecordUpdateParams<T>): Promise<TypedRecordUpdateResult<T>> {
|
|
146
|
+
const { status, record } = await this._record.update(params as RecordUpdateParams);
|
|
147
|
+
return { status, record: new TypedRecord<T>(record) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Delete the current record on the DWN.
|
|
152
|
+
*
|
|
153
|
+
* @param params - Delete parameters.
|
|
154
|
+
* @returns The status and a {@link TypedRecord} reflecting the deleted state.
|
|
155
|
+
*/
|
|
156
|
+
public async delete(params?: RecordDeleteParams): Promise<TypedRecordDeleteResult<T>> {
|
|
157
|
+
const { status, record } = await this._record.delete(params);
|
|
158
|
+
return { status, record: new TypedRecord<T>(record) };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// -------------------------------------------------------------------------
|
|
162
|
+
// Forwarded lifecycle methods
|
|
163
|
+
// -------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Stores the current record state to the owner's DWN.
|
|
167
|
+
*
|
|
168
|
+
* @param importRecord - If true, sign as owner before storing. Defaults to false.
|
|
169
|
+
*/
|
|
170
|
+
public async store(importRecord: boolean = false): Promise<DwnResponseStatus> {
|
|
171
|
+
return this._record.store(importRecord);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Signs and optionally stores the record to the owner's DWN.
|
|
176
|
+
* Useful when importing a record signed by someone else.
|
|
177
|
+
*
|
|
178
|
+
* @param store - If true, store after signing. Defaults to true.
|
|
179
|
+
*/
|
|
180
|
+
public async import(store: boolean = true): Promise<DwnResponseStatus> {
|
|
181
|
+
return this._record.import(store);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Send the current record to a remote DWN.
|
|
186
|
+
*
|
|
187
|
+
* @param target - Optional DID of the target DWN. Defaults to the connected DID.
|
|
188
|
+
*/
|
|
189
|
+
public async send(target?: string): Promise<DwnResponseStatus> {
|
|
190
|
+
return this._record.send(target);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Returns a JSON representation of the Record instance.
|
|
195
|
+
*/
|
|
196
|
+
public toJSON(): RecordModel {
|
|
197
|
+
return this._record.toJSON();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns a string representation of the Record instance.
|
|
202
|
+
*/
|
|
203
|
+
public toString(): string {
|
|
204
|
+
return this._record.toString();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns a pagination cursor for the current record given a sort order.
|
|
209
|
+
*/
|
|
210
|
+
public async paginationCursor(sort: DwnDateSort): Promise<DwnPaginationCursor | undefined> {
|
|
211
|
+
return this._record.paginationCursor(sort);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// -------------------------------------------------------------------------
|
|
215
|
+
// Forwarded immutable property getters
|
|
216
|
+
// -------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
/** Record's ID. */
|
|
219
|
+
public get id(): string { return this._record.id; }
|
|
220
|
+
|
|
221
|
+
/** Record's context ID. */
|
|
222
|
+
public get contextId(): string | undefined { return this._record.contextId; }
|
|
223
|
+
|
|
224
|
+
/** Record's creation date. */
|
|
225
|
+
public get dateCreated(): string { return this._record.dateCreated; }
|
|
226
|
+
|
|
227
|
+
/** Record's parent ID. */
|
|
228
|
+
public get parentId(): string | undefined { return this._record.parentId; }
|
|
229
|
+
|
|
230
|
+
/** Record's protocol. */
|
|
231
|
+
public get protocol(): string | undefined { return this._record.protocol; }
|
|
232
|
+
|
|
233
|
+
/** Record's protocol path. */
|
|
234
|
+
public get protocolPath(): string | undefined { return this._record.protocolPath; }
|
|
235
|
+
|
|
236
|
+
/** Record's recipient. */
|
|
237
|
+
public get recipient(): string | undefined { return this._record.recipient; }
|
|
238
|
+
|
|
239
|
+
/** Record's schema. */
|
|
240
|
+
public get schema(): string | undefined { return this._record.schema; }
|
|
241
|
+
|
|
242
|
+
// -------------------------------------------------------------------------
|
|
243
|
+
// Forwarded mutable property getters
|
|
244
|
+
// -------------------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
/** Record's data format. */
|
|
247
|
+
public get dataFormat(): string | undefined { return this._record.dataFormat; }
|
|
248
|
+
|
|
249
|
+
/** Record's data CID. */
|
|
250
|
+
public get dataCid(): string | undefined { return this._record.dataCid; }
|
|
251
|
+
|
|
252
|
+
/** Record's data size. */
|
|
253
|
+
public get dataSize(): number | undefined { return this._record.dataSize; }
|
|
254
|
+
|
|
255
|
+
/** Record's published date. */
|
|
256
|
+
public get datePublished(): string | undefined { return this._record.datePublished; }
|
|
257
|
+
|
|
258
|
+
/** Record's published status. */
|
|
259
|
+
public get published(): boolean | undefined { return this._record.published; }
|
|
260
|
+
|
|
261
|
+
/** Tags of the record. */
|
|
262
|
+
public get tags(): DwnMessage[DwnInterface.RecordsWrite]['descriptor']['tags'] | undefined {
|
|
263
|
+
return this._record.tags;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// -------------------------------------------------------------------------
|
|
267
|
+
// Forwarded state-dependent property getters
|
|
268
|
+
// -------------------------------------------------------------------------
|
|
269
|
+
|
|
270
|
+
/** DID that is the logical author of the Record. */
|
|
271
|
+
public get author(): string { return this._record.author; }
|
|
272
|
+
|
|
273
|
+
/** DID that is the original creator of the Record. */
|
|
274
|
+
public get creator(): string { return this._record.creator; }
|
|
275
|
+
|
|
276
|
+
/** Record's message timestamp. */
|
|
277
|
+
public get timestamp(): string { return this._record.timestamp; }
|
|
278
|
+
|
|
279
|
+
/** Record's encryption details. */
|
|
280
|
+
public get encryption(): DwnMessage[DwnInterface.RecordsWrite]['encryption'] {
|
|
281
|
+
return this._record.encryption;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Record's authorization. */
|
|
285
|
+
public get authorization(): DwnMessage[DwnInterface.RecordsWrite | DwnInterface.RecordsDelete]['authorization'] {
|
|
286
|
+
return this._record.authorization;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** Record's attestation. */
|
|
290
|
+
public get attestation(): DwnMessage[DwnInterface.RecordsWrite]['attestation'] | undefined {
|
|
291
|
+
return this._record.attestation;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Role under which the author is writing the record. */
|
|
295
|
+
public get protocolRole(): string | undefined { return this._record.protocolRole; }
|
|
296
|
+
|
|
297
|
+
/** Record's deleted state. */
|
|
298
|
+
public get deleted(): boolean { return this._record.deleted; }
|
|
299
|
+
|
|
300
|
+
/** Record's initial write if the record has been updated. */
|
|
301
|
+
public get initialWrite(): DwnMessage[DwnInterface.RecordsWrite] | undefined {
|
|
302
|
+
return this._record.initialWrite;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** The raw DWN message backing this record. */
|
|
306
|
+
public get rawMessage(): DwnMessage[DwnInterface.RecordsWrite] | DwnMessage[DwnInterface.RecordsDelete] {
|
|
307
|
+
return this._record.rawMessage;
|
|
308
|
+
}
|
|
309
|
+
}
|