Skip to content
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

Revert "feat: support create a new state client (#38)" #39

Merged
merged 1 commit into from
Oct 16, 2023
Merged
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
11 changes: 2 additions & 9 deletions src/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ChannelCredentials } from '@grpc/grpc-js';
import { RuntimeClient } from '../../proto/runtime/v1/runtime_grpc_pb';
import { ObjectStorageServiceClient } from '../../proto/extension/v1/s3/oss_grpc_pb';
import { CryptionServiceClient } from '../../proto/extension/v1/cryption/cryption_grpc_pb';
import { State, StateOptions } from './State';
import { State } from './State';
import { Hello } from './Hello';
import { Invoker } from './Invoker';
import { Lock } from './Lock';
Expand Down Expand Up @@ -112,7 +112,7 @@ export class Client {

get state() {
if (!this._state) {
this._state = new State(this._runtime, {}, this.initAPIOptions);
this._state = new State(this._runtime, this.initAPIOptions);
}
return this._state;
}
Expand Down Expand Up @@ -184,13 +184,6 @@ export class Client {
return new Oss(ossClient, options, this.initAPIOptions);
}

/**
* Create new state client instance
*/
createStateClient(options?: StateOptions) {
return new State(this._runtime, options, this.initAPIOptions);
}

get cryption() {
if (!this._cryption) {
if (!this._cryptionClient) {
Expand Down
19 changes: 0 additions & 19 deletions src/client/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,8 @@ import {
StateItem,
} from '../types/State';
import { isEmptyPBMessage, convertMapToKVString } from '../utils';
import { RuntimeClient } from '../../proto/runtime/v1/runtime_grpc_pb';
import { APIOptions } from './API';
import { RequestWithMeta } from '../types/common';

export interface StateOptions {
// set default metadata on every request
defaultRequestMeta?: Record<string, string>;
}

export class State extends RuntimeAPI {
#defaultRequestMeta?: Record<string, string>;

constructor(runtime: RuntimeClient, options?: StateOptions, apiOptions?: APIOptions) {
super(runtime, apiOptions);
this.#defaultRequestMeta = options?.defaultRequestMeta;
}

createMetadata(request: RequestWithMeta<{}>) {
return super.createMetadata(request, this.#defaultRequestMeta);
}

// Saves an array of state objects
async save(request: SaveStateRequest): Promise<void> {
let states = request.states;
Expand Down
28 changes: 0 additions & 28 deletions test/unit/client/State.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,32 +198,4 @@ describe('client/State.test.ts', () => {
// assert.equal(states.length, 20);
});
});

describe('createStateClient()', () => {
it('should create a new state client success', async () => {
const key = 'js-sdk-unit-' + Date.now();
const stateClient = client.createStateClient({
defaultRequestMeta: {
foo: 'bar',
},
});
const value = `hello js-sdk, with 中文, 😄, at ${Date()}`;
await stateClient.save({
storeName,
states: { key, value },
requestMeta: { traceid: `mock-traceid-unittest-${Date.now()}` },
});
const state = await stateClient.get({ storeName, key });
assert(state);
assert.equal(Buffer.from(state.value).toString(), value);

await stateClient.save({
storeName,
states: { key, value },
});
const state2 = await stateClient.get({ storeName, key });
assert(state2);
assert.equal(Buffer.from(state2.value).toString(), value);
});
});
});
Loading