remult 0.23.0-exp.7 → 0.23.0-exp.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.
Files changed (44) hide show
  1. package/README.md +1 -4
  2. package/esm/internals.d.ts +1 -0
  3. package/esm/server/JsonEntityFileStorage.js +1 -1
  4. package/esm/src/buildRestDataProvider.d.ts +1 -2
  5. package/esm/src/column.d.ts +1 -1
  6. package/esm/src/context.d.ts +1 -1
  7. package/esm/src/context.js +2 -1
  8. package/esm/src/data-interfaces.js +1 -2
  9. package/esm/src/data-providers/array-entity-data-provider.d.ts +1 -1
  10. package/esm/src/data-providers/array-entity-data-provider.js +6 -6
  11. package/esm/src/data-providers/web-sql-data-provider.js +3 -3
  12. package/esm/src/filter/filter-interfaces.d.ts +2 -2
  13. package/esm/src/filter/filter-interfaces.js +2 -3
  14. package/esm/src/live-query/SubscriptionChannel.js +1 -1
  15. package/esm/src/remult3/Fields.d.ts +2 -2
  16. package/esm/src/remult3/Fields.js +3 -1
  17. package/esm/src/remult3/RepositoryImplementation.d.ts +2 -2
  18. package/esm/src/remult3/RepositoryImplementation.js +51 -17
  19. package/esm/src/remult3/getEntityRef.d.ts +1 -1
  20. package/esm/src/remult3/getEntityRef.js +1 -1
  21. package/esm/src/sort.d.ts +3 -3
  22. package/esm/src/sort.js +2 -6
  23. package/internals.d.ts +1 -0
  24. package/package.json +1 -1
  25. package/server/JsonEntityFileStorage.js +1 -1
  26. package/src/buildRestDataProvider.d.ts +1 -2
  27. package/src/column.d.ts +1 -1
  28. package/src/context.d.ts +1 -1
  29. package/src/context.js +2 -1
  30. package/src/data-interfaces.js +1 -2
  31. package/src/data-providers/array-entity-data-provider.d.ts +1 -1
  32. package/src/data-providers/array-entity-data-provider.js +5 -6
  33. package/src/data-providers/web-sql-data-provider.js +3 -3
  34. package/src/filter/filter-interfaces.d.ts +2 -2
  35. package/src/filter/filter-interfaces.js +2 -3
  36. package/src/live-query/SubscriptionChannel.js +1 -1
  37. package/src/remult3/Fields.d.ts +2 -2
  38. package/src/remult3/Fields.js +3 -1
  39. package/src/remult3/RepositoryImplementation.d.ts +2 -2
  40. package/src/remult3/RepositoryImplementation.js +160 -120
  41. package/src/remult3/getEntityRef.d.ts +1 -1
  42. package/src/remult3/getEntityRef.js +2 -1
  43. package/src/sort.d.ts +3 -3
  44. package/src/sort.js +1 -4
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="https://github.com/remult/remult/raw/master/docs/public/logo.png" width="140" height="140">
4
4
  </a>
5
5
  <h1>Remult</h1>
6
- <p>A CRUD framework for full-stack TypeScript</p>
6
+ <p>Full-stack CRUD, simplified, with SSOT TypeScript entities</p>
7
7
  <a href="https://circleci.com/gh/remult/remult/tree/master" rel="nofollow">
8
8
  <img alt="CircleCI" src="https://circleci.com/gh/remult/remult/tree/master.svg?style=shield">
9
9
  </a>
@@ -22,9 +22,6 @@
22
22
  <a href="https://discord.gg/GXHk7ZfuG5" rel="nofollow">
23
23
  <img alt="Join Discord" src="https://badgen.net/discord/online-members/GXHk7ZfuG5?icon=discord&label=Discord"/>
24
24
  </a>
