Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
2 parents f24ae81 + 03dd0a4 commit 1da6e94
Show file tree
Hide file tree
Showing 25 changed files with 1,189 additions and 210 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/update-example-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
schedule:
- cron: '0 12 * * *'
# for testing, temporarily allow manual triggering
workflow_dispatch:

jobs:
update-example-deps:
name: Update Momento deps in examples
runs-on: ubuntu-latest
env:
# TODO: remove token stored as secret in favor of using a
# momento-local instance that can be spun up for testing
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}

steps:
- name: Setup repo
uses: actions/checkout@v3

- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Run update script
id: validation
run: |
./scripts/update-all-examples-dependencies.sh
198 changes: 99 additions & 99 deletions packages/client-sdk-nodejs/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/client-sdk-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"uuid": "8.3.2"
},
"dependencies": {
"@gomomento/generated-types": "0.96.0",
"@gomomento/generated-types": "0.97.1",
"@gomomento/sdk-core": "file:../core",
"@grpc/grpc-js": "1.9.0",
"@types/google-protobuf": "3.15.10",
Expand Down
159 changes: 156 additions & 3 deletions packages/client-sdk-nodejs/src/internal/vector-index-data-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {version} from '../../package.json';
import {IVectorIndexDataClient} from '@gomomento/sdk-core/dist/src/internal/clients/vector/IVectorIndexDataClient';
import {VectorIndexItem} from '@gomomento/sdk-core/dist/src/messages/vector-index';
import {
CredentialProvider,
InvalidArgumentError,
Expand All @@ -10,7 +9,12 @@ import {
VectorDeleteItemBatch,
VectorSearch,
VectorSearchAndFetchVectors,
VectorIndexMetadata,
VectorIndexItem,
VectorUpsertItemBatch,
VectorIndexStoredItem,
VectorGetItemBatch,
VectorGetItemMetadataBatch,
} from '@gomomento/sdk-core';
import {VectorIndexClientProps} from '../vector-index-client-props';
import {VectorIndexConfiguration} from '../config/vector-index-configuration';
Expand Down Expand Up @@ -265,7 +269,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
private static deserializeMetadata(
metadata: vectorindex._Metadata[],
errorCallback: () => void
): Record<string, string | number | boolean | Array<string>> {
): VectorIndexMetadata {
return metadata.reduce((acc, metadata) => {
const field = metadata.field;
switch (metadata.value) {
Expand All @@ -289,7 +293,7 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
break;
}
return acc;
}, {} as Record<string, string | number | boolean | Array<string>>);
}, {} as VectorIndexMetadata);
}

private async sendSearch(
Expand Down Expand Up @@ -411,6 +415,155 @@ export class VectorIndexDataClient implements IVectorIndexDataClient {
});
}

public async getItemBatch(
indexName: string,
ids: string[]
): Promise<VectorGetItemBatch.Response> {
try {
validateIndexName(indexName);
} catch (err) {
return new VectorGetItemBatch.Error(normalizeSdkError(err as Error));
}
return await this.sendGetItemBatch(indexName, ids);
}

private async sendGetItemBatch(
indexName: string,
ids: string[]
): Promise<VectorGetItemBatch.Response> {
const request = new vectorindex._GetItemBatchRequest({
index_name: indexName,
ids: ids,
metadata_fields: VectorIndexDataClient.prepareMetadataRequest({
metadataFields: ALL_VECTOR_METADATA,
}),
});
return await new Promise(resolve => {
this.client.GetItemBatch(
request,
{interceptors: this.interceptors},
(err, resp) => {
if (resp) {
resolve(
new VectorGetItemBatch.Success(
resp.item_response.reduce((acc, itemResponse) => {
switch (itemResponse.response) {
case 'hit':
acc[itemResponse.hit.id] = {
id: itemResponse.hit.id,
vector: itemResponse.hit.vector.elements,
metadata: VectorIndexDataClient.deserializeMetadata(
itemResponse.hit.metadata,
() =>
resolve(
new VectorGetItemBatch.Error(
new UnknownError(
'GetItemBatch responded with an unknown result'
)
)
)
),
};
break;
case 'miss':
break;
default:
resolve(
new VectorGetItemBatch.Error(
new UnknownError(
'GetItemBatch responded with an unknown result'
)
)
);
break;
}
return acc;
}, {} as Record<string, VectorIndexStoredItem>)
)
);
} else {
resolve(new VectorGetItemBatch.Error(cacheServiceErrorMapper(err)));
}
}
);
});
}

