@ddd-ts-kit/opensearch 0.108.1 → 0.109.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/README.fr.md +70 -3
- package/README.md +68 -2
- package/dist/testing/bodies-of.d.ts +4 -0
- package/dist/testing/bodies-of.d.ts.map +1 -0
- package/dist/testing/bodies-of.js +6 -0
- package/dist/testing/bodies-of.js.map +1 -0
- package/dist/testing/body-of.d.ts +5 -0
- package/dist/testing/body-of.d.ts.map +1 -0
- package/dist/testing/body-of.js +5 -0
- package/dist/testing/body-of.js.map +1 -0
- package/dist/testing/compare-as.d.ts +6 -0
- package/dist/testing/compare-as.d.ts.map +1 -0
- package/dist/testing/compare-as.js +21 -0
- package/dist/testing/compare-as.js.map +1 -0
- package/dist/testing/fake-index.d.ts +19 -0
- package/dist/testing/fake-index.d.ts.map +1 -0
- package/dist/testing/fake-index.js +65 -0
- package/dist/testing/fake-index.js.map +1 -0
- package/dist/testing/fake-refusal.d.ts +7 -0
- package/dist/testing/fake-refusal.d.ts.map +1 -0
- package/dist/testing/fake-refusal.js +11 -0
- package/dist/testing/fake-refusal.js.map +1 -0
- package/dist/testing/in-memory-open-search.d.ts +28 -0
- package/dist/testing/in-memory-open-search.d.ts.map +1 -0
- package/dist/testing/in-memory-open-search.js +200 -0
- package/dist/testing/in-memory-open-search.js.map +1 -0
- package/dist/testing/matches.d.ts +12 -0
- package/dist/testing/matches.d.ts.map +1 -0
- package/dist/testing/matches.js +86 -0
- package/dist/testing/matches.js.map +1 -0
- package/dist/testing/open-search-server.d.ts +24 -0
- package/dist/testing/open-search-server.d.ts.map +1 -0
- package/dist/testing/open-search-server.js +75 -0
- package/dist/testing/open-search-server.js.map +1 -0
- package/dist/testing/properties-of.d.ts +9 -0
- package/dist/testing/properties-of.d.ts.map +1 -0
- package/dist/testing/properties-of.js +13 -0
- package/dist/testing/properties-of.js.map +1 -0
- package/dist/testing/searched.d.ts +15 -0
- package/dist/testing/searched.d.ts.map +1 -0
- package/dist/testing/searched.js +60 -0
- package/dist/testing/searched.js.map +1 -0
- package/dist/testing/text-at.d.ts +4 -0
- package/dist/testing/text-at.d.ts.map +1 -0
- package/dist/testing/text-at.js +6 -0
- package/dist/testing/text-at.js.map +1 -0
- package/dist/testing/type-at.d.ts +4 -0
- package/dist/testing/type-at.d.ts.map +1 -0
- package/dist/testing/type-at.js +10 -0
- package/dist/testing/type-at.js.map +1 -0
- package/dist/testing/unknown-query-error.d.ts +4 -0
- package/dist/testing/unknown-query-error.d.ts.map +1 -0
- package/dist/testing/unknown-query-error.js +4 -0
- package/dist/testing/unknown-query-error.js.map +1 -0
- package/dist/testing/value-at.d.ts +5 -0
- package/dist/testing/value-at.d.ts.map +1 -0
- package/dist/testing/value-at.js +7 -0
- package/dist/testing/value-at.js.map +1 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +2 -0
- package/dist/testing.js.map +1 -1
- package/package.json +4 -4
package/README.fr.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[English](README.md) · **Français**
|
|
2
|
-
<!-- translation-of: README.md sha256:
|
|
2
|
+
<!-- translation-of: README.md sha256:eee20ce395d8b623 -->
|
|
3
3
|
|
|
4
4
|
# @ddd-ts-kit/opensearch
|
|
5
5
|
|
|
@@ -15,8 +15,11 @@ de son modèle de lecture, et la plateforme lie cet adaptateur.
|
|
|
15
15
|
npm i @ddd-ts-kit/opensearch
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
`init`
|
|
19
|
-
|
|
18
|
+
`init --search opensearch` le câble dans la plateforme d'un projet généré : `SearchIndexes` fixe le
|
|
19
|
+
transport et la stratégie de locataires et provisionne les index, et un adaptateur appelle
|
|
20
|
+
`super(search.options(name, definition))` ([Modèles de lecture de recherche](../../docs/tools/search-read-models.fr.md),
|
|
21
|
+
[ADR-0009](../../docs/adr/0009-init-wires-opensearch.fr.md)). La composition ci-dessous est la même à la main,
|
|
22
|
+
et [la décision](../../docs/adr/0008-a-read-model-store-on-opensearch.fr.md) consigne chaque choix.
|
|
20
23
|
|
|
21
24
|
## Racine de composition
|
|
22
25
|
|
|
@@ -209,6 +212,70 @@ les specs utilisent.
|
|
|
209
212
|
- **Une chaîne jusqu'à 32 766 octets** dans un champ filtré : Lucene refuse un terme plus long.
|
|
210
213
|
- Les pages par décalage s'arrêtent à `index.max_result_window` ; au-delà, paginer par curseur.
|
|
211
214
|
|
|
215
|
+
## Dans les specs d'un projet
|
|
216
|
+
|
|
217
|
+
`@ddd-ts-kit/opensearch/testing` exporte `InMemoryOpenSearch`, l'OpenSearch en mémoire sur lequel
|
|
218
|
+
tournent les specs de ce paquet : un `OpenSearchTransport` qui sert le sous-ensemble de l'API REST
|
|
219
|
+
que le store appelle (*mappings* stricts, alias avec un filtre et un routage, écritures
|
|
220
|
+
conditionnelles, le DSL de requête qu'écrit le store), chaque écriture vue par la recherche
|
|
221
|
+
suivante. Donné à `OpenSearchReadModelStore`, il tient un adaptateur à son contrat dans une spec
|
|
222
|
+
unitaire, sans serveur. `OpenSearchServer` sert le même nœud sur un port local, derrière les
|
|
223
|
+
identifiants du plugin de sécurité, pour une spec qui passe par `fetchTransport`. Aucun des deux
|
|
224
|
+
n'est OpenSearch : une spec de l'adaptateur sur un vrai nœud est celle qui prouve une requête
|
|
225
|
+
qu'OpenSearch répond autrement ; les specs d'un contexte lient le port de lecture à
|
|
226
|
+
`InMemoryReadModelStore` du noyau.
|
|
227
|
+
|
|
228
|
+
<!-- checked sample -->
|
|
229
|
+
```ts
|
|
230
|
+
import { defineCriteria } from '@ddd-ts-kit/kernel';
|
|
231
|
+
import { OpenSearchReadModelStore, fetchTransport } from '@ddd-ts-kit/opensearch';
|
|
232
|
+
import { InMemoryOpenSearch, OpenSearchServer } from '@ddd-ts-kit/opensearch/testing';
|
|
233
|
+
|
|
234
|
+
interface InvoiceRow {
|
|
235
|
+
readonly id: string;
|
|
236
|
+
readonly status: string;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const invoiceCriteria = defineCriteria<InvoiceRow>({
|
|
240
|
+
fields: { id: { type: 'string', filter: ['eq'] }, status: { type: 'string', filter: ['eq'], sortable: true } },
|
|
241
|
+
defaultSort: [{ field: 'status', direction: 'asc' }],
|
|
242
|
+
tieBreaker: 'id',
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const issued = { eventId: 'evt-1', occurredAt: new Date('2026-11-01T09:00:00Z') };
|
|
246
|
+
|
|
247
|
+
// Une spec unitaire : le store sur le nœud en mémoire, dans le processus.
|
|
248
|
+
export async function onTheNodeInMemory(): Promise<InvoiceRow | undefined> {
|
|
249
|
+
const store = new OpenSearchReadModelStore<InvoiceRow>({
|
|
250
|
+
transport: new InMemoryOpenSearch(),
|
|
251
|
+
name: 'billing_invoices',
|
|
252
|
+
definition: invoiceCriteria,
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
await store.ensureMapping();
|
|
256
|
+
await store.upsertIfNewer('i1', issued, () => ({ id: 'i1', status: 'issued' }));
|
|
257
|
+
|
|
258
|
+
return store.get('i1');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Une spec du transport : le même nœud sur un port local, atteint par fetchTransport.
|
|
262
|
+
export async function overHttp(): Promise<void> {
|
|
263
|
+
const credentials = { username: 'app', password: 'app-secret' };
|
|
264
|
+
const server = await OpenSearchServer.start(credentials);
|
|
265
|
+
const store = new OpenSearchReadModelStore<InvoiceRow>({
|
|
266
|
+
transport: fetchTransport({ node: server.url, auth: credentials }),
|
|
267
|
+
name: 'billing_invoices',
|
|
268
|
+
definition: invoiceCriteria,
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
try {
|
|
272
|
+
await store.ensureMapping();
|
|
273
|
+
} finally {
|
|
274
|
+
await server.stop();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
212
279
|
## Tests
|
|
213
280
|
|
|
214
281
|
`readModelRowsContract` et `criteriaContract` de `@ddd-ts-kit/testing/contracts` (réexportés par
|
package/README.md
CHANGED
|
@@ -13,8 +13,11 @@ this package: a projector writes to its read model port, and the platform binds
|
|
|
13
13
|
npm i @ddd-ts-kit/opensearch
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
`init
|
|
17
|
-
|
|
16
|
+
`init --search opensearch` wires it in the platform of a generated project: `SearchIndexes` sets the
|
|
17
|
+
transport and the tenancy and provisions the indices, and an adapter calls
|
|
18
|
+
`super(search.options(name, definition))` ([Search read models](../../docs/tools/search-read-models.md),
|
|
19
|
+
[ADR-0009](../../docs/adr/0009-init-wires-opensearch.md)). The composition below is the same by hand,
|
|
20
|
+
and [the decision record](../../docs/adr/0008-a-read-model-store-on-opensearch.md) states each choice.
|
|
18
21
|
|
|
19
22
|
## Composition root
|
|
20
23
|
|
|
@@ -196,6 +199,69 @@ wait on every write; it is what the specs use.
|
|
|
196
199
|
- **A string up to 32 766 bytes** in a filtered field: Lucene refuses a longer term.
|
|
197
200
|
- Offset pages stop at `index.max_result_window`; page by cursor beyond.
|
|
198
201
|
|
|
202
|
+
## In the specs of a project
|
|
203
|
+
|
|
204
|
+
`@ddd-ts-kit/opensearch/testing` exports `InMemoryOpenSearch`, the OpenSearch in memory the specs
|
|
205
|
+
of this package run on: an `OpenSearchTransport` that serves the subset of the REST API the store
|
|
206
|
+
calls (strict mappings, aliases with a filter and a routing, conditional writes, the query DSL the
|
|
207
|
+
store writes), every write seen by the next search. Handed to `OpenSearchReadModelStore`, it holds
|
|
208
|
+
an adapter to its contract in a unit spec, with no server. `OpenSearchServer` serves the same node
|
|
209
|
+
on a local port, behind the credentials of the security plugin, for a spec that goes through
|
|
210
|
+
`fetchTransport`. Neither is OpenSearch: a spec of the adapter on a real node is the one that
|
|
211
|
+
proves a query OpenSearch answers differently; the specs of a context bind the read port to
|
|
212
|
+
`InMemoryReadModelStore` of the kernel.
|
|
213
|
+
|
|
214
|
+
<!-- checked sample -->
|
|
215
|
+
```ts
|
|
216
|
+
import { defineCriteria } from '@ddd-ts-kit/kernel';
|
|
217
|
+
import { OpenSearchReadModelStore, fetchTransport } from '@ddd-ts-kit/opensearch';
|
|
218
|
+
import { InMemoryOpenSearch, OpenSearchServer } from '@ddd-ts-kit/opensearch/testing';
|
|
219
|
+
|
|
220
|
+
interface InvoiceRow {
|
|
221
|
+
readonly id: string;
|
|
222
|
+
readonly status: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const invoiceCriteria = defineCriteria<InvoiceRow>({
|
|
226
|
+
fields: { id: { type: 'string', filter: ['eq'] }, status: { type: 'string', filter: ['eq'], sortable: true } },
|
|
227
|
+
defaultSort: [{ field: 'status', direction: 'asc' }],
|
|
228
|
+
tieBreaker: 'id',
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const issued = { eventId: 'evt-1', occurredAt: new Date('2026-11-01T09:00:00Z') };
|
|
232
|
+
|
|
233
|
+
// A unit spec: the store on the node in memory, in the process.
|
|
234
|
+
export async function onTheNodeInMemory(): Promise<InvoiceRow | undefined> {
|
|
235
|
+
const store = new OpenSearchReadModelStore<InvoiceRow>({
|
|
236
|
+
transport: new InMemoryOpenSearch(),
|
|
237
|
+
name: 'billing_invoices',
|
|
238
|
+
definition: invoiceCriteria,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
await store.ensureMapping();
|
|
242
|
+
await store.upsertIfNewer('i1', issued, () => ({ id: 'i1', status: 'issued' }));
|
|
243
|
+
|
|
244
|
+
return store.get('i1');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// A spec of the transport: the same node on a local port, reached through fetchTransport.
|
|
248
|
+
export async function overHttp(): Promise<void> {
|
|
249
|
+
const credentials = { username: 'app', password: 'app-secret' };
|
|
250
|
+
const server = await OpenSearchServer.start(credentials);
|
|
251
|
+
const store = new OpenSearchReadModelStore<InvoiceRow>({
|
|
252
|
+
transport: fetchTransport({ node: server.url, auth: credentials }),
|
|
253
|
+
name: 'billing_invoices',
|
|
254
|
+
definition: invoiceCriteria,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
await store.ensureMapping();
|
|
259
|
+
} finally {
|
|
260
|
+
await server.stop();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
199
265
|
## Tests
|
|
200
266
|
|
|
201
267
|
`readModelRowsContract` and `criteriaContract` of `@ddd-ts-kit/testing/contracts` (re-exported by
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodies-of.d.ts","sourceRoot":"","sources":["../../src/testing/bodies-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAE9C,2GAA2G;AAC3G,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,EAAE,CAE/C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { bodyOf } from './body-of.js';
|
|
2
|
+
/** A list of JSON objects, one written alone, or none: the clauses of a `bool`, the actions on aliases. */
|
|
3
|
+
export function bodiesOf(value) {
|
|
4
|
+
return (Array.isArray(value) ? value : value === undefined ? [] : [value]).map(bodyOf);
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=bodies-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bodies-of.js","sourceRoot":"","sources":["../../src/testing/bodies-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAE9C,2GAA2G;AAC3G,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** A JSON object of a request, a mapping or a query, as the fake reads it. */
|
|
2
|
+
export type Body = Readonly<Record<string, unknown>>;
|
|
3
|
+
/** The value when it is a JSON object, an empty one otherwise: what the node reads of a part it ignores. */
|
|
4
|
+
export declare function bodyOf(value: unknown): Body;
|
|
5
|
+
//# sourceMappingURL=body-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-of.d.ts","sourceRoot":"","sources":["../../src/testing/body-of.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,MAAM,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAErD,4GAA4G;AAC5G,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAE3C"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The value when it is a JSON object, an empty one otherwise: what the node reads of a part it ignores. */
|
|
2
|
+
export function bodyOf(value) {
|
|
3
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? { ...value } : {};
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=body-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-of.js","sourceRoot":"","sources":["../../src/testing/body-of.ts"],"names":[],"mappings":"AAGA,4GAA4G;AAC5G,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The order of two values of a field as an index of OpenSearch orders them: a keyword by its bytes
|
|
3
|
+
* (the order of the code points), a number by value, a date by its instant, `false` before `true`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function compareAs(type: string, left: unknown, right: unknown): number;
|
|
6
|
+
//# sourceMappingURL=compare-as.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare-as.d.ts","sourceRoot":"","sources":["../../src/testing/compare-as.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAW7E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The order of two values of a field as an index of OpenSearch orders them: a keyword by its bytes
|
|
3
|
+
* (the order of the code points), a number by value, a date by its instant, `false` before `true`.
|
|
4
|
+
*/
|
|
5
|
+
export function compareAs(type, left, right) {
|
|
6
|
+
switch (type) {
|
|
7
|
+
case 'double':
|
|
8
|
+
return Number(left) - Number(right);
|
|
9
|
+
case 'date':
|
|
10
|
+
return Date.parse(String(left)) - Date.parse(String(right));
|
|
11
|
+
case 'boolean':
|
|
12
|
+
return Number(left === true || left === 'true') - Number(right === true || right === 'true');
|
|
13
|
+
default:
|
|
14
|
+
return codePoints(String(left), String(right));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** The order of the UTF-8 bytes, which is the order of the code points. */
|
|
18
|
+
function codePoints(left, right) {
|
|
19
|
+
return Buffer.compare(Buffer.from(left, 'utf8'), Buffer.from(right, 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=compare-as.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare-as.js","sourceRoot":"","sources":["../../src/testing/compare-as.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,IAAa,EAAE,KAAc;IACnE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACtC,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9D,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC;QAC/F;YACE,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,SAAS,UAAU,CAAC,IAAY,EAAE,KAAa;IAC7C,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FakeProperty } from './properties-of.js';
|
|
2
|
+
type Source = Readonly<Record<string, unknown>>;
|
|
3
|
+
export interface FakeDocument {
|
|
4
|
+
readonly source: Source;
|
|
5
|
+
readonly seqNo: number;
|
|
6
|
+
readonly primaryTerm: number;
|
|
7
|
+
}
|
|
8
|
+
/** One index of one shard: its strict mapping and its documents, each with its sequence number. */
|
|
9
|
+
export declare class FakeIndex {
|
|
10
|
+
properties: Readonly<Record<string, FakeProperty>>;
|
|
11
|
+
readonly documents: Map<string, FakeDocument>;
|
|
12
|
+
private sequence;
|
|
13
|
+
constructor(properties: Readonly<Record<string, FakeProperty>>);
|
|
14
|
+
/** Adds the fields a mapping lacks; a field mapped otherwise is refused, as the node does. */
|
|
15
|
+
extend(properties: Readonly<Record<string, FakeProperty>>): void;
|
|
16
|
+
write(id: string, source: Source): FakeDocument;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=fake-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-index.d.ts","sourceRoot":"","sources":["../../src/testing/fake-index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AASD,mGAAmG;AACnG,qBAAa,SAAS;IAKD,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAJrE,QAAQ,CAAC,SAAS,4BAAmC;IAErD,OAAO,CAAC,QAAQ,CAAM;IAEtB,YAAmB,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EAAI;IAEzE,8FAA8F;IAC9F,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,GAAG,IAAI,CAE/D;IAED,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,CAS9C;CACF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { bodyOf } from './body-of.js';
|
|
2
|
+
import { FakeRefusal } from './fake-refusal.js';
|
|
3
|
+
const LEAF_TYPES = {
|
|
4
|
+
keyword: (value) => ['string', 'number', 'boolean'].includes(typeof value),
|
|
5
|
+
double: (value) => typeof value === 'number',
|
|
6
|
+
boolean: (value) => typeof value === 'boolean',
|
|
7
|
+
date: (value) => typeof value === 'string' && !Number.isNaN(Date.parse(value)),
|
|
8
|
+
};
|
|
9
|
+
/** One index of one shard: its strict mapping and its documents, each with its sequence number. */
|
|
10
|
+
export class FakeIndex {
|
|
11
|
+
properties;
|
|
12
|
+
documents = new Map();
|
|
13
|
+
sequence = -1;
|
|
14
|
+
constructor(properties) {
|
|
15
|
+
this.properties = properties;
|
|
16
|
+
}
|
|
17
|
+
/** Adds the fields a mapping lacks; a field mapped otherwise is refused, as the node does. */
|
|
18
|
+
extend(properties) {
|
|
19
|
+
this.properties = merged(this.properties, properties);
|
|
20
|
+
}
|
|
21
|
+
write(id, source) {
|
|
22
|
+
checked(source, this.properties, '_doc');
|
|
23
|
+
this.sequence += 1;
|
|
24
|
+
const document = { source: structuredClone(source), seqNo: this.sequence, primaryTerm: 1 };
|
|
25
|
+
this.documents.set(id, document);
|
|
26
|
+
return document;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function merged(held, added) {
|
|
30
|
+
const result = { ...held };
|
|
31
|
+
for (const [name, property] of Object.entries(added)) {
|
|
32
|
+
const current = held[name];
|
|
33
|
+
if (current === undefined) {
|
|
34
|
+
result[name] = property;
|
|
35
|
+
}
|
|
36
|
+
else if ((current.type ?? 'object') !== (property.type ?? 'object')) {
|
|
37
|
+
throw new FakeRefusal(400, 'illegal_argument_exception', `mapper [${name}] cannot be changed from type [${String(current.type)}] to [${String(property.type)}]`);
|
|
38
|
+
}
|
|
39
|
+
else if (current.properties !== undefined || property.properties !== undefined) {
|
|
40
|
+
result[name] = { ...current, properties: merged(current.properties ?? {}, property.properties ?? {}) };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function checked(source, properties, within) {
|
|
46
|
+
for (const [name, value] of Object.entries(source)) {
|
|
47
|
+
const property = properties[name];
|
|
48
|
+
if (property === undefined) {
|
|
49
|
+
throw new FakeRefusal(400, 'strict_dynamic_mapping_exception', `mapping set to strict, dynamic introduction of [${name}] within [${within}] is not allowed`);
|
|
50
|
+
}
|
|
51
|
+
if (value === null || property.enabled === false) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (property.properties !== undefined) {
|
|
55
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
56
|
+
throw new FakeRefusal(400, 'mapper_parsing_exception', `object mapping for [${name}] tried to parse a value`);
|
|
57
|
+
}
|
|
58
|
+
checked(bodyOf(value), property.properties, name);
|
|
59
|
+
}
|
|
60
|
+
else if (!(LEAF_TYPES[property.type ?? 'keyword'] ?? (() => true))(value)) {
|
|
61
|
+
throw new FakeRefusal(400, 'mapper_parsing_exception', `failed to parse field [${name}] of type [${String(property.type)}]`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=fake-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-index.js","sourceRoot":"","sources":["../../src/testing/fake-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAW7C,MAAM,UAAU,GAA0D;IACxE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;IAC1E,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ;IAC5C,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS;IAC9C,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;CAC/E,CAAC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AAM,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACpD,CAAC;aAAM,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5E,MAAM,IAAI,WAAW,CACnB,GAAG,EACH,0BAA0B,EAC1B,0BAA0B,IAAI,cAAc,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CACrE,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** A refusal of a mapping or a document, as the node types it. */
|
|
2
|
+
export declare class FakeRefusal extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
readonly type: string;
|
|
5
|
+
constructor(status: number, type: string, reason: string);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=fake-refusal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-refusal.d.ts","sourceRoot":"","sources":["../../src/testing/fake-refusal.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,qBAAa,WAAY,SAAQ,KAAK;IAElC,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAFvB,YACW,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EAGf;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** A refusal of a mapping or a document, as the node types it. */
|
|
2
|
+
export class FakeRefusal extends Error {
|
|
3
|
+
status;
|
|
4
|
+
type;
|
|
5
|
+
constructor(status, type, reason) {
|
|
6
|
+
super(reason);
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.type = type;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=fake-refusal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-refusal.js","sourceRoot":"","sources":["../../src/testing/fake-refusal.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,MAAM,OAAO,WAAY,SAAQ,KAAK;IAEzB,MAAM;IACN,IAAI;IAFf,YACW,MAAc,EACd,IAAY,EACrB,MAAc;QAEd,KAAK,CAAC,MAAM,CAAC,CAAC;sBAJL,MAAM;oBACN,IAAI;IAIf,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { OpenSearchRequest, OpenSearchResponse, OpenSearchTransport } from '../transport/open-search-transport.js';
|
|
2
|
+
/**
|
|
3
|
+
* OpenSearch in memory, for the subset of the REST API the store calls: indices with a strict
|
|
4
|
+
* mapping, aliases with a filter and a routing, documents with their sequence numbers and the
|
|
5
|
+
* conditional writes on them, and the search of the query DSL the store writes. One shard per
|
|
6
|
+
* index, refreshed at every write: a search sees every write at once. The answers, statuses and
|
|
7
|
+
* error types are the ones of OpenSearch 3; the specs run on both, with the same expectations.
|
|
8
|
+
*/
|
|
9
|
+
export declare class InMemoryOpenSearch implements OpenSearchTransport {
|
|
10
|
+
/** Every request received, in order. */
|
|
11
|
+
readonly requests: OpenSearchRequest[];
|
|
12
|
+
private readonly indices;
|
|
13
|
+
private readonly aliases;
|
|
14
|
+
request(request: OpenSearchRequest): Promise<OpenSearchResponse>;
|
|
15
|
+
private routed;
|
|
16
|
+
private ofIndex;
|
|
17
|
+
private create;
|
|
18
|
+
private drop;
|
|
19
|
+
private changeAliases;
|
|
20
|
+
private get;
|
|
21
|
+
private put;
|
|
22
|
+
/** The one index a document call through `target` reaches. */
|
|
23
|
+
private writeIndexOf;
|
|
24
|
+
/** The indices a search of `target` reaches, each with the filters of the aliases it was reached through. */
|
|
25
|
+
private resolved;
|
|
26
|
+
private index;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=in-memory-open-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-open-search.d.ts","sourceRoot":"","sources":["../../src/testing/in-memory-open-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAkBrH;;;;;;GAMG;AACH,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,EAAE,CAAM;IAE5C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgC;IAExD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IAE/D,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsBrE;IAED,OAAO,CAAC,MAAM;IA+Bd,OAAO,CAAC,OAAO;IAYf,OAAO,CAAC,MAAM;IAcd,OAAO,CAAC,IAAI;IAYZ,OAAO,CAAC,aAAa;IA6BrB,OAAO,CAAC,GAAG;IAqBX,OAAO,CAAC,GAAG;IAgCX,8DAA8D;IAC9D,OAAO,CAAC,YAAY;IAoBpB,6GAA6G;IAC7G,OAAO,CAAC,QAAQ;IAuBhB,OAAO,CAAC,KAAK;CASd"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { bodiesOf } from './bodies-of.js';
|
|
2
|
+
import { bodyOf } from './body-of.js';
|
|
3
|
+
import { FakeIndex } from './fake-index.js';
|
|
4
|
+
import { FakeRefusal } from './fake-refusal.js';
|
|
5
|
+
import { propertiesOf } from './properties-of.js';
|
|
6
|
+
import { searched } from './searched.js';
|
|
7
|
+
import { textAt } from './text-at.js';
|
|
8
|
+
import { UnknownQueryError } from './unknown-query-error.js';
|
|
9
|
+
const INVALID_INDEX_NAME = /[A-Z\\/*?"<>| ,#:]|^[-_+]|^\.{1,2}$/;
|
|
10
|
+
/**
|
|
11
|
+
* OpenSearch in memory, for the subset of the REST API the store calls: indices with a strict
|
|
12
|
+
* mapping, aliases with a filter and a routing, documents with their sequence numbers and the
|
|
13
|
+
* conditional writes on them, and the search of the query DSL the store writes. One shard per
|
|
14
|
+
* index, refreshed at every write: a search sees every write at once. The answers, statuses and
|
|
15
|
+
* error types are the ones of OpenSearch 3; the specs run on both, with the same expectations.
|
|
16
|
+
*/
|
|
17
|
+
export class InMemoryOpenSearch {
|
|
18
|
+
/** Every request received, in order. */
|
|
19
|
+
requests = [];
|
|
20
|
+
indices = new Map();
|
|
21
|
+
aliases = new Map();
|
|
22
|
+
async request(request) {
|
|
23
|
+
this.requests.push(request);
|
|
24
|
+
try {
|
|
25
|
+
return this.routed(request, request.path
|
|
26
|
+
.split('/')
|
|
27
|
+
.filter((segment) => segment !== '')
|
|
28
|
+
.map(decodeURIComponent));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (error instanceof FakeRefusal) {
|
|
32
|
+
return refusal(error.status, error.type, error.message);
|
|
33
|
+
}
|
|
34
|
+
if (error instanceof UnknownQueryError) {
|
|
35
|
+
return refusal(400, 'parsing_exception', error.message);
|
|
36
|
+
}
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
routed(request, [target = '', action, id]) {
|
|
41
|
+
const body = bodyOf(request.body);
|
|
42
|
+
const query = request.query ?? {};
|
|
43
|
+
if (target === '_aliases' && request.method === 'POST') {
|
|
44
|
+
return this.changeAliases(body);
|
|
45
|
+
}
|
|
46
|
+
if (action === undefined) {
|
|
47
|
+
return this.ofIndex(request.method, target, body);
|
|
48
|
+
}
|
|
49
|
+
if (action === '_mapping') {
|
|
50
|
+
this.index(target).extend(propertiesOf(body['properties']));
|
|
51
|
+
return { status: 200, body: { acknowledged: true } };
|
|
52
|
+
}
|
|
53
|
+
if (action === '_search') {
|
|
54
|
+
const lenient = query['ignore_unavailable'] === 'true';
|
|
55
|
+
return { status: 200, body: searched(this.resolved(target, lenient), body) };
|
|
56
|
+
}
|
|
57
|
+
if (action === '_refresh') {
|
|
58
|
+
return { status: 200, body: { _shards: { failed: 0 } } };
|
|
59
|
+
}
|
|
60
|
+
return request.method === 'GET' ? this.get(target, String(id)) : this.put(target, String(id), body, query);
|
|
61
|
+
}
|
|
62
|
+
ofIndex(method, target, body) {
|
|
63
|
+
if (method === 'PUT') {
|
|
64
|
+
return this.create(target, body);
|
|
65
|
+
}
|
|
66
|
+
if (method === 'DELETE') {
|
|
67
|
+
return this.drop(target);
|
|
68
|
+
}
|
|
69
|
+
return { status: 200, body: { [target]: { mappings: { properties: this.index(target).properties } } } };
|
|
70
|
+
}
|
|
71
|
+
create(name, body) {
|
|
72
|
+
if (INVALID_INDEX_NAME.test(name) || name.length > 255) {
|
|
73
|
+
throw new FakeRefusal(400, 'invalid_index_name_exception', `Invalid index name [${name}]`);
|
|
74
|
+
}
|
|
75
|
+
if (this.indices.has(name) || this.aliases.has(name)) {
|
|
76
|
+
throw new FakeRefusal(400, 'resource_already_exists_exception', `index [${name}] already exists`);
|
|
77
|
+
}
|
|
78
|
+
this.indices.set(name, new FakeIndex(propertiesOf(bodyOf(body['mappings'])['properties'])));
|
|
79
|
+
return { status: 200, body: { acknowledged: true, index: name } };
|
|
80
|
+
}
|
|
81
|
+
drop(target) {
|
|
82
|
+
for (const name of target.split(',')) {
|
|
83
|
+
this.indices.delete(name);
|
|
84
|
+
for (const indices of this.aliases.values()) {
|
|
85
|
+
indices.delete(name);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { status: 200, body: { acknowledged: true } };
|
|
89
|
+
}
|
|
90
|
+
changeAliases(body) {
|
|
91
|
+
for (const action of bodiesOf(body['actions'])) {
|
|
92
|
+
const add = bodyOf(action['add']);
|
|
93
|
+
const [index, alias] = [textAt(add, 'index'), textAt(add, 'alias')];
|
|
94
|
+
const { filter, routing } = add;
|
|
95
|
+
this.index(index);
|
|
96
|
+
if (this.indices.has(alias)) {
|
|
97
|
+
throw new FakeRefusal(400, 'invalid_alias_name_exception', `Invalid alias name [${alias}]: an index exists with the same name`);
|
|
98
|
+
}
|
|
99
|
+
const indices = this.aliases.get(alias) ?? new Map();
|
|
100
|
+
indices.set(index, {
|
|
101
|
+
...(filter === undefined ? {} : { filter: bodyOf(filter) }),
|
|
102
|
+
...(typeof routing === 'string' ? { routing } : {}),
|
|
103
|
+
});
|
|
104
|
+
this.aliases.set(alias, indices);
|
|
105
|
+
}
|
|
106
|
+
return { status: 200, body: { acknowledged: true } };
|
|
107
|
+
}
|
|
108
|
+
get(target, id) {
|
|
109
|
+
const name = this.writeIndexOf(target, false);
|
|
110
|
+
const document = this.index(name).documents.get(id);
|
|
111
|
+
if (document === undefined) {
|
|
112
|
+
return { status: 404, body: { _index: name, _id: id, found: false } };
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
status: 200,
|
|
116
|
+
body: {
|
|
117
|
+
_index: name,
|
|
118
|
+
_id: id,
|
|
119
|
+
_seq_no: document.seqNo,
|
|
120
|
+
_primary_term: document.primaryTerm,
|
|
121
|
+
found: true,
|
|
122
|
+
_source: structuredClone(document.source),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
put(target, id, body, query) {
|
|
127
|
+
const name = this.writeIndexOf(target, query['require_alias'] === 'true');
|
|
128
|
+
const index = this.index(name);
|
|
129
|
+
const held = index.documents.get(id);
|
|
130
|
+
const create = query['op_type'] === 'create';
|
|
131
|
+
const conditional = query['if_seq_no'] !== undefined;
|
|
132
|
+
const conflict = (create && held !== undefined) ||
|
|
133
|
+
(conditional &&
|
|
134
|
+
(held === undefined ||
|
|
135
|
+
String(held.seqNo) !== query['if_seq_no'] ||
|
|
136
|
+
String(held.primaryTerm) !== query['if_primary_term']));
|
|
137
|
+
if (conflict) {
|
|
138
|
+
throw new FakeRefusal(409, 'version_conflict_engine_exception', `[${id}]: version conflict`);
|
|
139
|
+
}
|
|
140
|
+
const written = index.write(id, body);
|
|
141
|
+
return {
|
|
142
|
+
status: held === undefined ? 201 : 200,
|
|
143
|
+
body: {
|
|
144
|
+
_index: name,
|
|
145
|
+
_id: id,
|
|
146
|
+
result: held === undefined ? 'created' : 'updated',
|
|
147
|
+
_seq_no: written.seqNo,
|
|
148
|
+
_primary_term: written.primaryTerm,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** The one index a document call through `target` reaches. */
|
|
153
|
+
writeIndexOf(target, requireAlias) {
|
|
154
|
+
const alias = this.aliases.get(target);
|
|
155
|
+
if (alias === undefined) {
|
|
156
|
+
if (requireAlias || !this.indices.has(target)) {
|
|
157
|
+
throw notFound(target);
|
|
158
|
+
}
|
|
159
|
+
return target;
|
|
160
|
+
}
|
|
161
|
+
const [only, ...others] = [...alias.keys()];
|
|
162
|
+
if (only === undefined || others.length > 0) {
|
|
163
|
+
throw new FakeRefusal(400, 'illegal_argument_exception', `no write index is defined for alias [${target}]`);
|
|
164
|
+
}
|
|
165
|
+
return only;
|
|
166
|
+
}
|
|
167
|
+
/** The indices a search of `target` reaches, each with the filters of the aliases it was reached through. */
|
|
168
|
+
resolved(target, lenient) {
|
|
169
|
+
const reached = new Map();
|
|
170
|
+
for (const name of target.split(',')) {
|
|
171
|
+
const alias = this.aliases.get(name);
|
|
172
|
+
if (alias !== undefined) {
|
|
173
|
+
for (const [index, { filter }] of alias) {
|
|
174
|
+
reached.set(index, [...(reached.get(index) ?? []), filter]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (this.indices.has(name)) {
|
|
178
|
+
reached.set(name, [undefined]);
|
|
179
|
+
}
|
|
180
|
+
else if (!lenient) {
|
|
181
|
+
throw notFound(name);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return [...reached].map(([name, filters]) => ({ index: this.index(name), name, filters }));
|
|
185
|
+
}
|
|
186
|
+
index(name) {
|
|
187
|
+
const index = this.indices.get(name);
|
|
188
|
+
if (index === undefined) {
|
|
189
|
+
throw notFound(name);
|
|
190
|
+
}
|
|
191
|
+
return index;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function notFound(name) {
|
|
195
|
+
return new FakeRefusal(404, 'index_not_found_exception', `no such index [${name}]`);
|
|
196
|
+
}
|
|
197
|
+
function refusal(status, type, reason) {
|
|
198
|
+
return { status, body: { error: { type, reason }, status } };
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=in-memory-open-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-open-search.js","sourceRoot":"","sources":["../../src/testing/in-memory-open-search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAQ1D,MAAM,kBAAkB,GAAG,qCAAqC,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IAC7B,wCAAwC;IAC/B,QAAQ,GAAwB,EAAE,CAAC;IAE3B,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAEvC,OAAO,GAAG,IAAI,GAAG,EAAkC,CAAC;IAErE,KAAK,CAAC,OAAO,CAAC,OAA0B;QACtC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE5B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,MAAM,CAChB,OAAO,EACP,OAAO,CAAC,IAAI;iBACT,KAAK,CAAC,GAAG,CAAC;iBACV,MAAM,CAAC,CAAC,OAAO,EAAE,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AAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAErC,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,WAAW,CAAC,GAAG,EAAE,2BAA2B,EAAE,kBAAkB,IAAI,GAAG,CAAC,CAAC;AACtF,CAAC;AAED,SAAS,OAAO,CAAC,MAAc,EAAE,IAAY,EAAE,MAAc;IAC3D,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FakeProperty } from './properties-of.js';
|
|
2
|
+
type Source = Readonly<Record<string, unknown>>;
|
|
3
|
+
type Clause = Readonly<Record<string, unknown>>;
|
|
4
|
+
type Properties = Readonly<Record<string, FakeProperty>>;
|
|
5
|
+
/**
|
|
6
|
+
* Whether a document matches a query of the subset of the DSL the store writes: `bool`, `term`,
|
|
7
|
+
* `terms`, `range`, `exists`, `wildcard`, `prefix`, `match_all`. A missing or null value matches
|
|
8
|
+
* no comparison, as in an index.
|
|
9
|
+
*/
|
|
10
|
+
export declare function matches(query: Clause, source: Source, properties: Properties): boolean;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=matches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches.d.ts","sourceRoot":"","sources":["../../src/testing/matches.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAKpD,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAChD,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAChD,KAAK,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAsBtF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { bodiesOf } from './bodies-of.js';
|
|
2
|
+
import { bodyOf } from './body-of.js';
|
|
3
|
+
import { compareAs } from './compare-as.js';
|
|
4
|
+
import { typeAt } from './type-at.js';
|
|
5
|
+
import { UnknownQueryError } from './unknown-query-error.js';
|
|
6
|
+
import { valueAt } from './value-at.js';
|
|
7
|
+
/**
|
|
8
|
+
* Whether a document matches a query of the subset of the DSL the store writes: `bool`, `term`,
|
|
9
|
+
* `terms`, `range`, `exists`, `wildcard`, `prefix`, `match_all`. A missing or null value matches
|
|
10
|
+
* no comparison, as in an index.
|
|
11
|
+
*/
|
|
12
|
+
export function matches(query, source, properties) {
|
|
13
|
+
const [kind, body] = Object.entries(query)[0] ?? ['match_all', {}];
|
|
14
|
+
const clause = bodyOf(body);
|
|
15
|
+
if (kind === 'bool') {
|
|
16
|
+
return holdsBool(clause, source, properties);
|
|
17
|
+
}
|
|
18
|
+
if (kind === 'match_all') {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (kind === 'exists') {
|
|
22
|
+
const value = valueAt(source, String(clause['field']));
|
|
23
|
+
return value !== undefined && value !== null;
|
|
24
|
+
}
|
|
25
|
+
const [path = '', operand] = Object.entries(clause)[0] ?? [];
|
|
26
|
+
const value = valueAt(source, path);
|
|
27
|
+
return value !== undefined && value !== null && compares(kind, operand, value, typeAt(properties, path));
|
|
28
|
+
}
|
|
29
|
+
function holdsBool(clause, source, properties) {
|
|
30
|
+
const list = (name) => bodiesOf(clause[name]);
|
|
31
|
+
const all = [...list('filter'), ...list('must')].every((inner) => matches(inner, source, properties));
|
|
32
|
+
const none = list('must_not').every((inner) => !matches(inner, source, properties));
|
|
33
|
+
const should = list('should');
|
|
34
|
+
const least = Number(clause['minimum_should_match'] ?? (list('filter').length + list('must').length === 0 ? 1 : 0));
|
|
35
|
+
const some = should.filter((inner) => matches(inner, source, properties)).length >= Math.min(least, should.length);
|
|
36
|
+
return all && none && some;
|
|
37
|
+
}
|
|
38
|
+
function compares(kind, operand, value, type) {
|
|
39
|
+
const order = (other) => compareAs(type, value, other);
|
|
40
|
+
const written = bodyOf(operand);
|
|
41
|
+
switch (kind) {
|
|
42
|
+
case 'term':
|
|
43
|
+
return order(operand) === 0;
|
|
44
|
+
case 'terms':
|
|
45
|
+
return (Array.isArray(operand) ? operand : []).some((candidate) => order(candidate) === 0);
|
|
46
|
+
case 'range':
|
|
47
|
+
return Object.entries(written).every(([bound, limit]) => inRange(bound, order(limit)));
|
|
48
|
+
case 'wildcard':
|
|
49
|
+
return patternOf(String(written['value'])).test(String(value));
|
|
50
|
+
case 'prefix':
|
|
51
|
+
return String(value).startsWith(String(written['value']));
|
|
52
|
+
default:
|
|
53
|
+
throw new UnknownQueryError(`[${kind}] query is not supported by the fake`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function inRange(bound, order) {
|
|
57
|
+
switch (bound) {
|
|
58
|
+
case 'gt':
|
|
59
|
+
return order > 0;
|
|
60
|
+
case 'gte':
|
|
61
|
+
return order >= 0;
|
|
62
|
+
case 'lt':
|
|
63
|
+
return order < 0;
|
|
64
|
+
default:
|
|
65
|
+
return order <= 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** A wildcard pattern: `*` any run, `?` one character, `\` escapes the next one. */
|
|
69
|
+
function patternOf(pattern) {
|
|
70
|
+
let source = '';
|
|
71
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
72
|
+
const character = pattern[index] ?? '';
|
|
73
|
+
if (character === '\\') {
|
|
74
|
+
index += 1;
|
|
75
|
+
source += escapeRegExp(pattern[index] ?? '');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
source += character === '*' ? '[\\s\\S]*' : character === '?' ? '[\\s\\S]' : escapeRegExp(character);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return new RegExp(`^${source}$`, 'u');
|
|
82
|
+
}
|
|
83
|
+
function escapeRegExp(text) {
|
|
84
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=matches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches.js","sourceRoot":"","sources":["../../src/testing/matches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAMrC;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,MAAc,EAAE,UAAsB;IAC3E,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE5B,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IAC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,SAAS,CAAC,CAAC;QACvG,CAAC;IACH,CAAC;IAED,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { InMemoryOpenSearch } from './in-memory-open-search.js';
|
|
2
|
+
/** What the server answers instead of the node, for the specs of the transport. */
|
|
3
|
+
export type ServerMood = 'answering' | 'silent' | 'behind a proxy';
|
|
4
|
+
/**
|
|
5
|
+
* The in-memory OpenSearch on a port of its own, so that the specs reach it through
|
|
6
|
+
* `fetchTransport` as they reach a real node: the credentials of the security plugin checked on
|
|
7
|
+
* every request (401 otherwise), and a mood for the cases a transport must survive.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OpenSearchServer {
|
|
10
|
+
private readonly authorization;
|
|
11
|
+
static start(credentials: {
|
|
12
|
+
readonly username: string;
|
|
13
|
+
readonly password: string;
|
|
14
|
+
}): Promise<OpenSearchServer>;
|
|
15
|
+
readonly node: InMemoryOpenSearch;
|
|
16
|
+
mood: ServerMood;
|
|
17
|
+
private readonly http;
|
|
18
|
+
private readonly held;
|
|
19
|
+
private constructor();
|
|
20
|
+
get url(): string;
|
|
21
|
+
stop(): Promise<void>;
|
|
22
|
+
private answer;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=open-search-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-search-server.d.ts","sourceRoot":"","sources":["../../src/testing/open-search-server.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAI7D,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAEnE;;;;GAIG;AACH,qBAAa,gBAAgB;IAmBP,OAAO,CAAC,QAAQ,CAAC,aAAa;IAlBlD,OAAa,KAAK,CAAC,WAAW,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAQnH;IAED,QAAQ,CAAC,IAAI,qBAA4B;IAEzC,IAAI,EAAE,UAAU,CAAe;IAE/B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAElD,OAAO,eAIN;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAM1B;YAEa,MAAM;CAuCrB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { InMemoryOpenSearch } from './in-memory-open-search.js';
|
|
3
|
+
const METHODS = ['GET', 'PUT', 'POST', 'DELETE'];
|
|
4
|
+
/**
|
|
5
|
+
* The in-memory OpenSearch on a port of its own, so that the specs reach it through
|
|
6
|
+
* `fetchTransport` as they reach a real node: the credentials of the security plugin checked on
|
|
7
|
+
* every request (401 otherwise), and a mood for the cases a transport must survive.
|
|
8
|
+
*/
|
|
9
|
+
export class OpenSearchServer {
|
|
10
|
+
authorization;
|
|
11
|
+
static async start(credentials) {
|
|
12
|
+
const server = new OpenSearchServer(`Basic ${Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64')}`);
|
|
13
|
+
await new Promise((resolve) => server.http.listen(0, '127.0.0.1', resolve));
|
|
14
|
+
return server;
|
|
15
|
+
}
|
|
16
|
+
node = new InMemoryOpenSearch();
|
|
17
|
+
mood = 'answering';
|
|
18
|
+
http;
|
|
19
|
+
held = new Set();
|
|
20
|
+
constructor(authorization) {
|
|
21
|
+
this.authorization = authorization;
|
|
22
|
+
this.http = createServer((incoming, response) => {
|
|
23
|
+
void this.answer(incoming, response);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
get url() {
|
|
27
|
+
return `http://127.0.0.1:${String(Reflect.get(Object(this.http.address()), 'port'))}`;
|
|
28
|
+
}
|
|
29
|
+
async stop() {
|
|
30
|
+
for (const response of this.held) {
|
|
31
|
+
response.destroy();
|
|
32
|
+
}
|
|
33
|
+
await new Promise((resolve) => this.http.close(() => resolve()));
|
|
34
|
+
}
|
|
35
|
+
async answer(incoming, response) {
|
|
36
|
+
const text = await bodyOf(incoming);
|
|
37
|
+
if (this.mood === 'silent') {
|
|
38
|
+
this.held.add(response);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (this.mood === 'behind a proxy') {
|
|
42
|
+
response.writeHead(502, { 'content-type': 'text/html' }).end('<html><body>Bad gateway</body></html>');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (incoming.headers.authorization !== this.authorization) {
|
|
46
|
+
response.writeHead(401, { 'content-type': 'application/json' });
|
|
47
|
+
response.end(JSON.stringify({
|
|
48
|
+
error: { type: 'security_exception', reason: 'missing authentication credentials' },
|
|
49
|
+
status: 401,
|
|
50
|
+
}));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const url = new URL(incoming.url ?? '/', 'http://node');
|
|
54
|
+
const answered = await this.node.request({
|
|
55
|
+
method: methodOf(incoming.method),
|
|
56
|
+
path: url.pathname,
|
|
57
|
+
query: Object.fromEntries(url.searchParams),
|
|
58
|
+
...(text === '' ? {} : { body: JSON.parse(text) }),
|
|
59
|
+
});
|
|
60
|
+
response.writeHead(answered.status, { 'content-type': 'application/json' }).end(JSON.stringify(answered.body));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function bodyOf(incoming) {
|
|
64
|
+
let text = '';
|
|
65
|
+
incoming.setEncoding('utf8');
|
|
66
|
+
for await (const chunk of incoming) {
|
|
67
|
+
text += String(chunk);
|
|
68
|
+
}
|
|
69
|
+
return text;
|
|
70
|
+
}
|
|
71
|
+
/** The method of a request, among those the store sends. */
|
|
72
|
+
function methodOf(written) {
|
|
73
|
+
return METHODS.find((method) => method === written) ?? 'GET';
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=open-search-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-search-server.js","sourceRoot":"","sources":["../../src/testing/open-search-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA0D,MAAM,WAAW,CAAC;AAEjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,OAAO,GAA2C,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAKzF;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAmBU,aAAa;IAlBlD,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,WAAqE;QACtF,MAAM,MAAM,GAAG,IAAI,gBAAgB,CACjC,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAC7F,CAAC;QAEF,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QAElF,OAAO,MAAM,CAAC;IAChB,CAAC;IAEQ,IAAI,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAEzC,IAAI,GAAe,WAAW,CAAC;IAEd,IAAI,CAAS;IAEb,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IAElD,YAAqC,aAAqB;6BAArB,aAAa;QAChD,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;YAC9C,KAAK,IAAI,CAAC,MAAM,CAAC,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;AAC/D,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The mapping of a field, as the fake reads it. */
|
|
2
|
+
export interface FakeProperty {
|
|
3
|
+
readonly type?: string;
|
|
4
|
+
readonly enabled?: boolean;
|
|
5
|
+
readonly properties?: Readonly<Record<string, FakeProperty>>;
|
|
6
|
+
}
|
|
7
|
+
/** The properties of a mapping as a request wrote them, each field read for what the fake checks. */
|
|
8
|
+
export declare function propertiesOf(value: unknown): Readonly<Record<string, FakeProperty>>;
|
|
9
|
+
//# sourceMappingURL=properties-of.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"properties-of.d.ts","sourceRoot":"","sources":["../../src/testing/properties-of.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;CAC9D;AAED,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAInF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { bodyOf } from './body-of.js';
|
|
2
|
+
/** The properties of a mapping as a request wrote them, each field read for what the fake checks. */
|
|
3
|
+
export function propertiesOf(value) {
|
|
4
|
+
return Object.fromEntries(Object.entries(bodyOf(value)).map(([name, written]) => [name, propertyOf(bodyOf(written))]));
|
|
5
|
+
}
|
|
6
|
+
function propertyOf({ type, enabled, properties }) {
|
|
7
|
+
return {
|
|
8
|
+
...(typeof type === 'string' ? { type } : {}),
|
|
9
|
+
...(typeof enabled === 'boolean' ? { enabled } : {}),
|
|
10
|
+
...(properties === undefined ? {} : { properties: propertiesOf(properties) }),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=properties-of.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"properties-of.js","sourceRoot":"","sources":["../../src/testing/properties-of.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAS9C,qGAAqG;AACrG,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAC5F,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAQ;IACrD,OAAO;QACL,GAAG,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7C,GAAG,CAAC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;KAC9E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Body } from './body-of.js';
|
|
2
|
+
import type { FakeIndex } from './fake-index.js';
|
|
3
|
+
interface Reached {
|
|
4
|
+
readonly index: FakeIndex;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly filters: readonly (Body | undefined)[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The answer of a `_search` over the indices it reached: an index reached through an alias that
|
|
10
|
+
* filters keeps the documents one of its filters matches, the query keeps those it matches, then
|
|
11
|
+
* the sort, `from` and `size`, and the total unless `track_total_hits` is false.
|
|
12
|
+
*/
|
|
13
|
+
export declare function searched(reached: readonly Reached[], body: Body): Body;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=searched.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searched.d.ts","sourceRoot":"","sources":["../../src/testing/searched.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,KAAK,IAAI,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAc9C,UAAU,OAAO;IACf,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC;CACjD;AAQD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CA6BtE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { bodiesOf } from './bodies-of.js';
|
|
2
|
+
import { bodyOf } from './body-of.js';
|
|
3
|
+
import { compareAs } from './compare-as.js';
|
|
4
|
+
import { matches } from './matches.js';
|
|
5
|
+
import { typeAt } from './type-at.js';
|
|
6
|
+
import { valueAt } from './value-at.js';
|
|
7
|
+
/**
|
|
8
|
+
* The answer of a `_search` over the indices it reached: an index reached through an alias that
|
|
9
|
+
* filters keeps the documents one of its filters matches, the query keeps those it matches, then
|
|
10
|
+
* the sort, `from` and `size`, and the total unless `track_total_hits` is false.
|
|
11
|
+
*/
|
|
12
|
+
export function searched(reached, body) {
|
|
13
|
+
const sort = sortOf(body['sort']);
|
|
14
|
+
const query = bodyOf(body['query'] ?? { match_all: {} });
|
|
15
|
+
const hits = reached.flatMap(({ index, name, filters }) => [...index.documents]
|
|
16
|
+
.filter(([, { source }]) => filters.some((filter) => filter === undefined || matches(filter, source, index.properties)))
|
|
17
|
+
.filter(([, { source }]) => matches(query, source, index.properties))
|
|
18
|
+
.map(([id, { source }]) => ({
|
|
19
|
+
_index: name,
|
|
20
|
+
_id: id,
|
|
21
|
+
_source: structuredClone(source),
|
|
22
|
+
properties: index.properties,
|
|
23
|
+
})));
|
|
24
|
+
hits.sort((left, right) => ordered(sort, left, right));
|
|
25
|
+
const from = Number(body['from'] ?? 0);
|
|
26
|
+
const page = hits.slice(from, from + Number(body['size'] ?? 10)).map(({ properties: _properties, ...hit }) => hit);
|
|
27
|
+
return {
|
|
28
|
+
hits: {
|
|
29
|
+
...(body['track_total_hits'] === false ? {} : { total: { value: hits.length, relation: 'eq' } }),
|
|
30
|
+
hits: page,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function sortOf(written) {
|
|
35
|
+
return bodiesOf(written).flatMap((entry) => Object.entries(entry).map(([path, options]) => {
|
|
36
|
+
const { order = 'asc', missing = '_last' } = bodyOf(options);
|
|
37
|
+
return { path, order: String(order), missing: String(missing) };
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
function ordered(sort, left, right) {
|
|
41
|
+
for (const { path, order, missing } of sort) {
|
|
42
|
+
const type = typeAt(left.properties, path);
|
|
43
|
+
const a = valueAt(left._source, path);
|
|
44
|
+
const b = valueAt(right._source, path);
|
|
45
|
+
const absent = (value) => value === undefined || value === null;
|
|
46
|
+
if (absent(a) || absent(b)) {
|
|
47
|
+
const last = Number(absent(a)) - Number(absent(b));
|
|
48
|
+
if (last !== 0) {
|
|
49
|
+
return missing === '_first' ? -last : last;
|
|
50
|
+
}
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const compared = compareAs(type, a, b);
|
|
54
|
+
if (compared !== 0) {
|
|
55
|
+
return order === 'desc' ? -compared : compared;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=searched.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searched.js","sourceRoot":"","sources":["../../src/testing/searched.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAsBrC;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,OAA2B,EAAE,IAAU;IAC9D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;IAEzD,MAAM,IAAI,GAAU,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAC/D,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;SACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CACzB,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAC5F;SACA,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,C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QAEvC,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;YACnB,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;QACjD,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-at.d.ts","sourceRoot":"","sources":["../../src/testing/text-at.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,0EAA0E;AAC1E,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAItD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-at.js","sourceRoot":"","sources":["../../src/testing/text-at.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAC1E,MAAM,UAAU,MAAM,CAAC,IAAU,EAAE,GAAW;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;IAExB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FakeProperty } from './properties-of.js';
|
|
2
|
+
/** The type the mapping gives a dotted path: `keyword` for a path it does not know. */
|
|
3
|
+
export declare function typeAt(properties: Readonly<Record<string, FakeProperty>>, path: string): string;
|
|
4
|
+
//# sourceMappingURL=type-at.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-at.d.ts","sourceRoot":"","sources":["../../src/testing/type-at.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,uFAAuF;AACvF,wBAAgB,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAS/F"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The type the mapping gives a dotted path: `keyword` for a path it does not know. */
|
|
2
|
+
export function typeAt(properties, path) {
|
|
3
|
+
const [name = '', ...rest] = path.split('.');
|
|
4
|
+
const property = properties[name];
|
|
5
|
+
if (rest.length === 0 || property?.properties === undefined) {
|
|
6
|
+
return property?.type ?? 'keyword';
|
|
7
|
+
}
|
|
8
|
+
return typeAt(property.properties, rest.join('.'));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=type-at.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-at.js","sourceRoot":"","sources":["../../src/testing/type-at.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,UAAU,MAAM,CAAC,UAAkD,EAAE,IAAY;IACrF,MAAM,CAAC,IAAI,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAElC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;QAC5D,OAAO,QAAQ,EAAE,IAAI,IAAI,SAAS,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknown-query-error.d.ts","sourceRoot":"","sources":["../../src/testing/unknown-query-error.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qBAAa,iBAAkB,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unknown-query-error.js","sourceRoot":"","sources":["../../src/testing/unknown-query-error.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,OAAO,iBAAkB,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-at.d.ts","sourceRoot":"","sources":["../../src/testing/value-at.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhD,gFAAgF;AAChF,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAI7D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The value at a dotted path of a document, `undefined` when it holds none. */
|
|
2
|
+
export function valueAt(source, path) {
|
|
3
|
+
return path.split('.').reduce((value, name) => {
|
|
4
|
+
return typeof value === 'object' && value !== null ? Reflect.get(value, name) : undefined;
|
|
5
|
+
}, source);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=value-at.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-at.js","sourceRoot":"","sources":["../../src/testing/value-at.ts"],"names":[],"mappings":"AAEA,gFAAgF;AAChF,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,IAAY;IAClD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAU,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5F,CAAC,EAAE,MAAM,CAAC,CAAC;AACb,CAAC"}
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { criteriaContract, readModelRowsContract, type CriteriaContractOptions, type ReadModelRowsContractOptions, } from '@ddd-ts-kit/testing/contracts';
|
|
2
|
+
export { InMemoryOpenSearch } from './testing/in-memory-open-search.js';
|
|
3
|
+
export { OpenSearchServer, type ServerMood } from './testing/open-search-server.js';
|
|
2
4
|
//# sourceMappingURL=testing.d.ts.map
|
package/dist/testing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,GAClC,MAAM,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,GAClC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/testing.js
CHANGED
package/dist/testing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,GAGtB,MAAM,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,GAGtB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAmB,MAAM,8BAA8B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts-kit/opensearch",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.109.0",
|
|
4
4
|
"description": "Adapter of the kernel ReadModelStore port on OpenSearch, with no client library: criteria translated to the query DSL, writes ordered by the event stamp, tenants kept apart by an index each or by filtered aliases on one index.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ddd",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"dist"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@ddd-ts-kit/kernel": "0.
|
|
49
|
+
"@ddd-ts-kit/kernel": "0.109.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@ddd-ts-kit/testing": "0.
|
|
52
|
+
"@ddd-ts-kit/testing": "0.109.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependenciesMeta": {
|
|
55
55
|
"@ddd-ts-kit/testing": {
|
|
@@ -57,6 +57,6 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@ddd-ts-kit/testing": "0.
|
|
60
|
+
"@ddd-ts-kit/testing": "0.109.0"
|
|
61
61
|
}
|
|
62
62
|
}
|