@researchdatabox/sails-ng-common 0.0.1-beta.8936
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/README.md +5 -0
- package/dist/src/config/base-field-component.model.d.ts +26 -0
- package/dist/src/config/base-field-component.model.js +29 -0
- package/dist/src/config/base-field-component.outline.d.ts +100 -0
- package/dist/src/config/base-field-component.outline.js +3 -0
- package/dist/src/config/component/accordion.model.d.ts +103 -0
- package/dist/src/config/component/accordion.model.js +127 -0
- package/dist/src/config/component/accordion.outline.d.ts +150 -0
- package/dist/src/config/component/accordion.outline.js +13 -0
- package/dist/src/config/component/action-row-layout.model.d.ts +28 -0
- package/dist/src/config/component/action-row-layout.model.js +35 -0
- package/dist/src/config/component/action-row-layout.outline.d.ts +36 -0
- package/dist/src/config/component/action-row-layout.outline.js +6 -0
- package/dist/src/config/component/cancel-button.model.d.ts +46 -0
- package/dist/src/config/component/cancel-button.model.js +56 -0
- package/dist/src/config/component/cancel-button.outline.d.ts +69 -0
- package/dist/src/config/component/cancel-button.outline.js +6 -0
- package/dist/src/config/component/checkbox-input.model.d.ts +65 -0
- package/dist/src/config/component/checkbox-input.model.js +78 -0
- package/dist/src/config/component/checkbox-input.outline.d.ts +85 -0
- package/dist/src/config/component/checkbox-input.outline.js +8 -0
- package/dist/src/config/component/checkbox-tree.model.d.ts +66 -0
- package/dist/src/config/component/checkbox-tree.model.js +79 -0
- package/dist/src/config/component/checkbox-tree.outline.d.ts +96 -0
- package/dist/src/config/component/checkbox-tree.outline.js +8 -0
- package/dist/src/config/component/content.model.d.ts +45 -0
- package/dist/src/config/component/content.model.js +55 -0
- package/dist/src/config/component/content.outline.d.ts +64 -0
- package/dist/src/config/component/content.outline.js +6 -0
- package/dist/src/config/component/data-location.model.d.ts +82 -0
- package/dist/src/config/component/data-location.model.js +94 -0
- package/dist/src/config/component/data-location.outline.d.ts +117 -0
- package/dist/src/config/component/data-location.outline.js +6 -0
- package/dist/src/config/component/date-input.model.d.ts +66 -0
- package/dist/src/config/component/date-input.model.js +79 -0
- package/dist/src/config/component/date-input.outline.d.ts +81 -0
- package/dist/src/config/component/date-input.outline.js +8 -0
- package/dist/src/config/component/default-layout.model.d.ts +22 -0
- package/dist/src/config/component/default-layout.model.js +30 -0
- package/dist/src/config/component/default-layout.outline.d.ts +29 -0
- package/dist/src/config/component/default-layout.outline.js +5 -0
- package/dist/src/config/component/delete-button.model.d.ts +46 -0
- package/dist/src/config/component/delete-button.model.js +48 -0
- package/dist/src/config/component/delete-button.outline.d.ts +55 -0
- package/dist/src/config/component/delete-button.outline.js +5 -0
- package/dist/src/config/component/dropdown-input.model.d.ts +64 -0
- package/dist/src/config/component/dropdown-input.model.js +77 -0
- package/dist/src/config/component/dropdown-input.outline.d.ts +84 -0
- package/dist/src/config/component/dropdown-input.outline.js +8 -0
- package/dist/src/config/component/file-upload.model.d.ts +67 -0
- package/dist/src/config/component/file-upload.model.js +81 -0
- package/dist/src/config/component/file-upload.outline.d.ts +93 -0
- package/dist/src/config/component/file-upload.outline.js +8 -0
- package/dist/src/config/component/group.model.d.ts +61 -0
- package/dist/src/config/component/group.model.js +75 -0
- package/dist/src/config/component/group.outline.d.ts +77 -0
- package/dist/src/config/component/group.outline.js +8 -0
- package/dist/src/config/component/inline-layout.model.d.ts +22 -0
- package/dist/src/config/component/inline-layout.model.js +29 -0
- package/dist/src/config/component/inline-layout.outline.d.ts +29 -0
- package/dist/src/config/component/inline-layout.outline.js +5 -0
- package/dist/src/config/component/map.model.d.ts +68 -0
- package/dist/src/config/component/map.model.js +85 -0
- package/dist/src/config/component/map.outline.d.ts +102 -0
- package/dist/src/config/component/map.outline.js +8 -0
- package/dist/src/config/component/pdf-list.model.d.ts +68 -0
- package/dist/src/config/component/pdf-list.model.js +71 -0
- package/dist/src/config/component/pdf-list.outline.d.ts +91 -0
- package/dist/src/config/component/pdf-list.outline.js +6 -0
- package/dist/src/config/component/publish-data-location-refresh.model.d.ts +38 -0
- package/dist/src/config/component/publish-data-location-refresh.model.js +51 -0
- package/dist/src/config/component/publish-data-location-refresh.outline.d.ts +47 -0
- package/dist/src/config/component/publish-data-location-refresh.outline.js +5 -0
- package/dist/src/config/component/publish-data-location-selector.model.d.ts +74 -0
- package/dist/src/config/component/publish-data-location-selector.model.js +100 -0
- package/dist/src/config/component/publish-data-location-selector.outline.d.ts +99 -0
- package/dist/src/config/component/publish-data-location-selector.outline.js +6 -0
- package/dist/src/config/component/question-tree.helper.d.ts +61 -0
- package/dist/src/config/component/question-tree.helper.js +298 -0
- package/dist/src/config/component/question-tree.model.d.ts +64 -0
- package/dist/src/config/component/question-tree.model.js +80 -0
- package/dist/src/config/component/question-tree.outline.d.ts +305 -0
- package/dist/src/config/component/question-tree.outline.js +9 -0
- package/dist/src/config/component/radio-input.model.d.ts +63 -0
- package/dist/src/config/component/radio-input.model.js +76 -0
- package/dist/src/config/component/radio-input.outline.d.ts +83 -0
- package/dist/src/config/component/radio-input.outline.js +8 -0
- package/dist/src/config/component/record-metadata-retriever.model.d.ts +41 -0
- package/dist/src/config/component/record-metadata-retriever.model.js +57 -0
- package/dist/src/config/component/record-metadata-retriever.outline.d.ts +47 -0
- package/dist/src/config/component/record-metadata-retriever.outline.js +5 -0
- package/dist/src/config/component/record-selector.model.d.ts +60 -0
- package/dist/src/config/component/record-selector.model.js +60 -0
- package/dist/src/config/component/record-selector.outline.d.ts +84 -0
- package/dist/src/config/component/record-selector.outline.js +6 -0
- package/dist/src/config/component/repeatable.model.d.ts +90 -0
- package/dist/src/config/component/repeatable.model.js +109 -0
- package/dist/src/config/component/repeatable.outline.d.ts +108 -0
- package/dist/src/config/component/repeatable.outline.js +10 -0
- package/dist/src/config/component/reusable.model.d.ts +42 -0
- package/dist/src/config/component/reusable.model.js +57 -0
- package/dist/src/config/component/reusable.outline.d.ts +49 -0
- package/dist/src/config/component/reusable.outline.js +6 -0
- package/dist/src/config/component/rich-text-editor.model.d.ts +65 -0
- package/dist/src/config/component/rich-text-editor.model.js +79 -0
- package/dist/src/config/component/rich-text-editor.outline.d.ts +86 -0
- package/dist/src/config/component/rich-text-editor.outline.js +8 -0
- package/dist/src/config/component/save-button.model.d.ts +45 -0
- package/dist/src/config/component/save-button.model.js +55 -0
- package/dist/src/config/component/save-button.outline.d.ts +65 -0
- package/dist/src/config/component/save-button.outline.js +6 -0
- package/dist/src/config/component/save-status.model.d.ts +42 -0
- package/dist/src/config/component/save-status.model.js +60 -0
- package/dist/src/config/component/save-status.outline.d.ts +52 -0
- package/dist/src/config/component/save-status.outline.js +6 -0
- package/dist/src/config/component/simple-input.model.d.ts +62 -0
- package/dist/src/config/component/simple-input.model.js +75 -0
- package/dist/src/config/component/simple-input.outline.d.ts +80 -0
- package/dist/src/config/component/simple-input.outline.js +9 -0
- package/dist/src/config/component/tab-content.model.d.ts +63 -0
- package/dist/src/config/component/tab-content.model.js +77 -0
- package/dist/src/config/component/tab-content.outline.d.ts +92 -0
- package/dist/src/config/component/tab-content.outline.js +8 -0
- package/dist/src/config/component/tab-nav-button.model.d.ts +45 -0
- package/dist/src/config/component/tab-nav-button.model.js +55 -0
- package/dist/src/config/component/tab-nav-button.outline.d.ts +64 -0
- package/dist/src/config/component/tab-nav-button.outline.js +6 -0
- package/dist/src/config/component/tab.model.d.ts +71 -0
- package/dist/src/config/component/tab.model.js +84 -0
- package/dist/src/config/component/tab.outline.d.ts +106 -0
- package/dist/src/config/component/tab.outline.js +9 -0
- package/dist/src/config/component/text-area.model.d.ts +63 -0
- package/dist/src/config/component/text-area.model.js +76 -0
- package/dist/src/config/component/text-area.outline.d.ts +81 -0
- package/dist/src/config/component/text-area.outline.js +8 -0
- package/dist/src/config/component/typeahead-input.model.d.ts +78 -0
- package/dist/src/config/component/typeahead-input.model.js +91 -0
- package/dist/src/config/component/typeahead-input.outline.d.ts +107 -0
- package/dist/src/config/component/typeahead-input.outline.js +8 -0
- package/dist/src/config/component/validation-summary.model.d.ts +42 -0
- package/dist/src/config/component/validation-summary.model.js +60 -0
- package/dist/src/config/component/validation-summary.outline.d.ts +57 -0
- package/dist/src/config/component/validation-summary.outline.js +6 -0
- package/dist/src/config/dictionary.model.d.ts +624 -0
- package/dist/src/config/dictionary.model.js +175 -0
- package/dist/src/config/dictionary.outline.d.ts +94 -0
- package/dist/src/config/dictionary.outline.js +3 -0
- package/dist/src/config/field-component.model.d.ts +7 -0
- package/dist/src/config/field-component.model.js +11 -0
- package/dist/src/config/field-component.outline.d.ts +20 -0
- package/dist/src/config/field-component.outline.js +3 -0
- package/dist/src/config/field-layout.model.d.ts +19 -0
- package/dist/src/config/field-layout.model.js +23 -0
- package/dist/src/config/field-layout.outline.d.ts +42 -0
- package/dist/src/config/field-layout.outline.js +3 -0
- package/dist/src/config/field-model.model.d.ts +22 -0
- package/dist/src/config/field-model.model.js +25 -0
- package/dist/src/config/field-model.outline.d.ts +63 -0
- package/dist/src/config/field-model.outline.js +3 -0
- package/dist/src/config/field.model.d.ts +12 -0
- package/dist/src/config/field.model.js +12 -0
- package/dist/src/config/field.outline.d.ts +19 -0
- package/dist/src/config/field.outline.js +3 -0
- package/dist/src/config/form-behaviour.outline.d.ts +128 -0
- package/dist/src/config/form-behaviour.outline.js +40 -0
- package/dist/src/config/form-component.model.d.ts +38 -0
- package/dist/src/config/form-component.model.js +36 -0
- package/dist/src/config/form-component.outline.d.ts +257 -0
- package/dist/src/config/form-component.outline.js +24 -0
- package/dist/src/config/form-config.model.d.ts +33 -0
- package/dist/src/config/form-config.model.js +36 -0
- package/dist/src/config/form-config.outline.d.ts +109 -0
- package/dist/src/config/form-config.outline.js +3 -0
- package/dist/src/config/form-override.model.d.ts +116 -0
- package/dist/src/config/form-override.model.js +1209 -0
- package/dist/src/config/form-override.outline.d.ts +15 -0
- package/dist/src/config/form-override.outline.js +3 -0
- package/dist/src/config/form-types.model.d.ts +6 -0
- package/dist/src/config/form-types.model.js +23 -0
- package/dist/src/config/form-types.outline.d.ts +48 -0
- package/dist/src/config/form-types.outline.js +137 -0
- package/dist/src/config/helpers.d.ts +23 -0
- package/dist/src/config/helpers.js +105 -0
- package/dist/src/config/names/naming-helpers.d.ts +71 -0
- package/dist/src/config/names/naming-helpers.js +72 -0
- package/dist/src/config/names/query-helpers.d.ts +43 -0
- package/dist/src/config/names/query-helpers.js +64 -0
- package/dist/src/config/shared.outline.d.ts +54 -0
- package/dist/src/config/shared.outline.js +41 -0
- package/dist/src/config/visitor/base.model.d.ts +137 -0
- package/dist/src/config/visitor/base.model.js +323 -0
- package/dist/src/config/visitor/base.outline.d.ts +140 -0
- package/dist/src/config/visitor/base.outline.js +3 -0
- package/dist/src/config/visitor/common.model.d.ts +119 -0
- package/dist/src/config/visitor/common.model.js +421 -0
- package/dist/src/handlebars-helpers.d.ts +224 -0
- package/dist/src/handlebars-helpers.js +558 -0
- package/dist/src/index.d.ts +109 -0
- package/dist/src/index.js +136 -0
- package/dist/src/logger.interface.d.ts +14 -0
- package/dist/src/logger.interface.js +3 -0
- package/dist/src/record.model.d.ts +35 -0
- package/dist/src/record.model.js +21 -0
- package/dist/src/report.model.d.ts +21 -0
- package/dist/src/report.model.js +19 -0
- package/dist/src/status.model.d.ts +22 -0
- package/dist/src/status.model.js +28 -0
- package/dist/src/template.outline.d.ts +49 -0
- package/dist/src/template.outline.js +13 -0
- package/dist/src/translation-helpers.d.ts +10 -0
- package/dist/src/translation-helpers.js +30 -0
- package/dist/src/validation/form.model.d.ts +247 -0
- package/dist/src/validation/form.model.js +31 -0
- package/dist/src/validation/helpers.d.ts +14 -0
- package/dist/src/validation/helpers.js +68 -0
- package/dist/src/validation/validators-support.d.ts +41 -0
- package/dist/src/validation/validators-support.js +141 -0
- package/dist/src/validation/validators.d.ts +23 -0
- package/dist/src/validation/validators.js +427 -0
- package/package.json +95 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FormModesConfig } from "./shared.outline";
|
|
2
|
+
import { AllFormComponentDefinitionOutlines } from "./dictionary.outline";
|
|
3
|
+
import { VisitorComponentClassNamesType } from "./dictionary.model";
|
|
4
|
+
import { FormOverrideModesClassConfig } from "./form-component.outline";
|
|
5
|
+
/**
|
|
6
|
+
* The type that specifies the known transformations.
|
|
7
|
+
*/
|
|
8
|
+
export type KnownTransformsType = Partial<{
|
|
9
|
+
[key in VisitorComponentClassNamesType]: Partial<{
|
|
10
|
+
[key in VisitorComponentClassNamesType]: (source: any, formMode: FormModesConfig) => AllFormComponentDefinitionOutlines;
|
|
11
|
+
}>;
|
|
12
|
+
}>;
|
|
13
|
+
export type DefaultTransformsType = Partial<{
|
|
14
|
+
[key in VisitorComponentClassNamesType]: FormOverrideModesClassConfig;
|
|
15
|
+
}>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS1vdmVycmlkZS5vdXRsaW5lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NvbmZpZy9mb3JtLW92ZXJyaWRlLm91dGxpbmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FormValidatorDefinition } from "../validation/form.model";
|
|
2
|
+
/**
|
|
3
|
+
* Check if the item is a valid form validation definition.
|
|
4
|
+
* @param item The item to check.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isTypeFormValidatorDefinition(item: unknown): item is FormValidatorDefinition;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTypeFormValidatorDefinition = isTypeFormValidatorDefinition;
|
|
4
|
+
const helpers_1 = require("./helpers");
|
|
5
|
+
/**
|
|
6
|
+
* Check if the item is a valid form validation definition.
|
|
7
|
+
* @param item The item to check.
|
|
8
|
+
*/
|
|
9
|
+
function isTypeFormValidatorDefinition(item) {
|
|
10
|
+
if (item === undefined || item === null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const i = item;
|
|
14
|
+
const hasExpectedPropClass = 'class' in i && (0, helpers_1.guessType)(i.class) === 'string';
|
|
15
|
+
const hasExpectedPropClassValue = i.class?.toString()?.trim().length > 0;
|
|
16
|
+
const hasExpectedPropMessage = 'message' in i && (0, helpers_1.guessType)(i.message) === 'string';
|
|
17
|
+
const hasExpectedPropMessageValue = i.message?.toString()?.trim().length > 0;
|
|
18
|
+
const hasExpectedPropCreate = 'create' in i;
|
|
19
|
+
return hasExpectedPropClass && hasExpectedPropClassValue
|
|
20
|
+
&& hasExpectedPropMessage && hasExpectedPropMessageValue
|
|
21
|
+
&& hasExpectedPropCreate;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS10eXBlcy5tb2RlbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb25maWcvZm9ybS10eXBlcy5tb2RlbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQVFBLHNFQWlCQztBQXpCRCx1Q0FBb0M7QUFJcEM7OztHQUdHO0FBQ0gsU0FBZ0IsNkJBQTZCLENBQUMsSUFBYTtJQUN2RCxJQUFJLElBQUksS0FBSyxTQUFTLElBQUksSUFBSSxLQUFLLElBQUksRUFBRSxDQUFDO1FBQ3RDLE9BQU8sS0FBSyxDQUFDO0lBQ2pCLENBQUM7SUFDRCxNQUFNLENBQUMsR0FBRyxJQUErQixDQUFDO0lBRTFDLE1BQU0sb0JBQW9CLEdBQUcsT0FBTyxJQUFJLENBQUMsSUFBSSxJQUFBLG1CQUFTLEVBQUMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxLQUFLLFFBQVEsQ0FBQztJQUM3RSxNQUFNLHlCQUF5QixHQUFHLENBQUMsQ0FBQyxLQUFLLEVBQUUsUUFBUSxFQUFFLEVBQUUsSUFBSSxFQUFFLENBQUMsTUFBTSxHQUFHLENBQUMsQ0FBQztJQUV6RSxNQUFNLHNCQUFzQixHQUFHLFNBQVMsSUFBSSxDQUFDLElBQUksSUFBQSxtQkFBUyxFQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsS0FBSyxRQUFRLENBQUM7SUFDbkYsTUFBTSwyQkFBMkIsR0FBRyxDQUFDLENBQUMsT0FBTyxFQUFFLFFBQVEsRUFBRSxFQUFFLElBQUksRUFBRSxDQUFDLE1BQU0sR0FBRyxDQUFDLENBQUM7SUFFN0UsTUFBTSxxQkFBcUIsR0FBRyxRQUFRLElBQUksQ0FBQyxDQUFDO0lBRTVDLE9BQU8sb0JBQW9CLElBQUkseUJBQXlCO1dBQ2pELHNCQUFzQixJQUFJLDJCQUEyQjtXQUNyRCxxQkFBcUIsQ0FBQztBQUNqQyxDQUFDIn0=
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { FormComponentDefinitionFrame } from "./form-component.outline";
|
|
2
|
+
import { FormConfigFrame } from "./form-config.outline";
|
|
3
|
+
import { FieldDefinitionFrame } from "./field.outline";
|
|
4
|
+
import { ReusableFormComponentDefinitionFrame } from "./component/reusable.outline";
|
|
5
|
+
import { AvailableFormComponentDefinitionFrames } from "./dictionary.outline";
|
|
6
|
+
/**
|
|
7
|
+
* Check if the item is a field definition (it has at least 'class' and optional 'config' properties).
|
|
8
|
+
* @param item The item to check.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isTypeFieldDefinition(item: unknown): item is FieldDefinitionFrame;
|
|
11
|
+
/**
|
|
12
|
+
* Check if the item is a field definition of a particular type by comparing the class name
|
|
13
|
+
* (class name is the discriminator in the type union).
|
|
14
|
+
* @param item The item to check.
|
|
15
|
+
* @param name The class name to check.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isTypeFieldDefinitionName<T extends FieldDefinitionFrame>(item: unknown, name: string): item is T;
|
|
18
|
+
/**
|
|
19
|
+
* Check if the item is a form component definition (it has at least 'name' and 'component' properties).
|
|
20
|
+
* @param item The item to check.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isTypeFormComponentDefinition(item: unknown): item is FormComponentDefinitionFrame;
|
|
23
|
+
/**
|
|
24
|
+
* Check if the item is a form definition of a particular type by comparing the component class
|
|
25
|
+
* (component class name is the discriminator in the type union).
|
|
26
|
+
* @param item The item to check.
|
|
27
|
+
* @param name The class name to check.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isTypeFormComponentDefinitionName<T extends FormComponentDefinitionFrame>(item: unknown, name: string): item is T;
|
|
30
|
+
/**
|
|
31
|
+
* Check if the item has a componentDefinitions array property.
|
|
32
|
+
* @param item The item to check.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isTypeWithComponentDefinitions<T extends {
|
|
35
|
+
componentDefinitions: unknown[];
|
|
36
|
+
}>(item: unknown): item is T;
|
|
37
|
+
/**
|
|
38
|
+
* Check if the item is a FormConfig (it has a name and componentDefinitions array property).
|
|
39
|
+
* @param item The item to check.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isTypeFormConfig<T extends FormConfigFrame>(item: unknown): item is T;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a form component definition specifies to use a reusable form config.
|
|
44
|
+
* @param item The form component definition.
|
|
45
|
+
* @param reusableFormDefNames The names of the available reusable form definitions.
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
48
|
+
export declare function isTypeReusableComponent(item: AvailableFormComponentDefinitionFrames, reusableFormDefNames: string[]): item is ReusableFormComponentDefinitionFrame;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTypeFieldDefinition = isTypeFieldDefinition;
|
|
4
|
+
exports.isTypeFieldDefinitionName = isTypeFieldDefinitionName;
|
|
5
|
+
exports.isTypeFormComponentDefinition = isTypeFormComponentDefinition;
|
|
6
|
+
exports.isTypeFormComponentDefinitionName = isTypeFormComponentDefinitionName;
|
|
7
|
+
exports.isTypeWithComponentDefinitions = isTypeWithComponentDefinitions;
|
|
8
|
+
exports.isTypeFormConfig = isTypeFormConfig;
|
|
9
|
+
exports.isTypeReusableComponent = isTypeReusableComponent;
|
|
10
|
+
const helpers_1 = require("./helpers");
|
|
11
|
+
const reusable_outline_1 = require("./component/reusable.outline");
|
|
12
|
+
/*
|
|
13
|
+
* The functions starting with 'isType*' use typescript narrowing to check the value
|
|
14
|
+
* see: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Check if the item is a field definition (it has at least 'class' and optional 'config' properties).
|
|
18
|
+
* @param item The item to check.
|
|
19
|
+
*/
|
|
20
|
+
function isTypeFieldDefinition(item) {
|
|
21
|
+
if (item === undefined || item === null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const i = item;
|
|
25
|
+
const propClassGuessType = (0, helpers_1.guessType)(i?.class);
|
|
26
|
+
const hasExpectedPropClass = 'class' in i && propClassGuessType === 'string';
|
|
27
|
+
// 'config' can be null or object or not set
|
|
28
|
+
const propConfigGuessType = (0, helpers_1.guessType)(i.config);
|
|
29
|
+
const hasExpectedPropConfig = ('config' in i && ["object", "null"].includes(propConfigGuessType)) || i?.config === undefined;
|
|
30
|
+
const isFieldDefinition = hasExpectedPropClass && hasExpectedPropConfig;
|
|
31
|
+
if (!isFieldDefinition) {
|
|
32
|
+
console.log(`isTypeFieldDefinition propClassGuessType ${propClassGuessType} propConfigGuessType ${propConfigGuessType}`);
|
|
33
|
+
}
|
|
34
|
+
return isFieldDefinition;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if the item is a field definition of a particular type by comparing the class name
|
|
38
|
+
* (class name is the discriminator in the type union).
|
|
39
|
+
* @param item The item to check.
|
|
40
|
+
* @param name The class name to check.
|
|
41
|
+
*/
|
|
42
|
+
function isTypeFieldDefinitionName(item, name) {
|
|
43
|
+
if (item === undefined || item === null) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const hasExpectedFieldDefClass = isTypeFieldDefinition(item) && item?.class === name;
|
|
47
|
+
return hasExpectedFieldDefClass;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if the item is a form component definition (it has at least 'name' and 'component' properties).
|
|
51
|
+
* @param item The item to check.
|
|
52
|
+
*/
|
|
53
|
+
function isTypeFormComponentDefinition(item) {
|
|
54
|
+
if (item === undefined || item === null) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// use typescript narrowing to check the value
|
|
58
|
+
const i = item;
|
|
59
|
+
// only name and component are required
|
|
60
|
+
const hasName = 'name' in i;
|
|
61
|
+
const hasExpectedNameValue = ["null", "string"].includes((0, helpers_1.guessType)(i?.name));
|
|
62
|
+
const hasComponent = 'component' in i;
|
|
63
|
+
const isFormFieldComponent = isTypeFieldDefinition(i?.component);
|
|
64
|
+
return hasName && hasExpectedNameValue && hasComponent && isFormFieldComponent;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if the item is a form definition of a particular type by comparing the component class
|
|
68
|
+
* (component class name is the discriminator in the type union).
|
|
69
|
+
* @param item The item to check.
|
|
70
|
+
* @param name The class name to check.
|
|
71
|
+
*/
|
|
72
|
+
function isTypeFormComponentDefinitionName(item, name) {
|
|
73
|
+
if (item === undefined || item === null) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const hasExpectedFormDefClass = isTypeFormComponentDefinition(item) && item?.component?.class === name;
|
|
77
|
+
return hasExpectedFormDefClass;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if the item has a componentDefinitions array property.
|
|
81
|
+
* @param item The item to check.
|
|
82
|
+
*/
|
|
83
|
+
function isTypeWithComponentDefinitions(item) {
|
|
84
|
+
if (item === undefined || item === null) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// use typescript narrowing to check the value
|
|
88
|
+
const i = item;
|
|
89
|
+
const hasExpectedPropCompDefs = 'componentDefinitions' in i && (0, helpers_1.guessType)(i?.componentDefinitions) === 'array';
|
|
90
|
+
return hasExpectedPropCompDefs;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if the item is a FormConfig (it has a name and componentDefinitions array property).
|
|
94
|
+
* @param item The item to check.
|
|
95
|
+
*/
|
|
96
|
+
function isTypeFormConfig(item) {
|
|
97
|
+
if (item === undefined || item === null) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const i = item;
|
|
101
|
+
const hasExpectedPropName = 'name' in i && (0, helpers_1.guessType)(i.name) === 'string';
|
|
102
|
+
const hasExpectedPropCompDefs = isTypeWithComponentDefinitions(item);
|
|
103
|
+
return hasExpectedPropName && hasExpectedPropCompDefs;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if a form component definition specifies to use a reusable form config.
|
|
107
|
+
* @param item The form component definition.
|
|
108
|
+
* @param reusableFormDefNames The names of the available reusable form definitions.
|
|
109
|
+
* @protected
|
|
110
|
+
*/
|
|
111
|
+
function isTypeReusableComponent(item, reusableFormDefNames) {
|
|
112
|
+
const componentClassName = item?.component?.class ?? "";
|
|
113
|
+
const itemReusableFormName = item?.overrides?.reusableFormName ?? "";
|
|
114
|
+
const isReusableComponent = componentClassName === reusable_outline_1.ReusableComponentName;
|
|
115
|
+
const hasReusableFormName = itemReusableFormName && reusableFormDefNames.includes(itemReusableFormName);
|
|
116
|
+
if (!isReusableComponent && !hasReusableFormName) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (hasReusableFormName && isTypeFormComponentDefinitionName(item, reusable_outline_1.ReusableComponentName)) {
|
|
120
|
+
const overrides = item?.overrides ?? {};
|
|
121
|
+
const overrideKeys = Object.keys(overrides);
|
|
122
|
+
const reusableFormNameOnly = overrideKeys.includes('reusableFormName') && overrideKeys.length === 1;
|
|
123
|
+
const noKeys = overrideKeys.length === 0;
|
|
124
|
+
if (!reusableFormNameOnly && !noKeys) {
|
|
125
|
+
throw new Error("Invalid usage of reusable form config. " +
|
|
126
|
+
`Override for component name '${item.name}' class '${item.component.class}' must contain only 'reusableFormName', ` +
|
|
127
|
+
`it cannot be combined with other properties '${JSON.stringify(overrides)}'. ` +
|
|
128
|
+
`Change the form component name by setting the 'replaceName' property for the relevant componentDefinition. ` +
|
|
129
|
+
`The 'formModeClasses' can only be changed on subcomponents.`);
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
throw new Error("Invalid usage of reusable form config. " +
|
|
134
|
+
`Component class '${componentClassName}' must be '${reusable_outline_1.ReusableComponentName}' ` +
|
|
135
|
+
`and reusableFormName '${itemReusableFormName}' must be one of '${reusableFormDefNames.join(', ') || '(none available)'}'.`);
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybS10eXBlcy5vdXRsaW5lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2NvbmZpZy9mb3JtLXR5cGVzLm91dGxpbmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFpQkEsc0RBbUJDO0FBUUQsOERBUUM7QUFNRCxzRUFhQztBQVFELDhFQVFDO0FBTUQsd0VBWUM7QUFNRCw0Q0FXQztBQVFELDBEQWdDQztBQWxLRCx1Q0FBb0M7QUFJcEMsbUVBQXlHO0FBSXpHOzs7R0FHRztBQUVIOzs7R0FHRztBQUNILFNBQWdCLHFCQUFxQixDQUFDLElBQWE7SUFDL0MsSUFBSSxJQUFJLEtBQUssU0FBUyxJQUFJLElBQUksS0FBSyxJQUFJLEVBQUUsQ0FBQztRQUN0QyxPQUFPLEtBQUssQ0FBQztJQUNqQixDQUFDO0lBQ0QsTUFBTSxDQUFD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zdHLDZEQUE2RCxDQUFDLENBQUM7UUFDdkUsQ0FBQztRQUNELE9BQU8sSUFBSSxDQUFDO0lBQ2hCLENBQUM7SUFFRCxNQUFNLElBQUksS0FBSyxDQUFDLHlDQUF5QztRQUNyRCxvQkFBb0Isa0JBQWtCLGNBQWMsd0NBQXFCLElBQUk7UUFDN0UseUJBQXlCLG9CQUFvQixxQkFBcUIsb0JBQW9CLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxJQUFJLGtCQUFrQixJQUFJLENBQUMsQ0FBQztBQUNySSxDQUFDIn0=
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type GuessedType = "null" | "undefined" | "boolean" | "number" | "array" | "object" | "function" | "timestamp" | "string" | "unknown";
|
|
2
|
+
/**
|
|
3
|
+
* Guess the type of the value.
|
|
4
|
+
* @param value Guess the type of this value.
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
export declare function guessType(value: unknown): GuessedType;
|
|
8
|
+
/**
|
|
9
|
+
* Apply conventions to convert a value to a boolean.
|
|
10
|
+
* @param value A value to convert to boolean.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toBoolean(value: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Extract all properties of the type T that are of the type U.
|
|
15
|
+
*/
|
|
16
|
+
export type ExtractPropertyNamesOfType<T, U> = {
|
|
17
|
+
[K in keyof T]: T[K] extends U ? K : never;
|
|
18
|
+
}[keyof T];
|
|
19
|
+
/**
|
|
20
|
+
* Extract all properties from each of the types in the union type T, where the properties are of type U.
|
|
21
|
+
* This uses the distributive feature of conditional types (T extends T ? ...).
|
|
22
|
+
*/
|
|
23
|
+
export type ExtractPropertyNamesOfTypeFromTypeUnion<T, U> = T extends T ? ExtractPropertyNamesOfType<T, U> : never;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.guessType = guessType;
|
|
4
|
+
exports.toBoolean = toBoolean;
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const luxon_1 = require("luxon");
|
|
7
|
+
/**
|
|
8
|
+
* Guess the type of the value.
|
|
9
|
+
* @param value Guess the type of this value.
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
function guessType(value) {
|
|
13
|
+
if (value === null) {
|
|
14
|
+
return "null";
|
|
15
|
+
}
|
|
16
|
+
if (value === undefined) {
|
|
17
|
+
return "undefined";
|
|
18
|
+
}
|
|
19
|
+
if ((0, lodash_1.isBoolean)(value)) {
|
|
20
|
+
return "boolean";
|
|
21
|
+
}
|
|
22
|
+
if (Number.isFinite(value)) {
|
|
23
|
+
return "number";
|
|
24
|
+
}
|
|
25
|
+
if ((0, lodash_1.isArray)(value)) {
|
|
26
|
+
return "array";
|
|
27
|
+
}
|
|
28
|
+
if ((0, lodash_1.isPlainObject)(value)) {
|
|
29
|
+
return "object";
|
|
30
|
+
}
|
|
31
|
+
// Check for custom Object.
|
|
32
|
+
try {
|
|
33
|
+
const valueInfo = valueProtoInfo(value);
|
|
34
|
+
if (valueInfo.isObjectLike && valueInfo.isValueStringTagObject &&
|
|
35
|
+
valueInfo.isValueProtoCtorFunc && !valueInfo.isValueProtoCtorFuncObj) {
|
|
36
|
+
return "object";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.debug(`guessType custom object error with value '${value}': ${err}`);
|
|
41
|
+
}
|
|
42
|
+
if ((0, lodash_1.isFunction)(value)) {
|
|
43
|
+
return "function";
|
|
44
|
+
}
|
|
45
|
+
// check for date
|
|
46
|
+
const dateTimeFormats = [
|
|
47
|
+
luxon_1.DateTime.fromISO,
|
|
48
|
+
luxon_1.DateTime.fromRFC2822,
|
|
49
|
+
luxon_1.DateTime.fromHTTP,
|
|
50
|
+
];
|
|
51
|
+
try {
|
|
52
|
+
for (const dateTimeFormat of dateTimeFormats) {
|
|
53
|
+
const result = dateTimeFormat(value?.toString() ?? "");
|
|
54
|
+
if (result && result.isValid) {
|
|
55
|
+
return "timestamp";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.debug(`guessType parse error with value '${value}' formats ${JSON.stringify(dateTimeFormats)}: ${err}`);
|
|
61
|
+
}
|
|
62
|
+
if ((0, lodash_1.isString)(value)) {
|
|
63
|
+
return "string";
|
|
64
|
+
}
|
|
65
|
+
console.debug(`guessType unknown type for '${value}' info ${JSON.stringify(valueProtoInfo(value))}`);
|
|
66
|
+
return "unknown";
|
|
67
|
+
}
|
|
68
|
+
function valueProtoInfo(value) {
|
|
69
|
+
const isObjectLike = (0, lodash_1.isObjectLike)(value);
|
|
70
|
+
const isValueStringTagObject = Object.prototype.toString.call(value) === '[object Object]';
|
|
71
|
+
const valuePrototypeCtor = Object.getPrototypeOf(value).constructor;
|
|
72
|
+
const isValueProtoCtorFunc = typeof valuePrototypeCtor === 'function';
|
|
73
|
+
const isValueProtoCtorFuncObj = Function.prototype.toString.call(valuePrototypeCtor) === Function.prototype.toString.call(Object);
|
|
74
|
+
return {
|
|
75
|
+
isObjectLike,
|
|
76
|
+
isValueStringTagObject,
|
|
77
|
+
valuePrototypeCtor,
|
|
78
|
+
isValueProtoCtorFunc,
|
|
79
|
+
isValueProtoCtorFuncObj,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Apply conventions to convert a value to a boolean.
|
|
84
|
+
* @param value A value to convert to boolean.
|
|
85
|
+
*/
|
|
86
|
+
function toBoolean(value) {
|
|
87
|
+
if (typeof value === 'boolean') {
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === 'number') {
|
|
91
|
+
return !Number.isNaN(value) && value !== 0;
|
|
92
|
+
}
|
|
93
|
+
const normalized = String(value ?? '').trim().toLowerCase();
|
|
94
|
+
const trueValues = ["true", "t", "1", "yes", "y", "on", "enable", "enabled"];
|
|
95
|
+
return trueValues.includes(normalized);
|
|
96
|
+
}
|
|
97
|
+
// TODO: consider trying to type the access to the config properties.
|
|
98
|
+
// type FormFieldComponentOrLayoutDefinitionConfig = FormFieldComponentOrLayoutDefinition['config'];
|
|
99
|
+
// type FormFieldComponentOrLayoutStringKeys = NonNullable<ExtractPropertyNamesOfTypeFromTypeUnion<
|
|
100
|
+
// FormFieldComponentOrLayoutDefinitionConfig, string | undefined | null
|
|
101
|
+
// >>;
|
|
102
|
+
// type FormFieldComponentOrLayoutBooleanKeys = NonNullable<ExtractPropertyNamesOfTypeFromTypeUnion<
|
|
103
|
+
// FormFieldComponentOrLayoutDefinitionConfig, boolean | undefined | null
|
|
104
|
+
// >>;
|
|
105
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb25maWcvaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQTBCQSw4QkErREM7QUFxQkQsOEJBVUM7QUF4SEQsbUNBT2dCO0FBQ2hCLGlDQUErQjtBQWEvQjs7OztHQUlHO0FBQ0gsU0FBZ0IsU0FBUyxDQUFDLEtBQWM7SUFDcEMsSUFBSSxLQUFLLEtBQUssSUFBSSxFQUFFLENBQUM7UUFDakIsT0FBTyxNQUFNLENBQUM7SUFDbEIsQ0FBQztJQUNELElBQUksS0FBSyxLQUFLLFNBQVMsRUFBRSxDQUFDO1FBQ3RCLE9BQU8sV0FBVyxDQUFDO0lBQ3ZCLENBQUM7SUFFRCxJQUFJLElBQUEsa0JBQVUsRUFBQyxLQUFLLENBQUMsRUFBRSxDQUFDO1FBQ3BCLE9BQU8sU0FBUyxDQUFDO0lBQ3JCLENBQUM7SUFFRCxJQUFJLE1BQU0sQ0FBQyxRQUFRLENBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQztRQUN6QixPQUFPLF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NIn0=
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lineage path is an ordered list of keys (string|number) describing a path lineage for
|
|
3
|
+
* different domains of form configuration.
|
|
4
|
+
* A string key is a property name or array index number as a string, a number key is an array index.
|
|
5
|
+
*/
|
|
6
|
+
export type LineagePath = (string | number)[];
|
|
7
|
+
/**
|
|
8
|
+
* A collection of lineage paths that describe different relationships.
|
|
9
|
+
*/
|
|
10
|
+
export interface LineagePaths {
|
|
11
|
+
/**
|
|
12
|
+
* The path to the item in the form config.
|
|
13
|
+
*/
|
|
14
|
+
formConfig: LineagePath;
|
|
15
|
+
/**
|
|
16
|
+
* The path to the item in the form data model.
|
|
17
|
+
*/
|
|
18
|
+
dataModel: LineagePath;
|
|
19
|
+
/**
|
|
20
|
+
* The path to the item in the angular control hierarchy.
|
|
21
|
+
*/
|
|
22
|
+
angularComponents: LineagePath;
|
|
23
|
+
/**
|
|
24
|
+
* The JSONPointer to the angular control.
|
|
25
|
+
*/
|
|
26
|
+
angularComponentsJsonPointer?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The path to the item in the layout hierarchy.
|
|
29
|
+
* Uses the component name with a "-layout" suffix.
|
|
30
|
+
*/
|
|
31
|
+
layout: LineagePath;
|
|
32
|
+
/**
|
|
33
|
+
* The JSONPointer to the layout item.
|
|
34
|
+
*/
|
|
35
|
+
layoutJsonPointer?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Allow providing a partial lineage paths object.
|
|
39
|
+
* This is for adding to an existing lineage path.
|
|
40
|
+
*/
|
|
41
|
+
export interface LineagePathsPartial {
|
|
42
|
+
formConfig?: LineagePath;
|
|
43
|
+
dataModel?: LineagePath;
|
|
44
|
+
angularComponents?: LineagePath;
|
|
45
|
+
layout?: LineagePath;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Build the lineage paths from a base item, and add the entries in `more` as relative
|
|
49
|
+
* parts at the end of each lineage path. Undefined inputs default to empty arrays.
|
|
50
|
+
* This was previously an instance method of FormService.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildLineagePaths(base?: LineagePaths, more?: LineagePathsPartial): LineagePaths;
|
|
53
|
+
/**
|
|
54
|
+
* Get a JSON Pointer string from an array of path segments.
|
|
55
|
+
*
|
|
56
|
+
* @param paths
|
|
57
|
+
* @returns JSON Pointer string
|
|
58
|
+
*/
|
|
59
|
+
export declare function getJSONPointerByArrayPaths(paths: (string | number)[]): string;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieve any object property using a JSON Pointer or an array of path segments.
|
|
62
|
+
*
|
|
63
|
+
* @param obj
|
|
64
|
+
* @param pointer
|
|
65
|
+
* @returns JSON Pointer reference: {key: 'key', val: 'object value at key', obj: 'context object, 1 level up from key'}
|
|
66
|
+
*/
|
|
67
|
+
export declare function getObjectWithJsonPointer(obj: any, pointer: string | string[]): any;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieve the last segment of a JSONPointer string
|
|
70
|
+
*/
|
|
71
|
+
export declare function getLastSegmentFromJSONPointer(pointer: string): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025 Queensland Cyber Infrastructure Foundation (http://www.qcif.edu.au/)
|
|
3
|
+
//
|
|
4
|
+
// GNU GENERAL PUBLIC LICENSE
|
|
5
|
+
// Version 2, June 1991
|
|
6
|
+
//
|
|
7
|
+
// This program is free software; you can redistribute it and/or modify
|
|
8
|
+
// it under the terms of the GNU General Public License as published by
|
|
9
|
+
// the Free Software Foundation; either version 2 of the License, or
|
|
10
|
+
// (at your option) any later version.
|
|
11
|
+
//
|
|
12
|
+
// This program is distributed in the hope that it will be useful,
|
|
13
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
// GNU General Public License for more details.
|
|
16
|
+
//
|
|
17
|
+
// You should have received a copy of the GNU General Public License along
|
|
18
|
+
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
19
|
+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.buildLineagePaths = buildLineagePaths;
|
|
22
|
+
exports.getJSONPointerByArrayPaths = getJSONPointerByArrayPaths;
|
|
23
|
+
exports.getObjectWithJsonPointer = getObjectWithJsonPointer;
|
|
24
|
+
exports.getLastSegmentFromJSONPointer = getLastSegmentFromJSONPointer;
|
|
25
|
+
const json_pointer_1 = require("@jsonjoy.com/json-pointer");
|
|
26
|
+
/**
|
|
27
|
+
* Build the lineage paths from a base item, and add the entries in `more` as relative
|
|
28
|
+
* parts at the end of each lineage path. Undefined inputs default to empty arrays.
|
|
29
|
+
* This was previously an instance method of FormService.
|
|
30
|
+
*/
|
|
31
|
+
function buildLineagePaths(base, more) {
|
|
32
|
+
const lineagePaths = {
|
|
33
|
+
formConfig: [...(base?.formConfig ?? []), ...(more?.formConfig ?? [])],
|
|
34
|
+
dataModel: [...(base?.dataModel ?? []), ...(more?.dataModel ?? [])],
|
|
35
|
+
angularComponents: [...(base?.angularComponents ?? []), ...(more?.angularComponents ?? [])],
|
|
36
|
+
layout: [...(base?.layout ?? []), ...(more?.layout ?? [])],
|
|
37
|
+
};
|
|
38
|
+
lineagePaths.angularComponentsJsonPointer = getJSONPointerByArrayPaths(lineagePaths.angularComponents);
|
|
39
|
+
lineagePaths.layoutJsonPointer = getJSONPointerByArrayPaths(lineagePaths.layout);
|
|
40
|
+
return lineagePaths;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get a JSON Pointer string from an array of path segments.
|
|
44
|
+
*
|
|
45
|
+
* @param paths
|
|
46
|
+
* @returns JSON Pointer string
|
|
47
|
+
*/
|
|
48
|
+
function getJSONPointerByArrayPaths(paths) {
|
|
49
|
+
return (0, json_pointer_1.formatJsonPointer)(paths);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve any object property using a JSON Pointer or an array of path segments.
|
|
53
|
+
*
|
|
54
|
+
* @param obj
|
|
55
|
+
* @param pointer
|
|
56
|
+
* @returns JSON Pointer reference: {key: 'key', val: 'object value at key', obj: 'context object, 1 level up from key'}
|
|
57
|
+
*/
|
|
58
|
+
function getObjectWithJsonPointer(obj, pointer) {
|
|
59
|
+
if (Array.isArray(pointer)) {
|
|
60
|
+
return (0, json_pointer_1.find)(obj, pointer);
|
|
61
|
+
}
|
|
62
|
+
// Documentation has the order of the parameters reversed compared to the type definition.
|
|
63
|
+
return (0, json_pointer_1.findByPointer)(pointer, obj);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Retrieve the last segment of a JSONPointer string
|
|
67
|
+
*/
|
|
68
|
+
function getLastSegmentFromJSONPointer(pointer) {
|
|
69
|
+
const segments = pointer.split('/');
|
|
70
|
+
return segments[segments.length - 1];
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmFtaW5nLWhlbHBlcnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvY29uZmlnL25hbWVzL25hbWluZy1oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwRkFBMEY7QUFDMUYsRUFBRTtBQUNGLDZCQUE2QjtBQUM3QiwwQkFBMEI7QUFDMUIsRUFBRTtBQUNGLHVFQUF1RTtBQUN2RSx1RUFBdUU7QUFDdkUsb0VBQW9FO0FBQ3BFLHNDQUFzQztBQUN0QyxFQUFFO0FBQ0Ysa0VBQWtFO0FBQ2xFLGlFQUFpRTtBQUNqRSxnRUFBZ0U7QUFDaEUsK0NBQStDO0FBQy9DLEVBQUU7QUFDRiwwRUFBMEU7QUFDMUUsMEVBQTBFO0FBQzFFLDhEQUE4RDs7QUE2RDlELDhDQVVDO0FB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sQ0FBQyxLQUEwQjtJQUNqRSxPQUFPLElBQUEsZ0NBQWlCLEVBQUMsS0FBSyxDQUFDLENBQUM7QUFDcEMsQ0FBQztBQUVEOzs7Ozs7R0FNRztBQUNILFNBQWdCLHdCQUF3QixDQUFDLEdBQVEsRUFBRSxPQUEwQjtJQUN6RSxJQUFJLEtBQUssQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLEVBQUUsQ0FBQztRQUN6QixPQUFPLElBQUEsbUJBQUksRUFBQyxHQUFHLEVBQUUsT0FBTyxDQUFDLENBQUM7SUFDOUIsQ0FBQztJQUNELDBGQUEwRjtJQUMxRixPQUFPLElBQUEsNEJBQWEsRUFBQyxPQUFPLEVBQUUsR0FBRyxDQUFDLENBQUM7QUFDdkMsQ0FBQztBQUVEOztHQUVHO0FBQ0gsU0FBZ0IsNkJBQTZCLENBQUMsT0FBZTtJQUN6RCxNQUFNLFFBQVEsR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQ3BDLE9BQU8sUUFBUSxDQUFDLFFBQVEsQ0FBQyxNQUFNLEdBQUcsQ0FBQyxDQUFDLENBQUM7QUFDekMsQ0FBQyJ9
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for querying components using JSONata.
|
|
3
|
+
*
|
|
4
|
+
* Note: these functions are intended to be generic and reusable across contexts, i.e. server and client-side. Further specialisation may be required to be more useful in the specific context.
|
|
5
|
+
*/
|
|
6
|
+
import { LineagePaths } from "./naming-helpers";
|
|
7
|
+
/**
|
|
8
|
+
* Entry representing a property in the JSONata query source tree. This must have no circular references, see: https://docs.jsonata.org/next/embedding-extending#expressionevaluateinput-bindings-callback
|
|
9
|
+
*/
|
|
10
|
+
export interface JSONataQuerySourceProperty {
|
|
11
|
+
name: string;
|
|
12
|
+
lineagePaths?: LineagePaths;
|
|
13
|
+
jsonPointer?: string;
|
|
14
|
+
children?: JSONataQuerySourceProperty[];
|
|
15
|
+
}
|
|
16
|
+
export type FormRequestParamValue = string | string[] | true;
|
|
17
|
+
export type FormRequestParamsMap = Readonly<Record<string, FormRequestParamValue>>;
|
|
18
|
+
export interface JSONataQueryRuntimeContext {
|
|
19
|
+
requestParams?: FormRequestParamsMap;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface JSONataQuerySource {
|
|
23
|
+
queryOrigSource: unknown;
|
|
24
|
+
querySource: JSONataQuerySourceProperty[];
|
|
25
|
+
jsonPointerSource: unknown;
|
|
26
|
+
runtimeContext?: JSONataQueryRuntimeContext;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Performs a deep copy of an object, removing circular references.
|
|
30
|
+
*
|
|
31
|
+
* TODO: Consider trimming more properties that are not needed querying.
|
|
32
|
+
*
|
|
33
|
+
* @param obj
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function decycleObjectForJSONata(obj: any): any;
|
|
37
|
+
/**
|
|
38
|
+
* Simple query function for string inputs. Not meant for integration with the form app, which requires pre-compilation.
|
|
39
|
+
*
|
|
40
|
+
* @param querySource
|
|
41
|
+
* @param query
|
|
42
|
+
*/
|
|
43
|
+
export declare function queryJSONata(querySource: JSONataQuerySource, query: string): Promise<any>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025 Queensland Cyber Infrastructure Foundation (http://www.qcif.edu.au/)
|
|
3
|
+
//
|
|
4
|
+
// GNU GENERAL PUBLIC LICENSE
|
|
5
|
+
// Version 2, June 1991
|
|
6
|
+
//
|
|
7
|
+
// This program is free software; you can redistribute it and/or modify
|
|
8
|
+
// it under the terms of the GNU General Public License as published by
|
|
9
|
+
// the Free Software Foundation; either version 2 of the License, or
|
|
10
|
+
// (at your option) any later version.
|
|
11
|
+
//
|
|
12
|
+
// This program is distributed in the hope that it will be useful,
|
|
13
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
// GNU General Public License for more details.
|
|
16
|
+
//
|
|
17
|
+
// You should have received a copy of the GNU General Public License along
|
|
18
|
+
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
19
|
+
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.decycleObjectForJSONata = decycleObjectForJSONata;
|
|
25
|
+
exports.queryJSONata = queryJSONata;
|
|
26
|
+
const jsonata_1 = __importDefault(require("jsonata"));
|
|
27
|
+
/**
|
|
28
|
+
* Performs a deep copy of an object, removing circular references.
|
|
29
|
+
*
|
|
30
|
+
* TODO: Consider trimming more properties that are not needed querying.
|
|
31
|
+
*
|
|
32
|
+
* @param obj
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
function decycleObjectForJSONata(obj) {
|
|
36
|
+
const cache = new Set();
|
|
37
|
+
return JSON.parse(JSON.stringify(obj, (key, value) => {
|
|
38
|
+
if (typeof value === 'function') {
|
|
39
|
+
return; // Remove functions
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === 'object' && value !== null) {
|
|
42
|
+
if (cache.has(value)) {
|
|
43
|
+
// Circular reference found, discard key
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
cache.add(value);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Simple query function for string inputs. Not meant for integration with the form app, which requires pre-compilation.
|
|
53
|
+
*
|
|
54
|
+
* @param querySource
|
|
55
|
+
* @param query
|
|
56
|
+
*/
|
|
57
|
+
async function queryJSONata(querySource, query) {
|
|
58
|
+
// `.querySource` should already have no circular references, but just in case...
|
|
59
|
+
const queryDoc = decycleObjectForJSONata(querySource.querySource);
|
|
60
|
+
const expression = (0, jsonata_1.default)(query);
|
|
61
|
+
const result = await expression.evaluate(queryDoc);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicXVlcnktaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9jb25maWcvbmFtZXMvcXVlcnktaGVscGVycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEZBQTBGO0FBQzFGLEVBQUU7QUFDRiw2QkFBNkI7QUFDN0IsMEJBQTBCO0FBQzFCLEVBQUU7QUFDRix1RUFBdUU7QUFDdkUsdUVBQXVFO0FBQ3ZFLG9FQUFvRTtBQUNwRSxzQ0FBc0M7QUFDdEMsRUFBRTtBQUNGLGtFQUFrRTtBQUNsRSxpRUFBaUU7QUFDakUsZ0VBQWdFO0FBQ2hFLCtDQUErQztBQUMvQyxFQUFFO0FBQ0YsMEVBQTBFO0FBQzFFLDBFQUEwRTtBQUMxRSw4REFBOEQ7Ozs7O0FBZ0Q5RCwwREFlQztBQVFELG9DQU1DO0FBbkVELHNEQUE4QjtBQThCOUI7Ozs7Ozs7R0FPRztBQUNILFNBQWdCLHVCQUF1QixDQUFDLEdBQVE7SUFDOUMsTUFBTSxLQUFLLEdBQUcsSUFBSSxHQUFHLEVBQUUsQ0FBQztJQUN4QixPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxHQUFHLEVBQUUsQ0FBQyxHQUFHLEVBQUUsS0FBSyxFQUFFLEVBQUU7UUFDbkQsSUFBSSxPQUFPLEtBQUssS0FBSyxVQUFVLEVBQUUsQ0FBQztZQUNoQyxPQUFPLENBQUMsbUJBQW1CO1FBQzdCLENBQUM7UU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