@inventarch/db 0.0.0-stage → 1.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.
Files changed (94) hide show
  1. package/LANGUAGE.md +56 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +4 -0
  4. package/README.md +19 -2
  5. package/SPEC.md +71 -0
  6. package/dist/cache.d.ts +13 -0
  7. package/dist/cache.d.ts.map +1 -0
  8. package/dist/cache.js +49 -0
  9. package/dist/cache.js.map +1 -0
  10. package/dist/descriptors/app.d.ts +89 -0
  11. package/dist/descriptors/app.d.ts.map +1 -0
  12. package/dist/descriptors/app.js +231 -0
  13. package/dist/descriptors/app.js.map +1 -0
  14. package/dist/descriptors/codec.d.ts +102 -0
  15. package/dist/descriptors/codec.d.ts.map +1 -0
  16. package/dist/descriptors/codec.js +383 -0
  17. package/dist/descriptors/codec.js.map +1 -0
  18. package/dist/descriptors/domain.d.ts +141 -0
  19. package/dist/descriptors/domain.d.ts.map +1 -0
  20. package/dist/descriptors/domain.js +287 -0
  21. package/dist/descriptors/domain.js.map +1 -0
  22. package/dist/descriptors/envelope.d.ts +52 -0
  23. package/dist/descriptors/envelope.d.ts.map +1 -0
  24. package/dist/descriptors/envelope.js +175 -0
  25. package/dist/descriptors/envelope.js.map +1 -0
  26. package/dist/descriptors/index.d.ts +18 -0
  27. package/dist/descriptors/index.d.ts.map +1 -0
  28. package/dist/descriptors/index.js +12 -0
  29. package/dist/descriptors/index.js.map +1 -0
  30. package/dist/descriptors/registry.d.ts +37 -0
  31. package/dist/descriptors/registry.d.ts.map +1 -0
  32. package/dist/descriptors/registry.js +87 -0
  33. package/dist/descriptors/registry.js.map +1 -0
  34. package/dist/descriptors/storage.d.ts +60 -0
  35. package/dist/descriptors/storage.d.ts.map +1 -0
  36. package/dist/descriptors/storage.js +158 -0
  37. package/dist/descriptors/storage.js.map +1 -0
  38. package/dist/distribution/codec.d.ts +40 -0
  39. package/dist/distribution/codec.d.ts.map +1 -0
  40. package/dist/distribution/codec.js +181 -0
  41. package/dist/distribution/codec.js.map +1 -0
  42. package/dist/distribution/contracts.d.ts +94 -0
  43. package/dist/distribution/contracts.d.ts.map +1 -0
  44. package/dist/distribution/contracts.js +241 -0
  45. package/dist/distribution/contracts.js.map +1 -0
  46. package/dist/distribution/index.d.ts +9 -0
  47. package/dist/distribution/index.d.ts.map +1 -0
  48. package/dist/distribution/index.js +5 -0
  49. package/dist/distribution/index.js.map +1 -0
  50. package/dist/distribution/membership.d.ts +9 -0
  51. package/dist/distribution/membership.d.ts.map +1 -0
  52. package/dist/distribution/membership.js +61 -0
  53. package/dist/distribution/membership.js.map +1 -0
  54. package/dist/distribution/reader.d.ts +32 -0
  55. package/dist/distribution/reader.d.ts.map +1 -0
  56. package/dist/distribution/reader.js +226 -0
  57. package/dist/distribution/reader.js.map +1 -0
  58. package/dist/editor/index.d.ts +40 -0
  59. package/dist/editor/index.d.ts.map +1 -0
  60. package/dist/editor/index.js +173 -0
  61. package/dist/editor/index.js.map +1 -0
  62. package/dist/errors.d.ts +7 -0
  63. package/dist/errors.d.ts.map +1 -0
  64. package/dist/errors.js +22 -0
  65. package/dist/errors.js.map +1 -0
  66. package/dist/handle.d.ts +80 -0
  67. package/dist/handle.d.ts.map +1 -0
  68. package/dist/handle.js +227 -0
  69. package/dist/handle.js.map +1 -0
  70. package/dist/index.d.ts +11 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +5 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/inputs.d.ts +46 -0
  75. package/dist/inputs.d.ts.map +1 -0
  76. package/dist/inputs.js +397 -0
  77. package/dist/inputs.js.map +1 -0
  78. package/dist/json.d.ts +18 -0
  79. package/dist/json.d.ts.map +1 -0
  80. package/dist/json.js +100 -0
  81. package/dist/json.js.map +1 -0
  82. package/dist/paths.d.ts +42 -0
  83. package/dist/paths.d.ts.map +1 -0
  84. package/dist/paths.js +119 -0
  85. package/dist/paths.js.map +1 -0
  86. package/dist/preview.d.ts +19 -0
  87. package/dist/preview.d.ts.map +1 -0
  88. package/dist/preview.js +70 -0
  89. package/dist/preview.js.map +1 -0
  90. package/dist/view.d.ts +22 -0
  91. package/dist/view.d.ts.map +1 -0
  92. package/dist/view.js +221 -0
  93. package/dist/view.js.map +1 -0
  94. package/package.json +148 -3
