Skip to content
Closed
37 changes: 33 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@
"require": "./dist/node/cjs/index.js",
"default": "./dist/node/esm/index.js"
}
},
"./web": {
"types": {
"require": "./dist/web/index.web.d.cts",
"default": "./dist/web/index.web.d.ts"
},
"default": {
"require": "./dist/web/index.web.cjs",
"default": "./dist/web/index.web.js"
}
}
},
"browser": "./dist/web/index.web.js",
"engines": {
"node": ">=22.0.0"
},
Expand Down Expand Up @@ -61,6 +72,7 @@
"nice-grpc": "^2.1.14",
"nice-grpc-client-middleware-retry": "^3.1.13",
"nice-grpc-common": "^2.0.2",
"nice-grpc-web": "^3.3.10",
"uuid": "^14.0.0"
},
"devDependencies": {
Expand All @@ -78,6 +90,7 @@
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"babel-jest": "^29.4.3",
"buffer": "^6.0.3",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/alias/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectionREST } from '../index.js';
import { ConnectionREST } from '../connection/index.js';
import { WeaviateAlias, WeaviateAliasResponse } from '../openapi/types.js';
import { Alias, AliasListAllOptions, CreateAliasArgs, UpdateAliasArgs } from './types.js';

Expand Down
3 changes: 2 additions & 1 deletion src/collections/aggregate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { FilterValue } from '../filters/index.js';

