@hexaijs/plugin-contracts-generator 0.2.0 → 0.2.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.
@@ -10,7 +10,7 @@ interface MessageClass<T = any> {
10
10
  getSchemaVersion(): Version;
11
11
  getType(): string;
12
12
  from(rawPayload: Record<string, unknown>, header?: MessageHeaders): T;
13
- new (payload: any, headers?: any): T;
13
+ new (payload: any, options?: any): T;
14
14
  }
15
15
  declare class MessageRegistry {
16
16
  private readonly registry;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/message-registry.ts"],"names":[],"mappings":";AAmBO,IAAM,kBAAN,MAAsB;AAAA,EACR,QAAA,uBAAe,GAAA,EAA0B;AAAA,EAE1D,SAAS,YAAA,EAAkC;AACvC,IAAA,MAAM,IAAA,GAAO,aAAa,OAAA,EAAQ;AAClC,IAAA,MAAM,OAAA,GAAU,aAAa,gBAAA,EAAiB;AAC9C,IAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AAEjC,IAAA,IAAI,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA,EAAG;AACxB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,OAAO,IAAA,EAAM,OAAO,CAAC,CAAA,uBAAA,CAAyB,CAAA;AAAA,IACrE;AAEA,IAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAA,EAAK,YAAY,CAAA;AACnC,IAAA,OAAO,IAAA;AAAA,EACX;AAAA,EAEA,SAAA,CAAa,QAAwB,IAAA,EAAkC;AACnE,IAAA,MAAM,EAAE,IAAA,EAAM,aAAA,EAAc,GAAI,MAAA;AAChC,IAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,IAAA,EAAM,aAAa,CAAA;AACvC,IAAA,MAAM,YAAA,GAAe,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA;AAE1C,IAAA,IAAI,CAAC,YAAA,EAAc;AACf,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,OAAO,IAAA,EAAM,aAAa,CAAC,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACvE;AAEA,IAAA,OAAO,YAAA,CAAa,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA;AAAA,EACzC;AAAA,EAEA,GAAA,CAAI,MAAc,OAAA,EAA4B;AAC1C,IAAA,OAAO,KAAK,QAAA,CAAS,GAAA,CAAI,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAC,CAAA;AAAA,EACnD;AAAA,EAEA,IAAA,GAAe;AACX,IAAA,OAAO,KAAK,QAAA,CAAS,IAAA;AAAA,EACzB;AACJ;AAEA,SAAS,OAAA,CAAQ,MAAc,OAAA,EAA2B;AACtD,EAAA,OAAO,YAAY,MAAA,GAAY,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,GAAK,IAAA;AAC1D;AAEA,SAAS,MAAA,CAAO,MAAc,OAAA,EAA2B;AACrD,EAAA,OAAO,OAAA,KAAY,SAAY,CAAA,CAAA,EAAI,IAAI,OAAO,OAAO,CAAA,CAAA,CAAA,GAAM,IAAI,IAAI,CAAA,CAAA,CAAA;AACvE","file":"index.js","sourcesContent":["type Version = string | number | undefined;\n\nexport interface MessageHeaders {\n id: string;\n type: string;\n schemaVersion?: Version;\n createdAt: Date;\n [key: string]: unknown;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface MessageClass<T = any> {\n getSchemaVersion(): Version;\n getType(): string;\n from(rawPayload: Record<string, unknown>, header?: MessageHeaders): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (payload: any, headers?: any): T;\n}\n\nexport class MessageRegistry {\n private readonly registry = new Map<string, MessageClass>();\n\n register(messageClass: MessageClass): this {\n const type = messageClass.getType();\n const version = messageClass.getSchemaVersion();\n const key = makeKey(type, version);\n\n if (this.registry.has(key)) {\n throw new Error(`${format(type, version)} is already registered.`);\n }\n\n this.registry.set(key, messageClass);\n return this;\n }\n\n dehydrate<T>(header: MessageHeaders, body: Record<string, unknown>): T {\n const { type, schemaVersion } = header;\n const key = makeKey(type, schemaVersion);\n const messageClass = this.registry.get(key);\n\n if (!messageClass) {\n throw new Error(`${format(type, schemaVersion)} is not registered.`);\n }\n\n return messageClass.from(body, header) as T;\n }\n\n has(type: string, version?: Version): boolean {\n return this.registry.has(makeKey(type, version));\n }\n\n size(): number {\n return this.registry.size;\n }\n}\n\nfunction makeKey(type: string, version?: Version): string {\n return version !== undefined ? `${type}:${version}` : type;\n}\n\nfunction format(type: string, version?: Version): string {\n return version !== undefined ? `'${type}' (v${version})` : `'${type}'`;\n}\n"]}
1
+ {"version":3,"sources":["../../src/runtime/message-registry.ts"],"names":[],"mappings":";AAmBO,IAAM,kBAAN,MAAsB;AAAA,EACR,QAAA,uBAAe,GAAA,EAA0B;AAAA,EAE1D,SAAS,YAAA,EAAkC;AACvC,IAAA,MAAM,IAAA,GAAO,aAAa,OAAA,EAAQ;AAClC,IAAA,MAAM,OAAA,GAAU,aAAa,gBAAA,EAAiB;AAC9C,IAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAA;AAEjC,IAAA,IAAI,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA,EAAG;AACxB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,OAAO,IAAA,EAAM,OAAO,CAAC,CAAA,uBAAA,CAAyB,CAAA;AAAA,IACrE;AAEA,IAAA,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAA,EAAK,YAAY,CAAA;AACnC,IAAA,OAAO,IAAA;AAAA,EACX;AAAA,EAEA,SAAA,CAAa,QAAwB,IAAA,EAAkC;AACnE,IAAA,MAAM,EAAE,IAAA,EAAM,aAAA,EAAc,GAAI,MAAA;AAChC,IAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,IAAA,EAAM,aAAa,CAAA;AACvC,IAAA,MAAM,YAAA,GAAe,IAAA,CAAK,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA;AAE1C,IAAA,IAAI,CAAC,YAAA,EAAc;AACf,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,OAAO,IAAA,EAAM,aAAa,CAAC,CAAA,mBAAA,CAAqB,CAAA;AAAA,IACvE;AAEA,IAAA,OAAO,YAAA,CAAa,IAAA,CAAK,IAAA,EAAM,MAAM,CAAA;AAAA,EACzC;AAAA,EAEA,GAAA,CAAI,MAAc,OAAA,EAA4B;AAC1C,IAAA,OAAO,KAAK,QAAA,CAAS,GAAA,CAAI,OAAA,CAAQ,IAAA,EAAM,OAAO,CAAC,CAAA;AAAA,EACnD;AAAA,EAEA,IAAA,GAAe;AACX,IAAA,OAAO,KAAK,QAAA,CAAS,IAAA;AAAA,EACzB;AACJ;AAEA,SAAS,OAAA,CAAQ,MAAc,OAAA,EAA2B;AACtD,EAAA,OAAO,YAAY,MAAA,GAAY,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,GAAK,IAAA;AAC1D;AAEA,SAAS,MAAA,CAAO,MAAc,OAAA,EAA2B;AACrD,EAAA,OAAO,OAAA,KAAY,SAAY,CAAA,CAAA,EAAI,IAAI,OAAO,OAAO,CAAA,CAAA,CAAA,GAAM,IAAI,IAAI,CAAA,CAAA,CAAA;AACvE","file":"index.js","sourcesContent":["type Version = string | number | undefined;\n\nexport interface MessageHeaders {\n id: string;\n type: string;\n schemaVersion?: Version;\n createdAt: Date;\n [key: string]: unknown;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface MessageClass<T = any> {\n getSchemaVersion(): Version;\n getType(): string;\n from(rawPayload: Record<string, unknown>, header?: MessageHeaders): T;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (payload: any, options?: any): T;\n}\n\nexport class MessageRegistry {\n private readonly registry = new Map<string, MessageClass>();\n\n register(messageClass: MessageClass): this {\n const type = messageClass.getType();\n const version = messageClass.getSchemaVersion();\n const key = makeKey(type, version);\n\n if (this.registry.has(key)) {\n throw new Error(`${format(type, version)} is already registered.`);\n }\n\n this.registry.set(key, messageClass);\n return this;\n }\n\n dehydrate<T>(header: MessageHeaders, body: Record<string, unknown>): T {\n const { type, schemaVersion } = header;\n const key = makeKey(type, schemaVersion);\n const messageClass = this.registry.get(key);\n\n if (!messageClass) {\n throw new Error(`${format(type, schemaVersion)} is not registered.`);\n }\n\n return messageClass.from(body, header) as T;\n }\n\n has(type: string, version?: Version): boolean {\n return this.registry.has(makeKey(type, version));\n }\n\n size(): number {\n return this.registry.size;\n }\n}\n\nfunction makeKey(type: string, version?: Version): string {\n return version !== undefined ? `${type}:${version}` : type;\n}\n\nfunction format(type: string, version?: Version): string {\n return version !== undefined ? `'${type}' (v${version})` : `'${type}'`;\n}\n"]}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.0",
6
+ "version": "0.2.1",
7
7
  "type": "module",
8
8
  "description": "Collect domain events and commands from bounded contexts and generate frontend-compatible contracts package",
9
9
  "license": "MIT",
@@ -31,10 +31,6 @@
31
31
  "types": "./dist/index.d.ts",
32
32
  "import": "./dist/index.js"
33
33
  },
34
- "./decorators": {
35
- "types": "./dist/decorators/index.d.ts",
36
- "import": "./dist/decorators/index.js"
37
- },
38
34
  "./runtime": {
39
35
  "types": "./dist/runtime/index.d.ts",
40
36
  "import": "./dist/runtime/index.js"
@@ -49,9 +45,9 @@
49
45
  "build": "tsup"
50
46
  },
51
47
  "dependencies": {
48
+ "@hexaijs/contracts": "workspace:^",
52
49
  "glob": "^10.3.0",
53
- "minimatch": "^9.0.0",
54
- "reflect-metadata": "^0.2.2"
50
+ "minimatch": "^9.0.0"
55
51
  },
56
52
  "peerDependencies": {
57
53
  "@hexaijs/cli": "^0.2.0",
@@ -1,144 +0,0 @@
1
- /**
2
- * Decorators for marking Domain Events and Commands.
3
- * These decorators have no runtime effect - the Message Parser
4
- * statically analyzes source code to find and extract them.
5
- */
6
-
7
- interface PublicEventOptions {
8
- /**
9
- * Event version for versioned events
10
- * @example @PublicEvent({ version: 2 })
11
- */
12
- version?: number;
13
- /**
14
- * Business context this event belongs to
15
- * If not specified, inferred from package name
16
- * @example @PublicEvent({ context: 'lecture' })
17
- */
18
- context?: string;
19
- }
20
- interface PublicCommandOptions {
21
- /**
22
- * Business context this command belongs to
23
- * If not specified, inferred from package name
24
- * @example @PublicCommand({ context: 'auth' })
25
- */
26
- context?: string;
27
- /**
28
- * Explicit response type name for this command
29
- * If specified, the parser will look for this type in the same file
30
- * @example @PublicCommand({ response: 'CreateUserResult' })
31
- */
32
- response?: string;
33
- }
34
- interface PublicQueryOptions {
35
- /**
36
- * Business context this query belongs to
37
- * If not specified, inferred from package name
38
- * @example @PublicQuery({ context: 'catalog' })
39
- */
40
- context?: string;
41
- /**
42
- * Explicit response type name for this query
43
- * If specified, the parser will look for this type in the same file
44
- * @example @PublicQuery({ response: 'UserProfile' })
45
- */
46
- response?: string;
47
- }
48
- declare const PUBLIC_EVENT_METADATA: unique symbol;
49
- declare const PUBLIC_COMMAND_METADATA: unique symbol;
50
- declare const PUBLIC_QUERY_METADATA: unique symbol;
51
- /**
52
- * Marks a class as a Domain Event for extraction to public contracts
53
- *
54
- * @example
55
- * ```typescript
56
- * @PublicEvent()
57
- * export class UserRegistered extends Message {
58
- * constructor(
59
- * public readonly userId: string,
60
- * public readonly email: string,
61
- * ) {
62
- * super();
63
- * }
64
- * }
65
- * ```
66
- *
67
- * @example With options
68
- * ```typescript
69
- * @PublicEvent({ version: 2, context: 'auth' })
70
- * export class UserRegisteredV2 extends Message {
71
- * // ...
72
- * }
73
- * ```
74
- */
75
- declare function PublicEvent(options?: PublicEventOptions): ClassDecorator;
76
- /**
77
- * Marks a class as a Command for extraction to public contracts
78
- *
79
- * @example
80
- * ```typescript
81
- * @PublicCommand()
82
- * export class CreateUser extends Request<CreateUserResult> {
83
- * constructor(
84
- * public readonly email: string,
85
- * public readonly name: string,
86
- * ) {
87
- * super();
88
- * }
89
- * }
90
- * ```
91
- *
92
- * @example With context option
93
- * ```typescript
94
- * @PublicCommand({ context: 'auth' })
95
- * export class CreateUser extends Request<CreateUserResult> {
96
- * // ...
97
- * }
98
- * ```
99
- *
100
- * @example With explicit response type
101
- * ```typescript
102
- * @PublicCommand({ response: 'DialogueCreatedResult' })
103
- * export class BeginDialogueRequest extends Request<DialogueCreatedResult> {
104
- * // ...
105
- * }
106
- * export type DialogueCreatedResult = { dialogueId: string };
107
- * ```
108
- */
109
- declare function PublicCommand(options?: PublicCommandOptions): ClassDecorator;
110
- /**
111
- * Marks a class as a Query for extraction to public contracts
112
- *
113
- * @example
114
- * ```typescript
115
- * @PublicQuery()
116
- * export class GetUserProfile extends Request<UserProfile> {
117
- * constructor(
118
- * public readonly userId: string,
119
- * ) {
120
- * super();
121
- * }
122
- * }
123
- * ```
124
- *
125
- * @example With context option
126
- * ```typescript
127
- * @PublicQuery({ context: 'catalog' })
128
- * export class GetProductDetails extends Request<ProductDetails> {
129
- * // ...
130
- * }
131
- * ```
132
- *
133
- * @example With explicit response type
134
- * ```typescript
135
- * @PublicQuery({ response: 'UserProfileResult' })
136
- * export class GetUserProfile extends Request<UserProfileResult> {
137
- * // ...
138
- * }
139
- * export type UserProfileResult = { name: string; email: string };
140
- * ```
141
- */
142
- declare function PublicQuery(options?: PublicQueryOptions): ClassDecorator;
143
-
144
- export { PUBLIC_COMMAND_METADATA, PUBLIC_EVENT_METADATA, PUBLIC_QUERY_METADATA, PublicCommand, type PublicCommandOptions, PublicEvent, type PublicEventOptions, PublicQuery, type PublicQueryOptions };
@@ -1,28 +0,0 @@
1
- import 'reflect-metadata';
2
-
3
- // src/decorators/index.ts
4
- var PUBLIC_EVENT_METADATA = /* @__PURE__ */ Symbol("publicEvent");
5
- var PUBLIC_COMMAND_METADATA = /* @__PURE__ */ Symbol("publicCommand");
6
- var PUBLIC_QUERY_METADATA = /* @__PURE__ */ Symbol("publicQuery");
7
- function PublicEvent(options = {}) {
8
- return (target) => {
9
- Reflect.defineMetadata(PUBLIC_EVENT_METADATA, options, target);
10
- return target;
11
- };
12
- }
13
- function PublicCommand(options = {}) {
14
- return (target) => {
15
- Reflect.defineMetadata(PUBLIC_COMMAND_METADATA, options, target);
16
- return target;
17
- };
18
- }
19
- function PublicQuery(options = {}) {
20
- return (target) => {
21
- Reflect.defineMetadata(PUBLIC_QUERY_METADATA, options, target);
22
- return target;
23
- };
24
- }
25
-
26
- export { PUBLIC_COMMAND_METADATA, PUBLIC_EVENT_METADATA, PUBLIC_QUERY_METADATA, PublicCommand, PublicEvent, PublicQuery };
27
- //# sourceMappingURL=index.js.map
28
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAuDO,IAAM,qBAAA,0BAA+B,aAAa;AAClD,IAAM,uBAAA,0BAAiC,eAAe;AACtD,IAAM,qBAAA,0BAA+B,aAAa;AA0BlD,SAAS,WAAA,CAAY,OAAA,GAA8B,EAAC,EAAmB;AAC5E,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,OAAA,CAAQ,cAAA,CAAe,qBAAA,EAAuB,OAAA,EAAS,MAAM,CAAA;AAC7D,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;AAmCO,SAAS,aAAA,CAAc,OAAA,GAAgC,EAAC,EAAmB;AAChF,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,OAAA,CAAQ,cAAA,CAAe,uBAAA,EAAyB,OAAA,EAAS,MAAM,CAAA;AAC/D,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF;AAmCO,SAAS,WAAA,CAAY,OAAA,GAA8B,EAAC,EAAmB;AAC5E,EAAA,OAAO,CAAC,MAAA,KAAW;AACjB,IAAA,OAAA,CAAQ,cAAA,CAAe,qBAAA,EAAuB,OAAA,EAAS,MAAM,CAAA;AAC7D,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AACF","file":"index.js","sourcesContent":["/**\n * Decorators for marking Domain Events and Commands.\n * These decorators have no runtime effect - the Message Parser\n * statically analyzes source code to find and extract them.\n */\nimport \"reflect-metadata\";\n\nexport interface PublicEventOptions {\n /**\n * Event version for versioned events\n * @example @PublicEvent({ version: 2 })\n */\n version?: number;\n\n /**\n * Business context this event belongs to\n * If not specified, inferred from package name\n * @example @PublicEvent({ context: 'lecture' })\n */\n context?: string;\n}\n\nexport interface PublicCommandOptions {\n /**\n * Business context this command belongs to\n * If not specified, inferred from package name\n * @example @PublicCommand({ context: 'auth' })\n */\n context?: string;\n\n /**\n * Explicit response type name for this command\n * If specified, the parser will look for this type in the same file\n * @example @PublicCommand({ response: 'CreateUserResult' })\n */\n response?: string;\n}\n\n\nexport interface PublicQueryOptions {\n /**\n * Business context this query belongs to\n * If not specified, inferred from package name\n * @example @PublicQuery({ context: 'catalog' })\n */\n context?: string;\n\n /**\n * Explicit response type name for this query\n * If specified, the parser will look for this type in the same file\n * @example @PublicQuery({ response: 'UserProfile' })\n */\n response?: string;\n}\n\nexport const PUBLIC_EVENT_METADATA = Symbol('publicEvent');\nexport const PUBLIC_COMMAND_METADATA = Symbol('publicCommand');\nexport const PUBLIC_QUERY_METADATA = Symbol('publicQuery');\n\n/**\n * Marks a class as a Domain Event for extraction to public contracts\n *\n * @example\n * ```typescript\n * @PublicEvent()\n * export class UserRegistered extends Message {\n * constructor(\n * public readonly userId: string,\n * public readonly email: string,\n * ) {\n * super();\n * }\n * }\n * ```\n *\n * @example With options\n * ```typescript\n * @PublicEvent({ version: 2, context: 'auth' })\n * export class UserRegisteredV2 extends Message {\n * // ...\n * }\n * ```\n */\nexport function PublicEvent(options: PublicEventOptions = {}): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(PUBLIC_EVENT_METADATA, options, target);\n return target;\n };\n}\n\n/**\n * Marks a class as a Command for extraction to public contracts\n *\n * @example\n * ```typescript\n * @PublicCommand()\n * export class CreateUser extends Request<CreateUserResult> {\n * constructor(\n * public readonly email: string,\n * public readonly name: string,\n * ) {\n * super();\n * }\n * }\n * ```\n *\n * @example With context option\n * ```typescript\n * @PublicCommand({ context: 'auth' })\n * export class CreateUser extends Request<CreateUserResult> {\n * // ...\n * }\n * ```\n *\n * @example With explicit response type\n * ```typescript\n * @PublicCommand({ response: 'DialogueCreatedResult' })\n * export class BeginDialogueRequest extends Request<DialogueCreatedResult> {\n * // ...\n * }\n * export type DialogueCreatedResult = { dialogueId: string };\n * ```\n */\nexport function PublicCommand(options: PublicCommandOptions = {}): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(PUBLIC_COMMAND_METADATA, options, target);\n return target;\n };\n}\n\n\n/**\n * Marks a class as a Query for extraction to public contracts\n *\n * @example\n * ```typescript\n * @PublicQuery()\n * export class GetUserProfile extends Request<UserProfile> {\n * constructor(\n * public readonly userId: string,\n * ) {\n * super();\n * }\n * }\n * ```\n *\n * @example With context option\n * ```typescript\n * @PublicQuery({ context: 'catalog' })\n * export class GetProductDetails extends Request<ProductDetails> {\n * // ...\n * }\n * ```\n *\n * @example With explicit response type\n * ```typescript\n * @PublicQuery({ response: 'UserProfileResult' })\n * export class GetUserProfile extends Request<UserProfileResult> {\n * // ...\n * }\n * export type UserProfileResult = { name: string; email: string };\n * ```\n */\nexport function PublicQuery(options: PublicQueryOptions = {}): ClassDecorator {\n return (target) => {\n Reflect.defineMetadata(PUBLIC_QUERY_METADATA, options, target);\n return target;\n };\n}\n"]}