swoop-common 2.0.2 → 2.0.4

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.
@@ -1,3 +1,4 @@
1
1
  export * from "./generated/core/exports";
2
2
  export * from "./generated/swoop/exports";
3
3
  export { init } from "./init";
4
+ export { deepOrderedMerge } from "../rendering/util/merge";
package/dist/api/index.js CHANGED
@@ -3,3 +3,4 @@ export * from "./generated/core/exports";
3
3
  //export * from "./api/generated/itinerary/exports" Nothing exported directly
4
4
  export * from "./generated/swoop/exports";
5
5
  export { init } from "./init";
6
+ export { deepOrderedMerge } from "../rendering/util/merge";
@@ -9,7 +9,7 @@ export const generateJsonSchema = (formSchema, stage, onlyEditableFields) => {
9
9
  properties: {},
10
10
  required: [],
11
11
  };
12
- formSchema.forEach(s => {
12
+ formSchema.forEach((s) => {
13
13
  if (stage < s.existsFrom)
14
14
  return;
15
15
  if (onlyEditableFields && !s.editableIn.includes(stage))
@@ -32,12 +32,17 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
32
32
  field.fieldType = (_a = field.fieldType) !== null && _a !== void 0 ? _a : "string";
33
33
  let schema = getType(field.fieldType);
34
34
  if (!schema)
35
- throw new Error("tried to generate schema from unknown type: " + field.fieldType + "\nFull object: " + JSON.stringify(field, null, 2));
35
+ throw new Error("tried to generate schema from unknown type: " +
36
+ field.fieldType +
37
+ "\nFull object: " +
38
+ JSON.stringify(field, null, 2));
36
39
  const requiredFields = [];
37
40
  if (field.required)
38
41
  requiredFields.push(field.name);
39
42
  // Specific for array
40
- let arrayItems = field.fieldType === "array" ? defaultConverter((_b = field.arrayOptions) === null || _b === void 0 ? void 0 : _b.itemDefinition, stage, true, true) : undefined;
43
+ let arrayItems = field.fieldType === "array"
44
+ ? defaultConverter((_b = field.arrayOptions) === null || _b === void 0 ? void 0 : _b.itemDefinition, stage, true, true)
45
+ : undefined;
41
46
  // Obj childs
42
47
  const properties = {};
43
48
  for (const child of (_d = (_c = field.objectOptions) === null || _c === void 0 ? void 0 : _c.properties) !== null && _d !== void 0 ? _d : []) {
@@ -46,16 +51,20 @@ const defaultConverter = (field, stage, omitTitle, isChild) => {
46
51
  if (child.required)
47
52
  requiredFields.push(fieldId);
48
53
  }
49
- // Enum fails if empty, fixes
50
- let enumOpts = field.fieldType === "enum" ? (() => {
51
- var _a;
52
- let enumOptions = (((_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) || []);
53
- if (enumOptions.length === 0)
54
- enumOptions.push("");
55
- return enumOptions;
56
- })() : undefined;
54
+ let enumOpts = field.fieldType === "enum" || "stagedEnum"
55
+ ? (() => {
56
+ var _a;
57
+ let enumOptions = (((_a = field.enumOptions) === null || _a === void 0 ? void 0 : _a.enumValues) ||
58
+ []);
59
+ if (enumOptions.length === 0)
60
+ enumOptions.push("");
61
+ return enumOptions;
62
+ })()
63
+ : undefined;
57
64
  // Component (probably should change this)
58
- let templates = field.fieldType === "componentPicker" ? { "x-templateIds": (_e = field.componentOptions) === null || _e === void 0 ? void 0 : _e.templateIds } : {};
65
+ let templates = field.fieldType === "componentPicker"
66
+ ? { "x-templateIds": (_e = field.componentOptions) === null || _e === void 0 ? void 0 : _e.templateIds }
67
+ : {};
59
68
  let title = omitTitle ? undefined : field.name;
60
- return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, ((!isChild && !field.editableIn.includes(stage)) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), { required: requiredFields }), (enumOpts && { enum: enumOpts })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
69
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (!isChild && !field.editableIn.includes(stage) && { readOnly: true })), { title, type: schema.schema.type, "x-type": schema.schema["x-type"] }), templates), (schema.schema.type === "object" && { properties })), { required: requiredFields }), (enumOpts && { enum: enumOpts })), (arrayItems && { items: arrayItems })), (field.fieldType === "object" && { properties }));
61
70
  };
@@ -40,6 +40,20 @@ registerType("enum", "Dropdown", { type: "string" }, {
40
40
  },
41
41
  },
42
42
  }, true);
43
+ registerType("stagedEnum", "Staged Dropdown", {
44
+ type: "array",
45
+ items: { type: "string" },
46
+ }, {
47
+ type: "object",
48
+ title: "Dropdown Options",
49
+ properties: {
50
+ enumValues: {
51
+ title: "Dropdown Values",
52
+ type: "array",
53
+ items: { type: "string" },
54
+ },
55
+ },
56
+ }, true);
43
57
  registerType("array", "List", { type: "array" }, {
44
58
  type: "object",
45
59
  title: "List Options",
@@ -0,0 +1 @@
1
+ export declare const deepOrderedMerge: (...objects: Array<Record<string, any>>) => Record<string, any>;
@@ -0,0 +1,26 @@
1
+ // If this throws an error, it is due to a missmatch in types between objects
2
+ // Objects a merged in order, with later objects taking priority
3
+ export const deepOrderedMerge = (...objects) => {
4
+ if (objects.length === 0)
5
+ return {};
6
+ if (objects.length === 1)
7
+ return objects[0];
8
+ let base = objects[0];
9
+ // Does not account for TYPES changing, only values
10
+ for (let i = 1; i < objects.length; i++) {
11
+ let keys = Object.keys(objects[i]);
12
+ keys.forEach(key => {
13
+ const val = objects[i][key];
14
+ if (!(key in base)) {
15
+ base[key] = val;
16
+ }
17
+ else if (val === null || typeof val !== "object" || Array.isArray(val)) {
18
+ base[key] = val;
19
+ }
20
+ else {
21
+ base[key] = deepOrderedMerge(base[key], val);
22
+ }
23
+ });
24
+ }
25
+ return base;
26
+ };
package/dist/test.d.ts CHANGED
@@ -1 +0,0 @@
1
- export {};
package/dist/test.js CHANGED
@@ -1,26 +1 @@
1
- // If this throws an error, it is due to a missmatch in types between objects
2
- const conv = (...objects) => {
3
- if (objects.length === 0)
4
- return {};
5
- if (objects.length === 1)
6
- return objects[0];
7
- let base = objects[0];
8
- // Does not account for TYPES changing, only values
9
- for (let i = 1; i < objects.length; i++) {
10
- let keys = Object.keys(objects[i]);
11
- keys.forEach(key => {
12
- const val = objects[i][key];
13
- if (!(key in base)) {
14
- base[key] = val;
15
- }
16
- else if (val === null || typeof val !== "object" || Array.isArray(val)) {
17
- base[key] = val;
18
- }
19
- else {
20
- base[key] = conv(base[key], val);
21
- }
22
- });
23
- }
24
- return base;
25
- };
26
- export {};
1
+ "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swoop-common",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {