UNPKG

@azure/search-documents

Version:
100 lines (99 loc) 3.02 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var indexDocumentsBatch_exports = {}; __export(indexDocumentsBatch_exports, { IndexDocumentsBatch: () => IndexDocumentsBatch }); module.exports = __toCommonJS(indexDocumentsBatch_exports); class IndexDocumentsBatch { /** * The set of actions taken in this batch. */ actions; constructor(actions = []) { this.actions = actions; } /** * Upload an array of documents to the index. * @param documents - The documents to upload. */ upload(documents) { const batch = documents.map((doc) => { return { ...doc, __actionType: "upload" }; }); this.actions.push(...batch); } /** * Update a set of documents in the index. For more details about how merging works, see * https://learn.microsoft.com/rest/api/searchservice/AddUpdate-or-Delete-Documents * @param documents - The updated documents. */ merge(documents) { const batch = documents.map((doc) => { return { ...doc, __actionType: "merge" }; }); this.actions.push(...batch); } /** * Update a set of documents in the index or uploads them if they don't exist. For more details * about how merging works, see * https://learn.microsoft.com/rest/api/searchservice/AddUpdate-or-Delete-Documents * @param documents - The new/updated documents. */ mergeOrUpload(documents) { const batch = documents.map((doc) => { return { ...doc, __actionType: "mergeOrUpload" }; }); this.actions.push(...batch); } delete(keyNameOrDocuments, keyValues) { if (keyValues) { const keyName = keyNameOrDocuments; const batch = keyValues.map((keyValue) => { return { __actionType: "delete", [keyName]: keyValue }; }); this.actions.push(...batch); } else { const documents = keyNameOrDocuments; const batch = documents.map((document) => { return { __actionType: "delete", ...document }; }); this.actions.push(...batch); } } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { IndexDocumentsBatch }); //# sourceMappingURL=indexDocumentsBatch.js.map