@openfn/language-collections 0.6.1 → 0.7.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 +14 -4
- package/dist/index.js +14 -4
- package/package.json +1 -1
- package/types/mock.d.ts +2 -0
package/dist/index.cjs
CHANGED
|
@@ -271,6 +271,7 @@ function createServer(url = "https://app.openfn.org") {
|
|
|
271
271
|
mockPool.intercept({ method: "delete", path: /collections\/./ }).reply(remove2).persist();
|
|
272
272
|
return {
|
|
273
273
|
api,
|
|
274
|
+
agent,
|
|
274
275
|
request: ({ method, path, data, ...rest }) => {
|
|
275
276
|
const opts = {
|
|
276
277
|
method,
|
|
@@ -384,10 +385,19 @@ function set(name, keyGen, values) {
|
|
|
384
385
|
} else {
|
|
385
386
|
const dataArray = Array.isArray(resolvedValues) ? resolvedValues : [resolvedValues];
|
|
386
387
|
const keyGenFn = typeof keyGen === "string" ? () => keyGen : keyGen;
|
|
387
|
-
kvPairs = dataArray.map((value, index) =>
|
|
388
|
-
key
|
|
389
|
-
|
|
390
|
-
|
|
388
|
+
kvPairs = dataArray.map((value, index) => {
|
|
389
|
+
const key = keyGenFn(value, state, index);
|
|
390
|
+
if (typeof key !== "string") {
|
|
391
|
+
const e = new Error("KEYGEN_ERROR");
|
|
392
|
+
e.description = "The key generator function returned a non-string value which is not a valid key";
|
|
393
|
+
e.fix = `The second argument to set() is a key or key-generator function. If you pass a function, make sure the function returns a string (a key). Note that this function is NOT a state reference and does not support lazy state ($)`;
|
|
394
|
+
throw e;
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
key,
|
|
398
|
+
value: JSON.stringify(value)
|
|
399
|
+
};
|
|
400
|
+
});
|
|
391
401
|
}
|
|
392
402
|
while (kvPairs.length) {
|
|
393
403
|
const batch = kvPairs.splice(0, batchSize);
|
package/dist/index.js
CHANGED
|
@@ -246,6 +246,7 @@ function createServer(url = "https://app.openfn.org") {
|
|
|
246
246
|
mockPool.intercept({ method: "delete", path: /collections\/./ }).reply(remove2).persist();
|
|
247
247
|
return {
|
|
248
248
|
api,
|
|
249
|
+
agent,
|
|
249
250
|
request: ({ method, path, data, ...rest }) => {
|
|
250
251
|
const opts = {
|
|
251
252
|
method,
|
|
@@ -359,10 +360,19 @@ function set(name, keyGen, values) {
|
|
|
359
360
|
} else {
|
|
360
361
|
const dataArray = Array.isArray(resolvedValues) ? resolvedValues : [resolvedValues];
|
|
361
362
|
const keyGenFn = typeof keyGen === "string" ? () => keyGen : keyGen;
|
|
362
|
-
kvPairs = dataArray.map((value, index) =>
|
|
363
|
-
key
|
|
364
|
-
|
|
365
|
-
|
|
363
|
+
kvPairs = dataArray.map((value, index) => {
|
|
364
|
+
const key = keyGenFn(value, state, index);
|
|
365
|
+
if (typeof key !== "string") {
|
|
366
|
+
const e = new Error("KEYGEN_ERROR");
|
|
367
|
+
e.description = "The key generator function returned a non-string value which is not a valid key";
|
|
368
|
+
e.fix = `The second argument to set() is a key or key-generator function. If you pass a function, make sure the function returns a string (a key). Note that this function is NOT a state reference and does not support lazy state ($)`;
|
|
369
|
+
throw e;
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
key,
|
|
373
|
+
value: JSON.stringify(value)
|
|
374
|
+
};
|
|
375
|
+
});
|
|
366
376
|
}
|
|
367
377
|
while (kvPairs.length) {
|
|
368
378
|
const batch = kvPairs.splice(0, batchSize);
|
package/package.json
CHANGED
package/types/mock.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export function API(): {
|
|
|
17
17
|
};
|
|
18
18
|
export function createServer(url?: string): {
|
|
19
19
|
api: any;
|
|
20
|
+
agent: MockAgent<MockAgent.Options>;
|
|
20
21
|
request: ({ method, path, data, ...rest }: {
|
|
21
22
|
[x: string]: any;
|
|
22
23
|
method: any;
|
|
@@ -24,3 +25,4 @@ export function createServer(url?: string): {
|
|
|
24
25
|
data: any;
|
|
25
26
|
}) => Promise<import("undici/types/dispatcher").default.ResponseData>;
|
|
26
27
|
};
|
|
28
|
+
import { MockAgent } from "undici/types";
|