type-mongodb
Advanced tools
Comparing version 0.0.1-beta3 to 0.0.1-beta4
@@ -12,3 +12,3 @@ import { MongoClient, SessionOptions } from 'mongodb'; | ||
export interface ContainerLike { | ||
get: <T = any>(service: Newable<T>) => T; | ||
get: <T = any>(service: Newable<T>) => any; | ||
} | ||
@@ -33,3 +33,3 @@ export interface DocumentManagerOptions { | ||
constructor(opts: DocumentManagerOptions); | ||
buildMetadata(): void; | ||
buildMetadata(): Promise<void>; | ||
buildSubscribers(): void; | ||
@@ -36,0 +36,0 @@ /** |
@@ -42,3 +42,5 @@ "use strict"; | ||
buildMetadata() { | ||
this.metadataFactory.build(); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.metadataFactory.build(); | ||
}); | ||
} | ||
@@ -146,3 +148,3 @@ buildSubscribers() { | ||
yield dm.connect(); | ||
dm.buildMetadata(); | ||
yield dm.buildMetadata(); | ||
dm.buildSubscribers(); | ||
@@ -149,0 +151,0 @@ return dm; |
@@ -19,3 +19,3 @@ import { DocumentMetadata } from './DocumentMetadata'; | ||
constructor(opts: BuildMetadataStorageOptions); | ||
build(): void; | ||
build(): Promise<void>; | ||
/** | ||
@@ -41,7 +41,7 @@ * Gets the DocumentMetadata for the given class. | ||
*/ | ||
protected buildDocuments(): void; | ||
protected buildDocuments(): Promise<void>; | ||
/** | ||
* Builds the DocumentMetadata and it's fields for the given class. | ||
*/ | ||
protected buildMetadataForDocument(DocumentClass: DocumentClass): DocumentMetadata; | ||
protected buildMetadataForDocument(DocumentClass: DocumentClass): Promise<DocumentMetadata>; | ||
protected buildEmbeddedDocumentMetadata(DocumentClass: DocumentClass): EmbeddedDocumentMetadata; | ||
@@ -48,0 +48,0 @@ /** |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,2 +17,3 @@ const DocumentMetadata_1 = require("./DocumentMetadata"); | ||
const repository_1 = require("../repository"); | ||
const isPromise_1 = require("../utils/isPromise"); | ||
/** | ||
@@ -23,7 +33,9 @@ * DocumentMetadataFactory builds and validates all the Document's metadata. | ||
build() { | ||
if (this.isBuilt) { | ||
throw new Error('DocumentMetadata already built'); | ||
} | ||
this.buildDocuments(); | ||
this.isBuilt = true; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.isBuilt) { | ||
throw new Error('DocumentMetadata already built'); | ||
} | ||
yield this.buildDocuments(); | ||
this.isBuilt = true; | ||
}); | ||
} | ||
@@ -76,4 +88,14 @@ /** | ||
buildDocuments() { | ||
this.opts.documents.forEach(DocumentClass => { | ||
this.loadedDocumentMetadata.set(DocumentClass, this.buildMetadataForDocument(DocumentClass)); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield Promise.all(this.opts.documents.map(DocumentClass => { | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
this.loadedDocumentMetadata.set(DocumentClass, yield this.buildMetadataForDocument(DocumentClass)); | ||
resolve(); | ||
} | ||
catch (err) { | ||
reject(err); | ||
} | ||
})); | ||
})); | ||
}); | ||
@@ -85,21 +107,26 @@ } | ||
buildMetadataForDocument(DocumentClass) { | ||
if (!definitionStorage_1.definitionStorage.documents.has(DocumentClass)) { | ||
throw new Error(`"${DocumentClass.name}" is not a decorated @Document()`); | ||
} | ||
const def = definitionStorage_1.definitionStorage.documents.get(DocumentClass); | ||
const connection = this.opts.dm.connection; | ||
const db = connection.getDatabase(connection, def.database); | ||
const RepositoryClass = def.repository ? def.repository() : repository_1.Repository; | ||
const repository = this.opts.dm.container.get(RepositoryClass); | ||
repository.manager = this.opts.dm; | ||
const meta = new DocumentMetadata_1.DocumentMetadata({ | ||
DocumentClass, | ||
fields: this.buildFields(DocumentClass), | ||
connection, | ||
db, | ||
collection: db.collection(def.collection), | ||
repository, | ||
extensions: def.extensions || {} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!definitionStorage_1.definitionStorage.documents.has(DocumentClass)) { | ||
throw new Error(`"${DocumentClass.name}" is not a decorated @Document()`); | ||
} | ||
const def = definitionStorage_1.definitionStorage.documents.get(DocumentClass); | ||
const connection = this.opts.dm.connection; | ||
const db = connection.getDatabase(connection, def.database); | ||
const RepositoryClass = def.repository ? def.repository() : repository_1.Repository; | ||
const repository = this.opts.dm.container.get(RepositoryClass); | ||
if (isPromise_1.isPromise(repository)) { | ||
yield repository; | ||
} | ||
repository.manager = this.opts.dm; | ||
const meta = new DocumentMetadata_1.DocumentMetadata({ | ||
DocumentClass, | ||
fields: this.buildFields(DocumentClass), | ||
connection, | ||
db, | ||
collection: db.collection(def.collection), | ||
repository, | ||
extensions: def.extensions || {} | ||
}); | ||
return meta; | ||
}); | ||
return meta; | ||
} | ||
@@ -106,0 +133,0 @@ buildEmbeddedDocumentMetadata(DocumentClass) { |
{ | ||
"name": "type-mongodb", | ||
"version": "0.0.1-beta3", | ||
"version": "0.0.1-beta4", | ||
"description": "A simple decorator based MongoDB ODM.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176729
110
2246