@sebspark/opensearch 0.3.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -72
- package/dist/index.d.mts +484 -263
- package/dist/index.d.ts +484 -263
- package/dist/index.js +45 -193
- package/dist/index.mjs +37 -179
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,208 +15,62 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
OpenSearchClient: () => OpenSearchClient,
|
|
24
|
+
bulkCreate: () => bulkCreate,
|
|
25
|
+
bulkDelete: () => bulkDelete,
|
|
26
|
+
bulkIndex: () => bulkIndex,
|
|
27
|
+
bulkUpdate: () => bulkUpdate
|
|
34
28
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
30
|
|
|
37
|
-
// src/
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var omitId = (0, import_omit.default)("id");
|
|
43
|
-
var fixIds = (searchQuery) => {
|
|
44
|
-
const { query: q, _source, from, size, sort } = searchQuery.body;
|
|
45
|
-
const body = {
|
|
46
|
-
query: {
|
|
47
|
-
ids: q.ids,
|
|
48
|
-
bool: q.bool ? fixBool(q.bool) : void 0,
|
|
49
|
-
match: q.match ? fixId(q.match) : void 0,
|
|
50
|
-
collapse: q.collapse,
|
|
51
|
-
exists: q.exists ? fixExists(q.exists) : void 0,
|
|
52
|
-
filter: q.filter ? fixFilter(q.filter) : void 0,
|
|
53
|
-
fuzzy: q.fuzzy ? fixId(q.fuzzy) : void 0,
|
|
54
|
-
highlight: q.highlight,
|
|
55
|
-
match_all: q.match_all,
|
|
56
|
-
match_phrase: q.match_phrase ? fixId(q.match_phrase) : void 0,
|
|
57
|
-
match_phrase_prefix: q.match_phrase_prefix ? fixId(q.match_phrase_prefix) : void 0,
|
|
58
|
-
more_like_this: q.more_like_this ? fixWithFields(q.more_like_this) : void 0,
|
|
59
|
-
multi_match: q.multi_match ? fixId(q.multi_match) : void 0,
|
|
60
|
-
prefix: q.prefix ? fixId(q.prefix) : void 0,
|
|
61
|
-
range: q.range ? fixId(q.range) : void 0,
|
|
62
|
-
regexp: q.regexp ? fixId(q.regexp) : void 0,
|
|
63
|
-
script_score: q.script_score,
|
|
64
|
-
term: q.term ? fixId(q.term) : void 0,
|
|
65
|
-
terms: q.terms ? fixId(q.terms) : void 0,
|
|
66
|
-
wildcard: q.wildcard ? fixId(q.wildcard) : void 0
|
|
67
|
-
},
|
|
68
|
-
_source,
|
|
69
|
-
from,
|
|
70
|
-
size,
|
|
71
|
-
sort: sort ? fixId(sort) : void 0
|
|
72
|
-
};
|
|
73
|
-
return {
|
|
74
|
-
...searchQuery,
|
|
75
|
-
body: clean(body)
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
var fixBool = (bool) => ({
|
|
79
|
-
...bool,
|
|
80
|
-
filter: bool.filter ? Array.isArray(bool.filter) ? bool.filter.map(fixFilter) : fixFilter(bool.filter) : void 0,
|
|
81
|
-
boost: bool.boost,
|
|
82
|
-
minimum_should_match: bool.minimum_should_match,
|
|
83
|
-
must: bool.must ? Array.isArray(bool.must) ? bool.must.map(fixFilter) : fixFilter(bool.must) : void 0,
|
|
84
|
-
must_not: bool.must_not ? Array.isArray(bool.must_not) ? bool.must_not.map(fixFilter) : fixFilter(bool.must_not) : void 0,
|
|
85
|
-
should: bool.should ? Array.isArray(bool.should) ? bool.should.map(fixFilter) : fixFilter(bool.should) : void 0
|
|
86
|
-
});
|
|
87
|
-
var fixFilter = (filter) => clean({
|
|
88
|
-
bool: filter.bool ? fixBool(filter.bool) : void 0,
|
|
89
|
-
exists: filter.exists ? fixExists(filter.exists) : void 0,
|
|
90
|
-
fuzzy: filter.fuzzy ? fixId(filter.fuzzy) : void 0,
|
|
91
|
-
match: filter.match ? fixId(filter.match) : void 0,
|
|
92
|
-
match_phrase: filter.match_phrase ? fixId(filter.match_phrase) : void 0,
|
|
93
|
-
multi_match: filter.multi_match ? fixId(filter.multi_match) : void 0,
|
|
94
|
-
match_phrase_prefix: filter.match_phrase_prefix ? fixId(filter.match_phrase_prefix) : void 0,
|
|
95
|
-
prefix: filter.prefix ? fixId(filter.prefix) : void 0,
|
|
96
|
-
query_string: filter.query_string ? fixWithFields(filter.query_string) : void 0,
|
|
97
|
-
range: filter.range ? fixId(filter.range) : void 0,
|
|
98
|
-
regexp: filter.regexp ? fixId(filter.regexp) : void 0,
|
|
99
|
-
simple_query_string: filter.simple_query_string ? fixWithFields(filter.simple_query_string) : void 0,
|
|
100
|
-
term: filter.term ? fixId(filter.term) : void 0,
|
|
101
|
-
terms: filter.terms ? fixId(filter.terms) : void 0,
|
|
102
|
-
wildcard: filter.wildcard ? fixId(filter.wildcard) : void 0
|
|
103
|
-
});
|
|
104
|
-
var fixWithFields = (old) => ({
|
|
105
|
-
...old,
|
|
106
|
-
fields: old.fields ? old.fields.map(fixIdValue) : void 0
|
|
107
|
-
});
|
|
108
|
-
var fixExists = (exists) => ({
|
|
109
|
-
...exists,
|
|
110
|
-
field: fixIdValue(exists.field)
|
|
111
|
-
});
|
|
112
|
-
var fixId = (old) => {
|
|
113
|
-
const fixed = omitId(old);
|
|
114
|
-
if (old.id) fixed._id = old.id;
|
|
115
|
-
return fixed;
|
|
116
|
-
};
|
|
117
|
-
var fixIdValue = (val) => val === "id" ? "_id" : val;
|
|
118
|
-
var clean = (obj) => {
|
|
119
|
-
const cleaned = JSON.parse(JSON.stringify(obj));
|
|
120
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
121
|
-
if (Array.isArray(value)) {
|
|
122
|
-
cleaned[key] = value.filter(Boolean);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return cleaned;
|
|
31
|
+
// src/client.ts
|
|
32
|
+
var import_opensearch = require("@opensearch-project/opensearch");
|
|
33
|
+
var OpenSearchClient = function(...args) {
|
|
34
|
+
const clientInstance = new import_opensearch.Client(...args);
|
|
35
|
+
return clientInstance;
|
|
126
36
|
};
|
|
127
37
|
|
|
128
|
-
// src/
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const results = response.body.hits.hits.map(
|
|
134
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
135
|
-
(hit) => ({
|
|
136
|
-
id: hit._id,
|
|
137
|
-
...hit._source
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
return { results, response };
|
|
141
|
-
};
|
|
142
|
-
var typedIndex = async (client, index, data) => {
|
|
143
|
-
const { id, ...body } = data;
|
|
144
|
-
const response = await client.index({
|
|
145
|
-
index,
|
|
146
|
-
id,
|
|
147
|
-
body,
|
|
148
|
-
refresh: true
|
|
149
|
-
// Adjust based on your requirement
|
|
38
|
+
// src/helpers.ts
|
|
39
|
+
function bulkIndex(index, docs, idFn) {
|
|
40
|
+
const body = docs.flatMap((doc) => {
|
|
41
|
+
const op = idFn ? { _id: idFn(doc) } : {};
|
|
42
|
+
return [{ index: op }, doc];
|
|
150
43
|
});
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
id,
|
|
158
|
-
body: {
|
|
159
|
-
doc,
|
|
160
|
-
doc_as_upsert: true
|
|
161
|
-
}
|
|
44
|
+
return { index, body };
|
|
45
|
+
}
|
|
46
|
+
function bulkCreate(index, docs, idFn) {
|
|
47
|
+
const body = docs.flatMap((doc) => {
|
|
48
|
+
const op = { _id: idFn(doc) };
|
|
49
|
+
return [{ create: op }, doc];
|
|
162
50
|
});
|
|
163
|
-
return
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const body =
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
];
|
|
51
|
+
return { index, body };
|
|
52
|
+
}
|
|
53
|
+
function bulkUpdate(index, updates, idFn) {
|
|
54
|
+
const body = updates.flatMap((update) => {
|
|
55
|
+
const op = {
|
|
56
|
+
_id: idFn(update.doc || update.upsert)
|
|
57
|
+
};
|
|
58
|
+
return [{ update: op }, update];
|
|
172
59
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
(value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
(0, import_node_assert.default)(
|
|
183
|
-
isLeafNode({
|
|
184
|
-
type: "nested",
|
|
185
|
-
properties: { name: { type: "keyword" }, type: { type: "keyword" } }
|
|
186
|
-
})
|
|
187
|
-
);
|
|
188
|
-
var flattenObject = (obj, parentKey = "", result = {}) => {
|
|
189
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
190
|
-
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
|
191
|
-
if (typeof value === "object" && value !== null && !isLeafNode(value)) {
|
|
192
|
-
flattenObject(value, newKey, result);
|
|
193
|
-
} else {
|
|
194
|
-
result[newKey] = value;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return result;
|
|
198
|
-
};
|
|
199
|
-
var typedIndexCreate = async (client, index, { mappings, ...props }) => {
|
|
200
|
-
const { body: exists } = await client.indices.exists({ index });
|
|
201
|
-
if (exists) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const response = await client.indices.create({
|
|
205
|
-
index,
|
|
206
|
-
body: {
|
|
207
|
-
...props,
|
|
208
|
-
mappings: (mappings == null ? void 0 : mappings.properties) ? { properties: flattenObject(mappings.properties) } : void 0
|
|
209
|
-
}
|
|
60
|
+
return { index, body };
|
|
61
|
+
}
|
|
62
|
+
function bulkDelete(index, ids) {
|
|
63
|
+
const body = ids.map((_id) => {
|
|
64
|
+
const op = { _id };
|
|
65
|
+
return { delete: op };
|
|
210
66
|
});
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
var helper = (client) => ({
|
|
214
|
-
...client,
|
|
215
|
-
typedBulkUpsert: (index, data) => typedBulkUpsert(client, index, data),
|
|
216
|
-
typedIndexCreate: (index, options) => typedIndexCreate(client, index, options),
|
|
217
|
-
typedIndex: (index, data) => typedIndex(client, index, data),
|
|
218
|
-
typedSearch: (query) => typedSearch(client, query),
|
|
219
|
-
typedUpsert: (index, data) => typedUpsert(client, index, data)
|
|
220
|
-
});
|
|
67
|
+
return { index, body };
|
|
68
|
+
}
|
|
221
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
70
|
0 && (module.exports = {
|
|
223
|
-
|
|
71
|
+
OpenSearchClient,
|
|
72
|
+
bulkCreate,
|
|
73
|
+
bulkDelete,
|
|
74
|
+
bulkIndex,
|
|
75
|
+
bulkUpdate
|
|
224
76
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,187 +1,45 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var omitId = omit("id");
|
|
7
|
-
var fixIds = (searchQuery) => {
|
|
8
|
-
const { query: q, _source, from, size, sort } = searchQuery.body;
|
|
9
|
-
const body = {
|
|
10
|
-
query: {
|
|
11
|
-
ids: q.ids,
|
|
12
|
-
bool: q.bool ? fixBool(q.bool) : void 0,
|
|
13
|
-
match: q.match ? fixId(q.match) : void 0,
|
|
14
|
-
collapse: q.collapse,
|
|
15
|
-
exists: q.exists ? fixExists(q.exists) : void 0,
|
|
16
|
-
filter: q.filter ? fixFilter(q.filter) : void 0,
|
|
17
|
-
fuzzy: q.fuzzy ? fixId(q.fuzzy) : void 0,
|
|
18
|
-
highlight: q.highlight,
|
|
19
|
-
match_all: q.match_all,
|
|
20
|
-
match_phrase: q.match_phrase ? fixId(q.match_phrase) : void 0,
|
|
21
|
-
match_phrase_prefix: q.match_phrase_prefix ? fixId(q.match_phrase_prefix) : void 0,
|
|
22
|
-
more_like_this: q.more_like_this ? fixWithFields(q.more_like_this) : void 0,
|
|
23
|
-
multi_match: q.multi_match ? fixId(q.multi_match) : void 0,
|
|
24
|
-
prefix: q.prefix ? fixId(q.prefix) : void 0,
|
|
25
|
-
range: q.range ? fixId(q.range) : void 0,
|
|
26
|
-
regexp: q.regexp ? fixId(q.regexp) : void 0,
|
|
27
|
-
script_score: q.script_score,
|
|
28
|
-
term: q.term ? fixId(q.term) : void 0,
|
|
29
|
-
terms: q.terms ? fixId(q.terms) : void 0,
|
|
30
|
-
wildcard: q.wildcard ? fixId(q.wildcard) : void 0
|
|
31
|
-
},
|
|
32
|
-
_source,
|
|
33
|
-
from,
|
|
34
|
-
size,
|
|
35
|
-
sort: sort ? fixId(sort) : void 0
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
...searchQuery,
|
|
39
|
-
body: clean(body)
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
var fixBool = (bool) => ({
|
|
43
|
-
...bool,
|
|
44
|
-
filter: bool.filter ? Array.isArray(bool.filter) ? bool.filter.map(fixFilter) : fixFilter(bool.filter) : void 0,
|
|
45
|
-
boost: bool.boost,
|
|
46
|
-
minimum_should_match: bool.minimum_should_match,
|
|
47
|
-
must: bool.must ? Array.isArray(bool.must) ? bool.must.map(fixFilter) : fixFilter(bool.must) : void 0,
|
|
48
|
-
must_not: bool.must_not ? Array.isArray(bool.must_not) ? bool.must_not.map(fixFilter) : fixFilter(bool.must_not) : void 0,
|
|
49
|
-
should: bool.should ? Array.isArray(bool.should) ? bool.should.map(fixFilter) : fixFilter(bool.should) : void 0
|
|
50
|
-
});
|
|
51
|
-
var fixFilter = (filter) => clean({
|
|
52
|
-
bool: filter.bool ? fixBool(filter.bool) : void 0,
|
|
53
|
-
exists: filter.exists ? fixExists(filter.exists) : void 0,
|
|
54
|
-
fuzzy: filter.fuzzy ? fixId(filter.fuzzy) : void 0,
|
|
55
|
-
match: filter.match ? fixId(filter.match) : void 0,
|
|
56
|
-
match_phrase: filter.match_phrase ? fixId(filter.match_phrase) : void 0,
|
|
57
|
-
multi_match: filter.multi_match ? fixId(filter.multi_match) : void 0,
|
|
58
|
-
match_phrase_prefix: filter.match_phrase_prefix ? fixId(filter.match_phrase_prefix) : void 0,
|
|
59
|
-
prefix: filter.prefix ? fixId(filter.prefix) : void 0,
|
|
60
|
-
query_string: filter.query_string ? fixWithFields(filter.query_string) : void 0,
|
|
61
|
-
range: filter.range ? fixId(filter.range) : void 0,
|
|
62
|
-
regexp: filter.regexp ? fixId(filter.regexp) : void 0,
|
|
63
|
-
simple_query_string: filter.simple_query_string ? fixWithFields(filter.simple_query_string) : void 0,
|
|
64
|
-
term: filter.term ? fixId(filter.term) : void 0,
|
|
65
|
-
terms: filter.terms ? fixId(filter.terms) : void 0,
|
|
66
|
-
wildcard: filter.wildcard ? fixId(filter.wildcard) : void 0
|
|
67
|
-
});
|
|
68
|
-
var fixWithFields = (old) => ({
|
|
69
|
-
...old,
|
|
70
|
-
fields: old.fields ? old.fields.map(fixIdValue) : void 0
|
|
71
|
-
});
|
|
72
|
-
var fixExists = (exists) => ({
|
|
73
|
-
...exists,
|
|
74
|
-
field: fixIdValue(exists.field)
|
|
75
|
-
});
|
|
76
|
-
var fixId = (old) => {
|
|
77
|
-
const fixed = omitId(old);
|
|
78
|
-
if (old.id) fixed._id = old.id;
|
|
79
|
-
return fixed;
|
|
80
|
-
};
|
|
81
|
-
var fixIdValue = (val) => val === "id" ? "_id" : val;
|
|
82
|
-
var clean = (obj) => {
|
|
83
|
-
const cleaned = JSON.parse(JSON.stringify(obj));
|
|
84
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
85
|
-
if (Array.isArray(value)) {
|
|
86
|
-
cleaned[key] = value.filter(Boolean);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return cleaned;
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import { Client } from "@opensearch-project/opensearch";
|
|
3
|
+
var OpenSearchClient = function(...args) {
|
|
4
|
+
const clientInstance = new Client(...args);
|
|
5
|
+
return clientInstance;
|
|
90
6
|
};
|
|
91
7
|
|
|
92
|
-
// src/
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const results = response.body.hits.hits.map(
|
|
98
|
-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
99
|
-
(hit) => ({
|
|
100
|
-
id: hit._id,
|
|
101
|
-
...hit._source
|
|
102
|
-
})
|
|
103
|
-
);
|
|
104
|
-
return { results, response };
|
|
105
|
-
};
|
|
106
|
-
var typedIndex = async (client, index, data) => {
|
|
107
|
-
const { id, ...body } = data;
|
|
108
|
-
const response = await client.index({
|
|
109
|
-
index,
|
|
110
|
-
id,
|
|
111
|
-
body,
|
|
112
|
-
refresh: true
|
|
113
|
-
// Adjust based on your requirement
|
|
8
|
+
// src/helpers.ts
|
|
9
|
+
function bulkIndex(index, docs, idFn) {
|
|
10
|
+
const body = docs.flatMap((doc) => {
|
|
11
|
+
const op = idFn ? { _id: idFn(doc) } : {};
|
|
12
|
+
return [{ index: op }, doc];
|
|
114
13
|
});
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
id,
|
|
122
|
-
body: {
|
|
123
|
-
doc,
|
|
124
|
-
doc_as_upsert: true
|
|
125
|
-
}
|
|
14
|
+
return { index, body };
|
|
15
|
+
}
|
|
16
|
+
function bulkCreate(index, docs, idFn) {
|
|
17
|
+
const body = docs.flatMap((doc) => {
|
|
18
|
+
const op = { _id: idFn(doc) };
|
|
19
|
+
return [{ create: op }, doc];
|
|
126
20
|
});
|
|
127
|
-
return
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const body =
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
];
|
|
21
|
+
return { index, body };
|
|
22
|
+
}
|
|
23
|
+
function bulkUpdate(index, updates, idFn) {
|
|
24
|
+
const body = updates.flatMap((update) => {
|
|
25
|
+
const op = {
|
|
26
|
+
_id: idFn(update.doc || update.upsert)
|
|
27
|
+
};
|
|
28
|
+
return [{ update: op }, update];
|
|
136
29
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
(value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
assert(
|
|
147
|
-
isLeafNode({
|
|
148
|
-
type: "nested",
|
|
149
|
-
properties: { name: { type: "keyword" }, type: { type: "keyword" } }
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
var flattenObject = (obj, parentKey = "", result = {}) => {
|
|
153
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
154
|
-
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
|
155
|
-
if (typeof value === "object" && value !== null && !isLeafNode(value)) {
|
|
156
|
-
flattenObject(value, newKey, result);
|
|
157
|
-
} else {
|
|
158
|
-
result[newKey] = value;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return result;
|
|
162
|
-
};
|
|
163
|
-
var typedIndexCreate = async (client, index, { mappings, ...props }) => {
|
|
164
|
-
const { body: exists } = await client.indices.exists({ index });
|
|
165
|
-
if (exists) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const response = await client.indices.create({
|
|
169
|
-
index,
|
|
170
|
-
body: {
|
|
171
|
-
...props,
|
|
172
|
-
mappings: (mappings == null ? void 0 : mappings.properties) ? { properties: flattenObject(mappings.properties) } : void 0
|
|
173
|
-
}
|
|
30
|
+
return { index, body };
|
|
31
|
+
}
|
|
32
|
+
function bulkDelete(index, ids) {
|
|
33
|
+
const body = ids.map((_id) => {
|
|
34
|
+
const op = { _id };
|
|
35
|
+
return { delete: op };
|
|
174
36
|
});
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
var helper = (client) => ({
|
|
178
|
-
...client,
|
|
179
|
-
typedBulkUpsert: (index, data) => typedBulkUpsert(client, index, data),
|
|
180
|
-
typedIndexCreate: (index, options) => typedIndexCreate(client, index, options),
|
|
181
|
-
typedIndex: (index, data) => typedIndex(client, index, data),
|
|
182
|
-
typedSearch: (query) => typedSearch(client, query),
|
|
183
|
-
typedUpsert: (index, data) => typedUpsert(client, index, data)
|
|
184
|
-
});
|
|
37
|
+
return { index, body };
|
|
38
|
+
}
|
|
185
39
|
export {
|
|
186
|
-
|
|
40
|
+
OpenSearchClient,
|
|
41
|
+
bulkCreate,
|
|
42
|
+
bulkDelete,
|
|
43
|
+
bulkIndex,
|
|
44
|
+
bulkUpdate
|
|
187
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/opensearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"dev": "tsc --watch --noEmit",
|
|
14
14
|
"lint": "biome check .",
|
|
15
15
|
"test": "vitest run --passWithNoTests --coverage",
|
|
16
|
+
"test:e2e": "vitest --config vitest.config.e2e.ts --run",
|
|
16
17
|
"typecheck": "vitest --typecheck.only --passWithNoTests"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
|
-
"
|
|
20
|
+
"testcontainers": "10.25.0",
|
|
20
21
|
"tsconfig": "*"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@opensearch-project/opensearch": "2.
|
|
24
|
-
"omit": "1.0.1"
|
|
24
|
+
"@opensearch-project/opensearch": "3.2.0"
|
|
25
25
|
}
|
|
26
26
|
}
|