@gmb/bitmark-parser 7.0.0 → 7.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.
- package/README.md +147 -11
- package/dist/browser/bitmark-parser.min.js +4 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- package/dist/browser/cjs/index.cjs +439 -67
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +320 -17
- package/dist/browser/esm/index.d.ts +320 -17
- package/dist/browser/esm/index.js +432 -67
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +317 -29
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
- package/dist/index.cjs +114 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +315 -17
- package/dist/index.d.ts +315 -17
- package/dist/index.js +107 -38
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +1 -1
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.js +1 -1
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +7 -7
- package/schema/bitmark.schema.json +30 -6
- package/wasm/bitmark_wasm.d.ts +43 -8
- package/wasm/bitmark_wasm.js +165 -19
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +4 -1
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +43 -8
- package/wasm-bitmark-json/bitmark_json_wasm.js +156 -10
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +4 -1
- package/wasm-bitmark-json/package.json +1 -1
- package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +43 -8
- package/wasm-browser-full/bitmark_browser_full_wasm.js +165 -19
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +4 -1
- package/wasm-browser-full/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createRequire } from "module";
|
|
|
10
10
|
// src/generated/package_info.ts
|
|
11
11
|
var PACKAGE_INFO = {
|
|
12
12
|
"name": "@gmb/bitmark-parser",
|
|
13
|
-
"version": "7.
|
|
13
|
+
"version": "7.2.0",
|
|
14
14
|
"author": "Get More Brain Ltd <info@getmorebrain.com>",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"description": "A parser for bitmark text, powered by WebAssembly."
|
|
@@ -102,6 +102,7 @@ function planTransform(wasm, input, options) {
|
|
|
102
102
|
const sel = options.inputFormat ?? "auto";
|
|
103
103
|
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
104
104
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
105
|
+
wasm.transform("", "bitmark", output, mode, "", false, indent, spacesAroundValues);
|
|
105
106
|
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
106
107
|
const total = units.length;
|
|
107
108
|
const hooked = [];
|
|
@@ -117,7 +118,9 @@ function planTransform(wasm, input, options) {
|
|
|
117
118
|
if (patchJson === "") {
|
|
118
119
|
resolved = units.map((_, index) => ({ source: index, bit: null, patch: [] }));
|
|
119
120
|
} else {
|
|
120
|
-
resolved = JSON.parse(
|
|
121
|
+
resolved = JSON.parse(
|
|
122
|
+
wasm.resolve_patch_document(input, inputFormat, patchJson)
|
|
123
|
+
);
|
|
121
124
|
}
|
|
122
125
|
const jobs = [];
|
|
123
126
|
const views = [];
|
|
@@ -167,7 +170,7 @@ function computeBit(wasm, job) {
|
|
|
167
170
|
return job.outputFormat === "json" ? stripArray(out) : out;
|
|
168
171
|
}
|
|
169
172
|
function recombine(wasm, elements, output, pretty, indent) {
|
|
170
|
-
if (output
|
|
173
|
+
if (output !== "json") return elements.join("\n");
|
|
171
174
|
const arr = `[${elements.join(",")}]`;
|
|
172
175
|
return pretty ? wasm.prettify(arr, indent) : arr;
|
|
173
176
|
}
|
|
@@ -195,62 +198,57 @@ async function orchestrateParallel(wasm, input, options, runJobs) {
|
|
|
195
198
|
// src/node/pool.ts
|
|
196
199
|
import { fileURLToPath } from "url";
|
|
197
200
|
import { Worker } from "worker_threads";
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
function runJobsParallel(jobs, workers, feature) {
|
|
201
|
+
|
|
202
|
+
// src/core/pool.ts
|
|
203
|
+
function runJobsWithPool(jobs, workers, spawn) {
|
|
202
204
|
if (jobs.length === 0) return Promise.resolve([]);
|
|
203
205
|
const poolSize = Math.max(1, Math.min(workers, jobs.length));
|
|
204
|
-
|
|
205
|
-
return new Promise((resolve, reject) => {
|
|
206
|
+
return new Promise((resolve2, reject) => {
|
|
206
207
|
const results = new Array(jobs.length);
|
|
207
208
|
let next = 0;
|
|
208
209
|
let settled = 0;
|
|
209
210
|
let done = false;
|
|
210
211
|
const pool = [];
|
|
211
|
-
const
|
|
212
|
-
for (const w of pool) void w.terminate();
|
|
213
|
-
};
|
|
214
|
-
const fail = (err) => {
|
|
212
|
+
const finish = (err) => {
|
|
215
213
|
if (done) return;
|
|
216
214
|
done = true;
|
|
217
|
-
|
|
218
|
-
reject(err);
|
|
215
|
+
for (const w of pool) w.terminate();
|
|
216
|
+
if (err) reject(err);
|
|
217
|
+
else resolve2(results);
|
|
219
218
|
};
|
|
220
219
|
const dispatch = (w) => {
|
|
221
|
-
if (done) return;
|
|
222
|
-
if (next >= jobs.length) return;
|
|
220
|
+
if (done || next >= jobs.length) return;
|
|
223
221
|
const id = next++;
|
|
224
|
-
w.
|
|
222
|
+
w.post({ id, job: jobs[id] });
|
|
225
223
|
};
|
|
226
224
|
for (let i = 0; i < poolSize; i++) {
|
|
227
|
-
const w =
|
|
228
|
-
pool.push(w);
|
|
229
|
-
w.on("message", (res) => {
|
|
225
|
+
const w = spawn((res) => {
|
|
230
226
|
if (done) return;
|
|
231
|
-
if (!res.ok)
|
|
232
|
-
fail(new Error(res.error ?? "worker job failed"));
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
227
|
+
if (!res.ok) return finish(new Error(res.error ?? "worker job failed"));
|
|
235
228
|
results[res.id] = res.element;
|
|
236
|
-
settled
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
resolve(results);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
dispatch(w);
|
|
244
|
-
});
|
|
245
|
-
w.on("error", fail);
|
|
246
|
-
w.on("exit", (code) => {
|
|
247
|
-
if (!done && code !== 0) fail(new Error(`worker exited with code ${code}`));
|
|
248
|
-
});
|
|
229
|
+
if (++settled === jobs.length) finish();
|
|
230
|
+
else dispatch(w);
|
|
231
|
+
}, finish);
|
|
232
|
+
pool.push(w);
|
|
249
233
|
}
|
|
250
234
|
for (const w of pool) dispatch(w);
|
|
251
235
|
});
|
|
252
236
|
}
|
|
253
237
|
|
|
238
|
+
// src/node/pool.ts
|
|
239
|
+
function runJobsParallel(jobs, workers, feature) {
|
|
240
|
+
const path2 = fileURLToPath(new URL("./worker-entry.cjs", import.meta.url));
|
|
241
|
+
return runJobsWithPool(jobs, workers, (onResult, onError) => {
|
|
242
|
+
const w = new Worker(path2, { workerData: { feature } });
|
|
243
|
+
w.on("message", (res) => onResult(res));
|
|
244
|
+
w.on("error", onError);
|
|
245
|
+
w.on("exit", (code) => {
|
|
246
|
+
if (code !== 0) onError(new Error(`worker exited with code ${code}`));
|
|
247
|
+
});
|
|
248
|
+
return { post: (msg) => w.postMessage(msg), terminate: () => void w.terminate() };
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
254
252
|
// src/node/transform-parallel.ts
|
|
255
253
|
function runParallelTransform(wasm, input, options) {
|
|
256
254
|
const feature = variant() ?? "full";
|
|
@@ -1360,6 +1358,24 @@ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
|
|
|
1360
1358
|
var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
|
|
1361
1359
|
var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
|
|
1362
1360
|
|
|
1361
|
+
// src/editor-types.ts
|
|
1362
|
+
var DiagnosticSeverity = {
|
|
1363
|
+
Error: 1,
|
|
1364
|
+
Warning: 2,
|
|
1365
|
+
Information: 3,
|
|
1366
|
+
Hint: 4
|
|
1367
|
+
};
|
|
1368
|
+
var CompletionItemKind = {
|
|
1369
|
+
Class: 7,
|
|
1370
|
+
Property: 10,
|
|
1371
|
+
Value: 12,
|
|
1372
|
+
Keyword: 14,
|
|
1373
|
+
Snippet: 15,
|
|
1374
|
+
EnumMember: 20,
|
|
1375
|
+
TypeParameter: 25
|
|
1376
|
+
};
|
|
1377
|
+
var CompletionItemTag = { Deprecated: 1 };
|
|
1378
|
+
|
|
1363
1379
|
// src/types.ts
|
|
1364
1380
|
function patchEntry(path2, op, value) {
|
|
1365
1381
|
return value === void 0 ? { path: path2, op } : { path: path2, op, value };
|
|
@@ -1427,6 +1443,52 @@ function semanticTokens(input, options = {}) {
|
|
|
1427
1443
|
})
|
|
1428
1444
|
);
|
|
1429
1445
|
}
|
|
1446
|
+
function diagnostics(input, options = {}) {
|
|
1447
|
+
return JSON.parse(
|
|
1448
|
+
convert(input, {
|
|
1449
|
+
inputFormat: "bitmark",
|
|
1450
|
+
outputFormat: "diagnostics",
|
|
1451
|
+
positionEncoding: options.positionEncoding
|
|
1452
|
+
})
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
function complete(input, position, options = {}) {
|
|
1456
|
+
const wasm = getActive();
|
|
1457
|
+
if (typeof wasm.complete !== "function") throw new UnsupportedFeatureError("complete", variant());
|
|
1458
|
+
return JSON.parse(
|
|
1459
|
+
wasm.complete(
|
|
1460
|
+
input,
|
|
1461
|
+
position.line,
|
|
1462
|
+
position.character,
|
|
1463
|
+
options.positionEncoding ?? "",
|
|
1464
|
+
options.includeDeprecated ?? false,
|
|
1465
|
+
options.triggerCharacter ?? ""
|
|
1466
|
+
)
|
|
1467
|
+
);
|
|
1468
|
+
}
|
|
1469
|
+
function resolve(input, position, item, options = {}) {
|
|
1470
|
+
const wasm = getActive();
|
|
1471
|
+
if (typeof wasm.resolve !== "function") throw new UnsupportedFeatureError("resolve", variant());
|
|
1472
|
+
const resolved = JSON.parse(
|
|
1473
|
+
wasm.resolve(
|
|
1474
|
+
input,
|
|
1475
|
+
position.line,
|
|
1476
|
+
position.character,
|
|
1477
|
+
options.positionEncoding ?? "",
|
|
1478
|
+
options.includeDeprecated ?? false,
|
|
1479
|
+
item.label,
|
|
1480
|
+
item.kind
|
|
1481
|
+
)
|
|
1482
|
+
);
|
|
1483
|
+
return resolved ?? item;
|
|
1484
|
+
}
|
|
1485
|
+
function hover(input, position, options = {}) {
|
|
1486
|
+
const wasm = getActive();
|
|
1487
|
+
if (typeof wasm.hover !== "function") throw new UnsupportedFeatureError("hover", variant());
|
|
1488
|
+
return JSON.parse(
|
|
1489
|
+
wasm.hover(input, position.line, position.character, options.positionEncoding ?? "")
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1430
1492
|
function canonicalize(input, options = {}) {
|
|
1431
1493
|
return getActive().canonicalize(
|
|
1432
1494
|
input,
|
|
@@ -1555,16 +1617,22 @@ function transformParallel(input, options = {}) {
|
|
|
1555
1617
|
}
|
|
1556
1618
|
export {
|
|
1557
1619
|
ALL_LANGUAGES,
|
|
1620
|
+
CompletionItemKind,
|
|
1621
|
+
CompletionItemTag,
|
|
1622
|
+
DiagnosticSeverity,
|
|
1558
1623
|
NotInitializedError,
|
|
1559
1624
|
RegisterError,
|
|
1560
1625
|
UnsupportedFeatureError,
|
|
1561
1626
|
bitmarkToObjects,
|
|
1562
1627
|
breakscapeText,
|
|
1563
1628
|
canonicalize,
|
|
1629
|
+
complete,
|
|
1564
1630
|
convert,
|
|
1565
1631
|
countBits,
|
|
1632
|
+
diagnostics,
|
|
1566
1633
|
diff,
|
|
1567
1634
|
diffBits,
|
|
1635
|
+
hover,
|
|
1568
1636
|
info,
|
|
1569
1637
|
init,
|
|
1570
1638
|
initSync,
|
|
@@ -1572,6 +1640,7 @@ export {
|
|
|
1572
1640
|
objectsToBitmark,
|
|
1573
1641
|
patchEntry,
|
|
1574
1642
|
register,
|
|
1643
|
+
resolve,
|
|
1575
1644
|
semanticTokens,
|
|
1576
1645
|
splitBits,
|
|
1577
1646
|
transform,
|