@salesforce/graphiti 10.10.2
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/AGENT_GUIDE.md +424 -0
- package/CHANGELOG.md +448 -0
- package/LICENSE.txt +82 -0
- package/README.md +204 -0
- package/TASK.md +249 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +683 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/args.d.ts +13 -0
- package/dist/commands/args.js +207 -0
- package/dist/commands/args.js.map +1 -0
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/build.js +209 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/connect.d.ts +8 -0
- package/dist/commands/connect.js +55 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/describe.d.ts +6 -0
- package/dist/commands/describe.js +229 -0
- package/dist/commands/describe.js.map +1 -0
- package/dist/commands/meta.d.ts +9 -0
- package/dist/commands/meta.js +140 -0
- package/dist/commands/meta.js.map +1 -0
- package/dist/commands/navigate.d.ts +14 -0
- package/dist/commands/navigate.js +105 -0
- package/dist/commands/navigate.js.map +1 -0
- package/dist/commands/query-helpers.d.ts +80 -0
- package/dist/commands/query-helpers.js +865 -0
- package/dist/commands/query-helpers.js.map +1 -0
- package/dist/commands/query.d.ts +26 -0
- package/dist/commands/query.js +901 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/review.d.ts +18 -0
- package/dist/commands/review.js +533 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/session-mgmt.d.ts +25 -0
- package/dist/commands/session-mgmt.js +206 -0
- package/dist/commands/session-mgmt.js.map +1 -0
- package/dist/commands/type.d.ts +6 -0
- package/dist/commands/type.js +342 -0
- package/dist/commands/type.js.map +1 -0
- package/dist/commands/validate-input.d.ts +6 -0
- package/dist/commands/validate-input.js +32 -0
- package/dist/commands/validate-input.js.map +1 -0
- package/dist/intent/build-aggregate.d.ts +33 -0
- package/dist/intent/build-aggregate.js +134 -0
- package/dist/intent/build-aggregate.js.map +1 -0
- package/dist/intent/build-create.d.ts +14 -0
- package/dist/intent/build-create.js +16 -0
- package/dist/intent/build-create.js.map +1 -0
- package/dist/intent/build-delete.d.ts +30 -0
- package/dist/intent/build-delete.js +53 -0
- package/dist/intent/build-delete.js.map +1 -0
- package/dist/intent/build-detail.d.ts +32 -0
- package/dist/intent/build-detail.js +80 -0
- package/dist/intent/build-detail.js.map +1 -0
- package/dist/intent/build-discover.d.ts +30 -0
- package/dist/intent/build-discover.js +149 -0
- package/dist/intent/build-discover.js.map +1 -0
- package/dist/intent/build-list.d.ts +28 -0
- package/dist/intent/build-list.js +75 -0
- package/dist/intent/build-list.js.map +1 -0
- package/dist/intent/build-mutation.d.ts +23 -0
- package/dist/intent/build-mutation.js +54 -0
- package/dist/intent/build-mutation.js.map +1 -0
- package/dist/intent/build-output.d.ts +27 -0
- package/dist/intent/build-output.js +60 -0
- package/dist/intent/build-output.js.map +1 -0
- package/dist/intent/build-raw.d.ts +23 -0
- package/dist/intent/build-raw.js +54 -0
- package/dist/intent/build-raw.js.map +1 -0
- package/dist/intent/build-update.d.ts +14 -0
- package/dist/intent/build-update.js +16 -0
- package/dist/intent/build-update.js.map +1 -0
- package/dist/intent/get-schema-with-priming.d.ts +26 -0
- package/dist/intent/get-schema-with-priming.js +32 -0
- package/dist/intent/get-schema-with-priming.js.map +1 -0
- package/dist/intent/select-child-relationship.d.ts +19 -0
- package/dist/intent/select-child-relationship.js +38 -0
- package/dist/intent/select-child-relationship.js.map +1 -0
- package/dist/intent/types.d.ts +159 -0
- package/dist/intent/types.js +21 -0
- package/dist/intent/types.js.map +1 -0
- package/dist/lib/apply-command.d.ts +15 -0
- package/dist/lib/apply-command.js +238 -0
- package/dist/lib/apply-command.js.map +1 -0
- package/dist/lib/auth.d.ts +38 -0
- package/dist/lib/auth.js +113 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/codegen.d.ts +32 -0
- package/dist/lib/codegen.js +700 -0
- package/dist/lib/codegen.js.map +1 -0
- package/dist/lib/command-registry.d.ts +59 -0
- package/dist/lib/command-registry.js +366 -0
- package/dist/lib/command-registry.js.map +1 -0
- package/dist/lib/formatter.d.ts +76 -0
- package/dist/lib/formatter.js +419 -0
- package/dist/lib/formatter.js.map +1 -0
- package/dist/lib/fs-utils.d.ts +23 -0
- package/dist/lib/fs-utils.js +46 -0
- package/dist/lib/fs-utils.js.map +1 -0
- package/dist/lib/graphql-name.d.ts +27 -0
- package/dist/lib/graphql-name.js +32 -0
- package/dist/lib/graphql-name.js.map +1 -0
- package/dist/lib/interactive.d.ts +6 -0
- package/dist/lib/interactive.js +562 -0
- package/dist/lib/interactive.js.map +1 -0
- package/dist/lib/introspect.d.ts +40 -0
- package/dist/lib/introspect.js +280 -0
- package/dist/lib/introspect.js.map +1 -0
- package/dist/lib/object-info.d.ts +79 -0
- package/dist/lib/object-info.js +313 -0
- package/dist/lib/object-info.js.map +1 -0
- package/dist/lib/path-selection.d.ts +50 -0
- package/dist/lib/path-selection.js +146 -0
- package/dist/lib/path-selection.js.map +1 -0
- package/dist/lib/prime-schema.d.ts +59 -0
- package/dist/lib/prime-schema.js +158 -0
- package/dist/lib/prime-schema.js.map +1 -0
- package/dist/lib/query-builder.d.ts +10 -0
- package/dist/lib/query-builder.js +168 -0
- package/dist/lib/query-builder.js.map +1 -0
- package/dist/lib/query-commands.d.ts +19 -0
- package/dist/lib/query-commands.js +262 -0
- package/dist/lib/query-commands.js.map +1 -0
- package/dist/lib/session.d.ts +205 -0
- package/dist/lib/session.js +1075 -0
- package/dist/lib/session.js.map +1 -0
- package/dist/lib/tokenize.d.ts +12 -0
- package/dist/lib/tokenize.js +48 -0
- package/dist/lib/tokenize.js.map +1 -0
- package/dist/lib/uiapi.d.ts +109 -0
- package/dist/lib/uiapi.js +159 -0
- package/dist/lib/uiapi.js.map +1 -0
- package/dist/lib/validator.d.ts +27 -0
- package/dist/lib/validator.js +100 -0
- package/dist/lib/validator.js.map +1 -0
- package/dist/lib/variable-promotion.d.ts +69 -0
- package/dist/lib/variable-promotion.js +95 -0
- package/dist/lib/variable-promotion.js.map +1 -0
- package/dist/lib/walker.d.ts +147 -0
- package/dist/lib/walker.js +723 -0
- package/dist/lib/walker.js.map +1 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +34 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/stdio.d.ts +7 -0
- package/dist/mcp/stdio.js +25 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/tools/echo.d.ts +7 -0
- package/dist/mcp/tools/echo.js +17 -0
- package/dist/mcp/tools/echo.js.map +1 -0
- package/dist/mcp/tools/sf-gql-aggregate.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-aggregate.js +75 -0
- package/dist/mcp/tools/sf-gql-aggregate.js.map +1 -0
- package/dist/mcp/tools/sf-gql-create.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-create.js +35 -0
- package/dist/mcp/tools/sf-gql-create.js.map +1 -0
- package/dist/mcp/tools/sf-gql-delete.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-delete.js +31 -0
- package/dist/mcp/tools/sf-gql-delete.js.map +1 -0
- package/dist/mcp/tools/sf-gql-detail.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-detail.js +58 -0
- package/dist/mcp/tools/sf-gql-detail.js.map +1 -0
- package/dist/mcp/tools/sf-gql-discover.d.ts +9 -0
- package/dist/mcp/tools/sf-gql-discover.js +51 -0
- package/dist/mcp/tools/sf-gql-discover.js.map +1 -0
- package/dist/mcp/tools/sf-gql-list.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-list.js +53 -0
- package/dist/mcp/tools/sf-gql-list.js.map +1 -0
- package/dist/mcp/tools/sf-gql-raw.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-raw.js +39 -0
- package/dist/mcp/tools/sf-gql-raw.js.map +1 -0
- package/dist/mcp/tools/sf-gql-update.d.ts +11 -0
- package/dist/mcp/tools/sf-gql-update.js +35 -0
- package/dist/mcp/tools/sf-gql-update.js.map +1 -0
- package/dist/mcp/tools/shared/zod-schemas.d.ts +49 -0
- package/dist/mcp/tools/shared/zod-schemas.js +46 -0
- package/dist/mcp/tools/shared/zod-schemas.js.map +1 -0
- package/package.json +36 -0
- package/ralph-loop.sh +120 -0
- package/scripts/smoke-orderby.sh +190 -0
- package/src/__tests__/helpers/prime-deps.ts +46 -0
- package/src/__tests__/helpers/schema.ts +73 -0
- package/src/__tests__/helpers/stdout.ts +33 -0
- package/src/__tests__/setup.ts +19 -0
- package/src/cli.ts +764 -0
- package/src/commands/__tests__/query.spec.ts +137 -0
- package/src/commands/args.ts +306 -0
- package/src/commands/build.ts +288 -0
- package/src/commands/connect.ts +60 -0
- package/src/commands/describe.ts +246 -0
- package/src/commands/meta.ts +171 -0
- package/src/commands/navigate.ts +134 -0
- package/src/commands/query-helpers.ts +1202 -0
- package/src/commands/query.ts +1085 -0
- package/src/commands/review.ts +670 -0
- package/src/commands/session-mgmt.ts +256 -0
- package/src/commands/type.ts +437 -0
- package/src/commands/validate-input.ts +38 -0
- package/src/intent/__tests__/build-aggregate.spec.ts +931 -0
- package/src/intent/__tests__/build-create-validation.spec.ts +135 -0
- package/src/intent/__tests__/build-delete.spec.ts +121 -0
- package/src/intent/__tests__/build-detail.spec.ts +333 -0
- package/src/intent/__tests__/build-discover.spec.ts +432 -0
- package/src/intent/__tests__/build-list.spec.ts +284 -0
- package/src/intent/__tests__/build-mutation.spec.ts +108 -0
- package/src/intent/__tests__/build-output.spec.ts +55 -0
- package/src/intent/__tests__/build-raw.spec.ts +153 -0
- package/src/intent/__tests__/build-update-validation.spec.ts +134 -0
- package/src/intent/build-aggregate.ts +182 -0
- package/src/intent/build-create.ts +19 -0
- package/src/intent/build-delete.ts +62 -0
- package/src/intent/build-detail.ts +95 -0
- package/src/intent/build-discover.ts +199 -0
- package/src/intent/build-list.ts +91 -0
- package/src/intent/build-mutation.ts +75 -0
- package/src/intent/build-output.ts +72 -0
- package/src/intent/build-raw.ts +61 -0
- package/src/intent/build-update.ts +19 -0
- package/src/intent/get-schema-with-priming.ts +43 -0
- package/src/intent/select-child-relationship.ts +48 -0
- package/src/intent/types.ts +181 -0
- package/src/lib/__tests__/apply-command.parity.spec.ts +97 -0
- package/src/lib/__tests__/apply-command.spec.ts +171 -0
- package/src/lib/__tests__/auth.spec.ts +292 -0
- package/src/lib/__tests__/formatter.spec.ts +86 -0
- package/src/lib/__tests__/graphql-name.spec.ts +64 -0
- package/src/lib/__tests__/introspect.spec.ts +399 -0
- package/src/lib/__tests__/object-info.spec.ts +124 -0
- package/src/lib/__tests__/path-selection.spec.ts +219 -0
- package/src/lib/__tests__/prime-schema.spec.ts +269 -0
- package/src/lib/__tests__/query-builder.spec.ts +95 -0
- package/src/lib/__tests__/query-commands.spec.ts +74 -0
- package/src/lib/__tests__/session.spec.ts +292 -0
- package/src/lib/__tests__/tokenize.spec.ts +33 -0
- package/src/lib/__tests__/uiapi.spec.ts +192 -0
- package/src/lib/__tests__/variable-promotion.spec.ts +211 -0
- package/src/lib/__tests__/walker.spec.ts +250 -0
- package/src/lib/apply-command.ts +286 -0
- package/src/lib/auth.ts +157 -0
- package/src/lib/codegen.ts +899 -0
- package/src/lib/command-registry.ts +434 -0
- package/src/lib/formatter.ts +587 -0
- package/src/lib/fs-utils.ts +46 -0
- package/src/lib/graphql-name.ts +35 -0
- package/src/lib/interactive.ts +634 -0
- package/src/lib/introspect.ts +320 -0
- package/src/lib/object-info.ts +409 -0
- package/src/lib/path-selection.ts +162 -0
- package/src/lib/prime-schema.ts +195 -0
- package/src/lib/query-builder.ts +193 -0
- package/src/lib/query-commands.ts +290 -0
- package/src/lib/session.ts +1304 -0
- package/src/lib/tokenize.ts +43 -0
- package/src/lib/uiapi.ts +176 -0
- package/src/lib/validator.ts +143 -0
- package/src/lib/variable-promotion.ts +145 -0
- package/src/lib/walker.ts +975 -0
- package/src/mcp/__tests__/server.spec.ts +155 -0
- package/src/mcp/server.ts +38 -0
- package/src/mcp/stdio.ts +29 -0
- package/src/mcp/tools/__tests__/sf-gql-aggregate.spec.ts +173 -0
- package/src/mcp/tools/__tests__/sf-gql-create.spec.ts +235 -0
- package/src/mcp/tools/__tests__/sf-gql-delete.spec.ts +194 -0
- package/src/mcp/tools/__tests__/sf-gql-detail.spec.ts +246 -0
- package/src/mcp/tools/__tests__/sf-gql-discover.spec.ts +320 -0
- package/src/mcp/tools/__tests__/sf-gql-list.spec.ts +128 -0
- package/src/mcp/tools/__tests__/sf-gql-raw.spec.ts +141 -0
- package/src/mcp/tools/__tests__/sf-gql-update.spec.ts +207 -0
- package/src/mcp/tools/echo.ts +24 -0
- package/src/mcp/tools/sf-gql-aggregate.ts +102 -0
- package/src/mcp/tools/sf-gql-create.ts +55 -0
- package/src/mcp/tools/sf-gql-delete.ts +49 -0
- package/src/mcp/tools/sf-gql-detail.ts +85 -0
- package/src/mcp/tools/sf-gql-discover.ts +67 -0
- package/src/mcp/tools/sf-gql-list.ts +73 -0
- package/src/mcp/tools/sf-gql-raw.ts +56 -0
- package/src/mcp/tools/sf-gql-update.ts +55 -0
- package/src/mcp/tools/shared/zod-schemas.ts +55 -0
- package/tsconfig.json +18 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getSessionSchema } from "./query-helpers.js";
|
|
8
|
+
import { formatHelp } from "../lib/query-commands.js";
|
|
9
|
+
import {
|
|
10
|
+
loadSession,
|
|
11
|
+
getNavigationContext,
|
|
12
|
+
isInArgsContext,
|
|
13
|
+
queryNavToSchemaPath,
|
|
14
|
+
getArgsFieldPath,
|
|
15
|
+
getInputSubPath,
|
|
16
|
+
parseVariablePath,
|
|
17
|
+
} from "../lib/session.js";
|
|
18
|
+
import { formatPath } from "../lib/session.js";
|
|
19
|
+
import {
|
|
20
|
+
getRootFields,
|
|
21
|
+
resolveArgByName,
|
|
22
|
+
resolveInputPath,
|
|
23
|
+
resolvePath,
|
|
24
|
+
type InputWalkerResult,
|
|
25
|
+
} from "../lib/walker.js";
|
|
26
|
+
|
|
27
|
+
export function queryExample(sessionId: string): void {
|
|
28
|
+
const session = loadSession(sessionId);
|
|
29
|
+
const ctx = getNavigationContext(session.navigationPath);
|
|
30
|
+
const schema = getSessionSchema(session);
|
|
31
|
+
|
|
32
|
+
if (ctx === "root" || session.navigationPath.length === 0) {
|
|
33
|
+
console.log("At root. Navigate into query/ or variables/:");
|
|
34
|
+
console.log(" cd query — build the query projection");
|
|
35
|
+
console.log(" cd variables — manage query variables");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (ctx === "variables") {
|
|
40
|
+
const varParsed = parseVariablePath(session.navigationPath);
|
|
41
|
+
if (!varParsed) {
|
|
42
|
+
console.log("Define and manage query variables:");
|
|
43
|
+
console.log(" define $filter AccountWhere — create with explicit type");
|
|
44
|
+
console.log(" define $limit Int 10 — with a default value");
|
|
45
|
+
console.log(" define $filter @args/where — auto-infer type from a path");
|
|
46
|
+
console.log(" cd $filter — navigate into a complex variable");
|
|
47
|
+
console.log(" assign $limit 10 — set a scalar variable value");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const variable = session.variables.find((v) => v.name === varParsed.varName);
|
|
51
|
+
if (!variable) return;
|
|
52
|
+
const rawType = variable.type.replace(/[![\]]/g, "");
|
|
53
|
+
const inputResult = resolveInputPath(schema, rawType, varParsed.inputSubPath);
|
|
54
|
+
printInputExamples(inputResult, "assign");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isInArgsContext(session.navigationPath)) {
|
|
59
|
+
const fieldSchemaPath = getArgsFieldPath(session.navigationPath);
|
|
60
|
+
const inputSubPath = getInputSubPath(session.navigationPath);
|
|
61
|
+
const wr = resolvePath(schema, session.operation, fieldSchemaPath);
|
|
62
|
+
|
|
63
|
+
if (inputSubPath.length === 0) {
|
|
64
|
+
console.log(`Arguments for field at ${formatPath(fieldSchemaPath)}:`);
|
|
65
|
+
for (const arg of wr.args) {
|
|
66
|
+
const isLeaf = arg.typeKind === "SCALAR" || arg.typeKind === "ENUM";
|
|
67
|
+
if (isLeaf) {
|
|
68
|
+
console.log(` assign ${arg.name} <value> — ${arg.typeName}`);
|
|
69
|
+
} else {
|
|
70
|
+
console.log(` cd ${arg.name} — navigate into ${arg.typeName}`);
|
|
71
|
+
console.log(` assign ${arg.name} $var — or bind a variable`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
console.log("");
|
|
75
|
+
console.log(" define $varName @args/where — auto-infer type and bind");
|
|
76
|
+
console.log(" define $varName — auto-infer from current arg (after cd)");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const argName = inputSubPath[0];
|
|
81
|
+
const argInfo = resolveArgByName(schema, wr, argName);
|
|
82
|
+
const rawType = argInfo.typeName;
|
|
83
|
+
const remaining = inputSubPath.slice(1);
|
|
84
|
+
const inputResult = resolveInputPath(schema, rawType, remaining);
|
|
85
|
+
printInputExamples(inputResult, "assign");
|
|
86
|
+
console.log("");
|
|
87
|
+
console.log(" define $varName — auto-infer type and bind to this position");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const schemaPath = queryNavToSchemaPath(session.navigationPath);
|
|
92
|
+
if (schemaPath.length === 0) {
|
|
93
|
+
const rootFields = getRootFields(schema, session.operation);
|
|
94
|
+
console.log("Navigate into a field:");
|
|
95
|
+
for (const f of rootFields.slice(0, 5)) {
|
|
96
|
+
console.log(` cd ${f.name}`);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const wr = resolvePath(schema, session.operation, schemaPath);
|
|
102
|
+
|
|
103
|
+
console.log("Select leaf fields:");
|
|
104
|
+
const leaves = wr.fields.filter((f) => f.typeKind === "SCALAR" || f.typeKind === "ENUM");
|
|
105
|
+
for (const f of leaves.slice(0, 5)) {
|
|
106
|
+
const alias = f.name.charAt(0).toLowerCase() + f.name.slice(1);
|
|
107
|
+
console.log(` select ${f.name}:${alias}`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const dirs = wr.fields.filter((f) => f.typeKind !== "SCALAR" && f.typeKind !== "ENUM");
|
|
111
|
+
if (dirs.length > 0) {
|
|
112
|
+
console.log("");
|
|
113
|
+
console.log("Navigate into directories:");
|
|
114
|
+
for (const f of dirs.slice(0, 3)) {
|
|
115
|
+
console.log(` cd ${f.name}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (wr.args.length > 0) {
|
|
120
|
+
console.log("");
|
|
121
|
+
console.log("Configure arguments:");
|
|
122
|
+
console.log(" cd @args");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
console.log("");
|
|
126
|
+
console.log("Create aliased instances:");
|
|
127
|
+
if (wr.fields.length > 0) {
|
|
128
|
+
const f = dirs[0] ?? wr.fields[0];
|
|
129
|
+
console.log(` mkdir myAlias ${f.name}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function printInputExamples(inputResult: InputWalkerResult, cmd: string): void {
|
|
134
|
+
if (inputResult.isList) {
|
|
135
|
+
console.log("List type — add elements with mkdir:");
|
|
136
|
+
console.log(" mkdir — add a new element");
|
|
137
|
+
console.log(" cd 0 — navigate into element 0");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const leaves = inputResult.inputFields.filter(
|
|
142
|
+
(f) => f.typeKind === "SCALAR" || f.typeKind === "ENUM",
|
|
143
|
+
);
|
|
144
|
+
const objs = inputResult.inputFields.filter(
|
|
145
|
+
(f) => f.typeKind !== "SCALAR" && f.typeKind !== "ENUM",
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (leaves.length > 0) {
|
|
149
|
+
console.log("Assign scalar fields:");
|
|
150
|
+
for (const f of leaves.slice(0, 5)) {
|
|
151
|
+
console.log(` ${cmd} ${f.name} <value> — ${f.typeName}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (objs.length > 0) {
|
|
155
|
+
console.log("Navigate into nested types:");
|
|
156
|
+
for (const f of objs.slice(0, 3)) {
|
|
157
|
+
console.log(` cd ${f.name} — ${f.typeName}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function queryHelp(sessionId: string | undefined, topic?: string): void {
|
|
163
|
+
if (sessionId) {
|
|
164
|
+
try {
|
|
165
|
+
loadSession(sessionId);
|
|
166
|
+
} catch {
|
|
167
|
+
// Ignore — still show help even for invalid sessions.
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
console.log(formatHelp(topic));
|
|
171
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- graphiti traverses untyped schema/introspection JSON; see follow-up to replace with `unknown` + narrowing */
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
CommandError,
|
|
10
|
+
getSessionSchema,
|
|
11
|
+
resolveDirectoryPathInSession,
|
|
12
|
+
resolveAliasSegments,
|
|
13
|
+
parsePathInput,
|
|
14
|
+
formatAliasContext,
|
|
15
|
+
detectSObjectName,
|
|
16
|
+
printDirectory,
|
|
17
|
+
} from "./query-helpers.js";
|
|
18
|
+
import { getOrgAuth } from "../lib/auth.js";
|
|
19
|
+
import { formatNavigationPath, parseSearchTerms, parseSearchRegex } from "../lib/formatter.js";
|
|
20
|
+
import { getObjectInfo } from "../lib/object-info.js";
|
|
21
|
+
import {
|
|
22
|
+
loadSession,
|
|
23
|
+
saveSession,
|
|
24
|
+
syncFocusFromNavigationPath,
|
|
25
|
+
getNavigationContext,
|
|
26
|
+
isInArgsContext,
|
|
27
|
+
queryNavToSchemaPath,
|
|
28
|
+
} from "../lib/session.js";
|
|
29
|
+
import { getRootFields, resolvePath, type WalkerResult } from "../lib/walker.js";
|
|
30
|
+
|
|
31
|
+
export function queryPwd(sessionId: string): void {
|
|
32
|
+
const session = loadSession(sessionId);
|
|
33
|
+
console.log(formatNavigationPath(session.navigationPath));
|
|
34
|
+
const aliasCtx = formatAliasContext(session);
|
|
35
|
+
if (aliasCtx) console.log(aliasCtx);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function queryLs(
|
|
39
|
+
sessionId: string,
|
|
40
|
+
opts: { search?: string; regex?: string; long?: boolean; all?: boolean; dataCloud?: boolean },
|
|
41
|
+
directories?: string[],
|
|
42
|
+
): Promise<void> {
|
|
43
|
+
const session = loadSession(sessionId);
|
|
44
|
+
|
|
45
|
+
if (opts.long) {
|
|
46
|
+
const sObjectName = detectSObjectName(session);
|
|
47
|
+
if (sObjectName) {
|
|
48
|
+
try {
|
|
49
|
+
const auth = await getOrgAuth(session.orgAlias);
|
|
50
|
+
await getObjectInfo(auth, session.orgAlias, sObjectName);
|
|
51
|
+
} catch {
|
|
52
|
+
// Ignore — picklist values just won't be shown
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (directories && directories.length > 0) {
|
|
58
|
+
const schema = getSessionSchema(session);
|
|
59
|
+
|
|
60
|
+
for (const rawDir of directories) {
|
|
61
|
+
const dir =
|
|
62
|
+
rawDir.includes(".") && !rawDir.includes("/") ? rawDir.replace(/\./g, "/") : rawDir;
|
|
63
|
+
let resolved = parsePathInput(session.navigationPath, dir);
|
|
64
|
+
if (resolved.length > 0 && resolved[0] !== "query" && resolved[0] !== "variables") {
|
|
65
|
+
resolved = ["query", ...resolved];
|
|
66
|
+
}
|
|
67
|
+
resolved = resolveAliasSegments(session, resolved);
|
|
68
|
+
const ctx = getNavigationContext(resolved);
|
|
69
|
+
|
|
70
|
+
if (ctx === "variables" || isInArgsContext(resolved)) {
|
|
71
|
+
const tempSession = { ...session, navigationPath: resolved };
|
|
72
|
+
printDirectory(tempSession, opts);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const schemaPath = queryNavToSchemaPath(resolved);
|
|
77
|
+
if (schemaPath.length === 0) {
|
|
78
|
+
let rootFields = getRootFields(schema, session.operation);
|
|
79
|
+
const rootMatcher = opts.regex
|
|
80
|
+
? parseSearchRegex(opts.regex)
|
|
81
|
+
: opts.search
|
|
82
|
+
? parseSearchTerms(opts.search)
|
|
83
|
+
: undefined;
|
|
84
|
+
if (rootMatcher) {
|
|
85
|
+
rootFields = rootFields.filter((f) => rootMatcher.test(f.name));
|
|
86
|
+
}
|
|
87
|
+
console.log(`${rawDir}/`);
|
|
88
|
+
for (const f of rootFields) {
|
|
89
|
+
console.log(` ${f.name}/`);
|
|
90
|
+
}
|
|
91
|
+
console.log("");
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let wr: WalkerResult;
|
|
96
|
+
try {
|
|
97
|
+
wr = resolvePath(schema, session.operation, schemaPath);
|
|
98
|
+
} catch (e: any) {
|
|
99
|
+
console.log(`${rawDir}/ — ${e.message}`);
|
|
100
|
+
console.log("");
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (wr.isLeaf) {
|
|
104
|
+
console.log(`${rawDir} (${wr.typeName}) — leaf field`);
|
|
105
|
+
console.log("");
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
console.log(`${rawDir}/`);
|
|
109
|
+
const tempSession = { ...session, navigationPath: resolved };
|
|
110
|
+
printDirectory(tempSession, { ...opts, all: opts.all || false });
|
|
111
|
+
console.log("");
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
printDirectory(session, opts);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function queryCd(sessionId: string, rawPath: string): void {
|
|
120
|
+
const session = loadSession(sessionId);
|
|
121
|
+
let nextPath: string[];
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
nextPath = resolveDirectoryPathInSession(session, rawPath);
|
|
125
|
+
} catch (error: any) {
|
|
126
|
+
throw new CommandError(`Invalid path: ${error.message}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
session.navigationPath = nextPath;
|
|
130
|
+
syncFocusFromNavigationPath(session);
|
|
131
|
+
saveSession(session);
|
|
132
|
+
console.log(formatNavigationPath(session.navigationPath));
|
|
133
|
+
printDirectory(session, { showFields: false });
|
|
134
|
+
}
|