@scalar/oas-utils 0.2.43 → 0.2.45

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.
Files changed (188) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/diff/diff.d.ts +13 -0
  3. package/dist/diff/diff.d.ts.map +1 -0
  4. package/dist/diff/index.d.ts +1 -0
  5. package/dist/diff/index.d.ts.map +1 -0
  6. package/dist/diff/index.js +1 -0
  7. package/dist/entities/{workspace/cookie → cookie}/cookie.d.ts +1 -17
  8. package/dist/entities/cookie/cookie.d.ts.map +1 -0
  9. package/dist/entities/{workspace/cookie → cookie}/cookie.js +1 -4
  10. package/dist/entities/cookie/index.d.ts.map +1 -0
  11. package/dist/entities/cookie/index.js +1 -0
  12. package/dist/entities/environment/environment.d.ts +24 -0
  13. package/dist/entities/environment/environment.d.ts.map +1 -0
  14. package/dist/entities/environment/environment.js +12 -0
  15. package/dist/entities/environment/index.d.ts.map +1 -0
  16. package/dist/entities/environment/index.js +1 -0
  17. package/dist/entities/{workspace/consts/hot-keys.d.ts → hotkeys/hotkeys.d.ts} +2 -2
  18. package/dist/entities/hotkeys/hotkeys.d.ts.map +1 -0
  19. package/dist/entities/{workspace/consts/hot-keys.js → hotkeys/hotkeys.js} +1 -0
  20. package/dist/entities/hotkeys/index.d.ts +2 -0
  21. package/dist/entities/hotkeys/index.d.ts.map +1 -0
  22. package/dist/entities/hotkeys/index.js +1 -0
  23. package/dist/entities/index.d.ts +1 -1
  24. package/dist/entities/index.d.ts.map +1 -1
  25. package/dist/entities/index.js +1 -1
  26. package/dist/entities/shared/index.d.ts.map +1 -0
  27. package/dist/entities/shared/utility.d.ts.map +1 -0
  28. package/dist/entities/spec/collection.d.ts +489 -0
  29. package/dist/entities/spec/collection.d.ts.map +1 -0
  30. package/dist/entities/spec/collection.js +63 -0
  31. package/dist/entities/spec/index.d.ts +10 -0
  32. package/dist/entities/spec/index.d.ts.map +1 -0
  33. package/dist/entities/spec/index.js +7 -0
  34. package/dist/entities/spec/parameters.d.ts +42 -0
  35. package/dist/entities/spec/parameters.d.ts.map +1 -0
  36. package/dist/entities/spec/parameters.js +30 -0
  37. package/dist/entities/spec/request-examples.d.ts +916 -0
  38. package/dist/entities/spec/request-examples.d.ts.map +1 -0
  39. package/dist/entities/spec/request-examples.js +168 -0
  40. package/dist/entities/spec/requests.d.ts +317 -0
  41. package/dist/entities/spec/requests.d.ts.map +1 -0
  42. package/dist/entities/{workspace/spec → spec}/requests.js +56 -32
  43. package/dist/entities/spec/security.d.ts +964 -0
  44. package/dist/entities/spec/security.d.ts.map +1 -0
  45. package/dist/entities/spec/security.js +222 -0
  46. package/dist/entities/spec/server.d.ts +82 -0
  47. package/dist/entities/spec/server.d.ts.map +1 -0
  48. package/dist/entities/{workspace/server → spec}/server.js +11 -13
  49. package/dist/entities/spec/spec-objects.d.ts +279 -0
  50. package/dist/entities/spec/spec-objects.d.ts.map +1 -0
  51. package/dist/entities/{workspace/collection/collection.js → spec/spec-objects.js} +21 -45
  52. package/dist/entities/workspace/index.js +1 -1
  53. package/dist/entities/workspace/workspace.d.ts +24 -43
  54. package/dist/entities/workspace/workspace.d.ts.map +1 -1
  55. package/dist/entities/workspace/workspace.js +6 -7
  56. package/dist/helpers/httpMethods.d.ts +16 -82
  57. package/dist/helpers/httpMethods.d.ts.map +1 -1
  58. package/dist/helpers/httpMethods.js +45 -41
  59. package/dist/helpers/index.d.ts +2 -0
  60. package/dist/helpers/index.d.ts.map +1 -1
  61. package/dist/helpers/index.js +4 -2
  62. package/dist/helpers/local-storage.d.ts +16 -0
  63. package/dist/helpers/local-storage.d.ts.map +1 -0
  64. package/dist/helpers/local-storage.js +17 -0
  65. package/dist/helpers/redirectToProxy.d.ts +2 -0
  66. package/dist/helpers/redirectToProxy.d.ts.map +1 -1
  67. package/dist/helpers/redirectToProxy.js +6 -7
  68. package/dist/helpers/regexHelpers.d.ts +3 -0
  69. package/dist/helpers/regexHelpers.d.ts.map +1 -0
  70. package/dist/helpers/regexHelpers.js +4 -0
  71. package/dist/helpers/schema-model.d.ts +2 -2
  72. package/dist/helpers/schema-model.d.ts.map +1 -1
  73. package/dist/helpers/schema-model.js +11 -17
  74. package/dist/migrations/data-version.d.ts +12 -0
  75. package/dist/migrations/data-version.d.ts.map +1 -0
  76. package/dist/migrations/data-version.js +13 -0
  77. package/dist/migrations/generate-types.d.ts +2 -0
  78. package/dist/migrations/generate-types.d.ts.map +1 -0
  79. package/dist/migrations/index.d.ts +4 -0
  80. package/dist/migrations/index.d.ts.map +1 -0
  81. package/dist/migrations/index.js +3 -0
  82. package/dist/migrations/local-storage.d.ts +8 -0
  83. package/dist/migrations/local-storage.d.ts.map +1 -0
  84. package/dist/migrations/local-storage.js +36 -0
  85. package/dist/migrations/migrator.d.ts +4 -0
  86. package/dist/migrations/migrator.d.ts.map +1 -0
  87. package/dist/migrations/migrator.js +40 -0
  88. package/dist/migrations/semver.d.ts +5 -0
  89. package/dist/migrations/semver.d.ts.map +1 -0
  90. package/dist/migrations/semver.js +25 -0
  91. package/dist/migrations/v-0.0.0/index.d.ts +2 -0
  92. package/dist/migrations/v-0.0.0/index.d.ts.map +1 -0
  93. package/dist/migrations/v-0.0.0/index.js +1 -0
  94. package/dist/migrations/v-0.0.0/types.generated.d.ts +347 -0
  95. package/dist/migrations/v-0.0.0/types.generated.d.ts.map +1 -0
  96. package/dist/migrations/v-2.1.0/index.d.ts +3 -0
  97. package/dist/migrations/v-2.1.0/index.d.ts.map +1 -0
  98. package/dist/migrations/v-2.1.0/index.js +1 -0
  99. package/dist/migrations/v-2.1.0/migration.d.ts +334 -0
  100. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -0
  101. package/dist/migrations/v-2.1.0/migration.js +249 -0
  102. package/dist/migrations/v-2.1.0/types.generated.d.ts +42 -0
  103. package/dist/migrations/v-2.1.0/types.generated.d.ts.map +1 -0
  104. package/dist/spec-getters/getExampleFromSchema.d.ts.map +1 -1
  105. package/dist/spec-getters/getExampleFromSchema.js +21 -8
  106. package/dist/spec-getters/getParametersFromOperation.d.ts +1 -1
  107. package/dist/spec-getters/getParametersFromOperation.d.ts.map +1 -1
  108. package/dist/spec-getters/getParametersFromOperation.js +8 -7
  109. package/dist/spec-getters/getRequestBodyFromOperation.d.ts +12 -40
  110. package/dist/spec-getters/getRequestBodyFromOperation.d.ts.map +1 -1
  111. package/dist/spec-getters/getRequestBodyFromOperation.js +34 -23
  112. package/dist/spec-getters/getRequestFromOperation.d.ts.map +1 -1
  113. package/dist/spec-getters/getRequestFromOperation.js +1 -2
  114. package/dist/spec-getters/getServerVariableExamples.d.ts +4 -0
  115. package/dist/spec-getters/getServerVariableExamples.d.ts.map +1 -0
  116. package/dist/spec-getters/getServerVariableExamples.js +12 -0
  117. package/dist/spec-getters/index.d.ts +1 -0
  118. package/dist/spec-getters/index.d.ts.map +1 -1
  119. package/dist/spec-getters/index.js +1 -0
  120. package/dist/transforms/export-spec.d.ts +68 -0
  121. package/dist/transforms/export-spec.d.ts.map +1 -0
  122. package/dist/transforms/import-spec.d.ts +20 -68
  123. package/dist/transforms/import-spec.d.ts.map +1 -1
  124. package/dist/transforms/import-spec.js +209 -126
  125. package/package.json +43 -37
  126. package/dist/entities/workspace/collection/collection.d.ts +0 -330
  127. package/dist/entities/workspace/collection/collection.d.ts.map +0 -1
  128. package/dist/entities/workspace/collection/index.d.ts +0 -2
  129. package/dist/entities/workspace/collection/index.d.ts.map +0 -1
  130. package/dist/entities/workspace/collection/index.js +0 -1
  131. package/dist/entities/workspace/consts/hot-keys.d.ts.map +0 -1
  132. package/dist/entities/workspace/consts/index.d.ts +0 -2
  133. package/dist/entities/workspace/consts/index.d.ts.map +0 -1
  134. package/dist/entities/workspace/consts/index.js +0 -1
  135. package/dist/entities/workspace/cookie/cookie.d.ts.map +0 -1
  136. package/dist/entities/workspace/cookie/index.d.ts.map +0 -1
  137. package/dist/entities/workspace/cookie/index.js +0 -1
  138. package/dist/entities/workspace/environment/environment.d.ts +0 -55
  139. package/dist/entities/workspace/environment/environment.d.ts.map +0 -1
  140. package/dist/entities/workspace/environment/environment.js +0 -23
  141. package/dist/entities/workspace/environment/index.d.ts.map +0 -1
  142. package/dist/entities/workspace/environment/index.js +0 -1
  143. package/dist/entities/workspace/folder/folder.d.ts +0 -36
  144. package/dist/entities/workspace/folder/folder.d.ts.map +0 -1
  145. package/dist/entities/workspace/folder/folder.js +0 -21
  146. package/dist/entities/workspace/folder/index.d.ts +0 -2
  147. package/dist/entities/workspace/folder/index.d.ts.map +0 -1
  148. package/dist/entities/workspace/folder/index.js +0 -1
  149. package/dist/entities/workspace/security/index.d.ts +0 -3
  150. package/dist/entities/workspace/security/index.d.ts.map +0 -1
  151. package/dist/entities/workspace/security/index.js +0 -2
  152. package/dist/entities/workspace/security/security-requirement.d.ts +0 -13
  153. package/dist/entities/workspace/security/security-requirement.d.ts.map +0 -1
  154. package/dist/entities/workspace/security/security-requirement.js +0 -15
  155. package/dist/entities/workspace/security/security-schemes.d.ts +0 -696
  156. package/dist/entities/workspace/security/security-schemes.d.ts.map +0 -1
  157. package/dist/entities/workspace/security/security-schemes.js +0 -139
  158. package/dist/entities/workspace/server/index.d.ts +0 -2
  159. package/dist/entities/workspace/server/index.d.ts.map +0 -1
  160. package/dist/entities/workspace/server/index.js +0 -1
  161. package/dist/entities/workspace/server/server.d.ts +0 -91
  162. package/dist/entities/workspace/server/server.d.ts.map +0 -1
  163. package/dist/entities/workspace/shared/index.d.ts.map +0 -1
  164. package/dist/entities/workspace/shared/utility.d.ts.map +0 -1
  165. package/dist/entities/workspace/spec/components.d.ts +0 -3
  166. package/dist/entities/workspace/spec/components.d.ts.map +0 -1
  167. package/dist/entities/workspace/spec/index.d.ts +0 -5
  168. package/dist/entities/workspace/spec/index.d.ts.map +0 -1
  169. package/dist/entities/workspace/spec/index.js +0 -2
  170. package/dist/entities/workspace/spec/parameters.d.ts +0 -16
  171. package/dist/entities/workspace/spec/parameters.d.ts.map +0 -1
  172. package/dist/entities/workspace/spec/refs.d.ts +0 -30
  173. package/dist/entities/workspace/spec/refs.d.ts.map +0 -1
  174. package/dist/entities/workspace/spec/refs.js +0 -9
  175. package/dist/entities/workspace/spec/request-examples.d.ts +0 -1573
  176. package/dist/entities/workspace/spec/request-examples.d.ts.map +0 -1
  177. package/dist/entities/workspace/spec/request-examples.js +0 -96
  178. package/dist/entities/workspace/spec/requests.d.ts +0 -181
  179. package/dist/entities/workspace/spec/requests.d.ts.map +0 -1
  180. package/dist/entities/workspace/spec/spec.d.ts +0 -18
  181. package/dist/entities/workspace/spec/spec.d.ts.map +0 -1
  182. package/dist/entities/workspace/spec/spec.js +0 -8
  183. /package/dist/entities/{workspace/cookie → cookie}/index.d.ts +0 -0
  184. /package/dist/entities/{workspace/environment → environment}/index.d.ts +0 -0
  185. /package/dist/entities/{workspace/shared → shared}/index.d.ts +0 -0
  186. /package/dist/entities/{workspace/shared → shared}/index.js +0 -0
  187. /package/dist/entities/{workspace/shared → shared}/utility.d.ts +0 -0
  188. /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,CAiBpE;AAED,mCAAmC;AACnC,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,WAI/C"}
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 (!url.startsWith('http://') && !url.startsWith('https://')) {
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,3 @@
1
+ export declare const variableRegex: RegExp;
2
+ export declare const pathRegex: RegExp;
3
+ //# sourceMappingURL=regexHelpers.d.ts.map
@@ -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;AACzD,eAAO,MAAM,SAAS,QAA2B,CAAA"}
@@ -0,0 +1,4 @@
1
+ const variableRegex = /{{((?:[^{}]|{[^{}]*})*)}}/g;
2
+ const pathRegex = /(?<!{){([^{}]+)}(?!})/g;
3
+
4
+ export { pathRegex, variableRegex };
@@ -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,GAChB,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,GACjB,CAAC,GAAG,IAAI,CAAA"}
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
- function schemaModel(data, schema, throwError = true) {
2
- if (throwError) {
3
- const result = schema.safeParse(data);
4
- if (!result.success) {
5
- console.error('Zod Schema Error');
6
- console.group();
7
- result.error.issues.forEach((issue) => {
8
- console.log(`Path: ${issue.path.join(', ')} \nError: ${issue.message}`);
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generate-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../../src/migrations/generate-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ export * from './data-version.js';
2
+ export * from './migrator.js';
3
+ export * from './semver.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ export { DATA_VERSION, DATA_VERSION_LS_LEY } from './data-version.js';
2
+ export { migrator } from './migrator.js';
3
+ export { semverLessThan } from './semver.js';
@@ -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,4 @@
1
+ import { type v_2_1_0 } from '../migrations/v-2.1.0/index.js';
2
+ /** Handles all data migrations per entity */
3
+ export declare const migrator: () => v_2_1_0.DataArray;
4
+ //# sourceMappingURL=migrator.d.ts.map
@@ -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,5 @@
1
+ /**
2
+ * Compares semver versions and checks if the left one is less than the right
3
+ */
4
+ export declare const semverLessThan: (left: string, right: string) => boolean;
5
+ //# sourceMappingURL=semver.d.ts.map
@@ -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,2 @@
1
+ export * from './types.generated';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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
+