@tsed/objection 6.88.0 → 6.91.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.
Files changed (102) hide show
  1. package/lib/{components → cjs/components}/createBooleanColumn.d.ts +0 -0
  2. package/lib/cjs/components/createBooleanColumn.js +13 -0
  3. package/lib/cjs/components/createBooleanColumn.js.map +1 -0
  4. package/lib/{components → cjs/components}/createIdColumn.d.ts +0 -0
  5. package/lib/cjs/components/createIdColumn.js +18 -0
  6. package/lib/cjs/components/createIdColumn.js.map +1 -0
  7. package/lib/{components → cjs/components}/createNumberColumn.d.ts +0 -0
  8. package/lib/cjs/components/createNumberColumn.js +13 -0
  9. package/lib/cjs/components/createNumberColumn.js.map +1 -0
  10. package/lib/{components → cjs/components}/createStringColumn.d.ts +0 -0
  11. package/lib/cjs/components/createStringColumn.js +13 -0
  12. package/lib/cjs/components/createStringColumn.js.map +1 -0
  13. package/lib/{decorators → cjs/decorators}/columnOptions.d.ts +0 -0
  14. package/lib/cjs/decorators/columnOptions.js +15 -0
  15. package/lib/cjs/decorators/columnOptions.js.map +1 -0
  16. package/lib/{decorators → cjs/decorators}/decimal.d.ts +0 -0
  17. package/lib/cjs/decorators/decimal.js +29 -0
  18. package/lib/cjs/decorators/decimal.js.map +1 -0
  19. package/lib/{decorators → cjs/decorators}/entity.d.ts +0 -0
  20. package/lib/cjs/decorators/entity.js +23 -0
  21. package/lib/cjs/decorators/entity.js.map +1 -0
  22. package/lib/{decorators → cjs/decorators}/idColumn.d.ts +0 -0
  23. package/lib/cjs/decorators/idColumn.js +25 -0
  24. package/lib/cjs/decorators/idColumn.js.map +1 -0
  25. package/lib/{domain → cjs/domain}/ColumnOpts.d.ts +0 -0
  26. package/lib/cjs/domain/ColumnOpts.js +3 -0
  27. package/lib/cjs/domain/ColumnOpts.js.map +1 -0
  28. package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  29. package/lib/cjs/index.js +21 -0
  30. package/lib/cjs/index.js.map +1 -0
  31. package/lib/{services → cjs/services}/ColumnTypesContainer.d.ts +0 -0
  32. package/lib/cjs/services/ColumnTypesContainer.js +8 -0
  33. package/lib/cjs/services/ColumnTypesContainer.js.map +1 -0
  34. package/lib/{services → cjs/services}/ObjectionConnection.d.ts +0 -0
  35. package/lib/cjs/services/ObjectionConnection.js +24 -0
  36. package/lib/cjs/services/ObjectionConnection.js.map +1 -0
  37. package/lib/{utils → cjs/utils}/connect.d.ts +0 -0
  38. package/lib/cjs/utils/connect.js +13 -0
  39. package/lib/cjs/utils/connect.js.map +1 -0
  40. package/lib/{utils → cjs/utils}/createColumns.d.ts +0 -0
  41. package/lib/cjs/utils/createColumns.js +38 -0
  42. package/lib/cjs/utils/createColumns.js.map +1 -0
  43. package/lib/{utils → cjs/utils}/defineStaticGetter.d.ts +0 -0
  44. package/lib/cjs/utils/defineStaticGetter.js +14 -0
  45. package/lib/cjs/utils/defineStaticGetter.js.map +1 -0
  46. package/lib/{utils → cjs/utils}/getColumnCtx.d.ts +0 -0
  47. package/lib/cjs/utils/getColumnCtx.js +13 -0
  48. package/lib/cjs/utils/getColumnCtx.js.map +1 -0
  49. package/lib/esm/components/createBooleanColumn.js +9 -0
  50. package/lib/esm/components/createBooleanColumn.js.map +1 -0
  51. package/lib/esm/components/createIdColumn.js +14 -0
  52. package/lib/esm/components/createIdColumn.js.map +1 -0
  53. package/lib/esm/components/createNumberColumn.js +9 -0
  54. package/lib/esm/components/createNumberColumn.js.map +1 -0
  55. package/lib/esm/components/createStringColumn.js +9 -0
  56. package/lib/esm/components/createStringColumn.js.map +1 -0
  57. package/lib/esm/decorators/columnOptions.js +11 -0
  58. package/lib/esm/decorators/columnOptions.js.map +1 -0
  59. package/lib/esm/decorators/decimal.js +25 -0
  60. package/lib/esm/decorators/decimal.js.map +1 -0
  61. package/lib/esm/decorators/entity.js +19 -0
  62. package/lib/esm/decorators/entity.js.map +1 -0
  63. package/lib/esm/decorators/idColumn.js +21 -0
  64. package/lib/esm/decorators/idColumn.js.map +1 -0
  65. package/lib/esm/domain/ColumnOpts.js +2 -0
  66. package/lib/esm/domain/ColumnOpts.js.map +1 -0
  67. package/lib/esm/index.js +18 -0
  68. package/lib/esm/index.js.map +1 -0
  69. package/lib/esm/services/ColumnTypesContainer.js +5 -0
  70. package/lib/esm/services/ColumnTypesContainer.js.map +1 -0
  71. package/lib/esm/services/ObjectionConnection.js +21 -0
  72. package/lib/esm/services/ObjectionConnection.js.map +1 -0
  73. package/lib/esm/utils/connect.js +8 -0
  74. package/lib/esm/utils/connect.js.map +1 -0
  75. package/lib/esm/utils/createColumns.js +32 -0
  76. package/lib/esm/utils/createColumns.js.map +1 -0
  77. package/lib/esm/utils/defineStaticGetter.js +10 -0
  78. package/lib/esm/utils/defineStaticGetter.js.map +1 -0
  79. package/lib/esm/utils/getColumnCtx.js +9 -0
  80. package/lib/esm/utils/getColumnCtx.js.map +1 -0
  81. package/lib/types/components/createBooleanColumn.d.ts +6 -0
  82. package/lib/types/components/createIdColumn.d.ts +6 -0
  83. package/lib/types/components/createNumberColumn.d.ts +6 -0
  84. package/lib/types/components/createStringColumn.d.ts +6 -0
  85. package/lib/types/decorators/columnOptions.d.ts +8 -0
  86. package/lib/types/decorators/decimal.d.ts +11 -0
  87. package/lib/types/decorators/entity.d.ts +11 -0
  88. package/lib/types/decorators/idColumn.d.ts +7 -0
  89. package/lib/types/domain/ColumnOpts.d.ts +4 -0
  90. package/lib/types/index.d.ts +21 -0
  91. package/lib/types/services/ColumnTypesContainer.d.ts +6 -0
  92. package/lib/types/services/ObjectionConnection.d.ts +3 -0
  93. package/lib/types/utils/connect.d.ts +2 -0
  94. package/lib/types/utils/createColumns.d.ts +18 -0
  95. package/lib/types/utils/defineStaticGetter.d.ts +4 -0
  96. package/lib/types/utils/getColumnCtx.d.ts +13 -0
  97. package/package.json +20 -16
  98. package/tsconfig.compile.esm.json +23 -0
  99. package/lib/index.js +0 -257
  100. package/lib/index.js.map +0 -1
  101. package/lib/index.modern.js +0 -240
  102. package/lib/index.modern.js.map +0 -1
