import {z} from 'zod' export type GoogleCloudDatacatalogV1SerializedPolicyTag = {childPolicyTags?: Array | undefined, description?: string | undefined, displayName?: string | undefined, policyTag?: string | undefined}; export type GoogleCloudDatacatalogV1SerializedTaxonomy = {activatedPolicyTypes?: (Array<'POLICY_TYPE_UNSPECIFIED' | 'FINE_GRAINED_ACCESS_CONTROL'>) | undefined, description?: string | undefined, displayName?: string | undefined, policyTags?: Array | undefined}; export type GoogleCloudDatacatalogV1ReplaceTaxonomyRequest = {serializedTaxonomy?: GoogleCloudDatacatalogV1SerializedTaxonomy | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesTaxonomiesIdReplaceArgs = {projectsId: string, locationsId: string, taxonomiesId: string, body: GoogleCloudDatacatalogV1ReplaceTaxonomyRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesTaxonomiesIdReplaceOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const googleCloudDatacatalogV1TaxonomyService = z.object({identity: z.string().optional(), name: z.enum(["MANAGING_SYSTEM_UNSPECIFIED", "MANAGING_SYSTEM_DATAPLEX", "MANAGING_SYSTEM_OTHER"]).optional()}); export const googleCloudDatacatalogV1SystemTimestamps = z.object({createTime: z.string().optional(), expireTime: z.string().optional(), updateTime: z.string().optional()}); export const googleCloudDatacatalogV1Taxonomy = z.object({activatedPolicyTypes: z.array(z.enum(["POLICY_TYPE_UNSPECIFIED", "FINE_GRAINED_ACCESS_CONTROL"])).optional(), description: z.string().optional(), displayName: z.string().optional(), name: z.string().optional(), policyTagCount: z.number().int().optional(), service: googleCloudDatacatalogV1TaxonomyService.optional(), taxonomyTimestamps: googleCloudDatacatalogV1SystemTimestamps.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 }; /** * Replaces (updates) a taxonomy and all its policy tags. The taxonomy and its entire hierarchy of policy tags must be represented literally by `SerializedTaxonomy` and the nested `SerializedPolicyTag` messages. This operation automatically does the following: - Deletes the existing policy tags that are missing from the `SerializedPolicyTag`. - Creates policy tags that don't have resource names. They are considered new. - Updates policy tags with valid resources names accordingly. * * POST /v1/projects/{projectsId}/locations/{locationsId}/taxonomies/{taxonomiesId}:replace */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesTaxonomiesIdReplace = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesTaxonomiesIdReplaceArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdTaxonomiesTaxonomiesIdReplaceOptions) => { 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/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/taxonomies/${encodeURIComponent(String(args.taxonomiesId))}:replace${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(googleCloudDatacatalogV1Taxonomy, await res.json()) };