@travetto/registry 7.1.3 → 8.0.0-alpha.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/package.json +2 -2
- package/src/registry.ts +7 -7
- package/src/store.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/registry",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Patterns and utilities for handling registration of metadata and functionality for run-time use",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"directory": "module/registry"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@travetto/runtime": "^
|
|
31
|
+
"@travetto/runtime": "^8.0.0-alpha.0"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
|
34
34
|
"displayName": "Registry"
|
package/src/registry.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuntimeError, castTo, type Class, Env, flushPendingFunctions, isClass, Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import type { RegistryIndex, RegistryIndexClass } from './types.ts';
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ class $Registry {
|
|
|
27
27
|
|
|
28
28
|
validateConstructor(source: unknown): void {
|
|
29
29
|
if (source !== this) {
|
|
30
|
-
throw new
|
|
30
|
+
throw new RuntimeError('constructor is private');
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -100,7 +100,7 @@ class $Registry {
|
|
|
100
100
|
*/
|
|
101
101
|
verifyInitialized(): void {
|
|
102
102
|
if (!this.#resolved) {
|
|
103
|
-
throw new
|
|
103
|
+
throw new RuntimeError('Registry not initialized, call init() first');
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -108,12 +108,12 @@ class $Registry {
|
|
|
108
108
|
* Register a new index
|
|
109
109
|
*/
|
|
110
110
|
registerIndex<T extends RegistryIndexClass>(indexCls: T): InstanceType<T> {
|
|
111
|
-
|
|
111
|
+
const result = this.#indexByClass.getOrInsertComputed(indexCls, () => {
|
|
112
112
|
const instance = new indexCls(this);
|
|
113
|
-
this.#indexByClass.set(indexCls, instance);
|
|
114
113
|
this.#indexes.push(instance);
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
return instance;
|
|
115
|
+
});
|
|
116
|
+
return castTo(result);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
package/src/store.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuntimeError, castTo, type Class, getParentClass } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import type { RegistrationMethods, RegistryAdapter, RegistrySimpleStore } from './types.ts';
|
|
4
4
|
|
|
@@ -51,14 +51,14 @@ export class RegistryIndexStore<A extends RegistryAdapter<{}> = RegistryAdapter<
|
|
|
51
51
|
|
|
52
52
|
getForRegister(cls: Class, allowFinalized = false): A {
|
|
53
53
|
if (this.#finalized.get(cls) && !allowFinalized) {
|
|
54
|
-
throw new
|
|
54
|
+
throw new RuntimeError(`Class ${cls.Ⲑid} is already finalized`);
|
|
55
55
|
}
|
|
56
56
|
return this.adapter(cls);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
get(cls: Class): Omit<A, RegistrationMethods> {
|
|
60
60
|
if (!this.has(cls)) {
|
|
61
|
-
throw new
|
|
61
|
+
throw new RuntimeError(`Class ${cls.Ⲑid} is not registered for ${this.#adapterCls.Ⲑid}`);
|
|
62
62
|
}
|
|
63
63
|
return this.adapter(cls);
|
|
64
64
|
}
|