Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,917 changes: 2,016 additions & 6,901 deletions dist/typesense.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/typesense.min.js.map

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions doc/examples/server/querySuggestions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import "@babel/register";
/* eslint-disable @typescript-eslint/no-var-requires */
import Typesense from "../../../lib/Typesense.js";

// import axios from "axios";
// import curlirize from "axios-curlirize";

const masterApiKey = "xyz";

const typesense = new Typesense.Client({
Expand All @@ -23,8 +20,6 @@ const typesense = new Typesense.Client({
apiKey: masterApiKey,
});

// curlirize(axios);

async function runExample() {
await deleteDataFromPreviousRuns();
try {
Expand Down
10 changes: 4 additions & 6 deletions doc/examples/server/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ require("@babel/register");

const Typesense = require("../../../lib/Typesense");

// If you need to use a custom agent:
// const { Agent: HTTPAgent } = require("http");
// const { Agent: HTTPSAgent } = require("https");
// If you need custom Node connection pooling, use an Undici dispatcher:
// const { Agent } = require("undici");

// Create a client
const typesense = new Typesense.Client({
Expand Down Expand Up @@ -46,9 +45,8 @@ const typesense = new Typesense.Client({
healthcheckIntervalSeconds: 2,
logLevel: "debug",

// If you need to use a custom agent:
// httpAgent: new HTTPAgent({ keepAlive: true }),
// httpsAgent: new HTTPSAgent({ keepAlive: true }),
// If you need custom Node connection pooling:
// dispatcher: new Agent({ keepAliveTimeout: 10_000 }),
});

let schema = {
Expand Down
14 changes: 6 additions & 8 deletions doc/examples/server/stopwords.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import "@babel/register";
/* eslint-disable @typescript-eslint/no-var-requires */
import Typesense from "../../../lib/Typesense.js";

// import axios from "axios";
// import curlirize from "axios-curlirize";

// Create a client
const typesense = new Typesense.Client({
nodes: [
Expand Down Expand Up @@ -60,8 +57,6 @@ let documents = [
},
];

// curlirize(axios);

async function runExample() {
try {
// Delete if the collection already exists from a previous example run
Expand Down Expand Up @@ -91,7 +86,7 @@ async function runExample() {

// retrieve stopword set
result = await typesense.stopwords("common-words").retrieve();
console.dir(result), { depth: null };
(console.dir(result), { depth: null });

// retrieve all stopword sets
result = await typesense.stopwords().retrieve();
Expand All @@ -104,9 +99,12 @@ async function runExample() {
.search({
q: "the acme",
query_by: "company_name",
stopwords: "common-words"
stopwords: "common-words",
});
console.dir(searchResults.hits.map(h => h.highlight), { depth: null });
console.dir(
searchResults.hits.map((h) => h.highlight),
{ depth: null },
);
} catch (error) {
console.dir(error, { depth: null });
} finally {
Expand Down
1 change: 1 addition & 0 deletions lib/Typesense.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type * from "./Typesense/AnalyticsRules";
export type * from "./Typesense/Collection";
export type * from "./Typesense/Collections";
export type * from "./Typesense/Configuration";
export type * from "./Typesense/Transport";
export type * from "./Typesense/Conversations";
export type * from "./Typesense/Conversation";
export type * from "./Typesense/ConversationModel";
Expand Down
29 changes: 16 additions & 13 deletions lib/Typesense/ApiCall.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import type { AxiosRequestConfig, AxiosResponse, Method } from "axios";
import { Logger } from "loglevel";
import Configuration from "./Configuration";
import type { NodeConfiguration, StreamConfig } from "./Configuration";
import TypesenseError from "./Errors/TypesenseError";
import type { DocumentSchema } from "./Documents";
import { RequestMethod, ResponseType, TypesenseResponse } from "./Transport";
interface Node extends NodeConfiguration {
isHealthy: boolean;
index: string | number;
}
export interface HttpClient {
get<T>(endpoint: string, queryParameters: Record<string, unknown>, { abortSignal, responseType, streamConfig, isStreamingRequest, }: {
abortSignal?: AbortSignal | null;
responseType?: AxiosRequestConfig["responseType"] | undefined;
responseType?: ResponseType | undefined;
streamConfig?: StreamConfig<T extends DocumentSchema ? T : DocumentSchema> | undefined;
isStreamingRequest: boolean | undefined;
}): Promise<T>;
delete<T>(endpoint: string, queryParameters: Record<string, unknown>): Promise<T>;
post<T>(endpoint: string, bodyParameters: unknown, queryParameters: Record<string, unknown>, additionalHeaders: Record<string, string>, { abortSignal, responseType, streamConfig, isStreamingRequest, }: {
abortSignal?: AbortSignal | null;
responseType?: AxiosRequestConfig["responseType"] | undefined;
responseType?: ResponseType | undefined;
streamConfig?: StreamConfig<T extends DocumentSchema ? T : DocumentSchema> | undefined;
isStreamingRequest: boolean | undefined;
}): Promise<T>;
Expand All @@ -36,31 +36,31 @@ export default class ApiCall implements HttpClient {
private readonly sendApiKeyAsQueryParam?;
private readonly numRetriesPerRequest;
private readonly additionalUserHeaders?;
private readonly transport;
readonly logger: Logger;
private currentNodeIndex;
constructor(configuration: Configuration);
get<T>(endpoint: string, queryParameters?: any, { abortSignal, responseType, streamConfig, isStreamingRequest, }?: {
abortSignal?: any;
responseType?: AxiosRequestConfig["responseType"] | undefined;
responseType?: ResponseType | undefined;
streamConfig?: StreamConfig<T extends DocumentSchema ? T : DocumentSchema> | undefined;
isStreamingRequest?: boolean | undefined;
}): Promise<T>;
delete<T>(endpoint: string, queryParameters?: any): Promise<T>;
post<T>(endpoint: string, bodyParameters?: any, queryParameters?: any, additionalHeaders?: any, { abortSignal, responseType, streamConfig, isStreamingRequest, }?: {
abortSignal?: AbortSignal | null;
responseType?: AxiosRequestConfig["responseType"] | undefined;
responseType?: ResponseType | undefined;
streamConfig?: StreamConfig<T extends DocumentSchema ? T : DocumentSchema> | undefined;
isStreamingRequest?: boolean | undefined;
}): Promise<T>;
put<T>(endpoint: string, bodyParameters?: any, queryParameters?: any): Promise<T>;
patch<T>(endpoint: string, bodyParameters?: any, queryParameters?: any): Promise<T>;
private getAdapter;
performRequest<T>(requestType: Method, endpoint: string, { queryParameters, bodyParameters, additionalHeaders, abortSignal, responseType, skipConnectionTimeout, enableKeepAlive, streamConfig, isStreamingRequest, }: {
performRequest<T>(requestType: RequestMethod, endpoint: string, { queryParameters, bodyParameters, additionalHeaders, abortSignal, responseType, skipConnectionTimeout, enableKeepAlive, streamConfig, isStreamingRequest, }: {
queryParameters?: any;
bodyParameters?: any;
additionalHeaders?: any;
abortSignal?: any;
responseType?: AxiosRequestConfig["responseType"] | undefined;
responseType?: ResponseType | undefined;
skipConnectionTimeout?: boolean;
enableKeepAlive?: boolean | undefined;
streamConfig?: StreamConfig<T extends DocumentSchema ? T : DocumentSchema> | undefined;
Expand All @@ -69,10 +69,9 @@ export default class ApiCall implements HttpClient {
private processStreamingLine;
private processDataLine;
private handleStreamingResponse;
private handleNodeStreaming;
private handleBrowserStreaming;
private handleBrowserReadableStream;
private handleBrowserStringResponse;
private handleReadableStream;
private handleStringStreamResponse;
private isReadableStream;
private processStreamLines;
private finalizeStreamResult;
/**
Expand All @@ -90,8 +89,12 @@ export default class ApiCall implements HttpClient {
setNodeHealthcheck(node: any, isHealthy: any): void;
uriFor(endpoint: string, node: any): string;
defaultHeaders(): any;
private mergeHeaders;
private isCallerAbortError;
private messageFromResponseData;
private httpBodyForError;
timer(seconds: any): Promise<void>;
customErrorForResponse(response: AxiosResponse, messageFromServer: string, httpBody?: string): TypesenseError;
customErrorForResponse(response: TypesenseResponse, messageFromServer: string, httpBody?: string): TypesenseError;
private invokeOnChunkCallback;
private invokeOnCompleteCallback;
private invokeOnErrorCallback;
Expand Down
Loading
Loading