@adempiere/grpc-api
Advanced tools
Comparing version 1.0.5 to 1.0.6
135
index.js
@@ -37,2 +37,3 @@ /************************************************************************************* | ||
this.initAccessService() | ||
this.initUIService() | ||
this.initBusinessService() | ||
@@ -90,6 +91,13 @@ this.initDictionaryService() | ||
// Init connection | ||
initUIService() { | ||
var grpc = require('grpc'); | ||
var services = require('./src/grpc/proto/business_grpc_pb'); | ||
this.ui = new services.UserInterfaceClient(this.businessHost, grpc.credentials.createInsecure()); | ||
} | ||
// Init connection | ||
initBusinessService() { | ||
var grpc = require('grpc'); | ||
var services = require('./src/grpc/proto/business_grpc_pb'); | ||
this.business = new services.UserInterfaceClient(this.businessHost, grpc.credentials.createInsecure()); | ||
this.business = new services.BusinessDataClient(this.businessHost, grpc.credentials.createInsecure()); | ||
} | ||
@@ -102,2 +110,7 @@ | ||
// Get UI Service | ||
getUIService() { | ||
return this.ui | ||
} | ||
// Get Business Service | ||
@@ -229,3 +242,3 @@ getBusinessService() { | ||
request.setResourceUuid(resourceUuid) | ||
const stream = this.getBusinessService().getResource(request)//, callback) | ||
const stream = this.getUIService().getResource(request) | ||
let result = new Uint8Array() | ||
@@ -263,3 +276,3 @@ stream.on('data', (response) => { | ||
// Convert value from gRPC | ||
convertValueFromGRPC(value) { | ||
convertAccessValuesFromGRPC(value) { | ||
const { ContextValue } = require('./src/grpc/proto/access_pb.js') | ||
@@ -398,3 +411,119 @@ const { ValueType } = ContextValue | ||
} | ||
// Business CRUD | ||
// Get a Entity | ||
getEntity({ | ||
token, | ||
id, | ||
uuid, | ||
tableName | ||
}, callback) { | ||
const { GetEntityRequest } = require('./src/grpc/proto/business_pb.js') | ||
const request = new GetEntityRequest() | ||
request.setRecordId(id) | ||
request.setUuid(uuid) | ||
request.setTableName(tableName) | ||
request.setClientRequest(this.createClientRequest(token)) | ||
this.getBusinessService().getEntity(request, callback) | ||
} | ||
// Create a Entity | ||
createEntity({ | ||
token, | ||
tableName, | ||
attributes | ||
}, callback) { | ||
const { CreateEntityRequest } = require('./src/grpc/proto/business_pb.js') | ||
const { convertParameterToGRPC } = require('./src/convertValues.js'); | ||
const request = new CreateEntityRequest() | ||
request.setTableName(tableName) | ||
if(attributes) { | ||
attributes.forEach(attribute => { | ||
request.addAttributes(convertParameterToGRPC({ | ||
columnName: attribute.key, | ||
value: attribute.value | ||
})) | ||
}) | ||
} | ||
request.setClientRequest(this.createClientRequest(token)) | ||
this.getBusinessService().createEntity(request, callback) | ||
} | ||
// Create a Entity | ||
updateEntity({ | ||
token, | ||
tableName, | ||
id, | ||
uuid, | ||
attributes | ||
}, callback) { | ||
const { UpdateEntityRequest } = require('./src/grpc/proto/business_pb.js') | ||
const { convertParameterToGRPC } = require('./src/convertValues.js'); | ||
const request = new UpdateEntityRequest() | ||
request.setTableName(tableName) | ||
request.setRecordId(id) | ||
request.setUuid(uuid) | ||
if(attributes) { | ||
attributes.forEach(attribute => { | ||
request.addAttributes(convertParameterToGRPC({ | ||
columnName: attribute.key, | ||
value: attribute.value | ||
})) | ||
}) | ||
} | ||
request.setClientRequest(this.createClientRequest(token)) | ||
this.getBusinessService().updateEntity(request, callback) | ||
} | ||
// Convert business values from gRPC | ||
convertBusinessValuesFromGRPC(value) { | ||
const { convertValueFromGRPC } = require('./src/convertBaseDataType.js'); | ||
return convertValueFromGRPC(value) | ||
} | ||
// Delete a Entity | ||
deleteEntity({ | ||
token, | ||
id, | ||
uuid, | ||
tableName | ||
}, callback) { | ||
const { DeleteEntityRequest } = require('./src/grpc/proto/business_pb.js') | ||
const request = new DeleteEntityRequest() | ||
request.setRecordId(id) | ||
request.setUuid(uuid) | ||
request.setTableName(tableName) | ||
request.setClientRequest(this.createClientRequest(token)) | ||
this.getBusinessService().deleteEntity(request, callback) | ||
} | ||
// List Entities | ||
listEntities({ | ||
token, | ||
tableName, | ||
// Custom Query | ||
query, | ||
whereClause, | ||
orderByClause, | ||
limit, | ||
// Page Data | ||
pageSize, | ||
pageToken | ||
}, callback) { | ||
const { ListEntitiesRequest } = require('./src/grpc/proto/business_pb.js') | ||
const request = new ListEntitiesRequest() | ||
const { convertCriteriaToGRPC } = require('./src/convertValues.js'); | ||
// TODO: Add support to all parameters | ||
request.setCriteria(convertCriteriaToGRPC({ | ||
tableName, | ||
query, | ||
whereClause, | ||
orderByClause, | ||
limit | ||
})) | ||
// TODO: Add Criteria | ||
request.setClientRequest(this.createClientRequest(token)) | ||
this.getBusinessService().listEntities(request, callback) | ||
} | ||
} | ||
module.exports = Api; |
{ | ||
"name": "@adempiere/grpc-api", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "ADempiere Web Store write in Javascript for a node service", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -109,3 +109,3 @@ # ADempiere Web Store backend API for gRPC | ||
yarn global add grpc-tools | ||
grpc_tools_node_protoc --js_out=import_style=commonjs,binary:src/grpc --grpc_out=src/grpc --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` proto/access.proto proto/client.proto proto/base_data_type.proto proto/core_functionality.proto proto/dictionary.proto | ||
grpc_tools_node_protoc --js_out=import_style=commonjs,binary:src/grpc --grpc_out=src/grpc --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` proto/access.proto proto/client.proto proto/base_data_type.proto proto/core_functionality.proto proto/dictionary.proto proto/business.proto | ||
``` | ||
@@ -112,0 +112,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1752548
27
51007