import {z} from 'zod' export type GoogleCloudDatacatalogV1SearchCatalogRequestScope = {includeGcpPublicDatasets?: boolean | undefined, includeOrgIds?: Array | undefined, includeProjectIds?: Array | undefined, includePublicTagTemplates?: boolean | undefined, restrictedLocations?: Array | undefined, starredOnly?: boolean | undefined}; export type GoogleCloudDatacatalogV1SearchCatalogRequest = {adminSearch?: boolean | undefined, orderBy?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined, query?: string | undefined, scope?: GoogleCloudDatacatalogV1SearchCatalogRequestScope | undefined}; export type CreateApiV1CatalogSearchArgs = {body: GoogleCloudDatacatalogV1SearchCatalogRequest}; export type CreateApiV1CatalogSearchOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudDatacatalogV1SearchCatalogResult = z.object({description: z.string().optional(), displayName: z.string().optional(), fullyQualifiedName: z.string().optional(), integratedSystem: z.enum(["INTEGRATED_SYSTEM_UNSPECIFIED", "BIGQUERY", "CLOUD_PUBSUB", "DATAPROC_METASTORE", "DATAPLEX", "CLOUD_SPANNER", "CLOUD_BIGTABLE", "CLOUD_SQL", "LOOKER", "VERTEX_AI"]).optional(), linkedResource: z.string().optional(), modifyTime: z.string().optional(), relativeResourceName: z.string().optional(), searchResultSubtype: z.string().optional(), searchResultType: z.enum(["SEARCH_RESULT_TYPE_UNSPECIFIED", "ENTRY", "TAG_TEMPLATE", "ENTRY_GROUP"]).optional(), userSpecifiedSystem: z.string().optional()}); export const googleCloudDatacatalogV1SearchCatalogResponse = z.object({nextPageToken: z.string().optional(), results: z.array(googleCloudDatacatalogV1SearchCatalogResult).optional(), totalSize: z.number().int().optional(), unreachable: z.array(z.string()).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Searches Data Catalog for multiple resources like entries and tags that match a query. This is a [Custom Method] (https://cloud.google.com/apis/design/custom_methods) that doesn't return all information on a resource, only its ID and high level fields. To get more information, you can subsequently call specific get methods. Note: Data Catalog search queries don't guarantee full recall. Results that match your query might not be returned, even in subsequent result pages. Additionally, returned (and not returned) results can vary if you repeat search queries. For more information, see [Data Catalog search syntax] (https://cloud.google.com/data-catalog/docs/how-to/search-reference). * * POST /v1/catalog:search */ export const createApiV1CatalogSearch = async (args: CreateApiV1CatalogSearchArgs, options?: CreateApiV1CatalogSearchOptions) => { const {baseUrl = "https://datacatalog.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/catalog:search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(googleCloudDatacatalogV1SearchCatalogResponse, await res.json()) };