@soda-gql/tools 0.13.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.
Files changed (49) hide show
  1. package/README.md +72 -0
  2. package/codegen.d.ts +2 -0
  3. package/codegen.js +1 -0
  4. package/dist/bin.cjs +15509 -0
  5. package/dist/bin.cjs.map +1 -0
  6. package/dist/bin.d.cts +839 -0
  7. package/dist/bin.d.cts.map +1 -0
  8. package/dist/chunk-BrXtsOCC.cjs +41 -0
  9. package/dist/codegen.cjs +4704 -0
  10. package/dist/codegen.cjs.map +1 -0
  11. package/dist/codegen.d.cts +416 -0
  12. package/dist/codegen.d.cts.map +1 -0
  13. package/dist/codegen.d.mts +416 -0
  14. package/dist/codegen.d.mts.map +1 -0
  15. package/dist/codegen.mjs +4712 -0
  16. package/dist/codegen.mjs.map +1 -0
  17. package/dist/formatter-Glj5a663.cjs +510 -0
  18. package/dist/formatter-Glj5a663.cjs.map +1 -0
  19. package/dist/formatter.cjs +509 -0
  20. package/dist/formatter.cjs.map +1 -0
  21. package/dist/formatter.d.cts +33 -0
  22. package/dist/formatter.d.cts.map +1 -0
  23. package/dist/formatter.d.mts +33 -0
  24. package/dist/formatter.d.mts.map +1 -0
  25. package/dist/formatter.mjs +507 -0
  26. package/dist/formatter.mjs.map +1 -0
  27. package/dist/index.cjs +13 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +11 -0
  30. package/dist/index.d.cts.map +1 -0
  31. package/dist/index.d.mts +11 -0
  32. package/dist/index.d.mts.map +1 -0
  33. package/dist/index.mjs +12 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/typegen.cjs +864 -0
  36. package/dist/typegen.cjs.map +1 -0
  37. package/dist/typegen.d.cts +205 -0
  38. package/dist/typegen.d.cts.map +1 -0
  39. package/dist/typegen.d.mts +205 -0
  40. package/dist/typegen.d.mts.map +1 -0
  41. package/dist/typegen.mjs +859 -0
  42. package/dist/typegen.mjs.map +1 -0
  43. package/formatter.d.ts +2 -0
  44. package/formatter.js +1 -0
  45. package/index.d.ts +2 -0
  46. package/index.js +1 -0
  47. package/package.json +102 -0
  48. package/typegen.d.ts +2 -0
  49. package/typegen.js +1 -0
