@loopback/repository 2.2.1 → 2.5.1

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 (135) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/common-types.d.ts +1 -0
  3. package/dist/common-types.js +2 -0
  4. package/dist/common-types.js.map +1 -1
  5. package/dist/connectors/index.js +4 -0
  6. package/dist/connectors/index.js.map +1 -1
  7. package/dist/decorators/metadata.js +1 -0
  8. package/dist/decorators/metadata.js.map +1 -1
  9. package/dist/decorators/model.decorator.d.ts +1 -1
  10. package/dist/decorators/model.decorator.js +1 -0
  11. package/dist/decorators/model.decorator.js.map +1 -1
  12. package/dist/decorators/repository.decorator.js +1 -0
  13. package/dist/decorators/repository.decorator.js.map +1 -1
  14. package/dist/define-model-class.js +1 -0
  15. package/dist/define-model-class.js.map +1 -1
  16. package/dist/define-repository-class.d.ts +119 -0
  17. package/dist/define-repository-class.js +98 -0
  18. package/dist/define-repository-class.js.map +1 -0
  19. package/dist/errors/entity-not-found.error.js +1 -0
  20. package/dist/errors/entity-not-found.error.js.map +1 -1
  21. package/dist/errors/invalid-relation.error.js +1 -0
  22. package/dist/errors/invalid-relation.error.js.map +1 -1
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/keys.d.ts +34 -0
  27. package/dist/keys.js +44 -0
  28. package/dist/keys.js.map +1 -0
  29. package/dist/mixins/repository.mixin.d.ts +91 -9
  30. package/dist/mixins/repository.mixin.js +62 -20
  31. package/dist/mixins/repository.mixin.js.map +1 -1
  32. package/dist/model.d.ts +16 -1
  33. package/dist/model.js +61 -9
  34. package/dist/model.js.map +1 -1
  35. package/dist/query.js +1 -0
  36. package/dist/query.js.map +1 -1
  37. package/dist/relations/belongs-to/belongs-to-accessor.js +1 -0
  38. package/dist/relations/belongs-to/belongs-to-accessor.js.map +1 -1
  39. package/dist/relations/belongs-to/belongs-to.decorator.js +1 -0
  40. package/dist/relations/belongs-to/belongs-to.decorator.js.map +1 -1
  41. package/dist/relations/belongs-to/belongs-to.helpers.js +1 -0
  42. package/dist/relations/belongs-to/belongs-to.helpers.js.map +1 -1
  43. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js +1 -0
  44. package/dist/relations/belongs-to/belongs-to.inclusion-resolver.js.map +1 -1
  45. package/dist/relations/belongs-to/belongs-to.repository.js +1 -0
  46. package/dist/relations/belongs-to/belongs-to.repository.js.map +1 -1
  47. package/dist/relations/has-many/has-many-repository.factory.js +1 -0
  48. package/dist/relations/has-many/has-many-repository.factory.js.map +1 -1
  49. package/dist/relations/has-many/has-many-through.helpers.d.ts +74 -0
  50. package/dist/relations/has-many/has-many-through.helpers.js +145 -0
  51. package/dist/relations/has-many/has-many-through.helpers.js.map +1 -0
  52. package/dist/relations/has-many/has-many.decorator.js +1 -0
  53. package/dist/relations/has-many/has-many.decorator.js.map +1 -1
  54. package/dist/relations/has-many/has-many.helpers.d.ts +9 -0
  55. package/dist/relations/has-many/has-many.helpers.js +33 -21
  56. package/dist/relations/has-many/has-many.helpers.js.map +1 -1
  57. package/dist/relations/has-many/has-many.inclusion-resolver.js +1 -0
  58. package/dist/relations/has-many/has-many.inclusion-resolver.js.map +1 -1
  59. package/dist/relations/has-many/has-many.repository.js +1 -0
  60. package/dist/relations/has-many/has-many.repository.js.map +1 -1
  61. package/dist/relations/has-one/has-one-repository.factory.js +1 -0
  62. package/dist/relations/has-one/has-one-repository.factory.js.map +1 -1
  63. package/dist/relations/has-one/has-one.decorator.js +1 -0
  64. package/dist/relations/has-one/has-one.decorator.js.map +1 -1
  65. package/dist/relations/has-one/has-one.helpers.js +1 -0
  66. package/dist/relations/has-one/has-one.helpers.js.map +1 -1
  67. package/dist/relations/has-one/has-one.inclusion-resolver.js +1 -0
  68. package/dist/relations/has-one/has-one.inclusion-resolver.js.map +1 -1
  69. package/dist/relations/has-one/has-one.repository.js +1 -0
  70. package/dist/relations/has-one/has-one.repository.js.map +1 -1
  71. package/dist/relations/relation.decorator.js +1 -0
  72. package/dist/relations/relation.decorator.js.map +1 -1
  73. package/dist/relations/relation.helpers.js +1 -0
  74. package/dist/relations/relation.helpers.js.map +1 -1
  75. package/dist/relations/relation.types.d.ts +25 -27
  76. package/dist/relations/relation.types.js +2 -1
  77. package/dist/relations/relation.types.js.map +1 -1
  78. package/dist/repositories/constraint-utils.js +1 -0
  79. package/dist/repositories/constraint-utils.js.map +1 -1
  80. package/dist/repositories/index.js +1 -0
  81. package/dist/repositories/index.js.map +1 -1
  82. package/dist/repositories/kv.repository.bridge.js +1 -0
  83. package/dist/repositories/kv.repository.bridge.js.map +1 -1
  84. package/dist/repositories/legacy-juggler-bridge.d.ts +3 -3
  85. package/dist/repositories/legacy-juggler-bridge.js +8 -18
  86. package/dist/repositories/legacy-juggler-bridge.js.map +1 -1
  87. package/dist/repositories/repository.js +1 -0
  88. package/dist/repositories/repository.js.map +1 -1
  89. package/dist/transaction.js +1 -0
  90. package/dist/transaction.js.map +1 -1
  91. package/dist/type-resolver.d.ts +4 -0
  92. package/dist/type-resolver.js +9 -0
  93. package/dist/type-resolver.js.map +1 -1
  94. package/dist/types/any.js +1 -0
  95. package/dist/types/any.js.map +1 -1
  96. package/dist/types/array.js +1 -0
  97. package/dist/types/array.js.map +1 -1
  98. package/dist/types/boolean.js +1 -0
  99. package/dist/types/boolean.js.map +1 -1
  100. package/dist/types/buffer.js +1 -0
  101. package/dist/types/buffer.js.map +1 -1
  102. package/dist/types/date.js +1 -0
  103. package/dist/types/date.js.map +1 -1
  104. package/dist/types/index.d.ts +11 -9
  105. package/dist/types/index.js +33 -17
  106. package/dist/types/index.js.map +1 -1
  107. package/dist/types/model.js +1 -0
  108. package/dist/types/model.js.map +1 -1
  109. package/dist/types/null.d.ts +12 -0
  110. package/dist/types/null.js +33 -0
  111. package/dist/types/null.js.map +1 -0
  112. package/dist/types/number.js +1 -0
  113. package/dist/types/number.js.map +1 -1
  114. package/dist/types/object.js +1 -0
  115. package/dist/types/object.js.map +1 -1
  116. package/dist/types/string.js +1 -0
  117. package/dist/types/string.js.map +1 -1
  118. package/dist/types/union.js +1 -0
  119. package/dist/types/union.js.map +1 -1
  120. package/package.json +13 -14
  121. package/src/common-types.ts +1 -0
  122. package/src/define-repository-class.ts +170 -0
  123. package/src/index.ts +2 -0
  124. package/src/keys.ts +40 -0
  125. package/src/mixins/repository.mixin.ts +120 -25
  126. package/src/model.ts +74 -11
  127. package/src/relations/has-many/has-many-through.helpers.ts +193 -0
  128. package/src/relations/has-many/has-many.helpers.ts +41 -27
  129. package/src/relations/relation.types.ts +24 -30
  130. package/src/repositories/legacy-juggler-bridge.ts +16 -24
  131. package/src/type-resolver.ts +8 -0
  132. package/src/types/index.ts +11 -8
  133. package/src/types/null.ts +35 -0
  134. package/index.d.ts +0 -6
  135. package/index.js +0 -6
