remult 0.26.23 → 0.27.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 (126) hide show
  1. package/SseSubscriptionServer.d.ts +3 -4
  2. package/assign.js +1 -2
  3. package/esm/graphql.js +1 -1
  4. package/esm/remult-hono.js +3 -1
  5. package/esm/remult-knex/index.js +3 -1
  6. package/esm/remult-sqlite3.js +4 -1
  7. package/esm/remult-sveltekit.js +1 -0
  8. package/esm/server/index.js +3 -2
  9. package/esm/server/initAsyncHooks.js +3 -3
  10. package/esm/server/remult-admin.js +1 -4
  11. package/esm/server/remult-api-server.js +47 -48
  12. package/esm/src/CompoundIdField.js +9 -9
  13. package/esm/src/data-api.js +1 -1
  14. package/esm/src/data-providers/json-entity-opfs-storage.js +9 -5
  15. package/esm/src/data-providers/sql-database.js +9 -9
  16. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +3 -1
  17. package/esm/src/filter/filter-interfaces.js +1 -1
  18. package/esm/src/live-query/LiveQueryClient.js +0 -1
  19. package/esm/src/remult-proxy.js +1 -3
  20. package/esm/src/remult-static.js +1 -0
  21. package/esm/src/remult3/Fields.js +15 -7
  22. package/esm/src/remult3/RepositoryImplementation.js +165 -125
  23. package/esm/src/remult3/entity.js +1 -1
  24. package/esm/src/remult3/relation-loader.js +2 -2
  25. package/esm/src/remult3/remult3.js +15 -0
  26. package/esm/src/server-action.js +16 -12
  27. package/esm/src/sort.js +0 -2
  28. package/esm/src/validators.js +3 -3
  29. package/esm/src/valueConverters.js +2 -2
  30. package/graphql.js +3 -4
  31. package/index.js +2 -2
  32. package/live-query/data-provider-live-query-storage.js +6 -6
  33. package/migrations/compare-migration-snapshots.js +48 -49
  34. package/migrations/generate-migrations.js +1 -2
  35. package/migrations/migrate.js +2 -3
  36. package/migrations/migration-types.d.ts +1 -1
  37. package/migrations/migration-types.js +4 -4
  38. package/migrations/update-migrations-ts-file.js +1 -2
  39. package/myLog.js +1 -2
  40. package/package.json +1 -1
  41. package/postgres/postgres-data-provider.d.ts +2 -2
  42. package/postgres/postgres-data-provider.js +5 -5
  43. package/postgres/schema-builder.d.ts +1 -1
  44. package/postgres/schema-builder.js +3 -3
  45. package/remult-express.js +4 -3
  46. package/remult-fastify.js +4 -3
  47. package/remult-fresh.js +1 -2
  48. package/remult-hapi.js +4 -3
  49. package/remult-hono.js +6 -3
  50. package/remult-knex/index.d.ts +2 -2
  51. package/remult-knex/index.js +7 -5
  52. package/remult-mongo.d.ts +1 -1
  53. package/remult-next.d.ts +5 -6
  54. package/remult-next.js +11 -6
  55. package/remult-nuxt.js +1 -2
  56. package/remult-solid-start.js +1 -2
  57. package/remult-sqlite3.js +4 -1
  58. package/remult-sveltekit.d.ts +1 -1
  59. package/remult-sveltekit.js +33 -35
  60. package/server/JsonEntityFileStorage.d.ts +1 -1
  61. package/server/get-remult-admin-html.js +1 -2
  62. package/server/index.js +4 -3
  63. package/server/initAsyncHooks.d.ts +10 -10
  64. package/server/initAsyncHooks.js +5 -2
  65. package/server/initDataProvider.js +1 -2
  66. package/server/initDataProviderOrJson.js +1 -2
  67. package/server/remult-admin.js +3 -7
  68. package/server/remult-api-server.d.ts +21 -21
  69. package/server/remult-api-server.js +54 -48
  70. package/src/CompoundIdField.d.ts +2 -2
  71. package/src/CompoundIdField.js +9 -0
  72. package/src/buildRestDataProvider.d.ts +1 -1
  73. package/src/buildRestDataProvider.js +8 -8
  74. package/src/column-interfaces.d.ts +4 -4
  75. package/src/column-interfaces.js +1 -2
  76. package/src/column.d.ts +4 -4
  77. package/src/column.js +2 -2
  78. package/src/context.d.ts +4 -4
  79. package/src/context.js +5 -5
  80. package/src/data-api.d.ts +4 -4
  81. package/src/data-api.js +4 -4
  82. package/src/data-interfaces.d.ts +1 -1
  83. package/src/data-interfaces.js +1 -2
  84. package/src/data-providers/json-entity-opfs-storage.js +30 -16
  85. package/src/data-providers/rest-data-provider.d.ts +3 -3
  86. package/src/data-providers/rest-data-provider.js +4 -4
  87. package/src/data-providers/sql-database.d.ts +1 -1
  88. package/src/data-providers/sql-database.js +11 -11
  89. package/src/data-providers/web-sql-data-provider.d.ts +2 -2
  90. package/src/entity.d.ts +1 -1
  91. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +3 -3
  92. package/src/filter/filter-consumer-bridge-to-sql-request.js +21 -19
  93. package/src/filter/filter-interfaces.d.ts +2 -1
  94. package/src/filter/filter-interfaces.js +10 -7
  95. package/src/isOfType.js +2 -3
  96. package/src/live-query/SubscriptionServer.js +95 -97
  97. package/src/remult-proxy.js +1 -3
  98. package/src/remult-static.d.ts +2 -2
  99. package/src/remult-static.js +7 -4
  100. package/src/remult3/Fields.d.ts +17 -17
  101. package/src/remult3/Fields.js +22 -13
  102. package/src/remult3/RepositoryImplementation.d.ts +51 -46
  103. package/src/remult3/RepositoryImplementation.js +421 -368
  104. package/src/remult3/__updateEntityBasedOnWhere.js +1 -2
  105. package/src/remult3/addValidator.d.ts +1 -1
  106. package/src/remult3/addValidator.js +1 -2
  107. package/src/remult3/classDescribers.d.ts +4 -4
  108. package/src/remult3/classDescribers.js +3 -4
  109. package/src/remult3/columnInfo.d.ts +1 -1
  110. package/src/remult3/entity.js +2 -4
  111. package/src/remult3/getEntityRef.js +4 -4
  112. package/src/remult3/relation-loader.d.ts +1 -1
  113. package/src/remult3/relationInfoMember.d.ts +3 -3
  114. package/src/remult3/relationInfoMember.js +4 -5
  115. package/src/remult3/remult3.d.ts +23 -20
  116. package/src/remult3/remult3.js +15 -0
  117. package/src/remult3/repository-internals.d.ts +3 -3
  118. package/src/remult3/repository-internals.js +2 -2
  119. package/src/server-action.d.ts +2 -2
  120. package/src/server-action.js +65 -58
  121. package/src/sort.d.ts +1 -1
  122. package/src/sort.js +0 -2
  123. package/src/sql-command.d.ts +1 -1
  124. package/src/validators.d.ts +1 -1
  125. package/src/validators.js +13 -11
  126. package/src/valueConverters.js +3 -2
