@biorate/sequelize 1.159.0 → 2.0.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 (58) hide show
  1. package/dist/{index.js → cjs/index.js} +0 -1
  2. package/dist/cjs/package.json +3 -0
  3. package/dist/{src → cjs/src}/errors.js +0 -1
  4. package/dist/{src → cjs/src}/index.js +0 -1
  5. package/dist/{src → cjs/src}/interfaces.js +0 -1
  6. package/dist/esm/index.js +1 -0
  7. package/dist/esm/package.json +3 -0
  8. package/dist/esm/src/errors.js +11 -0
  9. package/dist/esm/src/index.js +47 -0
  10. package/dist/esm/src/interfaces.js +1 -0
  11. package/dist/types/src/errors.d.ts +7 -0
  12. package/dist/types/src/index.d.ts +23 -0
  13. package/{src/interfaces.ts → dist/types/src/interfaces.d.ts} +10 -12
  14. package/package.json +34 -9
  15. package/.nyc_output/7d273a30-bdb1-4134-9bd0-c8b150a04af0.json +0 -1
  16. package/.nyc_output/df0b2ef8-f769-4750-bf53-017bcbc1d748.json +0 -1
  17. package/.nyc_output/f45374f3-8bca-43e8-b395-9d5aabdd0549.json +0 -1
  18. package/.nyc_output/processinfo/7d273a30-bdb1-4134-9bd0-c8b150a04af0.json +0 -1
  19. package/.nyc_output/processinfo/df0b2ef8-f769-4750-bf53-017bcbc1d748.json +0 -1
  20. package/.nyc_output/processinfo/f45374f3-8bca-43e8-b395-9d5aabdd0549.json +0 -1
  21. package/.nyc_output/processinfo/index.json +0 -1
  22. package/CHANGELOG.md +0 -625
  23. package/allure-results/14a446bd-8240-41f3-918b-87c1fff2ff12-result.json +0 -1
  24. package/allure-results/203b83fb-2330-4fc2-8ad3-026c7ae90805-result.json +0 -1
  25. package/allure-results/2bae4767-1549-49e0-80da-d819586b0b7e-container.json +0 -1
  26. package/allure-results/44e53edc-760f-44aa-a7fa-ab8f2c6eda6b-result.json +0 -1
  27. package/allure-results/6e4d9fce-1ce3-4dce-ac66-29b95b177f4c-container.json +0 -1
  28. package/allure-results/cc97c180-ee25-4451-a851-2d0f7c766639-result.json +0 -1
  29. package/coverage/base.css +0 -224
  30. package/coverage/block-navigation.js +0 -87
  31. package/coverage/clover.xml +0 -62
  32. package/coverage/coverage-final.json +0 -7
  33. package/coverage/favicon.png +0 -0
  34. package/coverage/index.html +0 -146
  35. package/coverage/prettify.css +0 -1
  36. package/coverage/prettify.js +0 -2
  37. package/coverage/sort-arrow-sprite.png +0 -0
  38. package/coverage/sorter.js +0 -210
  39. package/coverage/src/errors.ts.html +0 -124
  40. package/coverage/src/index.html +0 -146
  41. package/coverage/src/index.ts.html +0 -523
  42. package/coverage/src/interfaces.ts.html +0 -148
  43. package/coverage/tests/__mocks__/index.html +0 -116
  44. package/coverage/tests/__mocks__/index.ts.html +0 -205
  45. package/coverage/tests/__mocks__/models/index.html +0 -131
  46. package/coverage/tests/__mocks__/models/index.ts.html +0 -88
  47. package/coverage/tests/__mocks__/models/test.ts.html +0 -124
  48. package/dist/index.js.map +0 -1
  49. package/dist/src/errors.js.map +0 -1
  50. package/dist/src/index.js.map +0 -1
  51. package/dist/src/interfaces.js.map +0 -1
  52. package/dist/tsconfig.build.tsbuildinfo +0 -1
  53. package/index.d.ts +0 -23
  54. package/src/errors.ts +0 -13
  55. package/src/index.ts +0 -146
  56. package/tsconfig.build.json +0 -5
  57. package/tsconfig.json +0 -9
  58. /package/{index.ts → dist/types/index.d.ts} +0 -0
