feat(medusa,event-bus-local,event-bus-redis): Event Bus modules (#2599)

This commit is contained in:
Oliver Windall Juhl
2023-03-22 10:26:21 +01:00
committed by GitHub
parent 7408111d11
commit ef5ef9f5a2
114 changed files with 2423 additions and 1669 deletions
+4
View File
@@ -16,6 +16,9 @@
],
"author": "Medusa",
"license": "MIT",
"dependencies": {
"@medusajs/modules-sdk": "^0.0.1"
},
"devDependencies": {
"cross-env": "^5.2.1",
"typeorm": "^0.3.11",
@@ -24,6 +27,7 @@
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"build": "tsc --build",
"watch": "tsc --build --watch",
"test": "exit 0"
}
}
+4
View File
@@ -0,0 +1,4 @@
export * as CommonTypes from "./common"
export * as EventBusTypes from "./event-bus"
export * as TransactionBaseTypes from "./transaction-base"
@@ -0,0 +1,51 @@
import {
ExternalModuleDeclaration,
InternalModuleDeclaration
} from "@medusajs/modules-sdk"
import { LoggerOptions } from "typeorm"
type SessionOptions = {
name?: string
resave?: boolean
rolling?: boolean
saveUninitialized?: boolean
secret?: string
ttl?: number
}
export type ConfigModule = {
projectConfig: {
redis_url?: string
session_options?: SessionOptions
jwt_secret?: string
cookie_secret?: string
database_url?: string
database_type: string
database_database?: string
database_schema?: string
database_logging: LoggerOptions
database_extra?: Record<string, unknown> & {
ssl: { rejectUnauthorized: false }
}
store_cors?: string
admin_cors?: string
}
featureFlags: Record<string, boolean | string>
modules?: Record<
string,
| false
| string
| Partial<InternalModuleDeclaration | ExternalModuleDeclaration>
>
plugins: (
| {
resolve: string
options: Record<string, unknown>
}
| string
)[]
}
+1
View File
@@ -0,0 +1 @@
export * from "./config-module";
+25
View File
@@ -0,0 +1,25 @@
export type Subscriber<T = unknown> = (
data: T,
eventName: string
) => Promise<void>
export type SubscriberContext = {
subscriberId: string
}
export type SubscriberDescriptor = {
id: string
subscriber: Subscriber
}
export type EventHandler<T = unknown> = (
data: T,
eventName: string
) => Promise<void>
export type EmitData<T = unknown> = {
eventName: string
data: T
options?: Record<string, unknown>
}
@@ -0,0 +1,22 @@
import { EmitData, Subscriber, SubscriberContext } from "./common"
export interface IEventBusModuleService {
emit<T>(
eventName: string,
data: T,
options: Record<string, unknown>
): Promise<void>
emit<T>(data: EmitData<T>[]): Promise<void>
subscribe(
eventName: string | symbol,
subscriber: Subscriber,
context?: SubscriberContext
): this
unsubscribe(
eventName: string | symbol,
subscriber: Subscriber,
context?: SubscriberContext
): this
}
+17
View File
@@ -0,0 +1,17 @@
import { Subscriber, SubscriberContext } from "."
import { ITransactionBaseService } from "../transaction-base/transaction-base"
export interface IEventBusService extends ITransactionBaseService {
subscribe(
eventName: string | symbol,
subscriber: Subscriber,
context?: SubscriberContext
): this
unsubscribe(
eventName: string | symbol,
subscriber: Subscriber,
context?: SubscriberContext
): this
emit<T>(event: string, data: T, options?: unknown): Promise<unknown | void>
}
+4
View File
@@ -0,0 +1,4 @@
export * from "./common"
export * from "./event-bus"
export * from "./event-bus-module"
+4
View File
@@ -1 +1,5 @@
export * from "./bundles"
export * from "./common"
export * from "./event-bus"
export * from "./shared-context"
export * from "./transaction-base"
@@ -0,0 +1,2 @@
export * from "./transaction-base";
@@ -0,0 +1,5 @@
import { EntityManager } from "typeorm"
export interface ITransactionBaseService {
withTransaction(transactionManager?: EntityManager): this
}