fix: Потерялась зависимость rfdc

fix: Исправить опечатку number_
fix: Фикс в монге, коллекцию не надо создавать до проверки уникального ключа
fix: Заменить TypeError на ErrStorage в mongo
fix: Исправить collectionName в сигнатуре remove
This commit is contained in:
Nikita Dezzpil Orlov 2021-10-13 14:55:35 +03:00
parent 231895c7cd
commit e1d03577dd
7 changed files with 28 additions and 20 deletions

9
orm.d.ts vendored
View File

@ -1,10 +1,13 @@
/** @public */
export declare abstract class Data {
[key: string]: any;
/**
* @deprecated use fromObject()
*/
static assign(vo: Data, values: ValuesObject): Data;
set(key: string, value: any): void;
fromObject(object: ValuesObject): void;
toObject(exclude?: string[]): Record<string, any>;
toObject(exclude?: string[]): ValuesObject;
abstract uniqKey(): string;
}
@ -99,13 +102,13 @@ declare abstract class Storage_2 {
abstract save(name: string, uniqKey: string, data: Record<string, any>): Promise<string>;
abstract createSession(): StorageSession;
abstract count(name: string, query?: Record<string, any>): Promise<number>;
abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean>;
abstract remove(name: string, uniqKey: string, uniqVal: string | number): Promise<boolean>;
}
export { Storage_2 as Storage }
/** @public */
export declare interface StorageCursor {
limit(number_: number): StorageCursor;
limit(number: number): StorageCursor;
sort(parameters: Record<string, any>): StorageCursor;
skip(offset: number): StorageCursor;
toArray(): Promise<any[]>;

10
package-lock.json generated
View File

@ -8,6 +8,9 @@
"name": "ivna-orm",
"version": "1.3.2",
"license": "ISC",
"dependencies": {
"rfdc": "^1.3.0"
},
"devDependencies": {
"@jest/test-sequencer": "^27.2.3",
"@microsoft/api-extractor": "^7.18.11",
@ -21,7 +24,6 @@
"jest-teamcity": "^1.10.0",
"nanoid": "^3.1.28",
"prettier": "^2.4.1",
"rfdc": "^1.3.0",
"standard-version": "^9.3.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
@ -5658,8 +5660,7 @@
"node_modules/rfdc": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz",
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==",
"dev": true
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA=="
},
"node_modules/rimraf": {
"version": "3.0.2",
@ -11393,8 +11394,7 @@
"rfdc": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz",
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==",
"dev": true
"integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA=="
},
"rimraf": {
"version": "3.0.2",

View File

@ -43,7 +43,6 @@
"jest-teamcity": "^1.10.0",
"nanoid": "^3.1.28",
"prettier": "^2.4.1",
"rfdc": "^1.3.0",
"standard-version": "^9.3.1",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
@ -60,5 +59,8 @@
"semi": false,
"singleQuote": true,
"tabWidth": 4
},
"dependencies": {
"rfdc": "^1.3.0"
}
}

View File

@ -7,6 +7,9 @@ export type ValuesObject = Record<string, any>
export abstract class Data {
[key: string]: any
/**
* @deprecated use fromObject()
*/
static assign(vo: Data, values: ValuesObject): Data {
for (const key of Object.getOwnPropertyNames(values)) {
vo[key] = values[key]
@ -26,7 +29,7 @@ export abstract class Data {
}
}
toObject(exclude: string[] = []): Record<string, any> {
toObject(exclude: string[] = []): ValuesObject {
const object = {} as ValuesObject
for (const key of Object.getOwnPropertyNames(this)) {
if (key.startsWith('__')) {

View File

@ -1,6 +1,6 @@
/** @public */
export interface StorageCursor {
limit(number_: number): StorageCursor
limit(number: number): StorageCursor
sort(parameters: Record<string, any>): StorageCursor
skip(offset: number): StorageCursor
toArray(): Promise<any[]>
@ -28,7 +28,7 @@ export abstract class Storage {
abstract count(name: string, query?: Record<string, any>): Promise<number>
abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean>
abstract remove(name: string, uniqKey: string, uniqVal: string | number): Promise<boolean>
}
/** @public */

View File

@ -1,5 +1,5 @@
import { ClientSession, MongoClient, TransactionOptions } from 'mongodb'
import { Storage, StorageCursor, StorageSession } from '../storage'
import { ErrStorage, Storage, StorageCursor, StorageSession } from '../storage'
import { ErrEntityHasNoUniqKeyValue } from '../entity'
/** @public */
@ -36,8 +36,8 @@ export class MongoStorage extends Storage {
async save(collectionName: string, uniqKey: string, data: Record<string, any>): Promise<string> {
await this._connect()
const id = data[uniqKey]
const coll = await this._client.db().collection(collectionName)
if (id !== null && id !== undefined) {
const coll = await this._client.db().collection(collectionName)
const filter = { [uniqKey]: id }
const result = await coll.findOneAndReplace(filter, data, { upsert: true })
if (result.lastErrorObject) {
@ -48,7 +48,7 @@ export class MongoStorage extends Storage {
return result.lastErrorObject.upserted
}
throw new TypeError(`can not save data to ${collectionName} with result ${result}`)
throw new ErrStorage(`can not save data to ${collectionName} with result ${result}`)
} else {
// Нельзя сохранить сущность без значения уникального ключа
// const result = await coll.insertOne(data)
@ -70,8 +70,8 @@ export class MongoStorage extends Storage {
return this._client
}
async remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean> {
const coll = await this._client.db().collection(collectionName)
async remove(name: string, uniqKeyName: string, uniqKey: string): Promise<boolean> {
const coll = await this._client.db().collection(name)
const result = await coll.deleteOne({ [uniqKeyName]: uniqKey })
return Promise.resolve(result.acknowledged)
}

View File

@ -9,8 +9,8 @@ export class MapCursor implements StorageCursor {
this._map = map
}
limit(number_: number): StorageCursor {
this._limit = number_
limit(number: number): StorageCursor {
this._limit = number
return this
}
@ -67,7 +67,7 @@ export class MapStorage extends Storage {
return Promise.resolve(0)
}
async remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean> {
async remove(name: string, uniqKeyName: string, uniqKey: string): Promise<boolean> {
return Promise.resolve(true)
}