Files
Bingbing b266c3c6f1 feat(examples): add example model and authoring
## Background

A request can only keep its latest response, so a request/response pair worth keeping has nowhere to live. This adds an Example document: a full snapshot of a request and a response, stored next to the request, listed in the sidebar and edited in its own tab.

## Changes

- Add the `Example` model (`exp_` prefix) with zod schemas for the request snapshot, the response snapshot, the client patch and the sidebar summary. Register it with the database, type maps, tree metadata and sync flags, so examples can be duplicated and synchronized.
- Add `services.example` (list, get, list by parents, create, update, remove, duplicate, create from request) and expose examples from the workspace data service.
- Extend the workspace children cache with example summaries and add a per-example query that carries the bodies, so workspace-wide reads stay small. The database change listener refreshes or drops an open example.
- Export and import examples in v5 files, including the generated 5.1 schema, and include them in Git sync.
- Add the example route and editor: request pane reusing the HTTP editors, response pane, breadcrumb entry under the parent request and redirect for stale URLs.
- Add example rows to the sidebar with collapse, drag and drop and rename, and give the tab a code icon instead of a method badge.
- Cover the model, services, cache and file format with unit tests and add a smoke test.

Refs INS-3997
2026-10-29 16:39:38 +08:00

103 lines
4.8 KiB
TypeScript

import * as apiSpecService from './api-spec';
import * as appDataService from './app-data';
import * as caCertificateService from './ca-certificate';
import * as clientCertificateService from './client-certificate';
import * as cloudCredentialService from './cloud-credential';
import * as cookieJarService from './cookie-jar';
import * as environmentService from './environment';
import * as exampleService from './example';
import * as gitCredentialsService from './git-credentials';
import * as gitRepositoryService from './git-repository';
import * as grpcRequestService from './grpc-request';
import * as grpcRequestMetaService from './grpc-request-meta';
import * as helpersService from './helpers';
import * as mcpPayloadService from './mcp-payload';
import * as mcpRequestService from './mcp-request';
import * as mcpResponseService from './mcp-response';
import * as mockRouteService from './mock-route';
import * as mockServerService from './mock-server';
import * as oAuth2TokenService from './o-auth-2-token';
import * as organizationService from './organization';
import * as pluginDataService from './plugin-data';
import * as projectService from './project';
import * as projectLintRulesetService from './project-lint-ruleset';
import * as protoDirectoryService from './proto-directory';
import * as protoFileService from './proto-file';
import * as requestService from './request';
import * as requestGroupService from './request-group';
import * as requestGroupMetaService from './request-group-meta';
import * as requestMetaService from './request-meta';
import * as requestVersionService from './request-version';
import * as responseService from './response';
import * as runnerTestResultService from './runner-test-result';
import * as settingsService from './settings';
import * as socketIOPayloadService from './socket-io-payload';
import * as socketIORequestService from './socket-io-request';
import * as socketIORequestMetaService from './socket-io-request-meta';
import * as socketIOResponseService from './socket-io-response';
import * as statsService from './stats';
import * as unitTestService from './unit-test';
import * as unitTestResultService from './unit-test-result';
import * as unitTestSuiteService from './unit-test-suite';
import * as userSessionService from './user-session';
import * as webSocketPayloadService from './websocket-payload';
import * as webSocketRequestService from './websocket-request';
import * as webSocketRequestMetaService from './websocket-request-meta';
import * as webSocketResponseService from './websocket-response';
import * as workspaceService from './workspace';
import * as workspaceMetaService from './workspace-meta';
// Services are consumed from renderer via preload -> IPC (`ipcRenderer.invoke`), so this contract
// must stay async across runtimes even if a main-process implementation could be synchronous.
// `satisfies` keeps the original inferred type while still producing compile-time errors for sync actions.
export const servicesNodeImpl = {
apiSpec: apiSpecService,
caCertificate: caCertificateService,
clientCertificate: clientCertificateService,
cloudCredential: cloudCredentialService,
gitCredentials: gitCredentialsService,
gitRepository: gitRepositoryService,
mcpPayload: mcpPayloadService,
cookieJar: cookieJarService,
environment: environmentService,
example: exampleService,
mcpRequest: mcpRequestService,
mcpResponse: mcpResponseService,
oAuth2Token: oAuth2TokenService,
organization: organizationService,
pluginData: pluginDataService,
protoDirectory: protoDirectoryService,
protoFile: protoFileService,
request: requestService,
requestGroup: requestGroupService,
requestGroupMeta: requestGroupMetaService,
requestMeta: requestMetaService,
requestVersion: requestVersionService,
response: responseService,
runnerTestResult: runnerTestResultService,
project: projectService,
projectLintRuleset: projectLintRulesetService,
settings: settingsService,
stats: statsService,
userSession: userSessionService,
grpcRequest: grpcRequestService,
grpcRequestMeta: grpcRequestMetaService,
workspace: workspaceService,
workspaceMeta: workspaceMetaService,
appData: appDataService,
mockRoute: mockRouteService,
mockServer: mockServerService,
unitTest: unitTestService,
unitTestResult: unitTestResultService,
unitTestSuite: unitTestSuiteService,
socketIOPayload: socketIOPayloadService,
socketIORequest: socketIORequestService,
socketIORequestMeta: socketIORequestMetaService,
socketIOResponse: socketIOResponseService,
webSocketPayload: webSocketPayloadService,
webSocketRequest: webSocketRequestService,
webSocketRequestMeta: webSocketRequestMetaService,
webSocketResponse: webSocketResponseService,
helpers: helpersService,
} satisfies Record<string, Record<string, (...args: never[]) => Promise<unknown>>>;