@objectstack/rest 4.2.0 → 5.0.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/dist/index.cjs CHANGED
@@ -1153,11 +1153,17 @@ var RestServer = class {
1153
1153
  }
1154
1154
  const body = req.body ?? {};
1155
1155
  const item = body && typeof body === "object" && "metadata" in body ? body.metadata : body && typeof body === "object" && "item" in body ? body.item : body;
1156
+ const ifMatchHeader = req.headers?.["if-match"] ?? req.headers?.["If-Match"];
1157
+ const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
1158
+ const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
1159
+ const actor = typeof actorHeader === "string" ? actorHeader : void 0;
1156
1160
  const result = await p.saveMetaItem({
1157
1161
  type: req.params.type,
1158
1162
  name: req.params.name,
1159
1163
  item,
1160
- ...projectId ? { projectId } : {}
1164
+ ...projectId ? { projectId } : {},
1165
+ ...parentVersion !== void 0 ? { parentVersion } : {},
1166
+ ...actor ? { actor } : {}
1161
1167
  });
1162
1168
  res.json(result);
1163
1169
  } catch (error) {
@@ -1183,10 +1189,16 @@ var RestServer = class {
1183
1189
  });
1184
1190
  return;
1185
1191
  }
1192
+ const ifMatchHeader = req.headers?.["if-match"] ?? req.headers?.["If-Match"];
1193
+ const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
1194
+ const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
1195
+ const actor = typeof actorHeader === "string" ? actorHeader : void 0;
1186
1196
  const result = await p.deleteMetaItem({
1187
1197
  type: req.params.type,
1188
1198
  name: req.params.name,
1189
- ...projectId ? { projectId } : {}
1199
+ ...projectId ? { projectId } : {},
1200
+ ...parentVersion !== void 0 ? { parentVersion } : {},
1201
+ ...actor ? { actor } : {}
1190
1202
  });
1191
1203
  res.json(result);
1192
1204
  } catch (error) {
@@ -1199,6 +1211,39 @@ var RestServer = class {
1199
1211
  tags: ["metadata"]
1200
1212
  }
1201
1213
  });
1214
+ this.routeManager.register({
1215
+ method: "GET",
1216
+ path: `${metaPath}/:type/:name/history`,
1217
+ handler: async (req, res) => {
1218
+ try {
1219
+ const projectId = isScoped ? req.params?.projectId : void 0;
1220
+ const p = await this.resolveProtocol(projectId, req);
1221
+ if (!p.historyMetaItem) {
1222
+ res.status(501).json({
1223
+ error: "History query not supported by protocol implementation"
1224
+ });
1225
+ return;
1226
+ }
1227
+ const sinceSeq = req.query?.sinceSeq !== void 0 ? Number(req.query.sinceSeq) : void 0;
1228
+ const limit = req.query?.limit !== void 0 ? Number(req.query.limit) : void 0;
1229
+ const result = await p.historyMetaItem({
1230
+ type: req.params.type,
1231
+ name: req.params.name,
1232
+ ...projectId ? { projectId } : {},
1233
+ ...sinceSeq !== void 0 && Number.isFinite(sinceSeq) ? { sinceSeq } : {},
1234
+ ...limit !== void 0 && Number.isFinite(limit) ? { limit } : {}
1235
+ });
1236
+ res.json(result);
1237
+ } catch (error) {
1238
+ logError("[REST] Unhandled error:", error);
1239
+ sendError(res, error);
1240
+ }
1241
+ },
1242
+ metadata: {
1243
+ summary: "List durable history events for a metadata item",
1244
+ tags: ["metadata"]
1245
+ }
1246
+ });
1202
1247
  if (metadata.endpoints.item !== false) {
1203
1248
  this.routeManager.register({
1204
1249
  method: "GET",
@@ -1239,11 +1284,17 @@ var RestServer = class {
1239
1284
  return;
1240
1285
  }
1241
1286
  const compoundName = `${req.params.section}/${req.params.name}`;
1287
+ const ifMatchHeader = req.headers?.["if-match"] ?? req.headers?.["If-Match"];
1288
+ const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
1289
+ const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
1290
+ const actor = typeof actorHeader === "string" ? actorHeader : void 0;
1242
1291
  const result = await p.saveMetaItem({
1243
1292
  type: req.params.type,
1244
1293
  name: compoundName,
1245
1294
  item: req.body,
1246
- ...projectId ? { projectId } : {}
1295
+ ...projectId ? { projectId } : {},
1296
+ ...parentVersion !== void 0 ? { parentVersion } : {},
1297
+ ...actor ? { actor } : {}
1247
1298
  });
1248
1299
  res.json(result);
1249
1300
  } catch (error) {