@sequenceholdings/orm 2.2.0 → 2.3.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/cli.cjs CHANGED
@@ -1429,14 +1429,20 @@ function requiredArtifactIrVersion(operations) {
1429
1429
  var CLAIMS_CONTRACT = {
1430
1430
  sub: "string",
1431
1431
  org: "string?",
1432
+ ext_subject: "string?",
1433
+ ext_email: "string?",
1432
1434
  roles: "string[]",
1433
1435
  capabilities: "string[]"
1434
1436
  };
1437
+ var EXTERNAL_POLICY_CLAIM_KEYS = ["ext_subject", "ext_email"];
1438
+ function isExternalPolicyClaimKey(key) {
1439
+ return EXTERNAL_POLICY_CLAIM_KEYS.includes(key);
1440
+ }
1435
1441
  var scalarLiteral = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]);
1436
1442
  var valueIrSchema = zod.z.discriminatedUnion("kind", [
1437
1443
  zod.z.object({ kind: zod.z.literal("literal"), value: zod.z.union([scalarLiteral, zod.z.array(scalarLiteral)]) }),
1438
1444
  zod.z.object({ kind: zod.z.literal("variable"), name: zod.z.string() }),
1439
- zod.z.object({ kind: zod.z.literal("claim"), key: zod.z.enum(["sub", "org"]) })
1445
+ zod.z.object({ kind: zod.z.literal("claim"), key: zod.z.enum(["sub", "org", ...EXTERNAL_POLICY_CLAIM_KEYS]) })
1440
1446
  ]);
1441
1447
  var CMP_OPS = [
1442
1448
  "eq",
@@ -2353,6 +2359,7 @@ var PolicyCompiler = class {
2353
2359
  case "or":
2354
2360
  return { kind: node.kind, operands: node.operands.map((operand) => this.compile(operand, table, depth)) };
2355
2361
  case "not":
2362
+ assertNoNegatedExternalClaim(node.operand);
2356
2363
  return { kind: "not", operand: this.compile(node.operand, table, depth) };
2357
2364
  case "capability":
2358
2365
  return { kind: "capability", key: node.key };
@@ -2432,6 +2439,9 @@ var PolicyCompiler = class {
2432
2439
  columnCandidates(info)
2433
2440
  );
2434
2441
  }
2442
+ if (valueSide.kind === "claim" && isExternalPolicyClaimKey(valueSide.key)) {
2443
+ assertExternalClaimComparison({ op, key: valueSide.key, column: info.columns.find((c) => c.name === column) });
2444
+ }
2435
2445
  let cmp = this.buildCmp(op, column, valueSide);
2436
2446
  for (let i = links.length - 1; i >= 0; i -= 1) {
2437
2447
  cmp = { kind: "exists", link: links[i].name, where: cmp };
@@ -2452,6 +2462,33 @@ var PolicyCompiler = class {
2452
2462
  return { kind: "cmp", op: CMP_BY_OP[op], column, value };
2453
2463
  }
2454
2464
  };
2465
+ function assertExternalClaimComparison({ op, key, column }) {
2466
+ if (op !== "=") {
2467
+ throw new PolicyCompileError(
2468
+ `claim('${key}') supports = comparisons only, got '${op}'`,
2469
+ "unsupported-comparison"
2470
+ );
2471
+ }
2472
+ if (column?.type !== "text") {
2473
+ const actual = column?.type === void 0 ? "of unknown type" : typeof column.type === "string" ? column.type : "an enum";
2474
+ throw new PolicyCompileError(
2475
+ `claim('${key}') is text and compares to a text column only \u2014 '${column?.name ?? "?"}' is ${actual}`,
2476
+ "claim-type-mismatch"
2477
+ );
2478
+ }
2479
+ }
2480
+ function assertNoNegatedExternalClaim(operand) {
2481
+ walkPolicy(operand, (node) => {
2482
+ if (node.kind !== "compare") return;
2483
+ const claim = [node.left, node.right].find((side) => side.kind === "claim" && isExternalPolicyClaimKey(side.key));
2484
+ if (claim?.kind === "claim") {
2485
+ throw new PolicyCompileError(
2486
+ `claim('${claim.key}') cannot appear under not(): a negated borrower comparison admits other borrowers' rows`,
2487
+ "unsupported-comparison"
2488
+ );
2489
+ }
2490
+ });
2491
+ }
2455
2492
  function compilePredicateV2({ expression, table, resolver, maxLinkDepth }) {
2456
2493
  const parsed = typeof expression === "string" ? parsePolicy(expression) : expression;
2457
2494
  const compiler = new PolicyCompiler({ resolver, maxLinkDepth: maxLinkDepth ?? POLICY_MAX_LINK_DEPTH });