@fjell/registry 4.4.17 → 4.4.20

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.
Files changed (60) hide show
  1. package/build.js +4 -0
  2. package/dist/Coordinate.d.ts +2 -1
  3. package/dist/Coordinate.d.ts.map +1 -0
  4. package/dist/Instance.d.ts +3 -2
  5. package/dist/Instance.d.ts.map +1 -0
  6. package/dist/Registry.d.ts +1 -0
  7. package/dist/Registry.d.ts.map +1 -0
  8. package/dist/RegistryHub.d.ts +1 -0
  9. package/dist/RegistryHub.d.ts.map +1 -0
  10. package/dist/RegistryStats.d.ts +1 -0
  11. package/dist/RegistryStats.d.ts.map +1 -0
  12. package/dist/errors/CoordinateError.d.ts +1 -0
  13. package/dist/errors/CoordinateError.d.ts.map +1 -0
  14. package/dist/errors/InstanceError.d.ts +1 -0
  15. package/dist/errors/InstanceError.d.ts.map +1 -0
  16. package/dist/errors/RegistryError.d.ts +1 -0
  17. package/dist/errors/RegistryError.d.ts.map +1 -0
  18. package/dist/errors/RegistryHubError.d.ts +1 -0
  19. package/dist/errors/RegistryHubError.d.ts.map +1 -0
  20. package/dist/errors/index.d.ts +1 -0
  21. package/dist/errors/index.d.ts.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +685 -10
  25. package/dist/index.js.map +7 -0
  26. package/dist/logger.d.ts +2 -1
  27. package/dist/logger.d.ts.map +1 -0
  28. package/dist/types.d.ts +1 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/docs/docs.config.ts +1 -32
  31. package/docs/package-lock.json +5129 -0
  32. package/docs/package.json +2 -2
  33. package/docs/src/types.d.ts +13 -5
  34. package/docs/timing-range.svg +40 -40
  35. package/package.json +21 -33
  36. package/tsconfig.docs.json +28 -0
  37. package/vitest.config.ts +17 -0
  38. package/MIGRATION_SUMMARY.md +0 -200
  39. package/dist/Coordinate.cjs +0 -32
  40. package/dist/Coordinate.js +0 -28
  41. package/dist/Instance.cjs +0 -24
  42. package/dist/Instance.js +0 -19
  43. package/dist/Registry.cjs +0 -182
  44. package/dist/Registry.js +0 -178
  45. package/dist/RegistryHub.cjs +0 -94
  46. package/dist/RegistryHub.js +0 -90
  47. package/dist/RegistryStats.cjs +0 -198
  48. package/dist/RegistryStats.js +0 -194
  49. package/dist/errors/CoordinateError.cjs +0 -70
  50. package/dist/errors/CoordinateError.js +0 -63
  51. package/dist/errors/InstanceError.cjs +0 -101
  52. package/dist/errors/InstanceError.js +0 -92
  53. package/dist/errors/RegistryError.cjs +0 -82
  54. package/dist/errors/RegistryError.js +0 -75
  55. package/dist/errors/RegistryHubError.cjs +0 -92
  56. package/dist/errors/RegistryHubError.js +0 -84
  57. package/dist/index.cjs +0 -821
  58. package/dist/index.cjs.map +0 -1
  59. package/dist/logger.cjs +0 -10
  60. package/dist/logger.js +0 -6
