ibm-watson
Version:
Client library to use the IBM Watson Services
1,028 lines • 167 kB
JavaScript
"use strict";
/**
* (C) Copyright IBM Corp. 2019, 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* IBM OpenAPI SDK Code Generator Version: 3.96.1-5136e54a-20241108-203028
*/
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* IBM Watson® Discovery is a cognitive search and content analytics engine that you can add to applications to
* identify patterns, trends and actionable insights to drive better decision-making. Securely unify structured and
* unstructured data with pre-enriched content, and use a simplified query language to eliminate the need for manual
* filtering of results.
*
* API Version: 2.0
* See: https://cloud.ibm.com/docs/discovery-data
*/
var DiscoveryV2 = /** @class */ (function (_super) {
__extends(DiscoveryV2, _super);
/**
* Construct a DiscoveryV2 object.
*
* @param {Object} options - Options for the service.
* @param {string} options.version - Release date of the version of the API you want to use. Specify dates in
* YYYY-MM-DD format. The current version is `2023-03-31`.
* @param {string} [options.serviceUrl] - The base URL for the service
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service. Defaults to environment if not set
* @constructor
* @returns {DiscoveryV2}
*/
function DiscoveryV2(options) {
var _this = this;
options = options || {};
var _requiredParams = ['version'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(options, _requiredParams, null);
if (_validationErrors) {
throw _validationErrors;
}
if (!options.serviceName) {
options.serviceName = DiscoveryV2.DEFAULT_SERVICE_NAME;
}
// If the caller didn't supply an authenticator, construct one from external configuration.
if (!options.authenticator) {
options.authenticator = (0, ibm_cloud_sdk_core_1.getAuthenticatorFromEnvironment)(options.serviceName);
}
_this = _super.call(this, options) || this;
_this.configureService(options.serviceName);
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
_this.version = options.version;
return _this;
}
/*************************
* projects
************************/
/**
* List projects.
*
* Lists existing projects for this instance.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ListProjectsResponse>>}
*/
DiscoveryV2.prototype.listProjects = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'listProjects');
var parameters = {
options: {
url: '/v2/projects',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create a project.
*
* Create a new project for this instance.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.name - The human readable name of this project.
* @param {string} params.type - The type of project.
*
* The `content_intelligence` type is a *Document Retrieval for Contracts* project and the `other` type is a *Custom*
* project.
*
* The `content_mining` and `content_intelligence` types are available with Premium plan managed deployments and
* installed deployments only.
*
* The Intelligent Document Processing (IDP) project type is available from IBM Cloud-managed instances only.
* @param {DefaultQueryParams} [params.defaultQueryParameters] - Default query parameters for this project.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ProjectDetails>>}
*/
DiscoveryV2.prototype.createProject = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['name', 'type'];
var _validParams = ['name', 'type', 'defaultQueryParameters', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'type': _params.type,
'default_query_parameters': _params.defaultQueryParameters,
};
var query = {
'version': this.version,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'createProject');
var parameters = {
options: {
url: '/v2/projects',
method: 'POST',
body: body,
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get project.
*
* Get details on the specified project.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ProjectDetails>>}
*/
DiscoveryV2.prototype.getProject = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId'];
var _validParams = ['projectId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'getProject');
var parameters = {
options: {
url: '/v2/projects/{project_id}',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update a project.
*
* Update the specified project's name.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} [params.name] - The new name to give this project.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ProjectDetails>>}
*/
DiscoveryV2.prototype.updateProject = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId'];
var _validParams = ['projectId', 'name', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
};
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'updateProject');
var parameters = {
options: {
url: '/v2/projects/{project_id}',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete a project.
*
* Deletes the specified project.
*
* **Important:** Deleting a project deletes everything that is part of the specified project, including all
* collections.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.EmptyObject>>}
*/
DiscoveryV2.prototype.deleteProject = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId'];
var _validParams = ['projectId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteProject');
var parameters = {
options: {
url: '/v2/projects/{project_id}',
method: 'DELETE',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* List fields.
*
* Gets a list of the unique fields (and their types) stored in the specified collections.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string[]} [params.collectionIds] - Comma separated list of the collection IDs. If this parameter is not
* specified, all collections in the project are used.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ListFieldsResponse>>}
*/
DiscoveryV2.prototype.listFields = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId'];
var _validParams = ['projectId', 'collectionIds', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'collection_ids': _params.collectionIds,
};
var path = {
'project_id': _params.projectId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'listFields');
var parameters = {
options: {
url: '/v2/projects/{project_id}/fields',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* collections
************************/
/**
* List collections.
*
* Lists existing collections for the specified project.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ListCollectionsResponse>>}
*/
DiscoveryV2.prototype.listCollections = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId'];
var _validParams = ['projectId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'listCollections');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Create a collection.
*
* Create a new collection in the specified project.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.name - The name of the collection.
* @param {string} [params.description] - A description of the collection.
* @param {string} [params.language] - The language of the collection. For a list of supported languages, see the
* [product documentation](/docs/discovery-data?topic=discovery-data-language-support).
* @param {boolean} [params.ocrEnabled] - If set to `true`, optical character recognition (OCR) is enabled. For more
* information, see [Optical character recognition](/docs/discovery-data?topic=discovery-data-collections#ocr).
* @param {CollectionEnrichment[]} [params.enrichments] - An array of enrichments that are applied to this collection.
* To get a list of enrichments that are available for a project, use the [List enrichments](#listenrichments) method.
*
* If no enrichments are specified when the collection is created, the default enrichments for the project type are
* applied. For more information about project default settings, see the [product
* documentation](/docs/discovery-data?topic=discovery-data-project-defaults).
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>>}
*/
DiscoveryV2.prototype.createCollection = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'name'];
var _validParams = ['projectId', 'name', 'description', 'language', 'ocrEnabled', 'enrichments', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'description': _params.description,
'language': _params.language,
'ocr_enabled': _params.ocrEnabled,
'enrichments': _params.enrichments,
};
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'createCollection');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get collection details.
*
* Get details about the specified collection.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>>}
*/
DiscoveryV2.prototype.getCollection = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId'];
var _validParams = ['projectId', 'collectionId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'getCollection');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update a collection.
*
* Updates the specified collection's name, description, enrichments, and configuration.
*
* If you apply normalization rules to data in an existing collection, you must initiate reprocessing of the
* collection. To do so, from the *Manage fields* page in the product user interface, temporarily change the data type
* of a field to enable the reprocess button. Change the data type of the field back to its original value, and then
* click **Apply changes and reprocess**.
*
* To remove a configuration that applies JSON normalization operations as part of the conversion phase of ingestion,
* specify an empty `json_normalizations` object (`[]`) in the request.
*
* To remove a configuration that applies JSON normalization operations after enrichments are applied, specify an
* empty `normalizations` object (`[]`) in the request.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {string} [params.name] - The new name of the collection.
* @param {string} [params.description] - The new description of the collection.
* @param {boolean} [params.ocrEnabled] - If set to `true`, optical character recognition (OCR) is enabled. For more
* information, see [Optical character recognition](/docs/discovery-data?topic=discovery-data-collections#ocr).
* @param {CollectionEnrichment[]} [params.enrichments] - An array of enrichments that are applied to this collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.CollectionDetails>>}
*/
DiscoveryV2.prototype.updateCollection = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId'];
var _validParams = ['projectId', 'collectionId', 'name', 'description', 'ocrEnabled', 'enrichments', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'name': _params.name,
'description': _params.description,
'ocr_enabled': _params.ocrEnabled,
'enrichments': _params.enrichments,
};
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'updateCollection');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete a collection.
*
* Deletes the specified collection from the project. All documents stored in the specified collection and not shared
* is also deleted.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.EmptyObject>>}
*/
DiscoveryV2.prototype.deleteCollection = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId'];
var _validParams = ['projectId', 'collectionId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteCollection');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}',
method: 'DELETE',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* documents
************************/
/**
* List documents.
*
* Lists the documents in the specified collection. The list includes only the document ID of each document and
* returns information for up to 10,000 documents.
*
* **Note**: This method is available only from Cloud Pak for Data version 4.0.9 and later installed instances, and
* from IBM Cloud-managed instances.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {number} [params.count] - The maximum number of documents to return. Up to 1,000 documents are returned by
* default. The maximum number allowed is 10,000.
* @param {string} [params.status] - Filters the documents to include only documents with the specified ingestion
* status. The options include:
*
* * `available`: Ingestion is finished and the document is indexed.
*
* * `failed`: Ingestion is finished, but the document is not indexed because of an error.
*
* * `pending`: The document is uploaded, but the ingestion process is not started.
*
* * `processing`: Ingestion is in progress.
*
* You can specify one status value or add a comma-separated list of more than one status value. For example,
* `available,failed`.
* @param {boolean} [params.hasNotices] - If set to `true`, only documents that have notices, meaning documents for
* which warnings or errors were generated during the ingestion, are returned. If set to `false`, only documents that
* don't have notices are returned. If unspecified, no filter based on notices is applied.
*
* Notice details are not available in the result, but you can use the [Query collection
* notices](#querycollectionnotices) method to find details by adding the parameter
* `query=notices.document_id:{document-id}`.
* @param {boolean} [params.isParent] - If set to `true`, only parent documents, meaning documents that were split
* during the ingestion process and resulted in two or more child documents, are returned. If set to `false`, only
* child documents are returned. If unspecified, no filter based on the parent or child relationship is applied.
*
* CSV files, for example, are split into separate documents per line and JSON files are split into separate documents
* per object.
* @param {string} [params.parentDocumentId] - Filters the documents to include only child documents that were
* generated when the specified parent document was processed.
* @param {string} [params.sha256] - Filters the documents to include only documents with the specified SHA-256 hash.
* Format the hash as a hexadecimal string.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.ListDocumentsResponse>>}
*/
DiscoveryV2.prototype.listDocuments = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId'];
var _validParams = ['projectId', 'collectionId', 'count', 'status', 'hasNotices', 'isParent', 'parentDocumentId', 'sha256', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'count': _params.count,
'status': _params.status,
'has_notices': _params.hasNotices,
'is_parent': _params.isParent,
'parent_document_id': _params.parentDocumentId,
'sha256': _params.sha256,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'listDocuments');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}/documents',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Add a document.
*
* Add a document to a collection with optional metadata.
*
* Returns immediately after the system has accepted the document for processing.
*
* Use this method to upload a file to the collection. You cannot use this method to crawl an external data source.
*
* * For a list of supported file types, see the [product
* documentation](/docs/discovery-data?topic=discovery-data-collections#supportedfiletypes).
*
* * You must provide document content, metadata, or both. If the request is missing both document content and
* metadata, it is rejected.
*
* * You can set the **Content-Type** parameter on the **file** part to indicate the media type of the document. If
* the **Content-Type** parameter is missing or is one of the generic media types (for example,
* `application/octet-stream`), then the service attempts to automatically detect the document's media type.
*
* * If the document is uploaded to a collection that shares its data with another collection, the
* **X-Watson-Discovery-Force** header must be set to `true`.
*
* * In curl requests only, you can assign an ID to a document that you add by appending the ID to the endpoint
* (`/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}`). If a document already exists
* with the specified ID, it is replaced.
*
* For more information about how certain file types and field names are handled when a file is added to a collection,
* see the [product documentation](/docs/discovery-data?topic=discovery-data-index-overview#field-name-limits).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {NodeJS.ReadableStream | Buffer} [params.file] - **Add a document**: The content of the document to ingest.
* For the supported file types and maximum supported file size limits when adding a document, see [the
* documentation](/docs/discovery-data?topic=discovery-data-collections#supportedfiletypes).
*
* **Analyze a document**: The content of the document to analyze but not ingest. Only the `application/json` content
* type is supported by the Analyze API. For maximum supported file size limits, see [the product
* documentation](/docs/discovery-data?topic=discovery-data-analyzeapi#analyzeapi-limits).
* @param {string} [params.filename] - The filename for file.
* @param {string} [params.fileContentType] - The content type of file.
* @param {string} [params.metadata] - Add information about the file that you want to include in the response.
*
* The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB are rejected.
*
* Example:
*
* ```
* {
* "filename": "favorites2.json",
* "file_type": "json"
* }.
* @param {boolean} [params.xWatsonDiscoveryForce] - When `true`, the uploaded document is added to the collection
* even if the data for that collection is shared with other collections.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.DocumentAccepted>>}
*/
DiscoveryV2.prototype.addDocument = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId'];
var _validParams = ['projectId', 'collectionId', 'file', 'filename', 'fileContentType', 'metadata', 'xWatsonDiscoveryForce', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var formData = {
'file': {
data: _params.file,
filename: _params.filename,
contentType: _params.fileContentType,
},
'metadata': _params.metadata,
};
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'addDocument');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}/documents',
method: 'POST',
qs: query,
path: path,
formData: formData
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'X-Watson-Discovery-Force': _params.xWatsonDiscoveryForce,
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Get document details.
*
* Get details about a specific document, whether the document is added by uploading a file or by crawling an external
* data source.
*
* **Note**: This method is available only from Cloud Pak for Data version 4.0.9 and later installed instances, and
* from IBM Cloud-managed instances.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {string} params.documentId - The ID of the document.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.DocumentDetails>>}
*/
DiscoveryV2.prototype.getDocument = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId', 'documentId'];
var _validParams = ['projectId', 'collectionId', 'documentId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
'document_id': _params.documentId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'getDocument');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update a document.
*
* Replace an existing document or add a document with a specified document ID. Starts ingesting a document with
* optional metadata.
*
* Use this method to upload a file to a collection. You cannot use this method to crawl an external data source.
*
* If the document is uploaded to a collection that shares its data with another collection, the
* **X-Watson-Discovery-Force** header must be set to `true`.
*
* **Notes:**
*
* * Uploading a new document with this method automatically replaces any existing document stored with the same
* document ID.
*
* * If an uploaded document is split into child documents during ingestion, all existing child documents are
* overwritten, even if the updated version of the document has fewer child documents.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {string} params.documentId - The ID of the document.
* @param {NodeJS.ReadableStream | Buffer} [params.file] - **Add a document**: The content of the document to ingest.
* For the supported file types and maximum supported file size limits when adding a document, see [the
* documentation](/docs/discovery-data?topic=discovery-data-collections#supportedfiletypes).
*
* **Analyze a document**: The content of the document to analyze but not ingest. Only the `application/json` content
* type is supported by the Analyze API. For maximum supported file size limits, see [the product
* documentation](/docs/discovery-data?topic=discovery-data-analyzeapi#analyzeapi-limits).
* @param {string} [params.filename] - The filename for file.
* @param {string} [params.fileContentType] - The content type of file.
* @param {string} [params.metadata] - Add information about the file that you want to include in the response.
*
* The maximum supported metadata file size is 1 MB. Metadata parts larger than 1 MB are rejected.
*
* Example:
*
* ```
* {
* "filename": "favorites2.json",
* "file_type": "json"
* }.
* @param {boolean} [params.xWatsonDiscoveryForce] - When `true`, the uploaded document is added to the collection
* even if the data for that collection is shared with other collections.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.DocumentAccepted>>}
*/
DiscoveryV2.prototype.updateDocument = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId', 'documentId'];
var _validParams = ['projectId', 'collectionId', 'documentId', 'file', 'filename', 'fileContentType', 'metadata', 'xWatsonDiscoveryForce', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var formData = {
'file': {
data: _params.file,
filename: _params.filename,
contentType: _params.fileContentType,
},
'metadata': _params.metadata,
};
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
'document_id': _params.documentId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'updateDocument');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}',
method: 'POST',
qs: query,
path: path,
formData: formData
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
'X-Watson-Discovery-Force': _params.xWatsonDiscoveryForce,
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete a document.
*
* Deletes the document with the document ID that you specify from the collection. Removes uploaded documents from the
* collection permanently. If you delete a document that was added by crawling an external data source, the document
* will be added again with the next scheduled crawl of the data source. The delete function removes the document from
* the collection, not from the external data source.
*
* **Note:** Files such as CSV or JSON files generate subdocuments when they are added to a collection. If you delete
* a subdocument, and then repeat the action that created it, the deleted document is added back in to your
* collection. To remove subdocuments that are generated by an uploaded file, delete the original document instead.
* You can get the document ID of the original document from the `parent_document_id` of the subdocument result.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string} params.collectionId - The Universally Unique Identifier (UUID) of the collection.
* @param {string} params.documentId - The ID of the document.
* @param {boolean} [params.xWatsonDiscoveryForce] - When `true`, the uploaded document is added to the collection
* even if the data for that collection is shared with other collections.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<DiscoveryV2.Response<DiscoveryV2.DeleteDocumentResponse>>}
*/
DiscoveryV2.prototype.deleteDocument = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['projectId', 'collectionId', 'documentId'];
var _validParams = ['projectId', 'collectionId', 'documentId', 'xWatsonDiscoveryForce', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'project_id': _params.projectId,
'collection_id': _params.collectionId,
'document_id': _params.documentId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(DiscoveryV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteDocument');
var parameters = {
options: {
url: '/v2/projects/{project_id}/collections/{collection_id}/documents/{document_id}',
method: 'DELETE',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'X-Watson-Discovery-Force': _params.xWatsonDiscoveryForce,
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* queries
************************/
/**
* Query a project.
*
* Search your data by submitting queries that are written in natural language or formatted in the Discovery Query
* Language. For more information, see the [Discovery
* documentation](/docs/discovery-data?topic=discovery-data-query-concepts). The default query parameters differ by
* project type. For more information about the project default settings, see the [Discovery
* documentation](/docs/discovery-data?topic=discovery-data-query-defaults). See [the Projects API
* documentation](#create-project) for details about how to set custom default query settings.
*
* The length of the UTF-8 encoding of the POST body cannot exceed 10,000 bytes, which is roughly equivalent to 10,000
* characters in English.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.projectId - The Universally Unique Identifier (UUID) of the project. This information can be
* found from the *Integrate and Deploy* page in Discovery.
* @param {string[]} [params.collectionIds] - A comma-separated list of collection IDs to be queried against.
* @param {string} [params.filter] - Searches for documents that match the Discovery Query Language criteria that is
* specified as input. Filter calls are cached and are faster than query calls because the results are not ordered by
* relevance. When used with the **aggregation**, **query**, or **natural_language_query** parameters, the **filter**
* parameter runs first. This parameter is useful for limiting results to those that contain specific metadata values.
* @param