@objectstack/runtime 3.0.8 → 3.0.10
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +20 -0
- package/dist/index.cjs +158 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +158 -7
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/dispatcher-plugin.ts +82 -1
- package/src/http-dispatcher.test.ts +101 -1
- package/src/http-dispatcher.ts +112 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @objectstack/runtime@3.0.
|
|
2
|
+
> @objectstack/runtime@3.0.10 build /home/runner/work/spec/spec/packages/runtime
|
|
3
3
|
> tsup --config ../../tsup.config.ts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
13
|
+
[32mESM[39m [1mdist/index.js [22m[32m52.28 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m117.25 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 178ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m54.16 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m117.31 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 166ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 6341ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m20.49 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m20.49 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @objectstack/runtime
|
|
2
2
|
|
|
3
|
+
## 3.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d1e5d31]
|
|
8
|
+
- @objectstack/spec@3.0.10
|
|
9
|
+
- @objectstack/core@3.0.10
|
|
10
|
+
- @objectstack/rest@3.0.10
|
|
11
|
+
- @objectstack/types@3.0.10
|
|
12
|
+
|
|
13
|
+
## 3.0.9
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [15e0df6]
|
|
18
|
+
- @objectstack/spec@3.0.9
|
|
19
|
+
- @objectstack/core@3.0.9
|
|
20
|
+
- @objectstack/rest@3.0.9
|
|
21
|
+
- @objectstack/types@3.0.9
|
|
22
|
+
|
|
3
23
|
## 3.0.8
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -486,7 +486,11 @@ var HttpDispatcher = class {
|
|
|
486
486
|
}
|
|
487
487
|
if (parts.length === 2 && m === "GET") {
|
|
488
488
|
const id = parts[1];
|
|
489
|
-
const
|
|
489
|
+
const { select, expand } = query || {};
|
|
490
|
+
const allowedParams = {};
|
|
491
|
+
if (select != null) allowedParams.select = select;
|
|
492
|
+
if (expand != null) allowedParams.expand = expand;
|
|
493
|
+
const result = await broker.call("data.get", { object: objectName, id, ...allowedParams }, { request: context.request });
|
|
490
494
|
return { handled: true, response: this.success(result) };
|
|
491
495
|
}
|
|
492
496
|
if (parts.length === 2 && m === "PATCH") {
|
|
@@ -501,7 +505,7 @@ var HttpDispatcher = class {
|
|
|
501
505
|
}
|
|
502
506
|
} else {
|
|
503
507
|
if (m === "GET") {
|
|
504
|
-
const result = await broker.call("data.query", { object: objectName,
|
|
508
|
+
const result = await broker.call("data.query", { object: objectName, query }, { request: context.request });
|
|
505
509
|
return { handled: true, response: this.success(result) };
|
|
506
510
|
}
|
|
507
511
|
if (m === "POST") {
|
|
@@ -715,18 +719,93 @@ var HttpDispatcher = class {
|
|
|
715
719
|
/**
|
|
716
720
|
* Handles Automation requests
|
|
717
721
|
* path: sub-path after /automation/
|
|
722
|
+
*
|
|
723
|
+
* Routes:
|
|
724
|
+
* GET / → listFlows
|
|
725
|
+
* GET /:name → getFlow
|
|
726
|
+
* POST / → createFlow (registerFlow)
|
|
727
|
+
* PUT /:name → updateFlow
|
|
728
|
+
* DELETE /:name → deleteFlow (unregisterFlow)
|
|
729
|
+
* POST /:name/trigger → execute (legacy: trigger/:name also supported)
|
|
730
|
+
* POST /:name/toggle → toggleFlow
|
|
731
|
+
* GET /:name/runs → listRuns
|
|
732
|
+
* GET /:name/runs/:runId → getRun
|
|
718
733
|
*/
|
|
719
|
-
async handleAutomation(path, method, body, context) {
|
|
734
|
+
async handleAutomation(path, method, body, context, query) {
|
|
720
735
|
const automationService = this.getService(import_system.CoreServiceName.enum.automation);
|
|
721
736
|
if (!automationService) return { handled: false };
|
|
722
737
|
const m = method.toUpperCase();
|
|
723
|
-
const parts = path.replace(/^\/+/, "").split("/");
|
|
738
|
+
const parts = path.replace(/^\/+/, "").split("/").filter(Boolean);
|
|
724
739
|
if (parts[0] === "trigger" && parts[1] && m === "POST") {
|
|
725
740
|
const triggerName = parts[1];
|
|
726
741
|
if (typeof automationService.trigger === "function") {
|
|
727
742
|
const result = await automationService.trigger(triggerName, body, { request: context.request });
|
|
728
743
|
return { handled: true, response: this.success(result) };
|
|
729
744
|
}
|
|
745
|
+
if (typeof automationService.execute === "function") {
|
|
746
|
+
const result = await automationService.execute(triggerName, body);
|
|
747
|
+
return { handled: true, response: this.success(result) };
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (parts.length === 0 && m === "GET") {
|
|
751
|
+
if (typeof automationService.listFlows === "function") {
|
|
752
|
+
const names = await automationService.listFlows();
|
|
753
|
+
return { handled: true, response: this.success({ flows: names, total: names.length, hasMore: false }) };
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (parts.length === 0 && m === "POST") {
|
|
757
|
+
if (typeof automationService.registerFlow === "function") {
|
|
758
|
+
automationService.registerFlow(body?.name, body);
|
|
759
|
+
return { handled: true, response: this.success(body) };
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (parts.length >= 1) {
|
|
763
|
+
const name = parts[0];
|
|
764
|
+
if (parts[1] === "trigger" && m === "POST") {
|
|
765
|
+
if (typeof automationService.execute === "function") {
|
|
766
|
+
const result = await automationService.execute(name, body);
|
|
767
|
+
return { handled: true, response: this.success(result) };
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (parts[1] === "toggle" && m === "POST") {
|
|
771
|
+
if (typeof automationService.toggleFlow === "function") {
|
|
772
|
+
await automationService.toggleFlow(name, body?.enabled ?? true);
|
|
773
|
+
return { handled: true, response: this.success({ name, enabled: body?.enabled ?? true }) };
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (parts[1] === "runs" && parts[2] && m === "GET") {
|
|
777
|
+
if (typeof automationService.getRun === "function") {
|
|
778
|
+
const run = await automationService.getRun(parts[2]);
|
|
779
|
+
if (!run) return { handled: true, response: this.error("Execution not found", 404) };
|
|
780
|
+
return { handled: true, response: this.success(run) };
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (parts[1] === "runs" && !parts[2] && m === "GET") {
|
|
784
|
+
if (typeof automationService.listRuns === "function") {
|
|
785
|
+
const options = query ? { limit: query.limit ? Number(query.limit) : void 0, cursor: query.cursor } : void 0;
|
|
786
|
+
const runs = await automationService.listRuns(name, options);
|
|
787
|
+
return { handled: true, response: this.success({ runs, hasMore: false }) };
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
if (parts.length === 1 && m === "GET") {
|
|
791
|
+
if (typeof automationService.getFlow === "function") {
|
|
792
|
+
const flow = await automationService.getFlow(name);
|
|
793
|
+
if (!flow) return { handled: true, response: this.error("Flow not found", 404) };
|
|
794
|
+
return { handled: true, response: this.success(flow) };
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
if (parts.length === 1 && m === "PUT") {
|
|
798
|
+
if (typeof automationService.registerFlow === "function") {
|
|
799
|
+
automationService.registerFlow(name, body?.definition ?? body);
|
|
800
|
+
return { handled: true, response: this.success(body?.definition ?? body) };
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (parts.length === 1 && m === "DELETE") {
|
|
804
|
+
if (typeof automationService.unregisterFlow === "function") {
|
|
805
|
+
automationService.unregisterFlow(name);
|
|
806
|
+
return { handled: true, response: this.success({ name, deleted: true }) };
|
|
807
|
+
}
|
|
808
|
+
}
|
|
730
809
|
}
|
|
731
810
|
return { handled: false };
|
|
732
811
|
}
|
|
@@ -801,7 +880,7 @@ var HttpDispatcher = class {
|
|
|
801
880
|
return this.handleUi(cleanPath.substring(3), query, context);
|
|
802
881
|
}
|
|
803
882
|
if (cleanPath.startsWith("/automation")) {
|
|
804
|
-
return this.handleAutomation(cleanPath.substring(11), method, body, context);
|
|
883
|
+
return this.handleAutomation(cleanPath.substring(11), method, body, context, query);
|
|
805
884
|
}
|
|
806
885
|
if (cleanPath.startsWith("/analytics")) {
|
|
807
886
|
return this.handleAnalytics(cleanPath.substring(10), method, body, context);
|
|
@@ -847,8 +926,8 @@ var HttpDispatcher = class {
|
|
|
847
926
|
if (endpoint.objectParams) {
|
|
848
927
|
const { object, operation } = endpoint.objectParams;
|
|
849
928
|
if (operation === "find") {
|
|
850
|
-
const result = await broker.call("data.query", { object,
|
|
851
|
-
return { handled: true, response: this.success(result.
|
|
929
|
+
const result = await broker.call("data.query", { object, query }, { request: context.request });
|
|
930
|
+
return { handled: true, response: this.success(result.records, { total: result.total }) };
|
|
852
931
|
}
|
|
853
932
|
if (operation === "get" && query.id) {
|
|
854
933
|
const result = await broker.call("data.get", { object, id: query.id }, { request: context.request });
|
|
@@ -1030,6 +1109,46 @@ function createDispatcherPlugin(config = {}) {
|
|
|
1030
1109
|
errorResponse(err, res);
|
|
1031
1110
|
}
|
|
1032
1111
|
});
|
|
1112
|
+
server.get(`${prefix}/automation`, async (req, res) => {
|
|
1113
|
+
try {
|
|
1114
|
+
const result = await dispatcher.handleAutomation("", "GET", {}, { request: req });
|
|
1115
|
+
sendResult(result, res);
|
|
1116
|
+
} catch (err) {
|
|
1117
|
+
errorResponse(err, res);
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
server.post(`${prefix}/automation`, async (req, res) => {
|
|
1121
|
+
try {
|
|
1122
|
+
const result = await dispatcher.handleAutomation("", "POST", req.body, { request: req });
|
|
1123
|
+
sendResult(result, res);
|
|
1124
|
+
} catch (err) {
|
|
1125
|
+
errorResponse(err, res);
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
server.get(`${prefix}/automation/:name`, async (req, res) => {
|
|
1129
|
+
try {
|
|
1130
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}`, "GET", {}, { request: req });
|
|
1131
|
+
sendResult(result, res);
|
|
1132
|
+
} catch (err) {
|
|
1133
|
+
errorResponse(err, res);
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
server.put(`${prefix}/automation/:name`, async (req, res) => {
|
|
1137
|
+
try {
|
|
1138
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}`, "PUT", req.body, { request: req });
|
|
1139
|
+
sendResult(result, res);
|
|
1140
|
+
} catch (err) {
|
|
1141
|
+
errorResponse(err, res);
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
server.delete(`${prefix}/automation/:name`, async (req, res) => {
|
|
1145
|
+
try {
|
|
1146
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}`, "DELETE", {}, { request: req });
|
|
1147
|
+
sendResult(result, res);
|
|
1148
|
+
} catch (err) {
|
|
1149
|
+
errorResponse(err, res);
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1033
1152
|
server.post(`${prefix}/automation/trigger/:name`, async (req, res) => {
|
|
1034
1153
|
try {
|
|
1035
1154
|
const result = await dispatcher.handleAutomation(`trigger/${req.params.name}`, "POST", req.body, { request: req });
|
|
@@ -1038,6 +1157,38 @@ function createDispatcherPlugin(config = {}) {
|
|
|
1038
1157
|
errorResponse(err, res);
|
|
1039
1158
|
}
|
|
1040
1159
|
});
|
|
1160
|
+
server.post(`${prefix}/automation/:name/trigger`, async (req, res) => {
|
|
1161
|
+
try {
|
|
1162
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}/trigger`, "POST", req.body, { request: req });
|
|
1163
|
+
sendResult(result, res);
|
|
1164
|
+
} catch (err) {
|
|
1165
|
+
errorResponse(err, res);
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
server.post(`${prefix}/automation/:name/toggle`, async (req, res) => {
|
|
1169
|
+
try {
|
|
1170
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}/toggle`, "POST", req.body, { request: req });
|
|
1171
|
+
sendResult(result, res);
|
|
1172
|
+
} catch (err) {
|
|
1173
|
+
errorResponse(err, res);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
server.get(`${prefix}/automation/:name/runs`, async (req, res) => {
|
|
1177
|
+
try {
|
|
1178
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}/runs`, "GET", {}, { request: req }, req.query);
|
|
1179
|
+
sendResult(result, res);
|
|
1180
|
+
} catch (err) {
|
|
1181
|
+
errorResponse(err, res);
|
|
1182
|
+
}
|
|
1183
|
+
});
|
|
1184
|
+
server.get(`${prefix}/automation/:name/runs/:runId`, async (req, res) => {
|
|
1185
|
+
try {
|
|
1186
|
+
const result = await dispatcher.handleAutomation(`${req.params.name}/runs/${req.params.runId}`, "GET", {}, { request: req });
|
|
1187
|
+
sendResult(result, res);
|
|
1188
|
+
} catch (err) {
|
|
1189
|
+
errorResponse(err, res);
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1041
1192
|
ctx.logger.info("Dispatcher bridge routes registered", { prefix });
|
|
1042
1193
|
}
|
|
1043
1194
|
};
|