@finsys/core 1.1.0 → 1.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finsys/core",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Convert unified form configurations into Zod schemas, React Hook Form defaults, and SurveyJS JSON",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,18 +10,19 @@
10
10
  "bugs": {
11
11
  "url": "https://github.com/ExtraGalaxies/finsys-core/issues"
12
12
  },
13
- "main": "dist/index.js",
14
- "types": "dist/index.d.ts",
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
15
16
  "type": "module",
16
17
  "exports": {
17
18
  ".": {
18
- "import": {
19
- "types": "./dist/index.d.ts",
20
- "default": "./dist/index.js"
21
- }
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
22
  },
23
23
  "./schema": {
24
- "import": "./dist/schema/unified-form.schema.json"
24
+ "import": "./dist/schema/unified-form.schema.json",
25
+ "require": "./dist/schema/unified-form.schema.json"
25
26
  }
26
27
  },
27
28
  "files": [
@@ -30,8 +31,8 @@
30
31
  "LICENSE"
31
32
  ],
32
33
  "scripts": {
33
- "build": "tsc && cp src/schema/unified-form.schema.json dist/schema/unified-form.schema.json && rm -rf dist/data && cp -r src/data dist/data",
34
- "dev": "tsc --watch",
34
+ "build": "tsup",
35
+ "dev": "tsup --watch",
35
36
  "test": "vitest run",
36
37
  "lint": "tsc --noEmit",
37
38
  "prepublishOnly": "npm run build"
@@ -54,6 +55,7 @@
54
55
  "@types/node": "^25.0.10",
55
56
  "@types/semver": "^7.5.0",
56
57
  "survey-core": "^2.5.6",
58
+ "tsup": "^8.5.1",
57
59
  "typescript": "^5.4.0",
58
60
  "vitest": "^4.0.18"
59
61
  },
