@stonecrop/stonecrop 0.42.0 → 0.44.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.
@@ -159,9 +159,9 @@ export declare interface BatchOperation {
159
159
  export declare type ClientHandlerApi = Record<string, unknown>;
160
160
 
161
161
  /**
162
- * Build a new record, once, from every starting value: the schema's empty values, the doctype's `defaults`, then
163
- * the source the app registered for it. Layers apply in that order, so the registered source wins however long
164
- * the doctype's took.
162
+ * Build a new record, once, from every starting value: the doctype's `defaults`, then the source the app registered
163
+ * for it, over the record's tables and embedded records. Layers apply in that order, so the registered source wins
164
+ * however long the doctype's took. A field neither sets has no value, so a save leaves it to the database's default.
165
165
  *
166
166
  * Nothing is returned until every value is in, so nothing is written to the record after a user can see it.
167
167
  * A value that throws, rejects, or has not arrived within `timeoutMs` (default {@link DEFAULTS_TIMEOUT_MS}) is
@@ -1553,15 +1553,18 @@ export declare class Registry {
1553
1553
  */
1554
1554
  private buildTableConfig;
1555
1555
  /**
1556
- * Initialize a new record with default values based on a resolved schema.
1556
+ * The shape of a new record before any starting value: the containers its fields need, and no values.
1557
1557
  * Narrows by `kind` discriminator for precise branch selection.
1558
1558
  *
1559
- * - `kind: 'table'` or `kind: 'link'` → `[]` or `{}`
1559
+ * - `kind: 'table'` → `[]`
1560
+ * - `kind: 'link'` → the embedded record, built the same way
1560
1561
  * - `kind: 'fieldset'` → its children, at the top level of the record: a fieldset is layout
1561
- * - `kind: 'field'` → an empty value for the component's category; falls back to `null`
1562
+ * - `kind: 'field'` → no key at all
1562
1563
  *
1563
- * @param schema - The resolved schema array to derive defaults from
1564
- * @returns A plain object with default values for each field
1564
+ * Starting values are the doctype's `defaults` and the app's, which `composeNewRecord` lays over this.
1565
+ *
1566
+ * @param schema - The resolved schema array to derive the record from
1567
+ * @returns A plain object holding each table and embedded record, and no field values
1565
1568
  * @public
1566
1569
  */
1567
1570
  initializeRecord(schema: ResolvedField[]): Record<string, any>;
@@ -2198,9 +2201,8 @@ export declare class Stonecrop {
2198
2201
  */
2199
2202
  collectRecordPayload(doctype: Doctype, recordId: string): Record<string, any>;
2200
2203
  /**
2201
- * Scaffold empty descendant records from defaults for all descendant links.
2202
- *
2203
- * Initializes all scalar and link fields at their HST paths with default values.
2204
+ * Scaffold a new descendant record at `path`: its node, so edits under it land, and its starting values, each at
2205
+ * its own HST path. A field with no starting value gets no path until someone fills it in.
2204
2206
  * For new records, call this after setting up the doctype to ensure all paths exist.
2205
2207
  *
2206
2208
  * @param path - HST path (e.g., "customer.new")
package/dist/stonecrop.js CHANGED
@@ -1671,9 +1671,8 @@ var Stonecrop = class Stonecrop {
1671
1671
  return payload;
1672
1672
  }
1673
1673
  /**
1674
- * Scaffold empty descendant records from defaults for all descendant links.
1675
- *
1676
- * Initializes all scalar and link fields at their HST paths with default values.
1674
+ * Scaffold a new descendant record at `path`: its node, so edits under it land, and its starting values, each at
1675
+ * its own HST path. A field with no starting value gets no path until someone fills it in.
1677
1676
  * For new records, call this after setting up the doctype to ensure all paths exist.
1678
1677
  *
1679
1678
  * @param path - HST path (e.g., "customer.new")
@@ -3034,19 +3033,13 @@ async function applyDoctypeDefaults(target, doctype, run, path, within) {
3034
3033
  await applyLayer(target, doctype.defaults, fields, run, path, [...within, doctype]);
3035
3034
  }
3036
3035
  /**
3037
- * One row of a table's starting value: the row's own empty values and its doctype's `defaults`, then the row's
3038
- * entries. A linked table's rows are records of its target doctype; an inline table's rows have one value per
3039
- * column.
3036
+ * One row of a table's starting value: its doctype's `defaults`, then the row's entries. A linked table's rows are
3037
+ * records of its target doctype; an inline table's rows have no doctype, so they hold only their entries.
3040
3038
  */
3041
3039
  async function composeRow(row, table, run, path, within) {
3042
3040
  const { registry, now } = run;
3043
3041
  const fields = table.holds === "rows" ? recordFields(registry, table.target) : columnFields(table.columns);
3044
- const floor = table.holds === "rows" ? registry.initializeRecord(registry.resolveSchema(table.target)) : registry.initializeRecord(table.columns.map((column) => ({
3045
- kind: "field",
3046
- fieldname: column.fieldname,
3047
- component: column.component ?? "ATextInput",
3048
- label: column.label
3049
- })));
3042
+ const floor = table.holds === "rows" ? registry.initializeRecord(registry.resolveSchema(table.target)) : {};
3050
3043
  if (table.holds === "rows") await applyDoctypeDefaults(floor, table.target, run, `${path} defaults`, within);
3051
3044
  const rowRecord = resolveTokensInRecord(floor, fields, registry, now);
3052
3045
  if (!isDefaultsDocument(row)) {
@@ -3071,9 +3064,9 @@ async function applyLayer(target, layer, fields, run, path, within) {
3071
3064
  await applyDocument(target, evaluated.value, fields, run, path, within);
3072
3065
  }
3073
3066
  /**
3074
- * Build a new record, once, from every starting value: the schema's empty values, the doctype's `defaults`, then
3075
- * the source the app registered for it. Layers apply in that order, so the registered source wins however long
3076
- * the doctype's took.
3067
+ * Build a new record, once, from every starting value: the doctype's `defaults`, then the source the app registered
3068
+ * for it, over the record's tables and embedded records. Layers apply in that order, so the registered source wins
3069
+ * however long the doctype's took. A field neither sets has no value, so a save leaves it to the database's default.
3077
3070
  *
3078
3071
  * Nothing is returned until every value is in, so nothing is written to the record after a user can see it.
3079
3072
  * A value that throws, rejects, or has not arrived within `timeoutMs` (default {@link DEFAULTS_TIMEOUT_MS}) is
@@ -3308,15 +3301,18 @@ var Registry = class Registry {
3308
3301
  };
3309
3302
  }
3310
3303
  /**
3311
- * Initialize a new record with default values based on a resolved schema.
3304
+ * The shape of a new record before any starting value: the containers its fields need, and no values.
3312
3305
  * Narrows by `kind` discriminator for precise branch selection.
3313
3306
  *
3314
- * - `kind: 'table'` or `kind: 'link'` → `[]` or `{}`
3307
+ * - `kind: 'table'` → `[]`
3308
+ * - `kind: 'link'` → the embedded record, built the same way
3315
3309
  * - `kind: 'fieldset'` → its children, at the top level of the record: a fieldset is layout
3316
- * - `kind: 'field'` → an empty value for the component's category; falls back to `null`
3310
+ * - `kind: 'field'` → no key at all
3317
3311
  *
3318
- * @param schema - The resolved schema array to derive defaults from
3319
- * @returns A plain object with default values for each field
3312
+ * Starting values are the doctype's `defaults` and the app's, which `composeNewRecord` lays over this.
3313
+ *
3314
+ * @param schema - The resolved schema array to derive the record from
3315
+ * @returns A plain object holding each table and embedded record, and no field values
3320
3316
  * @public
3321
3317
  */
3322
3318
  initializeRecord(schema) {
@@ -3324,14 +3320,6 @@ var Registry = class Registry {
3324
3320
  for (const field of schema) if (field.kind === "table") record[field.fieldname] = [];
3325
3321
  else if (field.kind === "link") record[field.fieldname] = this.initializeRecord(field.schema);
3326
3322
  else if (field.kind === "fieldset") Object.assign(record, this.initializeRecord(field.schema));
3327
- else {
3328
- const category = componentCategory(field.component);
3329
- if (category === "text") record[field.fieldname] = "";
3330
- else if (category === "number") record[field.fieldname] = 0;
3331
- else if (category === "boolean") record[field.fieldname] = false;
3332
- else if (category === "code" && field.language) record[field.fieldname] = field.language === "json" ? {} : "";
3333
- else record[field.fieldname] = null;
3334
- }
3335
3323
  return record;
3336
3324
  }
3337
3325
  /**