diff --git a/.eslintrc b/.eslintrc index 114c344..9bcdb46 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "eslint-config-egg/typescript" + "extends": [ + "eslint-config-egg/typescript", + "eslint-config-egg/lib/rules/enforce-node-prefix" + ] } diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 84a1827..ef985b3 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -40,7 +40,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [16, 18, 20] + node-version: [14, 16, 18, 20] os: [ubuntu-latest] steps: diff --git a/demo/configuration/subscribe.ts b/demo/configuration/subscribe.ts index 7f37d3d..65bab88 100644 --- a/demo/configuration/subscribe.ts +++ b/demo/configuration/subscribe.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client, utils } from 'layotto'; const client = new Client(); diff --git a/demo/helloworld.ts b/demo/helloworld.ts index d11f6eb..ea55668 100644 --- a/demo/helloworld.ts +++ b/demo/helloworld.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from 'layotto'; const client = new Client(); diff --git a/demo/pubsub/client.ts b/demo/pubsub/client.ts index 90d3eaf..8752766 100644 --- a/demo/pubsub/client.ts +++ b/demo/pubsub/client.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from 'layotto'; const client = new Client(); diff --git a/demo/rpc/http/server.js b/demo/rpc/http/server.js index 9eae035..a6592c0 100644 --- a/demo/rpc/http/server.js +++ b/demo/rpc/http/server.js @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -const http = require('http'); +const http = require('node:http'); const hostname = '127.0.0.1'; const port = 8889; diff --git a/demo/state.ts b/demo/state.ts index 24f0481..b364a72 100644 --- a/demo/state.ts +++ b/demo/state.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from 'layotto'; const client = new Client(); diff --git a/layotto b/layotto index 9141559..c8c8e51 160000 --- a/layotto +++ b/layotto @@ -1 +1 @@ -Subproject commit 91415599f4ffa43fdd6e53e210c52d78c0a1f746 +Subproject commit c8c8e5176971ac16dd64cfcf3a4898fc918d4870 diff --git a/src/client/API.ts b/src/client/API.ts index c38ed78..eeec1fe 100644 --- a/src/client/API.ts +++ b/src/client/API.ts @@ -13,15 +13,9 @@ * limitations under the License. */ import { Metadata } from '@grpc/grpc-js'; -import { RuntimeClient } from '../../proto/runtime/v1/runtime_grpc_pb'; import { KV, RequestWithMeta, Map } from '../types/common'; export class API { - readonly runtime: RuntimeClient; - constructor(runtime: RuntimeClient) { - this.runtime = runtime; - } - createMetadata(request: RequestWithMeta<{}>): Metadata { const metadata = new Metadata(); if (!request.requestMeta) return metadata; diff --git a/src/client/Binding.ts b/src/client/Binding.ts index b07cb91..e049915 100644 --- a/src/client/Binding.ts +++ b/src/client/Binding.ts @@ -16,14 +16,14 @@ import { InvokeBindingRequest as InvokeBindingRequestPB, InvokeBindingResponse as InvokeBindingResponsePB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { InvokeBindingRequest, InvokeBindingResponse, } from '../types/Binding'; import { convertMapToKVString } from '../utils'; -export default class Binding extends API { +export default class Binding extends RuntimeAPI { async invoke(request: InvokeBindingRequest): Promise { const req = new InvokeBindingRequestPB(); req.setName(request.name); diff --git a/src/client/Client.ts b/src/client/Client.ts index e3e9a1d..d606c5f 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -15,6 +15,8 @@ import { debuglog } from 'node:util'; 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 from './State'; import Hello from './Hello'; import Invoker from './Invoker'; @@ -24,20 +26,22 @@ import Configuration from './Configuration'; import PubSub from './PubSub'; import File from './File'; import Binding from './Binding'; -import { ObjectStorageServiceClient } from '../../proto/extension/v1/s3/oss_grpc_pb'; import Oss from './Oss'; +import Cryption from './Cryption'; const debug = debuglog('layotto:client:main'); export interface ClientOptions { ossEnable?: boolean; + cryptionEnable?: boolean; } export default class Client { - readonly host: string; - readonly port: string; - private _runtime: RuntimeClient; - private _ossClient: ObjectStorageServiceClient; + protected readonly host: string; + protected readonly port: string; + private readonly _runtime: RuntimeClient; + private readonly _ossClient: ObjectStorageServiceClient; + private readonly _cryptionClient: CryptionServiceClient; private _hello: Hello; private _state: State; private _invoker: Invoker; @@ -48,16 +52,21 @@ export default class Client { private _file: File; private _binding: Binding; private _oss: Oss; + private _cryption: Cryption; constructor(port: string = process.env.runtime_GRPC_PORT ?? '34904', host: string = process.env.runtime_GRPC_HOST ?? '127.0.0.1', options?: ClientOptions) { this.host = host; this.port = port; const clientCredentials = ChannelCredentials.createInsecure(); - this._runtime = new RuntimeClient(`${this.host}:${this.port}`, clientCredentials); - debug('Start connection to %s:%s', this.host, this.port); + const address = `${this.host}:${this.port}`; + this._runtime = new RuntimeClient(address, clientCredentials); + debug('Start connection to %o', address); if (options?.ossEnable) { - this._ossClient = new ObjectStorageServiceClient(`${this.host}:${this.port}`, clientCredentials); + this._ossClient = new ObjectStorageServiceClient(address, clientCredentials); + } + if (options?.cryptionEnable) { + this._cryptionClient = new CryptionServiceClient(address, clientCredentials); } } @@ -115,4 +124,14 @@ export default class Client { } return this._oss; } + + get cryption() { + if (!this._cryption) { + if (!this._cryptionClient) { + throw new Error('client not enable cryption'); + } + this._cryption = new Cryption(this._cryptionClient); + } + return this._cryption; + } } diff --git a/src/client/Configuration.ts b/src/client/Configuration.ts index 71b1f00..1c486f8 100644 --- a/src/client/Configuration.ts +++ b/src/client/Configuration.ts @@ -22,7 +22,7 @@ import { SubscribeConfigurationRequest as SubscribeConfigurationRequestPB, SubscribeConfigurationResponse as SubscribeConfigurationResponsePB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { GetConfigurationRequest, GetConfigurationItem, @@ -34,7 +34,7 @@ import { convertArrayToKVString } from '../types/common'; const debug = debuglog('layotto:client:configuration'); -export default class Configuration extends API { +export default class Configuration extends RuntimeAPI { // GetConfiguration gets configuration from configuration store. async get(request: GetConfigurationRequest): Promise { const req = new GetConfigurationRequestPB(); diff --git a/src/client/Cryption.ts b/src/client/Cryption.ts new file mode 100644 index 0000000..6f70e2c --- /dev/null +++ b/src/client/Cryption.ts @@ -0,0 +1,70 @@ +import { + EncryptRequest as EncryptRequestPB, + EncryptResponse, + DecryptRequest as DecryptRequestPB, + DecryptResponse as DecryptResponsePB, +} from '../../proto/extension/v1/cryption/cryption_pb'; +import { CryptionServiceClient } from '../../proto/extension/v1/cryption/cryption_grpc_pb'; +import { API } from './API'; +import { RequestWithMeta } from '../types/common'; + +export type EncryptRequest = RequestWithMeta<{ + componentName: string; + plainText: Uint8Array | string; + keyId?: string; +}>; + +export type DecryptRequest = RequestWithMeta; + +export type DecryptResponse = { + plainText: Uint8Array; + keyId: string, + keyVersionId: string, + requestId: string, +}; + +export default class Cryption extends API { + private readonly cryptionClient: CryptionServiceClient; + + constructor(cryptionClient: CryptionServiceClient) { + super(); + this.cryptionClient = cryptionClient; + } + + async encrypt(request: EncryptRequest): Promise { + const req = new EncryptRequestPB(); + req.setComponentName(request.componentName); + let plainText = request.plainText; + if (typeof plainText === 'string') { + plainText = Buffer.from(plainText); + } + req.setPlainText(plainText); + if (request.keyId) { + req.setKeyId(request.keyId); + } + + return new Promise((resolve, reject) => { + this.cryptionClient.encrypt(req, this.createMetadata(request), (err, res: EncryptResponse) => { + if (err) return reject(err); + resolve(res.toObject()); + }); + }); + } + + async decrypt(request: DecryptRequest): Promise { + const req = new DecryptRequestPB(); + req.setComponentName(request.componentName); + req.setCipherText(request.cipherText); + + return new Promise((resolve, reject) => { + this.cryptionClient.decrypt(req, this.createMetadata(request), (err, res: DecryptResponsePB) => { + if (err) return reject(err); + const plainText = Buffer.from(res.getPlainText_asB64(), 'base64'); + resolve({ + ...res.toObject(), + plainText, + }); + }); + }); + } +} diff --git a/src/client/File.ts b/src/client/File.ts index 7be67c0..7d0f9d5 100644 --- a/src/client/File.ts +++ b/src/client/File.ts @@ -13,8 +13,8 @@ * limitations under the License. */ import { debuglog } from 'node:util'; -import { Transform, Readable } from 'stream'; -import { pipeline as pipelinePromise } from 'stream/promises'; +import { Transform, Readable } from 'node:stream'; +import { pipeline as pipelinePromise } from 'node:stream/promises'; import { GetFileRequest as GetFileRequestPB, GetFileResponse as GetFileResponsePB, @@ -22,12 +22,12 @@ import { ListFileRequest as ListFileRequestPB, DelFileRequest as DelFileRequestPB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { GetFileRequest, ListFileResponse, PutFileRequest } from '../types/File'; const debug = debuglog('layotto:client:file'); -export default class File extends API { +export default class File extends RuntimeAPI { // Get a file stream async get(request: GetFileRequest): Promise { const req = new GetFileRequestPB(); diff --git a/src/client/Hello.ts b/src/client/Hello.ts index 473e774..66d5de1 100644 --- a/src/client/Hello.ts +++ b/src/client/Hello.ts @@ -16,10 +16,10 @@ import { SayHelloRequest as SayHelloRequestPB, SayHelloResponse as SayHelloResponsePB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { SayHelloRequest } from '../types/Hello'; -export default class Hello extends API { +export default class Hello extends RuntimeAPI { async sayHello(request?: SayHelloRequest): Promise { const req = new SayHelloRequestPB(); if (!request) request = {}; diff --git a/src/client/Invoker.ts b/src/client/Invoker.ts index 4999173..533526a 100644 --- a/src/client/Invoker.ts +++ b/src/client/Invoker.ts @@ -19,10 +19,10 @@ import { HTTPExtension, InvokeResponse as InvokeResponsePB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { InvokeServiceRequest, InvokeResponse } from '../types/Invoker'; -export default class Invoker extends API { +export default class Invoker extends RuntimeAPI { async invoke(request: InvokeServiceRequest): Promise { const message = new CommonInvokeRequestPB(); message.setMethod(request.method); diff --git a/src/client/Lock.ts b/src/client/Lock.ts index 8d6c795..58b4c6d 100644 --- a/src/client/Lock.ts +++ b/src/client/Lock.ts @@ -12,17 +12,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as crypto from 'crypto'; +import { randomUUID } from 'node:crypto'; import { TryLockRequest as TryLockRequestPB, TryLockResponse as TryLockResponsePB, UnlockRequest as UnlockRequestPB, UnlockResponse as UnlockResponsePB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { TryLockRequest, UnlockRequest } from '../types/Lock'; -export default class Lock extends API { +export default class Lock extends RuntimeAPI { // A non-blocking method trying to get a lock with ttl // expire is the time before expire. The time unit is second. async tryLock(request: TryLockRequest): Promise { @@ -55,6 +55,6 @@ export default class Lock extends API { } uuid() { - return crypto.randomUUID(); + return randomUUID(); } } diff --git a/src/client/Oss.ts b/src/client/Oss.ts index b0819c2..5cf0b18 100644 --- a/src/client/Oss.ts +++ b/src/client/Oss.ts @@ -1,3 +1,5 @@ +import { Readable, PassThrough, Writable } from 'node:stream'; +import { pipeline as pipelinePromise } from 'node:stream/promises'; import { CopyObjectRequest, DeleteObjectRequest, @@ -27,27 +29,16 @@ import { SignURLOutput, } from '../../proto/extension/v1/s3/oss_pb'; import { ObjectStorageServiceClient } from '../../proto/extension/v1/s3/oss_grpc_pb'; -import { RequestWithMeta } from '../types/common'; -import { Metadata } from '@grpc/grpc-js'; -import { Readable, PassThrough, Writable } from 'stream'; -import { pipeline as pipelinePromise } from 'stream/promises'; +import { API } from './API'; -export default class Oss { +export default class Oss extends API { private readonly ossClient: ObjectStorageServiceClient; constructor(ossClient: ObjectStorageServiceClient) { + super(); this.ossClient = ossClient; } - createMetadata(request: RequestWithMeta<{}>): Metadata { - const metadata = new Metadata(); - if (!request.requestMeta) return metadata; - for (const key of Object.keys(request.requestMeta)) { - metadata.add(key, request.requestMeta[key]); - } - return metadata; - } - private async* putObjectIterator(request: PutObjectRequest): AsyncGenerator { for await (const chunk of request.body) { const req = new PutObjectInput(); diff --git a/src/client/PubSub.ts b/src/client/PubSub.ts index 609ce24..37664a7 100644 --- a/src/client/PubSub.ts +++ b/src/client/PubSub.ts @@ -15,10 +15,10 @@ import { PublishEventRequest as PublishEventRequestPB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { PublishEventRequest } from '../types/PubSub'; -export default class PubSub extends API { +export default class PubSub extends RuntimeAPI { async publish(request: PublishEventRequest): Promise { const req = new PublishEventRequestPB(); req.setPubsubName(request.pubsubName); diff --git a/src/client/RuntimeAPI.ts b/src/client/RuntimeAPI.ts new file mode 100644 index 0000000..20f5063 --- /dev/null +++ b/src/client/RuntimeAPI.ts @@ -0,0 +1,10 @@ +import { RuntimeClient } from '../../proto/runtime/v1/runtime_grpc_pb'; +import { API } from './API'; + +export class RuntimeAPI extends API { + readonly runtime: RuntimeClient; + constructor(runtime: RuntimeClient) { + super(); + this.runtime = runtime; + } +} diff --git a/src/client/Sequencer.ts b/src/client/Sequencer.ts index f4e88ca..9c5fdc3 100644 --- a/src/client/Sequencer.ts +++ b/src/client/Sequencer.ts @@ -17,10 +17,10 @@ import { GetNextIdResponse as GetNextIdResponsePB, SequencerOptions as SequencerOptionsPB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { GetNextIdRequest } from '../types/Sequencer'; -export default class Sequencer extends API { +export default class Sequencer extends RuntimeAPI { // Get next unique id with some auto-increment guarantee async getNextId(request: GetNextIdRequest): Promise { const req = new GetNextIdRequestPB(); diff --git a/src/client/State.ts b/src/client/State.ts index 56117fd..f0eb06f 100644 --- a/src/client/State.ts +++ b/src/client/State.ts @@ -25,7 +25,7 @@ import { ExecuteStateTransactionRequest as ExecuteStateTransactionRequestPB, TransactionalStateOperation as TransactionalStateOperationPB, } from '../../proto/runtime/v1/runtime_pb'; -import { API } from './API'; +import { RuntimeAPI } from './RuntimeAPI'; import { DeleteBulkStateRequest, DeleteStateItem, @@ -39,7 +39,7 @@ import { } from '../types/State'; import { isEmptyPBMessage, convertMapToKVString } from '../utils'; -export default class State extends API { +export default class State extends RuntimeAPI { // Saves an array of state objects async save(request: SaveStateRequest): Promise { let states = request.states; diff --git a/src/index.ts b/src/index.ts index 5fb04f4..6fea020 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,13 +15,13 @@ import Client from './client/Client'; import Server from './server/Server'; import * as utils from './utils'; -import * as RumtimeTypes from '../proto/runtime/v1/runtime_pb'; +import * as RuntimeTypes from '../proto/runtime/v1/runtime_pb'; import * as Types from './types'; export { Client, Server, utils, - RumtimeTypes, + RuntimeTypes, Types, }; diff --git a/src/types/File.ts b/src/types/File.ts index 06890b3..4bc5c83 100644 --- a/src/types/File.ts +++ b/src/types/File.ts @@ -1,4 +1,4 @@ -import { Readable } from 'stream'; +import { Readable } from 'node:stream'; import { RequireExactlyOne } from 'type-fest'; import { KV, RequestWithMeta } from './common'; diff --git a/src/types/Oss.ts b/src/types/Oss.ts index 985971a..e9be4c4 100644 --- a/src/types/Oss.ts +++ b/src/types/Oss.ts @@ -1,5 +1,5 @@ +import { Readable } from 'node:stream'; import { RequestWithMeta } from './common'; -import { Readable } from 'stream'; import { GetObjectOutput } from '../../proto/extension/v1/s3/oss_pb'; export type PutObjectRequest = RequestWithMeta<{ @@ -24,6 +24,7 @@ export interface PutObjectResponse { expiration: string; requestCharged: string; versionId: string; + metadataMap: Array<[string, string]>; } export type GetObjectRequest = RequestWithMeta<{ diff --git a/src/utils.ts b/src/utils.ts index ece60e8..fc9f4ad 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { setTimeout } from 'timers/promises'; +import { setTimeout } from 'node:timers/promises'; import { Map as MapPB } from 'google-protobuf'; import { KV } from './types/common'; diff --git a/test/unit/client/Binding.test.ts b/test/unit/client/Binding.test.ts index 42ebaef..5b47dbd 100644 --- a/test/unit/client/Binding.test.ts +++ b/test/unit/client/Binding.test.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from '../../../src'; describe('client/Binding.test.ts', () => { diff --git a/test/unit/client/Client.test.ts b/test/unit/client/Client.test.ts index d9982a1..9d74a4c 100644 --- a/test/unit/client/Client.test.ts +++ b/test/unit/client/Client.test.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from '../../../src'; describe('client/Client.test.ts', () => { diff --git a/test/unit/client/Configuration.test.ts b/test/unit/client/Configuration.test.ts index 3cb5873..733d295 100644 --- a/test/unit/client/Configuration.test.ts +++ b/test/unit/client/Configuration.test.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client, utils } from '../../../src'; describe('client/Configuration.test.ts', () => { diff --git a/test/unit/client/Cryption.test.ts b/test/unit/client/Cryption.test.ts new file mode 100644 index 0000000..a29466f --- /dev/null +++ b/test/unit/client/Cryption.test.ts @@ -0,0 +1,39 @@ +import { strict as assert } from 'node:assert'; +import { Client } from '../../../src'; + +describe.skip('Cryption.test.ts', () => { + let client: Client; + const componentName = 'cryption_demo'; + + beforeAll(() => { + client = new Client('34904', '127.0.0.1', { cryptionEnable: true }); + }); + + it('should encrypt and decrypt success', async () => { + const encryptResult = await client.cryption.encrypt({ + componentName, + plainText: 'hello layotto 😄 你好', + }); + // { + // cipherText: 'TmpnNFl6RmtOxxxxxxxx1ZXMvY2xtZzM2V0k9', + // keyId: 'xxx-665f-486a-9529-xxx', + // keyVersionId: 'xxx-6950-407a-91d9-xxx', + // requestId: '63969176-4659-4059-8593-cd2f7ea2282b' + // } + // console.log(encryptResult); + assert(encryptResult.cipherText); + assert.equal(typeof encryptResult.cipherText, 'string'); + const decryptResult = await client.cryption.decrypt({ + componentName, + cipherText: encryptResult.cipherText, + }); + // { + // plainText: , + // keyId: 'xxx-665f-486a-9529-xxx', + // keyVersionId: 'xxx-6950-407a-91d9-xxx', + // requestId: 'ecf966e9-027e-4f1f-993f-1685f1bcd7e7' + // } + assert(Buffer.isBuffer(decryptResult.plainText)); + assert.equal(decryptResult.plainText.toString(), 'hello layotto 😄 你好'); + }); +}); diff --git a/test/unit/client/File.test.ts b/test/unit/client/File.test.ts index 74aaae6..db92bbb 100644 --- a/test/unit/client/File.test.ts +++ b/test/unit/client/File.test.ts @@ -12,12 +12,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; -import { tmpdir } from 'os'; -import { existsSync, createWriteStream, createReadStream } from 'fs'; -import { mkdtemp, rm } from 'fs/promises'; -import { pipeline } from 'stream/promises'; -import { join } from 'path'; +import { strict as assert } from 'node:assert'; +import { tmpdir } from 'node:os'; +import { existsSync, createWriteStream, createReadStream } from 'node:fs'; +import { mkdtemp, rm } from 'node:fs/promises'; +import { pipeline } from 'node:stream/promises'; +import { join } from 'node:path'; import { Client, utils } from '../../../src'; describe.skip('client/File.test.ts', () => { diff --git a/test/unit/client/Invoker.test.ts b/test/unit/client/Invoker.test.ts index 3bafba5..d9e1db1 100644 --- a/test/unit/client/Invoker.test.ts +++ b/test/unit/client/Invoker.test.ts @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from '../../../src'; -import { RumtimeTypes } from '../../../src'; +import { RuntimeTypes } from '../../../src'; describe.skip('client/Invoker.test.ts', () => { let client: Client; @@ -37,7 +37,7 @@ describe.skip('client/Invoker.test.ts', () => { const state = await client.invoker.invoke({ id: 'HelloService:1.0', method: '/hello', - httpVerb: RumtimeTypes.HTTPExtension.Verb.POST, + httpVerb: RuntimeTypes.HTTPExtension.Verb.POST, data: { 'hello runtime': 'I am js-sdk client', }, diff --git a/test/unit/client/Lock.test.ts b/test/unit/client/Lock.test.ts index 396dcb3..ea2cd41 100644 --- a/test/unit/client/Lock.test.ts +++ b/test/unit/client/Lock.test.ts @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; -import { Client, RumtimeTypes, utils } from '../../../src'; +import { strict as assert } from 'node:assert'; +import { Client, RuntimeTypes, utils } from '../../../src'; describe('Lock.test.ts', () => { let client: Client; @@ -27,7 +27,7 @@ describe('Lock.test.ts', () => { const resourceId = 'js-sdk-lock-not-exists'; const lockOwner = client.lock.uuid(); const result = await client.lock.unLock({ storeName, resourceId, lockOwner }); - assert.equal(result.status, RumtimeTypes.UnlockResponse.Status.LOCK_UNEXIST); + assert.equal(result.status, RuntimeTypes.UnlockResponse.Status.LOCK_UNEXIST); }); it('should lock 2 seconds work', async () => { @@ -45,10 +45,10 @@ describe('Lock.test.ts', () => { // unlock by other owner will fail const lockOwner2 = client.lock.uuid(); const status1 = await client.lock.unLock({ storeName, resourceId, lockOwner: lockOwner2 }); - assert.equal(status1.status, RumtimeTypes.UnlockResponse.Status.LOCK_BELONG_TO_OTHERS); + assert.equal(status1.status, RuntimeTypes.UnlockResponse.Status.LOCK_BELONG_TO_OTHERS); // unlock success by owner const status2 = await client.lock.unLock({ storeName, resourceId, lockOwner }); - assert.equal(status2.status, RumtimeTypes.UnlockResponse.Status.SUCCESS); + assert.equal(status2.status, RuntimeTypes.UnlockResponse.Status.SUCCESS); }); }); diff --git a/test/unit/client/Oss.test.ts b/test/unit/client/Oss.test.ts index ee6410f..1461c07 100644 --- a/test/unit/client/Oss.test.ts +++ b/test/unit/client/Oss.test.ts @@ -1,7 +1,7 @@ -import assert from 'assert'; +import assert from 'node:assert'; +import { Readable } from 'node:stream'; +import crypto from 'node:crypto'; import { Client } from '../../../src'; -import { Readable } from 'stream'; -import crypto from 'crypto'; describe.skip('client/Oss.test.ts', () => { const client = new Client('34901', '127.0.0.1', { ossEnable: true }); diff --git a/test/unit/client/Sequencer.test.ts b/test/unit/client/Sequencer.test.ts index bfb20ba..f6a721c 100644 --- a/test/unit/client/Sequencer.test.ts +++ b/test/unit/client/Sequencer.test.ts @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; -import { Client, RumtimeTypes } from '../../../src'; +import { strict as assert } from 'node:assert'; +import { Client, RuntimeTypes } from '../../../src'; describe('client/Sequencer.test.ts', () => { let client: Client; @@ -50,7 +50,7 @@ describe('client/Sequencer.test.ts', () => { storeName, key: 'user_info', options: { - increment: RumtimeTypes.SequencerOptions.AutoIncrement.WEAK, + increment: RuntimeTypes.SequencerOptions.AutoIncrement.WEAK, }, }); assert(BigInt(currentId) > BigInt(lastId)); diff --git a/test/unit/client/State.test.ts b/test/unit/client/State.test.ts index 56661b0..5e673eb 100644 --- a/test/unit/client/State.test.ts +++ b/test/unit/client/State.test.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from '../../../src'; import { StateOperation, StateOperationType } from '../../../src/types/State'; diff --git a/test/unit/server/GRPCServerImpl.test.ts b/test/unit/server/GRPCServerImpl.test.ts index f8644e4..7903c6f 100644 --- a/test/unit/server/GRPCServerImpl.test.ts +++ b/test/unit/server/GRPCServerImpl.test.ts @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; -import { execSync } from 'child_process'; +import { strict as assert } from 'node:assert'; +import { execSync } from 'node:child_process'; import { Server, Client, utils } from '../../../src'; import GRPCServerImpl from './GRPCServerImpl'; diff --git a/test/unit/server/PubSub.test.ts b/test/unit/server/PubSub.test.ts index 3d576d4..f0f013f 100644 --- a/test/unit/server/PubSub.test.ts +++ b/test/unit/server/PubSub.test.ts @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; -import { execSync } from 'child_process'; +import { strict as assert } from 'node:assert'; +import { execSync } from 'node:child_process'; import { Server, Client, utils } from '../../../src'; describe.skip('server/PubSub.test.ts', () => { diff --git a/test/unit/server/publishClient.ts b/test/unit/server/publishClient.ts index a34f5eb..21232ec 100644 --- a/test/unit/server/publishClient.ts +++ b/test/unit/server/publishClient.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from '../../../src'; const client = new Client(); diff --git a/test/unit/server/publishSofamqClient.ts b/test/unit/server/publishSofamqClient.ts index f2dfcea..03f425b 100644 --- a/test/unit/server/publishSofamqClient.ts +++ b/test/unit/server/publishSofamqClient.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { strict as assert } from 'assert'; +import { strict as assert } from 'node:assert'; import { Client } from '../../../src'; const client = new Client();