@sanity/cli 6.0.0-alpha.19 → 6.0.0-alpha.21

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 (229) hide show
  1. package/README.md +713 -533
  2. package/dist/actions/auth/authServer.js +13 -11
  3. package/dist/actions/auth/authServer.js.map +1 -1
  4. package/dist/actions/auth/login/getProvider.js +43 -39
  5. package/dist/actions/auth/login/getProvider.js.map +1 -1
  6. package/dist/actions/auth/login/getSSOProvider.js +25 -19
  7. package/dist/actions/auth/login/getSSOProvider.js.map +1 -1
  8. package/dist/actions/auth/login/login.js +12 -33
  9. package/dist/actions/auth/login/login.js.map +1 -1
  10. package/dist/actions/auth/types.js.map +1 -1
  11. package/dist/actions/codemods/reactIconsV3.js +2 -2
  12. package/dist/actions/codemods/reactIconsV3.js.map +1 -1
  13. package/dist/actions/debug/formatters.js +22 -0
  14. package/dist/actions/debug/formatters.js.map +1 -0
  15. package/dist/actions/dev/getDashboardAppUrl.js +3 -3
  16. package/dist/actions/dev/getDashboardAppUrl.js.map +1 -1
  17. package/dist/actions/documents/validateDocuments.worker.js +2 -2
  18. package/dist/actions/documents/validateDocuments.worker.js.map +1 -1
  19. package/dist/actions/documents/validation/reporters/prettyReporter/formatDocumentValidation.js +1 -1
  20. package/dist/actions/documents/validation/reporters/prettyReporter/formatDocumentValidation.js.map +1 -1
  21. package/dist/actions/documents/validation/reporters/prettyReporter/tree.js +108 -0
  22. package/dist/actions/documents/validation/reporters/prettyReporter/tree.js.map +1 -0
  23. package/dist/actions/graphql/SchemaError.js +4 -26
  24. package/dist/actions/graphql/SchemaError.js.map +1 -1
  25. package/dist/actions/graphql/extractFromSanitySchema.js +3 -4
  26. package/dist/actions/graphql/extractFromSanitySchema.js.map +1 -1
  27. package/dist/actions/graphql/extractGraphQLAPIs.js +150 -0
  28. package/dist/actions/graphql/extractGraphQLAPIs.js.map +1 -0
  29. package/dist/actions/graphql/extractGraphQLAPIs.worker.js +12 -0
  30. package/dist/actions/graphql/extractGraphQLAPIs.worker.js.map +1 -0
  31. package/dist/actions/graphql/gen1/index.js +5 -5
  32. package/dist/actions/graphql/gen1/index.js.map +1 -1
  33. package/dist/actions/graphql/gen2/index.js +6 -6
  34. package/dist/actions/graphql/gen2/index.js.map +1 -1
  35. package/dist/actions/graphql/gen3/generateTypeQueries.js +2 -3
  36. package/dist/actions/graphql/gen3/generateTypeQueries.js.map +1 -1
  37. package/dist/actions/graphql/gen3/index.js +6 -7
  38. package/dist/actions/graphql/gen3/index.js.map +1 -1
  39. package/dist/actions/graphql/getGraphQLAPIs.js +12 -35
  40. package/dist/actions/graphql/getGraphQLAPIs.js.map +1 -1
  41. package/dist/actions/graphql/getGraphQLAPIs.worker.js +75 -106
  42. package/dist/actions/graphql/getGraphQLAPIs.worker.js.map +1 -1
  43. package/dist/actions/graphql/helpers.js +13 -0
  44. package/dist/actions/graphql/helpers.js.map +1 -1
  45. package/dist/actions/graphql/resolveGraphQLApisFromWorkspaces.js +187 -0
  46. package/dist/actions/graphql/resolveGraphQLApisFromWorkspaces.js.map +1 -0
  47. package/dist/actions/graphql/types.js +1 -1
  48. package/dist/actions/graphql/types.js.map +1 -1
  49. package/dist/actions/init/bootstrapLocalTemplate.js +2 -1
  50. package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -1
  51. package/dist/actions/init/bootstrapRemoteTemplate.js +6 -5
  52. package/dist/actions/init/bootstrapRemoteTemplate.js.map +1 -1
  53. package/dist/actions/init/createPackageManifest.js +5 -0
  54. package/dist/actions/init/createPackageManifest.js.map +1 -1
  55. package/dist/actions/init/templates/appQuickstart.js +2 -1
  56. package/dist/actions/init/templates/appQuickstart.js.map +1 -1
  57. package/dist/actions/init/templates/appSanityUi.js +2 -1
  58. package/dist/actions/init/templates/appSanityUi.js.map +1 -1
  59. package/dist/actions/init/types.js.map +1 -1
  60. package/dist/actions/media/importMedia.js +1 -2
  61. package/dist/actions/media/importMedia.js.map +1 -1
  62. package/dist/actions/projects/getManageUrl.js +1 -2
  63. package/dist/actions/projects/getManageUrl.js.map +1 -1
  64. package/dist/actions/schema/validateSchema.worker.js +1 -3
  65. package/dist/actions/schema/validateSchema.worker.js.map +1 -1
  66. package/dist/actions/telemetry/isTrueish.js +10 -0
  67. package/dist/actions/telemetry/isTrueish.js.map +1 -0
  68. package/dist/actions/telemetry/resolveConsent.js +2 -1
  69. package/dist/actions/telemetry/resolveConsent.js.map +1 -1
  70. package/dist/actions/telemetry/setConsent.js +2 -1
  71. package/dist/actions/telemetry/setConsent.js.map +1 -1
  72. package/dist/actions/versions/findSanityModulesVersions.js +1 -2
  73. package/dist/actions/versions/findSanityModulesVersions.js.map +1 -1
  74. package/dist/commands/backup/disable.js +21 -1
  75. package/dist/commands/backup/disable.js.map +1 -1
  76. package/dist/commands/backup/download.js +18 -4
  77. package/dist/commands/backup/download.js.map +1 -1
  78. package/dist/commands/backup/enable.js +21 -1
  79. package/dist/commands/backup/enable.js.map +1 -1
  80. package/dist/commands/backup/list.js +15 -1
  81. package/dist/commands/backup/list.js.map +1 -1
  82. package/dist/commands/cors/add.js +19 -1
  83. package/dist/commands/cors/add.js.map +1 -1
  84. package/dist/commands/cors/delete.js +21 -1
  85. package/dist/commands/cors/delete.js.map +1 -1
  86. package/dist/commands/cors/list.js +21 -1
  87. package/dist/commands/cors/list.js.map +1 -1
  88. package/dist/commands/dataset/alias/create.js +4 -2
  89. package/dist/commands/dataset/alias/create.js.map +1 -1
  90. package/dist/commands/dataset/alias/delete.js +4 -2
  91. package/dist/commands/dataset/alias/delete.js.map +1 -1
  92. package/dist/commands/dataset/alias/link.js +4 -2
  93. package/dist/commands/dataset/alias/link.js.map +1 -1
  94. package/dist/commands/dataset/alias/unlink.js +4 -2
  95. package/dist/commands/dataset/alias/unlink.js.map +1 -1
  96. package/dist/commands/dataset/copy.js +4 -2
  97. package/dist/commands/dataset/copy.js.map +1 -1
  98. package/dist/commands/dataset/create.js +4 -2
  99. package/dist/commands/dataset/create.js.map +1 -1
  100. package/dist/commands/dataset/delete.js +4 -2
  101. package/dist/commands/dataset/delete.js.map +1 -1
  102. package/dist/commands/dataset/embeddings/disable.js +4 -2
  103. package/dist/commands/dataset/embeddings/disable.js.map +1 -1
  104. package/dist/commands/dataset/embeddings/enable.js +6 -4
  105. package/dist/commands/dataset/embeddings/enable.js.map +1 -1
  106. package/dist/commands/dataset/embeddings/status.js +4 -2
  107. package/dist/commands/dataset/embeddings/status.js.map +1 -1
  108. package/dist/commands/dataset/export.js +7 -11
  109. package/dist/commands/dataset/export.js.map +1 -1
  110. package/dist/commands/dataset/list.js +4 -2
  111. package/dist/commands/dataset/list.js.map +1 -1
  112. package/dist/commands/dataset/visibility/get.js +4 -2
  113. package/dist/commands/dataset/visibility/get.js.map +1 -1
  114. package/dist/commands/dataset/visibility/set.js +4 -2
  115. package/dist/commands/dataset/visibility/set.js.map +1 -1
  116. package/dist/commands/debug.js +2 -1
  117. package/dist/commands/debug.js.map +1 -1
  118. package/dist/commands/documents/create.js +15 -5
  119. package/dist/commands/documents/create.js.map +1 -1
  120. package/dist/commands/documents/delete.js +17 -6
  121. package/dist/commands/documents/delete.js.map +1 -1
  122. package/dist/commands/documents/get.js +15 -6
  123. package/dist/commands/documents/get.js.map +1 -1
  124. package/dist/commands/documents/query.js +24 -12
  125. package/dist/commands/documents/query.js.map +1 -1
  126. package/dist/commands/documents/validate.js +29 -9
  127. package/dist/commands/documents/validate.js.map +1 -1
  128. package/dist/commands/graphql/deploy.js +55 -28
  129. package/dist/commands/graphql/deploy.js.map +1 -1
  130. package/dist/commands/graphql/list.js +14 -1
  131. package/dist/commands/graphql/list.js.map +1 -1
  132. package/dist/commands/graphql/undeploy.js +36 -14
  133. package/dist/commands/graphql/undeploy.js.map +1 -1
  134. package/dist/commands/hook/attempt.js +21 -1
  135. package/dist/commands/hook/attempt.js.map +1 -1
  136. package/dist/commands/hook/create.js +22 -2
  137. package/dist/commands/hook/create.js.map +1 -1
  138. package/dist/commands/hook/delete.js +21 -1
  139. package/dist/commands/hook/delete.js.map +1 -1
  140. package/dist/commands/hook/list.js +21 -1
  141. package/dist/commands/hook/list.js.map +1 -1
  142. package/dist/commands/hook/logs.js +19 -1
  143. package/dist/commands/hook/logs.js.map +1 -1
  144. package/dist/commands/init.js +13 -6
  145. package/dist/commands/init.js.map +1 -1
  146. package/dist/commands/login.js +13 -6
  147. package/dist/commands/login.js.map +1 -1
  148. package/dist/commands/logout.js +8 -6
  149. package/dist/commands/logout.js.map +1 -1
  150. package/dist/commands/media/create-aspect.js +3 -3
  151. package/dist/commands/media/create-aspect.js.map +1 -1
  152. package/dist/commands/media/delete-aspect.js +8 -1
  153. package/dist/commands/media/delete-aspect.js.map +1 -1
  154. package/dist/commands/media/deploy-aspect.js +20 -3
  155. package/dist/commands/media/deploy-aspect.js.map +1 -1
  156. package/dist/commands/media/export.js +8 -1
  157. package/dist/commands/media/export.js.map +1 -1
  158. package/dist/commands/media/import.js +9 -2
  159. package/dist/commands/media/import.js.map +1 -1
  160. package/dist/commands/schema/delete.js +19 -6
  161. package/dist/commands/schema/delete.js.map +1 -1
  162. package/dist/commands/schema/deploy.js +8 -2
  163. package/dist/commands/schema/deploy.js.map +1 -1
  164. package/dist/commands/tokens/add.js +23 -1
  165. package/dist/commands/tokens/add.js.map +1 -1
  166. package/dist/commands/tokens/delete.js +19 -1
  167. package/dist/commands/tokens/delete.js.map +1 -1
  168. package/dist/commands/tokens/list.js +19 -1
  169. package/dist/commands/tokens/list.js.map +1 -1
  170. package/dist/commands/users/invite.js +23 -1
  171. package/dist/commands/users/invite.js.map +1 -1
  172. package/dist/commands/users/list.js +23 -1
  173. package/dist/commands/users/list.js.map +1 -1
  174. package/dist/hooks/prerun/flushTelemetry.worker.js +1 -1
  175. package/dist/hooks/prerun/flushTelemetry.worker.js.map +1 -1
  176. package/dist/hooks/prerun/injectEnvVariables.js +9 -1
  177. package/dist/hooks/prerun/injectEnvVariables.js.map +1 -1
  178. package/dist/hooks/prerun/setupTelemetry.js +2 -1
  179. package/dist/hooks/prerun/setupTelemetry.js.map +1 -1
  180. package/dist/prompts/promptForProject.js.map +1 -1
  181. package/dist/{actions/auth/login/promptProviders.js → prompts/promptForProviders.js} +3 -3
  182. package/dist/prompts/promptForProviders.js.map +1 -0
  183. package/dist/services/auth.js +36 -3
  184. package/dist/services/auth.js.map +1 -1
  185. package/dist/services/docs.js +2 -2
  186. package/dist/services/docs.js.map +1 -1
  187. package/dist/services/getUrlHeaders.js +0 -2
  188. package/dist/services/getUrlHeaders.js.map +1 -1
  189. package/dist/services/projects.js +4 -2
  190. package/dist/services/projects.js.map +1 -1
  191. package/dist/services/telemetry.js +2 -1
  192. package/dist/services/telemetry.js.map +1 -1
  193. package/dist/util/createExpiringConfig.js +64 -0
  194. package/dist/util/createExpiringConfig.js.map +1 -0
  195. package/dist/util/detectFramework.js +135 -0
  196. package/dist/util/detectFramework.js.map +1 -0
  197. package/dist/util/extractDocumentsFromNdjsonOrTarball.js +1 -2
  198. package/dist/util/extractDocumentsFromNdjsonOrTarball.js.map +1 -1
  199. package/dist/util/isSchemaError.js +11 -0
  200. package/dist/util/isSchemaError.js.map +1 -0
  201. package/dist/util/isTar.js +8 -0
  202. package/dist/util/isTar.js.map +1 -0
  203. package/dist/util/sharedFlags.js +44 -14
  204. package/dist/util/sharedFlags.js.map +1 -1
  205. package/dist/util/telemetry/cleanupOldTelemetryFiles.js +30 -0
  206. package/dist/util/telemetry/cleanupOldTelemetryFiles.js.map +1 -0
  207. package/dist/util/telemetry/createTelemetryStore.js +95 -0
  208. package/dist/util/telemetry/createTelemetryStore.js.map +1 -0
  209. package/dist/util/telemetry/createTraceId.js +10 -0
  210. package/dist/util/telemetry/createTraceId.js.map +1 -0
  211. package/dist/util/telemetry/findTelemetryFiles.js +35 -0
  212. package/dist/util/telemetry/findTelemetryFiles.js.map +1 -0
  213. package/dist/util/telemetry/flushTelemetryFiles.js +118 -0
  214. package/dist/util/telemetry/flushTelemetryFiles.js.map +1 -0
  215. package/dist/util/telemetry/generateTelemetryFilePath.js +30 -0
  216. package/dist/util/telemetry/generateTelemetryFilePath.js.map +1 -0
  217. package/dist/util/telemetry/logger.js +59 -0
  218. package/dist/util/telemetry/logger.js.map +1 -0
  219. package/dist/util/telemetry/readNDJSON.js +28 -0
  220. package/dist/util/telemetry/readNDJSON.js.map +1 -0
  221. package/dist/util/telemetry/telemetryStoreDebug.js +7 -0
  222. package/dist/util/telemetry/telemetryStoreDebug.js.map +1 -0
  223. package/dist/util/telemetry/trace.js +150 -0
  224. package/dist/util/telemetry/trace.js.map +1 -0
  225. package/dist/util/update/updateChecker.js +2 -1
  226. package/dist/util/update/updateChecker.js.map +1 -1
  227. package/oclif.manifest.json +1211 -774
  228. package/package.json +19 -22
  229. package/dist/actions/auth/login/promptProviders.js.map +0 -1
