-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Upgraded to version 9 - Fixed linting issues - Fixed formatting issues
- Loading branch information
1 parent
5f5151d
commit 34f6515
Showing
26 changed files
with
711 additions
and
662 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,4 @@ npm-debug.log | |
/.nyc_output | ||
|
||
# dist | ||
dist | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
"trailingComma": "all", | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,8 @@ npm i --save @needle-innovision/nestjs-tenancy | |
|
||
| Nest versions | Command | | ||
|---------------|---------------------------------------------------------| | ||
| v8.x | `npm i --save @needle-innovision/nestjs-tenancy` | | ||
| v7.x | `npm i --save @needle-innovision/nestjs-tenancy | | ||
| v8.x | `npm i --save @needle-innovision/nestjs-tenancy@2.0.0 | | ||
| v6.x or v7.x | `npm i --save @needle-innovision/[email protected]` | | ||
|
||
## Basic usage | ||
|
@@ -329,10 +330,10 @@ we can make use of the property in `TenancyModuleOptions` which is `forceCreateC | |
|
||
## Requirements | ||
|
||
1. @nest/mongoose ^6.x.x || ^8.x.x | ||
2. @nestjs/common ^6.x.x || ^8.x.x | ||
3. @nestjs/core ^6.x.x || ^8.x.x | ||
4. mongoose ^5.7.12 (with typings `@types/mongoose`) || ^6.3.8 | ||
1. @nest/mongoose ^6.x.x || ^8.x.x || ^9.x.x | ||
2. @nestjs/common ^6.x.x || ^8.x.x || ^9.x.x | ||
3. @nestjs/core ^6.x.x || ^8.x.x || ^9.x.x | ||
4. mongoose ^5.7.12 (with typings `@types/mongoose`) || ^6.3.8 || ^6.7.0 | ||
|
||
## Test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './dist'; | ||
export * from './dist'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
"use strict"; | ||
|
||
function __export(m) { | ||
for (var p in m) | ||
if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
exports.__esModule = true; | ||
__export(require("./dist")); | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./dist"), exports); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './tenancy.decorator'; | ||
export * from './tenancy.decorator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './tenancy.factory'; | ||
export * from './tenancy.factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,54 @@ | ||
import { Provider } from '@nestjs/common'; | ||
import { Connection } from 'mongoose'; | ||
import { ModelDefinition } from '../interfaces'; | ||
import { CONNECTION_MAP, MODEL_DEFINITION_MAP, TENANT_CONNECTION } from '../tenancy.constants'; | ||
import { | ||
CONNECTION_MAP, | ||
MODEL_DEFINITION_MAP, | ||
TENANT_CONNECTION, | ||
} from '../tenancy.constants'; | ||
import { ConnectionMap, ModelDefinitionMap } from '../types'; | ||
import { getTenantModelDefinitionToken, getTenantModelToken } from '../utils'; | ||
|
||
export const createTenancyProviders = (definitions: ModelDefinition[]): Provider[] => { | ||
const providers: Provider[] = []; | ||
export const createTenancyProviders = ( | ||
definitions: ModelDefinition[], | ||
): Provider[] => { | ||
const providers: Provider[] = []; | ||
|
||
for (const definition of definitions) { | ||
// Extract the definition data | ||
const { name, schema, collection } = definition; | ||
for (const definition of definitions) { | ||
// Extract the definition data | ||
const { name, schema, collection } = definition; | ||
|
||
providers.push({ | ||
provide: getTenantModelDefinitionToken(name), | ||
useFactory: ( | ||
modelDefinitionMap: ModelDefinitionMap, | ||
connectionMap: ConnectionMap, | ||
) => { | ||
const exists = modelDefinitionMap.has(name); | ||
if (!exists) { | ||
modelDefinitionMap.set(name, { ...definition }); | ||
providers.push({ | ||
provide: getTenantModelDefinitionToken(name), | ||
useFactory: ( | ||
modelDefinitionMap: ModelDefinitionMap, | ||
connectionMap: ConnectionMap, | ||
) => { | ||
const exists = modelDefinitionMap.has(name); | ||
if (!exists) { | ||
modelDefinitionMap.set(name, { ...definition }); | ||
|
||
connectionMap.forEach((connection: Connection) => { | ||
connection.model(name, schema, collection); | ||
}); | ||
} | ||
}, | ||
inject: [ | ||
MODEL_DEFINITION_MAP, | ||
CONNECTION_MAP, | ||
], | ||
}); | ||
connectionMap.forEach((connection: Connection) => { | ||
connection.model(name, schema, collection); | ||
}); | ||
} | ||
}, | ||
inject: [MODEL_DEFINITION_MAP, CONNECTION_MAP], | ||
}); | ||
|
||
// Creating Models with connections attached | ||
providers.push({ | ||
provide: getTenantModelToken(name), | ||
useFactory(tenantConnection: Connection) { | ||
return tenantConnection.models[name] || tenantConnection.model(name, schema, collection); | ||
}, | ||
inject: [TENANT_CONNECTION], | ||
}); | ||
} | ||
// Creating Models with connections attached | ||
providers.push({ | ||
provide: getTenantModelToken(name), | ||
useFactory(tenantConnection: Connection) { | ||
return ( | ||
tenantConnection.models[name] || | ||
tenantConnection.model(name, schema, collection) | ||
); | ||
}, | ||
inject: [TENANT_CONNECTION], | ||
}); | ||
} | ||
|
||
// Return the list of providers mapping | ||
return providers; | ||
// Return the list of providers mapping | ||
return providers; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './model-definition.interface'; | ||
export * from './tenancy-options.interface'; | ||
export * from './tenancy-options.interface'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Schema } from 'mongoose'; | ||
|
||
export interface ModelDefinition { | ||
name: string; | ||
schema: Schema; | ||
collection?: string; | ||
name: string; | ||
schema: Schema; | ||
collection?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.