@ballistix.digital/odata-query-builder 0.9.0 → 0.10.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.
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * failure.
8
8
  */
9
9
  import type { Chain, ExpandKey, ExpandNamespace, QueryParams } from './module/query/domain/chain/chain.model';
10
- import type { ExpandChain } from './module/query/domain/chain/expandChain.model';
10
+ import type { ExpandChain, ToOneExpandChain } from './module/query/domain/chain/expandChain.model';
11
11
  import type { ItemChain } from './module/query/domain/chain/itemChain.model';
12
12
  import { QueryBuilderExceptionCode } from './module/query/domain/exceptionCode.model';
13
13
  import type { ExceptionDetail } from './module/query/domain/exceptionDetail.model';
@@ -27,4 +27,4 @@ import { ReservedNameError } from './module/query/exception/reservedName.excepti
27
27
  import { and, maxdatetime, mindatetime, not, now, or, raw } from './module/query/service/filter/filter.facade';
28
28
  import { odataItem, odataQuery } from './module/query/service/queryChain.service';
29
29
  export { InvalidFilterError, QueryBuilderException, QueryBuilderExceptionCode, ReservedNameError, and, maxdatetime, mindatetime, not, now, odataItem, odataQuery, or, raw, };
30
- export type { BooleanExpr, CastResult, Castable, Chain, Comparable, DateExpr, DateInput, EdmTarget, EmbeddedObjectKeys, EmbeddedOf, ExceptionDetail, ExpandChain, ExpandKey, ExpandNamespace, ExprFor, ItemChain, LambdaNamespace, Node, NumberExpr, Operators, OwnKeys, Predicate, PrimitiveArrayKeys, PrimitiveLambdaNamespace, QueryParams, Relation, Scalar, ScalarFieldKeys, Scope, StringExpr, ToManyKeys, ToOneKeys, Unwrap, };
30
+ export type { BooleanExpr, CastResult, Castable, Chain, Comparable, DateExpr, DateInput, EdmTarget, EmbeddedObjectKeys, EmbeddedOf, ExceptionDetail, ExpandChain, ExpandKey, ExpandNamespace, ExprFor, ItemChain, LambdaNamespace, Node, NumberExpr, Operators, OwnKeys, Predicate, PrimitiveArrayKeys, PrimitiveLambdaNamespace, QueryParams, Relation, Scalar, ScalarFieldKeys, Scope, StringExpr, ToManyKeys, ToOneExpandChain, ToOneKeys, Unwrap, };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAUH,mFAAsF;AAoDrF,0GApDQ,+CAAyB,OAoDR;AApB1B,8FAAsF;AAkBrF,mGAlBQ,4CAAkB,OAkBR;AAjBnB,4FAAwF;AAkBvF,sGAlBQ,8CAAqB,OAkBR;AAjBtB,4FAAoF;AAmBnF,kGAnBQ,0CAAiB,OAmBR;AAlBlB,+EAQqD;AAWpD,oFAlBA,mBAAG,OAkBA;AACH,4FAlBA,2BAAW,OAkBA;AACX,4FAlBA,2BAAW,OAkBA;AACX,oFAlBA,mBAAG,OAkBA;AACH,oFAlBA,mBAAG,OAkBA;AAGH,mFApBA,kBAAE,OAoBA;AACF,oFApBA,mBAAG,OAoBA;AAlBJ,kFAGmD;AAYlD,0FAdA,8BAAS,OAcA;AACT,2FAdA,+BAAU,OAcA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAaH,mFAAsF;AAoDrF,0GApDQ,+CAAyB,OAoDR;AApB1B,8FAAsF;AAkBrF,mGAlBQ,4CAAkB,OAkBR;AAjBnB,4FAAwF;AAkBvF,sGAlBQ,8CAAqB,OAkBR;AAjBtB,4FAAoF;AAmBnF,kGAnBQ,0CAAiB,OAmBR;AAlBlB,+EAQqD;AAWpD,oFAlBA,mBAAG,OAkBA;AACH,4FAlBA,2BAAW,OAkBA;AACX,4FAlBA,2BAAW,OAkBA;AACX,oFAlBA,mBAAG,OAkBA;AACH,oFAlBA,mBAAG,OAkBA;AAGH,mFApBA,kBAAE,OAoBA;AACF,oFApBA,mBAAG,OAoBA;AAlBJ,kFAGmD;AAYlD,0FAdA,8BAAS,OAcA;AACT,2FAdA,+BAAU,OAcA"}
@@ -4,17 +4,18 @@
4
4
  * The builder produces a query STRING. It does not fetch, and it does not know
5
5
  * about the `_embedded` / `_page` response envelope.
6
6
  *
7
- * `ExpandNamespace` is the type of the `expand` member of all three chain
8
- * types. It holds one function per relation of the DTO, typed from
7
+ * `ExpandNamespace` is the type of the `expand` member of every chain
8
+ * type. It holds one function per relation of the DTO, typed from
9
9
  * `_embedded`: `q.expand.` lists exactly the relations `_embedded` declares,
