conftree 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/cache/cache.d.ts +23 -0
- package/dist/cache/cache.d.ts.map +1 -0
- package/dist/cache/cache.js +95 -0
- package/dist/cache/cache.js.map +1 -0
- package/dist/cache/change-bus.d.ts +16 -0
- package/dist/cache/change-bus.d.ts.map +1 -0
- package/dist/cache/change-bus.js +14 -0
- package/dist/cache/change-bus.js.map +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +58 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/types.d.ts +52 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/engine/auditor.d.ts +8 -0
- package/dist/engine/auditor.d.ts.map +1 -0
- package/dist/engine/auditor.js +22 -0
- package/dist/engine/auditor.js.map +1 -0
- package/dist/engine/engine.d.ts +25 -0
- package/dist/engine/engine.d.ts.map +1 -0
- package/dist/engine/engine.js +24 -0
- package/dist/engine/engine.js.map +1 -0
- package/dist/engine/hierarchy-cache-sync.d.ts +4 -0
- package/dist/engine/hierarchy-cache-sync.d.ts.map +1 -0
- package/dist/engine/hierarchy-cache-sync.js +26 -0
- package/dist/engine/hierarchy-cache-sync.js.map +1 -0
- package/dist/engine/resolver.d.ts +24 -0
- package/dist/engine/resolver.d.ts.map +1 -0
- package/dist/engine/resolver.js +195 -0
- package/dist/engine/resolver.js.map +1 -0
- package/dist/engine/writer.d.ts +32 -0
- package/dist/engine/writer.d.ts.map +1 -0
- package/dist/engine/writer.js +178 -0
- package/dist/engine/writer.js.map +1 -0
- package/dist/hierarchy/scope-hierarchy.d.ts +15 -0
- package/dist/hierarchy/scope-hierarchy.d.ts.map +1 -0
- package/dist/hierarchy/scope-hierarchy.js +86 -0
- package/dist/hierarchy/scope-hierarchy.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +895 -0
- package/dist/index.mjs.map +1 -0
- package/dist/storage/memory-storage.d.ts +25 -0
- package/dist/storage/memory-storage.d.ts.map +1 -0
- package/dist/storage/memory-storage.js +176 -0
- package/dist/storage/memory-storage.js.map +1 -0
- package/dist/storage/storage-port.d.ts +93 -0
- package/dist/storage/storage-port.d.ts.map +1 -0
- package/dist/storage/storage-port.js +3 -0
- package/dist/storage/storage-port.js.map +1 -0
- package/dist/typed/registry.d.ts +7 -0
- package/dist/typed/registry.d.ts.map +1 -0
- package/dist/typed/registry.js +3 -0
- package/dist/typed/registry.js.map +1 -0
- package/dist/typed/typed-auditor.d.ts +12 -0
- package/dist/typed/typed-auditor.d.ts.map +1 -0
- package/dist/typed/typed-auditor.js +14 -0
- package/dist/typed/typed-auditor.js.map +1 -0
- package/dist/typed/typed-engine.d.ts +11 -0
- package/dist/typed/typed-engine.d.ts.map +1 -0
- package/dist/typed/typed-engine.js +14 -0
- package/dist/typed/typed-engine.js.map +1 -0
- package/dist/typed/typed-resolver.d.ts +23 -0
- package/dist/typed/typed-resolver.d.ts.map +1 -0
- package/dist/typed/typed-resolver.js +22 -0
- package/dist/typed/typed-resolver.js.map +1 -0
- package/dist/typed/typed-writer.d.ts +32 -0
- package/dist/typed/typed-writer.d.ts.map +1 -0
- package/dist/typed/typed-writer.js +20 -0
- package/dist/typed/typed-writer.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/types.ts","../src/core/errors.ts","../src/cache/change-bus.ts","../src/cache/cache.ts","../src/hierarchy/scope-hierarchy.ts","../src/storage/memory-storage.ts","../src/engine/resolver.ts","../src/engine/writer.ts","../src/engine/auditor.ts","../src/engine/hierarchy-cache-sync.ts","../src/engine/engine.ts","../src/typed/typed-resolver.ts","../src/typed/typed-writer.ts","../src/typed/typed-auditor.ts","../src/typed/typed-engine.ts"],"sourcesContent":["export type JsonValue =\n\t| null\n\t| boolean\n\t| number\n\t| string\n\t| JsonValue[]\n\t| { [key: string]: JsonValue };\n\nexport type Value = Date | JsonValue;\n\nexport interface Scope {\n\tkind: string;\n\trefId: string | null;\n}\n\nexport const DEFAULT_SCOPE: Scope = { kind: 'default', refId: null };\n\nexport type ValueType =\n\t'BOOLEAN' | 'NUMERIC' | 'TEXT' | 'ENUM' | 'JSON' | 'DATE';\n\nexport type Inherit = 'LOCKED' | 'INHERITABLE_OVERRIDABLE' | 'INDEPENDENT';\n\nexport type Status = 'DRAFT' | 'STABLE' | 'DEPRECATED' | 'RETIRED';\n\nexport interface DefRecord {\n\tid: string;\n\tkey: string;\n\tversion: number;\n\tlabel: string;\n\tdescription: string | null;\n\ttype: ValueType;\n\toptions: string[];\n\tmin: number | null;\n\tmax: number | null;\n\tscopes: string[];\n\tinherit: Inherit;\n\trequired: boolean;\n\tsecret: boolean;\n\tstatus: Status;\n\tcategory: string | null;\n}\n\nexport interface ValueRecord {\n\tid: string;\n\tdefinitionId: string;\n\tscopeKind: string;\n\tscopeRefId: string | null;\n\tbool: boolean | null;\n\tnum: number | null;\n\ttext: string | null;\n\tjson: unknown;\n\tjsonSet: boolean;\n\tdate: Date | null;\n\tversion: number;\n}\n\nexport interface ScopeHierarchy {\n\tchain(scopeRefId: string): Promise<string[]>;\n\tdescendants(scopeRefId: string): Promise<string[]>;\n\tchildren(scopeRefId: string): Promise<string[]>;\n\tparent(scopeRefId: string): Promise<string | null>;\n\tattach(id: string, parentId: string | null): Promise<void>;\n\tmove(id: string, newParentId: string | null): Promise<void>;\n\tdetach(id: string): Promise<void>;\n}\n","export type ErrorCode =\n\t| 'NOT_FOUND'\n\t| 'SCOPE'\n\t| 'REQUIRED'\n\t| 'VALUE'\n\t| 'CONFLICT'\n\t| 'CORRUPT'\n\t| 'CYCLE';\n\nexport class ConfTreeError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly code: ErrorCode,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = new.target.name;\n\t\tError.captureStackTrace?.(this, new.target);\n\t}\n}\n\nexport class NotFoundError extends ConfTreeError {\n\tconstructor(key: string) {\n\t\tsuper(`Unknown setting definition: \"${key}\"`, 'NOT_FOUND');\n\t}\n}\n\nexport class ScopeError extends ConfTreeError {\n\tconstructor(key: string, scopeKind: string) {\n\t\tsuper(\n\t\t\t`Setting \"${key}\" cannot be set or read at scope kind \"${scopeKind}\"`,\n\t\t\t'SCOPE',\n\t\t);\n\t}\n}\n\nexport class RequiredError extends ConfTreeError {\n\tconstructor(key: string, scopeKind: string, scopeRefId: string | null) {\n\t\tsuper(\n\t\t\t`Required setting \"${key}\" has no resolvable value for scope ${scopeKind}:${scopeRefId ?? 'null'} ` +\n\t\t\t\t`and no default is defined`,\n\t\t\t'REQUIRED',\n\t\t);\n\t}\n}\n\nexport class ValueError extends ConfTreeError {\n\tconstructor(message: string) {\n\t\tsuper(message, 'VALUE');\n\t}\n}\n\nexport class ConflictError extends ConfTreeError {\n\tconstructor(key: string, scopeKind: string, scopeRefId: string | null) {\n\t\tsuper(\n\t\t\t`Setting \"${key}\" at scope ${scopeKind}:${scopeRefId ?? 'null'} was modified concurrently. ` +\n\t\t\t\t`Reload the current value and retry.`,\n\t\t\t'CONFLICT',\n\t\t);\n\t}\n}\n\nexport class CorruptError extends ConfTreeError {\n\tconstructor(valueId: string) {\n\t\tsuper(\n\t\t\t`setting value row ${valueId} has no typed value set: data corruption`,\n\t\t\t'CORRUPT',\n\t\t);\n\t}\n}\n\nexport class CycleError extends ConfTreeError {\n\tconstructor(id: string, newParentId: string) {\n\t\tsuper(\n\t\t\t`Cannot attach/move scope \"${id}\" under \"${newParentId}\": would create a cycle`,\n\t\t\t'CYCLE',\n\t\t);\n\t}\n}\n","export interface ChangeEvent {\n\tdefinitionId: string;\n\tkey: string;\n\tscopeKind: string;\n\tscopeRefId: string | null;\n}\n\nexport interface ChangeBus {\n\tpublish(event: ChangeEvent): Promise<void>;\n\tsubscribe(listener: (event: ChangeEvent) => void | Promise<void>): void;\n}\n\nexport class LocalBus implements ChangeBus {\n\tprivate readonly listeners = new Set<\n\t\t(event: ChangeEvent) => void | Promise<void>\n\t>();\n\n\tasync publish(event: ChangeEvent): Promise<void> {\n\t\tawait Promise.all(\n\t\t\t[...this.listeners].map((listener) =>\n\t\t\t\tPromise.resolve(listener(event)),\n\t\t\t),\n\t\t);\n\t}\n\n\tsubscribe(listener: (event: ChangeEvent) => void | Promise<void>): void {\n\t\tthis.listeners.add(listener);\n\t}\n}\n","import type { Scope, ScopeHierarchy, Value } from '../core/types';\nimport type { ChangeBus, ChangeEvent } from './change-bus';\n\nexport interface CacheOptions {\n\tenabled?: boolean;\n\tttlMs?: number;\n\tmaxEntries?: number;\n}\n\ninterface Entry {\n\tkey: string;\n\tscopeKind: string;\n\tscopeRefId: string | null;\n\tvalue: Value;\n\texpiresAt: number;\n}\n\nconst DEFAULT_TTL_MS = 30_000;\nconst DEFAULT_MAX_ENTRIES = 50_000;\n\nexport class Cache {\n\tprivate readonly store = new Map<string, Entry>();\n\n\tconstructor(\n\t\tprivate readonly bus: ChangeBus,\n\t\tprivate readonly options: CacheOptions = {},\n\t\tprivate readonly hierarchy?: ScopeHierarchy,\n\t) {\n\t\tthis.bus.subscribe((event) => this.onChange(event));\n\t}\n\n\tget(key: string, scope: Scope): Value | undefined {\n\t\tif (this.options.enabled === false) return undefined;\n\t\tconst cacheKey = this.keyFor(key, scope);\n\t\tconst entry = this.store.get(cacheKey);\n\t\tif (!entry) return undefined;\n\t\tif (entry.expiresAt <= Date.now()) {\n\t\t\tthis.store.delete(cacheKey);\n\t\t\treturn undefined;\n\t\t}\n\t\treturn entry.value;\n\t}\n\n\tset(key: string, scope: Scope, value: Value): void {\n\t\tif (this.options.enabled === false) return;\n\t\tconst cacheKey = this.keyFor(key, scope);\n\t\tif (\n\t\t\t!this.store.has(cacheKey) &&\n\t\t\tthis.store.size >= (this.options.maxEntries ?? DEFAULT_MAX_ENTRIES)\n\t\t) {\n\t\t\tconst oldest = this.store.keys().next().value;\n\t\t\tif (oldest !== undefined) this.store.delete(oldest);\n\t\t}\n\t\tconst ttlMs = this.options.ttlMs ?? DEFAULT_TTL_MS;\n\t\tthis.store.set(cacheKey, {\n\t\t\tkey,\n\t\t\tscopeKind: scope.kind,\n\t\t\tscopeRefId: scope.refId,\n\t\t\tvalue,\n\t\t\texpiresAt: Date.now() + ttlMs,\n\t\t});\n\t}\n\n\tdrop(key: string): void {\n\t\tfor (const [cacheKey, entry] of this.store) {\n\t\t\tif (entry.key === key) this.store.delete(cacheKey);\n\t\t}\n\t}\n\n\tdropAll(): void {\n\t\tthis.store.clear();\n\t}\n\n\tdropForScopes(scopeRefIds: Iterable<string>): void {\n\t\tconst targets = new Set(scopeRefIds);\n\t\tif (targets.size === 0) return;\n\t\tfor (const [cacheKey, entry] of this.store) {\n\t\t\tif (entry.scopeRefId !== null && targets.has(entry.scopeRefId)) {\n\t\t\t\tthis.store.delete(cacheKey);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dropScoped(key: string, scopeRefIds: Iterable<string>): void {\n\t\tconst targets = new Set(scopeRefIds);\n\t\tfor (const [cacheKey, entry] of this.store) {\n\t\t\tif (\n\t\t\t\tentry.key === key &&\n\t\t\t\tentry.scopeRefId !== null &&\n\t\t\t\ttargets.has(entry.scopeRefId)\n\t\t\t) {\n\t\t\t\tthis.store.delete(cacheKey);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async onChange(event: ChangeEvent): Promise<void> {\n\t\tif (this.hierarchy && event.scopeRefId !== null) {\n\t\t\tconst descendants = await this.hierarchy\n\t\t\t\t.descendants(event.scopeRefId)\n\t\t\t\t.catch(() => null);\n\t\t\tif (descendants !== null) {\n\t\t\t\tthis.dropScoped(event.key, descendants);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.drop(event.key);\n\t}\n\n\tprivate keyFor(key: string, scope: Scope): string {\n\t\treturn JSON.stringify([key, scope.kind, scope.refId]);\n\t}\n}\n","import { CycleError } from '../core/errors';\nimport type { ScopeHierarchy } from '../core/types';\n\nexport class LocalScopeHierarchy implements ScopeHierarchy {\n\tprivate readonly parentOf = new Map<string, string | null>();\n\tprivate readonly childrenOf = new Map<string, Set<string>>();\n\n\tasync chain(id: string): Promise<string[]> {\n\t\tconst result: string[] = [];\n\t\tconst seen = new Set<string>();\n\t\tlet current: string | null = id;\n\t\twhile (current !== null) {\n\t\t\tif (seen.has(current)) break;\n\t\t\tseen.add(current);\n\t\t\tresult.push(current);\n\t\t\tcurrent = this.parentOf.get(current) ?? null;\n\t\t}\n\t\treturn result;\n\t}\n\n\tasync descendants(id: string): Promise<string[]> {\n\t\tconst result: string[] = [];\n\t\tconst stack = [id];\n\t\tconst seen = new Set<string>();\n\t\twhile (stack.length > 0) {\n\t\t\tconst current = stack.pop()!;\n\t\t\tif (seen.has(current)) continue;\n\t\t\tseen.add(current);\n\t\t\tresult.push(current);\n\t\t\tconst kids = this.childrenOf.get(current);\n\t\t\tif (kids) stack.push(...kids);\n\t\t}\n\t\treturn result;\n\t}\n\n\tasync children(id: string): Promise<string[]> {\n\t\treturn [...(this.childrenOf.get(id) ?? [])];\n\t}\n\n\tasync parent(id: string): Promise<string | null> {\n\t\treturn this.parentOf.get(id) ?? null;\n\t}\n\n\tasync attach(id: string, parentId: string | null): Promise<void> {\n\t\tif (parentId !== null) await this.assertNoCycle(id, parentId);\n\t\tthis.parentOf.set(id, parentId);\n\t\tif (parentId !== null) this.addChild(parentId, id);\n\t\tif (!this.childrenOf.has(id)) this.childrenOf.set(id, new Set());\n\t}\n\n\tasync move(id: string, newParentId: string | null): Promise<void> {\n\t\tif (newParentId !== null) await this.assertNoCycle(id, newParentId);\n\t\tconst oldParent = this.parentOf.get(id) ?? null;\n\t\tif (oldParent !== null) this.childrenOf.get(oldParent)?.delete(id);\n\t\tthis.parentOf.set(id, newParentId);\n\t\tif (newParentId !== null) this.addChild(newParentId, id);\n\t}\n\n\tasync detach(id: string): Promise<void> {\n\t\tconst parentId = this.parentOf.get(id) ?? null;\n\t\tconst kids = [...(this.childrenOf.get(id) ?? [])];\n\t\tfor (const kid of kids) {\n\t\t\tawait this.move(kid, parentId);\n\t\t}\n\t\tif (parentId !== null) this.childrenOf.get(parentId)?.delete(id);\n\t\tthis.parentOf.delete(id);\n\t\tthis.childrenOf.delete(id);\n\t}\n\n\tprivate addChild(parentId: string, id: string): void {\n\t\tif (!this.childrenOf.has(parentId))\n\t\t\tthis.childrenOf.set(parentId, new Set());\n\t\tthis.childrenOf.get(parentId)!.add(id);\n\t}\n\n\tprivate async assertNoCycle(\n\t\tid: string,\n\t\tnewParentId: string,\n\t): Promise<void> {\n\t\tif (\n\t\t\tid === newParentId ||\n\t\t\t(await this.chain(newParentId)).includes(id)\n\t\t) {\n\t\t\tthrow new CycleError(id, newParentId);\n\t\t}\n\t}\n}\n","import type {\n\tAuditRecord,\n\tCreateAuditInput,\n\tCreateDefInput,\n\tCreateValueInput,\n\tFindAuditQuery,\n\tFindChainQuery,\n\tFindValuesQuery,\n\tListValuesQuery,\n\tListValuesResult,\n\tStorageAdapter,\n\tStorageTx,\n} from './storage-port';\nimport type {\n\tDefRecord,\n\tStatus,\n\tValue,\n\tValueRecord,\n\tValueType,\n} from '../core/types';\nimport { NotFoundError } from '../core/errors';\n\ninterface StoredValue extends ValueRecord {\n\tvalidFrom: Date;\n\tvalidTo: Date | null;\n}\n\nfunction toTypedColumns(type: ValueType, value: Value) {\n\treturn {\n\t\tbool: type === 'BOOLEAN' ? (value as boolean) : null,\n\t\tnum: type === 'NUMERIC' ? (value as number) : null,\n\t\ttext: type === 'TEXT' || type === 'ENUM' ? (value as string) : null,\n\t\tjson: type === 'JSON' ? value : null,\n\t\tjsonSet: type === 'JSON',\n\t\tdate: type === 'DATE' ? (value as Date) : null,\n\t};\n}\n\nexport class MemoryStorageAdapter implements StorageAdapter {\n\tprivate defs: DefRecord[] = [];\n\tprivate values: StoredValue[] = [];\n\tprivate auditLog: AuditRecord[] = [];\n\tprivate nextId = 1;\n\tprivate txQueue: Promise<unknown> = Promise.resolve();\n\n\tprivate newId(prefix: string): string {\n\t\treturn `${prefix}-${this.nextId++}`;\n\t}\n\n\tasync findDefs(keys: string[]): Promise<DefRecord[]> {\n\t\tconst result: DefRecord[] = [];\n\t\tfor (const key of keys) {\n\t\t\tconst found = this.latestByStatus(key, ['STABLE', 'DEPRECATED']);\n\t\t\tif (found) result.push(found);\n\t\t}\n\t\treturn result;\n\t}\n\n\tasync findValues(query: FindValuesQuery): Promise<ValueRecord[]> {\n\t\tconst asOf = query.asOf ?? new Date();\n\t\tconst ids = new Set(query.definitionIds);\n\t\treturn this.values.filter(\n\t\t\t(v) =>\n\t\t\t\tids.has(v.definitionId) &&\n\t\t\t\tv.scopeKind === query.scopeKind &&\n\t\t\t\tv.scopeRefId === query.scopeRefId &&\n\t\t\t\tv.validFrom <= asOf &&\n\t\t\t\t(v.validTo === null || v.validTo > asOf),\n\t\t);\n\t}\n\n\tasync findChainValues(query: FindChainQuery): Promise<ValueRecord[]> {\n\t\tconst asOf = query.asOf ?? new Date();\n\t\tconst defIds = new Set(query.definitionIds);\n\t\tconst refIds = new Set(query.chain);\n\t\treturn this.values.filter(\n\t\t\t(v) =>\n\t\t\t\tdefIds.has(v.definitionId) &&\n\t\t\t\tv.scopeRefId !== null &&\n\t\t\t\trefIds.has(v.scopeRefId) &&\n\t\t\t\tv.validFrom <= asOf &&\n\t\t\t\t(v.validTo === null || v.validTo > asOf),\n\t\t);\n\t}\n\n\tasync findDefsByIds(ids: string[]): Promise<DefRecord[]> {\n\t\tconst idSet = new Set(ids);\n\t\treturn this.defs.filter((d) => idSet.has(d.id));\n\t}\n\n\tasync findAnyDef(key: string): Promise<DefRecord | null> {\n\t\treturn this.latestVersion(key) ?? null;\n\t}\n\n\tasync listValues(query: ListValuesQuery): Promise<ListValuesResult> {\n\t\tconst now = new Date();\n\t\tconst active = this.values\n\t\t\t.filter(\n\t\t\t\t(v) =>\n\t\t\t\t\tv.scopeKind === query.scopeKind &&\n\t\t\t\t\tv.scopeRefId === query.scopeRefId &&\n\t\t\t\t\tv.validFrom <= now &&\n\t\t\t\t\t(v.validTo === null || v.validTo > now),\n\t\t\t)\n\t\t\t.sort((a, b) => a.id.localeCompare(b.id));\n\n\t\tconst startIndex = query.cursor\n\t\t\t? active.findIndex((v) => v.id === query.cursor) + 1\n\t\t\t: 0;\n\t\tconst limit = query.limit ?? active.length - startIndex;\n\t\tconst page = active.slice(startIndex, startIndex + limit);\n\t\tconst nextCursor =\n\t\t\tstartIndex + page.length < active.length\n\t\t\t\t? (page[page.length - 1]?.id ?? null)\n\t\t\t\t: null;\n\n\t\treturn { values: page, nextCursor };\n\t}\n\n\tasync findAudit(query: FindAuditQuery): Promise<AuditRecord[]> {\n\t\treturn this.auditLog\n\t\t\t.filter(\n\t\t\t\t(a) =>\n\t\t\t\t\ta.definitionId === query.definitionId &&\n\t\t\t\t\t(query.scopeKind === undefined ||\n\t\t\t\t\t\ta.scopeKind === query.scopeKind) &&\n\t\t\t\t\t(query.scopeRefId === undefined ||\n\t\t\t\t\t\ta.scopeRefId === query.scopeRefId),\n\t\t\t)\n\t\t\t.sort((a, b) => a.at.getTime() - b.at.getTime());\n\t}\n\n\tasync createDef(input: CreateDefInput): Promise<DefRecord> {\n\t\tconst existingVersions = this.defs.filter((d) => d.key === input.key);\n\t\tconst version =\n\t\t\texistingVersions.length > 0\n\t\t\t\t? Math.max(...existingVersions.map((d) => d.version)) + 1\n\t\t\t\t: 1;\n\t\tconst record: DefRecord = {\n\t\t\tid: this.newId('def'),\n\t\t\tkey: input.key,\n\t\t\tversion,\n\t\t\tlabel: input.label,\n\t\t\tdescription: input.description ?? null,\n\t\t\ttype: input.type,\n\t\t\toptions: input.options ?? [],\n\t\t\tmin: input.min ?? null,\n\t\t\tmax: input.max ?? null,\n\t\t\tscopes: input.scopes,\n\t\t\tinherit: input.inherit,\n\t\t\trequired: input.required,\n\t\t\tsecret: input.secret ?? false,\n\t\t\tstatus: input.status ?? 'DRAFT',\n\t\t\tcategory: input.category ?? null,\n\t\t};\n\t\tthis.defs.push(record);\n\t\treturn record;\n\t}\n\n\tasync updateDefStatus(key: string, status: Status): Promise<DefRecord> {\n\t\tconst current = this.latestVersion(key);\n\t\tif (!current) throw new NotFoundError(key);\n\n\t\tcurrent.status = status;\n\t\treturn current;\n\t}\n\n\tasync listDefs(status?: Status): Promise<DefRecord[]> {\n\t\tconst rows = status\n\t\t\t? this.defs.filter((d) => d.status === status)\n\t\t\t: this.defs;\n\t\treturn [...rows].sort(\n\t\t\t(a, b) =>\n\t\t\t\t(a.category ?? '').localeCompare(b.category ?? '') ||\n\t\t\t\ta.key.localeCompare(b.key),\n\t\t);\n\t}\n\n\tasync transact<T>(fn: (tx: StorageTx) => Promise<T>): Promise<T> {\n\t\tconst run = this.txQueue.then(() => fn(this.tx()));\n\t\tthis.txQueue = run.catch(() => {});\n\t\treturn run;\n\t}\n\n\tprivate latestByStatus(\n\t\tkey: string,\n\t\tstatuses: Status[],\n\t): DefRecord | undefined {\n\t\tconst latest = this.latestVersion(key);\n\t\treturn latest && statuses.includes(latest.status) ? latest : undefined;\n\t}\n\n\tprivate latestVersion(key: string): DefRecord | undefined {\n\t\treturn this.defs\n\t\t\t.filter((d) => d.key === key)\n\t\t\t.sort((a, b) => b.version - a.version)[0];\n\t}\n\n\tprivate tx(): StorageTx {\n\t\treturn {\n\t\t\tfindDef: async (key: string) =>\n\t\t\t\tthis.latestByStatus(key, ['STABLE']) ?? null,\n\n\t\t\tfindValue: async (definitionId, scopeKind, scopeRefId) =>\n\t\t\t\tthis.values.find(\n\t\t\t\t\t(v) =>\n\t\t\t\t\t\tv.definitionId === definitionId &&\n\t\t\t\t\t\tv.scopeKind === scopeKind &&\n\t\t\t\t\t\tv.scopeRefId === scopeRefId &&\n\t\t\t\t\t\tv.validTo === null,\n\t\t\t\t) ?? null,\n\n\t\t\tcloseValue: async (id: string) => {\n\t\t\t\tconst row = this.values.find((v) => v.id === id);\n\t\t\t\tif (row) row.validTo = new Date();\n\t\t\t},\n\n\t\t\tcreateValue: async (input: CreateValueInput) => {\n\t\t\t\tconst record: StoredValue = {\n\t\t\t\t\tid: this.newId('val'),\n\t\t\t\t\tdefinitionId: input.definitionId,\n\t\t\t\t\tscopeKind: input.scopeKind,\n\t\t\t\t\tscopeRefId: input.scopeRefId,\n\t\t\t\t\tversion: input.version,\n\t\t\t\t\tvalidFrom: new Date(),\n\t\t\t\t\tvalidTo: null,\n\t\t\t\t\t...toTypedColumns(input.type, input.value),\n\t\t\t\t};\n\t\t\t\tthis.values.push(record);\n\t\t\t\treturn record;\n\t\t\t},\n\n\t\t\tcreateAudit: async (input: CreateAuditInput): Promise<void> => {\n\t\t\t\tthis.auditLog.push({\n\t\t\t\t\t...input,\n\t\t\t\t\tid: this.newId('audit'),\n\t\t\t\t\tat: new Date(),\n\t\t\t\t});\n\t\t\t},\n\t\t};\n\t}\n}\n","import type {\n\tDefRecord,\n\tScope,\n\tScopeHierarchy,\n\tValue,\n\tValueRecord,\n} from '../core/types';\nimport { DEFAULT_SCOPE } from '../core/types';\nimport {\n\tCorruptError,\n\tRequiredError,\n\tScopeError,\n\tNotFoundError,\n} from '../core/errors';\nimport type { StorageReader } from '../storage/storage-port';\nimport type { Cache } from '../cache/cache';\n\nexport interface ListAtPage {\n\tentries: Record<string, Value>;\n\tnextCursor: string | null;\n}\n\nexport class Resolver {\n\tconstructor(\n\t\tprivate readonly storage: StorageReader,\n\t\tprivate readonly hierarchy?: ScopeHierarchy,\n\t\tprivate readonly cache?: Cache,\n\t) {}\n\n\tasync get(key: string, scope: Scope, asOf?: Date): Promise<Value> {\n\t\tconst result = await this.getMany([key], scope, asOf);\n\t\treturn result[key];\n\t}\n\n\tasync listAt(\n\t\tscope: Scope,\n\t\topts: { limit?: number; cursor?: string } = {},\n\t): Promise<ListAtPage> {\n\t\tconst { values, nextCursor } = await this.storage.listValues({\n\t\t\tscopeKind: scope.kind,\n\t\t\tscopeRefId: scope.refId,\n\t\t\tlimit: opts.limit,\n\t\t\tcursor: opts.cursor,\n\t\t});\n\t\tif (values.length === 0) return { entries: {}, nextCursor };\n\n\t\tconst defs = await this.storage.findDefsByIds([\n\t\t\t...new Set(values.map((v) => v.definitionId)),\n\t\t]);\n\t\tconst defById = new Map(defs.map((d) => [d.id, d]));\n\n\t\tconst entries: Record<string, Value> = {};\n\t\tfor (const row of values) {\n\t\t\tconst def = defById.get(row.definitionId);\n\t\t\tif (!def) continue;\n\t\t\tentries[def.key] = this.unwrap(def, row);\n\t\t}\n\t\treturn { entries, nextCursor };\n\t}\n\n\tasync getMany(\n\t\tkeys: string[],\n\t\tscope: Scope,\n\t\tasOf?: Date,\n\t): Promise<Record<string, Value>> {\n\t\tconst uniqueKeys = [...new Set(keys)];\n\t\tconst result: Record<string, Value> = {};\n\t\tconst uncached: string[] = [];\n\n\t\tif (asOf === undefined) {\n\t\t\tfor (const key of uniqueKeys) {\n\t\t\t\tconst cached = this.cache?.get(key, scope);\n\t\t\t\tif (cached !== undefined) result[key] = cached;\n\t\t\t\telse uncached.push(key);\n\t\t\t}\n\t\t} else {\n\t\t\tuncached.push(...uniqueKeys);\n\t\t}\n\t\tif (uncached.length === 0) return result;\n\n\t\tconst defByKey = await this.getDefs(uncached);\n\t\tfor (const key of uncached) {\n\t\t\tthis.checkScope(defByKey.get(key)!, scope);\n\t\t}\n\n\t\tconst exactDefs: DefRecord[] = [];\n\t\tconst chainDefs: DefRecord[] = [];\n\t\tfor (const key of uncached) {\n\t\t\tconst def = defByKey.get(key)!;\n\t\t\tconst climbsHierarchy =\n\t\t\t\tdef.inherit !== 'INDEPENDENT' &&\n\t\t\t\tscope.refId !== null &&\n\t\t\t\tthis.hierarchy;\n\t\t\t(climbsHierarchy ? chainDefs : exactDefs).push(def);\n\t\t}\n\n\t\tconst chain =\n\t\t\tchainDefs.length > 0 && scope.refId !== null && this.hierarchy\n\t\t\t\t? await this.hierarchy.chain(scope.refId)\n\t\t\t\t: [];\n\n\t\tconst [exactRows, chainRows] = await Promise.all([\n\t\t\texactDefs.length > 0\n\t\t\t\t? this.storage.findValues({\n\t\t\t\t\t\tdefinitionIds: exactDefs.map((d) => d.id),\n\t\t\t\t\t\tscopeKind: scope.kind,\n\t\t\t\t\t\tscopeRefId: scope.refId,\n\t\t\t\t\t\tasOf,\n\t\t\t\t\t})\n\t\t\t\t: Promise.resolve([] as ValueRecord[]),\n\t\t\tchainDefs.length > 0 && chain.length > 0\n\t\t\t\t? this.storage.findChainValues({\n\t\t\t\t\t\tdefinitionIds: chainDefs.map((d) => d.id),\n\t\t\t\t\t\tchain,\n\t\t\t\t\t\tasOf,\n\t\t\t\t\t})\n\t\t\t\t: Promise.resolve([] as ValueRecord[]),\n\t\t]);\n\n\t\tconst exactByDef = new Map(exactRows.map((r) => [r.definitionId, r]));\n\t\tconst chainByDef = new Map<string, ValueRecord[]>();\n\t\tfor (const row of chainRows) {\n\t\t\tconst list = chainByDef.get(row.definitionId) ?? [];\n\t\t\tlist.push(row);\n\t\t\tchainByDef.set(row.definitionId, list);\n\t\t}\n\t\tconst chainDefIds = new Set(chainDefs.map((d) => d.id));\n\n\t\tconst missing: DefRecord[] = [];\n\t\tfor (const key of uncached) {\n\t\t\tconst def = defByKey.get(key)!;\n\t\t\tlet row: ValueRecord | undefined;\n\t\t\tif (chainDefIds.has(def.id)) {\n\t\t\t\tconst byRef = new Map(\n\t\t\t\t\t(chainByDef.get(def.id) ?? []).map((v) => [\n\t\t\t\t\t\tv.scopeRefId,\n\t\t\t\t\t\tv,\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t\tfor (const ref of chain) {\n\t\t\t\t\trow = byRef.get(ref);\n\t\t\t\t\tif (row) break;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\trow = exactByDef.get(def.id);\n\t\t\t}\n\t\t\tif (row) {\n\t\t\t\tresult[key] = this.unwrap(def, row);\n\t\t\t\tif (asOf === undefined)\n\t\t\t\t\tthis.cache?.set(key, scope, result[key]);\n\t\t\t} else {\n\t\t\t\tmissing.push(def);\n\t\t\t}\n\t\t}\n\n\t\tif (missing.length > 0)\n\t\t\tawait this.resolveMissing(\n\t\t\t\tmissing,\n\t\t\t\tscope,\n\t\t\t\tuncached,\n\t\t\t\tdefByKey,\n\t\t\t\tresult,\n\t\t\t\tasOf,\n\t\t\t);\n\n\t\treturn result;\n\t}\n\n\tprivate async resolveMissing(\n\t\tmissing: DefRecord[],\n\t\tscope: Scope,\n\t\tkeysInOrder: string[],\n\t\tdefByKey: Map<string, DefRecord>,\n\t\tresult: Record<string, Value>,\n\t\tasOf?: Date,\n\t): Promise<void> {\n\t\tconst defaultRows = await this.storage.findValues({\n\t\t\tdefinitionIds: missing.map((d) => d.id),\n\t\t\tscopeKind: DEFAULT_SCOPE.kind,\n\t\t\tscopeRefId: DEFAULT_SCOPE.refId,\n\t\t});\n\t\tconst defaultByDef = new Map(\n\t\t\tdefaultRows.map((r) => [r.definitionId, r]),\n\t\t);\n\t\tconst missingIds = new Set(missing.map((d) => d.id));\n\n\t\tfor (const key of keysInOrder) {\n\t\t\tconst def = defByKey.get(key)!;\n\t\t\tif (!missingIds.has(def.id)) continue;\n\t\t\tconst row = defaultByDef.get(def.id);\n\t\t\tif (!row) {\n\t\t\t\tthrow new RequiredError(def.key, scope.kind, scope.refId);\n\t\t\t}\n\t\t\tresult[key] = this.unwrap(def, row);\n\t\t\tif (asOf === undefined) this.cache?.set(key, scope, result[key]);\n\t\t}\n\t}\n\n\tprivate async getDefs(keys: string[]): Promise<Map<string, DefRecord>> {\n\t\tconst defs = await this.storage.findDefs(keys);\n\t\tconst byKey = new Map(defs.map((d) => [d.key, d]));\n\t\tfor (const key of keys) {\n\t\t\tif (!byKey.has(key)) throw new NotFoundError(key);\n\t\t}\n\t\treturn byKey;\n\t}\n\n\tprivate checkScope(def: DefRecord, scope: Scope): void {\n\t\tif (scope.kind === 'default') return;\n\t\tif (!def.scopes.includes(scope.kind)) {\n\t\t\tthrow new ScopeError(def.key, scope.kind);\n\t\t}\n\t}\n\n\tprivate unwrap(def: DefRecord, row: ValueRecord): Value {\n\t\tswitch (def.type) {\n\t\t\tcase 'BOOLEAN':\n\t\t\t\tif (row.bool === null) throw new CorruptError(row.id);\n\t\t\t\treturn row.bool;\n\t\t\tcase 'NUMERIC':\n\t\t\t\tif (row.num === null) throw new CorruptError(row.id);\n\t\t\t\treturn row.num;\n\t\t\tcase 'TEXT':\n\t\t\tcase 'ENUM':\n\t\t\t\tif (row.text === null) throw new CorruptError(row.id);\n\t\t\t\treturn row.text;\n\t\t\tcase 'JSON':\n\t\t\t\tif (!row.jsonSet) throw new CorruptError(row.id);\n\t\t\t\treturn row.json as Value;\n\t\t\tcase 'DATE':\n\t\t\t\tif (row.date === null) throw new CorruptError(row.id);\n\t\t\t\treturn row.date;\n\t\t}\n\t}\n}\n","import type { DefRecord, Scope, Value, ValueRecord } from '../core/types';\nimport {\n\tConflictError,\n\tScopeError,\n\tValueError,\n\tNotFoundError,\n} from '../core/errors';\nimport type { StorageAdapter, StorageTx } from '../storage/storage-port';\nimport type { ChangeBus } from '../cache/change-bus';\n\nexport interface SetParams {\n\tkey: string;\n\tscope: Scope;\n\tvalue: Value;\n\texpectedVersion?: number;\n\tauthorId: string;\n\treason?: string;\n}\n\nexport interface UnsetParams {\n\tkey: string;\n\tscope: Scope;\n\texpectedVersion?: number;\n\tauthorId: string;\n\treason?: string;\n}\n\nconst REDACTED = '[redacted]';\n\nexport class Writer {\n\tconstructor(\n\t\tprivate readonly storage: StorageAdapter,\n\t\tprivate readonly bus?: ChangeBus,\n\t) {}\n\n\tasync set(params: SetParams): Promise<ValueRecord> {\n\t\tconst created = await this.storage.transact((tx) =>\n\t\t\tthis.setInTx(tx, params),\n\t\t);\n\t\tawait this.emit(created, params.key);\n\t\treturn created;\n\t}\n\n\tasync setMany(paramsList: SetParams[]): Promise<ValueRecord[]> {\n\t\tconst created = await this.storage.transact(async (tx) => {\n\t\t\tconst results: ValueRecord[] = [];\n\t\t\tfor (const params of paramsList) {\n\t\t\t\tresults.push(await this.setInTx(tx, params));\n\t\t\t}\n\t\t\treturn results;\n\t\t});\n\t\tawait Promise.all(\n\t\t\tcreated.map((row, i) => this.emit(row, paramsList[i].key)),\n\t\t);\n\t\treturn created;\n\t}\n\n\tprivate async setInTx(\n\t\ttx: StorageTx,\n\t\tparams: SetParams,\n\t): Promise<ValueRecord> {\n\t\tconst def = await tx.findDef(params.key);\n\t\tif (!def) throw new NotFoundError(params.key);\n\n\t\tif (\n\t\t\tparams.scope.kind !== 'default' &&\n\t\t\t!def.scopes.includes(params.scope.kind)\n\t\t) {\n\t\t\tthrow new ScopeError(def.key, params.scope.kind);\n\t\t}\n\n\t\tthis.validate(def, params.value);\n\n\t\tconst current = await tx.findValue(\n\t\t\tdef.id,\n\t\t\tparams.scope.kind,\n\t\t\tparams.scope.refId,\n\t\t);\n\n\t\tconst currentVersion = current?.version ?? 0;\n\t\tconst expected = params.expectedVersion ?? 0;\n\t\tif (currentVersion !== expected) {\n\t\t\tthrow new ConflictError(\n\t\t\t\tdef.key,\n\t\t\t\tparams.scope.kind,\n\t\t\t\tparams.scope.refId,\n\t\t\t);\n\t\t}\n\n\t\tif (current) {\n\t\t\tawait tx.closeValue(current.id);\n\t\t}\n\n\t\tconst created = await tx.createValue({\n\t\t\tdefinitionId: def.id,\n\t\t\tscopeKind: params.scope.kind,\n\t\t\tscopeRefId: params.scope.refId,\n\t\t\tversion: currentVersion + 1,\n\t\t\tauthorId: params.authorId,\n\t\t\treason: params.reason,\n\t\t\ttype: def.type,\n\t\t\tvalue: params.value,\n\t\t});\n\n\t\tawait tx.createAudit({\n\t\t\tvalueId: created.id,\n\t\t\tdefinitionId: def.id,\n\t\t\tscopeKind: created.scopeKind,\n\t\t\tscopeRefId: created.scopeRefId,\n\t\t\taction: current ? 'superseded' : 'created',\n\t\t\tauthorId: params.authorId,\n\t\t\tbefore: current ? this.snapshotOf(def, current) : undefined,\n\t\t\tafter: this.snapshotOf(def, created),\n\t\t\treason: params.reason,\n\t\t});\n\n\t\treturn created;\n\t}\n\n\tasync unset(params: UnsetParams): Promise<void> {\n\t\tconst closed = await this.storage.transact((tx) =>\n\t\t\tthis.unsetInTx(tx, params),\n\t\t);\n\t\tif (closed) await this.emit(closed, params.key);\n\t}\n\n\tprivate async unsetInTx(\n\t\ttx: StorageTx,\n\t\tparams: UnsetParams,\n\t): Promise<ValueRecord | null> {\n\t\tconst def = await tx.findDef(params.key);\n\t\tif (!def) throw new NotFoundError(params.key);\n\n\t\tif (\n\t\t\tparams.scope.kind !== 'default' &&\n\t\t\t!def.scopes.includes(params.scope.kind)\n\t\t) {\n\t\t\tthrow new ScopeError(def.key, params.scope.kind);\n\t\t}\n\n\t\tconst current = await tx.findValue(\n\t\t\tdef.id,\n\t\t\tparams.scope.kind,\n\t\t\tparams.scope.refId,\n\t\t);\n\n\t\tconst currentVersion = current?.version ?? 0;\n\t\tconst expected = params.expectedVersion ?? 0;\n\t\tif (currentVersion !== expected) {\n\t\t\tthrow new ConflictError(\n\t\t\t\tdef.key,\n\t\t\t\tparams.scope.kind,\n\t\t\t\tparams.scope.refId,\n\t\t\t);\n\t\t}\n\t\tif (!current) return null;\n\n\t\tawait tx.closeValue(current.id);\n\t\tawait tx.createAudit({\n\t\t\tvalueId: current.id,\n\t\t\tdefinitionId: def.id,\n\t\t\tscopeKind: current.scopeKind,\n\t\t\tscopeRefId: current.scopeRefId,\n\t\t\taction: 'unset',\n\t\t\tauthorId: params.authorId,\n\t\t\tbefore: this.snapshotOf(def, current),\n\t\t\treason: params.reason,\n\t\t});\n\n\t\treturn current;\n\t}\n\n\tprivate async emit(created: ValueRecord, key: string): Promise<void> {\n\t\tawait this.bus?.publish({\n\t\t\tdefinitionId: created.definitionId,\n\t\t\tkey,\n\t\t\tscopeKind: created.scopeKind,\n\t\t\tscopeRefId: created.scopeRefId,\n\t\t});\n\t}\n\n\tprivate validate(def: DefRecord, value: Value): void {\n\t\tswitch (def.type) {\n\t\t\tcase 'BOOLEAN':\n\t\t\t\tif (typeof value !== 'boolean') {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" expects a boolean`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'NUMERIC': {\n\t\t\t\tif (typeof value !== 'number' || !Number.isFinite(value)) {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" expects a finite number`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (def.min !== null && value < def.min) {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" must be >= ${def.min}, got ${value}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (def.max !== null && value > def.max) {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" must be <= ${def.max}, got ${value}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'TEXT':\n\t\t\t\tif (typeof value !== 'string') {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" expects a string`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'ENUM':\n\t\t\t\tif (typeof value !== 'string' || !def.options.includes(value)) {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" must be one of: ${def.options.join(', ')}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'JSON':\n\t\t\t\ttry {\n\t\t\t\t\tJSON.stringify(value);\n\t\t\t\t} catch {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" expects a JSON-serializable value`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'DATE':\n\t\t\t\tif (!(value instanceof Date) || Number.isNaN(value.getTime())) {\n\t\t\t\t\tthrow new ValueError(\n\t\t\t\t\t\t`Setting \"${def.key}\" expects a valid Date`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate snapshotOf(def: DefRecord, row: ValueRecord) {\n\t\tif (def.secret) {\n\t\t\treturn {\n\t\t\t\tscopeKind: row.scopeKind,\n\t\t\t\tscopeRefId: row.scopeRefId,\n\t\t\t\tversion: row.version,\n\t\t\t\tvalue: REDACTED,\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tscopeKind: row.scopeKind,\n\t\t\tscopeRefId: row.scopeRefId,\n\t\t\tversion: row.version,\n\t\t\tbool: row.bool,\n\t\t\tnum: row.num,\n\t\t\ttext: row.text,\n\t\t\tjson: row.jsonSet ? row.json : undefined,\n\t\t\tdate: row.date,\n\t\t};\n\t}\n}\n","import type { Scope } from '../core/types';\nimport { NotFoundError } from '../core/errors';\nimport type { AuditRecord, StorageReader } from '../storage/storage-port';\n\nexport class Auditor {\n\tconstructor(private readonly storage: StorageReader) {}\n\n\tasync history(key: string, scope?: Scope): Promise<AuditRecord[]> {\n\t\tconst def = await this.storage.findAnyDef(key);\n\t\tif (!def) throw new NotFoundError(key);\n\n\t\treturn this.storage.findAudit({\n\t\t\tdefinitionId: def.id,\n\t\t\tscopeKind: scope?.kind,\n\t\t\tscopeRefId: scope?.refId,\n\t\t});\n\t}\n}\n","import type { Cache } from '../cache/cache';\nimport type { ScopeHierarchy } from '../core/types';\n\nexport function withHierarchyInvalidation(\n\thierarchy: ScopeHierarchy,\n\tcache: Cache,\n): ScopeHierarchy {\n\treturn {\n\t\tchain: (id) => hierarchy.chain(id),\n\t\tdescendants: (id) => hierarchy.descendants(id),\n\t\tchildren: (id) => hierarchy.children(id),\n\t\tparent: (id) => hierarchy.parent(id),\n\t\tattach: async (id, parentId) => {\n\t\t\tawait hierarchy.attach(id, parentId);\n\t\t\tcache.dropForScopes(await hierarchy.descendants(id));\n\t\t},\n\t\tmove: async (id, newParentId) => {\n\t\t\tconst descendants = await hierarchy.descendants(id);\n\t\t\tawait hierarchy.move(id, newParentId);\n\t\t\tcache.dropForScopes(descendants);\n\t\t},\n\t\tdetach: async (id) => {\n\t\t\tconst descendants = await hierarchy.descendants(id);\n\t\t\tawait hierarchy.detach(id);\n\t\t\tcache.dropForScopes(descendants);\n\t\t},\n\t};\n}\n","import type { ChangeBus } from '../cache/change-bus';\nimport { LocalBus } from '../cache/change-bus';\nimport type { CacheOptions } from '../cache/cache';\nimport { Cache } from '../cache/cache';\nimport { withHierarchyInvalidation } from './hierarchy-cache-sync';\nimport { MemoryStorageAdapter } from '../storage/memory-storage';\nimport { Resolver } from './resolver';\nimport { LocalScopeHierarchy } from '../hierarchy/scope-hierarchy';\nimport type { StorageAdapter } from '../storage/storage-port';\nimport type { ScopeHierarchy } from '../core/types';\nimport { Writer } from './writer';\nimport { Auditor } from './auditor';\n\nexport interface EngineOptions {\n\tstorage?: StorageAdapter;\n\thierarchy?: ScopeHierarchy;\n\tbus?: ChangeBus;\n\tcache?: CacheOptions | false;\n}\n\nexport interface Engine {\n\tstorage: StorageAdapter;\n\thierarchy: ScopeHierarchy;\n\tbus: ChangeBus;\n\tcache: Cache;\n\tresolver: Resolver;\n\twriter: Writer;\n\tauditor: Auditor;\n}\n\nexport function createEngine(options: EngineOptions = {}): Engine {\n\tconst storage = options.storage ?? new MemoryStorageAdapter();\n\tconst rawHierarchy = options.hierarchy ?? new LocalScopeHierarchy();\n\tconst bus = options.bus ?? new LocalBus();\n\tconst cacheOptions =\n\t\toptions.cache === false ? { enabled: false } : (options.cache ?? {});\n\tconst cache = new Cache(bus, cacheOptions, rawHierarchy);\n\tconst hierarchy = withHierarchyInvalidation(rawHierarchy, cache);\n\tconst resolver = new Resolver(storage, hierarchy, cache);\n\tconst writer = new Writer(storage, bus);\n\tconst auditor = new Auditor(storage);\n\treturn { storage, hierarchy, bus, cache, resolver, writer, auditor };\n}\n","import type { Scope } from '../core/types';\nimport type { Resolver } from '../engine/resolver';\nimport type { SettingScopeKind, SettingValue } from './registry';\n\nexport class TypedResolver<Registry> {\n\tconstructor(private readonly resolver: Resolver) {}\n\n\tget<K extends keyof Registry & string>(\n\t\tkey: K,\n\t\tscope: Scope & { kind: SettingScopeKind<Registry, K> },\n\t\tasOf?: Date,\n\t): Promise<SettingValue<Registry, K>> {\n\t\treturn this.resolver.get(key, scope, asOf) as Promise<\n\t\t\tSettingValue<Registry, K>\n\t\t>;\n\t}\n\n\tasync getMany<K extends readonly (keyof Registry & string)[]>(\n\t\tkeys: K,\n\t\tscope: Scope,\n\t\tasOf?: Date,\n\t): Promise<{ [P in K[number]]: SettingValue<Registry, P> }> {\n\t\tconst result = await this.resolver.getMany([...keys], scope, asOf);\n\t\treturn result as { [P in K[number]]: SettingValue<Registry, P> };\n\t}\n\n\tasync listAt(\n\t\tscope: Scope,\n\t\topts: { limit?: number; cursor?: string } = {},\n\t): Promise<{\n\t\tentries: Partial<{\n\t\t\t[K in keyof Registry & string]: SettingValue<Registry, K>;\n\t\t}>;\n\t\tnextCursor: string | null;\n\t}> {\n\t\tconst page = await this.resolver.listAt(scope, opts);\n\t\treturn page as {\n\t\t\tentries: Partial<{\n\t\t\t\t[K in keyof Registry & string]: SettingValue<Registry, K>;\n\t\t\t}>;\n\t\t\tnextCursor: string | null;\n\t\t};\n\t}\n}\n","import type { Scope, ValueRecord } from '../core/types';\nimport type { SetParams, Writer } from '../engine/writer';\nimport type { SettingScopeKind, SettingValue } from './registry';\n\nexport interface TypedSetParams<Registry, K extends keyof Registry & string> {\n\tkey: K;\n\tscope: Scope & { kind: SettingScopeKind<Registry, K> };\n\tvalue: SettingValue<Registry, K>;\n\texpectedVersion?: number;\n\tauthorId: string;\n\treason?: string;\n}\n\nexport interface TypedUnsetParams<Registry, K extends keyof Registry & string> {\n\tkey: K;\n\tscope: Scope & { kind: SettingScopeKind<Registry, K> };\n\texpectedVersion?: number;\n\tauthorId: string;\n\treason?: string;\n}\n\nexport class TypedWriter<Registry> {\n\tconstructor(private readonly writer: Writer) {}\n\n\tset<K extends keyof Registry & string>(\n\t\tparams: TypedSetParams<Registry, K>,\n\t): Promise<ValueRecord> {\n\t\treturn this.writer.set(params as unknown as SetParams);\n\t}\n\n\tsetMany(\n\t\tparamsList: {\n\t\t\t[K in keyof Registry & string]: TypedSetParams<Registry, K>;\n\t\t}[keyof Registry & string][],\n\t): Promise<ValueRecord[]> {\n\t\treturn this.writer.setMany(paramsList as unknown as SetParams[]);\n\t}\n\n\tunset<K extends keyof Registry & string>(\n\t\tparams: TypedUnsetParams<Registry, K>,\n\t): Promise<void> {\n\t\treturn this.writer.unset(params);\n\t}\n}\n","import type { Scope } from '../core/types';\nimport type { Auditor } from '../engine/auditor';\nimport type { AuditRecord } from '../storage/storage-port';\nimport type { SettingScopeKind } from './registry';\n\nexport class TypedAuditor<Registry> {\n\tconstructor(private readonly auditor: Auditor) {}\n\n\thistory<K extends keyof Registry & string>(\n\t\tkey: K,\n\t\tscope?: Scope & { kind: SettingScopeKind<Registry, K> },\n\t): Promise<AuditRecord[]> {\n\t\treturn this.auditor.history(key, scope);\n\t}\n}\n","import type { Engine } from '../engine/engine';\nimport { TypedResolver } from './typed-resolver';\nimport { TypedWriter } from './typed-writer';\nimport { TypedAuditor } from './typed-auditor';\n\nexport interface TypedEngine<Registry> {\n\tresolver: TypedResolver<Registry>;\n\twriter: TypedWriter<Registry>;\n\tauditor: TypedAuditor<Registry>;\n}\n\nexport function createTypedEngine<Registry>(\n\tengine: Engine,\n): TypedEngine<Registry> {\n\treturn {\n\t\tresolver: new TypedResolver<Registry>(engine.resolver),\n\t\twriter: new TypedWriter<Registry>(engine.writer),\n\t\tauditor: new TypedAuditor<Registry>(engine.auditor),\n\t};\n}\n"],"mappings":";AAeO,IAAM,gBAAuB,EAAE,MA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G1C;AAAA,EAEA,MAAM,QACL,MACA,OACA,MAC2D;AAC3D,UAAM,SAAS,MAAM,KAAK,SAAS,QAAQ,CAAC,GAAG,IAAI,GAAG,OAAO,IAAI;AACjE,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,OACL,OACA,OAA4C,CAAC,GAM3C;AACF,UAAM,OAAO,MAAM,KAAK,SAAS,OAAO,OAAO,IAAI;AACnD,WAAO;AAAA,EAMR;AACD;;;ACtBO,IAAM,cAAN,MAA4B;AAAA,EAClC,YAA6B,QAAgB;AAAhB;AAAA,EAAiB;AAAA,EAAjB;AAAA,EAE7B,IACC,QACuB;AACvB,WAAO,KAAK,OAAO,IAAI,MAA8B;AAAA,EACtD;AAAA,EAEA,QACC,YAGyB;AACzB,WAAO,KAAK,OAAO,QAAQ,UAAoC;AAAA,EAChE;AAAA,EAEA,MACC,QACgB;AAChB,WAAO,KAAK,OAAO,MAAM,MAAM;AAAA,EAChC;AACD;;;ACtCO,IAAM,eAAN,MAA6B;AAAA,EACnC,YAA6B,SAAkB;AAAlB;AAAA,EAAmB;AAAA,EAAnB;AAAA,EAE7B,QACC,KACA,OACyB;AACzB,WAAO,KAAK,QAAQ,QAAQ,KAAK,KAAK;AAAA,EACvC;AACD;;;ACHO,SAAS,kBACf,QACwB;AACxB,SAAO;AAAA,IACN,UAAU,IAAI,cAAwB,OAAO,QAAQ;AAAA,IACrD,QAAQ,IAAI,YAAsB,OAAO,MAAM;AAAA,IAC/C,SAAS,IAAI,aAAuB,OAAO,OAAO;AAAA,EACnD;AACD;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuditRecord, CreateDefInput, FindAuditQuery, FindChainQuery, FindValuesQuery, ListValuesQuery, ListValuesResult, StorageAdapter, StorageTx } from './storage-port';
|
|
2
|
+
import type { DefRecord, Status, ValueRecord } from '../core/types';
|
|
3
|
+
export declare class MemoryStorageAdapter implements StorageAdapter {
|
|
4
|
+
private defs;
|
|
5
|
+
private values;
|
|
6
|
+
private auditLog;
|
|
7
|
+
private nextId;
|
|
8
|
+
private txQueue;
|
|
9
|
+
private newId;
|
|
10
|
+
findDefs(keys: string[]): Promise<DefRecord[]>;
|
|
11
|
+
findValues(query: FindValuesQuery): Promise<ValueRecord[]>;
|
|
12
|
+
findChainValues(query: FindChainQuery): Promise<ValueRecord[]>;
|
|
13
|
+
findDefsByIds(ids: string[]): Promise<DefRecord[]>;
|
|
14
|
+
findAnyDef(key: string): Promise<DefRecord | null>;
|
|
15
|
+
listValues(query: ListValuesQuery): Promise<ListValuesResult>;
|
|
16
|
+
findAudit(query: FindAuditQuery): Promise<AuditRecord[]>;
|
|
17
|
+
createDef(input: CreateDefInput): Promise<DefRecord>;
|
|
18
|
+
updateDefStatus(key: string, status: Status): Promise<DefRecord>;
|
|
19
|
+
listDefs(status?: Status): Promise<DefRecord[]>;
|
|
20
|
+
transact<T>(fn: (tx: StorageTx) => Promise<T>): Promise<T>;
|
|
21
|
+
private latestByStatus;
|
|
22
|
+
private latestVersion;
|
|
23
|
+
private tx;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=memory-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-storage.d.ts","sourceRoot":"","sources":["../../src/storage/memory-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,WAAW,EAEX,cAAc,EAEd,cAAc,EACd,cAAc,EACd,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EACX,SAAS,EACT,MAAM,EAEN,WAAW,EAEX,MAAM,eAAe,CAAC;AAmBvB,qBAAa,oBAAqB,YAAW,cAAc;IAC1D,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAAuC;IAEtD,OAAO,CAAC,KAAK;IAIP,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAS9C,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAa1D,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAc9D,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAKlD,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAIlD,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyB7D,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAaxD,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;IA2BpD,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAQhE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAW/C,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAMhE,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,EAAE;CA2CV"}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryStorageAdapter = void 0;
|
|
4
|
+
const errors_1 = require("../core/errors");
|
|
5
|
+
function toTypedColumns(type, value) {
|
|
6
|
+
return {
|
|
7
|
+
bool: type === 'BOOLEAN' ? value : null,
|
|
8
|
+
num: type === 'NUMERIC' ? value : null,
|
|
9
|
+
text: type === 'TEXT' || type === 'ENUM' ? value : null,
|
|
10
|
+
json: type === 'JSON' ? value : null,
|
|
11
|
+
jsonSet: type === 'JSON',
|
|
12
|
+
date: type === 'DATE' ? value : null,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
class MemoryStorageAdapter {
|
|
16
|
+
defs = [];
|
|
17
|
+
values = [];
|
|
18
|
+
auditLog = [];
|
|
19
|
+
nextId = 1;
|
|
20
|
+
txQueue = Promise.resolve();
|
|
21
|
+
newId(prefix) {
|
|
22
|
+
return `${prefix}-${this.nextId++}`;
|
|
23
|
+
}
|
|
24
|
+
async findDefs(keys) {
|
|
25
|
+
const result = [];
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
const found = this.latestByStatus(key, ['STABLE', 'DEPRECATED']);
|
|
28
|
+
if (found)
|
|
29
|
+
result.push(found);
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async findValues(query) {
|
|
34
|
+
const asOf = query.asOf ?? new Date();
|
|
35
|
+
const ids = new Set(query.definitionIds);
|
|
36
|
+
return this.values.filter((v) => ids.has(v.definitionId) &&
|
|
37
|
+
v.scopeKind === query.scopeKind &&
|
|
38
|
+
v.scopeRefId === query.scopeRefId &&
|
|
39
|
+
v.validFrom <= asOf &&
|
|
40
|
+
(v.validTo === null || v.validTo > asOf));
|
|
41
|
+
}
|
|
42
|
+
async findChainValues(query) {
|
|
43
|
+
const asOf = query.asOf ?? new Date();
|
|
44
|
+
const defIds = new Set(query.definitionIds);
|
|
45
|
+
const refIds = new Set(query.chain);
|
|
46
|
+
return this.values.filter((v) => defIds.has(v.definitionId) &&
|
|
47
|
+
v.scopeRefId !== null &&
|
|
48
|
+
refIds.has(v.scopeRefId) &&
|
|
49
|
+
v.validFrom <= asOf &&
|
|
50
|
+
(v.validTo === null || v.validTo > asOf));
|
|
51
|
+
}
|
|
52
|
+
async findDefsByIds(ids) {
|
|
53
|
+
const idSet = new Set(ids);
|
|
54
|
+
return this.defs.filter((d) => idSet.has(d.id));
|
|
55
|
+
}
|
|
56
|
+
async findAnyDef(key) {
|
|
57
|
+
return this.latestVersion(key) ?? null;
|
|
58
|
+
}
|
|
59
|
+
async listValues(query) {
|
|
60
|
+
const now = new Date();
|
|
61
|
+
const active = this.values
|
|
62
|
+
.filter((v) => v.scopeKind === query.scopeKind &&
|
|
63
|
+
v.scopeRefId === query.scopeRefId &&
|
|
64
|
+
v.validFrom <= now &&
|
|
65
|
+
(v.validTo === null || v.validTo > now))
|
|
66
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
67
|
+
const startIndex = query.cursor
|
|
68
|
+
? active.findIndex((v) => v.id === query.cursor) + 1
|
|
69
|
+
: 0;
|
|
70
|
+
const limit = query.limit ?? active.length - startIndex;
|
|
71
|
+
const page = active.slice(startIndex, startIndex + limit);
|
|
72
|
+
const nextCursor = startIndex + page.length < active.length
|
|
73
|
+
? (page[page.length - 1]?.id ?? null)
|
|
74
|
+
: null;
|
|
75
|
+
return { values: page, nextCursor };
|
|
76
|
+
}
|
|
77
|
+
async findAudit(query) {
|
|
78
|
+
return this.auditLog
|
|
79
|
+
.filter((a) => a.definitionId === query.definitionId &&
|
|
80
|
+
(query.scopeKind === undefined ||
|
|
81
|
+
a.scopeKind === query.scopeKind) &&
|
|
82
|
+
(query.scopeRefId === undefined ||
|
|
83
|
+
a.scopeRefId === query.scopeRefId))
|
|
84
|
+
.sort((a, b) => a.at.getTime() - b.at.getTime());
|
|
85
|
+
}
|
|
86
|
+
async createDef(input) {
|
|
87
|
+
const existingVersions = this.defs.filter((d) => d.key === input.key);
|
|
88
|
+
const version = existingVersions.length > 0
|
|
89
|
+
? Math.max(...existingVersions.map((d) => d.version)) + 1
|
|
90
|
+
: 1;
|
|
91
|
+
const record = {
|
|
92
|
+
id: this.newId('def'),
|
|
93
|
+
key: input.key,
|
|
94
|
+
version,
|
|
95
|
+
label: input.label,
|
|
96
|
+
description: input.description ?? null,
|
|
97
|
+
type: input.type,
|
|
98
|
+
options: input.options ?? [],
|
|
99
|
+
min: input.min ?? null,
|
|
100
|
+
max: input.max ?? null,
|
|
101
|
+
scopes: input.scopes,
|
|
102
|
+
inherit: input.inherit,
|
|
103
|
+
required: input.required,
|
|
104
|
+
secret: input.secret ?? false,
|
|
105
|
+
status: input.status ?? 'DRAFT',
|
|
106
|
+
category: input.category ?? null,
|
|
107
|
+
};
|
|
108
|
+
this.defs.push(record);
|
|
109
|
+
return record;
|
|
110
|
+
}
|
|
111
|
+
async updateDefStatus(key, status) {
|
|
112
|
+
const current = this.latestVersion(key);
|
|
113
|
+
if (!current)
|
|
114
|
+
throw new errors_1.NotFoundError(key);
|
|
115
|
+
current.status = status;
|
|
116
|
+
return current;
|
|
117
|
+
}
|
|
118
|
+
async listDefs(status) {
|
|
119
|
+
const rows = status
|
|
120
|
+
? this.defs.filter((d) => d.status === status)
|
|
121
|
+
: this.defs;
|
|
122
|
+
return [...rows].sort((a, b) => (a.category ?? '').localeCompare(b.category ?? '') ||
|
|
123
|
+
a.key.localeCompare(b.key));
|
|
124
|
+
}
|
|
125
|
+
async transact(fn) {
|
|
126
|
+
const run = this.txQueue.then(() => fn(this.tx()));
|
|
127
|
+
this.txQueue = run.catch(() => { });
|
|
128
|
+
return run;
|
|
129
|
+
}
|
|
130
|
+
latestByStatus(key, statuses) {
|
|
131
|
+
const latest = this.latestVersion(key);
|
|
132
|
+
return latest && statuses.includes(latest.status) ? latest : undefined;
|
|
133
|
+
}
|
|
134
|
+
latestVersion(key) {
|
|
135
|
+
return this.defs
|
|
136
|
+
.filter((d) => d.key === key)
|
|
137
|
+
.sort((a, b) => b.version - a.version)[0];
|
|
138
|
+
}
|
|
139
|
+
tx() {
|
|
140
|
+
return {
|
|
141
|
+
findDef: async (key) => this.latestByStatus(key, ['STABLE']) ?? null,
|
|
142
|
+
findValue: async (definitionId, scopeKind, scopeRefId) => this.values.find((v) => v.definitionId === definitionId &&
|
|
143
|
+
v.scopeKind === scopeKind &&
|
|
144
|
+
v.scopeRefId === scopeRefId &&
|
|
145
|
+
v.validTo === null) ?? null,
|
|
146
|
+
closeValue: async (id) => {
|
|
147
|
+
const row = this.values.find((v) => v.id === id);
|
|
148
|
+
if (row)
|
|
149
|
+
row.validTo = new Date();
|
|
150
|
+
},
|
|
151
|
+
createValue: async (input) => {
|
|
152
|
+
const record = {
|
|
153
|
+
id: this.newId('val'),
|
|
154
|
+
definitionId: input.definitionId,
|
|
155
|
+
scopeKind: input.scopeKind,
|
|
156
|
+
scopeRefId: input.scopeRefId,
|
|
157
|
+
version: input.version,
|
|
158
|
+
validFrom: new Date(),
|
|
159
|
+
validTo: null,
|
|
160
|
+
...toTypedColumns(input.type, input.value),
|
|
161
|
+
};
|
|
162
|
+
this.values.push(record);
|
|
163
|
+
return record;
|
|
164
|
+
},
|
|
165
|
+
createAudit: async (input) => {
|
|
166
|
+
this.auditLog.push({
|
|
167
|
+
...input,
|
|
168
|
+
id: this.newId('audit'),
|
|
169
|
+
at: new Date(),
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.MemoryStorageAdapter = MemoryStorageAdapter;
|
|
176
|
+
//# sourceMappingURL=memory-storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-storage.js","sourceRoot":"","sources":["../../src/storage/memory-storage.ts"],"names":[],"mappings":";;;AAoBA,2CAA+C;AAO/C,SAAS,cAAc,CAAC,IAAe,EAAE,KAAY;IACpD,OAAO;QACN,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAE,KAAiB,CAAC,CAAC,CAAC,IAAI;QACpD,GAAG,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAE,KAAgB,CAAC,CAAC,CAAC,IAAI;QAClD,IAAI,EAAE,IAAI,KAAK,MAAM,IAAI,I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AEV,UAAU,EAAE,KAAK,EAAE,EAAU,EAAE,EAAE;gBAChC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;gBACjD,IAAI,GAAG;oBAAE,GAAG,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;YACnC,CAAC;YAED,WAAW,EAAE,KAAK,EAAE,KAAuB,EAAE,EAAE;gBAC9C,MAAM,MAAM,GAAgB;oBAC3B,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;oBACrB,YAAY,EAAE,KAAK,CAAC,YAAY;oBAChC,SAAS,EAAE,KAAK,CAAC,SAAS;oBAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,SAAS,EAAE,IAAI,IAAI,EAAE;oBACrB,OAAO,EAAE,IAAI;oBACb,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC;iBAC1C,CAAC;gBACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACzB,OAAO,MAAM,CAAC;YACf,CAAC;YAED,WAAW,EAAE,KAAK,EAAE,KAAuB,EAAiB,EAAE;gBAC7D,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;oBAClB,GAAG,KAAK;oBACR,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;oBACvB,EAAE,EAAE,IAAI,IAAI,EAAE;iBACd,CAAC,CAAC;YACJ,CAAC;SACD,CAAC;IACH,CAAC;CACD;AA3MD,oDA2MC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { DefRecord, Inherit, Status, Value, ValueRecord, ValueType } from '../core/types';
|
|
2
|
+
export interface FindValuesQuery {
|
|
3
|
+
definitionIds: string[];
|
|
4
|
+
scopeKind: string;
|
|
5
|
+
scopeRefId: string | null;
|
|
6
|
+
asOf?: Date;
|
|
7
|
+
}
|
|
8
|
+
export interface FindChainQuery {
|
|
9
|
+
definitionIds: string[];
|
|
10
|
+
chain: string[];
|
|
11
|
+
asOf?: Date;
|
|
12
|
+
}
|
|
13
|
+
export interface CreateDefInput {
|
|
14
|
+
key: string;
|
|
15
|
+
label: string;
|
|
16
|
+
description?: string | null;
|
|
17
|
+
type: ValueType;
|
|
18
|
+
options?: string[];
|
|
19
|
+
min?: number | null;
|
|
20
|
+
max?: number | null;
|
|
21
|
+
scopes: string[];
|
|
22
|
+
inherit: Inherit;
|
|
23
|
+
required: boolean;
|
|
24
|
+
secret?: boolean;
|
|
25
|
+
category?: string | null;
|
|
26
|
+
status?: Status;
|
|
27
|
+
}
|
|
28
|
+
export interface CreateValueInput {
|
|
29
|
+
definitionId: string;
|
|
30
|
+
scopeKind: string;
|
|
31
|
+
scopeRefId: string | null;
|
|
32
|
+
version: number;
|
|
33
|
+
authorId: string;
|
|
34
|
+
reason?: string;
|
|
35
|
+
type: ValueType;
|
|
36
|
+
value: Value;
|
|
37
|
+
}
|
|
38
|
+
export type AuditAction = 'created' | 'superseded' | 'unset';
|
|
39
|
+
export interface CreateAuditInput {
|
|
40
|
+
valueId: string;
|
|
41
|
+
definitionId: string;
|
|
42
|
+
scopeKind: string;
|
|
43
|
+
scopeRefId: string | null;
|
|
44
|
+
action: AuditAction;
|
|
45
|
+
authorId: string;
|
|
46
|
+
before?: unknown;
|
|
47
|
+
after?: unknown;
|
|
48
|
+
reason?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface AuditRecord extends CreateAuditInput {
|
|
51
|
+
id: string;
|
|
52
|
+
at: Date;
|
|
53
|
+
}
|
|
54
|
+
export interface FindAuditQuery {
|
|
55
|
+
definitionId: string;
|
|
56
|
+
scopeKind?: string;
|
|
57
|
+
scopeRefId?: string | null;
|
|
58
|
+
}
|
|
59
|
+
export interface ListValuesQuery {
|
|
60
|
+
scopeKind: string;
|
|
61
|
+
scopeRefId: string | null;
|
|
62
|
+
limit?: number;
|
|
63
|
+
cursor?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ListValuesResult {
|
|
66
|
+
values: ValueRecord[];
|
|
67
|
+
nextCursor: string | null;
|
|
68
|
+
}
|
|
69
|
+
export interface StorageReader {
|
|
70
|
+
findDefs(keys: string[]): Promise<DefRecord[]>;
|
|
71
|
+
findDefsByIds(ids: string[]): Promise<DefRecord[]>;
|
|
72
|
+
findAnyDef(key: string): Promise<DefRecord | null>;
|
|
73
|
+
findValues(query: FindValuesQuery): Promise<ValueRecord[]>;
|
|
74
|
+
findChainValues(query: FindChainQuery): Promise<ValueRecord[]>;
|
|
75
|
+
findAudit(query: FindAuditQuery): Promise<AuditRecord[]>;
|
|
76
|
+
listValues(query: ListValuesQuery): Promise<ListValuesResult>;
|
|
77
|
+
}
|
|
78
|
+
export interface StorageTx {
|
|
79
|
+
findDef(key: string): Promise<DefRecord | null>;
|
|
80
|
+
findValue(definitionId: string, scopeKind: string, scopeRefId: string | null): Promise<ValueRecord | null>;
|
|
81
|
+
closeValue(id: string): Promise<void>;
|
|
82
|
+
createValue(input: CreateValueInput): Promise<ValueRecord>;
|
|
83
|
+
createAudit(input: CreateAuditInput): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
export interface StorageWriter {
|
|
86
|
+
createDef(input: CreateDefInput): Promise<DefRecord>;
|
|
87
|
+
updateDefStatus(key: string, status: Status): Promise<DefRecord>;
|
|
88
|
+
listDefs(status?: Status): Promise<DefRecord[]>;
|
|
89
|
+
transact<T>(fn: (tx: StorageTx) => Promise<T>): Promise<T>;
|
|
90
|
+
}
|
|
91
|
+
export interface StorageAdapter extends StorageReader, StorageWriter {
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=storage-port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-port.d.ts","sourceRoot":"","sources":["../../src/storage/storage-port.ts"],"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AW,cAAe,SAAQ,aAAa,EAAE,aAAa;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-port.js","sourceRoot":"","sources":["../../src/storage/storage-port.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface SettingEntry<Value = unknown, ScopeKind extends string = string> {
|
|
2
|
+
value: Value;
|
|
3
|
+
scope: ScopeKind;
|
|
4
|
+
}
|
|
5
|
+
export type SettingValue<Registry, K extends keyof Registry> = Registry[K] extends SettingEntry<infer V, string> ? V : never;
|
|
6
|
+
export type SettingScopeKind<Registry, K extends keyof Registry> = Registry[K] extends SettingEntry<unknown, infer S> ? S : never;
|
|
7
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/typed/registry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY,CAC5B,KAAK,GAAG,OAAO,EACf,SAAS,SAAS,MAAM,GAAG,MAAM;IAEjC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;CACjB;AAED,MAAM,MAAM,YAAY,CAAC,QAAQ,EAAE,CAAC,SAAS,MAAM,QAAQ,IAC1D,QAAQ,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/D,MAAM,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC,SAAS,MAAM,QAAQ,IAC9D,QAAQ,CAAC,CAAC,CAAC,SAAS,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/typed/registry.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Scope } from '../core/types';
|
|
2
|
+
import type { Auditor } from '../engine/auditor';
|
|
3
|
+
import type { AuditRecord } from '../storage/storage-port';
|
|
4
|
+
import type { SettingScopeKind } from './registry';
|
|
5
|
+
export declare class TypedAuditor<Registry> {
|
|
6
|
+
private readonly auditor;
|
|
7
|
+
constructor(auditor: Auditor);
|
|
8
|
+
history<K extends keyof Registry & string>(key: K, scope?: Scope & {
|
|
9
|
+
kind: SettingScopeKind<Registry, K>;
|
|
10
|
+
}): Promise<AuditRecord[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=typed-auditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-auditor.d.ts","sourceRoot":"","sources":["../../src/typed/typed-auditor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,qBAAa,YAAY,CAAC,QAAQ;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,OAAO;IAE7C,OAAO,CAAC,CAAC,SAAS,MAAM,QAAQ,GAAG,MAAM,EACxC,GAAG,EAAE,CAAC,EACN,KAAK,CAAC,EAAE,KAAK,GAAG;QAAE,IAAI,EAAE,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;KAAE,GACrD,OAAO,CAAC,WAAW,EAAE,CAAC;CAGzB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedAuditor = void 0;
|
|
4
|
+
class TypedAuditor {
|
|
5
|
+
auditor;
|
|
6
|
+
constructor(auditor) {
|
|
7
|
+
this.auditor = auditor;
|
|
8
|
+
}
|
|
9
|
+
history(key, scope) {
|
|
10
|
+
return this.auditor.history(key, scope);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.TypedAuditor = TypedAuditor;
|
|
14
|
+
//# sourceMappingURL=typed-auditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-auditor.js","sourceRoot":"","sources":["../../src/typed/typed-auditor.ts"],"names":[],"mappings":";;;AAKA,MAAa,YAAY;IACK;IAA7B,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,OAAO,CACN,GAAM,EACN,KAAuD;QAEvD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;CACD;AATD,oCASC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Engine } from '../engine/engine';
|
|
2
|
+
import { TypedResolver } from './typed-resolver';
|
|
3
|
+
import { TypedWriter } from './typed-writer';
|
|
4
|
+
import { TypedAuditor } from './typed-auditor';
|
|
5
|
+
export interface TypedEngine<Registry> {
|
|
6
|
+
resolver: TypedResolver<Registry>;
|
|
7
|
+
writer: TypedWriter<Registry>;
|
|
8
|
+
auditor: TypedAuditor<Registry>;
|
|
9
|
+
}
|
|
10
|
+
export declare function createTypedEngine<Registry>(engine: Engine): TypedEngine<Registry>;
|
|
11
|
+
//# sourceMappingURL=typed-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-engine.d.ts","sourceRoot":"","sources":["../../src/typed/typed-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,WAAW,CAAC,QAAQ;IACpC,QAAQ,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC9B,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;CAChC;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EACzC,MAAM,EAAE,MAAM,GACZ,WAAW,CAAC,QAAQ,CAAC,CAMvB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTypedEngine = createTypedEngine;
|
|
4
|
+
const typed_resolver_1 = require("./typed-resolver");
|
|
5
|
+
const typed_writer_1 = require("./typed-writer");
|
|
6
|
+
const typed_auditor_1 = require("./typed-auditor");
|
|
7
|
+
function createTypedEngine(engine) {
|
|
8
|
+
return {
|
|
9
|
+
resolver: new typed_resolver_1.TypedResolver(engine.resolver),
|
|
10
|
+
writer: new typed_writer_1.TypedWriter(engine.writer),
|
|
11
|
+
auditor: new typed_auditor_1.TypedAuditor(engine.auditor),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=typed-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-engine.js","sourceRoot":"","sources":["../../src/typed/typed-engine.ts"],"names":[],"mappings":";;AAWA,8CAQC;AAlBD,qDAAiD;AACjD,iDAA6C;AAC7C,mDAA+C;AAQ/C,SAAgB,iBAAiB,CAChC,MAAc;IAEd,OAAO;QACN,QAAQ,EAAE,IAAI,8BAAa,CAAW,MAAM,CAAC,QAAQ,CAAC;QACtD,MAAM,EAAE,IAAI,0BAAW,CAAW,MAAM,CAAC,MAAM,CAAC;QAChD,OAAO,EAAE,IAAI,4BAAY,CAAW,MAAM,CAAC,OAAO,CAAC;KACnD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Scope } from '../core/types';
|
|
2
|
+
import type { Resolver } from '../engine/resolver';
|
|
3
|
+
import type { SettingScopeKind, SettingValue } from './registry';
|
|
4
|
+
export declare class TypedResolver<Registry> {
|
|
5
|
+
private readonly resolver;
|
|
6
|
+
constructor(resolver: Resolver);
|
|
7
|
+
get<K extends keyof Registry & string>(key: K, scope: Scope & {
|
|
8
|
+
kind: SettingScopeKind<Registry, K>;
|
|
9
|
+
}, asOf?: Date): Promise<SettingValue<Registry, K>>;
|
|
10
|
+
getMany<K extends readonly (keyof Registry & string)[]>(keys: K, scope: Scope, asOf?: Date): Promise<{
|
|
11
|
+
[P in K[number]]: SettingValue<Registry, P>;
|
|
12
|
+
}>;
|
|
13
|
+
listAt(scope: Scope, opts?: {
|
|
14
|
+
limit?: number;
|
|
15
|
+
cursor?: string;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
entries: Partial<{
|
|
18
|
+
[K in keyof Registry & string]: SettingValue<Registry, K>;
|
|
19
|
+
}>;
|
|
20
|
+
nextCursor: string | null;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=typed-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-resolver.d.ts","sourceRoot":"","sources":["../../src/typed/typed-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEjE,qBAAa,aAAa,CAAC,QAAQ;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAE/C,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,GAAG,MAAM,EACpC,GAAG,EAAE,CAAC,EACN,KAAK,EAAE,KAAK,GAAG;QAAE,IAAI,EAAE,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;KAAE,EACtD,IAAI,CAAC,EAAE,IAAI,GACT,OAAO,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAM/B,OAAO,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,EAC3D,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,IAAI,GACT,OAAO,CAAC;SAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;KAAE,CAAC;IAKrD,MAAM,CACX,KAAK,EAAE,KAAK,EACZ,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO,GAC5C,OAAO,CAAC;QACV,OAAO,EAAE,OAAO,CAAC;aACf,CAAC,IAAI,MAAM,QAAQ,GAAG,MAAM,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;SACzD,CAAC,CAAC;QACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;KAC1B,CAAC;CASF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypedResolver = void 0;
|
|
4
|
+
class TypedResolver {
|
|
5
|
+
resolver;
|
|
6
|
+
constructor(resolver) {
|
|
7
|
+
this.resolver = resolver;
|
|
8
|
+
}
|
|
9
|
+
get(key, scope, asOf) {
|
|
10
|
+
return this.resolver.get(key, scope, asOf);
|
|
11
|
+
}
|
|
12
|
+
async getMany(keys, scope, asOf) {
|
|
13
|
+
const result = await this.resolver.getMany([...keys], scope, asOf);
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
async listAt(scope, opts = {}) {
|
|
17
|
+
const page = await this.resolver.listAt(scope, opts);
|
|
18
|
+
return page;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.TypedResolver = TypedResolver;
|
|
22
|
+
//# sourceMappingURL=typed-resolver.js.map
|