@@ -0,0 +1,150 @@
1
+ import { isMainThread } from 'node:worker_threads';
2
+ import { findStudioConfigPath, getCliConfig, studioWorkerTask, subdebug } from '@sanity/cli-core';
3
+ import { isSchemaError } from '../../util/isSchemaError.js';
4
+ import { extractFromSanitySchema } from './extractFromSanitySchema.js';
5
+ import { resolveGraphQLApis } from './resolveGraphQLApisFromWorkspaces.js';
6
+ import { SchemaError } from './SchemaError.js';
7
+ // ---------------------------------------------------------------------------
8
+ // Main-thread orchestrator
9
+ // ---------------------------------------------------------------------------
10
+ export async function extractGraphQLAPIs(workDir, options) {
11
+ if (!isMainThread) {
12
+ throw new Error('extractGraphQLAPIs() must be called from the main thread');
13
+ }
14
+ const [cliConfig, configPath] = await Promise.all([
15
+ getCliConfig(workDir),
16
+ findStudioConfigPath(workDir)
17
+ ]);
18
+ const result = await studioWorkerTask(new URL('extractGraphQLAPIs.worker.js', import.meta.url), {
19
+ name: 'extractGraphQLAPIs',
20
+ studioRootPath: workDir,
21
+ workerData: {
22
+ cliConfig: extractGraphQLConfig(cliConfig),
23
+ configPath,
24
+ nonNullDocumentFieldsFlag: options.nonNullDocumentFieldsFlag,
25
+ withUnionCache: options.withUnionCache,
26
+ workDir
27
+ }
28
+ });
29
+ if (result.configErrors?.length) {
30
+ throw new SchemaError(result.configErrors);
31
+ }
32
+ return result.apis;
33
+ }
34
+ function extractGraphQLConfig(config) {
35
+ return {
36
+ graphql: config.graphql
37
+ };
38
+ }
39
+ const debug = subdebug('graphql:extractGraphQLAPIs:worker');
40
+ export async function extractGraphQLAPIsWorker(port, data, deps) {
41
+ const { cliConfig, configPath, nonNullDocumentFieldsFlag, withUnionCache, workDir } = data;
42
+ // Load workspaces — this loads sanity.config.ts through Vite, caching `sanity` in the process
43
+ let workspaces;
44
+ try {
45
+ workspaces = await deps.getStudioWorkspaces(configPath);
46
+ } catch (err) {
47
+ if (isSchemaError(err)) {
48
+ const validation = err.schema._validation ?? [];
49
+ const configErrors = validation.map((g)=>({
50
+ ...g,
51
+ problems: g.problems.filter((p)=>p.severity === 'error')
52
+ })).filter((g)=>g.problems.length > 0);
53
+ // Only treat error-severity problems as schema errors. If the validation
54
+ // only contains warnings, re-throw the original error so it isn't silently
55
+ // swallowed — warnings alone should not block deployment.
56
+ if (configErrors.length === 0) {
57
+ throw err;
58
+ }
59
+ port.postMessage({
60
+ apis: [],
61
+ configErrors
62
+ });
63
+ return;
64
+ }
65
+ throw err;
66
+ }
67
+ // Resolve which GraphQL APIs to deploy from workspace + CLI config
68
+ const resolvedApis = resolveGraphQLApis({
69
+ cliConfig,
70
+ workspaces
71
+ });
72
+ // Get createSchema from sanity (0ms — already cached by ViteNodeRunner)
73
+ const { createSchema } = await deps.resolveLocalPackage('sanity', workDir);
74
+ // Build default schema to identify built-in types that should be filtered out
75
+ const defaultSchema = createSchema({
76
+ name: 'default',
77
+ types: []
78
+ });
79
+ const defaultTypes = defaultSchema.getTypeNames();
80
+ const isCustomType = (type)=>!defaultTypes.includes(type.name);
81
+ // For each API: create compiled schema, extract GraphQL spec, catch SchemaError
82
+ const results = [];
83
+ for (const api of resolvedApis){
84
+ const apiBase = {
85
+ dataset: api.dataset,
86
+ filterSuffix: api.filterSuffix,
87
+ generation: api.generation,
88
+ id: api.id,
89
+ nonNullDocumentFields: api.nonNullDocumentFields,
90
+ playground: api.playground,
91
+ projectId: api.projectId,
92
+ tag: api.tag
93
+ };
94
+ try {
95
+ const schema = createSchema({
96
+ name: 'default',
97
+ types: api.schemaTypes.filter((type)=>isCustomType(type))
98
+ });
99
+ const extracted = extractFromSanitySchema(schema, {
100
+ nonNullDocumentFields: nonNullDocumentFieldsFlag === undefined ? api.nonNullDocumentFields : nonNullDocumentFieldsFlag,
101
+ withUnionCache
102
+ });
103
+ results.push({
104
+ ...apiBase,
105
+ extracted
106
+ });
107
+ } catch (err) {
108
+ if (err instanceof SchemaError) {
109
+ results.push({
110
+ ...apiBase,
111
+ schemaErrors: err.problemGroups
112
+ });
113
+ } else if (isSchemaError(err)) {
114
+ // Sanity's internal schema error from createSchema() — different class from our
115
+ // SchemaError, but carries structured validation data on err.schema._validation.
116
+ // This is low-probability since getStudioWorkspaces() above already validated,
117
+ // but createSchema() on filtered types could still surface issues.
118
+ const validation = err.schema._validation ?? [];
119
+ const errorGroups = validation.map((g)=>({
120
+ ...g,
121
+ problems: g.problems.filter((p)=>p.severity === 'error')
122
+ })).filter((g)=>g.problems.length > 0);
123
+ if (errorGroups.length > 0) {
124
+ results.push({
125
+ ...apiBase,
126
+ schemaErrors: errorGroups
127
+ });
128
+ } else {
129
+ // Warning-only or empty _validation — fall through to generic error with the
130
+ // message, matching the global path which re-throws warning-only errors.
131
+ results.push({
132
+ ...apiBase,
133
+ extractionError: err instanceof Error ? err.message : String(err)
134
+ });
135
+ }
136
+ } else {
137
+ debug('Schema extraction failed for %s/%s: %O', apiBase.dataset, apiBase.tag ?? 'default', err);
138
+ results.push({
139
+ ...apiBase,
140
+ extractionError: err instanceof Error ? err.message : String(err)
141
+ });
142
+ }
143
+ }
144
+ }
145
+ port.postMessage({
146
+ apis: results
147
+ });
148
+ }
149
+
150
+ //# sourceMappingURL=extractGraphQLAPIs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/graphql/extractGraphQLAPIs.ts"],"sourcesContent":["import {isMainThread, type MessagePort} from 'node:worker_threads'\n\nimport {\n type CliConfig,\n findStudioConfigPath,\n getCliConfig,\n studioWorkerTask,\n subdebug,\n} from '@sanity/cli-core'\n\nimport {isSchemaError} from '../../util/isSchemaError.js'\nimport {extractFromSanitySchema} from './extractFromSanitySchema.js'\nimport {resolveGraphQLApis, type Workspace} from './resolveGraphQLApisFromWorkspaces.js'\nimport {SchemaError} from './SchemaError.js'\nimport {\n type ExtractedGraphQLAPI,\n type GraphQLAPIConfig,\n type GraphQLWorkerResult,\n type SchemaDefinitionish,\n} from './types.js'\n\n// ---------------------------------------------------------------------------\n// Main-thread orchestrator\n// ---------------------------------------------------------------------------\n\nexport async function extractGraphQLAPIs(\n workDir: string,\n options: {nonNullDocumentFieldsFlag?: boolean; withUnionCache?: boolean},\n): Promise<ExtractedGraphQLAPI[]> {\n if (!isMainThread) {\n throw new Error('extractGraphQLAPIs() must be called from the main thread')\n }\n\n const [cliConfig, configPath] = await Promise.all([\n getCliConfig(workDir),\n findStudioConfigPath(workDir),\n ])\n\n const result = await studioWorkerTask<GraphQLWorkerResult>(\n new URL('extractGraphQLAPIs.worker.js', import.meta.url),\n {\n name: 'extractGraphQLAPIs',\n studioRootPath: workDir,\n workerData: {\n cliConfig: extractGraphQLConfig(cliConfig),\n configPath,\n nonNullDocumentFieldsFlag: options.nonNullDocumentFieldsFlag,\n withUnionCache: options.withUnionCache,\n workDir,\n },\n },\n )\n\n if (result.configErrors?.length) {\n throw new SchemaError(result.configErrors)\n }\n\n return result.apis\n}\n\nfunction extractGraphQLConfig(config: CliConfig) {\n return {\n graphql: config.graphql,\n }\n}\n\n// ---------------------------------------------------------------------------\n// Worker logic (runs inside the worker thread)\n// ---------------------------------------------------------------------------\n\nexport interface ExtractWorkerData {\n configPath: string\n workDir: string\n\n cliConfig?: {graphql?: GraphQLAPIConfig[]}\n nonNullDocumentFieldsFlag?: boolean\n withUnionCache?: boolean\n}\n\nexport interface ExtractWorkerDeps {\n getStudioWorkspaces: (configPath: string) => Promise<unknown[]>\n resolveLocalPackage: <T>(name: string, workDir: string) => Promise<T>\n}\n\nconst debug = subdebug('graphql:extractGraphQLAPIs:worker')\n\nexport async function extractGraphQLAPIsWorker(\n port: MessagePort,\n data: ExtractWorkerData,\n deps: ExtractWorkerDeps,\n): Promise<void> {\n const {cliConfig, configPath, nonNullDocumentFieldsFlag, withUnionCache, workDir} = data\n\n // Load workspaces — this loads sanity.config.ts through Vite, caching `sanity` in the process\n let workspaces: Workspace[]\n try {\n workspaces = (await deps.getStudioWorkspaces(configPath)) as Workspace[]\n } catch (err) {\n if (isSchemaError(err)) {\n const validation = err.schema._validation ?? []\n const configErrors = validation\n .map((g) => ({...g, problems: g.problems.filter((p) => p.severity === 'error')}))\n .filter((g) => g.problems.length > 0)\n\n // Only treat error-severity problems as schema errors. If the validation\n // only contains warnings, re-throw the original error so it isn't silently\n // swallowed — warnings alone should not block deployment.\n if (configErrors.length === 0) {\n throw err\n }\n\n port.postMessage({apis: [], configErrors} satisfies GraphQLWorkerResult)\n return\n }\n throw err\n }\n\n // Resolve which GraphQL APIs to deploy from workspace + CLI config\n const resolvedApis = resolveGraphQLApis({cliConfig, workspaces})\n\n // Get createSchema from sanity (0ms — already cached by ViteNodeRunner)\n const {createSchema} = await deps.resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n\n // Build default schema to identify built-in types that should be filtered out\n const defaultSchema = createSchema({name: 'default', types: []})\n const defaultTypes = defaultSchema.getTypeNames()\n const isCustomType = (type: SchemaDefinitionish) => !defaultTypes.includes(type.name)\n\n // For each API: create compiled schema, extract GraphQL spec, catch SchemaError\n const results: ExtractedGraphQLAPI[] = []\n\n for (const api of resolvedApis) {\n const apiBase: Omit<ExtractedGraphQLAPI, 'extracted' | 'extractionError' | 'schemaErrors'> = {\n dataset: api.dataset,\n filterSuffix: api.filterSuffix,\n generation: api.generation,\n id: api.id,\n nonNullDocumentFields: api.nonNullDocumentFields,\n playground: api.playground,\n projectId: api.projectId,\n tag: api.tag,\n }\n\n try {\n const schema = createSchema({\n name: 'default',\n types: api.schemaTypes.filter((type) => isCustomType(type)),\n })\n\n const extracted = extractFromSanitySchema(schema, {\n nonNullDocumentFields:\n nonNullDocumentFieldsFlag === undefined\n ? api.nonNullDocumentFields\n : nonNullDocumentFieldsFlag,\n withUnionCache,\n })\n\n results.push({...apiBase, extracted})\n } catch (err) {\n if (err instanceof SchemaError) {\n results.push({...apiBase, schemaErrors: err.problemGroups})\n } else if (isSchemaError(err)) {\n // Sanity's internal schema error from createSchema() — different class from our\n // SchemaError, but carries structured validation data on err.schema._validation.\n // This is low-probability since getStudioWorkspaces() above already validated,\n // but createSchema() on filtered types could still surface issues.\n const validation = err.schema._validation ?? []\n const errorGroups = validation\n .map((g) => ({...g, problems: g.problems.filter((p) => p.severity === 'error')}))\n .filter((g) => g.problems.length > 0)\n if (errorGroups.length > 0) {\n results.push({...apiBase, schemaErrors: errorGroups})\n } else {\n // Warning-only or empty _validation — fall through to generic error with the\n // message, matching the global path which re-throws warning-only errors.\n results.push({\n ...apiBase,\n extractionError: err instanceof Error ? err.message : String(err),\n })\n }\n } else {\n debug(\n 'Schema extraction failed for %s/%s: %O',\n apiBase.dataset,\n apiBase.tag ?? 'default',\n err,\n )\n results.push({\n ...apiBase,\n extractionError: err instanceof Error ? err.message : String(err),\n })\n }\n }\n }\n\n port.postMessage({apis: results} satisfies GraphQLWorkerResult)\n}\n"],"names":["isMainThread","findStudioConfigPath","getCliConfig","studioWorkerTask","subdebug","isSchemaError","extractFromSanitySchema","resolveGraphQLApis","SchemaError","extractGraphQLAPIs","workDir","options","Error","cliConfig","configPath","Promise","all","result","URL","url","name","studioRootPath","workerData","extractGraphQLConfig","nonNullDocumentFieldsFlag","withUnionCache","configErrors","length","apis","config","graphql","debug","extractGraphQLAPIsWorker","port","data","deps","workspaces","getStudioWorkspaces","err","validation","schema","_validation","map","g","problems","filter","p","severity","postMessage","resolvedApis","createSchema","resolveLocalPackage","defaultSchema","types","defaultTypes","getTypeNames","isCustomType","type","includes","results","api","apiBase","dataset","filterSuffix","generation","id","nonNullDocumentFields","playground","projectId","tag","schemaTypes","extracted","undefined","push","schemaErrors","problemGroups","errorGroups","extractionError","message","String"],"mappings":"AAAA,SAAQA,YAAY,QAAyB,sBAAqB;AAElE,SAEEC,oBAAoB,EACpBC,YAAY,EACZC,gBAAgB,EAChBC,QAAQ,QACH,mBAAkB;AAEzB,SAAQC,aAAa,QAAO,8BAA6B;AACzD,SAAQC,uBAAuB,QAAO,+BAA8B;AACpE,SAAQC,kBAAkB,QAAuB,wCAAuC;AACxF,SAAQC,WAAW,QAAO,mBAAkB;AAQ5C,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,OAAO,eAAeC,mBACpBC,OAAe,EACfC,OAAwE;IAExE,IAAI,CAACX,cAAc;QACjB,MAAM,IAAIY,MAAM;IAClB;IAEA,MAAM,CAACC,WAAWC,WAAW,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAChDd,aAAaQ;QACbT,qBAAqBS;KACtB;IAED,MAAMO,SAAS,MAAMd,iBACnB,IAAIe,IAAI,gCAAgC,YAAYC,GAAG,GACvD;QACEC,MAAM;QACNC,gBAAgBX;QAChBY,YAAY;YACVT,WAAWU,qBAAqBV;YAChCC;YACAU,2BAA2Bb,QAAQa,yBAAyB;YAC5DC,gBAAgBd,QAAQc,cAAc;YACtCf;QACF;IACF;IAGF,IAAIO,OAAOS,YAAY,EAAEC,QAAQ;QAC/B,MAAM,IAAInB,YAAYS,OAAOS,YAAY;IAC3C;IAEA,OAAOT,OAAOW,IAAI;AACpB;AAEA,SAASL,qBAAqBM,MAAiB;IAC7C,OAAO;QACLC,SAASD,OAAOC,OAAO;IACzB;AACF;AAoBA,MAAMC,QAAQ3B,SAAS;AAEvB,OAAO,eAAe4B,yBACpBC,IAAiB,EACjBC,IAAuB,EACvBC,IAAu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ACX,GAAGZ,OAAO;wBACVgB,iBAAiBvC,eAAe1B,QAAQ0B,IAAIwC,OAAO,GAAGC,OAAOzC;oBAC/D;gBACF;YACF,OAAO;gBACLP,MACE,0CACA8B,QAAQC,OAAO,EACfD,QAAQQ,GAAG,IAAI,WACf/B;gBAEFqB,QAAQc,IAAI,CAAC;oBACX,GAAGZ,OAAO;oBACVgB,iBAAiBvC,eAAe1B,QAAQ0B,IAAIwC,OAAO,GAAGC,OAAOzC;gBAC/D;YACF;QACF;IACF;IAEAL,KAAKe,WAAW,CAAC;QAACpB,MAAM+B;IAAO;AACjC"}
@@ -0,0 +1,12 @@
1
+ import { isMainThread, parentPort, workerData } from 'node:worker_threads';
2
+ import { getStudioWorkspaces, resolveLocalPackage } from '@sanity/cli-core';
3
+ import { extractGraphQLAPIsWorker } from './extractGraphQLAPIs.js';
4
+ if (isMainThread || !parentPort) {
5
+ throw new Error('This module must be run as a worker thread');
6
+ }
7
+ await extractGraphQLAPIsWorker(parentPort, workerData, {
8
+ getStudioWorkspaces,
9
+ resolveLocalPackage
10
+ });
11
+
12
+ //# sourceMappingURL=extractGraphQLAPIs.worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/actions/graphql/extractGraphQLAPIs.worker.ts"],"sourcesContent":["import {isMainThread, parentPort, workerData} from 'node:worker_threads'\n\nimport {getStudioWorkspaces, resolveLocalPackage} from '@sanity/cli-core'\n\nimport {extractGraphQLAPIsWorker, type ExtractWorkerData} from './extractGraphQLAPIs.js'\n\nif (isMainThread || !parentPort) {\n throw new Error('This module must be run as a worker thread')\n}\n\nawait extractGraphQLAPIsWorker(parentPort, workerData as ExtractWorkerData, {\n getStudioWorkspaces,\n resolveLocalPackage,\n})\n"],"names":["isMainThread","parentPort","workerData","getStudioWorkspaces","resolveLocalPackage","extractGraphQLAPIsWorker","Error"],"mappings":"AAAA,SAAQA,YAAY,EAAEC,UAAU,EAAEC,UAAU,QAAO,sBAAqB;AAExE,SAAQC,mBAAmB,EAAEC,mBAAmB,QAAO,mBAAkB;AAEzE,SAAQC,wBAAwB,QAA+B,0BAAyB;AAExF,IAAIL,gBAAgB,CAACC,YAAY;IAC/B,MAAM,IAAIK,MAAM;AAClB;AAEA,MAAMD,yBAAyBJ,YAAYC,YAAiC;IAC1EC;IACAC;AACF"}
@@ -1,17 +1,17 @@
1
+ import { stripInternalMeta } from '../helpers.js';
1
2
  import { generateTypeFilters } from './generateTypeFilters.js';
