@sortlist/cli 0.40.0 → 0.42.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 +71 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -873,7 +873,7 @@ function ucfirst(s) {
|
|
|
873
873
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
874
874
|
}
|
|
875
875
|
var PAYLOAD_TYPE_PATTERN = /(?:Response|Payload|MutationPayload)$/;
|
|
876
|
-
function buildSelections(type, schema, depth, exclude, prefix, visited) {
|
|
876
|
+
function buildSelections(type, schema, depth, exclude, prefix, totalCount, visited) {
|
|
877
877
|
if (!isObjectType(type)) return [];
|
|
878
878
|
if (visited.has(type.name)) return [];
|
|
879
879
|
visited.add(type.name);
|
|
@@ -882,8 +882,16 @@ function buildSelections(type, schema, depth, exclude, prefix, visited) {
|
|
|
882
882
|
const isPayload = PAYLOAD_TYPE_PATTERN.test(type.name);
|
|
883
883
|
if (isConnection(type)) {
|
|
884
884
|
const nodesType = unwrap(fields.nodes.type);
|
|
885
|
-
const nodeSelections = buildSelections(
|
|
886
|
-
|
|
885
|
+
const nodeSelections = buildSelections(
|
|
886
|
+
nodesType,
|
|
887
|
+
schema,
|
|
888
|
+
depth,
|
|
889
|
+
exclude,
|
|
890
|
+
`${prefix}nodes.`,
|
|
891
|
+
totalCount,
|
|
892
|
+
new Set(visited)
|
|
893
|
+
);
|
|
894
|
+
return connectionSelections(type, nodeSelections, totalCount);
|
|
887
895
|
}
|
|
888
896
|
for (const [name, field] of Object.entries(fields)) {
|
|
889
897
|
if (name.startsWith("__")) continue;
|
|
@@ -896,7 +904,15 @@ function buildSelections(type, schema, depth, exclude, prefix, visited) {
|
|
|
896
904
|
if (isLeaf(namedType)) {
|
|
897
905
|
lines.push(name);
|
|
898
906
|
} else if (isObjectType(namedType) && depth > 0) {
|
|
899
|
-
const subSelections = buildSelections(
|
|
907
|
+
const subSelections = buildSelections(
|
|
908
|
+
namedType,
|
|
909
|
+
schema,
|
|
910
|
+
depth - 1,
|
|
911
|
+
exclude,
|
|
912
|
+
`${fullPath}.`,
|
|
913
|
+
totalCount,
|
|
914
|
+
new Set(visited)
|
|
915
|
+
);
|
|
900
916
|
if (subSelections.length > 0) {
|
|
901
917
|
lines.push(`${fieldCall(name, field)} {`);
|
|
902
918
|
for (const sel of subSelections) lines.push(` ${sel}`);
|
|
@@ -939,7 +955,7 @@ function edgeExtras(connection) {
|
|
|
939
955
|
}
|
|
940
956
|
return lines.length === 0 ? null : { edge, lines };
|
|
941
957
|
}
|
|
942
|
-
function connectionSelections(connection, nodeSelections) {
|
|
958
|
+
function connectionSelections(connection, nodeSelections, totalCount) {
|
|
943
959
|
if (nodeSelections.length === 0) return [];
|
|
944
960
|
const lines = [];
|
|
945
961
|
const extras = edgeExtras(connection);
|
|
@@ -959,7 +975,7 @@ function connectionSelections(connection, nodeSelections) {
|
|
|
959
975
|
lines.push(" hasNextPage");
|
|
960
976
|
lines.push(" endCursor");
|
|
961
977
|
lines.push("}");
|
|
962
|
-
if (connection.getFields().totalCount) lines.push("totalCount");
|
|
978
|
+
if (totalCount && connection.getFields().totalCount) lines.push("totalCount");
|
|
963
979
|
for (const extra of connectionExtras(connection)) lines.push(extra);
|
|
964
980
|
return lines;
|
|
965
981
|
}
|
|
@@ -1002,6 +1018,7 @@ function buildQuery(schema, kind, fieldName, variables, options = {}) {
|
|
|
1002
1018
|
if (!field) throw new Error(`Unknown ${kind} field: ${fieldName}`);
|
|
1003
1019
|
const depth = options.depth ?? 0;
|
|
1004
1020
|
const exclude = new Set(options.exclude ?? []);
|
|
1021
|
+
const wantsTotalCount = options.totalCount === true;
|
|
1005
1022
|
const returnType = unwrap(field.type);
|
|
1006
1023
|
const allArgs = field.args;
|
|
1007
1024
|
const varDefsInner = allArgs.map((a) => `$${a.name}: ${a.type.toString()}`).join(", ");
|
|
@@ -1014,9 +1031,9 @@ function buildQuery(schema, kind, fieldName, variables, options = {}) {
|
|
|
1014
1031
|
} else {
|
|
1015
1032
|
let selections;
|
|
1016
1033
|
if (options.fields && options.fields.length > 0) {
|
|
1017
|
-
selections = buildFieldsFromList(returnType, schema, options.fields);
|
|
1034
|
+
selections = buildFieldsFromList(returnType, schema, options.fields, wantsTotalCount);
|
|
1018
1035
|
} else {
|
|
1019
|
-
selections = buildSelections(returnType, schema, depth, exclude, "", /* @__PURE__ */ new Set());
|
|
1036
|
+
selections = buildSelections(returnType, schema, depth, exclude, "", wantsTotalCount, /* @__PURE__ */ new Set());
|
|
1020
1037
|
}
|
|
1021
1038
|
if (selections.length === 0) {
|
|
1022
1039
|
selectionBody = ` ${fieldName}${fieldArgs} {
|
|
@@ -1036,14 +1053,19 @@ ${selectionBody}
|
|
|
1036
1053
|
}`;
|
|
1037
1054
|
return { query, variables, fieldName };
|
|
1038
1055
|
}
|
|
1039
|
-
function buildFieldsFromList(type, schema, fieldPaths) {
|
|
1056
|
+
function buildFieldsFromList(type, schema, fieldPaths, totalCount) {
|
|
1040
1057
|
if (!isObjectType(type)) return [];
|
|
1041
1058
|
const fields = type.getFields();
|
|
1042
1059
|
if (isConnection(type)) {
|
|
1043
1060
|
const nodesType = unwrap(fields.nodes.type);
|
|
1044
1061
|
const withId = isObjectType(nodesType) && nodesType.getFields().id && !fieldPaths.includes("id");
|
|
1045
|
-
const nodeSelections = buildFieldsFromList(
|
|
1046
|
-
|
|
1062
|
+
const nodeSelections = buildFieldsFromList(
|
|
1063
|
+
nodesType,
|
|
1064
|
+
schema,
|
|
1065
|
+
withId ? ["id", ...fieldPaths] : fieldPaths,
|
|
1066
|
+
totalCount
|
|
1067
|
+
);
|
|
1068
|
+
return connectionSelections(type, nodeSelections, totalCount);
|
|
1047
1069
|
}
|
|
1048
1070
|
const lines = [];
|
|
1049
1071
|
const grouped = /* @__PURE__ */ new Map();
|
|
@@ -1059,7 +1081,7 @@ function buildFieldsFromList(type, schema, fieldPaths) {
|
|
|
1059
1081
|
if (isLeaf(namedType)) {
|
|
1060
1082
|
lines.push(name);
|
|
1061
1083
|
} else if (isObjectType(namedType) && subPaths.length > 0) {
|
|
1062
|
-
const subSelections = buildFieldsFromList(namedType, schema, subPaths);
|
|
1084
|
+
const subSelections = buildFieldsFromList(namedType, schema, subPaths, totalCount);
|
|
1063
1085
|
if (subSelections.length > 0) {
|
|
1064
1086
|
lines.push(`${fieldCall(name, field)} {`);
|
|
1065
1087
|
for (const sel of subSelections) lines.push(` ${sel}`);
|
|
@@ -1231,6 +1253,11 @@ function enumListOf(type) {
|
|
|
1231
1253
|
const inner = unwrap2(listless.ofType);
|
|
1232
1254
|
return isEnumType2(inner) ? inner : null;
|
|
1233
1255
|
}
|
|
1256
|
+
function enumOf(type) {
|
|
1257
|
+
const listless = isNonNullType2(type) ? type.ofType : type;
|
|
1258
|
+
if (isListType2(listless)) return null;
|
|
1259
|
+
return isEnumType2(listless) ? listless : null;
|
|
1260
|
+
}
|
|
1234
1261
|
function commonPrefix(values) {
|
|
1235
1262
|
if (values.length < 2) return "";
|
|
1236
1263
|
let prefix = values[0];
|
|
@@ -1238,28 +1265,46 @@ function commonPrefix(values) {
|
|
|
1238
1265
|
const cut = prefix.lastIndexOf("_");
|
|
1239
1266
|
return cut === -1 ? "" : prefix.slice(0, cut + 1);
|
|
1240
1267
|
}
|
|
1268
|
+
function matchEnumValue(part, names, prefix) {
|
|
1269
|
+
const wanted = part.trim().replace(/([a-z0-9])([A-Z])/g, "$1_$2").toUpperCase();
|
|
1270
|
+
return names.find((name) => name === wanted || name === `${prefix}${wanted}`);
|
|
1271
|
+
}
|
|
1272
|
+
function spellableValues(names, prefix) {
|
|
1273
|
+
return names.map(
|
|
1274
|
+
(name) => name.slice(prefix.length).toLowerCase().replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
1275
|
+
);
|
|
1276
|
+
}
|
|
1241
1277
|
function coerceEnumList(raw, enumType, flagName) {
|
|
1242
1278
|
const names = enumType.getValues().map((value) => value.name);
|
|
1243
1279
|
if (raw.trim() === "all") return names;
|
|
1244
1280
|
if (raw.trim() === "none") return [];
|
|
1245
1281
|
const prefix = commonPrefix(names);
|
|
1246
1282
|
return raw.split(",").filter((part) => part.trim() !== "").map((part) => {
|
|
1247
|
-
const
|
|
1248
|
-
const match = names.find((name) => name === wanted || name === `${prefix}${wanted}`);
|
|
1283
|
+
const match = matchEnumValue(part, names, prefix);
|
|
1249
1284
|
if (match === void 0) {
|
|
1250
|
-
const short = names.map(
|
|
1251
|
-
(name) => name.slice(prefix.length).toLowerCase().replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
1252
|
-
);
|
|
1253
1285
|
throw new Error(
|
|
1254
|
-
`--${flagName} does not know "${part.trim()}". One or more of: ${
|
|
1286
|
+
`--${flagName} does not know "${part.trim()}". One or more of: ${spellableValues(names, prefix).join(", ")}, all, or none.`
|
|
1255
1287
|
);
|
|
1256
1288
|
}
|
|
1257
1289
|
return match;
|
|
1258
1290
|
});
|
|
1259
1291
|
}
|
|
1292
|
+
function coerceEnum(raw, enumType, flagName) {
|
|
1293
|
+
const names = enumType.getValues().map((value) => value.name);
|
|
1294
|
+
const prefix = commonPrefix(names);
|
|
1295
|
+
const match = matchEnumValue(raw, names, prefix);
|
|
1296
|
+
if (match === void 0) {
|
|
1297
|
+
throw new Error(
|
|
1298
|
+
`--${flagName} does not know "${raw.trim()}". One of: ${spellableValues(names, prefix).join(", ")}.`
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
return match;
|
|
1302
|
+
}
|
|
1260
1303
|
function coerceValue(raw, type, flagName) {
|
|
1261
1304
|
const enumList = enumListOf(type);
|
|
1262
1305
|
if (enumList && !raw.trim().startsWith("[")) return coerceEnumList(raw, enumList, flagName);
|
|
1306
|
+
const enumValue = enumOf(type);
|
|
1307
|
+
if (enumValue) return coerceEnum(raw, enumValue, flagName);
|
|
1263
1308
|
if (isStructuredInput(type)) {
|
|
1264
1309
|
try {
|
|
1265
1310
|
return JSON.parse(raw);
|
|
@@ -1402,7 +1447,7 @@ function buildCommand(schema, fieldName, kind, description, service) {
|
|
|
1402
1447
|
cmd.option(flag, describeArg(a));
|
|
1403
1448
|
}
|
|
1404
1449
|
}
|
|
1405
|
-
cmd.option("--depth <depth>", "Selection depth (default: 0)", parseInt).option("--fields <fields>", "Comma-separated fields to include").option("--exclude <fields>", "Comma-separated fields to exclude");
|
|
1450
|
+
cmd.option("--depth <depth>", "Selection depth (default: 0)", parseInt).option("--fields <fields>", "Comma-separated fields to include").option("--exclude <fields>", "Comma-separated fields to exclude").option("--total-count", "Also count every match, not just this page (slow on a broad filter)");
|
|
1406
1451
|
cmd.action(async function() {
|
|
1407
1452
|
const opts = this.optsWithGlobals();
|
|
1408
1453
|
const ctx = getUserContext();
|
|
@@ -1437,7 +1482,8 @@ function buildCommand(schema, fieldName, kind, description, service) {
|
|
|
1437
1482
|
built = buildQuery(schema, kind, fieldName, variables, {
|
|
1438
1483
|
depth: opts.depth,
|
|
1439
1484
|
fields: opts.fields?.split(","),
|
|
1440
|
-
exclude: opts.exclude?.split(",")
|
|
1485
|
+
exclude: opts.exclude?.split(","),
|
|
1486
|
+
totalCount: opts.totalCount === true
|
|
1441
1487
|
});
|
|
1442
1488
|
} catch (buildError) {
|
|
1443
1489
|
if (!(buildError instanceof UnknownFieldError)) throw buildError;
|
|
@@ -1587,7 +1633,11 @@ var API_SCOPES = [
|
|
|
1587
1633
|
"signals/*:read",
|
|
1588
1634
|
"billing/*:*",
|
|
1589
1635
|
"billing/*:read",
|
|
1590
|
-
"billing/offer:*"
|
|
1636
|
+
"billing/offer:*",
|
|
1637
|
+
"outreach/*:*",
|
|
1638
|
+
"outreach/*:read",
|
|
1639
|
+
"hermes/*:*",
|
|
1640
|
+
"hermes/*:read"
|
|
1591
1641
|
];
|
|
1592
1642
|
var DEFAULT_SCOPE = `openid profile email offline_access ${API_SCOPES.join(" ")}`;
|
|
1593
1643
|
function sleep(ms) {
|