Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d8e2e40360 | ||
|
7f25b665f4 |
@ -1,5 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
||||||
|
|
||||||
### 1.0.1 (2021-09-29)
|
|
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.1.0](https://git.archive.systems/Dezzpil/ivanovna.orm/compare/v1.0.2...v1.1.0) (2021-09-29)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Добавил разметку для экстрактора апи и команду для сборника типов ([7f25b66](https://git.archive.systems/Dezzpil/ivanovna.orm/commit/7f25b665f4f27665595065f006c41669b0f77dd3))
|
||||||
|
|
||||||
### [1.0.2](https://git.archive.systems/Dezzpil/ivanovna.orm/compare/v1.0.1...v1.0.2) (2021-09-29)
|
### [1.0.2](https://git.archive.systems/Dezzpil/ivanovna.orm/compare/v1.0.1...v1.0.2) (2021-09-29)
|
||||||
|
|
||||||
|
|
||||||
|
44
api-extractor.json
Normal file
44
api-extractor.json
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
||||||
|
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts",
|
||||||
|
"apiReport": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"docModel": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"dtsRollup": {
|
||||||
|
"enabled": true,
|
||||||
|
"untrimmedFilePath": "",
|
||||||
|
"publicTrimmedFilePath": "<projectFolder>/orm.d.ts"
|
||||||
|
},
|
||||||
|
"tsdocMetadata": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"newlineKind": "lf",
|
||||||
|
"messages": {
|
||||||
|
"compilerMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extractorMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "error"
|
||||||
|
},
|
||||||
|
"ae-internal-missing-underscore": {
|
||||||
|
"logLevel": "none",
|
||||||
|
"addToApiReportFile": false
|
||||||
|
},
|
||||||
|
"ae-forgotten-export": {
|
||||||
|
"logLevel": "error",
|
||||||
|
"addToApiReportFile": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tsdocMessageReporting": {
|
||||||
|
"default": {
|
||||||
|
"logLevel": "none"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
orm.d.ts
vendored
Normal file
109
orm.d.ts
vendored
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/** @public */
|
||||||
|
export declare abstract class Data {
|
||||||
|
[key: string]: any;
|
||||||
|
static assign(vo: Data, values: ValuesObject): Data;
|
||||||
|
set(key: string, value: any): void;
|
||||||
|
fromObject(object: ValuesObject): void;
|
||||||
|
toObject(exclude?: string[]): Record<string, any>;
|
||||||
|
abstract uniqKey(): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare abstract class Entity<T extends Data> {
|
||||||
|
abstract _getRepo(storage: Storage_2): Repo<Entity<T>>;
|
||||||
|
abstract _getVO(): T;
|
||||||
|
protected _data: T;
|
||||||
|
private __id;
|
||||||
|
get data(): T;
|
||||||
|
get _id(): string;
|
||||||
|
set _id(value: string);
|
||||||
|
constructor(data?: T);
|
||||||
|
getUniqKey(): any;
|
||||||
|
isPersisted(): boolean;
|
||||||
|
toString(): any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare type EntityConstructor<T extends Data> = new (data?: T) => Entity<T>;
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare class ErrEntityHasNoUniqKeyValue extends Error {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare class ErrEntityNotFound extends Error {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare class ErrFoundNotUniqEntity extends Error {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare class ErrNoSession extends ErrStorage {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare class ErrStorage extends Error {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare abstract class Repo<T extends Entity<any>> {
|
||||||
|
protected _storage: Storage_2;
|
||||||
|
protected _entity: T;
|
||||||
|
protected _limit: number;
|
||||||
|
protected _offset: number;
|
||||||
|
/**
|
||||||
|
* Возвращает объект соотв. сущности, например new App()
|
||||||
|
*/
|
||||||
|
abstract Entity(): T;
|
||||||
|
/**
|
||||||
|
* Возвращает название коллекции/таблицы/... хранящей записи соотв. сущностей
|
||||||
|
*/
|
||||||
|
abstract Name(): string;
|
||||||
|
_transformer: (object: any) => any;
|
||||||
|
constructor(storage: Storage_2);
|
||||||
|
resetTransformer(): void;
|
||||||
|
get storage(): Storage_2;
|
||||||
|
save(entity: T): Promise<this>;
|
||||||
|
findById(id: string): Promise<T | null>;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
_findByParams(parameters: Record<string, unknown>, limit?: number, order?: Record<string, unknown>): Promise<T[]>;
|
||||||
|
findMany(parameters: Record<string, unknown>, order?: Record<string, unknown>): Promise<T[]>;
|
||||||
|
shift(limit?: number, offset?: number): this;
|
||||||
|
count(query?: Record<string, unknown>): Promise<number>;
|
||||||
|
remove(entity: T, silent?: boolean): Promise<this>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
declare abstract class Storage_2 {
|
||||||
|
protected _dsn: string;
|
||||||
|
constructor(dsn: string);
|
||||||
|
abstract find(name: string, query: Record<string, unknown>): Promise<StorageCursor>;
|
||||||
|
abstract save(name: string, uniqKey: string, data: Record<string, unknown>): Promise<string>;
|
||||||
|
abstract createSession(): StorageSession;
|
||||||
|
abstract count(name: string, query?: Record<string, unknown>): Promise<number>;
|
||||||
|
abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean>;
|
||||||
|
}
|
||||||
|
export { Storage_2 as Storage }
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare interface StorageCursor {
|
||||||
|
limit(number_: number): StorageCursor;
|
||||||
|
sort(parameters: Record<string, any>): StorageCursor;
|
||||||
|
skip(offset: number): StorageCursor;
|
||||||
|
toArray(): Promise<any[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare abstract class StorageSession {
|
||||||
|
abstract start(options?: Record<string, unknown>): Promise<void>;
|
||||||
|
abstract commit(fn: () => any, options?: Record<string, unknown>): Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export declare type ValuesObject = Record<string, any>;
|
||||||
|
|
||||||
|
export { }
|
858
package-lock.json
generated
858
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -1,18 +1,23 @@
|
|||||||
{
|
{
|
||||||
"name": "ivna-orm",
|
"name": "ivna-orm",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"description": "Mini ORM for convenience",
|
"description": "Mini ORM for convenience",
|
||||||
"main": "src/index.ts",
|
"main": "dist/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
"dist/index.js",
|
"dist/index.js",
|
||||||
"dist/index.d.ts",
|
"dist/index.d.ts",
|
||||||
"dist/app/**/*"
|
"dist/app/**/*",
|
||||||
|
"src/index.ts",
|
||||||
|
"src/app/**/*",
|
||||||
|
"orm.d.ts"
|
||||||
],
|
],
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --no-warnings node_modules/.bin/jest --runInBand --forceExit",
|
"test": "node --no-warnings node_modules/.bin/jest --runInBand --forceExit",
|
||||||
"prepare": "npm test && npm run build",
|
|
||||||
"build": "rimraf dist && tsc -b -v",
|
"build": "rimraf dist && tsc -b -v",
|
||||||
"release": "standard-version -i HISTORY.md"
|
"build:api": "npm run build && api-extractor run && rimraf 'dist/**/*.d.ts*'",
|
||||||
|
"release": "standard-version -i HISTORY.md",
|
||||||
|
"prepare": "npm test && npm run build:api"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -27,6 +32,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@jest/test-sequencer": "^27.2.3",
|
"@jest/test-sequencer": "^27.2.3",
|
||||||
|
"@microsoft/api-extractor": "^7.18.11",
|
||||||
"@types/chai": "^4.2.22",
|
"@types/chai": "^4.2.22",
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
"@types/node": "^14.17.19",
|
"@types/node": "^14.17.19",
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import rfdc from 'rfdc'
|
import rfdc from 'rfdc'
|
||||||
|
|
||||||
type ValuesObject = Record<string, any>
|
/** @public */
|
||||||
|
export type ValuesObject = Record<string, any>
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export abstract class Data {
|
export abstract class Data {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
|
|
||||||
|
@ -2,10 +2,13 @@ import { Data } from './data'
|
|||||||
import { Repo } from './repo'
|
import { Repo } from './repo'
|
||||||
import { Storage } from './storage'
|
import { Storage } from './storage'
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export type EntityConstructor<T extends Data> = new (data?: T) => Entity<T>
|
export type EntityConstructor<T extends Data> = new (data?: T) => Entity<T>
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export class ErrEntityHasNoUniqKeyValue extends Error {}
|
export class ErrEntityHasNoUniqKeyValue extends Error {}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export abstract class Entity<T extends Data> {
|
export abstract class Entity<T extends Data> {
|
||||||
abstract _getRepo(storage: Storage): Repo<Entity<T>>
|
abstract _getRepo(storage: Storage): Repo<Entity<T>>
|
||||||
abstract _getVO(): T
|
abstract _getVO(): T
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import { Entity } from './entity'
|
import { Entity } from './entity'
|
||||||
import { Storage } from './storage'
|
import { Storage } from './storage'
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export class ErrFoundNotUniqEntity extends Error {}
|
export class ErrFoundNotUniqEntity extends Error {}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export class ErrEntityNotFound extends Error {}
|
export class ErrEntityNotFound extends Error {}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export abstract class Repo<T extends Entity<any>> {
|
export abstract class Repo<T extends Entity<any>> {
|
||||||
protected _storage: Storage
|
protected _storage: Storage
|
||||||
protected _entity: T
|
protected _entity: T
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/** @public */
|
||||||
export interface StorageCursor {
|
export interface StorageCursor {
|
||||||
limit(number_: number): StorageCursor
|
limit(number_: number): StorageCursor
|
||||||
sort(parameters: Record<string, any>): StorageCursor
|
sort(parameters: Record<string, any>): StorageCursor
|
||||||
@ -5,9 +6,13 @@ export interface StorageCursor {
|
|||||||
toArray(): Promise<any[]>
|
toArray(): Promise<any[]>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export class ErrStorage extends Error {}
|
export class ErrStorage extends Error {}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export class ErrNoSession extends ErrStorage {}
|
export class ErrNoSession extends ErrStorage {}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export abstract class Storage {
|
export abstract class Storage {
|
||||||
protected _dsn: string
|
protected _dsn: string
|
||||||
|
|
||||||
@ -26,6 +31,7 @@ export abstract class Storage {
|
|||||||
abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean>
|
abstract remove(collectionName: string, uniqKeyName: string, uniqKey: string): Promise<boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export abstract class StorageSession {
|
export abstract class StorageSession {
|
||||||
abstract start(options?: Record<string, unknown>): Promise<void>
|
abstract start(options?: Record<string, unknown>): Promise<void>
|
||||||
abstract commit(fn: () => any, options?: Record<string, unknown>): Promise<void>
|
abstract commit(fn: () => any, options?: Record<string, unknown>): Promise<void>
|
||||||
|
@ -2,6 +2,7 @@ import { ClientSession, MongoClient, TransactionOptions } from 'mongodb'
|
|||||||
import { Storage, StorageCursor, StorageSession } from '../storage'
|
import { Storage, StorageCursor, StorageSession } from '../storage'
|
||||||
import { ErrEntityHasNoUniqKeyValue } from '../entity'
|
import { ErrEntityHasNoUniqKeyValue } from '../entity'
|
||||||
|
|
||||||
|
/** @public */
|
||||||
export class MongoStorage extends Storage {
|
export class MongoStorage extends Storage {
|
||||||
private readonly _client: MongoClient
|
private readonly _client: MongoClient
|
||||||
_session: ClientSession
|
_session: ClientSession
|
||||||
|
@ -2,7 +2,7 @@ import { EntityConstructor, ErrEntityHasNoUniqKeyValue } from './app/entity'
|
|||||||
import { ErrEntityNotFound, ErrFoundNotUniqEntity } from './app/repo'
|
import { ErrEntityNotFound, ErrFoundNotUniqEntity } from './app/repo'
|
||||||
import { ErrNoSession, ErrStorage, StorageCursor, StorageSession } from './app/storage'
|
import { ErrNoSession, ErrStorage, StorageCursor, StorageSession } from './app/storage'
|
||||||
|
|
||||||
export { Data } from './app/data'
|
export { Data, ValuesObject } from './app/data'
|
||||||
export { Entity, EntityConstructor, ErrEntityHasNoUniqKeyValue } from './app/entity'
|
export { Entity, EntityConstructor, ErrEntityHasNoUniqKeyValue } from './app/entity'
|
||||||
export { Repo, ErrFoundNotUniqEntity, ErrEntityNotFound } from './app/repo'
|
export { Repo, ErrFoundNotUniqEntity, ErrEntityNotFound } from './app/repo'
|
||||||
export { Storage, StorageCursor, ErrStorage, ErrNoSession, StorageSession } from './app/storage'
|
export { Storage, StorageCursor, ErrStorage, ErrNoSession, StorageSession } from './app/storage'
|
||||||
|
@ -4,10 +4,9 @@
|
|||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"sourceMap": false,
|
"sourceMap": false,
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": false,
|
"declarationMap": true,
|
||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
"checkJs": false,
|
"checkJs": false,
|
||||||
"removeComments": true,
|
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user