remult 0.21.1-exp.0 → 0.21.1-exp.2

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 (41) hide show
  1. package/esm/remult-knex/index.d.ts +1 -1
  2. package/esm/remult-knex/index.js +1 -1
  3. package/esm/server/expressBridge.d.ts +0 -9
  4. package/esm/server/expressBridge.js +1 -33
  5. package/esm/server/initAsyncHooks.js +1 -1
  6. package/esm/src/column.d.ts +4 -0
  7. package/esm/src/column.js +10 -0
  8. package/esm/src/context.d.ts +12 -0
  9. package/esm/src/context.js +43 -2
  10. package/esm/src/data-interfaces.d.ts +1 -1
  11. package/esm/src/data-providers/rest-data-provider.d.ts +1 -1
  12. package/esm/src/data-providers/rest-data-provider.js +1 -1
  13. package/esm/src/remult-proxy.js +2 -1
  14. package/esm/src/remult3/RepositoryImplementation.d.ts +4 -2
  15. package/esm/src/remult3/RepositoryImplementation.js +51 -22
  16. package/esm/src/remult3/remult3.d.ts +4 -1
  17. package/esm/src/server-action.d.ts +1 -1
  18. package/esm/src/server-action.js +3 -3
  19. package/esm/src/tests/testHelper.spec.d.ts +1 -1
  20. package/esm/src/tests/testHelper.spec.js +1 -1
  21. package/package.json +2 -2
  22. package/remult-knex/index.d.ts +1 -1
  23. package/server/expressBridge.d.ts +0 -9
  24. package/server/expressBridge.js +4 -36
  25. package/server/initAsyncHooks.js +2 -2
  26. package/src/column.d.ts +4 -0
  27. package/src/column.js +9 -0
  28. package/src/context.d.ts +12 -0
  29. package/src/context.js +43 -2
  30. package/src/data-interfaces.d.ts +1 -1
  31. package/src/data-providers/rest-data-provider.d.ts +1 -1
  32. package/src/data-providers/rest-data-provider.js +1 -1
  33. package/src/remult-proxy.js +7 -7
  34. package/src/remult3/RepositoryImplementation.d.ts +4 -2
  35. package/src/remult3/RepositoryImplementation.js +67 -43
  36. package/src/remult3/remult3.d.ts +4 -1
  37. package/src/server-action.d.ts +1 -1
  38. package/src/server-action.js +2 -2
  39. package/src/tests/testHelper.spec.d.ts +1 -1
  40. package/src/tests/testHelper.spec.js +1 -1
  41. package/projects/core/package.json +0 -153
@@ -11,7 +11,7 @@ export declare class KnexDataProvider implements DataProvider {
11
11
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
12
12
  static rawFilter(build: CustomKnexFilterBuilderFunction): EntityFilter<any>;
13
13
  static filterToRaw<entityType>(entity: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>): Promise<(knex: any) => void>;
14
- supportsRawFilter?: boolean;
14
+ isProxy?: boolean;
15
15
  ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
16
16
  }
17
17
  export type CustomKnexFilterBuilderFunction = () => Promise<(builder: Knex.QueryBuilder) => void>;
@@ -53,7 +53,7 @@ export class KnexDataProvider {
53
53
  let r = await b.resolveWhere();
54
54
  return knex => r.forEach(y => y(knex));
55
55
  }
