@powerhousedao/powerhouse-vetra-packages 6.2.2-dev.42 → 6.2.2-dev.44

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.
Files changed (72) hide show
  1. package/dist/browser/assets/{entry-Db_lIhQq.js → entry-C2ClkbVN.js} +2 -2
  2. package/dist/browser/assets/{projection-entry-DqgHaUSy.js → projection-entry-S39DdeT-.js} +3 -3
  3. package/dist/browser/{linting-_AQWr8aE.js → button-CuO8Gh3v.js} +17 -4
  4. package/dist/browser/button-CuO8Gh3v.js.map +1 -0
  5. package/dist/browser/{connect-BUnNjGUW.js → connect-70_1bgIZ.js} +49 -7
  6. package/dist/browser/{connect-BUnNjGUW.js.map → connect-70_1bgIZ.js.map} +1 -1
  7. package/dist/browser/{dist-BatmWBzA.js → dist-CXIjN0Ex.js} +150 -25
  8. package/dist/browser/dist-CXIjN0Ex.js.map +1 -0
  9. package/dist/browser/{document-drive-D3Z9vXTQ.js → document-drive-PYPIaEvw.js} +197 -13
  10. package/dist/browser/document-drive-PYPIaEvw.js.map +1 -0
  11. package/dist/browser/document-models/index.js +1 -1
  12. package/dist/browser/{editor-BLeFoOh6.js → editor-DOJeQKlN.js} +5 -5
  13. package/dist/browser/{editor-BLeFoOh6.js.map → editor-DOJeQKlN.js.map} +1 -1
  14. package/dist/browser/{editor-Bn6uXvxG.js → editor-QW6D3wl8.js} +668 -101
  15. package/dist/browser/editor-QW6D3wl8.js.map +1 -0
  16. package/dist/browser/editors/document-model-editor/module.js +1 -1
  17. package/dist/browser/editors/generic-drive-explorer/index.js +4 -4
  18. package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
  19. package/dist/browser/{folder-view-DNzFnfW2.js → folder-view-VM5cJbvv.js} +29 -10
  20. package/dist/browser/folder-view-VM5cJbvv.js.map +1 -0
  21. package/dist/browser/{graphql-editor-DWo8N_z4.js → graphql-editor-CjpiNMV0.js} +3 -3
  22. package/dist/browser/{graphql-editor-DWo8N_z4.js.map → graphql-editor-CjpiNMV0.js.map} +1 -1
  23. package/dist/browser/index.js +378 -9
  24. package/dist/browser/index.js.map +1 -1
  25. package/dist/browser/{json-editor-CEugjpFj.js → json-editor-CeIHor4v.js} +3 -3
  26. package/dist/browser/{json-editor-CEugjpFj.js.map → json-editor-CeIHor4v.js.map} +1 -1
  27. package/dist/browser/{lib-CiaHsAaR.js → lib-PZlA5c3e.js} +2 -2
  28. package/dist/browser/lib-PZlA5c3e.js.map +1 -0
  29. package/dist/browser/{state-schemas-VrticHe4.js → state-schemas-CbPirA44.js} +5 -15
  30. package/dist/browser/state-schemas-CbPirA44.js.map +1 -0
  31. package/dist/node/{linting-BjvRPjCY.mjs → button-Da7CxMn7.mjs} +17 -4
  32. package/dist/node/button-Da7CxMn7.mjs.map +1 -0
  33. package/dist/node/{connect-wMkkAckX.mjs → connect-CkBYxX_q.mjs} +49 -7
  34. package/dist/node/{connect-wMkkAckX.mjs.map → connect-CkBYxX_q.mjs.map} +1 -1
  35. package/dist/node/{dist-CUHBOv3P.mjs → dist-CS8QwZwZ.mjs} +150 -25
  36. package/dist/node/dist-CS8QwZwZ.mjs.map +1 -0
  37. package/dist/node/{document-drive-CI0J7nMj.mjs → document-drive-DrBAR9as.mjs} +197 -13
  38. package/dist/node/document-drive-DrBAR9as.mjs.map +1 -0
  39. package/dist/node/document-models/index.mjs +1 -1
  40. package/dist/node/{editor-Cr-mNQca.mjs → editor-ClZqmnoh.mjs} +670 -103
  41. package/dist/node/editor-ClZqmnoh.mjs.map +1 -0
  42. package/dist/node/{editor-aIeTo2EE.mjs → editor-Dv22q5WR.mjs} +5 -5
  43. package/dist/node/{editor-aIeTo2EE.mjs.map → editor-Dv22q5WR.mjs.map} +1 -1
  44. package/dist/node/editors/document-model-editor/module.mjs +1 -1
  45. package/dist/node/editors/generic-drive-explorer/index.mjs +4 -4
  46. package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
  47. package/dist/node/{folder-view-_x1OBYZN.mjs → folder-view-6H-dMp8X.mjs} +29 -10
  48. package/dist/node/folder-view-6H-dMp8X.mjs.map +1 -0
  49. package/dist/node/{graphql-editor-Dd2_z5QJ.mjs → graphql-editor-DP0o3W7f.mjs} +3 -3
  50. package/dist/node/{graphql-editor-Dd2_z5QJ.mjs.map → graphql-editor-DP0o3W7f.mjs.map} +1 -1
  51. package/dist/node/index.mjs +378 -9
  52. package/dist/node/index.mjs.map +1 -1
  53. package/dist/node/{json-editor-Dphg6ZeL.mjs → json-editor-CNbnXYz6.mjs} +3 -3
  54. package/dist/node/{json-editor-Dphg6ZeL.mjs.map → json-editor-CNbnXYz6.mjs.map} +1 -1
  55. package/dist/node/{main-Db0ei9wX.mjs → main-aITg389Z.mjs} +2 -2
  56. package/dist/node/main-aITg389Z.mjs.map +1 -0
  57. package/dist/node/{state-schemas-BSLgTw2O.mjs → state-schemas-CylQoH3Q.mjs} +6 -16
  58. package/dist/{browser/state-schemas-VrticHe4.js.map → node/state-schemas-CylQoH3Q.mjs.map} +1 -1
  59. package/package.json +7 -6
  60. package/dist/browser/dist-BatmWBzA.js.map +0 -1
  61. package/dist/browser/document-drive-D3Z9vXTQ.js.map +0 -1
  62. package/dist/browser/editor-Bn6uXvxG.js.map +0 -1
  63. package/dist/browser/folder-view-DNzFnfW2.js.map +0 -1
  64. package/dist/browser/lib-CiaHsAaR.js.map +0 -1
  65. package/dist/browser/linting-_AQWr8aE.js.map +0 -1
  66. package/dist/node/dist-CUHBOv3P.mjs.map +0 -1
  67. package/dist/node/document-drive-CI0J7nMj.mjs.map +0 -1
  68. package/dist/node/editor-Cr-mNQca.mjs.map +0 -1
  69. package/dist/node/folder-view-_x1OBYZN.mjs.map +0 -1
  70. package/dist/node/linting-BjvRPjCY.mjs.map +0 -1
  71. package/dist/node/main-Db0ei9wX.mjs.map +0 -1
  72. package/dist/node/state-schemas-BSLgTw2O.mjs.map +0 -1
