@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.
Files changed (73) hide show
  1. package/README.md +235 -35
  2. package/dist/browser.mjs +13 -13
  3. package/dist/browser.mjs.map +4 -4
  4. package/dist/esm/dwn-api.js +24 -10
  5. package/dist/esm/dwn-api.js.map +1 -1
  6. package/dist/esm/index.js +6 -0
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/esm/live-query.js +34 -5
  9. package/dist/esm/live-query.js.map +1 -1
  10. package/dist/esm/permission-grant.js +3 -6
  11. package/dist/esm/permission-grant.js.map +1 -1
  12. package/dist/esm/permission-request.js +4 -7
  13. package/dist/esm/permission-request.js.map +1 -1
  14. package/dist/esm/record-data.js +131 -0
  15. package/dist/esm/record-data.js.map +1 -0
  16. package/dist/esm/record-types.js +9 -0
  17. package/dist/esm/record-types.js.map +1 -0
  18. package/dist/esm/record.js +58 -184
  19. package/dist/esm/record.js.map +1 -1
  20. package/dist/esm/repository-types.js +13 -0
  21. package/dist/esm/repository-types.js.map +1 -0
  22. package/dist/esm/repository.js +347 -0
  23. package/dist/esm/repository.js.map +1 -0
  24. package/dist/esm/typed-live-query.js +101 -0
  25. package/dist/esm/typed-live-query.js.map +1 -0
  26. package/dist/esm/typed-record.js +227 -0
  27. package/dist/esm/typed-record.js.map +1 -0
  28. package/dist/esm/typed-web5.js +134 -23
  29. package/dist/esm/typed-web5.js.map +1 -1
  30. package/dist/esm/web5.js +78 -20
  31. package/dist/esm/web5.js.map +1 -1
  32. package/dist/types/dwn-api.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +6 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/live-query.d.ts +43 -4
  36. package/dist/types/live-query.d.ts.map +1 -1
  37. package/dist/types/permission-grant.d.ts +1 -1
  38. package/dist/types/permission-grant.d.ts.map +1 -1
  39. package/dist/types/permission-request.d.ts +1 -1
  40. package/dist/types/permission-request.d.ts.map +1 -1
  41. package/dist/types/record-data.d.ts +49 -0
  42. package/dist/types/record-data.d.ts.map +1 -0
  43. package/dist/types/record-types.d.ts +145 -0
  44. package/dist/types/record-types.d.ts.map +1 -0
  45. package/dist/types/record.d.ts +13 -144
  46. package/dist/types/record.d.ts.map +1 -1
  47. package/dist/types/repository-types.d.ts +137 -0
  48. package/dist/types/repository-types.d.ts.map +1 -0
  49. package/dist/types/repository.d.ts +59 -0
  50. package/dist/types/repository.d.ts.map +1 -0
  51. package/dist/types/typed-live-query.d.ts +86 -0
  52. package/dist/types/typed-live-query.d.ts.map +1 -0
  53. package/dist/types/typed-record.d.ts +179 -0
  54. package/dist/types/typed-record.d.ts.map +1 -0
  55. package/dist/types/typed-web5.d.ts +55 -24
  56. package/dist/types/typed-web5.d.ts.map +1 -1
  57. package/dist/types/web5.d.ts +47 -2
  58. package/dist/types/web5.d.ts.map +1 -1
  59. package/package.json +8 -7
  60. package/src/dwn-api.ts +30 -13
  61. package/src/index.ts +6 -0
  62. package/src/live-query.ts +71 -7
  63. package/src/permission-grant.ts +2 -3
  64. package/src/permission-request.ts +3 -4
  65. package/src/record-data.ts +155 -0
  66. package/src/record-types.ts +188 -0
  67. package/src/record.ts +86 -389
  68. package/src/repository-types.ts +249 -0
  69. package/src/repository.ts +391 -0
  70. package/src/typed-live-query.ts +156 -0
  71. package/src/typed-record.ts +309 -0
  72. package/src/typed-web5.ts +202 -49
  73. package/src/web5.ts +150 -23
@@ -3,142 +3,11 @@
3
3
  * https://github.com/enboxorg/enbox/pull/507
