@lorion-org/registry-hub 1.0.0-beta.0 → 1.0.0-beta.2

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/README.md CHANGED
@@ -39,17 +39,21 @@ import { createRegistry, createRegistryHub } from '@lorion-org/registry-hub';
39
39
  ```ts
40
40
  import { createRegistry, type RegistryItem } from '@lorion-org/registry-hub';
41
41
 
42
- type Command = RegistryItem & {
43
- command: string;
42
+ type PaymentProvider = RegistryItem & {
43
+ createCheckoutPath: (input: { shopId: string }) => string;
44
44
  };
45
45
 
46
- const commands = createRegistry<Command>('commands');
46
+ const paymentProviders = createRegistry<PaymentProvider>('payment-checkout-providers');
47
47
 
48
- commands.register({ id: 'build', command: 'pnpm build' });
48
+ paymentProviders.register({
49
+ id: 'payment-provider-stripe',
50
+ createCheckoutPath: (input) =>
51
+ `/providers/payment-provider-stripe/checkout?shop=${encodeURIComponent(input.shopId)}`,
52
+ });
49
53
 
50
- commands.get('build');
51
- commands.list();
52
- commands.entries();
54
+ paymentProviders.get('payment-provider-stripe');
55
+ paymentProviders.list();
56
+ paymentProviders.entries();
53
57
  ```
54
58
 
55
59
  ### Use a registry hub
@@ -57,37 +61,38 @@ commands.entries();
57
61
  ```ts
58
62
  import { createRegistryHub, type RegistryItem } from '@lorion-org/registry-hub';
59
63
 
60
- type Tool = RegistryItem & {
61
- title: string;
64
+ type Shop = RegistryItem & {
65
+ path: string;
62
66
  };
63
67
 
64
68
  const hub = createRegistryHub();
65
69
 
66
- hub.createRegistry<Tool>('tools');
67
- hub.register<Tool>('tools', { id: 'lint', title: 'Lint workspace' });
70
+ hub.createRegistry<Shop>('shops');
71
+ hub.register<Shop>('shops', { id: 'shop-coffee', path: '/shops/coffee' });
68
72
 
69
- const tool = hub.get<Tool>('tools', 'lint');
70
- const tools = hub.list<Tool>('tools');
73
+ const shop = hub.get<Shop>('shops', 'shop-coffee');
74
+ const shops = hub.list<Shop>('shops');
71
75
  const registries = hub.entries();
72
76
  ```
73
77
 
74
- ### Renderer registry example
78
+ ### Shop registry example
75
79
 
76
80
  ```ts
77
81
  import { createRegistry, type RegistryItem } from '@lorion-org/registry-hub';
78
82
 
79
- type FieldRenderer = RegistryItem & {
80
- component: string;
83
+ type Shop = RegistryItem & {
84
+ name: string;
85
+ path: string;
81
86
  };
82
87
 
83
- const renderers = createRegistry<FieldRenderer>('field-renderers');
88
+ const shops = createRegistry<Shop>('shops');
84
89
 
85
- renderers.register([
86
- { id: 'text', component: 'TextFieldRenderer' },
87
- { id: 'date', component: 'DateFieldRenderer' },
90
+ shops.register([
91
+ { id: 'shop-coffee', name: 'Bean Supply', path: '/shops/coffee' },
92
+ { id: 'shop-stationery', name: 'Paper Desk', path: '/shops/stationery' },
88
93
  ]);
89
94
 
90
- const knownRenderers = renderers.entries();
95
+ const knownShops = shops.entries();
91
96
  ```
92
97
 
93
98
  ### Framework recipe
@@ -113,14 +118,16 @@ Another plugin can then consume that injected hub and register its own entries.
113
118
  ```ts
114
119
  import type { RegistryItem } from '@lorion-org/registry-hub';
115
120
 
116
- type Tool = RegistryItem & {
117
- title: string;
121
+ type Shop = RegistryItem & {
122
+ name: string;
123
+ path: string;
118
124
  };
119
125
 
120
126
  export default defineNuxtPlugin((nuxtApp) => {
121
- nuxtApp.$registryHub.register<Tool>('tools', {
122
- id: 'lint',
123
- title: 'Lint workspace',
127
+ nuxtApp.$registryHub.register<Shop>('shops', {
128
+ id: 'shop-coffee',
129
+ name: 'Bean Supply',
130
+ path: '/shops/coffee',
124
131
  });
125
132
  });
126
133
  ```
@@ -130,18 +137,19 @@ A composable can later load all entries of one typed registry from that same hub
130
137
  ```ts
131
138
  import type { RegistryItem } from '@lorion-org/registry-hub';
132
139
 
133
- type Tool = RegistryItem & {
134
- title: string;
140
+ type Shop = RegistryItem & {
141
+ name: string;
142
+ path: string;
135
143
  };
136
144
 
137
- export function useTools(): Tool[] {
138
- return useNuxtApp().$registryHub.list<Tool>('tools');
145
+ export function useShops(): Shop[] {
146
+ return useNuxtApp().$registryHub.list<Shop>('shops');
139
147
  }
140
148
  ```