2
3
  import { generateTypeQueries } from './generateTypeQueries.js';
3
4
  const gen1 = (extracted)=>{
4
5
  const filters = generateTypeFilters(extracted.types);
5
6
  const queries = generateTypeQueries(extracted.types, filters);
6
- const types = [
7
- ...extracted.types,
8
- ...filters
9
- ];
10
7
  return {
11
8
  generation: 'gen1',
12
9
  interfaces: extracted.interfaces,
13
10
  queries,
14
- types
11
+ types: [
12
+ ...stripInternalMeta(extracted.types),
13
+ ...filters
14
+ ]
15
15
  };
16
16
  };
17
17
  export default gen1;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/graphql/gen1/index.ts"],"sourcesContent":["import {type ApiSpecification, type GeneratedApiSpecification} from '../types.js'\nimport {generateTypeFilters} from './generateTypeFilters.js'\nimport {generateTypeQueries} from './generateTypeQueries.js'\n\nconst gen1 = (extracted: ApiSpecification): GeneratedApiSpecification => {\n const filters = generateTypeFilters(extracted.types)\n const queries = generateTypeQueries(extracted.types, filters)\n const types = [...extracted.types, ...filters]\n return {generation: 'gen1', interfaces: extracted.interfaces, queries, types}\n}\n\nexport default gen1\n"],"names":["generateTypeFilters","generateTypeQueries","gen1","extracted","filters","types","queries","generation","interfaces"],"mappings":"AACA,SAAQA,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D,MAAMC,OAAO,CAACC;IACZ,MAAMC,UAAUJ,oBAAoBG,UAAUE,KAAK;IACnD,MAAMC,UAAUL,oBAAoBE,UAAUE,KAAK,EAAED;IACrD,MAAMC,QAAQ;WAAIF,UAAUE,KAAK;WAAKD;KAAQ;IAC9C,OAAO;QAACG,YAAY;QAAQC,YAAYL,UAAUK,UAAU;QAAEF;QAASD;IAAK;AAC9E;AAEA,eAAeH,KAAI"}
