@sanity/codegen 6.0.3-canary.0 → 6.1.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.
@@ -24,7 +24,17 @@ export declare type CodegenConfig = TypeGenConfig
24
24
  */
25
25
  export declare const configDefinition: z.ZodObject<
26
26
  {
27
- formatGeneratedCode: z.ZodDefault<z.ZodBoolean>
27
+ formatGeneratedCode: z.ZodDefault<
28
+ z.ZodUnion<
29
+ readonly [
30
+ z.ZodBoolean,
31
+ z.ZodEnum<{
32
+ oxfmt: 'oxfmt'
33
+ prettier: 'prettier'
34
+ }>,
35
+ ]
36
+ >
37
+ >
28
38
  generates: z.ZodDefault<z.ZodString>
29
39
  overloadClientMethods: z.ZodDefault<z.ZodBoolean>
30
40
  path: z.ZodDefault<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString>]>>
@@ -1,11 +1,11 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
2
  import { spinner } from '@sanity/cli-core/ux';
3
- import { format, resolveConfig as resolvePrettierConfig } from 'prettier';
4
3
  import { count } from '../utils/count.js';
5
4
  import { debug } from '../utils/debug.js';
6
5
  import { formatPath } from '../utils/formatPath.js';
7
6
  import { getMessage } from '../utils/getMessage.js';
8
7
  import { percent } from '../utils/percent.js';
8
+ import { defineFormatter } from '../utils/resolveFormatter.js';
9
9
  import { generatedFileWarning } from './generatedFileWarning.js';
