@routr/simpledata 2.6.2 → 2.6.3

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.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { CommonTypes as CT } from "@routr/common";
2
- import { CommonConnect as CC } from "@routr/common";
1
+ import { CommonTypes as CT, CommonConnect as CC } from "@routr/common";
3
2
  /**
4
3
  * Enclosure with method to obtain a resource by reference.
5
4
  *
package/dist/api.js CHANGED
@@ -21,7 +21,6 @@ exports.findBy = exports.get = void 0;
21
21
  */
22
22
  const pb_util_1 = require("pb-util");
23
23
  const common_1 = require("@routr/common");
24
- const common_2 = require("@routr/common");
25
24
  /**
26
25
  * Enclosure with method to obtain a resource by reference.
27
26
  *
@@ -36,7 +35,7 @@ function get(resources) {
36
35
  if (call.request.ref == null) {
37
36
  return callback(new common_1.CommonErrors.BadRequestError("parameter ref is required"), null);
38
37
  }
39
- const resource = common_2.Helper.deepCopy(resources.find((r) => r.ref === call.request.ref));
38
+ const resource = common_1.Helper.deepCopy(resources.find((r) => r.ref === call.request.ref));
40
39
  // Serialize to protobuf
41
40
  if (resource === null || resource === void 0 ? void 0 : resource.extended) {
42
41
  resource.extended = pb_util_1.struct.encode(resource.extended);
@@ -55,9 +54,6 @@ exports.get = get;
55
54
  */
