@openfn/language-collections 1.0.0-next-13f27ea6 → 1.0.0-next-4f38509f
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 +5 -13
- package/dist/index.cjs +27 -8
- package/dist/index.js +27 -8
- package/package.json +1 -1
- package/types/collections.d.ts +1 -0
package/README.md
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
# language-collections <img src='./assets/square.png' width="30" height="30"/>
|
|
2
2
|
|
|
3
|
-
An OpenFn **_adaptor_** for building integration jobs for use with the
|
|
3
|
+
An OpenFn **_adaptor_** for building integration jobs for use with the
|
|
4
|
+
collections API.
|
|
5
|
+
|
|
6
|
+
The collections API is not designed to be used alone, but in conjunction with
|
|
7
|
+
other adaptors.
|
|
4
8
|
|
|
5
9
|
## Documentation
|
|
6
10
|
|
|
7
11
|
View the [docs site](https://docs.openfn.org/adaptors/packages/collections-docs)
|
|
8
12
|
for full technical documentation.
|
|
9
13
|
|
|
10
|
-
### Configuration
|
|
11
|
-
|
|
12
|
-
View the
|
|
13
|
-
[configuration-schema](https://docs.openfn.org/adaptors/packages/collections-configuration-schema/)
|
|
14
|
-
for required and optional `configuration` properties.
|
|
15
|
-
|
|
16
|
-
### A example expression using the `create` function
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
post('patient', { name: 'Bukayo' });
|
|
20
|
-
```
|
|
21
|
-
|
|
22
14
|
## Development
|
|
23
15
|
|
|
24
16
|
Clone the [adaptors monorepo](https://github.com/OpenFn/adaptors). Follow the
|
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(collections_exports, {
|
|
|
36
36
|
each: () => each,
|
|
37
37
|
expandQuery: () => expandQuery,
|
|
38
38
|
get: () => get,
|
|
39
|
+
parseQuery: () => parseQuery,
|
|
39
40
|
remove: () => remove,
|
|
40
41
|
request: () => request,
|
|
41
42
|
set: () => set,
|
|
@@ -224,11 +225,12 @@ var setMockClient = (mockClient) => {
|
|
|
224
225
|
function get(name, query = {}) {
|
|
225
226
|
return async (state) => {
|
|
226
227
|
const [resolvedName, resolvedQuery] = (0, import_util.expandReferences)(state, name, query);
|
|
227
|
-
const { key } = expandQuery(resolvedQuery);
|
|
228
|
+
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
228
229
|
const response = await request(
|
|
229
230
|
state,
|
|
230
231
|
getClient(state),
|
|
231
|
-
`${resolvedName}/${key}
|
|
232
|
+
`${resolvedName}/${key}`,
|
|
233
|
+
{ query: rest }
|
|
232
234
|
);
|
|
233
235
|
let data;
|
|
234
236
|
if (!key.match(/\*/) || Object.keys(resolvedQuery).length === 0) {
|
|
@@ -270,13 +272,14 @@ function set(name, keyGen, values) {
|
|
|
270
272
|
function remove(name, query = {}, options = {}) {
|
|
271
273
|
return async (state) => {
|
|
272
274
|
const [resolvedName, resolvedQuery] = (0, import_util.expandReferences)(state, name, query);
|
|
273
|
-
const { key } = expandQuery(resolvedQuery);
|
|
275
|
+
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
274
276
|
const response = await request(
|
|
275
277
|
state,
|
|
276
278
|
getClient(state),
|
|
277
279
|
`${resolvedName}/${key}`,
|
|
278
280
|
{
|
|
279
|
-
method: "DELETE"
|
|
281
|
+
method: "DELETE",
|
|
282
|
+
query: rest
|
|
280
283
|
}
|
|
281
284
|
);
|
|
282
285
|
return state;
|
|
@@ -285,11 +288,12 @@ function remove(name, query = {}, options = {}) {
|
|
|
285
288
|
function each(name, query = {}, callback = {}) {
|
|
286
289
|
return async (state) => {
|
|
287
290
|
const [resolvedName, resolvedQuery] = (0, import_util.expandReferences)(state, name, query);
|
|
288
|
-
const { key } = expandQuery(resolvedQuery);
|
|
291
|
+
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
289
292
|
const response = await request(
|
|
290
293
|
state,
|
|
291
294
|
getClient(state),
|
|
292
|
-
`${resolvedName}/${key}
|
|
295
|
+
`${resolvedName}/${key}`,
|
|
296
|
+
{ query: rest }
|
|
293
297
|
);
|
|
294
298
|
await streamResponse(response, async ({ key: key2, value }) => {
|
|
295
299
|
await callback(state, value, key2);
|
|
@@ -318,6 +322,19 @@ var expandQuery = (query) => {
|
|
|
318
322
|
}
|
|
319
323
|
return query;
|
|
320
324
|
};
|
|
325
|
+
var queryMaps = {
|
|
326
|
+
createdBefore: "created_before",
|
|
327
|
+
createdAfter: "created_after",
|
|
328
|
+
updatedBefore: "updated_before",
|
|
329
|
+
updatedAfter: "updated_after"
|
|
330
|
+
};
|
|
331
|
+
var parseQuery = (options = {}) => {
|
|
332
|
+
return Object.keys(options.query ?? {}).reduce((result, next) => {
|
|
333
|
+
const key = queryMaps[next] ?? next;
|
|
334
|
+
result[key] = options.query[next];
|
|
335
|
+
return result;
|
|
336
|
+
}, {});
|
|
337
|
+
};
|
|
321
338
|
var request = (state, client2, path, options = {}) => {
|
|
322
339
|
if (!state.configuration.collections_token) {
|
|
323
340
|
(0, import_util.throwError)("INVALID_AUTH", {
|
|
@@ -330,12 +347,14 @@ var request = (state, client2, path, options = {}) => {
|
|
|
330
347
|
Authorization: `Bearer ${state.configuration.collections_token}`
|
|
331
348
|
};
|
|
332
349
|
Object.assign(headers, options == null ? void 0 : options.headers);
|
|
333
|
-
const { headers:
|
|
350
|
+
const { headers: _h, query: _q, ...otherOptions } = options;
|
|
351
|
+
const query = parseQuery(options.query);
|
|
334
352
|
return client2.request({
|
|
335
353
|
path: import_node_path.default.join("collections", path),
|
|
336
354
|
headers,
|
|
337
355
|
method: "GET",
|
|
338
|
-
|
|
356
|
+
query,
|
|
357
|
+
...otherOptions
|
|
339
358
|
});
|
|
340
359
|
};
|
|
341
360
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ __export(collections_exports, {
|
|
|
11
11
|
each: () => each,
|
|
12
12
|
expandQuery: () => expandQuery,
|
|
13
13
|
get: () => get,
|
|
14
|
+
parseQuery: () => parseQuery,
|
|
14
15
|
remove: () => remove,
|
|
15
16
|
request: () => request,
|
|
16
17
|
set: () => set,
|
|
@@ -199,11 +200,12 @@ var setMockClient = (mockClient) => {
|
|
|
199
200
|
function get(name, query = {}) {
|
|
200
201
|
return async (state) => {
|
|
201
202
|
const [resolvedName, resolvedQuery] = expandReferences(state, name, query);
|
|
202
|
-
const { key } = expandQuery(resolvedQuery);
|
|
203
|
+
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
203
204
|
const response = await request(
|
|
204
205
|
state,
|
|
205
206
|
getClient(state),
|
|
206
|
-
`${resolvedName}/${key}
|
|
207
|
+
`${resolvedName}/${key}`,
|
|
208
|
+
{ query: rest }
|
|
207
209
|
);
|
|
208
210
|
let data;
|
|
209
211
|
if (!key.match(/\*/) || Object.keys(resolvedQuery).length === 0) {
|
|
@@ -245,13 +247,14 @@ function set(name, keyGen, values) {
|
|
|
245
247
|
function remove(name, query = {}, options = {}) {
|
|
246
248
|
return async (state) => {
|
|
247
249
|
const [resolvedName, resolvedQuery] = expandReferences(state, name, query);
|
|
248
|
-
const { key } = expandQuery(resolvedQuery);
|
|
250
|
+
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
249
251
|
const response = await request(
|
|
250
252
|
state,
|
|
251
253
|
getClient(state),
|
|
252
254
|
`${resolvedName}/${key}`,
|
|
253
255
|
{
|
|
254
|
-
method: "DELETE"
|
|
256
|
+
method: "DELETE",
|
|
257
|
+
query: rest
|
|
255
258
|
}
|
|
256
259
|
);
|
|
257
260
|
return state;
|
|
@@ -260,11 +263,12 @@ function remove(name, query = {}, options = {}) {
|
|
|
260
263
|
function each(name, query = {}, callback = {}) {
|
|
261
264
|
return async (state) => {
|
|
262
265
|
const [resolvedName, resolvedQuery] = expandReferences(state, name, query);
|
|
263
|
-
const { key } = expandQuery(resolvedQuery);
|
|
266
|
+
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
264
267
|
const response = await request(
|
|
265
268
|
state,
|
|
266
269
|
getClient(state),
|
|
267
|
-
`${resolvedName}/${key}
|
|
270
|
+
`${resolvedName}/${key}`,
|
|
271
|
+
{ query: rest }
|
|
268
272
|
);
|
|
269
273
|
await streamResponse(response, async ({ key: key2, value }) => {
|
|
270
274
|
await callback(state, value, key2);
|
|
@@ -293,6 +297,19 @@ var expandQuery = (query) => {
|
|
|
293
297
|
}
|
|
294
298
|
return query;
|
|
295
299
|
};
|
|
300
|
+
var queryMaps = {
|
|
301
|
+
createdBefore: "created_before",
|
|
302
|
+
createdAfter: "created_after",
|
|
303
|
+
updatedBefore: "updated_before",
|
|
304
|
+
updatedAfter: "updated_after"
|
|
305
|
+
};
|
|
306
|
+
var parseQuery = (options = {}) => {
|
|
307
|
+
return Object.keys(options.query ?? {}).reduce((result, next) => {
|
|
308
|
+
const key = queryMaps[next] ?? next;
|
|
309
|
+
result[key] = options.query[next];
|
|
310
|
+
return result;
|
|
311
|
+
}, {});
|
|
312
|
+
};
|
|
296
313
|
var request = (state, client2, path, options = {}) => {
|
|
297
314
|
if (!state.configuration.collections_token) {
|
|
298
315
|
throwError("INVALID_AUTH", {
|
|
@@ -305,12 +322,14 @@ var request = (state, client2, path, options = {}) => {
|
|
|
305
322
|
Authorization: `Bearer ${state.configuration.collections_token}`
|
|
306
323
|
};
|
|
307
324
|
Object.assign(headers, options == null ? void 0 : options.headers);
|
|
308
|
-
const { headers:
|
|
325
|
+
const { headers: _h, query: _q, ...otherOptions } = options;
|
|
326
|
+
const query = parseQuery(options.query);
|
|
309
327
|
return client2.request({
|
|
310
328
|
path: nodepath.join("collections", path),
|
|
311
329
|
headers,
|
|
312
330
|
method: "GET",
|
|
313
|
-
|
|
331
|
+
query,
|
|
332
|
+
...otherOptions
|
|
314
333
|
});
|
|
315
334
|
};
|
|
316
335
|
export {
|
package/package.json
CHANGED
package/types/collections.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export { createServer as createMockServer };
|
|
|
85
85
|
export function setMockClient(mockClient: any): void;
|
|
86
86
|
export function streamResponse(response: any, onValue: any): Promise<void>;
|
|
87
87
|
export function expandQuery(query: any): any;
|
|
88
|
+
export function parseQuery(options?: {}): {};
|
|
88
89
|
export function request(state: any, client: any, path: any, options?: {}): any;
|
|
89
90
|
/**
|
|
90
91
|
* Query options. All dates should be parseable as ISO 8601 strings, see https://simple.wikipedia.org/wiki/ISO_8601
|