remult 0.12.7 → 0.13.1

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/graphql.js +2 -2
  2. package/index.d.ts +2 -1
  3. package/index.js +6 -5
  4. package/package.json +1 -1
  5. package/postgres/postgres-data-provider.js +3 -2
  6. package/postgres/postgresColumnSyntax.js +1 -1
  7. package/readme.md +7 -1
  8. package/remult-knex/index.js +6 -5
  9. package/remult-mongo.js +1 -1
  10. package/server/expressBridge.js +8 -8
  11. package/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +1 -1
  12. package/src/backend-tests/backend-database-test-setup.backend-spec.js +1 -1
  13. package/src/backend-tests/my-test.backend-spec.js +112 -0
  14. package/src/context.js +1 -1
  15. package/src/data-api.js +73 -52
  16. package/src/data-providers/array-entity-data-provider.js +8 -7
  17. package/src/data-providers/web-sql-data-provider.js +12 -6
  18. package/src/entity.d.ts +0 -1
  19. package/src/filter/filter-interfaces.d.ts +2 -2
  20. package/src/filter/filter-interfaces.js +5 -2
  21. package/src/id-entity.js +1 -5
  22. package/src/remult3/RepositoryImplementation.d.ts +53 -16
  23. package/src/remult3/RepositoryImplementation.js +224 -78
  24. package/src/remult3/remult3.d.ts +4 -4
  25. package/src/shared-tests/db-tests.db-tests.js +34 -127
  26. package/src/shared-tests/entityWithValidations.js +2 -2
  27. package/src/shared-tests/test-custom-id-column.spec.js +26 -4
  28. package/src/shared-tests/test-special-value.spec.js +2 -2
  29. package/src/shared-tests/test-update-with-null.spec.js +2 -2
  30. package/src/tests/c.js +2 -2
  31. package/src/tests/d.js +2 -2
  32. package/src/tests/dWithPrefilter.js +2 -2
  33. package/src/tests/entityForCustomFilter.js +1 -1
  34. package/src/tests/entityWithValidationsOnColumn.js +2 -2
  35. package/src/tests/h.js +6 -4
  36. package/src/tests/remult-3-entities.js +11 -11
  37. package/src/tests/tasks.js +3 -3
  38. package/src/validators.d.ts +5 -3
  39. package/src/validators.js +9 -7
  40. package/valueConverters.d.ts +11 -24
  41. package/valueConverters.js +148 -210
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebSqlDataProvider = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var remult3_1 = require("../remult3");
5
6
  var sql_database_1 = require("./sql-database");
6
7
  var filter_consumer_bridge_to_sql_request_1 = require("../filter/filter-consumer-bridge-to-sql-request");
7
8
  //SqlDatabase.LogToConsole = true;
