@astrale-os/kernel-dsl 1.0.0-beta.10 → 1.0.0-beta.11
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.
|
@@ -10,11 +10,11 @@ export function ClassKey(input) {
|
|
|
10
10
|
/** Construction, admission, and structural-coordinate operations for exact Class keys. */
|
|
11
11
|
(function (ClassKey) {
|
|
12
12
|
function of(ref) {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
13
|
+
const key = Key.of(ref);
|
|
14
|
+
if (!key.slice(key.indexOf(':') + 1).startsWith('class.')) {
|
|
15
15
|
throw new TypeError(`Invalid ClassKey coordinate: ${JSON.stringify(ref)}.`);
|
|
16
16
|
}
|
|
17
|
-
return
|
|
17
|
+
return key;
|
|
18
18
|
}
|
|
19
19
|
ClassKey.of = of;
|
|
20
20
|
function is(input) {
|
|
@@ -12,7 +12,10 @@ export declare namespace Key {
|
|
|
12
12
|
type Definition<Kind extends DefinitionKind = DefinitionKind, Name extends string = string, Origin extends Key.Origin = Key.Origin> = DefinitionKey<Origin, Kind, Name>;
|
|
13
13
|
type Callable = DefinitionKey<Key.Origin, 'function'> | MethodKey;
|
|
14
14
|
type View = DefinitionKey<Key.Origin, 'view'>;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Derive a canonical Definition key from its structured coordinate. A frozen coordinate of data
|
|
17
|
+
* fields cannot change, so its key is derived once and read back for every later call.
|
|
18
|
+
*/
|
|
16
19
|
function of<const Ref extends DefinitionRef>(ref: Ref): DefinitionKey<Ref['origin'], Ref['kind'], Ref['name']>;
|
|
17
20
|
function origin(input: Key): Key.Origin;
|
|
18
21
|
function is(input: unknown): input is Key;
|
|
@@ -3,6 +3,8 @@ import { DOMAIN_ORIGIN_PATTERN } from './patterns.js';
|
|
|
3
3
|
const DEFINITION_KEY = /^(?:class|function|policy|view)\.([A-Za-z][A-Za-z0-9_]*)$/u;
|
|
4
4
|
const CORE_KEY = /^core\.([a-z][a-z0-9-]{0,99})$/u;
|
|
5
5
|
const MEMBER_KEY = /^class\.([A-Za-z][A-Za-z0-9_]*)\.(property|method)\.([A-Za-z][A-Za-z0-9_]*)$/u;
|
|
6
|
+
/** The keys of frozen Definition coordinates, derived once each. */
|
|
7
|
+
const derived = new WeakMap();
|
|
6
8
|
export function Key(input) {
|
|
7
9
|
if (typeof input !== 'string' || !isCanonicalKey(input)) {
|
|
8
10
|
throw new TypeError(`Invalid Key: ${JSON.stringify(input)}.`);
|
|
@@ -11,10 +13,22 @@ export function Key(input) {
|
|
|
11
13
|
}
|
|
12
14
|
/** Canonical origin-qualified address operations. */
|
|
13
15
|
(function (Key) {
|
|
14
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Derive a canonical Definition key from its structured coordinate. A frozen coordinate of data
|
|
18
|
+
* fields cannot change, so its key is derived once and read back for every later call.
|
|
19
|
+
*/
|
|
15
20
|
function of(ref) {
|
|
21
|
+
const object = typeof ref === 'object' && ref !== null;
|
|
22
|
+
const known = object ? derived.get(ref) : undefined;
|
|
23
|
+
if (known !== undefined)
|
|
24
|
+
return known;
|
|
25
|
+
// Decided before admission reads the fields: only then are the fields read the final ones.
|
|
26
|
+
const stable = object && immutable(ref);
|
|
16
27
|
const definition = acceptDefinitionRef(ref);
|
|
17
|
-
|
|
28
|
+
const key = Key(`${definition.origin}:${definition.kind}.${definition.name}`);
|
|
29
|
+
if (stable)
|
|
30
|
+
derived.set(ref, key);
|
|
31
|
+
return key;
|
|
18
32
|
}
|
|
19
33
|
Key.of = of;
|
|
20
34
|
function origin(input) {
|
|
@@ -37,3 +51,8 @@ function isCanonicalKey(input) {
|
|
|
37
51
|
function isCanonicalCoordinate(input) {
|
|
38
52
|
return DEFINITION_KEY.test(input) || CORE_KEY.test(input) || MEMBER_KEY.test(input);
|
|
39
53
|
}
|
|
54
|
+
/** A frozen object of data fields answers every read alike; a getter may not. */
|
|
55
|
+
function immutable(ref) {
|
|
56
|
+
return (Object.isFrozen(ref) &&
|
|
57
|
+
Reflect.ownKeys(ref).every((key) => 'value' in Reflect.getOwnPropertyDescriptor(ref, key)));
|
|
58
|
+
}
|