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
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createId } from '@paralleldrive/cuid2';
|
|
2
2
|
import { v4 as uuid } from 'uuid';
|
|
3
3
|
import { ValueConverters } from '../valueConverters';
|
|
4
|
-
import {
|
|
5
|
-
import { buildOptions, columnsOfType, } from './RepositoryImplementation';
|
|
4
|
+
import { buildOptions, columnsOfType } from './RepositoryImplementation';
|
|
6
5
|
import { relationInfoMember } from './relationInfoMember';
|
|
7
6
|
export class Fields {
|
|
8
7
|
/**
|
|
@@ -47,8 +46,8 @@ export class Fields {
|
|
|
47
46
|
static createdAt(...options) {
|
|
48
47
|
return Field(() => Date, {
|
|
49
48
|
allowApiUpdate: false,
|
|
50
|
-
saving: (_, ref) => {
|
|
51
|
-
if (
|
|
49
|
+
saving: (_, { isNew }, ref) => {
|
|
50
|
+
if (isNew)
|
|
52
51
|
ref.value = new Date();
|
|
53
52
|
},
|
|
54
53
|
}, ...options);
|
|
@@ -56,7 +55,7 @@ export class Fields {
|
|
|
56
55
|
static updatedAt(...options) {
|
|
57
56
|
return Field(() => Date, {
|
|
58
57
|
allowApiUpdate: false,
|
|
59
|
-
saving: (_, ref) => {
|
|
58
|
+
saving: (_, _1, ref) => {
|
|
60
59
|
ref.value = new Date();
|
|
61
60
|
},
|
|
62
61
|
}, ...options);
|
|
@@ -65,7 +64,7 @@ export class Fields {
|
|
|
65
64
|
return Field(() => String, {
|
|
66
65
|
allowApiUpdate: false,
|
|
67
66
|
defaultValue: () => uuid(),
|
|
68
|
-
saving: (_, r) => {
|
|
67
|
+
saving: (_, _1, r) => {
|
|
69
68
|
if (!r.value)
|
|
70
69
|
r.value = uuid();
|
|
71
70
|
},
|
|
@@ -75,7 +74,7 @@ export class Fields {
|
|
|
75
74
|
return Field(() => String, {
|
|
76
75
|
allowApiUpdate: false,
|
|
77
76
|
defaultValue: () => createId(),
|
|
78
|
-
saving: (_, r) => {
|
|
77
|
+
saving: (_, _1, r) => {
|
|
79
78
|
if (!r.value)
|
|
80
79
|
r.value = createId();
|
|
81
80
|
},
|
|
@@ -87,25 +86,24 @@ export class Fields {
|
|
|
87
86
|
static boolean(...options) {
|
|
88
87
|
return Field(() => Boolean, ...options);
|
|
89
88
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
? {}
|
|
94
|
-
: options);
|
|
95
|
-
return Field(toEntityType, {
|
|
96
|
-
...op,
|
|
97
|
-
//@ts-ignore
|
|
98
|
-
[relationInfoMember]: {
|
|
99
|
-
//field,
|
|
100
|
-
toType: toEntityType,
|
|
101
|
-
type: 'reference',
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
static many(toEntityType, options) {
|
|
89
|
+
}
|
|
90
|
+
export class Relations {
|
|
91
|
+
static toOne(toEntityType, options) {
|
|
106
92
|
let op = (typeof options === 'string'
|
|
107
93
|
? { field: options }
|
|
108
|
-
: options
|
|
94
|
+
: !options
|
|
95
|
+
? {}
|
|
96
|
+
: options);
|
|
97
|
+
if (!op.field && !op.fields && !op.findOptions)
|
|
98
|
+
return Field(toEntityType, {
|
|
99
|
+
...op,
|
|
100
|
+
//@ts-ignore
|
|
101
|
+
[relationInfoMember]: {
|
|
102
|
+
//field,
|
|
103
|
+
toType: toEntityType,
|
|
104
|
+
type: 'reference',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
109
107
|
return Field(() => undefined, {
|
|
110
108
|
...op,
|
|
111
109
|
serverExpression: () => undefined,
|
|
@@ -113,16 +111,14 @@ export class Fields {
|
|
|
113
111
|
[relationInfoMember]: {
|
|
114
112
|
//field,
|
|
115
113
|
toType: toEntityType,
|
|
116
|
-
type: '
|
|
114
|
+
type: 'toOne',
|
|
117
115
|
},
|
|
118
116
|
});
|
|
119
117
|
}
|
|
120
|
-
static
|
|
118
|
+
static toMany(toEntityType, options) {
|
|
121
119
|
let op = (typeof options === 'string'
|
|
122
120
|
? { field: options }
|
|
123
|
-
:
|
|
124
|
-
? {}
|
|
125
|
-
: options);
|
|
121
|
+
: options);
|
|
126
122
|
return Field(() => undefined, {
|
|
127
123
|
...op,
|
|
128
124
|
serverExpression: () => undefined,
|
|
@@ -130,7 +126,7 @@ export class Fields {
|
|
|
130
126
|
[relationInfoMember]: {
|
|
131
127
|
//field,
|
|
132
128
|
toType: toEntityType,
|
|
133
|
-
type: '
|
|
129
|
+
type: 'toMany',
|
|
134
130
|
},
|
|
135
131
|
});
|
|
136
132
|
}
|
|
@@ -3,27 +3,23 @@ import { LookupColumn } from '../column';
|
|
|
3
3
|
import type { FieldMetadata, FieldOptions, ValueConverter, ValueListItem } from '../column-interfaces';
|
|
4
4
|
import { Remult } from '../context';
|
|
5
5
|
import type { EntityOptions } from '../entity';
|
|
6
|
-
import type { ControllerRef, EntityFilter, EntityMetadata, EntityOrderBy, EntityRef, FieldRef, FieldsMetadata, FieldsRef, FindFirstOptions, FindFirstOptionsBase, FindOptions, IdMetadata, LiveQuery, OmitEB, QueryOptions, QueryResult, Repository,
|
|
6
|
+
import type { ControllerRef, EntityFilter, EntityMetadata, EntityOrderBy, EntityRef, FieldRef, FieldsMetadata, FieldsRef, FindFirstOptions, FindFirstOptionsBase, FindOptions, IdMetadata, LiveQuery, OmitEB, QueryOptions, QueryResult, Repository, Subscribable } from './remult3';
|
|
7
7
|
import type { RefSubscriber } from './remult3';
|
|
8
8
|
import type { entityEventListener } from '../__EntityValueProvider';
|
|
9
9
|
import type { DataProvider, EntityDataProvider, EntityDataProviderFindOptions, ErrorInfo } from '../data-interfaces';
|
|
10
10
|
import type { Unsubscribe } from '../live-query/SubscriptionChannel';
|
|
11
|
-
import type { columnInfo } from './columnInfo';
|
|
12
|
-
import { RelationLoader } from './relation-loader';
|
|
13
11
|
export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
|
|
14
12
|
private entity;
|
|
15
13
|
remult: Remult;
|
|
16
14
|
private dataProvider;
|
|
17
|
-
private _info;
|
|
18
|
-
private defaultFindOptions?;
|
|
19
15
|
createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
|
|
20
|
-
|
|
16
|
+
private _info;
|
|
21
17
|
private __edp;
|
|
22
18
|
private get edp();
|
|
23
|
-
constructor(entity: ClassType<entityType>, remult: Remult, dataProvider: DataProvider
|
|
19
|
+
constructor(entity: ClassType<entityType>, remult: Remult, dataProvider: DataProvider);
|
|
24
20
|
idCache: Map<any, any>;
|
|
25
|
-
getCachedById(id: any
|
|
26
|
-
getCachedByIdAsync(id: any
|
|
21
|
+
getCachedById(id: any): entityType;
|
|
22
|
+
getCachedByIdAsync(id: any): Promise<entityType>;
|
|
27
23
|
addToCache(item: entityType): void;
|
|
28
24
|
get metadata(): EntityMetadata<entityType>;
|
|
29
25
|
listeners: entityEventListener<entityType>[];
|
|
@@ -50,7 +46,6 @@ export declare class RepositoryImplementation<entityType> implements Repository<
|
|
|
50
46
|
save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
|
|
51
47
|
save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
|
|
52
48
|
liveQuery(options?: FindOptions<entityType>): LiveQuery<entityType>;
|
|
53
|
-
rawFind(options: FindOptions<entityType>, skipOrderByAndLimit: boolean, loader: RelationLoader): Promise<Awaited<entityType>[]>;
|
|
54
49
|
find(options: FindOptions<entityType>, skipOrderByAndLimit?: boolean): Promise<entityType[]>;
|
|
55
50
|
buildEntityDataProviderFindOptions(options: FindOptions<entityType>): Promise<EntityDataProviderFindOptions>;
|
|
56
51
|
fromJsonArray(jsonItems: any[], load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[]): Promise<Awaited<entityType>[]>;
|
|
@@ -103,7 +98,7 @@ declare abstract class rowHelperBase<T> {
|
|
|
103
98
|
__validateEntity(): Promise<void>;
|
|
104
99
|
__performColumnAndEntityValidations(): Promise<void>;
|
|
105
100
|
toApiJson(includeRelatedEntities?: boolean): any;
|
|
106
|
-
_updateEntityBasedOnApi(body: any): Promise<void>;
|
|
101
|
+
_updateEntityBasedOnApi(body: any, ignoreApiAllowed?: boolean): Promise<void>;
|
|
107
102
|
}
|
|
108
103
|
export declare class rowHelperImplementation<T> extends rowHelperBase<T> implements EntityRef<T> {
|
|
109
104
|
private info;
|
|
@@ -223,7 +218,28 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
|
|
|
223
218
|
caption: string;
|
|
224
219
|
}
|
|
225
220
|
export declare function FieldType<valueType = any>(...options: (FieldOptions<any, valueType> | ((options: FieldOptions<any, valueType>, remult: Remult) => void))[]): (target: any, context?: any) => any;
|
|
221
|
+
export declare class Fields {
|
|
222
|
+
/**
|
|
223
|
+
* Stored as a JSON.stringify - to store as json use Fields.json
|
|
224
|
+
*/
|
|
225
|
+
static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
|
|
226
|
+
static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, valueType | undefined>, c?: any) => void;
|
|
227
|
+
static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
|
|
228
|
+
static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
|
|
229
|
+
static integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
|
|
230
|
+
static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
|
|
231
|
+
static number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, number | undefined>, c?: any) => void;
|
|
232
|
+
static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
|
|
233
|
+
static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, Date | undefined>, c?: any) => void;
|
|
234
|
+
static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
|
|
235
|
+
static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
|
|
236
|
+
static string<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, string | undefined>, c?: any) => void;
|
|
237
|
+
static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, boolean | undefined>, c?: any) => void;
|
|
238
|
+
}
|
|
226
239
|
export declare function isAutoIncrement(f: FieldMetadata): boolean;
|
|
240
|
+
export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
|
|
241
|
+
maxLength?: number;
|
|
242
|
+
}
|
|
227
243
|
export declare function ValueListFieldType<valueType extends ValueListItem = any>(...options: (ValueListFieldOptions<any, valueType> | ((options: FieldOptions<any, valueType>, remult: Remult) => void))[]): (type: ClassType<valueType>, context?: any) => void;
|
|
228
244
|
export interface ValueListFieldOptions<entityType, valueType> extends FieldOptions<entityType, valueType> {
|
|
229
245
|
getValues?: () => valueType[];
|
|
@@ -261,9 +277,26 @@ export interface ClassDecoratorContextStub<Class extends new (...args: any) => a
|
|
|
261
277
|
readonly name: string | undefined;
|
|
262
278
|
addInitializer(initializer: (this: Class) => void): void;
|
|
263
279
|
}
|
|
280
|
+
/**Decorates fields that should be used as fields.
|
|
281
|
+
* for more info see: [Field Types](https://remult.dev/docs/field-types.html)
|
|
282
|
+
*
|
|
283
|
+
* FieldOptions can be set in two ways:
|
|
284
|
+
* @example
|
|
285
|
+
* // as an object
|
|
286
|
+
* @Fields.string({ includeInApi:false })
|
|
287
|
+
* title='';
|
|
288
|
+
* @example
|
|
289
|
+
* // as an arrow function that receives `remult` as a parameter
|
|
290
|
+
* @Fields.string((options,remult) => options.includeInApi = true)
|
|
291
|
+
* title='';
|
|
292
|
+
*/
|
|
293
|
+
export declare function Field<entityType = any, valueType = any>(valueType: () => ClassType<valueType>, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, context: ClassFieldDecoratorContextStub<entityType, valueType | undefined> | string, c?: any) => void;
|
|
264
294
|
export declare const storableMember: unique symbol;
|
|
265
|
-
export declare function buildOptions<entityType = any, valueType = any>(options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[], remult: Remult): FieldOptions<entityType, valueType>;
|
|
266
295
|
export declare function decorateColumnSettings<valueType>(settings: FieldOptions<any, valueType>, remult: Remult): FieldOptions<any, valueType>;
|
|
296
|
+
interface columnInfo {
|
|
297
|
+
key: string;
|
|
298
|
+
settings: (remult: Remult) => FieldOptions;
|
|
299
|
+
}
|
|
267
300
|
export declare class EntityBase {
|
|
268
301
|
get _(): EntityRef<this>;
|
|
269
302
|
save(): Promise<this>;
|
|
@@ -272,6 +305,9 @@ export declare class EntityBase {
|
|
|
272
305
|
isNew(): boolean;
|
|
273
306
|
get $(): FieldsRef<this>;
|
|
274
307
|
}
|
|
308
|
+
export declare class IdEntity extends EntityBase {
|
|
309
|
+
id: string;
|
|
310
|
+
}
|
|
275
311
|
export declare class ControllerBase {
|
|
276
312
|
protected remult: Remult;
|
|
277
313
|
constructor(remult?: Remult);
|
|
@@ -292,4 +328,5 @@ export declare function getEntityMetadata<entityType>(entity: EntityMetadataOver
|
|
|
292
328
|
export declare function getRepository<entityType>(entity: RepositoryOverloads<entityType>): Repository<entityType>;
|
|
293
329
|
export type EntityMetadataOverloads<entityType> = Repository<entityType> | EntityMetadata<entityType> | ClassType<entityType>;
|
|
294
330
|
export type RepositoryOverloads<entityType> = Repository<entityType> | ClassType<entityType>;
|
|
331
|
+
export declare function checkTarget(target: any): void;
|
|
295
332
|
export {};
|