@nxgt/janus 0.1.0 → 0.1.1

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 (38) hide show
  1. package/README.md +113 -24
  2. package/dist/auth/config.d.ts +3 -3
  3. package/dist/auth/config.d.ts.map +1 -1
  4. package/dist/auth/context.d.ts +1 -1
  5. package/dist/auth/context.d.ts.map +1 -1
  6. package/dist/auth/janus.d.ts +2 -2
  7. package/dist/auth/janus.d.ts.map +1 -1
  8. package/dist/auth/outage.d.ts +11 -17
  9. package/dist/auth/outage.d.ts.map +1 -1
  10. package/dist/auth/port/types.d.ts +6 -6
  11. package/dist/chunks/index-6p56fpbe.js.map +2 -2
  12. package/dist/chunks/{index-6dytvy3h.js → index-hm4v76kd.js} +7 -29
  13. package/dist/chunks/index-hm4v76kd.js.map +11 -0
  14. package/dist/conformance/assert.d.ts +1 -1
  15. package/dist/conformance/index.js +3 -3
  16. package/dist/conformance/index.js.map +5 -5
  17. package/dist/errors/janus-error.d.ts +1 -1
  18. package/dist/index.d.ts +9 -8
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +33 -12
  21. package/dist/index.js.map +7 -6
  22. package/dist/permissions/index.js +3 -3
  23. package/dist/permissions/index.js.map +4 -4
  24. package/dist/stores/guard.d.ts +24 -0
  25. package/dist/stores/guard.d.ts.map +1 -0
  26. package/dist/subjects/subject.d.ts +2 -2
  27. package/docs/README.md +19 -3
  28. package/docs/guide/adapters.md +4 -4
  29. package/docs/guide/errors.md +3 -3
  30. package/docs/guide/passwords.md +1 -1
  31. package/docs/guide/permissions.md +7 -2
  32. package/docs/guide/sessions.md +2 -2
  33. package/docs/guide/users.md +8 -7
  34. package/docs/guide/vocabulary.md +70 -3
  35. package/docs/roadmap.md +4 -4
  36. package/docs/troubleshooting.md +9 -9
  37. package/package.json +2 -2
  38. package/dist/chunks/index-6dytvy3h.js.map +0 -11
