import type { CollectionType } from '@scalar/workspace-store/events'; import type { VariableEntry } from '@scalar/workspace-store/request-example'; import type { XScalarEnvVar } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'; /** * A single change to persist to the active environment in response to a script's * `pm.environment.set()` / `pm.environment.unset()`. Shapes mirror the workspace event * bus payloads (`environment:upsert:environment-variable` / `:delete:environment-variable`) * so the caller can emit each action directly. */ type EnvironmentPersistenceAction = { environmentName: string; } & CollectionType & ({ type: 'upsert'; variable: { name: string; value: string; }; index?: number; } | { type: 'delete'; index: number; }); /** * Resolve which environment variables a script changed and where to persist them. * * The active environment is a merge of workspace- and document-scoped variables: * `getActiveEnvironment` concatenates them as `[...workspaceVariables, ...documentVariables]`. * We use that ordering to map each changed variable back to the scope and index it came * from, so updates mutate the correct collection in place instead of creating duplicates. * New variables are added to whichever scope actually defines the active environment, so the * upsert target exists (the mutator no-ops when the environment is missing from a collection). * * Variables present before the scripts ran but gone afterwards were removed via * `pm.environment.unset()` and are emitted as deletes. Deletes splice the underlying array, * so they are ordered last and by descending index — an earlier splice must not invalidate the * index of a later one. Upserts run first because they replace in place without shifting. */ export declare const getEnvironmentPersistenceActions: ({ environmentName, seededVariables, scriptVariables, mergedVariables, documentVariables, environmentExistsOnDocument, }: { /** Name of the active environment being written to. */ environmentName: string; /** Environment values seeded into the store before the scripts ran. */ seededVariables: Record; /** Environment scope read back from the store after the scripts ran. */ scriptVariables: VariableEntry[] | Record; /** The merged (workspace + document) variables of the active environment. */ mergedVariables: XScalarEnvVar[]; /** The document-scoped variables of the active environment (appended last in the merge). */ documentVariables: XScalarEnvVar[]; /** Whether the active environment is defined on the document (vs. the workspace). */ environmentExistsOnDocument: boolean; }) => EnvironmentPersistenceAction[]; export {}; //# sourceMappingURL=persist-script-environment.d.ts.map