@spyglassmc/core 0.1.2 → 0.2.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 (187) hide show
  1. package/README.md +7 -0
  2. package/lib/browser.d.ts +2 -0
  3. package/lib/browser.js +2 -0
  4. package/lib/common/TwoWayMap.js +4 -10
  5. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  6. package/lib/common/externals/BrowserExternals.js +191 -0
  7. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  8. package/lib/common/externals/NodeJsExternals.js +151 -0
  9. package/lib/common/externals/downloader.d.ts +31 -0
  10. package/lib/common/externals/downloader.js +32 -0
  11. package/lib/common/externals/index.d.ts +96 -0
  12. package/lib/common/externals/index.js +2 -0
  13. package/lib/common/index.d.ts +2 -1
  14. package/lib/common/index.js +2 -17
  15. package/lib/common/util.d.ts +15 -15
  16. package/lib/common/util.js +30 -77
  17. package/lib/index.d.ts +7 -7
  18. package/lib/index.js +7 -23
  19. package/lib/node/AstNode.d.ts +3 -3
  20. package/lib/node/AstNode.js +10 -16
  21. package/lib/node/BooleanNode.d.ts +2 -2
  22. package/lib/node/BooleanNode.js +4 -7
  23. package/lib/node/CommentNode.d.ts +1 -1
  24. package/lib/node/CommentNode.js +2 -5
  25. package/lib/node/ErrorNode.d.ts +1 -1
  26. package/lib/node/ErrorNode.js +2 -5
  27. package/lib/node/FileNode.d.ts +3 -3
  28. package/lib/node/FileNode.js +2 -5
  29. package/lib/node/FloatNode.d.ts +2 -2
  30. package/lib/node/FloatNode.js +4 -7
  31. package/lib/node/IntegerNode.d.ts +2 -2
  32. package/lib/node/IntegerNode.js +4 -7
  33. package/lib/node/ListNode.d.ts +2 -2
  34. package/lib/node/ListNode.js +2 -5
  35. package/lib/node/LiteralNode.d.ts +3 -3
  36. package/lib/node/LiteralNode.js +4 -7
  37. package/lib/node/LongNode.d.ts +2 -2
  38. package/lib/node/LongNode.js +4 -7
  39. package/lib/node/RecordNode.d.ts +2 -2
  40. package/lib/node/RecordNode.js +2 -5
  41. package/lib/node/ResourceLocationNode.d.ts +5 -5
  42. package/lib/node/ResourceLocationNode.js +9 -12
  43. package/lib/node/Sequence.d.ts +2 -2
  44. package/lib/node/Sequence.js +4 -7
  45. package/lib/node/StringNode.d.ts +4 -4
  46. package/lib/node/StringNode.js +9 -12
  47. package/lib/node/SymbolNode.d.ts +3 -3
  48. package/lib/node/SymbolNode.js +4 -7
  49. package/lib/node/index.d.ts +15 -15
  50. package/lib/node/index.js +15 -31
  51. package/lib/nodejs.d.ts +2 -0
  52. package/lib/nodejs.js +2 -0
  53. package/lib/parser/Parser.d.ts +3 -3
  54. package/lib/parser/Parser.js +1 -4
  55. package/lib/parser/boolean.d.ts +2 -2
  56. package/lib/parser/boolean.js +3 -6
  57. package/lib/parser/comment.d.ts +2 -2
  58. package/lib/parser/comment.js +5 -9
  59. package/lib/parser/empty.d.ts +1 -1
  60. package/lib/parser/empty.js +1 -5
  61. package/lib/parser/error.d.ts +2 -2
  62. package/lib/parser/error.js +5 -9
  63. package/lib/parser/file.d.ts +3 -3
  64. package/lib/parser/file.js +9 -13
  65. package/lib/parser/float.d.ts +4 -4
  66. package/lib/parser/float.js +12 -16
  67. package/lib/parser/index.d.ts +16 -16
  68. package/lib/parser/index.js +16 -38
  69. package/lib/parser/integer.d.ts +4 -4
  70. package/lib/parser/integer.js +10 -14
  71. package/lib/parser/list.d.ts +2 -2
  72. package/lib/parser/list.js +15 -19
  73. package/lib/parser/literal.d.ts +2 -2
  74. package/lib/parser/literal.js +5 -9
  75. package/lib/parser/long.d.ts +4 -4
  76. package/lib/parser/long.js +10 -14
  77. package/lib/parser/record.d.ts +3 -3
  78. package/lib/parser/record.js +20 -24
  79. package/lib/parser/resourceLocation.d.ts +2 -2
  80. package/lib/parser/resourceLocation.js +14 -18
  81. package/lib/parser/string.d.ts +5 -5
  82. package/lib/parser/string.js +36 -42
  83. package/lib/parser/symbol.d.ts +3 -3
  84. package/lib/parser/symbol.js +3 -7
  85. package/lib/parser/util.d.ts +5 -5
  86. package/lib/parser/util.js +38 -56
  87. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  88. package/lib/processor/ColorInfoProvider.js +6 -9
  89. package/lib/processor/InlayHintProvider.d.ts +2 -2
  90. package/lib/processor/InlayHintProvider.js +1 -2
  91. package/lib/processor/SignatureHelpProvider.d.ts +2 -2
  92. package/lib/processor/SignatureHelpProvider.js +1 -2
  93. package/lib/processor/checker/Checker.d.ts +2 -2
  94. package/lib/processor/checker/Checker.js +1 -5
  95. package/lib/processor/checker/builtin.d.ts +4 -4
  96. package/lib/processor/checker/builtin.js +19 -30
  97. package/lib/processor/checker/index.d.ts +2 -2
  98. package/lib/processor/checker/index.js +2 -31
  99. package/lib/processor/colorizer/Colorizer.d.ts +4 -4
  100. package/lib/processor/colorizer/Colorizer.js +8 -11
  101. package/lib/processor/colorizer/builtin.d.ts +3 -3
  102. package/lib/processor/colorizer/builtin.js +33 -46
  103. package/lib/processor/colorizer/index.d.ts +2 -2
  104. package/lib/processor/colorizer/index.js +2 -31
  105. package/lib/processor/completer/Completer.d.ts +4 -4
  106. package/lib/processor/completer/Completer.js +14 -33
  107. package/lib/processor/completer/builtin.d.ts +7 -7
  108. package/lib/processor/completer/builtin.js +46 -62
  109. package/lib/processor/completer/index.d.ts +2 -2
  110. package/lib/processor/completer/index.js +2 -31
  111. package/lib/processor/formatter/Formatter.d.ts +2 -2
  112. package/lib/processor/formatter/Formatter.js +2 -7
  113. package/lib/processor/formatter/builtin.d.ts +3 -3
  114. package/lib/processor/formatter/builtin.js +22 -36
  115. package/lib/processor/formatter/index.d.ts +2 -2
  116. package/lib/processor/formatter/index.js +2 -31
  117. package/lib/processor/index.d.ts +9 -9
  118. package/lib/processor/index.js +9 -25
  119. package/lib/processor/linter/Linter.d.ts +2 -2
  120. package/lib/processor/linter/Linter.js +1 -2
  121. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  122. package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
  123. package/lib/processor/linter/builtin.d.ts +3 -3
  124. package/lib/processor/linter/builtin.js +19 -26
  125. package/lib/processor/linter/index.d.ts +2 -2
  126. package/lib/processor/linter/index.js +2 -31
  127. package/lib/processor/util.d.ts +2 -2
  128. package/lib/processor/util.js +4 -9
  129. package/lib/service/CacheService.d.ts +6 -6
  130. package/lib/service/CacheService.js +32 -56
  131. package/lib/service/Config.d.ts +11 -12
  132. package/lib/service/Config.js +50 -45
  133. package/lib/service/Context.d.ts +13 -13
  134. package/lib/service/Context.js +29 -32
  135. package/lib/service/Dependency.js +2 -5
  136. package/lib/service/Downloader.d.ts +10 -40
  137. package/lib/service/Downloader.js +37 -110
  138. package/lib/service/ErrorReporter.d.ts +2 -2
  139. package/lib/service/ErrorReporter.js +10 -14
  140. package/lib/service/FileService.d.ts +16 -14
  141. package/lib/service/FileService.js +55 -92
  142. package/lib/service/Hover.d.ts +2 -2
  143. package/lib/service/Hover.js +4 -7
  144. package/lib/service/Logger.js +2 -5
  145. package/lib/service/MetaRegistry.d.ts +12 -12
  146. package/lib/service/MetaRegistry.js +62 -73
  147. package/lib/service/Operations.js +3 -9
  148. package/lib/service/Profiler.d.ts +1 -1
  149. package/lib/service/Profiler.js +25 -41
  150. package/lib/service/Project.d.ts +47 -51
  151. package/lib/service/Project.js +199 -239
  152. package/lib/service/Service.d.ts +17 -27
  153. package/lib/service/Service.js +37 -43
  154. package/lib/service/SymbolLocations.d.ts +3 -3
  155. package/lib/service/SymbolLocations.js +4 -7
  156. package/lib/service/SymbolRegistrar.d.ts +1 -1
  157. package/lib/service/SymbolRegistrar.js +1 -2
  158. package/lib/service/fileUtil.d.ts +15 -45
  159. package/lib/service/fileUtil.js +38 -143
  160. package/lib/service/index.d.ts +17 -17
  161. package/lib/service/index.js +17 -35
  162. package/lib/source/IndexMap.d.ts +1 -1
  163. package/lib/source/IndexMap.js +7 -10
  164. package/lib/source/LanguageError.d.ts +2 -2
  165. package/lib/source/LanguageError.js +2 -5
  166. package/lib/source/Location.d.ts +3 -3
  167. package/lib/source/Location.js +6 -9
  168. package/lib/source/Offset.d.ts +1 -1
  169. package/lib/source/Offset.js +4 -7
  170. package/lib/source/Position.js +2 -5
  171. package/lib/source/PositionRange.d.ts +2 -2
  172. package/lib/source/PositionRange.js +14 -17
  173. package/lib/source/Range.d.ts +1 -1
  174. package/lib/source/Range.js +7 -10
  175. package/lib/source/Source.d.ts +3 -3
  176. package/lib/source/Source.js +28 -29
  177. package/lib/source/index.d.ts +8 -8
  178. package/lib/source/index.js +8 -24
  179. package/lib/symbol/Symbol.d.ts +2 -2
  180. package/lib/symbol/Symbol.js +49 -65
  181. package/lib/symbol/SymbolUtil.d.ts +22 -25
  182. package/lib/symbol/SymbolUtil.js +150 -151
  183. package/lib/symbol/UriBinder.d.ts +1 -1
  184. package/lib/symbol/UriBinder.js +1 -2
  185. package/lib/symbol/index.d.ts +3 -3
  186. package/lib/symbol/index.js +3 -19
  187. package/package.json +7 -4
