@scalar/oas-utils 0.2.73 → 0.2.75

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.2.75
4
+
5
+ ### Patch Changes
6
+
7
+ - 49ccdee: refactor: updates regexHelpers
8
+
9
+ ## 0.2.74
10
+
11
+ ### Patch Changes
12
+
13
+ - ac55d0f: chore: add time logging for the workspace store
14
+ - Updated dependencies [0c07766]
15
+ - @scalar/themes@0.9.48
16
+
3
17
  ## 0.2.73
4
18
 
5
19
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"findVariables.d.ts","sourceRoot":"","sources":["../../src/helpers/findVariables.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,aAO1C,CAAA"}
1
+ {"version":3,"file":"findVariables.d.ts","sourceRoot":"","sources":["../../src/helpers/findVariables.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,aAM1C,CAAA"}
@@ -1,12 +1,10 @@
1
+ import { REGEX } from './regexHelpers.js';
2
+
1
3
  /**
2
4
  * Find all strings wrapped in {} or {{}} in value.
3
5
  */
4
6
  const findVariables = (value) => {
5
- // Wrapped in single or double curly braces.
6
- // Ignores whitespace
7
- // Works with lowercase, uppercase, numbers, dashes, underscores
8
- const regex = /(?:\{+)\s*(\w+)\s*(?:\}+)/g;
9
- return [...value.matchAll(regex)].map((match) => match[1]?.trim()) || [];
7
+ return ([...value.matchAll(REGEX.PATH), ...value.matchAll(REGEX.VARIABLES)].map((match) => match[1]?.trim()) || []);
10
8
  };
11
9
 
12
10
  export { findVariables };
@@ -16,7 +16,7 @@ export { getObjectKeys, objectMerge } from './object.js';
16
16
  export { formatJsonOrYamlString, isJsonString, json, parseJsonOrYaml, transformToJson, yaml } from './parse.js';
17
17
  export { prettyPrintJson, replaceCircularDependencies } from './prettyPrintJson.js';
18
18
  export { isRelativePath, redirectToProxy, shouldUseProxy } from './redirectToProxy.js';
19
- export { pathRegex, variableRegex } from './regexHelpers.js';
19
+ export { REGEX } from './regexHelpers.js';
20
20
  export { replaceVariables } from './replaceVariables.js';
21
21
  export { schemaModel } from './schema-model.js';
22
22
  export { defaultStateFactory, ssrState } from './ssrState.js';
@@ -1,3 +1,5 @@
1
- export declare const variableRegex: RegExp;
2
- export declare const pathRegex: RegExp;
1
+ export declare const REGEX: {
2
+ readonly VARIABLES: RegExp;
3
+ readonly PATH: RegExp;
4
+ };
3
5
  //# sourceMappingURL=regexHelpers.d.ts.map
@@ -1 +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,QAAyB,CAAA"}
1
+ {"version":3,"file":"regexHelpers.d.ts","sourceRoot":"","sources":["../../src/helpers/regexHelpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK;;;CAGR,CAAA"}
@@ -1,4 +1,6 @@
1
- const variableRegex = /{{((?:[^{}]|{[^{}]*})*)}}/g;
2
- const pathRegex = /(?:{)([^{}]+)}(?!})/g;
1
+ const REGEX = {
2
+ VARIABLES: /{{((?:[^{}]|{[^{}]*})*)}}/g,
3
+ PATH: /(?:{)([^{}]+)}(?!})/g,
4
+ };
3
5
 