package/src/index.ts DELETED
@@ -1,146 +0,0 @@
1
- import { injectable } from '@biorate/inversion';
2
- import { Connector } from '@biorate/connector';
3
- import { Sequelize } from 'sequelize-typescript';
4
- import { QueryTypes, QueryOptions, QueryOptionsWithType } from 'sequelize';
5
- import { omit } from 'lodash';
6
- import { SequelizeCantConnectError, UndefinedConnectionError } from './errors';
7
- import { ISequelizeConfig, ISequelizeConnection, IModels } from './interfaces';
8
-
9
- export * from './errors';
10
- export * from './interfaces';
11
- export * from 'sequelize-typescript';
12
- export {
13
- QueryTypes,
14
- QueryOptions,
15
- QueryOptionsWithType,
16
- Transaction,
17
- TransactionOptions,
18
- Op,
19
- } from 'sequelize';
20
-
21
- /**
22
- * @description Sequelize ORM connector
23
- *
24
- * ### Features:
25
- * - connector manager for sequelize
26
- *
27
- * @example
28
- * ```
29
- * import { join } from 'path';
30
- * import { tmpdir } from 'os';
31
- * import { container, Core, inject, Types } from '@biorate/inversion';
32
- * import { Config, IConfig } from '@biorate/config';
33
- * import { ISequelizeConnector, SequelizeConnector as BaseSequelizeConnector } from '@biorate/sequelize';
34
- * import { Table, Column, Model, DataType } from '@biorate/sequelize';
35
- *
36
- * const connectionName = 'db';
37
- *
38
- * // Create model
39
- * @Table({
40
- * tableName: 'test',
41
- * timestamps: false,
42
- * })
43
- * export class TestModel extends Model {
44
- * @Column({ type: DataType.CHAR, primaryKey: true })
45
- * key: string;
46
- *
47
- * @Column(DataType.INTEGER)
48
- * value: number;
49
- * }
50
- *
51
- * // Assign models with sequelize connector
52
- * class SequelizeConnector extends BaseSequelizeConnector {
53
- * protected readonly models = { [connectionName]: [TestModel] };
54
- * }
55
- *
56
- * // Create Root class
57
- * export class Root extends Core() {
58
- * @inject(SequelizeConnector) public connector: ISequelizeConnector;
59
- * }
60
- *
61
- * // Bind dependencies
62
- * container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
63
- * container.bind<ISequelizeConnector>(SequelizeConnector).toSelf().inSingletonScope();
64
- * container.bind<Root>(Root).toSelf().inSingletonScope();
65
- *
66
- * // Merge config
67
- * container.get<IConfig>(Types.Config).merge({
68
- * Sequelize: [
69
- * {
70
- * name: connectionName,
71
- * options: {
72
- * logging: false,
73
- * dialect: 'sqlite',
74
- * storage: join(tmpdir(), 'sqlite-test.db'),
75
- * },
76
- * },
77
- * ],
78
- * });
79
- *
80
- * // Example
81
- * (async () => {
82
- * await container.get<Root>(Root).$run();
83
- * // Drop table if exists
84
- * await TestModel.drop();
85
- * // Create table
86
- * await TestModel.sync();
87
- * // Create model item
88
- * await TestModel.create({ key: 'test', value: 1 });
89
- * // Create find model item by key
90
- * const data = await TestModel.findOne({ where: { key: 'test' } });
91
- * console.log(data.toJSON()); // { key: 'test', value: 1 }
92
- * })();
93
- * ```
94
- */
95
- @injectable()
96
- export class SequelizeConnector extends Connector<
97
- ISequelizeConfig,
98
- ISequelizeConnection
99
- > {
100
- /**
101
- * @description Private connections storage
102
- */
103
- private '#connections': Map<string, ISequelizeConnection>;
104
- /**
105
- * @description Private link to selected (used) connection
106
- */
107
- private '#current': ISequelizeConnection | undefined;
108
- /**
109
- * @description Namespace path for fetching configuration
110
- */
111
- protected readonly namespace = 'Sequelize';
112
- /**
113
- * @description Models list, key - connection name, value - array of models
114
- */
115
- protected readonly models: { [key: string]: IModels } = {};
116
- /**
117
- * @description Create connection
118
- */
119
- protected async connect(config: ISequelizeConfig) {
120
- let connection: ISequelizeConnection;
121
- try {
122
- config.options.models = this.models[config.name] ?? [];
123
- connection = new Sequelize(config.options);
124
- await connection.authenticate();
125
- } catch (e: unknown) {
126
- throw new SequelizeCantConnectError(<Error>e);
127
- }
128
- return connection;
129
- }
130
- /**
131
- * @description Execute query on current connection
132
- */
133
- public async query<T = unknown>(
134
- sql: string | { query: string; values: unknown[] },
135
- options: (QueryOptions | QueryOptionsWithType<QueryTypes.RAW>) & {
136
- connection?: string;
137
- } = {},
138
- ): Promise<T[]> {
139
- const name = options?.connection;
140
- omit(options, 'connection');
141
- const connection = this.connection(name);
142
- if (!connection) throw new UndefinedConnectionError(name);
143
- const result = await connection.query(sql, options);
144
- return result[0] as T[];
145
- }
146
- }
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["index.ts", "src/**/*"],
4
- "exclude": ["node_modules", "dist", "tests", "**/*spec.ts"]
5
- }
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json",
3
- "compilerOptions": {
4
- "strict": true,
5
- "strictPropertyInitialization": false
6
- },
7
- "include": ["index.ts", "src/**/*", "tests/**/*"],
8
- "exclude": ["node_modules", "dist"]
9
- }
File without changes