Skip to content
Draft
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
23 changes: 18 additions & 5 deletions libraries/grpc-sdk/src/interfaces/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export enum PostgresIndexType {
BRIN = 'BRIN',
}

/**
* Portable ascending/descending indexes that exist on MongoDB and every SQL dialect.
* Map to Mongo 1/-1 and SQL BTREE ASC/DESC. Optional uniqueness lives on index options.
*/
export enum CompatibleIndexType {
Ascending = 'Ascending',
Descending = 'Descending',
}

export type IndexType = MongoIndexType | PostgresIndexType | CompatibleIndexType;

export type ModelOptionsIndexTypes = IndexType | readonly IndexType[];

export type Array = any[];

export interface ConduitStringValidation {
Expand Down Expand Up @@ -71,9 +84,7 @@ export interface ConduitArrayValidation {
}

export type ConduitValidationRules =
| ConduitStringValidation
| ConduitNumberValidation
| ConduitArrayValidation;
ConduitStringValidation | ConduitNumberValidation | ConduitArrayValidation;

type BaseConduitModelField = {
type?: TYPE | TYPE[] | ConduitModel | ArrayConduitModel[];
Expand Down Expand Up @@ -198,16 +209,18 @@ export interface ConduitSchemaOptions {
}

export interface SchemaFieldIndex {
type?: MongoIndexType | PostgresIndexType;
type?: IndexType;
options?: MongoIndexOptions | PostgresIndexOptions;

[field: string]: any;
}

export interface ModelOptionsIndexes {
fields: string[] | readonly string[];
types?: MongoIndexType[] | PostgresIndexType;
types?: ModelOptionsIndexTypes;
options?: MongoIndexOptions | PostgresIndexOptions;
/** Optional. Generated deterministically when omitted. */
name?: string;

[field: string]: any;
}
Expand Down
7 changes: 4 additions & 3 deletions modules/authorization/src/models/ActorIndex.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
CompatibleIndexType,
ConduitModel,
ConduitSchemaOptions,
DatabaseProvider,
MongoIndexType,
TYPE,
} from '@conduitplatform/grpc-sdk';
import { ConduitActiveSchema } from '@conduitplatform/module-tools';
Expand All @@ -23,7 +23,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
subjectId: {
Expand All @@ -41,7 +41,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
entityId: {
Expand Down Expand Up @@ -69,6 +69,7 @@ const schemaOptions: ConduitSchemaOptions = {
indexes: [
{
fields: ['subject', 'entity'],
types: [CompatibleIndexType.Ascending, CompatibleIndexType.Ascending],
},
],
conduit: {
Expand Down
23 changes: 19 additions & 4 deletions modules/authorization/src/models/ObjectIndex.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
CompatibleIndexType,
ConduitModel,
ConduitSchemaOptions,
DatabaseProvider,
MongoIndexType,
TYPE,
} from '@conduitplatform/grpc-sdk';
import { ConduitActiveSchema } from '@conduitplatform/module-tools';
Expand All @@ -23,7 +23,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
subjectId: {
Expand All @@ -47,7 +47,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
entityId: {
Expand Down Expand Up @@ -75,7 +75,7 @@ const schema: ConduitModel = {
type: [TYPE.String],
default: [],
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
createdAt: TYPE.Date,
Expand All @@ -86,12 +86,27 @@ const schemaOptions: ConduitSchemaOptions = {
indexes: [
{
fields: ['subjectType', 'subjectPermission', 'entity'],
types: [
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
],
},
{
fields: ['entity', 'subjectType', 'subjectPermission'],
types: [
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
],
},
{
fields: ['entityType', 'entityId', 'entityPermission'],
types: [
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
],
},
],
conduit: {
Expand Down
8 changes: 4 additions & 4 deletions modules/authorization/src/models/Permission.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CompatibleIndexType,
ConduitModel,
DatabaseProvider,
MongoIndexType,
TYPE,
} from '@conduitplatform/grpc-sdk';
import { ConduitActiveSchema } from '@conduitplatform/module-tools';
Expand All @@ -18,7 +18,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
resourceId: {
Expand All @@ -37,7 +37,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
subjectId: {
Expand All @@ -61,7 +61,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
options: {
unique: true,
},
Expand Down
8 changes: 4 additions & 4 deletions modules/authorization/src/models/Relationship.schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CompatibleIndexType,
ConduitModel,
DatabaseProvider,
MongoIndexType,
TYPE,
} from '@conduitplatform/grpc-sdk';
import { ConduitActiveSchema } from '@conduitplatform/module-tools';
Expand All @@ -17,7 +17,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
resourceId: {
Expand All @@ -36,7 +36,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
},
},
// user:1adasdas
Expand All @@ -61,7 +61,7 @@ const schema: ConduitModel = {
type: TYPE.String,
required: true,
index: {
type: MongoIndexType.Ascending,
type: CompatibleIndexType.Ascending,
options: {
unique: true,
},
Expand Down
9 changes: 8 additions & 1 deletion modules/chat/src/models/ChatRoom.schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CompatibleIndexType,
ConduitModel,
ConduitSchemaOptions,
DatabaseProvider,
Expand Down Expand Up @@ -40,7 +41,13 @@ const schema: ConduitModel = {
};
const modelOptions: ConduitSchemaOptions = {
timestamps: true,
indexes: [{ fields: ['participants'] }, { fields: ['participants', 'deleted'] }],
indexes: [
{ fields: ['participants'], types: [CompatibleIndexType.Ascending] },
{
fields: ['participants', 'deleted'],
types: [CompatibleIndexType.Ascending, CompatibleIndexType.Ascending],
},
],
conduit: {
permissions: {
extendable: true,
Expand Down
17 changes: 14 additions & 3 deletions modules/chat/src/models/Message.schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {
CompatibleIndexType,
ConduitModel,
ConduitSchemaOptions,
DatabaseProvider,
TYPE,
ConduitSchemaOptions,
} from '@conduitplatform/grpc-sdk';
import { ConduitActiveSchema } from '@conduitplatform/module-tools';
import { ChatRoom } from './ChatRoom.schema.js';
Expand Down Expand Up @@ -53,8 +54,18 @@ const schema: ConduitModel = {
const modelOptions: ConduitSchemaOptions = {
timestamps: true,
indexes: [
{ fields: ['room', 'createdAt'] },
{ fields: ['room', 'deleted', 'createdAt'] },
{
fields: ['room', 'createdAt'],
types: [CompatibleIndexType.Ascending, CompatibleIndexType.Ascending],
},
{
fields: ['room', 'deleted', 'createdAt'],
types: [
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
CompatibleIndexType.Ascending,
],
},
],
conduit: {
permissions: {
Expand Down
Loading
Loading