@@ -2,14 +2,14 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/permissions/resolve.ts", "../src/permissions/input.ts", "../src/permissions/model.ts", "../src/permissions/reverse.ts", "../src/permissions/walk.ts", "../src/permissions/engine.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * A model, resolved: every string parsed once, every reference checked, every\n * refusal a `TypeError` naming where it is.\n *\n * The types refuse most of these first. This is what refuses them for a model\n * built at run time or written in JavaScript, and what refuses what the types\n * cannot see: names, and a permission that reaches itself without crossing a\n * relation.\n */\n\nimport type { Subject } from '../subjects/subject';\nimport type { ModelConfig } from './model';\n\n/** Who may hold a stored relation: a subject type, or a subject set. */\nexport type Holder =\n\t| { readonly kind: 'type'; readonly type: string }\n\t| { readonly kind: 'set'; readonly type: string; readonly relation: string };\n\n/**\n * Whether a stored relation admits `subject` as a holder: an entity of a\n * declared type, or a set of a declared `type#relation`. One rule for what\n * `grant()` writes and what `can()` and `list()` follow — a tuple the model\n * does not admit grants nothing, however it was stored.\n */\nexport function admits(holders: readonly Holder[], subject: Subject): boolean {\n\treturn holders.some((holder) =>\n\t\tholder.kind === 'type'\n\t\t\t? !('relation' in subject) && holder.type === subject.type\n\t\t\t: 'relation' in subject &&\n\t\t\t\tholder.type === subject.type &&\n\t\t\t\tholder.relation === subject.relation,\n\t);\n}\n\nexport type ResolvedRelation =\n\t| { readonly kind: 'stored'; readonly holders: readonly Holder[] }\n\t| {\n\t\t\treadonly kind: 'fromField';\n\t\t\treadonly field: string;\n\t\t\treadonly subject: string;\n\t\t\t/** What `list()` reverses it with. Absent: `list()` cannot reach through it. */\n\t\t\treadonly lookup?: (subjectId: string) => Promise<readonly string[]>;\n\t };\n\n/** One rule of a permission. `test`, when present, must pass for it to grant. */\nexport type ResolvedRule = (\n\t| { readonly kind: 'name'; readonly name: string }\n\t| {\n\t\t\treadonly kind: 'arrow';\n\t\t\treadonly relation: string;\n\t\t\treadonly target: string;\n\t }\n) & { readonly test?: (ctx: never) => boolean };\n\nexport interface ResolvedObjectType {\n\treadonly name: string;\n\treadonly relations: ReadonlyMap<string, ResolvedRelation>;\n\treadonly permissions: ReadonlyMap<string, readonly ResolvedRule[]>;\n}\n\nexport interface ResolvedModel {\n\treadonly subjects: ReadonlySet<string>;\n\treadonly types: ReadonlyMap<string, ResolvedObjectType>;\n}\n\n/** camelCase, as every name in this package — and never `#`, `-`, `>` or `:`, which the notation uses. */\nconst NAME = /^[a-z][A-Za-z0-9]*$/;\n/** A field `fromField` reads: a top-level property. */\nconst FIELD = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport function resolveModel(\n\tconfig: ModelConfig,\n\twhere: string,\n): ResolvedModel {\n\tconst refuse = (message: string) => new TypeError(`${where}: ${message}`);\n\n\tif (!isRecord(config)) throw refuse('pass { subjects, types }');\n\tif (!Array.isArray(config.subjects)) {\n\t\tthrow refuse(\n\t\t\t'subjects must be an array of user types — pass auth.types from janus()',\n\t\t);\n\t}\n\tfor (const subject of config.subjects) {\n\t\tif (typeof subject !== 'string' || !NAME.test(subject)) {\n\t\t\tthrow refuse(\n\t\t\t\t`the subject type \"${String(subject)}\" must be a camelCase name`,\n\t\t\t);\n\t\t}\n\t}\n\tconst subjects = new Set<string>(config.subjects);\n\n\tif (!isRecord(config.types) || Object.keys(config.types).length === 0) {\n\t\tthrow refuse('types declares no object type');\n\t}\n\tconst typeNames = new Set(Object.keys(config.types));\n\tfor (const name of typeNames) {\n\t\tif (!NAME.test(name)) {\n\t\t\tthrow refuse(\n\t\t\t\t`the object type \"${name}\" must be a camelCase name — letters and digits, starting with a lowercase letter`,\n\t\t\t);\n\t\t}\n\t\tif (subjects.has(name)) {\n\t\t\tthrow refuse(\n\t\t\t\t`\"${name}\" names a user type and an object type; a subject of type \"${name}\" would be ambiguous`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// The relation names first: a subject set or an arrow may name a relation\n\t// of a type declared further down.\n\tconst relationNames = new Map<string, Set<string>>();\n\tconst permissionNames = new Map<string, Set<string>>();\n\tfor (const [name, def] of Object.entries(config.types)) {\n\t\tconst at = `types.${name}`;\n\t\tif (!isRecord(def)) throw refuse(`${at} must be an object`);\n\t\tfor (const key of Object.keys(def)) {\n\t\t\tif (key !== 'relations' && key !== 'permissions') {\n\t\t\t\tthrow refuse(`${at}.${key} is not a key of an object type`);\n\t\t\t}\n\t\t}\n\t\trelationNames.set(name, namesIn(def.relations, `${at}.relations`, refuse));\n\t\tconst permissions = namesIn(def.permissions, `${at}.permissions`, refuse);\n\t\tfor (const permission of permissions) {\n\t\t\tif (relationNames.get(name)?.has(permission)) {\n\t\t\t\tthrow refuse(\n\t\t\t\t\t`${at}: \"${permission}\" names a relation and a permission; rename one`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tpermissionNames.set(name, permissions);\n\t}\n\n\tconst isSubjectType = (type: string) =>\n\t\tsubjects.has(type) || typeNames.has(type);\n\tconst namesOf = (type: string) =>\n\t\tnew Set([\n\t\t\t...(relationNames.get(type) ?? []),\n\t\t\t...(permissionNames.get(type) ?? []),\n\t\t]);\n\n\tconst types = new Map<string, ResolvedObjectType>();\n\tfor (const [name, def] of Object.entries(config.types)) {\n\t\tconst at = `types.${name}`;\n\t\tconst relations = new Map<string, ResolvedRelation>();\n\n\t\tfor (const [relation, holders] of Object.entries(def.relations ?? {})) {\n\t\t\tconst here = `${at}.relations.${relation}`;\n\t\t\trelations.set(\n\t\t\t\trelation,\n\t\t\t\tresolveRelation(holders, here, {\n\t\t\t\t\trefuse,\n\t\t\t\t\tisSubjectType,\n\t\t\t\t\trelationNames,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst permissions = new Map<string, readonly ResolvedRule[]>();\n\t\tfor (const [permission, rules] of Object.entries(def.permissions ?? {})) {\n\t\t\tconst here = `${at}.permissions.${permission}`;\n\t\t\tif (!Array.isArray(rules) || rules.length === 0) {\n\t\t\t\tthrow refuse(`${here} must be a non-empty array of rules`);\n\t\t\t}\n\t\t\tpermissions.set(\n\t\t\t\tpermission,\n\t\t\t\trules.map((rule: unknown, index: number) =>\n\t\t\t\t\tresolveRule(rule, `${here}[${index}]`, {\n\t\t\t\t\t\trefuse,\n\t\t\t\t\t\town: namesOf(name),\n\t\t\t\t\t\trelations,\n\t\t\t\t\t\ttypeNames,\n\t\t\t\t\t\tnamesOf,\n\t\t\t\t\t\tself: name,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\ttypes.set(name, { name, relations, permissions });\n\t}\n\n\trefuseLoops(types, refuse);\n\trefuseDataBeyondRoot(types, refuse);\n\n\treturn { subjects, types };\n}\n\nfunction namesIn(\n\tvalue: unknown,\n\tat: string,\n\trefuse: (message: string) => TypeError,\n): Set<string> {\n\tif (value === undefined) return new Set();\n\tif (!isRecord(value)) throw refuse(`${at} must be an object`);\n\tfor (const name of Object.keys(value)) {\n\t\tif (!NAME.test(name)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${at}: \"${name}\" must be a camelCase name — letters and digits, starting with a lowercase letter`,\n\t\t\t);\n\t\t}\n\t}\n\treturn new Set(Object.keys(value));\n}\n\nfunction resolveRelation(\n\tvalue: unknown,\n\there: string,\n\t{\n\t\trefuse,\n\t\tisSubjectType,\n\t\trelationNames,\n\t}: {\n\t\trefuse: (message: string) => TypeError;\n\t\tisSubjectType: (type: string) => boolean;\n\t\trelationNames: ReadonlyMap<string, ReadonlySet<string>>;\n\t},\n): ResolvedRelation {\n\tif (isRecord(value) && value.kind === 'fromField') {\n\t\tconst { field, subject, lookup } = value;\n\t\tif (typeof field !== 'string' || !FIELD.test(field)) {\n\t\t\tthrow refuse(`${here}: fromField must name a top-level field`);\n\t\t}\n\t\tif (typeof subject !== 'string' || !isSubjectType(subject)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: fromField names \"${String(subject)}\", which is not a subject type`,\n\t\t\t);\n\t\t}\n\t\tif (lookup !== undefined && typeof lookup !== 'function') {\n\t\t\tthrow refuse(`${here}: fromField's lookup must be a function`);\n\t\t}\n\t\treturn lookup === undefined\n\t\t\t? { kind: 'fromField', field, subject }\n\t\t\t: {\n\t\t\t\t\tkind: 'fromField',\n\t\t\t\t\tfield,\n\t\t\t\t\tsubject,\n\t\t\t\t\tlookup: lookup as (subjectId: string) => Promise<readonly string[]>,\n\t\t\t\t};\n\t}\n\n\tif (!Array.isArray(value) || value.length === 0) {\n\t\tthrow refuse(\n\t\t\t`${here} must be a non-empty array of subject types, or fromField()`,\n\t\t);\n\t}\n\tconst holders = value.map((holder: unknown): Holder => {\n\t\tif (typeof holder !== 'string') {\n\t\t\tthrow refuse(`${here}: a holder must be a string`);\n\t\t}\n\t\tconst hash = holder.indexOf('#');\n\t\tif (hash < 0) {\n\t\t\tif (!isSubjectType(holder)) {\n\t\t\t\tthrow refuse(`${here}: \"${holder}\" is not a subject type`);\n\t\t\t}\n\t\t\treturn { kind: 'type', type: holder };\n\t\t}\n\t\tconst type = holder.slice(0, hash);\n\t\tconst relation = holder.slice(hash + 1);\n\t\tif (!relationNames.get(type)?.has(relation)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${holder}\" is not a subject set — it must name an object type and one of its relations`,\n\t\t\t);\n\t\t}\n\t\treturn { kind: 'set', type, relation };\n\t});\n\treturn { kind: 'stored', holders };\n}\n\nfunction resolveRule(\n\tvalue: unknown,\n\there: string,\n\tcontext: {\n\t\trefuse: (message: string) => TypeError;\n\t\town: ReadonlySet<string>;\n\t\trelations: ReadonlyMap<string, ResolvedRelation>;\n\t\ttypeNames: ReadonlySet<string>;\n\t\tnamesOf: (type: string) => ReadonlySet<string>;\n\t\tself: string;\n\t},\n): ResolvedRule {\n\tconst { refuse } = context;\n\n\tif (isRecord(value) && value.kind === 'when') {\n\t\tif (typeof value.test !== 'function') {\n\t\t\tthrow refuse(`${here}: when() takes a function as its test`);\n\t\t}\n\t\tconst inner = resolveRule(value.rule, here, context);\n\t\treturn { ...inner, test: value.test as (ctx: never) => boolean };\n\t}\n\tif (typeof value !== 'string') {\n\t\tthrow refuse(`${here}: a rule is a name, an arrow, or when()`);\n\t}\n\n\tconst arrow = value.indexOf('->');\n\tif (arrow < 0) {\n\t\tif (!context.own.has(value)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${value}\" is not a relation or a permission of ${context.self}`,\n\t\t\t);\n\t\t}\n\t\treturn { kind: 'name', name: value };\n\t}\n\n\tconst relation = value.slice(0, arrow);\n\tconst target = value.slice(arrow + 2);\n\tconst through = context.relations.get(relation);\n\tif (through === undefined) {\n\t\tthrow refuse(\n\t\t\t`${here}: \"${value}\" goes through \"${relation}\", which is not a relation of ${context.self}`,\n\t\t);\n\t}\n\tconst targets =\n\t\tthrough.kind === 'fromField'\n\t\t\t? [through.subject]\n\t\t\t: through.holders.map((holder) =>\n\t\t\t\t\tholder.kind === 'type' ? holder.type : null,\n\t\t\t\t);\n\tfor (const type of targets) {\n\t\t// A subject set, or a user type, has no permissions to follow.\n\t\tif (type === null || !context.typeNames.has(type)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${value}\" goes through \"${relation}\", which can hold ${type === null ? 'a subject set' : `a ${type}`}; an arrow follows object types only`,\n\t\t\t);\n\t\t}\n\t\tif (!context.namesOf(type).has(target)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${value}\" names \"${target}\", which ${type} does not declare`,\n\t\t\t);\n\t\t}\n\t}\n\treturn { kind: 'arrow', relation, target };\n}\n\n/**\n * A permission that reaches itself through names alone — `view: ['edit']`,\n * `edit: ['view']` — never reaches a relation, so no data could end the walk.\n * Refused here rather than cut at run time: it is a model's bug, not a\n * user's data.\n */\nfunction refuseLoops(\n\ttypes: ReadonlyMap<string, ResolvedObjectType>,\n\trefuse: (message: string) => TypeError,\n): void {\n\tfor (const type of types.values()) {\n\t\tconst visiting: string[] = [];\n\t\tconst done = new Set<string>();\n\n\t\tconst visit = (permission: string): void => {\n\t\t\tif (done.has(permission)) return;\n\t\t\tconst loop = visiting.indexOf(permission);\n\t\t\tif (loop >= 0) {\n\t\t\t\tthrow refuse(\n\t\t\t\t\t`types.${type.name}.permissions: ${[...visiting.slice(loop), permission].join(' → ')} is a loop no relation ends`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tvisiting.push(permission);\n\t\t\tfor (const rule of type.permissions.get(permission) ?? []) {\n\t\t\t\tif (rule.kind === 'name' && type.permissions.has(rule.name)) {\n\t\t\t\t\tvisit(rule.name);\n\t\t\t\t}\n\t\t\t}\n\t\t\tvisiting.pop();\n\t\t\tdone.add(permission);\n\t\t};\n\n\t\tfor (const permission of type.permissions.keys()) visit(permission);\n\t}\n}\n\n/**\n * A `fromField` is read from the object `can()` was given — the route loaded\n * it (decided 2026-09-24). An object reached through a subject set or an arrow\n * was loaded by nobody, so a rule that needs its data could never be decided.\n * Refused here, where it is a sentence, rather than at the first check that\n * reaches it, where it would be a denial nobody can explain.\n */\nfunction refuseDataBeyondRoot(\n\ttypes: ReadonlyMap<string, ResolvedObjectType>,\n\trefuse: (message: string) => TypeError,\n): void {\n\t/** The field `name` of `type` reads, directly or through its own rules; `null` when none. */\n\tconst fieldRead = (type: ResolvedObjectType, name: string): string | null => {\n\t\tconst relation = type.relations.get(name);\n\t\tif (relation !== undefined) {\n\t\t\treturn relation.kind === 'fromField' ? relation.field : null;\n\t\t}\n\t\tfor (const rule of type.permissions.get(name) ?? []) {\n\t\t\tconst field =\n\t\t\t\trule.kind === 'name'\n\t\t\t\t\t? fieldRead(type, rule.name)\n\t\t\t\t\t: // An arrow reads its own relation on this object.\n\t\t\t\t\t\tfieldRead(type, rule.relation);\n\t\t\tif (field !== null) return field;\n\t\t}\n\t\treturn null;\n\t};\n\n\tfor (const type of types.values()) {\n\t\tfor (const [relation, def] of type.relations) {\n\t\t\tif (def.kind !== 'stored') continue;\n\t\t\tfor (const holder of def.holders) {\n\t\t\t\tif (holder.kind !== 'set') continue;\n\t\t\t\tconst target = types.get(holder.type);\n\t\t\t\tconst field =\n\t\t\t\t\ttarget === undefined ? null : fieldRead(target, holder.relation);\n\t\t\t\tif (field !== null) {\n\t\t\t\t\tthrow refuse(\n\t\t\t\t\t\t`types.${type.name}.relations.${relation}: \"${holder.type}#${holder.relation}\" reads ${holder.type}.${field}, and a subject set reaches ${holder.type}s nobody passed to can() — store that relation instead of reading it`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const [permission, rules] of type.permissions) {\n\t\t\tfor (const rule of rules) {\n\t\t\t\tif (rule.kind !== 'arrow') continue;\n\t\t\t\tconst through = type.relations.get(rule.relation);\n\t\t\t\tconst targets =\n\t\t\t\t\tthrough?.kind === 'fromField'\n\t\t\t\t\t\t? [through.subject]\n\t\t\t\t\t\t: (through?.holders ?? []).map((holder) => holder.type);\n\t\t\t\tfor (const name of targets) {\n\t\t\t\t\tconst target = types.get(name);\n\t\t\t\t\tconst field =\n\t\t\t\t\t\ttarget === undefined ? null : fieldRead(target, rule.target);\n\t\t\t\t\tif (field !== null) {\n\t\t\t\t\t\tthrow refuse(\n\t\t\t\t\t\t\t`types.${type.name}.permissions.${permission}: \"${rule.relation}->${rule.target}\" reaches ${name}.${rule.target}, which reads ${name}.${field}, and only the object passed to can() carries its data — store that relation instead of reading it`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n",
5
+ "/**\n * A model, resolved: every string parsed once, every reference checked, every\n * refusal a `TypeError` naming where it is.\n *\n * The types refuse most of these first. This is what refuses them for a model\n * built at run time or written in JavaScript, and what refuses what the types\n * cannot see: names, and a permission that reaches itself without crossing a\n * relation.\n */\n\nimport type { Subject } from '../subjects/subject';\nimport type { ModelConfig } from './model';\n\n/** Who may hold a stored relation: a subject type, or a subject set. */\nexport type Holder =\n\t| { readonly kind: 'type'; readonly type: string }\n\t| { readonly kind: 'set'; readonly type: string; readonly relation: string };\n\n/**\n * Whether a stored relation admits `subject` as a holder: an entity of a\n * declared type, or a set of a declared `type#relation`. One rule for what\n * `grant()` writes and what `can()` and `list()` follow — a tuple the model\n * does not admit grants nothing, however it was stored.\n */\nexport function admits(holders: readonly Holder[], subject: Subject): boolean {\n\treturn holders.some((holder) =>\n\t\tholder.kind === 'type'\n\t\t\t? !('relation' in subject) && holder.type === subject.type\n\t\t\t: 'relation' in subject &&\n\t\t\t\tholder.type === subject.type &&\n\t\t\t\tholder.relation === subject.relation,\n\t);\n}\n\nexport type ResolvedRelation =\n\t| { readonly kind: 'stored'; readonly holders: readonly Holder[] }\n\t| {\n\t\t\treadonly kind: 'fromField';\n\t\t\treadonly field: string;\n\t\t\treadonly subject: string;\n\t\t\t/** What `list()` reverses it with. Absent: `list()` cannot reach through it. */\n\t\t\treadonly lookup?: (subjectId: string) => Promise<readonly string[]>;\n\t };\n\n/** One rule of a permission. `test`, when present, must pass for it to grant. */\nexport type ResolvedRule = (\n\t| { readonly kind: 'name'; readonly name: string }\n\t| {\n\t\t\treadonly kind: 'arrow';\n\t\t\treadonly relation: string;\n\t\t\treadonly target: string;\n\t }\n) & { readonly test?: (ctx: never) => boolean };\n\nexport interface ResolvedObjectType {\n\treadonly name: string;\n\treadonly relations: ReadonlyMap<string, ResolvedRelation>;\n\treadonly permissions: ReadonlyMap<string, readonly ResolvedRule[]>;\n}\n\nexport interface ResolvedModel {\n\treadonly subjects: ReadonlySet<string>;\n\treadonly types: ReadonlyMap<string, ResolvedObjectType>;\n}\n\n/** camelCase, as every name in this package — and never `#`, `-`, `>` or `:`, which the notation uses. */\nconst NAME = /^[a-z][A-Za-z0-9]*$/;\n/** A field `fromField` reads: a top-level property. */\nconst FIELD = /^[A-Za-z_$][A-Za-z0-9_$]*$/;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value);\n\nexport function resolveModel(\n\tconfig: ModelConfig,\n\twhere: string,\n): ResolvedModel {\n\tconst refuse = (message: string) => new TypeError(`${where}: ${message}`);\n\n\tif (!isRecord(config)) throw refuse('pass { subjects, types }');\n\tif (!Array.isArray(config.subjects)) {\n\t\tthrow refuse(\n\t\t\t'subjects must be an array of subject type names — auth.types from janus(), or your own',\n\t\t);\n\t}\n\tfor (const subject of config.subjects) {\n\t\tif (typeof subject !== 'string' || !NAME.test(subject)) {\n\t\t\tthrow refuse(\n\t\t\t\t`the subject type \"${String(subject)}\" must be a camelCase name`,\n\t\t\t);\n\t\t}\n\t}\n\tconst subjects = new Set<string>(config.subjects);\n\n\tif (!isRecord(config.types) || Object.keys(config.types).length === 0) {\n\t\tthrow refuse('types declares no object type');\n\t}\n\tconst typeNames = new Set(Object.keys(config.types));\n\tfor (const name of typeNames) {\n\t\tif (!NAME.test(name)) {\n\t\t\tthrow refuse(\n\t\t\t\t`the object type \"${name}\" must be a camelCase name — letters and digits, starting with a lowercase letter`,\n\t\t\t);\n\t\t}\n\t\tif (subjects.has(name)) {\n\t\t\tthrow refuse(\n\t\t\t\t`\"${name}\" names a user type and an object type; a subject of type \"${name}\" would be ambiguous`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// The relation names first: a subject set or an arrow may name a relation\n\t// of a type declared further down.\n\tconst relationNames = new Map<string, Set<string>>();\n\tconst permissionNames = new Map<string, Set<string>>();\n\tfor (const [name, def] of Object.entries(config.types)) {\n\t\tconst at = `types.${name}`;\n\t\tif (!isRecord(def)) throw refuse(`${at} must be an object`);\n\t\tfor (const key of Object.keys(def)) {\n\t\t\tif (key !== 'relations' && key !== 'permissions') {\n\t\t\t\tthrow refuse(`${at}.${key} is not a key of an object type`);\n\t\t\t}\n\t\t}\n\t\trelationNames.set(name, namesIn(def.relations, `${at}.relations`, refuse));\n\t\tconst permissions = namesIn(def.permissions, `${at}.permissions`, refuse);\n\t\tfor (const permission of permissions) {\n\t\t\tif (relationNames.get(name)?.has(permission)) {\n\t\t\t\tthrow refuse(\n\t\t\t\t\t`${at}: \"${permission}\" names a relation and a permission; rename one`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tpermissionNames.set(name, permissions);\n\t}\n\n\tconst isSubjectType = (type: string) =>\n\t\tsubjects.has(type) || typeNames.has(type);\n\tconst namesOf = (type: string) =>\n\t\tnew Set([\n\t\t\t...(relationNames.get(type) ?? []),\n\t\t\t...(permissionNames.get(type) ?? []),\n\t\t]);\n\n\tconst types = new Map<string, ResolvedObjectType>();\n\tfor (const [name, def] of Object.entries(config.types)) {\n\t\tconst at = `types.${name}`;\n\t\tconst relations = new Map<string, ResolvedRelation>();\n\n\t\tfor (const [relation, holders] of Object.entries(def.relations ?? {})) {\n\t\t\tconst here = `${at}.relations.${relation}`;\n\t\t\trelations.set(\n\t\t\t\trelation,\n\t\t\t\tresolveRelation(holders, here, {\n\t\t\t\t\trefuse,\n\t\t\t\t\tisSubjectType,\n\t\t\t\t\trelationNames,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tconst permissions = new Map<string, readonly ResolvedRule[]>();\n\t\tfor (const [permission, rules] of Object.entries(def.permissions ?? {})) {\n\t\t\tconst here = `${at}.permissions.${permission}`;\n\t\t\tif (!Array.isArray(rules) || rules.length === 0) {\n\t\t\t\tthrow refuse(`${here} must be a non-empty array of rules`);\n\t\t\t}\n\t\t\tpermissions.set(\n\t\t\t\tpermission,\n\t\t\t\trules.map((rule: unknown, index: number) =>\n\t\t\t\t\tresolveRule(rule, `${here}[${index}]`, {\n\t\t\t\t\t\trefuse,\n\t\t\t\t\t\town: namesOf(name),\n\t\t\t\t\t\trelations,\n\t\t\t\t\t\ttypeNames,\n\t\t\t\t\t\tnamesOf,\n\t\t\t\t\t\tself: name,\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\ttypes.set(name, { name, relations, permissions });\n\t}\n\n\trefuseLoops(types, refuse);\n\trefuseDataBeyondRoot(types, refuse);\n\n\treturn { subjects, types };\n}\n\nfunction namesIn(\n\tvalue: unknown,\n\tat: string,\n\trefuse: (message: string) => TypeError,\n): Set<string> {\n\tif (value === undefined) return new Set();\n\tif (!isRecord(value)) throw refuse(`${at} must be an object`);\n\tfor (const name of Object.keys(value)) {\n\t\tif (!NAME.test(name)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${at}: \"${name}\" must be a camelCase name — letters and digits, starting with a lowercase letter`,\n\t\t\t);\n\t\t}\n\t}\n\treturn new Set(Object.keys(value));\n}\n\nfunction resolveRelation(\n\tvalue: unknown,\n\there: string,\n\t{\n\t\trefuse,\n\t\tisSubjectType,\n\t\trelationNames,\n\t}: {\n\t\trefuse: (message: string) => TypeError;\n\t\tisSubjectType: (type: string) => boolean;\n\t\trelationNames: ReadonlyMap<string, ReadonlySet<string>>;\n\t},\n): ResolvedRelation {\n\tif (isRecord(value) && value.kind === 'fromField') {\n\t\tconst { field, subject, lookup } = value;\n\t\tif (typeof field !== 'string' || !FIELD.test(field)) {\n\t\t\tthrow refuse(`${here}: fromField must name a top-level field`);\n\t\t}\n\t\tif (typeof subject !== 'string' || !isSubjectType(subject)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: fromField names \"${String(subject)}\", which is not a subject type`,\n\t\t\t);\n\t\t}\n\t\tif (lookup !== undefined && typeof lookup !== 'function') {\n\t\t\tthrow refuse(`${here}: fromField's lookup must be a function`);\n\t\t}\n\t\treturn lookup === undefined\n\t\t\t? { kind: 'fromField', field, subject }\n\t\t\t: {\n\t\t\t\t\tkind: 'fromField',\n\t\t\t\t\tfield,\n\t\t\t\t\tsubject,\n\t\t\t\t\tlookup: lookup as (subjectId: string) => Promise<readonly string[]>,\n\t\t\t\t};\n\t}\n\n\tif (!Array.isArray(value) || value.length === 0) {\n\t\tthrow refuse(\n\t\t\t`${here} must be a non-empty array of subject types, or fromField()`,\n\t\t);\n\t}\n\tconst holders = value.map((holder: unknown): Holder => {\n\t\tif (typeof holder !== 'string') {\n\t\t\tthrow refuse(`${here}: a holder must be a string`);\n\t\t}\n\t\tconst hash = holder.indexOf('#');\n\t\tif (hash < 0) {\n\t\t\tif (!isSubjectType(holder)) {\n\t\t\t\tthrow refuse(`${here}: \"${holder}\" is not a subject type`);\n\t\t\t}\n\t\t\treturn { kind: 'type', type: holder };\n\t\t}\n\t\tconst type = holder.slice(0, hash);\n\t\tconst relation = holder.slice(hash + 1);\n\t\tif (!relationNames.get(type)?.has(relation)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${holder}\" is not a subject set — it must name an object type and one of its relations`,\n\t\t\t);\n\t\t}\n\t\treturn { kind: 'set', type, relation };\n\t});\n\treturn { kind: 'stored', holders };\n}\n\nfunction resolveRule(\n\tvalue: unknown,\n\there: string,\n\tcontext: {\n\t\trefuse: (message: string) => TypeError;\n\t\town: ReadonlySet<string>;\n\t\trelations: ReadonlyMap<string, ResolvedRelation>;\n\t\ttypeNames: ReadonlySet<string>;\n\t\tnamesOf: (type: string) => ReadonlySet<string>;\n\t\tself: string;\n\t},\n): ResolvedRule {\n\tconst { refuse } = context;\n\n\tif (isRecord(value) && value.kind === 'when') {\n\t\tif (typeof value.test !== 'function') {\n\t\t\tthrow refuse(`${here}: when() takes a function as its test`);\n\t\t}\n\t\tconst inner = resolveRule(value.rule, here, context);\n\t\treturn { ...inner, test: value.test as (ctx: never) => boolean };\n\t}\n\tif (typeof value !== 'string') {\n\t\tthrow refuse(`${here}: a rule is a name, an arrow, or when()`);\n\t}\n\n\tconst arrow = value.indexOf('->');\n\tif (arrow < 0) {\n\t\tif (!context.own.has(value)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${value}\" is not a relation or a permission of ${context.self}`,\n\t\t\t);\n\t\t}\n\t\treturn { kind: 'name', name: value };\n\t}\n\n\tconst relation = value.slice(0, arrow);\n\tconst target = value.slice(arrow + 2);\n\tconst through = context.relations.get(relation);\n\tif (through === undefined) {\n\t\tthrow refuse(\n\t\t\t`${here}: \"${value}\" goes through \"${relation}\", which is not a relation of ${context.self}`,\n\t\t);\n\t}\n\tconst targets =\n\t\tthrough.kind === 'fromField'\n\t\t\t? [through.subject]\n\t\t\t: through.holders.map((holder) =>\n\t\t\t\t\tholder.kind === 'type' ? holder.type : null,\n\t\t\t\t);\n\tfor (const type of targets) {\n\t\t// A subject set, or a user type, has no permissions to follow.\n\t\tif (type === null || !context.typeNames.has(type)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${value}\" goes through \"${relation}\", which can hold ${type === null ? 'a subject set' : `a ${type}`}; an arrow follows object types only`,\n\t\t\t);\n\t\t}\n\t\tif (!context.namesOf(type).has(target)) {\n\t\t\tthrow refuse(\n\t\t\t\t`${here}: \"${value}\" names \"${target}\", which ${type} does not declare`,\n\t\t\t);\n\t\t}\n\t}\n\treturn { kind: 'arrow', relation, target };\n}\n\n/**\n * A permission that reaches itself through names alone — `view: ['edit']`,\n * `edit: ['view']` — never reaches a relation, so no data could end the walk.\n * Refused here rather than cut at run time: it is a model's bug, not a\n * user's data.\n */\nfunction refuseLoops(\n\ttypes: ReadonlyMap<string, ResolvedObjectType>,\n\trefuse: (message: string) => TypeError,\n): void {\n\tfor (const type of types.values()) {\n\t\tconst visiting: string[] = [];\n\t\tconst done = new Set<string>();\n\n\t\tconst visit = (permission: string): void => {\n\t\t\tif (done.has(permission)) return;\n\t\t\tconst loop = visiting.indexOf(permission);\n\t\t\tif (loop >= 0) {\n\t\t\t\tthrow refuse(\n\t\t\t\t\t`types.${type.name}.permissions: ${[...visiting.slice(loop), permission].join(' → ')} is a loop no relation ends`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tvisiting.push(permission);\n\t\t\tfor (const rule of type.permissions.get(permission) ?? []) {\n\t\t\t\tif (rule.kind === 'name' && type.permissions.has(rule.name)) {\n\t\t\t\t\tvisit(rule.name);\n\t\t\t\t}\n\t\t\t}\n\t\t\tvisiting.pop();\n\t\t\tdone.add(permission);\n\t\t};\n\n\t\tfor (const permission of type.permissions.keys()) visit(permission);\n\t}\n}\n\n/**\n * A `fromField` is read from the object `can()` was given — the route loaded\n * it (decided 2026-09-24). An object reached through a subject set or an arrow\n * was loaded by nobody, so a rule that needs its data could never be decided.\n * Refused here, where it is a sentence, rather than at the first check that\n * reaches it, where it would be a denial nobody can explain.\n */\nfunction refuseDataBeyondRoot(\n\ttypes: ReadonlyMap<string, ResolvedObjectType>,\n\trefuse: (message: string) => TypeError,\n): void {\n\t/** The field `name` of `type` reads, directly or through its own rules; `null` when none. */\n\tconst fieldRead = (type: ResolvedObjectType, name: string): string | null => {\n\t\tconst relation = type.relations.get(name);\n\t\tif (relation !== undefined) {\n\t\t\treturn relation.kind === 'fromField' ? relation.field : null;\n\t\t}\n\t\tfor (const rule of type.permissions.get(name) ?? []) {\n\t\t\tconst field =\n\t\t\t\trule.kind === 'name'\n\t\t\t\t\t? fieldRead(type, rule.name)\n\t\t\t\t\t: // An arrow reads its own relation on this object.\n\t\t\t\t\t\tfieldRead(type, rule.relation);\n\t\t\tif (field !== null) return field;\n\t\t}\n\t\treturn null;\n\t};\n\n\tfor (const type of types.values()) {\n\t\tfor (const [relation, def] of type.relations) {\n\t\t\tif (def.kind !== 'stored') continue;\n\t\t\tfor (const holder of def.holders) {\n\t\t\t\tif (holder.kind !== 'set') continue;\n\t\t\t\tconst target = types.get(holder.type);\n\t\t\t\tconst field =\n\t\t\t\t\ttarget === undefined ? null : fieldRead(target, holder.relation);\n\t\t\t\tif (field !== null) {\n\t\t\t\t\tthrow refuse(\n\t\t\t\t\t\t`types.${type.name}.relations.${relation}: \"${holder.type}#${holder.relation}\" reads ${holder.type}.${field}, and a subject set reaches ${holder.type}s nobody passed to can() — store that relation instead of reading it`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const [permission, rules] of type.permissions) {\n\t\t\tfor (const rule of rules) {\n\t\t\t\tif (rule.kind !== 'arrow') continue;\n\t\t\t\tconst through = type.relations.get(rule.relation);\n\t\t\t\tconst targets =\n\t\t\t\t\tthrough?.kind === 'fromField'\n\t\t\t\t\t\t? [through.subject]\n\t\t\t\t\t\t: (through?.holders ?? []).map((holder) => holder.type);\n\t\t\t\tfor (const name of targets) {\n\t\t\t\t\tconst target = types.get(name);\n\t\t\t\t\tconst field =\n\t\t\t\t\t\ttarget === undefined ? null : fieldRead(target, rule.target);\n\t\t\t\t\tif (field !== null) {\n\t\t\t\t\t\tthrow refuse(\n\t\t\t\t\t\t\t`types.${type.name}.permissions.${permission}: \"${rule.relation}->${rule.target}\" reaches ${name}.${rule.target}, which reads ${name}.${field}, and only the object passed to can() carries its data — store that relation instead of reading it`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n",
6
6
  "/** Reading what a caller passed to `can()`, `list()`, `grant()` and `revoke()`. */\n\nimport type { Subject } from '../subjects/subject';\nimport { admits, type ResolvedModel, type ResolvedObjectType } from './resolve';\n\n/** What no part of an id may hold: the notation would read it two ways. */\nconst RESERVED = /[@#()]/;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === 'object' && value !== null;\n\nexport function idOf(value: unknown, what: string, where: string): string {\n\tif (typeof value !== 'string' || value === '' || RESERVED.test(value)) {\n\t\tthrow new TypeError(\n\t\t\t`${where}: ${what} must be a non-empty string without @, # or parentheses`,\n\t\t);\n\t}\n\treturn value;\n}\n\nexport function typeOf(\n\tmodel: ResolvedModel,\n\tname: string,\n\twhere: string,\n): ResolvedObjectType {\n\tconst type = model.types.get(name);\n\tif (type === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`${where}: \"${name}\" is not an object type of the model`,\n\t\t);\n\t}\n\treturn type;\n}\n\nexport function objectOf(\n\tmodel: ResolvedModel,\n\tvalue: unknown,\n\twhere: string,\n): {\n\treadonly type: string;\n\treadonly id: string;\n\treadonly data: Readonly<Record<string, unknown>>;\n} {\n\tif (!isRecord(value) || typeof value.type !== 'string') {\n\t\tthrow new TypeError(\n\t\t\t`${where}: the object must be { type, id, …its fields }`,\n\t\t);\n\t}\n\ttypeOf(model, value.type, where);\n\treturn {\n\t\ttype: value.type,\n\t\tid: idOf(value.id, 'the object id', where),\n\t\tdata: value,\n\t};\n}\n\n/**\n * The subject as the store compares it: `{ type, id }` for a user or an\n * object, and `{ type, id, relation }` for a subject set.\n *\n * Decided by the type, not the shape: a user's fields are flat on it, and one\n * named `relation` must not make a user read as a set. A user type is never a\n * set; an object type is one when `relation` is given.\n */\nexport function subjectOf(\n\tmodel: ResolvedModel,\n\tvalue: unknown,\n\twhere: string,\n): Subject {\n\tif (!isRecord(value) || typeof value.type !== 'string') {\n\t\tthrow new TypeError(\n\t\t\t`${where}: the subject must be a user, or { type, id }`,\n\t\t);\n\t}\n\tconst id = idOf(value.id, 'the subject id', where);\n\tif (model.subjects.has(value.type)) return { type: value.type, id };\n\n\tconst type = typeOf(model, value.type, where);\n\tif (typeof value.relation !== 'string') return { type: type.name, id };\n\tif (!type.relations.has(value.relation)) {\n\t\tthrow new TypeError(\n\t\t\t`${where}: \"${value.relation}\" is not a relation of ${type.name}, so ${type.name}:${id}#${value.relation} is no subject set`,\n\t\t);\n\t}\n\treturn { type: type.name, id, relation: value.relation };\n}\n\n/** A tuple `grant` or `revoke` may write: a stored relation, and a holder it admits. */\nexport function tupleOf(\n\tmodel: ResolvedModel,\n\tobject: unknown,\n\trelation: string,\n\tsubject: unknown,\n\twhere: string,\n) {\n\tconst target = objectOf(model, object, where);\n\tconst type = typeOf(model, target.type, where);\n\tconst def = type.relations.get(relation);\n\tif (def === undefined) {\n\t\tthrow new TypeError(\n\t\t\t`${where}: \"${relation}\" is not a relation of ${type.name}`,\n\t\t);\n\t}\n\tif (def.kind === 'fromField') {\n\t\tthrow new TypeError(\n\t\t\t`${where}: ${type.name}.${relation} is read from ${def.field}; there is nothing to store — change the ${type.name} instead`,\n\t\t);\n\t}\n\n\tconst who = subjectOf(model, subject, where);\n\tif (!admits(def.holders, who)) {\n\t\tthrow new TypeError(\n\t\t\t`${where}: ${type.name}.${relation} is not held by ${'relation' in who ? `${who.type}#${who.relation}` : who.type}`,\n\t\t);\n\t}\n\n\treturn {\n\t\tobject: { type: target.type, id: target.id },\n\t\trelation,\n\t\tsubject: who,\n\t};\n}\n",
7
7
  "/**\n * The permission model: which object types exist, which relations they hold,\n * and which permissions those relations grant — written in TypeScript, and\n * typed from itself.\n *\n * **ReBAC, embedded.** Zanzibar's data model — relations between objects and\n * subjects, permissions computed from them — without its infrastructure: the\n * database is the application's own, so reads follow writes and there is\n * nothing to cache or sequence. Two things go beyond Zanzibar's descendants:\n *\n * - **`fromField`**, a relation read from the object's own data — a record's\n * `doctorId` — rather than a tuple to keep in sync with it. Two sources of\n * truth for one fact is the first trap of a Zanzibar deployment;\n * - **`when`**, a condition written in TypeScript and typed: its `ctx` is what\n * `can()` then requires, and only for the permissions whose rules reach it.\n *\n * The model is a flat `const` literal, and everything the compiler can check\n * about it is checked here: a relation naming a subject type that does not\n * exist, a permission naming a relation that does not exist, an arrow to a\n * permission its target does not have. What only running it can check —\n * names, cycles — is refused by {@link defineModel} with a `TypeError`.\n */\n\nimport type { CursorPage } from '../pagination/cursor-page';\nimport { type ResolvedModel, resolveModel } from './resolve';\n\n// ─── The two building blocks ──────────────────────────────────────────────\n\n/**\n * The ids of the objects whose field names this subject id — what `list()`\n * needs to reverse a `fromField`: `(doctorId) => db.records.ids({ doctorId })`.\n * Unpaged; a failure throws, as a store's does.\n */\nexport type Lookup = (subjectId: string) => Promise<readonly string[]>;\n\n/**\n * A relation read from the object's own data: `fromField('doctorId', 'staff')`\n * holds for the subject of type `staff` whose id is `object.doctorId`.\n *\n * Nothing is stored. `can()` receives the object — the route has already\n * loaded it — and the compiler requires the field on it. `list()` cannot read\n * a field of objects it has not found yet, so it asks `lookup` instead; a\n * `list()` that would need one it was not given is a compile error.\n */\nexport interface FromField<\n\tField extends string = string,\n\tSubject extends string = string,\n> {\n\treadonly kind: 'fromField';\n\treadonly field: Field;\n\treadonly subject: Subject;\n\treadonly lookup?: Lookup;\n}\n\n/** A `fromField` `list()` can reverse. */\nexport interface ReversibleFromField<\n\tField extends string = string,\n\tSubject extends string = string,\n> extends FromField<Field, Subject> {\n\treadonly lookup: Lookup;\n}\n\nexport function fromField<\n\tconst Field extends string,\n\tconst Subject extends string,\n>(field: Field, subject: Subject): FromField<Field, Subject>;\nexport function fromField<\n\tconst Field extends string,\n\tconst Subject extends string,\n>(\n\tfield: Field,\n\tsubject: Subject,\n\toptions: { readonly lookup: Lookup },\n): ReversibleFromField<Field, Subject>;\nexport function fromField(\n\tfield: string,\n\tsubject: string,\n\toptions?: { readonly lookup: Lookup },\n): FromField {\n\treturn Object.freeze(\n\t\toptions === undefined\n\t\t\t? { kind: 'fromField' as const, field, subject }\n\t\t\t: { kind: 'fromField' as const, field, subject, lookup: options.lookup },\n\t);\n}\n\n/**\n * A rule that grants only when `test(ctx)` is true: `when('doctor', (ctx:\n * { onShift: boolean }) => ctx.onShift)`.\n *\n * `rule` is any rule of the same object type — a relation, a permission, an\n * arrow. The test is synchronous and pure: it decides on what the caller\n * passes, and reads nothing, so it can never fail the way a store can.\n */\nexport interface When<Rule extends string = string, Ctx = never> {\n\treadonly kind: 'when';\n\treadonly rule: Rule;\n\treadonly test: (ctx: Ctx) => boolean;\n}\n\nexport function when<const Rule extends string, Ctx>(\n\trule: Rule,\n\ttest: (ctx: Ctx) => boolean,\n): When<Rule, Ctx> {\n\treturn Object.freeze({ kind: 'when', rule, test });\n}\n\n// ─── The shape of a model ─────────────────────────────────────────────────\n\n/**\n * Who may hold a relation: subject types — `'staff'`, a user type, or `'team'`,\n * an object type — and subject sets, `'team#member'`: every member of a team.\n * Or a relation read from the object's data.\n */\nexport type RelationDef = readonly string[] | FromField;\n\n/**\n * One way to hold a permission: a relation or a permission of the same object\n * type (`'doctor'`, `'manage'`), an arrow to a permission of a related object\n * (`'team->view'`: who can view the record's team), or one of those under a\n * condition.\n */\nexport type RuleDef = string | When<string, never>;\n\nexport interface ObjectTypeDef {\n\treadonly relations?: { readonly [name: string]: RelationDef };\n\t/** Each permission is the union of its rules. */\n\treadonly permissions?: { readonly [name: string]: readonly RuleDef[] };\n}\n\nexport interface ModelConfig {\n\t/**\n\t * The user types that can be subjects — pass `auth.types` from `janus()`,\n\t * so a user type and a subject type are one name.\n\t */\n\treadonly subjects: readonly string[];\n\treadonly types: { readonly [name: string]: ObjectTypeDef };\n}\n\n// ─── Reading a model's types ──────────────────────────────────────────────\n\ntype TypesOf<C extends ModelConfig> = C['types'];\n\n/** The object types a model declares. */\nexport type ObjectTypeOf<C extends ModelConfig> = keyof TypesOf<C> & string;\n\n/** The user types a model accepts as subjects. */\nexport type UserTypeOf<C extends ModelConfig> = C['subjects'][number];\n\ntype RelationsOf<Ts, T> = T extends keyof Ts\n\t? Ts[T] extends { readonly relations: infer R }\n\t\t? keyof R & string\n\t\t: never\n\t: never;\n\ntype PermissionsOf<Ts, T> = T extends keyof Ts\n\t? Ts[T] extends { readonly permissions: infer P }\n\t\t? keyof P & string\n\t\t: never\n\t: never;\n\ntype NamesOf<Ts, T> = RelationsOf<Ts, T> | PermissionsOf<Ts, T>;\n\ntype RelationDefOf<Ts, T, R> = T extends keyof Ts\n\t? Ts[T] extends { readonly relations: infer Rs }\n\t\t? R extends keyof Rs\n\t\t\t? Rs[R]\n\t\t\t: never\n\t\t: never\n\t: never;\n\n/** The relations of `T` that are stored as tuples: every one but its `fromField`s. */\ntype StoredRelationsOf<Ts, T> = {\n\t[R in RelationsOf<Ts, T>]: RelationDefOf<Ts, T, R> extends FromField\n\t\t? never\n\t\t: R;\n}[RelationsOf<Ts, T>];\n\n/**\n * `'team#member'` for every stored relation of every object type. Not a\n * `fromField`: a subject set reaches objects nobody passed to `can()`, so there\n * is no data to read the field from.\n */\ntype SubjectSetOf<Ts> = {\n\t[T in keyof Ts & string]: `${T}#${StoredRelationsOf<Ts, T>}`;\n}[keyof Ts & string];\n\ntype SubjectRefOf<S extends string, Ts> =\n\t| S\n\t| (keyof Ts & string)\n\t| SubjectSetOf<Ts>;\n\n/** The object types an arrow through `R` reaches: its direct subject types. */\ntype ArrowTargets<Ts, T, R> =\n\tRelationDefOf<Ts, T, R> extends FromField<string, infer Sub>\n\t\t? Sub\n\t\t: RelationDefOf<Ts, T, R> extends readonly (infer E)[]\n\t\t\t? E extends `${string}#${string}`\n\t\t\t\t? never\n\t\t\t\t: E\n\t\t\t: never;\n\n/** The names every one of `Targets` declares. */\ntype CommonNames<Ts, Targets> =\n\tNamesOf<Ts, Targets> extends infer N\n\t\t? N extends string\n\t\t\t? [Targets] extends [TypesNaming<Ts, N>]\n\t\t\t\t? N\n\t\t\t\t: never\n\t\t\t: never\n\t\t: never;\n\ntype TypesNaming<Ts, N> = {\n\t[X in keyof Ts]: N extends NamesOf<Ts, X> ? X : never;\n}[keyof Ts];\n\n/** `'team->view'`, for each relation whose targets are all object types. */\ntype ArrowsOf<Ts, T> = {\n\t[R in RelationsOf<Ts, T>]: [ArrowTargets<Ts, T, R>] extends [never]\n\t\t? never\n\t\t: [ArrowTargets<Ts, T, R>] extends [keyof Ts]\n\t\t\t? `${R}->${CommonNames<Ts, ArrowTargets<Ts, T, R>>}`\n\t\t\t: never;\n}[RelationsOf<Ts, T>];\n\n/** Every string a rule of `T` may be. */\ntype RuleRefOf<Ts, T> = NamesOf<Ts, T> | ArrowsOf<Ts, T>;\n\n/** What `can()` accepts for an object type: its relations and its permissions. */\nexport type CheckableOf<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n> = NamesOf<TypesOf<C>, T>;\n\n/** The fields an object of type `T` must carry: those its `fromField`s read. */\nexport type FieldsOf<C extends ModelConfig, T extends ObjectTypeOf<C>> = {\n\t[R in RelationsOf<TypesOf<C>, T>]: RelationDefOf<\n\t\tTypesOf<C>,\n\t\tT,\n\t\tR\n\t> extends FromField<infer F, string>\n\t\t? F\n\t\t: never;\n}[RelationsOf<TypesOf<C>, T>];\n\n/**\n * An object, as `can()` takes it: its type and id, and **every field a\n * `fromField` of its type reads** — required, so an object passed without\n * them is a compile error rather than a silent denial. `null` is a field\n * holding nobody.\n */\nexport type ObjectRef<C extends ModelConfig, T extends ObjectTypeOf<C>> = {\n\treadonly type: T;\n\treadonly id: string;\n} & { readonly [F in FieldsOf<C, T>]: string | null };\n\n/** A subject: a user from `janus()` as it is, or an object. */\nexport interface SubjectRef<C extends ModelConfig> {\n\treadonly type: UserTypeOf<C> | ObjectTypeOf<C>;\n\treadonly id: string;\n}\n\n// ─── The context a check requires ─────────────────────────────────────────\n\ntype UnionToIntersection<U> = (\n\tU extends unknown\n\t\t? (union: U) => void\n\t\t: never\n) extends (intersection: infer I) => void\n\t? I\n\t: never;\n\ntype CtxOfRule<E> = E extends When<string, infer X> ? X : never;\n\ntype NameOfRule<E> = E extends string\n\t? E\n\t: E extends When<infer R, never>\n\t\t? R\n\t\t: never;\n\ntype CtxOfName<Ts, T, N, Seen> = N extends `${infer R}->${infer P}`\n\t? CtxOfPermission<Ts, ArrowTargets<Ts, T, R>, P, Seen>\n\t: CtxOfPermission<Ts, T, N, Seen>;\n\n/**\n * The union of the `ctx` types a permission's rules reach — through its own\n * rules, the permissions they name, and arrows into other types. `Seen` stops\n * the walk on a cycle.\n */\ntype CtxOfPermission<Ts, T, P, Seen> = T extends keyof Ts & string\n\t? P extends string\n\t\t? `${T}.${P}` extends Seen\n\t\t\t? never\n\t\t\t: Ts[T] extends { readonly permissions: infer Ps }\n\t\t\t\t? P extends keyof Ps\n\t\t\t\t\t? Ps[P] extends readonly (infer E)[]\n\t\t\t\t\t\t? CtxOfRule<E> | CtxOfName<Ts, T, NameOfRule<E>, Seen | `${T}.${P}`>\n\t\t\t\t\t\t: never\n\t\t\t\t\t: never\n\t\t\t\t: never\n\t\t: never\n\t: never;\n\n/**\n * What `can(…, permission, object)` requires as `ctx`: every condition its\n * rules can reach, intersected. `never` when none — and then `can()` takes no\n * `ctx` at all.\n */\nexport type CtxOf<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> = [CtxOfPermission<TypesOf<C>, T, P, never>] extends [never]\n\t? never\n\t: UnionToIntersection<CtxOfPermission<TypesOf<C>, T, P, never>>;\n\n/**\n * The options of a check: `ctx` required exactly when a condition is\n * reachable.\n *\n * Loose when `T` or `P` is its whole constraint — what the compiler falls back\n * to when the argument was wrong. Requiring `ctx` there would report a missing\n * argument instead of the wrong type or permission that caused it; the\n * refusal on that argument is the one worth reading. A `when` reached with no\n * `ctx` still throws at run time.\n */\nexport type CheckArgs<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> = [ObjectTypeOf<C>] extends [T]\n\t? [ObjectTypeOf<C>] extends [never]\n\t\t? [options?: { readonly ctx?: unknown }]\n\t\t: IsSingle<ObjectTypeOf<C>> extends true\n\t\t\t? // One object type: `T` is its constraint and right; `P` may not be.\n\t\t\t\tPermissionArgs<C, T, P>\n\t\t\t: [options?: { readonly ctx?: unknown }]\n\t: PermissionArgs<C, T, P>;\n\n/** `CheckArgs` once `T` is known right: loose when `P` is its whole constraint. */\ntype PermissionArgs<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> = [CheckableOf<C, T>] extends [P]\n\t? IsSingle<CheckableOf<C, T>> extends true\n\t\t? Strict<C, T, P>\n\t\t: [options?: { readonly ctx?: unknown }]\n\t: Strict<C, T, P>;\n\ntype Strict<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> = [CtxOf<C, T, P>] extends [never]\n\t? [options?: { readonly ctx?: never }]\n\t: [options: { readonly ctx: CtxOf<C, T, P> }];\n\n/** Whether `U` is one type rather than a union of several. */\ntype IsSingle<U> = [U] extends [UnionToIntersection<U>] ? true : false;\n\n/**\n * The signature of `can()`, typed from the model: the permission must be one\n * the object's type declares, the object must carry every field its\n * `fromField`s read, and `ctx` is required exactly when a condition is\n * reachable. `null` is anonymous, and answers `false`.\n */\nexport type Can<C extends ModelConfig> = <\n\tT extends ObjectTypeOf<C>,\n\tP extends CheckableOf<C, T>,\n>(\n\tsubject: SubjectRef<C> | null,\n\tpermission: P,\n\tobject: ObjectRef<C, T>,\n\t...options: CheckArgs<C, T, P>\n) => Promise<boolean>;\n\n// ─── What list() can reverse ──────────────────────────────────────────────\n\n/** `'record.doctor'` when relation `R` of `T` is a `fromField` with no `lookup`. */\ntype GapOfRelation<Ts, T, R> =\n\tRelationDefOf<Ts, T, R> extends { readonly lookup: Lookup }\n\t\t? never\n\t\t: RelationDefOf<Ts, T, R> extends FromField\n\t\t\t? `${T & string}.${R & string}`\n\t\t\t: never;\n\ntype GapOfName<Ts, T, N, Seen> = N extends `${infer R}->${infer P}`\n\t?\n\t\t\t| GapOfRelation<Ts, T, R>\n\t\t\t| GapOfPermission<Ts, ArrowTargets<Ts, T, R>, P, Seen>\n\t: GapOfPermission<Ts, T, N, Seen>;\n\n/**\n * The `fromField`s without a `lookup` that `list(…, P, T)` would have to\n * reverse — through `P`'s rules, the names they reach, and arrows. A subject\n * set never reaches one: `defineModel` refuses that.\n */\ntype GapOfPermission<Ts, T, P, Seen> = T extends keyof Ts & string\n\t? P extends string\n\t\t? `${T}.${P}` extends Seen\n\t\t\t? never\n\t\t\t: P extends RelationsOf<Ts, T>\n\t\t\t\t? GapOfRelation<Ts, T, P>\n\t\t\t\t: Ts[T] extends { readonly permissions: infer Ps }\n\t\t\t\t\t? P extends keyof Ps\n\t\t\t\t\t\t? Ps[P] extends readonly (infer E)[]\n\t\t\t\t\t\t\t? GapOfName<Ts, T, NameOfRule<E>, Seen | `${T}.${P}`>\n\t\t\t\t\t\t\t: never\n\t\t\t\t\t\t: never\n\t\t\t\t\t: never\n\t\t: never\n\t: never;\n\n/** Every `fromField` without a `lookup` that `list(…, P, T)` would reach; `never` when none. */\nexport type LookupGap<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> = GapOfPermission<TypesOf<C>, T, P, never>;\n\n/** What a permission must also be for `list()`: reversible. */\ntype ListCheck<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> = [LookupGap<C, T, P>] extends [never]\n\t? unknown\n\t: Refusal<\n\t\t\t`list cannot reverse ${LookupGap<C, T, P>}: give that fromField a lookup`,\n\t\t\tnever\n\t\t>;\n\n/** Where a page of `list()` starts, and how much it holds. */\nexport interface ListPage {\n\t/** The `nextCursor` of the previous page; absent or `null` for the first. */\n\treadonly after?: string | null;\n\t/** Between 1 and 100; 20 when absent. */\n\treadonly limit?: number;\n}\n\n/** `CheckArgs`, with a page. */\ntype ListArgs<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n\tP extends string,\n> =\n\tCheckArgs<C, T, P> extends [infer O]\n\t\t? [options: O & ListPage]\n\t\t: CheckArgs<C, T, P> extends [options?: infer O]\n\t\t\t? [options?: O & ListPage]\n\t\t\t: never;\n\n/**\n * The signature of `list()`: the ids of the objects of `type` on which\n * `subject` holds `permission`, in ascending order, by pages. Typed like\n * `can()`, and refuses a permission that reaches a `fromField` with no\n * `lookup`: nothing could find the objects whose field names the subject.\n */\nexport type List<C extends ModelConfig> = <\n\tT extends ObjectTypeOf<C>,\n\tP extends CheckableOf<C, T>,\n>(\n\tsubject: SubjectRef<C> | null,\n\tpermission: P & ListCheck<C, T, P>,\n\ttype: T,\n\t...options: ListArgs<C, T, P>\n) => Promise<CursorPage<string>>;\n\n/** The relations of an object type that `grant` can write: not its `fromField`s. */\nexport type GrantableOf<\n\tC extends ModelConfig,\n\tT extends ObjectTypeOf<C>,\n> = StoredRelationsOf<TypesOf<C>, T>;\n\n/**\n * Who may be granted relation `R` on an object of type `T`: an entity of each\n * subject type it names, and a subject set for each set it names.\n */\nexport type HolderOf<C extends ModelConfig, T extends ObjectTypeOf<C>, R> =\n\tRelationDefOf<TypesOf<C>, T, R> extends readonly (infer E)[]\n\t\t? E extends `${infer SetType}#${infer SetRelation}`\n\t\t\t? {\n\t\t\t\t\treadonly type: SetType;\n\t\t\t\t\treadonly id: string;\n\t\t\t\t\treadonly relation: SetRelation;\n\t\t\t\t}\n\t\t\t: { readonly type: E; readonly id: string }\n\t\t: never;\n\n/** Writes one tuple, or removes it: typed like `can()`. */\nexport type Grant<C extends ModelConfig> = <\n\tT extends ObjectTypeOf<C>,\n\tR extends GrantableOf<C, T>,\n>(\n\tobject: { readonly type: T; readonly id: string },\n\trelation: R,\n\tsubject: HolderOf<C, T, R>,\n) => Promise<void>;\n\n/** What `permissions()` answers. */\nexport interface Permissions<C extends ModelConfig> {\n\treadonly model: PermissionModel<C>;\n\t/**\n\t * Whether `subject` holds `permission` on `object`: `true` or `false`, and\n\t * **a failure throws** — a store that cannot answer is `STORE_FAILED`, never\n\t * a denial. `null` is anonymous, and `false` before any store call.\n\t */\n\treadonly can: Can<C>;\n\t/**\n\t * The ids of the objects of `type` on which `subject` holds `permission`,\n\t * ascending, by pages — what `can()` answers `true` for, found without\n\t * naming them. `null` is anonymous, and an empty page before any store call.\n\t * A failure throws, as for `can()`.\n\t */\n\treadonly list: List<C>;\n\t/** Stores that `subject` holds `relation` on `object`. Idempotent. */\n\treadonly grant: Grant<C>;\n\t/** Removes it. Idempotent: revoking what is not held is not an error. */\n\treadonly revoke: Grant<C>;\n}\n\n/** The configuration a model was defined from. */\nexport type ConfigOf<M> = M extends PermissionModel<infer C> ? C : never;\n\n// ─── The checks, as types ─────────────────────────────────────────────────\n\ntype Refusal<Text extends string, Expected> = {\n\treadonly [K in Text]: Expected;\n};\n\ntype CheckRelation<C extends ModelConfig, Def> =\n\tDef extends FromField<string, infer Sub>\n\t\t? Sub extends UserTypeOf<C> | ObjectTypeOf<C>\n\t\t\t? unknown\n\t\t\t: {\n\t\t\t\t\treadonly subject: Refusal<\n\t\t\t\t\t\t`\"${Sub}\" is not a subject type; name one of`,\n\t\t\t\t\t\tUserTypeOf<C> | ObjectTypeOf<C>\n\t\t\t\t\t>;\n\t\t\t\t}\n\t\t: {\n\t\t\t\treadonly [I in keyof Def]: Def[I] extends SubjectRefOf<\n\t\t\t\t\tUserTypeOf<C>,\n\t\t\t\t\tTypesOf<C>\n\t\t\t\t>\n\t\t\t\t\t? unknown\n\t\t\t\t\t: Refusal<\n\t\t\t\t\t\t\t`\"${Def[I] & string}\" is not a subject type or a subject set; name one of`,\n\t\t\t\t\t\t\tSubjectRefOf<UserTypeOf<C>, TypesOf<C>>\n\t\t\t\t\t\t>;\n\t\t\t};\n\ntype CheckRules<Ts, T, Rules> = {\n\treadonly [I in keyof Rules]: Rules[I] extends string\n\t\t? Rules[I] extends RuleRefOf<Ts, T>\n\t\t\t? unknown\n\t\t\t: Refusal<\n\t\t\t\t\t`\"${Rules[I]}\" is not a relation, a permission or an arrow of ${T & string}; name one of`,\n\t\t\t\t\tRuleRefOf<Ts, T>\n\t\t\t\t>\n\t\t: Rules[I] extends When<infer R, never>\n\t\t\t? R extends RuleRefOf<Ts, T>\n\t\t\t\t? unknown\n\t\t\t\t: {\n\t\t\t\t\t\treadonly rule: Refusal<\n\t\t\t\t\t\t\t`\"${R}\" is not a relation, a permission or an arrow of ${T & string}; name one of`,\n\t\t\t\t\t\t\tRuleRefOf<Ts, T>\n\t\t\t\t\t\t>;\n\t\t\t\t\t}\n\t\t\t: unknown;\n};\n\ntype CheckObjectType<C extends ModelConfig, T> = (TypesOf<C>[T &\n\tkeyof TypesOf<C>] extends { readonly relations: infer Rs }\n\t? {\n\t\t\treadonly relations: {\n\t\t\t\treadonly [R in keyof Rs]: CheckRelation<C, Rs[R]>;\n\t\t\t};\n\t\t}\n\t: unknown) &\n\t(TypesOf<C>[T & keyof TypesOf<C>] extends { readonly permissions: infer Ps }\n\t\t? {\n\t\t\t\treadonly permissions: {\n\t\t\t\t\treadonly [P in keyof Ps]: P extends RelationsOf<TypesOf<C>, T>\n\t\t\t\t\t\t? Refusal<\n\t\t\t\t\t\t\t\t`\"${P & string}\" names a relation and a permission of ${T & string}; rename one`,\n\t\t\t\t\t\t\t\tnever\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t: CheckRules<TypesOf<C>, T, Ps[P]>;\n\t\t\t\t};\n\t\t\t}\n\t\t: unknown);\n\n/**\n * The compile-time checks `defineModel` intersects into its parameter — the\n * `C & Checked<C>` pattern of `janus()`: a wrong value is unassignable **on\n * the offending key**, and the reason is the type the compiler prints.\n */\nexport type CheckedModel<C extends ModelConfig> = {\n\treadonly types: {\n\t\treadonly [T in keyof TypesOf<C>]: CheckObjectType<C, T>;\n\t};\n};\n\n// ─── Defining one ─────────────────────────────────────────────────────────\n\n/** A model, checked and resolved. What `permissions()` will take. */\nexport interface PermissionModel<C extends ModelConfig = ModelConfig> {\n\t/** The user types it accepts as subjects. */\n\treadonly subjects: readonly UserTypeOf<C>[];\n\t/** The object types it declares. */\n\treadonly types: readonly ObjectTypeOf<C>[];\n\t/** The definition, as written. Frozen. */\n\treadonly definition: C;\n}\n\n// Keyed by the frozen model itself: nothing outside this module can reach it.\nconst RESOLVED = new WeakMap<object, ResolvedModel>();\n\n/**\n * Checks a model and resolves it. Connects to nothing.\n *\n * ```ts\n * export const model = defineModel({\n * subjects: auth.types,\n * types: {\n * team: {\n * relations: { member: ['staff', 'team#member'], lead: ['staff'] },\n * permissions: { manage: ['lead'], view: ['member', 'manage'] },\n * },\n * record: {\n * relations: {\n * doctor: fromField('doctorId', 'staff'),\n * team: ['team'],\n * },\n * permissions: {\n * view: ['doctor', 'team->view'],\n * edit: [when('doctor', (ctx: { onShift: boolean }) => ctx.onShift)],\n * },\n * },\n * },\n * });\n * ```\n *\n * Refuses with a `TypeError` what only running it can see: a name that is not\n * camelCase, an object type named like a user type, a permission that reaches\n * itself without crossing a relation — which no data could ever end.\n */\nexport function defineModel<const C extends ModelConfig>(\n\tconfig: C & CheckedModel<C>,\n): PermissionModel<C> {\n\tconst resolved = resolveModel(config, 'defineModel');\n\tconst model: PermissionModel<C> = Object.freeze({\n\t\tsubjects: [...resolved.subjects] as UserTypeOf<C>[],\n\t\ttypes: [...resolved.types.keys()] as ObjectTypeOf<C>[],\n\t\tdefinition: config,\n\t});\n\tRESOLVED.set(model, resolved);\n\treturn model;\n}\n\n/** The resolved form of a model this module defined. Internal. */\nexport function resolvedOf(model: object): ResolvedModel {\n\tconst resolved = RESOLVED.get(model);\n\tif (resolved === undefined) {\n\t\tthrow new TypeError(\n\t\t\t'permissions: this model was not made by defineModel() — pass what defineModel() answered',\n\t\t);\n\t}\n\treturn resolved;\n}\n",
8
8
  "import { PermissionDepthError } from '../errors/janus-error';\nimport type { CursorPage } from '../pagination/cursor-page';\nimport { MAX_PAGE_SIZE } from '../pagination/cursor-page';\nimport type { Subject } from '../subjects/subject';\nimport type { RelationStore } from './port/types';\nimport {\n\tadmits,\n\ttype ResolvedModel,\n\ttype ResolvedObjectType,\n\ttype ResolvedRule,\n} from './resolve';\n\n/**\n * One `list()`: the objects a subject holds a name on, found backwards —\n * from the subject to the tuples naming it, through the sets and arrows the\n * model declares, to the objects.\n *\n * **A least fixpoint.** `objects(type, name)` is a union of what its rules\n * reach, and a rule can reach its own name again — a folder viewable through\n * its parent, a team member through a team. Such a name, met again on the\n * current path, answers what the previous round found; rounds repeat until\n * none adds an id. That is exactly the set of objects with a derivation that\n * does not loop — what `can()`'s cut finds, one object at a time. A round\n * that met no loop is final.\n *\n * **Depth.** Each round past the first follows the loops one relation\n * further; more than `maxDepth` rounds is `PERMISSION_DEPTH`, as crossing more\n * than `maxDepth` relations is for `can()`.\n *\n * **Cost.** Every page of `findObjects` for every id each step reaches, every\n * round. Linear in what the subject can reach — fine for the objects of one\n * user, not for a subject set holding most of the database.\n */\nexport class Reverse {\n\tprivate previous = new Map<string, ReadonlySet<string>>();\n\tprivate current = new Map<string, ReadonlySet<string>>();\n\tprivate readonly path = new Set<string>();\n\tprivate looped = false;\n\n\tconstructor(\n\t\tprivate readonly model: ResolvedModel,\n\t\tprivate readonly store: RelationStore,\n\t\tprivate readonly maxDepth: number,\n\t\tprivate readonly ctx: unknown,\n\t\tprivate readonly subject: Subject,\n\t\tprivate readonly question: string,\n\t) {}\n\n\tasync objects(type: string, name: string): Promise<ReadonlySet<string>> {\n\t\tfor (let round = 0; round <= this.maxDepth; round += 1) {\n\t\t\tthis.current = new Map();\n\t\t\tthis.looped = false;\n\t\t\tconst found = await this.reach(type, name);\n\t\t\tif (!this.looped || this.same()) return found;\n\t\t\tthis.previous = this.current;\n\t\t}\n\t\tthrow new PermissionDepthError(\n\t\t\t`list: listing ${this.question} crossed more than ${this.maxDepth} relations without an answer`,\n\t\t\t{ permission: this.question, maxDepth: this.maxDepth },\n\t\t);\n\t}\n\n\t/** Whether this round found what the previous one did: nothing more to find. */\n\tprivate same(): boolean {\n\t\tfor (const [key, ids] of this.current) {\n\t\t\tif ((this.previous.get(key)?.size ?? 0) !== ids.size) return false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/** The ids of the objects of `typeName` on which the subject holds `name`. */\n\tprivate async reach(\n\t\ttypeName: string,\n\t\tname: string,\n\t): Promise<ReadonlySet<string>> {\n\t\tconst key = `${typeName}#${name}`;\n\t\tconst done = this.current.get(key);\n\t\tif (done !== undefined) return done;\n\t\tif (this.path.has(key)) {\n\t\t\tthis.looped = true;\n\t\t\treturn this.previous.get(key) ?? new Set();\n\t\t}\n\n\t\tconst type = this.model.types.get(typeName);\n\t\tif (type === undefined) return new Set();\n\n\t\tthis.path.add(key);\n\t\ttry {\n\t\t\tconst found = type.permissions.has(name)\n\t\t\t\t? await this.permission(type, name)\n\t\t\t\t: await this.relation(type, name);\n\t\t\tthis.current.set(key, found);\n\t\t\treturn found;\n\t\t} finally {\n\t\t\tthis.path.delete(key);\n\t\t}\n\t}\n\n\tprivate async relation(\n\t\ttype: ResolvedObjectType,\n\t\tname: string,\n\t): Promise<Set<string>> {\n\t\tconst relation = type.relations.get(name);\n\t\tif (relation === undefined) return new Set();\n\n\t\tif (relation.kind === 'fromField') {\n\t\t\tconst subject = this.subject;\n\t\t\treturn 'relation' in subject || subject.type !== relation.subject\n\t\t\t\t? new Set()\n\t\t\t\t: new Set(await this.lookup(type, name, subject.id));\n\t\t}\n\n\t\t// A direct tuple counts only when the model admits the subject here.\n\t\tconst found = new Set(\n\t\t\tadmits(relation.holders, this.subject)\n\t\t\t\t? await this.holding(type.name, name, this.subject)\n\t\t\t\t: [],\n\t\t);\n\t\tfor (const holder of relation.holders) {\n\t\t\tif (holder.kind !== 'set') continue;\n\t\t\tfor (const id of await this.reach(holder.type, holder.relation)) {\n\t\t\t\tconst set = { type: holder.type, id, relation: holder.relation };\n\t\t\t\tfor (const object of await this.holding(type.name, name, set)) {\n\t\t\t\t\tfound.add(object);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn found;\n\t}\n\n\tprivate async permission(\n\t\ttype: ResolvedObjectType,\n\t\tname: string,\n\t): Promise<Set<string>> {\n\t\tconst found = new Set<string>();\n\t\tfor (const rule of type.permissions.get(name) ?? []) {\n\t\t\tif (rule.test !== undefined && !this.passes(rule, type, name)) continue;\n\n\t\t\tif (rule.kind === 'name') {\n\t\t\t\tfor (const id of await this.reach(type.name, rule.name)) found.add(id);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const id of await this.arrow(type, rule.relation, rule.target)) {\n\t\t\t\tfound.add(id);\n\t\t\t}\n\t\t}\n\t\treturn found;\n\t}\n\n\t/** The objects of `type` whose `relation` reaches an object on which the subject holds `target`. */\n\tprivate async arrow(\n\t\ttype: ResolvedObjectType,\n\t\trelation: string,\n\t\ttarget: string,\n\t): Promise<Set<string>> {\n\t\tconst through = type.relations.get(relation);\n\t\tconst found = new Set<string>();\n\t\tif (through === undefined) return found;\n\n\t\tif (through.kind === 'fromField') {\n\t\t\tfor (const id of await this.reach(through.subject, target)) {\n\t\t\t\tfor (const object of await this.lookup(type, relation, id)) {\n\t\t\t\t\tfound.add(object);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn found;\n\t\t}\n\t\tfor (const holder of through.holders) {\n\t\t\t// An arrow follows entities; a user type holds no permission.\n\t\t\tif (holder.kind !== 'type' || !this.model.types.has(holder.type)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const id of await this.reach(holder.type, target)) {\n\t\t\t\tconst entity = { type: holder.type, id };\n\t\t\t\tfor (const object of await this.holding(type.name, relation, entity)) {\n\t\t\t\t\tfound.add(object);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn found;\n\t}\n\n\t/** Every id of every page of `findObjects`. */\n\tprivate async holding(\n\t\ttype: string,\n\t\trelation: string,\n\t\tsubject: Subject,\n\t): Promise<string[]> {\n\t\tconst ids: string[] = [];\n\t\tlet after: string | null = null;\n\t\tdo {\n\t\t\tconst page: CursorPage<string> = await this.store.findObjects({\n\t\t\t\ttype,\n\t\t\t\trelation,\n\t\t\t\tsubject,\n\t\t\t\tafter,\n\t\t\t\tlimit: MAX_PAGE_SIZE,\n\t\t\t});\n\t\t\tids.push(...page.items);\n\t\t\tafter = page.nextCursor;\n\t\t} while (after !== null);\n\t\treturn ids;\n\t}\n\n\t/** The objects whose field names `id`, from the `fromField`'s lookup. */\n\tprivate async lookup(\n\t\ttype: ResolvedObjectType,\n\t\trelation: string,\n\t\tid: string,\n\t): Promise<readonly string[]> {\n\t\tconst def = type.relations.get(relation);\n\t\tif (def?.kind !== 'fromField' || def.lookup === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`list: ${type.name}.${relation} is read from a field, and has no lookup to find the ${type.name}s naming ${id} — fromField('${def?.kind === 'fromField' ? def.field : relation}', '${def?.kind === 'fromField' ? def.subject : ''}', { lookup })`,\n\t\t\t);\n\t\t}\n\t\tconst ids = await def.lookup(id);\n\t\tif (!Array.isArray(ids) || ids.some((each) => typeof each !== 'string')) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`list: the lookup of ${type.name}.${relation} must answer an array of ids`,\n\t\t\t);\n\t\t}\n\t\treturn ids;\n\t}\n\n\t/** The condition, run on the caller's `ctx`, as for `can()`. */\n\tprivate passes(\n\t\trule: ResolvedRule,\n\t\ttype: ResolvedObjectType,\n\t\tname: string,\n\t): boolean {\n\t\tif (this.ctx === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`list: ${type.name}.${name} reaches a condition, and no ctx was passed — pass { ctx }`,\n\t\t\t);\n\t\t}\n\t\treturn (rule.test as (ctx: unknown) => boolean)(this.ctx) === true;\n\t}\n}\n",
9
9
  "/** The walk behind `can()`: from an object, through its rules, to a subject. */\n\nimport { PermissionDepthError } from '../errors/janus-error';\nimport { formatEntity } from '../subjects/notation';\nimport type { Entity, Subject } from '../subjects/subject';\nimport type { RelationStore } from './port/types';\nimport {\n\tadmits,\n\ttype ResolvedModel,\n\ttype ResolvedObjectType,\n\ttype ResolvedRule,\n} from './resolve';\n\n/** An object on the walk: its entity, and its data when the caller passed it. */\nexport interface Node {\n\treadonly entity: Entity;\n\treadonly data: Readonly<Record<string, unknown>> | null;\n}\n\n/** One check: its context, its path, and the depth it may reach. */\nexport class Walk {\n\t/** The nodes on the current path. The walk is sequential, so one set is the stack. */\n\tprivate readonly path = new Set<string>();\n\n\tconstructor(\n\t\tprivate readonly model: ResolvedModel,\n\t\tprivate readonly store: RelationStore,\n\t\tprivate readonly maxDepth: number,\n\t\tprivate readonly ctx: unknown,\n\t\tprivate readonly question: string,\n\t) {}\n\n\t/** Whether `subject` holds `name` — a relation or a permission — on `node`. */\n\tasync holds(\n\t\tsubject: Subject,\n\t\tnode: Node,\n\t\tname: string,\n\t\tdepth: number,\n\t): Promise<boolean> {\n\t\tif (depth > this.maxDepth) {\n\t\t\tthrow new PermissionDepthError(\n\t\t\t\t`can: checking ${this.question} crossed more than ${this.maxDepth} relations without an answer`,\n\t\t\t\t{ permission: this.question, maxDepth: this.maxDepth },\n\t\t\t);\n\t\t}\n\n\t\tconst key = `${formatEntity(node.entity)}#${name}`;\n\t\t// A cycle in the data: this branch grants nothing, and it is not an error.\n\t\tif (this.path.has(key)) return false;\n\n\t\tconst type = this.model.types.get(node.entity.type);\n\t\t// A stored tuple naming a type the model no longer declares grants nothing.\n\t\tif (type === undefined) return false;\n\n\t\tthis.path.add(key);\n\t\ttry {\n\t\t\treturn type.permissions.has(name)\n\t\t\t\t? await this.permission(subject, type, node, name, depth)\n\t\t\t\t: await this.relation(subject, type, node, name, depth);\n\t\t} finally {\n\t\t\tthis.path.delete(key);\n\t\t}\n\t}\n\n\tprivate async relation(\n\t\tsubject: Subject,\n\t\ttype: ResolvedObjectType,\n\t\tnode: Node,\n\t\tname: string,\n\t\tdepth: number,\n\t): Promise<boolean> {\n\t\tconst relation = type.relations.get(name);\n\t\tif (relation === undefined) return false;\n\n\t\tif (relation.kind === 'fromField') {\n\t\t\tconst id = fieldOf(node, relation.field, `${type.name}.${name}`);\n\t\t\treturn (\n\t\t\t\tid !== null &&\n\t\t\t\t!('relation' in subject) &&\n\t\t\t\tsubject.type === relation.subject &&\n\t\t\t\tsubject.id === id\n\t\t\t);\n\t\t}\n\n\t\t// What the model does not admit here grants nothing, however it was stored.\n\t\tif (\n\t\t\tadmits(relation.holders, subject) &&\n\t\t\t(await this.store.has({ object: node.entity, relation: name, subject }))\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\tfor (const set of await this.store.findSubjectSets(node.entity, name)) {\n\t\t\tif (!admits(relation.holders, set)) continue;\n\t\t\tconst through = { entity: { type: set.type, id: set.id }, data: null };\n\t\t\tif (await this.holds(subject, through, set.relation, depth + 1)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate async permission(\n\t\tsubject: Subject,\n\t\ttype: ResolvedObjectType,\n\t\tnode: Node,\n\t\tname: string,\n\t\tdepth: number,\n\t): Promise<boolean> {\n\t\tfor (const rule of type.permissions.get(name) ?? []) {\n\t\t\tif (rule.test !== undefined && !this.passes(rule, type, name)) continue;\n\n\t\t\tif (rule.kind === 'name') {\n\t\t\t\tif (await this.holds(subject, node, rule.name, depth)) return true;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const target of await this.targets(type, node, rule.relation)) {\n\t\t\t\tif (await this.holds(subject, target, rule.target, depth + 1)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t/** The condition, run on the caller's `ctx`. Its absence is a caller's bug, not a denial. */\n\tprivate passes(\n\t\trule: ResolvedRule,\n\t\ttype: ResolvedObjectType,\n\t\tname: string,\n\t): boolean {\n\t\tif (this.ctx === undefined) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`can: ${type.name}.${name} reaches a condition, and no ctx was passed — pass { ctx }`,\n\t\t\t);\n\t\t}\n\t\treturn (rule.test as (ctx: unknown) => boolean)(this.ctx) === true;\n\t}\n\n\t/** The objects an arrow through `relation` reaches from `node`. */\n\tprivate async targets(\n\t\ttype: ResolvedObjectType,\n\t\tnode: Node,\n\t\trelation: string,\n\t): Promise<Node[]> {\n\t\tconst through = type.relations.get(relation);\n\t\tif (through === undefined) return [];\n\n\t\tif (through.kind === 'fromField') {\n\t\t\tconst id = fieldOf(node, through.field, `${type.name}.${relation}`);\n\t\t\treturn id === null\n\t\t\t\t? []\n\t\t\t\t: [{ entity: { type: through.subject, id }, data: null }];\n\t\t}\n\t\t// An entity of a type the model does not admit here is no target.\n\t\treturn (await this.store.findEntities(node.entity, relation))\n\t\t\t.filter((entity) => admits(through.holders, entity))\n\t\t\t.map((entity) => ({\n\t\t\t\tentity: { type: entity.type, id: entity.id },\n\t\t\t\tdata: null,\n\t\t\t}));\n\t}\n}\n\n/** The id a `fromField` reads, or `null` for nobody. A missing field is the caller's bug. */\nfunction fieldOf(node: Node, field: string, what: string): string | null {\n\tif (node.data === null) {\n\t\t// resolveModel refuses a model that could get here.\n\t\tthrow new TypeError(\n\t\t\t`can: ${what} reads ${field} from an object nobody passed`,\n\t\t);\n\t}\n\tconst value = node.data[field];\n\tif (value === null) return null;\n\tif (typeof value !== 'string') {\n\t\tthrow new TypeError(\n\t\t\t`can: ${what} reads ${field}, which the object ${value === undefined ? 'does not carry — pass the loaded object, spread' : 'holds as something other than a string id'}`,\n\t\t);\n\t}\n\treturn value;\n}\n",
10
- "/**\n * The engine: `permissions({ model, store })`, the traversal behind `can()`,\n * and the same traversal run backwards behind `list()` — `walk.ts` and\n * `reverse.ts`; what a caller passes is read in `input.ts`.\n *\n * **The invariant, permission side.** A denial is `false` — never a thrown\n * error, which is how Keto's historical endpoint answers and why a denial and\n * an outage look alike there. A failure throws — never `false`, which would\n * deny everybody everything during an outage and say nothing. The store is\n * reached only through `guardRelations`, and `outage.spec.ts` refuses a `catch`\n * anywhere in this directory.\n *\n * **What is walked.** A relation holds when the tuple is stored, or through a\n * subject set holding it (`team:t1#member`), or — for a `fromField` — when the\n * object's field names the subject. A permission holds when any of its rules\n * does: a name of the same object, an arrow to a related object's permission,\n * either under a condition. The walk is sequential and stops at the first\n * grant, so a check reads no more than it needs.\n *\n * **Cycles and depth.** A node already on the current path — a team member of\n * a team member of itself — is cut: that branch grants nothing, and it is not\n * an error, because it is data. Crossing more than `maxDepth` relations *is*\n * an error, `PERMISSION_DEPTH`: an evaluation that stopped half-way decided\n * nothing, and `false` would hide it.\n */\n\nimport { guardRelations } from '../auth/outage';\nimport type { CursorPage } from '../pagination/cursor-page';\nimport { pageLimit } from '../pagination/cursor-page';\nimport { objectOf, subjectOf, tupleOf, typeOf } from './input';\nimport type { ModelConfig, PermissionModel, Permissions } from './model';\nimport { resolvedOf } from './model';\nimport type { RelationStore } from './port/types';\nimport { Reverse } from './reverse';\nimport { Walk } from './walk';\n\n/** Deep enough for any hierarchy a person draws; OpenFGA's default too. */\nconst DEFAULT_MAX_DEPTH = 25;\n\nconst REQUIRED = [\n\t'write',\n\t'has',\n\t'findSubjectSets',\n\t'findEntities',\n\t'findObjects',\n\t'deleteEntity',\n] as const;\n\nexport interface PermissionsOptions<C extends ModelConfig> {\n\t/** What `defineModel()` answered. */\n\treadonly model: PermissionModel<C>;\n\t/** Where tuples live. `createMemoryRelations()` in tests. */\n\treadonly store: RelationStore;\n\t/** How many relations a check may cross. `25` when absent. */\n\treadonly maxDepth?: number;\n}\n\n/**\n * Binds a model to a relation store. Connects to nothing.\n *\n * ```ts\n * const access = permissions({ model, store: createMemoryRelations() });\n * await access.grant({ type: 'team', id: 't1' }, 'member', staff);\n * await access.can(staff, 'view', { type: 'record', ...record }, { ctx: { onShift } });\n * ```\n */\nexport function permissions<C extends ModelConfig>(\n\toptions: PermissionsOptions<C>,\n): Permissions<C> {\n\tconst where = 'permissions';\n\tconst model = resolvedOf(options.model);\n\tconst maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;\n\tif (!Number.isInteger(maxDepth) || maxDepth < 1) {\n\t\tthrow new TypeError(`${where}: maxDepth must be a positive integer`);\n\t}\n\tconst raw = options.store as unknown as Record<string, unknown> | undefined;\n\tfor (const method of REQUIRED) {\n\t\tif (typeof raw?.[method] !== 'function') {\n\t\t\tthrow new TypeError(`${where}: store.${method} is missing`);\n\t\t}\n\t}\n\tconst store = guardRelations(options.store);\n\n\tconst check = async (\n\t\tsubject: unknown,\n\t\tpermission: string,\n\t\tobject: unknown,\n\t\toptions?: { readonly ctx?: unknown },\n\t): Promise<boolean> => {\n\t\t// Anonymous, before anything else — and before the store.\n\t\tif (subject === null || subject === undefined) return false;\n\n\t\tconst root = objectOf(model, object, 'can');\n\t\tconst type = typeOf(model, root.type, 'can');\n\t\tif (!type.relations.has(permission) && !type.permissions.has(permission)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`can: \"${permission}\" is not a relation or a permission of ${type.name}`,\n\t\t\t);\n\t\t}\n\n\t\treturn new Walk(\n\t\t\tmodel,\n\t\t\tstore,\n\t\t\tmaxDepth,\n\t\t\toptions?.ctx,\n\t\t\t`${type.name}#${permission}`,\n\t\t).holds(\n\t\t\tsubjectOf(model, subject, 'can'),\n\t\t\t{ entity: { type: root.type, id: root.id }, data: root.data },\n\t\t\tpermission,\n\t\t\t0,\n\t\t);\n\t};\n\n\tconst list = async (\n\t\tsubject: unknown,\n\t\tpermission: string,\n\t\ttypeName: unknown,\n\t\toptions?: {\n\t\t\treadonly ctx?: unknown;\n\t\t\treadonly after?: string | null;\n\t\t\treadonly limit?: number;\n\t\t},\n\t): Promise<CursorPage<string>> => {\n\t\tconst limit = pageLimit(options?.limit, 'list');\n\t\tconst after = options?.after ?? null;\n\t\tif (after !== null && typeof after !== 'string') {\n\t\t\tthrow new TypeError(\n\t\t\t\t'list: after must be the nextCursor of a page, or null',\n\t\t\t);\n\t\t}\n\t\t// Anonymous holds nothing, and the store is not asked.\n\t\tif (subject === null || subject === undefined) {\n\t\t\treturn { items: [], nextCursor: null };\n\t\t}\n\n\t\tif (typeof typeName !== 'string') {\n\t\t\tthrow new TypeError('list: the type must be an object type of the model');\n\t\t}\n\t\tconst type = typeOf(model, typeName, 'list');\n\t\tif (!type.relations.has(permission) && !type.permissions.has(permission)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`list: \"${permission}\" is not a relation or a permission of ${type.name}`,\n\t\t\t);\n\t\t}\n\n\t\tconst ids = await new Reverse(\n\t\t\tmodel,\n\t\t\tstore,\n\t\t\tmaxDepth,\n\t\t\toptions?.ctx,\n\t\t\tsubjectOf(model, subject, 'list'),\n\t\t\t`${type.name}#${permission}`,\n\t\t).objects(type.name, permission);\n\n\t\tconst rest = [...ids].sort().filter((id) => after === null || id > after);\n\t\tconst items = rest.slice(0, limit);\n\t\tconst last = items.at(-1);\n\t\treturn {\n\t\t\titems,\n\t\t\tnextCursor: rest.length > limit && last !== undefined ? last : null,\n\t\t};\n\t};\n\n\tconst change =\n\t\t(operation: 'grant' | 'revoke') =>\n\t\tasync (object: unknown, relation: string, subject: unknown) => {\n\t\t\tconst tuple = tupleOf(model, object, relation, subject, operation);\n\t\t\tawait store.write(\n\t\t\t\toperation === 'grant' ? { add: [tuple] } : { remove: [tuple] },\n\t\t\t);\n\t\t};\n\n\treturn Object.freeze({\n\t\tmodel: options.model,\n\t\tcan: check as Permissions<C>['can'],\n\t\tlist: list as Permissions<C>['list'],\n\t\tgrant: change('grant') as Permissions<C>['grant'],\n\t\trevoke: change('revoke') as Permissions<C>['revoke'],\n\t});\n}\n"
10
+ "/**\n * The engine: `permissions({ model, store })`, the traversal behind `can()`,\n * and the same traversal run backwards behind `list()` — `walk.ts` and\n * `reverse.ts`; what a caller passes is read in `input.ts`.\n *\n * **The invariant, permission side.** A denial is `false` — never a thrown\n * error, which is how Keto's historical endpoint answers and why a denial and\n * an outage look alike there. A failure throws — never `false`, which would\n * deny everybody everything during an outage and say nothing. The store is\n * reached only through `guardRelations`, and `outage.spec.ts` refuses a `catch`\n * anywhere in this directory.\n *\n * **What is walked.** A relation holds when the tuple is stored, or through a\n * subject set holding it (`team:t1#member`), or — for a `fromField` — when the\n * object's field names the subject. A permission holds when any of its rules\n * does: a name of the same object, an arrow to a related object's permission,\n * either under a condition. The walk is sequential and stops at the first\n * grant, so a check reads no more than it needs.\n *\n * **Cycles and depth.** A node already on the current path — a team member of\n * a team member of itself — is cut: that branch grants nothing, and it is not\n * an error, because it is data. Crossing more than `maxDepth` relations *is*\n * an error, `PERMISSION_DEPTH`: an evaluation that stopped half-way decided\n * nothing, and `false` would hide it.\n */\n\nimport type { CursorPage } from '../pagination/cursor-page';\nimport { pageLimit } from '../pagination/cursor-page';\nimport { guardRelations } from '../stores/guard';\nimport { objectOf, subjectOf, tupleOf, typeOf } from './input';\nimport type { ModelConfig, PermissionModel, Permissions } from './model';\nimport { resolvedOf } from './model';\nimport type { RelationStore } from './port/types';\nimport { Reverse } from './reverse';\nimport { Walk } from './walk';\n\n/** Deep enough for any hierarchy a person draws; OpenFGA's default too. */\nconst DEFAULT_MAX_DEPTH = 25;\n\nconst REQUIRED = [\n\t'write',\n\t'has',\n\t'findSubjectSets',\n\t'findEntities',\n\t'findObjects',\n\t'deleteEntity',\n] as const;\n\nexport interface PermissionsOptions<C extends ModelConfig> {\n\t/** What `defineModel()` answered. */\n\treadonly model: PermissionModel<C>;\n\t/** Where tuples live. `createMemoryRelations()` in tests. */\n\treadonly store: RelationStore;\n\t/** How many relations a check may cross. `25` when absent. */\n\treadonly maxDepth?: number;\n}\n\n/**\n * Binds a model to a relation store. Connects to nothing.\n *\n * ```ts\n * const access = permissions({ model, store: createMemoryRelations() });\n * await access.grant({ type: 'team', id: 't1' }, 'member', staff);\n * await access.can(staff, 'view', { type: 'record', ...record }, { ctx: { onShift } });\n * ```\n */\nexport function permissions<C extends ModelConfig>(\n\toptions: PermissionsOptions<C>,\n): Permissions<C> {\n\tconst where = 'permissions';\n\tconst model = resolvedOf(options.model);\n\tconst maxDepth = options.maxDepth ?? DEFAULT_MAX_DEPTH;\n\tif (!Number.isInteger(maxDepth) || maxDepth < 1) {\n\t\tthrow new TypeError(`${where}: maxDepth must be a positive integer`);\n\t}\n\tconst raw = options.store as unknown as Record<string, unknown> | undefined;\n\tfor (const method of REQUIRED) {\n\t\tif (typeof raw?.[method] !== 'function') {\n\t\t\tthrow new TypeError(`${where}: store.${method} is missing`);\n\t\t}\n\t}\n\tconst store = guardRelations(options.store);\n\n\tconst check = async (\n\t\tsubject: unknown,\n\t\tpermission: string,\n\t\tobject: unknown,\n\t\toptions?: { readonly ctx?: unknown },\n\t): Promise<boolean> => {\n\t\t// Anonymous, before anything else — and before the store.\n\t\tif (subject === null || subject === undefined) return false;\n\n\t\tconst root = objectOf(model, object, 'can');\n\t\tconst type = typeOf(model, root.type, 'can');\n\t\tif (!type.relations.has(permission) && !type.permissions.has(permission)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`can: \"${permission}\" is not a relation or a permission of ${type.name}`,\n\t\t\t);\n\t\t}\n\n\t\treturn new Walk(\n\t\t\tmodel,\n\t\t\tstore,\n\t\t\tmaxDepth,\n\t\t\toptions?.ctx,\n\t\t\t`${type.name}#${permission}`,\n\t\t).holds(\n\t\t\tsubjectOf(model, subject, 'can'),\n\t\t\t{ entity: { type: root.type, id: root.id }, data: root.data },\n\t\t\tpermission,\n\t\t\t0,\n\t\t);\n\t};\n\n\tconst list = async (\n\t\tsubject: unknown,\n\t\tpermission: string,\n\t\ttypeName: unknown,\n\t\toptions?: {\n\t\t\treadonly ctx?: unknown;\n\t\t\treadonly after?: string | null;\n\t\t\treadonly limit?: number;\n\t\t},\n\t): Promise<CursorPage<string>> => {\n\t\tconst limit = pageLimit(options?.limit, 'list');\n\t\tconst after = options?.after ?? null;\n\t\tif (after !== null && typeof after !== 'string') {\n\t\t\tthrow new TypeError(\n\t\t\t\t'list: after must be the nextCursor of a page, or null',\n\t\t\t);\n\t\t}\n\t\t// Anonymous holds nothing, and the store is not asked.\n\t\tif (subject === null || subject === undefined) {\n\t\t\treturn { items: [], nextCursor: null };\n\t\t}\n\n\t\tif (typeof typeName !== 'string') {\n\t\t\tthrow new TypeError('list: the type must be an object type of the model');\n\t\t}\n\t\tconst type = typeOf(model, typeName, 'list');\n\t\tif (!type.relations.has(permission) && !type.permissions.has(permission)) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`list: \"${permission}\" is not a relation or a permission of ${type.name}`,\n\t\t\t);\n\t\t}\n\n\t\tconst ids = await new Reverse(\n\t\t\tmodel,\n\t\t\tstore,\n\t\t\tmaxDepth,\n\t\t\toptions?.ctx,\n\t\t\tsubjectOf(model, subject, 'list'),\n\t\t\t`${type.name}#${permission}`,\n\t\t).objects(type.name, permission);\n\n\t\tconst rest = [...ids].sort().filter((id) => after === null || id > after);\n\t\tconst items = rest.slice(0, limit);\n\t\tconst last = items.at(-1);\n\t\treturn {\n\t\t\titems,\n\t\t\tnextCursor: rest.length > limit && last !== undefined ? last : null,\n\t\t};\n\t};\n\n\tconst change =\n\t\t(operation: 'grant' | 'revoke') =>\n\t\tasync (object: unknown, relation: string, subject: unknown) => {\n\t\t\tconst tuple = tupleOf(model, object, relation, subject, operation);\n\t\t\tawait store.write(\n\t\t\t\toperation === 'grant' ? { add: [tuple] } : { remove: [tuple] },\n\t\t\t);\n\t\t};\n\n\treturn Object.freeze({\n\t\tmodel: options.model,\n\t\tcan: check as Permissions<C>['can'],\n\t\tlist: list as Permissions<C>['list'],\n\t\tgrant: change('grant') as Permissions<C>['grant'],\n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K,UAAU,IAAI,UAAU,KAAK,CAAC,KAAK,YAAY,IAAI,UAAU,GAAG;AAAA,MACzE,MAAM,IAAI,UACT,UAAU,oDAAoD,KAAK,MACpE;AAAA,IACD;AAAA,IAEA,MAAM,MAAM,MAAM,IAAI,QACrB,OACA,OACA,UACA,SAAS,KACT,UAAU,OAAO,SAAS,MAAM,GAChC,GAAG,KAAK,QAAQ,YACjB,EAAE,QAAQ,KAAK,MAAM,UAAU;AAAA,IAE/B,MAAM,OAAO,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,UAAU,QAAQ,KAAK,KAAK;AAAA,IACxE,MAAM,QAAQ,KAAK,MAAM,GAAG,KAAK;AAAA,IACjC,MAAM,OAAO,MAAM,GAAG,EAAE;AAAA,IACxB,OAAO;AAAA,MACN;AAAA,MACA,YAAY,KAAK,SAAS,SAAS,SAAS,YAAY,OAAO;AAAA,IAChE;AAAA;AAAA,EAGD,MAAM,SACL,CAAC,cACD,OAAO,QAAiB,UAAkB,YAAqB;AAAA,IAC9D,MAAM,QAAQ,QAAQ,OAAO,QAAQ,UAAU,SAAS,SAAS;AAAA,IACjE,MAAM,MAAM,MACX,cAAc,UAAU,EAAE,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,EAAE,CAC9D;AAAA;AAAA,EAGF,OAAO,OAAO,OAAO;AAAA,IACpB,OAAO,QAAQ;AAAA,IACf,KAAK;AAAA,IACL;AAAA,IACA,OAAO,OAAO,OAAO;AAAA,IACrB,QAAQ,OAAO,QAAQ;AAAA,EACxB,CAAC;AAAA;",
13
+ "debugId": "B13C4A414094D54564756E2164756E21",
14
14
  "names": []
15
15
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * **The one place a store's answer is caught**, shared by both sides of the
3
+ * package: the identity stores and the relation store reach a caller only
4
+ * through {@link guardStore}.
5
+ *
6
+ * - A `JanusError` the store threw passes through, so `instanceof` holds.
7
+ * - **Anything else it threw is a failure** — `StoreFailure`, naming the slot
8
+ * and the method, with the original as `cause`. Never an absence.
9
+ * - `undefined` where the port says `null` is a store that forgot to answer,
10
+ * and becomes `StoreFailure` rather than "not found".
11
+ *
12
+ * The `catch` below always rethrows; `src/auth/outage.spec.ts` holds it to that.
13
+ */
14
+ import { StoreFailure } from '../errors/janus-error';
15
+ import type { RelationStore } from '../permissions/port/types';
16
+ /** A store the guard names in a `StoreFailure`: `users`, `sessions`, `tokens` or `relations`. */
17
+ export type StoreSlot = NonNullable<StoreFailure['slot']>;
18
+ export declare function guardStore<S extends object>(slot: StoreSlot, store: S): S;
19
+ /**
20
+ * The relation store, guarded the same way: the permission engine's only way
21
+ * to a store, so a failure there is `STORE_FAILED` and never a denial.
22
+ */
23
+ export declare function guardRelations(store: RelationStore): RelationStore;
24
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/stores/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAGN,YAAY,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,iGAAiG;AACjG,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AAS1D,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CA6BzE;AAoCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAElE"}
@@ -63,8 +63,8 @@ export declare function isSubjectSet(subject: Subject): subject is SubjectSet;
63
63
  /**
64
64
  * The subject a user is: their `type` and `id`, and nothing else.
65
65
  *
66
- * One line, and the entire join between the two halves of the package. It
67
- * takes the narrowest shape it reads, so the permissions half never has to
66
+ * One line, and the entire join between the two sides of the package. It
67
+ * takes the narrowest shape it reads, so the permissions side never has to
68
68
  * know what a user is, and it copies those two fields so none of the user's
69
69
  * own fields ever reaches a tuple.
70
70
  */
package/docs/README.md CHANGED
@@ -3,15 +3,31 @@
3
3
  The [README](../README.md) shows that it works; these pages show how, one area
4
4
  at a time, with an example for every option.
5
5
 
6
+ Janus has two sides, each usable alone — see
7
+ [Three ways to use it](../README.md#three-ways-to-use-it) — and the words
8
+ below are defined once, in [Words](guide/vocabulary.md#words).
9
+
10
+ ### Identities — `janus()`
11
+
6
12
  | Page | Read it when |
7
13
  | --- | --- |
8
- | [Users — `janus()`](guide/users.md) | You are wiring `janus()`, declaring one or several kinds of user, or calling `create`, `update`, `list`, `delete` |
14
+ | [Users](guide/users.md) | You are wiring `janus()`, declaring one or several user types, or calling `create`, `update`, `list`, `delete` |
9
15
  | [Sessions](guide/sessions.md) | You need to know who a request belongs to, set or clear the cookie, renew, sign out, or test expiry |
10
16
  | [E-mail verification and password reset](guide/email-flows.md) | You are sending a verification or reset link, and handling what comes back |
11
17
  | [Password hashing](guide/passwords.md) | You are choosing a hasher, raising its cost, moving to argon2id, or importing hashes from another system |
18
+
19
+ ### Permissions — `@nxgt/janus/permissions`
20
+
21
+ | Page | Read it when |
22
+ | --- | --- |
12
23
  | [Permissions](guide/permissions.md) | You are modelling access with `defineModel`, `fromField` and `when`, and calling `can`, `list`, `grant`, `revoke` |
24
+
25
+ ### Shared by both sides
26
+
27
+ | Page | Read it when |
28
+ | --- | --- |
29
+ | [The shared vocabulary](guide/vocabulary.md) | You want the words the documentation uses, or subjects and the tuple notation, ids, cursors, durations or `fixedClock` |
13
30
  | [Errors](guide/errors.md) | You are turning what the package throws into a status code, and want every code and what it carries |
14
- | [The shared vocabulary](guide/vocabulary.md) | You need subjects and the tuple notation, ids, cursors, durations or `fixedClock` |
15
- | [Writing an adapter](guide/adapters.md) | You are implementing the store port or the relation store for your database, and running the conformance suites |
31
+ | [Writing an adapter](guide/adapters.md) | You are implementing the identity stores or the relation store for your database, and running the conformance suites |
16
32
  | [Troubleshooting](troubleshooting.md) | You have an error message and want its cause and its fix |
17
33
  | [Roadmap](roadmap.md) | You want to know what is coming, what shipped, and what is deliberately not planned |
@@ -1,4 +1,4 @@
1
- # Writing an adapter — the store port and `@nxgt/janus/conformance`
1
+ # Writing an adapter — the ports and `@nxgt/janus/conformance`
2
2
 
3
3
  This page is for putting `janus()` or `permissions()` on a database of your
4
4
  choice: the two ports you implement, the rules they carry, and the conformance
@@ -100,7 +100,7 @@ interface TokenStore {
100
100
  and answers it **as it was before the call**, in **one conditional write**.
101
101
  Twenty concurrent calls must produce exactly one answer with `spentAt: null`;
102
102
  in MongoDB that is one `findOneAndUpdate` returning the document before the
103
- update. A read followed by a write lets two requests redeem one reset code.
103
+ update. A read followed by a write lets two requests redeem one reset token.
104
104
 
105
105
  Expiry is the core's decision: a read answers a stored session verbatim,
106
106
  lapsed or revoked, and never a record it has changed.
@@ -278,10 +278,10 @@ for (const conformanceCase of allCases) {
278
278
 
279
279
  | Export | What it is |
280
280
  | --- | --- |
281
- | `allCases`, `userStoreCases`, `sessionStoreCases`, `tokenStoreCases`, `outageCases` | The user-port cases, as `ConformanceCase` objects with a stable `id` |
281
+ | `allCases`, `userStoreCases`, `sessionStoreCases`, `tokenStoreCases`, `outageCases` | The identity stores' cases, as `ConformanceCase` objects with a stable `id` |
282
282
  | `runCase(case, harness)` | Runs one; throws on failure, answers `{ passed: true }` or `{ skipped }` |
283
283
  | `SKIP_REASONS` | The reasons the suite gives itself |
284
- | `allRelationCases`, `relationStoreCases`, `relationOutageCases`, `runRelationCase` | The same for the relation port |
284
+ | `allRelationCases`, `relationStoreCases`, `relationOutageCases`, `runRelationCase` | The same for the relation store |
285
285
  | `referenceHarness()`, `referenceRelationHarness()` | The suites against the reference stores: the examples to copy |
286
286
 
287
287
  Types: `ConformanceHarness`, `OpenedStores`, `StoreFaults`, `ConformanceCase`,
@@ -53,8 +53,8 @@ instead of answering `undefined`.
53
53
  answers `null`, `false` or an empty page. A store that cannot answer — a
54
54
  refused connection, a timeout, a primary stepping down, a bug in the adapter —
55
55
  rejects with `STORE_FAILED`. Answer 503. Mapping it to a 404, to `null` or to
56
- `false` turns an outage into a silent lockout: everybody who has an account is
57
- told they do not.
56
+ `false` turns an outage into a silent lockout: every user is
57
+ told they do not exist.
58
58
 
59
59
  ## Two kinds of refusal
60
60
 
@@ -109,7 +109,7 @@ async function signIn(email: string, password: string): Promise<Response> {
109
109
  ```
110
110
 
111
111
  - **Never put `reason` in a response body.** `unknownLogin` tells an attacker
112
- which accounts exist.
112
+ which users exist.
113
113
  - **`STORE_FAILED` is never a 401 or a 404.** Test for it before anything that
114
114
  would read as "no".
115
115
  - **`VERSION_CONFLICT` is a retry**: read the user again, reapply, write with
@@ -127,7 +127,7 @@ per prefix the old system wrote (`$2a$`, `$2b$`, `$2y$` for bcrypt).
127
127
  - The plain password is never stored, and never appears in an error message.
128
128
  - The hash never reaches a `User` — `hasPassword` says whether there is one.
129
129
  - `signIn` compares against a dummy hash when nobody holds the login, so the
130
- time taken does not reveal which accounts exist. The store's own latency
130
+ time taken does not reveal which users exist. The store's own latency
131
131
  still can, and that limit is stated rather than denied.
132
132
 
133
133
  ## See also
@@ -6,6 +6,11 @@ Zanzibar's model — relations between objects and subjects, permissions
6
6
  computed from them — **without its infrastructure**: the tuples live in your
7
7
  database, so a read follows a write and there is nothing to cache.
8
8
 
9
+ It is the **permissions** side, and it is usable alone: the example below wires
10
+ it to `janus()` so the user types become the subjects, but `subjects` takes
11
+ any list of names — `defineModel({ subjects: ['user'], … })` — when your users
12
+ live elsewhere. Importing `@nxgt/janus/permissions` loads no identity code.
13
+
9
14
  ```ts
10
15
  import { z } from 'zod';
11
16
  import { createMemoryStores, janus, scryptHasher } from '@nxgt/janus';
@@ -257,8 +262,8 @@ own for that.
257
262
  ### `grant` and `revoke`
258
263
 
259
264
  ```ts
260
- grant(object, relation, holder): Promise<void>;
261
- revoke(object, relation, holder): Promise<void>;
265
+ grant(object, relation, subject): Promise<void>;
266
+ revoke(object, relation, subject): Promise<void>;
262
267
  ```
263
268
 
264
269
  Both are typed from the model: only a stored relation (never a `fromField`),
@@ -53,11 +53,11 @@ await auth.authenticate({ headers: { cookie: `janus-session=${token}` } });
53
53
  ```
54
54
 
55
55
  It reads `Authorization: Bearer`, then `X-Session-Token`, then the cookie.
56
- **The first credential present wins, not the first valid one**: a client that
56
+ **The first session credential present wins, not the first valid one**: a client that
57
57
  sends a lapsed bearer beside a live cookie is anonymous. An `Authorization`
58
58
  header of another scheme (`Basic`) is not a session credential.
59
59
 
60
- It answers `null` — anonymous — for no credential, an unknown token, a lapsed
60
+ It answers `null` — anonymous — for no session credential, an unknown token, a lapsed
61
61
  or revoked session, a user deleted or inactive, or a user of another type than
62
62
  `options.type`:
63
63
 
@@ -1,8 +1,9 @@
1
1
  # Users — `janus()`
2
2
 
3
3
  This page is for wiring `janus()` and managing users with it: the
4
- configuration, one or several kinds of user, and every method a user type
5
- answers. Sessions have [their own page](sessions.md), and so do the
4
+ configuration, one or several user types, and every method a user type
5
+ answers. It is the **identities** side, usable alone: nothing here needs
6
+ [permissions](permissions.md), and `@nxgt/janus` loads none of their code. Sessions have [their own page](sessions.md), and so do the
6
7
  [e-mail flows](email-flows.md) and [password hashing](passwords.md).
7
8
 
8
9
  ```ts
@@ -71,8 +72,8 @@ before the store sees it.
71
72
 
72
73
  | Option | Type | Default | Effect |
73
74
  | --- | --- | --- | --- |
74
- | `user` | Standard Schema | — | One kind of user, named `'user'`. Exactly one of `user` and `users` |
75
- | `users` | `{ [type]: UserTypeConfig }` | — | Several kinds of user. See [Several kinds of user](#several-kinds-of-user) |
75
+ | `user` | Standard Schema | — | One user type, named `'user'`. Exactly one of `user` and `users` |
76
+ | `users` | `{ [type]: UserTypeConfig }` | — | Several user types. See [Several user types](#several-user-types) |
76
77
  | `password.login` | a field name | — | The field users sign in with: a **top-level, required string** field. A typo is a compile error |
77
78
  | `password.normalize` | `'none' \| 'lowercase' \| 'lowercaseTrim' \| 'nfkcLowercaseTrim' \| (value) => string` | `'lowercaseTrim'` | Applied to the login before any store sees it, at sign-up and at sign-in alike |
78
79
  | `password.minLength` | integer ≥ 1 | `8` | Below it: `PASSWORD_TOO_SHORT` |
@@ -122,7 +123,7 @@ A function is accepted, and must be deterministic: the same rule normalises
122
123
  at sign-up and at sign-in. An e-mail used by the e-mail flows is always
123
124
  compared lower-cased and trimmed, whatever the login's rule.
124
125
 
125
- ## Several kinds of user
126
+ ## Several user types
126
127
 
127
128
  ```ts
128
129
  const Patient = z.object({ email: z.email(), birthDate: z.string() });
@@ -151,7 +152,7 @@ if (current?.user.type === 'staff') current.user.service; // narrowed by type
151
152
 
152
153
  Each type carries `schema` and, optionally, `password`, `email`, `session`
153
154
  and `schemaVersion`, with the defaults above. A login is unique **per type**:
154
- the same e-mail may hold a patient account and a staff account. A type name is
155
+ the same e-mail may hold a patient user and a staff user. A type name is
155
156
  camelCase, and may not be one of `janus()`'s own methods (`authenticate`,
156
157
  `signOut`, `signOutEverywhere`, `findUser`, `getUser`, `cookie`,
157
158
  `collectExpired`, `types`) — a compile error, and a `TypeError` for a
@@ -274,4 +275,4 @@ fields against your schema, not that `password` is a string.
274
275
 
275
276
  - [Sessions](sessions.md) — `authenticate`, the cookie, signing out
276
277
  - [Errors](errors.md) — every code, and the status it deserves
277
- - [Writing an adapter](adapters.md) — the store port behind `store`
278
+ - [Writing an adapter](adapters.md) — the identity stores behind `store`