@@ -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,5 @@
1
+ /**
2
+ * @ignore
3
+ */
4
+ export const ColumnTypesContainer = new Map();
5
+ //# sourceMappingURL=ColumnTypesContainer.js.map
@@ -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,8 @@
1
+ import knex from "knex";
2
+ import { Model } from "objection";
3
+ export function createConnection(connectionOptions) {
4
+ const connection = knex(connectionOptions);
5
+ Model.knex(connection);
6
+ return connection;
7
+ }
8
+ //# sourceMappingURL=connect.js.map
@@ -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,10 @@
1
+ import { classOf } from "@tsed/core";
2
+ /**
3
+ * @ignore
4
+ */
5
+ export function defineStaticGetter(target, propertyKey, fn) {
6
+ return Object.defineProperty(classOf(target), propertyKey, {
7
+ get: fn
8
+ });
9
+ }
10
+ //# sourceMappingURL=defineStaticGetter.js.map
@@ -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,6 @@
1
+ import type { Knex } from "knex";
2
+ import { ColumnCtx } from "../utils/getColumnCtx";
3
+ /**
4
+ * @ignore
5
+ */
6
+ export declare function createBooleanColumn(table: Knex.TableBuilder, { entity }: ColumnCtx): void;
@@ -0,0 +1,6 @@
1
+ import type { Knex } from "knex";
2
+ import { ColumnCtx } from "../utils/getColumnCtx";
3
+ /**
4
+ * @ignore
5
+ */
6
+ export declare function createIdColumn(table: Knex.TableBuilder, { entity, options }: ColumnCtx): void;
@@ -0,0 +1,6 @@
1
+ import type { Knex } from "knex";
2
+ import { ColumnCtx } from "../utils/getColumnCtx";
3
+ /**
4
+ * @ignore
5
+ */
6
+ export declare function createNumberColumn(table: Knex.TableBuilder, { entity, options }: ColumnCtx): void;
@@ -0,0 +1,6 @@
1
+ import type { Knex } from "knex";
2
+ import { ColumnCtx } from "../utils/getColumnCtx";
3
+ /**
4
+ * @ignore
5
+ */
6
+ export declare function createStringColumn(table: Knex.TableBuilder, { entity, schema }: ColumnCtx): void;
@@ -0,0 +1,8 @@
1
+ import type { ColumnOpts } from "../domain/ColumnOpts";
2
+ /**
3
+ *
4
+ * @param options
5
+ * @decorator
6
+ * @objection
7
+ */
8
+ export declare function ColumnOptions(options: Partial<ColumnOpts>): PropertyDecorator;
@@ -0,0 +1,11 @@
1
+ export interface DecimalOptions {
2
+ precision?: number | null;
3
+ scale?: number;
4
+ }
5
+ /**
6
+ *
7
+ * @param options
8
+ * @decorator
9
+ * @objection
10
+ */
11
+ export declare function Decimal(options?: DecimalOptions): any;
@@ -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,7 @@
1
+ /**
2
+ *
3
+ * @param type
4
+ * @decorator
5
+ * @objection
6
+ */
7
+ export declare function IdColumn(type?: "increments" | "bigIncrements"): PropertyDecorator;
@@ -0,0 +1,4 @@
1
+ export interface ColumnOpts {
2
+ columnType: "idColumn" | "string" | "number" | "boolean";
3
+ options: any;
4
+ }
@@ -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,6 @@
1
+ import type { Knex } from "knex";
2
+ import { ColumnCtx } from "../utils/getColumnCtx";
3
+ /**
4
+ * @ignore
5
+ */
6
+ export declare const ColumnTypesContainer: Map<string, (table: Knex.TableBuilder, ctx: ColumnCtx) => void>;
@@ -0,0 +1,3 @@
1
+ import type { Knex } from "knex";
2
+ export declare const OBJECTION_CONNECTION: unique symbol;
3
+ export declare type OBJECTION_CONNECTION = Knex<any, unknown[]>;
@@ -0,0 +1,2 @@
1
+ import { Knex } from "knex";
2
+ export declare function createConnection(connectionOptions: Knex.Config): Knex;
@@ -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,4 @@
1
+ /**
2
+ * @ignore
3
+ */
4
+ export declare function defineStaticGetter(target: any, propertyKey: string, fn: any): any;
@@ -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.88.0",
3
+ "version": "6.91.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
- "require": "./lib/index.js",
11
- "default": "./lib/index.modern.js"
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": "microbundle --target node --no-compress --format modern,cjs --tsconfig ./tsconfig.compile.json",
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.88.0",
22
- "@tsed/core": "6.88.0",
23
- "@tsed/di": "6.88.0",
24
- "@tsed/json-mapper": "6.88.0",
25
- "@tsed/schema": "6.88.0",
25
+ "@tsed/ajv": "6.91.0",
26
+ "@tsed/core": "6.91.0",
27
+ "@tsed/di": "6.91.0",
28
+ "@tsed/json-mapper": "6.91.0",
29
+ "@tsed/schema": "6.91.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.88.0",
38
- "@tsed/core": "^6.88.0",
39
- "@tsed/di": "^6.88.0",
40
- "@tsed/json-mapper": "^6.88.0",
41
- "@tsed/schema": "^6.88.0",
41
+ "@tsed/ajv": "^6.91.0",
42
+ "@tsed/core": "^6.91.0",
43
+ "@tsed/di": "^6.91.0",
44
+ "@tsed/json-mapper": "^6.91.0",
45
+ "@tsed/schema": "^6.91.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