@deepseek-ai/dsh-storage-json 0.2.2-rc.1 → 0.2.2-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/types/atomic.d.ts.map +1 -0
- package/lib/types/atomic.js.map +1 -0
- package/lib/types/format.d.ts.map +1 -0
- package/lib/types/format.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/per-record-unit.d.ts.map +1 -0
- package/lib/types/per-record-unit.js.map +1 -0
- package/lib/types/single-unit.d.ts.map +1 -0
- package/lib/types/single-unit.js.map +1 -0
- package/package.json +7 -4
- package/src/atomic.ts +57 -0
- package/src/format.ts +128 -0
- package/src/index.ts +119 -0
- package/src/per-record-unit.ts +379 -0
- package/src/single-unit.ts +161 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic.d.ts","sourceRoot":"","sources":["../../src/atomic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB3E;AAED;;;;GAIG;AAEH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQhE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../../src/atomic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IA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CAAA;IACzG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-unit.d.ts","sourceRoot":"","sources":["../../src/single-unit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAKxE;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,IAAI,GAClB,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-unit.js","sourceRoot":"","sources":["../../src/single-unit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG9C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,UAA4B,EAC5B,IAAY,EACZ,OAAmB;IAEnB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG,UAAU,CAAC,IAAI,OAAO,CAAC,CAAA;IAClD,IAAI,IAAwB,CAAA;IAC5B,IAAI,CAAC;QACH,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAA;QACnE,wEAAwE;IAC1E,CAAC;IACD,MAAM,KAAK,GACT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AAU;QAChB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CAAC,QAAQ,EAAE,SAAS,IAAI,CAAC,UAAU,CAAC,IAAI,aAAa,CAAC,CAAA;QAC9E,CAAC;IACH,CAAC;IACD,sBAAsB;IAEd,OAAO,CAAC,KAAa;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC5C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,UAAU,CAAC,IAAI,6BAA6B,KAAK,GAAG,CAAC,CAAA;QACrF,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAA;QACjF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACxB,uEAAuE;QACvE,oDAAoD;QACpD,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QAChE,OAAO,KAAK,CAAA;IACd,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-storage-json",
|
|
3
3
|
"description": "JSON file KV storage backend for the DeepSeek Harness storage hub",
|
|
4
|
-
"version": "0.2.2-rc.
|
|
4
|
+
"version": "0.2.2-rc.2",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -25,18 +25,21 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"locale/*.json",
|
|
27
27
|
"lib/index.js",
|
|
28
|
-
"lib/types/**/*.d.ts"
|
|
28
|
+
"lib/types/**/*.d.ts",
|
|
29
|
+
"lib/types/**/*.d.ts.map",
|
|
30
|
+
"lib/**/*.js.map",
|
|
31
|
+
"src"
|
|
29
32
|
],
|
|
30
33
|
"license": "MIT",
|
|
31
34
|
"peerDependencies": {
|
|
32
|
-
"@deepseek-ai/dsh-storage": "0.2.2-rc.
|
|
35
|
+
"@deepseek-ai/dsh-storage": "0.2.2-rc.2",
|
|
33
36
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
39
|
"@deepseek-ai/schemastery": "~3.19.0"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
39
|
-
"@deepseek-ai/dsh-storage": "0.2.2-rc.
|
|
42
|
+
"@deepseek-ai/dsh-storage": "0.2.2-rc.2",
|
|
40
43
|
"@deepseek-ai/cordis": "~4.1.0"
|
|
41
44
|
}
|
|
42
45
|
}
|
package/src/atomic.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atomic whole-file replacement for the JSON backend.
|
|
3
|
+
*
|
|
4
|
+
* Publish protocol: write a same-directory temp file, fsync it, then
|
|
5
|
+
* `rename()` over the target. Rename is an atomic replace on POSIX and on
|
|
6
|
+
* Windows (libuv maps it to `MoveFileExW(..., MOVEFILE_REPLACE_EXISTING)`),
|
|
7
|
+
* and replacement is the intended semantic here — unlike the session-log
|
|
8
|
+
* backend's link()+unlink() no-clobber protocol, a unit file has exactly one
|
|
9
|
+
* writer per process and last-write-wins is correct. After the rename the
|
|
10
|
+
* parent directory is fsynced on POSIX so the new entry is crash-durable.
|
|
11
|
+
* @module @deepseek-ai/dsh-storage-json/src/atomic
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { open, rename, rm } from 'node:fs/promises'
|
|
15
|
+
import { dirname, join } from 'node:path'
|
|
16
|
+
import { randomUUID } from 'node:crypto'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Durably replace `path` with `data`.
|
|
20
|
+
* @param path - Absolute target file path.
|
|
21
|
+
* @param data - Full new file content.
|
|
22
|
+
* @returns resolution after the replacement is crash-durable.
|
|
23
|
+
*/
|
|
24
|
+
export async function writeAtomic(path: string, data: string): Promise<void> {
|
|
25
|
+
const tmp = join(dirname(path), `.${randomUUID()}.tmp`)
|
|
26
|
+
try {
|
|
27
|
+
const handle = await open(tmp, 'wx', 0o600)
|
|
28
|
+
try {
|
|
29
|
+
await handle.writeFile(data, 'utf8')
|
|
30
|
+
await handle.sync()
|
|
31
|
+
} finally {
|
|
32
|
+
await handle.close()
|
|
33
|
+
}
|
|
34
|
+
await rename(tmp, path)
|
|
35
|
+
await fsyncDirectory(dirname(path))
|
|
36
|
+
} catch (error) {
|
|
37
|
+
await rm(tmp, { force: true })
|
|
38
|
+
throw error
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Persist directory-entry changes on POSIX; skip this unsupported operation on Windows.
|
|
44
|
+
* @param path - Absolute directory path.
|
|
45
|
+
* @returns resolution after the directory is synced, or immediately on Windows.
|
|
46
|
+
*/
|
|
47
|
+
/* v8 ignore start -- Windows rejects O_RDONLY directory opens; POSIX coverage exercises this. */
|
|
48
|
+
export async function fsyncDirectory(path: string): Promise<void> {
|
|
49
|
+
if (process.platform === 'win32') return
|
|
50
|
+
const handle = await open(path, 'r')
|
|
51
|
+
try {
|
|
52
|
+
await handle.sync()
|
|
53
|
+
} finally {
|
|
54
|
+
await handle.close()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/* v8 ignore stop */
|
package/src/format.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On-disk JSON unit format: the file is always the current net state, kept
|
|
3
|
+
* human-readable (pretty-printed, stable key order from insertion) — that
|
|
4
|
+
* legibility is this backend's reason to exist. `single`-layout units are
|
|
5
|
+
* one document with a unit header; `per-record`-layout units are a directory
|
|
6
|
+
* with one version-stamped document per record (`<table>/<key>.json`) plus a
|
|
7
|
+
* `global.json` for the global slot, so a write rewrites one record instead
|
|
8
|
+
* of the whole unit.
|
|
9
|
+
* @module @deepseek-ai/dsh-storage-json/src/format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { StorageError } from '@deepseek-ai/dsh-storage'
|
|
13
|
+
import type { KvUnitDescriptor } from '@deepseek-ai/dsh-storage'
|
|
14
|
+
|
|
15
|
+
/** In-memory authoritative state of one unit; the file is its projection. `global` is `null` until first written. */
|
|
16
|
+
export interface UnitState {
|
|
17
|
+
version: number
|
|
18
|
+
global: unknown
|
|
19
|
+
tables: Map<string, Map<string, unknown>>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Serialize a unit state to file content.
|
|
24
|
+
* @param name - Unit name, stamped into the header.
|
|
25
|
+
* @param state - Authoritative in-memory state.
|
|
26
|
+
* @returns pretty-printed JSON document with a trailing newline.
|
|
27
|
+
*/
|
|
28
|
+
export function serialize(name: string, state: UnitState): string {
|
|
29
|
+
const tables: Record<string, Record<string, unknown>> = {}
|
|
30
|
+
for (const [table, records] of state.tables) {
|
|
31
|
+
tables[table] = Object.fromEntries(records)
|
|
32
|
+
}
|
|
33
|
+
const document = {
|
|
34
|
+
unit: { name, version: state.version },
|
|
35
|
+
global: state.global,
|
|
36
|
+
tables,
|
|
37
|
+
}
|
|
38
|
+
return `${JSON.stringify(document, null, 2)}\n`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Parse file content into unit state, validating shape and version.
|
|
43
|
+
* @param text - Raw file content.
|
|
44
|
+
* @param descriptor - Expected identity and accepted current or compatible versions.
|
|
45
|
+
* @returns the parsed state.
|
|
46
|
+
*/
|
|
47
|
+
export function parse(text: string, descriptor: KvUnitDescriptor): UnitState {
|
|
48
|
+
let document: unknown
|
|
49
|
+
try {
|
|
50
|
+
document = JSON.parse(text)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new StorageError('malformed-medium', `unit '${descriptor.name}': file is not valid JSON`, { cause: error })
|
|
53
|
+
}
|
|
54
|
+
if (typeof document !== 'object' || document === null) {
|
|
55
|
+
throw new StorageError('malformed-medium', `unit '${descriptor.name}': file is not a JSON object`)
|
|
56
|
+
}
|
|
57
|
+
const { unit, global: globalValue, tables } = document as Record<string, unknown>
|
|
58
|
+
if (
|
|
59
|
+
typeof unit !== 'object' || unit === null ||
|
|
60
|
+
(unit as Record<string, unknown>)['name'] !== descriptor.name ||
|
|
61
|
+
typeof (unit as Record<string, unknown>)['version'] !== 'number'
|
|
62
|
+
) {
|
|
63
|
+
throw new StorageError('malformed-medium', `unit '${descriptor.name}': missing or foreign unit header`)
|
|
64
|
+
}
|
|
65
|
+
const version = (unit as Record<string, unknown>)['version'] as number
|
|
66
|
+
if (version !== descriptor.version && !descriptor.compatibleVersions?.includes(version)) {
|
|
67
|
+
throw new StorageError(
|
|
68
|
+
'version-mismatch',
|
|
69
|
+
`unit '${descriptor.name}': stored version ${version} is not accepted by version ${descriptor.version}`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
// `typeof` alone admits an array: reading one as a table map reports every
|
|
73
|
+
// declared table as absent, and the next publish replaces the file with that
|
|
74
|
+
// empty view, discarding records this reader could not see.
|
|
75
|
+
if (typeof tables !== 'object' || tables === null || Array.isArray(tables)) {
|
|
76
|
+
throw new StorageError('malformed-medium', `unit '${descriptor.name}': tables is not an object`)
|
|
77
|
+
}
|
|
78
|
+
const state: UnitState = { version, global: globalValue ?? null, tables: new Map() }
|
|
79
|
+
for (const table of descriptor.tables) {
|
|
80
|
+
const records = (tables as Record<string, unknown>)[table]
|
|
81
|
+
if (records === undefined) {
|
|
82
|
+
state.tables.set(table, new Map())
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
if (typeof records !== 'object' || records === null || Array.isArray(records)) {
|
|
86
|
+
throw new StorageError('malformed-medium', `unit '${descriptor.name}': table '${table}' is not an object`)
|
|
87
|
+
}
|
|
88
|
+
state.tables.set(table, new Map(Object.entries(records as Record<string, unknown>)))
|
|
89
|
+
}
|
|
90
|
+
return state
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Serialize one per-record document: the unit's version stamp plus the
|
|
95
|
+
* record value, pretty-printed like the whole-unit document.
|
|
96
|
+
* @param version - Unit format version, stamped into the header.
|
|
97
|
+
* @param value - The record value (or the global singleton value).
|
|
98
|
+
* @returns pretty-printed JSON document with a trailing newline.
|
|
99
|
+
*/
|
|
100
|
+
export function serializeRecord(version: number, value: unknown): string {
|
|
101
|
+
return `${JSON.stringify({ version, record: value }, null, 2)}\n`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Parse one per-record document, validating its version stamp. A document
|
|
106
|
+
* that is malformed or stamped with an unaccepted version is FOREIGN and
|
|
107
|
+
* reads as absent — the per-record contract: one bad or stale record file
|
|
108
|
+
* must not brick the whole unit, and an unaccepted version stamp discards the
|
|
109
|
+
* record instead of migrating it (the whole-unit format rejects instead,
|
|
110
|
+
* because there is exactly one document).
|
|
111
|
+
* @param text - Raw per-record document content.
|
|
112
|
+
* @param versions - Accepted unit versions (the current one plus the
|
|
113
|
+
* descriptor's compatibleVersions); any other stamp discards the
|
|
114
|
+
* document.
|
|
115
|
+
* @returns the record value, or `undefined` for a foreign document.
|
|
116
|
+
*/
|
|
117
|
+
export function parseRecord(text: string, versions: readonly number[]): unknown {
|
|
118
|
+
let document: unknown
|
|
119
|
+
try {
|
|
120
|
+
document = JSON.parse(text)
|
|
121
|
+
} catch {
|
|
122
|
+
return undefined
|
|
123
|
+
}
|
|
124
|
+
if (typeof document !== 'object' || document === null) return undefined
|
|
125
|
+
const { version: stamped, record } = document as Record<string, unknown>
|
|
126
|
+
if (typeof stamped !== 'number' || !versions.includes(stamped)) return undefined
|
|
127
|
+
return record
|
|
128
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON storage backend: one human-readable document per unit under a
|
|
3
|
+
* configured root — a whole-unit file (`single` layout) or one document per
|
|
4
|
+
* record (`per-record` layout), published by atomic rewrite. Registers as
|
|
5
|
+
* backend `json` on the storage hub.
|
|
6
|
+
* @module @deepseek-ai/dsh-storage-json
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { mkdir } from 'node:fs/promises'
|
|
10
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
11
|
+
import z from '@deepseek-ai/schemastery'
|
|
12
|
+
import { StorageError, UNIT_NAME_RE, storageBackendServiceKey } from '@deepseek-ai/dsh-storage'
|
|
13
|
+
import type { KvFacet, KvUnit, KvUnitDescriptor, StorageBackend } from '@deepseek-ai/dsh-storage'
|
|
14
|
+
import { openSingleUnit } from './single-unit.ts'
|
|
15
|
+
import { openPerRecordUnit } from './per-record-unit.ts'
|
|
16
|
+
|
|
17
|
+
/** Cordis plugin name. */
|
|
18
|
+
export const name = 'storage-json'
|
|
19
|
+
/** The hub must exist before the backend can register. */
|
|
20
|
+
export const inject = ['storage']
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Plugin configuration.
|
|
24
|
+
* `root` has NO default on purpose: a `process.cwd()` fallback would scatter
|
|
25
|
+
* unit files wherever the process happens to start; assemblies state the
|
|
26
|
+
* location explicitly.
|
|
27
|
+
*/
|
|
28
|
+
export interface Config {
|
|
29
|
+
/** Directory holding one `<unit>.json` file (or `<unit>/` tree) per unit. */
|
|
30
|
+
root: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Config schema. */
|
|
34
|
+
export const Config: z<Config> = z.object({
|
|
35
|
+
root: z.string().required(),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/** JSON backend: owns the file-tree root and serves the `kv` facet. */
|
|
39
|
+
export class JsonStorageBackend implements StorageBackend {
|
|
40
|
+
private readonly open = new Map<string, KvUnit>()
|
|
41
|
+
// Reserved synchronously at open() entry so a concurrent open of the same
|
|
42
|
+
// unit fails, and close() can await opens still in flight.
|
|
43
|
+
private readonly opening = new Map<string, Promise<KvUnit>>()
|
|
44
|
+
private closed = false
|
|
45
|
+
|
|
46
|
+
constructor(private readonly root: string) {}
|
|
47
|
+
|
|
48
|
+
readonly kv: KvFacet = {
|
|
49
|
+
// The body up to the first await runs synchronously, so the opening-slot
|
|
50
|
+
// reservation below still excludes a concurrent open of the same unit.
|
|
51
|
+
open: async (descriptor: KvUnitDescriptor): Promise<KvUnit> => {
|
|
52
|
+
if (this.closed) throw new StorageError('closed', 'json backend is closed')
|
|
53
|
+
validateDescriptor(descriptor)
|
|
54
|
+
if (this.open.has(descriptor.name) || this.opening.has(descriptor.name)) {
|
|
55
|
+
// Double-open is a caller bug, not a medium condition.
|
|
56
|
+
throw new Error(`unit '${descriptor.name}' is already open; a unit has exactly one live handle`)
|
|
57
|
+
}
|
|
58
|
+
const opening = this.openUnit(descriptor)
|
|
59
|
+
this.opening.set(descriptor.name, opening)
|
|
60
|
+
return opening.finally(() => this.opening.delete(descriptor.name))
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private async openUnit(descriptor: KvUnitDescriptor): Promise<KvUnit> {
|
|
65
|
+
await mkdir(this.root, { recursive: true, mode: 0o700 })
|
|
66
|
+
// The two layouts differ in medium shape only; each opener owns its own
|
|
67
|
+
// path convention under the shared root.
|
|
68
|
+
const onClose = () => this.open.delete(descriptor.name)
|
|
69
|
+
const unit = descriptor.layout === 'per-record'
|
|
70
|
+
? await openPerRecordUnit(descriptor, this.root, onClose)
|
|
71
|
+
: await openSingleUnit(descriptor, this.root, onClose)
|
|
72
|
+
if (this.closed) {
|
|
73
|
+
// The backend closed while this open was in flight: do not hand out a
|
|
74
|
+
// live unit past close().
|
|
75
|
+
await unit.close()
|
|
76
|
+
throw new StorageError('closed', 'json backend is closed')
|
|
77
|
+
}
|
|
78
|
+
this.open.set(descriptor.name, unit)
|
|
79
|
+
return unit
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async close(): Promise<void> {
|
|
83
|
+
if (!this.closed) {
|
|
84
|
+
this.closed = true
|
|
85
|
+
}
|
|
86
|
+
await Promise.allSettled([...this.opening.values()])
|
|
87
|
+
for (const unit of [...this.open.values()]) {
|
|
88
|
+
await unit.close()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function validateDescriptor(descriptor: KvUnitDescriptor): void {
|
|
94
|
+
if (!UNIT_NAME_RE.test(descriptor.name)) {
|
|
95
|
+
throw new StorageError('malformed-medium', `invalid unit name '${descriptor.name}'`)
|
|
96
|
+
}
|
|
97
|
+
for (const table of descriptor.tables) {
|
|
98
|
+
if (!UNIT_NAME_RE.test(table)) {
|
|
99
|
+
throw new StorageError('malformed-medium', `invalid table name '${table}' in unit '${descriptor.name}'`)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Register the `json` backend on the storage hub.
|
|
106
|
+
* @param ctx - Plugin context.
|
|
107
|
+
* @param config - Validated configuration.
|
|
108
|
+
*/
|
|
109
|
+
export function apply(ctx: Context, config: Config) {
|
|
110
|
+
const backend = new JsonStorageBackend(config.root)
|
|
111
|
+
ctx.effect(() => {
|
|
112
|
+
const unregister = ctx.storage.backend.register('json', backend)
|
|
113
|
+
return async () => {
|
|
114
|
+
unregister()
|
|
115
|
+
await backend.close()
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
ctx.provide(storageBackendServiceKey('json'), backend)
|
|
119
|
+
}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One opened JSON unit in `per-record` layout: the unit is a directory at
|
|
3
|
+
* `dir`, holding one document per record under `<dir>/<table>/<key>.json`
|
|
4
|
+
* plus `global.json` for the global slot. The directory is the state — this
|
|
5
|
+
* unit holds NO in-memory state of its own: `loadAll` re-reads the tree, each
|
|
6
|
+
* put or delete touches one durable document, and a batch delete renames its
|
|
7
|
+
* documents out of the readable set before unlinking them. The domain layer owns the live
|
|
8
|
+
* in-memory tables (seeded by the open-time `loadAll`) and serializes writes
|
|
9
|
+
* through its write chain. A rejected write leaves domain memory unchanged;
|
|
10
|
+
* a failed deletion restores its staged documents or quarantines the unit
|
|
11
|
+
* with `unknown-state` when restoration cannot be established.
|
|
12
|
+
*
|
|
13
|
+
* Per-record contract: a record document that is malformed or stamped with a
|
|
14
|
+
* version outside the accepted set (the descriptor's current version plus
|
|
15
|
+
* its `compatibleVersions`) reads as an absent record — one bad or stale
|
|
16
|
+
* file never bricks the whole unit, and an unaccepted version stamp discards
|
|
17
|
+
* the record instead of migrating it. Record keys become path segments, so
|
|
18
|
+
* they must be path-safe (`[a-zA-Z0-9_-]+`); an unsafe key rejects at write.
|
|
19
|
+
*
|
|
20
|
+
* Legacy bootstrap: when the new tree has no declared table directory or
|
|
21
|
+
* global document, a whole-unit file `<root>/<name>.json` seeds
|
|
22
|
+
* per-record documents, provided its stored unit version is in the accepted
|
|
23
|
+
* set — a legacy file stamped with any other version is left alone and reads
|
|
24
|
+
* as the empty unit. An existing declared table directory, even when empty,
|
|
25
|
+
* or a declared global document suppresses the bootstrap for the whole unit.
|
|
26
|
+
* The legacy file is never changed or deleted.
|
|
27
|
+
* @module @deepseek-ai/dsh-storage-json/src/per-record-unit
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { mkdir, readFile, readdir, rename, rm } from 'node:fs/promises'
|
|
31
|
+
import { dirname, join } from 'node:path'
|
|
32
|
+
import type { Dirent } from 'node:fs'
|
|
33
|
+
import { StorageError } from '@deepseek-ai/dsh-storage'
|
|
34
|
+
import type { KvUnit, KvUnitDescriptor } from '@deepseek-ai/dsh-storage'
|
|
35
|
+
import { fsyncDirectory, writeAtomic } from './atomic.ts'
|
|
36
|
+
import { parseRecord, serializeRecord } from './format.ts'
|
|
37
|
+
import type { UnitState } from './format.ts'
|
|
38
|
+
|
|
39
|
+
/** Keys become path segments in this layout; this set is path-safe on every OS. */
|
|
40
|
+
const SAFE_KEY_RE = /^[a-zA-Z0-9_-]+$/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Open one `per-record`-layout unit under `root`: the unit directory is
|
|
44
|
+
* `<root>/<name>/`. Loads lazily on the first `loadAll` — this unit holds no
|
|
45
|
+
* state, so opening touches nothing on the medium.
|
|
46
|
+
* @param descriptor - Static identity and shape of the unit.
|
|
47
|
+
* @param root - Absolute backend root directory.
|
|
48
|
+
* @param onClose - Backend callback releasing the unit's open-slot.
|
|
49
|
+
* @returns the opened unit.
|
|
50
|
+
*/
|
|
51
|
+
// oxlint-disable-next-line typescript/require-await -- async keeps both openers' call sites uniform
|
|
52
|
+
export async function openPerRecordUnit(
|
|
53
|
+
descriptor: KvUnitDescriptor,
|
|
54
|
+
root: string,
|
|
55
|
+
onClose: () => void,
|
|
56
|
+
): Promise<KvUnit> {
|
|
57
|
+
return new PerRecordJsonUnit(descriptor, join(root, descriptor.name), onClose)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Read every record document under the unit directory: each declared table's
|
|
62
|
+
* `<key>.json` files plus `global.json`. A missing directory is the empty
|
|
63
|
+
* unit (materialization defers to the first write); a foreign document
|
|
64
|
+
* (missing, malformed, or stamped with an unaccepted version) reads as an absent
|
|
65
|
+
* record, per the per-record contract.
|
|
66
|
+
* @param descriptor - Static identity and shape of the unit.
|
|
67
|
+
* @param dir - Absolute unit directory path.
|
|
68
|
+
* @returns the authoritative state reconstructed from the tree.
|
|
69
|
+
*/
|
|
70
|
+
async function loadPerRecordState(descriptor: KvUnitDescriptor, dir: string): Promise<UnitState> {
|
|
71
|
+
const versions = acceptedStamps(descriptor)
|
|
72
|
+
const state: UnitState = {
|
|
73
|
+
version: descriptor.version,
|
|
74
|
+
global: null,
|
|
75
|
+
tables: new Map(descriptor.tables.map(table => [table, new Map<string, unknown>()])),
|
|
76
|
+
}
|
|
77
|
+
let entries: Dirent[] | undefined
|
|
78
|
+
try {
|
|
79
|
+
entries = await readdir(dir, { withFileTypes: true })
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
82
|
+
// Missing directory = empty unit; the legacy bootstrap below still runs
|
|
83
|
+
// (the fresh-upgrade shape is exactly an absent new tree).
|
|
84
|
+
}
|
|
85
|
+
const hasNewState = entries === undefined
|
|
86
|
+
? false
|
|
87
|
+
: (await Promise.all(entries.map(async (entry) => {
|
|
88
|
+
if (entry.isDirectory()) {
|
|
89
|
+
const records = state.tables.get(entry.name)
|
|
90
|
+
if (records !== undefined) {
|
|
91
|
+
await loadTableRecords(records, versions, join(dir, entry.name))
|
|
92
|
+
return true
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (entry.name === 'global.json' && descriptor.hasGlobal) {
|
|
96
|
+
const global = await readRecord(join(dir, entry.name), versions)
|
|
97
|
+
if (global !== undefined) state.global = global
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
return false
|
|
101
|
+
}))).some(Boolean)
|
|
102
|
+
if (!hasNewState) await bootstrapLegacyUnit(descriptor, dir, state)
|
|
103
|
+
return state
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The version stamps this unit reads as its own: current plus declared compatible versions. */
|
|
107
|
+
function acceptedStamps(descriptor: KvUnitDescriptor): readonly number[] {
|
|
108
|
+
return [descriptor.version, ...descriptor.compatibleVersions ?? []]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Bootstrap an unmaterialized per-record tree from a legacy whole-unit file
|
|
113
|
+
* (`<root>/<name>.json`, the pre-per-record layout). Every declared-table
|
|
114
|
+
* record is copied into a current-version document, while the legacy file is
|
|
115
|
+
* retained unchanged. A missing, foreign (another unit's name), malformed,
|
|
116
|
+
* or non-unit legacy file is left alone, and so is one whose stored unit
|
|
117
|
+
* version is outside the accepted set — migrating records the owner never
|
|
118
|
+
* vouched for would stamp them with the current version and turn a
|
|
119
|
+
* discardable stale cache into schema failures at the domain layer. Other
|
|
120
|
+
* read failures propagate.
|
|
121
|
+
* @param descriptor - Static identity and shape of the unit.
|
|
122
|
+
* @param dir - The per-record unit directory (`<root>/<name>`).
|
|
123
|
+
* @param state - The empty tree state; bootstrapped records are added.
|
|
124
|
+
*/
|
|
125
|
+
async function bootstrapLegacyUnit(descriptor: KvUnitDescriptor, dir: string, state: UnitState): Promise<void> {
|
|
126
|
+
const legacyPath = join(dirname(dir), `${descriptor.name}.json`)
|
|
127
|
+
let text: string | undefined
|
|
128
|
+
try {
|
|
129
|
+
text = await readFile(legacyPath, 'utf8')
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
// The legacy document is runtime data: only `unit.name`, `unit.version`,
|
|
135
|
+
// and the tables map shape are checked here — the record values are
|
|
136
|
+
// migrated as-is and the domain layer's schemas judge them.
|
|
137
|
+
let document: { unit?: { name?: unknown; version?: unknown }; tables?: unknown }
|
|
138
|
+
try {
|
|
139
|
+
document = JSON.parse(text) as { unit?: { name?: unknown; version?: unknown }; tables?: unknown }
|
|
140
|
+
} catch {
|
|
141
|
+
return // Malformed legacy file: not ours to interpret or delete.
|
|
142
|
+
}
|
|
143
|
+
if (document.unit?.name !== descriptor.name) return
|
|
144
|
+
const stamped = document.unit.version
|
|
145
|
+
if (typeof stamped !== 'number' || !acceptedStamps(descriptor).includes(stamped)) return
|
|
146
|
+
const tables = document.tables
|
|
147
|
+
if (typeof tables !== 'object' || tables === null) return
|
|
148
|
+
const recordsByTable = tables as Record<string, Record<string, unknown>>
|
|
149
|
+
for (const [table, records] of Object.entries(recordsByTable)) {
|
|
150
|
+
const target = state.tables.get(table)
|
|
151
|
+
if (target === undefined) continue
|
|
152
|
+
for (const [key, value] of Object.entries(records)) {
|
|
153
|
+
const path = join(dir, table, `${key}.json`)
|
|
154
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 })
|
|
155
|
+
await writeAtomic(path, serializeRecord(descriptor.version, value))
|
|
156
|
+
target.set(key, value)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Read one declared table's record documents into `records`.
|
|
163
|
+
*/
|
|
164
|
+
async function loadTableRecords(records: Map<string, unknown>, versions: readonly number[], dir: string): Promise<void> {
|
|
165
|
+
const files = await readdir(dir, { withFileTypes: true })
|
|
166
|
+
const loaded = await Promise.all(files.map(async (file) => {
|
|
167
|
+
if (!file.name.endsWith('.json')) return
|
|
168
|
+
const key = file.name.slice(0, -'.json'.length)
|
|
169
|
+
if (!SAFE_KEY_RE.test(key)) return
|
|
170
|
+
const record = await readRecord(join(dir, file.name), versions)
|
|
171
|
+
if (record !== undefined) return [key, record] as const
|
|
172
|
+
}))
|
|
173
|
+
for (const record of loaded) {
|
|
174
|
+
if (record !== undefined) records.set(...record)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Read one record document; a foreign (unreadable or stale) one reads as absent. */
|
|
179
|
+
async function readRecord(path: string, versions: readonly number[]): Promise<unknown> {
|
|
180
|
+
try {
|
|
181
|
+
return parseRecord(await readFile(path, 'utf8'), versions)
|
|
182
|
+
} catch {
|
|
183
|
+
return undefined
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* One opened `per-record`-layout unit. Stateless by design: the directory is
|
|
189
|
+
* the medium and the domain layer owns the live memory. Replacements publish
|
|
190
|
+
* one document; deletions stage and sync their documents before cleanup.
|
|
191
|
+
* Write ordering belongs to the caller (the domain layer's write chain).
|
|
192
|
+
*/
|
|
193
|
+
export class PerRecordJsonUnit implements KvUnit {
|
|
194
|
+
private closed = false
|
|
195
|
+
/** Set when a failed batch could not restore its staged documents. */
|
|
196
|
+
private unusable: StorageError | undefined
|
|
197
|
+
/** In-flight durable writes; close() drains them before releasing the unit. */
|
|
198
|
+
private readonly inFlight = new Set<Promise<void>>()
|
|
199
|
+
|
|
200
|
+
constructor(
|
|
201
|
+
private readonly descriptor: KvUnitDescriptor,
|
|
202
|
+
private readonly dir: string,
|
|
203
|
+
private readonly onClose: () => void,
|
|
204
|
+
) {}
|
|
205
|
+
|
|
206
|
+
/** Re-read the tree: the directory is the authoritative state. */
|
|
207
|
+
async loadAll(): Promise<{ tables: Record<string, Record<string, unknown>>; global: unknown }> {
|
|
208
|
+
this.assertOpen()
|
|
209
|
+
const state = await loadPerRecordState(this.descriptor, this.dir)
|
|
210
|
+
const tables: Record<string, Record<string, unknown>> = {}
|
|
211
|
+
for (const [table, records] of state.tables) {
|
|
212
|
+
tables[table] = Object.fromEntries(records)
|
|
213
|
+
}
|
|
214
|
+
return { tables, global: state.global }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Durably replace one record: its own document, atomically. */
|
|
218
|
+
async putRecord(table: string, key: string, value: unknown): Promise<void> {
|
|
219
|
+
this.assertOpen()
|
|
220
|
+
assertSafeKey(this.descriptor.name, key)
|
|
221
|
+
await this.tracked(this.writeDocument(join(this.tableDir(table), `${key}.json`), value))
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** Durably delete one record. Idempotent: a missing key is a no-op. */
|
|
225
|
+
deleteRecord(table: string, key: string): Promise<void> {
|
|
226
|
+
return this.deleteRecords(table, [key])
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Durably delete many records as one batch. Documents are renamed out of the
|
|
231
|
+
* readable set first; only after the whole batch is staged are the staged
|
|
232
|
+
* copies unlinked. A failure while staging restores the documents it moved,
|
|
233
|
+
* so a rejection normally leaves the batch unapplied. If that restoration
|
|
234
|
+
* itself fails, the readable or durable state is unknown: the unit rejects with
|
|
235
|
+
* `unknown-state` and every later operation on it rejects, while `close`
|
|
236
|
+
* still releases it. Staged directory changes are synced before cleanup on
|
|
237
|
+
* POSIX, so a resolved deletion remains absent after a crash. Cleanup residue
|
|
238
|
+
* is not readable (`open` reads `*.json` documents only).
|
|
239
|
+
*/
|
|
240
|
+
async deleteRecords(table: string, keys: readonly string[]): Promise<void> {
|
|
241
|
+
this.assertOpen()
|
|
242
|
+
const dir = this.tableDir(table)
|
|
243
|
+
const unique = [...new Set(keys)]
|
|
244
|
+
for (const key of unique) assertSafeKey(this.descriptor.name, key)
|
|
245
|
+
// Track staging, restoration, and cleanup together so close() drains them.
|
|
246
|
+
await this.tracked(this.removeDocuments(dir, unique))
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Remove one batch's documents under a single tracked promise.
|
|
251
|
+
* @param dir - Declared table directory.
|
|
252
|
+
* @param keys - Validated, de-duplicated record keys.
|
|
253
|
+
*/
|
|
254
|
+
private async removeDocuments(dir: string, keys: readonly string[]): Promise<void> {
|
|
255
|
+
const staged: Array<{ from: string; to: string }> = []
|
|
256
|
+
try {
|
|
257
|
+
for (const key of keys) {
|
|
258
|
+
const from = join(dir, `${key}.json`)
|
|
259
|
+
const to = `${from}.deleting`
|
|
260
|
+
try {
|
|
261
|
+
await rename(from, to)
|
|
262
|
+
} catch (error: unknown) {
|
|
263
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') continue
|
|
264
|
+
throw error
|
|
265
|
+
}
|
|
266
|
+
staged.push({ from, to })
|
|
267
|
+
}
|
|
268
|
+
if (staged.length > 0) await fsyncDirectory(dir)
|
|
269
|
+
} catch (error: unknown) {
|
|
270
|
+
const restoreFailures: unknown[] = []
|
|
271
|
+
for (const { from, to } of staged) {
|
|
272
|
+
try {
|
|
273
|
+
await rename(to, from)
|
|
274
|
+
} catch (restoreError: unknown) {
|
|
275
|
+
restoreFailures.push(restoreError)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (staged.length > 0) {
|
|
279
|
+
try {
|
|
280
|
+
await fsyncDirectory(dir)
|
|
281
|
+
} catch (restoreError: unknown) {
|
|
282
|
+
restoreFailures.push(restoreError)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (restoreFailures.length === 0) throw error
|
|
286
|
+
this.unusable = new StorageError(
|
|
287
|
+
'unknown-state',
|
|
288
|
+
`unit '${this.descriptor.name}' could not restore a failed batch delete; its state is unknown`,
|
|
289
|
+
{ cause: new AggregateError([error, ...restoreFailures], 'batch delete failed and restoration failed') },
|
|
290
|
+
)
|
|
291
|
+
throw this.unusable
|
|
292
|
+
}
|
|
293
|
+
// The renames already removed the batch from the readable set; unlinking is
|
|
294
|
+
// cleanup, and a failed unlink leaves an unreadable file rather than an entry.
|
|
295
|
+
await Promise.allSettled(staged.map(({ to }) => rm(to, { force: true })))
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Move one record's document aside as `<key>.json.bak.<YYYYMMDDHHmm>`. The
|
|
300
|
+
* moved file no longer ends in `.json`, so every later read ignores it; the
|
|
301
|
+
* bytes stay on disk for inspection. A same-minute backup of the same
|
|
302
|
+
* key overwrites the previous backup (the newer bytes are the ones worth
|
|
303
|
+
* keeping).
|
|
304
|
+
*/
|
|
305
|
+
async backupRecord(table: string, key: string): Promise<string> {
|
|
306
|
+
this.assertOpen()
|
|
307
|
+
assertSafeKey(this.descriptor.name, key)
|
|
308
|
+
const path = join(this.tableDir(table), `${key}.json`)
|
|
309
|
+
const moved = `${path}.bak.${backupStamp(new Date())}`
|
|
310
|
+
await this.tracked(rename(path, moved))
|
|
311
|
+
return moved
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Durably replace the global singleton. Only valid when declared. */
|
|
315
|
+
async setGlobal(value: unknown): Promise<void> {
|
|
316
|
+
this.assertOpen()
|
|
317
|
+
if (!this.descriptor.hasGlobal) {
|
|
318
|
+
throw new Error(`unit '${this.descriptor.name}' does not declare a global slot`)
|
|
319
|
+
}
|
|
320
|
+
await this.tracked(this.writeDocument(join(this.dir, 'global.json'), value))
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/* jscpd:ignore-start -- the two unit classes are standalone; the drain/guard lifecycle mirrors the shared KvUnit contract */
|
|
324
|
+
/** Drain in-flight writes and release the unit. Idempotent. */
|
|
325
|
+
async close(): Promise<void> {
|
|
326
|
+
if (this.closed) {
|
|
327
|
+
await Promise.allSettled(this.inFlight)
|
|
328
|
+
return
|
|
329
|
+
}
|
|
330
|
+
this.closed = true
|
|
331
|
+
await Promise.allSettled(this.inFlight)
|
|
332
|
+
this.onClose()
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
private assertOpen(): void {
|
|
336
|
+
if (this.closed) {
|
|
337
|
+
throw new StorageError('closed', `unit '${this.descriptor.name}' is closed`)
|
|
338
|
+
}
|
|
339
|
+
if (this.unusable !== undefined) throw this.unusable
|
|
340
|
+
}
|
|
341
|
+
/* jscpd:ignore-end */
|
|
342
|
+
|
|
343
|
+
/** Resolve a declared table's directory; an undeclared table is a caller bug and throws. */
|
|
344
|
+
private tableDir(table: string): string {
|
|
345
|
+
if (!this.descriptor.tables.includes(table)) {
|
|
346
|
+
throw new Error(`unit '${this.descriptor.name}' does not declare table '${table}'`)
|
|
347
|
+
}
|
|
348
|
+
return join(this.dir, table)
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** Durably replace one document, creating its parent directory. */
|
|
352
|
+
private async writeDocument(path: string, value: unknown): Promise<void> {
|
|
353
|
+
const text = serializeRecord(this.descriptor.version, value)
|
|
354
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 })
|
|
355
|
+
await writeAtomic(path, text)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Track one durable write so close() drains it. */
|
|
359
|
+
private tracked(write: Promise<void>): Promise<void> {
|
|
360
|
+
this.inFlight.add(write)
|
|
361
|
+
// Swallow only on the tracking branch: the caller still awaits `write`
|
|
362
|
+
// itself, so rejections stay observed exactly once.
|
|
363
|
+
write.catch(() => {}).finally(() => this.inFlight.delete(write))
|
|
364
|
+
return write
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Local-time `YYYYMMDDHHmm` suffix for backed-up documents. */
|
|
369
|
+
function backupStamp(now: Date): string {
|
|
370
|
+
const pad = (value: number): string => String(value).padStart(2, '0')
|
|
371
|
+
return `${String(now.getFullYear())}${pad(now.getMonth() + 1)}${pad(now.getDate())}${pad(now.getHours())}${pad(now.getMinutes())}`
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Reject a record key that would be unsafe as a path segment. */
|
|
375
|
+
function assertSafeKey(unit: string, key: string): void {
|
|
376
|
+
if (!SAFE_KEY_RE.test(key)) {
|
|
377
|
+
throw new Error(`unit '${unit}': per-record key '${key}' is not path-safe (must match ${SAFE_KEY_RE})`)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One opened JSON unit in `single` layout: the whole unit is one document at
|
|
3
|
+
* `<root>/<name>.json`. The in-memory state is authoritative; every write
|
|
4
|
+
* primitive mutates it and republishes the whole file atomically, including a
|
|
5
|
+
* batch delete, which changes several records but publishes once. Writes are
|
|
6
|
+
* NOT queued here — per the backend contract, write ordering belongs to the
|
|
7
|
+
* caller (the domain layer's write chain); this unit only guarantees that
|
|
8
|
+
* each single call publishes a complete, durable file. The `per-record`
|
|
9
|
+
* layout is a separate unit class in `per-record-unit.ts`.
|
|
10
|
+
* @module @deepseek-ai/dsh-storage-json/src/single-unit
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { readFile } from 'node:fs/promises'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
import { StorageError } from '@deepseek-ai/dsh-storage'
|
|
16
|
+
import type { KvUnit, KvUnitDescriptor } from '@deepseek-ai/dsh-storage'
|
|
17
|
+
import { writeAtomic } from './atomic.ts'
|
|
18
|
+
import { parse, serialize } from './format.ts'
|
|
19
|
+
import type { UnitState } from './format.ts'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Open (load or lazily create) one `single`-layout unit under `root`: the
|
|
23
|
+
* unit file is `<root>/<name>.json`.
|
|
24
|
+
* @param descriptor - Static identity and shape of the unit.
|
|
25
|
+
* @param root - Absolute backend root directory.
|
|
26
|
+
* @param onClose - Backend callback releasing the unit's open-slot.
|
|
27
|
+
* @returns the opened unit.
|
|
28
|
+
*/
|
|
29
|
+
export async function openSingleUnit(
|
|
30
|
+
descriptor: KvUnitDescriptor,
|
|
31
|
+
root: string,
|
|
32
|
+
onClose: () => void,
|
|
33
|
+
): Promise<KvUnit> {
|
|
34
|
+
const path = join(root, `${descriptor.name}.json`)
|
|
35
|
+
let text: string | undefined
|
|
36
|
+
try {
|
|
37
|
+
text = await readFile(path, 'utf8')
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
40
|
+
// Missing file = empty unit; materialization defers to the first write.
|
|
41
|
+
}
|
|
42
|
+
const state: UnitState =
|
|
43
|
+
text === undefined
|
|
44
|
+
? {
|
|
45
|
+
version: descriptor.version,
|
|
46
|
+
global: null,
|
|
47
|
+
tables: new Map(descriptor.tables.map(table => [table, new Map<string, unknown>()])),
|
|
48
|
+
}
|
|
49
|
+
: parse(text, descriptor)
|
|
50
|
+
// Opening leaves the file untouched; the next atomic publish uses the current stamp.
|
|
51
|
+
state.version = descriptor.version
|
|
52
|
+
return new SingleJsonUnit(descriptor, path, state, onClose)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class SingleJsonUnit implements KvUnit {
|
|
56
|
+
private closed = false
|
|
57
|
+
/** In-flight publishes; close() drains them before releasing the unit. */
|
|
58
|
+
private readonly inFlight = new Set<Promise<void>>()
|
|
59
|
+
|
|
60
|
+
constructor(
|
|
61
|
+
private readonly descriptor: KvUnitDescriptor,
|
|
62
|
+
private readonly path: string,
|
|
63
|
+
private readonly state: UnitState,
|
|
64
|
+
private readonly onClose: () => void,
|
|
65
|
+
) {}
|
|
66
|
+
|
|
67
|
+
// oxlint-disable-next-line typescript/require-await -- async keeps the closed guard a rejection, not a synchronous throw
|
|
68
|
+
async loadAll(): Promise<{ tables: Record<string, Record<string, unknown>>; global: unknown }> {
|
|
69
|
+
this.assertOpen()
|
|
70
|
+
const tables: Record<string, Record<string, unknown>> = {}
|
|
71
|
+
for (const [table, records] of this.state.tables) {
|
|
72
|
+
tables[table] = Object.fromEntries(records)
|
|
73
|
+
}
|
|
74
|
+
return { tables, global: this.state.global }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async putRecord(table: string, key: string, value: unknown): Promise<void> {
|
|
78
|
+
this.assertOpen()
|
|
79
|
+
const records = this.records(table)
|
|
80
|
+
const hadKey = records.has(key)
|
|
81
|
+
const previous = records.get(key)
|
|
82
|
+
records.set(key, value)
|
|
83
|
+
// Roll back on a failed publish: memory is authoritative, so a rejected
|
|
84
|
+
// write must not survive in memory (or ride along with the next publish).
|
|
85
|
+
await this.publish().catch((error: unknown) => {
|
|
86
|
+
if (hadKey) records.set(key, previous)
|
|
87
|
+
else records.delete(key)
|
|
88
|
+
throw error
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
deleteRecord(table: string, key: string): Promise<void> {
|
|
93
|
+
return this.deleteRecords(table, [key])
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async deleteRecords(table: string, keys: readonly string[]): Promise<void> {
|
|
97
|
+
this.assertOpen()
|
|
98
|
+
const records = this.records(table)
|
|
99
|
+
const removed = new Map<string, unknown>()
|
|
100
|
+
for (const key of new Set(keys)) {
|
|
101
|
+
if (!records.has(key)) continue
|
|
102
|
+
removed.set(key, records.get(key))
|
|
103
|
+
records.delete(key)
|
|
104
|
+
}
|
|
105
|
+
if (removed.size === 0) return
|
|
106
|
+
// One atomic publish applies the whole batch; a failed publish restores
|
|
107
|
+
// every removed entry so memory and the medium stay together.
|
|
108
|
+
await this.publish().catch((error: unknown) => {
|
|
109
|
+
for (const [key, value] of removed) records.set(key, value)
|
|
110
|
+
throw error
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async setGlobal(value: unknown): Promise<void> {
|
|
115
|
+
this.assertOpen()
|
|
116
|
+
if (!this.descriptor.hasGlobal) {
|
|
117
|
+
throw new Error(`unit '${this.descriptor.name}' does not declare a global slot`)
|
|
118
|
+
}
|
|
119
|
+
const previous = this.state.global
|
|
120
|
+
this.state.global = value
|
|
121
|
+
await this.publish().catch((error: unknown) => {
|
|
122
|
+
this.state.global = previous
|
|
123
|
+
throw error
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* jscpd:ignore-start -- the two unit classes are standalone; the drain/guard lifecycle mirrors the shared KvUnit contract */
|
|
128
|
+
async close(): Promise<void> {
|
|
129
|
+
if (this.closed) {
|
|
130
|
+
await Promise.allSettled(this.inFlight)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
this.closed = true
|
|
134
|
+
await Promise.allSettled(this.inFlight)
|
|
135
|
+
this.onClose()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private assertOpen(): void {
|
|
139
|
+
if (this.closed) {
|
|
140
|
+
throw new StorageError('closed', `unit '${this.descriptor.name}' is closed`)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/* jscpd:ignore-end */
|
|
144
|
+
|
|
145
|
+
private records(table: string): Map<string, unknown> {
|
|
146
|
+
const records = this.state.tables.get(table)
|
|
147
|
+
if (!records) {
|
|
148
|
+
throw new Error(`unit '${this.descriptor.name}' does not declare table '${table}'`)
|
|
149
|
+
}
|
|
150
|
+
return records
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private async publish(): Promise<void> {
|
|
154
|
+
const write = writeAtomic(this.path, serialize(this.descriptor.name, this.state))
|
|
155
|
+
this.inFlight.add(write)
|
|
156
|
+
// Swallow only on the tracking branch: the caller still awaits `write`
|
|
157
|
+
// itself, so rejections stay observed exactly once.
|
|
158
|
+
write.catch(() => {}).finally(() => this.inFlight.delete(write))
|
|
159
|
+
return write
|
|
160
|
+
}
|
|
161
|
+
}
|