@@ -4,30 +4,46 @@
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- const string_1 = require("./string");
8
- exports.StringType = string_1.StringType;
9
- const boolean_1 = require("./boolean");
10
- exports.BooleanType = boolean_1.BooleanType;
11
- const number_1 = require("./number");
12
- exports.NumberType = number_1.NumberType;
13
- const date_1 = require("./date");
14
- exports.DateType = date_1.DateType;
15
- const buffer_1 = require("./buffer");
16
- exports.BufferType = buffer_1.BufferType;
7
+ exports.NULL = exports.ANY = exports.BUFFER = exports.DATE = exports.NUMBER = exports.BOOLEAN = exports.STRING = exports.ObjectType = exports.NullType = exports.ModelType = exports.UnionType = exports.ArrayType = exports.AnyType = exports.BufferType = exports.DateType = exports.NumberType = exports.BooleanType = exports.StringType = void 0;
8
+ /**
9
+ * Built-in types for LoopBack modeling
10
+ * - Type: abstract base type
11
+ * - StringType: string
12
+ * - BooleanType: boolean
13
+ * - NumberType: number
14
+ * - DateType: Date
15
+ * - BufferType: Buffer
16
+ * - AnyType: any
17
+ * - ArrayType: Array<T>
18
+ * - UnionType: Union of types
19
+ */
17
20
  const any_1 = require("./any");
