@spyglassmc/core 0.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.
Files changed (186) hide show
  1. package/README.md +10 -0
  2. package/lib/common/Heap.d.ts +1 -0
  3. package/lib/common/Heap.js +2 -0
  4. package/lib/common/index.d.ts +2 -0
  5. package/lib/common/index.js +14 -0
  6. package/lib/common/util.d.ts +120 -0
  7. package/lib/common/util.js +292 -0
  8. package/lib/index.d.ts +8 -0
  9. package/lib/index.js +20 -0
  10. package/lib/node/AstNode.d.ts +64 -0
  11. package/lib/node/AstNode.js +108 -0
  12. package/lib/node/BooleanNode.d.ts +13 -0
  13. package/lib/node/BooleanNode.js +20 -0
  14. package/lib/node/CommentNode.d.ts +12 -0
  15. package/lib/node/CommentNode.js +11 -0
  16. package/lib/node/ErrorNode.d.ts +8 -0
  17. package/lib/node/ErrorNode.js +12 -0
  18. package/lib/node/FileNode.d.ts +21 -0
  19. package/lib/node/FileNode.js +11 -0
  20. package/lib/node/FloatNode.d.ts +13 -0
  21. package/lib/node/FloatNode.js +21 -0
  22. package/lib/node/IntegerNode.d.ts +13 -0
  23. package/lib/node/IntegerNode.js +20 -0
  24. package/lib/node/ListNode.d.ts +15 -0
  25. package/lib/node/ListNode.js +11 -0
  26. package/lib/node/LiteralNode.d.ts +19 -0
  27. package/lib/node/LiteralNode.js +22 -0
  28. package/lib/node/LongNode.d.ts +13 -0
  29. package/lib/node/LongNode.js +20 -0
  30. package/lib/node/RecordNode.d.ts +20 -0
  31. package/lib/node/RecordNode.js +11 -0
  32. package/lib/node/ResourceLocationNode.d.ts +41 -0
  33. package/lib/node/ResourceLocationNode.js +65 -0
  34. package/lib/node/Sequence.d.ts +22 -0
  35. package/lib/node/Sequence.js +11 -0
  36. package/lib/node/StringNode.d.ts +63 -0
  37. package/lib/node/StringNode.js +43 -0
  38. package/lib/node/SymbolNode.d.ts +21 -0
  39. package/lib/node/SymbolNode.js +22 -0
  40. package/lib/node/TableNode.d.ts +17 -0
  41. package/lib/node/TableNode.js +11 -0
  42. package/lib/node/index.d.ts +16 -0
  43. package/lib/node/index.js +28 -0
  44. package/lib/parser/Parser.d.ts +16 -0
  45. package/lib/parser/Parser.js +5 -0
  46. package/lib/parser/boolean.d.ts +4 -0
  47. package/lib/parser/boolean.js +11 -0
  48. package/lib/parser/comment.d.ts +12 -0
  49. package/lib/parser/comment.js +34 -0
  50. package/lib/parser/empty.d.ts +3 -0
  51. package/lib/parser/empty.js +7 -0
  52. package/lib/parser/error.d.ts +8 -0
  53. package/lib/parser/error.js +22 -0
  54. package/lib/parser/file.d.ts +9 -0
  55. package/lib/parser/file.js +37 -0
  56. package/lib/parser/float.d.ts +33 -0
  57. package/lib/parser/float.js +57 -0
  58. package/lib/parser/index.d.ts +17 -0
  59. package/lib/parser/index.js +36 -0
  60. package/lib/parser/integer.d.ts +33 -0
  61. package/lib/parser/integer.js +46 -0
  62. package/lib/parser/list.d.ts +12 -0
  63. package/lib/parser/list.js +70 -0
  64. package/lib/parser/literal.d.ts +5 -0
  65. package/lib/parser/literal.js +41 -0
  66. package/lib/parser/long.d.ts +33 -0
  67. package/lib/parser/long.js +50 -0
  68. package/lib/parser/record.d.ts +22 -0
  69. package/lib/parser/record.js +97 -0
  70. package/lib/parser/resourceLocation.d.ts +4 -0
  71. package/lib/parser/resourceLocation.js +67 -0
  72. package/lib/parser/string.d.ts +18 -0
  73. package/lib/parser/string.js +129 -0
  74. package/lib/parser/symbol.d.ts +12 -0
  75. package/lib/parser/symbol.js +33 -0
  76. package/lib/parser/table.d.ts +22 -0
  77. package/lib/parser/table.js +97 -0
  78. package/lib/parser/util.d.ts +134 -0
  79. package/lib/parser/util.js +224 -0
  80. package/lib/processor/ColorInfoProvider.d.ts +87 -0
  81. package/lib/processor/ColorInfoProvider.js +141 -0
  82. package/lib/processor/InlayHintProvider.d.ts +8 -0
  83. package/lib/processor/InlayHintProvider.js +3 -0
  84. package/lib/processor/SignatureHelpProvider.d.ts +18 -0
  85. package/lib/processor/SignatureHelpProvider.js +3 -0
  86. package/lib/processor/checker/Checker.d.ts +7 -0
  87. package/lib/processor/checker/Checker.js +7 -0
  88. package/lib/processor/checker/builtin.d.ts +23 -0
  89. package/lib/processor/checker/builtin.js +83 -0
  90. package/lib/processor/checker/index.d.ts +3 -0
  91. package/lib/processor/checker/index.js +28 -0
  92. package/lib/processor/colorizer/Colorizer.d.ts +23 -0
  93. package/lib/processor/colorizer/Colorizer.js +70 -0
  94. package/lib/processor/colorizer/builtin.d.ts +17 -0
  95. package/lib/processor/colorizer/builtin.js +84 -0
  96. package/lib/processor/colorizer/index.d.ts +3 -0
  97. package/lib/processor/colorizer/index.js +28 -0
  98. package/lib/processor/completer/Completer.d.ts +75 -0
  99. package/lib/processor/completer/Completer.js +92 -0
  100. package/lib/processor/completer/builtin.d.ts +30 -0
  101. package/lib/processor/completer/builtin.js +172 -0
  102. package/lib/processor/completer/index.d.ts +3 -0
  103. package/lib/processor/completer/index.js +28 -0
  104. package/lib/processor/formatter/Formatter.d.ts +6 -0
  105. package/lib/processor/formatter/Formatter.js +19 -0
  106. package/lib/processor/formatter/builtin.d.ts +15 -0
  107. package/lib/processor/formatter/builtin.js +60 -0
  108. package/lib/processor/formatter/index.d.ts +3 -0
  109. package/lib/processor/formatter/index.js +28 -0
  110. package/lib/processor/index.d.ts +10 -0
  111. package/lib/processor/index.js +22 -0
  112. package/lib/processor/linter/Linter.d.ts +4 -0
  113. package/lib/processor/linter/Linter.js +3 -0
  114. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +4 -0
  115. package/lib/processor/linter/builtin/undeclaredSymbol.js +73 -0
  116. package/lib/processor/linter/builtin.d.ts +15 -0
  117. package/lib/processor/linter/builtin.js +120 -0
  118. package/lib/processor/linter/index.d.ts +3 -0
  119. package/lib/processor/linter/index.js +28 -0
  120. package/lib/processor/util.d.ts +17 -0
  121. package/lib/processor/util.js +32 -0
  122. package/lib/service/CacheService.d.ts +54 -0
  123. package/lib/service/CacheService.js +195 -0
  124. package/lib/service/CommandExecutor.d.ts +3 -0
  125. package/lib/service/CommandExecutor.js +7 -0
  126. package/lib/service/Config.d.ts +218 -0
  127. package/lib/service/Config.js +264 -0
  128. package/lib/service/Context.d.ts +143 -0
  129. package/lib/service/Context.js +143 -0
  130. package/lib/service/Dependency.d.ts +10 -0
  131. package/lib/service/Dependency.js +11 -0
  132. package/lib/service/Downloader.d.ts +67 -0
  133. package/lib/service/Downloader.js +185 -0
  134. package/lib/service/ErrorReporter.d.ts +27 -0
  135. package/lib/service/ErrorReporter.js +49 -0
  136. package/lib/service/FileService.d.ts +96 -0
  137. package/lib/service/FileService.js +224 -0
  138. package/lib/service/Hover.d.ts +10 -0
  139. package/lib/service/Hover.js +16 -0
  140. package/lib/service/Logger.d.ts +31 -0
  141. package/lib/service/Logger.js +30 -0
  142. package/lib/service/MetaRegistry.d.ts +106 -0
  143. package/lib/service/MetaRegistry.js +192 -0
  144. package/lib/service/Operations.d.ts +8 -0
  145. package/lib/service/Operations.js +26 -0
  146. package/lib/service/Profiler.d.ts +33 -0
  147. package/lib/service/Profiler.js +76 -0
  148. package/lib/service/Project.d.ts +173 -0
  149. package/lib/service/Project.js +593 -0
  150. package/lib/service/Service.d.ts +55 -0
  151. package/lib/service/Service.js +207 -0
  152. package/lib/service/SymbolLocations.d.ts +17 -0
  153. package/lib/service/SymbolLocations.js +16 -0
  154. package/lib/service/SymbolRegistrar.d.ts +5 -0
  155. package/lib/service/SymbolRegistrar.js +3 -0
  156. package/lib/service/fileUtil.d.ts +121 -0
  157. package/lib/service/fileUtil.js +268 -0
  158. package/lib/service/index.d.ts +18 -0
  159. package/lib/service/index.js +33 -0
  160. package/lib/source/IndexMap.d.ts +16 -0
  161. package/lib/source/IndexMap.js +46 -0
  162. package/lib/source/LanguageError.d.ts +27 -0
  163. package/lib/source/LanguageError.js +15 -0
  164. package/lib/source/Location.d.ts +19 -0
  165. package/lib/source/Location.js +25 -0
  166. package/lib/source/Offset.d.ts +13 -0
  167. package/lib/source/Offset.js +25 -0
  168. package/lib/source/Position.d.ts +23 -0
  169. package/lib/source/Position.js +43 -0
  170. package/lib/source/PositionRange.d.ts +38 -0
  171. package/lib/source/PositionRange.js +83 -0
  172. package/lib/source/Range.d.ts +68 -0
  173. package/lib/source/Range.js +155 -0
  174. package/lib/source/Source.d.ts +110 -0
  175. package/lib/source/Source.js +222 -0
  176. package/lib/source/index.d.ts +9 -0
  177. package/lib/source/index.js +21 -0
  178. package/lib/symbol/Symbol.d.ts +219 -0
  179. package/lib/symbol/Symbol.js +324 -0
  180. package/lib/symbol/SymbolUtil.d.ts +407 -0
  181. package/lib/symbol/SymbolUtil.js +880 -0
  182. package/lib/symbol/UriBinder.d.ts +3 -0
  183. package/lib/symbol/UriBinder.js +3 -0
  184. package/lib/symbol/index.d.ts +4 -0
  185. package/lib/symbol/index.js +16 -0
  186. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # `@spyglassmc/core`
