@hydranium/protocol 1.0.0-next.316 → 1.0.0-next.318
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/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/testing/index.d.ts +1 -0
- package/lib/testing/index.d.ts.map +1 -1
- package/lib/testing/index.js +3 -2
- package/lib/testing/index.js.map +1 -1
- package/lib/testing/transfer-node-builder.d.ts +81 -0
- package/lib/testing/transfer-node-builder.d.ts.map +1 -0
- package/lib/testing/transfer-node-builder.js +47 -0
- package/lib/testing/transfer-node-builder.js.map +1 -0
- package/lib/transfer-element.d.ts +4 -4
- package/lib/types.d.ts +32 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +11 -0
- package/lib/types.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/testing/index.ts +3 -2
- package/src/testing/transfer-node-builder.ts +107 -0
- package/src/transfer-element.ts +4 -4
- package/src/types.ts +30 -0
package/lib/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from './profiling';
|
|
|
30
30
|
export * from './tracer';
|
|
31
31
|
export * from './transfer-diagnostic';
|
|
32
32
|
export * from './transfer-element';
|
|
33
|
+
export * from './types';
|
|
33
34
|
export * from './model-service';
|
|
34
35
|
export * from './transfer-document';
|
|
35
36
|
export * from './model-server';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AASlF,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAA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AAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,OAAO,CAAC;AACtB,cAAc,OAAO,CAAC;AACtB,cAAc,QAAQ,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -55,6 +55,7 @@ __exportStar(require("./profiling"), exports);
|
|
|
55
55
|
__exportStar(require("./tracer"), exports);
|
|
56
56
|
__exportStar(require("./transfer-diagnostic"), exports);
|
|
57
57
|
__exportStar(require("./transfer-element"), exports);
|
|
58
|
+
__exportStar(require("./types"), exports);
|
|
58
59
|
__exportStar(require("./model-service"), exports);
|
|
59
60
|
__exportStar(require("./transfer-document"), exports);
|
|
60
61
|
__exportStar(require("./model-server"), exports);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kFAAkF;AAClF,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,iDAAiD;AAEjD,oDAAkC;AAClC,mDAAiC;AACjC,2CAAyB;AACzB,+CAA6B;AAC7B,0CAAwB;AACxB,yCAAuB;AACvB,oDAAkC;AAClC,8CAA4B;AAC5B,4DAA0C;AAC1C,4DAA0C;AAC1C,2CAAyB;AACzB,qDAAmC;AACnC,2CAAyB;AACzB,sDAAoC;AACpC,6EAA6E;AAC7E,+EAA+E;AAC/E,+BAA+B;AAC/B,wDAAsC;AACtC,gDAA8B;AAC9B,oDAAkC;AAClC,gDAA8B;AAC9B,qDAAmC;AACnC,oDAAkC;AAClC,8CAA4B;AAC5B,2CAAyB;AACzB,wDAAsC;AACtC,qDAAmC;AACnC,kDAAgC;AAChC,sDAAoC;AACpC,iDAA+B;AAC/B,4CAA0B;AAC1B,gDAA8B;AAC9B,uDAAqC;AACrC,wCAAsB;AACtB,wCAAsB;AACtB,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,kFAAkF;AAClF,+EAA+E;AAC/E,8EAA8E;AAC9E,+EAA+E;AAC/E,4EAA4E;AAC5E,iDAAiD;AAEjD,oDAAkC;AAClC,mDAAiC;AACjC,2CAAyB;AACzB,+CAA6B;AAC7B,0CAAwB;AACxB,yCAAuB;AACvB,oDAAkC;AAClC,8CAA4B;AAC5B,4DAA0C;AAC1C,4DAA0C;AAC1C,2CAAyB;AACzB,qDAAmC;AACnC,2CAAyB;AACzB,sDAAoC;AACpC,6EAA6E;AAC7E,+EAA+E;AAC/E,+BAA+B;AAC/B,wDAAsC;AACtC,gDAA8B;AAC9B,oDAAkC;AAClC,gDAA8B;AAC9B,qDAAmC;AACnC,oDAAkC;AAClC,8CAA4B;AAC5B,2CAAyB;AACzB,wDAAsC;AACtC,qDAAmC;AACnC,0CAAwB;AACxB,kDAAgC;AAChC,sDAAoC;AACpC,iDAA+B;AAC/B,4CAA0B;AAC1B,gDAA8B;AAC9B,uDAAqC;AACrC,wCAAsB;AACtB,wCAAsB;AACtB,yCAAuB"}
|
package/lib/testing/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAiBlF,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAiBlF,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC"}
|
package/lib/testing/index.js
CHANGED
|
@@ -26,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
// primitives: `makeFakeClock` (deterministic `Clock` double on one virtual time
|
|
27
27
|
// axis), `waitFor` / `tick`, the client-side data-head doubles
|
|
28
28
|
// (`makeFakeDataPort` / `makeCapturingDataClient`), the translation-catalogue
|
|
29
|
-
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`),
|
|
30
|
-
// the `Harness` marker
|
|
29
|
+
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`), the
|
|
30
|
+
// transfer-node builder (`makeTransferNodeBuilder`), and the `Harness` marker
|
|
31
31
|
// interface every framework harness extends. Kept out of the main barrel so production bundles don't pull
|
|
32
32
|
// the test scaffolding in by default; adopters opt in by importing from
|
|
33
33
|
// `@hydranium/protocol/testing`.
|
|
@@ -40,5 +40,6 @@ __exportStar(require("./catalogue-audit"), exports);
|
|
|
40
40
|
__exportStar(require("./data-doubles"), exports);
|
|
41
41
|
__exportStar(require("./fake-clock"), exports);
|
|
42
42
|
__exportStar(require("./harness"), exports);
|
|
43
|
+
__exportStar(require("./transfer-node-builder"), exports);
|
|
43
44
|
__exportStar(require("./wait-for"), exports);
|
|
44
45
|
//# sourceMappingURL=index.js.map
|
package/lib/testing/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,gFAAgF;AAChF,gFAAgF;AAChF,+DAA+D;AAC/D,8EAA8E;AAC9E,8EAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF;;;;;;;;;;;;;;;;AAElF,gFAAgF;AAChF,gFAAgF;AAChF,+DAA+D;AAC/D,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,0GAA0G;AAC1G,wEAAwE;AACxE,iCAAiC;AACjC,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,+EAA+E;AAE/E,oDAAkC;AAClC,iDAA+B;AAC/B,+CAA6B;AAC7B,4CAA0B;AAC1B,0DAAwC;AACxC,6CAA2B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
import type { TransferElement } from '../transfer-element';
|
|
10
|
+
import type { ConcreteTypeName, SingleTypeName } from '../types';
|
|
11
|
+
/**
|
|
12
|
+
* The per-type constant the generated transfer model emits under each type's
|
|
13
|
+
* name, as Langium does for the AST. Its `$type` literal picks the interface
|
|
14
|
+
* out of the builder's type map.
|
|
15
|
+
*/
|
|
16
|
+
export interface TransferTypeConstant<TType extends string = string> {
|
|
17
|
+
readonly $type: TType;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* What {@link makeTransferNodeBuilder} reads from a reflection: each type's
|
|
21
|
+
* grammar properties and their defaults. The generated
|
|
22
|
+
* `<LanguageId>TransferReflection` satisfies it without importing it, and
|
|
23
|
+
* keeps the literal type of its `types` so the builder can tell which fields
|
|
24
|
+
* the grammar defaults.
|
|
25
|
+
*/
|
|
26
|
+
export interface TransferReflection {
|
|
27
|
+
getTypeMetaData(type: string): {
|
|
28
|
+
readonly properties: Readonly<Record<string, {
|
|
29
|
+
readonly defaultValue?: unknown;
|
|
30
|
+
}>>;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The properties of `TType` that `TReflection`'s literal `types` gives a `defaultValue`; none for a reflection typed only as the interface. */
|
|
34
|
+
type DefaultedKeys<TReflection, TType> = TReflection extends {
|
|
35
|
+
readonly types: infer Types;
|
|
36
|
+
} ? TType extends keyof Types ? Types[TType] extends {
|
|
37
|
+
readonly properties: infer Properties;
|
|
38
|
+
} ? {
|
|
39
|
+
[K in keyof Properties]: Properties[K] extends {
|
|
40
|
+
readonly defaultValue: unknown;
|
|
41
|
+
} ? K : never;
|
|
42
|
+
}[keyof Properties] : never : never : never;
|
|
43
|
+
/**
|
|
44
|
+
* Init payload of a {@link TransferNodeBuilder}: every field of `T` as its
|
|
45
|
+
* interface declares it, except that the fields named by `TDefaulted`, which
|
|
46
|
+
* the grammar defaults, are optional. `$type` comes from the constant.
|
|
47
|
+
*/
|
|
48
|
+
export type TransferNodeInit<T extends TransferElement, TDefaulted extends PropertyKey = never> = Omit<T, '$type' | TDefaulted> & Partial<Pick<T, Extract<TDefaulted, keyof T>>>;
|
|
49
|
+
/**
|
|
50
|
+
* Transfer-node factory bound to a grammar's type map, the transfer twin of
|
|
51
|
+
* core's `AstNodeBuilder`. `TMap` is the generated `<LanguageId>TransferTypes`,
|
|
52
|
+
* `TReflection` the type of the generated reflection.
|
|
53
|
+
*/
|
|
54
|
+
export interface TransferNodeBuilder<TMap, TReflection extends TransferReflection = TransferReflection> {
|
|
55
|
+
/** A complete node: the grammar's defaults, then `init`. */
|
|
56
|
+
<TType extends ConcreteTypeName<TMap>>(typeConstant: TransferTypeConstant<TType> & SingleTypeName<TType>, init: TransferNodeInit<Extract<TMap[TType], TransferElement>, DefaultedKeys<TReflection, TType>>): Extract<TMap[TType], TransferElement>;
|
|
57
|
+
/**
|
|
58
|
+
* A node holding only `init`, with no defaults filled, typed as the
|
|
59
|
+
* incomplete node it is.
|
|
60
|
+
*/
|
|
61
|
+
partial<TType extends ConcreteTypeName<TMap>>(typeConstant: TransferTypeConstant<TType> & SingleTypeName<TType>, init?: Partial<Omit<Extract<TMap[TType], TransferElement>, '$type'>>): Partial<Extract<TMap[TType], TransferElement>> & TransferTypeConstant<TType>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Bind a {@link TransferNodeBuilder} to a grammar's reflection, so a test names
|
|
65
|
+
* only the fields it cares about and a containment field the grammar gains
|
|
66
|
+
* later needs no change at the call site.
|
|
67
|
+
*
|
|
68
|
+
* Defaults come from the reflection's grammar metadata alone, so a derived
|
|
69
|
+
* field the overlay adds is never defaulted, and stays required. An array
|
|
70
|
+
* default is a fresh `[]` per node. An init field named as `undefined` keeps
|
|
71
|
+
* its default, since the init type cannot refuse `undefined` for an optional
|
|
72
|
+
* field and a plain assign would leave the node typed complete without it.
|
|
73
|
+
*
|
|
74
|
+
* The constant's `$type` is written after `init`, because the init type keeps
|
|
75
|
+
* out only a `$type` written in the call: a spread of another node passes the
|
|
76
|
+
* check and would otherwise hand back a node typed as one type and tagged as
|
|
77
|
+
* another.
|
|
78
|
+
*/
|
|
79
|
+
export declare function makeTransferNodeBuilder<TMap, TReflection extends TransferReflection = TransferReflection>(reflection: TReflection): TransferNodeBuilder<TMap, TReflection>;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=transfer-node-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer-node-builder.d.ts","sourceRoot":"","sources":["../../src/testing/transfer-node-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D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S,kBAAkB,GAAG,kBAAkB;IACnG,4DAA4D;IAC5D,CAAC,KAAK,SAAS,gBAAgB,CAAC,IAAI,CAAC,EAClC,YAAY,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,EACjE,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,EAAE,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,GAChG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,CAAC;IACzC;;;OAGG;IACH,OAAO,CAAC,KAAK,SAAS,gBAAgB,CAAC,IAAI,CAAC,EACzC,YAAY,EAAE,oBAAoB,CAAC,KAAK,CAAC,GAAG,cAAc,CAAC,KAAK,CAAC,EACjE,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,EAAE,OAAO,CAAC,CAAC,GACpE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC,CAAC,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;CAClF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,SAAS,kBAAkB,GAAG,kBAAkB,EACtG,UAAU,EAAE,WAAW,GACvB,mBAAmB,CAAC,IAAI,EAAE,WAAW,CAAC,CAkBxC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.makeTransferNodeBuilder = makeTransferNodeBuilder;
|
|
12
|
+
/**
|
|
13
|
+
* Bind a {@link TransferNodeBuilder} to a grammar's reflection, so a test names
|
|
14
|
+
* only the fields it cares about and a containment field the grammar gains
|
|
15
|
+
* later needs no change at the call site.
|
|
16
|
+
*
|
|
17
|
+
* Defaults come from the reflection's grammar metadata alone, so a derived
|
|
18
|
+
* field the overlay adds is never defaulted, and stays required. An array
|
|
19
|
+
* default is a fresh `[]` per node. An init field named as `undefined` keeps
|
|
20
|
+
* its default, since the init type cannot refuse `undefined` for an optional
|
|
21
|
+
* field and a plain assign would leave the node typed complete without it.
|
|
22
|
+
*
|
|
23
|
+
* The constant's `$type` is written after `init`, because the init type keeps
|
|
24
|
+
* out only a `$type` written in the call: a spread of another node passes the
|
|
25
|
+
* check and would otherwise hand back a node typed as one type and tagged as
|
|
26
|
+
* another.
|
|
27
|
+
*/
|
|
28
|
+
function makeTransferNodeBuilder(reflection) {
|
|
29
|
+
const build = (typeConstant, init) => {
|
|
30
|
+
const node = { $type: typeConstant.$type };
|
|
31
|
+
for (const [name, property] of Object.entries(reflection.getTypeMetaData(typeConstant.$type).properties)) {
|
|
32
|
+
if (property.defaultValue !== undefined) {
|
|
33
|
+
node[name] = Array.isArray(property.defaultValue) ? [...property.defaultValue] : property.defaultValue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const [name, value] of Object.entries(init)) {
|
|
37
|
+
if (value !== undefined || !Object.hasOwn(node, name)) {
|
|
38
|
+
node[name] = value;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
node.$type = typeConstant.$type;
|
|
42
|
+
return node;
|
|
43
|
+
};
|
|
44
|
+
const partial = (typeConstant, init = {}) => ({ ...init, $type: typeConstant.$type });
|
|
45
|
+
return Object.assign(build, { partial });
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=transfer-node-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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,CAAC;IAC5H,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAA2C,CAAC;AACtF,CAAC"}
|
|
@@ -26,10 +26,10 @@ export interface TransferElement {
|
|
|
26
26
|
* declared wire shape — or fall back to the structural base
|
|
27
27
|
* {@link TransferElement} when no entry is declared.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* `TransferElement` — the framework default behaves
|
|
32
|
-
* overlay (no autocomplete, but no compile error either).
|
|
29
|
+
* The transfer-model generator emits the overlay as `<LanguageId>TransferTypes`;
|
|
30
|
+
* an encoder that relabels a type overrides that entry. Types not in the
|
|
31
|
+
* overlay resolve to `TransferElement` — the framework default behaves
|
|
32
|
+
* correctly without an overlay (no autocomplete, but no compile error either).
|
|
33
33
|
*
|
|
34
34
|
* The lookup is compile-time only; no runtime cost.
|
|
35
35
|
*/
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
/**
|
|
10
|
+
* The keys of a type map, Langium's `<LanguageName>AstType` or the generated
|
|
11
|
+
* `<LanguageId>TransferTypes`, that a node can carry as its `$type`: those
|
|
12
|
+
* listed in their own type's `$type`. A union, or an abstract type whose
|
|
13
|
+
* `$type` names only its subtypes, has a constant too, but building one would
|
|
14
|
+
* yield a node that no guard accepts. A concrete type with subtypes lists its
|
|
15
|
+
* own name beside theirs, as Langium writes it, and stays buildable.
|
|
16
|
+
*/
|
|
17
|
+
export type ConcreteTypeName<TMap> = {
|
|
18
|
+
[K in keyof TMap]: K extends (TMap[K] extends {
|
|
19
|
+
readonly $type: infer TType;
|
|
20
|
+
} ? TType : never) ? K : never;
|
|
21
|
+
}[keyof TMap] & string;
|
|
22
|
+
type IsUnion<T, TAll = T> = T extends unknown ? ([TAll] extends [T] ? false : true) : never;
|
|
23
|
+
/**
|
|
24
|
+
* Intersected onto a builder's type-constant parameter, refuses a constant
|
|
25
|
+
* typed by a union of type names: the init would hold only the members' common
|
|
26
|
+
* fields, so either type could be built incomplete.
|
|
27
|
+
*/
|
|
28
|
+
export type SingleTypeName<TType> = true extends IsUnion<TType> ? {
|
|
29
|
+
readonly $type: never;
|
|
30
|
+
} : unknown;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,IAAI,IAAI;KACjC,CAAC,IAAI,MAAM,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;QAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,KAAK,CAAA;KAAE,GAAG,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK;CAC5G,CAAC,MAAM,IAAI,CAAC,GACV,MAAM,CAAC;AAEV,KAAK,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;AAE5F;;;;GAIG;AACH,MAAM,MAAM,cAAc,CAAC,KAAK,IAAI,IAAI,SAAS,OAAO,CAAC,KAAK,CAAC,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG,OAAO,CAAC"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the MIT License which is available in the project root.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: MIT
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;kFAOkF"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export * from './profiling';
|
|
|
41
41
|
export * from './tracer';
|
|
42
42
|
export * from './transfer-diagnostic';
|
|
43
43
|
export * from './transfer-element';
|
|
44
|
+
export * from './types';
|
|
44
45
|
export * from './model-service';
|
|
45
46
|
export * from './transfer-document';
|
|
46
47
|
export * from './model-server';
|
package/src/testing/index.ts
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
// primitives: `makeFakeClock` (deterministic `Clock` double on one virtual time
|
|
12
12
|
// axis), `waitFor` / `tick`, the client-side data-head doubles
|
|
13
13
|
// (`makeFakeDataPort` / `makeCapturingDataClient`), the translation-catalogue
|
|
14
|
-
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`),
|
|
15
|
-
// the `Harness` marker
|
|
14
|
+
// audit (`flattenCatalogue` / `findUndeclaredCodes` / `findSharedCodes`), the
|
|
15
|
+
// transfer-node builder (`makeTransferNodeBuilder`), and the `Harness` marker
|
|
16
16
|
// interface every framework harness extends. Kept out of the main barrel so production bundles don't pull
|
|
17
17
|
// the test scaffolding in by default; adopters opt in by importing from
|
|
18
18
|
// `@hydranium/protocol/testing`.
|
|
@@ -26,4 +26,5 @@ export * from './catalogue-audit';
|
|
|
26
26
|
export * from './data-doubles';
|
|
27
27
|
export * from './fake-clock';
|
|
28
28
|
export * from './harness';
|
|
29
|
+
export * from './transfer-node-builder';
|
|
29
30
|
export * from './wait-for';
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import type { TransferElement } from '../transfer-element';
|
|
11
|
+
import type { ConcreteTypeName, SingleTypeName } from '../types';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The per-type constant the generated transfer model emits under each type's
|
|
15
|
+
* name, as Langium does for the AST. Its `$type` literal picks the interface
|
|
16
|
+
* out of the builder's type map.
|
|
17
|
+
*/
|
|
18
|
+
export interface TransferTypeConstant<TType extends string = string> {
|
|
19
|
+
readonly $type: TType;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* What {@link makeTransferNodeBuilder} reads from a reflection: each type's
|
|
24
|
+
* grammar properties and their defaults. The generated
|
|
25
|
+
* `<LanguageId>TransferReflection` satisfies it without importing it, and
|
|
26
|
+
* keeps the literal type of its `types` so the builder can tell which fields
|
|
27
|
+
* the grammar defaults.
|
|
28
|
+
*/
|
|
29
|
+
export interface TransferReflection {
|
|
30
|
+
getTypeMetaData(type: string): { readonly properties: Readonly<Record<string, { readonly defaultValue?: unknown }>> };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The properties of `TType` that `TReflection`'s literal `types` gives a `defaultValue`; none for a reflection typed only as the interface. */
|
|
34
|
+
type DefaultedKeys<TReflection, TType> = TReflection extends { readonly types: infer Types }
|
|
35
|
+
? TType extends keyof Types
|
|
36
|
+
? Types[TType] extends { readonly properties: infer Properties }
|
|
37
|
+
? { [K in keyof Properties]: Properties[K] extends { readonly defaultValue: unknown } ? K : never }[keyof Properties]
|
|
38
|
+
: never
|
|
39
|
+
: never
|
|
40
|
+
: never;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Init payload of a {@link TransferNodeBuilder}: every field of `T` as its
|
|
44
|
+
* interface declares it, except that the fields named by `TDefaulted`, which
|
|
45
|
+
* the grammar defaults, are optional. `$type` comes from the constant.
|
|
46
|
+
*/
|
|
47
|
+
export type TransferNodeInit<T extends TransferElement, TDefaulted extends PropertyKey = never> = Omit<T, '$type' | TDefaulted> &
|
|
48
|
+
Partial<Pick<T, Extract<TDefaulted, keyof T>>>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Transfer-node factory bound to a grammar's type map, the transfer twin of
|
|
52
|
+
* core's `AstNodeBuilder`. `TMap` is the generated `<LanguageId>TransferTypes`,
|
|
53
|
+
* `TReflection` the type of the generated reflection.
|
|
54
|
+
*/
|
|
55
|
+
export interface TransferNodeBuilder<TMap, TReflection extends TransferReflection = TransferReflection> {
|
|
56
|
+
/** A complete node: the grammar's defaults, then `init`. */
|
|
57
|
+
<TType extends ConcreteTypeName<TMap>>(
|
|
58
|
+
typeConstant: TransferTypeConstant<TType> & SingleTypeName<TType>,
|
|
59
|
+
init: TransferNodeInit<Extract<TMap[TType], TransferElement>, DefaultedKeys<TReflection, TType>>
|
|
60
|
+
): Extract<TMap[TType], TransferElement>;
|
|
61
|
+
/**
|
|
62
|
+
* A node holding only `init`, with no defaults filled, typed as the
|
|
63
|
+
* incomplete node it is.
|
|
64
|
+
*/
|
|
65
|
+
partial<TType extends ConcreteTypeName<TMap>>(
|
|
66
|
+
typeConstant: TransferTypeConstant<TType> & SingleTypeName<TType>,
|
|
67
|
+
init?: Partial<Omit<Extract<TMap[TType], TransferElement>, '$type'>>
|
|
68
|
+
): Partial<Extract<TMap[TType], TransferElement>> & TransferTypeConstant<TType>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Bind a {@link TransferNodeBuilder} to a grammar's reflection, so a test names
|
|
73
|
+
* only the fields it cares about and a containment field the grammar gains
|
|
74
|
+
* later needs no change at the call site.
|
|
75
|
+
*
|
|
76
|
+
* Defaults come from the reflection's grammar metadata alone, so a derived
|
|
77
|
+
* field the overlay adds is never defaulted, and stays required. An array
|
|
78
|
+
* default is a fresh `[]` per node. An init field named as `undefined` keeps
|
|
79
|
+
* its default, since the init type cannot refuse `undefined` for an optional
|
|
80
|
+
* field and a plain assign would leave the node typed complete without it.
|
|
81
|
+
*
|
|
82
|
+
* The constant's `$type` is written after `init`, because the init type keeps
|
|
83
|
+
* out only a `$type` written in the call: a spread of another node passes the
|
|
84
|
+
* check and would otherwise hand back a node typed as one type and tagged as
|
|
85
|
+
* another.
|
|
86
|
+
*/
|
|
87
|
+
export function makeTransferNodeBuilder<TMap, TReflection extends TransferReflection = TransferReflection>(
|
|
88
|
+
reflection: TReflection
|
|
89
|
+
): TransferNodeBuilder<TMap, TReflection> {
|
|
90
|
+
const build = (typeConstant: TransferTypeConstant, init: object): object => {
|
|
91
|
+
const node: Record<string, unknown> = { $type: typeConstant.$type };
|
|
92
|
+
for (const [name, property] of Object.entries(reflection.getTypeMetaData(typeConstant.$type).properties)) {
|
|
93
|
+
if (property.defaultValue !== undefined) {
|
|
94
|
+
node[name] = Array.isArray(property.defaultValue) ? [...property.defaultValue] : property.defaultValue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const [name, value] of Object.entries(init)) {
|
|
98
|
+
if (value !== undefined || !Object.hasOwn(node, name)) {
|
|
99
|
+
node[name] = value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
node.$type = typeConstant.$type;
|
|
103
|
+
return node;
|
|
104
|
+
};
|
|
105
|
+
const partial = (typeConstant: TransferTypeConstant, init: object = {}): object => ({ ...init, $type: typeConstant.$type });
|
|
106
|
+
return Object.assign(build, { partial }) as TransferNodeBuilder<TMap, TReflection>;
|
|
107
|
+
}
|
package/src/transfer-element.ts
CHANGED
|
@@ -29,10 +29,10 @@ export interface TransferElement {
|
|
|
29
29
|
* declared wire shape — or fall back to the structural base
|
|
30
30
|
* {@link TransferElement} when no entry is declared.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* `TransferElement` — the framework default behaves
|
|
35
|
-
* overlay (no autocomplete, but no compile error either).
|
|
32
|
+
* The transfer-model generator emits the overlay as `<LanguageId>TransferTypes`;
|
|
33
|
+
* an encoder that relabels a type overrides that entry. Types not in the
|
|
34
|
+
* overlay resolve to `TransferElement` — the framework default behaves
|
|
35
|
+
* correctly without an overlay (no autocomplete, but no compile error either).
|
|
36
36
|
*
|
|
37
37
|
* The lookup is compile-time only; no runtime cost.
|
|
38
38
|
*/
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The keys of a type map, Langium's `<LanguageName>AstType` or the generated
|
|
12
|
+
* `<LanguageId>TransferTypes`, that a node can carry as its `$type`: those
|
|
13
|
+
* listed in their own type's `$type`. A union, or an abstract type whose
|
|
14
|
+
* `$type` names only its subtypes, has a constant too, but building one would
|
|
15
|
+
* yield a node that no guard accepts. A concrete type with subtypes lists its
|
|
16
|
+
* own name beside theirs, as Langium writes it, and stays buildable.
|
|
17
|
+
*/
|
|
18
|
+
export type ConcreteTypeName<TMap> = {
|
|
19
|
+
[K in keyof TMap]: K extends (TMap[K] extends { readonly $type: infer TType } ? TType : never) ? K : never;
|
|
20
|
+
}[keyof TMap] &
|
|
21
|
+
string;
|
|
22
|
+
|
|
23
|
+
type IsUnion<T, TAll = T> = T extends unknown ? ([TAll] extends [T] ? false : true) : never;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Intersected onto a builder's type-constant parameter, refuses a constant
|
|
27
|
+
* typed by a union of type names: the init would hold only the members' common
|
|
28
|
+
* fields, so either type could be built incomplete.
|
|
29
|
+
*/
|
|
30
|
+
export type SingleTypeName<TType> = true extends IsUnion<TType> ? { readonly $type: never } : unknown;
|