import { WeaviateInvalidInputError, WeaviateQueryError } from '../../errors.js';
import { Aggregator } from '../../graphql/index.js';
import { PrimitiveKeys, toBase64FromMedia } from '../../index.js';
import type { PrimitiveKeys } from '../../index.js';
import { toBase64FromMedia } from '../../utils/base64.js';
import { Deserialize } from '../deserialize/index.js';
import { Bm25OperatorOptions, Bm25QueryProperty, NearVectorInputType, TargetVector } from '../query/types.js';
import { NearVectorInputGuards } from '../query/utils.js';
Expand Down
6 changes: 6 additions & 0 deletions src/collections/data/batch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Deque } from '@datastructures-js/deque';
import { v4 as uuidv4 } from 'uuid';
import Connection from '../../connection/grpc.js';
import { WeaviateUnsupportedFeatureError } from '../../errors.js';
import { ConsistencyLevel } from '../../index.js';
import {
BatchObject as BatchObjectGRPC,
Expand Down Expand Up @@ -66,6 +67,11 @@ export interface Batch {
export default function (connection: Connection, dbVersionSupport: DbVersionSupport): Batch {
return {
stream: async (consistencyLevel) => {
if (!connection.supportsStreaming()) {
throw new WeaviateUnsupportedFeatureError(
'Streaming batch (batch.stream / data.ingest) is not supported over gRPC-Web. Use data.insertMany instead.'
);
}
const { supports, message } = await dbVersionSupport.supportsServerSideBatching();
if (!supports) {
throw new Error(message);
Expand Down
2 changes: 1 addition & 1 deletion src/collections/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ConsistencyLevel } from '../../data/index.js';
import { DbVersionSupport } from '../../utils/dbVersion.js';

import { WeaviateInvalidInputError } from '../../errors.js';
import { toBase64FromMedia } from '../../index.js';
import { GenerativeSearch } from '../../proto/v1/generative.js';
import { SearchReply } from '../../proto/v1/search_get.js';
import { toBase64FromMedia } from '../../utils/base64.js';
import { Deserialize } from '../deserialize/index.js';
import { Check } from '../query/check.js';
import { CallOptions } from '../query/index.js';
Expand Down
2 changes: 1 addition & 1 deletion src/collections/serialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import {
SearchNearVectorArgs,
SearchNearVideoArgs,
} from '../../grpc/searcher.js';
import { toBase64FromMedia } from '../../index.js';
import {
AggregateRequest_Aggregation,
AggregateRequest_Aggregation_Boolean,
Expand All @@ -97,6 +96,7 @@ import {
Vectors as VectorsGrpc,
Vectors_VectorType,
} from '../../proto/v1/base.js';
import { toBase64FromMedia } from '../../utils/base64.js';
import { yieldToEventLoop } from '../../utils/yield.js';
import { FilterId } from '../filters/classes.js';
import { FilterValue, Filters } from '../filters/index.js';
Expand Down
41 changes: 10 additions & 31 deletions src/connection/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ import { getClientVersionHeader, InternalConnectionParams } from './http.js';

import { ConsistencyLevel } from '../data/index.js';

import {
ChannelCredentials,
ChannelOptions,
ClientError,
createChannel,
createClientFactory,
Metadata,
Status,
} from 'nice-grpc';
import { retryMiddleware } from 'nice-grpc-client-middleware-retry';
import { ClientError, Metadata, Status } from 'nice-grpc-common';

import { HealthCheckResponse_ServingStatus, HealthDefinition } from '../proto/google/health/v1/health.js';
import { WeaviateDefinition } from '../proto/v1/weaviate.js';
import { HealthCheckResponse_ServingStatus } from '../proto/google/health/v1/health.js';

import Batcher, { Batch } from '../grpc/batcher.js';
import Searcher, { Search } from '../grpc/searcher.js';
Expand All @@ -27,14 +17,14 @@ import { DbVersionSupport, initDbVersionProvider } from '../utils/dbVersion.js';
import { WeaviateGRPCUnavailableError, WeaviateUnsupportedFeatureError } from '../errors.js';
import Aggregator, { Aggregate } from '../grpc/aggregator.js';
import { Meta } from '../openapi/types.js';
import { GrpcTransport } from './transports/types.js';

export interface GrpcConnectionParams extends InternalConnectionParams {
grpcAddress: string;
grpcSecure: boolean;
transport?: GrpcTransport;
}

const clientFactory = createClientFactory().use(retryMiddleware);

const MAX_GRPC_MESSAGE_LENGTH = 104858000; // 10mb, needs to be synchronized with GRPC server

// Must extend from ConnectionGQL so that it can be passed to all the builder methods,
Expand Down Expand Up @@ -156,6 +146,8 @@ export default class ConnectionGRPC extends ConnectionGQL {
return new Promise<Tenants>((resolve) => resolve(this.grpc.tenants(collection)));
};

public supportsStreaming = (): boolean => this.params.transport?.supportsStreaming ?? true;

close = () => {
this.grpc.close();
this.http.close();
Expand Down Expand Up @@ -188,23 +180,10 @@ export interface GrpcClient {
}

export const grpcClient = (config: GrpcConnectionParams & { grpcMaxMessageLength: number }): GrpcClient => {
const channelOptions: ChannelOptions = {
'grpc.max_send_message_length': config.grpcMaxMessageLength,
'grpc.max_receive_message_length': config.grpcMaxMessageLength,
};
if (config.grpcProxyUrl) {
// grpc.http_proxy is not used by grpc.js under-the-hood
// only uses the env var and whether http_proxy is enabled
process.env.grpc_proxy = config.grpcProxyUrl;
channelOptions['grpc.enabled_http_proxy'] = true;
if (!config.transport) {
throw new Error('grpcClient requires a transport to be configured');
}
const channel = createChannel(
config.grpcAddress,
config.grpcSecure ? ChannelCredentials.createSsl() : ChannelCredentials.createInsecure(),
channelOptions
);
const client = clientFactory.create(WeaviateDefinition, channel);
const health = clientFactory.create(HealthDefinition, channel);
const { client, health, close } = config.transport.create(config);
return {
aggregate: (
collection: string,
Expand All @@ -229,7 +208,7 @@ export const grpcClient = (config: GrpcConnectionParams & { grpcMaxMessageLength
consistencyLevel,
tenant
),
close: () => channel.close(),
close: () => close(),
health: () => {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), (config.timeout?.init || 2) * 1000);
Expand Down
6 changes: 6 additions & 0 deletions src/connection/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type ConnectToWeaviateCloudOptions = {
timeout?: TimeoutParams;
/** Whether to skip the initialization checks */
skipInitChecks?: boolean;
/** Which gRPC transport to use: 'native' (default, Node) or 'grpc-web' (browser-compatible). */
transport?: 'native' | 'grpc-web';
};

/** @deprecated Use `ConnectToWeaviateCloudOptions` instead. */
Expand All @@ -41,6 +43,8 @@ export type ConnectToLocalOptions = {
timeout?: TimeoutParams;
/** Whether to skip the initialization checks */
skipInitChecks?: boolean;
/** Which gRPC transport to use: 'native' (default, Node) or 'grpc-web' (browser-compatible). */
transport?: 'native' | 'grpc-web';
};

export type ConnectToCustomOptions = {
Expand Down Expand Up @@ -68,6 +72,8 @@ export type ConnectToCustomOptions = {
timeout?: TimeoutParams;
/** Whether to skip the initialization checks */
skipInitChecks?: boolean;
/** Which gRPC transport to use: 'native' (default, Node) or 'grpc-web' (browser-compatible). */
transport?: 'native' | 'grpc-web';
};

export function connectToWeaviateCloud(
Expand Down
4 changes: 2 additions & 2 deletions src/connection/http.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isAbortError } from 'abort-controller-x';
import { Agent } from 'http';
import type { Agent } from 'http';

import OpenidConfigurationGetter from '../misc/openidConfigurationGetter.js';

Expand Down Expand Up @@ -262,7 +262,7 @@ export const httpClient = (config: InternalConnectionParams): HttpClient => {
const url = makeUrl(baseUri);

return {
close: () => config.agent?.destroy(),
close: () => config.agent?.destroy?.(),
post: <B, T>(
path: string,
payload: B,
Expand Down
Loading
Loading