@lorion-org/registry-hub 1.0.0-beta.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # @lorion-org/registry-hub
2
+
3
+ Framework-free typed registry and registry-hub primitives.
4
+
5
+ This package provides small registry primitives for systems that need typed named entries without coupling the registry to a framework runtime.
6
+ It stays intentionally small and does not know anything about Nuxt, Nitro, H3, or app-specific lifecycle hooks.
7
+
8
+ ## Design goals
9
+
10
+ - generic names for reusable runtime terms
11
+ - deterministic overwrite behavior for duplicate item ids
12
+ - lazy registry creation via the hub
13
+ - no framework globals, events, priorities, or persistence
14
+ - `entries()` covers explicit inspect/debug and enumeration use cases in v1
15
+
16
+ ## Installation
17
+
18
+ ```shell
19
+ pnpm add @lorion-org/registry-hub
20
+ ```
21
+
22
+ ## When not to use this package
23
+
24
+ This package is intentionally small. It is not a fit if you need:
25
+
26
+ - ordered or priority-based plugin execution
27
+ - unregister or disposal semantics
28
+ - async lifecycle orchestration
29
+ - persistence or distributed registry state
30
+
31
+ ## API
32
+
33
+ ```ts
34
+ import { createRegistry, createRegistryHub } from '@lorion-org/registry-hub';
35
+ ```
36
+
37
+ ### Create a single registry
38
+
39
+ ```ts
40
+ import { createRegistry, type RegistryItem } from '@lorion-org/registry-hub';
41
+
42
+ type Command = RegistryItem & {
43
+ command: string;
44
+ };
45
+
46
+ const commands = createRegistry<Command>('commands');
47
+
48
+ commands.register({ id: 'build', command: 'pnpm build' });
49
+
50
+ commands.get('build');
51
+ commands.list();
52
+ commands.entries();
53
+ ```
54
+
55
+ ### Use a registry hub
56
+
57
+ ```ts
58
+ import { createRegistryHub, type RegistryItem } from '@lorion-org/registry-hub';
59
+
60
+ type Tool = RegistryItem & {
61
+ title: string;
62
+ };
63
+
64
+ const hub = createRegistryHub();
65
+
66
+ hub.createRegistry<Tool>('tools');
67
+ hub.register<Tool>('tools', { id: 'lint', title: 'Lint workspace' });
68
+
69
+ const tool = hub.get<Tool>('tools', 'lint');
70
+ const tools = hub.list<Tool>('tools');
71
+ const registries = hub.entries();
72
+ ```
73
+
74
+ ### Renderer registry example
75
+
76
+ ```ts
77
+ import { createRegistry, type RegistryItem } from '@lorion-org/registry-hub';
78
+
79
+ type FieldRenderer = RegistryItem & {
80
+ component: string;
81
+ };
82
+
83
+ const renderers = createRegistry<FieldRenderer>('field-renderers');
84
+
85
+ renderers.register([
86
+ { id: 'text', component: 'TextFieldRenderer' },
87
+ { id: 'date', component: 'DateFieldRenderer' },
88
+ ]);
89
+
90
+ const knownRenderers = renderers.entries();
91
+ ```
92
+
93
+ ### Framework recipe
94
+
95
+ The package does not ship framework bindings, but it is designed to be easy to inject into one.
96
+
97
+ ```ts
98
+ import { createRegistryHub } from '@lorion-org/registry-hub';
99
+
100
+ export default defineNuxtPlugin(() => {
101
+ const registryHub = createRegistryHub();
102
+
103
+ return {
104
+ provide: {
105
+ registryHub,
106
+ },
107
+ };
108
+ });
109
+ ```
110
+
111
+ Another plugin can then consume that injected hub and register its own entries.
112
+
113
+ ```ts
114
+ import type { RegistryItem } from '@lorion-org/registry-hub';
115
+
116
+ type Tool = RegistryItem & {
117
+ title: string;
118
+ };
119
+
120
+ export default defineNuxtPlugin((nuxtApp) => {
121
+ nuxtApp.$registryHub.register<Tool>('tools', {
122
+ id: 'lint',
123
+ title: 'Lint workspace',
124
+ });
125
+ });
126
+ ```
127
+
128
+ A composable can later load all entries of one typed registry from that same hub.
129
+
130
+ ```ts
131
+ import type { RegistryItem } from '@lorion-org/registry-hub';
132
+
133
+ type Tool = RegistryItem & {
134
+ title: string;
135
+ };
136
+
137
+ export function useTools(): Tool[] {
138
+ return useNuxtApp().$registryHub.list<Tool>('tools');
139
+ }
140
+ ```
141
+
142
+ Runnable example files live in [`examples/`](./examples).
143
+ The Node example imports the published package name instead of local source files so it mirrors real consumer usage.
144
+ The examples use neutral domain names so the package can be understood as a generic registry utility.
145
+
146
+ ## Local commands
147
+
148
+ ```shell
149
+ cd packages/registry-hub
150
+ pnpm build
151
+ pnpm test
152
+ pnpm coverage
153
+ pnpm typecheck
154
+ pnpm package:check
155
+ ```
156
+
157
+ `pnpm package:check` builds the package, runs `pnpm pack --dry-run`, and
158
+ validates the published package shape with `publint`.
package/dist/index.cjs ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createRegistry: () => createRegistry,
24
+ createRegistryHub: () => createRegistryHub
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ function createRegistry(id) {
28
+ const map = /* @__PURE__ */ new Map();
29
+ return {
30
+ id,
31
+ get: (itemId) => map.get(itemId),
32
+ list: () => Array.from(map.values()),
33
+ entries: () => Array.from(map.entries()),
34
+ register: (items) => {
35
+ const normalized = Array.isArray(items) ? items : [items];
36
+ for (const item of normalized) map.set(item.id, item);
37
+ return normalized;
38
+ }
39
+ };
40
+ }
41
+ function createRegistryHub() {
42
+ const registries = /* @__PURE__ */ new Map();
43
+ return {
44
+ createRegistry: (id) => {
45
+ const existing = registries.get(id);
46
+ if (existing) return existing;
47
+ const created = createRegistry(id);
48
+ registries.set(id, created);
49
+ return created;
50
+ },
51
+ getRegistry: (id) => registries.get(id),
52
+ register: (registryId, items) => {
53
+ const registry = registries.get(registryId) ?? createRegistry(registryId);
54
+ if (!registries.has(registryId))
55
+ registries.set(registryId, registry);
56
+ return registry.register(items);
57
+ },
58
+ get: (registryId, itemId) => {
59
+ const registry = registries.get(registryId);
60
+ return registry?.get(itemId);
61
+ },
62
+ list: (registryId) => {
63
+ const registry = registries.get(registryId);
64
+ return registry?.list() ?? [];
65
+ },
66
+ entries: () => Array.from(registries.entries())
67
+ };
68
+ }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ createRegistry,
72
+ createRegistryHub
73
+ });
@@ -0,0 +1,22 @@
1
+ type RegistryItem = {
2
+ id: string;
3
+ };
4
+ type Registry<T extends RegistryItem = RegistryItem> = {
5
+ id: string;
6
+ get: (id: string) => T | undefined;
7
+ list: () => T[];
8
+ register: (items: T | T[]) => T[];
9
+ entries: () => Array<[string, T]>;
10
+ };
11
+ type RegistryHub = {
12
+ createRegistry: <T extends RegistryItem>(id: string) => Registry<T>;
13
+ getRegistry: <T extends RegistryItem>(id: string) => Registry<T> | undefined;
14
+ register: <T extends RegistryItem>(registryId: string, items: T | T[]) => T[];
15
+ get: <T extends RegistryItem>(registryId: string, itemId: string) => T | undefined;
16
+ list: <T extends RegistryItem>(registryId: string) => T[];
17
+ entries: () => Array<[string, Registry<RegistryItem>]>;
18
+ };
19
+ declare function createRegistry<T extends RegistryItem>(id: string): Registry<T>;
20
+ declare function createRegistryHub(): RegistryHub;
21
+
22
+ export { type Registry, type RegistryHub, type RegistryItem, createRegistry, createRegistryHub };
@@ -0,0 +1,22 @@
1
+ type RegistryItem = {
2
+ id: string;
3
+ };
4
+ type Registry<T extends RegistryItem = RegistryItem> = {
5
+ id: string;
6
+ get: (id: string) => T | undefined;
7
+ list: () => T[];
8
+ register: (items: T | T[]) => T[];
9
+ entries: () => Array<[string, T]>;
10
+ };
11
+ type RegistryHub = {
12
+ createRegistry: <T extends RegistryItem>(id: string) => Registry<T>;
13
+ getRegistry: <T extends RegistryItem>(id: string) => Registry<T> | undefined;
14
+ register: <T extends RegistryItem>(registryId: string, items: T | T[]) => T[];
15
+ get: <T extends RegistryItem>(registryId: string, itemId: string) => T | undefined;
16
+ list: <T extends RegistryItem>(registryId: string) => T[];
17
+ entries: () => Array<[string, Registry<RegistryItem>]>;
18
+ };
19
+ declare function createRegistry<T extends RegistryItem>(id: string): Registry<T>;
20
+ declare function createRegistryHub(): RegistryHub;
21
+
22
+ export { type Registry, type RegistryHub, type RegistryItem, createRegistry, createRegistryHub };
package/dist/index.js ADDED
@@ -0,0 +1,47 @@
1
+ // src/index.ts
2
+ function createRegistry(id) {
3
+ const map = /* @__PURE__ */ new Map();
4
+ return {
5
+ id,
6
+ get: (itemId) => map.get(itemId),
7
+ list: () => Array.from(map.values()),
8
+ entries: () => Array.from(map.entries()),
9
+ register: (items) => {
10
+ const normalized = Array.isArray(items) ? items : [items];
11
+ for (const item of normalized) map.set(item.id, item);
12
+ return normalized;
13
+ }
14
+ };
15
+ }
16
+ function createRegistryHub() {
17
+ const registries = /* @__PURE__ */ new Map();
18
+ return {
19
+ createRegistry: (id) => {
20
+ const existing = registries.get(id);
21
+ if (existing) return existing;
22
+ const created = createRegistry(id);
23
+ registries.set(id, created);
24
+ return created;
25
+ },
26
+ getRegistry: (id) => registries.get(id),
27
+ register: (registryId, items) => {
28
+ const registry = registries.get(registryId) ?? createRegistry(registryId);
29
+ if (!registries.has(registryId))
30
+ registries.set(registryId, registry);
31
+ return registry.register(items);
32
+ },
33
+ get: (registryId, itemId) => {
34
+ const registry = registries.get(registryId);
35
+ return registry?.get(itemId);
36
+ },
37
+ list: (registryId) => {
38
+ const registry = registries.get(registryId);
39
+ return registry?.list() ?? [];
40
+ },
41
+ entries: () => Array.from(registries.entries())
42
+ };
43
+ }
44
+ export {
45
+ createRegistry,
46
+ createRegistryHub
47
+ };
@@ -0,0 +1,10 @@
1
+ import { createRegistryHub } from '@lorion-org/registry-hub';
2
+ import process from 'node:process';
3
+
4
+ const hub = createRegistryHub();
5
+
6
+ hub.register('commands', { id: 'build', command: 'pnpm build' });
7
+ hub.register('tools', { id: 'lint', title: 'Lint workspace' });
8
+
9
+ process.stdout.write(`${JSON.stringify(hub.list('commands'))}\n`);
10
+ process.stdout.write(`${JSON.stringify(hub.get('tools', 'lint'))}\n`);
@@ -0,0 +1,20 @@
1
+ import { createRegistryHub, type RegistryItem } from '@lorion-org/registry-hub';
2
+
3
+ type Command = RegistryItem & {
4
+ command: string;
5
+ };
6
+
7
+ type Tool = RegistryItem & {
8
+ title: string;
9
+ };
10
+
11
+ const hub = createRegistryHub();
12
+
13
+ hub.register<Command>('commands', { id: 'build', command: 'pnpm build' });
14
+ hub.register<Tool>('tools', { id: 'lint', title: 'Lint workspace' });
15
+
16
+ console.log(hub.list<Command>('commands'));
17
+ // [{ id: 'build', command: 'pnpm build' }]
18
+
19
+ console.log(hub.get<Tool>('tools', 'lint'));
20
+ // { id: 'lint', title: 'Lint workspace' }
@@ -0,0 +1,14 @@
1
+ import { createRegistryHub } from '@lorion-org/registry-hub';
2
+
3
+ export default defineNuxtPlugin(() => {
4
+ const registryHub = createRegistryHub();
5
+
6
+ console.log(['registryHub']);
7
+ // ['registryHub']
8
+
9
+ return {
10
+ provide: {
11
+ registryHub,
12
+ },
13
+ };
14
+ });
@@ -0,0 +1,16 @@
1
+ import { createRegistry } from '@lorion-org/registry-hub';
2
+ import process from 'node:process';
3
+
4
+ const renderers = createRegistry('field-renderers');
5
+
6
+ renderers.register([
7
+ { id: 'text', component: 'TextFieldRenderer' },
8
+ { id: 'date', component: 'DateFieldRenderer' },
9
+ ]);
10
+
11
+ process.stdout.write(
12
+ `${renderers.id}:${renderers
13
+ .entries()
14
+ .map(([id]) => id)
15
+ .join(',')}\n`,
16
+ );
@@ -0,0 +1,18 @@
1
+ import { createRegistry, type RegistryItem } from '@lorion-org/registry-hub';
2
+
3
+ type FieldRenderer = RegistryItem & {
4
+ component: string;
5
+ };
6
+
7
+ const renderers = createRegistry<FieldRenderer>('field-renderers');
8
+
9
+ renderers.register([
10
+ { id: 'text', component: 'TextFieldRenderer' },
11
+ { id: 'date', component: 'DateFieldRenderer' },
12
+ ]);
13
+
14
+ console.log(renderers.entries());
15
+ // [
16
+ // ['text', { id: 'text', component: 'TextFieldRenderer' }],
17
+ // ['date', { id: 'date', component: 'DateFieldRenderer' }]
18
+ // ]
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@lorion-org/registry-hub",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "Framework-free typed registry and registry-hub primitives.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/lorion-org/lorion.git",
9
+ "directory": "packages/registry-hub"
10
+ },
11
+ "homepage": "https://github.com/lorion-org/lorion/tree/main/packages/registry-hub#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/lorion-org/lorion/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "require": {
30
+ "types": "./dist/index.d.cts",
31
+ "default": "./dist/index.cjs"
32
+ }
33
+ }
34
+ },
35
+ "files": [
36
+ "dist",
37
+ "examples",
38
+ "LICENSE"
39
+ ],
40
+ "keywords": [
41
+ "registry",
42
+ "hub",
43
+ "typed",
44
+ "typescript"
45
+ ],
46
+ "engines": {
47
+ "node": "^20.19.0 || >=22.12.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsup src/index.ts --format esm,cjs --dts",
51
+ "clean": "rimraf coverage dist tsconfig.tsbuildinfo",
52
+ "example:node": "node ./examples/node-basic.js",
53
+ "example:renderer": "node ./examples/renderer-registry.js",
54
+ "lint": "eslint src --ext .ts",
55
+ "test": "vitest run --root ../.. --config vitest.config.mts packages/registry-hub/src/index.spec.ts",
56
+ "coverage": "vitest run --coverage --coverage.include=packages/registry-hub/src/index.ts --root ../.. --config vitest.config.mts packages/registry-hub/src/index.spec.ts",
57
+ "typecheck": "tsc -p tsconfig.json --noEmit",
58
+ "package:check": "pnpm build && pnpm pack --dry-run && publint"
59
+ }
60
+ }