141
149
 
142
150
  Runnable example files live in [`examples/`](./examples).
143
151
  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.
152
+ The examples use the same shop and checkout-provider domain as the LORION playgrounds.
145
153
 
146
154
  ## Local commands
147
155
 
@@ -3,8 +3,12 @@ import process from 'node:process';
3
3
 
4
4
  const hub = createRegistryHub();
5
5
 
6
- hub.register('commands', { id: 'build', command: 'pnpm build' });
7
- hub.register('tools', { id: 'lint', title: 'Lint workspace' });
6
+ hub.register('payment-checkout-providers', {
7
+ id: 'payment-provider-stripe',
8
+ createCheckoutPath: (input) =>
9
+ `/providers/payment-provider-stripe/checkout?shop=${encodeURIComponent(input.shopId)}`,
10
+ });
11
+ hub.register('shops', { id: 'shop-coffee', path: '/shops/coffee' });
8
12
 
9
- process.stdout.write(`${JSON.stringify(hub.list('commands'))}\n`);
10
- process.stdout.write(`${JSON.stringify(hub.get('tools', 'lint'))}\n`);
13
+ process.stdout.write(`${JSON.stringify(hub.list('payment-checkout-providers'))}\n`);
14
+ process.stdout.write(`${JSON.stringify(hub.get('shops', 'shop-coffee'))}\n`);
@@ -1,20 +1,24 @@
1
1
  import { createRegistryHub, type RegistryItem } from '@lorion-org/registry-hub';
2
2
 
