@ai-matrx/records 0.44.1 → 0.45.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 +36 -0
- package/dist/core/index.cjs +208 -0
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +208 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +208 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +124 -1
- package/dist/index.d.ts +124 -1
- package/dist/index.js +208 -0
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +208 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +124 -1
- package/dist/react/index.d.ts +124 -1
- package/dist/react/index.js +208 -0
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -153,6 +153,129 @@ declare function holdsARetiredChoice(document: RecordDocument | undefined, field
|
|
|
153
153
|
/** True when a token looks like a uuid — which a choice value is no longer allowed to be. */
|
|
154
154
|
declare function looksLikeAnId(value: unknown): boolean;
|
|
155
155
|
|
|
156
|
+
/**
|
|
157
|
+
* EVERYTHING THIS FILE NEEDS TO KNOW ABOUT A FIELD, AND NOTHING ELSE.
|
|
158
|
+
*
|
|
159
|
+
* A full `Field` satisfies it, and so does every narrower shape the store
|
|
160
|
+
* hands to a screen — `CaptureField` on a phone with no network, the Field
|
|
161
|
+
* documents `custom.form_public` and `custom.booking_public` publish to a
|
|
162
|
+
* stranger. Asking for the whole `Field` would have meant the capture sheet
|
|
163
|
+
* keeping its own `Number(raw)`, which is exactly the duplication this file
|
|
164
|
+
* exists to end.
|
|
165
|
+
*/
|
|
166
|
+
interface CoercibleField {
|
|
167
|
+
/** Named so the doc above is checkable: a full {@link Field} satisfies this. */
|
|
168
|
+
key: string;
|
|
169
|
+
label?: string | null;
|
|
170
|
+
name?: string | null;
|
|
171
|
+
/** FLD-1. One of five behaviours; an unknown word is treated as text. */
|
|
172
|
+
type?: string | null;
|
|
173
|
+
multi?: boolean | null;
|
|
174
|
+
unit?: string | null;
|
|
175
|
+
format?: string | null;
|
|
176
|
+
config?: Record<string, unknown> | null | undefined;
|
|
177
|
+
relation_target?: string | null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The kind of value one Field holds, resolved from its DECLARATION only — the
|
|
181
|
+
* behaviour, the modifiers, the format, the relation target and the config,
|
|
182
|
+
* because those are what the store stores. A screen that guessed from a value
|
|
183
|
+
* would answer differently for an empty record.
|
|
184
|
+
*
|
|
185
|
+
* `plain_text`, `long_text`, `number` and `boolean` are behaviours that carry
|
|
186
|
+
* no parity type of their own; every other word here is a parity type.
|
|
187
|
+
*/
|
|
188
|
+
declare const FIELD_KINDS: readonly ["attachment", "checkbox", "currency", "datetime", "email", "formula", "json", "long_text", "lookup", "member", "multi_select", "number", "percent", "phone", "relation", "rollup", "select", "text", "url"];
|
|
189
|
+
/**
|
|
190
|
+
* 🚨 THE UNION IS DERIVED FROM THE LIST ABOVE, and the list is what the
|
|
191
|
+
* coverage test walks. Add a kind here and the test drives it; give it no arm
|
|
192
|
+
* in `coerceTypedAnswer` and the test says so, instead of the new kind falling
|
|
193
|
+
* quietly through `default:` and a value of the wrong shape reaching the store
|
|
194
|
+
* — which is the whole defect this file closes.
|
|
195
|
+
*/
|
|
196
|
+
type FieldKind = (typeof FIELD_KINDS)[number];
|
|
197
|
+
/** The kernel Table ids REC-31 pins the two special relations to. */
|
|
198
|
+
interface KernelTargets {
|
|
199
|
+
/** The kernel `File` Table — a relation pointing here is an attachment. */
|
|
200
|
+
file?: string | undefined;
|
|
201
|
+
/** The kernel `Person` Table — a relation pointing here names a person. */
|
|
202
|
+
person?: string | undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Which kind of value this Field holds.
|
|
206
|
+
*
|
|
207
|
+
* This is the ONE classifier. `@ai-matrx/records-ui`'s `editorKindFor` — which
|
|
208
|
+
* decides which editor to DRAW — delegates to it, so the editor a person types
|
|
209
|
+
* into and the coercion applied to what they typed can never disagree about
|
|
210
|
+
* the same column. They did disagree before this moved here; that is the whole
|
|
211
|
+
* class of grid defect September was spent closing.
|
|
212
|
+
*/
|
|
213
|
+
declare function fieldKindFor(field: CoercibleField, kernel?: KernelTargets): FieldKind;
|
|
214
|
+
/** One Field's options, indexed the way a typed word has to be looked up. */
|
|
215
|
+
interface ChoiceOptions {
|
|
216
|
+
/**
|
|
217
|
+
* Lower-cased label, option key and option id, each pointing at the OPTION
|
|
218
|
+
* RECORD'S ID — which is what a list Field stores (FLD-5/FLD-6).
|
|
219
|
+
*/
|
|
220
|
+
byWord: Map<string, string>;
|
|
221
|
+
/** The labels, in order, so a refusal can say what is on offer. */
|
|
222
|
+
labels: string[];
|
|
223
|
+
}
|
|
224
|
+
/** What one answer became, or the sentence saying why it did not. */
|
|
225
|
+
type Coerced = {
|
|
226
|
+
value: unknown;
|
|
227
|
+
} | {
|
|
228
|
+
refusal: string;
|
|
229
|
+
unmatched?: string[];
|
|
230
|
+
};
|
|
231
|
+
interface CoerceOptions {
|
|
232
|
+
/** This Field's choices, when the caller has loaded them. */
|
|
233
|
+
options?: ChoiceOptions | undefined;
|
|
234
|
+
/** The kernel File/Person Table ids, for classifying relations. */
|
|
235
|
+
kernel?: KernelTargets | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* The Field's name as this caller writes it. Defaults to the Field's own
|
|
238
|
+
* label. A screen passes the same words it printed above the box.
|
|
239
|
+
*/
|
|
240
|
+
label?: string | undefined;
|
|
241
|
+
}
|
|
242
|
+
/** The Field's name in plain words — never its key on a screen. */
|
|
243
|
+
declare function coercionLabel(field: CoercibleField): string;
|
|
244
|
+
/**
|
|
245
|
+
* Turn ONE typed-in string into the value this Field holds — or say, in a
|
|
246
|
+
* sentence a person can act on, why it is not one.
|
|
247
|
+
*
|
|
248
|
+
* An empty answer is `null` for every kind: a blank means "no answer here",
|
|
249
|
+
* and clearing a value is a thing a person means to do. Whether the Field may
|
|
250
|
+
* be blank is the store's question, asked with the Field's `required` and its
|
|
251
|
+
* Rules, not this one's.
|
|
252
|
+
*/
|
|
253
|
+
declare function coerceTypedAnswer(field: CoercibleField, raw: string, opts?: CoerceOptions): Coerced;
|
|
254
|
+
/** What a whole set of typed-in answers became. */
|
|
255
|
+
interface CoercedAnswers {
|
|
256
|
+
/** Ready to send to the store. Only the keys that coerced cleanly. */
|
|
257
|
+
values: Record<string, unknown>;
|
|
258
|
+
/** Field key → the sentence saying why that answer was not written. */
|
|
259
|
+
refusals: Record<string, string>;
|
|
260
|
+
/** The field keys the caller sent that this table has no Field for. */
|
|
261
|
+
unknownKeys: string[];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Every typed-in answer on one screen, coerced together — the shape the two
|
|
265
|
+
* public doors and the import wizard actually need.
|
|
266
|
+
*
|
|
267
|
+
* Keys the table has no Field for are reported rather than dropped: the store
|
|
268
|
+
* refuses an unknown key by name and a caller that quietly deleted it would
|
|
269
|
+
* hide a real mismatch between a page and its table.
|
|
270
|
+
*/
|
|
271
|
+
declare function coerceTypedAnswers(fields: readonly CoercibleField[], answers: Readonly<Record<string, unknown>>, opts?: {
|
|
272
|
+
kernel?: KernelTargets | undefined;
|
|
273
|
+
/** Choices per Field key, for the list columns. */
|
|
274
|
+
options?: ReadonlyMap<string, ChoiceOptions> | undefined;
|
|
275
|
+
/** Field key → the words that screen printed above the box. */
|
|
276
|
+
labels?: Readonly<Record<string, string>> | undefined;
|
|
277
|
+
}): CoercedAnswers;
|
|
278
|
+
|
|
156
279
|
/** The seven table types. Only these two carry custom fields (REC-34, DD-011). */
|
|
157
280
|
type CustomFieldTableType = "entity" | "detail";
|
|
158
281
|
/** What `custom.entity_table` answers about a registry token. */
|
|
@@ -2894,4 +3017,4 @@ interface ConversationScopeContext {
|
|
|
2894
3017
|
/** `About: Acme Industrial` — the chip a bound chat wears. */
|
|
2895
3018
|
declare function scopeChip(scope: ConversationScope): string;
|
|
2896
3019
|
|
|
2897
|
-
export { Actor, type AggregateBucket, type AggregateFilter, type AggregateMeasure, type AggregateOperation, type AggregateRow, type AggregateWindow, type AnonTokenBinding, type BookingAvailability, type BookingDeclared, type BookingSummary, type BookingWindow, type CaptureField, type CaptureFileRef, type CaptureOutcome, type CaptureQuestion, type CaptureQueue, type CaptureQueueCounts, type CaptureQueueOptions, type CaptureQueuePorts, type CaptureQueueStore, type CaptureSheetFace, type CaptureSheetSummary, type CaptureSyncReport, type ChecklistDeclared, type ChecklistRequirement, type ChecklistRequirementKind, type ChecklistRoleSpec, type ChecklistRunStarted, type ChecklistRunStep, type ChecklistRunSummary, type ChecklistSpec, type ChecklistStepCompleted, type ChecklistStepSpec, type ChecklistTemplateShape, type ChecklistTemplateSummary, type ChecklistTrigger, type ChecklistTriggerKind, type ChoiceOption, type CommentThreadRead, type CommentWritten, type ConversationScope, type ConversationScopeContext, type CustomFieldTableType, type DashboardBlock, type DashboardBlockKind, type DashboardBlockResult, type DashboardRunResult, type DashboardSummary, Delivery, type DigestPreview, type DocRenderRow, type DocSignatureCheck, type DocSignatureRow, type DocTemplateRow, type DocToken, type DocUnresolvedToken, type EnrichAlternate, type EnrichCell, type EnrichDeclared, type EnrichDueRow, type EnrichRun, type EnrichSource, type Enrichment, type EnrichmentSummary, type EntityFieldRights, type EntityFieldValue, type EntityRecordMatch, type EntityRecordRead, type EntityRecordsFound, type EntityTableFacts, type ExternalPrincipalCard, Field, type FieldHistoryEntry, type FormSummary, Freshness, type HistoryActor, type HistoryActorKind, type HistoryChange, type Home, type ImportBatchResult, type ImportColumnPlan, type ImportFinished, type ImportOpened, type ImportOutcome, type ImportPlan, type ImportPolicy, type ImportProposal, type ImportReport, type ImportRun, type InboundAddress, type InboundDeclared, type MergeField, MergeFieldModifier, type MergeFieldProvenance, type MergeFieldResolution, MergeFieldSemanticType, MergeFieldSource, type MergeFieldTransform, type MissingBehavior, type MyLevel, type MySubscription, type NewEntityFieldDeclaration, OnDelete, OverridePolicy, PERMISSION_LEVELS, PIPELINE_RULE_KINDS, ParityFieldType, type PermissionLevel, PgError, type Pipeline, type PipelineColumn, type PipelineDeclared, type PipelineGate, type PipelineGatePreview, type PipelineMissingField, type PipelineMoveResult, type PipelineRule, type PipelineRuleKind, type PipelineSpec, type PipelineStage, type PipelineVerdict, type PortalCard, type PortalInvitation, type PortalPreviewRow, type PortalPrincipal, type PortalRevocation, type PortalSummary, type PortalTableExposure, type PublishBinding, type QueuedCapture, type QueuedCaptureFile, type QueuedCaptureState, type QuietHours, REFUSALS_WORTH_REPEATING, type RecordComment, RecordDocument, type RecordHistoryEntry, type RecordScopeComment, type RecordScopeContext, type RecordScopeField, type RecordScopeHistoryEntry, type RecordScopeRelation, type RecordScopeWithheld, type RecordsActor, type RecordsChangeSink, type RecordsConfig, type RecordsDataSource, type RecordsErrorSink, type RecordsFilter, type RecordsRealtimePort, type RecordsResolverPort, type RecordsResponse, type RecordsTableQuery, type RegisteredTable, type Relation, RelationBinding, RelationCardinality, type RelationCarries, type RelationCoordinate, RelationFlavor, type RelationProperties, type RelationTarget, type ResolutionTriple, type ResolvedPublishBinding, type RestorePreview, type RestoreResult, type Rule, type RuleAnswer, type RuleExpression, RuleNodeKind, RuleUse, STAGE_RULE_ENFORCEMENT, STAGE_RULE_ON_FAIL, type SavedViewRow, type SavedViewSpecIn, type StagePending, type StagePendingOnBoard, type StageRuleEnforcement, type StageRuleOnFail, type StageRuleWarning, StorageMode, StoredRecord, type StuckRow, type Subscription, type SubscriptionBlock, type SubscriptionCadence, type SubscriptionSpec, type Table, type TableCapacity, TableDisplay, TableOrigin, TableType, Timestamp, Uuid, type WorkApprovalDecision, type WorkApprovalFiled, type WorkApprover, type WorkAssignment, type WorkAssignmentField, type WorkChange, type WorkDueState, type WorkGraph, type WorkInboxItem, type WorkInboxKind, type WorkInstantiation, type WorkListFlavour, type WorkListItem, type WorkOrigin, type WorkRecordState, type WorkSlotHold, type WorkState, type WorkTemplateNode, type WorkTemplateRelation, type WorkTurn, asPermissionLevel, atLeast, bookingPath, choiceSlug, choiceValuesOf, choicesOf, forgetAllOps, highestLevel, holdsARetiredChoice, indexedDbStore, isDecided, isOwnOp, isTheChosen, looksLikeAnId, mayDrag, measureKey, memoryStore, mintClientKey, mintOpId, openCaptureQueue, optionKey, optionLabel, portalPath, publicFormPath, rememberedOpCount, scopeChip };
|
|
3020
|
+
export { Actor, type AggregateBucket, type AggregateFilter, type AggregateMeasure, type AggregateOperation, type AggregateRow, type AggregateWindow, type AnonTokenBinding, type BookingAvailability, type BookingDeclared, type BookingSummary, type BookingWindow, type CaptureField, type CaptureFileRef, type CaptureOutcome, type CaptureQuestion, type CaptureQueue, type CaptureQueueCounts, type CaptureQueueOptions, type CaptureQueuePorts, type CaptureQueueStore, type CaptureSheetFace, type CaptureSheetSummary, type CaptureSyncReport, type ChecklistDeclared, type ChecklistRequirement, type ChecklistRequirementKind, type ChecklistRoleSpec, type ChecklistRunStarted, type ChecklistRunStep, type ChecklistRunSummary, type ChecklistSpec, type ChecklistStepCompleted, type ChecklistStepSpec, type ChecklistTemplateShape, type ChecklistTemplateSummary, type ChecklistTrigger, type ChecklistTriggerKind, type ChoiceOption, type ChoiceOptions, type CoerceOptions, type Coerced, type CoercedAnswers, type CoercibleField, type CommentThreadRead, type CommentWritten, type ConversationScope, type ConversationScopeContext, type CustomFieldTableType, type DashboardBlock, type DashboardBlockKind, type DashboardBlockResult, type DashboardRunResult, type DashboardSummary, Delivery, type DigestPreview, type DocRenderRow, type DocSignatureCheck, type DocSignatureRow, type DocTemplateRow, type DocToken, type DocUnresolvedToken, type EnrichAlternate, type EnrichCell, type EnrichDeclared, type EnrichDueRow, type EnrichRun, type EnrichSource, type Enrichment, type EnrichmentSummary, type EntityFieldRights, type EntityFieldValue, type EntityRecordMatch, type EntityRecordRead, type EntityRecordsFound, type EntityTableFacts, type ExternalPrincipalCard, FIELD_KINDS, Field, type FieldHistoryEntry, type FieldKind, type FormSummary, Freshness, type HistoryActor, type HistoryActorKind, type HistoryChange, type Home, type ImportBatchResult, type ImportColumnPlan, type ImportFinished, type ImportOpened, type ImportOutcome, type ImportPlan, type ImportPolicy, type ImportProposal, type ImportReport, type ImportRun, type InboundAddress, type InboundDeclared, type KernelTargets, type MergeField, MergeFieldModifier, type MergeFieldProvenance, type MergeFieldResolution, MergeFieldSemanticType, MergeFieldSource, type MergeFieldTransform, type MissingBehavior, type MyLevel, type MySubscription, type NewEntityFieldDeclaration, OnDelete, OverridePolicy, PERMISSION_LEVELS, PIPELINE_RULE_KINDS, ParityFieldType, type PermissionLevel, PgError, type Pipeline, type PipelineColumn, type PipelineDeclared, type PipelineGate, type PipelineGatePreview, type PipelineMissingField, type PipelineMoveResult, type PipelineRule, type PipelineRuleKind, type PipelineSpec, type PipelineStage, type PipelineVerdict, type PortalCard, type PortalInvitation, type PortalPreviewRow, type PortalPrincipal, type PortalRevocation, type PortalSummary, type PortalTableExposure, type PublishBinding, type QueuedCapture, type QueuedCaptureFile, type QueuedCaptureState, type QuietHours, REFUSALS_WORTH_REPEATING, type RecordComment, RecordDocument, type RecordHistoryEntry, type RecordScopeComment, type RecordScopeContext, type RecordScopeField, type RecordScopeHistoryEntry, type RecordScopeRelation, type RecordScopeWithheld, type RecordsActor, type RecordsChangeSink, type RecordsConfig, type RecordsDataSource, type RecordsErrorSink, type RecordsFilter, type RecordsRealtimePort, type RecordsResolverPort, type RecordsResponse, type RecordsTableQuery, type RegisteredTable, type Relation, RelationBinding, RelationCardinality, type RelationCarries, type RelationCoordinate, RelationFlavor, type RelationProperties, type RelationTarget, type ResolutionTriple, type ResolvedPublishBinding, type RestorePreview, type RestoreResult, type Rule, type RuleAnswer, type RuleExpression, RuleNodeKind, RuleUse, STAGE_RULE_ENFORCEMENT, STAGE_RULE_ON_FAIL, type SavedViewRow, type SavedViewSpecIn, type StagePending, type StagePendingOnBoard, type StageRuleEnforcement, type StageRuleOnFail, type StageRuleWarning, StorageMode, StoredRecord, type StuckRow, type Subscription, type SubscriptionBlock, type SubscriptionCadence, type SubscriptionSpec, type Table, type TableCapacity, TableDisplay, TableOrigin, TableType, Timestamp, Uuid, type WorkApprovalDecision, type WorkApprovalFiled, type WorkApprover, type WorkAssignment, type WorkAssignmentField, type WorkChange, type WorkDueState, type WorkGraph, type WorkInboxItem, type WorkInboxKind, type WorkInstantiation, type WorkListFlavour, type WorkListItem, type WorkOrigin, type WorkRecordState, type WorkSlotHold, type WorkState, type WorkTemplateNode, type WorkTemplateRelation, type WorkTurn, asPermissionLevel, atLeast, bookingPath, choiceSlug, choiceValuesOf, choicesOf, coerceTypedAnswer, coerceTypedAnswers, coercionLabel, fieldKindFor, forgetAllOps, highestLevel, holdsARetiredChoice, indexedDbStore, isDecided, isOwnOp, isTheChosen, looksLikeAnId, mayDrag, measureKey, memoryStore, mintClientKey, mintOpId, openCaptureQueue, optionKey, optionLabel, portalPath, publicFormPath, rememberedOpCount, scopeChip };
|
package/dist/index.d.ts
CHANGED
|
@@ -153,6 +153,129 @@ declare function holdsARetiredChoice(document: RecordDocument | undefined, field
|
|
|
153
153
|
/** True when a token looks like a uuid — which a choice value is no longer allowed to be. */
|
|
154
154
|
declare function looksLikeAnId(value: unknown): boolean;
|
|
155
155
|
|
|
156
|
+
/**
|
|
157
|
+
* EVERYTHING THIS FILE NEEDS TO KNOW ABOUT A FIELD, AND NOTHING ELSE.
|
|
158
|
+
*
|
|
159
|
+
* A full `Field` satisfies it, and so does every narrower shape the store
|
|
160
|
+
* hands to a screen — `CaptureField` on a phone with no network, the Field
|
|
161
|
+
* documents `custom.form_public` and `custom.booking_public` publish to a
|
|
162
|
+
* stranger. Asking for the whole `Field` would have meant the capture sheet
|
|
163
|
+
* keeping its own `Number(raw)`, which is exactly the duplication this file
|
|
164
|
+
* exists to end.
|
|
165
|
+
*/
|
|
166
|
+
interface CoercibleField {
|
|
167
|
+
/** Named so the doc above is checkable: a full {@link Field} satisfies this. */
|
|
168
|
+
key: string;
|
|
169
|
+
label?: string | null;
|
|
170
|
+
name?: string | null;
|
|
171
|
+
/** FLD-1. One of five behaviours; an unknown word is treated as text. */
|
|
172
|
+
type?: string | null;
|
|
173
|
+
multi?: boolean | null;
|
|
174
|
+
unit?: string | null;
|
|
175
|
+
format?: string | null;
|
|
176
|
+
config?: Record<string, unknown> | null | undefined;
|
|
177
|
+
relation_target?: string | null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The kind of value one Field holds, resolved from its DECLARATION only — the
|
|
181
|
+
* behaviour, the modifiers, the format, the relation target and the config,
|
|
182
|
+
* because those are what the store stores. A screen that guessed from a value
|
|
183
|
+
* would answer differently for an empty record.
|
|
184
|
+
*
|
|
185
|
+
* `plain_text`, `long_text`, `number` and `boolean` are behaviours that carry
|
|
186
|
+
* no parity type of their own; every other word here is a parity type.
|
|
187
|
+
*/
|
|
188
|
+
declare const FIELD_KINDS: readonly ["attachment", "checkbox", "currency", "datetime", "email", "formula", "json", "long_text", "lookup", "member", "multi_select", "number", "percent", "phone", "relation", "rollup", "select", "text", "url"];
|
|
189
|
+
/**
|
|
190
|
+
* 🚨 THE UNION IS DERIVED FROM THE LIST ABOVE, and the list is what the
|
|
191
|
+
* coverage test walks. Add a kind here and the test drives it; give it no arm
|
|
192
|
+
* in `coerceTypedAnswer` and the test says so, instead of the new kind falling
|
|
193
|
+
* quietly through `default:` and a value of the wrong shape reaching the store
|
|
194
|
+
* — which is the whole defect this file closes.
|
|
195
|
+
*/
|
|
196
|
+
type FieldKind = (typeof FIELD_KINDS)[number];
|
|
197
|
+
/** The kernel Table ids REC-31 pins the two special relations to. */
|
|
198
|
+
interface KernelTargets {
|
|
199
|
+
/** The kernel `File` Table — a relation pointing here is an attachment. */
|
|
200
|
+
file?: string | undefined;
|
|
201
|
+
/** The kernel `Person` Table — a relation pointing here names a person. */
|
|
202
|
+
person?: string | undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Which kind of value this Field holds.
|
|
206
|
+
*
|
|
207
|
+
* This is the ONE classifier. `@ai-matrx/records-ui`'s `editorKindFor` — which
|
|
208
|
+
* decides which editor to DRAW — delegates to it, so the editor a person types
|
|
209
|
+
* into and the coercion applied to what they typed can never disagree about
|
|
210
|
+
* the same column. They did disagree before this moved here; that is the whole
|
|
211
|
+
* class of grid defect September was spent closing.
|
|
212
|
+
*/
|
|
213
|
+
declare function fieldKindFor(field: CoercibleField, kernel?: KernelTargets): FieldKind;
|
|
214
|
+
/** One Field's options, indexed the way a typed word has to be looked up. */
|
|
215
|
+
interface ChoiceOptions {
|
|
216
|
+
/**
|
|
217
|
+
* Lower-cased label, option key and option id, each pointing at the OPTION
|
|
218
|
+
* RECORD'S ID — which is what a list Field stores (FLD-5/FLD-6).
|
|
219
|
+
*/
|
|
220
|
+
byWord: Map<string, string>;
|
|
221
|
+
/** The labels, in order, so a refusal can say what is on offer. */
|
|
222
|
+
labels: string[];
|
|
223
|
+
}
|
|
224
|
+
/** What one answer became, or the sentence saying why it did not. */
|
|
225
|
+
type Coerced = {
|
|
226
|
+
value: unknown;
|
|
227
|
+
} | {
|
|
228
|
+
refusal: string;
|
|
229
|
+
unmatched?: string[];
|
|
230
|
+
};
|
|
231
|
+
interface CoerceOptions {
|
|
232
|
+
/** This Field's choices, when the caller has loaded them. */
|
|
233
|
+
options?: ChoiceOptions | undefined;
|
|
234
|
+
/** The kernel File/Person Table ids, for classifying relations. */
|
|
235
|
+
kernel?: KernelTargets | undefined;
|
|
236
|
+
/**
|
|
237
|
+
* The Field's name as this caller writes it. Defaults to the Field's own
|
|
238
|
+
* label. A screen passes the same words it printed above the box.
|
|
239
|
+
*/
|
|
240
|
+
label?: string | undefined;
|
|
241
|
+
}
|
|
242
|
+
/** The Field's name in plain words — never its key on a screen. */
|
|
243
|
+
declare function coercionLabel(field: CoercibleField): string;
|
|
244
|
+
/**
|
|
245
|
+
* Turn ONE typed-in string into the value this Field holds — or say, in a
|
|
246
|
+
* sentence a person can act on, why it is not one.
|
|
247
|
+
*
|
|
248
|
+
* An empty answer is `null` for every kind: a blank means "no answer here",
|
|
249
|
+
* and clearing a value is a thing a person means to do. Whether the Field may
|
|
250
|
+
* be blank is the store's question, asked with the Field's `required` and its
|
|
251
|
+
* Rules, not this one's.
|
|
252
|
+
*/
|
|
253
|
+
declare function coerceTypedAnswer(field: CoercibleField, raw: string, opts?: CoerceOptions): Coerced;
|
|
254
|
+
/** What a whole set of typed-in answers became. */
|
|
255
|
+
interface CoercedAnswers {
|
|
256
|
+
/** Ready to send to the store. Only the keys that coerced cleanly. */
|
|
257
|
+
values: Record<string, unknown>;
|
|
258
|
+
/** Field key → the sentence saying why that answer was not written. */
|
|
259
|
+
refusals: Record<string, string>;
|
|
260
|
+
/** The field keys the caller sent that this table has no Field for. */
|
|
261
|
+
unknownKeys: string[];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Every typed-in answer on one screen, coerced together — the shape the two
|
|
265
|
+
* public doors and the import wizard actually need.
|
|
266
|
+
*
|
|
267
|
+
* Keys the table has no Field for are reported rather than dropped: the store
|
|
268
|
+
* refuses an unknown key by name and a caller that quietly deleted it would
|
|
269
|
+
* hide a real mismatch between a page and its table.
|
|
270
|
+
*/
|
|
271
|
+
declare function coerceTypedAnswers(fields: readonly CoercibleField[], answers: Readonly<Record<string, unknown>>, opts?: {
|
|
272
|
+
kernel?: KernelTargets | undefined;
|
|
273
|
+
/** Choices per Field key, for the list columns. */
|
|
274
|
+
options?: ReadonlyMap<string, ChoiceOptions> | undefined;
|
|
275
|
+
/** Field key → the words that screen printed above the box. */
|
|
276
|
+
labels?: Readonly<Record<string, string>> | undefined;
|
|
277
|
+
}): CoercedAnswers;
|
|
278
|
+
|
|
156
279
|
/** The seven table types. Only these two carry custom fields (REC-34, DD-011). */
|
|
157
280
|
type CustomFieldTableType = "entity" | "detail";
|
|
158
281
|
/** What `custom.entity_table` answers about a registry token. */
|
|
@@ -2894,4 +3017,4 @@ interface ConversationScopeContext {
|
|
|
2894
3017
|
/** `About: Acme Industrial` — the chip a bound chat wears. */
|
|
2895
3018
|
declare function scopeChip(scope: ConversationScope): string;
|
|
2896
3019
|
|
|
2897
|
-
export { Actor, type AggregateBucket, type AggregateFilter, type AggregateMeasure, type AggregateOperation, type AggregateRow, type AggregateWindow, type AnonTokenBinding, type BookingAvailability, type BookingDeclared, type BookingSummary, type BookingWindow, type CaptureField, type CaptureFileRef, type CaptureOutcome, type CaptureQuestion, type CaptureQueue, type CaptureQueueCounts, type CaptureQueueOptions, type CaptureQueuePorts, type CaptureQueueStore, type CaptureSheetFace, type CaptureSheetSummary, type CaptureSyncReport, type ChecklistDeclared, type ChecklistRequirement, type ChecklistRequirementKind, type ChecklistRoleSpec, type ChecklistRunStarted, type ChecklistRunStep, type ChecklistRunSummary, type ChecklistSpec, type ChecklistStepCompleted, type ChecklistStepSpec, type ChecklistTemplateShape, type ChecklistTemplateSummary, type ChecklistTrigger, type ChecklistTriggerKind, type ChoiceOption, type CommentThreadRead, type CommentWritten, type ConversationScope, type ConversationScopeContext, type CustomFieldTableType, type DashboardBlock, type DashboardBlockKind, type DashboardBlockResult, type DashboardRunResult, type DashboardSummary, Delivery, type DigestPreview, type DocRenderRow, type DocSignatureCheck, type DocSignatureRow, type DocTemplateRow, type DocToken, type DocUnresolvedToken, type EnrichAlternate, type EnrichCell, type EnrichDeclared, type EnrichDueRow, type EnrichRun, type EnrichSource, type Enrichment, type EnrichmentSummary, type EntityFieldRights, type EntityFieldValue, type EntityRecordMatch, type EntityRecordRead, type EntityRecordsFound, type EntityTableFacts, type ExternalPrincipalCard, Field, type FieldHistoryEntry, type FormSummary, Freshness, type HistoryActor, type HistoryActorKind, type HistoryChange, type Home, type ImportBatchResult, type ImportColumnPlan, type ImportFinished, type ImportOpened, type ImportOutcome, type ImportPlan, type ImportPolicy, type ImportProposal, type ImportReport, type ImportRun, type InboundAddress, type InboundDeclared, type MergeField, MergeFieldModifier, type MergeFieldProvenance, type MergeFieldResolution, MergeFieldSemanticType, MergeFieldSource, type MergeFieldTransform, type MissingBehavior, type MyLevel, type MySubscription, type NewEntityFieldDeclaration, OnDelete, OverridePolicy, PERMISSION_LEVELS, PIPELINE_RULE_KINDS, ParityFieldType, type PermissionLevel, PgError, type Pipeline, type PipelineColumn, type PipelineDeclared, type PipelineGate, type PipelineGatePreview, type PipelineMissingField, type PipelineMoveResult, type PipelineRule, type PipelineRuleKind, type PipelineSpec, type PipelineStage, type PipelineVerdict, type PortalCard, type PortalInvitation, type PortalPreviewRow, type PortalPrincipal, type PortalRevocation, type PortalSummary, type PortalTableExposure, type PublishBinding, type QueuedCapture, type QueuedCaptureFile, type QueuedCaptureState, type QuietHours, REFUSALS_WORTH_REPEATING, type RecordComment, RecordDocument, type RecordHistoryEntry, type RecordScopeComment, type RecordScopeContext, type RecordScopeField, type RecordScopeHistoryEntry, type RecordScopeRelation, type RecordScopeWithheld, type RecordsActor, type RecordsChangeSink, type RecordsConfig, type RecordsDataSource, type RecordsErrorSink, type RecordsFilter, type RecordsRealtimePort, type RecordsResolverPort, type RecordsResponse, type RecordsTableQuery, type RegisteredTable, type Relation, RelationBinding, RelationCardinality, type RelationCarries, type RelationCoordinate, RelationFlavor, type RelationProperties, type RelationTarget, type ResolutionTriple, type ResolvedPublishBinding, type RestorePreview, type RestoreResult, type Rule, type RuleAnswer, type RuleExpression, RuleNodeKind, RuleUse, STAGE_RULE_ENFORCEMENT, STAGE_RULE_ON_FAIL, type SavedViewRow, type SavedViewSpecIn, type StagePending, type StagePendingOnBoard, type StageRuleEnforcement, type StageRuleOnFail, type StageRuleWarning, StorageMode, StoredRecord, type StuckRow, type Subscription, type SubscriptionBlock, type SubscriptionCadence, type SubscriptionSpec, type Table, type TableCapacity, TableDisplay, TableOrigin, TableType, Timestamp, Uuid, type WorkApprovalDecision, type WorkApprovalFiled, type WorkApprover, type WorkAssignment, type WorkAssignmentField, type WorkChange, type WorkDueState, type WorkGraph, type WorkInboxItem, type WorkInboxKind, type WorkInstantiation, type WorkListFlavour, type WorkListItem, type WorkOrigin, type WorkRecordState, type WorkSlotHold, type WorkState, type WorkTemplateNode, type WorkTemplateRelation, type WorkTurn, asPermissionLevel, atLeast, bookingPath, choiceSlug, choiceValuesOf, choicesOf, forgetAllOps, highestLevel, holdsARetiredChoice, indexedDbStore, isDecided, isOwnOp, isTheChosen, looksLikeAnId, mayDrag, measureKey, memoryStore, mintClientKey, mintOpId, openCaptureQueue, optionKey, optionLabel, portalPath, publicFormPath, rememberedOpCount, scopeChip };
|
|
3020
|
+
export { Actor, type AggregateBucket, type AggregateFilter, type AggregateMeasure, type AggregateOperation, type AggregateRow, type AggregateWindow, type AnonTokenBinding, type BookingAvailability, type BookingDeclared, type BookingSummary, type BookingWindow, type CaptureField, type CaptureFileRef, type CaptureOutcome, type CaptureQuestion, type CaptureQueue, type CaptureQueueCounts, type CaptureQueueOptions, type CaptureQueuePorts, type CaptureQueueStore, type CaptureSheetFace, type CaptureSheetSummary, type CaptureSyncReport, type ChecklistDeclared, type ChecklistRequirement, type ChecklistRequirementKind, type ChecklistRoleSpec, type ChecklistRunStarted, type ChecklistRunStep, type ChecklistRunSummary, type ChecklistSpec, type ChecklistStepCompleted, type ChecklistStepSpec, type ChecklistTemplateShape, type ChecklistTemplateSummary, type ChecklistTrigger, type ChecklistTriggerKind, type ChoiceOption, type ChoiceOptions, type CoerceOptions, type Coerced, type CoercedAnswers, type CoercibleField, type CommentThreadRead, type CommentWritten, type ConversationScope, type ConversationScopeContext, type CustomFieldTableType, type DashboardBlock, type DashboardBlockKind, type DashboardBlockResult, type DashboardRunResult, type DashboardSummary, Delivery, type DigestPreview, type DocRenderRow, type DocSignatureCheck, type DocSignatureRow, type DocTemplateRow, type DocToken, type DocUnresolvedToken, type EnrichAlternate, type EnrichCell, type EnrichDeclared, type EnrichDueRow, type EnrichRun, type EnrichSource, type Enrichment, type EnrichmentSummary, type EntityFieldRights, type EntityFieldValue, type EntityRecordMatch, type EntityRecordRead, type EntityRecordsFound, type EntityTableFacts, type ExternalPrincipalCard, FIELD_KINDS, Field, type FieldHistoryEntry, type FieldKind, type FormSummary, Freshness, type HistoryActor, type HistoryActorKind, type HistoryChange, type Home, type ImportBatchResult, type ImportColumnPlan, type ImportFinished, type ImportOpened, type ImportOutcome, type ImportPlan, type ImportPolicy, type ImportProposal, type ImportReport, type ImportRun, type InboundAddress, type InboundDeclared, type KernelTargets, type MergeField, MergeFieldModifier, type MergeFieldProvenance, type MergeFieldResolution, MergeFieldSemanticType, MergeFieldSource, type MergeFieldTransform, type MissingBehavior, type MyLevel, type MySubscription, type NewEntityFieldDeclaration, OnDelete, OverridePolicy, PERMISSION_LEVELS, PIPELINE_RULE_KINDS, ParityFieldType, type PermissionLevel, PgError, type Pipeline, type PipelineColumn, type PipelineDeclared, type PipelineGate, type PipelineGatePreview, type PipelineMissingField, type PipelineMoveResult, type PipelineRule, type PipelineRuleKind, type PipelineSpec, type PipelineStage, type PipelineVerdict, type PortalCard, type PortalInvitation, type PortalPreviewRow, type PortalPrincipal, type PortalRevocation, type PortalSummary, type PortalTableExposure, type PublishBinding, type QueuedCapture, type QueuedCaptureFile, type QueuedCaptureState, type QuietHours, REFUSALS_WORTH_REPEATING, type RecordComment, RecordDocument, type RecordHistoryEntry, type RecordScopeComment, type RecordScopeContext, type RecordScopeField, type RecordScopeHistoryEntry, type RecordScopeRelation, type RecordScopeWithheld, type RecordsActor, type RecordsChangeSink, type RecordsConfig, type RecordsDataSource, type RecordsErrorSink, type RecordsFilter, type RecordsRealtimePort, type RecordsResolverPort, type RecordsResponse, type RecordsTableQuery, type RegisteredTable, type Relation, RelationBinding, RelationCardinality, type RelationCarries, type RelationCoordinate, RelationFlavor, type RelationProperties, type RelationTarget, type ResolutionTriple, type ResolvedPublishBinding, type RestorePreview, type RestoreResult, type Rule, type RuleAnswer, type RuleExpression, RuleNodeKind, RuleUse, STAGE_RULE_ENFORCEMENT, STAGE_RULE_ON_FAIL, type SavedViewRow, type SavedViewSpecIn, type StagePending, type StagePendingOnBoard, type StageRuleEnforcement, type StageRuleOnFail, type StageRuleWarning, StorageMode, StoredRecord, type StuckRow, type Subscription, type SubscriptionBlock, type SubscriptionCadence, type SubscriptionSpec, type Table, type TableCapacity, TableDisplay, TableOrigin, TableType, Timestamp, Uuid, type WorkApprovalDecision, type WorkApprovalFiled, type WorkApprover, type WorkAssignment, type WorkAssignmentField, type WorkChange, type WorkDueState, type WorkGraph, type WorkInboxItem, type WorkInboxKind, type WorkInstantiation, type WorkListFlavour, type WorkListItem, type WorkOrigin, type WorkRecordState, type WorkSlotHold, type WorkState, type WorkTemplateNode, type WorkTemplateRelation, type WorkTurn, asPermissionLevel, atLeast, bookingPath, choiceSlug, choiceValuesOf, choicesOf, coerceTypedAnswer, coerceTypedAnswers, coercionLabel, fieldKindFor, forgetAllOps, highestLevel, holdsARetiredChoice, indexedDbStore, isDecided, isOwnOp, isTheChosen, looksLikeAnId, mayDrag, measureKey, memoryStore, mintClientKey, mintOpId, openCaptureQueue, optionKey, optionLabel, portalPath, publicFormPath, rememberedOpCount, scopeChip };
|
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"];
|
|
@@ -2201,6 +2404,7 @@ export {
|
|
|
2201
2404
|
CONTEXT_POLICIES,
|
|
2202
2405
|
DELIVERIES,
|
|
2203
2406
|
ENTITY_TOKENS,
|
|
2407
|
+
FIELD_KINDS,
|
|
2204
2408
|
FIELD_SENSITIVITIES,
|
|
2205
2409
|
FIELD_SOURCES,
|
|
2206
2410
|
FRESHNESS,
|
|
@@ -2238,7 +2442,11 @@ export {
|
|
|
2238
2442
|
choiceSlug,
|
|
2239
2443
|
choiceValuesOf,
|
|
2240
2444
|
choicesOf,
|
|
2445
|
+
coerceTypedAnswer,
|
|
2446
|
+
coerceTypedAnswers,
|
|
2447
|
+
coercionLabel,
|
|
2241
2448
|
err,
|
|
2449
|
+
fieldKindFor,
|
|
2242
2450
|
forgetAllOps,
|
|
2243
2451
|
highestLevel,
|
|
2244
2452
|
holdsARetiredChoice,
|