@@ -59,15 +60,20 @@ var WebSqlDataProvider = /** @class */ (function () {
59
60
  try {
60
61
  for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
61
62
  x = _b.value;
62
- if (!e.isDbReadonly(x)) {
63
+ if (!e.isDbReadonly(x) || remult3_1.isAutoIncrement(x)) {
63
64
  if (result.length != 0)
64
65
  result += ',';
65
66
  result += '\r\n ';
66
- result += this.addColumnSqlSyntax(x, e.nameOf(x));
67
- if (x.key == entity.idMetadata.field.key) {
68
- result += ' primary key';
69
- if (entity.options.dbAutoIncrementId)
70
- result += " autoincrement";
67
+ if (remult3_1.isAutoIncrement(x)) {
68
+ if (x.key != entity.idMetadata.field.key)
69
+ throw "in web sql, autoincrement is only allowed for primary key";
70
+ result += e.nameOf(x) + ' integer primary key autoincrement';
71
+ }
72
+ else {
73
+ result += this.addColumnSqlSyntax(x, e.nameOf(x));
74
+ if (x.key == entity.idMetadata.field.key) {
75
+ result += ' primary key';
76
+ }
71
77
  }
72
78
  }
73
79
  }
package/src/entity.d.ts CHANGED
@@ -3,7 +3,6 @@ import { FieldMetadata as FieldMetadata } from './column-interfaces';
3
3
  import { EntityOrderBy, FieldsMetadata, EntityFilter, EntityRef } from "./remult3";
4
4
  export interface EntityOptions<entityType = any> {
5
5
  id?: (entity: FieldsMetadata<entityType>) => FieldMetadata;
6
- dbAutoIncrementId?: boolean;
7
6
  /**
8
7
  * The name of the table in the database that holds the data for this entity.
9
8
  * If no name is set, the `key` will be used instead.
@@ -6,8 +6,8 @@ export declare class Filter {
6
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
- static createCustom<entityType>(customFilterTranslator: (r: Remult) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>): (() => EntityFilter<entityType>) & customFilterInfo<entityType>;
10
- static createCustom<entityType, argsType>(customFilterTranslator: (r: Remult, args: argsType) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>): ((y: argsType) => EntityFilter<entityType>) & customFilterInfo<entityType>;
9
+ static createCustom<entityType>(customFilterTranslator: (r: Remult) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>, key?: string): (() => EntityFilter<entityType>) & customFilterInfo<entityType>;
10
+ static createCustom<entityType, argsType>(customFilterTranslator: (r: Remult, args: argsType) => EntityFilter<entityType> | Promise<EntityFilter<entityType>>, key?: string): ((y: argsType) => EntityFilter<entityType>) & customFilterInfo<entityType>;
11
11
  static fromEntityFilter<T>(entity: EntityMetadata<T>, whereItem: EntityFilter<T>): Filter;
12
12
  toJson(): any;
13
13
  static entityFilterToJson<T>(entityDefs: EntityMetadata<T>, where: EntityFilter<T>): any;
@@ -26,13 +26,16 @@ var Filter = /** @class */ (function () {
26
26
  });
27
27
  });
28
28
  };
29
- Filter.createCustom = function (customFilterTranslator) {
30
- var customFilterInfo = { key: '', customFilterTranslator: customFilterTranslator };
29
+ Filter.createCustom = function (customFilterTranslator, key) {
30
+ if (key === void 0) { key = ''; }
31
+ var customFilterInfo = { key: key, customFilterTranslator: customFilterTranslator };
31
32
  return Object.assign(function (x) {
32
33
  var _a;
33
34
  var z = {};
34
35
  if (x == undefined)
35
36
  x = {};
37
+ if (!customFilterInfo.key)
38
+ throw "Usage of custom filter before a key was assigned to it";
36
39
  return _a = {},
37
40
  _a[exports.customUrlToken + customFilterInfo.key] = x,
38
41
  _a;
package/src/id-entity.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IdEntity = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var uuid_1 = require("uuid");
6
5
  var remult3_1 = require("./remult3");
7
6
  var IdEntity = /** @class */ (function (_super) {
8
7
  tslib_1.__extends(IdEntity, _super);
@@ -10,10 +9,7 @@ var IdEntity = /** @class */ (function (_super) {
10
9
  return _super !== null && _super.apply(this, arguments) || this;
11
10
  }
12
11
  tslib_1.__decorate([
13
- remult3_1.Field({
14
- allowApiUpdate: false,
15
- defaultValue: function () { return uuid_1.v4(); }
16
- }),
12
+ remult3_1.Fields.Uuid(),
17
13
  tslib_1.__metadata("design:type", String)
18
14
  ], IdEntity.prototype, "id", void 0);
19
15
  return IdEntity;
@@ -1,7 +1,7 @@
1
- import { FieldMetadata, FieldOptions, ValueListItem } from "../column-interfaces";
1
+ import { FieldMetadata, FieldOptions, ValueConverter, ValueListItem } from "../column-interfaces";
2
2
  import { EntityOptions } from "../entity";
3
3
  import { LookupColumn } from '../column';
4
- import { EntityMetadata, FieldRef, Fields, EntityFilter, FindOptions, Repository, EntityRef, QueryOptions, QueryResult, EntityOrderBy, FieldsMetadata, IdMetadata, FindFirstOptionsBase, FindFirstOptions, OmitEB, Subscribable, ControllerRef } from "./remult3";
4
+ import { EntityMetadata, FieldRef, FieldsRef, EntityFilter, FindOptions, Repository, EntityRef, QueryOptions, QueryResult, EntityOrderBy, FieldsMetadata, IdMetadata, FindFirstOptionsBase, FindFirstOptions, OmitEB, Subscribable, ControllerRef } from "./remult3";
5
5
  import { ClassType } from "../../classType";
6
6
  import { Remult, Unobserve } from "../context";
7
7
  import { entityEventListener } from "../__EntityValueProvider";
@@ -78,7 +78,7 @@ declare abstract class rowHelperBase<T> {
78
78
  [key: string]: string;
79
79
  };
80
80
  protected __assertValidity(): void;
81
- abstract get fields(): Fields<T>;
81
+ abstract get fields(): FieldsRef<T>;
82
82
  catchSaveErrors(err: any): any;
83
83
  __clearErrorsAndReportChanged(): void;
84
84
  _reportChangedToEntityAndFields(): void;
@@ -108,7 +108,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
108
108
  undoChanges(): void;
109
109
  reload(): Promise<T>;
110
110
  private _columns;
111
- get fields(): Fields<T>;
111
+ get fields(): FieldsRef<T>;
112
112
  private _saving;
113
113
  save(): Promise<T>;
114
114
  private getIdFilter;
@@ -121,7 +121,7 @@ export declare class rowHelperImplementation<T> extends rowHelperBase<T> impleme
121
121
  wasChanged(): boolean;
122
122
  __performColumnAndEntityValidations(): Promise<void>;
123
123
  }
124
- export declare function getFields<fieldsContainerType>(container: fieldsContainerType, remult?: Remult): Fields<fieldsContainerType>;
124
+ export declare function getFields<fieldsContainerType>(container: fieldsContainerType, remult?: Remult): FieldsRef<fieldsContainerType>;
125
125
  export declare function getControllerRef<fieldsContainerType>(container: fieldsContainerType, remult?: Remult): ControllerRef<fieldsContainerType>;
126
126
  export declare class controllerRefImpl<T = any> extends rowHelperBase<T> implements ControllerRef<T> {
127
127
  constructor(columnsInfo: FieldOptions[], instance: any, remult: Remult);
@@ -130,7 +130,7 @@ export declare class controllerRefImpl<T = any> extends rowHelperBase<T> impleme
130
130
  [key: string]: string;
131
131
  };
132
132
  originalValues: any;
133
- fields: Fields<T>;
133
+ fields: FieldsRef<T>;
134
134
  }
135
135
  export declare class FieldRefImplementation<entityType, valueType> implements FieldRef<entityType, valueType> {
136
136
  private settings;
@@ -176,7 +176,7 @@ export declare class columnDefsImpl implements FieldMetadata {
176
176
  options: FieldOptions<any, any>;
177
177
  target: ClassType<any>;
178
178
  readonly: boolean;
179
- valueConverter: import("../column-interfaces").ValueConverter<any>;
179
+ valueConverter: ValueConverter<any>;
180
180
  allowNull: boolean;
181
181
  caption: string;
182
182
  get dbName(): any;
@@ -201,18 +201,55 @@ declare class EntityFullInfo<T> implements EntityMetadata<T> {
201
201
  dbNamePromise: Promise<string>;
202
202
  getDbName(): Promise<string>;
203
203
  idMetadata: IdMetadata<T>;
204
- dbAutoIncrementId: boolean;
205
204
  fields: FieldsMetadata<T>;
206
205
  dbName: string;
207
206
  caption: string;
208
207
  }
209
208
  export declare function FieldType<valueType = any>(...options: (FieldOptions<any, valueType> | ((options: FieldOptions<any, valueType>, remult: Remult) => void))[]): (target: any) => any;
210
- export declare function JsonField<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
211
- export declare function DateOnlyField<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
212
- export declare function IntegerField<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
213
- export declare function ValueListFieldType<entityType = any, valueType extends ValueListItem = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (type: ClassType<valueType>) => any;
214
- export declare function UuidField<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
215
- export declare function Field<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
209
+ export declare const Fields1: {
210
+ String: () => (a: any) => void;
211
+ };
212
+ export declare class Fields {
213
+ static Object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
214
+ static DateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
215
+ static Date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
216
+ static Integer<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
217
+ static AutoIncrement<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
218
+ static Number<entityType = any>(...options: (FieldOptions<entityType, Number> | ((options: FieldOptions<entityType, Number>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
219
+ static Uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
220
+ static String<entityType = any>(...options: (StringFieldOptions<entityType> | ((options: StringFieldOptions<entityType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
221
+ static Boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
222
+ }
223
+ export declare function isAutoIncrement(f: FieldMetadata): boolean;
224
+ export interface StringFieldOptions<entityType = any> extends FieldOptions<entityType, string> {
225
+ maxLength?: number;
226
+ }
227
+ export declare function ValueListFieldType<entityType = any, valueType extends ValueListItem = any>(...options: (ValueListFieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (type: ClassType<valueType>) => any;
228
+ export interface ValueListFieldOptions<entityType, valueType> extends FieldOptions<entityType, valueType> {
229
+ getValues?: () => valueType[];
230
+ }
231
+ export declare class ValueListInfo<T extends ValueListItem> implements ValueConverter<T> {
232
+ private valueListType;
233
+ static get<T extends ValueListItem>(type: ClassType<T>): ValueListInfo<T>;
234
+ private byIdMap;
235
+ private values;
236
+ isNumeric: boolean;
237
+ private constructor();
238
+ getValues(): T[];
239
+ byId(key: any): T;
240
+ fromJson(val: any): T;
241
+ toJson(val: T): any;
242
+ fromDb(val: any): T;
243
+ toDb(val: T): any;
244
+ toInput(val: T, inputType: string): string;
245
+ fromInput(val: string, inputType: string): T;
246
+ displayValue?(val: T): string;
247
+ fieldTypeInDb?: string;
248
+ inputType?: string;
249
+ }
250
+ export declare function getValueList<T>(type: ClassType<T>): T[];
251
+ export declare function Field<entityType = any, valueType = any>(valueType: () => ClassType<valueType>, ...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): (target: any, key: any, c?: any) => void;
252
+ export declare const storableMember: unique symbol;
216
253
  export declare function decorateColumnSettings<valueType>(settings: FieldOptions<any, valueType>, remult: Remult): FieldOptions<any, valueType>;
217
254
  interface columnInfo {
218
255
  key: string;
@@ -229,12 +266,12 @@ export declare class EntityBase {
229
266
  assign(values: Partial<Omit<this, keyof EntityBase>>): this;
230
267
  delete(): Promise<void>;
231
268
  isNew(): boolean;
232
- get $(): Fields<this>;
269
+ get $(): FieldsRef<this>;
233
270
  }
234
271
  export declare class ControllerBase {
235
272
  protected remult: Remult;
236
273
  constructor(remult: Remult);
237
- get $(): Fields<this>;
274
+ get $(): FieldsRef<this>;
238
275
  get _(): ControllerRef<this>;
239
276
  }
240
277
  declare class SubscribableImp implements Subscribable {