10
- * and each callback is typed to the entity that relation reaches. There is no
11
- * build step and no `$metadata` document.
10
+ * and each callback is typed to the entity that relation reaches. A to-many
11
+ * relation's callback receives an `ExpandChain`, a to-one relation's a
12
+ * `ToOneExpandChain`. There is no build step and no `$metadata` document.
12
13
  */
13
14
  import type { Predicate } from '../filter/node.model';
14
15
  import type { Operators } from '../filter/operators.model';
15
16
  import type { ColumnExpr, Relation, ScalarFieldKeys, Scope, SelectScope, ToManyKeys, ToOneKeys } from '../filter/scope.model';
16
17
  import type { StringExpr } from '../filter/stringExpr.model';
17
- import type { ExpandChain } from './expandChain.model';
18
+ import type { ExpandChain, ToOneExpandChain } from './expandChain.model';
18
19
  /** A flat `{ $option: value }` map, for a caller that serialises its own URL. */
19
20
  export type QueryParams = Record<string, string>;
20
21
  /** Every expandable relation name of a DTO. A real allowlist. */
@@ -24,7 +25,7 @@ export type ExpandKey<T> = ToOneKeys<T> | ToManyKeys<T>;
24
25
  * chains at whatever level it is written.
25
26
  */
26
27
  export type ExpandNamespace<T, Self> = {
27
- readonly [K in ExpandKey<T>]: (build?: (chain: ExpandChain<Relation<T, K>>) => unknown) => Self;
28
+ readonly [K in ExpandKey<T>]: (build?: (chain: K extends ToManyKeys<T> ? ExpandChain<Relation<T, K>> : ToOneExpandChain<Relation<T, K>>) => unknown) => Self;
28
29
  };
29
30
  export interface Chain<T> {
30
31
  readonly expand: ExpandNamespace<T, Chain<T>>;
@@ -1,6 +1,9 @@
1
1
  /**
2
- * What a nested `$expand` may carry: `$filter`, `$select`, a further
3
- * `$expand`, `$top` and `$skip`, and nothing else.
2
+ * What a nested `$expand` may carry. `ExpandChain` is the chain of a to-many
3
+ * relation: `$filter`, `$select`, a further `$expand`, `$top` and `$skip`, and
4
+ * nothing else. `ToOneExpandChain` is the chain of a to-one relation: the same
5
+ * without `$top` and `$skip`, because the server pages a collection only and
6
+ * answers `$expand=owner($top=5)` with a 400.
4
7
  *
5
8
  * `$orderby`, `$count` and `$levels` inside `$expand` are an
6
9
  * `UnsupportedFeatureError` from the server, so they are absent from this
@@ -28,14 +31,20 @@ export interface ExpandChain<T> {
28
31
  * written relative to it, not to the root. Repeated calls AND together.
29
32
  */
30
33
  filter(build: (scope: Scope<T>, operators: Operators) => Predicate): ExpandChain<T>;
31
- /**
32
- * `$expand=rel($top=…)`. The server applies it per parent row, on a to-many
33
- * relation only.
34
- */
34
+ /** `$expand=rel($top=…)`. The server applies it per parent row. */
35
35
  top(count: number): ExpandChain<T>;
36
+ /** `$expand=rel($skip=…)`. The server applies it per parent row. */
37
+ skip(count: number): ExpandChain<T>;
38
+ }
39
+ export interface ToOneExpandChain<T> {
40
+ readonly expand: ExpandNamespace<T, ToOneExpandChain<T>>;
41
+ /** Own columns, by name. */
42
+ select(...keys: ScalarFieldKeys<T>[]): ToOneExpandChain<T>;
43
+ /** Own columns and embedded leaves: `select((v) => [v.id, v.address.city])`. */
44
+ select(columns: (scope: SelectScope<T>) => ColumnExpr | readonly ColumnExpr[]): ToOneExpandChain<T>;
36
45
  /**
37
- * `$expand=rel($skip=…)`. The server applies it per parent row, on a to-many
38
- * relation only.
46
+ * `$expand=rel($filter=…)`. The scope is the EXPANDED entity, so paths are
47
+ * written relative to it, not to the root. Repeated calls AND together.
39
48
  */
40
- skip(count: number): ExpandChain<T>;
49
+ filter(build: (scope: Scope<T>, operators: Operators) => Predicate): ToOneExpandChain<T>;
41
50
  }
@@ -11,12 +11,13 @@
11
11
  * query therefore does not change this class, and a change to this class does
12
12
  * not change how the query is printed.
13
13
  *
