Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"undici": "^7.16.0",
"winston": "^3.17.0",
"xml-formatter": "^3.6.7",
"zod": "^4.1.11",
"zustand": "^5.0.8"
},
"packageManager": "[email protected]"
Expand Down
16 changes: 14 additions & 2 deletions src/main/persistence/service/info-files/latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import { Collection } from 'shim/objects/collection';
import { Folder } from 'shim/objects/folder';
import { TrufosRequest } from 'shim/objects/request';
import { VariableMap } from 'shim/objects/variables';
import { InfoFile, VERSION, RequestInfoFile, FolderInfoFile, CollectionInfoFile } from './v1-3-0';
import {
InfoFile,
VERSION,
RequestInfoFile,
FolderInfoFile,
CollectionInfoFile,
InfoFileBaseSchema,
} from './v1-4-0';

export { VERSION, InfoFile, CollectionInfoFile, FolderInfoFile, RequestInfoFile } from './v1-3-0';
export { VERSION, InfoFile, CollectionInfoFile, FolderInfoFile, RequestInfoFile } from './v1-4-0';

/**
* Deep clones the given object and removes any properties that are not allowed in an info file.
Expand Down Expand Up @@ -48,6 +55,11 @@ export function fromFolderInfoFile(
parentId: Folder['parentId'],
children: Folder['children']
): Folder {
try {
InfoFileBaseSchema.parse(infoFile);
} catch (error) {
logger.error('Could not open folder due to validation errors:', error); // TODO avoid loading folder and implement generic error handling
}
return Object.assign(infoFile, { type: 'folder' as const, parentId, children });
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/persistence/service/info-files/migrators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { InfoFileMigrator as V1_0_1 } from './v1-0-1';
import { InfoFileMigrator as V1_1_0 } from './v1-1-0';
import { InfoFileMigrator as V1_2_0 } from './v1-2-0';
import { InfoFileMigrator as V1_3_0 } from './v1-3-0';
import { InfoFileMigrator as V1_4_0 } from './v1-4-0';

// add new migrators here
const MIGRATOR_ARRAY = [new V1_0_1(), new V1_1_0(), new V1_2_0(), new V1_3_0()];
const MIGRATOR_ARRAY = [new V1_0_1(), new V1_1_0(), new V1_2_0(), new V1_3_0(), new V1_4_0()];

const MIGRATORS = new Map<string, AbstractInfoFileMigrator<VersionedObject, VersionedObject>>(
MIGRATOR_ARRAY.map((mapper) => [mapper.fromVersion, mapper])
Expand Down
54 changes: 54 additions & 0 deletions src/main/persistence/service/info-files/v1-4-0.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { RequestBody } from 'shim/objects/request';
import { VariableMap } from 'shim/objects/variables';
import { EnvironmentMap } from 'shim/objects/environment';
import { RequestMethod } from 'shim/objects/request-method';
import { TrufosHeader } from 'shim/objects/headers';
import { SemVer } from 'main/util/semver';
import { AbstractInfoFileMigrator } from './migrator';
import { TrufosObjectType } from 'shim/objects';
import { AuthorizationInformation, InheritAuthorizationInformation } from 'shim/objects/auth';

import { InfoFile as OldInfoFile, VERSION as OLD_VERSION } from './v1-3-0';
import { z } from 'zod';

export const VERSION = new SemVer(1, 4, 0);

export const InfoFileBaseSchema = z.object({
id: z.string(),
version: z.literal(VERSION.toString),
title: z.string(),
});

export type InfoFileBase = z.infer<typeof InfoFileBaseSchema>;

export type RequestInfoFile = InfoFileBase & {
url: string;
method: RequestMethod;
headers: TrufosHeader[];
body: RequestBody;
auth?: AuthorizationInformation;
};

export type FolderInfoFile = InfoFileBase;

export type CollectionInfoFile = InfoFileBase & {
environments: EnvironmentMap;
variables: VariableMap;
auth?: Exclude<AuthorizationInformation, InheritAuthorizationInformation>;
};

export type InfoFile = RequestInfoFile | FolderInfoFile | CollectionInfoFile;

/**
* Migrates schema `v1.3.0` to `v1.4.0`.
*
* Changes:
* - Migrates version attribute from v1.3.0 to v1.4.0
*/
export class InfoFileMigrator extends AbstractInfoFileMigrator<OldInfoFile, InfoFile> {
public readonly fromVersion = OLD_VERSION.toString();

async migrate(old: OldInfoFile, type: TrufosObjectType, filePath: string): Promise<InfoFile> {
return Object.assign(old, { version: VERSION.toString() });
}
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11321,6 +11321,7 @@ __metadata:
webpack: "npm:^5.101.3"
winston: "npm:^3.17.0"
xml-formatter: "npm:^3.6.7"
zod: "npm:^4.1.11"
zustand: "npm:^5.0.8"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -12434,6 +12435,13 @@ __metadata:
languageName: node
linkType: hard

"zod@npm:^4.1.11":
version: 4.1.11
resolution: "zod@npm:4.1.11"
checksum: 10c0/ce6a4c4acfbf51d7dd0f2669c82f207d62a1f00264eef608994b94eb99d86a74c99f59b0dd3e61ef82909ee136631378b709e0908f0a02a2d5c21d0c497de5db
languageName: node
linkType: hard

"zustand@npm:^5.0.8":
version: 5.0.8
resolution: "zustand@npm:5.0.8"
Expand Down