@routr/pgdata 2.0.8-alpha.17 → 2.0.8-alpha.19
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/dist/api/create.d.ts +3 -3
- package/dist/api/create.js +32 -34
- package/dist/api/delete.d.ts +3 -0
- package/dist/api/delete.js +32 -0
- package/dist/api/find.d.ts +3 -0
- package/dist/api/find.js +58 -0
- package/dist/api/get.d.ts +3 -0
- package/dist/{api.js → api/get.js} +14 -9
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +36 -0
- package/dist/api/list.d.ts +3 -0
- package/dist/api/list.js +66 -0
- package/dist/api/update.d.ts +3 -0
- package/dist/api/update.js +70 -0
- package/dist/mappers/acl.d.ts +13 -0
- package/dist/mappers/acl.js +129 -0
- package/dist/mappers/agent.d.ts +24 -0
- package/dist/mappers/agent.js +130 -0
- package/dist/mappers/credentials.d.ts +13 -0
- package/dist/mappers/credentials.js +113 -0
- package/dist/mappers/domain.d.ts +19 -0
- package/dist/mappers/domain.js +114 -0
- package/dist/mappers/manager.d.ts +6 -0
- package/dist/mappers/manager.js +7 -0
- package/dist/mappers/number.d.ts +26 -0
- package/dist/mappers/number.js +155 -0
- package/dist/mappers/peer.d.ts +20 -0
- package/dist/mappers/peer.js +164 -0
- package/dist/mappers/trunk.d.ts +22 -0
- package/dist/mappers/trunk.js +144 -0
- package/dist/mappers/utils.d.ts +9 -0
- package/dist/mappers/utils.js +49 -0
- package/dist/service.js +26 -10
- package/dist/types.d.ts +35 -0
- package/package.json +7 -5
- package/dist/api.d.ts +0 -2
- package/dist/utils.d.ts +0 -8
- package/dist/utils.js +0 -32
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
exports.PeerManager = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Routr.
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License");
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
/* eslint-disable require-jsdoc */
|
|
46
|
+
const Validator = __importStar(require("validator"));
|
|
47
|
+
const common_1 = require("@routr/common");
|
|
48
|
+
const acl_1 = require("./acl");
|
|
49
|
+
const credentials_1 = require("./credentials");
|
|
50
|
+
const manager_1 = require("./manager");
|
|
51
|
+
// Needs testing
|
|
52
|
+
class PeerManager extends manager_1.EntityManager {
|
|
53
|
+
constructor(peer) {
|
|
54
|
+
super();
|
|
55
|
+
this.peer = peer;
|
|
56
|
+
}
|
|
57
|
+
static includeFields() {
|
|
58
|
+
return {
|
|
59
|
+
accessControlList: true,
|
|
60
|
+
credentials: true
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
validOrThrowCreate() {
|
|
64
|
+
if (!this.peer.name) {
|
|
65
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
|
|
66
|
+
}
|
|
67
|
+
if (!Validator.default.isLength(this.peer.name, { min: 3, max: 64 })) {
|
|
68
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
|
|
69
|
+
}
|
|
70
|
+
if (!this.peer.username) {
|
|
71
|
+
throw new common_1.CommonErrors.BadRequestError("the username is required");
|
|
72
|
+
}
|
|
73
|
+
if (!Validator.default.isAlphanumeric(this.peer.username)) {
|
|
74
|
+
throw new common_1.CommonErrors.BadRequestError("the username must be alphanumeric and without spaces");
|
|
75
|
+
}
|
|
76
|
+
if (!this.peer.aor) {
|
|
77
|
+
throw new common_1.CommonErrors.BadRequestError("the address of record (aor) is required");
|
|
78
|
+
}
|
|
79
|
+
// TODO: We will need a better way to validate this so is a valid SIP URI
|
|
80
|
+
if (!this.peer.aor.startsWith("backend:") &&
|
|
81
|
+
!this.peer.aor.startsWith("sip:")) {
|
|
82
|
+
throw new common_1.CommonErrors.BadRequestError("the aor schema must start with `backend:` or `sip:`");
|
|
83
|
+
}
|
|
84
|
+
if (this.peer.aor.startsWith("backend:")) {
|
|
85
|
+
if (!this.peer.balancingAlgorithm) {
|
|
86
|
+
throw new common_1.CommonErrors.BadRequestError("when the aor schema is `backend:`, the balancing algorithm is required");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (this.peer.aor.startsWith("sip:")) {
|
|
90
|
+
if (this.peer.balancingAlgorithm) {
|
|
91
|
+
throw new common_1.CommonErrors.BadRequestError("when the aor schema is `sip:`, the balancing algorithm is not allowed");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
validOrThrowUpdate() {
|
|
96
|
+
if (!this.peer.ref) {
|
|
97
|
+
throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
|
|
98
|
+
}
|
|
99
|
+
if (!this.peer.name) {
|
|
100
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
|
|
101
|
+
}
|
|
102
|
+
if (!Validator.default.isLength(this.peer.name, { min: 3, max: 64 })) {
|
|
103
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
|
|
104
|
+
}
|
|
105
|
+
if (this.peer.aor) {
|
|
106
|
+
// TODO: We will need a better way to validate this so is a valid SIP URI
|
|
107
|
+
if (!this.peer.aor.startsWith("backend:") &&
|
|
108
|
+
!this.peer.aor.startsWith("sip:")) {
|
|
109
|
+
throw new common_1.CommonErrors.BadRequestError("the aor schema must start with `backend:` or `sip:`");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (this.peer.aor.startsWith("backend:")) {
|
|
113
|
+
if (!this.peer.balancingAlgorithm) {
|
|
114
|
+
throw new common_1.CommonErrors.BadRequestError("when the aor schema is `backend:`, the balancing algorithm is required");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (this.peer.aor.startsWith("sip:")) {
|
|
118
|
+
if (this.peer.balancingAlgorithm) {
|
|
119
|
+
throw new common_1.CommonErrors.BadRequestError("when the aor schema is `sip:`, the balancing algorithm is not allowed");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
mapToPrisma() {
|
|
124
|
+
return {
|
|
125
|
+
// TODO: Set a default value for apiVersion
|
|
126
|
+
apiVersion: "v2",
|
|
127
|
+
ref: this.peer.ref,
|
|
128
|
+
name: this.peer.name,
|
|
129
|
+
username: this.peer.username,
|
|
130
|
+
aor: this.peer.aor,
|
|
131
|
+
contactAddr: this.peer.contactAddr,
|
|
132
|
+
balancingAlgorithm: this.peer
|
|
133
|
+
.balancingAlgorithm,
|
|
134
|
+
withSessionAffinity: this.peer.withSessionAffinity,
|
|
135
|
+
enabled: this.peer.enabled,
|
|
136
|
+
credentialsRef: this.peer.credentialsRef,
|
|
137
|
+
accessControlListRef: this.peer.accessControlListRef,
|
|
138
|
+
createdAt: this.peer.createdAt,
|
|
139
|
+
updatedAt: this.peer.updatedAt,
|
|
140
|
+
extended: this.peer.extended
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
static mapToDto(peer) {
|
|
144
|
+
return {
|
|
145
|
+
apiVersion: peer.apiVersion,
|
|
146
|
+
ref: peer.ref,
|
|
147
|
+
name: peer.name,
|
|
148
|
+
username: peer.username,
|
|
149
|
+
aor: peer.aor,
|
|
150
|
+
contactAddr: peer.contactAddr,
|
|
151
|
+
balancingAlgorithm: peer.balancingAlgorithm,
|
|
152
|
+
withSessionAffinity: peer.withSessionAffinity,
|
|
153
|
+
enabled: peer.enabled,
|
|
154
|
+
credentialsRef: peer.credentialsRef,
|
|
155
|
+
credentials: credentials_1.CredentialsManager.mapToDto(peer.credentials),
|
|
156
|
+
accessControlListRef: peer.accessControlListRef,
|
|
157
|
+
accessControlList: acl_1.ACLManager.mapToDto(peer.accessControlList),
|
|
158
|
+
createdAt: peer.createdAt,
|
|
159
|
+
updatedAt: peer.updatedAt,
|
|
160
|
+
extended: peer.extended
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.PeerManager = PeerManager;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Trunk as TrunkPrismaModel, Prisma } from "@prisma/client";
|
|
2
|
+
import { CommonConnect as CC } from "@routr/common";
|
|
3
|
+
import { JsonObject } from "pb-util/build";
|
|
4
|
+
import { EntityManager } from "./manager";
|
|
5
|
+
type TrunkWithEagerLoading = Prisma.TrunkGetPayload<{
|
|
6
|
+
include: {
|
|
7
|
+
accessControlList: true;
|
|
8
|
+
inboundCredentials: true;
|
|
9
|
+
outboundCredentials: true;
|
|
10
|
+
uris: true;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
export declare class TrunkManager extends EntityManager {
|
|
14
|
+
private trunk;
|
|
15
|
+
constructor(trunk: CC.Trunk | Omit<CC.Trunk, "uris">);
|
|
16
|
+
static includeFields(): JsonObject;
|
|
17
|
+
validOrThrowCreate(): void;
|
|
18
|
+
validOrThrowUpdate(): void;
|
|
19
|
+
mapToPrisma(): TrunkPrismaModel;
|
|
20
|
+
static mapToDto(trunk: TrunkWithEagerLoading): CC.Trunk;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
exports.TrunkManager = void 0;
|
|
27
|
+
/*
|
|
28
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
29
|
+
* http://github.com/fonoster
|
|
30
|
+
*
|
|
31
|
+
* This file is part of Routr.
|
|
32
|
+
*
|
|
33
|
+
* Licensed under the MIT License (the "License");
|
|
34
|
+
* you may not use this file except in compliance with
|
|
35
|
+
* the License. You may obtain a copy of the License at
|
|
36
|
+
*
|
|
37
|
+
* https://opensource.org/licenses/MIT
|
|
38
|
+
*
|
|
39
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
40
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
41
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
42
|
+
* See the License for the specific language governing permissions and
|
|
43
|
+
* limitations under the License.
|
|
44
|
+
*/
|
|
45
|
+
/* eslint-disable require-jsdoc */
|
|
46
|
+
const Validator = __importStar(require("validator"));
|
|
47
|
+
const common_1 = require("@routr/common");
|
|
48
|
+
const acl_1 = require("./acl");
|
|
49
|
+
const credentials_1 = require("./credentials");
|
|
50
|
+
const manager_1 = require("./manager");
|
|
51
|
+
// Needs testing
|
|
52
|
+
class TrunkManager extends manager_1.EntityManager {
|
|
53
|
+
constructor(trunk) {
|
|
54
|
+
super();
|
|
55
|
+
this.trunk = trunk;
|
|
56
|
+
}
|
|
57
|
+
static includeFields() {
|
|
58
|
+
return {
|
|
59
|
+
accessControlList: true,
|
|
60
|
+
inboundCredentials: true,
|
|
61
|
+
outboundCredentials: true,
|
|
62
|
+
uris: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
validOrThrowCreate() {
|
|
66
|
+
if (!this.trunk.name) {
|
|
67
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
|
|
68
|
+
}
|
|
69
|
+
if (!Validator.default.isLength(this.trunk.name, { min: 3, max: 64 })) {
|
|
70
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
|
|
71
|
+
}
|
|
72
|
+
if (!this.trunk.inboundUri) {
|
|
73
|
+
throw new common_1.CommonErrors.BadRequestError("the inboundUri is required");
|
|
74
|
+
}
|
|
75
|
+
if (!Validator.default.isFQDN(this.trunk.inboundUri)) {
|
|
76
|
+
throw new common_1.CommonErrors.BadRequestError("the inbound URI must be a valid FQDN (e.g. sip.example.com)");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
validOrThrowUpdate() {
|
|
80
|
+
if (!this.trunk.ref) {
|
|
81
|
+
throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
|
|
82
|
+
}
|
|
83
|
+
if (!this.trunk.name) {
|
|
84
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
|
|
85
|
+
}
|
|
86
|
+
if (!Validator.default.isLength(this.trunk.name, { min: 3, max: 64 })) {
|
|
87
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
|
|
88
|
+
}
|
|
89
|
+
if (this.trunk.inboundUri) {
|
|
90
|
+
if (!Validator.default.isFQDN(this.trunk.inboundUri)) {
|
|
91
|
+
throw new common_1.CommonErrors.BadRequestError("the inbound URI must be a valid FQDN (e.g. sip.example.com)");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
mapToPrisma() {
|
|
96
|
+
return {
|
|
97
|
+
// TODO: Set a default value for apiVersion
|
|
98
|
+
apiVersion: "v2",
|
|
99
|
+
ref: this.trunk.ref,
|
|
100
|
+
name: this.trunk.name,
|
|
101
|
+
accessControlListRef: this.trunk.accessControlListRef,
|
|
102
|
+
inboundUri: this.trunk.inboundUri,
|
|
103
|
+
inboundCredentialsRef: this.trunk.inboundCredentialsRef,
|
|
104
|
+
outboundCredentialsRef: this.trunk.outboundCredentialsRef,
|
|
105
|
+
extended: this.trunk.extended,
|
|
106
|
+
sendRegister: this.trunk.sendRegister,
|
|
107
|
+
createdAt: this.trunk.createdAt,
|
|
108
|
+
updatedAt: this.trunk.updatedAt
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
static mapToDto(trunk) {
|
|
112
|
+
var _a, _b, _c;
|
|
113
|
+
return {
|
|
114
|
+
apiVersion: trunk.apiVersion,
|
|
115
|
+
ref: trunk.ref,
|
|
116
|
+
name: trunk.name,
|
|
117
|
+
accessControlListRef: (_a = trunk.accessControlList) === null || _a === void 0 ? void 0 : _a.ref,
|
|
118
|
+
accessControlList: acl_1.ACLManager.mapToDto(trunk.accessControlList),
|
|
119
|
+
inboundUri: trunk.inboundUri,
|
|
120
|
+
inboundCredentialsRef: (_b = trunk.inboundCredentials) === null || _b === void 0 ? void 0 : _b.ref,
|
|
121
|
+
inboundCredentials: credentials_1.CredentialsManager.mapToDto(trunk.inboundCredentials),
|
|
122
|
+
outboundCredentialsRef: (_c = trunk.outboundCredentials) === null || _c === void 0 ? void 0 : _c.ref,
|
|
123
|
+
outboundCredentials: credentials_1.CredentialsManager.mapToDto(trunk.outboundCredentials),
|
|
124
|
+
extended: trunk.extended,
|
|
125
|
+
sendRegister: trunk.sendRegister,
|
|
126
|
+
uris: trunk.uris.map((uri) => {
|
|
127
|
+
return {
|
|
128
|
+
ref: uri.ref,
|
|
129
|
+
trunkRef: uri.trunkRef,
|
|
130
|
+
host: uri.host,
|
|
131
|
+
port: uri.port,
|
|
132
|
+
transport: uri.transport.toUpperCase(),
|
|
133
|
+
user: uri.user,
|
|
134
|
+
weight: uri.weight,
|
|
135
|
+
priority: uri.priority,
|
|
136
|
+
enabled: uri.enabled
|
|
137
|
+
};
|
|
138
|
+
}),
|
|
139
|
+
createdAt: trunk.createdAt,
|
|
140
|
+
updatedAt: trunk.updatedAt
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.TrunkManager = TrunkManager;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CommonConnect as CC } from "@routr/common";
|
|
2
|
+
import { ACLManager } from "./acl";
|
|
3
|
+
import { AgentManager } from "./agent";
|
|
4
|
+
import { CredentialsManager } from "./credentials";
|
|
5
|
+
import { DomainManager } from "./domain";
|
|
6
|
+
import { NumberManager } from "./number";
|
|
7
|
+
import { PeerManager } from "./peer";
|
|
8
|
+
import { TrunkManager } from "./trunk";
|
|
9
|
+
export declare function getManager(kind: CC.KindWithoutUnknown): typeof ACLManager | typeof CredentialsManager | typeof DomainManager | typeof AgentManager | typeof TrunkManager | typeof NumberManager | typeof PeerManager;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getManager = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster
|
|
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
|
+
/* eslint-disable require-jsdoc */
|
|
23
|
+
const common_1 = require("@routr/common");
|
|
24
|
+
const acl_1 = require("./acl");
|
|
25
|
+
const agent_1 = require("./agent");
|
|
26
|
+
const credentials_1 = require("./credentials");
|
|
27
|
+
const domain_1 = require("./domain");
|
|
28
|
+
const number_1 = require("./number");
|
|
29
|
+
const peer_1 = require("./peer");
|
|
30
|
+
const trunk_1 = require("./trunk");
|
|
31
|
+
function getManager(kind) {
|
|
32
|
+
switch (kind) {
|
|
33
|
+
case common_1.CommonConnect.Kind.AGENT:
|
|
34
|
+
return agent_1.AgentManager;
|
|
35
|
+
case common_1.CommonConnect.Kind.PEER:
|
|
36
|
+
return peer_1.PeerManager;
|
|
37
|
+
case common_1.CommonConnect.Kind.ACL:
|
|
38
|
+
return acl_1.ACLManager;
|
|
39
|
+
case common_1.CommonConnect.Kind.CREDENTIALS:
|
|
40
|
+
return credentials_1.CredentialsManager;
|
|
41
|
+
case common_1.CommonConnect.Kind.NUMBER:
|
|
42
|
+
return number_1.NumberManager;
|
|
43
|
+
case common_1.CommonConnect.Kind.TRUNK:
|
|
44
|
+
return trunk_1.TrunkManager;
|
|
45
|
+
case common_1.CommonConnect.Kind.DOMAIN:
|
|
46
|
+
return domain_1.DomainManager;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.getManager = getManager;
|
package/dist/service.js
CHANGED
|
@@ -43,11 +43,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
43
43
|
*/
|
|
44
44
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
45
45
|
const common_1 = require("@routr/common");
|
|
46
|
-
const utils_1 = require("./utils");
|
|
47
46
|
const logger_1 = require("@fonoster/logger");
|
|
48
|
-
const api_1 = require("./api");
|
|
49
|
-
const create_1 = require("./api/create");
|
|
50
47
|
const client_1 = require("@prisma/client");
|
|
48
|
+
const create_1 = require("./api/create");
|
|
49
|
+
const update_1 = require("./api/update");
|
|
50
|
+
const get_1 = require("./api/get");
|
|
51
|
+
const delete_1 = require("./api/delete");
|
|
52
|
+
const find_1 = require("./api/find");
|
|
53
|
+
const list_1 = require("./api/list");
|
|
51
54
|
const prisma = new client_1.PrismaClient();
|
|
52
55
|
const logger = (0, logger_1.getLogger)({ service: "pgdata", filePath: __filename });
|
|
53
56
|
/**
|
|
@@ -59,13 +62,26 @@ function pgDataService(config) {
|
|
|
59
62
|
const { bindAddr } = config;
|
|
60
63
|
logger.info("starting routr service", { bindAddr, name: "pgdata" });
|
|
61
64
|
const server = new grpc.Server();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const kinds = [
|
|
66
|
+
common_1.CommonConnect.Kind.AGENT,
|
|
67
|
+
common_1.CommonConnect.Kind.CREDENTIALS,
|
|
68
|
+
common_1.CommonConnect.Kind.NUMBER,
|
|
69
|
+
common_1.CommonConnect.Kind.TRUNK,
|
|
70
|
+
common_1.CommonConnect.Kind.PEER,
|
|
71
|
+
common_1.CommonConnect.Kind.DOMAIN,
|
|
72
|
+
"accessControlList"
|
|
73
|
+
];
|
|
74
|
+
kinds.forEach((kind) => {
|
|
75
|
+
const k = kind.toLowerCase();
|
|
76
|
+
const delegate = prisma[kind];
|
|
77
|
+
server.addService(common_1.CommonConnect.createService(k), {
|
|
78
|
+
create: (0, create_1.create)(delegate.create, k),
|
|
79
|
+
get: (0, get_1.get)(delegate.findUnique, k),
|
|
80
|
+
findBy: (0, find_1.findBy)(delegate.findMany, k),
|
|
81
|
+
delete: (0, delete_1.del)(delegate.delete),
|
|
82
|
+
update: (0, update_1.update)(delegate.update, k),
|
|
83
|
+
list: (0, list_1.list)(delegate.findMany, k)
|
|
84
|
+
});
|
|
69
85
|
});
|
|
70
86
|
server.bindAsync(config.bindAddr, grpc.ServerCredentials.createInsecure(), () => {
|
|
71
87
|
server.start();
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
import { CommonConnect as CC } from "@routr/common";
|
|
2
|
+
import { JsonObject } from "pb-util/build";
|
|
1
3
|
export interface PostgresDataConfig {
|
|
2
4
|
bindAddr: string;
|
|
3
5
|
}
|
|
6
|
+
export type DBDelegate = Exclude<Exclude<CC.Kind, CC.Kind.UNKNOWN>, CC.Kind.ACL> | "accessControlList";
|
|
7
|
+
export type PrismaOperation = (request: {
|
|
8
|
+
where: {
|
|
9
|
+
ref: string;
|
|
10
|
+
};
|
|
11
|
+
include?: JsonObject;
|
|
12
|
+
}) => unknown;
|
|
13
|
+
export type PrismaFindByOperation = (request: {
|
|
14
|
+
where: {
|
|
15
|
+
[key: string]: boolean | string | number;
|
|
16
|
+
};
|
|
17
|
+
include?: JsonObject;
|
|
18
|
+
}) => unknown;
|
|
19
|
+
export type PrismaListOperation = (request: {
|
|
20
|
+
take: number;
|
|
21
|
+
skip: number;
|
|
22
|
+
cursor: {
|
|
23
|
+
ref: string;
|
|
24
|
+
};
|
|
25
|
+
orderBy: JsonObject;
|
|
26
|
+
include?: JsonObject;
|
|
27
|
+
}) => unknown;
|
|
28
|
+
export type PrismaCreateOperation = (request: {
|
|
29
|
+
data: any;
|
|
30
|
+
include?: JsonObject;
|
|
31
|
+
}) => unknown;
|
|
32
|
+
export type PrismaUpdateOperation = (request: {
|
|
33
|
+
where: {
|
|
34
|
+
ref: string;
|
|
35
|
+
};
|
|
36
|
+
data: any;
|
|
37
|
+
include?: JsonObject;
|
|
38
|
+
}) => unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/pgdata",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.19",
|
|
4
4
|
"description": "Postgres API Server for Routr Connect",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
31
31
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
32
32
|
"@prisma/client": "^4.8.0",
|
|
33
|
-
"@routr/common": "^2.0.8-alpha.
|
|
34
|
-
"@routr/processor": "^2.0.8-alpha.
|
|
33
|
+
"@routr/common": "^2.0.8-alpha.19",
|
|
34
|
+
"@routr/processor": "^2.0.8-alpha.19",
|
|
35
35
|
"google-protobuf": "^3.9.2",
|
|
36
|
-
"pb-util": "^1.0.3"
|
|
36
|
+
"pb-util": "^1.0.3",
|
|
37
|
+
"validator": "^13.7.0"
|
|
37
38
|
},
|
|
38
39
|
"files": [
|
|
39
40
|
"dist"
|
|
@@ -50,7 +51,8 @@
|
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@types/google-protobuf": "^3.15.6",
|
|
54
|
+
"@types/validator": "^13.7.10",
|
|
53
55
|
"prisma": "^4.8.0"
|
|
54
56
|
},
|
|
55
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "ff62abb0ff7704a79f98a8e0b10c0036b949cc11"
|
|
56
58
|
}
|
package/dist/api.d.ts
DELETED
package/dist/utils.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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;
|