Skip to content
Merged
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
58 changes: 26 additions & 32 deletions src/services/search/service/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpenAPI.components['schemas']['ResultEntry']['content']>;
export type MatchedPrincipalSets =
OpenAPI.components['schemas']['ResultEntry']['matched_principal_sets'];
type Schemas = OpenAPI.components['schemas'];

type Content = NonNullable<Schemas['ResultEntry']['content']>;
export type MatchedPrincipalSets = Schemas['ResultEntry']['matched_principal_sets'];
/**
* @see https://docs.globus.org/api/search/reference/post_query/#gmetaresult
*/
export type GMetaResult<C extends Content = Content> = Omit<
OpenAPI.components['schemas']['GMetaResult'],
'entries'
> & {
entries: (Omit<OpenAPI.components['schemas']['ResultEntry'], 'content'> & { content: C })[];
export type GMetaResult<C extends Content = Content> = Omit<Schemas['GMetaResult'], 'entries'> & {
entries: (Omit<Schemas['ResultEntry'], 'content'> & { content: C })[];
};

/**
Expand All @@ -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;
};

Expand Down Expand Up @@ -137,32 +141,22 @@ export const post = function <C extends Content = Content>(
);
};

type OptionalKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

/**
* @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, K extends string> = T extends object ? OptionalKeys<T, K & keyof T> : T;

type GFilterTypeMatch = 'match_any' | 'match_all';
type GFilterTypeRange = 'range';

type GFilterMatch = {
type: GFilterTypeMatch;
field_name: string;
values: Array<string>;
};
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<Schemas['GFilter'], '@version' | 'post_filter'>;

type HistogramRange = { low: number | string; high: number | string };

Expand Down