remult 3.0.6 → 3.1.0-next.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.
- package/README.md +2 -2
- package/SseSubscriptionServer.js +1 -2
- package/async-hooks.d.ts +26 -1
- package/async-hooks.js +31 -2
- package/esm/SseSubscriptionServer.js +1 -2
- package/esm/async-hooks.js +31 -1
- package/esm/remult-express.js +13 -4
- package/esm/server/get-remult-admin-html.js +1 -1
- package/esm/server/initAsyncHooks.js +0 -25
- package/esm/src/live-query/SubscriptionChannel.js +1 -2
- package/esm/src/remult-static.js +1 -0
- package/esm/src/remult3/Fields.js +54 -33
- package/esm/src/remult3/IdEntity.js +1 -1
- package/esm/src/remult3/entity.js +1 -1
- package/esm/src/server-action.js +5 -4
- package/package.json +5 -4
- package/remult-express.js +13 -4
- package/server/get-remult-admin-html.js +1 -1
- package/server/initAsyncHooks.d.ts +0 -25
- package/server/initAsyncHooks.js +0 -25
- package/server/remult-api-server.d.ts +1 -1
- package/src/column-interfaces.d.ts +4 -3
- package/src/live-query/SubscriptionChannel.js +1 -2
- package/src/remult-static.d.ts +1 -0
- package/src/remult-static.js +1 -0
- package/src/remult3/Fields.d.ts +34 -4
- package/src/remult3/Fields.js +56 -44
- package/src/remult3/IdEntity.js +1 -1
- package/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/src/remult3/entity.d.ts +1 -1
- package/src/remult3/entity.js +1 -1
- package/src/server-action.d.ts +0 -1
- package/src/server-action.js +5 -4
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
import { type RemultAsyncLocalStorageCore } from '../src/context.js';
|
|
2
|
-
/**
|
|
3
|
-
* Initializes async context tracking for the server.
|
|
4
|
-
*
|
|
5
|
-
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
6
|
-
* @example
|
|
7
|
-
* import { remult, repo, withRemult } from 'remult';
|
|
8
|
-
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
9
|
-
*
|
|
10
|
-
* import { Task } from './entities/Task.js';
|
|
11
|
-
*
|
|
12
|
-
* initAsyncHooks();
|
|
13
|
-
*
|
|
14
|
-
* // Thx to the `initAsyncHooks` above,
|
|
15
|
-
* // we have isolated async contexts with multiple `withRemult()`,
|
|
16
|
-
* // without needing to initialize a `remultApi` all the time!
|
|
17
|
-
* withRemult(async () => {
|
|
18
|
-
* remult.user = { id: '42' };
|
|
19
|
-
* repo(Task).find()
|
|
20
|
-
* });
|
|
21
|
-
*
|
|
22
|
-
* withRemult(async () => {
|
|
23
|
-
* remult.user = { id: '21' };
|
|
24
|
-
* repo(Task).find()
|
|
25
|
-
* });
|
|
26
|
-
*/
|
|
27
2
|
export declare function initAsyncHooks(): void;
|
|
28
3
|
export declare class AsyncLocalStorageBridgeToRemultAsyncLocalStorageCoreImpl<T> implements RemultAsyncLocalStorageCore<T> {
|
|
29
4
|
private asyncLocalStorage;
|
package/server/initAsyncHooks.js
CHANGED
|
@@ -7,31 +7,6 @@ var async_hooks_1 = require("async_hooks");
|
|
|
7
7
|
var context_js_1 = require("../src/context.js");
|
|
8
8
|
var remult_static_js_1 = require("../src/remult-static.js");
|
|
9
9
|
var init = false;
|
|
10
|
-
/**
|
|
11
|
-
* Initializes async context tracking for the server.
|
|
12
|
-
*
|
|
13
|
-
* This should be called before handling any incoming requests or calling `withRemult()`.
|
|
14
|
-
* @example
|
|
15
|
-
* import { remult, repo, withRemult } from 'remult';
|
|
16
|
-
* import { initAsyncHooks } from 'remult/async-hooks';
|
|
17
|
-
*
|
|
18
|
-
* import { Task } from './entities/Task.js';
|
|
19
|
-
*
|
|
20
|
-
* initAsyncHooks();
|
|
21
|
-
*
|
|
22
|
-
* // Thx to the `initAsyncHooks` above,
|
|
23
|
-
* // we have isolated async contexts with multiple `withRemult()`,
|
|
24
|
-
* // without needing to initialize a `remultApi` all the time!
|
|
25
|
-
* withRemult(async () => {
|
|
26
|
-
* remult.user = { id: '42' };
|
|
27
|
-
* repo(Task).find()
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* withRemult(async () => {
|
|
31
|
-
* remult.user = { id: '21' };
|
|
32
|
-
* repo(Task).find()
|
|
33
|
-
* });
|
|
34
|
-
*/
|
|
35
10
|
function initAsyncHooks() {
|
|
36
11
|
var _this = this;
|
|
37
12
|
if (init)
|
|
@@ -94,7 +94,7 @@ export interface RemultServerOptions<RequestType> {
|
|
|
94
94
|
sendError: (httpStatusCode: number, body: any) => void;
|
|
95
95
|
}) => Promise<void> | undefined;
|
|
96
96
|
/**
|
|
97
|
-
* Modules are here to group code by feature.
|
|
97
|
+
* Modules are here to group code by feature. [Module Guide](https://remult.dev/docs/modules)
|
|
98
98
|
*
|
|
99
99
|
* @example
|
|
100
100
|
* import { Module } from 'remult/server'
|
|
@@ -12,11 +12,12 @@ export interface FieldOptions<entityType = unknown, valueType = unknown> {
|
|
|
12
12
|
* <input placeholder={taskRepo.metadata.fields.title.label}/>
|
|
13
13
|
*/
|
|
14
14
|
label?: string;
|
|
15
|
-
/** If it can store null in the database */
|
|
15
|
+
/** If it can store `null` in the database. @default false */
|
|
16
16
|
allowNull?: boolean;
|
|
17
17
|
/** If a value is required. Short-cut to say `validate: Validators.required`.
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
* @default false
|
|
19
|
+
* @see option [validate](https://remult.dev/docs/ref_field#validate)
|
|
20
|
+
* @see validator [required](https://remult.dev/docs/ref_validators#required)
|
|
20
21
|
*/
|
|
21
22
|
required?: boolean;
|
|
22
23
|
/**
|
|
@@ -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 = (
|
|
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
|
}
|
package/src/remult-static.d.ts
CHANGED
package/src/remult-static.js
CHANGED
package/src/remult3/Fields.d.ts
CHANGED
|
@@ -15,13 +15,43 @@ export declare class Fields {
|
|
|
15
15
|
static number<entityType = unknown>(...options: (FieldOptions<entityType, number> | ((options: FieldOptions<entityType, number>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, number | undefined>;
|
|
16
16
|
static createdAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
17
17
|
static updatedAt<entityType = unknown>(...options: (FieldOptions<entityType, Date> | ((options: FieldOptions<entityType, Date>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, Date | undefined>;
|
|
18
|
+
/** @deprecated use `@Fields.id()` instead */
|
|
18
19
|
static uuid<entityType = unknown>(...options: (FieldOptions<entityType, string> | ((options: FieldOptions<entityType, string>, remult: Remult) => void))[]): ClassFieldDecorator<entityType, string | undefined>;
|
|
20
|
+
private static _defaultIdFactory;
|
|
21
|
+
static get defaultIdFactory(): () => string;
|
|
22
|
+
static set defaultIdFactory(value: () => string);
|
|
19
23
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
24
|
+
* Defines a field that will be used as the id of the entity.
|
|
25
|
+
* By default it will use `crypto.randomUUID` to generate the id.
|
|
26
|
+
*
|
|
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.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { createId } from '@paralleldrive/cuid2'
|
|
34
|
+
* Fields.defaultIdFactory = () => createId()
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* You can also pass an id factory as an option to the `@Fields.id` to have a different value locally.
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { createId } from '@paralleldrive/cuid2'
|
|
41
|
+
* // import { v4 as uuid } from 'uuid'
|
|
42
|
+
*
|
|
43
|
+
* class MyEntity {
|
|
44
|
+
* \@Fields.id({
|
|
45
|
+
* idFactory: () => createId()
|
|
46
|
+
* // idFactory: () => uuid()
|
|
47
|
+
* })
|
|
48
|
+
* id: string = '';
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
23
51
|
*/
|
|
24
|
-
static
|
|
52
|
+
static id<entityType = unknown>(options?: FieldOptions<entityType, string> & {
|
|
53
|
+
idFactory?: () => string;
|
|
54
|
+
}): ClassFieldDecorator<entityType, string | undefined>;
|
|
25
55
|
/**
|
|
26
56
|
* Defines a field that can hold a value from a specified set of string literals.
|
|
27
57
|
* @param {() => readonly valueType[]} optionalValues - A function that returns an array of allowed string literals.
|
package/src/remult3/Fields.js
CHANGED
|
@@ -4,8 +4,6 @@ exports.Relations = exports.Fields = void 0;
|
|
|
4
4
|
exports.Field = Field;
|
|
5
5
|
exports.checkTarget = checkTarget;
|
|
6
6
|
var tslib_1 = require("tslib");
|
|
7
|
-
var cuid2_1 = require("@paralleldrive/cuid2");
|
|
8
|
-
var uuid_1 = require("uuid");
|
|
9
7
|
var valueConverters_js_1 = require("../valueConverters.js");
|
|
10
8
|
var RepositoryImplementation_js_1 = require("./RepositoryImplementation.js");
|
|
11
9
|
var validators_js_1 = require("../validators.js");
|
|
@@ -128,53 +126,62 @@ var Fields = /** @class */ (function () {
|
|
|
128
126
|
},
|
|
129
127
|
}], tslib_1.__read(options), false));
|
|
130
128
|
};
|
|
129
|
+
/** @deprecated use `@Fields.id()` instead */
|
|
131
130
|
Fields.uuid = function () {
|
|
132
131
|
var options = [];
|
|
133
132
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
134
133
|
options[_i] = arguments[_i];
|
|
135
134
|
}
|
|
136
|
-
return
|
|
137
|
-
{
|
|
138
|
-
allowApiUpdate: false,
|
|
139
|
-
defaultValue: function () { return (0, uuid_1.v4)(); },
|
|
140
|
-
saving: function (_, r) {
|
|
141
|
-
if (!r.value)
|
|
142
|
-
r.value = (0, uuid_1.v4)();
|
|
143
|
-
},
|
|
144
|
-
}], tslib_1.__read(options), false));
|
|
135
|
+
return Fields.id(tslib_1.__assign({ idFactory: function () { return crypto.randomUUID(); } }, options));
|
|
145
136
|
};
|
|
137
|
+
Object.defineProperty(Fields, "defaultIdFactory", {
|
|
138
|
+
get: function () {
|
|
139
|
+
return this._defaultIdFactory;
|
|
140
|
+
},
|
|
141
|
+
set: function (value) {
|
|
142
|
+
this._defaultIdFactory = value;
|
|
143
|
+
remult_static_js_1.remultStatic.defaultIdFactory = value;
|
|
144
|
+
},
|
|
145
|
+
enumerable: false,
|
|
146
|
+
configurable: true
|
|
147
|
+
});
|
|
146
148
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
149
|
+
* Defines a field that will be used as the id of the entity.
|
|
150
|
+
* By default it will use `crypto.randomUUID` to generate the id.
|
|
151
|
+
*
|
|
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.
|
|
156
|
+
*
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { createId } from '@paralleldrive/cuid2'
|
|
159
|
+
* Fields.defaultIdFactory = () => createId()
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* You can also pass an id factory as an option to the `@Fields.id` to have a different value locally.
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* import { createId } from '@paralleldrive/cuid2'
|
|
166
|
+
* // import { v4 as uuid } from 'uuid'
|
|
167
|
+
*
|
|
168
|
+
* class MyEntity {
|
|
169
|
+
* \@Fields.id({
|
|
170
|
+
* idFactory: () => createId()
|
|
171
|
+
* // idFactory: () => uuid()
|
|
172
|
+
* })
|
|
173
|
+
* id: string = '';
|
|
174
|
+
* }
|
|
175
|
+
* ```
|
|
150
176
|
*/
|
|
151
|
-
Fields.
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
allowApiUpdate: false,
|
|
159
|
-
defaultValue: function () { return (0, cuid2_1.createId)(); },
|
|
160
|
-
saving: function (_, r) {
|
|
161
|
-
if (!r.value)
|
|
162
|
-
r.value = (0, cuid2_1.createId)();
|
|
163
|
-
},
|
|
164
|
-
}], tslib_1.__read(options), false));
|
|
177
|
+
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 idFactory(); }, saving: function (_, r) {
|
|
181
|
+
if (!r.value)
|
|
182
|
+
r.value = idFactory();
|
|
183
|
+
} }, options));
|
|
165
184
|
};
|
|
166
|
-
// static id<entityType = unknown>(
|
|
167
|
-
// options?: FieldOptions<entityType, string> & { idFactory?: () => string },
|
|
168
|
-
// ): ClassFieldDecorator<entityType, string | undefined> {
|
|
169
|
-
// let buildId = options?.idFactory ?? createId
|
|
170
|
-
// return Field(() => String, {
|
|
171
|
-
// allowApiUpdate: false,
|
|
172
|
-
// defaultValue: () => buildId(),
|
|
173
|
-
// saving: (_, r) => {
|
|
174
|
-
// if (!r.value) r.value = buildId()
|
|
175
|
-
// },
|
|
176
|
-
// })
|
|
177
|
-
// }
|
|
178
185
|
/**
|
|
179
186
|
* Defines a field that can hold a value from a specified set of string literals.
|
|
180
187
|
* @param {() => readonly valueType[]} optionalValues - A function that returns an array of allowed string literals.
|
|
@@ -269,9 +276,12 @@ var Fields = /** @class */ (function () {
|
|
|
269
276
|
}
|
|
270
277
|
return Field.apply(void 0, tslib_1.__spreadArray([function () { return Boolean; }], tslib_1.__read(options), false));
|
|
271
278
|
};
|
|
279
|
+
Fields._defaultIdFactory = function () { return crypto.randomUUID(); };
|
|
272
280
|
return Fields;
|
|
273
281
|
}());
|
|
274
282
|
exports.Fields = Fields;
|
|
283
|
+
// Initialize remultStatic.defaultIdFactory with the default value
|
|
284
|
+
remult_static_js_1.remultStatic.defaultIdFactory = Fields.defaultIdFactory;
|
|
275
285
|
var Relations = /** @class */ (function () {
|
|
276
286
|
function Relations() {
|
|
277
287
|
}
|
|
@@ -386,10 +396,12 @@ function Field(valueType) {
|
|
|
386
396
|
r.dbName = r.key;
|
|
387
397
|
var type = r.valueType;
|
|
388
398
|
if (!type) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
399
|
+
// removing import 'reflect-metadata' from server-action.ts, so we return an empty array
|
|
400
|
+
type = undefined;
|
|
401
|
+
// type =
|
|
402
|
+
// typeof Reflect.getMetadata == 'function'
|
|
403
|
+
// ? Reflect.getMetadata('design:type', target, key)
|
|
404
|
+
// : []
|
|
393
405
|
r.valueType = type;
|
|
394
406
|
}
|
|
395
407
|
if (!r.target)
|
package/src/remult3/IdEntity.js
CHANGED
|
@@ -10,7 +10,7 @@ var IdEntity = /** @class */ (function (_super) {
|
|
|
10
10
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
11
11
|
}
|
|
12
12
|
tslib_1.__decorate([
|
|
13
|
-
Fields_js_1.Fields.
|
|
13
|
+
Fields_js_1.Fields.id(),
|
|
14
14
|
tslib_1.__metadata("design:type", String)
|
|
15
15
|
], IdEntity.prototype, "id", void 0);
|
|
16
16
|
return IdEntity;
|
|
@@ -243,7 +243,7 @@ export declare const LabelTransformer: {
|
|
|
243
243
|
*/
|
|
244
244
|
transformLabel: (remult: Remult, key: string, label: string, entityMetaData: EntityMetadata<any>) => string;
|
|
245
245
|
/**
|
|
246
|
-
* @
|
|
246
|
+
* @deprecated use LabelTransformer.transformLabel instead
|
|
247
247
|
*/
|
|
248
248
|
transformCaption: (remult: Remult, key: string, label: string, entityMetaData: EntityMetadata<any>) => string;
|
|
249
249
|
};
|
package/src/remult3/entity.d.ts
CHANGED
package/src/remult3/entity.js
CHANGED
package/src/server-action.d.ts
CHANGED
package/src/server-action.js
CHANGED
|
@@ -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
|
-
|
|
218
|
-
|
|
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'
|