4
4
  */
5
5
  import type { DwnDateSort, DwnMessage, DwnMessageDescriptor, DwnPaginationCursor, DwnResponseStatus, PermissionsApi, Web5Agent } from '@enbox/agent';
6
+ import type { RecordDeleteParams, RecordModel, RecordOptions, RecordUpdateParams } from './record-types.js';
6
7
  import { DwnInterface } from '@enbox/agent';
7
- /**
8
- * Represents Immutable Record properties that cannot be changed after the record is created.
9
- *
10
- * @beta
11
- * */
12
- export type ImmutableRecordProperties = Pick<DwnMessageDescriptor[DwnInterface.RecordsWrite], 'dateCreated' | 'parentId' | 'protocol' | 'protocolPath' | 'recipient' | 'schema'>;
13
- /**
14
- * Represents Optional Record properties that depend on the Record's current state.
15
- *
16
- * @beta
17
- */
18
- export type OptionalRecordProperties = Pick<DwnMessage[DwnInterface.RecordsWrite], 'authorization' | 'attestation' | 'encryption' | 'contextId'> & Pick<DwnMessageDescriptor[DwnInterface.RecordsWrite], 'dataFormat' | 'dataCid' | 'dataSize' | 'datePublished' | 'published' | 'tags'>;
19
- /**
20
- * Represents the structured data model of a record, encapsulating the essential fields that define
21
- * the record's metadata and payload within a Decentralized Web Node (DWN).
22
- *
23
- * @beta
24
- */
25
- export type RecordModel = ImmutableRecordProperties & OptionalRecordProperties & {
26
- /** The logical author of the record. */
27
- author: string;
28
- /** The unique identifier of the record. */
29
- recordId?: string;
30
- /** The message timestamp (time of creation, most recent update, or deletion). */
31
- timestamp?: string;
32
- /** The protocol role under which this record is written. */
33
- protocolRole?: RecordOptions['protocolRole'];
34
- };
35
- /**
36
- * Options for configuring a {@link Record} instance, extending the base `RecordsWriteMessage` with
37
- * additional properties.
38
- *
39
- * This type combines the standard fields required for writing DWN records with additional metadata
40
- * and configuration options used specifically in the {@link Record} class.
41
- *
42
- * @beta
43
- */
44
- export type RecordOptions = DwnMessage[DwnInterface.RecordsWrite | DwnInterface.RecordsDelete] & {
45
- /** The DID that signed the record. */
46
- author: string;
47
- /** The attestation signature(s) for the record. */
48
- attestation?: DwnMessage[DwnInterface.RecordsWrite]['attestation'];
49
- /** The encryption information for the record. */
50
- encryption?: DwnMessage[DwnInterface.RecordsWrite]['encryption'];
51
- /** The contextId associated with the record. */
52
- contextId?: string;
53
- /** The unique identifier of the record */
54
- recordId?: string;
55
- /** The DID of the DWN tenant under which record operations are being performed. */
56
- connectedDid: string;
57
- /** The optional DID that will sign the records on behalf of the connectedDid */
58
- delegateDid?: string;
59
- /** The data of the record, either as a Base64 URL encoded string or a Blob. */
60
- encodedData?: string | Blob;
61
- /**
62
- * A stream of data, conforming to the Web `ReadableStream` interface, providing a mechanism
63
- * to read the record's data sequentially. This is particularly useful for handling large
64
- * datasets that should not be loaded entirely in memory, allowing for efficient, chunked
65
- * processing of the record's data.
66
- *
67
- * The DWN SDK now returns Web `ReadableStream` natively, so no conversion is needed.
68
- */
69
- data?: ReadableStream;
70
- /** The initial `RecordsWriteMessage` that represents the initial state/version of the record. */
71
- initialWrite?: DwnMessage[DwnInterface.RecordsWrite];
72
- /** The protocol role under which this record is written. */
73
- protocolRole?: string;
74
- /** The remote tenant DID if the record was queried or read from a remote DWN. */
75
- remoteOrigin?: string;
76
- };
77
- /**
78
- * Parameters for updating a DWN record.
79
- *
80
- * This type specifies the set of properties that can be updated on an existing record. It is used
81
- * to convey the new state or changes to be applied to the record.
82
- *
83
- * @beta
84
- */
85
- export type RecordUpdateParams = {
86
- /**
87
- * The new data for the record, which can be of any type. This data will replace the existing
88
- * data of the record. It's essential to ensure that this data is compatible with the record's
89
- * schema or data format expectations.
90
- */
91
- data?: unknown;
92
- /**
93
- * The Content Identifier (CID) of the data. Updating this value changes the reference to the data
94
- * associated with the record.
95
- */
96
- dataCid?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['dataCid'];
97
- /** Whether or not to store the updated message. */
98
- store?: boolean;
99
- /** The data format/MIME type of the supplied data */
100
- dataFormat?: string;
101
- /** The size of the data in bytes. */
102
- dataSize?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['dataSize'];
103
- /** The timestamp of the update message. */
104
- timestamp?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['messageTimestamp'];
105
- /** The timestamp indicating when the record was published. */
106
- datePublished?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['datePublished'];
107
- /** The protocol role under which this record is written. */
108
- protocolRole?: RecordOptions['protocolRole'];
109
- /** The published status of the record. */
110
- published?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['published'];
111
- /** The tags associated with the updated record */
112
- tags?: DwnMessageDescriptor[DwnInterface.RecordsWrite]['tags'];
113
- /**
114
- * Controls whether the updated record should be auto-encrypted.
115
- *
116
- * If omitted, auto-detected from the original record: if the record was
117
- * originally encrypted, the update is automatically re-encrypted with a
118
- * fresh DEK. Set to `false` explicitly to skip encryption on the update.
119
- */
120
- encryption?: boolean;
121
- };
122
- /**
123
- * Parameters for deleting a DWN record.
124
- *
125
- * This type specifies the set of properties that are used when deleting an existing record. It is used
126
- * to convey the new state or changes to be applied to the record.
127
- *
128
- * @beta
129
- */
130
- export type RecordDeleteParams = {
131
- /** Whether or not to store the message. */
132
- store?: boolean;
133
- /** Whether or not to sign the delete as an owner in order to import it. */
134
- signAsOwner?: boolean;
135
- /** Whether or not to prune any children this record may have. */
136
- prune?: DwnMessageDescriptor[DwnInterface.RecordsDelete]['prune'];
137
- /** The timestamp of the delete message. */
138
- timestamp?: DwnMessageDescriptor[DwnInterface.RecordsDelete]['messageTimestamp'];
139
- /** The protocol role under which this record will be deleted. */
140
- protocolRole?: string;
141
- };
8
+ import type { RecordData } from './record-data.js';
9
+ export type { ImmutableRecordProperties, OptionalRecordProperties, RecordDeleteParams, RecordModel, RecordOptions, RecordUpdateParams, } from './record-types.js';
10
+ export type { RecordData } from './record-data.js';
142
11
  /**
143
12
  * The result of a {@link Record.update} operation.
144
13
  *
@@ -282,15 +151,7 @@ export declare class Record implements RecordModel {
282
151
  *
283
152
  * @beta
284
153
  */
