Skip to content

Commit

Permalink
[Console] Convert lib/mappings to TypeScript (opensearch-project#4008) (
Browse files Browse the repository at this point in the history
opensearch-project#4500)

* Convert mappings.js to TypeScript

Signed-off-by: Sirazh Gabdullin <[email protected]>

* Convert mappings.test.js to TypeScript

Signed-off-by: Sirazh Gabdullin <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Sirazh Gabdullin <[email protected]>

* Add test for getTypes with multi-index mode

Signed-off-by: Sirazh Gabdullin <[email protected]>

* type update

Signed-off-by: Sirazh Gabdullin <[email protected]>

* update typing

Signed-off-by: Sirazh Gabdullin <[email protected]>

* CHANGELOG fix

Signed-off-by: Sirazh Gabdullin <[email protected]>

* Changelog update

Signed-off-by: Sirazh Gabdullin <[email protected]>

* Update Changelog

Signed-off-by: Sirazh Gabdullin <[email protected]>

---------

Signed-off-by: Sirazh Gabdullin <[email protected]>
Signed-off-by: Kawika Avilla <[email protected]>
Signed-off-by: Josh Romero <[email protected]>
Signed-off-by: Anan Zhuang <[email protected]>
Co-authored-by: Kawika Avilla <[email protected]>
Co-authored-by: Qingyang(Abby) Hu <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
(cherry picked from commit e07c5e6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e079fde commit 0331696
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* under the License.
*/

import { Field } from '../mappings';
import '../../../application/models/sense_editor/sense_editor.test.mocks';
import * as mappings from '../mappings';

Expand All @@ -39,7 +40,7 @@ describe('Mappings', () => {
mappings.clear();
});

function fc(f1, f2) {
function fc(f1: Field, f2: Field) {
if (f1.name < f2.name) {
return -1;
}
Expand All @@ -49,8 +50,8 @@ describe('Mappings', () => {
return 0;
}

function f(name, type) {
return { name: name, type: type || 'string' };
function f(name: string, type?: string) {
return { name, type: type || 'string' };
}

test('Multi fields 1.0 style', function () {
Expand Down Expand Up @@ -256,10 +257,37 @@ describe('Mappings', () => {
'test_index2',
]);
expect(mappings.getIndices(false).sort()).toEqual(['test_index1', 'test_index2']);
expect(mappings.expandAliases(['alias1', 'test_index2']).sort()).toEqual([
expect((mappings.expandAliases(['alias1', 'test_index2']) as string[]).sort()).toEqual([
'test_index1',
'test_index2',
]);
expect(mappings.expandAliases('alias2')).toEqual('test_index2');
});

test('Multi types', function () {
mappings.loadMappings({
index: {
properties: {
name1: {
type: 'object',
path: 'just_name',
properties: {
first1: { type: 'string' },
last1: { type: 'string', index_name: 'i_last_1' },
},
},
name2: {
type: 'object',
path: 'full',
properties: {
first2: { type: 'string' },
last2: { type: 'string', index_name: 'i_last_2' },
},
},
},
},
});

expect(mappings.getTypes()).toEqual(['properties']);
});
});
Loading

0 comments on commit 0331696

Please sign in to comment.