@objectstack/rest 4.2.0 → 5.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/dist/index.js CHANGED
@@ -1114,11 +1114,17 @@ var RestServer = class {
1114
1114
  }
1115
1115
  const body = req.body ?? {};
1116
1116
  const item = body && typeof body === "object" && "metadata" in body ? body.metadata : body && typeof body === "object" && "item" in body ? body.item : body;
1117
+ const ifMatchHeader = req.headers?.["if-match"] ?? req.headers?.["If-Match"];
1118
+ const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
1119
+ const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
1120
+ const actor = typeof actorHeader === "string" ? actorHeader : void 0;
1117
1121
  const result = await p.saveMetaItem({
1118
1122
  type: req.params.type,
1119
1123
  name: req.params.name,
1120
1124
  item,
1121
- ...projectId ? { projectId } : {}
1125
+ ...projectId ? { projectId } : {},
1126
+ ...parentVersion !== void 0 ? { parentVersion } : {},
1127
+ ...actor ? { actor } : {}
1122
1128
  });
1123
1129
  res.json(result);
1124
1130
  } catch (error) {
@@ -1144,10 +1150,16 @@ var RestServer = class {
1144
1150
  });
1145
1151
  return;
1146
1152
  }
1153
+ const ifMatchHeader = req.headers?.["if-match"] ?? req.headers?.["If-Match"];
1154
+ const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
1155
+ const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
1156
+ const actor = typeof actorHeader === "string" ? actorHeader : void 0;
1147
1157
  const result = await p.deleteMetaItem({
1148
1158
  type: req.params.type,
1149
1159
  name: req.params.name,
1150
- ...projectId ? { projectId } : {}
1160
+ ...projectId ? { projectId } : {},
1161
+ ...parentVersion !== void 0 ? { parentVersion } : {},
1162
+ ...actor ? { actor } : {}
1151
1163
  });
1152
1164
  res.json(result);
1153
1165
  } catch (error) {
@@ -1160,6 +1172,39 @@ var RestServer = class {
1160
1172
  tags: ["metadata"]
1161
1173
  }
1162
1174
  });
1175
+ this.routeManager.register({
1176
+ method: "GET",
1177
+ path: `${metaPath}/:type/:name/history`,
1178
+ handler: async (req, res) => {
1179
+ try {
1180
+ const projectId = isScoped ? req.params?.projectId : void 0;
1181
+ const p = await this.resolveProtocol(projectId, req);
1182
+ if (!p.historyMetaItem) {
1183
+ res.status(501).json({
1184
+ error: "History query not supported by protocol implementation"
1185
+ });
1186
+ return;
1187
+ }
1188
+ const sinceSeq = req.query?.sinceSeq !== void 0 ? Number(req.query.sinceSeq) : void 0;
1189
+ const limit = req.query?.limit !== void 0 ? Number(req.query.limit) : void 0;
1190
+ const result = await p.historyMetaItem({
1191
+ type: req.params.type,
1192
+ name: req.params.name,
1193
+ ...projectId ? { projectId } : {},
1194
+ ...sinceSeq !== void 0 && Number.isFinite(sinceSeq) ? { sinceSeq } : {},
1195
+ ...limit !== void 0 && Number.isFinite(limit) ? { limit } : {}
1196
+ });
1197
+ res.json(result);
1198
+ } catch (error) {
1199
+ logError("[REST] Unhandled error:", error);
1200
+ sendError(res, error);
1201
+ }
1202
+ },
1203
+ metadata: {
1204
+ summary: "List durable history events for a metadata item",
1205
+ tags: ["metadata"]
1206
+ }
1207
+ });
1163
1208
  if (metadata.endpoints.item !== false) {
1164
1209
  this.routeManager.register({
1165
1210
  method: "GET",
@@ -1200,11 +1245,17 @@ var RestServer = class {
1200
1245
  return;
1201
1246
  }
1202
1247
  const compoundName = `${req.params.section}/${req.params.name}`;
1248
+ const ifMatchHeader = req.headers?.["if-match"] ?? req.headers?.["If-Match"];
1249
+ const parentVersion = typeof ifMatchHeader === "string" ? ifMatchHeader.replace(/^"|"$/g, "") : void 0;
1250
+ const actorHeader = req.headers?.["x-actor"] ?? req.headers?.["X-Actor"] ?? req.user?.id ?? req.userId;
1251
+ const actor = typeof actorHeader === "string" ? actorHeader : void 0;
1203
1252
  const result = await p.saveMetaItem({
1204
1253
  type: req.params.type,
1205
1254
  name: compoundName,
1206
1255
  item: req.body,
1207
- ...projectId ? { projectId } : {}
1256
+ ...projectId ? { projectId } : {},
1257
+ ...parentVersion !== void 0 ? { parentVersion } : {},
1258
+ ...actor ? { actor } : {}
1208
1259
  });
1209
1260
  res.json(result);
1210
1261
  } catch (error) {