-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chore/utils-repository-base-composite-support' of githu…
…b.com:medusajs/medusa into chore/utils-repository-base-composite-support
- Loading branch information
Showing
37 changed files
with
538 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@medusajs/authentication": patch | ||
"@medusajs/pricing": patch | ||
"@medusajs/utils": patch | ||
--- | ||
|
||
chore(utils): Update base repository to infer primary keys and support composite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@medusajs/modules-sdk": patch | ||
"@medusajs/types": patch | ||
--- | ||
|
||
feat: add Payment module package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/dist | ||
node_modules | ||
.DS_store | ||
.env* | ||
.env | ||
*.sql |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Payment Module | ||
|
||
A Payment is the result of a series of financial transactions performed as part of collecting a payment of a purchase. The Payment holds information about the payment provider as well as the state of it. You can associate a Payment with a Cart, an Order, an OrderEdit, or any other resource you’d like to have your customers pay for. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("Noop test", () => { | ||
it("noop check", async () => { | ||
expect(true).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if (typeof process.env.DB_TEMP_NAME === "undefined") { | ||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1") | ||
process.env.DB_TEMP_NAME = `medusa-payment-integration-${tempName}` | ||
} | ||
|
||
process.env.MEDUSA_PAYMENT_DB_SCHEMA = "public" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { JestUtils } from "medusa-test-utils" | ||
|
||
JestUtils.afterAllHookDropDatabase() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ModuleServiceInitializeOptions } from "@medusajs/types" | ||
|
||
export const databaseOptions: ModuleServiceInitializeOptions["database"] = { | ||
schema: "public", | ||
clientUrl: "medusa-payment-test", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { TestDatabaseUtils } from "medusa-test-utils" | ||
|
||
import * as PaymentModules from "@models" | ||
|
||
const pathToMigrations = "../../src/migrations" | ||
const mikroOrmEntities = PaymentModules as unknown as any[] | ||
|
||
export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper( | ||
mikroOrmEntities, | ||
pathToMigrations | ||
) | ||
|
||
export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig( | ||
mikroOrmEntities, | ||
pathToMigrations | ||
) | ||
|
||
export const DB_URL = TestDatabaseUtils.getDatabaseURL() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./config" | ||
export * from "./database" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
moduleNameMapper: { | ||
"^@models": "<rootDir>/src/models", | ||
"^@services": "<rootDir>/src/services", | ||
"^@repositories": "<rootDir>/src/repositories", | ||
}, | ||
transform: { | ||
"^.+\\.[jt]s?$": [ | ||
"ts-jest", | ||
{ | ||
tsConfig: "tsconfig.spec.json", | ||
isolatedModules: true, | ||
}, | ||
], | ||
}, | ||
testEnvironment: `node`, | ||
moduleFileExtensions: [`js`, `ts`], | ||
modulePathIgnorePatterns: ["dist/"], | ||
setupFiles: ["<rootDir>/integration-tests/setup-env.js"], | ||
setupFilesAfterEnv: ["<rootDir>/integration-tests/setup.js"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as entities from "./src/models" | ||
|
||
module.exports = { | ||
entities: Object.values(entities), | ||
schema: "public", | ||
clientUrl: "postgres://postgres@localhost/medusa-payment", | ||
type: "postgresql", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"name": "@medusajs/payment", | ||
"version": "0.0.1", | ||
"description": "Medusa Payment module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"bin": { | ||
"medusa-payment-seed": "dist/scripts/bin/run-seed.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/medusajs/medusa", | ||
"directory": "packages/payment" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"author": "Medusa", | ||
"license": "MIT", | ||
"scripts": { | ||
"watch": "tsc --build --watch", | ||
"watch:test": "tsc --build tsconfig.spec.json --watch", | ||
"prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json", | ||
"build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json", | ||
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts", | ||
"test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts", | ||
"migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate", | ||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial", | ||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create", | ||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up", | ||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear" | ||
}, | ||
"devDependencies": { | ||
"@mikro-orm/cli": "5.9.7", | ||
"cross-env": "^5.2.1", | ||
"jest": "^29.6.3", | ||
"medusa-test-utils": "^1.1.40", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^29.1.1", | ||
"ts-node": "^10.9.1", | ||
"tsc-alias": "^1.8.6", | ||
"typescript": "^5.1.6" | ||
}, | ||
"dependencies": { | ||
"@medusajs/modules-sdk": "^1.12.5", | ||
"@medusajs/types": "^1.11.9", | ||
"@medusajs/utils": "^1.11.2", | ||
"@mikro-orm/core": "5.9.7", | ||
"@mikro-orm/migrations": "5.9.7", | ||
"@mikro-orm/postgresql": "5.9.7", | ||
"awilix": "^8.0.0", | ||
"dotenv": "^16.1.4", | ||
"knex": "2.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { moduleDefinition } from "./module-definition" | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import { ModulesSdkUtils } from "@medusajs/utils" | ||
|
||
import * as PaymentModels from "@models" | ||
|
||
export default moduleDefinition | ||
|
||
const migrationScriptOptions = { | ||
moduleName: Modules.PAYMENT, | ||
models: PaymentModels, | ||
pathToMigrations: __dirname + "/migrations", | ||
} | ||
|
||
export const runMigrations = ModulesSdkUtils.buildMigrationScript( | ||
migrationScriptOptions | ||
) | ||
export const revertMigration = ModulesSdkUtils.buildRevertMigrationScript( | ||
migrationScriptOptions | ||
) | ||
|
||
export * from "./initialize" | ||
export * from "./loaders" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
ExternalModuleDeclaration, | ||
InternalModuleDeclaration, | ||
MedusaModule, | ||
MODULE_PACKAGE_NAMES, | ||
Modules, | ||
} from "@medusajs/modules-sdk" | ||
import { IPaymentModuleService, ModulesSdkTypes } from "@medusajs/types" | ||
import { moduleDefinition } from "../module-definition" | ||
import { InitializeModuleInjectableDependencies } from "../types" | ||
|
||
export const initialize = async ( | ||
options?: ModulesSdkTypes.ModuleBootstrapDeclaration, | ||
injectedDependencies?: InitializeModuleInjectableDependencies | ||
): Promise<IPaymentModuleService> => { | ||
const loaded = await MedusaModule.bootstrap<IPaymentModuleService>({ | ||
moduleKey: Modules.PAYMENT, | ||
defaultPath: MODULE_PACKAGE_NAMES[Modules.PAYMENT], | ||
declaration: options as | ||
| InternalModuleDeclaration | ||
| ExternalModuleDeclaration, | ||
injectedDependencies, | ||
moduleExports: moduleDefinition, | ||
}) | ||
|
||
return loaded[Modules.PAYMENT] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import { ModuleJoinerConfig } from "@medusajs/types" | ||
import { MapToConfig } from "@medusajs/utils" | ||
import { Payment } from "@models" | ||
|
||
export const LinkableKeys = { | ||
payment_id: Payment.name, | ||
} | ||
|
||
const entityLinkableKeysMap: MapToConfig = {} | ||
Object.entries(LinkableKeys).forEach(([key, value]) => { | ||
entityLinkableKeysMap[value] ??= [] | ||
entityLinkableKeysMap[value].push({ | ||
mapTo: key, | ||
valueFrom: key.split("_").pop()!, | ||
}) | ||
}) | ||
|
||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap | ||
|
||
export const joinerConfig: ModuleJoinerConfig = { | ||
serviceName: Modules.PAYMENT, | ||
primaryKeys: ["id"], | ||
linkableKeys: LinkableKeys, | ||
alias: { | ||
name: ["payment", "payments"], | ||
args: { | ||
entity: Payment.name, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
InternalModuleDeclaration, | ||
LoaderOptions, | ||
Modules, | ||
} from "@medusajs/modules-sdk" | ||
import { ModulesSdkTypes } from "@medusajs/types" | ||
import { ModulesSdkUtils } from "@medusajs/utils" | ||
import { EntitySchema } from "@mikro-orm/core" | ||
import * as PaymentModels from "../models" | ||
|
||
export default async ( | ||
{ | ||
options, | ||
container, | ||
logger, | ||
}: LoaderOptions< | ||
| ModulesSdkTypes.ModuleServiceInitializeOptions | ||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ||
>, | ||
moduleDeclaration?: InternalModuleDeclaration | ||
): Promise<void> => { | ||
const entities = Object.values(PaymentModels) as unknown as EntitySchema[] | ||
const pathToMigrations = __dirname + "/../migrations" | ||
|
||
await ModulesSdkUtils.mikroOrmConnectionLoader({ | ||
moduleName: Modules.PAYMENT, | ||
entities, | ||
container, | ||
options, | ||
moduleDeclaration, | ||
logger, | ||
pathToMigrations, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { LoaderOptions } from "@medusajs/modules-sdk" | ||
import { ModulesSdkTypes } from "@medusajs/types" | ||
import { loadCustomRepositories } from "@medusajs/utils" | ||
import { asClass } from "awilix" | ||
|
||
import * as defaultRepositories from "@repositories" | ||
import * as defaultServices from "@services" | ||
|
||
export default async ({ | ||
container, | ||
options, | ||
}: LoaderOptions< | ||
| ModulesSdkTypes.ModuleServiceInitializeOptions | ||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ||
>): Promise<void> => { | ||
const customRepositories = ( | ||
options as ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ||
)?.repositories | ||
|
||
container.register({ | ||
// paymentService: asClass(defaultServices.PaymentService).singleton(), | ||
}) | ||
|
||
if (customRepositories) { | ||
loadCustomRepositories({ | ||
defaultRepositories, | ||
customRepositories, | ||
container, | ||
}) | ||
} else { | ||
loadDefaultRepositories({ container }) | ||
} | ||
} | ||
|
||
function loadDefaultRepositories({ container }) { | ||
container.register({ | ||
baseRepository: asClass(defaultRepositories.BaseRepository).singleton(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./connection" | ||
export * from "./container" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Payment } from "./payment" |
Oops, something went wrong.