@objectstack/rest 6.7.0 → 6.8.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/LICENSE +93 -202
- package/README.md +2 -2
- package/dist/index.cjs +43 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -302,7 +302,8 @@ function sendError(res, error, object) {
|
|
|
302
302
|
const safeMsg = typeof error.message === "string" && error.message.length < 500 ? error.message : "Request failed";
|
|
303
303
|
res.status(error.status).json({
|
|
304
304
|
error: safeMsg,
|
|
305
|
-
...error.code ? { code: error.code } : {}
|
|
305
|
+
...error.code ? { code: error.code } : {},
|
|
306
|
+
...Array.isArray(error.issues) ? { issues: error.issues } : {}
|
|
306
307
|
});
|
|
307
308
|
return;
|
|
308
309
|
}
|
|
@@ -1211,6 +1212,33 @@ var RestServer = class {
|
|
|
1211
1212
|
});
|
|
1212
1213
|
}
|
|
1213
1214
|
if (metadata.endpoints.item !== false) {
|
|
1215
|
+
this.routeManager.register({
|
|
1216
|
+
method: "GET",
|
|
1217
|
+
path: `${metaPath}/:type/:name/references`,
|
|
1218
|
+
handler: async (req, res) => {
|
|
1219
|
+
try {
|
|
1220
|
+
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1221
|
+
const p = await this.resolveProtocol(environmentId, req);
|
|
1222
|
+
if (typeof p.findReferencesToMeta !== "function") {
|
|
1223
|
+
res.json({ references: [] });
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
const result = await p.findReferencesToMeta({
|
|
1227
|
+
type: req.params.type,
|
|
1228
|
+
name: req.params.name,
|
|
1229
|
+
...environmentId ? { environmentId } : {}
|
|
1230
|
+
});
|
|
1231
|
+
res.json(result);
|
|
1232
|
+
} catch (error) {
|
|
1233
|
+
logError("[REST] Unhandled error:", error);
|
|
1234
|
+
sendError(res, error);
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
metadata: {
|
|
1238
|
+
summary: "List metadata items that reference this item",
|
|
1239
|
+
tags: ["metadata"]
|
|
1240
|
+
}
|
|
1241
|
+
});
|
|
1214
1242
|
this.routeManager.register({
|
|
1215
1243
|
method: "GET",
|
|
1216
1244
|
path: `${metaPath}/:type/:name`,
|
|
@@ -1218,6 +1246,16 @@ var RestServer = class {
|
|
|
1218
1246
|
try {
|
|
1219
1247
|
const environmentId = isScoped ? req.params?.environmentId : void 0;
|
|
1220
1248
|
const p = await this.resolveProtocol(environmentId, req);
|
|
1249
|
+
const wantLayered = req.query?.layers !== void 0 && req.query?.layers !== "";
|
|
1250
|
+
if (wantLayered && typeof p.getMetaItemLayered === "function") {
|
|
1251
|
+
const layered = await p.getMetaItemLayered({
|
|
1252
|
+
type: req.params.type,
|
|
1253
|
+
name: req.params.name,
|
|
1254
|
+
...environmentId ? { environmentId } : {}
|
|
1255
|
+
});
|
|
1256
|
+
res.json(layered);
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1221
1259
|
if (metadata.enableCache && p.getMetaItemCached) {
|
|
1222
1260
|
const cacheRequest = {
|
|
1223
1261
|
ifNoneMatch: req.headers["if-none-match"],
|
|
@@ -1285,13 +1323,16 @@ var RestServer = class {
|
|
|
1285
1323
|
const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
|
|
1286
1324
|
const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
|
|
1287
1325
|
const actor = typeof actorHeader === "string" ? actorHeader : void 0;
|
|
1326
|
+
const forceRaw = req.query?.force;
|
|
1327
|
+
const force = typeof forceRaw === "string" ? ["true", "1", "yes", "on"].includes(forceRaw.toLowerCase()) : !!forceRaw;
|
|
1288
1328
|
const result = await p.saveMetaItem({
|
|
1289
1329
|
type: req.params.type,
|
|
1290
1330
|
name: req.params.name,
|
|
1291
1331
|
item,
|
|
1292
1332
|
...environmentId ? { environmentId } : {},
|
|
1293
1333
|
...parentVersion !== void 0 ? { parentVersion } : {},
|
|
1294
|
-
...actor ? { actor } : {}
|
|
1334
|
+
...actor ? { actor } : {},
|
|
1335
|
+
...force ? { force: true } : {}
|
|
1295
1336
|
});
|
|
1296
1337
|
res.json(result);
|
|
1297
1338
|
} catch (error) {
|