@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.
Files changed (73) hide show
  1. package/package.json +21 -3
  2. package/src/cli/corpus-candidate.ts +228 -0
  3. package/src/cli/corpus-command.ts +67 -0
  4. package/src/cli/corpus-pins.ts +73 -0
  5. package/src/cli/corpus-report.ts +36 -0
  6. package/src/cli/corpus-tar.ts +28 -0
  7. package/src/cli/corpus-usage.ts +106 -0
  8. package/src/cli/corpus.ts +50 -68
  9. package/src/cli/format-diff-data.ts +89 -0
  10. package/src/cli/format-diff-lock.ts +122 -0
  11. package/src/cli/format-diff-normal.ts +300 -0
  12. package/src/cli/format-diff-paths.ts +103 -0
  13. package/src/cli/format-diff-range.ts +112 -0
  14. package/src/cli/format-diff-report.ts +30 -0
  15. package/src/cli/format-diff-rules.ts +232 -0
  16. package/src/cli/format-diff.ts +226 -0
  17. package/src/cli/main.ts +81 -32
  18. package/src/cli/pack.ts +20 -3
  19. package/src/cli/validate.ts +1 -1
  20. package/src/format/clientOwnership.ts +1 -1
  21. package/src/format/clientTrails.ts +121 -46
  22. package/src/format/cook-data.ts +22 -3
  23. package/src/format/cook-deprecations.ts +53 -0
  24. package/src/format/cook-preparation.ts +105 -70
  25. package/src/format/creature-rest-rig.ts +248 -0
  26. package/src/format/creature-skin-bounds.ts +146 -0
  27. package/src/format/deprecations.ts +30 -21
  28. package/src/format/edge-observations.ts +67 -0
  29. package/src/format/empty-shardfile.ts +4 -2
  30. package/src/format/entry-read-set.ts +147 -0
  31. package/src/format/format-migrate-rebuild.ts +4 -1
  32. package/src/format/format-migrate.ts +10 -5
  33. package/src/format/format-migration-envelope.ts +40 -0
  34. package/src/format/format-migration-prune.ts +42 -1
  35. package/src/format/format-migrations.ts +10 -1
  36. package/src/format/format-window.ts +71 -0
  37. package/src/format/immutable.ts +4 -1
  38. package/src/format/json-schema.ts +1468 -0
  39. package/src/format/lootEconomy.ts +4 -1
  40. package/src/format/mat4.ts +225 -0
  41. package/src/format/memory-armed.json +1 -9
  42. package/src/format/memory-armed.ts +46 -17
  43. package/src/format/memory-epoch.ts +10 -3
  44. package/src/format/memory-line.ts +17 -6
  45. package/src/format/outputFields.ts +3 -2
  46. package/src/format/outputIndex.ts +41 -6
  47. package/src/format/platformDataSections.ts +5 -0
  48. package/src/format/platformFileFamilies.ts +3 -3
  49. package/src/format/play-area.ts +95 -0
  50. package/src/format/policy-verdict.ts +12 -2
  51. package/src/format/preparation-checks.ts +100 -0
  52. package/src/format/preparation-spec.ts +45 -0
  53. package/src/format/registeredJson.ts +2 -2
  54. package/src/format/runtime-tier.ts +14 -7
  55. package/src/format/save-revision.ts +105 -0
  56. package/src/format/schema-source.ts +70 -0
  57. package/src/format/sections.ts +4 -1
  58. package/src/format/server-plan.ts +42 -0
  59. package/src/format/server-reads.ts +23 -0
  60. package/src/format/shardSchema.ts +9 -4
  61. package/src/format/shardSections.ts +17 -7
  62. package/src/format/shardfile-assets.ts +5 -5
  63. package/src/format/shardfile-stream-admit.ts +19 -10
  64. package/src/format/shardfile-stream-facts.ts +2 -1
  65. package/src/format/shardfile-stream.ts +2 -3
  66. package/src/format/shardfileValidation.ts +16 -9
  67. package/src/format/species-deprecations.ts +79 -0
  68. package/src/format/stateLineage.ts +15 -7
  69. package/src/format/tread-boxes.ts +65 -0
  70. package/src/format/vehicle-hulls.ts +124 -0
  71. package/src/format/version.ts +96 -10
  72. package/src/format/whole-inputs.ts +51 -0
  73. package/src/tools/runtime-hosts.json +4 -0