@@ -0,0 +1,226 @@
1
+ import { existsSync, lstatSync, readFileSync, readdirSync } from 'node:fs';
2
+ import { join, parse, resolve } from 'node:path';
3
+ import { canonicalDistributionJson, DISTRIBUTION_LIMITS, InstallationError, metadataDigest, portablePath, satisfies, sha256, } from './codec.js';
4
+ import { decodeActivationPointer, decodeBundleManifest, decodeDistributionLock, decodeGenerationInputs, generationDigest, } from './contracts.js';
5
+ import { deriveGenerationInputs, installationWorkspace } from './membership.js';
6
+ export const DISTRIBUTION_ENGINE_VERSION = '0.1.0';
7
+ export const INSTALL_PATHS = Object.freeze({
8
+ lock: '.ia/distributions.lock.json',
9
+ active: '.ia/distributions/active.json',
10
+ pending: '.ia/distributions/pending.json',
11
+ store: '.ia/distributions/store',
12
+ generations: '.ia/distributions/generations',
13
+ });
14
+ function corrupt(message) {
15
+ throw new InstallationError('corrupt-state', message);
16
+ }
17
+ function safe(root, path) {
18
+ portablePath(path);
19
+ const absolute = resolve(root, path), volume = parse(absolute).root;
20
+ let current = volume;
21
+ for (const piece of absolute.slice(volume.length).split(/[\\/]/).filter(Boolean)) {
22
+ current = join(current, piece);
23
+ try {
24
+ if (lstatSync(current).isSymbolicLink())
25
+ corrupt('Installed path traverses a link/junction');
26
+ }
27
+ catch (error) {
28
+ if (error.code !== 'ENOENT')
29
+ throw error;
30
+ }
31
+ }
32
+ let parent = resolve(root);
33
+ for (const piece of path.split('/')) {
34
+ if (existsSync(parent) &&
35
+ readdirSync(parent).some((name) => name !== piece && name.toLowerCase() === piece.toLowerCase()))
36
+ corrupt('Installed path has a case alias');
37
+ parent = join(parent, piece);
38
+ }
39
+ return absolute;
40
+ }
41
+ function read(root, path, max = DISTRIBUTION_LIMITS.metadata) {
42
+ const target = safe(root, path);
43
+ let stat;
44
+ try {
45
+ stat = lstatSync(target);
46
+ }
47
+ catch (error) {
48
+ if (error.code === 'ENOENT')
49
+ return null;
50
+ throw error;
51
+ }
52
+ if (!stat.isFile() || stat.nlink !== 1 || stat.size > max)
53
+ corrupt(`Expected bounded unaliased regular file: ${path}`);
54
+ const bytes = readFileSync(target);
55
+ if (bytes.length > max)
56
+ corrupt('Installed file grew beyond limit');
57
+ return bytes;
58
+ }
59
+ function utf8(bytes) {
60
+ try {
61
+ return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
62
+ }
63
+ catch {
64
+ return corrupt('Invalid installed UTF-8');
65
+ }
66
+ }
67
+ function required(root, path, max) {
68
+ return read(root, path, max) ?? corrupt(`Missing installed file: ${path}; restore exact artifacts`);
69
+ }
70
+ function decode(bytes, decoder) {
71
+ const value = decoder(utf8(bytes));
72
+ if (canonicalDistributionJson(value) !== utf8(bytes))
73
+ corrupt('Installed metadata is not canonical');
74
+ return value;
75
+ }
76
+ export function generationSources(pointer, lock, inputs, bundles) {
77
+ if (canonicalDistributionJson(deriveGenerationInputs(lock, bundles)) !== canonicalDistributionJson(inputs))
78
+ corrupt('Generation membership differs from manifests');
79
+ let total = 0;
80
+ for (const bundle of bundles.values()) {
81
+ const manifest = decodeBundleManifest(bundle.manifest);
82
+ if (sha256(canonicalDistributionJson(manifest)) !== bundle.manifestDigest ||
83
+ bundle.files.size !== manifest.files.length ||
84
+ !satisfies(DISTRIBUTION_ENGINE_VERSION, manifest.engine))
85
+ corrupt('Bundle metadata/engine differs');
86
+ for (const pin of manifest.files) {
87
+ const content = bundle.files.get(pin.path);
88
+ if (!content || content.length !== pin.bytes || sha256(content) !== pin.sha256)
89
+ corrupt('Candidate payload pin differs');
90
+ total += content.length;
91
+ if (total > DISTRIBUTION_LIMITS.expanded)
92
+ corrupt('Combined installation byte limit');
93
+ }
94
+ }
95
+ const workspaceText = installationWorkspace(lock, inputs, bundles);
96
+ if (generationDigest(lock, inputs, workspaceText) !== pointer.generation)
97
+ corrupt('Candidate generation digest differs');
98
+ const sources = [];
99
+ for (const system of inputs.systems) {
100
+ const bundle = bundles.get(system.selected);
101
+ for (const path of system.files)
102
+ sources.push(Object.freeze({
103
+ path: `${INSTALL_PATHS.store}/${bundle.archiveDigest}/${path}`,
104
+ text: utf8(bundle.files.get(path)),
105
+ location: Object.freeze({
106
+ placement: Object.freeze({ kind: 'adopted', band: 90, reach: '' }),
107
+ provenance: 'methodology',
108
+ }),
109
+ }));
110
+ }
111
+ if (workspaceText !== null)
112
+ sources.push(Object.freeze({
113
+ path: `${INSTALL_PATHS.generations}/${pointer.generation}/workspace.ia`,
114
+ text: workspaceText,
115
+ location: Object.freeze({
116
+ placement: Object.freeze({ kind: 'authored', band: 100, reach: '' }),
117
+ provenance: 'workspace',
118
+ }),
119
+ }));
120
+ return Object.freeze(sources);
121
+ }
122
+ /** Complete immutable payload verification; no execution, writes or network. */
123
+ export function readExpandedBundle(root, pkg, maximumBytes = DISTRIBUTION_LIMITS.expanded) {
124
+ const directory = `${INSTALL_PATHS.store}/${pkg.archive}`, manifestBytes = required(root, `${directory}/distribution.json`);
125
+ if (sha256(manifestBytes) !== pkg.manifest)
126
+ corrupt(`Manifest digest differs for ${pkg.id}`);
127
+ const manifest = decode(manifestBytes, decodeBundleManifest);
128
+ if (manifest.id !== pkg.id || manifest.version !== pkg.version)
129
+ corrupt('Selected release identity differs');
130
+ if (manifest.files.reduce((sum, file) => sum + file.bytes, 0) > maximumBytes)
131
+ corrupt('Combined installation byte limit');
132
+ const expected = new Map(manifest.files.map((f) => [f.path, f])), files = new Map(), aliases = new Set();
133
+ let expanded = 0;
134
+ const walk = (path) => {
135
+ for (const entry of readdirSync(safe(root, `${directory}${path ? '/' + path : ''}`), { withFileTypes: true })) {
136
+ const local = `${path ? path + '/' : ''}${entry.name}`, key = portablePath(local).toLowerCase();
137
+ if (aliases.has(key) || entry.isSymbolicLink())
138
+ corrupt('Aliased installed inventory');
139
+ aliases.add(key);
140
+ if (aliases.size > DISTRIBUTION_LIMITS.files * 8)
141
+ corrupt('Installed directory inventory exceeds limit');
142
+ if (entry.isDirectory()) {
143
+ walk(local);
144
+ continue;
145
+ }
146
+ if (!entry.isFile())
147
+ corrupt('Nonregular installed payload');
148
+ if (local === 'distribution.json')
149
+ continue;
150
+ const pin = expected.get(local);
151
+ if (!pin && platformDebris(entry.name))
152
+ continue;
153
+ if (!pin)
154
+ corrupt(`Extra installed file: ${local}`);
155
+ const content = required(root, `${directory}/${local}`, DISTRIBUTION_LIMITS.file);
156
+ expanded += content.length;
157
+ if (expanded > DISTRIBUTION_LIMITS.expanded || content.length !== pin.bytes || sha256(content) !== pin.sha256)
158
+ corrupt(`Installed content differs: ${local}`);
159
+ if (pin.role === 'source')
160
+ utf8(content);
161
+ files.set(local, content);
162
+ }
163
+ };
164
+ walk('');
165
+ if (files.size !== expected.size)
166
+ corrupt('Incomplete installed payload inventory');
167
+ return { manifest, files, archiveDigest: pkg.archive, manifestDigest: pkg.manifest };
168
+ }
169
+ export function readInstalledGeneration(root, candidate) {
170
+ if (!candidate && read(root, INSTALL_PATHS.pending))
171
+ throw new InstallationError('recovery-required', 'Run explicit distribution recovery before reading');
172
+ const activeBytes = read(root, INSTALL_PATHS.active), portableBytes = read(root, INSTALL_PATHS.lock);
173
+ if (!candidate && !activeBytes && !portableBytes)
174
+ return undefined;
175
+ if (!candidate && !activeBytes)
176
+ throw new InstallationError('restore-required', 'Portable lock has no active installation');
177
+ const pointer = candidate ? decodeActivationPointer(candidate) : decode(activeBytes, decodeActivationPointer), directory = `${INSTALL_PATHS.generations}/${pointer.generation}`;
178
+ const lockBytes = required(root, `${directory}/lock.json`), lock = decode(lockBytes, decodeDistributionLock);
179
+ if (!candidate && (!portableBytes || !portableBytes.equals(lockBytes)))
180
+ throw new InstallationError('lock-drift', 'Portable lock differs from the active generation; restore explicitly');
181
+ if (!satisfies(DISTRIBUTION_ENGINE_VERSION, lock.engine))
182
+ corrupt('Installation engine compatibility differs');
183
+ const inputs = decode(required(root, `${directory}/inputs.json`), decodeGenerationInputs), workspaceBytes = read(root, `${directory}/workspace.ia`, DISTRIBUTION_LIMITS.file), workspaceText = workspaceBytes === null ? null : utf8(workspaceBytes);
184
+ if (generationDigest(lock, inputs, workspaceText) !== pointer.generation)
185
+ corrupt('Generation inventory digest differs');
186
+ if (readdirSync(safe(root, directory), { withFileTypes: true })
187
+ .filter((entry) => !entry.isFile() || !platformDebris(entry.name))
188
+ .map((entry) => entry.name)
189
+ .sort()
190
+ .join('|') !==
191
+ (workspaceText === null ? ['inputs.json', 'lock.json'] : ['inputs.json', 'lock.json', 'workspace.ia']).join('|'))
192
+ corrupt('Extra generation files');
193
+ const bundles = new Map();
194
+ let remaining = DISTRIBUTION_LIMITS.expanded;
195
+ for (const pkg of lock.packages) {
196
+ const bundle = readExpandedBundle(root, pkg, remaining);
197
+ remaining -= bundle.manifest.files.reduce((sum, file) => sum + file.bytes, 0);
198
+ bundles.set(pkg.id, bundle);
199
+ }
200
+ for (const bundle of bundles.values())
201
+ if (!satisfies(DISTRIBUTION_ENGINE_VERSION, bundle.manifest.engine))
202
+ corrupt('Bundle engine compatibility differs');
203
+ if (canonicalDistributionJson(deriveGenerationInputs(lock, bundles)) !== canonicalDistributionJson(inputs) ||
204
+ installationWorkspace(lock, inputs, bundles) !== workspaceText)
205
+ corrupt('Generation membership/workspace differs from manifests');
206
+ const sources = generationSources(pointer, lock, inputs, bundles);
207
+ if (!candidate &&
208
+ (!read(root, INSTALL_PATHS.active)?.equals(activeBytes) ||
209
+ !read(root, INSTALL_PATHS.lock)?.equals(portableBytes) ||
210
+ existsSync(safe(root, INSTALL_PATHS.pending))))
211
+ throw new InstallationError('recovery-required', 'Activation changed during read; reopen after transaction completion');
212
+ return Object.freeze({
213
+ pointer,
214
+ lock,
215
+ inputs,
216
+ sources: Object.freeze(sources),
217
+ fingerprint: metadataDigest({ pointer, lock, inputs }),
218
+ });
219
+ }
220
+ /**
221
+ * Files a platform writes into any directory it opens, which never belong to a payload: Finder's `.DS_Store`, and the
222
+ * AppleDouble `._<name>` files macOS writes beside files on volumes without extended attributes (exFAT, SMB). A strict
223
+ * inventory skips one only when it is not pinned; a pinned file of such a name is verified like any other (#323).
224
+ */
225
+ export const platformDebris = (name) => name === '.DS_Store' || name.startsWith('._');
226
+ //# sourceMappingURL=reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../../src/distribution/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,SAAS,EACT,MAAM,GACP,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAGhF,MAAM,CAAC,MAAM,2BAA2B,GAAG,OAAO,CAAC;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,6BAA6B;IACnC,MAAM,EAAE,+BAA+B;IACvC,OAAO,EAAE,gCAAgC;IACzC,KAAK,EAAE,yBAAyB;IAChC,WAAW,EAAE,+BAA+B;CAC7C,CAAC,CAAC;AACH,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,IAAI,iBAAiB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AACxD,CAAC;AACD,SAAS,IAAI,CAAC,IAAY,EAAE,IA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I,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,aAAa;QAE9D,OAAO,CAAC,wDAAwD,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,iBAAiB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClE,IACE,CAAC,SAAS;QACV,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,WAAY,CAAC;YACtD,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,aAAc,CAAC;YACvD,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;QAEhD,MAAM,IAAI,iBAAiB,CACzB,mBAAmB,EACnB,qEAAqE,CACtE,CAAC;IACJ,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO;QACP,IAAI;QACJ,MAAM;QACN,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAC/B,WAAW,EAAE,cAAc,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;KACvD,CAAC,CAAC;AACL,CAAC;AACD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { RevisionSource } from '@inventarch/graph';
2
+ import { Reader } from '../handle.js';
3
+ import type { ReadOptions } from '../handle.js';
4
+ import type { InputOptions, InputSnapshot } from '../inputs.js';
5
+ import type { View } from '../view.js';
6
+ import type { LockedPackage } from '../distribution/contracts.js';
7
+ export type { ReadOptions, ReadHandle } from '../handle.js';
8
+ export type { InputOptions } from '../inputs.js';
9
+ export interface Overlay {
10
+ readonly path: string;
11
+ readonly text: string | null;
12
+ readonly version: number;
13
+ }
14
+ export interface EditorSource extends RevisionSource {
15
+ readonly origin: 'local' | 'embedded' | 'explicit' | 'adopted' | 'installed';
16
+ readonly writable: boolean;
17
+ readonly dirty: boolean;
18
+ readonly version?: number;
19
+ readonly hash: string;
20
+ }
21
+ /** Privileged local inspection. This type is not exported by the remote Door. */
22
+ export declare class EditorSnapshot extends Reader {
23
+ readonly sources: readonly EditorSource[];
24
+ readonly installed: readonly LockedPackage[];
25
+ constructor(input: InputSnapshot, changes?: readonly Overlay[], options?: InputOptions);
26
+ inspect(options?: Omit<ReadOptions, 'within'>): View;
27
+ candidate(changes: readonly Overlay[]): EditorSnapshot;
28
+ }
29
+ /** Atomic rebuild: a failed capture never replaces a usable view. No cache is published. */
30
+ export declare class EditorDatabase {
31
+ #private;
32
+ readonly root: string;
33
+ constructor(root: string, options?: InputOptions);
34
+ get generation(): number;
35
+ get savedRevision(): string;
36
+ get current(): EditorSnapshot;
37
+ update(changes: readonly Overlay[], refresh?: boolean): EditorSnapshot;
38
+ close(): void;
39
+ }
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEhE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,OAAO;IACtB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1
+ import { createHash } from 'node:crypto';
2
+ import { canonicalRoot, stableSerialize } from '@inventarch/graph';
3
+ import { DbError } from '../errors.js';
4
+ import { Reader } from '../handle.js';
5
+ import { inputOptions, pathKey, readInputs, safePath } from '../inputs.js';
6
+ import { viewBuilder } from '../view.js';
7
+ const digest = (text) => createHash('sha256').update(text).digest('hex');
8
+ function overlayInputs(input, changes, locations = {}) {
9
+ const sources = new Map(input.sources.map((s) => [pathKey(s.path), s])), seen = new Set();
10
+ for (const change of changes) {
11
+ const path = canonicalRoot(change.path), key = pathKey(path), previous = sources.get(key);
12
+ if (path !== change.path ||
13
+ !path.startsWith('.ia/src/') ||
14
+ !path.endsWith('.ia') ||
15
+ /[\u0000-\u001f<>:"|?*]/.test(path) ||
16
+ !Number.isSafeInteger(change.version) ||
17
+ change.version < 0 ||
18
+ seen.has(key) ||
19
+ (previous !== undefined && previous.path !== path) ||
20
+ (change.text !== null &&
21
+ (typeof change.text !== 'string' || Buffer.from(change.text).toString('utf8') !== change.text)))
22
+ throw new DbError('IA-DB-DRAFT-INVALID', 'Invalid, duplicate or aliased editor overlay');
23
+ safePath(input.root, path);
24
+ seen.add(key);
25
+ if (pathKey(path).startsWith('.ia/src/floor/') && input.floorOrigin !== 'local')
26
+ throw new DbError('IA-DB-DRAFT-INVALID', 'Virtual floor sources are read-only');
27
+ if (previous !== undefined && previous.location.provenance !== 'workspace' && !key.startsWith('.ia/src/floor/'))
28
+ throw new DbError('IA-DB-DRAFT-INVALID', 'Non-workspace sources are read-only');
29
+ if (change.text === null) {
30
+ sources.delete(key);
31
+ continue;
32
+ }
33
+ const location = previous?.location ??
34
+ locations[key] ??
35
+ (key.startsWith('.ia/src/floor/')
36
+ ? { placement: { kind: 'floor', band: 10, reach: '' }, provenance: 'bootstrap' }
37
+ : { placement: { kind: 'authored', band: 100, reach: '' }, provenance: 'workspace' });
38
+ sources.set(key, Object.freeze({ path, text: change.text, location }));
39
+ }
40
+ const ordered = Object.freeze([...sources.values()].sort((a, b) => a.path.localeCompare(b.path)));
41
+ // A buffer may add a file to an existing or new system folder; disk refresh owns removal of empty directories.
42
+ const folders = Object.freeze([
43
+ ...new Set([
44
+ ...input.folders,
45
+ ...ordered.flatMap((s) => (s.path.startsWith('.ia/src/systems/') ? [s.path.split('/')[3]] : [])),
46
+ ]),
47
+ ].sort());
48
+ return Object.freeze({
49
+ ...input,
50
+ sources: ordered,
51
+ folders,
52
+ fingerprint: digest(stableSerialize({
53
+ sources: ordered,
54
+ folders,
55
+ floorOrigin: input.floorOrigin,
56
+ ...(input.activation ? { activation: input.activation } : {}),
57
+ })),
58
+ });
59
+ }
60
+ /** Privileged local inspection. This type is not exported by the remote Door. */
61
+ export class EditorSnapshot extends Reader {
62
+ sources;
63
+ installed;
64
+ constructor(input, changes = [], options = {}) {
65
+ const captured = overlayInputs(input, changes, options.locations), build = viewBuilder(captured), rootView = build();
66
+ super({
67
+ inputs: captured,
68
+ build,
69
+ rootView,
70
+ cache: { state: 'disabled', observations: [] },
71
+ views: new Map([['["",null]', rootView]]),
72
+ }, options.locations);
73
+ const overlays = new Map(changes.map((c) => [pathKey(c.path), c])), savedSources = new Map(input.sources.map((s) => [s.path, s.text]));
74
+ this.sources = Object.freeze(captured.sources.map((source) => {
75
+ const virtual = source.path.startsWith('.ia/src/floor/') && input.floorOrigin !== 'local';
76
+ const overlay = overlays.get(pathKey(source.path));
77
+ const installed = source.path.startsWith('.ia/distributions/');
78
+ return Object.freeze({
79
+ ...source,
80
+ origin: installed
81
+ ? 'installed'
82
+ : source.path.startsWith('.ia/adopted/')
83
+ ? 'adopted'
84
+ : virtual
85
+ ? input.floorOrigin
86
+ : 'local',
87
+ writable: !virtual &&
88
+ !installed &&
89
+ (source.location.provenance === 'workspace' || source.location.placement.kind === 'floor'),
90
+ dirty: overlay !== undefined && savedSources.get(source.path) !== source.text,
91
+ ...(overlay === undefined ? {} : { version: overlay.version }),
92
+ hash: digest(source.text),
93
+ });
94
+ }));
95
+ this.installed = captured.installed ?? [];
96
+ Object.freeze(this);
97
+ }
98
+ inspect(options = {}) {
99
+ return this.view(options);
100
+ }
101
+ candidate(changes) {
102
+ return new EditorSnapshot(this.capturedInputs, changes);
103
+ }
104
+ }
105
+ function capture(root, options, changes = []) {
106
+ for (let attempt = 0; attempt < 3; attempt++) {
107
+ let current;
108
+ try {
109
+ const saved = readInputs(root, options);
110
+ current = new EditorSnapshot(saved, changes, options);
111
+ if (readInputs(root, options).fingerprint === saved.fingerprint)
112
+ return { saved, current };
113
+ }
114
+ catch (error) {
115
+ current?.close();
116
+ if (!(error instanceof DbError) || error.code !== 'IA-DB-SOURCE-CHANGED')
117
+ throw error;
118
+ }
119
+ current?.close();
120
+ }
121
+ throw new DbError('IA-DB-SOURCE-CHANGED', 'Source inputs changed during three consecutive editor snapshot attempts');
122
+ }
123
+ /** Atomic rebuild: a failed capture never replaces a usable view. No cache is published. */
124
+ export class EditorDatabase {
125
+ root;
126
+ #options;
127
+ #saved;
128
+ #current;
129
+ #versions = new Map();
130
+ #generation = 0;
131
+ #closed = false;
132
+ constructor(root, options = {}) {
133
+ this.#options = inputOptions(options);
134
+ const captured = capture(root, this.#options);
135
+ this.#saved = captured.saved;
136
+ this.root = this.#saved.root;
137
+ this.#current = captured.current;
138
+ }
139
+ get generation() {
140
+ return this.#generation;
141
+ }
142
+ get savedRevision() {
143
+ return this.#saved.fingerprint;
144
+ }
145
+ get current() {
146
+ return this.#current;
147
+ }
148
+ update(changes, refresh = false) {
149
+ if (this.#closed)
150
+ throw new DbError('IA-DB-CLOSED', 'Editor database is closed');
151
+ for (const change of changes) {
152
+ const previous = this.#versions.get(pathKey(change.path));
153
+ if (previous &&
154
+ (change.version < previous.version || (change.version === previous.version && change.text !== previous.text)))
155
+ throw new DbError('IA-DB-STALE', 'Overlay version moved backwards or changed bytes without a new version');
156
+ }
157
+ const captured = refresh
158
+ ? capture(this.root, this.#options, changes)
159
+ : { saved: this.#saved, current: new EditorSnapshot(this.#saved, changes, this.#options) };
160
+ const saved = captured.saved, next = captured.current;
161
+ this.#current.close();
162
+ this.#current = next;
163
+ this.#saved = saved;
164
+ this.#versions = new Map(changes.map((c) => [pathKey(c.path), { version: c.version, text: c.text }]));
165
+ this.#generation++;
166
+ return next;
167
+ }
168
+ close() {
169
+ this.#closed = true;
170
+ this.#current.close();
171
+ }
172
+ }
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGnE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAkBzC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzF,SAAS,aAAa,CACpB,KAAoB,EACpB,OAA2B,EAC3B,YAAgD,EAAE;IAElD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EACrE,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC3B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EACrC,GAAG,GAAG,OAAO,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ODES: readonly ["IA-DB-ROOT-INVALID", "IA-DB-PATH-UNSAFE", "IA-DB-SOURCE-UNAVAILABLE", "IA-DB-SOURCE-CHANGED", "IA-DB-SCOPE-UNAVAILABLE", "IA-DB-SCOPE-MISMATCH", "IA-DB-STALE", "IA-DB-CLOSED", "IA-DB-OUT-OF-SCOPE", "IA-DB-CACHE-UNAVAILABLE", "IA-DB-DRAFT-INVALID"];
2
+ export type DbCode = (typeof DB_CODES)[number];
3
+ export declare class DbError extends Error {
4
+ readonly code: DbCode;
5
+ constructor(code: DbCode, message: string);
6
+ }
7
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,oQAYX,CAAC;AACX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/C,qBAAa,OAAQ,SAAQ,KAAK;IAE9B,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB"}
package/dist/errors.js ADDED
@@ -0,0 +1,22 @@
1
+ export const DB_CODES = [
2
+ 'IA-DB-ROOT-INVALID',
3
+ 'IA-DB-PATH-UNSAFE',
4
+ 'IA-DB-SOURCE-UNAVAILABLE',
5
+ 'IA-DB-SOURCE-CHANGED',
6
+ 'IA-DB-SCOPE-UNAVAILABLE',
7
+ 'IA-DB-SCOPE-MISMATCH',
8
+ 'IA-DB-STALE',
9
+ 'IA-DB-CLOSED',
10
+ 'IA-DB-OUT-OF-SCOPE',
11
+ 'IA-DB-CACHE-UNAVAILABLE',
12
+ 'IA-DB-DRAFT-INVALID',
13
+ ];
14
+ export class DbError extends Error {
15
+ code;
16
+ constructor(code, message) {
17
+ super(`${code}: ${message}`);
18
+ this.code = code;
19
+ this.name = 'DbError';
20
+ }
21
+ }
22
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,oBAAoB;IACpB,mBAAmB;IACnB,0BAA0B;IAC1B,sBAAsB;IACtB,yBAAyB;IACzB,sBAAsB;IACtB,aAAa;IACb,cAAc;IACd,oBAAoB;IACpB,yBAAyB;IACzB,qBAAqB;CACb,CAAC;AAEX,MAAM,OAAO,OAAQ,SAAQ,KAAK;IAErB;IADX,YACW,IAAY,EACrB,OAAe;QAEf,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QAHpB,SAAI,GAAJ,IAAI,CAAQ;QAIrB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF"}
@@ -0,0 +1,80 @@
1
+ import type { EdgeReference, Phase } from '@inventarch/language';
2
+ import type { FieldReference, Node, Resolution, SearchHit, Traversal, TraverseOptions } from '@inventarch/graph';
3
+ import type { Report } from '@inventarch/compliance';
4
+ import type { CacheStatus } from './cache.js';
5
+ import type { InputOptions, InputSnapshot } from './inputs.js';
6
+ import { viewBuilder } from './view.js';
7
+ import type { RefusedRecord, View } from './view.js';
8
+ import type { DraftChange, DraftPreview } from './preview.js';
9
+ export interface OpenOptions extends InputOptions {
10
+ readonly cache?: boolean;
11
+ }
12
+ export interface ReadOptions {
13
+ readonly root?: string;
14
+ readonly phase?: Phase | null;
15
+ readonly revision?: string;
16
+ readonly within?: string;
17
+ }
18
+ export interface ScopeRequest extends ReadOptions {
19
+ readonly identities?: readonly string[];
20
+ }
21
+ export interface Scope {
22
+ readonly token: string;
23
+ readonly root: string;
24
+ readonly phase?: Phase;
25
+ readonly revision: string;
26
+ }
27
+ export interface Snapshot {
28
+ readonly revision: string;
29
+ readonly root: string;
30
+ readonly phase?: Phase;
31
+ readonly records: readonly Node[];
32
+ readonly systems: readonly string[];
33
+ }
34
+ export interface DatabaseTraversalOptions extends Omit<TraverseOptions, 'scope'>, ReadOptions {
35
+ }
36
+ interface State {
37
+ readonly inputs: InputSnapshot;
38
+ readonly build: ReturnType<typeof viewBuilder>;
39
+ readonly rootView: View;
40
+ readonly cache: CacheStatus;
41
+ readonly views: Map<string, View>;
42
+ }
43
+ /** Internal observation seam: production supplies readInputs, tests can prove
44
+ * the bounded retry and no-publication invariant with real captured inputs. */
45
+ export declare function stableState(read: () => InputSnapshot, cache: boolean): State;
46
+ /** Shared read engine for disk handles and cache-free editor snapshots. */
47
+ export declare class Reader {
48
+ #private;
49
+ readonly root: string;
50
+ constructor(state: State, locations?: Readonly<Record<string, import('@inventarch/language').Location>>);
51
+ protected get capturedInputs(): InputSnapshot;
52
+ protected replaceState(next: State): void;
53
+ protected view(options: ReadOptions): View;
54
+ resolveScope(options?: ScopeRequest): Scope;
55
+ /** Whole-workspace preview can expose refused sources as diagnostics. Admitted-record counts cannot prove disclosure. */
56
+ isCompleteScope(token: string): boolean;
57
+ get revision(): string;
58
+ get report(): Report;
59
+ get refused(): readonly RefusedRecord[];
60
+ get cache(): CacheStatus;
61
+ snapshot(options?: ReadOptions): Snapshot;
62
+ records(options?: ReadOptions): readonly Node[];
63
+ preview(changes: readonly DraftChange[]): DraftPreview;
64
+ get(identity: string, options?: ReadOptions): Node | undefined;
65
+ resolve(reference: EdgeReference, options?: ReadOptions): Resolution;
66
+ /** Graph G06a typed field references naming `identity`, holders pruned to the scope. Derived, not edges: traverse never walks them. */
67
+ referencedBy(identity: string, options?: ReadOptions): readonly FieldReference[];
68
+ search(text: string, options?: ReadOptions): readonly SearchHit[];
69
+ traverse(options: DatabaseTraversalOptions): Traversal;
70
+ close(): void;
71
+ }
72
+ export declare class Handle extends Reader {
73
+ #private;
74
+ constructor(root: string, options?: OpenOptions);
75
+ refresh(): Snapshot;
76
+ }
77
+ export type ReadHandle = Omit<Handle, 'refresh'>;
78
+ export declare function open(root: string, options?: OpenOptions): Handle;
79
+ export {};
80
+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