@loopback/sequelize 0.1.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 (87) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +194 -0
  3. package/dist/.sandbox/6646miobBk/application.js +15 -0
  4. package/dist/.sandbox/6646miobBk/controllers/book-category.controller.js +41 -0
  5. package/dist/.sandbox/6646miobBk/controllers/book.controller.js +210 -0
  6. package/dist/.sandbox/6646miobBk/controllers/category.controller.js +198 -0
  7. package/dist/.sandbox/6646miobBk/controllers/developer.controller.js +177 -0
  8. package/dist/.sandbox/6646miobBk/controllers/doctor-patient.controller.js +112 -0
  9. package/dist/.sandbox/6646miobBk/controllers/doctor.controller.js +177 -0
  10. package/dist/.sandbox/6646miobBk/controllers/index.js +20 -0
  11. package/dist/.sandbox/6646miobBk/controllers/patient.controller.js +165 -0
  12. package/dist/.sandbox/6646miobBk/controllers/programming-languange.controller.js +204 -0
  13. package/dist/.sandbox/6646miobBk/controllers/test.controller.base.js +25 -0
  14. package/dist/.sandbox/6646miobBk/controllers/todo-list-todo.controller.js +113 -0
  15. package/dist/.sandbox/6646miobBk/controllers/todo-list.controller.js +177 -0
  16. package/dist/.sandbox/6646miobBk/controllers/todo-todo-list.controller.js +41 -0
  17. package/dist/.sandbox/6646miobBk/controllers/todo.controller.js +177 -0
  18. package/dist/.sandbox/6646miobBk/controllers/user-todo-list.controller.js +113 -0
  19. package/dist/.sandbox/6646miobBk/controllers/user.controller.js +210 -0
  20. package/dist/.sandbox/6646miobBk/datasources/db.datasource.js +28 -0
  21. package/dist/.sandbox/6646miobBk/models/appointment.model.js +37 -0
  22. package/dist/.sandbox/6646miobBk/models/book.model.js +48 -0
  23. package/dist/.sandbox/6646miobBk/models/category.model.js +32 -0
  24. package/dist/.sandbox/6646miobBk/models/developer.model.js +40 -0
  25. package/dist/.sandbox/6646miobBk/models/doctor.model.js +44 -0
  26. package/dist/.sandbox/6646miobBk/models/index.js +15 -0
  27. package/dist/.sandbox/6646miobBk/models/patient.model.js +32 -0
  28. package/dist/.sandbox/6646miobBk/models/programming-language.model.js +32 -0
  29. package/dist/.sandbox/6646miobBk/models/todo-list.model.js +45 -0
  30. package/dist/.sandbox/6646miobBk/models/todo.model.js +44 -0
  31. package/dist/.sandbox/6646miobBk/models/user.model.js +85 -0
  32. package/dist/.sandbox/6646miobBk/repositories/appointment.repository.js +20 -0
  33. package/dist/.sandbox/6646miobBk/repositories/book.repository.js +25 -0
  34. package/dist/.sandbox/6646miobBk/repositories/category.repository.js +20 -0
  35. package/dist/.sandbox/6646miobBk/repositories/developer.repository.js +25 -0
  36. package/dist/.sandbox/6646miobBk/repositories/doctor.repository.js +27 -0
  37. package/dist/.sandbox/6646miobBk/repositories/index.js +15 -0
  38. package/dist/.sandbox/6646miobBk/repositories/patient.repository.js +20 -0
  39. package/dist/.sandbox/6646miobBk/repositories/programming-language.repository.js +20 -0
  40. package/dist/.sandbox/6646miobBk/repositories/todo-list.repository.js +25 -0
  41. package/dist/.sandbox/6646miobBk/repositories/todo.repository.js +25 -0
  42. package/dist/.sandbox/6646miobBk/repositories/user.repository.js +29 -0
  43. package/dist/component.d.ts +7 -0
  44. package/dist/component.js +30 -0
  45. package/dist/component.js.map +1 -0
  46. package/dist/index.d.ts +4 -0
  47. package/dist/index.js +12 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/keys.d.ts +8 -0
  50. package/dist/keys.js +16 -0
  51. package/dist/keys.js.map +1 -0
  52. package/dist/sequelize/connector-mapping.d.ts +9 -0
  53. package/dist/sequelize/connector-mapping.js +19 -0
  54. package/dist/sequelize/connector-mapping.js.map +1 -0
  55. package/dist/sequelize/index.d.ts +2 -0
  56. package/dist/sequelize/index.js +10 -0
  57. package/dist/sequelize/index.js.map +1 -0
  58. package/dist/sequelize/operator-translation.d.ts +8 -0
  59. package/dist/sequelize/operator-translation.js +31 -0
  60. package/dist/sequelize/operator-translation.js.map +1 -0
  61. package/dist/sequelize/sequelize.datasource.base.d.ts +23 -0
  62. package/dist/sequelize/sequelize.datasource.base.js +60 -0
  63. package/dist/sequelize/sequelize.datasource.base.js.map +1 -0
  64. package/dist/sequelize/sequelize.model.d.ts +7 -0
  65. package/dist/sequelize/sequelize.model.js +24 -0
  66. package/dist/sequelize/sequelize.model.js.map +1 -0
  67. package/dist/sequelize/sequelize.repository.base.d.ts +231 -0
  68. package/dist/sequelize/sequelize.repository.base.js +835 -0
  69. package/dist/sequelize/sequelize.repository.base.js.map +1 -0
  70. package/dist/sequelize/utils.d.ts +6 -0
  71. package/dist/sequelize/utils.js +17 -0
  72. package/dist/sequelize/utils.js.map +1 -0
  73. package/dist/types.d.ts +9 -0
  74. package/dist/types.js +14 -0
  75. package/dist/types.js.map +1 -0
  76. package/package.json +64 -0
  77. package/src/component.ts +34 -0
  78. package/src/index.ts +9 -0
  79. package/src/keys.ts +16 -0
  80. package/src/sequelize/connector-mapping.ts +26 -0
  81. package/src/sequelize/index.ts +7 -0
  82. package/src/sequelize/operator-translation.ts +32 -0
  83. package/src/sequelize/sequelize.datasource.base.ts +81 -0
  84. package/src/sequelize/sequelize.model.ts +22 -0
  85. package/src/sequelize/sequelize.repository.base.ts +1246 -0
  86. package/src/sequelize/utils.ts +13 -0
  87. package/src/types.ts +19 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAQwB;AACxB,iCAA0D;AAC1D,mCAGiB;AAEjB,uDAAuD;AAMhD,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACrC,YAEU,WAAwB,EAExB,UAA6C,0CAAkC;QAF/E,gBAAW,GAAX,WAAW,CAAa;QAExB,YAAO,GAAP,OAAO,CAAwE;IACtF,CAAC;CACL,CAAA;AAPY,0BAA0B;IALtC,IAAA,iBAAU,EAAC;QACV,IAAI,EAAE;YACJ,CAAC,kBAAW,CAAC,GAAG,CAAC,EAAE,yCAAkC,CAAC,SAAS;SAChE;KACF,CAAC;IAGG,mBAAA,IAAA,aAAM,EAAC,mBAAY,CAAC,oBAAoB,CAAC,CAAA;IAEzC,mBAAA,IAAA,aAAM,GAAE,CAAA;6CADY,kBAAW;GAHvB,0BAA0B,CAOtC;AAPY,gEAA0B"}
