@scalar/workspace-store 0.38.1 → 0.39.0
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 +27 -0
- package/dist/entities/auth/index.d.ts.map +1 -1
- package/dist/entities/auth/index.js +13 -21
- package/dist/entities/auth/index.js.map +2 -2
- package/dist/entities/auth/schema.d.ts +50 -0
- package/dist/entities/auth/schema.d.ts.map +1 -1
- package/dist/events/definitions/operation.d.ts +13 -0
- package/dist/events/definitions/operation.d.ts.map +1 -1
- package/dist/events/definitions/ui.d.ts +9 -1
- package/dist/events/definitions/ui.d.ts.map +1 -1
- package/dist/helpers/detect-changes-proxy.d.ts +5 -2
- package/dist/helpers/detect-changes-proxy.d.ts.map +1 -1
- package/dist/helpers/detect-changes-proxy.js +7 -0
- package/dist/helpers/detect-changes-proxy.js.map +2 -2
- package/dist/mutators/document.d.ts.map +1 -1
- package/dist/mutators/document.js +2 -2
- package/dist/mutators/document.js.map +2 -2
- package/dist/mutators/environment.d.ts +7 -0
- package/dist/mutators/environment.d.ts.map +1 -1
- package/dist/mutators/environment.js.map +2 -2
- package/dist/mutators/index.d.ts +2 -0
- package/dist/mutators/index.d.ts.map +1 -1
- package/dist/mutators/operation/helpers/sync-path-parameters.d.ts +43 -7
- package/dist/mutators/operation/helpers/sync-path-parameters.d.ts.map +1 -1
- package/dist/mutators/operation/helpers/sync-path-parameters.js +30 -25
- package/dist/mutators/operation/helpers/sync-path-parameters.js.map +2 -2
- package/dist/mutators/operation/index.d.ts +1 -0
- package/dist/mutators/operation/index.d.ts.map +1 -1
- package/dist/mutators/operation/index.js +2 -0
- package/dist/mutators/operation/index.js.map +2 -2
- package/dist/mutators/operation/operation.d.ts +12 -0
- package/dist/mutators/operation/operation.d.ts.map +1 -1
- package/dist/mutators/operation/operation.js +62 -4
- package/dist/mutators/operation/operation.js.map +2 -2
- package/dist/navigation/helpers/traverse-document.d.ts.map +1 -1
- package/dist/navigation/helpers/traverse-document.js +2 -1
- package/dist/navigation/helpers/traverse-document.js.map +2 -2
- package/dist/plugins/bundler/index.d.ts.map +1 -1
- package/dist/plugins/bundler/index.js +29 -25
- package/dist/plugins/bundler/index.js.map +3 -3
- package/dist/plugins/client/persistence.d.ts.map +1 -1
- package/dist/plugins/client/persistence.js +28 -1
- package/dist/plugins/client/persistence.js.map +2 -2
- package/dist/schemas/inmemory-workspace.d.ts +30 -0
- package/dist/schemas/inmemory-workspace.d.ts.map +1 -1
- package/dist/schemas/reference-config/index.d.ts +10 -0
- package/dist/schemas/reference-config/index.d.ts.map +1 -1
- package/dist/schemas/reference-config/settings.d.ts +10 -0
- package/dist/schemas/reference-config/settings.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/openapi-document.d.ts +350 -0
- package/dist/schemas/v3.1/strict/openapi-document.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/schema.d.ts +13 -0
- package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
- package/dist/schemas/v3.1/strict/schema.js +3 -1
- package/dist/schemas/v3.1/strict/schema.js.map +2 -2
- package/dist/schemas/workspace.d.ts +30 -0
- package/dist/schemas/workspace.d.ts.map +1 -1
- package/dist/workspace-plugin.d.ts +6 -0
- package/dist/workspace-plugin.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/mutators/environment.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EnvironmentEvents } from '@/events/definitions/environment'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport type { Workspace, WorkspaceDocument } from '@/schemas'\nimport {\n type XScalarEnvVar,\n type XScalarEnvironment,\n xScalarEnvVarSchema,\n xScalarEnvironmentSchema,\n} from '@/schemas/extensions/document/x-scalar-environments'\nimport { coerceValue } from '@/schemas/typebox-coerce'\n\ntype Event<T extends keyof EnvironmentEvents> = Omit<EnvironmentEvents[T], 'collectionType'>\n\n/**\n * Adds OR updates an environment to the document or workspace.\n *\n * @param document - current document if available\n * @param workspace - current workspace if available\n * @param environmentName - Name of the environment to add\n * @param payload - The environment configuration to add\n * @param oldEnvironmentName - Only needed when renaming the environment\n * @returns the parsed environment that was added or updated or undefined if the collection is not found\n */\nexport const upsertEnvironment = (\n workspace: Workspace | null,\n collection: WorkspaceDocument | Workspace | null,\n { environmentName, payload, oldEnvironmentName }: Event<'environment:upsert:environment'>,\n): XScalarEnvironment | undefined => {\n /** Discriminating between document and workspace */\n if (!collection || !workspace) {\n return\n }\n\n if (!collection['x-scalar-environments']) {\n collection['x-scalar-environments'] = {}\n }\n\n // Check if this is a new environment before we create it\n const isNewEnvironment = !collection['x-scalar-environments'][oldEnvironmentName ?? environmentName]\n\n // Ensure we parse the payload but keep the old variables\n const parsed = coerceValue(xScalarEnvironmentSchema, {\n ...unpackProxyObject(collection['x-scalar-environments'][oldEnvironmentName ?? environmentName], { depth: 1 }),\n ...payload,\n })\n collection['x-scalar-environments'][environmentName] = parsed\n\n // If we are renaming the environment, we need to delete the old one\n if (oldEnvironmentName && oldEnvironmentName !== environmentName) {\n delete collection['x-scalar-environments'][oldEnvironmentName]\n\n // If the old environment was active, we need to set the new environment as active\n if (workspace['x-scalar-active-environment'] === oldEnvironmentName) {\n workspace['x-scalar-active-environment'] = environmentName\n }\n }\n\n // Set the newly created workspace environment as active\n if (isNewEnvironment) {\n workspace['x-scalar-active-environment'] = environmentName\n }\n\n return parsed\n}\n\nexport const deleteEnvironment = (\n workspace: Workspace | null,\n collection: WorkspaceDocument | Workspace | null,\n { environmentName }: Event<'environment:delete:environment'>,\n) => {\n if (!collection || !workspace) {\n return\n }\n\n delete collection['x-scalar-environments']?.[environmentName]\n}\n\n/**\n * Adds OR updates an environment variable to the document or workspace.\n *\n * @param collection - Workspace OR document\n * @param environmentName - Name of the environment to add the variable to\n * @param variableName - Name of the variable to add\n * @param value - Value of the variable to add\n * @returns the parsed variable that was added or updated or undefined if the collection is not found\n */\nexport const upsertEnvironmentVariable = (\n collection: WorkspaceDocument | Workspace | null,\n { environmentName, variable, index }: Event<'environment:upsert:environment-variable'>,\n): XScalarEnvVar | undefined => {\n // The environment should exist by now if we are upserting a variable\n if (!collection?.['x-scalar-environments']?.[environmentName]) {\n console.error('Environment not found', environmentName)\n return\n }\n\n // Ensure we parse the variable for type safety\n const parsed = coerceValue(xScalarEnvVarSchema, variable)\n\n if (index !== undefined) {\n // Delete the row if the name is empty\n if (parsed.name === '') {\n collection['x-scalar-environments'][environmentName].variables.splice(index, 1)\n return\n }\n\n // Update\n collection['x-scalar-environments'][environmentName].variables[index] = parsed\n }\n // Add\n else {\n collection['x-scalar-environments'][environmentName].variables.push(parsed)\n }\n\n return parsed\n}\n\nexport const deleteEnvironmentVariable = (\n collection: WorkspaceDocument | Workspace | null,\n { environmentName, index }: Event<'environment:delete:environment-variable'>,\n) => {\n if (!collection?.['x-scalar-environments']?.[environmentName]) {\n console.error('Environment not found', environmentName)\n return\n }\n collection['x-scalar-environments']?.[environmentName]?.variables?.splice(index, 1)\n}\n\nexport const environmentMutatorsFactory = ({\n workspace,\n collection,\n}: {\n workspace: Workspace | null\n collection: WorkspaceDocument | Workspace | null\n}) => {\n return {\n upsertEnvironment: (payload: Event<'environment:upsert:environment'>) =>\n upsertEnvironment(workspace, collection, payload),\n deleteEnvironment: (payload: Event<'environment:delete:environment'>) =>\n deleteEnvironment(workspace, collection, payload),\n upsertEnvironmentVariable: (payload: Event<'environment:upsert:environment-variable'>) =>\n upsertEnvironmentVariable(collection, payload),\n deleteEnvironmentVariable: (payload: Event<'environment:delete:environment-variable'>) =>\n deleteEnvironmentVariable(collection, payload),\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAyB;AAElC;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAcrB,MAAM,oBAAoB,CAC/B,WACA,YACA,EAAE,iBAAiB,SAAS,mBAAmB,MACZ;AAEnC,MAAI,CAAC,cAAc,CAAC,WAAW;AAC7B;AAAA,EACF;AAEA,MAAI,CAAC,WAAW,uBAAuB,GAAG;AACxC,eAAW,uBAAuB,IAAI,CAAC;AAAA,EACzC;AAGA,QAAM,mBAAmB,CAAC,WAAW,uBAAuB,EAAE,sBAAsB,eAAe;AAGnG,QAAM,SAAS,YAAY,0BAA0B;AAAA,IACnD,GAAG,kBAAkB,WAAW,uBAAuB,EAAE,sBAAsB,eAAe,GAAG,EAAE,OAAO,EAAE,CAAC;AAAA,IAC7G,GAAG;AAAA,EACL,CAAC;AACD,aAAW,uBAAuB,EAAE,eAAe,IAAI;AAGvD,MAAI,sBAAsB,uBAAuB,iBAAiB;AAChE,WAAO,WAAW,uBAAuB,EAAE,kBAAkB;AAG7D,QAAI,UAAU,6BAA6B,MAAM,oBAAoB;AACnE,gBAAU,6BAA6B,IAAI;AAAA,IAC7C;AAAA,EACF;AAGA,MAAI,kBAAkB;AACpB,cAAU,6BAA6B,IAAI;AAAA,EAC7C;AAEA,SAAO;AACT;
|
|
4
|
+
"sourcesContent": ["import type { EnvironmentEvents } from '@/events/definitions/environment'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport type { Workspace, WorkspaceDocument } from '@/schemas'\nimport {\n type XScalarEnvVar,\n type XScalarEnvironment,\n xScalarEnvVarSchema,\n xScalarEnvironmentSchema,\n} from '@/schemas/extensions/document/x-scalar-environments'\nimport { coerceValue } from '@/schemas/typebox-coerce'\n\ntype Event<T extends keyof EnvironmentEvents> = Omit<EnvironmentEvents[T], 'collectionType'>\n\n/**\n * Adds OR updates an environment to the document or workspace.\n *\n * @param document - current document if available\n * @param workspace - current workspace if available\n * @param environmentName - Name of the environment to add\n * @param payload - The environment configuration to add\n * @param oldEnvironmentName - Only needed when renaming the environment\n * @returns the parsed environment that was added or updated or undefined if the collection is not found\n */\nexport const upsertEnvironment = (\n workspace: Workspace | null,\n collection: WorkspaceDocument | Workspace | null,\n { environmentName, payload, oldEnvironmentName }: Event<'environment:upsert:environment'>,\n): XScalarEnvironment | undefined => {\n /** Discriminating between document and workspace */\n if (!collection || !workspace) {\n return\n }\n\n if (!collection['x-scalar-environments']) {\n collection['x-scalar-environments'] = {}\n }\n\n // Check if this is a new environment before we create it\n const isNewEnvironment = !collection['x-scalar-environments'][oldEnvironmentName ?? environmentName]\n\n // Ensure we parse the payload but keep the old variables\n const parsed = coerceValue(xScalarEnvironmentSchema, {\n ...unpackProxyObject(collection['x-scalar-environments'][oldEnvironmentName ?? environmentName], { depth: 1 }),\n ...payload,\n })\n collection['x-scalar-environments'][environmentName] = parsed\n\n // If we are renaming the environment, we need to delete the old one\n if (oldEnvironmentName && oldEnvironmentName !== environmentName) {\n delete collection['x-scalar-environments'][oldEnvironmentName]\n\n // If the old environment was active, we need to set the new environment as active\n if (workspace['x-scalar-active-environment'] === oldEnvironmentName) {\n workspace['x-scalar-active-environment'] = environmentName\n }\n }\n\n // Set the newly created workspace environment as active\n if (isNewEnvironment) {\n workspace['x-scalar-active-environment'] = environmentName\n }\n\n return parsed\n}\n\n/**\n * Deletes an environment from the given collection and handles active environment state.\n *\n * @param workspace - The workspace object, or null if unavailable.\n * @param collection - The workspace document or workspace object, or null if unavailable.\n * @param environmentName - The name of the environment to delete.\n */\nexport const deleteEnvironment = (\n workspace: Workspace | null,\n collection: WorkspaceDocument | Workspace | null,\n { environmentName }: Event<'environment:delete:environment'>,\n) => {\n if (!collection || !workspace) {\n return\n }\n\n // Trigegr the change event for the active environment\n delete collection['x-scalar-environments']?.[environmentName]\n}\n\n/**\n * Adds OR updates an environment variable to the document or workspace.\n *\n * @param collection - Workspace OR document\n * @param environmentName - Name of the environment to add the variable to\n * @param variableName - Name of the variable to add\n * @param value - Value of the variable to add\n * @returns the parsed variable that was added or updated or undefined if the collection is not found\n */\nexport const upsertEnvironmentVariable = (\n collection: WorkspaceDocument | Workspace | null,\n { environmentName, variable, index }: Event<'environment:upsert:environment-variable'>,\n): XScalarEnvVar | undefined => {\n // The environment should exist by now if we are upserting a variable\n if (!collection?.['x-scalar-environments']?.[environmentName]) {\n console.error('Environment not found', environmentName)\n return\n }\n\n // Ensure we parse the variable for type safety\n const parsed = coerceValue(xScalarEnvVarSchema, variable)\n\n if (index !== undefined) {\n // Delete the row if the name is empty\n if (parsed.name === '') {\n collection['x-scalar-environments'][environmentName].variables.splice(index, 1)\n return\n }\n\n // Update\n collection['x-scalar-environments'][environmentName].variables[index] = parsed\n }\n // Add\n else {\n collection['x-scalar-environments'][environmentName].variables.push(parsed)\n }\n\n return parsed\n}\n\nexport const deleteEnvironmentVariable = (\n collection: WorkspaceDocument | Workspace | null,\n { environmentName, index }: Event<'environment:delete:environment-variable'>,\n) => {\n if (!collection?.['x-scalar-environments']?.[environmentName]) {\n console.error('Environment not found', environmentName)\n return\n }\n collection['x-scalar-environments']?.[environmentName]?.variables?.splice(index, 1)\n}\n\nexport const environmentMutatorsFactory = ({\n workspace,\n collection,\n}: {\n workspace: Workspace | null\n collection: WorkspaceDocument | Workspace | null\n}) => {\n return {\n upsertEnvironment: (payload: Event<'environment:upsert:environment'>) =>\n upsertEnvironment(workspace, collection, payload),\n deleteEnvironment: (payload: Event<'environment:delete:environment'>) =>\n deleteEnvironment(workspace, collection, payload),\n upsertEnvironmentVariable: (payload: Event<'environment:upsert:environment-variable'>) =>\n upsertEnvironmentVariable(collection, payload),\n deleteEnvironmentVariable: (payload: Event<'environment:delete:environment-variable'>) =>\n deleteEnvironmentVariable(collection, payload),\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,yBAAyB;AAElC;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAcrB,MAAM,oBAAoB,CAC/B,WACA,YACA,EAAE,iBAAiB,SAAS,mBAAmB,MACZ;AAEnC,MAAI,CAAC,cAAc,CAAC,WAAW;AAC7B;AAAA,EACF;AAEA,MAAI,CAAC,WAAW,uBAAuB,GAAG;AACxC,eAAW,uBAAuB,IAAI,CAAC;AAAA,EACzC;AAGA,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AAC,aAAa,uBAAuB,IAAI,eAAe,GAAG;AAC7D,YAAQ,MAAM,yBAAyB,eAAe;AACtD;AAAA,EACF;AACA,aAAW,uBAAuB,IAAI,eAAe,GAAG,WAAW,OAAO,OAAO,CAAC;AACpF;AAEO,MAAM,6BAA6B,CAAC;AAAA,EACzC;AAAA,EACA;AACF,MAGM;AACJ,SAAO;AAAA,IACL,mBAAmB,CAAC,YAClB,kBAAkB,WAAW,YAAY,OAAO;AAAA,IAClD,mBAAmB,CAAC,YAClB,kBAAkB,WAAW,YAAY,OAAO;AAAA,IAClD,2BAA2B,CAAC,YAC1B,0BAA0B,YAAY,OAAO;AAAA,IAC/C,2BAA2B,CAAC,YAC1B,0BAA0B,YAAY,OAAO;AAAA,EACjD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/mutators/index.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ export declare function generateClientMutators(store: WorkspaceStore | null): {
|
|
|
96
96
|
deleteOperation: (payload: import("../events/index.js").OperationEvents["operation:delete:operation"]) => void;
|
|
97
97
|
createOperationDraftExample: (payload: import("../events/index.js").OperationEvents["operation:create:draft-example"]) => void;
|
|
98
98
|
deleteOperationExample: (payload: import("../events/index.js").OperationEvents["operation:delete:example"]) => void;
|
|
99
|
+
renameOperationExample: (payload: import("../events/index.js").OperationEvents["operation:rename:example"]) => void;
|
|
99
100
|
updateOperationExtension: (payload: import("../events/index.js").OperationEvents["operation:update:extension"]) => void;
|
|
100
101
|
updateOperationExtraParameters: (payload: import("../events/index.js").OperationEvents["operation:update:extra-parameters"]) => void;
|
|
101
102
|
upsertOperationParameter: (payload: import("../events/index.js").OperationEvents["operation:upsert:parameter"]) => void;
|
|
@@ -181,6 +182,7 @@ export declare function generateClientMutators(store: WorkspaceStore | null): {
|
|
|
181
182
|
deleteOperation: (payload: import("../events/index.js").OperationEvents["operation:delete:operation"]) => void;
|
|
182
183
|
createOperationDraftExample: (payload: import("../events/index.js").OperationEvents["operation:create:draft-example"]) => void;
|
|
183
184
|
deleteOperationExample: (payload: import("../events/index.js").OperationEvents["operation:delete:example"]) => void;
|
|
185
|
+
renameOperationExample: (payload: import("../events/index.js").OperationEvents["operation:rename:example"]) => void;
|
|
184
186
|
updateOperationExtension: (payload: import("../events/index.js").OperationEvents["operation:update:extension"]) => void;
|
|
185
187
|
updateOperationExtraParameters: (payload: import("../events/index.js").OperationEvents["operation:update:extra-parameters"]) => void;
|
|
186
188
|
upsertOperationParameter: (payload: import("../events/index.js").OperationEvents["operation:upsert:parameter"]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAa9C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAqC/D;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;OAGG
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mutators/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAa9C;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAqC/D;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;OAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEH;;;;OAIG;gBACS,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAErB"}
|
|
@@ -1,13 +1,49 @@
|
|
|
1
1
|
import type { ParameterObject } from '../../../schemas/v3.1/strict/parameter.js';
|
|
2
2
|
import type { ReferenceType } from '../../../schemas/v3.1/strict/reference.js';
|
|
3
|
+
export type MinimalParameterObject = Pick<ParameterObject, 'name' | 'in'>;
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Synchronizes path parameters when a path string changes.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Behavior:
|
|
8
|
+
* - Preserves as much of the existing parameter configuration as possible when the set of path variables
|
|
9
|
+
* changes due to a path update.
|
|
10
|
+
* - If a parameter with the same name exists in the new path, its configuration is preserved.
|
|
11
|
+
* - If a parameter appears at the same position as an old parameter (name changed), the old parameter's
|
|
12
|
+
* configuration is kept and its name is updated in place via the resolved object.
|
|
13
|
+
* - Any newly required parameters (variables present in the new path but not in the old path) are added
|
|
14
|
+
* as new minimal parameter objects.
|
|
15
|
+
* - Parameters that are no longer present in the new path are dropped.
|
|
16
|
+
* - Non-path parameters (query, header, etc.) from `existingParameters` are included unchanged in the result.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ This function mutates parameter objects in the `existingParameters` array in place when a path
|
|
19
|
+
* parameter is renamed (i.e., reused objects may have their `name` updated via `resolve`).
|
|
20
|
+
*
|
|
21
|
+
* Returns the full new parameters array. Use the return value directly as the new operation.parameters.
|
|
22
|
+
*
|
|
23
|
+
* @param newPath - The path string after the change (e.g. '/users/{id}/posts/{postId}').
|
|
24
|
+
* @param oldPath - The path string before the change (e.g. '/users/{userId}').
|
|
25
|
+
* @param existingParameters - Current operation parameters (may be refs); path params are synced, others passed through.
|
|
26
|
+
* @param resolve - Callback to resolve a reference to a minimal parameter object (used for reading and mutating).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Given:
|
|
31
|
+
* // - oldPath: '/users/{userId}'
|
|
32
|
+
* // - newPath: '/users/{id}/posts/{postId}'
|
|
33
|
+
* // - existingParameters: [ { name: 'userId', in: 'path' } ]
|
|
34
|
+
*
|
|
35
|
+
* const newParams = syncParametersForPathChange(
|
|
36
|
+
* '/users/{id}/posts/{postId}',
|
|
37
|
+
* '/users/{userId}',
|
|
38
|
+
* existingParameters,
|
|
39
|
+
* (node) => resolveRef(node) // or unwrap $ref to get { name, in }
|
|
40
|
+
* )
|
|
41
|
+
*
|
|
42
|
+
* // existingParameters[0] was mutated in place (name -> 'id' via resolve).
|
|
43
|
+
* // newParams is the full array: [ renamed path param 'id', new path param 'postId' ]
|
|
44
|
+
*
|
|
45
|
+
* operation.parameters = newParams
|
|
46
|
+
* ```
|
|
11
47
|
*/
|
|
12
|
-
export declare const syncParametersForPathChange: (newPath: string, oldPath: string, existingParameters: ReferenceType<
|
|
48
|
+
export declare const syncParametersForPathChange: <T extends MinimalParameterObject>(newPath: string, oldPath: string, existingParameters: ReferenceType<T>[], resolve: (node: ReferenceType<T>) => MinimalParameterObject) => ReferenceType<T>[];
|
|
13
49
|
//# sourceMappingURL=sync-path-parameters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-path-parameters.d.ts","sourceRoot":"","sources":["../../../../src/mutators/operation/helpers/sync-path-parameters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sync-path-parameters.d.ts","sourceRoot":"","sources":["../../../../src/mutators/operation/helpers/sync-path-parameters.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAGpE,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,sBAAsB,EAC1E,SAAS,MAAM,EACf,SAAS,MAAM,EACf,oBAAoB,aAAa,CAAC,CAAC,CAAC,EAAE,EACtC,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,sBAAsB,KAC1D,aAAa,CAAC,CAAC,CAAC,EAmFlB,CAAA"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { findVariables } from "@scalar/helpers/regex/find-variables";
|
|
2
|
-
import { getResolvedRef } from "../../../helpers/get-resolved-ref.js";
|
|
3
2
|
import { unpackProxyObject } from "../../../helpers/unpack-proxy.js";
|
|
4
3
|
import { getParameterPositions } from "../../../mutators/operation/helpers/get-parameter-position.js";
|
|
5
|
-
const syncParametersForPathChange = (newPath, oldPath, existingParameters) => {
|
|
4
|
+
const syncParametersForPathChange = (newPath, oldPath, existingParameters, resolve) => {
|
|
6
5
|
const oldPathParams = findVariables(oldPath, { includePath: true, includeEnv: false }).filter(
|
|
7
6
|
(v) => v !== void 0
|
|
8
7
|
);
|
|
@@ -11,47 +10,53 @@ const syncParametersForPathChange = (newPath, oldPath, existingParameters) => {
|
|
|
11
10
|
);
|
|
12
11
|
const oldPositions = getParameterPositions(oldPath, oldPathParams);
|
|
13
12
|
const newPositions = getParameterPositions(newPath, newPathParams);
|
|
14
|
-
const pathParameters =
|
|
15
|
-
const nonPathParameters = [];
|
|
13
|
+
const pathParameters = /* @__PURE__ */ Object.create(null);
|
|
16
14
|
for (const param of existingParameters) {
|
|
17
|
-
const resolved =
|
|
15
|
+
const resolved = resolve(param);
|
|
18
16
|
if (resolved?.in === "path") {
|
|
19
|
-
pathParameters.
|
|
20
|
-
} else {
|
|
21
|
-
nonPathParameters.push(param);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const existingPathParamsByName = /* @__PURE__ */ new Map();
|
|
25
|
-
for (const param of pathParameters) {
|
|
26
|
-
if (param.name) {
|
|
27
|
-
existingPathParamsByName.set(param.name, param);
|
|
17
|
+
pathParameters[resolved.name] = param;
|
|
28
18
|
}
|
|
29
19
|
}
|
|
30
20
|
const usedOldParams = /* @__PURE__ */ new Set();
|
|
31
|
-
const
|
|
21
|
+
const usedPathParameters = /* @__PURE__ */ new Set();
|
|
22
|
+
const newPathParameters = [];
|
|
32
23
|
for (const newParamName of newPathParams) {
|
|
33
|
-
if (
|
|
34
|
-
syncedPathParameters.push(existingPathParamsByName.get(newParamName));
|
|
24
|
+
if (pathParameters[newParamName]) {
|
|
35
25
|
usedOldParams.add(newParamName);
|
|
26
|
+
usedPathParameters.add(pathParameters[newParamName]);
|
|
36
27
|
continue;
|
|
37
28
|
}
|
|
38
29
|
const newParamPosition = newPositions[newParamName];
|
|
39
30
|
const oldParamAtPosition = oldPathParams.find(
|
|
40
31
|
(oldParam) => oldPositions[oldParam] === newParamPosition && !usedOldParams.has(oldParam)
|
|
41
32
|
);
|
|
42
|
-
if (oldParamAtPosition &&
|
|
43
|
-
const oldParam =
|
|
44
|
-
oldParam
|
|
45
|
-
|
|
33
|
+
if (oldParamAtPosition && pathParameters[oldParamAtPosition] !== void 0) {
|
|
34
|
+
const oldParam = pathParameters[oldParamAtPosition];
|
|
35
|
+
if (oldParam) {
|
|
36
|
+
resolve(oldParam).name = newParamName;
|
|
37
|
+
usedPathParameters.add(oldParam);
|
|
38
|
+
}
|
|
46
39
|
usedOldParams.add(oldParamAtPosition);
|
|
47
40
|
continue;
|
|
48
41
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
newPathParameters.push({
|
|
43
|
+
in: "path",
|
|
44
|
+
name: newParamName
|
|
52
45
|
});
|
|
53
46
|
}
|
|
54
|
-
|
|
47
|
+
const result = [];
|
|
48
|
+
for (const param of existingParameters) {
|
|
49
|
+
const resolved = resolve(param);
|
|
50
|
+
const rawParam = unpackProxyObject(param, { depth: 1 });
|
|
51
|
+
if (resolved?.in !== "path") {
|
|
52
|
+
result.push(rawParam);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (usedPathParameters.has(param)) {
|
|
56
|
+
result.push(rawParam);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result.concat(newPathParameters);
|
|
55
60
|
};
|
|
56
61
|
export {
|
|
57
62
|
syncParametersForPathChange
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/mutators/operation/helpers/sync-path-parameters.ts"],
|
|
4
|
-
"sourcesContent": ["import { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport { getParameterPositions } from '@/mutators/operation/helpers/get-parameter-position'\nimport type { ParameterObject } from '@/schemas/v3.1/strict/parameter'\nimport type { ReferenceType } from '@/schemas/v3.1/strict/reference'\n\n// We use a minimal parameter object becuase we use this function during bundling and we don't want to prevalidate the parameters\nexport type MinimalParameterObject = Pick<ParameterObject, 'name' | 'in'>\n\n/**\n * Synchronizes path parameters when a path string changes.\n *\n * Behavior:\n * - Preserves as much of the existing parameter configuration as possible when the set of path variables\n * changes due to a path update.\n * - If a parameter with the same name exists in the new path, its configuration is preserved.\n * - If a parameter appears at the same position as an old parameter (name changed), the old parameter's\n * configuration is kept and its name is updated in place via the resolved object.\n * - Any newly required parameters (variables present in the new path but not in the old path) are added\n * as new minimal parameter objects.\n * - Parameters that are no longer present in the new path are dropped.\n * - Non-path parameters (query, header, etc.) from `existingParameters` are included unchanged in the result.\n *\n * \u26A0\uFE0F This function mutates parameter objects in the `existingParameters` array in place when a path\n * parameter is renamed (i.e., reused objects may have their `name` updated via `resolve`).\n *\n * Returns the full new parameters array. Use the return value directly as the new operation.parameters.\n *\n * @param newPath - The path string after the change (e.g. '/users/{id}/posts/{postId}').\n * @param oldPath - The path string before the change (e.g. '/users/{userId}').\n * @param existingParameters - Current operation parameters (may be refs); path params are synced, others passed through.\n * @param resolve - Callback to resolve a reference to a minimal parameter object (used for reading and mutating).\n *\n * @example\n * ```ts\n * // Given:\n * // - oldPath: '/users/{userId}'\n * // - newPath: '/users/{id}/posts/{postId}'\n * // - existingParameters: [ { name: 'userId', in: 'path' } ]\n *\n * const newParams = syncParametersForPathChange(\n * '/users/{id}/posts/{postId}',\n * '/users/{userId}',\n * existingParameters,\n * (node) => resolveRef(node) // or unwrap $ref to get { name, in }\n * )\n *\n * // existingParameters[0] was mutated in place (name -> 'id' via resolve).\n * // newParams is the full array: [ renamed path param 'id', new path param 'postId' ]\n *\n * operation.parameters = newParams\n * ```\n */\nexport const syncParametersForPathChange = <T extends MinimalParameterObject>(\n newPath: string,\n oldPath: string,\n existingParameters: ReferenceType<T>[],\n resolve: (node: ReferenceType<T>) => MinimalParameterObject,\n): ReferenceType<T>[] => {\n // Extract path parameter names from both paths\n const oldPathParams = findVariables(oldPath, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newPathParams = findVariables(newPath, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n const oldPositions = getParameterPositions(oldPath, oldPathParams)\n const newPositions = getParameterPositions(newPath, newPathParams)\n\n // Keep a map of path parameters by name for quick lookup (references unchanged objects)\n const pathParameters: Record<string, ReferenceType<T>> = Object.create(null)\n\n // Populate the map with the existing path parameters\n for (const param of existingParameters) {\n const resolved = resolve(param)\n if (resolved?.in === 'path') {\n pathParameters[resolved.name] = param\n }\n }\n\n // Keep track of old parameters that we have already used\n const usedOldParams = new Set<string>()\n // Keep track of path parameter objects we keep after sync\n const usedPathParameters = new Set<ReferenceType<T>>()\n // These are only truly new parameters created in this run\n const newPathParameters: T[] = []\n\n for (const newParamName of newPathParams) {\n // Case 1: Parameter with same name exists - preserve its config, and mark as used\n if (pathParameters[newParamName]) {\n usedOldParams.add(newParamName)\n usedPathParameters.add(pathParameters[newParamName])\n continue\n }\n\n // Case 2: Check for parameter at same position (likely a rename)\n const newParamPosition = newPositions[newParamName]\n const oldParamAtPosition = oldPathParams.find(\n (oldParam) => oldPositions[oldParam] === newParamPosition && !usedOldParams.has(oldParam),\n )\n\n // If found, mutate old parameter's name and mark as used\n if (oldParamAtPosition && pathParameters[oldParamAtPosition] !== undefined) {\n const oldParam = pathParameters[oldParamAtPosition]\n if (oldParam) {\n // Change its name in-place\n resolve(oldParam).name = newParamName\n usedPathParameters.add(oldParam)\n }\n usedOldParams.add(oldParamAtPosition)\n continue\n }\n\n // Case 3: New parameter - create a new minimal parameter object\n newPathParameters.push({\n in: 'path',\n name: newParamName,\n } as T)\n }\n\n const result: ReferenceType<T>[] = []\n\n // Push the raw parameters to enure we are not pushing proxies\n for (const param of existingParameters) {\n const resolved = resolve(param)\n const rawParam = unpackProxyObject(param, { depth: 1 })\n if (resolved?.in !== 'path') {\n result.push(rawParam)\n continue\n }\n\n // Only adda the parameter if HAS not been used in the old path\n // This we we ensure to drop parameters that are no longer present in the new path\n if (usedPathParameters.has(param)) {\n result.push(rawParam)\n }\n }\n\n // Only return newly created parameter objects\u2014call site should combine with possibly-mutated originals\n return result.concat(newPathParameters)\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,yBAAyB;AAClC,SAAS,6BAA6B;AAmD/B,MAAM,8BAA8B,CACzC,SACA,SACA,oBACA,YACuB;AAEvB,QAAM,gBAAgB,cAAc,SAAS,EAAE,aAAa,MAAM,YAAY,MAAM,CAAC,EAAE;AAAA,IACrF,CAAC,MAAmB,MAAM;AAAA,EAC5B;AACA,QAAM,gBAAgB,cAAc,SAAS,EAAE,aAAa,MAAM,YAAY,MAAM,CAAC,EAAE;AAAA,IACrF,CAAC,MAAmB,MAAM;AAAA,EAC5B;AAEA,QAAM,eAAe,sBAAsB,SAAS,aAAa;AACjE,QAAM,eAAe,sBAAsB,SAAS,aAAa;AAGjE,QAAM,iBAAmD,uBAAO,OAAO,IAAI;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 export declare const operationMutatorsFactory: ({ document, store, }: {
|
|
|
12
12
|
deleteOperation: (payload: OperationEvents["operation:delete:operation"]) => void;
|
|
13
13
|
createOperationDraftExample: (payload: OperationEvents["operation:create:draft-example"]) => void;
|
|
14
14
|
deleteOperationExample: (payload: OperationEvents["operation:delete:example"]) => void;
|
|
15
|
+
renameOperationExample: (payload: OperationEvents["operation:rename:example"]) => void;
|
|
15
16
|
updateOperationExtension: (payload: OperationEvents["operation:update:extension"]) => void;
|
|
16
17
|
updateOperationExtraParameters: (payload: OperationEvents["operation:update:extra-parameters"]) => void;
|
|
17
18
|
upsertOperationParameter: (payload: OperationEvents["operation:upsert:parameter"]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mutators/operation/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/mutators/operation/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAuBrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD,eAAO,MAAM,wBAAwB,GAAI,sBAGtC;IACD,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAA;CAC7B;+BAE8B,eAAe,CAAC,4BAA4B,CAAC;mCACzC,eAAe,CAAC,uBAAuB,CAAC;yCAElC,eAAe,CAAC,6BAA6B,CAAC;+BAExD,eAAe,CAAC,4BAA4B,CAAC;2CACjC,eAAe,CAAC,gCAAgC,CAAC;sCAEtD,eAAe,CAAC,0BAA0B,CAAC;sCAE3C,eAAe,CAAC,0BAA0B,CAAC;wCAEzC,eAAe,CAAC,4BAA4B,CAAC;8CAEvC,eAAe,CAAC,mCAAmC,CAAC;wCAE1D,eAAe,CAAC,4BAA4B,CAAC;wCAE7C,eAAe,CAAC,4BAA4B,CAAC;4CAEzC,eAAe,CAAC,iCAAiC,CAAC;qDAEzC,eAAe,CAAC,0CAA0C,CAAC;iDAE/D,eAAe,CAAC,oCAAoC,CAAC;mDAEnD,eAAe,CAAC,wCAAwC,CAAC;oCAExE,WAAW,CAAC,2BAA2B,CAAC;sCAEtC,eAAe,CAAC,0BAA0B,CAAC;CAGhF,CAAA"}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createOperationDraftExample,
|
|
11
11
|
deleteOperation,
|
|
12
12
|
deleteOperationExample,
|
|
13
|
+
renameOperationExample,
|
|
13
14
|
updateOperationMeta,
|
|
14
15
|
updateOperationPathMethod
|
|
15
16
|
} from "../../mutators/operation/operation.js";
|
|
@@ -30,6 +31,7 @@ const operationMutatorsFactory = ({
|
|
|
30
31
|
deleteOperation: (payload) => deleteOperation(store, payload),
|
|
31
32
|
createOperationDraftExample: (payload) => createOperationDraftExample(store, payload),
|
|
32
33
|
deleteOperationExample: (payload) => deleteOperationExample(store, payload),
|
|
34
|
+
renameOperationExample: (payload) => renameOperationExample(store, payload),
|
|
33
35
|
updateOperationExtension: (payload) => updateOperationExtension(document, payload),
|
|
34
36
|
updateOperationExtraParameters: (payload) => updateOperationExtraParameters(document, payload),
|
|
35
37
|
upsertOperationParameter: (payload) => upsertOperationParameter(document, payload),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/mutators/operation/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type { WorkspaceStore } from '@/client'\nimport type { HooksEvents } from '@/events/definitions/hooks'\nimport type { OperationEvents } from '@/events/definitions/operation'\nimport {\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormValue,\n} from '@/mutators/operation/body'\nimport { updateOperationExtension } from '@/mutators/operation/extensions'\nimport { addResponseToHistory, reloadOperationHistory } from '@/mutators/operation/history'\nimport {\n createOperation,\n createOperationDraftExample,\n deleteOperation,\n deleteOperationExample,\n updateOperationMeta,\n updateOperationPathMethod,\n} from '@/mutators/operation/operation'\nimport {\n deleteAllOperationParameters,\n deleteOperationParameter,\n updateOperationExtraParameters,\n upsertOperationParameter,\n} from '@/mutators/operation/parameters'\nimport type { WorkspaceDocument } from '@/schemas'\n\nexport const operationMutatorsFactory = ({\n document,\n store,\n}: {\n document: WorkspaceDocument | null\n store: WorkspaceStore | null\n}) => {\n return {\n createOperation: (payload: OperationEvents['operation:create:operation']) => createOperation(store, payload),\n updateOperationMeta: (payload: OperationEvents['operation:update:meta']) =>\n updateOperationMeta(store, document, payload),\n updateOperationPathMethod: (payload: OperationEvents['operation:update:pathMethod']) =>\n updateOperationPathMethod(document, store, payload),\n deleteOperation: (payload: OperationEvents['operation:delete:operation']) => deleteOperation(store, payload),\n createOperationDraftExample: (payload: OperationEvents['operation:create:draft-example']) =>\n createOperationDraftExample(store, payload),\n deleteOperationExample: (payload: OperationEvents['operation:delete:example']) =>\n deleteOperationExample(store, payload),\n updateOperationExtension: (payload: OperationEvents['operation:update:extension']) =>\n updateOperationExtension(document, payload),\n updateOperationExtraParameters: (payload: OperationEvents['operation:update:extra-parameters']) =>\n updateOperationExtraParameters(document, payload),\n upsertOperationParameter: (payload: OperationEvents['operation:upsert:parameter']) =>\n upsertOperationParameter(document, payload),\n deleteOperationParameter: (payload: OperationEvents['operation:delete:parameter']) =>\n deleteOperationParameter(document, payload),\n deleteAllOperationParameters: (payload: OperationEvents['operation:delete-all:parameters']) =>\n deleteAllOperationParameters(document, payload),\n updateOperationRequestBodyContentType: (payload: OperationEvents['operation:update:requestBody:contentType']) =>\n updateOperationRequestBodyContentType(document, payload),\n updateOperationRequestBodyExample: (payload: OperationEvents['operation:update:requestBody:value']) =>\n updateOperationRequestBodyExample(document, payload),\n updateOperationRequestBodyFormValue: (payload: OperationEvents['operation:update:requestBody:formValue']) =>\n updateOperationRequestBodyFormValue(document, payload),\n addResponseToHistory: (payload: HooksEvents['hooks:on:request:complete']) =>\n addResponseToHistory(store, document, payload),\n reloadOperationHistory: (payload: OperationEvents['operation:reload:history']) =>\n reloadOperationHistory(store, document, payload),\n }\n}\n"],
|
|
5
|
-
"mappings": "AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB,8BAA8B;AAC7D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,MAAM,2BAA2B,CAAC;AAAA,EACvC;AAAA,EACA;AACF,MAGM;AACJ,SAAO;AAAA,IACL,iBAAiB,CAAC,YAA2D,gBAAgB,OAAO,OAAO;AAAA,IAC3G,qBAAqB,CAAC,YACpB,oBAAoB,OAAO,UAAU,OAAO;AAAA,IAC9C,2BAA2B,CAAC,YAC1B,0BAA0B,UAAU,OAAO,OAAO;AAAA,IACpD,iBAAiB,CAAC,YAA2D,gBAAgB,OAAO,OAAO;AAAA,IAC3G,6BAA6B,CAAC,YAC5B,4BAA4B,OAAO,OAAO;AAAA,IAC5C,wBAAwB,CAAC,YACvB,uBAAuB,OAAO,OAAO;AAAA,IACvC,0BAA0B,CAAC,YACzB,yBAAyB,UAAU,OAAO;AAAA,IAC5C,gCAAgC,CAAC,YAC/B,+BAA+B,UAAU,OAAO;AAAA,IAClD,0BAA0B,CAAC,YACzB,yBAAyB,UAAU,OAAO;AAAA,IAC5C,0BAA0B,CAAC,YACzB,yBAAyB,UAAU,OAAO;AAAA,IAC5C,8BAA8B,CAAC,YAC7B,6BAA6B,UAAU,OAAO;AAAA,IAChD,uCAAuC,CAAC,YACtC,sCAAsC,UAAU,OAAO;AAAA,IACzD,mCAAmC,CAAC,YAClC,kCAAkC,UAAU,OAAO;AAAA,IACrD,qCAAqC,CAAC,YACpC,oCAAoC,UAAU,OAAO;AAAA,IACvD,sBAAsB,CAAC,YACrB,qBAAqB,OAAO,UAAU,OAAO;AAAA,IAC/C,wBAAwB,CAAC,YACvB,uBAAuB,OAAO,UAAU,OAAO;AAAA,EACnD;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { WorkspaceStore } from '@/client'\nimport type { HooksEvents } from '@/events/definitions/hooks'\nimport type { OperationEvents } from '@/events/definitions/operation'\nimport {\n updateOperationRequestBodyContentType,\n updateOperationRequestBodyExample,\n updateOperationRequestBodyFormValue,\n} from '@/mutators/operation/body'\nimport { updateOperationExtension } from '@/mutators/operation/extensions'\nimport { addResponseToHistory, reloadOperationHistory } from '@/mutators/operation/history'\nimport {\n createOperation,\n createOperationDraftExample,\n deleteOperation,\n deleteOperationExample,\n renameOperationExample,\n updateOperationMeta,\n updateOperationPathMethod,\n} from '@/mutators/operation/operation'\nimport {\n deleteAllOperationParameters,\n deleteOperationParameter,\n updateOperationExtraParameters,\n upsertOperationParameter,\n} from '@/mutators/operation/parameters'\nimport type { WorkspaceDocument } from '@/schemas'\n\nexport const operationMutatorsFactory = ({\n document,\n store,\n}: {\n document: WorkspaceDocument | null\n store: WorkspaceStore | null\n}) => {\n return {\n createOperation: (payload: OperationEvents['operation:create:operation']) => createOperation(store, payload),\n updateOperationMeta: (payload: OperationEvents['operation:update:meta']) =>\n updateOperationMeta(store, document, payload),\n updateOperationPathMethod: (payload: OperationEvents['operation:update:pathMethod']) =>\n updateOperationPathMethod(document, store, payload),\n deleteOperation: (payload: OperationEvents['operation:delete:operation']) => deleteOperation(store, payload),\n createOperationDraftExample: (payload: OperationEvents['operation:create:draft-example']) =>\n createOperationDraftExample(store, payload),\n deleteOperationExample: (payload: OperationEvents['operation:delete:example']) =>\n deleteOperationExample(store, payload),\n renameOperationExample: (payload: OperationEvents['operation:rename:example']) =>\n renameOperationExample(store, payload),\n updateOperationExtension: (payload: OperationEvents['operation:update:extension']) =>\n updateOperationExtension(document, payload),\n updateOperationExtraParameters: (payload: OperationEvents['operation:update:extra-parameters']) =>\n updateOperationExtraParameters(document, payload),\n upsertOperationParameter: (payload: OperationEvents['operation:upsert:parameter']) =>\n upsertOperationParameter(document, payload),\n deleteOperationParameter: (payload: OperationEvents['operation:delete:parameter']) =>\n deleteOperationParameter(document, payload),\n deleteAllOperationParameters: (payload: OperationEvents['operation:delete-all:parameters']) =>\n deleteAllOperationParameters(document, payload),\n updateOperationRequestBodyContentType: (payload: OperationEvents['operation:update:requestBody:contentType']) =>\n updateOperationRequestBodyContentType(document, payload),\n updateOperationRequestBodyExample: (payload: OperationEvents['operation:update:requestBody:value']) =>\n updateOperationRequestBodyExample(document, payload),\n updateOperationRequestBodyFormValue: (payload: OperationEvents['operation:update:requestBody:formValue']) =>\n updateOperationRequestBodyFormValue(document, payload),\n addResponseToHistory: (payload: HooksEvents['hooks:on:request:complete']) =>\n addResponseToHistory(store, document, payload),\n reloadOperationHistory: (payload: OperationEvents['operation:reload:history']) =>\n reloadOperationHistory(store, document, payload),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAGA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB,8BAA8B;AAC7D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGA,MAAM,2BAA2B,CAAC;AAAA,EACvC;AAAA,EACA;AACF,MAGM;AACJ,SAAO;AAAA,IACL,iBAAiB,CAAC,YAA2D,gBAAgB,OAAO,OAAO;AAAA,IAC3G,qBAAqB,CAAC,YACpB,oBAAoB,OAAO,UAAU,OAAO;AAAA,IAC9C,2BAA2B,CAAC,YAC1B,0BAA0B,UAAU,OAAO,OAAO;AAAA,IACpD,iBAAiB,CAAC,YAA2D,gBAAgB,OAAO,OAAO;AAAA,IAC3G,6BAA6B,CAAC,YAC5B,4BAA4B,OAAO,OAAO;AAAA,IAC5C,wBAAwB,CAAC,YACvB,uBAAuB,OAAO,OAAO;AAAA,IACvC,wBAAwB,CAAC,YACvB,uBAAuB,OAAO,OAAO;AAAA,IACvC,0BAA0B,CAAC,YACzB,yBAAyB,UAAU,OAAO;AAAA,IAC5C,gCAAgC,CAAC,YAC/B,+BAA+B,UAAU,OAAO;AAAA,IAClD,0BAA0B,CAAC,YACzB,yBAAyB,UAAU,OAAO;AAAA,IAC5C,0BAA0B,CAAC,YACzB,yBAAyB,UAAU,OAAO;AAAA,IAC5C,8BAA8B,CAAC,YAC7B,6BAA6B,UAAU,OAAO;AAAA,IAChD,uCAAuC,CAAC,YACtC,sCAAsC,UAAU,OAAO;AAAA,IACzD,mCAAmC,CAAC,YAClC,kCAAkC,UAAU,OAAO;AAAA,IACrD,qCAAqC,CAAC,YACpC,oCAAoC,UAAU,OAAO;AAAA,IACvD,sBAAsB,CAAC,YACrB,qBAAqB,OAAO,UAAU,OAAO;AAAA,IAC/C,wBAAwB,CAAC,YACvB,uBAAuB,OAAO,UAAU,OAAO;AAAA,EACnD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -79,4 +79,16 @@ export declare const createOperationDraftExample: (workspace: WorkspaceStore | n
|
|
|
79
79
|
* - Safely no-ops if the document, operation, or request body does not exist.
|
|
80
80
|
*/
|
|
81
81
|
export declare const deleteOperationExample: (workspace: WorkspaceStore | null, { meta: { path, method, exampleKey }, documentName }: OperationEvents["operation:delete:example"]) => void;
|
|
82
|
+
/**
|
|
83
|
+
* Renames an example key for an operation across all operation-level example containers:
|
|
84
|
+
* - `x-draft-examples`
|
|
85
|
+
* - parameter-level examples
|
|
86
|
+
* - parameter content-level examples
|
|
87
|
+
* - request-body content examples
|
|
88
|
+
* - request-body selected-content-type map
|
|
89
|
+
*
|
|
90
|
+
* If the target example name already exists in any container, this is a no-op to avoid
|
|
91
|
+
* accidental data overwrites.
|
|
92
|
+
*/
|
|
93
|
+
export declare const renameOperationExample: (workspace: WorkspaceStore | null, { meta: { path, method, exampleKey }, documentName, payload }: OperationEvents["operation:rename:example"]) => void;
|
|
82
94
|
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/mutators/operation/operation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAOrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,cAAc,GAAG,IAAI,EACrC,SAAS,eAAe,CAAC,4BAA4B,CAAC,KACrD,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/mutators/operation/operation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAOrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,GAC1B,gBAAgB,cAAc,GAAG,IAAI,EACrC,SAAS,eAAe,CAAC,4BAA4B,CAAC,KACrD,MAAM,GAAG,SA0DX,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAC9B,OAAO,cAAc,GAAG,IAAI,EAC5B,UAAU,iBAAiB,GAAG,IAAI,EAClC,mBAAmB,eAAe,CAAC,uBAAuB,CAAC,SAsB5D,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,yBAAyB,GACpC,UAAU,iBAAiB,GAAG,IAAI,EAClC,OAAO,cAAc,GAAG,IAAI,EAC5B,+CAA+C,eAAe,CAAC,6BAA6B,CAAC,KAC5F,IAgGF,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,GAC1B,WAAW,cAAc,GAAG,IAAI,EAChC,wBAAwB,eAAe,CAAC,4BAA4B,CAAC,SAgBtE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GACtC,WAAW,cAAc,GAAG,IAAI,EAChC,uDAAuD,eAAe,CAAC,gCAAgC,CAAC,SAuBzG,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,WAAW,cAAc,GAAG,IAAI,EAChC,sDAAsD,eAAe,CAAC,0BAA0B,CAAC,SAiDlG,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GACjC,WAAW,cAAc,GAAG,IAAI,EAChC,+DAA+D,eAAe,CAAC,0BAA0B,CAAC,SAuE3G,CAAA"}
|
|
@@ -37,9 +37,10 @@ const createOperation = (workspaceStore, payload) => {
|
|
|
37
37
|
if (firstServer) {
|
|
38
38
|
document["x-scalar-selected-server"] = firstServer.url;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const existingParameters = operation.parameters;
|
|
41
|
+
const result = syncParametersForPathChange(normalizedPath, normalizedPath, existingParameters ?? [], getResolvedRef);
|
|
42
|
+
if (existingParameters !== void 0 || result.length > 0) {
|
|
43
|
+
operation.parameters = result;
|
|
43
44
|
}
|
|
44
45
|
payload.callback?.(true);
|
|
45
46
|
return normalizedPath;
|
|
@@ -92,7 +93,8 @@ const updateOperationPathMethod = (document, store, { meta, payload: { method, p
|
|
|
92
93
|
);
|
|
93
94
|
if (oldPathParams.length > 0 || newPathParams.length > 0) {
|
|
94
95
|
const existingParameters = operation.parameters ?? [];
|
|
95
|
-
|
|
96
|
+
const result = syncParametersForPathChange(finalPath, meta.path, existingParameters, getResolvedRef);
|
|
97
|
+
operation.parameters = result;
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
const { generateId } = getNavigationOptions(documentNavigation.name);
|
|
@@ -182,11 +184,67 @@ const deleteOperationExample = (workspace, { meta: { path, method, exampleKey },
|
|
|
182
184
|
delete mediaType.examples?.[exampleKey];
|
|
183
185
|
});
|
|
184
186
|
};
|
|
187
|
+
const renameOperationExample = (workspace, { meta: { path, method, exampleKey }, documentName, payload }) => {
|
|
188
|
+
const document = workspace?.workspace.documents[documentName];
|
|
189
|
+
if (!document) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const operation = getResolvedRef(document.paths?.[path]?.[method]);
|
|
193
|
+
if (!operation) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const nextExampleName = payload.name.trim();
|
|
197
|
+
if (!nextExampleName || nextExampleName === exampleKey) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
preventPollution(nextExampleName);
|
|
201
|
+
const records = [];
|
|
202
|
+
operation.parameters?.forEach((parameter) => {
|
|
203
|
+
const resolvedParameter = getResolvedRef(parameter);
|
|
204
|
+
if ("examples" in resolvedParameter && resolvedParameter.examples) {
|
|
205
|
+
records.push(resolvedParameter.examples);
|
|
206
|
+
}
|
|
207
|
+
if ("content" in resolvedParameter && resolvedParameter.content) {
|
|
208
|
+
Object.values(resolvedParameter.content).forEach((mediaType) => {
|
|
209
|
+
if (mediaType.examples) {
|
|
210
|
+
records.push(mediaType.examples);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const requestBody = getResolvedRef(operation.requestBody);
|
|
216
|
+
if (requestBody) {
|
|
217
|
+
Object.values(requestBody.content ?? {}).forEach((mediaType) => {
|
|
218
|
+
if (mediaType.examples) {
|
|
219
|
+
records.push(mediaType.examples);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
if (requestBody["x-scalar-selected-content-type"]) {
|
|
223
|
+
records.push(requestBody["x-scalar-selected-content-type"]);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (operation["x-draft-examples"]?.includes(nextExampleName) || records.some((record) => Object.hasOwn(record, nextExampleName))) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (operation["x-draft-examples"]) {
|
|
230
|
+
operation["x-draft-examples"] = operation["x-draft-examples"].map(
|
|
231
|
+
(name) => name === exampleKey ? nextExampleName : name
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
records.forEach((record) => {
|
|
235
|
+
if (!Object.hasOwn(record, exampleKey)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
record[nextExampleName] = unpackProxyObject(record[exampleKey]);
|
|
239
|
+
delete record[exampleKey];
|
|
240
|
+
});
|
|
241
|
+
};
|
|
185
242
|
export {
|
|
186
243
|
createOperation,
|
|
187
244
|
createOperationDraftExample,
|
|
188
245
|
deleteOperation,
|
|
189
246
|
deleteOperationExample,
|
|
247
|
+
renameOperationExample,
|
|
190
248
|
updateOperationMeta,
|
|
191
249
|
updateOperationPathMethod
|
|
192
250
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/mutators/operation/operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport { isHttpMethod } from '@scalar/helpers/http/is-http-method'\nimport { preventPollution } from '@scalar/helpers/object/prevent-pollution'\nimport { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { WorkspaceStore } from '@/client'\nimport type { OperationEvents } from '@/events/definitions/operation'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport { syncParametersForPathChange } from '@/mutators/operation/helpers/sync-path-parameters'\nimport { getOperationEntries } from '@/navigation'\nimport { getNavigationOptions } from '@/navigation/get-navigation-options'\nimport { updateOrderIds } from '@/navigation/helpers/update-order-ids'\nimport type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Creates a new operation at a specific path and method in the document.\n * Automatically normalizes the path to ensure it starts with a slash.\n *\n * Returns the normalized path if successful, undefined otherwise.\n *\n * Example:\n * ```ts\n * createOperation(\n * document,\n * 'users',\n * 'get',\n * { tags: ['Users'] },\n * )\n * ```\n */\nexport const createOperation = (\n workspaceStore: WorkspaceStore | null,\n payload: OperationEvents['operation:create:operation'],\n): string | undefined => {\n const document = workspaceStore?.workspace.documents[payload.documentName]\n if (!document) {\n payload.callback?.(false)\n return undefined\n }\n\n const { path, method, operation } = payload\n\n /** Ensure the path starts with a slash */\n const normalizedPath = path.startsWith('/') ? path : `/${path}`\n\n /** Create the operation in the document */\n if (!document.paths) {\n document.paths = {}\n }\n\n if (!document.paths[normalizedPath]) {\n document.paths[normalizedPath] = {}\n }\n\n /** Prevent pollution of the path and method */\n preventPollution(normalizedPath)\n preventPollution(method)\n\n /** Create the operation in the document */\n document.paths[normalizedPath][method] = operation\n\n // Make sure that we are selecting the new operation server\n const { servers } = operation\n const firstServer = unpackProxyObject(servers?.[0])\n\n // For now we only support document servers but in the future we might support operation servers\n for (const server of servers ?? []) {\n // If the server does not exist in the document, add it\n if (!document.servers?.some((s) => s.url === server.url)) {\n if (!document.servers) {\n document.servers = []\n }\n document.servers.push(unpackProxyObject(server))\n }\n }\n\n // Update the selected server to the first server of the created operation\n if (firstServer) {\n document['x-scalar-selected-server'] = firstServer.url\n }\n\n // Sync path variables\n const newParameters = syncParametersForPathChange(normalizedPath, normalizedPath, operation.parameters ?? [])\n if (newParameters.length > 0) {\n operation.parameters = newParameters\n }\n\n payload.callback?.(true)\n return normalizedPath\n}\n\n/**\n * Updates the `description` of an operation.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationDescription(\n * document,\n * { meta: { method: 'get', path: '/users' }, payload: { description: 'Get a single user' },\n * })\n * ```\n */\nexport const updateOperationMeta = (\n store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { meta, payload }: OperationEvents['operation:update:meta'],\n) => {\n if (!document || !store) {\n return\n }\n\n const documentName = document['x-scalar-navigation']?.name\n if (documentName === undefined) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method as HttpMethod])\n if (!operation) {\n console.error('Operation not found', { meta, document })\n return\n }\n\n // Update the description of the operation\n Object.assign(operation, payload)\n\n // Rebuild the sidebar to reflect the cahnges\n store.buildSidebar(documentName)\n}\n\n/**\n * Updates the HTTP method and/or path of an operation and moves it to the new location.\n * This function:\n * 1. Moves the operation from the old method/path to the new method/path under paths\n * 2. Updates x-scalar-order to maintain the operation's position in the sidebar\n * 3. Syncs path parameters when the path changes\n *\n * Safely no-ops if nothing has changed, or if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationPathMethod({\n * document,\n * store,\n * meta: { method: 'get', path: '/users' },\n * payload: { method: 'post', path: '/api/users' },\n * })\n * ```\n */\nexport const updateOperationPathMethod = (\n document: WorkspaceDocument | null,\n store: WorkspaceStore | null,\n { meta, payload: { method, path }, callback }: OperationEvents['operation:update:pathMethod'],\n): void => {\n const methodChanged = meta.method !== method\n const pathChanged = meta.path !== path\n\n // If nothing has changed, no need to do anything\n if (!methodChanged && !pathChanged) {\n callback('no-change')\n return\n }\n\n // Determine the final method and path\n const finalMethod = methodChanged ? method : meta.method\n const finalPath = pathChanged ? path : meta.path\n\n // Check for conflicts at the target location\n if (document?.paths?.[finalPath]?.[finalMethod as HttpMethod]) {\n callback('conflict')\n return\n }\n\n const documentNavigation = document?.['x-scalar-navigation']\n if (!documentNavigation || !store) {\n console.error('Document or workspace not found', { document })\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method as HttpMethod])\n if (!operation) {\n console.error('Operation not found', { meta, document })\n return\n }\n\n // Sync path parameters if the path has changed\n if (pathChanged) {\n const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newPathParams = findVariables(finalPath, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n if (oldPathParams.length > 0 || newPathParams.length > 0) {\n const existingParameters = operation.parameters ?? []\n operation.parameters = syncParametersForPathChange(finalPath, meta.path, existingParameters)\n }\n }\n\n /**\n * We don't pass navigation options as we don't have config on the client,\n * and we don't change path or method on the references\n */\n const { generateId } = getNavigationOptions(documentNavigation.name)\n\n /** Grabs all of the current operation entries for the given path and method */\n const operationEntriesMap = getOperationEntries(documentNavigation)\n const entries = operationEntriesMap.get(`${meta.path}|${meta.method}`)\n\n // Updates the order ID so we don't lose the sidebar ordering when it rebuilds\n if (entries) {\n updateOrderIds({ store, operation, generateId, method: finalMethod, path: finalPath, entries })\n }\n\n // Initialize the paths object if it does not exist\n if (!document.paths) {\n document.paths = {}\n }\n\n // Initialize the new path if it does not exist\n if (!document.paths[finalPath]) {\n document.paths[finalPath] = {}\n }\n\n // Prevent assigning dangerous keys to the path items object\n preventPollution(finalPath)\n preventPollution(meta.path)\n preventPollution(finalMethod)\n\n // Move the operation to the new location\n document.paths[finalPath][finalMethod] = unpackProxyObject(operation)\n\n // Remove the operation from the old location\n const oldPathItems = document.paths[meta.path]\n if (oldPathItems && isHttpMethod(meta.method)) {\n delete oldPathItems[meta.method]\n\n // If the old path has no more operations, remove the path entry\n if (Object.keys(oldPathItems).length === 0) {\n delete document.paths[meta.path]\n }\n }\n\n // We need to reset the history for the operation when the path or method changes\n store.history.clearOperationHistory(document['x-scalar-navigation']?.name ?? '', meta.path, meta.method)\n\n callback('success')\n}\n\n/**\n * Deletes an operation from the workspace\n *\n * Example:\n * ```ts\n * deleteOperation({\n * document,\n * meta: { method: 'get', path: '/users' },\n * })\n * ```\n */\nexport const deleteOperation = (\n workspace: WorkspaceStore | null,\n { meta, documentName }: OperationEvents['operation:delete:operation'],\n) => {\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n return\n }\n\n preventPollution(meta.path)\n preventPollution(meta.method)\n\n delete document.paths?.[meta.path]?.[meta.method]\n\n // If the path has no more operations, remove the path entry\n if (Object.keys(document.paths?.[meta.path] ?? {}).length === 0) {\n delete document.paths?.[meta.path]\n }\n}\n\n/**\n * Adds an example name to the 'x-draft-examples' array for a specific operation in a document.\n *\n * - Finds the target operation using the provided path and method within the specified document.\n * - If the operation is found and has an 'x-draft-examples' array, pushes the new exampleName to it.\n * - Safely no-ops if the document or operation does not exist.\n */\nexport const createOperationDraftExample = (\n workspace: WorkspaceStore | null,\n { meta: { path, method }, documentName, exampleName }: OperationEvents['operation:create:draft-example'],\n) => {\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n console.error('Document not found', { documentName })\n return\n }\n\n const operation = getResolvedRef(document.paths?.[path]?.[method])\n if (!operation) {\n console.error('Operation not found', { path, method })\n return\n }\n\n // Ensure that the x-draft-examples array exists\n operation['x-draft-examples'] ??= []\n\n // Remove duplicates\n const dedupe = new Set(operation['x-draft-examples'])\n // Add the new example name\n dedupe.add(exampleName)\n // Update the operation with the new x-draft-examples array\n operation['x-draft-examples'] = Array.from(dedupe)\n}\n\n/**\n * Deletes an example with the given exampleKey from operation parameters and request body.\n *\n * - Finds the target operation within the specified document and path/method.\n * - Removes example values matching exampleKey from both parameter-level and content-level examples.\n * - Safely no-ops if the document, operation, or request body does not exist.\n */\nexport const deleteOperationExample = (\n workspace: WorkspaceStore | null,\n { meta: { path, method, exampleKey }, documentName }: OperationEvents['operation:delete:example'],\n) => {\n // Find the document in workspace based on documentName\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n return\n }\n\n // Get the operation object for the given path and method\n const operation = getResolvedRef(document.paths?.[path]?.[method])\n if (!operation) {\n return\n }\n\n // Remove the example from the x-draft-examples array\n const dedupe = new Set(operation['x-draft-examples'] ?? [])\n dedupe.delete(exampleKey)\n\n if (operation['x-draft-examples'] !== undefined) {\n operation['x-draft-examples'] = Array.from(dedupe)\n }\n\n // Remove the example from all operation parameters\n operation.parameters?.forEach((parameter) => {\n const resolvedParameter = getResolvedRef(parameter)\n\n // Remove from content-level examples (if parameter uses content)\n if ('content' in resolvedParameter && resolvedParameter.content) {\n Object.values(resolvedParameter.content).forEach((mediaType) => {\n delete mediaType.examples?.[exampleKey]\n })\n }\n\n // Remove from parameter-level examples\n if ('examples' in resolvedParameter && resolvedParameter.examples) {\n delete resolvedParameter.examples?.[exampleKey]\n }\n })\n\n // Remove the example from request body content types (if requestBody exists)\n const requestBody = getResolvedRef(operation.requestBody)\n if (!requestBody) {\n return\n }\n\n // For each media type, remove the example matching exampleKey\n Object.values(requestBody.content ?? {}).forEach((mediaType) => {\n delete mediaType.examples?.[exampleKey]\n })\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAI9B,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,mCAAmC;AAC5C,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAmBxB,MAAM,kBAAkB,CAC7B,gBACA,YACuB;AACvB,QAAM,WAAW,gBAAgB,UAAU,UAAU,QAAQ,YAAY;AACzE,MAAI,CAAC,UAAU;AACb,YAAQ,WAAW,KAAK;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,QAAQ,UAAU,IAAI;AAGpC,QAAM,iBAAiB,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAG7D,MAAI,CAAC,SAAS,OAAO;AACnB,aAAS,QAAQ,CAAC;AAAA,EACpB;AAEA,MAAI,CAAC,SAAS,MAAM,cAAc,GAAG;AACnC,aAAS,MAAM,cAAc,IAAI,CAAC;AAAA,EACpC;AAGA,mBAAiB,cAAc;AAC/B,mBAAiB,MAAM;AAGvB,WAAS,MAAM,cAAc,EAAE,MAAM,IAAI;AAGzC,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,cAAc,kBAAkB,UAAU,CAAC,CAAC;AAGlD,aAAW,UAAU,WAAW,CAAC,GAAG;AAElC,QAAI,CAAC,SAAS,SAAS,KAAK,CAAC,MAAM,EAAE,QAAQ,OAAO,GAAG,GAAG;AACxD,UAAI,CAAC,SAAS,SAAS;AACrB,iBAAS,UAAU,CAAC;AAAA,MACtB;AACA,eAAS,QAAQ,KAAK,kBAAkB,MAAM,CAAC;AAAA,IACjD;AAAA,EACF;AAGA,MAAI,aAAa;AACf,aAAS,0BAA0B,IAAI,YAAY;AAAA,EACrD;
|
|
4
|
+
"sourcesContent": ["import type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport { isHttpMethod } from '@scalar/helpers/http/is-http-method'\nimport { preventPollution } from '@scalar/helpers/object/prevent-pollution'\nimport { findVariables } from '@scalar/helpers/regex/find-variables'\n\nimport type { WorkspaceStore } from '@/client'\nimport type { OperationEvents } from '@/events/definitions/operation'\nimport { getResolvedRef } from '@/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@/helpers/unpack-proxy'\nimport { syncParametersForPathChange } from '@/mutators/operation/helpers/sync-path-parameters'\nimport { getOperationEntries } from '@/navigation'\nimport { getNavigationOptions } from '@/navigation/get-navigation-options'\nimport { updateOrderIds } from '@/navigation/helpers/update-order-ids'\nimport type { WorkspaceDocument } from '@/schemas'\n\n/**\n * Creates a new operation at a specific path and method in the document.\n * Automatically normalizes the path to ensure it starts with a slash.\n *\n * Returns the normalized path if successful, undefined otherwise.\n *\n * Example:\n * ```ts\n * createOperation(\n * document,\n * 'users',\n * 'get',\n * { tags: ['Users'] },\n * )\n * ```\n */\nexport const createOperation = (\n workspaceStore: WorkspaceStore | null,\n payload: OperationEvents['operation:create:operation'],\n): string | undefined => {\n const document = workspaceStore?.workspace.documents[payload.documentName]\n if (!document) {\n payload.callback?.(false)\n return undefined\n }\n\n const { path, method, operation } = payload\n\n /** Ensure the path starts with a slash */\n const normalizedPath = path.startsWith('/') ? path : `/${path}`\n\n /** Create the operation in the document */\n if (!document.paths) {\n document.paths = {}\n }\n\n if (!document.paths[normalizedPath]) {\n document.paths[normalizedPath] = {}\n }\n\n /** Prevent pollution of the path and method */\n preventPollution(normalizedPath)\n preventPollution(method)\n\n /** Create the operation in the document */\n document.paths[normalizedPath][method] = operation\n\n // Make sure that we are selecting the new operation server\n const { servers } = operation\n const firstServer = unpackProxyObject(servers?.[0])\n\n // For now we only support document servers but in the future we might support operation servers\n for (const server of servers ?? []) {\n // If the server does not exist in the document, add it\n if (!document.servers?.some((s) => s.url === server.url)) {\n if (!document.servers) {\n document.servers = []\n }\n document.servers.push(unpackProxyObject(server))\n }\n }\n\n // Update the selected server to the first server of the created operation\n if (firstServer) {\n document['x-scalar-selected-server'] = firstServer.url\n }\n\n const existingParameters = operation.parameters\n\n // Sync path variables\n const result = syncParametersForPathChange(normalizedPath, normalizedPath, existingParameters ?? [], getResolvedRef)\n if (existingParameters !== undefined || result.length > 0) {\n operation.parameters = result\n }\n\n payload.callback?.(true)\n return normalizedPath\n}\n\n/**\n * Updates the `description` of an operation.\n * Safely no-ops if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationDescription(\n * document,\n * { meta: { method: 'get', path: '/users' }, payload: { description: 'Get a single user' },\n * })\n * ```\n */\nexport const updateOperationMeta = (\n store: WorkspaceStore | null,\n document: WorkspaceDocument | null,\n { meta, payload }: OperationEvents['operation:update:meta'],\n) => {\n if (!document || !store) {\n return\n }\n\n const documentName = document['x-scalar-navigation']?.name\n if (documentName === undefined) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method as HttpMethod])\n if (!operation) {\n console.error('Operation not found', { meta, document })\n return\n }\n\n // Update the description of the operation\n Object.assign(operation, payload)\n\n // Rebuild the sidebar to reflect the cahnges\n store.buildSidebar(documentName)\n}\n\n/**\n * Updates the HTTP method and/or path of an operation and moves it to the new location.\n * This function:\n * 1. Moves the operation from the old method/path to the new method/path under paths\n * 2. Updates x-scalar-order to maintain the operation's position in the sidebar\n * 3. Syncs path parameters when the path changes\n *\n * Safely no-ops if nothing has changed, or if the document or operation does not exist.\n *\n * Example:\n * ```ts\n * updateOperationPathMethod({\n * document,\n * store,\n * meta: { method: 'get', path: '/users' },\n * payload: { method: 'post', path: '/api/users' },\n * })\n * ```\n */\nexport const updateOperationPathMethod = (\n document: WorkspaceDocument | null,\n store: WorkspaceStore | null,\n { meta, payload: { method, path }, callback }: OperationEvents['operation:update:pathMethod'],\n): void => {\n const methodChanged = meta.method !== method\n const pathChanged = meta.path !== path\n\n // If nothing has changed, no need to do anything\n if (!methodChanged && !pathChanged) {\n callback('no-change')\n return\n }\n\n // Determine the final method and path\n const finalMethod = methodChanged ? method : meta.method\n const finalPath = pathChanged ? path : meta.path\n\n // Check for conflicts at the target location\n if (document?.paths?.[finalPath]?.[finalMethod as HttpMethod]) {\n callback('conflict')\n return\n }\n\n const documentNavigation = document?.['x-scalar-navigation']\n if (!documentNavigation || !store) {\n console.error('Document or workspace not found', { document })\n return\n }\n\n const operation = getResolvedRef(document.paths?.[meta.path]?.[meta.method as HttpMethod])\n if (!operation) {\n console.error('Operation not found', { meta, document })\n return\n }\n\n // Sync path parameters if the path has changed\n if (pathChanged) {\n const oldPathParams = findVariables(meta.path, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n const newPathParams = findVariables(finalPath, { includePath: true, includeEnv: false }).filter(\n (v): v is string => v !== undefined,\n )\n\n if (oldPathParams.length > 0 || newPathParams.length > 0) {\n const existingParameters = operation.parameters ?? []\n const result = syncParametersForPathChange(finalPath, meta.path, existingParameters, getResolvedRef)\n operation.parameters = result\n }\n }\n\n /**\n * We don't pass navigation options as we don't have config on the client,\n * and we don't change path or method on the references\n */\n const { generateId } = getNavigationOptions(documentNavigation.name)\n\n /** Grabs all of the current operation entries for the given path and method */\n const operationEntriesMap = getOperationEntries(documentNavigation)\n const entries = operationEntriesMap.get(`${meta.path}|${meta.method}`)\n\n // Updates the order ID so we don't lose the sidebar ordering when it rebuilds\n if (entries) {\n updateOrderIds({ store, operation, generateId, method: finalMethod, path: finalPath, entries })\n }\n\n // Initialize the paths object if it does not exist\n if (!document.paths) {\n document.paths = {}\n }\n\n // Initialize the new path if it does not exist\n if (!document.paths[finalPath]) {\n document.paths[finalPath] = {}\n }\n\n // Prevent assigning dangerous keys to the path items object\n preventPollution(finalPath)\n preventPollution(meta.path)\n preventPollution(finalMethod)\n\n // Move the operation to the new location\n document.paths[finalPath][finalMethod] = unpackProxyObject(operation)\n\n // Remove the operation from the old location\n const oldPathItems = document.paths[meta.path]\n if (oldPathItems && isHttpMethod(meta.method)) {\n delete oldPathItems[meta.method]\n\n // If the old path has no more operations, remove the path entry\n if (Object.keys(oldPathItems).length === 0) {\n delete document.paths[meta.path]\n }\n }\n\n // We need to reset the history for the operation when the path or method changes\n store.history.clearOperationHistory(document['x-scalar-navigation']?.name ?? '', meta.path, meta.method)\n\n callback('success')\n}\n\n/**\n * Deletes an operation from the workspace\n *\n * Example:\n * ```ts\n * deleteOperation({\n * document,\n * meta: { method: 'get', path: '/users' },\n * })\n * ```\n */\nexport const deleteOperation = (\n workspace: WorkspaceStore | null,\n { meta, documentName }: OperationEvents['operation:delete:operation'],\n) => {\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n return\n }\n\n preventPollution(meta.path)\n preventPollution(meta.method)\n\n delete document.paths?.[meta.path]?.[meta.method]\n\n // If the path has no more operations, remove the path entry\n if (Object.keys(document.paths?.[meta.path] ?? {}).length === 0) {\n delete document.paths?.[meta.path]\n }\n}\n\n/**\n * Adds an example name to the 'x-draft-examples' array for a specific operation in a document.\n *\n * - Finds the target operation using the provided path and method within the specified document.\n * - If the operation is found and has an 'x-draft-examples' array, pushes the new exampleName to it.\n * - Safely no-ops if the document or operation does not exist.\n */\nexport const createOperationDraftExample = (\n workspace: WorkspaceStore | null,\n { meta: { path, method }, documentName, exampleName }: OperationEvents['operation:create:draft-example'],\n) => {\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n console.error('Document not found', { documentName })\n return\n }\n\n const operation = getResolvedRef(document.paths?.[path]?.[method])\n if (!operation) {\n console.error('Operation not found', { path, method })\n return\n }\n\n // Ensure that the x-draft-examples array exists\n operation['x-draft-examples'] ??= []\n\n // Remove duplicates\n const dedupe = new Set(operation['x-draft-examples'])\n // Add the new example name\n dedupe.add(exampleName)\n // Update the operation with the new x-draft-examples array\n operation['x-draft-examples'] = Array.from(dedupe)\n}\n\n/**\n * Deletes an example with the given exampleKey from operation parameters and request body.\n *\n * - Finds the target operation within the specified document and path/method.\n * - Removes example values matching exampleKey from both parameter-level and content-level examples.\n * - Safely no-ops if the document, operation, or request body does not exist.\n */\nexport const deleteOperationExample = (\n workspace: WorkspaceStore | null,\n { meta: { path, method, exampleKey }, documentName }: OperationEvents['operation:delete:example'],\n) => {\n // Find the document in workspace based on documentName\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n return\n }\n\n // Get the operation object for the given path and method\n const operation = getResolvedRef(document.paths?.[path]?.[method])\n if (!operation) {\n return\n }\n\n // Remove the example from the x-draft-examples array\n const dedupe = new Set(operation['x-draft-examples'] ?? [])\n dedupe.delete(exampleKey)\n\n if (operation['x-draft-examples'] !== undefined) {\n operation['x-draft-examples'] = Array.from(dedupe)\n }\n\n // Remove the example from all operation parameters\n operation.parameters?.forEach((parameter) => {\n const resolvedParameter = getResolvedRef(parameter)\n\n // Remove from content-level examples (if parameter uses content)\n if ('content' in resolvedParameter && resolvedParameter.content) {\n Object.values(resolvedParameter.content).forEach((mediaType) => {\n delete mediaType.examples?.[exampleKey]\n })\n }\n\n // Remove from parameter-level examples\n if ('examples' in resolvedParameter && resolvedParameter.examples) {\n delete resolvedParameter.examples?.[exampleKey]\n }\n })\n\n // Remove the example from request body content types (if requestBody exists)\n const requestBody = getResolvedRef(operation.requestBody)\n if (!requestBody) {\n return\n }\n\n // For each media type, remove the example matching exampleKey\n Object.values(requestBody.content ?? {}).forEach((mediaType) => {\n delete mediaType.examples?.[exampleKey]\n })\n}\n\n/**\n * Renames an example key for an operation across all operation-level example containers:\n * - `x-draft-examples`\n * - parameter-level examples\n * - parameter content-level examples\n * - request-body content examples\n * - request-body selected-content-type map\n *\n * If the target example name already exists in any container, this is a no-op to avoid\n * accidental data overwrites.\n */\nexport const renameOperationExample = (\n workspace: WorkspaceStore | null,\n { meta: { path, method, exampleKey }, documentName, payload }: OperationEvents['operation:rename:example'],\n) => {\n const document = workspace?.workspace.documents[documentName]\n if (!document) {\n return\n }\n\n const operation = getResolvedRef(document.paths?.[path]?.[method])\n if (!operation) {\n return\n }\n\n const nextExampleName = payload.name.trim()\n if (!nextExampleName || nextExampleName === exampleKey) {\n return\n }\n\n preventPollution(nextExampleName)\n\n const records: Record<string, unknown>[] = []\n\n operation.parameters?.forEach((parameter) => {\n const resolvedParameter = getResolvedRef(parameter)\n\n if ('examples' in resolvedParameter && resolvedParameter.examples) {\n records.push(resolvedParameter.examples)\n }\n\n if ('content' in resolvedParameter && resolvedParameter.content) {\n Object.values(resolvedParameter.content).forEach((mediaType) => {\n if (mediaType.examples) {\n records.push(mediaType.examples)\n }\n })\n }\n })\n\n const requestBody = getResolvedRef(operation.requestBody)\n if (requestBody) {\n Object.values(requestBody.content ?? {}).forEach((mediaType) => {\n if (mediaType.examples) {\n records.push(mediaType.examples)\n }\n })\n\n if (requestBody['x-scalar-selected-content-type']) {\n records.push(requestBody['x-scalar-selected-content-type'])\n }\n }\n\n if (\n operation['x-draft-examples']?.includes(nextExampleName) ||\n records.some((record) => Object.hasOwn(record, nextExampleName))\n ) {\n return\n }\n\n if (operation['x-draft-examples']) {\n operation['x-draft-examples'] = operation['x-draft-examples'].map((name) =>\n name === exampleKey ? nextExampleName : name,\n )\n }\n\n records.forEach((record) => {\n if (!Object.hasOwn(record, exampleKey)) {\n return\n }\n\n record[nextExampleName] = unpackProxyObject(record[exampleKey])\n delete record[exampleKey]\n })\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAI9B,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,mCAAmC;AAC5C,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAmBxB,MAAM,kBAAkB,CAC7B,gBACA,YACuB;AACvB,QAAM,WAAW,gBAAgB,UAAU,UAAU,QAAQ,YAAY;AACzE,MAAI,CAAC,UAAU;AACb,YAAQ,WAAW,KAAK;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,QAAQ,UAAU,IAAI;AAGpC,QAAM,iBAAiB,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI;AAG7D,MAAI,CAAC,SAAS,OAAO;AACnB,aAAS,QAAQ,CAAC;AAAA,EACpB;AAEA,MAAI,CAAC,SAAS,MAAM,cAAc,GAAG;AACnC,aAAS,MAAM,cAAc,IAAI,CAAC;AAAA,EACpC;AAGA,mBAAiB,cAAc;AAC/B,mBAAiB,MAAM;AAGvB,WAAS,MAAM,cAAc,EAAE,MAAM,IAAI;AAGzC,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,cAAc,kBAAkB,UAAU,CAAC,CAAC;AAGlD,aAAW,UAAU,WAAW,CAAC,GAAG;AAElC,QAAI,CAAC,SAAS,SAAS,KAAK,CAAC,MAAM,EAAE,QAAQ,OAAO,GAAG,GAAG;AACxD,UAAI,CAAC,SAAS,SAAS;AACrB,iBAAS,UAAU,CAAC;AAAA,MACtB;AACA,eAAS,QAAQ,KAAK,kBAAkB,MAAM,CAAC;AAAA,IACjD;AAAA,EACF;AAGA,MAAI,aAAa;AACf,aAAS,0BAA0B,I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AA,EAC1B,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse-document.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,qCAAqC,CAAA;AAElG,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAQ7E;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,EAAE,UAAU,eAAe,EAAE,UAAU,iBAAiB;;;;;;;
|
|
1
|
+
{"version":3,"file":"traverse-document.d.ts","sourceRoot":"","sources":["../../../src/navigation/helpers/traverse-document.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAwB,MAAM,qCAAqC,CAAA;AAElG,OAAO,KAAK,EAAqB,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAA;AAQ7E;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,EAAE,UAAU,eAAe,EAAE,UAAU,iBAAiB;;;;;;;CAoH5G,CAAA"}
|
|
@@ -86,10 +86,11 @@ const traverseDocument = (documentName, document, options) => {
|
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
document["x-scalar-order"] = unpackProxyObject(entries.map((entry) => entry.id));
|
|
89
|
+
const documentTitle = document.info?.title?.trim() || "Untitled Document";
|
|
89
90
|
return {
|
|
90
91
|
id: documentId,
|
|
91
92
|
type: "document",
|
|
92
|
-
title:
|
|
93
|
+
title: documentTitle,
|
|
93
94
|
name: documentName,
|
|
94
95
|
children: entries,
|
|
95
96
|
icon: document["x-scalar-icon"]
|