@@ -17,109 +17,107 @@ var LiveQueryPublisher = /** @class */ (function () {
17
17
  var _this = this;
18
18
  return tslib_1.__generator(this, function (_a) {
19
19
  switch (_a.label) {
20
- case 0: return [4 /*yield*/, this.liveQueryStorage().forEach(entityKey, function (_a) {
21
- var q = _a.query, setData = _a.setData;
22
- return tslib_1.__awaiter(_this, void 0, void 0, function () {
23
- var query;
24
- var _this = this;
25
- return tslib_1.__generator(this, function (_b) {
26
- switch (_b.label) {
27
- case 0:
28
- query = tslib_1.__assign({}, q.data);
29
- return [4 /*yield*/, this.performWithContext(query.requestJson, entityKey, function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
30
- var messages, currentItems, currentIds, _loop_1, _a, _b, id, _loop_2, currentItems_1, currentItems_1_1, item;
31
- var e_1, _c, e_2, _d;
32
- return tslib_1.__generator(this, function (_e) {
33
- switch (_e.label) {
34
- case 0:
35
- messages = [];
36
- return [4 /*yield*/, repo.find((0, rest_data_provider_js_1.findOptionsFromJson)(query.findOptionsJson, repo.metadata))];
37
- case 1:
38
- currentItems = _e.sent();
39
- currentIds = currentItems.map(function (x) {
40
- return repo.getEntityRef(x).getId();
41
- });
42
- _loop_1 = function (id) {
43
- var c = changes.find(function (c) { return c.oldId == id; });
44
- if (c === undefined ||
45
- id != c.oldId ||
46
- !currentIds.includes(c.id))
47
- messages.push({
48
- type: 'remove',
49
- data: {
50
- id: id,
51
- },
52
- });
53
- };
20
+ case 0: return [4 /*yield*/, this.liveQueryStorage().forEach(entityKey, function (_a) { return tslib_1.__awaiter(_this, [_a], void 0, function (_b) {
21
+ var query;
22
+ var _this = this;
23
+ var q = _b.query, setData = _b.setData;
24
+ return tslib_1.__generator(this, function (_c) {
25
+ switch (_c.label) {
26
+ case 0:
27
+ query = tslib_1.__assign({}, q.data);
28
+ return [4 /*yield*/, this.performWithContext(query.requestJson, entityKey, function (repo) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
29
+ var messages, currentItems, currentIds, _loop_1, _a, _b, id, _loop_2, currentItems_1, currentItems_1_1, item;
30
+ var e_1, _c, e_2, _d;
31
+ return tslib_1.__generator(this, function (_e) {
32
+ switch (_e.label) {
33
+ case 0:
34
+ messages = [];
35
+ return [4 /*yield*/, repo.find((0, rest_data_provider_js_1.findOptionsFromJson)(query.findOptionsJson, repo.metadata))];
36
+ case 1:
37
+ currentItems = _e.sent();
38
+ currentIds = currentItems.map(function (x) {
39
+ return repo.getEntityRef(x).getId();
40
+ });
41
+ _loop_1 = function (id) {
42
+ var c = changes.find(function (c) { return c.oldId == id; });
43
+ if (c === undefined ||
44
+ id != c.oldId ||
45
+ !currentIds.includes(c.id))
46
+ messages.push({
47
+ type: 'remove',
48
+ data: {
49
+ id: id,
50
+ },
51
+ });
52
+ };
53
+ try {
54
+ for (_a = tslib_1.__values(query.lastIds.filter(function (y) { return !currentIds.includes(y); })), _b = _a.next(); !_b.done; _b = _a.next()) {
55
+ id = _b.value;
56
+ _loop_1(id);
57
+ }
58
+ }
59
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
60
+ finally {
54
61
  try {
55
- for (_a = tslib_1.__values(query.lastIds.filter(function (y) { return !currentIds.includes(y); })), _b = _a.next(); !_b.done; _b = _a.next()) {
56
- id = _b.value;
57
- _loop_1(id);
58
- }
62
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
59
63
  }
60
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
61
- finally {
62
- try {
63
- if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
64
- }
65
- finally { if (e_1) throw e_1.error; }
64
+ finally { if (e_1) throw e_1.error; }
65
+ }
66
+ _loop_2 = function (item) {
67
+ var itemRef = repo.getEntityRef(item);
68
+ var c = changes.find(function (c) { return c.id == itemRef.getId(); });
69
+ if (c !== undefined && query.lastIds.includes(c.oldId)) {
70
+ messages.push({
71
+ type: 'replace',
72
+ data: {
73
+ oldId: c.oldId,
74
+ item: itemRef.toApiJson(),
75
+ },
76
+ });
66
77
  }
67
- _loop_2 = function (item) {
68
- var itemRef = repo.getEntityRef(item);
69
- var c = changes.find(function (c) { return c.id == itemRef.getId(); });
70
- if (c !== undefined && query.lastIds.includes(c.oldId)) {
71
- messages.push({
72
- type: 'replace',
73
- data: {
74
- oldId: c.oldId,
75
- item: itemRef.toApiJson(),
76
- },
77
- });
78
- }
79
- else if (!query.lastIds.includes(itemRef.getId())) {
80
- messages.push({
81
- type: 'add',
82
- data: { item: itemRef.toApiJson() },
83
- });
84
- }
85
- };
86
- try {
87
- for (currentItems_1 = tslib_1.__values(currentItems), currentItems_1_1 = currentItems_1.next(); !currentItems_1_1.done; currentItems_1_1 = currentItems_1.next()) {
88
- item = currentItems_1_1.value;
89
- _loop_2(item);
90
- }
78
+ else if (!query.lastIds.includes(itemRef.getId())) {
79
+ messages.push({
80
+ type: 'add',
81
+ data: { item: itemRef.toApiJson() },
82
+ });
91
83
  }
92
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
93
- finally {
94
- try {
95
- if (currentItems_1_1 && !currentItems_1_1.done && (_d = currentItems_1.return)) _d.call(currentItems_1);
96
- }
97
- finally { if (e_2) throw e_2.error; }
84
+ };
85
+ try {
86
+ for (currentItems_1 = tslib_1.__values(currentItems), currentItems_1_1 = currentItems_1.next(); !currentItems_1_1.done; currentItems_1_1 = currentItems_1.next()) {
87
+ item = currentItems_1_1.value;
88
+ _loop_2(item);
98
89
  }
99
- this.debugFileSaver({
100
- query: q.id,
101
- currentIds: currentIds,
102
- changes: changes,
103
- lastIds: query.lastIds,
104
- messages: messages,
105
- });
106
- query.lastIds = currentIds;
107
- return [4 /*yield*/, setData(query)];
108
- case 2:
109
- _e.sent();
110
- if (messages.length > 0)
111
- this.subscriptionServer().publishMessage(q.id, messages);
112
- return [2 /*return*/];
113
- }
114
- });
115
- }); })];
116
- case 1:
117
- _b.sent();
118
- return [2 /*return*/];
119
- }
120
- });
90
+ }
91
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
92
+ finally {
93
+ try {
94
+ if (currentItems_1_1 && !currentItems_1_1.done && (_d = currentItems_1.return)) _d.call(currentItems_1);
95
+ }
96
+ finally { if (e_2) throw e_2.error; }
97
+ }
98
+ this.debugFileSaver({
99
+ query: q.id,
100
+ currentIds: currentIds,
101
+ changes: changes,
102
+ lastIds: query.lastIds,
103
+ messages: messages,
104
+ });
105
+ query.lastIds = currentIds;
106
+ return [4 /*yield*/, setData(query)];
107
+ case 2:
108
+ _e.sent();
109
+ if (messages.length > 0)
110
+ this.subscriptionServer().publishMessage(q.id, messages);
111
+ return [2 /*return*/];
112
+ }
113
+ });
114
+ }); })];
115
+ case 1:
116
+ _c.sent();
117
+ return [2 /*return*/];
118
+ }
121
119
  });
122
- })];
120
+ }); })];
123
121
  case 1:
124
122
  _a.sent();
125
123
  return [2 /*return*/];
@@ -35,9 +35,7 @@ var RemultProxy = /** @class */ (function () {
35
35
  //@ts-ignore
36
36
  _a[repository_internals_js_1.getInternalKey] = function () {
37
37
  var _a;
38
- return (_a = self
39
- .remultFactory())
40
- .repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false))[repository_internals_js_1.getInternalKey]();
38
+ return (_a = self.remultFactory()).repo.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(args), false))[repository_internals_js_1.getInternalKey]();
41
39
  },
42
40
  _a.relations = function (args2) {
43
41
  var _a;
@@ -1,6 +1,6 @@
1
1
  import type { ClassType } from '../classType.js';
2
2
  import type { ClassHelper, Remult, RemultAsyncLocalStorage } from './context.js';
3
- import { DataProvider } from './data-interfaces';
3
+ import type { DataProvider } from './data-interfaces.js';
4
4
  import type { columnInfo } from './remult3/columnInfo.js';
5
5
  export declare const remultStatic: {
6
6
  defaultRemultFactory: () => Remult;
@@ -20,7 +20,7 @@ export declare const remultStatic: {
20
20
  };
21
21
  };
22
22
  captionTransformer: any;
23
- defaultDataProvider: () => Promise<DataProvider>;
23
+ defaultDataProvider: () => Promise<DataProvider | undefined>;
24
24
  };
25
25
  export declare function defaultFactory(): Remult;
26
26
  export declare function resetFactory(): void;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetFactory = exports.defaultFactory = exports.remultStatic = void 0;
3
+ exports.remultStatic = void 0;
4
+ exports.defaultFactory = defaultFactory;
5
+ exports.resetFactory = resetFactory;
4
6
  var remultStaticKey = Symbol.for('remult-static1');
5
7
  var x = {
6
8
  defaultRemultFactory: undefined,
@@ -22,11 +24,14 @@ var x = {
22
24
  }); },
23
25
  },
