@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,179 @@
|
|
|
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
|
+
import type { Record } from './record.js';
|
|
25
|
+
import type { RecordData } from './record-data.js';
|
|
26
|
+
import type { DwnDateSort, DwnMessage, DwnPaginationCursor, DwnResponseStatus } from '@enbox/agent';
|
|
27
|
+
import type { RecordDeleteParams, RecordModel, RecordUpdateParams } from './record-types.js';
|
|
28
|
+
import type { DwnInterface } from '@enbox/agent';
|
|
29
|
+
/**
|
|
30
|
+
* A data accessor that preserves the record's type parameter `T` on
|
|
31
|
+
* the `json()` method.
|
|
32
|
+
*
|
|
33
|
+
* All other methods (`blob`, `bytes`, `text`, `stream`, `then`, `catch`)
|
|
34
|
+
* are forwarded unchanged from the underlying {@link RecordData}.
|
|
35
|
+
*/
|
|
36
|
+
export type TypedRecordData<T> = Omit<RecordData, 'json'> & {
|
|
37
|
+
/** Parse the data as JSON, returning the typed data shape `T`. */
|
|
38
|
+
json: () => Promise<T>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Update parameters for a {@link TypedRecord}.
|
|
42
|
+
*
|
|
43
|
+
* Extends the base `RecordUpdateParams` but narrows `data` from `unknown`
|
|
44
|
+
* to `Partial<T>`.
|
|
45
|
+
*/
|
|
46
|
+
export type TypedRecordUpdateParams<T> = Omit<RecordUpdateParams, 'data'> & {
|
|
47
|
+
/** The new data for the record. Type-checked against the schema map. */
|
|
48
|
+
data?: Partial<T>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Result of a {@link TypedRecord.update} operation.
|
|
52
|
+
*/
|
|
53
|
+
export type TypedRecordUpdateResult<T> = DwnResponseStatus & {
|
|
54
|
+
/** The updated record, carrying the same type parameter. */
|
|
55
|
+
record: TypedRecord<T>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Result of a {@link TypedRecord.delete} operation.
|
|
59
|
+
*/
|
|
60
|
+
export type TypedRecordDeleteResult<T> = DwnResponseStatus & {
|
|
61
|
+
/** The deleted record, carrying the same type parameter. */
|
|
62
|
+
record: TypedRecord<T>;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* A type-safe wrapper around {@link Record} that preserves the data type `T`.
|
|
66
|
+
*
|
|
67
|
+
* Obtain instances through `TypedWeb5.records.write()`, `.query()`, `.read()`,
|
|
68
|
+
* or `.subscribe()` — never construct directly.
|
|
69
|
+
*/
|
|
70
|
+
export declare class TypedRecord<T> {
|
|
71
|
+
/** The underlying untyped Record instance. */
|
|
72
|
+
private _record;
|
|
73
|
+
constructor(record: Record);
|
|
74
|
+
/** Access the underlying untyped {@link Record} for advanced use cases. */
|
|
75
|
+
get rawRecord(): Record;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the data of the current record with type-safe accessors.
|
|
78
|
+
*
|
|
79
|
+
* The `json()` method returns `Promise<T>` — no manual generic needed.
|
|
80
|
+
*
|
|
81
|
+
* @throws `Error` if the record has been deleted.
|
|
82
|
+
*/
|
|
83
|
+
get data(): TypedRecordData<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Update the current record on the DWN.
|
|
86
|
+
*
|
|
87
|
+
* @param params - Parameters including the typed `data` payload.
|
|
88
|
+
* @returns The status and an updated {@link TypedRecord}.
|
|
89
|
+
* @throws `Error` if the record has been deleted.
|
|
90
|
+
*/
|
|
91
|
+
update(params: TypedRecordUpdateParams<T>): Promise<TypedRecordUpdateResult<T>>;
|
|
92
|
+
/**
|
|
93
|
+
* Delete the current record on the DWN.
|
|
94
|
+
*
|
|
95
|
+
* @param params - Delete parameters.
|
|
96
|
+
* @returns The status and a {@link TypedRecord} reflecting the deleted state.
|
|
97
|
+
*/
|
|
98
|
+
delete(params?: RecordDeleteParams): Promise<TypedRecordDeleteResult<T>>;
|
|
99
|
+
/**
|
|
100
|
+
* Stores the current record state to the owner's DWN.
|
|
101
|
+
*
|
|
102
|
+
* @param importRecord - If true, sign as owner before storing. Defaults to false.
|
|
103
|
+
*/
|
|
104
|
+
store(importRecord?: boolean): Promise<DwnResponseStatus>;
|
|
105
|
+
/**
|
|
106
|
+
* Signs and optionally stores the record to the owner's DWN.
|
|
107
|
+
* Useful when importing a record signed by someone else.
|
|
108
|
+
*
|
|
109
|
+
* @param store - If true, store after signing. Defaults to true.
|
|
110
|
+
*/
|
|
111
|
+
import(store?: boolean): Promise<DwnResponseStatus>;
|
|
112
|
+
/**
|
|
113
|
+
* Send the current record to a remote DWN.
|
|
114
|
+
*
|
|
115
|
+
* @param target - Optional DID of the target DWN. Defaults to the connected DID.
|
|
116
|
+
*/
|
|
117
|
+
send(target?: string): Promise<DwnResponseStatus>;
|
|
118
|
+
/**
|
|
119
|
+
* Returns a JSON representation of the Record instance.
|
|
120
|
+
*/
|
|
121
|
+
toJSON(): RecordModel;
|
|
122
|
+
/**
|
|
123
|
+
* Returns a string representation of the Record instance.
|
|
124
|
+
*/
|
|
125
|
+
toString(): string;
|
|
126
|
+
/**
|
|
127
|
+
* Returns a pagination cursor for the current record given a sort order.
|
|
128
|
+
*/
|
|
129
|
+
paginationCursor(sort: DwnDateSort): Promise<DwnPaginationCursor | undefined>;
|
|
130
|
+
/** Record's ID. */
|
|
131
|
+
get id(): string;
|
|
132
|
+
/** Record's context ID. */
|
|
133
|
+
get contextId(): string | undefined;
|
|
134
|
+
/** Record's creation date. */
|
|
135
|
+
get dateCreated(): string;
|
|
136
|
+
/** Record's parent ID. */
|
|
137
|
+
get parentId(): string | undefined;
|
|
138
|
+
/** Record's protocol. */
|
|
139
|
+
get protocol(): string | undefined;
|
|
140
|
+
/** Record's protocol path. */
|
|
141
|
+
get protocolPath(): string | undefined;
|
|
142
|
+
/** Record's recipient. */
|
|
143
|
+
get recipient(): string | undefined;
|
|
144
|
+
/** Record's schema. */
|
|
145
|
+
get schema(): string | undefined;
|
|
146
|
+
/** Record's data format. */
|
|
147
|
+
get dataFormat(): string | undefined;
|
|
148
|
+
/** Record's data CID. */
|
|
149
|
+
get dataCid(): string | undefined;
|
|
150
|
+
/** Record's data size. */
|
|
151
|
+
get dataSize(): number | undefined;
|
|
152
|
+
/** Record's published date. */
|
|
153
|
+
get datePublished(): string | undefined;
|
|
154
|
+
/** Record's published status. */
|
|
155
|
+
get published(): boolean | undefined;
|
|
156
|
+
/** Tags of the record. */
|
|
157
|
+
get tags(): DwnMessage[DwnInterface.RecordsWrite]['descriptor']['tags'] | undefined;
|
|
158
|
+
/** DID that is the logical author of the Record. */
|
|
159
|
+
get author(): string;
|
|
160
|
+
/** DID that is the original creator of the Record. */
|
|
161
|
+
get creator(): string;
|
|
162
|
+
/** Record's message timestamp. */
|
|
163
|
+
get timestamp(): string;
|
|
164
|
+
/** Record's encryption details. */
|
|
165
|
+
get encryption(): DwnMessage[DwnInterface.RecordsWrite]['encryption'];
|
|
166
|
+
/** Record's authorization. */
|
|
167
|
+
get authorization(): DwnMessage[DwnInterface.RecordsWrite | DwnInterface.RecordsDelete]['authorization'];
|
|
168
|
+
/** Record's attestation. */
|
|
169
|
+
get attestation(): DwnMessage[DwnInterface.RecordsWrite]['attestation'] | undefined;
|
|
170
|
+
/** Role under which the author is writing the record. */
|
|
171
|
+
get protocolRole(): string | undefined;
|
|
172
|
+
/** Record's deleted state. */
|
|
173
|
+
get deleted(): boolean;
|
|
174
|
+
/** Record's initial write if the record has been updated. */
|
|
175
|
+
get initialWrite(): DwnMessage[DwnInterface.RecordsWrite] | undefined;
|
|
176
|
+
/** The raw DWN message backing this record. */
|
|
177
|
+
get rawMessage(): DwnMessage[DwnInterface.RecordsWrite] | DwnMessage[DwnInterface.RecordsDelete];
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=typed-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-record.d.ts","sourceRoot":"","sources":["../../src/typed-record.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AU,CAAC,YAAY,CAAC,YAAY,CAAC,GAAG,UAAU,CAAC,YAAY,CAAC,aAAa,CAAC,CAEtG;CACF"}
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
* and schema into every operation, and provides compile-time path
|
|
7
7
|
* autocompletion plus typed data payloads via the schema map.
|
|
8
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
|
+
*
|
|
9
13
|
* @example
|
|
10
14
|
* ```ts
|
|
11
15
|
* const social = web5.using(SocialProtocol);
|
|
@@ -13,33 +17,39 @@
|
|
|
13
17
|
* // Install the protocol
|
|
14
18
|
* await social.configure();
|
|
15
19
|
*
|
|
16
|
-
* //
|
|
17
|
-
* const { record } = await social.records.
|
|
20
|
+
* // Create — path and data type are checked at compile time
|
|
21
|
+
* const { record } = await social.records.create('thread', {
|
|
18
22
|
* data: { title: 'Hello World', body: '...' },
|
|
19
23
|
* });
|
|
24
|
+
* // record is TypedRecord<ThreadData>
|
|
25
|
+
*
|
|
26
|
+
* const data = await record.data.json(); // ThreadData — no cast needed
|
|
20
27
|
*
|
|
21
28
|
* // Query — protocol and protocolPath are auto-injected
|
|
22
29
|
* const { records } = await social.records.query('thread');
|
|
30
|
+
* // records is TypedRecord<ThreadData>[]
|
|
23
31
|
*
|
|
24
|
-
* // Subscribe — real-time changes via
|
|
32
|
+
* // Subscribe — real-time changes via TypedLiveQuery
|
|
25
33
|
* const { liveQuery } = await social.records.subscribe('thread/reply');
|
|
26
|
-
* liveQuery.on('create', (record) => {
|
|
34
|
+
* liveQuery.on('create', (record) => {
|
|
35
|
+
* // record is TypedRecord<ReplyData>
|
|
36
|
+
* });
|
|
27
37
|
* ```
|
|
28
38
|
*/
|
|
29
39
|
import type { DwnApi } from './dwn-api.js';
|
|
30
|
-
import type { LiveQuery } from './live-query.js';
|
|
31
40
|
import type { Protocol } from './protocol.js';
|
|
32
|
-
import type { Record } from './record.js';
|
|
33
41
|
import type { DateSort, ProtocolDefinition, ProtocolType, RecordsFilter } from '@enbox/dwn-sdk-js';
|
|
34
42
|
import type { DwnPaginationCursor, DwnResponseStatus } from '@enbox/agent';
|
|
35
43
|
import type { ProtocolPaths, SchemaMap, TypedProtocol, TypeNameAtPath } from './protocol-types.js';
|
|
44
|
+
import { TypedLiveQuery } from './typed-live-query.js';
|
|
45
|
+
import { TypedRecord } from './typed-record.js';
|
|
36
46
|
/**
|
|
37
47
|
* Resolves the TypeScript data type for a given protocol path.
|
|
38
48
|
*
|
|
39
49
|
* If the schema map contains a mapping for the type name at the given path,
|
|
40
50
|
* that type is returned. Otherwise falls back to `unknown`.
|
|
41
51
|
*/
|
|
42
|
-
type DataForPath<_D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = TypeNameAtPath<Path> extends keyof M ? M[TypeNameAtPath<Path>] : unknown;
|
|
52
|
+
export type DataForPath<_D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = TypeNameAtPath<Path> extends keyof M ? M[TypeNameAtPath<Path>] : unknown;
|
|
43
53
|
/**
|
|
44
54
|
* Resolves the `ProtocolType` entry for a given protocol path.
|
|
45
55
|
*/
|
|
@@ -50,8 +60,8 @@ type ProtocolTypeForPath<D extends ProtocolDefinition, Path extends string> = Ty
|
|
|
50
60
|
type DataFormatForPath<D extends ProtocolDefinition, Path extends string> = ProtocolTypeForPath<D, Path> extends {
|
|
51
61
|
dataFormats: infer F;
|
|
52
62
|
} ? F extends readonly string[] ? F[number] : string : string;
|
|
53
|
-
/** Options for {@link TypedWeb5} `records.
|
|
54
|
-
export type
|
|
63
|
+
/** Options for {@link TypedWeb5} `records.create()`. */
|
|
64
|
+
export type TypedCreateRequest<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = {
|
|
55
65
|
/** The data payload. Type-checked against the schema map. */
|
|
56
66
|
data: DataForPath<D, M, Path>;
|
|
57
67
|
parentContextId?: string;
|
|
@@ -66,9 +76,9 @@ export type TypedWriteRequest<D extends ProtocolDefinition, M extends SchemaMap,
|
|
|
66
76
|
/** Whether to auto-encrypt (follows protocol definition if omitted). */
|
|
67
77
|
encryption?: boolean;
|
|
68
78
|
};
|
|
69
|
-
/** Response from {@link TypedWeb5} `records.
|
|
70
|
-
export type
|
|
71
|
-
record:
|
|
79
|
+
/** Response from {@link TypedWeb5} `records.create()`. */
|
|
80
|
+
export type TypedCreateResponse<T = unknown> = DwnResponseStatus & {
|
|
81
|
+
record: TypedRecord<T>;
|
|
72
82
|
};
|
|
73
83
|
/** Filter options for {@link TypedWeb5} `records.query()`. */
|
|
74
84
|
export type TypedQueryFilter = Omit<RecordsFilter, 'protocol' | 'protocolPath' | 'schema'> & {
|
|
@@ -90,8 +100,8 @@ export type TypedQueryRequest = {
|
|
|
90
100
|
encryption?: boolean;
|
|
91
101
|
};
|
|
92
102
|
/** Response from {@link TypedWeb5} `records.query()`. */
|
|
93
|
-
export type TypedQueryResponse = DwnResponseStatus & {
|
|
94
|
-
records:
|
|
103
|
+
export type TypedQueryResponse<T = unknown> = DwnResponseStatus & {
|
|
104
|
+
records: TypedRecord<T>[];
|
|
95
105
|
cursor?: DwnPaginationCursor;
|
|
96
106
|
};
|
|
97
107
|
/** Options for {@link TypedWeb5} `records.read()`. */
|
|
@@ -104,8 +114,8 @@ export type TypedReadRequest = {
|
|
|
104
114
|
encryption?: boolean;
|
|
105
115
|
};
|
|
106
116
|
/** Response from {@link TypedWeb5} `records.read()`. */
|
|
107
|
-
export type TypedReadResponse = DwnResponseStatus & {
|
|
108
|
-
record:
|
|
117
|
+
export type TypedReadResponse<T = unknown> = DwnResponseStatus & {
|
|
118
|
+
record: TypedRecord<T>;
|
|
109
119
|
};
|
|
110
120
|
/** Options for {@link TypedWeb5} `records.delete()`. */
|
|
111
121
|
export type TypedDeleteRequest = {
|
|
@@ -123,14 +133,18 @@ export type TypedSubscribeRequest = {
|
|
|
123
133
|
protocolRole?: string;
|
|
124
134
|
};
|
|
125
135
|
/** Response from {@link TypedWeb5} `records.subscribe()`. */
|
|
126
|
-
export type TypedSubscribeResponse = DwnResponseStatus & {
|
|
127
|
-
/** The live query instance, or `undefined` if the request failed. */
|
|
128
|
-
liveQuery?:
|
|
136
|
+
export type TypedSubscribeResponse<T = unknown> = DwnResponseStatus & {
|
|
137
|
+
/** The typed live query instance, or `undefined` if the request failed. */
|
|
138
|
+
liveQuery?: TypedLiveQuery<T>;
|
|
129
139
|
};
|
|
130
140
|
/**
|
|
131
141
|
* A protocol-scoped API that auto-injects `protocol`, `protocolPath`, and
|
|
132
142
|
* `schema` into every DWN operation.
|
|
133
143
|
*
|
|
144
|
+
* All record-returning methods wrap results in {@link TypedRecord} so that
|
|
145
|
+
* the data type `T` (resolved from the schema map) flows end-to-end — from
|
|
146
|
+
* write through read, query, update, and subscribe — without manual casts.
|
|
147
|
+
*
|
|
134
148
|
* Obtain an instance via `web5.using(typedProtocol)`.
|
|
135
149
|
*
|
|
136
150
|
* @example
|
|
@@ -139,18 +153,25 @@ export type TypedSubscribeResponse = DwnResponseStatus & {
|
|
|
139
153
|
*
|
|
140
154
|
* await social.configure();
|
|
141
155
|
*
|
|
142
|
-
* const { record } = await social.records.
|
|
156
|
+
* const { record } = await social.records.create('friend', {
|
|
143
157
|
* data: { did: 'did:example:alice', alias: 'Alice' },
|
|
144
158
|
* });
|
|
159
|
+
* const data = await record.data.json(); // FriendData — no cast
|
|
145
160
|
*
|
|
146
161
|
* const { records } = await social.records.query('friend', {
|
|
147
162
|
* filter: { tags: { did: 'did:example:alice' } },
|
|
148
163
|
* });
|
|
164
|
+
* for (const r of records) {
|
|
165
|
+
* const d = await r.data.json(); // FriendData
|
|
166
|
+
* }
|
|
149
167
|
* ```
|
|
150
168
|
*/
|
|
151
169
|
export declare class TypedWeb5<D extends ProtocolDefinition = ProtocolDefinition, M extends SchemaMap = SchemaMap> {
|
|
152
170
|
private _dwn;
|
|
153
171
|
private _definition;
|
|
172
|
+
private _configured;
|
|
173
|
+
private _validPaths;
|
|
174
|
+
private _records?;
|
|
154
175
|
constructor(dwn: DwnApi, protocol: TypedProtocol<D, M>);
|
|
155
176
|
/** The protocol URI. */
|
|
156
177
|
get protocol(): string;
|
|
@@ -171,19 +192,29 @@ export declare class TypedWeb5<D extends ProtocolDefinition = ProtocolDefinition
|
|
|
171
192
|
}): Promise<DwnResponseStatus & {
|
|
172
193
|
protocol?: Protocol;
|
|
173
194
|
}>;
|
|
195
|
+
/** Whether the protocol has been configured (installed) on the local DWN. */
|
|
196
|
+
get isConfigured(): boolean;
|
|
197
|
+
/**
|
|
198
|
+
* Validates that the protocol has been configured and that the path is
|
|
199
|
+
* recognized. Throws a descriptive error if either check fails.
|
|
200
|
+
*/
|
|
201
|
+
private _assertReady;
|
|
174
202
|
/**
|
|
175
203
|
* Protocol-scoped record operations.
|
|
176
204
|
*
|
|
177
205
|
* Every method auto-injects the protocol URI, protocolPath, and schema
|
|
178
206
|
* from the protocol definition. Path parameters provide compile-time
|
|
179
207
|
* autocompletion via `ProtocolPaths<D>`.
|
|
208
|
+
*
|
|
209
|
+
* All methods return {@link TypedRecord} or {@link TypedLiveQuery} instances
|
|
210
|
+
* that carry the resolved data type from the schema map.
|
|
180
211
|
*/
|
|
181
212
|
get records(): {
|
|
182
|
-
|
|
183
|
-
query: <Path extends ProtocolPaths<D> & string>(path: Path, request?: TypedQueryRequest) => Promise<TypedQueryResponse
|
|
184
|
-
read: <Path extends ProtocolPaths<D> & string>(path: Path, request: TypedReadRequest) => Promise<TypedReadResponse
|
|
213
|
+
create: <Path extends ProtocolPaths<D> & string>(path: Path, request: TypedCreateRequest<D, M, Path>) => Promise<TypedCreateResponse<DataForPath<D, M, Path>>>;
|
|
214
|
+
query: <Path extends ProtocolPaths<D> & string>(path: Path, request?: TypedQueryRequest) => Promise<TypedQueryResponse<DataForPath<D, M, Path>>>;
|
|
215
|
+
read: <Path extends ProtocolPaths<D> & string>(path: Path, request: TypedReadRequest) => Promise<TypedReadResponse<DataForPath<D, M, Path>>>;
|
|
185
216
|
delete: <Path extends ProtocolPaths<D> & string>(path: Path, request: TypedDeleteRequest) => Promise<DwnResponseStatus>;
|
|
186
|
-
subscribe: <Path extends ProtocolPaths<D> & string>(path: Path, request?: TypedSubscribeRequest) => Promise<TypedSubscribeResponse
|
|
217
|
+
subscribe: <Path extends ProtocolPaths<D> & string>(path: Path, request?: TypedSubscribeRequest) => Promise<TypedSubscribeResponse<DataForPath<D, M, Path>>>;
|
|
187
218
|
};
|
|
188
219
|
}
|
|
189
220
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typed-web5.d.ts","sourceRoot":"","sources":["../../src/typed-web5.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"typed-web5.d.ts","sourceRoot":"","sources":["../../src/typed-web5.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEnG,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,CACrB,EAAE,SAAS,kBAAkB,EAC7B,CAAC,SAAS,SAAS,EACnB,IAAI,SAAS,MAAM,IACjB,cAAc,CAAC,IAAI,CAAC,SAAS,MAAM,CA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MAAM,EAC7C,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,kBAAkB,KACxB,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAEhC,SAAS,EAAE,CAAC,IAAI,SAAS,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,qBAAqB,KAC5B,OAAO,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;KAC7D,CAyKF;CACF"}
|
package/dist/types/web5.d.ts
CHANGED
|
@@ -67,6 +67,35 @@ export type Web5AnonymousApi = {
|
|
|
67
67
|
/** A read-only DWN API for querying public data on remote DWNs. */
|
|
68
68
|
dwn: DwnReaderApi;
|
|
69
69
|
};
|
|
70
|
+
/** Parameters passed to the onProviderAuthRequired callback. */
|
|
71
|
+
export type ProviderAuthParams = {
|
|
72
|
+
/** Full authorize URL to open in a browser (query params already appended). */
|
|
73
|
+
authorizeUrl: string;
|
|
74
|
+
/** The DWN endpoint URL this auth is for (informational). */
|
|
75
|
+
dwnEndpoint: string;
|
|
76
|
+
/** CSRF nonce — the provider will return this unchanged in the redirect. */
|
|
77
|
+
state: string;
|
|
78
|
+
};
|
|
79
|
+
/** Result returned by the app after the user completes provider auth. */
|
|
80
|
+
export type ProviderAuthResult = {
|
|
81
|
+
/** Authorization code from the provider's redirect. */
|
|
82
|
+
code: string;
|
|
83
|
+
/** Must match the state from ProviderAuthParams (CSRF validation). */
|
|
84
|
+
state: string;
|
|
85
|
+
};
|
|
86
|
+
/** Persisted registration token data for a DWN endpoint. */
|
|
87
|
+
export type RegistrationTokenData = {
|
|
88
|
+
/** Opaque registration token for POST /registration. */
|
|
89
|
+
registrationToken: string;
|
|
90
|
+
/** Refresh token for obtaining new registration tokens. */
|
|
91
|
+
refreshToken?: string;
|
|
92
|
+
/** Unix timestamp (ms) when the token expires. Undefined = never expires. */
|
|
93
|
+
expiresAt?: number;
|
|
94
|
+
/** Provider's token exchange URL (needed for code exchange). */
|
|
95
|
+
tokenUrl: string;
|
|
96
|
+
/** Provider's refresh URL (needed for token refresh). */
|
|
97
|
+
refreshUrl?: string;
|
|
98
|
+
};
|
|
70
99
|
/** Optional overrides that can be provided when calling {@link Web5.connect}. */
|
|
71
100
|
export type Web5ConnectOptions = {
|
|
72
101
|
/**
|
|
@@ -152,10 +181,26 @@ export type Web5ConnectOptions = {
|
|
|
152
181
|
* If registration is successful, the `onSuccess` callback will be called.
|
|
153
182
|
*/
|
|
154
183
|
registration?: {
|
|
155
|
-
/** Called when all of the DWN registrations are successful */
|
|
184
|
+
/** Called when all of the DWN registrations are successful. */
|
|
156
185
|
onSuccess: () => void;
|
|
157
|
-
/** Called when any of the DWN registrations fail */
|
|
186
|
+
/** Called when any of the DWN registrations fail. */
|
|
158
187
|
onFailure: (error: any) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Called when a DWN endpoint requires provider auth (`'provider-auth-v0'`).
|
|
190
|
+
* The app is responsible for opening the authorizeUrl in a browser,
|
|
191
|
+
* capturing the redirect back, and returning the auth code.
|
|
192
|
+
* If not provided, provider-auth endpoints fall back to PoW registration.
|
|
193
|
+
*/
|
|
194
|
+
onProviderAuthRequired?: (params: ProviderAuthParams) => Promise<ProviderAuthResult>;
|
|
195
|
+
/**
|
|
196
|
+
* Pre-existing registration tokens from a previous session, keyed by DWN endpoint URL.
|
|
197
|
+
* If a valid (non-expired) token exists for an endpoint, it is used directly.
|
|
198
|
+
*/
|
|
199
|
+
registrationTokens?: Record<string, RegistrationTokenData>;
|
|
200
|
+
/**
|
|
201
|
+
* Called when new registration tokens are obtained so the app can persist them.
|
|
202
|
+
*/
|
|
203
|
+
onRegistrationTokens?: (tokens: Record<string, RegistrationTokenData>) => void;
|
|
159
204
|
};
|
|
160
205
|
};
|
|
161
206
|
/**
|
package/dist/types/web5.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web5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AclE;;;;;;;;;;OAUG;WACU,OAAO,CAAC,EACnB,KAAK,EACL,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,GACrB,GAAE,kBAAuB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkRvD;;;OAGG;mBACkB,eAAe;IAuBpC;;;;OAIG;WACU,sBAAsB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE;QAClE,MAAM,EAAE,iCAAiC,EAAE,CAAC;QAC5C,KAAK,EAAE,SAAS,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqBtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enbox/api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "SDK for accessing the features and capabilities of Web5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -81,14 +81,15 @@
|
|
|
81
81
|
"bun": ">=1.0.0"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@enbox/agent": "0.1.
|
|
85
|
-
"@enbox/common": "0.0.
|
|
86
|
-
"@enbox/dwn-clients": "0.0.
|
|
84
|
+
"@enbox/agent": "0.1.9",
|
|
85
|
+
"@enbox/common": "0.0.4",
|
|
86
|
+
"@enbox/dwn-clients": "0.0.6"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
|
-
"@enbox/crypto": "0.0.
|
|
90
|
-
"@enbox/dids": "0.0.
|
|
91
|
-
"@enbox/dwn-sdk-js": "0.0.
|
|
89
|
+
"@enbox/crypto": "0.0.5",
|
|
90
|
+
"@enbox/dids": "0.0.6",
|
|
91
|
+
"@enbox/dwn-sdk-js": "0.0.8",
|
|
92
|
+
"@enbox/protocols": "0.2.6",
|
|
92
93
|
"@types/node": "20.14.8",
|
|
93
94
|
"@types/sinon": "17.0.3",
|
|
94
95
|
"@typescript-eslint/eslint-plugin": "8.32.1",
|
package/src/dwn-api.ts
CHANGED
|
@@ -17,6 +17,8 @@ import type {
|
|
|
17
17
|
ProcessDwnRequest,
|
|
18
18
|
Web5Agent } from '@enbox/agent';
|
|
19
19
|
|
|
20
|
+
import type { DwnSubscriptionMessage } from '@enbox/dwn-clients';
|
|
21
|
+
|
|
20
22
|
import {
|
|
21
23
|
AgentPermissionsApi,
|
|
22
24
|
} from '@enbox/agent';
|
|
@@ -285,7 +287,7 @@ export class DwnApi {
|
|
|
285
287
|
message,
|
|
286
288
|
};
|
|
287
289
|
|
|
288
|
-
return
|
|
290
|
+
return PermissionRequest.parse(requestParams);
|
|
289
291
|
},
|
|
290
292
|
/**
|
|
291
293
|
* Grant permission for a specific scope to a grantee DID.
|
|
@@ -302,7 +304,7 @@ export class DwnApi {
|
|
|
302
304
|
message,
|
|
303
305
|
};
|
|
304
306
|
|
|
305
|
-
return
|
|
307
|
+
return PermissionGrant.parse(grantParams);
|
|
306
308
|
},
|
|
307
309
|
/**
|
|
308
310
|
* Query permission requests. You can filter by protocol and specify if you want to query a remote DWN.
|
|
@@ -323,7 +325,7 @@ export class DwnApi {
|
|
|
323
325
|
agent : this.agent,
|
|
324
326
|
message : permission.message,
|
|
325
327
|
};
|
|
326
|
-
requests.push(
|
|
328
|
+
requests.push(PermissionRequest.parse(requestParams));
|
|
327
329
|
}
|
|
328
330
|
|
|
329
331
|
return requests;
|
|
@@ -351,7 +353,7 @@ export class DwnApi {
|
|
|
351
353
|
message : permission.message,
|
|
352
354
|
};
|
|
353
355
|
|
|
354
|
-
grants.push(
|
|
356
|
+
grants.push(PermissionGrant.parse(grantParams));
|
|
355
357
|
}
|
|
356
358
|
|
|
357
359
|
return grants;
|
|
@@ -736,19 +738,34 @@ export class DwnApi {
|
|
|
736
738
|
const remoteOrigin = from;
|
|
737
739
|
const protocolRole = messageParams.protocolRole;
|
|
738
740
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
741
|
+
const subscriptionHandler = (msg: DwnSubscriptionMessage): void => {
|
|
742
|
+
if (msg.type === 'eose') {
|
|
743
|
+
liveQuery?.handleLifecycleEvent('eose');
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
if (msg.type === 'disconnected') {
|
|
748
|
+
liveQuery?.handleLifecycleEvent('disconnected');
|
|
749
|
+
return;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (msg.type === 'reconnected') {
|
|
753
|
+
liveQuery?.handleLifecycleEvent('reconnected');
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
if (msg.type === 'reconnecting') {
|
|
758
|
+
liveQuery?.handleLifecycleEvent('reconnecting', { attempt: msg.attempt });
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
743
761
|
|
|
744
|
-
|
|
745
|
-
const { message, initialWrite } = event;
|
|
762
|
+
const { message, initialWrite } = msg.event;
|
|
746
763
|
const record = new Record(this.agent, {
|
|
747
|
-
...message,
|
|
748
|
-
author : getRecordAuthor(message),
|
|
764
|
+
...message as DwnMessage[DwnInterface.RecordsWrite],
|
|
765
|
+
author : getRecordAuthor(message as DwnMessage[DwnInterface.RecordsWrite]),
|
|
749
766
|
connectedDid : this.connectedDid,
|
|
750
767
|
remoteOrigin,
|
|
751
|
-
initialWrite,
|
|
768
|
+
initialWrite : initialWrite as DwnMessage[DwnInterface.RecordsWrite] | undefined,
|
|
752
769
|
protocolRole,
|
|
753
770
|
delegateDid : this.delegateDid,
|
|
754
771
|
}, this.permissionsApi);
|
package/src/index.ts
CHANGED
|
@@ -32,6 +32,12 @@ export * from './protocol.js';
|
|
|
32
32
|
export * from './protocol-types.js';
|
|
33
33
|
export * from './read-only-record.js';
|
|
34
34
|
export * from './record.js';
|
|
35
|
+
export * from './record-data.js';
|
|
36
|
+
export * from './record-types.js';
|
|
37
|
+
export * from './repository.js';
|
|
38
|
+
export * from './repository-types.js';
|
|
39
|
+
export * from './typed-live-query.js';
|
|
40
|
+
export * from './typed-record.js';
|
|
35
41
|
export * from './typed-web5.js';
|
|
36
42
|
export * from './vc-api.js';
|
|
37
43
|
export * from './web5.js';
|