@abedmurrar/objection 4.0.0-alpha.0 → 4.0.0-beta.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 (192) hide show
  1. package/README.md +103 -67
  2. package/lib/index.mjs +6 -0
  3. package/lib/initialize.js +6 -9
  4. package/lib/model/AjvValidator.js +235 -282
  5. package/lib/model/Model.js +653 -823
  6. package/lib/model/ModifierNotFoundError.js +5 -7
  7. package/lib/model/NotFoundError.js +14 -18
  8. package/lib/model/RelationDoesNotExistError.js +6 -9
  9. package/lib/model/ValidationError.js +33 -41
  10. package/lib/model/Validator.js +15 -21
  11. package/lib/model/getModel.js +1 -3
  12. package/lib/model/graph/ModelGraph.js +44 -64
  13. package/lib/model/graph/ModelGraphBuilder.js +164 -217
  14. package/lib/model/graph/ModelGraphEdge.js +31 -43
  15. package/lib/model/graph/ModelGraphNode.js +192 -231
  16. package/lib/model/inheritModel.js +9 -18
  17. package/lib/model/modelBindKnex.js +48 -62
  18. package/lib/model/modelClone.js +79 -98
  19. package/lib/model/modelColPropMap.js +16 -26
  20. package/lib/model/modelConcurrency.js +24 -0
  21. package/lib/model/modelId.js +44 -49
  22. package/lib/model/modelJsonAttributes.js +56 -76
  23. package/lib/model/modelParseRelations.js +68 -67
  24. package/lib/model/modelQueryProps.js +76 -107
  25. package/lib/model/modelSet.js +92 -112
  26. package/lib/model/modelTableMetadata.js +60 -72
  27. package/lib/model/modelToJson.js +120 -150
  28. package/lib/model/modelUtils.js +30 -37
  29. package/lib/model/modelValidate.js +34 -42
  30. package/lib/model/modelValues.js +78 -91
  31. package/lib/model/modelVisitor.js +22 -29
  32. package/lib/objection.js +42 -67
  33. package/lib/queryBuilder/FunctionBuilder.js +231 -279
  34. package/lib/queryBuilder/InternalOptions.js +19 -24
  35. package/lib/queryBuilder/JoinBuilder.js +116 -149
  36. package/lib/queryBuilder/QueryBuilder.js +1009 -1271
  37. package/lib/queryBuilder/QueryBuilderBase.js +647 -865
  38. package/lib/queryBuilder/QueryBuilderContext.js +14 -21
  39. package/lib/queryBuilder/QueryBuilderContextBase.js +20 -29
  40. package/lib/queryBuilder/QueryBuilderOperationSupport.js +462 -536
  41. package/lib/queryBuilder/QueryBuilderUserContext.js +19 -25
  42. package/lib/queryBuilder/RawBuilder.js +58 -73
  43. package/lib/queryBuilder/ReferenceBuilder.js +232 -270
  44. package/lib/queryBuilder/RelationExpression.js +322 -380
  45. package/lib/queryBuilder/StaticHookArguments.js +94 -106
  46. package/lib/queryBuilder/ValueBuilder.js +100 -112
  47. package/lib/queryBuilder/expressions.js +86 -116
  48. package/lib/queryBuilder/functions/mysql.js +642 -697
  49. package/lib/queryBuilder/graph/GraphAction.js +44 -59
  50. package/lib/queryBuilder/graph/GraphData.js +7 -9
  51. package/lib/queryBuilder/graph/GraphFetcher.js +115 -151
  52. package/lib/queryBuilder/graph/GraphNodeDbExistence.js +114 -152
  53. package/lib/queryBuilder/graph/GraphOperation.js +16 -22
  54. package/lib/queryBuilder/graph/GraphOptions.js +143 -185
  55. package/lib/queryBuilder/graph/GraphUpsert.js +167 -241
  56. package/lib/queryBuilder/graph/delete/GraphDelete.js +8 -13
  57. package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +44 -62
  58. package/lib/queryBuilder/graph/insert/GraphInsert.js +99 -128
  59. package/lib/queryBuilder/graph/insert/GraphInsertAction.js +151 -193
  60. package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +57 -79
  61. package/lib/queryBuilder/graph/patch/GraphPatch.js +8 -13
  62. package/lib/queryBuilder/graph/patch/GraphPatchAction.js +181 -234
  63. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +16 -21
  64. package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +80 -110
  65. package/lib/queryBuilder/join/JoinResultColumn.js +14 -18
  66. package/lib/queryBuilder/join/JoinResultParser.js +88 -101
  67. package/lib/queryBuilder/join/RelationJoiner.js +205 -288
  68. package/lib/queryBuilder/join/TableNode.js +117 -144
  69. package/lib/queryBuilder/join/TableTree.js +60 -76
  70. package/lib/queryBuilder/join/utils.js +10 -16
  71. package/lib/queryBuilder/operations/DelegateOperation.js +93 -133
  72. package/lib/queryBuilder/operations/DeleteOperation.js +33 -37
  73. package/lib/queryBuilder/operations/FindByIdOperation.js +20 -28
  74. package/lib/queryBuilder/operations/FindByIdsOperation.js +17 -23
  75. package/lib/queryBuilder/operations/FindOperation.js +114 -131
  76. package/lib/queryBuilder/operations/FirstOperation.js +14 -19
  77. package/lib/queryBuilder/operations/FromOperation.js +69 -88
  78. package/lib/queryBuilder/operations/InsertAndFetchOperation.js +28 -39
  79. package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +25 -35
  80. package/lib/queryBuilder/operations/InsertGraphOperation.js +77 -98
  81. package/lib/queryBuilder/operations/InsertOperation.js +132 -165
  82. package/lib/queryBuilder/operations/InstanceDeleteOperation.js +27 -36
  83. package/lib/queryBuilder/operations/InstanceFindOperation.js +9 -13
  84. package/lib/queryBuilder/operations/InstanceInsertOperation.js +13 -17
  85. package/lib/queryBuilder/operations/InstanceUpdateOperation.js +32 -46
  86. package/lib/queryBuilder/operations/JoinRelatedOperation.js +66 -86
  87. package/lib/queryBuilder/operations/KnexOperation.js +4 -7
  88. package/lib/queryBuilder/operations/MergeOperation.js +32 -45
  89. package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +131 -150
  90. package/lib/queryBuilder/operations/OnBuildKnexOperation.js +17 -23
  91. package/lib/queryBuilder/operations/OnBuildOperation.js +17 -23
  92. package/lib/queryBuilder/operations/OnErrorOperation.js +17 -23
  93. package/lib/queryBuilder/operations/QueryBuilderOperation.js +231 -270
  94. package/lib/queryBuilder/operations/RangeOperation.js +30 -40
  95. package/lib/queryBuilder/operations/RelateOperation.js +14 -21
  96. package/lib/queryBuilder/operations/ReturningOperation.js +12 -18
  97. package/lib/queryBuilder/operations/RunAfterOperation.js +17 -23
  98. package/lib/queryBuilder/operations/RunBeforeOperation.js +17 -23
  99. package/lib/queryBuilder/operations/UnrelateOperation.js +12 -17
  100. package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +48 -65
  101. package/lib/queryBuilder/operations/UpdateOperation.js +104 -129
  102. package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +25 -35
  103. package/lib/queryBuilder/operations/UpsertGraphOperation.js +36 -55
  104. package/lib/queryBuilder/operations/WhereCompositeOperation.js +30 -39
  105. package/lib/queryBuilder/operations/WhereInOperation.js +34 -36
  106. package/lib/queryBuilder/operations/eager/EagerOperation.js +37 -52
  107. package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +34 -44
  108. package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +4 -7
  109. package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +193 -251
  110. package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +18 -25
  111. package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +25 -41
  112. package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +19 -20
  113. package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +23 -21
  114. package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +106 -118
  115. package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +79 -108
  116. package/lib/queryBuilder/operations/select/SelectOperation.js +37 -53
  117. package/lib/queryBuilder/operations/select/Selection.js +94 -105
  118. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +68 -101
  119. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +65 -75
  120. package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +75 -84
  121. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +760 -859
  122. package/lib/queryBuilder/parsers/relationExpressionParser.js +840 -952
  123. package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +10 -15
  124. package/lib/queryBuilder/transformations/QueryTransformation.js +4 -6
  125. package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +35 -49
  126. package/lib/queryBuilder/transformations/index.js +3 -9
  127. package/lib/queryBuilder/whereScopes.js +158 -186
  128. package/lib/relations/Relation.js +293 -375
  129. package/lib/relations/RelationDeleteOperation.js +24 -28
  130. package/lib/relations/RelationFindOperation.js +108 -138
  131. package/lib/relations/RelationInsertOperation.js +24 -32
  132. package/lib/relations/RelationOwner.js +175 -209
  133. package/lib/relations/RelationProperty.js +186 -223
  134. package/lib/relations/RelationUpdateOperation.js +23 -29
  135. package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +16 -21
  136. package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +30 -41
  137. package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +36 -47
  138. package/lib/relations/belongsToOne/BelongsToOneRelation.js +42 -50
  139. package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +43 -58
  140. package/lib/relations/hasMany/HasManyInsertOperation.js +40 -56
  141. package/lib/relations/hasMany/HasManyRelateOperation.js +45 -61
  142. package/lib/relations/hasMany/HasManyRelation.js +38 -46
  143. package/lib/relations/hasMany/HasManyUnrelateOperation.js +25 -32
  144. package/lib/relations/hasOne/HasOneRelation.js +9 -12
  145. package/lib/relations/hasOneThrough/HasOneThroughRelation.js +9 -12
  146. package/lib/relations/manyToMany/ManyToManyModifyMixin.js +73 -95
  147. package/lib/relations/manyToMany/ManyToManyRelation.js +374 -473
  148. package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +23 -30
  149. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +8 -10
  150. package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +20 -25
  151. package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +8 -12
  152. package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +77 -100
  153. package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +37 -49
  154. package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +58 -74
  155. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +10 -13
  156. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +26 -33
  157. package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +10 -15
  158. package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +8 -10
  159. package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +61 -78
  160. package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +8 -12
  161. package/lib/transaction.js +53 -83
  162. package/lib/utils/assert.js +15 -21
  163. package/lib/utils/buildUtils.js +17 -19
  164. package/lib/utils/classUtils.js +7 -11
  165. package/lib/utils/cloneDeep.js +365 -0
  166. package/lib/utils/createModifier.js +36 -41
  167. package/lib/utils/deprecate.js +8 -12
  168. package/lib/utils/identifierMapping.js +153 -192
  169. package/lib/utils/internalPropUtils.js +4 -8
  170. package/lib/utils/knexUtils.js +61 -56
  171. package/lib/utils/mixin.js +16 -23
  172. package/lib/utils/mysqlJsonPath.js +55 -40
  173. package/lib/utils/normalizeIds.js +110 -127
  174. package/lib/utils/objectUtils.js +236 -338
  175. package/lib/utils/parseFieldExpression.js +66 -44
  176. package/lib/utils/postgresJsonPath.js +48 -62
  177. package/lib/utils/promiseUtils/after.js +10 -13
  178. package/lib/utils/promiseUtils/afterReturn.js +10 -13
  179. package/lib/utils/promiseUtils/index.js +15 -17
  180. package/lib/utils/promiseUtils/isPromise.js +6 -9
  181. package/lib/utils/promiseUtils/map.js +75 -89
  182. package/lib/utils/promiseUtils/mapAfterAllReturn.js +17 -23
  183. package/lib/utils/promiseUtils/try.js +15 -18
  184. package/lib/utils/resolveModel.js +91 -94
  185. package/lib/utils/tmpColumnUtils.js +4 -13
  186. package/package.json +50 -23
  187. package/typings/objection/index.d.mts +362 -0
  188. package/typings/objection/index.d.ts +36 -9
  189. package/lib/.eslintrc.json +0 -8
  190. package/lib/queryBuilder/parsers/jsonFieldExpressionParser.pegjs +0 -97
  191. package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +0 -141
  192. package/lib/utils/clone.js +0 -2329
