@sebspark/opensearch 0.1.1 → 0.2.0
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/dist/index.d.mts +10 -5
- package/dist/index.d.ts +10 -5
- package/dist/index.js +19 -0
- package/dist/index.mjs +9 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -20,6 +20,7 @@ type WithId = {
|
|
|
20
20
|
};
|
|
21
21
|
type ExcludeId<T> = Omit<T, 'id'>;
|
|
22
22
|
type SubstringOf<T extends string> = T extends `${infer Prefix}${infer _Rest}` ? Prefix | SubstringOf<Exclude<T, Prefix>> : never;
|
|
23
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
23
24
|
|
|
24
25
|
type FieldName<T> = NestedStringPaths<ExcludeId<T>> | '*' | (string & {});
|
|
25
26
|
type FieldObject<T> = {
|
|
@@ -237,11 +238,18 @@ type OpenSearchQuery<T extends {
|
|
|
237
238
|
from?: number;
|
|
238
239
|
size?: number;
|
|
239
240
|
} : never;
|
|
240
|
-
type BasicOpenSearchFieldTypes = 'text' | 'keyword' | 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' | 'date' | 'boolean' | 'binary';
|
|
241
|
+
type BasicOpenSearchFieldTypes = 'text' | 'keyword' | 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' | 'date' | 'boolean' | 'binary' | 'nested';
|
|
241
242
|
type ElementType<T> = T extends Array<infer U> ? U : T;
|
|
242
243
|
type OpenSearchFieldType<T> = ElementType<T> extends string ? 'text' | 'keyword' : ElementType<T> extends number ? 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' : ElementType<T> extends boolean ? 'boolean' : ElementType<T> extends Date ? 'date' : BasicOpenSearchFieldTypes;
|
|
243
244
|
type FieldOptions<T> = {
|
|
244
|
-
type: OpenSearchFieldType<T
|
|
245
|
+
type: OpenSearchFieldType<NotUndefined<T>>;
|
|
246
|
+
};
|
|
247
|
+
type NestedFieldOptions<T> = {
|
|
248
|
+
type: 'nested';
|
|
249
|
+
properties: IndexProperties<T>;
|
|
250
|
+
};
|
|
251
|
+
type IndexProperties<T> = {
|
|
252
|
+
[K in keyof Partial<T>]: T[K] extends Date ? FieldOptions<T[K]> : NotUndefined<T[K]> extends object ? NotUndefined<T[K]> extends Array<infer U> ? U extends object ? NestedFieldOptions<U> : FieldOptions<T[K]> : IndexProperties<T[K]> : FieldOptions<T[K]>;
|
|
245
253
|
};
|
|
246
254
|
type IndexOptions<T extends WithId> = {
|
|
247
255
|
settings?: {
|
|
@@ -255,9 +263,6 @@ type IndexOptions<T extends WithId> = {
|
|
|
255
263
|
};
|
|
256
264
|
aliases?: Record<string, Record<string, never>>;
|
|
257
265
|
};
|
|
258
|
-
type IndexProperties<T> = {
|
|
259
|
-
[K in keyof Partial<T>]: T[K] extends object ? T[K] extends Array<infer U> ? FieldOptions<T[K]> : IndexProperties<T[K]> : FieldOptions<T[K]>;
|
|
260
|
-
};
|
|
261
266
|
|
|
262
267
|
interface OpenSearchHelper extends Client {
|
|
263
268
|
typedSearch: <DataType extends WithId, ReturnType = DataType>(query: OpenSearchQuery<DataType, ReturnType>) => Promise<{
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ type WithId = {
|
|
|
20
20
|
};
|
|
21
21
|
type ExcludeId<T> = Omit<T, 'id'>;
|
|
22
22
|
type SubstringOf<T extends string> = T extends `${infer Prefix}${infer _Rest}` ? Prefix | SubstringOf<Exclude<T, Prefix>> : never;
|
|
23
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
23
24
|
|
|
24
25
|
type FieldName<T> = NestedStringPaths<ExcludeId<T>> | '*' | (string & {});
|
|
25
26
|
type FieldObject<T> = {
|
|
@@ -237,11 +238,18 @@ type OpenSearchQuery<T extends {
|
|
|
237
238
|
from?: number;
|
|
238
239
|
size?: number;
|
|
239
240
|
} : never;
|
|
240
|
-
type BasicOpenSearchFieldTypes = 'text' | 'keyword' | 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' | 'date' | 'boolean' | 'binary';
|
|
241
|
+
type BasicOpenSearchFieldTypes = 'text' | 'keyword' | 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' | 'date' | 'boolean' | 'binary' | 'nested';
|
|
241
242
|
type ElementType<T> = T extends Array<infer U> ? U : T;
|
|
242
243
|
type OpenSearchFieldType<T> = ElementType<T> extends string ? 'text' | 'keyword' : ElementType<T> extends number ? 'long' | 'integer' | 'short' | 'byte' | 'double' | 'float' : ElementType<T> extends boolean ? 'boolean' : ElementType<T> extends Date ? 'date' : BasicOpenSearchFieldTypes;
|
|
243
244
|
type FieldOptions<T> = {
|
|
244
|
-
type: OpenSearchFieldType<T
|
|
245
|
+
type: OpenSearchFieldType<NotUndefined<T>>;
|
|
246
|
+
};
|
|
247
|
+
type NestedFieldOptions<T> = {
|
|
248
|
+
type: 'nested';
|
|
249
|
+
properties: IndexProperties<T>;
|
|
250
|
+
};
|
|
251
|
+
type IndexProperties<T> = {
|
|
252
|
+
[K in keyof Partial<T>]: T[K] extends Date ? FieldOptions<T[K]> : NotUndefined<T[K]> extends object ? NotUndefined<T[K]> extends Array<infer U> ? U extends object ? NestedFieldOptions<U> : FieldOptions<T[K]> : IndexProperties<T[K]> : FieldOptions<T[K]>;
|
|
245
253
|
};
|
|
246
254
|
type IndexOptions<T extends WithId> = {
|
|
247
255
|
settings?: {
|
|
@@ -255,9 +263,6 @@ type IndexOptions<T extends WithId> = {
|
|
|
255
263
|
};
|
|
256
264
|
aliases?: Record<string, Record<string, never>>;
|
|
257
265
|
};
|
|
258
|
-
type IndexProperties<T> = {
|
|
259
|
-
[K in keyof Partial<T>]: T[K] extends object ? T[K] extends Array<infer U> ? FieldOptions<T[K]> : IndexProperties<T[K]> : FieldOptions<T[K]>;
|
|
260
|
-
};
|
|
261
266
|
|
|
262
267
|
interface OpenSearchHelper extends Client {
|
|
263
268
|
typedSearch: <DataType extends WithId, ReturnType = DataType>(query: OpenSearchQuery<DataType, ReturnType>) => Promise<{
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -25,6 +35,7 @@ __export(src_exports, {
|
|
|
25
35
|
module.exports = __toCommonJS(src_exports);
|
|
26
36
|
|
|
27
37
|
// src/openSearchHelper.ts
|
|
38
|
+
var import_assert = __toESM(require("assert"));
|
|
28
39
|
var typedSearch = async (client, searchQuery) => {
|
|
29
40
|
const response = await client.search(
|
|
30
41
|
searchQuery
|
|
@@ -73,10 +84,18 @@ var typedBulkUpsert = async (client, index, items) => {
|
|
|
73
84
|
return response;
|
|
74
85
|
};
|
|
75
86
|
var isLeafNode = (obj) => {
|
|
87
|
+
if (Object.values(obj).some((value) => value === "nested"))
|
|
88
|
+
return true;
|
|
76
89
|
return !Object.values(obj).some(
|
|
77
90
|
(value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
78
91
|
);
|
|
79
92
|
};
|
|
93
|
+
(0, import_assert.default)(
|
|
94
|
+
isLeafNode({
|
|
95
|
+
type: "nested",
|
|
96
|
+
properties: { name: { type: "keyword" }, type: { type: "keyword" } }
|
|
97
|
+
})
|
|
98
|
+
);
|
|
80
99
|
var flattenObject = (obj, parentKey = "", result = {}) => {
|
|
81
100
|
for (const [key, value] of Object.entries(obj)) {
|
|
82
101
|
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/openSearchHelper.ts
|
|
2
|
+
import assert from "assert";
|
|
2
3
|
var typedSearch = async (client, searchQuery) => {
|
|
3
4
|
const response = await client.search(
|
|
4
5
|
searchQuery
|
|
@@ -47,10 +48,18 @@ var typedBulkUpsert = async (client, index, items) => {
|
|
|
47
48
|
return response;
|
|
48
49
|
};
|
|
49
50
|
var isLeafNode = (obj) => {
|
|
51
|
+
if (Object.values(obj).some((value) => value === "nested"))
|
|
52
|
+
return true;
|
|
50
53
|
return !Object.values(obj).some(
|
|
51
54
|
(value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
52
55
|
);
|
|
53
56
|
};
|
|
57
|
+
assert(
|
|
58
|
+
isLeafNode({
|
|
59
|
+
type: "nested",
|
|
60
|
+
properties: { name: { type: "keyword" }, type: { type: "keyword" } }
|
|
61
|
+
})
|
|
62
|
+
);
|
|
54
63
|
var flattenObject = (obj, parentKey = "", result = {}) => {
|
|
55
64
|
for (const [key, value] of Object.entries(obj)) {
|
|
56
65
|
const newKey = parentKey ? `${parentKey}.${key}` : key;
|