@@ -3107,6 +3107,25 @@ var HashMismatchError = class extends Error {
3107
3107
  return this._operation;
3108
3108
  }
3109
3109
  };
3110
+ /**
3111
+ * Thrown when replay or import requires a document model version that is not
3112
+ * registered. Carries the data the UI needs to explain the mismatch.
3113
+ */
3114
+ var UnsupportedDocumentModelVersionError = class extends Error {
3115
+ documentType;
3116
+ requiredVersion;
3117
+ availableVersions;
3118
+ constructor(documentType, requiredVersion, availableVersions) {
3119
+ super(`No reducer registered for document version ${requiredVersion}. Available versions: ${availableVersions.join(", ")}`);
3120
+ this.name = "UnsupportedDocumentModelVersionError";
3121
+ this.documentType = documentType;
3122
+ this.requiredVersion = requiredVersion;
3123
+ this.availableVersions = availableVersions;
3124
+ }
3125
+ static isError(error) {
3126
+ return Error.isError(error) && error.name === "UnsupportedDocumentModelVersionError";
3127
+ }
3128
+ };
3110
3129
  const isDefinedNonNullAny$1 = (v) => v !== void 0 && v !== null;
3111
3130
  any().refine((v) => isDefinedNonNullAny$1(v));
3112
3131
  const Load_StateSchema = _enum(["LOAD_STATE"]);
