remult 0.22.8 → 0.22.9-exp.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.
Files changed (67) hide show
  1. package/esm/index.d.ts +4 -3
  2. package/esm/index.js +3 -1
  3. package/esm/internals.d.ts +6 -0
  4. package/esm/internals.js +5 -0
  5. package/esm/live-query/data-provider-live-query-storage.js +2 -1
  6. package/esm/server/expressBridge.d.ts +1 -1
  7. package/esm/server/expressBridge.js +2 -1
  8. package/esm/src/column.d.ts +3 -2
  9. package/esm/src/column.js +6 -5
  10. package/esm/src/context.js +2 -2
  11. package/esm/src/data-providers/array-entity-data-provider.d.ts +5 -2
  12. package/esm/src/data-providers/array-entity-data-provider.js +63 -46
  13. package/esm/src/data-providers/rest-data-provider.d.ts +1 -1
  14. package/esm/src/data-providers/rest-data-provider.js +51 -7
  15. package/esm/src/remult3/Fields.d.ts +46 -0
  16. package/esm/src/remult3/Fields.js +199 -0
  17. package/esm/src/remult3/IdEntity.d.ts +4 -0
  18. package/esm/src/remult3/IdEntity.js +10 -0
  19. package/esm/src/remult3/RepositoryImplementation.d.ts +11 -48
  20. package/esm/src/remult3/RepositoryImplementation.js +201 -193
  21. package/esm/src/remult3/columnInfo.d.ts +6 -0
  22. package/esm/src/remult3/columnInfo.js +1 -0
  23. package/esm/src/remult3/relation-loader-types.d.ts +7 -0
  24. package/esm/src/remult3/relation-loader-types.js +1 -0
  25. package/esm/src/remult3/relation-loader.d.ts +40 -0
  26. package/esm/src/remult3/relation-loader.js +139 -0
  27. package/esm/src/remult3/relationInfoMember.d.ts +4 -0
  28. package/esm/src/remult3/relationInfoMember.js +4 -0
  29. package/esm/src/remult3/remult3.d.ts +30 -1
  30. package/esm/src/remult3/remult3.js +4 -0
  31. package/esm/src/server-action.js +2 -1
  32. package/esm/src/sort.d.ts +1 -1
  33. package/esm/src/sort.js +5 -3
  34. package/index.d.ts +4 -3
  35. package/index.js +6 -4
  36. package/internals.d.ts +6 -0
  37. package/internals.js +13 -0
  38. package/live-query/data-provider-live-query-storage.js +5 -4
  39. package/package.json +6 -14
  40. package/server/expressBridge.d.ts +1 -1
  41. package/server/expressBridge.js +11 -10
  42. package/src/column.d.ts +3 -2
  43. package/src/column.js +4 -4
  44. package/src/context.js +1 -1
  45. package/src/data-providers/array-entity-data-provider.d.ts +5 -2
  46. package/src/data-providers/array-entity-data-provider.js +192 -134
  47. package/src/data-providers/rest-data-provider.d.ts +1 -1
  48. package/src/data-providers/rest-data-provider.js +45 -4
  49. package/src/remult3/Fields.d.ts +46 -0
  50. package/src/remult3/Fields.js +259 -0
  51. package/src/remult3/IdEntity.d.ts +4 -0
  52. package/src/remult3/IdEntity.js +18 -0
  53. package/src/remult3/RepositoryImplementation.d.ts +11 -48
  54. package/src/remult3/RepositoryImplementation.js +422 -415
  55. package/src/remult3/columnInfo.d.ts +6 -0
  56. package/src/remult3/columnInfo.js +2 -0
  57. package/src/remult3/relation-loader-types.d.ts +7 -0
  58. package/src/remult3/relation-loader-types.js +2 -0
  59. package/src/remult3/relation-loader.d.ts +40 -0
  60. package/src/remult3/relation-loader.js +216 -0
  61. package/src/remult3/relationInfoMember.d.ts +4 -0
  62. package/src/remult3/relationInfoMember.js +8 -0
  63. package/src/remult3/remult3.d.ts +30 -1
  64. package/src/remult3/remult3.js +4 -0
  65. package/src/server-action.js +2 -1
  66. package/src/sort.d.ts +1 -1
  67. package/src/sort.js +5 -3
