@lotics/app-sdk 0.133.3 → 0.133.5

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.js CHANGED
@@ -10234,6 +10234,45 @@ function stringifyForTemplate(value) {
10234
10234
  return textOf(value);
10235
10235
  }
10236
10236
 
10237
+ // ../shared/src/schemas/field_starts.ts
10238
+ function fieldDefaultValue(field) {
10239
+ switch (field.type) {
10240
+ case "text":
10241
+ case "number":
10242
+ case "boolean":
10243
+ case "date":
10244
+ case "select":
10245
+ case "select_member":
10246
+ return field.default_value ?? null;
10247
+ default:
10248
+ return null;
10249
+ }
10250
+ }
10251
+ function isUnsetCellValue(value) {
10252
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
10253
+ }
10254
+ function applyFieldDefaults(data, fields) {
10255
+ const result = { ...data };
10256
+ for (const field of fields) {
10257
+ const defaultValue = fieldDefaultValue(field);
10258
+ if (defaultValue == null) continue;
10259
+ if (isUnsetCellValue(result[field.key])) {
10260
+ result[field.key] = defaultValue;
10261
+ }
10262
+ }
10263
+ return result;
10264
+ }
10265
+ var COPIED_FIELD_TYPES = ["number", "text", "date", "boolean", "select", "select_member", "select_record_link"];
10266
+ function isCopiedFieldType(type) {
10267
+ return COPIED_FIELD_TYPES.some((one) => one === type);
10268
+ }
10269
+ function isCopiedField(field) {
10270
+ return isCopiedFieldType(field.type);
10271
+ }
10272
+ function fieldCopyOf(field) {
10273
+ return isCopiedField(field) ? field.default_from ?? void 0 : void 0;
10274
+ }
10275
+
10237
10276
  // ../shared/src/workflow_effect_plan.ts
10238
10277
  var WITHHELD = "__withheld";
10239
10278
 
@@ -10439,6 +10478,7 @@ async function predictCreate(walk, step) {
10439
10478
  return unknownAt(walk.ctx.step_outputs, step.id);
10440
10479
  }
10441
10480
  const table = await tableOf(walk, input);
10481
+ const defaulting = input.apply_field_defaults === void 0 ? true : await attempt(walk, input.apply_field_defaults);
10442
10482
  const given = input.ids === void 0 ? null : await attempt(walk, input.ids);
10443
10483
  const stated = given === null ? null : asIds(given);
10444
10484
  const records = input.rows !== void 0 || input.records === void 0 ? UNKNOWN : Array.isArray(input.records) ? input.records : await (async () => {
@@ -10459,7 +10499,14 @@ async function predictCreate(walk, step) {
10459
10499
  note(walk, { kind: "unknown", table_id: table });
10460
10500
  continue;
10461
10501
  }
10462
- note(walk, { kind: "create", table_id: table, record_id: id, cells: { ...constants.cells, ...row2.cells }, unknown: [...constants.unknown, ...row2.unknown] });
10502
+ const cells = { ...constants.cells, ...row2.cells };
10503
+ const unread2 = [...constants.unknown, ...row2.unknown];
10504
+ const copied = (field) => {
10505
+ const link2 = fieldCopyOf(field)?.link_field_key;
10506
+ return link2 !== void 0 && (unread2.includes(link2) || !isUnsetCellValue(cells[link2]));
10507
+ };
10508
+ const fields = defaulting === true ? (walk.input.tables.get(table)?.fields ?? []).filter((field) => !unread2.includes(field.key) && !copied(field)) : [];
10509
+ note(walk, { kind: "create", table_id: table, record_id: id, cells: applyFieldDefaults(cells, fields), unknown: unread2 });
10463
10510
  }
10464
10511
  const made = ids.filter((id) => id !== void 0);
10465
10512
  if (made.length !== records.length) return unknownAt(walk.ctx.step_outputs, step.id);
@@ -62,7 +62,7 @@ export interface ExportCall {
62
62
  * tab `sheet` — or a template the query declares under `templates`, by its name there.
63
63
  */
64
64
  export type ExportFile = { kind: "workbook"; language: ReportLanguage; sheet: string; columns: ReportColumn[]; } | { kind: "template"; template: string; };
65
- export type ExportNarrowing = { status?: string[] | undefined; filters?: Record<string, { kind: "ids"; ids: string[]; unset?: true | undefined; } | { kind: "members"; mine: boolean; ids: string[]; unset?: true | undefined; } | { kind: "dates"; from: string | null; to: string | null; unset?: true | undefined; } | { kind: "yes_no"; value: boolean; } | { kind: "number"; min: number | null; max: number | null; unit?: string | undefined; } | { kind: "bands"; bands: { min: number | null; max: number | null; }[]; } | null> | undefined; search?: string | undefined; overdue?: true | undefined; waiting?: boolean | undefined; tab?: string | undefined; period?: { from: string; to: string; } | undefined; window?: { from: string; to: string; } | undefined; sort?: { field: string; dir: "asc" | "desc"; } | undefined; group?: string | null | undefined; folder?: string | undefined; row?: string | undefined; per?: string | undefined; };
65
+ export type ExportNarrowing = { status?: string[] | undefined; filters?: Record<string, { kind: "ids"; ids: string[]; unset?: true | undefined; } | { kind: "members"; mine: boolean; ids: string[]; unset?: true | undefined; } | { kind: "dates"; from: string | null; to: string | null; unset?: true | undefined; } | { kind: "yes_no"; value: boolean; } | { kind: "number"; min: number | null; max: number | null; unit?: string | undefined; } | { kind: "any_check"; } | { kind: "bands"; bands: { min: number | null; max: number | null; }[]; } | null> | undefined; search?: string | undefined; overdue?: true | undefined; waiting?: boolean | undefined; tab?: string | undefined; period?: { from: string; to: string; } | undefined; window?: { from: string; to: string; } | undefined; sort?: { field: string; dir: "asc" | "desc"; } | undefined; group?: string | null | undefined; folder?: string | undefined; row?: string | undefined; per?: string | undefined; };
66
66
  /**
67
67
  * What an export states of its rows beside them: the page's title, one line per thing narrowing them, and the
68
68
  * figures over them as the screen drew them.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.133.3",
3
+ "version": "0.133.5",
4
4
  "description": "The SDK a Lotics custom-code app reads and writes through — typed hooks over the host bridge, cell readers, mount() and AppRouter",
5
5
  "type": "module",
6
6
  "exports": {