@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
package/dist/api/create.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function create(
|
|
1
|
+
import { CommonTypes as CT, CommonConnect as CC } from "@routr/common";
|
|
2
|
+
import { PrismaCreateOperation } from "../types";
|
|
3
|
+
export declare function create(operation: PrismaCreateOperation, kind: CC.KindWithoutUnknown): (call: CT.GrpcCall, callback: CT.GrpcCallback) => Promise<void>;
|
package/dist/api/create.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -51,19 +28,40 @@ exports.create = void 0;
|
|
|
51
28
|
* See the License for the specific language governing permissions and
|
|
52
29
|
* limitations under the License.
|
|
53
30
|
*/
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
function create(
|
|
31
|
+
/* eslint-disable require-jsdoc */
|
|
32
|
+
const pb_util_1 = require("pb-util");
|
|
33
|
+
const errors_1 = require("@routr/common/src/errors");
|
|
34
|
+
const utils_1 = require("../mappers/utils");
|
|
35
|
+
function create(operation, kind) {
|
|
59
36
|
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
37
|
+
try {
|
|
38
|
+
const { request } = call;
|
|
39
|
+
if (request.extended) {
|
|
40
|
+
request.extended = pb_util_1.struct.decode(request.extended);
|
|
41
|
+
}
|
|
42
|
+
const Manager = (0, utils_1.getManager)(kind);
|
|
43
|
+
const manager = new Manager(request);
|
|
44
|
+
manager.validOrThrowCreate();
|
|
45
|
+
const objFromDB = (yield operation({
|
|
46
|
+
data: manager.mapToPrisma(),
|
|
47
|
+
include: Manager.includeFields()
|
|
48
|
+
}));
|
|
49
|
+
if (objFromDB.extended) {
|
|
50
|
+
objFromDB.extended = pb_util_1.struct.encode(objFromDB.extended);
|
|
51
|
+
}
|
|
52
|
+
callback(null, objFromDB);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
if (e.code === "P2002") {
|
|
56
|
+
callback(new errors_1.BadRequestError("entity already exist for field: " + e.meta.target[0]), null);
|
|
57
|
+
}
|
|
58
|
+
else if (e.code === "P2003") {
|
|
59
|
+
callback(new errors_1.BadRequestError("dependent entity doesn't exist for: " + e.meta.field_name), null);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
callback(e, null);
|
|
63
|
+
}
|
|
63
64
|
}
|
|
64
|
-
if (request.extended)
|
|
65
|
-
request.extended = jsonToStruct(request.extended);
|
|
66
|
-
callback(null, request);
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
67
|
exports.create = create;
|
|
@@ -0,0 +1,32 @@
|
|
|
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.del = void 0;
|
|
13
|
+
const errors_1 = require("@routr/common/src/errors");
|
|
14
|
+
function del(operation) {
|
|
15
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
if (!call.request.ref) {
|
|
17
|
+
return callback(new errors_1.BadRequestError("parameter ref is required"), null);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
yield operation({
|
|
21
|
+
where: {
|
|
22
|
+
ref: call.request.ref
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// Ignore
|
|
28
|
+
}
|
|
29
|
+
callback(null, {});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.del = del;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CommonTypes as CT, CommonConnect as CC } from "@routr/common";
|
|
2
|
+
import { PrismaFindByOperation } from "../types";
|
|
3
|
+
export declare function findBy(operation: PrismaFindByOperation, kind: CC.KindWithoutUnknown): (call: CT.GrpcCall, callback: CT.GrpcCallback) => Promise<void>;
|
package/dist/api/find.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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.findBy = 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
|
+
/* eslint-disable require-jsdoc */
|
|
32
|
+
const pb_util_1 = require("pb-util");
|
|
33
|
+
const utils_1 = require("../mappers/utils");
|
|
34
|
+
function findBy(operation, kind) {
|
|
35
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
try {
|
|
37
|
+
const request = { [call.request.fieldName]: call.request.fieldValue };
|
|
38
|
+
const Manager = (0, utils_1.getManager)(kind);
|
|
39
|
+
// WARNING: This function currently doesn't work for boolean or enum fields
|
|
40
|
+
const items = (yield operation({
|
|
41
|
+
where: request,
|
|
42
|
+
include: Manager.includeFields()
|
|
43
|
+
}));
|
|
44
|
+
items.forEach((item) => {
|
|
45
|
+
if (item.extended) {
|
|
46
|
+
item.extended = pb_util_1.struct.encode(item.extended);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
callback(null, {
|
|
50
|
+
items: items
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
callback(e, null);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.findBy = findBy;
|
|
@@ -28,22 +28,27 @@ exports.get = void 0;
|
|
|
28
28
|
* See the License for the specific language governing permissions and
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
/* eslint-disable require-jsdoc */
|
|
32
|
+
const pb_util_1 = require("pb-util");
|
|
32
33
|
const common_1 = require("@routr/common");
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const utils_1 = require("../mappers/utils");
|
|
35
|
+
function get(operation, kind) {
|
|
36
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
if (!call.request.ref) {
|
|
38
38
|
return callback(new common_1.CommonErrors.BadRequestError("parameter ref is required"), null);
|
|
39
39
|
}
|
|
40
|
-
const
|
|
40
|
+
const Manager = (0, utils_1.getManager)(kind);
|
|
41
|
+
const objectFromDB = (yield operation({
|
|
41
42
|
where: {
|
|
42
43
|
ref: call.request.ref
|
|
43
|
-
}
|
|
44
|
+
},
|
|
45
|
+
include: Manager.includeFields()
|
|
44
46
|
}));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
if (objectFromDB === null || objectFromDB === void 0 ? void 0 : objectFromDB.extended) {
|
|
48
|
+
objectFromDB.extended = pb_util_1.struct.encode(objectFromDB.extended);
|
|
49
|
+
}
|
|
50
|
+
objectFromDB
|
|
51
|
+
? callback(null, objectFromDB)
|
|
47
52
|
: callback(new common_1.CommonErrors.ResourceNotFoundError(call.request.ref), null);
|
|
48
53
|
});
|
|
49
54
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
19
|
+
* http://github.com/fonoster
|
|
20
|
+
*
|
|
21
|
+
* This file is part of Routr.
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the MIT License (the "License");
|
|
24
|
+
* you may not use this file except in compliance with
|
|
25
|
+
* the License. You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* https://opensource.org/licenses/MIT
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
__exportStar(require("./create"), exports);
|
|
36
|
+
__exportStar(require("./find"), exports);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CommonTypes as CT, CommonConnect as CC } from "@routr/common";
|
|
2
|
+
import { PrismaListOperation } from "../types";
|
|
3
|
+
export declare function list(operation: PrismaListOperation, kind: CC.KindWithoutUnknown): (call: CT.GrpcCall, callback: CT.GrpcCallback) => Promise<void>;
|
package/dist/api/list.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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.list = 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
|
+
/* eslint-disable require-jsdoc */
|
|
32
|
+
const pb_util_1 = require("pb-util");
|
|
33
|
+
const utils_1 = require("../mappers/utils");
|
|
34
|
+
function list(operation, kind) {
|
|
35
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _a;
|
|
37
|
+
try {
|
|
38
|
+
const { request } = call;
|
|
39
|
+
const cursor = request.pageToken ? { ref: request.pageToken } : undefined;
|
|
40
|
+
const skip = request.pageToken ? 1 : 0;
|
|
41
|
+
const Manager = (0, utils_1.getManager)(kind);
|
|
42
|
+
const items = (yield operation({
|
|
43
|
+
take: request.pageSize,
|
|
44
|
+
skip,
|
|
45
|
+
cursor,
|
|
46
|
+
orderBy: {
|
|
47
|
+
createdAt: "desc"
|
|
48
|
+
},
|
|
49
|
+
include: Manager.includeFields()
|
|
50
|
+
}));
|
|
51
|
+
items.forEach((item) => {
|
|
52
|
+
if (item.extended) {
|
|
53
|
+
item.extended = pb_util_1.struct.encode(item.extended);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
callback(null, {
|
|
57
|
+
items,
|
|
58
|
+
nextPageToken: (_a = items[items.length - 1]) === null || _a === void 0 ? void 0 : _a.ref
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
callback(e, null);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.list = list;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CommonTypes as CT, CommonConnect as CC } from "@routr/common";
|
|
2
|
+
import { PrismaUpdateOperation } from "../types";
|
|
3
|
+
export declare function update(operation: PrismaUpdateOperation, kind: CC.KindWithoutUnknown): (call: CT.GrpcCall, callback: CT.GrpcCallback) => Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
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.update = 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
|
+
/* eslint-disable require-jsdoc */
|
|
32
|
+
const pb_util_1 = require("pb-util");
|
|
33
|
+
const errors_1 = require("@routr/common/src/errors");
|
|
34
|
+
const utils_1 = require("../mappers/utils");
|
|
35
|
+
function update(operation, kind) {
|
|
36
|
+
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
try {
|
|
38
|
+
const { request } = call;
|
|
39
|
+
if (request.extended) {
|
|
40
|
+
request.extended = pb_util_1.struct.decode(request.extended);
|
|
41
|
+
}
|
|
42
|
+
const Manager = (0, utils_1.getManager)(kind);
|
|
43
|
+
const manager = new Manager(request);
|
|
44
|
+
manager.validOrThrowUpdate();
|
|
45
|
+
const agentFromDB = (yield operation({
|
|
46
|
+
where: {
|
|
47
|
+
ref: request.ref
|
|
48
|
+
},
|
|
49
|
+
data: manager.mapToPrisma(),
|
|
50
|
+
include: Manager.includeFields()
|
|
51
|
+
}));
|
|
52
|
+
if (agentFromDB.extended) {
|
|
53
|
+
agentFromDB.extended = pb_util_1.struct.encode(agentFromDB.extended);
|
|
54
|
+
}
|
|
55
|
+
callback(null, agentFromDB);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
if (e.code === "P2025") {
|
|
59
|
+
callback(new errors_1.ResourceNotFoundError(call.request.ref), null);
|
|
60
|
+
}
|
|
61
|
+
else if (e.code === "P2003") {
|
|
62
|
+
callback(new errors_1.BadRequestError("dependent entity doesn't exist for: " + e.meta.field_name), null);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
callback(e, null);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.update = update;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AccessControlList as ACLPrismaModel } from "@prisma/client";
|
|
2
|
+
import { CommonConnect as CC } from "@routr/common";
|
|
3
|
+
import { JsonObject } from "pb-util/build";
|
|
4
|
+
import { EntityManager } from "./manager";
|
|
5
|
+
export declare class ACLManager extends EntityManager {
|
|
6
|
+
private acl;
|
|
7
|
+
constructor(acl: CC.AccessControlList);
|
|
8
|
+
static includeFields(): JsonObject;
|
|
9
|
+
validOrThrowCreate(): void;
|
|
10
|
+
validOrThrowUpdate(): void;
|
|
11
|
+
mapToPrisma(): ACLPrismaModel;
|
|
12
|
+
static mapToDto(acl: ACLPrismaModel): CC.AccessControlList;
|
|
13
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
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.ACLManager = 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 manager_1 = require("./manager");
|
|
49
|
+
class ACLManager extends manager_1.EntityManager {
|
|
50
|
+
constructor(acl) {
|
|
51
|
+
super();
|
|
52
|
+
this.acl = acl;
|
|
53
|
+
}
|
|
54
|
+
static includeFields() {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
validOrThrowCreate() {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
if (!this.acl.name) {
|
|
60
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
|
|
61
|
+
}
|
|
62
|
+
if (!Validator.default.isLength(this.acl.name, { min: 3, max: 64 })) {
|
|
63
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
|
|
64
|
+
}
|
|
65
|
+
if (!this.acl.deny ||
|
|
66
|
+
!this.acl.allow ||
|
|
67
|
+
((_a = this.acl.deny) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
68
|
+
((_b = this.acl.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
69
|
+
throw new common_1.CommonErrors.BadRequestError("acl rules are required");
|
|
70
|
+
}
|
|
71
|
+
this.acl.deny.forEach((cidr) => {
|
|
72
|
+
// 4 => IPv4
|
|
73
|
+
if (!Validator.default.isIPRange(cidr, 4)) {
|
|
74
|
+
throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
this.acl.allow.forEach((cidr) => {
|
|
78
|
+
// 4 => IPv4
|
|
79
|
+
if (!Validator.default.isIPRange(cidr, 4)) {
|
|
80
|
+
throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
validOrThrowUpdate() {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
if (!this.acl.ref) {
|
|
87
|
+
throw new common_1.CommonErrors.BadRequestError("the reference to the resource is required");
|
|
88
|
+
}
|
|
89
|
+
if (!this.acl.name) {
|
|
90
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name for the resource is required");
|
|
91
|
+
}
|
|
92
|
+
if (!Validator.default.isLength(this.acl.name, { min: 4, max: 64 })) {
|
|
93
|
+
throw new common_1.CommonErrors.BadRequestError("the friendly name must be between 3 and 64 characters");
|
|
94
|
+
}
|
|
95
|
+
if (!this.acl.deny ||
|
|
96
|
+
!this.acl.allow ||
|
|
97
|
+
((_a = this.acl.deny) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
|
|
98
|
+
((_b = this.acl.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
|
|
99
|
+
throw new common_1.CommonErrors.BadRequestError("acl rules are required");
|
|
100
|
+
}
|
|
101
|
+
this.acl.deny.forEach((cidr) => {
|
|
102
|
+
// 4 => IPv4
|
|
103
|
+
if (!Validator.default.isIPRange(cidr, 4)) {
|
|
104
|
+
throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
this.acl.allow.forEach((cidr) => {
|
|
108
|
+
// 4 => IPv4
|
|
109
|
+
if (!Validator.default.isIPRange(cidr, 4)) {
|
|
110
|
+
throw new common_1.CommonErrors.BadRequestError(`${cidr} is not a valid cidr`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
mapToPrisma() {
|
|
115
|
+
return {
|
|
116
|
+
// TODO: Set a default value for apiVersion
|
|
117
|
+
apiVersion: "v2",
|
|
118
|
+
ref: this.acl.ref,
|
|
119
|
+
name: this.acl.name,
|
|
120
|
+
allow: this.acl.allow,
|
|
121
|
+
deny: this.acl.deny,
|
|
122
|
+
extended: this.acl.extended || {}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
static mapToDto(acl) {
|
|
126
|
+
return Object.assign(Object.assign({}, acl), { extended: acl.extended });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.ACLManager = ACLManager;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Agent as AgentPrismaModel, 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 AgentWithDomainAndCredentials = Prisma.AgentGetPayload<{
|
|
6
|
+
include: {
|
|
7
|
+
domain: {
|
|
8
|
+
include: {
|
|
9
|
+
accessControlList: true;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
credentials: true;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export declare class AgentManager extends EntityManager {
|
|
16
|
+
private agent;
|
|
17
|
+
constructor(agent: CC.Agent);
|
|
18
|
+
static includeFields(): JsonObject;
|
|
19
|
+
validOrThrowCreate(): void;
|
|
20
|
+
validOrThrowUpdate(): void;
|
|
21
|
+
mapToPrisma(): AgentPrismaModel;
|
|
22
|
+
static mapToDto(agent: AgentWithDomainAndCredentials): CC.Agent;
|
|
23
|
+
}
|
|
24
|
+
export {};
|