@luomus/laji-form-builder 1.0.28

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/LICENSE +21 -0
  3. package/README.md +114 -0
  4. package/dist/laji-form-builder.js +2 -0
  5. package/dist/laji-form-builder.js.LICENSE.txt +82 -0
  6. package/dist/main.js +2 -0
  7. package/dist/main.js.LICENSE.txt +86 -0
  8. package/dist/styles.css +4 -0
  9. package/lib/api-client.d.ts +20 -0
  10. package/lib/api-client.js +60 -0
  11. package/lib/api-client.js.map +1 -0
  12. package/lib/client/LajiFormInterface.d.ts +44 -0
  13. package/lib/client/LajiFormInterface.js +39 -0
  14. package/lib/client/LajiFormInterface.js.map +1 -0
  15. package/lib/client/app.d.ts +9 -0
  16. package/lib/client/app.js +39 -0
  17. package/lib/client/app.js.map +1 -0
  18. package/lib/client/components/Builder.d.ts +101 -0
  19. package/lib/client/components/Builder.js +357 -0
  20. package/lib/client/components/Builder.js.map +1 -0
  21. package/lib/client/components/Context.d.ts +18 -0
  22. package/lib/client/components/Context.js +25 -0
  23. package/lib/client/components/Context.js.map +1 -0
  24. package/lib/client/components/Editor/BasicEditor.d.ts +29 -0
  25. package/lib/client/components/Editor/BasicEditor.js +185 -0
  26. package/lib/client/components/Editor/BasicEditor.js.map +1 -0
  27. package/lib/client/components/Editor/DiffViewer.d.ts +17 -0
  28. package/lib/client/components/Editor/DiffViewer.js +134 -0
  29. package/lib/client/components/Editor/DiffViewer.js.map +1 -0
  30. package/lib/client/components/Editor/Editor.d.ts +111 -0
  31. package/lib/client/components/Editor/Editor.js +344 -0
  32. package/lib/client/components/Editor/Editor.js.map +1 -0
  33. package/lib/client/components/Editor/ElemPicker.d.ts +13 -0
  34. package/lib/client/components/Editor/ElemPicker.js +170 -0
  35. package/lib/client/components/Editor/ElemPicker.js.map +1 -0
  36. package/lib/client/components/Editor/FieldEditor.d.ts +41 -0
  37. package/lib/client/components/Editor/FieldEditor.js +125 -0
  38. package/lib/client/components/Editor/FieldEditor.js.map +1 -0
  39. package/lib/client/components/Editor/Fields.d.ts +27 -0
  40. package/lib/client/components/Editor/Fields.js +185 -0
  41. package/lib/client/components/Editor/Fields.js.map +1 -0
  42. package/lib/client/components/Editor/OptionsEditor.d.ts +20 -0
  43. package/lib/client/components/Editor/OptionsEditor.js +207 -0
  44. package/lib/client/components/Editor/OptionsEditor.js.map +1 -0
  45. package/lib/client/components/Editor/UiSchemaEditor.d.ts +22 -0
  46. package/lib/client/components/Editor/UiSchemaEditor.js +368 -0
  47. package/lib/client/components/Editor/UiSchemaEditor.js.map +1 -0
  48. package/lib/client/components/LajiForm.d.ts +4 -0
  49. package/lib/client/components/LajiForm.js +32 -0
  50. package/lib/client/components/LajiForm.js.map +1 -0
  51. package/lib/client/components/Wizard.d.ts +11 -0
  52. package/lib/client/components/Wizard.js +364 -0
  53. package/lib/client/components/Wizard.js.map +1 -0
  54. package/lib/client/components/components.d.ts +103 -0
  55. package/lib/client/components/components.js +321 -0
  56. package/lib/client/components/components.js.map +1 -0
  57. package/lib/client/services/change-handler-service.d.ts +57 -0
  58. package/lib/client/services/change-handler-service.js +150 -0
  59. package/lib/client/services/change-handler-service.js.map +1 -0
  60. package/lib/client/services/form-service.d.ts +21 -0
  61. package/lib/client/services/form-service.js +77 -0
  62. package/lib/client/services/form-service.js.map +1 -0
  63. package/lib/client/styles.css +227 -0
  64. package/lib/client/styles.d.ts +2 -0
  65. package/lib/client/styles.js +5 -0
  66. package/lib/client/styles.js.map +1 -0
  67. package/lib/client/themes/bs3.d.ts +3 -0
  68. package/lib/client/themes/bs3.js +49 -0
  69. package/lib/client/themes/bs3.js.map +1 -0
  70. package/lib/client/themes/theme.d.ts +28 -0
  71. package/lib/client/themes/theme.js +14 -0
  72. package/lib/client/themes/theme.js.map +1 -0
  73. package/lib/client/translations.json +272 -0
  74. package/lib/client/utils.d.ts +63 -0
  75. package/lib/client/utils.js +370 -0
  76. package/lib/client/utils.js.map +1 -0
  77. package/lib/model.d.ts +205 -0
  78. package/lib/model.js +43 -0
  79. package/lib/model.js.map +1 -0
  80. package/lib/services/form-expander-service.d.ts +15 -0
  81. package/lib/services/form-expander-service.js +77 -0
  82. package/lib/services/form-expander-service.js.map +1 -0
  83. package/lib/services/has-cache.d.ts +8 -0
  84. package/lib/services/has-cache.js +22 -0
  85. package/lib/services/has-cache.js.map +1 -0
  86. package/lib/services/metadata-service.d.ts +23 -0
  87. package/lib/services/metadata-service.js +138 -0
  88. package/lib/services/metadata-service.js.map +1 -0
  89. package/lib/utils.d.ts +79 -0
  90. package/lib/utils.js +117 -0
  91. package/lib/utils.js.map +1 -0
  92. package/package.json +114 -0
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const utils_1 = require("../utils");
27
+ const deepmerge_1 = __importDefault(require("deepmerge"));
28
+ const fast_json_patch_1 = require("fast-json-patch");
29
+ class FormExpanderService {
30
+ constructor(storeService) {
31
+ this.mapBaseForm = (master, signal) => __awaiter(this, void 0, void 0, function* () {
32
+ if (!master.baseFormID) {
33
+ return master;
34
+ }
35
+ const baseForm = yield this.expandMaster(yield this.storeService.getForm(master.baseFormID, signal), signal);
36
+ return this.mapBaseFormFrom(master, baseForm);
37
+ });
38
+ this.mapFieldsFormID = (master) => __awaiter(this, void 0, void 0, function* () {
39
+ if (!master.fieldsFormID) {
40
+ return master;
41
+ }
42
+ const { fieldsFormID } = master, masterWithoutFieldsFormID = __rest(master, ["fieldsFormID"]);
43
+ const { fields, uiSchema, translations, context } = yield this.expandMaster(yield this.storeService.getForm(fieldsFormID));
44
+ const _master = Object.assign(Object.assign({}, masterWithoutFieldsFormID), { fields, translations: deepmerge_1.default(translations || {}, master.translations || {}), uiSchema: deepmerge_1.default(master.uiSchema || {}, uiSchema || {}) });
45
+ if (!master.context && context) {
46
+ _master.context = context;
47
+ }
48
+ return _master;
49
+ });
50
+ this.storeService = storeService;
51
+ }
52
+ linkMaster(master, signal) {
53
+ return utils_1.reduceWith(JSON.parse(JSON.stringify(master)), signal, this.mapBaseForm, this.mapFieldsFormID);
54
+ }
55
+ mapBaseFormFrom(form, baseForm) {
56
+ const { id } = baseForm, _baseForm = __rest(baseForm, ["id"]);
57
+ form = Object.assign(Object.assign(Object.assign({}, _baseForm), form), { translations: deepmerge_1.default(_baseForm.translations || {}, form.translations || {}), uiSchema: deepmerge_1.default(_baseForm.uiSchema || {}, form.uiSchema || {}) });
58
+ delete form.baseFormID;
59
+ return form;
60
+ }
61
+ expandMaster(master, signal) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ return utils_1.reduceWith(yield this.linkMaster(master, signal), undefined, this.applyPatches, addEmptyUiSchema);
64
+ });
65
+ }
66
+ applyPatches(master) {
67
+ const { patch } = master, _master = __rest(master, ["patch"]);
68
+ return patch
69
+ ? fast_json_patch_1.applyPatch(_master, patch, undefined, false).newDocument
70
+ : master;
71
+ }
72
+ }
73
+ exports.default = FormExpanderService;
74
+ const addEmptyUiSchema = (master) => master.uiSchema
75
+ ? master
76
+ : Object.assign(Object.assign({}, master), { uiSchema: {} });
77
+ //# sourceMappingURL=form-expander-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-expander-service.js","sourceRoot":"","sources":["../../src/services/form-expander-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAAsC;AACtC,0DAA8B;AAC9B,qDAA6C;AAI7C,MAAqB,mBAAmB;IAGvC,YAAY,YAAwB;QAa5B,gBAAW,GAAG,CACrB,MAAS,EAAE,MAAoB,EAAkC,EAAE;YACnE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;gBACvB,OAAO,MAAM,CAAC;aACd;YACD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;YAC7G,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC,CAAA,CAAA;QAeD,oBAAe,GACf,CACC,MAAS,EAAqC,EAAE;YAChD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;gBACzB,OAAO,MAAM,CAAC;aACd;YACD,MAAM,EAAC,YAAY,KAAkC,MAAM,EAAnC,yBAAyB,UAAI,MAAM,EAArD,gBAA4C,CAAS,CAAC;YAE5D,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAC,GAC9C,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;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AAC,EAAE,SAAS,EACjE,IAAI,CAAC,YAAY,EACjB,gBAAgB,CAChB,CAAC;QACH,CAAC;KAAA;IAEO,YAAY,CAAkC,MAAS;QAC9D,MAAM,EAAC,KAAK,KAAgB,MAAM,EAAjB,OAAO,UAAI,MAAM,EAA5B,SAAmB,CAAS,CAAC;QACnC,OAAO,KAAK;YACX,CAAC,CAAE,4BAAU,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,WAAiB;YACjE,CAAC,CAAC,MAAM,CAAC;IACX,CAAC;CACD;AAzED,sCAyEC;AAED,MAAM,gBAAgB,GAAG,CAA4B,MAAS,EAAgC,EAAE,CAC/F,MAAM,CAAC,QAAQ;IACd,CAAC,CAAC,MAAsC;IACxC,CAAC,iCAAK,MAAM,KAAE,QAAQ,EAAE,EAAE,GAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import memoize from "memoizee";
2
+ export default class HasCache {
3
+ private cacheStore;
4
+ protected cache: <F extends Function>(fn: F, options?: (memoize.Options & {
5
+ clearDepLength?: number | undefined;
6
+ }) | undefined) => F & memoize.Memoized<F>;
7
+ flush(): void;
8
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const memoizee_1 = __importDefault(require("memoizee"));
7
+ class HasCache {
8
+ constructor() {
9
+ this.cacheStore = [];
10
+ // eslint-disable-next-line @typescript-eslint/ban-types
11
+ this.cache = (fn, options) => {
12
+ const cached = memoizee_1.default(fn, Object.assign({ promise: true, primitive: true }, (options || {})));
13
+ this.cacheStore.push(cached);
14
+ return cached;
15
+ };
16
+ }
17
+ flush() {
18
+ this.cacheStore.forEach(c => c.clear());
19
+ }
20
+ }
21
+ exports.default = HasCache;
22
+ //# sourceMappingURL=has-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-cache.js","sourceRoot":"","sources":["../../src/services/has-cache.ts"],"names":[],"mappings":";;;;;AAAA,wDAA6C;AAE7C,MAAqB,QAAQ;IAA7B;QACS,eAAU,GAAsB,EAAE,CAAC;QAE3C,wDAAwD;QAC9C,UAAK,GAAG,CAAqB,EAAK,EAAE,OAAuD,EAAE,EAAE;YACxG,MAAM,MAAM,GAAG,kBAAO,CAAC,EAAE,kBAAI,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAK,CAAC,OAAO,IAAI,EAAE,CAAC,EAAG,CAAC;YACnF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,MAAM,CAAC;QACf,CAAC,CAAC;IAKH,CAAC;IAHO,KAAK;QACX,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACzC,CAAC;CACD;AAbD,2BAaC"}
@@ -0,0 +1,23 @@
1
+ /// <reference types="memoizee" />
2
+ import ApiClient from "../api-client";
3
+ import { Property, PropertyContext, Range, Lang, Class, JSONSchema, JSONSchemaV6Enum, JSONSchemaEnumOneOf, Field } from "../model";
4
+ import HasCache from "./has-cache";
5
+ export default class MetadataService extends HasCache {
6
+ private apiClient;
7
+ private lang;
8
+ private allRanges;
9
+ constructor(apiClient: ApiClient, lang: Lang);
10
+ flush(): void;
11
+ setLang(lang: Lang): void;
12
+ getPropertiesContextFor: ((context: string) => Promise<Record<string, PropertyContext>>) & import("memoizee").Memoized<(context: string) => Promise<Record<string, PropertyContext>>>;
13
+ getPropertiesForEmbeddedProperty: ((property: string, lang?: string, signal?: AbortSignal | undefined) => Promise<Property[]>) & import("memoizee").Memoized<(property: string, lang?: string, signal?: AbortSignal | undefined) => Promise<Property[]>>;
14
+ getProperties(fields: Field[], property: Property, signal?: AbortSignal): Promise<Record<string, Property>>;
15
+ getRange: ((property: string) => Promise<Range[]>) & import("memoizee").Memoized<(property: string) => Promise<Range[]>>;
16
+ getAllRanges: () => Promise<Record<string, Range[]>>;
17
+ isAltRange: (range: string) => Promise<boolean>;
18
+ getJSONSchemaFromProperty<T extends JSONSchema>(property: Property): Promise<T>;
19
+ getJSONSchemaFromProperty<T extends JSONSchema>(property: Property, useEnums: false): Promise<T>;
20
+ getJSONSchemaFromProperty<T extends JSONSchema<JSONSchemaV6Enum>>(property: Property, useEnums: true): Promise<T>;
21
+ getJSONSchemaFromProperty<T extends JSONSchema<JSONSchemaEnumOneOf | JSONSchemaV6Enum>>(property: Property, useEnums: boolean): Promise<T>;
22
+ getClasses: (() => Promise<Class[]>) & import("memoizee").Memoized<() => Promise<Class[]>>;
23
+ }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const model_1 = require("../model");
16
+ const utils_1 = require("../utils");
17
+ const has_cache_1 = __importDefault(require("./has-cache"));
18
+ class MetadataService extends has_cache_1.default {
19
+ constructor(apiClient, lang) {
20
+ super();
21
+ this.getPropertiesContextFor = this.cache((context) => utils_1.fetchJSON(`https://schema.laji.fi/context/${context}.jsonld`)
22
+ .then(result => result["@context"]));
23
+ this.getPropertiesForEmbeddedProperty = this.cache((property, lang = "multi", signal) => __awaiter(this, void 0, void 0, function* () {
24
+ return (yield this.apiClient.fetchJSON(`/metadata/classes/${utils_1.unprefixProp(property)}/properties`, { lang }, { signal })).results;
25
+ }), { length: 2 });
26
+ this.getRange = this.cache((property) => this.allRanges && Promise.resolve(this.allRanges[property])
27
+ || this.apiClient.fetchJSON(
28
+ // eslint-disable-next-line max-len
29
+ `/metadata/ranges/${utils_1.unprefixProp(property)}`, { lang: "multi" }));
30
+ this.getAllRanges = () => __awaiter(this, void 0, void 0, function* () {
31
+ if (this.allRanges) {
32
+ return this.allRanges;
33
+ }
34
+ const ranges = yield this.apiClient.fetchJSON("/metadata/ranges", { lang: "multi" });
35
+ this.allRanges = ranges;
36
+ return ranges;
37
+ });
38
+ this.isAltRange = (range) => __awaiter(this, void 0, void 0, function* () { return !!(yield this.getAllRanges())[range]; });
39
+ this.getClasses = this.cache(() => __awaiter(this, void 0, void 0, function* () { return (yield this.apiClient.fetchJSON("/metadata/classes")).results; }));
40
+ this.apiClient = apiClient;
41
+ this.lang = lang;
42
+ }
43
+ flush() {
44
+ super.flush();
45
+ this.allRanges = undefined;
46
+ }
47
+ setLang(lang) {
48
+ this.lang = lang;
49
+ }
50
+ getProperties(fields, property, signal) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ return fields
53
+ ? (yield this.getPropertiesForEmbeddedProperty(property.range[0], undefined, signal))
54
+ .reduce((propMap, prop) => {
55
+ if (fields.some(f => utils_1.unprefixProp(prop.property) === utils_1.unprefixProp(f.name))) {
56
+ propMap[utils_1.unprefixProp(prop.property)] = prop;
57
+ }
58
+ return propMap;
59
+ }, {})
60
+ : {};
61
+ });
62
+ }
63
+ getJSONSchemaFromProperty(property, useEnums = false) {
64
+ const mapRangeToSchema = (property) => __awaiter(this, void 0, void 0, function* () {
65
+ var _a, _b;
66
+ const range = property.range[0];
67
+ const isRange = yield this.isAltRange(range);
68
+ if (isRange) {
69
+ const _enums = yield this.getRange(range);
70
+ const empty = property.minOccurs === "1" ? [] : [""];
71
+ let enums = [...empty], enumNames = [...empty];
72
+ for (const e of _enums) {
73
+ enums.push(e.id);
74
+ enumNames.push(((_a = e.vernacularName) === null || _a === void 0 ? void 0 : _a[this.lang]) !== undefined
75
+ ? e.vernacularName[this.lang]
76
+ : ((_b = e.value) === null || _b === void 0 ? void 0 : _b[this.lang]) !== undefined
77
+ ? e.value[this.lang]
78
+ : e.id);
79
+ }
80
+ return utils_1.JSONSchemaBuilder.enu({ enum: enums, enumNames }, undefined, useEnums);
81
+ }
82
+ if (property.multiLanguage) {
83
+ return utils_1.JSONSchemaBuilder.object(["fi", "sv", "en"].reduce((props, lang) => (Object.assign(Object.assign({}, props), { [lang]: { type: "string" } })), {}));
84
+ }
85
+ let schema;
86
+ switch (range) {
87
+ case model_1.PropertyRange.String:
88
+ schema = utils_1.JSONSchemaBuilder.String();
89
+ break;
90
+ case model_1.PropertyRange.Boolean:
91
+ schema = utils_1.JSONSchemaBuilder.Boolean();
92
+ break;
93
+ case model_1.PropertyRange.Int:
94
+ schema = utils_1.JSONSchemaBuilder.Integer();
95
+ break;
96
+ case model_1.PropertyRange.NonNegativeInteger:
97
+ schema = utils_1.JSONSchemaBuilder.Integer({ minimum: 0 });
98
+ break;
99
+ case model_1.PropertyRange.PositiveInteger:
100
+ schema = utils_1.JSONSchemaBuilder.Integer({ exclusiveMinimum: 0 });
101
+ break;
102
+ case model_1.PropertyRange.Decimal:
103
+ schema = utils_1.JSONSchemaBuilder.Number();
104
+ break;
105
+ case model_1.PropertyRange.DateTime:
106
+ schema = utils_1.JSONSchemaBuilder.String({ format: "date-time" });
107
+ break;
108
+ case model_1.PropertyRange.keyValue:
109
+ case model_1.PropertyRange.keyAny:
110
+ schema = utils_1.JSONSchemaBuilder.object();
111
+ break;
112
+ default:
113
+ if (!property.isEmbeddable && utils_1.unprefixProp(property.property) !== "geometry") {
114
+ schema = utils_1.JSONSchemaBuilder.String();
115
+ }
116
+ else {
117
+ return propertiesToSchema(yield this.getPropertiesForEmbeddedProperty(range));
118
+ }
119
+ }
120
+ return schema;
121
+ });
122
+ const mapMaxOccurs = (schema, { maxOccurs }) => maxOccurs === "unbounded"
123
+ ? utils_1.JSONSchemaBuilder.array(schema)
124
+ : schema;
125
+ const mapUniqueItemsForUnboundedAlt = (schema, { range, maxOccurs }) => __awaiter(this, void 0, void 0, function* () {
126
+ return (yield this.isAltRange(range[0])) && maxOccurs === "unbounded"
127
+ ? Object.assign(Object.assign({}, schema), { uniqueItems: true }) : schema;
128
+ });
129
+ const mapLabel = (schema, { label }) => (Object.assign(Object.assign({}, schema), { title: utils_1.multiLang(label, this.lang) }));
130
+ const mapPropertyToJSONSchema = (property) => utils_1.reduceWith(mapRangeToSchema(property), property, mapMaxOccurs, mapUniqueItemsForUnboundedAlt, mapLabel);
131
+ const propertiesToSchema = (modelProperties) => __awaiter(this, void 0, void 0, function* () {
132
+ return utils_1.JSONSchemaBuilder.object((yield Promise.all(modelProperties.map((m) => __awaiter(this, void 0, void 0, function* () { return ({ property: m.shortName, schema: (yield mapPropertyToJSONSchema(m)) }); })))).reduce((properties, { property, schema }) => (Object.assign(Object.assign({}, properties), { [property]: schema })), {}));
133
+ });
134
+ return mapPropertyToJSONSchema(property);
135
+ }
136
+ }
137
+ exports.default = MetadataService;
138
+ //# sourceMappingURL=metadata-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-service.js","sourceRoot":"","sources":["../../src/services/metadata-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,oCAC8C;AAC9C,oCAA6F;AAC7F,4DAAmC;AAEnC,MAAqB,eAAgB,SAAQ,mBAAQ;IAKpD,YAAY,SAAoB,EAAE,IAAU;QAC3C,KAAK,EAAE,CAAC;QAcT,4BAAuB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAe,EAAE,EAAE,CACxD,iBAAS,CAAgD,kCAAkC,OAAO,SAAS,CAAC;aAC1G,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA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E,MAAM,EAAC,EAAE,EAAE,CAAC,iCAAK,UAAU,KAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAE,EAAE,EAAE,CAAC,CAAM,CAAA;UAAA,CAAC;QAE/F,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;CAGD;AA3KD,kCA2KC"}
package/lib/utils.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ import { Field, JSONSchema, JSONSchemaArray, JSONSchemaBoolean, JSONSchemaEnumOneOf, JSONSchemaInteger, JSONSchemaNumber, JSONSchemaObject, JSONSchemaString, JSONSchemaV6Enum, Lang, Master, Property } from "./model";
2
+ export declare const translate: <T>(obj: T, translations: Record<string, string>) => T;
3
+ declare type EVOptions = Record<string, unknown>;
4
+ export declare class JSONSchemaBuilder {
5
+ static type: <T extends JSONSchema<JSONSchemaEnumOneOf>>(type: string) => (options?: {}) => T;
6
+ static String: (options?: {}) => JSONSchemaString;
7
+ static Number: (options?: {}) => JSONSchemaNumber;
8
+ static Integer: (options?: {}) => JSONSchemaInteger;
9
+ static Boolean: (options?: {}) => JSONSchemaBoolean;
10
+ static array: (items: any, options?: {}) => JSONSchemaArray;
11
+ static object: (properties?: {}, options?: {}) => JSONSchemaObject<JSONSchemaEnumOneOf>;
12
+ static enu(_enum: {
13
+ enum: string[];
14
+ enumNames: string[];
15
+ }): JSONSchemaEnumOneOf;
16
+ static enu(_enum: {
17
+ enum: string[];
18
+ enumNames: string[];
19
+ }, options: EVOptions): JSONSchemaEnumOneOf;
20
+ static enu(_enum: {
21
+ enum: string[];
22
+ enumNames: string[];
23
+ }, options: EVOptions | undefined, useEnums: false): JSONSchemaEnumOneOf;
24
+ static enu(_enum: {
25
+ enum: string[];
26
+ enumNames: string[];
27
+ }, options: EVOptions | undefined, useEnums: true): JSONSchemaV6Enum;
28
+ static enu(_enum: {
29
+ enum: string[];
30
+ enumNames: string[];
31
+ }, options: EVOptions | undefined, useEnums: boolean): JSONSchemaEnumOneOf | JSONSchemaV6Enum;
32
+ }
33
+ export declare const parseJSONPointer: (obj: any, path: string, safeMode?: true | "createParents" | undefined) => any;
34
+ declare type Reducer<T, R, P> = {
35
+ (value: T, reduceWith: P): R | Promise<R>;
36
+ };
37
+ /**
38
+ * Reduces an initial value into something else with the given reducer functions.
39
+ * An additional value can be given, which will be provided for each reducer function as the 2nd param.
40
+ *
41
+ * @param initialValue The initial value that is passed to each reducer as 1st param.
42
+ * @param reduceWith An additional value that is passed to each reducer as 2nd param.
43
+ * @param {...reducers} Functions which return the accumulated result which is passed to the next reducer.
44
+ *
45
+ * @returns The accumulated result as a promise.
46
+ */
47
+ declare function reduceWith<T, P>(initialValue: T | Promise<T>, reduceWith: P): Promise<T>;
48
+ declare function reduceWith<T, P, A>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>): Promise<A>;
49
+ declare function reduceWith<T, P, A, B>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>): Promise<B>;
50
+ declare function reduceWith<T, P, A, B, C>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>): Promise<C>;
51
+ declare function reduceWith<T, P, A, B, C, D>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>, op4: Reducer<C, D, P>): Promise<D>;
52
+ declare function reduceWith<T, P, A, B, C, D, E>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>, op4: Reducer<C, D, P>, op5: Reducer<D, E, P>): Promise<E>;
53
+ declare function reduceWith<T, P, A, B, C, D, E, F>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>, op4: Reducer<C, D, P>, op5: Reducer<D, E, P>, op6: Reducer<E, F, P>): Promise<F>;
54
+ declare function reduceWith<T, P, A, B, C, D, E, F, G>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>, op4: Reducer<C, D, P>, op5: Reducer<D, E, P>, op6: Reducer<E, F, P>, op7: Reducer<F, G, P>): Promise<G>;
55
+ declare function reduceWith<T, P, A, B, C, D, E, F, G, H>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>, op4: Reducer<C, D, P>, op5: Reducer<D, E, P>, op6: Reducer<E, F, P>, op7: Reducer<F, G, P>, op8: Reducer<G, H, P>): Promise<H>;
56
+ declare function reduceWith<T, P, A, B, C, D, E, F, G, H, I>(initialValue: T | Promise<T>, reduceWith: P, op1: Reducer<T, A, P>, op2: Reducer<A, B, P>, op3: Reducer<B, C, P>, op4: Reducer<C, D, P>, op5: Reducer<D, E, P>, op6: Reducer<E, F, P>, op7: Reducer<F, G, P>, op8: Reducer<G, H, P>, op9: Reducer<H, I, P>): Promise<I>;
57
+ export { reduceWith };
58
+ export declare const bypass: <T>(any: T) => T;
59
+ export declare const multiLang: (obj: Partial<Record<Lang, string>> | undefined, lang: Lang) => string | undefined;
60
+ export declare const isObject: typeof import("@luomus/laji-map/lib/utils").isObject;
61
+ /**
62
+ * Removes the name space prefix.
63
+ *
64
+ * Example:
65
+ * unprefixProp("MY.document"); // returns "document"
66
+ **/
67
+ export declare const unprefixProp: (s: string) => string;
68
+ export declare const fetchJSON: <T>(path: string, options?: any) => Promise<T>;
69
+ /**
70
+ * Converts an array into a dictionary with the array items as the keys.
71
+ *
72
+ * Example:
73
+ * dictionary(["a", "b"]); // returns { a: true, b: true }
74
+ **/
75
+ export declare const dictionarify: <T, K extends string | number | symbol>(arr: T[], operator?: ((item: T) => K) | undefined) => Record<K, true>;
76
+ export declare const dictionarifyByKey: <T extends Record<string, unknown>>(objects: T[], key: keyof T) => Record<string, T>;
77
+ export declare const getPropertyContextName: (context?: string | undefined) => string;
78
+ export declare const getRootField: (master: Pick<Master, "context">) => Field;
79
+ export declare const getRootProperty: (rootField: Field) => Property;
package/lib/utils.js ADDED
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRootProperty = exports.getRootField = exports.getPropertyContextName = exports.dictionarifyByKey = exports.dictionarify = exports.fetchJSON = exports.unprefixProp = exports.isObject = exports.multiLang = exports.bypass = exports.reduceWith = exports.parseJSONPointer = exports.JSONSchemaBuilder = exports.translate = void 0;
7
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
8
+ const utils_1 = require("@luomus/laji-form/lib/utils");
9
+ const translate = (obj, translations) => {
10
+ function translate(_any) {
11
+ if (exports.isObject(_any)) {
12
+ return Object.keys(_any).reduce((translated, key) => {
13
+ translated[key] = translate(_any[key]);
14
+ return translated;
15
+ }, {});
16
+ }
17
+ else if (Array.isArray(_any)) {
18
+ return _any.map(translate);
19
+ }
20
+ if (typeof _any === "string" && _any[0] === "@") {
21
+ if (typeof translations[_any] === "string") {
22
+ return translations[_any];
23
+ }
24
+ // Return the key if it doesn't have the @ prefix
25
+ if (translations[_any.substr(1)]) {
26
+ return translations[_any.substr(1)];
27
+ }
28
+ }
29
+ return _any;
30
+ }
31
+ return translate(obj);
32
+ };
33
+ exports.translate = translate;
34
+ class JSONSchemaBuilder {
35
+ static enu(_enum, options, useEnums = false) {
36
+ return Object.assign(Object.assign({}, JSONSchemaBuilder.String(options)), (!useEnums
37
+ ? { oneOf: _enum.enum.reduce((oneOf, enu, idx) => {
38
+ oneOf.push({ const: enu, title: _enum.enumNames[idx] });
39
+ return oneOf;
40
+ }, []) }
41
+ : _enum));
42
+ }
43
+ }
44
+ exports.JSONSchemaBuilder = JSONSchemaBuilder;
45
+ JSONSchemaBuilder.type = (type) => (options = {}) => (Object.assign({ type }, options));
46
+ JSONSchemaBuilder.String = JSONSchemaBuilder.type("string");
47
+ JSONSchemaBuilder.Number = JSONSchemaBuilder.type("number");
48
+ JSONSchemaBuilder.Integer = JSONSchemaBuilder.type("integer");
49
+ JSONSchemaBuilder.Boolean = JSONSchemaBuilder.type("boolean");
50
+ JSONSchemaBuilder.array = (items, options = {}) => JSONSchemaBuilder.type("array")(Object.assign({ items }, options));
51
+ JSONSchemaBuilder.object = (properties = {}, options = {}) => JSONSchemaBuilder.type("object")(Object.assign({ properties }, options));
52
+ const parseJSONPointer = (obj, path, safeMode) => {
53
+ return utils_1.parseJSONPointer(obj, path, safeMode, true);
54
+ };
55
+ exports.parseJSONPointer = parseJSONPointer;
56
+ function isPromise(p) {
57
+ return !!(p === null || p === void 0 ? void 0 : p.then);
58
+ }
59
+ function reduceWith(initialValue, reduceWith, ...reducers) {
60
+ return reducers.reduce((promise, fn) => promise.then(value => isPromise(fn)
61
+ ? fn(value, reduceWith)
62
+ : Promise.resolve(fn(value, reduceWith))), isPromise(initialValue) ? initialValue : Promise.resolve(initialValue));
63
+ }
64
+ exports.reduceWith = reduceWith;
65
+ const bypass = (any) => any;
66
+ exports.bypass = bypass;
67
+ const multiLang = (obj, lang) => { var _a; return !obj ? undefined : ((_a = obj[lang]) !== null && _a !== void 0 ? _a : obj["en"]); };
68
+ exports.multiLang = multiLang;
69
+ exports.isObject = utils_1.isObject;
70
+ /**
71
+ * Removes the name space prefix.
72
+ *
73
+ * Example:
74
+ * unprefixProp("MY.document"); // returns "document"
75
+ **/
76
+ const unprefixProp = (s) => s.replace(/^.+\./, "");
77
+ exports.unprefixProp = unprefixProp;
78
+ const fetchJSON = (path, options) => cross_fetch_1.default(path, options).then(r => r.json());
79
+ exports.fetchJSON = fetchJSON;
80
+ /**
81
+ * Converts an array into a dictionary with the array items as the keys.
82
+ *
83
+ * Example:
84
+ * dictionary(["a", "b"]); // returns { a: true, b: true }
85
+ **/
86
+ const dictionarify = (arr, operator) => arr.reduce((dict, key) => {
87
+ dict[(operator ? operator(key) : key)] = true;
88
+ return dict;
89
+ }, {});
90
+ exports.dictionarify = dictionarify;
91
+ const dictionarifyByKey = (objects, key) => objects.reduce((map, obj) => {
92
+ map[obj[key]] = obj;
93
+ return map;
94
+ }, {});
95
+ exports.dictionarifyByKey = dictionarifyByKey;
96
+ const getPropertyContextName = (context) => typeof context === "string" ? context : "document";
97
+ exports.getPropertyContextName = getPropertyContextName;
98
+ const getRootField = (master) => {
99
+ return { name: exports.unprefixProp(exports.getPropertyContextName(master.context)) };
100
+ };
101
+ exports.getRootField = getRootField;
102
+ const getRootProperty = (rootField) => {
103
+ return {
104
+ property: rootField.name,
105
+ isEmbeddable: true,
106
+ range: [rootField.name],
107
+ label: {},
108
+ shortName: exports.unprefixProp(rootField.name),
109
+ required: true,
110
+ minOccurs: "1",
111
+ maxOccurs: "1",
112
+ multiLanguage: false,
113
+ domain: []
114
+ };
115
+ };
116
+ exports.getRootProperty = getRootProperty;
117
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAChC,uDAA2G;AAIpG,MAAM,SAAS,GAAG,CAAI,GAAM,EAAE,YAAoC,EAAK,EAAE;IAC/E,SAAS,SAAS,CAAC,IAAS;QAC3B,IAAI,gBAAQ,CAAC,IAAI,CAAC,EAAE;YACnB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAM,CAAC,UAAU,EAAE,GAAG,EAAE,EAAE;gBACxD,UAAU,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;gBACvC,OAAO,UAAU,CAAC;YACnB,CAAC,EAAE,EAAE,CAAC,CAAC;SACP;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC,GAAG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main": "lib/client/app.js",
6
+ "scripts": {
7
+ "start": "npm run start:dev",
8
+ "start:dev": "nodemon src/server/start-dev.ts --ignore test --ignore src/client",
9
+ "start:prod": "node build/main.js",
10
+ "test": "npm run test:server && npm run test:client",
11
+ "test:client": "HOST=localhost PORT=8082 protractor protractor.conf.js",
12
+ "test:client:ci": "webdriver-manager update --gecko false && HOST=localhost PORT=8082 STANDALONE=true protractor protractor.conf.js",
13
+ "test:client:debug": "HEADLESS=false HOST=localhost PORT=8082 node --inspect-brk node_modules/protractor/bin/protractor protractor.conf.js",
14
+ "test:server": "ts-node node_modules/jasmine-xml-reporter/bin/jasmine.js --conf=jasmine.json \"test/server/*-spec.ts\"",
15
+ "test:server:ci": "npm run test:server -- --junitreport --output=test-results/server",
16
+ "test:ci": "npm run test:server:ci && npm run test:client:ci",
17
+ "lint": "eslint -c .eslintrc.prod.json src",
18
+ "build:client": "rimraf lib && NODE_ENV=production tsc -p tsconfig.client.json && node-sass src/client/styles.scss lib/client/styles.css",
19
+ "build:dist": "rimraf dist && NODE_ENV=production webpack --config webpack.config.dist.js && rimraf dist/styles.js",
20
+ "build:build": "rimraf build && NODE_ENV=production webpack --config webpack.config.build.js",
21
+ "build:static": "rimraf static && NODE_ENV=production webpack --config webpack.config.static.js",
22
+ "build:server": "npm run build:static && npm run build:build",
23
+ "preversion": "npm run lint && npm test",
24
+ "postversion": "npm run build:client && npm publish && git push"
25
+ },
26
+ "keywords": [
27
+ "laji-form",
28
+ "laji.fi",
29
+ "FinBIF",
30
+ "luomus",
31
+ "react-jsonschema-form"
32
+ ],
33
+ "dependencies": {
34
+ "@luomus/laji-form": "^14.3.6",
35
+ "@types/deep-diff": "^1.0.2",
36
+ "@types/memoizee": "^0.4.3",
37
+ "@types/react": "^16.14.14",
38
+ "@types/react-bootstrap": "^0.32.25",
39
+ "@types/react-dom": "^17.0.9",
40
+ "@types/react-spinner": "^0.2.0",
41
+ "cross-fetch": "^3.1.5",
42
+ "deep-diff": "^1.0.2",
43
+ "deepmerge": "^4.2.2",
44
+ "fast-json-patch": "^3.1.0",
45
+ "json-schema": "^0.3.0",
46
+ "memoizee": "^0.4.14",
47
+ "parse-prop-types": "git+https://git@github.com/olzraiti/parse-prop-types.git#c8a4540d8d0af0e47187c1d0de155c11be84b9ce",
48
+ "react": "^17.0.2",
49
+ "react-bootstrap": "^0.33.1",
50
+ "react-dom": "^17.0.2",
51
+ "react-spinner": "^0.2.7"
52
+ },
53
+ "devDependencies": {
54
+ "@types/connect-history-api-fallback": "^1.3.5",
55
+ "@types/cron": "^2.0.0",
56
+ "@types/express": "^4.17.13",
57
+ "@types/jasmine": "^3.9.0",
58
+ "@types/node": "^14.18.12",
59
+ "@types/supertest": "^2.0.11",
60
+ "@typescript-eslint/eslint-plugin": "^4.31.1",
61
+ "@typescript-eslint/parser": "^4.31.1",
62
+ "ajv": "^8.10.0",
63
+ "connect-history-api-fallback": "^1.6.0",
64
+ "copyfiles": "^2.4.1",
65
+ "cron": "^2.2.0",
66
+ "css-loader": "^6.7.1",
67
+ "eslint": "^7.32.0",
68
+ "eslint-plugin-protractor": "^2.1.1",
69
+ "eslint-plugin-react": "^7.25.1",
70
+ "eslint-plugin-react-hooks": "^4.2.0",
71
+ "express": "^5.0.0-beta.1",
72
+ "html-webpack-plugin": "^5.5.0",
73
+ "ignore-loader": "^0.1.2",
74
+ "jasmine-reporters": "^2.5.0",
75
+ "jasmine-spec-reporter": "^7.0.0",
76
+ "jasmine-xml-reporter": "^1.2.1",
77
+ "mini-css-extract-plugin": "^2.6.0",
78
+ "node-sass": "^6.0.1",
79
+ "nodemon": "^2.0.15",
80
+ "notus": "^0.3.2",
81
+ "protractor": "^7.0.0",
82
+ "protractor-console-plugin": "^0.1.1",
83
+ "sass-loader": "^12.6.0",
84
+ "source-map-loader": "^3.0.1",
85
+ "style-loader": "^3.3.1",
86
+ "supertest": "^3.4.2",
87
+ "ts-loader": "^9.2.8",
88
+ "ts-node": "^10.2.1",
89
+ "typescript": "^4.3.5",
90
+ "webpack": "^5.70.0",
91
+ "webpack-cli": "^4.9.2",
92
+ "webpack-dev-middleware": "^5.3.1",
93
+ "webpack-hot-middleware": "^2.25.1"
94
+ },
95
+ "author": "Olli Raitio",
96
+ "license": "MIT",
97
+ "directories": {
98
+ "lib": "lib"
99
+ },
100
+ "repository": {
101
+ "type": "git",
102
+ "url": "git+https://github.com/luomus/laji-form-builder.git"
103
+ },
104
+ "bugs": {
105
+ "url": "https://github.com/luomus/laji-form-builder/issues"
106
+ },
107
+ "homepage": "https://github.com/luomus/laji-form-builder#readme",
108
+ "publishConfig": {
109
+ "access": "public"
110
+ },
111
+ "volta": {
112
+ "node": "14.21.3"
113
+ }
114
+ }