@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
@@ -1,55 +1,70 @@
1
- 'use strict';
2
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSON_CAST = void 0;
4
+ exports.toMySqlJsonPath = toMySqlJsonPath;
5
+ exports.toMySqlCastType = toMySqlCastType;
6
+ exports.isBooleanType = isBooleanType;
7
+ exports.toJsonSql = toJsonSql;
8
+ exports.jsonCastsForDialect = jsonCastsForDialect;
9
+ const knexUtils_1 = require("./knexUtils");
3
10
  // SQL types of `ReferenceBuilder` casts that MySQL's `CAST()` calls differently.
4
11
  // `CAST(x AS integer)` for example is a syntax error on MySQL.
5
12
  const MYSQL_CAST_TYPES = {
6
- text: 'CHAR',
7
- varchar: 'CHAR',
8
- integer: 'SIGNED',
9
- int: 'SIGNED',
10
- smallint: 'SIGNED',
11
- bigint: 'SIGNED',
12
- float: 'FLOAT',
13
- real: 'DOUBLE',
14
- double: 'DOUBLE',
15
- 'double precision': 'DOUBLE',
16
- decimal: 'DECIMAL(65,30)',
17
- numeric: 'DECIMAL(65,30)',
18
- json: 'JSON',
19
- jsonb: 'JSON',
13
+ text: 'CHAR',
14
+ varchar: 'CHAR',
15
+ integer: 'SIGNED',
16
+ int: 'SIGNED',
17
+ smallint: 'SIGNED',
18
+ bigint: 'SIGNED',
19
+ float: 'FLOAT',
20
+ real: 'DOUBLE',
21
+ double: 'DOUBLE',
22
+ 'double precision': 'DOUBLE',
23
+ decimal: 'DECIMAL(65,30)',
24
+ numeric: 'DECIMAL(65,30)',
25
+ json: 'JSON',
26
+ jsonb: 'JSON',
20
27
  };
21
-
22
28
  /**
23
29
  * Converts the `access` part of a parsed field expression into a MySQL JSON
24
30
  * path like `$."a"[1]."b.c"`. Keys are always quoted, so they can contain any
25
31
  * characters. The path must be passed to MySQL as a binding.
26
32
  */
27
33
  function toMySqlJsonPath(access) {
28
- return (
29
- '$' +
30
- access
31
- .map((it) => {
32
- if (it.type === 'array' && Number.isInteger(it.ref)) {
33
- return `[${it.ref}]`;
34
- } else {
35
- return `.${JSON.stringify(String(it.ref))}`;
36
- }
37
- })
38
- .join('')
39
- );
34
+ return ('$' +
35
+ access
36
+ .map((it) => {
37
+ if (it.type === 'array' && Number.isInteger(it.ref)) {
38
+ return `[${it.ref}]`;
39
+ }
40
+ else {
41
+ return `.${JSON.stringify(String(it.ref))}`;
42
+ }
43
+ })
44
+ .join(''));
40
45
  }
41
-
42
46
  function toMySqlCastType(sqlType) {
43
- return MYSQL_CAST_TYPES[sqlType.toLowerCase()] || sqlType;
47
+ return MYSQL_CAST_TYPES[sqlType.toLowerCase()] || sqlType;
44
48
  }
45
-
46
49
  function isBooleanType(sqlType) {
47
- const type = sqlType.toLowerCase();
48
- return type === 'boolean' || type === 'bool';
50
+ const type = sqlType.toLowerCase();
51
+ return type === 'boolean' || type === 'bool';
52
+ }
53
+ // The SQL that makes `sql` a JSON value. MariaDB has no JSON type to cast to:
54
+ // its JSON columns are text. `JSON_COMPACT()` returns the value as JSON, which
55
+ // `JSON_SET()` nests instead of storing a string, and in the compact form
56
+ // objection stores JSON in, so comparisons with columns work.
57
+ function toJsonSql(sql, knex) {
58
+ return (0, knexUtils_1.isMariaDb)(knex) ? `JSON_COMPACT(${sql})` : `CAST(${sql} AS JSON)`;
59
+ }
60
+ const JSON_CAST = 'CAST(? AS JSON)';
61
+ exports.JSON_CAST = JSON_CAST;
62
+ // For SQL that objection generates before the knex instance is known, like the
63
+ // conditions of the `whereJson*` methods: replaces `CAST(? AS JSON)` with
64
+ // `JSON_COMPACT(?)` on MariaDB. The values are always bindings, so the text
65
+ // only contains what objection generated.
66
+ function jsonCastsForDialect(sql, knex) {
67
+ return (0, knexUtils_1.isMariaDb)(knex) && sql.includes(JSON_CAST)
68
+ ? sql.split(JSON_CAST).join('JSON_COMPACT(?)')
69
+ : sql;
49
70
  }