@@ -0,0 +1,4 @@
1
+ export * from './component';
2
+ export * from './keys';
3
+ export * from './sequelize';
4
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // Copyright LoopBack contributors 2022. All Rights Reserved.
3
+ // Node module: @loopback/sequelize
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const tslib_1 = require("tslib");
8
+ tslib_1.__exportStar(require("./component"), exports);
9
+ tslib_1.__exportStar(require("./keys"), exports);
10
+ tslib_1.__exportStar(require("./sequelize"), exports);
11
+ tslib_1.__exportStar(require("./types"), exports);
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,sDAA4B;AAC5B,iDAAuB;AACvB,sDAA4B;AAC5B,kDAAwB"}
package/dist/keys.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { BindingKey } from '@loopback/core';
2
+ import { LoopbackSequelizeComponent } from './component';
3
+ /**
4
+ * Binding keys used by this component.
5
+ */
6
+ export declare namespace LoopbackSequelizeComponentBindings {
7
+ const COMPONENT: BindingKey<LoopbackSequelizeComponent>;
8
+ }
package/dist/keys.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ // Copyright LoopBack contributors 2022. All Rights Reserved.
3
+ // Node module: @loopback/sequelize
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.LoopbackSequelizeComponentBindings = void 0;
8
+ const core_1 = require("@loopback/core");
9
+ /**
10
+ * Binding keys used by this component.
11
+ */
12
+ var LoopbackSequelizeComponentBindings;
13
+ (function (LoopbackSequelizeComponentBindings) {
14
+ LoopbackSequelizeComponentBindings.COMPONENT = core_1.BindingKey.create(`${core_1.CoreBindings.COMPONENTS}.LoopbackSequelizeComponent`);
15
+ })(LoopbackSequelizeComponentBindings = exports.LoopbackSequelizeComponentBindings || (exports.LoopbackSequelizeComponentBindings = {}));
16
+ //# sourceMappingURL=keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,yCAAwD;AAGxD;;GAEG;AACH,IAAiB,kCAAkC,CAIlD;AAJD,WAAiB,kCAAkC;IACpC,4CAAS,GAAG,iBAAU,CAAC,MAAM,CACxC,GAAG,mBAAY,CAAC,UAAU,6BAA6B,CACxD,CAAC;AACJ,CAAC,EAJgB,kCAAkC,GAAlC,0CAAkC,KAAlC,0CAAkC,QAIlD"}
@@ -0,0 +1,9 @@
1
+ import { Dialect as AllSequelizeDialects } from 'sequelize';
2
+ export type SupportedLoopbackConnectors = 'mysql' | 'postgresql' | 'oracle' | 'sqlite3' | 'db2';
3
+ /**
4
+ * @key Loopback connectors name supported by this extension
5
+ * @value Equivalent Dialect in Sequelize
6
+ */
7
+ export declare const SupportedConnectorMapping: {
8
+ [key in SupportedLoopbackConnectors]?: AllSequelizeDialects;
9
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ // Copyright LoopBack contributors 2022. All Rights Reserved.
3
+ // Node module: @loopback/sequelize
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SupportedConnectorMapping = void 0;
8
+ /**
9
+ * @key Loopback connectors name supported by this extension
10
+ * @value Equivalent Dialect in Sequelize
11
+ */
12
+ exports.SupportedConnectorMapping = {
13
+ mysql: 'mysql',
14
+ postgresql: 'postgres',
15
+ oracle: 'oracle',
16
+ sqlite3: 'sqlite',
17
+ db2: 'db2',
18
+ };
19
+ //# sourceMappingURL=connector-mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-mapping.js","sourceRoot":"","sources":["../../src/sequelize/connector-mapping.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAUhE;;;GAGG;AACU,QAAA,yBAAyB,GAElC;IACF,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,UAAU;IACtB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,GAAG,EAAE,KAAK;CACX,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './sequelize.datasource.base';
2
+ export * from './sequelize.repository.base';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ // Copyright LoopBack contributors 2022. All Rights Reserved.
3
+ // Node module: @loopback/sequelize
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const tslib_1 = require("tslib");
8
+ tslib_1.__exportStar(require("./sequelize.datasource.base"), exports);
9
+ tslib_1.__exportStar(require("./sequelize.repository.base"), exports);
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sequelize/index.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,sEAA4C;AAC5C,sEAA4C"}
@@ -0,0 +1,8 @@
1
+ import { Operators } from '@loopback/repository';
2
+ /**
3
+ * @key Operator used in loopback
4
+ * @value Equivalent operator in Sequelize
5
+ */
6
+ export declare const operatorTranslations: {
7
+ [key in Operators]?: symbol;
8
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ // Copyright LoopBack contributors 2022. All Rights Reserved.
3
+ // Node module: @loopback/sequelize
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.operatorTranslations = void 0;
8
+ const sequelize_1 = require("sequelize");
9
+ /**
10
+ * @key Operator used in loopback
11
+ * @value Equivalent operator in Sequelize
12
+ */
13
+ exports.operatorTranslations = {
14
+ eq: sequelize_1.Op.eq,
15
+ gt: sequelize_1.Op.gt,
16
+ gte: sequelize_1.Op.gte,
17
+ lt: sequelize_1.Op.lt,
18
+ lte: sequelize_1.Op.lte,
19
+ neq: sequelize_1.Op.ne,
20
+ between: sequelize_1.Op.between,
21
+ inq: sequelize_1.Op.in,
22
+ nin: sequelize_1.Op.notIn,
23
+ like: sequelize_1.Op.like,
24
+ nlike: sequelize_1.Op.notLike,
25
+ ilike: sequelize_1.Op.iLike,
26
+ nilike: sequelize_1.Op.notILike,
27
+ regexp: sequelize_1.Op.regexp,
28
+ and: sequelize_1.Op.and,
29
+ or: sequelize_1.Op.or,
30
+ };
31
+ //# sourceMappingURL=operator-translation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operator-translation.js","sourceRoot":"","sources":["../../src/sequelize/operator-translation.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAGhE,yCAA6B;AAE7B;;;GAGG;AACU,QAAA,oBAAoB,GAE7B;IACF,EAAE,EAAE,cAAE,CAAC,EAAE;IACT,EAAE,EAAE,cAAE,CAAC,EAAE;IACT,GAAG,EAAE,cAAE,CAAC,GAAG;IACX,EAAE,EAAE,cAAE,CAAC,EAAE;IACT,GAAG,EAAE,cAAE,CAAC,GAAG;IACX,GAAG,EAAE,cAAE,CAAC,EAAE;IACV,OAAO,EAAE,cAAE,CAAC,OAAO;IACnB,GAAG,EAAE,cAAE,CAAC,EAAE;IACV,GAAG,EAAE,cAAE,CAAC,KAAK;IACb,IAAI,EAAE,cAAE,CAAC,IAAI;IACb,KAAK,EAAE,cAAE,CAAC,OAAO;IACjB,KAAK,EAAE,cAAE,CAAC,KAAK;IACf,MAAM,EAAE,cAAE,CAAC,QAAQ;IACnB,MAAM,EAAE,cAAE,CAAC,MAAM;IACjB,GAAG,EAAE,cAAE,CAAC,GAAG;IACX,EAAE,EAAE,cAAE,CAAC,EAAE;CACV,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { LifeCycleObserver } from '@loopback/core';
2
+ import { AnyObject } from '@loopback/repository';
3
+ import { Options as SequelizeOptions, Sequelize } from 'sequelize';
4
+ import { SupportedLoopbackConnectors } from './connector-mapping';
5
+ export declare class SequelizeDataSource implements LifeCycleObserver {
6
+ config: SequelizeDataSourceConfig;
7
+ name: string;
8
+ settings: {};
9
+ constructor(config: SequelizeDataSourceConfig);
10
+ sequelize?: Sequelize;
11
+ sequelizeConfig: SequelizeDataSourceConfig;
12
+ init(): Promise<void>;
13
+ start(..._injectedArgs: unknown[]): Promise<void>;
14
+ stop(): void;
15
+ automigrate(): void;
16
+ autoupdate(): void;
17
+ }
18
+ export type SequelizeDataSourceConfig = SequelizeOptions & {
19
+ name?: string;
20
+ user?: string;
21
+ connector?: SupportedLoopbackConnectors;
22
+ url?: string;
23
+ } & AnyObject;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SequelizeDataSource = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const debug_1 = tslib_1.__importDefault(require("debug"));
6
+ const sequelize_1 = require("sequelize");
7
+ const connector_mapping_1 = require("./connector-mapping");
8
+ const debug = (0, debug_1.default)('loopback:sequelize:datasource');
9
+ const queryLogging = (0, debug_1.default)('loopback:sequelize:queries');
10
+ class SequelizeDataSource {
11
+ constructor(config) {
12
+ var _a;
13
+ this.config = config;
14
+ this.settings = {};
15
+ if (this.config.connector &&
16
+ !(this.config.connector in connector_mapping_1.SupportedConnectorMapping)) {
17
+ throw new Error(`Specified connector ${(_a = this.config.connector) !== null && _a !== void 0 ? _a : this.config.dialect} is not supported.`);
18
+ }
19
+ }
20
+ async init() {
21
+ var _a;
22
+ const connector = this.config.connector;
23
+ const storage = this.config.file;
24
+ const schema = this.config.schema;
25
+ this.sequelizeConfig = {
26
+ database: this.config.database,
27
+ ...(connector
28
+ ? { dialect: connector_mapping_1.SupportedConnectorMapping[connector] }
29
+ : {}),
30
+ ...(storage ? { storage: storage } : {}),
31
+ host: this.config.host,
32
+ port: this.config.port,
33
+ ...(schema ? { schema: schema } : {}),
34
+ username: (_a = this.config.user) !== null && _a !== void 0 ? _a : this.config.username,
35
+ password: this.config.password,
36
+ logging: queryLogging,
37
+ };
38
+ this.sequelize = new sequelize_1.Sequelize(this.sequelizeConfig);
39
+ try {
40
+ await this.sequelize.authenticate();
41
+ debug('Connection has been established successfully.');
42
+ }
43
+ catch (error) {
44
+ console.error('Unable to connect to the database:', error);
45
+ }
46
+ }
47
+ async start(..._injectedArgs) { }
48
+ stop() {
49
+ var _a, _b;
50
+ (_b = (_a = this.sequelize) === null || _a === void 0 ? void 0 : _a.close) === null || _b === void 0 ? void 0 : _b.call(_a).catch(console.error);
51
+ }
52
+ automigrate() {
53
+ throw new Error('Migrations are not supported when using SequelizeDatasource, Use `db-migrate` package instead.');
54
+ }
55
+ autoupdate() {
56
+ throw new Error('Migrations are not supported when using SequelizeDatasource, Use `db-migrate` package instead.');
57
+ }
58
+ }
59
+ exports.SequelizeDataSource = SequelizeDataSource;
60
+ //# sourceMappingURL=sequelize.datasource.base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequelize.datasource.base.js","sourceRoot":"","sources":["../../src/sequelize/sequelize.datasource.base.ts"],"names":[],"mappings":";;;;AAEA,0DAAiC;AACjC,yCAA0E;AAC1E,2DAG6B;AAE7B,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,+BAA+B,CAAC,CAAC;AAC5D,MAAM,YAAY,GAAG,IAAA,eAAY,EAAC,4BAA4B,CAAC,CAAC;AAEhE,MAAa,mBAAmB;IAG9B,YAAmB,MAAiC;;QAAjC,WAAM,GAAN,MAAM,CAA2B;QADpD,aAAQ,GAAG,EAAE,CAAC;QAEZ,IACE,IAAI,CAAC,MAAM,CAAC,SAAS;YACrB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,6CAAyB,CAAC,EACrD;YACA,MAAM,IAAI,KAAK,CACb,uBACE,MAAA,IAAI,CAAC,MAAM,CAAC,SAAS,mCAAI,IAAI,CAAC,MAAM,CAAC,OACvC,oBAAoB,CACrB,CAAC;SACH;IACH,CAAC;IAID,KAAK,CAAC,IAAI;;QACR,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAElC,IAAI,CAAC,eAAe,GAAG;YACrB,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,GAAG,CAAC,SAAS;gBACX,CAAC,CAAC,EAAC,OAAO,EAAE,6CAAyB,CAAC,SAAS,CAAY,EAAC;gBAC5D,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACtC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,QAAQ,EAAE,MAAA,IAAI,CAAC,MAAM,CAAC,IAAI,mCAAI,IAAI,CAAC,MAAM,CAAC,QAAQ;YAClD,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,OAAO,EAAE,YAAY;SACtB,CAAC;QAEF,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAErD,IAAI;YACF,MAAM,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;YACpC,KAAK,CAAC,+CAA+C,CAAC,CAAC;SACxD;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;SAC5D;IACH,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,GAAG,aAAwB,IAAkB,CAAC;IAC1D,IAAI;;QACF,MAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,KAAK,mDAAK,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;IAED,WAAW;QACT,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,CAAC;IACD,UAAU;QACR,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,CAAC;CACF;AA7DD,kDA6DC"}
@@ -0,0 +1,7 @@
1
+ import { AnyObject, Entity } from '@loopback/repository';
2
+ import { Model } from 'sequelize';
3
+ export declare class SequelizeModel extends Model implements Entity {
4
+ getId(): null;
5
+ getIdObject(): Object;
6
+ toObject(_options?: AnyObject | undefined): Object;
7
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // Copyright LoopBack contributors 2022. All Rights Reserved.
3
+ // Node module: @loopback/sequelize
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.SequelizeModel = void 0;
8
+ const sequelize_1 = require("sequelize");
9
+ class SequelizeModel extends sequelize_1.Model {
10
+ getId() {
11
+ // Method implementation not required as this class is just being used as type not a constructor
12
+ return null;
13
+ }
14
+ getIdObject() {
15
+ // Method implementation not required as this class is just being used as type not a constructor
16
+ return {};
17
+ }
18
+ toObject(_options) {
19
+ // Method implementation not required as this class is just being used as type not a constructor
20
+ return {};
21
+ }
22
+ }
23
+ exports.SequelizeModel = SequelizeModel;
24
+ //# sourceMappingURL=sequelize.model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequelize.model.js","sourceRoot":"","sources":["../../src/sequelize/sequelize.model.ts"],"names":[],"mappings":";AAAA,6DAA6D;AAC7D,mCAAmC;AACnC,+CAA+C;AAC/C,gEAAgE;;;AAGhE,yCAAgC;AAEhC,MAAa,cAAe,SAAQ,iBAAK;IACvC,KAAK;QACH,gGAAgG;QAChG,OAAO,IAAI,CAAC;IACd,CAAC;IACD,WAAW;QACT,gGAAgG;QAChG,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,QAAQ,CAAC,QAAgC;QACvC,gGAAgG;QAChG,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAbD,wCAaC"}
@@ -0,0 +1,231 @@
1
+ import { AnyObject, BelongsToAccessor, Count, DataObject, Entity, EntityCrudRepository, Fields, Filter, FilterExcludingWhere, Getter, HasManyRepositoryFactory, HasManyThroughRepositoryFactory, HasOneRepositoryFactory, InclusionFilter, InclusionResolver, PositionalParameters, PropertyDefinition, ReferencesManyAccessor, Where } from '@loopback/repository';
2
+ import { Attributes, FindAttributeOptions, Includeable, Model, ModelAttributes, ModelStatic, Order, SyncOptions, WhereOptions } from 'sequelize';
3
+ import { operatorTranslations } from './operator-translation';
4
+ import { SequelizeDataSource } from './sequelize.datasource.base';
5
+ import { SequelizeModel } from './sequelize.model';
6
+ /**
7
+ * Sequelize implementation of CRUD repository to be used with default loopback entities
8
+ * and SequelizeDataSource for SQL Databases
9
+ */
10
+ export declare class SequelizeCrudRepository<T extends Entity, ID, Relations extends object = {}> implements EntityCrudRepository<T, ID, Relations> {
11
+ entityClass: typeof Entity & {
12
+ prototype: T;
13
+ };
14
+ dataSource: SequelizeDataSource;
15
+ constructor(entityClass: typeof Entity & {
16
+ prototype: T;
17
+ }, dataSource: SequelizeDataSource);
18
+ /**
19
+ * Default `order` filter style if only column name is specified
20
+ */
21
+ readonly DEFAULT_ORDER_STYLE = "ASC";
22
+ /**
23
+ * Object keys used in models for set database specific settings.
24
+ * Example: In model property definition one can use postgresql dataType as float
25
+ * {
26
+ * type: 'number',
27
+ * postgresql: {
28
+ * dataType: 'float',
29
+ * precision: 20,
30
+ * scale: 4,
31
+ * },
32
+ * }
33
+ *
34
+ * This array of keys is used while building model definition for sequelize.
35
+ */
36
+ readonly DB_SPECIFIC_SETTINGS_KEYS: readonly ["postgresql", "mysql", "sqlite3"];
37
+ readonly inclusionResolvers: Map<string, InclusionResolver<T, Entity>>;
38
+ /**
39
+ * Sequelize Model Instance created from the model definition received from the `entityClass`
40
+ */
41
+ sequelizeModel: ModelStatic<Model<T>>;
42
+ create(entity: DataObject<T>, options?: AnyObject): Promise<T>;
43
+ createAll(entities: DataObject<T>[], options?: AnyObject): Promise<T[]>;
44
+ exists(id: ID, _options?: AnyObject): Promise<boolean>;
45
+ save(entity: T, options?: AnyObject): Promise<T>;
46
+ update(entity: T, options?: AnyObject): Promise<void>;
47
+ updateById(id: ID, data: DataObject<T>, options?: AnyObject): Promise<void>;
48
+ updateAll(data: DataObject<T>, where?: Where<T>, options?: AnyObject): Promise<Count>;
49
+ delete(entity: T, options?: AnyObject): Promise<void>;
50
+ find(filter?: Filter<T>, options?: AnyObject): Promise<(T & Relations)[]>;
51
+ findOne(filter?: Filter<T>, options?: AnyObject): Promise<(T & Relations) | null>;
52
+ findById(id: ID, filter?: FilterExcludingWhere<T>, options?: AnyObject): Promise<T & Relations>;
53
+ replaceById(id: ID, data: DataObject<T>, options?: AnyObject | undefined): Promise<void>;
54
+ deleteAll(where?: Where<T> | undefined, options?: AnyObject | undefined): Promise<Count>;
55
+ deleteById(id: ID, options?: AnyObject | undefined): Promise<void>;
56
+ count(where?: Where<T>, options?: AnyObject): Promise<Count>;
57
+ execute(..._args: PositionalParameters): Promise<AnyObject>;
58
+ protected toEntities(models: Model<T, T>[]): T[];
59
+ /**
60
+ * Get Sequelize Operator
61
+ * @param key Name of the operator used in loopback eg. lt
62
+ * @returns Equivalent operator symbol if available in Sequelize eg `Op.lt`
63
+ */
64
+ protected getSequelizeOperator(key: keyof typeof operatorTranslations): symbol;
65
+ /**
66
+ * Get Sequelize `attributes` filter value from `fields` of loopback.
67
+ * @param fields Loopback styles `fields` options. eg. `["name", "age"]`, `{ id: false }`
68
+ * @returns Sequelize Compatible Object/Array based on the fields provided. eg. `{ "exclude": ["id"] }`
69
+ */
70
+ protected buildSequelizeAttributeFilter(fields?: Fields): FindAttributeOptions | undefined;
71
+ /**
72
+ * Get Sequelize Order filter value from loopback style order value
73
+ * @param order Sorting order in loopback style filter. eg. `title ASC`, `["id DESC", "age ASC"]`
74
+ * @returns Sequelize compatible order filter value
75
+ */
76
+ protected buildSequelizeOrder(order?: string[] | string): Order | undefined;
77
+ /**
78
+ * Build Sequelize compatible `include` filter
79
+ * @param inclusionFilters - loopback style `where` condition
80
+ * @param sourceModel - sequelize model instance
81
+ * @returns Sequelize compatible `Includeable` array
82
+ */
83
+ protected buildSequelizeIncludeFilter(inclusionFilters?: Array<InclusionFilter & {
84
+ required?: boolean;
85
+ }>, sourceModel?: ModelStatic<Model<T>>): Includeable[];
86
+ /**
87
+ * Build Sequelize compatible where condition object
88
+ * @param where loopback style `where` condition
89
+ * @returns Sequelize compatible where options to be used in queries
90
+ */
91
+ protected buildSequelizeWhere<MT extends T>(where?: Where<MT>): WhereOptions<MT>;
92
+ /**
93
+ * Get Sequelize Model
94
+ * @returns Sequelize Model Instance based on the definitions from `entityClass`
95
+ */
96
+ getSequelizeModel(entityClass?: typeof Entity & {
97
+ prototype: T;
98
+ }): import("sequelize").ModelCtor<Model<any, any>> | import("sequelize").ModelCtor<SequelizeModel>;
99
+ /**
100
+ * Run CREATE TABLE query for the target sequelize model, Useful for quick testing
101
+ * @param options Sequelize Sync Options
102
+ */
103
+ syncSequelizeModel(options?: SyncOptions): Promise<void>;
104
+ /**
105
+ * Run CREATE TABLE query for the all sequelize models, Useful for quick testing
106
+ * @param options Sequelize Sync Options
107
+ */
108
+ syncLoadedSequelizeModels(options?: SyncOptions): Promise<void>;
109
+ /**
110
+ * Get Sequelize Model Attributes
111
+ * @param definition property definition received from loopback entityClass eg. `{ id: { type: "Number", id: true } }`
112
+ * @returns model attributes supported in sequelize model definiotion
113
+ *
114
+ * TODO: Verify all possible loopback types https://loopback.io/doc/en/lb4/LoopBack-types.html
115
+ */
116
+ protected getSequelizeModelAttributes(definition: {
117
+ [name: string]: PropertyDefinition;
118
+ }): ModelAttributes<SequelizeModel, Attributes<SequelizeModel>>;
119
+ /**
120
+ * Remove hidden properties specified in model from response body. (See: https://github.com/sourcefuse/loopback4-sequelize/issues/3)
121
+ * @param entity normalized entity. You can use `entity.toJSON()`'s value
122
+ * @returns normalized entity excluding the hiddenProperties
123
+ */
124
+ protected excludeHiddenProps(entity: T & Relations): T & Relations;
125
+ /**
126
+ * Include related entities of `@referencesMany` relation
127
+ *
128
+ * referencesMany relation is NOT handled by `sequelizeModel.findAll` as it doesn't have any direct alternative to it,
129
+ * so to include relation data of referencesMany, we're manually fetching related data requested
130
+ *
131
+ * @param parentEntities source table data
132
+ * @param filter actual payload passed in request
133
+ * @param parentEntityClass loopback entity class for the parent entity
134
+ * @returns entities with related models in them
135
+ */
136
+ protected includeReferencesIfRequested(parentEntities: Model<T, T>[], parentEntityClass: typeof Entity, inclusionFilters?: InclusionFilter[]): Promise<(T & Relations)[]>;
137
+ /**
138
+ * Register an inclusion resolver for the related model name.
139
+ *
140
+ * @param relationName - Name of the relation defined on the source model
141
+ * @param resolver - Resolver function for getting related model entities
142
+ */
143
+ registerInclusionResolver(relationName: string, resolver: InclusionResolver<T, Entity>): void;
144
+ /**
145
+ * Function to create a constrained relation repository factory
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * class CustomerRepository extends SequelizeCrudRepository<
150
+ * Customer,
151
+ * typeof Customer.prototype.id,
152
+ * CustomerRelations
153
+ * > {
154
+ * public readonly orders: HasManyRepositoryFactory<Order, typeof Customer.prototype.id>;
155
+ *
156
+ * constructor(
157
+ * protected db: SequelizeDataSource,
158
+ * orderRepository: EntityCrudRepository<Order, typeof Order.prototype.id>,
159
+ * ) {
160
+ * super(Customer, db);
161
+ * this.orders = this.createHasManyRepositoryFactoryFor(
162
+ * 'orders',
163
+ * orderRepository,
164
+ * );
165
+ * }
166
+ * }
167
+ * ```
168
+ *
169
+ * @param relationName - Name of the relation defined on the source model
170
+ * @param targetRepo - Target repository instance
171
+ */
172
+ protected createHasManyRepositoryFactoryFor<Target extends Entity, TargetID, ForeignKeyType>(relationName: string, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>>): HasManyRepositoryFactory<Target, ForeignKeyType>;
173
+ /**
174
+ * Function to create a belongs to accessor
175
+ *
176
+ * @param relationName - Name of the relation defined on the source model
177
+ * @param targetRepo - Target repository instance
178
+ */
179
+ protected createBelongsToAccessorFor<Target extends Entity, TargetId>(relationName: string, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetId>> | {
180
+ [repoType: string]: Getter<EntityCrudRepository<Target, TargetId>>;
181
+ }): BelongsToAccessor<Target, ID>;
182
+ /**
183
+ * Function to create a constrained hasOne relation repository factory
184
+ *
185
+ * @param relationName - Name of the relation defined on the source model
186
+ * @param targetRepo - Target repository instance
187
+ */
188
+ protected createHasOneRepositoryFactoryFor<Target extends Entity, TargetID, ForeignKeyType>(relationName: string, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>> | {
189
+ [repoType: string]: Getter<EntityCrudRepository<Target, TargetID>>;
190
+ }): HasOneRepositoryFactory<Target, ForeignKeyType>;
191
+ /**
192
+ * Function to create a constrained hasManyThrough relation repository factory
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * class CustomerRepository extends SequelizeCrudRepository<
197
+ * Customer,
198
+ * typeof Customer.prototype.id,
199
+ * CustomerRelations
200
+ * > {
201
+ * public readonly cartItems: HasManyRepositoryFactory<CartItem, typeof Customer.prototype.id>;
202
+ *
203
+ * constructor(
204
+ * protected db: SequelizeDataSource,
205
+ * cartItemRepository: EntityCrudRepository<CartItem, typeof, CartItem.prototype.id>,
206
+ * throughRepository: EntityCrudRepository<Through, typeof Through.prototype.id>,
207
+ * ) {
208
+ * super(Customer, db);
209
+ * this.cartItems = this.createHasManyThroughRepositoryFactoryFor(
210
+ * 'cartItems',
211
+ * cartItemRepository,
212
+ * );
213
+ * }
214
+ * }
215
+ * ```
216
+ *
217
+ * @param relationName - Name of the relation defined on the source model
218
+ * @param targetRepo - Target repository instance
219
+ * @param throughRepo - Through repository instance
220
+ */
221
+ protected createHasManyThroughRepositoryFactoryFor<Target extends Entity, TargetID, Through extends Entity, ThroughID, ForeignKeyType>(relationName: string, targetRepositoryGetter: Getter<EntityCrudRepository<Target, TargetID>> | {
222
+ [repoType: string]: Getter<EntityCrudRepository<Target, TargetID>>;
223
+ }, throughRepositoryGetter: Getter<EntityCrudRepository<Through, ThroughID>>): HasManyThroughRepositoryFactory<Target, TargetID, Through, ForeignKeyType>;
224
+ /**
225
+ * Function to create a references many accessor
226
+ *
227
+ * @param relationName - Name of the relation defined on the source model
228
+ * @param targetRepo - Target repository instance
229
+ */
230
+ protected createReferencesManyAccessorFor<Target extends Entity, TargetId>(relationName: string, targetRepoGetter: Getter<EntityCrudRepository<Target, TargetId>>): ReferencesManyAccessor<Target, ID>;
231
+ }