@sanity-codegen/core
Advanced tools
+6
-0
@@ -6,2 +6,8 @@ # Change Log | ||
| # [1.0.0-alpha.41](https://github.com/ricokahler/sanity-codegen/compare/v1.0.0-alpha.40...v1.0.0-alpha.41) (2023-01-23) | ||
| ### Features | ||
| - support multiple workspaces ([#282](https://github.com/ricokahler/sanity-codegen/issues/282)) ([02c1efd](https://github.com/ricokahler/sanity-codegen/commit/02c1efd3cf38430e0c0afb2f1b35ffd051d8b134)) | ||
| # [1.0.0-alpha.38](https://github.com/ricokahler/sanity-codegen/compare/v1.0.0-alpha.37...v1.0.0-alpha.38) (2023-01-21) | ||
@@ -8,0 +14,0 @@ |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"generate-query-types.d.ts","sourceRoot":"","sources":["../src/generate-query-types.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAMlC,UAAU,yBAAyB;IACjC,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;IAC1C,aAAa,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;KAAE,CAAC;IAC5C,gBAAgB,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;CAChC;AAED,wBAAgB,kBAAkB,CAAC,EACjC,gBAAgB,EAChB,gBAAgB,EAChB,GAAG,OAAO,EACX,EAAE,yBAAyB;;;;;;;EAqI3B"} | ||
| {"version":3,"file":"generate-query-types.d.ts","sourceRoot":"","sources":["../src/generate-query-types.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAOlC,UAAU,yBAAyB;IACjC,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;IAC1C,aAAa,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;KAAE,CAAC;IAC5C,gBAAgB,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;CAChC;AAED,wBAAgB,kBAAkB,CAAC,EACjC,gBAAgB,EAChB,gBAAgB,EAChB,GAAG,OAAO,EACX,EAAE,yBAAyB;;;;;;;EA6J3B"} |
@@ -11,2 +11,3 @@ "use strict"; | ||
| var _transformStructureToTs = require("./transform-structure-to-ts"); | ||
| var _defaultGenerateTypeName = require("./default-generate-type-name"); | ||
| var _utils = require("./utils"); | ||
@@ -20,2 +21,4 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
| }) { | ||
| // TODO: allow customizing this? | ||
| const workspaceIdentifier = (0, _defaultGenerateTypeName.defaultGenerateTypeName)(normalizedSchema.name); | ||
| const { | ||
@@ -52,7 +55,7 @@ logger = _utils.simpleLogger | ||
| ...declarations, | ||
| [structure.hash]: t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier('Query'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier(queryKey), undefined, tsType)]))) | ||
| [structure.hash]: t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier(workspaceIdentifier), t.tsModuleDeclaration(t.identifier('Query'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier(queryKey), undefined, tsType)])))) | ||
| }, | ||
| substitutions: { | ||
| ...substitutions, | ||
| [structure.hash]: t.tsTypeReference(t.tsQualifiedName(t.tsQualifiedName(t.identifier('Sanity'), t.identifier('Query')), t.identifier(queryKey))) | ||
| [structure.hash]: t.tsTypeReference(t.tsQualifiedName(t.tsQualifiedName(t.tsQualifiedName(t.identifier('Sanity'), t.identifier(workspaceIdentifier)), t.identifier('Query')), t.identifier(queryKey))) | ||
| } | ||
@@ -69,3 +72,3 @@ }; | ||
| } else { | ||
| acc[`${hash}_${queryKey}`] = t.tsTypeReference(t.tsQualifiedName(t.tsQualifiedName(t.identifier('Sanity'), t.identifier('Query')), t.identifier(queryKey))); | ||
| acc[`${hash}_${queryKey}`] = t.tsTypeReference(t.tsQualifiedName(t.tsQualifiedName(t.tsQualifiedName(t.identifier('Sanity'), t.identifier(workspaceIdentifier)), t.identifier('Query')), t.identifier(queryKey))); | ||
| } | ||
@@ -84,3 +87,3 @@ } | ||
| } else { | ||
| acc[`${hash}_${queryKey}`] = t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier('Query'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier(queryKey), undefined, substitutions[structure.hash])]))); | ||
| acc[`${hash}_${queryKey}`] = t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier(workspaceIdentifier), t.tsModuleDeclaration(t.identifier('Query'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier(queryKey), undefined, substitutions[structure.hash])])))); | ||
| } | ||
@@ -94,5 +97,5 @@ } | ||
| ...declarations, | ||
| _ClientConfig: t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier('Client'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier('Config'), undefined, t.tsTypeLiteral(Object.entries(queryKeys).map(([queryKey, hash]) => { | ||
| _ClientConfig: t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier(workspaceIdentifier), t.tsModuleDeclaration(t.identifier('Client'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier('Config'), undefined, t.tsTypeLiteral(Object.entries(queryKeys).map(([queryKey, hash]) => { | ||
| return t.tsPropertySignature(t.identifier(queryKey), t.tsTypeAnnotation(substitutions[`${hash}_${queryKey}`] || substitutions[hash])); | ||
| })))]))) | ||
| })))])))) | ||
| }, | ||
@@ -99,0 +102,0 @@ substitutions |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"generate-schema-types.d.ts","sourceRoot":"","sources":["../src/generate-schema-types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,UAAU,0BAA0B;IAClC,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAClC,gBAAgB,GACjB,EAAE,0BAA0B;;;;;;;EA2D5B"} | ||
| {"version":3,"file":"generate-schema-types.d.ts","sourceRoot":"","sources":["../src/generate-schema-types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,UAAU,0BAA0B;IAClC,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED,wBAAgB,mBAAmB,CAAC,EAClC,gBAAgB,GACjB,EAAE,0BAA0B;;;;;;;EAuE5B"} |
@@ -16,2 +16,4 @@ "use strict"; | ||
| }) { | ||
| // TODO: allow customizing this? | ||
| const workspaceIdentifier = (0, _defaultGenerateTypeName.defaultGenerateTypeName)(normalizedSchema.name); | ||
| const topLevelSchemaNodes = [...normalizedSchema.documents, ...normalizedSchema.registeredTypes]; | ||
@@ -38,7 +40,7 @@ const topLevelTypes = topLevelSchemaNodes.map(node => { | ||
| ...declarations, | ||
| [structure.hash]: t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier('Schema'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier(identifier), undefined, tsType)]))) | ||
| [structure.hash]: t.tsModuleDeclaration(t.identifier('Sanity'), t.tsModuleDeclaration(t.identifier(workspaceIdentifier), t.tsModuleDeclaration(t.identifier('Schema'), t.tsModuleBlock([t.tsTypeAliasDeclaration(t.identifier(identifier), undefined, tsType)])))) | ||
| }, | ||
| substitutions: { | ||
| ...substitutions, | ||
| [structure.hash]: t.tsTypeReference(t.tsQualifiedName(t.tsQualifiedName(t.identifier('Sanity'), t.identifier('Schema')), t.identifier(identifier))) | ||
| [structure.hash]: t.tsTypeReference(t.tsQualifiedName(t.tsQualifiedName(t.tsQualifiedName(t.identifier('Sanity'), t.identifier(workspaceIdentifier)), t.identifier('Schema')), t.identifier(identifier))) | ||
| } | ||
@@ -45,0 +47,0 @@ }; |
@@ -18,6 +18,11 @@ /// <reference types="@sanity-codegen/types/extractor" /> | ||
| /** | ||
| * An extracted and normalized schema result from the | ||
| * `@sanity-codegen/extractor` package. | ||
| * An array of extracted and normalized schema results from the | ||
| * `normalizeSchema` function | ||
| */ | ||
| normalizedSchema: Sanity.SchemaDef.Schema; | ||
| normalizedSchemas: Sanity.SchemaDef.Schema[]; | ||
| /** | ||
| * Ignores workspace schemas and excludes them from codegen. Useful if you have a | ||
| * workspace that mirrors another one in schema (e.g. for staging env) | ||
| */ | ||
| ignoreSchemas?: string[]; | ||
| } | ||
@@ -31,3 +36,3 @@ /** | ||
| */ | ||
| export declare function generateTypes({ prettierResolveConfigOptions, prettierResolveConfigPath, normalizedSchema, ...pluckOptions }: GenerateTypesOptions): Promise<string>; | ||
| export declare function generateTypes({ prettierResolveConfigOptions, prettierResolveConfigPath, normalizedSchemas, ignoreSchemas, ...pluckOptions }: GenerateTypesOptions): Promise<string>; | ||
| //# sourceMappingURL=generate-types.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../src/generate-types.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,UAAU,CAAC;AAEvE,OAAO,EAEL,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAKjC,MAAM,WAAW,oBAAqB,SAAQ,yBAAyB;IACrE;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,oBAAoB,CAAC;IACpD;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,EAClC,4BAA4B,EAC5B,yBAAyB,EACzB,gBAAgB,EAChB,GAAG,YAAY,EAChB,EAAE,oBAAoB,mBAuDtB"} | ||
| {"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../src/generate-types.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAyB,MAAM,UAAU,CAAC;AAEvE,OAAO,EAEL,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAcjC,MAAM,WAAW,oBAAqB,SAAQ,yBAAyB;IACrE;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;OAIG;IACH,4BAA4B,CAAC,EAAE,oBAAoB,CAAC;IACpD;;;OAGG;IACH,iBAAiB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IAC7C;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,EAClC,4BAA4B,EAC5B,yBAAyB,EACzB,iBAAiB,EACjB,aAAkB,EAClB,GAAG,YAAY,EAChB,EAAE,oBAAoB,mBA8FtB"} |
+48
-20
@@ -14,2 +14,3 @@ "use strict"; | ||
| function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
| const logLevels = ['success', 'error', 'warn', 'info', 'verbose', 'debug']; | ||
| /** | ||
@@ -25,3 +26,4 @@ * Given a selection of filenames, this will pluck matching GROQ queries | ||
| prettierResolveConfigPath, | ||
| normalizedSchema, | ||
| normalizedSchemas, | ||
| ignoreSchemas = [], | ||
| ...pluckOptions | ||
@@ -32,24 +34,50 @@ }) { | ||
| } = pluckOptions; | ||
| logger.verbose('Generating types from your schema…'); | ||
| const schemaTypes = (0, _generateSchemaTypes.generateSchemaTypes)({ | ||
| normalizedSchema | ||
| }); | ||
| const schemaCount = Object.keys(schemaTypes.declarations).length; | ||
| logger[schemaCount ? 'success' : 'warn'](`Converted ${schemaCount} schema definition${schemaCount === 1 ? '' : 's'} to TypeScript`); | ||
| logger.verbose('Plucking queries from files…'); | ||
| const extractedQueries = await (0, _pluckGroqFromFiles.pluckGroqFromFiles)(pluckOptions); | ||
| logger.verbose('Converting queries to typescript…'); | ||
| const queryTypes = (0, _generateQueryTypes.generateQueryTypes)({ | ||
| normalizedSchema, | ||
| substitutions: schemaTypes.substitutions, | ||
| extractedQueries | ||
| }); | ||
| const queryCount = Object.keys(queryTypes.declarations).length; | ||
| logger[queryCount ? 'success' : 'success'](`Converted ${queryCount} ${queryCount === 1 ? 'query' : 'queries'} to TypeScript`); | ||
| const declarations = {}; | ||
| const substitutions = {}; | ||
| const filteredSchemas = normalizedSchemas.filter(schema => !ignoreSchemas.includes(schema.name)); | ||
| for (let i = 0; i < filteredSchemas.length; i++) { | ||
| const normalizedSchema = filteredSchemas[i]; | ||
| const wrappedLogger = logLevels.reduce((acc, next) => { | ||
| const prefix = `[${normalizedSchema.name}]${normalizedSchemas.length > 1 ? ` (${i + 1}/${normalizedSchemas.length})` : ''}`; | ||
| acc[next] = message => logger[next](`${prefix} ${message}`); | ||
| return acc; | ||
| }, { | ||
| ...logger | ||
| }); | ||
| wrappedLogger.verbose(`Generating types for workspace \`${normalizedSchema.name}\``); | ||
| const schemaTypes = (0, _generateSchemaTypes.generateSchemaTypes)({ | ||
| normalizedSchema | ||
| }); | ||
| const schemaCount = Object.keys(schemaTypes.declarations).length; | ||
| wrappedLogger[schemaCount ? 'success' : 'warn'](`Converted ${schemaCount} schema definition${schemaCount === 1 ? '' : 's'} to TypeScript`); | ||
| for (const [key, value] of Object.entries(schemaTypes.declarations)) { | ||
| declarations[key] = value; | ||
| } | ||
| for (const [key, value] of Object.entries(schemaTypes.substitutions)) { | ||
| substitutions[key] = value; | ||
| } | ||
| wrappedLogger.verbose(`Plucking queries from files…`); | ||
| const extractedQueries = await (0, _pluckGroqFromFiles.pluckGroqFromFiles)({ | ||
| ...pluckOptions, | ||
| logger: wrappedLogger | ||
| }); | ||
| wrappedLogger.verbose(`Converting queries to typescript…`); | ||
| const queryTypes = (0, _generateQueryTypes.generateQueryTypes)({ | ||
| normalizedSchema, | ||
| substitutions: schemaTypes.substitutions, | ||
| extractedQueries | ||
| }); | ||
| const queryCount = Object.keys(queryTypes.declarations).length; | ||
| wrappedLogger[queryCount ? 'success' : 'success'](`Converted ${queryCount} ${queryCount === 1 ? 'query' : 'queries'} to TypeScript`); | ||
| for (const [key, value] of Object.entries(queryTypes.declarations)) { | ||
| declarations[key] = value; | ||
| } | ||
| for (const [key, value] of Object.entries(queryTypes.substitutions)) { | ||
| substitutions[key] = value; | ||
| } | ||
| } | ||
| const finalCodegen = ` | ||
| /// <reference types="@sanity-codegen/types" /> | ||
| ${Object.values(schemaTypes.declarations).map(declaration => (0, _generator.default)(declaration).code).sort((a, b) => a.localeCompare(b, 'en')).join('\n')} | ||
| ${Object.values(queryTypes.declarations).map(declaration => (0, _generator.default)(declaration).code).sort((a, b) => a.localeCompare(b, 'en')).join('\n')} | ||
| ${Object.values(declarations).map(declaration => (0, _generator.default)(declaration).code).sort((a, b) => a.localeCompare(b, 'en')).join('\n')} | ||
| `; | ||
@@ -56,0 +84,0 @@ const resolvedConfig = prettierResolveConfigPath ? await (0, _prettier.resolveConfig)(prettierResolveConfigPath, prettierResolveConfigOptions) : null; |
| /// <reference types="@sanity-codegen/types/extractor" /> | ||
| export declare class SchemaParseError extends Error { | ||
| } | ||
| export interface SchemaNormalizerOptions { | ||
| /** | ||
| * The name that will be forwarded to the resulting output type | ||
| */ | ||
| name: string; | ||
| /** | ||
| * The raw sanity schema to be normalized | ||
| */ | ||
| types: unknown[]; | ||
| /** | ||
| * Whether or not to include the original node sanity in the output. This will | ||
| * make the `originalNode` property on a schema node be omitted. This is for | ||
| * serialization purposes. | ||
| */ | ||
| omitOriginalNode?: boolean; | ||
| } | ||
| /** | ||
@@ -12,3 +28,3 @@ * Takes in a raw sanity schema and returns a statically typed normalized | ||
| */ | ||
| export declare function schemaNormalizer(types: any[]): Sanity.SchemaDef.Schema; | ||
| export declare function schemaNormalizer({ name, types, omitOriginalNode, }: SchemaNormalizerOptions): Sanity.SchemaDef.Schema; | ||
| //# sourceMappingURL=schema-normalizer.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"schema-normalizer.d.ts","sourceRoot":"","sources":["../src/schema-normalizer.ts"],"names":[],"mappings":";AAGA,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAiU9C;;;;;;;GAOG;AAEH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CA2BtE"} | ||
| {"version":3,"file":"schema-normalizer.d.ts","sourceRoot":"","sources":["../src/schema-normalizer.ts"],"names":[],"mappings":";AAGA,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AA8V9C,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AAEH,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,KAAK,EACL,gBAAwB,GACzB,EAAE,uBAAuB,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAkCnD"} |
@@ -21,3 +21,3 @@ "use strict"; | ||
| }; | ||
| function getCommonProps(i) { | ||
| function getCommonProps(i, omitOriginalNode) { | ||
| var _i$codegen; | ||
@@ -34,3 +34,5 @@ return { | ||
| hasValidation: !!i.validation, | ||
| originalNode: i | ||
| ...(!omitOriginalNode && { | ||
| originalNode: i | ||
| }) | ||
| }; | ||
@@ -56,3 +58,3 @@ } | ||
| }; | ||
| function normalizeFields(t, parents) { | ||
| function normalizeFields(t, parents, omitOriginalNode) { | ||
| var _t$fields; | ||
@@ -82,3 +84,3 @@ const fields = t.fields || []; | ||
| hasValidation: !!f.validation, | ||
| definition: normalizeType(f, parents) | ||
| definition: normalizeType(f, parents, omitOriginalNode) | ||
| }; | ||
@@ -88,3 +90,3 @@ return schemaFieldDef; | ||
| } | ||
| function normalizeType(t, parents) { | ||
| function normalizeType(t, parents, omitOriginalNode) { | ||
| const pathname = [...parents, getFormattedName(t)].join('.'); | ||
@@ -106,5 +108,5 @@ if (!isRecord(t)) { | ||
| const schemaArrayDef = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type, | ||
| of: Array.isArray(of) ? of.map((i, index) => normalizeType(i, [...parents, index])) : [normalizeType(of, [...parents, 0])], | ||
| of: Array.isArray(of) ? of.map((i, index) => normalizeType(i, [...parents, index], omitOriginalNode)) : [normalizeType(of, [...parents, 0], omitOriginalNode)], | ||
| list: normalizeList(t, [...parents, getFormattedName(t)]) | ||
@@ -118,5 +120,5 @@ }; | ||
| const schemaBlockDef = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type, | ||
| of: of ? Array.isArray(of) ? of.map((i, index) => normalizeType(i, [...parents, index])) : [normalizeType(of, [...parents, 0])] : null, | ||
| of: of ? Array.isArray(of) ? of.map((i, index) => normalizeType(i, [...parents, index], omitOriginalNode)) : [normalizeType(of, [...parents, 0], omitOriginalNode)] : null, | ||
| // TODO: implement this | ||
@@ -130,5 +132,5 @@ markDefs: [] | ||
| const schemaDef = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type, | ||
| fields: normalizeFields(t, [...parents, getFormattedName(t)]) | ||
| fields: normalizeFields(t, [...parents, getFormattedName(t)], omitOriginalNode) | ||
| }; | ||
@@ -143,3 +145,3 @@ return schemaDef; | ||
| ...defProps | ||
| } = getCommonProps(t); | ||
| } = getCommonProps(t, omitOriginalNode); | ||
| if (!name || typeof name !== 'string') { | ||
@@ -156,3 +158,3 @@ throw new SchemaParseError(`\`name\` is required for documents`); | ||
| type, | ||
| fields: normalizeFields(t, [...parents, getFormattedName(t)]) | ||
| fields: normalizeFields(t, [...parents, getFormattedName(t)], omitOriginalNode) | ||
| }; | ||
@@ -170,3 +172,3 @@ return schemaDef; | ||
| const node = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type | ||
@@ -180,5 +182,5 @@ }; | ||
| const node = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type, | ||
| fields: t.fields ? normalizeFields(t, [...parents, getFormattedName(t)]) : null | ||
| fields: t.fields ? normalizeFields(t, [...parents, getFormattedName(t)], omitOriginalNode) : null | ||
| }; | ||
@@ -191,3 +193,3 @@ return node; | ||
| const node = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type, | ||
@@ -206,3 +208,3 @@ list: normalizeList(t, [...parents, getFormattedName(t)]) | ||
| const node = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type, | ||
@@ -214,3 +216,3 @@ to: (Array.isArray(to) ? to : [to]).map(i => { | ||
| const n = { | ||
| ...getCommonProps(i), | ||
| ...getCommonProps(i, omitOriginalNode), | ||
| to: i.type, | ||
@@ -234,3 +236,3 @@ type: 'RegistryReference' | ||
| const node = { | ||
| ...getCommonProps(t), | ||
| ...getCommonProps(t, omitOriginalNode), | ||
| type: 'RegistryReference', | ||
@@ -280,3 +282,2 @@ to: t.type | ||
| } | ||
| /** | ||
@@ -291,4 +292,11 @@ * Takes in a raw sanity schema and returns a statically typed normalized | ||
| // TODO: refactor this API to take in a config object instead of a single argument | ||
| function schemaNormalizer(types) { | ||
| const allRegisteredTypes = types.map(i => normalizeType(i, [])); | ||
| function schemaNormalizer({ | ||
| name, | ||
| types, | ||
| omitOriginalNode = false | ||
| }) { | ||
| if (!name) { | ||
| throw new SchemaParseError('No name was provided alongside a schema.'); | ||
| } | ||
| const allRegisteredTypes = types.map(i => normalizeType(i, [], omitOriginalNode)); | ||
@@ -304,2 +312,3 @@ // TODO: check if name is trying to override primitive types | ||
| return { | ||
| name, | ||
| type: 'SchemaRoot', | ||
@@ -306,0 +315,0 @@ documents, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"transform-schema-to-structure.d.ts","sourceRoot":"","sources":["../src/transform-schema-to-structure.ts"],"names":[],"mappings":";;AAQA,MAAM,WAAW,iCAAiC;IAChD;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,gBAAgB,GACjB,EAAE,iCAAiC,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CActE;AAED,UAAU,qCAAqC;IAC7C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;IAClC;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,IAAI,EACJ,gBAAgB,GACjB,EAAE,qCAAqC,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAyU1E"} | ||
| {"version":3,"file":"transform-schema-to-structure.d.ts","sourceRoot":"","sources":["../src/transform-schema-to-structure.ts"],"names":[],"mappings":";;AAQA,MAAM,WAAW,iCAAiC;IAChD;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,gBAAgB,GACjB,EAAE,iCAAiC,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAiBtE;AAED,UAAU,qCAAqC;IAC7C;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC;IAClC;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,IAAI,EACJ,gBAAgB,GACjB,EAAE,qCAAqC,GAAG,MAAM,CAAC,WAAW,CAAC,aAAa,CAyU1E"} |
@@ -26,2 +26,4 @@ "use strict"; | ||
| }))) | ||
| // for consistent output | ||
| .sort((a, b) => a.hash.localeCompare(b.hash, 'en')) | ||
| }), | ||
@@ -28,0 +30,0 @@ canBeNull: false, |
+3
-3
| { | ||
| "name": "@sanity-codegen/core", | ||
| "version": "1.0.0-alpha.38", | ||
| "version": "1.0.0-alpha.41", | ||
| "keywords": [ | ||
@@ -52,3 +52,3 @@ "sanity", | ||
| "@ricokahler/pool": "^1.2.0", | ||
| "@sanity-codegen/types": "^1.0.0-alpha.38", | ||
| "@sanity-codegen/types": "^1.0.0-alpha.41", | ||
| "babel-merge": "^3.0.0", | ||
@@ -77,3 +77,3 @@ "chalk": "^4.1.2", | ||
| }, | ||
| "gitHead": "97544931de62f8f0afaf73b2735817bf05d8e458" | ||
| "gitHead": "0b8b40df0c9fb2799aa2ce03b08049111eeace87" | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
775474
1.96%10790
0.98%