diff --git a/.npmignore b/.npmignore index 3f808b1..93e0634 100644 --- a/.npmignore +++ b/.npmignore @@ -14,6 +14,7 @@ coverage !*.d.ts test +.appveyor.yml jest.json .travis.yml tsconfig.json diff --git a/jest.json b/jest.json index 3420744..6d9c898 100644 --- a/jest.json +++ b/jest.json @@ -1,18 +1,18 @@ { - "collectCoverage": true, - "transform": { - "^.+\\.tsx?$": "/node_modules/ts-jest/preprocessor.js" - }, - "testMatch": [ - "**/test/**/*.spec.ts" - ], - "testPathIgnorePatterns": [ - "/node_modules/" - ], - "moduleFileExtensions": [ - "ts", - "tsx", - "js", - "json" - ] -} + "collectCoverage": true, + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testMatch": [ + "**/test/**/*.spec.ts" + ], + "testPathIgnorePatterns": [ + "/node_modules/" + ], + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "json" + ] +} \ No newline at end of file diff --git a/package.json b/package.json index ae0efd5..1222f94 100644 --- a/package.json +++ b/package.json @@ -36,12 +36,12 @@ "homepage": "https://github.com/smartive/es-model#readme", "dependencies": {}, "devDependencies": { - "@smartive/tslint-config": "^3.0.1", - "@types/jest": "^22.2.2", + "@smartive/tslint-config": "^4.0.0", + "@types/jest": "^23.0.0", "del-cli": "^1.1.0", - "jest": "^22.4.3", + "jest": "^24.8.0", "semantic-release": "^15.1.5", - "ts-jest": "^22.4.2", + "ts-jest": "^24.0.2", "tslint": "^5.9.1", "tslint-config-airbnb": "^5.8.0", "tsutils": "^2.26.0", diff --git a/src/models/Mapping.ts b/src/models/Mapping.ts index 1a533cf..c0ed3b5 100644 --- a/src/models/Mapping.ts +++ b/src/models/Mapping.ts @@ -1,16 +1,16 @@ -export type SimpleFieldType = 'text' | 'keyword' | 'date' | 'long' | 'double' | 'boolean' | 'ip'; +export type SimpleFieldType = 'text' | 'keyword' | 'date' | 'long' | 'integer' | 'double' | 'boolean' | 'ip'; export type ObjectFieldType = 'object' | 'nested'; export type SpecializedFieldType = 'geo_point' | 'geo_shape' | 'completion'; export type Field = { type?: SimpleFieldType | SpecializedFieldType | Function; - search_analyzer?: 'suggestion_query_analyzer'; - analyzer?: 'suggestion_analyzer' | 'default_analyzer'; + search_analyzer?: string; + analyzer?: string; format?: 'date' | 'hour_minute'; }; export type Fields = { - [name: string]: Field, + [name: string]: Field; }; export type MappingMeta = { diff --git a/src/utils/decorators.ts b/src/utils/decorators.ts index 9e700e2..df811c5 100644 --- a/src/utils/decorators.ts +++ b/src/utils/decorators.ts @@ -11,6 +11,6 @@ export function generatePropertyDecorator(key: string): (data?: T) => Propert mapping = {}; setMetadata(target, mapping, key); } - mapping[name] = data; + mapping[name.toString()] = data; }; } diff --git a/src/utils/template.ts b/src/utils/template.ts index f9785df..e5a8b05 100644 --- a/src/utils/template.ts +++ b/src/utils/template.ts @@ -50,7 +50,7 @@ function buildMapping(type: Function): { name: string | undefined, mapping: EsIn mapping._source = meta._source; mapping.dynamic = meta.dynamic; } - + const properties = getMetadata(type, 'properties'); if (properties) { mapping.properties = buildFields(properties, type); @@ -94,12 +94,12 @@ function buildField(field: Field, name: string, type: Function): EsIndexTemplate res.type = 'object'; const prototype = field.type.prototype; - + const fieldTypeMeta = getMetadata(prototype); if (fieldTypeMeta) { res = { ...res, ...fieldTypeMeta }; } - + const properties = getMetadata(prototype, 'properties'); if (properties) { res.properties = buildFields(properties, prototype); diff --git a/test/__snapshots__/decorators.spec.ts.snap b/test/__snapshots__/decorators.spec.ts.snap index 61de69a..dbe2f3d 100644 --- a/test/__snapshots__/decorators.spec.ts.snap +++ b/test/__snapshots__/decorators.spec.ts.snap @@ -14,6 +14,9 @@ Object { "b": Object { "type": [Function], }, + "c": Object { + "type": [Function], + }, "keyword": undefined, "keywordArray": Object { "type": [Function], diff --git a/test/__snapshots__/template.spec.ts.snap b/test/__snapshots__/template.spec.ts.snap index b317c40..63b7f3a 100644 --- a/test/__snapshots__/template.spec.ts.snap +++ b/test/__snapshots__/template.spec.ts.snap @@ -9,6 +9,14 @@ Object { "dynamic": "strict", "properties": Object { "b": Object { + "properties": Object { + "aProperty": Object { + "type": "keyword", + }, + }, + "type": "object", + }, + "c": Object { "properties": Object { "aProperty": Object { "type": "keyword", diff --git a/test/decorators.spec.ts b/test/decorators.spec.ts index faff842..496ba21 100644 --- a/test/decorators.spec.ts +++ b/test/decorators.spec.ts @@ -9,7 +9,6 @@ import { getMetadata } from '../src/utils/metadata'; describe('decorators', () => { describe('EsObject ', () => { it('generates metadata', () => { - @EsSubMapping() class Obj { @EsProperty() @@ -43,12 +42,12 @@ describe('decorators', () => { @EsProperty({ type: 'text' }) text: string; - + @EsProperty({ type: Obj }) b: Obj; @EsProperty({ type: Nested }) - b: Nested; + c: Nested; @EsProperty({ type: WithFields }) withFields: WithFields; diff --git a/test/template.spec.ts b/test/template.spec.ts index 86dadb6..0d8c062 100644 --- a/test/template.spec.ts +++ b/test/template.spec.ts @@ -9,7 +9,6 @@ import { buildMappings } from '../src/utils/template'; describe('decorators', () => { describe('EsObject ', () => { it('generates metadata', () => { - @EsSubMapping() class Obj { @EsProperty() @@ -43,12 +42,12 @@ describe('decorators', () => { @EsProperty({ type: 'text' }) text: string; - + @EsProperty({ type: Obj }) b: Obj; @EsProperty({ type: Nested }) - b: Nested; + c: Nested; @EsProperty({ type: WithFields }) withFields: WithFields; diff --git a/tsconfig.json b/tsconfig.json index c40f1e5..25054ce 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,9 @@ { - "extends": "./config/tsconfig.base.json", - "compilerOptions": { - "watch": true, - "sourceMap": true - } + "extends": "./config/tsconfig.base.json", + "compilerOptions": { + "strictPropertyInitialization": false, + "experimentalDecorators": true, + "watch": true, + "sourceMap": true + } }