24
26
  captionTransformer: undefined,
25
- defaultDataProvider: function () { return undefined; },
27
+ defaultDataProvider: function () {
28
+ return undefined;
29
+ },
26
30
  };
27
31
  if ((typeof process !== 'undefined' &&
28
32
  process.env['IGNORE_GLOBAL_REMULT_IN_TESTS']) ||
29
33
  typeof globalThis[remultStaticKey] === 'undefined') {
34
+ ;
30
35
  globalThis[remultStaticKey] = x;
31
36
  x.remultFactory = function () { return defaultFactory(); };
32
37
  }
@@ -40,8 +45,6 @@ function defaultFactory() {
40
45
  }
41
46
  return exports.remultStatic.defaultRemult;
42
47
  }
43
- exports.defaultFactory = defaultFactory;
44
48
  function resetFactory() {
45
49
  exports.remultStatic.remultFactory = function () { return defaultFactory(); };
46
50
  }
47
- exports.resetFactory = resetFactory;
@@ -6,22 +6,22 @@ export declare class Fields {
6
6
  /**
7
7
  * Stored as a JSON.stringify - to store as json use Fields.json
8
8
  */
9
- static object<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
10
- static json<entityType = any, valueType = any>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
11
- static dateOnly<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
12
- static date<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
13
- static integer<entityType = any>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
14
- static autoIncrement<entityType = any>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
15
- static number<entityType = any>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
16
- static createdAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
17
- static updatedAt<entityType = any>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
18
- static uuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
9
+ static object<entityType = unknown, valueType = unknown>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
10
+ static json<entityType = unknown, valueType = unknown>(...options: (FieldOptions<entityType, valueType> | ((options: FieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
11
+ static dateOnly<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
12
+ static date<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
13
+ static integer<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
14
+ static autoIncrement<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
15
+ static number<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
16
+ static createdAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
17
+ static updatedAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
18
+ static uuid<entityType = unknown>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
19
19
  /**
20
20
  * A CUID (Collision Resistant Unique Identifier) field.
21
21
  * This id value is determined on the backend on insert, and can't be updated through the API.
22
22
  * The CUID is generated using the `@paralleldrive/cuid2` npm package.
23
23
  */
24
- static cuid<entityType = any>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
24
+ static cuid<entityType = unknown>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
25
25
  /**
26
26
  * Defines a field that can hold a value from a specified set of string literals.
27
27
  * @param {() => readonly valueType[]} optionalValues - A function that returns an array of allowed string literals.
@@ -51,10 +51,10 @@ export declare class Fields {
51
51
  *
52
52
  * // This approach allows easy management and updates of the allowed values for the `status` field.
53
53
  */
54
- static literal<entityType = any, valueType extends string = any>(optionalValues: () => readonly valueType[], ...options: (StringFieldOptions<entityType, valueType> | ((options: StringFieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
55
- static enum<entityType = any, theEnum = any>(enumType: () => theEnum, ...options: (FieldOptions<entityType, theEnum[keyof theEnum]> | ((options: FieldOptions<entityType, theEnum[keyof theEnum]>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, theEnum[keyof theEnum] | undefined>;
56
- static string<entityType = any, valueType = string>(...options: (StringFieldOptions<entityType, valueType> | ((options: StringFieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
57
- static boolean<entityType = any>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
54
+ static literal<entityType = unknown, valueType extends string = string>(optionalValues: () => readonly valueType[], ...options: (StringFieldOptions<entityType, valueType> | ((options: StringFieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
55
+ static enum<entityType = unknown, theEnum = object>(enumType: () => theEnum, ...options: (FieldOptions<entityType, theEnum[keyof theEnum]> | ((options: FieldOptions<entityType, theEnum[keyof theEnum]>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, theEnum[keyof theEnum] | undefined>;
56
+ static string<entityType = unknown, valueType = string>(...options: (StringFieldOptions<entityType, valueType> | ((options: StringFieldOptions<entityType, valueType>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, valueType | undefined>;
57
+ static boolean<entityType = unknown>(...options: (FieldOptions<entityType, boolean> | ((options: FieldOptions<entityType, boolean>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, boolean | undefined>;
58
58
  }
59
59
  export declare class Relations {
60
60
  /**
@@ -162,8 +162,8 @@ export declare class Relations {
162
162
  * @Fields.string((options,remult) => options.includeInApi = true)
163
163
  * title='';
164
164
  */
165
- export declare function Field<entityType = any, valueType = any>(valueType: (() => valueType extends number ? Number : valueType extends string ? String : valueType extends boolean ? Boolean : 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;
166
- export interface StringFieldOptions<entityType = any, valueType = string> extends FieldOptions<entityType, valueType> {
165
+ export declare function Field<entityType = unknown, valueType = unknown>(valueType: (() => valueType extends number ? Number : valueType extends string ? String : valueType extends boolean ? Boolean : 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;
166
+ export interface StringFieldOptions<entityType = unknown, valueType = string> extends FieldOptions<entityType, valueType> {
167
167
  maxLength?: number;
168
168
  minLength?: number;
169
169
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkTarget = exports.Field = exports.Relations = exports.Fields = void 0;
3
+ exports.Relations = exports.Fields = void 0;
4
+ exports.Field = Field;
5
+ exports.checkTarget = checkTarget;
4
6
  var tslib_1 = require("tslib");
5
7
  var cuid2_1 = require("@paralleldrive/cuid2");
6
8
  var uuid_1 = require("uuid");
@@ -10,6 +12,7 @@ var validators_js_1 = require("../validators.js");
10
12
  var relationInfoMember_js_1 = require("./relationInfoMember.js");
11
13
  var remult_static_js_1 = require("../remult-static.js");
12
14
  var addValidator_js_1 = require("./addValidator.js");
15
+ var isOfType_js_1 = require("../isOfType.js");
13
16
  var validateNumber = (0, validators_js_1.createValueValidator)(function (x) {
14
17
  return !isNaN(x) && isFinite(x);
15
18
  });
@@ -155,7 +158,7 @@ var Fields = /** @class */ (function () {
155
158
  },
156
159
  }], tslib_1.__read(options), false));
157
160
  };
158
- // static id<entityType = any>(
161
+ // static id<entityType = unknown>(
159
162
  // options?: FieldOptions<entityType, string> & { idFactory?: () => string },
160
163
  // ): ClassFieldDecorator<entityType, string | undefined> {
161
164
  // let buildId = options?.idFactory ?? createId
@@ -218,14 +221,16 @@ var Fields = /** @class */ (function () {
218
221
  options[_i - 1] = arguments[_i];
219
222
  }
220
223
  var valueConverter;
221
- return Field.apply(void 0, tslib_1.__spreadArray(tslib_1.__spreadArray([function () {
222
- //@ts-ignore
223
- return (enumType());
224
- }, (_a = {
225
- validate: function (entity, event) { return validators_js_1.Validators.enum(enumType())(entity, event); }
224
+ return Field.apply(void 0, tslib_1.__spreadArray(tslib_1.__spreadArray([
225
+ //@ts-ignore
226
+ function () { return enumType(); }, (_a = {
227
+ validate: function (entity, event) {
228
+ return validators_js_1.Validators.enum(enumType())(entity, event);
229
+ }
226
230
  },
227
231
  _a[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = function () { return (0, validators_js_1.getEnumValues)(enumType()); },
228
232
  _a)], tslib_1.__read(options), false), [function (options) {
233
+ ;
229
234
  options[RepositoryImplementation_js_1.fieldOptionalValuesFunctionKey] = function () {
230
235
  return (0, validators_js_1.getEnumValues)(enumType());
231
236
  };
@@ -354,11 +359,17 @@ function Field(valueType) {
354
359
  if (r.required) {
355
360
  r.validate = (0, addValidator_js_1.addValidator)(r.validate, validators_js_1.Validators.required, true);
356
361
  }
357
- if (r.maxLength) {
358
- r.validate = (0, addValidator_js_1.addValidator)(r.validate, validators_js_1.Validators.maxLength(r.maxLength));
362
+ if ((0, isOfType_js_1.isOfType)(r, 'maxLength')) {
363
+ var z = r;
364
+ if (z.maxLength) {
365
+ z.validate = (0, addValidator_js_1.addValidator)(z.validate, validators_js_1.Validators.maxLength(z.maxLength));
366
+ }
359
367
  }
360
- if (r.minLength) {
361
- r.validate = (0, addValidator_js_1.addValidator)(r.validate, validators_js_1.Validators.minLength(r.minLength));
368
+ if ((0, isOfType_js_1.isOfType)(r, 'minLength')) {
369
+ var z = r;
370
+ if (z.minLength) {
371
+ z.validate = (0, addValidator_js_1.addValidator)(z.validate, validators_js_1.Validators.minLength(z.minLength));
372
+ }
362
373
  }
363
374
  if (!r.valueType && valueType) {
364
375
  r.valueType = valueType();
@@ -402,9 +413,7 @@ function Field(valueType) {
402
413
  }
403
414
  };
404
415
  }
405
- exports.Field = Field;
406
416
  function checkTarget(target) {
407
417
  if (!target)
408
418
  throw new Error("Set the 'experimentalDecorators:true' option in your 'tsconfig' or 'jsconfig' (target undefined)");
409
419
  }
410
- exports.checkTarget = checkTarget;