10
10
  /**
11
11
  * Processes the event stream from a typegen worker thread.
@@ -57,18 +57,22 @@ import { generatedFileWarning } from './generatedFileWarning.js';
57
57
  const code = `${generatedFileWarning}${result.code}`;
58
58
  await writeFile(generates, code);
59
59
  let formattingError = false;
60
- if (formatGeneratedCode) {
61
- spin.text = `Formatting generated types with prettier…`;
62
- try {
63
- const prettierConfig = await resolvePrettierConfig(generates);
64
- const formattedCode = await format(code, {
65
- ...prettierConfig,
66
- parser: 'typescript'
67
- });
68
- await writeFile(generates, formattedCode);
69
- } catch (err) {
70
- formattingError = true;
71
- spin.warn(`Failed to format generated types with prettier: ${getMessage(err)}`);
60
+ let formatterName;
61
+ if (formatGeneratedCode !== false) {
62
+ const formatter = defineFormatter(formatGeneratedCode);
63
+ if (formatter) {
64
+ formatterName = formatter.name;
65
+ try {
66
+ const { format } = await formatter.resolve();
67
+ if (format) {
68
+ spin.text = `Formatting generated types with ${formatter.name}…`;
69
+ const formattedCode = await format(generates, code);
70
+ await writeFile(generates, formattedCode);
71
+ }
72
+ } catch (err) {
73
+ formattingError = true;
74
+ spin.warn(`Failed to format generated types with ${formatter.name}: ${getMessage(err)}`);
75
+ }
72
76
  }
73
77
  }
74
78
  if (filesWithErrors > 0) {
@@ -87,8 +91,8 @@ import { generatedFileWarning } from './generatedFileWarning.js';
87
91
  unknownTypeNodesRatio: typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0
88
92
  };
89
93
  let successText = `Successfully generated types to ${formatPath(generates)} in ${Number(stats.duration).toFixed(0)}ms` + `\n └─ ${count(queriesCount, 'queries', 'query')} and ${count(schemaTypesCount, 'schema types', 'schema type')}` + `\n └─ found queries in ${count(queryFilesCount, 'files', 'file')} after evaluating ${count(evaluatedFiles, 'files', 'file')}`;
90
- if (formatGeneratedCode) {
91
- successText += `\n └─ ${formattingError ? 'an error occured during formatting' : 'formatted the generated code with prettier'}`;
94
+ if (formatterName) {
95
+ successText += `\n └─ ${formattingError ? 'an error occurred during formatting' : `formatted the generated code with ${formatterName}`}`;
92
96
  }
93
97
  spin.succeed(successText);
94
98
  return {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/actions/streamProcessor.ts"],"sourcesContent":["import {writeFile} from 'node:fs/promises'\n\nimport {spinner} from '@sanity/cli-core/ux'\nimport {WorkerChannelReceiver} from '@sanity/worker-channels'\nimport {format, resolveConfig as resolvePrettierConfig} from 'prettier'\n\nimport {TypeGenConfig} from '../readConfig.js'\nimport {count} from '../utils/count.js'\nimport {debug} from '../utils/debug.js'\nimport {formatPath} from '../utils/formatPath.js'\nimport {getMessage} from '../utils/getMessage.js'\nimport {percent} from '../utils/percent.js'\nimport {generatedFileWarning} from './generatedFileWarning.js'\nimport {TypegenWorkerChannel} from './types.js'\n\n/**\n * Processes the event stream from a typegen worker thread.\n *\n * Listens to worker channel events, displays progress via CLI spinners,\n * writes the generated types to disk, and optionally formats with prettier.\n *\n * @param receiver - Worker channel receiver for typegen events\n * @param options - Typegen configuration options\n * @returns Generation result containing the generated code and statistics\n */\nexport async function processTypegenWorkerStream(\n receiver: WorkerChannelReceiver<TypegenWorkerChannel>,\n options: TypeGenConfig,\n) {\n const start = Date.now()\n const {formatGeneratedCode, generates, schema} = options\n\n const spin = spinner().start(`Loading schema…`)\n\n try {\n await receiver.event.loadedSchema()\n spin.succeed(`Schema loaded from ${formatPath(schema ?? '')}`)\n\n spin.start('Generating schema types…')\n const {expectedFileCount} = await receiver.event.typegenStarted()\n const {schemaTypeDeclarations} = await receiver.event.generatedSchemaTypes()\n const schemaTypesCount = schemaTypeDeclarations.length\n\n spin.text = 'Generating query types…'\n\n let queriesCount = 0\n let evaluatedFiles = 0\n let filesWithErrors = 0\n let queryFilesCount = 0\n let typeNodesGenerated = 0\n let unknownTypeNodesGenerated = 0\n let emptyUnionTypeNodesGenerated = 0\n\n for await (const {errors, queries} of receiver.stream.evaluatedModules()) {\n evaluatedFiles++\n queriesCount += queries.length\n queryFilesCount += queries.length > 0 ? 1 : 0\n filesWithErrors += errors.length > 0 ? 1 : 0\n\n for (const {stats} of queries) {\n typeNodesGenerated += stats.allTypes\n unknownTypeNodesGenerated += stats.unknownTypes\n emptyUnionTypeNodesGenerated += stats.emptyUnions\n }\n\n for (const error of errors) {\n spin.fail(getMessage(error))\n }\n\n if (!spin.isSpinning) {\n spin.start()\n }\n\n spin.text =\n `Generating query types… (${percent(evaluatedFiles / expectedFileCount)})\\n` +\n ` └─ Processed ${count(evaluatedFiles)} of ${count(expectedFileCount, 'files')}. ` +\n `Found ${count(queriesCount, 'queries', 'query')} from ${count(queryFilesCount, 'files')}.`\n }\n\n const result = await receiver.event.typegenComplete()\n const code = `${generatedFileWarning}${result.code}`\n await writeFile(generates, code)\n\n let formattingError = false\n if (formatGeneratedCode) {\n spin.text = `Formatting generated types with prettier…`\n\n try {\n const prettierConfig = await resolvePrettierConfig(generates)\n const formattedCode = await format(code, {\n ...prettierConfig,\n parser: 'typescript' as const,\n })\n await writeFile(generates, formattedCode)\n } catch (err) {\n formattingError = true\n spin.warn(`Failed to format generated types with prettier: ${getMessage(err)}`)\n }\n }\n\n if (filesWithErrors > 0) {\n spin.warn(`Encountered errors in ${count(filesWithErrors, 'files')} while generating types`)\n }\n\n const stats = {\n duration: Date.now() - start,\n emptyUnionTypeNodesGenerated,\n filesWithErrors,\n outputSize: Buffer.byteLength(code),\n queriesCount,\n queryFilesCount,\n schemaTypesCount,\n typeNodesGenerated,\n unknownTypeNodesGenerated,\n unknownTypeNodesRatio:\n typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0,\n }\n\n let successText =\n `Successfully generated types to ${formatPath(generates)} in ${Number(stats.duration).toFixed(0)}ms` +\n `\\n └─ ${count(queriesCount, 'queries', 'query')} and ${count(schemaTypesCount, 'schema types', 'schema type')}` +\n `\\n └─ found queries in ${count(queryFilesCount, 'files', 'file')} after evaluating ${count(evaluatedFiles, 'files', 'file')}`\n\n if (formatGeneratedCode) {\n successText += `\\n └─ ${formattingError ? 'an error occured during formatting' : 'formatted the generated code with prettier'}`\n }\n\n spin.succeed(successText)\n\n return {\n ...stats,\n code,\n }\n } catch (err) {\n spin.fail()\n debug('error generating types', err)\n throw err\n } finally {\n receiver.unsubscribe()\n }\n}\n"],"names":["writeFile","spinner","format","resolveConfig","resolvePrettierConfig","count","debug","formatPath","getMessage","percent","generatedFileWarning","processTypegenWorkerStream","receiver","options","start","Date","now","formatGeneratedCode","generates","schema","spin","event","loadedSchema","succeed","expectedFileCount","typegenStarted","schemaTypeDeclarations","generatedSchemaTypes","schemaTypesCount","length","text","queriesCount","evaluatedFiles","filesWithErrors","queryFilesCount","typeNodesGenerated","unknownTypeNodesGenerated","emptyUnionTypeNodesGenerated","errors","queries","stream","evaluatedModules","stats","allTypes","unknownTypes","emptyUnions","error","fail","isSpinning","result","typegenComplete","code","formattingError","prettierConfig","formattedCode","parser","err","warn","duration","outputSize","Buffer","byteLength","unknownTypeNodesRatio","successText","Number","toFixed","unsubscribe"],"mappings":"AAAA,SAAQA,SAAS,QAAO,mBAAkB;AAE1C,SAAQC,OAAO,QAAO,sBAAqB;AAE3C,SAAQC,MAAM,EAAEC,iBAAiBC,qBAAqB,QAAO,WAAU;AAGvE,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,UAAU,QAAO,yBAAwB;AACjD,SAAQC,UAAU,QAAO,yBAAwB;AACjD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,oBAAoB,QAAO,4BAA2B;AAG9D;;;;;;;;;CASC,GACD,OAAO,eAAeC,2BACpBC,QAAqD,EACrDC,OAAsB;IAEtB,MAAMC,QAAQC,KAAKC,GAAG;IACtB,MAAM,EAACC,mBAAmB,EAAEC,SAAS,EAAEC,MAAM,EAAC,GAAGN;IAEjD,MAAMO,OAAOnB,UAAUa,KAAK,CAAC,CAAC,eAAe,CAAC;IAE9C,IAAI;QACF,MAAMF,SAASS,KAAK,CAACC,YAAY;QACjCF,KAAKG,OAAO,CAAC,CAAC,mBAAmB,EAAEhB,WAAWY,UAAU,KAAK;QAE7DC,KAAKN,KAAK,CAAC;QACX,MAAM,EAACU,iBAAiB,EAAC,GAAG,MAAMZ,SAASS,KAAK,CAACI,cAAc;QAC/D,MAAM,EAACC,sBAAsB,EAAC,GAAG,MAAMd,SAASS,KAAK,CAACM,oBAAoB;QAC1E,MAAMC,mBAAmBF,uBAAuBG,MAAM;QAEtDT,KAAKU,IAAI,GAAG;QAEZ,IAAIC,eAAe;QACnB,IAAIC,iBAAiB;QACrB,IAA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\n\nimport {spinner} from '@sanity/cli-core/ux'\nimport {WorkerChannelReceiver} from '@sanity/worker-channels'\n\nimport {TypeGenConfig} from '../readConfig.js'\nimport {count} from '../utils/count.js'\nimport {debug} from '../utils/debug.js'\nimport {formatPath} from '../utils/formatPath.js'\nimport {getMessage} from '../utils/getMessage.js'\nimport {percent} from '../utils/percent.js'\nimport {defineFormatter} from '../utils/resolveFormatter.js'\nimport {generatedFileWarning} from './generatedFileWarning.js'\nimport {TypegenWorkerChannel} from './types.js'\n\n/**\n * Processes the event stream from a typegen worker thread.\n *\n * Listens to worker channel events, displays progress via CLI spinners,\n * writes the generated types to disk, and optionally formats with prettier.\n *\n * @param receiver - Worker channel receiver for typegen events\n * @param options - Typegen configuration options\n * @returns Generation result containing the generated code and statistics\n */\nexport async function processTypegenWorkerStream(\n receiver: WorkerChannelReceiver<TypegenWorkerChannel>,\n options: TypeGenConfig,\n) {\n const start = Date.now()\n const {formatGeneratedCode, generates, schema} = options\n\n const spin = spinner().start(`Loading schema…`)\n\n try {\n await receiver.event.loadedSchema()\n spin.succeed(`Schema loaded from ${formatPath(schema ?? '')}`)\n\n spin.start('Generating schema types…')\n const {expectedFileCount} = await receiver.event.typegenStarted()\n const {schemaTypeDeclarations} = await receiver.event.generatedSchemaTypes()\n const schemaTypesCount = schemaTypeDeclarations.length\n\n spin.text = 'Generating query types…'\n\n let queriesCount = 0\n let evaluatedFiles = 0\n let filesWithErrors = 0\n let queryFilesCount = 0\n let typeNodesGenerated = 0\n let unknownTypeNodesGenerated = 0\n let emptyUnionTypeNodesGenerated = 0\n\n for await (const {errors, queries} of receiver.stream.evaluatedModules()) {\n evaluatedFiles++\n queriesCount += queries.length\n queryFilesCount += queries.length > 0 ? 1 : 0\n filesWithErrors += errors.length > 0 ? 1 : 0\n\n for (const {stats} of queries) {\n typeNodesGenerated += stats.allTypes\n unknownTypeNodesGenerated += stats.unknownTypes\n emptyUnionTypeNodesGenerated += stats.emptyUnions\n }\n\n for (const error of errors) {\n spin.fail(getMessage(error))\n }\n\n if (!spin.isSpinning) {\n spin.start()\n }\n\n spin.text =\n `Generating query types… (${percent(evaluatedFiles / expectedFileCount)})\\n` +\n ` └─ Processed ${count(evaluatedFiles)} of ${count(expectedFileCount, 'files')}. ` +\n `Found ${count(queriesCount, 'queries', 'query')} from ${count(queryFilesCount, 'files')}.`\n }\n\n const result = await receiver.event.typegenComplete()\n const code = `${generatedFileWarning}${result.code}`\n await writeFile(generates, code)\n\n let formattingError = false\n let formatterName: string | undefined\n if (formatGeneratedCode !== false) {\n const formatter = defineFormatter(formatGeneratedCode)\n if (formatter) {\n formatterName = formatter.name\n try {\n const {format} = await formatter.resolve()\n if (format) {\n spin.text = `Formatting generated types with ${formatter.name}…`\n const formattedCode = await format(generates, code)\n await writeFile(generates, formattedCode)\n }\n } catch (err) {\n formattingError = true\n spin.warn(`Failed to format generated types with ${formatter.name}: ${getMessage(err)}`)\n }\n }\n }\n\n if (filesWithErrors > 0) {\n spin.warn(`Encountered errors in ${count(filesWithErrors, 'files')} while generating types`)\n }\n\n const stats = {\n duration: Date.now() - start,\n emptyUnionTypeNodesGenerated,\n filesWithErrors,\n outputSize: Buffer.byteLength(code),\n queriesCount,\n queryFilesCount,\n schemaTypesCount,\n typeNodesGenerated,\n unknownTypeNodesGenerated,\n unknownTypeNodesRatio:\n typeNodesGenerated > 0 ? unknownTypeNodesGenerated / typeNodesGenerated : 0,\n }\n\n let successText =\n `Successfully generated types to ${formatPath(generates)} in ${Number(stats.duration).toFixed(0)}ms` +\n `\\n └─ ${count(queriesCount, 'queries', 'query')} and ${count(schemaTypesCount, 'schema types', 'schema type')}` +\n `\\n └─ found queries in ${count(queryFilesCount, 'files', 'file')} after evaluating ${count(evaluatedFiles, 'files', 'file')}`\n\n if (formatterName) {\n successText += `\\n └─ ${formattingError ? 'an error occurred during formatting' : `formatted the generated code with ${formatterName}`}`\n }\n\n spin.succeed(successText)\n\n return {\n ...stats,\n code,\n }\n } catch (err) {\n spin.fail()\n debug('error generating types', err)\n throw err\n } finally {\n receiver.unsubscribe()\n }\n}\n"],"names":["writeFile","spinner","count","debug","formatPath","getMessage","percent","defineFormatter","generatedFileWarning","processTypegenWorkerStream","receiver","options","start","Date","now","formatGeneratedCode","generates","schema","spin","event","loadedSchema","succeed","expectedFileCount","typegenStarted","schemaTypeDeclarations","generatedSchemaTypes","schemaTypesCount","length","text","queriesCount","evaluatedFiles","filesWithErrors","queryFilesCount","typeNodesGenerated","unknownTypeNodesGenerated","emptyUnionTypeNodesGenerated","errors","queries","stream","evaluatedModules","stats","allTypes","unknownTypes","emptyUnions","error","fail","isSpinning","result","typegenComplete","code","formattingError","formatterName","formatter","name","format","resolve","formattedCode","err","warn","duration","outputSize","Buffer","byteLength","unknownTypeNodesRatio","successText","Number","toFixed","unsubscribe"],"mappings":"AAAA,SAAQA,SAAS,QAAO,mBAAkB;AAE1C,SAAQC,OAAO,QAAO,sBAAqB;AAI3C,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,KAAK,QAAO,oBAAmB;AACvC,SAAQC,UAAU,QAAO,yBAAwB;AACjD,SAAQC,UAAU,QAAO,yBAAwB;AACjD,SAAQC,OAAO,QAAO,sBAAqB;AAC3C,SAAQC,eAAe,QAAO,+BAA8B;AAC5D,SAAQC,oBAAoB,QAAO,4BAA2B;AAG9D;;;;;;;;;CASC,GACD,OAAO,eAAeC,2BACpBC,QAAqD,EACrDC,OAAsB;IAEtB,MAAMC,QAAQC,KAAKC,GAAG;IACtB,MAAM,EAACC,mBAAmB,EAAEC,SAAS,EAAEC,MAAM,EAAC,GAAGN;IAEjD,MAAMO,OAAOjB,UAAUW,KAAK,CAAC,CAAC,eAAe,CAAC;IAE9C,IAAI;QACF,MAAMF,SAASS,KAAK,CAACC,YAAY;QACjCF,KAAKG,OAAO,CAAC,CAAC,mBAAmB,EAAEjB,WAAWa,UAAU,KAAK;QAE7DC,KAAKN,KAAK,CAAC;QACX,MAAM,EAACU,iBAAiB,EAAC,GAAG,M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,kBAAkB,EAAE9B,MAAM4B,gBAAgB,SAAS,SAAS;QAEjI,IAAIqB,eAAe;YACjBa,eAAe,CAAC,OAAO,EAAEd,kBAAkB,wCAAwC,CAAC,kCAAkC,EAAEC,eAAe,EAAE;QAC3I;QAEAjC,KAAKG,OAAO,CAAC2C;QAEb,OAAO;YACL,GAAGxB,KAAK;YACRS;QACF;IACF,EAAE,OAAOQ,KAAK;QACZvC,KAAK2B,IAAI;QACT1C,MAAM,0BAA0BsD;QAChC,MAAMA;IACR,SAAU;QACR/C,SAASyD,WAAW;IACtB;AACF"}
