@abedmurrar/objection 0.0.0-stage → 4.0.0-beta.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 (190) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +105 -2
  3. package/lib/index.mjs +6 -0
  4. package/lib/initialize.js +11 -0
  5. package/lib/model/AjvValidator.js +278 -0
  6. package/lib/model/Model.js +772 -0
  7. package/lib/model/ModifierNotFoundError.js +10 -0
  8. package/lib/model/NotFoundError.js +19 -0
  9. package/lib/model/RelationDoesNotExistError.js +11 -0
  10. package/lib/model/ValidationError.js +46 -0
  11. package/lib/model/Validator.js +20 -0
  12. package/lib/model/getModel.js +7 -0
  13. package/lib/model/graph/ModelGraph.js +60 -0
  14. package/lib/model/graph/ModelGraphBuilder.js +188 -0
  15. package/lib/model/graph/ModelGraphEdge.js +40 -0
  16. package/lib/model/graph/ModelGraphNode.js +201 -0
  17. package/lib/model/inheritModel.js +19 -0
  18. package/lib/model/modelBindKnex.js +69 -0
  19. package/lib/model/modelClone.js +102 -0
  20. package/lib/model/modelColPropMap.js +24 -0
  21. package/lib/model/modelConcurrency.js +24 -0
  22. package/lib/model/modelId.js +57 -0
  23. package/lib/model/modelJsonAttributes.js +72 -0
  24. package/lib/model/modelParseRelations.js +83 -0
  25. package/lib/model/modelQueryProps.js +116 -0
  26. package/lib/model/modelSet.js +116 -0
  27. package/lib/model/modelTableMetadata.js +71 -0
  28. package/lib/model/modelToJson.js +157 -0
  29. package/lib/model/modelUtils.js +40 -0
  30. package/lib/model/modelValidate.js +40 -0
  31. package/lib/model/modelValues.js +113 -0
  32. package/lib/model/modelVisitor.js +34 -0
  33. package/lib/objection.js +89 -0
  34. package/lib/queryBuilder/FunctionBuilder.js +291 -0
  35. package/lib/queryBuilder/InternalOptions.js +24 -0
  36. package/lib/queryBuilder/JoinBuilder.js +124 -0
  37. package/lib/queryBuilder/QueryBuilder.js +1136 -0
  38. package/lib/queryBuilder/QueryBuilderBase.js +666 -0
  39. package/lib/queryBuilder/QueryBuilderContext.js +20 -0
  40. package/lib/queryBuilder/QueryBuilderContextBase.js +26 -0
  41. package/lib/queryBuilder/QueryBuilderOperationSupport.js +484 -0
  42. package/lib/queryBuilder/QueryBuilderUserContext.js +25 -0
  43. package/lib/queryBuilder/RawBuilder.js +78 -0
  44. package/lib/queryBuilder/ReferenceBuilder.js +246 -0
  45. package/lib/queryBuilder/RelationExpression.js +373 -0
  46. package/lib/queryBuilder/StaticHookArguments.js +122 -0
  47. package/lib/queryBuilder/ValueBuilder.js +115 -0
  48. package/lib/queryBuilder/expressions.js +121 -0
  49. package/lib/queryBuilder/functions/mysql.js +762 -0
  50. package/lib/queryBuilder/graph/GraphAction.js +54 -0
  51. package/lib/queryBuilder/graph/GraphData.js +12 -0
  52. package/lib/queryBuilder/graph/GraphFetcher.js +155 -0
  53. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +146 -0
  54. package/lib/queryBuilder/graph/GraphOperation.js +21 -0
  55. package/lib/queryBuilder/graph/GraphOptions.js +165 -0
  56. package/lib/queryBuilder/graph/GraphUpsert.js +231 -0
  57. package/lib/queryBuilder/graph/delete/GraphDelete.js +15 -0
  58. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +56 -0
  59. package/lib/queryBuilder/graph/insert/GraphInsert.js +116 -0
  60. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +183 -0
  61. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +70 -0
  62. package/lib/queryBuilder/graph/patch/GraphPatch.js +15 -0
  63. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +205 -0
  64. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +26 -0
  65. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +96 -0
  66. package/lib/queryBuilder/join/JoinResultColumn.js +19 -0
  67. package/lib/queryBuilder/join/JoinResultParser.js +106 -0
  68. package/lib/queryBuilder/join/RelationJoiner.js +258 -0
  69. package/lib/queryBuilder/join/TableNode.js +136 -0
  70. package/lib/queryBuilder/join/TableTree.js +69 -0
  71. package/lib/queryBuilder/join/utils.js +19 -0
  72. package/lib/queryBuilder/operations/DelegateOperation.js +101 -0
  73. package/lib/queryBuilder/operations/DeleteOperation.js +47 -0
  74. package/lib/queryBuilder/operations/FindByIdOperation.js +29 -0
  75. package/lib/queryBuilder/operations/FindByIdsOperation.js +23 -0
  76. package/lib/queryBuilder/operations/FindOperation.js +147 -0
  77. package/lib/queryBuilder/operations/FirstOperation.js +22 -0
  78. package/lib/queryBuilder/operations/FromOperation.js +91 -0
  79. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +38 -0
  80. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +35 -0
  81. package/lib/queryBuilder/operations/InsertGraphOperation.js +87 -0
  82. package/lib/queryBuilder/operations/InsertOperation.js +173 -0
  83. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +37 -0
  84. package/lib/queryBuilder/operations/InstanceFindOperation.js +17 -0
  85. package/lib/queryBuilder/operations/InstanceInsertOperation.js +20 -0
  86. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +45 -0
  87. package/lib/queryBuilder/operations/JoinRelatedOperation.js +83 -0
  88. package/lib/queryBuilder/operations/KnexOperation.js +11 -0
  89. package/lib/queryBuilder/operations/MergeOperation.js +43 -0
  90. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +173 -0
  91. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +23 -0
  92. package/lib/queryBuilder/operations/OnBuildOperation.js +23 -0
  93. package/lib/queryBuilder/operations/OnErrorOperation.js +23 -0
  94. package/lib/queryBuilder/operations/QueryBuilderOperation.js +258 -0
  95. package/lib/queryBuilder/operations/RangeOperation.js +37 -0
  96. package/lib/queryBuilder/operations/RelateOperation.js +20 -0
  97. package/lib/queryBuilder/operations/ReturningOperation.js +24 -0
  98. package/lib/queryBuilder/operations/RunAfterOperation.js +23 -0
  99. package/lib/queryBuilder/operations/RunBeforeOperation.js +23 -0
  100. package/lib/queryBuilder/operations/UnrelateOperation.js +18 -0
  101. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +63 -0
  102. package/lib/queryBuilder/operations/UpdateOperation.js +130 -0
  103. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +35 -0
  104. package/lib/queryBuilder/operations/UpsertGraphOperation.js +47 -0
  105. package/lib/queryBuilder/operations/WhereCompositeOperation.js +48 -0
  106. package/lib/queryBuilder/operations/WhereInOperation.js +46 -0
  107. package/lib/queryBuilder/operations/eager/EagerOperation.js +46 -0
  108. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +41 -0
  109. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +10 -0
  110. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +227 -0
  111. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +29 -0
  112. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +37 -0
  113. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +30 -0
  114. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +33 -0
  115. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +155 -0
  116. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +135 -0
  117. package/lib/queryBuilder/operations/select/SelectOperation.js +50 -0
  118. package/lib/queryBuilder/operations/select/Selection.js +112 -0
  119. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +84 -0
  120. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +90 -0
  121. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +95 -0
  122. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +787 -0
  123. package/lib/queryBuilder/parsers/relationExpressionParser.js +930 -0
  124. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +17 -0
  125. package/lib/queryBuilder/transformations/QueryTransformation.js +9 -0
  126. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +57 -0
  127. package/lib/queryBuilder/transformations/index.js +9 -0
  128. package/lib/queryBuilder/whereScopes.js +199 -0
  129. package/lib/relations/Relation.js +317 -0
  130. package/lib/relations/RelationDeleteOperation.js +23 -0
  131. package/lib/relations/RelationFindOperation.js +116 -0
  132. package/lib/relations/RelationInsertOperation.js +25 -0
  133. package/lib/relations/RelationOwner.js +199 -0
  134. package/lib/relations/RelationProperty.js +207 -0
  135. package/lib/relations/RelationUpdateOperation.js +23 -0
  136. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +18 -0
  137. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +33 -0
  138. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +39 -0
  139. package/lib/relations/belongsToOne/BelongsToOneRelation.js +45 -0
  140. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +46 -0
  141. package/lib/relations/hasMany/HasManyInsertOperation.js +45 -0
  142. package/lib/relations/hasMany/HasManyRelateOperation.js +48 -0
  143. package/lib/relations/hasMany/HasManyRelation.js +41 -0
  144. package/lib/relations/hasMany/HasManyUnrelateOperation.js +26 -0
  145. package/lib/relations/hasOne/HasOneRelation.js +10 -0
  146. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +10 -0
  147. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +82 -0
  148. package/lib/relations/manyToMany/ManyToManyRelation.js +405 -0
  149. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +29 -0
  150. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -0
  151. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -0
  152. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -0
  153. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +82 -0
  154. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +40 -0
  155. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +64 -0
  156. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +11 -0
  157. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +27 -0
  158. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +11 -0
  159. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -0
  160. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +65 -0
  161. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -0
  162. package/lib/transaction.js +66 -0
  163. package/lib/utils/assert.js +19 -0
  164. package/lib/utils/buildUtils.js +19 -0
  165. package/lib/utils/classUtils.js +9 -0
  166. package/lib/utils/cloneDeep.js +365 -0
  167. package/lib/utils/createModifier.js +37 -0
  168. package/lib/utils/deprecate.js +11 -0
  169. package/lib/utils/identifierMapping.js +188 -0
  170. package/lib/utils/internalPropUtils.js +7 -0
  171. package/lib/utils/knexUtils.js +81 -0
  172. package/lib/utils/mixin.js +18 -0
  173. package/lib/utils/mysqlJsonPath.js +70 -0
  174. package/lib/utils/normalizeIds.js +127 -0
  175. package/lib/utils/objectUtils.js +314 -0
  176. package/lib/utils/parseFieldExpression.js +73 -0
  177. package/lib/utils/postgresJsonPath.js +96 -0
  178. package/lib/utils/promiseUtils/after.js +14 -0
  179. package/lib/utils/promiseUtils/afterReturn.js +14 -0
  180. package/lib/utils/promiseUtils/index.js +15 -0
  181. package/lib/utils/promiseUtils/isPromise.js +8 -0
  182. package/lib/utils/promiseUtils/map.js +96 -0
  183. package/lib/utils/promiseUtils/mapAfterAllReturn.js +23 -0
  184. package/lib/utils/promiseUtils/try.js +19 -0
  185. package/lib/utils/resolveModel.js +104 -0
  186. package/lib/utils/tmpColumnUtils.js +7 -0
  187. package/package.json +113 -4
  188. package/typings/objection/index.d.mts +362 -0
  189. package/typings/objection/index.d.ts +4131 -0
  190. package/typings/objection/relation-expression.d.ts +237 -0
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+ const { withWhereScope } = require('../../../queryBuilder/whereScopes');
3
+ const { UnrelateOperation } = require('../../../queryBuilder/operations/UnrelateOperation');
4
+ class ManyToManyUnrelateOperationBase extends UnrelateOperation {
5
+ queryExecutor(builder) {
6
+ const unrelateQuery = this.relation
7
+ .getJoinModelClass(builder.knex())
8
+ .query()
9
+ .childQueryOf(builder)
10
+ .delete();
11
+ withWhereScope(unrelateQuery, () => {
12
+ this.applyModifyFilterForJoinTable(unrelateQuery);
13
+ });
14
+ return unrelateQuery.modify(this.relation.joinTableModify);
15
+ }
16
+ /* istanbul ignore next */
17
+ applyModifyFilterForRelatedTable(builder) {
18
+ throw new Error('not implemented');
19
+ }
20
+ /* istanbul ignore next */
21
+ applyModifyFilterForJoinTable(builder) {
22
+ throw new Error('not implemented');
23
+ }
24
+ }
25
+ module.exports = {
26
+ ManyToManyUnrelateOperationBase,
27
+ };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+ const { ManyToManyUnrelateOperationBase } = require('./ManyToManyUnrelateOperationBase');
3
+ const { ManyToManySqliteModifyMixin } = require('../ManyToManySqliteModifyMixin');
4
+ class ManyToManyUnrelateSqliteOperation extends ManyToManySqliteModifyMixin(ManyToManyUnrelateOperationBase) {
5
+ get modifyMainQuery() {
6
+ return false;
7
+ }
8
+ }
9
+ module.exports = {
10
+ ManyToManyUnrelateSqliteOperation,
11
+ };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ const { ManyToManyUpdateOperationBase } = require('./ManyToManyUpdateOperationBase');
3
+ const { ManyToManyModifyMixin } = require('../ManyToManyModifyMixin');
4
+ class ManyToManyUpdateOperation extends ManyToManyModifyMixin(ManyToManyUpdateOperationBase) {
5
+ }
6
+ module.exports = {
7
+ ManyToManyUpdateOperation,
8
+ };
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+ const { withWhereScope } = require('../../../queryBuilder/whereScopes');
3
+ const { UpdateOperation } = require('../../../queryBuilder/operations/UpdateOperation');
4
+ class ManyToManyUpdateOperationBase extends UpdateOperation {
5
+ constructor(name, opt) {
6
+ super(name, opt);
7
+ this.relation = opt.relation;
8
+ this.owner = opt.owner;
9
+ this.hasExtraProps = false;
10
+ this.joinTablePatch = {};
11
+ this.joinTablePatchFilterQuery = null;
12
+ }
13
+ onAdd(builder, args) {
14
+ const obj = args[0];
15
+ // Copy all extra properties to the `joinTablePatch` object.
16
+ for (const extra of this.relation.joinTableExtras) {
17
+ if (extra.aliasProp in obj) {
18
+ this.hasExtraProps = true;
19
+ this.joinTablePatch[extra.joinTableProp] = obj[extra.aliasProp];
20
+ }
21
+ }
22
+ const res = super.onAdd(builder, args);
23
+ if (this.hasExtraProps) {
24
+ // Make sure we don't try to insert the extra properties
25
+ // to the target table.
26
+ this.relation.omitExtraProps([this.model]);
27
+ }
28
+ return res;
29
+ }
30
+ async onAfter1(builder, result) {
31
+ if (this.hasExtraProps) {
32
+ const joinTableUpdateQuery = this.relation
33
+ .getJoinModelClass(builder.knex())
34
+ .query()
35
+ .childQueryOf(builder)
36
+ .patch(this.joinTablePatch);
37
+ withWhereScope(joinTableUpdateQuery, () => {
38
+ this.applyModifyFilterForJoinTable(joinTableUpdateQuery);
39
+ });
40
+ await joinTableUpdateQuery.modify(this.relation.joinTableModify);
41
+ return result;
42
+ }
43
+ else {
44
+ return result;
45
+ }
46
+ }
47
+ /* istanbul ignore next */
48
+ applyModifyFilterForRelatedTable(builder) {
49
+ throw new Error('not implemented');
50
+ }
51
+ /* istanbul ignore next */
52
+ applyModifyFilterForJoinTable(builder) {
53
+ throw new Error('not implemented');
54
+ }
55
+ clone() {
56
+ const clone = super.clone();
57
+ clone.hasExtraProps = this.hasExtraProps;
58
+ clone.joinTablePatch = this.joinTablePatch;
59
+ clone.joinTablePatchFilterQuery = this.joinTablePatchFilterQuery;
60
+ return clone;
61
+ }
62
+ }
63
+ module.exports = {
64
+ ManyToManyUpdateOperationBase,
65
+ };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+ const { ManyToManyUpdateOperationBase } = require('./ManyToManyUpdateOperationBase');
3
+ const { ManyToManySqliteModifyMixin } = require('../ManyToManySqliteModifyMixin');
4
+ class ManyToManyUpdateSqliteOperation extends ManyToManySqliteModifyMixin(ManyToManyUpdateOperationBase) {
5
+ }
6
+ module.exports = {
7
+ ManyToManyUpdateSqliteOperation,
8
+ };
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+ const promiseUtils = require('./utils/promiseUtils');
3
+ const { isFunction } = require('./utils/objectUtils');
4
+ function transaction() {
5
+ // There must be at least one model class and the callback.
6
+ if (arguments.length < 2) {
7
+ return Promise.reject(new Error('objection.transaction: provide at least one Model class to bind to the transaction or a knex instance'));
8
+ }
9
+ let args = Array.from(arguments);
10
+ if (!isModelClass(args[0]) && isFunction(args[0].transaction)) {
11
+ const knex = args[0];
12
+ args = args.slice(1);
13
+ return knex.transaction.apply(knex, args);
14
+ }
15
+ else {
16
+ // The last argument should be the callback and all other Model subclasses.
17
+ const callback = args[args.length - 1];
18
+ const modelClasses = args.slice(0, args.length - 1);
19
+ let i;
20
+ for (i = 0; i < modelClasses.length; ++i) {
21
+ if (!isModelClass(modelClasses[i])) {
22
+ return Promise.reject(new Error('objection.transaction: all but the last argument should be Model subclasses'));
23
+ }
24
+ }
25
+ const knex = modelClasses[0].knex();
26
+ for (i = 0; i < modelClasses.length; ++i) {
27
+ if (modelClasses[i].knex() !== knex) {
28
+ return Promise.reject(new Error('objection.transaction: all Model subclasses must be bound to the same database'));
29
+ }
30
+ }
31
+ return knex.transaction((trx) => {
32
+ const args = new Array(modelClasses.length + 1);
33
+ for (let i = 0; i < modelClasses.length; ++i) {
34
+ args[i] = modelClasses[i].bindTransaction(trx);
35
+ }
36
+ args[args.length - 1] = trx;
37
+ return promiseUtils.try(() => {
38
+ return callback.apply(trx, args);
39
+ });
40
+ });
41
+ }
42
+ }
43
+ transaction.start = function (modelClassOrKnex) {
44
+ let knex = modelClassOrKnex;
45
+ if (isModelClass(modelClassOrKnex)) {
46
+ knex = modelClassOrKnex.knex();
47
+ }
48
+ if (!knex || !isFunction(knex.transaction)) {
49
+ return Promise.reject(new Error('objection.transaction.start: first argument must be a model class or a knex instance'));
50
+ }
51
+ return new Promise((resolve, reject) => {
52
+ knex
53
+ .transaction((trx) => {
54
+ resolve(trx);
55
+ })
56
+ .catch((err) => {
57
+ reject(err);
58
+ });
59
+ });
60
+ };
61
+ function isModelClass(maybeModel) {
62
+ return isFunction(maybeModel) && maybeModel.isObjectionModelClass;
63
+ }
64
+ module.exports = {
65
+ transaction,
66
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertHasId = assertHasId;
4
+ exports.assertIdNotUndefined = assertIdNotUndefined;
5
+ function assertHasId(model) {
6
+ if (!model.$hasId()) {
7
+ const modelClass = model.constructor;
8
+ const ids = modelClass.getIdColumnArray().join(', ');
9
+ throw new Error(`one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${modelClass.name}' using the 'idColumn' property?`);
10
+ }
11
+ }
12
+ function assertIdNotUndefined(id, message) {
13
+ if (Array.isArray(id)) {
14
+ id.forEach((id) => assertIdNotUndefined(id, message));
15
+ }
16
+ else if (id === undefined) {
17
+ throw Error(message);
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildArg = buildArg;
4
+ const objectUtils_1 = require("./objectUtils");
5
+ function buildArg(arg, builder) {
6
+ if (!(0, objectUtils_1.isObject)(arg)) {
7
+ return arg;
8
+ }
9
+ const buildable = arg;
10
+ if ((0, objectUtils_1.isFunction)(buildable.toKnexRaw)) {
11
+ return buildable.toKnexRaw(builder);
12
+ }
13
+ else if (buildable.isObjectionQueryBuilderBase === true) {
14
+ return buildable.subqueryOf(builder).toKnexQuery();
15
+ }
16
+ else {
17
+ return arg;
18
+ }
19
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inherit = inherit;
4
+ function inherit(Constructor, BaseConstructor) {
5
+ Constructor.prototype = Object.create(BaseConstructor.prototype);
6
+ Constructor.prototype.constructor = BaseConstructor;
7
+ Object.setPrototypeOf(Constructor, BaseConstructor);
8
+ return Constructor;
9
+ }
@@ -0,0 +1,365 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneDeep = cloneDeep;
4
+ const node_util_1 = require("node:util");
5
+ const { isTypedArray, isMap, isSet, isProxy } = node_util_1.types;
6
+ const toString = Object.prototype.toString;
7
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
8
+ const propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
9
+ const getPrototypeOf = Object.getPrototypeOf;
10
+ const getOwnPropertySymbols = Object.getOwnPropertySymbols;
11
+ const objectKeys = Object.keys;
12
+ const objectProto = Object.prototype;
13
+ const symToStringTag = Symbol.toStringTag;
14
+ const symbolValueOf = Symbol.prototype.valueOf;
15
+ const ARGS_TAG = '[object Arguments]';
16
+ const ARRAY_BUFFER_TAG = '[object ArrayBuffer]';
17
+ const BOOL_TAG = '[object Boolean]';
18
+ const DATA_VIEW_TAG = '[object DataView]';
19
+ const DATE_TAG = '[object Date]';
20
+ const FUNC_TAG = '[object Function]';
21
+ const GEN_TAG = '[object GeneratorFunction]';
22
+ const MAP_TAG = '[object Map]';
23
+ const NUMBER_TAG = '[object Number]';
24
+ const OBJECT_TAG = '[object Object]';
25
+ const REGEXP_TAG = '[object RegExp]';
26
+ const SET_TAG = '[object Set]';
27
+ const STRING_TAG = '[object String]';
28
+ const SYMBOL_TAG = '[object Symbol]';
29
+ const TYPED_ARRAY_TAGS = [
30
+ '[object Float32Array]',
31
+ '[object Float64Array]',
32
+ '[object Int8Array]',
33
+ '[object Int16Array]',
34
+ '[object Int32Array]',
35
+ '[object Uint8Array]',
36
+ '[object Uint8ClampedArray]',
37
+ '[object Uint16Array]',
38
+ '[object Uint32Array]',
39
+ ];
40
+ // The tags lodash clones by type. Values with other tags (Error, WeakMap,
41
+ // Promise, a custom `Symbol.toStringTag` and so on) aren't cloned.
42
+ const CLONEABLE_TAGS = new Set([
43
+ ARGS_TAG,
44
+ '[object Array]',
45
+ ARRAY_BUFFER_TAG,
46
+ DATA_VIEW_TAG,
47
+ BOOL_TAG,
48
+ DATE_TAG,
49
+ MAP_TAG,
50
+ NUMBER_TAG,
51
+ OBJECT_TAG,
52
+ REGEXP_TAG,
53
+ SET_TAG,
54
+ STRING_TAG,
55
+ SYMBOL_TAG,
56
+ ...TYPED_ARRAY_TAGS,
57
+ ]);
58
+ const RE_FLAGS = /\w*$/;
59
+ const RE_IS_UINT = /^(?:0|[1-9]\d*)$/;
60
+ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
61
+ function cloneDeep(value) {
62
+ if (!isObject(value)) {
63
+ return value;
64
+ }
65
+ return baseClone(value, false, new Map());
66
+ }
67
+ // `isNested` is true when the value is inside another value.
68
+ function baseClone(value, isNested, seen) {
69
+ if (!isObject(value)) {
70
+ return value;
71
+ }
72
+ if (Array.isArray(value)) {
73
+ return cloneArray(value, seen);
74
+ }
75
+ if (Buffer.isBuffer(value)) {
76
+ // Buffers are cloned before the lookup of values already seen, so a
77
+ // buffer found twice gives two copies, as in lodash.
78
+ const result = Buffer.allocUnsafe(value.length);
79
+ value.copy(result);
80
+ return result;
81
+ }
82
+ if (getPrototypeOf(value) === objectProto && !hasOwnProperty.call(value, symToStringTag)) {
83
+ return clonePlainObject(value, seen);
84
+ }
85
+ return cloneOther(value, isNested, seen);
86
+ }
87
+ function cloneArray(array, seen) {
88
+ const length = array.length;
89
+ const Ctor = array.constructor;
90
+ const result = new Ctor(length);
91
+ // The properties `RegExp#exec` adds to its result.
92
+ if (length && typeof array[0] === 'string' && hasOwnProperty.call(array, 'index')) {
93
+ result.index = array.index;
94
+ result.input = array.input;
95
+ }
96
+ const cloned = seen.get(array);
97
+ if (cloned !== undefined) {
98
+ return cloned;
99
+ }
100
+ seen.set(array, result);
101
+ if (Ctor === Array) {
102
+ // A new Array has no elements yet, so every assignment happens.
103
+ for (let i = 0; i < length; ++i) {
104
+ result[i] = baseClone(array[i], true, seen);
105
+ }
106
+ }
107
+ else {
108
+ for (let i = 0; i < length; ++i) {
109
+ assignValue(result, i, baseClone(array[i], true, seen));
110
+ }
111
+ }
112
+ return result;
113
+ }
114
+ // An object whose prototype is Object.prototype. This is the same as the
115
+ // general path for such objects, without the checks that can't apply.
116
+ function clonePlainObject(obj, seen) {
117
+ const cloned = seen.get(obj);
118
+ if (cloned !== undefined) {
119
+ return cloned;
120
+ }
121
+ const result = {};
122
+ seen.set(obj, result);
123
+ const keys = objectKeys(obj);
124
+ for (let i = 0, l = keys.length; i < l; ++i) {
125
+ const key = keys[i];
126
+ // lodash skips the `constructor` key of prototype objects.
127
+ if (key === 'constructor' && !isArrayLike(obj) && isPrototype(obj)) {
128
+ continue;
129
+ }
130
+ const value = baseClone(obj[key], true, seen);
131
+ if (key === '__proto__') {
132
+ defineOwn(result, key, value);
133
+ }
134
+ else {
135
+ result[key] = value;
136
+ }
137
+ }
138
+ copySymbols(obj, result, seen);
139
+ return result;
140
+ }
141
+ function cloneOther(value, isNested, seen) {
142
+ const tag = getTag(value);
143
+ const isFunc = tag === FUNC_TAG || tag === GEN_TAG;
144
+ let result;
145
+ if (tag === OBJECT_TAG || tag === ARGS_TAG || (isFunc && !isNested)) {
146
+ result = isFunc ? {} : initCloneObject(value);
147
+ }
148
+ else if (!CLONEABLE_TAGS.has(tag)) {
149
+ return isNested ? value : {};
150
+ }
151
+ else {
152
+ result = initCloneByTag(value, tag);
153
+ }
154
+ const cloned = seen.get(value);
155
+ if (cloned !== undefined) {
156
+ return cloned;
157
+ }
158
+ seen.set(value, result);
159
+ if (isSet(value)) {
160
+ value.forEach((item) => {
161
+ result.add(baseClone(item, true, seen));
162
+ });
163
+ return result;
164
+ }
165
+ if (isMap(value)) {
166
+ value.forEach((item, key) => {
167
+ result.set(key, baseClone(item, true, seen));
168
+ });
169
+ return result;
170
+ }
171
+ const keys = getKeys(value);
172
+ for (let i = 0, l = keys.length; i < l; ++i) {
173
+ const key = keys[i];
174
+ assignValue(result, key, baseClone(value[key], true, seen));
175
+ }
176
+ copySymbols(value, result, seen);
177
+ return result;
178
+ }
179
+ function copySymbols(source, result, seen) {
180
+ const symbols = getOwnPropertySymbols(source);
181
+ for (let i = 0, l = symbols.length; i < l; ++i) {
182
+ const symbol = symbols[i];
183
+ if (propertyIsEnumerable.call(source, symbol)) {
184
+ assignValue(result, symbol, baseClone(source[symbol], true, seen));
185
+ }
186
+ }
187
+ }
188
+ function initCloneObject(value) {
189
+ if (typeof value.constructor === 'function' && !isPrototype(value)) {
190
+ const proto = getPrototypeOf(value);
191
+ return isObject(proto) ? Object.create(proto) : {};
192
+ }
193
+ return {};
194
+ }
195
+ // `value` is an object with one of the tags in CLONEABLE_TAGS, other than
196
+ // the object, arguments and array tags.
197
+ function initCloneByTag(value, tag) {
198
+ const Ctor = value.constructor;
199
+ switch (tag) {
200
+ case ARRAY_BUFFER_TAG:
201
+ return cloneArrayBuffer(value);
202
+ case BOOL_TAG:
203
+ case DATE_TAG:
204
+ return new Ctor(+value);
205
+ case DATA_VIEW_TAG: {
206
+ const dataView = value;
207
+ return new Ctor(cloneArrayBuffer(dataView.buffer), dataView.byteOffset, dataView.byteLength);
208
+ }
209
+ case MAP_TAG:
210
+ case SET_TAG:
211
+ return new Ctor();
212
+ case NUMBER_TAG:
213
+ case STRING_TAG:
214
+ return new Ctor(value);
215
+ case REGEXP_TAG: {
216
+ const regExp = value;
217
+ const result = new Ctor(regExp.source, RE_FLAGS.exec(regExp));
218
+ result.lastIndex = regExp.lastIndex;
219
+ return result;
220
+ }
221
+ case SYMBOL_TAG:
222
+ return Object(symbolValueOf.call(value));
223
+ default: {
224
+ // A typed array.
225
+ const typedArray = value;
226
+ return new Ctor(cloneArrayBuffer(typedArray.buffer), typedArray.byteOffset, typedArray.length);
227
+ }
228
+ }
229
+ }
230
+ function cloneArrayBuffer(arrayBuffer) {
231
+ const result = new arrayBuffer.constructor(arrayBuffer.byteLength);
232
+ new Uint8Array(result).set(new Uint8Array(arrayBuffer));
233
+ return result;
234
+ }
235
+ // lodash's `keys`: the own enumerable string keys, except the indexes and
236
+ // `length` of arguments objects and typed arrays (which are listed by index
237
+ // instead) and the `constructor` key of prototype objects.
238
+ function getKeys(value) {
239
+ if (isArrayLike(value)) {
240
+ return arrayLikeKeys(value);
241
+ }
242
+ const keys = objectKeys(value);
243
+ return isPrototype(value) ? keys.filter((key) => key !== 'constructor') : keys;
244
+ }
245
+ function arrayLikeKeys(value) {
246
+ const isArgs = getTag(value) === ARGS_TAG;
247
+ const isTyped = !isArgs && isTypedArray(value);
248
+ const skipIndexes = isArgs || isTyped;
249
+ const length = skipIndexes ? value.length : 0;
250
+ const result = [];
251
+ for (let i = 0; i < length; ++i) {
252
+ result.push(String(i));
253
+ }
254
+ for (const key in value) {
255
+ if (hasOwnProperty.call(value, key) &&
256
+ !(skipIndexes &&
257
+ (key === 'length' ||
258
+ (isTyped && (key === 'buffer' || key === 'byteLength' || key === 'byteOffset')) ||
259
+ isIndex(key, length)))) {
260
+ result.push(key);
261
+ }
262
+ }
263
+ return result;
264
+ }
265
+ // lodash's `getTag`, which reads the built-in tag of an object whose
266
+ // `Symbol.toStringTag` property can be written over, the way lodash does it:
267
+ // lodash writes `undefined` over the tag, reads the tag and puts it back.
268
+ // Writing over a read-only tag, like the ones of Map, Set and the typed
269
+ // arrays, throws. That is checked first, because a throw is slow.
270
+ function getTag(value) {
271
+ if (!(symToStringTag in value)) {
272
+ return toString.call(value);
273
+ }
274
+ if (isProxy(value)) {
275
+ return getTagByWriting(value);
276
+ }
277
+ return canWriteTag(value) ? getTagByWriting(value) : toString.call(value);
278
+ }
279
+ // Whether `value[Symbol.toStringTag] = undefined` would succeed: the first
280
+ // object up the prototype chain that has the property decides, as in the
281
+ // [[Set]] of ordinary objects.
282
+ function canWriteTag(value) {
283
+ let obj = value;
284
+ while (obj !== null) {
285
+ if (isProxy(obj)) {
286
+ // A proxy decides for itself. Try it, as lodash does.
287
+ return true;
288
+ }
289
+ const desc = Object.getOwnPropertyDescriptor(obj, symToStringTag);
290
+ if (desc !== undefined) {
291
+ if ('value' in desc) {
292
+ return desc.writable && (obj === value || Object.isExtensible(value));
293
+ }
294
+ return desc.set !== undefined;
295
+ }
296
+ obj = getPrototypeOf(obj);
297
+ }
298
+ return true;
299
+ }
300
+ function getTagByWriting(value) {
301
+ const obj = value;
302
+ const isOwn = hasOwnProperty.call(obj, symToStringTag);
303
+ const tag = obj[symToStringTag];
304
+ let unmasked = false;
305
+ try {
306
+ obj[symToStringTag] = undefined;
307
+ unmasked = true;
308
+ }
309
+ catch (err) {
310
+ // The tag can't be written over, so it's used as is.
311
+ }
312
+ const result = toString.call(obj);
313
+ if (unmasked) {
314
+ if (isOwn) {
315
+ obj[symToStringTag] = tag;
316
+ }
317
+ else {
318
+ delete obj[symToStringTag];
319
+ }
320
+ }
321
+ return result;
322
+ }
323
+ // Assigns unless the property already has the same value, as lodash does.
324
+ function assignValue(object, key, value) {
325
+ const objValue = object[key];
326
+ if (!(hasOwnProperty.call(object, key) && sameValueZero(objValue, value)) ||
327
+ (value === undefined && !(key in object))) {
328
+ if (key === '__proto__') {
329
+ defineOwn(object, key, value);
330
+ }
331
+ else {
332
+ object[key] = value;
333
+ }
334
+ }
335
+ }
336
+ function defineOwn(object, key, value) {
337
+ Object.defineProperty(object, key, {
338
+ configurable: true,
339
+ enumerable: true,
340
+ value,
341
+ writable: true,
342
+ });
343
+ }
344
+ function isObject(value) {
345
+ const type = typeof value;
346
+ return value !== null && (type === 'object' || type === 'function');
347
+ }
348
+ function isPrototype(value) {
349
+ const Ctor = value.constructor;
350
+ const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
351
+ return value === proto;
352
+ }
353
+ function isArrayLike(value) {
354
+ return typeof value !== 'function' && isLength(value.length);
355
+ }
356
+ function isLength(value) {
357
+ return typeof value === 'number' && value > -1 && value % 1 === 0 && value <= MAX_SAFE_INTEGER;
358
+ }
359
+ function isIndex(key, length) {
360
+ // `key < length` compares the key as a number.
361
+ return length > 0 && RE_IS_UINT.test(key) && key < length;
362
+ }
363
+ function sameValueZero(a, b) {
364
+ return a === b || (a !== a && b !== b);
365
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createModifier = createModifier;
4
+ const objectUtils_1 = require("./objectUtils");
5
+ function createModifier({ modelClass, modifier, modifiers, }) {
6
+ const modelModifiers = modelClass ? modelClass.getModifiers() : {};
7
+ const modifierFunctions = (0, objectUtils_1.asArray)(modifier).map((modifier) => {
8
+ let modify = null;
9
+ if ((0, objectUtils_1.isString)(modifier)) {
10
+ modify = (modifiers && modifiers[modifier]) || modelModifiers[modifier];
11
+ // Modifiers can be pointers to other modifiers. Call this function recursively.
12
+ if (modify && !(0, objectUtils_1.isFunction)(modify)) {
13
+ return createModifier({ modelClass, modifier: modify, modifiers });
14
+ }
15
+ }
16
+ else if ((0, objectUtils_1.isFunction)(modifier)) {
17
+ modify = modifier;
18
+ }
19
+ else if ((0, objectUtils_1.isPlainObject)(modifier)) {
20
+ modify = (builder) => builder.where(modifier);
21
+ }
22
+ else if (Array.isArray(modifier)) {
23
+ return createModifier({ modelClass, modifier, modifiers });
24
+ }
25
+ if (!modify) {
26
+ // Without a model class this throws when the modifier is called, as it did
27
+ // in the JavaScript code.
28
+ modify = (builder) => modelClass.modifierNotFound(builder, modifier);
29
+ }
30
+ return modify;
31
+ });
32
+ return (builder, ...args) => {
33
+ for (const modifier of modifierFunctions) {
34
+ modifier.call(builder, builder, ...args);
35
+ }
36
+ };
37
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deprecate = deprecate;
4
+ const LOGGED_DEPRECATIONS = new Set();
5
+ function deprecate(message) {
6
+ // Only log deprecation messages once.
7
+ if (!LOGGED_DEPRECATIONS.has(message)) {
8
+ LOGGED_DEPRECATIONS.add(message);
9
+ console.warn(message);
10
+ }
11
+ }