diff --git a/examples/static/helloworld.ts b/examples/grpc_tools_node_protoc/helloworld.ts similarity index 100% rename from examples/static/helloworld.ts rename to examples/grpc_tools_node_protoc/helloworld.ts diff --git a/examples/package.json b/examples/package.json new file mode 100644 index 0000000..110e4d4 --- /dev/null +++ b/examples/package.json @@ -0,0 +1,16 @@ +{ + "name": "@senzing/sz-sdk-nodejs-grpc_examples", + "version": "0.0.1", + "description": "examples for using @senzing/serve-grpc with nodejs", + "main": "index.js", + "scripts": { + "szproduct/getVersion.ts": "tsx szproduct/getVersion.ts", + "grpc_tools_node_protoc/helloworld.ts": "tsx grpc_tools_node_protoc/helloworld.ts" + }, + "keywords": [ + "senzing", + "entity-resolution" + ], + "author": "", + "license": "MIT" +} diff --git a/examples/szproduct/getVersion.ts b/examples/szproduct/getVersion.ts new file mode 100644 index 0000000..0c4fef1 --- /dev/null +++ b/examples/szproduct/getVersion.ts @@ -0,0 +1,12 @@ +import { SzAbstractFactory, SzAbstractFactoryOptions } from '../../dist/@senzing/sz-sdk-nodejs-grpc/szfactorycreator/szFactoryCreator'; + +const szParamFactory = new SzAbstractFactory(`0.0.0.0:8261`); +const szProduct = szParamFactory.createProduct(); + +szProduct.getVersion(). + then((result)=>{ + console.log("RESPONSE:\n\r", result); + }). + catch((err)=>{ + console.error(err); + }); \ No newline at end of file diff --git a/src/abstracts/szAbstractFactory.ts b/src/abstracts/szAbstractFactory.ts index 912e5d9..adeaf9c 100644 --- a/src/abstracts/szAbstractFactory.ts +++ b/src/abstracts/szAbstractFactory.ts @@ -7,5 +7,5 @@ export abstract class SzAbstractFactory { abstract createConfigManager(): undefined; abstract createDiagnostic(): undefined; abstract createEngine(): undefined; - abstract createProducts(): SzAbstractProduct | undefined; + abstract createProduct(factory: any): SzAbstractProduct | undefined; } diff --git a/src/abstracts/szAbstractFactoryCreator.ts b/src/abstracts/szAbstractFactoryCreator.ts new file mode 100644 index 0000000..7fb32b8 --- /dev/null +++ b/src/abstracts/szAbstractFactoryCreator.ts @@ -0,0 +1,19 @@ + /* + func CreateGrpcAbstractFactory(grpcConnection *grpc.ClientConn) (senzing.SzAbstractFactory, error) { + szAbstractFactory := &szabstractfactorygrpc.Szabstractfactory{ + GrpcConnection: grpcConnection, + } + return szAbstractFactory, nil + } + */ + + export class szAbstractFactoryCreator { + /* + static CreateCoreAbstractFactory() { + + } + */ + static CreateGrpcAbstractFactory() { + + } + } \ No newline at end of file diff --git a/src/package.json b/src/package.json index 5648d95..e5fc76a 100644 --- a/src/package.json +++ b/src/package.json @@ -1,7 +1,7 @@ { "name": "@senzing/sz-sdk-nodejs-grpc", "main": "./index.js", - "version": "0.0.2", + "version": "0.0.1", "author": "development@senzing.com", "license": "MIT", "description": "A node library for handling Senzing SDK gRPC connections.", diff --git a/src/szProduct.ts b/src/szProduct.ts index 9394d42..47d74ac 100644 --- a/src/szProduct.ts +++ b/src/szProduct.ts @@ -2,23 +2,34 @@ import * as grpc from '@grpc/grpc-js'; import { GetVersionRequest, GetVersionResponse } from './szproduct/szproduct_pb'; import { SzProductClient } from './szproduct/szproduct_grpc_pb'; import { SzAbstractProduct } from './abstracts/szAbstractProduct'; +import { SzAbstractFactoryOptions } from './szfactorycreator/szFactoryCreator'; // --------------- user facing "grpc.SzProduct" inheriting from SzAbstractProduct export class SzProduct implements SzAbstractProduct { - private connectionString; - private credentials; + private connectionString: string; + private credentials: grpc.ChannelCredentials; private client; - constructor(connectionString = `0.0.0.0:8261`, credentials = grpc.credentials.createInsecure()) { + //connectionString = `0.0.0.0:8261`, credentials = grpc.credentials.createInsecure() + + constructor(parameters: SzAbstractFactoryOptions) { + const { connectionString, credentials } = parameters; this.connectionString = connectionString; - this.credentials = credentials; - this.client = new SzProductClient(this.connectionString, this.credentials); + this.credentials = credentials !== undefined? credentials : grpc.credentials.createInsecure(); + + if(this.connectionString) { + this.client = new SzProductClient(this.connectionString, this.credentials); + } } getLicense() { return undefined; } getVersion() { return new Promise((resolve, reject) => { + if(!this.client){ + reject('no connection present'); + return + } const request = new GetVersionRequest(); this.client.getVersion(request, (err, res) => { if(err) { diff --git a/src/szfactorycreator/szFactoryCreator.ts b/src/szfactorycreator/szFactoryCreator.ts index 5a10cf8..fe63032 100644 --- a/src/szfactorycreator/szFactoryCreator.ts +++ b/src/szfactorycreator/szFactoryCreator.ts @@ -2,20 +2,26 @@ import * as grpc from '@grpc/grpc-js'; //import { SzProduct } from '../szProduct'; import { SzAbstractProduct } from '../abstracts/szAbstractProduct'; import { SzAbstractFactory as SzAbstractFactoryAbstract } from '../abstracts/szAbstractFactory'; -import { SzProduct } from '../szProduct'; +import { SzProduct as SzProductGrpc } from '../szProduct'; // from "https://github.com/senzing-garage/sz-sdk-python/blob/main/src/senzing/szabstractfactory.py" -export interface SzAbstractFactoryParameters { - +export interface SzAbstractFactoryOptions { + connectionString: string, + credentials?: grpc.ChannelCredentials } // from grpc package -export class SzAbstractFactory implements SzAbstractFactoryAbstract{ +export class SzAbstractFactory extends SzAbstractFactoryAbstract{ //private channel: grpc.Channel = undefined; + private connectionStr: string; - constructor(szFactoryAbstract: SzAbstractFactoryAbstract) {} + constructor(connectionString: string) { + // create gRPC client connection + super(); + this.connectionStr = connectionString; + } - public createConfig(): undefined{ + public createConfig(): undefined { return undefined; } public createConfigManager(): undefined{ @@ -28,7 +34,7 @@ export class SzAbstractFactory implements SzAbstractFactoryAbstract{ return undefined; } - public createProducts(): SzProduct | undefined{ - return undefined; + override createProduct(): SzProductGrpc { + return new SzProductGrpc({ connectionString: this.connectionStr }); } } \ No newline at end of file