elasticlink 0.2.2-beta → 0.4.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -177
- package/dist/__tests__/aggregation-builder.test.d.ts +2 -0
- package/dist/__tests__/aggregation-builder.test.d.ts.map +1 -0
- package/dist/__tests__/aggregation-builder.test.js +622 -0
- package/dist/__tests__/bulk.test.d.ts +2 -0
- package/dist/__tests__/bulk.test.d.ts.map +1 -0
- package/dist/__tests__/bulk.test.js +679 -0
- package/dist/__tests__/examples.test.d.ts +2 -0
- package/dist/__tests__/examples.test.d.ts.map +1 -0
- package/dist/__tests__/examples.test.js +2123 -0
- package/dist/__tests__/fixtures/finance.d.ts +58 -0
- package/dist/__tests__/fixtures/finance.d.ts.map +1 -0
- package/dist/__tests__/fixtures/finance.js +73 -0
- package/dist/__tests__/fixtures/legal.d.ts +14 -0
- package/dist/__tests__/fixtures/legal.d.ts.map +1 -0
- package/dist/__tests__/fixtures/legal.js +27 -0
- package/dist/__tests__/fixtures/real-estate.d.ts +31 -0
- package/dist/__tests__/fixtures/real-estate.d.ts.map +1 -0
- package/dist/__tests__/fixtures/real-estate.js +39 -0
- package/dist/__tests__/index-management.test.d.ts +2 -0
- package/dist/__tests__/index-management.test.d.ts.map +1 -0
- package/dist/__tests__/index-management.test.js +1699 -0
- package/dist/__tests__/integration/aggregation.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/aggregation.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/aggregation.integration.test.js +188 -0
- package/dist/__tests__/integration/bulk.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/bulk.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/bulk.integration.test.js +90 -0
- package/dist/__tests__/integration/fixtures/finance.d.ts +37 -0
- package/dist/__tests__/integration/fixtures/finance.d.ts.map +1 -0
- package/dist/__tests__/integration/fixtures/finance.js +58 -0
- package/dist/__tests__/integration/fixtures/legal.d.ts +38 -0
- package/dist/__tests__/integration/fixtures/legal.d.ts.map +1 -0
- package/dist/__tests__/integration/fixtures/legal.js +65 -0
- package/dist/__tests__/integration/fixtures/real-estate.d.ts +17 -0
- package/dist/__tests__/integration/fixtures/real-estate.d.ts.map +1 -0
- package/dist/__tests__/integration/fixtures/real-estate.js +28 -0
- package/dist/__tests__/integration/helpers.d.ts +15 -0
- package/dist/__tests__/integration/helpers.d.ts.map +1 -0
- package/dist/__tests__/integration/helpers.js +21 -0
- package/dist/__tests__/integration/index-management.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/index-management.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/index-management.integration.test.js +67 -0
- package/dist/__tests__/integration/multi-search.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/multi-search.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/multi-search.integration.test.js +49 -0
- package/dist/__tests__/integration/query.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/query.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/query.integration.test.js +101 -0
- package/dist/__tests__/integration/suggester.integration.test.d.ts +2 -0
- package/dist/__tests__/integration/suggester.integration.test.d.ts.map +1 -0
- package/dist/__tests__/integration/suggester.integration.test.js +42 -0
- package/dist/__tests__/multi-search.test.d.ts +2 -0
- package/dist/__tests__/multi-search.test.d.ts.map +1 -0
- package/dist/__tests__/multi-search.test.js +325 -0
- package/dist/__tests__/query-builder-extensions.test.d.ts +2 -0
- package/dist/__tests__/query-builder-extensions.test.d.ts.map +1 -0
- package/dist/__tests__/query-builder-extensions.test.js +436 -0
- package/dist/__tests__/query-builder.test.d.ts +2 -0
- package/dist/__tests__/query-builder.test.d.ts.map +1 -0
- package/dist/__tests__/query-builder.test.js +5482 -0
- package/dist/__tests__/settings-presets.test.d.ts +2 -0
- package/dist/__tests__/settings-presets.test.d.ts.map +1 -0
- package/dist/__tests__/settings-presets.test.js +183 -0
- package/dist/__tests__/suggester.test.d.ts +2 -0
- package/dist/__tests__/suggester.test.d.ts.map +1 -0
- package/dist/__tests__/suggester.test.js +1006 -0
- package/dist/aggregation.builder.d.ts +4 -2
- package/dist/aggregation.builder.d.ts.map +1 -1
- package/dist/aggregation.builder.js +102 -95
- package/dist/aggregation.types.d.ts +16 -14
- package/dist/aggregation.types.d.ts.map +1 -1
- package/dist/bulk.builder.d.ts +126 -2
- package/dist/bulk.builder.d.ts.map +1 -1
- package/dist/bulk.builder.js +11 -12
- package/dist/bulk.types.d.ts.map +1 -1
- package/dist/field.helpers.d.ts +92 -42
- package/dist/field.helpers.d.ts.map +1 -1
- package/dist/field.helpers.js +99 -20
- package/dist/field.types.d.ts +113 -6
- package/dist/field.types.d.ts.map +1 -1
- package/dist/field.types.js +3 -3
- package/dist/index-management.builder.d.ts +19 -14
- package/dist/index-management.builder.d.ts.map +1 -1
- package/dist/index-management.builder.js +36 -34
- package/dist/index-management.types.d.ts +32 -62
- package/dist/index-management.types.d.ts.map +1 -1
- package/dist/index-management.types.js +0 -1
- package/dist/index.d.ts +18 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -8
- package/dist/mapping.builder.d.ts +37 -0
- package/dist/mapping.builder.d.ts.map +1 -0
- package/dist/mapping.builder.js +38 -0
- package/dist/mapping.types.d.ts +105 -0
- package/dist/mapping.types.d.ts.map +1 -0
- package/dist/mapping.types.js +6 -0
- package/dist/multi-search.builder.d.ts +5 -3
- package/dist/multi-search.builder.d.ts.map +1 -1
- package/dist/multi-search.builder.js +6 -4
- package/dist/multi-search.types.d.ts +7 -6
- package/dist/multi-search.types.d.ts.map +1 -1
- package/dist/query.builder.d.ts +3 -11
- package/dist/query.builder.d.ts.map +1 -1
- package/dist/query.builder.js +118 -259
- package/dist/query.types.d.ts +140 -236
- package/dist/query.types.d.ts.map +1 -1
- package/dist/query.types.js +2 -1
- package/dist/settings.presets.d.ts +98 -0
- package/dist/settings.presets.d.ts.map +1 -0
- package/dist/settings.presets.js +115 -0
- package/dist/suggester.builder.d.ts +5 -3
- package/dist/suggester.builder.d.ts.map +1 -1
- package/dist/suggester.builder.js +3 -2
- package/dist/suggester.types.d.ts +5 -4
- package/dist/suggester.types.d.ts.map +1 -1
- package/dist/vector.types.d.ts.map +1 -1
- package/package.json +12 -9
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregation.integration.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/integration/aggregation.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { query, indexBuilder } from '../../index.js';
|
|
2
|
+
import { createIndex, deleteIndex, indexDoc, refreshIndex, search } from './helpers.js';
|
|
3
|
+
import { matterMappings, MATTERS } from './fixtures/legal.js';
|
|
4
|
+
const INDEX = 'int-aggregation';
|
|
5
|
+
describe('AggregationBuilder', () => {
|
|
6
|
+
beforeAll(async () => {
|
|
7
|
+
await createIndex(INDEX, indexBuilder().mappings(matterMappings).build());
|
|
8
|
+
for (const doc of MATTERS)
|
|
9
|
+
await indexDoc(INDEX, doc);
|
|
10
|
+
await refreshIndex(INDEX);
|
|
11
|
+
});
|
|
12
|
+
afterAll(() => deleteIndex(INDEX));
|
|
13
|
+
describe('Aggregation — terms', () => {
|
|
14
|
+
it('buckets documents by a keyword field', async () => {
|
|
15
|
+
const result = await search(INDEX, query(matterMappings)
|
|
16
|
+
.matchAll()
|
|
17
|
+
.aggs((agg) => agg.terms('by_area', 'practice_area'))
|
|
18
|
+
.size(0)
|
|
19
|
+
.build());
|
|
20
|
+
expect(result.aggregations.by_area.buckets).toMatchInlineSnapshot(`
|
|
21
|
+
[
|
|
22
|
+
{
|
|
23
|
+
"doc_count": 1,
|
|
24
|
+
"key": "corporate",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"doc_count": 1,
|
|
28
|
+
"key": "intellectual-property",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"doc_count": 1,
|
|
32
|
+
"key": "real-estate",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"doc_count": 1,
|
|
36
|
+
"key": "securities",
|
|
37
|
+
},
|
|
38
|
+
]
|
|
39
|
+
`);
|
|
40
|
+
});
|
|
41
|
+
it('supports size option and sub-aggregations', async () => {
|
|
42
|
+
const result = await search(INDEX, query(matterMappings)
|
|
43
|
+
.matchAll()
|
|
44
|
+
.aggs((agg) => agg.terms('by_area', 'practice_area', { size: 2 }).subAgg((sub) => sub.avg('avg_rate', 'billing_rate')))
|
|
45
|
+
.size(0)
|
|
46
|
+
.build());
|
|
47
|
+
expect(result.aggregations.by_area.buckets).toMatchInlineSnapshot(`
|
|
48
|
+
[
|
|
49
|
+
{
|
|
50
|
+
"avg_rate": {
|
|
51
|
+
"value": 850,
|
|
52
|
+
},
|
|
53
|
+
"doc_count": 1,
|
|
54
|
+
"key": "corporate",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"avg_rate": {
|
|
58
|
+
"value": 780,
|
|
59
|
+
},
|
|
60
|
+
"doc_count": 1,
|
|
61
|
+
"key": "intellectual-property",
|
|
62
|
+
},
|
|
63
|
+
]
|
|
64
|
+
`);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('Aggregation — metrics', () => {
|
|
68
|
+
it('computes avg, min, max, sum, and value_count in one request', async () => {
|
|
69
|
+
const result = await search(INDEX, query(matterMappings)
|
|
70
|
+
.matchAll()
|
|
71
|
+
.aggs((agg) => agg
|
|
72
|
+
.avg('avg_rate', 'billing_rate')
|
|
73
|
+
.min('min_rate', 'billing_rate')
|
|
74
|
+
.max('max_rate', 'billing_rate')
|
|
75
|
+
.sum('total_rate', 'billing_rate')
|
|
76
|
+
.valueCount('count', 'billing_rate'))
|
|
77
|
+
.size(0)
|
|
78
|
+
.build());
|
|
79
|
+
expect(result.aggregations).toMatchInlineSnapshot(`
|
|
80
|
+
{
|
|
81
|
+
"avg_rate": {
|
|
82
|
+
"value": 792.5,
|
|
83
|
+
},
|
|
84
|
+
"count": {
|
|
85
|
+
"value": 4,
|
|
86
|
+
},
|
|
87
|
+
"max_rate": {
|
|
88
|
+
"value": 920,
|
|
89
|
+
},
|
|
90
|
+
"min_rate": {
|
|
91
|
+
"value": 620,
|
|
92
|
+
},
|
|
93
|
+
"total_rate": {
|
|
94
|
+
"value": 3170,
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
`);
|
|
98
|
+
});
|
|
99
|
+
it('computes stats and cardinality', async () => {
|
|
100
|
+
const result = await search(INDEX, query(matterMappings)
|
|
101
|
+
.matchAll()
|
|
102
|
+
.aggs((agg) => agg.stats('rate_stats', 'billing_rate').cardinality('unique_areas', 'practice_area'))
|
|
103
|
+
.size(0)
|
|
104
|
+
.build());
|
|
105
|
+
expect(result.aggregations).toMatchInlineSnapshot(`
|
|
106
|
+
{
|
|
107
|
+
"rate_stats": {
|
|
108
|
+
"avg": 792.5,
|
|
109
|
+
"count": 4,
|
|
110
|
+
"max": 920,
|
|
111
|
+
"min": 620,
|
|
112
|
+
"sum": 3170,
|
|
113
|
+
},
|
|
114
|
+
"unique_areas": {
|
|
115
|
+
"value": 4,
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
`);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('Aggregation — range', () => {
|
|
122
|
+
it('buckets documents into named billing rate ranges', async () => {
|
|
123
|
+
const result = await search(INDEX, query(matterMappings)
|
|
124
|
+
.matchAll()
|
|
125
|
+
.aggs((agg) => agg.range('rate_bands', 'billing_rate', {
|
|
126
|
+
ranges: [
|
|
127
|
+
{ key: 'standard', to: 700 },
|
|
128
|
+
{ key: 'senior', from: 700, to: 850 },
|
|
129
|
+
{ key: 'partner', from: 850 }
|
|
130
|
+
]
|
|
131
|
+
}))
|
|
132
|
+
.size(0)
|
|
133
|
+
.build());
|
|
134
|
+
expect(result.aggregations.rate_bands.buckets).toMatchInlineSnapshot(`
|
|
135
|
+
[
|
|
136
|
+
{
|
|
137
|
+
"doc_count": 1,
|
|
138
|
+
"key": "standard",
|
|
139
|
+
"to": 700,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"doc_count": 1,
|
|
143
|
+
"from": 700,
|
|
144
|
+
"key": "senior",
|
|
145
|
+
"to": 850,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"doc_count": 2,
|
|
149
|
+
"from": 850,
|
|
150
|
+
"key": "partner",
|
|
151
|
+
},
|
|
152
|
+
]
|
|
153
|
+
`);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
describe('Aggregation — dateHistogram', () => {
|
|
157
|
+
it('groups documents into yearly buckets', async () => {
|
|
158
|
+
const result = await search(INDEX, query(matterMappings)
|
|
159
|
+
.matchAll()
|
|
160
|
+
.aggs((agg) => agg.dateHistogram('by_year', 'opened_at', {
|
|
161
|
+
calendar_interval: 'year',
|
|
162
|
+
min_doc_count: 1,
|
|
163
|
+
format: 'yyyy'
|
|
164
|
+
}))
|
|
165
|
+
.size(0)
|
|
166
|
+
.build());
|
|
167
|
+
expect(result.aggregations.by_year.buckets.map((b) => ({
|
|
168
|
+
year: b.key_as_string,
|
|
169
|
+
doc_count: b.doc_count
|
|
170
|
+
}))).toMatchInlineSnapshot(`
|
|
171
|
+
[
|
|
172
|
+
{
|
|
173
|
+
"doc_count": 1,
|
|
174
|
+
"year": "2021",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"doc_count": 1,
|
|
178
|
+
"year": "2022",
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"doc_count": 2,
|
|
182
|
+
"year": "2023",
|
|
183
|
+
},
|
|
184
|
+
]
|
|
185
|
+
`);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk.integration.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/integration/bulk.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { bulk, query, indexBuilder } from '../../index.js';
|
|
2
|
+
import { createIndex, deleteIndex, refreshIndex, search, bulkRequest } from './helpers.js';
|
|
3
|
+
import { tradeMappings } from './fixtures/finance.js';
|
|
4
|
+
const INDEX = 'int-bulk';
|
|
5
|
+
describe('BulkBuilder', () => {
|
|
6
|
+
beforeAll(() => createIndex(INDEX, indexBuilder().mappings(tradeMappings).build()));
|
|
7
|
+
afterAll(() => deleteIndex(INDEX));
|
|
8
|
+
describe('Bulk — index and create', () => {
|
|
9
|
+
it('indexes and creates documents via bulk, then retrieves them', async () => {
|
|
10
|
+
const ndjson = bulk(tradeMappings)
|
|
11
|
+
.index({ reference: 'TRD-001 AAPL Buy 100', status: 'settled', priority: 1 }, { _index: INDEX, _id: 'trd-1' })
|
|
12
|
+
.index({ reference: 'TRD-002 MSFT Sell 50', status: 'pending', priority: 2 }, { _index: INDEX, _id: 'trd-2' })
|
|
13
|
+
.create({ reference: 'TRD-003 GOOG Buy 25', status: 'pending', priority: 3 }, { _index: INDEX, _id: 'trd-3' })
|
|
14
|
+
.build();
|
|
15
|
+
const bulkResult = await bulkRequest(ndjson);
|
|
16
|
+
await refreshIndex(INDEX);
|
|
17
|
+
expect(bulkResult.errors).toBe(false);
|
|
18
|
+
const searchResult = await search(INDEX, query(tradeMappings).matchAll().build());
|
|
19
|
+
expect(searchResult.hits.total.value).toBe(3);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('Bulk — update', () => {
|
|
23
|
+
it('partially updates a document', async () => {
|
|
24
|
+
const ndjson = bulk(tradeMappings)
|
|
25
|
+
.update({ _index: INDEX, _id: 'trd-2', doc: { status: 'settled' } })
|
|
26
|
+
.build();
|
|
27
|
+
await bulkRequest(ndjson);
|
|
28
|
+
await refreshIndex(INDEX);
|
|
29
|
+
const result = await search(INDEX, query(tradeMappings).term('status', 'settled').build());
|
|
30
|
+
expect(result.hits.total.value).toBe(2);
|
|
31
|
+
});
|
|
32
|
+
it('upserts a document that does not exist', async () => {
|
|
33
|
+
const ndjson = bulk(tradeMappings)
|
|
34
|
+
.update({
|
|
35
|
+
_index: INDEX,
|
|
36
|
+
_id: 'trd-4',
|
|
37
|
+
doc: {
|
|
38
|
+
reference: 'TRD-004 TSLA Buy 10',
|
|
39
|
+
status: 'pending',
|
|
40
|
+
priority: 4
|
|
41
|
+
},
|
|
42
|
+
doc_as_upsert: true
|
|
43
|
+
})
|
|
44
|
+
.build();
|
|
45
|
+
await bulkRequest(ndjson);
|
|
46
|
+
await refreshIndex(INDEX);
|
|
47
|
+
const result = await search(INDEX, query(tradeMappings).matchAll().build());
|
|
48
|
+
expect(result.hits.total.value).toBe(4);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('Bulk — delete', () => {
|
|
52
|
+
it('deletes a document via bulk', async () => {
|
|
53
|
+
const ndjson = bulk(tradeMappings).delete({ _index: INDEX, _id: 'trd-4' }).build();
|
|
54
|
+
await bulkRequest(ndjson);
|
|
55
|
+
await refreshIndex(INDEX);
|
|
56
|
+
const result = await search(INDEX, query(tradeMappings).matchAll().build());
|
|
57
|
+
expect(result.hits.total.value).toBe(3);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('Bulk — mixed operations', () => {
|
|
61
|
+
it('executes index, update, and delete in a single bulk call', async () => {
|
|
62
|
+
const ndjson = bulk(tradeMappings)
|
|
63
|
+
.index({ reference: 'TRD-099 NVDA Buy 5', status: 'pending', priority: 99 }, { _index: INDEX, _id: 'trd-temp' })
|
|
64
|
+
.update({ _index: INDEX, _id: 'trd-1', doc: { priority: 10 } })
|
|
65
|
+
.delete({ _index: INDEX, _id: 'trd-3' })
|
|
66
|
+
.build();
|
|
67
|
+
const bulkResult = await bulkRequest(ndjson);
|
|
68
|
+
expect(bulkResult.errors).toBe(false);
|
|
69
|
+
expect(bulkResult.items.map((i) => {
|
|
70
|
+
const [op] = Object.keys(i);
|
|
71
|
+
return { op, result: i[op].result };
|
|
72
|
+
})).toMatchInlineSnapshot(`
|
|
73
|
+
[
|
|
74
|
+
{
|
|
75
|
+
"op": "index",
|
|
76
|
+
"result": "created",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"op": "update",
|
|
80
|
+
"result": "updated",
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"op": "delete",
|
|
84
|
+
"result": "deleted",
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
`);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Infer } from '../../../index.js';
|
|
2
|
+
export declare const instrumentMappings: Readonly<{
|
|
3
|
+
_fieldTypes: {
|
|
4
|
+
name: "text";
|
|
5
|
+
asset_class: "keyword";
|
|
6
|
+
sector: "keyword";
|
|
7
|
+
tags: "keyword";
|
|
8
|
+
price: "integer";
|
|
9
|
+
yield_rate: "float";
|
|
10
|
+
active: "boolean";
|
|
11
|
+
listed_date: "date";
|
|
12
|
+
};
|
|
13
|
+
properties: Record<string, import("../../../index-management.types.js").FieldMapping>;
|
|
14
|
+
_mappingOptions?: import("../../../mapping.types.js").MappingOptions;
|
|
15
|
+
}>;
|
|
16
|
+
export type Instrument = Infer<typeof instrumentMappings>;
|
|
17
|
+
export declare const INSTRUMENTS: {
|
|
18
|
+
name: string;
|
|
19
|
+
asset_class: string;
|
|
20
|
+
sector: string;
|
|
21
|
+
tags: string[];
|
|
22
|
+
price: number;
|
|
23
|
+
yield_rate: number;
|
|
24
|
+
active: boolean;
|
|
25
|
+
listed_date: string;
|
|
26
|
+
}[];
|
|
27
|
+
export declare const tradeMappings: Readonly<{
|
|
28
|
+
_fieldTypes: {
|
|
29
|
+
reference: "text";
|
|
30
|
+
status: "keyword";
|
|
31
|
+
priority: "integer";
|
|
32
|
+
};
|
|
33
|
+
properties: Record<string, import("../../../index-management.types.js").FieldMapping>;
|
|
34
|
+
_mappingOptions?: import("../../../mapping.types.js").MappingOptions;
|
|
35
|
+
}>;
|
|
36
|
+
export type Trade = Infer<typeof tradeMappings>;
|
|
37
|
+
//# sourceMappingURL=finance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finance.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/integration/fixtures/finance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;EAS7B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE1D,eAAO,MAAM,WAAW;;;;;;;;;GAyCvB,CAAC;AAEF,eAAO,MAAM,aAAa;;;;;;;;EAIxB,CAAC;AAEH,MAAM,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { mappings, text, keyword, integer, float, date, boolean } from '../../../index.js';
|
|
2
|
+
export const instrumentMappings = mappings({
|
|
3
|
+
name: text(),
|
|
4
|
+
asset_class: keyword(),
|
|
5
|
+
sector: keyword(),
|
|
6
|
+
tags: keyword(),
|
|
7
|
+
price: integer(),
|
|
8
|
+
yield_rate: float(),
|
|
9
|
+
active: boolean(),
|
|
10
|
+
listed_date: date()
|
|
11
|
+
});
|
|
12
|
+
export const INSTRUMENTS = [
|
|
13
|
+
{
|
|
14
|
+
name: 'US Treasury 10-Year Note',
|
|
15
|
+
asset_class: 'fixed-income',
|
|
16
|
+
sector: 'government',
|
|
17
|
+
tags: ['sovereign', 'investment-grade', 'liquid'],
|
|
18
|
+
price: 98,
|
|
19
|
+
yield_rate: 4.3,
|
|
20
|
+
active: true,
|
|
21
|
+
listed_date: '2023-02-15'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'Investment Grade Corporate Bond ETF',
|
|
25
|
+
asset_class: 'fixed-income',
|
|
26
|
+
sector: 'corporate',
|
|
27
|
+
tags: ['etf', 'investment-grade', 'diversified'],
|
|
28
|
+
price: 112,
|
|
29
|
+
yield_rate: 5.1,
|
|
30
|
+
active: true,
|
|
31
|
+
listed_date: '2023-07-01'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Emerging Market Equity Fund',
|
|
35
|
+
asset_class: 'equity',
|
|
36
|
+
sector: 'emerging-markets',
|
|
37
|
+
tags: ['high-risk', 'growth', 'diversified'],
|
|
38
|
+
price: 54,
|
|
39
|
+
yield_rate: 2.8,
|
|
40
|
+
active: false,
|
|
41
|
+
listed_date: '2022-09-12'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'S&P 500 Index Fund',
|
|
45
|
+
asset_class: 'equity',
|
|
46
|
+
sector: 'broad-market',
|
|
47
|
+
tags: ['index', 'sp500', 'liquid'],
|
|
48
|
+
price: 479,
|
|
49
|
+
yield_rate: 1.5,
|
|
50
|
+
active: true,
|
|
51
|
+
listed_date: '2021-03-22'
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
export const tradeMappings = mappings({
|
|
55
|
+
reference: text(),
|
|
56
|
+
status: keyword(),
|
|
57
|
+
priority: integer()
|
|
58
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Infer } from '../../../index.js';
|
|
2
|
+
export declare const matterMappings: Readonly<{
|
|
3
|
+
_fieldTypes: {
|
|
4
|
+
title: "text";
|
|
5
|
+
practice_area: "keyword";
|
|
6
|
+
billing_rate: "integer";
|
|
7
|
+
risk_score: "float";
|
|
8
|
+
opened_at: "date";
|
|
9
|
+
};
|
|
10
|
+
properties: Record<string, import("../../../index-management.types.js").FieldMapping>;
|
|
11
|
+
_mappingOptions?: import("../../../mapping.types.js").MappingOptions;
|
|
12
|
+
}>;
|
|
13
|
+
export type Matter = Infer<typeof matterMappings>;
|
|
14
|
+
export declare const MATTERS: {
|
|
15
|
+
title: string;
|
|
16
|
+
practice_area: string;
|
|
17
|
+
billing_rate: number;
|
|
18
|
+
risk_score: number;
|
|
19
|
+
opened_at: string;
|
|
20
|
+
}[];
|
|
21
|
+
export declare const attorneyMappings: Readonly<{
|
|
22
|
+
_fieldTypes: {
|
|
23
|
+
name: "text";
|
|
24
|
+
practice_area: "keyword";
|
|
25
|
+
name_suggest: "completion";
|
|
26
|
+
};
|
|
27
|
+
properties: Record<string, import("../../../index-management.types.js").FieldMapping>;
|
|
28
|
+
_mappingOptions?: import("../../../mapping.types.js").MappingOptions;
|
|
29
|
+
}>;
|
|
30
|
+
export type Attorney = Infer<typeof attorneyMappings>;
|
|
31
|
+
export declare const ATTORNEYS: {
|
|
32
|
+
name: string;
|
|
33
|
+
practice_area: string;
|
|
34
|
+
name_suggest: {
|
|
35
|
+
input: string[];
|
|
36
|
+
};
|
|
37
|
+
}[];
|
|
38
|
+
//# sourceMappingURL=legal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legal.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/integration/fixtures/legal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,eAAO,MAAM,cAAc;;;;;;;;;;EAMzB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAElD,eAAO,MAAM,OAAO;;;;;;GA6BnB,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;EAI3B,CAAC;AAEH,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEtD,eAAO,MAAM,SAAS;;;;;;GAqBrB,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { mappings, text, keyword, integer, float, date, completion } from '../../../index.js';
|
|
2
|
+
export const matterMappings = mappings({
|
|
3
|
+
title: text(),
|
|
4
|
+
practice_area: keyword(),
|
|
5
|
+
billing_rate: integer(),
|
|
6
|
+
risk_score: float(),
|
|
7
|
+
opened_at: date()
|
|
8
|
+
});
|
|
9
|
+
export const MATTERS = [
|
|
10
|
+
{
|
|
11
|
+
title: 'Mergers & Acquisitions Advisory',
|
|
12
|
+
practice_area: 'corporate',
|
|
13
|
+
billing_rate: 850,
|
|
14
|
+
risk_score: 3.2,
|
|
15
|
+
opened_at: '2023-01-10'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
title: 'SEC Enforcement Defense',
|
|
19
|
+
practice_area: 'securities',
|
|
20
|
+
billing_rate: 920,
|
|
21
|
+
risk_score: 4.7,
|
|
22
|
+
opened_at: '2023-05-22'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: 'Patent Infringement Litigation',
|
|
26
|
+
practice_area: 'intellectual-property',
|
|
27
|
+
billing_rate: 780,
|
|
28
|
+
risk_score: 3.9,
|
|
29
|
+
opened_at: '2022-08-14'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: 'Commercial Real Estate Finance',
|
|
33
|
+
practice_area: 'real-estate',
|
|
34
|
+
billing_rate: 620,
|
|
35
|
+
risk_score: 2.1,
|
|
36
|
+
opened_at: '2021-11-03'
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
export const attorneyMappings = mappings({
|
|
40
|
+
name: text(),
|
|
41
|
+
practice_area: keyword(),
|
|
42
|
+
name_suggest: completion()
|
|
43
|
+
});
|
|
44
|
+
export const ATTORNEYS = [
|
|
45
|
+
{
|
|
46
|
+
name: 'Sarah Chen',
|
|
47
|
+
practice_area: 'corporate',
|
|
48
|
+
name_suggest: { input: ['Sarah Chen', 'Chen'] }
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'Marcus Williams',
|
|
52
|
+
practice_area: 'securities',
|
|
53
|
+
name_suggest: { input: ['Marcus Williams', 'Williams'] }
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'Priya Kapoor',
|
|
57
|
+
practice_area: 'intellectual-property',
|
|
58
|
+
name_suggest: { input: ['Priya Kapoor', 'Kapoor'] }
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'James Okafor',
|
|
62
|
+
practice_area: 'real-estate',
|
|
63
|
+
name_suggest: { input: ['James Okafor', 'Okafor'] }
|
|
64
|
+
}
|
|
65
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Infer } from '../../../index.js';
|
|
2
|
+
export declare const listingMappings: Readonly<{
|
|
3
|
+
_fieldTypes: {
|
|
4
|
+
address: "text";
|
|
5
|
+
property_class: "keyword";
|
|
6
|
+
list_price: "integer";
|
|
7
|
+
};
|
|
8
|
+
properties: Record<string, import("../../../index-management.types.js").FieldMapping>;
|
|
9
|
+
_mappingOptions?: import("../../../mapping.types.js").MappingOptions;
|
|
10
|
+
}>;
|
|
11
|
+
export type Listing = Infer<typeof listingMappings>;
|
|
12
|
+
export declare const LISTINGS: {
|
|
13
|
+
address: string;
|
|
14
|
+
property_class: string;
|
|
15
|
+
list_price: number;
|
|
16
|
+
}[];
|
|
17
|
+
//# sourceMappingURL=real-estate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"real-estate.d.ts","sourceRoot":"","sources":["../../../../src/__tests__/integration/fixtures/real-estate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,eAAO,MAAM,eAAe;;;;;;;;EAI1B,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEpD,eAAO,MAAM,QAAQ;;;;GAqBpB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mappings, text, keyword, integer } from '../../../index.js';
|
|
2
|
+
export const listingMappings = mappings({
|
|
3
|
+
address: text(),
|
|
4
|
+
property_class: keyword(),
|
|
5
|
+
list_price: integer()
|
|
6
|
+
});
|
|
7
|
+
export const LISTINGS = [
|
|
8
|
+
{
|
|
9
|
+
address: '200 Harbor View Dr, Unit 12A',
|
|
10
|
+
property_class: 'condo',
|
|
11
|
+
list_price: 1_250_000
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
address: '845 Park Avenue, Apt 8B',
|
|
15
|
+
property_class: 'condo',
|
|
16
|
+
list_price: 2_100_000
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
address: '12 Park Terrace',
|
|
20
|
+
property_class: 'townhouse',
|
|
21
|
+
list_price: 3_100_000
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
address: '500 Riverside Drive',
|
|
25
|
+
property_class: 'townhouse',
|
|
26
|
+
list_price: 4_800_000
|
|
27
|
+
}
|
|
28
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type EsRequest = {
|
|
2
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
3
|
+
path?: string;
|
|
4
|
+
body?: any;
|
|
5
|
+
};
|
|
6
|
+
export declare const createIndex: (index: string, config: any) => Promise<any>;
|
|
7
|
+
export declare const deleteIndex: (index: string) => Promise<any>;
|
|
8
|
+
export declare const refreshIndex: (index: string) => Promise<any>;
|
|
9
|
+
export declare const search: (index: string, body: any) => Promise<any>;
|
|
10
|
+
export declare const indexDoc: (index: string, body: any) => Promise<any>;
|
|
11
|
+
export declare const bulkRequest: (ndjson: string) => Promise<any>;
|
|
12
|
+
export declare const msearchRequest: (index: string, ndjson: string) => Promise<any>;
|
|
13
|
+
export declare const esGet: (path: string) => Promise<any>;
|
|
14
|
+
export declare const esPost: (path: string, body?: any) => Promise<any>;
|
|
15
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/__tests__/integration/helpers.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAC;AAgBF,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,EAAE,QAAQ,GAAG,iBAAgD,CAAC;AAEvG,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,iBAA2C,CAAC;AAErF,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,iBAAkD,CAAC;AAE7F,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,EAAE,MAAM,GAAG,iBAAuD,CAAC;AAEvG,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,MAAM,GAAG,iBAAoD,CAAC;AAEtG,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,iBAAwC,CAAC;AAEnF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,iBAAoD,CAAC;AAEjH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,iBAAsC,CAAC;AAEzE,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,OAAO,GAAG,iBAA6C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
const ES_URL = process.env.ELASTICSEARCH_URL || 'http://localhost:9200';
|
|
3
|
+
const esJson = (url, method, body) => fetch(url, {
|
|
4
|
+
method,
|
|
5
|
+
headers: { 'Content-Type': 'application/json' },
|
|
6
|
+
...(body && { body: JSON.stringify(body) })
|
|
7
|
+
}).then((r) => r.json());
|
|
8
|
+
const esNdjson = (url, body) => fetch(url, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: { 'Content-Type': 'application/x-ndjson' },
|
|
11
|
+
body
|
|
12
|
+
}).then((r) => r.json());
|
|
13
|
+
export const createIndex = (index, config) => esJson(`${ES_URL}/${index}`, 'PUT', config);
|
|
14
|
+
export const deleteIndex = (index) => esJson(`${ES_URL}/${index}`, 'DELETE');
|
|
15
|
+
export const refreshIndex = (index) => esJson(`${ES_URL}/${index}/_refresh`, 'POST');
|
|
16
|
+
export const search = (index, body) => esJson(`${ES_URL}/${index}/_search`, 'POST', body);
|
|
17
|
+
export const indexDoc = (index, body) => esJson(`${ES_URL}/${index}/_doc`, 'POST', body);
|
|
18
|
+
export const bulkRequest = (ndjson) => esNdjson(`${ES_URL}/_bulk`, ndjson);
|
|
19
|
+
export const msearchRequest = (index, ndjson) => esNdjson(`${ES_URL}/${index}/_msearch`, ndjson);
|
|
20
|
+
export const esGet = (path) => esJson(`${ES_URL}${path}`, 'GET');
|
|
21
|
+
export const esPost = (path, body) => esJson(`${ES_URL}${path}`, 'POST', body);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-management.integration.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/integration/index-management.integration.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { indexBuilder, mappings, text, keyword, integer, float, date, boolean, geoPoint, denseVector, nested, completion } from '../../index.js';
|
|
2
|
+
import { createIndex, deleteIndex, esGet } from './helpers.js';
|
|
3
|
+
const INDEX_FULL = 'int-index-mgmt-full';
|
|
4
|
+
const INDEX_ALIAS = 'int-index-mgmt-alias';
|
|
5
|
+
const fullDocMappings = mappings({
|
|
6
|
+
title: text(),
|
|
7
|
+
category: keyword(),
|
|
8
|
+
count: integer(),
|
|
9
|
+
score: float(),
|
|
10
|
+
created_at: date(),
|
|
11
|
+
active: boolean(),
|
|
12
|
+
location: geoPoint(),
|
|
13
|
+
embedding: denseVector({ dims: 3 }),
|
|
14
|
+
tags: nested({ label: keyword(), weight: float() }),
|
|
15
|
+
suggest: completion()
|
|
16
|
+
});
|
|
17
|
+
const fieldTypes = (props) => Object.fromEntries(Object.entries(props).map(([k, v]) => [k, v.type]));
|
|
18
|
+
describe('Index Management — full index config', () => {
|
|
19
|
+
beforeAll(() => createIndex(INDEX_FULL, indexBuilder().mappings(fullDocMappings).settings({ number_of_shards: 1, number_of_replicas: 0 }).build()));
|
|
20
|
+
afterAll(() => deleteIndex(INDEX_FULL));
|
|
21
|
+
it('registers all field types in the mapping', async () => {
|
|
22
|
+
const result = await esGet(`/${INDEX_FULL}/_mapping`);
|
|
23
|
+
expect(fieldTypes(result[INDEX_FULL].mappings.properties)).toMatchInlineSnapshot(`
|
|
24
|
+
{
|
|
25
|
+
"active": "boolean",
|
|
26
|
+
"category": "keyword",
|
|
27
|
+
"count": "integer",
|
|
28
|
+
"created_at": "date",
|
|
29
|
+
"embedding": "dense_vector",
|
|
30
|
+
"location": "geo_point",
|
|
31
|
+
"score": "float",
|
|
32
|
+
"suggest": "completion",
|
|
33
|
+
"tags": "nested",
|
|
34
|
+
"title": "text",
|
|
35
|
+
}
|
|
36
|
+
`);
|
|
37
|
+
});
|
|
38
|
+
it('applies index settings', async () => {
|
|
39
|
+
const result = await esGet(`/${INDEX_FULL}/_settings`);
|
|
40
|
+
const { [INDEX_FULL]: { settings: { index: { number_of_shards, number_of_replicas } } } } = result;
|
|
41
|
+
expect({ number_of_shards, number_of_replicas }).toMatchInlineSnapshot(`
|
|
42
|
+
{
|
|
43
|
+
"number_of_replicas": "0",
|
|
44
|
+
"number_of_shards": "1",
|
|
45
|
+
}
|
|
46
|
+
`);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('Index Management — aliases', () => {
|
|
50
|
+
beforeAll(() => createIndex(INDEX_ALIAS, indexBuilder()
|
|
51
|
+
.mappings({ title: text() })
|
|
52
|
+
.alias('int-alias-read')
|
|
53
|
+
.alias('int-alias-write', { is_write_index: true })
|
|
54
|
+
.build()));
|
|
55
|
+
afterAll(() => deleteIndex(INDEX_ALIAS));
|
|
56
|
+
it('creates aliases with correct configuration', async () => {
|
|
57
|
+
const result = await esGet(`/${INDEX_ALIAS}/_alias`);
|
|
58
|
+
expect(result[INDEX_ALIAS].aliases).toMatchInlineSnapshot(`
|
|
59
|
+
{
|
|
60
|
+
"int-alias-read": {},
|
|
61
|
+
"int-alias-write": {
|
|
62
|
+
"is_write_index": true,
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
`);
|
|
66
|
+
});
|
|
67
|
+
});
|