@@ -0,0 +1,507 @@
1
+ import { createRequire } from "node:module";
2
+ import { err, ok } from "neverthrow";
3
+ import { randomBytes } from "node:crypto";
4
+ import { formatTemplatesInSource, walkAndExtract } from "@soda-gql/common/template-extraction";
5
+ import { createSwcSpanConverter } from "@soda-gql/common/utils";
6
+ import { parseSync } from "@swc/core";
7
+
8
+ //#region packages/tools/src/formatter/detection.ts
9
+ /**
10
+ * Check if an expression is a reference to gql
11
+ * Handles: gql, namespace.gql
12
+ */
13
+ const isGqlReference = (node, gqlIdentifiers) => {
14
+ const unwrapped = node.type === "TsNonNullExpression" ? node.expression : node;
15
+ if (unwrapped.type === "Identifier") {
16
+ return gqlIdentifiers.has(unwrapped.value);
17
+ }
18
+ if (unwrapped.type === "MemberExpression" && unwrapped.property.type === "Identifier" && unwrapped.property.value === "gql") {
19
+ return true;
20
+ }
21
+ return false;
22
+ };
23
+ /**
24
+ * Check if a call expression is a gql definition call
25
+ * Handles: gql.default(...), gql.model(...), gql.schemaName(...) (multi-schema)
26
+ */
27
+ const isGqlDefinitionCall = (node, gqlIdentifiers) => {
28
+ if (node.callee.type !== "MemberExpression") return false;
29
+ const { object } = node.callee;
30
+ if (!isGqlReference(object, gqlIdentifiers)) return false;
31
+ const firstArg = node.arguments[0];
32
+ if (!firstArg || firstArg.expression.type !== "ArrowFunctionExpression" && firstArg.expression.type !== "FunctionExpression") return false;
33
+ return true;
34
+ };
35
+ /**
36
+ * Check if an object expression is a field selection object
37
+ * Field selection objects are returned from arrow functions with ({ f }) or ({ f, $ }) parameter
38
+ */
39
+ const isFieldSelectionObject = (object, parent) => {
40
+ let bodyObject = null;
41
+ if (parent.body.type === "ObjectExpression") {
42
+ bodyObject = parent.body;
43
+ } else if (parent.body.type === "ParenthesisExpression") {
44
+ const inner = parent.body.expression;
45
+ if (inner.type === "ObjectExpression") {
46
+ bodyObject = inner;
47
+ }
48
+ }
49
+ if (!bodyObject) return false;
50
+ if (bodyObject.span.start !== object.span.start) return false;
51
+ const param = parent.params[0];
52
+ if (!param || param.type !== "ObjectPattern") return false;
53
+ return param.properties.some((p) => {
54
+ if (p.type === "KeyValuePatternProperty" && p.key.type === "Identifier") {
55
+ return p.key.value === "f";
56
+ }
57
+ if (p.type === "AssignmentPatternProperty" && p.key.type === "Identifier") {
58
+ return p.key.value === "f";
59
+ }
60
+ return false;
61
+ });
62
+ };
63
+ /**
64
+ * Collect gql identifiers from import declarations
65
+ */
66
+ const collectGqlIdentifiers = (module) => {
67
+ const gqlIdentifiers = new Set();
68
+ for (const item of module.body) {
69
+ if (item.type !== "ImportDeclaration") continue;
70
+ for (const specifier of item.specifiers) {
71
+ if (specifier.type === "ImportSpecifier") {
72
+ const imported = specifier.imported?.value ?? specifier.local.value;
73
+ if (imported === "gql") {
74
+ gqlIdentifiers.add(specifier.local.value);
75
+ }
76
+ }
77
+ if (specifier.type === "ImportDefaultSpecifier") {
78
+ if (specifier.local.value === "gql") {
79
+ gqlIdentifiers.add(specifier.local.value);
80
+ }
81
+ }
82
+ if (specifier.type === "ImportNamespaceSpecifier") {}
83
+ }
84
+ }
85
+ return gqlIdentifiers;
86
+ };
87
+ /**
88
+ * Check if a call expression is a fragment definition call.
89
+ * Pattern: fragment.TypeName({ ... }) where `fragment` comes from gql factory destructuring.
90
+ */
91
+ const isFragmentDefinitionCall = (node, fragmentIdentifiers) => {
92
+ if (node.callee.type !== "MemberExpression") return false;
93
+ const { object } = node.callee;
94
+ if (object.type !== "Identifier") return false;
95
+ if (!fragmentIdentifiers.has(object.value)) return false;
96
+ const firstArg = node.arguments[0];
97
+ if (!firstArg || firstArg.expression.type !== "ObjectExpression") return false;
98
+ return true;
99
+ };
100
+ /**
101
+ * Check if an object expression already has a `key` property.
102
+ */
103
+ const hasKeyProperty = (obj) => {
104
+ return obj.properties.some((prop) => {
105
+ if (prop.type === "KeyValueProperty" && prop.key.type === "Identifier") {
106
+ return prop.key.value === "key";
107
+ }
108
+ return false;
109
+ });
110
+ };
111
+ /**
112
+ * Collect fragment identifiers from gql factory arrow function parameter.
113
+ * Looks for patterns like: ({ fragment }) => ... or ({ fragment: f }) => ...
114
+ */
115
+ const collectFragmentIdentifiers = (arrowFunction) => {
116
+ const fragmentIdentifiers = new Set();
117
+ const param = arrowFunction.params[0];
118
+ if (param?.type !== "ObjectPattern") return fragmentIdentifiers;
119
+ for (const p of param.properties) {
120
+ if (p.type === "KeyValuePatternProperty" && p.key.type === "Identifier" && p.key.value === "fragment") {
121
+ const localName = extractIdentifierName(p.value);
122
+ if (localName) fragmentIdentifiers.add(localName);
123
+ }
124
+ if (p.type === "AssignmentPatternProperty" && p.key.type === "Identifier" && p.key.value === "fragment") {
125
+ fragmentIdentifiers.add(p.key.value);
126
+ }
127
+ }
128
+ return fragmentIdentifiers;
129
+ };
130
+ /**
131
+ * Extract identifier name from a pattern node.
132
+ */
133
+ const extractIdentifierName = (pattern) => {
134
+ if (pattern.type === "Identifier") return pattern.value;
135
+ if (pattern.type === "BindingIdentifier") return pattern.value;
136
+ return null;
137
+ };
138
+
139
+ //#endregion
140
+ //#region packages/tools/src/formatter/insertion.ts
141
+ /**
142
+ * The newline string to insert after object opening brace
143
+ */
144
+ const NEWLINE_INSERTION = "\n";
145
+ /**
146
+ * Generate a random 8-character hex key for fragment identification.
147
+ * Uses Node.js crypto for cryptographically secure random bytes.
148
+ */
149
+ const generateFragmentKey = () => {
150
+ return randomBytes(4).toString("hex");
151
+ };
152
+ /**
153
+ * Create the key property insertion string.
154
+ *
155
+ * For single-line objects: returns ` key: "xxxxxxxx",\n`
156
+ * For multi-line objects (with indentation): returns `{indentation}key: "xxxxxxxx",\n`
157
+ * (the existing indentation before the next property is preserved)
158
+ *
159
+ * @param key - The hex key string
160
+ * @param indentation - Optional indentation string for multi-line objects
161
+ */
162
+ const createKeyInsertion = (key, indentation) => {
163
+ if (indentation !== undefined) {
164
+ return `${indentation}key: "${key}",\n`;
165
+ }
166
+ return ` key: "${key}",\n`;
167
+ };
168
+ /**
169
+ * Check if there's already a newline after the opening brace.
170
+ * Uses string inspection rather than AST.
171
+ *
172
+ * @param source - The source code string
173
+ * @param objectStartPos - The position of the `{` character in the source
174
+ */
175
+ const hasExistingNewline = (source, objectStartPos) => {
176
+ const pos = objectStartPos + 1;
177
+ const nextChar = source[pos];
178
+ return nextChar === "\n" || nextChar === "\r";
179
+ };
180
+ /**
181
+ * Detect the indentation used after an opening brace.
182
+ * Returns the whitespace string after the newline, or null if no newline.
183
+ *
184
+ * @param source - The source code string
185
+ * @param objectStartPos - The position of the `{` character
186
+ */
187
+ const detectIndentationAfterBrace = (source, objectStartPos) => {
188
+ const afterBrace = objectStartPos + 1;
189
+ const char = source[afterBrace];
190
+ if (char !== "\n" && char !== "\r") {
191
+ return null;
192
+ }
193
+ let pos = afterBrace + 1;
194
+ if (char === "\r" && source[pos] === "\n") {
195
+ pos++;
196
+ }
197
+ let indentation = "";
198
+ while (pos < source.length) {
199
+ const c = source[pos];
200
+ if (c === " " || c === " ") {
201
+ indentation += c;
202
+ pos++;
203
+ } else {
204
+ break;
205
+ }
206
+ }
207
+ return indentation;
208
+ };
209
+
210
+ //#endregion
211
+ //#region packages/tools/src/formatter/format.ts
212
+ const require = createRequire(import.meta.url);
213
+ let _graphqlModule;
214
+ let _graphqlModuleError;
215
+ const getGraphqlModule = () => {
216
+ if (_graphqlModuleError) {
217
+ return err({
218
+ type: "FormatError",
219
+ code: "MISSING_DEPENDENCY",
220
+ message: "The \"graphql\" package is required for soda-gql formatter. Install it with: bun add graphql"
221
+ });
222
+ }
223
+ if (!_graphqlModule) {
224
+ try {
225
+ _graphqlModule = require("graphql");
226
+ } catch (cause) {
227
+ _graphqlModuleError = cause instanceof Error ? cause : new Error(String(cause));
228
+ return err({
229
+ type: "FormatError",
230
+ code: "MISSING_DEPENDENCY",
231
+ message: "The \"graphql\" package is required for soda-gql formatter. Install it with: bun add graphql",
232
+ cause
233
+ });
234
+ }
235
+ }
236
+ return ok(_graphqlModule);
237
+ };
238
+ /**
239
+ * Simple recursive AST traversal
240
+ */
241
+ const traverseNode = (node, context, gqlIdentifiers, onObjectExpression) => {
242
+ if (node.type === "CallExpression" && isGqlDefinitionCall(node, gqlIdentifiers)) {
243
+ const call = node;
244
+ const firstArg = call.arguments[0];
245
+ if (firstArg?.expression.type === "ArrowFunctionExpression") {
246
+ const arrow = firstArg.expression;
247
+ const fragmentIds = collectFragmentIdentifiers(arrow);
248
+ context = {
249
+ ...context,
250
+ insideGqlDefinition: true,
251
+ fragmentIdentifiers: new Set([...context.fragmentIdentifiers, ...fragmentIds])
252
+ };
253
+ } else {
254
+ context = {
255
+ ...context,
256
+ insideGqlDefinition: true
257
+ };
258
+ }
259
+ }
260
+ if (node.type === "CallExpression" && context.insideGqlDefinition && isFragmentDefinitionCall(node, context.fragmentIdentifiers)) {
261
+ const call = node;
262
+ const firstArg = call.arguments[0];
263
+ if (firstArg?.expression.type === "ObjectExpression" && context.currentArrowFunction) {
264
+ onObjectExpression(firstArg.expression, context.currentArrowFunction, { isFragmentConfig: true });
265
+ }
266
+ }
267
+ if (node.type === "ObjectExpression" && context.insideGqlDefinition && context.currentArrowFunction && isFieldSelectionObject(node, context.currentArrowFunction)) {
268
+ onObjectExpression(node, context.currentArrowFunction, { isFragmentConfig: false });
269
+ }
270
+ if (node.type === "CallExpression") {
271
+ const call = node;
272
+ traverseNode(call.callee, context, gqlIdentifiers, onObjectExpression);
273
+ for (const arg of call.arguments) {
274
+ traverseNode(arg.expression, context, gqlIdentifiers, onObjectExpression);
275
+ }
276
+ } else if (node.type === "ArrowFunctionExpression") {
277
+ const arrow = node;
278
+ const childContext = {
279
+ ...context,
280
+ currentArrowFunction: arrow
281
+ };
282
+ if (arrow.body.type !== "BlockStatement") {
283
+ traverseNode(arrow.body, childContext, gqlIdentifiers, onObjectExpression);
284
+ }
285
+ } else if (node.type === "ParenthesisExpression") {
286
+ const paren = node;
287
+ if (paren.expression) {
288
+ traverseNode(paren.expression, context, gqlIdentifiers, onObjectExpression);
289
+ }
290
+ } else if (node.type === "MemberExpression") {
291
+ const member = node;
292
+ traverseNode(member.object, context, gqlIdentifiers, onObjectExpression);
293
+ } else if (node.type === "ObjectExpression") {
294
+ const obj = node;
295
+ for (const prop of obj.properties) {
296
+ if (prop.type === "SpreadElement") {
297
+ traverseNode(prop.arguments, context, gqlIdentifiers, onObjectExpression);
298
+ } else if (prop.type === "KeyValueProperty") {
299
+ traverseNode(prop.value, context, gqlIdentifiers, onObjectExpression);
300
+ }
301
+ }
302
+ } else {
303
+ for (const value of Object.values(node)) {
304
+ if (Array.isArray(value)) {
305
+ for (const child of value) {
306
+ if (child && typeof child === "object" && "type" in child) {
307
+ traverseNode(child, context, gqlIdentifiers, onObjectExpression);
308
+ }
309
+ }
310
+ } else if (value && typeof value === "object" && "type" in value) {
311
+ traverseNode(value, context, gqlIdentifiers, onObjectExpression);
312
+ }
313
+ }
314
+ }
315
+ };
316
+ const traverse = (module, gqlIdentifiers, onObjectExpression) => {
317
+ const initialContext = {
318
+ insideGqlDefinition: false,
319
+ currentArrowFunction: null,
320
+ fragmentIdentifiers: new Set()
321
+ };
322
+ for (const statement of module.body) {
323
+ traverseNode(statement, initialContext, gqlIdentifiers, onObjectExpression);
324
+ }
325
+ };
326
+ /**
327
+ * Format soda-gql field selection objects by inserting newlines.
328
+ * Optionally injects fragment keys for anonymous fragments.
329
+ */
330
+ const format = (options) => {
331
+ const { sourceCode, filePath, injectFragmentKeys = false } = options;
332
+ let module;
333
+ try {
334
+ const program = parseSync(sourceCode, {
335
+ syntax: "typescript",
336
+ tsx: filePath?.endsWith(".tsx") ?? true,
337
+ target: "es2022",
338
+ decorators: false,
339
+ dynamicImport: true
340
+ });
341
+ if (program.type !== "Module") {
342
+ return err({
343
+ type: "FormatError",
344
+ code: "PARSE_ERROR",
345
+ message: `Not a module${filePath ? ` (${filePath})` : ""}`
346
+ });
347
+ }
348
+ module = program;
349
+ } catch (cause) {
350
+ return err({
351
+ type: "FormatError",
352
+ code: "PARSE_ERROR",
353
+ message: `Failed to parse source code${filePath ? ` (${filePath})` : ""}`,
354
+ cause
355
+ });
356
+ }
357
+ const spanOffset = module.span.start;
358
+ const converter = createSwcSpanConverter(sourceCode);
359
+ const gqlIdentifiers = collectGqlIdentifiers(module);
360
+ if (gqlIdentifiers.size === 0) {
361
+ return ok({
362
+ modified: false,
363
+ sourceCode
364
+ });
365
+ }
366
+ const insertionPoints = [];
367
+ traverse(module, gqlIdentifiers, (object, _parent, callbackContext) => {
368
+ const objectStart = converter.byteOffsetToCharIndex(object.span.start - spanOffset);
369
+ if (callbackContext.isFragmentConfig && injectFragmentKeys && !hasKeyProperty(object)) {
370
+ const key = generateFragmentKey();
371
+ if (hasExistingNewline(sourceCode, objectStart)) {
372
+ const indentation = detectIndentationAfterBrace(sourceCode, objectStart) ?? "";
373
+ let insertPos = objectStart + 2;
374
+ if (sourceCode[objectStart + 1] === "\r") insertPos++;
375
+ insertionPoints.push({
376
+ position: insertPos,
377
+ content: createKeyInsertion(key, indentation)
378
+ });
379
+ } else {
380
+ insertionPoints.push({
381
+ position: objectStart + 1,
382
+ content: createKeyInsertion(key)
383
+ });
384
+ }
385
+ }
386
+ if (!callbackContext.isFragmentConfig && !hasExistingNewline(sourceCode, objectStart)) {
387
+ insertionPoints.push({
388
+ position: objectStart + 1,
389
+ content: NEWLINE_INSERTION
390
+ });
391
+ }
392
+ });
393
+ const graphqlResult = getGraphqlModule();
394
+ if (graphqlResult.isErr()) {
395
+ return err(graphqlResult.error);
396
+ }
397
+ const { parse: parseGraphql, print: printGraphql } = graphqlResult.value;
398
+ const positionCtx = {
399
+ spanOffset,
400
+ converter
401
+ };
402
+ const templates = walkAndExtract(module, gqlIdentifiers, positionCtx);
403
+ if (templates.length > 0) {
404
+ const defaultFormat = (source) => {
405
+ const ast = parseGraphql(source, { noLocation: false });
406
+ return printGraphql(ast);
407
+ };
408
+ const templateEdits = formatTemplatesInSource(templates, sourceCode, defaultFormat);
409
+ for (const edit of templateEdits) {
410
+ insertionPoints.push({
411
+ position: edit.start,
412
+ content: edit.newText,
413
+ endPosition: edit.end
414
+ });
415
+ }
416
+ }
417
+ if (insertionPoints.length === 0) {
418
+ return ok({
419
+ modified: false,
420
+ sourceCode
421
+ });
422
+ }
423
+ const sortedPoints = [...insertionPoints].sort((a, b) => b.position - a.position);
424
+ let result = sourceCode;
425
+ for (const point of sortedPoints) {
426
+ const end = point.endPosition ?? point.position;
427
+ result = result.slice(0, point.position) + point.content + result.slice(end);
428
+ }
429
+ return ok({
430
+ modified: true,
431
+ sourceCode: result
432
+ });
433
+ };
434
+ /**
435
+ * Check if a file needs formatting (has unformatted field selections).
436
+ * Useful for pre-commit hooks or CI checks.
437
+ */
438
+ const needsFormat = (options) => {
439
+ const { sourceCode, filePath } = options;
440
+ let module;
441
+ try {
442
+ const program = parseSync(sourceCode, {
443
+ syntax: "typescript",
444
+ tsx: filePath?.endsWith(".tsx") ?? true,
445
+ target: "es2022",
446
+ decorators: false,
447
+ dynamicImport: true
448
+ });
449
+ if (program.type !== "Module") {
450
+ return err({
451
+ type: "FormatError",
452
+ code: "PARSE_ERROR",
453
+ message: `Not a module${filePath ? ` (${filePath})` : ""}`
454
+ });
455
+ }
456
+ module = program;
457
+ } catch (cause) {
458
+ return err({
459
+ type: "FormatError",
460
+ code: "PARSE_ERROR",
461
+ message: `Failed to parse source code${filePath ? ` (${filePath})` : ""}`,
462
+ cause
463
+ });
464
+ }
465
+ const spanOffset = module.span.start;
466
+ const converter = createSwcSpanConverter(sourceCode);
467
+ const gqlIdentifiers = collectGqlIdentifiers(module);
468
+ if (gqlIdentifiers.size === 0) {
469
+ return ok(false);
470
+ }
471
+ let needsFormatting = false;
472
+ traverse(module, gqlIdentifiers, (object, _parent, callbackContext) => {
473
+ if (needsFormatting) return;
474
+ if (callbackContext.isFragmentConfig) return;
475
+ const objectStart = converter.byteOffsetToCharIndex(object.span.start - spanOffset);
476
+ if (!hasExistingNewline(sourceCode, objectStart)) {
477
+ needsFormatting = true;
478
+ }
479
+ });
480
+ if (!needsFormatting) {
481
+ const graphqlResult = getGraphqlModule();
482
+ if (graphqlResult.isErr()) {
483
+ return err(graphqlResult.error);
484
+ }
485
+ const { parse: parseGraphql, print: printGraphql } = graphqlResult.value;
486
+ const positionCtx = {
487
+ spanOffset,
488
+ converter
489
+ };
490
+ const templates = walkAndExtract(module, gqlIdentifiers, positionCtx);
491
+ if (templates.length > 0) {
492
+ const defaultFormat = (source) => {
493
+ const ast = parseGraphql(source, { noLocation: false });
494
+ return printGraphql(ast);
495
+ };
496
+ const templateEdits = formatTemplatesInSource(templates, sourceCode, defaultFormat);
497
+ if (templateEdits.length > 0) {
498
+ needsFormatting = true;
499
+ }
500
+ }
501
+ }
502
+ return ok(needsFormatting);
503
+ };
504
+
505
+ //#endregion
506
+ export { format, needsFormat };
507
+ //# sourceMappingURL=formatter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatter.mjs","names":["bodyObject: ObjectExpression | null","_graphqlModule: GraphqlModule | undefined","_graphqlModuleError: Error | undefined","initialContext: TraversalContext","module: Module","insertionPoints: InsertionPoint[]","positionCtx: PositionTrackingContext","defaultFormat: FormatGraphqlFn"],"sources":["../src/formatter/detection.ts","../src/formatter/insertion.ts","../src/formatter/format.ts"],"sourcesContent":["import type {\n ArrowFunctionExpression,\n CallExpression,\n Expression,\n Module,\n ObjectExpression,\n ObjectPatternProperty,\n Pattern,\n} from \"@swc/types\";\n\n/**\n * Check if an expression is a reference to gql\n * Handles: gql, namespace.gql\n */\nexport const isGqlReference = (node: Expression, gqlIdentifiers: ReadonlySet<string>): boolean => {\n // Unwrap TsNonNullExpression: gql! -> gql\n const unwrapped = node.type === \"TsNonNullExpression\" ? (node as { type: string; expression: Expression }).expression : node;\n if (unwrapped.type === \"Identifier\") {\n return gqlIdentifiers.has(unwrapped.value);\n }\n if (unwrapped.type === \"MemberExpression\" && unwrapped.property.type === \"Identifier\" && unwrapped.property.value === \"gql\") {\n return true;\n }\n return false;\n};\n\n/**\n * Check if a call expression is a gql definition call\n * Handles: gql.default(...), gql.model(...), gql.schemaName(...) (multi-schema)\n */\nexport const isGqlDefinitionCall = (node: CallExpression, gqlIdentifiers: ReadonlySet<string>): boolean => {\n if (node.callee.type !== \"MemberExpression\") return false;\n const { object } = node.callee;\n\n // Check object is a gql reference first\n if (!isGqlReference(object, gqlIdentifiers)) return false;\n\n // Verify first argument is an arrow function (factory pattern)\n // SWC's arguments are ExprOrSpread[], so access via .expression\n const firstArg = node.arguments[0];\n if (!firstArg || (firstArg.expression.type !== \"ArrowFunctionExpression\" && firstArg.expression.type !== \"FunctionExpression\"))\n return false;\n\n return true;\n};\n\n/**\n * Check if an object expression is a field selection object\n * Field selection objects are returned from arrow functions with ({ f }) or ({ f, $ }) parameter\n */\nexport const isFieldSelectionObject = (object: ObjectExpression, parent: ArrowFunctionExpression): boolean => {\n // The object must be the body of the arrow function\n // Handle both direct ObjectExpression and parenthesized ObjectExpression: `({ ... })`\n let bodyObject: ObjectExpression | null = null;\n\n if (parent.body.type === \"ObjectExpression\") {\n bodyObject = parent.body;\n } else if (parent.body.type === \"ParenthesisExpression\") {\n // Handle `({ f }) => ({ ...f.id() })` pattern where body is parenthesized\n const inner = parent.body.expression;\n if (inner.type === \"ObjectExpression\") {\n bodyObject = inner;\n }\n }\n\n if (!bodyObject) return false;\n if (bodyObject.span.start !== object.span.start) return false;\n\n // Check if first parameter has 'f' destructured\n const param = parent.params[0];\n if (!param || param.type !== \"ObjectPattern\") return false;\n\n return param.properties.some((p: ObjectPatternProperty) => {\n if (p.type === \"KeyValuePatternProperty\" && p.key.type === \"Identifier\") {\n return p.key.value === \"f\";\n }\n if (p.type === \"AssignmentPatternProperty\" && p.key.type === \"Identifier\") {\n return p.key.value === \"f\";\n }\n return false;\n });\n};\n\n/**\n * Collect gql identifiers from import declarations\n */\nexport const collectGqlIdentifiers = (module: Module): Set<string> => {\n const gqlIdentifiers = new Set<string>();\n\n for (const item of module.body) {\n if (item.type !== \"ImportDeclaration\") continue;\n\n for (const specifier of item.specifiers) {\n if (specifier.type === \"ImportSpecifier\") {\n const imported = specifier.imported?.value ?? specifier.local.value;\n if (imported === \"gql\") {\n gqlIdentifiers.add(specifier.local.value);\n }\n }\n if (specifier.type === \"ImportDefaultSpecifier\") {\n // Check if default import might be gql\n if (specifier.local.value === \"gql\") {\n gqlIdentifiers.add(specifier.local.value);\n }\n }\n if (specifier.type === \"ImportNamespaceSpecifier\") {\n // namespace import: import * as ns from \"...\"\n // Would need ns.gql pattern - handled by isGqlReference\n }\n }\n }\n\n return gqlIdentifiers;\n};\n\n/**\n * Check if a call expression is a fragment definition call.\n * Pattern: fragment.TypeName({ ... }) where `fragment` comes from gql factory destructuring.\n */\nexport const isFragmentDefinitionCall = (node: CallExpression, fragmentIdentifiers: ReadonlySet<string>): boolean => {\n if (node.callee.type !== \"MemberExpression\") return false;\n\n const { object } = node.callee;\n\n if (object.type !== \"Identifier\") return false;\n if (!fragmentIdentifiers.has(object.value)) return false;\n\n const firstArg = node.arguments[0];\n if (!firstArg || firstArg.expression.type !== \"ObjectExpression\") return false;\n\n return true;\n};\n\n/**\n * Check if an object expression already has a `key` property.\n */\nexport const hasKeyProperty = (obj: ObjectExpression): boolean => {\n return obj.properties.some((prop) => {\n if (prop.type === \"KeyValueProperty\" && prop.key.type === \"Identifier\") {\n return prop.key.value === \"key\";\n }\n return false;\n });\n};\n\n/**\n * Collect fragment identifiers from gql factory arrow function parameter.\n * Looks for patterns like: ({ fragment }) => ... or ({ fragment: f }) => ...\n */\nexport const collectFragmentIdentifiers = (arrowFunction: ArrowFunctionExpression): Set<string> => {\n const fragmentIdentifiers = new Set<string>();\n\n const param = arrowFunction.params[0];\n if (param?.type !== \"ObjectPattern\") return fragmentIdentifiers;\n\n for (const p of param.properties as ObjectPatternProperty[]) {\n if (p.type === \"KeyValuePatternProperty\" && p.key.type === \"Identifier\" && p.key.value === \"fragment\") {\n const localName = extractIdentifierName(p.value);\n if (localName) fragmentIdentifiers.add(localName);\n }\n if (p.type === \"AssignmentPatternProperty\" && p.key.type === \"Identifier\" && p.key.value === \"fragment\") {\n fragmentIdentifiers.add(p.key.value);\n }\n }\n\n return fragmentIdentifiers;\n};\n\n/**\n * Extract identifier name from a pattern node.\n */\nconst extractIdentifierName = (pattern: Pattern): string | null => {\n if (pattern.type === \"Identifier\") return pattern.value;\n // biome-ignore lint/suspicious/noExplicitAny: SWC types\n if ((pattern as any).type === \"BindingIdentifier\") return (pattern as any).value;\n return null;\n};\n","import { randomBytes } from \"node:crypto\";\n\n/**\n * The newline string to insert after object opening brace\n */\nexport const NEWLINE_INSERTION = \"\\n\";\n\n/**\n * Generate a random 8-character hex key for fragment identification.\n * Uses Node.js crypto for cryptographically secure random bytes.\n */\nexport const generateFragmentKey = (): string => {\n return randomBytes(4).toString(\"hex\");\n};\n\n/**\n * Create the key property insertion string.\n *\n * For single-line objects: returns ` key: \"xxxxxxxx\",\\n`\n * For multi-line objects (with indentation): returns `{indentation}key: \"xxxxxxxx\",\\n`\n * (the existing indentation before the next property is preserved)\n *\n * @param key - The hex key string\n * @param indentation - Optional indentation string for multi-line objects\n */\nexport const createKeyInsertion = (key: string, indentation?: string): string => {\n if (indentation !== undefined) {\n // Multi-line: key goes on its own line with indentation\n // The next property's indentation is already in the source, so don't duplicate it\n return `${indentation}key: \"${key}\",\\n`;\n }\n // Single-line: space before key, newline after\n return ` key: \"${key}\",\\n`;\n};\n\n/**\n * Check if there's already a newline after the opening brace.\n * Uses string inspection rather than AST.\n *\n * @param source - The source code string\n * @param objectStartPos - The position of the `{` character in the source\n */\nexport const hasExistingNewline = (source: string, objectStartPos: number): boolean => {\n // Skip the `{` character\n const pos = objectStartPos + 1;\n\n // Check if next character is a newline\n const nextChar = source[pos];\n return nextChar === \"\\n\" || nextChar === \"\\r\";\n};\n\n/**\n * Detect the indentation used after an opening brace.\n * Returns the whitespace string after the newline, or null if no newline.\n *\n * @param source - The source code string\n * @param objectStartPos - The position of the `{` character\n */\nexport const detectIndentationAfterBrace = (source: string, objectStartPos: number): string | null => {\n const afterBrace = objectStartPos + 1;\n const char = source[afterBrace];\n\n // Check for newline (handles both \\n and \\r\\n)\n if (char !== \"\\n\" && char !== \"\\r\") {\n return null;\n }\n\n // Skip past the newline character(s)\n let pos = afterBrace + 1;\n if (char === \"\\r\" && source[pos] === \"\\n\") {\n pos++;\n }\n\n // Collect whitespace (indentation)\n let indentation = \"\";\n while (pos < source.length) {\n const c = source[pos];\n if (c === \" \" || c === \"\\t\") {\n indentation += c;\n pos++;\n } else {\n break;\n }\n }\n\n return indentation;\n};\n","import { createRequire } from \"node:module\";\nimport {\n type FormatGraphqlFn,\n formatTemplatesInSource,\n type PositionTrackingContext,\n walkAndExtract,\n} from \"@soda-gql/common/template-extraction\";\nimport { createSwcSpanConverter } from \"@soda-gql/common/utils\";\nimport { parseSync } from \"@swc/core\";\nimport type { ArrowFunctionExpression, CallExpression, Module, Node, ObjectExpression } from \"@swc/types\";\nimport { err, ok, type Result } from \"neverthrow\";\n\nconst require = createRequire(import.meta.url);\n\ntype GraphqlModule = {\n parse: (source: string, options?: { noLocation?: boolean }) => unknown;\n print: (ast: unknown) => string;\n};\n\nlet _graphqlModule: GraphqlModule | undefined;\nlet _graphqlModuleError: Error | undefined;\n\nconst getGraphqlModule = (): Result<GraphqlModule, FormatError> => {\n if (_graphqlModuleError) {\n return err({\n type: \"FormatError\",\n code: \"MISSING_DEPENDENCY\",\n message: 'The \"graphql\" package is required for soda-gql formatter. Install it with: bun add graphql',\n });\n }\n if (!_graphqlModule) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n _graphqlModule = require(\"graphql\") as GraphqlModule;\n } catch (cause) {\n _graphqlModuleError = cause instanceof Error ? cause : new Error(String(cause));\n return err({\n type: \"FormatError\",\n code: \"MISSING_DEPENDENCY\",\n message: 'The \"graphql\" package is required for soda-gql formatter. Install it with: bun add graphql',\n cause,\n });\n }\n }\n return ok(_graphqlModule);\n};\n\nimport {\n collectFragmentIdentifiers,\n collectGqlIdentifiers,\n hasKeyProperty,\n isFieldSelectionObject,\n isFragmentDefinitionCall,\n isGqlDefinitionCall,\n} from \"./detection\";\nimport {\n createKeyInsertion,\n detectIndentationAfterBrace,\n generateFragmentKey,\n hasExistingNewline,\n NEWLINE_INSERTION,\n} from \"./insertion\";\nimport type { FormatError, FormatOptions, FormatResult } from \"./types\";\n\ntype InsertionPoint = {\n readonly position: number;\n readonly content: string;\n readonly endPosition?: number;\n};\n\ntype TraversalContext = {\n insideGqlDefinition: boolean;\n currentArrowFunction: ArrowFunctionExpression | null;\n fragmentIdentifiers: ReadonlySet<string>;\n};\n\ntype TraversalCallbackContext = {\n readonly isFragmentConfig: boolean;\n};\n\ntype TraversalCallback = (\n object: ObjectExpression,\n parent: ArrowFunctionExpression,\n callbackContext: TraversalCallbackContext,\n) => void;\n\n/**\n * Simple recursive AST traversal\n */\nconst traverseNode = (\n node: Node,\n context: TraversalContext,\n gqlIdentifiers: ReadonlySet<string>,\n onObjectExpression: TraversalCallback,\n): void => {\n // Check for gql definition call entry and collect fragment identifiers\n if (node.type === \"CallExpression\" && isGqlDefinitionCall(node as CallExpression, gqlIdentifiers)) {\n const call = node as CallExpression;\n const firstArg = call.arguments[0];\n if (firstArg?.expression.type === \"ArrowFunctionExpression\") {\n const arrow = firstArg.expression as ArrowFunctionExpression;\n const fragmentIds = collectFragmentIdentifiers(arrow);\n context = {\n ...context,\n insideGqlDefinition: true,\n fragmentIdentifiers: new Set([...context.fragmentIdentifiers, ...fragmentIds]),\n };\n } else {\n context = { ...context, insideGqlDefinition: true };\n }\n }\n\n // Check for fragment definition call: fragment.TypeName({ ... })\n if (\n node.type === \"CallExpression\" &&\n context.insideGqlDefinition &&\n isFragmentDefinitionCall(node as CallExpression, context.fragmentIdentifiers)\n ) {\n const call = node as CallExpression;\n const firstArg = call.arguments[0];\n if (firstArg?.expression.type === \"ObjectExpression\" && context.currentArrowFunction) {\n onObjectExpression(firstArg.expression as ObjectExpression, context.currentArrowFunction, {\n isFragmentConfig: true,\n });\n }\n }\n\n // Handle object expressions - check if it's the body of the current arrow function\n if (\n node.type === \"ObjectExpression\" &&\n context.insideGqlDefinition &&\n context.currentArrowFunction &&\n isFieldSelectionObject(node as ObjectExpression, context.currentArrowFunction)\n ) {\n onObjectExpression(node as ObjectExpression, context.currentArrowFunction, { isFragmentConfig: false });\n }\n\n // Recursively visit children\n if (node.type === \"CallExpression\") {\n const call = node as CallExpression;\n traverseNode(call.callee as Node, context, gqlIdentifiers, onObjectExpression);\n for (const arg of call.arguments) {\n traverseNode(arg.expression as Node, context, gqlIdentifiers, onObjectExpression);\n }\n } else if (node.type === \"ArrowFunctionExpression\") {\n const arrow = node as ArrowFunctionExpression;\n // Update context with the new arrow function\n const childContext = { ...context, currentArrowFunction: arrow };\n if (arrow.body.type !== \"BlockStatement\") {\n traverseNode(arrow.body as Node, childContext, gqlIdentifiers, onObjectExpression);\n }\n } else if (node.type === \"ParenthesisExpression\") {\n // Handle parenthesized expressions like `({ ...f.id() })`\n // biome-ignore lint/suspicious/noExplicitAny: SWC types\n const paren = node as any;\n if (paren.expression) {\n traverseNode(paren.expression as Node, context, gqlIdentifiers, onObjectExpression);\n }\n } else if (node.type === \"MemberExpression\") {\n // biome-ignore lint/suspicious/noExplicitAny: SWC types\n const member = node as any;\n traverseNode(member.object as Node, context, gqlIdentifiers, onObjectExpression);\n } else if (node.type === \"ObjectExpression\") {\n const obj = node as ObjectExpression;\n for (const prop of obj.properties) {\n if (prop.type === \"SpreadElement\") {\n traverseNode(prop.arguments as Node, context, gqlIdentifiers, onObjectExpression);\n } else if (prop.type === \"KeyValueProperty\") {\n traverseNode(prop.value as Node, context, gqlIdentifiers, onObjectExpression);\n }\n }\n } else {\n // Generic traversal for other node types\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n for (const child of value) {\n if (child && typeof child === \"object\" && \"type\" in child) {\n traverseNode(child as Node, context, gqlIdentifiers, onObjectExpression);\n }\n }\n } else if (value && typeof value === \"object\" && \"type\" in value) {\n traverseNode(value as Node, context, gqlIdentifiers, onObjectExpression);\n }\n }\n }\n};\n\nconst traverse = (module: Module, gqlIdentifiers: ReadonlySet<string>, onObjectExpression: TraversalCallback): void => {\n const initialContext: TraversalContext = {\n insideGqlDefinition: false,\n currentArrowFunction: null,\n fragmentIdentifiers: new Set(),\n };\n for (const statement of module.body) {\n traverseNode(statement, initialContext, gqlIdentifiers, onObjectExpression);\n }\n};\n\n/**\n * Format soda-gql field selection objects by inserting newlines.\n * Optionally injects fragment keys for anonymous fragments.\n */\nexport const format = (options: FormatOptions): Result<FormatResult, FormatError> => {\n const { sourceCode, filePath, injectFragmentKeys = false } = options;\n\n // Parse source code with SWC\n let module: Module;\n try {\n const program = parseSync(sourceCode, {\n syntax: \"typescript\",\n tsx: filePath?.endsWith(\".tsx\") ?? true,\n target: \"es2022\",\n decorators: false,\n dynamicImport: true,\n });\n\n if (program.type !== \"Module\") {\n return err({\n type: \"FormatError\",\n code: \"PARSE_ERROR\",\n message: `Not a module${filePath ? ` (${filePath})` : \"\"}`,\n });\n }\n module = program;\n } catch (cause) {\n return err({\n type: \"FormatError\",\n code: \"PARSE_ERROR\",\n message: `Failed to parse source code${filePath ? ` (${filePath})` : \"\"}`,\n cause,\n });\n }\n\n // Calculate span offset for position normalization\n // SWC's BytePos counter accumulates across parseSync calls within the same process\n // Using module.span.start ensures correct position calculation regardless of accumulation\n const spanOffset = module.span.start;\n\n // SWC returns UTF-8 byte offsets; JS strings use UTF-16 code units.\n // The converter handles this mapping (fast path for ASCII-only sources).\n const converter = createSwcSpanConverter(sourceCode);\n\n // Collect gql identifiers from imports\n const gqlIdentifiers = collectGqlIdentifiers(module);\n if (gqlIdentifiers.size === 0) {\n return ok({ modified: false, sourceCode });\n }\n\n // Collect insertion points\n const insertionPoints: InsertionPoint[] = [];\n\n traverse(module, gqlIdentifiers, (object, _parent, callbackContext) => {\n // Calculate actual position in source (byte offset → char index)\n const objectStart = converter.byteOffsetToCharIndex(object.span.start - spanOffset);\n\n // For fragment config objects, inject key if enabled and not present\n if (callbackContext.isFragmentConfig && injectFragmentKeys && !hasKeyProperty(object)) {\n const key = generateFragmentKey();\n\n if (hasExistingNewline(sourceCode, objectStart)) {\n // Multi-line: insert after newline, preserving indentation\n const indentation = detectIndentationAfterBrace(sourceCode, objectStart) ?? \"\";\n let insertPos = objectStart + 2; // Skip { and \\n\n if (sourceCode[objectStart + 1] === \"\\r\") insertPos++;\n\n insertionPoints.push({\n position: insertPos,\n content: createKeyInsertion(key, indentation),\n });\n } else {\n // Single-line: insert right after {\n insertionPoints.push({\n position: objectStart + 1,\n content: createKeyInsertion(key),\n });\n }\n }\n\n // For field selection objects, insert newline if not present\n if (!callbackContext.isFragmentConfig && !hasExistingNewline(sourceCode, objectStart)) {\n insertionPoints.push({\n position: objectStart + 1,\n content: NEWLINE_INSERTION,\n });\n }\n });\n\n // Tagged template formatting\n const graphqlResult = getGraphqlModule();\n if (graphqlResult.isErr()) {\n return err(graphqlResult.error);\n }\n const { parse: parseGraphql, print: printGraphql } = graphqlResult.value;\n\n const positionCtx: PositionTrackingContext = { spanOffset, converter };\n const templates = walkAndExtract(module as unknown as Node, gqlIdentifiers, positionCtx);\n\n if (templates.length > 0) {\n const defaultFormat: FormatGraphqlFn = (source) => {\n const ast = parseGraphql(source, { noLocation: false });\n return printGraphql(ast);\n };\n\n const templateEdits = formatTemplatesInSource(templates, sourceCode, defaultFormat);\n\n for (const edit of templateEdits) {\n insertionPoints.push({\n position: edit.start,\n content: edit.newText,\n endPosition: edit.end,\n });\n }\n }\n\n // Apply insertions\n if (insertionPoints.length === 0) {\n return ok({ modified: false, sourceCode });\n }\n\n // Sort in descending order to insert from end to beginning\n // This preserves earlier positions while modifying later parts\n const sortedPoints = [...insertionPoints].sort((a, b) => b.position - a.position);\n\n let result = sourceCode;\n for (const point of sortedPoints) {\n const end = point.endPosition ?? point.position;\n result = result.slice(0, point.position) + point.content + result.slice(end);\n }\n\n return ok({ modified: true, sourceCode: result });\n};\n\n/**\n * Check if a file needs formatting (has unformatted field selections).\n * Useful for pre-commit hooks or CI checks.\n */\nexport const needsFormat = (options: FormatOptions): Result<boolean, FormatError> => {\n const { sourceCode, filePath } = options;\n\n // Parse source code with SWC\n let module: Module;\n try {\n const program = parseSync(sourceCode, {\n syntax: \"typescript\",\n tsx: filePath?.endsWith(\".tsx\") ?? true,\n target: \"es2022\",\n decorators: false,\n dynamicImport: true,\n });\n\n if (program.type !== \"Module\") {\n return err({\n type: \"FormatError\",\n code: \"PARSE_ERROR\",\n message: `Not a module${filePath ? ` (${filePath})` : \"\"}`,\n });\n }\n module = program;\n } catch (cause) {\n return err({\n type: \"FormatError\",\n code: \"PARSE_ERROR\",\n message: `Failed to parse source code${filePath ? ` (${filePath})` : \"\"}`,\n cause,\n });\n }\n\n const spanOffset = module.span.start;\n const converter = createSwcSpanConverter(sourceCode);\n const gqlIdentifiers = collectGqlIdentifiers(module);\n\n if (gqlIdentifiers.size === 0) {\n return ok(false);\n }\n\n let needsFormatting = false;\n\n traverse(module, gqlIdentifiers, (object, _parent, callbackContext) => {\n if (needsFormatting) return; // Early exit\n\n // Skip fragment config objects for needsFormat check (key injection is optional)\n if (callbackContext.isFragmentConfig) return;\n\n const objectStart = converter.byteOffsetToCharIndex(object.span.start - spanOffset);\n if (!hasExistingNewline(sourceCode, objectStart)) {\n needsFormatting = true;\n }\n });\n\n // Check tagged templates\n if (!needsFormatting) {\n const graphqlResult = getGraphqlModule();\n if (graphqlResult.isErr()) {\n return err(graphqlResult.error);\n }\n const { parse: parseGraphql, print: printGraphql } = graphqlResult.value;\n\n const positionCtx: PositionTrackingContext = { spanOffset, converter };\n const templates = walkAndExtract(module as unknown as Node, gqlIdentifiers, positionCtx);\n\n if (templates.length > 0) {\n const defaultFormat: FormatGraphqlFn = (source) => {\n const ast = parseGraphql(source, { noLocation: false });\n return printGraphql(ast);\n };\n\n const templateEdits = formatTemplatesInSource(templates, sourceCode, defaultFormat);\n if (templateEdits.length > 0) {\n needsFormatting = true;\n }\n }\n }\n\n return ok(needsFormatting);\n};\n"],"mappings":";;;;;;;;;;;;AAcA,MAAa,kBAAkB,MAAkB,mBAAiD;CAEhG,MAAM,YAAY,KAAK,SAAS,wBAAyB,KAAkD,aAAa;AACxH,KAAI,UAAU,SAAS,cAAc;AACnC,SAAO,eAAe,IAAI,UAAU,MAAM;;AAE5C,KAAI,UAAU,SAAS,sBAAsB,UAAU,SAAS,SAAS,gBAAgB,UAAU,SAAS,UAAU,OAAO;AAC3H,SAAO;;AAET,QAAO;;;;;;AAOT,MAAa,uBAAuB,MAAsB,mBAAiD;AACzG,KAAI,KAAK,OAAO,SAAS,mBAAoB,QAAO;CACpD,MAAM,EAAE,WAAW,KAAK;AAGxB,KAAI,CAAC,eAAe,QAAQ,eAAe,CAAE,QAAO;CAIpD,MAAM,WAAW,KAAK,UAAU;AAChC,KAAI,CAAC,YAAa,SAAS,WAAW,SAAS,6BAA6B,SAAS,WAAW,SAAS,qBACvG,QAAO;AAET,QAAO;;;;;;AAOT,MAAa,0BAA0B,QAA0B,WAA6C;CAG5G,IAAIA,aAAsC;AAE1C,KAAI,OAAO,KAAK,SAAS,oBAAoB;AAC3C,eAAa,OAAO;YACX,OAAO,KAAK,SAAS,yBAAyB;EAEvD,MAAM,QAAQ,OAAO,KAAK;AAC1B,MAAI,MAAM,SAAS,oBAAoB;AACrC,gBAAa;;;AAIjB,KAAI,CAAC,WAAY,QAAO;AACxB,KAAI,WAAW,KAAK,UAAU,OAAO,KAAK,MAAO,QAAO;CAGxD,MAAM,QAAQ,OAAO,OAAO;AAC5B,KAAI,CAAC,SAAS,MAAM,SAAS,gBAAiB,QAAO;AAErD,QAAO,MAAM,WAAW,MAAM,MAA6B;AACzD,MAAI,EAAE,SAAS,6BAA6B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AAgB,wBAAwB,WAAW,YAAY,cAAc;AACnF,OAAI,cAAc,SAAS,GAAG;AAC5B,sBAAkB;;;;AAKxB,QAAO,GAAG,gBAAgB"}
package/dist/index.cjs ADDED
@@ -0,0 +1,13 @@
1
+
2
+ //#region packages/tools/src/index.ts
3
+ /**
4
+ * @soda-gql/tools has no root export. Use subpath imports instead:
5
+ * - `@soda-gql/tools/codegen`
6
+ * - `@soda-gql/tools/typegen`
7
+ * - `@soda-gql/tools/formatter`
8
+ */
9
+ const DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS = undefined;
10
+
11
+ //#endregion
12
+ exports.DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS = DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS;
13
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS: never"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @soda-gql/tools has no root export. Use subpath imports instead:\n * - `@soda-gql/tools/codegen`\n * - `@soda-gql/tools/typegen`\n * - `@soda-gql/tools/formatter`\n */\nexport const DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS: never = undefined as never;\n"],"mappings":";;;;;;;;AAMA,MAAaA,8CAAqD"}
@@ -0,0 +1,11 @@
1
+ //#region packages/tools/src/index.d.ts
2
+ /**
3
+ * @soda-gql/tools has no root export. Use subpath imports instead:
4
+ * - `@soda-gql/tools/codegen`
5
+ * - `@soda-gql/tools/typegen`
6
+ * - `@soda-gql/tools/formatter`
7
+ */
8
+ declare const DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS: never;
9
+ //#endregion
10
+ export { DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS };
11
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;;cAAa"}
@@ -0,0 +1,11 @@
1
+ //#region packages/tools/src/index.d.ts
2
+ /**
3
+ * @soda-gql/tools has no root export. Use subpath imports instead:
4
+ * - `@soda-gql/tools/codegen`
5
+ * - `@soda-gql/tools/typegen`
6
+ * - `@soda-gql/tools/formatter`
7
+ */
8
+ declare const DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS: never;
9
+ //#endregion
10
+ export { DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS };
11
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;AAMA;;;;;cAAa"}
package/dist/index.mjs ADDED
@@ -0,0 +1,12 @@
1
+ //#region packages/tools/src/index.ts
2
+ /**
3
+ * @soda-gql/tools has no root export. Use subpath imports instead:
4
+ * - `@soda-gql/tools/codegen`
5
+ * - `@soda-gql/tools/typegen`
6
+ * - `@soda-gql/tools/formatter`
7
+ */
8
+ const DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS = undefined;
9
+
10
+ //#endregion
11
+ export { DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS };
12
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS: never"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @soda-gql/tools has no root export. Use subpath imports instead:\n * - `@soda-gql/tools/codegen`\n * - `@soda-gql/tools/typegen`\n * - `@soda-gql/tools/formatter`\n */\nexport const DO_NOT_IMPORT_ROOT_OVER_IMPORTING_SUB_PATHS: never = undefined as never;\n"],"mappings":";;;;;;;AAMA,MAAaA,8CAAqD"}