56
- supportsRawFilter;
56
+ isProxy;
57
57
  async ensureSchema(entities) {
58
58
  var sb = new KnexSchemaBuilder(this.knex);
59
59
  await sb.ensureSchema(entities);
@@ -91,15 +91,6 @@ export interface GenericResponse {
91
91
  status(statusCode: number): GenericResponse;
92
92
  end(): any;
93
93
  }
94
- export declare class RemultAsyncLocalStorage {
95
- private readonly remultObjectStorage;
96
- static enable(): void;
97
- static disable(): void;
98
- constructor(remultObjectStorage: import('async_hooks').AsyncLocalStorage<Remult>);
99
- run(remult: Remult, callback: VoidFunction): void;
100
- getRemult(): Remult;
101
- static instance: RemultAsyncLocalStorage;
102
- }
103
94
  export interface queuedJobInfo {
104
95
  info: queuedJobInfoResponse;
105
96
  userId: string;
@@ -1,9 +1,8 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Action, actionInfo, classBackendMethodsArray, serverActionField } from '../src/server-action';
3
3
  import { DataApi, serializeError } from '../src/data-api';
4
- import { allEntities, Remult } from '../src/context';
4
+ import { allEntities, Remult, RemultAsyncLocalStorage } from '../src/context';
5
5
  import { Entity, Fields, getEntityKey, IdEntity } from '../src/remult3';
6
- import { remult } from '../src/remult-proxy';
7
6
  import { LiveQueryPublisher, InMemoryLiveQueryStorage } from '../src/live-query/SubscriptionServer';
8
7
  import { liveQueryKeepAliveRoute, streamUrl } from '../src/live-query/SubscriptionChannel';
9
8
  import { initDataProvider } from './initDataProvider';
@@ -80,37 +79,6 @@ export function createRemultServerCore(options, serverCoreOptions) {
80
79
  return bridge;
81
80
  }
82
81
  ;
83
- export class RemultAsyncLocalStorage {
84
- remultObjectStorage;
85
- static enable() {
86
- remult.remultFactory = () => {
87
- const r = RemultAsyncLocalStorage.instance.getRemult();
88
- if (r)
89
- return r;
90
- else
91
- throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
92
- };
93
- }
94
- static disable() {
95
- remult.resetFactory();
96
- }
97
- constructor(remultObjectStorage) {
98
- this.remultObjectStorage = remultObjectStorage;
99
- }
100
- run(remult, callback) {
101
- if (this.remultObjectStorage)
102
- this.remultObjectStorage.run(remult, callback);
103
- else
104
- callback();
105
- }
106
- getRemult() {
107
- if (!this.remultObjectStorage) {
108
- throw new Error("can't use static remult in this environment, `async_hooks` were not initialized");
109
- }
110
- return this.remultObjectStorage.getStore();
111
- }
112
- static instance = new RemultAsyncLocalStorage(undefined);
113
- }
114
82
  /* @internal*/
115
83
  export class RemultServerImplementation {
116
84
  queue;
@@ -1,5 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'async_hooks';
2
- import { RemultAsyncLocalStorage } from './expressBridge';
2
+ import { RemultAsyncLocalStorage } from '../src/context';
3
3
  let init = false;
4
4
  export function initAsyncHooks() {
5
5
  if (init)
@@ -31,9 +31,13 @@ export declare class CompoundIdField implements FieldMetadata<string> {
31
31
  export declare class LookupColumn<T> {
32
32
  private repository;
33
33
  id: idType<T>;
34
+ toJson(): any;
34
35
  setId(val: any): void;
35
36
  waitLoadOf(id: any): Promise<T>;
36
37
  get(id: any): any;
38
+ storedItem: {
39
+ item: T;
40
+ };
37
41
  set(item: T): void;
38
42
  constructor(repository: RepositoryImplementation<T>, id: idType<T>);
39
43
  get item(): T;
package/esm/src/column.js CHANGED
@@ -79,6 +79,11 @@ export class CompoundIdField {
79
79
  export class LookupColumn {
80
80
  repository;
81
81
  id;
82
+ toJson() {
83
+ if (this.item === null)
84
+ return null;
85
+ return this.repository.toJson(this.item);
86
+ }
82
87
  setId(val) {
83
88
  if (this.repository.metadata.idMetadata.field.valueType == Number)
84
89
  val = +val;
@@ -94,7 +99,9 @@ export class LookupColumn {
94
99
  return null;
95
100
  return this.repository.getCachedById(id);
96
101
  }
102
+ storedItem;
97
103
  set(item) {
104
+ this.storedItem = undefined;
98
105
  if (item) {
99
106
  if (typeof item === "string" || typeof item === "number")
100
107
  this.id = item;
@@ -105,6 +112,7 @@ export class LookupColumn {
105
112
  this.id = eo.getId();
106
113
  }
107
114
  else {
115
+ this.storedItem = { item };
108
116
  this.id = item[this.repository.metadata.idMetadata.field.key];
109
117
  }
110
118
  }
@@ -121,6 +129,8 @@ export class LookupColumn {
121
129
  this.id = id;
122
130
  }
123
131
  get item() {
132
+ if (this.storedItem)
133
+ return this.storedItem.item;
124
134
  return this.get(this.id);
125
135
  }
126
136
  async waitLoad() {
@@ -4,6 +4,15 @@ import { ClassType } from "../classType";
4
4
  import type { SubscriptionServer } from "./live-query/SubscriptionServer";
5
5
  import { ExternalHttpProvider } from "./buildRestDataProvider";
6
6
  import { SubscriptionClient, Unsubscribe } from "./live-query/SubscriptionChannel";
7
+ export declare class RemultAsyncLocalStorage {
8
+ private readonly remultObjectStorage;
9
+ static enable(): void;
10
+ static disable(): void;
11
+ constructor(remultObjectStorage: import('async_hooks').AsyncLocalStorage<Remult>);
12
+ run(remult: Remult, callback: VoidFunction): void;
13
+ getRemult(): Remult;
14
+ static instance: RemultAsyncLocalStorage;
15
+ }
7
16
  export declare function isBackend(): boolean;
8
17
  export declare class Remult {
9
18
  /**Return's a `Repository` of the specific entity type
@@ -59,6 +68,9 @@ export declare class Remult {
59
68
  readonly context: RemultContext;
60
69
  /** The api client that will be used by `remult` to perform calls to the `api` */
61
70
  apiClient: ApiClient;
71
+ static run<T>(callback: () => T, options: {
72
+ dataProvider: DataProvider;
73
+ }): T;
62
74
  }
63
75
  export type GetArguments<T> = T extends (...args: infer FirstArgument) => any ? FirstArgument : never;
64
76
  export interface RemultContext {
@@ -3,10 +3,41 @@ import { RestDataProvider } from './data-providers/rest-data-provider';
3
3
  import { RepositoryImplementation } from "./remult3/RepositoryImplementation";
4
4
  import { LiveQueryClient } from "./live-query/LiveQueryClient";
5
5
  import { SseSubscriptionClient } from "./live-query/SseSubscriptionClient";
6
- import { RemultProxy } from "./remult-proxy";
6
+ import { RemultProxy, remult } from "./remult-proxy";
7
7
  import { buildRestDataProvider, isExternalHttpProvider } from "./buildRestDataProvider";
8
+ export class RemultAsyncLocalStorage {
9
+ remultObjectStorage;
10
+ static enable() {
11
+ remult.remultFactory = () => {
12
+ const r = RemultAsyncLocalStorage.instance.getRemult();
13
+ if (r)
14
+ return r;
15
+ else
16
+ throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
17
+ };
18
+ }
19
+ static disable() {
20
+ remult.resetFactory();
21
+ }
22
+ constructor(remultObjectStorage) {
23
+ this.remultObjectStorage = remultObjectStorage;
24
+ }
25
+ run(remult, callback) {
26
+ if (this.remultObjectStorage)
27
+ this.remultObjectStorage.run(remult, callback);
28
+ else
29
+ callback();
30
+ }
31
+ getRemult() {
32
+ if (!this.remultObjectStorage) {
33
+ throw new Error("can't use static remult in this environment, `async_hooks` were not initialized");
34
+ }
35
+ return this.remultObjectStorage.getStore();
36
+ }
37
+ static instance = new RemultAsyncLocalStorage(undefined);
38
+ }
8
39
  export function isBackend() {
9
- return actionInfo.runningOnServer;
40
+ return actionInfo.runningOnServer || !remult.dataProvider.isProxy;
10
41
  }
11
42
  export class Remult {
12
43
  /**Return's a `Repository` of the specific entity type
@@ -144,6 +175,16 @@ export class Remult {
144
175
  url: '/api',
145
176
  subscriptionClient: new SseSubscriptionClient()
146
177
  };
178
+ static run(callback, options) {
179
+ const remult = new Remult();
180
+ if (options.dataProvider)
181
+ remult.dataProvider = options.dataProvider;
182
+ let r;
183
+ RemultAsyncLocalStorage.instance.run(remult, () => {
184
+ r = callback();
185
+ });
186
+ return r;
187
+ }
147
188
  }
148
189
  RemultProxy.defaultRemult = new Remult();
149
190
  ;
@@ -4,8 +4,8 @@ import { EntityMetadata, OmitEB } from './remult3';
4
4
  export interface DataProvider {
5
5
  getEntityDataProvider(entity: EntityMetadata): EntityDataProvider;
6
6
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
7
- supportsRawFilter?: boolean;
8
7
  ensureSchema?(entities: EntityMetadata[]): Promise<void>;
8
+ isProxy?: boolean;
9
9
  }
10
10
  export interface Storage {
11
11
  ensureSchema(): Promise<void>;
@@ -8,7 +8,7 @@ export declare class RestDataProvider implements DataProvider {
8
8
  constructor(apiProvider: () => ApiClient);
9
9
  getEntityDataProvider(entity: EntityMetadata): RestEntityDataProvider;
10
10
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
11
- supportsRawFilter: boolean;
11
+ isProxy: boolean;
12
12
  }
13
13
  export declare class RestEntityDataProvider implements EntityDataProvider {
14
14
  private url;
@@ -20,7 +20,7 @@ export class RestDataProvider {
20
20
  async transaction(action) {
21
21
  throw new Error("Method not implemented.");
22
22
  }
23
- supportsRawFilter = true;
23
+ isProxy = true;
24
24
  }
25
25
  //@internal
26
26
  export function findOptionsToJson(options, meta) {
@@ -74,7 +74,8 @@ export class RemultProxy {
74
74
  find: (...args2) => self.remultFactory().repo(...args).find(...args2),
75
75
  findFirst: (...args2) => self.remultFactory().repo(...args).findFirst(...args2),
76
76
  findId: (a, b) => self.remultFactory().repo(...args).findId(a, b),
77
- fromJson: (...args2) => self.remultFactory().repo(...args).fromJson(...args2),
77
+ toJson: (json) => self.remultFactory().repo(...args).toJson(json),
78
+ fromJson: (item, isNew) => self.remultFactory().repo(...args).fromJson(item, isNew),
78
79
  getEntityRef: (...args2) => self.remultFactory().repo(...args).getEntityRef(...args2),
79
80
  insert: (args2) => self.remultFactory().repo(...args).insert(args2),
80
81
  liveQuery: (...args2) => self.remultFactory().repo(...args).liveQuery(...args2),
@@ -51,7 +51,8 @@ export declare class RepositoryImplementation<entityType> implements Repository<
51
51
  fromJsonArray(jsonItems: any[], load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[]): Promise<Awaited<entityType>[]>;
52
52
  private loadManyToOneForManyRows;
53
53
  private mapRawDataToResult;
54
- fromJson(json: any, newRow?: boolean): Promise<entityType>;
54
+ toJson(item: entityType | entityType[]): any;
55
+ fromJson(json: any, newRow?: boolean): any;
55
56
  count(where?: EntityFilter<entityType>): Promise<number>;
56
57
  private cache;
57
58
  findFirst(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>, skipOrderByAndLimit?: boolean): Promise<entityType>;
@@ -101,7 +102,7 @@ declare abstract class rowHelperBase<T> {
101
102
  validate(): Promise<ErrorInfo<any>>;
102
103
  __validateEntity(): Promise<void>;
103
104
  __performColumnAndEntityValidations(): Promise<void>;
104
- toApiJson(): any;
105
+ toApiJson(includeRelatedEntities?: boolean): any;
105
106
  _updateEntityBasedOnApi(body: any): Promise<void>;
106
107
  }
107
108
  export declare class rowHelperImplementation<T> extends rowHelperBase<T> implements EntityRef<T> {
@@ -214,6 +215,7 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
214
215
  get apiReadAllowed(): boolean;
215
216
  apiDeleteAllowed(item: T): boolean;
216
217
  apiInsertAllowed(item: T): boolean;
218
+ getEntityMetadataWithoutBreakingTheEntity(item: T): EntityRef<T>;
217
219
  dbNamePromise: Promise<string>;
218
220
  getDbName(): Promise<string>;
219
221
  idMetadata: IdMetadata<T>;
@@ -4,7 +4,7 @@ import { allEntities, Remult, isBackend, queryConfig as queryConfig, setControll
4
4
  import { entityFilterToJson, Filter } from "../filter/filter-interfaces";
5
5
  import { Sort } from "../sort";
6
6
  import { v4 as uuid } from 'uuid';
7
- import cuid from 'cuid';
7
+ import { createId } from '@paralleldrive/cuid2';
8
8
  import { ValueConverters } from "../valueConverters";
9
9
  import { filterHelper } from "../filter/filter-interfaces";
10
10
  import { assign } from "../../assign";
@@ -168,7 +168,9 @@ export class RepositoryImplementation {
168
168
  }
169
169
  async validate(entity, ...fields) {
170
170
  {
171
- let ref = this.getEntityRef(entity);
171
+ let ref = getEntityRef(entity, false);
172
+ if (!ref)
173
+ ref = this.getEntityRef({ ...entity });
172
174
  if (!fields || fields.length === 0) {
173
175
  return await ref.validate();
174
176
  }
@@ -331,22 +333,40 @@ export class RepositoryImplementation {
331
333
  helper.saveOriginalData();
332
334
  return x;
333
335
  }
334
- // TODO2 - consider replacing with fromJsonArray - also consider having a TOJSON for similar cases
335
- async fromJson(json, newRow) {
336
- let obj = {};
336
+ toJson(item) {
337
+ if (Array.isArray(item))
338
+ return item.map(x => this.toJson(x));
339
+ return this.getEntityRef(item).toApiJson(true);
340
+ }
341
+ fromJson(json, newRow) {
342
+ if (json === null || json === undefined)
343
+ return json;
344
+ if (Array.isArray(json))
345
+ return json.map(item => this.fromJson(item));
346
+ let result = new this.entity(this.remult);
337
347
  for (const col of this.fieldsOf(json)) {
338
- if (json[col.key] !== undefined) {
339
- obj[col.key] = col.valueConverter.fromJson(json[col.key]);
348
+ let ei = getEntitySettings(col.valueType, false);
349
+ if (ei) {
350
+ result[col.key] = this.remult.repo(col.valueType).fromJson(json[col.key]);
351
+ }
352
+ else {
353
+ if (json[col.key] !== undefined) {
354
+ result[col.key] = col.valueConverter.fromJson(json[col.key]);
355
+ }
340
356
  }
341
357
  }
358
+ this.fixTypes(result);
342
359
  if (newRow) {
343
- let r = this.create();
344
- let helper = this.getEntityRef(r);
345
- await helper.loadDataFrom(obj);
346
- return r;
360
+ return this.create(result);
361
+ }
362
+ else {
363
+ let row = new rowHelperImplementation(this._info, result, this, this.edp, this.remult, false);
364
+ Object.defineProperty(result, entityMember, {
365
+ get: () => row
366
+ });
367
+ row.saveOriginalData();
368
+ return result;
347
369
  }
348
- else
349
- return this.mapRawDataToResult(obj, undefined);
350
370
  }
351
371
  async count(where) {
352
372
  return this.edp.count(await this.translateWhereToFilter(where));
@@ -462,7 +482,7 @@ export class RepositoryImplementation {
462
482
  };
463
483
  }
464
484
  let r = await Filter.fromEntityFilter(this.metadata, where);
465
- if (r && !this.dataProvider.supportsRawFilter) {
485
+ if (r && !this.dataProvider.isProxy) {
466
486
  r = await Filter.translateCustomWhere(r, this.metadata, this.remult);
467
487
  }
468
488
  return r;
@@ -757,14 +777,17 @@ class rowHelperBase {
757
777
  }
758
778
  async __performColumnAndEntityValidations() {
759
779
  }
760
- toApiJson() {
780
+ toApiJson(includeRelatedEntities = false) {
761
781
  let result = {};
762
782
  for (const col of this.columnsInfo) {
763
783
  if (!this.remult || col.includeInApi === undefined || this.remult.isAllowed(col.includeInApi)) {
764
784
  let val;
765
785
  let lu = this.lookups.get(col.key);
766
786
  if (lu)
767
- val = lu.id;
787
+ if (includeRelatedEntities)
788
+ val = lu.toJson();
789
+ else
790
+ val = lu.id;
768
791
  else {
769
792
  val = this.instance[col.key];
770
793
  if (!this.remult) {
@@ -1289,7 +1312,7 @@ export class columnDefsImpl {
1289
1312
  return this.remult.isAllowedForInstance(item, this.options.allowApiUpdate);
1290
1313
  }
1291
1314
  displayValue(item) {
1292
- return this.remult.repo(this.entityDefs.entityType).getEntityRef(item).fields.find(this.key).displayValue;
1315
+ return this.entityDefs.getEntityMetadataWithoutBreakingTheEntity(item).fields.find(this.key).displayValue;
1293
1316
  }
1294
1317
  get includedInApi() {
1295
1318
  if (this.options.includeInApi === undefined)
@@ -1415,7 +1438,7 @@ class EntityFullInfo {
1415
1438
  apiUpdateAllowed(item) {
1416
1439
  if (this.options.allowApiUpdate === undefined)
1417
1440
  return false;
1418
- return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiUpdate) : this.remult.repo(this.entityType).getEntityRef(item).apiUpdateAllowed;
1441
+ return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiUpdate) : this.getEntityMetadataWithoutBreakingTheEntity(item).apiUpdateAllowed;
1419
1442
  }
1420
1443
  get apiReadAllowed() {
1421
1444
  if (this.options.allowApiRead === undefined)
@@ -1425,12 +1448,18 @@ class EntityFullInfo {
1425
1448
  apiDeleteAllowed(item) {
1426
1449
  if (this.options.allowApiDelete === undefined)
1427
1450
  return false;
1428
- return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiDelete) : this.remult.repo(this.entityType).getEntityRef(item).apiDeleteAllowed;
1451
+ return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiDelete) : this.getEntityMetadataWithoutBreakingTheEntity(item).apiDeleteAllowed;
1429
1452
  }
1430
1453
  apiInsertAllowed(item) {
1431
1454
  if (this.options.allowApiUpdate === undefined)
1432
1455
  return false;
1433
- return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiInsert) : this.remult.repo(this.entityType).getEntityRef(item).apiInsertAllowed;
1456
+ return !item ? this.remult.isAllowedForInstance(undefined, this.options.allowApiInsert) : this.getEntityMetadataWithoutBreakingTheEntity(item).apiInsertAllowed;
1457
+ }
1458
+ getEntityMetadataWithoutBreakingTheEntity(item) {
1459
+ let result = getEntityRef(item, false);
1460
+ if (result)
1461
+ return result;
1462
+ return this.remult.repo(this.entityType).getEntityRef({ ...item });
1434
1463
  }
1435
1464
  dbNamePromise;
1436
1465
  getDbName() {
@@ -1570,10 +1599,10 @@ export class Fields {
1570
1599
  static cuid(...options) {
1571
1600
  return Field(() => String, {
1572
1601
  allowApiUpdate: false,
1573
- defaultValue: () => cuid(),
1602
+ defaultValue: () => createId(),
1574
1603
  saving: (_, r) => {
1575
1604
  if (!r.value)
1576
- r.value = cuid();
1605
+ r.value = createId();
1577
1606
  }
1578
1607
  }, ...options);
1579
1608
  }
@@ -236,8 +236,11 @@ export interface Repository<entityType> {
236
236
  delete(item: Partial<OmitEB<entityType>>): Promise<void>;
237
237
  /** Creates an instance of an item. It'll not be saved to the data source unless `save` or `insert` will be called for that item */
238
238
  create(item?: Partial<OmitEB<entityType>>): entityType;
239
+ toJson(item: entityType[]): any[];
240
+ toJson(item: entityType): any;
239
241
  /** Translates a json object to an item instance */
240
- fromJson(x: any, isNew?: boolean): Promise<entityType>;
242
+ fromJson(x: any[], isNew?: boolean): entityType[];
243
+ fromJson(x: any, isNew?: boolean): entityType;
241
244
  /** returns an `entityRef` for an item returned by `create`, `find` etc... */
242
245
  getEntityRef(item: entityType): EntityRef<entityType>;
243
246
  /** Provides information about the fields of the Repository's entity
@@ -26,7 +26,7 @@ export declare class ForbiddenError extends Error {
26
26
  export declare class myServerAction extends Action<inArgs, result> {
27
27
  private types;
28
28
  private options;
29
- private originalMethod;
29
+ originalMethod: (args: any[]) => any;
30
30
  constructor(name: string, types: any[], options: BackendMethodOptions<any>, originalMethod: (args: any[]) => any);
31
31
  protected execute(info: inArgs, remult: Remult, res: DataApiResponse): Promise<result>;
32
32
  }
@@ -1,5 +1,5 @@
1
1
  import 'reflect-metadata';
2
- import { Remult, allEntities, classHelpers, ClassHelper, setControllerSettings, doTransaction } from './context';
2
+ import { Remult, allEntities, classHelpers, ClassHelper, setControllerSettings, doTransaction, isBackend } from './context';
3
3
  import { buildRestDataProvider } from "./buildRestDataProvider";
4
4
  import { SqlDatabase } from './data-providers/sql-database';
5
5
  import { getEntityRef, decorateColumnSettings, getEntitySettings, getControllerRef } from './remult3';
@@ -140,7 +140,7 @@ export function BackendMethod(options) {
140
140
  return (await serverAction.run({ args }, url, http)).data;
141
141
  };
142
142
  result = async function (...args) {
143
- if (!actionInfo.runningOnServer) {
143
+ if (!isBackend()) {
144
144
  return await serverAction.doWork(args, undefined);
145
145
  }
146
146
  else
@@ -295,7 +295,7 @@ export function BackendMethod(options) {
295
295
  }
296
296
  };
297
297
  result = async function (...args) {
298
- if (!actionInfo.runningOnServer) {
298
+ if (!isBackend()) {
299
299
  let self = this;
300
300
  return serverAction.doWork(args, self);
301
301
  }
@@ -31,6 +31,6 @@ export declare class MockRestDataProvider implements DataProvider {
31
31
  constructor(remult: Remult);
32
32
  getEntityDataProvider(metadata: EntityMetadata<any>): EntityDataProvider;
33
33
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
34
- supportsRawFilter: boolean;
34
+ isProxy: boolean;
35
35
  }
36
36
  export declare function createMockHttpDataProvider(dataApi: DataApi<any>): import("../data-interfaces").RestDataProviderHttpProvider;
@@ -163,7 +163,7 @@ export class MockRestDataProvider {
163
163
  transaction(action) {
164
164
  throw new Error('Method not implemented.');
165
165
  }
166
- supportsRawFilter = true;
166
+ isProxy = true;
167
167
  }
168
168
  export function createMockHttpDataProvider(dataApi) {
169
169
  return new HttpProviderBridgeToRestDataProviderHttpProvider({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.21.1-exp.0",
3
+ "version": "0.21.1-exp.2",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
@@ -15,8 +15,8 @@
15
15
  "name": "Noam Honig"
16
16
  },
17
17
  "dependencies": {
18
+ "@paralleldrive/cuid2": "^2.2.1",
18
19
  "uuid": "^8.3.2",
19
- "cuid": "^2.1.8",
20
20
  "reflect-metadata": "^0.1.13",
21
21
  "tslib": "^2.3.1"
22
22
  },
@@ -11,7 +11,7 @@ export declare class KnexDataProvider implements DataProvider {
11
11
  transaction(action: (dataProvider: DataProvider) => Promise<void>): Promise<void>;
12
12
  static rawFilter(build: CustomKnexFilterBuilderFunction): EntityFilter<any>;
13
13
  static filterToRaw<entityType>(entity: RepositoryOverloads<entityType>, condition: EntityFilter<entityType>): Promise<(knex: any) => void>;
14
- supportsRawFilter?: boolean;
14
+ isProxy?: boolean;
15
15
  ensureSchema(entities: EntityMetadata<any>[]): Promise<void>;
16
16
  }
17
17
  export type CustomKnexFilterBuilderFunction = () => Promise<(builder: Knex.QueryBuilder) => void>;
@@ -91,15 +91,6 @@ export interface GenericResponse {
91
91
  status(statusCode: number): GenericResponse;
92
92
  end(): any;
93
93
  }
94
- export declare class RemultAsyncLocalStorage {
95
- private readonly remultObjectStorage;
96
- static enable(): void;
97
- static disable(): void;
98
- constructor(remultObjectStorage: import('async_hooks').AsyncLocalStorage<Remult>);
99
- run(remult: Remult, callback: VoidFunction): void;
100
- getRemult(): Remult;
101
- static instance: RemultAsyncLocalStorage;
102
- }
103
94
  export interface queuedJobInfo {
104
95
  info: queuedJobInfoResponse;
105
96
  userId: string;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JobsInQueueEntity = exports.EntityQueueStorage = exports.RemultServerImplementation = exports.RemultAsyncLocalStorage = exports.createRemultServerCore = void 0;
3
+ exports.JobsInQueueEntity = exports.EntityQueueStorage = exports.RemultServerImplementation = exports.createRemultServerCore = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var server_action_1 = require("../src/server-action");
6
6
  var data_api_1 = require("../src/data-api");
7
7
  var context_1 = require("../src/context");
8
8
  var remult3_1 = require("../src/remult3");
9
- var remult_proxy_1 = require("../src/remult-proxy");
10
9
  var SubscriptionServer_1 = require("../src/live-query/SubscriptionServer");
11
10
  var SubscriptionChannel_1 = require("../src/live-query/SubscriptionChannel");
12
11
  var initDataProvider_1 = require("./initDataProvider");
@@ -32,7 +31,7 @@ function createRemultServerCore(options, serverCoreOptions) {
32
31
  var dataProvider = (0, initDataProvider_1.initDataProvider)(options.dataProvider);
33
32
  if (options.ensureSchema === undefined)
34
33
  options.ensureSchema = true;
35
- RemultAsyncLocalStorage.enable();
34
+ context_1.RemultAsyncLocalStorage.enable();
36
35
  var entitiesMetaData = [];
37
36
  dataProvider = dataProvider.then(function (dp) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
38
37
  var remult;
@@ -42,7 +41,7 @@ function createRemultServerCore(options, serverCoreOptions) {
42
41
  case 0:
43
42
  remult = new context_1.Remult(dp);
44
43
  return [4 /*yield*/, new Promise(function (res) {
45
- RemultAsyncLocalStorage.instance.run(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
44
+ context_1.RemultAsyncLocalStorage.instance.run(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
46
45
  var started_1, startConsoleLog, _a, _b, item, e_1_1;
47
46
  var e_1, _c;
48
47
  return tslib_1.__generator(this, function (_d) {
@@ -131,37 +130,6 @@ function createRemultServerCore(options, serverCoreOptions) {
131
130
  }
132
131
  exports.createRemultServerCore = createRemultServerCore;
133
132
  ;
134
- var RemultAsyncLocalStorage = exports.RemultAsyncLocalStorage = /** @class */ (function () {
135
- function RemultAsyncLocalStorage(remultObjectStorage) {
136
- this.remultObjectStorage = remultObjectStorage;
137
- }
138
- RemultAsyncLocalStorage.enable = function () {
139
- remult_proxy_1.remult.remultFactory = function () {
140
- var r = RemultAsyncLocalStorage.instance.getRemult();
141
- if (r)
142
- return r;
143
- else
144
- throw new Error("remult object was requested outside of a valid context, try running it within initApi or a remult request cycle");
145
- };
146
- };
147
- RemultAsyncLocalStorage.disable = function () {
148
- remult_proxy_1.remult.resetFactory();
149
- };
150
- RemultAsyncLocalStorage.prototype.run = function (remult, callback) {
151
- if (this.remultObjectStorage)
152
- this.remultObjectStorage.run(remult, callback);
153
- else
154
- callback();
155
- };
156
- RemultAsyncLocalStorage.prototype.getRemult = function () {
157
- if (!this.remultObjectStorage) {
158
- throw new Error("can't use static remult in this environment, `async_hooks` were not initialized");
159
- }
160
- return this.remultObjectStorage.getStore();
161
- };
162
- RemultAsyncLocalStorage.instance = new RemultAsyncLocalStorage(undefined);
163
- return RemultAsyncLocalStorage;
164
- }());
165
133
  /* @internal*/
166
134
  var RemultServerImplementation = /** @class */ (function () {
167
135
  function RemultServerImplementation(queue, options, dataProvider, coreOptions, entitiesMetaData) {
@@ -508,7 +476,7 @@ var RemultServerImplementation = /** @class */ (function () {
508
476
  remult.subscriptionServer = this.subscriptionServer;
509
477
  remult.liveQueryStorage = this.liveQueryStorage;
510
478
  return [4 /*yield*/, new Promise(function (res) {
511
- RemultAsyncLocalStorage.instance.run(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
479
+ context_1.RemultAsyncLocalStorage.instance.run(remult, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
512
480
  var _a;
513
481
  return tslib_1.__generator(this, function (_b) {
514
482
  switch (_b.label) {