package/dist/Registry.cjs DELETED
@@ -1,182 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const logger$1 = require('./logger.cjs');
6
- const Instance = require('./Instance.cjs');
7
- const Coordinate = require('./Coordinate.cjs');
8
- const RegistryStats = require('./RegistryStats.cjs');
9
-
10
- const logger = logger$1.default.get("Registry");
11
- const findScopedInstance = (scopedInstances, requestedScopes)=>{
12
- if (!requestedScopes || requestedScopes.length === 0) {
13
- var _scopedInstances_;
14
- // Return first instance if no scopes specified
15
- const firstInstance = (_scopedInstances_ = scopedInstances[0]) === null || _scopedInstances_ === void 0 ? void 0 : _scopedInstances_.instance;
16
- if (!firstInstance) {
17
- throw new Error('No instances available');
18
- }
19
- return firstInstance;
20
- }
21
- // Find instance that matches all requested scopes
22
- const matchingInstance = scopedInstances.find((scopedInstance)=>{
23
- if (!scopedInstance.scopes) return false;
24
- return requestedScopes.every((scope)=>scopedInstance.scopes && scopedInstance.scopes.includes(scope));
25
- });
26
- if (!matchingInstance) {
27
- throw new Error(`No instance found matching scopes: ${requestedScopes.join(', ')}`);
28
- }
29
- return matchingInstance.instance;
30
- };
31
- const createRegistry = (type, registryHub)=>{
32
- const instanceTree = {};
33
- // Statistics tracking
34
- const registryStats = new RegistryStats.RegistryStats();
35
- /**
36
- * Creates a proxied Registry that automatically injects client information for service-to-service calls
37
- */ const createProxiedRegistry = (callingCoordinate)=>{
38
- const serviceClient = {
39
- registryType: type,
40
- coordinate: {
41
- kta: callingCoordinate.kta,
42
- scopes: callingCoordinate.scopes
43
- }
44
- };
45
- return {
46
- ...registry,
47
- get: (kta, options)=>{
48
- // Automatically inject the calling service as the client if no client is specified
49
- const clientToUse = (options === null || options === void 0 ? void 0 : options.client) || serviceClient;
50
- return registry.get(kta, {
51
- ...options,
52
- client: clientToUse
53
- });
54
- }
55
- };
56
- };
57
- const createInstance = (kta, scopes, factory)=>{
58
- logger.debug(`Creating and registering instance for key path and scopes`, kta, scopes, `in registry type: ${type}`);
59
- // Create coordinate for the instance
60
- const coordinate = Coordinate.createCoordinate(kta, scopes);
61
- // Create a proxied registry that automatically tracks this service as the client
62
- const proxiedRegistry = createProxiedRegistry(coordinate);
63
- // Use factory to create the instance with the proxied registry
64
- const instance = factory(coordinate, {
65
- registry: proxiedRegistry,
66
- registryHub
67
- });
68
- // Validate the created instance
69
- if (!Instance.isInstance(instance)) {
70
- throw new Error(`Factory did not return a valid instance for: ${kta.join('.')}`);
71
- }
72
- // Register the instance
73
- registerInternal(kta, instance, {
74
- scopes
75
- });
76
- return instance;
77
- };
78
- const registerInternal = (kta, instance, options)=>{
79
- const keyPath = [
80
- ...kta
81
- ].reverse(); // Work from most specific to least specific
82
- let currentLevel = instanceTree;
83
- logger.debug(`Registering instance for key path and scopes`, keyPath, options === null || options === void 0 ? void 0 : options.scopes, `in registry type: ${type}`);
84
- if (!Instance.isInstance(instance)) {
85
- throw new Error(`Attempting to register a non-instance: ${kta.join('.')}`);
86
- }
87
- // Navigate to the correct location in the tree
88
- for(let i = 0; i < keyPath.length; i++){
89
- const keyType = keyPath[i];
90
- const isLeaf = i === keyPath.length - 1;
91
- if (!currentLevel[keyType]) {
92
- currentLevel[keyType] = {
93
- instances: [],
94
- children: isLeaf ? null : {}
95
- };
96
- }
97
- if (isLeaf) {
98
- // Add instance to the leaf node
99
- currentLevel[keyType].instances.push({
100
- scopes: options === null || options === void 0 ? void 0 : options.scopes,
101
- instance
102
- });
103
- } else {
104
- // Navigate deeper into the tree
105
- if (!currentLevel[keyType].children) {
106
- currentLevel[keyType].children = {};
107
- }
108
- currentLevel = currentLevel[keyType].children;
109
- }
110
- }
111
- };
112
- const register = (kta, instance, options)=>{
113
- logger.debug('Using deprecated register method. Consider using createInstance instead.');
114
- registerInternal(kta, instance, options);
115
- };
116
- const get = (kta, options)=>{
117
- // Track statistics with kta, scopes, and client
118
- registryStats.recordGetCall(kta, options === null || options === void 0 ? void 0 : options.scopes, options === null || options === void 0 ? void 0 : options.client);
119
- const keyPath = [
120
- ...kta
121
- ].reverse();
122
- let currentLevel = instanceTree;
123
- // Navigate to the target node
124
- for(let i = 0; i < keyPath.length; i++){
125
- const keyType = keyPath[i];
126
- const isLeaf = i === keyPath.length - 1;
127
- if (!currentLevel[keyType]) {
128
- throw new Error(`Instance not found for key path: ${kta.join('.')}, Missing key: ${keyType}`);
129
- }
130
- if (isLeaf) {
131
- // Found the target node, extract instance
132
- const scopedInstances = currentLevel[keyType].instances;
133
- if (scopedInstances.length === 0) {
134
- throw new Error(`No instances registered for key path: ${kta.join('.')}`);
135
- }
136
- return findScopedInstance(scopedInstances, options === null || options === void 0 ? void 0 : options.scopes);
137
- } else {
138
- // Continue navigation
139
- if (!currentLevel[keyType].children) {
140
- throw new Error(`Instance not found for key path: ${kta.join('.')}, No children for: ${keyType}`);
141
- }
142
- currentLevel = currentLevel[keyType].children;
143
- }
144
- }
145
- return null;
146
- };
147
- const getCoordinates = ()=>{
148
- const coordinates = [];
149
- const traverseTree = (node)=>{
150
- for(const keyType in node){
151
- const treeNode = node[keyType];
152
- // Collect coordinates from instances at this level
153
- for (const scopedInstance of treeNode.instances){
154
- coordinates.push(scopedInstance.instance.coordinate);
155
- }
156
- // Recursively traverse children if they exist
157
- if (treeNode.children) {
158
- traverseTree(treeNode.children);
159
- }
160
- }
161
- };
162
- traverseTree(instanceTree);
163
- return coordinates;
164
- };
165
- const getStatistics = ()=>{
166
- return registryStats.getStatistics();
167
- };
168
- const registry = {
169
- type,
170
- registryHub,
171
- createInstance,
172
- register,
173
- get,
174
- getCoordinates,
175
- getStatistics,
176
- instanceTree
177
- };
178
- return registry;
179
- };
180
-
181
- exports.createRegistry = createRegistry;
182
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVnaXN0cnkuY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
package/dist/Registry.js DELETED
@@ -1,178 +0,0 @@
1
- import LibLogger from './logger.js';
2
- import { isInstance } from './Instance.js';
3
- import { createCoordinate } from './Coordinate.js';
4
- import { RegistryStats } from './RegistryStats.js';
5
-
6
- const logger = LibLogger.get("Registry");
7
- const findScopedInstance = (scopedInstances, requestedScopes)=>{
8
- if (!requestedScopes || requestedScopes.length === 0) {
9
- var _scopedInstances_;
10
- // Return first instance if no scopes specified
11
- const firstInstance = (_scopedInstances_ = scopedInstances[0]) === null || _scopedInstances_ === void 0 ? void 0 : _scopedInstances_.instance;
12
- if (!firstInstance) {
13
- throw new Error('No instances available');
14
- }
15
- return firstInstance;
16
- }
17
- // Find instance that matches all requested scopes
18
- const matchingInstance = scopedInstances.find((scopedInstance)=>{
19
- if (!scopedInstance.scopes) return false;
20
- return requestedScopes.every((scope)=>scopedInstance.scopes && scopedInstance.scopes.includes(scope));
21
- });
22
- if (!matchingInstance) {
23
- throw new Error(`No instance found matching scopes: ${requestedScopes.join(', ')}`);
24
- }
25
- return matchingInstance.instance;
26
- };
27
- const createRegistry = (type, registryHub)=>{
28
- const instanceTree = {};
29
- // Statistics tracking
30
- const registryStats = new RegistryStats();
31
- /**
32
- * Creates a proxied Registry that automatically injects client information for service-to-service calls
33
- */ const createProxiedRegistry = (callingCoordinate)=>{
34
- const serviceClient = {
35
- registryType: type,
36
- coordinate: {
37
- kta: callingCoordinate.kta,
38
- scopes: callingCoordinate.scopes
39
- }
40
- };
41
- return {
42
- ...registry,
43
- get: (kta, options)=>{
44
- // Automatically inject the calling service as the client if no client is specified
45
- const clientToUse = (options === null || options === void 0 ? void 0 : options.client) || serviceClient;
46
- return registry.get(kta, {
47
- ...options,
48
- client: clientToUse
49
- });
50
- }
51
- };
52
- };
53
- const createInstance = (kta, scopes, factory)=>{
54
- logger.debug(`Creating and registering instance for key path and scopes`, kta, scopes, `in registry type: ${type}`);
55
- // Create coordinate for the instance
56
- const coordinate = createCoordinate(kta, scopes);
57
- // Create a proxied registry that automatically tracks this service as the client
58
- const proxiedRegistry = createProxiedRegistry(coordinate);
59
- // Use factory to create the instance with the proxied registry
60
- const instance = factory(coordinate, {
61
- registry: proxiedRegistry,
62
- registryHub
63
- });
64
- // Validate the created instance
65
- if (!isInstance(instance)) {
66
- throw new Error(`Factory did not return a valid instance for: ${kta.join('.')}`);
67
- }
68
- // Register the instance
69
- registerInternal(kta, instance, {
70
- scopes
71
- });
72
- return instance;
73
- };
74
- const registerInternal = (kta, instance, options)=>{
75
- const keyPath = [
76
- ...kta
77
- ].reverse(); // Work from most specific to least specific
78
- let currentLevel = instanceTree;
79
- logger.debug(`Registering instance for key path and scopes`, keyPath, options === null || options === void 0 ? void 0 : options.scopes, `in registry type: ${type}`);
80
- if (!isInstance(instance)) {
81
- throw new Error(`Attempting to register a non-instance: ${kta.join('.')}`);
82
- }
83
- // Navigate to the correct location in the tree
84
- for(let i = 0; i < keyPath.length; i++){
85
- const keyType = keyPath[i];
86
- const isLeaf = i === keyPath.length - 1;
87
- if (!currentLevel[keyType]) {
88
- currentLevel[keyType] = {
89
- instances: [],
90
- children: isLeaf ? null : {}
91
- };
92
- }
93
- if (isLeaf) {
94
- // Add instance to the leaf node
95
- currentLevel[keyType].instances.push({
96
- scopes: options === null || options === void 0 ? void 0 : options.scopes,
97
- instance
98
- });
99
- } else {
100
- // Navigate deeper into the tree
101
- if (!currentLevel[keyType].children) {
102
- currentLevel[keyType].children = {};
103
- }
104
- currentLevel = currentLevel[keyType].children;
105
- }
106
- }
107
- };
108
- const register = (kta, instance, options)=>{
109
- logger.debug('Using deprecated register method. Consider using createInstance instead.');
110
- registerInternal(kta, instance, options);
111
- };
112
- const get = (kta, options)=>{
113
- // Track statistics with kta, scopes, and client
114
- registryStats.recordGetCall(kta, options === null || options === void 0 ? void 0 : options.scopes, options === null || options === void 0 ? void 0 : options.client);
115
- const keyPath = [
116
- ...kta
117
- ].reverse();
118
- let currentLevel = instanceTree;
119
- // Navigate to the target node
120
- for(let i = 0; i < keyPath.length; i++){
121
- const keyType = keyPath[i];
122
- const isLeaf = i === keyPath.length - 1;
123
- if (!currentLevel[keyType]) {
124
- throw new Error(`Instance not found for key path: ${kta.join('.')}, Missing key: ${keyType}`);
125
- }
126
- if (isLeaf) {
127
- // Found the target node, extract instance
128
- const scopedInstances = currentLevel[keyType].instances;
129
- if (scopedInstances.length === 0) {
130
- throw new Error(`No instances registered for key path: ${kta.join('.')}`);
131
- }
132
- return findScopedInstance(scopedInstances, options === null || options === void 0 ? void 0 : options.scopes);
133
- } else {
134
- // Continue navigation
135
- if (!currentLevel[keyType].children) {
136
- throw new Error(`Instance not found for key path: ${kta.join('.')}, No children for: ${keyType}`);
137
- }
138
- currentLevel = currentLevel[keyType].children;
139
- }
140
- }
141
- return null;
142
- };
143
- const getCoordinates = ()=>{
144
- const coordinates = [];
145
- const traverseTree = (node)=>{
146
- for(const keyType in node){
147
- const treeNode = node[keyType];
148
- // Collect coordinates from instances at this level
149
- for (const scopedInstance of treeNode.instances){
150
- coordinates.push(scopedInstance.instance.coordinate);
151
- }
152
- // Recursively traverse children if they exist
153
- if (treeNode.children) {
154
- traverseTree(treeNode.children);
155
- }
156
- }
157
- };
158
- traverseTree(instanceTree);
159
- return coordinates;
160
- };
161
- const getStatistics = ()=>{
162
- return registryStats.getStatistics();
163
- };
164
- const registry = {
165
- type,
166
- registryHub,
167
- createInstance,
168
- register,
169
- get,
170
- getCoordinates,
171
- getStatistics,
172
- instanceTree
173
- };
174
- return registry;
175
- };
176
-
177
- export { createRegistry };
178
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVnaXN0cnkuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const logger$1 = require('./logger.cjs');
6
- const RegistryHubError = require('./errors/RegistryHubError.cjs');
7
-
8
- const logger = logger$1.default.get("RegistryHub");
9
- const createRegistryHub = ()=>{
10
- const registries = {};
11
- const createRegistry = (type, factory)=>{
12
- logger.debug(`Creating new registry with type: ${type}`);
13
- if (registries[type]) {
14
- throw new RegistryHubError.DuplicateRegistryTypeError(type);
15
- }
16
- // Create the registry with a reference to this hub
17
- const registry = factory(type, hub);
18
- // Ensure the created registry has a reference to this hub if not already set
19
- if (!('registryHub' in registry) || registry.registryHub !== hub) {
20
- // @ts-expect-error: registryHub is optional and may be readonly, but we want to set it for hub awareness
21
- registry.registryHub = hub;
22
- }
23
- // Register the created registry
24
- registries[type] = registry;
25
- logger.debug(`Successfully created and registered new registry with type: ${type}`);
26
- return registry;
27
- };
28
- const registerRegistry = (registry)=>{
29
- const type = registry.type;
30
- logger.debug(`Registering registry with type: ${type}`);
31
- if (registries[type]) {
32
- throw new RegistryHubError.DuplicateRegistryTypeError(type);
33
- }
34
- registries[type] = registry;
35
- // Ensure the created registry has a reference to this hub if not already set
36
- if (!('registryHub' in registry) || registry.registryHub !== hub) {
37
- // @ts-expect-error: registryHub is optional and may be readonly, but we want to set it for hub awareness
38
- registry.registryHub = hub;
39
- }
40
- logger.debug(`Successfully registered registry with type: ${type}`);
41
- };
42
- const get = (type, kta, options)=>{
43
- var _options_scopes;
44
- logger.debug(`Looking up instance for type: ${type}, kta: ${kta.join('.')}, scopes: ${(options === null || options === void 0 ? void 0 : (_options_scopes = options.scopes) === null || _options_scopes === void 0 ? void 0 : _options_scopes.join(',')) || 'none'}`);
45
- const registry = registries[type];
46
- if (!registry) {
47
- const availableTypes = Object.keys(registries);
48
- throw new RegistryHubError.RegistryTypeNotFoundError(type, availableTypes);
49
- }
50
- return registry.get(kta, options);
51
- };
52
- const getRegistry = (type)=>{
53
- return registries[type] || null;
54
- };
55
- const getRegisteredTypes = ()=>{
56
- return Object.keys(registries);
57
- };
58
- const unregisterRegistry = (type)=>{
59
- if (registries[type]) {
60
- delete registries[type];
61
- logger.debug(`Unregistered registry under type: ${type}`);
62
- return true;
63
- }
64
- return false;
65
- };
66
- const getAllCoordinates = ()=>{
67
- const allCoordinates = [];
68
- for(const registryType in registries){
69
- const registry = registries[registryType];
70
- const coordinates = registry.getCoordinates();
71
- coordinates.forEach((coordinate)=>{
72
- allCoordinates.push({
73
- coordinate,
74
- registryType
75
- });
76
- });
77
- }
78
- logger.debug(`Retrieved ${allCoordinates.length} total coordinates from ${Object.keys(registries).length} registries`);
79
- return allCoordinates;
80
- };
81
- const hub = {
82
- createRegistry,
83
- registerRegistry,
84
- get,
85
- getRegistry,
86
- getRegisteredTypes,
87
- getAllCoordinates,
88
- unregisterRegistry
89
- };
90
- return hub;
91
- };
92
-
93
- exports.createRegistryHub = createRegistryHub;
94
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVnaXN0cnlIdWIuY2pzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -1,90 +0,0 @@
1
- import LibLogger from './logger.js';
2
- import { RegistryTypeNotFoundError, DuplicateRegistryTypeError } from './errors/RegistryHubError.js';
3
-
4
- const logger = LibLogger.get("RegistryHub");
5
- const createRegistryHub = ()=>{
6
- const registries = {};
7
- const createRegistry = (type, factory)=>{
8
- logger.debug(`Creating new registry with type: ${type}`);
9
- if (registries[type]) {
10
- throw new DuplicateRegistryTypeError(type);
11
- }
12
- // Create the registry with a reference to this hub
13
- const registry = factory(type, hub);
14
- // Ensure the created registry has a reference to this hub if not already set
15
- if (!('registryHub' in registry) || registry.registryHub !== hub) {
16
- // @ts-expect-error: registryHub is optional and may be readonly, but we want to set it for hub awareness
17
- registry.registryHub = hub;
18
- }
19
- // Register the created registry
20
- registries[type] = registry;
21
- logger.debug(`Successfully created and registered new registry with type: ${type}`);
22
- return registry;
23
- };
24
- const registerRegistry = (registry)=>{
25
- const type = registry.type;
26
- logger.debug(`Registering registry with type: ${type}`);
27
- if (registries[type]) {
28
- throw new DuplicateRegistryTypeError(type);
29
- }
30
- registries[type] = registry;
31
- // Ensure the created registry has a reference to this hub if not already set
32
- if (!('registryHub' in registry) || registry.registryHub !== hub) {
33
- // @ts-expect-error: registryHub is optional and may be readonly, but we want to set it for hub awareness
34
- registry.registryHub = hub;
35
- }
36
- logger.debug(`Successfully registered registry with type: ${type}`);
37
- };
38
- const get = (type, kta, options)=>{
39
- var _options_scopes;
40
- logger.debug(`Looking up instance for type: ${type}, kta: ${kta.join('.')}, scopes: ${(options === null || options === void 0 ? void 0 : (_options_scopes = options.scopes) === null || _options_scopes === void 0 ? void 0 : _options_scopes.join(',')) || 'none'}`);
41
- const registry = registries[type];
42
- if (!registry) {
43
- const availableTypes = Object.keys(registries);
44
- throw new RegistryTypeNotFoundError(type, availableTypes);
45
- }
46
- return registry.get(kta, options);
47
- };
48
- const getRegistry = (type)=>{
49
- return registries[type] || null;
50
- };
51
- const getRegisteredTypes = ()=>{
52
- return Object.keys(registries);
53
- };
54
- const unregisterRegistry = (type)=>{
55
- if (registries[type]) {
56
- delete registries[type];
57
- logger.debug(`Unregistered registry under type: ${type}`);
58
- return true;
59
- }
60
- return false;
61
- };
62
- const getAllCoordinates = ()=>{
63
- const allCoordinates = [];
64
- for(const registryType in registries){
65
- const registry = registries[registryType];
66
- const coordinates = registry.getCoordinates();
67
- coordinates.forEach((coordinate)=>{
68
- allCoordinates.push({
69
- coordinate,
70
- registryType
71
- });
72
- });
73
- }
74
- logger.debug(`Retrieved ${allCoordinates.length} total coordinates from ${Object.keys(registries).length} registries`);
75
- return allCoordinates;
76
- };
77
- const hub = {
78
- createRegistry,
79
- registerRegistry,
80
- get,
81
- getRegistry,
82
- getRegisteredTypes,
83
- getAllCoordinates,
84
- unregisterRegistry
85
- };
86
- return hub;
87
- };
88
-
89
- export { createRegistryHub };
90
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVnaXN0cnlIdWIuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=