@sanity/codegen
Advanced tools
Comparing version 3.52.5-canary.18 to 3.53.0
@@ -88,2 +88,15 @@ import {ExprNode} from 'groq-js' | ||
result: resolveExpressionReturnType | ||
/** location is the location of the query in the source */ | ||
location: { | ||
start?: { | ||
line: number | ||
column: number | ||
index: number | ||
} | ||
end?: { | ||
line: number | ||
column: number | ||
index: number | ||
} | ||
} | ||
} | ||
@@ -90,0 +103,0 @@ |
@@ -93,5 +93,4 @@ import fs$1, { readFile } from "node:fs/promises"; | ||
}) { | ||
var _a, _b, _c, _d; | ||
if (debug$2( | ||
`Resolving node ${node.type} in ${filename}:${(_a = node.loc) == null ? void 0 : _a.start.line}:${(_b = node.loc) == null ? void 0 : _b.start.column}` | ||
`Resolving node ${node.type} in ${filename}:${node.loc?.start.line}:${node.loc?.start.column}` | ||
), t.isTaggedTemplateExpression(node) && t.isIdentifier(node.tag) && TAGGED_TEMPLATE_ALLOW_LIST.includes(node.tag.name)) | ||
@@ -207,3 +206,3 @@ return resolveExpression({ | ||
throw new Error( | ||
`Unsupported expression type: ${node.type} in ${filename}:${(_c = node.loc) == null ? void 0 : _c.start.line}:${(_d = node.loc) == null ? void 0 : _d.start.column}` | ||
`Unsupported expression type: ${node.type} in ${filename}:${node.loc?.start.line}:${node.loc?.start.column}` | ||
); | ||
@@ -221,3 +220,2 @@ } | ||
}) { | ||
var _a, _b, _c, _d; | ||
const paramIndex = params.findIndex( | ||
@@ -241,3 +239,3 @@ (param) => t.isIdentifier(param) && node.name === param.name || t.isAssignmentPattern(param) && t.isIdentifier(param.left) && node.name === param.left.name | ||
throw new Error( | ||
`Could not resolve same identifier "${node.name}" in "${filename}:${(_a = node.loc) == null ? void 0 : _a.start.line}:${(_b = node.loc) == null ? void 0 : _b.start.column}"` | ||
`Could not resolve same identifier "${node.name}" in "${filename}:${node.loc?.start.line}:${node.loc?.start.column}"` | ||
); | ||
@@ -256,3 +254,3 @@ return resolveExpression({ | ||
throw new Error( | ||
`Could not find binding for node "${node.name}" in ${filename}:${(_c = node.loc) == null ? void 0 : _c.start.line}:${(_d = node.loc) == null ? void 0 : _d.start.column}` | ||
`Could not find binding for node "${node.name}" in ${filename}:${node.loc?.start.line}:${node.loc?.start.column}` | ||
); | ||
@@ -291,6 +289,5 @@ } | ||
ImportDeclaration(n) { | ||
var _a; | ||
if (t.isImportDeclaration(n.node)) | ||
for (const specifier of n.node.specifiers) { | ||
if (t.isImportDefaultSpecifier(specifier) && ((_a = specifier.local.loc) == null ? void 0 : _a.identifierName) === node.local.name) { | ||
if (t.isImportDefaultSpecifier(specifier) && specifier.local.loc?.identifierName === node.local.name) { | ||
importDeclaration = n.node; | ||
@@ -386,4 +383,11 @@ break; | ||
resolver | ||
}); | ||
queries.push({ name: queryName, result: queryResult }); | ||
}), location = node.loc ? { | ||
start: { | ||
...node.loc?.start | ||
}, | ||
end: { | ||
...node.loc?.end | ||
} | ||
} : {}; | ||
queries.push({ name: queryName, result: queryResult, location }); | ||
} | ||
@@ -394,7 +398,6 @@ } | ||
function declarationLeadingCommentContains(path2, comment) { | ||
var _a, _b; | ||
const variableDeclaration = path2.find((node) => node.isVariableDeclaration()); | ||
return variableDeclaration ? !!((_a = variableDeclaration.node.leadingComments) != null && _a.find( | ||
return variableDeclaration ? !!(variableDeclaration.node.leadingComments?.find( | ||
(commentItem) => commentItem.value.trim() === comment | ||
) || (_b = variableDeclaration.parent.leadingComments) != null && _b.find( | ||
) || variableDeclaration.parent.leadingComments?.find( | ||
(commentItem) => commentItem.value.trim() === comment | ||
@@ -480,7 +483,9 @@ )) : !1; | ||
} | ||
var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value); | ||
const REFERENCE_SYMBOL_NAME = "internalGroqTypeReferenceTo", ALL_SCHEMA_TYPES = "AllSanitySchemaTypes"; | ||
class TypeGenerator { | ||
generatedTypeName = /* @__PURE__ */ new Set(); | ||
typeNameMap = /* @__PURE__ */ new Map(); | ||
schema; | ||
constructor(schema) { | ||
__publicField(this, "generatedTypeName", /* @__PURE__ */ new Set()), __publicField(this, "typeNameMap", /* @__PURE__ */ new Map()), __publicField(this, "schema"), this.schema = schema; | ||
this.schema = schema; | ||
} | ||
@@ -547,7 +552,6 @@ /** | ||
generateQueryMap(queries) { | ||
var _a; | ||
const typesByQuerystring = {}; | ||
for (const query of queries) { | ||
const name = this.typeNameMap.get(query.typeNode); | ||
name && (typesByQuerystring[_a = query.query] != null || (typesByQuerystring[_a] = []), typesByQuerystring[query.query].push(name)); | ||
name && (typesByQuerystring[query.query] ??= [], typesByQuerystring[query.query].push(name)); | ||
} | ||
@@ -554,0 +558,0 @@ const queryReturnInterface = t.tsInterfaceDeclaration( |
@@ -100,5 +100,4 @@ "use strict"; | ||
}) { | ||
var _a, _b, _c, _d; | ||
if (debug$2( | ||
`Resolving node ${node.type} in ${filename}:${(_a = node.loc) == null ? void 0 : _a.start.line}:${(_b = node.loc) == null ? void 0 : _b.start.column}` | ||
`Resolving node ${node.type} in ${filename}:${node.loc?.start.line}:${node.loc?.start.column}` | ||
), t__namespace.isTaggedTemplateExpression(node) && t__namespace.isIdentifier(node.tag) && TAGGED_TEMPLATE_ALLOW_LIST.includes(node.tag.name)) | ||
@@ -214,3 +213,3 @@ return resolveExpression({ | ||
throw new Error( | ||
`Unsupported expression type: ${node.type} in ${filename}:${(_c = node.loc) == null ? void 0 : _c.start.line}:${(_d = node.loc) == null ? void 0 : _d.start.column}` | ||
`Unsupported expression type: ${node.type} in ${filename}:${node.loc?.start.line}:${node.loc?.start.column}` | ||
); | ||
@@ -228,3 +227,2 @@ } | ||
}) { | ||
var _a, _b, _c, _d; | ||
const paramIndex = params.findIndex( | ||
@@ -248,3 +246,3 @@ (param) => t__namespace.isIdentifier(param) && node.name === param.name || t__namespace.isAssignmentPattern(param) && t__namespace.isIdentifier(param.left) && node.name === param.left.name | ||
throw new Error( | ||
`Could not resolve same identifier "${node.name}" in "${filename}:${(_a = node.loc) == null ? void 0 : _a.start.line}:${(_b = node.loc) == null ? void 0 : _b.start.column}"` | ||
`Could not resolve same identifier "${node.name}" in "${filename}:${node.loc?.start.line}:${node.loc?.start.column}"` | ||
); | ||
@@ -263,3 +261,3 @@ return resolveExpression({ | ||
throw new Error( | ||
`Could not find binding for node "${node.name}" in ${filename}:${(_c = node.loc) == null ? void 0 : _c.start.line}:${(_d = node.loc) == null ? void 0 : _d.start.column}` | ||
`Could not find binding for node "${node.name}" in ${filename}:${node.loc?.start.line}:${node.loc?.start.column}` | ||
); | ||
@@ -298,6 +296,5 @@ } | ||
ImportDeclaration(n) { | ||
var _a; | ||
if (t__namespace.isImportDeclaration(n.node)) | ||
for (const specifier of n.node.specifiers) { | ||
if (t__namespace.isImportDefaultSpecifier(specifier) && ((_a = specifier.local.loc) == null ? void 0 : _a.identifierName) === node.local.name) { | ||
if (t__namespace.isImportDefaultSpecifier(specifier) && specifier.local.loc?.identifierName === node.local.name) { | ||
importDeclaration = n.node; | ||
@@ -393,4 +390,11 @@ break; | ||
resolver | ||
}); | ||
queries.push({ name: queryName, result: queryResult }); | ||
}), location = node.loc ? { | ||
start: { | ||
...node.loc?.start | ||
}, | ||
end: { | ||
...node.loc?.end | ||
} | ||
} : {}; | ||
queries.push({ name: queryName, result: queryResult, location }); | ||
} | ||
@@ -401,7 +405,6 @@ } | ||
function declarationLeadingCommentContains(path2, comment) { | ||
var _a, _b; | ||
const variableDeclaration = path2.find((node) => node.isVariableDeclaration()); | ||
return variableDeclaration ? !!((_a = variableDeclaration.node.leadingComments) != null && _a.find( | ||
return variableDeclaration ? !!(variableDeclaration.node.leadingComments?.find( | ||
(commentItem) => commentItem.value.trim() === comment | ||
) || (_b = variableDeclaration.parent.leadingComments) != null && _b.find( | ||
) || variableDeclaration.parent.leadingComments?.find( | ||
(commentItem) => commentItem.value.trim() === comment | ||
@@ -487,7 +490,9 @@ )) : !1; | ||
} | ||
var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value); | ||
const REFERENCE_SYMBOL_NAME = "internalGroqTypeReferenceTo", ALL_SCHEMA_TYPES = "AllSanitySchemaTypes"; | ||
class TypeGenerator { | ||
generatedTypeName = /* @__PURE__ */ new Set(); | ||
typeNameMap = /* @__PURE__ */ new Map(); | ||
schema; | ||
constructor(schema) { | ||
__publicField(this, "generatedTypeName", /* @__PURE__ */ new Set()), __publicField(this, "typeNameMap", /* @__PURE__ */ new Map()), __publicField(this, "schema"), this.schema = schema; | ||
this.schema = schema; | ||
} | ||
@@ -554,7 +559,6 @@ /** | ||
generateQueryMap(queries) { | ||
var _a; | ||
const typesByQuerystring = {}; | ||
for (const query of queries) { | ||
const name = this.typeNameMap.get(query.typeNode); | ||
name && (typesByQuerystring[_a = query.query] != null || (typesByQuerystring[_a] = []), typesByQuerystring[query.query].push(name)); | ||
name && (typesByQuerystring[query.query] ??= [], typesByQuerystring[query.query].push(name)); | ||
} | ||
@@ -561,0 +565,0 @@ const queryReturnInterface = t__namespace.tsInterfaceDeclaration( |
{ | ||
"name": "@sanity/codegen", | ||
"version": "3.52.5-canary.18+3b2329cf64", | ||
"version": "3.53.0", | ||
"description": "Codegen toolkit for Sanity.io", | ||
@@ -63,3 +63,3 @@ "keywords": [ | ||
"globby": "^10.0.0", | ||
"groq": "3.52.5-canary.18+3b2329cf64", | ||
"groq": "3.53.0", | ||
"groq-js": "^1.12.0", | ||
@@ -72,3 +72,3 @@ "json5": "^2.2.3", | ||
"@jest/globals": "^29.7.0", | ||
"@repo/package.config": "3.52.4", | ||
"@repo/package.config": "3.53.0", | ||
"@types/babel__core": "^7.20.5", | ||
@@ -87,3 +87,3 @@ "@types/babel__generator": "^7.6.8", | ||
}, | ||
"gitHead": "3b2329cf640954f308676a4b02f3fda701c65587" | ||
"gitHead": "d60dc6d2ae67d56ae680ebfffee2c66599924b4d" | ||
} |
@@ -23,2 +23,16 @@ import fs from 'node:fs' | ||
result: resolveExpressionReturnType | ||
/** location is the location of the query in the source */ | ||
location: { | ||
start?: { | ||
line: number | ||
column: number | ||
index: number | ||
} | ||
end?: { | ||
line: number | ||
column: number | ||
index: number | ||
} | ||
} | ||
} | ||
@@ -25,0 +39,0 @@ |
@@ -74,3 +74,14 @@ import {createRequire} from 'node:module' | ||
queries.push({name: queryName, result: queryResult}) | ||
const location = node.loc | ||
? { | ||
start: { | ||
...node.loc?.start, | ||
}, | ||
end: { | ||
...node.loc?.end, | ||
}, | ||
} | ||
: {} | ||
queries.push({name: queryName, result: queryResult, location}) | ||
} | ||
@@ -77,0 +88,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3523
0
0
298364
+ Addedgroq@3.53.0(transitive)
Updatedgroq@3.53.0