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.
- package/SseSubscriptionServer.js +1 -2
- package/esm/SseSubscriptionServer.js +1 -2
- package/esm/server/get-remult-admin-html.js +1 -1
- package/esm/src/live-query/SubscriptionChannel.js +1 -2
- package/esm/src/remult3/Fields.js +43 -17
- package/esm/src/server-action.js +5 -4
- package/package.json +1 -2
- package/server/get-remult-admin-html.js +1 -1
- package/src/live-query/SubscriptionChannel.js +1 -2
- package/src/remult3/Fields.d.ts +28 -6
- package/src/remult3/Fields.js +45 -18
- package/src/server-action.d.ts +0 -1
- package/src/server-action.js +5 -4
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { v4 as uuid } from 'uuid';
|
|
2
1
|
import { Sort } from '../sort.js';
|
|
3
2
|
import { remult as defaultRemult } from '../remult-proxy.js';
|
|
4
3
|
import { getRepositoryInternals } from '../remult3/repository-internals.js';
|
|
@@ -92,7 +91,7 @@ export class LiveQuerySubscriber {
|
|
|
92
91
|
}
|
|
93
92
|
defaultQueryState = [];
|
|
94
93
|
listeners = [];
|
|
95
|
-
id =
|
|
94
|
+
id = String(crypto.randomUUID());
|
|
96
95
|
constructor(repo, query, userId) {
|
|
97
96
|
this.repo = repo;
|
|
98
97
|
this.query = query;
|
|
@@ -84,51 +84,77 @@ export class Fields {
|
|
|
84
84
|
...options,
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
/**
|
|
88
|
+
* ### cuid
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { Fields } from 'remult'
|
|
92
|
+
* import { createId } from '@paralleldrive/cuid2'
|
|
93
|
+
* Fields.defaultIdFactory = () => createId()
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* ### nanoid
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { Fields } from 'remult'
|
|
100
|
+
* import { nanoid } from 'nanoid'
|
|
101
|
+
* Fields.defaultIdFactory = () => nanoid()
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
88
105
|
static get defaultIdFactory() {
|
|
89
|
-
return
|
|
106
|
+
return (remultStatic.defaultIdFactory ??
|
|
107
|
+
(remultStatic.defaultIdFactory = () => crypto.randomUUID()));
|
|
90
108
|
}
|
|
91
109
|
static set defaultIdFactory(value) {
|
|
92
|
-
this._defaultIdFactory = value;
|
|
93
110
|
remultStatic.defaultIdFactory = value;
|
|
94
111
|
}
|
|
95
112
|
/**
|
|
113
|
+
* ### Default
|
|
96
114
|
* Defines a field that will be used as the id of the entity.
|
|
97
115
|
* By default it will use `crypto.randomUUID` to generate the id.
|
|
98
116
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* This needs to be
|
|
117
|
+
* ---
|
|
118
|
+
* ### Global `IdFactory`
|
|
119
|
+
* You can change the algorithm used to generate the id by setting `Fields.defaultIdFactory`
|
|
120
|
+
* globally. This code needs to be in a shared file to be accessible frontend and backend.
|
|
103
121
|
*
|
|
104
122
|
* ```ts
|
|
105
123
|
* import { createId } from '@paralleldrive/cuid2'
|
|
106
124
|
* Fields.defaultIdFactory = () => createId()
|
|
107
125
|
* ```
|
|
108
126
|
*
|
|
109
|
-
*
|
|
127
|
+
* ---
|
|
128
|
+
* ### Local `IdFactory`
|
|
129
|
+
* You can also pass an `idFactory` as an option to the `@Fields.id` to have a different value on this field.
|
|
110
130
|
* @example
|
|
111
131
|
* ```ts
|
|
112
132
|
* import { createId } from '@paralleldrive/cuid2'
|
|
113
133
|
* // import { v4 as uuid } from 'uuid'
|
|
134
|
+
* // import { nanoid } from 'nanoid'
|
|
114
135
|
*
|
|
115
136
|
* class MyEntity {
|
|
116
137
|
* \@Fields.id({
|
|
117
138
|
* idFactory: () => createId()
|
|
118
139
|
* // idFactory: () => uuid()
|
|
140
|
+
* // idFactory: () => nanoid()
|
|
119
141
|
* })
|
|
120
142
|
* id: string = '';
|
|
121
143
|
* }
|
|
122
144
|
* ```
|
|
123
145
|
*/
|
|
124
146
|
static id(options) {
|
|
125
|
-
let idFactory = options?.idFactory ?? remultStatic.defaultIdFactory;
|
|
126
147
|
return Field(() => String, {
|
|
127
148
|
allowApiUpdate: false,
|
|
128
|
-
defaultValue: () =>
|
|
149
|
+
defaultValue: () => {
|
|
150
|
+
let idFactory = options?.idFactory ?? Fields.defaultIdFactory;
|
|
151
|
+
return idFactory();
|
|
152
|
+
},
|
|
129
153
|
saving: (_, r) => {
|
|
130
|
-
if (!r.value
|
|
154
|
+
if (!r.value) {
|
|
155
|
+
let idFactory = options?.idFactory ?? Fields.defaultIdFactory;
|
|
131
156
|
r.value = idFactory();
|
|
157
|
+
}
|
|
132
158
|
},
|
|
133
159
|
...options,
|
|
134
160
|
});
|
|
@@ -202,8 +228,6 @@ export class Fields {
|
|
|
202
228
|
return Field(() => Boolean, ...options);
|
|
203
229
|
}
|
|
204
230
|
}
|
|
205
|
-
// Initialize remultStatic.defaultIdFactory with the default value
|
|
206
|
-
remultStatic.defaultIdFactory = Fields.defaultIdFactory;
|
|
207
231
|
export class Relations {
|
|
208
232
|
/**
|
|
209
233
|
* Define a to-one relation between entities, indicating a one-to-one relationship.
|
|
@@ -321,10 +345,12 @@ export function Field(valueType, ...options) {
|
|
|
321
345
|
r.dbName = r.key;
|
|
322
346
|
let type = r.valueType;
|
|
323
347
|
if (!type) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
348
|
+
// removing import 'reflect-metadata' from server-action.ts, so we return an empty array
|
|
349
|
+
type = undefined;
|
|
350
|
+
// type =
|
|
351
|
+
// typeof Reflect.getMetadata == 'function'
|
|
352
|
+
// ? Reflect.getMetadata('design:type', target, key)
|
|
353
|
+
// : []
|
|
328
354
|
r.valueType = type;
|
|
329
355
|
}
|
|
330
356
|
if (!r.target)
|
package/esm/src/server-action.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
1
|
import { buildRestDataProvider } from './buildRestDataProvider.js';
|
|
3
2
|
import { ClassHelper, Remult, doTransaction, isBackend, setControllerSettings, } from './context.js';
|
|
4
3
|
import { SqlDatabase } from './data-providers/sql-database.js';
|
|
@@ -137,9 +136,11 @@ export function BackendMethod(options) {
|
|
|
137
136
|
let result = originalMethod;
|
|
138
137
|
checkTarget(target);
|
|
139
138
|
function getTypes() {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
// removing import 'reflect-metadata' from server-action.ts, so we return an empty array
|
|
140
|
+
var types = [];
|
|
141
|
+
// typeof Reflect.getMetadata == 'function'
|
|
142
|
+
// ? Reflect.getMetadata('design:paramtypes', target, key)
|
|
143
|
+
// : []
|
|
143
144
|
if (options.paramTypes)
|
|
144
145
|
types =
|
|
145
146
|
typeof options.paramTypes === 'function'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remult",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "A CRUD framework for full-stack TypeScript",
|
|
5
5
|
"homepage": "https://remult.dev",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
}
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"reflect-metadata": "^0.1.13",
|
|
28
27
|
"tslib": "^2.3.1"
|
|
29
28
|
},
|
|
30
29
|
"exports": {
|