@genesislcap/event-type-codegen 14.489.0-canary.FUI-2574 → 14.491.0-canary.FUI-2574-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/dist/render.d.ts.map +1 -1
- package/dist/render.js +32 -5
- package/dist/render.js.map +1 -1
- package/package.json +3 -3
- package/src/render.ts +36 -5
- package/test/fixtures/client-out/genesis-event-types.ts +19 -0
- package/test/fixtures/golden/genesis-event-types.ts +19 -0
- package/test/fixtures/mini-server/src/main/kotlin/com/example/Handlers.kt +2 -0
- package/test/fixtures/mini-server/src/main/kotlin/com/example/dto/Samples.kt +10 -0
- package/test/generate.test.ts +8 -1
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAKA,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAKA,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AA6GzE,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,aAAa,EAAE,EACvB,UAAU,eAAe,EAAE,EAC3B,MAAM,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EAC5B,QAAO,aAAyB,KAC/B,MA2BF,CAAC"}
|
package/dist/render.js
CHANGED
|
@@ -4,6 +4,33 @@ exports.renderEventTypesFile = void 0;
|
|
|
4
4
|
const naming_1 = require("./naming");
|
|
5
5
|
const parse_enums_1 = require("./parse-enums");
|
|
6
6
|
const parse_kotlin_1 = require("./parse-kotlin");
|
|
7
|
+
const kotlinTypeRoot = (kotlinType) => {
|
|
8
|
+
const listMatch = kotlinType.match(/^(?:List|MutableList|Set|MutableSet)<(.+)>$/);
|
|
9
|
+
if (listMatch) {
|
|
10
|
+
return kotlinTypeRoot(listMatch[1].trim());
|
|
11
|
+
}
|
|
12
|
+
return kotlinType.replace(/\?$/, '').trim();
|
|
13
|
+
};
|
|
14
|
+
/** Handler inputs plus any nested custom DTOs referenced from their properties. */
|
|
15
|
+
const expandUsedDtoNames = (mapped, dtos) => {
|
|
16
|
+
const used = new Set();
|
|
17
|
+
const visit = (dtoName) => {
|
|
18
|
+
if (used.has(dtoName) || !dtos.has(dtoName))
|
|
19
|
+
return;
|
|
20
|
+
used.add(dtoName);
|
|
21
|
+
const dto = dtos.get(dtoName);
|
|
22
|
+
for (const prop of dto.properties) {
|
|
23
|
+
const nested = kotlinTypeRoot(prop.kotlinType);
|
|
24
|
+
if (dtos.has(nested)) {
|
|
25
|
+
visit(nested);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
for (const handler of mapped) {
|
|
30
|
+
visit(handler.inputType);
|
|
31
|
+
}
|
|
32
|
+
return used;
|
|
33
|
+
};
|
|
7
34
|
const renderInterface = (dto, dtos, enums) => {
|
|
8
35
|
const interfaceName = (0, naming_1.handlerInputToDetailsInterfaceName)(dto.name);
|
|
9
36
|
const lines = dto.properties.map((prop) => {
|
|
@@ -48,10 +75,10 @@ const renderEnumExports = (enums, usedEnumNames) => {
|
|
|
48
75
|
}
|
|
49
76
|
return blocks.length > 0 ? `${blocks.join('\n\n')}\n\n` : '';
|
|
50
77
|
};
|
|
51
|
-
const collectUsedEnumNames = (
|
|
78
|
+
const collectUsedEnumNames = (usedDtoNames, dtos, enums) => {
|
|
52
79
|
const used = new Set();
|
|
53
|
-
for (const
|
|
54
|
-
const dto = dtos.get(
|
|
80
|
+
for (const dtoName of usedDtoNames) {
|
|
81
|
+
const dto = dtos.get(dtoName);
|
|
55
82
|
if (!dto)
|
|
56
83
|
continue;
|
|
57
84
|
for (const prop of dto.properties) {
|
|
@@ -63,13 +90,13 @@ const collectUsedEnumNames = (mapped, dtos, enums) => {
|
|
|
63
90
|
return used;
|
|
64
91
|
};
|
|
65
92
|
const renderEventTypesFile = (mapped, unmapped, dtos, enums = new Map()) => {
|
|
66
|
-
const usedDtos =
|
|
93
|
+
const usedDtos = expandUsedDtoNames(mapped, dtos);
|
|
67
94
|
const interfaces = [...usedDtos]
|
|
68
95
|
.map((name) => dtos.get(name))
|
|
69
96
|
.filter((dto) => dto != null)
|
|
70
97
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
71
98
|
.map((dto) => renderInterface(dto, dtos, enums));
|
|
72
|
-
const usedEnumNames = collectUsedEnumNames(
|
|
99
|
+
const usedEnumNames = collectUsedEnumNames(usedDtos, dtos, enums);
|
|
73
100
|
const enumExports = renderEnumExports(enums, usedEnumNames);
|
|
74
101
|
const mapEntries = mapped.map((m) => ` ${m.eventName}: ${m.detailsInterface};`).join('\n');
|
|
75
102
|
const eventClasses = renderEventClasses(mapped);
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":";;;AAAA,qCAIkB;AAClB,+CAAsE;AACtE,iDAAgD;AAGhD,MAAM,eAAe,GAAG,CACtB,GAAc,EACd,IAA4B,EAC5B,KAAoB,EACZ,EAAE;IACV,MAAM,aAAa,GAAG,IAAA,2CAAkC,EAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,MAAM,QAAQ,GAAG,IAAA,kCAAyB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,IAAA,6BAAc,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CA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AE5D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE5F,MAAM,YAAY,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,qBAAqB,GACzB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,mEAAmE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE/F,OAAO;;EAEP,qBAAqB,CAAC,QAAQ,CAAC,GAAG,qBAAqB,GAAG,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;;;EAG/F,UAAU;;;;EAIV,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC9C,CAAC,CAAC;AAhCW,QAAA,oBAAoB,wBAgC/B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/event-type-codegen",
|
|
3
3
|
"description": "Build-time TypeScript codegen from Kotlin event handler DTOs",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.491.0-canary.FUI-2574-2",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"consola": "^3.0.2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@genesislcap/foundation-testing": "14.
|
|
24
|
+
"@genesislcap/foundation-testing": "14.491.0-canary.FUI-2574-2",
|
|
25
25
|
"@types/node": "^22.10.2",
|
|
26
26
|
"tsx": "^4.7.0",
|
|
27
27
|
"uvu": "0.5.4"
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "161356e51cd0fc95a59154009859d0c8481119c9"
|
|
38
38
|
}
|
package/src/render.ts
CHANGED
|
@@ -7,6 +7,37 @@ import { kotlinEnumTypeRef, type KotlinEnumMap } from './parse-enums';
|
|
|
7
7
|
import { kotlinTypeToTs } from './parse-kotlin';
|
|
8
8
|
import type { KotlinDto, MappedHandler, UnmappedHandler } from './types';
|
|
9
9
|
|
|
10
|
+
const kotlinTypeRoot = (kotlinType: string): string => {
|
|
11
|
+
const listMatch = kotlinType.match(/^(?:List|MutableList|Set|MutableSet)<(.+)>$/);
|
|
12
|
+
if (listMatch) {
|
|
13
|
+
return kotlinTypeRoot(listMatch[1].trim());
|
|
14
|
+
}
|
|
15
|
+
return kotlinType.replace(/\?$/, '').trim();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Handler inputs plus any nested custom DTOs referenced from their properties. */
|
|
19
|
+
const expandUsedDtoNames = (mapped: MappedHandler[], dtos: Map<string, KotlinDto>): Set<string> => {
|
|
20
|
+
const used = new Set<string>();
|
|
21
|
+
|
|
22
|
+
const visit = (dtoName: string) => {
|
|
23
|
+
if (used.has(dtoName) || !dtos.has(dtoName)) return;
|
|
24
|
+
used.add(dtoName);
|
|
25
|
+
const dto = dtos.get(dtoName)!;
|
|
26
|
+
for (const prop of dto.properties) {
|
|
27
|
+
const nested = kotlinTypeRoot(prop.kotlinType);
|
|
28
|
+
if (dtos.has(nested)) {
|
|
29
|
+
visit(nested);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
for (const handler of mapped) {
|
|
35
|
+
visit(handler.inputType);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return used;
|
|
39
|
+
};
|
|
40
|
+
|
|
10
41
|
const renderInterface = (
|
|
11
42
|
dto: KotlinDto,
|
|
12
43
|
dtos: Map<string, KotlinDto>,
|
|
@@ -67,13 +98,13 @@ const renderEnumExports = (enums: KotlinEnumMap, usedEnumNames: Set<string>): st
|
|
|
67
98
|
};
|
|
68
99
|
|
|
69
100
|
const collectUsedEnumNames = (
|
|
70
|
-
|
|
101
|
+
usedDtoNames: Set<string>,
|
|
71
102
|
dtos: Map<string, KotlinDto>,
|
|
72
103
|
enums: KotlinEnumMap,
|
|
73
104
|
): Set<string> => {
|
|
74
105
|
const used = new Set<string>();
|
|
75
|
-
for (const
|
|
76
|
-
const dto = dtos.get(
|
|
106
|
+
for (const dtoName of usedDtoNames) {
|
|
107
|
+
const dto = dtos.get(dtoName);
|
|
77
108
|
if (!dto) continue;
|
|
78
109
|
for (const prop of dto.properties) {
|
|
79
110
|
const ref = kotlinEnumTypeRef(prop.kotlinType, enums);
|
|
@@ -89,14 +120,14 @@ export const renderEventTypesFile = (
|
|
|
89
120
|
dtos: Map<string, KotlinDto>,
|
|
90
121
|
enums: KotlinEnumMap = new Map(),
|
|
91
122
|
): string => {
|
|
92
|
-
const usedDtos =
|
|
123
|
+
const usedDtos = expandUsedDtoNames(mapped, dtos);
|
|
93
124
|
const interfaces = [...usedDtos]
|
|
94
125
|
.map((name) => dtos.get(name))
|
|
95
126
|
.filter((dto): dto is KotlinDto => dto != null)
|
|
96
127
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
97
128
|
.map((dto) => renderInterface(dto, dtos, enums));
|
|
98
129
|
|
|
99
|
-
const usedEnumNames = collectUsedEnumNames(
|
|
130
|
+
const usedEnumNames = collectUsedEnumNames(usedDtos, dtos, enums);
|
|
100
131
|
const enumExports = renderEnumExports(enums, usedEnumNames);
|
|
101
132
|
|
|
102
133
|
const mapEntries = mapped.map((m) => ` ${m.eventName}: ${m.detailsInterface};`).join('\n');
|
|
@@ -14,6 +14,16 @@ export const Side = {
|
|
|
14
14
|
|
|
15
15
|
export type Side = (typeof Side)[keyof typeof Side];
|
|
16
16
|
|
|
17
|
+
export interface AmendCellInputDetails {
|
|
18
|
+
MAX_SIZE: number;
|
|
19
|
+
MAX_INSTRUMENT_SCORE: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ChargeAmendInputDetails {
|
|
23
|
+
CHARGE_ADDITION_ID: string;
|
|
24
|
+
CELLS: AmendCellInputDetails[];
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
export interface FooInputDetails {
|
|
18
28
|
FOO_ID: string;
|
|
19
29
|
BAR_ID?: string;
|
|
@@ -44,6 +54,7 @@ export interface TradeByIdDetails {
|
|
|
44
54
|
|
|
45
55
|
export interface EventDetailsMap {
|
|
46
56
|
EVENT_BAR_BAZ: NestedInputDetails;
|
|
57
|
+
EVENT_CHARGE_AMEND: ChargeAmendInputDetails;
|
|
47
58
|
EVENT_CONTEXT_FOO: FooInputDetails;
|
|
48
59
|
EVENT_DAO_HANDLER: InstrumentByIdDetails;
|
|
49
60
|
EVENT_FOO: FooInputDetails;
|
|
@@ -61,6 +72,14 @@ export class EventBarBaz extends GenesisEvent<'EVENT_BAR_BAZ', NestedInputDetail
|
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
74
|
|
|
75
|
+
export class EventChargeAmend extends GenesisEvent<'EVENT_CHARGE_AMEND', ChargeAmendInputDetails> {
|
|
76
|
+
readonly MESSAGE_TYPE = 'EVENT_CHARGE_AMEND' as const;
|
|
77
|
+
|
|
78
|
+
constructor(details: ChargeAmendInputDetails) {
|
|
79
|
+
super(details);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
64
83
|
export class EventContextFoo extends GenesisEvent<'EVENT_CONTEXT_FOO', FooInputDetails> {
|
|
65
84
|
readonly MESSAGE_TYPE = 'EVENT_CONTEXT_FOO' as const;
|
|
66
85
|
|
|
@@ -14,6 +14,16 @@ export const Side = {
|
|
|
14
14
|
|
|
15
15
|
export type Side = (typeof Side)[keyof typeof Side];
|
|
16
16
|
|
|
17
|
+
export interface AmendCellInputDetails {
|
|
18
|
+
MAX_SIZE: number;
|
|
19
|
+
MAX_INSTRUMENT_SCORE: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ChargeAmendInputDetails {
|
|
23
|
+
CHARGE_ADDITION_ID: string;
|
|
24
|
+
CELLS: AmendCellInputDetails[];
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
export interface FooInputDetails {
|
|
18
28
|
FOO_ID: string;
|
|
19
29
|
BAR_ID?: string;
|
|
@@ -44,6 +54,7 @@ export interface TradeByIdDetails {
|
|
|
44
54
|
|
|
45
55
|
export interface EventDetailsMap {
|
|
46
56
|
EVENT_BAR_BAZ: NestedInputDetails;
|
|
57
|
+
EVENT_CHARGE_AMEND: ChargeAmendInputDetails;
|
|
47
58
|
EVENT_CONTEXT_FOO: FooInputDetails;
|
|
48
59
|
EVENT_DAO_HANDLER: InstrumentByIdDetails;
|
|
49
60
|
EVENT_FOO: FooInputDetails;
|
|
@@ -61,6 +72,14 @@ export class EventBarBaz extends GenesisEvent<'EVENT_BAR_BAZ', NestedInputDetail
|
|
|
61
72
|
}
|
|
62
73
|
}
|
|
63
74
|
|
|
75
|
+
export class EventChargeAmend extends GenesisEvent<'EVENT_CHARGE_AMEND', ChargeAmendInputDetails> {
|
|
76
|
+
readonly MESSAGE_TYPE = 'EVENT_CHARGE_AMEND' as const;
|
|
77
|
+
|
|
78
|
+
constructor(details: ChargeAmendInputDetails) {
|
|
79
|
+
super(details);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
64
83
|
export class EventContextFoo extends GenesisEvent<'EVENT_CONTEXT_FOO', FooInputDetails> {
|
|
65
84
|
readonly MESSAGE_TYPE = 'EVENT_CONTEXT_FOO' as const;
|
|
66
85
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
package com.example
|
|
2
2
|
|
|
3
|
+
import com.example.dto.ChargeAmendInput
|
|
3
4
|
import com.example.dto.FooInput
|
|
4
5
|
import com.example.dto.NestedInput
|
|
5
6
|
|
|
6
7
|
fun register() {
|
|
7
8
|
eventHandler<FooInput>("FOO")
|
|
8
9
|
eventHandler<NestedInput>("BAR_BAZ")
|
|
10
|
+
eventHandler<ChargeAmendInput>("CHARGE_AMEND")
|
|
9
11
|
contextEventHandler<FooInput, String>(name = "CONTEXT_FOO")
|
|
10
12
|
// Full table DAO — resolved from generated-dao sources
|
|
11
13
|
eventHandler<Trade>("TRADE_INSERT", transactional = true)
|
|
@@ -5,6 +5,16 @@ data class FooInput(
|
|
|
5
5
|
/* optional bar, with comma */ val barId: String? = null,
|
|
6
6
|
)
|
|
7
7
|
|
|
8
|
+
data class AmendCellInput(
|
|
9
|
+
val maxSize: Int,
|
|
10
|
+
val maxInstrumentScore: Int,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
data class ChargeAmendInput(
|
|
14
|
+
val chargeAdditionId: String,
|
|
15
|
+
val cells: List<AmendCellInput>,
|
|
16
|
+
)
|
|
17
|
+
|
|
8
18
|
data class NestedInput(
|
|
9
19
|
val items: List<FooInput>,
|
|
10
20
|
)
|
package/test/generate.test.ts
CHANGED
|
@@ -31,7 +31,7 @@ suite('generates golden genesis-event-types.ts from fixture Kotlin module', asyn
|
|
|
31
31
|
});
|
|
32
32
|
|
|
33
33
|
assert.ok(result);
|
|
34
|
-
assert.equal(result?.eventCount,
|
|
34
|
+
assert.equal(result?.eventCount, 7);
|
|
35
35
|
|
|
36
36
|
const actual = readFileSync(outputPath, 'utf8').trim();
|
|
37
37
|
const expected = readFileSync(goldenPath, 'utf8').trim();
|
|
@@ -85,4 +85,11 @@ suite('parses handlers with trailing named args (transactional)', async () => {
|
|
|
85
85
|
assert.is(actual.includes('EVENT_TRADE_INSERT: TradeDetails'), true);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
+
suite('emits nested DTO interfaces not used as handler inputs', async () => {
|
|
89
|
+
const actual = readFileSync(goldenPath, 'utf8');
|
|
90
|
+
assert.is(actual.includes('export interface AmendCellInputDetails'), true);
|
|
91
|
+
assert.is(actual.includes('CELLS: AmendCellInputDetails[]'), true);
|
|
92
|
+
assert.is(actual.includes('EVENT_CHARGE_AMEND: ChargeAmendInputDetails'), true);
|
|
93
|
+
});
|
|
94
|
+
|
|
88
95
|
suite.run();
|