@voxgig/apidef 8.33.3 → 8.34.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/dist/guide/heuristic01.d.ts +1 -1
- package/dist/guide/heuristic01.js +66 -10
- package/dist/guide/heuristic01.js.map +1 -1
- package/dist/transform/entity.js +5 -4
- package/dist/transform/entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility.d.ts +5 -2
- package/dist/utility.js +41 -3
- package/dist/utility.js.map +1 -1
- package/package.json +1 -1
- package/src/guide/heuristic01.ts +79 -9
- package/src/transform/entity.ts +6 -4
- package/src/utility.ts +44 -3
package/src/transform/entity.ts
CHANGED
|
@@ -24,6 +24,7 @@ import type {
|
|
|
24
24
|
|
|
25
25
|
import {
|
|
26
26
|
canonize, cmpRefName, depluralize, foldName, guideActive, guideParts, guidePath, isParam,
|
|
27
|
+
selectorParts, selectorPath,
|
|
27
28
|
paramName, paramOf, READ_METHODS, routeParams,
|
|
28
29
|
} from '../utility'
|
|
29
30
|
|
|
@@ -366,9 +367,10 @@ function mergeCommandEntities(guide: any, log?: any): string[] {
|
|
|
366
367
|
// are. Guide stage only.
|
|
367
368
|
function separateSharedPoints(guide: any, def: any, log?: any): string[] {
|
|
368
369
|
const separated: string[] = []
|
|
369
|
-
const literals = (key: string) =>
|
|
370
|
+
const literals = (key: string) => selectorParts(key).filter((part: string) => !isParam(part))
|
|
370
371
|
const actionOf = (lits: string[]) => lits
|
|
371
|
-
.map((lit: string) => snakify(lit.replace(/\.?\{[^}]*\}/g, '')
|
|
372
|
+
.map((lit: string) => snakify(lit.replace(/\.?\{[^}]*\}/g, '').replace(/\./g, '_'))
|
|
373
|
+
.replace(/[^a-zA-Z0-9_]/g, ''))
|
|
372
374
|
.filter((word: string) => '' !== word).join('_')
|
|
373
375
|
|
|
374
376
|
for (const ename of Object.keys(guide.entity ?? {}).sort(byCodePoint)) {
|
|
@@ -399,7 +401,7 @@ function separateSharedPoints(guide: any, def: any, log?: any): string[] {
|
|
|
399
401
|
const paths = groups[key].filter((pathStr: string) =>
|
|
400
402
|
0 === Object.keys(entity.path[pathStr]?.action ?? {}).length)
|
|
401
403
|
const names = (key: string) => depluralize(snakify(literals(key).pop() ?? '')) === ename ? 0 : 1
|
|
402
|
-
const keys = [...new Set(paths.map(
|
|
404
|
+
const keys = [...new Set(paths.map(selectorPath))].sort((a: string, b: string) =>
|
|
403
405
|
names(a) - names(b) || literals(a).length - literals(b).length ||
|
|
404
406
|
a.length - b.length || byCodePoint(a, b))
|
|
405
407
|
if (keys.length < 2) continue
|
|
@@ -411,7 +413,7 @@ function separateSharedPoints(guide: any, def: any, log?: any): string[] {
|
|
|
411
413
|
if ('' === action || taken.has(action)) action = actionOf(literals(other))
|
|
412
414
|
if ('' === action || taken.has(action)) continue
|
|
413
415
|
taken.add(action)
|
|
414
|
-
for (const pathStr of paths.filter((p: string) =>
|
|
416
|
+
for (const pathStr of paths.filter((p: string) => selectorPath(p) === other)) {
|
|
415
417
|
entity.path[pathStr].action = {
|
|
416
418
|
[action]: { why_action: ['ent', ename, 'shared-selector', plain] }
|
|
417
419
|
}
|
package/src/utility.ts
CHANGED
|
@@ -1261,7 +1261,18 @@ function stripSchemaNamespace(name: string): string {
|
|
|
1261
1261
|
// uniformly wherever schema refs are counted or resolved (MeasureRef,
|
|
1262
1262
|
// ResolveEntityComponent, findcmps) so the metric keys stay consistent.
|
|
1263
1263
|
function canonizeCmpName(orig: string): string {
|
|
1264
|
-
return canonize(stripSchemaNamespace(orig))
|
|
1264
|
+
return canonize(stripToolAffixes(stripSchemaNamespace(orig)))
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
const TOOL_SUFFIX_RE = /^(.*[a-z0-9])(Output|Input)$/
|
|
1269
|
+
|
|
1270
|
+
// A generator's module path and its Output or Input are no part of a name.
|
|
1271
|
+
function stripToolAffixes(name: string): string {
|
|
1272
|
+
if (null == name) return name
|
|
1273
|
+
const at = name.lastIndexOf('__')
|
|
1274
|
+
const bare = 0 < at && at + 2 < name.length ? name.slice(at + 2) : name
|
|
1275
|
+
return bare.match(TOOL_SUFFIX_RE)?.[1] ?? bare
|
|
1265
1276
|
}
|
|
1266
1277
|
|
|
1267
1278
|
|
|
@@ -1297,6 +1308,15 @@ const FORMAT_EXTENSIONS = new Set([
|
|
|
1297
1308
|
// repos.json and data.{format} are repos and data, and a format alone (json)
|
|
1298
1309
|
// names nothing.
|
|
1299
1310
|
function guideSegment(seg0: string): string | null {
|
|
1311
|
+
const seg = seg0.replace(/\$\{/g, '{')
|
|
1312
|
+
const dot = dotOutsidePlaceholder(seg)
|
|
1313
|
+
if (0 === dot) return null
|
|
1314
|
+
if (0 < dot) return seg.slice(0, dot)
|
|
1315
|
+
return FORMAT_EXTENSIONS.has(seg.toLowerCase()) ? null : seg
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
// A segment as a selector: a format dropped, a dotted name kept whole.
|
|
1319
|
+
function selectorSegment(seg0: string): string | null {
|
|
1300
1320
|
const seg = seg0.replace(/\$\{/g, '{')
|
|
1301
1321
|
const held = seg.match(/^(\{[^}]+\})\.(?:[A-Za-z0-9]+|\{[^}]+\})$/)
|
|
1302
1322
|
if (null != held) return held[1]
|
|
@@ -1307,13 +1327,24 @@ function guideSegment(seg0: string): string | null {
|
|
|
1307
1327
|
return FORMAT_EXTENSIONS.has(seg.toLowerCase()) ? null : seg
|
|
1308
1328
|
}
|
|
1309
1329
|
|
|
1330
|
+
// What precedes this dot names a segment; what follows does not.
|
|
1331
|
+
function dotOutsidePlaceholder(seg: string): number {
|
|
1332
|
+
let depth = 0
|
|
1333
|
+
for (let i = 0; i < seg.length; i++) {
|
|
1334
|
+
const c = seg[i]
|
|
1335
|
+
depth += '{' === c ? 1 : '}' === c ? -1 : 0
|
|
1336
|
+
if ('.' === c && 0 === depth) return i
|
|
1337
|
+
}
|
|
1338
|
+
return -1
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1310
1341
|
// The guide's parts of a route, query and fragment cut; a route that is all
|
|
1311
1342
|
// fragment, or of formats alone, keeps them.
|
|
1312
|
-
function guideParts(path: string): string[] {
|
|
1343
|
+
function guideParts(path: string, segment = guideSegment): string[] {
|
|
1313
1344
|
const split = (route: string) => route.replace(/\?.*$/, '').split('/').filter((p: string) => '' !== p)
|
|
1314
1345
|
const cut = split(path.replace(/#.*$/, ''))
|
|
1315
1346
|
const parts = 0 === cut.length ? split(path) : cut
|
|
1316
|
-
const kept = parts.map(
|
|
1347
|
+
const kept = parts.map(segment).filter((p): p is string => null != p)
|
|
1317
1348
|
return 0 === kept.length ? parts : kept
|
|
1318
1349
|
}
|
|
1319
1350
|
|
|
@@ -1321,6 +1352,14 @@ function guidePath(path: string): string {
|
|
|
1321
1352
|
return '/' + guideParts(path).join('/')
|
|
1322
1353
|
}
|
|
1323
1354
|
|
|
1355
|
+
function selectorParts(path: string): string[] {
|
|
1356
|
+
return guideParts(path, selectorSegment)
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
function selectorPath(path: string): string {
|
|
1360
|
+
return '/' + selectorParts(path).join('/')
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1324
1363
|
|
|
1325
1364
|
// aontu cannot unify a spread with a key Object.prototype owns, so no entity
|
|
1326
1365
|
// is given one of these names. Listed, not read, so both ports agree.
|
|
@@ -2854,6 +2893,8 @@ export {
|
|
|
2854
2893
|
guardPrototypeName,
|
|
2855
2894
|
guideParts,
|
|
2856
2895
|
guidePath,
|
|
2896
|
+
selectorParts,
|
|
2897
|
+
selectorPath,
|
|
2857
2898
|
stripOperationVerb,
|
|
2858
2899
|
debugpath,
|
|
2859
2900
|
debugpathOn,
|