Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: naming for classes and add 3d support #59

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/models/common/decorators/property/classGraphql.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,29 @@ const graphQLMetadataKey = Symbol('graphqlclassmapping');
type KeyValueDict = Record<string, unknown>;
const target = {};

export interface IGraphQLClass {
alias?: string;
}

export interface IGraphQLClassMapping {
name: string;
fields: IPropGraphQLMapping[];
}

export function graphqlClass(): ClassDecorator {
export function graphqlClass(args?: IGraphQLClass): ClassDecorator {
// eslint-disable-next-line @typescript-eslint/ban-types
return <TFunction extends Function>(graphqlmapping: TFunction) => {
return <TFunction extends Function>(classCtr: TFunction): TFunction => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
const classInstance = new (graphqlmapping as any)();
const classInstance = new (classCtr as any)();
const classData: IGraphQLClassMapping = {
fields: getGraphQLMappings(classInstance),
name: graphqlmapping.name,
name: args?.alias ?? classCtr.name,
};

const classDataList = getGraphQLClassMapping() ?? [];
classDataList.push(classData);
Reflect.defineMetadata(graphQLMetadataKey, classDataList, target);
return graphqlmapping;
return classCtr;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './common/index';
export * from './layerMetadata/index';
export * from './discreteIngestion/index';
export * from './layerMetadata/pycswLayerCatalogRecord';
export * from './layerMetadata/pycsw3DCatalogRecord';
283 changes: 283 additions & 0 deletions src/models/layerMetadata/pycsw3DCatalogRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
import { IPycswCoreModel } from '../pycsw/interfaces/pycswCoreModel';
import { IPropCatalogDBMapping } from '../common/interfaces/propCatalogDBMapping.interface';
import { IOrmCatalog } from '../common/interfaces/ormCatalog.interface';
import { graphql } from '../common/decorators/property/graphql.decorator';
import { graphqlClass } from '../common/decorators/property/classGraphql.decorator';
import { Link } from './link';
import { catalogDB, getCatalogDBMapping } from './decorators/property/catalogDB.decorator';
import { getTsTypesMapping, TsTypes, tsTypes } from './decorators/property/tsTypes.decorator';
import { LayerMetadata } from './layerMetadata';
import { getCatalogDBEntityMapping, catalogDBEntity, ICatalogDBEntityMapping } from './decorators/class/catalogDBEntity.decorator';

@catalogDBEntity({
table: 'records',
})
@graphqlClass({ alias: 'Layer3DRecord' })
// TODO: Replace LayerMetadata with Layter3DMetadata when implemented
export class Pycsw3DCatalogRecord extends LayerMetadata implements IPycswCoreModel, IOrmCatalog {
@catalogDB({
column: {
name: 'typename',
type: 'text',
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public typeName?: string = undefined;

@catalogDB({
column: {
name: 'schema',
type: 'text',
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public schema?: string = undefined;

@catalogDB({
column: {
name: 'mdsource',
type: 'text',
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public mdSource?: string = undefined;

@catalogDB({
column: {
name: 'xml',
type: 'text',
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public xml?: string = undefined;

@catalogDB({
column: {
name: 'anytext',
type: 'text',
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public anyText?: string = undefined;

@catalogDB({
column: {
name: 'insert_date',
type: 'timestamp without time zone',
},
})
@tsTypes({
mappingType: TsTypes.DATE,
})
@graphql({
nullable: true,
})
public insertDate?: Date = undefined;

@catalogDB({
column: {
name: 'wkt_geometry',
type: 'text',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public wktGeometry?: string = undefined;

@catalogDB({
column: {
name: 'links',
type: 'text',
nullable: true,
},
field: {
overrideType: TsTypes.STRING,
},
})
@tsTypes({
mappingType: TsTypes.LINKS,
})
@graphql({
nullable: true,
})
public links?: Link[] = undefined;

@catalogDB({
column: {
name: 'anytext_tsvector',
type: 'tsvector',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public anyTextTsvector?: string = undefined;

@catalogDB({
column: {
name: 'wkb_geometry',
type: 'geometry',
spatialFeatureType: 'Geometry',
srid: 4326,
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public wkbGeometry?: string = undefined;

@catalogDB({
column: {
name: 'title',
type: 'text',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public title?: string = undefined;

@catalogDB({
column: {
name: 'type',
type: 'text',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public type?: string = undefined;

@catalogDB({
column: {
name: 'srs',
type: 'text',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public srs?: string = undefined;

@catalogDB({
column: {
name: 'producer_name',
type: 'text',
defaultValue: 'IDFMU',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public producerName?: string = undefined;

@catalogDB({
column: {
name: 'project_name',
type: 'text',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public projectName?: string = undefined;

// TODO: remove field shoud be removed
@catalogDB({
column: {
name: 'project_name',
type: 'text',
nullable: true,
},
})
@tsTypes({
mappingType: TsTypes.STRING,
})
@graphql({
nullable: true,
})
public accuracyLE90?: string = undefined;

public constructor() {
super();
}

public getORMCatalogMappings(): IPropCatalogDBMapping[] {
const ret = [];

for (const prop in this) {
const catalogDbMap = getCatalogDBMapping(this, prop);
const tsTypesMap = getTsTypesMapping(this, prop);
if (catalogDbMap && tsTypesMap) {
ret.push({
prop: prop,
...catalogDbMap,
...tsTypesMap,
});
}
}
return ret;
}

public getORMCatalogEntityMappings(): ICatalogDBEntityMapping {
return getCatalogDBEntityMapping(Pycsw3DCatalogRecord);
}
}
2 changes: 1 addition & 1 deletion src/models/layerMetadata/pycswLayerCatalogRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getCatalogDBEntityMapping, catalogDBEntity, ICatalogDBEntityMapping } f
@catalogDBEntity({
table: 'records',
})
@graphqlClass()
@graphqlClass({ alias: 'LayerRasterRecord' })
export class PycswLayerCatalogRecord extends LayerMetadata implements IPycswCoreModel, IOrmCatalog {
@catalogDB({
column: {
Expand Down