@htilabs/platform-common-models 0.4.0-beta.1 → 0.5.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/index.cjs +18 -9
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +18 -9
- package/dist/constants/index.js.map +1 -1
- package/dist/cvcs/index.cjs +316 -1
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +368 -26
- package/dist/cvcs/index.d.ts +368 -26
- package/dist/cvcs/index.js +314 -1
- package/dist/cvcs/index.js.map +1 -1
- package/dist/index.cjs +373 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -5
- package/dist/index.d.ts +50 -5
- package/dist/index.js +369 -12
- package/dist/index.js.map +1 -1
- package/dist/models/index.cjs +2 -2
- package/dist/models/index.cjs.map +1 -1
- package/dist/models/index.js +2 -2
- package/dist/models/index.js.map +1 -1
- package/dist/{platform-auth-C-G2qeGM.d.cts → platform-auth-CjC57132.d.cts} +10 -7
- package/dist/{platform-auth-C-G2qeGM.d.ts → platform-auth-CjC57132.d.ts} +10 -7
- package/dist/schemas/index.cjs +16 -7
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.js +16 -7
- package/dist/schemas/index.js.map +1 -1
- package/dist/services/index.cjs +2 -2
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.js +2 -2
- package/dist/services/index.js.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/validation/index.cjs.map +1 -1
- package/dist/validation/index.d.cts +2 -2
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/cvc-sot.snap +10 -2
- package/src/__tests__/cvc-sot-snapshot.test.ts +13 -1
- package/src/__tests__/cvc-structural.test.ts +1 -1
- package/src/constants/ic.ts +24 -14
- package/src/cvcs/incidentInvolvementRoles.v1.0.0.json +105 -0
- package/src/cvcs/incidentParticipationRoles.v1.0.0.json +202 -0
- package/src/cvcs/index.ts +4 -0
- package/src/cvcs/serviceStates.v1.0.0.json +1 -1
- package/src/generated/cvc-enums.ts +51 -2
- package/src/models/cvcEntryModel.ts +1 -1
- package/src/models/cvcRegistryModel.ts +1 -1
- package/src/validation/cvc.ts +6 -3
package/dist/services/index.cjs
CHANGED
|
@@ -972,7 +972,7 @@ var _cvcRegistrySchema = buildCvcRegistrySchema();
|
|
|
972
972
|
|
|
973
973
|
// src/models/cvcRegistryModel.ts
|
|
974
974
|
function compileModel(connection, schema = buildCvcRegistrySchema()) {
|
|
975
|
-
return connection.models
|
|
975
|
+
return connection.models?.CvcRegistry ?? connection.model("CvcRegistry", schema);
|
|
976
976
|
}
|
|
977
977
|
|
|
978
978
|
// src/models/cvcEntryModel.ts
|
|
@@ -1076,7 +1076,7 @@ var _cvcEntrySchema = buildCvcEntrySchema();
|
|
|
1076
1076
|
|
|
1077
1077
|
// src/models/cvcEntryModel.ts
|
|
1078
1078
|
function compileModel2(connection, schema = buildCvcEntrySchema()) {
|
|
1079
|
-
return connection.models
|
|
1079
|
+
return connection.models?.CvcEntry ?? connection.model("CvcEntry", schema);
|
|
1080
1080
|
}
|
|
1081
1081
|
|
|
1082
1082
|
// src/services/cvcRegistryService.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/index.ts","../../src/services/cvcRegistryService.ts","../../src/schemas/form.ts","../../src/schemas/section.ts","../../src/schemas/question.ts","../../src/schemas/scoring-rule.ts","../../src/schemas/platform-function.ts","../../src/constants/platform-auth.ts","../../src/schemas/platform-role.ts","../../src/models/cvcRegistryModel.ts","../../src/schemas/cvcRegistry.ts","../../src/models/cvcEntryModel.ts","../../src/schemas/cvcEntry.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Services\n *\n * Runtime services that operate on the platform models. Currently houses\n * the CVC registry runtime API; future services (form resolution, etc.)\n * should follow the same export pattern.\n */\n\nexport {\n CvcRegistryService,\n cascadeExclusions,\n applyEntryOverrides,\n resolveRegistryWithInheritance,\n cvcVersionsToRecord,\n type RegistryScope,\n type CvcRegistryServiceOptions,\n type ICvcRegistry,\n type ICvcEntry,\n type RegistryLoader,\n type EntryLoader,\n} from \"./cvcRegistryService.js\";\n","/**\n * @htilabs/platform-common-models — CvcRegistryService\n *\n * Runtime API for resolving Controlled Vocabulary (CVC) data through a\n * registry. The service is the canonical entry point used by Thread, PAVE,\n * and any other consumer that needs \"give me the entries that are live in\n * scope X right now\". It hides three concerns from callers:\n *\n * 1. **Scope resolution.** Callers ask in terms of `{application, agencyId}`;\n * the service walks the agency-specific → app-specific → platform-default\n * fallback chain to find the active registry.\n * 2. **Inheritance.** A registry may be `basedOn` another registry. The\n * service merges the parent's pinned `cvcVersions` under the child's,\n * then applies the child's own `excludedEntries` / `includedEntries`\n * overrides on top of the merged entry pool.\n * 3. **Caching.** Resolved entry sets are memoised per active registry, and\n * flushed on `activate()` / `deprecate()` so that the next read picks\n * up the new pin.\n *\n * Locked spec reference:\n * §9.1.1 — Entry resolution logic (default / blacklist / whitelist modes)\n * §9.1.2 — `basedOn` inheritance resolution\n * §9.6 — Service API surface\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * The pure helpers (`cascadeExclusions`, `applyEntryOverrides`,\n * `resolveRegistryWithInheritance`) are exported alongside the class so\n * they can be unit-tested without a Mongoose connection.\n */\n\nimport { Types } from \"mongoose\";\nimport type { Connection, Model } from \"mongoose\";\n\nimport { cvcRegistryModel, cvcEntryModel } from \"../models/index.js\";\n\n// ─── Public types ────────────────────────────────────────────────────────────\n\n/**\n * Plain document shape for a `cvc_entries` row. Mirrors the Mongoose schema\n * in `schemas/cvcEntry.ts` (co-am3.2) and the locked spec §9.1.2 interface.\n *\n * Defined locally rather than imported because the schema-derived\n * `InferRawDocType<typeof schema>` types in `schemas/cvcEntry.ts` widen to\n * the Schema instance type — they're not usable as document shapes. This\n * interface is the canonical document contract for the service layer.\n */\nexport interface ICvcEntry {\n domain: string;\n version: string;\n code: string;\n key: string;\n title: string;\n selectable: boolean;\n parentCode: string | null;\n childCodes: string[];\n definition: string | null;\n meta?: Record<string, unknown> | null;\n createdAt?: Date;\n updatedAt?: Date;\n}\n\n/**\n * Plain document shape for a `cvc_registries` row. Mirrors the Mongoose\n * schema in `schemas/cvcRegistry.ts` (co-am3.2) and the locked spec §9.1.1\n * interface. See {@link ICvcEntry} for why this is defined locally.\n *\n * `cvcVersions` is typed as either a `Map` (raw mongoose hydrated doc) or\n * a plain object (from `.lean()` / `.toObject()`). The pure helpers\n * normalise both forms via {@link cvcVersionsToRecord}.\n */\nexport interface ICvcRegistry {\n _id: Types.ObjectId;\n version: string;\n name: string;\n application: string | null;\n agencyId: Types.ObjectId | null;\n status: \"draft\" | \"active\" | \"deprecated\";\n dateActivated?: Date | null;\n dateDeactivated?: Date | null;\n cvcVersions: Map<string, string> | Record<string, string>;\n excludedEntries: string[];\n includedEntries: string[];\n basedOn: Types.ObjectId | null;\n createdAt?: Date;\n updatedAt?: Date;\n}\n\n/**\n * Lookup scope for convenience methods. `null`/`undefined` widens the scope:\n * a missing `application` matches the platform-default registry; a missing\n * `agencyId` matches the application-wide registry.\n *\n * Locked spec §9.6 — scope hierarchy.\n */\nexport interface RegistryScope {\n application?: string | null;\n agencyId?: Types.ObjectId | null;\n}\n\n/**\n * Options accepted by the service constructor. Kept as a single object so\n * future toggles (telemetry, custom cache, etc.) can be added without\n * breaking the call site.\n */\nexport interface CvcRegistryServiceOptions {\n /**\n * When `true` (default), `getActiveRegistry` walks the\n * agency → application → platform fallback chain. When `false`, only the\n * exact requested scope is consulted.\n */\n scopeFallback?: boolean;\n}\n\n\n// ─── Pure helpers (exported for unit tests) ──────────────────────────────────\n\n/**\n * Convert a Mongoose `Map<string, string>` (or a plain object that came from\n * `.toObject()`) into a `Record<string, string>`. The Mongoose schema stores\n * `cvcVersions` as a `Map`, but the resolution logic in the locked spec is\n * written against `Object.entries(...)` — this normaliser bridges the gap\n * once at the entry to the pure layer.\n *\n * @param versions - Either a Map (raw mongoose doc) or a plain record\n * @returns A plain object whose keys are CVC domains and values are versions\n */\nexport function cvcVersionsToRecord(\n versions: Map<string, string> | Record<string, string> | undefined | null,\n): Record<string, string> {\n if (!versions) return {};\n if (versions instanceof Map) {\n return Object.fromEntries(versions.entries());\n }\n return { ...versions };\n}\n\n/**\n * Compute the cascading-exclusion set for a CVC entry pool.\n *\n * Cascading exclusion (locked spec §9.1.1) treats the entry tree as a DAG of\n * `parentCode → code` edges. Excluding a node implicitly excludes every\n * descendant reachable from it. The result set always contains the original\n * `excludedCodes` plus every transitively-reachable child.\n *\n * Implemented as breadth-first walk over a parent → children index built\n * from the entry pool. Time/space complexity is `O(N)` in the entry count.\n *\n * @param excludedCodes - Codes the registry explicitly excludes\n * @param entries - The entry pool to cascade through\n * @returns Set containing every excluded code plus every descendant\n */\nexport function cascadeExclusions(\n excludedCodes: ReadonlySet<string>,\n entries: readonly ICvcEntry[],\n): Set<string> {\n const result = new Set<string>(excludedCodes);\n\n // Build parent → children adjacency once. Entries with `parentCode === null`\n // are tree roots and contribute no edges.\n const childMap = new Map<string, string[]>();\n for (const entry of entries) {\n if (entry.parentCode) {\n const siblings = childMap.get(entry.parentCode);\n if (siblings) {\n siblings.push(entry.code);\n } else {\n childMap.set(entry.parentCode, [entry.code]);\n }\n }\n }\n\n // BFS from every initially-excluded code. The visited check (`!result.has`)\n // both prevents infinite loops on accidental cycles and ensures O(N) work.\n const queue: string[] = [...excludedCodes];\n while (queue.length > 0) {\n const code = queue.shift() as string;\n const children = childMap.get(code);\n if (!children) continue;\n for (const childCode of children) {\n if (!result.has(childCode)) {\n result.add(childCode);\n queue.push(childCode);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Apply a registry's `excludedEntries` / `includedEntries` overrides to a\n * pre-loaded entry pool. Implements the four-mode table from locked spec\n * §9.1.1:\n *\n * | excludedEntries | includedEntries | Mode |\n * | --------------- | --------------- | ------------------ |\n * | empty | empty | Default (all) |\n * | has values | empty | Blacklist |\n * | empty | has values | Whitelist |\n * | has values | has values | Blacklist + override |\n *\n * Inclusion always wins over exclusion in the override mode — that's how\n * agencies pull a single descendant back in after excluding its parent.\n *\n * @param excludedEntries - Codes the registry excludes (cascades to children)\n * @param includedEntries - Codes the registry force-includes (override or whitelist)\n * @param entries - The merged entry pool from all pinned domains\n * @returns A new array containing only the entries selected by the overrides\n */\nexport function applyEntryOverrides(\n excludedEntries: readonly string[] | null | undefined,\n includedEntries: readonly string[] | null | undefined,\n entries: readonly ICvcEntry[],\n): ICvcEntry[] {\n const excluded = new Set(excludedEntries ?? []);\n const included = new Set(includedEntries ?? []);\n const hasExclusions = excluded.size > 0;\n const hasInclusions = included.size > 0;\n\n // Default mode: no overrides at all → return the pool unchanged.\n if (!hasExclusions && !hasInclusions) {\n return [...entries];\n }\n\n // Whitelist mode: start from empty and pull in only the listed codes.\n if (!hasExclusions && hasInclusions) {\n return entries.filter((entry) => included.has(entry.code));\n }\n\n // Blacklist mode (with optional override): cascade the exclusion set, then\n // filter the pool, letting any explicitly-included code punch through.\n const cascadedExclusions = cascadeExclusions(excluded, entries);\n return entries.filter((entry) => {\n if (included.has(entry.code)) return true;\n if (cascadedExclusions.has(entry.code)) return false;\n return true;\n });\n}\n\n/**\n * Loader signature: fetch a registry document by id. Used by\n * `resolveRegistryWithInheritance` to walk the `basedOn` pointer without\n * needing a live Mongoose connection.\n */\nexport type RegistryLoader = (\n id: Types.ObjectId,\n) => Promise<ICvcRegistry | null>;\n\n/**\n * Loader signature: fetch all entries for a `(domain, version)` tuple. Used\n * by `resolveRegistryWithInheritance` so the pure resolution layer can be\n * tested with in-memory fixtures instead of a real `cvc_entries` collection.\n */\nexport type EntryLoader = (\n domain: string,\n version: string,\n) => Promise<ICvcEntry[]>;\n\n/**\n * Resolve a registry into its effective `(mergedVersions, entries)` pair,\n * walking exactly one level of `basedOn` inheritance per locked spec §9.1.2.\n *\n * The spec constrains `basedOn` chains to two levels (base → child); the\n * implementation enforces that constraint by **only** consulting the\n * immediate parent. Deeper grandparents are ignored even if a misconfigured\n * registry chains further — this matches the contract that downstream\n * callers see at most one merge step.\n *\n * Resolution order (locked spec §9.1.2):\n * 1. Start with the child's own `cvcVersions`\n * 2. If the child has `basedOn`, load the parent and overlay the child's\n * `cvcVersions` on top of the parent's (child wins per-domain)\n * 3. Load entries for every merged `(domain, version)` tuple\n * 4. Apply the child's own `excludedEntries` / `includedEntries` to the\n * merged pool — inheritance does not propagate overrides\n *\n * @param registry - The child registry being resolved\n * @param loadRegistry - Loader for the parent registry (only called if `basedOn` is set)\n * @param loadEntries - Loader for entry pools by (domain, version)\n * @returns The merged version pins and the resolved effective entry list\n */\nexport async function resolveRegistryWithInheritance(\n registry: ICvcRegistry,\n loadRegistry: RegistryLoader,\n loadEntries: EntryLoader,\n): Promise<{\n mergedVersions: Record<string, string>;\n entries: ICvcEntry[];\n}> {\n const childVersions = cvcVersionsToRecord(registry.cvcVersions);\n let mergedVersions: Record<string, string> = { ...childVersions };\n\n if (registry.basedOn) {\n const base = await loadRegistry(registry.basedOn);\n if (!base) {\n throw new Error(\n `CvcRegistryService: basedOn registry not found: ${registry.basedOn.toString()}`,\n );\n }\n // Locked spec §9.1.2: base versions first, child overrides on top.\n mergedVersions = {\n ...cvcVersionsToRecord(base.cvcVersions),\n ...childVersions,\n };\n }\n\n // Load entries for every pinned `(domain, version)`. We deliberately load\n // sequentially per domain rather than in parallel because consumer apps\n // typically have ≤5 domains pinned per registry — the parallelism win is\n // negligible and the sequential form keeps test fixtures deterministic.\n const pool: ICvcEntry[] = [];\n for (const [domain, version] of Object.entries(mergedVersions)) {\n const domainEntries = await loadEntries(domain, version);\n pool.push(...domainEntries);\n }\n\n const entries = applyEntryOverrides(\n registry.excludedEntries,\n registry.includedEntries,\n pool,\n );\n return { mergedVersions, entries };\n}\n\n// ─── Service class ───────────────────────────────────────────────────────────\n\n/**\n * Build a Mongo filter that pins a registry to a specific scope. `null`\n * scope keys translate to `null` in the filter (matching the on-disk default\n * for unscoped rows) — they do **not** become `$exists: false`. The schema\n * defaults `application` and `agencyId` to `null`, so this matches reality.\n */\nfunction scopeFilter(scope: RegistryScope): {\n application: string | null;\n agencyId: Types.ObjectId | null;\n} {\n return {\n application: scope.application ?? null,\n agencyId: scope.agencyId ?? null,\n };\n}\n\n/**\n * Build the cache key for a resolved registry. Cache keys are stringified\n * `_id`s — every registry has a unique `_id`, so two distinct scopes that\n * happen to share an active version still get distinct cache slots.\n */\nfunction cacheKeyFor(registryId: Types.ObjectId): string {\n return registryId.toString();\n}\n\n/**\n * Service class. See module-level docstring for the high-level contract;\n * each method documents its own scope-fallback / cache / lifecycle behavior.\n */\nexport class CvcRegistryService {\n private readonly registryModel: Model<ICvcRegistry>;\n private readonly entryModel: Model<ICvcEntry>;\n private readonly scopeFallback: boolean;\n\n /**\n * Cached resolved entry set per registry id. The value is the full\n * post-override entry list — domain filtering is done on read so the\n * cache stays domain-agnostic. Cleared on activate/deprecate of any\n * registry that overlaps the cached scope.\n */\n private readonly resolvedCache = new Map<string, ICvcEntry[]>();\n\n /**\n * @param connection - Mongoose connection that owns `cvc_registries` and `cvc_entries`\n * @param options - Optional behavior toggles (see {@link CvcRegistryServiceOptions})\n */\n constructor(connection: Connection, options: CvcRegistryServiceOptions = {}) {\n // The schema-derived `CvcRegistry`/`CvcEntry` types from co-am3.2's\n // `schemas/*.ts` widen to the Schema instance shape (a known limitation\n // of `InferRawDocType<Schema>` without preserved generics). Cast to the\n // canonical `ICvcRegistry`/`ICvcEntry` interfaces defined above —\n // these are the contract every method in this file is written against.\n this.registryModel = cvcRegistryModel.compileModel(\n connection,\n ) as unknown as Model<ICvcRegistry>;\n this.entryModel = cvcEntryModel.compileModel(\n connection,\n ) as unknown as Model<ICvcEntry>;\n this.scopeFallback = options.scopeFallback ?? true;\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Registry lifecycle\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Find the active registry for a scope, walking the fallback chain\n * (agency-specific → app-specific → platform-default) when enabled. Returns\n * `null` if no active registry exists at any level of the chain.\n */\n async getActiveRegistry(\n scope: RegistryScope,\n ): Promise<ICvcRegistry | null> {\n const candidates: RegistryScope[] = [scope];\n\n // Build the fallback ladder. We only widen scope if it actually narrows\n // something — there's no point asking for `{null, null}` twice.\n if (this.scopeFallback) {\n if (scope.agencyId != null && scope.application != null) {\n candidates.push({ application: scope.application, agencyId: null });\n }\n if (scope.application != null) {\n candidates.push({ application: null, agencyId: null });\n }\n }\n\n for (const candidate of candidates) {\n const found = await this.registryModel\n .findOne({ ...scopeFilter(candidate), status: \"active\" })\n .lean<ICvcRegistry>()\n .exec();\n if (found) return found;\n }\n return null;\n }\n\n /**\n * Look up a registry by its `(scope, version)` tuple. The scope must be\n * exact — there is no fallback chain here, since version pins are scope-\n * specific by definition.\n */\n async getRegistry(\n scope: RegistryScope,\n version: string,\n ): Promise<ICvcRegistry | null> {\n return this.registryModel\n .findOne({ ...scopeFilter(scope), version })\n .lean<ICvcRegistry>()\n .exec();\n }\n\n /**\n * List every registry version for an exact scope, regardless of status.\n * Sorted by version so callers get a deterministic ordering for change\n * logs / version pickers. The version field is a semver string, so the\n * sort is lexicographic — good enough for the typical 1.0.0 / 1.1.0 case.\n */\n async listVersions(scope: RegistryScope): Promise<ICvcRegistry[]> {\n return this.registryModel\n .find(scopeFilter(scope))\n .sort({ version: 1 })\n .lean<ICvcRegistry[]>()\n .exec();\n }\n\n /**\n * Promote a draft registry to `active`. Atomically demotes the previous\n * active registry in the same scope to `deprecated` so the\n * one-active-per-scope invariant holds even under concurrent activations\n * (the partial unique index on `cvc_registries` enforces this at the DB\n * layer; we mirror it here for clarity).\n *\n * @throws Error if the target registry doesn't exist or isn't in `draft`\n */\n async activate(registryId: Types.ObjectId): Promise<ICvcRegistry> {\n const target = await this.registryModel\n .findById(registryId)\n .lean<ICvcRegistry>()\n .exec();\n if (!target) {\n throw new Error(\n `CvcRegistryService.activate: registry not found: ${registryId.toString()}`,\n );\n }\n if (target.status !== \"draft\") {\n throw new Error(\n `CvcRegistryService.activate: registry ${registryId.toString()} is '${target.status}', expected 'draft'`,\n );\n }\n\n const now = new Date();\n\n // Demote the existing active registry in this scope (if any). Done\n // before promoting the new one so the partial unique index never sees\n // two active rows in the same scope, even mid-transaction.\n await this.registryModel\n .updateOne(\n {\n application: target.application ?? null,\n agencyId: target.agencyId ?? null,\n status: \"active\",\n },\n { $set: { status: \"deprecated\", dateDeactivated: now } },\n )\n .exec();\n\n const activated = await this.registryModel\n .findByIdAndUpdate(\n registryId,\n { $set: { status: \"active\", dateActivated: now } },\n { new: true },\n )\n .lean<ICvcRegistry>()\n .exec();\n if (!activated) {\n throw new Error(\n `CvcRegistryService.activate: registry vanished mid-update: ${registryId.toString()}`,\n );\n }\n\n // Cache invariants change on every activation: the previously active\n // registry's resolution is still correct for its id, but consumers\n // asking for \"active in scope X\" will now get a new id. Drop the entire\n // cache rather than reasoning about which entries overlap.\n this.resolvedCache.clear();\n return activated;\n }\n\n /**\n * Demote an active registry to `deprecated`. Idempotent only in the sense\n * that calling it twice on the same registry will fail the second time —\n * we don't allow re-deprecating something that's already deprecated, so\n * the lifecycle stays a strict state machine.\n *\n * @throws Error if the target registry doesn't exist or isn't `active`\n */\n async deprecate(registryId: Types.ObjectId): Promise<ICvcRegistry> {\n const target = await this.registryModel\n .findById(registryId)\n .lean<ICvcRegistry>()\n .exec();\n if (!target) {\n throw new Error(\n `CvcRegistryService.deprecate: registry not found: ${registryId.toString()}`,\n );\n }\n if (target.status !== \"active\") {\n throw new Error(\n `CvcRegistryService.deprecate: registry ${registryId.toString()} is '${target.status}', expected 'active'`,\n );\n }\n\n const updated = await this.registryModel\n .findByIdAndUpdate(\n registryId,\n { $set: { status: \"deprecated\", dateDeactivated: new Date() } },\n { new: true },\n )\n .lean<ICvcRegistry>()\n .exec();\n if (!updated) {\n throw new Error(\n `CvcRegistryService.deprecate: registry vanished mid-update: ${registryId.toString()}`,\n );\n }\n\n this.resolvedCache.clear();\n return updated;\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Entry resolution (core — all convenience methods funnel through here)\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Resolve a registry into its effective entry list, applying inheritance\n * and overrides. Results are memoised by registry id; the cache is\n * invalidated on `activate()` / `deprecate()`.\n */\n async resolveEntries(registryId: Types.ObjectId): Promise<ICvcEntry[]> {\n const cacheKey = cacheKeyFor(registryId);\n const cached = this.resolvedCache.get(cacheKey);\n if (cached) return cached;\n\n const registry = await this.registryModel\n .findById(registryId)\n .lean<ICvcRegistry>()\n .exec();\n if (!registry) {\n throw new Error(\n `CvcRegistryService.resolveEntries: registry not found: ${registryId.toString()}`,\n );\n }\n\n const { entries } = await resolveRegistryWithInheritance(\n registry,\n (id) =>\n this.registryModel\n .findById(id)\n .lean<ICvcRegistry>()\n .exec(),\n (domain, version) =>\n this.entryModel\n .find({ domain, version })\n .lean<ICvcEntry[]>()\n .exec(),\n );\n\n this.resolvedCache.set(cacheKey, entries);\n return entries;\n }\n\n /**\n * Same as {@link resolveEntries} but filtered to a single CVC domain.\n * Filtering is done on the cached set so repeated calls for different\n * domains share the same underlying load.\n */\n async resolveEntriesForDomain(\n registryId: Types.ObjectId,\n domain: string,\n ): Promise<ICvcEntry[]> {\n const all = await this.resolveEntries(registryId);\n return all.filter((entry) => entry.domain === domain);\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Entry lookups (convenience — resolve through the active registry)\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Find an entry by its 7-segment positional code within the active\n * registry for `scope`. Returns `null` if no active registry exists or\n * the code isn't present in the resolved entry set.\n */\n async getEntryByCode(\n scope: RegistryScope,\n code: string,\n ): Promise<ICvcEntry | null> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return null;\n const entries = await this.resolveEntries(registry._id);\n return entries.find((entry) => entry.code === code) ?? null;\n }\n\n /**\n * Find an entry by its stable machine key within a specific domain in the\n * active registry. Keys are unique per `(domain, version)` so the lookup\n * always returns at most one entry.\n */\n async getEntryByKey(\n scope: RegistryScope,\n domain: string,\n key: string,\n ): Promise<ICvcEntry | null> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return null;\n const entries = await this.resolveEntriesForDomain(registry._id, domain);\n return entries.find((entry) => entry.key === key) ?? null;\n }\n\n /**\n * Get every resolved entry for a given domain in the active registry.\n */\n async getEntries(\n scope: RegistryScope,\n domain: string,\n ): Promise<ICvcEntry[]> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return [];\n return this.resolveEntriesForDomain(registry._id, domain);\n }\n\n /**\n * Get only the selectable (leaf) entries for a domain — useful for form\n * dropdowns where structural grouping rows must be hidden.\n */\n async getSelectableEntries(\n scope: RegistryScope,\n domain: string,\n ): Promise<ICvcEntry[]> {\n const entries = await this.getEntries(scope, domain);\n return entries.filter((entry) => entry.selectable);\n }\n\n /**\n * Get the direct children of a parent code within the active registry.\n * Returns `[]` for leaves and for codes not present in the resolved set.\n */\n async getChildren(\n scope: RegistryScope,\n code: string,\n ): Promise<ICvcEntry[]> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return [];\n const entries = await this.resolveEntries(registry._id);\n return entries.filter((entry) => entry.parentCode === code);\n }\n\n /**\n * Walk the parent chain from `code` up to the tree root, returning the\n * ancestors in **root → entry** order (the entry itself is not included).\n * Stops early if a parent code references an entry that isn't present in\n * the resolved set — that's a corrupt-tree signal but we'd rather return\n * a partial chain than throw inside a UI breadcrumb call.\n */\n async getAncestors(\n scope: RegistryScope,\n code: string,\n ): Promise<ICvcEntry[]> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return [];\n const entries = await this.resolveEntries(registry._id);\n const byCode = new Map(entries.map((entry) => [entry.code, entry]));\n\n const chain: ICvcEntry[] = [];\n let current = byCode.get(code);\n // Cycle guard: if a corrupt tree contains a loop, stop after we've seen\n // every entry once. This bounds the walk to O(N) in the worst case.\n const seen = new Set<string>();\n while (current?.parentCode && !seen.has(current.parentCode)) {\n seen.add(current.parentCode);\n const parent = byCode.get(current.parentCode);\n if (!parent) break;\n chain.push(parent);\n current = parent;\n }\n return chain.reverse();\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Test seam: cache introspection\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Test-only accessor for the resolved-entry cache. Exposed so service\n * tests can assert that `activate()` / `deprecate()` actually flush the\n * cache, and so consumers diagnosing stale-data bugs can dump the live\n * keyset. Not part of the locked spec API surface — treat as internal.\n */\n get __cacheKeysForTests(): readonly string[] {\n return [...this.resolvedCache.keys()];\n }\n}\n","/**\n * @htilabs/platform-common-models — Form Schema\n *\n * Versioned form definitions for screening, intake, and assessment forms.\n * Forms contain ordered references to sections with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Form Section Reference Sub-Schema ───────────────────────────────────────\n\nexport const formSectionRefSchema = new Schema(\n {\n sectionId: { type: String, required: true },\n sectionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n isStep: { type: Boolean, default: false },\n wizardStep: { type: Number },\n label: { type: String },\n presetsType: { type: String },\n },\n { _id: false },\n);\n\nexport type FormSectionRef = InferRawDocType<typeof formSectionRefSchema>;\n\n// ─── Form Schema ─────────────────────────────────────────────────────────────\n\nexport const formSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Form info\n name: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n },\n formType: {\n type: String,\n index: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Ordered sections\n sections: {\n type: [formSectionRefSchema],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n};\n\nexport const formSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"forms\",\n};\n\n/**\n * Build the Form schema.\n * @returns Mongoose Schema for Form\n */\nexport function buildFormSchema(): Schema {\n const schema = new Schema(formSchemaDefinition, formSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _formSchema = buildFormSchema();\n\nexport type Form = InferRawDocType<typeof _formSchema>;\n","/**\n * @htilabs/platform-common-models — Section Schema\n *\n * Logical grouping of questions within a form.\n * Sections contain ordered references to questions with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Section Question Reference Sub-Schema ───────────────────────────────────\n\nexport const sectionQuestionRefSchema = new Schema(\n {\n questionId: { type: String, required: true },\n questionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type SectionQuestionRef = InferRawDocType<\n typeof sectionQuestionRefSchema\n>;\n\n// ─── Guidance Sub-Schema ─────────────────────────────────────────────────────\n\nexport const guidanceSchema = new Schema(\n {\n type: {\n type: String,\n required: true,\n enum: [\"tip\", \"warning\", \"prompt\"],\n },\n text: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type Guidance = InferRawDocType<typeof guidanceSchema>;\n\n// ─── Section Schema ──────────────────────────────────────────────────────────\n\nexport const sectionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Section info\n name: {\n type: String,\n required: true,\n },\n directions: {\n type: String,\n },\n\n // Typed guidance items\n guidance: {\n type: [guidanceSchema],\n default: [],\n },\n\n // Ordered question refs\n questions: {\n type: [sectionQuestionRefSchema],\n default: [],\n },\n\n // Template visibility\n templateScope: {\n type: [String],\n default: undefined,\n },\n collapsible: {\n type: Boolean,\n default: false,\n },\n defaultCollapsed: {\n type: Boolean,\n default: false,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n rephrasing: {\n type: String,\n },\n script: {\n type: String,\n },\n};\n\nexport const sectionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"sections\",\n};\n\n/**\n * Build the Section schema.\n * @returns Mongoose Schema for Section\n */\nexport function buildSectionSchema(): Schema {\n const schema = new Schema(sectionSchemaDefinition, sectionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _sectionSchema = buildSectionSchema();\n\nexport type Section = InferRawDocType<typeof _sectionSchema>;\n","/**\n * @htilabs/platform-common-models — Question Schema\n *\n * Individual form fields with validation, choices, visibility rules, and scoring.\n * Questions support static and dynamic choices, conditional visibility, and IC code mapping.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Choice Sub-Schema ───────────────────────────────────────────────────────\n\nexport const choiceSchema = new Schema(\n {\n val: { type: Schema.Types.Mixed, required: true },\n text: { type: String, required: true },\n tip: { type: String },\n trigger: { type: [String] },\n },\n { _id: false },\n);\n\nexport type Choice = InferRawDocType<typeof choiceSchema>;\n\n// ─── Visibility Rule Sub-Schema ──────────────────────────────────────────────\n\nexport const visibilityRuleSchema = new Schema(\n {\n dependsOn: { type: String, required: true },\n condition: {\n type: String,\n required: true,\n enum: [\"equals\", \"not_equals\", \"any_of\", \"in_range\"],\n },\n values: { type: [Schema.Types.Mixed], required: true },\n source: {\n type: String,\n enum: [\"form\", \"session\"],\n default: \"form\",\n },\n },\n { _id: false },\n);\n\nexport type VisibilityRule = InferRawDocType<typeof visibilityRuleSchema>;\n\n// ─── Layout Sub-Schema ───────────────────────────────────────────────────────\n\nexport const layoutSchema = new Schema(\n {\n columns: { type: Number, default: 1, min: 1, max: 4 },\n collapsible: { type: Boolean, default: false },\n groupKey: { type: String },\n },\n { _id: false },\n);\n\nexport type Layout = InferRawDocType<typeof layoutSchema>;\n\n// ─── Question Schema ─────────────────────────────────────────────────────────\n\nexport const questionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Question definition\n index: {\n type: Number,\n required: true,\n },\n text: {\n type: String,\n required: true,\n },\n format: {\n type: String,\n required: true,\n },\n sectionId: {\n type: String,\n required: true,\n },\n required: {\n type: Boolean,\n default: false,\n },\n allowMultiple: {\n type: Boolean,\n default: false,\n },\n\n // Nesting\n isNested: {\n type: Boolean,\n default: false,\n },\n nested: {\n type: [String],\n default: [],\n },\n\n // Trigger logic\n isTriggered: {\n type: Boolean,\n default: false,\n },\n triggersWhenAnswered: {\n type: [String],\n default: [],\n },\n\n // Display\n header: { type: String },\n directions: { type: String },\n tip: { type: String },\n\n // Dynamic choices\n hasDynamicChoices: {\n type: Boolean,\n default: false,\n },\n dynamicChoiceSet: { type: String },\n group: { type: String },\n\n // Static choices\n choices: {\n type: [choiceSchema],\n default: [],\n },\n\n // UI rendering hints\n componentProps: {\n type: Schema.Types.Mixed,\n },\n\n // Autofill\n autofillRules: {\n type: Schema.Types.Mixed,\n default: [],\n },\n\n // Classification\n formType: {\n type: [String],\n enum: [\"screening\", \"intake\", \"assessment\", \"demographics\"],\n default: [],\n },\n icCode: {\n type: String,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // Entity mapping (dual-write bridge)\n targetEntity: {\n type: String,\n enum: [\n \"caseSession\",\n \"protectedPerson\",\n \"perpetratorPerson\",\n \"personnelPerson\",\n \"caseRecord\",\n \"serviceInstance\",\n ],\n },\n targetField: {\n type: String,\n },\n\n // Conditional visibility\n visibilityRule: {\n type: visibilityRuleSchema,\n },\n\n // Layout hints\n layout: {\n type: layoutSchema,\n },\n microcopy: {\n type: String,\n },\n sensitivity: {\n type: String,\n enum: [\"standard\", \"sensitive\", \"highly_sensitive\"],\n },\n\n // Scoring group\n scoringGroup: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n groups: {\n type: [String],\n default: undefined,\n },\n rephrasingSelector: {\n type: Schema.Types.Mixed,\n },\n textSelector: {\n type: Schema.Types.Mixed,\n },\n tipSelector: {\n type: Schema.Types.Mixed,\n },\n sortChoices: {\n type: Boolean,\n },\n isAllRequired: {\n type: Boolean,\n },\n itemLabel: {\n type: String,\n },\n prompts: {\n type: [String],\n default: undefined,\n },\n rephrasing: {\n type: String,\n },\n dynamicChoiceTrigger: {\n type: String,\n },\n};\n\nexport const questionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"questions\",\n};\n\n/**\n * Build the Question schema.\n * @returns Mongoose Schema for Question\n */\nexport function buildQuestionSchema(): Schema {\n const schema = new Schema(questionSchemaDefinition, questionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n // Lookup by section + order\n schema.index({ sectionId: 1, index: 1 });\n\n // IC code lookup (sparse — many questions won't have an IC code)\n schema.index({ icCode: 1 }, { sparse: true });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _questionSchema = buildQuestionSchema();\n\nexport type Question = InferRawDocType<typeof _questionSchema>;\n","/**\n * @htilabs/platform-common-models — Scoring Rule Schema\n *\n * Evaluation rules for screening and assessment instruments.\n * Defines conditions to evaluate, score thresholds, and risk level recommendations.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Scoring Condition Sub-Schema ────────────────────────────────────────────\n\nexport const scoringConditionSchema = new Schema(\n {\n questionKey: { type: String, required: true },\n operator: {\n type: String,\n required: true,\n enum: [\"eq\", \"ne\", \"in\", \"not_in\", \"gt\", \"gte\", \"lt\", \"lte\"],\n },\n value: { type: Schema.Types.Mixed, required: true },\n weight: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringCondition = InferRawDocType<typeof scoringConditionSchema>;\n\n// ─── Scoring Threshold Sub-Schema ────────────────────────────────────────────\n\nexport const scoringThresholdSchema = new Schema(\n {\n minScore: { type: Number, required: true },\n maxScore: { type: Number, required: true },\n riskLevel: { type: String, required: true },\n label: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringThreshold = InferRawDocType<typeof scoringThresholdSchema>;\n\n// ─── Scoring Recommendation Sub-Schema ───────────────────────────────────────\n\nexport const scoringRecommendationSchema = new Schema(\n {\n riskLevel: { type: String, required: true },\n action: { type: String, required: true },\n description: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringRecommendation = InferRawDocType<\n typeof scoringRecommendationSchema\n>;\n\n// ─── Scoring Rule Schema ─────────────────────────────────────────────────────\n\nexport const scoringRuleSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Reference to Form (cross-db string, not ObjectId)\n formId: {\n type: String,\n required: true,\n },\n formVersion: {\n type: String,\n required: true,\n },\n\n // Rule info\n name: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n effectiveDate: {\n type: Date,\n },\n deprecatedDate: {\n type: Date,\n },\n replacedBy: {\n type: String,\n },\n\n // Scoring logic\n conditions: {\n type: [scoringConditionSchema],\n default: [],\n },\n thresholds: {\n type: [scoringThresholdSchema],\n default: [],\n },\n recommendations: {\n type: [scoringRecommendationSchema],\n default: [],\n },\n};\n\nexport const scoringRuleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"scoringrules\",\n};\n\n/**\n * Build the ScoringRule schema.\n * @returns Mongoose Schema for ScoringRule\n */\nexport function buildScoringRuleSchema(): Schema {\n const schema = new Schema(\n scoringRuleSchemaDefinition,\n scoringRuleSchemaOptions,\n );\n\n // Compound unique: one rule name per form version\n schema.index(\n { formId: 1, formVersion: 1, version: 1, name: 1 },\n { unique: true },\n );\n\n // Lookup active rules for a form\n schema.index({ formId: 1, formVersion: 1, status: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _scoringRuleSchema = buildScoringRuleSchema();\n\nexport type ScoringRule = InferRawDocType<typeof _scoringRuleSchema>;\n","/**\n * @htilabs/platform-common-models — Platform Function Schema\n *\n * Mongoose schema for the `platformFunctions` collection.\n * Each document represents a discrete action that can be performed\n * within the platform, with tool scope and admin/user relevance flags.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\nimport {\n PLATFORM_TOOL_VALUES,\n FUNCTION_STATUS_VALUES,\n} from \"../constants/platform-auth.js\";\n\n// ─── Schema Definition ──────────────────────────────────────────────\n\nexport const platformFunctionSchemaDefinition = {\n code: {\n type: String,\n required: true,\n },\n label: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n default: \"\",\n },\n category: {\n type: String,\n default: \"\",\n },\n tools: {\n type: [String],\n enum: [...PLATFORM_TOOL_VALUES],\n default: [],\n },\n isAdminRelevant: {\n type: Boolean,\n default: false,\n },\n isUserRelevant: {\n type: Boolean,\n default: false,\n },\n isHtiOnly: {\n type: Boolean,\n default: false,\n },\n status: {\n type: String,\n enum: [...FUNCTION_STATUS_VALUES],\n default: \"Not started\",\n },\n sortOrder: {\n type: Number,\n default: 0,\n },\n};\n\nexport const platformFunctionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"platformFunctions\",\n};\n\n// ─── Schema Builder ─────────────────────────────────────────────────\n\n/**\n * Build the PlatformFunction schema.\n * @returns Mongoose Schema for PlatformFunction\n */\nexport function buildPlatformFunctionSchema(): Schema {\n const schema = new Schema(\n platformFunctionSchemaDefinition,\n platformFunctionSchemaOptions,\n );\n\n // Unique index on function code\n schema.index({ code: 1 }, { unique: true });\n\n // Lookup indexes\n schema.index({ tools: 1 });\n schema.index({ category: 1 });\n schema.index({ sortOrder: 1 });\n\n return schema;\n}\n\n// ─── Type Inference ─────────────────────────────────────────────────\n\nconst _platformFunctionSchema = buildPlatformFunctionSchema();\nexport type PlatformFunction = InferRawDocType<typeof _platformFunctionSchema>;\n","/**\n * @htilabs/platform-common-models — Platform Authorization Constants\n *\n * Enums and labels for the platform role/function permission model.\n * Includes permission states, share view levels, tool codes, role levels,\n * and function implementation statuses.\n *\n * Source: PLATFORM_AUTH_SPEC.md Sections 5 + 6\n */\n\n// ─── Permission State (4-state role→function mapping) ──────────────\n\nexport const PERMISSION_STATE = {\n /** Role can always perform this function (mandatory, cannot disable). */\n ALWAYS: \"ALWAYS\",\n /** Default On — user can opt off. */\n PREF_YES: \"PREF_YES\",\n /** Default Off — user can opt in. */\n PREF_NO: \"PREF_NO\",\n /** Role is explicitly barred from this function. */\n NEVER: \"NEVER\",\n} as const;\n\nexport type PermissionStateValue =\n (typeof PERMISSION_STATE)[keyof typeof PERMISSION_STATE];\n\nexport const PERMISSION_STATE_VALUES = [\n PERMISSION_STATE.ALWAYS,\n PERMISSION_STATE.PREF_YES,\n PERMISSION_STATE.PREF_NO,\n PERMISSION_STATE.NEVER,\n] as const;\n\nexport const PERMISSION_STATE_LABELS: Record<PermissionStateValue, string> = {\n [PERMISSION_STATE.ALWAYS]: \"Always\",\n [PERMISSION_STATE.PREF_YES]: \"Default On\",\n [PERMISSION_STATE.PREF_NO]: \"Default Off\",\n [PERMISSION_STATE.NEVER]: \"Never\",\n};\n\n/** UI display metadata for permission states (colors, icons). */\nexport const PERMISSION_STATE_DISPLAY: Record<\n PermissionStateValue,\n { label: string; color: string; bgColor: string; icon: string }\n> = {\n [PERMISSION_STATE.ALWAYS]: {\n label: \"Always\",\n color: \"#2e7d32\",\n bgColor: \"#e8f5e9\",\n icon: \"\\u{1F512}\",\n },\n [PERMISSION_STATE.PREF_YES]: {\n label: \"Default On\",\n color: \"#1565c0\",\n bgColor: \"#e3f2fd\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.PREF_NO]: {\n label: \"Default Off\",\n color: \"#e65100\",\n bgColor: \"#fff3e0\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.NEVER]: {\n label: \"Never\",\n color: \"#c62828\",\n bgColor: \"#ffebee\",\n icon: \"\\u{1F512}\",\n },\n};\n\n// ─── Share View (data visibility for shared records) ───────────────\n\nexport const SHARE_VIEW = {\n /** System metadata only (partial access). */\n SYS_INFO: \"sys_info\",\n /** Full case/record content. */\n ALL: \"all\",\n /** No data access. */\n NONE: \"none\",\n} as const;\n\nexport type ShareViewValue = (typeof SHARE_VIEW)[keyof typeof SHARE_VIEW];\n\nexport const SHARE_VIEW_VALUES = [\n SHARE_VIEW.SYS_INFO,\n SHARE_VIEW.ALL,\n SHARE_VIEW.NONE,\n] as const;\n\nexport const SHARE_VIEW_LABELS: Record<ShareViewValue, string> = {\n [SHARE_VIEW.SYS_INFO]: \"System Info Only\",\n [SHARE_VIEW.ALL]: \"Full Content\",\n [SHARE_VIEW.NONE]: \"No Data Access\",\n};\n\n// ─── Platform Tool Codes ───────────────────────────────────────────\n\nexport const PLATFORM_TOOL = {\n PAVE: \"PAVE\",\n ECHO: \"ECHO\",\n LEADS: \"LEADS\",\n THREAD: \"THREAD\",\n TRAIL: \"TRAIL\",\n PLATFORM: \"PLATFORM\",\n} as const;\n\nexport type PlatformToolValue =\n (typeof PLATFORM_TOOL)[keyof typeof PLATFORM_TOOL];\n\nexport const PLATFORM_TOOL_VALUES = [\n PLATFORM_TOOL.PAVE,\n PLATFORM_TOOL.ECHO,\n PLATFORM_TOOL.LEADS,\n PLATFORM_TOOL.THREAD,\n PLATFORM_TOOL.TRAIL,\n PLATFORM_TOOL.PLATFORM,\n] as const;\n\nexport const PLATFORM_TOOL_LABELS: Record<PlatformToolValue, string> = {\n [PLATFORM_TOOL.PAVE]: \"PAVE\",\n [PLATFORM_TOOL.ECHO]: \"Echo\",\n [PLATFORM_TOOL.LEADS]: \"LEADS\",\n [PLATFORM_TOOL.THREAD]: \"Thread\",\n [PLATFORM_TOOL.TRAIL]: \"Trail\",\n [PLATFORM_TOOL.PLATFORM]: \"Platform\",\n};\n\n// ─── Role Level (hierarchy tiers) ──────────────────────────────────\n\nexport const ROLE_LEVEL = {\n /** User-facing roles (staff, volunteers, practitioners). */\n OPERATIONAL: \"operational\",\n /** Agency-level admin roles. */\n AGENCY: \"agency\",\n /** Team-level admin roles. */\n TEAM: \"team\",\n /** HTI-wide platform admin. */\n PLATFORM: \"platform\",\n /** External governance/oversight roles. */\n OVERSIGHT: \"oversight\",\n} as const;\n\nexport type RoleLevelValue = (typeof ROLE_LEVEL)[keyof typeof ROLE_LEVEL];\n\nexport const ROLE_LEVEL_VALUES = [\n ROLE_LEVEL.OPERATIONAL,\n ROLE_LEVEL.AGENCY,\n ROLE_LEVEL.TEAM,\n ROLE_LEVEL.PLATFORM,\n ROLE_LEVEL.OVERSIGHT,\n] as const;\n\nexport const ROLE_LEVEL_LABELS: Record<RoleLevelValue, string> = {\n [ROLE_LEVEL.OPERATIONAL]: \"Operational\",\n [ROLE_LEVEL.AGENCY]: \"Agency\",\n [ROLE_LEVEL.TEAM]: \"Team\",\n [ROLE_LEVEL.PLATFORM]: \"Platform\",\n [ROLE_LEVEL.OVERSIGHT]: \"Oversight\",\n};\n\n// ─── Function Implementation Status ────────────────────────────────\n\nexport const FUNCTION_STATUS = {\n NOT_STARTED: \"Not started\",\n DEFINED_NEW: \"Defined; new function\",\n DEFINED_EXISTING: \"Defined; existing PAVE function\",\n FUNCTIONAL: \"Functional on all apps\",\n FUTURE: \"Future function (not v1)\",\n} as const;\n\nexport type FunctionStatusValue =\n (typeof FUNCTION_STATUS)[keyof typeof FUNCTION_STATUS];\n\nexport const FUNCTION_STATUS_VALUES = [\n FUNCTION_STATUS.NOT_STARTED,\n FUNCTION_STATUS.DEFINED_NEW,\n FUNCTION_STATUS.DEFINED_EXISTING,\n FUNCTION_STATUS.FUNCTIONAL,\n FUNCTION_STATUS.FUTURE,\n] as const;\n\nexport const FUNCTION_STATUS_LABELS: Record<FunctionStatusValue, string> = {\n [FUNCTION_STATUS.NOT_STARTED]: \"Not Started\",\n [FUNCTION_STATUS.DEFINED_NEW]: \"Defined (New)\",\n [FUNCTION_STATUS.DEFINED_EXISTING]: \"Defined (Existing PAVE)\",\n [FUNCTION_STATUS.FUNCTIONAL]: \"Functional\",\n [FUNCTION_STATUS.FUTURE]: \"Future (Not v1)\",\n};\n","/**\n * @htilabs/platform-common-models — Platform Role Schema\n *\n * Mongoose schema for the `platformRoles` collection.\n * Each document represents a role that bundles function permissions,\n * tool scope, and share visibility settings.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\nimport {\n PLATFORM_TOOL_VALUES,\n ROLE_LEVEL_VALUES,\n SHARE_VIEW_VALUES,\n} from \"../constants/platform-auth.js\";\n\n// ─── Schema Definition ──────────────────────────────────────────────\n\nexport const platformRoleSchemaDefinition = {\n code: {\n type: String,\n required: true,\n },\n label: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n default: \"\",\n },\n level: {\n type: String,\n enum: [...ROLE_LEVEL_VALUES],\n required: true,\n },\n tools: {\n type: [String],\n enum: [...PLATFORM_TOOL_VALUES],\n default: [],\n },\n shareView: {\n type: String,\n enum: [...SHARE_VIEW_VALUES, null],\n default: null,\n },\n trainingRequirements: {\n type: String,\n default: null,\n },\n isHtiOnly: {\n type: Boolean,\n default: false,\n },\n /** Dynamic map of functionCode → PermissionStateValue. */\n functions: {\n type: Schema.Types.Mixed,\n default: {},\n },\n sortOrder: {\n type: Number,\n default: 0,\n },\n};\n\nexport const platformRoleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"platformRoles\",\n};\n\n// ─── Schema Builder ─────────────────────────────────────────────────\n\n/**\n * Build the PlatformRole schema.\n * @returns Mongoose Schema for PlatformRole\n */\nexport function buildPlatformRoleSchema(): Schema {\n const schema = new Schema(\n platformRoleSchemaDefinition,\n platformRoleSchemaOptions,\n );\n\n // Unique index on role code\n schema.index({ code: 1 }, { unique: true });\n\n // Lookup indexes\n schema.index({ level: 1 });\n schema.index({ tools: 1 });\n schema.index({ isHtiOnly: 1 });\n\n return schema;\n}\n\n// ─── Type Inference ─────────────────────────────────────────────────\n\nconst _platformRoleSchema = buildPlatformRoleSchema();\nexport type PlatformRole = InferRawDocType<typeof _platformRoleSchema>;\n","/**\n * @htilabs/platform-common-models — CvcRegistry Model\n *\n * Factory for creating the CvcRegistry model bound to a specific connection.\n * Mirrors the buildSchema/compileModel pattern used by the other platform\n * models in this package (see `formModel.ts`, `questionModel.ts`).\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport {\n buildCvcRegistrySchema,\n type CvcRegistry,\n} from \"../schemas/cvcRegistry.js\";\n\nexport type CvcRegistryDoc = HydratedDocument<CvcRegistry>;\n\n/**\n * Build the CvcRegistry schema.\n * @returns Mongoose Schema for CvcRegistry\n */\nexport { buildCvcRegistrySchema as buildSchema };\n\n/**\n * Compile the CvcRegistry model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildCvcRegistrySchema() if not provided)\n * @returns Mongoose Model for CvcRegistry\n */\nexport function compileModel(\n connection: Connection,\n schema = buildCvcRegistrySchema(),\n): Model<CvcRegistry> {\n return connection.models.CvcRegistry as Model<CvcRegistry>\n ?? connection.model<CvcRegistry>(\"CvcRegistry\", schema);\n}\n","/**\n * @htilabs/platform-common-models — CVC Registry Schema\n *\n * A CVC Registry is a configuration bundle that pins specific versions of\n * each Controlled Vocabulary (CVC) domain for a given application/agency\n * scope. Consumers resolve \"which entries should I use right now?\" by\n * looking up the active registry for their scope, then loading the pinned\n * versions from `cvc_entries`.\n *\n * Locked spec reference:\n * §9.1 — Generalized CVC data layer in platform-common-models\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * Scope hierarchy (most specific wins at lookup time):\n * 1. (application, agencyId) — agency-specific override for an app\n * 2. (application, null) — app-wide default\n * 3. (null, null) — platform-wide default\n *\n * Lifecycle: a registry begins in `draft`, transitions to `active` (at most\n * one active per scope), and is eventually `deprecated` when superseded.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── CVC Registry Schema ─────────────────────────────────────────────────────\n\nexport const cvcRegistrySchemaDefinition = {\n // Versioning — semantic version of this registry bundle\n version: {\n type: String,\n required: true,\n match: /^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)?$/,\n },\n\n // Human-readable name (e.g. \"PAVE production registry\")\n name: {\n type: String,\n required: true,\n },\n\n // Scope keys. `null` widens scope: a null `application` means platform-wide;\n // a null `agencyId` means all agencies within `application`.\n application: {\n type: String,\n default: null,\n },\n agencyId: {\n type: Schema.Types.ObjectId,\n default: null,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n dateActivated: {\n type: Date,\n },\n dateDeactivated: {\n type: Date,\n },\n\n // Pinned domain versions: { service_categories: \"1.0.0\", ... }\n // Stored as a Map<string, string> so individual domains can be added or\n // bumped without re-validating the whole document shape.\n cvcVersions: {\n type: Map,\n of: String,\n required: true,\n default: () => new Map(),\n },\n\n // Selective inclusion/exclusion lists. Both contain CVC entry codes\n // (positional 7-segment, format v2: e.g. \"022-002-000-000-000-000-000\").\n // The runtime applies excludes after includes when resolving the effective\n // set.\n excludedEntries: {\n type: [String],\n default: [],\n },\n includedEntries: {\n type: [String],\n default: [],\n },\n\n // Inheritance pointer — when set, this registry inherits cvcVersions /\n // include / exclude lists from its base before applying its own overrides.\n // Indexed below so a base-version bump can find every dependent registry.\n basedOn: {\n type: Schema.Types.ObjectId,\n default: null,\n },\n};\n\nexport const cvcRegistrySchemaOptions = {\n timestamps: true,\n collection: \"cvc_registries\",\n};\n\n/**\n * Build the CvcRegistry schema with its full set of indexes.\n *\n * Indexes:\n * 1. `{ application, agencyId, version }` unique — primary identity. Two\n * registries in the same scope cannot share a version number.\n * 2. `{ application, agencyId, status }` partial — at most one `active`\n * registry per scope (enforced by the `status: \"active\"` partial filter).\n * 3. `{ basedOn }` — fast lookup of dependent registries when a base\n * registry is bumped or deprecated.\n *\n * @returns Mongoose Schema for CvcRegistry\n */\nexport function buildCvcRegistrySchema(): Schema {\n const schema = new Schema(\n cvcRegistrySchemaDefinition,\n cvcRegistrySchemaOptions,\n );\n\n // Primary identity: one (application, agencyId, version) tuple per registry\n schema.index(\n { application: 1, agencyId: 1, version: 1 },\n { unique: true },\n );\n\n // At most one `active` registry per scope. The partial filter ensures the\n // uniqueness constraint only applies to active rows; draft and deprecated\n // rows are unindexed by this index.\n schema.index(\n { application: 1, agencyId: 1, status: 1 },\n {\n unique: true,\n partialFilterExpression: { status: \"active\" },\n },\n );\n\n // Reverse-lookup for inheritance: \"what registries inherit from me?\"\n schema.index({ basedOn: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _cvcRegistrySchema = buildCvcRegistrySchema();\n\nexport type CvcRegistry = InferRawDocType<typeof _cvcRegistrySchema>;\n","/**\n * @htilabs/platform-common-models — CvcEntry Model\n *\n * Factory for creating the CvcEntry model bound to a specific connection.\n * Mirrors the buildSchema/compileModel pattern used by the other platform\n * models in this package (see `formModel.ts`, `questionModel.ts`).\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildCvcEntrySchema, type CvcEntry } from \"../schemas/cvcEntry.js\";\n\nexport type CvcEntryDoc = HydratedDocument<CvcEntry>;\n\n/**\n * Build the CvcEntry schema.\n * @returns Mongoose Schema for CvcEntry\n */\nexport { buildCvcEntrySchema as buildSchema };\n\n/**\n * Compile the CvcEntry model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildCvcEntrySchema() if not provided)\n * @returns Mongoose Model for CvcEntry\n */\nexport function compileModel(\n connection: Connection,\n schema = buildCvcEntrySchema(),\n): Model<CvcEntry> {\n return connection.models.CvcEntry as Model<CvcEntry>\n ?? connection.model<CvcEntry>(\"CvcEntry\", schema);\n}\n","/**\n * @htilabs/platform-common-models — CVC Entry Schema\n *\n * Persistent storage for individual Controlled Vocabulary (CVC) entries.\n * Every entry is keyed by `(domain, version, code)` so that multiple\n * versions of a domain can coexist in the same collection — registries\n * pin which (domain, version) tuples are active for a given scope.\n *\n * Locked spec reference:\n * §9.1.2 — `cvc_entries` collection shape\n * §3 — Positional 7-segment code format\n * §3.2 — Stable machine key format\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * The Zod equivalents in `validation/cvc.ts` enforce the same shapes at the\n * application boundary; the Mongoose constraints below are the persistence\n * layer's defense in depth so that bad inserts fail loudly even if a caller\n * skipped Zod validation.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Shared validators ───────────────────────────────────────────────────────\n\n/**\n * Positional 7-segment CVC code: `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (format v2,\n * 3-digit segments with a Notion-aligned domain prefix). Mirrors\n * `CvcCodeSchema` in `validation/cvc.ts`. See locked spec §3.\n */\nconst CVC_CODE_PATTERN = /^\\d{3}(-\\d{3}){6}$/;\n\n/**\n * Stable machine key for a CVC entry. Mirrors `CvcKeySchema` in\n * `validation/cvc.ts`. See locked spec §3.2.\n */\nconst CVC_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;\n\n// ─── CVC Entry Schema ────────────────────────────────────────────────────────\n\nexport const cvcEntrySchemaDefinition = {\n // Compound identity: (domain, version, code) uniquely identifies an entry.\n // `domain` is the SOT family (e.g. \"service_categories\"); `version` is the\n // semantic version of the SOT JSON file the entry was loaded from.\n domain: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n code: {\n type: String,\n required: true,\n match: CVC_CODE_PATTERN,\n },\n\n // Stable machine key for cross-CVC references (e.g. `relevantMechanisms`\n // in service_categories points at service_mechanisms entries by `key`).\n key: {\n type: String,\n required: true,\n match: CVC_KEY_PATTERN,\n },\n\n // Display fields\n title: {\n type: String,\n required: true,\n },\n\n // `selectable` distinguishes leaf entries (selectable) from structural\n // grouping rows (not selectable). Required because the seed CLI must\n // populate it explicitly — there is no sane default.\n selectable: {\n type: Boolean,\n required: true,\n },\n\n // Tree structure. `parentCode` is `null` for root rows; `childCodes` is\n // empty for leaves. We give `parentCode` a `default: null` (rather than\n // marking it required) because Mongoose's `required` validator rejects\n // `null` outright — the default ensures the field is always present on\n // disk while still allowing the documented `string | null` shape. The\n // `match` validator is skipped by Mongoose when the value is null.\n parentCode: {\n type: String,\n default: null,\n match: CVC_CODE_PATTERN,\n },\n childCodes: {\n type: [String],\n required: true,\n default: [],\n },\n\n // Long-form definition. Same `default: null` treatment as `parentCode`\n // above — every row reaches disk with `definition` set to either a\n // string or an explicit null.\n definition: {\n type: String,\n default: null,\n },\n\n // Domain-specific extension bag. Used for fields that only apply to a\n // particular CVC family — e.g. `relevantMechanisms` on service_categories\n // entries (a cross-CVC reference into service_mechanisms by key).\n meta: {\n type: Schema.Types.Mixed,\n },\n};\n\nexport const cvcEntrySchemaOptions = {\n timestamps: true,\n collection: \"cvc_entities\",\n // `parentCode` defaults to null but Mongoose strips required-with-default\n // null assignments unless we keep minimize off.\n minimize: false,\n};\n\n/**\n * Build the CvcEntry schema with its full set of indexes.\n *\n * Indexes:\n * 1. `{ domain, version, code }` unique — primary identity. The seed CLI\n * uses this for upsert keys.\n * 2. `{ domain, version, key }` unique — secondary lookup target for\n * cross-CVC references like `relevantMechanisms`.\n * 3. `{ domain, version, parentCode }` non-unique — supports tree walks\n * (\"give me the children of this code at this version\").\n *\n * @returns Mongoose Schema for CvcEntry\n */\nexport function buildCvcEntrySchema(): Schema {\n const schema = new Schema(cvcEntrySchemaDefinition, cvcEntrySchemaOptions);\n\n // Primary identity\n schema.index(\n { domain: 1, version: 1, code: 1 },\n { unique: true },\n );\n\n // Secondary lookup for cross-CVC references by stable key\n schema.index(\n { domain: 1, version: 1, key: 1 },\n { unique: true },\n );\n\n // Tree walks\n schema.index({ domain: 1, version: 1, parentCode: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _cvcEntr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UAAM,SAAS,IAAI,IAAI,QAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,MAAM,KAAK,CAAC,CAAC;AAElE,UAAM,QAAqB,CAAC;AAC5B,QAAI,UAAU,OAAO,IAAI,IAAI;AAG7B,UAAM,OAAO,oBAAI,IAAY;AAC7B,WAAO,SAAS,cAAc,CAAC,KAAK,IAAI,QAAQ,UAAU,GAAG;AAC3D,WAAK,IAAI,QAAQ,UAAU;AAC3B,YAAM,SAAS,OAAO,IAAI,QAAQ,UAAU;AAC5C,UAAI,CAAC,OAAQ;AACb,YAAM,KAAK,MAAM;AACjB,gBAAU;AAAA,IACZ;AACA,WAAO,MAAM,QAAQ;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,IAAI,sBAAyC;AAC3C,WAAO,CAAC,GAAG,KAAK,cAAc,KAAK,CAAC;AAAA,EACtC;AACF;","names":["import_mongoose","import_mongoose","import_mongoose","import_mongoose","import_mongoose","import_mongoose","import_mongoose","compileModel","import_mongoose","compileModel"]}
|
|
1
|
+
{"version":3,"sources":["../../src/services/index.ts","../../src/services/cvcRegistryService.ts","../../src/schemas/form.ts","../../src/schemas/section.ts","../../src/schemas/question.ts","../../src/schemas/scoring-rule.ts","../../src/schemas/platform-function.ts","../../src/constants/platform-auth.ts","../../src/schemas/platform-role.ts","../../src/models/cvcRegistryModel.ts","../../src/schemas/cvcRegistry.ts","../../src/models/cvcEntryModel.ts","../../src/schemas/cvcEntry.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Services\n *\n * Runtime services that operate on the platform models. Currently houses\n * the CVC registry runtime API; future services (form resolution, etc.)\n * should follow the same export pattern.\n */\n\nexport {\n CvcRegistryService,\n cascadeExclusions,\n applyEntryOverrides,\n resolveRegistryWithInheritance,\n cvcVersionsToRecord,\n type RegistryScope,\n type CvcRegistryServiceOptions,\n type ICvcRegistry,\n type ICvcEntry,\n type RegistryLoader,\n type EntryLoader,\n} from \"./cvcRegistryService.js\";\n","/**\n * @htilabs/platform-common-models — CvcRegistryService\n *\n * Runtime API for resolving Controlled Vocabulary (CVC) data through a\n * registry. The service is the canonical entry point used by Thread, PAVE,\n * and any other consumer that needs \"give me the entries that are live in\n * scope X right now\". It hides three concerns from callers:\n *\n * 1. **Scope resolution.** Callers ask in terms of `{application, agencyId}`;\n * the service walks the agency-specific → app-specific → platform-default\n * fallback chain to find the active registry.\n * 2. **Inheritance.** A registry may be `basedOn` another registry. The\n * service merges the parent's pinned `cvcVersions` under the child's,\n * then applies the child's own `excludedEntries` / `includedEntries`\n * overrides on top of the merged entry pool.\n * 3. **Caching.** Resolved entry sets are memoised per active registry, and\n * flushed on `activate()` / `deprecate()` so that the next read picks\n * up the new pin.\n *\n * Locked spec reference:\n * §9.1.1 — Entry resolution logic (default / blacklist / whitelist modes)\n * §9.1.2 — `basedOn` inheritance resolution\n * §9.6 — Service API surface\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * The pure helpers (`cascadeExclusions`, `applyEntryOverrides`,\n * `resolveRegistryWithInheritance`) are exported alongside the class so\n * they can be unit-tested without a Mongoose connection.\n */\n\nimport { Types } from \"mongoose\";\nimport type { Connection, Model } from \"mongoose\";\n\nimport { cvcRegistryModel, cvcEntryModel } from \"../models/index.js\";\n\n// ─── Public types ────────────────────────────────────────────────────────────\n\n/**\n * Plain document shape for a `cvc_entries` row. Mirrors the Mongoose schema\n * in `schemas/cvcEntry.ts` (co-am3.2) and the locked spec §9.1.2 interface.\n *\n * Defined locally rather than imported because the schema-derived\n * `InferRawDocType<typeof schema>` types in `schemas/cvcEntry.ts` widen to\n * the Schema instance type — they're not usable as document shapes. This\n * interface is the canonical document contract for the service layer.\n */\nexport interface ICvcEntry {\n domain: string;\n version: string;\n code: string;\n key: string;\n title: string;\n selectable: boolean;\n parentCode: string | null;\n childCodes: string[];\n definition: string | null;\n meta?: Record<string, unknown> | null;\n createdAt?: Date;\n updatedAt?: Date;\n}\n\n/**\n * Plain document shape for a `cvc_registries` row. Mirrors the Mongoose\n * schema in `schemas/cvcRegistry.ts` (co-am3.2) and the locked spec §9.1.1\n * interface. See {@link ICvcEntry} for why this is defined locally.\n *\n * `cvcVersions` is typed as either a `Map` (raw mongoose hydrated doc) or\n * a plain object (from `.lean()` / `.toObject()`). The pure helpers\n * normalise both forms via {@link cvcVersionsToRecord}.\n */\nexport interface ICvcRegistry {\n _id: Types.ObjectId;\n version: string;\n name: string;\n application: string | null;\n agencyId: Types.ObjectId | null;\n status: \"draft\" | \"active\" | \"deprecated\";\n dateActivated?: Date | null;\n dateDeactivated?: Date | null;\n cvcVersions: Map<string, string> | Record<string, string>;\n excludedEntries: string[];\n includedEntries: string[];\n basedOn: Types.ObjectId | null;\n createdAt?: Date;\n updatedAt?: Date;\n}\n\n/**\n * Lookup scope for convenience methods. `null`/`undefined` widens the scope:\n * a missing `application` matches the platform-default registry; a missing\n * `agencyId` matches the application-wide registry.\n *\n * Locked spec §9.6 — scope hierarchy.\n */\nexport interface RegistryScope {\n application?: string | null;\n agencyId?: Types.ObjectId | null;\n}\n\n/**\n * Options accepted by the service constructor. Kept as a single object so\n * future toggles (telemetry, custom cache, etc.) can be added without\n * breaking the call site.\n */\nexport interface CvcRegistryServiceOptions {\n /**\n * When `true` (default), `getActiveRegistry` walks the\n * agency → application → platform fallback chain. When `false`, only the\n * exact requested scope is consulted.\n */\n scopeFallback?: boolean;\n}\n\n\n// ─── Pure helpers (exported for unit tests) ──────────────────────────────────\n\n/**\n * Convert a Mongoose `Map<string, string>` (or a plain object that came from\n * `.toObject()`) into a `Record<string, string>`. The Mongoose schema stores\n * `cvcVersions` as a `Map`, but the resolution logic in the locked spec is\n * written against `Object.entries(...)` — this normaliser bridges the gap\n * once at the entry to the pure layer.\n *\n * @param versions - Either a Map (raw mongoose doc) or a plain record\n * @returns A plain object whose keys are CVC domains and values are versions\n */\nexport function cvcVersionsToRecord(\n versions: Map<string, string> | Record<string, string> | undefined | null,\n): Record<string, string> {\n if (!versions) return {};\n if (versions instanceof Map) {\n return Object.fromEntries(versions.entries());\n }\n return { ...versions };\n}\n\n/**\n * Compute the cascading-exclusion set for a CVC entry pool.\n *\n * Cascading exclusion (locked spec §9.1.1) treats the entry tree as a DAG of\n * `parentCode → code` edges. Excluding a node implicitly excludes every\n * descendant reachable from it. The result set always contains the original\n * `excludedCodes` plus every transitively-reachable child.\n *\n * Implemented as breadth-first walk over a parent → children index built\n * from the entry pool. Time/space complexity is `O(N)` in the entry count.\n *\n * @param excludedCodes - Codes the registry explicitly excludes\n * @param entries - The entry pool to cascade through\n * @returns Set containing every excluded code plus every descendant\n */\nexport function cascadeExclusions(\n excludedCodes: ReadonlySet<string>,\n entries: readonly ICvcEntry[],\n): Set<string> {\n const result = new Set<string>(excludedCodes);\n\n // Build parent → children adjacency once. Entries with `parentCode === null`\n // are tree roots and contribute no edges.\n const childMap = new Map<string, string[]>();\n for (const entry of entries) {\n if (entry.parentCode) {\n const siblings = childMap.get(entry.parentCode);\n if (siblings) {\n siblings.push(entry.code);\n } else {\n childMap.set(entry.parentCode, [entry.code]);\n }\n }\n }\n\n // BFS from every initially-excluded code. The visited check (`!result.has`)\n // both prevents infinite loops on accidental cycles and ensures O(N) work.\n const queue: string[] = [...excludedCodes];\n while (queue.length > 0) {\n const code = queue.shift() as string;\n const children = childMap.get(code);\n if (!children) continue;\n for (const childCode of children) {\n if (!result.has(childCode)) {\n result.add(childCode);\n queue.push(childCode);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Apply a registry's `excludedEntries` / `includedEntries` overrides to a\n * pre-loaded entry pool. Implements the four-mode table from locked spec\n * §9.1.1:\n *\n * | excludedEntries | includedEntries | Mode |\n * | --------------- | --------------- | ------------------ |\n * | empty | empty | Default (all) |\n * | has values | empty | Blacklist |\n * | empty | has values | Whitelist |\n * | has values | has values | Blacklist + override |\n *\n * Inclusion always wins over exclusion in the override mode — that's how\n * agencies pull a single descendant back in after excluding its parent.\n *\n * @param excludedEntries - Codes the registry excludes (cascades to children)\n * @param includedEntries - Codes the registry force-includes (override or whitelist)\n * @param entries - The merged entry pool from all pinned domains\n * @returns A new array containing only the entries selected by the overrides\n */\nexport function applyEntryOverrides(\n excludedEntries: readonly string[] | null | undefined,\n includedEntries: readonly string[] | null | undefined,\n entries: readonly ICvcEntry[],\n): ICvcEntry[] {\n const excluded = new Set(excludedEntries ?? []);\n const included = new Set(includedEntries ?? []);\n const hasExclusions = excluded.size > 0;\n const hasInclusions = included.size > 0;\n\n // Default mode: no overrides at all → return the pool unchanged.\n if (!hasExclusions && !hasInclusions) {\n return [...entries];\n }\n\n // Whitelist mode: start from empty and pull in only the listed codes.\n if (!hasExclusions && hasInclusions) {\n return entries.filter((entry) => included.has(entry.code));\n }\n\n // Blacklist mode (with optional override): cascade the exclusion set, then\n // filter the pool, letting any explicitly-included code punch through.\n const cascadedExclusions = cascadeExclusions(excluded, entries);\n return entries.filter((entry) => {\n if (included.has(entry.code)) return true;\n if (cascadedExclusions.has(entry.code)) return false;\n return true;\n });\n}\n\n/**\n * Loader signature: fetch a registry document by id. Used by\n * `resolveRegistryWithInheritance` to walk the `basedOn` pointer without\n * needing a live Mongoose connection.\n */\nexport type RegistryLoader = (\n id: Types.ObjectId,\n) => Promise<ICvcRegistry | null>;\n\n/**\n * Loader signature: fetch all entries for a `(domain, version)` tuple. Used\n * by `resolveRegistryWithInheritance` so the pure resolution layer can be\n * tested with in-memory fixtures instead of a real `cvc_entries` collection.\n */\nexport type EntryLoader = (\n domain: string,\n version: string,\n) => Promise<ICvcEntry[]>;\n\n/**\n * Resolve a registry into its effective `(mergedVersions, entries)` pair,\n * walking exactly one level of `basedOn` inheritance per locked spec §9.1.2.\n *\n * The spec constrains `basedOn` chains to two levels (base → child); the\n * implementation enforces that constraint by **only** consulting the\n * immediate parent. Deeper grandparents are ignored even if a misconfigured\n * registry chains further — this matches the contract that downstream\n * callers see at most one merge step.\n *\n * Resolution order (locked spec §9.1.2):\n * 1. Start with the child's own `cvcVersions`\n * 2. If the child has `basedOn`, load the parent and overlay the child's\n * `cvcVersions` on top of the parent's (child wins per-domain)\n * 3. Load entries for every merged `(domain, version)` tuple\n * 4. Apply the child's own `excludedEntries` / `includedEntries` to the\n * merged pool — inheritance does not propagate overrides\n *\n * @param registry - The child registry being resolved\n * @param loadRegistry - Loader for the parent registry (only called if `basedOn` is set)\n * @param loadEntries - Loader for entry pools by (domain, version)\n * @returns The merged version pins and the resolved effective entry list\n */\nexport async function resolveRegistryWithInheritance(\n registry: ICvcRegistry,\n loadRegistry: RegistryLoader,\n loadEntries: EntryLoader,\n): Promise<{\n mergedVersions: Record<string, string>;\n entries: ICvcEntry[];\n}> {\n const childVersions = cvcVersionsToRecord(registry.cvcVersions);\n let mergedVersions: Record<string, string> = { ...childVersions };\n\n if (registry.basedOn) {\n const base = await loadRegistry(registry.basedOn);\n if (!base) {\n throw new Error(\n `CvcRegistryService: basedOn registry not found: ${registry.basedOn.toString()}`,\n );\n }\n // Locked spec §9.1.2: base versions first, child overrides on top.\n mergedVersions = {\n ...cvcVersionsToRecord(base.cvcVersions),\n ...childVersions,\n };\n }\n\n // Load entries for every pinned `(domain, version)`. We deliberately load\n // sequentially per domain rather than in parallel because consumer apps\n // typically have ≤5 domains pinned per registry — the parallelism win is\n // negligible and the sequential form keeps test fixtures deterministic.\n const pool: ICvcEntry[] = [];\n for (const [domain, version] of Object.entries(mergedVersions)) {\n const domainEntries = await loadEntries(domain, version);\n pool.push(...domainEntries);\n }\n\n const entries = applyEntryOverrides(\n registry.excludedEntries,\n registry.includedEntries,\n pool,\n );\n return { mergedVersions, entries };\n}\n\n// ─── Service class ───────────────────────────────────────────────────────────\n\n/**\n * Build a Mongo filter that pins a registry to a specific scope. `null`\n * scope keys translate to `null` in the filter (matching the on-disk default\n * for unscoped rows) — they do **not** become `$exists: false`. The schema\n * defaults `application` and `agencyId` to `null`, so this matches reality.\n */\nfunction scopeFilter(scope: RegistryScope): {\n application: string | null;\n agencyId: Types.ObjectId | null;\n} {\n return {\n application: scope.application ?? null,\n agencyId: scope.agencyId ?? null,\n };\n}\n\n/**\n * Build the cache key for a resolved registry. Cache keys are stringified\n * `_id`s — every registry has a unique `_id`, so two distinct scopes that\n * happen to share an active version still get distinct cache slots.\n */\nfunction cacheKeyFor(registryId: Types.ObjectId): string {\n return registryId.toString();\n}\n\n/**\n * Service class. See module-level docstring for the high-level contract;\n * each method documents its own scope-fallback / cache / lifecycle behavior.\n */\nexport class CvcRegistryService {\n private readonly registryModel: Model<ICvcRegistry>;\n private readonly entryModel: Model<ICvcEntry>;\n private readonly scopeFallback: boolean;\n\n /**\n * Cached resolved entry set per registry id. The value is the full\n * post-override entry list — domain filtering is done on read so the\n * cache stays domain-agnostic. Cleared on activate/deprecate of any\n * registry that overlaps the cached scope.\n */\n private readonly resolvedCache = new Map<string, ICvcEntry[]>();\n\n /**\n * @param connection - Mongoose connection that owns `cvc_registries` and `cvc_entries`\n * @param options - Optional behavior toggles (see {@link CvcRegistryServiceOptions})\n */\n constructor(connection: Connection, options: CvcRegistryServiceOptions = {}) {\n // The schema-derived `CvcRegistry`/`CvcEntry` types from co-am3.2's\n // `schemas/*.ts` widen to the Schema instance shape (a known limitation\n // of `InferRawDocType<Schema>` without preserved generics). Cast to the\n // canonical `ICvcRegistry`/`ICvcEntry` interfaces defined above —\n // these are the contract every method in this file is written against.\n this.registryModel = cvcRegistryModel.compileModel(\n connection,\n ) as unknown as Model<ICvcRegistry>;\n this.entryModel = cvcEntryModel.compileModel(\n connection,\n ) as unknown as Model<ICvcEntry>;\n this.scopeFallback = options.scopeFallback ?? true;\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Registry lifecycle\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Find the active registry for a scope, walking the fallback chain\n * (agency-specific → app-specific → platform-default) when enabled. Returns\n * `null` if no active registry exists at any level of the chain.\n */\n async getActiveRegistry(\n scope: RegistryScope,\n ): Promise<ICvcRegistry | null> {\n const candidates: RegistryScope[] = [scope];\n\n // Build the fallback ladder. We only widen scope if it actually narrows\n // something — there's no point asking for `{null, null}` twice.\n if (this.scopeFallback) {\n if (scope.agencyId != null && scope.application != null) {\n candidates.push({ application: scope.application, agencyId: null });\n }\n if (scope.application != null) {\n candidates.push({ application: null, agencyId: null });\n }\n }\n\n for (const candidate of candidates) {\n const found = await this.registryModel\n .findOne({ ...scopeFilter(candidate), status: \"active\" })\n .lean<ICvcRegistry>()\n .exec();\n if (found) return found;\n }\n return null;\n }\n\n /**\n * Look up a registry by its `(scope, version)` tuple. The scope must be\n * exact — there is no fallback chain here, since version pins are scope-\n * specific by definition.\n */\n async getRegistry(\n scope: RegistryScope,\n version: string,\n ): Promise<ICvcRegistry | null> {\n return this.registryModel\n .findOne({ ...scopeFilter(scope), version })\n .lean<ICvcRegistry>()\n .exec();\n }\n\n /**\n * List every registry version for an exact scope, regardless of status.\n * Sorted by version so callers get a deterministic ordering for change\n * logs / version pickers. The version field is a semver string, so the\n * sort is lexicographic — good enough for the typical 1.0.0 / 1.1.0 case.\n */\n async listVersions(scope: RegistryScope): Promise<ICvcRegistry[]> {\n return this.registryModel\n .find(scopeFilter(scope))\n .sort({ version: 1 })\n .lean<ICvcRegistry[]>()\n .exec();\n }\n\n /**\n * Promote a draft registry to `active`. Atomically demotes the previous\n * active registry in the same scope to `deprecated` so the\n * one-active-per-scope invariant holds even under concurrent activations\n * (the partial unique index on `cvc_registries` enforces this at the DB\n * layer; we mirror it here for clarity).\n *\n * @throws Error if the target registry doesn't exist or isn't in `draft`\n */\n async activate(registryId: Types.ObjectId): Promise<ICvcRegistry> {\n const target = await this.registryModel\n .findById(registryId)\n .lean<ICvcRegistry>()\n .exec();\n if (!target) {\n throw new Error(\n `CvcRegistryService.activate: registry not found: ${registryId.toString()}`,\n );\n }\n if (target.status !== \"draft\") {\n throw new Error(\n `CvcRegistryService.activate: registry ${registryId.toString()} is '${target.status}', expected 'draft'`,\n );\n }\n\n const now = new Date();\n\n // Demote the existing active registry in this scope (if any). Done\n // before promoting the new one so the partial unique index never sees\n // two active rows in the same scope, even mid-transaction.\n await this.registryModel\n .updateOne(\n {\n application: target.application ?? null,\n agencyId: target.agencyId ?? null,\n status: \"active\",\n },\n { $set: { status: \"deprecated\", dateDeactivated: now } },\n )\n .exec();\n\n const activated = await this.registryModel\n .findByIdAndUpdate(\n registryId,\n { $set: { status: \"active\", dateActivated: now } },\n { new: true },\n )\n .lean<ICvcRegistry>()\n .exec();\n if (!activated) {\n throw new Error(\n `CvcRegistryService.activate: registry vanished mid-update: ${registryId.toString()}`,\n );\n }\n\n // Cache invariants change on every activation: the previously active\n // registry's resolution is still correct for its id, but consumers\n // asking for \"active in scope X\" will now get a new id. Drop the entire\n // cache rather than reasoning about which entries overlap.\n this.resolvedCache.clear();\n return activated;\n }\n\n /**\n * Demote an active registry to `deprecated`. Idempotent only in the sense\n * that calling it twice on the same registry will fail the second time —\n * we don't allow re-deprecating something that's already deprecated, so\n * the lifecycle stays a strict state machine.\n *\n * @throws Error if the target registry doesn't exist or isn't `active`\n */\n async deprecate(registryId: Types.ObjectId): Promise<ICvcRegistry> {\n const target = await this.registryModel\n .findById(registryId)\n .lean<ICvcRegistry>()\n .exec();\n if (!target) {\n throw new Error(\n `CvcRegistryService.deprecate: registry not found: ${registryId.toString()}`,\n );\n }\n if (target.status !== \"active\") {\n throw new Error(\n `CvcRegistryService.deprecate: registry ${registryId.toString()} is '${target.status}', expected 'active'`,\n );\n }\n\n const updated = await this.registryModel\n .findByIdAndUpdate(\n registryId,\n { $set: { status: \"deprecated\", dateDeactivated: new Date() } },\n { new: true },\n )\n .lean<ICvcRegistry>()\n .exec();\n if (!updated) {\n throw new Error(\n `CvcRegistryService.deprecate: registry vanished mid-update: ${registryId.toString()}`,\n );\n }\n\n this.resolvedCache.clear();\n return updated;\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Entry resolution (core — all convenience methods funnel through here)\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Resolve a registry into its effective entry list, applying inheritance\n * and overrides. Results are memoised by registry id; the cache is\n * invalidated on `activate()` / `deprecate()`.\n */\n async resolveEntries(registryId: Types.ObjectId): Promise<ICvcEntry[]> {\n const cacheKey = cacheKeyFor(registryId);\n const cached = this.resolvedCache.get(cacheKey);\n if (cached) return cached;\n\n const registry = await this.registryModel\n .findById(registryId)\n .lean<ICvcRegistry>()\n .exec();\n if (!registry) {\n throw new Error(\n `CvcRegistryService.resolveEntries: registry not found: ${registryId.toString()}`,\n );\n }\n\n const { entries } = await resolveRegistryWithInheritance(\n registry,\n (id) =>\n this.registryModel\n .findById(id)\n .lean<ICvcRegistry>()\n .exec(),\n (domain, version) =>\n this.entryModel\n .find({ domain, version })\n .lean<ICvcEntry[]>()\n .exec(),\n );\n\n this.resolvedCache.set(cacheKey, entries);\n return entries;\n }\n\n /**\n * Same as {@link resolveEntries} but filtered to a single CVC domain.\n * Filtering is done on the cached set so repeated calls for different\n * domains share the same underlying load.\n */\n async resolveEntriesForDomain(\n registryId: Types.ObjectId,\n domain: string,\n ): Promise<ICvcEntry[]> {\n const all = await this.resolveEntries(registryId);\n return all.filter((entry) => entry.domain === domain);\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Entry lookups (convenience — resolve through the active registry)\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Find an entry by its 7-segment positional code within the active\n * registry for `scope`. Returns `null` if no active registry exists or\n * the code isn't present in the resolved entry set.\n */\n async getEntryByCode(\n scope: RegistryScope,\n code: string,\n ): Promise<ICvcEntry | null> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return null;\n const entries = await this.resolveEntries(registry._id);\n return entries.find((entry) => entry.code === code) ?? null;\n }\n\n /**\n * Find an entry by its stable machine key within a specific domain in the\n * active registry. Keys are unique per `(domain, version)` so the lookup\n * always returns at most one entry.\n */\n async getEntryByKey(\n scope: RegistryScope,\n domain: string,\n key: string,\n ): Promise<ICvcEntry | null> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return null;\n const entries = await this.resolveEntriesForDomain(registry._id, domain);\n return entries.find((entry) => entry.key === key) ?? null;\n }\n\n /**\n * Get every resolved entry for a given domain in the active registry.\n */\n async getEntries(\n scope: RegistryScope,\n domain: string,\n ): Promise<ICvcEntry[]> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return [];\n return this.resolveEntriesForDomain(registry._id, domain);\n }\n\n /**\n * Get only the selectable (leaf) entries for a domain — useful for form\n * dropdowns where structural grouping rows must be hidden.\n */\n async getSelectableEntries(\n scope: RegistryScope,\n domain: string,\n ): Promise<ICvcEntry[]> {\n const entries = await this.getEntries(scope, domain);\n return entries.filter((entry) => entry.selectable);\n }\n\n /**\n * Get the direct children of a parent code within the active registry.\n * Returns `[]` for leaves and for codes not present in the resolved set.\n */\n async getChildren(\n scope: RegistryScope,\n code: string,\n ): Promise<ICvcEntry[]> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return [];\n const entries = await this.resolveEntries(registry._id);\n return entries.filter((entry) => entry.parentCode === code);\n }\n\n /**\n * Walk the parent chain from `code` up to the tree root, returning the\n * ancestors in **root → entry** order (the entry itself is not included).\n * Stops early if a parent code references an entry that isn't present in\n * the resolved set — that's a corrupt-tree signal but we'd rather return\n * a partial chain than throw inside a UI breadcrumb call.\n */\n async getAncestors(\n scope: RegistryScope,\n code: string,\n ): Promise<ICvcEntry[]> {\n const registry = await this.getActiveRegistry(scope);\n if (!registry) return [];\n const entries = await this.resolveEntries(registry._id);\n const byCode = new Map(entries.map((entry) => [entry.code, entry]));\n\n const chain: ICvcEntry[] = [];\n let current = byCode.get(code);\n // Cycle guard: if a corrupt tree contains a loop, stop after we've seen\n // every entry once. This bounds the walk to O(N) in the worst case.\n const seen = new Set<string>();\n while (current?.parentCode && !seen.has(current.parentCode)) {\n seen.add(current.parentCode);\n const parent = byCode.get(current.parentCode);\n if (!parent) break;\n chain.push(parent);\n current = parent;\n }\n return chain.reverse();\n }\n\n // ──────────────────────────────────────────────────────────────────────────\n // Test seam: cache introspection\n // ──────────────────────────────────────────────────────────────────────────\n\n /**\n * Test-only accessor for the resolved-entry cache. Exposed so service\n * tests can assert that `activate()` / `deprecate()` actually flush the\n * cache, and so consumers diagnosing stale-data bugs can dump the live\n * keyset. Not part of the locked spec API surface — treat as internal.\n */\n get __cacheKeysForTests(): readonly string[] {\n return [...this.resolvedCache.keys()];\n }\n}\n","/**\n * @htilabs/platform-common-models — Form Schema\n *\n * Versioned form definitions for screening, intake, and assessment forms.\n * Forms contain ordered references to sections with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Form Section Reference Sub-Schema ───────────────────────────────────────\n\nexport const formSectionRefSchema = new Schema(\n {\n sectionId: { type: String, required: true },\n sectionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n isStep: { type: Boolean, default: false },\n wizardStep: { type: Number },\n label: { type: String },\n presetsType: { type: String },\n },\n { _id: false },\n);\n\nexport type FormSectionRef = InferRawDocType<typeof formSectionRefSchema>;\n\n// ─── Form Schema ─────────────────────────────────────────────────────────────\n\nexport const formSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Form info\n name: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n },\n formType: {\n type: String,\n index: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Ordered sections\n sections: {\n type: [formSectionRefSchema],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n};\n\nexport const formSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"forms\",\n};\n\n/**\n * Build the Form schema.\n * @returns Mongoose Schema for Form\n */\nexport function buildFormSchema(): Schema {\n const schema = new Schema(formSchemaDefinition, formSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _formSchema = buildFormSchema();\n\nexport type Form = InferRawDocType<typeof _formSchema>;\n","/**\n * @htilabs/platform-common-models — Section Schema\n *\n * Logical grouping of questions within a form.\n * Sections contain ordered references to questions with display metadata.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Section Question Reference Sub-Schema ───────────────────────────────────\n\nexport const sectionQuestionRefSchema = new Schema(\n {\n questionId: { type: String, required: true },\n questionVersion: { type: String, required: true },\n index: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type SectionQuestionRef = InferRawDocType<\n typeof sectionQuestionRefSchema\n>;\n\n// ─── Guidance Sub-Schema ─────────────────────────────────────────────────────\n\nexport const guidanceSchema = new Schema(\n {\n type: {\n type: String,\n required: true,\n enum: [\"tip\", \"warning\", \"prompt\"],\n },\n text: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type Guidance = InferRawDocType<typeof guidanceSchema>;\n\n// ─── Section Schema ──────────────────────────────────────────────────────────\n\nexport const sectionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Section info\n name: {\n type: String,\n required: true,\n },\n directions: {\n type: String,\n },\n\n // Typed guidance items\n guidance: {\n type: [guidanceSchema],\n default: [],\n },\n\n // Ordered question refs\n questions: {\n type: [sectionQuestionRefSchema],\n default: [],\n },\n\n // Template visibility\n templateScope: {\n type: [String],\n default: undefined,\n },\n collapsible: {\n type: Boolean,\n default: false,\n },\n defaultCollapsed: {\n type: Boolean,\n default: false,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n rephrasing: {\n type: String,\n },\n script: {\n type: String,\n },\n};\n\nexport const sectionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"sections\",\n};\n\n/**\n * Build the Section schema.\n * @returns Mongoose Schema for Section\n */\nexport function buildSectionSchema(): Schema {\n const schema = new Schema(sectionSchemaDefinition, sectionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _sectionSchema = buildSectionSchema();\n\nexport type Section = InferRawDocType<typeof _sectionSchema>;\n","/**\n * @htilabs/platform-common-models — Question Schema\n *\n * Individual form fields with validation, choices, visibility rules, and scoring.\n * Questions support static and dynamic choices, conditional visibility, and IC code mapping.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Choice Sub-Schema ───────────────────────────────────────────────────────\n\nexport const choiceSchema = new Schema(\n {\n val: { type: Schema.Types.Mixed, required: true },\n text: { type: String, required: true },\n tip: { type: String },\n trigger: { type: [String] },\n },\n { _id: false },\n);\n\nexport type Choice = InferRawDocType<typeof choiceSchema>;\n\n// ─── Visibility Rule Sub-Schema ──────────────────────────────────────────────\n\nexport const visibilityRuleSchema = new Schema(\n {\n dependsOn: { type: String, required: true },\n condition: {\n type: String,\n required: true,\n enum: [\"equals\", \"not_equals\", \"any_of\", \"in_range\"],\n },\n values: { type: [Schema.Types.Mixed], required: true },\n source: {\n type: String,\n enum: [\"form\", \"session\"],\n default: \"form\",\n },\n },\n { _id: false },\n);\n\nexport type VisibilityRule = InferRawDocType<typeof visibilityRuleSchema>;\n\n// ─── Layout Sub-Schema ───────────────────────────────────────────────────────\n\nexport const layoutSchema = new Schema(\n {\n columns: { type: Number, default: 1, min: 1, max: 4 },\n collapsible: { type: Boolean, default: false },\n groupKey: { type: String },\n },\n { _id: false },\n);\n\nexport type Layout = InferRawDocType<typeof layoutSchema>;\n\n// ─── Question Schema ─────────────────────────────────────────────────────────\n\nexport const questionSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Versioning\n key: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n\n // Question definition\n index: {\n type: Number,\n required: true,\n },\n text: {\n type: String,\n required: true,\n },\n format: {\n type: String,\n required: true,\n },\n sectionId: {\n type: String,\n required: true,\n },\n required: {\n type: Boolean,\n default: false,\n },\n allowMultiple: {\n type: Boolean,\n default: false,\n },\n\n // Nesting\n isNested: {\n type: Boolean,\n default: false,\n },\n nested: {\n type: [String],\n default: [],\n },\n\n // Trigger logic\n isTriggered: {\n type: Boolean,\n default: false,\n },\n triggersWhenAnswered: {\n type: [String],\n default: [],\n },\n\n // Display\n header: { type: String },\n directions: { type: String },\n tip: { type: String },\n\n // Dynamic choices\n hasDynamicChoices: {\n type: Boolean,\n default: false,\n },\n dynamicChoiceSet: { type: String },\n group: { type: String },\n\n // Static choices\n choices: {\n type: [choiceSchema],\n default: [],\n },\n\n // UI rendering hints\n componentProps: {\n type: Schema.Types.Mixed,\n },\n\n // Autofill\n autofillRules: {\n type: Schema.Types.Mixed,\n default: [],\n },\n\n // Classification\n formType: {\n type: [String],\n enum: [\"screening\", \"intake\", \"assessment\", \"demographics\"],\n default: [],\n },\n icCode: {\n type: String,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n supersedes: {\n type: String,\n },\n\n // Entity mapping (dual-write bridge)\n targetEntity: {\n type: String,\n enum: [\n \"caseSession\",\n \"protectedPerson\",\n \"perpetratorPerson\",\n \"personnelPerson\",\n \"caseRecord\",\n \"serviceInstance\",\n ],\n },\n targetField: {\n type: String,\n },\n\n // Conditional visibility\n visibilityRule: {\n type: visibilityRuleSchema,\n },\n\n // Layout hints\n layout: {\n type: layoutSchema,\n },\n microcopy: {\n type: String,\n },\n sensitivity: {\n type: String,\n enum: [\"standard\", \"sensitive\", \"highly_sensitive\"],\n },\n\n // Scoring group\n scoringGroup: {\n type: String,\n },\n\n // PAVE-aligned optional fields\n groups: {\n type: [String],\n default: undefined,\n },\n rephrasingSelector: {\n type: Schema.Types.Mixed,\n },\n textSelector: {\n type: Schema.Types.Mixed,\n },\n tipSelector: {\n type: Schema.Types.Mixed,\n },\n sortChoices: {\n type: Boolean,\n },\n isAllRequired: {\n type: Boolean,\n },\n itemLabel: {\n type: String,\n },\n prompts: {\n type: [String],\n default: undefined,\n },\n rephrasing: {\n type: String,\n },\n dynamicChoiceTrigger: {\n type: String,\n },\n};\n\nexport const questionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"questions\",\n};\n\n/**\n * Build the Question schema.\n * @returns Mongoose Schema for Question\n */\nexport function buildQuestionSchema(): Schema {\n const schema = new Schema(questionSchemaDefinition, questionSchemaOptions);\n\n // Compound unique: only one version of a given key\n schema.index({ key: 1, version: 1 }, { unique: true });\n\n // Partial unique: only one \"active\" document per key\n schema.index(\n { key: 1 },\n { unique: true, partialFilterExpression: { status: \"active\" } },\n );\n\n // Lookup by section + order\n schema.index({ sectionId: 1, index: 1 });\n\n // IC code lookup (sparse — many questions won't have an IC code)\n schema.index({ icCode: 1 }, { sparse: true });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _questionSchema = buildQuestionSchema();\n\nexport type Question = InferRawDocType<typeof _questionSchema>;\n","/**\n * @htilabs/platform-common-models — Scoring Rule Schema\n *\n * Evaluation rules for screening and assessment instruments.\n * Defines conditions to evaluate, score thresholds, and risk level recommendations.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Scoring Condition Sub-Schema ────────────────────────────────────────────\n\nexport const scoringConditionSchema = new Schema(\n {\n questionKey: { type: String, required: true },\n operator: {\n type: String,\n required: true,\n enum: [\"eq\", \"ne\", \"in\", \"not_in\", \"gt\", \"gte\", \"lt\", \"lte\"],\n },\n value: { type: Schema.Types.Mixed, required: true },\n weight: { type: Number, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringCondition = InferRawDocType<typeof scoringConditionSchema>;\n\n// ─── Scoring Threshold Sub-Schema ────────────────────────────────────────────\n\nexport const scoringThresholdSchema = new Schema(\n {\n minScore: { type: Number, required: true },\n maxScore: { type: Number, required: true },\n riskLevel: { type: String, required: true },\n label: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringThreshold = InferRawDocType<typeof scoringThresholdSchema>;\n\n// ─── Scoring Recommendation Sub-Schema ───────────────────────────────────────\n\nexport const scoringRecommendationSchema = new Schema(\n {\n riskLevel: { type: String, required: true },\n action: { type: String, required: true },\n description: { type: String, required: true },\n },\n { _id: false },\n);\n\nexport type ScoringRecommendation = InferRawDocType<\n typeof scoringRecommendationSchema\n>;\n\n// ─── Scoring Rule Schema ─────────────────────────────────────────────────────\n\nexport const scoringRuleSchemaDefinition = {\n _schemaVersion: {\n type: Number,\n required: true,\n default: 1,\n },\n\n // Audit fields\n createdUser: {\n type: Schema.Types.ObjectId,\n required: true,\n index: true,\n },\n updatedUser: {\n type: Schema.Types.ObjectId,\n index: true,\n },\n\n // Reference to Form (cross-db string, not ObjectId)\n formId: {\n type: String,\n required: true,\n },\n formVersion: {\n type: String,\n required: true,\n },\n\n // Rule info\n name: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n appScope: {\n type: [String],\n enum: [\"thread\", \"pave\", \"both\"],\n default: [],\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n effectiveDate: {\n type: Date,\n },\n deprecatedDate: {\n type: Date,\n },\n replacedBy: {\n type: String,\n },\n\n // Scoring logic\n conditions: {\n type: [scoringConditionSchema],\n default: [],\n },\n thresholds: {\n type: [scoringThresholdSchema],\n default: [],\n },\n recommendations: {\n type: [scoringRecommendationSchema],\n default: [],\n },\n};\n\nexport const scoringRuleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"scoringrules\",\n};\n\n/**\n * Build the ScoringRule schema.\n * @returns Mongoose Schema for ScoringRule\n */\nexport function buildScoringRuleSchema(): Schema {\n const schema = new Schema(\n scoringRuleSchemaDefinition,\n scoringRuleSchemaOptions,\n );\n\n // Compound unique: one rule name per form version\n schema.index(\n { formId: 1, formVersion: 1, version: 1, name: 1 },\n { unique: true },\n );\n\n // Lookup active rules for a form\n schema.index({ formId: 1, formVersion: 1, status: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _scoringRuleSchema = buildScoringRuleSchema();\n\nexport type ScoringRule = InferRawDocType<typeof _scoringRuleSchema>;\n","/**\n * @htilabs/platform-common-models — Platform Function Schema\n *\n * Mongoose schema for the `platformFunctions` collection.\n * Each document represents a discrete action that can be performed\n * within the platform, with tool scope and admin/user relevance flags.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\nimport {\n PLATFORM_TOOL_VALUES,\n FUNCTION_STATUS_VALUES,\n} from \"../constants/platform-auth.js\";\n\n// ─── Schema Definition ──────────────────────────────────────────────\n\nexport const platformFunctionSchemaDefinition = {\n code: {\n type: String,\n required: true,\n },\n label: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n default: \"\",\n },\n category: {\n type: String,\n default: \"\",\n },\n tools: {\n type: [String],\n enum: [...PLATFORM_TOOL_VALUES],\n default: [],\n },\n isAdminRelevant: {\n type: Boolean,\n default: false,\n },\n isUserRelevant: {\n type: Boolean,\n default: false,\n },\n isHtiOnly: {\n type: Boolean,\n default: false,\n },\n status: {\n type: String,\n enum: [...FUNCTION_STATUS_VALUES],\n default: \"Not started\",\n },\n sortOrder: {\n type: Number,\n default: 0,\n },\n};\n\nexport const platformFunctionSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"platformFunctions\",\n};\n\n// ─── Schema Builder ─────────────────────────────────────────────────\n\n/**\n * Build the PlatformFunction schema.\n * @returns Mongoose Schema for PlatformFunction\n */\nexport function buildPlatformFunctionSchema(): Schema {\n const schema = new Schema(\n platformFunctionSchemaDefinition,\n platformFunctionSchemaOptions,\n );\n\n // Unique index on function code\n schema.index({ code: 1 }, { unique: true });\n\n // Lookup indexes\n schema.index({ tools: 1 });\n schema.index({ category: 1 });\n schema.index({ sortOrder: 1 });\n\n return schema;\n}\n\n// ─── Type Inference ─────────────────────────────────────────────────\n\nconst _platformFunctionSchema = buildPlatformFunctionSchema();\nexport type PlatformFunction = InferRawDocType<typeof _platformFunctionSchema>;\n","/**\n * @htilabs/platform-common-models — Platform Authorization Constants\n *\n * Enums and labels for the platform role/function permission model.\n * Includes permission states, share view levels, tool codes, role levels,\n * and function implementation statuses.\n *\n * Source: PLATFORM_AUTH_SPEC.md Sections 5 + 6\n */\n\n// ─── Permission State (4-state role→function mapping) ──────────────\n\nexport const PERMISSION_STATE = {\n /** Role can always perform this function (mandatory, cannot disable). */\n ALWAYS: \"ALWAYS\",\n /** Default On — user can opt off. */\n PREF_YES: \"PREF_YES\",\n /** Default Off — user can opt in. */\n PREF_NO: \"PREF_NO\",\n /** Role is explicitly barred from this function. */\n NEVER: \"NEVER\",\n} as const;\n\nexport type PermissionStateValue =\n (typeof PERMISSION_STATE)[keyof typeof PERMISSION_STATE];\n\nexport const PERMISSION_STATE_VALUES = [\n PERMISSION_STATE.ALWAYS,\n PERMISSION_STATE.PREF_YES,\n PERMISSION_STATE.PREF_NO,\n PERMISSION_STATE.NEVER,\n] as const;\n\nexport const PERMISSION_STATE_LABELS: Record<PermissionStateValue, string> = {\n [PERMISSION_STATE.ALWAYS]: \"Always\",\n [PERMISSION_STATE.PREF_YES]: \"Default On\",\n [PERMISSION_STATE.PREF_NO]: \"Default Off\",\n [PERMISSION_STATE.NEVER]: \"Never\",\n};\n\n/** UI display metadata for permission states (colors, icons). */\nexport const PERMISSION_STATE_DISPLAY: Record<\n PermissionStateValue,\n { label: string; color: string; bgColor: string; icon: string }\n> = {\n [PERMISSION_STATE.ALWAYS]: {\n label: \"Always\",\n color: \"#2e7d32\",\n bgColor: \"#e8f5e9\",\n icon: \"\\u{1F512}\",\n },\n [PERMISSION_STATE.PREF_YES]: {\n label: \"Default On\",\n color: \"#1565c0\",\n bgColor: \"#e3f2fd\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.PREF_NO]: {\n label: \"Default Off\",\n color: \"#e65100\",\n bgColor: \"#fff3e0\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.NEVER]: {\n label: \"Never\",\n color: \"#c62828\",\n bgColor: \"#ffebee\",\n icon: \"\\u{1F512}\",\n },\n};\n\n// ─── Share View (data visibility for shared records) ───────────────\n\nexport const SHARE_VIEW = {\n /** System metadata only (partial access). */\n SYS_INFO: \"sys_info\",\n /** Full case/record content. */\n ALL: \"all\",\n /** No data access. */\n NONE: \"none\",\n} as const;\n\nexport type ShareViewValue = (typeof SHARE_VIEW)[keyof typeof SHARE_VIEW];\n\nexport const SHARE_VIEW_VALUES = [\n SHARE_VIEW.SYS_INFO,\n SHARE_VIEW.ALL,\n SHARE_VIEW.NONE,\n] as const;\n\nexport const SHARE_VIEW_LABELS: Record<ShareViewValue, string> = {\n [SHARE_VIEW.SYS_INFO]: \"System Info Only\",\n [SHARE_VIEW.ALL]: \"Full Content\",\n [SHARE_VIEW.NONE]: \"No Data Access\",\n};\n\n// ─── Platform Tool Codes ───────────────────────────────────────────\n\nexport const PLATFORM_TOOL = {\n PAVE: \"PAVE\",\n ECHO: \"ECHO\",\n LEADS: \"LEADS\",\n THREAD: \"THREAD\",\n TRAIL: \"TRAIL\",\n PLATFORM: \"PLATFORM\",\n} as const;\n\nexport type PlatformToolValue =\n (typeof PLATFORM_TOOL)[keyof typeof PLATFORM_TOOL];\n\nexport const PLATFORM_TOOL_VALUES = [\n PLATFORM_TOOL.PAVE,\n PLATFORM_TOOL.ECHO,\n PLATFORM_TOOL.LEADS,\n PLATFORM_TOOL.THREAD,\n PLATFORM_TOOL.TRAIL,\n PLATFORM_TOOL.PLATFORM,\n] as const;\n\nexport const PLATFORM_TOOL_LABELS: Record<PlatformToolValue, string> = {\n [PLATFORM_TOOL.PAVE]: \"PAVE\",\n [PLATFORM_TOOL.ECHO]: \"Echo\",\n [PLATFORM_TOOL.LEADS]: \"LEADS\",\n [PLATFORM_TOOL.THREAD]: \"Thread\",\n [PLATFORM_TOOL.TRAIL]: \"Trail\",\n [PLATFORM_TOOL.PLATFORM]: \"Platform\",\n};\n\n// ─── Role Level (hierarchy tiers) ──────────────────────────────────\n\nexport const ROLE_LEVEL = {\n /** User-facing roles (staff, volunteers, practitioners). */\n OPERATIONAL: \"operational\",\n /** Agency-level admin roles. */\n AGENCY: \"agency\",\n /** Team-level admin roles. */\n TEAM: \"team\",\n /** HTI-wide platform admin. */\n PLATFORM: \"platform\",\n /** External governance/oversight roles. */\n OVERSIGHT: \"oversight\",\n} as const;\n\nexport type RoleLevelValue = (typeof ROLE_LEVEL)[keyof typeof ROLE_LEVEL];\n\nexport const ROLE_LEVEL_VALUES = [\n ROLE_LEVEL.OPERATIONAL,\n ROLE_LEVEL.AGENCY,\n ROLE_LEVEL.TEAM,\n ROLE_LEVEL.PLATFORM,\n ROLE_LEVEL.OVERSIGHT,\n] as const;\n\nexport const ROLE_LEVEL_LABELS: Record<RoleLevelValue, string> = {\n [ROLE_LEVEL.OPERATIONAL]: \"Operational\",\n [ROLE_LEVEL.AGENCY]: \"Agency\",\n [ROLE_LEVEL.TEAM]: \"Team\",\n [ROLE_LEVEL.PLATFORM]: \"Platform\",\n [ROLE_LEVEL.OVERSIGHT]: \"Oversight\",\n};\n\n// ─── Function Implementation Status ────────────────────────────────\n\nexport const FUNCTION_STATUS = {\n NOT_STARTED: \"Not started\",\n DEFINED_NEW: \"Defined; new function\",\n DEFINED_EXISTING: \"Defined; existing PAVE function\",\n FUNCTIONAL: \"Functional on all apps\",\n FUTURE: \"Future function (not v1)\",\n} as const;\n\nexport type FunctionStatusValue =\n (typeof FUNCTION_STATUS)[keyof typeof FUNCTION_STATUS];\n\nexport const FUNCTION_STATUS_VALUES = [\n FUNCTION_STATUS.NOT_STARTED,\n FUNCTION_STATUS.DEFINED_NEW,\n FUNCTION_STATUS.DEFINED_EXISTING,\n FUNCTION_STATUS.FUNCTIONAL,\n FUNCTION_STATUS.FUTURE,\n] as const;\n\nexport const FUNCTION_STATUS_LABELS: Record<FunctionStatusValue, string> = {\n [FUNCTION_STATUS.NOT_STARTED]: \"Not Started\",\n [FUNCTION_STATUS.DEFINED_NEW]: \"Defined (New)\",\n [FUNCTION_STATUS.DEFINED_EXISTING]: \"Defined (Existing PAVE)\",\n [FUNCTION_STATUS.FUNCTIONAL]: \"Functional\",\n [FUNCTION_STATUS.FUTURE]: \"Future (Not v1)\",\n};\n","/**\n * @htilabs/platform-common-models — Platform Role Schema\n *\n * Mongoose schema for the `platformRoles` collection.\n * Each document represents a role that bundles function permissions,\n * tool scope, and share visibility settings.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\nimport {\n PLATFORM_TOOL_VALUES,\n ROLE_LEVEL_VALUES,\n SHARE_VIEW_VALUES,\n} from \"../constants/platform-auth.js\";\n\n// ─── Schema Definition ──────────────────────────────────────────────\n\nexport const platformRoleSchemaDefinition = {\n code: {\n type: String,\n required: true,\n },\n label: {\n type: String,\n required: true,\n },\n description: {\n type: String,\n default: \"\",\n },\n level: {\n type: String,\n enum: [...ROLE_LEVEL_VALUES],\n required: true,\n },\n tools: {\n type: [String],\n enum: [...PLATFORM_TOOL_VALUES],\n default: [],\n },\n shareView: {\n type: String,\n enum: [...SHARE_VIEW_VALUES, null],\n default: null,\n },\n trainingRequirements: {\n type: String,\n default: null,\n },\n isHtiOnly: {\n type: Boolean,\n default: false,\n },\n /** Dynamic map of functionCode → PermissionStateValue. */\n functions: {\n type: Schema.Types.Mixed,\n default: {},\n },\n sortOrder: {\n type: Number,\n default: 0,\n },\n};\n\nexport const platformRoleSchemaOptions = {\n timestamps: {\n createdAt: \"createdTime\",\n updatedAt: \"updatedTime\",\n },\n collection: \"platformRoles\",\n};\n\n// ─── Schema Builder ─────────────────────────────────────────────────\n\n/**\n * Build the PlatformRole schema.\n * @returns Mongoose Schema for PlatformRole\n */\nexport function buildPlatformRoleSchema(): Schema {\n const schema = new Schema(\n platformRoleSchemaDefinition,\n platformRoleSchemaOptions,\n );\n\n // Unique index on role code\n schema.index({ code: 1 }, { unique: true });\n\n // Lookup indexes\n schema.index({ level: 1 });\n schema.index({ tools: 1 });\n schema.index({ isHtiOnly: 1 });\n\n return schema;\n}\n\n// ─── Type Inference ─────────────────────────────────────────────────\n\nconst _platformRoleSchema = buildPlatformRoleSchema();\nexport type PlatformRole = InferRawDocType<typeof _platformRoleSchema>;\n","/**\n * @htilabs/platform-common-models — CvcRegistry Model\n *\n * Factory for creating the CvcRegistry model bound to a specific connection.\n * Mirrors the buildSchema/compileModel pattern used by the other platform\n * models in this package (see `formModel.ts`, `questionModel.ts`).\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport {\n buildCvcRegistrySchema,\n type CvcRegistry,\n} from \"../schemas/cvcRegistry.js\";\n\nexport type CvcRegistryDoc = HydratedDocument<CvcRegistry>;\n\n/**\n * Build the CvcRegistry schema.\n * @returns Mongoose Schema for CvcRegistry\n */\nexport { buildCvcRegistrySchema as buildSchema };\n\n/**\n * Compile the CvcRegistry model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildCvcRegistrySchema() if not provided)\n * @returns Mongoose Model for CvcRegistry\n */\nexport function compileModel(\n connection: Connection,\n schema = buildCvcRegistrySchema(),\n): Model<CvcRegistry> {\n return connection.models?.CvcRegistry as Model<CvcRegistry>\n ?? connection.model<CvcRegistry>(\"CvcRegistry\", schema);\n}\n","/**\n * @htilabs/platform-common-models — CVC Registry Schema\n *\n * A CVC Registry is a configuration bundle that pins specific versions of\n * each Controlled Vocabulary (CVC) domain for a given application/agency\n * scope. Consumers resolve \"which entries should I use right now?\" by\n * looking up the active registry for their scope, then loading the pinned\n * versions from `cvc_entries`.\n *\n * Locked spec reference:\n * §9.1 — Generalized CVC data layer in platform-common-models\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * Scope hierarchy (most specific wins at lookup time):\n * 1. (application, agencyId) — agency-specific override for an app\n * 2. (application, null) — app-wide default\n * 3. (null, null) — platform-wide default\n *\n * Lifecycle: a registry begins in `draft`, transitions to `active` (at most\n * one active per scope), and is eventually `deprecated` when superseded.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── CVC Registry Schema ─────────────────────────────────────────────────────\n\nexport const cvcRegistrySchemaDefinition = {\n // Versioning — semantic version of this registry bundle\n version: {\n type: String,\n required: true,\n match: /^\\d+\\.\\d+\\.\\d+(?:[-+][0-9A-Za-z.-]+)?$/,\n },\n\n // Human-readable name (e.g. \"PAVE production registry\")\n name: {\n type: String,\n required: true,\n },\n\n // Scope keys. `null` widens scope: a null `application` means platform-wide;\n // a null `agencyId` means all agencies within `application`.\n application: {\n type: String,\n default: null,\n },\n agencyId: {\n type: Schema.Types.ObjectId,\n default: null,\n },\n\n // Lifecycle\n status: {\n type: String,\n required: true,\n enum: [\"draft\", \"active\", \"deprecated\"],\n default: \"draft\",\n index: true,\n },\n dateActivated: {\n type: Date,\n },\n dateDeactivated: {\n type: Date,\n },\n\n // Pinned domain versions: { service_categories: \"1.0.0\", ... }\n // Stored as a Map<string, string> so individual domains can be added or\n // bumped without re-validating the whole document shape.\n cvcVersions: {\n type: Map,\n of: String,\n required: true,\n default: () => new Map(),\n },\n\n // Selective inclusion/exclusion lists. Both contain CVC entry codes\n // (positional 7-segment, format v2: e.g. \"022-002-000-000-000-000-000\").\n // The runtime applies excludes after includes when resolving the effective\n // set.\n excludedEntries: {\n type: [String],\n default: [],\n },\n includedEntries: {\n type: [String],\n default: [],\n },\n\n // Inheritance pointer — when set, this registry inherits cvcVersions /\n // include / exclude lists from its base before applying its own overrides.\n // Indexed below so a base-version bump can find every dependent registry.\n basedOn: {\n type: Schema.Types.ObjectId,\n default: null,\n },\n};\n\nexport const cvcRegistrySchemaOptions = {\n timestamps: true,\n collection: \"cvc_registries\",\n};\n\n/**\n * Build the CvcRegistry schema with its full set of indexes.\n *\n * Indexes:\n * 1. `{ application, agencyId, version }` unique — primary identity. Two\n * registries in the same scope cannot share a version number.\n * 2. `{ application, agencyId, status }` partial — at most one `active`\n * registry per scope (enforced by the `status: \"active\"` partial filter).\n * 3. `{ basedOn }` — fast lookup of dependent registries when a base\n * registry is bumped or deprecated.\n *\n * @returns Mongoose Schema for CvcRegistry\n */\nexport function buildCvcRegistrySchema(): Schema {\n const schema = new Schema(\n cvcRegistrySchemaDefinition,\n cvcRegistrySchemaOptions,\n );\n\n // Primary identity: one (application, agencyId, version) tuple per registry\n schema.index(\n { application: 1, agencyId: 1, version: 1 },\n { unique: true },\n );\n\n // At most one `active` registry per scope. The partial filter ensures the\n // uniqueness constraint only applies to active rows; draft and deprecated\n // rows are unindexed by this index.\n schema.index(\n { application: 1, agencyId: 1, status: 1 },\n {\n unique: true,\n partialFilterExpression: { status: \"active\" },\n },\n );\n\n // Reverse-lookup for inheritance: \"what registries inherit from me?\"\n schema.index({ basedOn: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _cvcRegistrySchema = buildCvcRegistrySchema();\n\nexport type CvcRegistry = InferRawDocType<typeof _cvcRegistrySchema>;\n","/**\n * @htilabs/platform-common-models — CvcEntry Model\n *\n * Factory for creating the CvcEntry model bound to a specific connection.\n * Mirrors the buildSchema/compileModel pattern used by the other platform\n * models in this package (see `formModel.ts`, `questionModel.ts`).\n */\n\nimport type { Connection, Model, HydratedDocument } from \"mongoose\";\nimport { buildCvcEntrySchema, type CvcEntry } from \"../schemas/cvcEntry.js\";\n\nexport type CvcEntryDoc = HydratedDocument<CvcEntry>;\n\n/**\n * Build the CvcEntry schema.\n * @returns Mongoose Schema for CvcEntry\n */\nexport { buildCvcEntrySchema as buildSchema };\n\n/**\n * Compile the CvcEntry model on a specific connection.\n * @param connection - Mongoose connection to bind the model to\n * @param schema - Optional pre-built schema (uses buildCvcEntrySchema() if not provided)\n * @returns Mongoose Model for CvcEntry\n */\nexport function compileModel(\n connection: Connection,\n schema = buildCvcEntrySchema(),\n): Model<CvcEntry> {\n return connection.models?.CvcEntry as Model<CvcEntry>\n ?? connection.model<CvcEntry>(\"CvcEntry\", schema);\n}\n","/**\n * @htilabs/platform-common-models — CVC Entry Schema\n *\n * Persistent storage for individual Controlled Vocabulary (CVC) entries.\n * Every entry is keyed by `(domain, version, code)` so that multiple\n * versions of a domain can coexist in the same collection — registries\n * pin which (domain, version) tuples are active for a given scope.\n *\n * Locked spec reference:\n * §9.1.2 — `cvc_entries` collection shape\n * §3 — Positional 7-segment code format\n * §3.2 — Stable machine key format\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * The Zod equivalents in `validation/cvc.ts` enforce the same shapes at the\n * application boundary; the Mongoose constraints below are the persistence\n * layer's defense in depth so that bad inserts fail loudly even if a caller\n * skipped Zod validation.\n */\n\nimport { Schema } from \"mongoose\";\nimport type { InferRawDocType } from \"mongoose\";\n\n// ─── Shared validators ───────────────────────────────────────────────────────\n\n/**\n * Positional 7-segment CVC code: `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (format v2,\n * 3-digit segments with a Notion-aligned domain prefix). Mirrors\n * `CvcCodeSchema` in `validation/cvc.ts`. See locked spec §3.\n */\nconst CVC_CODE_PATTERN = /^\\d{3}(-\\d{3}){6}$/;\n\n/**\n * Stable machine key for a CVC entry. Mirrors `CvcKeySchema` in\n * `validation/cvc.ts`. See locked spec §3.2.\n */\nconst CVC_KEY_PATTERN = /^[a-z][a-z0-9_]*$/;\n\n// ─── CVC Entry Schema ────────────────────────────────────────────────────────\n\nexport const cvcEntrySchemaDefinition = {\n // Compound identity: (domain, version, code) uniquely identifies an entry.\n // `domain` is the SOT family (e.g. \"service_categories\"); `version` is the\n // semantic version of the SOT JSON file the entry was loaded from.\n domain: {\n type: String,\n required: true,\n },\n version: {\n type: String,\n required: true,\n },\n code: {\n type: String,\n required: true,\n match: CVC_CODE_PATTERN,\n },\n\n // Stable machine key for cross-CVC references (e.g. `relevantMechanisms`\n // in service_categories points at service_mechanisms entries by `key`).\n key: {\n type: String,\n required: true,\n match: CVC_KEY_PATTERN,\n },\n\n // Display fields\n title: {\n type: String,\n required: true,\n },\n\n // `selectable` distinguishes leaf entries (selectable) from structural\n // grouping rows (not selectable). Required because the seed CLI must\n // populate it explicitly — there is no sane default.\n selectable: {\n type: Boolean,\n required: true,\n },\n\n // Tree structure. `parentCode` is `null` for root rows; `childCodes` is\n // empty for leaves. We give `parentCode` a `default: null` (rather than\n // marking it required) because Mongoose's `required` validator rejects\n // `null` outright — the default ensures the field is always present on\n // disk while still allowing the documented `string | null` shape. The\n // `match` validator is skipped by Mongoose when the value is null.\n parentCode: {\n type: String,\n default: null,\n match: CVC_CODE_PATTERN,\n },\n childCodes: {\n type: [String],\n required: true,\n default: [],\n },\n\n // Long-form definition. Same `default: null` treatment as `parentCode`\n // above — every row reaches disk with `definition` set to either a\n // string or an explicit null.\n definition: {\n type: String,\n default: null,\n },\n\n // Domain-specific extension bag. Used for fields that only apply to a\n // particular CVC family — e.g. `relevantMechanisms` on service_categories\n // entries (a cross-CVC reference into service_mechanisms by key).\n meta: {\n type: Schema.Types.Mixed,\n },\n};\n\nexport const cvcEntrySchemaOptions = {\n timestamps: true,\n collection: \"cvc_entities\",\n // `parentCode` defaults to null but Mongoose strips required-with-default\n // null assignments unless we keep minimize off.\n minimize: false,\n};\n\n/**\n * Build the CvcEntry schema with its full set of indexes.\n *\n * Indexes:\n * 1. `{ domain, version, code }` unique — primary identity. The seed CLI\n * uses this for upsert keys.\n * 2. `{ domain, version, key }` unique — secondary lookup target for\n * cross-CVC references like `relevantMechanisms`.\n * 3. `{ domain, version, parentCode }` non-unique — supports tree walks\n * (\"give me the children of this code at this version\").\n *\n * @returns Mongoose Schema for CvcEntry\n */\nexport function buildCvcEntrySchema(): Schema {\n const schema = new Schema(cvcEntrySchemaDefinition, cvcEntrySchemaOptions);\n\n // Primary identity\n schema.index(\n { domain: 1, version: 1, code: 1 },\n { unique: true },\n );\n\n // Secondary lookup for cross-CVC references by stable key\n schema.index(\n { domain: 1, version: 1, key: 1 },\n { unique: true },\n );\n\n // Tree walks\n schema.index({ domain: 1, version: 1, parentCode: 1 });\n\n return schema;\n}\n\n// Pre-built schema for type inference\nconst _cvcEntrySchema = buildCvcEntrySchema();\n\nexport type CvcEntry = InferRawDocType<typeof _cvcEntrySchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC8BA,IAAAA,mBAAsB;;;ACvBtB,sBAAuB;AAKhB,IAAM,uBAAuB,IAAI;AAAA,EACtC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AU,GAAG;AAC3D,WAAK,IAAI,QAAQ,UAAU;AAC3B,YAAM,SAAS,OAAO,IAAI,QAAQ,UAAU;AAC5C,UAAI,CAAC,OAAQ;AACb,YAAM,KAAK,MAAM;AACjB,gBAAU;AAAA,IACZ;AACA,WAAO,MAAM,QAAQ;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,IAAI,sBAAyC;AAC3C,WAAO,CAAC,GAAG,KAAK,cAAc,KAAK,CAAC;AAAA,EACtC;AACF;","names":["import_mongoose","import_mongoose","import_mongoose","import_mongoose","import_mongoose","import_mongoose","import_mongoose","compileModel","import_mongoose","compileModel"]}
|
package/dist/services/index.js
CHANGED
|
@@ -948,7 +948,7 @@ var _cvcRegistrySchema = buildCvcRegistrySchema();
|
|
|
948
948
|
|
|
949
949
|
// src/models/cvcRegistryModel.ts
|
|
950
950
|
function compileModel(connection, schema = buildCvcRegistrySchema()) {
|
|
951
|
-
return connection.models
|
|
951
|
+
return connection.models?.CvcRegistry ?? connection.model("CvcRegistry", schema);
|
|
952
952
|
}
|
|
953
953
|
|
|
954
954
|
// src/models/cvcEntryModel.ts
|
|
@@ -1052,7 +1052,7 @@ var _cvcEntrySchema = buildCvcEntrySchema();
|
|
|
1052
1052
|
|
|
1053
1053
|
// src/models/cvcEntryModel.ts
|
|
1054
1054
|
function compileModel2(connection, schema = buildCvcEntrySchema()) {
|
|
1055
|
-
return connection.models
|
|
1055
|
+
return connection.models?.CvcEntry ?? connection.model("CvcEntry", schema);
|
|
1056
1056
|
}
|
|
1057
1057
|
|
|
1058
1058
|
// src/services/cvcRegistryService.ts
|