1
+ {"version":3,"sources":["../../../../src/actions/graphql/gen1/index.ts"],"sourcesContent":["import {stripInternalMeta} from '../helpers.js'\nimport {type ApiSpecification, type GeneratedApiSpecification} from '../types.js'\nimport {generateTypeFilters} from './generateTypeFilters.js'\nimport {generateTypeQueries} from './generateTypeQueries.js'\n\nconst gen1 = (extracted: ApiSpecification): GeneratedApiSpecification => {\n const filters = generateTypeFilters(extracted.types)\n const queries = generateTypeQueries(extracted.types, filters)\n\n return {\n generation: 'gen1',\n interfaces: extracted.interfaces,\n queries,\n types: [...stripInternalMeta(extracted.types), ...filters],\n }\n}\n\nexport default gen1\n"],"names":["stripInternalMeta","generateTypeFilters","generateTypeQueries","gen1","extracted","filters","types","queries","generation","interfaces"],"mappings":"AAAA,SAAQA,iBAAiB,QAAO,gBAAe;AAE/C,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,mBAAmB,QAAO,2BAA0B;AAE5D,MAAMC,OAAO,CAACC;IACZ,MAAMC,UAAUJ,oBAAoBG,UAAUE,KAAK;IACnD,MAAMC,UAAUL,oBAAoBE,UAAUE,KAAK,EAAED;IAErD,OAAO;QACLG,YAAY;QACZC,YAAYL,UAAUK,UAAU;QAChCF;QACAD,OAAO;eAAIN,kBAAkBI,UAAUE,KAAK;eAAMD;SAAQ;IAC5D;AACF;AAEA,eAAeF,KAAI"}
@@ -1,3 +1,4 @@
1
+ import { stripInternalMeta } from '../helpers.js';
1
2
  import { generateTypeFilters } from './generateTypeFilters.js';
