@ai-matrx/records 0.44.1 → 0.46.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/CHANGELOG.md +49 -0
- package/dist/core/index.cjs +225 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +14 -5
- package/dist/core/index.d.ts +14 -5
- package/dist/core/index.js +225 -1
- package/dist/core/index.js.map +1 -1
- package/dist/{field-D0Rr4Cqb.d.cts → field-N0ExInZA.d.cts} +22 -2
- package/dist/{field-D0Rr4Cqb.d.ts → field-N0ExInZA.d.ts} +22 -2
- package/dist/index.cjs +214 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -3
- package/dist/index.d.ts +146 -3
- package/dist/index.js +214 -1
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +225 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +174 -3
- package/dist/react/index.d.ts +174 -3
- package/dist/react/index.js +225 -1
- package/dist/react/index.js.map +1 -1
- package/dist/use-cases/index.cjs.map +1 -1
- package/dist/use-cases/index.d.cts +1 -1
- package/dist/use-cases/index.d.ts +1 -1
- package/dist/use-cases/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -124,6 +124,209 @@ function looksLikeAnId(value) {
|
|
|
124
124
|
return typeof value === "string" && UUID.test(value);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
// src/coerce.ts
|
|
128
|
+
var FIELD_KINDS = [
|
|
129
|
+
"attachment",
|
|
130
|
+
"checkbox",
|
|
131
|
+
"currency",
|
|
132
|
+
"datetime",
|
|
133
|
+
"email",
|
|
134
|
+
"formula",
|
|
135
|
+
"json",
|
|
136
|
+
"long_text",
|
|
137
|
+
"lookup",
|
|
138
|
+
"member",
|
|
139
|
+
"multi_select",
|
|
140
|
+
"number",
|
|
141
|
+
"percent",
|
|
142
|
+
"phone",
|
|
143
|
+
"relation",
|
|
144
|
+
"rollup",
|
|
145
|
+
"select",
|
|
146
|
+
"text",
|
|
147
|
+
"url"
|
|
148
|
+
];
|
|
149
|
+
function fieldKindFor(field, kernel) {
|
|
150
|
+
const format = (field.format ?? "").toLowerCase();
|
|
151
|
+
const config = field.config ?? {};
|
|
152
|
+
switch (field.type) {
|
|
153
|
+
case "boolean":
|
|
154
|
+
return "checkbox";
|
|
155
|
+
case "text":
|
|
156
|
+
if (format === "email") return "email";
|
|
157
|
+
if (format === "phone") return "phone";
|
|
158
|
+
if (format === "url") return "url";
|
|
159
|
+
if (format === "json" || config["json"] === true) return "json";
|
|
160
|
+
if (format === "long" || config["multiline"] === true) return "long_text";
|
|
161
|
+
return "text";
|
|
162
|
+
case "range": {
|
|
163
|
+
const kind = String(config["kind"] ?? "number");
|
|
164
|
+
if (kind === "date" || kind === "datetime") return "datetime";
|
|
165
|
+
if (format === "currency") return "currency";
|
|
166
|
+
if (format === "percent" || field.unit === "%") return "percent";
|
|
167
|
+
return "number";
|
|
168
|
+
}
|
|
169
|
+
case "list":
|
|
170
|
+
return field.multi ? "multi_select" : "select";
|
|
171
|
+
case "relation": {
|
|
172
|
+
const parity = String(config["parity"] ?? "");
|
|
173
|
+
if (parity === "attachment" || parity === "member") return parity;
|
|
174
|
+
if (kernel?.file && field.relation_target === kernel.file) return "attachment";
|
|
175
|
+
if (kernel?.person && field.relation_target === kernel.person) return "member";
|
|
176
|
+
return "relation";
|
|
177
|
+
}
|
|
178
|
+
case "formula": {
|
|
179
|
+
const via = config["via"];
|
|
180
|
+
if (via && config["agg"]) return "rollup";
|
|
181
|
+
if (via) return "lookup";
|
|
182
|
+
return "formula";
|
|
183
|
+
}
|
|
184
|
+
default:
|
|
185
|
+
return "text";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
var TRUE_WORDS = /* @__PURE__ */ new Set(["true", "yes", "y", "1", "\u2713", "x", "checked", "on"]);
|
|
189
|
+
var FALSE_WORDS = /* @__PURE__ */ new Set(["false", "no", "n", "0", "", "unchecked", "off"]);
|
|
190
|
+
function coercionLabel(field) {
|
|
191
|
+
const label = (field.label ?? "").trim();
|
|
192
|
+
if (label !== "") return label;
|
|
193
|
+
const name = (field.name ?? "").trim();
|
|
194
|
+
if (name !== "") return name;
|
|
195
|
+
return field.key.replace(/[_-]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()).trim();
|
|
196
|
+
}
|
|
197
|
+
function coerceTypedAnswer(field, raw, opts = {}) {
|
|
198
|
+
const label = opts.label ?? coercionLabel(field);
|
|
199
|
+
const text = raw.trim();
|
|
200
|
+
const kind = fieldKindFor(field, opts.kernel);
|
|
201
|
+
if (text === "" && kind !== "checkbox") return { value: null };
|
|
202
|
+
switch (kind) {
|
|
203
|
+
case "checkbox": {
|
|
204
|
+
const word = text.toLowerCase();
|
|
205
|
+
if (TRUE_WORDS.has(word)) return { value: true };
|
|
206
|
+
if (FALSE_WORDS.has(word)) return { value: word === "" ? null : false };
|
|
207
|
+
return {
|
|
208
|
+
refusal: `${label} is a tick box, so it takes yes or no \u2014 \u201C${raw}\u201D is neither. Write TRUE/FALSE, yes/no or 1/0.`
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
case "number":
|
|
212
|
+
case "currency":
|
|
213
|
+
case "percent": {
|
|
214
|
+
const negative = /^\(.*\)$/.test(text);
|
|
215
|
+
const bare = text.replace(/^\(|\)$/g, "").replace(/[\s,]/g, "").replace(/^[^\d.\-+]+/, "").replace(/[^\d.\-+eE]+$/, "");
|
|
216
|
+
const n = Number(bare);
|
|
217
|
+
if (bare === "" || Number.isNaN(n)) {
|
|
218
|
+
return {
|
|
219
|
+
refusal: `${label} holds a number, and \u201C${raw}\u201D is not one. Write digits \u2014 a currency symbol, a percent sign, commas and brackets for a negative are all fine.`
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return { value: negative ? -n : n };
|
|
223
|
+
}
|
|
224
|
+
case "datetime": {
|
|
225
|
+
const wantsTime = String(field.config?.["kind"] ?? "date") === "datetime";
|
|
226
|
+
const plainDay = /^\s*(\d{4})-(\d{2})-(\d{2})\s*$/.exec(raw);
|
|
227
|
+
if (!wantsTime && plainDay) return { value: `${plainDay[1]}-${plainDay[2]}-${plainDay[3]}` };
|
|
228
|
+
const at = Date.parse(text);
|
|
229
|
+
if (Number.isNaN(at)) {
|
|
230
|
+
return {
|
|
231
|
+
refusal: `${label} holds a date, and \u201C${raw}\u201D is not one this can read. Write it as 2026-09-21, or the way your spreadsheet writes dates.`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
const parsed = new Date(at);
|
|
235
|
+
if (wantsTime) return { value: parsed.toISOString() };
|
|
236
|
+
const y = parsed.getFullYear();
|
|
237
|
+
const m = String(parsed.getMonth() + 1).padStart(2, "0");
|
|
238
|
+
const d = String(parsed.getDate()).padStart(2, "0");
|
|
239
|
+
return { value: `${y}-${m}-${d}` };
|
|
240
|
+
}
|
|
241
|
+
case "json": {
|
|
242
|
+
try {
|
|
243
|
+
return { value: JSON.parse(text) };
|
|
244
|
+
} catch {
|
|
245
|
+
return {
|
|
246
|
+
refusal: `${label} holds a document, and \u201C${raw}\u201D is not valid JSON. Write the whole object, braces and all.`
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
case "select":
|
|
251
|
+
case "multi_select": {
|
|
252
|
+
if (!opts.options) {
|
|
253
|
+
return {
|
|
254
|
+
refusal: `${label} is a list and its options have not been read yet, so nothing can be matched to \u201C${raw}\u201D. Try again once the column's choices have loaded.`
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const wanted = kind === "multi_select" ? text.split(/[,;]/).map((w) => w.trim()).filter((w) => w.length > 0) : [text];
|
|
258
|
+
if (wanted.length === 0) return { value: kind === "multi_select" ? [] : null };
|
|
259
|
+
const matched = [];
|
|
260
|
+
const unmatched = [];
|
|
261
|
+
for (const word of wanted) {
|
|
262
|
+
const hit = opts.options.byWord.get(word.toLowerCase());
|
|
263
|
+
if (hit === void 0) unmatched.push(word);
|
|
264
|
+
else matched.push(hit);
|
|
265
|
+
}
|
|
266
|
+
if (unmatched.length > 0) {
|
|
267
|
+
const offered = opts.options.labels.length > 0 ? opts.options.labels.join(", ") : "it has none yet";
|
|
268
|
+
return {
|
|
269
|
+
refusal: `${label} does not have ${unmatched.map((w) => `\u201C${w}\u201D`).join(" or ")} among its options. It offers: ${offered}.`,
|
|
270
|
+
unmatched
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
return { value: kind === "multi_select" ? matched : matched[0] };
|
|
274
|
+
}
|
|
275
|
+
// AN IDENTITY IS NOT A WORD. Writing the word would put a string where an
|
|
276
|
+
// id belongs, and every filter, colour and rollup built on that column
|
|
277
|
+
// would stop agreeing with it. So it is refused and the person is told
|
|
278
|
+
// which control does hold it.
|
|
279
|
+
case "member":
|
|
280
|
+
return {
|
|
281
|
+
refusal: `${label} names a person in this organization, so it is chosen rather than typed. Open it and pick them.`
|
|
282
|
+
};
|
|
283
|
+
case "attachment":
|
|
284
|
+
return {
|
|
285
|
+
refusal: `${label} holds a file, which cannot arrive as typed-in text. Open it and attach the file.`
|
|
286
|
+
};
|
|
287
|
+
case "relation":
|
|
288
|
+
return {
|
|
289
|
+
refusal: `${label} points at another record, so it is chosen rather than typed. Open it and pick the record.`
|
|
290
|
+
};
|
|
291
|
+
case "formula":
|
|
292
|
+
case "lookup":
|
|
293
|
+
case "rollup":
|
|
294
|
+
return {
|
|
295
|
+
refusal: `${label} is worked out by the system, so nothing can be written into it.`
|
|
296
|
+
};
|
|
297
|
+
default:
|
|
298
|
+
return { value: raw };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function coerceTypedAnswers(fields, answers, opts = {}) {
|
|
302
|
+
const byKey = new Map(fields.map((f) => [f.key, f]));
|
|
303
|
+
const values = {};
|
|
304
|
+
const refusals = {};
|
|
305
|
+
const unknownKeys = [];
|
|
306
|
+
for (const [key, given] of Object.entries(answers)) {
|
|
307
|
+
const field = byKey.get(key);
|
|
308
|
+
if (!field) {
|
|
309
|
+
unknownKeys.push(key);
|
|
310
|
+
values[key] = given;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (typeof given !== "string") {
|
|
314
|
+
values[key] = given;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const opt = {};
|
|
318
|
+
const choices = opts.options?.get(key);
|
|
319
|
+
if (choices) opt.options = choices;
|
|
320
|
+
if (opts.kernel) opt.kernel = opts.kernel;
|
|
321
|
+
const label = opts.labels?.[key];
|
|
322
|
+
if (label) opt.label = label;
|
|
323
|
+
const answered = coerceTypedAnswer(field, given, opt);
|
|
324
|
+
if ("refusal" in answered) refusals[key] = answered.refusal;
|
|
325
|
+
else values[key] = answered.value;
|
|
326
|
+
}
|
|
327
|
+
return { values, refusals, unknownKeys };
|
|
328
|
+
}
|
|
329
|
+
|
|
127
330
|
// src/pipeline.ts
|
|
128
331
|
var PIPELINE_RULE_KINDS = ["moves", "requires", "who", "limit", "entry"];
|
|
129
332
|
var STAGE_RULE_ON_FAIL = ["refuse", "require_approval"];
|
|
@@ -853,6 +1056,9 @@ var STORE_DOORS = [
|
|
|
853
1056
|
{ name: "parity_values", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, parity_type text, behavior text, unit text, format text, value jsonb, value_version integer, actor text, written_at timestamp with time zone)", security: "invoker" },
|
|
854
1057
|
{ name: "per_value_access_words", args: "", returns: "text[]", security: "invoker" },
|
|
855
1058
|
{ name: "person_kernel_id", args: "", returns: "uuid", security: "invoker" },
|
|
1059
|
+
{ name: "phone_canonical", args: "p_text text", returns: "text", security: "invoker" },
|
|
1060
|
+
{ name: "phone_display", args: "p_text text", returns: "text", security: "invoker" },
|
|
1061
|
+
{ name: "phone_pattern", args: "", returns: "text", security: "invoker" },
|
|
856
1062
|
{ name: "pin_agent_cells", args: "p_new jsonb, p_old jsonb, p_agent_keys text[]", returns: "jsonb", security: "invoker" },
|
|
857
1063
|
{ name: "pipeline_board", args: "p_organization_id uuid, p_table_id uuid, p_measure text DEFAULT NULL::text", returns: "TABLE(stage_key text, stage_label text, stage_position integer, cards bigint, total numeric, wip_limit integer, over_limit boolean)", security: "definer" },
|
|
858
1064
|
{ name: "pipeline_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
|
|
@@ -874,6 +1080,7 @@ var STORE_DOORS = [
|
|
|
874
1080
|
{ name: "portal_record_title", args: "p_organization_id uuid, p_record_id uuid", returns: "text", security: "definer" },
|
|
875
1081
|
{ name: "portal_revoke", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid", returns: "jsonb", security: "definer" },
|
|
876
1082
|
{ name: "portal_slug", args: "p_organization_id uuid, p_title text, p_portal_id uuid DEFAULT NULL::uuid", returns: "text", security: "definer" },
|
|
1083
|
+
{ name: "portal_tables", args: "p_organization_id uuid", returns: "TABLE(portal_id uuid, table_id uuid, name text)", security: "definer" },
|
|
877
1084
|
{ name: "portals", args: "p_organization_id uuid", returns: "TABLE(portal_id uuid, title text, slug text, client_table_id uuid, client_table text, is_active boolean, tables integer, invited integer, signed_in integer, sign_in_method text, opened_at timestamp with time zone)", security: "definer" },
|
|
878
1085
|
{ name: "presentation_kernel_id", args: "", returns: "uuid", security: "invoker" },
|
|
879
1086
|
{ name: "promote_field", args: "p_organization_id uuid, p_table_id uuid, p_field_id uuid", returns: "jsonb", security: "invoker" },
|
|
@@ -1152,7 +1359,7 @@ var STORE_REFUSAL_CODES = [
|
|
|
1152
1359
|
{ code: "22004", raised_by: "_entity_custom_fields_guard,_value_envelope,actor_word,agg_assert_key,agg_sql,anon_capture,anon_token_issue,anon_write,assert_client_may_reach,booking_declare,capture_submit,checklist_declare,context_resolve,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,enrich_land,enrich_normalize,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,field_history,form_declare,form_submit,home_add,io_comment_write,io_import_begin,io_infer_column,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,pipeline_declare,pipeline_gate_preview,portal_declare,portal_invite,portal_principal_bind,provenance_retention_days,provenance_write,query_across_homes,query_by_coordinates,query_rollup,record_delete,record_reparent,record_resolve,record_restore,record_update,record_write,record_write_many,relation_carry,relation_own,rule_declare,share_grant,sign_request_create,sign_request_sign,subscription_declare,table_declare,table_share_outside_invite,value_restore,view_declare,work_approval_decide,work_approval_request,work_template_declare" },
|
|
1153
1360
|
{ code: "22007", raised_by: "dashboard_window_sql" },
|
|
1154
1361
|
{ code: "22012", raised_by: "rule_eval" },
|
|
1155
|
-
{ code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_take_op_id,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,io_export,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,record_update,record_write_many,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
|
|
1362
|
+
{ code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_take_op_id,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,field_update,io_export,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,record_update,record_write_many,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
|
|
1156
1363
|
{ code: "23503", raised_by: "_booking_availability,_checklist_instantiate,_containment_guard,_display_spec_for,_field_document_for,_pipeline_stage_key,_record_rule_uses,agg_digest_assemble,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,booking_cancel,booking_confirm,booking_declare,booking_hold,booking_reschedule,capture_publish,checklist_declare,checklist_steps_table,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,enrich_declare,enrich_due,enrich_land,form_declare,form_submit,home_add,inbound_declare,inbound_mail_land,inbound_set,io_comment_write,io_import_begin,io_import_finish,io_import_report,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,pipeline_board,pipeline_declare,pipeline_move,pipeline_read,pipeline_transition_refusal,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,sign_request_create,subscription_mute,subscription_preview,view_declare,work_set_state,work_take_assignment,work_template_instantiate" },
|
|
1157
1364
|
{ code: "23505", raised_by: "_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,inbound_declare,io_proposal_accept,relation_carry,relation_own,share_grant,sign_request_cancel,sign_request_create,table_share_outside_invite,table_share_outside_resend,work_approval_decide,work_slot_hold" },
|
|
1158
1365
|
{ code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_containment_guard,_dated_values_guard,_derived_fields,_display_spec_for,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_columns_word_guard,_table_shape_guard,_undeclared_key_guard,_value_envelope,_with_display,_work_shape_guard,_workdoors_approval_guard,assert_columns_are_defined,assert_entity_is_organization_scoped,booking_declare,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,table_declare,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
|
|
@@ -2052,6 +2259,7 @@ var ENTITY_TOKENS = [
|
|
|
2052
2259
|
"template_context_items",
|
|
2053
2260
|
"template_scope_types",
|
|
2054
2261
|
"templates",
|
|
2262
|
+
"test_handset_inbox",
|
|
2055
2263
|
"thread",
|
|
2056
2264
|
"tool",
|
|
2057
2265
|
"tool_binding",
|
|
@@ -2201,6 +2409,7 @@ export {
|
|
|
2201
2409
|
CONTEXT_POLICIES,
|
|
2202
2410
|
DELIVERIES,
|
|
2203
2411
|
ENTITY_TOKENS,
|
|
2412
|
+
FIELD_KINDS,
|
|
2204
2413
|
FIELD_SENSITIVITIES,
|
|
2205
2414
|
FIELD_SOURCES,
|
|
2206
2415
|
FRESHNESS,
|
|
@@ -2238,7 +2447,11 @@ export {
|
|
|
2238
2447
|
choiceSlug,
|
|
2239
2448
|
choiceValuesOf,
|
|
2240
2449
|
choicesOf,
|
|
2450
|
+
coerceTypedAnswer,
|
|
2451
|
+
coerceTypedAnswers,
|
|
2452
|
+
coercionLabel,
|
|
2241
2453
|
err,
|
|
2454
|
+
fieldKindFor,
|
|
2242
2455
|
forgetAllOps,
|
|
2243
2456
|
highestLevel,
|
|
2244
2457
|
holdsARetiredChoice,
|