@@ -0,0 +1,199 @@
1
+ import { createId } from '@paralleldrive/cuid2';
2
+ import { v4 as uuid } from 'uuid';
3
+ import { ValueConverters } from '../valueConverters';
4
+ import { getEntityRef } from './getEntityRef';
5
+ import { buildOptions, columnsOfType, } from './RepositoryImplementation';
6
+ import { relationInfoMember } from './relationInfoMember';
7
+ export class Fields {
8
+ /**
9
+ * Stored as a JSON.stringify - to store as json use Fields.json
10
+ */
11
+ static object(...options) {
12
+ return Field(undefined, ...options);
13
+ }
14
+ static json(...options) {
15
+ return Field(undefined, {
16
+ valueConverter: {
17
+ fieldTypeInDb: 'json',
18
+ },
19
+ }, ...options);
20
+ }
21
+ static dateOnly(...options) {
22
+ return Field(() => Date, {
23
+ valueConverter: ValueConverters.DateOnly,
24
+ }, ...options);
25
+ }
26
+ static date(...options) {
27
+ return Field(() => Date, ...options);
28
+ }
29
+ static integer(...options) {
30
+ return Field(() => Number, {
31
+ valueConverter: ValueConverters.Integer,
32
+ }, ...options);
33
+ }
34
+ static autoIncrement(...options) {
35
+ return Field(() => Number, {
36
+ allowApiUpdate: false,
37
+ dbReadOnly: true,
38
+ valueConverter: {
39
+ ...ValueConverters.Integer,
40
+ fieldTypeInDb: 'autoincrement',
41
+ },
42
+ }, ...options);
43
+ }
44
+ static number(...options) {
45
+ return Field(() => Number, ...options);
46
+ }
47
+ static createdAt(...options) {
48
+ return Field(() => Date, {
49
+ allowApiUpdate: false,
50
+ saving: (_, ref) => {
51
+ if (getEntityRef(_).isNew())
52
+ ref.value = new Date();
53
+ },
54
+ }, ...options);
55
+ }
56
+ static updatedAt(...options) {
57
+ return Field(() => Date, {
58
+ allowApiUpdate: false,
59
+ saving: (_, ref) => {
60
+ ref.value = new Date();
61
+ },
62
+ }, ...options);
63
+ }
64
+ static uuid(...options) {
65
+ return Field(() => String, {
66
+ allowApiUpdate: false,
67
+ defaultValue: () => uuid(),
68
+ saving: (_, r) => {
69
+ if (!r.value)
70
+ r.value = uuid();
71
+ },
72
+ }, ...options);
73
+ }
74
+ static cuid(...options) {
75
+ return Field(() => String, {
76
+ allowApiUpdate: false,
77
+ defaultValue: () => createId(),
78
+ saving: (_, r) => {
79
+ if (!r.value)
80
+ r.value = createId();
81
+ },
82
+ }, ...options);
83
+ }
84
+ static string(...options) {
85
+ return Field(() => String, ...options);
86
+ }
87
+ static boolean(...options) {
88
+ return Field(() => Boolean, ...options);
89
+ }
90
+ //[ ] docking the move from reference to one will not be fun,since the parameter order changes
91
+ static reference(toEntityType, options) {
92
+ let op = (!options
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) {
106
+ let op = (typeof options === 'string'
107
+ ? { field: options }
108
+ : options);
109
+ return Field(() => undefined, {
110
+ ...op,
111
+ serverExpression: () => undefined,
112
+ //@ts-ignore
113
+ [relationInfoMember]: {
114
+ //field,
115
+ toType: toEntityType,
116
+ type: 'toMany',
117
+ },
118
+ });
119
+ }
120
+ static one(entity, toEntityType, options) {
121
+ let op = (typeof options === 'string'
122
+ ? { field: options }
123
+ : !options
124
+ ? {}
125
+ : options);
126
+ return Field(() => undefined, {
127
+ ...op,
128
+ serverExpression: () => undefined,
129
+ //@ts-ignore
130
+ [relationInfoMember]: {
131
+ //field,
132
+ toType: toEntityType,
133
+ type: 'toOne',
134
+ },
135
+ });
136
+ }
137
+ }
138
+ /**Decorates fields that should be used as fields.
139
+ * for more info see: [Field Types](https://remult.dev/docs/field-types.html)
140
+ *
141
+ * FieldOptions can be set in two ways:
142
+ * @example
143
+ * // as an object
144
+ * @Fields.string({ includeInApi:false })
145
+ * title='';
146
+ * @example
147
+ * // as an arrow function that receives `remult` as a parameter
148
+ * @Fields.string((options,remult) => options.includeInApi = true)
149
+ * title='';
150
+ */
151
+ export function Field(valueType, ...options) {
152
+ // import ANT!!!! if you call this in another decorator, make sure to set It's return type correctly with the | undefined
153
+ return (target, context, c) => {
154
+ const key = typeof context === 'string' ? context : context.name.toString();
155
+ let factory = (remult) => {
156
+ let r = buildOptions(options, remult);
157
+ if (!r.valueType && valueType) {
158
+ r.valueType = valueType();
159
+ }
160
+ if (!r.key) {
161
+ r.key = key;
162
+ }
163
+ if (!r.dbName)
164
+ r.dbName = r.key;
165
+ let type = r.valueType;
166
+ if (!type) {
167
+ type = Reflect.getMetadata('design:type', target, key);
168
+ r.valueType = type;
169
+ }
170
+ if (!r.target)
171
+ r.target = target;
172
+ return r;
173
+ };
174
+ checkTarget(target);
175
+ let names = columnsOfType.get(target.constructor);
176
+ if (!names) {
177
+ names = [];
178
+ columnsOfType.set(target.constructor, names);
179
+ }
180
+ let set = names.find((x) => x.key == key);
181
+ if (!set)
182
+ names.push({
183
+ key,
184
+ settings: factory,
185
+ });
186
+ else {
187
+ let prev = set.settings;
188
+ set.settings = (c) => {
189
+ let prevO = prev(c);
190
+ let curr = factory(c);
191
+ return Object.assign(prevO, curr);
192
+ };
193
+ }
194
+ };
195
+ }
196
+ export function checkTarget(target) {
197
+ if (!target)
198
+ throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
199
+ }
@@ -0,0 +1,4 @@
1
+ import { EntityBase } from './RepositoryImplementation';
2
+ export declare class IdEntity extends EntityBase {
3
+ id: string;
4
+ }
@@ -0,0 +1,10 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Fields } from './Fields';
3
+ import { EntityBase } from './RepositoryImplementation';
4
+ export class IdEntity extends EntityBase {
5
+ id;
6
+ }
7
+ __decorate([
8
+ Fields.uuid(),
9
+ __metadata("design:type", String)
10
+ ], IdEntity.prototype, "id", void 0);
@@ -3,23 +3,27 @@ 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, Subscribable } from './remult3';
6
+ import type { ControllerRef, EntityFilter, EntityMetadata, EntityOrderBy, EntityRef, FieldRef, FieldsMetadata, FieldsRef, FindFirstOptions, FindFirstOptionsBase, FindOptions, IdMetadata, LiveQuery, OmitEB, QueryOptions, QueryResult, Repository, RepositoryRelations, 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';
11
13
  export declare class RepositoryImplementation<entityType> implements Repository<entityType> {
12
14
  private entity;
13
15
  remult: Remult;
14
16
  private dataProvider;
15
- createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
16
17
  private _info;
18
+ private defaultFindOptions?;
19
+ createAfterFilter(orderBy: EntityOrderBy<entityType>, lastRow: entityType): Promise<EntityFilter<entityType>>;
20
+ relations(item: entityType): RepositoryRelations<entityType>;
17
21
  private __edp;
18
22
  private get edp();
19
- constructor(entity: ClassType<entityType>, remult: Remult, dataProvider: DataProvider);
23
+ constructor(entity: ClassType<entityType>, remult: Remult, dataProvider: DataProvider, _info: EntityFullInfo<entityType>, defaultFindOptions?: FindOptions<entityType>);
20
24
  idCache: Map<any, any>;
21
- getCachedById(id: any): entityType;
22
- getCachedByIdAsync(id: any): Promise<entityType>;
25
+ getCachedById(id: any, doNotLoadIfNotFound: boolean): entityType;
26
+ getCachedByIdAsync(id: any, doNotLoadIfNotFound: boolean): Promise<entityType>;
23
27
  addToCache(item: entityType): void;
24
28
  get metadata(): EntityMetadata<entityType>;
25
29
  listeners: entityEventListener<entityType>[];
@@ -46,6 +50,7 @@ export declare class RepositoryImplementation<entityType> implements Repository<
46
50
  save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
47
51
  save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
48
52
  liveQuery(options?: FindOptions<entityType>): LiveQuery<entityType>;
53
+ rawFind(options: FindOptions<entityType>, skipOrderByAndLimit: boolean, loader: RelationLoader): Promise<Awaited<entityType>[]>;
49
54
  find(options: FindOptions<entityType>, skipOrderByAndLimit?: boolean): Promise<entityType[]>;
50
55
  buildEntityDataProviderFindOptions(options: FindOptions<entityType>): Promise<EntityDataProviderFindOptions>;
51
56
  fromJsonArray(jsonItems: any[], load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[]): Promise<Awaited<entityType>[]>;
@@ -218,28 +223,7 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
218
223
  caption: string;
219
224
  }
220
225
  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
- }
239
226
  export declare function isAutoIncrement(f: FieldMetadata): boolean;
