From 82eaccb245a70d978e518b75719e4ed546440928 Mon Sep 17 00:00:00 2001 From: Misode Date: Mon, 13 May 2024 21:14:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20old=20json=20checkers?= =?UTF-8?q?=20(#1127)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../checker/primitives/boolean.spec.js | 194 -- .../test-out/checker/primitives/list.spec.js | 1988 ------------ .../checker/primitives/number.spec.js | 2006 ------------ .../checker/primitives/object.spec.js | 2706 ----------------- .../checker/primitives/string.spec.js | 119 - .../src/json/checker/data/advancement.ts | 739 ----- .../src/json/checker/data/biome.ts | 227 -- .../src/json/checker/data/common.ts | 382 --- .../src/json/checker/data/dimension.ts | 327 -- .../src/json/checker/data/feature.ts | 1043 ------- .../src/json/checker/data/index.ts | 64 - .../src/json/checker/data/loot_table.ts | 367 --- .../src/json/checker/data/recipe.ts | 76 - .../src/json/checker/data/structure.ts | 234 -- .../java-edition/src/json/checker/data/tag.ts | 53 - .../src/json/checker/data/text_component.ts | 225 -- .../src/json/checker/util/advancement.ts | 21 - .../src/json/checker/util/block_states.ts | 105 - .../src/json/checker/util/color.ts | 77 - .../src/json/checker/util/index.ts | 7 - .../java-edition/src/json/checker/util/nbt.ts | 95 - .../src/json/checker/util/recipe.ts | 27 - .../src/json/checker/util/uuid.ts | 11 - .../src/json/checker/util/version.ts | 124 - .../src/mcfunction/checker/index.ts | 3 +- .../test/json/checker/vanilla.spec.ts | 58 - packages/json/src/checker/JsonChecker.ts | 9 - packages/json/src/checker/index.ts | 2 - .../json/src/checker/primitives/boolean.ts | 12 - packages/json/src/checker/primitives/index.ts | 6 - packages/json/src/checker/primitives/list.ts | 64 - .../json/src/checker/primitives/number.ts | 49 - .../json/src/checker/primitives/object.ts | 366 --- .../json/src/checker/primitives/string.ts | 105 - packages/json/src/checker/primitives/util.ts | 109 - packages/json/src/index.ts | 1 - .../test/checker/primitives/boolean.spec.ts | 17 - .../json/test/checker/primitives/list.spec.ts | 24 - .../test/checker/primitives/number.spec.ts | 37 - .../test/checker/primitives/object.spec.ts | 30 - .../test/checker/primitives/string.spec.ts | 10 - packages/json/test/utils.ts | 48 - 42 files changed, 1 insertion(+), 12166 deletions(-) delete mode 100644 __snapshots__/packages/json/test-out/checker/primitives/boolean.spec.js delete mode 100644 __snapshots__/packages/json/test-out/checker/primitives/list.spec.js delete mode 100644 __snapshots__/packages/json/test-out/checker/primitives/number.spec.js delete mode 100644 __snapshots__/packages/json/test-out/checker/primitives/object.spec.js delete mode 100644 __snapshots__/packages/json/test-out/checker/primitives/string.spec.js delete mode 100644 packages/java-edition/src/json/checker/data/advancement.ts delete mode 100644 packages/java-edition/src/json/checker/data/biome.ts delete mode 100644 packages/java-edition/src/json/checker/data/common.ts delete mode 100644 packages/java-edition/src/json/checker/data/dimension.ts delete mode 100644 packages/java-edition/src/json/checker/data/feature.ts delete mode 100644 packages/java-edition/src/json/checker/data/index.ts delete mode 100644 packages/java-edition/src/json/checker/data/loot_table.ts delete mode 100644 packages/java-edition/src/json/checker/data/recipe.ts delete mode 100644 packages/java-edition/src/json/checker/data/structure.ts delete mode 100644 packages/java-edition/src/json/checker/data/tag.ts delete mode 100644 packages/java-edition/src/json/checker/data/text_component.ts delete mode 100644 packages/java-edition/src/json/checker/util/advancement.ts delete mode 100644 packages/java-edition/src/json/checker/util/block_states.ts delete mode 100644 packages/java-edition/src/json/checker/util/color.ts delete mode 100644 packages/java-edition/src/json/checker/util/index.ts delete mode 100644 packages/java-edition/src/json/checker/util/nbt.ts delete mode 100644 packages/java-edition/src/json/checker/util/recipe.ts delete mode 100644 packages/java-edition/src/json/checker/util/uuid.ts delete mode 100644 packages/java-edition/src/json/checker/util/version.ts delete mode 100644 packages/java-edition/test/json/checker/vanilla.spec.ts delete mode 100644 packages/json/src/checker/JsonChecker.ts delete mode 100644 packages/json/src/checker/index.ts delete mode 100644 packages/json/src/checker/primitives/boolean.ts delete mode 100644 packages/json/src/checker/primitives/index.ts delete mode 100644 packages/json/src/checker/primitives/list.ts delete mode 100644 packages/json/src/checker/primitives/number.ts delete mode 100644 packages/json/src/checker/primitives/object.ts delete mode 100644 packages/json/src/checker/primitives/string.ts delete mode 100644 packages/json/src/checker/primitives/util.ts delete mode 100644 packages/json/test/checker/primitives/boolean.spec.ts delete mode 100644 packages/json/test/checker/primitives/list.spec.ts delete mode 100644 packages/json/test/checker/primitives/number.spec.ts delete mode 100644 packages/json/test/checker/primitives/object.spec.ts delete mode 100644 packages/json/test/checker/primitives/string.spec.ts diff --git a/__snapshots__/packages/json/test-out/checker/primitives/boolean.spec.js b/__snapshots__/packages/json/test-out/checker/primitives/boolean.spec.js deleted file mode 100644 index 5f25c51d4..000000000 --- a/__snapshots__/packages/json/test-out/checker/primitives/boolean.spec.js +++ /dev/null @@ -1,194 +0,0 @@ -exports['JSON boolean boolean Check ""true"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "true", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:boolean", - "typedoc": "Boolean" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 6 - }, - "message": "Expected a boolean", - "severity": 3 - } - ] -} - -exports['JSON boolean boolean Check "1" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 1, - "expectation": [ - { - "type": "json:boolean", - "typedoc": "Boolean" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a boolean", - "severity": 3 - } - ] -} - -exports['JSON boolean boolean Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:boolean", - "typedoc": "Boolean" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON boolean boolean Check "tru" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 0 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 0, - "end": 0 - } - } - ], - "expectation": [ - { - "type": "json:boolean", - "typedoc": "Boolean" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 0 - }, - "message": "Expected a boolean", - "severity": 3 - } - ] -} - -exports['JSON boolean boolean Check "true" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 4 - }, - "value": true, - "expectation": [ - { - "type": "json:boolean", - "typedoc": "Boolean" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON boolean boolean Check "trues" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 4 - }, - "value": true, - "expectation": [ - { - "type": "json:boolean", - "typedoc": "Boolean" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} diff --git a/__snapshots__/packages/json/test-out/checker/primitives/list.spec.js b/__snapshots__/packages/json/test-out/checker/primitives/list.spec.js deleted file mode 100644 index cd962e767..000000000 --- a/__snapshots__/packages/json/test-out/checker/primitives/list.spec.js +++ /dev/null @@ -1,1988 +0,0 @@ -exports['JSON list listOf(int) Check "5" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 5, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected an array", - "severity": 3 - } - ] -} - -exports['JSON list listOf(int) Check "["foo", "bar"]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 14 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 1, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 2, - "end": 2 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:string", - "range": { - "start": 1, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 2, - "end": 2 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "sep": { - "start": 6, - "end": 7 - } - }, - { - "type": "item", - "range": { - "start": 8, - "end": 13 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 8, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "bar", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 9, - "end": 9 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:string", - "range": { - "start": 8, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "bar", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 9, - "end": 9 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 1, - "end": 6 - }, - "message": "Expected an integer", - "severity": 3 - }, - { - "range": { - "start": 8, - "end": 13 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON list listOf(int) Check "[1, 4, 6]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 9 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 3 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "sep": { - "start": 2, - "end": 3 - } - }, - { - "type": "item", - "range": { - "start": 4, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 4, - "end": 5 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 4, - "end": 5 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "sep": { - "start": 5, - "end": 6 - } - }, - { - "type": "item", - "range": { - "start": 7, - "end": 8 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON list listOf(int) Check "[[4, 6]]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 8 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "json:array", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "item", - "range": { - "start": 2, - "end": 4 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - }, - "sep": { - "start": 3, - "end": 4 - } - }, - { - "type": "item", - "range": { - "start": 5, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:array", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "item", - "range": { - "start": 2, - "end": 4 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - }, - "sep": { - "start": 3, - "end": 4 - } - }, - { - "type": "item", - "range": { - "start": 5, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 1, - "end": 7 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON list listOf(int) Check "[]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON list listOf(listOf(int)) Check "5" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 5, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:array", - "typedoc": "Array" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected an array", - "severity": 3 - } - ] -} - -exports['JSON list listOf(listOf(int)) Check "["foo", "bar"]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 14 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 1, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 2, - "end": 2 - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ], - "value": { - "type": "json:string", - "range": { - "start": 1, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 2, - "end": 2 - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "sep": { - "start": 6, - "end": 7 - } - }, - { - "type": "item", - "range": { - "start": 8, - "end": 13 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 8, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "bar", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 9, - "end": 9 - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ], - "value": { - "type": "json:string", - "range": { - "start": 8, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "bar", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 9, - "end": 9 - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:array", - "typedoc": "Array" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 1, - "end": 6 - }, - "message": "Expected an array", - "severity": 3 - }, - { - "range": { - "start": 8, - "end": 13 - }, - "message": "Expected an array", - "severity": 3 - } - ] -} - -exports['JSON list listOf(listOf(int)) Check "[1, 4, 6]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 9 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 3 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 1, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 1, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "sep": { - "start": 2, - "end": 3 - } - }, - { - "type": "item", - "range": { - "start": 4, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 4, - "end": 5 - }, - "value": 4, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 4, - "end": 5 - }, - "value": 4, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - }, - "sep": { - "start": 5, - "end": 6 - } - }, - { - "type": "item", - "range": { - "start": 7, - "end": 8 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:array", - "typedoc": "Array" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 1, - "end": 2 - }, - "message": "Expected an array", - "severity": 3 - }, - { - "range": { - "start": 4, - "end": 5 - }, - "message": "Expected an array", - "severity": 3 - }, - { - "range": { - "start": 7, - "end": 8 - }, - "message": "Expected an array", - "severity": 3 - } - ] -} - -exports['JSON list listOf(listOf(int)) Check "[[4, 6]]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 8 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "json:array", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "item", - "range": { - "start": 2, - "end": 4 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "sep": { - "start": 3, - "end": 4 - } - }, - { - "type": "item", - "range": { - "start": 5, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ], - "value": { - "type": "json:array", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "item", - "range": { - "start": 2, - "end": 4 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "sep": { - "start": 3, - "end": 4 - } - }, - { - "type": "item", - "range": { - "start": 5, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:array", - "typedoc": "Array" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON list listOf(listOf(int)) Check "[]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:array", - "typedoc": "Array" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON list listOf(string) Check "5" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 5, - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected an array", - "severity": 3 - } - ] -} - -exports['JSON list listOf(string) Check "["foo", "bar"]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 14 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 1, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 2, - "end": 2 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ], - "value": { - "type": "json:string", - "range": { - "start": 1, - "end": 6 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 2, - "end": 2 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 6, - "end": 7 - } - }, - { - "type": "item", - "range": { - "start": 8, - "end": 13 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 8, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "bar", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 9, - "end": 9 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ], - "value": { - "type": "json:string", - "range": { - "start": 8, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "bar", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 9, - "end": 9 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON list listOf(string) Check "[1, 4, 6]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 9 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 3 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 1, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 1, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 2, - "end": 3 - } - }, - { - "type": "item", - "range": { - "start": 4, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 4, - "end": 5 - }, - "value": 4, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 4, - "end": 5 - }, - "value": 4, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 5, - "end": 6 - } - }, - { - "type": "item", - "range": { - "start": 7, - "end": 8 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ], - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 1, - "end": 2 - }, - "message": "Expected a string", - "severity": 3 - }, - { - "range": { - "start": 4, - "end": 5 - }, - "message": "Expected a string", - "severity": 3 - }, - { - "range": { - "start": 7, - "end": 8 - }, - "message": "Expected a string", - "severity": 3 - } - ] -} - -exports['JSON list listOf(string) Check "[[4, 6]]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 8 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "json:array", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "item", - "range": { - "start": 2, - "end": 4 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - }, - "sep": { - "start": 3, - "end": 4 - } - }, - { - "type": "item", - "range": { - "start": 5, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ], - "value": { - "type": "json:array", - "range": { - "start": 1, - "end": 7 - }, - "children": [ - { - "type": "item", - "range": { - "start": 2, - "end": 4 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 2, - "end": 3 - }, - "value": 4 - }, - "sep": { - "start": 3, - "end": 4 - } - }, - { - "type": "item", - "range": { - "start": 5, - "end": 6 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 5, - "end": 6 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 1, - "end": 7 - }, - "message": "Expected a string", - "severity": 3 - } - ] -} - -exports['JSON list listOf(string) Check "[]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:array", - "typedoc": "Array", - "items": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} diff --git a/__snapshots__/packages/json/test-out/checker/primitives/number.spec.js b/__snapshots__/packages/json/test-out/checker/primitives/number.spec.js deleted file mode 100644 index 0e8c5f777..000000000 --- a/__snapshots__/packages/json/test-out/checker/primitives/number.spec.js +++ /dev/null @@ -1,2006 +0,0 @@ -exports['JSON number float Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a float", - "severity": 3 - } - ] -} - -exports['JSON number float Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number float Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected a float", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(-5, undefined) Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a float", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(-5, undefined) Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected a number greater than or equal to -5", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(-5, undefined) Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 2 - }, - "message": "Expected a number greater than or equal to -5", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(-5, undefined) Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number floatRange(-5, undefined) Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number floatRange(-5, undefined) Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number floatRange(-5, undefined) Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number floatRange(-5, undefined) Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number floatRange(-5, undefined) Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-5, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected a float", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a float", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected a number between 1 and 2.4", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 2 - }, - "message": "Expected a number between 1 and 2.4", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number floatRange(1, 2.4) Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between 1 and 2.4", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a number between 1 and 2.4", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a number between 1 and 2.4", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between 1 and 2.4", - "severity": 3 - } - ] -} - -exports['JSON number floatRange(1, 2.4) Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 2.4)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected a float", - "severity": 3 - } - ] -} - -exports['JSON number int Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number int Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number int Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number int Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number int Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number int Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number int Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number int Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number int Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(-9, 0) Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between -9 and 0", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between -9 and 0", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a number between -9 and 0", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between -9 and 0", - "severity": 3 - } - ] -} - -exports['JSON number intRange(-9, 0) Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-9, 0)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 2 - }, - "message": "Expected a number between 1 and 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(1, 3) Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between 1 and 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a number between 1 and 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number between 1 and 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(1, 3) Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(1, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(3, undefined) Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(3, undefined) Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(3, undefined) Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 2 - }, - "message": "Expected a number greater than or equal to 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(3, undefined) Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number greater than or equal to 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(3, undefined) Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(3, undefined) Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(3, undefined) Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(3, undefined) Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(3, undefined) Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(3, +∞)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check ""5"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 3 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "5", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check "-5.62" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 5 - }, - "value": -5.62, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check "-7" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 2 - }, - "value": -7, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(undefined, 3) Check "2" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 2, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON number intRange(undefined, 3) Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number smaller than or equal to 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check "4.3" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 4.3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check "6e4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 3 - }, - "value": 60000, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected a number smaller than or equal to 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check "8b" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 8, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a number smaller than or equal to 3", - "severity": 3 - } - ] -} - -exports['JSON number intRange(undefined, 3) Check "false" 1'] = { - "node": { - "type": "json:boolean", - "range": { - "start": 0, - "end": 5 - }, - "value": false, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number(-∞, 3)" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 5 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} diff --git a/__snapshots__/packages/json/test-out/checker/primitives/object.spec.js b/__snapshots__/packages/json/test-out/checker/primitives/object.spec.js deleted file mode 100644 index 7bf58321d..000000000 --- a/__snapshots__/packages/json/test-out/checker/primitives/object.spec.js +++ /dev/null @@ -1,2706 +0,0 @@ -exports['JSON object object() Check "[2]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 3 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 2 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an object", - "severity": 3 - } - ] -} - -exports['JSON object object() Check "{ "a": 1 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1 - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object object() Check "{ "a": 3, "b": "foo" }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 22 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3 - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3 - }, - "end": { - "start": 8, - "end": 9 - } - }, - { - "type": "pair", - "range": { - "start": 10, - "end": 21 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ] - }, - { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ] - }, - "sep": { - "start": 13, - "end": 14 - }, - "value": { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object object() Check "{ "b": 6 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6 - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object object() Check "{}" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object object(string, () => int) Check "[2]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 3 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 2 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "keys": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an object", - "severity": 3 - } - ] -} - -exports['JSON object object(string, () => int) Check "{ "a": 1 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "keys": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object object(string, () => int) Check "{ "a": 3, "b": "foo" }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 22 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "end": { - "start": 8, - "end": 9 - } - }, - { - "type": "pair", - "range": { - "start": 10, - "end": 21 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 13, - "end": 14 - }, - "value": { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ], - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "keys": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 15, - "end": 20 - }, - "message": "Expected an integer", - "severity": 3 - } - ] -} - -exports['JSON object object(string, () => int) Check "{ "b": 6 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "keys": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object object(string, () => int) Check "{}" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "keys": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object record({ a: int }) Check "[2]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 3 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 2 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an object", - "severity": 3 - } - ] -} - -exports['JSON object record({ a: int }) Check "{ "a": 1 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object record({ a: int }) Check "{ "a": 3, "b": "foo" }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 22 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "end": { - "start": 8, - "end": 9 - } - }, - { - "type": "pair", - "range": { - "start": 10, - "end": 21 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ] - }, - { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ] - }, - "sep": { - "start": 13, - "end": 14 - }, - "value": { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 10, - "end": 13 - }, - "message": "Unknown property “b”", - "severity": 2 - } - ] -} - -exports['JSON object record({ a: int }) Check "{ "b": 6 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6 - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Missing property “a”", - "severity": 3 - }, - { - "range": { - "start": 2, - "end": 5 - }, - "message": "Unknown property “b”", - "severity": 2 - } - ] -} - -exports['JSON object record({ a: int }) Check "{}" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Missing property “a”", - "severity": 3 - } - ] -} - -exports['JSON object record({ a: opt(int) }) Check "[2]" 1'] = { - "node": { - "type": "json:array", - "range": { - "start": 0, - "end": 3 - }, - "children": [ - { - "type": "item", - "range": { - "start": 1, - "end": 2 - }, - "children": [ - { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - ], - "value": { - "type": "json:number", - "range": { - "start": 1, - "end": 2 - }, - "value": 2 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ], - "opt": true - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 3 - }, - "message": "Expected an object", - "severity": 3 - } - ] -} - -exports['JSON object record({ a: opt(int) }) Check "{ "a": 1 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 1, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ], - "opt": true - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON object record({ a: opt(int) }) Check "{ "a": 3, "b": "foo" }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 22 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "a", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ], - "hover": "```typescript\n.a: Number\n```" - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 3, - "expectation": [ - { - "type": "json:number", - "typedoc": "Number" - } - ] - }, - "end": { - "start": 8, - "end": 9 - } - }, - { - "type": "pair", - "range": { - "start": 10, - "end": 21 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ] - }, - { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ] - } - ], - "key": { - "type": "json:string", - "range": { - "start": 10, - "end": 13 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 11, - "end": 11 - } - } - ] - }, - "sep": { - "start": 13, - "end": 14 - }, - "value": { - "type": "json:string", - "range": { - "start": 15, - "end": 20 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 16, - "end": 16 - } - } - ] - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ], - "opt": true - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 10, - "end": 13 - }, - "message": "Unknown property “b”", - "severity": 2 - } - ] -} - -exports['JSON object record({ a: opt(int) }) Check "{ "b": 6 }" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 10 - }, - "children": [ - { - "type": "pair", - "range": { - "start": 2, - "end": 9 - }, - "children": [ - { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6 - } - ], - "key": { - "type": "json:string", - "range": { - "start": 2, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "b", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 3, - "end": 3 - } - } - ] - }, - "sep": { - "start": 5, - "end": 6 - }, - "value": { - "type": "json:number", - "range": { - "start": 7, - "end": 8 - }, - "value": 6 - } - } - ], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ], - "opt": true - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 2, - "end": 5 - }, - "message": "Unknown property “b”", - "severity": 2 - } - ] -} - -exports['JSON object record({ a: opt(int) }) Check "{}" 1'] = { - "node": { - "type": "json:object", - "range": { - "start": 0, - "end": 2 - }, - "children": [], - "expectation": [ - { - "type": "json:object", - "typedoc": "Object", - "fields": [ - { - "key": "a", - "value": [ - { - "type": "json:number", - "typedoc": "Number" - } - ], - "opt": true - } - ] - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} diff --git a/__snapshots__/packages/json/test-out/checker/primitives/string.spec.js b/__snapshots__/packages/json/test-out/checker/primitives/string.spec.js deleted file mode 100644 index 2b2b39459..000000000 --- a/__snapshots__/packages/json/test-out/checker/primitives/string.spec.js +++ /dev/null @@ -1,119 +0,0 @@ -exports['JSON string string Check ""foo"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON string string Check ""foo"bar"" 1'] = { - "node": { - "type": "json:string", - "range": { - "start": 0, - "end": 5 - }, - "options": { - "escapable": { - "characters": [ - "b", - "f", - "n", - "r", - "t" - ], - "unicode": true - }, - "quotes": [ - "\"" - ] - }, - "value": "foo", - "valueMap": [ - { - "inner": { - "start": 0, - "end": 0 - }, - "outer": { - "start": 1, - "end": 1 - } - } - ], - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "parserErrors": [], - "checkerErrors": [] -} - -exports['JSON string string Check "4" 1'] = { - "node": { - "type": "json:number", - "range": { - "start": 0, - "end": 1 - }, - "value": 4, - "expectation": [ - { - "type": "json:string", - "typedoc": "String" - } - ] - }, - "parserErrors": [], - "checkerErrors": [ - { - "range": { - "start": 0, - "end": 1 - }, - "message": "Expected a string", - "severity": 3 - } - ] -} diff --git a/packages/java-edition/src/json/checker/data/advancement.ts b/packages/java-edition/src/json/checker/data/advancement.ts deleted file mode 100644 index ae4df85ce..000000000 --- a/packages/java-edition/src/json/checker/data/advancement.ts +++ /dev/null @@ -1,739 +0,0 @@ -import type { JsonStringNode } from '@spyglassmc/json' -import type { JsonCheckerContext } from '@spyglassmc/json/lib/checker/index.js' -import { - any, - as, - boolean, - dispatch, - extract, - extractStringArray, - int, - listOf, - literal, - object, - opt, - pick, - record, - ref, - resource, - simpleString, - string, - when, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { dissectUri } from '../../../binder/index.js' -import { - blockStateMap, - criterionReference, - deprecated, - nbt, - versioned, -} from '../util/index.js' -import { float_bounds, int_bounds, Slots } from './common.js' -import { predicate } from './loot_table.js' -import { text_component } from './text_component.js' - -const Triggers = (ctx: JsonCheckerContext) => [ - 'minecraft:bee_nest_destroyed', - 'minecraft:bred_animals', - 'minecraft:brewed_potion', - 'minecraft:changed_dimension', - 'minecraft:channeled_lightning', - 'minecraft:construct_beacon', - 'minecraft:consume_item', - 'minecraft:cured_zombie_villager', - 'minecraft:effects_changed', - 'minecraft:enchanted_item', - 'minecraft:enter_block', - 'minecraft:entity_hurt_player', - 'minecraft:entity_killed_player', - ...versioned(ctx, '1.18', ['minecraft:fall_from_height']), - 'minecraft:filled_bucket', - 'minecraft:fishing_rod_hooked', - 'minecraft:hero_of_the_village', - 'minecraft:impossible', - 'minecraft:inventory_changed', - 'minecraft:item_durability_changed', - ...versioned(ctx, '1.16', ['minecraft:item_used_on_block']), - 'minecraft:killed_by_crossbow', - 'minecraft:levitation', - ...versioned(ctx, '1.17', ['minecraft:lightning_strike']), - 'minecraft:location', - 'minecraft:nether_travel', - 'minecraft:placed_block', - ...versioned(ctx, '1.16', ['minecraft:player_generates_container_loot']), - 'minecraft:player_hurt_entity', - ...versioned(ctx, '1.16', ['minecraft:player_interacted_with_entity']), - 'minecraft:player_killed_entity', - 'minecraft:recipe_unlocked', - ...versioned(ctx, '1.18', ['minecraft:ride_entity_in_lava']), - 'minecraft:shot_crossbow', - ...versioned(ctx, ['minecraft:safely_harvest_honey'], '1.16'), - 'minecraft:slept_in_bed', - 'minecraft:slide_down_block', - ...versioned(ctx, '1.17', ['minecraft:started_riding']), - 'minecraft:summoned_entity', - 'minecraft:tame_animal', - ...versioned(ctx, '1.16', ['minecraft:target_hit']), - 'minecraft:tick', - ...versioned(ctx, '1.16', ['minecraft:thrown_item_picked_up_by_entity']), - 'minecraft:used_ender_eye', - 'minecraft:used_totem', - ...versioned(ctx, '1.17', ['minecraft:using_item']), - 'minecraft:villager_trade', - 'minecraft:voluntary_exile', -] - -export const item_predicate = as( - 'item', - dispatch((props, ctx) => - record({ - ...versioned( - ctx, - { - item: opt(resource('item')), - }, - '1.17', - { - items: opt(listOf(resource('item'))), - }, - ), - tag: opt(resource('tag/item')), - count: opt(int_bounds), - durability: opt(float_bounds), - potion: opt(resource('potion')), - nbt: opt( - nbt({ - registry: 'item', - ids: extractStringArray('items', props), - tag: extract('tag', props), - }), - ), - enchantments: opt( - listOf( - record({ - enchantment: opt(resource('enchantment')), - levels: opt(int_bounds), - }), - ), - ), - }) - ), -) - -export const block_predicate = as( - 'block', - dispatch((props, ctx) => - record({ - ...versioned( - ctx, - { - block: opt(resource('block')), - }, - '1.17', - { - blocks: opt(listOf(resource('block'))), - }, - ), - tag: opt(resource('tag/block')), - nbt: opt( - nbt({ - registry: 'block', - ids: extractStringArray('blocks', props), - tag: extract('tag', props), - }), - ), - state: opt( - blockStateMap({ - ids: extractStringArray('blocks', props), - tag: extract('tag', props), - mixedTypes: true, - }), - ), - }) - ), -) - -export const fluid_predicate = as( - 'fluid', - dispatch((props) => - record({ - fluid: opt(resource('fluid')), - tag: opt(resource('tag/fluid')), - state: opt( - blockStateMap({ - category: 'fluid', - id: extract('fluid', props), - tag: extract('tag', props), - mixedTypes: true, - }), - ), - }) - ), -) - -export const location_predicate = as( - 'location', - dispatch((_, ctx) => - record({ - position: opt( - record({ - x: opt(float_bounds), - y: opt(float_bounds), - z: opt(float_bounds), - }), - ), - biome: opt(resource('worldgen/biome')), - feature: opt(simpleString), // TODO structure features - dimension: opt(resource('dimension')), - block: opt(block_predicate), - fluid: opt(fluid_predicate), - light: opt( - record({ - light: int_bounds, - }), - ), - smokey: opt(versioned(ctx, '1.16', boolean)), - }) - ), -) - -export const distance_predicate = as( - 'distance', - record({ - x: opt(float_bounds), - y: opt(float_bounds), - z: opt(float_bounds), - absolute: opt(float_bounds), - horizontal: opt(float_bounds), - }), -) - -export const mob_effect_predicate = as( - 'mob_effect', - record({ - amplifier: opt(int_bounds), - duration: opt(int_bounds), - ambient: opt(boolean), - visible: opt(boolean), - }), -) - -export const statistic_predicate = as( - 'statistic', - dispatch('type', (stat) => - record({ - type: resource('stat_type'), - ...pick(stat, { - mined: { stat: resource('block') }, - crafted: { stat: resource('item') }, - used: { stat: resource('item') }, - broken: { stat: resource('item') }, - picked_up: { stat: resource('item') }, - dropped: { stat: resource('item') }, - killed: { stat: resource('entity_type') }, - killed_by: { stat: resource('entity_type') }, - custom: { stat: resource('custom_stat') }, - }), - value: int_bounds, - })), -) - -export const player_predicate = as( - 'player', - dispatch((_, ctx) => - record({ - gamemode: opt( - literal(['survival', 'adventure', 'creative', 'spectator']), - ), - level: opt(int_bounds), - advancements: opt( - object(resource('advancement'), (advancement) => - any([ - boolean, - object(criterionReference(advancement), () => boolean), - ])), - ), - recipes: opt(object(resource('recipe'), () => boolean)), - stats: opt(listOf(statistic_predicate)), - looking_at: opt( - versioned( - ctx, - '1.17', - ref(() => entity_predicate), - ), - ), - }) - ), -) - -export const entity_predicate = as( - 'entity', - dispatch((props, ctx) => - record({ - type: opt(resource('entity_type', true)), - nbt: opt( - nbt({ registry: 'entity_type', idOrTag: extract('type', props) }), - ), - team: opt(literal('team')), - location: opt(location_predicate), - stepping_on: opt(versioned(ctx, '1.17', location_predicate)), - distance: opt(distance_predicate), - flags: opt( - record({ - is_on_fire: opt(boolean), - is_sneaking: opt(boolean), - is_sprinting: opt(boolean), - is_swimming: opt(boolean), - is_baby: opt(boolean), - }), - ), - equipment: opt(object(literal(Slots), () => item_predicate)), - effects: opt(object(simpleString, () => mob_effect_predicate)), - player: opt(player_predicate), - vehicle: opt( - versioned( - ctx, - '1.16', - ref(() => entity_predicate), - ), - ), - passenger: opt( - versioned( - ctx, - '1.17', - ref(() => entity_predicate), - ), - ), - targeted_entity: opt( - versioned( - ctx, - '1.16', - ref(() => entity_predicate), - ), - ), - lightning_bolt: opt( - versioned( - ctx, - '1.17', - record({ - blocks_set_on_fire: opt(int_bounds), - entity_struck: opt(ref(() => entity_predicate)), - }), - ), - ), - fishing_hook: opt( - versioned( - ctx, - '1.16', - record({ - in_open_water: opt(boolean), - }), - ), - ), - catType: opt(simpleString), - }) - ), -) - -export const damage_source_predicate = as( - 'damage_source', - record({ - is_explosion: opt(boolean), - is_fire: opt(boolean), - is_magic: opt(boolean), - is_projectile: opt(boolean), - is_lightning: opt(boolean), - bypasses_armor: opt(boolean), - bypasses_invulnerability: opt(boolean), - bypasses_magic: opt(boolean), - source_entity: opt(entity_predicate), - direct_entity: opt(entity_predicate), - }), -) - -export const damage_predicate = as( - 'damage', - record({ - dealt: opt(int_bounds), - taken: opt(int_bounds), - blocked: opt(boolean), - source_entity: opt(entity_predicate), - type: opt(damage_source_predicate), - }), -) - -const entity = any([entity_predicate, listOf(ref(() => predicate))]) - -export const criterion = as( - 'criterion', - dispatch('trigger', (trigger, _, ctx) => - record({ - trigger: resource(Triggers(ctx)), - conditions: opt( - dispatch((props) => - record({ - ...versioned( - ctx, - '1.16', - when( - trigger, - ['impossible'], - {}, - { - player: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - ), - ), - ...pick(trigger, { - bee_nest_destroyed: { - block: opt(resource('block')), - item: opt(item_predicate), - num_bees_inside: opt(int), - }, - bred_animals: { - parent: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - partner: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - child: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - brewed_potion: { - potion: opt(resource('potion')), - }, - changed_dimension: { - from: opt(resource('dimension')), - to: opt(resource('dimension')), - }, - channeled_lightning: { - victims: opt( - listOf( - versioned(ctx, entity_predicate, '1.16', entity), - ), - ), - }, - construct_beacon: { - level: opt(int_bounds), - }, - consume_item: { - item: opt(item_predicate), - }, - cured_zombie_villager: { - villager: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - zombie: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - effects_changed: { - effects: opt( - object(resource('mob_effect'), () => - mob_effect_predicate), - ), - source: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - enter_block: { - block: opt(resource('block')), - state: opt( - blockStateMap({ id: extract('block', props) }), - ), - }, - enchanted_item: { - levels: opt(int_bounds), - item: opt(item_predicate), - }, - entity_hurt_player: { - damage: opt(damage_predicate), - }, - entity_killed_player: { - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - killing_blow: opt(damage_source_predicate), - }, - fall_from_height: { - start_position: opt(location_predicate), - distance: opt(distance_predicate), - }, - filled_bucket: { - item: opt(item_predicate), - }, - fishing_rod_hooked: { - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - item: opt(item_predicate), - }, - hero_of_the_village: { - location: opt( - versioned(ctx, '1.16', location_predicate), - ), - }, - inventory_changed: { - slots: opt( - record({ - empty: opt(int_bounds), - occupied: opt(int_bounds), - full: opt(int_bounds), - }), - ), - items: opt(listOf(item_predicate)), - }, - item_durability_changed: { - delta: opt(float_bounds), - durability: opt(float_bounds), - item: opt(item_predicate), - }, - item_used_on_block: { - item: opt(item_predicate), - location: opt(location_predicate), - }, - killed_by_crossbow: { - unique_entity_types: opt(int_bounds), - victims: opt( - listOf( - versioned(ctx, entity_predicate, '1.16', entity), - ), - ), - }, - levitation: { - distance: opt(distance_predicate), - duration: opt(float_bounds), - }, - lightning_strike: { - lightning: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - bystander: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - location: { - location: opt( - versioned(ctx, '1.16', location_predicate), - ), - }, - nether_travel: { - ...versioned( - ctx, - { - entered: opt(location_predicate), - }, - '1.18', - { - start_position: opt(location_predicate), - }, - ), - exited: opt(versioned(ctx, location_predicate, '1.18')), - distance: opt(distance_predicate), - }, - placed_block: { - block: opt(resource('block')), - state: opt( - blockStateMap({ id: extract('block', props) }), - ), - item: opt(item_predicate), - location: opt(location_predicate), - }, - player_generates_container_loot: { - loot_table: resource('loot_table'), - }, - player_hurt_entity: { - damage: opt(damage_predicate), - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - player_interacted_with_entity: { - item: opt(item_predicate), - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - player_killed_entity: { - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - killing_blow: opt(damage_source_predicate), - }, - recipe_unlocked: { - recipe: resource('recipe'), - }, - ride_entity_in_lava: { - start_position: opt(location_predicate), - distance: opt(distance_predicate), - }, - slept_in_bed: { - location: opt( - versioned(ctx, '1.16', location_predicate), - ), - }, - slide_down_block: { - block: opt(resource('block')), - }, - shot_crossbow: { - item: opt(item_predicate), - }, - summoned_entity: { - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - tame_animal: { - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - }, - target_hit: { - projectile: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - shooter: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - signal_strength: opt(int_bounds), - }, - thrown_item_picked_up_by_entity: { - entity: opt( - versioned(ctx, entity_predicate, '1.16', entity), - ), - item: opt(item_predicate), - }, - used_ender_eye: { - distance: opt(float_bounds), - }, - used_totem: { - item: opt(item_predicate), - }, - using_item: { - item: opt(item_predicate), - }, - villager_trade: { - villager: opt(entity_predicate), - item: opt(item_predicate), - }, - voluntary_exile: { - location: opt( - versioned(ctx, '1.16', location_predicate), - ), - }, - }), - ...when( - trigger, - [ - 'hero_of_the_village', - 'location', - 'slept_in_bed', - 'voluntary_exile', - ], - { - position: opt( - deprecated( - ctx, - '1.16', - record({ - x: opt(float_bounds), - y: opt(float_bounds), - z: opt(float_bounds), - }), - ), - ), - biome: opt( - deprecated(ctx, '1.16', resource('worldgen/biome')), - ), - feature: opt(deprecated(ctx, '1.16', simpleString)), // TODO structure features - dimension: opt( - deprecated(ctx, '1.16', resource('dimension')), - ), - block: opt(deprecated(ctx, '1.16', block_predicate)), - fluid: opt(deprecated(ctx, '1.16', fluid_predicate)), - light: opt( - deprecated( - ctx, - '1.16', - record({ - light: int_bounds, - }), - ), - ), - smokey: opt(deprecated(ctx, '1.16', boolean)), - }, - ), - }) - ), - ), - })), -) - -export const advancement = as( - 'advancement', - record({ - display: opt( - record({ - icon: dispatch((props) => - record({ - item: resource('item'), - nbt: opt( - nbt({ registry: 'item', id: extract('item', props) }), - ), - }) - ), - title: text_component, - description: text_component, - background: opt(simpleString), - frame: opt(literal(['task', 'challenge', 'goal']), 'task'), - show_toast: opt(boolean, true), - announce_to_chat: opt(boolean, true), - hidden: opt(boolean, false), - }), - ), - parent: opt(resource('advancement')), - criteria: object( - string(undefined, undefined, (node, ctx) => { - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ctx.ensureBindingStarted) { - return - } - const parts = dissectUri(ctx.doc.uri, ctx) - const advancement = `${parts?.namespace}:${parts?.identifier}` - const criterion = (node as JsonStringNode).value - ctx.symbols - .query(ctx.doc, 'advancement', advancement, criterion) - .enter({ - data: { subcategory: 'criterion' }, - usage: { type: 'definition', node }, - }) - }), - () => criterion, - ), - requirements: opt( - listOf( - listOf((node, ctx) => { - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ctx.ensureBindingStarted) { - return - } - const parts = dissectUri(ctx.doc.uri, ctx) - const advancement = `${parts?.namespace}:${parts?.identifier}` - criterionReference(advancement)(node, ctx) - }), - ), - ), - rewards: opt( - record({ - function: opt(resource('function')), - loot: opt(listOf(resource('loot_table'))), - recipes: opt(listOf(resource('recipe'))), - experience: opt(int), - }), - ), - }), -) diff --git a/packages/java-edition/src/json/checker/data/biome.ts b/packages/java-edition/src/json/checker/data/biome.ts deleted file mode 100644 index 14bb56728..000000000 --- a/packages/java-edition/src/json/checker/data/biome.ts +++ /dev/null @@ -1,227 +0,0 @@ -import type { JsonCheckerContext } from '@spyglassmc/json/lib/checker/index.js' -import { - any, - as, - boolean, - dispatch, - float, - floatRange, - int, - intRange, - listOf, - literal, - object, - opt, - record, - resource, - when, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { intColor, versioned } from '../util/index.js' -import { - block_state, - floatProvider, - height_provider, - vertical_anchor, -} from './common.js' -import { - configured_feature_list_ref, - placed_feature_list_ref, -} from './feature.js' -import { configured_structure_feature } from './structure.js' - -const BiomeCategory = (ctx: JsonCheckerContext) => [ - 'beach', - 'desert', - 'extreme_hills', - 'forest', - 'icy', - 'jungle', - 'mesa', - ...versioned(ctx, '1.18', ['mountain']), - 'mushroom', - 'nether', - 'none', - 'ocean', - 'plains', - 'river', - 'savanna', - 'swamp', - 'taiga', - 'the_end', - ...versioned(ctx, '1.17', ['underground']), -] - -const MobCategory = (ctx: JsonCheckerContext) => [ - ...versioned(ctx, '1.18', ['axolotls']), - 'monster', - 'creature', - 'ambient', - 'water_creature', - 'water_ambient', - ...versioned(ctx, '1.17', ['underground_water_creature']), - 'misc', -] - -export const configured_surface_builder = as( - 'surface_builder', - record({ - type: resource('worldgen/surface_builder'), - config: record({ - top_material: block_state, - under_material: block_state, - underwater_material: block_state, - }), - }), -) - -export const configured_carver = as( - 'carver', - dispatch('type', (type, _, ctx) => - record({ - type: resource('worldgen/carver'), - config: record({ - probability: floatRange(0, 1), - ...versioned(ctx, '1.17', { - y: height_provider, - yScale: floatProvider(), - lava_level: vertical_anchor, - aquifers_enabled: versioned(ctx, boolean, '1.18'), - debug_settings: opt( - record({ - debug_mode: opt(boolean), - air_state: opt(block_state), - water_state: opt(block_state), - lava_state: opt(block_state), - barrier_state: opt(block_state), - }), - ), - ...when(type, ['cave', 'nether_cave', 'underwater_cave'], { - horizontal_radius_multiplier: floatProvider(), - vertical_radius_multiplier: floatProvider(), - floor_level: floatProvider(-1, 1), - }), - ...when(type, ['canyon', 'underwater_canyon'], { - vertical_rotation: floatProvider(), - shape: record({ - distance_factor: floatProvider(), - thickness: floatProvider(), - width_smoothness: intRange(0, undefined), - horizontal_radius_factor: floatProvider(), - vertical_radius_default_factor: float, - vertical_radius_center_factor: float, - }), - }), - }), - }), - })), -) - -export const biome = as( - 'biome', - dispatch((props, ctx) => - record({ - ...versioned( - ctx, - { - depth: float, - scale: float, - }, - '1.18', - ), - downfall: float, - temperature: float, - temperature_modifier: opt(literal(['none', 'frozen'])), - precipitation: literal(['none', 'rain', 'snow']), - category: literal(BiomeCategory(ctx)), - effects: record({ - sky_color: intColor(), - fog_color: intColor(), - water_color: intColor(), - water_fog_color: intColor(), - grass_color: opt(intColor()), - foliage_color: opt(intColor()), - grass_color_modifier: opt( - literal(['none', 'dark_forest', 'swamp']), - ), - particle: opt( - record({ - options: record({ - type: resource('particle_type'), - }), - probability: floatRange(0, 1), - }), - ), - ambient_sound: opt(resource('sound_event')), - mood_sound: opt( - record({ - sound: resource('sound_event'), - tick_delay: int, - block_search_extent: int, - offset: float, - }), - ), - additions_sound: opt( - record({ - sound: resource('sound_event'), - tick_chance: floatRange(0, 1), - }), - ), - music: opt( - record({ - sound: resource('sound_event'), - min_delay: int, - max_delay: int, - replace_current_music: boolean, - }), - ), - }), - player_spawn_friendly: opt(versioned(ctx, boolean, '1.18')), - creature_spawn_probability: opt(floatRange(0, 0.9999999)), - spawners: object(literal(MobCategory(ctx)), () => - listOf( - record({ - type: resource('entity_type'), - weight: int, - minCount: int, - maxCount: int, - }), - )), - spawn_costs: object(resource('entity_type'), () => - record({ - energy_budget: float, - charge: float, - })), - surface_builder: versioned( - ctx, - any([ - resource('worldgen/configured_surface_builder'), - configured_surface_builder, - ]), - '1.18', - ), - carvers: object(['air', 'liquid'], () => - opt( - any([ - listOf(resource('worldgen/configured_carver')), - listOf(configured_carver), - ]), - )), - starts: versioned( - ctx, - any([ - listOf(resource('worldgen/configured_structure_feature')), - listOf(configured_structure_feature), - ]), - '1.18', - ), - features: listOf( - versioned( - ctx, - configured_feature_list_ref, - '1.18', - placed_feature_list_ref, - ), - ), - }) - ), -) diff --git a/packages/java-edition/src/json/checker/data/common.ts b/packages/java-edition/src/json/checker/data/common.ts deleted file mode 100644 index 6cec7e6bc..000000000 --- a/packages/java-edition/src/json/checker/data/common.ts +++ /dev/null @@ -1,382 +0,0 @@ -import type { JsonChecker } from '@spyglassmc/json/lib/checker/JsonChecker.js' -import { - any, - as, - dispatch, - extract, - float, - floatRange, - int, - intRange, - listOf, - literal, - opt, - pick, - record, - ref, - resource, - simpleString, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { blockStateMap } from '../util/index.js' - -function smallestEncompassingPowerOfTwo(n: number) { - n = n - 1 - n |= n >> 1 - n |= n >> 2 - n |= n >> 4 - n |= n >> 8 - n |= n >> 16 - return n + 1 -} - -const BITS_FOR_Y = 64 - - 2 * (1 + Math.log2(smallestEncompassingPowerOfTwo(30000000))) // 12 -export const Y_SIZE = (1 << BITS_FOR_Y) - 32 // 4064 -export const MAX_Y = (Y_SIZE >> 1) - 1 // 2031 -export const MIN_Y = MAX_Y - Y_SIZE + 1 // -2031 - -export const number_provider = as( - 'range', - any([ - float, - dispatch('type', (type) => - record({ - type: opt(resource('loot_number_provider_type')), - ...(type === undefined - ? { - min: number_provider, - max: number_provider, - } - : {}), - ...pick(type, { - constant: { - value: float, - }, - uniform: { - min: number_provider, - max: number_provider, - }, - binomial: { - n: number_provider, - p: number_provider, - }, - score: { - target: score_provider, - score: literal('objective'), - scale: opt(float), - }, - }), - })), - ]), -) - -export const score_provider = any([ - literal(['this', 'killer', 'player_killer', 'direct_killer']), - dispatch('type', (type) => - record({ - type: resource('loot_score_provider_type'), - ...pick(type, { - context: { - target: literal([ - 'this', - 'killer', - 'player_killer', - 'direct_killer', - ]), - }, - fixed: { - name: simpleString, // TODO: score holder, no selector - }, - }), - })), -]) - -export const nbt_provider = any([ - literal(['this', 'killer', 'killer_player', 'block_entity']), - dispatch('type', (type) => - record({ - type: resource('loot_nbt_provider_type'), - ...pick(type, { - context: { - target: literal([ - 'this', - 'killer', - 'killer_player', - 'block_entity', - ]), - }, - storage: { - source: resource('storage'), - }, - }), - })), -]) - -export const int_bounds = as( - 'bounds', - any([ - int, - any([ - record({ - min: int, - max: opt(int), - }), - record({ - min: opt(int), - max: int, - }), - ]), - ]), -) - -export const float_bounds = as( - 'bounds', - any([ - float, - any([ - record({ - min: float, - max: opt(float), - }), - record({ - min: opt(float), - max: float, - }), - ]), - ]), -) - -export const block_state = as( - 'block_state', - dispatch((props) => - record({ - Name: resource('block'), - Properties: opt( - blockStateMap({ - id: extract('Name', props), - requireAll: true, - }), - ), - }) - ), -) - -export const fluid_state = as( - 'fluid_state', - dispatch((props) => - record({ - Name: resource('fluid'), - Properties: opt( - blockStateMap({ - id: extract('Name', props), - category: 'fluid', - requireAll: true, - }), - ), - }) - ), -) - -export const vertical_anchor = as( - 'vertical_anchor', - any([ - record({ - absolute: intRange(MIN_Y, MAX_Y), - }), - record({ - above_bottom: intRange(MIN_Y, MAX_Y), - }), - record({ - below_top: intRange(MIN_Y, MAX_Y), - }), - ]), -) - -export const height_provider = as( - 'height_provider', - any([ - vertical_anchor, - dispatch('type', (type) => - record({ - type: resource('height_provider_type'), - ...pick(type, { - constant: { - value: vertical_anchor, - }, - uniform: { - min_inclusive: vertical_anchor, - max_inclusive: vertical_anchor, - }, - biased_to_bottom: { - min_inclusive: vertical_anchor, - max_inclusive: vertical_anchor, - inner: opt(intRange(1, undefined), 1), - }, - very_biased_to_bottom: { - min_inclusive: vertical_anchor, - max_inclusive: vertical_anchor, - inner: opt(intRange(1, undefined), 1), - }, - trapezoid: { - min_inclusive: vertical_anchor, - max_inclusive: vertical_anchor, - plateau: opt(int, 0), - }, - weighted_list: { - distribution: listOf( - record({ - data: ref(() => height_provider), - weight: int, - }), - ), - }, - }), - })), - ]), -) - -export const floatProvider = ( - min: number | undefined = undefined, - max: number | undefined = undefined, -) => - as( - 'float_provider', - any([ - floatRange(min, max), - dispatch('type', (type) => - record({ - type: resource('float_provider_type'), - ...pick(type, { - constant: { - value: floatRange(min, max), - }, - uniform: { - value: record({ - min_inclusive: floatRange(min, max), - max_exclusive: floatRange(min, max), - }), - }, - clamped_normal: { - value: record({ - mean: float, - deviation: float, - min: floatRange(min, max), - max: floatRange(min, max), - }), - }, - trapezoid: { - value: record({ - min: floatRange(min, max), - max: floatRange(min, max), - plateau: float, - }), - }, - }), - })), - ]), - ) - -export const intProvider = ( - min: number | undefined = undefined, - max: number | undefined = undefined, -): JsonChecker => - as( - 'int_provider', - any([ - intRange(min, max), - dispatch('type', (type) => - record({ - type: resource('int_provider_type'), - ...pick(type, { - constant: { - value: intRange(min, max), - }, - uniform: { - value: record({ - min_inclusive: intRange(min, max), - max_inclusive: intRange(min, max), - }), - }, - biased_to_bottom: { - value: record({ - min_inclusive: intRange(min, max), - max_inclusive: intRange(min, max), - }), - }, - clamped: { - value: record({ - min_inclusive: intRange(min, max), - max_inclusive: intRange(min, max), - source: ref(() => intProvider()), - }), - }, - clamped_normal: { - value: record({ - mean: float, - deviation: float, - min_inclusive: intRange(min, max), - max_inclusive: intRange(min, max), - }), - }, - weighted_list: { - distribution: listOf( - record({ - data: ref(() => intProvider()), - weight: int, - }), - ), - }, - }), - })), - ]), - ) - -// until 1.16 -export const uniformInt = ( - min?: number, - max?: number, - maxSpread?: number, -): JsonChecker => - as( - 'uniform_int', - any([ - intRange(min, max), - record({ - base: intRange(min, max), - spread: intRange(0, maxSpread), - }), - ]), - ) - -export const inclusiveRange = ( - min?: number | undefined, - max?: number | undefined, -) => - as( - 'inclusive_range', - any([ - record({ - min_inclusive: intRange(min, max), - max_inclusive: intRange(min, max), - }), - listOf(intRange(min, max)), - ]), - ) - -export const noise_parameters = record({ - firstOctave: int, - amplitudes: listOf(float), -}) - -export const HeightmapType = [ - 'MOTION_BLOCKING', - 'MOTION_BLOCKING_NO_LEAVES', - 'OCEAN_FLOOR', - 'OCEAN_FLOOR_WG', - 'WORLD_SURFACE', - 'WORLD_SURFACE_WG', -] - -export const Slots = ['mainhand', 'offhand', 'head', 'chest', 'legs', 'feet'] - -export const Direction = ['up', 'down', 'north', 'east', 'south', 'west'] diff --git a/packages/java-edition/src/json/checker/data/dimension.ts b/packages/java-edition/src/json/checker/data/dimension.ts deleted file mode 100644 index 3716ad9b8..000000000 --- a/packages/java-edition/src/json/checker/data/dimension.ts +++ /dev/null @@ -1,327 +0,0 @@ -import { - any, - as, - boolean, - dispatch, - float, - floatRange, - int, - intRange, - listOf, - literal, - object, - opt, - pick, - record, - ref, - resource, - simpleString, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { versioned } from '../util/index.js' -import { block_state, noise_parameters, vertical_anchor } from './common.js' - -const material_condition = as( - 'material_condition', - dispatch('type', (type) => - record({ - type: resource('worldgen/material_condition'), - ...pick(type, { - biome: { - biome_is: listOf(resource('worldgen/biome')), - }, - noise_threshold: { - noise: resource('worldgen/noise'), - min_threshold: float, - max_threshold: float, - }, - not: { - invert: material_condition, - }, - stone_depth: { - offset: int, - surface_type: literal(['floor', 'ceiling']), - add_surface_depth: boolean, - add_surface_secondary_depth: boolean, - }, - vertical_gradient: { - random_name: simpleString, - true_at_and_below: vertical_anchor, - false_at_and_above: vertical_anchor, - }, - water: { - offset: int, - surface_depth_multiplier: intRange(-20, 20), - add_stone_depth: boolean, - }, - y_above: { - anchor: vertical_anchor, - surface_depth_multiplier: intRange(-20, 20), - add_stone_depth: boolean, - }, - }), - })), -) - -const material_rule = as( - 'material_rule', - dispatch('type', (type) => - record({ - type: resource('worldgen/material_rule'), - ...pick(type, { - block: { - result_state: block_state, - }, - condition: { - if_true: material_condition, - then_run: material_rule, - }, - sequence: { - sequence: listOf(material_rule), - }, - }), - })), -) - -const terrain_spline = as( - 'terrain_spline', - any([ - float, - record({ - coordinate: literal(['continents', 'erosion', 'weirdness', 'ridges']), - points: listOf( - record({ - location: float, - value: ref(() => terrain_spline), - derivative: float, - }), - ), - }), - ]), -) - -const structure_settings = as( - 'structure_settings', - record({ - stronghold: opt( - record({ - distance: intRange(0, 1023), - spread: intRange(0, 1023), - count: intRange(1, 4095), - }), - ), - structures: object(resource('worldgen/structure_feature'), () => - record({ - spacing: intRange(0, 4096), - separation: intRange(0, 4096), // TODO: validate separation < spacing - salt: intRange(0, undefined), - })), - }), -) - -const noise_slide_settings = dispatch((_, ctx) => - record({ - target: float, - size: versioned(ctx, int, '1.17', intRange(0, undefined)), - offset: int, - }) -) - -export const noise_settings = as( - 'noise_settings', - dispatch((_, ctx) => - record({ - bedrock_roof_position: versioned(ctx, int, '1.18'), - bedrock_floor_position: versioned(ctx, int, '1.18'), - sea_level: int, - min_surface_level: versioned(ctx, '1.17', versioned(ctx, int, '1.18')), - disable_mob_generation: boolean, - ...versioned(ctx, '1.17', { - noise_caves_enabled: boolean, - noodle_caves_enabled: boolean, - aquifers_enabled: boolean, - deepslate_enabled: versioned(ctx, boolean, '1.18'), - ore_veins_enabled: boolean, - }), - legacy_random_source: versioned(ctx, '1.18', boolean), - default_block: block_state, - default_fluid: block_state, - noise: record({ - min_y: versioned(ctx, '1.17', intRange(-2048, 2047)), // TODO: validate - height: intRange(0, 4096), - size_horizontal: intRange(1, 4), - size_vertical: intRange(1, 4), - density_factor: versioned(ctx, float, '1.18'), - density_offset: versioned(ctx, float, '1.18'), - simplex_surface_noise: versioned(ctx, boolean, '1.18'), - random_density_offset: opt(versioned(ctx, boolean, '1.18'), false), - island_noise_override: opt(boolean, false), - amplified: opt(boolean, false), - large_biomes: opt(versioned(ctx, '1.18', boolean), false), - sampling: record({ - xz_scale: floatRange(0.001, 1000), - y_scale: floatRange(0.001, 1000), - xz_factor: floatRange(0.001, 1000), - y_factor: floatRange(0.001, 1000), - }), - top_slide: noise_slide_settings, - bottom_slide: noise_slide_settings, - terrain_shaper: versioned( - ctx, - '1.18', - record({ - offset: terrain_spline, - factor: terrain_spline, - jaggedness: terrain_spline, - }), - ), - }), - surface_rule: versioned(ctx, '1.18', material_rule), - structures: structure_settings, - }) - ), -) - -const climate_parameter = any([floatRange(-2, 2), listOf(floatRange(-2, 2))]) - -const biome_source = as( - 'biome_source', - dispatch('type', (type, _, ctx) => - record({ - type: resource('worldgen/biome_source'), - ...pick(type, { - checkerboard: { - scale: opt(intRange(0, 62), 2), - biomes: listOf(resource('worldgen/biome')), - }, - fixed: { - biome: resource('worldgen/biome'), - }, - multi_noise: { - seed: versioned(ctx, int, '1.18'), - preset: opt( - versioned( - ctx, - literal(['nether']), - '1.18', - resource(['minecraft:overworld', 'minecraft:nether']), - ), - ), - ...versioned( - ctx, - { - altitude_noise: noise_parameters, - temperature_noise: noise_parameters, - humidity_noise: noise_parameters, - weirdness_noise: noise_parameters, - }, - '1.18', - ), - biomes: listOf( - record({ - biome: resource('worldgen/biome'), - parameters: record( - versioned( - ctx, - { - altitude: float, - temperature: float, - humidity: float, - weirdness: float, - offset: float, - }, - '1.18', - { - temperature: climate_parameter, - humidity: climate_parameter, - continentalness: climate_parameter, - erosion: climate_parameter, - weirdness: climate_parameter, - depth: climate_parameter, - offset: floatRange(0, 1), - }, - ), - ), - }), - ), - }, - the_end: { - seed: int, - }, - vanilla_layered: { - seed: int, - large_biomes: opt(boolean, false), - legacy_biome_init_layer: opt(boolean, false), - }, - }), - })), -) - -export const dimension_type = as( - 'dimension_type', - dispatch((_, ctx) => - record({ - min_y: versioned(ctx, '1.17', intRange(-2048, 2047)), // TODO: validate - height: versioned(ctx, '1.17', intRange(0, 4096)), - logical_height: versioned( - ctx, - intRange(0, 256), - '1.17', - intRange(0, 4096), - ), - coordinate_scale: floatRange(0.00001, 30000000), - ambient_light: float, - fixed_time: opt(int), - infiniburn: resource('tag/block'), - effects: opt( - resource(['overworld', 'the_nether', 'the_end']), - 'overworld', - ), - ultrawarm: boolean, - natural: boolean, - piglin_safe: boolean, - respawn_anchor_works: boolean, - bed_works: boolean, - has_raids: boolean, - has_skylight: boolean, - has_ceiling: boolean, - }) - ), -) - -export const dimension = as( - 'dimension', - record({ - type: any([resource('dimension_type'), dimension_type]), - generator: as( - 'chunk_generator', - dispatch('type', (type) => - record({ - type: resource('worldgen/chunk_generator'), - ...pick(type, { - flat: { - settings: record({ - layers: listOf( - record({ - block: resource('block'), - height: intRange(0, 4096), - }), - ), - biome: resource('worldgen/biome'), - lakes: opt(boolean, false), - features: opt(boolean, false), - structures: structure_settings, - }), - }, - noise: { - seed: int, - settings: any([ - resource('worldgen/noise_settings'), - noise_settings, - ]), - biome_source: biome_source, - }, - }), - })), - ), - }), -) diff --git a/packages/java-edition/src/json/checker/data/feature.ts b/packages/java-edition/src/json/checker/data/feature.ts deleted file mode 100644 index f7bf4181d..000000000 --- a/packages/java-edition/src/json/checker/data/feature.ts +++ /dev/null @@ -1,1043 +0,0 @@ -import type { Symbol } from '@spyglassmc/core' -import type { JsonNode } from '@spyglassmc/json' -import { JsonArrayNode, JsonObjectNode } from '@spyglassmc/json' -import type { JsonCheckerContext } from '@spyglassmc/json/lib/checker/index.js' -import { - any, - as, - boolean, - dispatch, - extract, - float, - floatRange, - int, - intRange, - listOf, - literal, - opt, - pick, - record, - ref, - resource, - simpleString, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { renamed, versioned } from '../util/index.js' -import { - block_state, - Direction, - floatProvider, - fluid_state, - height_provider, - HeightmapType, - inclusiveRange, - intProvider, - noise_parameters, - uniformInt, - Y_SIZE, -} from './common.js' -import { processor_list_ref, rule_test } from './structure.js' - -function intersection(...values: string[][]) { - return [ - ...new Set( - ([] as string[]) - .concat(...values) - .filter((e) => values.every((a) => a.includes(e))), - ), - ] -} - -function blockStateIntProperties( - node: JsonNode | undefined, - ctx: JsonCheckerContext, -): string[] { - if (node && JsonObjectNode.is(node)) { - let block = extract('Name', node.children) - if (block) { - if (!block.startsWith('minecraft:')) { - block = `minecraft:${block}` - } - return Object.values( - ctx.symbols.query(ctx.doc, 'block', block).symbol?.members ?? {}, - ) - .filter((m): m is Symbol => m?.subcategory === 'state') - .filter((m) => Object.keys(m.members ?? {})[0]?.match(/^\d+$/)) - .map((m) => m.identifier) - } - } else if (node && JsonArrayNode.is(node)) { - const values = node.children - .map((item) => item.value) - .filter((n) => n) - .map((n) => blockStateIntProperties(n as JsonNode, ctx)) - return intersection(...values) - } - return [] -} - -function blockProviderProperties( - node: JsonNode | undefined, - ctx: JsonCheckerContext, -): string[] { - if (!node || !JsonObjectNode.is(node)) return [] - switch (extract('type', node.children)?.replace(/^minecraft:/, '')) { - case 'dual_noise_provider': - case 'noise_provider': - const states = node.children.find((p) => p.key?.value === 'states') - ?.value - return blockStateIntProperties(states, ctx) - case 'noise_threshold': - const lowStates = node.children.find( - (p) => p.key?.value === 'low_states', - )?.value - const highStates = node.children.find( - (p) => p.key?.value === 'high_states', - )?.value - return intersection( - blockStateIntProperties(lowStates, ctx), - blockStateIntProperties(highStates, ctx), - ) - case 'randomized_int_state_provider': - const source = node.children.find((p) => p.key?.value === 'source') - ?.value - return blockProviderProperties(source, ctx) - case 'rotated_block_provider': - case 'simple_state_provider': - const state = node.children.find((p) => p.key?.value === 'state') - ?.value - return blockStateIntProperties(state, ctx) - case 'weighted_state_provider': - const entries = node.children.find( - (p) => p.key?.value === 'entries', - )?.value - if (entries && JsonArrayNode.is(entries)) { - const values = entries.children - .map( - (n) => - n.value && - JsonObjectNode.is(n.value) && - n.value.children.find((p) => p.key?.value === 'data') - ?.value, - ) - .filter((n) => n) - .map((n) => blockStateIntProperties(n as JsonNode, ctx)) - return intersection(...values) - } - } - return [] -} - -const noiseProvider = { - seed: int, - noise: noise_parameters, - scale: floatRange(0, undefined), // TODO: disallow 0 -} - -const block_state_provider = as( - 'block_state_provider', - dispatch('type', (type, props, ctx) => - record({ - type: resource('worldgen/block_state_provider_type'), - ...pick(type, { - dual_noise_provider: { - ...noiseProvider, - variety: inclusiveRange(1, 64), - slow_noise: noise_parameters, - slow_scale: floatRange(0, undefined), // TODO: disallow 0 - states: listOf(block_state), - }, - noise_threshold_provider: { - ...noiseProvider, - threshold: floatRange(-1, 1), - high_chance: floatRange(0, 1), - default_state: block_state, - low_states: listOf(block_state), - high_states: listOf(block_state), - }, - noise_provider: { - ...noiseProvider, - states: listOf(block_state), - }, - randomized_int_state_provider: { - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - property: (ctx.ensureBindingStarted as Function | undefined) - ? literal( - blockProviderProperties( - props.find((p) => p.key?.value === 'source')?.value, - ctx, - ), - ) - : simpleString, - values: intProvider(), - source: block_state_provider, - }, - rotated_block_provider: { - state: block_state, - }, - simple_state_provider: { - state: block_state, - }, - weighted_state_provider: { - entries: listOf( - record({ - weight: intRange(1, undefined), - data: block_state, - }), - ), - }, - }), - })), -) - -const blockPredicateOffset = { - offset: opt(listOf(intRange(-16, 16))), -} - -const block_predicate_worldgen = as( - 'block_predicate_worldgen', - dispatch('type', (type) => - record({ - type: resource('block_predicate_type'), - ...pick(type, { - all_of: { - predicates: listOf(block_predicate_worldgen), - }, - any_of: { - predicates: listOf(block_predicate_worldgen), - }, - has_sturdy_face: { - ...blockPredicateOffset, - direction: literal(Direction), - }, - inside_world_bounds: { - ...blockPredicateOffset, - }, - matching_block_tag: { - ...blockPredicateOffset, - tag: resource('tag/block'), - }, - matching_blocks: { - ...blockPredicateOffset, - blocks: listOf(resource('block')), - }, - matching_fluids: { - ...blockPredicateOffset, - fluids: listOf(resource('fluid')), - }, - not: { - predicate: block_predicate_worldgen, - }, - would_survive: { - ...blockPredicateOffset, - state: block_state, - }, - }), - })), -) - -const block_placer = as( - 'block_placer', - dispatch('type', (type, _, ctx) => - record({ - type: resource('worldgen/block_placer_type'), - ...pick(type, { - column_placer: { - ...versioned( - ctx, - { - min_size: int, - extra_size: int, - }, - '1.17', - { - size: intProvider(0, undefined), - }, - ), - }, - }), - })), -) - -const feature_size = as( - 'feature_size', - dispatch('type', (type) => - record({ - type: resource('worldgen/feature_size_type'), - min_clipped_height: opt(intRange(0, 80)), - ...pick(type, { - two_layers_feature_size: { - limit: opt(intRange(0, 81), 1), - lower_size: opt(intRange(0, 16), 0), - upper_size: opt(intRange(0, 16), 1), - }, - three_layers_feature_size: { - limit: opt(intRange(0, 81), 1), - upper_limit: opt(intRange(0, 80), 1), - lower_size: opt(intRange(0, 16), 0), - middle_size: opt(intRange(0, 16), 1), - upper_size: opt(intRange(0, 16), 1), - }, - }), - })), -) - -const trunk_placer = as( - 'trunk_placer', - dispatch('type', (type) => - record({ - type: resource('worldgen/trunk_placer_type'), - base_height: intRange(0, 32), - height_rand_a: intRange(0, 24), - height_rand_b: intRange(0, 24), - ...pick(type, { - bending_trunk_placer: { - bend_length: intProvider(1, 64), - min_height_for_leaves: opt(intRange(1, undefined), 1), - }, - }), - })), -) - -const foliage_placer = as( - 'foliage_placer', - dispatch('type', (type, _, ctx) => - record({ - type: resource('worldgen/foliage_placer_type'), - radius: versioned( - ctx, - uniformInt(0, 8, 8), - '1.17', - intProvider(0, 16), - ), - offset: versioned( - ctx, - uniformInt(0, 8, 8), - '1.17', - intProvider(0, 16), - ), - ...pick(type, { - blob_foliage_placer: { - height: intRange(0, 16), - }, - bush_foliage_placer: { - height: intRange(0, 16), - }, - fancy_foliage_placer: { - height: intRange(0, 16), - }, - jungle_foliage_placer: { - height: intRange(0, 16), - }, - mega_pine_foliage_placer: { - crown_height: versioned( - ctx, - uniformInt(0, 16, 8), - '1.17', - intProvider(0, 24), - ), - }, - pine_foliage_placer: { - height: versioned( - ctx, - uniformInt(0, 16, 8), - '1.17', - intProvider(0, 24), - ), - }, - random_spread_foliage_placer: { - foliage_height: intProvider(1, 512), - leaf_placement_attempts: intRange(0, 256), - }, - spruce_foliage_placer: { - trunk_height: versioned( - ctx, - uniformInt(0, 16, 8), - '1.17', - intProvider(0, 24), - ), - }, - }), - })), -) - -const tree_decorator = as( - 'tree_decorator', - dispatch('type', (type) => - record({ - type: resource('worldgen/tree_decorator_type'), - ...pick(type, { - alter_ground: { - provider: block_state_provider, - }, - beehive: { - probability: floatRange(0, 1), - }, - cocoa: { - probability: floatRange(0, 1), - }, - }), - })), -) - -const DiskConfig = (ctx: JsonCheckerContext) => ({ - state: block_state, - radius: versioned(ctx, uniformInt(0, 4, 4), '1.17', intProvider(0, 8)), - half_height: intRange(0, 4), - targets: listOf(block_state), -}) - -const RandomPatchConfig = (ctx: JsonCheckerContext) => - versioned( - ctx, - { - state_provider: block_state_provider, - block_placer: block_placer, - whitelist: listOf(block_state), - blacklist: listOf(block_state), - ...versioned( - ctx, - { - tries: int, - xspread: int, - yspread: int, - zspread: int, - can_replace: boolean, - project: boolean, - need_water: boolean, - }, - '1.17', - { - tries: opt(intRange(1, undefined), 128), - xspread: opt(intRange(0, undefined), 7), - yspread: opt(intRange(0, undefined), 3), - zspread: opt(intRange(0, undefined), 7), - can_replace: opt(boolean, false), - project: opt(boolean, true), - need_water: opt(boolean, false), - }, - ), - }, - '1.18', - { - tries: opt(intRange(1, undefined), 128), - xz_spread: opt(intRange(0, undefined)), - y_spread: opt(intRange(0, undefined)), - feature: placed_feature_ref, - }, - ) - -const HugeMushroomConfig = { - foliage_radius: opt(int, 2), - cap_provider: block_state_provider, - stem_provider: block_state_provider, -} - -const OreConfig = (ctx: JsonCheckerContext) => ({ - size: intRange(0, 64), - ...versioned( - ctx, - { - state: block_state, - target: rule_test, - }, - '1.17', - { - discard_chance_on_air_exposure: floatRange(0, 1), - targets: listOf( - record({ - state: block_state, - target: rule_test, - }), - ), - }, - ), -}) - -const CountConfig = (ctx: JsonCheckerContext) => ({ - count: versioned( - ctx, - uniformInt(-10, 128, 128), - '1.17', - intProvider(0, 256), - ), -}) - -// until 1.16 -const RangeConfig = { - maximum: int, - bottom_offset: int, - top_offset: int, -} - -const VegetationPatchConfig = (ctx: JsonCheckerContext) => ({ - surface: literal(['floor', 'ceiling']), - depth: intProvider(1, 128), - vertical_range: intRange(1, 256), - extra_bottom_block_chance: floatRange(0, 1), - extra_edge_column_chance: floatRange(0, 1), - vegetation_chance: floatRange(0, 1), - xz_radius: intProvider(), - replaceable: resource('tag/block'), - ground_state: block_state_provider, - vegetation_feature: versioned( - ctx, - ref(() => configured_feature_ref), - '1.18', - ref(() => placed_feature_ref), - ), -}) - -// until 1.17 -export const configured_decorator = as( - 'decorator', - dispatch('type', (type, _, ctx) => - record({ - type: resource('worldgen/decorator'), - config: record( - pick(type, { - carving_mask: { - step: literal(['air', 'liquid']), - probability: versioned(ctx, floatRange(0, 1), '1.16'), - }, - cave_surface: { - surface: literal(['floor', 'ceiling']), - floor_to_ceiling_search_range: int, - }, - chance: { - chance: int, - }, - count: CountConfig(ctx), - count_extra: { - count: int, - extra_chance: float, - extra_count: int, - }, - count_multilayer: CountConfig(ctx), - count_noise: { - noise_level: float, - below_noise: int, - above_noise: int, - }, - count_noise_biased: { - noise_to_count_ratio: int, - noise_factor: float, - noise_offset: opt(float, 0), - }, - decorated: { - outer: configured_decorator, - inner: configured_decorator, - }, - depth_average: { - baseline: int, - spread: int, - }, - fire: CountConfig(ctx), - glowstone: CountConfig(ctx), - heightmap: { - heightmap: versioned(ctx, '1.17', literal(HeightmapType)), - }, - heightmap_spread_double: { - heightmap: versioned(ctx, '1.17', literal(HeightmapType)), - }, - lava_lake: { - chance: int, - }, - range: { - ...versioned(ctx, RangeConfig, '1.17', { - height: height_provider, - }), - }, - range_biased: RangeConfig, - range_very_biased: RangeConfig, - water_depth_threshold: { - max_water_depth: int, - }, - water_lake: { - chance: int, - }, - }), - ), - })), -) - -export const placement_modifier = as( - 'placement_modifier', - dispatch('type', (type) => - record({ - type: resource('worldgen/placement_modifier_type'), - ...pick(type, { - block_predicate_filter: { - predicate: block_predicate_worldgen, - }, - carving_mask: { - step: literal(['air', 'liquid']), - }, - rarity_filter: { - chance: intRange(1, undefined), - }, - count: { - count: intProvider(0, 256), - }, - count_on_every_layer: { - count: intProvider(0, 256), - }, - noise_threshold_count: { - noise_level: float, - below_noise: int, - above_noise: int, - }, - noise_based_count: { - noise_to_count_ratio: int, - noise_factor: float, - noise_offset: opt(float), - }, - environment_scan: { - direction_of_search: literal(['up', 'down']), - max_steps: intRange(1, 32), - target_condition: block_predicate_worldgen, - allowed_search_condition: opt(block_predicate_worldgen), - }, - heightmap: { - heightmap: literal(HeightmapType), - }, - height_range: { - height: height_provider, - }, - random_offset: { - xz_spread: intProvider(-16, 16), - y_spread: intProvider(-16, 16), - }, - surface_relative_threshold_filter: { - heigtmap: literal(HeightmapType), - min_inclusive: opt(int), - max_inclusive: opt(int), - }, - surface_water_depth_filter: { - max_water_depth: int, - }, - }), - })), -) - -export const configured_feature = as( - 'feature', - dispatch('type', (type, _, ctx) => - record({ - type: resource('worldgen/feature'), - config: record( - pick(type, { - bamboo: { - probability: floatRange(0, 1), - }, - basalt_columns: { - reach: versioned( - ctx, - uniformInt(0, 2, 1), - '1.17', - intProvider(0, 3), - ), - height: versioned( - ctx, - uniformInt(1, 5, 5), - '1.17', - intProvider(1, 10), - ), - }, - block_column: { - direction: literal(Direction), - allowed_placement: block_predicate_worldgen, - prioritize_tip: boolean, - layers: listOf( - record({ - height: intProvider(0, undefined), - provider: block_state_provider, - }), - ), - }, - block_pile: { - state_provider: block_state_provider, - }, - decorated: { - decorator: configured_decorator, - feature: configured_feature_ref, - }, - delta_feature: { - contents: block_state, - rim: block_state, - size: versioned( - ctx, - uniformInt(0, 8, 8), - '1.17', - intProvider(0, 16), - ), - rim_size: versioned( - ctx, - uniformInt(0, 8, 8), - '1.17', - intProvider(0, 16), - ), - }, - disk: DiskConfig(ctx), - dripstone_cluster: { - floor_to_ceiling_search_range: intRange(1, 512), - height: intProvider(0, 128), - radius: intProvider(0, 128), - max_stalagmite_stalactite_height_diff: intRange(0, 64), - height_deviation: intRange(0, 64), - dripstone_block_layer_thickness: intProvider(0, 128), - density: floatProvider(0, 2), - wetness: floatProvider(0, 2), - chance_of_dripstone_column_at_max_distance_from_center: - floatRange( - 0, - 1, - ), - max_distance_from_edge_affecting_chance_of_dripstone_column: - intRange(1, 64), - max_distance_from_center_affecting_height_bias: intRange( - 1, - 64, - ), - }, - emerald_ore: { - state: block_state, - target: block_state, - }, - end_gateway: { - exit: opt(listOf(int)), - exact: boolean, - }, - end_spike: { - crystal_invulnerable: opt(boolean, false), - crystal_beam_target: opt(listOf(int)), - spikes: listOf( - record({ - centerX: opt(int, 0), - centerZ: opt(int, 0), - radius: opt(int, 0), - height: opt(int, 0), - guarded: opt(boolean, false), - }), - ), - }, - fill_layer: { - height: intRange(0, Y_SIZE), - state: block_state, - }, - flower: RandomPatchConfig(ctx), - forest_rock: { - state: block_state, - }, - fossil: { - max_empty_corners_allowed: intRange(0, 7), - fossil_structures: listOf(resource('structure')), - overlay_structures: listOf(resource('structure')), - fossil_processors: processor_list_ref, - overlay_processors: processor_list_ref, - }, - geode: { - blocks: record({ - filling_provider: block_state_provider, - inner_layer_provider: block_state_provider, - alternate_inner_layer_provider: block_state_provider, - middle_layer_provider: block_state_provider, - outer_layer_provider: block_state_provider, - inner_placements: listOf(block_state), - cannot_replace: resource('tag/block'), - invalid_blocks: resource('tag/block'), - }), - layers: record({ - filling: opt(floatRange(0.01, 50), 1.7), - inner_layer: opt(floatRange(0.01, 50), 2.2), - middle_layer: opt(floatRange(0.01, 50), 3.2), - outer_layer: opt(floatRange(0.01, 50), 4.2), - }), - crack: record({ - generate_crack_chance: opt(floatRange(0, 1), 1), - base_crack_size: opt(floatRange(0, 5), 2), - crack_point_offset: opt(intRange(0, 10), 2), - }), - noise_multiplier: opt(floatRange(0, 1), 0.05), - use_potential_placements_chance: opt(floatRange(0, 1), 0.35), - use_alternate_layer0_chance: opt(floatRange(0, 1), 0), - placements_require_layer0_alternate: opt(boolean, true), - outer_wall_distance: opt(intProvider(0, 10), { - value: { min_inclusive: 0, max_inclusive: 10 }, - }), - distribution_points: opt(intProvider(1, 20), { - value: { min_inclusive: 3, max_inclusive: 4 }, - }), - point_offset: opt(intProvider(0, 10), { - value: { min_inclusive: 1, max_inclusive: 2 }, - }), - min_gen_offset: opt(int, -16), - max_gen_offset: opt(int, 16), - invalid_blocks_threshold: int, - }, - glow_lichen: { - search_range: opt(intRange(1, 64), 10), - chance_of_spreading: opt(floatRange(0, 1), 0.5), - can_place_on_floor: opt(boolean, false), - can_place_on_wall: opt(boolean, false), - can_place_on_ceiling: opt(boolean, false), - can_be_placed_on: listOf( - versioned(ctx, block_state, '1.18', resource('block')), - ), - }, - growing_plant: { - direction: literal(Direction), - allow_water: boolean, - height_distribution: listOf( - record({ - weight: int, - data: intProvider(), - }), - ), - body_provider: block_state_provider, - head_provider: block_state_provider, - }, - huge_brown_mushroom: HugeMushroomConfig, - huge_fungus: { - planted: opt(boolean, false), - hat_state: block_state, - decor_state: block_state, - stem_state: block_state, - valid_base_block: block_state, - }, - huge_red_mushroom: HugeMushroomConfig, - ice_patch: DiskConfig(ctx), - iceberg: { - state: block_state, - }, - lake: versioned( - ctx, - { - state: block_state, - }, - '1.18', - { - fluid: block_state_provider, - barrier: block_state_provider, - }, - ), - large_dripstone: { - floor_to_ceiling_search_range: opt(intRange(1, 512), 30), - column_radius: intProvider(0, 20), - height_scale: floatProvider(0, 20), - max_column_radius_to_cave_height_ratio: floatRange(0, 1), - stalactite_bluntness: floatProvider(0.1, 10), - stalagmite_bluntness: floatProvider(0.1, 10), - wind_speed: floatProvider(0, 2), - min_radius_for_wind: intRange(0, 100), - min_bluntness_for_wind: floatRange(0, 5), - }, - nether_forest_vegetation: { - state_provider: block_state_provider, - ...versioned(ctx, '1.18', { - spread_width: intRange(1, undefined), - spread_height: intProvider(1, undefined), - }), - }, - netherrack_replace_blobs: { - radius: versioned( - ctx, - uniformInt(), - '1.17', - intProvider(0, 12), - ), - state: block_state, - target: block_state, - }, - no_bonemeal_flower: RandomPatchConfig(ctx), - no_surface_ore: OreConfig(ctx), - ore: OreConfig(ctx), - pointed_dripstone: { - chance_of_taller_dripstone: floatRange(0, 1), - chance_of_directional_spread: floatRange(0, 1), - chance_of_spread_radius2: floatRange(0, 1), - chance_of_spread_radius3: floatRange(0, 1), - }, - random_boolean_selector: { - feature_false: versioned( - ctx, - configured_feature_ref, - '1.18', - placed_feature_ref, - ), - feature_true: versioned( - ctx, - configured_feature_ref, - '1.18', - placed_feature_ref, - ), - }, - random_patch: RandomPatchConfig(ctx), - random_selector: { - features: listOf( - record({ - chance: floatRange(0, 1), - feature: versioned( - ctx, - configured_feature_ref, - '1.18', - placed_feature_ref, - ), - }), - ), - default: versioned( - ctx, - configured_feature_ref, - '1.18', - placed_feature_ref, - ), - }, - replace_single_block: { - targets: listOf( - record({ - state: block_state, - target: rule_test, - }), - ), - }, - root_system: { - required_vertical_space_for_tree: intRange(1, 64), - root_radius: intRange(1, 64), - root_placement_attempts: intRange(1, 256), - root_column_max_height: intRange(1, 4096), - hanging_root_radius: intRange(1, 64), - hanging_roots_vertical_span: intRange(0, 16), - hanging_root_placement_attempts: intRange(0, 256), - allowed_vertical_water_for_tree: intRange(1, 64), - root_replaceable: resource('tag/block'), - root_state_provider: block_state_provider, - hanging_root_state_provider: block_state_provider, - allowed_tree_position: versioned( - ctx, - '1.18', - block_predicate_worldgen, - ), - feature: versioned( - ctx, - configured_feature_ref, - '1.18', - placed_feature_ref, - ), - }, - scattered_ore: OreConfig(ctx), - sea_pickle: CountConfig(ctx), - seagrass: { - probability: floatRange(0, 1), - }, - simple_block: { - ...versioned( - ctx, - versioned( - ctx, - { - to_place: block_state, - place_on: listOf(block_state), - place_in: listOf(block_state), - place_under: listOf(block_state), - }, - '1.17', - { - to_place: block_state_provider, - place_on: opt(listOf(block_state), []), - place_in: opt(listOf(block_state), []), - place_under: opt(listOf(block_state), []), - }, - ), - '1.18', - { - to_place: block_state_provider, - }, - ), - }, - simple_random_selector: { - features: versioned( - ctx, - configured_feature_list_ref, - '1.18', - placed_feature_list_ref, - ), - }, - small_dripstone: { - max_placements: opt(intRange(0, 100), 5), - empty_space_search_radius: opt(intRange(0, 20), 10), - max_offset_from_origin: opt(intRange(0, 20), 2), - chance_of_taller_dripstone: opt(floatRange(0, 1), 0.2), - }, - spring_feature: { - requires_block_below: opt(boolean, true), - rock_count: opt(int, 4), - hole_count: opt(int, 1), - state: fluid_state, - valid_blocks: listOf(resource('block')), - }, - tree: { - ignore_vines: opt(boolean, false), - force_dirt: opt(versioned(ctx, '1.17', boolean), false), - max_water_depth: versioned(ctx, int, '1.17'), - heightmap: versioned(ctx, literal(HeightmapType), '1.17'), - minimum_size: feature_size, - dirt_provider: versioned(ctx, '1.17', block_state_provider), - sapling_provider: versioned( - ctx, - '1.17', - versioned(ctx, block_state_provider, '1.18'), - ), - trunk_provider: block_state_provider, - ...renamed( - ctx, - 'leaves_provider', - '1.17', - 'foliage_provider', - block_state_provider, - ), - trunk_placer: trunk_placer, - foliage_placer: foliage_placer, - decorators: listOf(tree_decorator), - }, - twisting_vines: versioned(ctx, {}, '1.18', { - spread_width: intRange(1, undefined), - spread_height: intRange(1, undefined), - max_height: intRange(1, undefined), - }), - underwater_magma: { - floor_search_range: intRange(0, 512), - placement_radius_around_floor: intRange(0, 64), - placement_probability_per_valid_position: floatRange(0, 1), - }, - vegetation_patch: VegetationPatchConfig(ctx), - waterlogged_vegetation_patch: VegetationPatchConfig(ctx), - }), - ), - })), -) - -export const configured_feature_ref = any([ - resource('worldgen/configured_feature'), - configured_feature, -]) - -export const configured_feature_list_ref = any([ - listOf(resource('worldgen/configured_feature')), - listOf(configured_feature), -]) - -export const placed_feature = as( - 'placed_feature', - record({ - feature: configured_feature_ref, - placement: listOf(placement_modifier), - }), -) - -export const placed_feature_ref = any([ - resource('worldgen/placed_feature'), - placed_feature, -]) - -export const placed_feature_list_ref = any([ - listOf(resource('worldgen/placed_feature')), - listOf(placed_feature), -]) diff --git a/packages/java-edition/src/json/checker/data/index.ts b/packages/java-edition/src/json/checker/data/index.ts deleted file mode 100644 index 8102e7f1d..000000000 --- a/packages/java-edition/src/json/checker/data/index.ts +++ /dev/null @@ -1,64 +0,0 @@ -import type { FileCategory } from '@spyglassmc/core' -import { as, int, record } from '@spyglassmc/json/lib/checker/index.js' -import type { JsonChecker } from '@spyglassmc/json/lib/checker/JsonChecker.js' -import { advancement } from './advancement.js' -import { - biome, - configured_carver, - configured_surface_builder, -} from './biome.js' -import { dimension, dimension_type, noise_settings } from './dimension.js' -import { configured_feature } from './feature.js' -import { item_modifier_list, loot_table, predicate_list } from './loot_table.js' -import { recipe } from './recipe.js' -import { - configured_structure_feature, - processor_list, - template_pool, -} from './structure.js' -import { - block_tag, - entity_type_tag, - fluid_tag, - function_tag, - game_event_tag, - item_tag, -} from './tag.js' -import { text_component } from './text_component.js' - -export const pack_mcmeta = as( - 'pack', - record( - { - pack: record({ - pack_format: int, - description: text_component, - }), - }, - { allowUnknownProperties: true }, - ), -) - -export const Checkers = new Map([ - ['advancement', advancement], - ['dimension', dimension], - ['dimension_type', dimension_type], - ['item_modifier', item_modifier_list], - ['loot_table', loot_table], - ['predicate', predicate_list], - ['recipe', recipe], - ['tag/block', block_tag], - ['tag/entity_type', entity_type_tag], - ['tag/fluid', fluid_tag], - ['tag/function', function_tag], - ['tag/game_event', game_event_tag], - ['tag/item', item_tag], - ['worldgen/biome', biome], - ['worldgen/configured_carver', configured_carver], - ['worldgen/configured_surface_builder', configured_surface_builder], - ['worldgen/configured_feature', configured_feature], - ['worldgen/configured_structure_feature', configured_structure_feature], - ['worldgen/noise_settings', noise_settings], - ['worldgen/processor_list', processor_list], - ['worldgen/template_pool', template_pool], -]) diff --git a/packages/java-edition/src/json/checker/data/loot_table.ts b/packages/java-edition/src/json/checker/data/loot_table.ts deleted file mode 100644 index d098497c8..000000000 --- a/packages/java-edition/src/json/checker/data/loot_table.ts +++ /dev/null @@ -1,367 +0,0 @@ -import { - any, - as, - boolean, - dispatch, - extract, - float, - floatRange, - int, - intRange, - listOf, - literal, - object, - opt, - pick, - record, - resource, - simpleString, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { - blockStateList, - blockStateMap, - nbt, - nbtPath, - uuid, - versioned, -} from '../util/index.js' -import { - damage_source_predicate, - entity_predicate, - item_predicate, - location_predicate, -} from './advancement.js' -import { int_bounds, nbt_provider, number_provider, Slots } from './common.js' -import { text_component } from './text_component.js' - -const loot_context_types = [ - 'empty', - 'chest', - 'command', - 'selector', - 'fishing', - 'entity', - 'gift', - 'barter', - 'advancement_reward', - 'advancement_entity', - 'generic', - 'block', -] - -const map_decorations = [ - 'mansion', - 'monument', - 'player', - 'frame', - 'red_marker', - 'blue_marker', - 'target_x', - 'target_point', - 'player_off_map', - 'player_off_limits', - 'red_x', - 'banner_white', - 'banner_orange', - 'banner_magenta', - 'banner_light_blue', - 'banner_yellow', - 'banner_lime', - 'banner_pink', - 'banner_gray', - 'banner_light_gray', - 'banner_cyan', - 'banner_purple', - 'banner_blue', - 'banner_brown', - 'banner_green', - 'banner_red', - 'banner_black', -] - -export const predicate = as( - 'predicate', - dispatch('condition', (condition, props) => - record({ - condition: resource('loot_condition_type'), - ...pick(condition, { - alternative: { - terms: listOf(predicate), - }, - block_state_property: { - block: resource('block'), - properties: blockStateMap({ id: extract('block', props) }), - }, - damage_source_properties: { - predicate: damage_source_predicate, - }, - entity_properties: { - entity: literal([ - 'this', - 'killer', - 'killer_player', - 'direct_killer', - ]), - predicate: entity_predicate, - }, - entity_scores: { - entity: literal([ - 'this', - 'killer', - 'killer_player', - 'direct_killer', - ]), - scores: object(literal('objective'), () => int_bounds), - }, - inverted: { - term: predicate, - }, - killed_by_player: { - inverse: opt(boolean, false), - }, - location_check: { - offsetX: opt(int, 0), - offsetY: opt(int, 0), - offsetZ: opt(int, 0), - predicate: location_predicate, - }, - match_tool: { - predicate: item_predicate, - }, - random_chance: { - chance: floatRange(0, 1), - }, - random_chance_with_looting: { - chance: floatRange(0, 1), - looting_multiplier: float, - }, - reference: { - name: resource('predicate'), - }, - table_bonus: { - enchantment: resource('enchantment'), - chances: listOf(floatRange(0, 1)), - }, - time_check: { - value: int_bounds, - period: opt(int), - }, - value_check: { - value: number_provider, - range: int_bounds, - }, - weather_check: { - raining: opt(boolean), - thundering: opt(boolean), - }, - }), - })), -) - -export const predicate_list = any([predicate, listOf(predicate)]) - -export const item_modifier = as( - 'item_modifier', - dispatch('function', (function_, props, ctx) => - record({ - function: resource('loot_function_type'), - ...pick(function_, { - apply_bonus: { - enchantment: resource('enchantment'), - formula: resource([ - 'binomial_with_bonus_count', - 'ore_drops', - 'uniform_bonus_count', - ]), - ...pick(extract('formula', props), { - binomial_with_bonus_count: { - parameters: record({ - extra: float, - probability: floatRange(0, 1), - }), - }, - uniform_bonus_count: { - parameters: record({ - bonusMultiplier: float, - }), - }, - }), - }, - copy_name: { - source: literal([ - 'this', - 'killer', - 'killer_player', - 'block_entity', - ]), - }, - copy_nbt: { - source: nbt_provider, - ops: listOf( - record({ - source: nbtPath({ registry: 'entity_type' }), // FIXME: Use 'block' instead if `source` is `block_entity`; use 'storage' if `source` is `storage`. - target: nbtPath({ registry: 'item' }), - op: literal(['replace', 'append', 'merge']), - }), - ), - }, - copy_state: { - block: resource('block'), - properties: blockStateList({ id: extract('block', props) }), - }, - enchant_randomly: { - enchantments: opt(listOf(resource('enchantment'))), - }, - enchant_with_levels: { - levels: number_provider, - treasure: opt(boolean, false), - }, - exploration_map: { - destination: opt( - resource('worldgen/structure_feature'), - 'buried_treasure', - ), - decoration: opt(literal(map_decorations), 'mansion'), - zoom: opt(int, 2), - search_radius: opt(int, 50), - skip_existing_chunks: opt(boolean, true), - }, - fill_player_head: { - entity: literal([ - 'this', - 'killer', - 'killer_player', - 'direct_killer', - ]), - }, - limit_count: { - limit: int_bounds, - }, - looting_enchant: { - count: number_provider, - limit: opt(int, 0), - }, - set_attributes: { - modifiers: listOf( - record({ - attribute: resource('attribute'), - name: simpleString, - operation: literal([ - 'addition', - 'multiply_base', - 'multiply_total', - ]), - id: opt(uuid), - amount: number_provider, - slot: any([literal(Slots), listOf(literal(Slots))]), - }), - ), - }, - set_contents: { - type: versioned(ctx, '1.18', resource('block_entity_type')), - entries: listOf(loot_entry), - }, - set_count: { - count: number_provider, - add: opt(versioned(ctx, '1.17', boolean), false), - }, - set_damage: { - damage: number_provider, - add: opt(versioned(ctx, '1.17', boolean), false), - }, - set_loot_table: { - name: resource('loot_table'), - seed: opt(int, 0), - }, - set_lore: { - entity: opt( - literal(['this', 'killer', 'killer_player', 'direct_killer']), - ), - lore: listOf(text_component), - replace: opt(boolean, false), - }, - set_name: { - entity: opt( - literal(['this', 'killer', 'killer_player', 'direct_killer']), - ), - name: opt(text_component), - }, - set_nbt: { - tag: nbt({ registry: 'item' }), - }, - set_potion: { - id: resource('potion'), - }, - set_stew_effect: { - effects: opt( - listOf( - record({ - type: resource('mob_effect'), - duration: number_provider, - }), - ), - [], - ), - }, - }), - conditions: opt(listOf(predicate)), - })), -) - -export const item_modifier_list = any([item_modifier, listOf(item_modifier)]) - -export const loot_entry = as( - 'loot_entry', - dispatch('type', (type) => - record({ - type: resource('loot_pool_entry_type'), - weight: opt(intRange(1, undefined), 1), - quality: opt(int, 0), - ...pick(type, { - alternatives: { - children: listOf(loot_entry), - }, - dynamic: { - name: resource(['contents']), - }, - group: { - children: listOf(loot_entry), - }, - item: { - name: resource('item'), - }, - loot_table: { - name: resource('loot_table'), - }, - sequence: { - children: listOf(loot_entry), - }, - tag: { - name: resource('tag/item'), - expand: boolean, - }, - }), - functions: opt(listOf(item_modifier), []), - conditions: opt(listOf(predicate), []), - })), -) - -export const loot_pool = as( - 'loot_pool', - record({ - rolls: number_provider, - bonus_rolls: opt(number_provider, 0), - entries: listOf(loot_entry), - functions: opt(listOf(item_modifier), []), - conditions: opt(listOf(predicate), []), - }), -) - -export const loot_table = as( - 'loot_table', - record({ - type: opt(resource(loot_context_types)), - pools: opt(listOf(loot_pool), []), - functions: opt(listOf(item_modifier), []), - }), -) diff --git a/packages/java-edition/src/json/checker/data/recipe.ts b/packages/java-edition/src/json/checker/data/recipe.ts deleted file mode 100644 index 43edf75bc..000000000 --- a/packages/java-edition/src/json/checker/data/recipe.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { - any, - as, - dispatch, - float, - int, - intRange, - listOf, - object, - opt, - pick, - record, - resource, - simpleString, - when, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { patternKeys, recipeGroup } from '../util/index.js' - -const one_recipe_ingredient = any([ - record({ - item: resource('item'), - }), - record({ - tag: resource('tag/item'), - }), -]) - -const recipe_ingredient = any([ - one_recipe_ingredient, - listOf(one_recipe_ingredient), -]) - -const recipe_result = record({ - item: resource('item'), - count: opt(intRange(1, 64), 1), -}) - -export const recipe = as( - 'recipe', - dispatch('type', (type, props) => - record({ - type: resource('recipe_serializer'), - group: opt(recipeGroup), - ...pick(type, { - crafting_shaped: { - pattern: listOf(simpleString), - key: object(patternKeys(props), () => recipe_ingredient), - result: recipe_result, - }, - crafting_shapeless: { - ingredients: listOf(recipe_ingredient), - result: recipe_result, - }, - stonecutting: { - ingredient: recipe_ingredient, - result: resource('item'), - count: int, - }, - smithing: { - base: one_recipe_ingredient, - addition: one_recipe_ingredient, - result: recipe_result, - }, - }), - ...when( - type, - ['blasting', 'campfire_cooking', 'smelting', 'smoking'], - { - ingredient: recipe_ingredient, - result: resource('item'), - experience: opt(float, 0), - cookingtime: opt(int, type === 'smelting' ? 200 : 100), - }, - ), - })), -) diff --git a/packages/java-edition/src/json/checker/data/structure.ts b/packages/java-edition/src/json/checker/data/structure.ts deleted file mode 100644 index 419346657..000000000 --- a/packages/java-edition/src/json/checker/data/structure.ts +++ /dev/null @@ -1,234 +0,0 @@ -import { - any, - as, - boolean, - dispatch, - extractNested, - float, - floatRange, - intRange, - listOf, - literal, - opt, - pick, - record, - resource, - simpleString, - when, -} from '@spyglassmc/json/lib/checker/index.js' -import { nbt, versioned } from '../util/index.js' -import { block_state, height_provider, HeightmapType } from './common.js' -import { configured_feature_ref, placed_feature_ref } from './feature.js' - -export const rule_test = as( - 'rule_test', - dispatch('predicate_type', (type) => - record({ - predicate_type: resource('rule_test'), - ...pick(type, { - block_match: { - block: resource('block'), - }, - blockstate_match: { - block_state: block_state, - }, - random_block_match: { - block: resource('block'), - probability: floatRange(0, 1), - }, - random_blockstate_match: { - block_state: block_state, - probability: floatRange(0, 1), - }, - tag_match: { - tag: resource('tag/block'), - }, - }), - })), -) - -export const pos_rule_test = as( - 'pos_rule_test', - dispatch('predicate_type', (type) => - record({ - predicate_type: resource('pos_rule_test'), - ...pick(type, { - axis_aligned_linear_pos: { - axis: literal(['x', 'y', 'z']), - min_dist: opt(intRange(0, 255)), - max_dist: opt(intRange(0, 255)), - min_chance: opt(floatRange(0, 1)), - max_chance: opt(floatRange(0, 1)), - }, - }), - ...when(type, ['axis_aligned_linear_pos', 'linear_pos'], {}), - })), -) - -const processor_rule = as( - 'processor_rule', - dispatch((props) => - record({ - position_predicate: opt(pos_rule_test, { - predicate_type: 'always_true', - }), - input_predicate: rule_test, - location_predicate: rule_test, - output_state: block_state, - output_nbt: opt( - nbt({ - registry: 'block', - id: extractNested('output_state', 'Name', props), - }), - ), - }) - ), -) - -const processor = as( - 'processor', - dispatch('processor_type', (type) => - record({ - processor_type: resource('worldgen/structure_processor'), - ...pick(type, { - block_age: { - mossiness: float, - }, - block_ignore: { - blocks: listOf(block_state), - }, - block_rot: { - integrity: floatRange(0, 1), - }, - gravity: { - heightmap: literal(HeightmapType), - }, - protected_blocks: { - value: resource('tag/block'), - }, - rule: { - rules: listOf(processor_rule), - }, - }), - })), -) - -export const processor_list = as( - 'processor_list', - any([ - record({ - processors: listOf(processor), - }), - listOf(processor), - ]), -) - -export const processor_list_ref = as( - 'processor_list', - any([resource('worldgen/processor_list'), processor_list]), -) - -const template_element = as( - 'template_element', - dispatch('element_type', (type, _, ctx) => - record({ - element_type: resource('worldgen/structure_pool_element'), - ...when( - type, - ['empty_pool_element'], - {}, - { - projection: literal(['rigid', 'terrain_matching']), - }, - ), - ...pick(type, { - feature_pool_element: { - feature: versioned( - ctx, - configured_feature_ref, - '1.18', - placed_feature_ref, - ), - }, - legacy_single_pool_element: { - location: resource('structure'), - processors: processor_list_ref, - }, - list_pool_element: { - elements: listOf(template_element), - }, - single_pool_element: { - location: resource('structure'), - processors: processor_list_ref, - }, - }), - })), -) - -export const template_pool = as( - 'template_pool', - record({ - name: simpleString, - fallback: resource('worldgen/template_pool'), - elements: listOf( - record({ - weight: intRange(1, undefined), - element: template_element, - }), - ), - }), -) - -export const template_pool_ref = any([ - resource('worldgen/template_pool'), - template_pool, -]) - -export const configured_structure_feature = as( - 'structure_feature', - dispatch('type', (type) => - record({ - type: resource('worldgen/structure_feature'), - config: record({ - ...when( - type, - ['bastion_remnant', 'pillager_outpost', 'village'], - { - start_pool: template_pool_ref, - size: intRange(0, 7), - }, - pick(type, { - buried_treasure: { - probability: floatRange(0, 1), - }, - mineshaft: { - type: literal(['normal', 'mesa']), - probability: floatRange(0, 1), - }, - nether_fossil: { - height: height_provider, - }, - ocean_ruin: { - biome_temp: literal(['cold', 'warm']), - large_probability: floatRange(0, 1), - cluster_probability: floatRange(0, 1), - }, - ruined_portal: { - portal_type: literal([ - 'standard', - 'desert', - 'jungle', - 'mountain', - 'nether', - 'ocean', - 'swamp', - ]), - }, - shipwreck: { - is_beached: opt(boolean, false), - }, - }), - ), - }), - })), -) diff --git a/packages/java-edition/src/json/checker/data/tag.ts b/packages/java-edition/src/json/checker/data/tag.ts deleted file mode 100644 index c1528353b..000000000 --- a/packages/java-edition/src/json/checker/data/tag.ts +++ /dev/null @@ -1,53 +0,0 @@ -import type { TaggableResourceLocationCategory } from '@spyglassmc/core' -import { ErrorSeverity, ResourceLocation } from '@spyglassmc/core' -import { JsonObjectNode, JsonStringNode } from '@spyglassmc/json' -import { - any, - boolean, - opt, - record, - resource, - uniqueListOf, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { localize } from '@spyglassmc/locales' - -const tag = (type: TaggableResourceLocationCategory) => - record({ - replace: opt(boolean, false), - values: uniqueListOf( - any([ - resource(type, true), - record({ - id: resource(type, true), - required: opt(boolean, true), - }), - ]), - { - items: (node) => { - if (JsonStringNode.is(node)) { - return [ResourceLocation.shorten(node.value), node] - } - if (JsonObjectNode.is(node)) { - const id = node.children.find((c) => c.key?.value === 'id') - if (id && id.value && JsonStringNode.is(id.value)) { - return [ResourceLocation.shorten(id.value.value), id.value] - } - } - return [undefined, node] - }, - report: (node, ctx) => - ctx.err.report( - localize('json.checker.tag-entry.duplicate'), - node, - ErrorSeverity.Warning, - ), - }, - ), - }) - -export const block_tag = tag('block') -export const entity_type_tag = tag('entity_type') -export const fluid_tag = tag('fluid') -export const function_tag = tag('function') -export const game_event_tag = tag('game_event') -export const item_tag = tag('item') diff --git a/packages/java-edition/src/json/checker/data/text_component.ts b/packages/java-edition/src/json/checker/data/text_component.ts deleted file mode 100644 index 6e50d230b..000000000 --- a/packages/java-edition/src/json/checker/data/text_component.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { integer } from '@spyglassmc/core' -import { - any, - as, - boolean, - dispatch, - extract, - having, - int, - listOf, - literal, - opt, - pick, - record, - ref, - resource, - simpleString, - string, -} from '@spyglassmc/json/lib/checker/primitives/index.js' -import { - deprecated, - nbt, - nbtPath, - stringColor, - uuid, - versioned, -} from '../util/index.js' - -const Keybinds = [ - 'key.jump', - 'key.sneak', - 'key.sprint', - 'key.left', - 'key.right', - 'key.back', - 'key.forward', - 'key.attack', - 'key.pickItem', - 'key.use', - 'key.drop', - 'key.hotbar.1', - 'key.hotbar.2', - 'key.hotbar.3', - 'key.hotbar.4', - 'key.hotbar.5', - 'key.hotbar.6', - 'key.hotbar.7', - 'key.hotbar.8', - 'key.hotbar.9', - 'key.inventory', - 'key.swapOffhand', - 'key.loadToolbarActivator', - 'key.saveToolbarActivator', - 'key.playerlist', - 'key.chat', - 'key.command', - 'key.socialInteractions', - 'key.advancements', - 'key.spectatorOutlines', - 'key.screenshot', - 'key.smoothCamera', - 'key.fullscreen', - 'key.togglePerspective', -] - -const text_component_object = as('text_component', (node, ctx) => - record({ - ...having(node, ctx, { - text: { - text: simpleString, - }, - translate: { - translate: simpleString, - with: opt(listOf(text_component), []), - }, - selector: { - selector: simpleString, // TODO: entity selector - separator: opt(versioned(ctx, '1.17', text_component)), - }, - score: { - score: record({ - name: simpleString, // TODO: score holder - objective: simpleString, // TODO: objective - value: opt(simpleString), - }), - }, - keybind: { - keybind: literal(Keybinds), - }, - nbt: () => ({ - nbt: simpleString, - ...having(node, ctx, { - block: { - block: simpleString, // TODO: block pos - nbt: nbtPath({ registry: 'block' }), - }, - entity: { - entity: simpleString, // TODO: entity selector - nbt: nbtPath({ - registry: - 'entity_type', /* FIXME: import { getTypesFromEntity } from '../../../../mcfunction/checker'; ids: getTypesFromEntity(somehowGetTheNodeHere, ctx) */ - }), - }, - storage: { - storage: resource('storage'), - nbt: nbtPath({ - registry: - 'storage', /* FIXME:, id: extract('storage', props) */ - }), - }, - }), - interpret: opt(boolean, false), - separator: opt(versioned(ctx, '1.17', text_component)), - }), - }), - color: opt(stringColor()), - font: opt(simpleString), - bold: opt(boolean), - italic: opt(boolean), - underlined: opt(boolean), - strikethrough: opt(boolean), - obfuscated: opt(boolean), - insertion: opt(simpleString), - clickEvent: opt( - dispatch('action', (action) => - record({ - action: literal([ - 'open_url', - 'open_file', - 'run_command', - 'suggest_command', - 'change_page', - 'copy_to_clipboard', - ]), - value: simpleString, - ...pick(action, { - run_command: { - value: string( - 'command', - ctx.meta.getParserLazily('mcfunction:command'), - ctx.meta.getChecker('mcfunction:command'), - ), - }, - change_page: { - value: string( - 'number', - integer({ pattern: /\d+/, min: 0 }), - ), - }, - }), - })), - ), - hoverEvent: opt( - dispatch('action', (action, _, ctx) => - record({ - action: literal(['show_text', 'show_item', 'show_entity']), - ...pick(action, { - show_text: { - value: deprecated(ctx, '1.16', text_component), - contents: opt(versioned(ctx, '1.16', text_component)), - }, - show_item: { - value: deprecated( - ctx, - '1.16', - nbt({ - definition: - '::minecraft::util::invitem::InventoryItem', - }), - ), - contents: opt( - versioned( - ctx, - '1.16', - dispatch((props) => - record({ - id: resource('item'), - count: opt(int), - tag: opt( - nbt({ - registry: 'item', - id: extract('id', props), - }), - ), - }) - ), - ), - ), - }, - show_entity: { - value: deprecated( - ctx, - '1.16', - record({ - name: opt(simpleString), - type: opt(resource('entity_type')), - id: opt(uuid), - }), - ), - contents: opt( - versioned( - ctx, - '1.16', - record({ - name: opt(text_component), - type: opt(resource('entity_type')), - id: opt(uuid), - }), - ), - ), - }, - }), - })), - ), - extra: opt(listOf(text_component)), - })(node, ctx)) - -export const text_component = as( - 'text_component', - any([ - simpleString, - text_component_object, - listOf(ref(() => text_component)), - ]), -) diff --git a/packages/java-edition/src/json/checker/util/advancement.ts b/packages/java-edition/src/json/checker/util/advancement.ts deleted file mode 100644 index 6c7ccca5f..000000000 --- a/packages/java-edition/src/json/checker/util/advancement.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { Symbol } from '@spyglassmc/core' -import { literal, simpleString } from '@spyglassmc/json/lib/checker/index.js' -import type { JsonChecker } from '@spyglassmc/json/lib/checker/JsonChecker.js' - -export function criterionReference(advancement: string): JsonChecker { - return (node, ctx) => { - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ctx.ensureBindingStarted) { - simpleString(node, ctx) - return - } - const criteria = Object.values( - ctx.symbols.query(ctx.doc, 'advancement', advancement).symbol - ?.members ?? - {}, - ) - .filter((m): m is Symbol => m?.subcategory === 'criterion') - .map((s) => s.identifier) - literal(criteria)(node, ctx) - } -} diff --git a/packages/java-edition/src/json/checker/util/block_states.ts b/packages/java-edition/src/json/checker/util/block_states.ts deleted file mode 100644 index 5f85a9a78..000000000 --- a/packages/java-edition/src/json/checker/util/block_states.ts +++ /dev/null @@ -1,105 +0,0 @@ -import * as core from '@spyglassmc/core' -import { - any, - boolean, - intRange, - listOf, - literal, - object, - opt, - record, - simpleString, -} from '@spyglassmc/json/lib/checker/index.js' -import type { JsonChecker } from '@spyglassmc/json/lib/checker/JsonChecker.js' -import { getTagValues } from '../../../common/index.js' - -interface Options { - category?: 'block' | 'fluid' - id?: string | undefined - ids?: readonly string[] | undefined - tag?: string | undefined - mixedTypes?: boolean - requireAll?: boolean -} - -export function blockStateMap({ - category, - id, - ids, - tag, - mixedTypes, - requireAll, -}: Options): JsonChecker { - return (node, ctx) => { - if (tag) { - ids = getTagValues(`tag/${category ?? 'block'}`, tag, ctx) - } else if (id) { - ids = [id] - } - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ids?.length || !ctx.ensureBindingStarted) { - const values = mixedTypes - ? any([boolean, simpleString, intBounds()]) - : simpleString - object(simpleString, () => (requireAll ? values : opt(values)))( - node, - ctx, - ) - return - } - const states = core.getStates(category ?? 'block', ids, ctx) - object(Object.keys(states), (state) => { - const values = states[state] ?? [] - const checkers: JsonChecker[] = [literal(values)] - if (mixedTypes && values.length) { - if (['true', 'false'].includes(values[0])) { - checkers.push(boolean) - } else if (values[0].match(/^\d+$/)) { - checkers.push( - intBounds( - parseInt(values[0]), - parseInt(values[values.length - 1]), - ), - ) - } - } - const checker = checkers.length > 1 ? any(checkers) : checkers[0] - return requireAll ? checker : opt(checker) - })(node, ctx) - } -} - -export function blockStateList({ - category, - id, - ids, - tag, -}: Options): JsonChecker { - return (node, ctx) => { - if (tag) { - ids = getTagValues(`tag/${category ?? 'block'}`, tag, ctx) - } else if (id) { - ids = [id] - } - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ids?.length || !ctx.ensureBindingStarted) { - listOf(simpleString)(node, ctx) - return - } - const states = core.getStates(category ?? 'block', ids, ctx) - listOf(literal(Object.keys(states)))(node, ctx) - } -} - -function intBounds( - min: number | undefined = undefined, - max: number | undefined = undefined, -): JsonChecker { - return any([ - intRange(min, max), - record({ - min: opt(intRange(min, max)), - max: opt(intRange(min, max)), - }), - ]) -} diff --git a/packages/java-edition/src/json/checker/util/color.ts b/packages/java-edition/src/json/checker/util/color.ts deleted file mode 100644 index 2ee2e3882..000000000 --- a/packages/java-edition/src/json/checker/util/color.ts +++ /dev/null @@ -1,77 +0,0 @@ -import type { Parser } from '@spyglassmc/core' -import { - Color, - ColorFormat, - Failure, - parseStringValue, - Range, -} from '@spyglassmc/core' -import { JsonNumberNode, JsonStringNode } from '@spyglassmc/json' -import type { JsonChecker } from '@spyglassmc/json/lib/checker/JsonChecker.js' -import { localize } from '@spyglassmc/locales' - -export function stringColor(): JsonChecker { - const HexPattern = /^[0-9a-f]{1,6}$/i - - const parser: Parser = (src, ctx) => { - let value = 0 - const start = src.cursor - if (src.trySkip('#')) { - const remaining = src.readRemaining() - if (remaining.match(HexPattern)) { - value = parseInt(remaining, 16) - } else { - ctx.err.report( - localize('expected', localize('json.checker.string.hex-color')), - Range.create(start, src), - ) - } - } else { - const remaining = src.readRemaining() - if (Color.NamedColors.has(remaining)) { - value = Color.NamedColors.get(remaining)! - } else { - ctx.err.report( - localize('expected', Color.ColorNames), - Range.create(start, src), - ) - } - } - return Color.fromCompositeInt(value) - } - - return (node, ctx) => { - node.expectation = [ - { - type: 'json:string', - typedoc: 'String("Color")', - pool: Color.ColorNames, - }, - ] - if (!JsonStringNode.is(node)) { - ctx.err.report(localize('expected', localize('string')), node) - } else { - const result = parseStringValue(parser, node.value, node.valueMap, ctx) - if (result !== Failure) { - node.color = { - value: result, - format: [ColorFormat.HexRGB], - range: { start: node.range.start + 1, end: node.range.end - 1 }, - } - } - } - } -} - -export function intColor(): JsonChecker { - return (node, ctx) => { - if (!JsonNumberNode.is(node) || !Number.isInteger(node.value)) { - ctx.err.report(localize('expected', localize('integer')), node) - } else { - node.color = { - value: Color.fromCompositeInt(node.value), - format: [ColorFormat.CompositeInt], - } - } - } -} diff --git a/packages/java-edition/src/json/checker/util/index.ts b/packages/java-edition/src/json/checker/util/index.ts deleted file mode 100644 index d8f3e0a21..000000000 --- a/packages/java-edition/src/json/checker/util/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './advancement.js' -export * from './block_states.js' -export * from './color.js' -export * from './nbt.js' -export * from './recipe.js' -export * from './uuid.js' -export * from './version.js' diff --git a/packages/java-edition/src/json/checker/util/nbt.ts b/packages/java-edition/src/json/checker/util/nbt.ts deleted file mode 100644 index e0c7fd4a9..000000000 --- a/packages/java-edition/src/json/checker/util/nbt.ts +++ /dev/null @@ -1,95 +0,0 @@ -import type { FullResourceLocation } from '@spyglassmc/core' -import { ResourceLocation } from '@spyglassmc/core' -import { simpleString, string } from '@spyglassmc/json/lib/checker/index.js' -import type { - JsonChecker, - JsonCheckerContext, -} from '@spyglassmc/json/lib/checker/JsonChecker.js' -import type { NbtCompoundNode, NbtPathNode } from '@spyglassmc/nbt' -import { checker as nbtChecker } from '@spyglassmc/nbt' -import { getTagValues } from '../../../common/index.js' - -interface DefinitionOptions { - definition: `::${string}::${string}` -} -interface RegistryOptions { - registry: string - id?: string | undefined - idOrTag?: string | undefined - ids?: readonly string[] | undefined - tag?: string | undefined -} - -type Options = DefinitionOptions | RegistryOptions - -export function nbt(options: Options): JsonChecker { - if (isDefinitionOptions(options)) { - return definitionNbt(options) - } else { - return registryNbt(options) - } -} - -function isDefinitionOptions(options: Options): options is DefinitionOptions { - return typeof (options as DefinitionOptions).definition === 'string' -} - -function definitionNbt({ definition }: DefinitionOptions): JsonChecker { - return (node, ctx) => { - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ctx.ensureBindingStarted) { - simpleString(node, ctx) - return - } - const parser = ctx.meta.getParserLazily('nbt:compound') - const checker = nbtChecker.definition(definition) - string('nbt', parser, checker)(node, ctx) - } -} - -function registryNbt(options: RegistryOptions): JsonChecker { - return (node, ctx) => { - const ids = getIds(options, ctx) - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ctx.ensureBindingStarted) { - simpleString(node, ctx) - return - } - const parser = ctx.meta.getParser('nbt:compound') - const checker = nbtChecker.index(options.registry, ids) - string('nbt', parser, checker)(node, ctx) - } -} - -export function nbtPath(options: RegistryOptions): JsonChecker { - return (node, ctx) => { - const ids = getIds(options, ctx) - // FIXME: Temporary solution to make tests pass when ensureBindingStarted is not given. - if (!ctx.ensureBindingStarted) { - simpleString(node, ctx) - return - } - const parser = ctx.meta.getParser('nbt:path') - const checker = nbtChecker.path(options.registry, ids) - string('nbt_path', parser, checker)(node, ctx) - } -} - -function getIds( - { registry, id, idOrTag, ids, tag }: RegistryOptions, - ctx: JsonCheckerContext, -): FullResourceLocation[] | undefined { - if (idOrTag) { - idOrTag.startsWith('#') ? (tag = idOrTag.slice(1)) : (id = idOrTag) - } - if ( - tag && - (registry === 'block' || registry === 'item' || - registry === 'entity_type') - ) { - ids = getTagValues(`tag/${registry}`, tag, ctx) - } else if (id) { - ids = [id] - } - return ids?.map(ResourceLocation.lengthen) -} diff --git a/packages/java-edition/src/json/checker/util/recipe.ts b/packages/java-edition/src/json/checker/util/recipe.ts deleted file mode 100644 index d438b9839..000000000 --- a/packages/java-edition/src/json/checker/util/recipe.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { ItemNode, PairNode } from '@spyglassmc/core' -import { symbol } from '@spyglassmc/core' -import type { JsonNode, JsonStringNode } from '@spyglassmc/json' -import { string } from '@spyglassmc/json/lib/checker/index.js' -import type { JsonChecker } from '@spyglassmc/json/lib/checker/JsonChecker.js' - -export const recipeGroup: JsonChecker = string( - 'recipe_group', - symbol('recipe_group'), -) - -export function patternKeys(props: PairNode[]) { - return [ - ...new Set( - ( - props.find( - (p) => - p.key?.value === 'pattern' && p.value?.type === 'json:array', - )?.value?.children ?? [] - ) - .map((n) => (n as ItemNode).value) - .filter((n) => n && n.type === 'json:string') - .flatMap((n) => [...(n as JsonStringNode).value]) - .filter((v) => v !== ' '), - ), - ] -} diff --git a/packages/java-edition/src/json/checker/util/uuid.ts b/packages/java-edition/src/json/checker/util/uuid.ts deleted file mode 100644 index 467836a29..000000000 --- a/packages/java-edition/src/json/checker/util/uuid.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { string } from '@spyglassmc/json/lib/checker/index.js' -import { localize } from '@spyglassmc/locales' - -const UuidRegex = - /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i - -export const uuid = string(undefined, undefined, (node, ctx) => { - if (!node.value.match(UuidRegex)) { - ctx.err.report(localize('expected', localize('uuid')), node) - } -}) diff --git a/packages/java-edition/src/json/checker/util/version.ts b/packages/java-edition/src/json/checker/util/version.ts deleted file mode 100644 index 0a5bd7027..000000000 --- a/packages/java-edition/src/json/checker/util/version.ts +++ /dev/null @@ -1,124 +0,0 @@ -import type { - JsonChecker, - JsonCheckerContext, - record, -} from '@spyglassmc/json/lib/checker/index.js' -import { deprecate } from '@spyglassmc/json/lib/checker/index.js' -import { ReleaseVersion } from '../../../dependency/index.js' - -type CheckerRecord = Parameters[0] - -function getVersion(ctx: JsonCheckerContext) { - return ctx.project['loadedVersion'] as ReleaseVersion -} - -function cmpVersion(ctx: JsonCheckerContext, target: ReleaseVersion): number { - return ReleaseVersion.cmp(getVersion(ctx), target) -} - -export function versioned( - ctx: JsonCheckerContext, - version: ReleaseVersion, - checker: string[], -): string[] -export function versioned( - ctx: JsonCheckerContext, - version: ReleaseVersion, - checker: JsonChecker | undefined, -): JsonChecker | undefined -export function versioned( - ctx: JsonCheckerContext, - version: ReleaseVersion, - checker: CheckerRecord | undefined, -): CheckerRecord | undefined - -export function versioned( - ctx: JsonCheckerContext, - checker: string[], - version: ReleaseVersion, -): string[] -export function versioned( - ctx: JsonCheckerContext, - checker: JsonChecker | undefined, - version: ReleaseVersion, -): JsonChecker | undefined -export function versioned( - ctx: JsonCheckerContext, - checker: CheckerRecord | undefined, - version: ReleaseVersion, -): CheckerRecord | undefined - -export function versioned( - ctx: JsonCheckerContext, - checker: string[], - version: ReleaseVersion, - checker2: string[], -): string[] -export function versioned( - ctx: JsonCheckerContext, - checker: JsonChecker, - version: ReleaseVersion, - checker2: JsonChecker, -): JsonChecker -export function versioned( - ctx: JsonCheckerContext, - checker: CheckerRecord, - version: ReleaseVersion, - checker2: CheckerRecord, -): CheckerRecord -export function versioned( - ctx: JsonCheckerContext, - arg1: any, - arg2?: any, - arg3?: any, -): any { - if (typeof arg1 === 'string') { - const check = cmpVersion(ctx, arg1 as ReleaseVersion) >= 0 - if (arg2 === undefined) { - return arg2 - } else if (Array.isArray(arg2)) { - return check ? arg2 : [] - } else { - return check ? arg2 : undefined - } - } else { - const check = cmpVersion(ctx, arg2 as ReleaseVersion) < 0 - if (arg1 === undefined) { - return arg1 - } else if (Array.isArray(arg1)) { - return check ? arg1 : arg3 ?? [] - } else { - return check ? arg1 : arg3 ?? undefined - } - } -} - -export function renamed( - ctx: JsonCheckerContext, - from: string, - version: ReleaseVersion, - to: string, - checker: JsonChecker, -): CheckerRecord | undefined { - return versioned( - ctx, - { - [from]: checker, - }, - version, - { - [to]: checker, - }, - ) -} - -export function deprecated( - ctx: JsonCheckerContext, - version: ReleaseVersion, - checker: JsonChecker | undefined, -) { - if (cmpVersion(ctx, version) < 0) { - return checker - } - return deprecate(checker) -} diff --git a/packages/java-edition/src/mcfunction/checker/index.ts b/packages/java-edition/src/mcfunction/checker/index.ts index e760096a7..d6cde99d3 100644 --- a/packages/java-edition/src/mcfunction/checker/index.ts +++ b/packages/java-edition/src/mcfunction/checker/index.ts @@ -4,7 +4,6 @@ import { localize } from '@spyglassmc/locales' import * as mcf from '@spyglassmc/mcfunction' import * as nbt from '@spyglassmc/nbt' import { getTagValues } from '../../common/index.js' -import { text_component } from '../../json/checker/data/text_component.js' import type { EntitySelectorInvertableArgumentValueNode } from '../node/index.js' import { BlockNode, EntityNode, ItemNode, ParticleNode } from '../node/index.js' @@ -47,7 +46,7 @@ const rootCommand = ( } else if (ParticleNode.is(node)) { particle(node, ctx) } else if (json.JsonNode.is(node)) { - text_component(node, { ...ctx, context: '' }) + // TODO v4.0: check text component } } diff --git a/packages/java-edition/test/json/checker/vanilla.spec.ts b/packages/java-edition/test/json/checker/vanilla.spec.ts deleted file mode 100644 index c415ee9c5..000000000 --- a/packages/java-edition/test/json/checker/vanilla.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { mockProjectData } from '@spyglassmc/core/test-out/utils.js' -import { testChecker } from '@spyglassmc/json/test-out/utils.js' -import * as nbt from '@spyglassmc/nbt' -import { strict as assert } from 'assert' -import fg from 'fast-glob' -import fs from 'fs' -import { TextDocument } from 'vscode-languageserver-textdocument' -import { Categories } from '../../../lib/binder/index.js' -import { Checkers } from '../../../lib/json/checker/data/index.js' - -describe.skip('Check vanilla files', async () => { - const root = 'node_modules/vanilla-datapack-data/data/minecraft/' - const summary = [...Categories.keys()].map((c) => - fg.sync(`${root}${c}/**/*.json`) - ) - - const project = mockProjectData({ - roots: ['file:///'], - ctx: { loadedVersion: '1.18' }, - }) - nbt.initialize(project) - - summary.forEach((files, i) => { - const category = [...Categories][i] - const checker = Checkers.get(category[1].category) - if (!checker || !files) return - - it(`Category ${category[1].category}`, () => { - let passing = true - files.forEach((file) => { - if (file.endsWith('/dimension/overworld.json')) { - return // skip insanely large file - } - const text = fs.readFileSync(file, 'utf-8') - const result = testChecker(checker, text, { project }) - const errors = result.parserErrors - .concat(result.checkerErrors) - .filter((e) => !e.message.startsWith('Cannot find')) - if (errors.length === 0) return - - passing = false - setTimeout(() => { - console.log( - `\t${file.slice(root.length + category[0].length + 1)}`, - ) - const doc = TextDocument.create('', '', 0, text) - errors.forEach((e) => { - const pos = doc.positionAt(e.range.start) - console.log( - `\t ${pos.line + 1}:${pos.character} ${e.message}`, - ) - }) - }, 0) - }) - assert(passing) - }) - }) -}) diff --git a/packages/json/src/checker/JsonChecker.ts b/packages/json/src/checker/JsonChecker.ts deleted file mode 100644 index 008f7026c..000000000 --- a/packages/json/src/checker/JsonChecker.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { CheckerContext } from '@spyglassmc/core' -import type { JsonNode } from '../node/index.js' - -export interface JsonCheckerContext extends CheckerContext { - context: string - depth?: number -} - -export type JsonChecker = (node: JsonNode, ctx: JsonCheckerContext) => void diff --git a/packages/json/src/checker/index.ts b/packages/json/src/checker/index.ts deleted file mode 100644 index dd1e5a610..000000000 --- a/packages/json/src/checker/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './JsonChecker.js' -export * from './primitives/index.js' diff --git a/packages/json/src/checker/primitives/boolean.ts b/packages/json/src/checker/primitives/boolean.ts deleted file mode 100644 index 716ae187b..000000000 --- a/packages/json/src/checker/primitives/boolean.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { localize } from '@spyglassmc/locales' -import type { JsonNode } from '../../node/index.js' -import { JsonBooleanNode } from '../../node/index.js' -import type { JsonCheckerContext } from '../JsonChecker.js' - -export function boolean(node: JsonNode, ctx: JsonCheckerContext) { - node.expectation = [{ type: 'json:boolean', typedoc: 'Boolean' }] - - if (!JsonBooleanNode.is(node)) { - ctx.err.report(localize('expected', localize('boolean')), node) - } -} diff --git a/packages/json/src/checker/primitives/index.ts b/packages/json/src/checker/primitives/index.ts deleted file mode 100644 index caf648ab0..000000000 --- a/packages/json/src/checker/primitives/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export * from './boolean.js' -export * from './list.js' -export * from './number.js' -export * from './object.js' -export * from './string.js' -export * from './util.js' diff --git a/packages/json/src/checker/primitives/list.ts b/packages/json/src/checker/primitives/list.ts deleted file mode 100644 index bf6a0c84d..000000000 --- a/packages/json/src/checker/primitives/list.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { ErrorSeverity } from '@spyglassmc/core' -import { localize } from '@spyglassmc/locales' -import type { JsonArrayExpectation, JsonNode } from '../../node/index.js' -import { JsonArrayNode, JsonStringNode } from '../../node/index.js' -import type { JsonChecker, JsonCheckerContext } from '../JsonChecker.js' -import { expectation } from './util.js' - -export function listOf(checker: JsonChecker): JsonChecker { - return (node, ctx) => { - node.expectation = [{ type: 'json:array', typedoc: 'Array' }] - if (!ctx.depth || ctx.depth <= 0) { - ;(node.expectation![0] as JsonArrayExpectation).items = expectation( - checker, - ctx, - ) - } - - if (!JsonArrayNode.is(node)) { - ctx.err.report(localize('expected', localize('array')), node) - } else { - node.children - .filter((e) => e.value) - .forEach((e) => checker(e.value!, ctx)) - } - } -} - -type UniqueListOptions = { - items?: (node: JsonNode) => [string | undefined, JsonNode] - report?: (node: JsonNode, ctx: JsonCheckerContext) => unknown -} -export function uniqueListOf( - checker: JsonChecker, - options: UniqueListOptions = {}, -): JsonChecker { - const getItem = options.items ?? - ((node) => [JsonStringNode.is(node) ? node.value : undefined, node]) - const reporter = options.report ?? - ((node, ctx) => - ctx.err.report( - localize('json.checker.item.duplicate'), - node, - ErrorSeverity.Warning, - )) - return (node, ctx) => { - listOf(checker)(node, ctx) - if (JsonArrayNode.is(node)) { - const items = new Map() - const duplicates = new Set() - node.children.forEach((c) => { - if (!c.value) return - const [value, item] = getItem(c.value) - if (!value) return - const existing = items.get(value) - if (existing) { - duplicates.add(existing) - duplicates.add(item) - } - items.set(value, item) - }) - duplicates.forEach((node) => reporter(node, ctx)) - } - } -} diff --git a/packages/json/src/checker/primitives/number.ts b/packages/json/src/checker/primitives/number.ts deleted file mode 100644 index bcbaa768d..000000000 --- a/packages/json/src/checker/primitives/number.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { localize } from '@spyglassmc/locales' -import { JsonNumberNode } from '../../node/index.js' -import type { JsonChecker } from '../JsonChecker.js' - -const number = - (type: 'integer' | 'float') => - (min: number | undefined, max: number | undefined): JsonChecker => { - return (node, ctx) => { - const typedoc = 'Number' + - (min === undefined && max === undefined - ? '' - : `(${min ?? '-∞'}, ${max ?? '+∞'})`) - node.expectation = [{ type: 'json:number', typedoc }] - - if ( - !JsonNumberNode.is(node) || - (type === 'integer' && !Number.isInteger(node.value)) - ) { - ctx.err.report(localize('expected', localize(type)), node) - } else if ( - min !== undefined && - max !== undefined && - (node.value < min || node.value > max) - ) { - ctx.err.report( - localize('expected', localize('number.between', min, max)), - node, - ) - } else if (min !== undefined && node.value < min) { - ctx.err.report( - localize('expected', localize('number.>=', min)), - node, - ) - } else if (max !== undefined && node.value > max) { - ctx.err.report( - localize('expected', localize('number.<=', max)), - node, - ) - } - } - } - -export const int = number('integer')(undefined, undefined) - -export const float = number('float')(undefined, undefined) - -export const intRange = number('integer') - -export const floatRange = number('float') diff --git a/packages/json/src/checker/primitives/object.ts b/packages/json/src/checker/primitives/object.ts deleted file mode 100644 index 65a27859e..000000000 --- a/packages/json/src/checker/primitives/object.ts +++ /dev/null @@ -1,366 +0,0 @@ -import type { ItemNode, PairNode } from '@spyglassmc/core' -import { ErrorSeverity, Range, ResourceLocation } from '@spyglassmc/core' -import { localeQuote, localize } from '@spyglassmc/locales' -import type { - JsonNode, - JsonObjectExpectation, - JsonStringNode, -} from '../../node/index.js' -import { JsonObjectNode, JsonStringExpectation } from '../../node/index.js' -import type { JsonChecker, JsonCheckerContext } from '../JsonChecker.js' -import { any, expectation } from './util.js' - -type JsonValue = - | string - | number - | boolean - // eslint-disable-next-line no-restricted-syntax - | null - | JsonValue[] - | { [key: string]: JsonValue } - -type ComplexProperty = { - checker: JsonChecker - opt?: boolean - def?: JsonValue - deprecated?: boolean - context?: string -} - -type CheckerProperty = JsonChecker | ComplexProperty - -type CheckerRecord = Record - -type ObjectCheckerOptions = { - allowUnknownProperties?: boolean -} - -function isComplex(checker: CheckerProperty): checker is ComplexProperty { - return (checker as ComplexProperty)?.checker !== undefined -} - -export function object(): JsonChecker -export function object( - keys: string[], - values: ( - key: string, - ctx: JsonCheckerContext, - ) => CheckerProperty | undefined, - options?: ObjectCheckerOptions, -): JsonChecker -export function object( - keys: JsonChecker, - values: ( - key: string, - ctx: JsonCheckerContext, - ) => CheckerProperty | undefined, - options?: ObjectCheckerOptions, -): JsonChecker -export function object( - keys?: string[] | JsonChecker, - values?: ( - key: string, - ctx: JsonCheckerContext, - ) => CheckerProperty | undefined, - options: ObjectCheckerOptions = {}, -): JsonChecker { - return (node, ctx) => { - node.expectation = [{ type: 'json:object', typedoc: 'Object' }] - if (!ctx.depth || ctx.depth <= 0) { - if (Array.isArray(keys) && values) { - const fields = keys - .map<[string, CheckerProperty]>(( - key, - ) => [key, values(key, ctx)!]) - .filter(([_, v]) => v !== undefined) - ;(node.expectation![0] as JsonObjectExpectation).fields = fields - .map( - ([key, prop]) => { - return { - key, - value: expectation( - isComplex(prop) ? prop.checker : prop, - ctx, - ), - ...(isComplex(prop) && (prop.opt || prop.deprecated) - ? { opt: true } - : {}), - ...(isComplex(prop) && prop.deprecated - ? { deprecated: true } - : {}), - } - }, - ) - } else if (typeof keys === 'function' && values) { - ;(node.expectation![0] as JsonObjectExpectation).keys = expectation( - keys, - ctx, - )?.filter(JsonStringExpectation.is) - } - } - - if (!JsonObjectNode.is(node)) { - ctx.err.report(localize('expected', localize('object')), node) - } else if (Array.isArray(keys) && values) { - const givenKeys = node.children.map((n) => n.key?.value) - keys.forEach((k) => { - const value = values(k, ctx) - if ( - !value || (isComplex(value) && (value.opt || value.deprecated)) - ) { - return - } - if (!givenKeys.includes(k)) { - ctx.err.report( - localize('json.checker.property.missing', localeQuote(k)), - Range.create(node.range.start, node.range.start + 1), - ) - } - }) - node.children - .filter((p) => p.key) - .forEach((prop) => { - const key = prop.key!.value - const value = values(key, ctx) - if (!value || !keys.includes(key)) { - if (!options.allowUnknownProperties) { - ctx.err.report( - localize( - 'json.checker.property.unknown', - localeQuote(key), - ), - prop.key!, - ErrorSeverity.Warning, - ) - } - return - } - if (isComplex(value) && value.deprecated) { - ctx.err.report( - localize( - 'json.checker.property.deprecated', - localeQuote(key), - ), - prop.key!, - ErrorSeverity.Hint, - { deprecated: true }, - ) - } - const context = ctx.context + - (isComplex(value) && value.context ? `.${value.context}` : '') - const doc = localize(`json.doc.${context}`) - const propNode: JsonNode = prop.value !== undefined - ? prop.value - : { type: 'json:null', range: Range.create(0) } - const checker = isComplex(value) ? value.checker : value - try { - checker(propNode, { ...ctx, context: `${context}.${key}` }) - } catch (e) { - const pos = ctx.doc.positionAt(prop.range.start) - ctx.logger.error( - `Checking "${key}" at ${pos.line}:${pos.character} in "${ctx.doc.uri}"`, - e, - ) - } - const defaultValue = isComplex(value) ? value.def : undefined - const typedoc = propNode.expectation - ?.map((e) => e.typedoc) - .join(' | ') - prop.key!.hover = - `\`\`\`typescript\n${context}.${key}: ${typedoc}\n\`\`\`${ - doc || defaultValue !== undefined ? '\n******\n ' : '' - }${doc}${ - defaultValue !== undefined - ? `\n\`@default\` ${JSON.stringify(defaultValue)}` - : '' - }` - }) - } else if (typeof keys === 'function' && values) { - node.children - .filter((p) => p.key) - .forEach((prop) => { - keys(prop.key!, ctx) - if (prop.value !== undefined) { - const value = values(prop.key!.value, ctx) - if (value) { - const checker = isComplex(value) ? value.checker : value - checker(prop.value, ctx) - } - } - }) - } - } -} - -export function record( - properties: CheckerRecord, - options?: ObjectCheckerOptions, -): JsonChecker { - return object(Object.keys(properties), (key) => properties[key], options) -} - -export function opt( - checker?: JsonChecker | ComplexProperty, - defaultValue?: JsonValue, -): ComplexProperty | undefined { - if (checker === undefined) return undefined - return isComplex(checker) - ? { ...checker, opt: true, def: defaultValue } - : { checker, opt: true, def: defaultValue } -} - -export function deprecate( - checker?: JsonChecker | ComplexProperty, -): ComplexProperty | undefined { - if (checker === undefined) return undefined - return isComplex(checker) - ? { ...checker, deprecated: true } - : { checker, deprecated: true } -} - -export function dispatch( - values: ( - children: PairNode[], - ctx: JsonCheckerContext, - ) => JsonChecker, -): JsonChecker -export function dispatch( - keyName: string, - values: ( - value: string | undefined, - children: PairNode[], - ctx: JsonCheckerContext, - ) => JsonChecker, -): JsonChecker -export function dispatch( - arg1: - | string - | (( - children: PairNode[], - ctx: JsonCheckerContext, - ) => JsonChecker), - arg2?: ( - value: string | undefined, - children: PairNode[], - ctx: JsonCheckerContext, - ) => JsonChecker, -): JsonChecker { - return (node, ctx) => { - if (!JsonObjectNode.is(node)) { - ctx.err.report(localize('expected', localize('object')), node) - } else if (arg2) { - const dispatcherIndex = node.children.findIndex( - (p) => p.key?.value === arg1, - ) - const dispatcher = node.children[dispatcherIndex] - const value = dispatcher?.value?.type === 'json:string' - ? dispatcher.value.value - : undefined - arg2(value, node.children, ctx)(node, ctx) - } else { - ;(arg1 as Function)(node.children, ctx)(node, ctx) - } - } -} - -export function pick( - value: string | undefined, - cases: Record, -): CheckerRecord { - if (value === undefined) { - return {} - } - const properties = cases[ResourceLocation.shorten(value)] - if (properties === undefined) { - return {} - } - Object.keys(properties).forEach((key) => { - const p = properties[key] - if (p === undefined) return - properties[key] = { - checker: isComplex(p) ? p.checker : p, - opt: isComplex(p) ? p.opt : undefined, - deprecated: isComplex(p) ? p.deprecated : undefined, - context: ResourceLocation.shorten(value), - } - }) - return properties -} - -export function when( - value: string | undefined, - values: string[], - properties: CheckerRecord, - notProperties: CheckerRecord = {}, -): CheckerRecord { - if (value === undefined) { - return {} - } - if (!values.includes(ResourceLocation.shorten(value))) { - return notProperties - } - return properties -} - -export function extract( - value: string, - children: PairNode[] | undefined, -) { - const node = children?.find((p) => p.key?.value === value) - return node?.value?.type === 'json:string' ? node.value.value : undefined -} - -export function extractNested( - wrap: string, - value: string, - children: PairNode[] | undefined, -) { - const wrapper = children?.find((p) => p.key?.value === wrap) - if (wrapper?.value?.type !== 'json:object') return undefined - const node = wrapper.children?.find( - (p) => - (p as unknown as PairNode).key?.value === - value, - ) - return node?.type === 'json:string' ? node.value : undefined -} - -export function extractStringArray( - value: string, - children?: PairNode[] | undefined, -): readonly string[] | undefined { - const node = children?.find((p) => p.key?.value === value) - return node?.value?.type === 'json:array' && - node.value.children?.every( - (n): n is ItemNode => - n.value?.type === 'json:string', - ) - ? node.value.children.map((n) => n.value!.value) - : undefined -} - -export function having( - node: JsonNode, - ctx: JsonCheckerContext, - cases: Record CheckerRecord)>, -): CheckerRecord { - const givenKeys = new Set( - JsonObjectNode.is(node) ? node.children.map((n) => n.key?.value) : [], - ) - const key = Object.keys(cases).find((c) => givenKeys.has(c)) - - if (key === undefined) { - ctx.err.report( - localize('json.checker.property.missing', Object.keys(cases)), - Range.create(node.range.start, node.range.start + 1), - ) - return Object.fromEntries( - Object.entries(cases).map(([k, v]) => [ - k, - opt(typeof v === 'function' ? any() : v[k] ?? any()), - ]), - ) - } - const c = cases[key] - return typeof c === 'function' ? c() : c -} diff --git a/packages/json/src/checker/primitives/string.ts b/packages/json/src/checker/primitives/string.ts deleted file mode 100644 index 13bf380f7..000000000 --- a/packages/json/src/checker/primitives/string.ts +++ /dev/null @@ -1,105 +0,0 @@ -import type { - AllCategory, - AstNode, - Checker, - Parser, - ResourceLocationCategory, - SyncChecker, - TaggableResourceLocationCategory, -} from '@spyglassmc/core' -import * as core from '@spyglassmc/core' -import { Failure, Lazy, ResourceLocation } from '@spyglassmc/core' -import { localize } from '@spyglassmc/locales' -import type { JsonExpectation } from '../../node/index.js' -import { JsonStringNode } from '../../node/index.js' -import type { JsonChecker } from '../JsonChecker.js' - -export function resource( - id: TaggableResourceLocationCategory, - allowTag?: boolean, -): JsonChecker -export function resource( - id: ResourceLocationCategory | string[], - allowTag?: false, -): JsonChecker -export function resource( - id: ResourceLocationCategory | string[], - allowTag = false, -): JsonChecker { - return string( - id, - core.resourceLocation( - typeof id === 'string' - ? { category: id as any, allowTag } - : { pool: id.map(ResourceLocation.lengthen) }, - ), - core.checker.resourceLocation, - ) -} - -export function literal(value: AllCategory | readonly string[]): JsonChecker { - return typeof value === 'string' - ? string(value, core.symbol(value)) - : string(value, core.literal(...value)) -} - -export function string( - name: string | readonly string[] | undefined, - parser: Lazy>, - checker?: Lazy>, - expectation?: Partial, -): JsonChecker -export function string( - name?: string | readonly string[], - parser?: undefined, - checker?: Lazy>, - expectation?: Partial, -): JsonChecker -export function string( - name?: string | readonly string[], - parser?: Lazy>, - checker?: Lazy>, - expectation?: Partial, -): JsonChecker { - return (node, ctx) => { - node.expectation = [ - { type: 'json:string', typedoc: typedoc(name), ...expectation }, - ] - if (!JsonStringNode.is(node)) { - ctx.err.report(localize('expected', localize('string')), node) - } else if (parser) { - const result = core.parseStringValue( - Lazy.resolve(parser), - node.value, - node.valueMap, - ctx, - ) - if (result !== Failure) { - node.children = [result] - result.parent = node - if (checker) { - Lazy.resolve(checker)(result, ctx) - } - } - } else if (checker) { - Lazy.resolve(checker)(node, ctx) - } - } -} - -function typedoc(id?: string | readonly string[]) { - if (!id) { - return 'String' - } - if (typeof id === 'string') { - return `String("${id}")` - } - return ( - id - .slice(0, 10) - .map((e) => `"${e}"`) - .join(' | ') + (id.length > 10 ? ' | ...' : '') - ) -} - -export const simpleString = string() diff --git a/packages/json/src/checker/primitives/util.ts b/packages/json/src/checker/primitives/util.ts deleted file mode 100644 index 07a486ff4..000000000 --- a/packages/json/src/checker/primitives/util.ts +++ /dev/null @@ -1,109 +0,0 @@ -import type { ErrorSeverity } from '@spyglassmc/core' -import { ErrorReporter, Range, StateProxy } from '@spyglassmc/core' -import { arrayToMessage, localize } from '@spyglassmc/locales' -import type { JsonExpectation, JsonNode } from '../../node/index.js' -import type { JsonChecker, JsonCheckerContext } from '../JsonChecker.js' - -export function ref(checker: () => JsonChecker): JsonChecker { - return (node, ctx) => { - return checker()(node, ctx) - } -} - -export function as(context: string, checker: JsonChecker): JsonChecker { - return (node, ctx) => { - checker(node, { ...ctx, context }) - } -} - -export type AttemptResult = { - totalErrorSpan: number - maxSeverity: ErrorSeverity - expectation?: JsonExpectation[] - updateNodeAndCtx: () => void -} - -export function attempt( - checker: JsonChecker, - node: JsonNode, - ctx: JsonCheckerContext, -): AttemptResult { - // TODO: The code below is mostly copied from core with some changes to support `expectation`. Could be refactored... I guess. - const tempCtx: JsonCheckerContext = { - ...ctx, - err: new ErrorReporter(), - symbols: ctx.symbols.clone(), - } - - checker(node, tempCtx) - - const tempExpectation = node.expectation - StateProxy.undoChanges(node as StateProxy) - - const totalErrorSpan = tempCtx.err.errors - .map((e) => e.range.end - e.range.start) - .reduce((a, b) => a + b, 0) - - return { - totalErrorSpan, - maxSeverity: Math.max(...tempCtx.err.errors.map((e) => e.severity)), - expectation: tempExpectation, - updateNodeAndCtx: () => { - ctx.err.absorb(tempCtx.err) - StateProxy.redoChanges(node as StateProxy) - tempCtx.symbols.applyDelayedEdits() - }, - } -} - -export function any(checkers: JsonChecker[] = []): JsonChecker { - return (node, ctx) => { - if (checkers.length === 0) { - return - } - - const attempts = checkers - .map((checker) => attempt(checker, node, ctx)) - .sort( - (a, b) => - a.maxSeverity - b.maxSeverity || - a.totalErrorSpan - b.totalErrorSpan, - ) - const sameTypeAttempts = attempts.filter((a) => - a.expectation?.map((e) => e.type).includes(node.type) - ) - const allExpectations = attempts - .filter((a) => a.expectation) - .flatMap((a) => a.expectation!) - - if (sameTypeAttempts.length === 0) { - const allowedTypes = allExpectations.map((e) => - localize(e.type.slice(5)) - ) - ctx.err.report( - localize('expected', arrayToMessage(allowedTypes, false)), - node, - ) - } else { - sameTypeAttempts[0].updateNodeAndCtx() - } - node.expectation = allExpectations - } -} - -export function expectation( - checker: JsonChecker, - ctx: JsonCheckerContext, -): JsonExpectation[] | undefined { - const node: JsonNode = StateProxy.create({ - type: 'json:null', - range: Range.create(0), - }) - const tempCtx: JsonCheckerContext = { - ...ctx, - err: new ErrorReporter(), - depth: (ctx.depth ?? 0) + 1, - } - checker(node, tempCtx) - return node.expectation -} diff --git a/packages/json/src/index.ts b/packages/json/src/index.ts index 1e3b4c4b3..03f512355 100644 --- a/packages/json/src/index.ts +++ b/packages/json/src/index.ts @@ -6,7 +6,6 @@ import * as completer from './completer/index.js' import * as formatter from './formatter/index.js' import * as parser from './parser/index.js' -export * as checker from './checker/index.js' export * as colorizer from './colorizer/index.js' export * as completer from './completer/index.js' export * as formatter from './formatter/index.js' diff --git a/packages/json/test/checker/primitives/boolean.spec.ts b/packages/json/test/checker/primitives/boolean.spec.ts deleted file mode 100644 index aa056af0e..000000000 --- a/packages/json/test/checker/primitives/boolean.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { describe } from 'mocha' -import { boolean } from '../../../lib/checker/primitives/index.js' -import { testGrid } from '../../utils.js' - -describe('JSON boolean', () => { - testGrid( - [ - { content: 'true' }, - { content: 'false' }, - { content: '1' }, - { content: 'tru' }, - { content: 'trues' }, - { content: '"true"' }, - ], - [{ name: 'boolean', checker: boolean }], - ) -}) diff --git a/packages/json/test/checker/primitives/list.spec.ts b/packages/json/test/checker/primitives/list.spec.ts deleted file mode 100644 index 027da0db4..000000000 --- a/packages/json/test/checker/primitives/list.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { describe } from 'mocha' -import { - int, - listOf, - simpleString, -} from '../../../lib/checker/primitives/index.js' -import { testGrid } from '../../utils.js' - -describe('JSON list', () => { - testGrid( - [ - { content: '[1, 4, 6]' }, - { content: '["foo", "bar"]' }, - { content: '[[4, 6]]' }, - { content: '[]' }, - { content: '5' }, - ], - [ - { name: 'listOf(int)', checker: listOf(int) }, - { name: 'listOf(string)', checker: listOf(simpleString) }, - { name: 'listOf(listOf(int))', checker: listOf(listOf(int)) }, - ], - ) -}) diff --git a/packages/json/test/checker/primitives/number.spec.ts b/packages/json/test/checker/primitives/number.spec.ts deleted file mode 100644 index 6b44847f2..000000000 --- a/packages/json/test/checker/primitives/number.spec.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { describe } from 'mocha' -import { - float, - floatRange, - int, - intRange, -} from '../../../lib/checker/primitives/index.js' -import { testGrid } from '../../utils.js' - -describe('JSON number', () => { - testGrid( - [ - { content: '2' }, - { content: '4' }, - { content: '-7' }, - { content: '4.3' }, - { content: '-5.62' }, - { content: 'false' }, - { content: '8b' }, - { content: '"5"' }, - { content: '6e4' }, - ], - [ - { name: 'int', checker: int }, - { name: 'float', checker: float }, - { name: 'intRange(1, 3)', checker: intRange(1, 3) }, - { name: 'intRange(-9, 0)', checker: intRange(-9, 0) }, - { name: 'intRange(undefined, 3)', checker: intRange(undefined, 3) }, - { name: 'intRange(3, undefined)', checker: intRange(3, undefined) }, - { name: 'floatRange(1, 2.4)', checker: floatRange(1, 2.4) }, - { - name: 'floatRange(-5, undefined)', - checker: floatRange(-5, undefined), - }, - ], - ) -}) diff --git a/packages/json/test/checker/primitives/object.spec.ts b/packages/json/test/checker/primitives/object.spec.ts deleted file mode 100644 index 1d573ae7f..000000000 --- a/packages/json/test/checker/primitives/object.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { describe } from 'mocha' -import { - int, - object, - opt, - record, - simpleString, -} from '../../../lib/checker/primitives/index.js' -import { testGrid } from '../../utils.js' - -describe('JSON object', () => { - testGrid( - [ - { content: '{}' }, - { content: '{ "b": 6 }' }, - { content: '{ "a": 1 }' }, - { content: '{ "a": 3, "b": "foo" }' }, - { content: '[2]' }, - ], - [ - { name: 'object()', checker: object() }, - { name: 'record({ a: int })', checker: record({ a: int }) }, - { name: 'record({ a: opt(int) })', checker: record({ a: opt(int) }) }, - { - name: 'object(string, () => int)', - checker: object(simpleString, () => int), - }, - ], - ) -}) diff --git a/packages/json/test/checker/primitives/string.spec.ts b/packages/json/test/checker/primitives/string.spec.ts deleted file mode 100644 index d9649f877..000000000 --- a/packages/json/test/checker/primitives/string.spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { describe } from 'mocha' -import { simpleString } from '../../../lib/checker/primitives/index.js' -import { testGrid } from '../../utils.js' - -describe('JSON string', () => { - testGrid( - [{ content: '"foo"' }, { content: '"foo"bar"' }, { content: '4' }], - [{ name: 'string', checker: simpleString }], - ) -}) diff --git a/packages/json/test/utils.ts b/packages/json/test/utils.ts index 965da50d3..b0b237657 100644 --- a/packages/json/test/utils.ts +++ b/packages/json/test/utils.ts @@ -21,57 +21,9 @@ import { } from '@spyglassmc/core/test-out/utils.js' import snapshot from 'snap-shot-it' import { TextDocument } from 'vscode-languageserver-textdocument' -import type { JsonChecker } from '../lib/checker/JsonChecker.js' import type { JsonExpectation, JsonNode } from '../lib/node/index.js' import { entry as parser } from '../lib/parser/index.js' -export function testChecker( - checker: JsonChecker, - test: string, - { project }: { project?: Partial } = {}, -): { - node: JsonNode | 'FAILURE' - parserErrors: readonly LanguageError[] - checkerErrors: readonly LanguageError[] -} { - const src = new Source(test) - const doc = TextDocument.create('file:///', 'json', 0, test) - const symbols = new SymbolUtil({}, NodeJsExternals.event.EventEmitter) - const parserCtx = ParserContext.create( - mockProjectData({ symbols, ...project }), - { doc }, - ) - const checkerCtx = CheckerContext.create( - mockProjectData({ symbols, ...project }), - { doc, src }, - ) - const result = parser(src, parserCtx) - if (result !== Failure) { - checker(result, { ...checkerCtx, context: '' }) - } - - return { - node: result === Failure ? 'FAILURE' : result, - parserErrors: parserCtx.err.dump(), - checkerErrors: checkerCtx.err.dump(), - } -} - -export function testGrid( - suites: { content: string }[], - checkers: { name: string; checker: JsonChecker }[], -) { - for (const { name, checker } of checkers) { - describe(name, () => { - for (const { content } of suites) { - it(`Check "${showWhitespaceGlyph(content)}"`, () => { - snapshot(testChecker(checker, content)) - }) - } - }) - } -} - export function testCompleter( completer: Completer, text: string,