diff --git a/generate/Dockerfile.generate b/generate/Dockerfile.generate index f341e1d..ec76bd2 100644 --- a/generate/Dockerfile.generate +++ b/generate/Dockerfile.generate @@ -1 +1 @@ -FROM openapitools/openapi-generator-cli:latest-release +FROM openapitools/openapi-generator-cli@sha256:bc3f07ee4032923c7158b1a4a59aadd1861c6b4227c58d8ded5ee2b6c075bf72 \ No newline at end of file diff --git a/generate/generate.sh b/generate/generate.sh index e4188b8..4d0935c 100755 --- a/generate/generate.sh +++ b/generate/generate.sh @@ -16,7 +16,7 @@ if [ -z "$TEMPLATES_PATH" ]; then die "TEMPLATES_PATH must be set, e.g. /path/to/sajari/sdk-node/generate/templates" fi -VERSION=4.5.2 +VERSION=4.6.2 docker-entrypoint.sh generate \ -i /openapi.json \ diff --git a/package-lock.json b/package-lock.json index de92a68..de91f1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@sajari/sdk-node", - "version": "4.5.2", + "version": "4.6.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7b18171..987c780 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sajari/sdk-node", - "version": "4.5.2", + "version": "4.6.2", "repository": "git@github.com:github.com/sajari/sdk-node.git", "author": "Search.io", "license": "MIT", diff --git a/src/generated/api/schemaApi.ts b/src/generated/api/schemaApi.ts index ff4a5a3..58a162e 100644 --- a/src/generated/api/schemaApi.ts +++ b/src/generated/api/schemaApi.ts @@ -345,6 +345,119 @@ export class SchemaApi { ); }); } + /** + * Deleting a schema field removes it from all records within the collection, however, references to the schema field in pipelines are not removed. > Note: This operation cannot be reversed. + * @summary Delete schema field + * @param collectionId The collection the schema field belongs to, e.g. `my-collection`. + * @param schemaFieldName The name of the schema field to delete. + */ + public async deleteSchemaField( + collectionId: string, + schemaFieldName: string, + options: { headers: { [name: string]: string } } = { headers: {} } + ): Promise<{ response: http.IncomingMessage; body: any }> { + const localVarPath = + this.basePath + + "/v4/collections/{collection_id}/schemaFields/{schema_field_name}" + .replace( + "{" + "collection_id" + "}", + encodeURIComponent(String(collectionId)) + ) + .replace( + "{" + "schema_field_name" + "}", + encodeURIComponent(String(schemaFieldName)) + ); + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign( + {}, + this._defaultHeaders + ); + const produces = ["application/json"]; + // give precedence to 'application/json' + if (produces.indexOf("application/json") >= 0) { + localVarHeaderParams.Accept = "application/json"; + } else { + localVarHeaderParams.Accept = produces.join(","); + } + let localVarFormParams: any = {}; + + // verify required parameter 'collectionId' is not null or undefined + if (collectionId === null || collectionId === undefined) { + throw new Error( + "Required parameter collectionId was null or undefined when calling deleteSchemaField." + ); + } + + // verify required parameter 'schemaFieldName' is not null or undefined + if (schemaFieldName === null || schemaFieldName === undefined) { + throw new Error( + "Required parameter schemaFieldName was null or undefined when calling deleteSchemaField." + ); + } + + (Object).assign(localVarHeaderParams, options.headers); + + let localVarUseFormData = false; + + let localVarRequestOptions: localVarRequest.Options = { + method: "DELETE", + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + }; + + let authenticationPromise = Promise.resolve(); + if ( + this.authentications.BasicAuth.username && + this.authentications.BasicAuth.password + ) { + authenticationPromise = authenticationPromise.then(() => + this.authentications.BasicAuth.applyToRequest(localVarRequestOptions) + ); + } + authenticationPromise = authenticationPromise.then(() => + this.authentications.default.applyToRequest(localVarRequestOptions) + ); + + let interceptorPromise = authenticationPromise; + for (const interceptor of this.interceptors) { + interceptorPromise = interceptorPromise.then(() => + interceptor(localVarRequestOptions) + ); + } + + return interceptorPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + return new Promise<{ response: http.IncomingMessage; body: any }>( + (resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if ( + response.statusCode && + response.statusCode >= 200 && + response.statusCode <= 299 + ) { + body = ObjectSerializer.deserialize(body, "any"); + resolve({ response: response, body: body }); + } else { + reject(new HttpError(response, body, response.statusCode)); + } + } + }); + } + ); + }); + } /** * Retrieve a list of schema fields in a collection. * @summary List schema fields @@ -469,4 +582,136 @@ export class SchemaApi { }); }); } + /** + * Update the details of a schema field. Only `name` and `description` can be updated. + * @summary Update schema field + * @param collectionId The collection the schema field belongs to, e.g. `my-collection`. + * @param schemaFieldName The name of the schema field to update. + * @param schemaField The schema field details to update. + * @param updateMask The list of fields to update, separated by a comma, e.g. `name,description`. Each field should be in snake case. For each field that you want to update, provide a corresponding value in the schema field object containing the new value. + */ + public async updateSchemaField( + collectionId: string, + schemaFieldName: string, + schemaField: SchemaField, + updateMask?: string, + options: { headers: { [name: string]: string } } = { headers: {} } + ): Promise<{ response: http.IncomingMessage; body: SchemaField }> { + const localVarPath = + this.basePath + + "/v4/collections/{collection_id}/schemaFields/{schema_field_name}" + .replace( + "{" + "collection_id" + "}", + encodeURIComponent(String(collectionId)) + ) + .replace( + "{" + "schema_field_name" + "}", + encodeURIComponent(String(schemaFieldName)) + ); + let localVarQueryParameters: any = {}; + let localVarHeaderParams: any = (Object).assign( + {}, + this._defaultHeaders + ); + const produces = ["application/json"]; + // give precedence to 'application/json' + if (produces.indexOf("application/json") >= 0) { + localVarHeaderParams.Accept = "application/json"; + } else { + localVarHeaderParams.Accept = produces.join(","); + } + let localVarFormParams: any = {}; + + // verify required parameter 'collectionId' is not null or undefined + if (collectionId === null || collectionId === undefined) { + throw new Error( + "Required parameter collectionId was null or undefined when calling updateSchemaField." + ); + } + + // verify required parameter 'schemaFieldName' is not null or undefined + if (schemaFieldName === null || schemaFieldName === undefined) { + throw new Error( + "Required parameter schemaFieldName was null or undefined when calling updateSchemaField." + ); + } + + // verify required parameter 'schemaField' is not null or undefined + if (schemaField === null || schemaField === undefined) { + throw new Error( + "Required parameter schemaField was null or undefined when calling updateSchemaField." + ); + } + + if (updateMask !== undefined) { + localVarQueryParameters["update_mask"] = ObjectSerializer.serialize( + updateMask, + "string" + ); + } + + (Object).assign(localVarHeaderParams, options.headers); + + let localVarUseFormData = false; + + let localVarRequestOptions: localVarRequest.Options = { + method: "PATCH", + qs: localVarQueryParameters, + headers: localVarHeaderParams, + uri: localVarPath, + useQuerystring: this._useQuerystring, + json: true, + body: ObjectSerializer.serialize(schemaField, "SchemaField"), + }; + + let authenticationPromise = Promise.resolve(); + if ( + this.authentications.BasicAuth.username && + this.authentications.BasicAuth.password + ) { + authenticationPromise = authenticationPromise.then(() => + this.authentications.BasicAuth.applyToRequest(localVarRequestOptions) + ); + } + authenticationPromise = authenticationPromise.then(() => + this.authentications.default.applyToRequest(localVarRequestOptions) + ); + + let interceptorPromise = authenticationPromise; + for (const interceptor of this.interceptors) { + interceptorPromise = interceptorPromise.then(() => + interceptor(localVarRequestOptions) + ); + } + + return interceptorPromise.then(() => { + if (Object.keys(localVarFormParams).length) { + if (localVarUseFormData) { + (localVarRequestOptions).formData = localVarFormParams; + } else { + localVarRequestOptions.form = localVarFormParams; + } + } + return new Promise<{ response: http.IncomingMessage; body: SchemaField }>( + (resolve, reject) => { + localVarRequest(localVarRequestOptions, (error, response, body) => { + if (error) { + reject(error); + } else { + if ( + response.statusCode && + response.statusCode >= 200 && + response.statusCode <= 299 + ) { + body = ObjectSerializer.deserialize(body, "SchemaField"); + resolve({ response: response, body: body }); + } else { + reject(new HttpError(response, body, response.statusCode)); + } + } + }); + } + ); + }); + } } diff --git a/src/schema.ts b/src/schema.ts index aee65aa..d3cd5c1 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -67,4 +67,36 @@ export class SchemaClient extends Client { throw handleError(e); } } + + async updateField( + fieldName: string, + field: SchemaField, + ...options: Array< + (updateMask?: Record) => void + > + ) { + const updateMask: Record = {}; + + for (const opt of options) { + opt(updateMask); + } + + const um = Object.keys(updateMask).map((field) => field); + + try { + const res = await this.client.updateSchemaField(this.collectionId, fieldName, field, um.join(",")); + return res.body; + } catch (e) { + throw handleError(e); + } + } + + async deleteField(fieldName: string) { + try { + const res = await this.client.deleteSchemaField(this.collectionId, fieldName); + return res.body; + } catch (e) { + throw handleError(e); + } + } } diff --git a/src/version.ts b/src/version.ts index 6647f64..a64a802 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,3 +1,3 @@ // Code generated by generate-version.ts. DO NOT EDIT. -export const version = "4.5.2"; +export const version = "4.6.2";