240
- export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
241
- maxLength?: number;
242
- }
243
227
  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;
244
228
  export interface ValueListFieldOptions<entityType, valueType> extends FieldOptions<entityType, valueType> {
245
229
  getValues?: () => valueType[];
@@ -277,26 +261,9 @@ export interface ClassDecoratorContextStub<Class extends new (...args: any) => a
277
261
  readonly name: string | undefined;
278
262
  addInitializer(initializer: (this: Class) => void): void;
279
263
  }
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;
294
264
  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>;
295
266
  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
- }
300
267
  export declare class EntityBase {
301
268
  get _(): EntityRef<this>;
302
269
  save(): Promise<this>;
@@ -305,9 +272,6 @@ export declare class EntityBase {
305
272
  isNew(): boolean;
306
273
  get $(): FieldsRef<this>;
307
274
  }
308
- export declare class IdEntity extends EntityBase {
309
- id: string;
310
- }
311
275
  export declare class ControllerBase {
312
276
  protected remult: Remult;
313
277
  constructor(remult?: Remult);
@@ -328,5 +292,4 @@ export declare function getEntityMetadata<entityType>(entity: EntityMetadataOver
328
292
  export declare function getRepository<entityType>(entity: RepositoryOverloads<entityType>): Repository<entityType>;
329
293
  export type EntityMetadataOverloads<entityType> = Repository<entityType> | EntityMetadata<entityType> | ClassType<entityType>;
330
294
  export type RepositoryOverloads<entityType> = Repository<entityType> | ClassType<entityType>;
331
- export declare function checkTarget(target: any): void;
332
295
  export {};