@openfn/language-collections 0.3.0 → 0.4.0
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/dist/index.cjs +30 -15
- package/dist/index.js +30 -15
- package/package.json +1 -1
- package/types/mock.d.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -98,8 +98,15 @@ function API() {
|
|
|
98
98
|
throw new Error(COLLECTION_NOT_FOUND);
|
|
99
99
|
}
|
|
100
100
|
const col = collections[name];
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const regex = new RegExp(key.replace("*", "(.*)"));
|
|
102
|
+
const removed = [];
|
|
103
|
+
for (const key2 in col) {
|
|
104
|
+
if (regex.test(key2)) {
|
|
105
|
+
delete col[key2];
|
|
106
|
+
removed.push(key2);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return removed;
|
|
103
110
|
};
|
|
104
111
|
const api = {
|
|
105
112
|
collections,
|
|
@@ -211,7 +218,11 @@ function createServer(url = "https://app.openfn.org") {
|
|
|
211
218
|
return { statusCode: 403 };
|
|
212
219
|
}
|
|
213
220
|
try {
|
|
214
|
-
|
|
221
|
+
let { name, key } = parsePath(req.path);
|
|
222
|
+
if (!key) {
|
|
223
|
+
const params = new URLSearchParams(req.query || req.path.split("?")[1]);
|
|
224
|
+
key = params.get("key") ?? "*";
|
|
225
|
+
}
|
|
215
226
|
const keys = api.remove(name, key);
|
|
216
227
|
return {
|
|
217
228
|
statusCode: 200,
|
|
@@ -346,19 +357,24 @@ function set(name, keyGen, values) {
|
|
|
346
357
|
}
|
|
347
358
|
function remove(name, query = {}, options = {}) {
|
|
348
359
|
return async (state) => {
|
|
349
|
-
|
|
360
|
+
let [resolvedName, resolvedQuery] = (0, import_util.expandReferences)(state, name, query);
|
|
361
|
+
if (typeof resolvedQuery === "string") {
|
|
362
|
+
resolvedQuery = { key: resolvedQuery };
|
|
363
|
+
}
|
|
350
364
|
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
let q;
|
|
366
|
+
let path = resolvedName;
|
|
367
|
+
if (key.match(/\*/) || Object.keys(rest).length) {
|
|
368
|
+
q = resolvedQuery;
|
|
369
|
+
} else {
|
|
370
|
+
path = `${resolvedName}/${key}`;
|
|
371
|
+
}
|
|
372
|
+
const response = await request(state, getClient(state), path, {
|
|
373
|
+
method: "DELETE",
|
|
374
|
+
query: q
|
|
375
|
+
});
|
|
360
376
|
const result = await response.body.json();
|
|
361
|
-
console.log(`
|
|
377
|
+
console.log(`Removed ${result.deleted} values in collection "${name}"`);
|
|
362
378
|
return state;
|
|
363
379
|
};
|
|
364
380
|
}
|
|
@@ -376,7 +392,6 @@ function each(name, query = {}, callback = () => {
|
|
|
376
392
|
const response = await request(state, getClient(state), resolvedName, {
|
|
377
393
|
query: q
|
|
378
394
|
});
|
|
379
|
-
console.log(`each response`, response.statusCode);
|
|
380
395
|
const cursor = await streamResponse(response, async ({ value, key: key2 }) => {
|
|
381
396
|
await callback(state, JSON.parse(value), key2);
|
|
382
397
|
});
|
package/dist/index.js
CHANGED
|
@@ -73,8 +73,15 @@ function API() {
|
|
|
73
73
|
throw new Error(COLLECTION_NOT_FOUND);
|
|
74
74
|
}
|
|
75
75
|
const col = collections[name];
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const regex = new RegExp(key.replace("*", "(.*)"));
|
|
77
|
+
const removed = [];
|
|
78
|
+
for (const key2 in col) {
|
|
79
|
+
if (regex.test(key2)) {
|
|
80
|
+
delete col[key2];
|
|
81
|
+
removed.push(key2);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return removed;
|
|
78
85
|
};
|
|
79
86
|
const api = {
|
|
80
87
|
collections,
|
|
@@ -186,7 +193,11 @@ function createServer(url = "https://app.openfn.org") {
|
|
|
186
193
|
return { statusCode: 403 };
|
|
187
194
|
}
|
|
188
195
|
try {
|
|
189
|
-
|
|
196
|
+
let { name, key } = parsePath(req.path);
|
|
197
|
+
if (!key) {
|
|
198
|
+
const params = new URLSearchParams(req.query || req.path.split("?")[1]);
|
|
199
|
+
key = params.get("key") ?? "*";
|
|
200
|
+
}
|
|
190
201
|
const keys = api.remove(name, key);
|
|
191
202
|
return {
|
|
192
203
|
statusCode: 200,
|
|
@@ -321,19 +332,24 @@ function set(name, keyGen, values) {
|
|
|
321
332
|
}
|
|
322
333
|
function remove(name, query = {}, options = {}) {
|
|
323
334
|
return async (state) => {
|
|
324
|
-
|
|
335
|
+
let [resolvedName, resolvedQuery] = expandReferences(state, name, query);
|
|
336
|
+
if (typeof resolvedQuery === "string") {
|
|
337
|
+
resolvedQuery = { key: resolvedQuery };
|
|
338
|
+
}
|
|
325
339
|
const { key, ...rest } = expandQuery(resolvedQuery);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
340
|
+
let q;
|
|
341
|
+
let path = resolvedName;
|
|
342
|
+
if (key.match(/\*/) || Object.keys(rest).length) {
|
|
343
|
+
q = resolvedQuery;
|
|
344
|
+
} else {
|
|
345
|
+
path = `${resolvedName}/${key}`;
|
|
346
|
+
}
|
|
347
|
+
const response = await request(state, getClient(state), path, {
|
|
348
|
+
method: "DELETE",
|
|
349
|
+
query: q
|
|
350
|
+
});
|
|
335
351
|
const result = await response.body.json();
|
|
336
|
-
console.log(`
|
|
352
|
+
console.log(`Removed ${result.deleted} values in collection "${name}"`);
|
|
337
353
|
return state;
|
|
338
354
|
};
|
|
339
355
|
}
|
|
@@ -351,7 +367,6 @@ function each(name, query = {}, callback = () => {
|
|
|
351
367
|
const response = await request(state, getClient(state), resolvedName, {
|
|
352
368
|
query: q
|
|
353
369
|
});
|
|
354
|
-
console.log(`each response`, response.statusCode);
|
|
355
370
|
const cursor = await streamResponse(response, async ({ value, key: key2 }) => {
|
|
356
371
|
await callback(state, JSON.parse(value), key2);
|
|
357
372
|
});
|
package/package.json
CHANGED