chainflow 0.1.9 → 5.0.3
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.
Potentially problematic release.
This version of chainflow might be problematic. Click here for more details.
- package/.idea/codeStyles/Project.xml +27 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/dotenv-master.iml +12 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.vscode/settings.json +2 -0
- package/CHANGELOG.md +431 -0
- package/LICENSE +23 -21
- package/README-es.md +442 -0
- package/README.md +633 -599
- package/config.d.ts +1 -0
- package/config.js +9 -0
- package/index.js +35 -0
- package/lib/cli-options.js +11 -0
- package/lib/env-options.js +24 -0
- package/lib/main.d.ts +156 -0
- package/lib/main.js +314 -0
- package/package.json +56 -52
- package/pk.json +64 -0
- package/dist/core/chainflow.d.ts +0 -47
- package/dist/core/chainflow.js +0 -116
- package/dist/core/chainflow.js.map +0 -1
- package/dist/core/inputNode.d.ts +0 -34
- package/dist/core/inputNode.js +0 -218
- package/dist/core/inputNode.js.map +0 -1
- package/dist/core/logger.d.ts +0 -4
- package/dist/core/logger.js +0 -19
- package/dist/core/logger.js.map +0 -1
- package/dist/core/sourceNode.d.ts +0 -24
- package/dist/core/sourceNode.js +0 -37
- package/dist/core/sourceNode.js.map +0 -1
- package/dist/core/store.d.ts +0 -13
- package/dist/core/store.js +0 -91
- package/dist/core/store.js.map +0 -1
- package/dist/core/utils/config.d.ts +0 -16
- package/dist/core/utils/config.js +0 -13
- package/dist/core/utils/config.js.map +0 -1
- package/dist/core/utils/constants.d.ts +0 -2
- package/dist/core/utils/constants.js +0 -6
- package/dist/core/utils/constants.js.map +0 -1
- package/dist/core/utils/initializers.d.ts +0 -12
- package/dist/core/utils/initializers.js +0 -18
- package/dist/core/utils/initializers.js.map +0 -1
- package/dist/core/utils/link.d.ts +0 -65
- package/dist/core/utils/link.js +0 -34
- package/dist/core/utils/link.js.map +0 -1
- package/dist/core/utils/symbols.d.ts +0 -7
- package/dist/core/utils/symbols.js +0 -11
- package/dist/core/utils/symbols.js.map +0 -1
- package/dist/http/endpoint.d.ts +0 -68
- package/dist/http/endpoint.js +0 -222
- package/dist/http/endpoint.js.map +0 -1
- package/dist/http/errors.d.ts +0 -16
- package/dist/http/errors.js +0 -36
- package/dist/http/errors.js.map +0 -1
- package/dist/http/logger.d.ts +0 -4
- package/dist/http/logger.js +0 -21
- package/dist/http/logger.js.map +0 -1
- package/dist/http/origin.d.ts +0 -29
- package/dist/http/origin.js +0 -62
- package/dist/http/origin.js.map +0 -1
- package/dist/http/reqBuilder.d.ts +0 -14
- package/dist/http/reqBuilder.js +0 -50
- package/dist/http/reqBuilder.js.map +0 -1
- package/dist/http/utils/client.d.ts +0 -27
- package/dist/http/utils/client.js +0 -88
- package/dist/http/utils/client.js.map +0 -1
- package/dist/http/utils/constants.d.ts +0 -2
- package/dist/http/utils/constants.js +0 -12
- package/dist/http/utils/constants.js.map +0 -1
- package/dist/http/utils/id.d.ts +0 -5
- package/dist/http/utils/id.js +0 -9
- package/dist/http/utils/id.js.map +0 -1
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -1
package/dist/core/store.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var _Store_instances, _Store_store, _Store_getStoreValue, _Store_accessRespValue, _Store_putInStore;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Store = void 0;
|
|
16
|
-
const symbols_1 = require("./utils/symbols");
|
|
17
|
-
/** Manages the storing of values for an endpoint. */
|
|
18
|
-
class Store {
|
|
19
|
-
constructor() {
|
|
20
|
-
_Store_instances.add(this);
|
|
21
|
-
/** Definition of values to be stored from responses to this endpoint. */
|
|
22
|
-
this.def = {};
|
|
23
|
-
/** Actual store of values received */
|
|
24
|
-
_Store_store.set(this, {});
|
|
25
|
-
}
|
|
26
|
-
/** Assigns values to be put in the chainflow's store. */
|
|
27
|
-
storeValues(resp) {
|
|
28
|
-
Object.entries(this.def).map(([key, val]) => {
|
|
29
|
-
if (val[symbols_1.nodePath]) {
|
|
30
|
-
// SourceNode
|
|
31
|
-
const { found, value, storePath } = __classPrivateFieldGet(this, _Store_instances, "m", _Store_accessRespValue).call(this, resp, [key], val);
|
|
32
|
-
if (found && storePath)
|
|
33
|
-
__classPrivateFieldGet(this, _Store_instances, "m", _Store_putInStore).call(this, storePath, value);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
// a nested store value
|
|
37
|
-
__classPrivateFieldGet(this, _Store_instances, "m", _Store_getStoreValue).call(this, resp, [key], val);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
const store = __classPrivateFieldGet(this, _Store_store, "f");
|
|
41
|
-
__classPrivateFieldSet(this, _Store_store, {}, "f"); // resets the store
|
|
42
|
-
return store;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
exports.Store = Store;
|
|
46
|
-
_Store_store = new WeakMap(), _Store_instances = new WeakSet(), _Store_getStoreValue = function _Store_getStoreValue(resp, currentPath, storeDef) {
|
|
47
|
-
Object.entries(storeDef).map(([key, val]) => {
|
|
48
|
-
if (val[symbols_1.nodePath]) {
|
|
49
|
-
// SourceNode
|
|
50
|
-
const { found, value, storePath } = __classPrivateFieldGet(this, _Store_instances, "m", _Store_accessRespValue).call(this, resp, [...currentPath, key], val);
|
|
51
|
-
if (found && storePath)
|
|
52
|
-
__classPrivateFieldGet(this, _Store_instances, "m", _Store_putInStore).call(this, storePath, value);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
// a nested store value
|
|
56
|
-
__classPrivateFieldGet(this, _Store_instances, "m", _Store_getStoreValue).call(this, resp, [...currentPath, key], val);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}, _Store_accessRespValue = function _Store_accessRespValue(resp, storePath, source) {
|
|
60
|
-
const sourcePath = source[symbols_1.nodePath];
|
|
61
|
-
let sourceVal = resp;
|
|
62
|
-
let i = 0;
|
|
63
|
-
while (i < sourcePath.length) {
|
|
64
|
-
// recall that `typeof null` returns 'object'
|
|
65
|
-
if (sourceVal == null || typeof sourceVal !== 'object') {
|
|
66
|
-
if (source[symbols_1.allowUndefined])
|
|
67
|
-
return { found: true, value: sourceVal, storePath };
|
|
68
|
-
return { found: false };
|
|
69
|
-
}
|
|
70
|
-
const accessor = sourcePath[i];
|
|
71
|
-
sourceVal = sourceVal[accessor];
|
|
72
|
-
i += 1;
|
|
73
|
-
}
|
|
74
|
-
return { found: true, value: sourceVal, storePath };
|
|
75
|
-
}, _Store_putInStore = function _Store_putInStore(storePath, value) {
|
|
76
|
-
let storeNode = __classPrivateFieldGet(this, _Store_store, "f");
|
|
77
|
-
let accessor;
|
|
78
|
-
for (let i = 0; i < storePath.length; i++) {
|
|
79
|
-
accessor = storePath[i];
|
|
80
|
-
if (i === storePath.length - 1) {
|
|
81
|
-
// reached final node
|
|
82
|
-
storeNode[accessor] = value;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
if (storeNode[accessor] === undefined) {
|
|
86
|
-
storeNode[accessor] = {};
|
|
87
|
-
}
|
|
88
|
-
storeNode = storeNode[accessor];
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
//# sourceMappingURL=store.js.map
|
package/dist/core/store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/core/store.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAA2D;AAO3D,qDAAqD;AACrD,MAAa,KAAK;IAAlB;;QACE,yEAAyE;QACzE,QAAG,GAAuB,EAAE,CAAC;QAC7B,sCAAsC;QACtC,uBAA0B,EAAE,EAAC;IA4E/B,CAAC;IA1EC,yDAAyD;IACzD,WAAW,CAAC,IAAa;QACvB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE;YAC1C,IAAK,GAAkB,CAAC,kBAAQ,CAAC,EAAE,CAAC;gBAClC,aAAa;gBACb,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,uBAAA,IAAI,gDAAiB,MAArB,IAAI,EAAkB,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAiB,CAAC,CAAC;gBAC1F,IAAI,KAAK,IAAI,SAAS;oBAAE,uBAAA,IAAI,2CAAY,MAAhB,IAAI,EAAa,SAAS,EAAE,KAAK,CAAC,CAAC;YAC7D,CAAC;iBAAM,CAAC;gBACN,uBAAuB;gBACvB,uBAAA,IAAI,8CAAe,MAAnB,IAAI,EAAgB,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,KAAK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,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;YAChF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QAC1B,CAAC;QACD,MAAM,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAE,CAAC;QAChC,SAAS,GAAI,SAAqC,CAAC,QAAQ,CAAC,CAAC;QAC7D,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AACtD,CAAC,iDAGW,SAAmB,EAAE,KAAc;IAC7C,IAAI,SAAS,GAAQ,uBAAA,IAAI,oBAAO,CAAC;IACjC,IAAI,QAAQ,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,qBAAqB;YACrB,SAAS,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC;YAC5B,MAAM;QACR,CAAC;QAED,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;YACtC,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QAC3B,CAAC;QACD,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SourceNode } from '../sourceNode';
|
|
2
|
-
/** Options to configure a Source Node. */
|
|
3
|
-
interface SourceConfigOpts {
|
|
4
|
-
/**
|
|
5
|
-
* Note that setting this to true will make it such that
|
|
6
|
-
* this SourceNode will ALWAYS be used to retrieve
|
|
7
|
-
* a value for any linked input node,
|
|
8
|
-
* unless there is another SourceNode with higher priority.
|
|
9
|
-
*/
|
|
10
|
-
allowUndefined?: boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Modifies a SourceNode with several options.
|
|
14
|
-
*/
|
|
15
|
-
export declare const config: (source: SourceNode, opts: SourceConfigOpts) => SourceNode;
|
|
16
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.config = void 0;
|
|
4
|
-
const symbols_1 = require("./symbols");
|
|
5
|
-
/**
|
|
6
|
-
* Modifies a SourceNode with several options.
|
|
7
|
-
*/
|
|
8
|
-
const config = (source, opts) => {
|
|
9
|
-
opts.allowUndefined && (source[symbols_1.allowUndefined] = true);
|
|
10
|
-
return source;
|
|
11
|
-
};
|
|
12
|
-
exports.config = config;
|
|
13
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/core/utils/config.ts"],"names":[],"mappings":";;;AACA,uCAA2C;AAa3C;;GAEG;AACI,MAAM,MAAM,GAAG,CAAC,MAAkB,EAAE,IAAsB,EAAE,EAAE;IACnE,IAAI,CAAC,cAAc,IAAI,CAAC,MAAM,CAAC,wBAAc,CAAC,GAAG,IAAI,CAAC,CAAC;IACvD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAHW,QAAA,MAAM,UAGjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/core/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,MAAM,CAAC;AACjB,QAAA,QAAQ,GAAG,OAAO,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { NODE_VALUE } from '../inputNode';
|
|
2
|
-
import { nodeValueIdentifier } from './symbols';
|
|
3
|
-
/** Provides a generator function to produce a value for an input. */
|
|
4
|
-
export declare const gen: (generator: () => any) => {
|
|
5
|
-
generator: () => any;
|
|
6
|
-
[nodeValueIdentifier]: NODE_VALUE;
|
|
7
|
-
};
|
|
8
|
-
/** Used to mark a param without a default value
|
|
9
|
-
* as required to be taken from another source. */
|
|
10
|
-
export declare const required: () => {
|
|
11
|
-
[nodeValueIdentifier]: NODE_VALUE;
|
|
12
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.required = exports.gen = void 0;
|
|
4
|
-
const inputNode_1 = require("../inputNode");
|
|
5
|
-
const symbols_1 = require("./symbols");
|
|
6
|
-
/** Provides a generator function to produce a value for an input. */
|
|
7
|
-
const gen = (generator) => ({
|
|
8
|
-
generator,
|
|
9
|
-
[symbols_1.nodeValueIdentifier]: inputNode_1.NODE_VALUE.GENERATOR,
|
|
10
|
-
});
|
|
11
|
-
exports.gen = gen;
|
|
12
|
-
/** Used to mark a param without a default value
|
|
13
|
-
* as required to be taken from another source. */
|
|
14
|
-
const required = () => ({
|
|
15
|
-
[symbols_1.nodeValueIdentifier]: inputNode_1.NODE_VALUE.REQUIRED,
|
|
16
|
-
});
|
|
17
|
-
exports.required = required;
|
|
18
|
-
//# sourceMappingURL=initializers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initializers.js","sourceRoot":"","sources":["../../../src/core/utils/initializers.ts"],"names":[],"mappings":";;;AAAA,4CAA0C;AAC1C,uCAAgD;AAEhD,qEAAqE;AAC9D,MAAM,GAAG,GAAG,CAAC,SAAoB,EAAE,EAAE,CAAC,CAAC;IAC5C,SAAS;IACT,CAAC,6BAAmB,CAAC,EAAE,sBAAU,CAAC,SAAS;CAC5C,CAAC,CAAC;AAHU,QAAA,GAAG,OAGb;AAEH;kDACkD;AAC3C,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,CAAC,6BAAmB,CAAC,EAAE,sBAAU,CAAC,QAAQ;CAC3C,CAAC,CAAC;AAFU,QAAA,QAAQ,YAElB"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { InputNode, NODE_VALUE } from '../inputNode';
|
|
2
|
-
import { nodeValueIdentifier } from './symbols';
|
|
3
|
-
import { SourceNode } from '../sourceNode';
|
|
4
|
-
export interface SourceInfo {
|
|
5
|
-
[nodeValueIdentifier]: NODE_VALUE;
|
|
6
|
-
source: SourceNode;
|
|
7
|
-
callback: ((val: any) => any) | undefined;
|
|
8
|
-
}
|
|
9
|
-
/** Overload signatures for `link` function. */
|
|
10
|
-
interface Link {
|
|
11
|
-
/**
|
|
12
|
-
* Link a Source node to an Input node.
|
|
13
|
-
* @param source the source node that will provide the value for an input.
|
|
14
|
-
* @param callback an optional function that is called on the source source value.
|
|
15
|
-
*/
|
|
16
|
-
(source: SourceNode, callback?: (val: any) => any): SourceInfo;
|
|
17
|
-
/**
|
|
18
|
-
* Link a Source node to an Input node.
|
|
19
|
-
* @param dest the input node that should take a value from a source.
|
|
20
|
-
* @param source the source node that will provide the value for an input.
|
|
21
|
-
* @param callback an optional function that is called on the source source value.
|
|
22
|
-
*/
|
|
23
|
-
(dest: InputNode, source: SourceNode, callback?: (val: any) => any): void;
|
|
24
|
-
}
|
|
25
|
-
export declare const link: Link;
|
|
26
|
-
export interface MergeSourcesInfo {
|
|
27
|
-
[nodeValueIdentifier]: NODE_VALUE;
|
|
28
|
-
sources: SourceNode[];
|
|
29
|
-
callback: ((val: any) => any) | undefined;
|
|
30
|
-
}
|
|
31
|
-
/** Overload signatures for `linkMerge` function. */
|
|
32
|
-
interface LinkMerge {
|
|
33
|
-
/**
|
|
34
|
-
* Links multiple Source nodes to an Input node via a callback.
|
|
35
|
-
* @param sources an array of source nodes to merge values from.
|
|
36
|
-
* @param callback a function to merge the sources into a single source for the dest.
|
|
37
|
-
*/
|
|
38
|
-
(sources: SourceNode[], callback?: (val: any) => any): MergeSourcesInfo;
|
|
39
|
-
/**
|
|
40
|
-
* Links multiple Source nodes to an Input node via a callback.
|
|
41
|
-
* @param sources an object with source nodes to merge values from.
|
|
42
|
-
* @param callback a function to merge the sources into a single source for the dest.
|
|
43
|
-
*/
|
|
44
|
-
(sources: {
|
|
45
|
-
[key: string]: SourceNode;
|
|
46
|
-
}, callback?: (val: any) => any): void;
|
|
47
|
-
/**
|
|
48
|
-
* Links multiple Source nodes to an Input node via a callback.
|
|
49
|
-
* @param dest the input node that should take a value from the callback.
|
|
50
|
-
* @param sources an array of source nodes to merge values from.
|
|
51
|
-
* @param callback a function to merge the sources into a single source for the dest.
|
|
52
|
-
*/
|
|
53
|
-
(dest: InputNode, sources: SourceNode[], callback?: (val: any) => any): void;
|
|
54
|
-
/**
|
|
55
|
-
* Links multiple Source nodes to an Input node via a callback.
|
|
56
|
-
* @param dest the input node that should take a value from the callback.
|
|
57
|
-
* @param sources an object with source nodes to merge values from.
|
|
58
|
-
* @param callback a function to merge the sources into a single source for the dest.
|
|
59
|
-
*/
|
|
60
|
-
(dest: InputNode, sources: {
|
|
61
|
-
[key: string]: SourceNode;
|
|
62
|
-
}, callback?: (val: any) => any): void;
|
|
63
|
-
}
|
|
64
|
-
export declare const linkMerge: LinkMerge;
|
|
65
|
-
export {};
|
package/dist/core/utils/link.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.linkMerge = exports.link = void 0;
|
|
4
|
-
const inputNode_1 = require("../inputNode");
|
|
5
|
-
const symbols_1 = require("./symbols");
|
|
6
|
-
exports.link = ((...args) => {
|
|
7
|
-
if (['function', 'undefined'].includes(typeof args[1])) {
|
|
8
|
-
const [source, callback] = args;
|
|
9
|
-
return {
|
|
10
|
-
[symbols_1.nodeValueIdentifier]: inputNode_1.NODE_VALUE.SOURCE_WITH_CALLBACK,
|
|
11
|
-
source,
|
|
12
|
-
callback,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
const [dest, source, callback] = args;
|
|
17
|
-
dest[symbols_1.setSource](source, callback);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
exports.linkMerge = ((...args) => {
|
|
21
|
-
if (['function', 'undefined'].includes(typeof args[1])) {
|
|
22
|
-
const [sources, callback] = args;
|
|
23
|
-
return {
|
|
24
|
-
[symbols_1.nodeValueIdentifier]: inputNode_1.NODE_VALUE.MERGE_SOURCES_WITH_CALLBACK,
|
|
25
|
-
sources,
|
|
26
|
-
callback,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const [dest, source, callback] = args;
|
|
31
|
-
dest[symbols_1.setSources](source, callback);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
//# sourceMappingURL=link.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"link.js","sourceRoot":"","sources":["../../../src/core/utils/link.ts"],"names":[],"mappings":";;;AAAA,4CAAqD;AACrD,uCAAuE;AA0B1D,QAAA,IAAI,GAAS,CAAC,CAAC,GAAG,IAAsB,EAAE,EAAE;IACvD,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,IAA8D,CAAC;QAC1F,OAAO;YACL,CAAC,6BAAmB,CAAC,EAAE,sBAAU,CAAC,oBAAoB;YACtD,MAAM;YACN,QAAQ;SACT,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,IAAkD,CAAC;QACpF,IAAI,CAAC,mBAAS,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;AACH,CAAC,CAAS,CAAC;AAsCE,QAAA,SAAS,GAAc,CAAC,CAAC,GAAG,IAA2B,EAAE,EAAE;IACtE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,IAG3B,CAAC;QACF,OAAO;YACL,CAAC,6BAAmB,CAAC,EAAE,sBAAU,CAAC,2BAA2B;YAC7D,OAAO;YACP,QAAQ;SACT,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,IAIhC,CAAC;QACF,IAAI,CAAC,oBAAU,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;AACH,CAAC,CAAc,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare const setSource: unique symbol;
|
|
2
|
-
export declare const setSources: unique symbol;
|
|
3
|
-
export declare const getNodeValue: unique symbol;
|
|
4
|
-
export declare const sourceId: unique symbol;
|
|
5
|
-
export declare const nodePath: unique symbol;
|
|
6
|
-
export declare const nodeValueIdentifier: unique symbol;
|
|
7
|
-
export declare const allowUndefined: unique symbol;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.allowUndefined = exports.nodeValueIdentifier = exports.nodePath = exports.sourceId = exports.getNodeValue = exports.setSources = exports.setSource = void 0;
|
|
4
|
-
exports.setSource = Symbol('setSource');
|
|
5
|
-
exports.setSources = Symbol('setSources');
|
|
6
|
-
exports.getNodeValue = Symbol('getNodeValue');
|
|
7
|
-
exports.sourceId = Symbol('sourceId');
|
|
8
|
-
exports.nodePath = Symbol('nodePath');
|
|
9
|
-
exports.nodeValueIdentifier = Symbol('nodeValueIdentifier');
|
|
10
|
-
exports.allowUndefined = Symbol('allowUndefined');
|
|
11
|
-
//# sourceMappingURL=symbols.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"symbols.js","sourceRoot":"","sources":["../../../src/core/utils/symbols.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAChC,QAAA,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAClC,QAAA,YAAY,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AACtC,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9B,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
package/dist/http/endpoint.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { InputNode, SourceValues, NODE_VALUE } from '../core/inputNode';
|
|
2
|
-
import { IHttpReq, RESP_PARSER, ParsedHttpResp } from './utils/client';
|
|
3
|
-
import { CallResult, IEndpoint } from '../core/chainflow';
|
|
4
|
-
import { SourceNode } from '../core/sourceNode';
|
|
5
|
-
import { nodeValueIdentifier } from '../core/utils/symbols';
|
|
6
|
-
import { IStore } from '../core/store';
|
|
7
|
-
import { SUPPORTED_METHOD } from './utils/constants';
|
|
8
|
-
import { MergeSourcesInfo, SourceInfo } from '../core/utils/link';
|
|
9
|
-
export interface INodeWithValue {
|
|
10
|
-
[nodeValueIdentifier]: NODE_VALUE;
|
|
11
|
-
}
|
|
12
|
-
/** Describes all the possible input nodes of a HTTP request. */
|
|
13
|
-
export interface HttpInputNodes {
|
|
14
|
-
pathParams: InputNode;
|
|
15
|
-
body: InputNode;
|
|
16
|
-
query: InputNode;
|
|
17
|
-
headers: InputNode;
|
|
18
|
-
}
|
|
19
|
-
/** Configurations for the endpoint. */
|
|
20
|
-
export interface EndpointConfig {
|
|
21
|
-
respParser?: `${RESP_PARSER}`;
|
|
22
|
-
respValidator?: (resp: ParsedHttpResp) => {
|
|
23
|
-
valid: boolean;
|
|
24
|
-
msg?: string;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/** Options for configuring an endpoint call. */
|
|
28
|
-
export interface HTTPCallOpts {
|
|
29
|
-
headers?: Record<string, string>;
|
|
30
|
-
query?: Record<string, string>;
|
|
31
|
-
pathParams?: Record<string, string>;
|
|
32
|
-
body?: Record<string, any>;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Manages request and response nodes,
|
|
36
|
-
* as well as calls to that endpoint
|
|
37
|
-
*/
|
|
38
|
-
export declare class Endpoint implements IEndpoint<HTTPCallOpts, IHttpReq, ParsedHttpResp> {
|
|
39
|
-
#private;
|
|
40
|
-
id: string;
|
|
41
|
-
url: string;
|
|
42
|
-
method: SUPPORTED_METHOD;
|
|
43
|
-
constructor({ url, method }: {
|
|
44
|
-
url: string;
|
|
45
|
-
method: SUPPORTED_METHOD;
|
|
46
|
-
});
|
|
47
|
-
/** @todo Update this when there is a better implementation of id. */
|
|
48
|
-
get details(): string;
|
|
49
|
-
/** Configures this endpoint. */
|
|
50
|
-
config(config: EndpointConfig): this;
|
|
51
|
-
/** Sets the request body. */
|
|
52
|
-
body(payload: any): this;
|
|
53
|
-
get resp(): SourceNode;
|
|
54
|
-
/** Sets the request query parameters. */
|
|
55
|
-
query(params: any): this;
|
|
56
|
-
/** Sets custom headers for requests. */
|
|
57
|
-
headers(params: Record<string, string | INodeWithValue | undefined>): this;
|
|
58
|
-
/** Sets the path params (if they exist in the URL). */
|
|
59
|
-
pathParams(params: Record<string, string | SourceNode | SourceInfo | MergeSourcesInfo>): this;
|
|
60
|
-
/** Sets headers provided by the originServer object. */
|
|
61
|
-
baseHeaders(node: InputNode): this;
|
|
62
|
-
/** Declare values to store from responses to this endpoint. */
|
|
63
|
-
store(callback: (resp: SourceNode) => IStore<SourceNode>): this;
|
|
64
|
-
/** Calls this endpoint with responses provided from earlier requests in the chain. */
|
|
65
|
-
call(responses: SourceValues, opts?: HTTPCallOpts): Promise<CallResult<IHttpReq, ParsedHttpResp>>;
|
|
66
|
-
/** Passes the request input nodes of this endpoint to a callback. */
|
|
67
|
-
set(setter: (nodes: HttpInputNodes) => void): this;
|
|
68
|
-
}
|
package/dist/http/endpoint.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
var _Endpoint_instances, _Endpoint_req, _Endpoint_resp, _Endpoint_config, _Endpoint_store, _Endpoint_extractPathParams, _Endpoint_insertPathParams, _Endpoint_insertQueryParams, _Endpoint_validateResp, _Endpoint_findMissingValues;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.Endpoint = void 0;
|
|
28
|
-
const id_1 = require("./utils/id");
|
|
29
|
-
const inputNode_1 = require("../core/inputNode");
|
|
30
|
-
const reqBuilder_1 = require("./reqBuilder");
|
|
31
|
-
const client_1 = require("./utils/client");
|
|
32
|
-
const errors_1 = require("./errors");
|
|
33
|
-
const deepmerge_1 = __importDefault(require("@fastify/deepmerge"));
|
|
34
|
-
const sourceNode_1 = require("../core/sourceNode");
|
|
35
|
-
const symbols_1 = require("../core/utils/symbols");
|
|
36
|
-
const initializers_1 = require("../core/utils/initializers");
|
|
37
|
-
const store_1 = require("../core/store");
|
|
38
|
-
const logger_1 = require("./logger");
|
|
39
|
-
const deepmerge = (0, deepmerge_1.default)();
|
|
40
|
-
const PATH_PARAM_REGEX = /\/(\{[^{}]+\})/g;
|
|
41
|
-
/**
|
|
42
|
-
* Manages request and response nodes,
|
|
43
|
-
* as well as calls to that endpoint
|
|
44
|
-
*/
|
|
45
|
-
class Endpoint {
|
|
46
|
-
constructor({ url, method }) {
|
|
47
|
-
_Endpoint_instances.add(this);
|
|
48
|
-
_Endpoint_req.set(this, void 0);
|
|
49
|
-
_Endpoint_resp.set(this, void 0);
|
|
50
|
-
_Endpoint_config.set(this, {});
|
|
51
|
-
_Endpoint_store.set(this, new store_1.Store());
|
|
52
|
-
/** @todo consider validating url */
|
|
53
|
-
!(url.startsWith('http://') || url.startsWith('https://')) && (url = `http://${url}`);
|
|
54
|
-
this.url = url;
|
|
55
|
-
this.method = method;
|
|
56
|
-
this.id = (0, id_1.getEndpointId)({ method, url });
|
|
57
|
-
__classPrivateFieldSet(this, _Endpoint_req, new reqBuilder_1.ReqBuilder(), "f");
|
|
58
|
-
__classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_extractPathParams).call(this);
|
|
59
|
-
__classPrivateFieldSet(this, _Endpoint_resp, (0, sourceNode_1.sourceNode)(this.id), "f");
|
|
60
|
-
}
|
|
61
|
-
/** @todo Update this when there is a better implementation of id. */
|
|
62
|
-
get details() {
|
|
63
|
-
return this.id;
|
|
64
|
-
}
|
|
65
|
-
/** Configures this endpoint. */
|
|
66
|
-
config(config) {
|
|
67
|
-
__classPrivateFieldSet(this, _Endpoint_config, config, "f");
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/** Sets the request body. */
|
|
71
|
-
body(payload) {
|
|
72
|
-
__classPrivateFieldGet(this, _Endpoint_req, "f").body = payload;
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
get resp() {
|
|
76
|
-
return __classPrivateFieldGet(this, _Endpoint_resp, "f");
|
|
77
|
-
}
|
|
78
|
-
/** Sets the request query parameters. */
|
|
79
|
-
query(params) {
|
|
80
|
-
__classPrivateFieldGet(this, _Endpoint_req, "f").query = params;
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
/** Sets custom headers for requests. */
|
|
84
|
-
headers(params) {
|
|
85
|
-
__classPrivateFieldGet(this, _Endpoint_req, "f").headers = params;
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
/** Sets the path params (if they exist in the URL). */
|
|
89
|
-
pathParams(params) {
|
|
90
|
-
const pathParamKeys = Object.keys(__classPrivateFieldGet(this, _Endpoint_req, "f").pathParams);
|
|
91
|
-
Object.entries(params).forEach(([key, val]) => {
|
|
92
|
-
if (pathParamKeys.includes(key)) {
|
|
93
|
-
__classPrivateFieldGet(this, _Endpoint_req, "f").pathParams[key] = new inputNode_1.InputNode(val);
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
/** Sets headers provided by the originServer object. */
|
|
99
|
-
baseHeaders(node) {
|
|
100
|
-
__classPrivateFieldGet(this, _Endpoint_req, "f").baseHeaders = node;
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
/** Declare values to store from responses to this endpoint. */
|
|
104
|
-
store(callback) {
|
|
105
|
-
__classPrivateFieldGet(this, _Endpoint_store, "f").def = callback(this.resp);
|
|
106
|
-
return this;
|
|
107
|
-
}
|
|
108
|
-
/** Calls this endpoint with responses provided from earlier requests in the chain. */
|
|
109
|
-
call(responses, opts) {
|
|
110
|
-
var _a, _b, _c;
|
|
111
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const method = this.method.toUpperCase();
|
|
113
|
-
let body;
|
|
114
|
-
const missingValues = []; // contains path of missing required values
|
|
115
|
-
if (method !== 'GET')
|
|
116
|
-
body = __classPrivateFieldGet(this, _Endpoint_req, "f").body[symbols_1.getNodeValue](responses, missingValues, ['body']);
|
|
117
|
-
let pathParams = {};
|
|
118
|
-
if (Object.keys(__classPrivateFieldGet(this, _Endpoint_req, "f").pathParams).length > 0) {
|
|
119
|
-
pathParams = __classPrivateFieldGet(this, _Endpoint_req, "f").pathParams[symbols_1.getNodeValue](responses, missingValues, ['pathParams']);
|
|
120
|
-
}
|
|
121
|
-
let queryParams = {};
|
|
122
|
-
if (Object.keys(__classPrivateFieldGet(this, _Endpoint_req, "f").query).length > 0) {
|
|
123
|
-
queryParams = __classPrivateFieldGet(this, _Endpoint_req, "f").query[symbols_1.getNodeValue](responses, missingValues, ['queryParams']);
|
|
124
|
-
}
|
|
125
|
-
const baseHeaders = __classPrivateFieldGet(this, _Endpoint_req, "f").baseHeaders[symbols_1.getNodeValue](responses, missingValues, ['headers']);
|
|
126
|
-
let headers = __classPrivateFieldGet(this, _Endpoint_req, "f").headers[symbols_1.getNodeValue](responses, missingValues, ['headers']);
|
|
127
|
-
baseHeaders && (headers = deepmerge(baseHeaders, headers !== null && headers !== void 0 ? headers : {}));
|
|
128
|
-
const finalMissingValues = __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_findMissingValues).call(this, missingValues, opts);
|
|
129
|
-
if (finalMissingValues.length > 0)
|
|
130
|
-
throw new errors_1.RequiredValuesNotFoundError(this.id, finalMissingValues);
|
|
131
|
-
if (opts === null || opts === void 0 ? void 0 : opts.body)
|
|
132
|
-
body = deepmerge(body, opts.body);
|
|
133
|
-
if (opts === null || opts === void 0 ? void 0 : opts.pathParams)
|
|
134
|
-
pathParams = deepmerge(pathParams, opts.pathParams);
|
|
135
|
-
if (opts === null || opts === void 0 ? void 0 : opts.query)
|
|
136
|
-
queryParams = deepmerge(queryParams, opts.query);
|
|
137
|
-
if (opts === null || opts === void 0 ? void 0 : opts.headers)
|
|
138
|
-
headers = deepmerge(headers, opts.headers);
|
|
139
|
-
let url = this.url;
|
|
140
|
-
url = __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_insertPathParams).call(this, url, pathParams);
|
|
141
|
-
url = __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_insertQueryParams).call(this, url, queryParams);
|
|
142
|
-
const resp = yield client_1.httpClient.request({
|
|
143
|
-
url,
|
|
144
|
-
method: this.method.toUpperCase(),
|
|
145
|
-
body,
|
|
146
|
-
headers,
|
|
147
|
-
respParser: __classPrivateFieldGet(this, _Endpoint_config, "f").respParser,
|
|
148
|
-
});
|
|
149
|
-
const results = (_c = (_b = (_a = __classPrivateFieldGet(this, _Endpoint_config, "f")).respValidator) === null || _b === void 0 ? void 0 : _b.call(_a, resp)) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_validateResp).call(this, resp);
|
|
150
|
-
if (!results.valid)
|
|
151
|
-
throw new errors_1.InvalidResponseError(results.msg);
|
|
152
|
-
return {
|
|
153
|
-
req: {
|
|
154
|
-
method,
|
|
155
|
-
url,
|
|
156
|
-
body,
|
|
157
|
-
headers,
|
|
158
|
-
respParser: __classPrivateFieldGet(this, _Endpoint_config, "f").respParser,
|
|
159
|
-
},
|
|
160
|
-
resp,
|
|
161
|
-
store: __classPrivateFieldGet(this, _Endpoint_store, "f").storeValues(resp),
|
|
162
|
-
};
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
/** Passes the request input nodes of this endpoint to a callback. */
|
|
166
|
-
set(setter) {
|
|
167
|
-
setter({
|
|
168
|
-
pathParams: __classPrivateFieldGet(this, _Endpoint_req, "f").pathParams,
|
|
169
|
-
body: __classPrivateFieldGet(this, _Endpoint_req, "f").body,
|
|
170
|
-
query: __classPrivateFieldGet(this, _Endpoint_req, "f").query,
|
|
171
|
-
headers: __classPrivateFieldGet(this, _Endpoint_req, "f").headers,
|
|
172
|
-
});
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
exports.Endpoint = Endpoint;
|
|
177
|
-
_Endpoint_req = new WeakMap(), _Endpoint_resp = new WeakMap(), _Endpoint_config = new WeakMap(), _Endpoint_store = new WeakMap(), _Endpoint_instances = new WeakSet(), _Endpoint_extractPathParams = function _Endpoint_extractPathParams() {
|
|
178
|
-
const pathParamRegex = new RegExp(PATH_PARAM_REGEX);
|
|
179
|
-
let param;
|
|
180
|
-
const params = {};
|
|
181
|
-
while ((param = pathParamRegex.exec(this.url)) !== null && typeof param[1] === 'string') {
|
|
182
|
-
const paramName = param[1].replace('{', '').replace('}', '');
|
|
183
|
-
params[paramName] = (0, initializers_1.required)();
|
|
184
|
-
}
|
|
185
|
-
__classPrivateFieldGet(this, _Endpoint_req, "f").pathParams = new inputNode_1.InputNode(params);
|
|
186
|
-
}, _Endpoint_insertPathParams = function _Endpoint_insertPathParams(path, pathParams) {
|
|
187
|
-
Object.entries(pathParams).forEach(([name, val]) => {
|
|
188
|
-
path = path.replace(`{${name}}`, val);
|
|
189
|
-
});
|
|
190
|
-
return path;
|
|
191
|
-
}, _Endpoint_insertQueryParams = function _Endpoint_insertQueryParams(path, queryParams) {
|
|
192
|
-
if (Object.keys(queryParams).length > 0)
|
|
193
|
-
path = `${path}?`;
|
|
194
|
-
Object.entries(queryParams).forEach(([name, val], i) => {
|
|
195
|
-
path = `${path}${i >= 1 ? '&' : ''}${name}=${val}`;
|
|
196
|
-
});
|
|
197
|
-
return path;
|
|
198
|
-
}, _Endpoint_validateResp = function _Endpoint_validateResp(resp) {
|
|
199
|
-
if (resp.statusCode >= 400) {
|
|
200
|
-
(0, logger_1.warn)(`Request failed with status code: ${resp.statusCode}`);
|
|
201
|
-
return { valid: false, msg: `Received HTTP status code ${resp.statusCode}` };
|
|
202
|
-
}
|
|
203
|
-
return { valid: true };
|
|
204
|
-
}, _Endpoint_findMissingValues = function _Endpoint_findMissingValues(missingValues, obj) {
|
|
205
|
-
const finalMissingValues = [];
|
|
206
|
-
for (const path of missingValues) {
|
|
207
|
-
if (obj === undefined) {
|
|
208
|
-
finalMissingValues.push(path.join('.'));
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
let state = obj;
|
|
212
|
-
for (const accessor of path) {
|
|
213
|
-
state = state[accessor];
|
|
214
|
-
if (state === undefined) {
|
|
215
|
-
finalMissingValues.push(path.join('.'));
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
return finalMissingValues;
|
|
221
|
-
};
|
|
222
|
-
//# sourceMappingURL=endpoint.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/http/endpoint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA2C;AAC3C,iDAAwE;AACxE,6CAA0C;AAC1C,2CAMwB;AACxB,qCAA6E;AAE7E,mEAAgD;AAChD,mDAA4D;AAC5D,mDAA0E;AAC1E,6DAAsD;AACtD,yCAA8C;AA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,KAAK,SAAS,EAAE,CAAC;YACtB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACxC,SAAS;QACX,CAAC;QACD,IAAI,KAAK,GAAG,GAAG,CAAC;QAChB,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC5B,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YACxB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACxC,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
package/dist/http/errors.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** When there is no value available for a required input node. */
|
|
2
|
-
export declare class RequiredValuesNotFoundError extends Error {
|
|
3
|
-
constructor(id: string, missingValues: string[]);
|
|
4
|
-
}
|
|
5
|
-
/** When a request to an endpoint fails to execute or receive a response. */
|
|
6
|
-
export declare class RequestFailedError extends Error {
|
|
7
|
-
constructor(msg?: string);
|
|
8
|
-
}
|
|
9
|
-
/** When a response fails a validation check. */
|
|
10
|
-
export declare class InvalidResponseError extends Error {
|
|
11
|
-
constructor(msg?: string);
|
|
12
|
-
}
|
|
13
|
-
/** When the client fails to parse a response body. */
|
|
14
|
-
export declare class ParseResponseError extends Error {
|
|
15
|
-
constructor(msg?: string);
|
|
16
|
-
}
|