Skip to content

Commit

Permalink
Change typeinstanceId to typeInstanceId
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed Feb 28, 2022
1 parent 84ff7fa commit 4bcf363
Show file tree
Hide file tree
Showing 59 changed files with 477 additions and 444 deletions.
1 change: 1 addition & 0 deletions docs/investigation/local-hub-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Ideally, we want to implement Local Hub in Go.
There are the following proof of concept projects:
- [PostgreSQL](./postresql/README.md) - The goal of this investigation is to find an efficient way to implement Local Hub backed with PostgreSQL.
- [Dgraph](./dgraph/README.md) - The goal of this investigation is to check whether Dgraph can be used as a Local Hub replacement.
- [Generate TypeScript gRPC client](./ts-grpc/README.md) - The goal of this investigation is to find which tools we should use to generate the gRPC client for delegated storage backend.
32 changes: 0 additions & 32 deletions docs/investigation/local-hub-v2/grpc/grpc-gen/client-ts-plugin.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This document aggregates raw notes from a short investigation as a part of the [#626](https://github.com/capactio/capact/issues/626) issue.

## Goal

The goal is to find which tools we should use to generate the gRPC client for delegated storage backend. We want to:
- have a TypeScript Types
- have support for async/await
Expand All @@ -28,9 +29,9 @@ There are numerous option to generate gRPC clients. The most popular ones:
- Stars: `1.1k`
- [`ts-proto`](https://www.npmjs.com/package/ts-proto)
**Stats:**
- Weekly downloads: `44,656`
- Last publish: `27/02/2022`
- Stars: `752`
- Weekly downloads: `44,656`
- Last publish: `27/02/2022`
- Stars: `752`

All the above tools generate code without native support for `async/await` but there are other options:
- [Promisify @grpc-js service client with typescript](https://gist.github.com/smnbbrv/f147fceb4c29be5ce877b6275018e294) - tested but didn't work, got error: `This expression is not callable. Type 'never' has no call signatures.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ This simple project demonstrates the different libraries you can use to perform

```bash
npm run start:client-official
```
```bash
npm run start:client-official-await
```
```bash
npm run start:client-ts-plugin
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,26 @@ const config_1 = require("./config");
async function main() {
const svc = new DelegatedStorageClient(config_1.PROTO_PATH, config_1.TARGET);
const provider = 'dotenv'; // or 'aws_secretsmanager';
const request = {
typeinstanceId: '123',
resourceVersion: 1,
context: Buffer.from(`{"provider":"${provider}"}`)
const onCreate = {
typeInstanceId: '1234',
context: Buffer.from(`{"provider":"${provider}"}`),
value: Buffer.from(`{"key":"${provider}"}`)
};
const res = await svc.getValue(request).catch((err) => console.error(err));
if (res) {
console.log(`(client) Got server response: ${res.value}`);
const { value, ...ti } = onCreate; // extract common id and context to `ti`
const createRes = await svc.onCreate(onCreate).catch((err) => console.error(err));
if (createRes) {
console.log(`TypeInstance created: ${createRes.context}`);
}
const onGet = {
...ti,
resourceVersion: 1
};
const getRes = await svc.getValue(onGet).catch((err) => console.error(err));
if (getRes) {
console.log(`Fetch TypeInstance: ${getRes.value}`);
}
const onDel = ti;
await svc.onDelete(onDel).then(() => console.info('Deleted TypeInstance')).catch((err) => console.error(err));
}
class DelegatedStorageClient {
constructor(protoPath, target) {
Expand All @@ -48,6 +59,20 @@ class DelegatedStorageClient {
return resolve(res);
}));
}
async onCreate(req) {
return new Promise((resolve, reject) => this.client.onCreate(req, (error, res) => {
if (error)
return reject(error);
return resolve(res);
}));
}
async onDelete(req) {
return new Promise((resolve, reject) => this.client.onDelete(req, (error, res) => {
if (error)
return reject(error);
return resolve(res);
}));
}
}
exports.default = DelegatedStorageClient;
const promisify = (fn) => (req) => new Promise((resolve, reject) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {

const provider = 'dotenv'; // or 'aws_secretsmanager';
const onCreate: OnCreateRequest = {
typeinstanceId: '1234',
typeInstanceId: '1234',
context: Buffer.from(`{"provider":"${provider}"}`),
value: Buffer.from(`{"key":"${provider}"}`)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function main() {
else {
const provider = 'dotenv'; // or 'aws_secretsmanager';
const request = {
typeinstanceId: '123',
typeInstanceId: '123',
resourceVersion: 1,
context: Buffer.from(`{"provider":"${provider}"}`)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function main() {
} else {
const provider = 'dotenv'; // or 'aws_secretsmanager';
const request: GetValueRequest = {
typeinstanceId: '123',
typeInstanceId: '123',
resourceVersion: 1,
context: Buffer.from(`{"provider":"${provider}"}`)
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const storage_backend_1 = require("./proto/ts-plugin/storage_backend");
const nice_grpc_1 = require("nice-grpc");
const config_1 = require("./config");
async function main() {
const channel = (0, nice_grpc_1.createChannel)(config_1.TARGET);
const client = (0, nice_grpc_1.createClient)(storage_backend_1.StorageBackendDefinition, channel);
const provider = 'dotenv'; // or 'aws_secretsmanager';
const onCreate = {
typeInstanceId: '1234',
context: Buffer.from(`{"provider":"${provider}"}`),
value: Buffer.from(`{"key":"${provider}"}`)
};
const { value, ...ti } = onCreate; // extract common id and context to `ti`
const createRes = await client.onCreate(onCreate).catch((err) => console.error(err));
if (createRes) {
console.log(`TypeInstance created: ${createRes.context}`);
}
const onGet = {
...ti,
resourceVersion: 1
};
const getRes = await client.getValue(onGet).catch((err) => console.error(err));
if (getRes) {
console.log(`Fetch TypeInstance: ${getRes.value}`);
}
const onDel = ti;
await client.onDelete(onDel).then(() => console.info('Deleted TypeInstance')).catch((err) => console.error(err));
}
(async () => {
await main();
})();
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function main() {

const provider = 'dotenv'; // or 'aws_secretsmanager';
const onCreate: OnCreateRequest = {
typeinstanceId: '1234',
typeInstanceId: '1234',
context: Buffer.from(`{"provider":"${provider}"}`),
value: Buffer.from(`{"key":"${provider}"}`)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


export interface GetLockedByRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'context'?: (Buffer | Uint8Array | string);
}

export interface GetLockedByRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'context': (Buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


export interface GetValueRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'resourceVersion'?: (number);
'context'?: (Buffer | Uint8Array | string);
}

export interface GetValueRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'resourceVersion': (number);
'context': (Buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


export interface OnCreateRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'value'?: (Buffer | Uint8Array | string);
'context'?: (Buffer | Uint8Array | string);
}

export interface OnCreateRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'value': (Buffer);
'context': (Buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


export interface OnDeleteRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'context'?: (Buffer | Uint8Array | string);
}

export interface OnDeleteRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'context': (Buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@


export interface OnLockRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'context'?: (Buffer | Uint8Array | string);
'lockedBy'?: (string);
}

export interface OnLockRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'context': (Buffer);
'lockedBy': (string);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@


export interface OnUnlockRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'context'?: (Buffer | Uint8Array | string);
}

export interface OnUnlockRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'context': (Buffer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


export interface OnUpdateRequest {
'typeinstanceId'?: (string);
'typeInstanceId'?: (string);
'newResourceVersion'?: (number);
'newValue'?: (Buffer | Uint8Array | string);
'context'?: (Buffer | Uint8Array | string);
'_context'?: "context";
}

export interface OnUpdateRequest__Output {
'typeinstanceId': (string);
'typeInstanceId': (string);
'newResourceVersion': (number);
'newValue': (Buffer);
'context'?: (Buffer);
Expand Down
Loading

0 comments on commit 4bcf363

Please sign in to comment.