From 46008011ee1e119cd04541474d132d3a23a2aa7e Mon Sep 17 00:00:00 2001 From: Shark <1160313432@qq.com> Date: Tue, 5 Jul 2022 21:48:54 +0800 Subject: [PATCH 1/3] feat:add Run lock API quickstart with js sdk - demo --- demo/examples-lock/lock.js | 41 ++++++++++++++++++++++++++++++++++++ demo/package.json | 4 +++- src/client/Client.ts | 2 +- src/client/Configuration.ts | 2 +- src/client/File.ts | 2 +- src/server/GRPCServerImpl.ts | 2 +- src/server/PubSub.ts | 2 +- src/server/Server.ts | 2 +- 8 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 demo/examples-lock/lock.js diff --git a/demo/examples-lock/lock.js b/demo/examples-lock/lock.js new file mode 100644 index 0000000..0cc0def --- /dev/null +++ b/demo/examples-lock/lock.js @@ -0,0 +1,41 @@ +/* + * Copyright 2021 Layotto Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +const { strict: assert } = require('assert'); +const { Client } = require('layotto'); + +const client = new Client(); +assert(client); + +async function main() { + const storeName = 'lock_demo'; + const resourceId = "lock-demo"; + const lockOwner = "demo"; + const expire = 3000; + const lockResult = await client.lock.tryLock({ + storeName, + resourceId, + lockOwner, + expire + }); + console.log(lockResult) + const unLockResult = await client.lock.unLock({ + storeName, + resourceId, + lockOwner + }) + console.log(unLockResult) +} + +main(); diff --git a/demo/package.json b/demo/package.json index f35ae7e..4c11095 100644 --- a/demo/package.json +++ b/demo/package.json @@ -7,10 +7,12 @@ "test:all": "npm run test:cjs && npm run test:esm && npm run test:ts", "test:cjs": "node ./state.js", "test:esm": "node ./state.mjs", + "test:lock": "node ./examples-lock/lock.js", "test:ts": "ts-node ./state.ts && ts-node ./configuration/subscribe.ts" }, "dependencies": { "koa": "^2.13.4", - "layotto": "*" + "layotto": "*", + "node": "^18.4.0" } } diff --git a/src/client/Client.ts b/src/client/Client.ts index 6a9e9a6..f7e556d 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'node:util'; +import { debuglog } from 'util'; import { ChannelCredentials } from '@grpc/grpc-js'; import { RuntimeClient } from '../../proto/runtime_grpc_pb'; import State from './State'; diff --git a/src/client/Configuration.ts b/src/client/Configuration.ts index ba13737..5880e73 100644 --- a/src/client/Configuration.ts +++ b/src/client/Configuration.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'node:util'; +import { debuglog } from 'util'; import { GetConfigurationRequest as GetConfigurationRequestPB, GetConfigurationResponse as GetConfigurationResponsePB, diff --git a/src/client/File.ts b/src/client/File.ts index 61f4bc9..3855857 100644 --- a/src/client/File.ts +++ b/src/client/File.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'node:util'; +import { debuglog } from 'util'; import { Transform, Readable } from 'stream'; import { pipeline as pipelinePromise } from 'stream/promises'; import { diff --git a/src/server/GRPCServerImpl.ts b/src/server/GRPCServerImpl.ts index ed153f9..af79756 100644 --- a/src/server/GRPCServerImpl.ts +++ b/src/server/GRPCServerImpl.ts @@ -13,7 +13,7 @@ * limitations under the License. * */ -import { debuglog } from 'node:util'; +import { debuglog } from 'util'; import * as grpc from '@grpc/grpc-js'; import { Empty } from 'google-protobuf/google/protobuf/empty_pb'; import { IAppCallbackServer } from '../../proto/appcallback_grpc_pb'; diff --git a/src/server/PubSub.ts b/src/server/PubSub.ts index 238dc8a..53f41e9 100644 --- a/src/server/PubSub.ts +++ b/src/server/PubSub.ts @@ -13,7 +13,7 @@ * limitations under the License. * */ -import { debuglog } from 'node:util'; +import { debuglog } from 'util'; import { PubSubCallback } from '../types/PubSub'; import GRPCServerImpl from './GRPCServerImpl'; diff --git a/src/server/Server.ts b/src/server/Server.ts index cb94403..15bfeb2 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'node:util'; +import { debuglog } from 'util'; import { ServerCredentials, Server as GRPCServer } from '@grpc/grpc-js'; import { AppCallbackService } from '../../proto/appcallback_grpc_pb'; import GRPCServerImpl from './GRPCServerImpl'; From 8a261f13311d5a9f1e4bcdb88cbd8b99fe701085 Mon Sep 17 00:00:00 2001 From: Shark <1160313432@qq.com> Date: Wed, 6 Jul 2022 19:46:42 +0800 Subject: [PATCH 2/3] fix:node package --- demo/package.json | 5 ++--- src/client/Client.ts | 2 +- src/client/Configuration.ts | 2 +- src/client/File.ts | 2 +- src/server/GRPCServerImpl.ts | 2 +- src/server/PubSub.ts | 2 +- src/server/Server.ts | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/demo/package.json b/demo/package.json index 4c11095..fff3d8c 100644 --- a/demo/package.json +++ b/demo/package.json @@ -4,7 +4,7 @@ "description": "Layotto Node.js SDK Demo", "private": true, "scripts": { - "test:all": "npm run test:cjs && npm run test:esm && npm run test:ts", + "test:all": "npm run test:lock && npm run test:cjs && npm run test:esm && npm run test:ts", "test:cjs": "node ./state.js", "test:esm": "node ./state.mjs", "test:lock": "node ./examples-lock/lock.js", @@ -12,7 +12,6 @@ }, "dependencies": { "koa": "^2.13.4", - "layotto": "*", - "node": "^18.4.0" + "layotto": "*" } } diff --git a/src/client/Client.ts b/src/client/Client.ts index f7e556d..6a9e9a6 100644 --- a/src/client/Client.ts +++ b/src/client/Client.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'util'; +import { debuglog } from 'node:util'; import { ChannelCredentials } from '@grpc/grpc-js'; import { RuntimeClient } from '../../proto/runtime_grpc_pb'; import State from './State'; diff --git a/src/client/Configuration.ts b/src/client/Configuration.ts index 5880e73..ba13737 100644 --- a/src/client/Configuration.ts +++ b/src/client/Configuration.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'util'; +import { debuglog } from 'node:util'; import { GetConfigurationRequest as GetConfigurationRequestPB, GetConfigurationResponse as GetConfigurationResponsePB, diff --git a/src/client/File.ts b/src/client/File.ts index 3855857..61f4bc9 100644 --- a/src/client/File.ts +++ b/src/client/File.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'util'; +import { debuglog } from 'node:util'; import { Transform, Readable } from 'stream'; import { pipeline as pipelinePromise } from 'stream/promises'; import { diff --git a/src/server/GRPCServerImpl.ts b/src/server/GRPCServerImpl.ts index af79756..ed153f9 100644 --- a/src/server/GRPCServerImpl.ts +++ b/src/server/GRPCServerImpl.ts @@ -13,7 +13,7 @@ * limitations under the License. * */ -import { debuglog } from 'util'; +import { debuglog } from 'node:util'; import * as grpc from '@grpc/grpc-js'; import { Empty } from 'google-protobuf/google/protobuf/empty_pb'; import { IAppCallbackServer } from '../../proto/appcallback_grpc_pb'; diff --git a/src/server/PubSub.ts b/src/server/PubSub.ts index 53f41e9..238dc8a 100644 --- a/src/server/PubSub.ts +++ b/src/server/PubSub.ts @@ -13,7 +13,7 @@ * limitations under the License. * */ -import { debuglog } from 'util'; +import { debuglog } from 'node:util'; import { PubSubCallback } from '../types/PubSub'; import GRPCServerImpl from './GRPCServerImpl'; diff --git a/src/server/Server.ts b/src/server/Server.ts index 15bfeb2..cb94403 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { debuglog } from 'util'; +import { debuglog } from 'node:util'; import { ServerCredentials, Server as GRPCServer } from '@grpc/grpc-js'; import { AppCallbackService } from '../../proto/appcallback_grpc_pb'; import GRPCServerImpl from './GRPCServerImpl'; From 2b68e6ab11a34d76265826b76e9a4466cb942d73 Mon Sep 17 00:00:00 2001 From: LZHKinger <1160313432@qq.com> Date: Wed, 19 Oct 2022 14:43:34 +0800 Subject: [PATCH 3/3] add test:lock script --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 28574f3..c577385 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "test": "jest --runInBand --detectOpenHandles", "test:unit": "NODE_ENV=test npm run test 'test/unit/.*\\.test\\.ts'", "test:demo": "cd demo && npm run test:all", + "test:lock": "cd demo && npm run test:lock", "lint": "tslint -p tsconfig.json", "build:grpc": "scripts/build-grpc.sh", "tsc:clean": "rm -rf dist",