@@ -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
+ }
@@ -1,42 +1,37 @@
1
- 'use strict';
2
-
3
- const { asArray, isString, isFunction, isPlainObject } = require('./objectUtils');
4
-
5
- function createModifier({ modelClass, modifier, modifiers }) {
6
- const modelModifiers = modelClass ? modelClass.getModifiers() : {};
7
-
8
- const modifierFunctions = asArray(modifier).map((modifier) => {
9
- let modify = null;
10
-
11
- if (isString(modifier)) {
12
- modify = (modifiers && modifiers[modifier]) || modelModifiers[modifier];
13
-
14
- // Modifiers can be pointers to other modifiers. Call this function recursively.
15
- if (modify && !isFunction(modify)) {
16
- return createModifier({ modelClass, modifier: modify, modifiers });
17
- }
18
- } else if (isFunction(modifier)) {
19
- modify = modifier;
20
- } else if (isPlainObject(modifier)) {
21
- modify = (builder) => builder.where(modifier);
22
- } else if (Array.isArray(modifier)) {
23
- return createModifier({ modelClass, modifier, modifiers });
24
- }
25
-
26
- if (!modify) {
27
- modify = (builder) => modelClass.modifierNotFound(builder, modifier);
28
- }
29
-
30
- return modify;
31
- });
32
-
33
- return (builder, ...args) => {
34
- for (const modifier of modifierFunctions) {
35
- modifier.call(builder, builder, ...args);
36
- }
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
+ };
38
37
  }
39
-
40
- module.exports = {
41
- createModifier,
42
- };
@@ -1,15 +1,11 @@
1
- 'use strict';
2
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deprecate = deprecate;
3
4
  const LOGGED_DEPRECATIONS = new Set();
4
-
5
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
- }
6
+ // Only log deprecation messages once.
7
+ if (!LOGGED_DEPRECATIONS.has(message)) {
8
+ LOGGED_DEPRECATIONS.add(message);
9
+ console.warn(message);
10
+ }
11
11
  }
12
-
13
- module.exports = {
14
- deprecate,
15
- };