remult 3.0.7-next.0 → 3.1.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.
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SubscriptionChannel = exports.liveQueryKeepAliveRoute = exports.LiveQuerySubscriber = exports.streamUrl = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var uuid_1 = require("uuid");
6
5
  var sort_js_1 = require("../sort.js");
7
6
  var remult_proxy_js_1 = require("../remult-proxy.js");
8
7
  var repository_internals_js_1 = require("../remult3/repository-internals.js");
@@ -15,7 +14,7 @@ var LiveQuerySubscriber = /** @class */ (function () {
15
14
  this.unsubscribe = function () { };
16
15
  this.defaultQueryState = [];
17
16
  this.listeners = [];
18
- this.id = (0, uuid_1.v4)();
17
+ this.id = String(crypto.randomUUID());
19
18
  this.queryChannel = "users:".concat(userId, ":queries:").concat(this.id);
20
19
  this.id = this.queryChannel;
21
20
  }
@@ -17,33 +17,55 @@ export declare class Fields {
17
17
  static updatedAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
18
18
  /** @deprecated use `@Fields.id()` instead */
19
19
  static uuid<entityType = unknown>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
20
- private static _defaultIdFactory;
20
+ /**
21
+ * ### cuid
22
+ * @example
23
+ * ```ts
24
+ * import { Fields } from 'remult'
25
+ * import { createId } from '@paralleldrive/cuid2'
26
+ * Fields.defaultIdFactory = () => createId()
27
+ * ```
28
+ *
29
+ * ### nanoid
30
+ * @example
31
+ * ```ts
32
+ * import { Fields } from 'remult'
33
+ * import { nanoid } from 'nanoid'
34
+ * Fields.defaultIdFactory = () => nanoid()
35
+ * ```
36
+ *
37
+ */
21
38
  static get defaultIdFactory(): () => string;
22
39
  static set defaultIdFactory(value: () => string);
23
40
  /**
41
+ * ### Default
24
42
  * Defines a field that will be used as the id of the entity.
25
43
  * By default it will use `crypto.randomUUID` to generate the id.
26
44
  *
27
- * You can change the algorithm used to generate the id by setting the `Fields.defaultIdFactory`
28
- * to a different function like:
29
- *
30
- * This needs to be done in a shared file to be accessible frontend and backend.
45
+ * ---
46
+ * ### Global `IdFactory`
47
+ * You can change the algorithm used to generate the id by setting `Fields.defaultIdFactory`
48
+ * globally. This code needs to be in a shared file to be accessible frontend and backend.
31
49
  *
32
50
  * ```ts
33
51
  * import { createId } from '@paralleldrive/cuid2'
34
52
  * Fields.defaultIdFactory = () => createId()
35
53
  * ```
36
54
  *
37
- * You can also pass an id factory as an option to the `@Fields.id` to have a different value locally.
55
+ * ---
56
+ * ### Local `IdFactory`
57
+ * You can also pass an `idFactory` as an option to the `@Fields.id` to have a different value on this field.
38
58
  * @example
39
59
  * ```ts
40
60
  * import { createId } from '@paralleldrive/cuid2'
41
61
  * // import { v4 as uuid } from 'uuid'
62
+ * // import { nanoid } from 'nanoid'
42
63
  *
43
64
  * class MyEntity {
44
65
  * \@Fields.id({
45
66
  * idFactory: () => createId()
46
67
  * // idFactory: () => uuid()
68
+ * // idFactory: () => nanoid()
47
69
  * })
48
70
  * id: string = '';
49
71
  * }
@@ -135,51 +135,79 @@ var Fields = /** @class */ (function () {
135
135
  return Fields.id(tslib_1.__assign({ idFactory: function () { return crypto.randomUUID(); } }, options));
136
136
  };
137
137
  Object.defineProperty(Fields, "defaultIdFactory", {
138
+ /**
139
+ * ### cuid
140
+ * @example
141
+ * ```ts
142
+ * import { Fields } from 'remult'
143
+ * import { createId } from '@paralleldrive/cuid2'
144
+ * Fields.defaultIdFactory = () => createId()
145
+ * ```
146
+ *
147
+ * ### nanoid
148
+ * @example
149
+ * ```ts
150
+ * import { Fields } from 'remult'
151
+ * import { nanoid } from 'nanoid'
152
+ * Fields.defaultIdFactory = () => nanoid()
153
+ * ```
154
+ *
155
+ */
138
156
  get: function () {
139
- return this._defaultIdFactory;
157
+ var _a;
158
+ return ((_a = remult_static_js_1.remultStatic.defaultIdFactory) !== null && _a !== void 0 ? _a : (remult_static_js_1.remultStatic.defaultIdFactory = function () { return crypto.randomUUID(); }));
140
159
  },
141
160
  set: function (value) {
142
- this._defaultIdFactory = value;
143
161
  remult_static_js_1.remultStatic.defaultIdFactory = value;
144
162
  },
145
163
  enumerable: false,
146
164
  configurable: true
147
165
  });
148
166
  /**
167
+ * ### Default
149
168
  * Defines a field that will be used as the id of the entity.
150
169
  * By default it will use `crypto.randomUUID` to generate the id.
151
170
  *
152
- * You can change the algorithm used to generate the id by setting the `Fields.defaultIdFactory`
153
- * to a different function like:
154
- *
155
- * This needs to be done in a shared file to be accessible frontend and backend.
171
+ * ---
172
+ * ### Global `IdFactory`
173
+ * You can change the algorithm used to generate the id by setting `Fields.defaultIdFactory`
174
+ * globally. This code needs to be in a shared file to be accessible frontend and backend.
156
175
  *
157
176
  * ```ts
158
177
  * import { createId } from '@paralleldrive/cuid2'
159
178
  * Fields.defaultIdFactory = () => createId()
160
179
  * ```
161
180
  *
162
- * You can also pass an id factory as an option to the `@Fields.id` to have a different value locally.
181
+ * ---
182
+ * ### Local `IdFactory`
183
+ * You can also pass an `idFactory` as an option to the `@Fields.id` to have a different value on this field.
163
184
  * @example
164
185
  * ```ts
165
186
  * import { createId } from '@paralleldrive/cuid2'
166
187
  * // import { v4 as uuid } from 'uuid'
188
+ * // import { nanoid } from 'nanoid'
167
189
  *
168
190
  * class MyEntity {
169
191
  * \@Fields.id({
170
192
  * idFactory: () => createId()
171
193
  * // idFactory: () => uuid()
194
+ * // idFactory: () => nanoid()
172
195
  * })
173
196
  * id: string = '';
174
197
  * }
175
198
  * ```
176
199
  */
177
200
  Fields.id = function (options) {
178
- var _a;
179
- var idFactory = (_a = options === null || options === void 0 ? void 0 : options.idFactory) !== null && _a !== void 0 ? _a : remult_static_js_1.remultStatic.defaultIdFactory;
180
- return Field(function () { return String; }, tslib_1.__assign({ allowApiUpdate: false, defaultValue: function () { return ((options === null || options === void 0 ? void 0 : options.allowNull) ? null : idFactory()); }, saving: function (_, r) {
181
- if (!r.value && !(options === null || options === void 0 ? void 0 : options.allowNull))
201
+ return Field(function () { return String; }, tslib_1.__assign({ allowApiUpdate: false, defaultValue: function () {
202
+ var _a;
203
+ var idFactory = (_a = options === null || options === void 0 ? void 0 : options.idFactory) !== null && _a !== void 0 ? _a : Fields.defaultIdFactory;
204
+ return idFactory();
205
+ }, saving: function (_, r) {
206
+ var _a;
207
+ if (!r.value) {
208
+ var idFactory = (_a = options === null || options === void 0 ? void 0 : options.idFactory) !== null && _a !== void 0 ? _a : Fields.defaultIdFactory;
182
209
  r.value = idFactory();
210
+ }
183
211
  } }, options));
184
212
  };
185
213
  /**
@@ -276,12 +304,9 @@ var Fields = /** @class */ (function () {
276
304
  }
277
305
  return Field.apply(void 0, tslib_1.__spreadArray([function () { return Boolean; }], tslib_1.__read(options), false));
278
306
  };
279
- Fields._defaultIdFactory = function () { return crypto.randomUUID(); };
280
307
  return Fields;
281
308
  }());
282
309
  exports.Fields = Fields;
283
- // Initialize remultStatic.defaultIdFactory with the default value
284
- remult_static_js_1.remultStatic.defaultIdFactory = Fields.defaultIdFactory;
285
310
  var Relations = /** @class */ (function () {
286
311
  function Relations() {
287
312
  }
@@ -396,10 +421,12 @@ function Field(valueType) {
396
421
  r.dbName = r.key;
397
422
  var type = r.valueType;
398
423
  if (!type) {
399
- type =
400
- typeof Reflect.getMetadata == 'function'
401
- ? Reflect.getMetadata('design:type', target, key)
402
- : [];
424
+ // removing import 'reflect-metadata' from server-action.ts, so we return an empty array
425
+ type = undefined;
426
+ // type =
427
+ // typeof Reflect.getMetadata == 'function'
428
+ // ? Reflect.getMetadata('design:type', target, key)
429
+ // : []
403
430
  r.valueType = type;
404
431
  }
405
432
  if (!r.target)
@@ -1,4 +1,3 @@
1
- import 'reflect-metadata';
2
1
  import type { AllowedForInstance } from './context.js';
3
2
  import { Remult } from './context.js';
4
3
  import type { DataApiResponse } from './data-api.js';
@@ -6,7 +6,6 @@ exports.BackendMethod = BackendMethod;
6
6
  exports.prepareArgsToSend = prepareArgsToSend;
7
7
  exports.prepareReceivedArgs = prepareReceivedArgs;
8
8
  var tslib_1 = require("tslib");
9
- require("reflect-metadata");
10
9
  var buildRestDataProvider_js_1 = require("./buildRestDataProvider.js");
11
10
  var context_js_1 = require("./context.js");
12
11
  var sql_database_js_1 = require("./data-providers/sql-database.js");
@@ -214,9 +213,11 @@ function BackendMethod(options) {
214
213
  var result = originalMethod;
215
214
  (0, Fields_js_1.checkTarget)(target);
216
215
  function getTypes() {
217
- var types = typeof Reflect.getMetadata == 'function'
218
- ? Reflect.getMetadata('design:paramtypes', target, key)
219
- : [];
216
+ // removing import 'reflect-metadata' from server-action.ts, so we return an empty array
217
+ var types = [];
218
+ // typeof Reflect.getMetadata == 'function'
219
+ // ? Reflect.getMetadata('design:paramtypes', target, key)
220
+ // : []
220
221
  if (options.paramTypes)
221
222
  types =
222
223
  typeof options.paramTypes === 'function'