@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
|
@@ -100,7 +100,7 @@ declare function verbOfItem(data: {
|
|
|
100
100
|
parent: string;
|
|
101
101
|
action: string;
|
|
102
102
|
} | null;
|
|
103
|
-
declare function shortLiteral(pm: PathMatch): boolean;
|
|
103
|
+
declare function shortLiteral(pm: PathMatch, parts: string[]): boolean;
|
|
104
104
|
declare function nounless(pm: PathMatch, parts: string[]): boolean;
|
|
105
105
|
declare function responsePayload(schema: any): {
|
|
106
106
|
scalars: boolean;
|
|
@@ -106,13 +106,23 @@ const VERB_WORDS = new Set([
|
|
|
106
106
|
'accept', 'decline', 'notify', 'ping', 'count', 'exists', 'preview', 'render', 'generate',
|
|
107
107
|
'calculate', 'compute', 'convert', 'process', 'trigger', 'dispatch', 'apply', 'revoke',
|
|
108
108
|
'grant', 'save', 'lock', 'test', 'inject', 'analyze', 'autocomplete', 'bypass', 'contains',
|
|
109
|
-
'finish', 'reorder', 'shuffle',
|
|
109
|
+
'finish', 'reorder', 'shuffle', 'show', 'award', 'authorize', 'reload',
|
|
110
110
|
]);
|
|
111
|
+
// A bare number is a release or an index, never a noun.
|
|
112
|
+
const NUMBER_PART_RE = /^\d+$/;
|
|
111
113
|
// A literal that names an identifier keys a resource rather than naming one.
|
|
112
114
|
const ID_LITERAL_RE = /(^|_)ids?$/;
|
|
113
115
|
// A component named for one of these, alone or as the bare member of a family
|
|
114
116
|
// of results, names no entity.
|
|
115
117
|
const GENERIC_CMP_WORDS = ['default', 'empty', 'ok', 'response', 'result', 'success', 'void'];
|
|
118
|
+
// A name made only of these words, as ResponseListResource, names nothing.
|
|
119
|
+
const GENERIC_NAME_WORDS = [...GENERIC_CMP_WORDS, 'list', 'resource'];
|
|
120
|
+
// A generic word and a number, as a generator names what it was not told
|
|
121
|
+
// to name: Example17, Model3, InlineObject2.
|
|
122
|
+
const GENERATED_CMP_RE = /^(example|model|schema|body|inline|inline_object|object)_?\d+$/;
|
|
123
|
+
// The body a generator names for the operation it is sent to,
|
|
124
|
+
// Body_create_item_items_post, names nothing either.
|
|
125
|
+
const OPERATION_BODY_RE = /^body_.+_(get|put|post|patch|delete)$/;
|
|
116
126
|
// A version tag groups routes by release, not by resource.
|
|
117
127
|
const VERSION_TAG_RE = /^v\d+([a-z]+\d*)?$/;
|
|
118
128
|
exports.VERSION_TAG_RE = VERSION_TAG_RE;
|
|
@@ -832,7 +842,8 @@ function collectionOwner(mdesc, parts, work) {
|
|
|
832
842
|
// is named for what it reads or sends.
|
|
833
843
|
function pathEntityName(data, mdesc, parts, pm, pathowner, why) {
|
|
834
844
|
const ment = mdesc.MethodEntity;
|
|
835
|
-
const joined = methodOf(mdesc.path) ??
|
|
845
|
+
const joined = methodOf(mdesc.path) ?? procedureOf(mdesc.path) ??
|
|
846
|
+
idsOfItem(data, parts, pathowner) ?? singletonPartOf(data, parts, pathowner) ??
|
|
836
847
|
readOfItem(data, mdesc, parts, pathowner);
|
|
837
848
|
if (null != joined) {
|
|
838
849
|
ment.verb_on_parent = parts[parts.length - 1] ?? joined.action;
|
|
@@ -911,7 +922,7 @@ function pathEntityName(data, mdesc, parts, pm, pathowner, why) {
|
|
|
911
922
|
// A short literal names nothing: the component the route answers, else
|
|
912
923
|
// the route's key, else what a route with no literal is named by, else the
|
|
913
924
|
// padded literal.
|
|
914
|
-
if (null != pm && shortLiteral(pm)) {
|
|
925
|
+
if (null != pm && shortLiteral(pm, parts)) {
|
|
915
926
|
why.push('short-literal');
|
|
916
927
|
const answered = answeredCmp(mdesc);
|
|
917
928
|
if (null != answered) {
|
|
@@ -1175,7 +1186,8 @@ function FindActions(spec) {
|
|
|
1175
1186
|
if (null != ment.same_path) {
|
|
1176
1187
|
return;
|
|
1177
1188
|
}
|
|
1178
|
-
const parts = verbParts(spec.data.work.pathmap[pathStr].parts)
|
|
1189
|
+
const parts = verbParts(spec.data.work.pathmap[pathStr].parts)
|
|
1190
|
+
.filter((part, i, all) => all.length - 1 === i || !NUMBER_PART_RE.test(part));
|
|
1179
1191
|
const fourthLastPart = parts[parts.length - 4];
|
|
1180
1192
|
const fourthLastPartCanon = (0, utility_1.literalName)(fourthLastPart);
|
|
1181
1193
|
const thirdLastPart = parts[parts.length - 3];
|
|
@@ -1521,7 +1533,9 @@ function BuildEntity(spec) {
|
|
|
1521
1533
|
}
|
|
1522
1534
|
function genericCmp(name, refs, schema) {
|
|
1523
1535
|
if (GENERIC_CMP_WORDS.includes(name) || ID_LITERAL_RE.test(name) || emptyObjectSchema(schema) ||
|
|
1524
|
-
('object' === name && 0 === Object.keys((0, utility_2.mergedProperties)(schema) ?? {}).length)
|
|
1536
|
+
('object' === name && 0 === Object.keys((0, utility_2.mergedProperties)(schema) ?? {}).length) ||
|
|
1537
|
+
GENERATED_CMP_RE.test(name) || OPERATION_BODY_RE.test(name) ||
|
|
1538
|
+
(name.includes('_') && name.split('_').every((word) => GENERIC_NAME_WORDS.includes(word)))) {
|
|
1525
1539
|
return true;
|
|
1526
1540
|
}
|
|
1527
1541
|
const at = name.lastIndexOf('_');
|
|
@@ -1587,7 +1601,7 @@ function pathNoun(pm, parts, why) {
|
|
|
1587
1601
|
const lit = (0, jostraca_2.snakify)(parts[at]);
|
|
1588
1602
|
if (null != custom || (isVerbWord(parts[at]) && !keyedBy(parts[at + 1], name))) {
|
|
1589
1603
|
for (let i = at - 1; 0 <= i; i--) {
|
|
1590
|
-
if (!isParam(parts[i])) {
|
|
1604
|
+
if (!isParam(parts[i]) && !NUMBER_PART_RE.test(parts[i])) {
|
|
1591
1605
|
// A version segment ends the base path, so no noun precedes the verb.
|
|
1592
1606
|
if (VERSION_TAG_RE.test(parts[i].toLowerCase())) {
|
|
1593
1607
|
break;
|
|
@@ -1845,6 +1859,35 @@ function methodOf(pathStr) {
|
|
|
1845
1859
|
const action = 2 <= names.length ? (0, jostraca_2.snakify)(names[names.length - 1]) : '';
|
|
1846
1860
|
return '' === parent || '' === action ? null : { parent, action, why: 'method-name' };
|
|
1847
1861
|
}
|
|
1862
|
+
// A list of identifiers beneath an item key, and each identifier in it, is
|
|
1863
|
+
// an action of that item: `/lists/{id}/ids` and `/lists/{id}/ids/{itemId}`.
|
|
1864
|
+
function idsOfItem(data, parts, pathowner) {
|
|
1865
|
+
const at = isParam(parts[parts.length - 1] ?? '') ? parts.length - 2 : parts.length - 1;
|
|
1866
|
+
if (at < 2 || isParam(parts[at]) || !isParam(parts[at - 1]) ||
|
|
1867
|
+
'ids' !== (0, jostraca_2.snakify)(parts[at]).replace(/^.*_/, '')) {
|
|
1868
|
+
return null;
|
|
1869
|
+
}
|
|
1870
|
+
const route = pathNamed(data, '/' + parts.slice(0, at).join('/'));
|
|
1871
|
+
const owners = null == route ? {} : (pathowner[route] ?? {});
|
|
1872
|
+
const parent = owners.GET ?? owners.QUERY ?? Object.values(owners).sort()[0];
|
|
1873
|
+
return null == parent ? null : { parent, action: (0, jostraca_2.snakify)(parts[at]), why: 'ids-of-item' };
|
|
1874
|
+
}
|
|
1875
|
+
// Verbs a remote procedure opens with beside the verb words.
|
|
1876
|
+
const PROCEDURE_VERBS = ['put', 'set', 'post'];
|
|
1877
|
+
// A remote procedure in an `Action=` value or after a segment's last dot: the
|
|
1878
|
+
// object after its verb names the entity, and the verb is the action.
|
|
1879
|
+
function procedureOf(pathStr) {
|
|
1880
|
+
const segs = pathStr.replace(/[?#].*$/, '').split('/');
|
|
1881
|
+
const action = pathStr.match(/[#?&]Action=([A-Za-z][A-Za-z0-9_]*)/)?.[1];
|
|
1882
|
+
const named = action ?? segs[segs.length - 1].match(/^[^{}]*\.([A-Za-z][A-Za-z0-9_]*)$/)?.[1];
|
|
1883
|
+
const words = null == named ? [] : (0, utility_2.canonize)(named).split('_');
|
|
1884
|
+
// An Action value may open with a word before its verb, as Batch does; a
|
|
1885
|
+
// dotted name only with the verb, so a class name is not read as one.
|
|
1886
|
+
const verb = words.slice(0, null == action ? 1 : 2).findIndex((word) => VERB_WORDS.has(word) || PROCEDURE_VERBS.includes(word));
|
|
1887
|
+
const parent = verb < 0 ? '' : words.slice(verb + 1).join('_');
|
|
1888
|
+
return parent.replace(/_/g, '').length < 3 ? null :
|
|
1889
|
+
{ parent, action: words.slice(0, verb + 1).join('_'), why: 'procedure' };
|
|
1890
|
+
}
|
|
1848
1891
|
// A sub-path of a keyless singleton, read, written and deleted with no schema
|
|
1849
1892
|
// and no key beneath it, is an action of that singleton, plural or not.
|
|
1850
1893
|
function singletonPartOf(data, parts, pathowner) {
|
|
@@ -1881,6 +1924,15 @@ function readOfItem(data, mdesc, parts, pathowner) {
|
|
|
1881
1924
|
if (key < 0 || lastLit < 0) {
|
|
1882
1925
|
return null;
|
|
1883
1926
|
}
|
|
1927
|
+
// A key of its literal's collection reads the item; a modifier, as a size,
|
|
1928
|
+
// after a literal that is no download itself, makes a download.
|
|
1929
|
+
const tail = parts[parts.length - 1];
|
|
1930
|
+
const prefix = pathNamed(data, '/' + parts.slice(0, -1).join('/'));
|
|
1931
|
+
const prefixRead = null == prefix ? null : data.def?.paths?.[prefix]?.get;
|
|
1932
|
+
if (isParam(tail) && (keyedBy(tail, (0, utility_1.literalName)(parts[lastLit])) || (null != prefix &&
|
|
1933
|
+
!(null != prefixRead && binaryResponse(prefixRead.responses))))) {
|
|
1934
|
+
return null;
|
|
1935
|
+
}
|
|
1884
1936
|
const literals = parts.slice(key + 1).filter((part) => !isParam(part));
|
|
1885
1937
|
const detail = parts.length - 1 === lastLit && key === lastLit - 1 &&
|
|
1886
1938
|
ITEM_READ_WORDS.includes((0, utility_1.literalName)(parts[lastLit]));
|
|
@@ -2012,9 +2064,10 @@ function verbActionName(literals) {
|
|
|
2012
2064
|
(0, jostraca_2.snakify)(lit.replace(/\.?\{[^}]*\}/g, '')).replace(/[^a-zA-Z0-9_]/g, ''))
|
|
2013
2065
|
.join('_');
|
|
2014
2066
|
}
|
|
2015
|
-
// A literal too short for a word names nothing.
|
|
2016
|
-
function shortLiteral(pm) {
|
|
2017
|
-
|
|
2067
|
+
// A literal too short for a word names nothing, nor does a verb whose noun is.
|
|
2068
|
+
function shortLiteral(pm, parts) {
|
|
2069
|
+
const short = (lit) => (0, utility_2.canonize)(lit).replace(/_/g, '').length < 3;
|
|
2070
|
+
return short(pm[PATH_NAME_INDEX[pm.expr]]) || short(pathNoun(pm, parts, []));
|
|
2018
2071
|
}
|
|
2019
2072
|
// The naming literal is a generic word, or a verb word with no literal
|
|
2020
2073
|
// before it in the path.
|
|
@@ -2022,7 +2075,7 @@ function nounless(pm, parts) {
|
|
|
2022
2075
|
const at = pm.index + PATH_NAME_INDEX[pm.expr];
|
|
2023
2076
|
const name = (0, utility_1.literalName)(parts[at]);
|
|
2024
2077
|
return GENERIC_WORDS.includes(name) ||
|
|
2025
|
-
(
|
|
2078
|
+
(isVerbWord(parts[at]) && parts.slice(0, at).every((part) => isParam(part)));
|
|
2026
2079
|
}
|
|
2027
2080
|
// The component a route answers with, cleaned, when no tag stands for it.
|
|
2028
2081
|
function answeredCmp(mdesc) {
|
|
@@ -2248,6 +2301,9 @@ function commandBodyName(data, mdesc) {
|
|
|
2248
2301
|
return null;
|
|
2249
2302
|
}
|
|
2250
2303
|
let name = cleanCmp(data, (0, utility_2.canonizeCmpName)((0, utility_2.cmpRefName)(xref)));
|
|
2304
|
+
if (GENERATED_CMP_RE.test(name) || OPERATION_BODY_RE.test(name)) {
|
|
2305
|
+
return null;
|
|
2306
|
+
}
|
|
2251
2307
|
for (;;) {
|
|
2252
2308
|
const suffix = COMMAND_SUFFIXES.find((sfx) => name.endsWith(sfx) && sfx.length < name.length);
|
|
2253
2309
|
if (null == suffix) {
|