Skip to content

Commit

Permalink
fix(grpc-sdk,commons,database,cms): modelOptions conflict between Con…
Browse files Browse the repository at this point in the history
…duitSchema and SchemaDefinitions (ConduitSchema.modelOptions -> ConduitSchema.schemaOptions)
  • Loading branch information
kon14 committed Dec 2, 2021
1 parent 6413184 commit e7a9381
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions libraries/grpc-sdk/src/classes/ConduitActiveSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export class ConduitActiveSchema<T> extends ConduitSchema {
dbInstance: DatabaseProvider,
name: string,
fields?: ConduitModel,
modelOptions?: ConduitModelOptions,
schemaOptions?: ConduitModelOptions,
collectionName?: string
) {
super(name, fields ?? {}, modelOptions, collectionName);
super(name, fields ?? {}, schemaOptions, collectionName);
this.dbInstance = dbInstance;
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/grpc-sdk/src/classes/ConduitSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ export class ConduitSchema {
readonly name: string;
readonly fields: ConduitModel;
readonly collectionName: string;
modelOptions: ConduitModelOptions;
readonly schemaOptions: ConduitModelOptions;
private ownerModule?: string;

constructor(
name: string,
fields: ConduitModel,
modelOptions?: ConduitModelOptions,
schemaOptions?: ConduitModelOptions,
collectionName?: string
) {
this.name = name;
this.fields = fields;
this.modelOptions = modelOptions ? modelOptions : {};
this.schemaOptions = schemaOptions ?? {};
if (collectionName && collectionName !== '') {
this.collectionName = collectionName;
} else {
Expand Down
2 changes: 1 addition & 1 deletion libraries/grpc-sdk/src/modules/databaseProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class DatabaseProvider extends ConduitModule<DatabaseProviderClient> {
schema: {
name: schema.name,
modelSchema: JSON.stringify(schema.fields ?? schema.modelSchema),
modelOptions: JSON.stringify(schema.modelOptions),
modelOptions: JSON.stringify(schema.schemaOptions),
collectionName: schema.collectionName,
},
},
Expand Down
6 changes: 3 additions & 3 deletions modules/cms/src/admin/schema.admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class SchemaAdmin {

if (newSchema.enabled) {
this.schemaController.createSchema(
new ConduitSchema(newSchema.name, newSchema.fields, newSchema.modelOptions),
new ConduitSchema(newSchema.name, newSchema.fields, newSchema.schemaOptions),
);
}

Expand Down Expand Up @@ -170,7 +170,7 @@ export class SchemaAdmin {
new ConduitSchema(
updatedSchema.name,
updatedSchema.fields,
updatedSchema.modelOptions,
updatedSchema.schemaOptions,
),
);
}
Expand Down Expand Up @@ -256,7 +256,7 @@ export class SchemaAdmin {
new ConduitSchema(
requestedSchema.name,
requestedSchema.fields,
requestedSchema.modelOptions,
requestedSchema.schemaOptions,
),
);

Expand Down
7 changes: 5 additions & 2 deletions modules/cms/src/models/SchemaDefinitions.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const schema = {
required: true,
systemRequired: true,
},
//todo The properties in JSON, replace adequetly
modelOptions: { type: TYPE.String, systemRequired: true },
modelOptions: { // TODO: The properties in JSON, replace adequetly
type: TYPE.String,
systemRequired: true
},
enabled: {
type: TYPE.Boolean,
default: true,
Expand Down Expand Up @@ -46,6 +48,7 @@ export class SchemaDefinitions extends ConduitActiveSchema<SchemaDefinitions> {
_id!: string;
name!: string;
fields!: any;
modelOptions!: string;
enabled!: boolean;
authentication!: boolean;
crudOperations!: boolean;
Expand Down
6 changes: 3 additions & 3 deletions modules/database/src/DatabaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class DatabaseProvider extends ConduitServiceModule {
let originalSchema = {
name: schemaAdapter.originalSchema.name,
modelSchema: JSON.stringify(schemaAdapter.originalSchema.modelSchema),
modelOptions: JSON.stringify(schemaAdapter.originalSchema.modelOptions),
modelOptions: JSON.stringify(schemaAdapter.originalSchema.schemaOptions),
collectionName: schemaAdapter.originalSchema.collectionName,
};
this.publishSchema({
Expand Down Expand Up @@ -182,7 +182,7 @@ export class DatabaseProvider extends ConduitServiceModule {
schema: {
name: schemaAdapter.name,
modelSchema: JSON.stringify(schemaAdapter.modelSchema),
modelOptions: JSON.stringify(schemaAdapter.modelOptions),
modelOptions: JSON.stringify(schemaAdapter.schemaOptions),
collectionName: schemaAdapter.collectionName,
},
});
Expand All @@ -202,7 +202,7 @@ export class DatabaseProvider extends ConduitServiceModule {
return {
name: schema.name,
modelSchema: JSON.stringify(schema.modelSchema),
modelOptions: JSON.stringify(schema.modelOptions),
modelOptions: JSON.stringify(schema.schemaOptions),
collectionName: schema.collectionName,
};
}),
Expand Down
4 changes: 2 additions & 2 deletions modules/database/src/adapters/DatabaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export abstract class DatabaseAdapter<T extends SchemaAdapter<any>> {
{
name: schema.name,
fields: schema.fields,
modelOptions: JSON.stringify(schema.modelOptions),
modelOptions: JSON.stringify(schema.schemaOptions),
ownerModule: schema.owner,
}
);
Expand All @@ -58,7 +58,7 @@ export abstract class DatabaseAdapter<T extends SchemaAdapter<any>> {
.create({
name: schema.name,
fields: schema.fields,
modelOptions: JSON.stringify(schema.modelOptions),
modelOptions: JSON.stringify(schema.schemaOptions),
ownerModule: schema.owner,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MongooseSchema implements SchemaAdapter<Model<any>> {
private readonly adapter: MongooseAdapter
) {
this.originalSchema = originalSchema;
let mongooseSchema = new Schema(schema.modelSchema as any, schema.modelOptions);
let mongooseSchema = new Schema(schema.modelSchema as any, schema.schemaOptions);
mongooseSchema.plugin(deepPopulate, {});
this.model = mongoose.model(schema.name, mongooseSchema);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/database/src/adapters/mongoose-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class MongooseAdapter extends DatabaseAdapter<MongooseSchema> {
async deleteSchema(schemaName: string, deleteData: boolean): Promise<string> {
if (!this.models?.[schemaName])
throw ConduitError.notFound('Requested schema not found');
if (this.models![schemaName].originalSchema.modelOptions.systemRequired) {
if (this.models![schemaName].originalSchema.schemaOptions.systemRequired) {
throw ConduitError.forbidden("Can't delete system required schema");
}
if(deleteData){
Expand Down
10 changes: 5 additions & 5 deletions packages/commons/src/models/ConduitSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ export class ConduitSchema {
private readonly _name: string;
private readonly _fields: ConduitModel;
private readonly _collectionName: string;
private readonly _modelOptions: ConduitModelOptions;
private readonly _schemaOptions: ConduitModelOptions;
private _ownerModule?: string;

constructor(
name: string,
fields: ConduitModel,
modelOptions?: ConduitModelOptions,
schemaOptions?: ConduitModelOptions,
collectionName?: string
) {
this._name = name;
this._fields = fields;
this._modelOptions = modelOptions ? modelOptions : {};
this._schemaOptions = schemaOptions ?? {};
// todo should pluralize like mongoose
if (collectionName && collectionName !== '') {
this._collectionName = collectionName;
Expand Down Expand Up @@ -48,7 +48,7 @@ export class ConduitSchema {
return this._collectionName;
}

get modelOptions(): ConduitModelOptions {
return this._modelOptions;
get schemaOptions(): ConduitModelOptions {
return this._schemaOptions;
}
}

0 comments on commit e7a9381

Please sign in to comment.