3
- type Command = RegistryItem & {
4
- command: string;
3
+ type PaymentProvider = RegistryItem & {
4
+ createCheckoutPath: (input: { shopId: string }) => string;
5
5
  };
6
6
 
7
- type Tool = RegistryItem & {
8
- title: string;
7
+ type Shop = RegistryItem & {
8
+ path: string;
9
9
  };
10
10
 
11
11
  const hub = createRegistryHub();
12
12
 
13
- hub.register<Command>('commands', { id: 'build', command: 'pnpm build' });
14
- hub.register<Tool>('tools', { id: 'lint', title: 'Lint workspace' });
13
+ hub.register<PaymentProvider>('payment-checkout-providers', {
14
+ id: 'payment-provider-stripe',
15
+ createCheckoutPath: (input) =>
16
+ `/providers/payment-provider-stripe/checkout?shop=${encodeURIComponent(input.shopId)}`,
17
+ });
18
+ hub.register<Shop>('shops', { id: 'shop-coffee', path: '/shops/coffee' });
15
19
 
16
- console.log(hub.list<Command>('commands'));
17
- // [{ id: 'build', command: 'pnpm build' }]
20
+ console.log(hub.list<PaymentProvider>('payment-checkout-providers'));
21
+ // [{ id: 'payment-provider-stripe', createCheckoutPath: [Function] }]
18
22
 
19
- console.log(hub.get<Tool>('tools', 'lint'));
20
- // { id: 'lint', title: 'Lint workspace' }
23
+ console.log(hub.get<Shop>('shops', 'shop-coffee'));
24
+ // { id: 'shop-coffee', path: '/shops/coffee' }
@@ -1,15 +1,15 @@
1
1
  import { createRegistry } from '@lorion-org/registry-hub';
2
2
  import process from 'node:process';
3
3
 
4
- const renderers = createRegistry('field-renderers');
4
+ const shops = createRegistry('shops');
5
5
 
6
- renderers.register([
7
- { id: 'text', component: 'TextFieldRenderer' },
8
- { id: 'date', component: 'DateFieldRenderer' },
6
+ shops.register([
7
+ { id: 'shop-coffee', name: 'Bean Supply', path: '/shops/coffee' },
8
+ { id: 'shop-stationery', name: 'Paper Desk', path: '/shops/stationery' },
9
9
  ]);
10
10
 
11
11
  process.stdout.write(
12
- `${renderers.id}:${renderers
12
+ `${shops.id}:${shops
13
13
  .entries()
14
14
  .map(([id]) => id)
15
15
  .join(',')}\n`,
@@ -1,18 +1,19 @@
1
1
  import { createRegistry, type RegistryItem } from '@lorion-org/registry-hub';
2
2
 
3
- type FieldRenderer = RegistryItem & {
4
- component: string;
3
+ type Shop = RegistryItem & {
4
+ name: string;
5
+ path: string;
5
6
  };
6
7
 
7
- const renderers = createRegistry<FieldRenderer>('field-renderers');
8
+ const shops = createRegistry<Shop>('shops');
8
9
 
9
- renderers.register([
10
- { id: 'text', component: 'TextFieldRenderer' },
11
- { id: 'date', component: 'DateFieldRenderer' },
10
+ shops.register([
11
+ { id: 'shop-coffee', name: 'Bean Supply', path: '/shops/coffee' },
12
+ { id: 'shop-stationery', name: 'Paper Desk', path: '/shops/stationery' },
12
13
  ]);
13
14
 
14
- console.log(renderers.entries());
15
+ console.log(shops.entries());
15
16
  // [
16
- // ['text', { id: 'text', component: 'TextFieldRenderer' }],
17
- // ['date', { id: 'date', component: 'DateFieldRenderer' }]
17
+ // ['shop-coffee', { id: 'shop-coffee', name: 'Bean Supply', path: '/shops/coffee' }],
18
+ // ['shop-stationery', { id: 'shop-stationery', name: 'Paper Desk', path: '/shops/stationery' }]
18
19
  // ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lorion-org/registry-hub",
3
- "version": "1.0.0-beta.0",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Framework-free typed registry and registry-hub primitives.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,6 +22,10 @@
22
22
  "types": "./dist/index.d.ts",
23
23
  "exports": {
24
24
  ".": {
25
+ "lorion-source": {
26
+ "types": "./src/index.ts",
27
+ "default": "./src/index.ts"
28
+ },
25
29
  "import": {
26
30
  "types": "./dist/index.d.ts",
27
31
  "default": "./dist/index.js"
@@ -35,7 +39,9 @@
35
39
  "files": [
36
40
  "dist",
37
41
  "examples",
38
- "LICENSE"
42
+ "LICENSE",
43
+ "src/**/*.ts",
44
+ "!src/**/*.spec.ts"
39
45
  ],
40
46
  "keywords": [
41
47
  "registry",
package/src/index.ts ADDED
@@ -0,0 +1,83 @@
1
+ export type RegistryItem = {
2
+ id: string;
3
+ };
4
+
5
+ export type Registry<T extends RegistryItem = RegistryItem> = {
6
+ id: string;
7
+ get: (id: string) => T | undefined;
8
+ list: () => T[];
9
+ register: (items: T | T[]) => T[];
10
+ entries: () => Array<[string, T]>;
11
+ };
12
+
13
+ export type RegistryHub = {
14
+ createRegistry: <T extends RegistryItem>(id: string) => Registry<T>;
15
+ getRegistry: <T extends RegistryItem>(id: string) => Registry<T> | undefined;
16
+ register: <T extends RegistryItem>(registryId: string, items: T | T[]) => T[];
17
+ get: <T extends RegistryItem>(registryId: string, itemId: string) => T | undefined;
18
+ list: <T extends RegistryItem>(registryId: string) => T[];
19
+ entries: () => Array<[string, Registry<RegistryItem>]>;
20
+ };
21
+
22
+ type AnyRegistry = Registry<RegistryItem>;
23
+
24
+ export function createRegistry<T extends RegistryItem>(id: string): Registry<T> {
25
+ const map: Map<string, T> = new Map();
26
+
27
+ return {
28
+ id,
29
+ get: (itemId: string) => map.get(itemId),
30
+ list: () => Array.from(map.values()),
31
+ entries: () => Array.from(map.entries()),
32
+ register: (items: T | T[]) => {
33
+ const normalized: T[] = Array.isArray(items) ? items : [items];
34
+
35
+ for (const item of normalized) map.set(item.id, item);
36
+
37
+ return normalized;
38
+ },
39
+ };
40
+ }
41
+
42
+ export function createRegistryHub(): RegistryHub {
43
+ const registries: Map<string, AnyRegistry> = new Map();
44
+
45
+ return {
46
+ createRegistry: <T extends RegistryItem>(id: string) => {
47
+ const existing: AnyRegistry | undefined = registries.get(id);
48
+
49
+ if (existing) return existing as unknown as Registry<T>;
50
+
51
+ const created: Registry<T> = createRegistry<T>(id);
52
+ registries.set(id, created as unknown as AnyRegistry);
53
+
54
+ return created;
55
+ },
56
+ getRegistry: <T extends RegistryItem>(id: string) =>
57
+ registries.get(id) as Registry<T> | undefined,
58
+ register: <T extends RegistryItem>(registryId: string, items: T | T[]) => {
59
+ const registry: Registry<T> =
60
+ (registries.get(registryId) as Registry<T> | undefined) ?? createRegistry<T>(registryId);
61
+
62
+ if (!registries.has(registryId))
63
+ registries.set(registryId, registry as unknown as AnyRegistry);
64
+
65
+ return registry.register(items);
66
+ },
67
+ get: <T extends RegistryItem>(registryId: string, itemId: string) => {
68
+ const registry: Registry<T> | undefined = registries.get(registryId) as
69
+ | Registry<T>
70
+ | undefined;
71
+
72
+ return registry?.get(itemId);
73
+ },
74
+ list: <T extends RegistryItem>(registryId: string) => {
75
+ const registry: Registry<T> | undefined = registries.get(registryId) as
76
+ | Registry<T>
77
+ | undefined;
78
+
79
+ return registry?.list() ?? [];
80
+ },
81
+ entries: () => Array.from(registries.entries()),
82
+ };
83
+ }