Skip to content

Commit f1991ac

Browse files
committed
feat(core): expand RequestDefinition and implement writeHttpFile
Add optional description, bodyFile, formData, and directives fields to RequestDefinition so plugin-authored requests can be serialized via serializeDocument(). Implement the writeHttpFile CLI context method using the new serializer, replacing the previous stub.
1 parent b0150a2 commit f1991ac

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/app/src/cli.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ function createPluginCommand(
4545
const resolved = nodePath.resolve(projectRoot, path);
4646
await fs.writeFile(resolved, content, 'utf-8');
4747
},
48-
writeHttpFile: async (_name: string, _requests) => {
49-
// Simplified implementation
50-
throw new Error('writeHttpFile not implemented in CLI context');
48+
writeHttpFile: async (name: string, requests) => {
49+
const fs = await import('node:fs/promises');
50+
const nodePath = await import('node:path');
51+
const { serializeDocument } = await import('@t-req/core');
52+
const resolved = nodePath.resolve(projectRoot, name);
53+
const content = serializeDocument({ requests });
54+
await fs.mkdir(nodePath.dirname(resolved), { recursive: true });
55+
await fs.writeFile(resolved, content, 'utf-8');
5156
},
5257
parseCollection: async () => {
5358
throw new Error('parseCollection not implemented in CLI context');

packages/core/src/plugin/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { z } from 'zod';
22
import type { EngineEvent } from '../runtime/types';
3-
import type { ParsedRequest } from '../types';
3+
import type { FileReference, FormField, ParsedRequest } from '../types';
44

55
// ============================================================================
66
// Plugin Permissions
@@ -538,10 +538,14 @@ export interface CommandContext {
538538
*/
539539
export interface RequestDefinition {
540540
name?: string;
541+
description?: string;
541542
method: string;
542543
url: string;
543544
headers?: Record<string, string>;
544545
body?: string;
546+
bodyFile?: FileReference;
547+
formData?: FormField[];
548+
directives?: Array<{ name: string; value: string }>;
545549
}
546550

547551
/**

0 commit comments

Comments
 (0)