@genesislcap/event-type-codegen 14.489.0-canary.FUI-2574-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/README.md +80 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +58 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/dist/naming.d.ts +9 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/naming.js +26 -0
- package/dist/naming.js.map +1 -0
- package/dist/parse-dao.d.ts +18 -0
- package/dist/parse-dao.d.ts.map +1 -0
- package/dist/parse-dao.js +175 -0
- package/dist/parse-dao.js.map +1 -0
- package/dist/parse-enums.d.ts +16 -0
- package/dist/parse-enums.d.ts.map +1 -0
- package/dist/parse-enums.js +98 -0
- package/dist/parse-enums.js.map +1 -0
- package/dist/parse-kotlin.d.ts +15 -0
- package/dist/parse-kotlin.d.ts.map +1 -0
- package/dist/parse-kotlin.js +190 -0
- package/dist/parse-kotlin.js.map +1 -0
- package/dist/render.d.ts +4 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +89 -0
- package/dist/render.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/license.txt +46 -0
- package/package.json +38 -0
- package/src/config.ts +67 -0
- package/src/index.ts +118 -0
- package/src/naming.ts +24 -0
- package/src/parse-dao.ts +186 -0
- package/src/parse-enums.ts +105 -0
- package/src/parse-kotlin.ts +216 -0
- package/src/render.ts +118 -0
- package/src/types.ts +56 -0
- package/test/fixtures/client-out/genesis-event-types.ts +102 -0
- package/test/fixtures/golden/genesis-event-types.ts +102 -0
- package/test/fixtures/mini-server/generated-dao/global/genesis/gen/dao/Instrument.kt +13 -0
- package/test/fixtures/mini-server/generated-dao/global/genesis/gen/dao/Trade.kt +51 -0
- package/test/fixtures/mini-server/src/main/kotlin/com/example/Handlers.kt +16 -0
- package/test/fixtures/mini-server/src/main/kotlin/com/example/dto/Samples.kt +10 -0
- package/test/generate.test.ts +88 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# @genesislcap/event-type-codegen
|
|
2
|
+
|
|
3
|
+
Build-time TypeScript interfaces for Genesis event `DETAILS` payloads, discovered from Kotlin PAL event handlers without a running server.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
Enable via `genx.config.*` or the `genx` / `genesis` key in `package.json`:
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"genx": {
|
|
12
|
+
"eventTypes": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"serverModule": "../server/my-app",
|
|
15
|
+
"kotlinSources": [
|
|
16
|
+
"src/main/kotlin/**/dto/**/*.kt",
|
|
17
|
+
"src/main/genesis/scripts/**/*.kts"
|
|
18
|
+
],
|
|
19
|
+
"generatedDaoSources": [
|
|
20
|
+
"build/internal-modules/**/*-generated-dao/build/generated/sources/dao/global/genesis/gen/dao/**/*.kt"
|
|
21
|
+
],
|
|
22
|
+
"handlerScan": [
|
|
23
|
+
"src/main/kotlin/**/*.kt",
|
|
24
|
+
"src/main/genesis/scripts/**/*.kts"
|
|
25
|
+
],
|
|
26
|
+
"output": "src/generated/genesis-event-types.ts",
|
|
27
|
+
"runOnBuild": true
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
When `enabled` is false or the block is omitted, codegen is skipped.
|
|
34
|
+
|
|
35
|
+
`generatedDaoSources` globs are resolved against both the app module (`serverModule`) and its parent Gradle `server/` directory (where dictionary-cache DAOs usually live). Defaults cover common monorepo layouts after `./gradlew …` has generated DAO sources. Custom `data class` DTOs always override a generated DAO with the same class name.
|
|
36
|
+
|
|
37
|
+
## CLI
|
|
38
|
+
|
|
39
|
+
From a client app directory:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
genx generate event-types
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`genx build` runs codegen first when `eventTypes.enabled` and `runOnBuild` (default `true` when enabled).
|
|
46
|
+
|
|
47
|
+
In the showcase server Gradle build, `generateDao` is `finalizedBy` `generateEventTypes`, which runs `genx generate event-types` in `react-client` when `genx` is available (after monorepo bootstrap). Disable with `-PenableEventTypeCodegen=false`.
|
|
48
|
+
|
|
49
|
+
## Limitations (v1)
|
|
50
|
+
|
|
51
|
+
- Discovery uses Kotlin source parsing, not the compiler or live JSON Schema.
|
|
52
|
+
- Only handlers with a resolvable DETAILS shape (custom DTO or generated table/index from `generatedDaoSources`) get `*Details` types and `EventDetailsMap` entries. Anything else is listed in a comment at the top of the generated file.
|
|
53
|
+
- Full table DAO handlers (e.g. `eventHandler<Trade>("TRADE_INSERT")`) and index handlers (e.g. `eventHandler<Trade.ById>("TRADE_DELETE")`) are mapped when generated DAO `.kt` sources are present under `generatedDaoSources`.
|
|
54
|
+
- Class-based handler sources named `*EventHandler.kt` under a `dto/` path are skipped. The `dto/**` glob is for input `data class`es only; those files are usually `SyncValidatingEventHandler` implementations and are not PAL `eventHandler { }` scripts. PAL handlers in `*-eventhandler.kts` (and other `handlerScan` paths) are still discovered.
|
|
55
|
+
- Generate DAO sources (Gradle) before client codegen in CI if the trees are not committed.
|
|
56
|
+
- Dictionary **ENUM** fields: string literal unions when `enum class` and/or companion `Field.Type.ENUM` `values = "…"` appear under `generatedDaoSources` (`gen/dao/**/*.kt`).
|
|
57
|
+
|
|
58
|
+
## Typed commits
|
|
59
|
+
|
|
60
|
+
- **`*Details` interfaces** — DETAILS payload from Kotlin DTOs.
|
|
61
|
+
- **`GenesisEvent`** (from `@genesislcap/foundation-comms`) — abstract base; subclass sets `MESSAGE_TYPE`.
|
|
62
|
+
- **Per-handler classes** — e.g. `EventAqsCounterpartyInsert`.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { commitGenesisEvent } from '@genesislcap/foundation-comms';
|
|
66
|
+
import { EventAqsCounterpartyInsert } from './generated/genesis-event-types';
|
|
67
|
+
|
|
68
|
+
await commitGenesisEvent(
|
|
69
|
+
connect,
|
|
70
|
+
new EventAqsCounterpartyInsert({ COUNTERPARTY_ID: 'x' }),
|
|
71
|
+
);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Migration
|
|
75
|
+
|
|
76
|
+
| App | Action |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| New genx template | Enable `eventTypes`, commit or gitignore generated output |
|
|
79
|
+
| Legacy | Add config, run `genx generate event-types`, adopt typed commits incrementally |
|
|
80
|
+
| No Kotlin DTOs | Leave disabled |
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EventTypesConfig, EventTypesResolvedConfig } from './types';
|
|
2
|
+
export declare const resolveEventTypesConfig: (clientRoot: string, config?: Partial<EventTypesConfig> & {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}, packageGenesis?: {
|
|
5
|
+
eventTypes?: EventTypesConfig;
|
|
6
|
+
}) => EventTypesResolvedConfig;
|
|
7
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AA6C1E,eAAO,MAAM,uBAAuB,GAClC,YAAY,MAAM,EAClB,SAAS,OAAO,CAAC,gBAAgB,CAAC,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EAC1D,iBAAiB;IAAE,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAAE,KACjD,wBAcF,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEventTypesConfig = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const DEFAULT_KOTLIN_SOURCES = [
|
|
7
|
+
'src/main/kotlin/**/dto/**/*.kt',
|
|
8
|
+
'src/main/genesis/scripts/**/*.kts',
|
|
9
|
+
];
|
|
10
|
+
const DEFAULT_HANDLER_SCAN = ['src/main/kotlin/**/*.kt', 'src/main/genesis/scripts/**/*.kts'];
|
|
11
|
+
/**
|
|
12
|
+
* Relative to the parent of `serverModule` (the Gradle `server/` tree).
|
|
13
|
+
* Covers dictionary-cache and genesis-home layouts after `./gradlew …` generateDao.
|
|
14
|
+
*/
|
|
15
|
+
const DEFAULT_GENERATED_DAO_SOURCES = [
|
|
16
|
+
'build/internal-modules/**/*-generated-dao/build/generated/sources/dao/global/genesis/gen/dao/**/*.kt',
|
|
17
|
+
'**/build/genesis-home/generated/**/gen/dao/**/*.kt',
|
|
18
|
+
];
|
|
19
|
+
const DEFAULT_OUTPUT = 'src/generated/genesis-event-types.ts';
|
|
20
|
+
const discoverServerModule = (clientRoot) => {
|
|
21
|
+
const serverDir = (0, node_path_1.resolve)(clientRoot, '../server');
|
|
22
|
+
if (!(0, node_fs_1.existsSync)(serverDir)) {
|
|
23
|
+
return '../server';
|
|
24
|
+
}
|
|
25
|
+
const children = (0, node_fs_1.readdirSync)(serverDir)
|
|
26
|
+
.map((name) => (0, node_path_1.join)(serverDir, name))
|
|
27
|
+
.filter((path) => {
|
|
28
|
+
try {
|
|
29
|
+
return (0, node_fs_1.statSync)(path).isDirectory();
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.filter((path) => (0, node_fs_1.existsSync)((0, node_path_1.join)(path, 'src', 'main', 'kotlin')));
|
|
36
|
+
if (children.length === 1) {
|
|
37
|
+
const relative = (0, node_path_1.join)('..', 'server', children[0].split(/[/\\]/).pop());
|
|
38
|
+
return relative.replace(/\\/g, '/');
|
|
39
|
+
}
|
|
40
|
+
return '../server';
|
|
41
|
+
};
|
|
42
|
+
const resolveEventTypesConfig = (clientRoot, config, packageGenesis) => {
|
|
43
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
44
|
+
const fromGenesis = (_a = packageGenesis === null || packageGenesis === void 0 ? void 0 : packageGenesis.eventTypes) !== null && _a !== void 0 ? _a : {};
|
|
45
|
+
const merged = Object.assign(Object.assign({}, fromGenesis), config);
|
|
46
|
+
const enabled = merged.enabled === true;
|
|
47
|
+
return {
|
|
48
|
+
enabled,
|
|
49
|
+
serverModule: (_b = merged.serverModule) !== null && _b !== void 0 ? _b : discoverServerModule(clientRoot),
|
|
50
|
+
kotlinSources: (_c = merged.kotlinSources) !== null && _c !== void 0 ? _c : DEFAULT_KOTLIN_SOURCES,
|
|
51
|
+
generatedDaoSources: (_d = merged.generatedDaoSources) !== null && _d !== void 0 ? _d : DEFAULT_GENERATED_DAO_SOURCES,
|
|
52
|
+
handlerScan: (_e = merged.handlerScan) !== null && _e !== void 0 ? _e : DEFAULT_HANDLER_SCAN,
|
|
53
|
+
output: (_f = merged.output) !== null && _f !== void 0 ? _f : DEFAULT_OUTPUT,
|
|
54
|
+
runOnBuild: (_g = merged.runOnBuild) !== null && _g !== void 0 ? _g : true,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.resolveEventTypesConfig = resolveEventTypesConfig;
|
|
58
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,qCAA4D;AAC5D,yCAA0C;AAI1C,MAAM,sBAAsB,GAAG;IAC7B,gCAAgC;IAChC,m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AAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEK,MAAM,uBAAuB,GAAG,CACrC,UAAkB,EAClB,MAA0D,EAC1D,cAAkD,EACxB,EAAE;;IAC5B,MAAM,WAAW,GAAG,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,UAAU,mCAAI,EAAE,CAAC;IACrD,MAAM,MAAM,mCAAQ,WAAW,GAAK,MAAM,CAAE,CAAC;IAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;IAExC,OAAO;QACL,OAAO;QACP,YAAY,EAAE,MAAA,MAAM,CAAC,YAAY,mCAAI,oBAAoB,CAAC,UAAU,CAAC;QACrE,aAAa,EAAE,MAAA,MAAM,CAAC,aAAa,mCAAI,sBAAsB;QAC7D,mBAAmB,EAAE,MAAA,MAAM,CAAC,mBAAmB,mCAAI,6BAA6B;QAChF,WAAW,EAAE,MAAA,MAAM,CAAC,WAAW,mCAAI,oBAAoB;QACvD,MAAM,EAAE,MAAA,MAAM,CAAC,MAAM,mCAAI,cAAc;QACvC,UAAU,EAAE,MAAA,MAAM,CAAC,UAAU,mCAAI,IAAI;KACtC,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,uBAAuB,2BAkBlC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EventTypesResolvedConfig, GenerateResult } from './types';
|
|
2
|
+
export type GenerateEventTypesOptions = {
|
|
3
|
+
clientRoot: string;
|
|
4
|
+
config?: EventTypesResolvedConfig;
|
|
5
|
+
packageGenesis?: {
|
|
6
|
+
eventTypes?: unknown;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare function generateEventTypes(options: GenerateEventTypesOptions): Promise<GenerateResult | null>;
|
|
10
|
+
export * from './types';
|
|
11
|
+
export { resolveEventTypesConfig } from './config';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,wBAAwB,EAAE,cAAc,EAAa,MAAM,SAAS,CAAC;AA0CnF,MAAM,MAAM,yBAAyB,GAAG;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,cAAc,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3C,CAAC;AAEF,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAsDhC;AAED,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveEventTypesConfig = void 0;
|
|
4
|
+
exports.generateEventTypes = generateEventTypes;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const consola_1 = require("consola");
|
|
10
|
+
const config_1 = require("./config");
|
|
11
|
+
const parse_dao_1 = require("./parse-dao");
|
|
12
|
+
const parse_enums_1 = require("./parse-enums");
|
|
13
|
+
const parse_kotlin_1 = require("./parse-kotlin");
|
|
14
|
+
const render_1 = require("./render");
|
|
15
|
+
const isDtoScanPath = (filePath) => filePath.replace(/\\/g, '/').includes('/dto/');
|
|
16
|
+
const isExcludedHandlerFile = (filePath) => {
|
|
17
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
18
|
+
return isDtoScanPath(normalized) && normalized.endsWith('EventHandler.kt');
|
|
19
|
+
};
|
|
20
|
+
const collectFiles = (root, patterns, options) => {
|
|
21
|
+
const files = new Set();
|
|
22
|
+
for (const pattern of patterns) {
|
|
23
|
+
const matches = (0, node_fs_1.globSync)(pattern, {
|
|
24
|
+
cwd: root,
|
|
25
|
+
exclude: (name) => {
|
|
26
|
+
if (name === 'node_modules')
|
|
27
|
+
return true;
|
|
28
|
+
if (!(options === null || options === void 0 ? void 0 : options.includeBuildDirs) && name === 'build')
|
|
29
|
+
return true;
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
for (const match of matches) {
|
|
34
|
+
files.add((0, node_path_1.join)(root, match));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return [...files];
|
|
38
|
+
};
|
|
39
|
+
const mergeTypeMaps = (primary, secondary) => {
|
|
40
|
+
const merged = new Map(secondary);
|
|
41
|
+
for (const [name, dto] of primary) {
|
|
42
|
+
merged.set(name, dto);
|
|
43
|
+
}
|
|
44
|
+
return merged;
|
|
45
|
+
};
|
|
46
|
+
function generateEventTypes(options) {
|
|
47
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
var _a;
|
|
49
|
+
const resolved = (_a = options.config) !== null && _a !== void 0 ? _a : (0, config_1.resolveEventTypesConfig)(options.clientRoot, undefined, options.packageGenesis);
|
|
50
|
+
if (!resolved.enabled) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const serverRoot = (0, node_path_1.resolve)(options.clientRoot, resolved.serverModule);
|
|
54
|
+
if (!(0, node_fs_1.existsSync)(serverRoot)) {
|
|
55
|
+
throw new Error(`eventTypes: server module not found at ${serverRoot}`);
|
|
56
|
+
}
|
|
57
|
+
// Gradle `server/` tree — parent of the app module (e.g. …/server/showcase-app → …/server)
|
|
58
|
+
const serverWorkspaceRoot = (0, node_path_1.resolve)(serverRoot, '..');
|
|
59
|
+
const dtoFiles = collectFiles(serverRoot, resolved.kotlinSources).filter((file) => !isExcludedHandlerFile(file));
|
|
60
|
+
const handlerFiles = collectFiles(serverRoot, resolved.handlerScan).filter((file) => !isExcludedHandlerFile(file));
|
|
61
|
+
// Scan app module and Gradle server workspace (dictionary-cache lives under server/build/).
|
|
62
|
+
const daoFiles = [
|
|
63
|
+
...collectFiles(serverRoot, resolved.generatedDaoSources, { includeBuildDirs: true }),
|
|
64
|
+
...collectFiles(serverWorkspaceRoot, resolved.generatedDaoSources, {
|
|
65
|
+
includeBuildDirs: true,
|
|
66
|
+
}),
|
|
67
|
+
];
|
|
68
|
+
const uniqueDaoFiles = [...new Set(daoFiles)];
|
|
69
|
+
const customDtos = (0, parse_kotlin_1.parseDtosFromSources)(dtoFiles);
|
|
70
|
+
const generatedDaos = (0, parse_dao_1.parseGeneratedDaosFromSources)(uniqueDaoFiles);
|
|
71
|
+
const generatedEnums = (0, parse_enums_1.parseGeneratedEnumsFromSources)(uniqueDaoFiles);
|
|
72
|
+
const dtos = mergeTypeMaps(customDtos, generatedDaos);
|
|
73
|
+
const { mapped, unmapped } = (0, parse_kotlin_1.parseHandlersFromSources)(handlerFiles, dtos);
|
|
74
|
+
const outputPath = (0, node_path_1.resolve)(options.clientRoot, resolved.output);
|
|
75
|
+
const contents = (0, render_1.renderEventTypesFile)(mapped, unmapped, dtos, generatedEnums);
|
|
76
|
+
yield (0, promises_1.mkdir)((0, node_path_1.dirname)(outputPath), { recursive: true });
|
|
77
|
+
yield (0, promises_1.writeFile)(outputPath, contents, 'utf8');
|
|
78
|
+
consola_1.consola.info(`eventTypes: wrote ${outputPath} (${mapped.length} events, ${customDtos.size} DTOs, ${generatedDaos.size} generated DAOs)`);
|
|
79
|
+
return {
|
|
80
|
+
outputPath,
|
|
81
|
+
eventCount: mapped.length,
|
|
82
|
+
dtoCount: dtos.size,
|
|
83
|
+
unmappedCount: unmapped.length,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
88
|
+
var config_2 = require("./config");
|
|
89
|
+
Object.defineProperty(exports, "resolveEventTypesConfig", { enumerable: true, get: function () { return config_2.resolveEventTypesConfig; } });
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA0DA,gDAwDC;;AAlHD,qCAA+C;AAC/C,+CAAoD;AACpD,yCAAmD;AACnD,qCAAkC;AAElC,qCAAmD;AACnD,2CAA4D;AAC5D,+CAA+D;AAC/D,iDAAgF;AAChF,qCAAgD;AAGhD,MAAM,aAAa,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAE3F,MAAM,qBAAqB,GAAG,CAAC,QAAgB,EAAE,EAAE;IACjD,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,aAAa,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,CACnB,IAAY,EACZ,QAAkB,EAClB,OAAwC,EACxC,EAAE;IACF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,IAAA,kBAAQ,EAAC,OAAO,EAAE;YAChC,GAAG,EAAE,IAAI;YACT,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChB,IAAI,IAAI,KAAK,cAAc;oBAAE,OAAO,IAAI,CAAC;gBACzC,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAA,IAAI,IAAI,KAAK,OAAO;oBAAE,OAAO,IAAI,CAAC;gBAChE,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAA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ACtD,MAAM,IAAA,oBAAS,EAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE9C,iBAAO,CAAC,IAAI,CACV,qBAAqB,UAAU,KAAK,MAAM,CAAC,MAAM,YAAY,UAAU,CAAC,IAAI,UAAU,aAAa,CAAC,IAAI,kBAAkB,CAC3H,CAAC;QAEF,OAAO;YACL,UAAU;YACV,UAAU,EAAE,MAAM,CAAC,MAAM;YACzB,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,aAAa,EAAE,QAAQ,CAAC,MAAM;SAC/B,CAAC;IACJ,CAAC;CAAA;AAED,kDAAwB;AACxB,mCAAmD;AAA1C,iHAAA,uBAAuB,OAAA"}
|
package/dist/naming.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Wire field name for a Kotlin property (DETAILS uses UPPER_SNAKE_CASE). */
|
|
2
|
+
export declare const kotlinPropertyToWireField: (propertyName: string) => string;
|
|
3
|
+
/** Generated interface name for a Kotlin DTO or handler input type. */
|
|
4
|
+
export declare const dtoToDetailsInterfaceName: (dtoName: string) => string;
|
|
5
|
+
/** e.g. `Trade.ById` → `TradeByIdDetails`, `FooInput` → `FooInputDetails` */
|
|
6
|
+
export declare const handlerInputToDetailsInterfaceName: (inputType: string) => string;
|
|
7
|
+
/** Per-event class carrying MESSAGE_TYPE and DETAILS (one per PAL handler). */
|
|
8
|
+
export declare const eventNameToEventClassName: (eventName: string) => string;
|
|
9
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,GAAI,cAAc,MAAM,KAAG,MACrC,CAAC;AAE7B,uEAAuE;AACvE,eAAO,MAAM,yBAAyB,GAAI,SAAS,MAAM,KAAG,MACC,CAAC;AAE9D,6EAA6E;AAC7E,eAAO,MAAM,kCAAkC,GAAI,WAAW,MAAM,KAAG,MAMtE,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,yBAAyB,GAAI,WAAW,MAAM,KAAG,MAG7D,CAAC"}
|
package/dist/naming.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eventNameToEventClassName = exports.handlerInputToDetailsInterfaceName = exports.dtoToDetailsInterfaceName = exports.kotlinPropertyToWireField = void 0;
|
|
4
|
+
const change_case_1 = require("change-case");
|
|
5
|
+
/** Wire field name for a Kotlin property (DETAILS uses UPPER_SNAKE_CASE). */
|
|
6
|
+
const kotlinPropertyToWireField = (propertyName) => (0, change_case_1.constantCase)(propertyName);
|
|
7
|
+
exports.kotlinPropertyToWireField = kotlinPropertyToWireField;
|
|
8
|
+
/** Generated interface name for a Kotlin DTO or handler input type. */
|
|
9
|
+
const dtoToDetailsInterfaceName = (dtoName) => dtoName.endsWith('Details') ? dtoName : `${dtoName}Details`;
|
|
10
|
+
exports.dtoToDetailsInterfaceName = dtoToDetailsInterfaceName;
|
|
11
|
+
/** e.g. `Trade.ById` → `TradeByIdDetails`, `FooInput` → `FooInputDetails` */
|
|
12
|
+
const handlerInputToDetailsInterfaceName = (inputType) => {
|
|
13
|
+
const indexMatch = inputType.match(/^(\w+)\.(By\w+)$/);
|
|
14
|
+
if (indexMatch) {
|
|
15
|
+
return `${indexMatch[1]}${indexMatch[2]}Details`;
|
|
16
|
+
}
|
|
17
|
+
return (0, exports.dtoToDetailsInterfaceName)(inputType);
|
|
18
|
+
};
|
|
19
|
+
exports.handlerInputToDetailsInterfaceName = handlerInputToDetailsInterfaceName;
|
|
20
|
+
/** Per-event class carrying MESSAGE_TYPE and DETAILS (one per PAL handler). */
|
|
21
|
+
const eventNameToEventClassName = (eventName) => {
|
|
22
|
+
const base = eventName.startsWith('EVENT_') ? eventName.slice('EVENT_'.length) : eventName;
|
|
23
|
+
return `Event${(0, change_case_1.pascalCase)(base)}`;
|
|
24
|
+
};
|
|
25
|
+
exports.eventNameToEventClassName = eventNameToEventClassName;
|
|
26
|
+
//# sourceMappingURL=naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.js","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":";;;AAAA,6CAAuD;AAEvD,6EAA6E;AACtE,MAAM,yBAAyB,GAAG,CAAC,YAAoB,EAAU,EAAE,CACxE,IAAA,0BAAY,EAAC,YAAY,CAAC,CAAC;AADhB,QAAA,yBAAyB,6BACT;AAE7B,uEAAuE;AAChE,MAAM,yBAAyB,GAAG,CAAC,OAAe,EAAU,EAAE,CACnE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,SAAS,CAAC;AADjD,QAAA,yBAAyB,6BACwB;AAE9D,6EAA6E;AACtE,MAAM,kCAAkC,GAAG,CAAC,SAAiB,EAAU,EAAE;IAC9E,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACvD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC;IACD,OAAO,IAAA,iCAAyB,EAAC,SAAS,CAAC,CAAC;AAC9C,CAAC,CAAC;AANW,QAAA,kCAAkC,sCAM7C;AAEF,+EAA+E;AACxE,MAAM,yBAAyB,GAAG,CAAC,SAAiB,EAAU,EAAE;IACrE,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3F,OAAO,QAAQ,IAAA,wBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;AACpC,CAAC,CAAC;AAHW,QAAA,yBAAyB,6BAGpC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { KotlinDto } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Generated Genesis DAO entities use a primary constructor with annotated
|
|
4
|
+
* `public var` parameters (and sometimes bare params for sequenced PKs).
|
|
5
|
+
* Only files directly under `.../gen/dao/*.kt` are entity classes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isGeneratedDaoEntityFile: (filePath: string) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Nested `data class By*` index types inside generated entity Kotlin (e.g. Trade.ById).
|
|
10
|
+
*/
|
|
11
|
+
export declare const extractGeneratedDaoIndices: (content: string, filePath: string) => KotlinDto[];
|
|
12
|
+
/**
|
|
13
|
+
* Extract table entity classes from generated DAO Kotlin sources.
|
|
14
|
+
* Prefer entities that look like Genesis table DAOs (constructor + TableEntity).
|
|
15
|
+
*/
|
|
16
|
+
export declare const extractGeneratedDaoEntities: (content: string, filePath: string) => KotlinDto[];
|
|
17
|
+
export declare const parseGeneratedDaosFromSources: (files: string[]) => Map<string, KotlinDto>;
|
|
18
|
+
//# sourceMappingURL=parse-dao.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-dao.d.ts","sourceRoot":"","sources":["../src/parse-dao.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,SAAS,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GAAI,UAAU,MAAM,KAAG,OAG3D,CAAC;AAkEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,GAAI,SAAS,MAAM,EAAE,UAAU,MAAM,KAAG,SAAS,EAyCvF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,MAAM,EAAE,UAAU,MAAM,KAAG,SAAS,EAmCxF,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,OAAO,MAAM,EAAE,KAAG,GAAG,CAAC,MAAM,EAAE,SAAS,CAoBpF,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGeneratedDaosFromSources = exports.extractGeneratedDaoEntities = exports.extractGeneratedDaoIndices = exports.isGeneratedDaoEntityFile = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
/**
|
|
6
|
+
* Generated Genesis DAO entities use a primary constructor with annotated
|
|
7
|
+
* `public var` parameters (and sometimes bare params for sequenced PKs).
|
|
8
|
+
* Only files directly under `.../gen/dao/*.kt` are entity classes.
|
|
9
|
+
*/
|
|
10
|
+
const isGeneratedDaoEntityFile = (filePath) => {
|
|
11
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
12
|
+
return /\/gen\/dao\/[^/]+\.kt$/i.test(normalized);
|
|
13
|
+
};
|
|
14
|
+
exports.isGeneratedDaoEntityFile = isGeneratedDaoEntityFile;
|
|
15
|
+
const stripKotlinAnnotations = (segment) => segment
|
|
16
|
+
.replace(/@[A-Za-z_][\w.]*(?:\s*<[^>]*>)?(?:\s*\([^)]*\))?/g, ' ')
|
|
17
|
+
.replace(/\s+/g, ' ')
|
|
18
|
+
.trim();
|
|
19
|
+
const splitTopLevelArgs = (body) => {
|
|
20
|
+
const parts = [];
|
|
21
|
+
let depth = 0;
|
|
22
|
+
let current = '';
|
|
23
|
+
for (const ch of body) {
|
|
24
|
+
if (ch === '(' || ch === '<' || ch === '[')
|
|
25
|
+
depth += 1;
|
|
26
|
+
if (ch === ')' || ch === '>' || ch === ']')
|
|
27
|
+
depth -= 1;
|
|
28
|
+
if (ch === ',' && depth === 0) {
|
|
29
|
+
parts.push(current.trim());
|
|
30
|
+
current = '';
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
current += ch;
|
|
34
|
+
}
|
|
35
|
+
if (current.trim())
|
|
36
|
+
parts.push(current.trim());
|
|
37
|
+
return parts;
|
|
38
|
+
};
|
|
39
|
+
const parseDaoConstructorProperty = (segment) => {
|
|
40
|
+
const cleaned = stripKotlinAnnotations(segment);
|
|
41
|
+
// Prefer property syntax: (public) var/val name: Type
|
|
42
|
+
const propertyMatch = cleaned.match(/^(?:public\s+)?(?:val|var)\s+(\w+)\s*:\s*([^=]+?)(?:\s*=\s*.+)?$/);
|
|
43
|
+
// Bare ctor param used for sequenced PKs: tradeId: String? = null
|
|
44
|
+
const bareMatch = propertyMatch !== null && propertyMatch !== void 0 ? propertyMatch : cleaned.match(/^(\w+)\s*:\s*([^=]+?)(?:\s*=\s*.+)?$/);
|
|
45
|
+
if (!bareMatch)
|
|
46
|
+
return null;
|
|
47
|
+
const name = bareMatch[1];
|
|
48
|
+
let kotlinType = bareMatch[2].trim();
|
|
49
|
+
const optional = kotlinType.endsWith('?') || cleaned.includes('=');
|
|
50
|
+
kotlinType = kotlinType.replace(/\?$/, '').trim();
|
|
51
|
+
return { name, kotlinType, optional };
|
|
52
|
+
};
|
|
53
|
+
const parseIndexDataClassProperty = (segment) => {
|
|
54
|
+
const cleaned = stripKotlinAnnotations(segment);
|
|
55
|
+
const match = cleaned.match(/^(?:public\s+)?(?:val|var)\s+(\w+)\s*:\s*([^=]+?)(?:\s*=\s*.+)?$/);
|
|
56
|
+
if (!match)
|
|
57
|
+
return null;
|
|
58
|
+
const name = match[1];
|
|
59
|
+
let kotlinType = match[2].trim();
|
|
60
|
+
const optional = kotlinType.endsWith('?') || cleaned.includes('=');
|
|
61
|
+
kotlinType = kotlinType.replace(/\?$/, '').trim();
|
|
62
|
+
return { name, kotlinType, optional };
|
|
63
|
+
};
|
|
64
|
+
const KOTLIN_FILE_EXTENSION = '.kt';
|
|
65
|
+
const entityNameFromDaoFile = (filePath) => {
|
|
66
|
+
const base = filePath.replace(/\\/g, '/').split('/').pop();
|
|
67
|
+
if (!(base === null || base === void 0 ? void 0 : base.endsWith(KOTLIN_FILE_EXTENSION)))
|
|
68
|
+
return null;
|
|
69
|
+
return base.slice(0, base.length - KOTLIN_FILE_EXTENSION.length);
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Nested `data class By*` index types inside generated entity Kotlin (e.g. Trade.ById).
|
|
73
|
+
*/
|
|
74
|
+
const extractGeneratedDaoIndices = (content, filePath) => {
|
|
75
|
+
const entityName = entityNameFromDaoFile(filePath);
|
|
76
|
+
if (!entityName)
|
|
77
|
+
return [];
|
|
78
|
+
const results = [];
|
|
79
|
+
const indexRegex = /(?:^|\n)\s*public\s+data\s+class\s+(By\w+)\s*\(/gm;
|
|
80
|
+
let match;
|
|
81
|
+
while ((match = indexRegex.exec(content)) !== null) {
|
|
82
|
+
const indexName = match[1];
|
|
83
|
+
const openParenIndex = match.index + match[0].length - 1;
|
|
84
|
+
let depth = 0;
|
|
85
|
+
let closeIndex = -1;
|
|
86
|
+
for (let i = openParenIndex; i < content.length; i += 1) {
|
|
87
|
+
const ch = content[i];
|
|
88
|
+
if (ch === '(')
|
|
89
|
+
depth += 1;
|
|
90
|
+
if (ch === ')') {
|
|
91
|
+
depth -= 1;
|
|
92
|
+
if (depth === 0) {
|
|
93
|
+
closeIndex = i;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (closeIndex === -1)
|
|
99
|
+
continue;
|
|
100
|
+
const body = content.slice(openParenIndex + 1, closeIndex);
|
|
101
|
+
const properties = splitTopLevelArgs(body)
|
|
102
|
+
.map(parseIndexDataClassProperty)
|
|
103
|
+
.filter((p) => p != null);
|
|
104
|
+
if (properties.length === 0)
|
|
105
|
+
continue;
|
|
106
|
+
results.push({
|
|
107
|
+
name: `${entityName}.${indexName}`,
|
|
108
|
+
properties,
|
|
109
|
+
filePath,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return results;
|
|
113
|
+
};
|
|
114
|
+
exports.extractGeneratedDaoIndices = extractGeneratedDaoIndices;
|
|
115
|
+
/**
|
|
116
|
+
* Extract table entity classes from generated DAO Kotlin sources.
|
|
117
|
+
* Prefer entities that look like Genesis table DAOs (constructor + TableEntity).
|
|
118
|
+
*/
|
|
119
|
+
const extractGeneratedDaoEntities = (content, filePath) => {
|
|
120
|
+
const results = [];
|
|
121
|
+
// Matches: public class Trade public constructor( ... ) :
|
|
122
|
+
const classRegex = /(?:^|\n)\s*(?:public\s+)?class\s+(\w+)\s+(?:public\s+)?constructor\s*\(/gm;
|
|
123
|
+
let match;
|
|
124
|
+
while ((match = classRegex.exec(content)) !== null) {
|
|
125
|
+
const name = match[1];
|
|
126
|
+
const openParenIndex = match.index + match[0].length - 1;
|
|
127
|
+
let depth = 0;
|
|
128
|
+
let closeIndex = -1;
|
|
129
|
+
for (let i = openParenIndex; i < content.length; i += 1) {
|
|
130
|
+
const ch = content[i];
|
|
131
|
+
if (ch === '(')
|
|
132
|
+
depth += 1;
|
|
133
|
+
if (ch === ')') {
|
|
134
|
+
depth -= 1;
|
|
135
|
+
if (depth === 0) {
|
|
136
|
+
closeIndex = i;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (closeIndex === -1)
|
|
142
|
+
continue;
|
|
143
|
+
const body = content.slice(openParenIndex + 1, closeIndex);
|
|
144
|
+
const properties = splitTopLevelArgs(body)
|
|
145
|
+
.map(parseDaoConstructorProperty)
|
|
146
|
+
.filter((p) => p != null);
|
|
147
|
+
if (properties.length > 0) {
|
|
148
|
+
results.push({ name, properties, filePath });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return results;
|
|
152
|
+
};
|
|
153
|
+
exports.extractGeneratedDaoEntities = extractGeneratedDaoEntities;
|
|
154
|
+
const parseGeneratedDaosFromSources = (files) => {
|
|
155
|
+
const daos = new Map();
|
|
156
|
+
for (const filePath of files) {
|
|
157
|
+
if (!(0, exports.isGeneratedDaoEntityFile)(filePath))
|
|
158
|
+
continue;
|
|
159
|
+
const rawContent = (0, node_fs_1.readFileSync)(filePath, 'utf8');
|
|
160
|
+
const content = rawContent.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '');
|
|
161
|
+
for (const entity of (0, exports.extractGeneratedDaoEntities)(content, filePath)) {
|
|
162
|
+
if (!daos.has(entity.name)) {
|
|
163
|
+
daos.set(entity.name, entity);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const index of (0, exports.extractGeneratedDaoIndices)(content, filePath)) {
|
|
167
|
+
if (!daos.has(index.name)) {
|
|
168
|
+
daos.set(index.name, index);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return daos;
|
|
173
|
+
};
|
|
174
|
+
exports.parseGeneratedDaosFromSources = parseGeneratedDaosFromSources;
|
|
175
|
+
//# sourceMappingURL=parse-dao.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-dao.js","sourceRoot":"","sources":["../src/parse-dao.ts"],"names":[],"mappings":";;;AAAA,qCAAuC;AAIvC;;;;GAIG;AACI,MAAM,wBAAwB,GAAG,CAAC,QAAgB,EAAW,EAAE;IACpE,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,yBAAyB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACpD,CAAC,CAAC;AAHW,QAAA,wBAAwB,4BAGnC;AAEF,MAAM,sBAAsB,GAAG,CAAC,OAAe,EAAU,EAAE,CACzD,OAAO;KACJ,OAAO,CAAC,mDAAmD,EAAE,GAAG,CAAC;KACjE,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;KACpB,IAAI,EAAE,CAAC;AAEZ,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAY,EAAE;IACnD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB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B,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,IAAA,kCAA0B,EAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;YAClE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AApBW,QAAA,6BAA6B,iCAoBxC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type KotlinEnumMap = Map<string, readonly string[]>;
|
|
2
|
+
/** Any generated DAO tree Kotlin (entities, enums, xref, etc.). */
|
|
3
|
+
export declare const isGeneratedDaoTreeFile: (filePath: string) => boolean;
|
|
4
|
+
/** `enum class Side { BUY, SELL }` in generated DAO sources. */
|
|
5
|
+
export declare const extractEnumClassesFromContent: (content: string) => KotlinEnumMap;
|
|
6
|
+
/**
|
|
7
|
+
* Companion `Field` metadata on generated entities, e.g.
|
|
8
|
+
* `values = "STANDARD PREMIUM TRIAL"` on `NonNullable<Tier>(Field(… type = Field.Type.ENUM …))`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const extractCompanionFieldEnumValues: (content: string) => KotlinEnumMap;
|
|
11
|
+
export declare const parseGeneratedEnumsFromSources: (files: string[]) => KotlinEnumMap;
|
|
12
|
+
export declare const kotlinEnumSimpleName: (kotlinType: string) => string;
|
|
13
|
+
export declare const kotlinEnumTypeToTs: (kotlinType: string, enums: KotlinEnumMap) => string | null;
|
|
14
|
+
/** Use generated enum type name when declared (paired with `renderEnumExports`). */
|
|
15
|
+
export declare const kotlinEnumTypeRef: (kotlinType: string, enums: KotlinEnumMap) => string | null;
|
|
16
|
+
//# sourceMappingURL=parse-enums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-enums.d.ts","sourceRoot":"","sources":["../src/parse-enums.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AAI3D,mEAAmE;AACnE,eAAO,MAAM,sBAAsB,GAAI,UAAU,MAAM,KAAG,OAGzD,CAAC;AASF,gEAAgE;AAChE,eAAO,MAAM,6BAA6B,GAAI,SAAS,MAAM,KAAG,aAc/D,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,GAAI,SAAS,MAAM,KAAG,aAyBjE,CAAC;AAUF,eAAO,MAAM,8BAA8B,GAAI,OAAO,MAAM,EAAE,KAAG,aAWhE,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,YAAY,MAAM,KAAG,MAGzD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,EAAE,OAAO,aAAa,KAAG,MAAM,GAAG,IAKtF,CAAC;AAEF,oFAAoF;AACpF,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,EAAE,OAAO,aAAa,KAAG,MAAM,GAAG,IAGrF,CAAC"}
|