Skip to content

Commit

Permalink
Merge pull request #3506 from terascope/datatype-indexed-required-con…
Browse files Browse the repository at this point in the history
…stant

add constant for index required field types
  • Loading branch information
jsnoble authored Dec 20, 2023
2 parents f02b3a4 + b25c02d commit 37cacb5
Show file tree
Hide file tree
Showing 54 changed files with 141 additions and 107 deletions.
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"bunyan": "^1.8.15",
"elasticsearch-store": "^0.75.0",
"elasticsearch-store": "^0.75.1",
"fs-extra": "^11.1.1",
"ms": "^2.1.3",
"nanoid": "^3.3.4",
Expand Down
10 changes: 5 additions & 5 deletions packages/data-mate/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terascope/data-mate",
"displayName": "Data-Mate",
"version": "0.49.0",
"version": "0.49.1",
"description": "Library of data validations/transformations",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/data-mate#readme",
"repository": {
Expand Down Expand Up @@ -29,9 +29,9 @@
"test:watch": "ts-scripts test --watch . --"
},
"dependencies": {
"@terascope/data-types": "^0.43.0",
"@terascope/types": "^0.12.0",
"@terascope/utils": "^0.52.0",
"@terascope/data-types": "^0.43.1",
"@terascope/types": "^0.12.1",
"@terascope/utils": "^0.52.1",
"@types/validator": "^13.11.7",
"awesome-phonenumber": "^2.70.0",
"date-fns": "^2.30.0",
Expand All @@ -46,7 +46,7 @@
"uuid": "^9.0.0",
"valid-url": "^1.0.9",
"validator": "^13.11.0",
"xlucene-parser": "^0.51.0"
"xlucene-parser": "^0.51.1"
},
"devDependencies": {
"@types/ip6addr": "^0.2.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/data-types/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@terascope/data-types",
"displayName": "Data Types",
"version": "0.43.0",
"version": "0.43.1",
"description": "A library for defining the data structures and mapping",
"homepage": "https://github.com/terascope/teraslice/tree/master/packages/data-types#readme",
"bugs": {
Expand All @@ -26,8 +26,8 @@
"test:watch": "ts-scripts test --watch . --"
},
"dependencies": {
"@terascope/types": "^0.12.0",
"@terascope/utils": "^0.52.0",
"@terascope/types": "^0.12.1",
"@terascope/utils": "^0.52.1",
"graphql": "^14.7.0",
"lodash": "^4.17.21",
"yargs": "^17.7.2"
Expand Down
17 changes: 12 additions & 5 deletions packages/data-types/src/types/base-type.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ClientMetadata, DataTypeFieldConfig, xLuceneTypeConfig } from '@terascope/types';
import * as ts from '@terascope/utils';
import {
GraphQLType, TypeESMapping
} from '../interfaces';
ClientMetadata, DataTypeFieldConfig, xLuceneTypeConfig, indexedRequiredFieldTypes
} from '@terascope/types';
import { castArray } from '@terascope/utils';
import { GraphQLType, TypeESMapping } from '../interfaces';
import { formatGQLComment } from '../graphql-helper';

export interface IBaseType {
Expand All @@ -27,6 +27,13 @@ export default abstract class BaseType {
this.config = config;
}

protected _validateESMapping() {
if (this.config.indexed === false) {
if (this.config.type in indexedRequiredFieldTypes) {
throw new Error(`${this.config.type} is required to be indexed`);
}
}
}
abstract toESMapping(config: ClientMetadata): TypeESMapping;
abstract toGraphQL(options?: ToGraphQLOptions): GraphQLType;
abstract toXlucene(): xLuceneTypeConfig;
Expand Down Expand Up @@ -60,7 +67,7 @@ export default abstract class BaseType {

function makeCustomTypes(customType?: string|(string[])): string[] {
if (!customType?.length) return [];
return ts.castArray(customType);
return castArray(customType);
}

export function formatGQLType(type: string, desc?: string):string {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/any.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class AnyType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: { [this.field]: { enabled: false } }
};
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class BooleanType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/boundary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Boundary extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/byte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Byte extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class DateType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
let format: string|undefined;

if (this.config.format && (
Expand Down
6 changes: 2 additions & 4 deletions packages/data-types/src/types/v1/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import BaseType from '../base-type';
import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Domain extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
override toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/double.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Double extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Float extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
4 changes: 1 addition & 3 deletions packages/data-types/src/types/v1/geo-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class GeoJSON extends BaseType {
toESMapping(clientMetaData: ClientMetadata): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
// we need to used deprecated quadtree and strategy because CONTAINS is
// not yet supported in 6.X or 7.X as of now
return {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/geo-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class GeoPointType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/geo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';
// TODO: This type is deprecated, not sure how to properly indicate it.
export default class GeoType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
4 changes: 1 addition & 3 deletions packages/data-types/src/types/v1/hostname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Hostname extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
return {
mapping: {
[this.field]: {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Integer extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/ip-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class IpRangeType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/ip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class IPType extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
4 changes: 1 addition & 3 deletions packages/data-types/src/types/v1/keyword-case-insensitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class KeywordCaseInsensitive extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.use_fields_hack ? {
Expand Down
4 changes: 1 addition & 3 deletions packages/data-types/src/types/v1/keyword-path-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class KeywordPathAnalyzer extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
return {
mapping: {
[this.field]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class KeywordTokensCaseInsensitive extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
return {
mapping: {
[this.field]: {
Expand Down
4 changes: 1 addition & 3 deletions packages/data-types/src/types/v1/keyword-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class KeywordTokens extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
return {
mapping: {
[this.field]: {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Keyword extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/long.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Long extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
4 changes: 1 addition & 3 deletions packages/data-types/src/types/v1/ngram-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class NgramTokens extends BaseType {
toESMapping(): TypeESMapping {
if (this.config.indexed === false) {
throw new Error(`${this.constructor.name} is required to be indexed`);
}
this._validateESMapping();
return {
mapping: {
[this.field]: {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class NumberClass extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
3 changes: 2 additions & 1 deletion packages/data-types/src/types/v1/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class ObjectType extends BaseType {
toESMapping(): TypeESMapping {
const type = this.config.array ? 'nested' : 'object';
this._validateESMapping();

const type = this.config.array ? 'nested' : 'object';
const typeConfig: ESTypeMapping = { type };

if (this.config.indexed === false) {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/short.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Short extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class StringClass extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
1 change: 1 addition & 0 deletions packages/data-types/src/types/v1/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GraphQLType, TypeESMapping } from '../../interfaces';

export default class Text extends BaseType {
toESMapping(): TypeESMapping {
this._validateESMapping();
return {
mapping: {
[this.field]: this.config.indexed === false ? {
Expand Down
Loading

0 comments on commit 37cacb5

Please sign in to comment.