@@ -0,0 +1,1468 @@
1
+ // The one JSON Schema projection of the format's valibot schemas (FORMAT-PRUNE FP9). Engine and the SDK import it from
2
+ // here; it moved byte for byte from the SDK's sharddev/formatJsonSchema.ts (once engine's host/formatJsonSchema), so its
3
+ // lint debt is waived below rather than counted, and it pays down as the file is touched.
4
+ /* oxlint-disable complexity, curly, max-lines, max-lines-per-function, max-statements, no-continue, no-magic-numbers, no-nested-ternary, no-use-before-define, prefer-destructuring, sort-vars, import/consistent-type-specifier-style, import/exports-last, import/group-exports, import/max-dependencies, typescript/explicit-function-return-type, typescript/no-unsafe-type-assertion, typescript/prefer-readonly-parameter-types, unicorn/consistent-function-scoping, unicorn/no-array-callback-reference, unicorn/no-immediate-mutation, unicorn/no-nested-ternary, unicorn/no-useless-undefined, unicorn/numeric-separators-style -- moved from the SDK as it was (FORMAT-PRUNE FP9); FP9 pays this down as rows touch it */
5
+ // oxlint-disable unicorn/prefer-string-raw -- Its patterns are schema bytes, kept as sharddev wrote them.
6
+
7
+ import { toJsonSchema, type JsonSchema } from '@valibot/to-json-schema'
8
+ import { finite, type GenericSchema } from 'valibot'
9
+
10
+ import { AccentSchema, ACCENT_IDS } from './accent.ts'
11
+ import { AchievementCounterDataSchema } from './achievementCounters.ts'
12
+ import { ActorMovesSchema } from './actorMoves.ts'
13
+ import { SHARDFILE_ADMISSION_LIMITS } from './admissionLimits.ts'
14
+ import { ForestLifeSchema } from './ambientLife.ts'
15
+ import {
16
+ ArenaRoomDocumentSchema,
17
+ ArenaRoomDocumentRowsSchema,
18
+ ArenaKingRowsSchema,
19
+ } from './arenaRoomDocument.ts'
20
+ import {
21
+ ArenaScriptFightFileSchema,
22
+ ArenaScriptGeometrySchema,
23
+ } from './arenaScriptRows.ts'
24
+ import { AudioDataSchema } from './audio.ts'
25
+ import {
26
+ AudioMusicSchema,
27
+ AudioSamplesSchema,
28
+ AudioZonesSchema,
29
+ } from './audioProfiles.ts'
30
+ import { AudioRoutingSchema } from './audioRouting.ts'
31
+ import { AudioSceneSchema } from './audioScene.ts'
32
+ import { BakedPlacementPlanSchema } from './bakedTiles.ts'
33
+ import { BinarySourceSchema } from './binarySource.ts'
34
+ import { BodySlotsSchema } from './bodySlots.ts'
35
+ import {
36
+ RoamingEncounterSchema,
37
+ WakeEncounterSchema,
38
+ BossEncounterPresentationSchema,
39
+ NativeBossBindingSchema,
40
+ } from './bossEncounter.ts'
41
+ import {
42
+ BossProfileSchema,
43
+ ArenaBossProfileSchema,
44
+ RoamingBossProfileSchema,
45
+ SpawnedBossProfileSchema,
46
+ HeldBossProfileSchema,
47
+ ScriptBossProfileSchema,
48
+ } from './bossProfiles.ts'
49
+ import { BowVariantSchema } from './bowVariantRows.ts'
50
+ import {
51
+ StalkerSchema,
52
+ GuardianPatternsSchema,
53
+ SkirmisherSchema,
54
+ ScriptBrainSchema,
55
+ GuardianSchema,
56
+ PerchHunterSchema,
57
+ } from './brains.ts'
58
+ import {
59
+ BuildingLifeDocumentSchema,
60
+ BakedBuildingLookSchema,
61
+ BuildingLifeLookSchema,
62
+ BuildingLifeRowsSchema,
63
+ BuildingCloudPoseSchema,
64
+ } from './buildings.ts'
65
+ import { CatalogueEconomySchema } from './catalogueEconomy.ts'
66
+ import { CaveFileSchema, CaveInteriorSchema } from './caveInterior.ts'
67
+ import { ChapterDirectorSchema, ChapterWakeSchema } from './chapterDirector.ts'
68
+ import {
69
+ HeldMeleeActionSchema,
70
+ ClientChannelsSchema,
71
+ ClientChannelProgramSchema,
72
+ PrivateSceneSchema,
73
+ WorldSceneSchema,
74
+ NumericPoseSchema,
75
+ } from './clientChannels.ts'
76
+ import { RuntimeBoundsSchema } from './clientPlan.ts'
77
+ import { ClientScriptsSchema } from './clientScripts.ts'
78
+ import {
79
+ ClientCheckpointSchema,
80
+ ItemCheckpointStatesSchema,
81
+ LogicalClientCheckpointSchema,
82
+ } from './clientState.ts'
83
+ import { CommonsCostsSchema } from './commonsCosts.ts'
84
+ import { ContractCatalogueSchema } from './contracts.ts'
85
+ import { CoverAppearanceSchema } from './coverAppearance.ts'
86
+ import {
87
+ CreaturesSchema,
88
+ CreatureHomeSchema,
89
+ CreatureStrikeSchema,
90
+ } from './creatures.ts'
91
+ import { FlockSchema } from './crowds.ts'
92
+ import { CueDirectorWireSchema } from './cueDirector.ts'
93
+ import { DecisionScriptsSchema } from './decisionScripts.ts'
94
+ import { DirectorSchema } from './director.ts'
95
+ import { DirectorDocumentSchema } from './directorDocument.ts'
96
+ import { DirectorStagesSchema } from './directorStages.ts'
97
+ import { EdgeProfileSchema, EdgeProfilesSchema } from './edgeProfiles.ts'
98
+ import { EliteFeatureSchema } from './eliteFeature.ts'
99
+ import { EliteScriptSchema } from './eliteScripts.ts'
100
+ import {
101
+ TimedEncountersSchema,
102
+ CloudSpecimenSchema,
103
+ CloudBodySchema,
104
+ } from './encounterRows.ts'
105
+ import { EncountersSchema } from './encounters.ts'
106
+ import { EntrywaysSchema } from './entryways.ts'
107
+ import { ExchangeSchema } from './exchange.ts'
108
+ import { FigureCatalogueSchema, FigureGroupSchema } from './figures.ts'
109
+ import { FindsCatalogueSchema } from './findsCatalogue.ts'
110
+ import { FixedDrawRowsSchema } from './fixedDraws.ts'
111
+ import {
112
+ DiverSchema,
113
+ OrbitDiverSchema,
114
+ PatrolDiverSchema,
115
+ BurstFlyerSchema,
116
+ } from './flyers.ts'
117
+ import { ForestNativeInputsSchema } from './forestNativeInputs.ts'
118
+ import {
119
+ ForestGroundLayoutSchema,
120
+ ForestPageSchema,
121
+ LivingPageSitesSchema,
122
+ } from './forestPage.ts'
123
+ import { ForestWeatherSchema } from './forestWeather.ts'
124
+ import { GraphArmsSchema } from './graphArmsRows.ts'
125
+ import {
126
+ RamGrazerSchema,
127
+ ChallengeGrazerSchema,
128
+ GrazerSchema,
129
+ } from './grazers.ts'
130
+ import { GroupBrainSchema } from './groupBrains.ts'
131
+ import {
132
+ ToonArmsLookSchema,
133
+ HeldArmsSchema,
134
+ HeldGraphCardsSchema,
135
+ } from './heldArms.ts'
136
+ import { HeldFinishesSchema } from './heldFinishes.ts'
137
+ import { HeldJianDocumentSchema } from './heldJianDocument.ts'
138
+ import { HeldCueSchema, ArcWeaponItemSchema } from './heldMelee.ts'
139
+ import {
140
+ BladeDocumentSchema,
141
+ PolearmDocumentSchema,
142
+ HeldSlotsDocumentSchema,
143
+ } from './heldWeaponDocuments.ts'
144
+ import { PopulationShelterSchema } from './herdShelter.ts'
145
+ import { HooksSchema } from './hooks.ts'
146
+ import { InputActionSchema, InputKeysSchema } from './inputDeclarations.ts'
147
+ import { FixedGeometryGroupsSchema } from './islandLibrary.ts'
148
+ import { ItemsSchema, ItemFamilyNameSchema } from './items.ts'
149
+ import { LedgerFactSchema, LedgerRulesSchema } from './ledger.ts'
150
+ import { LiftRiderSchema } from './liftRider.ts'
151
+ import { LimbCollisionBake } from './limbCollision.ts'
152
+ import { LimbRigSchema, LimbBlendSchema, BakedClipTable } from './limbRig.ts'
153
+ import { LootBagSchema } from './lootBag.ts'
154
+ import { MeshCollisionSchema } from './meshCollision.ts'
155
+ import { LogicalStateSchema, MigrationsSchema } from './migrations.ts'
156
+ import { PerchBodyFileSchema } from './mixedPopulation.ts'
157
+ import {
158
+ ModesSchema,
159
+ ZiplineModeSchema,
160
+ UpdraftModeSchema,
161
+ RideGaitsSchema,
162
+ RideModeSchema,
163
+ GrappleModeSchema,
164
+ TraverseModeSchema,
165
+ } from './modes.ts'
166
+ import { MountedSpecimenSeatSchema } from './mountedSpecimenRows.ts'
167
+ import {
168
+ MoverMotionSchema,
169
+ MoverTrackSchema,
170
+ MoverTriggerSchema,
171
+ MoverDriverSchema,
172
+ } from './moverMotion.ts'
173
+ import { MoversSchema } from './movers.ts'
174
+ import {
175
+ AdventurePersistenceSchema,
176
+ ReturnProgramSchema,
177
+ PageReturnRowsSchema,
178
+ QuestTraderSchema,
179
+ PosedLibrarySchema,
180
+ } from './namedJsonContracts.ts'
181
+ import { NativeGroundSchema } from './nativeGround.ts'
182
+ import { NativeGroundFileSchema } from './nativePhysics.ts'
183
+ import {
184
+ NativeQuestCompositionSchema,
185
+ NativeQuestServiceSpotsSchema,
186
+ } from './nativeQuestComposition.ts'
187
+ import { NavigationSchema } from './navigation.ts'
188
+ import {
189
+ NpcRowSchema,
190
+ NpcMotionSchema,
191
+ NpcDialogueRowSchema,
192
+ QuestNpcBindingSchema,
193
+ QuestNpcBindingsSchema,
194
+ } from './npcs.ts'
195
+ import { PageLifeSchema } from './pageLife.ts'
196
+ import {
197
+ PaintedAirSchema,
198
+ PaintedGroundSchema,
199
+ PaintedPanoramaSchema,
200
+ PainterKeyLightSchema,
201
+ PainterlyWorldSchema,
202
+ } from './paintedResources.ts'
203
+ import {
204
+ PanelDefinitionSchema,
205
+ QuestPanelCatalogueSchema,
206
+ } from './panelTemplate.ts'
207
+ import { PlumbingSchema } from './plumbing.ts'
208
+ import {
209
+ PopulationFieldSchema,
210
+ PopulationHabitatSchema,
211
+ } from './populationEnvironment.ts'
212
+ import { PopulationKeeperRowsSchema } from './populationKeeper.ts'
213
+ import {
214
+ PopulationProjectionSchema,
215
+ EnemyPlacementsSchema,
216
+ } from './populationProjection.ts'
217
+ import {
218
+ NativePopulationRowsSchema,
219
+ TamingPoseFileSchema,
220
+ } from './populationRoster.ts'
221
+ import { PortalLinkSchema } from './portalLink.ts'
222
+ import {
223
+ PostGraphLookSchema,
224
+ ScaledPostInputSchema,
225
+ postGraphIdentityTransforms,
226
+ } from './postGraphLook.ts'
227
+ import {
228
+ PracticeSceneSchema,
229
+ RidingPracticeSchema,
230
+ PracticeControllerSchema,
231
+ FixedPracticeFileSchema,
232
+ } from './practiceCourseRows.ts'
233
+ import { PresentationSchema } from './presentation.ts'
234
+ import { QuestContinuationSchema } from './questContinuation.ts'
235
+ import { QuestFiguresSchema, KitFigureCardsSchema } from './questFigures.ts'
236
+ import { QuestGraphSchema } from './questGraph.ts'
237
+ import { QuestHostSchema } from './questHost.ts'
238
+ import {
239
+ InteractionRowsSchema,
240
+ QuestPageInteractionsSchema,
241
+ } from './questInteractions.ts'
242
+ import { QuestInteractionSourceSchema } from './questInteractionSource.ts'
243
+ import {
244
+ QuestPageSchema,
245
+ QuestPageCompositionSchema,
246
+ ChapterViewSchema,
247
+ } from './questPageComposition.ts'
248
+ import { QuestRuntimeDocumentSchema } from './questRuntime.ts'
249
+ import { QuestDataSchema } from './quests.ts'
250
+ import {
251
+ QuestStepRowsSchema,
252
+ QuestServiceActionsSchema,
253
+ QuestKillRowsSchema,
254
+ QuestHintRowsSchema,
255
+ CarriedQuestSchema,
256
+ } from './questSteps.ts'
257
+ import {
258
+ QuestStorySchema,
259
+ ChapterStoryPresentationSchema,
260
+ AdventureContentSchema,
261
+ } from './questStory.ts'
262
+ import { QuestStoryBindingsSchema } from './questStoryBindings.ts'
263
+ import { QuestWorldSchema } from './questWorld.ts'
264
+ import { RainPresentationSchema } from './rainPresentation.ts'
265
+ import {
266
+ ForestWeatherObservationSchema,
267
+ RangedPageSchema,
268
+ } from './rangedPage.ts'
269
+ import {
270
+ registeredJsonContract,
271
+ type RegisteredSchemaJsonName,
272
+ } from './registeredJson.ts'
273
+ import {
274
+ ReturnProgramDocumentSchema,
275
+ ReturnProgramWireDocumentSchema,
276
+ } from './returnProgramDocument.ts'
277
+ import { ReturnProjectionV2Schema } from './returnProjectionV2.ts'
278
+ import { ClientRidingSessionSchema } from './riding.ts'
279
+ import { RoamingCombatSchema } from './roamingCombat.ts'
280
+ import { RowsSchema } from './rows.ts'
281
+ import { RuntimeSchema, ClientPlanRuntimeSchema } from './runtime.ts'
282
+ import { RuntimeBindsSchema } from './runtimeBinds.ts'
283
+ import {
284
+ MemoryMeasurementSchema,
285
+ RuntimeCostSchema,
286
+ RegionalSimCostSchema,
287
+ } from './runtimeCost.ts'
288
+ import { RuntimeSpawnsSchema } from './runtimeSpawns.ts'
289
+ import {
290
+ ScalarChannelSchema,
291
+ ScalarLatticeSchema,
292
+ ScalarTripletSchema,
293
+ } from './scalarChannel.ts'
294
+ import { SceneBuffersSchema } from './sceneBuffers.ts'
295
+ import {
296
+ SceneScatterPageSchema,
297
+ SceneDressingSchema,
298
+ SceneBakedGeometrySchema,
299
+ } from './sceneDressing.ts'
300
+ import {
301
+ SceneModelSourceSchema,
302
+ SceneBakeSourceSchema,
303
+ } from './sceneSources.ts'
304
+ import { ReturnModulesSchema } from './scriptContract.ts'
305
+ import { ScriptBindingsSchema } from './scripts.ts'
306
+ import {
307
+ ShardNaturalSchema,
308
+ ShardFiniteSchema,
309
+ ShardHashSchema,
310
+ ShardReferenceSchema,
311
+ ShardReferencesSchema,
312
+ ShardNamesSchema,
313
+ CellBoundsSchema,
314
+ IdentitySchema,
315
+ RequiresSchema,
316
+ BudgetsSchema,
317
+ SimSchema,
318
+ AuthorCapsSchema,
319
+ ServerBudgetSchema,
320
+ FilesSchema,
321
+ TilesSchema,
322
+ LibrarySchema,
323
+ CriticalSchema,
324
+ FarSchema,
325
+ SpawnSchema,
326
+ } from './shardSections.ts'
327
+ import {
328
+ CreatureSkinClipNameSchema,
329
+ SkinClipNameSchema,
330
+ SkinRowSchema,
331
+ SkinBindingSchema,
332
+ } from './skinData.ts'
333
+ import { SkinPoseLayerSchema } from './skinLayers.ts'
334
+ import {
335
+ SkinLookParametersSchema,
336
+ SkinClipParametersSchema,
337
+ ShardSkinFileSchema,
338
+ } from './skins.ts'
339
+ import { SocketLiftSchema } from './socketLift.ts'
340
+ import { SpeciesActorsFileSchema as SpeciesActorsDocumentSchema } from './speciesActorsFile.ts'
341
+ import { SpeciesActorsFileSchema } from './speciesBookRows.ts'
342
+ import {
343
+ CreatureInstallSchema,
344
+ PackedCreatureLooksSchema,
345
+ } from './speciesLooks.ts'
346
+ import { SpeciesSchema, NativeHuntSchema } from './speciesPrograms.ts'
347
+ import { ScriptSpeciesSchema } from './speciesScripts.ts'
348
+ import { SpecimenBookSchema } from './specimenCatalogue.ts'
349
+ import { StateSchema } from './state.ts'
350
+ import { StreamedCoverSchema, CoverCompositionSchema } from './streamedCover.ts'
351
+ import { StrikeDebrisJsonGuard } from './strike-debris.ts'
352
+ import { TargetsSchema } from './targets.ts'
353
+ import { TerrainSchema, ForestRowsSchema, GroundRowsSchema } from './terrain.ts'
354
+ import { TraversalSchema } from './traversal.ts'
355
+ import { UiSchema } from './ui.ts'
356
+ import { uniformIdentityTransforms } from './uniformRows.ts'
357
+ import { WaterSchema } from './water.ts'
358
+ import { WaterWorldSchema } from './waterWorld.ts'
359
+ import {
360
+ WeaponProfileSchema,
361
+ MeleeWeaponProfileSchema,
362
+ BowWeaponProfileSchema,
363
+ FirearmWeaponProfileSchema,
364
+ ThrownWeaponProfileSchema,
365
+ LashWeaponProfileSchema,
366
+ ConeWeaponProfileSchema,
367
+ HeldBowBaseSchema,
368
+ HeldBowRowsSchema,
369
+ HeldBowDefinitionSchema,
370
+ HeldBowFileSchema,
371
+ HeldFirearmPageSchema,
372
+ } from './weaponProfiles.ts'
373
+ import { WeatherBundleSchema, WeatherDocumentSchema } from './weatherBundle.ts'
374
+ import {
375
+ WeatherEffectsSchema,
376
+ WeatherGeometrySchema,
377
+ WeatherGeometryDataSchema,
378
+ } from './weatherEffects.ts'
379
+ import { WeatherProgramSchema, WeatherHitTagSchema } from './weatherProgram.ts'
380
+ import { WildlifePopulationSchema } from './wildlifePopulation.ts'
381
+ import { WorldAssemblySchema } from './worldAssembly.ts'
382
+ import { WorldSceneModelsSchema } from './worldSceneModels.ts'
383
+ import { WorldScenePageSchema } from './worldScenePages.ts'
384
+ import {
385
+ WorldScenePlacementSchema,
386
+ WorldScenePlacementPageSchema,
387
+ } from './worldScenePlacement.ts'
388
+ import {
389
+ WorldSceneWeldSchema,
390
+ WorldSceneWeldNodeSchema,
391
+ } from './worldSceneWeld.ts'
392
+ import { WorldUpdatesSchema } from './worldUpdates.ts'
393
+
394
+ /** JSON Schema plus explicit admission checks that JSON Schema cannot express. */
395
+ export interface FormatJsonSchema extends JsonSchema {
396
+ 'x-wildshard-checks'?: string[]
397
+ 'x-wildshard-string-length'?: 'utf16-code-units'
398
+ }
399
+
400
+ const plumbing = PlumbingSchema.pipe[2]
401
+ const input = plumbing.entries.input.pipe[0].item
402
+ const debug = plumbing.entries.debug.pipe[0].item
403
+ // These identities are the defining schemas, not message-based permissions for arbitrary author code.
404
+ const customSchemas = new Map<object, FormatJsonSchema>([
405
+ [
406
+ WeatherHitTagSchema,
407
+ { type: 'string', pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.*-]+$' },
408
+ ],
409
+ [
410
+ InputActionSchema.options[1],
411
+ {
412
+ type: 'string',
413
+ maxLength: 128,
414
+ pattern: '^[a-z][a-zA-Z0-9-]*(?:\\.[a-zA-Z0-9-]+)+$',
415
+ },
416
+ ],
417
+ [
418
+ input.entries.id,
419
+ {
420
+ type: 'string',
421
+ maxLength: 128,
422
+ pattern: '^[a-z][a-z0-9-]*(?:\\.[a-z][a-zA-Z0-9-]*)+$',
423
+ },
424
+ ],
425
+ [debug.entries.ask, { type: 'string', pattern: '^E[1-9][0-9]*$' }],
426
+ ])
427
+ // JSON text has already excluded accessors/functions; bridge only this exact defining preflight.
428
+ customSchemas.set(StrikeDebrisJsonGuard, {})
429
+ // The defining native hunt tag guard retains its bounded dotted namespace.
430
+ customSchemas.set(
431
+ schemaAt(
432
+ NativeHuntSchema,
433
+ '/entries/hit/entries/tags/pipe/0/item',
434
+ ) as GenericSchema,
435
+ {
436
+ type: 'string',
437
+ maxLength: 128,
438
+ pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.-]+$',
439
+ },
440
+ )
441
+ // Faithful projection of the native four-field header predicate. Registered
442
+ // post documents additionally run complete scaled-post and graph admission.
443
+ customSchemas.set(ScaledPostInputSchema, {
444
+ type: 'object',
445
+ required: ['programs', 'draws', 'targets', 'outputs'],
446
+ 'x-wildshard-checks': [
447
+ '@wildshard/format/scaledPostContract#parseScaledPostRow',
448
+ ],
449
+ } satisfies FormatJsonSchema)
450
+ customSchemas.set(HeldCueSchema, {
451
+ type: 'string',
452
+ pattern: '^cue\\.[a-z][a-zA-Z0-9.-]*$',
453
+ })
454
+ customSchemas.set(ArcWeaponItemSchema, {
455
+ type: 'string',
456
+ pattern: '^weapon\\.[a-z][a-zA-Z0-9.-]*$',
457
+ })
458
+ const postIdentityTransforms = new Set([
459
+ ...postGraphIdentityTransforms,
460
+ ...uniformIdentityTransforms,
461
+ ])
462
+ const namedClipTransform = schemaAt(
463
+ CreatureSkinClipNameSchema,
464
+ '/options/1/pipe/3',
465
+ )
466
+ // FP26 (format 0.1.0.4): the identity transform folds the old `revision` spelling into `saveRevision`.
467
+ const identitySaveRevision = schemaAt(IdentitySchema, '/pipe/2')
468
+ const skinPoseLayersRecord = schemaAt(
469
+ SkinBindingSchema,
470
+ '/entries/poseLayers/wrapped',
471
+ )
472
+ const skinPoseLayerValues = schemaAt(
473
+ SkinBindingSchema,
474
+ '/entries/poseLayers/wrapped/value',
475
+ ) as GenericSchema
476
+ customSchemas.set(HeldMeleeActionSchema, {
477
+ type: 'string',
478
+ pattern: '^[a-z][a-zA-Z0-9-]*\\.[a-zA-Z0-9.-]+$',
479
+ })
480
+ const bowVariant = BowVariantSchema.pipe[2].entries
481
+ customSchemas.set(bowVariant.id, {
482
+ type: 'string',
483
+ pattern: '^weapon\\.[a-z0-9.-]+$',
484
+ })
485
+ customSchemas.set(bowVariant.sourceTag, {
486
+ type: 'string',
487
+ pattern: '^[^.]+\\..+$',
488
+ })
489
+ customSchemas.set(CreatureStrikeSchema.entries.tags.pipe[0].item, {
490
+ type: 'string',
491
+ maxLength: 128,
492
+ pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.*-]+$',
493
+ })
494
+ // Exact fixed-palette validator; a caller's new custom schema receives no bridge.
495
+ customSchemas.set(AccentSchema.pipe[2], {
496
+ type: 'string',
497
+ enum: [...ACCENT_IDS],
498
+ })
499
+ // Template-literal item identities keep their exact native predicates; only these defining schema objects bridge.
500
+ const itemRows = ItemsSchema.pipe[2].entries.rows.pipe[0].item
501
+ const weaponRow = itemRows.options[0],
502
+ toolRow = itemRows.options[1]
503
+ customSchemas.set(weaponRow.entries.id, {
504
+ type: 'string',
505
+ maxLength: 128,
506
+ pattern: '^weapon\\.[a-z][a-zA-Z0-9.-]*$',
507
+ })
508
+ customSchemas.set(toolRow.entries.id, {
509
+ type: 'string',
510
+ maxLength: 128,
511
+ pattern: '^tool\\.[a-z][a-zA-Z0-9.-]*$',
512
+ })
513
+ customSchemas.set(weaponRow.entries.slot, {
514
+ type: 'string',
515
+ maxLength: 128,
516
+ pattern: '^declared\\.weapon\\.[a-z][a-zA-Z0-9.-]*$',
517
+ })
518
+ customSchemas.set(weaponRow.entries.light.entries.tags.pipe[0].item, {
519
+ type: 'string',
520
+ maxLength: 128,
521
+ pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.-]+$',
522
+ })
523
+ customSchemas.set(
524
+ ConeWeaponProfileSchema.entries.gust.entries.tags.pipe[0].item,
525
+ {
526
+ type: 'string',
527
+ maxLength: 128,
528
+ pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.-]+$',
529
+ },
530
+ )
531
+ customSchemas.set(weaponRow.entries.light.entries.effect.wrapped, {
532
+ type: 'string',
533
+ pattern: '^effect\\.[a-z][a-zA-Z0-9.-]*$',
534
+ })
535
+ customSchemas.set(toolRow.entries.action.wrapped, {
536
+ type: 'string',
537
+ pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.-]+$',
538
+ })
539
+ // The namespaced combat tag validator is the exact defining row object.
540
+ customSchemas.set(
541
+ RowsSchema.pipe[2].entries.strikes.pipe[0].item.entries.tags.pipe[0].item,
542
+ {
543
+ type: 'string',
544
+ maxLength: 128,
545
+ pattern: '^[a-z][a-zA-Z0-9.-]*\\.[a-zA-Z0-9.-]+$',
546
+ },
547
+ )
548
+ const unicodeRegexes = new Set<object>([
549
+ plumbing.entries.namespace.pipe[1],
550
+ InputKeysSchema.pipe[0].item.pipe[1],
551
+ debug.entries.reviewBy.pipe[1],
552
+ ])
553
+ const stateField = StateSchema.pipe[0].entries.shared.pipe[0].item
554
+ unicodeRegexes.add(stateField.entries.name.pipe[1])
555
+ unicodeRegexes.add(CommonsCostsSchema.pipe[0].key.pipe[1])
556
+ const edge = EdgeProfileSchema.pipe[0]
557
+ const finiteNumbers = new Set<object>([
558
+ edge.entries.heights.item.pipe[1],
559
+ stateField.entries.default.options[1].pipe[1],
560
+ ...edge.entries.colours.item.items.map(channel => channel.pipe[1]),
561
+ ])
562
+
563
+ // Only the exact retained defining roots grant action bridges. A caller's new check or transform never joins.
564
+ const wireRoots: Readonly<Record<string, GenericSchema>> = {
565
+ 'audioScene.AudioScene': AudioSceneSchema,
566
+ 'forestPage.LivingPageSites': LivingPageSitesSchema,
567
+ 'fixedDraws.FixedDrawRows': FixedDrawRowsSchema,
568
+ 'forestPage.ForestPage': ForestPageSchema,
569
+ 'forestPage.ForestGroundLayout': ForestGroundLayoutSchema,
570
+ 'caveInterior.CaveFile': CaveFileSchema,
571
+ 'caveInterior.CaveInterior': CaveInteriorSchema,
572
+ 'streamedCover.CoverComposition': CoverCompositionSchema,
573
+ 'speciesLooks.CreatureInstall': CreatureInstallSchema,
574
+ 'speciesLooks.PackedCreatureLooks': PackedCreatureLooksSchema,
575
+ 'questPageComposition.QuestPageComposition': QuestPageCompositionSchema,
576
+ 'chapterDirector.ChapterWake': ChapterWakeSchema,
577
+ 'bowVariantRows.BowVariant': BowVariantSchema,
578
+ 'scalarChannel.ScalarChannel': ScalarChannelSchema,
579
+ 'terrain.ForestRows': ForestRowsSchema,
580
+ 'clientPlan.RuntimeBounds': RuntimeBoundsSchema,
581
+ 'worldUpdates.WorldUpdates': WorldUpdatesSchema,
582
+ 'streamedCover.StreamedCover': StreamedCoverSchema,
583
+ 'practiceCourseRows.PracticeScene': PracticeSceneSchema,
584
+ 'graphArmsRows.GraphArms': GraphArmsSchema,
585
+ 'practiceCourseRows.RidingPractice': RidingPracticeSchema,
586
+ 'mountedSpecimenRows.MountedSpecimenSeat': MountedSpecimenSeatSchema,
587
+ 'speciesBookRows.SpeciesActorsFile': SpeciesActorsFileSchema,
588
+ 'arenaScriptRows.ArenaScriptFightFile': ArenaScriptFightFileSchema,
589
+ 'arenaScriptRows.ArenaScriptGeometry': ArenaScriptGeometrySchema,
590
+ 'encounterRows.TimedEncounters': TimedEncountersSchema,
591
+ 'encounterRows.CloudSpecimen': CloudSpecimenSchema,
592
+ 'roamingCombat.RoamingCombat': RoamingCombatSchema,
593
+ 'populationProjection.PopulationProjection': PopulationProjectionSchema,
594
+ 'populationProjection.EnemyPlacements': EnemyPlacementsSchema,
595
+ 'sceneDressing.SceneDressing': SceneDressingSchema,
596
+ 'clientChannels.NumericPose': NumericPoseSchema,
597
+ 'populationKeeper.PopulationKeeperRows': PopulationKeeperRowsSchema,
598
+ 'questInteractions.QuestPageInteractions': QuestPageInteractionsSchema,
599
+ 'questPageComposition.QuestPage': QuestPageSchema,
600
+ 'questContinuation.QuestContinuation': QuestContinuationSchema,
601
+ 'questWorld.QuestWorld': QuestWorldSchema,
602
+ 'questFigures.QuestFigures': QuestFiguresSchema,
603
+ 'questFigures.KitFigureCards': KitFigureCardsSchema,
604
+ 'cueDirector.CueDirectorWire': CueDirectorWireSchema,
605
+ 'questSteps.QuestHintRows': QuestHintRowsSchema,
606
+ 'questSteps.QuestKillRows': QuestKillRowsSchema,
607
+ 'questSteps.QuestServiceActions': QuestServiceActionsSchema,
608
+ 'exchange.Exchange': ExchangeSchema,
609
+ 'catalogueEconomy.CatalogueEconomy': CatalogueEconomySchema,
610
+ 'lootBag.LootBag': LootBagSchema,
611
+ 'contracts.ContractCatalogue': ContractCatalogueSchema,
612
+ 'achievementCounters.AchievementCounterData': AchievementCounterDataSchema,
613
+ 'herdShelter.PopulationShelter': PopulationShelterSchema,
614
+ 'panelTemplate.PanelDefinition': PanelDefinitionSchema,
615
+ 'heldFinishes.HeldFinishes': HeldFinishesSchema,
616
+ 'figures.FigureCatalogue': FigureCatalogueSchema,
617
+ 'figures.FigureGroup': FigureGroupSchema,
618
+ 'questStory.QuestStory': QuestStorySchema,
619
+ 'weatherProgram.WeatherProgram': WeatherProgramSchema,
620
+ 'forestWeather.ForestWeather': ForestWeatherSchema,
621
+ 'populationRoster.NativePopulationRows': NativePopulationRowsSchema,
622
+ 'chapterDirector.ChapterDirector': ChapterDirectorSchema,
623
+ 'eliteFeature.EliteFeature': EliteFeatureSchema,
624
+ 'coverAppearance.CoverAppearance': CoverAppearanceSchema,
625
+ 'pageLife.PageLife': PageLifeSchema,
626
+ 'worldSceneWeld.WorldSceneWeld': WorldSceneWeldSchema,
627
+ 'worldSceneModels.WorldSceneModels': WorldSceneModelsSchema,
628
+ 'sceneBuffers.SceneBuffers': SceneBuffersSchema,
629
+ 'worldScenePlacement.WorldScenePlacement': WorldScenePlacementSchema,
630
+ 'clientChannels.WorldScene': WorldSceneSchema,
631
+ 'buildings.BuildingLifeRows': BuildingLifeRowsSchema,
632
+ 'buildings.BuildingCloudPose': BuildingCloudPoseSchema,
633
+ 'bodySlots.BodySlots': BodySlotsSchema,
634
+ 'limbRig.LimbRig': LimbRigSchema,
635
+ 'limbRig.LimbBlend': LimbBlendSchema,
636
+ 'limbRig.BakedClipTable': BakedClipTable,
637
+ 'limbCollision.LimbCollisionBake': LimbCollisionBake,
638
+ 'plumbing.Plumbing': PlumbingSchema,
639
+ 'heldArms.ToonArmsLook': ToonArmsLookSchema,
640
+ 'npcs.QuestNpcBinding': QuestNpcBindingSchema,
641
+ 'questHost.QuestHost': QuestHostSchema,
642
+ 'npcs.QuestNpcBindings': QuestNpcBindingsSchema,
643
+ 'npcs.NpcRow': NpcRowSchema,
644
+ 'npcs.NpcMotion': NpcMotionSchema,
645
+ 'npcs.NpcDialogueRow': NpcDialogueRowSchema,
646
+ 'bossProfiles.BossProfile': BossProfileSchema,
647
+ 'bossProfiles.ArenaBossProfile': ArenaBossProfileSchema,
648
+ 'bossProfiles.RoamingBossProfile': RoamingBossProfileSchema,
649
+ 'bossProfiles.SpawnedBossProfile': SpawnedBossProfileSchema,
650
+ 'bossProfiles.HeldBossProfile': HeldBossProfileSchema,
651
+ 'bossProfiles.ScriptBossProfile': ScriptBossProfileSchema,
652
+ 'bossEncounter.RoamingEncounter': RoamingEncounterSchema,
653
+ 'bossEncounter.WakeEncounter': WakeEncounterSchema,
654
+ 'bossEncounter.BossEncounterPresentation': BossEncounterPresentationSchema,
655
+ 'bossEncounter.NativeBossBinding': NativeBossBindingSchema,
656
+ 'weaponProfiles.WeaponProfile': WeaponProfileSchema,
657
+ 'weaponProfiles.MeleeWeaponProfile': MeleeWeaponProfileSchema,
658
+ 'weaponProfiles.BowWeaponProfile': BowWeaponProfileSchema,
659
+ 'weaponProfiles.FirearmWeaponProfile': FirearmWeaponProfileSchema,
660
+ 'weaponProfiles.ThrownWeaponProfile': ThrownWeaponProfileSchema,
661
+ 'weaponProfiles.LashWeaponProfile': LashWeaponProfileSchema,
662
+ 'weaponProfiles.ConeWeaponProfile': ConeWeaponProfileSchema,
663
+ 'weaponProfiles.HeldBowBase': HeldBowBaseSchema,
664
+ 'weaponProfiles.HeldBowRows': HeldBowRowsSchema,
665
+ 'weaponProfiles.HeldBowDefinition': HeldBowDefinitionSchema,
666
+ 'brains.Skirmisher': SkirmisherSchema,
667
+ 'brains.Stalker': StalkerSchema,
668
+ 'brains.ScriptBrain': ScriptBrainSchema,
669
+ 'brains.Guardian': GuardianSchema,
670
+ 'brains.GuardianPatterns': GuardianPatternsSchema,
671
+ 'brains.PerchHunter': PerchHunterSchema,
672
+ 'flyers.Diver': DiverSchema,
673
+ 'flyers.OrbitDiver': OrbitDiverSchema,
674
+ 'flyers.PatrolDiver': PatrolDiverSchema,
675
+ 'flyers.BurstFlyer': BurstFlyerSchema,
676
+ 'grazers.Grazer': GrazerSchema,
677
+ 'grazers.RamGrazer': RamGrazerSchema,
678
+ 'grazers.ChallengeGrazer': ChallengeGrazerSchema,
679
+ 'groupBrains.GroupBrain': GroupBrainSchema,
680
+ 'creatures.Creatures': CreaturesSchema,
681
+ 'creatures.CreatureHome': CreatureHomeSchema,
682
+ 'crowds.Flock': FlockSchema,
683
+ 'encounters.Encounters': EncountersSchema,
684
+ 'audioProfiles.AudioMusic': AudioMusicSchema,
685
+ 'audioProfiles.AudioSamples': AudioSamplesSchema,
686
+ 'audioProfiles.AudioZones': AudioZonesSchema,
687
+ 'audioRouting.AudioRouting': AudioRoutingSchema,
688
+ 'audio.AudioData': AudioDataSchema,
689
+ 'ledger.LedgerFact': LedgerFactSchema,
690
+ 'ledger.LedgerRules': LedgerRulesSchema,
691
+ 'director.Director': DirectorSchema,
692
+ 'directorDocument.DirectorDocument': DirectorDocumentSchema,
693
+ 'directorStages.DirectorStages': DirectorStagesSchema,
694
+ 'migrations.LogicalState': LogicalStateSchema,
695
+ 'migrations.Migrations': MigrationsSchema,
696
+ 'traversal.Traversal': TraversalSchema,
697
+ 'runtimeBinds.RuntimeBinds': RuntimeBindsSchema,
698
+ 'runtimeSpawns.RuntimeSpawns': RuntimeSpawnsSchema,
699
+ 'skinLayers.SkinPoseLayer': SkinPoseLayerSchema,
700
+ 'presentation.Presentation': PresentationSchema,
701
+ 'meshCollision.MeshCollision': MeshCollisionSchema,
702
+ 'scripts.ScriptBindings': ScriptBindingsSchema,
703
+ 'actorMoves.ActorMoves': ActorMovesSchema,
704
+ 'decisionScripts.DecisionScripts': DecisionScriptsSchema,
705
+ 'hooks.Hooks': HooksSchema,
706
+ 'terrain.Terrain': TerrainSchema,
707
+ 'water.Water': WaterSchema,
708
+ 'accent.Accent': AccentSchema,
709
+ 'items.ItemFamilyName': ItemFamilyNameSchema,
710
+ 'items.Items': ItemsSchema,
711
+ 'targets.Targets': TargetsSchema,
712
+ 'quests.QuestData': QuestDataSchema,
713
+ 'questGraph.QuestGraph': QuestGraphSchema,
714
+ 'questSteps.QuestStepRows': QuestStepRowsSchema,
715
+ 'speciesPrograms.Species': SpeciesSchema,
716
+ 'buildings.BakedBuildingLook': BakedBuildingLookSchema,
717
+ 'buildings.BuildingLifeLook': BuildingLifeLookSchema,
718
+ 'questInteractions.InteractionRows': InteractionRowsSchema,
719
+ 'rows.Rows': RowsSchema,
720
+ 'movers.Movers': MoversSchema,
721
+ 'modes.Modes': ModesSchema,
722
+ 'modes.ZiplineMode': ZiplineModeSchema,
723
+ 'modes.UpdraftMode': UpdraftModeSchema,
724
+ 'modes.RideGaits': RideGaitsSchema,
725
+ 'modes.RideMode': RideModeSchema,
726
+ 'modes.GrappleMode': GrappleModeSchema,
727
+ 'modes.TraverseMode': TraverseModeSchema,
728
+ 'moverMotion.MoverMotion': MoverMotionSchema,
729
+ 'moverMotion.MoverTrack': MoverTrackSchema,
730
+ 'moverMotion.MoverTrigger': MoverTriggerSchema,
731
+ 'moverMotion.MoverDriver': MoverDriverSchema,
732
+ 'socketLift.SocketLift': SocketLiftSchema,
733
+ 'portalLink.PortalLink': PortalLinkSchema,
734
+ 'entryways.Entryways': EntrywaysSchema,
735
+ 'navigation.Navigation': NavigationSchema,
736
+ 'nativeGround.NativeGround': NativeGroundSchema,
737
+ 'ui.Ui': UiSchema,
738
+ 'clientScripts.ClientScripts': ClientScriptsSchema,
739
+ 'clientChannels.ClientChannels': ClientChannelsSchema,
740
+ 'clientChannels.ClientChannelProgram': ClientChannelProgramSchema,
741
+ 'clientChannels.PrivateScene': PrivateSceneSchema,
742
+ 'ambientLife.ForestLife': ForestLifeSchema,
743
+ 'runtimeCost.MemoryMeasurement': MemoryMeasurementSchema,
744
+ 'runtimeCost.RuntimeCost': RuntimeCostSchema,
745
+ 'runtimeCost.RegionalSimCost': RegionalSimCostSchema,
746
+ 'runtime.Runtime': RuntimeSchema,
747
+ 'runtime.ClientPlan': ClientPlanRuntimeSchema,
748
+ 'clientState.ClientCheckpoint': ClientCheckpointSchema,
749
+ 'clientState.ItemCheckpointStates': ItemCheckpointStatesSchema,
750
+ 'clientState.LogicalClientCheckpoint': LogicalClientCheckpointSchema,
751
+ 'liftRider.LiftRider': LiftRiderSchema,
752
+ 'speciesScripts.ScriptSpecies': ScriptSpeciesSchema,
753
+ 'eliteScripts.EliteScript': EliteScriptSchema,
754
+ 'skins.SkinLookParameters': SkinLookParametersSchema,
755
+ 'skins.SkinClipParameters': SkinClipParametersSchema,
756
+ 'skins.ShardSkinFile': ShardSkinFileSchema,
757
+ 'skinData.SkinClipName': SkinClipNameSchema,
758
+ 'skinData.SkinRow': SkinRowSchema,
759
+ 'skinData.SkinBinding': SkinBindingSchema,
760
+ 'shardSections.ShardNatural': ShardNaturalSchema,
761
+ 'shardSections.ShardFinite': ShardFiniteSchema,
762
+ 'shardSections.ShardHash': ShardHashSchema,
763
+ 'shardSections.ShardReference': ShardReferenceSchema,
764
+ 'shardSections.ShardReferences': ShardReferencesSchema,
765
+ 'shardSections.ShardNames': ShardNamesSchema,
766
+ 'shardSections.CellBounds': CellBoundsSchema,
767
+ 'shardSections.Identity': IdentitySchema,
768
+ 'shardSections.Requires': RequiresSchema,
769
+ 'shardSections.Budgets': BudgetsSchema,
770
+ 'shardSections.Sim': SimSchema,
771
+ 'shardSections.AuthorCaps': AuthorCapsSchema,
772
+ 'shardSections.ServerBudget': ServerBudgetSchema,
773
+ 'shardSections.Files': FilesSchema,
774
+ 'shardSections.Tiles': TilesSchema,
775
+ 'shardSections.Library': LibrarySchema,
776
+ 'shardSections.Critical': CriticalSchema,
777
+ 'shardSections.Far': FarSchema,
778
+ 'shardSections.Spawn': SpawnSchema,
779
+ 'terrain.GroundRows': GroundRowsSchema,
780
+ 'scalarChannel.ScalarLattice': ScalarLatticeSchema,
781
+ 'practiceCourseRows.Controller': PracticeControllerSchema,
782
+ 'scalarChannel.ScalarTriplet': ScalarTripletSchema,
783
+ 'returnProjectionV2.ReturnProjectionV2': ReturnProjectionV2Schema,
784
+ 'scriptContract.ReturnModules': ReturnModulesSchema,
785
+ 'nativePhysics.NativeGroundFile': NativeGroundFileSchema,
786
+ 'worldAssembly.WorldAssembly': WorldAssemblySchema,
787
+ 'binarySource.BinarySource': BinarySourceSchema,
788
+ 'namedJsonContracts.QuestTrader': QuestTraderSchema,
789
+ 'namedJsonContracts.AdventurePersistence': AdventurePersistenceSchema,
790
+ 'namedJsonContracts.PosedLibrary': PosedLibrarySchema,
791
+ 'populationEnvironment.PopulationField': PopulationFieldSchema,
792
+ 'namedJsonContracts.PageReturnRows': PageReturnRowsSchema,
793
+ 'worldScenePlacement.WorldScenePlacementPage': WorldScenePlacementPageSchema,
794
+ 'questSteps.CarriedQuest': CarriedQuestSchema,
795
+ 'nativeQuestComposition.NativeQuestComposition': NativeQuestCompositionSchema,
796
+ 'nativeQuestComposition.NativeQuestServiceSpots':
797
+ NativeQuestServiceSpotsSchema,
798
+ 'panelTemplate.QuestPanelCatalogue': QuestPanelCatalogueSchema,
799
+ 'sceneDressing.SceneScatterPage': SceneScatterPageSchema,
800
+ 'buildings.BuildingLifeDocument': BuildingLifeDocumentSchema,
801
+ 'bakedTiles.BakedPlacementPlan': BakedPlacementPlanSchema,
802
+ 'sceneSources.SceneModelSource': SceneModelSourceSchema,
803
+ 'sceneSources.SceneBakeSource': SceneBakeSourceSchema,
804
+ 'worldScenePages.WorldScenePage': WorldScenePageSchema,
805
+ 'weatherBundle.WeatherBundle': WeatherBundleSchema,
806
+ 'weatherBundle.WeatherDocument': WeatherDocumentSchema,
807
+ 'weatherEffects.WeatherEffects': WeatherEffectsSchema,
808
+ 'rainPresentation.RainPresentation': RainPresentationSchema,
809
+ 'rangedPage.ForestWeatherObservation': ForestWeatherObservationSchema,
810
+ 'paintedResources.PaintedAir': PaintedAirSchema,
811
+ 'paintedResources.PaintedGround': PaintedGroundSchema,
812
+ 'paintedResources.PaintedPanorama': PaintedPanoramaSchema,
813
+ 'paintedResources.PainterKeyLight': PainterKeyLightSchema,
814
+ 'paintedResources.PainterlyWorld': PainterlyWorldSchema,
815
+ 'postGraphLook.PostGraphLook': PostGraphLookSchema,
816
+ 'questStory.ChapterStoryPresentation': ChapterStoryPresentationSchema,
817
+
818
+ 'mixedPopulation.PerchBodyFile': PerchBodyFileSchema,
819
+ 'returnProgramDocument.ReturnProgramDocument': ReturnProgramDocumentSchema,
820
+ 'returnProgramDocument.ReturnProgramWireDocument':
821
+ ReturnProgramWireDocumentSchema,
822
+ 'populationEnvironment.PopulationHabitat': PopulationHabitatSchema,
823
+ 'populationRoster.TamingPoseFile': TamingPoseFileSchema,
824
+ 'questStory.AdventureContent': AdventureContentSchema,
825
+ 'findsCatalogue.FindsCatalogue': FindsCatalogueSchema,
826
+ 'wildlifePopulation.WildlifePopulation': WildlifePopulationSchema,
827
+ 'practiceCourseRows.FixedPracticeFile': FixedPracticeFileSchema,
828
+ 'islandLibrary.FixedGeometryGroups': FixedGeometryGroupsSchema,
829
+ 'specimenCatalogue.SpecimenBook': SpecimenBookSchema,
830
+ 'heldArms.HeldGraphCards': HeldGraphCardsSchema,
831
+ 'arenaRoomDocument.ArenaRoomDocument': ArenaRoomDocumentSchema,
832
+ 'riding.ClientRidingSession': ClientRidingSessionSchema,
833
+ 'rangedPage.RangedPage': RangedPageSchema,
834
+ 'speciesActorsFile.SpeciesActorsFile': SpeciesActorsDocumentSchema,
835
+
836
+ 'forestNativeInputs.ForestNativeInputs': ForestNativeInputsSchema,
837
+ 'waterWorld.WaterWorld': WaterWorldSchema,
838
+ 'weaponProfiles.HeldBowFile': HeldBowFileSchema,
839
+ 'weaponProfiles.HeldFirearmPage': HeldFirearmPageSchema,
840
+ 'heldWeaponDocuments.BladeDocument': BladeDocumentSchema,
841
+ 'heldWeaponDocuments.PolearmDocument': PolearmDocumentSchema,
842
+ 'heldWeaponDocuments.HeldSlotsDocument': HeldSlotsDocumentSchema,
843
+ 'heldJianDocument.HeldJianDocument': HeldJianDocumentSchema,
844
+ 'questInteractionSource.QuestInteractionSource': QuestInteractionSourceSchema,
845
+ 'questRuntime.QuestRuntimeDocument': QuestRuntimeDocumentSchema,
846
+ 'questStoryBindings.QuestStoryBindings': QuestStoryBindingsSchema,
847
+ 'questPageComposition.ChapterView': ChapterViewSchema,
848
+ }
849
+ const wireChecks = new Map<object, string>()
850
+ const wireFinite = new Set<object>()
851
+ const wireRegexes = new Set<object>()
852
+ const windDirections = new Set<object>()
853
+ function rememberActions(
854
+ value: unknown,
855
+ path: string,
856
+ seen: WeakSet<object>,
857
+ ): void {
858
+ if (typeof value !== 'object' || value === null || seen.has(value)) return
859
+ seen.add(value)
860
+ const kind: unknown = Reflect.get(value, 'kind'),
861
+ type: unknown = Reflect.get(value, 'type')
862
+ if (kind === 'schema' && type === 'lazy') {
863
+ const getter: unknown = Reflect.get(value, 'getter')
864
+ if (typeof getter === 'function') {
865
+ const nested: unknown = Reflect.apply(getter, undefined, [undefined])
866
+ rememberActions(nested, `${path}.wrapped`, seen)
867
+ }
868
+ }
869
+ if (kind === 'validation') {
870
+ if (type === 'check' && !wireChecks.has(value)) wireChecks.set(value, path)
871
+ else if (type === 'finite') wireFinite.add(value)
872
+ else if (
873
+ type === 'some_item' &&
874
+ path.endsWith('.entries.wind.wrapped.entries.toward.pipe.1')
875
+ )
876
+ windDirections.add(value)
877
+ else if (type === 'regex') {
878
+ const regex: unknown = Reflect.get(value, 'requirement')
879
+ if (regex instanceof RegExp && regex.flags === 'u') wireRegexes.add(value)
880
+ }
881
+ }
882
+ for (const [key, child] of Object.entries(value))
883
+ rememberActions(child, `${path}.${key}`, seen)
884
+ }
885
+ for (const [key, schema] of Object.entries(wireRoots)) {
886
+ const module = key.slice(0, key.indexOf('.')),
887
+ binding = key.slice(key.indexOf('.') + 1)
888
+ rememberActions(
889
+ schema,
890
+ `@wildshard/format/${module}#${binding}Schema`,
891
+ new WeakSet(),
892
+ )
893
+ }
894
+ // A composed quest host shares this exact check object; its nested path must not rename the defining public check.
895
+ wireChecks.set(
896
+ DirectorStagesSchema.pipe[1],
897
+ '@wildshard/format/directorStages#DirectorStagesSchema.pipe.1',
898
+ )
899
+ // ChapterWake borrows this check; composition cannot rename its defining public identity.
900
+ const wakePipe: unknown = Reflect.get(WakeEncounterSchema, 'pipe')
901
+ const wakeCheck: unknown = Array.isArray(wakePipe) ? wakePipe[1] : undefined
902
+ if (
903
+ typeof wakeCheck !== 'object' ||
904
+ wakeCheck === null ||
905
+ Reflect.get(wakeCheck, 'kind') !== 'validation' ||
906
+ Reflect.get(wakeCheck, 'type') !== 'check'
907
+ ) {
908
+ throw new Error('Missing defining wake encounter validation')
909
+ }
910
+ wireChecks.set(
911
+ wakeCheck,
912
+ '@wildshard/format/bossEncounter#WakeEncounterSchema.pipe.1',
913
+ )
914
+
915
+ /** Share only complete native grammars within these exact documents. The
916
+ * defining format parsers still own every semantic and resource admission. */
917
+ function encounterDefinitions(
918
+ schema: GenericSchema,
919
+ ): Record<string, GenericSchema> | undefined {
920
+ if (schema === ArenaScriptFightFileSchema)
921
+ return {
922
+ room: ArenaRoomDocumentRowsSchema,
923
+ king: ArenaKingRowsSchema,
924
+ privateScene: PrivateSceneSchema,
925
+ bossProfile: BossProfileSchema,
926
+ legacyReturn: ReturnProgramSchema,
927
+ completeReturn: ReturnProgramDocumentSchema,
928
+ projection: ReturnProjectionV2Schema,
929
+ }
930
+ if (schema === ArenaRoomDocumentSchema)
931
+ return {
932
+ room: ArenaRoomDocumentRowsSchema,
933
+ privateScene: PrivateSceneSchema,
934
+ bossProfile: BossProfileSchema,
935
+ legacyReturn: ReturnProgramSchema,
936
+ completeReturn: ReturnProgramDocumentSchema,
937
+ projection: ReturnProjectionV2Schema,
938
+ }
939
+ if (schema === ArenaScriptGeometrySchema)
940
+ return {
941
+ privateScene: PrivateSceneSchema,
942
+ nativeGeometry: WeatherGeometrySchema,
943
+ channelPrograms: ClientChannelsSchema,
944
+ }
945
+ if (schema === CloudSpecimenSchema)
946
+ return {
947
+ cloudBody: CloudBodySchema,
948
+ privateScene: PrivateSceneSchema,
949
+ nativeGeometry: WeatherGeometrySchema,
950
+ channelPrograms: ClientChannelsSchema,
951
+ }
952
+ if (schema === ClientRidingSessionSchema)
953
+ return {
954
+ legacyReturn: ReturnProgramSchema,
955
+ completeReturn: ReturnProgramDocumentSchema,
956
+ projection: ReturnProjectionV2Schema,
957
+ }
958
+ if (schema === TimedEncountersSchema)
959
+ return {
960
+ nativeGeometryData: WeatherGeometryDataSchema,
961
+ projection: ReturnProjectionV2Schema,
962
+ }
963
+ if (schema === MountedSpecimenSeatSchema)
964
+ return { bakedGeometry: SceneBakedGeometrySchema }
965
+ return undefined
966
+ }
967
+
968
+ /** Complete repeated grammars factored only within the approved native documents. */
969
+ function heldDocumentDefinitions(
970
+ schema: GenericSchema,
971
+ ): Record<string, GenericSchema> | undefined {
972
+ if (schema === HeldJianDocumentSchema)
973
+ return {
974
+ graphArms: GraphArmsSchema,
975
+ postGraph: PostGraphLookSchema,
976
+ channels: ClientChannelsSchema,
977
+ }
978
+ if (
979
+ schema === BladeDocumentSchema ||
980
+ schema === PolearmDocumentSchema ||
981
+ schema === HeldSlotsDocumentSchema
982
+ )
983
+ return {
984
+ completeReturn: ReturnProgramDocumentSchema,
985
+ projection: ReturnProjectionV2Schema,
986
+ }
987
+ if (schema === WaterWorldSchema)
988
+ return {
989
+ sceneNode: WorldSceneWeldNodeSchema,
990
+ completeReturn: ReturnProgramDocumentSchema,
991
+ projection: ReturnProjectionV2Schema,
992
+ }
993
+ if (schema === HeldFirearmPageSchema)
994
+ return { channels: ClientChannelsSchema }
995
+ return undefined
996
+ }
997
+
998
+ /**
999
+ * Convert an author schema with the official converter, refusing every unrecognised custom check or transform.
1000
+ * The extracted format checks have explicit bridges. Plumbing's cross-field checks remain named mandatory
1001
+ * admission checks; Valibot string bounds use UTF-16 code units, unlike JSON Schema's Unicode code points.
1002
+ * The custom-section bridge uses draft-07; existing wire documents keep draft-2020-12.
1003
+ * This structural document never replaces the defining format parser's admission verdict.
1004
+ */
1005
+ export function formatJsonSchema(
1006
+ schema: GenericSchema,
1007
+ target: 'draft-07' | 'draft-2020-12' = 'draft-2020-12',
1008
+ ): FormatJsonSchema {
1009
+ const heldDefinitions = heldDocumentDefinitions(schema)
1010
+ const definitions = encounterDefinitions(schema)
1011
+ return toJsonSchema(schema, {
1012
+ target,
1013
+ errorMode: 'throw',
1014
+ typeMode: 'output',
1015
+ // Both page kinds share the complete node grammar. A local definition
1016
+ // retains every constraint without repeating that grammar per branch.
1017
+ ...(schema === WorldScenePageSchema
1018
+ ? { definitions: { sceneNode: WorldSceneWeldNodeSchema } }
1019
+ : {}),
1020
+ // Both existing weather wires contain the same complete phase program.
1021
+ ...(schema === WeatherDocumentSchema
1022
+ ? { definitions: { weatherProgram: WeatherProgramSchema } }
1023
+ : {}),
1024
+ ...(heldDefinitions === undefined ? {} : { definitions: heldDefinitions }),
1025
+ // The complete sheep document keeps both original return envelopes and
1026
+ // exact-input script/projection constraints, shared without repetition.
1027
+ ...(schema === SpeciesActorsDocumentSchema
1028
+ ? {
1029
+ definitions: {
1030
+ legacyReturn: ReturnProgramSchema,
1031
+ wireReturn: ReturnProgramWireDocumentSchema,
1032
+ projection: ReturnProjectionV2Schema,
1033
+ },
1034
+ }
1035
+ : {}),
1036
+ ...(definitions === undefined ? {} : { definitions }),
1037
+ // The population's six identical return descriptors share their complete
1038
+ // native grammars; the defining parser and every wire constraint remain.
1039
+ ...(schema === WildlifePopulationSchema
1040
+ ? {
1041
+ definitions: {
1042
+ legacyReturn: ReturnProgramSchema,
1043
+ projection: ReturnProjectionV2Schema,
1044
+ },
1045
+ }
1046
+ : {}),
1047
+ ...(schema === PopulationProjectionSchema || schema === PerchBodyFileSchema
1048
+ ? {
1049
+ definitions: {
1050
+ legacyReturn: ReturnProgramSchema,
1051
+ wireReturn: ReturnProgramWireDocumentSchema,
1052
+ projection: ReturnProjectionV2Schema,
1053
+ },
1054
+ }
1055
+ : {}),
1056
+ overrideSchema: ({ valibotSchema }) => {
1057
+ if (valibotSchema !== skinPoseLayersRecord)
1058
+ return customSchemas.get(valibotSchema)
1059
+ // The converter cannot project a union as a record key. Keep both exact key rules and the value grammar.
1060
+ const { $schema: _keyDialect, ...propertyNames } = formatJsonSchema(
1061
+ CreatureSkinClipNameSchema,
1062
+ target,
1063
+ )
1064
+ const { $schema: _valueDialect, ...additionalProperties } =
1065
+ formatJsonSchema(skinPoseLayerValues, target)
1066
+ return { type: 'object', propertyNames, additionalProperties }
1067
+ },
1068
+ overrideAction: ({ valibotAction, jsonSchema, errors }) => {
1069
+ if (postIdentityTransforms.has(valibotAction)) return jsonSchema
1070
+ // The defining steer-wind action requires at least one nonzero axis.
1071
+ if (windDirections.has(valibotAction))
1072
+ return { ...jsonSchema, not: { const: [0, 0] } }
1073
+ // Exact one-pass sample transforms retain the original wire grammar; JSON numbers are finite.
1074
+ if (valibotAction === SkinPoseLayerSchema.entries.times.pipe[1])
1075
+ return {
1076
+ type: 'array',
1077
+ items: { type: 'number' },
1078
+ minItems: 2,
1079
+ maxItems: 4097,
1080
+ }
1081
+ if (
1082
+ valibotAction ===
1083
+ SkinPoseLayerSchema.entries.tracks.pipe[0].item.entries.values.pipe[1]
1084
+ )
1085
+ return { type: 'array', items: { type: 'number' }, maxItems: 300000 }
1086
+ if (valibotAction === GraphArmsSchema.entries.rig.entries.sockets.pipe[3])
1087
+ return { ...jsonSchema, uniqueItems: true }
1088
+ if (valibotAction === HeldArmsSchema.options[1].entries.tools.pipe[2])
1089
+ return { ...jsonSchema, uniqueItems: true }
1090
+ // This defining transform only omits empty optional namespaces; all nonempty maps retain the schema below.
1091
+ if (valibotAction === DecisionScriptsSchema.pipe[7]) return jsonSchema
1092
+ if (valibotAction === EdgeProfileSchema.pipe[1]) {
1093
+ // Both arrays must have the same native sample count; bound each branch exactly.
1094
+ return {
1095
+ ...jsonSchema,
1096
+ anyOf: [256, 257].map(count => ({
1097
+ properties: {
1098
+ heights: { minItems: count, maxItems: count },
1099
+ colours: { minItems: count, maxItems: count },
1100
+ },
1101
+ })),
1102
+ }
1103
+ }
1104
+ if (valibotAction === PlumbingSchema.pipe[3]) {
1105
+ return {
1106
+ ...jsonSchema,
1107
+ 'x-wildshard-checks': ['@wildshard/format/plumbing#plumbingRules'],
1108
+ } satisfies FormatJsonSchema
1109
+ }
1110
+ if (valibotAction === StateSchema.pipe[1]) {
1111
+ return {
1112
+ ...jsonSchema,
1113
+ 'x-wildshard-checks': ['@wildshard/format/state#stateRules'],
1114
+ } satisfies FormatJsonSchema
1115
+ }
1116
+ if (valibotAction === CommonsCostsSchema.pipe[1]) {
1117
+ return {
1118
+ ...jsonSchema,
1119
+ maxProperties: SHARDFILE_ADMISSION_LIMITS.commons,
1120
+ }
1121
+ }
1122
+ // Only the defining query form derives an omitted collider reference from its required sampling file.
1123
+ if (valibotAction === TerrainSchema.options[1].pipe[1])
1124
+ return {
1125
+ ...jsonSchema,
1126
+ required: [...(jsonSchema.required ?? []), 'collider'],
1127
+ 'x-wildshard-checks': [
1128
+ '@wildshard/format/terrain#TerrainSchema.options.1.pipe.1',
1129
+ ],
1130
+ } satisfies FormatJsonSchema
1131
+ // Both defining clip transforms brand the validated string without changing it.
1132
+ if (
1133
+ valibotAction === SkinClipNameSchema.pipe[2] ||
1134
+ valibotAction === namedClipTransform
1135
+ )
1136
+ return jsonSchema
1137
+ // The output identity always carries `saveRevision` and never the old `revision` spelling.
1138
+ if (valibotAction === identitySaveRevision) {
1139
+ const { revision: _old, ...properties } = jsonSchema.properties ?? {}
1140
+ return {
1141
+ ...jsonSchema,
1142
+ properties,
1143
+ required: [
1144
+ ...new Set([...(jsonSchema.required ?? []), 'saveRevision']),
1145
+ ],
1146
+ }
1147
+ }
1148
+ // `v.readonly()` only narrows the output type (format 0.43.0's grapple owners and hooks); the value is unchanged.
1149
+ if (valibotAction.type === 'readonly') return jsonSchema
1150
+ const check = wireChecks.get(valibotAction)
1151
+ if (check !== undefined) {
1152
+ const before =
1153
+ (jsonSchema as FormatJsonSchema)['x-wildshard-checks'] ?? []
1154
+ return {
1155
+ ...jsonSchema,
1156
+ 'x-wildshard-checks': [...before, check],
1157
+ } satisfies FormatJsonSchema
1158
+ }
1159
+ // JSON numbers cannot contain NaN or infinity. The existing ASCII regexes only use the Unicode flag.
1160
+ if (
1161
+ valibotAction.reference === finite ||
1162
+ finiteNumbers.has(valibotAction) ||
1163
+ unicodeRegexes.has(valibotAction) ||
1164
+ wireFinite.has(valibotAction) ||
1165
+ wireRegexes.has(valibotAction)
1166
+ )
1167
+ return jsonSchema
1168
+ if (
1169
+ errors === undefined &&
1170
+ jsonSchema.type === 'string' &&
1171
+ (valibotAction.type === 'min_length' ||
1172
+ valibotAction.type === 'max_length')
1173
+ ) {
1174
+ return {
1175
+ ...jsonSchema,
1176
+ 'x-wildshard-string-length': 'utf16-code-units',
1177
+ } satisfies FormatJsonSchema
1178
+ }
1179
+ return undefined
1180
+ },
1181
+ })
1182
+ }
1183
+
1184
+ const namedSchemas = new WeakMap<
1185
+ GenericSchema,
1186
+ Readonly<Record<string, unknown>>
1187
+ >()
1188
+ /** Build-only draft-07 structure for a named JSON producer's defining schema.
1189
+ * Like the custom-section bridge, omit documentation annotations that Ajv does
1190
+ * not implement; the producer and defining reader retain semantic admission.
1191
+ * Unknown checks and transforms still refuse conversion. Never infer from data.
1192
+ * New named JSON requests provenance: only an exact defining format root receives
1193
+ * its source identity. The default preserves every existing schema byte. */
1194
+ export function namedJsonSchema(
1195
+ schema: GenericSchema,
1196
+ options: { provenance?: boolean } = {},
1197
+ ): Readonly<Record<string, unknown>> {
1198
+ if (options.provenance === true) {
1199
+ const entry = Object.entries(wireRoots).find(([, root]) => root === schema)
1200
+ if (entry === undefined)
1201
+ throw new Error(
1202
+ 'Named JSON provenance requires a defining shared format root',
1203
+ )
1204
+ const [key] = entry,
1205
+ split = key.indexOf('.')
1206
+ return {
1207
+ ...namedJsonSchema(schema),
1208
+ $comment: `@wildshard/format/${key.slice(0, split)}#${key.slice(split + 1)}Schema`,
1209
+ }
1210
+ }
1211
+ const previous = namedSchemas.get(schema)
1212
+ if (previous !== undefined) return previous
1213
+ const structural = (value: unknown): unknown => {
1214
+ if (typeof value === 'string' && value.startsWith('#/$defs/'))
1215
+ return value.replace('#/$defs/', '#/definitions/')
1216
+ if (Array.isArray(value)) return value.map(structural)
1217
+ if (typeof value !== 'object' || value === null) return value
1218
+ return Object.fromEntries(
1219
+ Object.entries(value)
1220
+ .filter(
1221
+ ([key]) =>
1222
+ key !== 'x-wildshard-checks' && key !== 'x-wildshard-string-length',
1223
+ )
1224
+ .map(([key, child]) => [
1225
+ key === '$defs' ? 'definitions' : key,
1226
+ structural(child),
1227
+ ]),
1228
+ )
1229
+ }
1230
+ const wire = structural(formatJsonSchema(schema, 'draft-07'))
1231
+ if (typeof wire !== 'object' || wire === null || Array.isArray(wire))
1232
+ throw new Error('Named JSON requires a defining object schema')
1233
+ const result: Readonly<Record<string, unknown>> = Object.fromEntries(
1234
+ Object.entries(wire),
1235
+ )
1236
+ namedSchemas.set(schema, result)
1237
+ return result
1238
+ }
1239
+
1240
+ /** Project one registered consumer contract to its exact named draft-07 document.
1241
+ * Author tools name the contract without borrowing the format's Valibot object. */
1242
+ export function namedFormatJsonSchema(
1243
+ name: string,
1244
+ ): Readonly<Record<string, unknown>> {
1245
+ if (!Object.hasOwn(wireRoots, name))
1246
+ throw new Error(`Unknown named format contract: ${name}`)
1247
+ const schema = wireRoots[name]
1248
+ if (schema === undefined)
1249
+ throw new Error(`Missing named format contract: ${name}`)
1250
+ return namedJsonSchema(schema)
1251
+ }
1252
+
1253
+ /** Build-only provenance catalogue from the defining format objects, independently checked by the product freeze. */
1254
+ export function namedFormatJsonSchemas(): Readonly<
1255
+ Record<string, Readonly<Record<string, unknown>>>
1256
+ > {
1257
+ return Object.fromEntries(
1258
+ Object.values(wireRoots).map(schema => {
1259
+ const document = namedJsonSchema(schema, { provenance: true })
1260
+ return [String(document['$comment']), document]
1261
+ }),
1262
+ )
1263
+ }
1264
+
1265
+ /** Publish the exact defining schema of a registered logical JSON name.
1266
+ * Only metadata changes; the caller retains the original document bytes. */
1267
+ export function registeredJsonSchema(
1268
+ name: RegisteredSchemaJsonName,
1269
+ ): Readonly<Record<string, unknown>>
1270
+ export function registeredJsonSchema(
1271
+ name: string,
1272
+ ): Readonly<Record<string, unknown>> | undefined
1273
+ export function registeredJsonSchema(
1274
+ name: string,
1275
+ ): Readonly<Record<string, unknown>> | undefined {
1276
+ const contract = registeredJsonContract(name)
1277
+ if (contract === undefined) return undefined
1278
+ const document = namedJsonSchema(contract.schema, { provenance: true })
1279
+ if (document['$comment'] !== contract.source)
1280
+ throw new Error(`Registered JSON defining binding differs: ${name}`)
1281
+ return document
1282
+ }
1283
+
1284
+ /** The migrated wire roots, generated from their defining Valibot schemas; whole-shard extraction remains open. */
1285
+ export function formatJsonSchemas(): Readonly<
1286
+ Record<string, FormatJsonSchema>
1287
+ > {
1288
+ const document = (name: string, schema: GenericSchema): FormatJsonSchema => {
1289
+ try {
1290
+ return {
1291
+ ...formatJsonSchema(schema),
1292
+ title: name,
1293
+ $comment:
1294
+ 'DO-NOT-EDIT: generated from @wildshard/format by scripts/gen-format-schema.mjs. Structural schema; named checks and UTF-16 bounds still require the defining Valibot parser.',
1295
+ }
1296
+ } catch (error) {
1297
+ throw new Error(`Format schema ${name}: ${String(error)}`, {
1298
+ cause: error,
1299
+ })
1300
+ }
1301
+ }
1302
+ return {
1303
+ 'edge-profiles': document('edge-profiles', EdgeProfilesSchema),
1304
+ plumbing: document('plumbing', PlumbingSchema),
1305
+ state: document('state', StateSchema),
1306
+ 'commons-costs': document('commons-costs', CommonsCostsSchema),
1307
+ ...Object.fromEntries(
1308
+ Object.entries(wireRoots).map(([name, schema]) => [
1309
+ name,
1310
+ document(name, schema),
1311
+ ]),
1312
+ ),
1313
+ }
1314
+ }
1315
+
1316
+ /** JSON-only declaration discovery. Rules describe admission; this document never grants admission. */
1317
+ export interface SchemaDeclaration {
1318
+ kind: string
1319
+ rules: {
1320
+ kind: string
1321
+ requirement?: string | number | boolean
1322
+ message?: string
1323
+ }[]
1324
+ properties?: Record<string, SchemaDeclaration>
1325
+ items?: SchemaDeclaration[]
1326
+ item?: SchemaDeclaration
1327
+ alternatives?: SchemaDeclaration[]
1328
+ wrapped?: SchemaDeclaration
1329
+ optional?: boolean
1330
+ default?: string | number | boolean | null | object
1331
+ value?: string | number | boolean
1332
+ values?: (string | number | boolean)[]
1333
+ key?: SchemaDeclaration
1334
+ valueSchema?: SchemaDeclaration
1335
+ rest?: SchemaDeclaration
1336
+ }
1337
+
1338
+ function declarationOf(value: unknown): SchemaDeclaration {
1339
+ if (typeof value !== 'object' || value === null)
1340
+ throw new Error('Expected a defining schema')
1341
+ const read = (key: string): unknown => Reflect.get(value, key)
1342
+ const type = read('type')
1343
+ if (typeof type !== 'string')
1344
+ throw new Error('Expected a defining schema type')
1345
+ const pipeline = read('pipe')
1346
+ if (Array.isArray(pipeline)) {
1347
+ const schemas = pipeline.filter(
1348
+ (part: unknown) =>
1349
+ typeof part === 'object' &&
1350
+ part !== null &&
1351
+ Reflect.get(part, 'kind') === 'schema',
1352
+ )
1353
+ const base: unknown = schemas.at(-1)
1354
+ if (base === undefined) throw new Error('Missing pipeline schema')
1355
+ const declaration = declarationOf(base)
1356
+ for (const part of pipeline) {
1357
+ if (
1358
+ typeof part !== 'object' ||
1359
+ part === null ||
1360
+ Reflect.get(part, 'kind') === 'schema'
1361
+ )
1362
+ continue
1363
+ const kind: unknown = Reflect.get(part, 'type'),
1364
+ requirement: unknown = Reflect.get(part, 'requirement'),
1365
+ message: unknown = Reflect.get(part, 'message')
1366
+ if (typeof kind !== 'string')
1367
+ throw new Error('Missing admission rule type')
1368
+ declaration.rules.push({
1369
+ kind,
1370
+ ...(requirement instanceof RegExp
1371
+ ? { requirement: requirement.source }
1372
+ : typeof requirement === 'number' ||
1373
+ typeof requirement === 'string' ||
1374
+ typeof requirement === 'boolean'
1375
+ ? { requirement }
1376
+ : {}),
1377
+ ...(typeof message === 'string' ? { message } : {}),
1378
+ })
1379
+ }
1380
+ return declaration
1381
+ }
1382
+ const declaration: SchemaDeclaration = { kind: type, rules: [] }
1383
+ const entries = read('entries'),
1384
+ items = read('items'),
1385
+ item = read('item'),
1386
+ alternatives = read('options'),
1387
+ wrapped = read('wrapped')
1388
+ if (typeof entries === 'object' && entries !== null)
1389
+ declaration.properties = Object.fromEntries(
1390
+ Object.entries(entries).map(([key, schema]) => [
1391
+ key,
1392
+ declarationOf(schema),
1393
+ ]),
1394
+ )
1395
+ if (Array.isArray(items)) declaration.items = items.map(declarationOf)
1396
+ if (typeof item === 'object' && item !== null)
1397
+ declaration.item = declarationOf(item)
1398
+ if (Array.isArray(alternatives)) {
1399
+ if (
1400
+ alternatives.every(
1401
+ (option: unknown) =>
1402
+ typeof option === 'string' ||
1403
+ typeof option === 'number' ||
1404
+ typeof option === 'boolean',
1405
+ )
1406
+ )
1407
+ declaration.values = alternatives
1408
+ else declaration.alternatives = alternatives.map(declarationOf)
1409
+ }
1410
+ if (typeof wrapped === 'object' && wrapped !== null)
1411
+ declaration.wrapped = declarationOf(wrapped)
1412
+ for (const [source, target] of [
1413
+ ['key', 'key'],
1414
+ ['value', 'valueSchema'],
1415
+ ['rest', 'rest'],
1416
+ ] as const) {
1417
+ const child = read(source)
1418
+ if (typeof child === 'object' && child !== null)
1419
+ declaration[target] = declarationOf(child)
1420
+ }
1421
+ if (type === 'optional' || type === 'exact_optional')
1422
+ declaration.optional = true
1423
+ const fallback = read('default'),
1424
+ literal = read('literal')
1425
+ if (
1426
+ fallback === null ||
1427
+ typeof fallback === 'string' ||
1428
+ typeof fallback === 'number' ||
1429
+ typeof fallback === 'boolean' ||
1430
+ typeof fallback === 'object'
1431
+ )
1432
+ declaration.default = structuredClone(fallback)
1433
+ if (
1434
+ typeof literal === 'string' ||
1435
+ typeof literal === 'number' ||
1436
+ typeof literal === 'boolean'
1437
+ )
1438
+ declaration.value = literal
1439
+ return declaration
1440
+ }
1441
+
1442
+ /** Inspect every defining field, tuple and union without reaching into Valibot; semantic rules remain mandatory. */
1443
+ export function schemaDeclaration(schema: GenericSchema): SchemaDeclaration {
1444
+ return declarationOf(schema)
1445
+ }
1446
+
1447
+ /** Select an existing JSON document field by RFC 6901 pointer; malformed escapes and absent fields refuse. */
1448
+ export function schemaAt(document: object, pointer = ''): unknown {
1449
+ if (pointer === '') return document
1450
+ if (!pointer.startsWith('/'))
1451
+ throw new Error('Schema pointer must be empty or start with /')
1452
+ let value: unknown = document
1453
+ for (const token of pointer.slice(1).split('/')) {
1454
+ if (/~(?![01])/u.test(token))
1455
+ throw new Error('Invalid schema pointer escape')
1456
+ const key = token.replaceAll('~1', '/').replaceAll('~0', '~')
1457
+ if (
1458
+ typeof value !== 'object' ||
1459
+ value === null ||
1460
+ !Object.hasOwn(value, key)
1461
+ )
1462
+ throw new Error(`Unknown schema pointer: ${pointer}`)
1463
+ value = Reflect.get(value, key)
1464
+ }
1465
+ return value
1466
+ }
1467
+
1468
+ /** Declarative author composition; named strings resolve only defining format roots. */