kuzzle 2.60.1 → 2.61.0-beta.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/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/cluster/idCardHandler.d.ts +11 -1
- package/dist/lib/cluster/idCardHandler.js +10 -2
- package/dist/lib/cluster/node.d.ts +14 -0
- package/dist/lib/cluster/node.js +19 -0
- package/dist/lib/core/backend/backendStorage.js +4 -6
- package/dist/lib/core/plugin/pluginContext.js +2 -2
- package/dist/lib/core/storage/clientAdapter.d.ts +13 -10
- package/dist/lib/core/storage/clientAdapter.js +112 -60
- package/dist/lib/core/storage/conformance/capabilityCases.d.ts +3 -0
- package/dist/lib/core/storage/conformance/capabilityCases.js +121 -0
- package/dist/lib/core/storage/conformance/conformanceContext.d.ts +33 -0
- package/dist/lib/core/storage/conformance/conformanceContext.js +97 -0
- package/dist/lib/core/storage/conformance/conformanceEnvironment.d.ts +7 -0
- package/dist/lib/core/storage/conformance/conformanceEnvironment.js +136 -0
- package/dist/lib/core/storage/conformance/coreCases.d.ts +3 -0
- package/dist/lib/core/storage/conformance/coreCases.js +381 -0
- package/dist/lib/core/storage/conformance/storageDriverConformance.d.ts +53 -0
- package/dist/lib/core/storage/conformance/storageDriverConformance.js +89 -0
- package/dist/lib/core/storage/indexCache.d.ts +26 -2
- package/dist/lib/core/storage/indexCache.js +100 -2
- package/dist/lib/core/storage/storageDriverLoader.d.ts +41 -0
- package/dist/lib/core/storage/storageDriverLoader.js +276 -0
- package/dist/lib/core/storage/storageEngine.js +5 -1
- package/dist/lib/core/storage/storageError.d.ts +15 -0
- package/dist/lib/core/storage/storageError.js +36 -0
- package/dist/lib/kerror/codes/1-services.json +35 -0
- package/dist/lib/kerror/codes/8-cluster.json +6 -0
- package/dist/lib/service/storage/7/elasticsearch.d.ts +5 -1
- package/dist/lib/service/storage/builtInDrivers.d.ts +17 -0
- package/dist/lib/service/storage/builtInDrivers.js +61 -0
- package/dist/lib/service/storage/storageService.d.ts +13 -0
- package/dist/lib/service/storage/storageService.js +44 -0
- package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +8 -1
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/types/index.js +1 -0
- package/dist/lib/types/storage/StorageDriver.d.ts +306 -0
- package/dist/lib/types/storage/StorageDriver.js +41 -0
- package/dist/package.json +2 -1
- package/package.json +2 -1
- package/dist/lib/service/storage/Elasticsearch.d.ts +0 -16
- package/dist/lib/service/storage/Elasticsearch.js +0 -48
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2026 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.CONFORMANCE_MAPPINGS = exports.ConformanceContext = void 0;
|
|
27
|
+
exports.rejectsWith = rejectsWith;
|
|
28
|
+
exports.field = field;
|
|
29
|
+
exports.hasField = hasField;
|
|
30
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
31
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
32
|
+
const has_1 = __importDefault(require("lodash/has"));
|
|
33
|
+
/** What the conformance cases share: the drivers under test and their index */
|
|
34
|
+
class ConformanceContext {
|
|
35
|
+
constructor(
|
|
36
|
+
/** The index the kit creates in the public scope, then deletes */
|
|
37
|
+
index, capabilities) {
|
|
38
|
+
this.index = index;
|
|
39
|
+
this.capabilities = capabilities;
|
|
40
|
+
this.collectionCount = 0;
|
|
41
|
+
}
|
|
42
|
+
/** The public scope's driver instance, set before any case runs */
|
|
43
|
+
get driver() {
|
|
44
|
+
strict_1.default.ok(this.publicInstance, "the driver is not initialized");
|
|
45
|
+
return this.publicInstance;
|
|
46
|
+
}
|
|
47
|
+
/** The private scope's driver instance */
|
|
48
|
+
get privateDriver() {
|
|
49
|
+
strict_1.default.ok(this.privateInstance, "the driver is not initialized");
|
|
50
|
+
return this.privateInstance;
|
|
51
|
+
}
|
|
52
|
+
setDrivers(publicDriver, privateDriver) {
|
|
53
|
+
this.publicInstance = publicDriver;
|
|
54
|
+
this.privateInstance = privateDriver;
|
|
55
|
+
}
|
|
56
|
+
/** A name no other case of this run uses */
|
|
57
|
+
uniqueName(prefix) {
|
|
58
|
+
this.collectionCount += 1;
|
|
59
|
+
return `${prefix}-${this.collectionCount}`;
|
|
60
|
+
}
|
|
61
|
+
/** Creates a collection of the kit's index, with the kit's mappings */
|
|
62
|
+
async collection(prefix) {
|
|
63
|
+
const collection = this.uniqueName(prefix);
|
|
64
|
+
await this.driver.createCollection(this.index, collection, {
|
|
65
|
+
mappings: exports.CONFORMANCE_MAPPINGS,
|
|
66
|
+
});
|
|
67
|
+
return collection;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ConformanceContext = ConformanceContext;
|
|
71
|
+
/** The mappings of the collections the kit creates */
|
|
72
|
+
exports.CONFORMANCE_MAPPINGS = {
|
|
73
|
+
properties: {
|
|
74
|
+
age: { type: "integer" },
|
|
75
|
+
city: { type: "keyword" },
|
|
76
|
+
name: { type: "keyword" },
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Asserts that `promise` rejects with the Kuzzle error `expected`: its id, or
|
|
81
|
+
* its HTTP status
|
|
82
|
+
*/
|
|
83
|
+
async function rejectsWith(promise, expected) {
|
|
84
|
+
const key = typeof expected === "string" ? "id" : "status";
|
|
85
|
+
await strict_1.default.rejects(promise, (error) => {
|
|
86
|
+
strict_1.default.equal(field(error, key), expected, `expected the Kuzzle error ${key} ${JSON.stringify(expected)}, got: ${String(error)}`);
|
|
87
|
+
return true;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/** A field of a document or an answer, by its dotted path */
|
|
91
|
+
function field(object, path) {
|
|
92
|
+
return (0, get_1.default)(object, path);
|
|
93
|
+
}
|
|
94
|
+
function hasField(object, path) {
|
|
95
|
+
return (0, has_1.default)(object, path);
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=conformanceContext.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2026 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.installConformanceEnvironment = installConformanceEnvironment;
|
|
27
|
+
// The conformance kit runs a driver outside of Kuzzle. A driver may use what
|
|
28
|
+
// the built-in Elasticsearch drivers use of the running Kuzzle instance
|
|
29
|
+
// (`global.kuzzle`): its logger, its configuration, `hash`, `emit`, the
|
|
30
|
+
// internal cache through `ask("core:cache:internal:get" | "store" | "del")`,
|
|
31
|
+
// and `withLock`, whose locks live in that cache. This stands in for them
|
|
32
|
+
// while the kit runs, in one process.
|
|
33
|
+
const node_crypto_1 = require("node:crypto");
|
|
34
|
+
const default_config_1 = __importDefault(require("../../../config/default.config"));
|
|
35
|
+
/** A logger that writes nothing */
|
|
36
|
+
function silentLogger() {
|
|
37
|
+
const noop = () => undefined;
|
|
38
|
+
const logger = {
|
|
39
|
+
debug: noop,
|
|
40
|
+
error: noop,
|
|
41
|
+
info: noop,
|
|
42
|
+
trace: noop,
|
|
43
|
+
warn: noop,
|
|
44
|
+
};
|
|
45
|
+
logger.child = () => logger;
|
|
46
|
+
return logger;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The commands `withLock` (redis-semaphore) sends to the cache, run in
|
|
50
|
+
* memory: `SET NX PX` to acquire, and the scripts that release (key,
|
|
51
|
+
* identifier) or extend (key, identifier, ttl) a lock its holder still owns.
|
|
52
|
+
*/
|
|
53
|
+
function lockClient(cache) {
|
|
54
|
+
const runScript = (_script, _keys, key, identifier, ttl) => {
|
|
55
|
+
if (cache.get(key) !== identifier) {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
if (ttl === undefined) {
|
|
59
|
+
cache.delete(key);
|
|
60
|
+
}
|
|
61
|
+
return 1;
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
eval: runScript,
|
|
65
|
+
evalsha: runScript,
|
|
66
|
+
set: (key, value) => {
|
|
67
|
+
if (cache.has(key)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
cache.set(key, value);
|
|
71
|
+
return "OK";
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function conformanceKuzzle() {
|
|
76
|
+
const cache = new Map();
|
|
77
|
+
const answers = {
|
|
78
|
+
"core:cache:internal:client:get": () => lockClient(cache),
|
|
79
|
+
"core:cache:internal:del": (key) => cache.delete(String(key)),
|
|
80
|
+
"core:cache:internal:get": (key) => cache.get(String(key)) ?? null,
|
|
81
|
+
"core:cache:internal:store": (key, value) => {
|
|
82
|
+
cache.set(String(key), value);
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
ask: (event, ...args) => {
|
|
88
|
+
const answer = answers[event];
|
|
89
|
+
if (!answer) {
|
|
90
|
+
return Promise.reject(new Error(`The storage driver conformance kit does not answer "${event}"`));
|
|
91
|
+
}
|
|
92
|
+
return Promise.resolve(answer(...args));
|
|
93
|
+
},
|
|
94
|
+
config: default_config_1.default,
|
|
95
|
+
emit: () => undefined,
|
|
96
|
+
hash: (input) => (0, node_crypto_1.createHash)("sha256")
|
|
97
|
+
.update(typeof input === "string" ? input : JSON.stringify(input))
|
|
98
|
+
.digest("hex"),
|
|
99
|
+
log: silentLogger(),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** `global.kuzzle` is a getter that throws until Kuzzle is built */
|
|
103
|
+
function isKuzzleRunning() {
|
|
104
|
+
try {
|
|
105
|
+
return Boolean(globalThis.kuzzle);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Sets `global.kuzzle` to the stand-in, unless a Kuzzle instance (or a test
|
|
113
|
+
* double of one) is already there.
|
|
114
|
+
*
|
|
115
|
+
* @returns Puts `global.kuzzle` back as it was
|
|
116
|
+
*/
|
|
117
|
+
function installConformanceEnvironment() {
|
|
118
|
+
if (isKuzzleRunning()) {
|
|
119
|
+
return () => undefined;
|
|
120
|
+
}
|
|
121
|
+
const previous = Object.getOwnPropertyDescriptor(globalThis, "kuzzle");
|
|
122
|
+
Object.defineProperty(globalThis, "kuzzle", {
|
|
123
|
+
configurable: true,
|
|
124
|
+
value: conformanceKuzzle(),
|
|
125
|
+
writable: true,
|
|
126
|
+
});
|
|
127
|
+
return () => {
|
|
128
|
+
if (previous) {
|
|
129
|
+
Object.defineProperty(globalThis, "kuzzle", previous);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
Reflect.deleteProperty(globalThis, "kuzzle");
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=conformanceEnvironment.js.map
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2026 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.coreCases = coreCases;
|
|
27
|
+
// The cases of the mandatory core: every driver passes them. They check what
|
|
28
|
+
// Kuzzle relies on, through the answers its storage layer reads.
|
|
29
|
+
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
30
|
+
const conformanceContext_1 = require("./conformanceContext");
|
|
31
|
+
const WAIT = { refresh: "wait_for" };
|
|
32
|
+
/** The `_id`s of search hits or documents, sorted */
|
|
33
|
+
function ids(documents) {
|
|
34
|
+
return documents
|
|
35
|
+
.map(({ _id }) => String(_id))
|
|
36
|
+
.sort((a, b) => a.localeCompare(b));
|
|
37
|
+
}
|
|
38
|
+
function coreCases(test, context) {
|
|
39
|
+
test.describe("core: engine", () => {
|
|
40
|
+
test.it("answers its engine type and version", async () => {
|
|
41
|
+
const info = await context.driver.info();
|
|
42
|
+
strict_1.default.equal(typeof info.type, "string");
|
|
43
|
+
strict_1.default.ok(info.type.length > 0);
|
|
44
|
+
strict_1.default.equal(typeof info.version, "string");
|
|
45
|
+
});
|
|
46
|
+
test.it("translates Koncorde filters, or names the keyword it cannot", () => {
|
|
47
|
+
strict_1.default.equal(typeof context.driver.translateKoncordeFilters({
|
|
48
|
+
equals: { city: "Montpellier" },
|
|
49
|
+
}), "object");
|
|
50
|
+
// The Elasticsearch drivers cannot translate `bool`. Whatever a driver
|
|
51
|
+
// cannot translate, it says so the way Kuzzle reads it (`KeywordError`).
|
|
52
|
+
try {
|
|
53
|
+
context.driver.translateKoncordeFilters({
|
|
54
|
+
bool: { must: [{ equals: { city: "Lyon" } }] },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
strict_1.default.deepEqual((0, conformanceContext_1.field)(error, "keyword"), {
|
|
59
|
+
name: "bool",
|
|
60
|
+
type: "operator",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// The test API takes async callbacks; this case has nothing to await.
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
test.describe("core: indexes and collections", () => {
|
|
68
|
+
test.it("lists its index, without the other scope's", async () => {
|
|
69
|
+
const privateIndex = context.uniqueName(`${context.index}-private`);
|
|
70
|
+
await context.privateDriver.createIndex(privateIndex);
|
|
71
|
+
try {
|
|
72
|
+
const schema = await context.driver.getSchema();
|
|
73
|
+
const privateSchema = await context.privateDriver.getSchema();
|
|
74
|
+
strict_1.default.ok(Object.hasOwn(schema, context.index));
|
|
75
|
+
strict_1.default.ok(!Object.hasOwn(schema, privateIndex));
|
|
76
|
+
strict_1.default.ok(Object.hasOwn(privateSchema, privateIndex));
|
|
77
|
+
strict_1.default.ok(!Object.hasOwn(privateSchema, context.index));
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
await context.privateDriver.deleteIndex(privateIndex);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
test.it("rejects an index that already exists", async () => {
|
|
84
|
+
await (0, conformanceContext_1.rejectsWith)(context.driver.createIndex(context.index), "services.storage.index_already_exists");
|
|
85
|
+
});
|
|
86
|
+
test.it("creates a collection with its mappings and settings", async () => {
|
|
87
|
+
const collection = await context.collection("collection");
|
|
88
|
+
const schema = await context.driver.getSchema();
|
|
89
|
+
strict_1.default.ok(schema[context.index]?.includes(collection));
|
|
90
|
+
const mapping = await context.driver.getMapping(context.index, collection);
|
|
91
|
+
strict_1.default.deepEqual((0, conformanceContext_1.field)(mapping, "properties.city"), { type: "keyword" });
|
|
92
|
+
strict_1.default.deepEqual((0, conformanceContext_1.field)(mapping, "properties.age"), { type: "integer" });
|
|
93
|
+
strict_1.default.ok(!(0, conformanceContext_1.hasField)(mapping, "properties._kuzzle_info"));
|
|
94
|
+
const withMeta = await context.driver.getMapping(context.index, collection, { includeKuzzleMeta: true });
|
|
95
|
+
strict_1.default.ok((0, conformanceContext_1.hasField)(withMeta, "properties._kuzzle_info"));
|
|
96
|
+
strict_1.default.equal(typeof (await context.driver.getSettings(context.index, collection)), "object");
|
|
97
|
+
});
|
|
98
|
+
test.it("truncates, then deletes a collection", async () => {
|
|
99
|
+
const collection = await context.collection("truncated");
|
|
100
|
+
await context.driver.create(context.index, collection, { a: 1 }, WAIT);
|
|
101
|
+
await context.driver.truncateCollection(context.index, collection);
|
|
102
|
+
await context.driver.refreshCollection(context.index, collection);
|
|
103
|
+
strict_1.default.equal(await context.driver.count(context.index, collection), 0);
|
|
104
|
+
await context.driver.deleteCollection(context.index, collection);
|
|
105
|
+
const schema = await context.driver.getSchema();
|
|
106
|
+
strict_1.default.ok(!schema[context.index]?.includes(collection));
|
|
107
|
+
});
|
|
108
|
+
test.it("deletes indexes, answering the ones it deleted", async () => {
|
|
109
|
+
const index = context.uniqueName(`${context.index}-deleted`);
|
|
110
|
+
await context.driver.createIndex(index);
|
|
111
|
+
strict_1.default.deepEqual(await context.driver.deleteIndexes([index]), [index]);
|
|
112
|
+
strict_1.default.ok(!Object.hasOwn(await context.driver.getSchema(), index));
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
test.describe("core: documents", () => {
|
|
116
|
+
let collection;
|
|
117
|
+
test.beforeAll(async () => {
|
|
118
|
+
collection = await context.collection("documents");
|
|
119
|
+
});
|
|
120
|
+
test.it("creates a document, with or without an id", async () => {
|
|
121
|
+
const created = await context.driver.create(context.index, collection, { city: "Montpellier", name: "alyx" }, { id: "alyx", userId: "author-kuid" });
|
|
122
|
+
strict_1.default.equal(created._id, "alyx");
|
|
123
|
+
const generated = await context.driver.create(context.index, collection, {
|
|
124
|
+
name: "anonymous",
|
|
125
|
+
});
|
|
126
|
+
strict_1.default.equal(typeof generated._id, "string");
|
|
127
|
+
strict_1.default.ok(generated._id.length > 0);
|
|
128
|
+
const { _source } = await context.driver.get(context.index, collection, "alyx");
|
|
129
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "city"), "Montpellier");
|
|
130
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "_kuzzle_info.author"), "author-kuid");
|
|
131
|
+
});
|
|
132
|
+
test.it("rejects a document id that already exists", async () => {
|
|
133
|
+
await context.driver.create(context.index, collection, {}, { id: "dup" });
|
|
134
|
+
await (0, conformanceContext_1.rejectsWith)(context.driver.create(context.index, collection, {}, { id: "dup" }), "services.storage.document_already_exists");
|
|
135
|
+
});
|
|
136
|
+
test.it("rejects reading, changing or deleting a missing document", async () => {
|
|
137
|
+
const missing = "missing-document";
|
|
138
|
+
await (0, conformanceContext_1.rejectsWith)(context.driver.get(context.index, collection, missing), "services.storage.not_found");
|
|
139
|
+
// The built-in drivers answer `services.storage.unexpected_not_found`
|
|
140
|
+
// here: any 404 will do.
|
|
141
|
+
await (0, conformanceContext_1.rejectsWith)(context.driver.update(context.index, collection, missing, { a: 1 }), 404);
|
|
142
|
+
await (0, conformanceContext_1.rejectsWith)(context.driver.replace(context.index, collection, missing, { a: 1 }), "services.storage.not_found");
|
|
143
|
+
await (0, conformanceContext_1.rejectsWith)(context.driver.delete(context.index, collection, missing), "services.storage.not_found");
|
|
144
|
+
});
|
|
145
|
+
test.it("tells which documents exist", async () => {
|
|
146
|
+
await context.driver.create(context.index, collection, {}, { id: "e1" });
|
|
147
|
+
strict_1.default.equal(await context.driver.exists(context.index, collection, "e1"), true);
|
|
148
|
+
strict_1.default.equal(await context.driver.exists(context.index, collection, "nope"), false);
|
|
149
|
+
strict_1.default.deepEqual(await context.driver.mExists(context.index, collection, ["e1", "nope"]), { errors: ["nope"], items: ["e1"] });
|
|
150
|
+
});
|
|
151
|
+
test.it("gets several documents, listing the missing ones", async () => {
|
|
152
|
+
await context.driver.create(context.index, collection, { n: 1 }, {
|
|
153
|
+
id: "g1",
|
|
154
|
+
});
|
|
155
|
+
const { errors, items } = await context.driver.mGet(context.index, collection, ["g1", "nope"]);
|
|
156
|
+
strict_1.default.deepEqual(ids(items), ["g1"]);
|
|
157
|
+
strict_1.default.deepEqual((0, conformanceContext_1.field)(items[0]?._source, "n"), 1);
|
|
158
|
+
strict_1.default.deepEqual(errors, ["nope"]);
|
|
159
|
+
});
|
|
160
|
+
test.it("creates or replaces, telling which one it did", async () => {
|
|
161
|
+
const first = await context.driver.createOrReplace(context.index, collection, "cor", { v: 1 });
|
|
162
|
+
const second = await context.driver.createOrReplace(context.index, collection, "cor", { v: 2 });
|
|
163
|
+
strict_1.default.equal(first.created, true);
|
|
164
|
+
strict_1.default.equal(second.created, false);
|
|
165
|
+
const { _source } = await context.driver.get(context.index, collection, "cor");
|
|
166
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "v"), 2);
|
|
167
|
+
});
|
|
168
|
+
test.it("updates, replaces, then deletes fields of a document", async () => {
|
|
169
|
+
await context.driver.create(context.index, collection, { a: 1, b: 2 }, { id: "upd" });
|
|
170
|
+
await context.driver.update(context.index, collection, "upd", { c: 3 }, {
|
|
171
|
+
userId: "updater-kuid",
|
|
172
|
+
});
|
|
173
|
+
let { _source } = await context.driver.get(context.index, collection, "upd");
|
|
174
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "a"), 1);
|
|
175
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "c"), 3);
|
|
176
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "_kuzzle_info.updater"), "updater-kuid");
|
|
177
|
+
await context.driver.replace(context.index, collection, "upd", {
|
|
178
|
+
d: 4,
|
|
179
|
+
});
|
|
180
|
+
({ _source } = await context.driver.get(context.index, collection, "upd"));
|
|
181
|
+
strict_1.default.ok(!(0, conformanceContext_1.hasField)(_source, "a"));
|
|
182
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "d"), 4);
|
|
183
|
+
await context.driver.update(context.index, collection, "upd", { e: 5 });
|
|
184
|
+
await context.driver.deleteFields(context.index, collection, "upd", [
|
|
185
|
+
"e",
|
|
186
|
+
]);
|
|
187
|
+
({ _source } = await context.driver.get(context.index, collection, "upd"));
|
|
188
|
+
strict_1.default.ok(!(0, conformanceContext_1.hasField)(_source, "e"));
|
|
189
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "d"), 4);
|
|
190
|
+
});
|
|
191
|
+
test.it("upserts, applying the default values on creation only", async () => {
|
|
192
|
+
const created = await context.driver.upsert(context.index, collection, "ups", { a: 1 }, { defaultValues: { b: 2 } });
|
|
193
|
+
const updated = await context.driver.upsert(context.index, collection, "ups", { a: 3 }, { defaultValues: { b: 4 } });
|
|
194
|
+
strict_1.default.equal(created.created, true);
|
|
195
|
+
strict_1.default.equal(updated.created, false);
|
|
196
|
+
const { _source } = await context.driver.get(context.index, collection, "ups");
|
|
197
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "a"), 3);
|
|
198
|
+
strict_1.default.equal((0, conformanceContext_1.field)(_source, "b"), 2);
|
|
199
|
+
});
|
|
200
|
+
test.it("deletes a document", async () => {
|
|
201
|
+
await context.driver.create(context.index, collection, {}, { id: "del" });
|
|
202
|
+
await context.driver.delete(context.index, collection, "del");
|
|
203
|
+
strict_1.default.equal(await context.driver.exists(context.index, collection, "del"), false);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
test.describe("core: several documents at once", () => {
|
|
207
|
+
let collection;
|
|
208
|
+
test.beforeAll(async () => {
|
|
209
|
+
collection = await context.collection("many");
|
|
210
|
+
});
|
|
211
|
+
test.it("creates several documents, reporting the ones it could not", async () => {
|
|
212
|
+
await context.driver.create(context.index, collection, {}, { id: "m0" });
|
|
213
|
+
const { errors, items } = await context.driver.mCreate(context.index, collection, [
|
|
214
|
+
{ _id: "m0", body: { n: 0 } },
|
|
215
|
+
{ _id: "m1", body: { n: 1 } },
|
|
216
|
+
{ _id: "m2", body: { n: 2 } },
|
|
217
|
+
], WAIT);
|
|
218
|
+
strict_1.default.deepEqual(ids(items), ["m1", "m2"]);
|
|
219
|
+
strict_1.default.equal(errors.length, 1);
|
|
220
|
+
});
|
|
221
|
+
test.it("creates or replaces, updates, upserts and replaces several documents", async () => {
|
|
222
|
+
let result = await context.driver.mCreateOrReplace(context.index, collection, [
|
|
223
|
+
{ _id: "m1", body: { n: 10 } },
|
|
224
|
+
{ _id: "m3", body: { n: 3 } },
|
|
225
|
+
]);
|
|
226
|
+
strict_1.default.deepEqual(ids(result.items), ["m1", "m3"]);
|
|
227
|
+
result = await context.driver.mUpdate(context.index, collection, [
|
|
228
|
+
{ _id: "m1", body: { updated: true } },
|
|
229
|
+
{ _id: "nope", body: { updated: true } },
|
|
230
|
+
]);
|
|
231
|
+
strict_1.default.deepEqual(ids(result.items), ["m1"]);
|
|
232
|
+
strict_1.default.equal(result.errors.length, 1);
|
|
233
|
+
result = await context.driver.mUpsert(context.index, collection, [
|
|
234
|
+
{ _id: "m2", changes: { upserted: true } },
|
|
235
|
+
{ _id: "m4", changes: { upserted: true } },
|
|
236
|
+
]);
|
|
237
|
+
strict_1.default.deepEqual(ids(result.items), ["m2", "m4"]);
|
|
238
|
+
result = await context.driver.mReplace(context.index, collection, [
|
|
239
|
+
{ _id: "m3", body: { replaced: true } },
|
|
240
|
+
{ _id: "nope", body: { replaced: true } },
|
|
241
|
+
]);
|
|
242
|
+
strict_1.default.deepEqual(ids(result.items), ["m3"]);
|
|
243
|
+
strict_1.default.equal(result.errors.length, 1);
|
|
244
|
+
const { items } = await context.driver.mGet(context.index, collection, [
|
|
245
|
+
"m1",
|
|
246
|
+
"m2",
|
|
247
|
+
"m3",
|
|
248
|
+
"m4",
|
|
249
|
+
]);
|
|
250
|
+
const sources = Object.fromEntries(items.map(({ _id, _source }) => [_id, _source]));
|
|
251
|
+
strict_1.default.equal((0, conformanceContext_1.field)(sources.m1, "n"), 10);
|
|
252
|
+
strict_1.default.equal((0, conformanceContext_1.field)(sources.m1, "updated"), true);
|
|
253
|
+
strict_1.default.equal((0, conformanceContext_1.field)(sources.m2, "upserted"), true);
|
|
254
|
+
strict_1.default.equal((0, conformanceContext_1.field)(sources.m3, "replaced"), true);
|
|
255
|
+
strict_1.default.ok(!(0, conformanceContext_1.hasField)(sources.m3, "n"));
|
|
256
|
+
strict_1.default.equal((0, conformanceContext_1.field)(sources.m4, "upserted"), true);
|
|
257
|
+
});
|
|
258
|
+
test.it("deletes several documents, reporting the missing ones", async () => {
|
|
259
|
+
await context.driver.mCreateOrReplace(context.index, collection, [
|
|
260
|
+
{ _id: "d1", body: {} },
|
|
261
|
+
{ _id: "d2", body: {} },
|
|
262
|
+
]);
|
|
263
|
+
const { documents, errors } = await context.driver.mDelete(context.index, collection, ["d1", "d2", "nope"]);
|
|
264
|
+
strict_1.default.deepEqual(ids(documents), ["d1", "d2"]);
|
|
265
|
+
strict_1.default.equal(errors.length, 1);
|
|
266
|
+
});
|
|
267
|
+
test.it("imports documents in the bulk format", async () => {
|
|
268
|
+
const imported = context.uniqueName("imported");
|
|
269
|
+
await context.driver.createCollection(context.index, imported);
|
|
270
|
+
const { errors, items } = await context.driver.import(context.index, imported, [
|
|
271
|
+
{ index: { _id: "i1" } },
|
|
272
|
+
{ n: 1 },
|
|
273
|
+
{ create: { _id: "i2" } },
|
|
274
|
+
{ n: 2 },
|
|
275
|
+
], WAIT);
|
|
276
|
+
strict_1.default.deepEqual(errors, []);
|
|
277
|
+
strict_1.default.equal(items.length, 2);
|
|
278
|
+
strict_1.default.equal(await context.driver.count(context.index, imported), 2);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
test.describe("core: search", () => {
|
|
282
|
+
let collection;
|
|
283
|
+
let other;
|
|
284
|
+
test.beforeAll(async () => {
|
|
285
|
+
collection = await context.collection("search");
|
|
286
|
+
other = await context.collection("search-other");
|
|
287
|
+
await context.driver.mCreate(context.index, collection, [
|
|
288
|
+
{ _id: "s1", body: { age: 30, city: "Montpellier", name: "a" } },
|
|
289
|
+
{ _id: "s2", body: { age: 40, city: "Montpellier", name: "b" } },
|
|
290
|
+
{ _id: "s3", body: { age: 50, city: "Lyon", name: "c" } },
|
|
291
|
+
{ _id: "s4", body: { age: 60, city: "Paris", name: "d" } },
|
|
292
|
+
], WAIT);
|
|
293
|
+
await context.driver.create(context.index, other, { city: "Montpellier" }, { id: "o1", ...WAIT });
|
|
294
|
+
});
|
|
295
|
+
test.it("counts the documents matching a query", async () => {
|
|
296
|
+
strict_1.default.equal(await context.driver.count(context.index, collection), 4);
|
|
297
|
+
strict_1.default.equal(await context.driver.count(context.index, collection, {
|
|
298
|
+
query: { term: { city: "Montpellier" } },
|
|
299
|
+
}), 2);
|
|
300
|
+
});
|
|
301
|
+
test.it("searches with a query, sort, from and size", async () => {
|
|
302
|
+
const { hits, total } = await context.driver.search({
|
|
303
|
+
collection,
|
|
304
|
+
index: context.index,
|
|
305
|
+
searchBody: {
|
|
306
|
+
query: { range: { age: { gte: 40 } } },
|
|
307
|
+
sort: [{ age: "asc" }],
|
|
308
|
+
},
|
|
309
|
+
}, { from: 1, size: 1 });
|
|
310
|
+
strict_1.default.equal(total, 3);
|
|
311
|
+
strict_1.default.deepEqual(hits.map(({ _id }) => _id), ["s3"]);
|
|
312
|
+
});
|
|
313
|
+
test.it("searches with translated Koncorde filters", async () => {
|
|
314
|
+
const query = context.driver.translateKoncordeFilters({
|
|
315
|
+
equals: { city: "Lyon" },
|
|
316
|
+
});
|
|
317
|
+
const { hits } = await context.driver.search({
|
|
318
|
+
collection,
|
|
319
|
+
index: context.index,
|
|
320
|
+
searchBody: { query },
|
|
321
|
+
});
|
|
322
|
+
strict_1.default.deepEqual(ids(hits), ["s3"]);
|
|
323
|
+
});
|
|
324
|
+
test.it("searches several collections, telling where each hit is", async () => {
|
|
325
|
+
const { hits } = await context.driver.search({
|
|
326
|
+
searchBody: { query: { term: { city: "Montpellier" } } },
|
|
327
|
+
targets: [{ collections: [collection, other], index: context.index }],
|
|
328
|
+
});
|
|
329
|
+
strict_1.default.deepEqual(ids(hits), ["o1", "s1", "s2"]);
|
|
330
|
+
for (const hit of hits) {
|
|
331
|
+
strict_1.default.equal(hit.index, context.index);
|
|
332
|
+
strict_1.default.equal(hit.collection, hit._id === "o1" ? other : collection);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
test.it("scrolls through the results, page by page", async () => {
|
|
336
|
+
const first = await context.driver.search({
|
|
337
|
+
collection,
|
|
338
|
+
index: context.index,
|
|
339
|
+
searchBody: { sort: [{ age: "asc" }] },
|
|
340
|
+
}, { scroll: "10s", size: 3 });
|
|
341
|
+
strict_1.default.equal(first.total, 4);
|
|
342
|
+
strict_1.default.equal(first.hits.length, 3);
|
|
343
|
+
strict_1.default.equal(typeof first.scrollId, "string");
|
|
344
|
+
const second = await context.driver.scroll(String(first.scrollId), {
|
|
345
|
+
scrollTTL: "10s",
|
|
346
|
+
});
|
|
347
|
+
strict_1.default.deepEqual([...first.hits, ...second.hits].map(({ _id }) => _id), ["s1", "s2", "s3", "s4"]);
|
|
348
|
+
strict_1.default.equal(second.remaining, 0);
|
|
349
|
+
});
|
|
350
|
+
test.it("runs a callback on every page of documents matching a query", async () => {
|
|
351
|
+
const pages = await context.driver.mExecute(context.index, collection, { match_all: {} }, (documents) => documents.map(({ _id }) => _id), { size: 3 });
|
|
352
|
+
strict_1.default.deepEqual(pages
|
|
353
|
+
.flat()
|
|
354
|
+
.map(String)
|
|
355
|
+
.sort((a, b) => a.localeCompare(b)), ["s1", "s2", "s3", "s4"]);
|
|
356
|
+
});
|
|
357
|
+
test.it("deletes the documents matching a query, answering them", async () => {
|
|
358
|
+
const deleted = context.uniqueName("deleted");
|
|
359
|
+
await context.driver.createCollection(context.index, deleted, {
|
|
360
|
+
mappings: { properties: { city: { type: "keyword" } } },
|
|
361
|
+
});
|
|
362
|
+
await context.driver.mCreate(context.index, deleted, [
|
|
363
|
+
{ _id: "x1", body: { city: "Lyon" } },
|
|
364
|
+
{ _id: "x2", body: { city: "Paris" } },
|
|
365
|
+
], WAIT);
|
|
366
|
+
const { documents } = await context.driver.deleteByQuery(context.index, deleted, { term: { city: "Lyon" } }, WAIT);
|
|
367
|
+
strict_1.default.deepEqual(ids(documents), ["x1"]);
|
|
368
|
+
strict_1.default.equal(await context.driver.count(context.index, deleted), 1);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
test.describe("core: engine hooks", () => {
|
|
372
|
+
test.it("waits for a new collection's shards, when the driver can", async () => {
|
|
373
|
+
if (!context.driver.waitForCollectionShards) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const collection = await context.collection("shards");
|
|
377
|
+
await context.driver.waitForCollectionShards(context.index, collection, "10s");
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
//# sourceMappingURL=coreCases.js.map
|