@genesislcap/event-type-codegen 15.19.0 → 15.19.1
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 +3 -4
- package/license.txt +0 -46
- package/src/config.ts +0 -67
- package/src/index.ts +0 -184
- package/src/kotlin-parse-utils.ts +0 -75
- package/src/naming.ts +0 -80
- package/src/parse-dao.ts +0 -130
- package/src/parse-enums.ts +0 -105
- package/src/parse-kotlin.ts +0 -181
- package/src/parse-metadata.ts +0 -327
- package/src/render.ts +0 -149
- package/src/types.ts +0 -56
- package/test/fixtures/mini-server/src/main/kotlin/com/example/Handlers.kt +0 -23
- package/test/fixtures/mini-server/src/main/kotlin/com/example/dto/Samples.kt +0 -30
- package/test/generate.test.ts +0 -115
- package/test/kotlin-parse-utils.test.ts +0 -42
- package/test/naming.test.ts +0 -49
- package/test/parse-metadata.test.ts +0 -208
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
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": "15.19.
|
|
4
|
+
"version": "15.19.1",
|
|
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": "15.19.
|
|
24
|
+
"@genesislcap/foundation-testing": "15.19.1",
|
|
25
25
|
"@types/node": "^22.10.2",
|
|
26
26
|
"tsx": "^4.7.0",
|
|
27
27
|
"uvu": "0.5.4"
|
|
@@ -33,6 +33,5 @@
|
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
|
-
}
|
|
37
|
-
"gitHead": "83695de98c2288c2e89992215cb391652f6c5eec"
|
|
36
|
+
}
|
|
38
37
|
}
|
package/license.txt
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
Developer License Agreement
|
|
2
|
-
|
|
3
|
-
This Developer License Agreement (the “Agreement”) is entered into by and between Genesis, Global FinTech Inc.(“Genesis”) and you and/or the entity on whose behalf you are downloading the Software (as defined below) (“you”). This Agreement forms a legally binding contract between you and Genesis in relation to your use of the software libraries, reference implementations, and other related demonstration code (collectively, the “Genesis Software”). [a]
|
|
4
|
-
|
|
5
|
-
To use the Software, you must first agree to this Agreement. You may not use the Software if you do not agree to be bound by the terms of this Agreement. Accordingly, you and Genesis acknowledge and agree as follows:
|
|
6
|
-
|
|
7
|
-
1. LIMITED LICENSE.
|
|
8
|
-
Subject to your complete and ongoing compliance with all the terms and conditions set forth in this Agreement, including without limitation all license limitations and restrictions set forth herein, Genesis grants you the following limited, non-exclusive, non-transferable, non-sublicensable, revocable licenses to use, and (where applicable) authorize your employees to use, the Software internally solely in connection with building, developing and testing your own applications that interoperate with or incorporate the Software (“Applications”) for the purposes of evaluation.
|
|
9
|
-
|
|
10
|
-
2. RESTRICTIONS.
|
|
11
|
-
A. By accessing or using the Software, you represent, warrant, and covenant that (a) you are a person or business entity engaged in the development of software applications, and (b) in the case of a business entity, you have the full power and authority to bind such entity to the terms of this Agreement.
|
|
12
|
-
B. You acknowledge that the foregoing license does not include any right to:
|
|
13
|
-
(i) redistribute, sell, lease, license, modify or otherwise create any derivative works of any portion of the Software, or;
|
|
14
|
-
(ii) distribute, deploy, or otherwise utilize Applications on a public, production, commercial, or other similar purpose other than internal use for evaluation and the development of non-public, experimental Applications (any other public, production, commercial, or similar use requires a separate agreement with Genesis), or
|
|
15
|
-
(iii) use or implement any undocumented feature or API or use any documented feature or API other than in accordance with applicable documentation. You agree to not to do any of the foregoing.
|
|
16
|
-
C. Except as expressly provided herein, you may not:
|
|
17
|
-
(a) reproduce, distribute, publicly display, or publicly perform any part of the Software;
|
|
18
|
-
(b) decompile, reverse engineer, or otherwise access or attempt to access the source code for the Software not made available to you in source code form;
|
|
19
|
-
(c) make or attempt to make any modification to, or otherwise create derivative works of the Software; or
|
|
20
|
-
(d) remove, obscure, interfere with or circumvent any feature of the Software, including without limitation any copyright or other intellectual property notices, security, or access control mechanism;
|
|
21
|
-
(f) use the Software to do anything illegal, including facilitating, promoting, or otherwise encouraging any illegal activities.
|
|
22
|
-
|
|
23
|
-
3. RESERVATION OF RIGHTS.
|
|
24
|
-
A. The Software is owned by Genesis and licensed, not sold, to you. The Software, content, visual interfaces, interactive features, information, graphics, design, compilation, computer code, products, services, and all other elements of the Software and related documentation (the “Materials“), are protected by copyright, trade dress, patent, and trademark laws of the United States and other jurisdictions, international conventions, and all other relevant intellectual property and proprietary rights, and applicable laws (collectively, the “Intellectual Property Rights“).
|
|
25
|
-
B. You agree that Genesis or its subsidiaries or affiliated companies and/or its third-party licensors own all legal right, title and interest in and to the Software and Materials, including any and all Intellectual Property Rights. Genesis reserves all rights not expressly granted in this Agreement. You do not acquire any right, interest or title to the Materials, whether by implication, estoppel, or otherwise, except for the limited rights set forth in this Agreement.
|
|
26
|
-
C. You agree that the form and nature of the Software that Genesis provides may change without prior notice to you and that future versions of the Software may be incompatible with applications developed on previous of the Software. You agree that Genesis may stop (permanently or temporarily) providing the Software (or any features within the Software) to you or to users generally at Genesis’s sole discretion, without prior notice to you. Nothing in this Agreement gives you a right to use any of Genesis’s trade names, trademarks, service marks, logos, domain names, or other distinctive brand features.
|
|
27
|
-
|
|
28
|
-
4. TERMINATION.
|
|
29
|
-
At Genesis’s sole discretion, Genesis may terminate your Developer License and cease provision of the Genesis Software with or without notice, effective immediately, for any reason or no reason at all. Upon the expiration or termination of this Agreement all rights and licenses granted under this Agreement will immediately terminate.
|
|
30
|
-
|
|
31
|
-
5. THIRD PARTY SOFTWARE.
|
|
32
|
-
The Software consists of a package of components and may include references to certain third-party software (“Third Party Software”) that are provided by their authors under separate license terms (the “Third Party Terms”). Your use of any such Third-Party Software in conjunction with the Software in a manner consistent with this Agreement is permitted, however, you may have broader rights and/or restrictions under the applicable Third-Party Terms. Genesis cannot accept any responsibility for the Third-Party Software or your use thereof.
|
|
33
|
-
|
|
34
|
-
6. DISCLAIMER OF WARRANTIES.
|
|
35
|
-
YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SOFTWARE IS AT YOUR SOLE RISK AND THAT THE SOFTWARE IS PROVIDED “AS IS” AND “AS AVAILABLE” WITHOUT WARRANTY OF ANY KIND FROM GENESIS. YOUR USE OF THE SOFTWARE AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE SOFTWARE IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. GENESIS FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. GENESIS EXPRESSLY DISCLAIMS ANY WARRANTIES OF ANY KIND WITH RESPECT TO THE ACCURACY OR FUNCTIONALITY OF THE SOFTWARE, AND WITH RESPECT TO THE ACCURACY, VALIDITY, OR COMPLETENESS OF ANY INFORMATION OR FEATURES AVAILABLE THROUGH THE SOFTWARE, OR THE QUALITY OR CONSISTENCY OF THE SOFTWARE OR RESULTS OBTAINED THROUGH ITS USE.
|
|
36
|
-
|
|
37
|
-
7. INDEMNIFICATION. To the maximum extent permitted by law, you agree to defend, indemnify, and hold harmless Genesis, its affiliates, and their respective directors, officers, employees, and agents, from and against any and all third-party claims, actions, suits, or proceedings, as well as any and all losses, liabilities, damages, costs, and expenses (including reasonable attorneys’ fees) arising out of or accruing from (a) your breach of this Developer License; (b) your use or misuse of the Genesis Software; (c) your negligence or willful misconduct; and/or (d) your use of the Genesis Software that actually or allegedly infringes any Intellectual Property Rights or privacy rights of any third party in any jurisdiction.
|
|
38
|
-
|
|
39
|
-
8. MISCELLANEOUS.
|
|
40
|
-
(a) If you are agreeing to be bound by this Agreement on behalf of your employer or other entity, you represent and warrant that you have full legal authority to bind your employer or such entity to this Agreement. If you do not have the requisite authority, you may not accept this Agreement on behalf of your employer or other entity.
|
|
41
|
-
(b) This Developer License shall be governed by, and construed in accordance with, the laws of the State of New York without regard to conflict of law principles. For all purposes of this Developer License, the parties’ consent to exclusive jurisdiction and venue in the state and federal courts located in New York County, New York.
|
|
42
|
-
(c) Nothing in this Agreement, or in the nature of your access and use of the Genesis Software, shall create or is intended to create a joint-venture, partnership, or agency relationship between you and Genesis.
|
|
43
|
-
(d) You may not assign or transfer this Agreement or any of your rights or obligations hereunder, absent the prior written consent of Genesis.
|
|
44
|
-
(e) You agree that if Genesis does not exercise or enforce any legal right or remedy contained in this Agreement, this will not be taken to be a formal waiver of Genesis’s rights and that those rights or remedies will still be available to Genesis.
|
|
45
|
-
(f) This Agreement constitutes the complete understanding between you and Genesis with respect to the subject matter contained herein, and supersedes all prior written or oral communications, understandings, and agreements.
|
|
46
|
-
(g) If any provision of this Agreement is deemed to be illegal, invalid, or unenforceable, then that provision shall be removed, and the remaining terms will continue to be valid and enforceable.
|
package/src/config.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
-
import { join, resolve } from 'node:path';
|
|
3
|
-
|
|
4
|
-
import type { EventTypesConfig, EventTypesResolvedConfig } from './types';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_KOTLIN_SOURCES = [
|
|
7
|
-
'src/main/kotlin/**/dto/**/*.kt',
|
|
8
|
-
'src/main/genesis/scripts/**/*.kts',
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
const DEFAULT_HANDLER_SCAN = ['src/main/kotlin/**/*.kt', 'src/main/genesis/scripts/**/*.kts'];
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Relative to the parent of `serverModule` (the Gradle `server/` tree).
|
|
15
|
-
* Covers dictionary-cache and genesis-home layouts after `./gradlew …` generateDao.
|
|
16
|
-
*/
|
|
17
|
-
const DEFAULT_GENERATED_DAO_SOURCES = [
|
|
18
|
-
'build/internal-modules/**/*-generated-dao/build/generated/sources/dao/global/genesis/gen/dao/**/*.kt',
|
|
19
|
-
'**/build/genesis-home/generated/**/gen/dao/**/*.kt',
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const DEFAULT_OUTPUT = 'src/generated/genesis-event-types.ts';
|
|
23
|
-
|
|
24
|
-
const discoverServerModule = (clientRoot: string): string => {
|
|
25
|
-
const serverDir = resolve(clientRoot, '../server');
|
|
26
|
-
if (!existsSync(serverDir)) {
|
|
27
|
-
return '../server';
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const children = readdirSync(serverDir)
|
|
31
|
-
.map((name) => join(serverDir, name))
|
|
32
|
-
.filter((path) => {
|
|
33
|
-
try {
|
|
34
|
-
return statSync(path).isDirectory();
|
|
35
|
-
} catch {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
.filter((path) => existsSync(join(path, 'src', 'main', 'kotlin')));
|
|
40
|
-
|
|
41
|
-
if (children.length === 1) {
|
|
42
|
-
const relative = join('..', 'server', children[0].split(/[/\\]/).pop()!);
|
|
43
|
-
return relative.replace(/\\/g, '/');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return '../server';
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const resolveEventTypesConfig = (
|
|
50
|
-
clientRoot: string,
|
|
51
|
-
config?: Partial<EventTypesConfig> & { enabled?: boolean },
|
|
52
|
-
packageGenesis?: { eventTypes?: EventTypesConfig },
|
|
53
|
-
): EventTypesResolvedConfig => {
|
|
54
|
-
const fromGenesis = packageGenesis?.eventTypes ?? {};
|
|
55
|
-
const merged = { ...fromGenesis, ...config };
|
|
56
|
-
const enabled = merged.enabled === true;
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
enabled,
|
|
60
|
-
serverModule: merged.serverModule ?? discoverServerModule(clientRoot),
|
|
61
|
-
kotlinSources: merged.kotlinSources ?? DEFAULT_KOTLIN_SOURCES,
|
|
62
|
-
generatedDaoSources: merged.generatedDaoSources ?? DEFAULT_GENERATED_DAO_SOURCES,
|
|
63
|
-
handlerScan: merged.handlerScan ?? DEFAULT_HANDLER_SCAN,
|
|
64
|
-
output: merged.output ?? DEFAULT_OUTPUT,
|
|
65
|
-
runOnBuild: merged.runOnBuild ?? true,
|
|
66
|
-
};
|
|
67
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { existsSync, globSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { dirname, join, resolve } from 'node:path';
|
|
4
|
-
import { consola } from 'consola';
|
|
5
|
-
|
|
6
|
-
import { resolveEventTypesConfig } from './config';
|
|
7
|
-
import { parseGeneratedDaosFromSources } from './parse-dao';
|
|
8
|
-
import { parseGeneratedEnumsFromSources } from './parse-enums';
|
|
9
|
-
import { parseHandlersFromSources, parseDtosFromSources } from './parse-kotlin';
|
|
10
|
-
import {
|
|
11
|
-
parseEventMetadataDump,
|
|
12
|
-
renderEventTypesFromMetadataContracts,
|
|
13
|
-
type EventMetadataDump,
|
|
14
|
-
} from './parse-metadata';
|
|
15
|
-
import { renderEventTypesFile } from './render';
|
|
16
|
-
import type { EventTypesResolvedConfig, GenerateResult, KotlinDto } from './types';
|
|
17
|
-
|
|
18
|
-
const isDtoScanPath = (filePath: string) => filePath.replace(/\\/g, '/').includes('/dto/');
|
|
19
|
-
|
|
20
|
-
const isExcludedHandlerFile = (filePath: string) => {
|
|
21
|
-
const normalized = filePath.replace(/\\/g, '/');
|
|
22
|
-
return isDtoScanPath(normalized) && normalized.endsWith('EventHandler.kt');
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const collectFiles = (
|
|
26
|
-
root: string,
|
|
27
|
-
patterns: string[],
|
|
28
|
-
options?: { includeBuildDirs?: boolean },
|
|
29
|
-
) => {
|
|
30
|
-
const files = new Set<string>();
|
|
31
|
-
for (const pattern of patterns) {
|
|
32
|
-
const matches = globSync(pattern, {
|
|
33
|
-
cwd: root,
|
|
34
|
-
exclude: (name) => {
|
|
35
|
-
if (name === 'node_modules') return true;
|
|
36
|
-
if (!options?.includeBuildDirs && name === 'build') return true;
|
|
37
|
-
return false;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
for (const match of matches) {
|
|
41
|
-
files.add(join(root, match));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// Stable order so last/first-wins merges (DTOs, DAOs, enums) are reproducible
|
|
45
|
-
// across machines/filesystems — glob/Set iteration order is not.
|
|
46
|
-
return [...files].sort((a, b) => a.localeCompare(b));
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const mergeTypeMaps = (
|
|
50
|
-
primary: Map<string, KotlinDto>,
|
|
51
|
-
secondary: Map<string, KotlinDto>,
|
|
52
|
-
): Map<string, KotlinDto> => {
|
|
53
|
-
const merged = new Map(secondary);
|
|
54
|
-
for (const [name, dto] of primary) {
|
|
55
|
-
merged.set(name, dto);
|
|
56
|
-
}
|
|
57
|
-
return merged;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export type GenerateEventTypesOptions = {
|
|
61
|
-
clientRoot: string;
|
|
62
|
-
config?: EventTypesResolvedConfig;
|
|
63
|
-
packageGenesis?: { eventTypes?: unknown };
|
|
64
|
-
/** When set, generate from a header-captured metadata dump instead of Kotlin sources. */
|
|
65
|
-
fromMetadataPath?: string;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export async function generateEventTypesFromMetadata(options: {
|
|
69
|
-
clientRoot: string;
|
|
70
|
-
metadataPath: string;
|
|
71
|
-
output?: string;
|
|
72
|
-
}): Promise<GenerateResult> {
|
|
73
|
-
const metadataPath = resolve(options.clientRoot, options.metadataPath);
|
|
74
|
-
if (!existsSync(metadataPath)) {
|
|
75
|
-
throw new Error(`eventTypes: metadata dump not found at ${metadataPath}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let dump: EventMetadataDump;
|
|
79
|
-
try {
|
|
80
|
-
dump = JSON.parse(readFileSync(metadataPath, 'utf8')) as EventMetadataDump;
|
|
81
|
-
} catch (err) {
|
|
82
|
-
throw new Error(
|
|
83
|
-
`eventTypes: failed to parse metadata JSON dump at ${metadataPath}: ${
|
|
84
|
-
err instanceof Error ? err.message : String(err)
|
|
85
|
-
}`,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const { contracts, enums, unmapped } = parseEventMetadataDump(dump);
|
|
89
|
-
const contents = renderEventTypesFromMetadataContracts(contracts, enums, unmapped);
|
|
90
|
-
|
|
91
|
-
const outputRel = options.output ?? 'src/generated/genesis-event-types.ts';
|
|
92
|
-
const outputPath = resolve(options.clientRoot, outputRel);
|
|
93
|
-
await mkdir(dirname(outputPath), { recursive: true });
|
|
94
|
-
await writeFile(outputPath, contents, 'utf8');
|
|
95
|
-
|
|
96
|
-
consola.info(
|
|
97
|
-
`eventTypes: wrote ${outputPath} from metadata (${contracts.length} events, ${unmapped.length} unmapped)`,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
outputPath,
|
|
102
|
-
eventCount: contracts.length,
|
|
103
|
-
dtoCount: contracts.length,
|
|
104
|
-
unmappedCount: unmapped.length,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function generateEventTypes(
|
|
109
|
-
options: GenerateEventTypesOptions,
|
|
110
|
-
): Promise<GenerateResult | null> {
|
|
111
|
-
const resolved =
|
|
112
|
-
options.config ??
|
|
113
|
-
resolveEventTypesConfig(options.clientRoot, undefined, options.packageGenesis);
|
|
114
|
-
|
|
115
|
-
if (options.fromMetadataPath) {
|
|
116
|
-
return generateEventTypesFromMetadata({
|
|
117
|
-
clientRoot: options.clientRoot,
|
|
118
|
-
metadataPath: options.fromMetadataPath,
|
|
119
|
-
output: resolved.output,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (!resolved.enabled) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const serverRoot = resolve(options.clientRoot, resolved.serverModule);
|
|
128
|
-
if (!existsSync(serverRoot)) {
|
|
129
|
-
throw new Error(`eventTypes: server module not found at ${serverRoot}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Gradle `server/` tree — parent of the app module (e.g. …/server/showcase-app → …/server)
|
|
133
|
-
const serverWorkspaceRoot = resolve(serverRoot, '..');
|
|
134
|
-
|
|
135
|
-
const dtoFiles = collectFiles(serverRoot, resolved.kotlinSources).filter(
|
|
136
|
-
(file) => !isExcludedHandlerFile(file),
|
|
137
|
-
);
|
|
138
|
-
const handlerFiles = collectFiles(serverRoot, resolved.handlerScan).filter(
|
|
139
|
-
(file) => !isExcludedHandlerFile(file),
|
|
140
|
-
);
|
|
141
|
-
// Scan app module and Gradle server workspace (dictionary-cache lives under server/build/).
|
|
142
|
-
const daoFiles = [
|
|
143
|
-
...collectFiles(serverRoot, resolved.generatedDaoSources, { includeBuildDirs: true }),
|
|
144
|
-
...collectFiles(serverWorkspaceRoot, resolved.generatedDaoSources, {
|
|
145
|
-
includeBuildDirs: true,
|
|
146
|
-
}),
|
|
147
|
-
];
|
|
148
|
-
const uniqueDaoFiles = [...new Set(daoFiles)].sort((a, b) => a.localeCompare(b));
|
|
149
|
-
|
|
150
|
-
const customDtos = parseDtosFromSources(dtoFiles);
|
|
151
|
-
const generatedDaos = parseGeneratedDaosFromSources(uniqueDaoFiles);
|
|
152
|
-
const generatedEnums = parseGeneratedEnumsFromSources(uniqueDaoFiles);
|
|
153
|
-
const dtos = mergeTypeMaps(customDtos, generatedDaos);
|
|
154
|
-
const { mapped, unmapped } = parseHandlersFromSources(handlerFiles, dtos);
|
|
155
|
-
|
|
156
|
-
const outputPath = resolve(options.clientRoot, resolved.output);
|
|
157
|
-
const contents = renderEventTypesFile(mapped, unmapped, dtos, generatedEnums);
|
|
158
|
-
|
|
159
|
-
await mkdir(dirname(outputPath), { recursive: true });
|
|
160
|
-
await writeFile(outputPath, contents, 'utf8');
|
|
161
|
-
|
|
162
|
-
consola.info(
|
|
163
|
-
`eventTypes: wrote ${outputPath} (${mapped.length} events, ${customDtos.size} DTOs, ${generatedDaos.size} generated DAOs)`,
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
return {
|
|
167
|
-
outputPath,
|
|
168
|
-
eventCount: mapped.length,
|
|
169
|
-
dtoCount: dtos.size,
|
|
170
|
-
unmappedCount: unmapped.length,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export * from './types';
|
|
175
|
-
export { resolveEventTypesConfig } from './config';
|
|
176
|
-
export {
|
|
177
|
-
parseEventMetadataDump,
|
|
178
|
-
renderEventTypesFromMetadataContracts,
|
|
179
|
-
eventNameToDetailsInterfaceName,
|
|
180
|
-
type EventMetadataDump,
|
|
181
|
-
type MetadataEventContract,
|
|
182
|
-
type MetadataField,
|
|
183
|
-
} from './parse-metadata';
|
|
184
|
-
export { toUpperUnderscoreWithAcronyms, kotlinPropertyToWireField } from './naming';
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { KotlinProperty } from './types';
|
|
2
|
-
|
|
3
|
-
/** Strip Kotlin line and block comments from source before structural parsing. */
|
|
4
|
-
export const stripKotlinComments = (content: string): string =>
|
|
5
|
-
content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Strip annotations including use-site targets (field:/param:/get: prefixes).
|
|
9
|
-
* Nested call args in annotations are not fully balanced (secondary limitation).
|
|
10
|
-
*/
|
|
11
|
-
export const stripKotlinAnnotations = (segment: string): string =>
|
|
12
|
-
segment
|
|
13
|
-
.replace(/@(?:\w+:)?[A-Za-z_][\w.]*(?:\s*<[^>]*>)?(?:\s*\([^)]*\))?/g, ' ')
|
|
14
|
-
.replace(/\s+/g, ' ')
|
|
15
|
-
.trim();
|
|
16
|
-
|
|
17
|
-
/** Split a constructor/parameter list on top-level commas (respecting nested brackets). */
|
|
18
|
-
export const splitTopLevelArgs = (body: string): string[] => {
|
|
19
|
-
const parts: string[] = [];
|
|
20
|
-
let depth = 0;
|
|
21
|
-
let current = '';
|
|
22
|
-
for (const ch of body) {
|
|
23
|
-
if (ch === '(' || ch === '<' || ch === '[') depth += 1;
|
|
24
|
-
if (ch === ')' || ch === '>' || ch === ']') depth -= 1;
|
|
25
|
-
if (ch === ',' && depth === 0) {
|
|
26
|
-
parts.push(current.trim());
|
|
27
|
-
current = '';
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
current += ch;
|
|
31
|
-
}
|
|
32
|
-
if (current.trim()) parts.push(current.trim());
|
|
33
|
-
return parts;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type ParseKotlinPropertyOptions = {
|
|
37
|
-
/** Allow bare ctor params without val/var (sequenced PKs in generated DAOs). */
|
|
38
|
-
allowBareParams?: boolean;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/** Plain or backtick-escaped Kotlin identifier (`value` for reserved words). */
|
|
42
|
-
const KOTLIN_IDENT = '(?:\\w+|`[^`]+`)';
|
|
43
|
-
|
|
44
|
-
const PROPERTY_REGEX = new RegExp(
|
|
45
|
-
`^(?:public\\s+)?(?:val|var)\\s+(${KOTLIN_IDENT})\\s*:\\s*([^=]+?)(?:\\s*=\\s*.+)?$`,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const BARE_PROPERTY_REGEX = new RegExp(`^(${KOTLIN_IDENT})\\s*:\\s*([^=]+?)(?:\\s*=\\s*.+)?$`);
|
|
49
|
-
|
|
50
|
-
const stripBackticks = (ident: string): string =>
|
|
51
|
-
ident.startsWith('`') && ident.endsWith('`') ? ident.slice(1, -1) : ident;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Parse a Kotlin constructor / data-class property segment into a wire-facing property.
|
|
55
|
-
* Accepts optional public modifier, use-site-stripped annotations, and backtick-escaped
|
|
56
|
-
* reserved identifiers (e.g. `value` → value → wire VALUE).
|
|
57
|
-
*/
|
|
58
|
-
export const parseKotlinProperty = (
|
|
59
|
-
segment: string,
|
|
60
|
-
options: ParseKotlinPropertyOptions = {},
|
|
61
|
-
): KotlinProperty | null => {
|
|
62
|
-
const cleaned = stripKotlinAnnotations(segment);
|
|
63
|
-
const propertyMatch = cleaned.match(PROPERTY_REGEX);
|
|
64
|
-
const match =
|
|
65
|
-
propertyMatch ?? (options.allowBareParams ? cleaned.match(BARE_PROPERTY_REGEX) : null);
|
|
66
|
-
|
|
67
|
-
if (!match) return null;
|
|
68
|
-
|
|
69
|
-
const name = stripBackticks(match[1]);
|
|
70
|
-
let kotlinType = match[2].trim();
|
|
71
|
-
const optional = kotlinType.endsWith('?') || cleaned.includes('=');
|
|
72
|
-
kotlinType = kotlinType.replace(/\?$/, '').trim();
|
|
73
|
-
|
|
74
|
-
return { name, kotlinType, optional };
|
|
75
|
-
};
|
package/src/naming.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { pascalCase } from 'change-case';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Character classification used by {@link toUpperUnderscoreWithAcronyms}.
|
|
5
|
-
* Mirrors genesis-server `CharType` in GenesisMessage.kt.
|
|
6
|
-
*/
|
|
7
|
-
type CharType = 'UPPERCASE' | 'LOWERCASE' | 'NUMBER';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Convert camelCase / PascalCase to UPPER_UNDERSCORE, inserting `_` before digits and
|
|
11
|
-
* splitting acronyms the same way as genesis-server `toUpperUnderscoreWithAcronyms`.
|
|
12
|
-
*
|
|
13
|
-
* Examples: `addressLine1` → `ADDRESS_LINE_1`, `orderID` → `ORDER_ID`.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export const toUpperUnderscoreWithAcronyms = (name: string): string => {
|
|
18
|
-
if (!name) return name;
|
|
19
|
-
|
|
20
|
-
// Already wire-formatted — genesis-server passes these through unchanged.
|
|
21
|
-
if (/^[A-Z0-9]+(?:_[A-Z0-9]+)*$/.test(name)) return name;
|
|
22
|
-
|
|
23
|
-
const length = name.length;
|
|
24
|
-
const result: string[] = [];
|
|
25
|
-
// Genesis seeds non-upper (including digits) as NUMBER so the first digit after
|
|
26
|
-
// letters still gets a leading underscore on subsequent chars.
|
|
27
|
-
let lastCharacterType: CharType = name[0] >= 'A' && name[0] <= 'Z' ? 'UPPERCASE' : 'NUMBER';
|
|
28
|
-
|
|
29
|
-
result.push(name[0].toUpperCase());
|
|
30
|
-
|
|
31
|
-
const isUpperOrDigit = (c: string): boolean => (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
|
|
32
|
-
|
|
33
|
-
for (let i = 1; i < length; i += 1) {
|
|
34
|
-
const ch = name[i];
|
|
35
|
-
if (ch >= 'A' && ch <= 'Z') {
|
|
36
|
-
// Continue an acronym run when the next char is also upper/digit; otherwise split.
|
|
37
|
-
const continueAcronym =
|
|
38
|
-
lastCharacterType === 'UPPERCASE' && (i + 1 >= length || isUpperOrDigit(name[i + 1]));
|
|
39
|
-
if (!continueAcronym) {
|
|
40
|
-
result.push('_');
|
|
41
|
-
}
|
|
42
|
-
result.push(ch);
|
|
43
|
-
lastCharacterType = 'UPPERCASE';
|
|
44
|
-
} else if (ch >= '0' && ch <= '9') {
|
|
45
|
-
if (lastCharacterType !== 'NUMBER') {
|
|
46
|
-
result.push('_');
|
|
47
|
-
}
|
|
48
|
-
result.push(ch);
|
|
49
|
-
lastCharacterType = 'NUMBER';
|
|
50
|
-
} else {
|
|
51
|
-
result.push(ch.toUpperCase());
|
|
52
|
-
lastCharacterType = 'LOWERCASE';
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return result.join('');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/** Wire field name for a Kotlin property (DETAILS uses UPPER_SNAKE_CASE). */
|
|
60
|
-
export const kotlinPropertyToWireField = (propertyName: string): string =>
|
|
61
|
-
toUpperUnderscoreWithAcronyms(propertyName);
|
|
62
|
-
|
|
63
|
-
/** Generated interface name for a Kotlin DTO or handler input type. */
|
|
64
|
-
export const dtoToDetailsInterfaceName = (dtoName: string): string =>
|
|
65
|
-
dtoName.endsWith('Details') ? dtoName : `${dtoName}Details`;
|
|
66
|
-
|
|
67
|
-
/** e.g. `Trade.ById` → `TradeByIdDetails`, `FooInput` → `FooInputDetails` */
|
|
68
|
-
export const handlerInputToDetailsInterfaceName = (inputType: string): string => {
|
|
69
|
-
const indexMatch = inputType.match(/^(\w+)\.(By\w+)$/);
|
|
70
|
-
if (indexMatch) {
|
|
71
|
-
return `${indexMatch[1]}${indexMatch[2]}Details`;
|
|
72
|
-
}
|
|
73
|
-
return dtoToDetailsInterfaceName(inputType);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/** Per-event class carrying MESSAGE_TYPE and DETAILS (one per PAL handler). */
|
|
77
|
-
export const eventNameToEventClassName = (eventName: string): string => {
|
|
78
|
-
const base = eventName.startsWith('EVENT_') ? eventName.slice('EVENT_'.length) : eventName;
|
|
79
|
-
return `Event${pascalCase(base)}`;
|
|
80
|
-
};
|
package/src/parse-dao.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
|
|
3
|
-
import { parseKotlinProperty, splitTopLevelArgs, stripKotlinComments } from './kotlin-parse-utils';
|
|
4
|
-
import type { KotlinDto, KotlinProperty } from './types';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Generated Genesis DAO entities use a primary constructor with annotated
|
|
8
|
-
* `public var` parameters (and sometimes bare params for sequenced PKs).
|
|
9
|
-
* Only files directly under `.../gen/dao/*.kt` are entity classes.
|
|
10
|
-
*/
|
|
11
|
-
export const isGeneratedDaoEntityFile = (filePath: string): boolean => {
|
|
12
|
-
const normalized = filePath.replace(/\\/g, '/');
|
|
13
|
-
return /\/gen\/dao\/[^/]+\.kt$/i.test(normalized);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const KOTLIN_FILE_EXTENSION = '.kt';
|
|
17
|
-
|
|
18
|
-
const entityNameFromDaoFile = (filePath: string): string | null => {
|
|
19
|
-
const base = filePath.replace(/\\/g, '/').split('/').pop();
|
|
20
|
-
if (!base?.endsWith(KOTLIN_FILE_EXTENSION)) return null;
|
|
21
|
-
return base.slice(0, base.length - KOTLIN_FILE_EXTENSION.length);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Nested `data class By*` index types inside generated entity Kotlin (e.g. Trade.ById).
|
|
26
|
-
*/
|
|
27
|
-
export const extractGeneratedDaoIndices = (content: string, filePath: string): KotlinDto[] => {
|
|
28
|
-
const entityName = entityNameFromDaoFile(filePath);
|
|
29
|
-
if (!entityName) return [];
|
|
30
|
-
|
|
31
|
-
const results: KotlinDto[] = [];
|
|
32
|
-
const indexRegex = /(?:^|\n)\s*public\s+data\s+class\s+(By\w+)\s*\(/gm;
|
|
33
|
-
let match: RegExpExecArray | null;
|
|
34
|
-
|
|
35
|
-
while ((match = indexRegex.exec(content)) !== null) {
|
|
36
|
-
const indexName = match[1];
|
|
37
|
-
const openParenIndex = match.index + match[0].length - 1;
|
|
38
|
-
let depth = 0;
|
|
39
|
-
let closeIndex = -1;
|
|
40
|
-
for (let i = openParenIndex; i < content.length; i += 1) {
|
|
41
|
-
const ch = content[i];
|
|
42
|
-
if (ch === '(') depth += 1;
|
|
43
|
-
if (ch === ')') {
|
|
44
|
-
depth -= 1;
|
|
45
|
-
if (depth === 0) {
|
|
46
|
-
closeIndex = i;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (closeIndex === -1) continue;
|
|
52
|
-
|
|
53
|
-
const body = content.slice(openParenIndex + 1, closeIndex);
|
|
54
|
-
const properties = splitTopLevelArgs(body)
|
|
55
|
-
.map((segment) => parseKotlinProperty(segment))
|
|
56
|
-
.filter((p): p is KotlinProperty => p != null);
|
|
57
|
-
|
|
58
|
-
if (properties.length === 0) continue;
|
|
59
|
-
|
|
60
|
-
results.push({
|
|
61
|
-
name: `${entityName}.${indexName}`,
|
|
62
|
-
properties,
|
|
63
|
-
filePath,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return results;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Extract table entity classes from generated DAO Kotlin sources.
|
|
72
|
-
* Prefer entities that look like Genesis table DAOs (constructor + TableEntity).
|
|
73
|
-
*/
|
|
74
|
-
export const extractGeneratedDaoEntities = (content: string, filePath: string): KotlinDto[] => {
|
|
75
|
-
const results: KotlinDto[] = [];
|
|
76
|
-
// Matches: public class Trade public constructor( ... ) :
|
|
77
|
-
const classRegex = /(?:^|\n)\s*(?:public\s+)?class\s+(\w+)\s+(?:public\s+)?constructor\s*\(/gm;
|
|
78
|
-
let match: RegExpExecArray | null;
|
|
79
|
-
|
|
80
|
-
while ((match = classRegex.exec(content)) !== null) {
|
|
81
|
-
const name = match[1];
|
|
82
|
-
const openParenIndex = match.index + match[0].length - 1;
|
|
83
|
-
let depth = 0;
|
|
84
|
-
let closeIndex = -1;
|
|
85
|
-
for (let i = openParenIndex; i < content.length; i += 1) {
|
|
86
|
-
const ch = content[i];
|
|
87
|
-
if (ch === '(') depth += 1;
|
|
88
|
-
if (ch === ')') {
|
|
89
|
-
depth -= 1;
|
|
90
|
-
if (depth === 0) {
|
|
91
|
-
closeIndex = i;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (closeIndex === -1) continue;
|
|
97
|
-
|
|
98
|
-
const body = content.slice(openParenIndex + 1, closeIndex);
|
|
99
|
-
const properties = splitTopLevelArgs(body)
|
|
100
|
-
.map((segment) => parseKotlinProperty(segment, { allowBareParams: true }))
|
|
101
|
-
.filter((p): p is KotlinProperty => p != null);
|
|
102
|
-
|
|
103
|
-
if (properties.length > 0) {
|
|
104
|
-
results.push({ name, properties, filePath });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return results;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export const parseGeneratedDaosFromSources = (files: string[]): Map<string, KotlinDto> => {
|
|
112
|
-
const daos = new Map<string, KotlinDto>();
|
|
113
|
-
|
|
114
|
-
for (const filePath of files) {
|
|
115
|
-
if (!isGeneratedDaoEntityFile(filePath)) continue;
|
|
116
|
-
const content = stripKotlinComments(readFileSync(filePath, 'utf8'));
|
|
117
|
-
for (const entity of extractGeneratedDaoEntities(content, filePath)) {
|
|
118
|
-
if (!daos.has(entity.name)) {
|
|
119
|
-
daos.set(entity.name, entity);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (const index of extractGeneratedDaoIndices(content, filePath)) {
|
|
123
|
-
if (!daos.has(index.name)) {
|
|
124
|
-
daos.set(index.name, index);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return daos;
|
|
130
|
-
};
|