-
Notifications
You must be signed in to change notification settings - Fork 0
🌿 Fern Regeneration -- November 3, 2025 #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| export function encodeAsFormParameter(value: unknown): Record<string, string> { | ||
| const stringified = toQueryString(value, { encode: false }); | ||
|
|
||
| const keyValuePairs = stringified.split("&").map((pair) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic that splits the query string (lines 4–11) is naive. If any key or value contains '=' or '&', this will break. Consider using a more robust parser or at least add a comment explaining the limitation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Greptile Summary
This PR adds file upload functionality to the SDK through automatic code generation. The main changes enable the uploadFile endpoint which accepts actual file uploads (PDF, Word, Excel, etc.) instead of pre-parsed text.
Key Changes
- New
uploadFilemethod inDocumentCatalogclient for direct file uploads to/v0/catalog/uploadFile - File handling infrastructure with
Uploadabletype supporting multiple file formats (buffers, streams, paths, blobs) - FormData wrapper for multipart/form-data requests with automatic stream-to-blob conversion
- Comprehensive test suite covering various file types and edge cases
- Version bump from 0.1.9 to 0.1.10
Technical Implementation
The implementation provides robust file handling across Node.js and browser environments:
- Type guards for detecting various file-like objects (Buffer, ArrayBuffer, Blob, File, ReadableStream, Node streams)
- Automatic file metadata extraction (filename from path, content type from File/Blob, content length)
- Cross-platform path handling (Unix and Windows)
- Stream-to-buffer conversion for both Node.js Readable and Web ReadableStream
Generated Code Quality
This is auto-generated code from Fern, following established patterns in the SDK. The implementation is comprehensive with proper error handling, type safety, and test coverage.
Confidence Score: 5/5
- This PR is safe to merge - auto-generated code with comprehensive test coverage
- Score of 5 reflects that this is auto-generated code from a mature code generator (Fern), implements a well-understood pattern (file uploads), includes comprehensive test coverage, and follows the existing SDK architecture consistently
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| src/core/file/types.ts | 5/5 | New type definitions for file uploads (Uploadable union type with FileLike, FromPath, WithMetadata) |
| src/core/file/file.ts | 5/5 | Core file handling utilities for processing various file types (buffers, streams, paths, blobs) |
| src/core/form-data-utils/FormDataWrapper.ts | 5/5 | FormData wrapper for multipart/form-data uploads with stream-to-blob conversion |
| src/api/resources/documentCatalog/client/Client.ts | 5/5 | New uploadFile method added for direct file uploads with form data support |
| src/api/resources/documentCatalog/client/requests/UploadFileRequest.ts | 5/5 | New request interface for file upload endpoint with comprehensive metadata fields |
| tests/unit/file/file.test.ts | 5/5 | Comprehensive tests for file handling utilities (buffers, arrays, streams, blobs, paths) |
| tests/unit/form-data-utils/formDataWrapper.test.ts | 5/5 | Tests for FormDataWrapper including stream handling and file uploads |
Sequence Diagram
sequenceDiagram
participant Client as User Code
participant DC as DocumentCatalog
participant FW as FormDataWrapper
participant FH as File Handler
participant API as Credal API
Client->>DC: uploadFile(request)
DC->>FW: newFormData()
activate FW
FW-->>DC: FormDataWrapper instance
deactivate FW
DC->>FW: appendFile("file", uploadable)
activate FW
FW->>FH: toMultipartDataPart(uploadable)
activate FH
alt File is path-based
FH->>FH: fs.createReadStream(path)
FH->>FH: tryGetFileSizeFromPath()
FH->>FH: getNameFromPath()
else File is FileLike object
FH->>FH: tryGetContentLengthFromFileLike()
FH->>FH: tryGetNameFromFileLike()
FH->>FH: tryGetContentTypeFromFileLike()
end
FH-->>FW: {data, filename, contentType}
deactivate FH
FW->>FW: convertToBlob(data)
alt Stream (Node.js or Web)
FW->>FW: streamToBuffer()
FW->>FW: new Blob(buffer)
else Already Blob/Buffer/ArrayBuffer
FW->>FW: new Blob(data)
end
FW->>FW: fd.append("file", blob, filename)
deactivate FW
DC->>FW: append metadata fields
Note over DC,FW: documentName, uploadAsUserEmail,<br/>documentExternalId, etc.
DC->>FW: getRequest()
FW-->>DC: {body: FormData, headers, duplex}
DC->>DC: Build request headers
Note over DC: Authorization, Content-Type<br/>from FormData
DC->>API: POST /v0/catalog/uploadFile
Note over DC,API: multipart/form-data with file + metadata
alt Success
API-->>DC: UploadDocumentResponse
DC-->>Client: HttpResponsePromise<UploadDocumentResponse>
else Error
API-->>DC: Error response
DC->>DC: Throw CredalError/CredalTimeoutError
DC-->>Client: Error thrown
end
21 files reviewed, no comments
This PR regenerates code to match the latest API Definition.