@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.
Files changed (52) hide show
  1. package/README.md +80 -0
  2. package/dist/config.d.ts +7 -0
  3. package/dist/config.d.ts.map +1 -0
  4. package/dist/config.js +58 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/index.d.ts +12 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +90 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/naming.d.ts +9 -0
  11. package/dist/naming.d.ts.map +1 -0
  12. package/dist/naming.js +26 -0
  13. package/dist/naming.js.map +1 -0
  14. package/dist/parse-dao.d.ts +18 -0
  15. package/dist/parse-dao.d.ts.map +1 -0
  16. package/dist/parse-dao.js +175 -0
  17. package/dist/parse-dao.js.map +1 -0
  18. package/dist/parse-enums.d.ts +16 -0
  19. package/dist/parse-enums.d.ts.map +1 -0
  20. package/dist/parse-enums.js +98 -0
  21. package/dist/parse-enums.js.map +1 -0
  22. package/dist/parse-kotlin.d.ts +15 -0
  23. package/dist/parse-kotlin.d.ts.map +1 -0
  24. package/dist/parse-kotlin.js +190 -0
  25. package/dist/parse-kotlin.js.map +1 -0
  26. package/dist/render.d.ts +4 -0
  27. package/dist/render.d.ts.map +1 -0
  28. package/dist/render.js +89 -0
  29. package/dist/render.js.map +1 -0
  30. package/dist/types.d.ts +51 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/types.js +3 -0
  33. package/dist/types.js.map +1 -0
  34. package/license.txt +46 -0
  35. package/package.json +38 -0
  36. package/src/config.ts +67 -0
  37. package/src/index.ts +118 -0
  38. package/src/naming.ts +24 -0
  39. package/src/parse-dao.ts +186 -0
  40. package/src/parse-enums.ts +105 -0
  41. package/src/parse-kotlin.ts +216 -0
  42. package/src/render.ts +118 -0
  43. package/src/types.ts +56 -0
  44. package/test/fixtures/client-out/genesis-event-types.ts +102 -0
  45. package/test/fixtures/golden/genesis-event-types.ts +102 -0
  46. package/test/fixtures/mini-server/generated-dao/global/genesis/gen/dao/Instrument.kt +13 -0
  47. package/test/fixtures/mini-server/generated-dao/global/genesis/gen/dao/Trade.kt +51 -0
  48. package/test/fixtures/mini-server/src/main/kotlin/com/example/Handlers.kt +16 -0
  49. package/test/fixtures/mini-server/src/main/kotlin/com/example/dto/Samples.kt +10 -0
  50. package/test/generate.test.ts +88 -0
  51. package/tsconfig.json +12 -0
  52. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,88 @@
1
+ import { readFileSync, rmSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
3
+ import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
4
+
5
+ import { generateEventTypes } from '../src/index';
6
+
7
+ const fixtureRoot = resolve(__dirname, 'fixtures');
8
+ const serverModule = join(fixtureRoot, 'mini-server');
9
+ const goldenPath = join(fixtureRoot, 'golden', 'genesis-event-types.ts');
10
+
11
+ const suite = createLogicSuite('event-type-codegen');
12
+
13
+ suite('generates golden genesis-event-types.ts from fixture Kotlin module', async () => {
14
+ const clientRoot = join(fixtureRoot, 'client-out');
15
+ const output = 'genesis-event-types.ts';
16
+ const outputPath = join(clientRoot, output);
17
+
18
+ rmSync(clientRoot, { recursive: true, force: true });
19
+
20
+ const result = await generateEventTypes({
21
+ clientRoot,
22
+ config: {
23
+ enabled: true,
24
+ serverModule,
25
+ kotlinSources: ['src/main/kotlin/**/dto/**/*.kt'],
26
+ generatedDaoSources: ['generated-dao/**/*.kt'],
27
+ handlerScan: ['src/main/kotlin/**/*.kt'],
28
+ output,
29
+ runOnBuild: true,
30
+ },
31
+ });
32
+
33
+ assert.ok(result);
34
+ assert.equal(result?.eventCount, 6);
35
+
36
+ const actual = readFileSync(outputPath, 'utf8').trim();
37
+ const expected = readFileSync(goldenPath, 'utf8').trim();
38
+ assert.equal(actual, expected);
39
+ });
40
+
41
+ suite('maps handler name FOO to EVENT_FOO', async () => {
42
+ const actual = readFileSync(goldenPath, 'utf8');
43
+ assert.is(actual.includes('EVENT_FOO: FooInputDetails'), true);
44
+ });
45
+
46
+ suite('maps generated DAO Trade handler to EVENT_TRADE_INSERT', async () => {
47
+ const actual = readFileSync(goldenPath, 'utf8');
48
+ assert.is(actual.includes('EVENT_TRADE_INSERT: TradeDetails'), true);
49
+ assert.is(actual.includes('INSTRUMENT_ID: string'), true);
50
+ assert.is(
51
+ actual.includes("export class EventTradeInsert extends GenesisEvent<'EVENT_TRADE_INSERT'"),
52
+ true,
53
+ );
54
+ });
55
+
56
+ suite('emits GenesisEvent subclasses with message type', async () => {
57
+ const actual = readFileSync(goldenPath, 'utf8');
58
+ assert.is(actual.includes("export class EventFoo extends GenesisEvent<'EVENT_FOO'"), true);
59
+ assert.is(actual.includes("readonly MESSAGE_TYPE = 'EVENT_FOO' as const"), true);
60
+ });
61
+
62
+ suite('maps generated DAO Trade.ById handler to EVENT_TRADE_DELETE', async () => {
63
+ const actual = readFileSync(goldenPath, 'utf8');
64
+ assert.is(actual.includes('EVENT_TRADE_DELETE: TradeByIdDetails'), true);
65
+ assert.is(actual.includes('export interface TradeByIdDetails'), true);
66
+ assert.is(
67
+ actual.includes("export class EventTradeDelete extends GenesisEvent<'EVENT_TRADE_DELETE'"),
68
+ true,
69
+ );
70
+ });
71
+
72
+ suite('maps Instrument.ById index handler', async () => {
73
+ const actual = readFileSync(goldenPath, 'utf8');
74
+ assert.is(actual.includes('EVENT_DAO_HANDLER: InstrumentByIdDetails'), true);
75
+ });
76
+
77
+ suite('maps Trade SIDE enum to string union', async () => {
78
+ const actual = readFileSync(goldenPath, 'utf8');
79
+ assert.is(actual.includes('export const Side = {'), true);
80
+ assert.is(actual.includes('SIDE?: Side'), true);
81
+ });
82
+
83
+ suite('parses handlers with trailing named args (transactional)', async () => {
84
+ const actual = readFileSync(goldenPath, 'utf8');
85
+ assert.is(actual.includes('EVENT_TRADE_INSERT: TradeDetails'), true);
86
+ });
87
+
88
+ suite.run();
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declarationDir": "./dist",
5
+ "lib": ["ES2019"],
6
+ "module": "commonjs",
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "sourceMap": true
10
+ },
11
+ "include": ["src/**/*"]
12
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/config.ts","./src/index.ts","./src/naming.ts","./src/parse-dao.ts","./src/parse-enums.ts","./src/parse-kotlin.ts","./src/render.ts","./src/types.ts"],"version":"5.9.2"}