diff --git a/src/models/types.ts b/src/models/types.ts index 4f8fb3cd..14b36deb 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -1,4 +1,4 @@ -import { Struct } from "../npmDeps.ts"; +import { ObjectId, Struct } from "../npmDeps.ts"; /** * PureModel is interface of pure feature, @@ -39,6 +39,15 @@ export interface IRelationsFileds { [key: string]: TRelation; } +export type TInsertRelations = { + [mainKey in keyof T]?: { + _ids: ObjectId | ObjectId[]; + relatedRelations?: { + [key in keyof T[mainKey]["relatedRelations"]]: boolean; + }; + }; +}; + /** * if schema has relation with other schema and in SQL that we keep foreign key. * store in InRelation feature diff --git a/src/odm/insert/insertMany.ts b/src/odm/insert/insertMany.ts index acfb6e8d..67cb96ec 100644 --- a/src/odm/insert/insertMany.ts +++ b/src/odm/insert/insertMany.ts @@ -8,22 +8,13 @@ import { } from "../../npmDeps.ts"; import { IRelationsFileds } from "../../mod.ts"; import { createProjection } from "../../models/createProjection.ts"; -import { schemaFns, TSchemas } from "../../models/mod.ts"; +import { schemaFns, TInsertRelations, TSchemas } from "../../models/mod.ts"; import { throwError } from "../../utils/mod.ts"; import { Projection } from "../aggregation/type.ts"; import { findOne } from "../find/findOne.ts"; import { find } from "../find/find.ts"; import { filterDocsByProjection } from "../utils/filterDocsByProjection.ts"; -export type TInsertRelations = { - [mainKey in keyof T]?: { - _ids: ObjectId | ObjectId[]; - relatedRelations?: { - [key in keyof T[mainKey]["relatedRelations"]]: boolean; - }; - }; -}; - export const insertMany = async < TR extends IRelationsFileds, PureFields extends Document, diff --git a/src/odm/insert/insertOne.ts b/src/odm/insert/insertOne.ts index 9667ae21..37cd22e8 100644 --- a/src/odm/insert/insertOne.ts +++ b/src/odm/insert/insertOne.ts @@ -7,20 +7,11 @@ import { } from "../../npmDeps.ts"; import { IRelationsFileds } from "../../mod.ts"; import { createProjection } from "../../models/createProjection.ts"; -import { schemaFns, TSchemas } from "../../models/mod.ts"; +import { schemaFns, TInsertRelations, TSchemas } from "../../models/mod.ts"; import { throwError } from "../../utils/mod.ts"; import { Projection } from "../aggregation/type.ts"; import { handleInsertOne } from "../utils/insert/mod.ts"; -export type TInsertRelations = { - [mainKey in keyof T]?: { - _ids: ObjectId | ObjectId[]; - relatedRelations?: { - [key in keyof T[mainKey]["relatedRelations"]]: boolean; - }; - }; -}; - export const insertOne = async < TR extends IRelationsFileds, PureFields extends Document, diff --git a/src/odm/newModel/mod.ts b/src/odm/newModel/mod.ts index 81f93863..6dab9f85 100644 --- a/src/odm/newModel/mod.ts +++ b/src/odm/newModel/mod.ts @@ -8,7 +8,12 @@ import { optional, UpdateFilter, } from "../../mod.ts"; -import { IPureFields, schemaFns, TSchemas } from "../../models/mod.ts"; +import { + IPureFields, + schemaFns, + TInsertRelations, + TSchemas, +} from "../../models/mod.ts"; import { BulkWriteOptions, CountDocumentsOptions, @@ -27,7 +32,7 @@ import { deleteOne } from "../delete/deleteOne.ts"; import { aggregation } from "../find/aggregation.ts"; import { find } from "../find/find.ts"; import { findOne } from "../find/findOne.ts"; -import { insertOne, TInsertRelations } from "../insert/insertOne.ts"; +import { insertOne } from "../insert/insertOne.ts"; import { addRelation } from "../relation/addRelation.ts"; import { insertMany } from "../insert/insertMany.ts"; import { removeRelation } from "../relation/removeRelation.ts"; diff --git a/src/odm/relation/addRelation.ts b/src/odm/relation/addRelation.ts index bda0a26f..9f2177ec 100644 --- a/src/odm/relation/addRelation.ts +++ b/src/odm/relation/addRelation.ts @@ -1,9 +1,13 @@ import { Db, Document, Filter } from "../../npmDeps.ts"; import { createProjection } from "../../models/createProjection.ts"; -import { IRelationsFileds, schemaFns, TSchemas } from "../../models/mod.ts"; +import { + IRelationsFileds, + schemaFns, + TInsertRelations, + TSchemas, +} from "../../models/mod.ts"; import { throwError } from "../../utils/throwError.ts"; import { Projection } from "../aggregation/type.ts"; -import { TInsertRelations } from "../insert/insertOne.ts"; import { handleMultiRelation } from "../utils/insert/handleMultiRelation.ts"; import { handleSingleRelation } from "../utils/insert/handleSingleRelation.ts"; import { processRemoveRelatedRelations } from "../utils/processRemoveRelatedRelations.ts"; diff --git a/src/odm/relation/removeRelation.ts b/src/odm/relation/removeRelation.ts index 2053c4d9..09df754c 100644 --- a/src/odm/relation/removeRelation.ts +++ b/src/odm/relation/removeRelation.ts @@ -1,7 +1,11 @@ import { Db, Document, Filter, ObjectId } from "../../npmDeps.ts"; -import { IRelationsFileds, schemaFns, TSchemas } from "../../models/mod.ts"; +import { + IRelationsFileds, + schemaFns, + TInsertRelations, + TSchemas, +} from "../../models/mod.ts"; import { Projection } from "../aggregation/type.ts"; -import { TInsertRelations } from "../insert/insertOne.ts"; import { throwError } from "../../utils/throwError.ts"; import { createProjection } from "../../models/createProjection.ts"; import { filterDocByProjection } from "../utils/filterDocByProjection.ts"; diff --git a/src/odm/utils/insert/handleInsertOne.ts b/src/odm/utils/insert/handleInsertOne.ts index a5c23906..7cff9517 100644 --- a/src/odm/utils/insert/handleInsertOne.ts +++ b/src/odm/utils/insert/handleInsertOne.ts @@ -1,5 +1,9 @@ -import { Db, IModel, IRelationsFileds } from "../../../mod.ts"; -import { TInsertRelations } from "../../insert/insertOne.ts"; +import { + Db, + IModel, + IRelationsFileds, + TInsertRelations, +} from "../../../mod.ts"; import { handleMultiRelation } from "./handleMultiRelation.ts"; import { handleSingleRelation } from "./handleSingleRelation.ts"; diff --git a/src/odm/utils/insert/handleMultiRelation.ts b/src/odm/utils/insert/handleMultiRelation.ts index accc87eb..20f11204 100644 --- a/src/odm/utils/insert/handleMultiRelation.ts +++ b/src/odm/utils/insert/handleMultiRelation.ts @@ -1,8 +1,7 @@ -import { IModel, IRelationsFileds } from "../../../mod.ts"; +import { IModel, IRelationsFileds, TInsertRelations } from "../../../mod.ts"; import { Db, ObjectId } from "../../../npmDeps.ts"; import { throwError } from "../../../utils/mod.ts"; import { find } from "../../find/find.ts"; -import { TInsertRelations } from "../../insert/insertOne.ts"; import { filterDocByProjection } from "../filterDocByProjection.ts"; import { filterDocsByProjection } from "../filterDocsByProjection.ts"; import { generateUpdateFilter } from "../generateUpdateFilter.ts"; diff --git a/src/odm/utils/insert/handleSingleRelation.ts b/src/odm/utils/insert/handleSingleRelation.ts index 5ee5b61a..3359ed6a 100644 --- a/src/odm/utils/insert/handleSingleRelation.ts +++ b/src/odm/utils/insert/handleSingleRelation.ts @@ -1,8 +1,7 @@ -import { IModel, IRelationsFileds } from "../../../mod.ts"; +import { IModel, IRelationsFileds, TInsertRelations } from "../../../mod.ts"; import { Db, ObjectId } from "../../../npmDeps.ts"; import { throwError } from "../../../utils/mod.ts"; import { findOne } from "../../find/findOne.ts"; -import { TInsertRelations } from "../../insert/insertOne.ts"; import { filterDocByProjection } from "../filterDocByProjection.ts"; import { proccessRelatedRelation } from "./proccessRelatedRelation.ts"; diff --git a/src/odm/utils/processRemoveRelatedRelations.ts b/src/odm/utils/processRemoveRelatedRelations.ts index 0b388963..3279ab6d 100644 --- a/src/odm/utils/processRemoveRelatedRelations.ts +++ b/src/odm/utils/processRemoveRelatedRelations.ts @@ -1,6 +1,11 @@ import { Db, Document, UpdateFilter } from "../../npmDeps.ts"; -import { IModel, IRelationsFileds, ObjectId, WithId } from "../../mod.ts"; -import { TInsertRelations } from "../insert/insertOne.ts"; +import { + IModel, + IRelationsFileds, + ObjectId, + TInsertRelations, + WithId, +} from "../../mod.ts"; import { generateRemoveRelatedRelationFilter } from "./generateRemoveRelationRelationFilter.ts"; export const processRemoveRelatedRelations = async <