2
+
3
+ ![banner](https://raw.githubusercontent.com/SpyglassMC/logo/main/banner.png)
4
+
5
+ [![Discord](https://img.shields.io/discord/666020457568403505?logo=discord&style=flat-square)](https://discord.gg/EbdseuS)
6
+ [![npm](https://img.shields.io/npm/v/@spyglassmc/core.svg?logo=npm&style=flat-square)](https://npmjs.com/package/@spyglassmc/core)
7
+ [![License](https://img.shields.io/github/license/SpyglassMC/Spyglass.svg?style=flat-square)](https://github.com/SpyglassMC/Spyglass/blob/master/LICENSE)
8
+ [![Gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style=flat-square)](https://gitmoji.carloscuesta.me/)
9
+
10
+ This package is the core of the Spyglass Project. It defines the structure of a parser or validator, and provides the `SpyglassCore` class to help manage those things.
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=Heap.d.ts.map
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=Heap.js.map
@@ -0,0 +1,2 @@
1
+ export * from './util';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./util"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,120 @@
1
+ /// <reference types="node" />
2
+ import externalBinarySearch from 'binary-search';
3
+ import type { URL as Uri } from 'url';
4
+ import type { ProcessorContext, RootUriString } from '../service';
5
+ export { URL as Uri } from 'url';
6
+ /**
7
+ * @param getCacheKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
8
+ * The result of this function will be used as the key to cache the `Promise`. By default the first element in the argument
9
+ * list will be used.
10
+ *
11
+ * This is a decorator for async methods. Decorated methods will return the same `Promise` for
12
+ * the same arguments, provided that the cached `Promise` is still pending.
13
+ */
14
+ export declare function CachePromise(getCacheKey?: (args: any[]) => any): MethodDecorator;
15
+ /**
16
+ * This is a decorator for async methods. Decorated methods will return the same `Promise` no matter what.
17
+ */
18
+ export declare const SingletonPromise: MethodDecorator;
19
+ /**
20
+ * @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
21
+ * The result of this function will be used as the key to cache the `Timeout`. By default the first element in the argument
22
+ * list will be used.
23
+ *
24
+ * Decorated methods will be scheduled to run after `ms` milliseconds. The timer will reset when the method is called again.
25
+ */
26
+ export declare function Delay(ms: number, getKey?: (args: any[]) => any): MethodDecorator;
27
+ export declare namespace SpyglassUri {
28
+ const Protocol = "spyglassmc:";
29
+ namespace Archive {
30
+ const Hostname = "archive";
31
+ function get(archiveUri: string): RootUriString;
32
+ function get(archiveUri: string, pathInArchive: string): string;
33
+ function is(uri: Uri): boolean;
34
+ /**
35
+ * @throws When `uri` has the wrong protocol or hostname.
36
+ */
37
+ function decode(uri: Uri): {
38
+ archiveUri: string;
39
+ pathInArchive: string;
40
+ };
41
+ }
42
+ }
43
+ export declare type FullResourceLocation = `${string}:${string}`;
44
+ export interface ResourceLocation {
45
+ isTag: boolean;
46
+ namespace: string | undefined;
47
+ path: readonly string[];
48
+ }
49
+ export declare namespace ResourceLocation {
50
+ /**
51
+ * The prefix for tags.
52
+ */
53
+ const TagPrefix = "#";
54
+ /**
55
+ * The seperator of namespace and path.
56
+ */
57
+ const NamespacePathSep = ":";
58
+ /**
59
+ * The seperator between different path segments.
60
+ */
61
+ const PathSep = "/";
62
+ const DefaultNamespace = "minecraft";
63
+ function lengthen(value: string): FullResourceLocation;
64
+ function shorten(value: string): string;
65
+ }
66
+ /**
67
+ * @returns The string value decoded from the buffer according to UTF-8.
68
+ * Byte order mark is correctly removed.
69
+ */
70
+ export declare function bufferToString(buffer: Buffer): string;
71
+ export declare function stringToBase64(str: string): string;
72
+ export declare function base64ToString(base64: string): string;
73
+ /**
74
+ * @throws
75
+ */
76
+ export declare function getSha1(data: string | Buffer): string;
77
+ export declare function isErrorCode(e: unknown, code: string): boolean;
78
+ export declare function isEnoent(e: unknown): boolean;
79
+ export declare type Arrayable<T> = T | readonly T[];
80
+ export declare namespace Arrayable {
81
+ function is<T>(value: unknown, isT: (value: unknown) => value is T): value is Arrayable<T>;
82
+ function toArray<T>(value: Arrayable<T>): T[];
83
+ }
84
+ export declare namespace TypePredicates {
85
+ function isString(value: unknown): value is string;
86
+ }
87
+ export declare function promisifyAsyncIterable<T, U>(iterable: AsyncIterable<T>, joiner: (chunks: T[]) => U): Promise<U>;
88
+ export declare const unzip: (buffer: Buffer) => Promise<Buffer>;
89
+ export declare const zip: (buffer: Buffer) => Promise<Buffer>;
90
+ export declare function parseGzippedJson<T>(buffer: Buffer): Promise<T>;
91
+ export declare function isObject(value: unknown): value is Exclude<object, Array<any>>;
92
+ export declare function merge<T extends Record<string, any>>(a: T, b: Record<string, any>): T;
93
+ export declare type Lazy<T> = T | Lazy.ComplexLazy<T>;
94
+ export declare namespace Lazy {
95
+ const LazyDiscriminator: unique symbol;
96
+ export type UnresolvedLazy<T> = {
97
+ discriminator: typeof LazyDiscriminator;
98
+ getter: (this: void) => T;
99
+ };
100
+ export type ResolvedLazy<T> = {
101
+ discriminator: typeof LazyDiscriminator;
102
+ getter: (this: void) => T;
103
+ value: T;
104
+ };
105
+ export type ComplexLazy<T> = ResolvedLazy<T> | UnresolvedLazy<T>;
106
+ export function create<T>(getter: (this: void) => T): UnresolvedLazy<T>;
107
+ export function isComplex<T = any>(lazy: any): lazy is ComplexLazy<T>;
108
+ export function isUnresolved<T = any>(lazy: any): lazy is UnresolvedLazy<T>;
109
+ export function resolve<T>(lazy: Lazy<T>): T;
110
+ export {};
111
+ }
112
+ /**
113
+ * @param ids An array of block/fluid IDs, with or without the namespace.
114
+ * @returns A map from state names to the corresponding sets of values. The first element in the value array is the default
115
+ * value for that state.
116
+ */
117
+ export declare function getStates(category: 'block' | 'fluid', ids: readonly string[], ctx: ProcessorContext): Record<string, string[]>;
118
+ export declare const binarySearch: typeof externalBinarySearch;
119
+ export declare function isIterable(value: unknown): value is Iterable<unknown>;
120
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isIterable = exports.binarySearch = exports.getStates = exports.Lazy = exports.merge = exports.isObject = exports.parseGzippedJson = exports.zip = exports.unzip = exports.promisifyAsyncIterable = exports.TypePredicates = exports.Arrayable = exports.isEnoent = exports.isErrorCode = exports.getSha1 = exports.base64ToString = exports.stringToBase64 = exports.bufferToString = exports.ResourceLocation = exports.SpyglassUri = exports.Delay = exports.SingletonPromise = exports.CachePromise = exports.Uri = void 0;
7
+ const binary_search_1 = __importDefault(require("binary-search"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const rfdc_1 = __importDefault(require("rfdc"));
10
+ const util_1 = require("util");
11
+ const zlib_1 = __importDefault(require("zlib"));
12
+ var url_1 = require("url");
13
+ Object.defineProperty(exports, "Uri", { enumerable: true, get: function () { return url_1.URL; } });
14
+ /**
15
+ * @param getCacheKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
16
+ * The result of this function will be used as the key to cache the `Promise`. By default the first element in the argument
17
+ * list will be used.
18
+ *
19
+ * This is a decorator for async methods. Decorated methods will return the same `Promise` for
20
+ * the same arguments, provided that the cached `Promise` is still pending.
21
+ */
22
+ function CachePromise(getCacheKey = args => args[0]) {
23
+ return (_target, _key, descripter) => {
24
+ const promises = new Map();
25
+ const decoratedMethod = descripter.value;
26
+ // The `function` syntax is used to preserve `this` context from the decorated method.
27
+ descripter.value = function (...args) {
28
+ const cacheKey = getCacheKey(args);
29
+ if (promises.has(cacheKey)) {
30
+ return promises.get(cacheKey);
31
+ }
32
+ const ans = decoratedMethod.apply(this, args)
33
+ .then(ans => (promises.delete(cacheKey), ans), e => (promises.delete(cacheKey), Promise.reject(e)));
34
+ promises.set(cacheKey, ans);
35
+ return ans;
36
+ };
37
+ return descripter;
38
+ };
39
+ }
40
+ exports.CachePromise = CachePromise;
41
+ /**
42
+ * This is a decorator for async methods. Decorated methods will return the same `Promise` no matter what.
43
+ */
44
+ const SingletonPromise = (_target, _key, descripter) => {
45
+ let promise;
46
+ const decoratedMethod = descripter.value;
47
+ // The `function` syntax is used to preserve `this` context from the decorated method.
48
+ descripter.value = function (...args) {
49
+ return promise ?? (promise = decoratedMethod.apply(this, args));
50
+ };
51
+ return descripter;
52
+ };
53
+ exports.SingletonPromise = SingletonPromise;
54
+ /**
55
+ * @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
56
+ * The result of this function will be used as the key to cache the `Timeout`. By default the first element in the argument
57
+ * list will be used.
58
+ *
59
+ * Decorated methods will be scheduled to run after `ms` milliseconds. The timer will reset when the method is called again.
60
+ */
61
+ function Delay(ms, getKey = args => args[0]) {
62
+ return (_target, _key, descripter) => {
63
+ const timeouts = new Map();
64
+ const decoratedMethod = descripter.value;
65
+ // The `function` syntax is used to preserve `this` context from the decorated method.
66
+ descripter.value = function (...args) {
67
+ const key = getKey(args);
68
+ if (timeouts.has(key)) {
69
+ clearTimeout(timeouts.get(key));
70
+ }
71
+ timeouts.set(key, setTimeout(() => {
72
+ timeouts.delete(key);
73
+ decoratedMethod.apply(this, args);
74
+ }, ms));
75
+ };
76
+ return descripter;
77
+ };
78
+ }
79
+ exports.Delay = Delay;
80
+ var SpyglassUri;
81
+ (function (SpyglassUri) {
82
+ SpyglassUri.Protocol = 'spyglassmc:';
83
+ let Archive;
84
+ (function (Archive) {
85
+ Archive.Hostname = 'archive';
86
+ function get(archiveUri, pathInArchive = '') {
87
+ return `${SpyglassUri.Protocol}//${Archive.Hostname}/${encodeURIComponent(archiveUri)}/${pathInArchive.replace(/\\/g, '/')}`;
88
+ }
89
+ Archive.get = get;
90
+ function is(uri) {
91
+ return uri.protocol === SpyglassUri.Protocol && uri.hostname === Archive.Hostname;
92
+ }
93
+ Archive.is = is;
94
+ /**
95
+ * @throws When `uri` has the wrong protocol or hostname.
96
+ */
97
+ function decode(uri) {
98
+ if (uri.protocol !== SpyglassUri.Protocol) {
99
+ throw new Error(`Expected protocol “${SpyglassUri.Protocol}” in “${uri.toString()}”`);
100
+ }
101
+ if (uri.hostname !== Archive.Hostname) {
102
+ throw new Error(`Expected hostname “${Archive.Hostname}” in “${uri.toString()}”`);
103
+ }
104
+ // Ex. `pathname`: `/QzpcYS50YXIuZ3o=/foo/bar.json`
105
+ const paths = uri.pathname.split('/');
106
+ return {
107
+ archiveUri: decodeURIComponent(paths[1]),
108
+ pathInArchive: paths.slice(2).join('/'),
109
+ };
110
+ }
111
+ Archive.decode = decode;
112
+ })(Archive = SpyglassUri.Archive || (SpyglassUri.Archive = {}));
113
+ })(SpyglassUri = exports.SpyglassUri || (exports.SpyglassUri = {}));
114
+ var ResourceLocation;
115
+ (function (ResourceLocation) {
116
+ /**
117
+ * The prefix for tags.
118
+ */
119
+ ResourceLocation.TagPrefix = '#';
120
+ /**
121
+ * The seperator of namespace and path.
122
+ */
123
+ ResourceLocation.NamespacePathSep = ':';
124
+ /**
125
+ * The seperator between different path segments.
126
+ */
127
+ ResourceLocation.PathSep = '/';
128
+ ResourceLocation.DefaultNamespace = 'minecraft';
129
+ function lengthen(value) {
130
+ switch (value.indexOf(ResourceLocation.NamespacePathSep)) {
131
+ case -1:
132
+ return `${ResourceLocation.DefaultNamespace}${ResourceLocation.NamespacePathSep}${value}`;
133
+ case 0:
134
+ return `${ResourceLocation.DefaultNamespace}${value}`;
135
+ default:
136
+ return value;
137
+ }
138
+ }
139
+ ResourceLocation.lengthen = lengthen;
140
+ function shorten(value) {
141
+ return value.replace(/^(?:minecraft)?:/, '');
142
+ }
143
+ ResourceLocation.shorten = shorten;
144
+ })(ResourceLocation = exports.ResourceLocation || (exports.ResourceLocation = {}));
145
+ /**
146
+ * @returns The string value decoded from the buffer according to UTF-8.
147
+ * Byte order mark is correctly removed.
148
+ */
149
+ function bufferToString(buffer) {
150
+ const ans = buffer.toString('utf-8');
151
+ if (ans.charCodeAt(0) === 0xFEFF) {
152
+ return ans.slice(1);
153
+ }
154
+ return ans;
155
+ }
156
+ exports.bufferToString = bufferToString;
157
+ function stringToBase64(str) {
158
+ return Buffer.from(str).toString('base64');
159
+ }
160
+ exports.stringToBase64 = stringToBase64;
161
+ function base64ToString(base64) {
162
+ return Buffer.from(base64, 'base64').toString('utf-8');
163
+ }
164
+ exports.base64ToString = base64ToString;
165
+ /**
166
+ * @throws
167
+ */
168
+ function getSha1(data) {
169
+ const hash = crypto_1.default.createHash('sha1');
170
+ hash.update(data);
171
+ return hash.digest('hex');
172
+ }
173
+ exports.getSha1 = getSha1;
174
+ function isErrorCode(e, code) {
175
+ return e instanceof Error && e.code === code;
176
+ }
177
+ exports.isErrorCode = isErrorCode;
178
+ function isEnoent(e) {
179
+ return isErrorCode(e, 'ENOENT');
180
+ }
181
+ exports.isEnoent = isEnoent;
182
+ var Arrayable;
183
+ (function (Arrayable) {
184
+ function is(value, isT) {
185
+ return Array.isArray(value)
186
+ ? value.every(e => isT(e))
187
+ : isT(value);
188
+ }
189
+ Arrayable.is = is;
190
+ function toArray(value) {
191
+ return Array.isArray(value) ? value : [value];
192
+ }
193
+ Arrayable.toArray = toArray;
194
+ })(Arrayable = exports.Arrayable || (exports.Arrayable = {}));
195
+ var TypePredicates;
196
+ (function (TypePredicates) {
197
+ function isString(value) {
198
+ return typeof value === 'string';
199
+ }
200
+ TypePredicates.isString = isString;
201
+ })(TypePredicates = exports.TypePredicates || (exports.TypePredicates = {}));
202
+ function promisifyAsyncIterable(iterable, joiner) {
203
+ return (async () => {
204
+ const chunks = [];
205
+ for await (const chunk of iterable) {
206
+ chunks.push(chunk);
207
+ }
208
+ return joiner(chunks);
209
+ })();
210
+ }
211
+ exports.promisifyAsyncIterable = promisifyAsyncIterable;
212
+ exports.unzip = (0, util_1.promisify)(zlib_1.default.gunzip);
213
+ exports.zip = (0, util_1.promisify)(zlib_1.default.gzip);
214
+ async function parseGzippedJson(buffer) {
215
+ return JSON.parse(bufferToString(await (0, exports.unzip)(buffer)));
216
+ }
217
+ exports.parseGzippedJson = parseGzippedJson;
218
+ function isObject(value) {
219
+ return !!value && typeof value === 'object' && !Array.isArray(value);
220
+ }
221
+ exports.isObject = isObject;
222
+ function merge(a, b) {
223
+ const ans = (0, rfdc_1.default)()(a);
224
+ for (const [key, value] of Object.entries(b)) {
225
+ if (isObject(ans[key]) && isObject(value)) {
226
+ ans[key] = merge(ans[key], value);
227
+ }
228
+ else if (value === undefined) {
229
+ delete ans[key];
230
+ }
231
+ else {
232
+ ans[key] = value;
233
+ }
234
+ }
235
+ return ans;
236
+ }
237
+ exports.merge = merge;
238
+ var Lazy;
239
+ (function (Lazy) {
240
+ const LazyDiscriminator = Symbol('LazyDiscriminator');
241
+ function create(getter) {
242
+ return {
243
+ discriminator: LazyDiscriminator,
244
+ getter,
245
+ };
246
+ }
247
+ Lazy.create = create;
248
+ function isComplex(lazy) {
249
+ return lazy?.discriminator === LazyDiscriminator;
250
+ }
251
+ Lazy.isComplex = isComplex;
252
+ function isUnresolved(lazy) {
253
+ return isComplex(lazy) && !('value' in lazy);
254
+ }
255
+ Lazy.isUnresolved = isUnresolved;
256
+ function resolve(lazy) {
257
+ return isUnresolved(lazy) ? lazy.value = lazy.getter() : lazy;
258
+ }
259
+ Lazy.resolve = resolve;
260
+ })(Lazy = exports.Lazy || (exports.Lazy = {}));
261
+ /**
262
+ * @param ids An array of block/fluid IDs, with or without the namespace.
263
+ * @returns A map from state names to the corresponding sets of values. The first element in the value array is the default
264
+ * value for that state.
265
+ */
266
+ function getStates(category, ids, ctx) {
267
+ const ans = {};
268
+ ids = ids.map(ResourceLocation.lengthen);
269
+ for (const id of ids) {
270
+ ctx.symbols
271
+ .query(ctx.doc, category, id)
272
+ .forEachMember((state, stateQuery) => {
273
+ const values = Object.keys(stateQuery.visibleMembers);
274
+ const set = ans[state] ?? (ans[state] = new Set());
275
+ const defaultValue = stateQuery.symbol?.relations?.default;
276
+ if (defaultValue) {
277
+ set.add(defaultValue.path[defaultValue.path.length - 1]);
278
+ }
279
+ for (const value of values) {
280
+ set.add(value);
281
+ }
282
+ });
283
+ }
284
+ return Object.fromEntries(Object.entries(ans).map(([k, v]) => [k, [...v]]));
285
+ }
286
+ exports.getStates = getStates;
287
+ exports.binarySearch = binary_search_1.default;
288
+ function isIterable(value) {
289
+ return !!value[Symbol.iterator];
290
+ }
291
+ exports.isIterable = isIterable;
292
+ //# sourceMappingURL=util.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './common';
2
+ export * from './node';
3
+ export * from './parser';
4
+ export * from './processor';
5
+ export * from './service';
6
+ export * from './source';
7
+ export * from './symbol';
8
+ //# sourceMappingURL=index.d.ts.map
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./common"), exports);
14
+ __exportStar(require("./node"), exports);
15
+ __exportStar(require("./parser"), exports);
16
+ __exportStar(require("./processor"), exports);
17
+ __exportStar(require("./service"), exports);
18
+ __exportStar(require("./source"), exports);
19
+ __exportStar(require("./symbol"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,64 @@
1
+ import type { Color, FormattableColor } from '../processor';
2
+ import { Range } from '../source';
3
+ import type { Symbol, SymbolTable } from '../symbol';
4
+ export interface AstNode {
5
+ readonly type: string;
6
+ readonly range: Range;
7
+ /**
8
+ * All child nodes of this AST node.
9
+ */
10
+ readonly children?: AstNode[];
11
+ readonly parent?: AstNode;
12
+ locals?: SymbolTable;
13
+ symbol?: Symbol;
14
+ hover?: string;
15
+ /**
16
+ * An actual color that this node represents.
17
+ */
18
+ color?: Color | FormattableColor;
19
+ }
20
+ export declare namespace AstNode {
21
+ export function is(obj: unknown): obj is AstNode;
22
+ export function setParents(node: AstNode): void;
23
+ /**
24
+ * @param endInclusive Defaults to `false`.
25
+ */
26
+ export function findChildIndex(node: AstNode, needle: number | Range, endInclusive?: boolean): number;
27
+ /**
28
+ * @param endInclusive Defaults to `false`.
29
+ */
30
+ export function findChild<N extends AstNode>(node: N, needle: number | Range, endInclusive?: boolean): Exclude<N['children'], undefined>[number] | undefined;
31
+ /**
32
+ * Returns the index of the last child node that ends before the `needle`.
33
+ *
34
+ * @param endInclusive Defaults to `false`.
35
+ */
36
+ export function findLastChildIndex(node: AstNode, needle: number | Range, endInclusive?: boolean): number;
37
+ /**
38
+ * @param endInclusive Defaults to `false`.
39
+ */
40
+ export function findLastChild<N extends AstNode>(node: N, needle: number | Range, endInclusive?: boolean): (N['children'] extends unknown[] ? N['children'][number] : undefined) | undefined;
41
+ interface FindRecursivelyOptions<P = (node: AstNode) => boolean> {
42
+ node: AstNode;
43
+ needle: number;
44
+ endInclusive?: boolean;
45
+ predicate?: P;
46
+ }
47
+ /**
48
+ * @returns The deepest node that both contains `needle` and satisfies the `predicate`.
49
+ */
50
+ export function findDeepestChild<N extends AstNode>(options: FindRecursivelyOptions<(node: AstNode) => node is N>): N | undefined;
51
+ export function findDeepestChild(options: FindRecursivelyOptions): AstNode | undefined;
52
+ /**
53
+ * @returns The shallowest node that both contains `needle` and satisfies the `predicate`.
54
+ */
55
+ export function findShallowestChild<N extends AstNode>(options: FindRecursivelyOptions<(node: AstNode) => node is N>): N | undefined;
56
+ export function findShallowestChild(options: FindRecursivelyOptions): AstNode | undefined;
57
+ export function getLocalsToRoot(node: AstNode): Generator<SymbolTable>;
58
+ export function getLocalsToLeaves(node: AstNode): Generator<SymbolTable>;
59
+ export {};
60
+ }
61
+ export declare type Mutable<N> = N extends AstNode ? {
62
+ -readonly [K in keyof N]: Mutable<N[K]>;
63
+ } : N;
64
+ //# sourceMappingURL=AstNode.d.ts.map
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AstNode = void 0;
7
+ const binary_search_1 = __importDefault(require("binary-search"));
8
+ const source_1 = require("../source");
9
+ var AstNode;
10
+ (function (AstNode) {
11
+ /* istanbul ignore next */
12
+ function is(obj) {
13
+ return !!obj && typeof obj === 'object' && typeof obj.type === 'string' &&
14
+ source_1.Range.is(obj.range);
15
+ }
16
+ AstNode.is = is;
17
+ function setParents(node) {
18
+ for (const child of node.children ?? []) {
19
+ child.parent = node;
20
+ setParents(child);
21
+ }
22
+ }
23
+ AstNode.setParents = setParents;
24
+ /**
25
+ * @param endInclusive Defaults to `false`.
26
+ */
27
+ function findChildIndex(node, needle, endInclusive = false) {
28
+ if (!node.children) {
29
+ return -1;
30
+ }
31
+ const comparator = typeof needle === 'number' ? source_1.Range.compareOffset : source_1.Range.compare;
32
+ return (0, binary_search_1.default)(node.children, needle, (a, b) => comparator(a.range, b, endInclusive));
33
+ }
34
+ AstNode.findChildIndex = findChildIndex;
35
+ /**
36
+ * @param endInclusive Defaults to `false`.
37
+ */
38
+ function findChild(node, needle, endInclusive = false) {
39
+ return node.children?.[findChildIndex(node, needle, endInclusive)];
40
+ }
41
+ AstNode.findChild = findChild;
42
+ /**
43
+ * Returns the index of the last child node that ends before the `needle`.
44
+ *
45
+ * @param endInclusive Defaults to `false`.
46
+ */
47
+ function findLastChildIndex(node, needle, endInclusive = false) {
48
+ if (!node.children) {
49
+ return -1;
50
+ }
51
+ let ans = -1;
52
+ for (const [i, childNode] of node.children.entries()) {
53
+ if (source_1.Range.endsBefore(childNode.range, needle, endInclusive)) {
54
+ ans = i;
55
+ }
56
+ else {
57
+ break;
58
+ }
59
+ }
60
+ return ans;
61
+ }
62
+ AstNode.findLastChildIndex = findLastChildIndex;
63
+ /**
64
+ * @param endInclusive Defaults to `false`.
65
+ */
66
+ function findLastChild(node, needle, endInclusive = false) {
67
+ return node.children?.[findLastChildIndex(node, needle, endInclusive)];
68
+ }
69
+ AstNode.findLastChild = findLastChild;
70
+ function findDeepestChild({ node, needle, endInclusive = false, predicate = () => true }) {
71
+ let last;
72
+ let head = source_1.Range.contains(node, needle, endInclusive) ? node : undefined;
73
+ while (head && predicate(head)) {
74
+ last = head;
75
+ head = findChild(head, needle, endInclusive);
76
+ }
77
+ return last;
78
+ }
79
+ AstNode.findDeepestChild = findDeepestChild;
80
+ function findShallowestChild({ node, needle, endInclusive = false, predicate = () => true }) {
81
+ let head = source_1.Range.contains(node, needle, endInclusive) ? node : undefined;
82
+ while (head && !predicate(head)) {
83
+ head = findChild(head, needle, endInclusive);
84
+ }
85
+ return head;
86
+ }
87
+ AstNode.findShallowestChild = findShallowestChild;
88
+ function* getLocalsToRoot(node) {
89
+ let head = node;
90
+ while (head) {
91
+ if (head.locals) {
92
+ yield head.locals;
93
+ }
94
+ head = node.parent;
95
+ }
96
+ }
97
+ AstNode.getLocalsToRoot = getLocalsToRoot;
98
+ function* getLocalsToLeaves(node) {
99
+ if (node.locals) {
100
+ yield node.locals;
101
+ }
102
+ for (const child of node.children ?? []) {
103
+ yield* getLocalsToLeaves(child);
104
+ }
105
+ }
106
+ AstNode.getLocalsToLeaves = getLocalsToLeaves;
107
+ })(AstNode = exports.AstNode || (exports.AstNode = {}));
108
+ //# sourceMappingURL=AstNode.js.map
@@ -0,0 +1,13 @@
1
+ import type { RangeLike } from '../source';
2
+ import type { AstNode } from './AstNode';
3
+ export interface BooleanBaseNode extends AstNode {
4
+ readonly value?: boolean;
5
+ }
6
+ export interface BooleanNode extends BooleanBaseNode {
7
+ readonly type: 'boolean';
8
+ }
9
+ export declare namespace BooleanNode {
10
+ function is(obj: AstNode): obj is BooleanNode;
11
+ function mock(range: RangeLike): BooleanNode;
12
+ }
13
+ //# sourceMappingURL=BooleanNode.d.ts.map