@rebasepro/common 0.19.2-canary.g9b599d4 → 0.20.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/dist/index.es.js CHANGED
@@ -10,10 +10,28 @@ 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
+ */
13
30
  function getDefaultValuesFor(properties) {
14
31
  if (!properties) return {};
15
32
  return Object.entries(properties).map(([key, property]) => {
16
33
  if (!property) return {};
34
+ if (property.excludeFromApi) return {};
17
35
  const value = getDefaultValueFor(property);
18
36
  return value === void 0 ? {} : { [key]: value };
19
37
  }).reduce((a, b) => ({
@@ -124,18 +142,18 @@ function updateUserAutoValues({ inputValues, properties, status, uid }) {
124
142
  function applyDefaultValuesOnCreate(values, properties) {
125
143
  if (!properties) return values ?? {};
126
144
  const result = { ...values ?? {} };
127
- const defaults = getDefaultValuesFor(properties);
128
145
  for (const [key, property] of Object.entries(properties)) {
129
146
  if (!property) continue;
130
147
  if (!declaresDefault(property)) continue;
148
+ const defaultValue = getDefaultValueFor(property);
131
149
  if (result[key] !== void 0) {
132
150
  if (property.type === "map" && property.defaultValue === void 0 && isPlainObject(result[key])) result[key] = {
133
- ...defaults[key] ?? {},
151
+ ...defaultValue ?? {},
134
152
  ...result[key]
135
153
  };
136
154
  continue;
137
155
  }
138
- if (defaults[key] !== void 0) result[key] = defaults[key];
156
+ if (defaultValue !== void 0) result[key] = defaultValue;
139
157
  }
140
158
  return result;
141
159
  }