navi-hey 1.4.1 → 1.5.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.
@@ -17,7 +17,9 @@ class AssetRequestEnqueuer {
17
17
  * @param {string} rawHtml The raw HTML response body.
18
18
  * @param {AssetRequest} assetRequest The asset extraction rule.
19
19
  * @param {object} jobRegistry The job registry used to enqueue AssetDownloadJobs.
20
- * @param {object} clientRegistry The client registry used for URL resolution.
20
+ * @param {NamespaceMap} clientRegistry The namespace map used for URL resolution.
21
+ * Asset/HTML-parse client resolution is not namespace-aware: lookups always
22
+ * resolve against the `default` namespace.
21
23
  */
22
24
  constructor(rawHtml, assetRequest, jobRegistry, clientRegistry) {
23
25
  this.#rawHtml = rawHtml;
@@ -64,7 +66,7 @@ class AssetRequestEnqueuer {
64
66
  if (url.startsWith('//')) {
65
67
  return `https:${url}`;
66
68
  }
67
- const client = this.#clientRegistry.getClient(this.#assetRequest.client);
69
+ const client = this.#clientRegistry.getClient('default', this.#assetRequest.client);
68
70
  return `${client.baseUrl}${url}`;
69
71
  }
70
72
  }
@@ -0,0 +1,15 @@
1
+ import { ConfigurationFileNotFound } from './ConfigurationFileNotFound.js';
2
+
3
+ /**
4
+ * ConfigurationIncludeNotFound is thrown when a file referenced by a top-level
5
+ * `include:` list cannot be read.
6
+ * @author darthjee
7
+ */
8
+ class ConfigurationIncludeNotFound extends ConfigurationFileNotFound {
9
+ constructor(file) {
10
+ super(file);
11
+ this.name = 'ConfigurationIncludeNotFound';
12
+ }
13
+ }
14
+
15
+ export { ConfigurationIncludeNotFound };
@@ -0,0 +1,23 @@
1
+ import { AppError } from '../AppError.js';
2
+
3
+ /**
4
+ * DuplicateNamespaceItem is thrown when two files contributing to the same
5
+ * namespace declare a resource or client under the same name.
6
+ * @author darthjee
7
+ */
8
+ class DuplicateNamespaceItem extends AppError {
9
+ /**
10
+ * @param {string} itemName - The duplicated resource/client name.
11
+ * @param {object} attributes - Additional attributes describing the duplication.
12
+ * @param {string} attributes.namespace - The namespace where the duplication happened.
13
+ * @param {string} [attributes.itemType='Item'] - Either "resource" or "client".
14
+ */
15
+ constructor(itemName, { namespace, itemType = 'Item' } = {}) {
16
+ super(`${itemType} "${itemName}" is already declared in namespace "${namespace}".`);
17
+ this.itemName = itemName;
18
+ this.namespace = namespace;
19
+ this.itemType = itemType;
20
+ }
21
+ }
22
+
23
+ export { DuplicateNamespaceItem };
@@ -0,0 +1,16 @@
1
+ import { ItemNotFound } from './ItemNotFound.js';
2
+
3
+ /**
4
+ * NamespaceNotFound is a custom error class thrown when a requested namespace
5
+ * cannot be found in the NamespaceMap.
6
+ * @author darthjee
7
+ */
8
+ class NamespaceNotFound extends ItemNotFound {
9
+ constructor(namespaceName) {
10
+ super(namespaceName, { itemType: 'Namespace' });
11
+
12
+ this.namespaceName = namespaceName;
13
+ }
14
+ }
15
+
16
+ export { NamespaceNotFound };
@@ -19,7 +19,8 @@ class AssetDownloadJob extends Job {
19
19
  * @param {string} params.url - The fully-resolved asset URL to fetch.
20
20
  * @param {string} [params.client] - Named client to use (defaults to `'default'`).
21
21
  * @param {number} params.status - Expected HTTP status code.
22
- * @param {object} params.clientRegistry - The client registry used to look up the client.
22
+ * @param {NamespaceMap} params.clientRegistry - The namespace map used to look up the client.
23
+ * Resolution always targets the `default` namespace (not namespace-aware).
23
24
  */
24
25
  constructor({ id, url, client, status, clientRegistry }) {
25
26
  super({ id });
@@ -46,7 +47,7 @@ class AssetDownloadJob extends Job {
46
47
  logContext.debug(`AssetDownloadJob #${this.id} performing`);
47
48
  try {
48
49
  this.lastError = undefined;
49
- const client = this.#clientRegistry.getClient(this.#clientName);
50
+ const client = this.#clientRegistry.getClient('default', this.#clientName);
50
51
  return await client.performUrl(this.#url, this.#status, logContext);
51
52
  } catch (error) {
52
53
  logContext.error(`AssetDownloadJob #${this.id} failed: ${error}`);
@@ -18,7 +18,7 @@ class ResourceRequestJob extends Job {
18
18
  * @param {string} params.id - The unique identifier for this job.
19
19
  * @param {ResourceRequest} params.resourceRequest - The resource request associated with this job.
20
20
  * @param {object} params.parameters - Additional parameters for the request.
21
- * @param {ClientRegistry} params.clients - Clients registry to be used in a request.
21
+ * @param {NamespaceMap} params.clients - The namespace map used to resolve the client for this request.
22
22
  */
23
23
  constructor({ id, resourceRequest, parameters, clients }) {
24
24
  super({ id });
@@ -87,7 +87,11 @@ class ResourceRequestJob extends Job {
87
87
  */
88
88
  #getClient() {
89
89
  if (!this.#client) {
90
- this.#client = this.#clients.getClient(this.#resourceRequest.clientName);
90
+ this.#client = this.#clients.getClient(
91
+ this.#resourceRequest.namespace,
92
+ this.#resourceRequest.clientName,
93
+ this.#resourceRequest.clientNamespace,
94
+ );
91
95
  }
92
96
  return this.#client;
93
97
  }
@@ -1,26 +1,33 @@
1
1
  import { LogConfig } from './LogConfig.js';
2
2
  import { ClientRegistry } from '../../registry/ClientRegistry.js';
3
+ import { NamespaceMap } from '../../registry/NamespaceMap.js';
3
4
  import { ResourceRegistry } from '../../registry/ResourceRegistry.js';
4
5
  import { ConfigLoader } from '../../services/ConfigLoader.js';
5
6
 
7
+ const DEFAULT_NAMESPACE = 'default';
8
+
6
9
  /**
7
10
  * Config is a class that represents the configuration for the application.
8
- * It includes the resources and clients that are to be included in the configuration.
11
+ * It includes the namespace map (resources/clients, grouped by namespace) that is
12
+ * to be included in the configuration.
9
13
  * @author darthjee
10
14
  */
11
15
  class Config {
12
16
  /**
13
17
  * @param {object} params initialization parameters for the Config instance.
14
- * @param {Record<string, Resource>} params.resources - A mapping of resource names to Resource instances.
15
- * @param {Record<string, Client>} params.clients - A mapping of client names to Client instances.
18
+ * @param {Record<string, Namespace>} params.namespaceMap - A mapping of namespace name to Namespace instance.
16
19
  * @param {WorkersConfig} params.workersConfig - The configuration for worker instances.
17
20
  * @param {WebConfig|null} [params.webConfig] - Optional web server configuration.
18
21
  * @param {LogConfig} [params.logConfig] - Optional log configuration.
19
22
  * @param {FailureConfig|null} [params.failureConfig] - Optional failure threshold configuration.
20
23
  */
21
- constructor({ resources, clients, workersConfig, webConfig, logConfig, failureConfig }) {
22
- this.resourceRegistry = ResourceRegistry.build(resources);
23
- this.clientRegistry = ClientRegistry.build(clients);
24
+ constructor({ namespaceMap, workersConfig, webConfig, logConfig, failureConfig }) {
25
+ this.namespaceMap = NamespaceMap.build(namespaceMap);
26
+
27
+ const defaultNamespace = namespaceMap[DEFAULT_NAMESPACE];
28
+ this.resourceRegistry = ResourceRegistry.build(defaultNamespace ? defaultNamespace.resourceRegistry.items : {});
29
+ this.clientRegistry = ClientRegistry.build(defaultNamespace ? defaultNamespace.clientRegistry.items : {});
30
+
24
31
  this.workersConfig = workersConfig;
25
32
  this.webConfig = webConfig ?? null;
26
33
  this.logConfig = logConfig ?? new LogConfig();
@@ -28,18 +35,22 @@ class Config {
28
35
  }
29
36
 
30
37
  /**
31
- * Returns the resource identified by the given name.
38
+ * Returns the resource identified by the given name, resolved as if the caller
39
+ * originated from the `default` namespace.
32
40
  *
33
41
  * @param {string} name The name of the resource to retrieve.
42
+ * @param {string|null} [namespace=null] Explicit target namespace, or null to resolve
43
+ * against `default` (falling back to `default` again when not found there either).
34
44
  * @returns {Resource} The matching Resource instance.
35
45
  * @throws {Error} Throws when no resource with the given name exists.
36
46
  */
37
- getResource(name) {
38
- return this.resourceRegistry.getItem(name);
47
+ getResource(name, namespace = null) {
48
+ return this.namespaceMap.getResource(DEFAULT_NAMESPACE, name, namespace);
39
49
  }
40
50
 
41
51
  /**
42
- * Returns the client identified by the given name.
52
+ * Returns the client identified by the given name, resolved as if the caller
53
+ * originated from the `default` namespace.
43
54
  *
44
55
  * When `name` is `"default"` or not provided, the method first tries to
45
56
  * return the client registered under the `"default"` key. If no such
@@ -49,11 +60,13 @@ class Config {
49
60
  * @see ClientRegistry#getClient for the client retrieval logic.
50
61
  *
51
62
  * @param {string} [name] The name of the client to retrieve.
63
+ * @param {string|null} [namespace=null] Explicit target namespace, or null to resolve
64
+ * against `default` (falling back to `default` again when not found there either).
52
65
  * @returns {Client} The matching Client instance.
53
66
  * @throws {ClientNotFound} Throws when the named or default client is not found.
54
67
  */
55
- getClient(name) {
56
- return this.clientRegistry.getClient(name);
68
+ getClient(name, namespace = null) {
69
+ return this.namespaceMap.getClient(DEFAULT_NAMESPACE, name, namespace);
57
70
  }
58
71
 
59
72
  /**
@@ -70,4 +83,4 @@ class Config {
70
83
  }
71
84
  }
72
85
 
73
- export { Config };
86
+ export { Config };
@@ -11,13 +11,15 @@ class WebConfig {
11
11
  * @param {number} [config.logs_page_size=20] - Maximum number of log entries per page.
12
12
  * @param {boolean} [config.enable_shutdown=true] - Whether the shutdown button is enabled.
13
13
  * @param {boolean} [config.autostart=true] - Whether the engine starts processing immediately at boot.
14
+ * @param {number} [config.idle_timeout=0] - Seconds of inactivity (no busy workers, no queued jobs) before the application auto-shuts-down. `0` disables auto-shutdown.
14
15
  * @param {Array<string|object>} [config.links=[]] - Links shown in the web UI.
15
16
  */
16
- constructor({ port, logs_page_size: logsPageSize = 20, enable_shutdown: enableShutdown = true, autostart = true, links = [] }) {
17
+ constructor({ port, logs_page_size: logsPageSize = 20, enable_shutdown: enableShutdown = true, autostart = true, idle_timeout: idleTimeout = 0, links = [] }) {
17
18
  this.port = port;
18
19
  this.logsPageSize = logsPageSize;
19
20
  this.enableShutdown = enableShutdown;
20
21
  this.autostart = autostart;
22
+ this.idleTimeout = idleTimeout;
21
23
  this.links = links.map((link) => Link.fromObject(link));
22
24
  }
23
25
  }
@@ -10,36 +10,44 @@ class Resource {
10
10
  * @param {object} params - The parameters for creating a Resource instance.
11
11
  * @param {string} params.name - The name of the resource.
12
12
  * @param {Array} params.resourceRequests - The resource requests associated with the resource.
13
+ * @param {string} [params.namespace='default'] - The namespace this resource was declared in.
13
14
  */
14
- constructor({ name, resourceRequests }) {
15
+ constructor({ name, resourceRequests, namespace = 'default' }) {
15
16
  this.name = name;
16
17
  this.resourceRequests = resourceRequests;
18
+ this.namespace = namespace;
17
19
  }
18
20
 
19
21
  /**
20
22
  * Creates a Resource instance from a plain object.
21
23
  * @param {object} obj - The plain object representing a resource.
22
24
  * @param {string} obj.name - The name of the resource.
23
- * @param {string} [obj.client] - The name of the client to use for requests from this resource.
25
+ * @param {string|{name: string, namespace: string}} [obj.client] - The client to use for requests from
26
+ * this resource: either the bare client name, or an object with an explicit target `namespace`.
24
27
  * @param {Array<{url: string, status: number}>} obj.resourceRequests -
25
28
  * The resource requests associated with the resource.
29
+ * @param {object} [options={}] - Additional options.
30
+ * @param {string} [options.namespace='default'] - The namespace this resource was declared in.
26
31
  * @returns {Resource} A new Resource instance.
27
32
  */
28
- static fromObject(obj) {
33
+ static fromObject(obj, { namespace = 'default' } = {}) {
29
34
  return new Resource({
30
35
  name: obj.name,
31
- resourceRequests: ResourceRequest.fromList(obj.resourceRequests, { clientName: obj.client })
36
+ namespace,
37
+ resourceRequests: ResourceRequest.fromList(obj.resourceRequests, { clientName: obj.client, namespace })
32
38
  });
33
39
  }
34
40
 
35
41
  /**
36
42
  * Creates a list of Resource instances from a plain object.
37
43
  * @param {object} object - The plain object representing multiple resources.
44
+ * @param {object} [options={}] - Additional options.
45
+ * @param {string} [options.namespace='default'] - The namespace these resources were declared in.
38
46
  * @returns {Array<Resource>} A list of Resource instances.
39
47
  */
40
- static fromListObject(object) {
48
+ static fromListObject(object, { namespace = 'default' } = {}) {
41
49
  return Object.entries(object).map(([resourceName, requests]) => {
42
- return Resource.fromObject({ name: resourceName, resourceRequests: requests});
50
+ return Resource.fromObject({ name: resourceName, resourceRequests: requests }, { namespace });
43
51
  });
44
52
  }
45
53
  }
@@ -12,23 +12,32 @@ import { Application } from '../../services/Application.js';
12
12
  */
13
13
  class ResourceRequest {
14
14
  #clientName;
15
+ #clientNamespace;
16
+ #namespace;
15
17
 
16
18
  /**
17
19
  * @param {object} attributes ResourceRequest attributes
18
20
  * @param {string} attributes.url The URL to request.
19
21
  * @param {number} attributes.status The expected status code of the response.
20
- * @param {string} [attributes.clientName] The name of the client to use for this request.
22
+ * @param {string|{name: string, namespace: string}} [attributes.clientName] The client to use for this
23
+ * request: either the bare client name (shorthand), or an object with an explicit target `namespace`.
24
+ * @param {string} [attributes.namespace='default'] The namespace of the Resource that owns this request.
21
25
  * @param {Array} [attributes.actions=[]] List of raw action config objects.
22
26
  * @param {Array} [attributes.assets=[]] List of raw asset extraction rule objects.
23
27
  * @param {Array} [attributes.paginated_actions=[]] List of raw paginated action config objects.
24
28
  */
25
- constructor({ url, status, clientName, actions = [], assets = [], paginated_actions = [] }) {
29
+ constructor({ url, status, clientName, namespace = 'default', actions = [], assets = [], paginated_actions = [] }) {
26
30
  this.url = url;
27
31
  this.status = status;
28
- this.#clientName = clientName;
29
- this.actions = ResourceRequestAction.fromList(actions);
32
+ this.#namespace = namespace;
33
+
34
+ const parsedClient = ResourceRequest.#parseClient(clientName);
35
+ this.#clientName = parsedClient.name;
36
+ this.#clientNamespace = parsedClient.namespace;
37
+
38
+ this.actions = ResourceRequestAction.fromList(actions, { originNamespace: namespace });
30
39
  this.assets = AssetRequest.fromListObject(assets);
31
- this.paginatedActions = ResourceRequestPaginatedAction.fromList(paginated_actions);
40
+ this.paginatedActions = ResourceRequestPaginatedAction.fromList(paginated_actions, { originNamespace: namespace });
32
41
  }
33
42
 
34
43
  /**
@@ -40,6 +49,23 @@ class ResourceRequest {
40
49
  return this.#clientName;
41
50
  }
42
51
 
52
+ /**
53
+ * Returns the explicit target namespace of the client associated with this request,
54
+ * as inherited from the parent Resource's client attribute, or null when not given.
55
+ * @returns {string|null} The client's target namespace, or null when not explicitly set.
56
+ */
57
+ get clientNamespace() {
58
+ return this.#clientNamespace;
59
+ }
60
+
61
+ /**
62
+ * Returns the namespace of the Resource that owns this request.
63
+ * @returns {string} The owning resource's namespace.
64
+ */
65
+ get namespace() {
66
+ return this.#namespace;
67
+ }
68
+
43
69
  /**
44
70
  * Enqueues one ActionProcessingJob per action associated with the resource request.
45
71
  * Returns immediately if there are no actions.
@@ -116,11 +142,27 @@ class ResourceRequest {
116
142
  * Creates a list of ResourceRequest instances from an array of objects.
117
143
  * @param {Array<{ url: string, status: number }>} array list of objects with attributes to create a new ResourceRequest
118
144
  * @param {object} [options={}] optional options to assign to each ResourceRequest
119
- * @param {string} [options.clientName] optional client name to assign to each ResourceRequest
145
+ * @param {string|{name: string, namespace: string}} [options.clientName] optional client reference
146
+ * to assign to each ResourceRequest.
147
+ * @param {string} [options.namespace='default'] the namespace of the owning Resource.
120
148
  * @returns {Array<ResourceRequest>} list of ResourceRequest instances
121
149
  */
122
- static fromList(array, { clientName } = {}) {
123
- return array.map((attrs) => new ResourceRequest({ ...attrs, clientName }));
150
+ static fromList(array, { clientName, namespace = 'default' } = {}) {
151
+ return array.map((attrs) => new ResourceRequest({ ...attrs, clientName, namespace }));
152
+ }
153
+
154
+ /**
155
+ * Parses a raw client reference into a name/namespace pair.
156
+ * Accepts either a bare string (shorthand, resolved in the requester's own namespace)
157
+ * or an object with an explicit target `namespace`.
158
+ * @param {string|{name: string, namespace: string}} [client] The raw client reference.
159
+ * @returns {{name: string|undefined, namespace: string|null}} The parsed client name and target namespace.
160
+ */
161
+ static #parseClient(client) {
162
+ if (client && typeof client === 'object') {
163
+ return { name: client.name, namespace: client.namespace ?? null };
164
+ }
165
+ return { name: client, namespace: null };
124
166
  }
125
167
  }
126
168
 
@@ -1,7 +1,7 @@
1
1
  import { JobRegistry as DefaultJobRegistry } from '../../background/JobRegistry.js';
2
2
  import { MissingActionResource } from '../../exceptions/registry/MissingActionResource.js';
3
3
  import { LogRegistry } from '../../registry/LogRegistry.js';
4
- import { ResourceRegistry as DefaultResourceRegistry } from '../../registry/ResourceRegistry.js';
4
+ import { NamespaceMap as DefaultNamespaceMap } from '../../registry/NamespaceMap.js';
5
5
  import { Application } from '../../services/Application.js';
6
6
  import { ParametersMapper } from '../response/ParametersMapper.js';
7
7
 
@@ -18,23 +18,37 @@ import { ParametersMapper } from '../response/ParametersMapper.js';
18
18
  class ResourceRequestAction {
19
19
  #mapper;
20
20
  #jobRegistry;
21
- #resourceRegistry;
21
+ #namespaceMap;
22
22
 
23
23
  /**
24
24
  * @param {object} attributes Action attributes.
25
25
  * @param {string} attributes.resource Name of the resource to act upon.
26
+ * @param {string|null} [attributes.namespace=null] Explicit target namespace for the resource
27
+ * lookup. When omitted, resolution first tries `originNamespace`, then falls back to `default`.
28
+ * @param {string} [attributes.originNamespace='default'] The namespace of the resource that owns
29
+ * this action (i.e. the namespace this action was declared under). Threaded in at construction
30
+ * time, not read from YAML.
26
31
  * @param {object} [attributes.parameters={}] Key-value map where keys are destination
27
32
  * variable names and values are path expressions (e.g. `parsedBody.id`, `headers['page']`).
28
33
  * @param {object} [attributes.jobRegistry=JobRegistry] The job registry to enqueue jobs to.
29
- * @param {object} [attributes.resourceRegistry=ResourceRegistry] The resource registry to look up resources.
34
+ * @param {object} [attributes.namespaceMap=NamespaceMap] The namespace map used to look up resources.
30
35
  * @throws {MissingActionResource} If resource is absent or falsy.
31
36
  */
32
- constructor({ resource, parameters = {}, jobRegistry = DefaultJobRegistry, resourceRegistry = DefaultResourceRegistry }) {
37
+ constructor({
38
+ resource,
39
+ namespace = null,
40
+ originNamespace = 'default',
41
+ parameters = {},
42
+ jobRegistry = DefaultJobRegistry,
43
+ namespaceMap = DefaultNamespaceMap,
44
+ }) {
33
45
  if (!resource) throw new MissingActionResource();
34
46
  this.resource = resource;
47
+ this.namespace = namespace;
48
+ this.originNamespace = originNamespace;
35
49
  this.#mapper = new ParametersMapper(parameters);
36
50
  this.#jobRegistry = jobRegistry;
37
- this.#resourceRegistry = resourceRegistry;
51
+ this.#namespaceMap = namespaceMap;
38
52
  }
39
53
 
40
54
  /**
@@ -48,7 +62,7 @@ class ResourceRequestAction {
48
62
  execute(responseWrapper) {
49
63
  if (Application.isStopped()) return;
50
64
  const vars = this.#mapper.map(responseWrapper);
51
- const resource = this.#resourceRegistry.getItem(this.resource);
65
+ const resource = this.#namespaceMap.getResource(this.originNamespace, this.resource, this.namespace);
52
66
 
53
67
  for (const resourceRequest of resource.resourceRequests) {
54
68
  this.#jobRegistry.enqueue('ResourceRequestJob', { resourceRequest, parameters: vars });
@@ -59,12 +73,14 @@ class ResourceRequestAction {
59
73
  * Creates a list of ResourceRequestAction instances from an array of raw config objects.
60
74
  * Entries that fail to construct (e.g. missing resource) are logged and skipped.
61
75
  * @param {Array<object>} [array=[]] Raw action config entries.
76
+ * @param {object} [options={}] Additional options.
77
+ * @param {string} [options.originNamespace='default'] The namespace of the resource that owns these actions.
62
78
  * @returns {Array<ResourceRequestAction>} Valid action instances.
63
79
  */
64
- static fromList(array = []) {
80
+ static fromList(array = [], { originNamespace = 'default' } = {}) {
65
81
  return array.flatMap((attrs) => {
66
82
  try {
67
- return [new ResourceRequestAction(attrs)];
83
+ return [new ResourceRequestAction({ ...attrs, originNamespace })];
68
84
  } catch (error) {
69
85
  LogRegistry.error(`Skipping action: ${error}`);
70
86
  return [];
@@ -1,7 +1,7 @@
1
1
  import { JobRegistry as DefaultJobRegistry } from '../../background/JobRegistry.js';
2
2
  import { MissingActionResource } from '../../exceptions/registry/MissingActionResource.js';
3
3
  import { LogRegistry } from '../../registry/LogRegistry.js';
4
- import { ResourceRegistry as DefaultResourceRegistry } from '../../registry/ResourceRegistry.js';
4
+ import { NamespaceMap as DefaultNamespaceMap } from '../../registry/NamespaceMap.js';
5
5
  import { Application } from '../../services/Application.js';
6
6
  import { PaginationConfig } from '../configs/PaginationConfig.js';
7
7
 
@@ -14,29 +14,63 @@ import { PaginationConfig } from '../configs/PaginationConfig.js';
14
14
  */
15
15
  class ResourceRequestPaginatedAction {
16
16
  #resource;
17
+ #namespace;
18
+ #originNamespace;
17
19
  #pagination;
18
20
  #jobRegistry;
19
- #resourceRegistry;
21
+ #namespaceMap;
20
22
 
21
23
  /**
22
24
  * @param {object} attributes Action attributes.
23
25
  * @param {string} attributes.resource Name of the resource to act upon.
26
+ * @param {string|null} [attributes.namespace=null] Explicit target namespace for the resource
27
+ * lookup. When omitted, resolution first tries `originNamespace`, then falls back to `default`.
28
+ * @param {string} [attributes.originNamespace='default'] The namespace of the resource that owns
29
+ * this paginated action. Threaded in at construction time, not read from YAML.
24
30
  * @param {Array<object>} attributes.pagination Pagination config list.
25
31
  * @param {object} [attributes.jobRegistry=JobRegistry] The job registry to enqueue jobs to.
26
- * @param {object} [attributes.resourceRegistry=ResourceRegistry] The resource registry to look up resources.
32
+ * @param {object} [attributes.namespaceMap=NamespaceMap] The namespace map used to look up resources.
27
33
  * @throws {MissingActionResource} If resource is absent or falsy.
28
34
  */
29
35
  constructor({
30
36
  resource,
37
+ namespace = null,
38
+ originNamespace = 'default',
31
39
  pagination,
32
40
  jobRegistry = DefaultJobRegistry,
33
- resourceRegistry = DefaultResourceRegistry,
41
+ namespaceMap = DefaultNamespaceMap,
34
42
  }) {
35
43
  if (!resource) throw new MissingActionResource();
36
44
  this.#resource = resource;
45
+ this.#namespace = namespace;
46
+ this.#originNamespace = originNamespace;
37
47
  this.#pagination = PaginationConfig.fromList(pagination);
38
48
  this.#jobRegistry = jobRegistry;
39
- this.#resourceRegistry = resourceRegistry;
49
+ this.#namespaceMap = namespaceMap;
50
+ }
51
+
52
+ /**
53
+ * The name of the resource to act upon.
54
+ * @returns {string} The resource name.
55
+ */
56
+ get resource() {
57
+ return this.#resource;
58
+ }
59
+
60
+ /**
61
+ * The explicit target namespace for the resource lookup, or null when not given.
62
+ * @returns {string|null} The explicit target namespace.
63
+ */
64
+ get namespace() {
65
+ return this.#namespace;
66
+ }
67
+
68
+ /**
69
+ * The namespace of the resource that owns this paginated action.
70
+ * @returns {string} The origin namespace.
71
+ */
72
+ get originNamespace() {
73
+ return this.#originNamespace;
40
74
  }
41
75
 
42
76
  /**
@@ -51,7 +85,7 @@ class ResourceRequestPaginatedAction {
51
85
 
52
86
  const count = this.#pagination.resolvePages(responseWrapper);
53
87
  const pages = this.#pagination.pageNumbers(count);
54
- const resource = this.#resourceRegistry.getItem(this.#resource);
88
+ const resource = this.#namespaceMap.getResource(this.#originNamespace, this.#resource, this.#namespace);
55
89
 
56
90
  for (const page of pages) {
57
91
  const pageParameters = { ...parameters, [this.#pagination.pageKey]: page };
@@ -64,12 +98,14 @@ class ResourceRequestPaginatedAction {
64
98
  /**
65
99
  * Creates instances from a raw YAML list, skipping invalid entries.
66
100
  * @param {Array<object>} [array=[]] Raw paginated action config entries.
101
+ * @param {object} [options={}] Additional options.
102
+ * @param {string} [options.originNamespace='default'] The namespace of the resource that owns these actions.
67
103
  * @returns {Array<ResourceRequestPaginatedAction>} Valid paginated action instances.
68
104
  */
69
- static fromList(array = []) {
105
+ static fromList(array = [], { originNamespace = 'default' } = {}) {
70
106
  return array.flatMap((attrs) => {
71
107
  try {
72
- return [new ResourceRequestPaginatedAction(attrs)];
108
+ return [new ResourceRequestPaginatedAction({ ...attrs, originNamespace })];
73
109
  } catch (error) {
74
110
  LogRegistry.error(`Skipping paginated_action: ${error}`);
75
111
  return [];
@@ -0,0 +1,26 @@
1
+ import { ClientRegistry } from './ClientRegistry.js';
2
+ import { ResourceRegistry } from './ResourceRegistry.js';
3
+
4
+ /**
5
+ * Namespace groups together the resources and clients contributed by one or more
6
+ * configuration files sharing the same `namespace` name.
7
+ *
8
+ * `resourceRegistry`/`clientRegistry` are plain instances (not the static singleton
9
+ * facade) of the existing `ResourceRegistry`/`ClientRegistry` classes.
10
+ * @author darthjee
11
+ */
12
+ class Namespace {
13
+ /**
14
+ * @param {object} attributes Namespace attributes.
15
+ * @param {string} attributes.name The namespace name.
16
+ * @param {Record<string, Resource>} [attributes.resources={}] Resources declared in this namespace.
17
+ * @param {Record<string, Client>} [attributes.clients={}] Clients declared in this namespace.
18
+ */
19
+ constructor({ name, resources = {}, clients = {} }) {
20
+ this.name = name;
21
+ this.resourceRegistry = new ResourceRegistry(resources);
22
+ this.clientRegistry = new ClientRegistry(clients);
23
+ }
24
+ }
25
+
26
+ export { Namespace };