@spyglassmc/mcdoc 0.3.16 → 0.3.18
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.
|
@@ -6,9 +6,11 @@ const idValidator = validator.alternatives(validator.map(validator.string, v =>
|
|
|
6
6
|
tags: validator.optional(validator.options('allowed', 'implicit', 'required')),
|
|
7
7
|
definition: validator.optional(validator.boolean),
|
|
8
8
|
prefix: validator.optional(validator.options('!')),
|
|
9
|
+
path: validator.optional(validator.string),
|
|
9
10
|
empty: validator.optional(validator.options('allowed')),
|
|
11
|
+
exclude: validator.optional(validator.alternatives(validator.map(validator.string, v => [v]), validator.list(validator.string))),
|
|
10
12
|
}), () => ({}));
|
|
11
|
-
function getResourceLocationOptions({ registry, tags, definition }, requireCanonical, ctx, typeDef) {
|
|
13
|
+
function getResourceLocationOptions({ registry, tags, definition, path }, requireCanonical, ctx, typeDef) {
|
|
12
14
|
if (!registry) {
|
|
13
15
|
if (typeDef?.kind === 'enum' && typeDef.enumKind === 'string') {
|
|
14
16
|
return {
|
|
@@ -28,24 +30,20 @@ function getResourceLocationOptions({ registry, tags, definition }, requireCanon
|
|
|
28
30
|
registry = `tag/${registry}`;
|
|
29
31
|
}
|
|
30
32
|
if (tags === 'allowed' || tags === 'required') {
|
|
31
|
-
if (core.TaggableResourceLocationCategory.is(registry)) {
|
|
32
|
-
return {
|
|
33
|
-
category: registry,
|
|
34
|
-
requireCanonical,
|
|
35
|
-
allowTag: true,
|
|
36
|
-
requireTag: tags === 'required',
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else if (core.ResourceLocationCategory.is(registry)) {
|
|
41
33
|
return {
|
|
42
34
|
category: registry,
|
|
43
35
|
requireCanonical,
|
|
44
|
-
|
|
36
|
+
allowTag: true,
|
|
37
|
+
requireTag: tags === 'required',
|
|
38
|
+
implicitPath: path,
|
|
45
39
|
};
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
return {
|
|
42
|
+
category: registry,
|
|
43
|
+
requireCanonical,
|
|
44
|
+
usageType: definition ? 'definition' : 'reference',
|
|
45
|
+
implicitPath: path,
|
|
46
|
+
};
|
|
49
47
|
}
|
|
50
48
|
const integerValidator = validator.alternatives(validator.tree({
|
|
51
49
|
min: validator.optional(validator.number),
|
|
@@ -122,7 +120,17 @@ export function registerBuiltinAttributes(meta) {
|
|
|
122
120
|
if (config.prefix) {
|
|
123
121
|
return core.prefixed({ prefix: config.prefix, child: resourceLocation })(src, ctx);
|
|
124
122
|
}
|
|
125
|
-
|
|
123
|
+
const node = resourceLocation(src, ctx);
|
|
124
|
+
if (config.exclude) {
|
|
125
|
+
const resourceLocation = core.ResourceLocationNode.toString(node, 'full');
|
|
126
|
+
for (const e of config.exclude ?? []) {
|
|
127
|
+
const excluded = core.ResourceLocation.lengthen(e);
|
|
128
|
+
if (resourceLocation === excluded) {
|
|
129
|
+
ctx.err.report(localize('not-allowed-here', localeQuote(excluded)), node, 2 /* core.ErrorSeverity.Warning */);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return node;
|
|
126
134
|
};
|
|
127
135
|
},
|
|
128
136
|
stringMocker: (config, typeDef, ctx) => {
|
|
@@ -202,5 +210,25 @@ export function registerBuiltinAttributes(meta) {
|
|
|
202
210
|
};
|
|
203
211
|
},
|
|
204
212
|
});
|
|
213
|
+
registerAttribute(meta, 'regex_pattern', () => undefined, {
|
|
214
|
+
checker: (_, typeDef) => {
|
|
215
|
+
if (typeDef.kind !== 'literal' || typeDef.value.kind !== 'string') {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
const pattern = typeDef.value.value;
|
|
219
|
+
return (node, ctx) => {
|
|
220
|
+
try {
|
|
221
|
+
RegExp(pattern);
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
const message = e instanceof Error ? e.message : `${e}`;
|
|
225
|
+
const error = message
|
|
226
|
+
.replace(/^Invalid regular expression: /, '')
|
|
227
|
+
.replace(/^\/.+\/: /, '');
|
|
228
|
+
ctx.err.report(localize('invalid-regex-pattern', error), node, 2);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
});
|
|
205
233
|
}
|
|
206
234
|
//# sourceMappingURL=builtin.js.map
|
|
@@ -10,6 +10,7 @@ export declare function tree<C extends {
|
|
|
10
10
|
}>(properties: {
|
|
11
11
|
[K in keyof C]: McdocAttributeValidator<C[K]>;
|
|
12
12
|
}): McdocAttributeValidator<C>;
|
|
13
|
+
export declare function list<C extends core.Returnable>(itemValidator: McdocAttributeValidator<C>): McdocAttributeValidator<C[]>;
|
|
13
14
|
export declare function optional<C extends core.Returnable>(validator: McdocAttributeValidator<C>): McdocAttributeValidator<C | undefined>;
|
|
14
15
|
export declare function map<C extends core.Returnable, D extends core.Returnable>(validator: McdocAttributeValidator<C>, mapper: (value: C) => D | typeof core.Failure): McdocAttributeValidator<D>;
|
|
15
16
|
export declare function alternatives<C extends core.Returnable>(...validators: McdocAttributeValidator<C>[]): McdocAttributeValidator<C>;
|
|
@@ -59,6 +59,22 @@ export function tree(properties) {
|
|
|
59
59
|
return result;
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
export function list(itemValidator) {
|
|
63
|
+
return (value, ctx) => {
|
|
64
|
+
if (value?.kind !== 'tree') {
|
|
65
|
+
return core.Failure;
|
|
66
|
+
}
|
|
67
|
+
const result = [];
|
|
68
|
+
for (const element of Object.values(value.values)) {
|
|
69
|
+
const item = itemValidator(element, ctx);
|
|
70
|
+
if (item === core.Failure) {
|
|
71
|
+
return core.Failure;
|
|
72
|
+
}
|
|
73
|
+
result.push(item);
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
62
78
|
export function optional(validator) {
|
|
63
79
|
return (value, ctx) => {
|
|
64
80
|
const config = validator(value, ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/mcdoc",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/SpyglassMC/Spyglass/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@spyglassmc/core": "0.4.
|
|
29
|
-
"@spyglassmc/locales": "0.3.
|
|
28
|
+
"@spyglassmc/core": "0.4.15",
|
|
29
|
+
"@spyglassmc/locales": "0.3.9"
|
|
30
30
|
}
|
|
31
31
|
}
|