2
3
  import { generateTypeQueries } from './generateTypeQueries.js';
3
4
  import { generateTypeSortings } from './generateTypeSortings.js';
@@ -5,16 +6,15 @@ const gen2 = (extracted)=>{
5
6
  const filters = generateTypeFilters(extracted.types);
6
7
  const sortings = generateTypeSortings(extracted.types);
7
8
  const queries = generateTypeQueries(extracted.types, sortings.filter((node)=>node.kind === 'InputObject'));
8
- const types = [
9
- ...extracted.types,
10
- ...filters,
11
- ...sortings
12
- ];
13
9
  return {
14
10
  generation: 'gen2',
15
11
  interfaces: extracted.interfaces,
16
12
  queries,
17
- types
13
+ types: [
14
+ ...stripInternalMeta(extracted.types),
15
+ ...filters,
16
+ ...sortings
17
+ ]
18
18
  };
19
19
  };
20
20
  export default gen2;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/graphql/gen2/index.ts"],"sourcesContent":["import {\n type ApiSpecification,\n type GeneratedApiSpecification,\n type InputObjectType,\n} from '../types.js'\nimport {generateTypeFilters} from './generateTypeFilters.js'\nimport {generateTypeQueries} from './generateTypeQueries.js'\nimport {generateTypeSortings} from './generateTypeSortings.js'\n\nconst gen2 = (extracted: ApiSpecification): GeneratedApiSpecification => {\n const filters = generateTypeFilters(extracted.types)\n const sortings = generateTypeSortings(extracted.types)\n const queries = generateTypeQueries(\n extracted.types,\n sortings.filter((node): node is InputObjectType => node.kind === 'InputObject'),\n )\n const types = [...extracted.types, ...filters, ...sortings]\n\n return {generation: 'gen2', interfaces: extracted.interfaces, queries, types}\n}\n\nexport default gen2\n"],"names":["generateTypeFilters","generateTypeQueries","generateTypeSortings","gen2","extracted","filters","types","sortings","queries","filter","node","kind","generation","interfaces"],"mappings":"AAKA,SAAQA,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D,MAAMC,OAAO,CAACC;IACZ,MAAMC,UAAUL,oBAAoBI,UAAUE,KAAK;IACnD,MAAMC,WAAWL,qBAAqBE,UAAUE,KAAK;IACrD,MAAME,UAAUP,oBACdG,UAAUE,KAAK,EACfC,SAASE,MAAM,CAAC,CAACC,OAAkCA,KAAKC,IAAI,KAAK;IAEnE,MAAML,QAAQ;WAAIF,UAAUE,KAAK;WAAKD;WAAYE;KAAS;IAE3D,OAAO;QAACK,YAAY;QAAQC,YAAYT,UAAUS,UAAU;QAAEL;QAASF;IAAK;AAC9E;AAEA,eAAeH,KAAI"}
1
+ {"version":3,"sources":["../../../../src/actions/graphql/gen2/index.ts"],"sourcesContent":["import {stripInternalMeta} from '../helpers.js'\nimport {\n type ApiSpecification,\n type GeneratedApiSpecification,\n type InputObjectType,\n} from '../types.js'\nimport {generateTypeFilters} from './generateTypeFilters.js'\nimport {generateTypeQueries} from './generateTypeQueries.js'\nimport {generateTypeSortings} from './generateTypeSortings.js'\n\nconst gen2 = (extracted: ApiSpecification): GeneratedApiSpecification => {\n const filters = generateTypeFilters(extracted.types)\n const sortings = generateTypeSortings(extracted.types)\n const queries = generateTypeQueries(\n extracted.types,\n sortings.filter((node): node is InputObjectType => node.kind === 'InputObject'),\n )\n\n return {\n generation: 'gen2',\n interfaces: extracted.interfaces,\n queries,\n types: [...stripInternalMeta(extracted.types), ...filters, ...sortings],\n }\n}\n\nexport default gen2\n"],"names":["stripInternalMeta","generateTypeFilters","generateTypeQueries","generateTypeSortings","gen2","extracted","filters","types","sortings","queries","filter","node","kind","generation","interfaces"],"mappings":"AAAA,SAAQA,iBAAiB,QAAO,gBAAe;AAM/C,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D,MAAMC,OAAO,CAACC;IACZ,MAAMC,UAAUL,oBAAoBI,UAAUE,KAAK;IACnD,MAAMC,WAAWL,qBAAqBE,UAAUE,KAAK;IACrD,MAAME,UAAUP,oBACdG,UAAUE,KAAK,EACfC,SAASE,MAAM,CAAC,CAACC,OAAkCA,KAAKC,IAAI,KAAK;IAGnE,OAAO;QACLC,YAAY;QACZC,YAAYT,UAAUS,UAAU;QAChCL;QACAF,OAAO;eAAIP,kBAAkBK,UAAUE,KAAK;eAAMD;eAAYE;SAAS;IACzE;AACF;AAEA,eAAeJ,KAAI"}
@@ -1,6 +1,5 @@
1
1
  import upperFirst from 'lodash-es/upperFirst.js';
2
2
  import { isDocumentType, isUnion } from '../helpers.js';
3
- import { internal } from '../types.js';
4
3
  import { getFilterFieldName } from './utils.js';
