@keshavsoft/api-tree 1.0.0 → 6.1.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/README.md +77 -52
- package/docs/api.html +123 -0
- package/docs/examples.html +100 -0
- package/docs/how-it-works.html +69 -0
- package/docs/index.html +95 -26
- package/docs/style.css +272 -0
- package/docs/validation.html +88 -0
- package/package.json +7 -3
- package/src/index.d.ts +65 -19
- package/src/index.js +2 -2
- package/src/v2/blueprint/api.json +4 -0
- package/src/v2/blueprint/source.json +22 -0
- package/src/v2/index.js +33 -0
- package/src/v2/internal-working/route/attachPath.js +38 -0
- package/src/v2/internal-working/route/createLeafHandler.js +25 -0
- package/src/v2/internal-working/route/index.js +35 -0
- package/src/v2/internal-working/route/resolveLeafSpec.js +22 -0
- package/src/v2/internal-working/validate/index.js +42 -0
- package/src/v2/internal-working/validate/isPlainObject.js +12 -0
- package/src/v3/index.js +34 -0
- package/src/v3/internal-working/buildTree.js +35 -0
- package/src/v4/blueprint/api.json +13 -0
- package/src/v4/blueprint/source.json +228 -0
- package/src/v4/index.js +29 -0
- package/src/v4/internal-working/buildTree.js +35 -0
- package/src/v4/internal-working/guards/index.js +15 -0
- package/src/v4/internal-working/guards/isFunction.js +9 -0
- package/src/v4/internal-working/guards/isObject.js +9 -0
- package/src/v4/internal-working/guards/isStringArray.js +15 -0
- package/src/v5/blueprint/api.json +13 -0
- package/src/v5/blueprint/source.json +228 -0
- package/src/v5/engine/guards/index.js +15 -0
- package/src/v5/engine/guards/isFunction.js +9 -0
- package/src/v5/engine/guards/isObject.js +9 -0
- package/src/v5/engine/guards/isStringArray.js +15 -0
- package/src/v5/engine/run.js +35 -0
- package/src/v5/index.js +29 -0
- package/src/v6/blueprint/api.json +13 -0
- package/src/v6/blueprint/source.json +228 -0
- package/src/v6/engine/guards/index.js +15 -0
- package/src/v6/engine/guards/isFunction.js +9 -0
- package/src/v6/engine/guards/isObject.js +9 -0
- package/src/v6/engine/guards/isStringArray.js +15 -0
- package/src/v6/engine/run.js +35 -0
- package/src/v6/index.js +29 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const startFunc = ({ inSource, inApiPaths, inExecutor }) => {
|
|
2
|
+
const localSource = inSource;
|
|
3
|
+
const localApiPaths = inApiPaths;
|
|
4
|
+
const localExecutor = inExecutor;
|
|
5
|
+
|
|
6
|
+
const tree = {};
|
|
7
|
+
|
|
8
|
+
for (const path of localApiPaths) {
|
|
9
|
+
const parts = path.split(".");
|
|
10
|
+
const leaf = parts.pop();
|
|
11
|
+
|
|
12
|
+
let branch = tree;
|
|
13
|
+
for (const segment of parts) {
|
|
14
|
+
branch[segment] ??= {};
|
|
15
|
+
branch = branch[segment];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
branch[leaf] = async (param, ...args) => {
|
|
19
|
+
const localParam = param;
|
|
20
|
+
const localArgs = args;
|
|
21
|
+
|
|
22
|
+
return await localExecutor({
|
|
23
|
+
inRoutePath: path,
|
|
24
|
+
inParam: localParam,
|
|
25
|
+
inArgs: localArgs,
|
|
26
|
+
inSource: localSource
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const root = localApiPaths[0]?.split(".")[0];
|
|
32
|
+
return root && tree[root] ? tree[root] : tree;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default startFunc;
|
package/src/v6/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import guards from "./engine/guards/index.js";
|
|
2
|
+
import run from "./engine/run.js";
|
|
3
|
+
|
|
4
|
+
const apiTree = (source, apiPaths, executor) => {
|
|
5
|
+
let localSource = source;
|
|
6
|
+
let localApiPaths = apiPaths;
|
|
7
|
+
let localExecutor = executor;
|
|
8
|
+
|
|
9
|
+
if (source && typeof source === "object" && "inSource" in source) {
|
|
10
|
+
localSource = source.inSource;
|
|
11
|
+
localApiPaths = source.inApiPaths;
|
|
12
|
+
localExecutor = source.inExecutor;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
guards({
|
|
16
|
+
inSource: localSource,
|
|
17
|
+
inApiPaths: localApiPaths,
|
|
18
|
+
inExecutor: localExecutor
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return run({
|
|
22
|
+
inSource: localSource,
|
|
23
|
+
inApiPaths: localApiPaths,
|
|
24
|
+
inExecutor: localExecutor
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default apiTree;
|
|
29
|
+
export { apiTree, apiTree as start };
|