Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
114 changes: 79 additions & 35 deletions libraries/grpc-sdk/src/interfaces/Model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Document } from 'bson';
export enum TYPE {
String = 'String',
Number = 'Number',
Expand All @@ -22,25 +23,6 @@ export enum SQLDataType {
TIMESTAMP = 'TIMESTAMP',
}

export enum MongoIndexType {
Ascending = 1,
Descending = -1,
GeoSpatial2d = '2d',
GeoSpatial2dSphere = '2dsphere',
GeoHaystack = 'geoHaystack',
Hashed = 'hashed',
Text = 'text',
}

export enum PostgresIndexType {
BTREE = 'BTREE',
HASH = 'HASH',
GIST = 'GIST',
SPGIST = 'SPGIST',
GIN = 'GIN',
BRIN = 'BRIN',
}

export type Array = any[];

type BaseConduitModelField = {
Expand Down Expand Up @@ -158,28 +140,72 @@ export interface ConduitSchemaOptions {
enabled: boolean;
};
};
indexes?: ModelOptionsIndexes[];
indexes?: ModelOptionsIndex[];
}

// Index types
export interface SchemaFieldIndex {
type?: MongoIndexType | PostgresIndexType;
options?: MongoIndexOptions | PostgresIndexOptions;
name: string;
type?: MongoIndexType | SequelizeIndexType;
options?: MongoIndexOptions | SequelizeIndexOptions;
}

export interface ModelOptionsIndex {
name: string;
fields: string[];
types?: MongoIndexType[] | SequelizeIndexType[];
options?: MongoIndexOptions | SequelizeIndexOptions;
[field: string]: any;
}

export interface ModelOptionsIndexes {
fields: string[];
types?: MongoIndexType[] | PostgresIndexType;
options?: MongoIndexOptions | PostgresIndexOptions;
export enum MongoIndexType {
Ascending = 1,
Descending = -1,
GeoSpatial2d = '2d',
GeoSpatial2dSphere = '2dsphere',
GeoHaystack = 'geoHaystack',
Hashed = 'hashed',
Text = 'text',
}

[field: string]: any;
export const ReverseMongoIndexTypeMap: {
[key: string]: string;
} = {
'1': 'Ascending',
'-1': 'Descending',
'2d': 'GeoSpatial2d',
'2dsphere': 'GeoSpatial2dSphere',
geoHaystack: 'GeoHaystack',
hashed: 'Hashed',
text: 'Text',
};

export enum PgIndexType {
BTREE = 'BTREE',
HASH = 'HASH',
GIST = 'GIST',
SPGIST = 'SPGIST',
GIN = 'GIN',
BRIN = 'BRIN',
}

export enum MySQLMariaDBIndexType {
BTREE = 'BTREE',
HASH = 'HASH',
UNIQUE = 'UNIQUE',
FULLTEXT = 'FULLTEXT',
SPATIAL = 'SPATIAL',
}

export enum SQLiteIndexType {
BTREE = 'BTREE',
}

export type SequelizeIndexType = PgIndexType | MySQLMariaDBIndexType | SQLiteIndexType;

export interface MongoIndexOptions {
background?: boolean;
unique?: boolean;
name?: string;
partialFilterExpression?: Document;
sparse?: boolean;
expireAfterSeconds?: number;
Expand All @@ -199,15 +225,33 @@ export interface MongoIndexOptions {
hidden?: boolean;
}

export interface PostgresIndexOptions {
concurrently?: boolean;
name?: string;
operator?: string;
parser?: null | string;
prefix?: string;
export interface SequelizeIndexOptions {
parser?: string | null;
unique?: boolean;
using?: PostgresIndexType;
// Used instead of ModelOptionsIndexes fields for more complex index definitions
fields?: {
name: string;
length?: number;
order?: 'ASC' | 'DESC';
collate?: string;
operator?: string;
}[];
where?: {
[opt: string]: any;
};
prefix?: string;
}

export interface PgIndexOptions extends SequelizeIndexOptions {
concurrently?: boolean;
operator?: string;
using?: PgIndexType;
}

export interface MySQLMariaDBIndexOptions extends SequelizeIndexOptions {
type?: MySQLMariaDBIndexType;
}

export interface SQLiteIndexOptions extends SequelizeIndexOptions {
using?: SQLiteIndexType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class PermissionsController {
},
],
sqlQuery:
dbType === 'PostgreSQL'
dbType === 'postgres'
? getPostgresAccessListQuery(
objectTypeCollection,
computedTuple,
Expand Down
2 changes: 2 additions & 0 deletions modules/authorization/src/models/ActorIndex.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'subject_1',
type: MongoIndexType.Ascending,
},
},
Expand All @@ -40,6 +41,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'entity_1',
type: MongoIndexType.Ascending,
},
},
Expand Down
2 changes: 2 additions & 0 deletions modules/authorization/src/models/ObjectIndex.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'subject_1',
type: MongoIndexType.Ascending,
},
},
Expand All @@ -46,6 +47,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'entity_1',
type: MongoIndexType.Ascending,
},
},
Expand Down
2 changes: 2 additions & 0 deletions modules/authorization/src/models/Permission.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'resource_1',
type: MongoIndexType.Ascending,
},
},
Expand All @@ -37,6 +38,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'subject_1',
type: MongoIndexType.Ascending,
},
},
Expand Down
2 changes: 2 additions & 0 deletions modules/authorization/src/models/Relationship.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'resource_1',
type: MongoIndexType.Ascending,
},
},
Expand All @@ -36,6 +37,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
name: 'subject_1',
type: MongoIndexType.Ascending,
},
},
Expand Down
6 changes: 3 additions & 3 deletions modules/database/src/adapters/DatabaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ConduitModel,
ConduitSchema,
GrpcError,
ModelOptionsIndexes,
ModelOptionsIndex,
RawMongoQuery,
RawSQLQuery,
TYPE,
Expand Down Expand Up @@ -171,11 +171,11 @@ export abstract class DatabaseAdapter<T extends Schema> {

abstract createIndexes(
schemaName: string,
indexes: ModelOptionsIndexes[],
indexes: ModelOptionsIndex[],
callerModule: string,
): Promise<string>;

abstract getIndexes(schemaName: string): Promise<ModelOptionsIndexes[]>;
abstract getIndexes(schemaName: string): Promise<ModelOptionsIndex[]>;

abstract createView(
modelName: string,
Expand Down
Loading