@routr/pgdata 2.0.8-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Fonoster Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { PrismaClient } from "@prisma/client";
2
+ import { CommonTypes as CT } from "@routr/common";
3
+ export declare function create(prisma: PrismaClient): (call: CT.GrpcCall, callback: CT.GrpcCallback) => Promise<void>;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.create = void 0;
36
+ /*
37
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
38
+ * http://github.com/fonoster/routr
39
+ *
40
+ * This file is part of Routr
41
+ *
42
+ * Licensed under the MIT License (the "License");
43
+ * you may not use this file except in compliance with
44
+ * the License. You may obtain a copy of the License at
45
+ *
46
+ * https://opensource.org/licenses/MIT
47
+ *
48
+ * Unless required by applicable law or agreed to in writing, software
49
+ * distributed under the License is distributed on an "AS IS" BASIS,
50
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51
+ * See the License for the specific language governing permissions and
52
+ * limitations under the License.
53
+ */
54
+ const protobufUtil = __importStar(require("pb-util"));
55
+ const jsonToStruct = protobufUtil.struct.encode;
56
+ const structToJson = protobufUtil.struct.decode;
57
+ // eslint-disable-next-line require-jsdoc
58
+ function create(prisma) {
59
+ return (call, callback) => __awaiter(this, void 0, void 0, function* () {
60
+ const { request } = call;
61
+ if (request.extended) {
62
+ request.extended = structToJson(request.extended);
63
+ }
64
+ if (request.extended)
65
+ request.extended = jsonToStruct(request.extended);
66
+ callback(null, request);
67
+ });
68
+ }
69
+ exports.create = create;
package/dist/api.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { CommonTypes as CT } from "@routr/common";
2
+ export declare function get(call: CT.GrpcCall, callback: CT.GrpcCallback): Promise<void>;
package/dist/api.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.get = void 0;
13
+ /*
14
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/routr
16
+ *
17
+ * This file is part of Routr
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const client_1 = require("@prisma/client");
32
+ const common_1 = require("@routr/common");
33
+ const prisma = new client_1.PrismaClient();
34
+ // eslint-disable-next-line require-jsdoc
35
+ function get(call, callback) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (!call.request.ref) {
38
+ return callback(new common_1.CommonErrors.BadRequestError("parameter ref is required"), null);
39
+ }
40
+ const resource = (yield prisma.agent.findUnique({
41
+ where: {
42
+ ref: call.request.ref
43
+ }
44
+ }));
45
+ resource
46
+ ? callback(null, resource)
47
+ : callback(new common_1.CommonErrors.ResourceNotFoundError(call.request.ref), null);
48
+ });
49
+ }
50
+ exports.get = get;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/runner.js ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ var _a;
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ /*
9
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
10
+ * http://github.com/fonoster/routr
11
+ *
12
+ * This file is part of Routr
13
+ *
14
+ * Licensed under the MIT License (the "License");
15
+ * you may not use this file except in compliance with
16
+ * the License. You may obtain a copy of the License at
17
+ *
18
+ * https://opensource.org/licenses/MIT
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
27
+ require("./tracer").init("simpleauth");
28
+ const service_1 = __importDefault(require("./service"));
29
+ const logger_1 = require("@fonoster/logger");
30
+ const logger = (0, logger_1.getLogger)({ service: "pgdata", filePath: __filename });
31
+ try {
32
+ (0, service_1.default)({
33
+ bindAddr: (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51907"
34
+ });
35
+ }
36
+ catch (e) {
37
+ logger.error(e);
38
+ process.exit(1);
39
+ }
@@ -0,0 +1,7 @@
1
+ import { PostgresDataConfig } from "./types";
2
+ /**
3
+ * Starts a new posgres data service.
4
+ *
5
+ * @param {PostgresDataConfig} config - the configuration of the service
6
+ */
7
+ export default function pgDataService(config: PostgresDataConfig): void;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ /*
27
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
28
+ * http://github.com/fonoster/routr
29
+ *
30
+ * This file is part of Routr
31
+ *
32
+ * Licensed under the MIT License (the "License");
33
+ * you may not use this file except in compliance with
34
+ * the License. You may obtain a copy of the License at
35
+ *
36
+ * https://opensource.org/licenses/MIT
37
+ *
38
+ * Unless required by applicable law or agreed to in writing, software
39
+ * distributed under the License is distributed on an "AS IS" BASIS,
40
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41
+ * See the License for the specific language governing permissions and
42
+ * limitations under the License.
43
+ */
44
+ const grpc = __importStar(require("@grpc/grpc-js"));
45
+ const common_1 = require("@routr/common");
46
+ const utils_1 = require("./utils");
47
+ const logger_1 = require("@fonoster/logger");
48
+ const api_1 = require("./api");
49
+ const create_1 = require("./api/create");
50
+ const client_1 = require("@prisma/client");
51
+ const prisma = new client_1.PrismaClient();
52
+ const logger = (0, logger_1.getLogger)({ service: "pgdata", filePath: __filename });
53
+ /**
54
+ * Starts a new posgres data service.
55
+ *
56
+ * @param {PostgresDataConfig} config - the configuration of the service
57
+ */
58
+ function pgDataService(config) {
59
+ const { bindAddr } = config;
60
+ logger.info("starting routr service", { bindAddr, name: "pgdata" });
61
+ const server = new grpc.Server();
62
+ server.addService(common_1.CommonConnect.createService(common_1.CommonConnect.Kind.AGENT), {
63
+ get: api_1.get,
64
+ findBy: utils_1.nyi,
65
+ delete: utils_1.nyi,
66
+ update: utils_1.nyi,
67
+ create: (0, create_1.create)(prisma),
68
+ list: utils_1.nyi
69
+ });
70
+ server.bindAsync(config.bindAddr, grpc.ServerCredentials.createInsecure(), () => {
71
+ server.start();
72
+ });
73
+ }
74
+ exports.default = pgDataService;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This function registers the instrumentations for the service.
3
+ *
4
+ * @param {string} serviceName - The name of the service.
5
+ * @return {Tracer} The tracer object.
6
+ */
7
+ export declare function init(serviceName: string): import("@opentelemetry/api").Tracer;
package/dist/tracer.js ADDED
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init = void 0;
7
+ /*
8
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster/routr
10
+ *
11
+ * This file is part of Routr
12
+ *
13
+ * Licensed under the MIT License (the "License")
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const api_1 = __importDefault(require("@opentelemetry/api"));
26
+ const instrumentation_1 = require("@opentelemetry/instrumentation");
27
+ const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
28
+ const resources_1 = require("@opentelemetry/resources");
29
+ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
30
+ const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
31
+ const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
32
+ const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
33
+ /**
34
+ * This function registers the instrumentations for the service.
35
+ *
36
+ * @param {string} serviceName - The name of the service.
37
+ * @return {Tracer} The tracer object.
38
+ */
39
+ function init(serviceName) {
40
+ const provider = new sdk_trace_node_1.NodeTracerProvider({
41
+ resource: new resources_1.Resource({
42
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
43
+ })
44
+ });
45
+ const exporter = new exporter_jaeger_1.JaegerExporter();
46
+ provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
47
+ provider.register();
48
+ (0, instrumentation_1.registerInstrumentations)({
49
+ instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
50
+ });
51
+ return api_1.default.trace.getTracer("routr-tracer");
52
+ }
53
+ exports.init = init;
@@ -0,0 +1,3 @@
1
+ export interface PostgresDataConfig {
2
+ bindAddr: string;
3
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { CommonTypes as CT } from "@routr/common";
2
+ /**
3
+ * Returns UnimplementedError via callback.
4
+ *
5
+ * @param {GrpcCall} call - the grpc request
6
+ * @param {GrpcCallback} callback - the grpc callback
7
+ */
8
+ export declare function nyi(call: CT.GrpcCall, callback: CT.GrpcCallback): void;
package/dist/utils.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nyi = void 0;
4
+ /*
5
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/routr
7
+ *
8
+ * This file is part of Routr
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const common_1 = require("@routr/common");
23
+ /**
24
+ * Returns UnimplementedError via callback.
25
+ *
26
+ * @param {GrpcCall} call - the grpc request
27
+ * @param {GrpcCallback} callback - the grpc callback
28
+ */
29
+ function nyi(call, callback) {
30
+ callback(new common_1.CommonErrors.UnimplementedError());
31
+ }
32
+ exports.nyi = nyi;
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@routr/pgdata",
3
+ "version": "2.0.8-alpha.15",
4
+ "description": "Postgres API Server for Routr Connect",
5
+ "author": "Pedro Sanders <psanders@fonoster.com>",
6
+ "homepage": "https://github.com/fonoster/routr#readme",
7
+ "license": "MIT",
8
+ "main": "dist/pgdata",
9
+ "types": "dist/pgdata",
10
+ "directories": {
11
+ "src": "src",
12
+ "test": "test"
13
+ },
14
+ "scripts": {
15
+ "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
16
+ "build": "tsc -b tsconfig.json"
17
+ },
18
+ "bin": {
19
+ "run_pgdata": "dist/runner.js"
20
+ },
21
+ "dependencies": {
22
+ "@fonoster/logger": "0.3.18",
23
+ "@grpc/grpc-js": "^1.5.9",
24
+ "@opentelemetry/api": "^1.0.4",
25
+ "@opentelemetry/exporter-jaeger": "^1.0.4",
26
+ "@opentelemetry/instrumentation": "^0.27.0",
27
+ "@opentelemetry/instrumentation-grpc": "^0.27.0",
28
+ "@opentelemetry/resources": "^1.0.4",
29
+ "@opentelemetry/sdk-trace-base": "^1.0.4",
30
+ "@opentelemetry/sdk-trace-node": "^1.0.4",
31
+ "@opentelemetry/semantic-conventions": "^1.0.4",
32
+ "@prisma/client": "^4.8.0",
33
+ "@routr/common": "^2.0.8-alpha.15",
34
+ "@routr/processor": "^2.0.8-alpha.15",
35
+ "google-protobuf": "^3.9.2",
36
+ "pb-util": "^1.0.3"
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/fonoster/routr.git"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/fonoster/routr/issues"
50
+ },
51
+ "devDependencies": {
52
+ "@types/google-protobuf": "^3.15.6",
53
+ "prisma": "^4.8.0"
54
+ },
55
+ "gitHead": "713d176551252a157b5a7693ef8dba4e3e798dea"
56
+ }