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