-
-
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.
- Loading branch information
Showing
30 changed files
with
430 additions
and
0 deletions.
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
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 |
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 @@ | ||
# Store Module |
Empty file.
21 changes: 21 additions & 0 deletions
21
packages/store/integration-tests/__tests__/store-module-service.spec.ts
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 @@ | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import { IStoreModuleService } from "@medusajs/types" | ||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils" | ||
|
||
jest.setTimeout(100000) | ||
|
||
moduleIntegrationTestRunner({ | ||
moduleName: Modules.STORE, | ||
testSuite: ({ | ||
MikroOrmWrapper, | ||
service, | ||
}: SuiteOptions<IStoreModuleService>) => { | ||
describe("Store Module Service", () => { | ||
describe("noop", function () { | ||
it("should run", function () { | ||
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,22 @@ | ||
module.exports = { | ||
moduleNameMapper: { | ||
"^@models": "<rootDir>/src/models", | ||
"^@services": "<rootDir>/src/services", | ||
"^@repositories": "<rootDir>/src/repositories", | ||
"^@types": "<rootDir>/src/types", | ||
}, | ||
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-store", | ||
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/store", | ||
"version": "0.1.0", | ||
"description": "Medusa Store module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">=16" | ||
}, | ||
"bin": { | ||
"medusa-store-seed": "dist/scripts/bin/run-seed.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/medusajs/medusa", | ||
"directory": "packages/store" | ||
}, | ||
"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": "workspace:^", | ||
"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.4", | ||
"@medusajs/types": "^1.11.8", | ||
"@medusajs/utils": "^1.11.1", | ||
"@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,14 @@ | ||
import { moduleDefinition } from "./module-definition" | ||
import { initializeFactory, Modules } from "@medusajs/modules-sdk" | ||
|
||
export * from "./types" | ||
export * from "./models" | ||
export * from "./services" | ||
|
||
export const initialize = initializeFactory({ | ||
moduleName: Modules.STORE, | ||
moduleDefinition, | ||
}) | ||
export const runMigrations = moduleDefinition.runMigrations | ||
export const revertMigration = moduleDefinition.revertMigration | ||
export default moduleDefinition |
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,29 @@ | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import { ModuleJoinerConfig } from "@medusajs/types" | ||
import { MapToConfig } from "@medusajs/utils" | ||
import Store from "./models/store" | ||
|
||
export const LinkableKeys: Record<string, string> = {} | ||
|
||
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.STORE, | ||
primaryKeys: ["id"], | ||
linkableKeys: LinkableKeys, | ||
alias: [ | ||
{ | ||
name: ["store", "stores"], | ||
args: { entity: Store.name }, | ||
}, | ||
], | ||
} as ModuleJoinerConfig |
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 Store } from "./store" |
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,32 @@ | ||
import { generateEntityId } from "@medusajs/utils" | ||
|
||
import { | ||
BeforeCreate, | ||
Entity, | ||
OnInit, | ||
PrimaryKey, | ||
Property, | ||
} from "@mikro-orm/core" | ||
|
||
@Entity() | ||
export default class Store { | ||
@PrimaryKey({ columnType: "text" }) | ||
id: string | ||
|
||
@Property({ | ||
onCreate: () => new Date(), | ||
columnType: "timestamptz", | ||
defaultRaw: "now()", | ||
}) | ||
created_at: Date | ||
|
||
@BeforeCreate() | ||
onCreate() { | ||
this.id = generateEntityId(this.id, "store") | ||
} | ||
|
||
@OnInit() | ||
onInit() { | ||
this.id = generateEntityId(this.id, "store") | ||
} | ||
} |
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,44 @@ | ||
import { ModuleExports } from "@medusajs/types" | ||
import * as ModuleServices from "@services" | ||
import { StoreModuleService } from "@services" | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import * as Models from "@models" | ||
import * as ModuleModels from "@models" | ||
import { ModulesSdkUtils } from "@medusajs/utils" | ||
import * as ModuleRepositories from "@repositories" | ||
|
||
const migrationScriptOptions = { | ||
moduleName: Modules.STORE, | ||
models: Models, | ||
pathToMigrations: __dirname + "/migrations", | ||
} | ||
|
||
const runMigrations = ModulesSdkUtils.buildMigrationScript( | ||
migrationScriptOptions | ||
) | ||
|
||
const revertMigration = ModulesSdkUtils.buildRevertMigrationScript( | ||
migrationScriptOptions | ||
) | ||
|
||
const containerLoader = ModulesSdkUtils.moduleContainerLoaderFactory({ | ||
moduleModels: ModuleModels, | ||
moduleRepositories: ModuleRepositories, | ||
moduleServices: ModuleServices, | ||
}) | ||
|
||
const connectionLoader = ModulesSdkUtils.mikroOrmConnectionLoaderFactory({ | ||
moduleName: Modules.STORE, | ||
moduleModels: Object.values(Models), | ||
migrationsPath: __dirname + "/migrations", | ||
}) | ||
|
||
const service = StoreModuleService | ||
const loaders = [containerLoader, connectionLoader] as any | ||
|
||
export const moduleDefinition: ModuleExports = { | ||
service, | ||
loaders, | ||
revertMigration, | ||
runMigrations, | ||
} |
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 { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils" |
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,29 @@ | ||
#!/usr/bin/env node | ||
|
||
import { ModulesSdkUtils } from "@medusajs/utils" | ||
import { Modules } from "@medusajs/modules-sdk" | ||
import * as Models from "@models" | ||
import { EOL } from "os" | ||
|
||
const args = process.argv | ||
const path = args.pop() as string | ||
|
||
export default (async () => { | ||
const { config } = await import("dotenv") | ||
config() | ||
if (!path) { | ||
throw new Error( | ||
`filePath is required.${EOL}Example: medusa-store-seed <filePath>` | ||
) | ||
} | ||
|
||
const run = ModulesSdkUtils.buildSeedScript({ | ||
moduleName: Modules.STORE, | ||
models: Models, | ||
pathToMigrations: __dirname + "/../../migrations", | ||
seedHandler: async ({ manager, data }) => { | ||
// TODO: Add seed logic | ||
}, | ||
}) | ||
await run({ path }) | ||
})() |
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", function () { | ||
it("should run", function () { | ||
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 @@ | ||
export { default as StoreModuleService } from "./store-module-service" |
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,47 @@ | ||
import { | ||
DAL, | ||
InternalModuleDeclaration, | ||
ModuleJoinerConfig, | ||
ModulesSdkTypes, | ||
IStoreModuleService, | ||
StoreTypes, | ||
} from "@medusajs/types" | ||
import { ModulesSdkUtils } from "@medusajs/utils" | ||
|
||
import { Store } from "@models" | ||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config" | ||
|
||
const generateMethodForModels = [] | ||
|
||
type InjectedDependencies = { | ||
baseRepository: DAL.RepositoryService | ||
storeService: ModulesSdkTypes.InternalModuleService<any> | ||
} | ||
|
||
export default class StoreModuleService<TEntity extends Store = Store> | ||
extends ModulesSdkUtils.abstractModuleServiceFactory< | ||
InjectedDependencies, | ||
StoreTypes.StoreDTO, | ||
{ | ||
Store: { dto: StoreTypes.StoreDTO } | ||
} | ||
>(Store, generateMethodForModels, entityNameToLinkableKeysMap) | ||
implements IStoreModuleService | ||
{ | ||
protected baseRepository_: DAL.RepositoryService | ||
protected readonly storeService_: ModulesSdkTypes.InternalModuleService<TEntity> | ||
|
||
constructor( | ||
{ baseRepository, storeService }: InjectedDependencies, | ||
protected readonly moduleDeclaration: InternalModuleDeclaration | ||
) { | ||
// @ts-ignore | ||
super(...arguments) | ||
this.baseRepository_ = baseRepository | ||
this.storeService_ = storeService | ||
} | ||
|
||
__joinerConfig(): ModuleJoinerConfig { | ||
return joinerConfig | ||
} | ||
} |
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 { IEventBusModuleService, Logger } from "@medusajs/types" | ||
|
||
export type InitializeModuleInjectableDependencies = { | ||
logger?: Logger | ||
eventBusService?: IEventBusModuleService | ||
} |
Oops, something went wrong.