@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.
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
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/services/ColumnTypesContainer.ts","../src/components/createStringColumn.ts","../src/components/createIdColumn.ts","../src/components/createBooleanColumn.ts","../src/components/createNumberColumn.ts","../src/utils/defineStaticGetter.ts","../src/decorators/entity.ts","../src/decorators/columnOptions.ts","../src/decorators/decimal.ts","../src/decorators/idColumn.ts","../src/utils/connect.ts","../src/services/ObjectionConnection.ts","../src/utils/getColumnCtx.ts","../src/utils/createColumns.ts"],"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","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createStringColumn(table: Knex.TableBuilder, {entity, schema}: ColumnCtx) {\n table.string(entity.propertyName, schema.maxLength);\n}\n\nColumnTypesContainer.set(\"string\", createStringColumn);\n","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createIdColumn(table: Knex.TableBuilder, {entity, options}: ColumnCtx) {\n if (options.type === \"bigIncrements\") {\n table.bigIncrements(entity.propertyName).primary();\n } else {\n table.increments(entity.propertyName).primary();\n }\n}\n\nColumnTypesContainer.set(\"idColumn\", createIdColumn);\n","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n/**\n * @ignore\n */\nexport function createBooleanColumn(table: Knex.TableBuilder, {entity}: ColumnCtx) {\n table.boolean(entity.propertyName);\n}\n\nColumnTypesContainer.set(\"boolean\", createBooleanColumn);\n","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createNumberColumn(table: Knex.TableBuilder, {entity, options}: ColumnCtx) {\n table.decimal(entity.propertyName, options.precision, options.scale);\n}\n\nColumnTypesContainer.set(\"number\", createNumberColumn);\n","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","import {Type} from \"@tsed/core\";\nimport {getJsonSchema} from \"@tsed/schema\";\nimport {defineStaticGetter} from \"../utils/defineStaticGetter\";\n\n/**\n *\n * @param tableName\n * @decorator\n * @objection\n */\nexport function Entity(tableName: string): ClassDecorator {\n if (!tableName) {\n throw new Error(\"Please provide a table name\");\n }\n\n return (target: any) => {\n defineStaticGetter(target, \"tableName\", () => tableName);\n defineStaticGetter(target, \"jsonSchema\", () => getJsonSchema(target));\n\n return target;\n };\n}\n\nexport interface EntityMethods<T> extends Type<T> {\n readonly tableName: string;\n}\n","import {StoreSet} from \"@tsed/core\";\nimport type {ColumnOpts} from \"../domain/ColumnOpts\";\n\n/**\n *\n * @param options\n * @decorator\n * @objection\n */\nexport function ColumnOptions(options: Partial<ColumnOpts>): PropertyDecorator {\n return StoreSet(\"objection\", options) as any;\n}\n","import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Property} from \"@tsed/schema\";\nimport {ColumnOptions} from \"./columnOptions\";\n\nexport interface DecimalOptions {\n precision?: number | null;\n scale?: number;\n}\n\n/**\n *\n * @param options\n * @decorator\n * @objection\n */\nexport function Decimal(options: DecimalOptions = {}) {\n return useDecorators(\n Property(),\n ColumnOptions({\n columnType: \"number\",\n options: {\n type: \"decimal\",\n ...options\n }\n }),\n StoreSet(\"objection\", {\n columnType: \"number\",\n options: {\n type: \"decimal\",\n ...options\n }\n })\n );\n}\n","import {useDecorators} from \"@tsed/core\";\nimport {Property} from \"@tsed/schema\";\nimport {defineStaticGetter} from \"../utils/defineStaticGetter\";\nimport {ColumnOptions} from \"./columnOptions\";\n\n/**\n *\n * @param type\n * @decorator\n * @objection\n */\nexport function IdColumn(type: \"increments\" | \"bigIncrements\" = \"increments\"): PropertyDecorator {\n return useDecorators(\n Property(),\n ColumnOptions({\n columnType: \"idColumn\",\n options: {\n type\n }\n }),\n (target: any, propertyKey: string) => {\n defineStaticGetter(target, \"idColumn\", () => propertyKey);\n }\n );\n}\n","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","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","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","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"],"names":["ColumnTypesContainer","Map","createStringColumn","table","entity","schema","string","propertyName","maxLength","set","createIdColumn","options","type","bigIncrements","primary","increments","createBooleanColumn","boolean","createNumberColumn","decimal","precision","scale","defineStaticGetter","target","propertyKey","fn","Object","defineProperty","classOf","get","Entity","tableName","Error","getJsonSchema","ColumnOptions","StoreSet","Decimal","useDecorators","Property","columnType","IdColumn","createConnection","connectionOptions","connection","knex","Model","OBJECTION_CONNECTION","Symbol","for","registerProvider","provide","deps","Configuration","useAsyncFactory","configuration","er","console","error","getColumnCtx","toJSON","store","createColumn","ctx","has","getColumns","model","getProperties","withIgnoredProps","objection","groups","values","createColumns","map"],"mappings":";;;;;;;;;;AAGA;;;AAGO,MAAMA,oBAAoB,GAAoE,IAAIC,GAAJ,EAA9F;;ACFP;;;;SAGgBC,mBAAmBC,OAA0B;AAACC,EAAAA,MAAD;AAASC,EAAAA;AAAT;AAC3DF,EAAAA,KAAK,CAACG,MAAN,CAAaF,MAAM,CAACG,YAApB,EAAkCF,MAAM,CAACG,SAAzC;AACD;AAEDR,oBAAoB,CAACS,GAArB,CAAyB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J,CAAP;AACD;AAED;;;;SAGgBC,cAAcpE,OAA0B8D;AACtDD,EAAAA,UAAU,CAACC,KAAD,CAAV,CAAkBO,GAAlB,CAAuBpE,MAAD;AACpByD,IAAAA,YAAY,CAAC1D,KAAD,EAAQC,MAAR,CAAZ;AACD,GAFD;AAGD;;;;;;;;;;;;;;;;;"}
@@ -1,240 +0,0 @@
1
- import { getJsonSchema, Property, getProperties } from '@tsed/schema';
2
- import { classOf, StoreSet, useDecorators } from '@tsed/core';
3
- import { registerProvider, Configuration } from '@tsed/di';
4
- import knex from 'knex';
5
- import { Model } from 'objection';
6
-
7
- /**
8
- * @ignore
9
- */
10
- const ColumnTypesContainer = new Map();
11
-
12
- /**
13
- * @ignore
14
- */
15
-
16
- function createStringColumn(table, {
17
- entity,
18
- schema
19
- }) {
20
- table.string(entity.propertyName, schema.maxLength);
21
- }
22
- ColumnTypesContainer.set("string", createStringColumn);
23
-
24
- /**
25
- * @ignore
26
- */
27
-
28
- function createIdColumn(table, {
29
- entity,
30
- options
31
- }) {
32
- if (options.type === "bigIncrements") {
33
- table.bigIncrements(entity.propertyName).primary();
34
- } else {
35
- table.increments(entity.propertyName).primary();
36
- }
37
- }
38
- ColumnTypesContainer.set("idColumn", createIdColumn);
39
-
40
- /**
41
- * @ignore
42
- */
43
-
44
- function createBooleanColumn(table, {
45
- entity
46
- }) {
47
- table.boolean(entity.propertyName);
48
- }
49
- ColumnTypesContainer.set("boolean", createBooleanColumn);
50
-
51
- /**
52
- * @ignore
53
- */
54
-
55
- function createNumberColumn(table, {
56
- entity,
57
- options
58
- }) {
59
- table.decimal(entity.propertyName, options.precision, options.scale);
60
- }
61
- ColumnTypesContainer.set("number", createNumberColumn);
62
-
63
- /**
64
- * @ignore
65
- */
66
-
67
- function defineStaticGetter(target, propertyKey, fn) {
68
- return Object.defineProperty(classOf(target), propertyKey, {
69
- get: fn
70
- });
71
- }
72
-
73
- /**
74
- *
75
- * @param tableName
76
- * @decorator
77
- * @objection
78
- */
79
-
80
- function Entity(tableName) {
81
- if (!tableName) {
82
- throw new Error("Please provide a table name");
83
- }
84
-
85
- return target => {
86
- defineStaticGetter(target, "tableName", () => tableName);
87
- defineStaticGetter(target, "jsonSchema", () => getJsonSchema(target));
88
- return target;
89
- };
90
- }
91
-
92
- function _extends() {
93
- _extends = Object.assign || function (target) {
94
- for (var i = 1; i < arguments.length; i++) {
95
- var source = arguments[i];
96
-
97
- for (var key in source) {
98
- if (Object.prototype.hasOwnProperty.call(source, key)) {
99
- target[key] = source[key];
100
- }
101
- }
102
- }
103
-
104
- return target;
105
- };
106
-
107
- return _extends.apply(this, arguments);
108
- }
109
-
110
- /**
111
- *
112
- * @param options
113
- * @decorator
114
- * @objection
115
- */
116
-
117
- function ColumnOptions(options) {
118
- return StoreSet("objection", options);
119
- }
120
-
121
- /**
122
- *
123
- * @param options
124
- * @decorator
125
- * @objection
126
- */
127
-
128
- function Decimal(options = {}) {
129
- return useDecorators(Property(), ColumnOptions({
130
- columnType: "number",
131
- options: _extends({
132
- type: "decimal"
133
- }, options)
134
- }), StoreSet("objection", {
135
- columnType: "number",
136
- options: _extends({
137
- type: "decimal"
138
- }, options)
139
- }));
140
- }
141
-
142
- /**
143
- *
144
- * @param type
145
- * @decorator
146
- * @objection
147
- */
148
-
149
- function IdColumn(type = "increments") {
150
- return useDecorators(Property(), ColumnOptions({
151
- columnType: "idColumn",
152
- options: {
153
- type
154
- }
155
- }), (target, propertyKey) => {
156
- defineStaticGetter(target, "idColumn", () => propertyKey);
157
- });
158
- }
159
-
160
- function createConnection(connectionOptions) {
161
- const connection = knex(connectionOptions);
162
- Model.knex(connection);
163
- return connection;
164
- }
165
-
166
- const OBJECTION_CONNECTION = Symbol.for("DEFAULT_CONNECTION");
167
- registerProvider({
168
- provide: OBJECTION_CONNECTION,
169
- deps: [Configuration],
170
-
171
- async useAsyncFactory(configuration) {
172
- const connectionOptions = configuration.get("knex");
173
-
174
- if (connectionOptions) {
175
- try {
176
- return createConnection(connectionOptions);
177
- } catch (er) {
178
- // istanbul ignore next
179
- console.error(er);
180
- }
181
- }
182
-
183
- return {};
184
- }
185
-
186
- });
187
-
188
- /**
189
- * @ignore
190
- */
191
- function getColumnCtx(entity) {
192
- const schema = entity.schema.toJSON();
193
- const {
194
- columnType = schema.type,
195
- options = {}
196
- } = entity.store.get("objection", {});
197
- return {
198
- entity,
199
- columnType,
200
- options,
201
- schema
202
- };
203
- }
204
-
205
- /**
206
- * @ignore
207
- */
208
-
209
- function createColumn(table, entity) {
210
- const ctx = getColumnCtx(entity);
211
-
212
- if (!ColumnTypesContainer.has(ctx.columnType)) {
213
- throw `Column type ${ctx.columnType} isn't supported. Add function to ColumnTypesContainer to map the column with Knex`;
214
- }
215
-
216
- ColumnTypesContainer.get(ctx.columnType)(table, ctx);
217
- }
218
- /**
219
- * @ignore
220
- */
221
-
222
- function getColumns(model) {
223
- return [...getProperties(model, {
224
- withIgnoredProps: true,
225
- objection: true,
226
- groups: false
227
- }).values()];
228
- }
229
- /**
230
- * @ignore
231
- */
232
-
233
- function createColumns(table, model) {
234
- getColumns(model).map(entity => {
235
- createColumn(table, entity);
236
- });
237
- }
238
-
239
- export { ColumnOptions, Decimal, Entity, IdColumn, OBJECTION_CONNECTION, createBooleanColumn, createColumn, createColumns, createConnection, createIdColumn, createNumberColumn, createStringColumn, getColumnCtx, getColumns };
240
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/services/ColumnTypesContainer.ts","../src/components/createStringColumn.ts","../src/components/createIdColumn.ts","../src/components/createBooleanColumn.ts","../src/components/createNumberColumn.ts","../src/utils/defineStaticGetter.ts","../src/decorators/entity.ts","../src/decorators/columnOptions.ts","../src/decorators/decimal.ts","../src/decorators/idColumn.ts","../src/utils/connect.ts","../src/services/ObjectionConnection.ts","../src/utils/getColumnCtx.ts","../src/utils/createColumns.ts"],"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","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createStringColumn(table: Knex.TableBuilder, {entity, schema}: ColumnCtx) {\n table.string(entity.propertyName, schema.maxLength);\n}\n\nColumnTypesContainer.set(\"string\", createStringColumn);\n","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createIdColumn(table: Knex.TableBuilder, {entity, options}: ColumnCtx) {\n if (options.type === \"bigIncrements\") {\n table.bigIncrements(entity.propertyName).primary();\n } else {\n table.increments(entity.propertyName).primary();\n }\n}\n\nColumnTypesContainer.set(\"idColumn\", createIdColumn);\n","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n/**\n * @ignore\n */\nexport function createBooleanColumn(table: Knex.TableBuilder, {entity}: ColumnCtx) {\n table.boolean(entity.propertyName);\n}\n\nColumnTypesContainer.set(\"boolean\", createBooleanColumn);\n","import type {Knex} from \"knex\";\nimport {ColumnTypesContainer} from \"../services/ColumnTypesContainer\";\nimport {ColumnCtx} from \"../utils/getColumnCtx\";\n\n/**\n * @ignore\n */\nexport function createNumberColumn(table: Knex.TableBuilder, {entity, options}: ColumnCtx) {\n table.decimal(entity.propertyName, options.precision, options.scale);\n}\n\nColumnTypesContainer.set(\"number\", createNumberColumn);\n","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","import {Type} from \"@tsed/core\";\nimport {getJsonSchema} from \"@tsed/schema\";\nimport {defineStaticGetter} from \"../utils/defineStaticGetter\";\n\n/**\n *\n * @param tableName\n * @decorator\n * @objection\n */\nexport function Entity(tableName: string): ClassDecorator {\n if (!tableName) {\n throw new Error(\"Please provide a table name\");\n }\n\n return (target: any) => {\n defineStaticGetter(target, \"tableName\", () => tableName);\n defineStaticGetter(target, \"jsonSchema\", () => getJsonSchema(target));\n\n return target;\n };\n}\n\nexport interface EntityMethods<T> extends Type<T> {\n readonly tableName: string;\n}\n","import {StoreSet} from \"@tsed/core\";\nimport type {ColumnOpts} from \"../domain/ColumnOpts\";\n\n/**\n *\n * @param options\n * @decorator\n * @objection\n */\nexport function ColumnOptions(options: Partial<ColumnOpts>): PropertyDecorator {\n return StoreSet(\"objection\", options) as any;\n}\n","import {StoreSet, useDecorators} from \"@tsed/core\";\nimport {Property} from \"@tsed/schema\";\nimport {ColumnOptions} from \"./columnOptions\";\n\nexport interface DecimalOptions {\n precision?: number | null;\n scale?: number;\n}\n\n/**\n *\n * @param options\n * @decorator\n * @objection\n */\nexport function Decimal(options: DecimalOptions = {}) {\n return useDecorators(\n Property(),\n ColumnOptions({\n columnType: \"number\",\n options: {\n type: \"decimal\",\n ...options\n }\n }),\n StoreSet(\"objection\", {\n columnType: \"number\",\n options: {\n type: \"decimal\",\n ...options\n }\n })\n );\n}\n","import {useDecorators} from \"@tsed/core\";\nimport {Property} from \"@tsed/schema\";\nimport {defineStaticGetter} from \"../utils/defineStaticGetter\";\nimport {ColumnOptions} from \"./columnOptions\";\n\n/**\n *\n * @param type\n * @decorator\n * @objection\n */\nexport function IdColumn(type: \"increments\" | \"bigIncrements\" = \"increments\"): PropertyDecorator {\n return useDecorators(\n Property(),\n ColumnOptions({\n columnType: \"idColumn\",\n options: {\n type\n }\n }),\n (target: any, propertyKey: string) => {\n defineStaticGetter(target, \"idColumn\", () => propertyKey);\n }\n );\n}\n","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","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","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","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"],"names":["ColumnTypesContainer","Map","createStringColumn","table","entity","schema","string","propertyName","maxLength","set","createIdColumn","options","type","bigIncrements","primary","increments","createBooleanColumn","boolean","createNumberColumn","decimal","precision","scale","defineStaticGetter","target","propertyKey","fn","Object","defineProperty","classOf","get","Entity","tableName","Error","getJsonSchema","ColumnOptions","StoreSet","Decimal","useDecorators","Property","columnType","IdColumn","createConnection","connectionOptions","connection","knex","Model","OBJECTION_CONNECTION","Symbol","for","registerProvider","provide","deps","Configuration","useAsyncFactory","configuration","er","console","error","getColumnCtx","toJSON","store","createColumn","ctx","has","getColumns","model","getProperties","withIgnoredProps","objection","groups","values","createColumns","map"],"mappings":";;;;;;AAGA;;;AAGO,MAAMA,oBAAoB,GAAoE,IAAIC,GAAJ,EAA9F;;ACFP;;;;SAGgBC,mBAAmBC,OAA0B;AAACC,EAAAA,MAAD;AAASC,EAAAA;AAAT;AAC3DF,EAAAA,KAAK,CAACG,MAAN,CAAaF,MAAM,CAACG,YAApB,EAAkCF,MAAM,CAACG,SAAzC;AACD;AAEDR,oBAAoB,CAACS,GAArB,CAAyB,QAAzB,EAAmCP,kBAAnC;;ACPA;;;;SAGgBQ,eAAeP,OAA0B;AAACC,EAAAA,MAAD;AAASO,EAAAA;AAAT;AACvD,MAAIA,OAAO,CAACC,IAAR,KAAiB,eAArB,EAAsC;AACpCT,IAAAA,KAAK,CAACU,aAAN,CAAoBT,MAAM,CAACG,YAA3B,EAAyCO,OAAzC;AACD,GAFD,MAEO;AACLX,IAAAA,KAAK,CAACY,UAAN,CAAiBX,MAAM,CAACG,YAAxB,EAAsCO,OAAtC;AACD;AACF;AAEDd,oBAAoB,CAACS,GAArB,CAAyB,UAAzB,EAAqCC,cAArC;;ACZA;;;;SAGgBM,oBAAoBb,OAA0B;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