@jsprismarine/predicates 0.25.0 → 0.26.0-unstable-20261124210956
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/reference.d.ts.map +1 -1
- package/dist/reference.js +1 -0
- package/dist/reference.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @jsprismarine/predicates
|
|
2
2
|
|
|
3
|
+
## 0.26.0-unstable-20261124210956
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3680](https://github.com/JSPrismarine/JSPrismarine/pull/3680) [`ab601c6`](https://github.com/JSPrismarine/JSPrismarine/commit/ab601c6924c6f6fa754434e4225e93461fcef1f5) Thanks [@filiphsps](https://github.com/filiphsps)! - A predicate or item modifier file that holds a list now composes its entries when another file names it by id, as Java reads it. Before, the list was refused as not an object.
|
|
8
|
+
- Updated dependencies []:
|
|
9
|
+
- @jsprismarine/errors@0.26.0-unstable-20261124210956
|
|
10
|
+
|
|
3
11
|
## 0.25.0
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/reference.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.d.ts","sources":["../src/reference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,YAC3B,aAAa,EACb,eAAe,EACf,YAAY,EACZ,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,EACX,QAAQ,EACR,aAAa,CACP,CAAC;AAEX,yCAAyC;AACzC,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,aAAa,YACtB,MAAM,EACN,OAAO,EACP,aAAa,E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YAAY,eACR,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,KAAK,CAAC,GAAG,SAAS,KACtE,CAAC,EA0CH,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SACvB,OAAO,YACJ,eAAe,WAChB,YAAY,eACR,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,KAAK,CAAC,GAAG,SAAS,KACtE,CAAC,GAAG,SAMN,CAAC"}
|
package/dist/reference.js
CHANGED
|
@@ -122,6 +122,7 @@ var parseComposed = (value, registry, context, parseInline) => {
|
|
|
122
122
|
}
|
|
123
123
|
context.visiting.add(key);
|
|
124
124
|
try {
|
|
125
|
+
if (Array.isArray(element)) return parseComposed(element, registry, context.atReference(id), parseInline);
|
|
125
126
|
const parsed = parseInline(element, context.atReference(id));
|
|
126
127
|
return parsed === void 0 ? [] : [parsed];
|
|
127
128
|
} finally {
|
package/dist/reference.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference.js","names":[],"sources":["../src/reference.ts"],"sourcesContent":["import { namespaced } from './json';\nimport type { ParseContext } from './parse';\n\n/**\n * The eight registries 26.3 made composable: a field of one of these types\n * takes an inline value, a namespaced id, a list, or a `#tag`.\n */\nexport const ELEMENT_REGISTRIES = [\n 'advancement',\n 'item_modifier',\n 'loot_table',\n 'context_int_provider',\n 'context_float_provider',\n 'predicate',\n 'recipe',\n 'slot_source'\n] as const;\n\n/** One of {@link ELEMENT_REGISTRIES}. */\nexport type ElementRegistry = (typeof ELEMENT_REGISTRIES)[number];\n\n/**\n * Registries this package only ever reads tags from. A field like an item\n * predicate's `items` names members, not elements, so a `#tag` there expands\n * into identifiers rather than JSON.\n */\nexport const ID_REGISTRIES = [\n 'item',\n 'block',\n 'entity_type',\n 'enchantment',\n 'fluid',\n 'damage_type',\n 'mob_effect',\n 'worldgen/biome',\n 'worldgen/structure',\n 'villager_type'\n] as const;\n\n/** One of {@link ID_REGISTRIES}. */\nexport type IdRegistry = (typeof ID_REGISTRIES)[number];\n\n/** Any registry a reference can point into. */\nexport type ReferenceRegistry = ElementRegistry | IdRegistry;\n\n/**\n * How the evaluator reaches the rest of the datapack. Both members are\n * optional so a host that only uses inline grammar needs no resolver at all;\n * a reference with nothing to resolve it reports an error.\n */\nexport interface ReferenceResolver {\n /** Returns the parsed JSON of a registry element, or undefined when the id is unknown. */\n element?(registry: ElementRegistry, id: string): unknown;\n /** Returns the namespaced member ids of a tag, or undefined when the tag is unknown. */\n tag?(registry: ReferenceRegistry, id: string): readonly string[] | undefined;\n}\n\n/** Whether a JSON string is a tag reference rather than an element id. */\nexport const isTagReference = (value: string): boolean => value.startsWith('#');\n\nconst expandTag = (\n reference: string,\n registry: ReferenceRegistry,\n context: ParseContext,\n report: boolean,\n depth: number\n): readonly string[] => {\n const id = namespaced(reference.slice(1));\n const key = `#${registry}/${id}`;\n if (context.visiting.has(key)) {\n context.error(`tag reference ${reference} is cyclic`);\n return [];\n }\n if (depth > 32) {\n context.error(`tag reference ${reference} nests too deeply`);\n return [];\n }\n if (!context.resolver?.tag) {\n if (report) context.error(`cannot resolve ${reference}: the parse options carry no tag resolver`);\n return [];\n }\n\n const members = context.resolver.tag(registry, id);\n if (!members) {\n if (report) context.error(`unknown ${registry} tag ${reference}`);\n return [];\n }\n\n context.visiting.add(key);\n try {\n return members.flatMap((member) =>\n isTagReference(member) ? expandTag(member, registry, context, report, depth + 1) : [namespaced(member)]\n );\n } finally {\n context.visiting.delete(key);\n }\n};\n\n/**\n * What the member form of the composition rule names: the identifiers written\n * out directly or reached through a tag, and the tag names themselves.\n */\nexport interface MemberSet {\n readonly ids: ReadonlySet<string>;\n /** Namespaced tag names without the leading `#`, kept so a subject that carries its own tags still matches. */\n readonly tags: readonly string[];\n}\n\n/**\n * Resolves the member form of 26.3's composition rule: a single namespaced id,\n * a list of ids, or a `#tag`. Use it for fields that name registry members\n * rather than elements, such as an item predicate's `items`. A tag that no\n * resolver can expand is not an error, because the subject may know its own\n * tags.\n */\nexport const resolveMembers = (value: unknown, registry: ReferenceRegistry, context: ParseContext): MemberSet => {\n const ids = new Set<string>();\n const tags: string[] = [];\n\n const visit = (entry: unknown, at: ParseContext): void => {\n if (entry === undefined || entry === null) return;\n if (Array.isArray(entry)) {\n entry.forEach((nested, index) => visit(nested, at.at(index)));\n return;\n }\n if (typeof entry !== 'string') {\n at.error(`expected a ${registry} id, a list of ids or a tag`);\n return;\n }\n if (isTagReference(entry)) {\n tags.push(namespaced(entry.slice(1)));\n for (const id of expandTag(entry, registry, at, false, 0)) ids.add(id);\n return;\n }\n ids.add(namespaced(entry));\n };\n\n visit(value, context);\n return { ids, tags };\n};\n\n/**\n * Parses one field under 26.3's composition rule, which the plan calls the\n * clearest rule in the format: the value may be an inline object, a namespaced\n * id of a registry element, a list mixing both, or a `#tag` naming elements.\n * Every predicate, item modifier and provider field goes through here.\n *\n * @param parseInline - Compiles one inline value; called once per resolved element.\n * @returns One compiled value per element, in the order the composition names them.\n */\nexport const parseComposed = <T>(\n value: unknown,\n registry: ElementRegistry,\n context: ParseContext,\n parseInline: (value: unknown, context: ParseContext) => T | undefined\n): T[] => {\n if (value === undefined || value === null) return [];\n\n if (Array.isArray(value)) {\n return value.flatMap((entry, index) => parseComposed(entry, registry, context.at(index), parseInline));\n }\n\n if (typeof value === 'string') {\n const ids = isTagReference(value) ? expandTag(value, registry, context, true, 0) : [namespaced(value)];\n return ids.flatMap((id) => {\n const key = `${registry}/${id}`;\n if (context.visiting.has(key)) {\n context.error(`${registry} reference ${id} is cyclic`);\n return [];\n }\n if (!context.resolver?.element) {\n context.error(`cannot resolve ${id}: the parse options carry no element resolver`);\n return [];\n }\n\n const element = context.resolver.element(registry, id);\n if (element === undefined) {\n context.error(`unknown ${registry} ${id}`);\n return [];\n }\n\n context.visiting.add(key);\n try {\n const parsed = parseInline(element, context.atReference(id));\n return parsed === undefined ? [] : [parsed];\n } finally {\n context.visiting.delete(key);\n }\n });\n }\n\n const parsed = parseInline(value, context);\n return parsed === undefined ? [] : [parsed];\n};\n\n/**\n * The single-element form of {@link parseComposed}. Reports when a field that\n * takes one element is given several.\n */\nexport const parseComposedOne = <T>(\n value: unknown,\n registry: ElementRegistry,\n context: ParseContext,\n parseInline: (value: unknown, context: ParseContext) => T | undefined\n): T | undefined => {\n const parsed = parseComposed(value, registry, context, parseInline);\n if (parsed.length > 1) {\n context.error(`expected one ${registry} but the composition resolved to ${parsed.length}`);\n }\n return parsed[0];\n};\n"],"mappings":";;;;;;AAOA,IAAa,qBAAqB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;;AAUA,IAAa,gBAAgB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAqBA,IAAa,kBAAkB,UAA2B,MAAM,WAAW,GAAG;AAE9E,IAAM,aACF,WACA,UACA,SACA,QACA,UACoB;CACpB,MAAM,KAAK,WAAW,UAAU,MAAM,CAAC,CAAC;CACxC,MAAM,MAAM,IAAI,SAAS,GAAG;CAC5B,IAAI,QAAQ,SAAS,IAAI,GAAG,GAAG;EAC3B,QAAQ,MAAM,iBAAiB,UAAU,WAAW;EACpD,OAAO,CAAC;CACZ;CACA,IAAI,QAAQ,IAAI;EACZ,QAAQ,MAAM,iBAAiB,UAAU,kBAAkB;EAC3D,OAAO,CAAC;CACZ;CACA,IAAI,CAAC,QAAQ,UAAU,KAAK;EACxB,IAAI,QAAQ,QAAQ,MAAM,kBAAkB,UAAU,0CAA0C;EAChG,OAAO,CAAC;CACZ;CAEA,MAAM,UAAU,QAAQ,SAAS,IAAI,UAAU,EAAE;CACjD,IAAI,CAAC,SAAS;EACV,IAAI,QAAQ,QAAQ,MAAM,WAAW,SAAS,OAAO,WAAW;EAChE,OAAO,CAAC;CACZ;CAEA,QAAQ,SAAS,IAAI,GAAG;CACxB,IAAI;EACA,OAAO,QAAQ,SAAS,WACpB,eAAe,MAAM,IAAI,UAAU,QAAQ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SAAS,IAAI,GAAG,GAAG;GAC3B,QAAQ,MAAM,GAAG,SAAS,aAAa,GAAG,WAAW;GACrD,OAAO,CAAC;EACZ;EACA,IAAI,CAAC,QAAQ,UAAU,SAAS;GAC5B,QAAQ,MAAM,kBAAkB,GAAG,8CAA8C;GACjF,OAAO,CAAC;EACZ;EAEA,MAAM,UAAU,QAAQ,SAAS,QAAQ,UAAU,EAAE;EACrD,IAAI,YAAY,KAAA,GAAW;GACvB,QAAQ,MAAM,WAAW,SAAS,GAAG,IAAI;GACzC,OAAO,CAAC;EACZ;EAEA,QAAQ,SAAS,IAAI,GAAG;EACxB,IAAI;GACA,MAAM,SAAS,YAAY,SAAS,QAAQ,YAAY,EAAE,CAAC;GAC3D,OAAO,WAAW,KAAA,IAAY,CAAC,IAAI,CAAC,MAAM;EAC9C,UAAU;GACN,QAAQ,SAAS,OAAO,GAAG;EAC/B;CACJ,CAAC;CAGL,MAAM,SAAS,YAAY,OAAO,OAAO;CACzC,OAAO,WAAW,KAAA,IAAY,CAAC,IAAI,CAAC,MAAM;AAC9C;;;;;AAMA,IAAa,oBACT,OACA,UACA,SACA,gBACgB;CAChB,MAAM,SAAS,cAAc,OAAO,UAAU,SAAS,WAAW;CAClE,IAAI,OAAO,SAAS,GAChB,QAAQ,MAAM,gBAAgB,SAAS,mCAAmC,OAAO,QAAQ;CAE7F,OAAO,OAAO;AAClB"}
|
|
1
|
+
{"version":3,"file":"reference.js","names":[],"sources":["../src/reference.ts"],"sourcesContent":["import { namespaced } from './json';\nimport type { ParseContext } from './parse';\n\n/**\n * The eight registries 26.3 made composable: a field of one of these types\n * takes an inline value, a namespaced id, a list, or a `#tag`.\n */\nexport const ELEMENT_REGISTRIES = [\n 'advancement',\n 'item_modifier',\n 'loot_table',\n 'context_int_provider',\n 'context_float_provider',\n 'predicate',\n 'recipe',\n 'slot_source'\n] as const;\n\n/** One of {@link ELEMENT_REGISTRIES}. */\nexport type ElementRegistry = (typeof ELEMENT_REGISTRIES)[number];\n\n/**\n * Registries this package only ever reads tags from. A field like an item\n * predicate's `items` names members, not elements, so a `#tag` there expands\n * into identifiers rather than JSON.\n */\nexport const ID_REGISTRIES = [\n 'item',\n 'block',\n 'entity_type',\n 'enchantment',\n 'fluid',\n 'damage_type',\n 'mob_effect',\n 'worldgen/biome',\n 'worldgen/structure',\n 'villager_type'\n] as const;\n\n/** One of {@link ID_REGISTRIES}. */\nexport type IdRegistry = (typeof ID_REGISTRIES)[number];\n\n/** Any registry a reference can point into. */\nexport type ReferenceRegistry = ElementRegistry | IdRegistry;\n\n/**\n * How the evaluator reaches the rest of the datapack. Both members are\n * optional so a host that only uses inline grammar needs no resolver at all;\n * a reference with nothing to resolve it reports an error.\n */\nexport interface ReferenceResolver {\n /** Returns the parsed JSON of a registry element, or undefined when the id is unknown. */\n element?(registry: ElementRegistry, id: string): unknown;\n /** Returns the namespaced member ids of a tag, or undefined when the tag is unknown. */\n tag?(registry: ReferenceRegistry, id: string): readonly string[] | undefined;\n}\n\n/** Whether a JSON string is a tag reference rather than an element id. */\nexport const isTagReference = (value: string): boolean => value.startsWith('#');\n\nconst expandTag = (\n reference: string,\n registry: ReferenceRegistry,\n context: ParseContext,\n report: boolean,\n depth: number\n): readonly string[] => {\n const id = namespaced(reference.slice(1));\n const key = `#${registry}/${id}`;\n if (context.visiting.has(key)) {\n context.error(`tag reference ${reference} is cyclic`);\n return [];\n }\n if (depth > 32) {\n context.error(`tag reference ${reference} nests too deeply`);\n return [];\n }\n if (!context.resolver?.tag) {\n if (report) context.error(`cannot resolve ${reference}: the parse options carry no tag resolver`);\n return [];\n }\n\n const members = context.resolver.tag(registry, id);\n if (!members) {\n if (report) context.error(`unknown ${registry} tag ${reference}`);\n return [];\n }\n\n context.visiting.add(key);\n try {\n return members.flatMap((member) =>\n isTagReference(member) ? expandTag(member, registry, context, report, depth + 1) : [namespaced(member)]\n );\n } finally {\n context.visiting.delete(key);\n }\n};\n\n/**\n * What the member form of the composition rule names: the identifiers written\n * out directly or reached through a tag, and the tag names themselves.\n */\nexport interface MemberSet {\n readonly ids: ReadonlySet<string>;\n /** Namespaced tag names without the leading `#`, kept so a subject that carries its own tags still matches. */\n readonly tags: readonly string[];\n}\n\n/**\n * Resolves the member form of 26.3's composition rule: a single namespaced id,\n * a list of ids, or a `#tag`. Use it for fields that name registry members\n * rather than elements, such as an item predicate's `items`. A tag that no\n * resolver can expand is not an error, because the subject may know its own\n * tags.\n */\nexport const resolveMembers = (value: unknown, registry: ReferenceRegistry, context: ParseContext): MemberSet => {\n const ids = new Set<string>();\n const tags: string[] = [];\n\n const visit = (entry: unknown, at: ParseContext): void => {\n if (entry === undefined || entry === null) return;\n if (Array.isArray(entry)) {\n entry.forEach((nested, index) => visit(nested, at.at(index)));\n return;\n }\n if (typeof entry !== 'string') {\n at.error(`expected a ${registry} id, a list of ids or a tag`);\n return;\n }\n if (isTagReference(entry)) {\n tags.push(namespaced(entry.slice(1)));\n for (const id of expandTag(entry, registry, at, false, 0)) ids.add(id);\n return;\n }\n ids.add(namespaced(entry));\n };\n\n visit(value, context);\n return { ids, tags };\n};\n\n/**\n * Parses one field under 26.3's composition rule, which the plan calls the\n * clearest rule in the format: the value may be an inline object, a namespaced\n * id of a registry element, a list mixing both, or a `#tag` naming elements.\n * Every predicate, item modifier and provider field goes through here.\n *\n * @param parseInline - Compiles one inline value; called once per resolved element.\n * @returns One compiled value per element, in the order the composition names them.\n */\nexport const parseComposed = <T>(\n value: unknown,\n registry: ElementRegistry,\n context: ParseContext,\n parseInline: (value: unknown, context: ParseContext) => T | undefined\n): T[] => {\n if (value === undefined || value === null) return [];\n\n if (Array.isArray(value)) {\n return value.flatMap((entry, index) => parseComposed(entry, registry, context.at(index), parseInline));\n }\n\n if (typeof value === 'string') {\n const ids = isTagReference(value) ? expandTag(value, registry, context, true, 0) : [namespaced(value)];\n return ids.flatMap((id) => {\n const key = `${registry}/${id}`;\n if (context.visiting.has(key)) {\n context.error(`${registry} reference ${id} is cyclic`);\n return [];\n }\n if (!context.resolver?.element) {\n context.error(`cannot resolve ${id}: the parse options carry no element resolver`);\n return [];\n }\n\n const element = context.resolver.element(registry, id);\n if (element === undefined) {\n context.error(`unknown ${registry} ${id}`);\n return [];\n }\n\n context.visiting.add(key);\n try {\n // A file may hold a list as readily as an inline field, as an `item_modifier`\n // file of several functions does, and it composes the same way.\n if (Array.isArray(element))\n return parseComposed(element, registry, context.atReference(id), parseInline);\n const parsed = parseInline(element, context.atReference(id));\n return parsed === undefined ? [] : [parsed];\n } finally {\n context.visiting.delete(key);\n }\n });\n }\n\n const parsed = parseInline(value, context);\n return parsed === undefined ? [] : [parsed];\n};\n\n/**\n * The single-element form of {@link parseComposed}. Reports when a field that\n * takes one element is given several.\n */\nexport const parseComposedOne = <T>(\n value: unknown,\n registry: ElementRegistry,\n context: ParseContext,\n parseInline: (value: unknown, context: ParseContext) => T | undefined\n): T | undefined => {\n const parsed = parseComposed(value, registry, context, parseInline);\n if (parsed.length > 1) {\n context.error(`expected one ${registry} but the composition resolved to ${parsed.length}`);\n }\n return parsed[0];\n};\n"],"mappings":";;;;;;AAOA,IAAa,qBAAqB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;;;;;AAUA,IAAa,gBAAgB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAqBA,IAAa,kBAAkB,UAA2B,MAAM,WAAW,GAAG;AAE9E,IAAM,aACF,WACA,UACA,SACA,QACA,UACoB;CACpB,MAAM,KAAK,WAAW,UAAU,MAAM,CAAC,CAAC;CACxC,MAAM,MAAM,IAAI,SAAS,GAAG;CAC5B,IAAI,QAAQ,SAAS,IAAI,GAAG,GAAG;EAC3B,QAAQ,MAAM,iBAAiB,UAAU,WAAW;EACpD,OAAO,CAAC;CACZ;CACA,IAAI,QAAQ,IAAI;EACZ,QAAQ,MAAM,iBAAiB,UAAU,kBAAkB;EAC3D,OAAO,CAAC;CACZ;CACA,IAAI,CAAC,QAAQ,UAAU,K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gBAAgB,SAAS,mCAAmC,OAAO,QAAQ;CAE7F,OAAO,OAAO;AAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsprismarine/predicates",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0-unstable-20261124210956",
|
|
4
4
|
"description": "Java Edition predicate, item modifier and value provider evaluator for loot, advancements and enchantments.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"vitest": "5.1.1"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@jsprismarine/errors": "0.
|
|
52
|
+
"@jsprismarine/errors": "0.26.0-unstable-20261124210956"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"clean": "rimraf dist jsp *.tsbuildinfo vite.config.ts.timestamp-* .tsup .turbo",
|