@c4a/extract-ts 0.6.2 → 0.6.4
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 +28 -0
- package/README.zh-CN.md +32 -0
- package/index.js +504 -336
- package/package.json +5 -1
package/index.js
CHANGED
|
@@ -320,26 +320,26 @@ var require_directives = __commonJS((exports) => {
|
|
|
320
320
|
return false;
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
tagName(
|
|
324
|
-
if (
|
|
323
|
+
tagName(source, onError) {
|
|
324
|
+
if (source === "!")
|
|
325
325
|
return "!";
|
|
326
|
-
if (
|
|
327
|
-
onError(`Not a valid tag: ${
|
|
326
|
+
if (source[0] !== "!") {
|
|
327
|
+
onError(`Not a valid tag: ${source}`);
|
|
328
328
|
return null;
|
|
329
329
|
}
|
|
330
|
-
if (
|
|
331
|
-
const verbatim =
|
|
330
|
+
if (source[1] === "<") {
|
|
331
|
+
const verbatim = source.slice(2, -1);
|
|
332
332
|
if (verbatim === "!" || verbatim === "!!") {
|
|
333
|
-
onError(`Verbatim tags aren't resolved, so ${
|
|
333
|
+
onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);
|
|
334
334
|
return null;
|
|
335
335
|
}
|
|
336
|
-
if (
|
|
336
|
+
if (source[source.length - 1] !== ">")
|
|
337
337
|
onError("Verbatim tags must end with a >");
|
|
338
338
|
return verbatim;
|
|
339
339
|
}
|
|
340
|
-
const [, handle, suffix] =
|
|
340
|
+
const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);
|
|
341
341
|
if (!suffix)
|
|
342
|
-
onError(`The ${
|
|
342
|
+
onError(`The ${source} tag has no suffix`);
|
|
343
343
|
const prefix = this.tags[handle];
|
|
344
344
|
if (prefix) {
|
|
345
345
|
try {
|
|
@@ -350,8 +350,8 @@ var require_directives = __commonJS((exports) => {
|
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
if (handle === "!")
|
|
353
|
-
return
|
|
354
|
-
onError(`Could not resolve tag: ${
|
|
353
|
+
return source;
|
|
354
|
+
onError(`Could not resolve tag: ${source}`);
|
|
355
355
|
return null;
|
|
356
356
|
}
|
|
357
357
|
tagString(tag) {
|
|
@@ -423,21 +423,21 @@ var require_anchors = __commonJS((exports) => {
|
|
|
423
423
|
const sourceObjects = new Map;
|
|
424
424
|
let prevAnchors = null;
|
|
425
425
|
return {
|
|
426
|
-
onAnchor: (
|
|
427
|
-
aliasObjects.push(
|
|
426
|
+
onAnchor: (source) => {
|
|
427
|
+
aliasObjects.push(source);
|
|
428
428
|
prevAnchors ?? (prevAnchors = anchorNames(doc));
|
|
429
429
|
const anchor = findNewAnchor(prefix, prevAnchors);
|
|
430
430
|
prevAnchors.add(anchor);
|
|
431
431
|
return anchor;
|
|
432
432
|
},
|
|
433
433
|
setAnchors: () => {
|
|
434
|
-
for (const
|
|
435
|
-
const ref = sourceObjects.get(
|
|
434
|
+
for (const source of aliasObjects) {
|
|
435
|
+
const ref = sourceObjects.get(source);
|
|
436
436
|
if (typeof ref === "object" && ref.anchor && (identity.isScalar(ref.node) || identity.isCollection(ref.node))) {
|
|
437
437
|
ref.node.anchor = ref.anchor;
|
|
438
438
|
} else {
|
|
439
439
|
const error = new Error("Failed to resolve repeated object (this should not happen)");
|
|
440
|
-
error.source =
|
|
440
|
+
error.source = source;
|
|
441
441
|
throw error;
|
|
442
442
|
}
|
|
443
443
|
}
|
|
@@ -571,9 +571,9 @@ var require_Alias = __commonJS((exports) => {
|
|
|
571
571
|
var toJS = require_toJS();
|
|
572
572
|
|
|
573
573
|
class Alias extends Node.NodeBase {
|
|
574
|
-
constructor(
|
|
574
|
+
constructor(source) {
|
|
575
575
|
super(identity.ALIAS);
|
|
576
|
-
this.source =
|
|
576
|
+
this.source = source;
|
|
577
577
|
Object.defineProperty(this, "tag", {
|
|
578
578
|
set() {
|
|
579
579
|
throw new Error("Alias nodes cannot have tags");
|
|
@@ -608,15 +608,15 @@ var require_Alias = __commonJS((exports) => {
|
|
|
608
608
|
if (!ctx)
|
|
609
609
|
return { source: this.source };
|
|
610
610
|
const { anchors: anchors2, doc, maxAliasCount } = ctx;
|
|
611
|
-
const
|
|
612
|
-
if (!
|
|
611
|
+
const source = this.resolve(doc, ctx);
|
|
612
|
+
if (!source) {
|
|
613
613
|
const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
|
|
614
614
|
throw new ReferenceError(msg);
|
|
615
615
|
}
|
|
616
|
-
let data = anchors2.get(
|
|
616
|
+
let data = anchors2.get(source);
|
|
617
617
|
if (!data) {
|
|
618
|
-
toJS.toJS(
|
|
619
|
-
data = anchors2.get(
|
|
618
|
+
toJS.toJS(source, null, ctx);
|
|
619
|
+
data = anchors2.get(source);
|
|
620
620
|
}
|
|
621
621
|
if (data?.res === undefined) {
|
|
622
622
|
const msg = "This should not happen: Alias anchor was not resolved?";
|
|
@@ -625,7 +625,7 @@ var require_Alias = __commonJS((exports) => {
|
|
|
625
625
|
if (maxAliasCount >= 0) {
|
|
626
626
|
data.count += 1;
|
|
627
627
|
if (data.aliasCount === 0)
|
|
628
|
-
data.aliasCount = getAliasCount(doc,
|
|
628
|
+
data.aliasCount = getAliasCount(doc, source, anchors2);
|
|
629
629
|
if (data.count * data.aliasCount > maxAliasCount) {
|
|
630
630
|
const msg = "Excessive alias count indicates a resource exhaustion attack";
|
|
631
631
|
throw new ReferenceError(msg);
|
|
@@ -649,8 +649,8 @@ var require_Alias = __commonJS((exports) => {
|
|
|
649
649
|
}
|
|
650
650
|
function getAliasCount(doc, node2, anchors2) {
|
|
651
651
|
if (identity.isAlias(node2)) {
|
|
652
|
-
const
|
|
653
|
-
const anchor = anchors2 &&
|
|
652
|
+
const source = node2.resolve(doc);
|
|
653
|
+
const anchor = anchors2 && source && anchors2.get(source);
|
|
654
654
|
return anchor ? anchor.count * anchor.aliasCount : 0;
|
|
655
655
|
} else if (identity.isCollection(node2)) {
|
|
656
656
|
let count = 0;
|
|
@@ -1640,10 +1640,10 @@ var require_merge = __commonJS((exports) => {
|
|
|
1640
1640
|
mergeValue(ctx, map, value);
|
|
1641
1641
|
}
|
|
1642
1642
|
function mergeValue(ctx, map, value) {
|
|
1643
|
-
const
|
|
1644
|
-
if (!identity.isMap(
|
|
1643
|
+
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
1644
|
+
if (!identity.isMap(source))
|
|
1645
1645
|
throw new Error("Merge sources must be maps or map aliases");
|
|
1646
|
-
const srcMap =
|
|
1646
|
+
const srcMap = source.toJSON(null, ctx, Map);
|
|
1647
1647
|
for (const [key, value2] of srcMap) {
|
|
1648
1648
|
if (map instanceof Map) {
|
|
1649
1649
|
if (!map.has(key))
|
|
@@ -2194,7 +2194,7 @@ var require_null = __commonJS((exports) => {
|
|
|
2194
2194
|
tag: "tag:yaml.org,2002:null",
|
|
2195
2195
|
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
2196
2196
|
resolve: () => new Scalar.Scalar(null),
|
|
2197
|
-
stringify: ({ source
|
|
2197
|
+
stringify: ({ source }, ctx) => typeof source === "string" && nullTag.test.test(source) ? source : ctx.options.nullStr
|
|
2198
2198
|
};
|
|
2199
2199
|
exports.nullTag = nullTag;
|
|
2200
2200
|
});
|
|
@@ -2208,11 +2208,11 @@ var require_bool = __commonJS((exports) => {
|
|
|
2208
2208
|
tag: "tag:yaml.org,2002:bool",
|
|
2209
2209
|
test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
|
|
2210
2210
|
resolve: (str) => new Scalar.Scalar(str[0] === "t" || str[0] === "T"),
|
|
2211
|
-
stringify({ source
|
|
2212
|
-
if (
|
|
2213
|
-
const sv =
|
|
2211
|
+
stringify({ source, value }, ctx) {
|
|
2212
|
+
if (source && boolTag.test.test(source)) {
|
|
2213
|
+
const sv = source[0] === "t" || source[0] === "T";
|
|
2214
2214
|
if (value === sv)
|
|
2215
|
-
return
|
|
2215
|
+
return source;
|
|
2216
2216
|
}
|
|
2217
2217
|
return value ? ctx.options.trueStr : ctx.options.falseStr;
|
|
2218
2218
|
}
|
|
@@ -2623,10 +2623,10 @@ var require_omap = __commonJS((exports) => {
|
|
|
2623
2623
|
// ../../node_modules/.bun/yaml@2.8.2/node_modules/yaml/dist/schema/yaml-1.1/bool.js
|
|
2624
2624
|
var require_bool2 = __commonJS((exports) => {
|
|
2625
2625
|
var Scalar = require_Scalar();
|
|
2626
|
-
function boolStringify({ value, source
|
|
2626
|
+
function boolStringify({ value, source }, ctx) {
|
|
2627
2627
|
const boolObj = value ? trueTag : falseTag;
|
|
2628
|
-
if (
|
|
2629
|
-
return
|
|
2628
|
+
if (source && boolObj.test.test(source))
|
|
2629
|
+
return source;
|
|
2630
2630
|
return value ? ctx.options.trueStr : ctx.options.falseStr;
|
|
2631
2631
|
}
|
|
2632
2632
|
var trueTag = {
|
|
@@ -3839,7 +3839,7 @@ var require_resolve_end = __commonJS((exports) => {
|
|
|
3839
3839
|
let hasSpace = false;
|
|
3840
3840
|
let sep = "";
|
|
3841
3841
|
for (const token of end) {
|
|
3842
|
-
const { source
|
|
3842
|
+
const { source, type } = token;
|
|
3843
3843
|
switch (type) {
|
|
3844
3844
|
case "space":
|
|
3845
3845
|
hasSpace = true;
|
|
@@ -3847,7 +3847,7 @@ var require_resolve_end = __commonJS((exports) => {
|
|
|
3847
3847
|
case "comment": {
|
|
3848
3848
|
if (reqSpace && !hasSpace)
|
|
3849
3849
|
onError(token, "MISSING_CHAR", "Comments must be separated from other tokens by white space characters");
|
|
3850
|
-
const cb =
|
|
3850
|
+
const cb = source.substring(1) || " ";
|
|
3851
3851
|
if (!comment)
|
|
3852
3852
|
comment = cb;
|
|
3853
3853
|
else
|
|
@@ -3857,13 +3857,13 @@ var require_resolve_end = __commonJS((exports) => {
|
|
|
3857
3857
|
}
|
|
3858
3858
|
case "newline":
|
|
3859
3859
|
if (comment)
|
|
3860
|
-
sep +=
|
|
3860
|
+
sep += source;
|
|
3861
3861
|
hasSpace = true;
|
|
3862
3862
|
break;
|
|
3863
3863
|
default:
|
|
3864
3864
|
onError(token, "UNEXPECTED_TOKEN", `Unexpected ${type} at node end`);
|
|
3865
3865
|
}
|
|
3866
|
-
offset +=
|
|
3866
|
+
offset += source.length;
|
|
3867
3867
|
}
|
|
3868
3868
|
}
|
|
3869
3869
|
return { comment, offset };
|
|
@@ -4251,13 +4251,13 @@ var require_resolve_block_scalar = __commonJS((exports) => {
|
|
|
4251
4251
|
onError(props[0], "IMPOSSIBLE", "Block scalar header not found");
|
|
4252
4252
|
return null;
|
|
4253
4253
|
}
|
|
4254
|
-
const { source
|
|
4255
|
-
const mode =
|
|
4254
|
+
const { source } = props[0];
|
|
4255
|
+
const mode = source[0];
|
|
4256
4256
|
let indent = 0;
|
|
4257
4257
|
let chomp = "";
|
|
4258
4258
|
let error = -1;
|
|
4259
|
-
for (let i = 1;i <
|
|
4260
|
-
const ch =
|
|
4259
|
+
for (let i = 1;i < source.length; ++i) {
|
|
4260
|
+
const ch = source[i];
|
|
4261
4261
|
if (!chomp && (ch === "-" || ch === "+"))
|
|
4262
4262
|
chomp = ch;
|
|
4263
4263
|
else {
|
|
@@ -4269,10 +4269,10 @@ var require_resolve_block_scalar = __commonJS((exports) => {
|
|
|
4269
4269
|
}
|
|
4270
4270
|
}
|
|
4271
4271
|
if (error !== -1)
|
|
4272
|
-
onError(error, "UNEXPECTED_TOKEN", `Block scalar header includes extra characters: ${
|
|
4272
|
+
onError(error, "UNEXPECTED_TOKEN", `Block scalar header includes extra characters: ${source}`);
|
|
4273
4273
|
let hasSpace = false;
|
|
4274
4274
|
let comment = "";
|
|
4275
|
-
let length =
|
|
4275
|
+
let length = source.length;
|
|
4276
4276
|
for (let i = 1;i < props.length; ++i) {
|
|
4277
4277
|
const token = props[i];
|
|
4278
4278
|
switch (token.type) {
|
|
@@ -4304,8 +4304,8 @@ var require_resolve_block_scalar = __commonJS((exports) => {
|
|
|
4304
4304
|
}
|
|
4305
4305
|
return { mode, indent, chomp, comment, length };
|
|
4306
4306
|
}
|
|
4307
|
-
function splitLines(
|
|
4308
|
-
const split =
|
|
4307
|
+
function splitLines(source) {
|
|
4308
|
+
const split = source.split(/\n( *)/);
|
|
4309
4309
|
const first = split[0];
|
|
4310
4310
|
const m = first.match(/^( *)/);
|
|
4311
4311
|
const line0 = m?.[1] ? [m[1], first.slice(m[1].length)] : ["", first];
|
|
@@ -4322,22 +4322,22 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4322
4322
|
var Scalar = require_Scalar();
|
|
4323
4323
|
var resolveEnd = require_resolve_end();
|
|
4324
4324
|
function resolveFlowScalar(scalar, strict, onError) {
|
|
4325
|
-
const { offset, type, source
|
|
4325
|
+
const { offset, type, source, end } = scalar;
|
|
4326
4326
|
let _type;
|
|
4327
4327
|
let value;
|
|
4328
4328
|
const _onError = (rel, code, msg) => onError(offset + rel, code, msg);
|
|
4329
4329
|
switch (type) {
|
|
4330
4330
|
case "scalar":
|
|
4331
4331
|
_type = Scalar.Scalar.PLAIN;
|
|
4332
|
-
value = plainValue(
|
|
4332
|
+
value = plainValue(source, _onError);
|
|
4333
4333
|
break;
|
|
4334
4334
|
case "single-quoted-scalar":
|
|
4335
4335
|
_type = Scalar.Scalar.QUOTE_SINGLE;
|
|
4336
|
-
value = singleQuotedValue(
|
|
4336
|
+
value = singleQuotedValue(source, _onError);
|
|
4337
4337
|
break;
|
|
4338
4338
|
case "double-quoted-scalar":
|
|
4339
4339
|
_type = Scalar.Scalar.QUOTE_DOUBLE;
|
|
4340
|
-
value = doubleQuotedValue(
|
|
4340
|
+
value = doubleQuotedValue(source, _onError);
|
|
4341
4341
|
break;
|
|
4342
4342
|
default:
|
|
4343
4343
|
onError(scalar, "UNEXPECTED_TOKEN", `Expected a flow scalar value, but found: ${type}`);
|
|
@@ -4345,10 +4345,10 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4345
4345
|
value: "",
|
|
4346
4346
|
type: null,
|
|
4347
4347
|
comment: "",
|
|
4348
|
-
range: [offset, offset +
|
|
4348
|
+
range: [offset, offset + source.length, offset + source.length]
|
|
4349
4349
|
};
|
|
4350
4350
|
}
|
|
4351
|
-
const valueEnd = offset +
|
|
4351
|
+
const valueEnd = offset + source.length;
|
|
4352
4352
|
const re = resolveEnd.resolveEnd(end, valueEnd, strict, onError);
|
|
4353
4353
|
return {
|
|
4354
4354
|
value,
|
|
@@ -4357,9 +4357,9 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4357
4357
|
range: [offset, valueEnd, re.offset]
|
|
4358
4358
|
};
|
|
4359
4359
|
}
|
|
4360
|
-
function plainValue(
|
|
4360
|
+
function plainValue(source, onError) {
|
|
4361
4361
|
let badChar = "";
|
|
4362
|
-
switch (
|
|
4362
|
+
switch (source[0]) {
|
|
4363
4363
|
case "\t":
|
|
4364
4364
|
badChar = "a tab character";
|
|
4365
4365
|
break;
|
|
@@ -4371,25 +4371,25 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4371
4371
|
break;
|
|
4372
4372
|
case "|":
|
|
4373
4373
|
case ">": {
|
|
4374
|
-
badChar = `block scalar indicator ${
|
|
4374
|
+
badChar = `block scalar indicator ${source[0]}`;
|
|
4375
4375
|
break;
|
|
4376
4376
|
}
|
|
4377
4377
|
case "@":
|
|
4378
4378
|
case "`": {
|
|
4379
|
-
badChar = `reserved character ${
|
|
4379
|
+
badChar = `reserved character ${source[0]}`;
|
|
4380
4380
|
break;
|
|
4381
4381
|
}
|
|
4382
4382
|
}
|
|
4383
4383
|
if (badChar)
|
|
4384
4384
|
onError(0, "BAD_SCALAR_START", `Plain value cannot start with ${badChar}`);
|
|
4385
|
-
return foldLines(
|
|
4385
|
+
return foldLines(source);
|
|
4386
4386
|
}
|
|
4387
|
-
function singleQuotedValue(
|
|
4388
|
-
if (
|
|
4389
|
-
onError(
|
|
4390
|
-
return foldLines(
|
|
4387
|
+
function singleQuotedValue(source, onError) {
|
|
4388
|
+
if (source[source.length - 1] !== "'" || source.length === 1)
|
|
4389
|
+
onError(source.length, "MISSING_CHAR", "Missing closing 'quote");
|
|
4390
|
+
return foldLines(source.slice(1, -1)).replace(/''/g, "'");
|
|
4391
4391
|
}
|
|
4392
|
-
function foldLines(
|
|
4392
|
+
function foldLines(source) {
|
|
4393
4393
|
let first, line;
|
|
4394
4394
|
try {
|
|
4395
4395
|
first = new RegExp(`(.*?)(?<![ ])[ ]*\r?
|
|
@@ -4400,14 +4400,14 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4400
4400
|
first = /(.*?)[ \t]*\r?\n/sy;
|
|
4401
4401
|
line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
|
|
4402
4402
|
}
|
|
4403
|
-
let match = first.exec(
|
|
4403
|
+
let match = first.exec(source);
|
|
4404
4404
|
if (!match)
|
|
4405
|
-
return
|
|
4405
|
+
return source;
|
|
4406
4406
|
let res = match[1];
|
|
4407
4407
|
let sep = " ";
|
|
4408
4408
|
let pos = first.lastIndex;
|
|
4409
4409
|
line.lastIndex = pos;
|
|
4410
|
-
while (match = line.exec(
|
|
4410
|
+
while (match = line.exec(source)) {
|
|
4411
4411
|
if (match[1] === "") {
|
|
4412
4412
|
if (sep === `
|
|
4413
4413
|
`)
|
|
@@ -4423,68 +4423,68 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4423
4423
|
}
|
|
4424
4424
|
const last = /[ \t]*(.*)/sy;
|
|
4425
4425
|
last.lastIndex = pos;
|
|
4426
|
-
match = last.exec(
|
|
4426
|
+
match = last.exec(source);
|
|
4427
4427
|
return res + sep + (match?.[1] ?? "");
|
|
4428
4428
|
}
|
|
4429
|
-
function doubleQuotedValue(
|
|
4429
|
+
function doubleQuotedValue(source, onError) {
|
|
4430
4430
|
let res = "";
|
|
4431
|
-
for (let i = 1;i <
|
|
4432
|
-
const ch =
|
|
4433
|
-
if (ch === "\r" &&
|
|
4431
|
+
for (let i = 1;i < source.length - 1; ++i) {
|
|
4432
|
+
const ch = source[i];
|
|
4433
|
+
if (ch === "\r" && source[i + 1] === `
|
|
4434
4434
|
`)
|
|
4435
4435
|
continue;
|
|
4436
4436
|
if (ch === `
|
|
4437
4437
|
`) {
|
|
4438
|
-
const { fold, offset } = foldNewline(
|
|
4438
|
+
const { fold, offset } = foldNewline(source, i);
|
|
4439
4439
|
res += fold;
|
|
4440
4440
|
i = offset;
|
|
4441
4441
|
} else if (ch === "\\") {
|
|
4442
|
-
let next =
|
|
4442
|
+
let next = source[++i];
|
|
4443
4443
|
const cc = escapeCodes[next];
|
|
4444
4444
|
if (cc)
|
|
4445
4445
|
res += cc;
|
|
4446
4446
|
else if (next === `
|
|
4447
4447
|
`) {
|
|
4448
|
-
next =
|
|
4448
|
+
next = source[i + 1];
|
|
4449
4449
|
while (next === " " || next === "\t")
|
|
4450
|
-
next =
|
|
4451
|
-
} else if (next === "\r" &&
|
|
4450
|
+
next = source[++i + 1];
|
|
4451
|
+
} else if (next === "\r" && source[i + 1] === `
|
|
4452
4452
|
`) {
|
|
4453
|
-
next =
|
|
4453
|
+
next = source[++i + 1];
|
|
4454
4454
|
while (next === " " || next === "\t")
|
|
4455
|
-
next =
|
|
4455
|
+
next = source[++i + 1];
|
|
4456
4456
|
} else if (next === "x" || next === "u" || next === "U") {
|
|
4457
4457
|
const length = { x: 2, u: 4, U: 8 }[next];
|
|
4458
|
-
res += parseCharCode(
|
|
4458
|
+
res += parseCharCode(source, i + 1, length, onError);
|
|
4459
4459
|
i += length;
|
|
4460
4460
|
} else {
|
|
4461
|
-
const raw =
|
|
4461
|
+
const raw = source.substr(i - 1, 2);
|
|
4462
4462
|
onError(i - 1, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
|
|
4463
4463
|
res += raw;
|
|
4464
4464
|
}
|
|
4465
4465
|
} else if (ch === " " || ch === "\t") {
|
|
4466
4466
|
const wsStart = i;
|
|
4467
|
-
let next =
|
|
4467
|
+
let next = source[i + 1];
|
|
4468
4468
|
while (next === " " || next === "\t")
|
|
4469
|
-
next =
|
|
4469
|
+
next = source[++i + 1];
|
|
4470
4470
|
if (next !== `
|
|
4471
|
-
` && !(next === "\r" &&
|
|
4471
|
+
` && !(next === "\r" && source[i + 2] === `
|
|
4472
4472
|
`))
|
|
4473
|
-
res += i > wsStart ?
|
|
4473
|
+
res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
|
|
4474
4474
|
} else {
|
|
4475
4475
|
res += ch;
|
|
4476
4476
|
}
|
|
4477
4477
|
}
|
|
4478
|
-
if (
|
|
4479
|
-
onError(
|
|
4478
|
+
if (source[source.length - 1] !== '"' || source.length === 1)
|
|
4479
|
+
onError(source.length, "MISSING_CHAR", 'Missing closing "quote');
|
|
4480
4480
|
return res;
|
|
4481
4481
|
}
|
|
4482
|
-
function foldNewline(
|
|
4482
|
+
function foldNewline(source, offset) {
|
|
4483
4483
|
let fold = "";
|
|
4484
|
-
let ch =
|
|
4484
|
+
let ch = source[offset + 1];
|
|
4485
4485
|
while (ch === " " || ch === "\t" || ch === `
|
|
4486
4486
|
` || ch === "\r") {
|
|
4487
|
-
if (ch === "\r" &&
|
|
4487
|
+
if (ch === "\r" && source[offset + 2] !== `
|
|
4488
4488
|
`)
|
|
4489
4489
|
break;
|
|
4490
4490
|
if (ch === `
|
|
@@ -4492,7 +4492,7 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4492
4492
|
fold += `
|
|
4493
4493
|
`;
|
|
4494
4494
|
offset += 1;
|
|
4495
|
-
ch =
|
|
4495
|
+
ch = source[offset + 1];
|
|
4496
4496
|
}
|
|
4497
4497
|
if (!fold)
|
|
4498
4498
|
fold = " ";
|
|
@@ -4519,12 +4519,12 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
4519
4519
|
"\\": "\\",
|
|
4520
4520
|
"\t": "\t"
|
|
4521
4521
|
};
|
|
4522
|
-
function parseCharCode(
|
|
4523
|
-
const cc =
|
|
4522
|
+
function parseCharCode(source, offset, length, onError) {
|
|
4523
|
+
const cc = source.substr(offset, length);
|
|
4524
4524
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
4525
4525
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
4526
4526
|
if (isNaN(code)) {
|
|
4527
|
-
const raw =
|
|
4527
|
+
const raw = source.substr(offset - 2, length + 2);
|
|
4528
4528
|
onError(offset - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${raw}`);
|
|
4529
4529
|
return raw;
|
|
4530
4530
|
}
|
|
@@ -4719,13 +4719,13 @@ var require_compose_node = __commonJS((exports) => {
|
|
|
4719
4719
|
}
|
|
4720
4720
|
return node2;
|
|
4721
4721
|
}
|
|
4722
|
-
function composeAlias({ options }, { offset, source
|
|
4723
|
-
const alias = new Alias.Alias(
|
|
4722
|
+
function composeAlias({ options }, { offset, source, end }, onError) {
|
|
4723
|
+
const alias = new Alias.Alias(source.substring(1));
|
|
4724
4724
|
if (alias.source === "")
|
|
4725
4725
|
onError(offset, "BAD_ALIAS", "Alias cannot be an empty string");
|
|
4726
4726
|
if (alias.source.endsWith(":"))
|
|
4727
|
-
onError(offset +
|
|
4728
|
-
const valueEnd = offset +
|
|
4727
|
+
onError(offset + source.length - 1, "BAD_ALIAS", "Alias ending in : is ambiguous", true);
|
|
4728
|
+
const valueEnd = offset + source.length;
|
|
4729
4729
|
const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
|
|
4730
4730
|
alias.range = [offset, valueEnd, re.offset];
|
|
4731
4731
|
if (re.comment)
|
|
@@ -4790,21 +4790,21 @@ var require_composer = __commonJS((exports) => {
|
|
|
4790
4790
|
return [src, src + 1];
|
|
4791
4791
|
if (Array.isArray(src))
|
|
4792
4792
|
return src.length === 2 ? src : [src[0], src[1]];
|
|
4793
|
-
const { offset, source
|
|
4794
|
-
return [offset, offset + (typeof
|
|
4793
|
+
const { offset, source } = src;
|
|
4794
|
+
return [offset, offset + (typeof source === "string" ? source.length : 1)];
|
|
4795
4795
|
}
|
|
4796
4796
|
function parsePrelude(prelude) {
|
|
4797
4797
|
let comment = "";
|
|
4798
4798
|
let atComment = false;
|
|
4799
4799
|
let afterEmptyLine = false;
|
|
4800
4800
|
for (let i = 0;i < prelude.length; ++i) {
|
|
4801
|
-
const
|
|
4802
|
-
switch (
|
|
4801
|
+
const source = prelude[i];
|
|
4802
|
+
switch (source[0]) {
|
|
4803
4803
|
case "#":
|
|
4804
4804
|
comment += (comment === "" ? "" : afterEmptyLine ? `
|
|
4805
4805
|
|
|
4806
4806
|
` : `
|
|
4807
|
-
`) + (
|
|
4807
|
+
`) + (source.substring(1) || " ");
|
|
4808
4808
|
atComment = true;
|
|
4809
4809
|
afterEmptyLine = false;
|
|
4810
4810
|
break;
|
|
@@ -4829,8 +4829,8 @@ var require_composer = __commonJS((exports) => {
|
|
|
4829
4829
|
this.prelude = [];
|
|
4830
4830
|
this.errors = [];
|
|
4831
4831
|
this.warnings = [];
|
|
4832
|
-
this.onError = (
|
|
4833
|
-
const pos = getErrorPos(
|
|
4832
|
+
this.onError = (source, code, message, warning) => {
|
|
4833
|
+
const pos = getErrorPos(source);
|
|
4834
4834
|
if (warning)
|
|
4835
4835
|
this.warnings.push(new errors2.YAMLWarning(pos, code, message));
|
|
4836
4836
|
else
|
|
@@ -4993,7 +4993,7 @@ var require_cst_scalar = __commonJS((exports) => {
|
|
|
4993
4993
|
}
|
|
4994
4994
|
function createScalarToken(value, context) {
|
|
4995
4995
|
const { implicitKey = false, indent, inFlow = false, offset = -1, type = "PLAIN" } = context;
|
|
4996
|
-
const
|
|
4996
|
+
const source = stringifyString.stringifyString({ type, value }, {
|
|
4997
4997
|
implicitKey,
|
|
4998
4998
|
indent: indent > 0 ? " ".repeat(indent) : "",
|
|
4999
4999
|
inFlow,
|
|
@@ -5003,13 +5003,13 @@ var require_cst_scalar = __commonJS((exports) => {
|
|
|
5003
5003
|
{ type: "newline", offset: -1, indent, source: `
|
|
5004
5004
|
` }
|
|
5005
5005
|
];
|
|
5006
|
-
switch (
|
|
5006
|
+
switch (source[0]) {
|
|
5007
5007
|
case "|":
|
|
5008
5008
|
case ">": {
|
|
5009
|
-
const he =
|
|
5009
|
+
const he = source.indexOf(`
|
|
5010
5010
|
`);
|
|
5011
|
-
const head =
|
|
5012
|
-
const body =
|
|
5011
|
+
const head = source.substring(0, he);
|
|
5012
|
+
const body = source.substring(he + 1) + `
|
|
5013
5013
|
`;
|
|
5014
5014
|
const props = [
|
|
5015
5015
|
{ type: "block-scalar-header", offset, indent, source: head }
|
|
@@ -5020,11 +5020,11 @@ var require_cst_scalar = __commonJS((exports) => {
|
|
|
5020
5020
|
return { type: "block-scalar", offset, indent, props, source: body };
|
|
5021
5021
|
}
|
|
5022
5022
|
case '"':
|
|
5023
|
-
return { type: "double-quoted-scalar", offset, indent, source
|
|
5023
|
+
return { type: "double-quoted-scalar", offset, indent, source, end };
|
|
5024
5024
|
case "'":
|
|
5025
|
-
return { type: "single-quoted-scalar", offset, indent, source
|
|
5025
|
+
return { type: "single-quoted-scalar", offset, indent, source, end };
|
|
5026
5026
|
default:
|
|
5027
|
-
return { type: "scalar", offset, indent, source
|
|
5027
|
+
return { type: "scalar", offset, indent, source, end };
|
|
5028
5028
|
}
|
|
5029
5029
|
}
|
|
5030
5030
|
function setScalarValue(token, value, context = {}) {
|
|
@@ -5050,32 +5050,32 @@ var require_cst_scalar = __commonJS((exports) => {
|
|
|
5050
5050
|
default:
|
|
5051
5051
|
type = "PLAIN";
|
|
5052
5052
|
}
|
|
5053
|
-
const
|
|
5053
|
+
const source = stringifyString.stringifyString({ type, value }, {
|
|
5054
5054
|
implicitKey: implicitKey || indent === null,
|
|
5055
5055
|
indent: indent !== null && indent > 0 ? " ".repeat(indent) : "",
|
|
5056
5056
|
inFlow,
|
|
5057
5057
|
options: { blockQuote: true, lineWidth: -1 }
|
|
5058
5058
|
});
|
|
5059
|
-
switch (
|
|
5059
|
+
switch (source[0]) {
|
|
5060
5060
|
case "|":
|
|
5061
5061
|
case ">":
|
|
5062
|
-
setBlockScalarValue(token,
|
|
5062
|
+
setBlockScalarValue(token, source);
|
|
5063
5063
|
break;
|
|
5064
5064
|
case '"':
|
|
5065
|
-
setFlowScalarValue(token,
|
|
5065
|
+
setFlowScalarValue(token, source, "double-quoted-scalar");
|
|
5066
5066
|
break;
|
|
5067
5067
|
case "'":
|
|
5068
|
-
setFlowScalarValue(token,
|
|
5068
|
+
setFlowScalarValue(token, source, "single-quoted-scalar");
|
|
5069
5069
|
break;
|
|
5070
5070
|
default:
|
|
5071
|
-
setFlowScalarValue(token,
|
|
5071
|
+
setFlowScalarValue(token, source, "scalar");
|
|
5072
5072
|
}
|
|
5073
5073
|
}
|
|
5074
|
-
function setBlockScalarValue(token,
|
|
5075
|
-
const he =
|
|
5074
|
+
function setBlockScalarValue(token, source) {
|
|
5075
|
+
const he = source.indexOf(`
|
|
5076
5076
|
`);
|
|
5077
|
-
const head =
|
|
5078
|
-
const body =
|
|
5077
|
+
const head = source.substring(0, he);
|
|
5078
|
+
const body = source.substring(he + 1) + `
|
|
5079
5079
|
`;
|
|
5080
5080
|
if (token.type === "block-scalar") {
|
|
5081
5081
|
const header = token.props[0];
|
|
@@ -5112,32 +5112,32 @@ var require_cst_scalar = __commonJS((exports) => {
|
|
|
5112
5112
|
}
|
|
5113
5113
|
return false;
|
|
5114
5114
|
}
|
|
5115
|
-
function setFlowScalarValue(token,
|
|
5115
|
+
function setFlowScalarValue(token, source, type) {
|
|
5116
5116
|
switch (token.type) {
|
|
5117
5117
|
case "scalar":
|
|
5118
5118
|
case "double-quoted-scalar":
|
|
5119
5119
|
case "single-quoted-scalar":
|
|
5120
5120
|
token.type = type;
|
|
5121
|
-
token.source =
|
|
5121
|
+
token.source = source;
|
|
5122
5122
|
break;
|
|
5123
5123
|
case "block-scalar": {
|
|
5124
5124
|
const end = token.props.slice(1);
|
|
5125
|
-
let oa =
|
|
5125
|
+
let oa = source.length;
|
|
5126
5126
|
if (token.props[0].type === "block-scalar-header")
|
|
5127
5127
|
oa -= token.props[0].source.length;
|
|
5128
5128
|
for (const tok of end)
|
|
5129
5129
|
tok.offset += oa;
|
|
5130
5130
|
delete token.props;
|
|
5131
|
-
Object.assign(token, { type, source
|
|
5131
|
+
Object.assign(token, { type, source, end });
|
|
5132
5132
|
break;
|
|
5133
5133
|
}
|
|
5134
5134
|
case "block-map":
|
|
5135
5135
|
case "block-seq": {
|
|
5136
|
-
const offset = token.offset +
|
|
5136
|
+
const offset = token.offset + source.length;
|
|
5137
5137
|
const nl = { type: "newline", offset, indent: token.indent, source: `
|
|
5138
5138
|
` };
|
|
5139
5139
|
delete token.items;
|
|
5140
|
-
Object.assign(token, { type, source
|
|
5140
|
+
Object.assign(token, { type, source, end: [nl] });
|
|
5141
5141
|
break;
|
|
5142
5142
|
}
|
|
5143
5143
|
default: {
|
|
@@ -5146,7 +5146,7 @@ var require_cst_scalar = __commonJS((exports) => {
|
|
|
5146
5146
|
for (const key of Object.keys(token))
|
|
5147
5147
|
if (key !== "type" && key !== "offset")
|
|
5148
5148
|
delete token[key];
|
|
5149
|
-
Object.assign(token, { type, indent, source
|
|
5149
|
+
Object.assign(token, { type, indent, source, end });
|
|
5150
5150
|
}
|
|
5151
5151
|
}
|
|
5152
5152
|
}
|
|
@@ -5297,8 +5297,8 @@ var require_cst = __commonJS((exports) => {
|
|
|
5297
5297
|
return JSON.stringify(token);
|
|
5298
5298
|
}
|
|
5299
5299
|
}
|
|
5300
|
-
function tokenType(
|
|
5301
|
-
switch (
|
|
5300
|
+
function tokenType(source) {
|
|
5301
|
+
switch (source) {
|
|
5302
5302
|
case BOM:
|
|
5303
5303
|
return "byte-order-mark";
|
|
5304
5304
|
case DOCUMENT:
|
|
@@ -5334,7 +5334,7 @@ var require_cst = __commonJS((exports) => {
|
|
|
5334
5334
|
case ",":
|
|
5335
5335
|
return "comma";
|
|
5336
5336
|
}
|
|
5337
|
-
switch (
|
|
5337
|
+
switch (source[0]) {
|
|
5338
5338
|
case " ":
|
|
5339
5339
|
case "\t":
|
|
5340
5340
|
return "space";
|
|
@@ -5410,11 +5410,11 @@ var require_lexer = __commonJS((exports) => {
|
|
|
5410
5410
|
this.next = null;
|
|
5411
5411
|
this.pos = 0;
|
|
5412
5412
|
}
|
|
5413
|
-
*lex(
|
|
5414
|
-
if (
|
|
5415
|
-
if (typeof
|
|
5413
|
+
*lex(source, incomplete = false) {
|
|
5414
|
+
if (source) {
|
|
5415
|
+
if (typeof source !== "string")
|
|
5416
5416
|
throw TypeError("source is not a string");
|
|
5417
|
-
this.buffer = this.buffer ? this.buffer +
|
|
5417
|
+
this.buffer = this.buffer ? this.buffer + source : source;
|
|
5418
5418
|
this.lineEndPos = null;
|
|
5419
5419
|
}
|
|
5420
5420
|
this.atEnd = !incomplete;
|
|
@@ -6088,29 +6088,29 @@ var require_parser = __commonJS((exports) => {
|
|
|
6088
6088
|
this.lexer = new lexer.Lexer;
|
|
6089
6089
|
this.onNewLine = onNewLine;
|
|
6090
6090
|
}
|
|
6091
|
-
*parse(
|
|
6091
|
+
*parse(source, incomplete = false) {
|
|
6092
6092
|
if (this.onNewLine && this.offset === 0)
|
|
6093
6093
|
this.onNewLine(0);
|
|
6094
|
-
for (const lexeme of this.lexer.lex(
|
|
6094
|
+
for (const lexeme of this.lexer.lex(source, incomplete))
|
|
6095
6095
|
yield* this.next(lexeme);
|
|
6096
6096
|
if (!incomplete)
|
|
6097
6097
|
yield* this.end();
|
|
6098
6098
|
}
|
|
6099
|
-
*next(
|
|
6100
|
-
this.source =
|
|
6099
|
+
*next(source) {
|
|
6100
|
+
this.source = source;
|
|
6101
6101
|
if (node_process.env.LOG_TOKENS)
|
|
6102
|
-
console.log("|", cst.prettyToken(
|
|
6102
|
+
console.log("|", cst.prettyToken(source));
|
|
6103
6103
|
if (this.atScalar) {
|
|
6104
6104
|
this.atScalar = false;
|
|
6105
6105
|
yield* this.step();
|
|
6106
|
-
this.offset +=
|
|
6106
|
+
this.offset += source.length;
|
|
6107
6107
|
return;
|
|
6108
6108
|
}
|
|
6109
|
-
const type = cst.tokenType(
|
|
6109
|
+
const type = cst.tokenType(source);
|
|
6110
6110
|
if (!type) {
|
|
6111
|
-
const message = `Not a YAML token: ${
|
|
6112
|
-
yield* this.pop({ type: "error", offset: this.offset, message, source
|
|
6113
|
-
this.offset +=
|
|
6111
|
+
const message = `Not a YAML token: ${source}`;
|
|
6112
|
+
yield* this.pop({ type: "error", offset: this.offset, message, source });
|
|
6113
|
+
this.offset += source.length;
|
|
6114
6114
|
} else if (type === "scalar") {
|
|
6115
6115
|
this.atNewLine = false;
|
|
6116
6116
|
this.atScalar = true;
|
|
@@ -6123,17 +6123,17 @@ var require_parser = __commonJS((exports) => {
|
|
|
6123
6123
|
this.atNewLine = true;
|
|
6124
6124
|
this.indent = 0;
|
|
6125
6125
|
if (this.onNewLine)
|
|
6126
|
-
this.onNewLine(this.offset +
|
|
6126
|
+
this.onNewLine(this.offset + source.length);
|
|
6127
6127
|
break;
|
|
6128
6128
|
case "space":
|
|
6129
|
-
if (this.atNewLine &&
|
|
6130
|
-
this.indent +=
|
|
6129
|
+
if (this.atNewLine && source[0] === " ")
|
|
6130
|
+
this.indent += source.length;
|
|
6131
6131
|
break;
|
|
6132
6132
|
case "explicit-key-ind":
|
|
6133
6133
|
case "map-value-ind":
|
|
6134
6134
|
case "seq-item-ind":
|
|
6135
6135
|
if (this.atNewLine)
|
|
6136
|
-
this.indent +=
|
|
6136
|
+
this.indent += source.length;
|
|
6137
6137
|
break;
|
|
6138
6138
|
case "doc-mode":
|
|
6139
6139
|
case "flow-error-end":
|
|
@@ -6141,7 +6141,7 @@ var require_parser = __commonJS((exports) => {
|
|
|
6141
6141
|
default:
|
|
6142
6142
|
this.atNewLine = false;
|
|
6143
6143
|
}
|
|
6144
|
-
this.offset +=
|
|
6144
|
+
this.offset += source.length;
|
|
6145
6145
|
}
|
|
6146
6146
|
}
|
|
6147
6147
|
*end() {
|
|
@@ -6850,26 +6850,26 @@ var require_public_api = __commonJS((exports) => {
|
|
|
6850
6850
|
const lineCounter$1 = options.lineCounter || prettyErrors && new lineCounter.LineCounter || null;
|
|
6851
6851
|
return { lineCounter: lineCounter$1, prettyErrors };
|
|
6852
6852
|
}
|
|
6853
|
-
function parseAllDocuments(
|
|
6853
|
+
function parseAllDocuments(source, options = {}) {
|
|
6854
6854
|
const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
|
|
6855
6855
|
const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
|
|
6856
6856
|
const composer$1 = new composer.Composer(options);
|
|
6857
|
-
const docs = Array.from(composer$1.compose(parser$1.parse(
|
|
6857
|
+
const docs = Array.from(composer$1.compose(parser$1.parse(source)));
|
|
6858
6858
|
if (prettyErrors && lineCounter2)
|
|
6859
6859
|
for (const doc of docs) {
|
|
6860
|
-
doc.errors.forEach(errors2.prettifyError(
|
|
6861
|
-
doc.warnings.forEach(errors2.prettifyError(
|
|
6860
|
+
doc.errors.forEach(errors2.prettifyError(source, lineCounter2));
|
|
6861
|
+
doc.warnings.forEach(errors2.prettifyError(source, lineCounter2));
|
|
6862
6862
|
}
|
|
6863
6863
|
if (docs.length > 0)
|
|
6864
6864
|
return docs;
|
|
6865
6865
|
return Object.assign([], { empty: true }, composer$1.streamInfo());
|
|
6866
6866
|
}
|
|
6867
|
-
function parseDocument(
|
|
6867
|
+
function parseDocument(source, options = {}) {
|
|
6868
6868
|
const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
|
|
6869
6869
|
const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
|
|
6870
6870
|
const composer$1 = new composer.Composer(options);
|
|
6871
6871
|
let doc = null;
|
|
6872
|
-
for (const _doc of composer$1.compose(parser$1.parse(
|
|
6872
|
+
for (const _doc of composer$1.compose(parser$1.parse(source), true, source.length)) {
|
|
6873
6873
|
if (!doc)
|
|
6874
6874
|
doc = _doc;
|
|
6875
6875
|
else if (doc.options.logLevel !== "silent") {
|
|
@@ -6878,8 +6878,8 @@ var require_public_api = __commonJS((exports) => {
|
|
|
6878
6878
|
}
|
|
6879
6879
|
}
|
|
6880
6880
|
if (prettyErrors && lineCounter2) {
|
|
6881
|
-
doc.errors.forEach(errors2.prettifyError(
|
|
6882
|
-
doc.warnings.forEach(errors2.prettifyError(
|
|
6881
|
+
doc.errors.forEach(errors2.prettifyError(source, lineCounter2));
|
|
6882
|
+
doc.warnings.forEach(errors2.prettifyError(source, lineCounter2));
|
|
6883
6883
|
}
|
|
6884
6884
|
return doc;
|
|
6885
6885
|
}
|
|
@@ -7096,156 +7096,6 @@ var FactRelation;
|
|
|
7096
7096
|
FactRelation2["Supersedes"] = "supersedes";
|
|
7097
7097
|
FactRelation2["References"] = "references";
|
|
7098
7098
|
})(FactRelation ||= {});
|
|
7099
|
-
// ../core/src/types/serverConfig.ts
|
|
7100
|
-
var DEFAULT_SERVER_CONFIG = {
|
|
7101
|
-
server: {
|
|
7102
|
-
port: 5100,
|
|
7103
|
-
host: "::"
|
|
7104
|
-
},
|
|
7105
|
-
git_hosts: [],
|
|
7106
|
-
daemon_scheduler: {
|
|
7107
|
-
enabled: true,
|
|
7108
|
-
host: "localhost",
|
|
7109
|
-
port: 5110,
|
|
7110
|
-
workspace: "./data/daemon-workspace",
|
|
7111
|
-
max_daemons: 20
|
|
7112
|
-
},
|
|
7113
|
-
doc_db: {
|
|
7114
|
-
provider: "sqlite",
|
|
7115
|
-
sqlite: {
|
|
7116
|
-
path: "./data/c4a.db"
|
|
7117
|
-
},
|
|
7118
|
-
mongodb: {
|
|
7119
|
-
uri: "mongodb://localhost:27017/c4a?directConnection=true",
|
|
7120
|
-
database: "c4a"
|
|
7121
|
-
}
|
|
7122
|
-
},
|
|
7123
|
-
graph_db: {
|
|
7124
|
-
provider: "neo4j",
|
|
7125
|
-
neo4j: {
|
|
7126
|
-
uri: "bolt://localhost:7687",
|
|
7127
|
-
username: "neo4j",
|
|
7128
|
-
password: ""
|
|
7129
|
-
},
|
|
7130
|
-
nebulagraph: {
|
|
7131
|
-
uri: "localhost:9669",
|
|
7132
|
-
username: "root",
|
|
7133
|
-
password: "nebula",
|
|
7134
|
-
space: "c4a"
|
|
7135
|
-
},
|
|
7136
|
-
duckdb: {
|
|
7137
|
-
path: "./data/c4a-graph.duckdb"
|
|
7138
|
-
}
|
|
7139
|
-
},
|
|
7140
|
-
vector_db: {
|
|
7141
|
-
provider: "lancedb",
|
|
7142
|
-
collection_prefix: "c4a_",
|
|
7143
|
-
qdrant: {
|
|
7144
|
-
url: "http://localhost:6333",
|
|
7145
|
-
api_key: ""
|
|
7146
|
-
},
|
|
7147
|
-
milvus: {
|
|
7148
|
-
address: "localhost:19530"
|
|
7149
|
-
},
|
|
7150
|
-
lancedb: {
|
|
7151
|
-
path: "./data/lancedb"
|
|
7152
|
-
}
|
|
7153
|
-
},
|
|
7154
|
-
llm: {
|
|
7155
|
-
provider: "openai",
|
|
7156
|
-
openai: {
|
|
7157
|
-
api_key: "",
|
|
7158
|
-
base_url: "",
|
|
7159
|
-
default_model: "gpt-5.3-codex",
|
|
7160
|
-
wire_api: "chat"
|
|
7161
|
-
},
|
|
7162
|
-
anthropic: {
|
|
7163
|
-
api_key: "",
|
|
7164
|
-
base_url: "",
|
|
7165
|
-
default_model: "claude-opus-4-6"
|
|
7166
|
-
},
|
|
7167
|
-
google: {
|
|
7168
|
-
api_key: "",
|
|
7169
|
-
base_url: "",
|
|
7170
|
-
default_model: "gemini-3-pro-preview"
|
|
7171
|
-
}
|
|
7172
|
-
},
|
|
7173
|
-
task: {
|
|
7174
|
-
concurrency: {
|
|
7175
|
-
code_index: 2,
|
|
7176
|
-
doc_index: 2,
|
|
7177
|
-
remote_clone: 2,
|
|
7178
|
-
modeling: 1
|
|
7179
|
-
},
|
|
7180
|
-
default_timeout_ms: 150 * 60 * 1000,
|
|
7181
|
-
memory_ttl_ms: 48 * 60 * 60 * 1000,
|
|
7182
|
-
cleanup_interval_ms: 10 * 60 * 1000,
|
|
7183
|
-
log_max_entries: 500
|
|
7184
|
-
},
|
|
7185
|
-
indexing: {
|
|
7186
|
-
task_timeout_ms: 150 * 60 * 1000,
|
|
7187
|
-
file_timeout_ms: 15 * 60 * 1000
|
|
7188
|
-
},
|
|
7189
|
-
intent_router: {
|
|
7190
|
-
provider: "huggingface",
|
|
7191
|
-
huggingface: {
|
|
7192
|
-
model_id: "context4ai/intent-router-onnx",
|
|
7193
|
-
cache_dir: "./models/intent-router"
|
|
7194
|
-
},
|
|
7195
|
-
xenova: {
|
|
7196
|
-
model_id: "context4ai/intent-router-onnx",
|
|
7197
|
-
cache_dir: "./models/intent-router"
|
|
7198
|
-
}
|
|
7199
|
-
},
|
|
7200
|
-
embedding: {
|
|
7201
|
-
provider: "huggingface",
|
|
7202
|
-
huggingface: {
|
|
7203
|
-
model_id: "Xenova/all-MiniLM-L6-v2",
|
|
7204
|
-
dtype: "q8",
|
|
7205
|
-
cache_dir: "./models/embedding"
|
|
7206
|
-
},
|
|
7207
|
-
xenova: {
|
|
7208
|
-
model_id: "Xenova/bge-m3",
|
|
7209
|
-
dtype: "q8",
|
|
7210
|
-
cache_dir: "./models/embedding"
|
|
7211
|
-
},
|
|
7212
|
-
openai: {
|
|
7213
|
-
api_key: "",
|
|
7214
|
-
base_url: "",
|
|
7215
|
-
model_id: "text-embedding-3-small"
|
|
7216
|
-
},
|
|
7217
|
-
google: {
|
|
7218
|
-
api_key: "",
|
|
7219
|
-
model_id: "text-embedding-004"
|
|
7220
|
-
}
|
|
7221
|
-
},
|
|
7222
|
-
reranker: {
|
|
7223
|
-
enabled: false,
|
|
7224
|
-
provider: "huggingface",
|
|
7225
|
-
huggingface: {
|
|
7226
|
-
model_id: "onnx-community/bge-reranker-v2-m3-ONNX",
|
|
7227
|
-
dtype: "q8",
|
|
7228
|
-
cache_dir: "./models/reranker"
|
|
7229
|
-
},
|
|
7230
|
-
xenova: {
|
|
7231
|
-
model_id: "onnx-community/bge-reranker-v2-m3-ONNX",
|
|
7232
|
-
dtype: "q8",
|
|
7233
|
-
cache_dir: "./models/reranker"
|
|
7234
|
-
},
|
|
7235
|
-
max_rerank: 20
|
|
7236
|
-
}
|
|
7237
|
-
};
|
|
7238
|
-
// ../core/src/types/daemon.ts
|
|
7239
|
-
var CODE_PACKAGE_FILES = new Set([
|
|
7240
|
-
"package.json",
|
|
7241
|
-
"pyproject.toml",
|
|
7242
|
-
"setup.py",
|
|
7243
|
-
"go.mod",
|
|
7244
|
-
"cargo.toml",
|
|
7245
|
-
"pom.xml",
|
|
7246
|
-
"build.gradle",
|
|
7247
|
-
"build.gradle.kts"
|
|
7248
|
-
]);
|
|
7249
7099
|
// ../../node_modules/.bun/zod@3.25.76/node_modules/zod/v3/external.js
|
|
7250
7100
|
var exports_external = {};
|
|
7251
7101
|
__export(exports_external, {
|
|
@@ -12386,9 +12236,9 @@ class ExtractionPluginRegistry {
|
|
|
12386
12236
|
register(plugin) {
|
|
12387
12237
|
this.#plugins.push(plugin);
|
|
12388
12238
|
}
|
|
12389
|
-
resolve(
|
|
12390
|
-
const declaredLanguage =
|
|
12391
|
-
const manifestLanguages = new Set(
|
|
12239
|
+
resolve(source) {
|
|
12240
|
+
const declaredLanguage = source.language?.toLowerCase();
|
|
12241
|
+
const manifestLanguages = new Set(source.manifests.flatMap((manifest) => MANIFEST_LANGUAGE_CANDIDATES[manifest.type] ?? []));
|
|
12392
12242
|
const candidates = this.#plugins.filter((plugin) => {
|
|
12393
12243
|
const pluginLanguages = plugin.languages.map((language) => language.toLowerCase());
|
|
12394
12244
|
if (declaredLanguage) {
|
|
@@ -12400,7 +12250,7 @@ class ExtractionPluginRegistry {
|
|
|
12400
12250
|
return pluginLanguages.some((language) => manifestLanguages.has(language));
|
|
12401
12251
|
});
|
|
12402
12252
|
for (const plugin of candidates) {
|
|
12403
|
-
if (plugin.canHandle(
|
|
12253
|
+
if (plugin.canHandle(source)) {
|
|
12404
12254
|
return plugin;
|
|
12405
12255
|
}
|
|
12406
12256
|
}
|
|
@@ -12503,29 +12353,29 @@ var resetParser = () => {
|
|
|
12503
12353
|
parsedBytesSinceReset = 0;
|
|
12504
12354
|
parserDead = false;
|
|
12505
12355
|
};
|
|
12506
|
-
var tryParse = async (
|
|
12356
|
+
var tryParse = async (source, isTsx) => {
|
|
12507
12357
|
const { parser, tsLanguage, tsxLanguage } = await initParser();
|
|
12508
12358
|
parser.setLanguage(isTsx ? tsxLanguage : tsLanguage);
|
|
12509
|
-
const tree = parser.parse(
|
|
12510
|
-
parsedBytesSinceReset +=
|
|
12359
|
+
const tree = parser.parse(source);
|
|
12360
|
+
parsedBytesSinceReset += source.length;
|
|
12511
12361
|
if (tree.rootNode.hasError()) {
|
|
12512
12362
|
return null;
|
|
12513
12363
|
}
|
|
12514
12364
|
return tree;
|
|
12515
12365
|
};
|
|
12516
|
-
var parseFile = async (
|
|
12366
|
+
var parseFile = async (source, isTsx) => {
|
|
12517
12367
|
if (parserDead)
|
|
12518
12368
|
return null;
|
|
12519
12369
|
if (parsedBytesSinceReset > PARSER_RESET_THRESHOLD) {
|
|
12520
12370
|
resetParser();
|
|
12521
12371
|
}
|
|
12522
12372
|
try {
|
|
12523
|
-
return await tryParse(
|
|
12373
|
+
return await tryParse(source, isTsx);
|
|
12524
12374
|
} catch {
|
|
12525
12375
|
resetParser();
|
|
12526
12376
|
}
|
|
12527
12377
|
try {
|
|
12528
|
-
return await tryParse(
|
|
12378
|
+
return await tryParse(source, isTsx);
|
|
12529
12379
|
} catch (error) {
|
|
12530
12380
|
console.warn("[extract] Parser unrecoverable after retry, skipping remaining files:", error);
|
|
12531
12381
|
parserDead = true;
|
|
@@ -12596,11 +12446,11 @@ var collectImportBindings = (root) => {
|
|
|
12596
12446
|
const stringNode = node2.namedChildren.find((child) => child.type === "string");
|
|
12597
12447
|
if (!stringNode)
|
|
12598
12448
|
continue;
|
|
12599
|
-
const
|
|
12449
|
+
const source = stripQuotes(stringNode.text);
|
|
12600
12450
|
const clause = node2.namedChildren.find((child) => child.type === "import_clause");
|
|
12601
12451
|
for (const part of clause?.namedChildren ?? []) {
|
|
12602
12452
|
if (part.type === "identifier") {
|
|
12603
|
-
bindings.set(part.text, { source
|
|
12453
|
+
bindings.set(part.text, { source, importedName: "default" });
|
|
12604
12454
|
continue;
|
|
12605
12455
|
}
|
|
12606
12456
|
if (part.type !== "named_imports")
|
|
@@ -12608,7 +12458,7 @@ var collectImportBindings = (root) => {
|
|
|
12608
12458
|
for (const specifier of part.namedChildren.filter((child) => child.type === "import_specifier")) {
|
|
12609
12459
|
const parsed = parseImportSpecifier(specifier);
|
|
12610
12460
|
if (parsed) {
|
|
12611
|
-
bindings.set(parsed.localName, { source
|
|
12461
|
+
bindings.set(parsed.localName, { source, importedName: parsed.importedName });
|
|
12612
12462
|
}
|
|
12613
12463
|
}
|
|
12614
12464
|
}
|
|
@@ -12648,8 +12498,8 @@ var traceFile = async (filePath, fs, state) => {
|
|
|
12648
12498
|
const promise = (async () => {
|
|
12649
12499
|
state.inFlight.add(filePath);
|
|
12650
12500
|
state.files.add(filePath);
|
|
12651
|
-
const
|
|
12652
|
-
const tree = await parseFile(
|
|
12501
|
+
const source = await fs.readFile(filePath);
|
|
12502
|
+
const tree = await parseFile(source, filePath.endsWith(".tsx"));
|
|
12653
12503
|
if (!tree)
|
|
12654
12504
|
return [];
|
|
12655
12505
|
const root = tree.rootNode;
|
|
@@ -12778,10 +12628,10 @@ var BUILTIN_TYPES = new Set([
|
|
|
12778
12628
|
"never",
|
|
12779
12629
|
"any"
|
|
12780
12630
|
]);
|
|
12781
|
-
var countLines = (
|
|
12782
|
-
if (!
|
|
12631
|
+
var countLines = (source) => {
|
|
12632
|
+
if (!source)
|
|
12783
12633
|
return 0;
|
|
12784
|
-
const parts =
|
|
12634
|
+
const parts = source.split(/\r\n|\r|\n/);
|
|
12785
12635
|
return parts[parts.length - 1] === "" ? parts.length - 1 : parts.length;
|
|
12786
12636
|
};
|
|
12787
12637
|
var createRelation = (type, from, to, isExternal, line) => ({
|
|
@@ -13278,14 +13128,14 @@ var collectImportBindings2 = async (root, filePath, fs, resolver, relations) =>
|
|
|
13278
13128
|
return bindings;
|
|
13279
13129
|
};
|
|
13280
13130
|
var analyzeFile = async (filePath, fs, resolver = { mappings: [] }) => {
|
|
13281
|
-
const
|
|
13282
|
-
const tree = await parseFile(
|
|
13131
|
+
const source = await fs.readFile(filePath);
|
|
13132
|
+
const tree = await parseFile(source, filePath.endsWith(".tsx"));
|
|
13283
13133
|
if (!tree) {
|
|
13284
13134
|
return {
|
|
13285
13135
|
declarations: new Map,
|
|
13286
13136
|
importBindings: new Map,
|
|
13287
13137
|
relations: [],
|
|
13288
|
-
lines: countLines(
|
|
13138
|
+
lines: countLines(source)
|
|
13289
13139
|
};
|
|
13290
13140
|
}
|
|
13291
13141
|
const root = tree.rootNode;
|
|
@@ -13313,7 +13163,7 @@ var analyzeFile = async (filePath, fs, resolver = { mappings: [] }) => {
|
|
|
13313
13163
|
declarations,
|
|
13314
13164
|
importBindings,
|
|
13315
13165
|
relations,
|
|
13316
|
-
lines: countLines(
|
|
13166
|
+
lines: countLines(source)
|
|
13317
13167
|
};
|
|
13318
13168
|
};
|
|
13319
13169
|
|
|
@@ -13425,8 +13275,8 @@ class TypeScriptPlugin {
|
|
|
13425
13275
|
languages = ["typescript", "tsx"];
|
|
13426
13276
|
packageManagers = ["npm"];
|
|
13427
13277
|
#lastDetection = null;
|
|
13428
|
-
canHandle(
|
|
13429
|
-
return
|
|
13278
|
+
canHandle(source) {
|
|
13279
|
+
return source.manifests.some((manifest) => manifest.type === "package.json");
|
|
13430
13280
|
}
|
|
13431
13281
|
async detectEntries(manifest, fs) {
|
|
13432
13282
|
const result = await detectEntries(manifest, fs);
|
|
@@ -13446,6 +13296,324 @@ class TypeScriptPlugin {
|
|
|
13446
13296
|
return result;
|
|
13447
13297
|
}
|
|
13448
13298
|
}
|
|
13299
|
+
// src/reactRouter.ts
|
|
13300
|
+
import * as ts from "typescript";
|
|
13301
|
+
function compact(value) {
|
|
13302
|
+
return value.replace(/\s+/gu, " ").trim();
|
|
13303
|
+
}
|
|
13304
|
+
function scalarValue(node2) {
|
|
13305
|
+
if (!node2)
|
|
13306
|
+
return;
|
|
13307
|
+
if (ts.isStringLiteralLike(node2) || ts.isNoSubstitutionTemplateLiteral(node2))
|
|
13308
|
+
return node2.text;
|
|
13309
|
+
if (ts.isNumericLiteral(node2))
|
|
13310
|
+
return Number(node2.text);
|
|
13311
|
+
if (node2.kind === ts.SyntaxKind.TrueKeyword)
|
|
13312
|
+
return true;
|
|
13313
|
+
if (node2.kind === ts.SyntaxKind.FalseKeyword)
|
|
13314
|
+
return false;
|
|
13315
|
+
return;
|
|
13316
|
+
}
|
|
13317
|
+
function findDynamicImport(node2) {
|
|
13318
|
+
let result;
|
|
13319
|
+
const visit = (child) => {
|
|
13320
|
+
if (result)
|
|
13321
|
+
return;
|
|
13322
|
+
if (ts.isCallExpression(child) && child.expression.kind === ts.SyntaxKind.ImportKeyword && child.arguments[0] && ts.isStringLiteralLike(child.arguments[0])) {
|
|
13323
|
+
result = child.arguments[0].text;
|
|
13324
|
+
return;
|
|
13325
|
+
}
|
|
13326
|
+
ts.forEachChild(child, visit);
|
|
13327
|
+
};
|
|
13328
|
+
visit(node2);
|
|
13329
|
+
return result;
|
|
13330
|
+
}
|
|
13331
|
+
function parseSource(source, filePath) {
|
|
13332
|
+
const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
13333
|
+
const imports = new Map;
|
|
13334
|
+
const constants2 = new Map;
|
|
13335
|
+
for (const statement of sourceFile.statements) {
|
|
13336
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {
|
|
13337
|
+
const moduleSource = statement.moduleSpecifier.text;
|
|
13338
|
+
const clause = statement.importClause;
|
|
13339
|
+
if (clause?.name)
|
|
13340
|
+
imports.set(clause.name.text, moduleSource);
|
|
13341
|
+
const bindings = clause?.namedBindings;
|
|
13342
|
+
if (bindings && ts.isNamedImports(bindings)) {
|
|
13343
|
+
for (const element of bindings.elements)
|
|
13344
|
+
imports.set(element.name.text, moduleSource);
|
|
13345
|
+
}
|
|
13346
|
+
if (bindings && ts.isNamespaceImport(bindings))
|
|
13347
|
+
imports.set(bindings.name.text, moduleSource);
|
|
13348
|
+
}
|
|
13349
|
+
if (!ts.isVariableStatement(statement))
|
|
13350
|
+
continue;
|
|
13351
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
13352
|
+
if (!ts.isIdentifier(declaration.name) || !declaration.initializer)
|
|
13353
|
+
continue;
|
|
13354
|
+
const scalar = scalarValue(declaration.initializer);
|
|
13355
|
+
if (scalar !== undefined)
|
|
13356
|
+
constants2.set(declaration.name.text, scalar);
|
|
13357
|
+
const dynamicImport = findDynamicImport(declaration.initializer);
|
|
13358
|
+
if (dynamicImport)
|
|
13359
|
+
imports.set(declaration.name.text, dynamicImport);
|
|
13360
|
+
}
|
|
13361
|
+
}
|
|
13362
|
+
return { sourceFile, imports, constants: constants2 };
|
|
13363
|
+
}
|
|
13364
|
+
function locationFor(filePath, sourceFile, node2) {
|
|
13365
|
+
const start = sourceFile.getLineAndCharacterOfPosition(node2.getStart(sourceFile));
|
|
13366
|
+
const end = sourceFile.getLineAndCharacterOfPosition(node2.getEnd());
|
|
13367
|
+
return { path: filePath, startLine: start.line + 1, startColumn: start.character + 1, endLine: end.line + 1, endColumn: end.character + 1 };
|
|
13368
|
+
}
|
|
13369
|
+
function joinRoutePath(parent, child, index) {
|
|
13370
|
+
if (index || !child || child === "/")
|
|
13371
|
+
return parent || "/";
|
|
13372
|
+
if (child.startsWith("/"))
|
|
13373
|
+
return child.replace(/\/{2,}/gu, "/");
|
|
13374
|
+
return `${parent.replace(/\/$/u, "")}/${child.replace(/^\//u, "")}`.replace(/\/{2,}/gu, "/");
|
|
13375
|
+
}
|
|
13376
|
+
function routeConditions(node2, sourceFile) {
|
|
13377
|
+
const conditions = [];
|
|
13378
|
+
let current = node2;
|
|
13379
|
+
while (current?.parent) {
|
|
13380
|
+
const parent = current.parent;
|
|
13381
|
+
if (ts.isConditionalExpression(parent)) {
|
|
13382
|
+
const condition = compact(parent.condition.getText(sourceFile));
|
|
13383
|
+
conditions.push(current === parent.whenTrue ? condition : `!(${condition})`);
|
|
13384
|
+
} else if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken && current === parent.right) {
|
|
13385
|
+
conditions.push(compact(parent.left.getText(sourceFile)));
|
|
13386
|
+
}
|
|
13387
|
+
if (ts.isFunctionLike(parent))
|
|
13388
|
+
break;
|
|
13389
|
+
current = parent;
|
|
13390
|
+
}
|
|
13391
|
+
return [...new Set(conditions.reverse())];
|
|
13392
|
+
}
|
|
13393
|
+
function jsxAttributes(node2) {
|
|
13394
|
+
const result = new Map;
|
|
13395
|
+
for (const property of node2.attributes.properties)
|
|
13396
|
+
if (ts.isJsxAttribute(property))
|
|
13397
|
+
result.set(property.name.getText(), property);
|
|
13398
|
+
return result;
|
|
13399
|
+
}
|
|
13400
|
+
function jsxExpression(attribute) {
|
|
13401
|
+
const initializer = attribute?.initializer;
|
|
13402
|
+
return initializer && ts.isJsxExpression(initializer) ? initializer.expression : undefined;
|
|
13403
|
+
}
|
|
13404
|
+
function jsxScalar(attribute, constants2) {
|
|
13405
|
+
if (!attribute)
|
|
13406
|
+
return;
|
|
13407
|
+
if (!attribute.initializer)
|
|
13408
|
+
return true;
|
|
13409
|
+
if (ts.isStringLiteral(attribute.initializer))
|
|
13410
|
+
return attribute.initializer.text;
|
|
13411
|
+
const expression = jsxExpression(attribute);
|
|
13412
|
+
return scalarValue(expression) ?? (expression && ts.isIdentifier(expression) ? constants2.get(expression.text) : undefined);
|
|
13413
|
+
}
|
|
13414
|
+
function descendantTags(node2) {
|
|
13415
|
+
const tags = new Set;
|
|
13416
|
+
const visit = (child) => {
|
|
13417
|
+
if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child)) {
|
|
13418
|
+
const opening = ts.isJsxElement(child) ? child.openingElement : child;
|
|
13419
|
+
const tag = opening.tagName.getText();
|
|
13420
|
+
if (child !== node2 && tag === "Route")
|
|
13421
|
+
return;
|
|
13422
|
+
if (!["Route", "Routes", "Suspense", "Fragment", "React.Fragment", "Navigate"].includes(tag))
|
|
13423
|
+
tags.add(tag);
|
|
13424
|
+
}
|
|
13425
|
+
ts.forEachChild(child, visit);
|
|
13426
|
+
};
|
|
13427
|
+
visit(node2);
|
|
13428
|
+
return [...tags];
|
|
13429
|
+
}
|
|
13430
|
+
function navigateTarget(node2, sourceFile) {
|
|
13431
|
+
let target;
|
|
13432
|
+
const visit = (child) => {
|
|
13433
|
+
if (target)
|
|
13434
|
+
return;
|
|
13435
|
+
if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child)) {
|
|
13436
|
+
const opening = ts.isJsxElement(child) ? child.openingElement : child;
|
|
13437
|
+
if (child !== node2 && opening.tagName.getText() === "Route")
|
|
13438
|
+
return;
|
|
13439
|
+
if (opening.tagName.getText() === "Navigate") {
|
|
13440
|
+
const attribute = jsxAttributes(opening).get("to");
|
|
13441
|
+
const scalar = jsxScalar(attribute, new Map);
|
|
13442
|
+
if (typeof scalar === "string")
|
|
13443
|
+
target = scalar;
|
|
13444
|
+
const expression = jsxExpression(attribute);
|
|
13445
|
+
if (!target && expression) {
|
|
13446
|
+
const text = expression.getText(sourceFile);
|
|
13447
|
+
target = text.match(/pathname\s*:\s*['"]([^'"]+)['"]/u)?.[1] ?? compact(text);
|
|
13448
|
+
}
|
|
13449
|
+
}
|
|
13450
|
+
}
|
|
13451
|
+
ts.forEachChild(child, visit);
|
|
13452
|
+
};
|
|
13453
|
+
visit(node2);
|
|
13454
|
+
return target;
|
|
13455
|
+
}
|
|
13456
|
+
function leadingNote(node2, sourceFile) {
|
|
13457
|
+
const prefix = sourceFile.text.slice(Math.max(0, node2.getFullStart() - 600), node2.getStart(sourceFile));
|
|
13458
|
+
const comments = [...prefix.matchAll(/\/\*+([\s\S]*?)\*\/|\/\/([^\n]*)/gu)];
|
|
13459
|
+
const value = comments.at(-1)?.[1] ?? comments.at(-1)?.[2];
|
|
13460
|
+
return value ? compact(value.replace(/^\s*\*\s?/gmu, "")) : undefined;
|
|
13461
|
+
}
|
|
13462
|
+
function componentSource(component, imports) {
|
|
13463
|
+
const identifier = component?.match(/[A-Za-z_$][\w$]*/u)?.[0];
|
|
13464
|
+
return identifier ? imports.get(identifier) : undefined;
|
|
13465
|
+
}
|
|
13466
|
+
function objectProperty(object2, name) {
|
|
13467
|
+
for (const property of object2.properties) {
|
|
13468
|
+
if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property))
|
|
13469
|
+
continue;
|
|
13470
|
+
const key = property.name && (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name)) ? property.name.text : undefined;
|
|
13471
|
+
if (key !== name)
|
|
13472
|
+
continue;
|
|
13473
|
+
return ts.isPropertyAssignment(property) ? property.initializer : property.name;
|
|
13474
|
+
}
|
|
13475
|
+
return;
|
|
13476
|
+
}
|
|
13477
|
+
function extractReactRouterRoutes(source, filePath, options = {}) {
|
|
13478
|
+
const parsed = parseSource(source, filePath);
|
|
13479
|
+
const routeIdPrefix = options.routeIdPrefix ?? filePath;
|
|
13480
|
+
const mountPath = options.mountPath ?? "/";
|
|
13481
|
+
const ignoredCandidates = new Set(options.ignoredComponentCandidates ?? []);
|
|
13482
|
+
const routes = [];
|
|
13483
|
+
const relativePath = (fullPath) => {
|
|
13484
|
+
if (mountPath === "/")
|
|
13485
|
+
return fullPath;
|
|
13486
|
+
if (fullPath === mountPath)
|
|
13487
|
+
return "/";
|
|
13488
|
+
return fullPath.startsWith(`${mountPath.replace(/\/$/u, "")}/`) ? fullPath.slice(mountPath.length) : fullPath;
|
|
13489
|
+
};
|
|
13490
|
+
const pushRoute = (input) => {
|
|
13491
|
+
const fullPath = joinRoutePath(input.parentPath, input.path, input.index);
|
|
13492
|
+
const candidates = input.candidates ?? (input.component ? [input.component] : []);
|
|
13493
|
+
const location = locationFor(filePath, parsed.sourceFile, input.node);
|
|
13494
|
+
const sourceModule = componentSource(input.component ?? candidates[0], parsed.imports);
|
|
13495
|
+
const note = leadingNote(input.node, parsed.sourceFile);
|
|
13496
|
+
routes.push({
|
|
13497
|
+
id: `${routeIdPrefix}:${fullPath}:${location.startLine}`,
|
|
13498
|
+
kind: input.redirectTo ? "redirect" : input.component || candidates.length > 0 ? "page" : "group",
|
|
13499
|
+
relativePath: relativePath(fullPath),
|
|
13500
|
+
fullPath,
|
|
13501
|
+
index: input.index,
|
|
13502
|
+
...input.component ? { component: input.component } : candidates[0] ? { component: candidates[0] } : {},
|
|
13503
|
+
...sourceModule ? { componentSource: sourceModule } : {},
|
|
13504
|
+
componentCandidates: candidates,
|
|
13505
|
+
...input.redirectTo ? { redirectTo: input.redirectTo } : {},
|
|
13506
|
+
conditions: routeConditions(input.node, parsed.sourceFile),
|
|
13507
|
+
...note ? { note } : {},
|
|
13508
|
+
location
|
|
13509
|
+
});
|
|
13510
|
+
if (input.children)
|
|
13511
|
+
visitRouteObjects(input.children, fullPath);
|
|
13512
|
+
};
|
|
13513
|
+
const visitRouteObjects = (array, parentPath) => {
|
|
13514
|
+
for (const element of array.elements) {
|
|
13515
|
+
if (!ts.isObjectLiteralExpression(element))
|
|
13516
|
+
continue;
|
|
13517
|
+
const index = scalarValue(objectProperty(element, "index")) === true;
|
|
13518
|
+
const pathValue = scalarValue(objectProperty(element, "path"));
|
|
13519
|
+
const componentNode = objectProperty(element, "Component") ?? objectProperty(element, "element") ?? objectProperty(element, "lazy");
|
|
13520
|
+
const component = componentNode ? compact(componentNode.getText(parsed.sourceFile)) : undefined;
|
|
13521
|
+
const redirectNode = objectProperty(element, "redirectTo") ?? objectProperty(element, "to");
|
|
13522
|
+
const redirect = scalarValue(redirectNode);
|
|
13523
|
+
const children = objectProperty(element, "children");
|
|
13524
|
+
pushRoute({
|
|
13525
|
+
node: element,
|
|
13526
|
+
parentPath,
|
|
13527
|
+
path: typeof pathValue === "string" ? pathValue : "",
|
|
13528
|
+
index,
|
|
13529
|
+
...component ? { component } : {},
|
|
13530
|
+
...typeof redirect === "string" ? { redirectTo: redirect } : {},
|
|
13531
|
+
...children && ts.isArrayLiteralExpression(children) ? { children } : {}
|
|
13532
|
+
});
|
|
13533
|
+
}
|
|
13534
|
+
};
|
|
13535
|
+
const visit = (node2, parentPath) => {
|
|
13536
|
+
if (ts.isJsxElement(node2) || ts.isJsxSelfClosingElement(node2)) {
|
|
13537
|
+
const opening = ts.isJsxElement(node2) ? node2.openingElement : node2;
|
|
13538
|
+
if (opening.tagName.getText() === "Route") {
|
|
13539
|
+
const attributes = jsxAttributes(opening);
|
|
13540
|
+
const index = jsxScalar(attributes.get("index"), parsed.constants) === true;
|
|
13541
|
+
const pathValue = jsxScalar(attributes.get("path"), parsed.constants);
|
|
13542
|
+
const componentNode = jsxExpression(attributes.get("Component"));
|
|
13543
|
+
const elementNode = jsxExpression(attributes.get("element"));
|
|
13544
|
+
const component = componentNode ? compact(componentNode.getText(parsed.sourceFile)) : undefined;
|
|
13545
|
+
const candidateNode = elementNode ?? componentNode ?? node2;
|
|
13546
|
+
const candidates = (component ? [component] : descendantTags(candidateNode)).filter((candidate) => !ignoredCandidates.has(candidate));
|
|
13547
|
+
const fullPath = joinRoutePath(parentPath, typeof pathValue === "string" ? pathValue : "", index);
|
|
13548
|
+
const redirectTo = navigateTarget(candidateNode, parsed.sourceFile);
|
|
13549
|
+
pushRoute({ node: node2, parentPath, path: typeof pathValue === "string" ? pathValue : "", index, ...component ? { component } : {}, candidates, ...redirectTo ? { redirectTo } : {} });
|
|
13550
|
+
if (ts.isJsxElement(node2))
|
|
13551
|
+
for (const child of node2.children)
|
|
13552
|
+
visit(child, fullPath);
|
|
13553
|
+
return;
|
|
13554
|
+
}
|
|
13555
|
+
}
|
|
13556
|
+
if (ts.isCallExpression(node2)) {
|
|
13557
|
+
const callee = node2.expression.getText(parsed.sourceFile);
|
|
13558
|
+
if ((callee === "createBrowserRouter" || callee === "createHashRouter" || callee === "useRoutes") && node2.arguments[0] && ts.isArrayLiteralExpression(node2.arguments[0])) {
|
|
13559
|
+
visitRouteObjects(node2.arguments[0], mountPath);
|
|
13560
|
+
}
|
|
13561
|
+
}
|
|
13562
|
+
ts.forEachChild(node2, (child) => visit(child, parentPath));
|
|
13563
|
+
};
|
|
13564
|
+
visit(parsed.sourceFile, mountPath);
|
|
13565
|
+
return routes.sort((left, right) => left.fullPath.localeCompare(right.fullPath) || left.location.startLine - right.location.startLine || left.location.startColumn - right.location.startColumn);
|
|
13566
|
+
}
|
|
13567
|
+
// src/moduleExports.ts
|
|
13568
|
+
import * as ts2 from "typescript";
|
|
13569
|
+
function exportedDeclarationName(statement) {
|
|
13570
|
+
const exported = ts2.canHaveModifiers(statement) && ts2.getModifiers(statement)?.some((modifier) => modifier.kind === ts2.SyntaxKind.ExportKeyword);
|
|
13571
|
+
if (!exported)
|
|
13572
|
+
return;
|
|
13573
|
+
if ((ts2.isFunctionDeclaration(statement) || ts2.isClassDeclaration(statement) || ts2.isInterfaceDeclaration(statement) || ts2.isTypeAliasDeclaration(statement) || ts2.isEnumDeclaration(statement)) && statement.name) {
|
|
13574
|
+
return statement.name.text;
|
|
13575
|
+
}
|
|
13576
|
+
return;
|
|
13577
|
+
}
|
|
13578
|
+
function extractTypeScriptModuleExports(source, filePath = "module.ts") {
|
|
13579
|
+
const sourceFile = ts2.createSourceFile(filePath, source, ts2.ScriptTarget.Latest, true, filePath.endsWith("x") ? ts2.ScriptKind.TSX : ts2.ScriptKind.TS);
|
|
13580
|
+
const named = new Set;
|
|
13581
|
+
const wildcard = new Set;
|
|
13582
|
+
const targets = new Set;
|
|
13583
|
+
for (const statement of sourceFile.statements) {
|
|
13584
|
+
if (ts2.isExportDeclaration(statement)) {
|
|
13585
|
+
const target = statement.moduleSpecifier && ts2.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : undefined;
|
|
13586
|
+
if (target)
|
|
13587
|
+
targets.add(target);
|
|
13588
|
+
if (!statement.exportClause) {
|
|
13589
|
+
if (target)
|
|
13590
|
+
wildcard.add(target);
|
|
13591
|
+
} else if (ts2.isNamedExports(statement.exportClause)) {
|
|
13592
|
+
for (const element of statement.exportClause.elements)
|
|
13593
|
+
named.add(element.name.text);
|
|
13594
|
+
} else if (ts2.isNamespaceExport(statement.exportClause)) {
|
|
13595
|
+
named.add(statement.exportClause.name.text);
|
|
13596
|
+
}
|
|
13597
|
+
continue;
|
|
13598
|
+
}
|
|
13599
|
+
const declarationName = exportedDeclarationName(statement);
|
|
13600
|
+
if (declarationName)
|
|
13601
|
+
named.add(declarationName);
|
|
13602
|
+
if (ts2.isVariableStatement(statement) && ts2.getModifiers(statement)?.some((modifier) => modifier.kind === ts2.SyntaxKind.ExportKeyword)) {
|
|
13603
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
13604
|
+
if (ts2.isIdentifier(declaration.name))
|
|
13605
|
+
named.add(declaration.name.text);
|
|
13606
|
+
}
|
|
13607
|
+
}
|
|
13608
|
+
}
|
|
13609
|
+
return {
|
|
13610
|
+
named: [...named].sort(),
|
|
13611
|
+
wildcard: [...wildcard].sort(),
|
|
13612
|
+
targets: [...targets].sort()
|
|
13613
|
+
};
|
|
13614
|
+
}
|
|
13449
13615
|
export {
|
|
13616
|
+
extractTypeScriptModuleExports,
|
|
13617
|
+
extractReactRouterRoutes,
|
|
13450
13618
|
TypeScriptPlugin
|
|
13451
13619
|
};
|