|
1 | 1 | import path from "node:path"; |
2 | 2 | import { promises as fs } from "node:fs"; |
3 | | -import { |
4 | | - $, |
5 | | - _CodecsRegistry, |
6 | | - _ScalarCodec, |
7 | | - systemUtils, |
8 | | - type Client, |
9 | | - type Executor, |
10 | | -} from "gel"; |
| 3 | +import { $, systemUtils, type Client, type Executor } from "gel"; |
11 | 4 | import { type CommandOptions } from "./commandutil"; |
12 | 5 | import { headerComment } from "./genutil"; |
13 | 6 | import type { Target } from "./genutil"; |
@@ -73,7 +66,7 @@ currently supported.`); |
73 | 66 |
|
74 | 67 | try { |
75 | 68 | const query = await readFileUtf8(p); |
76 | | - const types = await analyzeQuery(client, query, { |
| 69 | + const types = await $.analyzeQuery(client, query, { |
77 | 70 | useResolvedCodecType: params.options.useResolvedCodecType, |
78 | 71 | }); |
79 | 72 | console.log(` ${prettyPath}`); |
@@ -129,7 +122,7 @@ currently supported.`); |
129 | 122 | try { |
130 | 123 | const query = await readFileUtf8(p); |
131 | 124 | if (!query) return; |
132 | | - const types = await analyzeQuery(client, query, { |
| 125 | + const types = await $.analyzeQuery(client, query, { |
133 | 126 | useResolvedCodecType: params.options.useResolvedCodecType, |
134 | 127 | }); |
135 | 128 | const files = generateFiles({ |
@@ -364,56 +357,3 @@ export class ImportMap extends Map<string, Set<string>> { |
364 | 357 | return out; |
365 | 358 | } |
366 | 359 | } |
367 | | - |
368 | | -const resolvedCodecTypeScalarTypeGenerator = $.defineCodecGeneratorTuple( |
369 | | - _ScalarCodec, |
370 | | - (codec, ctx) => { |
371 | | - if (codec.tsModule) { |
372 | | - ctx.imports.add(codec.tsModule, codec.tsType); |
373 | | - } |
374 | | - const isCustomScalar = !codec.typeName.startsWith("std::"); |
375 | | - if (isCustomScalar) { |
376 | | - ctx.imports.add("gel", "ResolvedCodecType"); |
377 | | - return `ResolvedCodecType<"${codec.typeName}", ${codec.tsType}>`; |
378 | | - } |
379 | | - return codec.tsType; |
380 | | - }, |
381 | | -); |
382 | | - |
383 | | -async function analyzeQuery( |
384 | | - client: Client, |
385 | | - query: string, |
386 | | - { useResolvedCodecType }: { useResolvedCodecType?: boolean } = {}, |
387 | | -): ReturnType<typeof $.analyzeQuery> { |
388 | | - const { |
389 | | - cardinality, |
390 | | - capabilities, |
391 | | - in: inCodec, |
392 | | - out: outCodec, |
393 | | - } = await client.describe(query); |
394 | | - |
395 | | - const generators = new Map([ |
396 | | - ...$.defaultCodecGenerators.entries(), |
397 | | - ...(useResolvedCodecType ? [resolvedCodecTypeScalarTypeGenerator] : []), |
398 | | - ]); |
399 | | - |
400 | | - const args = $.generateTSTypeFromCodec(inCodec, $.Cardinality.One, { |
401 | | - optionalNulls: true, |
402 | | - readonly: true, |
403 | | - generators: generators, |
404 | | - }); |
405 | | - const result = $.generateTSTypeFromCodec(outCodec, cardinality, { |
406 | | - generators: generators, |
407 | | - }); |
408 | | - |
409 | | - const imports = args.imports.merge(result.imports); |
410 | | - return { |
411 | | - result: result.type, |
412 | | - args: args.type, |
413 | | - cardinality, |
414 | | - capabilities, |
415 | | - query, |
416 | | - importMap: imports, |
417 | | - imports: imports.get("gel") ?? new Set(), |
418 | | - }; |
419 | | -} |
0 commit comments