@api-client/core 0.6.23 → 0.6.26

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.
@@ -90,17 +90,40 @@ export interface ContextDeleteEventDetail {
90
90
  */
91
91
  parent?: string;
92
92
  }
93
+ export interface ContextDeleteBulkEventDetail {
94
+ /**
95
+ * The list of ids of the domain object to remove.
96
+ */
97
+ ids: string[];
98
+ /**
99
+ * The id of the parent object, if applicable.
100
+ */
101
+ parent?: string;
102
+ }
93
103
  /**
94
104
  * An event to be used to delete a state in the context provider.
95
105
  */
96
106
  export declare class ContextDeleteEvent extends ContextEvent<ContextDeleteEventDetail, ContextDeleteRecord> {
97
107
  /**
108
+ * An event to be used to delete a state in the context provider.
98
109
  * @param type The type of the event to dispatch.
99
110
  * @param id The id of the object to delete
100
111
  * @param parent The id of the parent object, if applicable.
101
112
  */
102
113
  constructor(type: string, id: string, parent?: string);
103
114
  }
115
+ /**
116
+ * An event to be used to delete a number of entities in the context provider.
117
+ */
118
+ export declare class ContextDeleteBulkEvent extends ContextEvent<ContextDeleteBulkEventDetail, ContextDeleteRecord[]> {
119
+ /**
120
+ * An event to be used to delete a number of entities in the context provider.
121
+ * @param type The type of the event to dispatch.
122
+ * @param ids The list of ids of the domain object to remove.
123
+ * @param parent The id of the parent object, if applicable.
124
+ */
125
+ constructor(type: string, ids: string[], parent?: string);
126
+ }
104
127
  export interface ContextDeleteRecord {
105
128
  /**
106
129
  * The data kind of the deleted item.
@@ -116,6 +139,20 @@ export interface ContextDeleteRecord {
116
139
  */
117
140
  parent?: string;
118
141
  }
142
+ /**
143
+ * An event dispatched to the context store to restore previously deleted items.
144
+ */
145
+ export declare class ContextRestoreEvent<T> extends ContextEvent<ContextDeleteRecord[], ContextChangeRecord<T>[]> {
146
+ /**
147
+ * An event dispatched to the context store to restore previously deleted items.
148
+ *
149
+ * The result of the event is the list of `ContextChangeRecord` for the restored items.
150
+ *
151
+ * @param type The type of the event.
152
+ * @param records The records of previously deleted items.
153
+ */
154
+ constructor(type: string, records: ContextDeleteRecord[]);
155
+ }
119
156
  /**
120
157
  * An event dispatched when a context store object has been deleted.
121
158
  * In general a single context store uses the same event to dispatch the change record.
@@ -149,15 +186,52 @@ export interface ContextUpdateEventDetail<T> {
149
186
  */
150
187
  parent?: string;
151
188
  }
189
+ export interface ContextUpdateBulkEventDetail<T> {
190
+ /**
191
+ * The list of context store objects to be updated by the context provider.
192
+ */
193
+ items: T[];
194
+ /**
195
+ * The id of the parent object, if applicable.
196
+ */
197
+ parent?: string;
198
+ }
152
199
  /**
153
200
  * An event that is dispatched to update the entire object in the store.
154
201
  * This is equivalent to PUT operation in REST HTTP.
155
202
  *
156
203
  * @template T The object that is being updated.
204
+ * @template U The object that is returned by the context store after updating. By default it is the `T`.
157
205
  */
158
206
  export declare class ContextUpdateEvent<T extends object, U = T> extends ContextEvent<ContextUpdateEventDetail<T>, ContextChangeRecord<U>> {
207
+ /**
208
+ * An event that is dispatched to update the entire object in the store.
209
+ * This is equivalent to PUT operation in REST HTTP.
210
+ *
211
+ * @param type The type of the event to dispatch
212
+ * @param updateInfo The update information.
213
+ */
159
214
  constructor(type: string, updateInfo: ContextUpdateEventDetail<T>);
160
215
  }