18
- exports.AnyType = any_1.AnyType;
21
+ Object.defineProperty(exports, "AnyType", { enumerable: true, get: function () { return any_1.AnyType; } });
19
22
  const array_1 = require("./array");
20
- exports.ArrayType = array_1.ArrayType;
21
- const union_1 = require("./union");
22
- exports.UnionType = union_1.UnionType;
23
- const object_1 = require("./object");
24
- exports.ObjectType = object_1.ObjectType;
23
+ Object.defineProperty(exports, "ArrayType", { enumerable: true, get: function () { return array_1.ArrayType; } });
24
+ const boolean_1 = require("./boolean");
25
+ Object.defineProperty(exports, "BooleanType", { enumerable: true, get: function () { return boolean_1.BooleanType; } });
26
+ const buffer_1 = require("./buffer");
27
+ Object.defineProperty(exports, "BufferType", { enumerable: true, get: function () { return buffer_1.BufferType; } });
28
+ const date_1 = require("./date");
29
+ Object.defineProperty(exports, "DateType", { enumerable: true, get: function () { return date_1.DateType; } });
25
30
  const model_1 = require("./model");
26
- exports.ModelType = model_1.ModelType;
31
+ Object.defineProperty(exports, "ModelType", { enumerable: true, get: function () { return model_1.ModelType; } });
32
+ const null_1 = require("./null");
33
+ Object.defineProperty(exports, "NullType", { enumerable: true, get: function () { return null_1.NullType; } });
34
+ const number_1 = require("./number");
35
+ Object.defineProperty(exports, "NumberType", { enumerable: true, get: function () { return number_1.NumberType; } });
36
+ const object_1 = require("./object");
37
+ Object.defineProperty(exports, "ObjectType", { enumerable: true, get: function () { return object_1.ObjectType; } });
38
+ const string_1 = require("./string");
39
+ Object.defineProperty(exports, "StringType", { enumerable: true, get: function () { return string_1.StringType; } });
40
+ const union_1 = require("./union");
41
+ Object.defineProperty(exports, "UnionType", { enumerable: true, get: function () { return union_1.UnionType; } });
27
42
  exports.STRING = new string_1.StringType();
28
43
  exports.BOOLEAN = new boolean_1.BooleanType();
29
44
  exports.NUMBER = new number_1.NumberType();
30
45
  exports.DATE = new date_1.DateType();
31
46
  exports.BUFFER = new buffer_1.BufferType();
32
47
  exports.ANY = new any_1.AnyType();