public async getItemMetadataBatch(
indexName: string,
ids: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
try {
validateIndexName(indexName);
} catch (err) {
return new VectorGetItemMetadataBatch.Error(
normalizeSdkError(err as Error)
);
}
return await this.sendGetItemMetadataBatch(indexName, ids);
}

private async sendGetItemMetadataBatch(
indexName: string,
ids: string[]
): Promise<VectorGetItemMetadataBatch.Response> {
const request = new vectorindex._GetItemMetadataBatchRequest({
index_name: indexName,
ids: ids,
metadata_fields: VectorIndexDataClient.prepareMetadataRequest({
metadataFields: ALL_VECTOR_METADATA,
}),
});
return await new Promise(resolve => {
this.client.GetItemMetadataBatch(
request,
{interceptors: this.interceptors},
(err, resp) => {
if (resp) {
resolve(
new VectorGetItemMetadataBatch.Success(
resp.item_metadata_response.reduce((acc, itemResponse) => {
switch (itemResponse.response) {
case 'hit':
acc[itemResponse.hit.id] =
VectorIndexDataClient.deserializeMetadata(
itemResponse.hit.metadata,
() =>
resolve(
new VectorGetItemMetadataBatch.Error(
new UnknownError(
'GetItemMetadataBatch responded with an unknown result'
)
)
)
);
break;
case 'miss':
break;
default:
resolve(
new VectorGetItemMetadataBatch.Error(
new UnknownError(
'GetItemMetadataBatch responded with an unknown result'
)
)
);
break;
}
return acc;
}, {} as Record<string, VectorIndexMetadata>)
)
);
} else {
resolve(
new VectorGetItemMetadataBatch.Error(cacheServiceErrorMapper(err))
);
}
}
);
});
}

private validateRequestTimeout(timeout?: number) {
this.logger.debug(`Request timeout ms: ${String(timeout)}`);
if (timeout !== undefined && timeout <= 0) {
Expand Down
43 changes: 43 additions & 0 deletions packages/client-sdk-nodejs/src/internal/webhook-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ListWebhooks,
PostUrlWebhookDestination,
GetWebhookSecret,
RotateWebhookSecret,
} from '@gomomento/sdk-core';
import {ChannelCredentials, Interceptor} from '@grpc/grpc-js';
import {IWebhookClient} from '@gomomento/sdk-core/dist/src/internal/clients/pubsub/IWebhookClient';
Expand Down Expand Up @@ -190,4 +191,46 @@ export class WebhookClient implements IWebhookClient {
);
});
}

async rotateWebhookSecret(
id: WebhookId
): Promise<RotateWebhookSecret.Response> {
try {
validateCacheName(id.cacheName);
validateWebhookName(id.webhookName);
} catch (err) {
return new RotateWebhookSecret.Error(normalizeSdkError(err as Error));
}

const webhookId = grpcWebhook._WebhookId.fromObject({
webhook_name: id.webhookName,
cache_name: id.cacheName,
});
const request = new grpcWebhook._RotateWebhookSecretRequest({
webhook_id: webhookId,
});
this.logger.debug('issuing "RotateWebhookSecret" request');

return await new Promise<RotateWebhookSecret.Response>(resolve => {
this.webhookClient.RotateWebhookSecret(
request,
{interceptors: this.unaryInterceptors},
(err, resp) => {
if (err || !resp) {
resolve(
new RotateWebhookSecret.Error(cacheServiceErrorMapper(err))
);
} else {
resolve(
new RotateWebhookSecret.Success({
secret: resp.secret_string,
webhookName: id.webhookName,
cacheName: id.cacheName,
})
);
}
}
);
});
}
}
Loading

0 comments on commit 1da6e94

Please sign in to comment.