@tsed/objection 6.88.1 → 6.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{components → cjs/components}/createBooleanColumn.d.ts +0 -0
- package/lib/cjs/components/createBooleanColumn.js +13 -0
- package/lib/cjs/components/createBooleanColumn.js.map +1 -0
- package/lib/{components → cjs/components}/createIdColumn.d.ts +0 -0
- package/lib/cjs/components/createIdColumn.js +18 -0
- package/lib/cjs/components/createIdColumn.js.map +1 -0
- package/lib/{components → cjs/components}/createNumberColumn.d.ts +0 -0
- package/lib/cjs/components/createNumberColumn.js +13 -0
- package/lib/cjs/components/createNumberColumn.js.map +1 -0
- package/lib/{components → cjs/components}/createStringColumn.d.ts +0 -0
- package/lib/cjs/components/createStringColumn.js +13 -0
- package/lib/cjs/components/createStringColumn.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/columnOptions.d.ts +0 -0
- package/lib/cjs/decorators/columnOptions.js +15 -0
- package/lib/cjs/decorators/columnOptions.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/decimal.d.ts +0 -0
- package/lib/cjs/decorators/decimal.js +29 -0
- package/lib/cjs/decorators/decimal.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/entity.d.ts +0 -0
- package/lib/cjs/decorators/entity.js +23 -0
- package/lib/cjs/decorators/entity.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/idColumn.d.ts +0 -0
- package/lib/cjs/decorators/idColumn.js +25 -0
- package/lib/cjs/decorators/idColumn.js.map +1 -0
- package/lib/{domain → cjs/domain}/ColumnOpts.d.ts +0 -0
- package/lib/cjs/domain/ColumnOpts.js +3 -0
- package/lib/cjs/domain/ColumnOpts.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{services → cjs/services}/ColumnTypesContainer.d.ts +0 -0
- package/lib/cjs/services/ColumnTypesContainer.js +8 -0
- package/lib/cjs/services/ColumnTypesContainer.js.map +1 -0
- package/lib/{services → cjs/services}/ObjectionConnection.d.ts +0 -0
- package/lib/cjs/services/ObjectionConnection.js +24 -0
- package/lib/cjs/services/ObjectionConnection.js.map +1 -0
- package/lib/{utils → cjs/utils}/connect.d.ts +0 -0
- package/lib/cjs/utils/connect.js +13 -0
- package/lib/cjs/utils/connect.js.map +1 -0
- package/lib/{utils → cjs/utils}/createColumns.d.ts +0 -0
- package/lib/cjs/utils/createColumns.js +38 -0
- package/lib/cjs/utils/createColumns.js.map +1 -0
- package/lib/{utils → cjs/utils}/defineStaticGetter.d.ts +0 -0
- package/lib/cjs/utils/defineStaticGetter.js +14 -0
- package/lib/cjs/utils/defineStaticGetter.js.map +1 -0
- package/lib/{utils → cjs/utils}/getColumnCtx.d.ts +0 -0
- package/lib/cjs/utils/getColumnCtx.js +13 -0
- package/lib/cjs/utils/getColumnCtx.js.map +1 -0
- package/lib/esm/components/createBooleanColumn.js +9 -0
- package/lib/esm/components/createBooleanColumn.js.map +1 -0
- package/lib/esm/components/createIdColumn.js +14 -0
- package/lib/esm/components/createIdColumn.js.map +1 -0
- package/lib/esm/components/createNumberColumn.js +9 -0
- package/lib/esm/components/createNumberColumn.js.map +1 -0
- package/lib/esm/components/createStringColumn.js +9 -0
- package/lib/esm/components/createStringColumn.js.map +1 -0
- package/lib/esm/decorators/columnOptions.js +11 -0
- package/lib/esm/decorators/columnOptions.js.map +1 -0
- package/lib/esm/decorators/decimal.js +25 -0
- package/lib/esm/decorators/decimal.js.map +1 -0
- package/lib/esm/decorators/entity.js +19 -0
- package/lib/esm/decorators/entity.js.map +1 -0
- package/lib/esm/decorators/idColumn.js +21 -0
- package/lib/esm/decorators/idColumn.js.map +1 -0
- package/lib/esm/domain/ColumnOpts.js +2 -0
- package/lib/esm/domain/ColumnOpts.js.map +1 -0
- package/lib/esm/index.js +18 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/services/ColumnTypesContainer.js +5 -0
- package/lib/esm/services/ColumnTypesContainer.js.map +1 -0
- package/lib/esm/services/ObjectionConnection.js +21 -0
- package/lib/esm/services/ObjectionConnection.js.map +1 -0
- package/lib/esm/utils/connect.js +8 -0
- package/lib/esm/utils/connect.js.map +1 -0
- package/lib/esm/utils/createColumns.js +32 -0
- package/lib/esm/utils/createColumns.js.map +1 -0
- package/lib/esm/utils/defineStaticGetter.js +10 -0
- package/lib/esm/utils/defineStaticGetter.js.map +1 -0
- package/lib/esm/utils/getColumnCtx.js +9 -0
- package/lib/esm/utils/getColumnCtx.js.map +1 -0
- package/lib/types/components/createBooleanColumn.d.ts +6 -0
- package/lib/types/components/createIdColumn.d.ts +6 -0
- package/lib/types/components/createNumberColumn.d.ts +6 -0
- package/lib/types/components/createStringColumn.d.ts +6 -0
- package/lib/types/decorators/columnOptions.d.ts +8 -0
- package/lib/types/decorators/decimal.d.ts +11 -0
- package/lib/types/decorators/entity.d.ts +11 -0
- package/lib/types/decorators/idColumn.d.ts +7 -0
- package/lib/types/domain/ColumnOpts.d.ts +4 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/services/ColumnTypesContainer.d.ts +6 -0
- package/lib/types/services/ObjectionConnection.d.ts +3 -0
- package/lib/types/utils/connect.d.ts +2 -0
- package/lib/types/utils/createColumns.d.ts +18 -0
- package/lib/types/utils/defineStaticGetter.d.ts +4 -0
- package/lib/types/utils/getColumnCtx.d.ts +13 -0
- package/package.json +20 -16
- package/tsconfig.compile.esm.json +23 -0
- package/lib/index.js +0 -257
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -240
- package/lib/index.modern.js.map +0 -1
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// components
|
|
2
|
+
export * from "./components/createStringColumn";
|
|
3
|
+
export * from "./components/createIdColumn";
|
|
4
|
+
export * from "./components/createBooleanColumn";
|
|
5
|
+
export * from "./components/createNumberColumn";
|
|
6
|
+
// decorators
|
|
7
|
+
export * from "./decorators/entity";
|
|
8
|
+
export * from "./decorators/decimal";
|
|
9
|
+
export * from "./decorators/idColumn";
|
|
10
|
+
export * from "./decorators/columnOptions";
|
|
11
|
+
export * from "./domain/ColumnOpts";
|
|
12
|
+
// services
|
|
13
|
+
export * from "./services/ObjectionConnection";
|
|
14
|
+
// utils
|
|
15
|
+
export * from "./utils/connect";
|
|
16
|
+
export * from "./utils/createColumns";
|
|
17
|
+
export * from "./utils/getColumnCtx";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAUA,aAAa;AACb,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAEhD,aAAa;AACb,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,qBAAqB,CAAC;AAEpC,WAAW;AACX,cAAc,gCAAgC,CAAC;AAE/C,QAAQ;AACR,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC","sourcesContent":["import {Knex} from \"knex\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n knex: Knex.Config;\n }\n }\n}\n\n// components\nexport * from \"./components/createStringColumn\";\nexport * from \"./components/createIdColumn\";\nexport * from \"./components/createBooleanColumn\";\nexport * from \"./components/createNumberColumn\";\n\n// decorators\nexport * from \"./decorators/entity\";\nexport * from \"./decorators/decimal\";\nexport * from \"./decorators/idColumn\";\nexport * from \"./decorators/columnOptions\";\n\nexport * from \"./domain/ColumnOpts\";\n\n// services\nexport * from \"./services/ObjectionConnection\";\n\n// utils\nexport * from \"./utils/connect\";\nexport * from \"./utils/createColumns\";\nexport * from \"./utils/getColumnCtx\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColumnTypesContainer.js","sourceRoot":"","sources":["../../../src/services/ColumnTypesContainer.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAoE,IAAI,GAAG,EAAE,CAAC","sourcesContent":["import type {Knex} from \"knex\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport const ColumnTypesContainer: Map<string, (table: Knex.TableBuilder, ctx: ColumnCtx) => void> = new Map();\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Configuration, registerProvider } from "@tsed/di";
|
|
2
|
+
import { createConnection } from "../utils/connect";
|
|
3
|
+
export const OBJECTION_CONNECTION = Symbol.for("DEFAULT_CONNECTION");
|
|
4
|
+
registerProvider({
|
|
5
|
+
provide: OBJECTION_CONNECTION,
|
|
6
|
+
deps: [Configuration],
|
|
7
|
+
async useAsyncFactory(configuration) {
|
|
8
|
+
const connectionOptions = configuration.get("knex");
|
|
9
|
+
if (connectionOptions) {
|
|
10
|
+
try {
|
|
11
|
+
return createConnection(connectionOptions);
|
|
12
|
+
}
|
|
13
|
+
catch (er) {
|
|
14
|
+
// istanbul ignore next
|
|
15
|
+
console.error(er);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=ObjectionConnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObjectionConnection.js","sourceRoot":"","sources":["../../../src/services/ObjectionConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAEzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAElD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAGrE,gBAAgB,CAAC;IACf,OAAO,EAAE,oBAAoB;IAC7B,IAAI,EAAE,CAAC,aAAa,CAAC;IACrB,KAAK,CAAC,eAAe,CAAC,aAA4B;QAChD,MAAM,iBAAiB,GAAG,aAAa,CAAC,GAAG,CAAc,MAAM,CAAE,CAAC;QAElE,IAAI,iBAAiB,EAAE;YACrB,IAAI;gBACF,OAAO,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;aAC5C;YAAC,OAAO,EAAE,EAAE;gBACX,uBAAuB;gBACvB,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;aACnB;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import {Configuration, registerProvider} from \"@tsed/di\";\nimport type {Knex} from \"knex\";\nimport {createConnection} from \"../utils/connect\";\n\nexport const OBJECTION_CONNECTION = Symbol.for(\"DEFAULT_CONNECTION\");\nexport type OBJECTION_CONNECTION = Knex<any, unknown[]>;\n\nregisterProvider({\n provide: OBJECTION_CONNECTION,\n deps: [Configuration],\n async useAsyncFactory(configuration: Configuration) {\n const connectionOptions = configuration.get<Knex.Config>(\"knex\")!;\n\n if (connectionOptions) {\n try {\n return createConnection(connectionOptions);\n } catch (er) {\n // istanbul ignore next\n console.error(er);\n }\n }\n\n return {};\n }\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../../src/utils/connect.ts"],"names":[],"mappings":"AAAA,OAAO,IAAY,MAAM,MAAM,CAAC;AAChC,OAAO,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AAEhC,MAAM,UAAU,gBAAgB,CAAC,iBAA8B;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC3C,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAEvB,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import knex, {Knex} from \"knex\";\nimport {Model} from \"objection\";\n\nexport function createConnection(connectionOptions: Knex.Config): Knex {\n const connection = knex(connectionOptions);\n Model.knex(connection);\n\n return connection;\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getProperties } from "@tsed/schema";
|
|
2
|
+
import "../components/createBooleanColumn";
|
|
3
|
+
import "../components/createIdColumn";
|
|
4
|
+
import "../components/createNumberColumn";
|
|
5
|
+
import "../components/createStringColumn";
|
|
6
|
+
import { ColumnTypesContainer } from "../services/ColumnTypesContainer";
|
|
7
|
+
import { getColumnCtx } from "./getColumnCtx";
|
|
8
|
+
/**
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
export function createColumn(table, entity) {
|
|
12
|
+
const ctx = getColumnCtx(entity);
|
|
13
|
+
if (!ColumnTypesContainer.has(ctx.columnType)) {
|
|
14
|
+
throw `Column type ${ctx.columnType} isn't supported. Add function to ColumnTypesContainer to map the column with Knex`;
|
|
15
|
+
}
|
|
16
|
+
ColumnTypesContainer.get(ctx.columnType)(table, ctx);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @ignore
|
|
20
|
+
*/
|
|
21
|
+
export function getColumns(model) {
|
|
22
|
+
return [...getProperties(model, { withIgnoredProps: true, objection: true, groups: false }).values()];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @ignore
|
|
26
|
+
*/
|
|
27
|
+
export function createColumns(table, model) {
|
|
28
|
+
getColumns(model).map((entity) => {
|
|
29
|
+
createColumn(table, entity);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=createColumns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createColumns.js","sourceRoot":"","sources":["../../../src/utils/createColumns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAkB,MAAM,cAAc,CAAC;AAE5D,OAAO,mCAAmC,CAAC;AAC3C,OAAO,8BAA8B,CAAC;AACtC,OAAO,kCAAkC,CAAC;AAC1C,OAAO,kCAAkC,CAAC;AAC1C,OAAO,EAAC,oBAAoB,EAAC,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB,EAAE,MAAuB;IAC5E,MAAM,GAAG,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;QAC7C,MAAM,eAAe,GAAG,CAAC,UAAU,oFAAoF,CAAC;KACzH;IAED,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAE,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAU;IACnC,OAAO,CAAC,GAAG,aAAa,CAAC,KAAK,EAAE,EAAC,gBAAgB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACtG,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAwB,EAAE,KAAU;IAChE,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC/B,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {getProperties, JsonEntityStore} from \"@tsed/schema\";\nimport {Knex} from \"knex\";\nimport \"../components/createBooleanColumn\";\nimport \"../components/createIdColumn\";\nimport \"../components/createNumberColumn\";\nimport \"../components/createStringColumn\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {getColumnCtx} from \"./getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createColumn(table: Knex.TableBuilder, entity: JsonEntityStore) {\n const ctx = getColumnCtx(entity);\n\n if (!ColumnTypesContainer.has(ctx.columnType)) {\n throw `Column type ${ctx.columnType} isn't supported. Add function to ColumnTypesContainer to map the column with Knex`;\n }\n\n ColumnTypesContainer.get(ctx.columnType)!(table, ctx);\n}\n\n/**\n * @ignore\n */\nexport function getColumns(model: any) {\n return [...getProperties(model, {withIgnoredProps: true, objection: true, groups: false}).values()];\n}\n\n/**\n * @ignore\n */\nexport function createColumns(table: Knex.TableBuilder, model: any) {\n getColumns(model).map((entity) => {\n createColumn(table, entity);\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineStaticGetter.js","sourceRoot":"","sources":["../../../src/utils/defineStaticGetter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAW,EAAE,WAAmB,EAAE,EAAO;IAC1E,OAAO,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE;QACzD,GAAG,EAAE,EAAE;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {classOf} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function defineStaticGetter(target: any, propertyKey: string, fn: any) {\n return Object.defineProperty(classOf(target), propertyKey, {\n get: fn\n });\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
*/
|
|
4
|
+
export function getColumnCtx(entity) {
|
|
5
|
+
const schema = entity.schema.toJSON();
|
|
6
|
+
const { columnType = schema.type, options = {} } = entity.store.get("objection", {});
|
|
7
|
+
return { entity, columnType, options, schema };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=getColumnCtx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getColumnCtx.js","sourceRoot":"","sources":["../../../src/utils/getColumnCtx.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAuB;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACtC,MAAM,EAAC,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,OAAO,GAAG,EAAE,EAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAsB,WAAW,EAAE,EAAE,CAAC,CAAC;IAExG,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAC,CAAC;AAC/C,CAAC","sourcesContent":["import {JsonEntityStore} from \"@tsed/schema\";\nimport {ColumnOpts} from \"../domain/ColumnOpts\";\n\n/**\n * @ignore\n */\nexport interface ColumnCtx extends ColumnOpts {\n entity: JsonEntityStore;\n schema: any;\n}\n\n/**\n * @ignore\n */\nexport function getColumnCtx(entity: JsonEntityStore): ColumnCtx {\n const schema = entity.schema.toJSON();\n const {columnType = schema.type, options = {}} = entity.store.get<Partial<ColumnOpts>>(\"objection\", {});\n\n return {entity, columnType, options, schema};\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Type } from "@tsed/core";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param tableName
|
|
5
|
+
* @decorator
|
|
6
|
+
* @objection
|
|
7
|
+
*/
|
|
8
|
+
export declare function Entity(tableName: string): ClassDecorator;
|
|
9
|
+
export interface EntityMethods<T> extends Type<T> {
|
|
10
|
+
readonly tableName: string;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace TsED {
|
|
4
|
+
interface Configuration {
|
|
5
|
+
knex: Knex.Config;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export * from "./components/createStringColumn";
|
|
10
|
+
export * from "./components/createIdColumn";
|
|
11
|
+
export * from "./components/createBooleanColumn";
|
|
12
|
+
export * from "./components/createNumberColumn";
|
|
13
|
+
export * from "./decorators/entity";
|
|
14
|
+
export * from "./decorators/decimal";
|
|
15
|
+
export * from "./decorators/idColumn";
|
|
16
|
+
export * from "./decorators/columnOptions";
|
|
17
|
+
export * from "./domain/ColumnOpts";
|
|
18
|
+
export * from "./services/ObjectionConnection";
|
|
19
|
+
export * from "./utils/connect";
|
|
20
|
+
export * from "./utils/createColumns";
|
|
21
|
+
export * from "./utils/getColumnCtx";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JsonEntityStore } from "@tsed/schema";
|
|
2
|
+
import { Knex } from "knex";
|
|
3
|
+
import "../components/createBooleanColumn";
|
|
4
|
+
import "../components/createIdColumn";
|
|
5
|
+
import "../components/createNumberColumn";
|
|
6
|
+
import "../components/createStringColumn";
|
|
7
|
+
/**
|
|
8
|
+
* @ignore
|
|
9
|
+
*/
|
|
10
|
+
export declare function createColumn(table: Knex.TableBuilder, entity: JsonEntityStore): void;
|
|
11
|
+
/**
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
export declare function getColumns(model: any): import("@tsed/schema").JsonPropertyStore[];
|
|
15
|
+
/**
|
|
16
|
+
* @ignore
|
|
17
|
+
*/
|
|
18
|
+
export declare function createColumns(table: Knex.TableBuilder, model: any): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JsonEntityStore } from "@tsed/schema";
|
|
2
|
+
import { ColumnOpts } from "../domain/ColumnOpts";
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export interface ColumnCtx extends ColumnOpts {
|
|
7
|
+
entity: JsonEntityStore;
|
|
8
|
+
schema: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
export declare function getColumnCtx(entity: JsonEntityStore): ColumnCtx;
|
package/package.json
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/objection",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.89.0",
|
|
4
4
|
"description": "Objection.js package for Ts.ED framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
|
-
"main": "./lib/index.js",
|
|
8
|
-
"typings": "./lib/index.d.ts",
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./lib/types/index.d.ts",
|
|
11
|
+
"import": "./lib/esm/index.js",
|
|
12
|
+
"require": "./lib/cjs/index.js",
|
|
13
|
+
"default": "./lib/esm/index.js"
|
|
12
14
|
},
|
|
13
15
|
"scripts": {
|
|
14
|
-
"build": "
|
|
16
|
+
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
15
19
|
"test": "cross-env NODE_ENV=test yarn jest"
|
|
16
20
|
},
|
|
17
21
|
"dependencies": {
|
|
18
22
|
"tslib": "2.2.0"
|
|
19
23
|
},
|
|
20
24
|
"devDependencies": {
|
|
21
|
-
"@tsed/ajv": "6.
|
|
22
|
-
"@tsed/core": "6.
|
|
23
|
-
"@tsed/di": "6.
|
|
24
|
-
"@tsed/json-mapper": "6.
|
|
25
|
-
"@tsed/schema": "6.
|
|
25
|
+
"@tsed/ajv": "6.89.0",
|
|
26
|
+
"@tsed/core": "6.89.0",
|
|
27
|
+
"@tsed/di": "6.89.0",
|
|
28
|
+
"@tsed/json-mapper": "6.89.0",
|
|
29
|
+
"@tsed/schema": "6.89.0",
|
|
26
30
|
"knex": "^0.95.11",
|
|
27
31
|
"mssql": "^7.2.1",
|
|
28
32
|
"mysql": "^2.18.1",
|
|
@@ -34,11 +38,11 @@
|
|
|
34
38
|
"sqlite3": "^5.0.2"
|
|
35
39
|
},
|
|
36
40
|
"peerDependencies": {
|
|
37
|
-
"@tsed/ajv": "^6.
|
|
38
|
-
"@tsed/core": "^6.
|
|
39
|
-
"@tsed/di": "^6.
|
|
40
|
-
"@tsed/json-mapper": "^6.
|
|
41
|
-
"@tsed/schema": "^6.
|
|
41
|
+
"@tsed/ajv": "^6.89.0",
|
|
42
|
+
"@tsed/core": "^6.89.0",
|
|
43
|
+
"@tsed/di": "^6.89.0",
|
|
44
|
+
"@tsed/json-mapper": "^6.89.0",
|
|
45
|
+
"@tsed/schema": "^6.89.0",
|
|
42
46
|
"knex": ">=0.94.0",
|
|
43
47
|
"objection": ">=2.0.0"
|
|
44
48
|
},
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.compile.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "./lib/esm",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationDir": "./lib/types"
|
|
10
|
+
},
|
|
11
|
+
"exclude": [
|
|
12
|
+
"node_modules",
|
|
13
|
+
"test",
|
|
14
|
+
"lib",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"coverage",
|
|
17
|
+
"spec",
|
|
18
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|
package/lib/index.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
var schema = require('@tsed/schema');
|
|
2
|
-
var core = require('@tsed/core');
|
|
3
|
-
var di = require('@tsed/di');
|
|
4
|
-
var knex = require('knex');
|
|
5
|
-
var objection = require('objection');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var knex__default = /*#__PURE__*/_interopDefaultLegacy(knex);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @ignore
|
|
13
|
-
*/
|
|
14
|
-
const ColumnTypesContainer = new Map();
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @ignore
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
function createStringColumn(table, {
|
|
21
|
-
entity,
|
|
22
|
-
schema
|
|
23
|
-
}) {
|
|
24
|
-
table.string(entity.propertyName, schema.maxLength);
|
|
25
|
-
}
|
|
26
|
-
ColumnTypesContainer.set("string", createStringColumn);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @ignore
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
function createIdColumn(table, {
|
|
33
|
-
entity,
|
|
34
|
-
options
|
|
35
|
-
}) {
|
|
36
|
-
if (options.type === "bigIncrements") {
|
|
37
|
-
table.bigIncrements(entity.propertyName).primary();
|
|
38
|
-
} else {
|
|
39
|
-
table.increments(entity.propertyName).primary();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
ColumnTypesContainer.set("idColumn", createIdColumn);
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @ignore
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
function createBooleanColumn(table, {
|
|
49
|
-
entity
|
|
50
|
-
}) {
|
|
51
|
-
table.boolean(entity.propertyName);
|
|
52
|
-
}
|
|
53
|
-
ColumnTypesContainer.set("boolean", createBooleanColumn);
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @ignore
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
function createNumberColumn(table, {
|
|
60
|
-
entity,
|
|
61
|
-
options
|
|
62
|
-
}) {
|
|
63
|
-
table.decimal(entity.propertyName, options.precision, options.scale);
|
|
64
|
-
}
|
|
65
|
-
ColumnTypesContainer.set("number", createNumberColumn);
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @ignore
|
|
69
|
-
*/
|
|
70
|
-
|
|
71
|
-
function defineStaticGetter(target, propertyKey, fn) {
|
|
72
|
-
return Object.defineProperty(core.classOf(target), propertyKey, {
|
|
73
|
-
get: fn
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @param tableName
|
|
80
|
-
* @decorator
|
|
81
|
-
* @objection
|
|
82
|
-
*/
|
|
83
|
-
|
|
84
|
-
function Entity(tableName) {
|
|
85
|
-
if (!tableName) {
|
|
86
|
-
throw new Error("Please provide a table name");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return target => {
|
|
90
|
-
defineStaticGetter(target, "tableName", () => tableName);
|
|
91
|
-
defineStaticGetter(target, "jsonSchema", () => schema.getJsonSchema(target));
|
|
92
|
-
return target;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function _extends() {
|
|
97
|
-
_extends = Object.assign || function (target) {
|
|
98
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
99
|
-
var source = arguments[i];
|
|
100
|
-
|
|
101
|
-
for (var key in source) {
|
|
102
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
103
|
-
target[key] = source[key];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return target;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return _extends.apply(this, arguments);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
*
|
|
116
|
-
* @param options
|
|
117
|
-
* @decorator
|
|
118
|
-
* @objection
|
|
119
|
-
*/
|
|
120
|
-
|
|
121
|
-
function ColumnOptions(options) {
|
|
122
|
-
return core.StoreSet("objection", options);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
*
|
|
127
|
-
* @param options
|
|
128
|
-
* @decorator
|
|
129
|
-
* @objection
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
function Decimal(options = {}) {
|
|
133
|
-
return core.useDecorators(schema.Property(), ColumnOptions({
|
|
134
|
-
columnType: "number",
|
|
135
|
-
options: _extends({
|
|
136
|
-
type: "decimal"
|
|
137
|
-
}, options)
|
|
138
|
-
}), core.StoreSet("objection", {
|
|
139
|
-
columnType: "number",
|
|
140
|
-
options: _extends({
|
|
141
|
-
type: "decimal"
|
|
142
|
-
}, options)
|
|
143
|
-
}));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* @param type
|
|
149
|
-
* @decorator
|
|
150
|
-
* @objection
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
function IdColumn(type = "increments") {
|
|
154
|
-
return core.useDecorators(schema.Property(), ColumnOptions({
|
|
155
|
-
columnType: "idColumn",
|
|
156
|
-
options: {
|
|
157
|
-
type
|
|
158
|
-
}
|
|
159
|
-
}), (target, propertyKey) => {
|
|
160
|
-
defineStaticGetter(target, "idColumn", () => propertyKey);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function createConnection(connectionOptions) {
|
|
165
|
-
const connection = knex__default['default'](connectionOptions);
|
|
166
|
-
objection.Model.knex(connection);
|
|
167
|
-
return connection;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const OBJECTION_CONNECTION = Symbol.for("DEFAULT_CONNECTION");
|
|
171
|
-
di.registerProvider({
|
|
172
|
-
provide: OBJECTION_CONNECTION,
|
|
173
|
-
deps: [di.Configuration],
|
|
174
|
-
|
|
175
|
-
async useAsyncFactory(configuration) {
|
|
176
|
-
const connectionOptions = configuration.get("knex");
|
|
177
|
-
|
|
178
|
-
if (connectionOptions) {
|
|
179
|
-
try {
|
|
180
|
-
return createConnection(connectionOptions);
|
|
181
|
-
} catch (er) {
|
|
182
|
-
// istanbul ignore next
|
|
183
|
-
console.error(er);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return {};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @ignore
|
|
194
|
-
*/
|
|
195
|
-
function getColumnCtx(entity) {
|
|
196
|
-
const schema = entity.schema.toJSON();
|
|
197
|
-
const {
|
|
198
|
-
columnType = schema.type,
|
|
199
|
-
options = {}
|
|
200
|
-
} = entity.store.get("objection", {});
|
|
201
|
-
return {
|
|
202
|
-
entity,
|
|
203
|
-
columnType,
|
|
204
|
-
options,
|
|
205
|
-
schema
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @ignore
|
|
211
|
-
*/
|
|
212
|
-
|
|
213
|
-
function createColumn(table, entity) {
|
|
214
|
-
const ctx = getColumnCtx(entity);
|
|
215
|
-
|
|
216
|
-
if (!ColumnTypesContainer.has(ctx.columnType)) {
|
|
217
|
-
throw `Column type ${ctx.columnType} isn't supported. Add function to ColumnTypesContainer to map the column with Knex`;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
ColumnTypesContainer.get(ctx.columnType)(table, ctx);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* @ignore
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
function getColumns(model) {
|
|
227
|
-
return [...schema.getProperties(model, {
|
|
228
|
-
withIgnoredProps: true,
|
|
229
|
-
objection: true,
|
|
230
|
-
groups: false
|
|
231
|
-
}).values()];
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* @ignore
|
|
235
|
-
*/
|
|
236
|
-
|
|
237
|
-
function createColumns(table, model) {
|
|
238
|
-
getColumns(model).map(entity => {
|
|
239
|
-
createColumn(table, entity);
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
exports.ColumnOptions = ColumnOptions;
|
|
244
|
-
exports.Decimal = Decimal;
|
|
245
|
-
exports.Entity = Entity;
|
|
246
|
-
exports.IdColumn = IdColumn;
|
|
247
|
-
exports.OBJECTION_CONNECTION = OBJECTION_CONNECTION;
|
|
248
|
-
exports.createBooleanColumn = createBooleanColumn;
|
|
249
|
-
exports.createColumn = createColumn;
|
|
250
|
-
exports.createColumns = createColumns;
|
|
251
|
-
exports.createConnection = createConnection;
|
|
252
|
-
exports.createIdColumn = createIdColumn;
|
|
253
|
-
exports.createNumberColumn = createNumberColumn;
|
|
254
|
-
exports.createStringColumn = createStringColumn;
|
|
255
|
-
exports.getColumnCtx = getColumnCtx;
|
|
256
|
-
exports.getColumns = getColumns;
|
|
257
|
-
//# sourceMappingURL=index.js.map
|