Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asafgardin committed Nov 14, 2024
1 parent 7c27f16 commit 36400f8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/APIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UnifiedResponse,
} from './types';
import { AI21EnvConfig } from './EnvConfig';
import { createFetchInstance } from 'envFetch';
import { createFetchInstance } from './runtime';
import { Fetch } from 'fetch';

const validatePositiveInteger = (name: string, n: unknown): number => {
Expand Down
1 change: 1 addition & 0 deletions src/Streaming/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Stream } from './Stream';
export { BrowserSSEDecoder, NodeSSEDecoder, SSEDecoder } from './SSEDecoder';
8 changes: 4 additions & 4 deletions src/fetch/BaseFetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AI21Error } from 'errors';
import { Stream } from 'Streaming';
import { FinalRequestOptions, UnifiedResponse } from 'types';
import { APIResponseProps } from 'types/API';
import { AI21Error } from '../errors';
import { Stream } from '../Streaming';
import { FinalRequestOptions, UnifiedResponse } from '../types';
import { APIResponseProps } from '../types/API';

export type APIResponse<T> = {
data?: T;
Expand Down
3 changes: 1 addition & 2 deletions src/fetch/BrowserFetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FinalRequestOptions, UnifiedResponse } from 'types';
import { Fetch } from './BaseFetch';
import { Stream } from 'Streaming';
import { BrowserSSEDecoder } from 'Streaming/SSEDecoder';
import { Stream, BrowserSSEDecoder } from '../Streaming';

export class BrowserFetch extends Fetch {
call(url: string, options: FinalRequestOptions): Promise<UnifiedResponse> {
Expand Down
3 changes: 1 addition & 2 deletions src/fetch/NodeFetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FinalRequestOptions, UnifiedResponse } from 'types';
import { Fetch } from './BaseFetch';
import { NodeSSEDecoder } from 'Streaming/SSEDecoder';
import { Stream } from 'Streaming';
import { Stream, NodeSSEDecoder } from '../Streaming';

export class NodeFetch extends Fetch {
async call(url: string, options: FinalRequestOptions): Promise<UnifiedResponse> {
Expand Down
15 changes: 12 additions & 3 deletions src/envFetch.ts → src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { BrowserFetch, Fetch, NodeFetch } from 'fetch';
import { BrowserFetch, Fetch, NodeFetch } from './fetch';


export const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';

/**
* A Web Worker is a background thread that runs JavaScript code separate from the main thread.
* Web Workers enable concurrent processing by:
* - Running CPU-intensive tasks without blocking the UI
* - Performing background operations like data fetching and processing
* - Operating independently from the main window context
*/
export const isWebWorker =
typeof self === 'object' &&
typeof self?.importScripts === 'function' &&
Expand All @@ -14,7 +23,7 @@ export const isNode =
export function createFetchInstance(): Fetch {
if (isBrowser || isWebWorker) {
return new BrowserFetch();
} else {
return new NodeFetch();
}

return new NodeFetch();
}

0 comments on commit 36400f8

Please sign in to comment.