mirror of
https://github.com/cool-team-official/cool-admin-midway-packages.git
synced 2025-12-10 21:32:48 +00:00
自定义typeorm
This commit is contained in:
parent
89e7c3bc3d
commit
f0ab1a14e3
13
core/README.md
Normal file
13
core/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Cool Admin Node
|
||||
|
||||
cool-admin一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发CRUD,方便快速构建迭代后台管理系统,支持serverless、docker、普通服务器等多种方式部署 到 官网 进一步了解。
|
||||
|
||||
[https://cool-js.com](https://cool-js.com)
|
||||
|
||||
## 特性
|
||||
|
||||
- 🔥 **AI 编码** - 从页面到后端代码,部分功能实现零代码
|
||||
- 🎯 **Ai 流程编排** - 专门为 AI 开发设计,几乎无需编码,拖拽即可
|
||||
- 🎨 **扩展插件** - 可插拔式的插件机制,支付、短信等功能可通过后台动态安装卸载
|
||||
- 📦 **代码简洁** - 不同于一般代码生成器生成冗余代码,只需极少编码即可实现大部分需求
|
||||
- 🚀 **微服务支持** - 基于 Moleculer 的微服务架构,支持分布式部署
|
||||
13
rpc/README.md
Normal file
13
rpc/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Cool Admin Node
|
||||
|
||||
cool-admin一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发CRUD,方便快速构建迭代后台管理系统,支持serverless、docker、普通服务器等多种方式部署 到 官网 进一步了解。
|
||||
|
||||
[https://cool-js.com](https://cool-js.com)
|
||||
|
||||
## 特性
|
||||
|
||||
- 🔥 **AI 编码** - 从页面到后端代码,部分功能实现零代码
|
||||
- 🎯 **Ai 流程编排** - 专门为 AI 开发设计,几乎无需编码,拖拽即可
|
||||
- 🎨 **扩展插件** - 可插拔式的插件机制,支付、短信等功能可通过后台动态安装卸载
|
||||
- 📦 **代码简洁** - 不同于一般代码生成器生成冗余代码,只需极少编码即可实现大部分需求
|
||||
- 🚀 **微服务支持** - 基于 Moleculer 的微服务架构,支持分布式部署
|
||||
13
task/README.md
Normal file
13
task/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Cool Admin Node
|
||||
|
||||
cool-admin一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发CRUD,方便快速构建迭代后台管理系统,支持serverless、docker、普通服务器等多种方式部署 到 官网 进一步了解。
|
||||
|
||||
[https://cool-js.com](https://cool-js.com)
|
||||
|
||||
## 特性
|
||||
|
||||
- 🔥 **AI 编码** - 从页面到后端代码,部分功能实现零代码
|
||||
- 🎯 **Ai 流程编排** - 专门为 AI 开发设计,几乎无需编码,拖拽即可
|
||||
- 🎨 **扩展插件** - 可插拔式的插件机制,支付、短信等功能可通过后台动态安装卸载
|
||||
- 📦 **代码简洁** - 不同于一般代码生成器生成冗余代码,只需极少编码即可实现大部分需求
|
||||
- 🚀 **微服务支持** - 基于 Moleculer 的微服务架构,支持分布式部署
|
||||
13
typeorm/README.md
Normal file
13
typeorm/README.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Cool Admin Node
|
||||
|
||||
cool-admin一个很酷的后台权限管理系统,开源免费,模块化、插件化、极速开发CRUD,方便快速构建迭代后台管理系统,支持serverless、docker、普通服务器等多种方式部署 到 官网 进一步了解。
|
||||
|
||||
[https://cool-js.com](https://cool-js.com)
|
||||
|
||||
## 特性
|
||||
|
||||
- 🔥 **AI 编码** - 从页面到后端代码,部分功能实现零代码
|
||||
- 🎯 **Ai 流程编排** - 专门为 AI 开发设计,几乎无需编码,拖拽即可
|
||||
- 🎨 **扩展插件** - 可插拔式的插件机制,支付、短信等功能可通过后台动态安装卸载
|
||||
- 📦 **代码简洁** - 不同于一般代码生成器生成冗余代码,只需极少编码即可实现大部分需求
|
||||
- 🚀 **微服务支持** - 基于 Moleculer 的微服务架构,支持分布式部署
|
||||
52
typeorm/browser/cache/DbQueryResultCache.d.ts
vendored
Normal file
52
typeorm/browser/cache/DbQueryResultCache.d.ts
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { QueryRunner } from "../query-runner/QueryRunner";
|
||||
import { QueryResultCache } from "./QueryResultCache";
|
||||
import { QueryResultCacheOptions } from "./QueryResultCacheOptions";
|
||||
/**
|
||||
* Caches query result into current database, into separate table called "query-result-cache".
|
||||
*/
|
||||
export declare class DbQueryResultCache implements QueryResultCache {
|
||||
protected connection: DataSource;
|
||||
private queryResultCacheTable;
|
||||
private queryResultCacheDatabase?;
|
||||
private queryResultCacheSchema?;
|
||||
constructor(connection: DataSource);
|
||||
/**
|
||||
* Creates a connection with given cache provider.
|
||||
*/
|
||||
connect(): Promise<void>;
|
||||
/**
|
||||
* Disconnects with given cache provider.
|
||||
*/
|
||||
disconnect(): Promise<void>;
|
||||
/**
|
||||
* Creates table for storing cache if it does not exist yet.
|
||||
*/
|
||||
synchronize(queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Get data from cache.
|
||||
* Returns cache result if found.
|
||||
* Returns undefined if result is not cached.
|
||||
*/
|
||||
getFromCache(options: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise<QueryResultCacheOptions | undefined>;
|
||||
/**
|
||||
* Checks if cache is expired or not.
|
||||
*/
|
||||
isExpired(savedCache: QueryResultCacheOptions): boolean;
|
||||
/**
|
||||
* Stores given query result in the cache.
|
||||
*/
|
||||
storeInCache(options: QueryResultCacheOptions, savedCache: QueryResultCacheOptions | undefined, queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Clears everything stored in the cache.
|
||||
*/
|
||||
clear(queryRunner: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Removes all cached results by given identifiers from cache.
|
||||
*/
|
||||
remove(identifiers: string[], queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Gets a query runner to work with.
|
||||
*/
|
||||
protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner;
|
||||
}
|
||||
260
typeorm/browser/cache/DbQueryResultCache.js
vendored
Normal file
260
typeorm/browser/cache/DbQueryResultCache.js
vendored
Normal file
@ -0,0 +1,260 @@
|
||||
import { MssqlParameter } from "../driver/sqlserver/MssqlParameter";
|
||||
import { Table } from "../schema-builder/table/Table";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
/**
|
||||
* Caches query result into current database, into separate table called "query-result-cache".
|
||||
*/
|
||||
export class DbQueryResultCache {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
const { schema } = this.connection.driver.options;
|
||||
const database = this.connection.driver.database;
|
||||
const cacheOptions = typeof this.connection.options.cache === "object"
|
||||
? this.connection.options.cache
|
||||
: {};
|
||||
const cacheTableName = cacheOptions.tableName || "query-result-cache";
|
||||
this.queryResultCacheDatabase = database;
|
||||
this.queryResultCacheSchema = schema;
|
||||
this.queryResultCacheTable = this.connection.driver.buildTableName(cacheTableName, schema, database);
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Creates a connection with given cache provider.
|
||||
*/
|
||||
async connect() { }
|
||||
/**
|
||||
* Disconnects with given cache provider.
|
||||
*/
|
||||
async disconnect() { }
|
||||
/**
|
||||
* Creates table for storing cache if it does not exist yet.
|
||||
*/
|
||||
async synchronize(queryRunner) {
|
||||
queryRunner = this.getQueryRunner(queryRunner);
|
||||
const driver = this.connection.driver;
|
||||
const tableExist = await queryRunner.hasTable(this.queryResultCacheTable); // todo: table name should be configurable
|
||||
if (tableExist)
|
||||
return;
|
||||
await queryRunner.createTable(new Table({
|
||||
database: this.queryResultCacheDatabase,
|
||||
schema: this.queryResultCacheSchema,
|
||||
name: this.queryResultCacheTable,
|
||||
columns: [
|
||||
{
|
||||
name: "id",
|
||||
isPrimary: true,
|
||||
isNullable: false,
|
||||
type: driver.normalizeType({
|
||||
type: driver.mappedDataTypes.cacheId,
|
||||
}),
|
||||
generationStrategy: driver.options.type === "spanner"
|
||||
? "uuid"
|
||||
: "increment",
|
||||
isGenerated: true,
|
||||
},
|
||||
{
|
||||
name: "identifier",
|
||||
type: driver.normalizeType({
|
||||
type: driver.mappedDataTypes.cacheIdentifier,
|
||||
}),
|
||||
isNullable: true,
|
||||
},
|
||||
{
|
||||
name: "time",
|
||||
type: driver.normalizeType({
|
||||
type: driver.mappedDataTypes.cacheTime,
|
||||
}),
|
||||
isPrimary: false,
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "duration",
|
||||
type: driver.normalizeType({
|
||||
type: driver.mappedDataTypes.cacheDuration,
|
||||
}),
|
||||
isPrimary: false,
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "query",
|
||||
type: driver.normalizeType({
|
||||
type: driver.mappedDataTypes.cacheQuery,
|
||||
}),
|
||||
isPrimary: false,
|
||||
isNullable: false,
|
||||
},
|
||||
{
|
||||
name: "result",
|
||||
type: driver.normalizeType({
|
||||
type: driver.mappedDataTypes.cacheResult,
|
||||
}),
|
||||
isNullable: false,
|
||||
},
|
||||
],
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Get data from cache.
|
||||
* Returns cache result if found.
|
||||
* Returns undefined if result is not cached.
|
||||
*/
|
||||
getFromCache(options, queryRunner) {
|
||||
queryRunner = this.getQueryRunner(queryRunner);
|
||||
const qb = this.connection
|
||||
.createQueryBuilder(queryRunner)
|
||||
.select()
|
||||
.from(this.queryResultCacheTable, "cache");
|
||||
if (options.identifier) {
|
||||
return qb
|
||||
.where(`${qb.escape("cache")}.${qb.escape("identifier")} = :identifier`)
|
||||
.setParameters({
|
||||
identifier: this.connection.driver.options.type === "mssql"
|
||||
? new MssqlParameter(options.identifier, "nvarchar")
|
||||
: options.identifier,
|
||||
})
|
||||
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
||||
.getRawOne();
|
||||
}
|
||||
else if (options.query) {
|
||||
if (this.connection.driver.options.type === "oracle") {
|
||||
return qb
|
||||
.where(`dbms_lob.compare(${qb.escape("cache")}.${qb.escape("query")}, :query) = 0`, { query: options.query })
|
||||
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
||||
.getRawOne();
|
||||
}
|
||||
return qb
|
||||
.where(`${qb.escape("cache")}.${qb.escape("query")} = :query`)
|
||||
.setParameters({
|
||||
query: this.connection.driver.options.type === "mssql"
|
||||
? new MssqlParameter(options.query, "nvarchar")
|
||||
: options.query,
|
||||
})
|
||||
.cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
|
||||
.getRawOne();
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
/**
|
||||
* Checks if cache is expired or not.
|
||||
*/
|
||||
isExpired(savedCache) {
|
||||
const duration = typeof savedCache.duration === "string"
|
||||
? parseInt(savedCache.duration)
|
||||
: savedCache.duration;
|
||||
return ((typeof savedCache.time === "string"
|
||||
? parseInt(savedCache.time)
|
||||
: savedCache.time) +
|
||||
duration <
|
||||
new Date().getTime());
|
||||
}
|
||||
/**
|
||||
* Stores given query result in the cache.
|
||||
*/
|
||||
async storeInCache(options, savedCache, queryRunner) {
|
||||
const shouldCreateQueryRunner = queryRunner === undefined ||
|
||||
queryRunner?.getReplicationMode() === "slave";
|
||||
if (queryRunner === undefined || shouldCreateQueryRunner) {
|
||||
queryRunner = this.connection.createQueryRunner("master");
|
||||
}
|
||||
let insertedValues = options;
|
||||
if (this.connection.driver.options.type === "mssql") {
|
||||
// todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table
|
||||
insertedValues = {
|
||||
identifier: new MssqlParameter(options.identifier, "nvarchar"),
|
||||
time: new MssqlParameter(options.time, "bigint"),
|
||||
duration: new MssqlParameter(options.duration, "int"),
|
||||
query: new MssqlParameter(options.query, "nvarchar"),
|
||||
result: new MssqlParameter(options.result, "nvarchar"),
|
||||
};
|
||||
}
|
||||
if (savedCache && savedCache.identifier) {
|
||||
// if exist then update
|
||||
const qb = queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.update(this.queryResultCacheTable)
|
||||
.set(insertedValues);
|
||||
qb.where(`${qb.escape("identifier")} = :condition`, {
|
||||
condition: insertedValues.identifier,
|
||||
});
|
||||
await qb.execute();
|
||||
}
|
||||
else if (savedCache && savedCache.query) {
|
||||
// if exist then update
|
||||
const qb = queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.update(this.queryResultCacheTable)
|
||||
.set(insertedValues);
|
||||
if (this.connection.driver.options.type === "oracle") {
|
||||
qb.where(`dbms_lob.compare("query", :condition) = 0`, {
|
||||
condition: insertedValues.query,
|
||||
});
|
||||
}
|
||||
else {
|
||||
qb.where(`${qb.escape("query")} = :condition`, {
|
||||
condition: insertedValues.query,
|
||||
});
|
||||
}
|
||||
await qb.execute();
|
||||
}
|
||||
else {
|
||||
// Spanner does not support auto-generated columns
|
||||
if (this.connection.driver.options.type === "spanner" &&
|
||||
!insertedValues.id) {
|
||||
insertedValues.id = uuidv4();
|
||||
}
|
||||
// otherwise insert
|
||||
await queryRunner.manager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(this.queryResultCacheTable)
|
||||
.values(insertedValues)
|
||||
.execute();
|
||||
}
|
||||
if (shouldCreateQueryRunner) {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clears everything stored in the cache.
|
||||
*/
|
||||
async clear(queryRunner) {
|
||||
return this.getQueryRunner(queryRunner).clearTable(this.queryResultCacheTable);
|
||||
}
|
||||
/**
|
||||
* Removes all cached results by given identifiers from cache.
|
||||
*/
|
||||
async remove(identifiers, queryRunner) {
|
||||
let _queryRunner = queryRunner || this.getQueryRunner();
|
||||
await Promise.all(identifiers.map((identifier) => {
|
||||
const qb = _queryRunner.manager.createQueryBuilder();
|
||||
return qb
|
||||
.delete()
|
||||
.from(this.queryResultCacheTable)
|
||||
.where(`${qb.escape("identifier")} = :identifier`, {
|
||||
identifier,
|
||||
})
|
||||
.execute();
|
||||
}));
|
||||
if (!queryRunner) {
|
||||
await _queryRunner.release();
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Gets a query runner to work with.
|
||||
*/
|
||||
getQueryRunner(queryRunner) {
|
||||
if (queryRunner)
|
||||
return queryRunner;
|
||||
return this.connection.createQueryRunner();
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=DbQueryResultCache.js.map
|
||||
1
typeorm/browser/cache/DbQueryResultCache.js.map
vendored
Normal file
1
typeorm/browser/cache/DbQueryResultCache.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
39
typeorm/browser/cache/QueryResultCache.d.ts
vendored
Normal file
39
typeorm/browser/cache/QueryResultCache.d.ts
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
import { QueryResultCacheOptions } from "./QueryResultCacheOptions";
|
||||
import { QueryRunner } from "../query-runner/QueryRunner";
|
||||
/**
|
||||
* Implementations of this interface provide different strategies to cache query builder results.
|
||||
*/
|
||||
export interface QueryResultCache {
|
||||
/**
|
||||
* Creates a connection with given cache provider.
|
||||
*/
|
||||
connect(): Promise<void>;
|
||||
/**
|
||||
* Closes a connection with given cache provider.
|
||||
*/
|
||||
disconnect(): Promise<void>;
|
||||
/**
|
||||
* Performs operations needs to be created during schema synchronization.
|
||||
*/
|
||||
synchronize(queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Caches given query result.
|
||||
*/
|
||||
getFromCache(options: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise<QueryResultCacheOptions | undefined>;
|
||||
/**
|
||||
* Stores given query result in the cache.
|
||||
*/
|
||||
storeInCache(options: QueryResultCacheOptions, savedCache: QueryResultCacheOptions | undefined, queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Checks if cache is expired or not.
|
||||
*/
|
||||
isExpired(savedCache: QueryResultCacheOptions): boolean;
|
||||
/**
|
||||
* Clears everything stored in the cache.
|
||||
*/
|
||||
clear(queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Removes all cached results by given identifiers from cache.
|
||||
*/
|
||||
remove(identifiers: string[], queryRunner?: QueryRunner): Promise<void>;
|
||||
}
|
||||
3
typeorm/browser/cache/QueryResultCache.js
vendored
Normal file
3
typeorm/browser/cache/QueryResultCache.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=QueryResultCache.js.map
|
||||
1
typeorm/browser/cache/QueryResultCache.js.map
vendored
Normal file
1
typeorm/browser/cache/QueryResultCache.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/cache/QueryResultCache.ts"],"names":[],"mappings":"","file":"QueryResultCache.js","sourcesContent":["import { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\n\n/**\n * Implementations of this interface provide different strategies to cache query builder results.\n */\nexport interface QueryResultCache {\n /**\n * Creates a connection with given cache provider.\n */\n connect(): Promise<void>\n\n /**\n * Closes a connection with given cache provider.\n */\n disconnect(): Promise<void>\n\n /**\n * Performs operations needs to be created during schema synchronization.\n */\n synchronize(queryRunner?: QueryRunner): Promise<void>\n\n /**\n * Caches given query result.\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined>\n\n /**\n * Stores given query result in the cache.\n */\n storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void>\n\n /**\n * Checks if cache is expired or not.\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean\n\n /**\n * Clears everything stored in the cache.\n */\n clear(queryRunner?: QueryRunner): Promise<void>\n\n /**\n * Removes all cached results by given identifiers from cache.\n */\n remove(identifiers: string[], queryRunner?: QueryRunner): Promise<void>\n}\n"],"sourceRoot":".."}
|
||||
13
typeorm/browser/cache/QueryResultCacheFactory.d.ts
vendored
Normal file
13
typeorm/browser/cache/QueryResultCacheFactory.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { QueryResultCache } from "./QueryResultCache";
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
/**
|
||||
* Caches query result into Redis database.
|
||||
*/
|
||||
export declare class QueryResultCacheFactory {
|
||||
protected connection: DataSource;
|
||||
constructor(connection: DataSource);
|
||||
/**
|
||||
* Creates a new query result cache based on connection options.
|
||||
*/
|
||||
create(): QueryResultCache;
|
||||
}
|
||||
38
typeorm/browser/cache/QueryResultCacheFactory.js
vendored
Normal file
38
typeorm/browser/cache/QueryResultCacheFactory.js
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
import { RedisQueryResultCache } from "./RedisQueryResultCache";
|
||||
import { DbQueryResultCache } from "./DbQueryResultCache";
|
||||
import { TypeORMError } from "../error/TypeORMError";
|
||||
/**
|
||||
* Caches query result into Redis database.
|
||||
*/
|
||||
export class QueryResultCacheFactory {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Creates a new query result cache based on connection options.
|
||||
*/
|
||||
create() {
|
||||
if (!this.connection.options.cache)
|
||||
throw new TypeORMError(`To use cache you need to enable it in connection options by setting cache: true or providing some caching options. Example: { host: ..., username: ..., cache: true }`);
|
||||
const cache = this.connection.options.cache;
|
||||
if (cache.provider && typeof cache.provider === "function") {
|
||||
return cache.provider(this.connection);
|
||||
}
|
||||
if (cache.type === "redis" ||
|
||||
cache.type === "ioredis" ||
|
||||
cache.type === "ioredis/cluster") {
|
||||
return new RedisQueryResultCache(this.connection, cache.type);
|
||||
}
|
||||
else {
|
||||
return new DbQueryResultCache(this.connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=QueryResultCacheFactory.js.map
|
||||
1
typeorm/browser/cache/QueryResultCacheFactory.js.map
vendored
Normal file
1
typeorm/browser/cache/QueryResultCacheFactory.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/cache/QueryResultCacheFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpD;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAChC,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEhD,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,MAAM;QACF,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK;YAC9B,MAAM,IAAI,YAAY,CAClB,uKAAuK,CAC1K,CAAA;QAEL,MAAM,KAAK,GAAQ,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAA;QAEhD,IAAI,KAAK,CAAC,QAAQ,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAC1C,CAAC;QAED,IACI,KAAK,CAAC,IAAI,KAAK,OAAO;YACtB,KAAK,CAAC,IAAI,KAAK,SAAS;YACxB,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAClC,CAAC;YACC,OAAO,IAAI,qBAAqB,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;QACjE,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAClD,CAAC;IACL,CAAC;CACJ","file":"QueryResultCacheFactory.js","sourcesContent":["import { RedisQueryResultCache } from \"./RedisQueryResultCache\"\nimport { DbQueryResultCache } from \"./DbQueryResultCache\"\nimport { QueryResultCache } from \"./QueryResultCache\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { TypeORMError } from \"../error/TypeORMError\"\n\n/**\n * Caches query result into Redis database.\n */\nexport class QueryResultCacheFactory {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: DataSource) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a new query result cache based on connection options.\n */\n create(): QueryResultCache {\n if (!this.connection.options.cache)\n throw new TypeORMError(\n `To use cache you need to enable it in connection options by setting cache: true or providing some caching options. Example: { host: ..., username: ..., cache: true }`,\n )\n\n const cache: any = this.connection.options.cache\n\n if (cache.provider && typeof cache.provider === \"function\") {\n return cache.provider(this.connection)\n }\n\n if (\n cache.type === \"redis\" ||\n cache.type === \"ioredis\" ||\n cache.type === \"ioredis/cluster\"\n ) {\n return new RedisQueryResultCache(this.connection, cache.type)\n } else {\n return new DbQueryResultCache(this.connection)\n }\n }\n}\n"],"sourceRoot":".."}
|
||||
26
typeorm/browser/cache/QueryResultCacheOptions.d.ts
vendored
Normal file
26
typeorm/browser/cache/QueryResultCacheOptions.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Options passed to QueryResultCache class.
|
||||
*/
|
||||
export interface QueryResultCacheOptions {
|
||||
/**
|
||||
* Cache identifier set by user.
|
||||
* Can be empty.
|
||||
*/
|
||||
identifier?: string;
|
||||
/**
|
||||
* Time, when cache was created.
|
||||
*/
|
||||
time?: number;
|
||||
/**
|
||||
* Duration in milliseconds during which results will be returned from cache.
|
||||
*/
|
||||
duration: number;
|
||||
/**
|
||||
* Cached query.
|
||||
*/
|
||||
query?: string;
|
||||
/**
|
||||
* Query result that will be cached.
|
||||
*/
|
||||
result?: any;
|
||||
}
|
||||
3
typeorm/browser/cache/QueryResultCacheOptions.js
vendored
Normal file
3
typeorm/browser/cache/QueryResultCacheOptions.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=QueryResultCacheOptions.js.map
|
||||
1
typeorm/browser/cache/QueryResultCacheOptions.js.map
vendored
Normal file
1
typeorm/browser/cache/QueryResultCacheOptions.js.map
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/cache/QueryResultCacheOptions.ts"],"names":[],"mappings":"","file":"QueryResultCacheOptions.js","sourcesContent":["/**\n * Options passed to QueryResultCache class.\n */\nexport interface QueryResultCacheOptions {\n /**\n * Cache identifier set by user.\n * Can be empty.\n */\n identifier?: string\n\n /**\n * Time, when cache was created.\n */\n time?: number\n\n /**\n * Duration in milliseconds during which results will be returned from cache.\n */\n duration: number\n\n /**\n * Cached query.\n */\n query?: string\n\n /**\n * Query result that will be cached.\n */\n result?: any\n}\n"],"sourceRoot":".."}
|
||||
65
typeorm/browser/cache/RedisQueryResultCache.d.ts
vendored
Normal file
65
typeorm/browser/cache/RedisQueryResultCache.d.ts
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
import { QueryResultCache } from "./QueryResultCache";
|
||||
import { QueryResultCacheOptions } from "./QueryResultCacheOptions";
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { QueryRunner } from "../query-runner/QueryRunner";
|
||||
/**
|
||||
* Caches query result into Redis database.
|
||||
*/
|
||||
export declare class RedisQueryResultCache implements QueryResultCache {
|
||||
protected connection: DataSource;
|
||||
/**
|
||||
* Redis module instance loaded dynamically.
|
||||
*/
|
||||
protected redis: any;
|
||||
/**
|
||||
* Connected redis client.
|
||||
*/
|
||||
protected client: any;
|
||||
/**
|
||||
* Type of the Redis Client (redis or ioredis).
|
||||
*/
|
||||
protected clientType: "redis" | "ioredis" | "ioredis/cluster";
|
||||
constructor(connection: DataSource, clientType: "redis" | "ioredis" | "ioredis/cluster");
|
||||
/**
|
||||
* Creates a connection with given cache provider.
|
||||
*/
|
||||
connect(): Promise<void>;
|
||||
/**
|
||||
* Disconnects the connection
|
||||
*/
|
||||
disconnect(): Promise<void>;
|
||||
/**
|
||||
* Creates table for storing cache if it does not exist yet.
|
||||
*/
|
||||
synchronize(queryRunner: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Get data from cache.
|
||||
* Returns cache result if found.
|
||||
* Returns undefined if result is not cached.
|
||||
*/
|
||||
getFromCache(options: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise<QueryResultCacheOptions | undefined>;
|
||||
/**
|
||||
* Checks if cache is expired or not.
|
||||
*/
|
||||
isExpired(savedCache: QueryResultCacheOptions): boolean;
|
||||
/**
|
||||
* Stores given query result in the cache.
|
||||
*/
|
||||
storeInCache(options: QueryResultCacheOptions, savedCache: QueryResultCacheOptions, queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Clears everything stored in the cache.
|
||||
*/
|
||||
clear(queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Removes all cached results by given identifiers from cache.
|
||||
*/
|
||||
remove(identifiers: string[], queryRunner?: QueryRunner): Promise<void>;
|
||||
/**
|
||||
* Removes a single key from redis database.
|
||||
*/
|
||||
protected deleteKey(key: string): Promise<void>;
|
||||
/**
|
||||
* Loads redis dependency.
|
||||
*/
|
||||
protected loadRedis(): any;
|
||||
}
|
||||
193
typeorm/browser/cache/RedisQueryResultCache.js
vendored
Normal file
193
typeorm/browser/cache/RedisQueryResultCache.js
vendored
Normal file
@ -0,0 +1,193 @@
|
||||
import { PlatformTools } from "../platform/PlatformTools";
|
||||
import { TypeORMError } from "../error/TypeORMError";
|
||||
/**
|
||||
* Caches query result into Redis database.
|
||||
*/
|
||||
export class RedisQueryResultCache {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(connection, clientType) {
|
||||
this.connection = connection;
|
||||
this.clientType = clientType;
|
||||
this.redis = this.loadRedis();
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Creates a connection with given cache provider.
|
||||
*/
|
||||
async connect() {
|
||||
const cacheOptions = this.connection.options.cache;
|
||||
if (this.clientType === "redis") {
|
||||
this.client = this.redis.createClient({
|
||||
...cacheOptions?.options,
|
||||
legacyMode: true,
|
||||
});
|
||||
if (typeof this.connection.options.cache === "object" &&
|
||||
this.connection.options.cache.ignoreErrors) {
|
||||
this.client.on("error", (err) => {
|
||||
this.connection.logger.log("warn", err);
|
||||
});
|
||||
}
|
||||
if ("connect" in this.client) {
|
||||
await this.client.connect();
|
||||
}
|
||||
}
|
||||
else if (this.clientType === "ioredis") {
|
||||
if (cacheOptions && cacheOptions.port) {
|
||||
if (cacheOptions.options) {
|
||||
this.client = new this.redis(cacheOptions.port, cacheOptions.options);
|
||||
}
|
||||
else {
|
||||
this.client = new this.redis(cacheOptions.port);
|
||||
}
|
||||
}
|
||||
else if (cacheOptions && cacheOptions.options) {
|
||||
this.client = new this.redis(cacheOptions.options);
|
||||
}
|
||||
else {
|
||||
this.client = new this.redis();
|
||||
}
|
||||
}
|
||||
else if (this.clientType === "ioredis/cluster") {
|
||||
if (cacheOptions &&
|
||||
cacheOptions.options &&
|
||||
Array.isArray(cacheOptions.options)) {
|
||||
this.client = new this.redis.Cluster(cacheOptions.options);
|
||||
}
|
||||
else if (cacheOptions &&
|
||||
cacheOptions.options &&
|
||||
cacheOptions.options.startupNodes) {
|
||||
this.client = new this.redis.Cluster(cacheOptions.options.startupNodes, cacheOptions.options.options);
|
||||
}
|
||||
else {
|
||||
throw new TypeORMError(`options.startupNodes required for ${this.clientType}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Disconnects the connection
|
||||
*/
|
||||
async disconnect() {
|
||||
return new Promise((ok, fail) => {
|
||||
this.client.quit((err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok();
|
||||
this.client = undefined;
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Creates table for storing cache if it does not exist yet.
|
||||
*/
|
||||
async synchronize(queryRunner) { }
|
||||
/**
|
||||
* Get data from cache.
|
||||
* Returns cache result if found.
|
||||
* Returns undefined if result is not cached.
|
||||
*/
|
||||
getFromCache(options, queryRunner) {
|
||||
return new Promise((ok, fail) => {
|
||||
if (options.identifier) {
|
||||
this.client.get(options.identifier, (err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok(JSON.parse(result));
|
||||
});
|
||||
}
|
||||
else if (options.query) {
|
||||
this.client.get(options.query, (err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok(JSON.parse(result));
|
||||
});
|
||||
}
|
||||
else {
|
||||
ok(undefined);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Checks if cache is expired or not.
|
||||
*/
|
||||
isExpired(savedCache) {
|
||||
return savedCache.time + savedCache.duration < new Date().getTime();
|
||||
}
|
||||
/**
|
||||
* Stores given query result in the cache.
|
||||
*/
|
||||
async storeInCache(options, savedCache, queryRunner) {
|
||||
return new Promise((ok, fail) => {
|
||||
if (options.identifier) {
|
||||
this.client.set(options.identifier, JSON.stringify(options), "PX", options.duration, (err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok();
|
||||
});
|
||||
}
|
||||
else if (options.query) {
|
||||
this.client.set(options.query, JSON.stringify(options), "PX", options.duration, (err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Clears everything stored in the cache.
|
||||
*/
|
||||
async clear(queryRunner) {
|
||||
return new Promise((ok, fail) => {
|
||||
this.client.flushdb((err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Removes all cached results by given identifiers from cache.
|
||||
*/
|
||||
async remove(identifiers, queryRunner) {
|
||||
await Promise.all(identifiers.map((identifier) => {
|
||||
return this.deleteKey(identifier);
|
||||
}));
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Removes a single key from redis database.
|
||||
*/
|
||||
deleteKey(key) {
|
||||
return new Promise((ok, fail) => {
|
||||
this.client.del(key, (err, result) => {
|
||||
if (err)
|
||||
return fail(err);
|
||||
ok();
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Loads redis dependency.
|
||||
*/
|
||||
loadRedis() {
|
||||
try {
|
||||
if (this.clientType === "ioredis/cluster") {
|
||||
return PlatformTools.load("ioredis");
|
||||
}
|
||||
else {
|
||||
return PlatformTools.load(this.clientType);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
throw new TypeORMError(`Cannot use cache because ${this.clientType} is not installed. Please run "npm i ${this.clientType} --save".`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=RedisQueryResultCache.js.map
|
||||
1
typeorm/browser/cache/RedisQueryResultCache.js.map
vendored
Normal file
1
typeorm/browser/cache/RedisQueryResultCache.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
2
typeorm/browser/cli-ts-node-commonjs.d.ts
vendored
Normal file
2
typeorm/browser/cli-ts-node-commonjs.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
import "./cli";
|
||||
5
typeorm/browser/cli-ts-node-commonjs.js
Executable file
5
typeorm/browser/cli-ts-node-commonjs.js
Executable file
@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
require("ts-node").register();
|
||||
import "./cli";
|
||||
|
||||
//# sourceMappingURL=cli-ts-node-commonjs.js.map
|
||||
1
typeorm/browser/cli-ts-node-commonjs.js.map
Normal file
1
typeorm/browser/cli-ts-node-commonjs.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/cli-ts-node-commonjs.ts"],"names":[],"mappings":";AACA,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAA;AAC7B,OAAO,OAAO,CAAA","file":"cli-ts-node-commonjs.js","sourcesContent":["#!/usr/bin/env node\nrequire(\"ts-node\").register()\nimport \"./cli\"\n"],"sourceRoot":"."}
|
||||
2
typeorm/browser/cli-ts-node-esm.d.ts
vendored
Normal file
2
typeorm/browser/cli-ts-node-esm.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env node
|
||||
export {};
|
||||
23
typeorm/browser/cli-ts-node-esm.js
Executable file
23
typeorm/browser/cli-ts-node-esm.js
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawnSync } from "child_process";
|
||||
if ((process.env["NODE_OPTIONS"] || "").includes("--loader ts-node"))
|
||||
require("./cli");
|
||||
else {
|
||||
const childProcess = spawnSync(process.argv[0], process.argv.slice(1), {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_OPTIONS: [
|
||||
process.env["NODE_OPTIONS"],
|
||||
"--loader ts-node/esm",
|
||||
"--no-warnings",
|
||||
]
|
||||
.filter((item) => !!item)
|
||||
.join(" "),
|
||||
},
|
||||
windowsHide: true,
|
||||
});
|
||||
process.exit(childProcess.status || 0);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=cli-ts-node-esm.js.map
|
||||
1
typeorm/browser/cli-ts-node-esm.js.map
Normal file
1
typeorm/browser/cli-ts-node-esm.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/cli-ts-node-esm.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IAChE,OAAO,CAAC,OAAO,CAAC,CAAA;KACf,CAAC;IACF,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACnE,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE;YACD,GAAG,OAAO,CAAC,GAAG;YACd,YAAY,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;gBAC3B,sBAAsB;gBACtB,eAAe;aAClB;iBACI,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBACxB,IAAI,CAAC,GAAG,CAAC;SACjB;QACD,WAAW,EAAE,IAAI;KACpB,CAAC,CAAA;IAEF,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,CAAC,CAAA;AAC1C,CAAC","file":"cli-ts-node-esm.js","sourcesContent":["#!/usr/bin/env node\nimport { spawnSync } from \"child_process\"\n\nif ((process.env[\"NODE_OPTIONS\"] || \"\").includes(\"--loader ts-node\"))\n require(\"./cli\")\nelse {\n const childProcess = spawnSync(process.argv[0], process.argv.slice(1), {\n stdio: \"inherit\",\n env: {\n ...process.env,\n NODE_OPTIONS: [\n process.env[\"NODE_OPTIONS\"],\n \"--loader ts-node/esm\",\n \"--no-warnings\",\n ]\n .filter((item) => !!item)\n .join(\" \"),\n },\n windowsHide: true,\n })\n\n process.exit(childProcess.status || 0)\n}\n"],"sourceRoot":"."}
|
||||
6
typeorm/browser/common/DeepPartial.d.ts
vendored
Normal file
6
typeorm/browser/common/DeepPartial.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.
|
||||
*/
|
||||
export type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
||||
[K in keyof T]?: DeepPartial<T[K]>;
|
||||
} : T);
|
||||
3
typeorm/browser/common/DeepPartial.js
Normal file
3
typeorm/browser/common/DeepPartial.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=DeepPartial.js.map
|
||||
1
typeorm/browser/common/DeepPartial.js.map
Normal file
1
typeorm/browser/common/DeepPartial.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/DeepPartial.ts"],"names":[],"mappings":"","file":"DeepPartial.js","sourcesContent":["/**\n * Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.\n */\nexport type DeepPartial<T> =\n | T\n | (T extends Array<infer U>\n ? DeepPartial<U>[]\n : T extends Map<infer K, infer V>\n ? Map<DeepPartial<K>, DeepPartial<V>>\n : T extends Set<infer M>\n ? Set<DeepPartial<M>>\n : T extends object\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T)\n"],"sourceRoot":".."}
|
||||
9
typeorm/browser/common/EntityTarget.d.ts
vendored
Normal file
9
typeorm/browser/common/EntityTarget.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { ObjectType } from "./ObjectType";
|
||||
import { EntitySchema } from "..";
|
||||
/**
|
||||
* Entity target.
|
||||
*/
|
||||
export type EntityTarget<Entity> = ObjectType<Entity> | EntitySchema<Entity> | string | {
|
||||
type: Entity;
|
||||
name: string;
|
||||
};
|
||||
3
typeorm/browser/common/EntityTarget.js
Normal file
3
typeorm/browser/common/EntityTarget.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=EntityTarget.js.map
|
||||
1
typeorm/browser/common/EntityTarget.js.map
Normal file
1
typeorm/browser/common/EntityTarget.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/EntityTarget.ts"],"names":[],"mappings":"","file":"EntityTarget.js","sourcesContent":["import { ObjectType } from \"./ObjectType\"\nimport { EntitySchema } from \"..\"\n\n/**\n * Entity target.\n */\nexport type EntityTarget<Entity> =\n | ObjectType<Entity>\n | EntitySchema<Entity>\n | string\n | { type: Entity; name: string }\n"],"sourceRoot":".."}
|
||||
8
typeorm/browser/common/MixedList.d.ts
vendored
Normal file
8
typeorm/browser/common/MixedList.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* List of T-s passed as an array or object map.
|
||||
*
|
||||
* Example usage: entities as an array of imported using import * as syntax.
|
||||
*/
|
||||
export type MixedList<T> = T[] | {
|
||||
[key: string]: T;
|
||||
};
|
||||
3
typeorm/browser/common/MixedList.js
Normal file
3
typeorm/browser/common/MixedList.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=MixedList.js.map
|
||||
1
typeorm/browser/common/MixedList.js.map
Normal file
1
typeorm/browser/common/MixedList.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/MixedList.ts"],"names":[],"mappings":"","file":"MixedList.js","sourcesContent":["/**\n * List of T-s passed as an array or object map.\n *\n * Example usage: entities as an array of imported using import * as syntax.\n */\nexport type MixedList<T> = T[] | { [key: string]: T }\n"],"sourceRoot":".."}
|
||||
6
typeorm/browser/common/NonNever.d.ts
vendored
Normal file
6
typeorm/browser/common/NonNever.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Remove keys with `never` value from object type
|
||||
* */
|
||||
export type NonNever<T extends {}> = Pick<T, {
|
||||
[K in keyof T]: T[K] extends never ? never : K;
|
||||
}[keyof T]>;
|
||||
3
typeorm/browser/common/NonNever.js
Normal file
3
typeorm/browser/common/NonNever.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=NonNever.js.map
|
||||
1
typeorm/browser/common/NonNever.js.map
Normal file
1
typeorm/browser/common/NonNever.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/NonNever.ts"],"names":[],"mappings":"","file":"NonNever.js","sourcesContent":["/**\n * Remove keys with `never` value from object type\n * */\nexport type NonNever<T extends {}> = Pick<\n T,\n { [K in keyof T]: T[K] extends never ? never : K }[keyof T]\n>\n"],"sourceRoot":".."}
|
||||
6
typeorm/browser/common/ObjectLiteral.d.ts
vendored
Normal file
6
typeorm/browser/common/ObjectLiteral.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Interface of the simple literal object with any string keys.
|
||||
*/
|
||||
export interface ObjectLiteral {
|
||||
[key: string]: any;
|
||||
}
|
||||
3
typeorm/browser/common/ObjectLiteral.js
Normal file
3
typeorm/browser/common/ObjectLiteral.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=ObjectLiteral.js.map
|
||||
1
typeorm/browser/common/ObjectLiteral.js.map
Normal file
1
typeorm/browser/common/ObjectLiteral.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/ObjectLiteral.ts"],"names":[],"mappings":"","file":"ObjectLiteral.js","sourcesContent":["/**\n * Interface of the simple literal object with any string keys.\n */\nexport interface ObjectLiteral {\n [key: string]: any\n}\n"],"sourceRoot":".."}
|
||||
6
typeorm/browser/common/ObjectType.d.ts
vendored
Normal file
6
typeorm/browser/common/ObjectType.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Represents some Type of the Object.
|
||||
*/
|
||||
export type ObjectType<T> = {
|
||||
new (): T;
|
||||
} | Function;
|
||||
3
typeorm/browser/common/ObjectType.js
Normal file
3
typeorm/browser/common/ObjectType.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=ObjectType.js.map
|
||||
1
typeorm/browser/common/ObjectType.js.map
Normal file
1
typeorm/browser/common/ObjectType.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/ObjectType.ts"],"names":[],"mappings":"","file":"ObjectType.js","sourcesContent":["/**\n * Represents some Type of the Object.\n */\nexport type ObjectType<T> = { new (): T } | Function\n"],"sourceRoot":".."}
|
||||
6
typeorm/browser/common/PickKeysByType.d.ts
vendored
Normal file
6
typeorm/browser/common/PickKeysByType.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Pick only the keys that match the Type `U`
|
||||
*/
|
||||
export type PickKeysByType<T, U> = string & keyof {
|
||||
[P in keyof T as T[P] extends U ? P : never]: T[P];
|
||||
};
|
||||
3
typeorm/browser/common/PickKeysByType.js
Normal file
3
typeorm/browser/common/PickKeysByType.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=PickKeysByType.js.map
|
||||
1
typeorm/browser/common/PickKeysByType.js.map
Normal file
1
typeorm/browser/common/PickKeysByType.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/PickKeysByType.ts"],"names":[],"mappings":"","file":"PickKeysByType.js","sourcesContent":["/**\n * Pick only the keys that match the Type `U`\n */\nexport type PickKeysByType<T, U> = string &\n keyof {\n [P in keyof T as T[P] extends U ? P : never]: T[P]\n }\n"],"sourceRoot":".."}
|
||||
14
typeorm/browser/common/RelationType.d.ts
vendored
Normal file
14
typeorm/browser/common/RelationType.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Wrapper type for relation type definitions in entities.
|
||||
* Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.
|
||||
*
|
||||
* Usage example:
|
||||
* @Entity()
|
||||
* export default class User {
|
||||
*
|
||||
* @OneToOne(() => Profile, profile => profile.user)
|
||||
* profile: Relation<Profile>;
|
||||
*
|
||||
* }
|
||||
*/
|
||||
export type Relation<T> = T;
|
||||
3
typeorm/browser/common/RelationType.js
Normal file
3
typeorm/browser/common/RelationType.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=RelationType.js.map
|
||||
1
typeorm/browser/common/RelationType.js.map
Normal file
1
typeorm/browser/common/RelationType.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/common/RelationType.ts"],"names":[],"mappings":"","file":"RelationType.js","sourcesContent":["/**\n * Wrapper type for relation type definitions in entities.\n * Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.\n *\n * Usage example:\n * @Entity()\n * export default class User {\n *\n * @OneToOne(() => Profile, profile => profile.user)\n * profile: Relation<Profile>;\n *\n * }\n */\nexport type Relation<T> = T\n"],"sourceRoot":".."}
|
||||
7
typeorm/browser/connection/BaseConnectionOptions.d.ts
vendored
Normal file
7
typeorm/browser/connection/BaseConnectionOptions.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { BaseDataSourceOptions } from "../data-source/BaseDataSourceOptions";
|
||||
/**
|
||||
* BaseConnectionOptions is set of connection options shared by all database types.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export type BaseConnectionOptions = BaseDataSourceOptions;
|
||||
3
typeorm/browser/connection/BaseConnectionOptions.js
Normal file
3
typeorm/browser/connection/BaseConnectionOptions.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=BaseConnectionOptions.js.map
|
||||
1
typeorm/browser/connection/BaseConnectionOptions.js.map
Normal file
1
typeorm/browser/connection/BaseConnectionOptions.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../data-source/BaseDataSourceOptions\"\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n *\n * @deprecated\n */\nexport type BaseConnectionOptions = BaseDataSourceOptions\n"],"sourceRoot":".."}
|
||||
10
typeorm/browser/connection/Connection.d.ts
vendored
Normal file
10
typeorm/browser/connection/Connection.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
/**
|
||||
* Connection is a single database ORM connection to a specific database.
|
||||
* Its not required to be a database connection, depend on database type it can create connection pool.
|
||||
* You can have multiple connections to multiple databases in your application.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare class Connection extends DataSource {
|
||||
}
|
||||
12
typeorm/browser/connection/Connection.js
Normal file
12
typeorm/browser/connection/Connection.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
/**
|
||||
* Connection is a single database ORM connection to a specific database.
|
||||
* Its not required to be a database connection, depend on database type it can create connection pool.
|
||||
* You can have multiple connections to multiple databases in your application.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export class Connection extends DataSource {
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Connection.js.map
|
||||
1
typeorm/browser/connection/Connection.js.map
Normal file
1
typeorm/browser/connection/Connection.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/connection/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;CAAG","file":"Connection.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\n\n/**\n * Connection is a single database ORM connection to a specific database.\n * Its not required to be a database connection, depend on database type it can create connection pool.\n * You can have multiple connections to multiple databases in your application.\n *\n * @deprecated\n */\nexport class Connection extends DataSource {}\n"],"sourceRoot":".."}
|
||||
33
typeorm/browser/connection/ConnectionManager.d.ts
vendored
Normal file
33
typeorm/browser/connection/ConnectionManager.d.ts
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
||||
/**
|
||||
* ConnectionManager is used to store and manage multiple orm connections.
|
||||
* It also provides useful factory methods to simplify connection creation.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare class ConnectionManager {
|
||||
/**
|
||||
* List of connections registered in this connection manager.
|
||||
*/
|
||||
get connections(): DataSource[];
|
||||
/**
|
||||
* Internal lookup to quickly get from a connection name to the Connection object.
|
||||
*/
|
||||
private readonly connectionMap;
|
||||
/**
|
||||
* Checks if connection with the given name exist in the manager.
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
/**
|
||||
* Gets registered connection with the given name.
|
||||
* If connection name is not given then it will get a default connection.
|
||||
* Throws error if connection with the given name was not found.
|
||||
*/
|
||||
get(name?: string): DataSource;
|
||||
/**
|
||||
* Creates a new connection based on the given connection options and registers it in the manager.
|
||||
* Connection won't be established, you'll need to manually call connect method to establish connection.
|
||||
*/
|
||||
create(options: DataSourceOptions): DataSource;
|
||||
}
|
||||
62
typeorm/browser/connection/ConnectionManager.js
Normal file
62
typeorm/browser/connection/ConnectionManager.js
Normal file
@ -0,0 +1,62 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { ConnectionNotFoundError } from "../error/ConnectionNotFoundError";
|
||||
import { AlreadyHasActiveConnectionError } from "../error/AlreadyHasActiveConnectionError";
|
||||
/**
|
||||
* ConnectionManager is used to store and manage multiple orm connections.
|
||||
* It also provides useful factory methods to simplify connection creation.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export class ConnectionManager {
|
||||
constructor() {
|
||||
/**
|
||||
* Internal lookup to quickly get from a connection name to the Connection object.
|
||||
*/
|
||||
this.connectionMap = new Map();
|
||||
}
|
||||
/**
|
||||
* List of connections registered in this connection manager.
|
||||
*/
|
||||
get connections() {
|
||||
return Array.from(this.connectionMap.values());
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Checks if connection with the given name exist in the manager.
|
||||
*/
|
||||
has(name) {
|
||||
return this.connectionMap.has(name);
|
||||
}
|
||||
/**
|
||||
* Gets registered connection with the given name.
|
||||
* If connection name is not given then it will get a default connection.
|
||||
* Throws error if connection with the given name was not found.
|
||||
*/
|
||||
get(name = "default") {
|
||||
const connection = this.connectionMap.get(name);
|
||||
if (!connection)
|
||||
throw new ConnectionNotFoundError(name);
|
||||
return connection;
|
||||
}
|
||||
/**
|
||||
* Creates a new connection based on the given connection options and registers it in the manager.
|
||||
* Connection won't be established, you'll need to manually call connect method to establish connection.
|
||||
*/
|
||||
create(options) {
|
||||
// check if such connection is already registered
|
||||
const existConnection = this.connectionMap.get(options.name || "default");
|
||||
if (existConnection) {
|
||||
// if connection is registered and its not closed then throw an error
|
||||
if (existConnection.isInitialized)
|
||||
throw new AlreadyHasActiveConnectionError(options.name || "default");
|
||||
}
|
||||
// create a new connection
|
||||
const connection = new DataSource(options);
|
||||
this.connectionMap.set(connection.name, connection);
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionManager.js.map
|
||||
1
typeorm/browser/connection/ConnectionManager.js.map
Normal file
1
typeorm/browser/connection/ConnectionManager.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/connection/ConnectionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAE1E,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAA;AAE1F;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QAQI;;WAEG;QACc,kBAAa,GAA4B,IAAI,GAAG,EAAE,CAAA;IA+CvE,CAAC;IAzDG;;OAEG;IACH,IAAI,WAAW;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;IAClD,CAAC;IAOD,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,GAAG,CAAC,IAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,OAAe,SAAS;QACxB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC/C,IAAI,CAAC,UAAU;YAAE,MAAM,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAExD,OAAO,UAAU,CAAA;IACrB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAA0B;QAC7B,iDAAiD;QACjD,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAC1C,OAAO,CAAC,IAAI,IAAI,SAAS,CAC5B,CAAA;QACD,IAAI,eAAe,EAAE,CAAC;YAClB,qEAAqE;YACrE,IAAI,eAAe,CAAC,aAAa;gBAC7B,MAAM,IAAI,+BAA+B,CACrC,OAAO,CAAC,IAAI,IAAI,SAAS,CAC5B,CAAA;QACT,CAAC;QAED,0BAA0B;QAC1B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QACnD,OAAO,UAAU,CAAA;IACrB,CAAC;CACJ","file":"ConnectionManager.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport { ConnectionNotFoundError } from \"../error/ConnectionNotFoundError\"\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { AlreadyHasActiveConnectionError } from \"../error/AlreadyHasActiveConnectionError\"\n\n/**\n * ConnectionManager is used to store and manage multiple orm connections.\n * It also provides useful factory methods to simplify connection creation.\n *\n * @deprecated\n */\nexport class ConnectionManager {\n /**\n * List of connections registered in this connection manager.\n */\n get connections(): DataSource[] {\n return Array.from(this.connectionMap.values())\n }\n\n /**\n * Internal lookup to quickly get from a connection name to the Connection object.\n */\n private readonly connectionMap: Map<string, DataSource> = new Map()\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if connection with the given name exist in the manager.\n */\n has(name: string): boolean {\n return this.connectionMap.has(name)\n }\n\n /**\n * Gets registered connection with the given name.\n * If connection name is not given then it will get a default connection.\n * Throws error if connection with the given name was not found.\n */\n get(name: string = \"default\"): DataSource {\n const connection = this.connectionMap.get(name)\n if (!connection) throw new ConnectionNotFoundError(name)\n\n return connection\n }\n\n /**\n * Creates a new connection based on the given connection options and registers it in the manager.\n * Connection won't be established, you'll need to manually call connect method to establish connection.\n */\n create(options: DataSourceOptions): DataSource {\n // check if such connection is already registered\n const existConnection = this.connectionMap.get(\n options.name || \"default\",\n )\n if (existConnection) {\n // if connection is registered and its not closed then throw an error\n if (existConnection.isInitialized)\n throw new AlreadyHasActiveConnectionError(\n options.name || \"default\",\n )\n }\n\n // create a new connection\n const connection = new DataSource(options)\n this.connectionMap.set(connection.name, connection)\n return connection\n }\n}\n"],"sourceRoot":".."}
|
||||
24
typeorm/browser/connection/ConnectionMetadataBuilder.d.ts
vendored
Normal file
24
typeorm/browser/connection/ConnectionMetadataBuilder.d.ts
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import { MigrationInterface } from "../migration/MigrationInterface";
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { EntitySchema } from "../entity-schema/EntitySchema";
|
||||
import { EntityMetadata } from "../metadata/EntityMetadata";
|
||||
import { EntitySubscriberInterface } from "../subscriber/EntitySubscriberInterface";
|
||||
/**
|
||||
* Builds migration instances, subscriber instances and entity metadatas for the given classes.
|
||||
*/
|
||||
export declare class ConnectionMetadataBuilder {
|
||||
protected connection: DataSource;
|
||||
constructor(connection: DataSource);
|
||||
/**
|
||||
* Builds migration instances for the given classes or directories.
|
||||
*/
|
||||
buildMigrations(migrations: (Function | string)[]): Promise<MigrationInterface[]>;
|
||||
/**
|
||||
* Builds subscriber instances for the given classes or directories.
|
||||
*/
|
||||
buildSubscribers(subscribers: (Function | string)[]): Promise<EntitySubscriberInterface<any>[]>;
|
||||
/**
|
||||
* Builds entity metadatas for the given classes or directories.
|
||||
*/
|
||||
buildEntityMetadatas(entities: (Function | EntitySchema<any> | string)[]): Promise<EntityMetadata[]>;
|
||||
}
|
||||
70
typeorm/browser/connection/ConnectionMetadataBuilder.js
Normal file
70
typeorm/browser/connection/ConnectionMetadataBuilder.js
Normal file
@ -0,0 +1,70 @@
|
||||
import { importClassesFromDirectories } from "../util/DirectoryExportedClassesLoader";
|
||||
import { OrmUtils } from "../util/OrmUtils";
|
||||
import { getFromContainer } from "../container";
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { EntityMetadataBuilder } from "../metadata-builder/EntityMetadataBuilder";
|
||||
import { EntitySchemaTransformer } from "../entity-schema/EntitySchemaTransformer";
|
||||
import { InstanceChecker } from "../util/InstanceChecker";
|
||||
/**
|
||||
* Builds migration instances, subscriber instances and entity metadatas for the given classes.
|
||||
*/
|
||||
export class ConnectionMetadataBuilder {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Builds migration instances for the given classes or directories.
|
||||
*/
|
||||
async buildMigrations(migrations) {
|
||||
const [migrationClasses, migrationDirectories] = OrmUtils.splitClassesAndStrings(migrations);
|
||||
const allMigrationClasses = [
|
||||
...migrationClasses,
|
||||
...(await importClassesFromDirectories(this.connection.logger, migrationDirectories)),
|
||||
];
|
||||
return allMigrationClasses.map((migrationClass) => getFromContainer(migrationClass));
|
||||
}
|
||||
/**
|
||||
* Builds subscriber instances for the given classes or directories.
|
||||
*/
|
||||
async buildSubscribers(subscribers) {
|
||||
const [subscriberClasses, subscriberDirectories] = OrmUtils.splitClassesAndStrings(subscribers || []);
|
||||
const allSubscriberClasses = [
|
||||
...subscriberClasses,
|
||||
...(await importClassesFromDirectories(this.connection.logger, subscriberDirectories)),
|
||||
];
|
||||
return getMetadataArgsStorage()
|
||||
.filterSubscribers(allSubscriberClasses)
|
||||
.map((metadata) => getFromContainer(metadata.target));
|
||||
}
|
||||
/**
|
||||
* Builds entity metadatas for the given classes or directories.
|
||||
*/
|
||||
async buildEntityMetadatas(entities) {
|
||||
// todo: instead we need to merge multiple metadata args storages
|
||||
const [entityClassesOrSchemas, entityDirectories] = OrmUtils.splitClassesAndStrings(entities || []);
|
||||
const entityClasses = entityClassesOrSchemas.filter((entityClass) => !InstanceChecker.isEntitySchema(entityClass));
|
||||
const entitySchemas = entityClassesOrSchemas.filter((entityClass) => InstanceChecker.isEntitySchema(entityClass));
|
||||
const allEntityClasses = [
|
||||
...entityClasses,
|
||||
...(await importClassesFromDirectories(this.connection.logger, entityDirectories)),
|
||||
];
|
||||
allEntityClasses.forEach((entityClass) => {
|
||||
// if we have entity schemas loaded from directories
|
||||
if (InstanceChecker.isEntitySchema(entityClass)) {
|
||||
entitySchemas.push(entityClass);
|
||||
}
|
||||
});
|
||||
const decoratorEntityMetadatas = new EntityMetadataBuilder(this.connection, getMetadataArgsStorage()).build(allEntityClasses);
|
||||
const metadataArgsStorageFromSchema = new EntitySchemaTransformer().transform(entitySchemas);
|
||||
const schemaEntityMetadatas = new EntityMetadataBuilder(this.connection, metadataArgsStorageFromSchema).build();
|
||||
return [...decoratorEntityMetadatas, ...schemaEntityMetadatas];
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionMetadataBuilder.js.map
|
||||
File diff suppressed because one or more lines are too long
9
typeorm/browser/connection/ConnectionOptions.d.ts
vendored
Normal file
9
typeorm/browser/connection/ConnectionOptions.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
||||
/**
|
||||
* ConnectionOptions is an interface with settings and options for specific connection.
|
||||
* Options contain database and other connection-related settings.
|
||||
* Consumer must provide connection options for each of your connections.
|
||||
*
|
||||
* @deprecated use DataSourceOptions instead
|
||||
*/
|
||||
export type ConnectionOptions = DataSourceOptions;
|
||||
3
typeorm/browser/connection/ConnectionOptions.js
Normal file
3
typeorm/browser/connection/ConnectionOptions.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=ConnectionOptions.js.map
|
||||
1
typeorm/browser/connection/ConnectionOptions.js.map
Normal file
1
typeorm/browser/connection/ConnectionOptions.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/connection/ConnectionOptions.ts"],"names":[],"mappings":"","file":"ConnectionOptions.js","sourcesContent":["import { DataSourceOptions } from \"../data-source/DataSourceOptions\"\n\n/**\n * ConnectionOptions is an interface with settings and options for specific connection.\n * Options contain database and other connection-related settings.\n * Consumer must provide connection options for each of your connections.\n *\n * @deprecated use DataSourceOptions instead\n */\nexport type ConnectionOptions = DataSourceOptions\n"],"sourceRoot":".."}
|
||||
63
typeorm/browser/connection/ConnectionOptionsReader.d.ts
vendored
Normal file
63
typeorm/browser/connection/ConnectionOptionsReader.d.ts
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
||||
/**
|
||||
* Reads connection options from the ormconfig.
|
||||
*/
|
||||
export declare class ConnectionOptionsReader {
|
||||
protected options?: {
|
||||
/**
|
||||
* Directory where ormconfig should be read from.
|
||||
* By default its your application root (where your app package.json is located).
|
||||
*/
|
||||
root?: string | undefined;
|
||||
/**
|
||||
* Filename of the ormconfig configuration. By default its equal to "ormconfig".
|
||||
*/
|
||||
configName?: string | undefined;
|
||||
} | undefined;
|
||||
constructor(options?: {
|
||||
/**
|
||||
* Directory where ormconfig should be read from.
|
||||
* By default its your application root (where your app package.json is located).
|
||||
*/
|
||||
root?: string | undefined;
|
||||
/**
|
||||
* Filename of the ormconfig configuration. By default its equal to "ormconfig".
|
||||
*/
|
||||
configName?: string | undefined;
|
||||
} | undefined);
|
||||
/**
|
||||
* Returns all connection options read from the ormconfig.
|
||||
*/
|
||||
all(): Promise<DataSourceOptions[]>;
|
||||
/**
|
||||
* Gets a connection with a given name read from ormconfig.
|
||||
* If connection with such name would not be found then it throw error.
|
||||
*/
|
||||
get(name: string): Promise<DataSourceOptions>;
|
||||
/**
|
||||
* Checks if there is a TypeORM configuration file.
|
||||
*/
|
||||
has(name: string): Promise<boolean>;
|
||||
/**
|
||||
* Loads all connection options from a configuration file.
|
||||
*
|
||||
* todo: get in count NODE_ENV somehow
|
||||
*/
|
||||
protected load(): Promise<DataSourceOptions[] | undefined>;
|
||||
/**
|
||||
* Normalize connection options.
|
||||
*/
|
||||
protected normalizeConnectionOptions(connectionOptions: DataSourceOptions | DataSourceOptions[]): DataSourceOptions[];
|
||||
/**
|
||||
* Gets directory where configuration file should be located and configuration file name.
|
||||
*/
|
||||
protected get baseFilePath(): string;
|
||||
/**
|
||||
* Gets directory where configuration file should be located.
|
||||
*/
|
||||
protected get baseDirectory(): string;
|
||||
/**
|
||||
* Gets configuration file name.
|
||||
*/
|
||||
protected get baseConfigName(): string;
|
||||
}
|
||||
197
typeorm/browser/connection/ConnectionOptionsReader.js
Normal file
197
typeorm/browser/connection/ConnectionOptionsReader.js
Normal file
@ -0,0 +1,197 @@
|
||||
import appRootPath from "app-root-path";
|
||||
import path from "path";
|
||||
import { PlatformTools } from "../platform/PlatformTools";
|
||||
import { ConnectionOptionsEnvReader } from "./options-reader/ConnectionOptionsEnvReader";
|
||||
import { TypeORMError } from "../error";
|
||||
import { isAbsolute } from "../util/PathUtils";
|
||||
import { importOrRequireFile } from "../util/ImportUtils";
|
||||
/**
|
||||
* Reads connection options from the ormconfig.
|
||||
*/
|
||||
export class ConnectionOptionsReader {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Returns all connection options read from the ormconfig.
|
||||
*/
|
||||
async all() {
|
||||
const options = await this.load();
|
||||
if (!options)
|
||||
throw new TypeORMError(`No connection options were found in any orm configuration files.`);
|
||||
return options;
|
||||
}
|
||||
/**
|
||||
* Gets a connection with a given name read from ormconfig.
|
||||
* If connection with such name would not be found then it throw error.
|
||||
*/
|
||||
async get(name) {
|
||||
const allOptions = await this.all();
|
||||
const targetOptions = allOptions.find((options) => options.name === name || (name === "default" && !options.name));
|
||||
if (!targetOptions)
|
||||
throw new TypeORMError(`Cannot find connection ${name} because its not defined in any orm configuration files.`);
|
||||
return targetOptions;
|
||||
}
|
||||
/**
|
||||
* Checks if there is a TypeORM configuration file.
|
||||
*/
|
||||
async has(name) {
|
||||
const allOptions = await this.load();
|
||||
if (!allOptions)
|
||||
return false;
|
||||
const targetOptions = allOptions.find((options) => options.name === name || (name === "default" && !options.name));
|
||||
return !!targetOptions;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Loads all connection options from a configuration file.
|
||||
*
|
||||
* todo: get in count NODE_ENV somehow
|
||||
*/
|
||||
async load() {
|
||||
let connectionOptions = undefined;
|
||||
const fileFormats = [
|
||||
"env",
|
||||
"js",
|
||||
"mjs",
|
||||
"cjs",
|
||||
"ts",
|
||||
"mts",
|
||||
"cts",
|
||||
"json",
|
||||
];
|
||||
// Detect if baseFilePath contains file extension
|
||||
const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf("."));
|
||||
const fileExtension = fileFormats.find((extension) => `.${extension}` === possibleExtension);
|
||||
// try to find any of following configuration formats
|
||||
const foundFileFormat = fileExtension ||
|
||||
fileFormats.find((format) => {
|
||||
return PlatformTools.fileExist(this.baseFilePath + "." + format);
|
||||
});
|
||||
// Determine config file name
|
||||
const configFile = fileExtension
|
||||
? this.baseFilePath
|
||||
: this.baseFilePath + "." + foundFileFormat;
|
||||
// if .env file found then load all its variables into process.env using dotenv package
|
||||
if (foundFileFormat === "env") {
|
||||
PlatformTools.dotenv(configFile);
|
||||
}
|
||||
else if (PlatformTools.fileExist(this.baseDirectory + "/.env")) {
|
||||
PlatformTools.dotenv(this.baseDirectory + "/.env");
|
||||
}
|
||||
// try to find connection options from any of available sources of configuration
|
||||
if (PlatformTools.getEnvVariable("TYPEORM_CONNECTION") ||
|
||||
PlatformTools.getEnvVariable("TYPEORM_URL")) {
|
||||
connectionOptions = await new ConnectionOptionsEnvReader().read();
|
||||
}
|
||||
else if (foundFileFormat === "js" ||
|
||||
foundFileFormat === "mjs" ||
|
||||
foundFileFormat === "cjs" ||
|
||||
foundFileFormat === "ts" ||
|
||||
foundFileFormat === "mts" ||
|
||||
foundFileFormat === "cts") {
|
||||
const [importOrRequireResult, moduleSystem] = await importOrRequireFile(configFile);
|
||||
const configModule = await importOrRequireResult;
|
||||
if (moduleSystem === "esm" ||
|
||||
(configModule &&
|
||||
"__esModule" in configModule &&
|
||||
"default" in configModule)) {
|
||||
connectionOptions = configModule.default;
|
||||
}
|
||||
else {
|
||||
connectionOptions = configModule;
|
||||
}
|
||||
}
|
||||
else if (foundFileFormat === "json") {
|
||||
connectionOptions = require(configFile);
|
||||
}
|
||||
// normalize and return connection options
|
||||
if (connectionOptions) {
|
||||
return this.normalizeConnectionOptions(connectionOptions);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Normalize connection options.
|
||||
*/
|
||||
normalizeConnectionOptions(connectionOptions) {
|
||||
if (!Array.isArray(connectionOptions))
|
||||
connectionOptions = [connectionOptions];
|
||||
connectionOptions.forEach((options) => {
|
||||
options.baseDirectory = this.baseDirectory;
|
||||
if (options.entities) {
|
||||
const entities = options.entities.map((entity) => {
|
||||
if (typeof entity === "string" &&
|
||||
entity.substr(0, 1) !== "/")
|
||||
return this.baseDirectory + "/" + entity;
|
||||
return entity;
|
||||
});
|
||||
Object.assign(connectionOptions, { entities: entities });
|
||||
}
|
||||
if (options.subscribers) {
|
||||
const subscribers = options.subscribers.map((subscriber) => {
|
||||
if (typeof subscriber === "string" &&
|
||||
subscriber.substr(0, 1) !== "/")
|
||||
return this.baseDirectory + "/" + subscriber;
|
||||
return subscriber;
|
||||
});
|
||||
Object.assign(connectionOptions, { subscribers: subscribers });
|
||||
}
|
||||
if (options.migrations) {
|
||||
const migrations = options.migrations.map((migration) => {
|
||||
if (typeof migration === "string" &&
|
||||
migration.substr(0, 1) !== "/")
|
||||
return this.baseDirectory + "/" + migration;
|
||||
return migration;
|
||||
});
|
||||
Object.assign(connectionOptions, { migrations: migrations });
|
||||
}
|
||||
// make database path file in sqlite relative to package.json
|
||||
if (options.type === "sqlite" ||
|
||||
options.type === "better-sqlite3") {
|
||||
if (typeof options.database === "string" &&
|
||||
!isAbsolute(options.database) &&
|
||||
options.database.substr(0, 1) !== "/" && // unix absolute
|
||||
options.database.substr(1, 2) !== ":\\" && // windows absolute
|
||||
options.database !== ":memory:") {
|
||||
Object.assign(options, {
|
||||
database: this.baseDirectory + "/" + options.database,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return connectionOptions;
|
||||
}
|
||||
/**
|
||||
* Gets directory where configuration file should be located and configuration file name.
|
||||
*/
|
||||
get baseFilePath() {
|
||||
return path.resolve(this.baseDirectory, this.baseConfigName);
|
||||
}
|
||||
/**
|
||||
* Gets directory where configuration file should be located.
|
||||
*/
|
||||
get baseDirectory() {
|
||||
if (this.options && this.options.root)
|
||||
return this.options.root;
|
||||
return appRootPath.path;
|
||||
}
|
||||
/**
|
||||
* Gets configuration file name.
|
||||
*/
|
||||
get baseConfigName() {
|
||||
if (this.options && this.options.configName)
|
||||
return this.options.configName;
|
||||
return "ormconfig";
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionOptionsReader.js.map
|
||||
File diff suppressed because one or more lines are too long
30
typeorm/browser/connection/options-reader/ConnectionOptionsEnvReader.d.ts
vendored
Normal file
30
typeorm/browser/connection/options-reader/ConnectionOptionsEnvReader.d.ts
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
import { DataSourceOptions } from "../../data-source/DataSourceOptions";
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
* Environment variables can have only a single connection.
|
||||
* Its strongly required to define TYPEORM_CONNECTION env variable.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare class ConnectionOptionsEnvReader {
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
*/
|
||||
read(): Promise<DataSourceOptions[]>;
|
||||
/**
|
||||
* Transforms logging string into real logging value connection requires.
|
||||
*/
|
||||
protected transformLogging(logging: string): any;
|
||||
/**
|
||||
* Transforms caching option into real caching value option requires.
|
||||
*/
|
||||
protected transformCaching(): boolean | object | undefined;
|
||||
/**
|
||||
* Converts a string which contains multiple elements split by comma into a string array of strings.
|
||||
*/
|
||||
protected stringToArray(variable?: string): string[];
|
||||
/**
|
||||
* Converts a string which contains a number into a javascript number
|
||||
*/
|
||||
private stringToNumber;
|
||||
}
|
||||
@ -0,0 +1,107 @@
|
||||
import { PlatformTools } from "../../platform/PlatformTools";
|
||||
import { OrmUtils } from "../../util/OrmUtils";
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
* Environment variables can have only a single connection.
|
||||
* Its strongly required to define TYPEORM_CONNECTION env variable.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export class ConnectionOptionsEnvReader {
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
*/
|
||||
async read() {
|
||||
return [
|
||||
{
|
||||
type: PlatformTools.getEnvVariable("TYPEORM_CONNECTION") ||
|
||||
(PlatformTools.getEnvVariable("TYPEORM_URL")
|
||||
? PlatformTools.getEnvVariable("TYPEORM_URL").split("://")[0]
|
||||
: undefined),
|
||||
url: PlatformTools.getEnvVariable("TYPEORM_URL"),
|
||||
host: PlatformTools.getEnvVariable("TYPEORM_HOST"),
|
||||
port: this.stringToNumber(PlatformTools.getEnvVariable("TYPEORM_PORT")),
|
||||
username: PlatformTools.getEnvVariable("TYPEORM_USERNAME"),
|
||||
password: PlatformTools.getEnvVariable("TYPEORM_PASSWORD"),
|
||||
database: PlatformTools.getEnvVariable("TYPEORM_DATABASE"),
|
||||
sid: PlatformTools.getEnvVariable("TYPEORM_SID"),
|
||||
schema: PlatformTools.getEnvVariable("TYPEORM_SCHEMA"),
|
||||
extra: PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA")
|
||||
? JSON.parse(PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA"))
|
||||
: undefined,
|
||||
synchronize: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_SYNCHRONIZE")),
|
||||
dropSchema: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_DROP_SCHEMA")),
|
||||
migrationsRun: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_RUN")),
|
||||
entities: this.stringToArray(PlatformTools.getEnvVariable("TYPEORM_ENTITIES")),
|
||||
migrations: this.stringToArray(PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS")),
|
||||
migrationsTableName: PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_TABLE_NAME"),
|
||||
metadataTableName: PlatformTools.getEnvVariable("TYPEORM_METADATA_TABLE_NAME"),
|
||||
subscribers: this.stringToArray(PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS")),
|
||||
logging: this.transformLogging(PlatformTools.getEnvVariable("TYPEORM_LOGGING")),
|
||||
logger: PlatformTools.getEnvVariable("TYPEORM_LOGGER"),
|
||||
entityPrefix: PlatformTools.getEnvVariable("TYPEORM_ENTITY_PREFIX"),
|
||||
maxQueryExecutionTime: PlatformTools.getEnvVariable("TYPEORM_MAX_QUERY_EXECUTION_TIME"),
|
||||
debug: PlatformTools.getEnvVariable("TYPEORM_DEBUG"),
|
||||
cache: this.transformCaching(),
|
||||
uuidExtension: PlatformTools.getEnvVariable("TYPEORM_UUID_EXTENSION"),
|
||||
},
|
||||
];
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Transforms logging string into real logging value connection requires.
|
||||
*/
|
||||
transformLogging(logging) {
|
||||
if (logging === "true" || logging === "TRUE" || logging === "1")
|
||||
return true;
|
||||
if (logging === "all")
|
||||
return "all";
|
||||
return this.stringToArray(logging);
|
||||
}
|
||||
/**
|
||||
* Transforms caching option into real caching value option requires.
|
||||
*/
|
||||
transformCaching() {
|
||||
const caching = PlatformTools.getEnvVariable("TYPEORM_CACHE");
|
||||
if (caching === "true" || caching === "TRUE" || caching === "1")
|
||||
return true;
|
||||
if (caching === "false" || caching === "FALSE" || caching === "0")
|
||||
return false;
|
||||
if (caching === "redis" ||
|
||||
caching === "ioredis" ||
|
||||
caching === "database")
|
||||
return {
|
||||
type: caching,
|
||||
options: PlatformTools.getEnvVariable("TYPEORM_CACHE_OPTIONS")
|
||||
? JSON.parse(PlatformTools.getEnvVariable("TYPEORM_CACHE_OPTIONS"))
|
||||
: undefined,
|
||||
alwaysEnabled: PlatformTools.getEnvVariable("TYPEORM_CACHE_ALWAYS_ENABLED"),
|
||||
duration: parseInt(PlatformTools.getEnvVariable("TYPEORM_CACHE_DURATION")),
|
||||
};
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Converts a string which contains multiple elements split by comma into a string array of strings.
|
||||
*/
|
||||
stringToArray(variable) {
|
||||
if (!variable)
|
||||
return [];
|
||||
return variable.split(",").map((str) => str.trim());
|
||||
}
|
||||
/**
|
||||
* Converts a string which contains a number into a javascript number
|
||||
*/
|
||||
stringToNumber(value) {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
return parseInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionOptionsEnvReader.js.map
|
||||
File diff suppressed because one or more lines are too long
39
typeorm/browser/container.d.ts
vendored
Normal file
39
typeorm/browser/container.d.ts
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Container options.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export interface UseContainerOptions {
|
||||
/**
|
||||
* If set to true, then default container will be used in the case if given container haven't returned anything.
|
||||
*/
|
||||
fallback?: boolean;
|
||||
/**
|
||||
* If set to true, then default container will be used in the case if given container thrown an exception.
|
||||
*/
|
||||
fallbackOnErrors?: boolean;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export type ContainedType<T> = {
|
||||
new (...args: any[]): T;
|
||||
} | Function;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export interface ContainerInterface {
|
||||
get<T>(someClass: ContainedType<T>): T;
|
||||
}
|
||||
/**
|
||||
* Sets container to be used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare function useContainer(iocContainer: ContainerInterface, options?: UseContainerOptions): void;
|
||||
/**
|
||||
* Gets the IOC container used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare function getFromContainer<T>(someClass: ContainedType<T>): T;
|
||||
56
typeorm/browser/container.js
Normal file
56
typeorm/browser/container.js
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Container to be used by this library for inversion control. If container was not implicitly set then by default
|
||||
* container simply creates a new instance of the given class.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const defaultContainer = new (class {
|
||||
constructor() {
|
||||
this.instances = [];
|
||||
}
|
||||
get(someClass) {
|
||||
let instance = this.instances.find((i) => i.type === someClass);
|
||||
if (!instance) {
|
||||
instance = {
|
||||
type: someClass,
|
||||
object: new someClass(),
|
||||
};
|
||||
this.instances.push(instance);
|
||||
}
|
||||
return instance.object;
|
||||
}
|
||||
})();
|
||||
let userContainer;
|
||||
let userContainerOptions;
|
||||
/**
|
||||
* Sets container to be used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function useContainer(iocContainer, options) {
|
||||
userContainer = iocContainer;
|
||||
userContainerOptions = options;
|
||||
}
|
||||
/**
|
||||
* Gets the IOC container used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function getFromContainer(someClass) {
|
||||
if (userContainer) {
|
||||
try {
|
||||
const instance = userContainer.get(someClass);
|
||||
if (instance)
|
||||
return instance;
|
||||
if (!userContainerOptions || !userContainerOptions.fallback)
|
||||
return instance;
|
||||
}
|
||||
catch (error) {
|
||||
if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return defaultContainer.get(someClass);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=container.js.map
|
||||
1
typeorm/browser/container.js.map
Normal file
1
typeorm/browser/container.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/container.ts"],"names":[],"mappings":"AA6BA;;;;;GAKG;AACH,MAAM,gBAAgB,GAAuB,IAAI,CAAC;IAAA;QAGtC,cAAS,GAAsC,EAAE,CAAA;IAc7D,CAAC;IAZG,GAAG,CAAI,SAA2B;QAC9B,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;QAC/D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,QAAQ,GAAG;gBACP,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,IAAK,SAAyB,EAAE;aAC3C,CAAA;YACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACjC,CAAC;QAED,OAAO,QAAQ,CAAC,MAAM,CAAA;IAC1B,CAAC;CACJ,CAAC,EAAE,CAAA;AAEJ,IAAI,aAAiC,CAAA;AACrC,IAAI,oBAAqD,CAAA;AAEzD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CACxB,YAAgC,EAChC,OAA6B;IAE7B,aAAa,GAAG,YAAY,CAAA;IAC5B,oBAAoB,GAAG,OAAO,CAAA;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAI,SAA2B;IAC3D,IAAI,aAAa,EAAE,CAAC;QAChB,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7C,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAA;YAE7B,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,QAAQ;gBACvD,OAAO,QAAQ,CAAA;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,gBAAgB;gBAC/D,MAAM,KAAK,CAAA;QACnB,CAAC;IACL,CAAC;IACD,OAAO,gBAAgB,CAAC,GAAG,CAAI,SAAS,CAAC,CAAA;AAC7C,CAAC","file":"container.js","sourcesContent":["/**\n * Container options.\n *\n * @deprecated\n */\nexport interface UseContainerOptions {\n /**\n * If set to true, then default container will be used in the case if given container haven't returned anything.\n */\n fallback?: boolean\n\n /**\n * If set to true, then default container will be used in the case if given container thrown an exception.\n */\n fallbackOnErrors?: boolean\n}\n\n/**\n * @deprecated\n */\nexport type ContainedType<T> = { new (...args: any[]): T } | Function\n\n/**\n * @deprecated\n */\nexport interface ContainerInterface {\n get<T>(someClass: ContainedType<T>): T\n}\n\n/**\n * Container to be used by this library for inversion control. If container was not implicitly set then by default\n * container simply creates a new instance of the given class.\n *\n * @deprecated\n */\nconst defaultContainer: ContainerInterface = new (class\n implements ContainerInterface\n{\n private instances: { type: Function; object: any }[] = []\n\n get<T>(someClass: ContainedType<T>): T {\n let instance = this.instances.find((i) => i.type === someClass)\n if (!instance) {\n instance = {\n type: someClass,\n object: new (someClass as new () => T)(),\n }\n this.instances.push(instance)\n }\n\n return instance.object\n }\n})()\n\nlet userContainer: ContainerInterface\nlet userContainerOptions: UseContainerOptions | undefined\n\n/**\n * Sets container to be used by this library.\n *\n * @deprecated\n */\nexport function useContainer(\n iocContainer: ContainerInterface,\n options?: UseContainerOptions,\n) {\n userContainer = iocContainer\n userContainerOptions = options\n}\n\n/**\n * Gets the IOC container used by this library.\n *\n * @deprecated\n */\nexport function getFromContainer<T>(someClass: ContainedType<T>): T {\n if (userContainer) {\n try {\n const instance = userContainer.get(someClass)\n if (instance) return instance\n\n if (!userContainerOptions || !userContainerOptions.fallback)\n return instance\n } catch (error) {\n if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)\n throw error\n }\n }\n return defaultContainer.get<T>(someClass)\n}\n"],"sourceRoot":"."}
|
||||
169
typeorm/browser/data-source/BaseDataSourceOptions.d.ts
vendored
Normal file
169
typeorm/browser/data-source/BaseDataSourceOptions.d.ts
vendored
Normal file
@ -0,0 +1,169 @@
|
||||
import { EntitySchema } from "../entity-schema/EntitySchema";
|
||||
import { LoggerOptions } from "../logger/LoggerOptions";
|
||||
import { NamingStrategyInterface } from "../naming-strategy/NamingStrategyInterface";
|
||||
import { DatabaseType } from "../driver/types/DatabaseType";
|
||||
import { Logger } from "../logger/Logger";
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { QueryResultCache } from "../cache/QueryResultCache";
|
||||
import { MixedList } from "../common/MixedList";
|
||||
/**
|
||||
* BaseDataSourceOptions is set of DataSourceOptions shared by all database types.
|
||||
*/
|
||||
export interface BaseDataSourceOptions {
|
||||
/**
|
||||
* Database type. This value is required.
|
||||
*/
|
||||
readonly type: DatabaseType;
|
||||
/**
|
||||
* Connection name. If connection name is not given then it will be called "default".
|
||||
* Different connections must have different names.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
readonly name?: string;
|
||||
/**
|
||||
* Entities to be loaded for this connection.
|
||||
* Accepts both entity classes and directories where from entities need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly entities?: MixedList<Function | string | EntitySchema>;
|
||||
/**
|
||||
* Subscribers to be loaded for this connection.
|
||||
* Accepts both subscriber classes and directories where from subscribers need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly subscribers?: MixedList<Function | string>;
|
||||
/**
|
||||
* Migrations to be loaded for this connection.
|
||||
* Accepts both migration classes and glob patterns representing migration files.
|
||||
*/
|
||||
readonly migrations?: MixedList<Function | string>;
|
||||
/**
|
||||
* Migrations table name, in case of different name from "migrations".
|
||||
* Accepts single string name.
|
||||
*/
|
||||
readonly migrationsTableName?: string;
|
||||
/**
|
||||
* Transaction mode for migrations to run in
|
||||
*/
|
||||
readonly migrationsTransactionMode?: "all" | "none" | "each";
|
||||
/**
|
||||
* Typeorm metadata table name, in case of different name from "typeorm_metadata".
|
||||
* Accepts single string name.
|
||||
*/
|
||||
readonly metadataTableName?: string;
|
||||
/**
|
||||
* Naming strategy to be used to name tables and columns in the database.
|
||||
*/
|
||||
readonly namingStrategy?: NamingStrategyInterface;
|
||||
/**
|
||||
* Logging options.
|
||||
*/
|
||||
readonly logging?: LoggerOptions;
|
||||
/**
|
||||
* Logger instance used to log queries and events in the ORM.
|
||||
*/
|
||||
readonly logger?: "advanced-console" | "simple-console" | "file" | "debug" | Logger;
|
||||
/**
|
||||
* Maximum number of milliseconds query should be executed before logger log a warning.
|
||||
*/
|
||||
readonly maxQueryExecutionTime?: number;
|
||||
/**
|
||||
* Maximum number of clients the pool should contain.
|
||||
*/
|
||||
readonly poolSize?: number;
|
||||
/**
|
||||
* Indicates if database schema should be auto created on every application launch.
|
||||
* Be careful with this option and don't use this in production - otherwise you can lose production data.
|
||||
* This option is useful during debug and development.
|
||||
* Alternative to it, you can use CLI and run schema:sync command.
|
||||
*
|
||||
* Note that for MongoDB database it does not create schema, because MongoDB is schemaless.
|
||||
* Instead, it syncs just by creating indices.
|
||||
*/
|
||||
readonly synchronize?: boolean;
|
||||
/**
|
||||
* Indicates if migrations should be auto run on every application launch.
|
||||
* Alternative to it, you can use CLI and run migrations:run command.
|
||||
*/
|
||||
readonly migrationsRun?: boolean;
|
||||
/**
|
||||
* Drops the schema each time connection is being established.
|
||||
* Be careful with this option and don't use this in production - otherwise you'll lose all production data.
|
||||
* This option is useful during debug and development.
|
||||
*/
|
||||
readonly dropSchema?: boolean;
|
||||
/**
|
||||
* Prefix to use on all tables (collections) of this connection in the database.
|
||||
*/
|
||||
readonly entityPrefix?: string;
|
||||
/**
|
||||
* When creating new Entity instances, skip all constructors when true.
|
||||
*/
|
||||
readonly entitySkipConstructor?: boolean;
|
||||
/**
|
||||
* Extra connection options to be passed to the underlying driver.
|
||||
*
|
||||
* todo: deprecate this and move all database-specific types into hts own connection options object.
|
||||
*/
|
||||
readonly extra?: any;
|
||||
/**
|
||||
* Specifies how relations must be loaded - using "joins" or separate queries.
|
||||
* If you are loading too much data with nested joins it's better to load relations
|
||||
* using separate queries.
|
||||
*
|
||||
* Default strategy is "join", but this default can be changed here.
|
||||
* Also, strategy can be set per-query in FindOptions and QueryBuilder.
|
||||
*/
|
||||
readonly relationLoadStrategy?: "join" | "query";
|
||||
/**
|
||||
* Optionally applied "typename" to the model.
|
||||
* If set, then each hydrated model will have this property with the target model / entity name inside.
|
||||
*
|
||||
* (works like a discriminator property).
|
||||
*/
|
||||
readonly typename?: string;
|
||||
/**
|
||||
* Allows to setup cache options.
|
||||
*/
|
||||
readonly cache?: boolean | {
|
||||
/**
|
||||
* Type of caching.
|
||||
*
|
||||
* - "database" means cached values will be stored in the separate table in database. This is default value.
|
||||
* - "redis" means cached values will be stored inside redis. You must provide redis connection options.
|
||||
*/
|
||||
readonly type?: "database" | "redis" | "ioredis" | "ioredis/cluster";
|
||||
/**
|
||||
* Factory function for custom cache providers that implement QueryResultCache.
|
||||
*/
|
||||
readonly provider?: (connection: DataSource) => QueryResultCache;
|
||||
/**
|
||||
* Configurable table name for "database" type cache.
|
||||
* Default value is "query-result-cache"
|
||||
*/
|
||||
readonly tableName?: string;
|
||||
/**
|
||||
* Used to provide redis connection options.
|
||||
*/
|
||||
readonly options?: any;
|
||||
/**
|
||||
* If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.
|
||||
*/
|
||||
readonly alwaysEnabled?: boolean;
|
||||
/**
|
||||
* Time in milliseconds in which cache will expire.
|
||||
* This can be setup per-query.
|
||||
* Default value is 1000 which is equivalent to 1 second.
|
||||
*/
|
||||
readonly duration?: number;
|
||||
/**
|
||||
* Used to specify if cache errors should be ignored, and pass through the call to the Database.
|
||||
*/
|
||||
readonly ignoreErrors?: boolean;
|
||||
};
|
||||
/**
|
||||
* Allows automatic isolation of where clauses
|
||||
*/
|
||||
readonly isolateWhereStatements?: boolean;
|
||||
}
|
||||
3
typeorm/browser/data-source/BaseDataSourceOptions.js
Normal file
3
typeorm/browser/data-source/BaseDataSourceOptions.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=BaseDataSourceOptions.js.map
|
||||
1
typeorm/browser/data-source/BaseDataSourceOptions.js.map
Normal file
1
typeorm/browser/data-source/BaseDataSourceOptions.js.map
Normal file
File diff suppressed because one or more lines are too long
258
typeorm/browser/data-source/DataSource.d.ts
vendored
Normal file
258
typeorm/browser/data-source/DataSource.d.ts
vendored
Normal file
@ -0,0 +1,258 @@
|
||||
import { Driver } from "../driver/Driver";
|
||||
import { Repository } from "../repository/Repository";
|
||||
import { EntitySubscriberInterface } from "../subscriber/EntitySubscriberInterface";
|
||||
import { EntityTarget } from "../common/EntityTarget";
|
||||
import { ObjectType } from "../common/ObjectType";
|
||||
import { EntityManager } from "../entity-manager/EntityManager";
|
||||
import { TreeRepository } from "../repository/TreeRepository";
|
||||
import { NamingStrategyInterface } from "../naming-strategy/NamingStrategyInterface";
|
||||
import { EntityMetadata } from "../metadata/EntityMetadata";
|
||||
import { Logger } from "../logger/Logger";
|
||||
import { MigrationInterface } from "../migration/MigrationInterface";
|
||||
import { Migration } from "../migration/Migration";
|
||||
import { MongoRepository } from "../repository/MongoRepository";
|
||||
import { MongoEntityManager } from "../entity-manager/MongoEntityManager";
|
||||
import { DataSourceOptions } from "./DataSourceOptions";
|
||||
import { QueryRunner } from "../query-runner/QueryRunner";
|
||||
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
|
||||
import { QueryResultCache } from "../cache/QueryResultCache";
|
||||
import { SqljsEntityManager } from "../entity-manager/SqljsEntityManager";
|
||||
import { RelationLoader } from "../query-builder/RelationLoader";
|
||||
import { IsolationLevel } from "../driver/types/IsolationLevel";
|
||||
import { ReplicationMode } from "../driver/types/ReplicationMode";
|
||||
import { RelationIdLoader } from "../query-builder/RelationIdLoader";
|
||||
import { ObjectLiteral } from "../common/ObjectLiteral";
|
||||
/**
|
||||
* DataSource is a pre-defined connection configuration to a specific database.
|
||||
* You can have multiple data sources connected (with multiple connections in it),
|
||||
* connected to multiple databases in your application.
|
||||
*
|
||||
* Before, it was called `Connection`, but now `Connection` is deprecated
|
||||
* because `Connection` isn't the best name for what it's actually is.
|
||||
*/
|
||||
export declare class DataSource {
|
||||
readonly "@instanceof": symbol;
|
||||
/**
|
||||
* Connection name.
|
||||
*
|
||||
* @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* Connection options.
|
||||
*/
|
||||
readonly options: DataSourceOptions;
|
||||
/**
|
||||
* Indicates if DataSource is initialized or not.
|
||||
*/
|
||||
readonly isInitialized: boolean;
|
||||
/**
|
||||
* Database driver used by this connection.
|
||||
*/
|
||||
driver: Driver;
|
||||
/**
|
||||
* EntityManager of this connection.
|
||||
*/
|
||||
readonly manager: EntityManager;
|
||||
/**
|
||||
* Naming strategy used in the connection.
|
||||
*/
|
||||
namingStrategy: NamingStrategyInterface;
|
||||
/**
|
||||
* Name for the metadata table
|
||||
*/
|
||||
readonly metadataTableName: string;
|
||||
/**
|
||||
* Logger used to log orm events.
|
||||
*/
|
||||
logger: Logger;
|
||||
/**
|
||||
* Migration instances that are registered for this connection.
|
||||
*/
|
||||
readonly migrations: MigrationInterface[];
|
||||
/**
|
||||
* Entity subscriber instances that are registered for this connection.
|
||||
*/
|
||||
readonly subscribers: EntitySubscriberInterface<any>[];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
*/
|
||||
readonly entityMetadatas: EntityMetadata[];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
* This is a copy of #.entityMetadatas property -> used for more performant searches.
|
||||
*/
|
||||
readonly entityMetadatasMap: Map<EntityTarget<any>, EntityMetadata>;
|
||||
/**
|
||||
* Used to work with query result cache.
|
||||
*/
|
||||
queryResultCache?: QueryResultCache;
|
||||
/**
|
||||
* Used to load relations and work with lazy relations.
|
||||
*/
|
||||
readonly relationLoader: RelationLoader;
|
||||
readonly relationIdLoader: RelationIdLoader;
|
||||
constructor(options: DataSourceOptions);
|
||||
/**
|
||||
Indicates if DataSource is initialized or not.
|
||||
*
|
||||
* @deprecated use .isInitialized instead
|
||||
*/
|
||||
get isConnected(): boolean;
|
||||
/**
|
||||
* Gets the mongodb entity manager that allows to perform mongodb-specific repository operations
|
||||
* with any entity in this connection.
|
||||
*
|
||||
* Available only in mongodb connections.
|
||||
*/
|
||||
get mongoManager(): MongoEntityManager;
|
||||
/**
|
||||
* Gets a sql.js specific Entity Manager that allows to perform special load and save operations
|
||||
*
|
||||
* Available only in connection with the sqljs driver.
|
||||
*/
|
||||
get sqljsManager(): SqljsEntityManager;
|
||||
/**
|
||||
* Updates current connection options with provided options.
|
||||
*/
|
||||
setOptions(options: Partial<DataSourceOptions>): this;
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*/
|
||||
initialize(): Promise<this>;
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*
|
||||
* @deprecated use .initialize method instead
|
||||
*/
|
||||
connect(): Promise<this>;
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*/
|
||||
destroy(): Promise<void>;
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*
|
||||
* @deprecated use .destroy method instead
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Creates database schema for all entities registered in this connection.
|
||||
* Can be used only after connection to the database is established.
|
||||
*
|
||||
* @param dropBeforeSync If set to true then it drops the database with all its tables and data
|
||||
*/
|
||||
synchronize(dropBeforeSync?: boolean): Promise<void>;
|
||||
/**
|
||||
* Drops the database and all its data.
|
||||
* Be careful with this method on production since this method will erase all your database tables and their data.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
dropDatabase(): Promise<void>;
|
||||
/**
|
||||
* Runs all pending migrations.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
runMigrations(options?: {
|
||||
transaction?: "all" | "none" | "each";
|
||||
fake?: boolean;
|
||||
}): Promise<Migration[]>;
|
||||
/**
|
||||
* Reverts last executed migration.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
undoLastMigration(options?: {
|
||||
transaction?: "all" | "none" | "each";
|
||||
fake?: boolean;
|
||||
}): Promise<void>;
|
||||
/**
|
||||
* Lists all migrations and whether they have been run.
|
||||
* Returns true if there are pending migrations
|
||||
*/
|
||||
showMigrations(): Promise<boolean>;
|
||||
/**
|
||||
* Checks if entity metadata exist for the given entity class, target name or table name.
|
||||
*/
|
||||
hasMetadata(target: EntityTarget<any>): boolean;
|
||||
/**
|
||||
* Gets entity metadata for the given entity class or schema name.
|
||||
*/
|
||||
getMetadata(target: EntityTarget<any>): EntityMetadata;
|
||||
/**
|
||||
* Gets repository for the given entity.
|
||||
*/
|
||||
getRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): Repository<Entity>;
|
||||
/**
|
||||
* Gets tree repository for the given entity class or name.
|
||||
* Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.
|
||||
*/
|
||||
getTreeRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): TreeRepository<Entity>;
|
||||
/**
|
||||
* Gets mongodb-specific repository for the given entity class or name.
|
||||
* Works only if connection is mongodb-specific.
|
||||
*/
|
||||
getMongoRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): MongoRepository<Entity>;
|
||||
/**
|
||||
* Gets custom entity repository marked with @EntityRepository decorator.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
getCustomRepository<T>(customRepository: ObjectType<T>): T;
|
||||
/**
|
||||
* Wraps given function execution (and all operations made there) into a transaction.
|
||||
* All database operations must be executed using provided entity manager.
|
||||
*/
|
||||
transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
|
||||
transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
|
||||
/**
|
||||
* Executes raw SQL query and returns raw database results.
|
||||
*/
|
||||
query<T = any>(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<T>;
|
||||
/**
|
||||
* Creates a new query builder that can be used to build a SQL query.
|
||||
*/
|
||||
createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
|
||||
/**
|
||||
* Creates a new query builder that can be used to build a SQL query.
|
||||
*/
|
||||
createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;
|
||||
/**
|
||||
* Creates a query runner used for perform queries on a single database connection.
|
||||
* Using query runners you can control your queries to execute using single database connection and
|
||||
* manually control your database transaction.
|
||||
*
|
||||
* Mode is used in replication mode and indicates whatever you want to connect
|
||||
* to master database or any of slave databases.
|
||||
* If you perform writes you must use master database,
|
||||
* if you perform reads you can use slave databases.
|
||||
*/
|
||||
createQueryRunner(mode?: ReplicationMode): QueryRunner;
|
||||
/**
|
||||
* Gets entity metadata of the junction table (many-to-many table).
|
||||
*/
|
||||
getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string): EntityMetadata | undefined;
|
||||
/**
|
||||
* Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.
|
||||
*/
|
||||
createEntityManager(queryRunner?: QueryRunner): EntityManager;
|
||||
/**
|
||||
* Finds exist entity metadata by the given entity class, target name or table name.
|
||||
*/
|
||||
protected findMetadata(target: EntityTarget<any>): EntityMetadata | undefined;
|
||||
/**
|
||||
* Builds metadatas for all registered classes inside this connection.
|
||||
*/
|
||||
protected buildMetadatas(): Promise<void>;
|
||||
/**
|
||||
* Get the replication mode SELECT queries should use for this datasource by default
|
||||
*/
|
||||
defaultReplicationModeForReads(): ReplicationMode;
|
||||
}
|
||||
494
typeorm/browser/data-source/DataSource.js
Normal file
494
typeorm/browser/data-source/DataSource.js
Normal file
@ -0,0 +1,494 @@
|
||||
import { registerQueryBuilders } from "../query-builder";
|
||||
import { DefaultNamingStrategy } from "../naming-strategy/DefaultNamingStrategy";
|
||||
import { CannotConnectAlreadyConnectedError, CannotExecuteNotConnectedError, EntityMetadataNotFoundError, QueryRunnerProviderAlreadyReleasedError, TypeORMError, } from "../error";
|
||||
import { MigrationExecutor } from "../migration/MigrationExecutor";
|
||||
import { EntityMetadataValidator } from "../metadata-builder/EntityMetadataValidator";
|
||||
import { EntityManagerFactory } from "../entity-manager/EntityManagerFactory";
|
||||
import { DriverFactory } from "../driver/DriverFactory";
|
||||
import { ConnectionMetadataBuilder } from "../connection/ConnectionMetadataBuilder";
|
||||
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
|
||||
import { LoggerFactory } from "../logger/LoggerFactory";
|
||||
import { QueryResultCacheFactory } from "../cache/QueryResultCacheFactory";
|
||||
import { RelationLoader } from "../query-builder/RelationLoader";
|
||||
import { ObjectUtils } from "../util/ObjectUtils";
|
||||
import { RelationIdLoader } from "../query-builder/RelationIdLoader";
|
||||
import { DriverUtils } from "../driver/DriverUtils";
|
||||
import { InstanceChecker } from "../util/InstanceChecker";
|
||||
registerQueryBuilders();
|
||||
/**
|
||||
* DataSource is a pre-defined connection configuration to a specific database.
|
||||
* You can have multiple data sources connected (with multiple connections in it),
|
||||
* connected to multiple databases in your application.
|
||||
*
|
||||
* Before, it was called `Connection`, but now `Connection` is deprecated
|
||||
* because `Connection` isn't the best name for what it's actually is.
|
||||
*/
|
||||
export class DataSource {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(options) {
|
||||
this["@instanceof"] = Symbol.for("DataSource");
|
||||
/**
|
||||
* Migration instances that are registered for this connection.
|
||||
*/
|
||||
this.migrations = [];
|
||||
/**
|
||||
* Entity subscriber instances that are registered for this connection.
|
||||
*/
|
||||
this.subscribers = [];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
*/
|
||||
this.entityMetadatas = [];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
* This is a copy of #.entityMetadatas property -> used for more performant searches.
|
||||
*/
|
||||
this.entityMetadatasMap = new Map();
|
||||
registerQueryBuilders();
|
||||
this.name = options.name || "default";
|
||||
this.options = options;
|
||||
this.logger = new LoggerFactory().create(this.options.logger, this.options.logging);
|
||||
this.driver = new DriverFactory().create(this);
|
||||
this.manager = this.createEntityManager();
|
||||
this.namingStrategy =
|
||||
options.namingStrategy || new DefaultNamingStrategy();
|
||||
this.metadataTableName = options.metadataTableName || "typeorm_metadata";
|
||||
this.queryResultCache = options.cache
|
||||
? new QueryResultCacheFactory(this).create()
|
||||
: undefined;
|
||||
this.relationLoader = new RelationLoader(this);
|
||||
this.relationIdLoader = new RelationIdLoader(this);
|
||||
this.isInitialized = false;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Accessors
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
Indicates if DataSource is initialized or not.
|
||||
*
|
||||
* @deprecated use .isInitialized instead
|
||||
*/
|
||||
get isConnected() {
|
||||
return this.isInitialized;
|
||||
}
|
||||
/**
|
||||
* Gets the mongodb entity manager that allows to perform mongodb-specific repository operations
|
||||
* with any entity in this connection.
|
||||
*
|
||||
* Available only in mongodb connections.
|
||||
*/
|
||||
get mongoManager() {
|
||||
if (!InstanceChecker.isMongoEntityManager(this.manager))
|
||||
throw new TypeORMError(`MongoEntityManager is only available for MongoDB databases.`);
|
||||
return this.manager;
|
||||
}
|
||||
/**
|
||||
* Gets a sql.js specific Entity Manager that allows to perform special load and save operations
|
||||
*
|
||||
* Available only in connection with the sqljs driver.
|
||||
*/
|
||||
get sqljsManager() {
|
||||
if (!InstanceChecker.isSqljsEntityManager(this.manager))
|
||||
throw new TypeORMError(`SqljsEntityManager is only available for Sqljs databases.`);
|
||||
return this.manager;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Updates current connection options with provided options.
|
||||
*/
|
||||
setOptions(options) {
|
||||
Object.assign(this.options, options);
|
||||
if (options.logger || options.logging) {
|
||||
this.logger = new LoggerFactory().create(options.logger || this.options.logger, options.logging || this.options.logging);
|
||||
}
|
||||
if (options.namingStrategy) {
|
||||
this.namingStrategy = options.namingStrategy;
|
||||
}
|
||||
if (options.cache) {
|
||||
this.queryResultCache = new QueryResultCacheFactory(this).create();
|
||||
}
|
||||
// todo: we must update the database in the driver as well, if it was set by setOptions method
|
||||
// in the future we need to refactor the code and remove "database" from the driver, and instead
|
||||
// use database (and options) from a single place - data source.
|
||||
if (options.database) {
|
||||
this.driver.database = DriverUtils.buildDriverOptions(this.options).database;
|
||||
}
|
||||
// todo: need to take a look if we need to update schema and other "poor" properties
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*/
|
||||
async initialize() {
|
||||
if (this.isInitialized)
|
||||
throw new CannotConnectAlreadyConnectedError(this.name);
|
||||
// connect to the database via its driver
|
||||
await this.driver.connect();
|
||||
// connect to the cache-specific database if cache is enabled
|
||||
if (this.queryResultCache)
|
||||
await this.queryResultCache.connect();
|
||||
// set connected status for the current connection
|
||||
ObjectUtils.assign(this, { isInitialized: true });
|
||||
try {
|
||||
// build all metadatas registered in the current connection
|
||||
await this.buildMetadatas();
|
||||
await this.driver.afterConnect();
|
||||
// if option is set - drop schema once connection is done
|
||||
if (this.options.dropSchema)
|
||||
await this.dropDatabase();
|
||||
// if option is set - automatically synchronize a schema
|
||||
if (this.options.migrationsRun)
|
||||
await this.runMigrations({
|
||||
transaction: this.options.migrationsTransactionMode,
|
||||
});
|
||||
// if option is set - automatically synchronize a schema
|
||||
if (this.options.synchronize)
|
||||
await this.synchronize();
|
||||
}
|
||||
catch (error) {
|
||||
// if for some reason build metadata fail (for example validation error during entity metadata check)
|
||||
// connection needs to be closed
|
||||
await this.destroy();
|
||||
throw error;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*
|
||||
* @deprecated use .initialize method instead
|
||||
*/
|
||||
async connect() {
|
||||
return this.initialize();
|
||||
}
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*/
|
||||
async destroy() {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
await this.driver.disconnect();
|
||||
// disconnect from the cache-specific database if cache was enabled
|
||||
if (this.queryResultCache)
|
||||
await this.queryResultCache.disconnect();
|
||||
ObjectUtils.assign(this, { isInitialized: false });
|
||||
}
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*
|
||||
* @deprecated use .destroy method instead
|
||||
*/
|
||||
async close() {
|
||||
return this.destroy();
|
||||
}
|
||||
/**
|
||||
* Creates database schema for all entities registered in this connection.
|
||||
* Can be used only after connection to the database is established.
|
||||
*
|
||||
* @param dropBeforeSync If set to true then it drops the database with all its tables and data
|
||||
*/
|
||||
async synchronize(dropBeforeSync = false) {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
if (dropBeforeSync)
|
||||
await this.dropDatabase();
|
||||
const schemaBuilder = this.driver.createSchemaBuilder();
|
||||
await schemaBuilder.build();
|
||||
}
|
||||
/**
|
||||
* Drops the database and all its data.
|
||||
* Be careful with this method on production since this method will erase all your database tables and their data.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
// TODO rename
|
||||
async dropDatabase() {
|
||||
const queryRunner = this.createQueryRunner();
|
||||
try {
|
||||
if (this.driver.options.type === "mssql" ||
|
||||
DriverUtils.isMySQLFamily(this.driver) ||
|
||||
this.driver.options.type === "aurora-mysql" ||
|
||||
DriverUtils.isSQLiteFamily(this.driver)) {
|
||||
const databases = [];
|
||||
this.entityMetadatas.forEach((metadata) => {
|
||||
if (metadata.database &&
|
||||
databases.indexOf(metadata.database) === -1)
|
||||
databases.push(metadata.database);
|
||||
});
|
||||
if (databases.length === 0 && this.driver.database) {
|
||||
databases.push(this.driver.database);
|
||||
}
|
||||
if (databases.length === 0) {
|
||||
await queryRunner.clearDatabase();
|
||||
}
|
||||
else {
|
||||
for (const database of databases) {
|
||||
await queryRunner.clearDatabase(database);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
await queryRunner.clearDatabase();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Runs all pending migrations.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
async runMigrations(options) {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
const migrationExecutor = new MigrationExecutor(this);
|
||||
migrationExecutor.transaction =
|
||||
options?.transaction ||
|
||||
this.options?.migrationsTransactionMode ||
|
||||
"all";
|
||||
migrationExecutor.fake = (options && options.fake) || false;
|
||||
const successMigrations = await migrationExecutor.executePendingMigrations();
|
||||
return successMigrations;
|
||||
}
|
||||
/**
|
||||
* Reverts last executed migration.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
async undoLastMigration(options) {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
const migrationExecutor = new MigrationExecutor(this);
|
||||
migrationExecutor.transaction =
|
||||
(options && options.transaction) || "all";
|
||||
migrationExecutor.fake = (options && options.fake) || false;
|
||||
await migrationExecutor.undoLastMigration();
|
||||
}
|
||||
/**
|
||||
* Lists all migrations and whether they have been run.
|
||||
* Returns true if there are pending migrations
|
||||
*/
|
||||
async showMigrations() {
|
||||
if (!this.isInitialized) {
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
}
|
||||
const migrationExecutor = new MigrationExecutor(this);
|
||||
return await migrationExecutor.showMigrations();
|
||||
}
|
||||
/**
|
||||
* Checks if entity metadata exist for the given entity class, target name or table name.
|
||||
*/
|
||||
hasMetadata(target) {
|
||||
return !!this.findMetadata(target);
|
||||
}
|
||||
/**
|
||||
* Gets entity metadata for the given entity class or schema name.
|
||||
*/
|
||||
getMetadata(target) {
|
||||
const metadata = this.findMetadata(target);
|
||||
if (!metadata)
|
||||
throw new EntityMetadataNotFoundError(target);
|
||||
return metadata;
|
||||
}
|
||||
/**
|
||||
* Gets repository for the given entity.
|
||||
*/
|
||||
getRepository(target) {
|
||||
return this.manager.getRepository(target);
|
||||
}
|
||||
/**
|
||||
* Gets tree repository for the given entity class or name.
|
||||
* Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.
|
||||
*/
|
||||
getTreeRepository(target) {
|
||||
return this.manager.getTreeRepository(target);
|
||||
}
|
||||
/**
|
||||
* Gets mongodb-specific repository for the given entity class or name.
|
||||
* Works only if connection is mongodb-specific.
|
||||
*/
|
||||
getMongoRepository(target) {
|
||||
if (!(this.driver.options.type === "mongodb"))
|
||||
throw new TypeORMError(`You can use getMongoRepository only for MongoDB connections.`);
|
||||
return this.manager.getRepository(target);
|
||||
}
|
||||
/**
|
||||
* Gets custom entity repository marked with @EntityRepository decorator.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
getCustomRepository(customRepository) {
|
||||
return this.manager.getCustomRepository(customRepository);
|
||||
}
|
||||
async transaction(isolationOrRunInTransaction, runInTransactionParam) {
|
||||
return this.manager.transaction(isolationOrRunInTransaction, runInTransactionParam);
|
||||
}
|
||||
/**
|
||||
* Executes raw SQL query and returns raw database results.
|
||||
*/
|
||||
async query(query, parameters, queryRunner) {
|
||||
if (InstanceChecker.isMongoEntityManager(this.manager))
|
||||
throw new TypeORMError(`Queries aren't supported by MongoDB.`);
|
||||
if (queryRunner && queryRunner.isReleased)
|
||||
throw new QueryRunnerProviderAlreadyReleasedError();
|
||||
const usedQueryRunner = queryRunner || this.createQueryRunner();
|
||||
try {
|
||||
return await usedQueryRunner.query(query, parameters); // await is needed here because we are using finally
|
||||
}
|
||||
finally {
|
||||
if (!queryRunner)
|
||||
await usedQueryRunner.release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new query builder that can be used to build a SQL query.
|
||||
*/
|
||||
createQueryBuilder(entityOrRunner, alias, queryRunner) {
|
||||
if (InstanceChecker.isMongoEntityManager(this.manager))
|
||||
throw new TypeORMError(`Query Builder is not supported by MongoDB.`);
|
||||
if (alias) {
|
||||
alias = DriverUtils.buildAlias(this.driver, undefined, alias);
|
||||
const metadata = this.getMetadata(entityOrRunner);
|
||||
return new SelectQueryBuilder(this, queryRunner)
|
||||
.select(alias)
|
||||
.from(metadata.target, alias);
|
||||
}
|
||||
else {
|
||||
return new SelectQueryBuilder(this, entityOrRunner);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a query runner used for perform queries on a single database connection.
|
||||
* Using query runners you can control your queries to execute using single database connection and
|
||||
* manually control your database transaction.
|
||||
*
|
||||
* Mode is used in replication mode and indicates whatever you want to connect
|
||||
* to master database or any of slave databases.
|
||||
* If you perform writes you must use master database,
|
||||
* if you perform reads you can use slave databases.
|
||||
*/
|
||||
createQueryRunner(mode = "master") {
|
||||
const queryRunner = this.driver.createQueryRunner(mode);
|
||||
const manager = this.createEntityManager(queryRunner);
|
||||
Object.assign(queryRunner, { manager: manager });
|
||||
return queryRunner;
|
||||
}
|
||||
/**
|
||||
* Gets entity metadata of the junction table (many-to-many table).
|
||||
*/
|
||||
getManyToManyMetadata(entityTarget, relationPropertyPath) {
|
||||
const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);
|
||||
if (!relationMetadata)
|
||||
throw new TypeORMError(`Relation "${relationPropertyPath}" was not found in ${entityTarget} entity.`);
|
||||
if (!relationMetadata.isManyToMany)
|
||||
throw new TypeORMError(`Relation "${entityTarget}#${relationPropertyPath}" does not have a many-to-many relationship.` +
|
||||
`You can use this method only on many-to-many relations.`);
|
||||
return relationMetadata.junctionEntityMetadata;
|
||||
}
|
||||
/**
|
||||
* Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.
|
||||
*/
|
||||
createEntityManager(queryRunner) {
|
||||
return new EntityManagerFactory().create(this, queryRunner);
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Finds exist entity metadata by the given entity class, target name or table name.
|
||||
*/
|
||||
findMetadata(target) {
|
||||
const metadataFromMap = this.entityMetadatasMap.get(target);
|
||||
if (metadataFromMap)
|
||||
return metadataFromMap;
|
||||
for (let [_, metadata] of this.entityMetadatasMap) {
|
||||
if (InstanceChecker.isEntitySchema(target) &&
|
||||
metadata.name === target.options.name) {
|
||||
return metadata;
|
||||
}
|
||||
if (typeof target === "string") {
|
||||
if (target.indexOf(".") !== -1) {
|
||||
if (metadata.tablePath === target) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (metadata.name === target ||
|
||||
metadata.tableName === target) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ObjectUtils.isObjectWithName(target) &&
|
||||
typeof target.name === "string") {
|
||||
if (target.name.indexOf(".") !== -1) {
|
||||
if (metadata.tablePath === target.name) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (metadata.name === target.name ||
|
||||
metadata.tableName === target.name) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Builds metadatas for all registered classes inside this connection.
|
||||
*/
|
||||
async buildMetadatas() {
|
||||
const connectionMetadataBuilder = new ConnectionMetadataBuilder(this);
|
||||
const entityMetadataValidator = new EntityMetadataValidator();
|
||||
// create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)
|
||||
const flattenedSubscribers = ObjectUtils.mixedListToArray(this.options.subscribers || []);
|
||||
const subscribers = await connectionMetadataBuilder.buildSubscribers(flattenedSubscribers);
|
||||
ObjectUtils.assign(this, { subscribers: subscribers });
|
||||
// build entity metadatas
|
||||
const flattenedEntities = ObjectUtils.mixedListToArray(this.options.entities || []);
|
||||
const entityMetadatas = await connectionMetadataBuilder.buildEntityMetadatas(flattenedEntities);
|
||||
ObjectUtils.assign(this, {
|
||||
entityMetadatas: entityMetadatas,
|
||||
entityMetadatasMap: new Map(entityMetadatas.map((metadata) => [metadata.target, metadata])),
|
||||
});
|
||||
// create migration instances
|
||||
const flattenedMigrations = ObjectUtils.mixedListToArray(this.options.migrations || []);
|
||||
const migrations = await connectionMetadataBuilder.buildMigrations(flattenedMigrations);
|
||||
ObjectUtils.assign(this, { migrations: migrations });
|
||||
// validate all created entity metadatas to make sure user created entities are valid and correct
|
||||
entityMetadataValidator.validateMany(this.entityMetadatas.filter((metadata) => metadata.tableType !== "view"), this.driver);
|
||||
// set current data source to the entities
|
||||
for (let entityMetadata of entityMetadatas) {
|
||||
if (InstanceChecker.isBaseEntityConstructor(entityMetadata.target)) {
|
||||
entityMetadata.target.useDataSource(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the replication mode SELECT queries should use for this datasource by default
|
||||
*/
|
||||
defaultReplicationModeForReads() {
|
||||
if ("replication" in this.driver.options) {
|
||||
const value = this.driver.options.replication.defaultMode;
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "slave";
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=DataSource.js.map
|
||||
1
typeorm/browser/data-source/DataSource.js.map
Normal file
1
typeorm/browser/data-source/DataSource.js.map
Normal file
File diff suppressed because one or more lines are too long
22
typeorm/browser/data-source/DataSourceOptions.d.ts
vendored
Normal file
22
typeorm/browser/data-source/DataSourceOptions.d.ts
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
import { CockroachConnectionOptions } from "../driver/cockroachdb/CockroachConnectionOptions";
|
||||
import { MysqlConnectionOptions } from "../driver/mysql/MysqlConnectionOptions";
|
||||
import { PostgresConnectionOptions } from "../driver/postgres/PostgresConnectionOptions";
|
||||
import { SqliteConnectionOptions } from "../driver/sqlite/SqliteConnectionOptions";
|
||||
import { SqlServerConnectionOptions } from "../driver/sqlserver/SqlServerConnectionOptions";
|
||||
import { OracleConnectionOptions } from "../driver/oracle/OracleConnectionOptions";
|
||||
import { MongoConnectionOptions } from "../driver/mongodb/MongoConnectionOptions";
|
||||
import { CordovaConnectionOptions } from "../driver/cordova/CordovaConnectionOptions";
|
||||
import { SqljsConnectionOptions } from "../driver/sqljs/SqljsConnectionOptions";
|
||||
import { ReactNativeConnectionOptions } from "../driver/react-native/ReactNativeConnectionOptions";
|
||||
import { NativescriptConnectionOptions } from "../driver/nativescript/NativescriptConnectionOptions";
|
||||
import { ExpoConnectionOptions } from "../driver/expo/ExpoConnectionOptions";
|
||||
import { AuroraMysqlConnectionOptions } from "../driver/aurora-mysql/AuroraMysqlConnectionOptions";
|
||||
import { SapConnectionOptions } from "../driver/sap/SapConnectionOptions";
|
||||
import { AuroraPostgresConnectionOptions } from "../driver/aurora-postgres/AuroraPostgresConnectionOptions";
|
||||
import { BetterSqlite3ConnectionOptions } from "../driver/better-sqlite3/BetterSqlite3ConnectionOptions";
|
||||
import { CapacitorConnectionOptions } from "../driver/capacitor/CapacitorConnectionOptions";
|
||||
import { SpannerConnectionOptions } from "../driver/spanner/SpannerConnectionOptions";
|
||||
/**
|
||||
* DataSourceOptions is an interface with settings and options for specific DataSource.
|
||||
*/
|
||||
export type DataSourceOptions = MysqlConnectionOptions | PostgresConnectionOptions | CockroachConnectionOptions | SqliteConnectionOptions | SqlServerConnectionOptions | SapConnectionOptions | OracleConnectionOptions | CordovaConnectionOptions | NativescriptConnectionOptions | ReactNativeConnectionOptions | SqljsConnectionOptions | MongoConnectionOptions | AuroraMysqlConnectionOptions | AuroraPostgresConnectionOptions | ExpoConnectionOptions | BetterSqlite3ConnectionOptions | CapacitorConnectionOptions | SpannerConnectionOptions;
|
||||
3
typeorm/browser/data-source/DataSourceOptions.js
Normal file
3
typeorm/browser/data-source/DataSourceOptions.js
Normal file
@ -0,0 +1,3 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=DataSourceOptions.js.map
|
||||
1
typeorm/browser/data-source/DataSourceOptions.js.map
Normal file
1
typeorm/browser/data-source/DataSourceOptions.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/data-source/DataSourceOptions.ts"],"names":[],"mappings":"","file":"DataSourceOptions.js","sourcesContent":["import { CockroachConnectionOptions } from \"../driver/cockroachdb/CockroachConnectionOptions\"\nimport { MysqlConnectionOptions } from \"../driver/mysql/MysqlConnectionOptions\"\nimport { PostgresConnectionOptions } from \"../driver/postgres/PostgresConnectionOptions\"\nimport { SqliteConnectionOptions } from \"../driver/sqlite/SqliteConnectionOptions\"\nimport { SqlServerConnectionOptions } from \"../driver/sqlserver/SqlServerConnectionOptions\"\nimport { OracleConnectionOptions } from \"../driver/oracle/OracleConnectionOptions\"\nimport { MongoConnectionOptions } from \"../driver/mongodb/MongoConnectionOptions\"\nimport { CordovaConnectionOptions } from \"../driver/cordova/CordovaConnectionOptions\"\nimport { SqljsConnectionOptions } from \"../driver/sqljs/SqljsConnectionOptions\"\nimport { ReactNativeConnectionOptions } from \"../driver/react-native/ReactNativeConnectionOptions\"\nimport { NativescriptConnectionOptions } from \"../driver/nativescript/NativescriptConnectionOptions\"\nimport { ExpoConnectionOptions } from \"../driver/expo/ExpoConnectionOptions\"\nimport { AuroraMysqlConnectionOptions } from \"../driver/aurora-mysql/AuroraMysqlConnectionOptions\"\nimport { SapConnectionOptions } from \"../driver/sap/SapConnectionOptions\"\nimport { AuroraPostgresConnectionOptions } from \"../driver/aurora-postgres/AuroraPostgresConnectionOptions\"\nimport { BetterSqlite3ConnectionOptions } from \"../driver/better-sqlite3/BetterSqlite3ConnectionOptions\"\nimport { CapacitorConnectionOptions } from \"../driver/capacitor/CapacitorConnectionOptions\"\nimport { SpannerConnectionOptions } from \"../driver/spanner/SpannerConnectionOptions\"\n\n/**\n * DataSourceOptions is an interface with settings and options for specific DataSource.\n */\nexport type DataSourceOptions =\n | MysqlConnectionOptions\n | PostgresConnectionOptions\n | CockroachConnectionOptions\n | SqliteConnectionOptions\n | SqlServerConnectionOptions\n | SapConnectionOptions\n | OracleConnectionOptions\n | CordovaConnectionOptions\n | NativescriptConnectionOptions\n | ReactNativeConnectionOptions\n | SqljsConnectionOptions\n | MongoConnectionOptions\n | AuroraMysqlConnectionOptions\n | AuroraPostgresConnectionOptions\n | ExpoConnectionOptions\n | BetterSqlite3ConnectionOptions\n | CapacitorConnectionOptions\n | SpannerConnectionOptions\n"],"sourceRoot":".."}
|
||||
2
typeorm/browser/data-source/index.d.ts
vendored
Normal file
2
typeorm/browser/data-source/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from "./DataSource";
|
||||
export * from "./DataSourceOptions";
|
||||
4
typeorm/browser/data-source/index.js
Normal file
4
typeorm/browser/data-source/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
export * from "./DataSource";
|
||||
export * from "./DataSourceOptions";
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
typeorm/browser/data-source/index.js.map
Normal file
1
typeorm/browser/data-source/index.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/data-source/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA","file":"index.js","sourcesContent":["export * from \"./DataSource\"\nexport * from \"./DataSourceOptions\"\n"],"sourceRoot":".."}
|
||||
12
typeorm/browser/decorator/Check.d.ts
vendored
Normal file
12
typeorm/browser/decorator/Check.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Creates a database check.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create checks with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Check(expression: string): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database check.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create checks with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Check(name: string, expression: string): ClassDecorator & PropertyDecorator;
|
||||
24
typeorm/browser/decorator/Check.js
Normal file
24
typeorm/browser/decorator/Check.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { TypeORMError } from "../error";
|
||||
/**
|
||||
* Creates a database check.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create checks with composite columns when used on entity.
|
||||
*/
|
||||
export function Check(nameOrExpression, maybeExpression) {
|
||||
const name = maybeExpression ? nameOrExpression : undefined;
|
||||
const expression = maybeExpression ? maybeExpression : nameOrExpression;
|
||||
if (!expression)
|
||||
throw new TypeORMError(`Check expression is required`);
|
||||
return function (clsOrObject, propertyName) {
|
||||
getMetadataArgsStorage().checks.push({
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
expression: expression,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Check.js.map
|
||||
1
typeorm/browser/decorator/Check.js.map
Normal file
1
typeorm/browser/decorator/Check.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAmBvC;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACjB,gBAAwB,EACxB,eAAwB;IAExB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3D,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAA;IAEvE,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,YAAY,CAAC,8BAA8B,CAAC,CAAA;IAEvE,OAAO,UACH,WAA8B,EAC9B,YAA8B;QAE9B,sBAAsB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YACjC,MAAM,EAAE,YAAY;gBAChB,CAAC,CAAC,WAAW,CAAC,WAAW;gBACzB,CAAC,CAAE,WAAwB;YAC/B,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,UAAU;SACJ,CAAC,CAAA;IAC3B,CAAC,CAAA;AACL,CAAC","file":"Check.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { CheckMetadataArgs } from \"../metadata-args/CheckMetadataArgs\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Creates a database check.\n * Can be used on entity property or on entity.\n * Can create checks with composite columns when used on entity.\n */\nexport function Check(expression: string): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database check.\n * Can be used on entity property or on entity.\n * Can create checks with composite columns when used on entity.\n */\nexport function Check(\n name: string,\n expression: string,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database check.\n * Can be used on entity property or on entity.\n * Can create checks with composite columns when used on entity.\n */\nexport function Check(\n nameOrExpression: string,\n maybeExpression?: string,\n): ClassDecorator & PropertyDecorator {\n const name = maybeExpression ? nameOrExpression : undefined\n const expression = maybeExpression ? maybeExpression : nameOrExpression\n\n if (!expression) throw new TypeORMError(`Check expression is required`)\n\n return function (\n clsOrObject: Function | Object,\n propertyName?: string | symbol,\n ) {\n getMetadataArgsStorage().checks.push({\n target: propertyName\n ? clsOrObject.constructor\n : (clsOrObject as Function),\n name: name,\n expression: expression,\n } as CheckMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
9
typeorm/browser/decorator/EntityRepository.d.ts
vendored
Normal file
9
typeorm/browser/decorator/EntityRepository.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { EntitySchema } from "../entity-schema/EntitySchema";
|
||||
/**
|
||||
* Used to declare a class as a custom repository.
|
||||
* Custom repository can manage some specific entity or just be generic.
|
||||
* Custom repository optionally can extend AbstractRepository, Repository or TreeRepository.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
export declare function EntityRepository(entity?: Function | EntitySchema<any>): ClassDecorator;
|
||||
18
typeorm/browser/decorator/EntityRepository.js
Normal file
18
typeorm/browser/decorator/EntityRepository.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
/**
|
||||
* Used to declare a class as a custom repository.
|
||||
* Custom repository can manage some specific entity or just be generic.
|
||||
* Custom repository optionally can extend AbstractRepository, Repository or TreeRepository.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
export function EntityRepository(entity) {
|
||||
return function (target) {
|
||||
getMetadataArgsStorage().entityRepositories.push({
|
||||
target: target,
|
||||
entity: entity,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=EntityRepository.js.map
|
||||
1
typeorm/browser/decorator/EntityRepository.js.map
Normal file
1
typeorm/browser/decorator/EntityRepository.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/EntityRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAInD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC5B,MAAqC;IAErC,OAAO,UAAU,MAAgB;QAC7B,sBAAsB,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC;YAC7C,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;SACe,CAAC,CAAA;IACtC,CAAC,CAAA;AACL,CAAC","file":"EntityRepository.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { EntityRepositoryMetadataArgs } from \"../metadata-args/EntityRepositoryMetadataArgs\"\nimport { EntitySchema } from \"../entity-schema/EntitySchema\"\n\n/**\n * Used to declare a class as a custom repository.\n * Custom repository can manage some specific entity or just be generic.\n * Custom repository optionally can extend AbstractRepository, Repository or TreeRepository.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\nexport function EntityRepository(\n entity?: Function | EntitySchema<any>,\n): ClassDecorator {\n return function (target: Function) {\n getMetadataArgsStorage().entityRepositories.push({\n target: target,\n entity: entity,\n } as EntityRepositoryMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
12
typeorm/browser/decorator/Exclusion.d.ts
vendored
Normal file
12
typeorm/browser/decorator/Exclusion.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Creates a database exclusion.
|
||||
* Can be used on entity.
|
||||
* Can create exclusions with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Exclusion(expression: string): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database exclusion.
|
||||
* Can be used on entity.
|
||||
* Can create exclusions with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Exclusion(name: string, expression: string): ClassDecorator & PropertyDecorator;
|
||||
24
typeorm/browser/decorator/Exclusion.js
Normal file
24
typeorm/browser/decorator/Exclusion.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { TypeORMError } from "../error";
|
||||
/**
|
||||
* Creates a database exclusion.
|
||||
* Can be used on entity.
|
||||
* Can create exclusions with composite columns when used on entity.
|
||||
*/
|
||||
export function Exclusion(nameOrExpression, maybeExpression) {
|
||||
const name = maybeExpression ? nameOrExpression : undefined;
|
||||
const expression = maybeExpression ? maybeExpression : nameOrExpression;
|
||||
if (!expression)
|
||||
throw new TypeORMError(`Exclusion expression is required`);
|
||||
return function (clsOrObject, propertyName) {
|
||||
getMetadataArgsStorage().exclusions.push({
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
expression: expression,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Exclusion.js.map
|
||||
1
typeorm/browser/decorator/Exclusion.js.map
Normal file
1
typeorm/browser/decorator/Exclusion.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Exclusion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAqBvC;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACrB,gBAAwB,EACxB,eAAwB;IAExB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3D,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAA;IAEvE,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,YAAY,CAAC,kCAAkC,CAAC,CAAA;IAE3E,OAAO,UACH,WAA8B,EAC9B,YAA8B;QAE9B,sBAAsB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YACrC,MAAM,EAAE,YAAY;gBAChB,CAAC,CAAC,WAAW,CAAC,WAAW;gBACzB,CAAC,CAAE,WAAwB;YAC/B,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,UAAU;SACA,CAAC,CAAA;IAC/B,CAAC,CAAA;AACL,CAAC","file":"Exclusion.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { ExclusionMetadataArgs } from \"../metadata-args/ExclusionMetadataArgs\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Creates a database exclusion.\n * Can be used on entity.\n * Can create exclusions with composite columns when used on entity.\n */\nexport function Exclusion(\n expression: string,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database exclusion.\n * Can be used on entity.\n * Can create exclusions with composite columns when used on entity.\n */\nexport function Exclusion(\n name: string,\n expression: string,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database exclusion.\n * Can be used on entity.\n * Can create exclusions with composite columns when used on entity.\n */\nexport function Exclusion(\n nameOrExpression: string,\n maybeExpression?: string,\n): ClassDecorator & PropertyDecorator {\n const name = maybeExpression ? nameOrExpression : undefined\n const expression = maybeExpression ? maybeExpression : nameOrExpression\n\n if (!expression) throw new TypeORMError(`Exclusion expression is required`)\n\n return function (\n clsOrObject: Function | Object,\n propertyName?: string | symbol,\n ) {\n getMetadataArgsStorage().exclusions.push({\n target: propertyName\n ? clsOrObject.constructor\n : (clsOrObject as Function),\n name: name,\n expression: expression,\n } as ExclusionMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
10
typeorm/browser/decorator/Generated.d.ts
vendored
Normal file
10
typeorm/browser/decorator/Generated.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* Marks a column to generate a value on entity insertion.
|
||||
* There are three types of generation strategy - increment, uuid and rowid (cockroachdb only).
|
||||
* Increment uses a number which increases by one on each insertion.
|
||||
* Uuid generates a special UUID token.
|
||||
* Rowid supports only in CockroachDB and uses `unique_rowid()` function
|
||||
*
|
||||
* Note, some databases do not support non-primary generation columns.
|
||||
*/
|
||||
export declare function Generated(strategy?: "increment" | "uuid" | "rowid"): PropertyDecorator;
|
||||
21
typeorm/browser/decorator/Generated.js
Normal file
21
typeorm/browser/decorator/Generated.js
Normal file
@ -0,0 +1,21 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
/**
|
||||
* Marks a column to generate a value on entity insertion.
|
||||
* There are three types of generation strategy - increment, uuid and rowid (cockroachdb only).
|
||||
* Increment uses a number which increases by one on each insertion.
|
||||
* Uuid generates a special UUID token.
|
||||
* Rowid supports only in CockroachDB and uses `unique_rowid()` function
|
||||
*
|
||||
* Note, some databases do not support non-primary generation columns.
|
||||
*/
|
||||
export function Generated(strategy = "increment") {
|
||||
return function (object, propertyName) {
|
||||
getMetadataArgsStorage().generations.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
strategy: strategy,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Generated.js.map
|
||||
1
typeorm/browser/decorator/Generated.js.map
Normal file
1
typeorm/browser/decorator/Generated.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Generated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAGnD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACrB,WAA2C,WAAW;IAEtD,OAAO,UAAU,MAAc,EAAE,YAAoB;QACjD,sBAAsB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;YACtC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,QAAQ,EAAE,QAAQ;SACI,CAAC,CAAA;IAC/B,CAAC,CAAA;AACL,CAAC","file":"Generated.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { GeneratedMetadataArgs } from \"../metadata-args/GeneratedMetadataArgs\"\n\n/**\n * Marks a column to generate a value on entity insertion.\n * There are three types of generation strategy - increment, uuid and rowid (cockroachdb only).\n * Increment uses a number which increases by one on each insertion.\n * Uuid generates a special UUID token.\n * Rowid supports only in CockroachDB and uses `unique_rowid()` function\n *\n * Note, some databases do not support non-primary generation columns.\n */\nexport function Generated(\n strategy: \"increment\" | \"uuid\" | \"rowid\" = \"increment\",\n): PropertyDecorator {\n return function (object: Object, propertyName: string) {\n getMetadataArgsStorage().generations.push({\n target: object.constructor,\n propertyName: propertyName,\n strategy: strategy,\n } as GeneratedMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
49
typeorm/browser/decorator/Index.d.ts
vendored
Normal file
49
typeorm/browser/decorator/Index.d.ts
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
import { IndexOptions } from "./options/IndexOptions";
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, options: {
|
||||
synchronize: false;
|
||||
}): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, fields: string[], options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(fields: string[], options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(fields: (object?: any) => any[] | {
|
||||
[key: string]: number;
|
||||
}, options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, fields: (object?: any) => any[] | {
|
||||
[key: string]: number;
|
||||
}, options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
53
typeorm/browser/decorator/Index.js
Normal file
53
typeorm/browser/decorator/Index.js
Normal file
@ -0,0 +1,53 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { ObjectUtils } from "../util/ObjectUtils";
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export function Index(nameOrFieldsOrOptions, maybeFieldsOrOptions, maybeOptions) {
|
||||
// normalize parameters
|
||||
const name = typeof nameOrFieldsOrOptions === "string"
|
||||
? nameOrFieldsOrOptions
|
||||
: undefined;
|
||||
const fields = typeof nameOrFieldsOrOptions === "string"
|
||||
? maybeFieldsOrOptions
|
||||
: nameOrFieldsOrOptions;
|
||||
let options = ObjectUtils.isObject(nameOrFieldsOrOptions) &&
|
||||
!Array.isArray(nameOrFieldsOrOptions)
|
||||
? nameOrFieldsOrOptions
|
||||
: maybeOptions;
|
||||
if (!options)
|
||||
options =
|
||||
ObjectUtils.isObject(maybeFieldsOrOptions) &&
|
||||
!Array.isArray(maybeFieldsOrOptions)
|
||||
? maybeFieldsOrOptions
|
||||
: maybeOptions;
|
||||
return function (clsOrObject, propertyName) {
|
||||
getMetadataArgsStorage().indices.push({
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
columns: propertyName ? [propertyName] : fields,
|
||||
synchronize: options &&
|
||||
options.synchronize === false
|
||||
? false
|
||||
: true,
|
||||
where: options ? options.where : undefined,
|
||||
unique: options && options.unique ? true : false,
|
||||
spatial: options && options.spatial ? true : false,
|
||||
fulltext: options && options.fulltext ? true : false,
|
||||
nullFiltered: options && options.nullFiltered ? true : false,
|
||||
parser: options ? options.parser : undefined,
|
||||
sparse: options && options.sparse ? true : false,
|
||||
background: options && options.background ? true : false,
|
||||
concurrent: options && options.concurrent ? true : false,
|
||||
expireAfterSeconds: options
|
||||
? options.expireAfterSeconds
|
||||
: undefined,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Index.js.map
|
||||
1
typeorm/browser/decorator/Index.js.map
Normal file
1
typeorm/browser/decorator/Index.js.map
Normal file
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user