48
+ exports.NULL = new null_1.NullType();
33
49
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;AAehE,qCAAoC;AAalC,qBAbM,mBAAU,CAaN;AAZZ,uCAAsC;AAapC,sBAbM,qBAAW,CAaN;AAZb,qCAAoC;AAalC,qBAbM,mBAAU,CAaN;AAZZ,iCAAgC;AAa9B,mBAbM,eAAQ,CAaN;AAZV,qCAAoC;AAalC,qBAbM,mBAAU,CAaN;AAZZ,+BAA8B;AAa5B,kBAbM,aAAO,CAaN;AAZT,mCAAkC;AAahC,oBAbM,iBAAS,CAaN;AAZX,mCAAkC;AAahC,oBAbM,iBAAS,CAaN;AAZX,qCAAoC;AAclC,qBAdM,mBAAU,CAcN;AAbZ,mCAAkC;AAYhC,oBAZM,iBAAS,CAYN;AAIE,QAAA,MAAM,GAAG,IAAI,mBAAU,EAAE,CAAC;AAC1B,QAAA,OAAO,GAAG,IAAI,qBAAW,EAAE,CAAC;AAC5B,QAAA,MAAM,GAAG,IAAI,mBAAU,EAAE,CAAC;AAC1B,QAAA,IAAI,GAAG,IAAI,eAAQ,EAAE,CAAC;AACtB,QAAA,MAAM,GAAG,IAAI,mBAAU,EAAE,CAAC;AAC1B,QAAA,GAAG,GAAG,IAAI,aAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE;;;;;;;;;;;GAWG;AACH,+BAA8B;AAoB5B,wFApBM,aAAO,OAoBN;AAnBT,mCAAkC;AAoBhC,0FApBM,iBAAS,OAoBN;AAnBX,uCAAsC;AAcpC,4FAdM,qBAAW,OAcN;AAbb,qCAAoC;AAgBlC,2FAhBM,mBAAU,OAgBN;AAfZ,iCAAgC;AAc9B,yFAdM,eAAQ,OAcN;AAbV,mCAAkC;AAkBhC,0FAlBM,iBAAS,OAkBN;AAjBX,iCAAgC;AAkB9B,yFAlBM,eAAQ,OAkBN;AAjBV,qCAAoC;AAUlC,2FAVM,mBAAU,OAUN;AATZ,qCAAoC;AAiBlC,2FAjBM,mBAAU,OAiBN;AAhBZ,qCAAoC;AAMlC,2FANM,mBAAU,OAMN;AAJZ,mCAAkC;AAWhC,0FAXM,iBAAS,OAWN;AAME,QAAA,MAAM,GAAG,IAAI,mBAAU,EAAE,CAAC;AAC1B,QAAA,OAAO,GAAG,IAAI,qBAAW,EAAE,CAAC;AAC5B,QAAA,MAAM,GAAG,IAAI,mBAAU,EAAE,CAAC;AAC1B,QAAA,IAAI,GAAG,IAAI,eAAQ,EAAE,CAAC;AACtB,QAAA,MAAM,GAAG,IAAI,mBAAU,EAAE,CAAC;AAC1B,QAAA,GAAG,GAAG,IAAI,aAAO,EAAE,CAAC;AACpB,QAAA,IAAI,GAAG,IAAI,eAAQ,EAAE,CAAC"}
@@ -4,6 +4,7 @@
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ModelType = void 0;
7
8
  const object_1 = require("./object");
