@tsed/objection 7.0.0-alpha.1 → 7.0.0-beta.10
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/cjs/components/createBooleanColumn.js +13 -0
- package/lib/cjs/components/createBooleanColumn.js.map +1 -0
- package/lib/cjs/components/createIdColumn.js +18 -0
- package/lib/cjs/components/createIdColumn.js.map +1 -0
- package/lib/cjs/components/createNumberColumn.js +13 -0
- package/lib/cjs/components/createNumberColumn.js.map +1 -0
- package/lib/cjs/components/createStringColumn.js +13 -0
- package/lib/cjs/components/createStringColumn.js.map +1 -0
- package/lib/cjs/decorators/columnOptions.js +15 -0
- package/lib/cjs/decorators/columnOptions.js.map +1 -0
- package/lib/cjs/decorators/decimal.js +29 -0
- package/lib/cjs/decorators/decimal.js.map +1 -0
- package/lib/cjs/decorators/entity.js +23 -0
- package/lib/cjs/decorators/entity.js.map +1 -0
- package/lib/cjs/decorators/idColumn.js +25 -0
- package/lib/cjs/decorators/idColumn.js.map +1 -0
- package/lib/cjs/domain/ColumnOpts.js +3 -0
- package/lib/cjs/domain/ColumnOpts.js.map +1 -0
- package/lib/cjs/domain/interfaces.js +3 -0
- package/lib/cjs/domain/interfaces.js.map +1 -0
- package/lib/cjs/index.js +23 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/ColumnTypesContainer.js +8 -0
- package/lib/cjs/services/ColumnTypesContainer.js.map +1 -0
- package/lib/cjs/services/ObjectionConnection.js +24 -0
- package/lib/cjs/services/ObjectionConnection.js.map +1 -0
- package/lib/cjs/utils/connect.js +13 -0
- package/lib/cjs/utils/connect.js.map +1 -0
- package/lib/cjs/utils/createColumns.js +38 -0
- package/lib/cjs/utils/createColumns.js.map +1 -0
- package/lib/cjs/utils/defineStaticGetter.js +14 -0
- package/lib/cjs/utils/defineStaticGetter.js.map +1 -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/domain/interfaces.js +2 -0
- package/lib/esm/domain/interfaces.js.map +1 -0
- package/lib/esm/index.js +20 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +3 -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/{components → types/components}/createBooleanColumn.d.ts +0 -0
- package/lib/{components → types/components}/createIdColumn.d.ts +0 -0
- package/lib/{components → types/components}/createNumberColumn.d.ts +0 -0
- package/lib/{components → types/components}/createStringColumn.d.ts +0 -0
- package/lib/{decorators → types/decorators}/columnOptions.d.ts +0 -0
- package/lib/{decorators → types/decorators}/decimal.d.ts +0 -0
- package/lib/{decorators → types/decorators}/entity.d.ts +0 -0
- package/lib/{decorators → types/decorators}/idColumn.d.ts +0 -0
- package/lib/{domain → types/domain}/ColumnOpts.d.ts +0 -0
- package/lib/types/domain/interfaces.d.ts +8 -0
- package/lib/{index.d.ts → types/index.d.ts} +10 -13
- package/lib/{services → types/services}/ColumnTypesContainer.d.ts +0 -0
- package/lib/{services → types/services}/ObjectionConnection.d.ts +0 -0
- package/lib/{utils → types/utils}/connect.d.ts +0 -0
- package/lib/{utils → types/utils}/createColumns.d.ts +1 -1
- package/lib/{utils → types/utils}/defineStaticGetter.d.ts +0 -0
- package/lib/{utils → types/utils}/getColumnCtx.d.ts +0 -0
- package/package.json +49 -33
- package/readme.md +5 -7
- package/tsconfig.compile.esm.json +12 -0
- package/lib/index.js +0 -270
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -253
- package/lib/index.modern.js.map +0 -1
- package/lib/utils/patchModelJson.d.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,kCAAkC,CAAC;AACjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/createBooleanColumn\";\nexport * from \"./components/createIdColumn\";\nexport * from \"./components/createNumberColumn\";\nexport * from \"./components/createStringColumn\";\nexport * from \"./decorators/columnOptions\";\nexport * from \"./decorators/decimal\";\nexport * from \"./decorators/entity\";\nexport * from \"./decorators/idColumn\";\nexport * from \"./domain/ColumnOpts\";\nexport * from \"./domain/interfaces\";\nexport * from \"./services/ColumnTypesContainer\";\nexport * from \"./services/ObjectionConnection\";\nexport * from \"./utils/connect\";\nexport * from \"./utils/createColumns\";\nexport * from \"./utils/defineStaticGetter\";\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.js";
|
|
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.js";
|
|
3
|
+
import "../components/createIdColumn.js";
|
|
4
|
+
import "../components/createNumberColumn.js";
|
|
5
|
+
import "../components/createStringColumn.js";
|
|
6
|
+
import { ColumnTypesContainer } from "../services/ColumnTypesContainer.js";
|
|
7
|
+
import { getColumnCtx } from "./getColumnCtx.js";
|
|
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"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
namespace TsED {
|
|
5
|
-
interface Configuration {
|
|
6
|
-
knex: Knex.Config;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export * from "./components/createStringColumn";
|
|
11
|
-
export * from "./components/createIdColumn";
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
12
4
|
export * from "./components/createBooleanColumn";
|
|
5
|
+
export * from "./components/createIdColumn";
|
|
13
6
|
export * from "./components/createNumberColumn";
|
|
14
|
-
export * from "./
|
|
7
|
+
export * from "./components/createStringColumn";
|
|
8
|
+
export * from "./decorators/columnOptions";
|
|
15
9
|
export * from "./decorators/decimal";
|
|
10
|
+
export * from "./decorators/entity";
|
|
16
11
|
export * from "./decorators/idColumn";
|
|
17
|
-
export * from "./decorators/columnOptions";
|
|
18
12
|
export * from "./domain/ColumnOpts";
|
|
13
|
+
export * from "./domain/interfaces";
|
|
14
|
+
export * from "./services/ColumnTypesContainer";
|
|
19
15
|
export * from "./services/ObjectionConnection";
|
|
20
16
|
export * from "./utils/connect";
|
|
21
17
|
export * from "./utils/createColumns";
|
|
18
|
+
export * from "./utils/defineStaticGetter";
|
|
22
19
|
export * from "./utils/getColumnCtx";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -11,7 +11,7 @@ export declare function createColumn(table: Knex.TableBuilder, entity: JsonEntit
|
|
|
11
11
|
/**
|
|
12
12
|
* @ignore
|
|
13
13
|
*/
|
|
14
|
-
export declare function getColumns(model: any):
|
|
14
|
+
export declare function getColumns(model: any): import("@tsed/schema").JsonPropertyStore[];
|
|
15
15
|
/**
|
|
16
16
|
* @ignore
|
|
17
17
|
*/
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,59 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/objection",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.10",
|
|
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
|
-
"
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
9
|
+
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
11
|
+
"types": "./lib/types/index.d.ts",
|
|
12
|
+
"import": "./lib/esm/index.js",
|
|
13
|
+
"require": "./lib/cjs/index.js",
|
|
14
|
+
"default": "./lib/esm/index.js"
|
|
12
15
|
},
|
|
13
16
|
"scripts": {
|
|
14
|
-
"build": "
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
18
|
+
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
19
|
+
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
20
|
+
"barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
|
|
15
21
|
"test": "cross-env NODE_ENV=test yarn jest"
|
|
16
22
|
},
|
|
17
23
|
"dependencies": {
|
|
18
|
-
"tslib": "2.
|
|
24
|
+
"tslib": "2.3.1"
|
|
19
25
|
},
|
|
20
26
|
"devDependencies": {
|
|
21
|
-
"@tsed/ajv": "7.0.0-
|
|
22
|
-
"@tsed/core": "7.0.0-
|
|
23
|
-
"@tsed/di": "7.0.0-
|
|
24
|
-
"@tsed/json-mapper": "7.0.0-
|
|
25
|
-
"@tsed/schema": "7.0.0-
|
|
27
|
+
"@tsed/ajv": "7.0.0-beta.10",
|
|
28
|
+
"@tsed/core": "7.0.0-beta.10",
|
|
29
|
+
"@tsed/di": "7.0.0-beta.10",
|
|
30
|
+
"@tsed/json-mapper": "7.0.0-beta.10",
|
|
31
|
+
"@tsed/schema": "7.0.0-beta.10",
|
|
26
32
|
"knex": "^0.95.11",
|
|
27
|
-
"mssql": "^7.2.1",
|
|
28
|
-
"mysql": "^2.18.1",
|
|
29
|
-
"mysql2": "^2.3.0",
|
|
30
33
|
"objection": "^2.2.15",
|
|
31
|
-
"oracledb": "^5.2.0",
|
|
32
|
-
"pg": "^8.7.1",
|
|
33
|
-
"sqlite": "^4.0.23",
|
|
34
34
|
"sqlite3": "^5.0.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@tsed/ajv": "^7.0.0-
|
|
38
|
-
"@tsed/core": "^7.0.0-
|
|
39
|
-
"@tsed/di": "^7.0.0-
|
|
40
|
-
"@tsed/json-mapper": "^7.0.0-
|
|
41
|
-
"@tsed/schema": "^7.0.0-
|
|
42
|
-
"knex": "
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
37
|
+
"@tsed/ajv": "^7.0.0-beta.10",
|
|
38
|
+
"@tsed/core": "^7.0.0-beta.10",
|
|
39
|
+
"@tsed/di": "^7.0.0-beta.10",
|
|
40
|
+
"@tsed/json-mapper": "^7.0.0-beta.10",
|
|
41
|
+
"@tsed/schema": "^7.0.0-beta.10",
|
|
42
|
+
"knex": ">=0.94.0",
|
|
43
|
+
"objection": ">=2.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@tsed/ajv": {
|
|
47
|
+
"optional": false
|
|
48
|
+
},
|
|
49
|
+
"@tsed/core": {
|
|
50
|
+
"optional": false
|
|
51
|
+
},
|
|
52
|
+
"@tsed/di": {
|
|
53
|
+
"optional": false
|
|
54
|
+
},
|
|
55
|
+
"@tsed/json-mapper": {
|
|
56
|
+
"optional": false
|
|
57
|
+
},
|
|
58
|
+
"@tsed/schema": {
|
|
59
|
+
"optional": false
|
|
60
|
+
},
|
|
61
|
+
"knex": {
|
|
62
|
+
"optional": false
|
|
63
|
+
},
|
|
64
|
+
"objection": {
|
|
65
|
+
"optional": false
|
|
66
|
+
}
|
|
51
67
|
},
|
|
52
68
|
"repository": "https://github.com/tsedio/tsed",
|
|
53
69
|
"bugs": {
|
|
54
70
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
55
71
|
},
|
|
56
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
72
|
+
"homepage": "https://github.com/tsedio/tsed/tree/beta/packages/orm/objection",
|
|
57
73
|
"author": "Romain Lenzotti",
|
|
58
74
|
"license": "MIT"
|
|
59
75
|
}
|
package/readme.md
CHANGED
|
@@ -32,8 +32,8 @@ A package of Ts.ED framework. See website: https://tsed.io/tutorials/objection.h
|
|
|
32
32
|
## Feature
|
|
33
33
|
|
|
34
34
|
Currently, `@tsed/objection` allows you:
|
|
35
|
-
|
|
36
|
-
- Configure one database connection via the `@Configuration` decorator.
|
|
35
|
+
|
|
36
|
+
- Configure one database connection via the `@Configuration` decorator.
|
|
37
37
|
- Databases will be initialized when the server starts during the server's `OnInit` phase.
|
|
38
38
|
- Declare a Model from a class with annotation,
|
|
39
39
|
|
|
@@ -69,27 +69,25 @@ import "@tsed/objection"; // don't forget to add this line!
|
|
|
69
69
|
@Configuration({
|
|
70
70
|
// ...
|
|
71
71
|
knex: {
|
|
72
|
-
client:
|
|
73
|
-
connection:
|
|
72
|
+
client: "sqlite3",
|
|
73
|
+
connection: ":memory:"
|
|
74
74
|
}
|
|
75
75
|
})
|
|
76
76
|
class Server {}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
|
|
80
79
|
## Contributors
|
|
80
|
+
|
|
81
81
|
Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
|
|
82
82
|
|
|
83
83
|
<a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
|
|
84
84
|
|
|
85
|
-
|
|
86
85
|
## Backers
|
|
87
86
|
|
|
88
87
|
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
|
|
89
88
|
|
|
90
89
|
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
|
|
91
90
|
|
|
92
|
-
|
|
93
91
|
## Sponsors
|
|
94
92
|
|
|
95
93
|
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
|
|
@@ -0,0 +1,12 @@
|
|
|
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": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
12
|
+
}
|
package/lib/index.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
var core = require('@tsed/core');
|
|
2
|
-
var jsonMapper = require('@tsed/json-mapper');
|
|
3
|
-
var objection = require('objection');
|
|
4
|
-
var schema = require('@tsed/schema');
|
|
5
|
-
var di = require('@tsed/di');
|
|
6
|
-
var knex = require('knex');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var knex__default = /*#__PURE__*/_interopDefaultLegacy(knex);
|
|
11
|
-
|
|
12
|
-
function _extends() {
|
|
13
|
-
_extends = Object.assign || function (target) {
|
|
14
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
15
|
-
var source = arguments[i];
|
|
16
|
-
|
|
17
|
-
for (var key in source) {
|
|
18
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
19
|
-
target[key] = source[key];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return target;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return _extends.apply(this, arguments);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
objection.Model.prototype.toJSON = function toJSON(opt) {
|
|
31
|
-
const obj = this.$toJson(opt);
|
|
32
|
-
|
|
33
|
-
if (opt && opt.endpoint) {
|
|
34
|
-
return jsonMapper.serialize(obj, _extends({
|
|
35
|
-
type: core.classOf(this)
|
|
36
|
-
}, opt));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return obj;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @ignore
|
|
44
|
-
*/
|
|
45
|
-
const ColumnTypesContainer = new Map();
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @ignore
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
function createStringColumn(table, {
|
|
52
|
-
entity,
|
|
53
|
-
schema
|
|
54
|
-
}) {
|
|
55
|
-
table.string(entity.propertyName, schema.maxLength);
|
|
56
|
-
}
|
|
57
|
-
ColumnTypesContainer.set("string", createStringColumn);
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @ignore
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
function createIdColumn(table, {
|
|
64
|
-
entity,
|
|
65
|
-
options
|
|
66
|
-
}) {
|
|
67
|
-
if (options.type === "bigIncrements") {
|
|
68
|
-
table.bigIncrements(entity.propertyName).primary();
|
|
69
|
-
} else {
|
|
70
|
-
table.increments(entity.propertyName).primary();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
ColumnTypesContainer.set("idColumn", createIdColumn);
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @ignore
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
function createBooleanColumn(table, {
|
|
80
|
-
entity
|
|
81
|
-
}) {
|
|
82
|
-
table.boolean(entity.propertyName);
|
|
83
|
-
}
|
|
84
|
-
ColumnTypesContainer.set("boolean", createBooleanColumn);
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @ignore
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
function createNumberColumn(table, {
|
|
91
|
-
entity,
|
|
92
|
-
options
|
|
93
|
-
}) {
|
|
94
|
-
table.decimal(entity.propertyName, options.precision, options.scale);
|
|
95
|
-
}
|
|
96
|
-
ColumnTypesContainer.set("number", createNumberColumn);
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @ignore
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
function defineStaticGetter(target, propertyKey, fn) {
|
|
103
|
-
return Object.defineProperty(core.classOf(target), propertyKey, {
|
|
104
|
-
get: fn
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
* @param tableName
|
|
111
|
-
* @decorator
|
|
112
|
-
* @objection
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
function Entity(tableName) {
|
|
116
|
-
if (!tableName) {
|
|
117
|
-
throw new Error("Please provide a table name");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return target => {
|
|
121
|
-
defineStaticGetter(target, "tableName", () => tableName);
|
|
122
|
-
defineStaticGetter(target, "jsonSchema", () => schema.getJsonSchema(target));
|
|
123
|
-
return target;
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
*
|
|
129
|
-
* @param options
|
|
130
|
-
* @decorator
|
|
131
|
-
* @objection
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
function ColumnOptions(options) {
|
|
135
|
-
return core.StoreSet("objection", options);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
*
|
|
140
|
-
* @param options
|
|
141
|
-
* @decorator
|
|
142
|
-
* @objection
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
function Decimal(options = {}) {
|
|
146
|
-
return core.useDecorators(schema.Property(), ColumnOptions({
|
|
147
|
-
columnType: "number",
|
|
148
|
-
options: _extends({
|
|
149
|
-
type: "decimal"
|
|
150
|
-
}, options)
|
|
151
|
-
}), core.StoreSet("objection", {
|
|
152
|
-
columnType: "number",
|
|
153
|
-
options: _extends({
|
|
154
|
-
type: "decimal"
|
|
155
|
-
}, options)
|
|
156
|
-
}));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
*
|
|
161
|
-
* @param type
|
|
162
|
-
* @decorator
|
|
163
|
-
* @objection
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
function IdColumn(type = "increments") {
|
|
167
|
-
return core.useDecorators(schema.Property(), ColumnOptions({
|
|
168
|
-
columnType: "idColumn",
|
|
169
|
-
options: {
|
|
170
|
-
type
|
|
171
|
-
}
|
|
172
|
-
}), (target, propertyKey) => {
|
|
173
|
-
defineStaticGetter(target, "idColumn", () => propertyKey);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function createConnection(connectionOptions) {
|
|
178
|
-
const connection = knex__default['default'](connectionOptions);
|
|
179
|
-
objection.Model.knex(connection);
|
|
180
|
-
return connection;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const OBJECTION_CONNECTION = Symbol.for("DEFAULT_CONNECTION");
|
|
184
|
-
di.registerProvider({
|
|
185
|
-
provide: OBJECTION_CONNECTION,
|
|
186
|
-
deps: [di.Configuration],
|
|
187
|
-
|
|
188
|
-
async useAsyncFactory(configuration) {
|
|
189
|
-
const connectionOptions = configuration.get("knex");
|
|
190
|
-
|
|
191
|
-
if (connectionOptions) {
|
|
192
|
-
try {
|
|
193
|
-
return createConnection(connectionOptions);
|
|
194
|
-
} catch (er) {
|
|
195
|
-
// istanbul ignore next
|
|
196
|
-
console.error(er);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return {};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* @ignore
|
|
207
|
-
*/
|
|
208
|
-
function getColumnCtx(entity) {
|
|
209
|
-
const schema = entity.schema.toJSON();
|
|
210
|
-
const {
|
|
211
|
-
columnType = schema.type,
|
|
212
|
-
options = {}
|
|
213
|
-
} = entity.store.get("objection", {});
|
|
214
|
-
return {
|
|
215
|
-
entity,
|
|
216
|
-
columnType,
|
|
217
|
-
options,
|
|
218
|
-
schema
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* @ignore
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
function createColumn(table, entity) {
|
|
227
|
-
const ctx = getColumnCtx(entity);
|
|
228
|
-
|
|
229
|
-
if (!ColumnTypesContainer.has(ctx.columnType)) {
|
|
230
|
-
throw `Column type ${ctx.columnType} isn't supported. Add function to ColumnTypesContainer to map the column with Knex`;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
ColumnTypesContainer.get(ctx.columnType)(table, ctx);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* @ignore
|
|
237
|
-
*/
|
|
238
|
-
|
|
239
|
-
function getColumns(model) {
|
|
240
|
-
return [...schema.getProperties(model, {
|
|
241
|
-
withIgnoredProps: true,
|
|
242
|
-
objection: true,
|
|
243
|
-
groups: false
|
|
244
|
-
}).values()];
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* @ignore
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
function createColumns(table, model) {
|
|
251
|
-
getColumns(model).map(entity => {
|
|
252
|
-
createColumn(table, entity);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
exports.ColumnOptions = ColumnOptions;
|
|
257
|
-
exports.Decimal = Decimal;
|
|
258
|
-
exports.Entity = Entity;
|
|
259
|
-
exports.IdColumn = IdColumn;
|
|
260
|
-
exports.OBJECTION_CONNECTION = OBJECTION_CONNECTION;
|
|
261
|
-
exports.createBooleanColumn = createBooleanColumn;
|
|
262
|
-
exports.createColumn = createColumn;
|
|
263
|
-
exports.createColumns = createColumns;
|
|
264
|
-
exports.createConnection = createConnection;
|
|
265
|
-
exports.createIdColumn = createIdColumn;
|
|
266
|
-
exports.createNumberColumn = createNumberColumn;
|
|
267
|
-
exports.createStringColumn = createStringColumn;
|
|
268
|
-
exports.getColumnCtx = getColumnCtx;
|
|
269
|
-
exports.getColumns = getColumns;
|
|
270
|
-
//# sourceMappingURL=index.js.map
|