@orkestrel/guide 0.0.22 → 0.0.24
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/dist/src/core/index.cjs +58 -15
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +32 -15
- package/dist/src/core/index.d.ts +32 -15
- package/dist/src/core/index.js +58 -15
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +58 -15
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +11 -7
- package/dist/src/server/index.d.ts +11 -7
- package/dist/src/server/index.js +58 -15
- package/dist/src/server/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1311,7 +1311,14 @@ function extractHidden(source) {
|
|
|
1311
1311
|
}
|
|
1312
1312
|
/**
|
|
1313
1313
|
* Joins the declaration head starting at `start` into one space-separated
|
|
1314
|
-
* line, consuming lines until the first that ends with
|
|
1314
|
+
* line, consuming lines until the first that opens a body: one that ends with
|
|
1315
|
+
* `{`, or one that closes an empty body with `{}` or `{ }`.
|
|
1316
|
+
*
|
|
1317
|
+
* @remarks
|
|
1318
|
+
* A line ending with `{}` closes an empty body only when every angle, round,
|
|
1319
|
+
* and square bracket the head opened outside quoted text has closed; inside
|
|
1320
|
+
* one, `{}` is a type or an argument, and an arrow's `=>` closes nothing. A
|
|
1321
|
+
* head that reaches the next column-zero `export` line opens no body.
|
|
1315
1322
|
*
|
|
1316
1323
|
* @param lines - The file's source lines
|
|
1317
1324
|
* @param start - The index of the head's first line
|
|
@@ -1320,6 +1327,7 @@ function extractHidden(source) {
|
|
|
1320
1327
|
* @example
|
|
1321
1328
|
* ```ts
|
|
1322
1329
|
* joinHead(['export class X {'], 0) // { text: 'export class X {', end: 0 }
|
|
1330
|
+
* joinHead(['export interface Y extends X {}'], 0) // { text: 'export interface Y extends X {}', end: 0 }
|
|
1323
1331
|
* ```
|
|
1324
1332
|
*/
|
|
1325
1333
|
function joinHead(lines, start) {
|
|
@@ -1327,8 +1335,15 @@ function joinHead(lines, start) {
|
|
|
1327
1335
|
for (let index = start; index < lines.length; index += 1) {
|
|
1328
1336
|
const line = lines[index];
|
|
1329
1337
|
if (line === void 0) break;
|
|
1330
|
-
|
|
1331
|
-
if (
|
|
1338
|
+
const text = line.trimEnd();
|
|
1339
|
+
if (index > start && text.startsWith("export ")) return void 0;
|
|
1340
|
+
parts.push(index === start ? text : text.trimStart());
|
|
1341
|
+
if (text.endsWith("{")) return {
|
|
1342
|
+
text: parts.join(" "),
|
|
1343
|
+
end: index
|
|
1344
|
+
};
|
|
1345
|
+
const bare = parts.join(" ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/g, "");
|
|
1346
|
+
if ((bare.match(/</g)?.length ?? 0) <= (bare.match(/(?<!=)>/g)?.length ?? 0) && (bare.match(/\(/g)?.length ?? 0) <= (bare.match(/\)/g)?.length ?? 0) && (bare.match(/\[/g)?.length ?? 0) <= (bare.match(/\]/g)?.length ?? 0) && /\{\s*\}$/.test(text)) return {
|
|
1332
1347
|
text: parts.join(" "),
|
|
1333
1348
|
end: index
|
|
1334
1349
|
};
|
|
@@ -1369,12 +1384,14 @@ function escapeRegExp(value) {
|
|
|
1369
1384
|
* optional heritage clause between the identifier and the opening `{`; the identifier is the head's
|
|
1370
1385
|
* own run up to that list or clause, so it enters the key as literal text and no name reaches a
|
|
1371
1386
|
* `RegExp`. Body lines are the raw source between the head and the first projected column-zero `}`,
|
|
1372
|
-
* keeping JSDoc evidence intact
|
|
1387
|
+
* keeping JSDoc evidence intact; a head whose last line closes its own body with `{}` or `{ }`
|
|
1388
|
+
* records an empty body. Every balanced `<...>` span is removed from the head before its
|
|
1373
1389
|
* `extends` clause is read, so a `T extends Base` type parameter is never a base and `Base<T>`
|
|
1374
1390
|
* reads as `Base`; a class's `implements` clause and everything after it is excluded, and a
|
|
1375
1391
|
* qualified base such as `namespace.Base` is returned verbatim. The first head of a key that opens
|
|
1376
1392
|
* a column-zero close answers for that key: a head that opens none records nothing, and a later
|
|
1377
|
-
* head of a key already collected adds nothing
|
|
1393
|
+
* head of a key already collected adds nothing unless the earlier head recorded neither a body
|
|
1394
|
+
* nor bases, which declares nothing as {@link Source} reads it, so the later head replaces it.
|
|
1378
1395
|
*
|
|
1379
1396
|
* @param source - The file's source text to read
|
|
1380
1397
|
* @returns One entry per collected declaration, keyed `${keyword} ${name}`
|
|
@@ -1388,7 +1405,7 @@ function escapeRegExp(value) {
|
|
|
1388
1405
|
function collectDeclarations(source) {
|
|
1389
1406
|
const declarations = /* @__PURE__ */ new Map();
|
|
1390
1407
|
const opener = /^export (?:class|interface) /;
|
|
1391
|
-
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{
|
|
1408
|
+
const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
|
|
1392
1409
|
const lines = extractSourceLines(source);
|
|
1393
1410
|
const projected = lines.map((line) => line.code);
|
|
1394
1411
|
for (let index = 0; index < projected.length; index += 1) {
|
|
@@ -1401,14 +1418,22 @@ function collectDeclarations(source) {
|
|
|
1401
1418
|
const name = declared?.[2];
|
|
1402
1419
|
if (keyword === void 0 || name === void 0) continue;
|
|
1403
1420
|
const key = `${keyword} ${name}`;
|
|
1404
|
-
|
|
1421
|
+
const known = declarations.get(key);
|
|
1422
|
+
if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
|
|
1405
1423
|
let depth = 0;
|
|
1406
1424
|
let flat = "";
|
|
1407
|
-
for (const character of head.text.slice(`export ${key}`.length,
|
|
1425
|
+
for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
|
|
1408
1426
|
else if (character === ">") depth = Math.max(0, depth - 1);
|
|
1409
1427
|
else if (depth === 0) flat += character;
|
|
1410
1428
|
const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
|
|
1411
1429
|
const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(_orkestrel_contract.isNonEmptyString);
|
|
1430
|
+
if (head.text.endsWith("}")) {
|
|
1431
|
+
declarations.set(key, {
|
|
1432
|
+
body: [],
|
|
1433
|
+
bases
|
|
1434
|
+
});
|
|
1435
|
+
continue;
|
|
1436
|
+
}
|
|
1412
1437
|
for (let close = head.end + 1; close < projected.length; close += 1) {
|
|
1413
1438
|
if (projected[close] !== "}") continue;
|
|
1414
1439
|
declarations.set(key, {
|
|
@@ -2961,9 +2986,12 @@ var Guide = class {
|
|
|
2961
2986
|
* remain valid. `methods` resolves a declaration's members through its
|
|
2962
2987
|
* `extends` chain within the same module scope, keeping the keyword it started
|
|
2963
2988
|
* from; a base the scope does not declare contributes nothing. One declaration
|
|
2964
|
-
* answers
|
|
2965
|
-
* supplies its members and its bases, and a second file declaring the
|
|
2966
|
-
* adds nothing.
|
|
2989
|
+
* answers under each keyword: the first file in sorted key order that declares
|
|
2990
|
+
* the head supplies its members and its bases, and a second file declaring the
|
|
2991
|
+
* same name under that keyword adds nothing. The interface answers for a name,
|
|
2992
|
+
* and the class when no interface declares it; one file declaring the name as
|
|
2993
|
+
* both shapes, a TypeScript declaration merge, answers with both, own members
|
|
2994
|
+
* ahead of inherited ones and the interface's own first. Every reading derives once per instance from the immutable
|
|
2967
2995
|
* inventory and is reused — the scope's declaration map on the first `methods`
|
|
2968
2996
|
* or `examples` lookup, then each name's members and each example collection
|
|
2969
2997
|
* under the name asked for — so a reader asking twice reads the files once and
|
|
@@ -3003,6 +3031,7 @@ var Source = class {
|
|
|
3003
3031
|
#surface;
|
|
3004
3032
|
#hidden;
|
|
3005
3033
|
#declarations;
|
|
3034
|
+
#origins = /* @__PURE__ */ new Map();
|
|
3006
3035
|
constructor(options) {
|
|
3007
3036
|
this.#files = options.files;
|
|
3008
3037
|
this.#directories = normalizeDirectories(options.module);
|
|
@@ -3037,10 +3066,18 @@ var Source = class {
|
|
|
3037
3066
|
return examples;
|
|
3038
3067
|
}
|
|
3039
3068
|
#scanMethods(name) {
|
|
3040
|
-
const
|
|
3041
|
-
|
|
3042
|
-
const
|
|
3043
|
-
|
|
3069
|
+
const fromInterface = this.#members("interface", name, /* @__PURE__ */ new Set());
|
|
3070
|
+
const fromClass = this.#members("class", name, /* @__PURE__ */ new Set())?.filter((entry) => entry.name !== "constructor");
|
|
3071
|
+
const origin = this.#origin("interface", name);
|
|
3072
|
+
if (origin === void 0 || origin !== this.#origin("class", name)) return fromInterface ?? fromClass ?? [];
|
|
3073
|
+
const methods = /* @__PURE__ */ new Map();
|
|
3074
|
+
for (const entry of [
|
|
3075
|
+
...extractMemberMethods(this.#locate("interface", name)?.body ?? []),
|
|
3076
|
+
...extractMemberMethods(this.#locate("class", name)?.body ?? []),
|
|
3077
|
+
...fromInterface ?? [],
|
|
3078
|
+
...fromClass ?? []
|
|
3079
|
+
]) if (entry.name !== "constructor" && !methods.has(entry.name)) methods.set(entry.name, entry);
|
|
3080
|
+
return Array.from(methods.values()).sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
|
|
3044
3081
|
}
|
|
3045
3082
|
#scanExamples() {
|
|
3046
3083
|
const examples = [];
|
|
@@ -3130,6 +3167,9 @@ var Source = class {
|
|
|
3130
3167
|
if (this.#declarations === void 0) this.#declarations = this.#scanDeclarations();
|
|
3131
3168
|
return this.#declarations.get(`${keyword} ${name}`);
|
|
3132
3169
|
}
|
|
3170
|
+
#origin(keyword, name) {
|
|
3171
|
+
return this.#locate(keyword, name) === void 0 ? void 0 : this.#origins.get(`${keyword} ${name}`);
|
|
3172
|
+
}
|
|
3133
3173
|
#scanDeclarations() {
|
|
3134
3174
|
const declarations = /* @__PURE__ */ new Map();
|
|
3135
3175
|
for (const key of selectModuleKeys(this.#files, this.#directories)) {
|
|
@@ -3139,6 +3179,7 @@ var Source = class {
|
|
|
3139
3179
|
if (declarations.has(identity)) continue;
|
|
3140
3180
|
if (declaration.body.length === 0 && declaration.bases.length === 0) continue;
|
|
3141
3181
|
declarations.set(identity, declaration);
|
|
3182
|
+
this.#origins.set(identity, key);
|
|
3142
3183
|
}
|
|
3143
3184
|
}
|
|
3144
3185
|
return declarations;
|
|
@@ -3412,12 +3453,14 @@ var Parity = class Parity {
|
|
|
3412
3453
|
const groups = row.guide.methods();
|
|
3413
3454
|
const documented = groups.map((group) => group.interface);
|
|
3414
3455
|
const declared = new Set(row.source.surface().map((symbol) => symbol.name));
|
|
3456
|
+
const classes = new Set(row.source.surface().filter((symbol) => symbol.keyword === "class").map((symbol) => symbol.name));
|
|
3415
3457
|
for (const group of groups) {
|
|
3416
3458
|
const finding = compareMembership(row.entry.spec, group.interface, group.methods.map((entry) => entry.name), row.source.methods(group.interface).map((entry) => entry.name));
|
|
3417
3459
|
if (finding !== void 0) findings.push(finding);
|
|
3418
3460
|
}
|
|
3419
3461
|
for (const symbol of row.source.surface()) {
|
|
3420
3462
|
if (symbol.keyword !== "interface" && symbol.keyword !== "class") continue;
|
|
3463
|
+
if (symbol.keyword === "interface" && classes.has(symbol.name)) continue;
|
|
3421
3464
|
const members = row.source.methods(symbol.name).map((entry) => entry.name);
|
|
3422
3465
|
if (members.length === 0) continue;
|
|
3423
3466
|
const contract = `${symbol.name}Interface`;
|