@ocap/message 1.28.8 → 1.29.0

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/lib/provider.js DELETED
@@ -1,68 +0,0 @@
1
- const providers = [];
2
- const enums = {};
3
- const messages = {};
4
-
5
- function getMessageType(type) {
6
- const provider = providers.find((x) => x.getMessageType(type).fn);
7
- if (provider) {
8
- return provider.getMessageType(type);
9
- }
10
-
11
- return {};
12
- }
13
-
14
- function toTypeUrl(type) {
15
- const provider = providers.find((x) => x.toTypeUrl(type) !== type);
16
- if (provider) {
17
- return provider.toTypeUrl(type);
18
- }
19
-
20
- return type;
21
- }
22
-
23
- function fromTypeUrl(url) {
24
- const provider = providers.find((x) => x.fromTypeUrl(url) !== url);
25
- if (provider) {
26
- return provider.fromTypeUrl(url);
27
- }
28
-
29
- return url;
30
- }
31
-
32
- /**
33
- * Add type provider that can be used to format/create messages
34
- *
35
- * @param {object} provider - proto generated from {@see @ocap/proto}
36
- */
37
- function addProvider(provider) {
38
- if (['getMessageType', 'toTypeUrl', 'fromTypeUrl'].some((x) => typeof provider[x] !== 'function')) {
39
- throw new Error('addProvider requires a valid proto provider');
40
- }
41
-
42
- if (providers.includes(provider) === false) {
43
- providers.push(provider);
44
-
45
- if (provider.enums) {
46
- Object.assign(enums, provider.enums);
47
- }
48
- if (provider.messages) {
49
- Object.assign(messages, provider.messages);
50
- }
51
- }
52
- }
53
-
54
- function resetProviders() {
55
- while (providers.length) {
56
- providers.pop();
57
- }
58
- }
59
-
60
- module.exports = {
61
- addProvider,
62
- resetProviders,
63
- enums,
64
- messages,
65
- getMessageType,
66
- toTypeUrl,
67
- fromTypeUrl,
68
- };