8
9
  /**
9
10
  * Model type
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/types/model.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;AAIhE,qCAAoC;AAEpC;;GAEG;AACH,MAAa,SAA2B,SAAQ,mBAAa;IAG3D,YAAmB,UAAoB;QACrC,KAAK,CAAC,UAAU,CAAC,CAAC;QADD,eAAU,GAAV,UAAU,CAAU;QAF9B,SAAI,GAAW,OAAO,CAAC;IAIhC,CAAC;IAED,SAAS,CAAC,KAA2B;QACnC,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,KAAK,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;CACF;AAXD,8BAWC"}
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/types/model.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAIhE,qCAAoC;AAEpC;;GAEG;AACH,MAAa,SAA2B,SAAQ,mBAAa;IAG3D,YAAmB,UAAoB;QACrC,KAAK,CAAC,UAAU,CAAC,CAAC;QADD,eAAU,GAAV,UAAU,CAAU;QAF9B,SAAI,GAAW,OAAO,CAAC;IAIhC,CAAC;IAED,SAAS,CAAC,KAA2B;QACnC,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,KAAK,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;CACF;AAXD,8BAWC"}
@@ -0,0 +1,12 @@
1
+ import { Type } from './type';
2
+ /**
3
+ * Null type
4
+ */
5
+ export declare class NullType implements Type<null> {
6
+ readonly name = "boolean";
7
+ isInstance(value: any): boolean;
8
+ defaultValue(): null;
9
+ isCoercible(value: any): boolean;
10
+ coerce(value: any): null;
11
+ serialize(value: boolean | null | undefined): null;
12
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2017,2019. All Rights Reserved.
3
+ // Node module: @loopback/repository
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.NullType = void 0;
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
+ /**
10
+ * Null type
11
+ */
12
+ class NullType {
13
+ constructor() {
14
+ this.name = 'boolean';
15
+ }
16
+ isInstance(value) {
17
+ return value === null;
18
+ }
19
+ defaultValue() {
20
+ return null;
21
+ }
22
+ isCoercible(value) {
23
+ return value == null;
24
+ }
25
+ coerce(value) {
26
+ return null;
27
+ }
28
+ serialize(value) {
29
+ return null;
30
+ }
31
+ }
32
+ exports.NullType = NullType;
33
+ //# sourceMappingURL=null.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"null.js","sourceRoot":"","sources":["../../src/types/null.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAIhE,uDAAuD;AAEvD;;GAEG;AACH,MAAa,QAAQ;IAArB;QACW,SAAI,GAAG,SAAS,CAAC;IAqB5B,CAAC;IAnBC,UAAU,CAAC,KAAU;QACnB,OAAO,KAAK,KAAK,IAAI,CAAC;IACxB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,KAAU;QACpB,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,KAAU;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,CAAC,KAAiC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtBD,4BAsBC"}
@@ -4,6 +4,7 @@
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.NumberType = void 0;
7
8
  const tslib_1 = require("tslib");
8
9
  const util_1 = tslib_1.__importDefault(require("util"));
9
10
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -1 +1 @@
1
- {"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/types/number.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,wDAAwB;AAGxB,uDAAuD;AAEvD;;GAEG;AACH,MAAa,UAAU;IAAvB;QACW,SAAI,GAAG,QAAQ,CAAC;IA2B3B,CAAC;IAzBC,UAAU,CAAC,KAAU;QACnB,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC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,CAAC;IAED,MAAM,CAAC,KAAU;QACf,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,KAAK,CAAC;QAChC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACxB,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;YACZ,MAAM,GAAG,GAAG,cAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5D,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,SAAS,CAAC,KAAgC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA5BD,gCA4BC"}
@@ -4,6 +4,7 @@
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ObjectType = void 0;
7
8
  const tslib_1 = require("tslib");
8
9
  const util_1 = tslib_1.__importDefault(require("util"));
9
10
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,wDAAwB;AAIxB,uDAAuD;AAEvD;;GAEG;AACH,MAAa,UAAU;IAGrB,YAAmB,IAAc;QAAd,SAAI,GAAJ,IAAI,CAAU;QAFjC,SAAI,GAAG,QAAQ,CAAC;IAEoB,CAAC;IAErC,UAAU,CAAC,KAAU;QACnB,OAAO,KAAK,IAAI,IAAI,IAAI,KAAK,YAAY,IAAI,CAAC,IAAI,CAAC;IACrD,CAAC;IAED,WAAW,CAAC,KAAU;QACpB,OAAO,CACL,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAA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pB,OAAO,CACL,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CACtE,CAAC;IACJ,CAAC;IAED,YAAY;QACV,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,MAAM,CAAC,KAAU;QACf,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,KAAK,CAAC;QAChC,IAAI,KAAK,YAAY,IAAI,CAAC,IAAI,EAAE;YAC9B,OAAO,KAAK,CAAC;SACd;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACrD,MAAM,GAAG,GAAG,cAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5D,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,CAAC;SAC1B;QACD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED,SAAS,CAAC,KAA2B;QACnC,IAAI,KAAK,IAAI,IAAI;YAAE,OAAO,KAAK,CAAC;QAChC,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE;YACtC,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;SACvB;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtCD,gCAsCC"}
@@ -4,6 +4,7 @@
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.StringType = void 0;
7
8
  /* eslint-disable @typescript-eslint/no-explicit-any */
8
9
  /**
9
10
  * String type
@@ -1 +1 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/types/string.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+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I;YAAE,OAAO,KAAK,CAAC;QAChC,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE;YACtC,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;SACxB;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SAC9B;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAED,SAAS,CAAC,KAAgC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA7BD,gCA6BC"}
@@ -4,6 +4,7 @@
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.UnionType = void 0;
7
8
  const tslib_1 = require("tslib");
8
9
  const util_1 = tslib_1.__importDefault(require("util"));
9
10
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -1 +1 @@
1
- {"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/types/union.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,oCAAoC;AACpC,+CAA+C;AAC/C,gEAAgE;;;AAEhE,wDAAwB;AAGxB,uDAAuD;AAEvD;;GAEG;AACH,MAAa,SAAS;IACpB,YAAmB,SAAsB;QAAtB,cAAS,GAAT,SAAS,CAAa;QAEhC,SAAI,GAAG,OAAO,CAAC;IAFoB,CAAC;IAI7C,UAAU,CAAC,KAAU;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,WAAW,CAAC,KAAU;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,YAAY;QACV,OAAO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.5.1",
4
4
  "description": "Repository based persistence for LoopBack 4",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
5
7
  "engines": {
6
8
  "node": ">=10"
7
9
  },
8
- "main": "index",
9
10
  "scripts": {
10
11
  "acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
11
12
  "build": "lb-tsc",
@@ -18,28 +19,26 @@
18
19
  "copyright.owner": "IBM Corp.",
19
20
  "license": "MIT",
20
21
  "devDependencies": {
21
- "@loopback/build": "^5.2.0",
22
- "@loopback/eslint-config": "^6.0.4",
23
- "@loopback/testlab": "^3.1.1",
22
+ "@loopback/build": "^5.4.1",
23
+ "@loopback/eslint-config": "^7.0.1",
24
+ "@loopback/testlab": "^3.1.5",
24
25
  "@types/bson": "^4.0.2",
25
26
  "@types/json-schema": "^7.0.4",
26
- "@types/lodash": "^4.14.150",
27
- "@types/node": "^10.17.21",
27
+ "@types/lodash": "^4.14.152",
28
+ "@types/node": "^10.17.24",
28
29
  "bson": "4.0.4"
29
30
  },
30
31
  "dependencies": {
31
- "@loopback/context": "^3.5.1",
32
- "@loopback/core": "^2.4.1",
32
+ "@loopback/context": "^3.8.1",
33
+ "@loopback/core": "^2.7.0",
33
34
  "@types/debug": "^4.1.5",
34
35
  "debug": "^4.1.1",
35
36
  "lodash": "^4.17.15",
36
- "loopback-datasource-juggler": "^4.20.0",
37
- "tslib": "^1.11.1"
37
+ "loopback-datasource-juggler": "^4.21.2",
38
+ "tslib": "^2.0.0"
38
39
  },
39
40
  "files": [
40
41
  "README.md",
41
- "index.js",
42
- "index.d.ts",
43
42
  "dist",
44
43
  "src",
45
44
  "!*/__tests__"
@@ -49,5 +48,5 @@
49
48
  "url": "https://github.com/strongloop/loopback-next.git",
50
49
  "directory": "packages/repository"
51
50
  },
