Skip to content

Commit

Permalink
SzProduct using SzAbstractFactory WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
arawinters committed Dec 31, 2024
1 parent e3604a6 commit 1a7e18b
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 15 deletions.
File renamed without changes.
16 changes: 16 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 12 additions & 0 deletions examples/szproduct/getVersion.ts
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 1 addition & 1 deletion src/abstracts/szAbstractFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
19 changes: 19 additions & 0 deletions src/abstracts/szAbstractFactoryCreator.ts
Original file line number Diff line number Diff line change
@@ -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() {

}
}
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@senzing/sz-sdk-nodejs-grpc",
"main": "./index.js",
"version": "0.0.2",
"version": "0.0.1",
"author": "[email protected]",
"license": "MIT",
"description": "A node library for handling Senzing SDK gRPC connections.",
Expand Down
21 changes: 16 additions & 5 deletions src/szProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 14 additions & 8 deletions src/szfactorycreator/szFactoryCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 });
}
}

0 comments on commit 1a7e18b

Please sign in to comment.