@sortlist/cli 0.51.0 → 0.52.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/index.js +69 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1106,6 +1106,21 @@ function buildSelections(type, schema, depth, exclude, prefix, totalCount, visit
|
|
|
1106
1106
|
const namedType = unwrap(field.type);
|
|
1107
1107
|
if (isLeaf(namedType)) {
|
|
1108
1108
|
lines.push(name);
|
|
1109
|
+
} else if (isObjectType(namedType) && isConnection(namedType) && field.args.length === 0) {
|
|
1110
|
+
const pageSelections = buildSelections(
|
|
1111
|
+
namedType,
|
|
1112
|
+
schema,
|
|
1113
|
+
depth,
|
|
1114
|
+
exclude,
|
|
1115
|
+
`${fullPath}.`,
|
|
1116
|
+
totalCount,
|
|
1117
|
+
new Set(visited)
|
|
1118
|
+
);
|
|
1119
|
+
if (pageSelections.length > 0) {
|
|
1120
|
+
lines.push(`${name} {`);
|
|
1121
|
+
for (const sel of pageSelections) lines.push(` ${sel}`);
|
|
1122
|
+
lines.push(`}`);
|
|
1123
|
+
}
|
|
1109
1124
|
} else if (isObjectType(namedType) && depth > 0) {
|
|
1110
1125
|
const subSelections = buildSelections(
|
|
1111
1126
|
namedType,
|
|
@@ -1156,9 +1171,16 @@ function fieldCall(name, field) {
|
|
|
1156
1171
|
const pageable = isObjectType(named) && isConnection(named) && field.args.some((a) => a.name === "first");
|
|
1157
1172
|
return pageable ? `${name}(first: ${NESTED_PAGE_SIZE})` : name;
|
|
1158
1173
|
}
|
|
1174
|
+
function deliveredPageField(type) {
|
|
1175
|
+
const pages = Object.values(type.getFields()).filter((field) => {
|
|
1176
|
+
const named = unwrap(field.type);
|
|
1177
|
+
return isObjectType(named) && isConnection(named) && field.args.length === 0;
|
|
1178
|
+
});
|
|
1179
|
+
return pages.length === 1 ? pages[0] : null;
|
|
1180
|
+
}
|
|
1159
1181
|
function isConnection(type) {
|
|
1160
1182
|
const fields = type.getFields();
|
|
1161
|
-
return
|
|
1183
|
+
return Boolean(fields.nodes) && Boolean(fields.pageInfo);
|
|
1162
1184
|
}
|
|
1163
1185
|
function isAutoSelectable(field) {
|
|
1164
1186
|
if (field.name.startsWith("__") || field.deprecationReason != null) return false;
|
|
@@ -1297,9 +1319,11 @@ ${selectionBody}
|
|
|
1297
1319
|
}`;
|
|
1298
1320
|
return { query, variables, fieldName };
|
|
1299
1321
|
}
|
|
1300
|
-
function buildFieldsFromList(type, schema,
|
|
1322
|
+
function buildFieldsFromList(type, schema, requestedPaths, totalCount) {
|
|
1301
1323
|
if (!isObjectType(type)) return [];
|
|
1302
1324
|
const fields = type.getFields();
|
|
1325
|
+
const page = deliveredPageField(type);
|
|
1326
|
+
const fieldPaths = page ? requestedPaths.map((path7) => fields[path7.split(".")[0]] ? path7 : `${page.name}.${path7}`) : requestedPaths;
|
|
1303
1327
|
if (isConnection(type)) {
|
|
1304
1328
|
const nodesType = unwrap(fields.nodes.type);
|
|
1305
1329
|
const withId = isObjectType(nodesType) && nodesType.getFields().id && !fieldPaths.includes("id");
|
|
@@ -1729,6 +1753,30 @@ function resultSubscriptions(schema) {
|
|
|
1729
1753
|
}
|
|
1730
1754
|
return pairs;
|
|
1731
1755
|
}
|
|
1756
|
+
function isRecord2(value) {
|
|
1757
|
+
return typeof value === "object" && value !== null;
|
|
1758
|
+
}
|
|
1759
|
+
function isStillFilling(result) {
|
|
1760
|
+
return isRecord2(result) && result.status === "FILLING";
|
|
1761
|
+
}
|
|
1762
|
+
function shellWord(value) {
|
|
1763
|
+
if (/^[\w.:/@=+-]+$/.test(value)) return value;
|
|
1764
|
+
return "'" + value.replace(/'/g, "'\\''") + "'";
|
|
1765
|
+
}
|
|
1766
|
+
function nextPageCursor(result) {
|
|
1767
|
+
if (!isRecord2(result)) return null;
|
|
1768
|
+
for (const value of Object.values(result)) {
|
|
1769
|
+
const pageInfo = isRecord2(value) && isRecord2(value.pageInfo) ? value.pageInfo : null;
|
|
1770
|
+
if (pageInfo?.hasNextPage === true && typeof pageInfo.endCursor === "string") return pageInfo.endCursor;
|
|
1771
|
+
}
|
|
1772
|
+
return null;
|
|
1773
|
+
}
|
|
1774
|
+
function nextPageHint(commandName, externalId, page, result) {
|
|
1775
|
+
const cursor = nextPageCursor(result);
|
|
1776
|
+
if (!cursor) return null;
|
|
1777
|
+
const nextPage = JSON.stringify({ ...page ?? {}, after: cursor });
|
|
1778
|
+
return `Next page: sl ${commandName} --external-id ${shellWord(externalId)} --page ${shellWord(nextPage)} --wait`;
|
|
1779
|
+
}
|
|
1732
1780
|
function printResult(fieldName, result, opts) {
|
|
1733
1781
|
if (result == null) {
|
|
1734
1782
|
if (actingAsApplication()) {
|
|
@@ -1920,17 +1968,32 @@ function buildCommand(schema, fieldName, kind, description, service, resultSubsc
|
|
|
1920
1968
|
subscriptionVariables
|
|
1921
1969
|
);
|
|
1922
1970
|
const stream = await listen(subscriptionQuery, subscriptionVariables, requestOptions, seconds);
|
|
1971
|
+
let delivered;
|
|
1923
1972
|
try {
|
|
1924
1973
|
const { query: query2 } = build2(kind, fieldName, variables, false);
|
|
1925
1974
|
await graphqlRaw(query2, variables, requestOptions);
|
|
1926
1975
|
for await (const data2 of stream.events) {
|
|
1927
|
-
|
|
1928
|
-
|
|
1976
|
+
delivered = data2[subscriptionField];
|
|
1977
|
+
if (!isStillFilling(delivered)) break;
|
|
1978
|
+
}
|
|
1979
|
+
if (delivered === void 0) {
|
|
1980
|
+
warn(`${resultSubscription} closed without delivering a result.`);
|
|
1981
|
+
process.exit(1);
|
|
1929
1982
|
}
|
|
1930
|
-
|
|
1931
|
-
|
|
1983
|
+
printResult(resultSubscription, delivered, opts);
|
|
1984
|
+
const pageArgument = useInputWrapper ? variables.input.page : variables.page;
|
|
1985
|
+
const takesPage = cliArgs.some((a) => a.name === "page");
|
|
1986
|
+
const pageHint = takesPage ? nextPageHint(this.name(), externalId, pageArgument, delivered) : null;
|
|
1987
|
+
if (pageHint) hint(pageHint);
|
|
1988
|
+
return;
|
|
1932
1989
|
} catch (err) {
|
|
1933
1990
|
if (!isAbort(err) || !stream.timedOut()) throw err;
|
|
1991
|
+
if (delivered !== void 0) {
|
|
1992
|
+
printResult(resultSubscription, delivered, opts);
|
|
1993
|
+
warn(`Still filling after ${seconds}s: what is above may still change.`);
|
|
1994
|
+
hint(`Wait longer with --wait <seconds>; its external id is ${externalId}.`);
|
|
1995
|
+
process.exit(TIMED_OUT_EXIT_CODE);
|
|
1996
|
+
}
|
|
1934
1997
|
warn(`No result within ${seconds}s. The request was accepted and may still complete.`);
|
|
1935
1998
|
hint(`Wait longer with --wait <seconds>, or read the result later; its external id is ${externalId}.`);
|
|
1936
1999
|
process.exit(TIMED_OUT_EXIT_CODE);
|