52
- "gitHead": "11f282df0bbdf25c505a2131e6d82b85005a22a2"
51
+ "gitHead": "62aea854bf85c5a5995b59e6908fe5409f7eea96"
53
52
  }
@@ -101,6 +101,7 @@ export interface Count {
101
101
  export const CountSchema = {
102
102
  type: 'object',
103
103
  title: 'loopback.Count',
104
+ 'x-typescript-type': '@loopback/repository#Count',
104
105
  properties: {count: {type: 'number'}},
105
106
  };
106
107
 
@@ -0,0 +1,170 @@
1
+ // Copyright IBM Corp. 2020. All Rights Reserved.
2
+ // Node module: @loopback/repository
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ import assert from 'assert';
7
+ import {PrototypeOf} from './common-types';
8
+ import {Entity, Model} from './model';
9
+ import {
10
+ DefaultCrudRepository,
11
+ DefaultKeyValueRepository,
12
+ juggler,
13
+ Repository,
14
+ } from './repositories';
15
+
16
+ /**
17
+ * Signature for a Repository class bound to a given model. The constructor
18
+ * accepts only the dataSource to use for persistence.
19
+ *
20
+ * `define*` functions return a class implementing this interface.
21
+ *
22
+ * @typeParam M - Model class
23
+ * @typeParam R - Repository class/interface
24
+ */
25
+ export interface ModelRepositoryClass<
26
+ M extends Model,
27
+ R extends Repository<M>
28
+ > {
29
+ /**
30
+ * The constructor for the generated repository class
31
+ * @param dataSource - DataSource object
32
+ */
33
+ new (dataSource: juggler.DataSource): R;
34
+ prototype: R;
35
+ }
36
+
37
+ /**
38
+ * Signature for repository classes that can be used as the base class for
39
+ * `define*` functions. The constructor of a base repository class accepts
40
+ * the target model constructor and the datasource to use.
41
+ *
42
+ * `define*` functions require a class implementing this interface on input.
43
+ *
44
+ * @typeParam M - Model class constructor, e.g `typeof Model`.
45
+ * **❗️IMPORTANT: The type argument `M` is describing the model constructor type
46
+ * (e.g. `typeof Model`), not the model instance type (`Model`) as is the case
47
+ * in other repository-related types. The constructor type is required
48
+ * to support custom repository classes requiring a Model subclass in the
49
+ * constructor arguments, e.g. `Entity` or a user-provided model.**
50
+ *
51
+ * @typeParam R - Repository class/interface
52
+ */
53
+ export interface BaseRepositoryClass<
54
+ M extends typeof Model,
55
+ R extends Repository<PrototypeOf<M>>
56
+ > {
57
+ /**
58
+ * The constructor for the generated repository class
59
+ * @param modelClass - Model class
60
+ * @param dataSource - DataSource object
61
+ */
62
+ new (modelClass: M, dataSource: juggler.DataSource): R;
63
+ prototype: R;
64
+ }
65
+
66
+ /**
67
+ * Create (define) a repository class for the given model.
68
+ *
69
+ * See also `defineCrudRepositoryClass` and `defineKeyValueRepositoryClass`
70
+ * for convenience wrappers providing repository class factory for the default
71
+ * CRUD and KeyValue implementations.
72
+ *
73
+ * **❗️IMPORTANT: The compiler (TypeScript 3.8) is not able to correctly infer
74
+ * generic arguments `M` and `R` from the class constructors provided in
75
+ * function arguments. You must always provide both M and R types explicitly.**
76
+ *
77
+ * @example
78
+ *
79
+ * ```ts
80
+ * const AddressRepository = defineRepositoryClass<
81
+ * typeof Address,
82
+ * DefaultEntityCrudRepository<
83
+ * Address,
84
+ * typeof Address.prototype.id,
85
+ * AddressRelations
86
+ * >,
87
+ * >(Address, DefaultCrudRepository);
88
+ * ```
89
+ *
90
+ * @param modelClass - A model class such as `Address`.
91
+ * @param baseRepositoryClass - Repository implementation to use as the base,
92
+ * e.g. `DefaultCrudRepository`.
93
+ *
94
+ * @typeParam M - Model class constructor (e.g. `typeof Address`)
95
+ * @typeParam R - Repository class (e.g. `DefaultCrudRepository<Address, number>`)
96
+ */
97
+ export function defineRepositoryClass<
98
+ M extends typeof Model,
99
+ R extends Repository<PrototypeOf<M>>
100
+ >(
101
+ modelClass: M,
102
+ baseRepositoryClass: BaseRepositoryClass<M, R>,
103
+ ): ModelRepositoryClass<PrototypeOf<M>, R> {
104
+ const repoName = modelClass.name + 'Repository';
105
+ const defineNamedRepo = new Function(
106
+ 'ModelCtor',
107
+ 'BaseRepository',
108
+ `return class ${repoName} extends BaseRepository {
109
+ constructor(dataSource) {
110
+ super(ModelCtor, dataSource);
111
+ }
112
+ };`,
113
+ );
114
+
115
+ const repo = defineNamedRepo(modelClass, baseRepositoryClass);
116
+ assert.equal(repo.name, repoName);
117
+ return repo;
118
+ }
119
+
120
+ /**
121
+ * Create (define) an entity CRUD repository class for the given model.
122
+ * This function always uses `DefaultCrudRepository` as the base class,
123
+ * use `defineRepositoryClass` if you want to use your own base repository.
124
+ *
125
+ * @example
126
+ *
127
+ * ```ts
128
+ * const ProductRepository = defineCrudRepositoryClass<
129
+ * Product,
130
+ * typeof Product.prototype.id,
131
+ * ProductRelations
132
+ * >(Product);
133
+ * ```
134
+ *
135
+ * @param entityClass - An entity class such as `Product`.
136
+ *
137
+ * @typeParam E - An entity class
138
+ * @typeParam IdType - ID type for the entity
139
+ * @typeParam Relations - Relations for the entity
140
+ */
141
+ export function defineCrudRepositoryClass<
142
+ E extends Entity,
143
+ IdType,
144
+ Relations extends object
145
+ >(
146
+ entityClass: typeof Entity & {prototype: E},
147
+ ): ModelRepositoryClass<E, DefaultCrudRepository<E, IdType, Relations>> {
148
+ return defineRepositoryClass(entityClass, DefaultCrudRepository);
149
+ }
150
+
151
+ /**
152
+ * Create (define) a KeyValue repository class for the given entity.
153
+ * This function always uses `DefaultKeyValueRepository` as the base class,
154
+ * use `defineRepositoryClass` if you want to use your own base repository.
155
+ *
156
+ * @example
157
+ *
158
+ * ```ts
159
+ * const ProductKeyValueRepository = defineKeyValueRepositoryClass(Product);
160
+ * ```
161
+ *
162
+ * @param modelClass - An entity class such as `Product`.
163
+ *
164
+ * @typeParam M - Model class
165
+ */
166
+ export function defineKeyValueRepositoryClass<M extends Model>(
167
+ modelClass: typeof Model & {prototype: M},
168
+ ): ModelRepositoryClass<M, DefaultKeyValueRepository<M>> {
169
+ return defineRepositoryClass(modelClass, DefaultKeyValueRepository);
170
+ }
package/src/index.ts CHANGED
@@ -24,7 +24,9 @@ export * from './connectors';
24
24
  export * from './datasource';
25
25
  export * from './decorators';
26
26
  export * from './define-model-class';
27
+ export * from './define-repository-class';
27
28
  export * from './errors';
29
+ export * from './keys';
28
30
  export * from './mixins';
29
31
  export * from './model';
30
32
  export * from './query';
package/src/keys.ts ADDED
@@ -0,0 +1,40 @@
1
+ // Copyright IBM Corp. 2020. All Rights Reserved.
2
+ // Node module: @loopback/repository
3
+ // This file is licensed under the MIT License.
4
+ // License text available at https://opensource.org/licenses/MIT
5
+
6
+ /**
7
+ * Binding tags for repository related bindings
8
+ */
9
+ export namespace RepositoryTags {
10
+ /**
11
+ * Tag for model class bindings
12
+ */
13
+ export const MODEL = 'model';
14
+ /**
15
+ * Tag for repository bindings
16
+ */
17
+ export const REPOSITORY = 'repository';
18
+ /**
19
+ * Tag for datasource bindings
20
+ */
21
+ export const DATASOURCE = 'datasource';
22
+ }
23
+
24
+ /**
25
+ * Binding keys and namespaces for repository related bindings
26
+ */
27
+ export namespace RepositoryBindings {
28
+ /**
29
+ * Namespace for model class bindings
30
+ */
31
+ export const MODELS = 'models';
32
+ /**
33
+ * Namespace for repository bindings
34
+ */
35
+ export const REPOSITORIES = 'repositories';
36
+ /**
37
+ * Namespace for datasource bindings
38
+ */
39
+ export const DATASOURCES = 'datasources';
40
+ }