remult 0.22.9-exp.0 → 0.22.9
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/index.d.ts +3 -4
- package/esm/index.js +1 -3
- package/esm/internals.d.ts +2 -1
- package/esm/internals.js +1 -1
- package/esm/live-query/data-provider-live-query-storage.js +1 -2
- package/esm/server/expressBridge.d.ts +1 -1
- package/esm/server/expressBridge.js +1 -2
- package/esm/src/column.d.ts +2 -3
- package/esm/src/column.js +5 -6
- package/esm/src/context.js +2 -2
- package/esm/src/data-providers/array-entity-data-provider.d.ts +2 -5
- package/esm/src/data-providers/array-entity-data-provider.js +46 -63
- package/esm/src/data-providers/rest-data-provider.d.ts +1 -1
- package/esm/src/data-providers/rest-data-provider.js +7 -51
- package/esm/src/remult3/Fields.d.ts +27 -21
- package/esm/src/remult3/Fields.js +26 -30
- package/esm/src/remult3/RepositoryImplementation.d.ts +49 -12
- package/esm/src/remult3/RepositoryImplementation.js +195 -202
- package/esm/src/remult3/relation-loader.js +4 -1
- package/esm/src/remult3/remult3.d.ts +1 -30
- package/esm/src/remult3/remult3.js +0 -4
- package/esm/src/remult3/repository-internals.d.ts +14 -0
- package/esm/src/remult3/repository-internals.js +7 -0
- package/esm/src/server-action.js +2 -3
- package/esm/src/sort.d.ts +1 -1
- package/esm/src/sort.js +3 -5
- package/index.d.ts +3 -4
- package/index.js +4 -6
- package/internals.d.ts +2 -1
- package/internals.js +3 -1
- package/live-query/data-provider-live-query-storage.js +4 -5
- package/package.json +14 -6
- package/server/expressBridge.d.ts +1 -1
- package/server/expressBridge.js +10 -11
- package/src/column.d.ts +2 -3
- package/src/column.js +4 -4
- package/src/context.js +1 -1
- package/src/data-providers/array-entity-data-provider.d.ts +2 -5
- package/src/data-providers/array-entity-data-provider.js +134 -192
- package/src/data-providers/rest-data-provider.d.ts +1 -1
- package/src/data-providers/rest-data-provider.js +4 -45
- package/src/remult3/Fields.d.ts +27 -21
- package/src/remult3/Fields.js +32 -32
- package/src/remult3/RepositoryImplementation.d.ts +49 -12
- package/src/remult3/RepositoryImplementation.js +418 -423
- package/src/remult3/relation-loader.js +4 -1
- package/src/remult3/remult3.d.ts +1 -30
- package/src/remult3/remult3.js +0 -4
- package/src/remult3/repository-internals.d.ts +14 -0
- package/src/remult3/repository-internals.js +11 -0
- package/src/server-action.js +2 -3
- package/src/sort.d.ts +1 -1
- package/src/sort.js +3 -5
package/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo,
|
|
2
|
-
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
1
|
+
export { OmitEB, FieldsMetadata, FieldRef, IdFieldRef, FieldsRef, EntityMetadata, EntityOrderBy, EntityFilter, FindOptions, QueryResult, QueryOptions, Repository, FindFirstOptions, ComparisonValueFilter, ValueFilter, IdFilter, ContainsStringValueFilter, EntityRef, SortSegments, Paginator, LiveQuery, LiveQueryChangeInfo, } from './src/remult3/remult3';
|
|
2
|
+
export { Field, Fields, IdEntity, EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListFieldOptions, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
3
3
|
export { Entity } from './src/remult3/entity';
|
|
4
4
|
export { getEntityRef } from './src/remult3/getEntityRef';
|
|
5
|
-
export {
|
|
6
|
-
export { IdEntity } from './src/remult3/IdEntity';
|
|
5
|
+
export { StringFieldOptions } from './src/remult3/RepositoryImplementation';
|
|
7
6
|
export { describeClass } from './src/remult3/DecoratorReplacer';
|
|
8
7
|
export { EntityOptions } from './src/entity';
|
|
9
8
|
export { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo, RestDataProviderHttpProvider, } from './src/data-interfaces';
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export { EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
1
|
+
export { Field, Fields, IdEntity, EntityBase, ControllerBase, FieldType, getFields, ValueListFieldType, getValueList, ValueListInfo, CaptionTransformer, } from './src/remult3/RepositoryImplementation';
|
|
2
2
|
export { Entity } from './src/remult3/entity';
|
|
3
3
|
export { getEntityRef } from './src/remult3/getEntityRef';
|
|
4
|
-
export { Field, Fields } from './src/remult3/Fields';
|
|
5
|
-
export { IdEntity } from './src/remult3/IdEntity';
|
|
6
4
|
export { describeClass } from './src/remult3/DecoratorReplacer';
|
|
7
5
|
export { RestDataProvider } from './src/data-providers/rest-data-provider'; //V
|
|
8
6
|
export { InMemoryDataProvider } from './src/data-providers/in-memory-database'; //V
|
package/esm/internals.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { getRelationInfo } from './src/remult3/relationInfoMember';
|
|
2
|
-
export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
|
|
2
|
+
export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation';
|
|
3
3
|
export { getEntitySettings } from './src/remult3/getEntityRef';
|
|
4
4
|
export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
|
|
5
5
|
export { actionInfo } from './src/server-action-info';
|
|
6
6
|
export { RelationInfo } from './src/remult3/remult3';
|
|
7
|
+
export { ClassType } from './classType';
|
package/esm/internals.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getRelationInfo } from './src/remult3/relationInfoMember';
|
|
2
|
-
export { decorateColumnSettings } from './src/remult3/RepositoryImplementation';
|
|
2
|
+
export { decorateColumnSettings, controllerRefImpl, getControllerRef, } from './src/remult3/RepositoryImplementation';
|
|
3
3
|
export { getEntitySettings } from './src/remult3/getEntityRef';
|
|
4
4
|
export { __updateEntityBasedOnWhere } from './src/filter/filter-interfaces';
|
|
5
5
|
export { actionInfo } from './src/server-action-info';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { initDataProvider } from '../server/initDataProvider';
|
|
3
3
|
import { allEntities, Remult } from '../src/context';
|
|
4
|
-
import { EntityBase } from '../src/remult3/RepositoryImplementation';
|
|
5
|
-
import { Fields } from '../src/remult3/Fields';
|
|
4
|
+
import { EntityBase, Fields } from '../src/remult3/RepositoryImplementation';
|
|
6
5
|
import { Entity } from '../src/remult3/entity';
|
|
7
6
|
export class DataProviderLiveQueryStorage {
|
|
8
7
|
repo;
|
|
@@ -3,7 +3,7 @@ import type { UserInfo } from '../src/context';
|
|
|
3
3
|
import { Remult } from '../src/context';
|
|
4
4
|
import type { DataProvider } from '../src/data-interfaces';
|
|
5
5
|
import type { LiveQueryStorage, SubscriptionServer } from '../src/live-query/SubscriptionServer';
|
|
6
|
-
import { IdEntity } from '../src/remult3/
|
|
6
|
+
import { IdEntity } from '../src/remult3/RepositoryImplementation';
|
|
7
7
|
import type { Repository } from '../src/remult3/remult3';
|
|
8
8
|
import type { queuedJobInfoResponse } from '../src/server-action';
|
|
9
9
|
export interface RemultServerOptions<RequestType> {
|
|
@@ -4,8 +4,7 @@ import { Remult, RemultAsyncLocalStorage, allEntities } from '../src/context';
|
|
|
4
4
|
import { DataApi, serializeError } from '../src/data-api';
|
|
5
5
|
import { liveQueryKeepAliveRoute, streamUrl, } from '../src/live-query/SubscriptionChannel';
|
|
6
6
|
import { InMemoryLiveQueryStorage, LiveQueryPublisher, } from '../src/live-query/SubscriptionServer';
|
|
7
|
-
import { IdEntity } from '../src/remult3/
|
|
8
|
-
import { Fields } from '../src/remult3/Fields';
|
|
7
|
+
import { Fields, IdEntity } from '../src/remult3/RepositoryImplementation';
|
|
9
8
|
import { Entity } from '../src/remult3/entity';
|
|
10
9
|
import { getEntityKey } from '../src/remult3/getEntityRef';
|
|
11
10
|
import { Action, classBackendMethodsArray } from '../src/server-action';
|
package/esm/src/column.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { RepositoryImplementation } from './remult3/RepositoryImplementatio
|
|
|
3
3
|
export declare function makeTitle(name: string): string;
|
|
4
4
|
export declare class LookupColumn<T> {
|
|
5
5
|
private repository;
|
|
6
|
-
|
|
6
|
+
id: idType<T>;
|
|
7
7
|
toJson(): any;
|
|
8
8
|
setId(val: any): void;
|
|
9
9
|
waitLoadOf(id: any): Promise<T>;
|
|
@@ -12,8 +12,7 @@ export declare class LookupColumn<T> {
|
|
|
12
12
|
item: T;
|
|
13
13
|
};
|
|
14
14
|
set(item: T): void;
|
|
15
|
-
id: idType<T
|
|
16
|
-
constructor(repository: RepositoryImplementation<T>, isManyToOneRelation: any);
|
|
15
|
+
constructor(repository: RepositoryImplementation<T>, id: idType<T>);
|
|
17
16
|
get item(): T;
|
|
18
17
|
waitLoad(): Promise<T>;
|
|
19
18
|
}
|
package/esm/src/column.js
CHANGED
|
@@ -12,7 +12,7 @@ export function makeTitle(name) {
|
|
|
12
12
|
}
|
|
13
13
|
export class LookupColumn {
|
|
14
14
|
repository;
|
|
15
|
-
|
|
15
|
+
id;
|
|
16
16
|
toJson() {
|
|
17
17
|
if (!this.storedItem)
|
|
18
18
|
return undefined;
|
|
@@ -28,12 +28,12 @@ export class LookupColumn {
|
|
|
28
28
|
waitLoadOf(id) {
|
|
29
29
|
if (id === undefined || id === null)
|
|
30
30
|
return null;
|
|
31
|
-
return this.repository.getCachedByIdAsync(id
|
|
31
|
+
return this.repository.getCachedByIdAsync(id);
|
|
32
32
|
}
|
|
33
33
|
get(id) {
|
|
34
34
|
if (id === undefined || id === null)
|
|
35
35
|
return null;
|
|
36
|
-
return this.repository.getCachedById(id
|
|
36
|
+
return this.repository.getCachedById(id);
|
|
37
37
|
}
|
|
38
38
|
storedItem;
|
|
39
39
|
set(item) {
|
|
@@ -60,10 +60,9 @@ export class LookupColumn {
|
|
|
60
60
|
this.id = undefined;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
id
|
|
64
|
-
constructor(repository, isManyToOneRelation) {
|
|
63
|
+
constructor(repository, id) {
|
|
65
64
|
this.repository = repository;
|
|
66
|
-
this.
|
|
65
|
+
this.id = id;
|
|
67
66
|
}
|
|
68
67
|
get item() {
|
|
69
68
|
if (this.storedItem)
|
package/esm/src/context.js
CHANGED
|
@@ -2,7 +2,7 @@ import { RestDataProvider } from './data-providers/rest-data-provider';
|
|
|
2
2
|
import { LiveQueryClient } from './live-query/LiveQueryClient';
|
|
3
3
|
import { SseSubscriptionClient } from './live-query/SseSubscriptionClient';
|
|
4
4
|
import { RemultProxy, remult } from './remult-proxy';
|
|
5
|
-
import { RepositoryImplementation
|
|
5
|
+
import { RepositoryImplementation } from './remult3/RepositoryImplementation';
|
|
6
6
|
import { actionInfo, serverActionField } from './server-action-info';
|
|
7
7
|
import { buildRestDataProvider, isExternalHttpProvider, } from './buildRestDataProvider';
|
|
8
8
|
export class RemultAsyncLocalStorage {
|
|
@@ -57,7 +57,7 @@ export class Remult {
|
|
|
57
57
|
this.repCache.set(dataProvider, (dpCache = new Map()));
|
|
58
58
|
let r = dpCache.get(entity);
|
|
59
59
|
if (!r) {
|
|
60
|
-
dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider
|
|
60
|
+
dpCache.set(entity, (r = new RepositoryImplementation(entity, this, dataProvider)));
|
|
61
61
|
}
|
|
62
62
|
return r;
|
|
63
63
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { EntityDataProvider, EntityDataProviderFindOptions } from '../data-interfaces';
|
|
2
|
-
import { type EntityDbNamesBase } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
3
2
|
import { Filter } from '../filter/filter-interfaces';
|
|
4
3
|
import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
|
|
5
4
|
export declare class ArrayEntityDataProvider implements EntityDataProvider {
|
|
@@ -7,13 +6,11 @@ export declare class ArrayEntityDataProvider implements EntityDataProvider {
|
|
|
7
6
|
private rows?;
|
|
8
7
|
static rawFilter(filter: CustomArrayFilter): EntityFilter<any>;
|
|
9
8
|
constructor(entity: EntityMetadata, rows?: any[]);
|
|
10
|
-
__names: EntityDbNamesBase;
|
|
11
|
-
init(): Promise<EntityDbNamesBase>;
|
|
12
9
|
private verifyThatRowHasAllNotNullColumns;
|
|
13
10
|
count(where?: Filter): Promise<number>;
|
|
14
11
|
find(options?: EntityDataProviderFindOptions): Promise<any[]>;
|
|
15
|
-
translateFromJson(row: any
|
|
16
|
-
translateToJson(row: any
|
|
12
|
+
translateFromJson(row: any): {};
|
|
13
|
+
translateToJson(row: any): {};
|
|
17
14
|
private idMatches;
|
|
18
15
|
update(id: any, data: any): Promise<any>;
|
|
19
16
|
delete(id: any): Promise<void>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CompoundIdField } from '../CompoundIdField';
|
|
2
|
-
import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sql-request';
|
|
3
2
|
import { Filter, customDatabaseFilterToken } from '../filter/filter-interfaces';
|
|
4
3
|
export class ArrayEntityDataProvider {
|
|
5
4
|
entity;
|
|
@@ -17,24 +16,16 @@ export class ArrayEntityDataProvider {
|
|
|
17
16
|
if (!rows)
|
|
18
17
|
rows = [];
|
|
19
18
|
else {
|
|
19
|
+
for (const r of rows) {
|
|
20
|
+
this.verifyThatRowHasAllNotNullColumns(r);
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
async init() {
|
|
24
|
-
if (this.__names)
|
|
25
|
-
return this.__names;
|
|
26
|
-
this.__names = await dbNamesOf(this.entity);
|
|
27
|
-
for (const r of this.rows) {
|
|
28
|
-
this.verifyThatRowHasAllNotNullColumns(r, this.__names);
|
|
29
|
-
}
|
|
30
|
-
return this.__names;
|
|
31
|
-
}
|
|
32
|
-
verifyThatRowHasAllNotNullColumns(r, names) {
|
|
24
|
+
verifyThatRowHasAllNotNullColumns(r) {
|
|
33
25
|
for (const f of this.entity.fields) {
|
|
34
|
-
const key = names.$dbNameOf(f);
|
|
35
26
|
if (!f.isServerExpression)
|
|
36
27
|
if (!f.allowNull) {
|
|
37
|
-
if (r[key] === undefined || r[key] === null) {
|
|
28
|
+
if (r[f.key] === undefined || r[f.key] === null) {
|
|
38
29
|
let val = undefined;
|
|
39
30
|
if (f.valueType === Boolean)
|
|
40
31
|
val = false;
|
|
@@ -42,23 +33,22 @@ export class ArrayEntityDataProvider {
|
|
|
42
33
|
val = 0;
|
|
43
34
|
else if (f.valueType === String)
|
|
44
35
|
val = '';
|
|
45
|
-
r[key] = val;
|
|
36
|
+
r[f.key] = val;
|
|
46
37
|
}
|
|
47
38
|
}
|
|
48
|
-
else if (r[key] === undefined)
|
|
49
|
-
r[key] = null;
|
|
39
|
+
else if (r[f.key] === undefined)
|
|
40
|
+
r[f.key] = null;
|
|
50
41
|
}
|
|
51
42
|
}
|
|
52
43
|
async count(where) {
|
|
53
44
|
let rows = this.rows;
|
|
54
|
-
const names = await this.init();
|
|
55
45
|
let j = 0;
|
|
56
46
|
for (let i = 0; i < rows.length; i++) {
|
|
57
47
|
if (!where) {
|
|
58
48
|
j++;
|
|
59
49
|
}
|
|
60
50
|
else {
|
|
61
|
-
let x = new FilterConsumerBridgeToObject(rows[i]
|
|
51
|
+
let x = new FilterConsumerBridgeToObject(rows[i]);
|
|
62
52
|
where.__applyToConsumer(x);
|
|
63
53
|
if (x.ok)
|
|
64
54
|
j++;
|
|
@@ -68,74 +58,70 @@ export class ArrayEntityDataProvider {
|
|
|
68
58
|
}
|
|
69
59
|
async find(options) {
|
|
70
60
|
let rows = this.rows;
|
|
71
|
-
const dbNames = await this.init();
|
|
72
61
|
if (options) {
|
|
73
62
|
if (options.where) {
|
|
74
63
|
rows = rows.filter((i) => {
|
|
75
|
-
let x = new FilterConsumerBridgeToObject(i
|
|
64
|
+
let x = new FilterConsumerBridgeToObject(i);
|
|
76
65
|
options.where.__applyToConsumer(x);
|
|
77
66
|
return x.ok;
|
|
78
67
|
});
|
|
79
68
|
}
|
|
80
69
|
if (options.orderBy) {
|
|
81
70
|
rows = rows.sort((a, b) => {
|
|
82
|
-
return options.orderBy.compare(a, b
|
|
71
|
+
return options.orderBy.compare(a, b);
|
|
83
72
|
});
|
|
84
73
|
}
|
|
85
74
|
rows = pageArray(rows, options);
|
|
86
75
|
}
|
|
87
76
|
if (rows)
|
|
88
77
|
return rows.map((i) => {
|
|
89
|
-
return this.translateFromJson(i
|
|
78
|
+
return this.translateFromJson(i);
|
|
90
79
|
});
|
|
91
80
|
}
|
|
92
|
-
translateFromJson(row
|
|
81
|
+
translateFromJson(row) {
|
|
93
82
|
let result = {};
|
|
94
83
|
for (const col of this.entity.fields) {
|
|
95
|
-
result[col.key] = col.valueConverter.fromJson(row[
|
|
84
|
+
result[col.key] = col.valueConverter.fromJson(row[col.key]);
|
|
96
85
|
}
|
|
97
86
|
return result;
|
|
98
87
|
}
|
|
99
|
-
translateToJson(row
|
|
88
|
+
translateToJson(row) {
|
|
100
89
|
let result = {};
|
|
101
90
|
for (const col of this.entity.fields) {
|
|
102
|
-
|
|
103
|
-
result[dbNames.$dbNameOf(col)] = col.valueConverter.toJson(row[col.key]);
|
|
91
|
+
result[col.key] = col.valueConverter.toJson(row[col.key]);
|
|
104
92
|
}
|
|
105
93
|
return result;
|
|
106
94
|
}
|
|
107
|
-
idMatches(id
|
|
95
|
+
idMatches(id) {
|
|
108
96
|
return (item) => {
|
|
109
|
-
let x = new FilterConsumerBridgeToObject(item
|
|
97
|
+
let x = new FilterConsumerBridgeToObject(item);
|
|
110
98
|
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(x);
|
|
111
99
|
return x.ok;
|
|
112
100
|
};
|
|
113
101
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let idMatches = this.idMatches(id, names);
|
|
102
|
+
update(id, data) {
|
|
103
|
+
let idMatches = this.idMatches(id);
|
|
117
104
|
let keys = Object.keys(data);
|
|
118
105
|
for (let i = 0; i < this.rows.length; i++) {
|
|
119
106
|
let r = this.rows[i];
|
|
120
107
|
if (idMatches(r)) {
|
|
121
108
|
let newR = { ...r };
|
|
122
109
|
for (const f of this.entity.fields) {
|
|
123
|
-
if (!
|
|
110
|
+
if (!f.dbReadOnly && !f.isServerExpression) {
|
|
124
111
|
if (keys.includes(f.key)) {
|
|
125
|
-
newR[
|
|
112
|
+
newR[f.key] = f.valueConverter.toJson(data[f.key]);
|
|
126
113
|
}
|
|
127
114
|
}
|
|
128
115
|
}
|
|
129
|
-
this.verifyThatRowHasAllNotNullColumns(newR
|
|
116
|
+
this.verifyThatRowHasAllNotNullColumns(newR);
|
|
130
117
|
this.rows[i] = newR;
|
|
131
|
-
return Promise.resolve(this.translateFromJson(this.rows[i]
|
|
118
|
+
return Promise.resolve(this.translateFromJson(this.rows[i]));
|
|
132
119
|
}
|
|
133
120
|
}
|
|
134
121
|
throw new Error("couldn't find id to update: " + id);
|
|
135
122
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
let idMatches = this.idMatches(id, names);
|
|
123
|
+
delete(id) {
|
|
124
|
+
let idMatches = this.idMatches(id);
|
|
139
125
|
for (let i = 0; i < this.rows.length; i++) {
|
|
140
126
|
if (idMatches(this.rows[i])) {
|
|
141
127
|
this.rows.splice(i, 1);
|
|
@@ -145,26 +131,25 @@ export class ArrayEntityDataProvider {
|
|
|
145
131
|
throw new Error("couldn't find id to delete: " + id);
|
|
146
132
|
}
|
|
147
133
|
async insert(data) {
|
|
148
|
-
const names = await this.init();
|
|
149
|
-
let j = this.translateToJson(data, names);
|
|
150
134
|
let idf = this.entity.idMetadata.field;
|
|
151
135
|
if (!(idf instanceof CompoundIdField)) {
|
|
152
136
|
if (idf.options.valueConverter?.fieldTypeInDb === 'autoincrement') {
|
|
153
|
-
|
|
137
|
+
data[idf.key] = 1;
|
|
154
138
|
for (const row of this.rows) {
|
|
155
|
-
if (row[idf.key] >=
|
|
156
|
-
|
|
139
|
+
if (row[idf.key] >= data[idf.key])
|
|
140
|
+
data[idf.key] = row[idf.key] + 1;
|
|
157
141
|
}
|
|
158
142
|
}
|
|
159
|
-
if (
|
|
143
|
+
if (data[idf.key])
|
|
160
144
|
this.rows.forEach((i) => {
|
|
161
|
-
if (
|
|
145
|
+
if (data[idf.key] == i[idf.key])
|
|
162
146
|
throw Error('id already exists');
|
|
163
147
|
});
|
|
164
148
|
}
|
|
165
|
-
this.
|
|
149
|
+
let j = this.translateToJson(data);
|
|
150
|
+
this.verifyThatRowHasAllNotNullColumns(j);
|
|
166
151
|
this.rows.push(j);
|
|
167
|
-
return Promise.resolve(this.translateFromJson(j
|
|
152
|
+
return Promise.resolve(this.translateFromJson(j));
|
|
168
153
|
}
|
|
169
154
|
}
|
|
170
155
|
function pageArray(rows, options) {
|
|
@@ -187,11 +172,9 @@ function pageArray(rows, options) {
|
|
|
187
172
|
}
|
|
188
173
|
class FilterConsumerBridgeToObject {
|
|
189
174
|
row;
|
|
190
|
-
dbNames;
|
|
191
175
|
ok = true;
|
|
192
|
-
constructor(row
|
|
176
|
+
constructor(row) {
|
|
193
177
|
this.row = row;
|
|
194
|
-
this.dbNames = dbNames;
|
|
195
178
|
}
|
|
196
179
|
databaseCustom(databaseCustom) {
|
|
197
180
|
if (databaseCustom && databaseCustom.arrayFilter) {
|
|
@@ -204,7 +187,7 @@ class FilterConsumerBridgeToObject {
|
|
|
204
187
|
}
|
|
205
188
|
or(orElements) {
|
|
206
189
|
for (const element of orElements) {
|
|
207
|
-
let filter = new FilterConsumerBridgeToObject(this.row
|
|
190
|
+
let filter = new FilterConsumerBridgeToObject(this.row);
|
|
208
191
|
element.__applyToConsumer(filter);
|
|
209
192
|
if (filter.ok) {
|
|
210
193
|
return;
|
|
@@ -213,47 +196,47 @@ class FilterConsumerBridgeToObject {
|
|
|
213
196
|
this.ok = false;
|
|
214
197
|
}
|
|
215
198
|
isNull(col) {
|
|
216
|
-
if (this.row[
|
|
199
|
+
if (this.row[col.key] != null)
|
|
217
200
|
this.ok = false;
|
|
218
201
|
}
|
|
219
202
|
isNotNull(col) {
|
|
220
|
-
if (this.row[
|
|
203
|
+
if (this.row[col.key] == null)
|
|
221
204
|
this.ok = false;
|
|
222
205
|
}
|
|
223
206
|
isIn(col, val) {
|
|
224
207
|
for (const v of val) {
|
|
225
|
-
if (this.row[
|
|
208
|
+
if (this.row[col.key] == col.valueConverter.toJson(v)) {
|
|
226
209
|
return;
|
|
227
210
|
}
|
|
228
211
|
}
|
|
229
212
|
this.ok = false;
|
|
230
213
|
}
|
|
231
214
|
isEqualTo(col, val) {
|
|
232
|
-
if (this.row[
|
|
215
|
+
if (this.row[col.key] != col.valueConverter.toJson(val))
|
|
233
216
|
this.ok = false;
|
|
234
217
|
}
|
|
235
218
|
isDifferentFrom(col, val) {
|
|
236
|
-
if (this.row[
|
|
219
|
+
if (this.row[col.key] == col.valueConverter.toJson(val))
|
|
237
220
|
this.ok = false;
|
|
238
221
|
}
|
|
239
222
|
isGreaterOrEqualTo(col, val) {
|
|
240
|
-
if (this.row[
|
|
223
|
+
if (this.row[col.key] < col.valueConverter.toJson(val))
|
|
241
224
|
this.ok = false;
|
|
242
225
|
}
|
|
243
226
|
isGreaterThan(col, val) {
|
|
244
|
-
if (this.row[
|
|
227
|
+
if (this.row[col.key] <= col.valueConverter.toJson(val))
|
|
245
228
|
this.ok = false;
|
|
246
229
|
}
|
|
247
230
|
isLessOrEqualTo(col, val) {
|
|
248
|
-
if (this.row[
|
|
231
|
+
if (this.row[col.key] > col.valueConverter.toJson(val))
|
|
249
232
|
this.ok = false;
|
|
250
233
|
}
|
|
251
234
|
isLessThan(col, val) {
|
|
252
|
-
if (this.row[
|
|
235
|
+
if (this.row[col.key] >= col.valueConverter.toJson(val))
|
|
253
236
|
this.ok = false;
|
|
254
237
|
}
|
|
255
238
|
containsCaseInsensitive(col, val) {
|
|
256
|
-
let v = this.row[
|
|
239
|
+
let v = this.row[col.key];
|
|
257
240
|
if (!v) {
|
|
258
241
|
this.ok = false;
|
|
259
242
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, RestDataProviderHttpProvider } from '../data-interfaces';
|
|
2
2
|
import { UrlBuilder } from '../../urlBuilder';
|
|
3
|
-
import {
|
|
3
|
+
import type { ApiClient } from '../context';
|
|
4
4
|
import { Filter } from '../filter/filter-interfaces';
|
|
5
5
|
import type { EntityMetadata } from '../remult3/remult3';
|
|
6
6
|
export declare class RestDataProvider implements DataProvider {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { UrlBuilder } from '../../urlBuilder';
|
|
2
2
|
import { buildRestDataProvider, retry } from '../buildRestDataProvider';
|
|
3
|
-
import { Remult } from '../context';
|
|
4
3
|
import { customUrlToken, Filter } from '../filter/filter-interfaces';
|
|
5
4
|
import { actionInfo } from '../server-action-info';
|
|
6
|
-
import { getRelationInfo } from '../remult3/relationInfoMember';
|
|
7
5
|
export class RestDataProvider {
|
|
8
6
|
apiProvider;
|
|
9
7
|
constructor(apiProvider) {
|
|
@@ -26,64 +24,22 @@ export class RestDataProvider {
|
|
|
26
24
|
}
|
|
27
25
|
//@internal
|
|
28
26
|
export function findOptionsToJson(options, meta) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let element = options.include[key];
|
|
34
|
-
if (typeof element === 'object') {
|
|
35
|
-
const rel = getRelationInfo(meta.fields.find(key).options);
|
|
36
|
-
if (rel) {
|
|
37
|
-
element = findOptionsToJson(element, new Remult().repo(rel.toType()).metadata);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
newInclude[key] = element;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
options = { ...options, include: newInclude };
|
|
44
|
-
}
|
|
45
|
-
if (options.where)
|
|
46
|
-
options = {
|
|
47
|
-
...options,
|
|
48
|
-
where: Filter.entityFilterToJson(meta, options.where),
|
|
49
|
-
};
|
|
27
|
+
const r = {
|
|
28
|
+
...options,
|
|
29
|
+
where: Filter.entityFilterToJson(meta, options.where),
|
|
30
|
+
};
|
|
50
31
|
if (options.load)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
load: options.load(meta.fields).map((y) => y.key),
|
|
54
|
-
};
|
|
55
|
-
return options;
|
|
32
|
+
r.load = options.load(meta.fields).map((y) => y.key);
|
|
33
|
+
return r;
|
|
56
34
|
}
|
|
57
35
|
//@internal
|
|
58
36
|
export function findOptionsFromJson(json, meta) {
|
|
59
37
|
let r = {};
|
|
60
|
-
for (const key of [
|
|
61
|
-
'limit',
|
|
62
|
-
'page',
|
|
63
|
-
'where',
|
|
64
|
-
'orderBy',
|
|
65
|
-
'include',
|
|
66
|
-
]) {
|
|
38
|
+
for (const key of ['limit', 'page', 'where', 'orderBy']) {
|
|
67
39
|
if (json[key] !== undefined) {
|
|
68
40
|
if (key === 'where') {
|
|
69
41
|
r[key] = Filter.entityFilterFromJson(meta, json.where);
|
|
70
42
|
}
|
|
71
|
-
else if (key === 'include') {
|
|
72
|
-
let newInclude = { ...json[key] };
|
|
73
|
-
for (const key in newInclude) {
|
|
74
|
-
if (Object.prototype.hasOwnProperty.call(newInclude, key)) {
|
|
75
|
-
let element = newInclude[key];
|
|
76
|
-
if (typeof element === 'object') {
|
|
77
|
-
const rel = getRelationInfo(meta.fields.find(key).options);
|
|
78
|
-
if (rel) {
|
|
79
|
-
element = findOptionsFromJson(element, new Remult().repo(rel.toType()).metadata);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
newInclude[key] = element;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
r[key] = newInclude;
|
|
86
|
-
}
|
|
87
43
|
else
|
|
88
44
|
r[key] = json[key];
|
|
89
45
|
}
|
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import type { ClassType } from '../../classType';
|
|
2
2
|
import type { FieldOptions } from '../column-interfaces';
|
|
3
3
|
import type { Remult } from '../context';
|
|
4
|
-
import type { FindOptions, RelationOptions,
|
|
5
|
-
import { type ClassFieldDecoratorContextStub } from './RepositoryImplementation';
|
|
4
|
+
import type { FindOptions, RelationOptions, ClassFieldDecorator, ClassFieldDecoratorContextStub } from './remult3';
|
|
6
5
|
export declare class Fields {
|
|
7
6
|
/**
|
|
8
7
|
* Stored as a JSON.stringify - to store as json use Fields.json
|
|
9
8
|
*/
|
|
10
|
-
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]):
|
|
11
|
-
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]):
|
|
12
|
-
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
13
|
-
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
14
|
-
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
15
|
-
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
16
|
-
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]):
|
|
17
|
-
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
18
|
-
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]):
|
|
19
|
-
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]):
|
|
20
|
-
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]):
|
|
21
|
-
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]):
|
|
22
|
-
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]):
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
10
|
+
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
|
|
11
|
+
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
12
|
+
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
13
|
+
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
14
|
+
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
15
|
+
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
16
|
+
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
17
|
+
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
18
|
+
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
19
|
+
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
20
|
+
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
21
|
+
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
|
|
22
|
+
}
|
|
23
|
+
export declare class Relations {
|
|
24
|
+
/** A to one relation with an automatically generated field */
|
|
25
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: FieldOptions<entityType, toEntityType> & Pick<RelationOptions<entityType, toEntityType, any, any>, 'defaultIncluded'>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
26
|
+
/** A to one relation with fields defined in the second parameter */
|
|
27
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInMyEntity?: keyof entityType): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
28
|
+
/** A to one relation with fields defined in the field/fields parameter */
|
|
29
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'field'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
30
|
+
/** A to one relation with fields defined in the field/fields parameter */
|
|
31
|
+
static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: Omit<RelationOptions<entityType, toEntityType, entityType>, keyof Pick<RelationOptions<entityType, toEntityType, entityType>, 'fields'>>): ClassFieldDecorator<entityType, toEntityType | undefined>;
|
|
32
|
+
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, fieldInToEntity?: keyof toEntityType): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
33
|
+
static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>>): ClassFieldDecorator<entityType, toEntityType[] | undefined>;
|
|
28
34
|
}
|
|
29
35
|
/**Decorates fields that should be used as fields.
|
|
30
36
|
* for more info see: [Field Types](https://remult.dev/docs/field-types.html)
|
|
@@ -39,7 +45,7 @@ export declare class Fields {
|
|
|
39
45
|
* @Fields.string((options,remult) => options.includeInApi = true)
|
|
40
46
|
* title='';
|
|
41
47
|
*/
|
|
42
|
-
export declare function Field<entityType = any, valueType = any>(valueType: () => ClassType<valueType
|
|
48
|
+
export declare function Field<entityType = any, valueType = any>(valueType: (() => ClassType<valueType>) | undefined, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
|
|
43
49
|
export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
|
|
44
50
|
maxLength?: number;
|
|
45
51
|
}
|