@@ -4107,7 +4126,7 @@ function assertValidGrant(grant, documentType) {
4107
4126
  const grantId = isPlainValue(grant) && typeof grant.id === "string" ? grant.id : "";
4108
4127
  const problem = grantProblem(grant);
4109
4128
  if (problem !== null) throw new InvalidGrantError(grantId, problem);
4110
- if (documentType === "@powerhousedao/document-group" && "group" in grant.principal) throw new GroupPrincipalNotAllowedError(grantId);
4129
+ if (documentType === "powerhouse/reactor-group" && "group" in grant.principal) throw new GroupPrincipalNotAllowedError(grantId);
4111
4130
  }
4112
4131
  /**
4113
4132
  * Validates an initial grant list: the count cap, every grant, and — on a
@@ -4181,6 +4200,158 @@ function assertAuthAdministrationRetained(creator, previous, next, grantId) {
4181
4200
  if (creator !== void 0) return;
4182
4201
  if (administrationReachable(previous) && !administrationReachable(next)) throw new AuthAdministrationLockoutError(grantId);
4183
4202
  }
4203
+ /**
4204
+ * An operand whose shape validation would have rejected. Distinguished from
4205
+ * an unresolved path so a structurally malformed operand poisons its whole
4206
+ * condition to false rather than reading as "absent", which `not` would
4207
+ * otherwise widen to true.
4208
+ */
4209
+ const INVALID_OPERAND = Symbol("invalid-operand");
4210
+ /**
4211
+ * Narrows to the values conditions compare. An object, array, or non-finite
4212
+ * number resolves to undefined, and every comparison involving undefined is
4213
+ * false.
4214
+ */
4215
+ function asConditionValue(value) {
4216
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
4217
+ if (typeof value === "number" && Number.isFinite(value)) return value;
4218
+ }
4219
+ /**
4220
+ * Resolves one operand. Attr roots: `subject.*`, `doc.<scope>.*` where the
4221
+ * scope must be the executing scope (validation already rejects any other,
4222
+ * but resolution stays total), and `action.input.*`. Path steps read own
4223
+ * properties only, so prototype members can never influence a verdict.
4224
+ */
4225
+ function resolveOperand(operand, subject, request, conditions) {
4226
+ if (!isPlainValue(operand)) return INVALID_OPERAND;
4227
+ const keys = Object.keys(operand);
4228
+ if (keys.length !== 1) return INVALID_OPERAND;
4229
+ if (keys[0] === "lit") {
4230
+ const value = asConditionValue(operand.lit);
4231
+ return value === void 0 ? INVALID_OPERAND : value;
4232
+ }
4233
+ if (keys[0] !== "attr") return INVALID_OPERAND;
4234
+ const attr = operand.attr;
4235
+ if (typeof attr !== "string" || attr.length === 0) return INVALID_OPERAND;
4236
+ const path = attr.split(".");
4237
+ let value;
4238
+ let rest;
4239
+ if (path[0] === "subject") {
4240
+ value = subject;
4241
+ rest = path.slice(1);
4242
+ } else if (path[0] === "doc") {
4243
+ if (path[1] !== request.scope) return;
4244
+ value = conditions.scopeState;
4245
+ rest = path.slice(2);
4246
+ } else if (path[0] === "action" && path[1] === "input") {
4247
+ value = conditions.actionInput;
4248
+ rest = path.slice(2);
4249
+ } else return;
4250
+ for (const segment of rest) {
4251
+ if (!isPlainValue(value) || !Object.hasOwn(value, segment)) return;
4252
+ value = value[segment];
4253
+ }
4254
+ return asConditionValue(value);
4255
+ }
4256
+ /**
4257
+ * Total order within one type: numbers numerically, strings by code point.
4258
+ * Everything else, including mixed types, does not order.
4259
+ */
4260
+ function compareValues(left, right) {
4261
+ if (typeof left === "number" && typeof right === "number") return left < right ? -1 : left > right ? 1 : 0;
4262
+ if (typeof left === "string" && typeof right === "string") {
4263
+ const leftPoints = Array.from(left);
4264
+ const rightPoints = Array.from(right);
4265
+ const shared = Math.min(leftPoints.length, rightPoints.length);
4266
+ for (let i = 0; i < shared; i++) {
4267
+ const a = leftPoints[i].codePointAt(0) ?? 0;
4268
+ const b = rightPoints[i].codePointAt(0) ?? 0;
4269
+ if (a !== b) return a < b ? -1 : 1;
4270
+ }
4271
+ return leftPoints.length === rightPoints.length ? 0 : leftPoints.length < rightPoints.length ? -1 : 1;
4272
+ }
4273
+ }
4274
+ /**
4275
+ * Tri-state evaluation: undefined marks a structurally invalid node, which
4276
+ * poisons the whole tree to false at the top — and a structurally malformed
4277
+ * operand poisons its condition the same way. Both are distinct from an
4278
+ * operand whose path fails to resolve, which is a valid comparison that is
4279
+ * false. The distinction keeps `not` from widening over malformed input.
4280
+ */
4281
+ function evaluateNode(node, subject, request, conditions) {
4282
+ if (!isPlainValue(node)) return;
4283
+ const keys = Object.keys(node);
4284
+ if (keys.length !== 1) return;
4285
+ const kind = keys[0];
4286
+ const body = node[kind];
4287
+ switch (kind) {
4288
+ case "eq":
4289
+ case "ne":
4290
+ case "lt":
4291
+ case "lte":
4292
+ case "gt":
4293
+ case "gte": {
4294
+ if (!Array.isArray(body) || body.length !== 2) return;
4295
+ const left = resolveOperand(body[0], subject, request, conditions);
4296
+ const right = resolveOperand(body[1], subject, request, conditions);
4297
+ if (left === INVALID_OPERAND || right === INVALID_OPERAND) return;
4298
+ if (left === void 0 || right === void 0) return false;
4299
+ if (kind === "eq") return left === right;
4300
+ if (kind === "ne") return left !== right;
4301
+ const order = compareValues(left, right);
4302
+ if (order === void 0) return false;
4303
+ switch (kind) {
4304
+ case "lt": return order < 0;
4305
+ case "lte": return order <= 0;
4306
+ case "gt": return order > 0;
4307
+ case "gte": return order >= 0;
4308
+ }
4309
+ return;
4310
+ }
4311
+ case "in":
4312
+ case "notIn": {
4313
+ if (!Array.isArray(body) || body.length !== 2 || !Array.isArray(body[1])) return;
4314
+ const left = resolveOperand(body[0], subject, request, conditions);
4315
+ if (left === INVALID_OPERAND) return;
4316
+ const elements = body[1].map((element) => resolveOperand(element, subject, request, conditions));
4317
+ if (elements.some((value) => value === INVALID_OPERAND)) return;
4318
+ if (left === void 0) return false;
4319
+ const found = elements.some((value) => value !== void 0 && value === left);
4320
+ return kind === "in" ? found : !found;
4321
+ }
4322
+ case "exists": {
4323
+ const value = resolveOperand(body, subject, request, conditions);
4324
+ if (value === INVALID_OPERAND) return;
4325
+ return value !== void 0;
4326
+ }
4327
+ case "and":
4328
+ case "or": {
4329
+ if (!Array.isArray(body)) return;
4330
+ let result = kind === "and";
4331
+ for (const child of body) {
4332
+ const value = evaluateNode(child, subject, request, conditions);
4333
+ if (value === void 0) return;
4334
+ if (kind === "and") result = result && value;
4335
+ else result = result || value;
4336
+ }
4337
+ return result;
4338
+ }
4339
+ case "not": {
4340
+ const value = evaluateNode(body, subject, request, conditions);
4341
+ return value === void 0 ? void 0 : !value;
4342
+ }
4343
+ default: return;
4344
+ }
4345
+ }
4346
+ /**
4347
+ * Evaluates a version-1 condition. Deterministic, total, and pure: any input
4348
+ * shape yields a boolean and never throws, and a malformed condition is
4349
+ * false. These are consensus semantics, versioned by `PHAuthState.version`;
4350
+ * changing them requires a new version.
4351
+ */
4352
+ function evaluateCondition(condition, subject, request, conditions) {
4353
+ return evaluateNode(condition, subject, request, conditions) === true;
4354
+ }
4184
4355
  function capabilityCovers(capability, request) {
4185
4356
  if (capability.can !== request.verb) return false;
4186
4357
  const scope = capability.scope;
@@ -4191,21 +4362,37 @@ function capabilityCovers(capability, request) {
4191
4362
  }
4192
4363
  return true;
4193
4364
  }