14
- * `Chain<T>`, `ItemChain<T>` and `ExpandChain<T>` are three interfaces over
15
- * this one class. Only the type that a factory returns differs. `Chain<T>`
16
- * has every member. `ItemChain<T>` has `select`, `expand`, `toQueryString()`
17
- * and `toParams()`. `ExpandChain<T>` has `select`, `expand`, `filter`, `top`
18
- * and `skip`, the options that the server accepts inside `$expand`. At
19
- * runtime, every instance has every member.
14
+ * `Chain<T>`, `ItemChain<T>`, `ExpandChain<T>` and `ToOneExpandChain<T>` are
15
+ * four interfaces over this one class. Only the type that a factory returns
16
+ * differs. `Chain<T>` has every member. `ItemChain<T>` has `select`, `expand`,
17
+ * `toQueryString()` and `toParams()`. `ExpandChain<T>` has `select`, `expand`,
18
+ * `filter`, `top` and `skip`, the options that the server accepts inside the
19
+ * `$expand` of a to-many relation. `ToOneExpandChain<T>` has the same without
20
+ * `top` and `skip`. At runtime, every instance has every member.
20
21
  */
21
22
  import type { Chain, QueryParams } from '../domain/chain/chain.model';
22
23
  import type { ItemChain } from '../domain/chain/itemChain.model';
@@ -1 +1 @@
1
- {"version":3,"file":"queryChain.service.js","sourceRoot":"","sources":["../../../../src/module/query/service/queryChain.service.ts"],"names":[],"mappings":";;;AAyBA,kFAA0E;AAC1E,gFAAwE;AACxE,oDAAsE;AACtE,0DAKgC;AAEhC,MAAa,iBAAiB;IACpB,UAAU,GAAe;QACjC,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;KACX,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAA4B,EAAE;YAChE,GAAG,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBAC1B,IAAI,OAAO,QAAQ,KAAK,QAAQ;oBAAE,OAAO,SAAS,CAAC;gBACnD,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,QAAQ;oBAC/C,MAAM,IA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D,2DAA2D;AACpD,MAAM,SAAS,GAAG,GAAoB,EAAE,CAC9C,IAAI,iBAAiB,EAA6B,CAAC;AADvC,QAAA,SAAS,aAC8B"}
1
+ {"version":3,"file":"queryChain.service.js","sourceRoot":"","sources":["../../../../src/module/query/service/queryChain.service.ts"],"names":[],"mappings":";;;AA0BA,kFAA0E;AAC1E,gFAAwE;AACxE,oDAAsE;AACtE,0DAKgC;AAEhC,MAAa,iBAAiB;IACpB,UAAU,GAAe;QACjC,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,EAAE;KACX,CAAC;IAEF;;;;;;;;;;;OAWG;IACH,IAAI,MAAM;QACT,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAA4B,EAAE;YAChE,GAAG,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBAC1B,IAAI,OAAO,QAAQ,KAAK,QAAQ;oBAAE,OAAO,SAAS,CAAC;gBACnD,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,KAAK,QAAQ;oBAC/C,MAAM,IAAI,0CAAiB,CAAC,QAAQ,CAAC,CAAC;gBACvC,IAAI,QAAQ,KAAK,aAAa;oBAAE,OAAO,SAAS,CAAC;gBACjD,OAAO,CAAC,KAA6C,EAAE,EAAE;oBACxD,MAAM,KAAK,GAAG,IAAI,iBAAiB,EAAE,CAAC;oBACtC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;oBACf,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC;wBAC3B,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE,KAAK,CAAC,UAAU;qBAC5B,CAAC,CAAC;oBACH,OAAO,IAAI,CAAC;gBACb,CAAC,CAAC;YACH,CAAC;YACD,GAAG,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,QAAQ,KAAK,QAAQ;SACxD,CAAC,CA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KAAK,CAAC,EAAE,GAAG,IAAI;QACd,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC;QAC3B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,aAAa;QACZ,OAAO,IAAA,6BAAe,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;IAED,QAAQ;QACP,OAAO,IAAA,6BAAe,EAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC;CACD;AA/FD,8CA+FC;AAED,yFAAyF;AACzF,MAAM,aAAa,GAAG,CAAC,IAAoB,EAAE,KAAa,EAAU,EAAE;IACrE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAC5C,MAAM,IAAI,4CAAkB,CAC3B,GAAG,KAAK,mBAAmB,IAAI,gDAAgD,EAC/E,IAAI,CACJ,CAAC;IACH,OAAO,KAAK,CAAC;AACd,CAAC,CAAC;AAEF,wDAAwD;AACjD,MAAM,UAAU,GAAG,GAAgB,EAAE,CAC3C,IAAI,iBAAiB,EAAyB,CAAC;AADnC,QAAA,UAAU,cACyB;AAEhD,2DAA2D;AACpD,MAAM,SAAS,GAAG,GAAoB,EAAE,CAC9C,IAAI,iBAAiB,EAA6B,CAAC;AADvC,QAAA,SAAS,aAC8B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ballistix.digital/odata-query-builder",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Typed, fluent OData v4 query-string builder for the dialect @ballistix.digital/typeorm-extensions serves.",
5
5
  "license": "MIT",
6
6
  "repository": {