4
- export { pathRegex, variableRegex };
6
+ export { REGEX };
@@ -1 +1 @@
1
- {"version":3,"file":"getRequestFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAK7B,eAAO,MAAM,uBAAuB,cACvB,oBAAoB,YACrB;IACR;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,uBACoB,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,kBAAkB,CA4D5B,CAAA"}
1
+ {"version":3,"file":"getRequestFromOperation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/getRequestFromOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAGlB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAM7B,eAAO,MAAM,uBAAuB,cACvB,oBAAoB,YACrB;IACR;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,uBACoB,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,kBAAkB,CA4D5B,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import { getParametersFromOperation } from './getParametersFromOperation.js';
2
2
  import { getRequestBodyFromOperation } from './getRequestBodyFromOperation.js';
3
+ import { REGEX } from '../helpers/regexHelpers.js';
3
4
 
4
5
  const getRequestFromOperation = (operation, options, selectedExampleKey) => {
5
6
  // Replace all variables of the format {something} with the uppercase variable name without the brackets
@@ -7,7 +8,7 @@ const getRequestFromOperation = (operation, options, selectedExampleKey) => {
7
8
  // {id} -> 123
8
9
  const pathParameters = getParametersFromOperation(operation, 'path', false);
9
10
  if (pathParameters.length) {
10
- const pathVariables = path.match(/{(.*?)}/g);
11
+ const pathVariables = path.match(REGEX.PATH);
11
12
  if (pathVariables) {
12
13
  pathVariables.forEach((variable) => {
13
14
  const variableName = variable.replace(/{|}/g, '');
@@ -22,7 +23,7 @@ const getRequestFromOperation = (operation, options, selectedExampleKey) => {
22
23
  }
23
24
  // {id} -> __ID__
24
25
  if (options?.replaceVariables === true) {
25
- const pathVariables = path.match(/{(.*?)}/g);
26
+ const pathVariables = path.match(REGEX.PATH);
26
27
  if (pathVariables) {
27
28
  pathVariables.forEach((variable) => {
28
29
  const variableName = variable.replace(/{|}/g, '');
@@ -15,12 +15,17 @@ export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' |
15
15
  setCollectionSecurity?: boolean;
16
16
  };
17
17
  /**
18
- * Import an OpenAPI spec file and convert it to workspace entities
18
+ * Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
19
19
  *
20
- * We will aim to keep the entities as close to the specification as possible
21
- * to leverage bi-directional translation. Where entities are able to be
22
- * created and used at various levels we will index via the uids to create
23
- * the relationships
20
+ * The imported entities maintain a close mapping to the original OpenAPI specification to enable:
21
+ * - Bi-directional translation between spec and workspace entities
22
+ * - Preservation of specification details and structure
23
+ * - Accurate representation of relationships between components
24
+ *
25
+ * Relationships between entities are maintained through unique identifiers (UIDs) which allow:
26
+ * - Flexible organization at different levels (workspace, collection, request)
27
+ * - Proper linking between related components
28
+ * - Easy lookup and reference of dependent entities
24
29
  */
25
30
  export declare function importSpecToWorkspace(spec: string | UnknownObject, { authentication, baseServerURL, documentUrl, servers: overloadServers, setCollectionSecurity, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{
26
31
  error: false;
@@ -1 +1 @@
1
- {"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAOT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAIhC,MAAM,0BAA0B,CAAA;AAIjC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAwDxD,2DAA2D;AAC3D,eAAO,MAAM,iBAA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,WAAW,CAAC,QAAQ,CAAA;IACjD,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAC5C,CA8SA"}
@@ -86,18 +86,25 @@ const getBaseAuthValues = (scheme, auth) => {
86
86
  };
87
87
  /** Takes a string or object and parses it into an openapi spec compliant schema */
88
88
  const parseSchema = async (spec) => {
89
+ // TODO: Plugins for URLs and files with the proxy is missing here.
90
+ // @see packages/api-reference/src/helpers/parse.ts
89
91
  const { filesystem } = await load(spec);
90
92
  const { specification } = upgrade(filesystem);
91
93
  const { schema, errors = [] } = await dereference(specification);
92
94
  return { schema: schema, errors };
93
95
  };
94
96
  /**
95
- * Import an OpenAPI spec file and convert it to workspace entities
97
+ * Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
96
98
  *
97
- * We will aim to keep the entities as close to the specification as possible
98
- * to leverage bi-directional translation. Where entities are able to be
99
- * created and used at various levels we will index via the uids to create
100
- * the relationships
99
+ * The imported entities maintain a close mapping to the original OpenAPI specification to enable:
100
+ * - Bi-directional translation between spec and workspace entities
101
+ * - Preservation of specification details and structure
102
+ * - Accurate representation of relationships between components
103
+ *
104
+ * Relationships between entities are maintained through unique identifiers (UIDs) which allow:
105
+ * - Flexible organization at different levels (workspace, collection, request)
106
+ * - Proper linking between related components
107
+ * - Easy lookup and reference of dependent entities
101
108
  */
102
109
  async function importSpecToWorkspace(spec, { authentication, baseServerURL, documentUrl, servers: overloadServers, setCollectionSecurity = false, watchMode = false, } = {}) {
103
110
  const { schema, errors } = await parseSchema(spec);
@@ -106,6 +113,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
106
113
  return { importWarnings, error: true };
107
114
  // ---------------------------------------------------------------------------
108
115
  // Some entities will be broken out as individual lists for modification in the workspace
116
+ const start = performance.now();
109
117
  const requests = [];
110
118
  // Grab the base server URL for relative servers
111
119
  const backupBaseServerUrl = typeof window !== 'undefined' ? window.location.origin : 'http://localhost';
@@ -324,6 +332,8 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
324
332
  },
325
333
  securitySchemes: securitySchemes.map((s) => s.uid),
326
334
  });
335
+ const end = performance.now();
336
+ console.log(`workspace: ${Math.round(end - start)} ms`);
327
337
  /**
328
338
  * Servers and requests will be saved in top level maps and indexed via UID to
329
339
  * maintain specification relationships
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.2.73",
19
+ "version": "0.2.75",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -108,7 +108,7 @@
108
108
  "zod": "^3.23.8",
109
109
  "@scalar/object-utils": "1.1.12",
110
110
  "@scalar/openapi-types": "0.1.5",
111
- "@scalar/themes": "0.9.47",
111
+ "@scalar/themes": "0.9.48",
112
112
  "@scalar/types": "0.0.19"
113
113
  },
114
114
  "devDependencies": {
@@ -116,9 +116,9 @@
116
116
  "vite": "^5.4.9",
117
117
  "vitest": "^1.6.0",
118
118
  "zod-to-ts": "^1.2.0",
119
+ "@scalar/openapi-types": "0.1.5",
119
120
  "@scalar/openapi-parser": "0.8.9",
120
- "@scalar/build-tooling": "0.1.12",
121
- "@scalar/openapi-types": "0.1.5"
121
+ "@scalar/build-tooling": "0.1.12"
122
122
  },
123
123
  "scripts": {
124
124
  "build": "scalar-build-rollup",