4194
- function principalMatches(principal, subject) {
4365
+ function principalMatches(principal, subject, request, groups, conditions) {
4195
4366
  if ("anyone" in principal) return true;
4196
4367
  if ("address" in principal) return subject.address !== void 0 && subject.address.toLowerCase() === principal.address.toLowerCase();
4368
+ if ("group" in principal) {
4369
+ if (groups === void 0 || subject.address === void 0) return false;
4370
+ const group = groups[principal.group];
4371
+ if (group === void 0 || !Array.isArray(group.members)) return false;
4372
+ const address = subject.address.toLowerCase();
4373
+ return group.members.some((member) => member.toLowerCase() === address);
4374
+ }
4375
+ if ("match" in principal) {
4376
+ if (conditions === void 0) return false;
4377
+ return evaluateCondition(principal.match, subject, request, conditions);
4378
+ }
4197
4379
  return false;
4198
4380
  }
4199
4381
  /**
4200
4382
  * Evaluates a v1 grant stack: default deny, last applicable grant wins, and
4201
- * reports which grant decided it. Group and match principals and `where`
4202
- * conditions are not evaluated yet; a grant that uses any of them never applies.
4383
+ * reports which grant decided it. Group principals match only against a
4384
+ * supplied groups map, and `where` clauses and { match } principals evaluate
4385
+ * only against a supplied condition context; a grant that uses an unsupplied
4386
+ * feature never applies.
4203
4387
  */
4204
- function evaluateGrantStack(grants, subject, request) {
4388
+ function evaluateGrantStack(grants, subject, request, groups, conditions) {
4205
4389
  let applicable;
4206
4390
  for (const grant of grants) {
4207
- if (grant.where !== void 0) continue;
4208
- if (capabilityCovers(grant.capability, request) && principalMatches(grant.principal, subject)) applicable = grant;
4391
+ if (grant.where !== void 0) {
4392
+ if (conditions === void 0) continue;
4393
+ if (!evaluateCondition(grant.where, subject, request, conditions)) continue;
4394
+ }
4395
+ if (capabilityCovers(grant.capability, request) && principalMatches(grant.principal, subject, request, groups, conditions)) applicable = grant;
4209
4396
  }
4210
4397
  if (applicable === void 0) return {
4211
4398
  decision: "deny",
@@ -6826,10 +7013,7 @@ function replayDocumentVersioned(initialState, operations, config, header, dispa
6826
7013
  const segmentEndHashPerScope = /* @__PURE__ */ new Map();
6827
7014
  for (let k = 0; k <= validatedUpgrades.length; k++) {
6828
7015
  const reducer = config.reducers[currentVersion];
6829
- if (!reducer) {
6830
- const available = Object.keys(config.reducers).join(", ");
6831
- throw new Error(`No reducer registered for document version ${currentVersion}. Available versions: ${available}`);
6832
- }
7016
+ if (!reducer) throw new UnsupportedDocumentModelVersionError(header.documentType, currentVersion, Object.keys(config.reducers).map(Number).sort((a, b) => a - b));
6833
7017
  for (const s of replayScopes) {
6834
7018
  const ops = scopeOps[s] ?? [];
6835
7019
  const segStart = k === 0 ? 0 : boundaries[k - 1]?.[s] ?? 0;
@@ -8106,6 +8290,6 @@ const driveDocumentModelModule = {
8106
8290
  }
8107
8291
  };
8108
8292
  //#endregion
8109
- export { generateId as $, documentModelDocumentType as A, setModelId as B, createReducer as C, deleteModule as D, defaultBaseState as E, setAuthorName as F, setOperationErrorName as G, setModuleName as H, setAuthorWebsite as I, setStateSchema as J, setOperationName as K, setInitialState as L, isDocumentAction as M, redo as N, deleteOperation as O, replayDocumentVersioned as P, validateStateSchemaName as Q, setModelDescription as R, createPresignedHeader as S, createZip as T, setName as U, setModelName as V, setOperationDescription as W, validateInitialState as X, undo as Y, validateModules as Z, baseCreateDocument as _, handleTargetNameCollisions as a, baseSaveToFileHandle as b, isValidName as c, documentModelDocumentModelModule as d, logger as f, assertAuthPreservedOnDuplicate as g, addOperationError as h, generateNodesCopy as i, hashDocumentStateForScope as j, deleteOperationError as k, moveNode as l, addOperation as m, copyNode as n, isFileNode as o, addModule as p, setOperationSchema as q, driveDocumentModelModule as r, isFolderNode as s, addFolder as t, updateNode as u, baseLoadFromInput as v, createState as w, buildSignedAction as x, baseLoadFromInputVersioned as y, setModelExtension as z };
8293
+ export { setOperationSchema as $, createZip as A, replayDocumentVersioned as B, baseSaveToFileHandle as C, createPresignedHeader as D, createBaseState as E, documentModelDocumentType as F, setModelExtension as G, setAuthorWebsite as H, hashDocumentStateForScope as I, setModuleName as J, setModelId as K, isDocumentAction as L, deleteModule as M, deleteOperation as N, createReducer as O, deleteOperationError as P, setOperationName as Q, redo as R, baseLoadFromInputVersioned as S, createAction as T, setInitialState as U, setAuthorName as V, setModelDescription as W, setOperationDescription as X, setName as Y, setOperationErrorName as Z, addOperationError as _, handleTargetNameCollisions as a, generateId as at, baseCreateDocument as b, isValidName as c, documentModelDocumentModelModule as d, setStateSchema as et, logger as f, addOperation as g, addModule as h, generateNodesCopy as i, validateStateSchemaName as it, defaultBaseState as j, createState as k, moveNode as l, BaseDocumentStateSchema as m, copyNode as n, validateInitialState as nt, isFileNode as o, BaseDocumentHeaderSchema as p, setModelName as q, driveDocumentModelModule as r, validateModules as rt, isFolderNode as s, addFolder as t, undo as tt, updateNode as u, assertAuthPreservedOnDuplicate as v, buildSignedAction as w, baseLoadFromInput as x, baseActions as y, releaseNewVersion as z };
8110
8294
 
8111
- //# sourceMappingURL=document-drive-D3Z9vXTQ.js.map
8295
+ //# sourceMappingURL=document-drive-PYPIaEvw.js.map