@@ -4,7 +4,13 @@ import * as z from 'zod';
4
4
  /**
5
5
  * @public
6
6
  */ export const configDefinition = z.object({
7
- formatGeneratedCode: z.boolean().default(true),
7
+ formatGeneratedCode: z.union([
8
+ z.boolean(),
9
+ z.enum([
10
+ 'oxfmt',
11
+ 'prettier'
12
+ ])
13
+ ]).default(true),
8
14
  generates: z.string().default('./sanity.types.ts'),
9
15
  overloadClientMethods: z.boolean().default(true),
10
16
  path: z.string().or(z.array(z.string())).default([
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/readConfig.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\n\nimport json5 from 'json5'\nimport * as z from 'zod'\n\n/**\n * @public\n */\nexport const configDefinition = z.object({\n formatGeneratedCode: z.boolean().default(true),\n generates: z.string().default('./sanity.types.ts'),\n overloadClientMethods: z.boolean().default(true),\n path: z\n .string()\n .or(z.array(z.string()))\n .default([\n './src/**/*.{ts,tsx,js,jsx,mjs,cjs,astro,vue,svelte}',\n './app/**/*.{ts,tsx,js,jsx,mjs,cjs,astro,vue,svelte}',\n './sanity/**/*.{ts,tsx,js,jsx,mjs,cjs}',\n ]),\n schema: z.string().default('./schema.json'),\n})\n\n/** @public */\nexport type TypeGenConfig = z.infer<typeof configDefinition>\n\n/**\n * @deprecated use TypeGenConfig\n * @public\n */\nexport type CodegenConfig = TypeGenConfig\n\n/**\n * Read, parse and process a config file\n * @internal\n */\nexport async function readConfig(path: string): Promise<TypeGenConfig> {\n try {\n const content = await readFile(path, 'utf8')\n const json = json5.parse(content)\n return configDefinition.parseAsync(json)\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new Error(\n `Error in config file\\n ${error.issues.map((err) => err.message).join('\\n')}`,\n {cause: error},\n )\n }\n if (typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT') {\n return configDefinition.parse({})\n }\n\n throw error\n }\n}\n"],"names":["readFile","json5","z","configDefinition","object","formatGeneratedCode","boolean","default","generates","string","overloadClientMethods","path","or","array","schema","readConfig","content","json","parse","parseAsync","error","ZodError","Error","issues","map","err","message","join","cause","code"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC,OAAOC,WAAW,QAAO;AACzB,YAAYC,OAAO,MAAK;AAExB;;CAEC,GACD,OAAO,MAAMC,mBAAmBD,EAAEE,MAAM,CAAC;IACvCC,qBAAqBH,EAAEI,OAAO,GAAGC,OAAO,CAAC;IACzCC,WAAWN,EAAEO,MAAM,GAAGF,OAAO,CAAC;IAC9BG,uBAAuBR,EAAEI,OAAO,GAAGC,OAAO,CAAC;IAC3CI,MAAMT,EACHO,MAAM,GACNG,EAAE,CAACV,EAAEW,KAAK,CAACX,EAAEO,MAAM,KACnBF,OAAO,CAAC;QACP;QACA;QACA;KACD;IACHO,QAAQZ,EAAEO,MAAM,GAAGF,OAAO,CAAC;AAC7B,GAAE;AAWF;;;CAGC,GACD,OAAO,eAAeQ,WAAWJ,IAAY;IAC3C,IAAI;QACF,MAAMK,UAAU,MAAMhB,SAASW,MAAM;QACrC,MAAMM,OAAOhB,MAAMiB,KAAK,CAACF;QACzB,OAAOb,iBAAiBgB,UAAU,CAACF;IACrC,EAAE,OAAOG,OAAO;QACd,IAAIA,iBAAiBlB,EAAEmB,QAAQ,EAAE;YAC/B,MAAM,IAAIC,MACR,CAAC,uBAAuB,EAAEF,MAAMG,MAAM,CAACC,GAAG,CAAC,CAACC,MAAQA,IAAIC,OAAO,EAAEC,IAAI,CAAC,OAAO,EAC7E;gBAACC,OAAOR;YAAK;QAEjB;QACA,IAAI,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMS,IAAI,KAAK,UAAU;YAC7F,OAAO1B,iBAAiBe,KAAK,CAAC,CAAC;QACjC;QAEA,MAAME;IACR;AACF"}
1
+ {"version":3,"sources":["../src/readConfig.ts"],"sourcesContent":["import {readFile} from 'node:fs/promises'\n\nimport json5 from 'json5'\nimport * as z from 'zod'\n\n/**\n * The formatter to use for generated code.\n * - `false` - Do not format generated code.\n * - `true` | `'prettier'` - Format with prettier.\n * - `'oxfmt'` - Format with oxfmt. Throws if oxfmt is not installed.\n * @public\n */\nexport type FormatGeneratedCode = 'oxfmt' | 'prettier' | boolean\n\n/**\n * @public\n */\nexport const configDefinition = z.object({\n formatGeneratedCode: z.union([z.boolean(), z.enum(['oxfmt', 'prettier'])]).default(true),\n generates: z.string().default('./sanity.types.ts'),\n overloadClientMethods: z.boolean().default(true),\n path: z\n .string()\n .or(z.array(z.string()))\n .default([\n './src/**/*.{ts,tsx,js,jsx,mjs,cjs,astro,vue,svelte}',\n './app/**/*.{ts,tsx,js,jsx,mjs,cjs,astro,vue,svelte}',\n './sanity/**/*.{ts,tsx,js,jsx,mjs,cjs}',\n ]),\n schema: z.string().default('./schema.json'),\n})\n\n/** @public */\nexport type TypeGenConfig = z.infer<typeof configDefinition>\n\n/**\n * @deprecated use TypeGenConfig\n * @public\n */\nexport type CodegenConfig = TypeGenConfig\n\n/**\n * Read, parse and process a config file\n * @internal\n */\nexport async function readConfig(path: string): Promise<TypeGenConfig> {\n try {\n const content = await readFile(path, 'utf8')\n const json = json5.parse(content)\n return configDefinition.parseAsync(json)\n } catch (error) {\n if (error instanceof z.ZodError) {\n throw new Error(\n `Error in config file\\n ${error.issues.map((err) => err.message).join('\\n')}`,\n {cause: error},\n )\n }\n if (typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT') {\n return configDefinition.parse({})\n }\n\n throw error\n }\n}\n"],"names":["readFile","json5","z","configDefinition","object","formatGeneratedCode","union","boolean","enum","default","generates","string","overloadClientMethods","path","or","array","schema","readConfig","content","json","parse","parseAsync","error","ZodError","Error","issues","map","err","message","join","cause","code"],"mappings":"AAAA,SAAQA,QAAQ,QAAO,mBAAkB;AAEzC,OAAOC,WAAW,QAAO;AACzB,YAAYC,OAAO,MAAK;AAWxB;;CAEC,GACD,OAAO,MAAMC,mBAAmBD,EAAEE,MAAM,CAAC;IACvCC,qBAAqBH,EAAEI,KAAK,CAAC;QAACJ,EAAEK,OAAO;QAAIL,EAAEM,IAAI,CAAC;YAAC;YAAS;SAAW;KAAE,EAAEC,OAAO,CAAC;IACnFC,WAAWR,EAAES,MAAM,GAAGF,OAAO,CAAC;IAC9BG,uBAAuBV,EAAEK,OAAO,GAAGE,OAAO,CAAC;IAC3CI,MAAMX,EACHS,MAAM,GACNG,EAAE,CAACZ,EAAEa,KAAK,CAACb,EAAES,MAAM,KACnBF,OAAO,CAAC;QACP;QACA;QACA;KACD;IACHO,QAAQd,EAAES,MAAM,GAAGF,OAAO,CAAC;AAC7B,GAAE;AAWF;;;CAGC,GACD,OAAO,eAAeQ,WAAWJ,IAAY;IAC3C,IAAI;QACF,MAAMK,UAAU,MAAMlB,SAASa,MAAM;QACrC,MAAMM,OAAOlB,MAAMmB,KAAK,CAACF;QACzB,OAAOf,iBAAiBkB,UAAU,CAACF;IACrC,EAAE,OAAOG,OAAO;QACd,IAAIA,iBAAiBpB,EAAEqB,QAAQ,EAAE;YAC/B,MAAM,IAAIC,MACR,CAAC,uBAAuB,EAAEF,MAAMG,MAAM,CAACC,GAAG,CAAC,CAACC,MAAQA,IAAIC,OAAO,EAAEC,IAAI,CAAC,OAAO,EAC7E;gBAACC,OAAOR;YAAK;QAEjB;QACA,IAAI,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMS,IAAI,KAAK,UAAU;YAC7F,OAAO5B,iBAAiBiB,KAAK,CAAC,CAAC;QACjC;QAEA,MAAME;IACR;AACF"}
@@ -38,26 +38,6 @@ export class SchemaTypeGenerator {
38
38
  for (const type of schema){
39
39
  this.tsTypes.set(type.name, this.generateTsType(type));
40
40
  }
41
- let hasEffectivelyUnknownTypes = false;
42
- for (const type of schema){
43
- const tsType = this.tsTypes.get(type.name);
44
- if (tsType && SchemaTypeGenerator.isEffectivelyUnknown(tsType)) {
45
- this.identifiers.delete(type.name);
46
- hasEffectivelyUnknownTypes = true;
47
- }
48
- }
49
- if (hasEffectivelyUnknownTypes) {
50
- for (const type of schema){
51
- this.tsTypes.set(type.name, this.generateTsType(type));
52
- }
53
- }
54
- }
55
- static isEffectivelyUnknown(tsType) {
56
- if (t.isTSUnknownKeyword(tsType)) return true;
57
- if (t.isTSTypeReference(tsType) && t.isIdentifier(tsType.typeName) && tsType.typeParameters?.params.length === 1 && t.isTSUnknownKeyword(tsType.typeParameters.params[0])) {
58
- return true;
59
- }
60
- return false;
61
41
  }
62
42
  getType(typeName) {
63
43
  const tsType = this.tsTypes.get(typeName);
@@ -76,10 +56,9 @@ export class SchemaTypeGenerator {
76
56
  }
77
57
  *[Symbol.iterator]() {
78
58
  for (const { name } of this.schema){
79
- const type = this.getType(name);
80
- if (type) yield {
59
+ yield {
81
60
  name,
82
- ...type
61
+ ...this.getType(name)
83
62
  };
84
63
  }
85
64
  }
@@ -135,10 +114,11 @@ export class SchemaTypeGenerator {
135
114
  }
136
115
  generateInlineTsType(typeNode) {
137
116
  const id = this.identifiers.get(typeNode.name);
138
- if (id) return t.tsTypeReference(id);
139
- const resolvedType = this.tsTypes.get(typeNode.name);
140
- if (resolvedType) return t.cloneNode(resolvedType, true);
141
- return t.addComment(t.tsUnknownKeyword(), 'trailing', ` Unable to locate the referenced type "${typeNode.name}" in schema`, true);
117
+ if (!id) {
118
+ // Not found in schema, return unknown type
119
+ return t.addComment(t.tsUnknownKeyword(), 'trailing', ` Unable to locate the referenced type "${typeNode.name}" in schema`, true);
120
+ }
121
+ return t.tsTypeReference(id);
142
122
  }
143
123
  // Helper function used to generate TS types for object type nodes.
144
124
  generateObjectTsType(typeNode) {
@@ -259,11 +239,8 @@ export class SchemaTypeGenerator {
259
239
  // Helper function used to generate TS types for union type nodes.
260
240
  generateUnionTsType(typeNode) {
261
241
  if (typeNode.of.length === 0) return t.tsNeverKeyword();
262
- const generated = typeNode.of.map((node)=>this.generateTsType(node));
263
- const nonUnknown = generated.filter((tsType)=>!t.isTSUnknownKeyword(tsType));
264
- if (nonUnknown.length === 0) return t.tsUnknownKeyword();
265
- if (nonUnknown.length === 1) return nonUnknown[0];
266
- return t.tsUnionType(nonUnknown);
242
+ if (typeNode.of.length === 1) return this.generateTsType(typeNode.of[0]);
243
+ return t.tsUnionType(typeNode.of.map((node)=>this.generateTsType(node)));
267
244
  }
268
245
  }
269
246
  export function walkAndCountQueryTypeNodeStats(typeNode) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/typescript/schemaTypeGenerator.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport {\n type ArrayTypeNode,\n type DocumentSchemaType,\n type InlineTypeNode,\n type ObjectAttribute,\n type ObjectTypeNode,\n type SchemaType,\n type TypeDeclarationSchemaType,\n typeEvaluate,\n type TypeNode,\n type UnionTypeNode,\n} from 'groq-js'\n\nimport {safeParseQuery} from '../safeParseQuery.js'\nimport {ARRAY_OF, INTERNAL_REFERENCE_SYMBOL} from './constants.js'\nimport {\n getFilterArrayUnionType,\n getUniqueIdentifierForName,\n isIdentifierName,\n weakMapMemo,\n} from './helpers.js'\nimport {type ExtractedQuery, type TypeEvaluationStats} from './types.js'\n\nexport class SchemaTypeGenerator {\n public readonly schema: SchemaType\n evaluateQuery = weakMapMemo(\n // eslint-disable-next-line unicorn/consistent-function-scoping\n ({query}: Pick<ExtractedQuery, 'query'>): {stats: TypeEvaluationStats; tsType: t.TSType} => {\n const ast = safeParseQuery(query)\n const typeNode = typeEvaluate(ast, this.schema)\n const tsType = this.generateTsType(typeNode)\n const stats = walkAndCountQueryTypeNodeStats(typeNode)\n return {stats, tsType}\n },\n )\n private arrayOfUsed = false\n\n private identifiers = new Map<string, t.Identifier>()\n\n private tsTypes = new Map<string, t.TSType>()\n\n constructor(schema: SchemaType) {\n this.schema = schema\n\n const uniqueTypeNames = new Set<string>()\n for (const type of schema) {\n if (uniqueTypeNames.has(type.name)) {\n throw new Error(\n `Duplicate type name \"${type.name}\" in schema. Type names must be unique within the same schema.`,\n )\n }\n uniqueTypeNames.add(type.name)\n }\n\n for (const type of schema) {\n const currentIdentifierNames = new Set([...this.identifiers.values()].map((id) => id.name))\n const uniqueIdentifier = getUniqueIdentifierForName(type.name, currentIdentifierNames)\n this.identifiers.set(type.name, uniqueIdentifier)\n }\n\n for (const type of schema) {\n this.tsTypes.set(type.name, this.generateTsType(type))\n }\n\n let hasEffectivelyUnknownTypes = false\n for (const type of schema) {\n const tsType = this.tsTypes.get(type.name)\n if (tsType && SchemaTypeGenerator.isEffectivelyUnknown(tsType)) {\n this.identifiers.delete(type.name)\n hasEffectivelyUnknownTypes = true\n }\n }\n\n if (hasEffectivelyUnknownTypes) {\n for (const type of schema) {\n this.tsTypes.set(type.name, this.generateTsType(type))\n }\n }\n }\n\n private static isEffectivelyUnknown(tsType: t.TSType): boolean {\n if (t.isTSUnknownKeyword(tsType)) return true\n if (\n t.isTSTypeReference(tsType) &&\n t.isIdentifier(tsType.typeName) &&\n tsType.typeParameters?.params.length === 1 &&\n t.isTSUnknownKeyword(tsType.typeParameters.params[0])\n ) {\n return true\n }\n return false\n }\n\n getType(typeName: string): {id: t.Identifier; tsType: t.TSType} | undefined {\n const tsType = this.tsTypes.get(typeName)\n const id = this.identifiers.get(typeName)\n if (tsType && id) return {id, tsType}\n return undefined\n }\n\n hasType(typeName: string): boolean {\n return this.tsTypes.has(typeName)\n }\n\n isArrayOfUsed(): boolean {\n return this.arrayOfUsed\n }\n\n *[Symbol.iterator]() {\n for (const {name} of this.schema) {\n const type = this.getType(name)\n if (type) yield {name, ...type}\n }\n }\n\n typeNames(): string[] {\n return this.schema.map((schemaType) => schemaType.name)\n }\n\n /**\n * Helper function used to generate TS types for arrays of inline types, or arrays of inline types\n * wrapped in the ArrayOf wrapper that adds _key prop\n */\n private generateArrayOfTsType(typeNode: ArrayTypeNode): t.TSTypeReference {\n this.arrayOfUsed = true\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(ARRAY_OF, t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // Helper function used to generate TS types for array type nodes.\n private generateArrayTsType(typeNode: ArrayTypeNode): t.TSTypeReference | t.TSUnionType {\n // if it's an array of a single inline type, wrap it in ArrayOf\n if (typeNode.of.type === 'inline') {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // if it's not an inline object and not a union, wrap in Array\n if (typeNode.of.type !== 'union') {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // if it's not a union type or all of the union type members are non-inlines, wrap type in Array\n if (typeNode.of.of.every((unionTypeNode) => unionTypeNode.type !== 'inline')) {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // all the union types nodes are inline\n if (typeNode.of.of.every((unionMember) => unionMember.type === 'inline')) {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // some of the union types are inlines, while some are not - split and recurse\n const arrayOfNonInline = getFilterArrayUnionType(typeNode, (member) => member.type !== 'inline')\n const arrayOfInline = getFilterArrayUnionType(typeNode, (member) => member.type === 'inline')\n\n return t.tsUnionType([\n this.generateArrayTsType(arrayOfNonInline),\n this.generateArrayTsType(arrayOfInline),\n ])\n }\n\n // Helper function used to generate TS types for document type nodes.\n private generateDocumentTsType(document: DocumentSchemaType): t.TSType {\n const props = Object.entries(document.attributes).map(([key, node]) =>\n this.generateTsObjectProperty(key, node),\n )\n\n return t.tsTypeLiteral(props)\n }\n\n private generateInlineTsType(typeNode: InlineTypeNode): t.TSType {\n const id = this.identifiers.get(typeNode.name)\n if (id) return t.tsTypeReference(id)\n\n const resolvedType = this.tsTypes.get(typeNode.name)\n if (resolvedType) return t.cloneNode(resolvedType, true)\n\n return t.addComment(\n t.tsUnknownKeyword(),\n 'trailing',\n ` Unable to locate the referenced type \"${typeNode.name}\" in schema`,\n true,\n )\n }\n\n // Helper function used to generate TS types for object type nodes.\n private generateObjectTsType(typeNode: ObjectTypeNode): t.TSType {\n const props: t.TSPropertySignature[] = []\n for (const [key, attribute] of Object.entries(typeNode.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n const rest = typeNode.rest\n\n if (rest) {\n switch (rest.type) {\n case 'inline': {\n const resolved = this.generateInlineTsType(rest)\n // if object rest is unknown, we can't generate a type literal for it\n if (t.isTSUnknownKeyword(resolved)) return resolved\n return t.tsIntersectionType([t.tsTypeLiteral(props), resolved])\n }\n case 'object': {\n for (const [key, attribute] of Object.entries(rest.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n break\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n default: {\n // @ts-expect-error This should never happen\n throw new Error(`Type \"${rest.type}\" not found in schema`)\n }\n }\n }\n\n if (typeNode.dereferencesTo) {\n const derefType = Object.assign(\n t.tsPropertySignature(\n INTERNAL_REFERENCE_SYMBOL,\n t.tsTypeAnnotation(t.tsLiteralType(t.stringLiteral(typeNode.dereferencesTo))),\n ),\n {computed: true, optional: true},\n )\n props.push(derefType)\n }\n\n return t.tsTypeLiteral(props)\n }\n\n // Helper function used to generate TS types for object properties.\n private generateTsObjectProperty(key: string, attribute: ObjectAttribute): t.TSPropertySignature {\n const type = this.generateTsType(attribute.value)\n const keyNode = isIdentifierName(key) ? t.identifier(key) : t.stringLiteral(key)\n const propertySignature = t.tsPropertySignature(keyNode, t.tsTypeAnnotation(type))\n propertySignature.optional = attribute.optional\n\n return propertySignature\n }\n\n private generateTsType(\n typeNode: DocumentSchemaType | TypeDeclarationSchemaType | TypeNode,\n ): t.TSType {\n switch (typeNode.type) {\n case 'array': {\n return this.generateArrayTsType(typeNode)\n }\n case 'boolean': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.booleanLiteral(typeNode.value))\n }\n return t.tsBooleanKeyword()\n }\n case 'document': {\n return this.generateDocumentTsType(typeNode)\n }\n case 'inline': {\n return this.generateInlineTsType(typeNode)\n }\n case 'null': {\n return t.tsNullKeyword()\n }\n case 'number': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.numericLiteral(typeNode.value))\n }\n return t.tsNumberKeyword()\n }\n case 'object': {\n return this.generateObjectTsType(typeNode)\n }\n case 'string': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.stringLiteral(typeNode.value))\n }\n return t.tsStringKeyword()\n }\n case 'type': {\n return this.generateTsType(typeNode.value)\n }\n case 'union': {\n return this.generateUnionTsType(typeNode)\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n\n default: {\n throw new Error(\n `Encountered unsupported node type \"${\n // @ts-expect-error This should never happen\n typeNode.type\n }\" while generating schema types`,\n )\n }\n }\n }\n\n // Helper function used to generate TS types for union type nodes.\n private generateUnionTsType(typeNode: UnionTypeNode): t.TSType {\n if (typeNode.of.length === 0) return t.tsNeverKeyword()\n\n const generated = typeNode.of.map((node) => this.generateTsType(node))\n const nonUnknown = generated.filter((tsType) => !t.isTSUnknownKeyword(tsType))\n\n if (nonUnknown.length === 0) return t.tsUnknownKeyword()\n if (nonUnknown.length === 1) return nonUnknown[0]!\n return t.tsUnionType(nonUnknown)\n }\n}\n\nexport function walkAndCountQueryTypeNodeStats(typeNode: TypeNode): TypeEvaluationStats {\n switch (typeNode.type) {\n case 'array': {\n const acc = walkAndCountQueryTypeNodeStats(typeNode.of)\n acc.allTypes += 1 // count the array type itself\n return acc\n }\n case 'object': {\n // if the rest is unknown, we count it as one unknown type\n if (typeNode.rest && typeNode.rest.type === 'unknown') {\n return {allTypes: 2, emptyUnions: 0, unknownTypes: 1} // count the object type itself as well\n }\n\n const restStats = typeNode.rest\n ? walkAndCountQueryTypeNodeStats(typeNode.rest)\n : {allTypes: 0, emptyUnions: 0, unknownTypes: 0}\n\n // count the object type itself\n restStats.allTypes += 1\n\n const attrs = Object.values(typeNode.attributes)\n let acc = restStats\n for (const attribute of attrs) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(\n attribute.value,\n )\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'union': {\n if (typeNode.of.length === 0) {\n return {allTypes: 1, emptyUnions: 1, unknownTypes: 0}\n }\n\n let acc = {allTypes: 1, emptyUnions: 0, unknownTypes: 0} // count the union type itself\n for (const type of typeNode.of) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(type)\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'unknown': {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 1}\n }\n default: {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 0}\n }\n }\n}\n"],"names":["t","typeEvaluate","safeParseQuery","ARRAY_OF","INTERNAL_REFERENCE_SYMBOL","getFilterArrayUnionType","getUniqueIdentifierForName","isIdentifierName","weakMapMemo","SchemaTypeGenerator","schema","evaluateQuery","query","ast","typeNode","tsType","generateTsType","stats","walkAndCountQueryTypeNodeStats","arrayOfUsed","identifiers","Map","tsTypes","uniqueTypeNames","Set","type","has","name","Error","add","currentIdentifierNames","values","map","id","uniqueIdentifier","set","hasEffectivelyUnknownTypes","get","isEffectivelyUnknown","delete","isTSUnknownKeyword","isTSTypeReference","isIdentifier","typeName","typeParameters","params","length","getType","undefined","hasType","isArrayOfUsed","Symbol","iterator","typeNames","schemaType","generateArrayOfTsType","typeNodes","of","tsTypeReference","tsTypeParameterInstantiation","generateArrayTsType","identifier","every","unionTypeNode","unionMember","arrayOfNonInline","member","arrayOfInline","tsUnionType","generateDocumentTsType","document","props","Object","entries","attributes","key","node","generateTsObjectProperty","tsTypeLiteral","generateInlineTsType","resolvedType","cloneNode","addComment","tsUnknownKeyword","generateObjectTsType","attribute","push","rest","resolved","tsIntersectionType","dereferencesTo","derefType","assign","tsPropertySignature","tsTypeAnnotation","tsLiteralType","stringLiteral","computed","optional","value","keyNode","propertySignature","booleanLiteral","tsBooleanKeyword","tsNullKeyword","numericLiteral","tsNumberKeyword","tsStringKeyword","generateUnionTsType","tsNeverKeyword","generated","nonUnknown","filter","acc","allTypes","emptyUnions","unknownTypes","restStats","attrs"],"mappings":"AAAA,YAAYA,OAAO,eAAc;AACjC,SAQEC,YAAY,QAGP,UAAS;AAEhB,SAAQC,cAAc,QAAO,uBAAsB;AACnD,SAAQC,QAAQ,EAAEC,yBAAyB,QAAO,iBAAgB;AAClE,SACEC,uBAAuB,EACvBC,0BAA0B,EAC1BC,gBAAgB,EAChBC,WAAW,QACN,eAAc;AAGrB,OAAO,MAAMC;IACKC,OAAkB;IAClCC,gBAAgBH,YACd,+DAA+D;IAC/D,CAAC,EAACI,KAAK,EAAgC;QACrC,MAAMC,MAAMX,eAAeU;QAC3B,MAAME,WAAWb,aAAaY,KAAK,IAAI,CAACH,MAAM;QAC9C,MAAMK,SAAS,IAAI,CAACC,cAAc,CAACF;QACnC,MAAMG,QAAQC,+BAA+BJ;QAC7C,OAAO;YAACG;YAAOF;QAAM;IACvB,GACD;IACOI,cAAc,MAAK;IAEnBC,cAAc,IAAIC,MAA2B;IAE7CC,UAAU,IAAID,MAAuB;IAE7C,YAAYX,MAAkB,CAAE;QAC9B,IAAI,CAACA,MAAM,GAAGA;QAEd,MAAMa,kBAAkB,IAAIC;QAC5B,KAAK,MAAMC,QAAQf,OAAQ;YACzB,IAA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GAAGlG,+BAA+BO;oBAC7EwF,MAAM;wBACJC,UAAUD,IAAIC,QAAQ,GAAGA;wBACzBC,aAAaF,IAAIE,WAAW,GAAGA;wBAC/BC,cAAcH,IAAIG,YAAY,GAAGA;oBACnC;gBACF;gBACA,OAAOH;YACT;QACA,KAAK;YAAW;gBACd,OAAO;oBAACC,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC;YACtD;QACA;YAAS;gBACP,OAAO;oBAACF,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC;YACtD;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/typescript/schemaTypeGenerator.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport {\n type ArrayTypeNode,\n type DocumentSchemaType,\n type InlineTypeNode,\n type ObjectAttribute,\n type ObjectTypeNode,\n type SchemaType,\n type TypeDeclarationSchemaType,\n typeEvaluate,\n type TypeNode,\n type UnionTypeNode,\n} from 'groq-js'\n\nimport {safeParseQuery} from '../safeParseQuery.js'\nimport {ARRAY_OF, INTERNAL_REFERENCE_SYMBOL} from './constants.js'\nimport {\n getFilterArrayUnionType,\n getUniqueIdentifierForName,\n isIdentifierName,\n weakMapMemo,\n} from './helpers.js'\nimport {type ExtractedQuery, type TypeEvaluationStats} from './types.js'\n\nexport class SchemaTypeGenerator {\n public readonly schema: SchemaType\n evaluateQuery = weakMapMemo(\n // eslint-disable-next-line unicorn/consistent-function-scoping\n ({query}: Pick<ExtractedQuery, 'query'>): {stats: TypeEvaluationStats; tsType: t.TSType} => {\n const ast = safeParseQuery(query)\n const typeNode = typeEvaluate(ast, this.schema)\n const tsType = this.generateTsType(typeNode)\n const stats = walkAndCountQueryTypeNodeStats(typeNode)\n return {stats, tsType}\n },\n )\n private arrayOfUsed = false\n\n private identifiers = new Map<string, t.Identifier>()\n\n private tsTypes = new Map<string, t.TSType>()\n\n constructor(schema: SchemaType) {\n this.schema = schema\n\n const uniqueTypeNames = new Set<string>()\n for (const type of schema) {\n if (uniqueTypeNames.has(type.name)) {\n throw new Error(\n `Duplicate type name \"${type.name}\" in schema. Type names must be unique within the same schema.`,\n )\n }\n uniqueTypeNames.add(type.name)\n }\n\n for (const type of schema) {\n const currentIdentifierNames = new Set([...this.identifiers.values()].map((id) => id.name))\n const uniqueIdentifier = getUniqueIdentifierForName(type.name, currentIdentifierNames)\n this.identifiers.set(type.name, uniqueIdentifier)\n }\n\n for (const type of schema) {\n this.tsTypes.set(type.name, this.generateTsType(type))\n }\n }\n\n getType(typeName: string): {id: t.Identifier; tsType: t.TSType} | undefined {\n const tsType = this.tsTypes.get(typeName)\n const id = this.identifiers.get(typeName)\n if (tsType && id) return {id, tsType}\n return undefined\n }\n\n hasType(typeName: string): boolean {\n return this.tsTypes.has(typeName)\n }\n\n isArrayOfUsed(): boolean {\n return this.arrayOfUsed\n }\n\n *[Symbol.iterator]() {\n for (const {name} of this.schema) {\n yield {name, ...this.getType(name)!}\n }\n }\n\n typeNames(): string[] {\n return this.schema.map((schemaType) => schemaType.name)\n }\n\n /**\n * Helper function used to generate TS types for arrays of inline types, or arrays of inline types\n * wrapped in the ArrayOf wrapper that adds _key prop\n */\n private generateArrayOfTsType(typeNode: ArrayTypeNode): t.TSTypeReference {\n this.arrayOfUsed = true\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(ARRAY_OF, t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // Helper function used to generate TS types for array type nodes.\n private generateArrayTsType(typeNode: ArrayTypeNode): t.TSTypeReference | t.TSUnionType {\n // if it's an array of a single inline type, wrap it in ArrayOf\n if (typeNode.of.type === 'inline') {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // if it's not an inline object and not a union, wrap in Array\n if (typeNode.of.type !== 'union') {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // if it's not a union type or all of the union type members are non-inlines, wrap type in Array\n if (typeNode.of.of.every((unionTypeNode) => unionTypeNode.type !== 'inline')) {\n const typeNodes = this.generateTsType(typeNode.of)\n return t.tsTypeReference(t.identifier('Array'), t.tsTypeParameterInstantiation([typeNodes]))\n }\n\n // all the union types nodes are inline\n if (typeNode.of.of.every((unionMember) => unionMember.type === 'inline')) {\n return this.generateArrayOfTsType(typeNode)\n }\n\n // some of the union types are inlines, while some are not - split and recurse\n const arrayOfNonInline = getFilterArrayUnionType(typeNode, (member) => member.type !== 'inline')\n const arrayOfInline = getFilterArrayUnionType(typeNode, (member) => member.type === 'inline')\n\n return t.tsUnionType([\n this.generateArrayTsType(arrayOfNonInline),\n this.generateArrayTsType(arrayOfInline),\n ])\n }\n\n // Helper function used to generate TS types for document type nodes.\n private generateDocumentTsType(document: DocumentSchemaType): t.TSType {\n const props = Object.entries(document.attributes).map(([key, node]) =>\n this.generateTsObjectProperty(key, node),\n )\n\n return t.tsTypeLiteral(props)\n }\n\n private generateInlineTsType(typeNode: InlineTypeNode): t.TSType {\n const id = this.identifiers.get(typeNode.name)\n if (!id) {\n // Not found in schema, return unknown type\n return t.addComment(\n t.tsUnknownKeyword(),\n 'trailing',\n ` Unable to locate the referenced type \"${typeNode.name}\" in schema`,\n true,\n )\n }\n\n return t.tsTypeReference(id)\n }\n\n // Helper function used to generate TS types for object type nodes.\n private generateObjectTsType(typeNode: ObjectTypeNode): t.TSType {\n const props: t.TSPropertySignature[] = []\n for (const [key, attribute] of Object.entries(typeNode.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n const rest = typeNode.rest\n\n if (rest) {\n switch (rest.type) {\n case 'inline': {\n const resolved = this.generateInlineTsType(rest)\n // if object rest is unknown, we can't generate a type literal for it\n if (t.isTSUnknownKeyword(resolved)) return resolved\n return t.tsIntersectionType([t.tsTypeLiteral(props), resolved])\n }\n case 'object': {\n for (const [key, attribute] of Object.entries(rest.attributes)) {\n props.push(this.generateTsObjectProperty(key, attribute))\n }\n break\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n default: {\n // @ts-expect-error This should never happen\n throw new Error(`Type \"${rest.type}\" not found in schema`)\n }\n }\n }\n\n if (typeNode.dereferencesTo) {\n const derefType = Object.assign(\n t.tsPropertySignature(\n INTERNAL_REFERENCE_SYMBOL,\n t.tsTypeAnnotation(t.tsLiteralType(t.stringLiteral(typeNode.dereferencesTo))),\n ),\n {computed: true, optional: true},\n )\n props.push(derefType)\n }\n\n return t.tsTypeLiteral(props)\n }\n\n // Helper function used to generate TS types for object properties.\n private generateTsObjectProperty(key: string, attribute: ObjectAttribute): t.TSPropertySignature {\n const type = this.generateTsType(attribute.value)\n const keyNode = isIdentifierName(key) ? t.identifier(key) : t.stringLiteral(key)\n const propertySignature = t.tsPropertySignature(keyNode, t.tsTypeAnnotation(type))\n propertySignature.optional = attribute.optional\n\n return propertySignature\n }\n\n private generateTsType(\n typeNode: DocumentSchemaType | TypeDeclarationSchemaType | TypeNode,\n ): t.TSType {\n switch (typeNode.type) {\n case 'array': {\n return this.generateArrayTsType(typeNode)\n }\n case 'boolean': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.booleanLiteral(typeNode.value))\n }\n return t.tsBooleanKeyword()\n }\n case 'document': {\n return this.generateDocumentTsType(typeNode)\n }\n case 'inline': {\n return this.generateInlineTsType(typeNode)\n }\n case 'null': {\n return t.tsNullKeyword()\n }\n case 'number': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.numericLiteral(typeNode.value))\n }\n return t.tsNumberKeyword()\n }\n case 'object': {\n return this.generateObjectTsType(typeNode)\n }\n case 'string': {\n if (typeNode.value !== undefined) {\n return t.tsLiteralType(t.stringLiteral(typeNode.value))\n }\n return t.tsStringKeyword()\n }\n case 'type': {\n return this.generateTsType(typeNode.value)\n }\n case 'union': {\n return this.generateUnionTsType(typeNode)\n }\n case 'unknown': {\n return t.tsUnknownKeyword()\n }\n\n default: {\n throw new Error(\n `Encountered unsupported node type \"${\n // @ts-expect-error This should never happen\n typeNode.type\n }\" while generating schema types`,\n )\n }\n }\n }\n\n // Helper function used to generate TS types for union type nodes.\n private generateUnionTsType(typeNode: UnionTypeNode): t.TSType {\n if (typeNode.of.length === 0) return t.tsNeverKeyword()\n if (typeNode.of.length === 1) return this.generateTsType(typeNode.of[0]!)\n return t.tsUnionType(typeNode.of.map((node) => this.generateTsType(node)))\n }\n}\n\nexport function walkAndCountQueryTypeNodeStats(typeNode: TypeNode): TypeEvaluationStats {\n switch (typeNode.type) {\n case 'array': {\n const acc = walkAndCountQueryTypeNodeStats(typeNode.of)\n acc.allTypes += 1 // count the array type itself\n return acc\n }\n case 'object': {\n // if the rest is unknown, we count it as one unknown type\n if (typeNode.rest && typeNode.rest.type === 'unknown') {\n return {allTypes: 2, emptyUnions: 0, unknownTypes: 1} // count the object type itself as well\n }\n\n const restStats = typeNode.rest\n ? walkAndCountQueryTypeNodeStats(typeNode.rest)\n : {allTypes: 0, emptyUnions: 0, unknownTypes: 0}\n\n // count the object type itself\n restStats.allTypes += 1\n\n const attrs = Object.values(typeNode.attributes)\n let acc = restStats\n for (const attribute of attrs) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(\n attribute.value,\n )\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'union': {\n if (typeNode.of.length === 0) {\n return {allTypes: 1, emptyUnions: 1, unknownTypes: 0}\n }\n\n let acc = {allTypes: 1, emptyUnions: 0, unknownTypes: 0} // count the union type itself\n for (const type of typeNode.of) {\n const {allTypes, emptyUnions, unknownTypes} = walkAndCountQueryTypeNodeStats(type)\n acc = {\n allTypes: acc.allTypes + allTypes,\n emptyUnions: acc.emptyUnions + emptyUnions,\n unknownTypes: acc.unknownTypes + unknownTypes,\n }\n }\n return acc\n }\n case 'unknown': {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 1}\n }\n default: {\n return {allTypes: 1, emptyUnions: 0, unknownTypes: 0}\n }\n }\n}\n"],"names":["t","typeEvaluate","safeParseQuery","ARRAY_OF","INTERNAL_REFERENCE_SYMBOL","getFilterArrayUnionType","getUniqueIdentifierForName","isIdentifierName","weakMapMemo","SchemaTypeGenerator","schema","evaluateQuery","query","ast","typeNode","tsType","generateTsType","stats","walkAndCountQueryTypeNodeStats","arrayOfUsed","identifiers","Map","tsTypes","uniqueTypeNames","Set","type","has","name","Error","add","currentIdentifierNames","values","map","id","uniqueIdentifier","set","getType","typeName","get","undefined","hasType","isArrayOfUsed","Symbol","iterator","typeNames","schemaType","generateArrayOfTsType","typeNodes","of","tsTypeReference","tsTypeParameterInstantiation","generateArrayTsType","identifier","every","unionTypeNode","unionMember","arrayOfNonInline","member","arrayOfInline","tsUnionType","generateDocumentTsType","document","props","Object","entries","attributes","key","node","generateTsObjectProperty","tsTypeLiteral","generateInlineTsType","addComment","tsUnknownKeyword","generateObjectTsType","attribute","push","rest","resolved","isTSUnknownKeyword","tsIntersectionType","dereferencesTo","derefType","assign","tsPropertySignature","tsTypeAnnotation","tsLiteralType","stringLiteral","computed","optional","value","keyNode","propertySignature","booleanLiteral","tsBooleanKeyword","tsNullKeyword","numericLiteral","tsNumberKeyword","tsStringKeyword","generateUnionTsType","length","tsNeverKeyword","acc","allTypes","emptyUnions","unknownTypes","restStats","attrs"],"mappings":"AAAA,YAAYA,OAAO,eAAc;AACjC,SAQEC,YAAY,QAGP,UAAS;AAEhB,SAAQC,cAAc,QAAO,uBAAsB;AACnD,SAAQC,QAAQ,EAAEC,yBAAyB,QAAO,iBAAgB;AAClE,SACEC,uBAAuB,EACvBC,0BAA0B,EAC1BC,gBAAgB,EAChBC,WAAW,QACN,eAAc;AAGrB,OAAO,MAAMC;IACKC,OAAkB;IAClCC,gBAAgBH,YACd,+DAA+D;IAC/D,CAAC,EAACI,KAAK,EAAgC;QACrC,MAAMC,MAAMX,eAAeU;QAC3B,MAAME,WAAWb,aAAaY,KAAK,IAAI,CAACH,MAAM;QAC9C,MAAMK,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,GAAGtF,+BAC5CwD,UAAUe,KAAK;oBAEjBY,MAAM;wBACJC,UAAUD,IAAIC,QAAQ,GAAGA;wBACzBC,aAAaF,IAAIE,WAAW,GAAGA;wBAC/BC,cAAcH,IAAIG,YAAY,GAAGA;oBACnC;gBACF;gBACA,OAAOH;YACT;QACA,KAAK;YAAS;gBACZ,IAAIvF,SAASkC,EAAE,CAACmD,MAAM,KAAK,GAAG;oBAC5B,OAAO;wBAACG,UAAU;wBAAGC,aAAa;wBAAGC,cAAc;oBAAC;gBACtD;gBAEA,IAAIH,MAAM;oBAACC,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC,EAAE,8BAA8B;;gBACvF,KAAK,MAAM/E,QAAQX,SAASkC,EAAE,CAAE;oBAC9B,MAAM,EAACsD,QAAQ,EAAEC,WAAW,EAAEC,YAAY,EAAC,GAAGtF,+BAA+BO;oBAC7E4E,MAAM;wBACJC,UAAUD,IAAIC,QAAQ,GAAGA;wBACzBC,aAAaF,IAAIE,WAAW,GAAGA;wBAC/BC,cAAcH,IAAIG,YAAY,GAAGA;oBACnC;gBACF;gBACA,OAAOH;YACT;QACA,KAAK;YAAW;gBACd,OAAO;oBAACC,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC;YACtD;QACA;YAAS;gBACP,OAAO;oBAACF,UAAU;oBAAGC,aAAa;oBAAGC,cAAc;gBAAC;YACtD;IACF;AACF"}
@@ -0,0 +1,99 @@
1
+ import { debug } from './debug.js';
2
+ // Wrapper to avoid lint rule against dynamic imports
3
+ // eslint-disable-next-line no-restricted-syntax
4
+ const tryImport = (specifier)=>import(specifier);
5
+ /**
6
+ * Synchronously defines a formatter based on the `formatGeneratedCode` configuration.
7
+ * The `name` is available immediately; call `resolve()` to load the formatter (which may throw).
8
+ *
9
+ * Returns `undefined` if `formatGeneratedCode` is `false`.
10
+ *
11
+ * @param formatGeneratedCode - The formatter mode to resolve
12
+ */ export function defineFormatter(formatGeneratedCode) {
13
+ if (formatGeneratedCode === false) {
14
+ return undefined;
15
+ }
16
+ if (formatGeneratedCode === 'oxfmt') {
17
+ return {
18
+ name: 'oxfmt',
19
+ resolve: resolveOxfmt
20
+ };
21
+ }
22
+ // true or 'prettier' → use prettier
23
+ return {
24
+ name: 'prettier',
25
+ resolve: resolvePrettier
26
+ };
27
+ }
28
+ /**
29
+ * Resolves a code formatter based on the `formatGeneratedCode` configuration.
30
+ *
31
+ * Resolution:
32
+ * - `false` → no formatter
33
+ * - `true` | `'prettier'` → prettier (always available as a dependency)
34
+ * - `'oxfmt'` → oxfmt, throws if not installed
35
+ *
36
+ * @param formatGeneratedCode - The formatter mode to resolve
37
+ */ export async function resolveFormatter(formatGeneratedCode) {
38
+ const defined = defineFormatter(formatGeneratedCode);
39
+ if (!defined) {
40
+ return {
41
+ format: undefined,
42
+ name: undefined
43
+ };
44
+ }
45
+ return defined.resolve();
46
+ }
47
+ async function resolveOxfmt() {
48
+ try {
49
+ const oxfmt = await tryImport('oxfmt');
50
+ const format = oxfmt.format ?? oxfmt.default?.format;
51
+ if (typeof format !== 'function') {
52
+ throw new TypeError('oxfmt module does not export a format function');
53
+ }
54
+ return {
55
+ format: async (filename, text)=>{
56
+ const result = await format(filename, text);
57
+ if (result.errors && result.errors.length > 0) {
58
+ throw new Error('Failed to format generated code with oxfmt', {
59
+ cause: result.errors
60
+ });
61
+ }
62
+ return result.code;
63
+ },
64
+ name: 'oxfmt'
65
+ };
66
+ } catch (err) {
67
+ throw new Error('formatGeneratedCode is set to "oxfmt" but oxfmt could not be loaded. ' + 'Make sure oxfmt is installed as a dependency in your project. ' + 'See: https://oxc.rs/docs/guide/usage/formatter/quickstart.html', {
68
+ cause: err
69
+ });
70
+ }
71
+ }
72
+ async function resolvePrettier() {
73
+ try {
74
+ const prettier = await tryImport('prettier');
75
+ const format = prettier.format ?? prettier.default?.format;
76
+ const resolveConfig = prettier.resolveConfig ?? prettier.default?.resolveConfig;
77
+ if (typeof format !== 'function') {
78
+ throw new TypeError('prettier module does not export a format function');
79
+ }
80
+ return {
81
+ format: async (filename, text)=>{
82
+ const prettierConfig = typeof resolveConfig === 'function' ? await resolveConfig(filename) : undefined;
83
+ return format(text, {
84
+ ...prettierConfig,
85
+ parser: 'typescript'
86
+ });
87
+ },
88
+ name: 'prettier'
89
+ };
90
+ } catch (err) {
91
+ debug('prettier not available: %s', err instanceof Error ? err.message : err);
92
+ return {
93
+ format: undefined,
94
+ name: undefined
95
+ };
96
+ }
97
+ }
98
+
99
+ //# sourceMappingURL=resolveFormatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/resolveFormatter.ts"],"sourcesContent":["import {type FormatGeneratedCode} from '../readConfig.js'\nimport {debug} from './debug.js'\n\n/**\n * A resolved formatter function that takes a filename and text, and returns formatted text.\n */\nexport type FormatterFn = (filename: string, text: string) => Promise<string>\n\n/**\n * The result of resolving a formatter.\n */\nexport interface ResolvedFormatter {\n /** The formatter function, or undefined if no formatter was found */\n format: FormatterFn | undefined\n /** The name of the resolved formatter, for display purposes */\n name: string | undefined\n}\n\n/**\n * A defined formatter with a known name and an async resolve step.\n */\nexport interface DefinedFormatter {\n /** The name of the formatter, available synchronously */\n name: string\n /** Resolves the formatter — may throw if the formatter cannot be loaded */\n resolve: () => Promise<ResolvedFormatter>\n}\n\n// Wrapper to avoid lint rule against dynamic imports\n// eslint-disable-next-line no-restricted-syntax\nconst tryImport = (specifier: string) => import(specifier)\n\n/**\n * Synchronously defines a formatter based on the `formatGeneratedCode` configuration.\n * The `name` is available immediately; call `resolve()` to load the formatter (which may throw).\n *\n * Returns `undefined` if `formatGeneratedCode` is `false`.\n *\n * @param formatGeneratedCode - The formatter mode to resolve\n */\nexport function defineFormatter(\n formatGeneratedCode: FormatGeneratedCode,\n): DefinedFormatter | undefined {\n if (formatGeneratedCode === false) {\n return undefined\n }\n\n if (formatGeneratedCode === 'oxfmt') {\n return {name: 'oxfmt', resolve: resolveOxfmt}\n }\n\n // true or 'prettier' → use prettier\n return {name: 'prettier', resolve: resolvePrettier}\n}\n\n/**\n * Resolves a code formatter based on the `formatGeneratedCode` configuration.\n *\n * Resolution:\n * - `false` → no formatter\n * - `true` | `'prettier'` → prettier (always available as a dependency)\n * - `'oxfmt'` → oxfmt, throws if not installed\n *\n * @param formatGeneratedCode - The formatter mode to resolve\n */\nexport async function resolveFormatter(\n formatGeneratedCode: FormatGeneratedCode,\n): Promise<ResolvedFormatter> {\n const defined = defineFormatter(formatGeneratedCode)\n if (!defined) {\n return {format: undefined, name: undefined}\n }\n return defined.resolve()\n}\n\nasync function resolveOxfmt(): Promise<ResolvedFormatter> {\n try {\n const oxfmt = await tryImport('oxfmt')\n const format = oxfmt.format ?? oxfmt.default?.format\n if (typeof format !== 'function') {\n throw new TypeError('oxfmt module does not export a format function')\n }\n return {\n format: async (filename: string, text: string) => {\n const result = await format(filename, text)\n if (result.errors && result.errors.length > 0) {\n throw new Error('Failed to format generated code with oxfmt', {cause: result.errors})\n }\n return result.code\n },\n name: 'oxfmt',\n }\n } catch (err) {\n throw new Error(\n 'formatGeneratedCode is set to \"oxfmt\" but oxfmt could not be loaded. ' +\n 'Make sure oxfmt is installed as a dependency in your project. ' +\n 'See: https://oxc.rs/docs/guide/usage/formatter/quickstart.html',\n {cause: err},\n )\n }\n}\n\nasync function resolvePrettier(): Promise<ResolvedFormatter> {\n try {\n const prettier = await tryImport('prettier')\n const format = prettier.format ?? prettier.default?.format\n const resolveConfig = prettier.resolveConfig ?? prettier.default?.resolveConfig\n if (typeof format !== 'function') {\n throw new TypeError('prettier module does not export a format function')\n }\n return {\n format: async (filename: string, text: string) => {\n const prettierConfig =\n typeof resolveConfig === 'function' ? await resolveConfig(filename) : undefined\n return format(text, {\n ...prettierConfig,\n parser: 'typescript' as const,\n })\n },\n name: 'prettier',\n }\n } catch (err) {\n debug('prettier not available: %s', err instanceof Error ? err.message : err)\n return {format: undefined, name: undefined}\n }\n}\n"],"names":["debug","tryImport","specifier","defineFormatter","formatGeneratedCode","undefined","name","resolve","resolveOxfmt","resolvePrettier","resolveFormatter","defined","format","oxfmt","default","TypeError","filename","text","result","errors","length","Error","cause","code","err","prettier","resolveConfig","prettierConfig","parser","message"],"mappings":"AACA,SAAQA,KAAK,QAAO,aAAY;AA2BhC,qDAAqD;AACrD,gDAAgD;AAChD,MAAMC,YAAY,CAACC,YAAsB,MAAM,CAACA;AAEhD;;;;;;;CAOC,GACD,OAAO,SAASC,gBACdC,mBAAwC;IAExC,IAAIA,wBAAwB,OAAO;QACjC,OAAOC;IACT;IAEA,IAAID,wBAAwB,SAAS;QACnC,OAAO;YAACE,MAAM;YAASC,SAASC;QAAY;IAC9C;IAEA,oCAAoC;IACpC,OAAO;QAACF,MAAM;QAAYC,SAASE;IAAe;AACpD;AAEA;;;;;;;;;CASC,GACD,OAAO,eAAeC,iBACpBN,mBAAwC;IAExC,MAAMO,UAAUR,gBAAgBC;IAChC,IAAI,CAACO,SAAS;QACZ,OAAO;YAACC,QAAQP;YAAWC,MAAMD;QAAS;IAC5C;IACA,OAAOM,QAAQJ,OAAO;AACxB;AAEA,eAAeC;IACb,IAAI;QACF,MAAMK,QAAQ,MAAMZ,UAAU;QAC9B,MAAMW,SAASC,MAAMD,MAAM,IAAIC,MAAMC,OAAO,EAAEF;QAC9C,IAAI,OAAOA,WAAW,YAAY;YAChC,MAAM,IAAIG,UAAU;QACtB;QACA,OAAO;YACLH,QAAQ,OAAOI,UAAkBC;gBAC/B,MAAMC,SAAS,MAAMN,OAAOI,UAAUC;gBACtC,IAAIC,OAAOC,MAAM,IAAID,OAAOC,MAAM,CAACC,MAAM,GAAG,GAAG;oBAC7C,MAAM,IAAIC,MAAM,8CAA8C;wBAACC,OAAOJ,OAAOC,MAAM;oBAAA;gBACrF;gBACA,OAAOD,OAAOK,IAAI;YACpB;YACAjB,MAAM;QACR;IACF,EAAE,OAAOkB,KAAK;QACZ,MAAM,IAAIH,MACR,0EACE,mEACA,kEACF;YAACC,OAAOE;QAAG;IAEf;AACF;AAEA,eAAef;IACb,IAAI;QACF,MAAMgB,WAAW,MAAMxB,UAAU;QACjC,MAAMW,SAASa,SAASb,MAAM,IAAIa,SAASX,OAAO,EAAEF;QACpD,MAAMc,gBAAgBD,SAASC,aAAa,IAAID,SAASX,OAAO,EAAEY;QAClE,IAAI,OAAOd,WAAW,YAAY;YAChC,MAAM,IAAIG,UAAU;QACtB;QACA,OAAO;YACLH,QAAQ,OAAOI,UAAkBC;gBAC/B,MAAMU,iBACJ,OAAOD,kBAAkB,aAAa,MAAMA,cAAcV,YAAYX;gBACxE,OAAOO,OAAOK,MAAM;oBAClB,GAAGU,cAAc;oBACjBC,QAAQ;gBACV;YACF;YACAtB,MAAM;QACR;IACF,EAAE,OAAOkB,KAAK;QACZxB,MAAM,8BAA8BwB,eAAeH,QAAQG,IAAIK,OAAO,GAAGL;QACzE,OAAO;YAACZ,QAAQP;YAAWC,MAAMD;QAAS;IAC5C;AACF"}
@@ -3,7 +3,7 @@
3
3
  "typegen:generate": {
4
4
  "aliases": [],
5
5
  "args": {},
6
- "description": "Sanity TypeGen\n\n\u001b[1mConfiguration:\u001b[22m\nThis command can utilize configuration settings defined in a `sanity-typegen.json` file. These settings include:\n\n- \"path\": Specifies a glob pattern to locate your TypeScript or JavaScript files.\n Default: \"./src/**/*.{ts,tsx,js,jsx}\"\n\n- \"schema\": Defines the path to your Sanity schema file. This file should be generated using the `sanity schema extract` command.\n Default: \"schema.json\"\n\n- \"generates\": Indicates the path where the generated TypeScript type definitions will be saved.\n Default: \"./sanity.types.ts\"\n\nThe default configuration values listed above are used if not overridden in your `sanity-typegen.json` configuration file. To customize the behavior of the type generation, adjust these properties in the configuration file according to your project's needs.\n\n\u001b[1mNote:\u001b[22m\n- The `sanity schema extract` command is a prerequisite for extracting your Sanity Studio schema into a `schema.json` file, which is then used by the `sanity typegen generate` command to generate type definitions.",
6
+ "description": "Sanity TypeGen\n\nConfiguration:\nThis command can utilize configuration settings defined in a `sanity-typegen.json` file. These settings include:\n\n- \"path\": Specifies a glob pattern to locate your TypeScript or JavaScript files.\n Default: \"./src/**/*.{ts,tsx,js,jsx}\"\n\n- \"schema\": Defines the path to your Sanity schema file. This file should be generated using the `sanity schema extract` command.\n Default: \"schema.json\"\n\n- \"generates\": Indicates the path where the generated TypeScript type definitions will be saved.\n Default: \"./sanity.types.ts\"\n\nThe default configuration values listed above are used if not overridden in your `sanity-typegen.json` configuration file. To customize the behavior of the type generation, adjust these properties in the configuration file according to your project's needs.\n\nNote:\n- The `sanity schema extract` command is a prerequisite for extracting your Sanity Studio schema into a `schema.json` file, which is then used by the `sanity typegen generate` command to generate type definitions.",
7
7
  "examples": [
8
8
  {
9
9
  "command": "<%= config.bin %> <%= command.id %>",
@@ -41,5 +41,5 @@
41
41
  ]
42
42
  }
43
43
  },
44
- "version": "6.0.3-canary.0"
44
+ "version": "6.1.0"
45
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/codegen",
3
- "version": "6.0.3-canary.0",
3
+ "version": "6.1.0",
4
4
  "description": "Codegen toolkit for Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -50,10 +50,10 @@
50
50
  "chokidar": "^3.6.0",
51
51
  "debug": "^4.4.3",
52
52
  "globby": "^11.1.0",
53
- "groq": "^5.18.0",
54
- "groq-js": "^1.29.0",
53
+ "groq": "^5.23.0",
54
+ "groq-js": "^1.30.1",
55
55
  "json5": "^2.2.3",
56
- "lodash-es": "^4.17.23",
56
+ "lodash-es": "^4.18.1",
57
57
  "prettier": "^3.8.1",
58
58
  "reselect": "^5.1.1",
59
59
  "tsconfig-paths": "^4.2.0",
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@eslint/compat": "^2.0.3",
64
- "@sanity/cli-core": "^1.3.0",
65
- "@sanity/cli-test": "^0.3.0",
64
+ "@sanity/cli-core": "^1.3.1",
65
+ "@sanity/cli-test": "^0.3.1",
66
66
  "@sanity/eslint-config-cli": "^1.1.0",
67
- "@sanity/pkg-utils": "^10.4.13",
67
+ "@sanity/pkg-utils": "^10.4.18",
68
68
  "@sanity/telemetry": "^0.9.0",
69
69
  "@swc/cli": "^0.7.9",
70
70
  "@swc/core": "^1.15.8",
@@ -72,24 +72,31 @@
72
72
  "@types/babel__generator": "^7.27.0",
73
73
  "@types/babel__register": "^7.17.3",
74
74
  "@types/babel__traverse": "^7.28.0",
75
- "@types/debug": "^4.1.12",
75
+ "@types/debug": "^4.1.13",
76
76
  "@types/lodash-es": "^4.17.12",
77
- "@types/node": "^20.19.35",
78
- "@vitest/coverage-istanbul": "^4.0.18",
77
+ "@types/node": "^20.19.39",
78
+ "@vitest/coverage-istanbul": "^4.1.5",
79
79
  "eslint": "^9.39.4",
80
80
  "husky": "^9.1.7",
81
- "lint-staged": "^16.3.1",
81
+ "lint-staged": "^16.4.0",
82
82
  "oclif": "^4.22.85",
83
+ "oxfmt": "^0.47.0",
83
84
  "prettier-plugin-packagejson": "^3.0.2",
84
85
  "rimraf": "^5.0.10",
85
- "tinyglobby": "^0.2.15",
86
+ "tinyglobby": "^0.2.16",
86
87
  "typescript": "^5.9.3",
87
- "vitest": "^4.0.18"
88
+ "vitest": "^4.1.5"
88
89
  },
89
90
  "peerDependencies": {
90
91
  "@oclif/core": "^4.8.0",
91
92
  "@sanity/cli-core": "^1",
92
- "@sanity/telemetry": "^0.9.0"
93
+ "@sanity/telemetry": "^0.9.0",
94
+ "oxfmt": "*"
95
+ },
96
+ "peerDependenciesMeta": {
97
+ "oxfmt": {
98
+ "optional": true
99
+ }
93
100
  },
94
101
  "engines": {
95
102
  "node": ">=20.19 <22 || >=22.12"