feat(index): Index module foundation (#9095)
**What** Index module foundation Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
co-authored by
Carlos R. L. Rodrigues
parent
3cfcd075ae
commit
58167b5dfa
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
EventBusTypes,
|
||||
IEventBusModuleService,
|
||||
Message,
|
||||
Subscriber,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export class EventBusServiceMock implements IEventBusModuleService {
|
||||
protected readonly subscribers_: Map<string | symbol, Set<Subscriber>> =
|
||||
new Map()
|
||||
|
||||
async emit<T>(
|
||||
messages: Message<T> | Message<T>[],
|
||||
options?: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const messages_ = Array.isArray(messages) ? messages : [messages]
|
||||
|
||||
for (const message of messages_) {
|
||||
const subscribers = this.subscribers_.get(message.name)
|
||||
|
||||
for (const subscriber of subscribers ?? []) {
|
||||
const { options, ...payload } = message
|
||||
await subscriber(payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscribe(event: string | symbol, subscriber: Subscriber): this {
|
||||
this.subscribers_.set(event, new Set([subscriber]))
|
||||
return this
|
||||
}
|
||||
|
||||
unsubscribe(
|
||||
event: string | symbol,
|
||||
subscriber: Subscriber,
|
||||
context?: EventBusTypes.SubscriberContext
|
||||
): this {
|
||||
return this
|
||||
}
|
||||
|
||||
releaseGroupedEvents(eventGroupId: string): Promise<void> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
clearGroupedEvents(eventGroupId: string): Promise<void> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./event-bus"
|
||||
export * from "./schema"
|
||||
@@ -0,0 +1,38 @@
|
||||
const { defineConfig, Modules } = require("@medusajs/utils")
|
||||
const { schema } = require("./schema")
|
||||
|
||||
export const dbName = "medusa-index-integration-2024"
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost:5432"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${dbName}`
|
||||
|
||||
const config = defineConfig({
|
||||
admin: {
|
||||
disable: true,
|
||||
},
|
||||
projectConfig: {
|
||||
databaseUrl: DB_URL,
|
||||
},
|
||||
})
|
||||
|
||||
Object.keys(config.modules).forEach((key) => {
|
||||
if ([Modules.EVENT_BUS].includes(key)) {
|
||||
return
|
||||
}
|
||||
|
||||
config.modules[key] = false
|
||||
})
|
||||
|
||||
config.modules[Modules.INDEX] = {
|
||||
resolve: "@medusajs/index",
|
||||
dependencies: [Modules.EVENT_BUS],
|
||||
options: {
|
||||
schema,
|
||||
},
|
||||
}
|
||||
|
||||
config.modules[Modules.PRODUCT] = true
|
||||
config.modules[Modules.PRICING] = true
|
||||
|
||||
export default config
|
||||
@@ -0,0 +1,28 @@
|
||||
export const schema = `
|
||||
type Product @Listeners(values: ["product.created", "product.updated", "product.deleted"]) {
|
||||
id: String
|
||||
title: String
|
||||
deep: InternalNested
|
||||
variants: [ProductVariant]
|
||||
}
|
||||
|
||||
type InternalNested {
|
||||
a: Int
|
||||
obj: InternalObject
|
||||
}
|
||||
|
||||
type InternalObject {
|
||||
b: Int
|
||||
}
|
||||
|
||||
type ProductVariant @Listeners(values: ["variant.created", "variant.updated", "variant.deleted"]) {
|
||||
id: String
|
||||
product_id: String
|
||||
sku: String
|
||||
prices: [Price]
|
||||
}
|
||||
|
||||
type Price @Listeners(values: ["price.created", "price.updated", "price.deleted"]) {
|
||||
amount: Int
|
||||
}
|
||||
`
|
||||
Reference in New Issue
Block a user