@@ -1,13 +0,0 @@
1
- import type { FieldData, Category } from "./survey-generator.js";
2
- import type { FormFieldTypeDefinitions } from "./form-field.js";
3
- import type { FormValidatorDefinitions } from "./form-field-validator.js";
4
- export declare const BASE_FIELD_SPECS: {
5
- schemaVersion: string;
6
- categories: Category[];
7
- fields: FieldData[];
8
- };
9
- export declare const FIELD_TYPE_DEFINITIONS: FormFieldTypeDefinitions;
10
- export declare const DEFAULT_VALIDATOR_DEFINITIONS: FormValidatorDefinitions;
11
- export declare function getBaseFieldSpecs(): FieldData[];
12
- export declare function getBaseCategories(): Category[];
13
- export declare function getBaseFieldNames(): string[];
package/dist/catalogs.js DELETED
@@ -1,35 +0,0 @@
1
- import FormField from "./form-field.js";
2
- import baseSpecsData from "./data/form-field-base-specs.json" with { type: "json" };
3
- import typeDefsData from "./data/form-field-types.json" with { type: "json" };
4
- import validatorDefsData from "./data/form-field-validators.json" with { type: "json" };
5
- export const BASE_FIELD_SPECS = baseSpecsData;
6
- export const FIELD_TYPE_DEFINITIONS = typeDefsData;
7
- export const DEFAULT_VALIDATOR_DEFINITIONS = {
8
- version: validatorDefsData.version,
9
- options: validatorDefsData.options,
10
- };
11
- export function getBaseFieldSpecs() {
12
- return BASE_FIELD_SPECS.fields;
13
- }
14
- export function getBaseCategories() {
15
- return BASE_FIELD_SPECS.categories;
16
- }
17
- let cachedFieldNames = null;
18
- export function getBaseFieldNames() {
19
- if (cachedFieldNames) {
20
- return cachedFieldNames;
21
- }
22
- const fields = BASE_FIELD_SPECS.fields;
23
- const names = [];
24
- for (const field of fields) {
25
- try {
26
- const formField = FormField.fromObject(field);
27
- names.push(...formField.getFieldNames());
28
- }
29
- catch {
30
- // Skip fields that fail to parse
31
- }
32
- }
33
- cachedFieldNames = [...new Set(names)];
34
- return cachedFieldNames;
35
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,207 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { generateRHFSchema } from "./rhf-generator.js";
3
- import { BASE_FIELD_SPECS, FIELD_TYPE_DEFINITIONS, DEFAULT_VALIDATOR_DEFINITIONS, getBaseFieldSpecs, getBaseCategories, getBaseFieldNames, } from "./catalogs.js";
4
- describe("BASE_FIELD_SPECS", () => {
5
- it("has schemaVersion, categories, and fields", () => {
6
- expect(BASE_FIELD_SPECS.schemaVersion).toBeDefined();
7
- expect(Array.isArray(BASE_FIELD_SPECS.categories)).toBe(true);
8
- expect(Array.isArray(BASE_FIELD_SPECS.fields)).toBe(true);
9
- expect(BASE_FIELD_SPECS.categories.length).toBeGreaterThan(0);
10
- expect(BASE_FIELD_SPECS.fields.length).toBeGreaterThan(0);
11
- });
12
- });
13
- describe("FIELD_TYPE_DEFINITIONS", () => {
14
- it("has version, types, and input_types", () => {
15
- expect(FIELD_TYPE_DEFINITIONS.version).toBeDefined();
16
- expect(Array.isArray(FIELD_TYPE_DEFINITIONS.types)).toBe(true);
17
- expect(Array.isArray(FIELD_TYPE_DEFINITIONS.input_types)).toBe(true);
18
- expect(FIELD_TYPE_DEFINITIONS.types.length).toBeGreaterThan(0);
19
- expect(FIELD_TYPE_DEFINITIONS.input_types.length).toBeGreaterThan(0);
20
- });
21
- });
22
- describe("DEFAULT_VALIDATOR_DEFINITIONS", () => {
23
- it("has version and options", () => {
24
- expect(DEFAULT_VALIDATOR_DEFINITIONS.version).toBeDefined();
25
- expect(Array.isArray(DEFAULT_VALIDATOR_DEFINITIONS.options)).toBe(true);
26
- expect(DEFAULT_VALIDATOR_DEFINITIONS.options.length).toBeGreaterThan(0);
27
- });
28
- });
29
- describe("getBaseFieldSpecs", () => {
30
- it("returns field array", () => {
31
- const fields = getBaseFieldSpecs();
32
- expect(Array.isArray(fields)).toBe(true);
33
- expect(fields.length).toBeGreaterThan(0);
34
- expect(fields[0].name).toBeDefined();
35
- expect(fields[0].type).toBeDefined();
36
- });
37
- });
38
- describe("getBaseCategories", () => {
39
- it("returns category array", () => {
40
- const categories = getBaseCategories();
41
- expect(Array.isArray(categories)).toBe(true);
42
- expect(categories.length).toBeGreaterThan(0);
43
- expect(categories[0].id).toBeDefined();
44
- expect(categories[0].name).toBeDefined();
45
- });
46
- });
47
- describe("getBaseFieldNames", () => {
48
- it("returns unique field names", () => {
49
- const names = getBaseFieldNames();
50
- expect(Array.isArray(names)).toBe(true);
51
- expect(names.length).toBeGreaterThan(0);
52
- // Should be unique
53
- expect(new Set(names).size).toBe(names.length);
54
- });
55
- });
56
- describe("Base Specs Zod Validation", () => {
57
- it("all field definitions should be valid for RHF schema generation", () => {
58
- const fields = BASE_FIELD_SPECS.fields;
59
- const categories = BASE_FIELD_SPECS.categories;
60
- const failedFields = [];
61
- fields.forEach((field) => {
62
- try {
63
- const config = {
64
- schemaVersion: "v2.0.0",
65
- displayName: "Test",
66
- categories: categories,
67
- fields: {
68
- [field.name]: field,
69
- },
70
- pages: [
71
- {
72
- id: "test-page",
73
- fields: [field.name],
74
- },
75
- ],
76
- };
77
- const { zodSchema, defaultValues } = generateRHFSchema(config);
78
- const result = zodSchema.safeParse(defaultValues);
79
- if (!result.success) {
80
- const hasRequirementError = result.error.issues.some((i) => i.message === "This field is required" || i.code === "too_small");
81
- const isRequired = field.isRequired !== false && field.required !== false;
82
- if (!(isRequired && hasRequirementError && !field.defaultValue)) {
83
- failedFields.push({
84
- name: field.name,
85
- error: `Validation failed: ${JSON.stringify(result.error.issues)}`,
86
- });
87
- }
88
- }
89
- }
90
- catch (error) {
91
- failedFields.push({
92
- name: field.name,
93
- error: `Exception: ${error.message}`,
94
- });
95
- }
96
- });
97
- if (failedFields.length > 0) {
98
- const errorMsg = failedFields.map((f) => `[${f.name}]: ${f.error}`).join("\n");
99
- expect.unreachable(`Found ${failedFields.length} invalid field definitions:\n${errorMsg.substring(0, 2000)}`);
100
- }
101
- });
102
- });
103
- describe("Field Types Zod Validation", () => {
104
- it("all supported type combinations should be valid for RHF schema generation", () => {
105
- const types = FIELD_TYPE_DEFINITIONS.types;
106
- const inputTypes = FIELD_TYPE_DEFINITIONS.input_types;
107
- const failedCombinations = [];
108
- for (const typeObj of types) {
109
- const baseType = typeObj.name;
110
- const targetInputTypes = baseType === "text" ? inputTypes : [{ name: undefined }];
111
- for (const inputTypeObj of targetInputTypes) {
112
- const inputType = inputTypeObj.name;
113
- try {
114
- const field = {
115
- name: "testField",
116
- displayName: "Test Field",
117
- category: "1",
118
- type: baseType,
119
- };
120
- if (inputType)
121
- field.inputType = inputType;
122
- const config = {
123
- schemaVersion: "v2.0.0",
124
- displayName: "Test",
125
- categories: [{ id: "1", name: "Test" }],
126
- fields: { [field.name]: field },
127
- pages: [{ id: "test-page", fields: [field.name] }],
128
- };
129
- const { zodSchema, defaultValues } = generateRHFSchema(config);
130
- const result = zodSchema.safeParse(defaultValues);
131
- if (!result.success) {
132
- const errors = result.error.issues.filter((i) => i.message !== "This field is required" && i.code !== "too_small");
133
- if (errors.length > 0) {
134
- failedCombinations.push({
135
- type: baseType,
136
- inputType,
137
- error: `Validation failed: ${JSON.stringify(errors)}`,
138
- });
139
- }
140
- }
141
- }
142
- catch (error) {
143
- failedCombinations.push({
144
- type: baseType,
145
- inputType,
146
- error: `Exception: ${error.message}`,
147
- });
148
- }
149
- }
150
- }
151
- if (failedCombinations.length > 0) {
152
- const errorMsg = failedCombinations
153
- .map((c) => `[${c.type}${c.inputType ? "/" + c.inputType : ""}]: ${c.error}`)
154
- .join("\n");
155
- expect.unreachable(`Found ${failedCombinations.length} invalid type combinations:\n${errorMsg}`);
156
- }
157
- });
158
- });
159
- describe("Field Validators Zod Validation", () => {
160
- it("all shared validator definitions should be valid for RHF schema generation", () => {
161
- const options = DEFAULT_VALIDATOR_DEFINITIONS.options;
162
- const failedValidators = [];
163
- options.forEach((option) => {
164
- try {
165
- const field = {
166
- name: "testField",
167
- displayName: "Test Field",
168
- category: "1",
169
- type: "text",
170
- validators: option.validators || [],
171
- };
172
- if (option.validators?.some((v) => v.type === "numeric")) {
173
- field.type = "number";
174
- field.inputType = "number";
175
- }
176
- const config = {
177
- schemaVersion: "v2.0.0",
178
- displayName: "Test",
179
- categories: [{ id: "1", name: "Test" }],
180
- fields: { [field.name]: field },
181
- pages: [{ id: "test-page", fields: [field.name] }],
182
- };
183
- const { zodSchema, defaultValues } = generateRHFSchema(config);
184
- const result = zodSchema.safeParse(defaultValues);
185
- if (!result.success) {
186
- const errors = result.error.issues.filter((i) => i.message !== "This field is required");
187
- if (errors.length > 0) {
188
- failedValidators.push({
189
- name: option.displayName,
190
- error: `Validation failed: ${JSON.stringify(errors)}`,
191
- });
192
- }
193
- }
194
- }
195
- catch (error) {
196
- failedValidators.push({
197
- name: option.displayName,
198
- error: `Exception: ${error.message}`,
199
- });
200
- }
201
- });
202
- if (failedValidators.length > 0) {
203
- const errorMsg = failedValidators.map((f) => `[${f.name}]: ${f.error}`).join("\n");
204
- expect.unreachable(`Found ${failedValidators.length} invalid validator definitions:\n${errorMsg.substring(0, 2000)}`);
205
- }
206
- });
207
- });
@@ -1,12 +0,0 @@
1
- export declare class FormFieldCategory {
2
- private _id;
3
- private _name;
4
- constructor(id: string | number, name: string);
5
- get id(): string;
6
- get name(): string;
7
- set name(value: string);
8
- toJSON(): {
9
- id: string;
10
- name: string;
11
- };
12
- }
@@ -1,21 +0,0 @@
1
- export class FormFieldCategory {
2
- constructor(id, name) {
3
- this._id = String(id);
4
- this._name = name;
5
- }
6
- get id() {
7
- return this._id;
8
- }
9
- get name() {
10
- return this._name;
11
- }
12
- set name(value) {
13
- this._name = value;
14
- }
15
- toJSON() {
16
- return {
17
- id: this._id,
18
- name: this._name,
19
- };
20
- }
21
- }
@@ -1,18 +0,0 @@
1
- import type { Validator } from "./survey-generator.js";
2
- import type { EditorValidator } from "./form-field.js";
3
- export interface FormValidatorDefinitions {
4
- options: EditorValidator[];
5
- version: number;
6
- }
7
- export declare class FormFieldValidator implements EditorValidator {
8
- id: number;
9
- displayName: string;
10
- class: string;
11
- description: string;
12
- isRequired: boolean;
13
- validators: Validator[];
14
- constructor(validatorData: EditorValidator);
15
- validate(value: any): boolean;
16
- private validateNumeric;
17
- private validateText;
18
- }
@@ -1,41 +0,0 @@
1
- export class FormFieldValidator {
2
- constructor(validatorData) {
3
- this.id = validatorData.id;
4
- this.displayName = validatorData.displayName;
5
- this.class = validatorData.class;
6
- this.description = validatorData.description;
7
- this.isRequired = validatorData.isRequired;
8
- this.validators = validatorData.validators;
9
- }
10
- validate(value) {
11
- for (const validator of this.validators) {
12
- switch (validator.type) {
13
- case 'numeric':
14
- if (!this.validateNumeric(value, validator.minValue, validator.maxValue)) {
15
- return false;
16
- }
17
- break;
18
- case 'text':
19
- if (!this.validateText(value, validator.minLength, validator.maxLength)) {
20
- return false;
21
- }
22
- break;
23
- }
24
- }
25
- return true;
26
- }
27
- validateNumeric(value, min, max) {
28
- if (min !== undefined && value < min)
29
- return false;
30
- if (max !== undefined && value > max)
31
- return false;
32
- return true;
33
- }
34
- validateText(value, minLength, maxLength) {
35
- if (minLength !== undefined && value.length < minLength)
36
- return false;
37
- if (maxLength !== undefined && value.length > maxLength)
38
- return false;
39
- return true;
40
- }
41
- }
@@ -1,81 +0,0 @@
1
- import type { FieldData, Choice, Validator } from "./survey-generator.js";
2
- export declare enum FieldType {
3
- FILE = "file",
4
- TEXT = "text",
5
- DROPDOWN = "dropdown",
6
- BOOLEAN = "boolean",
7
- CHECKBOX = "checkbox",
8
- RADIOGROUP = "radiogroup",
9
- SLIDER = "slider",
10
- HTML = "html",
11
- TAGBOX = "tagbox",
12
- NUMBER = "number",
13
- EMAIL = "email",
14
- COMMENT = "comment",
15
- RANGE = "range",
16
- UNKNOWN = "unknown"
17
- }
18
- export interface FormFieldType {
19
- name: string;
20
- displayName: string;
21
- }
22
- export interface FormFieldInputType {
23
- name: string;
24
- displayName: string;
25
- }
26
- export interface FormFieldTypeDefinitions {
27
- version: number;
28
- types: FormFieldType[];
29
- input_types: FormFieldInputType[];
30
- }
31
- export interface DropdownOption {
32
- id: number;
33
- name: string;
34
- displayName: string;
35
- choices: Choice[];
36
- }
37
- export interface EditorValidator {
38
- id: number;
39
- displayName: string;
40
- class: string;
41
- description: string;
42
- isRequired: boolean;
43
- validators: Validator[];
44
- }
45
- export default abstract class FormField {
46
- fieldObject: FieldData;
47
- constructor(name: string, displayName: string, type: string, category: string);
48
- static fromObject(fieldObject: FieldData): FormField;
49
- abstract getFieldNames(): string[];
50
- protected cleanObject(obj: any): any;
51
- toJSON(): any;
52
- get displayName(): string;
53
- set displayName(newDisplayName: string);
54
- get name(): string;
55
- get type(): FieldType;
56
- get inputType(): string;
57
- get categoryId(): string;
58
- set categoryId(categoryId: string);
59
- get defaultValue(): any;
60
- set defaultValue(value: any);
61
- get placeholder(): string | undefined;
62
- get validators(): Validator[] | undefined;
63
- get choices(): Choice[];
64
- set choices(choices: Choice[]);
65
- get visible(): boolean;
66
- get visibleIf(): string | undefined;
67
- get isRequired(): boolean;
68
- get startWithNewLine(): boolean;
69
- get requiredForEvaluation(): boolean;
70
- get maxLength(): number | undefined;
71
- get min(): number | undefined;
72
- get max(): number | undefined;
73
- }
74
- export declare class BasicFormField extends FormField {
75
- constructor(name: string, displayName: string, type: string, category: string);
76
- getFieldNames(): string[];
77
- }
78
- export declare class FileFormField extends FormField {
79
- constructor(name: string, displayName: string, type: string, category: string, ihs_column_names: string[]);
80
- getFieldNames(): string[];
81
- }
@@ -1,197 +0,0 @@
1
- export var FieldType;
2
- (function (FieldType) {
3
- FieldType["FILE"] = "file";
4
- FieldType["TEXT"] = "text";
5
- FieldType["DROPDOWN"] = "dropdown";
6
- FieldType["BOOLEAN"] = "boolean";
7
- FieldType["CHECKBOX"] = "checkbox";
8
- FieldType["RADIOGROUP"] = "radiogroup";
9
- FieldType["SLIDER"] = "slider";
10
- FieldType["HTML"] = "html";
11
- FieldType["TAGBOX"] = "tagbox";
12
- FieldType["NUMBER"] = "number";
13
- FieldType["EMAIL"] = "email";
14
- FieldType["COMMENT"] = "comment";
15
- FieldType["RANGE"] = "range";
16
- FieldType["UNKNOWN"] = "unknown";
17
- })(FieldType || (FieldType = {}));
18
- function toFieldType(value) {
19
- const typeMap = {
20
- [FieldType.FILE]: FieldType.FILE,
21
- [FieldType.TEXT]: FieldType.TEXT,
22
- [FieldType.DROPDOWN]: FieldType.DROPDOWN,
23
- [FieldType.BOOLEAN]: FieldType.BOOLEAN,
24
- [FieldType.CHECKBOX]: FieldType.CHECKBOX,
25
- [FieldType.RADIOGROUP]: FieldType.RADIOGROUP,
26
- [FieldType.SLIDER]: FieldType.SLIDER,
27
- [FieldType.HTML]: FieldType.HTML,
28
- [FieldType.TAGBOX]: FieldType.TAGBOX,
29
- [FieldType.NUMBER]: FieldType.NUMBER,
30
- [FieldType.EMAIL]: FieldType.EMAIL,
31
- [FieldType.COMMENT]: FieldType.COMMENT,
32
- [FieldType.RANGE]: FieldType.RANGE,
33
- };
34
- return typeMap[value] || FieldType.UNKNOWN;
35
- }
36
- export default class FormField {
37
- constructor(name, displayName, type, category) {
38
- this.fieldObject = {
39
- name,
40
- displayName,
41
- type,
42
- category,
43
- };
44
- }
45
- static fromObject(fieldObject) {
46
- if (!fieldObject.name) {
47
- throw new Error('Field name is required');
48
- }
49
- if (!fieldObject.displayName || !fieldObject.category) {
50
- throw new Error(`Invalid field object: '${fieldObject.name}' field missing displayName or category`);
51
- }
52
- const identifiedType = toFieldType(fieldObject.type);
53
- if (identifiedType === FieldType.UNKNOWN) {
54
- throw new Error(`'${fieldObject.name}' field has unsupported or missing type: ${fieldObject.type}`);
55
- }
56
- if (fieldObject.choices &&
57
- !['dropdown', 'checkbox', 'radiogroup', 'tagbox'].includes(fieldObject.type)) {
58
- // Logic remained as is
59
- }
60
- if (fieldObject.type === 'dropdown' && !fieldObject.choices) {
61
- throw new Error(`Invalid field object: '${fieldObject.name}' field has type dropdown, but does not have choices`);
62
- }
63
- let field;
64
- if (fieldObject.type === 'file') {
65
- field = new FileFormField(fieldObject.name, fieldObject.displayName || fieldObject.name, fieldObject.type, String(fieldObject.category), fieldObject.ihs_column_names || []);
66
- }
67
- else {
68
- field = new BasicFormField(fieldObject.name, fieldObject.displayName || fieldObject.name, fieldObject.type || 'text', String(fieldObject.category));
69
- }
70
- field.fieldObject = { ...fieldObject };
71
- field.fieldObject.category = String(field.fieldObject.category);
72
- // Remove legacy categoryId property
73
- delete field.fieldObject.categoryId;
74
- return field;
75
- }
76
- cleanObject(obj) {
77
- if (obj === null || obj === undefined)
78
- return obj;
79
- let target = obj;
80
- if (typeof obj.toJSON === 'function' && obj !== this) {
81
- target = obj.toJSON();
82
- }
83
- if (Array.isArray(target)) {
84
- return target.map((v) => (typeof v === 'object' ? this.cleanObject(v) : v));
85
- }
86
- if (typeof target !== 'object')
87
- return target;
88
- const cleaned = {};
89
- Object.keys(target).forEach((key) => {
90
- const value = target[key];
91
- if (value !== null && value !== undefined && value !== '') {
92
- if (typeof value === 'object') {
93
- cleaned[key] = this.cleanObject(value);
94
- }
95
- else {
96
- cleaned[key] = value;
97
- }
98
- }
99
- });
100
- return cleaned;
101
- }
102
- toJSON() {
103
- return this.cleanObject({ ...this.fieldObject });
104
- }
105
- get displayName() {
106
- return this.fieldObject.displayName || this.fieldObject.name || '';
107
- }
108
- set displayName(newDisplayName) {
109
- this.fieldObject.displayName = newDisplayName;
110
- }
111
- get name() {
112
- return this.fieldObject.name || '';
113
- }
114
- get type() {
115
- return toFieldType(this.fieldObject.type);
116
- }
117
- get inputType() {
118
- return this.fieldObject.inputType ?? '';
119
- }
120
- get categoryId() {
121
- return String(this.fieldObject.category || '');
122
- }
123
- set categoryId(categoryId) {
124
- this.fieldObject.category = categoryId;
125
- }
126
- get defaultValue() {
127
- return this.fieldObject.defaultValue;
128
- }
129
- set defaultValue(value) {
130
- this.fieldObject.defaultValue = value;
131
- }
132
- get placeholder() {
133
- return this.fieldObject.placeholder;
134
- }
135
- get validators() {
136
- return this.fieldObject.validators;
137
- }
138
- get choices() {
139
- return this.fieldObject.choices ?? [];
140
- }
141
- set choices(choices) {
142
- this.fieldObject.choices = choices;
143
- }
144
- get visible() {
145
- return this.fieldObject.visible ?? true;
146
- }
147
- get visibleIf() {
148
- return this.fieldObject.visibleIf;
149
- }
150
- get isRequired() {
151
- return this.fieldObject.required ?? this.fieldObject.isRequired ?? true;
152
- }
153
- get startWithNewLine() {
154
- return this.fieldObject.startWithNewLine ?? true;
155
- }
156
- get requiredForEvaluation() {
157
- return this.fieldObject.requiredForEvaluation ?? true;
158
- }
159
- get maxLength() {
160
- return typeof this.fieldObject.maxLength === 'string'
161
- ? Number.parseInt(this.fieldObject.maxLength)
162
- : this.fieldObject.maxLength;
163
- }
164
- get min() {
165
- return typeof this.fieldObject.min === 'string'
166
- ? Number.parseFloat(this.fieldObject.min)
167
- : this.fieldObject.min;
168
- }
169
- get max() {
170
- return typeof this.fieldObject.max === 'string'
171
- ? Number.parseFloat(this.fieldObject.max)
172
- : this.fieldObject.max;
173
- }
174
- }
175
- export class BasicFormField extends FormField {
176
- constructor(name, displayName, type, category) {
177
- super(name, displayName, type, category);
178
- }
179
- getFieldNames() {
180
- if (this.fieldObject.requiredForEvaluation === false) {
181
- return [];
182
- }
183
- return [this.fieldObject.name];
184
- }
185
- }
186
- export class FileFormField extends FormField {
187
- constructor(name, displayName, type, category, ihs_column_names) {
188
- super(name, displayName, type, category);
189
- this.fieldObject.ihs_column_names = ihs_column_names;
190
- }
191
- getFieldNames() {
192
- if (this.fieldObject.requiredForEvaluation === false) {
193
- return [];
194
- }
195
- return this.fieldObject.ihs_column_names || [];
196
- }
197
- }