5
4
  export function generateTypeQueries(types, sortings, options) {
6
5
  const { filterSuffix } = options || {};
@@ -96,8 +95,8 @@ export function generateTypeQueries(types, sortings, options) {
96
95
  return queries;
97
96
  }
98
97
  function getDeprecation(type) {
99
- return type[internal]?.deprecationReason ? {
100
- deprecationReason: type[internal].deprecationReason
98
+ return type._internal?.deprecationReason ? {
99
+ deprecationReason: type._internal.deprecationReason
101
100
  } : {};
102
101
  }
103
102
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/graphql/gen3/generateTypeQueries.ts"],"sourcesContent":["import upperFirst from 'lodash-es/upperFirst.js'\n\nimport {isDocumentType, isUnion} from '../helpers.js'\nimport {\n type ApiCustomizationOptions,\n type ConvertedType,\n type ConvertedUnion,\n type Deprecation,\n type InputObjectType,\n internal,\n type QueryDefinition,\n} from '../types.js'\nimport {getFilterFieldName} from './utils.js'\n\nexport function generateTypeQueries(\n types: (ConvertedType | ConvertedUnion)[],\n sortings: InputObjectType[],\n options?: ApiCustomizationOptions,\n): QueryDefinition[] {\n const {filterSuffix} = options || {}\n const queries: QueryDefinition[] = []\n const documentTypes = types.filter((type) => isDocumentType(type))\n\n const documentTypeNames = documentTypes.map((docType) =>\n JSON.stringify(docType.originalName || docType.name),\n )\n const documentsFilter = `_type in [${documentTypeNames.join(', ')}]`\n\n const documentInterface = types.find((type) => type.name === 'Document')\n if (!documentInterface || isUnion(documentInterface)) {\n throw new Error('Failed to find document interface')\n }\n\n const queryable = [...documentTypes, documentInterface]\n const isSortable = (type: ConvertedType) =>\n sortings.some((sorting) => sorting.name === `${type.name}Sorting`)\n\n // Single ID-based result lookup queries\n for (const type of queryable) {\n queries.push({\n args: [\n {\n description: `${type.name} document ID`,\n isNullable: false,\n name: 'id',\n type: 'ID',\n },\n ],\n constraints: [\n {\n comparator: 'eq',\n field: '_id',\n value: {argName: 'id', kind: 'argumentValue'},\n },\n ],\n fieldName: type.name,\n type: type.name,\n ...getDeprecation(type),\n })\n }\n\n // Fetch all of type\n for (const type of queryable) {\n const sorting: QueryDefinition['args'] = []\n if (isSortable(type)) {\n sorting.push({\n name: 'sort',\n type: {\n children: {\n isNullable: false,\n type: `${type.name}Sorting`,\n },\n isNullable: true,\n kind: 'List',\n },\n })\n }\n\n queries.push({\n args: [\n {\n isFieldFilter: true,\n name: 'where',\n type: getFilterFieldName(type.name, filterSuffix),\n },\n ...sorting,\n {\n description: 'Max documents to return',\n isFieldFilter: false,\n name: 'limit',\n type: 'Int',\n },\n {\n description: 'Offset at which to start returning documents from',\n isFieldFilter: false,\n name: 'offset',\n type: 'Int',\n },\n ],\n fieldName: `all${upperFirst(type.name)}`,\n filter:\n type.name === 'Document' && type.kind === 'Interface'\n ? documentsFilter\n : `_type == ${JSON.stringify(type.originalName || type.name)}`,\n type: {\n children: {isNullable: false, type: type.name},\n isNullable: false,\n kind: 'List',\n },\n ...getDeprecation(type),\n })\n }\n\n return queries\n}\n\nfunction getDeprecation(type: ConvertedType): Partial<Deprecation> {\n return type[internal]?.deprecationReason\n ? {\n deprecationReason: type[internal].deprecationReason,\n }\n : {}\n}\n"],"names":["upperFirst","isDocumentType","isUnion","internal","getFilterFieldName","generateTypeQueries","types","sortings","options","filterSuffix","queries","documentTypes","filter","type","documentTypeNames","map","docType","JSON","stringify","originalName","name","documentsFilter","join","documentInterface","find","Error","queryable","isSortable","some","sorting","push","args","description","isNullable","constraints","comparator","field","value","argName","kind","fieldName","getDeprecation","children","isFieldFilter","deprecationReason"],"mappings":"AAAA,OAAOA,gBAAgB,0BAAyB;AAEhD,SAAQC,cAAc,EAAEC,OAAO,QAAO,gBAAe;AACrD,SAMEC,QAAQ,QAEH,cAAa;AACpB,SAAQC,kBAAkB,QAAO,aAAY;AAE7C,OAAO,SAASC,oBACdC,KAAyC,EACzCC,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oBACJ6B,UAAU;wBACRT,YAAY;wBACZpB,MAAM,GAAGA,KAAKO,IAAI,CAAC,OAAO,CAAC;oBAC7B;oBACAa,YAAY;oBACZM,MAAM;gBACR;YACF;QACF;QAEA7B,QAAQoB,IAAI,CAAC;YACXC,MAAM;gBACJ;oBACEY,eAAe;oBACfvB,MAAM;oBACNP,MAAMT,mBAAmBS,KAAKO,IAAI,EAAEX;gBACtC;mBACGoB;gBACH;oBACEG,aAAa;oBACbW,eAAe;oBACfvB,MAAM;oBACNP,MAAM;gBACR;gBACA;oBACEmB,aAAa;oBACbW,eAAe;oBACfvB,MAAM;oBACNP,MAAM;gBACR;aACD;YACD2B,WAAW,CAAC,GAAG,EAAExC,WAAWa,KAAKO,IAAI,GAAG;YACxCR,QACEC,KAAKO,IAAI,KAAK,cAAcP,KAAK0B,IAAI,KAAK,cACtClB,kBACA,CAAC,SAAS,EAAEJ,KAAKC,SAAS,CAACL,KAAKM,YAAY,IAAIN,KAAKO,IAAI,GAAG;YAClEP,MAAM;gBACJ6B,UAAU;oBAACT,YAAY;oBAAOpB,MAAMA,KAAKO,IAAI;gBAAA;gBAC7Ca,YAAY;gBACZM,MAAM;YACR;YACA,GAAGE,eAAe5B,KAAK;QACzB;IACF;IAEA,OAAOH;AACT;AAEA,SAAS+B,eAAe5B,IAAmB;IACzC,OAAOA,IAAI,CAACV,SAAS,EAAEyC,oBACnB;QACEA,mBAAmB/B,IAAI,CAACV,SAAS,CAACyC,iBAAiB;IACrD,IACA,CAAC;AACP"}
1
+ {"version":3,"sources":["../../../../src/actions/graphql/gen3/generateTypeQueries.ts"],"sourcesContent":["import upperFirst from 'lodash-es/upperFirst.js'\n\nimport {isDocumentType, isUnion} from '../helpers.js'\nimport {\n type ApiCustomizationOptions,\n type ConvertedType,\n type ConvertedUnion,\n type Deprecation,\n type InputObjectType,\n type QueryDefinition,\n} from '../types.js'\nimport {getFilterFieldName} from './utils.js'\n\nexport function generateTypeQueries(\n types: (ConvertedType | ConvertedUnion)[],\n sortings: InputObjectType[],\n options?: ApiCustomizationOptions,\n): QueryDefinition[] {\n const {filterSuffix} = options || {}\n const queries: QueryDefinition[] = []\n const documentTypes = types.filter((type) => isDocumentType(type))\n\n const documentTypeNames = documentTypes.map((docType) =>\n JSON.stringify(docType.originalName || docType.name),\n )\n const documentsFilter = `_type in [${documentTypeNames.join(', ')}]`\n\n const documentInterface = types.find((type) => type.name === 'Document')\n if (!documentInterface || isUnion(documentInterface)) {\n throw new Error('Failed to find document interface')\n }\n\n const queryable = [...documentTypes, documentInterface]\n const isSortable = (type: ConvertedType) =>\n sortings.some((sorting) => sorting.name === `${type.name}Sorting`)\n\n // Single ID-based result lookup queries\n for (const type of queryable) {\n queries.push({\n args: [\n {\n description: `${type.name} document ID`,\n isNullable: false,\n name: 'id',\n type: 'ID',\n },\n ],\n constraints: [\n {\n comparator: 'eq',\n field: '_id',\n value: {argName: 'id', kind: 'argumentValue'},\n },\n ],\n fieldName: type.name,\n type: type.name,\n ...getDeprecation(type),\n })\n }\n\n // Fetch all of type\n for (const type of queryable) {\n const sorting: QueryDefinition['args'] = []\n if (isSortable(type)) {\n sorting.push({\n name: 'sort',\n type: {\n children: {\n isNullable: false,\n type: `${type.name}Sorting`,\n },\n isNullable: true,\n kind: 'List',\n },\n })\n }\n\n queries.push({\n args: [\n {\n isFieldFilter: true,\n name: 'where',\n type: getFilterFieldName(type.name, filterSuffix),\n },\n ...sorting,\n {\n description: 'Max documents to return',\n isFieldFilter: false,\n name: 'limit',\n type: 'Int',\n },\n {\n description: 'Offset at which to start returning documents from',\n isFieldFilter: false,\n name: 'offset',\n type: 'Int',\n },\n ],\n fieldName: `all${upperFirst(type.name)}`,\n filter:\n type.name === 'Document' && type.kind === 'Interface'\n ? documentsFilter\n : `_type == ${JSON.stringify(type.originalName || type.name)}`,\n type: {\n children: {isNullable: false, type: type.name},\n isNullable: false,\n kind: 'List',\n },\n ...getDeprecation(type),\n })\n }\n\n return queries\n}\n\nfunction getDeprecation(type: ConvertedType): Partial<Deprecation> {\n return type._internal?.deprecationReason\n ? {\n deprecationReason: type._internal.deprecationReason,\n }\n : {}\n}\n"],"names":["upperFirst","isDocumentType","isUnion","getFilterFieldName","generateTypeQueries","types","sortings","options","filterSuffix","queries","documentTypes","filter","type","documentTypeNames","map","docType","JSON","stringify","originalName","name","documentsFilter","join","documentInterface","find","Error","queryable","isSortable","some","sorting","push","args","description","isNullable","constraints","comparator","field","value","argName","kind","fieldName","getDeprecation","children","isFieldFilter","_internal","deprecationReason"],"mappings":"AAAA,OAAOA,gBAAgB,0BAAyB;AAEhD,SAAQC,cAAc,EAAEC,OAAO,QAAO,gBAAe;AASrD,SAAQC,kBAAkB,QAAO,aAAY;AAE7C,OAAO,SAASC,oBACdC,KAAyC,EACzCC,QAA2B,EAC3BC,OAAiC;IAEjC,MAAM,EAACC,YAAY,EAAC,GAAGD,WAAW,CAAC;IACnC,MAAME,UAA6B,EAAE;IACrC,MAAMC,gBAAgBL,MAAMM,MAAM,CAAC,CAACC,OAASX,eAAeW;IAE5D,MAAMC,oBAAoBH,cAAcI,GAAG,CAAC,CAACC,UAC3CC,KAAKC,SAAS,CAACF,QAAQG,YAAY,IAAIH,QAAQI,IAAI;IAErD,MAAMC,kBAAkB,CAAC,UAAU,EAAEP,kBAAkBQ,IAAI,CAAC,MAAM,CAAC,CAAC;IAEpE,MAAMC,oBAAoBjB,MAAMkB,IAAI,CAAC,CAACX,OAASA,KAAKO,IAAI,KAAK;IAC7D,IAAI,CAACG,qBAAqBpB,QAAQoB,oBAAoB;QACpD,MAAM,IAAIE,MAAM;IAClB;IAEA,MAAMC,YAAY;WAAIf;QAAeY;KAAkB;IACvD,MAAMI,aAAa,CAACd,OAClBN,SAASqB,IAAI,CAAC,CAACC,UAAYA,QAAQT,IAAI,KAAK,GAAGP,KAAKO,IAAI,CAAC,OAAO,CAAC;IAEnE,wCAAwC;IACxC,KAAK,MAAMP,QAAQa,UAAW;QAC5BhB,QAAQoB,IAAI,CAAC;Y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B,KAAK;QACzB;IACF;IAEA,OAAOH;AACT;AAEA,SAAS+B,eAAe5B,IAAmB;IACzC,OAAOA,KAAK+B,SAAS,EAAEC,oBACnB;QACEA,mBAAmBhC,KAAK+B,SAAS,CAACC,iBAAiB;IACrD,IACA,CAAC;AACP"}
@@ -1,4 +1,4 @@
1
- import { isUnion } from '../helpers.js';
1
+ import { isUnion, stripInternalMeta } from '../helpers.js';
2
2
  import { generateTypeFilters } from './generateTypeFilters.js';
3
3
  import { generateTypeQueries } from './generateTypeQueries.js';
4
4
  import { generateTypeSortings } from './generateTypeSortings.js';
@@ -14,16 +14,15 @@ const gen3 = (extracted, options)=>{
14
14
  const filters = generateTypeFilters(types, options);
15
15
  const sortings = generateTypeSortings(types);
16
16
  const queries = generateTypeQueries(types, sortings.filter((node)=>node.kind === 'InputObject'), options);
17
- const graphqlTypes = [
18
- ...extracted.types,
19
- ...filters,
20
- ...sortings
21
- ];
22
17
  return {
23
18
  generation: 'gen3',
24
19
  interfaces: extracted.interfaces,
25
20
  queries,
26
- types: graphqlTypes
21
+ types: [
22
+ ...stripInternalMeta(extracted.types),
23
+ ...filters,
24
+ ...sortings
25
+ ]
27
26
  };
28
27
  };
29
28
  export default gen3;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/actions/graphql/gen3/index.ts"],"sourcesContent":["import {isUnion} from '../helpers.js'\nimport {\n type ApiCustomizationOptions,\n type ApiSpecification,\n type ConvertedType,\n type GeneratedApiSpecification,\n type InputObjectType,\n} from '../types.js'\nimport {generateTypeFilters} from './generateTypeFilters.js'\nimport {generateTypeQueries} from './generateTypeQueries.js'\nimport {generateTypeSortings} from './generateTypeSortings.js'\n\nconst gen3 = (\n extracted: ApiSpecification,\n options?: ApiCustomizationOptions,\n): GeneratedApiSpecification => {\n const documentInterface = extracted.interfaces.find((iface) => iface.name === 'Document')\n if (!documentInterface || isUnion(documentInterface)) {\n throw new Error('Failed to find document interface')\n }\n\n const types = [...extracted.types, documentInterface as ConvertedType]\n\n const filters = generateTypeFilters(types, options)\n const sortings = generateTypeSortings(types)\n const queries = generateTypeQueries(\n types,\n sortings.filter((node): node is InputObjectType => node.kind === 'InputObject'),\n options,\n )\n const graphqlTypes = [...extracted.types, ...filters, ...sortings]\n\n return {generation: 'gen3', interfaces: extracted.interfaces, queries, types: graphqlTypes}\n}\n\nexport default gen3\n"],"names":["isUnion","generateTypeFilters","generateTypeQueries","generateTypeSortings","gen3","extracted","options","documentInterface","interfaces","find","iface","name","Error","types","filters","sortings","queries","filter","node","kind","graphqlTypes","generation"],"mappings":"AAAA,SAAQA,OAAO,QAAO,gBAAe;AAQrC,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D,MAAMC,OAAO,CACXC,WACAC;IAEA,MAAMC,oBAAoBF,UAAUG,UAAU,CAACC,IAAI,CAAC,CAACC,QAAUA,MAAMC,IAAI,KAAK;IAC9E,IAAI,CAACJ,qBAAqBP,QAAQO,oBAAoB;QACpD,MAAM,IAAIK,MAAM;IAClB;IAEA,MAAMC,QAAQ;WAAIR,UAAUQ,KAAK;QAAEN;KAAmC;IAEtE,MAAMO,UAAUb,oBAAoBY,OAAOP;IAC3C,MAAMS,WAAWZ,qBAAqBU;IACtC,MAAMG,UAAUd,oBACdW,OACAE,SAASE,MAAM,CAAC,CAACC,OAAkCA,KAAKC,IAAI,KAAK,gBACjEb;IAEF,MAAMc,eAAe;WAAIf,UAAUQ,KAAK;WAAKC;WAAYC;KAAS;IAElE,OAAO;QAACM,YAAY;QAAQb,YAAYH,UAAUG,UAAU;QAAEQ;QAASH,OAAOO;IAAY;AAC5F;AAEA,eAAehB,KAAI"}
1
+ {"version":3,"sources":["../../../../src/actions/graphql/gen3/index.ts"],"sourcesContent":["import {isUnion, stripInternalMeta} from '../helpers.js'\nimport {\n type ApiCustomizationOptions,\n type ApiSpecification,\n type ConvertedType,\n type GeneratedApiSpecification,\n type InputObjectType,\n} from '../types.js'\nimport {generateTypeFilters} from './generateTypeFilters.js'\nimport {generateTypeQueries} from './generateTypeQueries.js'\nimport {generateTypeSortings} from './generateTypeSortings.js'\n\nconst gen3 = (\n extracted: ApiSpecification,\n options?: ApiCustomizationOptions,\n): GeneratedApiSpecification => {\n const documentInterface = extracted.interfaces.find((iface) => iface.name === 'Document')\n if (!documentInterface || isUnion(documentInterface)) {\n throw new Error('Failed to find document interface')\n }\n\n const types = [...extracted.types, documentInterface as ConvertedType]\n\n const filters = generateTypeFilters(types, options)\n const sortings = generateTypeSortings(types)\n const queries = generateTypeQueries(\n types,\n sortings.filter((node): node is InputObjectType => node.kind === 'InputObject'),\n options,\n )\n\n return {\n generation: 'gen3',\n interfaces: extracted.interfaces,\n queries,\n types: [...stripInternalMeta(extracted.types), ...filters, ...sortings],\n }\n}\n\nexport default gen3\n"],"names":["isUnion","stripInternalMeta","generateTypeFilters","generateTypeQueries","generateTypeSortings","gen3","extracted","options","documentInterface","interfaces","find","iface","name","Error","types","filters","sortings","queries","filter","node","kind","generation"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,iBAAiB,QAAO,gBAAe;AAQxD,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,mBAAmB,QAAO,2BAA0B;AAC5D,SAAQC,oBAAoB,QAAO,4BAA2B;AAE9D,MAAMC,OAAO,CACXC,WACAC;IAEA,MAAMC,oBAAoBF,UAAUG,UAAU,CAACC,IAAI,CAAC,CAACC,QAAUA,MAAMC,IAAI,KAAK;IAC9E,IAAI,CAACJ,qBAAqBR,QAAQQ,oBAAoB;QACpD,MAAM,IAAIK,MAAM;IAClB;IAEA,MAAMC,QAAQ;WAAIR,UAAUQ,KAAK;QAAEN;KAAmC;IAEtE,MAAMO,UAAUb,oBAAoBY,OAAOP;IAC3C,MAAMS,WAAWZ,qBAAqBU;IACtC,MAAMG,UAAUd,oBACdW,OACAE,SAASE,MAAM,CAAC,CAACC,OAAkCA,KAAKC,IAAI,KAAK,gBACjEb;IAGF,OAAO;QACLc,YAAY;QACZZ,YAAYH,UAAUG,UAAU;QAChCQ;QACAH,OAAO;eAAIb,kBAAkBK,UAAUQ,KAAK;eAAMC;eAAYC;SAAS;IACzE;AACF;AAEA,eAAeX,KAAI"}
@@ -1,46 +1,23 @@
1
1
  import { isMainThread } from 'node:worker_threads';
2
- import { getCliConfig, getStudioConfig, promisifyWorker, resolveLocalPackage } from '@sanity/cli-core';
2
+ import { findStudioConfigPath, getCliConfig, studioWorkerTask } from '@sanity/cli-core';
3
3
  export async function getGraphQLAPIs(workDir) {
4
4
  if (!isMainThread) {
5
5
  throw new Error('getGraphQLAPIs() must be called from the main thread');
6
6
  }
7
- // Resolve `sanity` local to the project in order to avoid using incompatible versions, and to avoid circular dependencies
8
- const { createSchema } = await resolveLocalPackage('sanity', workDir);
9
- const defaultSchema = createSchema({
10
- name: 'default',
11
- types: []
12
- });
13
- const defaultTypes = defaultSchema.getTypeNames();
14
- const isCustomType = (type)=>!defaultTypes.includes(type.name);
15
- const apis = await getApisWithSchemaTypes(workDir);
16
- const resolved = apis.map(({ schemaTypes, ...api })=>({
17
- schema: createSchema({
18
- name: 'default',
19
- types: schemaTypes.filter((element)=>isCustomType(element))
20
- }),
21
- ...api
22
- }));
23
- return resolved;
24
- }
25
- async function getApisWithSchemaTypes(workDir) {
26
- const cliConfig = await getCliConfig(workDir);
27
- const workspaces = await getStudioConfig(workDir, {
28
- resolvePlugins: true
29
- });
30
- return promisifyWorker(new URL('getGraphQLAPIs.worker.js', import.meta.url), {
31
- env: process.env,
7
+ const [cliConfig, configPath] = await Promise.all([
8
+ getCliConfig(workDir),
9
+ findStudioConfigPath(workDir)
10
+ ]);
11
+ return studioWorkerTask(new URL('getGraphQLAPIs.worker.js', import.meta.url), {
12
+ name: 'getGraphQLAPIs',
13
+ studioRootPath: workDir,
32
14
  workerData: {
33
- cliConfig: extractGraphQLConfig(cliConfig),
34
- workDir,
35
- workspaces
15
+ cliConfig: {
16
+ graphql: cliConfig.graphql
17
+ },
18
+ configPath
36
19
  }
37
20
  });
38
21
  }
39
- function extractGraphQLConfig(config) {
40
- return structuredClone({
41
- api: config.api,
42
- graphql: config.graphql
43
- });
44
- }
45
22
 
46
23
  //# sourceMappingURL=getGraphQLAPIs.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/actions/graphql/getGraphQLAPIs.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {\n type CliConfig,\n getCliConfig,\n getStudioConfig,\n promisifyWorker,\n resolveLocalPackage,\n} from '@sanity/cli-core'\n\nimport {\n type ResolvedGraphQLAPI,\n type ResolvedSourceProperties,\n type SchemaDefinitionish,\n type TypeResolvedGraphQLAPI,\n} from './types.js'\n\nexport async function getGraphQLAPIs(workDir: string): Promise<ResolvedGraphQLAPI[]> {\n if (!isMainThread) {\n throw new Error('getGraphQLAPIs() must be called from the main thread')\n }\n\n // Resolve `sanity` local to the project in order to avoid using incompatible versions, and to avoid circular dependencies\n const {createSchema} = await resolveLocalPackage<typeof import('sanity')>('sanity', workDir)\n\n const defaultSchema = createSchema({name: 'default', types: []})\n const defaultTypes = defaultSchema.getTypeNames()\n const isCustomType = (type: SchemaDefinitionish) => !defaultTypes.includes(type.name)\n\n const apis = await getApisWithSchemaTypes(workDir)\n const resolved = apis.map(\n ({schemaTypes, ...api}): ResolvedSourceProperties => ({\n schema: createSchema({\n name: 'default',\n types: schemaTypes.filter((element) => isCustomType(element)),\n }),\n ...api,\n }),\n )\n\n return resolved\n}\n\nasync function getApisWithSchemaTypes(workDir: string): Promise<TypeResolvedGraphQLAPI[]> {\n const cliConfig = await getCliConfig(workDir)\n const workspaces = await getStudioConfig(workDir, {resolvePlugins: true})\n\n return promisifyWorker<TypeResolvedGraphQLAPI[]>(\n new URL('getGraphQLAPIs.worker.js', import.meta.url),\n {\n env: process.env,\n workerData: {\n cliConfig: extractGraphQLConfig(cliConfig),\n workDir,\n workspaces,\n },\n },\n )\n}\n\nfunction extractGraphQLConfig(config: CliConfig) {\n return structuredClone({\n api: config.api,\n graphql: config.graphql,\n })\n}\n"],"names":["isMainThread","getCliConfig","getStudioConfig","promisifyWorker","resolveLocalPackage","getGraphQLAPIs","workDir","Error","createSchema","defaultSchema","name","types","defaultTypes","getTypeNames","isCustomType","type","includes","apis","getApisWithSchemaTypes","resolved","map","schemaTypes","api","schema","filter","element","cliConfig","workspaces","resolvePlugins","URL","url","env","process","workerData","extractGraphQLConfig","config","structuredClone","graphql"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAEEC,YAAY,EACZC,eAAe,EACfC,eAAe,EACfC,mBAAmB,QACd,mBAAkB;AASzB,OAAO,eAAeC,eAAeC,OAAe;IAClD,IAAI,CAACN,cAAc;QACjB,MAAM,IAAIO,MAAM;IAClB;IAEA,0HAA0H;IAC1H,MAAM,EAACC,YAAY,EAAC,GAAG,MAAMJ,oBAA6C,UAAUE;IAEpF,MAAMG,gBAAgBD,aAAa;QAACE,MAAM;QAAWC,OAAO,EAAE;IAAA;IAC9D,MAAMC,eAAeH,cAAcI,YAAY;IAC/C,MAAMC,eAAe,CAACC,OAA8B,CAACH,aAAaI,QAAQ,CAACD,KAAKL,IAAI;IAEpF,MAAMO,OAAO,MAAMC,uBAAuBZ;IAC1C,MAAMa,WAAWF,KAAKG,GAAG,CACvB,CAAC,EAACC,WAAW,EAAE,GAAGC,KAAI,GAAgC,CAAA;YACpDC,QAAQf,aAAa;gBACnBE,MAAM;gBACNC,OAAOU,YAAYG,MAAM,CAAC,CAACC,UAAYX,aAAaW;YACtD;YACA,GAAGH,GAAG;QACR,CAAA;IAGF,OAAOH;AACT;AAEA,eAAeD,uBAAuBZ,OAAe;IACnD,MAAMoB,YAAY,MAAMzB,aAAaK;IACrC,MAAMqB,aAAa,MAAMzB,gBAAgBI,SAAS;QAACsB,gBAAgB;IAAI;IAEvE,OAAOzB,gBACL,IAAI0B,IAAI,4BAA4B,YAAYC,GAAG,GACnD;QACEC,KAAKC,QAAQD,GAAG;QAChBE,YAAY;YACVP,WAAWQ,qBAAqBR;YAChCpB;YACAqB;QACF;IACF;AAEJ;AAEA,SAASO,qBAAqBC,MAAiB;IAC7C,OAAOC,gBAAgB;QACrBd,KAAKa,OAAOb,GAAG;QACfe,SAASF,OAAOE,OAAO;IACzB;AACF"}
1
+ {"version":3,"sources":["../../../src/actions/graphql/getGraphQLAPIs.ts"],"sourcesContent":["import {isMainThread} from 'node:worker_threads'\n\nimport {findStudioConfigPath, getCliConfig, studioWorkerTask} from '@sanity/cli-core'\n\nimport {type ExtractedGraphQLAPI} from './types.js'\n\nexport async function getGraphQLAPIs(workDir: string): Promise<ExtractedGraphQLAPI[]> {\n if (!isMainThread) {\n throw new Error('getGraphQLAPIs() must be called from the main thread')\n }\n\n const [cliConfig, configPath] = await Promise.all([\n getCliConfig(workDir),\n findStudioConfigPath(workDir),\n ])\n\n return studioWorkerTask<ExtractedGraphQLAPI[]>(\n new URL('getGraphQLAPIs.worker.js', import.meta.url),\n {\n name: 'getGraphQLAPIs',\n studioRootPath: workDir,\n workerData: {\n cliConfig: {graphql: cliConfig.graphql},\n configPath,\n },\n },\n )\n}\n"],"names":["isMainThread","findStudioConfigPath","getCliConfig","studioWorkerTask","getGraphQLAPIs","workDir","Error","cliConfig","configPath","Promise","all","URL","url","name","studioRootPath","workerData","graphql"],"mappings":"AAAA,SAAQA,YAAY,QAAO,sBAAqB;AAEhD,SAAQC,oBAAoB,EAAEC,YAAY,EAAEC,gBAAgB,QAAO,mBAAkB;AAIrF,OAAO,eAAeC,eAAeC,OAAe;IAClD,IAAI,CAACL,cAAc;QACjB,MAAM,IAAIM,MAAM;IAClB;IAEA,MAAM,CAACC,WAAWC,WAAW,GAAG,MAAMC,QAAQC,GAAG,CAAC;QAChDR,aAAaG;QACbJ,qBAAqBI;KACtB;IAED,OAAOF,iBACL,IAAIQ,IAAI,4BAA4B,YAAYC,GAAG,GACnD;QACEC,MAAM;QACNC,gBAAgBT;QAChBU,YAAY;YACVR,WAAW;gBAACS,SAAST,UAAUS,OAAO;YAAA;YACtCR;QACF;IACF;AAEJ"}