25
- <a href="https://twitter.com/intent/tweet?text=Remult%20-%20open-source%20CRUD%20framework%20for%20full-stack%20TypeScript%0A%0A%40remultjs%0A&url=https%3A%2F%2Fgithub.com%2Fremult%2Fremult">
26
- <img alt="Twitter URL" src="https://img.shields.io/twitter/url?style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Ftext%3DRemult%2520-%2520open-source%2520CRUD%2520framework%2520for%2520full-stack%2520TypeScript%250A%250A%2540remultjs%250A%26url%3Dhttps%253A%252F%252Fgithub.com%252Fremult%252Fremult">
27
- </a>
28
25
  </div>
29
26
 
30
27
  <br/>
@@ -4,3 +4,4 @@ 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';
@@ -8,7 +8,7 @@ export class JsonEntityFileStorage {
8
8
  if (fs.existsSync(fn)) {
9
9
  return fs.readFileSync(fn).toString();
10
10
  }
11
- return undefined;
11
+ return null;
12
12
  }
13
13
  setItem(entityDbName, json) {
14
14
  if (!fs.existsSync(this.folderPath)) {
@@ -1,6 +1,5 @@
1
1
  import type { RestDataProviderHttpProvider } from './data-interfaces';
2
- import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
3
- export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProviderUsingFetch | RestDataProviderHttpProvider;
2
+ export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProvider;
4
3
  export declare function isExternalHttpProvider(item: any): boolean;
5
4
  export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
6
5
  private http;
@@ -8,7 +8,7 @@ export declare class LookupColumn<T> {
8
8
  setId(val: any): void;
9
9
  waitLoadOf(id: any): Promise<T>;
10
10
  get(id: any): any;
11
- storedItem: {
11
+ storedItem?: {
12
12
  item: T;
13
13
  };
14
14
  set(item: T): void;
@@ -15,7 +15,7 @@ export declare class RemultAsyncLocalStorage {
15
15
  }
16
16
  type myAsyncLocalStorage<T> = {
17
17
  run<R>(store: T, callback: (...args: any[]) => R, ...args: any[]): R;
18
- getStore(): T;
18
+ getStore(): T | undefined;
19
19
  };
20
20
  export declare function isBackend(): boolean;
21
21
  export declare class Remult {
@@ -90,7 +90,7 @@ export class Remult {
90
90
  if (typeof roles === 'boolean')
91
91
  return roles;
92
92
  if (typeof roles === 'string')
93
- if (this.user?.roles?.indexOf(roles.toString()) >= 0)
93
+ if (this.user?.roles?.includes(roles.toString()))
94
94
  return true;
95
95
  return false;
96
96
  }
@@ -112,6 +112,7 @@ export class Remult {
112
112
  }
113
113
  else
114
114
  return this.isAllowed(allowed);
115
+ return undefined;
115
116
  }
116
117
  /** The current data provider */
117
118
  dataProvider = new RestDataProvider(() => this.apiClient);
@@ -1,7 +1,5 @@
1
1
  import { Sort } from './sort';
2
2
  export function extractSort(sort) {
3
- if (sort instanceof Sort)
4
- return sort;
5
3
  if (sort instanceof Array) {
6
4
  let r = new Sort();
7
5
  sort.forEach((i) => {
@@ -9,4 +7,5 @@ export function extractSort(sort) {
9
7
  });
10
8
  return r;
11
9
  }
10
+ return sort;
12
11
  }
@@ -4,8 +4,8 @@ import { Filter } from '../filter/filter-interfaces';
4
4
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
5
5
  export declare class ArrayEntityDataProvider implements EntityDataProvider {
6
6
  private entity;
7
- private rows?;
8
7
  static rawFilter(filter: CustomArrayFilter): EntityFilter<any>;
8
+ private rows;
9
9
  constructor(entity: EntityMetadata, rows?: any[]);
10
10
  __names: EntityDbNamesBase;
11
11
  init(): Promise<EntityDbNamesBase>;
@@ -3,7 +3,6 @@ import { dbNamesOf, isDbReadonly, } from '../filter/filter-consumer-bridge-to-sq
3
3
  import { Filter, customDatabaseFilterToken } from '../filter/filter-interfaces';
4
4
  export class ArrayEntityDataProvider {
5
5
  entity;
6
- rows;
7
6
  static rawFilter(filter) {
8
7
  return {
9
8
  [customDatabaseFilterToken]: {
@@ -11,13 +10,13 @@ export class ArrayEntityDataProvider {
11
10
  },
12
11
  };
13
12
  }
13
+ rows;
14
14
  constructor(entity, rows) {
15
15
  this.entity = entity;
16
- this.rows = rows;
17
- if (!rows)
18
- rows = [];
19
- else {
20
- }
16
+ if (rows === undefined)
17
+ this.rows = [];
18
+ else
19
+ this.rows = rows;
21
20
  }
22
21
  __names;
23
22
  async init() {
@@ -88,6 +87,7 @@ export class ArrayEntityDataProvider {
88
87
  return rows.map((i) => {
89
88
  return this.translateFromJson(i, dbNames);
90
89
  });
90
+ return [];
91
91
  }
92
92
  translateFromJson(row, dbNames) {
93
93
  let result = {};
@@ -116,7 +116,7 @@ class WebSqlBridgeToSQLCommand {
116
116
  });
117
117
  t.executeSql(s, v, (t1, r) => resolve(new WebSqlBridgeToSQLQueryResult(r)), (t2, err) => {
118
118
  reject(err.message);
119
- return undefined;
119
+ return false;
120
120
  });
121
121
  }));
122
122
  }
@@ -125,13 +125,13 @@ class WebSqlBridgeToSQLQueryResult {
125
125
  r;
126
126
  getColumnKeyInResultForIndexInSelect(index) {
127
127
  if (this.rows.length == 0)
128
- return undefined;
128
+ throw Error('No rows');
129
129
  let i = 0;
130
130
  for (let m in this.rows[0]) {
131
131
  if (i++ == index)
132
132
  return m;
133
133
  }
134
- return undefined;
134
+ throw Error('index not found');
135
135
  }
136
136
  //@ts-ignore
137
137
  constructor(r) {
@@ -2,8 +2,8 @@ import type { FieldMetadata } from '../column-interfaces';
2
2
  import type { Remult } from '../context';
3
3
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
4
4
  export declare class Filter {
5
- private apply?;
6
- constructor(apply?: (add: FilterConsumer) => void);
5
+ private apply;
6
+ constructor(apply: (add: FilterConsumer) => void);
7
7
  __applyToConsumer(add: FilterConsumer): void;
8
8
  static resolve<entityType>(filter: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)): Promise<EntityFilter<entityType>>;
9
9
  static createCustom<entityType>(rawFilterTranslator: (unused: never, r: Remult) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>, key?: string): (() => EntityFilter<entityType>) & customFilterInfo<entityType>;
@@ -4,9 +4,6 @@ export class Filter {
4
4
  apply;
5
5
  constructor(apply) {
6
6
  this.apply = apply;
7
- if (!this.apply) {
8
- this.apply = () => { };
9
- }
10
7
  }
11
8
  __applyToConsumer(add) {
12
9
  this.apply(add);
@@ -211,6 +208,8 @@ class filterHelper {
211
208
  }
212
209
  isIn(val) {
213
210
  val = val.map((x) => this.processVal(x));
211
+ if (val?.length == 1 && val[0] != undefined && val[0] !== null)
212
+ return new Filter((add) => add.isEqualTo(this.metadata, val[0]));
214
213
  return new Filter((add) => add.isIn(this.metadata, val));
215
214
  }
216
215
  }
@@ -15,7 +15,7 @@ export class LiveQuerySubscriber {
15
15
  async setAllItems(result) {
16
16
  const items = await this.repo.fromJsonArray(result, this.query.options);
17
17
  this.forListeners((listener) => {
18
- listener((x) => {
18
+ listener(() => {
19
19
  return items;
20
20
  });
21
21
  }, this.allItemsMessage(items));
@@ -23,7 +23,7 @@ export declare class Fields {
23
23
  }
24
24
  export declare class Relations {
25
25
  static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: RelationOptions<entityType, toEntityType, entityType> | keyof entityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, toEntityType>, c?: any) => void;
26
- static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
26
+ static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
27
27
  fromEntityType?: ClassType<entityType>;
28
28
  }) | keyof toEntityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, any>, c?: any) => void;
29
29
  }
@@ -40,7 +40,7 @@ export declare class Relations {
40
40
  * @Fields.string((options,remult) => options.includeInApi = true)
41
41
  * title='';
42
42
  */
43
- 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;
43
+ 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;
44
44
  export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
45
45
  maxLength?: number;
46
46
  }
@@ -193,4 +193,6 @@ export function checkTarget(target) {
193
193
  if (!target)
194
194
  throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
195
195
  }
196
- //[ ] there is a duplicity between the oneToMany and manyToOne - maybe we should allow some derivation from one to another?
196
+ //[ ] I think JY finds it confusing that the field options and relation options are together - but I still think it's good - not sure if it's a transition faze or not
197
+ //[ ] I wish that when you define a toOne we automagically get the toMany on the other side! 😉
198
+ //[ ] implement to many inference based on to one
@@ -50,10 +50,10 @@ export declare class RepositoryImplementation<entityType> implements Repository<
50
50
  save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
51
51
  save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
52
52
  liveQuery(options?: FindOptions<entityType>): LiveQuery<entityType>;
53
- rawFind(options: FindOptions<entityType>, skipOrderByAndLimit: boolean, loader: RelationLoader): Promise<Awaited<entityType>[]>;
53
+ rawFind(options: FindOptions<entityType>, skipOrderByAndLimit: boolean, loader: RelationLoader): Promise<entityType[]>;
54
54
  find(options: FindOptions<entityType>, skipOrderByAndLimit?: boolean): Promise<entityType[]>;
55
55
  buildEntityDataProviderFindOptions(options: FindOptions<entityType>): Promise<EntityDataProviderFindOptions>;
56
- fromJsonArray(jsonItems: any[], loadOptions: LoadOptions<entityType>): Promise<Awaited<entityType>[]>;
56
+ fromJsonArray(jsonItems: any[], loadOptions: LoadOptions<entityType>): Promise<entityType[]>;
57
57
  private loadManyToOneForManyRows;
58
58
  private mapRawDataToResult;
59
59
  toJson(item: entityType | entityType[] | Promise<entityType> | Promise<entityType[]>): any;
@@ -451,7 +451,7 @@ export class RepositoryImplementation {
451
451
  let where = [];
452
452
  let findOptions = {};
453
453
  let findOptionsSources = [];
454
- const options = field.options;
454
+ let options = field.options;
455
455
  if (typeof options.findOptions === 'function') {
456
456
  findOptionsSources.push(options.findOptions(row));
457
457
  }
@@ -473,6 +473,32 @@ export class RepositoryImplementation {
473
473
  findOptions[key] = source[key];
474
474
  }
475
475
  }
476
+ if (rel.type === 'toMany' && !options.field && !options.fields) {
477
+ for (const field of otherRepo.fields.toArray()) {
478
+ const rel = getRelationInfo(field.options);
479
+ const relOp = field.options;
480
+ if (rel)
481
+ if (rel.type === 'reference') {
482
+ options = { ...findOptions, field: field.key };
483
+ }
484
+ else if (rel.type === 'toOne') {
485
+ if (relOp.field) {
486
+ options = { ...options, field: relOp.field };
487
+ }
488
+ else if (relOp.fields) {
489
+ let fields = {};
490
+ for (const key in relOp.fields) {
491
+ if (Object.prototype.hasOwnProperty.call(relOp.fields, key)) {
492
+ const keyInMyTable = relOp.fields[key];
493
+ fields[keyInMyTable] = key;
494
+ }
495
+ }
496
+ options = { ...options, fields };
497
+ }
498
+ break;
499
+ }
500
+ }
501
+ }
476
502
  if (options.field) {
477
503
  if (rel.type === 'toOne') {
478
504
  where.push(otherRepo.metadata.idMetadata.getIdFilter(row[options.field]));
@@ -1133,12 +1159,14 @@ export class rowHelperImplementation extends rowHelperBase {
1133
1159
  await this.__validateEntity();
1134
1160
  let doNotSave = false;
1135
1161
  let e = this.buildLifeCycleEvent(() => (doNotSave = true));
1136
- for (const col of this.fields) {
1137
- if (col.metadata.options.saving)
1138
- await col.metadata.options.saving(this.instance, e, col);
1139
- }
1140
- if (this.info.entityInfo.saving) {
1141
- await this.info.entityInfo.saving(this.instance, e);
1162
+ if (!this.remult.dataProvider.isProxy) {
1163
+ for (const col of this.fields) {
1164
+ if (col.metadata.options.saving)
1165
+ await col.metadata.options.saving(this.instance, e, col);
1166
+ }
1167
+ if (this.info.entityInfo.saving) {
1168
+ await this.info.entityInfo.saving(this.instance, e);
1169
+ }
1142
1170
  }
1143
1171
  this.__assertValidity();
1144
1172
  let d = this.copyDataToObject();
@@ -1185,12 +1213,14 @@ export class rowHelperImplementation extends rowHelperBase {
1185
1213
  }
1186
1214
  }
1187
1215
  await this.loadDataFrom(updatedRow);
1188
- if (this.info.entityInfo.saved)
1189
- await this.info.entityInfo.saved(this.instance, e);
1190
- if (this.repository.listeners)
1191
- for (const listener of this.repository.listeners.filter((x) => x.saved)) {
1192
- await listener.saved(this.instance, isNew);
1193
- }
1216
+ if (!this.remult.dataProvider.isProxy) {
1217
+ if (this.info.entityInfo.saved)
1218
+ await this.info.entityInfo.saved(this.instance, e);
1219
+ if (this.repository.listeners)
1220
+ for (const listener of this.repository.listeners.filter((x) => x.saved)) {
1221
+ await listener.saved(this.instance, isNew);
1222
+ }
1223
+ }
1194
1224
  await this.repository.remult.liveQueryPublisher.itemChanged(this.repository.metadata.key, [{ id: this.getId(), oldId: this.getOriginalId(), deleted: false }]);
1195
1225
  this.saveOriginalData();
1196
1226
  this._isNew = false;
@@ -1225,13 +1255,17 @@ export class rowHelperImplementation extends rowHelperBase {
1225
1255
  async delete() {
1226
1256
  this.__clearErrorsAndReportChanged();
1227
1257
  let e = this.buildLifeCycleEvent();
1228
- if (this.info.entityInfo.deleting)
1229
- await this.info.entityInfo.deleting(this.instance, e);
1258
+ if (!this.remult.dataProvider.isProxy) {
1259
+ if (this.info.entityInfo.deleting)
1260
+ await this.info.entityInfo.deleting(this.instance, e);
1261
+ }
1230
1262
  this.__assertValidity();
1231
1263
  try {
1232
1264
  await this.edp.delete(this.id);
1233
- if (this.info.entityInfo.deleted)
1234
- await this.info.entityInfo.deleted(this.instance, e);
1265
+ if (!this.remult.dataProvider.isProxy) {
1266
+ if (this.info.entityInfo.deleted)
1267
+ await this.info.entityInfo.deleted(this.instance, e);
1268
+ }
1235
1269
  if (this.repository.listeners)
1236
1270
  for (const listener of this.repository.listeners.filter((x) => x.deleted)) {
1237
1271
  await listener.deleted(this.instance);
@@ -5,5 +5,5 @@ export declare function getEntityRef<entityType>(entity: entityType, throwExcept
5
5
  export declare const entityMember: unique symbol;
6
6
  export declare const entityInfo: unique symbol;
7
7
  export declare const entityInfo_key: unique symbol;
8
- export declare function getEntitySettings<T>(entity: ClassType<T>, throwError?: boolean): EntityOptionsFactory;
8
+ export declare function getEntitySettings<T>(entity: ClassType<T>, throwError?: boolean): EntityOptionsFactory | undefined;
9
9
  export declare function getEntityKey(entity: ClassType<any>): string;
@@ -2,7 +2,7 @@ export function getEntityRef(entity, throwException = true) {
2
2
  let x = entity[entityMember];
3
3
  if (!x && throwException)
4
4
  throw new Error('item ' +
5
- entity.constructor.name +
5
+ (entity.constructor?.name || entity) +
6
6
  ' was not initialized using a context');
7
7
  return x;
8
8
  }
package/esm/src/sort.d.ts CHANGED
@@ -6,9 +6,9 @@ export declare class Sort {
6
6
  Segments: SortSegment[];
7
7
  reverse(): Sort;
8
8
  compare(a: any, b: any, getFieldKey?: (field: FieldMetadata) => string): number;
9
- static translateOrderByToSort<T>(entityDefs: EntityMetadata<T>, orderBy: EntityOrderBy<T>): Sort;
10
- static createUniqueSort<T>(entityMetadata: EntityMetadata<T>, orderBy: Sort): Sort;
11
- static createUniqueEntityOrderBy<T>(entityMetadata: EntityMetadata<T>, orderBy: EntityOrderBy<T>): EntityOrderBy<T>;
9
+ static translateOrderByToSort<T>(entityDefs: EntityMetadata<T>, orderBy?: EntityOrderBy<T>): Sort;
10
+ static createUniqueSort<T>(entityMetadata: EntityMetadata<T>, orderBy?: Sort): Sort;
11
+ static createUniqueEntityOrderBy<T>(entityMetadata: EntityMetadata<T>, orderBy?: EntityOrderBy<T>): EntityOrderBy<T>;
12
12
  }
13
13
  export interface SortSegment {
14
14
  field: FieldMetadata;
package/esm/src/sort.js CHANGED
@@ -44,11 +44,8 @@ export class Sort {
44
44
  return r;
45
45
  }
46
46
  static translateOrderByToSort(entityDefs, orderBy) {
47
- if (!orderBy)
48
- return undefined;
49
- let sort;
50
- if (orderBy) {
51
- sort = new Sort();
47
+ let sort = new Sort();
48
+ if (orderBy)
52
49
  for (const key in orderBy) {
53
50
  if (Object.prototype.hasOwnProperty.call(orderBy, key)) {
54
51
  const element = orderBy[key];
@@ -85,7 +82,6 @@ export class Sort {
85
82
  }
86
83
  }
87
84
  }
88
- }
89
85
  return sort;
90
86
  }
91
87
  static createUniqueSort(entityMetadata, orderBy) {
package/internals.d.ts CHANGED
@@ -4,3 +4,4 @@ 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.23.0-exp.7",
3
+ "version": "0.23.0-exp.9",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
@@ -14,7 +14,7 @@ var JsonEntityFileStorage = /** @class */ (function () {
14
14
  if (fs.existsSync(fn)) {
15
15
  return fs.readFileSync(fn).toString();
16
16
  }
17
- return undefined;
17
+ return null;
18
18
  };
19
19
  JsonEntityFileStorage.prototype.setItem = function (entityDbName, json) {
20
20
  if (!fs.existsSync(this.folderPath)) {
@@ -1,6 +1,5 @@
1
1
  import type { RestDataProviderHttpProvider } from './data-interfaces';
2
- import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
3
- export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProviderUsingFetch | RestDataProviderHttpProvider;
2
+ export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProvider;
4
3
  export declare function isExternalHttpProvider(item: any): boolean;
5
4
  export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
6
5
  private http;
package/src/column.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare class LookupColumn<T> {
8
8
  setId(val: any): void;
9
9
  waitLoadOf(id: any): Promise<T>;
10
10
  get(id: any): any;
11
- storedItem: {
11
+ storedItem?: {
12
12
  item: T;
13
13
  };
14
14
  set(item: T): void;
package/src/context.d.ts CHANGED
@@ -15,7 +15,7 @@ export declare class RemultAsyncLocalStorage {
15
15
  }
16
16
  type myAsyncLocalStorage<T> = {
17
17
  run<R>(store: T, callback: (...args: any[]) => R, ...args: any[]): R;
18
- getStore(): T;
18
+ getStore(): T | undefined;
19
19
  };
20
20
  export declare function isBackend(): boolean;
21
21
  export declare class Remult {
package/src/context.js CHANGED
@@ -149,7 +149,7 @@ var Remult = /** @class */ (function () {
149
149
  if (typeof roles === 'boolean')
150
150
  return roles;
151
151
  if (typeof roles === 'string')
152
- if (((_c = (_b = this.user) === null || _b === void 0 ? void 0 : _b.roles) === null || _c === void 0 ? void 0 : _c.indexOf(roles.toString())) >= 0)
152
+ if ((_c = (_b = this.user) === null || _b === void 0 ? void 0 : _b.roles) === null || _c === void 0 ? void 0 : _c.includes(roles.toString()))
153
153
  return true;
154
154
  return false;
155
155
  };
@@ -182,6 +182,7 @@ var Remult = /** @class */ (function () {
182
182
  }
183
183
  else
184
184
  return this.isAllowed(allowed);
185
+ return undefined;
185
186
  };
186
187
  //@ts-ignore // type error of typescript regarding args that doesn't appear in my normal development
187
188
  /** Used to call a `backendMethod` using a specific `remult` object
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractSort = void 0;
4
4
  var sort_1 = require("./sort");
5
5
  function extractSort(sort) {
6
- if (sort instanceof sort_1.Sort)
7
- return sort;
8
6
  if (sort instanceof Array) {
9
7
  var r_1 = new sort_1.Sort();
10
8
  sort.forEach(function (i) {
@@ -12,5 +10,6 @@ function extractSort(sort) {
12
10
  });
13
11
  return r_1;
14
12
  }
13
+ return sort;
15
14
  }
16
15
  exports.extractSort = extractSort;
@@ -4,8 +4,8 @@ import { Filter } from '../filter/filter-interfaces';
4
4
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
5
5
  export declare class ArrayEntityDataProvider implements EntityDataProvider {
6
6
  private entity;
7
- private rows?;
8
7
  static rawFilter(filter: CustomArrayFilter): EntityFilter<any>;
8
+ private rows;
9
9
  constructor(entity: EntityMetadata, rows?: any[]);
10
10
  __names: EntityDbNamesBase;
11
11
  init(): Promise<EntityDbNamesBase>;
@@ -8,11 +8,10 @@ var filter_interfaces_1 = require("../filter/filter-interfaces");
8
8
  var ArrayEntityDataProvider = /** @class */ (function () {
9
9
  function ArrayEntityDataProvider(entity, rows) {
10
10
  this.entity = entity;
11
- this.rows = rows;
12
- if (!rows)
13
- rows = [];
14
- else {
15
- }
11
+ if (rows === undefined)
12
+ this.rows = [];
13
+ else
14
+ this.rows = rows;
16
15
  }
17
16
  ArrayEntityDataProvider.rawFilter = function (filter) {
18
17
  var _a;
@@ -141,7 +140,7 @@ var ArrayEntityDataProvider = /** @class */ (function () {
141
140
  return [2 /*return*/, rows.map(function (i) {
142
141
  return _this.translateFromJson(i, dbNames);
143
142
  })];
144
- return [2 /*return*/];
143
+ return [2 /*return*/, []];
145
144
  }
146
145
  });
147
146
  });
@@ -199,7 +199,7 @@ var WebSqlBridgeToSQLCommand = /** @class */ (function () {
199
199
  });
200
200
  t.executeSql(s, v, function (t1, r) { return resolve(new WebSqlBridgeToSQLQueryResult(r)); }, function (t2, err) {
201
201
  reject(err.message);
202
- return undefined;
202
+ return false;
203
203
  });
204
204
  });
205
205
  });
@@ -217,13 +217,13 @@ var WebSqlBridgeToSQLQueryResult = /** @class */ (function () {
217
217
  }
218
218
  WebSqlBridgeToSQLQueryResult.prototype.getColumnKeyInResultForIndexInSelect = function (index) {
219
219
  if (this.rows.length == 0)
220
- return undefined;
220
+ throw Error('No rows');
221
221
  var i = 0;
222
222
  for (var m in this.rows[0]) {
223
223
  if (i++ == index)
224
224
  return m;
225
225
  }
226
- return undefined;
226
+ throw Error('index not found');
227
227
  };
228
228
  return WebSqlBridgeToSQLQueryResult;
229
229
  }());
@@ -2,8 +2,8 @@ import type { FieldMetadata } from '../column-interfaces';
2
2
  import type { Remult } from '../context';
3
3
  import type { EntityFilter, EntityMetadata } from '../remult3/remult3';
4
4
  export declare class Filter {
5
- private apply?;
6
- constructor(apply?: (add: FilterConsumer) => void);
5
+ private apply;
6
+ constructor(apply: (add: FilterConsumer) => void);
7
7
  __applyToConsumer(add: FilterConsumer): void;
8
8
  static resolve<entityType>(filter: EntityFilter<entityType> | (() => EntityFilter<entityType> | Promise<EntityFilter<entityType>>)): Promise<EntityFilter<entityType>>;
9
9
  static createCustom<entityType>(rawFilterTranslator: (unused: never, r: Remult) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>, key?: string): (() => EntityFilter<entityType>) & customFilterInfo<entityType>;
@@ -7,9 +7,6 @@ var relationInfoMember_1 = require("../remult3/relationInfoMember");
7
7
  var Filter = /** @class */ (function () {
8
8
  function Filter(apply) {
9
9
  this.apply = apply;
10
- if (!this.apply) {
11
- this.apply = function () { };
12
- }
13
10
  }
14
11
  Filter.prototype.__applyToConsumer = function (add) {
15
12
  this.apply(add);
@@ -282,6 +279,8 @@ var filterHelper = /** @class */ (function () {
282
279
  filterHelper.prototype.isIn = function (val) {
283
280
  var _this = this;
284
281
  val = val.map(function (x) { return _this.processVal(x); });
282
+ if ((val === null || val === void 0 ? void 0 : val.length) == 1 && val[0] != undefined && val[0] !== null)
283
+ return new Filter(function (add) { return add.isEqualTo(_this.metadata, val[0]); });
285
284
  return new Filter(function (add) { return add.isIn(_this.metadata, val); });
286
285
  };
287
286
  return filterHelper;
@@ -31,7 +31,7 @@ var LiveQuerySubscriber = /** @class */ (function () {
31
31
  case 1:
32
32
  items = _a.sent();
33
33
  this.forListeners(function (listener) {
34
- listener(function (x) {
34
+ listener(function () {
35
35
  return items;
36
36
  });
37
37
  }, this.allItemsMessage(items));
@@ -23,7 +23,7 @@ export declare class Fields {
23
23
  }
24
24
  export declare class Relations {
25
25
  static toOne<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: RelationOptions<entityType, toEntityType, entityType> | keyof entityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, toEntityType>, c?: any) => void;
26
- static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
26
+ static toMany<entityType, toEntityType>(toEntityType: () => ClassType<toEntityType>, options?: (RelationOptions<entityType, toEntityType, toEntityType, FindOptions<toEntityType>> & {
27
27
  fromEntityType?: ClassType<entityType>;
28
28
  }) | keyof toEntityType): (target: any, context: string | ClassFieldDecoratorContextStub<entityType, any>, c?: any) => void;
29
29
  }
@@ -40,7 +40,7 @@ export declare class Relations {
40
40
  * @Fields.string((options,remult) => options.includeInApi = true)
41
41
  * title='';
42
42
  */
43
- 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;
43
+ 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;
44
44
  export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
45
45
  maxLength?: number;
46
46
  }