Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: renames extension functions for releases #271

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/evaluator/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ sanity['dataset'] = async function (_args, scope) {
}

// eslint-disable-next-line require-await
sanity['versionOf'] = async function (args, scope, execute) {
sanity['versionsOf'] = async function (args, scope, execute) {
if (!scope.source.isArray()) return NULL_VALUE

const value = await execute(args[0], scope)
Expand Down Expand Up @@ -482,10 +482,10 @@ sanity['versionOf'] = async function (args, scope, execute) {

return fromJS(versionIds)
}
sanity['versionOf'].arity = 1
sanity['versionsOf'].arity = 1

// eslint-disable-next-line require-await
sanity['documentsOf'] = async function (args, scope, execute) {
sanity['partOfRelease'] = async function (args, scope, execute) {
if (!scope.source.isArray()) return NULL_VALUE

const value = await execute(args[0], scope)
Expand Down Expand Up @@ -514,7 +514,7 @@ sanity['documentsOf'] = async function (args, scope, execute) {

return fromJS(documentIdsInBundle)
}
sanity['documentsOf'].arity = 1
sanity['partOfRelease'].arity = 1

export type GroqPipeFunction = (
base: Value,
Expand Down
4 changes: 2 additions & 2 deletions src/typeEvaluator/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
})
})
}
case 'sanity.versionOf': {
case 'sanity.versionsOf': {
const typeNode = walk({node: node.args[0], scope})
return mapNode(typeNode, scope, (typeNode) => {
if (typeNode.type === 'unknown') {
Expand All @@ -456,7 +456,7 @@ export function handleFuncCallNode(node: FuncCallNode, scope: Scope): TypeNode {
return {type: 'array', of: {type: 'string'}}
})
}
case 'sanity.documentsOf': {
case 'sanity.partOfRelease': {
const typeNode = walk({node: node.args[0], scope})
return mapNode(typeNode, scope, (typeNode) => {
if (typeNode.type === 'unknown') {
Expand Down
8 changes: 4 additions & 4 deletions test/evaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ t.test('Basic parsing', async (t) => {
t.same(data, 'abcdef')
})

t.test('sanity::versionOf()', async (t) => {
t.test('sanity::versionsOf()', async (t) => {
const dataset = [
{_id: 'doc1', _version: {}},
{_id: 'drafts.doc1', _version: {}},
Expand All @@ -293,13 +293,13 @@ t.test('Basic parsing', async (t) => {
{_id: 'doc2', _version: {}},
]

const tree = parse('{"versions": sanity::versionOf("doc1")}')
const tree = parse('{"versions": sanity::versionsOf("doc1")}')
const value = await evaluate(tree, {dataset})
const data = await value.get()
t.same(data, {versions: ['drafts.doc1', 'sale.doc1']})
})

t.test('sanity::documentsOf()', async (t) => {
t.test('sanity::partOfRelease()', async (t) => {
const dataset = [
{_id: 'doc1', _version: {}},
{_id: 'drafts.doc1', _version: {}},
Expand All @@ -310,7 +310,7 @@ t.test('Basic parsing', async (t) => {
{_id: 'doc2', _version: {}},
]

const tree = parse('{"documentsInBundle": sanity::documentsOf("sale")}')
const tree = parse('{"documentsInBundle": sanity::partOfRelease("sale")}')
const value = await evaluate(tree, {dataset})
const data = await value.get()
t.same(data, {documentsInBundle: ['sale.doc1', 'sale.doc2']})
Expand Down
8 changes: 4 additions & 4 deletions test/typeEvaluate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3274,9 +3274,9 @@ t.test('splat on optional object', (t) => {
t.end()
})

t.test('function: sanity::versionOf', (t) => {
t.test('function: sanity::versionsOf', (t) => {
const query = `*[_type == "author"] {
"versions": sanity::versionOf("foo")
"versions": sanity::versionsOf("foo")
}`
const ast = parse(query)
const res = typeEvaluate(ast, schemas)
Expand All @@ -3301,9 +3301,9 @@ t.test('function: sanity::versionOf', (t) => {
t.end()
})

t.test('function: sanity::documentsOf', (t) => {
t.test('function: sanity::partOfRelease', (t) => {
const query = `*[_type == "author"] {
"saleBundleDocuments": sanity::documentsOf("sale")
"saleBundleDocuments": sanity::partOfRelease("sale")
}`
const ast = parse(query)
const res = typeEvaluate(ast, schemas)
Expand Down