@rebasepro/common 0.19.2-canary.g09316f6 → 0.19.2-canary.g2cd43e9
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/dist/index.es.js +3 -21
- package/dist/index.es.js.map +1 -1
- package/dist/util/entities.d.ts +0 -17
- package/package.json +3 -3
package/dist/index.es.js
CHANGED
|
@@ -10,28 +10,10 @@ var DEFAULT_ONE_OF_VALUE = "value";
|
|
|
10
10
|
function isPropertyBuilder(property) {
|
|
11
11
|
return typeof property?.dynamicProps === "function";
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* What a form opens with: a value for every property it can write.
|
|
15
|
-
*
|
|
16
|
-
* `excludeFromApi` columns are left out, and that is the whole of the rule —
|
|
17
|
-
* they are not part of the API surface in either direction, so there is nothing
|
|
18
|
-
* for a form to open showing and nothing it may send back. Including them was
|
|
19
|
-
* not cosmetic: the baseline is what gets submitted, so a new record carried
|
|
20
|
-
* `passwordHash: null` and `emailVerificationToken: null` into the create, and
|
|
21
|
-
* the server refused the whole write with "these columns are the server's to
|
|
22
|
-
* set" — the users collection could not be added to from the panel at all. The
|
|
23
|
-
* fields were invisible on screen (`admin.disabled.hidden`), which is what made
|
|
24
|
-
* the error read as being about the roles the operator *had* just edited.
|
|
25
|
-
*
|
|
26
|
-
* Server-side defaulting does not come through here: `applyDefaultValuesOnCreate`
|
|
27
|
-
* asks each property for its own default, so an excluded column with a declared
|
|
28
|
-
* `defaultValue` is still filled in on an in-process write.
|
|
29
|
-
*/
|
|
30
13
|
function getDefaultValuesFor(properties) {
|
|
31
14
|
if (!properties) return {};
|
|
32
15
|
return Object.entries(properties).map(([key, property]) => {
|
|
33
16
|
if (!property) return {};
|
|
34
|
-
if (property.excludeFromApi) return {};
|
|
35
17
|
const value = getDefaultValueFor(property);
|
|
36
18
|
return value === void 0 ? {} : { [key]: value };
|
|
37
19
|
}).reduce((a, b) => ({
|
|
@@ -142,18 +124,18 @@ function updateUserAutoValues({ inputValues, properties, status, uid }) {
|
|
|
142
124
|
function applyDefaultValuesOnCreate(values, properties) {
|
|
143
125
|
if (!properties) return values ?? {};
|
|
144
126
|
const result = { ...values ?? {} };
|
|
127
|
+
const defaults = getDefaultValuesFor(properties);
|
|
145
128
|
for (const [key, property] of Object.entries(properties)) {
|
|
146
129
|
if (!property) continue;
|
|
147
130
|
if (!declaresDefault(property)) continue;
|
|
148
|
-
const defaultValue = getDefaultValueFor(property);
|
|
149
131
|
if (result[key] !== void 0) {
|
|
150
132
|
if (property.type === "map" && property.defaultValue === void 0 && isPlainObject(result[key])) result[key] = {
|
|
151
|
-
...
|
|
133
|
+
...defaults[key] ?? {},
|
|
152
134
|
...result[key]
|
|
153
135
|
};
|
|
154
136
|
continue;
|
|
155
137
|
}
|
|
156
|
-
if (
|
|
138
|
+
if (defaults[key] !== void 0) result[key] = defaults[key];
|
|
157
139
|
}
|
|
158
140
|
return result;
|
|
159
141
|
}
|