typeorm-extensions 2.2.0-rc.0 → 2.2.0-rc.2

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.
@@ -130,10 +130,11 @@ async function readWithTotals(builder, paginationFilter, options, read) {
130
130
  */
131
131
  async function bothOrFirstError(first, second) {
132
132
  const [a, b] = await Promise.all([settle(first), settle(second)]);
133
- if (!a.fulfilled) {
133
+ // `=== false`: without strictNullChecks `!fulfilled` doesn't narrow the union
134
+ if (a.fulfilled === false) {
134
135
  throw a.reason;
135
136
  }
136
- if (!b.fulfilled) {
137
+ if (b.fulfilled === false) {
137
138
  throw b.reason;
138
139
  }
139
140
  return [a.value, b.value];
@@ -8,6 +8,10 @@ declare class TypedRootMark<Root> {
8
8
  * with an optional symbol method that only types carry. Entities loaded with it are plain entities.
9
9
  */
10
10
  export type WithTypedRoot<Entity, Root extends ObjectLiteral> = Entity & TypedRootMark<Root>;
11
- /** The root of a builder's typed callbacks: the one set with `typed<Root>()`, or else its entity. */
12
- export type TypedRoot<Entity> = Entity extends TypedRootMark<infer Root> ? Root extends ObjectLiteral ? Root : Entity : Entity;
11
+ /**
12
+ * The root of a builder's typed callbacks: the one set with `typed<Root>()`, or else its entity. The key check
13
+ * comes first: without `strictNullChecks` an entity with an index signature (`ObjectLiteral`) matches the
14
+ * optional mark too, and its root would be inferred as `unknown`.
15
+ */
16
+ export type TypedRoot<Entity> = typeof typedRoot extends keyof Entity ? Entity extends TypedRootMark<infer Root> ? Root extends ObjectLiteral ? Root : Entity : Entity : Entity;
13
17
  export {};
@@ -30,12 +30,29 @@ function requireMainAliasName(queryBuilder, key) {
30
30
  }
31
31
  return mainAlias.name;
32
32
  }
33
+ /**
34
+ * An alias of the query by name, or of a query it is part of. The builder of a `Brackets` callback has the
35
+ * outer query's main alias but an empty alias list: the aliases, joins included, are on its parent. A subquery
36
+ * sees the aliases of the outer query too, its own first.
37
+ */
38
+ function findQueryAlias(queryBuilder, aliasName) {
39
+ var _a, _b;
40
+ // parentQueryBuilder is protected in TypeORM's types
41
+ for (let query = queryBuilder; query; query = query.parentQueryBuilder) {
42
+ const { aliases = [], mainAlias } = (_a = query.expressionMap) !== null && _a !== void 0 ? _a : {};
43
+ const alias = (_b = aliases.find((candidate) => candidate.name === aliasName)) !== null && _b !== void 0 ? _b : ((mainAlias === null || mainAlias === void 0 ? void 0 : mainAlias.name) === aliasName ? mainAlias : undefined);
44
+ if (alias) {
45
+ return alias;
46
+ }
47
+ }
48
+ return undefined;
49
+ }
33
50
  /** Entity metadata of a query alias (the main alias when `aliasName` is undefined), if it has any. */
34
51
  function getAliasMetadata(queryBuilder, aliasName) {
35
- const expressionMap = queryBuilder.expressionMap;
52
+ var _a;
36
53
  const alias = aliasName === undefined
37
- ? expressionMap === null || expressionMap === void 0 ? void 0 : expressionMap.mainAlias
38
- : expressionMap === null || expressionMap === void 0 ? void 0 : expressionMap.aliases.find((queryAlias) => queryAlias.name === aliasName);
54
+ ? (_a = queryBuilder.expressionMap) === null || _a === void 0 ? void 0 : _a.mainAlias
55
+ : findQueryAlias(queryBuilder, aliasName);
39
56
  return (alias === null || alias === void 0 ? void 0 : alias.hasMetadata) ? alias.metadata : undefined;
40
57
  }
41
58
  /**
@@ -85,14 +102,11 @@ exports.findFieldColumn = findFieldColumn;
85
102
  * `stringToSQLIdentifier` does, in the driver's quotes.
86
103
  */
87
104
  function toFieldSql(builder, field) {
88
- var _a;
89
105
  const queryBuilder = builder;
90
106
  const dot = field.indexOf('.');
91
107
  if (dot > 0) {
92
108
  const aliasName = field.slice(0, dot);
93
- const metadata = ((_a = queryBuilder.expressionMap) === null || _a === void 0 ? void 0 : _a.aliases.some((alias) => alias.name === aliasName))
94
- ? getAliasMetadata(queryBuilder, aliasName)
95
- : undefined;
109
+ const metadata = getAliasMetadata(queryBuilder, aliasName);
96
110
  const column = metadata && findColumn(metadata, field.slice(dot + 1));
97
111
  if (column) {
98
112
  const columnSql = queryBuilder.escape(column.databaseName);
@@ -182,7 +196,7 @@ function resolveTypedKeyPath(queryBuilder, keys) {
182
196
  ...findColumnPath(metadata, restKeys),
183
197
  };
184
198
  }
185
- const queryAlias = expressionMap === null || expressionMap === void 0 ? void 0 : expressionMap.aliases.find((alias) => alias.name === firstKey);
199
+ const queryAlias = findQueryAlias(queryBuilder, firstKey);
186
200
  if (!queryAlias && mainAlias) {
187
201
  const mainMetadata = getAliasMetadata(queryBuilder, undefined);
188
202
  const columnPath = findColumnPath(mainMetadata, keys);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeorm-extensions",
3
- "version": "2.2.0-rc.0",
3
+ "version": "2.2.0-rc.2",
4
4
  "description": "typeorm commonly used extensions",
5
5
  "main": "./dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "scripts": {
15
15
  "build": "tsc -p .",
16
16
  "lint": "eslint . --ext .ts",
17
- "test:types": "tsc -p test/types"
17
+ "test:types": "tsc -p test/types && tsc -p test/types/tsconfig.loose.json"
18
18
  },
19
19
  "keywords": [
20
20
  "typeorm",