package/README.md CHANGED
@@ -8,3 +8,10 @@
8
8
  [![Gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg?style=flat-square)](https://gitmoji.carloscuesta.me/)
9
9
 
10
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.
11
+
12
+ ## Exports
13
+
14
+ * `@spyglassmc/core`: Contains all core functionalities.
15
+ * `@spyglassmc/core/lib/browser.js`: Contains browser-specific features.
16
+ * `@spyglassmc/core/lib/nodejs.js`: Contains Node.js-specific features.
17
+ * `@spyglassmc/core/test-out/utils.js`: For internal development use only. Does not exist in the package published to npm.
@@ -0,0 +1,2 @@
1
+ export * from './common/externals/BrowserExternals.js';
2
+ //# sourceMappingURL=browser.d.ts.map
package/lib/browser.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './common/externals/BrowserExternals.js';
2
+ //# sourceMappingURL=browser.js.map
@@ -1,12 +1,7 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TwoWayMap = void 0;
5
- class TwoWayMap {
1
+ export class TwoWayMap {
2
+ _map = new Map();
3
+ _reversedMap = new Map();
6
4
  constructor(values = []) {
7
- this._map = new Map();
8
- this._reversedMap = new Map();
9
- this[_a] = 'TwoWayMap';
10
5
  for (const [k, v] of values) {
11
6
  this._map.set(k, v);
12
7
  this._reversedMap.set(v, k);
@@ -69,7 +64,6 @@ class TwoWayMap {
69
64
  [Symbol.iterator]() {
70
65
  return this._map.entries();
71
66
  }
67
+ [Symbol.toStringTag] = 'TwoWayMap';
72
68
  }
73
- exports.TwoWayMap = TwoWayMap;
74
- _a = Symbol.toStringTag;
75
69
  //# sourceMappingURL=TwoWayMap.js.map
@@ -0,0 +1,3 @@
1
+ import type { Externals } from './index.js';
2
+ export declare const BrowserExternals: Externals;
3
+ //# sourceMappingURL=BrowserExternals.d.ts.map
@@ -0,0 +1,191 @@
1
+ import { decode as arrayBufferFromBase64, encode as arrayBufferToBase64 } from 'base64-arraybuffer';
2
+ import pako from 'pako';
3
+ import { fileUtil } from '../../service/fileUtil.js';
4
+ import { Uri } from '../index.js';
5
+ class BrowserEventEmitter {
6
+ #listeners = new Map();
7
+ emit(eventName, ...args) {
8
+ const listeners = this.#listeners.get(eventName);
9
+ if (!listeners?.all?.size) {
10
+ return false;
11
+ }
12
+ for (const listener of listeners.all) {
13
+ listener(...args);
14
+ if (listeners.once.has(listener)) {
15
+ listeners.all.delete(listener);
16
+ listeners.once.delete(listener);
17
+ }
18
+ }
19
+ return false;
20
+ }
21
+ on(eventName, listener) {
22
+ if (!this.#listeners.has(eventName)) {
23
+ this.#listeners.set(eventName, { all: new Set(), once: new Set() });
24
+ }
25
+ const listeners = this.#listeners.get(eventName);
26
+ listeners.all.add(listener);
27
+ return this;
28
+ }
29
+ once(eventName, listener) {
30
+ if (!this.#listeners.has(eventName)) {
31
+ this.#listeners.set(eventName, { all: new Set(), once: new Set() });
32
+ }
33
+ const listeners = this.#listeners.get(eventName);
34
+ listeners.all.add(listener);
35
+ listeners.once.add(listener);
36
+ return this;
37
+ }
38
+ }
39
+ class BrowserExternalDownloader {
40
+ async get(uri, options = {}) {
41
+ const headers = new Headers();
42
+ for (const [name, value] of Object.entries(options?.headers ?? {})) {
43
+ const values = typeof value === 'string' ? [value] : value;
44
+ for (const v of values) {
45
+ headers.append(name, v);
46
+ }
47
+ }
48
+ const res = await fetch(uri, {
49
+ headers,
50
+ redirect: 'follow',
51
+ });
52
+ if (!res.ok) {
53
+ throw new Error(`Status code ${res.status}: ${res.ok}`);
54
+ }
55
+ else {
56
+ return new Uint8Array(await res.arrayBuffer());
57
+ }
58
+ }
59
+ }
60
+ class BrowserFsWatcher {
61
+ on(event, listener) {
62
+ if (event === 'ready') {
63
+ listener();
64
+ }
65
+ return this;
66
+ }
67
+ once(event, listener) {
68
+ if (event === 'ready') {
69
+ listener();
70
+ }
71
+ return this;
72
+ }
73
+ async close() {
74
+ }
75
+ }
76
+ class BrowserFileSystem {
77
+ static LocalStorageKey = 'spyglassmc-browser-fs';
78
+ states;
79
+ constructor() {
80
+ this.states = JSON.parse(localStorage.getItem(BrowserFileSystem.LocalStorageKey) ?? '{}');
81
+ }
82
+ saveStates() {
83
+ localStorage.setItem(BrowserFileSystem.LocalStorageKey, JSON.stringify(this.states));
84
+ }
85
+ async chmod(_location, _mode) {
86
+ return;
87
+ }
88
+ async getAllFiles(_location) {
89
+ return [];
90
+ }
91
+ async mkdir(location, _options) {
92
+ location = fileUtil.ensureEndingSlash(location.toString());
93
+ if (this.states[location]) {
94
+ throw new Error(`EEXIST: ${location}`);
95
+ }
96
+ this.states[location] = { type: 'directory' };
97
+ this.saveStates();
98
+ }
99
+ async readFile(location) {
100
+ location = location.toString();
101
+ const entry = this.states[location];
102
+ if (!entry) {
103
+ throw new Error(`ENOENT: ${location}`);
104
+ }
105
+ else if (entry.type === 'directory') {
106
+ throw new Error(`EISDIR: ${location}`);
107
+ }
108
+ return new Uint8Array(arrayBufferFromBase64(entry.content));
109
+ }
110
+ async showFile(_path) {
111
+ throw new Error('showFile not supported on browser');
112
+ }
113
+ async stat(location) {
114
+ location = location.toString();
115
+ const entry = this.states[location];
116
+ if (!entry) {
117
+ throw new Error(`ENOENT: ${location}`);
118
+ }
119
+ return {
120
+ isDirectory: () => entry.type === 'directory',
121
+ isFile: () => entry.type === 'file',
122
+ };
123
+ }
124
+ async unlink(location) {
125
+ location = location.toString();
126
+ const entry = this.states[location];
127
+ if (!entry) {
128
+ throw new Error(`ENOENT: ${location}`);
129
+ }
130
+ delete this.states[location];
131
+ this.saveStates();
132
+ }
133
+ watch(_location) {
134
+ return new BrowserFsWatcher();
135
+ }
136
+ async writeFile(location, data, _options) {
137
+ location = location.toString();
138
+ if (typeof data === 'string') {
139
+ data = new TextEncoder().encode(data);
140
+ }
141
+ data = arrayBufferToBase64(data);
142
+ this.states[location] = { type: 'file', content: data };
143
+ this.saveStates();
144
+ }
145
+ }
146
+ export const BrowserExternals = {
147
+ archive: {
148
+ decompressBall(_buffer, _options) {
149
+ throw new Error('decompressBall not supported on browser.');
150
+ },
151
+ async gunzip(buffer) {
152
+ return pako.inflate(buffer);
153
+ },
154
+ async gzip(buffer) {
155
+ return pako.gzip(buffer);
156
+ },
157
+ },
158
+ crypto: {
159
+ async getSha1(data) {
160
+ if (typeof data === 'string') {
161
+ data = new TextEncoder().encode(data);
162
+ }
163
+ const hash = await crypto.subtle.digest('SHA-1', data);
164
+ return uint8ArrayToHex(new Uint8Array(hash));
165
+ },
166
+ },
167
+ downloader: new BrowserExternalDownloader(),
168
+ error: {
169
+ isKind(e, kind) {
170
+ return e instanceof Error && e.message.startsWith(kind);
171
+ },
172
+ },
173
+ event: {
174
+ EventEmitter: BrowserEventEmitter,
175
+ },
176
+ fs: new BrowserFileSystem(),
177
+ uri: {
178
+ normalize(uri) {
179
+ return new Uri(uri).toString();
180
+ },
181
+ },
182
+ };
183
+ function uint8ArrayToHex(array) {
184
+ let ans = '';
185
+ for (const v of array) {
186
+ ans += v.toString(16).padStart(2, '0');
187
+ }
188
+ return ans;
189
+ }
190
+ Object.freeze(BrowserExternals);
191
+ //# sourceMappingURL=BrowserExternals.js.map
@@ -0,0 +1,3 @@
1
+ import type { Externals } from './index.js';
2
+ export declare const NodeJsExternals: Externals;
3
+ //# sourceMappingURL=NodeJsExternals.d.ts.map
@@ -0,0 +1,151 @@
1
+ import chokidar from 'chokidar';
2
+ import decompress from 'decompress';
3
+ import followRedirects from 'follow-redirects';
4
+ import globby from 'globby';
5
+ import { Buffer } from 'node:buffer';
6
+ import cp from 'node:child_process';
7
+ import crypto from 'node:crypto';
8
+ import { EventEmitter } from 'node:events';
9
+ import { promises as fsp } from 'node:fs';
10
+ import process from 'node:process';
11
+ import url from 'node:url';
12
+ import { promisify } from 'node:util';
13
+ import zlib from 'node:zlib';
14
+ import { promisifyAsyncIterable, Uri } from '../util.js';
15
+ const { http, https } = followRedirects;
16
+ const gunzip = promisify(zlib.gunzip);
17
+ const gzip = promisify(zlib.gzip);
18
+ class NodeJsExternalDownloader {
19
+ get(uri, options = {}) {
20
+ const protocol = new Uri(uri).protocol;
21
+ return new Promise((resolve, reject) => {
22
+ const backend = protocol === 'http:' ? http : https;
23
+ backend.get(uri, options, (res) => {
24
+ if (res.statusCode !== 200) {
25
+ reject(new Error(`Status code ${res.statusCode}: ${res.statusMessage}`));
26
+ }
27
+ else {
28
+ resolve(promisifyAsyncIterable(res, chunks => Buffer.concat(chunks)));
29
+ }
30
+ });
31
+ });
32
+ }
33
+ }
34
+ export const NodeJsExternals = {
35
+ archive: {
36
+ decompressBall(buffer, options) {
37
+ if (buffer instanceof Buffer) {
38
+ return decompress(buffer, { strip: options?.stripLevel });
39
+ }
40
+ throw new TypeError(`The 'buffer' argument for 'decompressBall' on Node.js must be an instance of 'Buffer'. Got '${buffer}' instead.`);
41
+ },
42
+ gunzip(buffer) {
43
+ return gunzip(buffer);
44
+ },
45
+ gzip(buffer) {
46
+ return gzip(buffer);
47
+ },
48
+ },
49
+ crypto: {
50
+ async getSha1(data) {
51
+ const hash = crypto.createHash('sha1');
52
+ hash.update(data);
53
+ return hash.digest('hex');
54
+ },
55
+ },
56
+ downloader: new NodeJsExternalDownloader(),
57
+ error: {
58
+ isKind(e, kind) {
59
+ return e instanceof Error && e.code === kind;
60
+ },
61
+ },
62
+ event: {
63
+ EventEmitter,
64
+ },
65
+ fs: {
66
+ chmod(location, mode) {
67
+ return fsp.chmod(toFsPathLike(location), mode);
68
+ },
69
+ async getAllFiles(location) {
70
+ return (await globby(toPath(location) + '**/*', { absolute: true, dot: true })).map(uriFromPath);
71
+ },
72
+ async mkdir(location, options) {
73
+ return void await fsp.mkdir(toFsPathLike(location), options);
74
+ },
75
+ readFile(location) {
76
+ return fsp.readFile(toFsPathLike(location));
77
+ },
78
+ async showFile(location) {
79
+ const execFile = promisify(cp.execFile);
80
+ let command;
81
+ switch (process.platform) {
82
+ case 'darwin':
83
+ command = 'open';
84
+ break;
85
+ case 'win32':
86
+ command = 'explorer';
87
+ break;
88
+ default:
89
+ command = 'xdg-open';
90
+ break;
91
+ }
92
+ return void await execFile(command, [toPath(location)]);
93
+ },
94
+ stat(location) {
95
+ return fsp.stat(toFsPathLike(location));
96
+ },
97
+ unlink(location) {
98
+ return fsp.unlink(toFsPathLike(location));
99
+ },
100
+ watch(location) {
101
+ return new ChokidarWatcherWrapper(chokidar.watch(toPath(location)));
102
+ },
103
+ writeFile(location, data, options) {
104
+ return fsp.writeFile(toFsPathLike(location), data, options);
105
+ },
106
+ },
107
+ uri: {
108
+ normalize(uri) {
109
+ if (uri.startsWith('file:')) {
110
+ return url.pathToFileURL(url.fileURLToPath(uri)).toString();
111
+ }
112
+ else {
113
+ return new Uri(uri).toString();
114
+ }
115
+ },
116
+ },
117
+ };
118
+ Object.freeze(NodeJsExternals);
119
+ /**
120
+ * @returns A {@link fs.PathLike}.
121
+ */
122
+ function toFsPathLike(path) {
123
+ if (typeof path === 'string' && path.startsWith('file:')) {
124
+ return new Uri(path);
125
+ }
126
+ return path;
127
+ }
128
+ function toPath(path) {
129
+ if (typeof path === 'string' && !path.startsWith('file:')) {
130
+ return path;
131
+ }
132
+ return uriToPath(path);
133
+ }
134
+ const uriToPath = (uri) => url.fileURLToPath(uri);
135
+ const uriFromPath = (path) => url.pathToFileURL(path).toString();
136
+ class ChokidarWatcherWrapper extends EventEmitter {
137
+ #watcher;
138
+ constructor(watcher) {
139
+ super();
140
+ this.#watcher = watcher
141
+ .on('ready', () => this.emit('ready'))
142
+ .on('add', path => this.emit('add', uriFromPath(path)))
143
+ .on('change', path => this.emit('change', uriFromPath(path)))
144
+ .on('unlink', path => this.emit('unlink', uriFromPath(path)))
145
+ .on('error', e => this.emit('error', e));
146
+ }
147
+ close() {
148
+ return this.#watcher.close();
149
+ }
150
+ }
151
+ //# sourceMappingURL=NodeJsExternals.js.map
@@ -0,0 +1,31 @@
1
+ declare type RemoteUriProtocol = 'http:' | 'https:';
2
+ export declare type RemoteUriString = `${RemoteUriProtocol}${string}`;
3
+ export declare const RemoteUriString: Readonly<{
4
+ is(value: string): value is `http:${string}` | `https:${string}`;
5
+ }>;
6
+ export interface ExternalDownloaderOptions {
7
+ /**
8
+ * Use an string array to set multiple values to the header.
9
+ */
10
+ headers?: Record<string, string | string[]>;
11
+ timeout?: number;
12
+ }
13
+ export interface ExternalDownloader {
14
+ /**
15
+ * @throws
16
+ */
17
+ get(uri: RemoteUriString, options?: ExternalDownloaderOptions): Promise<Uint8Array>;
18
+ }
19
+ export declare const ExternalDownloader: Readonly<{
20
+ mock(options: ExternalDownloaderMockOptions): ExternalDownloader;
21
+ }>;
22
+ interface ExternalDownloaderMockOptions {
23
+ /**
24
+ * A record from URIs to fixture data. The {@link ExternalDownloader.get} only returns a {@link Uint8Array},
25
+ * therefore `string` fixtures will be turned into a `Uint8Array` and `object` fixtures will be transformed
26
+ * into JSON and then turned into a `Uint8Array`.
27
+ */
28
+ fixtures: Record<RemoteUriString, string | Uint8Array | object>;
29
+ }
30
+ export {};
31
+ //# sourceMappingURL=downloader.d.ts.map
@@ -0,0 +1,32 @@
1
+ export const RemoteUriString = Object.freeze({
2
+ is(value) {
3
+ return value.startsWith('http:') || value.startsWith('https:');
4
+ },
5
+ });
6
+ export const ExternalDownloader = Object.freeze({
7
+ mock(options) {
8
+ return new ExternalDownloaderMock(options);
9
+ },
10
+ });
11
+ class ExternalDownloaderMock {
12
+ options;
13
+ constructor(options) {
14
+ this.options = options;
15
+ }
16
+ async get(uri) {
17
+ if (!this.options.fixtures[uri]) {
18
+ throw new Error(`404 not found: ${uri}`);
19
+ }
20
+ const fixture = this.options.fixtures[uri];
21
+ if (fixture instanceof Uint8Array) {
22
+ return fixture;
23
+ }
24
+ else if (typeof fixture === 'string') {
25
+ return new TextEncoder().encode(fixture);
26
+ }
27
+ else {
28
+ return new TextEncoder().encode(JSON.stringify(fixture));
29
+ }
30
+ }
31
+ }
32
+ //# sourceMappingURL=downloader.js.map
@@ -0,0 +1,96 @@
1
+ import type { Uri } from '../util.js';
2
+ import type { ExternalDownloader } from './downloader.js';
3
+ export * from './downloader.js';
4
+ export interface Externals {
5
+ archive: {
6
+ decompressBall: (buffer: Uint8Array, options?: {
7
+ stripLevel?: number;
8
+ }) => Promise<DecompressedFile[]>;
9
+ gzip: (buffer: Uint8Array) => Promise<Uint8Array>;
10
+ gunzip: (buffer: Uint8Array) => Promise<Uint8Array>;
11
+ };
12
+ crypto: {
13
+ /**
14
+ * @returns SHA-1 digest of the given data in hexadecimal format.
15
+ */
16
+ getSha1: (data: string | Uint8Array) => Promise<string>;
17
+ };
18
+ downloader: ExternalDownloader;
19
+ error: {
20
+ isKind: (e: unknown, kind: ExternalErrorKind) => boolean;
21
+ };
22
+ event: {
23
+ EventEmitter: new () => ExternalEventEmitter;
24
+ };
25
+ fs: ExternalFileSystem;
26
+ uri: {
27
+ normalize: (uri: string) => string;
28
+ };
29
+ }
30
+ export interface DecompressedFile {
31
+ data: Uint8Array;
32
+ mode: number;
33
+ mtime: string;
34
+ path: string;
35
+ type: string;
36
+ }
37
+ export declare type ExternalErrorKind = 'EEXIST' | 'EISDIR' | 'ENOENT';
38
+ export interface ExternalEventEmitter {
39
+ emit(eventName: string, ...args: unknown[]): boolean;
40
+ on(eventName: string, listener: (...args: unknown[]) => unknown): this;
41
+ once(eventName: string, listener: (...args: unknown[]) => unknown): this;
42
+ }
43
+ export interface ExternalFileSystem {
44
+ /**
45
+ * @param mode File mode bit mask (e.g. `0o775`).
46
+ */
47
+ chmod(location: FsLocation, mode: number): Promise<void>;
48
+ /**
49
+ * @returns an array of file URIs under the given `location`.
50
+ */
51
+ getAllFiles(location: FsLocation): Promise<string[]>;
52
+ /**
53
+ * @param options `mode` - File mode bit mask (e.g. `0o775`).
54
+ */
55
+ mkdir(location: FsLocation, options?: {
56
+ mode?: number;
57
+ recursive?: boolean;
58
+ }): Promise<void>;
59
+ readFile(location: FsLocation): Promise<Uint8Array>;
60
+ /**
61
+ * Show the file/directory in the platform-specific explorer program.
62
+ *
63
+ * Should not be called with unsanitized user-input path due to the possibility of arbitrary code execution.
64
+ */
65
+ showFile(path: FsLocation): Promise<void>;
66
+ stat(location: FsLocation): Promise<{
67
+ isDirectory(): boolean;
68
+ isFile(): boolean;
69
+ }>;
70
+ unlink(location: FsLocation): Promise<void>;
71
+ watch(location: FsLocation): FsWatcher;
72
+ /**
73
+ * @param options `mode` - File mode bit mask (e.g. `0o775`).
74
+ */
75
+ writeFile(location: FsLocation, data: string | Uint8Array, options?: {
76
+ mode: number;
77
+ }): Promise<void>;
78
+ }
79
+ /**
80
+ * A file file URI string or a URI object.
81
+ */
82
+ export declare type FsLocation = string | Uri;
83
+ export interface FsWatcher {
84
+ on(eventName: 'ready', listener: () => unknown): this;
85
+ once(eventName: 'ready', listener: () => unknown): this;
86
+ on(eventName: 'add', listener: (uri: string) => unknown): this;
87
+ once(eventName: 'add', listener: (uri: string) => unknown): this;
88
+ on(eventName: 'change', listener: (uri: string) => unknown): this;
89
+ once(eventName: 'change', listener: (uri: string) => unknown): this;
90
+ on(eventName: 'unlink', listener: (uri: string) => unknown): this;
91
+ once(eventName: 'unlink', listener: (uri: string) => unknown): this;
92
+ on(eventName: 'error', listener: (error: Error) => unknown): this;
93
+ once(eventName: 'error', listener: (error: Error) => unknown): this;
94
+ close(): Promise<void>;
95
+ }
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from './downloader.js';
2
+ //# sourceMappingURL=index.js.map
@@ -1,2 +1,3 @@
1
- export * from './util';
1
+ export * from './externals/index.js';
2
+ export * from './util.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1,18 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./util"), exports);
1
+ export * from './externals/index.js';
2
+ export * from './util.js';
18
3
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,17 @@
1
- /// <reference types="node" />
2
1
  import externalBinarySearch from 'binary-search';
3
- import type { ProcessorContext } from '../service';
4
- export { URL as Uri } from 'url';
2
+ import type { ProcessorContext } from '../service/index.js';
3
+ import type { Externals } from './externals/index.js';
4
+ export declare const Uri: {
5
+ new (url: string | URL, base?: string | URL | undefined): URL;
6
+ prototype: URL;
7
+ createObjectURL(obj: Blob | MediaSource): string;
8
+ revokeObjectURL(url: string): void;
9
+ };
10
+ export declare type Uri = URL;
11
+ /**
12
+ * `NodeJS.Timeout` on Node.js and `number` on browser.
13
+ */
14
+ export declare type IntervalId = any;
5
15
  /**
6
16
  * @param getCacheKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
7
17
  * The result of this function will be used as the key to cache the `Promise`. By default the first element in the argument
@@ -50,15 +60,7 @@ export declare namespace ResourceLocation {
50
60
  * @returns The string value decoded from the buffer according to UTF-8.
51
61
  * Byte order mark is correctly removed.
52
62
  */
53
- export declare function bufferToString(buffer: Buffer): string;
54
- export declare function stringToBase64(str: string): string;
55
- export declare function base64ToString(base64: string): string;
56
- /**
57
- * @throws
58
- */
59
- export declare function getSha1(data: string | Buffer): string;
60
- export declare function isErrorCode(e: unknown, code: string): boolean;
61
- export declare function isEnoent(e: unknown): boolean;
63
+ export declare function bufferToString(buffer: Uint8Array): string;
62
64
  export declare type Arrayable<T> = T | readonly T[];
63
65
  export declare namespace Arrayable {
64
66
  function is<T>(value: unknown, isT: (value: unknown) => value is T): value is Arrayable<T>;
@@ -68,9 +70,7 @@ export declare namespace TypePredicates {
68
70
  function isString(value: unknown): value is string;
69
71
  }
70
72
  export declare function promisifyAsyncIterable<T, U>(iterable: AsyncIterable<T>, joiner: (chunks: T[]) => U): Promise<U>;
71
- export declare const unzip: (buffer: Buffer) => Promise<Buffer>;
72
- export declare const zip: (buffer: Buffer) => Promise<Buffer>;
73
- export declare function parseGzippedJson<T>(buffer: Buffer): Promise<T>;
73
+ export declare function parseGzippedJson(externals: Externals, buffer: Uint8Array): Promise<unknown>;
74
74
  export declare function isObject(value: unknown): value is Exclude<object, Array<any>>;
75
75
  export declare function merge<T extends Record<string, any>>(a: T, b: Record<string, any>): T;
76
76
  export declare type Lazy<T> = T | Lazy.ComplexLazy<T>;