Skip to content

Commit

Permalink
Revert "feat: support create a new state client (#38)" (#39)
Browse files Browse the repository at this point in the history
This reverts commit 327adec.
  • Loading branch information
fengmk2 authored Oct 16, 2023
1 parent 2b5ddcb commit 5d7c23f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 56 deletions.
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);
});
});
});

0 comments on commit 5d7c23f

Please sign in to comment.