216
+ /**
217
+ * An event that is dispatched to update a list of objects in the store.
218
+ * This is equivalent to PUT operation in REST HTTP.
219
+ *
220
+ * If there's a parent, this event only allows to update entities in bulk for the same parent.
221
+ *
222
+ * @template T The object that is being updated.
223
+ * @template U The object that is returned by the context store after updating. By default it is the `T`.
224
+ */
225
+ export declare class ContextUpdateBulkEvent<T extends object, U = T> extends ContextEvent<ContextUpdateBulkEventDetail<T>, ContextChangeRecord<U>[]> {
226
+ /**
227
+ * An event that is dispatched to update the entire object in the store.
228
+ * This is equivalent to PUT operation in REST HTTP.
229
+ *
230
+ * @param type The type of the event to dispatch
231
+ * @param updateInfo The update information.
232
+ */
233
+ constructor(type: string, updateInfo: ContextUpdateBulkEventDetail<T>);
234
+ }
161
235
  /**
162
236
  * Data store query result object.
163
237
  */
@@ -193,3 +267,46 @@ export declare class ContextListEvent<T> extends ContextEvent<ContextListOptions
193
267
  */
194
268
  constructor(type: string, opts?: ContextListOptions);
195
269
  }
270
+ export interface IQueryDetail {
271
+ /**
272
+ * The query term. All values are always passed as string. Context store must parse value if it requires other types.
273
+ */
274
+ term: string;
275
+ /**
276
+ * If the context store supports it, the tags to use with the query function to limit the results.
277
+ */
278
+ tags?: string[];
279
+ /**
280
+ * General purpose type to be defined by the context store.
281
+ * Allows to specify the type of the query to perform.
282
+ */
283
+ type?: string;
284
+ /**
285
+ * General purpose keyword to be defined by the context store.
286
+ * The purpose is to instruct the context store to perform detailed search.
287
+ * Usually this means longer search time but more accurate results.
288
+ */
289
+ detailed?: boolean;
290
+ }
291
+ /**
292
+ * An event dispatched to the context store to perform a query operation.
293
+ * If the context store supports the query operation, it should use the definition of `IQueryDetail` to perform the query.
294
+ * The result is the list of objects ordered by the store from the most relevant items to the least.
295
+ *
296
+ * The implementation should not assume pagination and return enough results for the user to find what they were looking for
297
+ * or to redefine the query. Suggested limit is `50` which in many cases is equivalent of 2 pages of results.
298
+ */
299
+ export declare class ContextQueryEvent<T = unknown> extends ContextEvent<IQueryDetail, T[]> {
300
+ /**
301
+ * An event dispatched to the context store to perform a query operation.
302
+ * If the context store supports the query operation, it should use the definition of `IQueryDetail` to perform the query.
303
+ * The result is the list of objects ordered by the store from the most relevant items to the least.
304
+ *
305
+ * The implementation should not assume pagination and return enough results for the user to find what they were looking for
306
+ * or to redefine the query. Suggested limit is `50` which in many cases is equivalent of 2 pages of results.
307
+ *
308
+ * @param type The type of the event.
309
+ * @param opts The query options.
310
+ */
311
+ constructor(type: string, opts: IQueryDetail);
312
+ }
@@ -49,6 +49,7 @@ export class ContextReadBulkEvent extends ContextEvent {
49
49
  */
50
50
  export class ContextDeleteEvent extends ContextEvent {
51
51
  /**
52
+ * An event to be used to delete a state in the context provider.
52
53
  * @param type The type of the event to dispatch.
53
54
  * @param id The id of the object to delete
54
55
  * @param parent The id of the parent object, if applicable.
@@ -57,6 +58,36 @@ export class ContextDeleteEvent extends ContextEvent {
57
58
  super(type, { id, parent });
58
59
  }
59
60
  }
61
+ /**
62
+ * An event to be used to delete a number of entities in the context provider.
63
+ */
64
+ export class ContextDeleteBulkEvent extends ContextEvent {
65
+ /**
66
+ * An event to be used to delete a number of entities in the context provider.
67
+ * @param type The type of the event to dispatch.
68
+ * @param ids The list of ids of the domain object to remove.
69
+ * @param parent The id of the parent object, if applicable.
70
+ */
71
+ constructor(type, ids, parent) {
72
+ super(type, { ids, parent });
73
+ }
74
+ }
75
+ /**
76
+ * An event dispatched to the context store to restore previously deleted items.
77
+ */
78
+ export class ContextRestoreEvent extends ContextEvent {
79
+ /**
80
+ * An event dispatched to the context store to restore previously deleted items.
81
+ *
82
+ * The result of the event is the list of `ContextChangeRecord` for the restored items.
83
+ *
84
+ * @param type The type of the event.
85
+ * @param records The records of previously deleted items.
86
+ */
87
+ constructor(type, records) {
88
+ super(type, records);
89
+ }
90
+ }
60
91
  /**
61
92
  * An event dispatched when a context store object has been deleted.
62
93
  * In general a single context store uses the same event to dispatch the change record.
@@ -99,8 +130,37 @@ export class ContextStateUpdateEvent extends CustomEvent {
99
130
  * This is equivalent to PUT operation in REST HTTP.
100
131
  *
101
132
  * @template T The object that is being updated.
133
+ * @template U The object that is returned by the context store after updating. By default it is the `T`.
102
134
  */
103
135
  export class ContextUpdateEvent extends ContextEvent {
136
+ /**
137
+ * An event that is dispatched to update the entire object in the store.
138
+ * This is equivalent to PUT operation in REST HTTP.
139
+ *
140
+ * @param type The type of the event to dispatch
141
+ * @param updateInfo The update information.
142
+ */
143
+ constructor(type, updateInfo) {
144
+ super(type, updateInfo);
145
+ }
146
+ }
147
+ /**
148
+ * An event that is dispatched to update a list of objects in the store.
149
+ * This is equivalent to PUT operation in REST HTTP.
150
+ *
151
+ * If there's a parent, this event only allows to update entities in bulk for the same parent.
152
+ *
153
+ * @template T The object that is being updated.
154
+ * @template U The object that is returned by the context store after updating. By default it is the `T`.
155
+ */
156
+ export class ContextUpdateBulkEvent extends ContextEvent {
157
+ /**
158
+ * An event that is dispatched to update the entire object in the store.
159
+ * This is equivalent to PUT operation in REST HTTP.
160
+ *
161
+ * @param type The type of the event to dispatch
162
+ * @param updateInfo The update information.
163
+ */
104
164
  constructor(type, updateInfo) {
105
165
  super(type, updateInfo);
106
166
  }
@@ -114,4 +174,28 @@ export class ContextListEvent extends ContextEvent {
114
174
  super(type, opts);
115
175
  }
116
176
  }
177
+ /**
178
+ * An event dispatched to the context store to perform a query operation.
179
+ * If the context store supports the query operation, it should use the definition of `IQueryDetail` to perform the query.
180
+ * The result is the list of objects ordered by the store from the most relevant items to the least.
181
+ *
182
+ * The implementation should not assume pagination and return enough results for the user to find what they were looking for
183
+ * or to redefine the query. Suggested limit is `50` which in many cases is equivalent of 2 pages of results.
184
+ */
185
+ export class ContextQueryEvent extends ContextEvent {
186
+ /**
187
+ * An event dispatched to the context store to perform a query operation.
188
+ * If the context store supports the query operation, it should use the definition of `IQueryDetail` to perform the query.
189
+ * The result is the list of objects ordered by the store from the most relevant items to the least.
190
+ *
191
+ * The implementation should not assume pagination and return enough results for the user to find what they were looking for
192
+ * or to redefine the query. Suggested limit is `50` which in many cases is equivalent of 2 pages of results.
193
+ *
194
+ * @param type The type of the event.
195
+ * @param opts The query options.
196
+ */
197
+ constructor(type, opts) {
198
+ super(type, opts);
199
+ }
200
+ }
117
201
  //# sourceMappingURL=BaseEvents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseEvents.js","sourceRoot":"","sources":["../../../src/events/BaseEvents.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAc3C;;GAEG;AACH,MAAM,OAAO,YAAkC,SAAQ,WAAgD;IACrG;;;OAGG;IACH,YAAY,IAAY,EAAE,MAAS;QACjC,KAAK,CAAC,IAAI,EAAE;YACV,OAAO,EAAE,IAAI;YACb,QAAQ,E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CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC1B,CAAC;CACF;AAgCD,MAAM,OAAO,gBAAoB,SAAQ,YAAsD;IAC7F;;;OAGG;IACH,YAAY,IAAY,EAAE,OAA2B,EAAE;QACrD,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpB,CAAC;CACF;AA2BD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAA+B,SAAQ,YAA+B;IACjF;;;;;;;;;;OAUG;IACH,YAAY,IAAY,EAAE,IAAkB;QAC1C,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpB,CAAC;CACF"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import { ARCCertificateIndex, RequestCertificate } from './legacy/models/ClientCertificate.js';
2
3
  export declare type CertificateType = 'p12' | 'pem';
3
4
  export declare const Kind = "Core#Certificate";
4
5
  export declare type CertificateDataFormat = string | ArrayBuffer | Buffer | Uint8Array;
@@ -144,13 +145,20 @@ export declare class Certificate {
144
145
  * @param passphrase The key passphrase
145
146
  */
146
147
  static fromP12(cert: CertificateDataFormat, name?: string, passphrase?: string): Certificate;
148
+ /**
149
+ * Creates a certificate object from the ARC's legacy certificate definition.
150
+ *
151
+ * @param index The legacy certificate index object. If it has set `_id` it will be used as the `key`.
152
+ * @param index The certificate data object as read from the data store. Do not restore the data to its original format.
153
+ */
154
+ static fromLegacy(index: ARCCertificateIndex, cert: RequestCertificate): Certificate;
147
155
  constructor(certificate: HttpCertificate);
148
156
  /**
149
157
  * When needed it reads the certificate's original format.
150
158
  * @param data The certificate data.
151
159
  * @returns The restored certificate.
152
160
  */
153
- fromStore(data: ICertificateData): ICertificateData;
161
+ static fromStore(data: ICertificateData): ICertificateData;
154
162
  /**
155
163
  * Prepares certificate object to be stored in the data store.
156
164
  * If the `data` property is not string then it assumes buffer (either
@@ -165,6 +173,6 @@ export declare class Certificate {
165
173
  * @param data The certificate data object.
166
174
  * @throws When data is not set
167
175
  */
168
- toStore(data: ICertificateData): ICertificateData;
176
+ static toStore(data: ICertificateData): ICertificateData;
169
177
  toJSON(): HttpCertificate;
170
178
  }
@@ -79,17 +79,55 @@ export class Certificate {
79
79
  }
80
80
  return new Certificate(init);
81
81
  }
82
+ /**
83
+ * Creates a certificate object from the ARC's legacy certificate definition.
84
+ *
85
+ * @param index The legacy certificate index object. If it has set `_id` it will be used as the `key`.
86
+ * @param index The certificate data object as read from the data store. Do not restore the data to its original format.
87
+ */
88
+ static fromLegacy(index, cert) {
89
+ const { name = '', type, created = Date.now(), _id = v4() } = index;
90
+ if (type === 'pem') {
91
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
92
+ const key = Array.isArray(cert.key) ? cert.key[0] : cert.key;
93
+ if (!key) {
94
+ throw new Error(`Unable to create a PEM certificate without the key.`);
95
+ }
96
+ const init = {
97
+ kind: Kind,
98
+ cert: data,
99
+ certKey: key,
100
+ key: _id,
101
+ name,
102
+ type: 'pem',
103
+ created,
104
+ };
105
+ return new Certificate(init);
106
+ }
107
+ else if (type === 'p12') {
108
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
109
+ const init = {
110
+ kind: Kind,
111
+ cert: data,
112
+ key: _id,
113
+ name,
114
+ type: 'p12',
115
+ };
116
+ return new Certificate(init);
117
+ }
118
+ throw new Error(`Unable to create a certificate. Unknown type: ${type}.`);
119
+ }
82
120
  constructor(certificate) {
83
121
  const { type, cert, key = v4(), name = '', created } = certificate;
84
122
  this.key = key;
85
123
  this.name = name;
86
124
  this.type = type;
87
- this.cert = this.fromStore(cert);
125
+ this.cert = Certificate.fromStore(cert);
88
126
  if (typeof created === 'number') {
89
127
  this.created = created;
90
128
  }
91
129
  if (type === 'pem') {
92
- this.certKey = this.fromStore(certificate.certKey);
130
+ this.certKey = Certificate.fromStore(certificate.certKey);
93
131
  }
94
132
  }
95
133
  /**
@@ -97,7 +135,7 @@ export class Certificate {
97
135
  * @param data The certificate data.
98
136
  * @returns The restored certificate.
99
137
  */
100
- fromStore(data) {
138
+ static fromStore(data) {
101
139
  if (data.type) {
102
140
  delete data.type;
103
141
  const content = data.data;
@@ -119,7 +157,7 @@ export class Certificate {
119
157
  * @param data The certificate data object.
120
158
  * @throws When data is not set
121
159
  */
122
- toStore(data) {
160
+ static toStore(data) {
123
161
  if (!data) {
124
162
  throw new Error('Certificate data is missing.');
125
163
  }
@@ -137,13 +175,13 @@ export class Certificate {
137
175
  const result = {
138
176
  kind: Kind,
139
177
  key: this.key,
140
- cert: this.toStore(this.cert),
178
+ cert: Certificate.toStore(this.cert),
141
179
  name: this.name,
142
180
  type: 'p12',
143
181
  };
144
182
  if (this.type === 'pem' && this.certKey) {
145
183
  const typed = result;
146
- typed.certKey = this.toStore(this.certKey);
184
+ typed.certKey = Certificate.toStore(this.certKey);
147
185
  }
148
186
  return result;
149
187
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClientCertificate.js","sourceRoot":"","sources":["../../../src/models/ClientCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAIhC,MAAM,CAAC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AA2GvC;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,IAAI,GAAG,IAAI,CAAC;IACZ;;OAEG;IACH,GAAG,CAAS;IACZ;;OAEG;IACH,IAAI,CAAS;IACb;;;OAGG;IACH,OAAO,CAAU;IACjB;;OAEG;IACH,IAAI,CAAkB;IACtB;;OAEG;IACH,IAAI,CAAmB;IACvB;;OAEG;IACH,OAAO,CAAoB;IAE3B;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,GAA0B,EAAE,GAA0B,EAAE,IAAI,GAAG,qBAAqB,EAAE,aAAsB;QACzH,MAAM,IAAI,GAAoB;YAC5B,IAAI,EAAE,IAAI;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,GAAG;aAC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 {"version":3,"file":"ClientCertificate.js","sourceRoot":"","sources":["../../../src/models/ClientCertificate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAKhC,MAAM,CAAC,MAAM,IAAI,GAAG,kBAAkB,CAAC;AA2GvC;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,IAAI,GAAG,IAAI,CAAC;IACZ;;OAEG;IACH,GAAG,CAAS;IACZ;;OAEG;IACH,IAAI,CAAS;IACb;;;OAGG;IACH,OAAO,CAAU;IACjB;;OAEG;IACH,IAAI,CAAkB;IACtB;;OAEG;IACH,IAAI,CAAmB;IACvB;;OAEG;IACH,OAAO,CAAoB;IAE3B;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,CAAC,GAA0B,EAAE,GAA0B,EAAE,IAAI,GAAG,qBAAqB,EAAE,aAAsB;QACzH,MAAM,IAAI,GAAoB;YAC5B,IAAI,EAAE,IAAI;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,GAAG;aACV;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,GAAG;aACV;YACD,GAAG,EAAE,EAAE,EAAE;YACT,IAAI;YACJ,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,IAAI,aAAa,EAAE;YACjB,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,aAAa,CAAC;SACzC;QACD,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,CAAC,IAA2B,EAAE,IAAI,GAAG,qBAAqB,EAAE,UAAmB;QAC3F,MAAM,IAAI,GAAoB;YAC5B,IAAI,EAAE,IAAI;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,IAAI;aACX;YACD,GAAG,EAAE,EAAE,EAAE;YACT,IAAI;YACJ,IAAI,EAAE,KAAK;SACZ,CAAC;QACF,IAAI,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ACT,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;SACjD;QACD,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE;YACjC,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;YACrB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAc,CAAC;YACjC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;SAClC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAoB;YAC9B,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACpC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,KAAK;SACZ,CAAC;QAEF,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,EAAE;YACvC,MAAM,KAAK,GAAI,MAAqC,CAAC;YACrD,KAAK,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACnD;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.6.23",
4
+ "version": "0.6.26",
5
5
  "license": "Apache-2.0",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -113,11 +113,23 @@ export interface ContextDeleteEventDetail {
113
113
  parent?: string;
114
114
  }
115
115
 
116
+ export interface ContextDeleteBulkEventDetail {
117
+ /**
118
+ * The list of ids of the domain object to remove.
119
+ */
120
+ ids: string[];
121
+ /**
122
+ * The id of the parent object, if applicable.
123
+ */
124
+ parent?: string;
125
+ }
126
+
116
127
  /**
117
128
  * An event to be used to delete a state in the context provider.
118
129
  */
119
130
  export class ContextDeleteEvent extends ContextEvent<ContextDeleteEventDetail, ContextDeleteRecord> {
120
131
  /**
132
+ * An event to be used to delete a state in the context provider.
121
133
  * @param type The type of the event to dispatch.
122
134
  * @param id The id of the object to delete
123
135
  * @param parent The id of the parent object, if applicable.
@@ -127,6 +139,21 @@ export class ContextDeleteEvent extends ContextEvent<ContextDeleteEventDetail, C
127
139
  }
128
140
  }
129
141
 
142
+ /**
143
+ * An event to be used to delete a number of entities in the context provider.
144
+ */
145
+ export class ContextDeleteBulkEvent extends ContextEvent<ContextDeleteBulkEventDetail, ContextDeleteRecord[]> {
146
+ /**
147
+ * An event to be used to delete a number of entities in the context provider.
148
+ * @param type The type of the event to dispatch.
149
+ * @param ids The list of ids of the domain object to remove.
150
+ * @param parent The id of the parent object, if applicable.
151
+ */
152
+ constructor(type: string, ids: string[], parent?: string) {
153
+ super(type, { ids, parent });
154
+ }
155
+ }
156
+
130
157
  export interface ContextDeleteRecord {
131
158
  /**
132
159
  * The data kind of the deleted item.
@@ -143,6 +170,23 @@ export interface ContextDeleteRecord {
143
170
  parent?: string;
144
171
  }
145
172
 
173
+ /**
174
+ * An event dispatched to the context store to restore previously deleted items.
175
+ */
176
+ export class ContextRestoreEvent<T> extends ContextEvent<ContextDeleteRecord[], ContextChangeRecord<T>[]> {
177
+ /**
178
+ * An event dispatched to the context store to restore previously deleted items.
179
+ *
180
+ * The result of the event is the list of `ContextChangeRecord` for the restored items.
181
+ *
182
+ * @param type The type of the event.
183
+ * @param records The records of previously deleted items.
184
+ */
185
+ constructor(type: string, records: ContextDeleteRecord[]) {
186
+ super(type, records);
187
+ }
188
+ }
189
+
146
190
  /**
147
191
  * An event dispatched when a context store object has been deleted.
148
192
  * In general a single context store uses the same event to dispatch the change record.
@@ -193,18 +237,59 @@ export interface ContextUpdateEventDetail<T> {
193
237
  parent?: string;
194
238
  }
195
239
 
240
+ export interface ContextUpdateBulkEventDetail<T> {
241
+ /**
242
+ * The list of context store objects to be updated by the context provider.
243
+ */
244
+ items: T[];
245
+ /**
246
+ * The id of the parent object, if applicable.
247
+ */
248
+ parent?: string;
249
+ }
250
+
196
251
  /**
197
252
  * An event that is dispatched to update the entire object in the store.
198
253
  * This is equivalent to PUT operation in REST HTTP.
199
254
  *
200
255
  * @template T The object that is being updated.
256
+ * @template U The object that is returned by the context store after updating. By default it is the `T`.
201
257
  */
202
258
  export class ContextUpdateEvent<T extends object, U = T> extends ContextEvent<ContextUpdateEventDetail<T>, ContextChangeRecord<U>> {
259
+ /**
260
+ * An event that is dispatched to update the entire object in the store.
261
+ * This is equivalent to PUT operation in REST HTTP.
262
+ *
263
+ * @param type The type of the event to dispatch
264
+ * @param updateInfo The update information.
265
+ */
203
266
  constructor(type: string, updateInfo: ContextUpdateEventDetail<T>) {
204
267
  super(type, updateInfo);
205
268
  }
206
269
  }
207
270
 
271
+ /**
272
+ * An event that is dispatched to update a list of objects in the store.
273
+ * This is equivalent to PUT operation in REST HTTP.
274
+ *
275
+ * If there's a parent, this event only allows to update entities in bulk for the same parent.
276
+ *
277
+ * @template T The object that is being updated.
278
+ * @template U The object that is returned by the context store after updating. By default it is the `T`.
279
+ */
280
+ export class ContextUpdateBulkEvent<T extends object, U = T> extends ContextEvent<ContextUpdateBulkEventDetail<T>, ContextChangeRecord<U>[]> {
281
+ /**
282
+ * An event that is dispatched to update the entire object in the store.
283
+ * This is equivalent to PUT operation in REST HTTP.
284
+ *
285
+ * @param type The type of the event to dispatch
286
+ * @param updateInfo The update information.
287
+ */
288
+ constructor(type: string, updateInfo: ContextUpdateBulkEventDetail<T>) {
289
+ super(type, updateInfo);
290
+ }
291
+ }
292
+
208
293
  /**
209
294
  * Data store query result object.
210
295
  */
@@ -244,3 +329,53 @@ export class ContextListEvent<T> extends ContextEvent<ContextListOptions, Contex
244
329
  super(type, opts);
245
330
  }
246
331
  }
332
+
333
+ export interface IQueryDetail {
334
+ /**
335
+ * The query term. All values are always passed as string. Context store must parse value if it requires other types.
336
+ */
337
+ term: string;
338
+
339
+ /**
340
+ * If the context store supports it, the tags to use with the query function to limit the results.
341
+ */
342
+ tags?: string[];
343
+
344
+ /**
345
+ * General purpose type to be defined by the context store.
346
+ * Allows to specify the type of the query to perform.
347
+ */
348
+ type?: string;
349
+
350
+ /**
351
+ * General purpose keyword to be defined by the context store.
352
+ * The purpose is to instruct the context store to perform detailed search.
353
+ * Usually this means longer search time but more accurate results.
354
+ */
355
+ detailed?: boolean;
356
+ }
357
+
358
+ /**
359
+ * An event dispatched to the context store to perform a query operation.
360
+ * If the context store supports the query operation, it should use the definition of `IQueryDetail` to perform the query.
361
+ * The result is the list of objects ordered by the store from the most relevant items to the least.
362
+ *
363
+ * The implementation should not assume pagination and return enough results for the user to find what they were looking for
364
+ * or to redefine the query. Suggested limit is `50` which in many cases is equivalent of 2 pages of results.
365
+ */
366
+ export class ContextQueryEvent<T = unknown> extends ContextEvent<IQueryDetail, T[]> {
367
+ /**
368
+ * An event dispatched to the context store to perform a query operation.
369
+ * If the context store supports the query operation, it should use the definition of `IQueryDetail` to perform the query.
370
+ * The result is the list of objects ordered by the store from the most relevant items to the least.
371
+ *
372
+ * The implementation should not assume pagination and return enough results for the user to find what they were looking for
373
+ * or to redefine the query. Suggested limit is `50` which in many cases is equivalent of 2 pages of results.
374
+ *
375
+ * @param type The type of the event.
376
+ * @param opts The query options.
377
+ */
378
+ constructor(type: string, opts: IQueryDetail) {
379
+ super(type, opts);
380
+ }
381
+ }
@@ -1,5 +1,6 @@
1
1
  import { base64ToBuffer, bufferToBase64 } from '../lib/Buffer.js';
2
2
  import v4 from '../lib/uuid.js';
3
+ import { Certificate as LegacyCertificate, ARCCertificateIndex, RequestCertificate } from './legacy/models/ClientCertificate.js';
3
4
 
4
5
  export type CertificateType = 'p12' | 'pem';
5
6
 
@@ -77,15 +78,15 @@ export interface IPemCreateOptions {
77
78
  /**
78
79
  * The certificate contents.
79
80
  */
80
- cert: CertificateDataFormat;
81
+ cert: CertificateDataFormat;
81
82
  /**
82
83
  * The key contents.
83
84
  */
84
- key: CertificateDataFormat;
85
+ key: CertificateDataFormat;
85
86
  /**
86
87
  * Optional name for the certificate.
87
88
  */
88
- name?: string;
89
+ name?: string;
89
90
  /**
90
91
  * Optional passphrase for the key.
91
92
  */
@@ -101,7 +102,7 @@ export interface IP12CreateOptions {
101
102
  /**
102
103
  * Optional name for the certificate.
103
104
  */
104
- name?: string;
105
+ name?: string;
105
106
  /**
106
107
  * Optional passphrase for the certificate.
107
108
  */
@@ -140,7 +141,7 @@ export class Certificate {
140
141
  * The key for the `pem` type certificate.
141
142
  */
142
143
  certKey?: ICertificateData;
143
-
144
+
144
145
  /**
145
146
  * Creates a new certificate instance for a PEM key
146
147
  *
@@ -191,17 +192,55 @@ export class Certificate {
191
192
  return new Certificate(init);
192
193
  }
193
194
 
195
+ /**
196
+ * Creates a certificate object from the ARC's legacy certificate definition.
197
+ *
198
+ * @param index The legacy certificate index object. If it has set `_id` it will be used as the `key`.
199
+ * @param index The certificate data object as read from the data store. Do not restore the data to its original format.
200
+ */
201
+ static fromLegacy(index: ARCCertificateIndex, cert: RequestCertificate): Certificate {
202
+ const { name = '', type, created = Date.now(), _id = v4() } = index;
203
+ if (type === 'pem') {
204
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
205
+ const key = Array.isArray(cert.key) ? cert.key[0] : cert.key as LegacyCertificate;
206
+ if (!key) {
207
+ throw new Error(`Unable to create a PEM certificate without the key.`);
208
+ }
209
+ const init: IPemCertificate = {
210
+ kind: Kind,
211
+ cert: data as ICertificateData, // these are compatible.
212
+ certKey: key as ICertificateData,
213
+ key: _id,
214
+ name,
215
+ type: 'pem',
216
+ created,
217
+ };
218
+ return new Certificate(init);
219
+ } else if (type === 'p12') {
220
+ const data = Array.isArray(cert.cert) ? cert.cert[0] : cert.cert;
221
+ const init: IP12Certificate = {
222
+ kind: Kind,
223
+ cert: data as ICertificateData, // these are compatible.
224
+ key: _id,
225
+ name,
226
+ type: 'p12',
227
+ };
228
+ return new Certificate(init);
229
+ }
230
+ throw new Error(`Unable to create a certificate. Unknown type: ${type}.`);
231
+ }
232
+
194
233
  constructor(certificate: HttpCertificate) {
195
- const { type, cert, key=v4(), name='', created } = certificate;
234
+ const { type, cert, key = v4(), name = '', created } = certificate;
196
235
  this.key = key;
197
236
  this.name = name;
198
237
  this.type = type;
199
- this.cert = this.fromStore(cert);
238
+ this.cert = Certificate.fromStore(cert);
200
239
  if (typeof created === 'number') {
201
240
  this.created = created;
202
241
  }
203
242
  if (type === 'pem') {
204
- this.certKey = this.fromStore(certificate.certKey);
243
+ this.certKey = Certificate.fromStore(certificate.certKey);
205
244
  }
206
245
  }
207
246
 
@@ -210,7 +249,7 @@ export class Certificate {
210
249
  * @param data The certificate data.
211
250
  * @returns The restored certificate.
212
251
  */
213
- fromStore(data: ICertificateData): ICertificateData {
252
+ static fromStore(data: ICertificateData): ICertificateData {
214
253
  if (data.type) {
215
254
  delete data.type;
216
255
  const content = data.data as string;
@@ -233,7 +272,7 @@ export class Certificate {
233
272
  * @param data The certificate data object.
234
273
  * @throws When data is not set
235
274
  */
236
- toStore(data: ICertificateData): ICertificateData {
275
+ static toStore(data: ICertificateData): ICertificateData {
237
276
  if (!data) {
238
277
  throw new Error('Certificate data is missing.');
239
278
  }
@@ -252,14 +291,14 @@ export class Certificate {
252
291
  const result: IP12Certificate = {
253
292
  kind: Kind,
254
293
  key: this.key,
255
- cert: this.toStore(this.cert),
294
+ cert: Certificate.toStore(this.cert),
256
295
  name: this.name,
257
296
  type: 'p12',
258
297
  };
259
298
 
260
299
  if (this.type === 'pem' && this.certKey) {
261
300
  const typed = (result as unknown) as IPemCertificate;
262
- typed.certKey = this.toStore(this.certKey);
301
+ typed.certKey = Certificate.toStore(this.certKey);
263
302
  }
264
303
 
265
304
  return result;