mcbe-leveldb 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Changelog.md +27 -0
- package/LevelUtils.js.map +1 -1
- package/LevelUtils.ts +30 -32
- package/README.md +13 -0
- package/nbtSchemas.js +221 -120
- package/nbtSchemas.js.map +1 -1
- package/nbtSchemas.ts +812 -309
- package/package.json +1 -2
package/nbtSchemas.js
CHANGED
|
@@ -2290,9 +2290,9 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
2290
2290
|
},
|
|
2291
2291
|
$fragment: false,
|
|
2292
2292
|
},
|
|
2293
|
-
|
|
2294
|
-
id: "
|
|
2295
|
-
title: "The
|
|
2293
|
+
VillageDwellers: {
|
|
2294
|
+
id: "VillageDwellers",
|
|
2295
|
+
title: "The VillageDwellers schema.",
|
|
2296
2296
|
description: "The village dwellers data.",
|
|
2297
2297
|
type: "compound",
|
|
2298
2298
|
properties: {
|
|
@@ -2335,9 +2335,9 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
2335
2335
|
},
|
|
2336
2336
|
$fragment: false,
|
|
2337
2337
|
},
|
|
2338
|
-
|
|
2339
|
-
id: "
|
|
2340
|
-
title: "The
|
|
2338
|
+
VillageInfo: {
|
|
2339
|
+
id: "VillageInfo",
|
|
2340
|
+
title: "The VillageInfo schema.",
|
|
2341
2341
|
description: "The village info data.",
|
|
2342
2342
|
type: "compound",
|
|
2343
2343
|
properties: {
|
|
@@ -2401,9 +2401,9 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
2401
2401
|
},
|
|
2402
2402
|
$fragment: false,
|
|
2403
2403
|
},
|
|
2404
|
-
|
|
2405
|
-
id: "
|
|
2406
|
-
title: "The
|
|
2404
|
+
VillagePlayers: {
|
|
2405
|
+
id: "VillagePlayers",
|
|
2406
|
+
title: "The VillagePlayers schema.",
|
|
2407
2407
|
description: "The village players data.",
|
|
2408
2408
|
type: "compound",
|
|
2409
2409
|
properties: {
|
|
@@ -2413,9 +2413,9 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
2413
2413
|
},
|
|
2414
2414
|
$fragment: false,
|
|
2415
2415
|
},
|
|
2416
|
-
|
|
2417
|
-
id: "
|
|
2418
|
-
title: "The
|
|
2416
|
+
VillagePOI: {
|
|
2417
|
+
id: "VillagePOI",
|
|
2418
|
+
title: "The VillagePOI schema.",
|
|
2419
2419
|
description: "The village POIs data.",
|
|
2420
2420
|
type: "compound",
|
|
2421
2421
|
properties: {
|
|
@@ -7614,6 +7614,66 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
7614
7614
|
$fragment: false,
|
|
7615
7615
|
},
|
|
7616
7616
|
//#endregion
|
|
7617
|
+
//#region Custom NBT Schemas
|
|
7618
|
+
SubChunkPrefix: {
|
|
7619
|
+
id: "SubChunkPrefix",
|
|
7620
|
+
title: "The SubChunkPrefix schema.",
|
|
7621
|
+
description: "A custom schema for the NBT structure used by the custom parser and serializer for the SubChunkPrefix content type.",
|
|
7622
|
+
type: "compound",
|
|
7623
|
+
required: ["version", "layerCount", "layers"],
|
|
7624
|
+
properties: {
|
|
7625
|
+
version: {
|
|
7626
|
+
type: "byte",
|
|
7627
|
+
enum: [
|
|
7628
|
+
{
|
|
7629
|
+
type: "byte",
|
|
7630
|
+
value: 0x08,
|
|
7631
|
+
},
|
|
7632
|
+
{
|
|
7633
|
+
type: "byte",
|
|
7634
|
+
value: 0x09,
|
|
7635
|
+
},
|
|
7636
|
+
],
|
|
7637
|
+
},
|
|
7638
|
+
layerCount: {
|
|
7639
|
+
type: "byte",
|
|
7640
|
+
},
|
|
7641
|
+
layers: {
|
|
7642
|
+
type: "list",
|
|
7643
|
+
items: {
|
|
7644
|
+
$ref: "SubChunkPrefixLayer",
|
|
7645
|
+
},
|
|
7646
|
+
},
|
|
7647
|
+
subChunkIndex: {
|
|
7648
|
+
type: "byte",
|
|
7649
|
+
},
|
|
7650
|
+
},
|
|
7651
|
+
$fragment: false,
|
|
7652
|
+
},
|
|
7653
|
+
SubChunkPrefixLayer: {
|
|
7654
|
+
id: "SubChunkPrefixLayer",
|
|
7655
|
+
title: "The SubChunkPrefixLayer schema.",
|
|
7656
|
+
description: "A custom schema for the NBT structure used by the custom parser and serializer for the SubChunkPrefix content type.",
|
|
7657
|
+
type: "compound",
|
|
7658
|
+
required: ["storageVersion", "palette", "block_indices"],
|
|
7659
|
+
properties: {
|
|
7660
|
+
storageVersion: {
|
|
7661
|
+
type: "byte",
|
|
7662
|
+
},
|
|
7663
|
+
palette: {
|
|
7664
|
+
type: "compound",
|
|
7665
|
+
additionalProperties: { $ref: "Block" },
|
|
7666
|
+
},
|
|
7667
|
+
block_indices: {
|
|
7668
|
+
type: "list",
|
|
7669
|
+
items: {
|
|
7670
|
+
type: "int",
|
|
7671
|
+
},
|
|
7672
|
+
},
|
|
7673
|
+
},
|
|
7674
|
+
$fragment: true,
|
|
7675
|
+
},
|
|
7676
|
+
//#endregion
|
|
7617
7677
|
}, {
|
|
7618
7678
|
/**
|
|
7619
7679
|
* This is an alias of {@link nbtSchemas.PlayerClient}, this only exists because it is what it is called on the Minecraft Wiki, so it is here for the Minecraft Wiki data to schema converter.
|
|
@@ -7624,6 +7684,12 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
7624
7684
|
key: "PlayerClient",
|
|
7625
7685
|
description: "The players data.",
|
|
7626
7686
|
},
|
|
7687
|
+
/**
|
|
7688
|
+
* This is an alias of {@link nbtSchemas.Entity_Player}.
|
|
7689
|
+
*/
|
|
7690
|
+
Player: {
|
|
7691
|
+
key: "Entity_Player",
|
|
7692
|
+
},
|
|
7627
7693
|
/**
|
|
7628
7694
|
* This is an alias of {@link nbtSchemas.TickingArea}, this only exists because it is what it is called on the Minecraft Wiki, so it is here for the Minecraft Wiki data to schema converter.
|
|
7629
7695
|
*
|
|
@@ -7632,6 +7698,38 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
7632
7698
|
Tickingarea: {
|
|
7633
7699
|
key: "TickingArea",
|
|
7634
7700
|
},
|
|
7701
|
+
/**
|
|
7702
|
+
* This is an alias of {@link nbtSchemas.VillageDwellers}, this only exists because it is what it is called on the Minecraft Wiki, so it is here for the Minecraft Wiki data to schema converter.
|
|
7703
|
+
*
|
|
7704
|
+
* @deprecated Use {@link nbtSchemas.VillageDwellers} instead.
|
|
7705
|
+
*/
|
|
7706
|
+
VILLAGE_DWELLERS: {
|
|
7707
|
+
key: "VillageDwellers",
|
|
7708
|
+
},
|
|
7709
|
+
/**
|
|
7710
|
+
* This is an alias of {@link nbtSchemas.VillageInfo}, this only exists because it is what it is called on the Minecraft Wiki, so it is here for the Minecraft Wiki data to schema converter.
|
|
7711
|
+
*
|
|
7712
|
+
* @deprecated Use {@link nbtSchemas.VillageInfo} instead.
|
|
7713
|
+
*/
|
|
7714
|
+
VILLAGE_INFO: {
|
|
7715
|
+
key: "VillageInfo",
|
|
7716
|
+
},
|
|
7717
|
+
/**
|
|
7718
|
+
* This is an alias of {@link nbtSchemas.VillagePlayers}, this only exists because it is what it is called on the Minecraft Wiki, so it is here for the Minecraft Wiki data to schema converter.
|
|
7719
|
+
*
|
|
7720
|
+
* @deprecated Use {@link nbtSchemas.VillagePlayers} instead.
|
|
7721
|
+
*/
|
|
7722
|
+
VILLAGE_PLAYERS: {
|
|
7723
|
+
key: "VillagePlayers",
|
|
7724
|
+
},
|
|
7725
|
+
/**
|
|
7726
|
+
* This is an alias of {@link nbtSchemas.VillagePOI}, this only exists because it is what it is called on the Minecraft Wiki, so it is here for the Minecraft Wiki data to schema converter.
|
|
7727
|
+
*
|
|
7728
|
+
* @deprecated Use {@link nbtSchemas.VillagePOI} instead.
|
|
7729
|
+
*/
|
|
7730
|
+
VILLAGE_POI: {
|
|
7731
|
+
key: "VillagePOI",
|
|
7732
|
+
},
|
|
7635
7733
|
});
|
|
7636
7734
|
NBTSchemas.GenericPrismarineJSONNBTSchema = {
|
|
7637
7735
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
@@ -8122,7 +8220,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8122
8220
|
const defVal = formatValue(schema.default);
|
|
8123
8221
|
// Put on new line if contains non-alphanumeric characters
|
|
8124
8222
|
if (/[^a-zA-Z0-9_.=+-]/.test(defVal) && !/^"[a-zA-Z0-9_.=+-\s]+"$/.test(defVal)) {
|
|
8125
|
-
parts.push(`@default\n${
|
|
8223
|
+
parts.push(`@default\n${defVal}`);
|
|
8126
8224
|
}
|
|
8127
8225
|
else {
|
|
8128
8226
|
parts.push(`@default ${defVal}`);
|
|
@@ -8133,7 +8231,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8133
8231
|
for (const ex of schema.examples) {
|
|
8134
8232
|
const exVal = formatValue(ex);
|
|
8135
8233
|
if (/[^a-zA-Z0-9_]/.test(exVal)) {
|
|
8136
|
-
parts.push(`@example\n${
|
|
8234
|
+
parts.push(`@example\n${exVal}`);
|
|
8137
8235
|
}
|
|
8138
8236
|
else {
|
|
8139
8237
|
parts.push(`@example ${exVal}`);
|
|
@@ -8144,7 +8242,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8144
8242
|
if (schema.enum && Array.isArray(schema.enum)) {
|
|
8145
8243
|
parts.push(`@enum ${formatEnum(schema.enum)}`);
|
|
8146
8244
|
if (schema.enumDescriptions && Array.isArray(schema.enumDescriptions)) {
|
|
8147
|
-
parts.push(`@enumDescriptions\n${
|
|
8245
|
+
parts.push(`@enumDescriptions\n${schema.enumDescriptions
|
|
8148
8246
|
.map((d, i) => `- ${schema.enum[i]?.value !== undefined ? `\`${schema.enum[i]?.value}\`` : `UNKNOWN_ENUM_MEMBER_${i}`}: ${d}`)
|
|
8149
8247
|
.join("\n")}`);
|
|
8150
8248
|
}
|
|
@@ -8157,7 +8255,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8157
8255
|
.map((l) => `${indent} * ${l}`);
|
|
8158
8256
|
return `${indent}/**\n${lines.join("\n")}\n${indent} */\n`;
|
|
8159
8257
|
}
|
|
8160
|
-
function refToType(ref, indent, opts = {}, ctx = { helperTypes: [], helperCounter: 0 }) {
|
|
8258
|
+
function refToType(ref, indent, opts = {}, ctx = { helperTypes: [], helperCounter: 0 }, additionalInformation = {}) {
|
|
8161
8259
|
const refLookup = opts.refLookup ?? NBTSchemas.nbtSchemas;
|
|
8162
8260
|
const resolvedRef = (typeof ref === "boolean"
|
|
8163
8261
|
? ref
|
|
@@ -8201,7 +8299,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8201
8299
|
if (resolvedRef.length === 0)
|
|
8202
8300
|
return { type: "never", value: "never" };
|
|
8203
8301
|
// tuple-style list -> union of each item
|
|
8204
|
-
const children = resolvedRef.map((r) => refToType(r, indent, opts, ctx));
|
|
8302
|
+
const children = resolvedRef.map((r) => refToType(r, indent, opts, ctx, { ...additionalInformation, isListChild: true }));
|
|
8205
8303
|
const allSameType = children.every((c) => c.type === children[0].type);
|
|
8206
8304
|
if (allSameType) {
|
|
8207
8305
|
// collapse into single type wrapping array of values
|
|
@@ -8228,9 +8326,9 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8228
8326
|
}
|
|
8229
8327
|
}
|
|
8230
8328
|
// single schema
|
|
8231
|
-
return schemaToBuiltType(resolvedRef, indent, opts, ctx);
|
|
8329
|
+
return schemaToBuiltType(resolvedRef, indent, opts, ctx, additionalInformation);
|
|
8232
8330
|
}
|
|
8233
|
-
function schemaToBuiltType(schema, indent, opts, ctx) {
|
|
8331
|
+
function schemaToBuiltType(schema, indent, opts, ctx, additionalInformation = {}) {
|
|
8234
8332
|
const refLookup = opts.refLookup ?? NBTSchemas.nbtSchemas;
|
|
8235
8333
|
const st = schema.type;
|
|
8236
8334
|
const mainSchemaRefName = schema.$ref
|
|
@@ -8245,14 +8343,15 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8245
8343
|
let allOfRefTypes = opts.inlineRefs ?? false
|
|
8246
8344
|
? undefined
|
|
8247
8345
|
: typeof schema === "object" && schema.$ref !== undefined && mainSchemaRefName !== undefined /* && schema.$ref in refLookup */
|
|
8248
|
-
? [mainSchemaRefName]
|
|
8346
|
+
? [mainSchemaRefName + (additionalInformation.isListChild ? '["value"]' : "")]
|
|
8249
8347
|
: undefined;
|
|
8250
8348
|
if (!(opts.inlineRefs ?? false) && schema.allOf !== undefined) {
|
|
8251
8349
|
const refAllOfs = schema.allOf.filter((ref) => typeof ref === "object" && !!ref.$ref);
|
|
8252
8350
|
if (refAllOfs.length > 0) {
|
|
8253
8351
|
allOfRefTypes ??= [];
|
|
8254
8352
|
for (const refAllOf of refAllOfs) {
|
|
8255
|
-
allOfRefTypes.push(resolveSchemaRefName(refAllOf.$ref, !(opts.inlineRefs ?? false), opts)
|
|
8353
|
+
allOfRefTypes.push(resolveSchemaRefName(refAllOf.$ref, !(opts.inlineRefs ?? false), opts) +
|
|
8354
|
+
(additionalInformation.isListChild ? '["value"]' : ""));
|
|
8256
8355
|
}
|
|
8257
8356
|
}
|
|
8258
8357
|
}
|
|
@@ -8262,7 +8361,8 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8262
8361
|
if (refOneOfs.length > 0) {
|
|
8263
8362
|
oneOfRefTypes ??= [];
|
|
8264
8363
|
for (const refOneOf of refOneOfs) {
|
|
8265
|
-
oneOfRefTypes.push(resolveSchemaRefName(refOneOf.$ref, !(opts.inlineRefs ?? false), opts)
|
|
8364
|
+
oneOfRefTypes.push(resolveSchemaRefName(refOneOf.$ref, !(opts.inlineRefs ?? false), opts) +
|
|
8365
|
+
(additionalInformation.isListChild ? '["value"]' : ""));
|
|
8266
8366
|
}
|
|
8267
8367
|
}
|
|
8268
8368
|
}
|
|
@@ -8298,21 +8398,28 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8298
8398
|
if (resolvedSchema.properties) {
|
|
8299
8399
|
const compoundType = buildBuiltTypeForTag("compound", resolvedSchema, indent, opts, ctx);
|
|
8300
8400
|
return {
|
|
8301
|
-
type: "compound",
|
|
8401
|
+
type: '"compound"',
|
|
8302
8402
|
value: opts.inlineRefs ?? false
|
|
8303
|
-
? `(${compoundType.value})${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""}`
|
|
8304
|
-
: `(${compoundType.value})${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""}
|
|
8403
|
+
? `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(compoundType.value) ? "" : `(${compoundType.value})`}${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""}`
|
|
8404
|
+
: `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(compoundType.value) ? "" : `(${compoundType.value})`}${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""}`.replace(/^ & /, ""),
|
|
8405
|
+
};
|
|
8406
|
+
}
|
|
8407
|
+
if (!(opts.inlineRefs ?? false) && schema.$ref) {
|
|
8408
|
+
const refType = refLookup[resolveSchemaRefName(schema.$ref, false, opts)]
|
|
8409
|
+
?.type;
|
|
8410
|
+
return {
|
|
8411
|
+
type: typeof refType === "string" ? `"${refType}"` : "unknown",
|
|
8412
|
+
value: mainSchemaRefName + (additionalInformation.isListChild ? '["value"]' : ""),
|
|
8305
8413
|
};
|
|
8306
8414
|
}
|
|
8307
|
-
// BUG: This is not resolving $ref properties.
|
|
8308
8415
|
return { type: "unknown", value: "any" };
|
|
8309
8416
|
}
|
|
8310
8417
|
const builtType = buildBuiltTypeForTag(st, resolvedSchema, indent, opts, ctx);
|
|
8311
8418
|
return {
|
|
8312
8419
|
type: builtType.type,
|
|
8313
8420
|
value: opts.inlineRefs ?? false
|
|
8314
|
-
? `(${builtType.value})${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""}
|
|
8315
|
-
: `(${builtType.value})${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""}
|
|
8421
|
+
? `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(builtType.value) ? "" : `(${builtType.value})`}${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""}`.replace(/^ & /, "")
|
|
8422
|
+
: `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(builtType.value) ? "" : `(${builtType.value})`}${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""}`.replace(/^ & /, ""),
|
|
8316
8423
|
};
|
|
8317
8424
|
}
|
|
8318
8425
|
function buildBuiltTypeForTag(tagType, schema, indent, opts, ctx) {
|
|
@@ -8387,7 +8494,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8387
8494
|
}
|
|
8388
8495
|
// homogeneous list
|
|
8389
8496
|
if (Array.isArray(items)) {
|
|
8390
|
-
const child = refToType(items, indent + "
|
|
8497
|
+
const child = refToType(items, indent + " ", opts, ctx);
|
|
8391
8498
|
function builtTypeValueToTupleList(value) {
|
|
8392
8499
|
return typeof value === "string"
|
|
8393
8500
|
? value
|
|
@@ -8408,7 +8515,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8408
8515
|
}
|
|
8409
8516
|
else {
|
|
8410
8517
|
// TO-DO: Test this, as it may not work correctly.
|
|
8411
|
-
const child = refToType(items, indent + "
|
|
8518
|
+
const child = refToType(items, indent + " ", opts, ctx, { isListChild: true });
|
|
8412
8519
|
function builtTypeValueToUnionList(value) {
|
|
8413
8520
|
return typeof value === "string"
|
|
8414
8521
|
? value
|
|
@@ -8428,7 +8535,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8428
8535
|
const comment = renderComment(childSchema, undefined, indent);
|
|
8429
8536
|
const required = parentReq.has(key) || childSchema.required === true;
|
|
8430
8537
|
const sep = required ? ":" : "?:";
|
|
8431
|
-
return comment + `${indent}${JSON.stringify(key)}${sep} ${schemaToType(childSchema, indent + "
|
|
8538
|
+
return comment + `${indent}${JSON.stringify(key)}${sep} ${schemaToType(childSchema, indent + " ", opts, ctx)};`;
|
|
8432
8539
|
});
|
|
8433
8540
|
const propLinesCount = lines.length;
|
|
8434
8541
|
if (schema.patternProperties) {
|
|
@@ -8463,7 +8570,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8463
8570
|
keyType = `\`${key.replaceAll("\\d+", "${number}")}\``;
|
|
8464
8571
|
break;
|
|
8465
8572
|
}
|
|
8466
|
-
found.push([keyType, schemaToType(value, indent + "
|
|
8573
|
+
found.push([keyType, schemaToType(value, indent + " ", opts, ctx)]);
|
|
8467
8574
|
}
|
|
8468
8575
|
for (const key of new Set(found.map(([key]) => key))) {
|
|
8469
8576
|
if (found.filter(([key2]) => key2 === key).length === 1) {
|
|
@@ -8483,7 +8590,15 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8483
8590
|
lines.push(`${propLinesCount > 0 ? `${indent}} & {\n` : ""}${indent}[key: string]: { type: any, value: any };`);
|
|
8484
8591
|
}
|
|
8485
8592
|
else {
|
|
8486
|
-
|
|
8593
|
+
const builtType = schemaToBuiltType(schema.additionalProperties, indent + " ", opts, ctx);
|
|
8594
|
+
if (schema.additionalProperties.$ref) {
|
|
8595
|
+
lines.push(`${propLinesCount > 0 ? `${indent}} & {\n` : ""}${indent}[key: string]: ${builtType.value};`);
|
|
8596
|
+
}
|
|
8597
|
+
else {
|
|
8598
|
+
lines.push(`${propLinesCount > 0 ? `${indent}} & {\n` : ""}${indent}[key: string]: ${builtType.value.includes("\n")
|
|
8599
|
+
? `{\n${indent}type: ${builtType.type},\n${indent}value: ${builtType.value}\n${indent}}`
|
|
8600
|
+
: `{ type: ${builtType.type}, value: ${builtType.value} }`};`);
|
|
8601
|
+
}
|
|
8487
8602
|
}
|
|
8488
8603
|
}
|
|
8489
8604
|
}
|
|
@@ -8561,100 +8676,86 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8561
8676
|
*/
|
|
8562
8677
|
function schemaToType(schema, indent = "s".repeat(4), opts = {}, ctx = { helperTypes: [], helperCounter: 0 }) {
|
|
8563
8678
|
const refLookup = opts.refLookup ?? NBTSchemas.nbtSchemas;
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8679
|
+
const st = schema.type;
|
|
8680
|
+
const mainSchemaRefName = schema.$ref
|
|
8681
|
+
? resolveSchemaRefName(schema.$ref, !(opts.inlineRefs ?? false), opts)
|
|
8682
|
+
: undefined;
|
|
8683
|
+
const resolvedSchema = opts.inlineRefs && schema.$ref && mainSchemaRefName && mainSchemaRefName in refLookup
|
|
8684
|
+
? {
|
|
8685
|
+
...refLookup[mainSchemaRefName],
|
|
8686
|
+
...schema,
|
|
8687
|
+
}
|
|
8688
|
+
: schema;
|
|
8689
|
+
let allOfRefTypes = opts.inlineRefs ?? false
|
|
8690
|
+
? undefined
|
|
8691
|
+
: typeof schema === "object" && schema.$ref !== undefined && mainSchemaRefName !== undefined /* && schema.$ref in refLookup */
|
|
8692
|
+
? [mainSchemaRefName]
|
|
8693
|
+
: undefined;
|
|
8694
|
+
if (!(opts.inlineRefs ?? false) && schema.allOf !== undefined) {
|
|
8695
|
+
const refAllOfs = schema.allOf.filter((ref) => typeof ref === "object" && !!ref.$ref);
|
|
8696
|
+
if (refAllOfs.length > 0) {
|
|
8697
|
+
allOfRefTypes ??= [];
|
|
8698
|
+
for (const refAllOf of refAllOfs) {
|
|
8699
|
+
allOfRefTypes.push(resolveSchemaRefName(refAllOf.$ref, !(opts.inlineRefs ?? false), opts));
|
|
8700
|
+
}
|
|
8701
|
+
}
|
|
8702
|
+
}
|
|
8703
|
+
let oneOfRefTypes = undefined;
|
|
8704
|
+
if (!(opts.inlineRefs ?? false) && schema.oneOf !== undefined) {
|
|
8705
|
+
const refOneOfs = schema.oneOf.filter((ref) => typeof ref === "object" && !!ref.$ref);
|
|
8706
|
+
if (refOneOfs.length > 0) {
|
|
8707
|
+
oneOfRefTypes ??= [];
|
|
8708
|
+
for (const refOneOf of refOneOfs) {
|
|
8709
|
+
oneOfRefTypes.push(resolveSchemaRefName(refOneOf.$ref, !(opts.inlineRefs ?? false), opts));
|
|
8710
|
+
}
|
|
8711
|
+
}
|
|
8568
8712
|
}
|
|
8569
|
-
const
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
// {}
|
|
8585
|
-
// )
|
|
8586
|
-
// : {}),
|
|
8587
|
-
...Object.fromEntries(Object.entries(schema).filter(([key]): boolean => key !== "$ref")),
|
|
8588
|
-
}
|
|
8589
|
-
: */
|
|
8590
|
-
{
|
|
8591
|
-
type: refLookup[schema.$ref].type,
|
|
8592
|
-
...Object.fromEntries(Object.entries(schema).filter(([key]) => key !== "$ref")),
|
|
8713
|
+
const inlineRefTypes = {
|
|
8714
|
+
allOf: [],
|
|
8715
|
+
oneOf: [],
|
|
8716
|
+
};
|
|
8717
|
+
if (opts.inlineRefs ?? false) {
|
|
8718
|
+
if (allOfRefTypes)
|
|
8719
|
+
for (const refType of allOfRefTypes) {
|
|
8720
|
+
const types = refLookup[refType].type ?? resolvedSchema.type;
|
|
8721
|
+
if (!types)
|
|
8722
|
+
continue;
|
|
8723
|
+
inlineRefTypes.allOf.push(Array.isArray(types)
|
|
8724
|
+
? types
|
|
8725
|
+
.map((t) => buildTypeForTag(t, refLookup[refType], indent, opts, ctx))
|
|
8726
|
+
.join("|")
|
|
8727
|
+
: buildTypeForTag(types, refLookup[refType], indent, opts, ctx));
|
|
8593
8728
|
}
|
|
8594
|
-
|
|
8595
|
-
|
|
8596
|
-
|
|
8597
|
-
|
|
8598
|
-
|
|
8599
|
-
|
|
8600
|
-
|
|
8601
|
-
|
|
8602
|
-
|
|
8603
|
-
|
|
8604
|
-
// inlineRefTypes.allOf.push(
|
|
8605
|
-
// Array.isArray(types)
|
|
8606
|
-
// ? types
|
|
8607
|
-
// .map((t: string): string =>
|
|
8608
|
-
// buildTypeForTag(t, refLookup[refType as keyof typeof refLookup] as NBTSubSchema, indent, opts, ctx)
|
|
8609
|
-
// )
|
|
8610
|
-
// .join("|")
|
|
8611
|
-
// : buildTypeForTag(types, refLookup[refType as keyof typeof refLookup] as NBTSubSchema, indent, opts, ctx)
|
|
8612
|
-
// );
|
|
8613
|
-
// }
|
|
8614
|
-
// if (oneOfRefTypes)
|
|
8615
|
-
// for (const refType of oneOfRefTypes) {
|
|
8616
|
-
// const types = (refLookup[refType as keyof typeof refLookup] as NBTSubSchema).type ?? schema.type;
|
|
8617
|
-
// if (!types) continue;
|
|
8618
|
-
// inlineRefTypes.oneOf.push(
|
|
8619
|
-
// Array.isArray(types)
|
|
8620
|
-
// ? types
|
|
8621
|
-
// .map((t: string): string =>
|
|
8622
|
-
// buildTypeForTag(t, refLookup[refType as keyof typeof refLookup] as NBTSubSchema, indent, opts, ctx)
|
|
8623
|
-
// )
|
|
8624
|
-
// .join("|")
|
|
8625
|
-
// : buildTypeForTag(types, refLookup[refType as keyof typeof refLookup] as NBTSubSchema, indent, opts, ctx)
|
|
8626
|
-
// );
|
|
8627
|
-
// }
|
|
8628
|
-
// }
|
|
8629
|
-
if (Array.isArray(resolvedSchema.type)) {
|
|
8630
|
-
const types = resolvedSchema.type.map((t) => {
|
|
8631
|
-
const built = buildTypeForTag(t, resolvedSchema, indent, opts, ctx);
|
|
8632
|
-
if (opts.emitHelperTypes) {
|
|
8633
|
-
const helperName = makeHelperName("NBT", ctx);
|
|
8634
|
-
ctx.helperTypes.push(`export type ${helperName} = ${built};`);
|
|
8635
|
-
return helperName;
|
|
8729
|
+
if (oneOfRefTypes)
|
|
8730
|
+
for (const refType of oneOfRefTypes) {
|
|
8731
|
+
const types = refLookup[refType].type ?? resolvedSchema.type;
|
|
8732
|
+
if (!types)
|
|
8733
|
+
continue;
|
|
8734
|
+
inlineRefTypes.oneOf.push(Array.isArray(types)
|
|
8735
|
+
? types
|
|
8736
|
+
.map((t) => buildTypeForTag(t, refLookup[refType], indent, opts, ctx))
|
|
8737
|
+
.join("|")
|
|
8738
|
+
: buildTypeForTag(types, refLookup[refType], indent, opts, ctx));
|
|
8636
8739
|
}
|
|
8637
|
-
return built;
|
|
8638
|
-
});
|
|
8639
|
-
return `(${types.join(" | ")})`;
|
|
8640
|
-
// if (opts.inlineRefs ?? false) {
|
|
8641
|
-
// return `(${types.join(" | ")})${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${
|
|
8642
|
-
// inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""
|
|
8643
|
-
// }`;
|
|
8644
|
-
// } else {
|
|
8645
|
-
// return `(${types.join(" | ")})${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${
|
|
8646
|
-
// oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""
|
|
8647
|
-
// }`;
|
|
8648
|
-
// }
|
|
8649
8740
|
}
|
|
8650
|
-
const st = resolvedSchema.type;
|
|
8651
8741
|
if (!st) {
|
|
8652
8742
|
if (resolvedSchema.properties) {
|
|
8653
|
-
|
|
8743
|
+
const compoundType = buildTypeForTag("compound", resolvedSchema, indent, opts, ctx);
|
|
8744
|
+
return opts.inlineRefs ?? false
|
|
8745
|
+
? `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(compoundType) ? "" : `(${compoundType})`}${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""}`
|
|
8746
|
+
: `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(compoundType) ? "" : `(${compoundType})`}${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""}`.replace(/^ & /, "");
|
|
8747
|
+
}
|
|
8748
|
+
if (!(opts.inlineRefs ?? false) && schema.$ref) {
|
|
8749
|
+
const refType = refLookup[resolveSchemaRefName(schema.$ref, false, opts)]
|
|
8750
|
+
?.type;
|
|
8751
|
+
return mainSchemaRefName;
|
|
8654
8752
|
}
|
|
8655
|
-
return
|
|
8753
|
+
return `{ type: unknown, value: any }`;
|
|
8656
8754
|
}
|
|
8657
|
-
|
|
8755
|
+
const builtType = buildTypeForTag(st, resolvedSchema, indent, opts, ctx);
|
|
8756
|
+
return opts.inlineRefs ?? false
|
|
8757
|
+
? `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(builtType) ? "" : `(${builtType})`}${inlineRefTypes.allOf ? ` & ${inlineRefTypes.allOf.join(" & ")}` : ""}${inlineRefTypes.oneOf ? ` & (${inlineRefTypes.oneOf.join(" | ")})` : ""}`.replace(/^ & /, "")
|
|
8758
|
+
: `${(allOfRefTypes || oneOfRefTypes) && /^\{\s*\}$/.test(builtType) ? "" : `(${builtType})`}${allOfRefTypes ? ` & ${allOfRefTypes.join(" & ")}` : ""}${oneOfRefTypes ? ` & (${oneOfRefTypes.join(" | ")})` : ""}`.replace(/^ & /, "");
|
|
8658
8759
|
}
|
|
8659
8760
|
/**
|
|
8660
8761
|
* Generates a TypeScript type from a top-level {@link NBTSchema} or {@link NBTSchemaFragment}.
|
|
@@ -8782,7 +8883,7 @@ however when the corresponding block in the block layer is broken, this block ge
|
|
|
8782
8883
|
// if (schema.additionalProperties === true) {
|
|
8783
8884
|
// extendsLines.push(`Omit<{ [key: string]: { type: any, value: any } }, never>`);
|
|
8784
8885
|
// } else {
|
|
8785
|
-
// extendsLines.push(`Omit<{ [key: string]: ${schemaToType(schema.additionalProperties, indent + "
|
|
8886
|
+
// extendsLines.push(`Omit<{ [key: string]: ${schemaToType(schema.additionalProperties, indent + " ", opts, ctx)} }, never>`);
|
|
8786
8887
|
// }
|
|
8787
8888
|
// }
|
|
8788
8889
|
// } else if (opts.allowExtraProps) {
|