diff --git a/accounting-service-api/package.json b/accounting-service-api/package.json index 1683b9f..94e0c60 100644 --- a/accounting-service-api/package.json +++ b/accounting-service-api/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/accounting-service-api", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/accounting-service-api/src/index.ts b/accounting-service-api/src/index.ts index f2ef1f5..27e9b96 100644 --- a/accounting-service-api/src/index.ts +++ b/accounting-service-api/src/index.ts @@ -1,2 +1,2 @@ -export * from './lib/entities'; -export * from './lib/service'; +export * from './lib/entities.js'; +export * from './lib/service.js'; diff --git a/accounting-service-api/src/lib/entities.ts b/accounting-service-api/src/lib/entities.ts new file mode 100644 index 0000000..d49ecb3 --- /dev/null +++ b/accounting-service-api/src/lib/entities.ts @@ -0,0 +1,13 @@ +import { entity, JSONEntity, JSONPartial, uuid, UUID } from '@deepkit/type'; + +import { Consumer } from '@ftgo/consumer-service-api'; + +@entity.name('account') +export class Account { + readonly id: UUID = uuid(); + readonly consumerId: Consumer['id']; + + static create(data: JSONPartial): Account { + return Object.assign(new Account(), data); + } +} diff --git a/accounting-service-api/src/lib/entities/account.ts b/accounting-service-api/src/lib/entities/account.ts deleted file mode 100644 index bc65bb0..0000000 --- a/accounting-service-api/src/lib/entities/account.ts +++ /dev/null @@ -1,13 +0,0 @@ -import {entity, JSONEntity, uuid, UUID} from "@deepkit/type"; - -import {Consumer} from "@ftgo/consumer-service-api"; - -@entity.name('account') -export class Account { - readonly id: UUID = uuid(); - readonly consumerId: Consumer['id']; - - static create(data: JSONEntity): Account{ - return Object.assign(new Account(), data); - } -} diff --git a/accounting-service-api/src/lib/entities/index.ts b/accounting-service-api/src/lib/entities/index.ts deleted file mode 100644 index 362a768..0000000 --- a/accounting-service-api/src/lib/entities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './account'; diff --git a/accounting-service-api/tsconfig.lib.json b/accounting-service-api/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/accounting-service-api/tsconfig.lib.json +++ b/accounting-service-api/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/accounting-service/project.json b/accounting-service/project.json index cdd5eec..b533e2a 100644 --- a/accounting-service/project.json +++ b/accounting-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["accounting-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/accounting-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/accounting-service/src/account.repository.ts b/accounting-service/src/account.repository.ts index 461b240..624203f 100644 --- a/accounting-service/src/account.repository.ts +++ b/accounting-service/src/account.repository.ts @@ -1,4 +1,4 @@ -import { Repository } from '@ftgo/common'; +import { RestateRepository } from '@ftgo/common'; import { Account } from '@ftgo/accounting-service-api'; -export class AccountRepository extends Repository(Account) {} +export class AccountRepository extends RestateRepository(Account) {} diff --git a/accounting-service/src/accounting.service.ts b/accounting-service/src/accounting.service.ts index d2ffed9..7e30044 100644 --- a/accounting-service/src/accounting.service.ts +++ b/accounting-service/src/accounting.service.ts @@ -1,12 +1,12 @@ import { restate, RestateServiceContext } from 'deepkit-restate'; +import { Consumer, KafkaConsumerTopic } from '@ftgo/consumer-service-api'; import { AccountingServiceApi, AccountingServiceHandlers, } from '@ftgo/accounting-service-api'; -import { Consumer, KafkaConsumerTopic } from '@ftgo/consumer-service-api'; -import { AccountRepository } from './account.repository'; +import { AccountRepository } from './account.repository.js'; @restate.service() export class AccountingService implements AccountingServiceHandlers { diff --git a/accounting-service/src/main.ts b/accounting-service/src/main.ts index d55554b..8ec5ae9 100644 --- a/accounting-service/src/main.ts +++ b/accounting-service/src/main.ts @@ -5,9 +5,9 @@ import { RestateModule } from 'deepkit-restate'; import { provideDatabase } from '@ftgo/common'; import { Account } from '@ftgo/accounting-service-api'; -import { AccountingServiceConfig } from './config'; -import { AccountingService } from './accounting.service'; -import { AccountRepository } from './account.repository'; +import { AccountingServiceConfig } from './config.js'; +import { AccountingService } from './accounting.service.js'; +import { AccountRepository } from './account.repository.js'; void new App({ config: AccountingServiceConfig, diff --git a/bun.lockb b/bun.lockb index 18604e9..aff0b2e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/common/package.json b/common/package.json index 2181a3d..7e663d8 100644 --- a/common/package.json +++ b/common/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/common", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/common/project.json b/common/project.json index edcb3ef..b771d31 100644 --- a/common/project.json +++ b/common/project.json @@ -19,7 +19,7 @@ "executor": "@nx/vite:test", "outputs": ["{options.reportsDirectory}"], "options": { - "reportsDirectory": "../coverage/common" + "reportsDirectory": "../../coverage/common" } } } diff --git a/common/src/index.ts b/common/src/index.ts index dbbf844..4922179 100644 --- a/common/src/index.ts +++ b/common/src/index.ts @@ -1,5 +1,5 @@ -export * from './lib/config'; -export * from './lib/database'; -export * from './lib/entities'; -export * from './lib/repository'; -export * from './lib/types'; +export * from './lib/config.js'; +export * from './lib/database.js'; +export * from './lib/entities.js'; +export * from './lib/repository.js'; +export * from './lib/types.js'; diff --git a/common/src/lib/config.ts b/common/src/lib/config.ts index 2d221cc..a9c2acb 100644 --- a/common/src/lib/config.ts +++ b/common/src/lib/config.ts @@ -14,5 +14,5 @@ export class DatabaseConfig { export class ServiceConfig { readonly database: DatabaseConfig; readonly restate: RestateConfig; - readonly framework?: FrameworkConfig; + readonly framework: FrameworkConfig = new FrameworkConfig(); } diff --git a/common/src/lib/database.ts b/common/src/lib/database.ts index 5ff90b9..d731185 100644 --- a/common/src/lib/database.ts +++ b/common/src/lib/database.ts @@ -3,12 +3,12 @@ import { PostgresDatabaseAdapter } from '@deepkit/postgres'; import { ClassType } from '@deepkit/core'; import { FactoryProvider } from '@deepkit/injector'; -import { DatabaseConfig } from './config'; +import { DatabaseConfig } from './config.js'; export class Database extends OrmDatabase { constructor( { user, host, password, port, name, schema }: DatabaseConfig, - entities: readonly ClassType[], + entities: ClassType[], ) { const uri = `postgres://${user}:${password}@${host}:${port}/${name}?schema=${schema}`; super(new PostgresDatabaseAdapter(uri), entities); @@ -16,7 +16,7 @@ export class Database extends OrmDatabase { } export function provideDatabase( - entities: readonly ClassType[], + entities: ClassType[], ): FactoryProvider { return { provide: Database, diff --git a/common/src/lib/entities.ts b/common/src/lib/entities.ts index 035871e..fd88f71 100644 --- a/common/src/lib/entities.ts +++ b/common/src/lib/entities.ts @@ -1,7 +1,7 @@ -import {float} from "@deepkit/type"; +import { float } from '@deepkit/type'; export class Money { - static ZERO = new Money(0) + static ZERO = new Money(0); constructor(readonly amount: float) {} diff --git a/common/src/lib/repository.ts b/common/src/lib/repository.ts index 7074fba..0112970 100644 --- a/common/src/lib/repository.ts +++ b/common/src/lib/repository.ts @@ -1,5 +1,15 @@ import { ClassType } from '@deepkit/core'; -import { ChangesInterface, DeepPartial, JSONEntity } from '@deepkit/type'; +import { + ChangesInterface, + DeepPartial, + JSONEntity, + JSONPartial, +} from '@deepkit/type'; +import { + RestateContextStorage, + RestateCustomContext, + RunAction, +} from 'deepkit-restate'; import { Database, DatabaseQueryModel, @@ -8,37 +18,58 @@ import { PatchResult, } from '@deepkit/orm'; -export function Repository( - entity: ClassType & { create(data: JSONEntity): T }, +export function RestateRepository( + entity: ClassType & { create(data: JSONPartial): T }, ) { - return class BaseRepository { - constructor(readonly database: Database) {} + return class Repository { + constructor( + readonly contextStorage: RestateContextStorage, + readonly database: Database, + ) {} - async findOne(filter: DatabaseQueryModel['filter']): Promise { - return await this.database.query(entity).filter(filter).findOne(); + get #ctx(): Pick { + return ( + this.contextStorage.getStore() || { + run: async (action: RunAction) => action(), + } + ); } - async deleteOne( + // async findOne(filter: DatabaseQueryModel['filter']): Promise { + // return await this.database.query(entity).filter(filter).findOne(); + // } + + async delete( filter: DatabaseQueryModel['filter'], ): Promise> { - return await this.database.query(entity).filter(filter).deleteOne(); + return await this.#ctx.run>(() => + this.database.query(entity).filter(filter).deleteOne(), + ); } - async find(filter: DatabaseQueryModel['filter']): Promise { - return await this.database.query(entity).filter(filter).find(); + // async find(filter: DatabaseQueryModel['filter']): Promise { + // return await this.database.query(entity).filter(filter).find(); + // } + + async find(filter: DatabaseQueryModel['filter']): Promise { + return await this.database.query(entity).filter(filter).findOne(); } async update( filter: DatabaseQueryModel['filter'], changes: ChangesInterface | DeepPartial, ): Promise> { - return await this.database.query(entity).filter(filter).patchOne(changes); + return await this.#ctx.run>(() => + this.database.query(entity).filter(filter).patchOne(changes), + ); } - async create(data: JSONEntity): Promise { - const et = entity.create(data); - await this.database.persist(et); - return et; + async create(data: JSONPartial): Promise { + return await this.#ctx.run(async () => { + const et = entity.create(data); + await this.database.persist(et); + return et; + }); } }; } diff --git a/common/tsconfig.lib.json b/common/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/common/tsconfig.lib.json +++ b/common/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/consumer-service-api/package.json b/consumer-service-api/package.json index b4e1d7a..17d4e86 100644 --- a/consumer-service-api/package.json +++ b/consumer-service-api/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/consumer-service-api", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/consumer-service-api/src/index.ts b/consumer-service-api/src/index.ts index 6908d38..7078ca6 100644 --- a/consumer-service-api/src/index.ts +++ b/consumer-service-api/src/index.ts @@ -1,3 +1,3 @@ -export * from './lib/entities'; -export * from './lib/service'; -export * from './lib/topics'; +export * from './lib/entities.js'; +export * from './lib/service.js'; +export * from './lib/topics.js'; diff --git a/consumer-service-api/src/lib/entities.ts b/consumer-service-api/src/lib/entities.ts new file mode 100644 index 0000000..7856f62 --- /dev/null +++ b/consumer-service-api/src/lib/entities.ts @@ -0,0 +1,20 @@ +import { + entity, + JSONEntity, + JSONPartial, + PrimaryKey, + uuid, + UUID, +} from '@deepkit/type'; + +import { PersonName } from '@ftgo/common'; + +@entity.name('consumer') +export class Consumer { + readonly id: UUID & PrimaryKey = uuid(); + readonly name: PersonName; + + static create(data: JSONPartial) { + return Object.assign(new Consumer(), data); + } +} diff --git a/consumer-service-api/src/lib/entities/consumer.ts b/consumer-service-api/src/lib/entities/consumer.ts deleted file mode 100644 index 7f3ce1f..0000000 --- a/consumer-service-api/src/lib/entities/consumer.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {entity, JSONEntity, PrimaryKey, uuid, UUID} from "@deepkit/type"; - -import {PersonName} from "@ftgo/common"; - -@entity.name('consumer') -export class Consumer { - readonly id: UUID & PrimaryKey = uuid(); - readonly name: PersonName; - - static create(data: JSONEntity) { - return Object.assign(new Consumer(), data); - } -} - diff --git a/consumer-service-api/src/lib/entities/index.ts b/consumer-service-api/src/lib/entities/index.ts deleted file mode 100644 index fd46f68..0000000 --- a/consumer-service-api/src/lib/entities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './consumer'; diff --git a/consumer-service-api/src/lib/topics.ts b/consumer-service-api/src/lib/topics.ts index 24a617f..8c10893 100644 --- a/consumer-service-api/src/lib/topics.ts +++ b/consumer-service-api/src/lib/topics.ts @@ -1,6 +1,6 @@ import { RestateKafkaTopic } from 'deepkit-restate'; -import { Consumer } from './entities'; +import { Consumer } from './entities.js'; export type KafkaConsumerTopic = RestateKafkaTopic< 'consumer', diff --git a/consumer-service-api/tsconfig.lib.json b/consumer-service-api/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/consumer-service-api/tsconfig.lib.json +++ b/consumer-service-api/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/consumer-service/project.json b/consumer-service/project.json index 145bf77..a7e9248 100644 --- a/consumer-service/project.json +++ b/consumer-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["consumer-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/consumer-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/consumer-service/src/consumer.repository.ts b/consumer-service/src/consumer.repository.ts index 3d13e81..aa27b0e 100644 --- a/consumer-service/src/consumer.repository.ts +++ b/consumer-service/src/consumer.repository.ts @@ -1,4 +1,4 @@ -import { Repository } from '@ftgo/common'; +import { RestateRepository } from '@ftgo/common'; import { Consumer } from '@ftgo/consumer-service-api'; -export class ConsumerRepository extends Repository(Consumer) {} +export class ConsumerRepository extends RestateRepository(Consumer) {} diff --git a/consumer-service/src/consumer.service.ts b/consumer-service/src/consumer.service.ts index fd8659a..7be0e94 100644 --- a/consumer-service/src/consumer.service.ts +++ b/consumer-service/src/consumer.service.ts @@ -2,15 +2,15 @@ import { restate, RestateServiceContext } from 'deepkit-restate'; import { RestateKafkaProducer } from 'deepkit-restate/kafka'; import { UUID } from '@deepkit/type'; +import { PersonName } from '@ftgo/common'; import { Consumer, ConsumerServiceApi, ConsumerServiceHandlers, KafkaConsumerTopic, } from '@ftgo/consumer-service-api'; -import { PersonName } from '@ftgo/common'; -import { ConsumerRepository } from './consumer.repository'; +import { ConsumerRepository } from './consumer.repository.js'; @restate.service() export class ConsumerService implements ConsumerServiceHandlers { @@ -26,5 +26,6 @@ export class ConsumerService implements ConsumerServiceHandlers { this.consumer.create({ name }), ); await this.kafka.produce([consumer]); + return consumer.id; } } diff --git a/consumer-service/src/main.ts b/consumer-service/src/main.ts index 6433b4a..8f3d662 100644 --- a/consumer-service/src/main.ts +++ b/consumer-service/src/main.ts @@ -3,16 +3,16 @@ import { FrameworkModule } from '@deepkit/framework'; import { RestateKafkaProducerModule } from 'deepkit-restate/kafka'; import { RestateModule } from 'deepkit-restate'; +import { provideDatabase } from '@ftgo/common'; import { Account, provideAccountingServiceApi, } from '@ftgo/accounting-service-api'; -import { ConsumerServiceConfig } from './config'; -import { provideDatabase } from '@ftgo/common'; -import { ConsumerController } from './consumer.controller'; -import { ConsumerService } from './consumer.service'; -import { ConsumerRepository } from './consumer.repository'; +import { ConsumerServiceConfig } from './config.js'; +import { ConsumerController } from './consumer.controller.js'; +import { ConsumerService } from './consumer.service.js'; +import { ConsumerRepository } from './consumer.repository.js'; void new App({ config: ConsumerServiceConfig, diff --git a/delivery-service-api/package.json b/delivery-service-api/package.json index 9c81c74..9272914 100644 --- a/delivery-service-api/package.json +++ b/delivery-service-api/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/delivery-service-api", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/delivery-service-api/src/index.ts b/delivery-service-api/src/index.ts index f2ef1f5..27e9b96 100644 --- a/delivery-service-api/src/index.ts +++ b/delivery-service-api/src/index.ts @@ -1,2 +1,2 @@ -export * from './lib/entities'; -export * from './lib/service'; +export * from './lib/entities.js'; +export * from './lib/service.js'; diff --git a/delivery-service-api/src/lib/entities/delivery.ts b/delivery-service-api/src/lib/entities.ts similarity index 72% rename from delivery-service-api/src/lib/entities/delivery.ts rename to delivery-service-api/src/lib/entities.ts index bd3c508..743adf9 100644 --- a/delivery-service-api/src/lib/entities/delivery.ts +++ b/delivery-service-api/src/lib/entities.ts @@ -1,4 +1,4 @@ -import {entity, JSONEntity} from "@deepkit/type"; +import { entity, JSONEntity } from '@deepkit/type'; @entity.name('delivery') export class Delivery { @@ -6,4 +6,3 @@ export class Delivery { return new Delivery(); } } - diff --git a/delivery-service-api/src/lib/entities/index.ts b/delivery-service-api/src/lib/entities/index.ts deleted file mode 100644 index 6459754..0000000 --- a/delivery-service-api/src/lib/entities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './delivery'; diff --git a/delivery-service-api/tsconfig.lib.json b/delivery-service-api/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/delivery-service-api/tsconfig.lib.json +++ b/delivery-service-api/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/delivery-service/project.json b/delivery-service/project.json index 18c4353..c7fd014 100644 --- a/delivery-service/project.json +++ b/delivery-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["delivery-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/delivery-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/delivery-service/src/delivery.repository.ts b/delivery-service/src/delivery.repository.ts index 2faab29..c694185 100644 --- a/delivery-service/src/delivery.repository.ts +++ b/delivery-service/src/delivery.repository.ts @@ -1,4 +1,4 @@ -import { Repository } from '@ftgo/common'; +import { RestateRepository } from '@ftgo/common'; import { Delivery } from '@ftgo/delivery-service-api'; -export class DeliveryRepository extends Repository(Delivery) {} +export class DeliveryRepository extends RestateRepository(Delivery) {} diff --git a/delivery-service/src/main.ts b/delivery-service/src/main.ts index 93fe59b..5eec814 100644 --- a/delivery-service/src/main.ts +++ b/delivery-service/src/main.ts @@ -4,10 +4,10 @@ import { RestateModule } from 'deepkit-restate'; import { provideDatabase } from '@ftgo/common'; -import { DeliveryServiceConfig } from './config'; -import { DeliveryRepository } from './delivery.repository'; -import { DeliveryController } from './delivery.controller'; -import { DeliveryService } from './delivery.service'; +import { DeliveryServiceConfig } from './config.js'; +import { DeliveryRepository } from './delivery.repository.js'; +import { DeliveryController } from './delivery.controller.js'; +import { DeliveryService } from './delivery.service.js'; void new App({ config: DeliveryServiceConfig, diff --git a/docker-compose.yml b/docker-compose.yml index 5cee4ea..b3a0c35 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,8 @@ +volumes: + postgres: + redpanda: + restate: + services: postgres: image: docker.io/postgres:16.4-alpine3.19 @@ -24,7 +29,7 @@ services: - '8080:8080' - '9070:9070' environment: - - 'RESTATE_CONFIG=/etc/config/config.toml' + - 'RESTATE_CONFIG=/etc/config/restate.toml' volumes: - ./infra/restate/config.toml:/etc/config/restate.toml extra_hosts: diff --git a/infra/postgres/project.json b/infra/postgres/project.json deleted file mode 100644 index e69de29..0000000 diff --git a/infra/redpanda/project.json b/infra/redpanda/project.json deleted file mode 100644 index e69de29..0000000 diff --git a/infra/restate/project.json b/infra/restate/project.json deleted file mode 100644 index e69de29..0000000 diff --git a/kitchen-service-api/package.json b/kitchen-service-api/package.json index 1f144a1..dc1ef24 100644 --- a/kitchen-service-api/package.json +++ b/kitchen-service-api/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/kitchen-service-api", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/kitchen-service-api/src/index.ts b/kitchen-service-api/src/index.ts index f2ef1f5..27e9b96 100644 --- a/kitchen-service-api/src/index.ts +++ b/kitchen-service-api/src/index.ts @@ -1,2 +1,2 @@ -export * from './lib/entities'; -export * from './lib/service'; +export * from './lib/entities.js'; +export * from './lib/service.js'; diff --git a/kitchen-service-api/src/lib/entities/kitchen.ts b/kitchen-service-api/src/lib/entities.ts similarity index 72% rename from kitchen-service-api/src/lib/entities/kitchen.ts rename to kitchen-service-api/src/lib/entities.ts index 3f63183..a017101 100644 --- a/kitchen-service-api/src/lib/entities/kitchen.ts +++ b/kitchen-service-api/src/lib/entities.ts @@ -1,4 +1,4 @@ -import {entity, JSONEntity} from "@deepkit/type"; +import { entity, JSONEntity } from '@deepkit/type'; @entity.name('kitchen') export class Kitchen { @@ -6,4 +6,3 @@ export class Kitchen { return new Kitchen(); } } - diff --git a/kitchen-service-api/src/lib/entities/index.ts b/kitchen-service-api/src/lib/entities/index.ts deleted file mode 100644 index d5133e5..0000000 --- a/kitchen-service-api/src/lib/entities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './kitchen'; diff --git a/kitchen-service-api/tsconfig.lib.json b/kitchen-service-api/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/kitchen-service-api/tsconfig.lib.json +++ b/kitchen-service-api/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/kitchen-service/project.json b/kitchen-service/project.json index 1f4b2b1..0770f1c 100644 --- a/kitchen-service/project.json +++ b/kitchen-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["kitchen-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/kitchen-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/kitchen-service/src/kitchen.repository.ts b/kitchen-service/src/kitchen.repository.ts index 7966d10..b860586 100644 --- a/kitchen-service/src/kitchen.repository.ts +++ b/kitchen-service/src/kitchen.repository.ts @@ -1,4 +1,4 @@ -import { Repository } from '@ftgo/common'; +import { RestateRepository } from '@ftgo/common'; import { Kitchen } from '@ftgo/kitchen-service-api'; -export class KitchenRepository extends Repository(Kitchen) {} +export class KitchenRepository extends RestateRepository(Kitchen) {} diff --git a/kitchen-service/src/main.ts b/kitchen-service/src/main.ts index 8c6072c..452719e 100644 --- a/kitchen-service/src/main.ts +++ b/kitchen-service/src/main.ts @@ -4,10 +4,10 @@ import { RestateModule } from 'deepkit-restate'; import { provideDatabase } from '@ftgo/common'; -import { KitchenServiceConfig } from './config'; -import { KitchenRepository } from './kitchen.repository'; -import { KitchenController } from './kitchen.controller'; -import { KitchenService } from './kitchen.service'; +import { KitchenServiceConfig } from './config.js'; +import { KitchenRepository } from './kitchen.repository.js'; +import { KitchenController } from './kitchen.controller.js'; +import { KitchenService } from './kitchen.service.js'; void new App({ config: KitchenServiceConfig, diff --git a/node-vite-config.ts b/node-vite-config.ts index 45ec0ab..1801493 100644 --- a/node-vite-config.ts +++ b/node-vite-config.ts @@ -25,8 +25,11 @@ export function defineNodeConfig({ return { root, + cacheDir: `${workspaceRoot}/node_modules/.vite/${projectPathFromWorkspaceRoot}`, build: { minify: mode === 'production', + outDir: `${workspaceRoot}/dist/${projectPathFromWorkspaceRoot}`, + emptyOutDir: true, rollupOptions: { preserveEntrySignatures: 'strict', output: { @@ -34,6 +37,9 @@ export function defineNodeConfig({ entryFileNames: `[name].mjs`, }, }, + commonjsOptions: { + transformMixedEsModules: true, + }, }, resolve: { mainFields: ['module'], @@ -45,7 +51,7 @@ export function defineNodeConfig({ sourceMap: true, }, }), - nxViteTsPaths({ debug }), + nxViteTsPaths({ debug, buildLibsFromSource: false }), ...(plugins || []), ], test: { @@ -53,7 +59,7 @@ export function defineNodeConfig({ passWithNoTests: true, environment: 'node', include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], - reporters: ['default', 'hanging-process'], + reporters: ['default'], coverage: { reportsDirectory: join( workspaceRoot, diff --git a/nx.json b/nx.json index a7e483c..f78b6c6 100644 --- a/nx.json +++ b/nx.json @@ -29,21 +29,11 @@ "@nx/vite:test": { "cache": true, "inputs": ["default", "^production"] - } - }, - "plugins": [ - { - "plugin": "@nx/eslint/plugin", - "options": { - "targetName": "lint" - } }, - { - "plugin": "@nx/jest/plugin", - "options": { - "targetName": "test" - }, - "exclude": ["order-service-e2e/**/*"] + "@nx/vite:build": { + "cache": true, + "dependsOn": ["^build"], + "inputs": ["production", "^production"] } - ] + } } diff --git a/order-history-service/project.json b/order-history-service/project.json index 39ee7bb..ecdbede 100644 --- a/order-history-service/project.json +++ b/order-history-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["order-history-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/order-history-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/order-history-service/src/main.ts b/order-history-service/src/main.ts index ec4b49b..895eed3 100644 --- a/order-history-service/src/main.ts +++ b/order-history-service/src/main.ts @@ -4,8 +4,8 @@ import { RestateModule } from 'deepkit-restate'; import { provideDatabase } from '@ftgo/common'; -import { OrderHistoryServiceConfig } from './config'; -import { OrderHistoryController } from './order-history.controller'; +import { OrderHistoryServiceConfig } from './config.js'; +import { OrderHistoryController } from './order-history.controller.js'; void new App({ config: OrderHistoryServiceConfig, diff --git a/order-service-api/package.json b/order-service-api/package.json index 8756005..4f7b007 100644 --- a/order-service-api/package.json +++ b/order-service-api/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/order-service-api", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/order-service-api/src/index.ts b/order-service-api/src/index.ts index f2ef1f5..27e9b96 100644 --- a/order-service-api/src/index.ts +++ b/order-service-api/src/index.ts @@ -1,2 +1,2 @@ -export * from './lib/entities'; -export * from './lib/service'; +export * from './lib/entities.js'; +export * from './lib/service.js'; diff --git a/order-service-api/src/lib/entities/order.ts b/order-service-api/src/lib/entities.ts similarity index 70% rename from order-service-api/src/lib/entities/order.ts rename to order-service-api/src/lib/entities.ts index c7b9ae0..5643a45 100644 --- a/order-service-api/src/lib/entities/order.ts +++ b/order-service-api/src/lib/entities.ts @@ -1,4 +1,4 @@ -import {entity, JSONEntity} from "@deepkit/type"; +import { entity, JSONEntity } from '@deepkit/type'; @entity.name('order') export class Order { @@ -6,4 +6,3 @@ export class Order { return new Order(); } } - diff --git a/order-service-api/src/lib/entities/index.ts b/order-service-api/src/lib/entities/index.ts deleted file mode 100644 index 4a42ee0..0000000 --- a/order-service-api/src/lib/entities/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './order'; diff --git a/order-service-api/tsconfig.lib.json b/order-service-api/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/order-service-api/tsconfig.lib.json +++ b/order-service-api/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/order-service/project.json b/order-service/project.json index 113152c..1eb3bb7 100644 --- a/order-service/project.json +++ b/order-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["order-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/order-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/order-service/src/main.ts b/order-service/src/main.ts index c2e40cc..3f2bf3a 100644 --- a/order-service/src/main.ts +++ b/order-service/src/main.ts @@ -5,10 +5,10 @@ import { RestateModule } from 'deepkit-restate'; import { Order } from '@ftgo/order-service-api'; import { provideDatabase } from '@ftgo/common'; -import { OrderServiceConfig } from './config'; -import { OrderController } from './order.controller'; -import { OrderService } from './order.service'; -import { OrderRepository } from './order.repository'; +import { OrderServiceConfig } from './config.js'; +import { OrderController } from './order.controller.js'; +import { OrderService } from './order.service.js'; +import { OrderRepository } from './order.repository.js'; void new App({ config: OrderServiceConfig, diff --git a/order-service/src/order.repository.ts b/order-service/src/order.repository.ts index 1889cc7..12ad91c 100644 --- a/order-service/src/order.repository.ts +++ b/order-service/src/order.repository.ts @@ -1,4 +1,4 @@ -import { Repository } from '@ftgo/common'; +import { RestateRepository } from '@ftgo/common'; import { Order } from '@ftgo/order-service-api'; -export class OrderRepository extends Repository(Order) {} +export class OrderRepository extends RestateRepository(Order) {} diff --git a/package.json b/package.json index abe0bf7..8700c56 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,11 @@ "@nx/js": "19.5.7", "@nx/node": "^19.5.7", "@nx/vite": "^19.5.7", + "@nx/web": "19.5.7", "@nx/workspace": "19.5.7", + "@swc-node/register": "~1.9.1", + "@swc/core": "~1.5.7", + "@swc/helpers": "~0.5.11", "@types/node": "~18.16.9", "@typescript-eslint/eslint-plugin": "^7.16.0", "@typescript-eslint/parser": "^7.16.0", @@ -21,6 +25,7 @@ "@vitest/ui": "^1.3.1", "eslint": "~8.57.0", "eslint-config-prettier": "^9.0.0", + "jsdom": "~22.1.0", "nx": "19.5.7", "prettier": "^3.3.3", "typescript": "^5.5.4", @@ -44,7 +49,7 @@ "@deepkit/postgres": "^1.0.1-alpha.153", "@deepkit/sql": "^1.0.1-alpha.153", "@deepkit/type": "^1.0.1-alpha.153", - "deepkit-restate": "^0.0.33", + "deepkit-restate": "^0.0.37", "kafkajs": "2.2.4", "tslib": "2.6.3" }, diff --git a/restaurant-service-api/package.json b/restaurant-service-api/package.json index 1006f0c..d1a6e75 100644 --- a/restaurant-service-api/package.json +++ b/restaurant-service-api/package.json @@ -1,10 +1,9 @@ { "name": "@ftgo/restaurant-service-api", "version": "0.0.1", + "type": "module", "dependencies": { "tslib": "^2.3.0" }, - "main": "./src/index.js", - "typings": "./src/index.d.ts", "private": true } diff --git a/restaurant-service-api/src/index.ts b/restaurant-service-api/src/index.ts index ae856c3..c1f0763 100644 --- a/restaurant-service-api/src/index.ts +++ b/restaurant-service-api/src/index.ts @@ -1,4 +1,4 @@ -export * from './lib/entities'; -export * from './lib/dtos'; -export * from './lib/service'; -export * from './lib/topics'; +export * from './lib/entities.js'; +export * from './lib/dtos.js'; +export * from './lib/service.js'; +export * from './lib/topics.js'; diff --git a/restaurant-service-api/src/lib/dtos.ts b/restaurant-service-api/src/lib/dtos.ts index 953f445..ce8a92c 100644 --- a/restaurant-service-api/src/lib/dtos.ts +++ b/restaurant-service-api/src/lib/dtos.ts @@ -1,8 +1,8 @@ import { UUID } from '@deepkit/type'; -import {Address} from "@ftgo/common"; +import { Address } from '@ftgo/common'; -import {RestaurantMenu} from './entities'; +import { RestaurantMenu } from './entities.js'; export interface CreateRestaurantRequest { readonly name: string; diff --git a/restaurant-service-api/src/lib/entities.ts b/restaurant-service-api/src/lib/entities.ts index 6ffcd88..80da3b7 100644 --- a/restaurant-service-api/src/lib/entities.ts +++ b/restaurant-service-api/src/lib/entities.ts @@ -1,6 +1,14 @@ -import {Embedded, entity, JSONEntity, PrimaryKey, uuid, UUID} from '@deepkit/type'; +import { + Embedded, + entity, + JSONEntity, + JSONPartial, + PrimaryKey, + uuid, + UUID, +} from '@deepkit/type'; -import {Address, Money} from "@ftgo/common"; +import { Address, Money } from '@ftgo/common'; @entity.name('restaurant') export class Restaurant { @@ -9,7 +17,7 @@ export class Restaurant { readonly address: Address; readonly menu: Embedded; - static create(data: JSONEntity): Restaurant { + static create(data: JSONPartial): Restaurant { return Object.assign(new Restaurant(), data); } } @@ -22,6 +30,8 @@ export interface RestaurantMenu { export class MenuItem { readonly id: UUID & PrimaryKey = uuid(); - constructor(readonly name: string, readonly price: Money) { - } + constructor( + readonly name: string, + readonly price: Money, + ) {} } diff --git a/restaurant-service-api/src/lib/service.ts b/restaurant-service-api/src/lib/service.ts index e9d0f3d..393c1cd 100644 --- a/restaurant-service-api/src/lib/service.ts +++ b/restaurant-service-api/src/lib/service.ts @@ -2,8 +2,8 @@ import { RestateClient, RestateService } from 'deepkit-restate'; import { typeOf, UUID } from '@deepkit/type'; import { FactoryProvider } from '@deepkit/injector'; -import { Restaurant } from './entities'; -import { CreateRestaurantRequest } from './dtos'; +import { Restaurant } from './entities.js'; +import { CreateRestaurantRequest } from './dtos.js'; export interface RestaurantServiceHandlers { create(request: CreateRestaurantRequest): Promise; diff --git a/restaurant-service-api/src/lib/topics.ts b/restaurant-service-api/src/lib/topics.ts index 13d0f72..2804ec2 100644 --- a/restaurant-service-api/src/lib/topics.ts +++ b/restaurant-service-api/src/lib/topics.ts @@ -1,6 +1,6 @@ import { RestateKafkaTopic } from 'deepkit-restate'; -import {Restaurant, RestaurantMenu} from './entities'; +import { Restaurant, RestaurantMenu } from './entities.js'; export type KafkaRestaurantCreatedTopic = RestateKafkaTopic< 'restaurant-created', @@ -9,4 +9,7 @@ export type KafkaRestaurantCreatedTopic = RestateKafkaTopic< // export type RestateRestaurantCreatedEvent = RestateEvent; -export type KafkaRestaurantMenuRevisedTopic = RestateKafkaTopic<'restaurant-menu-revised', [menu: RestaurantMenu]>; +export type KafkaRestaurantMenuRevisedTopic = RestateKafkaTopic< + 'restaurant-menu-revised', + [menu: RestaurantMenu] +>; diff --git a/restaurant-service-api/tsconfig.lib.json b/restaurant-service-api/tsconfig.lib.json index 2fd1e3f..0eb21b7 100644 --- a/restaurant-service-api/tsconfig.lib.json +++ b/restaurant-service-api/tsconfig.lib.json @@ -3,6 +3,8 @@ "compilerOptions": { "outDir": "../dist/out-tsc", "declaration": true, + "module": "esnext", + "moduleResolution": "node", "types": ["node"] }, "include": ["src/**/*.ts"], diff --git a/restaurant-service/project.json b/restaurant-service/project.json index 29bb625..5410e88 100644 --- a/restaurant-service/project.json +++ b/restaurant-service/project.json @@ -10,13 +10,9 @@ "executor": "@nx/vite:build", "outputs": ["{options.outputPath}"], "defaultConfiguration": "development", - "inputs": ["restaurant-service"], "options": { - "buildLibsFromSource": false, - "generatePackageJson": true, "outputPath": "dist/restaurant-service", "ssr": "src/main.ts", - "emptyOutDir": true, "outputFileName": "main.mjs" }, "configurations": { diff --git a/restaurant-service/src/main.ts b/restaurant-service/src/main.ts index 5104714..6a92ce9 100644 --- a/restaurant-service/src/main.ts +++ b/restaurant-service/src/main.ts @@ -9,10 +9,10 @@ import { } from '@ftgo/restaurant-service-api'; import { provideDatabase } from '@ftgo/common'; -import { RestaurantServiceConfig } from './config'; -import { RestaurantController } from './restaurant.controller'; -import { RestaurantService } from './restaurant.service'; -import { RestaurantRepository } from './restaurant.repository'; +import { RestaurantServiceConfig } from './config.js'; +import { RestaurantController } from './restaurant.controller.js'; +import { RestaurantService } from './restaurant.service.js'; +import { RestaurantRepository } from './restaurant.repository.js'; void new App({ config: RestaurantServiceConfig, diff --git a/restaurant-service/src/restaurant.repository.ts b/restaurant-service/src/restaurant.repository.ts index 588faf0..1017e9e 100644 --- a/restaurant-service/src/restaurant.repository.ts +++ b/restaurant-service/src/restaurant.repository.ts @@ -1,4 +1,4 @@ -import { Repository } from '@ftgo/common'; +import { RestateRepository } from '@ftgo/common'; import { Restaurant } from '@ftgo/restaurant-service-api'; -export class RestaurantRepository extends Repository(Restaurant) {} +export class RestaurantRepository extends RestateRepository(Restaurant) {} diff --git a/restaurant-service/src/restaurant.service.ts b/restaurant-service/src/restaurant.service.ts index e4a90b6..6c50e63 100644 --- a/restaurant-service/src/restaurant.service.ts +++ b/restaurant-service/src/restaurant.service.ts @@ -9,8 +9,16 @@ import { RestaurantServiceHandlers, } from '@ftgo/restaurant-service-api'; -import { RestaurantRepository } from './restaurant.repository'; +import { RestaurantRepository } from './restaurant.repository.js'; +/* +Type 'RestateService<"Restaurant", RestaurantServiceHandlers, any[]>' does not satisfy the constraint 'RestateService | RestateObject'. + Type 'RestateService<"Restaurant", RestaurantServiceHandlers, any[]>' is not assignable to type 'RestateObject'. + Property 'create' is incompatible with index signature. + Type '(request: CreateRestaurantRequest) => RestateHandlerRequest' is not assignable to type '(...args: unknown[]) => RestateHandlerRequest'. + Types of parameters 'request' and 'args' are incompatible. + Type 'unknown' is not assignable to type 'CreateRestaurantRequest' + */ @restate.service() export class RestaurantService implements RestaurantServiceHandlers { constructor( @@ -21,9 +29,8 @@ export class RestaurantService implements RestaurantServiceHandlers { @restate.handler() async create(request: CreateRestaurantRequest): Promise { - const restaurant = await this.ctx.run(() => - this.restaurant.create(request), - ); + // FIXME: why is type T and not Restaurant ? + const restaurant = (await this.restaurant.create(request)) as Restaurant; await this.kafka.produce([restaurant]); return restaurant; } diff --git a/restaurant-service/tsconfig.json b/restaurant-service/tsconfig.json index 60bce4b..9594da0 100644 --- a/restaurant-service/tsconfig.json +++ b/restaurant-service/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "../tsconfig.base.json", "compilerOptions": { - "strictPropertyInitialization": false, "types": ["vite/client"] }, "files": [], diff --git a/tsconfig.base.json b/tsconfig.base.json index d2bf801..185479a 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -4,7 +4,7 @@ "rootDir": ".", "sourceMap": true, "declaration": false, - "moduleResolution": "node", + "moduleResolution": "nodenext", "strictPropertyInitialization": false, "emitDecoratorMetadata": true, "useDefineForClassFields": false, @@ -19,39 +19,20 @@ "experimentalDecorators": true, "importHelpers": true, "target": "esnext", - "module": "esnext", - "lib": [ - "esnext", - "dom" - ], + "module": "nodenext", + "lib": ["esnext", "dom"], "skipLibCheck": true, "skipDefaultLibCheck": true, "baseUrl": ".", - "types": [ - "node" - ], + "types": ["node"], "paths": { - "@ftgo/accounting-service-api": [ - "accounting-service-api/src/index.ts" - ], - "@ftgo/consumer-service-api": [ - "consumer-service-api/src/index.ts" - ], - "@ftgo/delivery-service-api": [ - "delivery-service-api/src/index.ts" - ], - "@ftgo/kitchen-service-api": [ - "kitchen-service-api/src/index.ts" - ], - "@ftgo/order-service-api": [ - "order-service-api/src/index.ts" - ], - "@ftgo/restaurant-service-api": [ - "restaurant-service-api/src/index.ts" - ], - "@ftgo/common": [ - "common/src/index.ts" - ] + "@ftgo/accounting-service-api": ["accounting-service-api/src/index.ts"], + "@ftgo/common": ["common/src/index.ts"], + "@ftgo/consumer-service-api": ["consumer-service-api/src/index.ts"], + "@ftgo/delivery-service-api": ["delivery-service-api/src/index.ts"], + "@ftgo/kitchen-service-api": ["kitchen-service-api/src/index.ts"], + "@ftgo/order-service-api": ["order-service-api/src/index.ts"], + "@ftgo/restaurant-service-api": ["restaurant-service-api/src/index.ts"] } }, "exclude": ["node_modules", "tmp"]