@travetto/registry 8.0.0-alpha.8 → 8.0.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/README.md +2 -6
- package/__index__.ts +1 -1
- package/package.json +14 -14
- package/src/registry.ts +12 -11
- package/src/store.ts +1 -2
- package/src/types.ts +3 -3
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ This flow ensures all files are loaded and processed before application starts.
|
|
|
28
28
|
|
|
29
29
|
**Code: Sample Registry**
|
|
30
30
|
```typescript
|
|
31
|
+
import { Registry, type RegistryAdapter, type RegistryIndex, RegistryIndexStore } from '@travetto/registry';
|
|
31
32
|
import type { Class } from '@travetto/runtime';
|
|
32
|
-
import { type RegistryAdapter, type RegistryIndex, RegistryIndexStore, Registry } from '@travetto/registry';
|
|
33
33
|
|
|
34
34
|
interface Group {
|
|
35
35
|
class: Class;
|
|
@@ -46,7 +46,6 @@ interface Child {
|
|
|
46
46
|
* The adapter to handle mapping/modeling a specific class
|
|
47
47
|
*/
|
|
48
48
|
class SampleRegistryAdapter implements RegistryAdapter<Group> {
|
|
49
|
-
|
|
50
49
|
#class: Class;
|
|
51
50
|
#config: Group;
|
|
52
51
|
|
|
@@ -58,10 +57,7 @@ class SampleRegistryAdapter implements RegistryAdapter<Group> {
|
|
|
58
57
|
for (const group of groups) {
|
|
59
58
|
Object.assign(this.#config, {
|
|
60
59
|
...group,
|
|
61
|
-
children: [
|
|
62
|
-
...(this.#config?.children ?? []),
|
|
63
|
-
...(group.children ?? [])
|
|
64
|
-
]
|
|
60
|
+
children: [...(this.#config?.children ?? []), ...(group.children ?? [])]
|
|
65
61
|
});
|
|
66
62
|
}
|
|
67
63
|
return this.#config;
|
package/__index__.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/registry",
|
|
3
|
-
"version": "8.0.0
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "8.0.0",
|
|
5
4
|
"description": "Patterns and utilities for handling registration of metadata and functionality for run-time use",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"ast-transformations",
|
|
8
|
-
"registry",
|
|
9
7
|
"metadata",
|
|
8
|
+
"real-time",
|
|
9
|
+
"registry",
|
|
10
10
|
"travetto",
|
|
11
|
-
"typescript"
|
|
12
|
-
"real-time"
|
|
11
|
+
"typescript"
|
|
13
12
|
],
|
|
14
13
|
"homepage": "https://travetto.io",
|
|
15
14
|
"license": "MIT",
|
|
16
15
|
"author": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
16
|
+
"name": "Travetto Framework",
|
|
17
|
+
"email": "travetto.framework@gmail.com"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"url": "git+https://github.com/travetto/travetto.git",
|
|
21
|
+
"directory": "module/registry"
|
|
19
22
|
},
|
|
20
23
|
"files": [
|
|
21
24
|
"__index__.ts",
|
|
22
25
|
"src",
|
|
23
26
|
"support"
|
|
24
27
|
],
|
|
28
|
+
"type": "module",
|
|
25
29
|
"main": "__index__.ts",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"directory": "module/registry"
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
31
|
-
"@travetto/runtime": "^8.0.0
|
|
34
|
+
"@travetto/runtime": "^8.0.0"
|
|
32
35
|
},
|
|
33
36
|
"travetto": {
|
|
34
37
|
"displayName": "Registry"
|
|
35
|
-
},
|
|
36
|
-
"publishConfig": {
|
|
37
|
-
"access": "public"
|
|
38
38
|
}
|
|
39
39
|
}
|
package/src/registry.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Class, castTo, Env, flushPendingFunctions, isClass, Runtime, RuntimeError, RuntimeIndex } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import type { RegistryIndex, RegistryIndexClass } from './types.ts';
|
|
4
4
|
|
|
5
5
|
class $Registry {
|
|
6
|
-
|
|
7
6
|
#resolved = false;
|
|
8
7
|
#initialized?: Promise<unknown>;
|
|
9
8
|
#indexByClass = new Map<RegistryIndexClass, RegistryIndex>();
|
|
@@ -44,7 +43,10 @@ class $Registry {
|
|
|
44
43
|
|
|
45
44
|
const byIndex = new Map<RegistryIndex, Class[]>();
|
|
46
45
|
for (const index of this.#indexes) {
|
|
47
|
-
byIndex.set(
|
|
46
|
+
byIndex.set(
|
|
47
|
+
index,
|
|
48
|
+
classes.filter(cls => index.store.has(cls))
|
|
49
|
+
);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
for (const index of this.#indexes) {
|
|
@@ -73,14 +75,13 @@ class $Registry {
|
|
|
73
75
|
|
|
74
76
|
// Ensure everything is loaded
|
|
75
77
|
for (const entry of RuntimeIndex.find({
|
|
76
|
-
module:
|
|
78
|
+
module: module => {
|
|
77
79
|
const role = Env.TRV_ROLE.value;
|
|
78
|
-
return
|
|
80
|
+
return (
|
|
81
|
+
role !== 'test' && // Skip all modules when in test
|
|
79
82
|
module.roles.includes('std') &&
|
|
80
|
-
(
|
|
81
|
-
|
|
82
|
-
(role === 'doc' && module.roles.includes(role))
|
|
83
|
-
);
|
|
83
|
+
(!Runtime.production || module.production || (role === 'doc' && module.roles.includes(role)))
|
|
84
|
+
);
|
|
84
85
|
},
|
|
85
86
|
folder: folder => folder === 'src' || folder === '$index'
|
|
86
87
|
})) {
|
|
@@ -123,7 +124,7 @@ class $Registry {
|
|
|
123
124
|
if (this.trace && this.#initialized) {
|
|
124
125
|
console.trace('Trying to re-initialize', { initialized: !!this.#initialized });
|
|
125
126
|
}
|
|
126
|
-
return this.#initialized ??= this.#init();
|
|
127
|
+
return (this.#initialized ??= this.#init());
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
/**
|
|
@@ -144,4 +145,4 @@ class $Registry {
|
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
export const Registry = new $Registry();
|
|
148
|
+
export const Registry = new $Registry();
|
package/src/store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Class, castTo, getParentClass, RuntimeError } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import type { RegistrationMethods, RegistryAdapter, RegistrySimpleStore } from './types.ts';
|
|
4
4
|
|
|
@@ -6,7 +6,6 @@ import type { RegistrationMethods, RegistryAdapter, RegistrySimpleStore } from '
|
|
|
6
6
|
* Base registry index implementation
|
|
7
7
|
*/
|
|
8
8
|
export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<{}>> implements RegistrySimpleStore {
|
|
9
|
-
|
|
10
9
|
// Core data
|
|
11
10
|
#adapters = new Map<Class, A>();
|
|
12
11
|
#idToCls = new Map<string, Class>();
|
package/src/types.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface RegistryAdapter<C extends {} = {}> {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type RegistryIndexClass = {
|
|
15
|
-
new(source: unknown): RegistryIndex;
|
|
15
|
+
new (source: unknown): RegistryIndex;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -23,7 +23,7 @@ export interface RegistrySimpleStore {
|
|
|
23
23
|
finalize(cls: Class): void;
|
|
24
24
|
finalized(cls: Class): boolean;
|
|
25
25
|
getClasses(): Class[];
|
|
26
|
-
}
|
|
26
|
+
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Registry index definition
|
|
@@ -35,4 +35,4 @@ export interface RegistryIndex {
|
|
|
35
35
|
onCreate?(cls: Class): void;
|
|
36
36
|
onChangeSetComplete?(events: Class[]): void;
|
|
37
37
|
beforeChangeSetComplete?(events: Class[]): void;
|
|
38
|
-
}
|
|
38
|
+
}
|