dsh 0.2.0-rc.2: in-container update (experimental channel), path-agnostic compose, upstream patches adapted to 0.1.x/0.2.x

This commit is contained in:
hermes committed 2026-10-01 19:21:19 +00:00
commit e6dcef9bf5
302 files changed
+75178

No files matched your search

@@ -0,0 +1,23 @@
import { TrustError } from './validation.mjs'
function normalize(value) {
if (value === null || typeof value === 'string' || typeof value === 'boolean') return value
if (typeof value === 'number') {
if (!Number.isSafeInteger(value)) throw new TrustError('canonical JSON numbers must be safe integers')
return value
}
if (Array.isArray(value)) return value.map(normalize)
if (typeof value === 'object') {
const result = {}
for (const key of Object.keys(value).sort()) {
if (value[key] === undefined) throw new TrustError('canonical JSON cannot contain undefined')
result[key] = normalize(value[key])
}
return result
}
throw new TrustError(`canonical JSON cannot contain ${typeof value}`)
}
export function canonicalJson(value) {
return Buffer.from(`${JSON.stringify(normalize(value))}\n`)
}