@scalar/oas-utils 0.2.43 → 0.2.44
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.
- package/CHANGELOG.md +15 -0
- package/dist/diff/diff.d.ts +13 -0
- package/dist/diff/diff.d.ts.map +1 -0
- package/dist/diff/index.d.ts +1 -0
- package/dist/diff/index.d.ts.map +1 -0
- package/dist/diff/index.js +1 -0
- package/dist/entities/{workspace/cookie → cookie}/cookie.d.ts +1 -17
- package/dist/entities/cookie/cookie.d.ts.map +1 -0
- package/dist/entities/{workspace/cookie → cookie}/cookie.js +1 -4
- package/dist/entities/cookie/index.d.ts.map +1 -0
- package/dist/entities/cookie/index.js +1 -0
- package/dist/entities/environment/environment.d.ts +24 -0
- package/dist/entities/environment/environment.d.ts.map +1 -0
- package/dist/entities/environment/environment.js +12 -0
- package/dist/entities/environment/index.d.ts.map +1 -0
- package/dist/entities/environment/index.js +1 -0
- package/dist/entities/{workspace/consts/hot-keys.d.ts → hotkeys/hotkeys.d.ts} +2 -2
- package/dist/entities/hotkeys/hotkeys.d.ts.map +1 -0
- package/dist/entities/{workspace/consts/hot-keys.js → hotkeys/hotkeys.js} +1 -0
- package/dist/entities/hotkeys/index.d.ts +2 -0
- package/dist/entities/hotkeys/index.d.ts.map +1 -0
- package/dist/entities/hotkeys/index.js +1 -0
- package/dist/entities/index.d.ts +1 -1
- package/dist/entities/index.d.ts.map +1 -1
- package/dist/entities/index.js +1 -1
- package/dist/entities/shared/index.d.ts.map +1 -0
- package/dist/entities/shared/utility.d.ts.map +1 -0
- package/dist/entities/spec/collection.d.ts +489 -0
- package/dist/entities/spec/collection.d.ts.map +1 -0
- package/dist/entities/spec/collection.js +63 -0
- package/dist/entities/spec/index.d.ts +10 -0
- package/dist/entities/spec/index.d.ts.map +1 -0
- package/dist/entities/spec/index.js +7 -0
- package/dist/entities/spec/parameters.d.ts +42 -0
- package/dist/entities/spec/parameters.d.ts.map +1 -0
- package/dist/entities/spec/parameters.js +30 -0
- package/dist/entities/spec/request-examples.d.ts +915 -0
- package/dist/entities/spec/request-examples.d.ts.map +1 -0
- package/dist/entities/spec/request-examples.js +168 -0
- package/dist/entities/spec/requests.d.ts +317 -0
- package/dist/entities/spec/requests.d.ts.map +1 -0
- package/dist/entities/{workspace/spec → spec}/requests.js +56 -32
- package/dist/entities/spec/security.d.ts +964 -0
- package/dist/entities/spec/security.d.ts.map +1 -0
- package/dist/entities/spec/security.js +222 -0
- package/dist/entities/spec/server.d.ts +82 -0
- package/dist/entities/spec/server.d.ts.map +1 -0
- package/dist/entities/{workspace/server → spec}/server.js +11 -13
- package/dist/entities/spec/spec-objects.d.ts +279 -0
- package/dist/entities/spec/spec-objects.d.ts.map +1 -0
- package/dist/entities/{workspace/collection/collection.js → spec/spec-objects.js} +21 -45
- package/dist/entities/workspace/index.js +1 -1
- package/dist/entities/workspace/workspace.d.ts +24 -43
- package/dist/entities/workspace/workspace.d.ts.map +1 -1
- package/dist/entities/workspace/workspace.js +6 -7
- package/dist/helpers/httpMethods.d.ts +16 -82
- package/dist/helpers/httpMethods.d.ts.map +1 -1
- package/dist/helpers/httpMethods.js +45 -41
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +4 -2
- package/dist/helpers/local-storage.d.ts +16 -0
- package/dist/helpers/local-storage.d.ts.map +1 -0
- package/dist/helpers/local-storage.js +17 -0
- package/dist/helpers/redirectToProxy.d.ts +2 -0
- package/dist/helpers/redirectToProxy.d.ts.map +1 -1
- package/dist/helpers/redirectToProxy.js +6 -7
- package/dist/helpers/regexHelpers.d.ts +2 -0
- package/dist/helpers/regexHelpers.d.ts.map +1 -0
- package/dist/helpers/regexHelpers.js +3 -0
- package/dist/helpers/schema-model.d.ts +2 -2
- package/dist/helpers/schema-model.d.ts.map +1 -1
- package/dist/helpers/schema-model.js +11 -17
- package/dist/migrations/data-version.d.ts +12 -0
- package/dist/migrations/data-version.d.ts.map +1 -0
- package/dist/migrations/data-version.js +13 -0
- package/dist/migrations/generate-types.d.ts +2 -0
- package/dist/migrations/generate-types.d.ts.map +1 -0
- package/dist/migrations/index.d.ts +4 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +3 -0
- package/dist/migrations/local-storage.d.ts +8 -0
- package/dist/migrations/local-storage.d.ts.map +1 -0
- package/dist/migrations/local-storage.js +36 -0
- package/dist/migrations/migrator.d.ts +4 -0
- package/dist/migrations/migrator.d.ts.map +1 -0
- package/dist/migrations/migrator.js +40 -0
- package/dist/migrations/semver.d.ts +5 -0
- package/dist/migrations/semver.d.ts.map +1 -0
- package/dist/migrations/semver.js +25 -0
- package/dist/migrations/v-0.0.0/index.d.ts +2 -0
- package/dist/migrations/v-0.0.0/index.d.ts.map +1 -0
- package/dist/migrations/v-0.0.0/index.js +1 -0
- package/dist/migrations/v-0.0.0/types.generated.d.ts +347 -0
- package/dist/migrations/v-0.0.0/types.generated.d.ts.map +1 -0
- package/dist/migrations/v-2.1.0/index.d.ts +3 -0
- package/dist/migrations/v-2.1.0/index.d.ts.map +1 -0
- package/dist/migrations/v-2.1.0/index.js +1 -0
- package/dist/migrations/v-2.1.0/migration.d.ts +334 -0
- package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -0
- package/dist/migrations/v-2.1.0/migration.js +249 -0
- package/dist/migrations/v-2.1.0/types.generated.d.ts +42 -0
- package/dist/migrations/v-2.1.0/types.generated.d.ts.map +1 -0
- package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
- package/dist/spec-getters/getExampleFromSchema.js +21 -8
- package/dist/spec-getters/getParametersFromOperation.d.ts +1 -1
- package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
- package/dist/spec-getters/getParametersFromOperation.js +8 -7
- package/dist/spec-getters/getRequestBodyFromOperation.d.ts +12 -40
- package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
- package/dist/spec-getters/getRequestBodyFromOperation.js +34 -23
- package/dist/spec-getters/getRequestFromOperation.d.ts.map +1 -1
- package/dist/spec-getters/getRequestFromOperation.js +1 -2
- package/dist/spec-getters/getServerVariableExamples.d.ts +4 -0
- package/dist/spec-getters/getServerVariableExamples.d.ts.map +1 -0
- package/dist/spec-getters/getServerVariableExamples.js +12 -0
- package/dist/spec-getters/index.d.ts +1 -0
- package/dist/spec-getters/index.d.ts.map +1 -1
- package/dist/spec-getters/index.js +1 -0
- package/dist/transforms/export-spec.d.ts +68 -0
- package/dist/transforms/export-spec.d.ts.map +1 -0
- package/dist/transforms/import-spec.d.ts +20 -68
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +209 -126
- package/package.json +42 -36
- package/dist/entities/workspace/collection/collection.d.ts +0 -330
- package/dist/entities/workspace/collection/collection.d.ts.map +0 -1
- package/dist/entities/workspace/collection/index.d.ts +0 -2
- package/dist/entities/workspace/collection/index.d.ts.map +0 -1
- package/dist/entities/workspace/collection/index.js +0 -1
- package/dist/entities/workspace/consts/hot-keys.d.ts.map +0 -1
- package/dist/entities/workspace/consts/index.d.ts +0 -2
- package/dist/entities/workspace/consts/index.d.ts.map +0 -1
- package/dist/entities/workspace/consts/index.js +0 -1
- package/dist/entities/workspace/cookie/cookie.d.ts.map +0 -1
- package/dist/entities/workspace/cookie/index.d.ts.map +0 -1
- package/dist/entities/workspace/cookie/index.js +0 -1
- package/dist/entities/workspace/environment/environment.d.ts +0 -55
- package/dist/entities/workspace/environment/environment.d.ts.map +0 -1
- package/dist/entities/workspace/environment/environment.js +0 -23
- package/dist/entities/workspace/environment/index.d.ts.map +0 -1
- package/dist/entities/workspace/environment/index.js +0 -1
- package/dist/entities/workspace/folder/folder.d.ts +0 -36
- package/dist/entities/workspace/folder/folder.d.ts.map +0 -1
- package/dist/entities/workspace/folder/folder.js +0 -21
- package/dist/entities/workspace/folder/index.d.ts +0 -2
- package/dist/entities/workspace/folder/index.d.ts.map +0 -1
- package/dist/entities/workspace/folder/index.js +0 -1
- package/dist/entities/workspace/security/index.d.ts +0 -3
- package/dist/entities/workspace/security/index.d.ts.map +0 -1
- package/dist/entities/workspace/security/index.js +0 -2
- package/dist/entities/workspace/security/security-requirement.d.ts +0 -13
- package/dist/entities/workspace/security/security-requirement.d.ts.map +0 -1
- package/dist/entities/workspace/security/security-requirement.js +0 -15
- package/dist/entities/workspace/security/security-schemes.d.ts +0 -696
- package/dist/entities/workspace/security/security-schemes.d.ts.map +0 -1
- package/dist/entities/workspace/security/security-schemes.js +0 -139
- package/dist/entities/workspace/server/index.d.ts +0 -2
- package/dist/entities/workspace/server/index.d.ts.map +0 -1
- package/dist/entities/workspace/server/index.js +0 -1
- package/dist/entities/workspace/server/server.d.ts +0 -91
- package/dist/entities/workspace/server/server.d.ts.map +0 -1
- package/dist/entities/workspace/shared/index.d.ts.map +0 -1
- package/dist/entities/workspace/shared/utility.d.ts.map +0 -1
- package/dist/entities/workspace/spec/components.d.ts +0 -3
- package/dist/entities/workspace/spec/components.d.ts.map +0 -1
- package/dist/entities/workspace/spec/index.d.ts +0 -5
- package/dist/entities/workspace/spec/index.d.ts.map +0 -1
- package/dist/entities/workspace/spec/index.js +0 -2
- package/dist/entities/workspace/spec/parameters.d.ts +0 -16
- package/dist/entities/workspace/spec/parameters.d.ts.map +0 -1
- package/dist/entities/workspace/spec/refs.d.ts +0 -30
- package/dist/entities/workspace/spec/refs.d.ts.map +0 -1
- package/dist/entities/workspace/spec/refs.js +0 -9
- package/dist/entities/workspace/spec/request-examples.d.ts +0 -1573
- package/dist/entities/workspace/spec/request-examples.d.ts.map +0 -1
- package/dist/entities/workspace/spec/request-examples.js +0 -96
- package/dist/entities/workspace/spec/requests.d.ts +0 -181
- package/dist/entities/workspace/spec/requests.d.ts.map +0 -1
- package/dist/entities/workspace/spec/spec.d.ts +0 -18
- package/dist/entities/workspace/spec/spec.d.ts.map +0 -1
- package/dist/entities/workspace/spec/spec.js +0 -8
- /package/dist/entities/{workspace/cookie → cookie}/index.d.ts +0 -0
- /package/dist/entities/{workspace/environment → environment}/index.d.ts +0 -0
- /package/dist/entities/{workspace/shared → shared}/index.d.ts +0 -0
- /package/dist/entities/{workspace/shared → shared}/index.js +0 -0
- /package/dist/entities/{workspace/shared → shared}/utility.d.ts +0 -0
- /package/dist/entities/{workspace/shared → shared}/utility.js +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* localStorage keys for resources
|
|
3
|
+
* DO NOT CHANGE THESE AS IT WILL BREAK THE MIGRATION
|
|
4
|
+
*/
|
|
5
|
+
const LS_KEYS = {
|
|
6
|
+
COLLECTION: 'collection',
|
|
7
|
+
COOKIE: 'cookie',
|
|
8
|
+
ENVIRONMENT: 'environment',
|
|
9
|
+
REQUEST: 'request',
|
|
10
|
+
REQUEST_EXAMPLE: 'requestExample',
|
|
11
|
+
SECURITY_SCHEME: 'securityScheme',
|
|
12
|
+
SERVER: 'server',
|
|
13
|
+
TAG: 'tag',
|
|
14
|
+
WORKSPACE: 'workspace',
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { LS_KEYS };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Redirects the request to a proxy server with a given URL. */
|
|
2
2
|
export declare function redirectToProxy(proxy?: string, url?: string): string;
|
|
3
|
+
/** Check if the URL is relative, aka doesn't start with http[s] */
|
|
4
|
+
export declare const isRelativePath: (url: string) => boolean;
|
|
3
5
|
/** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
|
|
4
6
|
export declare function shouldUseProxy(proxy?: string, url?: string): boolean;
|
|
5
7
|
/** Detect requests to localhost */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"redirectToProxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirectToProxy.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,QAAS,MAAM,YAA8B,CAAA;AAExE,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAWpE;AAED,mCAAmC;AACnC,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,WAI/C"}
|
|
@@ -11,20 +11,19 @@ function redirectToProxy(proxy, url) {
|
|
|
11
11
|
newUrl.searchParams.append('scalar_url', url);
|
|
12
12
|
return newUrl.toString();
|
|
13
13
|
}
|
|
14
|
+
/** Check if the URL is relative, aka doesn't start with http[s] */
|
|
15
|
+
const isRelativePath = (url) => !/^https?:\/\//.test(url);
|
|
14
16
|
/** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
|
|
15
17
|
function shouldUseProxy(proxy, url) {
|
|
16
18
|
// No proxy or url
|
|
17
|
-
if (!proxy || !url)
|
|
19
|
+
if (!proxy || !url)
|
|
18
20
|
return false;
|
|
19
|
-
}
|
|
20
21
|
// Relative URLs
|
|
21
|
-
if (
|
|
22
|
+
if (isRelativePath(url))
|
|
22
23
|
return false;
|
|
23
|
-
}
|
|
24
24
|
// Requests to localhost
|
|
25
|
-
if (isRequestToLocalhost(url))
|
|
25
|
+
if (isRequestToLocalhost(url))
|
|
26
26
|
return false;
|
|
27
|
-
}
|
|
28
27
|
return true;
|
|
29
28
|
}
|
|
30
29
|
/** Detect requests to localhost */
|
|
@@ -34,4 +33,4 @@ function isRequestToLocalhost(url) {
|
|
|
34
33
|
return listOfLocalUrls.includes(hostname);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
export { isRequestToLocalhost, redirectToProxy, shouldUseProxy };
|
|
36
|
+
export { isRelativePath, isRequestToLocalhost, redirectToProxy, shouldUseProxy };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAA+B,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ZodSchema, ZodTypeDef } from 'zod';
|
|
2
2
|
/** Parse an value from a given schema with optional error or null return */
|
|
3
|
-
export declare function schemaModel<T, I = any>(data: I, schema: ZodSchema<T, ZodTypeDef, any>, throwError?: true): T;
|
|
4
|
-
export declare function schemaModel<T, I = any>(data: I, schema: ZodSchema<T, ZodTypeDef, any>, throwError?: false): T | null;
|
|
3
|
+
export declare function schemaModel<T, I = any>(data: I, schema: ZodSchema<T, ZodTypeDef, any>, throwError?: true, errorLocation?: string): T;
|
|
4
|
+
export declare function schemaModel<T, I = any>(data: I, schema: ZodSchema<T, ZodTypeDef, any>, throwError?: false, errorLocation?: string): T | null;
|
|
5
5
|
//# sourceMappingURL=schema-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-model.d.ts","sourceRoot":"","sources":["../../src/helpers/schema-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAEhD,4EAA4E;AAC5E,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EACpC,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EACrC,UAAU,CAAC,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"schema-model.d.ts","sourceRoot":"","sources":["../../src/helpers/schema-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAEhD,4EAA4E;AAC5E,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EACpC,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EACrC,UAAU,CAAC,EAAE,IAAI,EACjB,aAAa,CAAC,EAAE,MAAM,GACrB,CAAC,CAAA;AACJ,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EACpC,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EACrC,UAAU,CAAC,EAAE,KAAK,EAClB,aAAa,CAAC,EAAE,MAAM,GACrB,CAAC,GAAG,IAAI,CAAA"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
console.groupEnd();
|
|
11
|
-
throw new Error('Zod validation failure');
|
|
12
|
-
}
|
|
13
|
-
return result.data;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
const res = schema.safeParse(data);
|
|
17
|
-
return res.success ? res.data : null;
|
|
1
|
+
/** Parse a Zod */
|
|
2
|
+
function schemaModel(data, schema, throwError = true, errorLocation) {
|
|
3
|
+
const result = schema.safeParse(data);
|
|
4
|
+
if (!result.success) {
|
|
5
|
+
console.group('Schema Error' + (errorLocation ? ` - ${errorLocation}` : ''));
|
|
6
|
+
console.warn(JSON.stringify(result.error.format(), null, 2));
|
|
7
|
+
console.log('Recieved: ', data);
|
|
8
|
+
console.groupEnd();
|
|
18
9
|
}
|
|
10
|
+
if (throwError && !result.success)
|
|
11
|
+
throw new Error('Zod validation failure');
|
|
12
|
+
return result.data;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
15
|
export { schemaModel };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensure we update this every migration
|
|
3
|
+
*
|
|
4
|
+
* previous data versions:
|
|
5
|
+
* - undefined
|
|
6
|
+
* - 0.0.0
|
|
7
|
+
* - 2.1.0
|
|
8
|
+
*/
|
|
9
|
+
export declare const DATA_VERSION = "2.1.0";
|
|
10
|
+
/** The localStorage key under which the data version is stored */
|
|
11
|
+
export declare const DATA_VERSION_LS_LEY = "scalar_api_client_data_version";
|
|
12
|
+
//# sourceMappingURL=data-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-version.d.ts","sourceRoot":"","sources":["../../src/migrations/data-version.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,UAAU,CAAA;AAEnC,kEAAkE;AAClE,eAAO,MAAM,mBAAmB,mCAAmC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ensure we update this every migration
|
|
3
|
+
*
|
|
4
|
+
* previous data versions:
|
|
5
|
+
* - undefined
|
|
6
|
+
* - 0.0.0
|
|
7
|
+
* - 2.1.0
|
|
8
|
+
*/
|
|
9
|
+
const DATA_VERSION = '2.1.0';
|
|
10
|
+
/** The localStorage key under which the data version is stored */
|
|
11
|
+
const DATA_VERSION_LS_LEY = 'scalar_api_client_data_version';
|
|
12
|
+
|
|
13
|
+
export { DATA_VERSION, DATA_VERSION_LS_LEY };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../../src/migrations/generate-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LS_KEYS } from '../helpers/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Supports pre-flatted local storage
|
|
4
|
+
*/
|
|
5
|
+
export declare const parseLocalStorage: (lsKey: (typeof LS_KEYS)[keyof typeof LS_KEYS]) => Record<string, unknown>;
|
|
6
|
+
/** Take a best guess of the localStorage version */
|
|
7
|
+
export declare const getLocalStorageVersion: () => string;
|
|
8
|
+
//# sourceMappingURL=local-storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-storage.d.ts","sourceRoot":"","sources":["../../src/migrations/local-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAKxC;;GAEG;AACH,eAAO,MAAM,iBAAiB,UACrB,CAAC,OAAO,OAAO,EAAE,MAAM,OAAO,OAAO,CAAC,KAC5C,MAAM,CAAC,MAAM,EAAE,OAAO,CAKxB,CAAA;AAED,oDAAoD;AACpD,eAAO,MAAM,sBAAsB,QAAO,MAsBzC,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DATA_VERSION_LS_LEY } from './data-version.js';
|
|
2
|
+
import { parse } from 'flatted';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Supports pre-flatted local storage
|
|
6
|
+
*/
|
|
7
|
+
const parseLocalStorage = (lsKey) => {
|
|
8
|
+
const item = localStorage.getItem(lsKey) || '[{}]';
|
|
9
|
+
const data = item[0] === '[' ? parse(item) : JSON.parse(item);
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
/** Take a best guess of the localStorage version */
|
|
13
|
+
const getLocalStorageVersion = () => {
|
|
14
|
+
const collectionStr = localStorage.getItem('collection');
|
|
15
|
+
const dataVersion = localStorage.getItem(DATA_VERSION_LS_LEY);
|
|
16
|
+
// No flatted means first version
|
|
17
|
+
if (!collectionStr?.length || collectionStr?.[0] === '{')
|
|
18
|
+
return '0.0.0';
|
|
19
|
+
// Flatted + types means 2.1.0
|
|
20
|
+
try {
|
|
21
|
+
const [collection] = Object.values(parse(collectionStr) ?? {});
|
|
22
|
+
if (collection.type === 'collection')
|
|
23
|
+
return '2.1.0';
|
|
24
|
+
if (dataVersion)
|
|
25
|
+
return dataVersion;
|
|
26
|
+
return '0.0.0';
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
console.error(e);
|
|
30
|
+
if (dataVersion)
|
|
31
|
+
return dataVersion;
|
|
32
|
+
return '0.0.0';
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { getLocalStorageVersion, parseLocalStorage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../../src/migrations/migrator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAmB,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEpE,6CAA6C;AAC7C,eAAO,MAAM,QAAQ,QAAO,OAAO,CAAC,SAkCnC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getLocalStorageVersion, parseLocalStorage } from './local-storage.js';
|
|
2
|
+
import { semverLessThan } from './semver.js';
|
|
3
|
+
import { migrate_v_2_1_0 } from './v-2.1.0/migration.js';
|
|
4
|
+
|
|
5
|
+
/** Handles all data migrations per entity */
|
|
6
|
+
const migrator = () => {
|
|
7
|
+
const dataVersion = getLocalStorageVersion();
|
|
8
|
+
console.info('Data version: ' + dataVersion);
|
|
9
|
+
// First we gather all of the old data
|
|
10
|
+
let data = {
|
|
11
|
+
collections: parseLocalStorage('collection'),
|
|
12
|
+
cookies: parseLocalStorage('cookie'),
|
|
13
|
+
environments: parseLocalStorage('environment'),
|
|
14
|
+
requestExamples: parseLocalStorage('requestExample'),
|
|
15
|
+
requests: parseLocalStorage('request'),
|
|
16
|
+
securitySchemes: parseLocalStorage('securityScheme'),
|
|
17
|
+
servers: parseLocalStorage('server'),
|
|
18
|
+
tags: parseLocalStorage('tag'),
|
|
19
|
+
workspaces: parseLocalStorage('workspace'),
|
|
20
|
+
};
|
|
21
|
+
// 0.0.0 -> 2.1.0 migration
|
|
22
|
+
if (semverLessThan(dataVersion, '2.1.0'))
|
|
23
|
+
data = migrate_v_2_1_0(data);
|
|
24
|
+
// If no migration, just grab values
|
|
25
|
+
else
|
|
26
|
+
data = {
|
|
27
|
+
collections: Object.values(data.collections),
|
|
28
|
+
cookies: Object.values(data.cookies),
|
|
29
|
+
environments: Object.values(data.environments),
|
|
30
|
+
requestExamples: Object.values(data.requestExamples),
|
|
31
|
+
requests: Object.values(data.requests),
|
|
32
|
+
securitySchemes: Object.values(data.securitySchemes),
|
|
33
|
+
servers: Object.values(data.servers),
|
|
34
|
+
tags: Object.values(data.tags),
|
|
35
|
+
workspaces: Object.values(data.workspaces),
|
|
36
|
+
};
|
|
37
|
+
return data;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { migrator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semver.d.ts","sourceRoot":"","sources":["../../src/migrations/semver.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,cAAc,SAAU,MAAM,SAAS,MAAM,KAAG,OAqB5D,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compares semver versions and checks if the left one is less than the right
|
|
3
|
+
*/
|
|
4
|
+
const semverLessThan = (left, right) => {
|
|
5
|
+
// Parse the strings into numbers
|
|
6
|
+
const parseSemver = (version) => {
|
|
7
|
+
const [major, minor = 0, patch = 0] = version
|
|
8
|
+
.split('.')
|
|
9
|
+
.map((part) => parseInt(part, 10));
|
|
10
|
+
return { major, minor, patch };
|
|
11
|
+
};
|
|
12
|
+
const { major: major1, minor: minor1, patch: patch1 } = parseSemver(left);
|
|
13
|
+
const { major: major2, minor: minor2, patch: patch2 } = parseSemver(right);
|
|
14
|
+
if (major1 < major2)
|
|
15
|
+
return true;
|
|
16
|
+
if (major1 > major2)
|
|
17
|
+
return false;
|
|
18
|
+
if (minor1 < minor2)
|
|
19
|
+
return true;
|
|
20
|
+
if (minor1 > minor2)
|
|
21
|
+
return false;
|
|
22
|
+
return patch1 < patch2;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export { semverLessThan };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-0.0.0/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|