@objectstack/runtime 3.2.7 → 3.2.8
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 +8 -8
- package/CHANGELOG.md +9 -0
- package/dist/index.cjs +77 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +77 -40
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/http-dispatcher.test.ts +100 -0
- package/src/http-dispatcher.ts +88 -42
package/dist/index.js
CHANGED
|
@@ -1043,7 +1043,7 @@ var HttpDispatcher = class {
|
|
|
1043
1043
|
* Fallback for backward compat: /metadata (all objects), /metadata/:objectName (get object)
|
|
1044
1044
|
*/
|
|
1045
1045
|
async handleMetadata(path, context, method, body, query) {
|
|
1046
|
-
const broker = this.
|
|
1046
|
+
const broker = this.kernel.broker ?? null;
|
|
1047
1047
|
const parts = path.replace(/^\/+/, "").split("/").filter(Boolean);
|
|
1048
1048
|
if (parts[0] === "types") {
|
|
1049
1049
|
const protocol = await this.resolveService("protocol");
|
|
@@ -1051,12 +1051,14 @@ var HttpDispatcher = class {
|
|
|
1051
1051
|
const result = await protocol.getMetaTypes({});
|
|
1052
1052
|
return { handled: true, response: this.success(result) };
|
|
1053
1053
|
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1054
|
+
if (broker) {
|
|
1055
|
+
try {
|
|
1056
|
+
const data = await broker.call("metadata.types", {}, { request: context.request });
|
|
1057
|
+
return { handled: true, response: this.success(data) };
|
|
1058
|
+
} catch {
|
|
1059
|
+
}
|
|
1059
1060
|
}
|
|
1061
|
+
return { handled: true, response: this.success({ types: ["object", "app", "plugin"] }) };
|
|
1060
1062
|
}
|
|
1061
1063
|
if (parts.length === 3 && parts[2] === "published" && (!method || method === "GET")) {
|
|
1062
1064
|
const [type, name] = parts;
|
|
@@ -1066,12 +1068,15 @@ var HttpDispatcher = class {
|
|
|
1066
1068
|
if (data === void 0) return { handled: true, response: this.error("Not found", 404) };
|
|
1067
1069
|
return { handled: true, response: this.success(data) };
|
|
1068
1070
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1071
|
+
if (broker) {
|
|
1072
|
+
try {
|
|
1073
|
+
const data = await broker.call("metadata.getPublished", { type, name }, { request: context.request });
|
|
1074
|
+
return { handled: true, response: this.success(data) };
|
|
1075
|
+
} catch (e) {
|
|
1076
|
+
return { handled: true, response: this.error(e.message, 404) };
|
|
1077
|
+
}
|
|
1074
1078
|
}
|
|
1079
|
+
return { handled: true, response: this.error("Not found", 404) };
|
|
1075
1080
|
}
|
|
1076
1081
|
if (parts.length === 2) {
|
|
1077
1082
|
const [type, name] = parts;
|
|
@@ -1085,30 +1090,44 @@ var HttpDispatcher = class {
|
|
|
1085
1090
|
return { handled: true, response: this.error(e.message, 400) };
|
|
1086
1091
|
}
|
|
1087
1092
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
+
if (broker) {
|
|
1094
|
+
try {
|
|
1095
|
+
const data = await broker.call("metadata.saveItem", { type, name, item: body }, { request: context.request });
|
|
1096
|
+
return { handled: true, response: this.success(data) };
|
|
1097
|
+
} catch (e) {
|
|
1098
|
+
return { handled: true, response: this.error(e.message || "Save not supported", 501) };
|
|
1099
|
+
}
|
|
1093
1100
|
}
|
|
1101
|
+
return { handled: true, response: this.error("Save not supported", 501) };
|
|
1094
1102
|
}
|
|
1095
1103
|
try {
|
|
1096
1104
|
if (type === "objects" || type === "object") {
|
|
1097
|
-
|
|
1098
|
-
|
|
1105
|
+
if (broker) {
|
|
1106
|
+
const data = await broker.call("metadata.getObject", { objectName: name }, { request: context.request });
|
|
1107
|
+
return { handled: true, response: this.success(data) };
|
|
1108
|
+
}
|
|
1109
|
+
const qlService = await this.getObjectQLService();
|
|
1110
|
+
if (qlService?.registry) {
|
|
1111
|
+
const data = qlService.registry.getObject(name);
|
|
1112
|
+
if (data) return { handled: true, response: this.success(data) };
|
|
1113
|
+
}
|
|
1114
|
+
return { handled: true, response: this.error("Not found", 404) };
|
|
1099
1115
|
}
|
|
1100
1116
|
const singularType = type.endsWith("s") ? type.slice(0, -1) : type;
|
|
1101
1117
|
const protocol = await this.resolveService("protocol");
|
|
1102
1118
|
if (protocol && typeof protocol.getMetaItem === "function") {
|
|
1103
1119
|
try {
|
|
1104
|
-
const
|
|
1105
|
-
return { handled: true, response: this.success(
|
|
1120
|
+
const data = await protocol.getMetaItem({ type: singularType, name });
|
|
1121
|
+
return { handled: true, response: this.success(data) };
|
|
1106
1122
|
} catch (e) {
|
|
1107
1123
|
}
|
|
1108
1124
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1125
|
+
if (broker) {
|
|
1126
|
+
const method2 = `metadata.get${this.capitalize(singularType)}`;
|
|
1127
|
+
const data = await broker.call(method2, { name }, { request: context.request });
|
|
1128
|
+
return { handled: true, response: this.success(data) };
|
|
1129
|
+
}
|
|
1130
|
+
return { handled: true, response: this.error("Not found", 404) };
|
|
1112
1131
|
} catch (e) {
|
|
1113
1132
|
return { handled: true, response: this.error(e.message, 404) };
|
|
1114
1133
|
}
|
|
@@ -1126,23 +1145,39 @@ var HttpDispatcher = class {
|
|
|
1126
1145
|
} catch {
|
|
1127
1146
|
}
|
|
1128
1147
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1148
|
+
if (broker) {
|
|
1149
|
+
try {
|
|
1150
|
+
if (typeOrName === "objects") {
|
|
1151
|
+
const data2 = await broker.call("metadata.objects", { packageId }, { request: context.request });
|
|
1152
|
+
return { handled: true, response: this.success(data2) };
|
|
1153
|
+
}
|
|
1154
|
+
const data = await broker.call(`metadata.${typeOrName}`, { packageId }, { request: context.request });
|
|
1155
|
+
if (data !== null && data !== void 0) {
|
|
1156
|
+
return { handled: true, response: this.success(data) };
|
|
1157
|
+
}
|
|
1158
|
+
} catch {
|
|
1133
1159
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1160
|
+
try {
|
|
1161
|
+
const data = await broker.call("metadata.getObject", { objectName: typeOrName }, { request: context.request });
|
|
1136
1162
|
return { handled: true, response: this.success(data) };
|
|
1163
|
+
} catch (e) {
|
|
1164
|
+
return { handled: true, response: this.error(e.message, 404) };
|
|
1137
1165
|
}
|
|
1138
|
-
} catch {
|
|
1139
1166
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1167
|
+
const qlService = await this.getObjectQLService();
|
|
1168
|
+
if (qlService?.registry) {
|
|
1169
|
+
if (typeOrName === "objects") {
|
|
1170
|
+
const objs = qlService.registry.getAllObjects(packageId);
|
|
1171
|
+
return { handled: true, response: this.success({ type: "object", items: objs }) };
|
|
1172
|
+
}
|
|
1173
|
+
const items = qlService.registry.listItems?.(typeOrName, packageId);
|
|
1174
|
+
if (items && items.length > 0) {
|
|
1175
|
+
return { handled: true, response: this.success({ type: typeOrName, items }) };
|
|
1176
|
+
}
|
|
1177
|
+
const obj = qlService.registry.getObject(typeOrName);
|
|
1178
|
+
if (obj) return { handled: true, response: this.success(obj) };
|
|
1145
1179
|
}
|
|
1180
|
+
return { handled: true, response: this.error("Not found", 404) };
|
|
1146
1181
|
}
|
|
1147
1182
|
if (parts.length === 0) {
|
|
1148
1183
|
const protocol = await this.resolveService("protocol");
|
|
@@ -1150,12 +1185,14 @@ var HttpDispatcher = class {
|
|
|
1150
1185
|
const result = await protocol.getMetaTypes({});
|
|
1151
1186
|
return { handled: true, response: this.success(result) };
|
|
1152
1187
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1188
|
+
if (broker) {
|
|
1189
|
+
try {
|
|
1190
|
+
const data = await broker.call("metadata.types", {}, { request: context.request });
|
|
1191
|
+
return { handled: true, response: this.success(data) };
|
|
1192
|
+
} catch {
|
|
1193
|
+
}
|
|
1158
1194
|
}
|
|
1195
|
+
return { handled: true, response: this.success({ types: ["object", "app", "plugin"] }) };
|
|
1159
1196
|
}
|
|
1160
1197
|
return { handled: false };
|
|
1161
1198
|
}
|