285
- get data(): {
286
- blob: () => Promise<Blob>;
287
- bytes: () => Promise<Uint8Array>;
288
- json: <T = unknown>() => Promise<T>;
289
- text: () => Promise<string>;
290
- stream: () => Promise<ReadableStream>;
291
- then: (onFulfilled?: (value: ReadableStream) => ReadableStream | PromiseLike<ReadableStream>, onRejected?: (reason: any) => PromiseLike<never>) => Promise<ReadableStream>;
292
- catch: (onRejected?: (reason: any) => PromiseLike<never>) => Promise<ReadableStream>;
293
- };
154
+ get data(): RecordData;
294
155
  /**
295
156
  * Stores the current record state as well as any initial write to the owner's DWN.
296
157
  *
@@ -382,6 +243,14 @@ export declare class Record implements RecordModel {
382
243
  * @beta
383
244
  */
384
245
  private readRecordData;
246
+ /**
247
+ * If the record is operating as a delegate, fetches the appropriate permission grant
248
+ * and applies it to the given DWN request options. This centralises the repeated
249
+ * pattern of looking up a delegated grant and attaching it to a request.
250
+ *
251
+ * @param requestOptions - The DWN request options to augment with the delegate grant.
252
+ */
253
+ private applyDelegateGrant;
385
254
  /**
386
255
  * Verifies if the properties to be mutated are mutable.
387
256
  *
@@ -1 +1 @@
1
- {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,oBAAoB,EAEpB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EAGd,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEL,YAAY,EAKb,MAAM,cAAc,CAAC;AAKtB;;;;KAIK;AACL,MAAM,MAAM,yBAAyB,GACnC,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,cAAc,GAAG,WAAW,GAAG,QAAQ,CAAC,CAAC;AAE3I;;;;EAIE;AACF,MAAM,MAAM,wBAAwB,GAClC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,eAAe,GAAG,aAAa,GAAG,YAAY,GAAG,WAAW,CAAE,GAC1G,IAAI,CAAC,oBAAoB,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,UAAU,GAAG,eAAe,GAAG,WAAW,GAAG,MAAM,CAAC,CAAC;AAExI;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,yBAAyB,GAAG,wBAAwB,GAAG;IAE/E,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IAEf,2CAA2C;IAC3C,QAAQ,CAAC,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1,137 @@
1
+ /**
2
+ * Type-level machinery for the protocol repository pattern.
3
+ *
4
+ * These types produce a statically-typed CRUD API shape from a
5
+ * `ProtocolDefinition` + `SchemaMap`, with singleton detection
6
+ * (via `$recordLimit: { max: 1 }`) and nested-path awareness.
7
+ *
8
+ * All types are purely compile-time — they produce no runtime code.
9
+ *
10
+ * @module
11
+ */
12
+ import type { SchemaMap } from './protocol-types.js';
13
+ import type { TypedLiveQuery } from './typed-live-query.js';
14
+ import type { TypedRecord } from './typed-record.js';
15
+ import type { DataForPath, TypedCreateRequest, TypedQueryRequest, TypedSubscribeRequest } from './typed-web5.js';
16
+ import type { DwnPaginationCursor, DwnResponseStatus } from '@enbox/agent';
17
+ import type { ProtocolDefinition, ProtocolRuleSet } from '@enbox/dwn-sdk-js';
18
+ /**
19
+ * Navigates a `ProtocolRuleSet` tree to the node at a slash-delimited path.
20
+ */
21
+ type RuleSetAtPath<R, Path extends string> = Path extends `${infer Head}/${infer Tail}` ? Head extends keyof R ? R[Head] extends ProtocolRuleSet ? RuleSetAtPath<R[Head], Tail> : never : never : Path extends keyof R ? R[Path] extends ProtocolRuleSet ? R[Path] : never : never;
22
+ /**
23
+ * Extracts the `$recordLimit` from a rule set node, if present.
24
+ */
25
+ type RecordLimitAtRuleSet<RS> = RS extends {
26
+ $recordLimit: infer L;
27
+ } ? L : never;
28
+ /**
29
+ * `true` when the rule set at `Path` has `$recordLimit: { max: 1 }`.
30
+ */
31
+ export type IsSingleton<D extends ProtocolDefinition, Path extends string> = RecordLimitAtRuleSet<RuleSetAtPath<D['structure'], Path>> extends {
32
+ max: 1;
33
+ } ? true : false;
34
+ /** Resolves the TypeScript data type for a given path. */
35
+ type DataAt<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = DataForPath<D, M, Path>;
36
+ /**
37
+ * Write options for a collection `create()` call.
38
+ * Omits `data` (passed separately) and protocol-injected fields.
39
+ */
40
+ export type CollectionCreateOptions<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = Omit<TypedCreateRequest<D, M, Path>, 'data' | 'parentContextId'> & {
41
+ data: DataAt<D, M, Path>;
42
+ };
43
+ /**
44
+ * Write options for a singleton `set()` call.
45
+ */
46
+ export type SingletonSetOptions<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = Omit<TypedCreateRequest<D, M, Path>, 'data' | 'parentContextId'> & {
47
+ data: DataAt<D, M, Path>;
48
+ };
49
+ /** CRUD API for a root-level collection (unbounded or max > 1). */
50
+ export type CollectionCRUD<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = {
51
+ create(options: CollectionCreateOptions<D, M, Path>): Promise<DwnResponseStatus & {
52
+ record: TypedRecord<DataAt<D, M, Path>>;
53
+ }>;
54
+ query(options?: TypedQueryRequest): Promise<DwnResponseStatus & {
55
+ records: TypedRecord<DataAt<D, M, Path>>[];
56
+ cursor?: DwnPaginationCursor;
57
+ }>;
58
+ get(recordId: string): Promise<TypedRecord<DataAt<D, M, Path>>>;
59
+ delete(recordId: string): Promise<DwnResponseStatus>;
60
+ subscribe(options?: TypedSubscribeRequest): Promise<TypedLiveQuery<DataAt<D, M, Path>> | undefined>;
61
+ };
62
+ /** CRUD API for a root-level singleton ($recordLimit max: 1). */
63
+ export type SingletonCRUD<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = {
64
+ set(options: SingletonSetOptions<D, M, Path>): Promise<DwnResponseStatus & {
65
+ record: TypedRecord<DataAt<D, M, Path>>;
66
+ }>;
67
+ get(): Promise<TypedRecord<DataAt<D, M, Path>> | undefined>;
68
+ delete(recordId: string): Promise<DwnResponseStatus>;
69
+ };
70
+ /** CRUD API for a nested collection (parent context required). */
71
+ export type NestedCollectionCRUD<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = {
72
+ create(parentContextId: string, options: CollectionCreateOptions<D, M, Path>): Promise<DwnResponseStatus & {
73
+ record: TypedRecord<DataAt<D, M, Path>>;
74
+ }>;
75
+ query(parentContextId: string, options?: TypedQueryRequest): Promise<DwnResponseStatus & {
76
+ records: TypedRecord<DataAt<D, M, Path>>[];
77
+ cursor?: DwnPaginationCursor;
78
+ }>;
79
+ get(recordId: string): Promise<TypedRecord<DataAt<D, M, Path>>>;
80
+ delete(recordId: string): Promise<DwnResponseStatus>;
81
+ subscribe(parentContextId: string, options?: TypedSubscribeRequest): Promise<TypedLiveQuery<DataAt<D, M, Path>> | undefined>;
82
+ };
83
+ /** CRUD API for a nested singleton ($recordLimit max: 1). */
84
+ export type NestedSingletonCRUD<D extends ProtocolDefinition, M extends SchemaMap, Path extends string> = {
85
+ set(parentContextId: string, options: SingletonSetOptions<D, M, Path>): Promise<DwnResponseStatus & {
86
+ record: TypedRecord<DataAt<D, M, Path>>;
87
+ }>;
88
+ get(parentContextId: string): Promise<TypedRecord<DataAt<D, M, Path>> | undefined>;
89
+ delete(recordId: string): Promise<DwnResponseStatus>;
90
+ };
91
+ /**
92
+ * Extracts the child type names (non-`$`-prefixed keys that extend ProtocolRuleSet)
93
+ * from a rule set node.
94
+ */
95
+ type ChildKeys<RS> = {
96
+ [K in Extract<keyof RS, string>]: K extends `$${string}` ? never : RS[K] extends ProtocolRuleSet ? K : never;
97
+ }[Extract<keyof RS, string>];
98
+ /**
99
+ * Builds nested repository nodes for all children of a given rule set.
100
+ */
101
+ type ChildNodes<D extends ProtocolDefinition, M extends SchemaMap, RS, ParentPath extends string> = {
102
+ [K in ChildKeys<RS>]: RepositoryNode<D, M, RS[K], `${ParentPath}/${K}`, true>;
103
+ };
104
+ /**
105
+ * A single node in the repository tree. Provides CRUD methods appropriate
106
+ * to whether the path is root/nested and singleton/collection, plus child
107
+ * nodes for further nesting.
108
+ */
109
+ export type RepositoryNode<D extends ProtocolDefinition, M extends SchemaMap, RS, Path extends string, IsNested extends boolean = false> = (IsNested extends true ? (IsSingleton<D, Path> extends true ? NestedSingletonCRUD<D, M, Path> : NestedCollectionCRUD<D, M, Path>) : (IsSingleton<D, Path> extends true ? SingletonCRUD<D, M, Path> : CollectionCRUD<D, M, Path>)) & ChildNodes<D, M, RS, Path>;
110
+ /**
111
+ * The top-level repository type for a protocol definition.
112
+ *
113
+ * Maps each root-level type name in the protocol's `structure` to a
114
+ * `RepositoryNode` with the appropriate CRUD methods and nested children.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const social: Repository<typeof SocialGraphDef, SocialGraphSchemaMap>;
119
+ *
120
+ * // Root collection
121
+ * await social.friend.create({ data: { did: '...' } });
122
+ * await social.friend.query();
123
+ *
124
+ * // Nested under group
125
+ * await social.group.member.create(groupCtxId, { data: { did: '...' } });
126
+ * ```
127
+ */
128
+ export type Repository<D extends ProtocolDefinition, M extends SchemaMap> = {
129
+ [K in Extract<keyof D['structure'], string> as K extends `$${string}` ? never : K]: D['structure'][K] extends ProtocolRuleSet ? RepositoryNode<D, M, D['structure'][K], K> : never;
130
+ } & {
131
+ /** Install (configure) the protocol. Idempotent — no-op if already installed. */
132
+ configure(options?: {
133
+ encryption?: boolean;
134
+ }): Promise<DwnResponseStatus>;
135
+ };
136
+ export {};
137
+ //# sourceMappingURL=repository-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-types.d.ts","sourceRoot":"","sources":["../../src/repository-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAM7E;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC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AC,CAAC,CAAC,SAAS,eAAe,GACrC,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAC1C,KAAK;CACZ,GAAG;IACF,iFAAiF;IACjF,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC3E,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Protocol-aware repository factory.
3
+ *
4
+ * `repository()` takes a `TypedWeb5` instance and returns a Proxy-backed
5
+ * object whose shape mirrors the protocol's `structure` tree with
6
+ * ergonomic CRUD methods on each node.
7
+ *
8
+ * - **Collections** (default): `create`, `query`, `get`, `delete`, `subscribe`
9
+ * - **Singletons** (`$recordLimit: { max: 1 }`): `set`, `get`, `delete`
10
+ * - **Nested types**: first argument is `parentContextId`
11
+ * - **`configure()`**: idempotent protocol installation
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const social = repository(web5.using(SocialGraphProtocol));
16
+ * await social.configure();
17
+ *
18
+ * // Root collection
19
+ * const { record } = await social.friend.create({
20
+ * data: { did: 'did:example:alice' },
21
+ * });
22
+ *
23
+ * // Nested under group
24
+ * const members = await social.group.member.query(groupContextId);
25
+ * ```
26
+ *
27
+ * @module
28
+ */
29
+ import type { Repository } from './repository-types.js';
30
+ import type { SchemaMap } from './protocol-types.js';
31
+ import type { TypedWeb5 } from './typed-web5.js';
32
+ import type { ProtocolDefinition } from '@enbox/dwn-sdk-js';
33
+ /**
34
+ * Creates a protocol-aware repository from a `TypedWeb5` instance.
35
+ *
36
+ * The returned object provides domain-specific CRUD methods that mirror
37
+ * the protocol's structure tree:
38
+ *
39
+ * - Root types: `repo.friend.create()`, `repo.friend.query()`
40
+ * - Nested types: `repo.group.member.create(groupCtxId, { data })`
41
+ * - Singletons: `repo.profile.set()`, `repo.profile.get()`
42
+ * - Protocol install: `repo.configure()`
43
+ *
44
+ * @param typed - A `TypedWeb5` instance from `web5.using(protocol)`.
45
+ * @returns A typed repository object.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const social = repository(web5.using(SocialGraphProtocol));
50
+ * await social.configure();
51
+ *
52
+ * const rec = await social.friend.create({
53
+ * data: { did: 'did:example:alice' },
54
+ * });
55
+ * const friends = await social.friend.query();
56
+ * ```
57
+ */
58
+ export declare function repository<D extends ProtocolDefinition, M extends SchemaMap>(typed: TypedWeb5<D, M>): Repository<D, M>;
59
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../src/repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAmB,MAAM,mBAAmB,CAAC;AAoS7E;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CACxB,CAAC,SAAS,kBAAkB,EAC5B,CAAC,SAAS,SAAS,EACnB,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAqC1C"}
@@ -0,0 +1,86 @@
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
+ import type { PaginationCursor } from '@enbox/dwn-sdk-js';
25
+ import type { LiveQuery, RecordChange } from './live-query.js';
26
+ import { TypedRecord } from './typed-record.js';
27
+ /**
28
+ * Describes a change to a record in a {@link TypedLiveQuery}.
29
+ *
30
+ * Same shape as {@link RecordChange} but with the record wrapped
31
+ * in a {@link TypedRecord}.
32
+ */
33
+ export type TypedRecordChange<T> = {
34
+ /** Whether the record was created, updated, or deleted. */
35
+ type: RecordChange['type'];
36
+ /** The typed record affected by the change. */
37
+ record: TypedRecord<T>;
38
+ };
39
+ /**
40
+ * A type-safe wrapper around {@link LiveQuery} that preserves the data type `T`
41
+ * through the initial snapshot and all subsequent change events.
42
+ *
43
+ * Obtain instances through `TypedWeb5.records.subscribe()` — never construct
44
+ * directly.
45
+ */
46
+ export declare class TypedLiveQuery<T> {
47
+ /** The underlying untyped LiveQuery instance. */
48
+ private _liveQuery;
49
+ /** Cached typed record array, built lazily from the underlying records. */
50
+ private _typedRecords?;
51
+ constructor(liveQuery: LiveQuery);
52
+ /** Access the underlying untyped {@link LiveQuery} for advanced use cases. */
53
+ get rawLiveQuery(): LiveQuery;
54
+ /** The initial snapshot of matching records, typed as `TypedRecord<T>[]`. */
55
+ get records(): TypedRecord<T>[];
56
+ /**
57
+ * Pagination cursor for fetching the next page of initial results.
58
+ *
59
+ * `undefined` when there are no more results.
60
+ */
61
+ get cursor(): PaginationCursor | undefined;
62
+ /**
63
+ * Register a typed event handler. Returns an unsubscribe function.
64
+ *
65
+ * @param event - The event type to listen for.
66
+ * @param handler - The handler function with typed record(s).
67
+ * @returns A function that removes the handler when called.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const off = liveQuery.on('create', (record) => {
72
+ * // record is TypedRecord<T>
73
+ * });
74
+ * off(); // stop listening
75
+ * ```
76
+ */
77
+ on(event: 'change', handler: (change: TypedRecordChange<T>) => void): () => void;
78
+ on(event: 'create', handler: (record: TypedRecord<T>) => void): () => void;
79
+ on(event: 'update', handler: (record: TypedRecord<T>) => void): () => void;
80
+ on(event: 'delete', handler: (record: TypedRecord<T>) => void): () => void;
81
+ /**
82
+ * Close the underlying subscription and stop dispatching events.
83
+ */
84
+ close(): Promise<void>;
85
+ }
86
+ //# sourceMappingURL=typed-live-query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-live-query.d.ts","sourceRoot":"","sources":["../../src/typed-live-query.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMhD;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;IACjC,2DAA2D;IAC3D,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAE3B,+CAA+C;IAC/C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;CACxB,CAAC;AAMF;;;;;;GAMG;AACH,qBAAa,cAAc,CAAC,CAAC;IAC3B,iDAAiD;IACjD,OAAO,CAAC,UAAU,CAAY;IAE9B,2EAA2E;IAC3E,OAAO,CAAC,aAAa,CAAC,CAAmB;gBAE7B,SAAS,EAAE,SAAS;IAQhC,8EAA8E;IAC9E,IAAW,YAAY,IAAI,SAAS,CAEnC;IAMD,6EAA6E;IAC7E,IAAW,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,CAOrC;IAED;;;;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