remult 0.27.20-next.2 → 0.27.20-next.4
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/esm/src/data-providers/rest-data-provider.js +7 -2
- package/esm/src/remult3/QueryResultImpl.js +3 -5
- package/package.json +1 -1
- package/src/data-providers/rest-data-provider.js +10 -1
- package/src/remult3/QueryResultImpl.d.ts +1 -1
- package/src/remult3/QueryResultImpl.js +3 -5
- package/src/remult3/RepositoryImplementation.d.ts +4 -2
- package/src/remult3/remult3.d.ts +16 -11
|
@@ -105,9 +105,14 @@ export class RestEntityDataProvider {
|
|
|
105
105
|
}
|
|
106
106
|
query(options, aggregateOptions) {
|
|
107
107
|
const r = this.buildFindRequest(options);
|
|
108
|
-
return r
|
|
108
|
+
return r
|
|
109
|
+
.run('query', {
|
|
109
110
|
aggregate: this.buildAggregateOptions(aggregateOptions),
|
|
110
|
-
})
|
|
111
|
+
})
|
|
112
|
+
.then(({ items, aggregates }) => ({
|
|
113
|
+
items: items.map((x) => this.translateFromJson(x)),
|
|
114
|
+
aggregates,
|
|
115
|
+
}));
|
|
111
116
|
}
|
|
112
117
|
async groupBy(options) {
|
|
113
118
|
const { run } = this.buildFindRequest({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { queryConfig } from '../context.js';
|
|
2
|
+
import { isOfType } from '../isOfType.js';
|
|
2
3
|
import { Sort } from '../sort.js';
|
|
3
4
|
import { RelationLoader } from './relation-loader.js';
|
|
4
5
|
export class QueryResultImpl {
|
|
@@ -52,11 +53,8 @@ export class QueryResultImpl {
|
|
|
52
53
|
include: this.options.include,
|
|
53
54
|
};
|
|
54
55
|
let getItems = () => this.repo.find(options);
|
|
55
|
-
if (this._aggregates === undefined
|
|
56
|
-
|
|
57
|
-
this.options,
|
|
58
|
-
'aggregate',
|
|
59
|
-
))*/) {
|
|
56
|
+
if (this._aggregates === undefined &&
|
|
57
|
+
isOfType(this.options, 'aggregate')) {
|
|
60
58
|
let agg = this.options.aggregate;
|
|
61
59
|
if (!this.repo._dataProvider.isProxy) {
|
|
62
60
|
let itemsPromise = getItems();
|
package/package.json
CHANGED
|
@@ -121,9 +121,18 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
121
121
|
this.entity = entity;
|
|
122
122
|
}
|
|
123
123
|
RestEntityDataProvider.prototype.query = function (options, aggregateOptions) {
|
|
124
|
+
var _this = this;
|
|
124
125
|
var r = this.buildFindRequest(options);
|
|
125
|
-
return r
|
|
126
|
+
return r
|
|
127
|
+
.run('query', {
|
|
126
128
|
aggregate: this.buildAggregateOptions(aggregateOptions),
|
|
129
|
+
})
|
|
130
|
+
.then(function (_a) {
|
|
131
|
+
var items = _a.items, aggregates = _a.aggregates;
|
|
132
|
+
return ({
|
|
133
|
+
items: items.map(function (x) { return _this.translateFromJson(x); }),
|
|
134
|
+
aggregates: aggregates,
|
|
135
|
+
});
|
|
127
136
|
});
|
|
128
137
|
};
|
|
129
138
|
RestEntityDataProvider.prototype.groupBy = function (options) {
|
|
@@ -3,7 +3,7 @@ import type { RepositoryImplementation } from './RepositoryImplementation.js';
|
|
|
3
3
|
export declare class QueryResultImpl<entityType> implements QueryResult<entityType> {
|
|
4
4
|
private options;
|
|
5
5
|
private repo;
|
|
6
|
-
constructor(options: QueryOptions<entityType
|
|
6
|
+
constructor(options: QueryOptions<entityType>, repo: RepositoryImplementation<entityType>);
|
|
7
7
|
private _count;
|
|
8
8
|
private _aggregates;
|
|
9
9
|
getPage(page?: number): Promise<entityType[]>;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QueryResultImpl = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var context_js_1 = require("../context.js");
|
|
6
|
+
var isOfType_js_1 = require("../isOfType.js");
|
|
6
7
|
var sort_js_1 = require("../sort.js");
|
|
7
8
|
var relation_loader_js_1 = require("./relation-loader.js");
|
|
8
9
|
var QueryResultImpl = /** @class */ (function () {
|
|
@@ -116,11 +117,8 @@ var QueryResultImpl = /** @class */ (function () {
|
|
|
116
117
|
include: this.options.include,
|
|
117
118
|
};
|
|
118
119
|
getItems = function () { return _this.repo.find(options); };
|
|
119
|
-
if (this._aggregates === undefined
|
|
120
|
-
|
|
121
|
-
this.options,
|
|
122
|
-
'aggregate',
|
|
123
|
-
))*/) {
|
|
120
|
+
if (this._aggregates === undefined &&
|
|
121
|
+
(0, isOfType_js_1.isOfType)(this.options, 'aggregate')) {
|
|
124
122
|
agg_1 = this.options.aggregate;
|
|
125
123
|
if (!this.repo._dataProvider.isProxy) {
|
|
126
124
|
itemsPromise_1 = getItems();
|
|
@@ -5,7 +5,7 @@ import { Remult } from '../context.js';
|
|
|
5
5
|
import type { EntityOptions } from '../entity.js';
|
|
6
6
|
import { Filter } from '../filter/filter-interfaces.js';
|
|
7
7
|
import { type GroupByOptions, type GroupByResult, type ControllerRef, type ControllerRefForControllerBase, type EntityFilter, type EntityMetadata, type EntityOrderBy, type EntityRef, type EntityRefForEntityBase, type FieldRef, type FieldsMetadata, type FieldsRef, type FieldsRefForEntityBase, type FindFirstOptions, type FindFirstOptionsBase, type FindOptions, type IdMetadata, type LiveQuery, type LoadOptions, type MembersOnly, type NumericKeys, type Repository, type RepositoryRelations, type Subscribable, type idType } from './remult3.js';
|
|
8
|
-
import type { QueryOptions,
|
|
8
|
+
import type { QueryOptions, RefSubscriber, UpsertOptions } from './remult3.js';
|
|
9
9
|
import type { entityEventListener } from '../__EntityValueProvider.js';
|
|
10
10
|
import type { DataProvider, EntityDataProvider, EntityDataProviderGroupByOptions, EntityDataProviderFindOptions, ErrorInfo } from '../data-interfaces.js';
|
|
11
11
|
import type { Unsubscribe } from '../live-query/SubscriptionChannel.js';
|
|
@@ -42,7 +42,9 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
42
42
|
get metadata(): EntityMetadata<entityType>;
|
|
43
43
|
listeners?: entityEventListener<entityType>[];
|
|
44
44
|
addEventListener(listener: entityEventListener<entityType>): () => void;
|
|
45
|
-
query<
|
|
45
|
+
query<Options extends QueryOptions<entityType> & {
|
|
46
|
+
aggregate?: Omit<GroupByOptions<entityType, never, NumericKeys<entityType>[], NumericKeys<entityType>[], (keyof MembersOnly<entityType>)[], (keyof MembersOnly<entityType>)[], (keyof MembersOnly<entityType>)[]>, 'group' | 'orderBy' | 'where' | 'limit' | 'page'>;
|
|
47
|
+
}>(options?: Options): any;
|
|
46
48
|
getEntityRef(entity: entityType): EntityRef<entityType>;
|
|
47
49
|
delete(id: idType<entityType>): Promise<void>;
|
|
48
50
|
delete(item: Partial<MembersOnly<entityType>>): Promise<void>;
|
package/src/remult3/remult3.d.ts
CHANGED
|
@@ -483,8 +483,8 @@ export interface Repository<entityType> {
|
|
|
483
483
|
* @template maxFields The fields to find the maximum value, provided as an array of keys from the entity type.
|
|
484
484
|
* @template distinctCountFields The fields to count distinct values, provided as an array of keys from the entity type.
|
|
485
485
|
*
|
|
486
|
-
* @param {
|
|
487
|
-
* @returns {
|
|
486
|
+
* @param {QueryOptions<entityType, sumFields, averageFields, minFields, maxFields, distinctCountFields>} options - The options for the query and aggregation.
|
|
487
|
+
* @returns {QueryResult<entityType, sumFields, averageFields, minFields, maxFields, distinctCountFields>} The result of the query, including paginated items and aggregation results.
|
|
488
488
|
*
|
|
489
489
|
* @example
|
|
490
490
|
* // Basic usage with asynchronous iteration:
|
|
@@ -526,7 +526,11 @@ export interface Repository<entityType> {
|
|
|
526
526
|
* console.log('Total salary:', result.aggregates.salary.sum); // Sum of all salaries
|
|
527
527
|
* console.log('Average age:', result.aggregates.age.average); // Average age
|
|
528
528
|
*/
|
|
529
|
-
query<
|
|
529
|
+
query<Options extends QueryOptions<entityType> & {
|
|
530
|
+
aggregate?: Omit<GroupByOptions<entityType, never, NumericKeys<entityType>[], NumericKeys<entityType>[], (keyof MembersOnly<entityType>)[], (keyof MembersOnly<entityType>)[], (keyof MembersOnly<entityType>)[]>, 'group' | 'orderBy' | 'where' | 'limit' | 'page'>;
|
|
531
|
+
}>(options?: Options): Options extends {
|
|
532
|
+
aggregate: Omit<GroupByOptions<entityType, never, NumericKeys<entityType>[], NumericKeys<entityType>[], (keyof MembersOnly<entityType>)[], (keyof MembersOnly<entityType>)[], (keyof MembersOnly<entityType>)[]>, 'group' | 'orderBy' | 'where' | 'limit' | 'page'>;
|
|
533
|
+
} ? QueryResult<entityType, GroupByResult<entityType, never, NonNullable<Options['aggregate']['sum']>, NonNullable<Options['aggregate']['avg']>, NonNullable<Options['aggregate']['min']>, NonNullable<Options['aggregate']['max']>, NonNullable<Options['aggregate']['distinctCount']>>> : QueryResult<entityType>;
|
|
530
534
|
/** Returns a count of the items matching the criteria.
|
|
531
535
|
* @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
|
|
532
536
|
* @example
|
|
@@ -1049,18 +1053,18 @@ export interface FindFirstOptionsBase<entityType> extends LoadOptions<entityType
|
|
|
1049
1053
|
/** If set to true and an item is not found, it's created and returned*/
|
|
1050
1054
|
createIfNotFound?: boolean;
|
|
1051
1055
|
}
|
|
1052
|
-
export interface QueryOptions<entityType
|
|
1056
|
+
export interface QueryOptions<entityType> extends FindOptionsBase<entityType> {
|
|
1053
1057
|
/** The number of items to return in each step */
|
|
1054
1058
|
pageSize?: number;
|
|
1055
1059
|
/** A callback method to indicate the progress of the iteration */
|
|
1056
1060
|
progress?: {
|
|
1057
1061
|
progress: (progress: number) => void;
|
|
1058
1062
|
};
|
|
1059
|
-
aggregate?: Omit<GroupByOptions<entityType, never, sumFields, averageFields, minFields, maxFields, distinctCountFields>, 'group' | 'orderBy' | 'where' | 'limit' | 'page'>;
|
|
1060
1063
|
}
|
|
1064
|
+
export type EmptyAggregateResult = 'EmptyAggregateResult';
|
|
1061
1065
|
/** The result of a call to the `query` method in the `Repository` object.
|
|
1062
1066
|
*/
|
|
1063
|
-
export interface QueryResult<entityType,
|
|
1067
|
+
export interface QueryResult<entityType, AggregateResult = EmptyAggregateResult> {
|
|
1064
1068
|
/** returns an iterator that iterates the rows in the result using a paging mechanism
|
|
1065
1069
|
* @example
|
|
1066
1070
|
* for await (const task of taskRepo.query()) {
|
|
@@ -1077,7 +1081,7 @@ export interface QueryResult<entityType, sumFields extends NumericKeys<entityTyp
|
|
|
1077
1081
|
/** Performs an operation on all the items matching the query criteria */
|
|
1078
1082
|
forEach(what: (item: entityType) => Promise<any>): Promise<number>;
|
|
1079
1083
|
/** Returns a `Paginator` object that is used for efficient paging */
|
|
1080
|
-
paginator(): Promise<Paginator<entityType,
|
|
1084
|
+
paginator(): Promise<Paginator<entityType, AggregateResult>>;
|
|
1081
1085
|
}
|
|
1082
1086
|
/** An interface used to paginating using the `query` method in the `Repository` object
|
|
1083
1087
|
* @example
|
|
@@ -1095,7 +1099,7 @@ export interface QueryResult<entityType, sumFields extends NumericKeys<entityTyp
|
|
|
1095
1099
|
* console.log(paginator.items.length)
|
|
1096
1100
|
* }
|
|
1097
1101
|
*/
|
|
1098
|
-
export
|
|
1102
|
+
export type Paginator<entityType, AggregateResult = EmptyAggregateResult> = {
|
|
1099
1103
|
/** the items in the current page */
|
|
1100
1104
|
items: entityType[];
|
|
1101
1105
|
/** True if next page exists */
|
|
@@ -1103,9 +1107,10 @@ export interface Paginator<entityType, sumFields extends NumericKeys<entityType>
|
|
|
1103
1107
|
/** the count of the total items in the `query`'s result */
|
|
1104
1108
|
count(): Promise<number>;
|
|
1105
1109
|
/** Gets the next page in the `query`'s result set */
|
|
1106
|
-
nextPage(): Promise<Paginator<entityType,
|
|
1107
|
-
|
|
1108
|
-
|
|
1110
|
+
nextPage(): Promise<Paginator<entityType, AggregateResult>>;
|
|
1111
|
+
} & (AggregateResult extends EmptyAggregateResult ? {} : {
|
|
1112
|
+
aggregates: AggregateResult;
|
|
1113
|
+
});
|
|
1109
1114
|
/**
|
|
1110
1115
|
* Options for configuring a relation between entities.
|
|
1111
1116
|
*
|