50
-
51
- module.exports = {
52
- toMySqlJsonPath,
53
- toMySqlCastType,
54
- isBooleanType,
55
- };
@@ -1,144 +1,127 @@
1
- 'use strict';
2
-
3
- const { isObject } = require('../utils/objectUtils');
4
-
5
- // ids is of type RelationProperty.
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeIds = normalizeIds;
4
+ const objectUtils_1 = require("../utils/objectUtils");
6
5
  function normalizeIds(ids, prop, opt) {
7
- opt = opt || {};
8
-
9
- let isComposite = prop.size > 1;
10
- let ret;
11
-
12
- if (isComposite) {
13
- // For composite ids these are okay:
14
- //
15
- // 1. [1, 'foo', 4]
16
- // 2. {a: 1, b: 'foo', c: 4}
17
- // 3. [[1, 'foo', 4], [4, 'bar', 1]]
18
- // 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]
19
- //
20
- if (Array.isArray(ids)) {
21
- if (Array.isArray(ids[0])) {
22
- ret = new Array(ids.length);
23
-
24
- // 3.
25
- for (let i = 0, l = ids.length; i < l; ++i) {
26
- ret[i] = convertIdArrayToObject(ids[i], prop);
6
+ opt = opt || {};
7
+ const isComposite = prop.size > 1;
8
+ let ret;
9
+ if (isComposite) {
10
+ // For composite ids these are okay:
11
+ //
12
+ // 1. [1, 'foo', 4]
13
+ // 2. {a: 1, b: 'foo', c: 4}
14
+ // 3. [[1, 'foo', 4], [4, 'bar', 1]]
15
+ // 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]
16
+ //
17
+ if (Array.isArray(ids)) {
18
+ if (Array.isArray(ids[0])) {
19
+ ret = new Array(ids.length);
20
+ // 3.
21
+ for (let i = 0, l = ids.length; i < l; ++i) {
22
+ ret[i] = convertIdArrayToObject(ids[i], prop);
23
+ }
24
+ }
25
+ else if ((0, objectUtils_1.isObject)(ids[0])) {
26
+ ret = new Array(ids.length);
27
+ // 4.
28
+ for (let i = 0, l = ids.length; i < l; ++i) {
29
+ ret[i] = ensureObject(ids[i]);
30
+ }
31
+ }
32
+ else {
33
+ // 1.
34
+ ret = [convertIdArrayToObject(ids, prop)];
35
+ }
27
36
  }
28
- } else if (isObject(ids[0])) {
29
- ret = new Array(ids.length);
30
-
31
- // 4.
32
- for (let i = 0, l = ids.length; i < l; ++i) {
33
- ret[i] = ensureObject(ids[i], prop);
37
+ else if ((0, objectUtils_1.isObject)(ids)) {
38
+ // 2.
39
+ ret = [ids];
40
+ }
41
+ else {
42
+ throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
34
43
  }
35
- } else {
36
- // 1.
37
- ret = [convertIdArrayToObject(ids, prop)];
38
- }
39
- } else if (isObject(ids)) {
40
- // 2.
41
- ret = [ids];
42
- } else {
43
- throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
44
44
  }
45
- } else {
46
- // For non-composite ids, these are okay:
47
- //
48
- // 1. 1
49
- // 2. {id: 1}
50
- // 3. [1, 'foo', 4]
51
- // 4. [{id: 1}, {id: 'foo'}, {id: 4}]
52
- //
53
- if (Array.isArray(ids)) {
54
- if (isObject(ids[0])) {
55
- ret = new Array(ids.length);
56
-
57
- // 4.
58
- for (let i = 0, l = ids.length; i < l; ++i) {
59
- ret[i] = ensureObject(ids[i]);
45
+ else {
46
+ // For non-composite ids, these are okay:
47
+ //
48
+ // 1. 1
49
+ // 2. {id: 1}
50
+ // 3. [1, 'foo', 4]
51
+ // 4. [{id: 1}, {id: 'foo'}, {id: 4}]
52
+ //
53
+ if (Array.isArray(ids)) {
54
+ if ((0, objectUtils_1.isObject)(ids[0])) {
55
+ ret = new Array(ids.length);
56
+ // 4.
57
+ for (let i = 0, l = ids.length; i < l; ++i) {
58
+ ret[i] = ensureObject(ids[i]);
59
+ }
60
+ }
61
+ else {
62
+ ret = new Array(ids.length);
63
+ // 3.
64
+ for (let i = 0, l = ids.length; i < l; ++i) {
65
+ ret[i] = {};
66
+ prop.setProp(ret[i], 0, ids[i]);
67
+ }
68
+ }
69
+ }
70
+ else if ((0, objectUtils_1.isObject)(ids)) {
71
+ // 2.
72
+ ret = [ids];
60
73
  }
61
- } else {
62
- ret = new Array(ids.length);
63
-
64
- // 3.
65
- for (let i = 0, l = ids.length; i < l; ++i) {
66
- ret[i] = {};
67
- prop.setProp(ret[i], 0, ids[i]);
74
+ else {
75
+ // 1.
76
+ const obj = {};
77
+ prop.setProp(obj, 0, ids);
78
+ ret = [obj];
68
79
  }
69
- }
70
- } else if (isObject(ids)) {
71
- // 2.
72
- ret = [ids];
73
- } else {
74
- // 1.
75
- const obj = {};
76
- prop.setProp(obj, 0, ids);
77
- ret = [obj];
78
80
  }
79
- }
80
-
81
- checkProperties(ret, prop);
82
-
83
- if (opt.arrayOutput) {
84
- return normalizedToArray(ret, prop);
85
- } else {
86
- return ret;
87
- }
81
+ checkProperties(ret, prop);
82
+ if (opt.arrayOutput) {
83
+ return normalizedToArray(ret, prop);
84
+ }
85
+ else {
86
+ return ret;
87
+ }
88
88
  }
89
-
90
89
  function convertIdArrayToObject(ids, prop) {
91
- if (!Array.isArray(ids)) {
92
- throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
93
- }
94
-
95
- if (ids.length != prop.size) {
96
- throw new Error(`composite identifier ${JSON.stringify(ids)} should have ${prop.size} values`);
97
- }
98
-
99
- const obj = {};
100
-
101
- for (let i = 0; i < ids.length; ++i) {
102
- prop.setProp(obj, i, ids[i]);
103
- }
104
-
105
- return obj;
90
+ if (!Array.isArray(ids)) {
91
+ throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
92
+ }
93
+ if (ids.length != prop.size) {
94
+ throw new Error(`composite identifier ${JSON.stringify(ids)} should have ${prop.size} values`);
95
+ }
96
+ const obj = {};
97
+ for (let i = 0; i < ids.length; ++i) {
98
+ prop.setProp(obj, i, ids[i]);
99
+ }
100
+ return obj;
106
101
  }
107
-
108
102
  function ensureObject(ids) {
109
- if (isObject(ids)) {
110
- return ids;
111
- } else {
112
- throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
113
- }
103
+ if ((0, objectUtils_1.isObject)(ids)) {
104
+ return ids;
105
+ }
106
+ else {
107
+ throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
108
+ }
114
109
  }
115
-
116
110
  function checkProperties(ret, prop) {
117
- for (let i = 0, l = ret.length; i < l; ++i) {
118
- const obj = ret[i];
119
-
120
- for (let j = 0, lp = prop.size; j < lp; ++j) {
121
- const val = prop.getProp(obj, j);
122
-
123
- if (typeof val === 'undefined') {
124
- throw new Error(
125
- `expected id ${JSON.stringify(obj)} to have property ${prop.propDescription(j)}`,
126
- );
127
- }
111
+ for (let i = 0, l = ret.length; i < l; ++i) {
112
+ const obj = ret[i];
113
+ for (let j = 0, lp = prop.size; j < lp; ++j) {
114
+ const val = prop.getProp(obj, j);
115
+ if (typeof val === 'undefined') {
116
+ throw new Error(`expected id ${JSON.stringify(obj)} to have property ${prop.propDescription(j)}`);
117
+ }
118
+ }
128
119
  }
129
- }
130
120
  }
131
-
132
121
  function normalizedToArray(ret, prop) {
133
- const arr = new Array(ret.length);
134
-
135
- for (let i = 0, l = ret.length; i < l; ++i) {
136
- arr[i] = prop.getProps(ret[i]);
137
- }
138
-
139
- return arr;
122
+ const arr = new Array(ret.length);
123
+ for (let i = 0, l = ret.length; i < l; ++i) {
124
+ arr[i] = prop.getProps(ret[i]);
125
+ }
126
+ return arr;
140
127
  }
141
-
142
- module.exports = {
143
- normalizeIds,
144
- };