Working towards a unified storage medium

This commit is contained in:
Luke Hagar
2024-06-29 08:20:00 +00:00
parent a7d20a6ebf
commit 7f96b00b67
10 changed files with 2163 additions and 1843 deletions

View File

@@ -1,8 +1,8 @@
import { get } from 'svelte/store';
import type { ModalSettings, ModalStore } from '@skeletonlabs/skeleton';
import { pathTemplate } from './pathTemplate';
import { openApiStore } from '$lib';
import type { OpenAPIV3 } from './openAPITypes';
import type { OpenAPIV3_1 } from './openAPITypes';
import { selectedSpec } from './db';
export const pathVariables = /\{([^}]+)\}/gm;
@@ -39,9 +39,9 @@ export const addPath = (modalStore: ModalStore, startingPoint: string = '/') =>
}
// create path object
const store = get(openApiStore);
if (!store.paths) store.paths = {};
store.paths[userPath] = pathTemplate;
const store = get(selectedSpec);
if (!store.spec.paths) store.spec.paths = {};
store.spec.paths[userPath] = pathTemplate;
// sort paths alphabetically
sortPathsAlphabetically();
@@ -80,16 +80,16 @@ export const renamePath = (modalStore: ModalStore, oldPath: string) => {
}
// create path object
const store = get(openApiStore);
if (!store.paths) store.paths = {};
const store = get(selectedSpec);
if (!store.spec.paths) store.spec.paths = {};
// copy old path object to new path object
store.paths[userPath] = store.paths[oldPath];
store.spec.paths[userPath] = store.spec.paths[oldPath];
// delete old path object
delete store.paths[oldPath];
delete store.spec.paths[oldPath];
// add path to store
openApiStore.set(store);
selectedSpec.set(store);
// sort paths alphabetically
sortPathsAlphabetically();
@@ -109,12 +109,12 @@ export const deletePath = (modalStore: ModalStore, path: string) => {
// TRUE if confirm pressed, FALSE if cancel pressed
response: (r: boolean) => {
if (r === false) return;
const store = get(openApiStore);
const store = get(selectedSpec);
// check if path exists
if (!store.paths) return;
if (!(path in store.paths)) return;
delete store.paths[path];
openApiStore.set(store);
if (!store.spec.paths) return;
if (!(path in store.spec.paths)) return;
delete store.spec.paths[path];
selectedSpec.set(store);
}
};
modalStore.trigger(modal);
@@ -122,8 +122,8 @@ export const deletePath = (modalStore: ModalStore, path: string) => {
/// checks if a given path already exists
export const pathExists = (path: string) => {
const store = get(openApiStore);
return !(path in store.paths!);
const store = get(selectedSpec);
return !(path in store.spec.paths!);
};
/// checks if a given path is valid
@@ -148,7 +148,7 @@ export const isValidPath = (path: string) => {
/// sorts the paths in the OpenAPI document alphabetically
export const sortPathsAlphabetically = () => {
const tempPathObject = {};
const store = get(openApiStore);
const store = get(selectedSpec);
// @ts-expect-error - we are working with an initially empty object
Object.keys(store.paths)
.sort()
@@ -158,8 +158,8 @@ export const sortPathsAlphabetically = () => {
});
// update path object
openApiStore.update((data) => {
data.paths = tempPathObject;
selectedSpec.update((data) => {
data.spec.paths = tempPathObject;
return data;
});
};
@@ -171,7 +171,7 @@ export const getPathVariables = (path: string) => {
return variables.map((variable) => variable.replace('{', '').replace('}', ''));
};
export const sortPathParameters = (parameters: OpenAPIV3.ParameterObject[]) => {
export const sortPathParameters = (parameters: OpenAPIV3_1.ParameterObject[]) => {
const tempParameters = parameters;
tempParameters.sort((a, b) => {
if (a.in < b.in) return -1;