Skip to content

Commit

Permalink
Merge pull request #17 from smartive/develop
Browse files Browse the repository at this point in the history
Release 2019-07-30
  • Loading branch information
mfeltscher authored Jul 30, 2019
2 parents 19934a0 + b53b361 commit d4663ea
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 40 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ coverage
!*.d.ts
test

.appveyor.yml
jest.json
.travis.yml
tsconfig.json
Expand Down
34 changes: 17 additions & 17 deletions jest.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"collectCoverage": true,
"transform": {
"^.+\\.tsx?$": "<rootDir>/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"
]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/models/Mapping.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export function generatePropertyDecorator<T>(key: string): (data?: T) => Propert
mapping = {};
setMetadata(target, mapping, key);
}
mapping[name] = data;
mapping[name.toString()] = data;
};
}
6 changes: 3 additions & 3 deletions src/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function buildMapping(type: Function): { name: string | undefined, mapping: EsIn
mapping._source = meta._source;
mapping.dynamic = meta.dynamic;
}

const properties = getMetadata<Fields>(type, 'properties');
if (properties) {
mapping.properties = buildFields(properties, type);
Expand Down Expand Up @@ -94,12 +94,12 @@ function buildField(field: Field, name: string, type: Function): EsIndexTemplate
res.type = 'object';

const prototype = field.type.prototype;

const fieldTypeMeta = getMetadata<SubMappingMeta>(prototype);
if (fieldTypeMeta) {
res = { ...res, ...fieldTypeMeta };
}

const properties = getMetadata<Fields>(prototype, 'properties');
if (properties) {
res.properties = buildFields(properties, prototype);
Expand Down
3 changes: 3 additions & 0 deletions test/__snapshots__/decorators.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Object {
"b": Object {
"type": [Function],
},
"c": Object {
"type": [Function],
},
"keyword": undefined,
"keywordArray": Object {
"type": [Function],
Expand Down
8 changes: 8 additions & 0 deletions test/__snapshots__/template.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions test/decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { getMetadata } from '../src/utils/metadata';
describe('decorators', () => {
describe('EsObject ', () => {
it('generates metadata', () => {

@EsSubMapping()
class Obj {
@EsProperty()
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions test/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { buildMappings } from '../src/utils/template';
describe('decorators', () => {
describe('EsObject ', () => {
it('generates metadata', () => {

@EsSubMapping()
class Obj {
@EsProperty()
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit d4663ea

Please sign in to comment.