56
55
  function findBy(resources) {
57
56
  return (call, callback) => {
58
- if (resources.length === 0) {
59
- return callback(new common_1.CommonErrors.ResourceNotFoundError(""), null);
60
- }
61
57
  const { request } = call;
62
58
  const queryResult = resources.filter((r) => `${r[request.fieldName]}` ===
63
59
  `${request.fieldValue}`);
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function aclLoader(config: CC.UserConfig): CC.AccessControlList;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.aclLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ function aclLoader(config) {
25
+ if (config.kind !== common_1.CommonConnect.Kind.ACL)
26
+ throw new Error("invalid resource type `AccessControlList`");
27
+ return common_1.CommonConnect.mapToACL(config);
28
+ }
29
+ exports.aclLoader = aclLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function agentsLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Agent;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agentsLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ const find_1 = require("./find");
25
+ function agentsLoader(config, list) {
26
+ if (config.kind !== common_1.CommonConnect.Kind.AGENT)
27
+ throw new Error("invalid resource type `Agent`");
28
+ const agent = common_1.CommonConnect.mapToAgent(config);
29
+ agent.domain = (0, find_1.findByRef)(config.spec.domainRef, list);
30
+ agent.credentials = (0, find_1.findByRef)(config.spec.credentialsRef, list);
31
+ return agent;
32
+ }
33
+ exports.agentsLoader = agentsLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function credentialsLoader(config: CC.UserConfig): CC.Credentials;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.credentialsLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ function credentialsLoader(config) {
25
+ if (config.kind !== common_1.CommonConnect.Kind.CREDENTIALS)
26
+ throw new Error("invalid resource type `Credentials`");
27
+ return common_1.CommonConnect.mapToCredentials(config);
28
+ }
29
+ exports.credentialsLoader = credentialsLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function domainsLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Domain;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.domainsLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ const find_1 = require("./find");
25
+ function domainsLoader(config, list) {
26
+ var _a;
27
+ if (config.kind !== common_1.CommonConnect.Kind.DOMAIN)
28
+ throw new Error("invalid resource type `Domain`");
29
+ const egressPolicies = (_a = config.spec.context.egressPolicies) === null || _a === void 0 ? void 0 : _a.map((policy) => {
30
+ return {
31
+ rule: policy.rule,
32
+ numberRef: policy.numberRef,
33
+ number: (0, find_1.findByRef)(policy.numberRef, list)
34
+ };
35
+ });
36
+ const domain = common_1.CommonConnect.mapToDomain(config);
37
+ domain.egressPolicies = egressPolicies;
38
+ domain.accessControlList = (0, find_1.findByRef)(config.spec.accessControlListRef, list);
39
+ return domain;
40
+ }
41
+ exports.domainsLoader = domainsLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare const findByRef: (ref: string, list: CC.UserConfig[]) => CC.AccessControlList | CC.Domain | CC.INumber | CC.Agent | CC.Credentials | CC.Trunk | CC.Peer;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findByRef = void 0;
4
+ /*
5
+ * Copyright (C) 2023 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 logger_1 = require("@fonoster/logger");
23
+ const loader_1 = require("./loader");
24
+ const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
25
+ const findByRef = (ref, list) => {
26
+ const resource = list.find((r) => r.ref === ref);
27
+ if (ref != null && resource == null) {
28
+ logger.error(`the resource with ref ${ref} does not exist in the configuration file; exiting`);
29
+ process.exit(1);
30
+ }
31
+ return resource ? (0, loader_1.getLoader)(resource.kind)(resource, list) : null;
32
+ };
33
+ exports.findByRef = findByRef;
@@ -0,0 +1 @@
1
+ export { getLoader } from "./loader";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLoader = void 0;
4
+ /*
5
+ * Copyright (C) 2023 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
+ var loader_1 = require("./loader");
23
+ Object.defineProperty(exports, "getLoader", { enumerable: true, get: function () { return loader_1.getLoader; } });
@@ -0,0 +1,8 @@
1
+ import { agentsLoader } from "./agents";
2
+ import { domainsLoader } from "./domains";
3
+ import { credentialsLoader } from "./credentials";
4
+ import { trunksLoader } from "./trunks";
5
+ import { peersLoader } from "./peers";
6
+ import { numbersLoader } from "./numbers";
7
+ import { aclLoader } from "./acl";
8
+ export declare const getLoader: (kind: string) => typeof agentsLoader | typeof domainsLoader | typeof peersLoader | typeof numbersLoader | typeof trunksLoader | typeof credentialsLoader | typeof aclLoader;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLoader = void 0;
4
+ /*
5
+ * Copyright (C) 2023 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
+ const agents_1 = require("./agents");
24
+ const domains_1 = require("./domains");
25
+ const credentials_1 = require("./credentials");
26
+ const trunks_1 = require("./trunks");
27
+ const peers_1 = require("./peers");
28
+ const numbers_1 = require("./numbers");
29
+ const acl_1 = require("./acl");
30
+ const getLoader = (kind) => {
31
+ switch (kind) {
32
+ case common_1.CommonConnect.Kind.AGENT:
33
+ return agents_1.agentsLoader;
34
+ case common_1.CommonConnect.Kind.DOMAIN:
35
+ return domains_1.domainsLoader;
36
+ case common_1.CommonConnect.Kind.PEER:
37
+ return peers_1.peersLoader;
38
+ case common_1.CommonConnect.Kind.NUMBER:
39
+ return numbers_1.numbersLoader;
40
+ case common_1.CommonConnect.Kind.TRUNK:
41
+ return trunks_1.trunksLoader;
42
+ case common_1.CommonConnect.Kind.CREDENTIALS:
43
+ return credentials_1.credentialsLoader;
44
+ case common_1.CommonConnect.Kind.ACL:
45
+ return acl_1.aclLoader;
46
+ }
47
+ };
48
+ exports.getLoader = getLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function numbersLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.INumber;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.numbersLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ const find_1 = require("./find");
25
+ function numbersLoader(config, list) {
26
+ if (config.kind !== common_1.CommonConnect.Kind.NUMBER)
27
+ throw new Error("invalid resource type `Number`");
28
+ const number = common_1.CommonConnect.mapToNumber(config);
29
+ number.trunk = (0, find_1.findByRef)(config.spec.trunkRef, list);
30
+ return number;
31
+ }
32
+ exports.numbersLoader = numbersLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function peersLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Peer;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.peersLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ const find_1 = require("./find");
25
+ function peersLoader(config, list) {
26
+ if (config.kind !== common_1.CommonConnect.Kind.PEER)
27
+ throw new Error("invalid resource type `Peer`");
28
+ const peer = common_1.CommonConnect.mapToPeer(config);
29
+ peer.credentials = (0, find_1.findByRef)(config.spec.credentialsRef, list);
30
+ return peer;
31
+ }
32
+ exports.peersLoader = peersLoader;
@@ -0,0 +1,2 @@
1
+ import { CommonConnect as CC } from "@routr/common";
2
+ export declare function trunksLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Trunk;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trunksLoader = void 0;
4
+ /* eslint-disable require-jsdoc */
5
+ /*
6
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
+ * http://github.com/fonoster/routr
8
+ *
9
+ * This file is part of Routr.
10
+ *
11
+ * Licensed under the MIT License (the "License");
12
+ * you may not use this file except in compliance with
13
+ * the License. You may obtain a copy of the License at
14
+ *
15
+ * https://opensource.org/licenses/MIT
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software
18
+ * distributed under the License is distributed on an "AS IS" BASIS,
19
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ * See the License for the specific language governing permissions and
21
+ * limitations under the License.
22
+ */
23
+ const common_1 = require("@routr/common");
24
+ const find_1 = require("./find");
25
+ function trunksLoader(config, list) {
26
+ if (config.kind !== common_1.CommonConnect.Kind.TRUNK)
27
+ throw new Error("invalid resource type `Trunk`");
28
+ const inbound = config.spec.inbound;
29
+ const outbound = config.spec.outbound;
30
+ const trunk = common_1.CommonConnect.mapToTrunk(config);
31
+ trunk.inboundCredentials = (0, find_1.findByRef)(inbound.credentialsRef, list);
32
+ trunk.outboundCredentials = (0, find_1.findByRef)(outbound.credentialsRef, list);
33
+ trunk.accessControlList = (0, find_1.findByRef)(inbound.accessControlListRef, list);
34
+ return trunk;
35
+ }
36
+ exports.trunksLoader = trunksLoader;
package/dist/utils.js CHANGED
@@ -44,9 +44,9 @@ const checkReferences = (resources) => {
44
44
  function loadResources(resourcesPath, kind) {
45
45
  const all = [];
46
46
  const files = (0, fs_1.readdirSync)(resourcesPath);
47
- files.forEach((file) => {
47
+ files === null || files === void 0 ? void 0 : files.forEach((file) => {
48
48
  const resources = common_1.Helper.readConfigFile(`${resourcesPath}/${file}`);
49
- resources.forEach((resource) => {
49
+ resources === null || resources === void 0 ? void 0 : resources.forEach((resource) => {
50
50
  resource.kind = resource.kind.toLowerCase();
51
51
  // Assert the reference has no spaces
52
52
  if (resource.ref.includes(" ")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/simpledata",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "Files-based API Server for Routr Connect",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -53,5 +53,5 @@
53
53
  "@types/google-protobuf": "^3.15.6",
54
54
  "@types/jsonpath": "^0.2.0"
55
55
  },
56
- "gitHead": "87f2724c378af3b3b3a4ae22b91dfa63201161d3"
56
+ "gitHead": "917a3bac2a626cada27ed6f11654ae312bf95a12"
57
57
  }
package/dist/loaders.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { CommonConnect as CC } from "@routr/common";
2
- export declare const getLoader: (kind: string) => typeof agentLoader | typeof domainLoader | typeof peerLoader | typeof numberLoader | typeof trunkLoader | typeof credentialsLoader | typeof aclLoader;
3
- export declare function agentLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Agent;
4
- export declare function domainLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Domain;
5
- export declare function peerLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Peer;
6
- export declare function numberLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.INumber;
7
- export declare function trunkLoader(config: CC.UserConfig, list: CC.UserConfig[]): CC.Trunk;
8
- export declare function credentialsLoader(config: CC.UserConfig): CC.Credentials;
9
- export declare function aclLoader(config: CC.UserConfig): CC.AccessControlList;
package/dist/loaders.js DELETED
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.aclLoader = exports.credentialsLoader = exports.trunkLoader = exports.numberLoader = exports.peerLoader = exports.domainLoader = exports.agentLoader = exports.getLoader = void 0;
4
- /*
5
- * Copyright (C) 2023 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
- /* eslint-disable require-jsdoc */
23
- const logger_1 = require("@fonoster/logger");
24
- const common_1 = require("@routr/common");
25
- const logger = (0, logger_1.getLogger)({ service: "simpledata", filePath: __filename });
26
- const findByRef = (ref, list) => {
27
- const resource = list.find((r) => r.ref === ref);
28
- if (ref != null && resource == null) {
29
- logger.error(`the resource with ref ${ref} does not exist in the configuration file; exiting`);
30
- process.exit(1);
31
- }
32
- return resource ? (0, exports.getLoader)(resource.kind)(resource, list) : null;
33
- };
34
- const getLoader = (kind) => {
35
- switch (kind) {
36
- case common_1.CommonConnect.Kind.AGENT:
37
- return agentLoader;
38
- case common_1.CommonConnect.Kind.DOMAIN:
39
- return domainLoader;
40
- case common_1.CommonConnect.Kind.PEER:
41
- return peerLoader;
42
- case common_1.CommonConnect.Kind.NUMBER:
43
- return numberLoader;
44
- case common_1.CommonConnect.Kind.TRUNK:
45
- return trunkLoader;
46
- case common_1.CommonConnect.Kind.CREDENTIALS:
47
- return credentialsLoader;
48
- case common_1.CommonConnect.Kind.ACL:
49
- return aclLoader;
50
- }
51
- };
52
- exports.getLoader = getLoader;
53
- function agentLoader(config, list) {
54
- if (config.kind !== common_1.CommonConnect.Kind.AGENT)
55
- throw new Error("invalid resource type `Agent`");
56
- const agent = common_1.CommonConnect.mapToAgent(config);
57
- agent.domain = findByRef(config.spec.domainRef, list);
58
- agent.credentials = findByRef(config.spec.credentialsRef, list);
59
- return agent;
60
- }
61
- exports.agentLoader = agentLoader;
62
- function domainLoader(config, list) {
63
- var _a;
64
- if (config.kind !== common_1.CommonConnect.Kind.DOMAIN)
65
- throw new Error("invalid resource type `Domain`");
66
- const egressPolicies = (_a = config.spec.context.egressPolicies) === null || _a === void 0 ? void 0 : _a.map((policy) => {
67
- return {
68
- rule: policy.rule,
69
- numberRef: policy.numberRef,
70
- number: findByRef(policy.numberRef, list)
71
- };
72
- });
73
- const domain = common_1.CommonConnect.mapToDomain(config);
74
- domain.egressPolicies = egressPolicies;
75
- domain.accessControlList = findByRef(config.spec.accessControlListRef, list);
76
- return domain;
77
- }
78
- exports.domainLoader = domainLoader;
79
- function peerLoader(config, list) {
80
- if (config.kind !== common_1.CommonConnect.Kind.PEER)
81
- throw new Error("invalid resource type `Peer`");
82
- const peer = common_1.CommonConnect.mapToPeer(config);
83
- peer.credentials = findByRef(config.spec.credentialsRef, list);
84
- return peer;
85
- }
86
- exports.peerLoader = peerLoader;
87
- function numberLoader(config, list) {
88
- if (config.kind !== common_1.CommonConnect.Kind.NUMBER)
89
- throw new Error("invalid resource type `Number`");
90
- const number = common_1.CommonConnect.mapToNumber(config);
91
- number.trunk = findByRef(config.spec.trunkRef, list);
92
- return number;
93
- }
94
- exports.numberLoader = numberLoader;
95
- function trunkLoader(config, list) {
96
- if (config.kind !== common_1.CommonConnect.Kind.TRUNK)
97
- throw new Error("invalid resource type `Trunk`");
98
- const inbound = config.spec.inbound;
99
- const outbound = config.spec.outbound;
100
- const trunk = common_1.CommonConnect.mapToTrunk(config);
101
- trunk.inboundCredentials = findByRef(inbound.credentialsRef, list);
102
- trunk.outboundCredentials = findByRef(outbound.credentialsRef, list);
103
- trunk.accessControlList = findByRef(inbound.accessControlListRef, list);
104
- return trunk;
105
- }
106
- exports.trunkLoader = trunkLoader;
107
- function credentialsLoader(config) {
108
- if (config.kind !== common_1.CommonConnect.Kind.CREDENTIALS)
109
- throw new Error("invalid resource type `Credentials`");
110
- return common_1.CommonConnect.mapToCredentials(config);
111
- }
112
- exports.credentialsLoader = credentialsLoader;
113
- function aclLoader(config) {
114
- if (config.kind !== common_1.CommonConnect.Kind.ACL)
115
- throw new Error("invalid resource type `AccessControlList`");
116
- return common_1.CommonConnect.mapToACL(config);
117
- }
118
- exports.aclLoader = aclLoader;