-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types(groq-builder): use TRootConfig instead of TSchema
- Loading branch information
scottrippey
committed
Oct 1, 2023
1 parent
5e81c85
commit 0071634
Showing
12 changed files
with
82 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { GroqBuilder } from "../groq-builder"; | ||
import { GroqBuilder, RootConfig } from "../groq-builder"; | ||
import { ExtractRefType } from "../common-types"; | ||
|
||
declare module "../groq-builder" { | ||
export interface GroqBuilder<TSchema, TScope> { | ||
export interface GroqBuilder<TScope, TRootConfig extends RootConfig> { | ||
deref(): TScope extends Array<infer TScopeItem> | ||
? Array<ExtractRefType<TSchema, TScopeItem>> | ||
: ExtractRefType<TSchema, TScope>; | ||
? Array<ExtractRefType<TScopeItem, TRootConfig>> | ||
: ExtractRefType<TScope, TRootConfig>; | ||
} | ||
} | ||
|
||
GroqBuilder.implement({ | ||
deref(this: GroqBuilder<any, any>): any { | ||
deref(this: GroqBuilder<any, RootConfig>): any { | ||
return this.extend("->", null); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 24 additions & 6 deletions
30
packages/nextjs/sanity-studio/builder/commands/filter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import { createGroqBuilder } from "../groq-builder"; | ||
import { SanitySchemaTypes } from "../../sanity-types"; | ||
import { SanitySchemaTypes, SchemaConfig } from "../../sanity-types"; | ||
import { expectType } from "../test-utils/expectType"; | ||
import { ExtractScope } from "../common-types"; | ||
import { SanitySchemaRaw } from "../../sanity.config"; | ||
import { Simplify, SimplifyDeep } from "../type-utils"; | ||
|
||
const q = createGroqBuilder<SanitySchemaTypes>(); | ||
const q = createGroqBuilder<SchemaConfig>(); | ||
|
||
describe("filter", () => { | ||
it("", () => { | ||
const res = q.filterByType("flavour"); | ||
expectType<ExtractScope<typeof res>>().toStrictEqual<SanitySchemaRaw["flavour"]>(); | ||
const res = q.filter(); | ||
expectType<typeof res>().toStrictEqual<typeof q>(); | ||
expect(q).toMatchObject({ | ||
query: `[]`, | ||
}); | ||
}); | ||
it("", () => { | ||
const res = q.filter(`_type == 'flavour'`); | ||
expectType<typeof res>().toStrictEqual<typeof q>(); | ||
expect(q).toMatchObject({ | ||
query: `[_type == 'flavour']`, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("filterByType", () => { | ||
it("", () => { | ||
const res = q.field("*").filterByType("flavour"); | ||
expectType<ExtractScope<typeof res>>().toStrictEqual<Array<SanitySchemaTypes["flavour"]>>(); | ||
expect(q).toMatchObject({ | ||
query: `*[_type == 'flavour']`, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { SanitySchemaRaw } from "./sanity.config"; | ||
// import { SimplifyDeep } from "./builder/type-utils"; | ||
import { _referenced } from "@sanity-typed/types"; | ||
|
||
/** Typescript type of all types! */ | ||
// export type SanitySchemaTypes = SimplifyDeep<SanitySchemaRaw>; | ||
export type SanitySchemaTypes = SanitySchemaRaw; | ||
|
||
export type SchemaConfig = { TSchema: SanitySchemaRaw; referenced: typeof _referenced }; |