swoop-common 2.0.1 → 2.0.3

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.
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { services } from "../init";
10
+ import { CoreService } from "../generated/core";
11
11
  const buildTemplateTree = (templates) => {
12
12
  const revisionGroups = new Map();
13
13
  // Step 1: Group templates by revisionGroupId
@@ -43,7 +43,7 @@ const buildTemplateTree = (templates) => {
43
43
  };
44
44
  export const resolveTemplateHierarchy = (templateId) => __awaiter(void 0, void 0, void 0, function* () {
45
45
  // First fetch all templates
46
- const allTemplates = yield services.CoreService.templateList(1);
46
+ const allTemplates = yield (new CoreService).templateList(1);
47
47
  // Find the initial template
48
48
  const initialTemplate = allTemplates.data.find((t) => t.id === templateId);
49
49
  if (!initialTemplate) {
@@ -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";
@@ -1,11 +1,6 @@
1
1
  import * as Core from "./generated/core/index";
2
2
  import * as Itinerary from "./generated/itinerary/index";
3
3
  import * as Swoop from "./generated/swoop/index";
4
- export declare const services: {
5
- SwoopService: Swoop.SwoopService;
6
- CoreService: Core.CoreService;
7
- ItineraryService: Itinerary.ItineraryService;
8
- };
9
4
  export declare const init: (opts: {
10
5
  itineraryServiceUrl: string;
11
6
  coreServiceUrl: string;
package/dist/api/init.js CHANGED
@@ -2,11 +2,6 @@ import * as Core from "./generated/core/index";
2
2
  import * as Itinerary from "./generated/itinerary/index";
3
3
  import * as Swoop from "./generated/swoop/index";
4
4
  let initalised = false;
5
- export const services = {
6
- SwoopService: new Swoop.SwoopService(),
7
- CoreService: new Core.CoreService(),
8
- ItineraryService: new Itinerary.ItineraryService(),
9
- };
10
5
  export const init = (opts) => {
11
6
  // Keeps it consitent
12
7
  if (opts.coreServiceUrl.endsWith("/"))
@@ -20,7 +15,11 @@ export const init = (opts) => {
20
15
  Itinerary.OpenAPI.BASE = opts.itineraryServiceUrl;
21
16
  Swoop.OpenAPI.BASE = opts.swoopServiceForwardUrl;
22
17
  initalised = true;
23
- return services;
18
+ return {
19
+ SwoopService: new Swoop.SwoopService(),
20
+ CoreService: new Core.CoreService(),
21
+ ItineraryService: new Itinerary.ItineraryService(),
22
+ };
24
23
  };
25
24
  export const initialisedCheck = () => {
26
25
  if (initalised)
@@ -6,15 +6,15 @@ export declare const fetchComponents: () => Promise<{
6
6
  templateId: string;
7
7
  revisionGroupId: string;
8
8
  revision: number;
9
- metadata: import("../../api/generated/core/exports").Metadata;
9
+ metadata: import("../../api/generated/core").Metadata;
10
10
  name: string;
11
- componentFields: Array<import("../../api/generated/core/exports").Field>;
11
+ componentFields: Array<import("../../api/generated/core").Field>;
12
12
  partners: Array<string>;
13
- bundle: Array<import("../../api/generated/core/exports").Bundle>;
13
+ bundle: Array<import("../../api/generated/core").Bundle>;
14
14
  startDate?: string | null;
15
15
  endDate?: string | null;
16
16
  duration?: number | null;
17
- details: import("../../api/generated/core/exports").ComponentDetails;
17
+ details: import("../../api/generated/core").ComponentDetails;
18
18
  state?: string | null;
19
19
  }[];
20
20
  }>;
@@ -12,7 +12,7 @@ import { Paper, Typography, Box, TextField, Autocomplete } from '@mui/material';
12
12
  import { useLocalErrors } from '../hooks/errors';
13
13
  import { ComponentPool } from '../registry/types';
14
14
  import { registerComponent } from '../registry/components';
15
- import { services } from '../../api/init';
15
+ import { CoreService } from '../../api/generated/core';
16
16
  const FormComponentPicker = ({ components, selectedComponent, onChange, templateIds, getError, label, enabled }) => {
17
17
  const selected = components.find(c => c.id === selectedComponent) || null;
18
18
  return (React.createElement(Paper, { component: "form", sx: { display: 'flex', flexDirection: 'column', gap: 1, p: 2, mb: 1 }, noValidate: true, autoComplete: "off" },
@@ -51,7 +51,7 @@ const FormRendererComponentPicker = ({ data, handleChange, path, label, enabled,
51
51
  registerComponent("component", FormRendererComponentPicker, ComponentPool.FORM);
52
52
  export const fetchComponents = () => __awaiter(void 0, void 0, void 0, function* () {
53
53
  const componentsByGroup = new Map();
54
- const data = yield services.CoreService.componentList(1, 1000);
54
+ const data = yield (new CoreService).componentList(1, 1000);
55
55
  (data.data || []).forEach((component) => {
56
56
  const groupId = component.revisionGroupId;
57
57
  if (!componentsByGroup.has(groupId)) {
@@ -13,7 +13,7 @@ import { Paper, Typography, Box, TextField, Chip, Autocomplete } from '@mui/mate
13
13
  import { useLocalErrors } from '../hooks/errors';
14
14
  import { registerComponent } from '../registry/components';
15
15
  import { ComponentPool } from '../registry/types';
16
- import { services } from '../../api/init';
16
+ import { CoreService } from '../../api/generated/core';
17
17
  const FormTemplatePicker = ({ templates, selectedTemplates, onChange, label, enabled }) => {
18
18
  const selectedValues = templates.filter(t => selectedTemplates.includes(t.id));
19
19
  return (React.createElement(Paper, { component: "form", sx: { display: 'flex', flexDirection: 'column', gap: 2, p: 2, mb: 1 }, noValidate: true, autoComplete: "off" },
@@ -33,7 +33,7 @@ const FormRendererTemplatePicker = ({ data, handleChange, path, label, enabled }
33
33
  useEffect(() => {
34
34
  const load = () => __awaiter(void 0, void 0, void 0, function* () {
35
35
  try {
36
- const result = yield services.CoreService.templateList(1);
36
+ const result = yield (new CoreService).templateList(1);
37
37
  setTemplates(result.data);
38
38
  }
39
39
  catch (err) {
@@ -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.1",
3
+ "version": "2.0.3",
4
4
  "main": "dist/api/index.js",
5
5
  "types": "dist/api/index.d.ts",
6
6
  "exports": {