ngx-t-forms-types 0.0.36 → 0.0.38
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/interfaces/Form/formInterface.d.ts +18 -0
- package/dist/interfaces/FormBuilder/FormInputKeys.d.ts +2 -0
- package/dist/interfaces/FormBuilder/FormInputKeys.js +2 -0
- package/dist/interfaces/FormBuilder/elementEditor.d.ts +8 -0
- package/dist/interfaces/FormBuilder/elementEditor.js +8 -0
- package/dist/interfaces/Import/ImportIdentity.d.ts +132 -1
- package/dist/interfaces/Import/ImportRecipe.d.ts +423 -0
- package/dist/interfaces/Import/ImportRecipe.js +19 -0
- package/dist/interfaces/Import/ImportRowState.d.ts +84 -7
- package/dist/interfaces/Import/index.d.ts +4 -2
- package/dist/interfaces/Import/index.js +1 -1
- package/dist/interfaces/Tower/ITowerFormSteps.d.ts +19 -0
- package/dist/interfaces/Tower/index.d.ts +2 -1
- package/dist/interfaces/environment/environment.d.ts +47 -0
- package/dist/interfaces/environment/index.d.ts +2 -2
- package/dist/interfaces/formInput/APIDataFetchingConfigurationInterface.d.ts +10 -2
- package/dist/interfaces/formInput/MinimumInputRequiredInterface.d.ts +14 -0
- package/dist/interfaces/formInput/MinimumInputRequiredInterface.js +14 -0
- package/dist/interfaces/workflow/DocumentSectionConfigurationsInterface.d.ts +22 -1
- package/dist/interfaces/workflow/DocumentSectionConfigurationsInterface.js +6 -0
- package/dist/interfaces/workflow/index.d.ts +2 -2
- package/dist/schemas/FormInputSchema.js +6 -0
- package/dist/schemas/FormSchema.d.ts +35 -0
- package/dist/schemas/FormSchema.js +57 -0
- package/dist/schemas/index.d.ts +3 -2
- package/dist/schemas/index.js +2 -2
- package/dist/skillet/input-members.d.ts +1 -1
- package/dist/skillet/input-members.js +1 -0
- package/package.json +1 -1
|
@@ -10,6 +10,24 @@ export interface FormInterface {
|
|
|
10
10
|
submissionHandle?: FormSubmissionHandleInterface;
|
|
11
11
|
formId: string | any;
|
|
12
12
|
formTitle: string;
|
|
13
|
+
/**
|
|
14
|
+
* What the form is for, who fills it in and what happens to a submission —
|
|
15
|
+
* the form-wide counterpart of `formTitle`.
|
|
16
|
+
*
|
|
17
|
+
* The builder will not save a form without one: at least
|
|
18
|
+
* `FORM_DESCRIPTION_MIN_WORDS` words in at most `FORM_DESCRIPTION_MAX_PARAGRAPHS`
|
|
19
|
+
* paragraphs (paragraphs are separated by a blank line), checked by
|
|
20
|
+
* `validateFormDescription`. Optional on the type because forms stored before it
|
|
21
|
+
* existed, empty-form factories and AI drafts arrive without one.
|
|
22
|
+
*/
|
|
23
|
+
formDescription?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The `value`s of the classifications this form belongs to, chosen from the list
|
|
26
|
+
* the application supplies through `NgxTFormsConfig.formClassifications` (an
|
|
27
|
+
* industry, a module, a use case — whatever the application classifies by).
|
|
28
|
+
* A value the application no longer lists is kept as-is; it is never dropped.
|
|
29
|
+
*/
|
|
30
|
+
formClassifications?: string[];
|
|
13
31
|
submissionMessage?: string;
|
|
14
32
|
}
|
|
15
33
|
export interface MainFormInterface {
|
|
@@ -94,6 +94,8 @@ export declare enum AllFormInputPrimaryKeys {
|
|
|
94
94
|
FormIsOpen = "formIsOpen",
|
|
95
95
|
LinkedSegmentId = "linkedSegmentId",
|
|
96
96
|
CanReload = "canReload",
|
|
97
|
+
/** Runtime-only search bridge for an options fetch bound to the field's search box. Never persisted. */
|
|
98
|
+
OptionsSearch = "optionsSearch",
|
|
97
99
|
WorkflowFormForScoreSheet = "workflowFormForScoreSheet",
|
|
98
100
|
AdjudicationStep = "adjudicationStep",
|
|
99
101
|
AdjudicationPointTypes = "adjudicationPointTypes",
|
|
@@ -98,6 +98,8 @@ export var AllFormInputPrimaryKeys;
|
|
|
98
98
|
AllFormInputPrimaryKeys["FormIsOpen"] = "formIsOpen";
|
|
99
99
|
AllFormInputPrimaryKeys["LinkedSegmentId"] = "linkedSegmentId";
|
|
100
100
|
AllFormInputPrimaryKeys["CanReload"] = "canReload";
|
|
101
|
+
/** Runtime-only search bridge for an options fetch bound to the field's search box. Never persisted. */
|
|
102
|
+
AllFormInputPrimaryKeys["OptionsSearch"] = "optionsSearch";
|
|
101
103
|
AllFormInputPrimaryKeys["WorkflowFormForScoreSheet"] = "workflowFormForScoreSheet";
|
|
102
104
|
AllFormInputPrimaryKeys["AdjudicationStep"] = "adjudicationStep";
|
|
103
105
|
AllFormInputPrimaryKeys["AdjudicationPointTypes"] = "adjudicationPointTypes";
|
|
@@ -34,6 +34,14 @@ export declare enum ElementEditorTypes {
|
|
|
34
34
|
DataSourcePicker = "dataSourcePicker",
|
|
35
35
|
ListLabelConfigEditor = "listLabelConfigEditor",
|
|
36
36
|
DecisionGateSettings = "decisionGateSettings",
|
|
37
|
+
/**
|
|
38
|
+
* Multi-paragraph plain-text description with live word / sentence /
|
|
39
|
+
* paragraph counts. Rendered by the ngx-t-workflows element editor host (like
|
|
40
|
+
* {@link ElementEditorTypes.DecisionGateSettings}), which picks the workflow or
|
|
41
|
+
* the step description rules from what it is editing. `lib-t-dynamic-data-edit`
|
|
42
|
+
* has no case for it.
|
|
43
|
+
*/
|
|
44
|
+
DescriptionEditor = "descriptionEditor",
|
|
37
45
|
RecordListManager = "recordListManager",
|
|
38
46
|
MapMatOptionsKeys = "mapMatOptionsKeys",
|
|
39
47
|
FormPayloadProjection = "formPayloadProjection",
|
|
@@ -28,6 +28,14 @@ export var ElementEditorTypes;
|
|
|
28
28
|
ElementEditorTypes["DataSourcePicker"] = "dataSourcePicker";
|
|
29
29
|
ElementEditorTypes["ListLabelConfigEditor"] = "listLabelConfigEditor";
|
|
30
30
|
ElementEditorTypes["DecisionGateSettings"] = "decisionGateSettings";
|
|
31
|
+
/**
|
|
32
|
+
* Multi-paragraph plain-text description with live word / sentence /
|
|
33
|
+
* paragraph counts. Rendered by the ngx-t-workflows element editor host (like
|
|
34
|
+
* {@link ElementEditorTypes.DecisionGateSettings}), which picks the workflow or
|
|
35
|
+
* the step description rules from what it is editing. `lib-t-dynamic-data-edit`
|
|
36
|
+
* has no case for it.
|
|
37
|
+
*/
|
|
38
|
+
ElementEditorTypes["DescriptionEditor"] = "descriptionEditor";
|
|
31
39
|
ElementEditorTypes["RecordListManager"] = "recordListManager";
|
|
32
40
|
ElementEditorTypes["MapMatOptionsKeys"] = "mapMatOptionsKeys";
|
|
33
41
|
ElementEditorTypes["FormPayloadProjection"] = "formPayloadProjection";
|
|
@@ -13,8 +13,15 @@ export interface ImportIdentity {
|
|
|
13
13
|
* `formControlName`s that together identify a record (for a multiple-input
|
|
14
14
|
* import: the child inputs' `formControlName`s). A row whose values for all
|
|
15
15
|
* of them repeat an earlier row's is a duplicate of that row. Empty or
|
|
16
|
-
* absent disables duplicate detection
|
|
16
|
+
* absent disables duplicate detection between records — `lists` still
|
|
17
|
+
* folds repeats inside each record's lists. A name the form does not have
|
|
17
18
|
* rejects the run rather than matching nothing.
|
|
19
|
+
*
|
|
20
|
+
* A key may also be a dot path below a field, as a workflow's
|
|
21
|
+
* `uniqueKeys` names one leaf of an object value — e.g.
|
|
22
|
+
* `glAccount.accrual.FUND.debit.SCOAid` for one mSCOA account. It is
|
|
23
|
+
* compared on that leaf alone, read the way the server reads
|
|
24
|
+
* `form.<key>`; its first segment must be a field of the form.
|
|
18
25
|
*/
|
|
19
26
|
readonly distinctKeys: readonly string[];
|
|
20
27
|
/**
|
|
@@ -29,4 +36,128 @@ export interface ImportIdentity {
|
|
|
29
36
|
* imported.
|
|
30
37
|
*/
|
|
31
38
|
readonly onDuplicate?: 'skip' | 'flag';
|
|
39
|
+
/**
|
|
40
|
+
* Which row of a group of duplicates is kept as the record.
|
|
41
|
+
*
|
|
42
|
+
* - `first` — the lowest row index. The default.
|
|
43
|
+
* - `last` — the highest row index, for a sheet that lists later
|
|
44
|
+
* corrections below earlier lines.
|
|
45
|
+
* - `{ latest: field }` — the row with the greatest value of `field`, a
|
|
46
|
+
* `formControlName` of the form (for a multiple-input import: a child
|
|
47
|
+
* input's), e.g. the most recently dated line. A row's value is read
|
|
48
|
+
* from its settled value once it has settled, else from the sheet's
|
|
49
|
+
* cell. Only values that compare unambiguously count: a `Date`, a finite
|
|
50
|
+
* number, or ISO text (`yyyy-mm-dd`, optionally with a time; without an
|
|
51
|
+
* offset it is local time). A blank or unparseable value never beats a
|
|
52
|
+
* real one, and a tie — all blank included — keeps the lowest row index.
|
|
53
|
+
* Dates and numbers are not converted into each other, so the field
|
|
54
|
+
* should carry one kind. A name the form does not have rejects the run.
|
|
55
|
+
*
|
|
56
|
+
* A host may still keep a specific row of a group (the import controller's
|
|
57
|
+
* `keepRow`), which wins over this default.
|
|
58
|
+
*/
|
|
59
|
+
readonly keep?: 'first' | 'last' | {
|
|
60
|
+
readonly latest: string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Fields whose value the kept row takes from its WHOLE group rather than
|
|
64
|
+
* from itself: `formControlName` → how the group's values are combined.
|
|
65
|
+
* Every other field is the kept row's own.
|
|
66
|
+
*
|
|
67
|
+
* The combined value is written into the kept row's cells before its form
|
|
68
|
+
* is built, so calculations derive from it and validators judge it — a
|
|
69
|
+
* total over a field's maximum fails like any other value over it. The
|
|
70
|
+
* group's rows are read as the sheet gave them, and a blank cell is left
|
|
71
|
+
* out. A cell the op cannot read makes the kept row `invalid`, with
|
|
72
|
+
* `notCombinable:<row numbers>` in its `colErrors` for the field, rather
|
|
73
|
+
* than being dropped.
|
|
74
|
+
*
|
|
75
|
+
* - A number field (`sum`, `avg`, `min`, `max`) reads a finite number or
|
|
76
|
+
* text holding a plain decimal (`1500`, `-12.5`); any other text cannot
|
|
77
|
+
* be read.
|
|
78
|
+
* - A text or multi-select field (`join`) reads text — a cell holding
|
|
79
|
+
* several values, comma-separated or as a JSON list, contributes each —
|
|
80
|
+
* and writes every distinct value once, comma-separated, in the order
|
|
81
|
+
* first seen, as a multi-select cell is written. A structure cannot be
|
|
82
|
+
* read.
|
|
83
|
+
* - A list field — a MultipleInput (`collect`) — reads the rows of each
|
|
84
|
+
* member's list and writes them all, in sheet order, as the kept row's
|
|
85
|
+
* list; `lists` then folds the repeats inside it. A cell that is not a
|
|
86
|
+
* list cannot be read.
|
|
87
|
+
*
|
|
88
|
+
* A field must be a top-level field of the form (for a multiple-input
|
|
89
|
+
* import: a child input), and neither a unique key nor the field a
|
|
90
|
+
* `latest` keeper ranks by; `collect` needs a list field, and the other
|
|
91
|
+
* ops a field that is not one. A name or op that breaks this rejects the
|
|
92
|
+
* run. Unset, every field is the kept row's own, as before.
|
|
93
|
+
*/
|
|
94
|
+
readonly combine?: Readonly<Record<string, ImportCombineOp>>;
|
|
95
|
+
/**
|
|
96
|
+
* Repeats inside the rows of a list field — a MultipleInput — of each
|
|
97
|
+
* record: the list's `formControlName` → how its rows are told apart and
|
|
98
|
+
* folded. A sheet that lists a record's detail rows may repeat a row the
|
|
99
|
+
* way its main rows repeat a record, and a `collect` that gathered the
|
|
100
|
+
* lists of a record's repeats makes such repeats of its own.
|
|
101
|
+
*
|
|
102
|
+
* Applied to every record's list as the sheet gave it — after `collect`
|
|
103
|
+
* gathered it, when it did — before any of its rows is checked: a row that
|
|
104
|
+
* repeats an earlier one on the list's keys is folded into the row the
|
|
105
|
+
* list keeps, the children named in its `combine` take the group's
|
|
106
|
+
* combined value, and the list is checked with the rows that remain. What
|
|
107
|
+
* was folded is reported in `ImportRowState.folded`.
|
|
108
|
+
*
|
|
109
|
+
* Rows are compared on their cells as the sheet gave them, the way a
|
|
110
|
+
* record's raw identity is: text trimmed, whitespace collapsed, case
|
|
111
|
+
* folded; a choice cell by its text, not the option it resolves to. The
|
|
112
|
+
* list field must be a list of the form (for a multiple-input import: a
|
|
113
|
+
* list among the children); its keys and combined fields name the list's
|
|
114
|
+
* children. Absent, a list's rows are checked as they came.
|
|
115
|
+
*/
|
|
116
|
+
readonly lists?: Readonly<Record<string, ImportListIdentity>>;
|
|
32
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* How the rows of one list field are told apart and folded — see
|
|
120
|
+
* {@link ImportIdentity.lists}. Each member means what it means on
|
|
121
|
+
* {@link ImportIdentity}, read against the list's children instead of the
|
|
122
|
+
* form's fields.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export interface ImportListIdentity {
|
|
127
|
+
/**
|
|
128
|
+
* Children whose values together identify a row of the list; a dot path
|
|
129
|
+
* below a child is read as for a record. Empty folds nothing. A name the
|
|
130
|
+
* list has no child for rejects the run.
|
|
131
|
+
*/
|
|
132
|
+
readonly distinctKeys: readonly string[];
|
|
133
|
+
/**
|
|
134
|
+
* Which row of a group of repeats the list keeps: `first` (the default),
|
|
135
|
+
* `last`, or the row with the greatest value of a child, judged on the
|
|
136
|
+
* cell as the sheet gave it.
|
|
137
|
+
*/
|
|
138
|
+
readonly keep?: 'first' | 'last' | {
|
|
139
|
+
readonly latest: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Children whose value the kept row takes from its whole group, as
|
|
143
|
+
* {@link ImportIdentity.combine} describes; `collect` applies to a child
|
|
144
|
+
* that is itself a list.
|
|
145
|
+
*/
|
|
146
|
+
readonly combine?: Readonly<Record<string, ImportCombineOp>>;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* How a group's values of a field are combined — see
|
|
150
|
+
* {@link ImportIdentity.combine}.
|
|
151
|
+
*
|
|
152
|
+
* - `sum` — added up, at the precision of the most precise value.
|
|
153
|
+
* - `avg` — the mean of the rows that have a value, rounded to two decimals
|
|
154
|
+
* or to the inputs' own precision, whichever is finer.
|
|
155
|
+
* - `min` / `max` — the lowest / highest value.
|
|
156
|
+
* - `join` — every distinct value, comma-separated, as a multi-select cell
|
|
157
|
+
* is written.
|
|
158
|
+
* - `collect` — every row of the group's lists, in sheet order, for a list
|
|
159
|
+
* field.
|
|
160
|
+
*
|
|
161
|
+
* @public
|
|
162
|
+
*/
|
|
163
|
+
export type ImportCombineOp = 'sum' | 'avg' | 'min' | 'max' | 'join' | 'collect';
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
import type { ImportIdentity } from './ImportIdentity.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reserved key of a mapped import row: the ids of the source rows it was built
|
|
4
|
+
* from. The import controller strips it before the row reaches a form, keeps
|
|
5
|
+
* it in `ImportRowState.originalData`, and never treats it as a field.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare const SOURCE_ROWS_KEY = "$sourceRows";
|
|
10
|
+
/**
|
|
11
|
+
* Reserved key of a mapped import row (and of each sub-row a mapping builds):
|
|
12
|
+
* for every choice cell the mapping could not settle up front, the other
|
|
13
|
+
* columns the option must agree with — an {@link OptionMatchCriteriaByCell}.
|
|
14
|
+
* The import controller strips it before the row reaches a form, keeps it in
|
|
15
|
+
* `ImportRowState.originalData`, and matches the cell against the options the
|
|
16
|
+
* form loads for the row only among those that agree with every criterion.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare const OPTION_MATCH_KEY = "$optionMatch";
|
|
21
|
+
/**
|
|
22
|
+
* What one choice cell must agree with besides its own text — a recipe's
|
|
23
|
+
* {@link ChoiceRule.matchOn} and {@link ChoiceRule.narrow} rules with the
|
|
24
|
+
* row's values filled in. An option is a match only when its `matchOn`
|
|
25
|
+
* attribute (any text it has, when absent) names the cell's text AND every
|
|
26
|
+
* `equals` attribute equals the given value, compared normalised.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export interface OptionMatchCriteria {
|
|
31
|
+
/** The option attribute the cell's text names; absent compares every text an option has. */
|
|
32
|
+
readonly matchOn?: string;
|
|
33
|
+
/** Option attribute → the value it must equal on this row (normalised on compare). */
|
|
34
|
+
readonly equals: Readonly<Record<string, string>>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The value of {@link OPTION_MATCH_KEY}: cell key (`formControlName`) →
|
|
38
|
+
* what that cell's option must agree with.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export type OptionMatchCriteriaByCell = Readonly<Record<string, OptionMatchCriteria>>;
|
|
43
|
+
/**
|
|
44
|
+
* A saved, named way to turn one kind of source spreadsheet — a user's own
|
|
45
|
+
* export, not the import template — into import rows for one workflow.
|
|
46
|
+
*
|
|
47
|
+
* Plain data: column sources, value maps and typed rules. Never an expression
|
|
48
|
+
* or code, because a recipe is shared by every user of the workflow.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface ImportRecipe {
|
|
53
|
+
/** UUID; immutable. Saves address a recipe by it, never by name. */
|
|
54
|
+
readonly id: string;
|
|
55
|
+
/** Unique within the workflow, compared trimmed and case-insensitively. */
|
|
56
|
+
readonly name: string;
|
|
57
|
+
/** The workflow the recipe imports into. */
|
|
58
|
+
readonly workflowId: string;
|
|
59
|
+
/** Optimistic-concurrency guard: 1 when created, +1 on every update. */
|
|
60
|
+
readonly revision: number;
|
|
61
|
+
/** Version of this shape; a newer one than the library knows is refused. */
|
|
62
|
+
readonly schemaVersion: 1;
|
|
63
|
+
/** Which sheet and header row of the source file the recipe reads. */
|
|
64
|
+
readonly source: RecipeSource;
|
|
65
|
+
/** Import column key → where its cell comes from. A key left out is not filled. */
|
|
66
|
+
readonly columns: Readonly<Record<string, ColumnSource>>;
|
|
67
|
+
/** Choice column key → how a source text is matched to one of its options. */
|
|
68
|
+
readonly choices: Readonly<Record<string, ChoiceRule>>;
|
|
69
|
+
/**
|
|
70
|
+
* Source rows to import. Rules joined by `and` must all hold; `or` starts
|
|
71
|
+
* another group, and a row is kept when any one group holds — see
|
|
72
|
+
* {@link RowRule.join}. Absent imports every row.
|
|
73
|
+
*/
|
|
74
|
+
readonly rowRules?: readonly RowRule[];
|
|
75
|
+
/** Folds several source rows into one record with a detail list. */
|
|
76
|
+
readonly grouping?: GroupingRule;
|
|
77
|
+
/**
|
|
78
|
+
* The import's own choices saved with the mapping — how repeats are told
|
|
79
|
+
* apart and combined, and how the rows are checked — so whoever uses the
|
|
80
|
+
* mapping next imports exactly the way it was set up. Absent leaves the
|
|
81
|
+
* import's defaults.
|
|
82
|
+
*/
|
|
83
|
+
readonly settings?: ImportRecipeSettings;
|
|
84
|
+
/** User id of whoever created the recipe. */
|
|
85
|
+
readonly createdBy?: string;
|
|
86
|
+
/** User id of whoever saved the current revision. */
|
|
87
|
+
readonly updatedBy?: string;
|
|
88
|
+
/** When the current revision was saved, as ISO text. */
|
|
89
|
+
readonly updatedAt?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Where a recipe reads its source.
|
|
93
|
+
*
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export interface RecipeSource {
|
|
97
|
+
/** Sheet name; absent means the first sheet. */
|
|
98
|
+
readonly sheet?: string;
|
|
99
|
+
/** 1-based row that holds the headers; data starts below it. */
|
|
100
|
+
readonly headerRow: number;
|
|
101
|
+
/** The headers at save time, normalised — what offers the recipe for a matching file. */
|
|
102
|
+
readonly headerSignature: readonly string[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Where one import column's cell comes from.
|
|
106
|
+
*
|
|
107
|
+
* - `column` — a source column, optionally transformed.
|
|
108
|
+
* - `constant` — the same text on every row.
|
|
109
|
+
* - `join` — several source columns joined by `separator`; blanks are skipped.
|
|
110
|
+
* - `random` — one of `values` (option stored values of a choice field) picked
|
|
111
|
+
* per row. The pick is a hash of `seed` and the source row id, so it is
|
|
112
|
+
* stable while one file is mapped and differs between fields; among options
|
|
113
|
+
* that depend on another input, only those the row's parent allows are drawn.
|
|
114
|
+
* - `skip` — deliberately left empty.
|
|
115
|
+
*
|
|
116
|
+
* @public
|
|
117
|
+
*/
|
|
118
|
+
export type ColumnSource = {
|
|
119
|
+
readonly kind: 'column';
|
|
120
|
+
readonly column: string;
|
|
121
|
+
readonly transforms?: readonly TransformStep[];
|
|
122
|
+
} | {
|
|
123
|
+
readonly kind: 'constant';
|
|
124
|
+
readonly value: string;
|
|
125
|
+
} | {
|
|
126
|
+
readonly kind: 'join';
|
|
127
|
+
readonly columns: readonly string[];
|
|
128
|
+
readonly separator: string;
|
|
129
|
+
} | {
|
|
130
|
+
readonly kind: 'random';
|
|
131
|
+
readonly values: readonly string[];
|
|
132
|
+
readonly seed: string;
|
|
133
|
+
} | {
|
|
134
|
+
readonly kind: 'skip';
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* How a source text is matched to one option of a choice column. A `valueMap`
|
|
138
|
+
* answer wins outright; otherwise an option matches when its `matchOn`
|
|
139
|
+
* attribute names the text AND it satisfies every `narrow` rule — the columns
|
|
140
|
+
* are considered together, so a label shared by several records (two
|
|
141
|
+
* "Finance" departments) is told apart by another column (their codes). A
|
|
142
|
+
* text still tied or unmatched is passed through for the import's own
|
|
143
|
+
* resolver, carrying the row's criteria under {@link OPTION_MATCH_KEY} so
|
|
144
|
+
* options loaded only while the row is checked are matched the same way.
|
|
145
|
+
*
|
|
146
|
+
* @public
|
|
147
|
+
*/
|
|
148
|
+
export interface ChoiceRule {
|
|
149
|
+
/** The option attribute the text is compared with; absent compares every text an option has. */
|
|
150
|
+
readonly matchOn?: string;
|
|
151
|
+
/** Further columns the option must agree with; an option must satisfy all of them. */
|
|
152
|
+
readonly narrow?: readonly NarrowRule[];
|
|
153
|
+
/** Answers the user gave for specific source texts. */
|
|
154
|
+
readonly valueMap?: readonly ValueMapEntry[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Keeps the options whose `attribute` equals a source column's value on the
|
|
158
|
+
* same row, or a fixed value.
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export interface NarrowRule {
|
|
163
|
+
/** Option attribute to compare. */
|
|
164
|
+
readonly attribute: string;
|
|
165
|
+
/** What it must equal: the row's value in a source column, or a fixed text. */
|
|
166
|
+
readonly equals: {
|
|
167
|
+
readonly column: string;
|
|
168
|
+
} | {
|
|
169
|
+
readonly value: string;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* One answer the user gave: this source text means this option.
|
|
174
|
+
*
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
export interface ValueMapEntry {
|
|
178
|
+
/** The source text, normalised (trimmed, whitespace collapsed, case folded). */
|
|
179
|
+
readonly sourceText: string;
|
|
180
|
+
/**
|
|
181
|
+
* Source column → normalised value the answer is limited to — for a text
|
|
182
|
+
* that means different options under different values of a narrowing
|
|
183
|
+
* column. Absent applies everywhere.
|
|
184
|
+
*/
|
|
185
|
+
readonly context?: Readonly<Record<string, string>>;
|
|
186
|
+
/** The option's stored value, as the template lists it (`ImportTemplateOption.value`). */
|
|
187
|
+
readonly optionValue: string;
|
|
188
|
+
/** The option's label when the answer was saved, for messages when it is gone. */
|
|
189
|
+
readonly optionLabel: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* One typed step that rewrites a source cell's text. Never code.
|
|
193
|
+
*
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
export type TransformStep = {
|
|
197
|
+
readonly op: 'trim';
|
|
198
|
+
} | {
|
|
199
|
+
readonly op: 'case';
|
|
200
|
+
readonly to: 'upper' | 'lower' | 'title';
|
|
201
|
+
} | {
|
|
202
|
+
readonly op: 'replace';
|
|
203
|
+
readonly find: string;
|
|
204
|
+
readonly with: string;
|
|
205
|
+
} | {
|
|
206
|
+
readonly op: 'split';
|
|
207
|
+
readonly on: string;
|
|
208
|
+
readonly take: number;
|
|
209
|
+
} | {
|
|
210
|
+
readonly op: 'date';
|
|
211
|
+
readonly format: 'dd/mm/yyyy' | 'mm/dd/yyyy' | 'yyyy-mm-dd' | 'excel-serial';
|
|
212
|
+
} | {
|
|
213
|
+
readonly op: 'number';
|
|
214
|
+
readonly decimal: '.' | ',';
|
|
215
|
+
readonly stripCurrency: boolean;
|
|
216
|
+
} | {
|
|
217
|
+
readonly op: 'scale';
|
|
218
|
+
readonly by: number;
|
|
219
|
+
} | {
|
|
220
|
+
readonly op: 'affix';
|
|
221
|
+
readonly prefix?: string;
|
|
222
|
+
readonly suffix?: string;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* A condition on a source row's cell. A recipe's rules read as `&&` / `||`
|
|
226
|
+
* with the usual precedence: `and` binds tighter than `or`, so
|
|
227
|
+
* `A and B or C` keeps a row when A and B both hold, or when C does.
|
|
228
|
+
*
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
export interface RowRule {
|
|
232
|
+
/** Source column. */
|
|
233
|
+
readonly column: string;
|
|
234
|
+
/** Comparison; `gt` / `lt` compare numbers, the rest normalised text. */
|
|
235
|
+
readonly op: 'is' | 'isNot' | 'contains' | 'blank' | 'notBlank' | 'gt' | 'lt';
|
|
236
|
+
/** Operand; unused by `blank` / `notBlank`. */
|
|
237
|
+
readonly value?: string;
|
|
238
|
+
/**
|
|
239
|
+
* How the rule joins the rule before it: `and` (the default) adds it to
|
|
240
|
+
* that rule's group, `or` starts a new group. Ignored on the first rule.
|
|
241
|
+
*/
|
|
242
|
+
readonly join?: 'and' | 'or';
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The import's own choices saved with a recipe — see
|
|
246
|
+
* {@link ImportRecipe.settings}. Every member is optional; one left out keeps
|
|
247
|
+
* the import's default.
|
|
248
|
+
*
|
|
249
|
+
* @public
|
|
250
|
+
*/
|
|
251
|
+
export interface ImportRecipeSettings {
|
|
252
|
+
/**
|
|
253
|
+
* How repeated rows are told apart, which row a repeat keeps, and which
|
|
254
|
+
* fields it takes from the whole group (`sum`, `join`, `collect`, …) — the
|
|
255
|
+
* run's identity as the user set it. A key, field or list the form no
|
|
256
|
+
* longer has is dropped when the mapping is applied.
|
|
257
|
+
*/
|
|
258
|
+
readonly identity?: ImportIdentity;
|
|
259
|
+
/** Whether identical API calls are shared between rows while they are checked. */
|
|
260
|
+
readonly apiCache?: boolean;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Folds source rows into records: one record per distinct tuple of `by`, its
|
|
264
|
+
* rows becoming the detail rows of one MultipleInput.
|
|
265
|
+
*
|
|
266
|
+
* @public
|
|
267
|
+
*/
|
|
268
|
+
export interface GroupingRule {
|
|
269
|
+
/** Source columns whose values identify a record. */
|
|
270
|
+
readonly by: readonly string[];
|
|
271
|
+
/** `formControlName` of the MultipleInput the grouped rows fill. */
|
|
272
|
+
readonly detailTarget: string;
|
|
273
|
+
/** Main-sheet column key → how the group's values combine; `first` by default. */
|
|
274
|
+
readonly aggregate?: Readonly<Record<string, 'first' | 'last' | 'sum' | 'min' | 'max' | 'count' | 'join'>>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* One sheet of a source file as a grid of cell texts, before any header row is chosen.
|
|
278
|
+
*
|
|
279
|
+
* @public
|
|
280
|
+
*/
|
|
281
|
+
export interface SourceSheet {
|
|
282
|
+
/** The sheet's tab name. */
|
|
283
|
+
readonly name: string;
|
|
284
|
+
/** Rows top to bottom, cells left to right, as trimmed text; blanks are `''`. */
|
|
285
|
+
readonly grid: readonly (readonly string[])[];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* One data row of a source sheet.
|
|
289
|
+
*
|
|
290
|
+
* @public
|
|
291
|
+
*/
|
|
292
|
+
export interface SourceRow {
|
|
293
|
+
/** UUID minted when the file was read; identifies the row for this import session only. */
|
|
294
|
+
readonly id: string;
|
|
295
|
+
/** Sheet the row is on. */
|
|
296
|
+
readonly sheet: string;
|
|
297
|
+
/** 1-based row number in that sheet. */
|
|
298
|
+
readonly row: number;
|
|
299
|
+
/** Header → cell text. */
|
|
300
|
+
readonly cells: Readonly<Record<string, string>>;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* A source sheet read under a chosen header row.
|
|
304
|
+
*
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
export interface SourceTable {
|
|
308
|
+
/** Sheet the table was read from. */
|
|
309
|
+
readonly sheet: string;
|
|
310
|
+
/** 1-based header row. */
|
|
311
|
+
readonly headerRow: number;
|
|
312
|
+
/** Headers left to right; blank and repeated headers are made unique. */
|
|
313
|
+
readonly headers: readonly string[];
|
|
314
|
+
/** Data rows below the header row; wholly blank rows are left out. */
|
|
315
|
+
readonly rows: readonly SourceRow[];
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* What an uploaded file is, as far as the import is concerned.
|
|
319
|
+
*
|
|
320
|
+
* - `template` — the import template (or a sheet shaped exactly like it): it
|
|
321
|
+
* goes through today's import unchanged.
|
|
322
|
+
* - `near-template` — the template with headers renamed or added; `suggestion`
|
|
323
|
+
* maps it.
|
|
324
|
+
* - `own` — the user's own export; `suggestion` is a starting mapping.
|
|
325
|
+
*
|
|
326
|
+
* Both of the last two carry `saved`: the workflow's recipes whose headers
|
|
327
|
+
* resemble the file's.
|
|
328
|
+
*
|
|
329
|
+
* @public
|
|
330
|
+
*/
|
|
331
|
+
export type SourceVerdict = {
|
|
332
|
+
readonly kind: 'template';
|
|
333
|
+
} | {
|
|
334
|
+
readonly kind: 'near-template';
|
|
335
|
+
readonly score: number;
|
|
336
|
+
readonly suggestion: ImportRecipe;
|
|
337
|
+
readonly saved: readonly SavedRecipeMatch[];
|
|
338
|
+
} | {
|
|
339
|
+
readonly kind: 'own';
|
|
340
|
+
readonly score: number;
|
|
341
|
+
readonly suggestion: ImportRecipe;
|
|
342
|
+
readonly saved: readonly SavedRecipeMatch[];
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* A saved recipe offered for a file, with how well it fits.
|
|
346
|
+
*
|
|
347
|
+
* @public
|
|
348
|
+
*/
|
|
349
|
+
export interface SavedRecipeMatch {
|
|
350
|
+
/** The recipe. */
|
|
351
|
+
readonly recipe: ImportRecipe;
|
|
352
|
+
/** Jaccard similarity of its header signature to the file's headers, 0–1. */
|
|
353
|
+
readonly similarity: number;
|
|
354
|
+
/** What no longer fits; a recipe with blocking issues is still offered. */
|
|
355
|
+
readonly check: RecipeCheck;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* One broken reference in a recipe.
|
|
359
|
+
*
|
|
360
|
+
* @public
|
|
361
|
+
*/
|
|
362
|
+
export interface RecipeIssue {
|
|
363
|
+
/** What is wrong. */
|
|
364
|
+
readonly kind: 'targetMissing' | 'requiredUnmapped' | 'sourceColumnMissing' | 'optionMissing' | 'optionUnverifiable' | 'attributeMissing' | 'groupingInvalid' | 'schemaNewer';
|
|
365
|
+
/** `true` when the recipe cannot be validated or saved until it is fixed. */
|
|
366
|
+
readonly blocking: boolean;
|
|
367
|
+
/** The import column key concerned, when there is one. */
|
|
368
|
+
readonly target?: string;
|
|
369
|
+
/** The source column concerned, when there is one. */
|
|
370
|
+
readonly source?: string;
|
|
371
|
+
/** The issue in plain words. */
|
|
372
|
+
readonly detail: string;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The result of checking a recipe against a form and, optionally, a file.
|
|
376
|
+
*
|
|
377
|
+
* @public
|
|
378
|
+
*/
|
|
379
|
+
export interface RecipeCheck {
|
|
380
|
+
/** `true` when no issue is blocking. */
|
|
381
|
+
readonly ok: boolean;
|
|
382
|
+
/** Every issue found, blocking first. */
|
|
383
|
+
readonly issues: readonly RecipeIssue[];
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* How one choice cell was settled by a recipe.
|
|
387
|
+
*
|
|
388
|
+
* @public
|
|
389
|
+
*/
|
|
390
|
+
export interface ChoiceOutcome {
|
|
391
|
+
/** `value`: `cell` is an option's stored value. `pass-through`: `cell` is the original text. */
|
|
392
|
+
readonly kind: 'value' | 'pass-through';
|
|
393
|
+
/** The cell to put in the mapped row. */
|
|
394
|
+
readonly cell: unknown;
|
|
395
|
+
/** Which step decided, or why none did. */
|
|
396
|
+
readonly reason: 'map' | 'rule' | 'unique' | 'tied' | 'unmatched' | 'partial';
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* The rows a recipe produced, ready for the import controller.
|
|
400
|
+
*
|
|
401
|
+
* @public
|
|
402
|
+
*/
|
|
403
|
+
export interface MappedImport {
|
|
404
|
+
/** Template-shaped rows, each carrying {@link SOURCE_ROWS_KEY}. */
|
|
405
|
+
readonly rows: Record<string, unknown>[];
|
|
406
|
+
/** Counts for the mapper's summary. */
|
|
407
|
+
readonly stats: MappingStats;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Counts describing a mapping run.
|
|
411
|
+
*
|
|
412
|
+
* @public
|
|
413
|
+
*/
|
|
414
|
+
export interface MappingStats {
|
|
415
|
+
/** Required columns the recipe fills. */
|
|
416
|
+
readonly requiredMapped: number;
|
|
417
|
+
/** Required columns of the form. */
|
|
418
|
+
readonly requiredTotal: number;
|
|
419
|
+
/** Choice column key → cells passed through unmatched or tied. */
|
|
420
|
+
readonly unmatchedValues: Readonly<Record<string, number>>;
|
|
421
|
+
/** Source rows the row rules left out. */
|
|
422
|
+
readonly filteredOut: number;
|
|
423
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserved key of a mapped import row: the ids of the source rows it was built
|
|
3
|
+
* from. The import controller strips it before the row reaches a form, keeps
|
|
4
|
+
* it in `ImportRowState.originalData`, and never treats it as a field.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export const SOURCE_ROWS_KEY = '$sourceRows';
|
|
9
|
+
/**
|
|
10
|
+
* Reserved key of a mapped import row (and of each sub-row a mapping builds):
|
|
11
|
+
* for every choice cell the mapping could not settle up front, the other
|
|
12
|
+
* columns the option must agree with — an {@link OptionMatchCriteriaByCell}.
|
|
13
|
+
* The import controller strips it before the row reaches a form, keeps it in
|
|
14
|
+
* `ImportRowState.originalData`, and matches the cell against the options the
|
|
15
|
+
* form loads for the row only among those that agree with every criterion.
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export const OPTION_MATCH_KEY = '$optionMatch';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ImportCombineOp } from './ImportIdentity.js';
|
|
1
2
|
/**
|
|
2
3
|
* Lifecycle states for a single import row driven by the import controller in
|
|
3
4
|
* `ngx-t-forms`.
|
|
@@ -82,15 +83,91 @@ export interface ImportRowState {
|
|
|
82
83
|
*/
|
|
83
84
|
optionChoices?: Record<string, ImportOptionChoice[]>;
|
|
84
85
|
/**
|
|
85
|
-
* The `rowIndex` of the
|
|
86
|
-
* given an `ImportIdentity` and this row's identity matches.
|
|
87
|
-
* LOWEST index of the
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
86
|
+
* The `rowIndex` of the row kept for this row's group, when the session was
|
|
87
|
+
* given an `ImportIdentity` and this row's identity matches. The kept row is
|
|
88
|
+
* the LOWEST index of the group — first wins — unless `ImportIdentity.keep`
|
|
89
|
+
* is `last` or the host kept another row with the controller's `keepRow`; it
|
|
90
|
+
* is stable between such choices, so a host can offer "go to row N". Set
|
|
91
|
+
* under both duplicate policies; under `skip` the row's `status` is
|
|
92
|
+
* `duplicate` as well. Cleared when a re-run changes the identities so that
|
|
93
|
+
* the row no longer repeats anything.
|
|
92
94
|
*/
|
|
93
95
|
duplicateOf?: number;
|
|
96
|
+
/**
|
|
97
|
+
* formControlName → how this row's value was taken from its duplicate
|
|
98
|
+
* group, for each field `ImportIdentity.combine` names. Set on the row a
|
|
99
|
+
* group keeps once it has been checked with the combined values; absent on
|
|
100
|
+
* a row that stands alone. `settledValue` already holds the outcome — this
|
|
101
|
+
* says where it came from.
|
|
102
|
+
*/
|
|
103
|
+
combined?: Record<string, ImportCombinedValue>;
|
|
104
|
+
/**
|
|
105
|
+
* formControlName of a list field → how the repeats inside its rows were
|
|
106
|
+
* folded (`ImportIdentity.lists`), for each list some row of which repeated
|
|
107
|
+
* another. Absent when no list of the row had a repeat. `settledValue`
|
|
108
|
+
* holds the list as it was checked — the rows that remained — and this
|
|
109
|
+
* says which rows each of them stands for.
|
|
110
|
+
*/
|
|
111
|
+
folded?: Record<string, ImportListFold>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Where a kept row's value of a combined field came from — see
|
|
115
|
+
* {@link ImportRowState.combined}.
|
|
116
|
+
*
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export interface ImportCombinedValue {
|
|
120
|
+
/** How the group's values were combined. */
|
|
121
|
+
op: ImportCombineOp;
|
|
122
|
+
/**
|
|
123
|
+
* The value the row was checked with: a number, or for `join` the joined
|
|
124
|
+
* text. Absent when no row of the group had a value there, and for
|
|
125
|
+
* `collect`, whose outcome is the list itself (see `items`).
|
|
126
|
+
*/
|
|
127
|
+
value?: number | string;
|
|
128
|
+
/**
|
|
129
|
+
* `rowIndex` of every row of the group, in sheet order, the kept row
|
|
130
|
+
* included. For a group inside a list ({@link ImportListFoldGroup}), the
|
|
131
|
+
* position of each row in the list as it came, from 0.
|
|
132
|
+
*/
|
|
133
|
+
rows: number[];
|
|
134
|
+
/** The rows whose cell held a value the op could read, and so went into the outcome; blank ones are left out. */
|
|
135
|
+
counted: number[];
|
|
136
|
+
/** The rows whose cell held something the op could not read; when any, the kept row is `invalid`. */
|
|
137
|
+
rejected: number[];
|
|
138
|
+
/** For `collect`: how many list rows the counted rows' lists held together — the kept row's list before any fold. */
|
|
139
|
+
items?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* How the repeats inside one list of a row were folded — see
|
|
143
|
+
* {@link ImportRowState.folded}.
|
|
144
|
+
*
|
|
145
|
+
* @public
|
|
146
|
+
*/
|
|
147
|
+
export interface ImportListFold {
|
|
148
|
+
/** How many rows the list had as the sheet gave it. */
|
|
149
|
+
rows: number;
|
|
150
|
+
/** How many rows remained, and were checked. */
|
|
151
|
+
kept: number;
|
|
152
|
+
/** Each group of rows that repeated one another, in the order of their kept rows. */
|
|
153
|
+
groups: ImportListFoldGroup[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* One group of repeated rows inside a list — see {@link ImportListFold}.
|
|
157
|
+
* Positions count the rows of the list as the sheet gave it, from 0, except
|
|
158
|
+
* `at`, which counts the rows that remained.
|
|
159
|
+
*
|
|
160
|
+
* @public
|
|
161
|
+
*/
|
|
162
|
+
export interface ImportListFoldGroup {
|
|
163
|
+
/** The position of the row the group kept, in the list as it came. */
|
|
164
|
+
keeper: number;
|
|
165
|
+
/** The position of the kept row in the list as it was checked — its index in `settledValue`'s list. */
|
|
166
|
+
at: number;
|
|
167
|
+
/** The position of every row of the group, in list order, the kept one included. */
|
|
168
|
+
rows: number[];
|
|
169
|
+
/** Child `formControlName` → how the kept row's value was taken from the group, for each child the list's `combine` names. */
|
|
170
|
+
combined: Record<string, ImportCombinedValue>;
|
|
94
171
|
}
|
|
95
172
|
/**
|
|
96
173
|
* One option an imported cell could stand for.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export { ImportOptionCandidate, ImportOptionChoice, ImportRowState, ImportRowStatus } from './ImportRowState.js';
|
|
1
|
+
export { ImportCombinedValue, ImportListFold, ImportListFoldGroup, ImportOptionCandidate, ImportOptionChoice, ImportRowState, ImportRowStatus } from './ImportRowState.js';
|
|
2
2
|
export { ImportProgress } from './ImportProgress.js';
|
|
3
|
-
export { ImportIdentity } from './ImportIdentity.js';
|
|
3
|
+
export { ImportCombineOp, ImportIdentity, ImportListIdentity } from './ImportIdentity.js';
|
|
4
|
+
export { OPTION_MATCH_KEY, SOURCE_ROWS_KEY } from './ImportRecipe.js';
|
|
5
|
+
export type { ChoiceOutcome, ChoiceRule, OptionMatchCriteria, OptionMatchCriteriaByCell, ColumnSource, GroupingRule, ImportRecipe, ImportRecipeSettings, MappedImport, MappingStats, NarrowRule, RecipeCheck, RecipeIssue, RecipeSource, RowRule, SavedRecipeMatch, SourceRow, SourceSheet, SourceTable, SourceVerdict, TransformStep, ValueMapEntry, } from './ImportRecipe.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { OPTION_MATCH_KEY, SOURCE_ROWS_KEY } from './ImportRecipe.js';
|
|
@@ -4,11 +4,30 @@ import { FormListSection, FormStateErrors, IFormsInitStateInterface, LocalFormSt
|
|
|
4
4
|
import { DatabaseFormInterface } from '../Form/formInterface.js';
|
|
5
5
|
export interface ITowerStepColumn extends FormColumnInputs {
|
|
6
6
|
canReload: IInputCanReload;
|
|
7
|
+
/**
|
|
8
|
+
* Present only when the column's options fetch binds the field's search box
|
|
9
|
+
* (a `searchTerm` mapped input, or a `{{@search}}` template token). The
|
|
10
|
+
* rendered search box then drives the API instead of filtering locally.
|
|
11
|
+
* Absent ⇒ the search box filters the loaded options in the browser.
|
|
12
|
+
*/
|
|
13
|
+
optionsSearch?: IInputOptionsSearch;
|
|
7
14
|
inputConfigErrors: {
|
|
8
15
|
key: string;
|
|
9
16
|
message: string;
|
|
10
17
|
}[];
|
|
11
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The bridge between a field's search box and its search-bound options fetch.
|
|
21
|
+
* Handed to the rendered column by the form engine; never persisted.
|
|
22
|
+
*/
|
|
23
|
+
export interface IInputOptionsSearch {
|
|
24
|
+
/** Sends a new search term to the options fetch (re-fires it when the term changed). */
|
|
25
|
+
search: (term: string) => void;
|
|
26
|
+
/** The term the options fetch currently uses — seeds a re-created search box. */
|
|
27
|
+
term: () => string;
|
|
28
|
+
/** Whether the options fetch is in flight (reactive when read in a template). */
|
|
29
|
+
isSearching: () => boolean;
|
|
30
|
+
}
|
|
12
31
|
export interface IInputCanReload {
|
|
13
32
|
emit: () => void;
|
|
14
33
|
canReload: boolean;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { FormsStoreSelectorsInterface, ITowerFormSteps, ITowerStepColumn } from "./ITowerFormSteps.js";
|
|
1
|
+
import { FormsStoreSelectorsInterface, IInputOptionsSearch, ITowerFormSteps, ITowerStepColumn } from "./ITowerFormSteps.js";
|
|
2
2
|
export { ITowerFormSteps, FormsStoreSelectorsInterface, ITowerStepColumn };
|
|
3
|
+
export type { IInputOptionsSearch };
|
|
@@ -126,6 +126,33 @@ export interface NgxTFormsLocalization {
|
|
|
126
126
|
* library follows every emission and uses its defaults until the first one.
|
|
127
127
|
*/
|
|
128
128
|
export type NgxTFormsLocalizationSource = NgxTFormsLocalization | Observable<NgxTFormsLocalization>;
|
|
129
|
+
/**
|
|
130
|
+
* One classification a form can be filed under — see `NgxTFormsConfig.formClassifications`.
|
|
131
|
+
*/
|
|
132
|
+
export interface FormClassificationOption {
|
|
133
|
+
/** Stable identifier stored on the form (`FormInterface.formClassifications`). Never rename it once forms use it. */
|
|
134
|
+
value: string;
|
|
135
|
+
/** What the form builder shows. */
|
|
136
|
+
label: string;
|
|
137
|
+
/**
|
|
138
|
+
* Optional heading the option is listed under, e.g. `Industry` or `Module`, so one
|
|
139
|
+
* list can classify along several axes. Options without a group are listed first.
|
|
140
|
+
*/
|
|
141
|
+
group?: string;
|
|
142
|
+
/** Optional one-line hint shown under the label in the picker. */
|
|
143
|
+
description?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Pre-select this option on every NEW form. Applies only to a form that has not
|
|
146
|
+
* been saved and whose classifications the author has not touched; stored forms
|
|
147
|
+
* keep what they have, and an author can clear a default and have that stick.
|
|
148
|
+
*/
|
|
149
|
+
isDefault?: boolean;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Either a fixed classification list or a stream of it, for an application whose
|
|
153
|
+
* list depends on the signed-in organisation. The library follows every emission.
|
|
154
|
+
*/
|
|
155
|
+
export type FormClassificationsSource = ReadonlyArray<FormClassificationOption> | Observable<ReadonlyArray<FormClassificationOption>>;
|
|
129
156
|
/** Tuning for the spreadsheet import template — see `NgxTFormsConfig.importTemplate`. */
|
|
130
157
|
export interface ImportTemplateConfig {
|
|
131
158
|
/**
|
|
@@ -205,5 +232,25 @@ export interface NgxTFormsConfig {
|
|
|
205
232
|
* })
|
|
206
233
|
*/
|
|
207
234
|
localization?: NgxTFormsLocalizationSource;
|
|
235
|
+
/**
|
|
236
|
+
* The classifications a form builder can file a form under — industries, modules,
|
|
237
|
+
* use cases, whatever the application groups its forms by. The builder offers them
|
|
238
|
+
* as a multi-select and stores the chosen `value`s on
|
|
239
|
+
* `FormInterface.formClassifications`. Options marked `isDefault` are pre-selected
|
|
240
|
+
* on new forms. Omit it (or supply an empty list) and the builder hides the picker.
|
|
241
|
+
*
|
|
242
|
+
* Pass an `Observable` when the list belongs to the signed-in organisation.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* provideNgxTForms({
|
|
246
|
+
* formBuilder: myStoreFunctions,
|
|
247
|
+
* formClassifications: [
|
|
248
|
+
* { value: 'construction', label: 'Construction', group: 'Industry' },
|
|
249
|
+
* { value: 'procurement', label: 'Procurement', group: 'Module', isDefault: true },
|
|
250
|
+
* { value: 'onboarding', label: 'Supplier onboarding', group: 'Use case' },
|
|
251
|
+
* ],
|
|
252
|
+
* })
|
|
253
|
+
*/
|
|
254
|
+
formClassifications?: FormClassificationsSource;
|
|
208
255
|
[key: string]: string | Object | undefined;
|
|
209
256
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ActionButton, BasisValidationError, DialogConfig, IStoreFunctions, MscoaValuetValidationErrors } from "./IStoreFunctions.js";
|
|
2
|
-
import { DateLike, FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, FormsCurrencyDisplay, FormsDateFormat, FormsTimeFormat, FormsWeekDay, GlobalVariables, GlobalVariableValue, IFinancialCycles, NgxTFormsCurrencyLocalization, NgxTFormsLocalization, NgxTFormsLocalizationSource } from "./environment.js";
|
|
3
|
-
export { IStoreFunctions, FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, FormsCurrencyDisplay, FormsDateFormat, FormsTimeFormat, FormsWeekDay, NgxTFormsCurrencyLocalization, NgxTFormsLocalization, NgxTFormsLocalizationSource, ActionButton, DialogConfig, IFinancialCycles, DateLike, GlobalVariables, GlobalVariableValue, MscoaValuetValidationErrors, BasisValidationError, };
|
|
2
|
+
import { DateLike, FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, FormsCurrencyDisplay, FormsDateFormat, FormsTimeFormat, FormsWeekDay, GlobalVariables, GlobalVariableValue, IFinancialCycles, NgxTFormsCurrencyLocalization, NgxTFormsLocalization, NgxTFormsLocalizationSource, FormClassificationOption, FormClassificationsSource } from "./environment.js";
|
|
3
|
+
export { IStoreFunctions, FORMS_CURRENCY_DISPLAYS, FORMS_DATE_FORMATS, FORMS_TIME_FORMATS, FORMS_WEEK_DAYS, FormsCurrencyDisplay, FormsDateFormat, FormsTimeFormat, FormsWeekDay, NgxTFormsCurrencyLocalization, NgxTFormsLocalization, NgxTFormsLocalizationSource, FormClassificationOption, FormClassificationsSource, ActionButton, DialogConfig, IFinancialCycles, DateLike, GlobalVariables, GlobalVariableValue, MscoaValuetValidationErrors, BasisValidationError, };
|
|
@@ -23,6 +23,9 @@ export interface DataFetchingBaseConfig {
|
|
|
23
23
|
* string (`"prefix-{{x}}"`).
|
|
24
24
|
* - Objects and arrays nest arbitrarily; object keys are literal, so Mongo-style
|
|
25
25
|
* dotted keys such as `"form.contractType"` are preserved as authored.
|
|
26
|
+
* - The reserved `"{{@search}}"` token (options fetches only) is the text typed
|
|
27
|
+
* into the field's own search box. It never holds the fetch idle: an empty
|
|
28
|
+
* search resolves to `''`.
|
|
26
29
|
*/
|
|
27
30
|
export type PayloadTemplateValue = string | number | boolean | null | PayloadTemplateValue[] | {
|
|
28
31
|
[key: string]: PayloadTemplateValue;
|
|
@@ -91,7 +94,9 @@ export type HeaderTemplateValue = string | number | boolean;
|
|
|
91
94
|
* Like a payload template, a token that resolves empty keeps the fetch **idle**:
|
|
92
95
|
* a request that would go out without its `Authorization`/tenant header is a
|
|
93
96
|
* request that fails, so the engine waits for the bound field instead of issuing
|
|
94
|
-
* a doomed call.
|
|
97
|
+
* a doomed call. The reserved `{{@search}}` token (options fetches only) is the
|
|
98
|
+
* exception: it binds the field's own search box and never holds the fetch idle
|
|
99
|
+
* — an exact `{{@search}}` value is simply left out while the search box is empty.
|
|
95
100
|
*
|
|
96
101
|
* @example
|
|
97
102
|
* headerTemplate: {
|
|
@@ -130,12 +135,15 @@ export type QueryTemplateValue = string | number | boolean;
|
|
|
130
135
|
*
|
|
131
136
|
* Like a header template, a token that resolves empty keeps the fetch **idle**:
|
|
132
137
|
* a request missing a bound parameter would return the wrong data, so the
|
|
133
|
-
* engine waits for the bound field instead.
|
|
138
|
+
* engine waits for the bound field instead. The reserved `{{@search}}` token
|
|
139
|
+
* (options fetches only) binds the field's own search box and never idles —
|
|
140
|
+
* an exact `{{@search}}` parameter is left out while the search box is empty.
|
|
134
141
|
*
|
|
135
142
|
* @example
|
|
136
143
|
* queryTemplate: {
|
|
137
144
|
* financialYear: '{{financialYear}}',
|
|
138
145
|
* department: '{{departmentId}}',
|
|
146
|
+
* search: '{{@search}}',
|
|
139
147
|
* pageSize: 50,
|
|
140
148
|
* }
|
|
141
149
|
*/
|
|
@@ -3,6 +3,20 @@ export declare enum MinInputTypes {
|
|
|
3
3
|
Default = "default",
|
|
4
4
|
MapTo = "mapto",
|
|
5
5
|
MapDocFilter = "mapDocFilter",
|
|
6
|
+
/**
|
|
7
|
+
* Resolves to the text the user types into the field's own search box (the
|
|
8
|
+
* dropdown's panel search or the selection table's search field). Only
|
|
9
|
+
* meaningful on an **options** fetch: every change of the search text re-fires
|
|
10
|
+
* the fetch with the new term, so the API does the filtering instead of the
|
|
11
|
+
* browser.
|
|
12
|
+
*
|
|
13
|
+
* Never gates the fetch — an empty search box sends `''`, which the endpoint
|
|
14
|
+
* should read as "no filter". Carries no `mapTo`/`defaultValue`.
|
|
15
|
+
*
|
|
16
|
+
* The template equivalent is the reserved `{{@search}}` token, accepted by
|
|
17
|
+
* `payloadTemplate`, `queryTemplate` and `headerTemplate`.
|
|
18
|
+
*/
|
|
19
|
+
SearchTerm = "searchTerm",
|
|
6
20
|
/**
|
|
7
21
|
* @deprecated Never implemented. No editor offers it, no runtime handles it —
|
|
8
22
|
* a `bind` entry leaves its fetch permanently idle. The runtime now surfaces a
|
|
@@ -3,6 +3,20 @@ export var MinInputTypes;
|
|
|
3
3
|
MinInputTypes["Default"] = "default";
|
|
4
4
|
MinInputTypes["MapTo"] = "mapto";
|
|
5
5
|
MinInputTypes["MapDocFilter"] = "mapDocFilter";
|
|
6
|
+
/**
|
|
7
|
+
* Resolves to the text the user types into the field's own search box (the
|
|
8
|
+
* dropdown's panel search or the selection table's search field). Only
|
|
9
|
+
* meaningful on an **options** fetch: every change of the search text re-fires
|
|
10
|
+
* the fetch with the new term, so the API does the filtering instead of the
|
|
11
|
+
* browser.
|
|
12
|
+
*
|
|
13
|
+
* Never gates the fetch — an empty search box sends `''`, which the endpoint
|
|
14
|
+
* should read as "no filter". Carries no `mapTo`/`defaultValue`.
|
|
15
|
+
*
|
|
16
|
+
* The template equivalent is the reserved `{{@search}}` token, accepted by
|
|
17
|
+
* `payloadTemplate`, `queryTemplate` and `headerTemplate`.
|
|
18
|
+
*/
|
|
19
|
+
MinInputTypes["SearchTerm"] = "searchTerm";
|
|
6
20
|
/**
|
|
7
21
|
* @deprecated Never implemented. No editor offers it, no runtime handles it —
|
|
8
22
|
* a `bind` entry leaves its fetch permanently idle. The runtime now surfaces a
|
|
@@ -39,7 +39,27 @@ export declare enum ReportTypes {
|
|
|
39
39
|
Sum = "sum",
|
|
40
40
|
Lowest = "lowest",
|
|
41
41
|
Highest = "highest",
|
|
42
|
-
Category = "category"
|
|
42
|
+
Category = "category",
|
|
43
|
+
/** Middle value of a currency/number field; money is right-skewed, so it can deserve the headline. */
|
|
44
|
+
Median = "median",
|
|
45
|
+
/** Opts a date/daysAgo field in as a time axis (volume, seasonality, lead time). */
|
|
46
|
+
Trend = "trend",
|
|
47
|
+
/** Opts a string/systemReference field in as an entity (unique count, Pareto) — suppliers, customers, assets. */
|
|
48
|
+
Distinct = "distinct"
|
|
49
|
+
}
|
|
50
|
+
/** Whether a rise in a measure is good news, bad news, or neither. */
|
|
51
|
+
export type ReportPolarity = 'higherIsBetter' | 'lowerIsBetter' | 'neutral';
|
|
52
|
+
/**
|
|
53
|
+
* Optional qualifiers on a reportable field. None is required: absent, the report engine
|
|
54
|
+
* picks the first measure/dimension as primary, never judges direction, and bands by quartile.
|
|
55
|
+
*/
|
|
56
|
+
export interface ReportHintsInterface {
|
|
57
|
+
/** Picks the hero KPI (measure) or the default "by" grouping (dimension). */
|
|
58
|
+
primary?: boolean;
|
|
59
|
+
/** Lets insights say "improved"/"worsened" instead of "rose"/"fell". */
|
|
60
|
+
polarity?: ReportPolarity;
|
|
61
|
+
/** Ascending value edges for concentration insights, e.g. [100000, 500000]. */
|
|
62
|
+
bands?: number[];
|
|
43
63
|
}
|
|
44
64
|
export interface DocumentLitsLabelConfigInterface {
|
|
45
65
|
label: string;
|
|
@@ -48,6 +68,7 @@ export interface DocumentLitsLabelConfigInterface {
|
|
|
48
68
|
stepName: string | null;
|
|
49
69
|
valueType: DocumentLitsLabelConfigInterfaceValueType;
|
|
50
70
|
reportType?: ReportTypes[];
|
|
71
|
+
reportHints?: ReportHintsInterface;
|
|
51
72
|
}
|
|
52
73
|
export interface GridListLabelConfigInterface {
|
|
53
74
|
labelConfiguration: DocumentLitsLabelConfigInterface[];
|
|
@@ -25,4 +25,10 @@ export var ReportTypes;
|
|
|
25
25
|
ReportTypes["Lowest"] = "lowest";
|
|
26
26
|
ReportTypes["Highest"] = "highest";
|
|
27
27
|
ReportTypes["Category"] = "category";
|
|
28
|
+
/** Middle value of a currency/number field; money is right-skewed, so it can deserve the headline. */
|
|
29
|
+
ReportTypes["Median"] = "median";
|
|
30
|
+
/** Opts a date/daysAgo field in as a time axis (volume, seasonality, lead time). */
|
|
31
|
+
ReportTypes["Trend"] = "trend";
|
|
32
|
+
/** Opts a string/systemReference field in as an entity (unique count, Pareto) — suppliers, customers, assets. */
|
|
33
|
+
ReportTypes["Distinct"] = "distinct";
|
|
28
34
|
})(ReportTypes || (ReportTypes = {}));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DocumentLitsLabelConfigInterface, DocumentLitsLabelConfigInterfaceValueType, ReportTypes } from "./DocumentSectionConfigurationsInterface.js";
|
|
1
|
+
import { DocumentLitsLabelConfigInterface, DocumentLitsLabelConfigInterfaceValueType, ReportHintsInterface, ReportPolarity, ReportTypes } from "./DocumentSectionConfigurationsInterface.js";
|
|
2
2
|
import { WorkflowFunctionTypes } from "./WorkflowFunctionTypes.js";
|
|
3
|
-
export { DocumentLitsLabelConfigInterface, DocumentLitsLabelConfigInterfaceValueType, ReportTypes, WorkflowFunctionTypes };
|
|
3
|
+
export { DocumentLitsLabelConfigInterface, DocumentLitsLabelConfigInterfaceValueType, ReportHintsInterface, ReportPolarity, ReportTypes, WorkflowFunctionTypes };
|
|
@@ -138,6 +138,12 @@ export const baseFormColumnInputsSchema = Joi.object({
|
|
|
138
138
|
emit: Joi.function().required(),
|
|
139
139
|
canReload: Joi.boolean().required()
|
|
140
140
|
}).optional(),
|
|
141
|
+
// Runtime-only: present only on inputs whose options fetch is bound to the search box.
|
|
142
|
+
[AllFormInputPrimaryKeys.OptionsSearch]: Joi.object({
|
|
143
|
+
search: Joi.function().required(),
|
|
144
|
+
term: Joi.function().required(),
|
|
145
|
+
isSearching: Joi.function().required()
|
|
146
|
+
}).optional(),
|
|
141
147
|
[AllFormInputPrimaryKeys.GroupBy]: Joi.array().items(Joi.string()),
|
|
142
148
|
[AllFormInputPrimaryKeys.ConditionalInputConfig]: Joi.any().optional(),
|
|
143
149
|
[SpecialElementKeys.MultipleInputAvailableOperations]: Joi.array().items(Joi.string().valid(...Object.values(MultipleInputAvailableOperations))).optional(),
|
|
@@ -3,6 +3,41 @@ import { FormInterface } from "../interfaces/Form/index.js";
|
|
|
3
3
|
export declare const FormSlideSchema: Joi.ObjectSchema<any>;
|
|
4
4
|
export declare const FormSubmissionHandleSchema: Joi.ObjectSchema<any>;
|
|
5
5
|
export declare const FormSchema: Joi.ObjectSchema<any>;
|
|
6
|
+
/**
|
|
7
|
+
* Fewest words a form description may have — one full sentence — see
|
|
8
|
+
* `validateFormDescription`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const FORM_DESCRIPTION_MIN_WORDS = 10;
|
|
11
|
+
/** Most paragraphs a form description may have — see `validateFormDescription`. */
|
|
12
|
+
export declare const FORM_DESCRIPTION_MAX_PARAGRAPHS = 2;
|
|
13
|
+
/** Word and paragraph counts of a form description, as `validateFormDescription` counts them. */
|
|
14
|
+
export interface FormDescriptionMeasure {
|
|
15
|
+
/** Whitespace-separated words. */
|
|
16
|
+
words: number;
|
|
17
|
+
/** Non-empty blocks separated by at least one blank line. A single line break does not start a paragraph. */
|
|
18
|
+
paragraphs: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Counts the words and paragraphs of a form description. Paragraphs are separated
|
|
22
|
+
* by a blank line (whitespace-only lines count as blank); a single line break stays
|
|
23
|
+
* inside its paragraph.
|
|
24
|
+
*
|
|
25
|
+
* @param text The description; `undefined`/`null` count as empty.
|
|
26
|
+
* @returns The counts — both `0` for blank text.
|
|
27
|
+
*/
|
|
28
|
+
export declare function measureFormDescription(text: string | null | undefined): FormDescriptionMeasure;
|
|
29
|
+
/**
|
|
30
|
+
* The rule a form description must pass before the builder saves the form: present,
|
|
31
|
+
* at least `FORM_DESCRIPTION_MIN_WORDS` words, at most `FORM_DESCRIPTION_MAX_PARAGRAPHS`
|
|
32
|
+
* paragraphs.
|
|
33
|
+
*
|
|
34
|
+
* @param text The description; `undefined`/`null` count as missing.
|
|
35
|
+
* @returns One entry per broken rule, keyed `formDescription`; empty when it passes.
|
|
36
|
+
*/
|
|
37
|
+
export declare function validateFormDescription(text: string | null | undefined): {
|
|
38
|
+
key: string;
|
|
39
|
+
message: string;
|
|
40
|
+
}[];
|
|
6
41
|
export declare const DatabaseFormSchema: Joi.ObjectSchema<any>;
|
|
7
42
|
export declare function validateFormSlide(data: any): {
|
|
8
43
|
key: string;
|
|
@@ -18,8 +18,65 @@ export const FormSchema = Joi.object({
|
|
|
18
18
|
submissionHandle: FormSubmissionHandleSchema.required(),
|
|
19
19
|
formId: Joi.string().optional(),
|
|
20
20
|
formTitle: Joi.string().required(),
|
|
21
|
+
// Shape only. Whether the description is good enough to save is the builder's
|
|
22
|
+
// rule (`validateFormDescription`), so stored forms and AI drafts that predate it
|
|
23
|
+
// stay valid here.
|
|
24
|
+
formDescription: Joi.string().allow('').optional(),
|
|
25
|
+
formClassifications: Joi.array().items(Joi.string()).optional(),
|
|
21
26
|
systemDefault: Joi.boolean().optional(),
|
|
22
27
|
});
|
|
28
|
+
/**
|
|
29
|
+
* Fewest words a form description may have — one full sentence — see
|
|
30
|
+
* `validateFormDescription`.
|
|
31
|
+
*/
|
|
32
|
+
export const FORM_DESCRIPTION_MIN_WORDS = 10;
|
|
33
|
+
/** Most paragraphs a form description may have — see `validateFormDescription`. */
|
|
34
|
+
export const FORM_DESCRIPTION_MAX_PARAGRAPHS = 2;
|
|
35
|
+
/**
|
|
36
|
+
* Counts the words and paragraphs of a form description. Paragraphs are separated
|
|
37
|
+
* by a blank line (whitespace-only lines count as blank); a single line break stays
|
|
38
|
+
* inside its paragraph.
|
|
39
|
+
*
|
|
40
|
+
* @param text The description; `undefined`/`null` count as empty.
|
|
41
|
+
* @returns The counts — both `0` for blank text.
|
|
42
|
+
*/
|
|
43
|
+
export function measureFormDescription(text) {
|
|
44
|
+
const normalised = (text ?? '').replace(/\r\n?/g, '\n').trim();
|
|
45
|
+
if (!normalised)
|
|
46
|
+
return { words: 0, paragraphs: 0 };
|
|
47
|
+
return {
|
|
48
|
+
words: normalised.split(/\s+/).filter(Boolean).length,
|
|
49
|
+
paragraphs: normalised.split(/\n[^\S\n]*\n\s*/).filter(p => p.trim().length > 0).length,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The rule a form description must pass before the builder saves the form: present,
|
|
54
|
+
* at least `FORM_DESCRIPTION_MIN_WORDS` words, at most `FORM_DESCRIPTION_MAX_PARAGRAPHS`
|
|
55
|
+
* paragraphs.
|
|
56
|
+
*
|
|
57
|
+
* @param text The description; `undefined`/`null` count as missing.
|
|
58
|
+
* @returns One entry per broken rule, keyed `formDescription`; empty when it passes.
|
|
59
|
+
*/
|
|
60
|
+
export function validateFormDescription(text) {
|
|
61
|
+
const { words, paragraphs } = measureFormDescription(text);
|
|
62
|
+
if (words === 0) {
|
|
63
|
+
return [{ key: 'formDescription', message: 'A form description is required' }];
|
|
64
|
+
}
|
|
65
|
+
const errors = [];
|
|
66
|
+
if (words < FORM_DESCRIPTION_MIN_WORDS) {
|
|
67
|
+
errors.push({
|
|
68
|
+
key: 'formDescription',
|
|
69
|
+
message: `The form description needs at least ${FORM_DESCRIPTION_MIN_WORDS} words (it has ${words})`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (paragraphs > FORM_DESCRIPTION_MAX_PARAGRAPHS) {
|
|
73
|
+
errors.push({
|
|
74
|
+
key: 'formDescription',
|
|
75
|
+
message: `The form description can have at most ${FORM_DESCRIPTION_MAX_PARAGRAPHS} paragraphs (it has ${paragraphs})`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return errors;
|
|
79
|
+
}
|
|
23
80
|
export const DatabaseFormSchema = Joi.object({
|
|
24
81
|
_id: Joi.string().required(),
|
|
25
82
|
systemDefault: Joi.boolean().required(),
|
package/dist/schemas/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { validateCalculatedFieldRules } from "./CalculatedFieldRulesSchema.js";
|
|
2
2
|
import { formColumnInputsSchema, validateFormColumnInputs, validateFormColumnInputsWithRequired } from "./FormInputSchema.js";
|
|
3
|
-
import { DatabaseFormSchema, FormSchema, validateApiDataFetchingConfiguration, validateForm, validateFormSlide } from "./FormSchema.js";
|
|
3
|
+
import { DatabaseFormSchema, FORM_DESCRIPTION_MAX_PARAGRAPHS, FORM_DESCRIPTION_MIN_WORDS, FormDescriptionMeasure, FormSchema, measureFormDescription, validateApiDataFetchingConfiguration, validateForm, validateFormDescription, validateFormSlide } from "./FormSchema.js";
|
|
4
4
|
import { MscoaInputConfigSchema, validateMscoaInputConfig } from "./MscoaConfigSchema.js";
|
|
5
|
-
export { FormSchema, DatabaseFormSchema, formColumnInputsSchema, validateCalculatedFieldRules, validateFormColumnInputs, validateFormSlide, validateFormColumnInputsWithRequired, validateForm, validateApiDataFetchingConfiguration, MscoaInputConfigSchema, validateMscoaInputConfig };
|
|
5
|
+
export { FormSchema, DatabaseFormSchema, formColumnInputsSchema, validateCalculatedFieldRules, validateFormColumnInputs, validateFormSlide, validateFormColumnInputsWithRequired, validateForm, validateApiDataFetchingConfiguration, MscoaInputConfigSchema, validateMscoaInputConfig, FORM_DESCRIPTION_MIN_WORDS, FORM_DESCRIPTION_MAX_PARAGRAPHS, measureFormDescription, validateFormDescription };
|
|
6
|
+
export type { FormDescriptionMeasure };
|
package/dist/schemas/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateCalculatedFieldRules } from "./CalculatedFieldRulesSchema.js";
|
|
2
2
|
import { formColumnInputsSchema, validateFormColumnInputs, validateFormColumnInputsWithRequired } from "./FormInputSchema.js";
|
|
3
|
-
import { DatabaseFormSchema, FormSchema, validateApiDataFetchingConfiguration, validateForm, validateFormSlide } from "./FormSchema.js";
|
|
3
|
+
import { DatabaseFormSchema, FORM_DESCRIPTION_MAX_PARAGRAPHS, FORM_DESCRIPTION_MIN_WORDS, FormSchema, measureFormDescription, validateApiDataFetchingConfiguration, validateForm, validateFormDescription, validateFormSlide } from "./FormSchema.js";
|
|
4
4
|
import { MscoaInputConfigSchema, validateMscoaInputConfig } from "./MscoaConfigSchema.js";
|
|
5
|
-
export { FormSchema, DatabaseFormSchema, formColumnInputsSchema, validateCalculatedFieldRules, validateFormColumnInputs, validateFormSlide, validateFormColumnInputsWithRequired, validateForm, validateApiDataFetchingConfiguration, MscoaInputConfigSchema, validateMscoaInputConfig };
|
|
5
|
+
export { FormSchema, DatabaseFormSchema, formColumnInputsSchema, validateCalculatedFieldRules, validateFormColumnInputs, validateFormSlide, validateFormColumnInputsWithRequired, validateForm, validateApiDataFetchingConfiguration, MscoaInputConfigSchema, validateMscoaInputConfig, FORM_DESCRIPTION_MIN_WORDS, FORM_DESCRIPTION_MAX_PARAGRAPHS, measureFormDescription, validateFormDescription };
|
|
@@ -54,7 +54,7 @@ type MemberValue<K extends AllFormInputPrimaryKeys> = K extends keyof FormColumn
|
|
|
54
54
|
* runtime state the form owns while it is open. These are excluded from
|
|
55
55
|
* generation schemas entirely and stitched in afterwards.
|
|
56
56
|
*/
|
|
57
|
-
export declare const SYSTEM_OWNED_INPUT_MEMBERS: readonly [AllFormInputPrimaryKeys.Id, AllFormInputPrimaryKeys.SectionId, AllFormInputPrimaryKeys.SystemDefault, AllFormInputPrimaryKeys.Status, AllFormInputPrimaryKeys.ValueUpdatedAt, AllFormInputPrimaryKeys.TemporaryHint, AllFormInputPrimaryKeys.FormIsOpen, AllFormInputPrimaryKeys.MultipleInputInEditId, AllFormInputPrimaryKeys.CanReload];
|
|
57
|
+
export declare const SYSTEM_OWNED_INPUT_MEMBERS: readonly [AllFormInputPrimaryKeys.Id, AllFormInputPrimaryKeys.SectionId, AllFormInputPrimaryKeys.SystemDefault, AllFormInputPrimaryKeys.Status, AllFormInputPrimaryKeys.ValueUpdatedAt, AllFormInputPrimaryKeys.TemporaryHint, AllFormInputPrimaryKeys.FormIsOpen, AllFormInputPrimaryKeys.MultipleInputInEditId, AllFormInputPrimaryKeys.CanReload, AllFormInputPrimaryKeys.OptionsSearch];
|
|
58
58
|
/**
|
|
59
59
|
* Members kept only so stored forms keep deserialising. They are excluded from
|
|
60
60
|
* generation entirely: a model must never author a property the codebase has
|
|
@@ -26,6 +26,7 @@ export const SYSTEM_OWNED_INPUT_MEMBERS = [
|
|
|
26
26
|
AllFormInputPrimaryKeys.FormIsOpen,
|
|
27
27
|
AllFormInputPrimaryKeys.MultipleInputInEditId,
|
|
28
28
|
AllFormInputPrimaryKeys.CanReload,
|
|
29
|
+
AllFormInputPrimaryKeys.OptionsSearch,
|
|
29
30
|
];
|
|
30
31
|
/**
|
|
31
32
|
* Members kept only so stored forms keep deserialising. They are excluded from
|