@oxeo-drivers/mongo 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/decorators.d.ts +3 -0
- package/dist/common/decorators.js +14 -0
- package/dist/common/decorators.js.map +1 -0
- package/dist/common/index.d.ts +3 -0
- package/dist/common/index.js +20 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/tokens.d.ts +3 -0
- package/dist/common/tokens.js +14 -0
- package/dist/common/tokens.js.map +1 -0
- package/dist/common/utils.d.ts +2 -0
- package/dist/common/utils.js +19 -0
- package/dist/common/utils.js.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/driver.module.d.ts +16 -0
- package/dist/driver.module.js +40 -0
- package/dist/driver.module.js.map +1 -0
- package/dist/drivers/collection.driver.d.ts +33 -0
- package/dist/drivers/collection.driver.js +151 -0
- package/dist/drivers/collection.driver.js.map +1 -0
- package/dist/drivers/table.driver.d.ts +15 -0
- package/dist/drivers/table.driver.js +88 -0
- package/dist/drivers/table.driver.js.map +1 -0
- package/dist/factories/definitions.factory.d.ts +11 -0
- package/dist/factories/definitions.factory.js +127 -0
- package/dist/factories/definitions.factory.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/mongoose-options.interface.d.ts +12 -0
- package/dist/mongoose-options.interface.js +3 -0
- package/dist/mongoose-options.interface.js.map +1 -0
- package/dist/mongoose.module.d.ts +11 -0
- package/dist/mongoose.module.js +108 -0
- package/dist/mongoose.module.js.map +1 -0
- package/dist/storages/data-source.d.ts +10 -0
- package/dist/storages/data-source.js +36 -0
- package/dist/storages/data-source.js.map +1 -0
- package/dist/utils/flatten.d.ts +1 -0
- package/dist/utils/flatten.js +42 -0
- package/dist/utils/flatten.js.map +1 -0
- package/package.json +48 -3
- package/README.md +0 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectConnection = exports.InjectDataSource = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const tokens_1 = require("./tokens");
|
|
6
|
+
const InjectDataSource = (dataSource) => {
|
|
7
|
+
return (0, common_1.Inject)((0, tokens_1.getDataSourceToken)(dataSource));
|
|
8
|
+
};
|
|
9
|
+
exports.InjectDataSource = InjectDataSource;
|
|
10
|
+
const InjectConnection = () => {
|
|
11
|
+
return (0, common_1.Inject)((0, tokens_1.getConnectionToken)());
|
|
12
|
+
};
|
|
13
|
+
exports.InjectConnection = InjectConnection;
|
|
14
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../lib/common/decorators.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,qCAAiE;AAM1D,MAAM,gBAAgB,GAAG,CAAC,UAAwC,EAAE,EAAE;IAC3E,OAAO,IAAA,eAAM,EAAC,IAAA,2BAAkB,EAAC,UAAU,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B;AAKM,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,IAAA,eAAM,EAAC,IAAA,2BAAkB,GAAE,CAAC,CAAA;AACrC,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./decorators"), exports);
|
|
18
|
+
__exportStar(require("./tokens"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,2CAAwB;AACxB,0CAAuB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDataSourceToken = exports.getConnectionToken = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const data_source_1 = require("../storages/data-source");
|
|
6
|
+
const getConnectionToken = (name) => {
|
|
7
|
+
return name && name !== constants_1.DEFAULT_DB_CONNECTION ? `${name}Connection` : constants_1.DEFAULT_DB_CONNECTION;
|
|
8
|
+
};
|
|
9
|
+
exports.getConnectionToken = getConnectionToken;
|
|
10
|
+
const getDataSourceToken = (dataScheme) => {
|
|
11
|
+
return data_source_1.DataSourceStorage.getProviderToken(dataScheme);
|
|
12
|
+
};
|
|
13
|
+
exports.getDataSourceToken = getDataSourceToken;
|
|
14
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../lib/common/tokens.ts"],"names":[],"mappings":";;;AAAA,4CAAoD;AAEpD,yDAA2D;AAKpD,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAAE,EAAE;IAClD,OAAO,IAAI,IAAI,IAAI,KAAK,iCAAqB,CAAC,CAAC,CAAC,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,iCAAqB,CAAA;AAC7F,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAKM,MAAM,kBAAkB,GAAG,CAAC,UAAwC,EAAE,EAAE;IAC7E,OAAO,+BAAiB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAA;AACvD,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleRetry = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const handleRetry = (retryAttempts = 9, retryDelay = 3000, verboseRetryLog = false) => {
|
|
7
|
+
const logger = new common_1.Logger('MongooseModule');
|
|
8
|
+
return (source) => source.pipe((0, operators_1.retryWhen)((e) => e.pipe((0, operators_1.scan)((errorCount, error) => {
|
|
9
|
+
const verboseMessage = verboseRetryLog ? ` Message: ${error.message}.` : '';
|
|
10
|
+
const retryMessage = retryAttempts > 0 ? ` Retrying (${errorCount + 1})...` : '';
|
|
11
|
+
logger.error(['Unable to connect to the database.', verboseMessage, retryMessage].join(''), error.stack);
|
|
12
|
+
if (errorCount + 1 >= retryAttempts) {
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
return errorCount + 1;
|
|
16
|
+
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
17
|
+
};
|
|
18
|
+
exports.handleRetry = handleRetry;
|
|
19
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/common/utils.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AAEvC,8CAAuD;AAEhD,MAAM,WAAW,GAAG,CAAC,aAAa,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,EAAE,eAAe,GAAG,KAAK,EAAE,EAAE;IAC3F,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,gBAAgB,CAAC,CAAA;IAE3C,OAAO,CAAI,MAAqB,EAAE,EAAE,CAClC,MAAM,CAAC,IAAI,CACT,IAAA,qBAAS,EAAC,CAAC,CAAC,EAAE,EAAE,CACd,CAAC,CAAC,IAAI,CACJ,IAAA,gBAAI,EAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE;QACzB,MAAM,cAAc,GAAG,eAAe,CAAC,CAAC,CAAC,aAAa,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QAC3E,MAAM,YAAY,GAAG,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,UAAU,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAA;QAEhF,MAAM,CAAC,KAAK,CACV,CAAC,oCAAoC,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAC7E,KAAK,CAAC,KAAK,CACZ,CAAA;QACD,IAAI,UAAU,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC;YACpC,MAAM,KAAK,CAAA;QACb,CAAC;QACD,OAAO,UAAU,GAAG,CAAC,CAAA;IACvB,CAAC,EAAE,CAAC,CAAC,EACL,IAAA,iBAAK,EAAC,UAAU,CAAC,CAClB,CACF,CACF,CAAA;AACL,CAAC,CAAA;AAxBY,QAAA,WAAW,eAwBvB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const DEFAULT_DB_CONNECTION = "OxeoDatabaseConnection";
|
|
2
|
+
export declare const MONGOOSE_MODULE_OPTIONS = "OxeoMongooseModuleOptions";
|
|
3
|
+
export declare const MONGOOSE_CONNECTION_NAME = "OxeoMongooseConnectionName";
|
|
4
|
+
export declare const DATA_SOURCE_TOKEN = "OXEO_DATA_SOURCE";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DATA_SOURCE_TOKEN = exports.MONGOOSE_CONNECTION_NAME = exports.MONGOOSE_MODULE_OPTIONS = exports.DEFAULT_DB_CONNECTION = void 0;
|
|
4
|
+
exports.DEFAULT_DB_CONNECTION = 'OxeoDatabaseConnection';
|
|
5
|
+
exports.MONGOOSE_MODULE_OPTIONS = 'OxeoMongooseModuleOptions';
|
|
6
|
+
exports.MONGOOSE_CONNECTION_NAME = 'OxeoMongooseConnectionName';
|
|
7
|
+
exports.DATA_SOURCE_TOKEN = `OXEO_DATA_SOURCE`;
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,wBAAwB,CAAA;AAChD,QAAA,uBAAuB,GAAG,2BAA2B,CAAA;AACrD,QAAA,wBAAwB,GAAG,4BAA4B,CAAA;AACvD,QAAA,iBAAiB,GAAG,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { CollectionScheme, DataScheme } from '@oxeo/scheme';
|
|
3
|
+
import { MongooseModuleOptions } from './mongoose-options.interface';
|
|
4
|
+
import { MongoDriverOptions } from './drivers/collection.driver';
|
|
5
|
+
interface RootOptions {
|
|
6
|
+
uri: string;
|
|
7
|
+
mongoOptions?: MongooseModuleOptions;
|
|
8
|
+
schemas: {
|
|
9
|
+
dataScheme: DataScheme<CollectionScheme>;
|
|
10
|
+
driverOptions?: Omit<MongoDriverOptions, 'connection'>;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
export declare class MongooseDriverModule {
|
|
14
|
+
static forRoot(options: RootOptions): DynamicModule;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var MongooseDriverModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MongooseDriverModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const tokens_1 = require("./common/tokens");
|
|
13
|
+
const mongoose_module_1 = require("./mongoose.module");
|
|
14
|
+
const data_source_1 = require("./storages/data-source");
|
|
15
|
+
let MongooseDriverModule = MongooseDriverModule_1 = class MongooseDriverModule {
|
|
16
|
+
static forRoot(options) {
|
|
17
|
+
const { uri, schemas, mongoOptions = {} } = options;
|
|
18
|
+
const providers = schemas.map(({ dataScheme, driverOptions = {} }) => {
|
|
19
|
+
return {
|
|
20
|
+
provide: (0, tokens_1.getDataSourceToken)(dataScheme),
|
|
21
|
+
useFactory: (connection) => {
|
|
22
|
+
return data_source_1.DataSourceStorage.getSource(dataScheme, { connection, ...driverOptions });
|
|
23
|
+
},
|
|
24
|
+
inject: [(0, tokens_1.getConnectionToken)(mongoOptions.connectionName)]
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
global: true,
|
|
29
|
+
module: MongooseDriverModule_1,
|
|
30
|
+
imports: [mongoose_module_1.MongooseCoreModule.forRoot(uri, mongoOptions)],
|
|
31
|
+
providers: providers,
|
|
32
|
+
exports: providers
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.MongooseDriverModule = MongooseDriverModule;
|
|
37
|
+
exports.MongooseDriverModule = MongooseDriverModule = MongooseDriverModule_1 = __decorate([
|
|
38
|
+
(0, common_1.Module)({})
|
|
39
|
+
], MongooseDriverModule);
|
|
40
|
+
//# sourceMappingURL=driver.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"driver.module.js","sourceRoot":"","sources":["../lib/driver.module.ts"],"names":[],"mappings":";;;;;;;;;;AACA,2CAAsD;AACtD,4CAAwE;AAIxE,uDAAsD;AAEtD,wDAA0D;AAgBnD,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAC/B,MAAM,CAAC,OAAO,CAAC,OAAoB;QACjC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,OAAO,CAAA;QAEnD,MAAM,SAAS,GAAe,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,GAAG,EAAE,EAAE,EAAE,EAAE;YAC/E,OAAO;gBACL,OAAO,EAAE,IAAA,2BAAkB,EAAC,UAAU,CAAC;gBACvC,UAAU,EAAE,CAAC,UAAsB,EAAgC,EAAE;oBACnE,OAAO,+BAAiB,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,CAAC,CAAA;gBAClF,CAAC;gBACD,MAAM,EAAE,CAAC,IAAA,2BAAkB,EAAC,YAAY,CAAC,cAAc,CAAC,CAAC;aAC1D,CAAA;QACH,CAAC,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,sBAAoB;YAC5B,OAAO,EAAE,CAAC,oCAAkB,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACxD,SAAS,EAAE,SAAS;YACpB,OAAO,EAAE,SAAS;SACnB,CAAA;IACH,CAAC;CAiBF,CAAA;AAtCY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,oBAAoB,CAsChC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CollectionScheme, DataScheme, ExtractType } from '@oxeo/scheme';
|
|
2
|
+
import { CollectionDriver, CollectionDriverParams } from '@oxeo/server';
|
|
3
|
+
import { MongoRelationsTable } from './table.driver';
|
|
4
|
+
import { Connection } from 'mongoose';
|
|
5
|
+
export interface MongoDriverOptions {
|
|
6
|
+
connection: Connection;
|
|
7
|
+
dev?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class MongoCollectionDriver<Scheme extends CollectionScheme> implements CollectionDriver {
|
|
10
|
+
private dataScheme;
|
|
11
|
+
private dev;
|
|
12
|
+
private onClenupCallbacks;
|
|
13
|
+
private collections;
|
|
14
|
+
private discriminatedModels;
|
|
15
|
+
tables: MongoRelationsTable<Scheme>;
|
|
16
|
+
constructor(dataScheme: DataScheme<Scheme>, { connection, dev }: MongoDriverOptions);
|
|
17
|
+
subscribeCleanup<K extends keyof Scheme>(name: K, callback: (data: ExtractType<Scheme[K]['model']>) => void): void;
|
|
18
|
+
findOneBy({ model, filter }: CollectionDriverParams.Filter): Promise<any>;
|
|
19
|
+
findBy({ model, filter }: CollectionDriverParams.Filter): Promise<any[]>;
|
|
20
|
+
getAll({ model }: CollectionDriverParams.Model): Promise<any[]>;
|
|
21
|
+
get({ model, id }: CollectionDriverParams.Record): Promise<any>;
|
|
22
|
+
exists({ model, id }: CollectionDriverParams.Record): Promise<boolean>;
|
|
23
|
+
count({ model, filter }: CollectionDriverParams.Count): Promise<number>;
|
|
24
|
+
existsBy({ model, filter }: CollectionDriverParams.Filter): Promise<boolean>;
|
|
25
|
+
create({ model, data }: CollectionDriverParams.Create): Promise<void>;
|
|
26
|
+
remove({ model, id }: CollectionDriverParams.Record): Promise<void>;
|
|
27
|
+
update({ model, id, patches }: CollectionDriverParams.Update): Promise<void>;
|
|
28
|
+
replace({ model, id, data }: CollectionDriverParams.Replace): Promise<void>;
|
|
29
|
+
private getCollection;
|
|
30
|
+
private getIdentifierKey;
|
|
31
|
+
private log;
|
|
32
|
+
}
|
|
33
|
+
export declare const createMongoDriver: (options: MongoDriverOptions) => <T extends CollectionScheme>(dataScheme: DataScheme<T>) => MongoCollectionDriver<T>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMongoDriver = exports.MongoCollectionDriver = void 0;
|
|
4
|
+
const table_driver_1 = require("./table.driver");
|
|
5
|
+
const mongoose_1 = require("mongoose");
|
|
6
|
+
const definitions_factory_1 = require("../factories/definitions.factory");
|
|
7
|
+
const common_1 = require("@nestjs/common");
|
|
8
|
+
const flatten_1 = require("../utils/flatten");
|
|
9
|
+
class MongoCollectionDriver {
|
|
10
|
+
constructor(dataScheme, { connection, dev }) {
|
|
11
|
+
this.dataScheme = dataScheme;
|
|
12
|
+
this.dev = false;
|
|
13
|
+
this.onClenupCallbacks = {};
|
|
14
|
+
this.collections = {};
|
|
15
|
+
this.discriminatedModels = {};
|
|
16
|
+
common_1.Logger.log('Driver bootstrap', 'MongoDriver');
|
|
17
|
+
this.dev = dev ?? false;
|
|
18
|
+
this.tables = new table_driver_1.MongoRelationsTable(dataScheme, connection);
|
|
19
|
+
const factory = new definitions_factory_1.DefinitionsFactory(dataScheme);
|
|
20
|
+
const getModel = (model, schema) => {
|
|
21
|
+
return connection.models[model] ?? connection.model(model, schema);
|
|
22
|
+
};
|
|
23
|
+
for (const name in dataScheme.collectionsScheme) {
|
|
24
|
+
const model = dataScheme.collectionsScheme[name].name;
|
|
25
|
+
const scheme = dataScheme.models[model].scheme;
|
|
26
|
+
const baseDefinition = factory.createForScheme(scheme);
|
|
27
|
+
if (scheme.type === 'base') {
|
|
28
|
+
this.collections[model] = getModel(model, new mongoose_1.Schema(baseDefinition));
|
|
29
|
+
}
|
|
30
|
+
if (scheme.type === 'discriminated') {
|
|
31
|
+
this.collections[model] = getModel(model, new mongoose_1.Schema(baseDefinition, {
|
|
32
|
+
discriminatorKey: scheme.discriminatorKey
|
|
33
|
+
}));
|
|
34
|
+
this.discriminatedModels[model] = {
|
|
35
|
+
discriminatorKey: scheme.discriminatorKey,
|
|
36
|
+
models: {}
|
|
37
|
+
};
|
|
38
|
+
for (const discriminator of scheme.discriminators) {
|
|
39
|
+
const discriminatedModel = this.collections[model].discriminator(discriminator.name, new mongoose_1.Schema(factory.createDefinitionScheme(discriminator)), discriminator.value);
|
|
40
|
+
this.discriminatedModels[model].models[discriminator.value] = discriminatedModel;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
subscribeCleanup(name, callback) {
|
|
46
|
+
const model = this.dataScheme.collectionsScheme[name].name;
|
|
47
|
+
if (!this.onClenupCallbacks[model]) {
|
|
48
|
+
this.onClenupCallbacks[model] = [];
|
|
49
|
+
}
|
|
50
|
+
this.onClenupCallbacks[model].push(callback);
|
|
51
|
+
}
|
|
52
|
+
async findOneBy({ model, filter }) {
|
|
53
|
+
return this.collections[model].findOne((0, flatten_1.buildFlattenMap)(filter)).lean().exec();
|
|
54
|
+
}
|
|
55
|
+
async findBy({ model, filter }) {
|
|
56
|
+
return this.collections[model].find((0, flatten_1.buildFlattenMap)(filter)).lean().exec();
|
|
57
|
+
}
|
|
58
|
+
async getAll({ model }) {
|
|
59
|
+
return this.collections[model].find().lean().exec();
|
|
60
|
+
}
|
|
61
|
+
async get({ model, id }) {
|
|
62
|
+
return this.collections[model].findOne({ [this.getIdentifierKey(model)]: id }).lean();
|
|
63
|
+
}
|
|
64
|
+
async exists({ model, id }) {
|
|
65
|
+
const result = await this.collections[model].exists({
|
|
66
|
+
[this.getIdentifierKey(model)]: id
|
|
67
|
+
});
|
|
68
|
+
return result !== null;
|
|
69
|
+
}
|
|
70
|
+
async count({ model, filter }) {
|
|
71
|
+
return this.collections[model].countDocuments((0, flatten_1.buildFlattenMap)(filter ?? {}));
|
|
72
|
+
}
|
|
73
|
+
async existsBy({ model, filter }) {
|
|
74
|
+
const result = await this.collections[model].exists((0, flatten_1.buildFlattenMap)(filter));
|
|
75
|
+
return result !== null;
|
|
76
|
+
}
|
|
77
|
+
async create({ model, data }) {
|
|
78
|
+
if (this.dev) {
|
|
79
|
+
this.log({ op: 'COLLECTIONS:CREATE', model, data });
|
|
80
|
+
}
|
|
81
|
+
await new this.collections[model](data).save();
|
|
82
|
+
}
|
|
83
|
+
async remove({ model, id }) {
|
|
84
|
+
if (this.dev) {
|
|
85
|
+
this.log({ op: 'COLLECTIONS:REMOVE', model, id });
|
|
86
|
+
}
|
|
87
|
+
const cache = { data: null };
|
|
88
|
+
if (this.onClenupCallbacks[model]) {
|
|
89
|
+
cache.data = await this.get({ model, id });
|
|
90
|
+
}
|
|
91
|
+
await this.collections[model].deleteOne({ [this.getIdentifierKey(model)]: id }).exec();
|
|
92
|
+
if (cache.data) {
|
|
93
|
+
this.onClenupCallbacks[model].forEach((cb) => {
|
|
94
|
+
cb(cache.data);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async update({ model, id, patches }) {
|
|
99
|
+
const identifierKey = this.getIdentifierKey(model);
|
|
100
|
+
const collection = await this.getCollection({ model, id });
|
|
101
|
+
const responses = await Promise.all(patches.map(async (patch) => {
|
|
102
|
+
switch (patch.type) {
|
|
103
|
+
case 'set': {
|
|
104
|
+
return collection.updateOne({ [identifierKey]: id }, { $set: { [patch.address]: patch.value } });
|
|
105
|
+
}
|
|
106
|
+
case 'push': {
|
|
107
|
+
return collection.updateOne({ [identifierKey]: id }, { $push: { [patch.address]: { $each: patch.items } } });
|
|
108
|
+
}
|
|
109
|
+
case 'pull': {
|
|
110
|
+
return collection.updateOne({ [identifierKey]: id }, { $pull: { [patch.address]: { $in: patch.items } } });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
for (const response of responses) {
|
|
115
|
+
if (!response.acknowledged) {
|
|
116
|
+
console.log('MongoDB Write Warning', { model, id, patches }, responses);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (this.dev) {
|
|
120
|
+
this.log({ op: 'COLLECTIONS:UPDATE', id, patches });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async replace({ model, id, data }) {
|
|
124
|
+
if (this.dev) {
|
|
125
|
+
this.log({ op: 'COLLECTIONS:REPLACE', model, id, data });
|
|
126
|
+
}
|
|
127
|
+
await this.collections[model].replaceOne({ [this.getIdentifierKey(model)]: id }, data).exec();
|
|
128
|
+
}
|
|
129
|
+
async getCollection({ model, id }) {
|
|
130
|
+
if (this.discriminatedModels[model]) {
|
|
131
|
+
const target = await this.get({ model, id });
|
|
132
|
+
const discriminatorValue = target[this.discriminatedModels[model].discriminatorKey];
|
|
133
|
+
return this.discriminatedModels[model].models[discriminatorValue];
|
|
134
|
+
}
|
|
135
|
+
return this.collections[model];
|
|
136
|
+
}
|
|
137
|
+
getIdentifierKey(model) {
|
|
138
|
+
return this.dataScheme.models[model].scheme.identifier.propertyKey;
|
|
139
|
+
}
|
|
140
|
+
log(item) {
|
|
141
|
+
console.dir(item, { depth: null, colors: true });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.MongoCollectionDriver = MongoCollectionDriver;
|
|
145
|
+
const createMongoDriver = (options) => {
|
|
146
|
+
return (dataScheme) => {
|
|
147
|
+
return new MongoCollectionDriver(dataScheme, options);
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
exports.createMongoDriver = createMongoDriver;
|
|
151
|
+
//# sourceMappingURL=collection.driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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,EAAE,EAAE,EAAE,CAAC,CAAA;YAC5C,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAW,CAAA;YAE7F,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAA;QACnE,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC;IAEO,gBAAgB,CAAC,KAAa;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAA;IACpE,CAAC;IAEO,GAAG,CAAC,IAAY;QACtB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAClD,CAAC;CACF;AA7MD,sDA6MC;AAEM,MAAM,iBAAiB,GAAG,CAAC,OAA2B,EAAE,EAAE;IAC/D,OAAO,CAA6B,UAAyB,EAAE,EAAE;QAC/D,OAAO,IAAI,qBAAqB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC,CAAA;AACH,CAAC,CAAA;AAJY,QAAA,iBAAiB,qBAI7B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CollectionScheme, DataScheme, IType } from '@oxeo/scheme';
|
|
2
|
+
import { OppositeSlice, RelationRecord, TableDriver, TableRelationSlice, TableRow } from '@oxeo/server';
|
|
3
|
+
import { Connection } from 'mongoose';
|
|
4
|
+
export declare class MongoRelationsTable<T extends CollectionScheme> implements TableDriver {
|
|
5
|
+
private readonly tables;
|
|
6
|
+
constructor(dataScheme: DataScheme<T>, connection: Connection);
|
|
7
|
+
createRecord(row: RelationRecord): Promise<void>;
|
|
8
|
+
removeRecord(row: RelationRecord): Promise<void>;
|
|
9
|
+
removeRecordsByModel(row: TableRelationSlice): Promise<void>;
|
|
10
|
+
getRecords({ tableName, modelSide, modelId }: TableRelationSlice): Promise<IType[]>;
|
|
11
|
+
getTables(): Promise<{
|
|
12
|
+
[name: string]: TableRow[];
|
|
13
|
+
}>;
|
|
14
|
+
getOppositeModelName({ tableName, modelSide }: OppositeSlice): Promise<string>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoRelationsTable = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
class MongoTableStore {
|
|
6
|
+
constructor({ rules, tableName }, connection) {
|
|
7
|
+
this.connection = connection;
|
|
8
|
+
this.modelKey = {};
|
|
9
|
+
this.keyMirror = { m1: 'm2', m2: 'm1' };
|
|
10
|
+
this.oppositeModels = { m1: '', m2: '' };
|
|
11
|
+
this.modelKey[rules.m1] = 'm1';
|
|
12
|
+
this.modelKey[rules.m2] = 'm2';
|
|
13
|
+
this.model = this.useModel(tableName, new mongoose_1.Schema(this.getSchemeDefinition()));
|
|
14
|
+
this.oppositeModels.m1 = rules.m2;
|
|
15
|
+
this.oppositeModels.m2 = rules.m1;
|
|
16
|
+
}
|
|
17
|
+
getSchemeDefinition() {
|
|
18
|
+
return {
|
|
19
|
+
m1: { type: mongoose_1.Schema.Types.Mixed, index: true, required: true },
|
|
20
|
+
m2: { type: mongoose_1.Schema.Types.Mixed, index: true, required: true }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
getRow({ modelId, modelSide, oppositeId }) {
|
|
24
|
+
const key = this.modelKey[modelSide];
|
|
25
|
+
const row = { [key]: modelId, [this.keyMirror[key]]: oppositeId };
|
|
26
|
+
return row;
|
|
27
|
+
}
|
|
28
|
+
async addRow(row) {
|
|
29
|
+
await this.model.create(this.getRow(row));
|
|
30
|
+
}
|
|
31
|
+
async removeRow(row) {
|
|
32
|
+
await this.model.deleteOne(this.getRow(row)).exec();
|
|
33
|
+
}
|
|
34
|
+
async removeModel(model, modelId) {
|
|
35
|
+
await this.model.deleteMany({ [this.modelKey[model]]: modelId }).exec();
|
|
36
|
+
}
|
|
37
|
+
async getRelations(model, modelId) {
|
|
38
|
+
const key = this.modelKey[model];
|
|
39
|
+
const oppositeKey = this.keyMirror[key];
|
|
40
|
+
const rows = await this.model
|
|
41
|
+
.find({ [key]: modelId })
|
|
42
|
+
.select({ [oppositeKey]: 1, _id: 0 })
|
|
43
|
+
.lean()
|
|
44
|
+
.exec();
|
|
45
|
+
return rows.map((row) => row[oppositeKey]);
|
|
46
|
+
}
|
|
47
|
+
useModel(model, schema) {
|
|
48
|
+
return this.connection.models[model] ?? this.connection.model(model, schema);
|
|
49
|
+
}
|
|
50
|
+
getStore() {
|
|
51
|
+
return this.model.find().lean().exec();
|
|
52
|
+
}
|
|
53
|
+
getOppositeModelName(model) {
|
|
54
|
+
return this.oppositeModels[this.modelKey[model]];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class MongoRelationsTable {
|
|
58
|
+
constructor(dataScheme, connection) {
|
|
59
|
+
this.tables = {};
|
|
60
|
+
for (const table of dataScheme.tables) {
|
|
61
|
+
this.tables[table.tableName] = new MongoTableStore(table, connection);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async createRecord(row) {
|
|
65
|
+
await this.tables[row.tableName].addRow(row);
|
|
66
|
+
}
|
|
67
|
+
async removeRecord(row) {
|
|
68
|
+
await this.tables[row.tableName].removeRow(row);
|
|
69
|
+
}
|
|
70
|
+
async removeRecordsByModel(row) {
|
|
71
|
+
await this.tables[row.tableName].removeModel(row.modelSide, row.modelId);
|
|
72
|
+
}
|
|
73
|
+
async getRecords({ tableName, modelSide, modelId }) {
|
|
74
|
+
return this.tables[tableName].getRelations(modelSide, modelId);
|
|
75
|
+
}
|
|
76
|
+
async getTables() {
|
|
77
|
+
const state = {};
|
|
78
|
+
for (const tableName in this.tables) {
|
|
79
|
+
state[tableName] = await this.tables[tableName].getStore();
|
|
80
|
+
}
|
|
81
|
+
return state;
|
|
82
|
+
}
|
|
83
|
+
async getOppositeModelName({ tableName, modelSide }) {
|
|
84
|
+
return this.tables[tableName].getOppositeModelName(modelSide);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.MongoRelationsTable = MongoRelationsTable;
|
|
88
|
+
//# sourceMappingURL=table.driver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.driver.js","sourceRoot":"","sources":["../../lib/drivers/table.driver.ts"],"names":[],"mappings":";;;AAQA,uCAAsE;AAEtE,MAAM,eAAe;IAOnB,YAAY,EAAE,KAAK,EAAE,SAAS,EAAsB,EAAU,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAN5E,aAAQ,GAAqC,EAAE,CAAA;QAC/C,cAAS,GAAG,EAAE,EAAE,EAAE,IAAY,EAAE,EAAE,EAAE,IAAY,EAAE,CAAA;QAClD,mBAAc,GAA+B,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAA;QAKrE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;QAC9B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAW,SAAS,EAAE,IAAI,iBAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAA;QAEvF,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAA;QACjC,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAA;IACnC,CAAC;IAEO,mBAAmB;QACzB,OAAO;YACL,EAAE,EAAE,EAAE,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAA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,GAAG,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACjD,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,GAAuB;QAChD,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAC1E,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAsB;QACpE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAChE,CAAC;IAED,KAAK,CAAC,SAAS;QACb,MAAM,KAAK,GAAmC,EAAE,CAAA;QAEhD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACpC,KAAK,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAA;QAC5D,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,EAAE,SAAS,EAAE,SAAS,EAAiB;QAChE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAA;IAC/D,CAAC;CACF;AAtCD,kDAsCC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CollectionScheme, DataScheme, ModelProperties, ModelScheme } from '@oxeo/scheme';
|
|
2
|
+
import type { SchemaDefinition } from 'mongoose';
|
|
3
|
+
export declare class DefinitionsFactory<T extends CollectionScheme> {
|
|
4
|
+
private dataScheme;
|
|
5
|
+
constructor(dataScheme: DataScheme<T>);
|
|
6
|
+
createForCollection(name: keyof T): SchemaDefinition;
|
|
7
|
+
createForScheme(scheme: ModelScheme): SchemaDefinition;
|
|
8
|
+
createDefinitionScheme({ properties, references }: ModelProperties): SchemaDefinition;
|
|
9
|
+
private getPropertyDefinition;
|
|
10
|
+
private getRelationDefinition;
|
|
11
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefinitionsFactory = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const TypesTranslator = {
|
|
6
|
+
string: String,
|
|
7
|
+
number: Number,
|
|
8
|
+
json: Object,
|
|
9
|
+
boolean: Boolean
|
|
10
|
+
};
|
|
11
|
+
class DefinitionsFactory {
|
|
12
|
+
constructor(dataScheme) {
|
|
13
|
+
this.dataScheme = dataScheme;
|
|
14
|
+
}
|
|
15
|
+
createForCollection(name) {
|
|
16
|
+
return this.createForScheme(this.dataScheme.models[this.dataScheme.collectionsScheme[name].name].scheme);
|
|
17
|
+
}
|
|
18
|
+
createForScheme(scheme) {
|
|
19
|
+
return {
|
|
20
|
+
[scheme.identifier.propertyKey]: {
|
|
21
|
+
index: true,
|
|
22
|
+
type: TypesTranslator[scheme.identifier.options.type],
|
|
23
|
+
unique: true
|
|
24
|
+
},
|
|
25
|
+
...this.createDefinitionScheme(scheme)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
createDefinitionScheme({ properties, references }) {
|
|
29
|
+
const map = {};
|
|
30
|
+
for (const property of properties) {
|
|
31
|
+
map[property.propertyKey] = this.getPropertyDefinition(property);
|
|
32
|
+
}
|
|
33
|
+
for (const reference of references) {
|
|
34
|
+
map[reference.propertyKey] = this.getRelationDefinition(reference);
|
|
35
|
+
}
|
|
36
|
+
return map;
|
|
37
|
+
}
|
|
38
|
+
getPropertyDefinition({ primitive }) {
|
|
39
|
+
switch (primitive.type) {
|
|
40
|
+
case 'embedded': {
|
|
41
|
+
return {
|
|
42
|
+
_id: false,
|
|
43
|
+
type: this.createDefinitionScheme(primitive),
|
|
44
|
+
required: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
case 'array': {
|
|
48
|
+
return {
|
|
49
|
+
type: [TypesTranslator[primitive.itemType]],
|
|
50
|
+
required: true
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case 'literal': {
|
|
54
|
+
return {
|
|
55
|
+
type: mongoose_1.Schema.Types.Mixed,
|
|
56
|
+
enum: primitive.values,
|
|
57
|
+
required: !primitive.nullable
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
case 'enum': {
|
|
61
|
+
return {
|
|
62
|
+
type: [String],
|
|
63
|
+
enum: primitive.values,
|
|
64
|
+
required: !primitive.nullable
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
case 'string':
|
|
68
|
+
case 'number': {
|
|
69
|
+
return {
|
|
70
|
+
type: TypesTranslator[primitive.type],
|
|
71
|
+
unique: primitive.unique,
|
|
72
|
+
index: primitive.index
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
default: {
|
|
76
|
+
return {
|
|
77
|
+
type: TypesTranslator[primitive.type]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
getRelationDefinition(reference) {
|
|
83
|
+
const refModel = this.dataScheme.metadata.getModelSchemaByTarget(reference.referenceModel);
|
|
84
|
+
switch (reference.refType) {
|
|
85
|
+
case 'reference-to': {
|
|
86
|
+
const nullable = reference.options?.onRefDeleting === 'set-null' || (reference.options?.onRefDeleting === 'restrict' && (reference.options.nullable ?? false));
|
|
87
|
+
return {
|
|
88
|
+
type: TypesTranslator[refModel.identifier.options.type],
|
|
89
|
+
index: reference.options?.index,
|
|
90
|
+
unique: reference.options?.unique,
|
|
91
|
+
required: !nullable
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
case 'reference-set': {
|
|
95
|
+
return {
|
|
96
|
+
type: [TypesTranslator[refModel.identifier.options.type]]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
case 'belongs-to': {
|
|
100
|
+
return {
|
|
101
|
+
type: TypesTranslator[refModel.identifier.options.type],
|
|
102
|
+
required: true
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
case 'has-many': {
|
|
106
|
+
return {
|
|
107
|
+
type: [TypesTranslator[refModel.identifier.options.type]],
|
|
108
|
+
required: true
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case 'owner': {
|
|
112
|
+
return {
|
|
113
|
+
type: TypesTranslator[refModel.identifier.options.type],
|
|
114
|
+
required: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
case 'owner-fallback': {
|
|
118
|
+
return {
|
|
119
|
+
type: TypesTranslator[refModel.identifier.options.type],
|
|
120
|
+
refType: 'owner-fallback'
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.DefinitionsFactory = DefinitionsFactory;
|
|
127
|
+
//# sourceMappingURL=definitions.factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.factory.js","sourceRoot":"","sources":["../../lib/factories/definitions.factory.ts"],"names":[],"mappings":";;;AASA,uCAAiC;AAEjC,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,MAAM;IACd,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,OAAO;CACjB,CAAA;AAED,MAAa,kBAAkB;IAC7B,YAAoB,UAAyB;QAAzB,eAAU,GAAV,UAAU,CAAe;IAAG,CAAC;IAEjD,mBAAmB,CAAC,IAAa;QAC/B,OAAO,IAAI,CAAC,eAAe,CACzB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAC5E,CAAA;IACH,CAAC;IAED,eAAe,CAAC,MAAmB;QACjC,OAAO;YACL,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAA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E,CAAC,QAAQ;iBACpB,CAAA;YACH,CAAC;YACD,KAAK,eAAe,CAAC,CAAC,CAAC;gBACrB,OAAO;oBACL,IAAI,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;iBAC1D,CAAA;YACH,CAAC;YACD,KAAK,YAAY,CAAC,CAAC,CAAC;gBAClB,OAAO;oBACL,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC;oBACvD,QAAQ,EAAE,IAAI;iBACf,CAAA;YACH,CAAC;YACD,KAAK,UAAU,CAAC,CAAC,CAAC;gBAChB,OAAO;oBACL,IAAI,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;oBACzD,QAAQ,EAAE,IAAI;iBACf,CAAA;YACH,CAAC;YACD,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,OAAO;oBACL,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC;oBACvD,QAAQ,EAAE,IAAI;iBACf,CAAA;YACH,CAAC;YACD,KAAK,gBAAgB,CAAC,CAAC,CAAC;gBACtB,OAAO;oBACL,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC;oBACvD,OAAO,EAAE,gBAAgB;iBAC1B,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA7HD,gDA6HC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./drivers/table.driver"), exports);
|
|
19
|
+
__exportStar(require("./drivers/collection.driver"), exports);
|
|
20
|
+
__exportStar(require("./driver.module"), exports);
|
|
21
|
+
__exportStar(require("./mongoose-options.interface"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,yDAAsC;AACtC,8DAA2C;AAC3C,kDAA+B;AAC/B,+DAA4C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConnectOptions, Connection, MongooseError } from 'mongoose';
|
|
2
|
+
export interface MongooseModuleOptions extends ConnectOptions {
|
|
3
|
+
uri?: string;
|
|
4
|
+
retryAttempts?: number;
|
|
5
|
+
retryDelay?: number;
|
|
6
|
+
connectionName?: string;
|
|
7
|
+
connectionFactory?: (connection: any, name: string) => any;
|
|
8
|
+
connectionErrorFactory?: (error: MongooseError) => MongooseError;
|
|
9
|
+
lazyConnection?: boolean;
|
|
10
|
+
onConnectionCreate?: (connection: Connection) => void;
|
|
11
|
+
verboseRetryLog?: boolean;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoose-options.interface.js","sourceRoot":"","sources":["../lib/mongoose-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { ModuleRef } from '@nestjs/core';
|
|
3
|
+
import { MongooseModuleOptions } from './mongoose-options.interface';
|
|
4
|
+
export declare class MongooseCoreModule implements OnApplicationShutdown {
|
|
5
|
+
private readonly connectionName;
|
|
6
|
+
private readonly moduleRef;
|
|
7
|
+
constructor(connectionName: string, moduleRef: ModuleRef);
|
|
8
|
+
static forRoot(uri: string, options?: MongooseModuleOptions): DynamicModule;
|
|
9
|
+
private static createMongooseConnection;
|
|
10
|
+
onApplicationShutdown(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
45
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
46
|
+
};
|
|
47
|
+
var MongooseCoreModule_1;
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.MongooseCoreModule = void 0;
|
|
50
|
+
const mongoose = __importStar(require("mongoose"));
|
|
51
|
+
const common_1 = require("@nestjs/common");
|
|
52
|
+
const core_1 = require("@nestjs/core");
|
|
53
|
+
const rxjs_1 = require("rxjs");
|
|
54
|
+
const operators_1 = require("rxjs/operators");
|
|
55
|
+
const constants_1 = require("./constants");
|
|
56
|
+
const common_2 = require("./common");
|
|
57
|
+
let MongooseCoreModule = MongooseCoreModule_1 = class MongooseCoreModule {
|
|
58
|
+
constructor(connectionName, moduleRef) {
|
|
59
|
+
this.connectionName = connectionName;
|
|
60
|
+
this.moduleRef = moduleRef;
|
|
61
|
+
}
|
|
62
|
+
static forRoot(uri, options = {}) {
|
|
63
|
+
const { retryAttempts, retryDelay, connectionName, connectionFactory, connectionErrorFactory, lazyConnection, onConnectionCreate, verboseRetryLog, ...mongooseOptions } = options;
|
|
64
|
+
const mongooseConnectionFactory = connectionFactory || ((connection) => connection);
|
|
65
|
+
const mongooseConnectionError = connectionErrorFactory || ((error) => error);
|
|
66
|
+
const mongooseConnectionName = (0, common_2.getConnectionToken)(connectionName);
|
|
67
|
+
const mongooseConnectionNameProvider = {
|
|
68
|
+
provide: constants_1.MONGOOSE_CONNECTION_NAME,
|
|
69
|
+
useValue: mongooseConnectionName
|
|
70
|
+
};
|
|
71
|
+
const connectionProvider = {
|
|
72
|
+
provide: mongooseConnectionName,
|
|
73
|
+
useFactory: async () => await (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(async () => mongooseConnectionFactory(await this.createMongooseConnection(uri, mongooseOptions, {
|
|
74
|
+
lazyConnection,
|
|
75
|
+
onConnectionCreate
|
|
76
|
+
}), mongooseConnectionName)).pipe((0, common_2.handleRetry)(retryAttempts, retryDelay, verboseRetryLog), (0, operators_1.catchError)((error) => {
|
|
77
|
+
throw mongooseConnectionError(error);
|
|
78
|
+
})))
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
module: MongooseCoreModule_1,
|
|
82
|
+
providers: [connectionProvider, mongooseConnectionNameProvider],
|
|
83
|
+
exports: [connectionProvider]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
static async createMongooseConnection(uri, mongooseOptions, factoryOptions) {
|
|
87
|
+
const connection = mongoose.createConnection(uri, mongooseOptions);
|
|
88
|
+
if (factoryOptions?.lazyConnection) {
|
|
89
|
+
return connection;
|
|
90
|
+
}
|
|
91
|
+
factoryOptions?.onConnectionCreate?.(connection);
|
|
92
|
+
return connection.asPromise();
|
|
93
|
+
}
|
|
94
|
+
async onApplicationShutdown() {
|
|
95
|
+
const connection = this.moduleRef.get(this.connectionName);
|
|
96
|
+
if (connection) {
|
|
97
|
+
await connection.close();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
exports.MongooseCoreModule = MongooseCoreModule;
|
|
102
|
+
exports.MongooseCoreModule = MongooseCoreModule = MongooseCoreModule_1 = __decorate([
|
|
103
|
+
(0, common_1.Global)(),
|
|
104
|
+
(0, common_1.Module)({}),
|
|
105
|
+
__param(0, (0, common_1.Inject)(constants_1.MONGOOSE_CONNECTION_NAME)),
|
|
106
|
+
__metadata("design:paramtypes", [String, core_1.ModuleRef])
|
|
107
|
+
], MongooseCoreModule);
|
|
108
|
+
//# sourceMappingURL=mongoose.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoose.module.js","sourceRoot":"","sources":["../lib/mongoose.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAoC;AACpC,2CAA6F;AAC7F,uCAAwC;AAExC,+BAA2C;AAC3C,8CAA2C;AAC3C,2CAAsD;AACtD,qCAA0D;AAKnD,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC7B,YACqD,cAAsB,EACxD,SAAoB;QADc,mBAAc,GAAd,cAAc,CAAQ;QACxD,cAAS,GAAT,SAAS,CAAW;IACpC,CAAC;IAEJ,MAAM,CAAC,OAAO,CAAC,GAAW,EAAE,UAAiC,EAAE;QAC7D,MAAM,EACJ,aAAa,EACb,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,GAAG,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E,CAAC;YACnC,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,cAAc,EAAE,kBAAkB,EAAE,CAAC,UAAU,CAAC,CAAA;QAEhD,OAAO,UAAU,CAAC,SAAS,EAAE,CAAA;IAC/B,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAM,IAAI,CAAC,cAAc,CAAC,CAAA;QAC/D,IAAI,UAAU,EAAE,CAAC;YACf,MAAM,UAAU,CAAC,KAAK,EAAE,CAAA;QAC1B,CAAC;IACH,CAAC;CACF,CAAA;AAlFY,gDAAkB;6BAAlB,kBAAkB;IAF9B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;IAGN,WAAA,IAAA,eAAM,EAAC,oCAAwB,CAAC,CAAA;6CACL,gBAAS;GAH5B,kBAAkB,CAkF9B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CollectionScheme, DataScheme } from '@oxeo/scheme';
|
|
2
|
+
import { DataSource } from '@oxeo/server';
|
|
3
|
+
import { MongoDriverOptions } from '../drivers/collection.driver';
|
|
4
|
+
declare class DataSourceStorageService {
|
|
5
|
+
private store;
|
|
6
|
+
getProviderToken(dataScheme: DataScheme<CollectionScheme>): string;
|
|
7
|
+
getSource(dataScheme: DataScheme<CollectionScheme>, options: MongoDriverOptions): DataSource<CollectionScheme, import("@oxeo/server").CollectionDriver>;
|
|
8
|
+
}
|
|
9
|
+
export declare const DataSourceStorage: DataSourceStorageService;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSourceStorage = void 0;
|
|
4
|
+
const server_1 = require("@oxeo/server");
|
|
5
|
+
const collection_driver_1 = require("../drivers/collection.driver");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
class DataSourceStorageService {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.store = new Map();
|
|
10
|
+
}
|
|
11
|
+
getProviderToken(dataScheme) {
|
|
12
|
+
if (this.store.has(dataScheme)) {
|
|
13
|
+
return this.store.get(dataScheme).token;
|
|
14
|
+
}
|
|
15
|
+
const token = `${constants_1.DATA_SOURCE_TOKEN}-${this.store.size + 1}`;
|
|
16
|
+
this.store.set(dataScheme, {
|
|
17
|
+
token,
|
|
18
|
+
dataSource: null
|
|
19
|
+
});
|
|
20
|
+
return token;
|
|
21
|
+
}
|
|
22
|
+
getSource(dataScheme, options) {
|
|
23
|
+
const data = this.store.get(dataScheme);
|
|
24
|
+
if (!data) {
|
|
25
|
+
throw new Error(`[MongoDriver] provided dataScheme not defined`);
|
|
26
|
+
}
|
|
27
|
+
if (!data.dataSource) {
|
|
28
|
+
data.dataSource = new server_1.DataSource(dataScheme, {
|
|
29
|
+
createDriver: (0, collection_driver_1.createMongoDriver)(options)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return data.dataSource;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.DataSourceStorage = new DataSourceStorageService();
|
|
36
|
+
//# sourceMappingURL=data-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source.js","sourceRoot":"","sources":["../../lib/storages/data-source.ts"],"names":[],"mappings":";;;AACA,yCAAyC;AACzC,oEAAoF;AACpF,4CAAgD;AAOhD,MAAM,wBAAwB;IAA9B;QACU,UAAK,GAAG,IAAI,GAAG,EAAuC,CAAA;IAgChE,CAAC;IA9BC,gBAAgB,CAAC,UAAwC;QACvD,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC,KAAK,CAAA;QAC1C,CAAC;QAED,MAAM,KAAK,GAAG,GAAG,6BAAiB,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,CAAA;QAE3D,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE;YACzB,KAAK;YACL,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;QAEF,OAAO,KAAK,CAAA;IACd,CAAC;IAED,SAAS,CAAC,UAAwC,EAAE,OAA2B;QAC7E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;QAEvC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAClE,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,IAAI,mBAAU,CAAC,UAAU,EAAE;gBAC3C,YAAY,EAAE,IAAA,qCAAiB,EAAC,OAAO,CAAC;aACzC,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAA;IACxB,CAAC;CACF;AAEY,QAAA,iBAAiB,GAAG,IAAI,wBAAwB,EAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const buildFlattenMap: (filter: object) => Record<string, unknown>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildFlattenMap = void 0;
|
|
4
|
+
const utils_js_1 = require("@companix/utils-js");
|
|
5
|
+
const scheme_1 = require("@oxeo/scheme");
|
|
6
|
+
const buildFlattenMap = (filter) => {
|
|
7
|
+
const out = {};
|
|
8
|
+
const walk = (node, prefix) => {
|
|
9
|
+
if (node === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (node === null || typeof node !== 'object' || Array.isArray(node) || !(0, utils_js_1.isPlainObject)(node)) {
|
|
13
|
+
if (prefix !== '') {
|
|
14
|
+
out[prefix] = node;
|
|
15
|
+
}
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (prefix !== '' && (0, scheme_1.isFilterOperators)(node)) {
|
|
19
|
+
const operators = {};
|
|
20
|
+
for (const operator in node) {
|
|
21
|
+
operators[`$${operator}`] = node[operator];
|
|
22
|
+
}
|
|
23
|
+
out[prefix] = operators;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const keys = Object.keys(node);
|
|
27
|
+
if (keys.length === 0) {
|
|
28
|
+
if (prefix !== '') {
|
|
29
|
+
out[prefix] = node;
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (const key of keys) {
|
|
34
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
35
|
+
walk(node[key], path);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
walk(filter, '');
|
|
39
|
+
return out;
|
|
40
|
+
};
|
|
41
|
+
exports.buildFlattenMap = buildFlattenMap;
|
|
42
|
+
//# sourceMappingURL=flatten.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flatten.js","sourceRoot":"","sources":["../../lib/utils/flatten.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAClD,yCAAgD;AAMzC,MAAM,eAAe,GAAG,CAAC,MAAc,EAA2B,EAAE;IACzE,MAAM,GAAG,GAA4B,EAAE,CAAA;IAEvC,MAAM,IAAI,GAAG,CAAC,IAAa,EAAE,MAAc,EAAE,EAAE;QAC7C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,OAAM;QACR,CAAC;QAED,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAA,wBAAa,EAAC,IAAI,CAAC,EAAE,CAAC;YAC7F,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;gBAClB,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;YACpB,CAAC;YAED,OAAM;QACR,CAAC;QAED,IAAI,MAAM,KAAK,EAAE,IAAI,IAAA,0BAAiB,EAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,MAAM,SAAS,GAA4B,EAAE,CAAA;YAE7C,KAAK,MAAM,QAAQ,IAAI,IAAI,EAAE,CAAC;gBAC5B,SAAS,CAAC,IAAI,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,QAAwB,CAAC,CAAA;YAC5D,CAAC;YAED,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;YACvB,OAAM;QACR,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE9B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;gBAClB,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;YACpB,CAAC;YAED,OAAM;QACR,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAA;YAE9C,IAAI,CAAE,IAAgC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAA;QACpD,CAAC;IACH,CAAC,CAAA;IAED,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAEhB,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AA/CY,QAAA,eAAe,mBA+C3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxeo-drivers/mongo",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Драйвер @oxeo/server для MongoDB и модуль NestJS над ним",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/troovi/oxeo.git",
|
|
8
|
+
"directory": "drivers/mongo"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"echo": "echo \"@oxeo-drivers/mongo.\"",
|
|
17
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
18
|
+
"test:unit": "tsc --noEmit && tsx ./tests/unit/definitions.test.ts",
|
|
19
|
+
"test:unit:map": "tsc --noEmit && tsx ./tests/unit/flatten.test.ts",
|
|
20
|
+
"test:app": "nest start --watch --builder tsc --path tsconfig.test-app.json --sourceRoot tests/app --entryFile main",
|
|
21
|
+
"test:custom": "nest start --watch --builder tsc --path tsconfig.test-app.json --sourceRoot tests --entryFile integrations/custom.test",
|
|
22
|
+
"test:cases": "jest --config ./jest.cases.config.cjs --runInBand"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@oxeo-drivers/memory": "*",
|
|
26
|
+
"@nestjs/common": "^11.1.17",
|
|
27
|
+
"@nestjs/core": "^11.1.17",
|
|
28
|
+
"@nestjs/platform-express": "^11.1.12",
|
|
29
|
+
"@types/jest": "^30.0.0",
|
|
30
|
+
"class-transformer": "^0.5.1",
|
|
31
|
+
"class-validator": "^0.15.1",
|
|
32
|
+
"eslint-config-react-app": "^7.0.1",
|
|
33
|
+
"eslint-plugin-import": "^2.29.1",
|
|
34
|
+
"eslint-plugin-react": "^7.34.3",
|
|
35
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
36
|
+
"jest": "^30.3.0",
|
|
37
|
+
"mongoose": "9.3.3",
|
|
38
|
+
"ts-jest": "^29.4.6",
|
|
39
|
+
"zod": "^4.3.6"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@companix/utils-js": "*",
|
|
43
|
+
"@oxeo/scheme": "*",
|
|
44
|
+
"@oxeo/server": "*"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
48
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
49
|
+
"mongoose": "^9.0.0"
|
|
50
|
+
}
|
|
6
51
|
}
|
package/README.md
DELETED