diff --git a/src/services/search/service/query.ts b/src/services/search/service/query.ts index 8ee4d2ca..bcc09896 100644 --- a/src/services/search/service/query.ts +++ b/src/services/search/service/query.ts @@ -7,17 +7,15 @@ import type { JSONFetchResponse, SDKOptions, ServiceMethodOptions } from '../../ import type { OpenAPI } from '../index.js'; import type { ResultFormatVersion } from '../types.js'; -type Content = NonNullable; -export type MatchedPrincipalSets = - OpenAPI.components['schemas']['ResultEntry']['matched_principal_sets']; +type Schemas = OpenAPI.components['schemas']; + +type Content = NonNullable; +export type MatchedPrincipalSets = Schemas['ResultEntry']['matched_principal_sets']; /** * @see https://docs.globus.org/api/search/reference/post_query/#gmetaresult */ -export type GMetaResult = Omit< - OpenAPI.components['schemas']['GMetaResult'], - 'entries' -> & { - entries: (Omit & { content: C })[]; +export type GMetaResult = Omit & { + entries: (Omit & { content: C })[]; }; /** @@ -33,7 +31,13 @@ export type GFacetResult = { * @see https://docs.globus.org/api/search/reference/post_query/#gbucket */ export type GBucket = { - value: string | GFilter; + value: + | string + | number + | { + to: string; + from: string; + }; count: number; }; @@ -137,32 +141,22 @@ export const post = function ( ); }; +type OptionalKeys = Omit & Partial>; + /** - * @see https://docs.globus.org/api/search/reference/post_query/#gfilter + * Utility type to make specific keys in a union of objects optional. + * This is used to account for `defaultNonNullable: true` when generating types. + * @see file://./../../../../scripts/open-api/generate-types.mjs#L54-L55 */ -export type GFilter = GFilterMatch | GFilterRange | GFilterExists | GFilterNot; +type OptionalKeysInUnion = T extends object ? OptionalKeys : T; -type GFilterTypeMatch = 'match_any' | 'match_all'; -type GFilterTypeRange = 'range'; - -type GFilterMatch = { - type: GFilterTypeMatch; - field_name: string; - values: Array; -}; -type GFilterRange = { - type: GFilterTypeRange; - field_name: string; - values: Array<{ from: string; to: string }>; -}; -type GFilterExists = { - type: 'exists'; - field_name: string; -}; -type GFilterNot = { - type: 'not'; - filter: GFilter; -}; +/** + * @see https://docs.globus.org/api/search/reference/post_query/#gfilter + * + * @privateRemarks + * The `GFilter` type includes `@version` and `post_filter` with `"default"` values. + */ +export type GFilter = OptionalKeysInUnion; type HistogramRange = { low: number | string; high: number | string };