@wildshard/shard-format 0.69.2 → 0.71.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/package.json +21 -3
- package/src/cli/corpus-candidate.ts +228 -0
- package/src/cli/corpus-command.ts +67 -0
- package/src/cli/corpus-pins.ts +73 -0
- package/src/cli/corpus-report.ts +36 -0
- package/src/cli/corpus-tar.ts +28 -0
- package/src/cli/corpus-usage.ts +106 -0
- package/src/cli/corpus.ts +50 -68
- package/src/cli/format-diff-data.ts +89 -0
- package/src/cli/format-diff-lock.ts +122 -0
- package/src/cli/format-diff-normal.ts +300 -0
- package/src/cli/format-diff-paths.ts +103 -0
- package/src/cli/format-diff-range.ts +112 -0
- package/src/cli/format-diff-report.ts +30 -0
- package/src/cli/format-diff-rules.ts +232 -0
- package/src/cli/format-diff.ts +226 -0
- package/src/cli/main.ts +81 -32
- package/src/cli/pack.ts +20 -3
- package/src/cli/validate.ts +1 -1
- package/src/format/clientOwnership.ts +1 -1
- package/src/format/clientTrails.ts +121 -46
- package/src/format/cook-data.ts +22 -3
- package/src/format/cook-deprecations.ts +53 -0
- package/src/format/cook-preparation.ts +105 -70
- package/src/format/creature-rest-rig.ts +248 -0
- package/src/format/creature-skin-bounds.ts +146 -0
- package/src/format/deprecations.ts +30 -21
- package/src/format/edge-observations.ts +67 -0
- package/src/format/empty-shardfile.ts +4 -2
- package/src/format/entry-read-set.ts +147 -0
- package/src/format/format-migrate-rebuild.ts +4 -1
- package/src/format/format-migrate.ts +10 -5
- package/src/format/format-migration-envelope.ts +40 -0
- package/src/format/format-migration-prune.ts +42 -1
- package/src/format/format-migrations.ts +10 -1
- package/src/format/format-window.ts +71 -0
- package/src/format/immutable.ts +4 -1
- package/src/format/json-schema.ts +1468 -0
- package/src/format/lootEconomy.ts +4 -1
- package/src/format/mat4.ts +225 -0
- package/src/format/memory-armed.json +1 -9
- package/src/format/memory-armed.ts +46 -17
- package/src/format/memory-epoch.ts +10 -3
- package/src/format/memory-line.ts +17 -6
- package/src/format/outputFields.ts +3 -2
- package/src/format/outputIndex.ts +41 -6
- package/src/format/platformDataSections.ts +5 -0
- package/src/format/platformFileFamilies.ts +3 -3
- package/src/format/play-area.ts +95 -0
- package/src/format/policy-verdict.ts +12 -2
- package/src/format/preparation-checks.ts +100 -0
- package/src/format/preparation-spec.ts +45 -0
- package/src/format/registeredJson.ts +2 -2
- package/src/format/runtime-tier.ts +14 -7
- package/src/format/save-revision.ts +105 -0
- package/src/format/schema-source.ts +70 -0
- package/src/format/sections.ts +4 -1
- package/src/format/server-plan.ts +42 -0
- package/src/format/server-reads.ts +23 -0
- package/src/format/shardSchema.ts +9 -4
- package/src/format/shardSections.ts +17 -7
- package/src/format/shardfile-assets.ts +5 -5
- package/src/format/shardfile-stream-admit.ts +19 -10
- package/src/format/shardfile-stream-facts.ts +2 -1
- package/src/format/shardfile-stream.ts +2 -3
- package/src/format/shardfileValidation.ts +16 -9
- package/src/format/species-deprecations.ts +79 -0
- package/src/format/stateLineage.ts +15 -7
- package/src/format/tread-boxes.ts +65 -0
- package/src/format/vehicle-hulls.ts +124 -0
- package/src/format/version.ts +96 -10
- package/src/format/whole-inputs.ts +51 -0
- package/src/tools/runtime-hosts.json +4 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {
|
|
2
|
+
dataFinding,
|
|
3
|
+
directed,
|
|
4
|
+
finding,
|
|
5
|
+
setFinding,
|
|
6
|
+
} from './format-diff-data.ts'
|
|
7
|
+
import { isRecord } from './format-diff-lock.ts'
|
|
8
|
+
|
|
9
|
+
import type { Finding } from './format-diff-data.ts'
|
|
10
|
+
import type { Json } from './format-diff-lock.ts'
|
|
11
|
+
import type { Row, SchemaRow } from './format-diff-normal.ts'
|
|
12
|
+
|
|
13
|
+
// SHARD-COMPAT FE2: how one changed row is classified. "Additive" means an
|
|
14
|
+
// old file still reads on the new reader (never the reverse: every schema is
|
|
15
|
+
// strict). "Breaking" means some old file is refused or means something else.
|
|
16
|
+
// "Review" is what no rule can decide (a predicate's code, a default, a
|
|
17
|
+
// transform). The suggested op is an FE8 migration op.
|
|
18
|
+
|
|
19
|
+
interface Action {
|
|
20
|
+
readonly kind: string
|
|
21
|
+
readonly type: string
|
|
22
|
+
readonly requirement: Json | undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const LOOSE = 0
|
|
26
|
+
const PLAIN = 1
|
|
27
|
+
const STRICT = 2
|
|
28
|
+
/** Strictness per shape family: a lower level admits more. */
|
|
29
|
+
const LOOSENESS: Readonly<Record<string, readonly [string, number]>> = {
|
|
30
|
+
loose_object: ['object', LOOSE],
|
|
31
|
+
object: ['object', PLAIN],
|
|
32
|
+
object_with_rest: ['object', LOOSE],
|
|
33
|
+
strict_object: ['object', STRICT],
|
|
34
|
+
loose_tuple: ['tuple', LOOSE],
|
|
35
|
+
tuple: ['tuple', PLAIN],
|
|
36
|
+
tuple_with_rest: ['tuple', LOOSE],
|
|
37
|
+
strict_tuple: ['tuple', STRICT],
|
|
38
|
+
}
|
|
39
|
+
const OPTIONALS: ReadonlySet<string> = new Set([
|
|
40
|
+
'exact_optional',
|
|
41
|
+
'nullish',
|
|
42
|
+
'optional',
|
|
43
|
+
'undefinedable',
|
|
44
|
+
])
|
|
45
|
+
const NULLABLES: ReadonlySet<string> = new Set(['nullable', 'nullish'])
|
|
46
|
+
const UNIONS: ReadonlySet<string> = new Set(['picklist', 'union', 'variant'])
|
|
47
|
+
const KIND_FIELD = /\.(?:kind|type)$/u
|
|
48
|
+
const SKIPPED_ACTIONS: ReadonlySet<string> = new Set(['metadata'])
|
|
49
|
+
const NONE = 0
|
|
50
|
+
|
|
51
|
+
function text(value: Json | undefined): string {
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
return 'none'
|
|
54
|
+
}
|
|
55
|
+
return typeof value === 'string' ? value : JSON.stringify(value)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A type change: within a shape family by looseness, into a union for review, else a break. */
|
|
59
|
+
function typeFinding(before: SchemaRow, after: SchemaRow): readonly Finding[] {
|
|
60
|
+
if (before.type === after.type) {
|
|
61
|
+
return []
|
|
62
|
+
}
|
|
63
|
+
const [familyBefore, levelBefore] = LOOSENESS[before.type] ?? ['', PLAIN]
|
|
64
|
+
const [familyAfter, levelAfter] = LOOSENESS[after.type] ?? ['', PLAIN]
|
|
65
|
+
const what = `type ${before.type} -> ${after.type}`
|
|
66
|
+
if (familyBefore !== '' && familyBefore === familyAfter) {
|
|
67
|
+
return [directed(levelAfter < levelBefore, what)]
|
|
68
|
+
}
|
|
69
|
+
if (UNIONS.has(after.type) && !UNIONS.has(before.type)) {
|
|
70
|
+
// It may still admit the old shape as one option: a person checks.
|
|
71
|
+
return [finding('review', `${what} (does an option admit the old?)`)]
|
|
72
|
+
}
|
|
73
|
+
return [finding('breaking', what, 'map')]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function admits(wrap: readonly string[], set: ReadonlySet<string>): boolean {
|
|
77
|
+
return wrap.some((type: string): boolean => set.has(type))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Wrapper changes: gaining optional or nullable admits more; losing it refuses old files. */
|
|
81
|
+
function wrapFindings(before: SchemaRow, after: SchemaRow): readonly Finding[] {
|
|
82
|
+
if (before.wrap.join('/') === after.wrap.join('/')) {
|
|
83
|
+
return []
|
|
84
|
+
}
|
|
85
|
+
const out: Finding[] = []
|
|
86
|
+
for (const [set, name] of [
|
|
87
|
+
[OPTIONALS, 'optional'],
|
|
88
|
+
[NULLABLES, 'nullable'],
|
|
89
|
+
] as const) {
|
|
90
|
+
const now = admits(after.wrap, set)
|
|
91
|
+
if (admits(before.wrap, set) !== now) {
|
|
92
|
+
out.push(
|
|
93
|
+
now
|
|
94
|
+
? finding('additive', `now ${name}`)
|
|
95
|
+
: finding('breaking', `no longer ${name}`, 'fill'),
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const moved = `wrappers ${before.wrap.join('/')} -> ${after.wrap.join('/')}`
|
|
100
|
+
return out.length > NONE ? out : [finding('review', moved)]
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function actionOf(action: Json): Action | undefined {
|
|
104
|
+
if (!isRecord(action)) {
|
|
105
|
+
return undefined
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
kind: text(action['kind']),
|
|
109
|
+
type: text(action['type']),
|
|
110
|
+
requirement: action['requirement'],
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function actionsOf(pipe: Json | undefined): readonly Action[] {
|
|
115
|
+
const actions = Array.isArray(pipe) ? pipe : []
|
|
116
|
+
return actions
|
|
117
|
+
.map((action: Json): Action | undefined => actionOf(action))
|
|
118
|
+
.filter(
|
|
119
|
+
(action: Action | undefined): action is Action =>
|
|
120
|
+
action !== undefined && !SKIPPED_ACTIONS.has(action.kind),
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** One validation kept but with a new requirement. */
|
|
125
|
+
function requirementFinding(
|
|
126
|
+
type: string,
|
|
127
|
+
before: Json | undefined,
|
|
128
|
+
after: Json | undefined,
|
|
129
|
+
): Finding {
|
|
130
|
+
const what = `${type} ${text(before)} -> ${text(after)}`
|
|
131
|
+
if (typeof before === 'number' && typeof after === 'number') {
|
|
132
|
+
if (type.startsWith('max_')) {
|
|
133
|
+
return directed(after > before, what)
|
|
134
|
+
}
|
|
135
|
+
return type.startsWith('min_')
|
|
136
|
+
? directed(after < before, what)
|
|
137
|
+
: finding('breaking', what)
|
|
138
|
+
}
|
|
139
|
+
if (Array.isArray(before) && Array.isArray(after)) {
|
|
140
|
+
return setFinding(type, before, after)
|
|
141
|
+
}
|
|
142
|
+
return finding('review', what)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function sameAction(left: Action, right: Action): boolean {
|
|
146
|
+
return left.kind === right.kind && left.type === right.type
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function edge(action: Action, verb: 'adds' | 'drops'): Finding {
|
|
150
|
+
if (action.kind !== 'validation') {
|
|
151
|
+
return finding('review', `${verb} ${action.type}`)
|
|
152
|
+
}
|
|
153
|
+
// An added check narrows what reads; a dropped one widens it.
|
|
154
|
+
return directed(verb === 'drops', `${verb} ${action.type}`)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Pipe changes: an added check narrows, a dropped one widens, a moved limit by its direction. */
|
|
158
|
+
function pipeFindings(before: SchemaRow, after: SchemaRow): readonly Finding[] {
|
|
159
|
+
const was = actionsOf(before.facts['pipe'])
|
|
160
|
+
const now = actionsOf(after.facts['pipe'])
|
|
161
|
+
const kept = now.flatMap((action: Action): readonly Finding[] => {
|
|
162
|
+
const old = was.find((other: Action): boolean => sameAction(other, action))
|
|
163
|
+
if (old === undefined) {
|
|
164
|
+
return [edge(action, 'adds')]
|
|
165
|
+
}
|
|
166
|
+
return text(old.requirement) === text(action.requirement)
|
|
167
|
+
? []
|
|
168
|
+
: [requirementFinding(action.type, old.requirement, action.requirement)]
|
|
169
|
+
})
|
|
170
|
+
const dropped = was
|
|
171
|
+
.filter(
|
|
172
|
+
(action: Action): boolean =>
|
|
173
|
+
!now.some((other: Action): boolean => sameAction(other, action)),
|
|
174
|
+
)
|
|
175
|
+
.map((action: Action): Finding => edge(action, 'drops'))
|
|
176
|
+
return [...kept, ...dropped]
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The other facts: a literal is a break, a default, getter, predicate or async flag is for review. */
|
|
180
|
+
function factFindings(
|
|
181
|
+
path: string,
|
|
182
|
+
before: SchemaRow,
|
|
183
|
+
after: SchemaRow,
|
|
184
|
+
): readonly Finding[] {
|
|
185
|
+
const keys = new Set([
|
|
186
|
+
...Object.keys(before.facts),
|
|
187
|
+
...Object.keys(after.facts),
|
|
188
|
+
])
|
|
189
|
+
return [...keys]
|
|
190
|
+
.filter(
|
|
191
|
+
(key: string): boolean =>
|
|
192
|
+
key !== 'pipe' && text(before.facts[key]) !== text(after.facts[key]),
|
|
193
|
+
)
|
|
194
|
+
.toSorted()
|
|
195
|
+
.map((key: string): Finding => {
|
|
196
|
+
const moved = `${key} ${text(before.facts[key])} -> ${text(after.facts[key])}`
|
|
197
|
+
if (key !== 'literal') {
|
|
198
|
+
return finding('review', moved)
|
|
199
|
+
}
|
|
200
|
+
return finding(
|
|
201
|
+
'breaking',
|
|
202
|
+
moved,
|
|
203
|
+
KIND_FIELD.test(path) ? 'renameKind' : 'map',
|
|
204
|
+
)
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Every finding for one row present in both locks. */
|
|
209
|
+
function changedFindings(
|
|
210
|
+
path: string,
|
|
211
|
+
before: Row,
|
|
212
|
+
after: Row,
|
|
213
|
+
): readonly Finding[] {
|
|
214
|
+
if (before.kind === 'data' && after.kind === 'data') {
|
|
215
|
+
return text(before.value) === text(after.value)
|
|
216
|
+
? []
|
|
217
|
+
: [dataFinding(path, before, after)]
|
|
218
|
+
}
|
|
219
|
+
if (before.kind === 'schema' && after.kind === 'schema') {
|
|
220
|
+
const type = typeFinding(before, after)
|
|
221
|
+
const same = type.length === NONE
|
|
222
|
+
return [
|
|
223
|
+
...type,
|
|
224
|
+
...wrapFindings(before, after),
|
|
225
|
+
...(same ? pipeFindings(before, after) : []),
|
|
226
|
+
...(same ? factFindings(path, before, after) : []),
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
return [finding('breaking', 'a schema became plain data, or the reverse')]
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { changedFindings, OPTIONALS }
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { finding } from './format-diff-data.ts'
|
|
2
|
+
import { MARKS, normalRows } from './format-diff-normal.ts'
|
|
3
|
+
import {
|
|
4
|
+
CHAIN,
|
|
5
|
+
DEPRECATIONS,
|
|
6
|
+
lastSegment,
|
|
7
|
+
renameChange,
|
|
8
|
+
renames,
|
|
9
|
+
} from './format-diff-paths.ts'
|
|
10
|
+
import { changedFindings, OPTIONALS } from './format-diff-rules.ts'
|
|
11
|
+
|
|
12
|
+
import type {
|
|
13
|
+
Change,
|
|
14
|
+
ChangeKind,
|
|
15
|
+
Finding,
|
|
16
|
+
MigrationOp,
|
|
17
|
+
} from './format-diff-data.ts'
|
|
18
|
+
import type { LockData } from './format-diff-lock.ts'
|
|
19
|
+
import type { Row } from './format-diff-normal.ts'
|
|
20
|
+
|
|
21
|
+
// SHARD-COMPAT FE2: `shard-format format-diff <a> <b>` classifies each
|
|
22
|
+
// change between two format locks (FE1) as additive, deprecation, breaking
|
|
23
|
+
// or review, pairs a removed and an added part with the same subtree as
|
|
24
|
+
// `rename?`, and suggests an FE8 migration op. Only the topmost added or
|
|
25
|
+
// removed path is reported: a new optional object is one change, not one
|
|
26
|
+
// per field inside it. Rules per row: format-diff-rules.ts.
|
|
27
|
+
|
|
28
|
+
interface Report {
|
|
29
|
+
readonly chain:
|
|
30
|
+
| { readonly before: string; readonly after: string }
|
|
31
|
+
| undefined
|
|
32
|
+
readonly changes: readonly Change[]
|
|
33
|
+
readonly worst: ChangeKind | 'none'
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const KINDS: readonly ChangeKind[] = [
|
|
37
|
+
'breaking',
|
|
38
|
+
'review',
|
|
39
|
+
'deprecation',
|
|
40
|
+
'additive',
|
|
41
|
+
]
|
|
42
|
+
const NONE = 0
|
|
43
|
+
const NEXT = 1
|
|
44
|
+
const BEFORE = -1
|
|
45
|
+
const REMOVED: Readonly<
|
|
46
|
+
Record<string, readonly [string, MigrationOp | undefined]>
|
|
47
|
+
> = {
|
|
48
|
+
'': ['export removed', undefined],
|
|
49
|
+
'.': ['field removed', 'drop'],
|
|
50
|
+
'|': ['union option removed', 'map'],
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Whether some proper prefix of `key`, cut at a mark, is in `set`. */
|
|
54
|
+
function covered(key: string, set: ReadonlySet<string>): boolean {
|
|
55
|
+
for (let at = NEXT; at < key.length; at += NEXT) {
|
|
56
|
+
if (MARKS.has(key.charAt(at)) && set.has(key.slice(NONE, at))) {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function topmost(keys: ReadonlySet<string>): readonly string[] {
|
|
64
|
+
return [...keys]
|
|
65
|
+
.filter((key: string): boolean => !covered(key, keys))
|
|
66
|
+
.toSorted()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function fieldFinding(parent: string, row: Row | undefined): Finding {
|
|
70
|
+
if (
|
|
71
|
+
row?.kind === 'schema' &&
|
|
72
|
+
row.wrap.some((type: string): boolean => OPTIONALS.has(type))
|
|
73
|
+
) {
|
|
74
|
+
return finding('additive', 'new optional field')
|
|
75
|
+
}
|
|
76
|
+
return finding('breaking', `new required field in ${parent}`, 'fill')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function addedFinding(key: string, rows: ReadonlyMap<string, Row>): Finding {
|
|
80
|
+
if (key.startsWith(CHAIN)) {
|
|
81
|
+
return finding('additive', `new chain step ${key.slice(CHAIN.length)}`)
|
|
82
|
+
}
|
|
83
|
+
if (key.startsWith(DEPRECATIONS)) {
|
|
84
|
+
return finding(
|
|
85
|
+
'deprecation',
|
|
86
|
+
`deprecates ${key.slice(DEPRECATIONS.length)}`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
const [parent, mark] = lastSegment(key)
|
|
90
|
+
const plain: Readonly<Record<string, Finding>> = {
|
|
91
|
+
'': finding('additive', 'new export'),
|
|
92
|
+
'|': finding('additive', 'new union option'),
|
|
93
|
+
}
|
|
94
|
+
if (mark === '.') {
|
|
95
|
+
return fieldFinding(parent, rows.get(key))
|
|
96
|
+
}
|
|
97
|
+
const tuple = mark === '[' && !key.endsWith('[]')
|
|
98
|
+
return (
|
|
99
|
+
plain[mark] ??
|
|
100
|
+
(tuple
|
|
101
|
+
? finding('breaking', 'new tuple item', 'fill')
|
|
102
|
+
: finding('review', 'new part'))
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function removedFinding(key: string): Finding {
|
|
107
|
+
if (key.startsWith(CHAIN)) {
|
|
108
|
+
return finding(
|
|
109
|
+
'breaking',
|
|
110
|
+
`deletes chain step ${key.slice(CHAIN.length)} (FE13 gate)`,
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
if (key.startsWith(DEPRECATIONS)) {
|
|
114
|
+
return finding(
|
|
115
|
+
'breaking',
|
|
116
|
+
`deletes deprecated ${key.slice(DEPRECATIONS.length)} (FE13 gate)`,
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
const [, mark] = lastSegment(key)
|
|
120
|
+
const [text, op] = REMOVED[mark] ?? ['part removed', undefined]
|
|
121
|
+
return finding('breaking', text, op)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function withPath(path: string, found: Finding): Change {
|
|
125
|
+
return { path, ...found }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Rows present on both sides whose facts moved. */
|
|
129
|
+
function changedRows(
|
|
130
|
+
before: ReadonlyMap<string, Row>,
|
|
131
|
+
after: ReadonlyMap<string, Row>,
|
|
132
|
+
): readonly Change[] {
|
|
133
|
+
return [...after].flatMap(
|
|
134
|
+
([key, row]: readonly [string, Row]): readonly Change[] => {
|
|
135
|
+
const old = before.get(key)
|
|
136
|
+
if (old === undefined || JSON.stringify(old) === JSON.stringify(row)) {
|
|
137
|
+
return []
|
|
138
|
+
}
|
|
139
|
+
return changedFindings(key, old, row).map((found: Finding): Change =>
|
|
140
|
+
withPath(key, found),
|
|
141
|
+
)
|
|
142
|
+
},
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Exported functions (FE1 excludes them with a reason): a new one adds, a gone one breaks importers. */
|
|
147
|
+
function excludedChanges(before: LockData, after: LockData): readonly Change[] {
|
|
148
|
+
const added = Object.keys(after.excluded).filter(
|
|
149
|
+
(key: string): boolean => !(key in before.excluded),
|
|
150
|
+
)
|
|
151
|
+
const gone = Object.keys(before.excluded).filter(
|
|
152
|
+
(key: string): boolean => !(key in after.excluded),
|
|
153
|
+
)
|
|
154
|
+
return [
|
|
155
|
+
...added.map((key: string): Change =>
|
|
156
|
+
withPath(key, finding('additive', 'new export (not locked: function)')),
|
|
157
|
+
),
|
|
158
|
+
...gone.map((key: string): Change =>
|
|
159
|
+
withPath(key, finding('breaking', 'export removed (was a function)')),
|
|
160
|
+
),
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function worstOf(changes: readonly Change[]): ChangeKind | 'none' {
|
|
165
|
+
return (
|
|
166
|
+
KINDS.find((kind: ChangeKind): boolean =>
|
|
167
|
+
changes.some((found: Readonly<Change>): boolean => found.kind === kind),
|
|
168
|
+
) ?? 'none'
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function order(left: Readonly<Change>, right: Readonly<Change>): number {
|
|
173
|
+
const rank = KINDS.indexOf(left.kind) - KINDS.indexOf(right.kind)
|
|
174
|
+
if (rank !== NONE) {
|
|
175
|
+
return rank
|
|
176
|
+
}
|
|
177
|
+
return left.path < right.path ? BEFORE : NEXT
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Keys only one side has, topmost only; an option list (`x|`) whose node both sides hold is that node's change. */
|
|
181
|
+
function onlyIn(
|
|
182
|
+
side: ReadonlyMap<string, Row>,
|
|
183
|
+
other: ReadonlyMap<string, Row>,
|
|
184
|
+
): readonly string[] {
|
|
185
|
+
const keys = [...side.keys()].filter(
|
|
186
|
+
(key: string): boolean =>
|
|
187
|
+
!other.has(key) &&
|
|
188
|
+
!(
|
|
189
|
+
key.endsWith('|') &&
|
|
190
|
+
other.has(key.slice(NONE, BEFORE)) &&
|
|
191
|
+
side.has(key.slice(NONE, BEFORE))
|
|
192
|
+
),
|
|
193
|
+
)
|
|
194
|
+
return topmost(new Set(keys))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Every change from one lock to the next, classified. */
|
|
198
|
+
function formatDiff(before: LockData, after: LockData): Report {
|
|
199
|
+
const was = normalRows(before.rows)
|
|
200
|
+
const now = normalRows(after.rows)
|
|
201
|
+
const added = onlyIn(now, was)
|
|
202
|
+
const gone = onlyIn(was, now)
|
|
203
|
+
const pairs = renames(gone, added, [was, now])
|
|
204
|
+
const paired = new Set(pairs.values())
|
|
205
|
+
const changes = [
|
|
206
|
+
...[...pairs].map(([from, to]: readonly [string, string]): Change =>
|
|
207
|
+
renameChange(from, to),
|
|
208
|
+
),
|
|
209
|
+
...gone
|
|
210
|
+
.filter((key: string): boolean => !pairs.has(key))
|
|
211
|
+
.map((key: string): Change => withPath(key, removedFinding(key))),
|
|
212
|
+
...added
|
|
213
|
+
.filter((key: string): boolean => !paired.has(key))
|
|
214
|
+
.map((key: string): Change => withPath(key, addedFinding(key, now))),
|
|
215
|
+
...changedRows(was, now),
|
|
216
|
+
...excludedChanges(before, after),
|
|
217
|
+
].toSorted(order)
|
|
218
|
+
const chain =
|
|
219
|
+
before.chainId === after.chainId
|
|
220
|
+
? undefined
|
|
221
|
+
: { before: before.chainId, after: after.chainId }
|
|
222
|
+
return { chain, changes, worst: worstOf(changes) }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { formatDiff, KINDS }
|
|
226
|
+
export type { Report }
|
package/src/cli/main.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFile } from 'node:fs/promises'
|
|
3
2
|
import { parseArgs } from 'node:util'
|
|
4
3
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { corpusCommand } from './corpus-command.ts'
|
|
5
|
+
import { readLock } from './format-diff-lock.ts'
|
|
6
|
+
import { isRange, rangeOutput } from './format-diff-range.ts'
|
|
7
|
+
import { formatDiffReport } from './format-diff-report.ts'
|
|
8
|
+
import { formatDiff } from './format-diff.ts'
|
|
7
9
|
import { packFolder } from './pack.ts'
|
|
8
10
|
import { summary, validateShardfile } from './validate.ts'
|
|
9
11
|
import { readVersion } from './version.ts'
|
|
@@ -13,12 +15,12 @@ const EXIT_USAGE = 1
|
|
|
13
15
|
const EXIT_CRASH = 2
|
|
14
16
|
const EXIT_INVALID = 3
|
|
15
17
|
const NONE = 0
|
|
18
|
+
const JSON_INDENT = 1
|
|
16
19
|
|
|
17
20
|
// Arguments start after [node, script] in process.argv.
|
|
18
21
|
const FIRST_CLI_ARG = 2
|
|
19
22
|
const DEFAULT_API = 'https://api.wildshard.io'
|
|
20
23
|
const DEFAULT_CACHE = 'tmp/corpus'
|
|
21
|
-
const KNOWN_FAILURES = 'corpus/known-failures.json'
|
|
22
24
|
|
|
23
25
|
const USAGE = `Usage: shard-format <command> [options]
|
|
24
26
|
|
|
@@ -30,10 +32,23 @@ Commands:
|
|
|
30
32
|
Tar a folder into a shardfile: what its sections
|
|
31
33
|
measure follows them, and format's validator must
|
|
32
34
|
pass. Writes <slug>.tar by default
|
|
33
|
-
corpus [--api <url>] [--cache <dir>]
|
|
35
|
+
corpus [--api <url>] [--cache <dir>] [--usage <file>] [--pins <file|url>]
|
|
36
|
+
[--candidate <module>] [--only <slug,...>]
|
|
34
37
|
Validate every stored shard file the API keeps,
|
|
35
38
|
as stored originals; list every failure. Exits 3
|
|
36
|
-
when any fails
|
|
39
|
+
when any fails. --usage writes who uses each
|
|
40
|
+
deprecated path and chain step (FE13 reads it)
|
|
41
|
+
--candidate <module> judges each original again
|
|
42
|
+
under a candidate chain and validator (FE3b):
|
|
43
|
+
valid, migrates or fails by path; --only <slugs>
|
|
44
|
+
limits the run to those shards (slug@r5: one
|
|
45
|
+
revision)
|
|
46
|
+
format-diff <a> <b> [--json]
|
|
47
|
+
format-diff <a>..<b> [--json] (FE6) each lock change in the range, then the net delta
|
|
48
|
+
Classify every change between two format locks
|
|
49
|
+
(a git ref or a folder holding src/format/lock):
|
|
50
|
+
additive, deprecation, breaking or review, with
|
|
51
|
+
rename? pairs and a suggested migration op
|
|
37
52
|
|
|
38
53
|
Options:
|
|
39
54
|
--version Print the version
|
|
@@ -48,6 +63,11 @@ interface CliArgs {
|
|
|
48
63
|
readonly api: string
|
|
49
64
|
readonly cache: string
|
|
50
65
|
readonly version: boolean
|
|
66
|
+
readonly json: boolean
|
|
67
|
+
readonly usage: string | undefined
|
|
68
|
+
readonly pins: string | undefined
|
|
69
|
+
readonly candidate: string | undefined
|
|
70
|
+
readonly only: string | undefined
|
|
51
71
|
}
|
|
52
72
|
|
|
53
73
|
function parseCliArgs(argv: readonly string[]): CliArgs {
|
|
@@ -60,6 +80,11 @@ function parseCliArgs(argv: readonly string[]): CliArgs {
|
|
|
60
80
|
api: { type: 'string', default: DEFAULT_API },
|
|
61
81
|
cache: { type: 'string', default: DEFAULT_CACHE },
|
|
62
82
|
version: { type: 'boolean', default: false },
|
|
83
|
+
json: { type: 'boolean', default: false },
|
|
84
|
+
usage: { type: 'string' },
|
|
85
|
+
pins: { type: 'string' },
|
|
86
|
+
candidate: { type: 'string' },
|
|
87
|
+
only: { type: 'string' },
|
|
63
88
|
},
|
|
64
89
|
})
|
|
65
90
|
const [command, ...operands] = positionals
|
|
@@ -71,6 +96,11 @@ function parseCliArgs(argv: readonly string[]): CliArgs {
|
|
|
71
96
|
api: values.api,
|
|
72
97
|
cache: values.cache,
|
|
73
98
|
version: values.version,
|
|
99
|
+
json: values.json,
|
|
100
|
+
usage: values.usage,
|
|
101
|
+
pins: values.pins,
|
|
102
|
+
candidate: values.candidate,
|
|
103
|
+
only: values.only,
|
|
74
104
|
}
|
|
75
105
|
}
|
|
76
106
|
|
|
@@ -129,40 +159,59 @@ async function pack(args: CliArgs): Promise<number> {
|
|
|
129
159
|
return await packReport(dir, args.out)
|
|
130
160
|
}
|
|
131
161
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
process.stdout.write(`${corpusReport(rows)}\n`)
|
|
143
|
-
// SHARD-COMPAT FE5: only a failure not listed with its owner blocks a release.
|
|
144
|
-
const listed = await readFile(KNOWN_FAILURES, 'utf8').catch(
|
|
145
|
-
(): string => '[]',
|
|
162
|
+
/** `format-diff <a> <b>`: the two locks' report, as text or JSON. */
|
|
163
|
+
async function pairOutput(
|
|
164
|
+
before: string,
|
|
165
|
+
after: string,
|
|
166
|
+
json: boolean,
|
|
167
|
+
): Promise<string> {
|
|
168
|
+
const cwd = process.cwd()
|
|
169
|
+
const report = formatDiff(
|
|
170
|
+
await readLock(before, cwd),
|
|
171
|
+
await readLock(after, cwd),
|
|
146
172
|
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
return json
|
|
174
|
+
? JSON.stringify(report, undefined, JSON_INDENT)
|
|
175
|
+
: formatDiffReport(report)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function formatDiffCommand(args: CliArgs): Promise<number> {
|
|
179
|
+
const [before, after, ...extra] = args.operands
|
|
180
|
+
if (before !== undefined && isRange(before) && after === undefined) {
|
|
181
|
+
process.stdout.write(`${await rangeOutput(before, args.json)}\n`)
|
|
182
|
+
return EXIT_OK
|
|
150
183
|
}
|
|
151
|
-
|
|
184
|
+
if (before === undefined || after === undefined || extra.length > NONE) {
|
|
185
|
+
process.stderr.write(
|
|
186
|
+
`shard-format: format-diff takes two locks\n\n${USAGE}`,
|
|
187
|
+
)
|
|
188
|
+
return EXIT_USAGE
|
|
189
|
+
}
|
|
190
|
+
process.stdout.write(`${await pairOutput(before, after, args.json)}\n`)
|
|
191
|
+
return EXIT_OK
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const COMMANDS: Readonly<Record<string, (args: CliArgs) => Promise<number>>> = {
|
|
195
|
+
validate: async (args: CliArgs): Promise<number> =>
|
|
196
|
+
await validate(args.operands),
|
|
197
|
+
pack,
|
|
198
|
+
corpus: async (args: CliArgs): Promise<number> => {
|
|
199
|
+
if (args.operands.length > NONE) {
|
|
200
|
+
process.stderr.write(`shard-format: corpus takes no operands\n\n${USAGE}`)
|
|
201
|
+
return EXIT_USAGE
|
|
202
|
+
}
|
|
203
|
+
return await corpusCommand(args)
|
|
204
|
+
},
|
|
205
|
+
'format-diff': formatDiffCommand,
|
|
152
206
|
}
|
|
153
207
|
|
|
154
208
|
async function runCommand(args: CliArgs): Promise<number> {
|
|
155
209
|
if (args.command === undefined) {
|
|
156
210
|
return printUsage(EXIT_USAGE)
|
|
157
211
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (args.command === 'pack') {
|
|
162
|
-
return await pack(args)
|
|
163
|
-
}
|
|
164
|
-
if (args.command === 'corpus') {
|
|
165
|
-
return await corpus(args)
|
|
212
|
+
const command = COMMANDS[args.command]
|
|
213
|
+
if (command !== undefined) {
|
|
214
|
+
return await command(args)
|
|
166
215
|
}
|
|
167
216
|
process.stderr.write(
|
|
168
217
|
`shard-format: unknown command ${args.command}\n\n${USAGE}`,
|
package/src/cli/pack.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
parseOutputIndex,
|
|
8
8
|
} from '../format/outputIndex.ts'
|
|
9
9
|
import { receiptCost } from '../format/receipt-cost.ts'
|
|
10
|
+
import { asWrittenIdentity } from '../format/save-revision.ts'
|
|
10
11
|
import { packFromMembers } from '../format/shardfile-reads.ts'
|
|
11
12
|
import { writeTar } from '../format/tar.ts'
|
|
12
13
|
import { validationSourceBytes } from '../format/validationReceipt.ts'
|
|
@@ -56,6 +57,9 @@ interface PackRow extends Listed {
|
|
|
56
57
|
/** The rows of `shard.json` this reads; the rest passes through. */
|
|
57
58
|
interface HeldIndex {
|
|
58
59
|
readonly build: Readonly<{ sourceHash: string }>
|
|
60
|
+
/** FP26: which spelling of the save lineage the hashes cover. */
|
|
61
|
+
readonly formatVersion?: unknown
|
|
62
|
+
readonly identity?: unknown
|
|
59
63
|
readonly files: readonly Listed[]
|
|
60
64
|
readonly packs?: readonly PackRow[] | undefined
|
|
61
65
|
readonly schemas?: readonly Listed[] | undefined
|
|
@@ -197,7 +201,21 @@ function sourceHash(index: HeldIndex, files: Files): string {
|
|
|
197
201
|
jsonOf(held(files, row.path)),
|
|
198
202
|
]),
|
|
199
203
|
)
|
|
200
|
-
|
|
204
|
+
// FP26: an older format's hash covers the identity as it wrote it (`revision`).
|
|
205
|
+
const shard = assembleOutputShardfile(index, payloads)
|
|
206
|
+
return sha256(
|
|
207
|
+
validationSourceBytes(asWrittenIdentity(shard, index.formatVersion)),
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** `shard.json` with its new source hash, the save lineage spelled as its format writes it (FP26). */
|
|
212
|
+
function indexBytes(index: HeldIndex, source: string): Uint8Array {
|
|
213
|
+
const build = { ...index.build, sourceHash: source }
|
|
214
|
+
const written = asWrittenIdentity(
|
|
215
|
+
{ ...index, identity: index.identity, build },
|
|
216
|
+
index.formatVersion,
|
|
217
|
+
)
|
|
218
|
+
return validationSourceBytes(written)
|
|
201
219
|
}
|
|
202
220
|
|
|
203
221
|
/** The index's bytes, and the receipt that names them. */
|
|
@@ -206,8 +224,7 @@ function sealed(
|
|
|
206
224
|
files: Files,
|
|
207
225
|
): readonly (readonly [string, Uint8Array])[] {
|
|
208
226
|
const source = sourceHash(index, files)
|
|
209
|
-
const
|
|
210
|
-
const bytes = validationSourceBytes({ ...index, build })
|
|
227
|
+
const bytes = indexBytes(index, source)
|
|
211
228
|
const receipt = files.get(RECEIPT)
|
|
212
229
|
if (receipt === undefined) {
|
|
213
230
|
return [[INDEX, bytes]]
|
package/src/cli/validate.ts
CHANGED
|
@@ -188,7 +188,7 @@ async function validateShardfile(target: string): Promise<ValidationSummary> {
|
|
|
188
188
|
)
|
|
189
189
|
return {
|
|
190
190
|
slug: valid.shard.identity.slug,
|
|
191
|
-
revision: valid.shard.identity.
|
|
191
|
+
revision: valid.shard.identity.saveRevision,
|
|
192
192
|
sections: valid.sections.size,
|
|
193
193
|
assets: valid.assets.size,
|
|
194
194
|
sourceHash: valid.index.build.sourceHash,
|