@dangreaves/groq-query-builder
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -92,2 +92,3 @@ import { Logger } from 'pino'; | ||
type TConditionalUnion<T extends Record<string, TSchema> = Record<string, TSchema>> = TUnion<SchemaArrayFromConditions<T>> & { | ||
groqType: "conditionalUnion"; | ||
[optionsKey$1]?: TConditionalUnionOptions; | ||
@@ -101,2 +102,6 @@ [originalConditionsKey]: T; | ||
/** | ||
* Return true if the given schema is a conditional union. | ||
*/ | ||
declare function isConditionalUnion(value: unknown): value is TConditionalUnion; | ||
/** | ||
* Expand the given conditional union. | ||
@@ -123,2 +128,3 @@ */ | ||
type TProjection<T extends TProperties = TProperties> = TObject<T> & { | ||
groqType: "projection"; | ||
[optionsKey]?: TProjectionOptions; | ||
@@ -132,2 +138,6 @@ [originalPropertiesKey]: T; | ||
/** | ||
* Return true if the given schema is a projection. | ||
*/ | ||
declare function isProjection(value: unknown): value is TProjection; | ||
/** | ||
* Expand the given projection. | ||
@@ -151,2 +161,7 @@ */ | ||
/** | ||
* Dereference the given schema. | ||
*/ | ||
declare function Reference<T extends TProjection | TConditionalUnion>(schema: T, conditionalAttribute?: string): T; | ||
/** | ||
* Object properties with required _type attribute. | ||
@@ -188,2 +203,3 @@ */ | ||
groq?: string; | ||
groqType?: string; | ||
} | ||
@@ -201,2 +217,3 @@ } | ||
declare const index_Raw: typeof Raw; | ||
declare const index_Reference: typeof Reference; | ||
declare const index_String: typeof String; | ||
@@ -225,8 +242,10 @@ declare const index_TBoolean: typeof TBoolean; | ||
declare const index_filterProjection: typeof filterProjection; | ||
declare const index_isConditionalUnion: typeof isConditionalUnion; | ||
declare const index_isProjection: typeof isProjection; | ||
declare const index_sliceCollection: typeof sliceCollection; | ||
declare const index_sliceProjection: typeof sliceProjection; | ||
declare namespace index { | ||
export { index_Alias as Alias, index_Boolean as Boolean, index_Collection as Collection, index_ConditionalUnion as ConditionalUnion, index_Literal as Literal, index_Nullable as Nullable, index_Number as Number, index_Projection as Projection, index_Raw as Raw, index_String as String, index_TBoolean as TBoolean, type index_TCollection as TCollection, type index_TCollectionOptions as TCollectionOptions, type index_TConditionalUnion as TConditionalUnion, type index_TConditionalUnionOptions as TConditionalUnionOptions, index_TLiteral as TLiteral, type index_TNullable as TNullable, index_TNumber as TNumber, type index_TProjection as TProjection, type index_TProjectionOptions as TProjectionOptions, index_TSchema as TSchema, index_TString as TString, type index_TTypedProjection as TTypedProjection, type index_TTypedUnion as TTypedUnion, index_TUnknown as TUnknown, index_TypedProjection as TypedProjection, index_TypedUnion as TypedUnion, index_Unknown as Unknown, index_expandConditionalUnion as expandConditionalUnion, index_expandProjection as expandProjection, index_filterCollection as filterCollection, index_filterProjection as filterProjection, index_sliceCollection as sliceCollection, index_sliceProjection as sliceProjection }; | ||
export { index_Alias as Alias, index_Boolean as Boolean, index_Collection as Collection, index_ConditionalUnion as ConditionalUnion, index_Literal as Literal, index_Nullable as Nullable, index_Number as Number, index_Projection as Projection, index_Raw as Raw, index_Reference as Reference, index_String as String, index_TBoolean as TBoolean, type index_TCollection as TCollection, type index_TCollectionOptions as TCollectionOptions, type index_TConditionalUnion as TConditionalUnion, type index_TConditionalUnionOptions as TConditionalUnionOptions, index_TLiteral as TLiteral, type index_TNullable as TNullable, index_TNumber as TNumber, type index_TProjection as TProjection, type index_TProjectionOptions as TProjectionOptions, index_TSchema as TSchema, index_TString as TString, type index_TTypedProjection as TTypedProjection, type index_TTypedUnion as TTypedUnion, index_TUnknown as TUnknown, index_TypedProjection as TypedProjection, index_TypedUnion as TypedUnion, index_Unknown as Unknown, index_expandConditionalUnion as expandConditionalUnion, index_expandProjection as expandProjection, index_filterCollection as filterCollection, index_filterProjection as filterProjection, index_isConditionalUnion as isConditionalUnion, index_isProjection as isProjection, index_sliceCollection as sliceCollection, index_sliceProjection as sliceProjection }; | ||
} | ||
export { type InferFromSchema, index as S, index as Schemas, makeSafeSanityFetch }; |
@@ -79,2 +79,3 @@ var __defProp = Object.defineProperty; | ||
Raw: () => Raw, | ||
Reference: () => Reference, | ||
String: () => String, | ||
@@ -88,2 +89,4 @@ TypedProjection: () => TypedProjection, | ||
filterProjection: () => filterProjection, | ||
isConditionalUnion: () => isConditionalUnion, | ||
isProjection: () => isProjection, | ||
sliceCollection: () => sliceCollection, | ||
@@ -148,3 +151,3 @@ sliceProjection: () => sliceProjection | ||
// src/schemas/ConditionalUnion.ts | ||
import { Type as Type3 } from "@sinclair/typebox"; | ||
import { Type as Type3, TypeGuard } from "@sinclair/typebox"; | ||
var optionsKey2 = Symbol("options"); | ||
@@ -173,2 +176,3 @@ var originalConditionsKey = Symbol("originalConditions"); | ||
const schema = Type3.Union(schemas, { groq }); | ||
schema.groqType = "conditionalUnion"; | ||
if (options) | ||
@@ -179,2 +183,5 @@ schema[optionsKey2] = options; | ||
} | ||
function isConditionalUnion(value) { | ||
return TypeGuard.IsSchema(value) && "conditionalUnion" === value.groqType; | ||
} | ||
function expandConditionalUnion(schema, expandReference) { | ||
@@ -188,3 +195,3 @@ return ConditionalUnion(schema[originalConditionsKey], { | ||
// src/schemas/Projection.ts | ||
import { Type as Type4 } from "@sinclair/typebox"; | ||
import { Type as Type4, TypeGuard as TypeGuard2 } from "@sinclair/typebox"; | ||
var optionsKey3 = Symbol("options"); | ||
@@ -217,2 +224,3 @@ var originalPropertiesKey = Symbol("originalProperties"); | ||
const schema = Type4.Object(properties, { groq }); | ||
schema["groqType"] = "projection"; | ||
if (options) | ||
@@ -223,2 +231,5 @@ schema[optionsKey3] = options; | ||
} | ||
function isProjection(value) { | ||
return TypeGuard2.IsSchema(value) && "projection" === value.groqType; | ||
} | ||
function expandProjection(schema, expandReference) { | ||
@@ -251,2 +262,13 @@ return Projection(schema[originalPropertiesKey], { | ||
// src/schemas/Reference.ts | ||
function Reference(schema, conditionalAttribute) { | ||
if (isProjection(schema)) { | ||
return expandProjection(schema, conditionalAttribute); | ||
} | ||
if (isConditionalUnion(schema)) { | ||
return expandConditionalUnion(schema, conditionalAttribute); | ||
} | ||
return schema; | ||
} | ||
// src/schemas/TypedProjection.ts | ||
@@ -253,0 +275,0 @@ function TypedProjection(properties, options) { |
{ | ||
"name": "@dangreaves/groq-query-builder", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42995
812