@soda-gql/common 0.14.0 → 0.14.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/dist/index-DO6j6Cif.d.cts.map +1 -1
- package/dist/index-DeJfMmkU.d.mts.map +1 -1
- package/dist/template-extraction.cjs +331 -3
- package/dist/template-extraction.cjs.map +1 -1
- package/dist/template-extraction.d.cts +101 -6
- package/dist/template-extraction.d.cts.map +1 -1
- package/dist/template-extraction.d.mts +101 -6
- package/dist/template-extraction.d.mts.map +1 -1
- package/dist/template-extraction.mjs +329 -4
- package/dist/template-extraction.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -9,19 +9,30 @@ import { ArrowFunctionExpression, CallExpression, Node, TaggedTemplateExpression
|
|
|
9
9
|
*/
|
|
10
10
|
/** Operation kind extracted from tagged template tag name. */
|
|
11
11
|
type OperationKind = "query" | "mutation" | "subscription" | "fragment";
|
|
12
|
-
/** A single
|
|
12
|
+
/** A single template extracted from a TypeScript source file. */
|
|
13
13
|
type ExtractedTemplate = {
|
|
14
14
|
/** Resolved schema name from gql.{schemaName}. */
|
|
15
15
|
readonly schemaName: string;
|
|
16
16
|
/** Operation kind from tag name. */
|
|
17
17
|
readonly kind: OperationKind;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Raw content extracted from template.
|
|
20
|
+
* For tagged templates: GraphQL body (e.g., "{ user { id } }").
|
|
21
|
+
* For callback-variables: variable definition string (e.g., "($id: ID!)").
|
|
22
|
+
* When source is "callback-variables", content is NOT standalone valid GraphQL —
|
|
23
|
+
* consumers must wrap it in a dummy operation before parsing.
|
|
24
|
+
*/
|
|
19
25
|
readonly content: string;
|
|
20
26
|
/** Element name from curried tag call (e.g., "GetUser" from query("GetUser")). */
|
|
21
27
|
readonly elementName?: string;
|
|
22
28
|
/** Type name from curried fragment call (e.g., "User" from fragment("UserFields", "User")). */
|
|
23
29
|
readonly typeName?: string;
|
|
24
|
-
/** Character offset range of
|
|
30
|
+
/** Character offset range of typeName within TS source (excludes quotes). */
|
|
31
|
+
readonly typeNameSpan?: {
|
|
32
|
+
readonly start: number;
|
|
33
|
+
readonly end: number;
|
|
34
|
+
};
|
|
35
|
+
/** Character offset range of content within TS source (excludes backticks/quotes). */
|
|
25
36
|
readonly contentRange?: {
|
|
26
37
|
readonly start: number;
|
|
27
38
|
readonly end: number;
|
|
@@ -31,6 +42,11 @@ type ExtractedTemplate = {
|
|
|
31
42
|
readonly start: number;
|
|
32
43
|
readonly end: number;
|
|
33
44
|
}[];
|
|
45
|
+
/**
|
|
46
|
+
* Extraction source discriminator. Undefined for tagged template (default).
|
|
47
|
+
* "callback-variables" for variables property extracted from callback builder options object.
|
|
48
|
+
*/
|
|
49
|
+
readonly source?: "tagged-template" | "callback-variables";
|
|
34
50
|
};
|
|
35
51
|
/** ExtractedTemplate with guaranteed position information (when positionCtx is provided). */
|
|
36
52
|
type ExtractedTemplateWithPosition = ExtractedTemplate & {
|
|
@@ -45,9 +61,61 @@ type TemplateFormatEdit = {
|
|
|
45
61
|
readonly end: number;
|
|
46
62
|
readonly newText: string;
|
|
47
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* A single f("fieldName") call in a callback builder field selection.
|
|
66
|
+
* Schema-independent — extracted purely from SWC AST.
|
|
67
|
+
*/
|
|
68
|
+
type FieldCallNode = {
|
|
69
|
+
readonly fieldName: string;
|
|
70
|
+
readonly fieldNameSpan: {
|
|
71
|
+
readonly start: number;
|
|
72
|
+
readonly end: number;
|
|
73
|
+
};
|
|
74
|
+
readonly callSpan: {
|
|
75
|
+
readonly start: number;
|
|
76
|
+
readonly end: number;
|
|
77
|
+
};
|
|
78
|
+
readonly nested: FieldCallNested | null;
|
|
79
|
+
};
|
|
80
|
+
type FieldCallNested = {
|
|
81
|
+
readonly kind: "object";
|
|
82
|
+
readonly span: {
|
|
83
|
+
readonly start: number;
|
|
84
|
+
readonly end: number;
|
|
85
|
+
};
|
|
86
|
+
readonly children: readonly FieldCallNode[];
|
|
87
|
+
} | {
|
|
88
|
+
readonly kind: "union";
|
|
89
|
+
readonly span: {
|
|
90
|
+
readonly start: number;
|
|
91
|
+
readonly end: number;
|
|
92
|
+
};
|
|
93
|
+
readonly branches: readonly UnionBranchNode[];
|
|
94
|
+
};
|
|
95
|
+
type UnionBranchNode = {
|
|
96
|
+
readonly typeName: string;
|
|
97
|
+
readonly typeNameSpan: {
|
|
98
|
+
readonly start: number;
|
|
99
|
+
readonly end: number;
|
|
100
|
+
};
|
|
101
|
+
readonly branchSpan: {
|
|
102
|
+
readonly start: number;
|
|
103
|
+
readonly end: number;
|
|
104
|
+
};
|
|
105
|
+
readonly children: readonly FieldCallNode[];
|
|
106
|
+
};
|
|
107
|
+
type ExtractedFieldTree = {
|
|
108
|
+
readonly schemaName: string;
|
|
109
|
+
readonly kind: OperationKind;
|
|
110
|
+
readonly elementName?: string;
|
|
111
|
+
readonly rootSpan: {
|
|
112
|
+
readonly start: number;
|
|
113
|
+
readonly end: number;
|
|
114
|
+
};
|
|
115
|
+
readonly children: readonly FieldCallNode[];
|
|
116
|
+
};
|
|
48
117
|
//#endregion
|
|
49
118
|
//#region packages/common/src/template-extraction/extract.d.ts
|
|
50
|
-
|
|
51
119
|
declare const OPERATION_KINDS: Set<string>;
|
|
52
120
|
declare const isOperationKind: (value: string) => value is OperationKind;
|
|
53
121
|
/** Optional position tracking context for extraction. */
|
|
@@ -60,9 +128,18 @@ type PositionTrackingContext = {
|
|
|
60
128
|
* Returns the schema name if it is, null otherwise.
|
|
61
129
|
*/
|
|
62
130
|
declare const getGqlCallSchemaName: (identifiers: ReadonlySet<string>, call: CallExpression) => string | null;
|
|
131
|
+
/**
|
|
132
|
+
* Extract variables template from a callback builder options object.
|
|
133
|
+
* Handles patterns like:
|
|
134
|
+
* - `query("Name")({ variables: \`($id: ID!)\`, fields: ... })({})`
|
|
135
|
+
* - `query("Name")({ variables: "($id: ID!)", fields: ... })`
|
|
136
|
+
*
|
|
137
|
+
* Returns true if a callback builder pattern was detected (even if no variables property found).
|
|
138
|
+
*/
|
|
139
|
+
declare const extractVariablesFromCallbackBuilder: (expr: Node, schemaName: string, templates: ExtractedTemplate[], positionCtx?: PositionTrackingContext) => boolean;
|
|
63
140
|
/**
|
|
64
141
|
* Extract templates from a gql callback's arrow function body.
|
|
65
|
-
* Handles
|
|
142
|
+
* Handles tagged templates, metadata chaining, and callback builder variables.
|
|
66
143
|
*/
|
|
67
144
|
declare const extractTemplatesFromCallback: (arrow: ArrowFunctionExpression, schemaName: string, positionCtx?: PositionTrackingContext) => ExtractedTemplate[];
|
|
68
145
|
/**
|
|
@@ -79,6 +156,24 @@ declare const findGqlCall: (identifiers: ReadonlySet<string>, node: Node) => Cal
|
|
|
79
156
|
*/
|
|
80
157
|
declare function walkAndExtract(node: Node, identifiers: ReadonlySet<string>, positionCtx: PositionTrackingContext): ExtractedTemplateWithPosition[];
|
|
81
158
|
declare function walkAndExtract(node: Node, identifiers: ReadonlySet<string>, positionCtx?: PositionTrackingContext): ExtractedTemplate[];
|
|
159
|
+
/**
|
|
160
|
+
* Walk AST to find gql callback builder calls and extract field call trees.
|
|
161
|
+
* Companion to walkAndExtract — collects ExtractedFieldTree instead of ExtractedTemplate.
|
|
162
|
+
*/
|
|
163
|
+
declare const walkAndExtractFieldTrees: (node: Node, identifiers: ReadonlySet<string>, positionCtx?: PositionTrackingContext) => ExtractedFieldTree[];
|
|
164
|
+
/**
|
|
165
|
+
* Extract a field call tree from a callback builder expression.
|
|
166
|
+
*
|
|
167
|
+
* Expects a top-level expression of the callback builder pattern:
|
|
168
|
+
* `query("Name")({ fields: ({ f }) => ({ ...f("id")(), ...f("name")() }) })({})`
|
|
169
|
+
*
|
|
170
|
+
* Returns an `ExtractedFieldTree` describing the root children (fields on the root selection set),
|
|
171
|
+
* or `null` if the expression is not a callback builder or has no `fields` property.
|
|
172
|
+
*
|
|
173
|
+
* The `positionCtx` is optional — when provided, all span values will be character offsets
|
|
174
|
+
* in the original TypeScript source. When omitted, spans are raw SWC byte positions.
|
|
175
|
+
*/
|
|
176
|
+
declare const extractFieldCallTree: (expr: Node, schemaName: string, positionCtx?: PositionTrackingContext) => ExtractedFieldTree | null;
|
|
82
177
|
//#endregion
|
|
83
178
|
//#region packages/common/src/template-extraction/format.d.ts
|
|
84
179
|
/** A function that formats GraphQL source text. */
|
|
@@ -140,5 +235,5 @@ declare const unwrapFormattedContent: (formatted: string, prefixPattern: RegExp
|
|
|
140
235
|
*/
|
|
141
236
|
declare const formatTemplatesInSource: (templates: readonly ExtractedTemplate[], tsSource: string, formatGraphql: FormatGraphqlFn) => readonly TemplateFormatEdit[];
|
|
142
237
|
//#endregion
|
|
143
|
-
export { ExtractedTemplate, ExtractedTemplateWithPosition, FormatGraphqlFn, OPERATION_KINDS, OperationKind, PositionTrackingContext, TemplateFormatEdit, buildGraphqlWrapper, detectBaseIndent, detectIndentUnit, extractFromTaggedTemplate, extractTemplatesFromCallback, findGqlCall, formatTemplatesInSource, getGqlCallSchemaName, isOperationKind, reindent, unwrapFormattedContent, walkAndExtract };
|
|
238
|
+
export { ExtractedFieldTree, ExtractedTemplate, ExtractedTemplateWithPosition, FieldCallNested, FieldCallNode, FormatGraphqlFn, OPERATION_KINDS, OperationKind, PositionTrackingContext, TemplateFormatEdit, UnionBranchNode, buildGraphqlWrapper, detectBaseIndent, detectIndentUnit, extractFieldCallTree, extractFromTaggedTemplate, extractTemplatesFromCallback, extractVariablesFromCallbackBuilder, findGqlCall, formatTemplatesInSource, getGqlCallSchemaName, isOperationKind, reindent, unwrapFormattedContent, walkAndExtract, walkAndExtractFieldTrees };
|
|
144
239
|
//# sourceMappingURL=template-extraction.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-extraction.d.cts","names":[],"sources":["../src/template-extraction/types.ts","../src/template-extraction/extract.ts","../src/template-extraction/format.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAMA;AAGY,KAHA,aAAA,GAGiB,OAAA,GAIZ,UAAA,GAAa,cAAA,GAAA,UAAA;
|
|
1
|
+
{"version":3,"file":"template-extraction.d.cts","names":[],"sources":["../src/template-extraction/types.ts","../src/template-extraction/extract.ts","../src/template-extraction/format.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAMA;AAGY,KAHA,aAAA,GAGiB,OAAA,GAIZ,UAAA,GAAa,cAAA,GAAA,UAAA;AA2B9B;AAKY,KApCA,iBAAA,GAoCkB;EAUlB;EAOA,SAAA,UAAe,EAAA,MAAA;EAYf;EAOA,SAAA,IAAA,EApEK,aAoEa;;;;ACjD9B;AAEA;AAGA;AASA;EAgFa,SAAA,OAAA,EAAA,MAAA;EACL;EAEK,SAAA,WAAA,CAAA,EAAA,MAAA;EACG;EAAuB,SAAA,QAAA,CAAA,EAAA,MAAA;EAsE1B;EACJ,SAAA,YAAA,CAAA,EAAA;IAEO,SAAA,KAAA,EAAA,MAAA;IACb,SAAA,GAAA,EAAA,MAAA;EAAiB,CAAA;EA8CP;EACH,SAAA,YAAA,CAAA,EAAA;IAEG,SAAA,KAAA,EAAA,MAAA;IACG,SAAA,GAAA,EAAA,MAAA;EAAuB,CAAA;EAuG1B;EAA4B,SAAA,gBAAA,CAAA,EAAA,SAAA;IAA2B,SAAA,KAAA,EAAA,MAAA;IAAO,SAAA,GAAA,EAAA,MAAA;EAAc,CAAA,EAAA;EAqBzE;;;;EAIb,SAAA,MAAA,CAAA,EAAA,iBAAA,GAAA,oBAAA;CAA6B;AAChC;AACQ,KDxVI,6BAAA,GAAgC,iBCwVpC,GAAA;EACO,SAAA,YAAA,EAAA;IACC,SAAA,KAAA,EAAA,MAAA;IACb,SAAA,GAAA,EAAA,MAAA;EAAiB,CAAA;AAoDpB,CAAA;;AAEe,KD5YH,kBAAA,GC4YG;EACC,SAAA,KAAA,EAAA,MAAA;EACb,SAAA,GAAA,EAAA,MAAA;EAAkB,SAAA,OAAA,EAAA,MAAA;AA2NrB,CAAA;;;;;KD/lBY,aAAA;;;IE3CA,SA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,gBDwPuD,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,GAAA,MAAA;;;AAqBpE;;;;;;AAKA;;AAEe,cC5PF,mBD4PE,EAAA,CAAA,QAAA,EC5P+B,iBD4P/B,EAAA,GAAA;EACC,OAAA,EAAA,MAAA;EACb,aAAA,EC9PiG,MD8PjG,GAAA,IAAA;CAAiB;AAoDpB;;;;;AAIqB,cCtRR,sBDsRQ,EAAA,CAAA,SAAA,EAAA,MAAA,EAAA,aAAA,ECtRoD,MDsRpD,GAAA,IAAA,EAAA,GAAA,MAAA;AA2NrB;;;;;;;;AC1oBA;AAMa,cAmKA,uBArJZ,EAAA,CAAA,SAAA,EAAA,SAsJqB,iBAtJrB,EAAA,EAAA,QAAA,EAAA,MAAA,EAAA,aAAA,EAwJgB,eAxJhB,EAAA,GAAA,SAyJW,kBAzJX,EAAA"}
|
|
@@ -9,19 +9,30 @@ import { ArrowFunctionExpression, CallExpression, Node, TaggedTemplateExpression
|
|
|
9
9
|
*/
|
|
10
10
|
/** Operation kind extracted from tagged template tag name. */
|
|
11
11
|
type OperationKind = "query" | "mutation" | "subscription" | "fragment";
|
|
12
|
-
/** A single
|
|
12
|
+
/** A single template extracted from a TypeScript source file. */
|
|
13
13
|
type ExtractedTemplate = {
|
|
14
14
|
/** Resolved schema name from gql.{schemaName}. */
|
|
15
15
|
readonly schemaName: string;
|
|
16
16
|
/** Operation kind from tag name. */
|
|
17
17
|
readonly kind: OperationKind;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Raw content extracted from template.
|
|
20
|
+
* For tagged templates: GraphQL body (e.g., "{ user { id } }").
|
|
21
|
+
* For callback-variables: variable definition string (e.g., "($id: ID!)").
|
|
22
|
+
* When source is "callback-variables", content is NOT standalone valid GraphQL —
|
|
23
|
+
* consumers must wrap it in a dummy operation before parsing.
|
|
24
|
+
*/
|
|
19
25
|
readonly content: string;
|
|
20
26
|
/** Element name from curried tag call (e.g., "GetUser" from query("GetUser")). */
|
|
21
27
|
readonly elementName?: string;
|
|
22
28
|
/** Type name from curried fragment call (e.g., "User" from fragment("UserFields", "User")). */
|
|
23
29
|
readonly typeName?: string;
|
|
24
|
-
/** Character offset range of
|
|
30
|
+
/** Character offset range of typeName within TS source (excludes quotes). */
|
|
31
|
+
readonly typeNameSpan?: {
|
|
32
|
+
readonly start: number;
|
|
33
|
+
readonly end: number;
|
|
34
|
+
};
|
|
35
|
+
/** Character offset range of content within TS source (excludes backticks/quotes). */
|
|
25
36
|
readonly contentRange?: {
|
|
26
37
|
readonly start: number;
|
|
27
38
|
readonly end: number;
|
|
@@ -31,6 +42,11 @@ type ExtractedTemplate = {
|
|
|
31
42
|
readonly start: number;
|
|
32
43
|
readonly end: number;
|
|
33
44
|
}[];
|
|
45
|
+
/**
|
|
46
|
+
* Extraction source discriminator. Undefined for tagged template (default).
|
|
47
|
+
* "callback-variables" for variables property extracted from callback builder options object.
|
|
48
|
+
*/
|
|
49
|
+
readonly source?: "tagged-template" | "callback-variables";
|
|
34
50
|
};
|
|
35
51
|
/** ExtractedTemplate with guaranteed position information (when positionCtx is provided). */
|
|
36
52
|
type ExtractedTemplateWithPosition = ExtractedTemplate & {
|
|
@@ -45,9 +61,61 @@ type TemplateFormatEdit = {
|
|
|
45
61
|
readonly end: number;
|
|
46
62
|
readonly newText: string;
|
|
47
63
|
};
|
|
64
|
+
/**
|
|
65
|
+
* A single f("fieldName") call in a callback builder field selection.
|
|
66
|
+
* Schema-independent — extracted purely from SWC AST.
|
|
67
|
+
*/
|
|
68
|
+
type FieldCallNode = {
|
|
69
|
+
readonly fieldName: string;
|
|
70
|
+
readonly fieldNameSpan: {
|
|
71
|
+
readonly start: number;
|
|
72
|
+
readonly end: number;
|
|
73
|
+
};
|
|
74
|
+
readonly callSpan: {
|
|
75
|
+
readonly start: number;
|
|
76
|
+
readonly end: number;
|
|
77
|
+
};
|
|
78
|
+
readonly nested: FieldCallNested | null;
|
|
79
|
+
};
|
|
80
|
+
type FieldCallNested = {
|
|
81
|
+
readonly kind: "object";
|
|
82
|
+
readonly span: {
|
|
83
|
+
readonly start: number;
|
|
84
|
+
readonly end: number;
|
|
85
|
+
};
|
|
86
|
+
readonly children: readonly FieldCallNode[];
|
|
87
|
+
} | {
|
|
88
|
+
readonly kind: "union";
|
|
89
|
+
readonly span: {
|
|
90
|
+
readonly start: number;
|
|
91
|
+
readonly end: number;
|
|
92
|
+
};
|
|
93
|
+
readonly branches: readonly UnionBranchNode[];
|
|
94
|
+
};
|
|
95
|
+
type UnionBranchNode = {
|
|
96
|
+
readonly typeName: string;
|
|
97
|
+
readonly typeNameSpan: {
|
|
98
|
+
readonly start: number;
|
|
99
|
+
readonly end: number;
|
|
100
|
+
};
|
|
101
|
+
readonly branchSpan: {
|
|
102
|
+
readonly start: number;
|
|
103
|
+
readonly end: number;
|
|
104
|
+
};
|
|
105
|
+
readonly children: readonly FieldCallNode[];
|
|
106
|
+
};
|
|
107
|
+
type ExtractedFieldTree = {
|
|
108
|
+
readonly schemaName: string;
|
|
109
|
+
readonly kind: OperationKind;
|
|
110
|
+
readonly elementName?: string;
|
|
111
|
+
readonly rootSpan: {
|
|
112
|
+
readonly start: number;
|
|
113
|
+
readonly end: number;
|
|
114
|
+
};
|
|
115
|
+
readonly children: readonly FieldCallNode[];
|
|
116
|
+
};
|
|
48
117
|
//#endregion
|
|
49
118
|
//#region packages/common/src/template-extraction/extract.d.ts
|
|
50
|
-
|
|
51
119
|
declare const OPERATION_KINDS: Set<string>;
|
|
52
120
|
declare const isOperationKind: (value: string) => value is OperationKind;
|
|
53
121
|
/** Optional position tracking context for extraction. */
|
|
@@ -60,9 +128,18 @@ type PositionTrackingContext = {
|
|
|
60
128
|
* Returns the schema name if it is, null otherwise.
|
|
61
129
|
*/
|
|
62
130
|
declare const getGqlCallSchemaName: (identifiers: ReadonlySet<string>, call: CallExpression) => string | null;
|
|
131
|
+
/**
|
|
132
|
+
* Extract variables template from a callback builder options object.
|
|
133
|
+
* Handles patterns like:
|
|
134
|
+
* - `query("Name")({ variables: \`($id: ID!)\`, fields: ... })({})`
|
|
135
|
+
* - `query("Name")({ variables: "($id: ID!)", fields: ... })`
|
|
136
|
+
*
|
|
137
|
+
* Returns true if a callback builder pattern was detected (even if no variables property found).
|
|
138
|
+
*/
|
|
139
|
+
declare const extractVariablesFromCallbackBuilder: (expr: Node, schemaName: string, templates: ExtractedTemplate[], positionCtx?: PositionTrackingContext) => boolean;
|
|
63
140
|
/**
|
|
64
141
|
* Extract templates from a gql callback's arrow function body.
|
|
65
|
-
* Handles
|
|
142
|
+
* Handles tagged templates, metadata chaining, and callback builder variables.
|
|
66
143
|
*/
|
|
67
144
|
declare const extractTemplatesFromCallback: (arrow: ArrowFunctionExpression, schemaName: string, positionCtx?: PositionTrackingContext) => ExtractedTemplate[];
|
|
68
145
|
/**
|
|
@@ -79,6 +156,24 @@ declare const findGqlCall: (identifiers: ReadonlySet<string>, node: Node) => Cal
|
|
|
79
156
|
*/
|
|
80
157
|
declare function walkAndExtract(node: Node, identifiers: ReadonlySet<string>, positionCtx: PositionTrackingContext): ExtractedTemplateWithPosition[];
|
|
81
158
|
declare function walkAndExtract(node: Node, identifiers: ReadonlySet<string>, positionCtx?: PositionTrackingContext): ExtractedTemplate[];
|
|
159
|
+
/**
|
|
160
|
+
* Walk AST to find gql callback builder calls and extract field call trees.
|
|
161
|
+
* Companion to walkAndExtract — collects ExtractedFieldTree instead of ExtractedTemplate.
|
|
162
|
+
*/
|
|
163
|
+
declare const walkAndExtractFieldTrees: (node: Node, identifiers: ReadonlySet<string>, positionCtx?: PositionTrackingContext) => ExtractedFieldTree[];
|
|
164
|
+
/**
|
|
165
|
+
* Extract a field call tree from a callback builder expression.
|
|
166
|
+
*
|
|
167
|
+
* Expects a top-level expression of the callback builder pattern:
|
|
168
|
+
* `query("Name")({ fields: ({ f }) => ({ ...f("id")(), ...f("name")() }) })({})`
|
|
169
|
+
*
|
|
170
|
+
* Returns an `ExtractedFieldTree` describing the root children (fields on the root selection set),
|
|
171
|
+
* or `null` if the expression is not a callback builder or has no `fields` property.
|
|
172
|
+
*
|
|
173
|
+
* The `positionCtx` is optional — when provided, all span values will be character offsets
|
|
174
|
+
* in the original TypeScript source. When omitted, spans are raw SWC byte positions.
|
|
175
|
+
*/
|
|
176
|
+
declare const extractFieldCallTree: (expr: Node, schemaName: string, positionCtx?: PositionTrackingContext) => ExtractedFieldTree | null;
|
|
82
177
|
//#endregion
|
|
83
178
|
//#region packages/common/src/template-extraction/format.d.ts
|
|
84
179
|
/** A function that formats GraphQL source text. */
|
|
@@ -140,5 +235,5 @@ declare const unwrapFormattedContent: (formatted: string, prefixPattern: RegExp
|
|
|
140
235
|
*/
|
|
141
236
|
declare const formatTemplatesInSource: (templates: readonly ExtractedTemplate[], tsSource: string, formatGraphql: FormatGraphqlFn) => readonly TemplateFormatEdit[];
|
|
142
237
|
//#endregion
|
|
143
|
-
export { ExtractedTemplate, ExtractedTemplateWithPosition, FormatGraphqlFn, OPERATION_KINDS, OperationKind, PositionTrackingContext, TemplateFormatEdit, buildGraphqlWrapper, detectBaseIndent, detectIndentUnit, extractFromTaggedTemplate, extractTemplatesFromCallback, findGqlCall, formatTemplatesInSource, getGqlCallSchemaName, isOperationKind, reindent, unwrapFormattedContent, walkAndExtract };
|
|
238
|
+
export { ExtractedFieldTree, ExtractedTemplate, ExtractedTemplateWithPosition, FieldCallNested, FieldCallNode, FormatGraphqlFn, OPERATION_KINDS, OperationKind, PositionTrackingContext, TemplateFormatEdit, UnionBranchNode, buildGraphqlWrapper, detectBaseIndent, detectIndentUnit, extractFieldCallTree, extractFromTaggedTemplate, extractTemplatesFromCallback, extractVariablesFromCallbackBuilder, findGqlCall, formatTemplatesInSource, getGqlCallSchemaName, isOperationKind, reindent, unwrapFormattedContent, walkAndExtract, walkAndExtractFieldTrees };
|
|
144
239
|
//# sourceMappingURL=template-extraction.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-extraction.d.mts","names":[],"sources":["../src/template-extraction/types.ts","../src/template-extraction/extract.ts","../src/template-extraction/format.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAMA;AAGY,KAHA,aAAA,GAGiB,OAAA,GAIZ,UAAA,GAAa,cAAA,GAAA,UAAA;
|
|
1
|
+
{"version":3,"file":"template-extraction.d.mts","names":[],"sources":["../src/template-extraction/types.ts","../src/template-extraction/extract.ts","../src/template-extraction/format.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAMA;AAGY,KAHA,aAAA,GAGiB,OAAA,GAIZ,UAAA,GAAa,cAAA,GAAA,UAAA;AA2B9B;AAKY,KApCA,iBAAA,GAoCkB;EAUlB;EAOA,SAAA,UAAe,EAAA,MAAA;EAYf;EAOA,SAAA,IAAA,EApEK,aAoEa;;;;ACjD9B;AAEA;AAGA;AASA;EAgFa,SAAA,OAAA,EAAA,MAAA;EACL;EAEK,SAAA,WAAA,CAAA,EAAA,MAAA;EACG;EAAuB,SAAA,QAAA,CAAA,EAAA,MAAA;EAsE1B;EACJ,SAAA,YAAA,CAAA,EAAA;IAEO,SAAA,KAAA,EAAA,MAAA;IACb,SAAA,GAAA,EAAA,MAAA;EAAiB,CAAA;EA8CP;EACH,SAAA,YAAA,CAAA,EAAA;IAEG,SAAA,KAAA,EAAA,MAAA;IACG,SAAA,GAAA,EAAA,MAAA;EAAuB,CAAA;EAuG1B;EAA4B,SAAA,gBAAA,CAAA,EAAA,SAAA;IAA2B,SAAA,KAAA,EAAA,MAAA;IAAO,SAAA,GAAA,EAAA,MAAA;EAAc,CAAA,EAAA;EAqBzE;;;;EAIb,SAAA,MAAA,CAAA,EAAA,iBAAA,GAAA,oBAAA;CAA6B;AAChC;AACQ,KDxVI,6BAAA,GAAgC,iBCwVpC,GAAA;EACO,SAAA,YAAA,EAAA;IACC,SAAA,KAAA,EAAA,MAAA;IACb,SAAA,GAAA,EAAA,MAAA;EAAiB,CAAA;AAoDpB,CAAA;;AAEe,KD5YH,kBAAA,GC4YG;EACC,SAAA,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