@bett3r-dev/pv3 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/adapters/cache/index.d.ts +2 -0
- package/build/adapters/cache/index.d.ts.map +1 -0
- package/build/adapters/cache/index.js +18 -0
- package/build/adapters/cache/index.js.map +1 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.d.ts +1 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.d.ts.map +1 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.js +6 -0
- package/build/adapters/cache/memory/__tests__/memoryCache.test.js.map +1 -0
- package/build/adapters/cache/memory/index.d.ts +3 -0
- package/build/adapters/cache/memory/index.d.ts.map +1 -0
- package/build/adapters/cache/memory/index.js +119 -0
- package/build/adapters/cache/memory/index.js.map +1 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.d.ts +2 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.d.ts.map +1 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.js +43 -0
- package/build/adapters/configuration/__tests__/dotEnv.test.js.map +1 -0
- package/build/adapters/configuration/dotEnv.d.ts +3 -0
- package/build/adapters/configuration/dotEnv.d.ts.map +1 -0
- package/build/adapters/configuration/dotEnv.js +35 -0
- package/build/adapters/configuration/dotEnv.js.map +1 -0
- package/build/adapters/configuration/index.d.ts +2 -0
- package/build/adapters/configuration/index.d.ts.map +1 -0
- package/build/adapters/configuration/index.js +18 -0
- package/build/adapters/configuration/index.js.map +1 -0
- package/build/adapters/database/index.d.ts +2 -0
- package/build/adapters/database/index.d.ts.map +1 -0
- package/build/adapters/database/index.js +18 -0
- package/build/adapters/database/index.js.map +1 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.d.ts +1 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.d.ts.map +1 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.js +36 -0
- package/build/adapters/database/memory/__tests__/memoryDb.test.js.map +1 -0
- package/build/adapters/database/memory/index.d.ts +3 -0
- package/build/adapters/database/memory/index.d.ts.map +1 -0
- package/build/adapters/database/memory/index.js +241 -0
- package/build/adapters/database/memory/index.js.map +1 -0
- package/build/adapters/endpoints/addAuthUser/index.d.ts +8 -0
- package/build/adapters/endpoints/addAuthUser/index.d.ts.map +1 -0
- package/build/adapters/endpoints/addAuthUser/index.js +57 -0
- package/build/adapters/endpoints/addAuthUser/index.js.map +1 -0
- package/build/adapters/endpoints/endpointValidation/index.d.ts +4 -0
- package/build/adapters/endpoints/endpointValidation/index.d.ts.map +1 -0
- package/build/adapters/endpoints/endpointValidation/index.js +27 -0
- package/build/adapters/endpoints/endpointValidation/index.js.map +1 -0
- package/build/adapters/endpoints/index.d.ts +4 -0
- package/build/adapters/endpoints/index.d.ts.map +1 -0
- package/build/adapters/endpoints/index.js +21 -0
- package/build/adapters/endpoints/index.js.map +1 -0
- package/build/adapters/endpoints/localAuthorization/index.d.ts +1 -0
- package/build/adapters/endpoints/localAuthorization/index.d.ts.map +1 -0
- package/build/adapters/endpoints/localAuthorization/index.js +68 -0
- package/build/adapters/endpoints/localAuthorization/index.js.map +1 -0
- package/build/adapters/endpoints/tcpConsumer/index.d.ts +3 -0
- package/build/adapters/endpoints/tcpConsumer/index.d.ts.map +1 -0
- package/build/adapters/endpoints/tcpConsumer/index.js +64 -0
- package/build/adapters/endpoints/tcpConsumer/index.js.map +1 -0
- package/build/adapters/endpoints/userSession/index.d.ts +8 -0
- package/build/adapters/endpoints/userSession/index.d.ts.map +1 -0
- package/build/adapters/endpoints/userSession/index.js +43 -0
- package/build/adapters/endpoints/userSession/index.js.map +1 -0
- package/build/adapters/eventstore/database.d.ts +3 -0
- package/build/adapters/eventstore/database.d.ts.map +1 -0
- package/build/adapters/eventstore/database.js +156 -0
- package/build/adapters/eventstore/database.js.map +1 -0
- package/build/adapters/eventstore/index.d.ts +2 -0
- package/build/adapters/eventstore/index.d.ts.map +1 -0
- package/build/adapters/eventstore/index.js +18 -0
- package/build/adapters/eventstore/index.js.map +1 -0
- package/build/adapters/infrastructure/index.d.ts +2 -0
- package/build/adapters/infrastructure/index.d.ts.map +1 -0
- package/build/adapters/infrastructure/index.js +18 -0
- package/build/adapters/infrastructure/index.js.map +1 -0
- package/build/adapters/infrastructure/local/index.d.ts +4 -0
- package/build/adapters/infrastructure/local/index.d.ts.map +1 -0
- package/build/adapters/infrastructure/local/index.js +37 -0
- package/build/adapters/infrastructure/local/index.js.map +1 -0
- package/build/adapters/logger/console.d.ts +3 -0
- package/build/adapters/logger/console.d.ts.map +1 -0
- package/build/adapters/logger/console.js +38 -0
- package/build/adapters/logger/console.js.map +1 -0
- package/build/adapters/logger/index.d.ts +2 -0
- package/build/adapters/logger/index.d.ts.map +1 -0
- package/build/adapters/logger/index.js +18 -0
- package/build/adapters/logger/index.js.map +1 -0
- package/build/index.d.ts +23 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +39 -0
- package/build/index.js.map +1 -0
- package/build/libraries/modules/fs.d.ts +12 -0
- package/build/libraries/modules/fs.d.ts.map +1 -0
- package/build/libraries/modules/fs.js +103 -0
- package/build/libraries/modules/fs.js.map +1 -0
- package/build/libraries/modules/index.d.ts +2 -0
- package/build/libraries/modules/index.d.ts.map +1 -0
- package/build/libraries/modules/index.js +18 -0
- package/build/libraries/modules/index.js.map +1 -0
- package/build/libraries/openApi/index.d.ts +2 -0
- package/build/libraries/openApi/index.d.ts.map +1 -0
- package/build/libraries/openApi/index.js +18 -0
- package/build/libraries/openApi/index.js.map +1 -0
- package/build/libraries/openApi/pruneUnusedRef.d.ts +3 -0
- package/build/libraries/openApi/pruneUnusedRef.d.ts.map +1 -0
- package/build/libraries/openApi/pruneUnusedRef.js +30 -0
- package/build/libraries/openApi/pruneUnusedRef.js.map +1 -0
- package/build/libraries/tcp/index.d.ts +8 -0
- package/build/libraries/tcp/index.d.ts.map +1 -0
- package/build/libraries/tcp/index.js +108 -0
- package/build/libraries/tcp/index.js.map +1 -0
- package/build/libraries/tcp/types.d.ts +45 -0
- package/build/libraries/tcp/types.d.ts.map +1 -0
- package/build/libraries/tcp/types.js +3 -0
- package/build/libraries/tcp/types.js.map +1 -0
- package/build/libraries/validation/__tests__/validation.test.d.ts +2 -0
- package/build/libraries/validation/__tests__/validation.test.d.ts.map +1 -0
- package/build/libraries/validation/__tests__/validation.test.js +53 -0
- package/build/libraries/validation/__tests__/validation.test.js.map +1 -0
- package/build/libraries/validation/index.d.ts +8 -0
- package/build/libraries/validation/index.d.ts.map +1 -0
- package/build/libraries/validation/index.js +51 -0
- package/build/libraries/validation/index.js.map +1 -0
- package/build/ports/authentication/index.d.ts +12 -0
- package/build/ports/authentication/index.d.ts.map +1 -0
- package/build/ports/authentication/index.js +23 -0
- package/build/ports/authentication/index.js.map +1 -0
- package/build/ports/base.d.ts +7 -0
- package/build/ports/base.d.ts.map +1 -0
- package/build/ports/base.js +25 -0
- package/build/ports/base.js.map +1 -0
- package/build/ports/cache/index.d.ts +3 -0
- package/build/ports/cache/index.d.ts.map +1 -0
- package/build/ports/cache/index.js +19 -0
- package/build/ports/cache/index.js.map +1 -0
- package/build/ports/configuration/__tests__/configurationPort.test.d.ts +2 -0
- package/build/ports/configuration/__tests__/configurationPort.test.d.ts.map +1 -0
- package/build/ports/configuration/__tests__/configurationPort.test.js +51 -0
- package/build/ports/configuration/__tests__/configurationPort.test.js.map +1 -0
- package/build/ports/configuration/args.d.ts +57 -0
- package/build/ports/configuration/args.d.ts.map +1 -0
- package/build/ports/configuration/args.js +44 -0
- package/build/ports/configuration/args.js.map +1 -0
- package/build/ports/configuration/common.d.ts +2 -0
- package/build/ports/configuration/common.d.ts.map +1 -0
- package/build/ports/configuration/common.js +19 -0
- package/build/ports/configuration/common.js.map +1 -0
- package/build/ports/configuration/index.d.ts +10 -0
- package/build/ports/configuration/index.d.ts.map +1 -0
- package/build/ports/configuration/index.js +96 -0
- package/build/ports/configuration/index.js.map +1 -0
- package/build/ports/configuration/localConfig.d.ts +3 -0
- package/build/ports/configuration/localConfig.d.ts.map +1 -0
- package/build/ports/configuration/localConfig.js +108 -0
- package/build/ports/configuration/localConfig.js.map +1 -0
- package/build/ports/database/index.d.ts +4 -0
- package/build/ports/database/index.d.ts.map +1 -0
- package/build/ports/database/index.js +27 -0
- package/build/ports/database/index.js.map +1 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.d.ts +2 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.js +21 -0
- package/build/ports/endpoints/__tests__/endpointsCall.test.js.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.d.ts +77 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.js +91 -0
- package/build/ports/endpoints/__tests__/test-client-library/base.js.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.d.ts +29 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.js +43 -0
- package/build/ports/endpoints/__tests__/test-client-library/index.js.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.d.ts +106 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.js +62 -0
- package/build/ports/endpoints/__tests__/test-client-library/services/service.js.map +1 -0
- package/build/ports/endpoints/__tests__/utils.test.d.ts +1 -0
- package/build/ports/endpoints/__tests__/utils.test.d.ts.map +1 -0
- package/build/ports/endpoints/__tests__/utils.test.js +53 -0
- package/build/ports/endpoints/__tests__/utils.test.js.map +1 -0
- package/build/ports/endpoints/index.d.ts +29 -0
- package/build/ports/endpoints/index.d.ts.map +1 -0
- package/build/ports/endpoints/index.js +263 -0
- package/build/ports/endpoints/index.js.map +1 -0
- package/build/ports/endpoints/openApi.d.ts +16 -0
- package/build/ports/endpoints/openApi.d.ts.map +1 -0
- package/build/ports/endpoints/openApi.js +187 -0
- package/build/ports/endpoints/openApi.js.map +1 -0
- package/build/ports/endpoints/utils.d.ts +17 -0
- package/build/ports/endpoints/utils.d.ts.map +1 -0
- package/build/ports/endpoints/utils.js +31 -0
- package/build/ports/endpoints/utils.js.map +1 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.d.ts +2 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.d.ts.map +1 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.js +35 -0
- package/build/ports/eventsourcing/__tests__/eventhandlers.test.js.map +1 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.d.ts +2 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.d.ts.map +1 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.js +210 -0
- package/build/ports/eventsourcing/__tests__/invariants.test.js.map +1 -0
- package/build/ports/eventsourcing/commandHandlers/index.d.ts +25 -0
- package/build/ports/eventsourcing/commandHandlers/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandHandlers/index.js +392 -0
- package/build/ports/eventsourcing/commandHandlers/index.js.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/index.d.ts +3 -0
- package/build/ports/eventsourcing/commandTemplates/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/index.js +19 -0
- package/build/ports/eventsourcing/commandTemplates/index.js.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.d.ts +4 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.js +73 -0
- package/build/ports/eventsourcing/commandTemplates/multiStream.js.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.d.ts +9 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.d.ts.map +1 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.js +39 -0
- package/build/ports/eventsourcing/commandTemplates/snapshot.js.map +1 -0
- package/build/ports/eventsourcing/eventHandlers/index.d.ts +33 -0
- package/build/ports/eventsourcing/eventHandlers/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/eventHandlers/index.js +276 -0
- package/build/ports/eventsourcing/eventHandlers/index.js.map +1 -0
- package/build/ports/eventsourcing/index.d.ts +9 -0
- package/build/ports/eventsourcing/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/index.js +101 -0
- package/build/ports/eventsourcing/index.js.map +1 -0
- package/build/ports/eventsourcing/invariants/combinators.d.ts +4 -0
- package/build/ports/eventsourcing/invariants/combinators.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/combinators.js +20 -0
- package/build/ports/eventsourcing/invariants/combinators.js.map +1 -0
- package/build/ports/eventsourcing/invariants/common.d.ts +10 -0
- package/build/ports/eventsourcing/invariants/common.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/common.js +37 -0
- package/build/ports/eventsourcing/invariants/common.js.map +1 -0
- package/build/ports/eventsourcing/invariants/comparisons.d.ts +19 -0
- package/build/ports/eventsourcing/invariants/comparisons.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/comparisons.js +83 -0
- package/build/ports/eventsourcing/invariants/comparisons.js.map +1 -0
- package/build/ports/eventsourcing/invariants/index.d.ts +5 -0
- package/build/ports/eventsourcing/invariants/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/index.js +21 -0
- package/build/ports/eventsourcing/invariants/index.js.map +1 -0
- package/build/ports/eventsourcing/invariants/stateExistance.d.ts +4 -0
- package/build/ports/eventsourcing/invariants/stateExistance.d.ts.map +1 -0
- package/build/ports/eventsourcing/invariants/stateExistance.js +33 -0
- package/build/ports/eventsourcing/invariants/stateExistance.js.map +1 -0
- package/build/ports/eventsourcing/subscriptions/index.d.ts +2 -0
- package/build/ports/eventsourcing/subscriptions/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/subscriptions/index.js +18 -0
- package/build/ports/eventsourcing/subscriptions/index.js.map +1 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.d.ts +3 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.d.ts.map +1 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.js +81 -0
- package/build/ports/eventsourcing/subscriptions/sseSubscriptions.js.map +1 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.d.ts +4 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.js +45 -0
- package/build/ports/eventsourcing/utils/aggregateBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/commandBuilder.d.ts +3 -0
- package/build/ports/eventsourcing/utils/commandBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/commandBuilder.js +102 -0
- package/build/ports/eventsourcing/utils/commandBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.d.ts +3 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.js +19 -0
- package/build/ports/eventsourcing/utils/eventHandlerBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.d.ts +4 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.js +34 -0
- package/build/ports/eventsourcing/utils/externalSystemBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/index.d.ts +13 -0
- package/build/ports/eventsourcing/utils/index.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/index.js +45 -0
- package/build/ports/eventsourcing/utils/index.js.map +1 -0
- package/build/ports/eventsourcing/utils/policyBuilder.d.ts +3 -0
- package/build/ports/eventsourcing/utils/policyBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/policyBuilder.js +29 -0
- package/build/ports/eventsourcing/utils/policyBuilder.js.map +1 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.d.ts +5 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.d.ts.map +1 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.js +45 -0
- package/build/ports/eventsourcing/utils/readmodelBuilder.js.map +1 -0
- package/build/ports/eventstore/index.d.ts +3 -0
- package/build/ports/eventstore/index.d.ts.map +1 -0
- package/build/ports/eventstore/index.js +13 -0
- package/build/ports/eventstore/index.js.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/index.d.ts +3 -0
- package/build/ports/infrastructure/__tests__/fixture/index.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/index.js +19 -0
- package/build/ports/infrastructure/__tests__/fixture/index.js.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.d.ts +19 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.js +76 -0
- package/build/ports/infrastructure/__tests__/fixture/infrastructureServices.js.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.d.ts +177 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.js +258 -0
- package/build/ports/infrastructure/__tests__/fixture/structureState.js.map +1 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.d.ts +2 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.d.ts.map +1 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.js +11 -0
- package/build/ports/infrastructure/__tests__/infrastructure.test.js.map +1 -0
- package/build/ports/infrastructure/index.d.ts +53 -0
- package/build/ports/infrastructure/index.d.ts.map +1 -0
- package/build/ports/infrastructure/index.js +149 -0
- package/build/ports/infrastructure/index.js.map +1 -0
- package/build/ports/infrastructure/utils.d.ts +14 -0
- package/build/ports/infrastructure/utils.d.ts.map +1 -0
- package/build/ports/infrastructure/utils.js +126 -0
- package/build/ports/infrastructure/utils.js.map +1 -0
- package/build/ports/logger/index.d.ts +3 -0
- package/build/ports/logger/index.d.ts.map +1 -0
- package/build/ports/logger/index.js +32 -0
- package/build/ports/logger/index.js.map +1 -0
- package/build/utils/index.d.ts +35 -0
- package/build/utils/index.d.ts.map +1 -0
- package/build/utils/index.js +190 -0
- package/build/utils/index.js.map +1 -0
- package/package.json +28 -0
- package/src/adapters/cache/index.ts +1 -0
- package/src/adapters/cache/memory/__tests__/memoryCache.test.ts +6 -0
- package/src/adapters/cache/memory/index.ts +142 -0
- package/src/adapters/configuration/__tests__/.env +4 -0
- package/src/adapters/configuration/__tests__/dotEnv.test.ts +38 -0
- package/src/adapters/configuration/dotEnv.ts +33 -0
- package/src/adapters/configuration/index.ts +1 -0
- package/src/adapters/database/index.ts +1 -0
- package/src/adapters/database/memory/__tests__/memoryDb.test.ts +37 -0
- package/src/adapters/database/memory/index.ts +279 -0
- package/src/adapters/endpoints/addAuthUser/index.ts +55 -0
- package/src/adapters/endpoints/endpointValidation/index.ts +26 -0
- package/src/adapters/endpoints/index.ts +4 -0
- package/src/adapters/endpoints/localAuthorization/index.ts +75 -0
- package/src/adapters/endpoints/tcpConsumer/index.ts +69 -0
- package/src/adapters/endpoints/userSession/index.ts +40 -0
- package/src/adapters/eventstore/database.ts +178 -0
- package/src/adapters/eventstore/index.ts +1 -0
- package/src/adapters/infrastructure/index.ts +1 -0
- package/src/adapters/infrastructure/local/index.ts +40 -0
- package/src/adapters/logger/console.ts +42 -0
- package/src/adapters/logger/index.ts +1 -0
- package/src/index.ts +25 -0
- package/src/libraries/modules/fs.ts +88 -0
- package/src/libraries/modules/index.ts +1 -0
- package/src/libraries/openApi/index.ts +1 -0
- package/src/libraries/openApi/pruneUnusedRef.ts +35 -0
- package/src/libraries/tcp/index.ts +98 -0
- package/src/libraries/tcp/types.ts +43 -0
- package/src/libraries/validation/__tests__/validation.test.ts +25 -0
- package/src/libraries/validation/index.ts +48 -0
- package/src/ports/authentication/index.ts +25 -0
- package/src/ports/base.ts +20 -0
- package/src/ports/cache/index.ts +17 -0
- package/src/ports/configuration/__tests__/configurationPort.test.ts +47 -0
- package/src/ports/configuration/args.ts +39 -0
- package/src/ports/configuration/common.ts +12 -0
- package/src/ports/configuration/index.ts +110 -0
- package/src/ports/configuration/localConfig.ts +117 -0
- package/src/ports/database/index.ts +25 -0
- package/src/ports/endpoints/__tests__/endpointsCall.test.ts +20 -0
- package/src/ports/endpoints/__tests__/test-client-library/base.ts +167 -0
- package/src/ports/endpoints/__tests__/test-client-library/index.ts +23 -0
- package/src/ports/endpoints/__tests__/test-client-library/services/service.ts +181 -0
- package/src/ports/endpoints/__tests__/utils.test.ts +54 -0
- package/src/ports/endpoints/index.ts +272 -0
- package/src/ports/endpoints/openApi.ts +191 -0
- package/src/ports/endpoints/utils.ts +31 -0
- package/src/ports/eventsourcing/__tests__/eventhandlers.test.ts +30 -0
- package/src/ports/eventsourcing/__tests__/invariants.test.ts +213 -0
- package/src/ports/eventsourcing/commandHandlers/index.ts +625 -0
- package/src/ports/eventsourcing/commandTemplates/index.ts +2 -0
- package/src/ports/eventsourcing/commandTemplates/multiStream.ts +70 -0
- package/src/ports/eventsourcing/commandTemplates/snapshot.ts +43 -0
- package/src/ports/eventsourcing/eventHandlers/index.ts +429 -0
- package/src/ports/eventsourcing/index.ts +98 -0
- package/src/ports/eventsourcing/invariants/combinators.ts +25 -0
- package/src/ports/eventsourcing/invariants/common.ts +42 -0
- package/src/ports/eventsourcing/invariants/comparisons.ts +90 -0
- package/src/ports/eventsourcing/invariants/index.ts +4 -0
- package/src/ports/eventsourcing/invariants/stateExistance.ts +34 -0
- package/src/ports/eventsourcing/subscriptions/index.ts +1 -0
- package/src/ports/eventsourcing/subscriptions/sseSubscriptions.ts +103 -0
- package/src/ports/eventsourcing/utils/aggregateBuilder.ts +49 -0
- package/src/ports/eventsourcing/utils/commandBuilder.ts +113 -0
- package/src/ports/eventsourcing/utils/eventHandlerBuilder.ts +22 -0
- package/src/ports/eventsourcing/utils/externalSystemBuilder.ts +42 -0
- package/src/ports/eventsourcing/utils/index.ts +25 -0
- package/src/ports/eventsourcing/utils/policyBuilder.ts +31 -0
- package/src/ports/eventsourcing/utils/readmodelBuilder.ts +52 -0
- package/src/ports/eventstore/index.ts +11 -0
- package/src/ports/infrastructure/__tests__/fixture/index.ts +2 -0
- package/src/ports/infrastructure/__tests__/fixture/infrastructureServices.ts +72 -0
- package/src/ports/infrastructure/__tests__/fixture/structureState.ts +254 -0
- package/src/ports/infrastructure/__tests__/infrastructure.test.ts +11 -0
- package/src/ports/infrastructure/index.ts +162 -0
- package/src/ports/infrastructure/utils.ts +130 -0
- package/src/ports/logger/index.ts +34 -0
- package/src/utils/index.ts +186 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PortEmitter, PortEmitterEvents, TypedEventEmitter } from '@bett3r-dev/pv3-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Factory wrapper to create Ports, Extends the port definition with the PortEmitter Interface.
|
|
5
|
+
* @param port The Port to instanciate.
|
|
6
|
+
*/
|
|
7
|
+
export const createPort = <PORT>( port: PORT ): PORT & PortEmitter => {
|
|
8
|
+
const emitter = new TypedEventEmitter<PortEmitterEvents>();
|
|
9
|
+
emitter.setMaxListeners( 100 );
|
|
10
|
+
const instance = {
|
|
11
|
+
emitter,
|
|
12
|
+
isStarted: false,
|
|
13
|
+
onStarted: ( fn: () => void ) => {
|
|
14
|
+
if ( instance.isStarted ) fn();
|
|
15
|
+
emitter.once( 'started', fn );
|
|
16
|
+
},
|
|
17
|
+
...port
|
|
18
|
+
};
|
|
19
|
+
return instance;
|
|
20
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Provides the abstraction For Caching data on Memory, Redis, Memcached, etc.
|
|
4
|
+
*/
|
|
5
|
+
import { createPort } from '../base';
|
|
6
|
+
import { CacheAdapter, CachePort } from '@bett3r-dev/pv3-types';
|
|
7
|
+
|
|
8
|
+
export const Cache = ( adapter: CacheAdapter ): CachePort => {
|
|
9
|
+
const cache = createPort( adapter );
|
|
10
|
+
adapter.start()
|
|
11
|
+
.then(() => {
|
|
12
|
+
cache.isStarted = true;
|
|
13
|
+
cache.emitter.emit( 'started' );
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return cache;
|
|
17
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import S from '@bett3r-dev/jsonschema-definer';
|
|
2
|
+
import { Configuration } from '../index';
|
|
3
|
+
|
|
4
|
+
describe( 'configuration', function() {
|
|
5
|
+
const getAdapter = ( config: any ) => ({
|
|
6
|
+
applyConfig: async () => config,
|
|
7
|
+
name:'test',
|
|
8
|
+
_adapter:() => {},
|
|
9
|
+
start: async () =>{},
|
|
10
|
+
stop:async () => {}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe( 'getModuleConfig', function() {
|
|
14
|
+
it( 'returns all the config', async () => {
|
|
15
|
+
const config = { module1:{ prop1: 'prop1' }, module2:{ prop2: 'prop2' }};
|
|
16
|
+
const configuration = await Configuration( getAdapter( config ));
|
|
17
|
+
expect( configuration._getConfig()).toEqual({ module1: { prop1: 'prop1' }, module2: { prop2: 'prop2' }});
|
|
18
|
+
});
|
|
19
|
+
it( 'returns a partial of the configuration object', async () => {
|
|
20
|
+
const config = { module1:{ prop1: 'prop1' }, module2:{ prop2: 'prop2' }};
|
|
21
|
+
const configuration = await Configuration( getAdapter( config ));
|
|
22
|
+
expect( configuration.getModuleConfig( 'module1', S.shape({ prop1: S.string() }))).toEqual({ prop1: 'prop1' });
|
|
23
|
+
expect( configuration.getModuleConfig( 'module2', S.shape({ prop2: S.string() }))).toEqual({ prop2: 'prop2' });
|
|
24
|
+
});
|
|
25
|
+
it( 'throws when module not found', done => {
|
|
26
|
+
const config = { module1:{ prop1: 'prop1' }, module2:{ prop2: 'prop2' }};
|
|
27
|
+
Configuration( getAdapter( config ))
|
|
28
|
+
.then( configuration=>{
|
|
29
|
+
expect( configuration.getModuleConfig( 'module3', S.shape({ prop1: S.string() }))).toThrow( /Configuration not available/ );
|
|
30
|
+
})
|
|
31
|
+
.catch(() => done());
|
|
32
|
+
});
|
|
33
|
+
it( 'returns {} when optional module not found', async () => {
|
|
34
|
+
const config = { module1:{ prop1: 'prop1' }, module2:{ prop2: 'prop2' }};
|
|
35
|
+
const configuration = await Configuration( getAdapter( config ));
|
|
36
|
+
expect( configuration.getModuleConfig( 'module3', S.shape({ prop1: S.string() }).optional())).toEqual({});
|
|
37
|
+
});
|
|
38
|
+
it( 'throws when schema does not match', done => {
|
|
39
|
+
const config = { module1:{ prop1: 'prop1' }, module2:{ prop2: 'prop2' }};
|
|
40
|
+
Configuration( getAdapter( config ))
|
|
41
|
+
.then( configuration=>{
|
|
42
|
+
expect( configuration.getModuleConfig( 'module1', S.shape({ prop2: S.string() }))).toThrow( /should have required property/ );
|
|
43
|
+
})
|
|
44
|
+
.catch(() => done());
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { omit } from 'ramda';
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import { mergeConfigProperty } from './common';
|
|
4
|
+
|
|
5
|
+
export const getYargs = () => yargs;
|
|
6
|
+
|
|
7
|
+
export const getYargsInit = () =>
|
|
8
|
+
yargs
|
|
9
|
+
.config()
|
|
10
|
+
.usage( 'Usage: $0 [Commands | Options]' )
|
|
11
|
+
.help( 'h' )
|
|
12
|
+
.alias( 'h', 'help' )
|
|
13
|
+
.array( 'modules' )
|
|
14
|
+
.alias( 'modules', 'm' )
|
|
15
|
+
.boolean( 'admin' )
|
|
16
|
+
.alias( 'admin', 's' )
|
|
17
|
+
.boolean( 'infrastructure' )
|
|
18
|
+
.alias( 'infrastructure', 'i' )
|
|
19
|
+
.boolean( 'requestAuthorization' )
|
|
20
|
+
.alias( 'requestAuthorization', 'r' )
|
|
21
|
+
.boolean( 'outbox' )
|
|
22
|
+
.alias( 'outbox', 'o' )
|
|
23
|
+
.describe( 'modules', 'Modules to load' )
|
|
24
|
+
.epilog( `copyright bett3r.dev ${new Date().getFullYear()}` );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export const formatArgs = async( config:Record<string,any> ) => {
|
|
28
|
+
const y = getYargsInit();
|
|
29
|
+
const args = await y.parseAsync();
|
|
30
|
+
return omit([ 'm', '$0', '_' ], args );
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const applyArgs = async ( config: Record<string, any> = {}) => {
|
|
34
|
+
const args = await formatArgs( config );
|
|
35
|
+
return {
|
|
36
|
+
config: mergeConfigProperty( config, args ),
|
|
37
|
+
args
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function mergeConfigProperty( configObj:any, newConfig:any ) {
|
|
2
|
+
if ( !newConfig ) return configObj;
|
|
3
|
+
Object.getOwnPropertyNames( newConfig ).forEach(( prop ) => {
|
|
4
|
+
if ( newConfig[prop] && typeof newConfig[prop] === 'object' && !Array.isArray( newConfig[prop])) {
|
|
5
|
+
configObj[prop] = configObj[prop] || {};
|
|
6
|
+
mergeConfigProperty( configObj[prop], newConfig[prop]);
|
|
7
|
+
} else{
|
|
8
|
+
configObj[prop] = newConfig[prop];
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
return configObj;
|
|
12
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ObjectSchema } from '@bett3r-dev/jsonschema-definer';
|
|
2
|
+
import { CliArgDefinition, CliCommandDefinition, ConfigurationAdapter, ConfigurationPort, ConfigurationPortEmitterEvents, TypedEventEmitter } from '@bett3r-dev/pv3-types';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import R from 'ramda';
|
|
5
|
+
import { Argv } from 'yargs';
|
|
6
|
+
import { validateSchema } from '../../libraries/validation';
|
|
7
|
+
import { createPort } from '../base';
|
|
8
|
+
import { applyArgs, getYargs } from './args';
|
|
9
|
+
import { getLocalConfig, getProjectRootConfig } from './localConfig';
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
namespace globalThis {
|
|
13
|
+
interface global{
|
|
14
|
+
appRoot: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const appRoot = process.env.APP_ROOT_DIR || global.appRoot || process.cwd() || path.dirname( require.main?.filename || '' );
|
|
20
|
+
|
|
21
|
+
//*******************************************
|
|
22
|
+
// Public interface
|
|
23
|
+
//*******************************************
|
|
24
|
+
|
|
25
|
+
type AppConfig = Record<string, any>;
|
|
26
|
+
|
|
27
|
+
export const Configuration = ( ...adapters: ConfigurationAdapter[]): Promise<ConfigurationPort> => {
|
|
28
|
+
let _config: AppConfig;
|
|
29
|
+
let _args: Record<string, any> = {};
|
|
30
|
+
|
|
31
|
+
const applyAdapters = ( config: AppConfig ): Promise<AppConfig> => {
|
|
32
|
+
return ( adapters || []).reduce(
|
|
33
|
+
( success, adapter ) => success.then( adapter.applyConfig ), Promise.resolve( config )
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const _getConfig = () : Promise<AppConfig> =>
|
|
38
|
+
_config
|
|
39
|
+
? Promise.resolve( _config )
|
|
40
|
+
: getProjectRootConfig( appRoot )
|
|
41
|
+
.then(( rootConfig ) => getLocalConfig( appRoot, './config', rootConfig ))
|
|
42
|
+
.then( applyAdapters )
|
|
43
|
+
.then( config=> _config = config );
|
|
44
|
+
|
|
45
|
+
const getModuleConfig = <T extends Record<string,any>>( configPath:string, schema: ObjectSchema<T> ) =>{
|
|
46
|
+
const moduleConfig = R.path( configPath.split( '.' ), _config ) as T;
|
|
47
|
+
if ( !moduleConfig ) {
|
|
48
|
+
if ( schema.isRequired )
|
|
49
|
+
throw Error( `Configuration not available for ${configPath}` );
|
|
50
|
+
// return { config: {} as T, onArgsApplied: () => {} };
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
config: validateSchema( schema, true )( moduleConfig || {}),
|
|
54
|
+
onArgsApplied: ( callback: ( config: T ) => void ) => {
|
|
55
|
+
config.emitter.on( 'argsApplied', ({ config }) => {
|
|
56
|
+
callback( R.path( configPath.split( '.' ), config ) as T );
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const applyCLIArgs = async () => {
|
|
63
|
+
const appliedArgs = await applyArgs( _config );
|
|
64
|
+
config.emitter.emit( 'argsApplied', appliedArgs );
|
|
65
|
+
_config = appliedArgs.config;
|
|
66
|
+
_args = appliedArgs.args;
|
|
67
|
+
return config;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const getArgs = async () => {
|
|
71
|
+
await applyCLIArgs();
|
|
72
|
+
return _args;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const configureCliArg = ( options: CliArgDefinition, yargs?: Argv ) => {
|
|
76
|
+
const args = yargs || getYargs();
|
|
77
|
+
args[options['type'] as any]( options['name']);
|
|
78
|
+
options.alias && args.alias( options['name'], options['alias']);
|
|
79
|
+
options.default && args.default( options['name'], options['default']);
|
|
80
|
+
options.description && args.describe( options['name'], options['description']);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const configureCliCommand = ( options: CliCommandDefinition ) => {
|
|
84
|
+
const args = getYargs();
|
|
85
|
+
args.command([ options.name, options.alias || '' ].filter( n => !!n ), options.description || '', ( yargs ) => {
|
|
86
|
+
options.arguments && options.arguments.forEach(( arg ) => {
|
|
87
|
+
yargs.positional( arg.name, arg );
|
|
88
|
+
});
|
|
89
|
+
return yargs;
|
|
90
|
+
}, options.handler );
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const config: ConfigurationPort = createPort({
|
|
94
|
+
_getConfig: () => _config,
|
|
95
|
+
getModules: () => _config.modules,
|
|
96
|
+
getArgs,
|
|
97
|
+
applyArgs: applyCLIArgs,
|
|
98
|
+
getModuleConfig,
|
|
99
|
+
configureCliArg,
|
|
100
|
+
configureCliCommand,
|
|
101
|
+
emitter: new TypedEventEmitter<ConfigurationPortEmitterEvents>()
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return _getConfig()
|
|
105
|
+
.then(( _config ) => {
|
|
106
|
+
config.isStarted = true;
|
|
107
|
+
config.emitter.emit( 'started' );
|
|
108
|
+
return config;
|
|
109
|
+
});
|
|
110
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import * as glob from 'glob';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { always } from 'ramda';
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
import { mergeConfigProperty } from './common';
|
|
8
|
+
|
|
9
|
+
type LocalConfigOptions = {
|
|
10
|
+
configFolder: string
|
|
11
|
+
configFilePattern: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const environment = process.env.NODE_ENV || 'development';
|
|
15
|
+
|
|
16
|
+
const readFile = promisify( fs.readFile );
|
|
17
|
+
function searchFile( folder: string, pattern: string ) {
|
|
18
|
+
const files = glob.globSync( pattern, { cwd: folder });
|
|
19
|
+
if ( files && files.length && files[0]) return files[0];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const createDefaultConfigFile = ( folder:string ) => ( content: any ) => {
|
|
23
|
+
Promise.resolve();
|
|
24
|
+
return promisify( fs.writeFile )( path.join( folder, 'default.yaml' ), yaml.dump( content, {
|
|
25
|
+
indent: 2,
|
|
26
|
+
sortKeys: true,
|
|
27
|
+
}))
|
|
28
|
+
.then( always( content ));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function getFileContent( fileName: string ) {
|
|
32
|
+
if ([ '.js', '.json' ].includes( path.extname( fileName ))) {
|
|
33
|
+
return import( fileName );
|
|
34
|
+
} else if ([ '.yaml', '.yml' ].includes( path.extname( fileName ))) {
|
|
35
|
+
return readFile( fileName, 'utf8' ).then(
|
|
36
|
+
( file ) => yaml.load( file, { json: true })
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
return Promise.reject(
|
|
40
|
+
Error( `Unkown config file type for file ${fileName}.` )
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const getProjectRootConfig = ( appRoot: string ) => {
|
|
46
|
+
do {
|
|
47
|
+
appRoot = path.dirname( appRoot );
|
|
48
|
+
const rootProjectFolder = path.join( appRoot, '.esas.config.json' );
|
|
49
|
+
if ( fs.existsSync( rootProjectFolder )) {
|
|
50
|
+
return getLocalConfig( appRoot );
|
|
51
|
+
}
|
|
52
|
+
} while ( appRoot !== '/' );
|
|
53
|
+
return Promise.resolve({});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export function getLocalConfig( appRoot: string, configFolder = './config', initialConfig = {}, forceCreateDefaultConfigFile = false ) {
|
|
57
|
+
const options: LocalConfigOptions = {
|
|
58
|
+
configFolder: path.join( appRoot, configFolder ),
|
|
59
|
+
configFilePattern: '*+(c|C)onfig.+(js|json|yaml|yml)',
|
|
60
|
+
};
|
|
61
|
+
let defaultConfigFile = searchFile(
|
|
62
|
+
options.configFolder,
|
|
63
|
+
'default.+(js|json|yaml|yml)'
|
|
64
|
+
);
|
|
65
|
+
let defaultConfigPromise: Promise<any> = Promise.resolve();
|
|
66
|
+
return (
|
|
67
|
+
!defaultConfigFile && forceCreateDefaultConfigFile
|
|
68
|
+
? defaultConfigPromise
|
|
69
|
+
.then( createDefaultConfigFile( path.join( appRoot, '/config' )))
|
|
70
|
+
:
|
|
71
|
+
defaultConfigPromise
|
|
72
|
+
.then(() => !defaultConfigFile ? {} : getFileContent( path.join( options.configFolder, defaultConfigFile as string )))
|
|
73
|
+
.then(( defaultConfig ) => mergeConfigProperty( initialConfig, defaultConfig ))
|
|
74
|
+
)
|
|
75
|
+
.then( async ( configObj ) => {
|
|
76
|
+
let localConfigFile = searchFile(
|
|
77
|
+
options.configFolder,
|
|
78
|
+
'local.+(js|json|yaml|yml)'
|
|
79
|
+
);
|
|
80
|
+
if ( localConfigFile ) {
|
|
81
|
+
localConfigFile = path.join( options.configFolder, localConfigFile );
|
|
82
|
+
configObj = mergeConfigProperty(
|
|
83
|
+
configObj,
|
|
84
|
+
await getFileContent( localConfigFile )
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
let environmentFileName = searchFile(
|
|
88
|
+
options.configFolder,
|
|
89
|
+
`${environment}.+(js|json|yaml|yml)`
|
|
90
|
+
);
|
|
91
|
+
if ( environmentFileName ) {
|
|
92
|
+
environmentFileName = path.join(
|
|
93
|
+
options.configFolder,
|
|
94
|
+
environmentFileName
|
|
95
|
+
);
|
|
96
|
+
configObj = mergeConfigProperty(
|
|
97
|
+
configObj,
|
|
98
|
+
await getFileContent( environmentFileName )
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
let environmentFileLocalName = searchFile(
|
|
102
|
+
options.configFolder,
|
|
103
|
+
`local-${environment}.+(js|json|yaml|yml)`
|
|
104
|
+
);
|
|
105
|
+
if ( environmentFileLocalName ) {
|
|
106
|
+
environmentFileLocalName = path.join(
|
|
107
|
+
options.configFolder,
|
|
108
|
+
environmentFileLocalName
|
|
109
|
+
);
|
|
110
|
+
configObj = mergeConfigProperty(
|
|
111
|
+
configObj,
|
|
112
|
+
await getFileContent( environmentFileLocalName )
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return configObj;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AppError } from '../../utils';
|
|
2
|
+
import { createPort } from '../base';
|
|
3
|
+
import { DatabaseAdapter, DatabasePort } from '@bett3r-dev/pv3-types';
|
|
4
|
+
import S from '@bett3r-dev/jsonschema-definer';
|
|
5
|
+
|
|
6
|
+
export const DuplicatedValueInIndex = () => AppError({
|
|
7
|
+
error: 'NotUniqueError',
|
|
8
|
+
description: 'Duplicated values for Index marked as Unique',
|
|
9
|
+
schema: S.shape({}).additionalProperties( true ),
|
|
10
|
+
type: 'ConflictError',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const Database = ( adapter: DatabaseAdapter ): DatabasePort => {
|
|
14
|
+
const database = Object.assign(
|
|
15
|
+
createPort( adapter ),
|
|
16
|
+
{ _adapter: adapter },
|
|
17
|
+
);
|
|
18
|
+
adapter.start()
|
|
19
|
+
.then(() => {
|
|
20
|
+
database.isStarted = true;
|
|
21
|
+
database.emitter.emit( 'started' );
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return database;
|
|
25
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Configuration } from '@bett3r-dev/pv3';
|
|
2
|
+
import { ConfigurationPort } from '@bett3r-dev/pv3-types';
|
|
3
|
+
import { Endpoints } from '../index';
|
|
4
|
+
import { create } from './test-client-library';
|
|
5
|
+
|
|
6
|
+
describe( 'Endpoints', () => {
|
|
7
|
+
let configuration: ConfigurationPort;
|
|
8
|
+
beforeAll( async() => {
|
|
9
|
+
configuration = await Configuration();
|
|
10
|
+
});
|
|
11
|
+
it( 'should be defined', async () => {
|
|
12
|
+
const endpoints = Endpoints({ packageJson:{ name: 'test', version: '3' }, configuration });
|
|
13
|
+
const clientLibrary = create({ baseUrl: '' }, endpoints.fetch );
|
|
14
|
+
const response = await clientLibrary.commands.AssignFlowGroup({
|
|
15
|
+
id: 'asdf',
|
|
16
|
+
body: {},
|
|
17
|
+
query: {}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/** OneOf type helpers */
|
|
2
|
+
export type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
3
|
+
export type XOR<T, U> = ( T | U ) extends object ? ( Without<T, U> & U ) | ( Without<U, T> & T ) : T | U;
|
|
4
|
+
export type OneOf<T extends any[]> = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR<A, B>, ...Rest]> : never;
|
|
5
|
+
|
|
6
|
+
export type BackendConfig = {
|
|
7
|
+
baseUrl: string,
|
|
8
|
+
token?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type EventMetadata = {
|
|
12
|
+
causationId?: string | undefined;
|
|
13
|
+
correlationId?: string | undefined;
|
|
14
|
+
user?: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CommittedEvent<Payload = any> = {
|
|
18
|
+
name: string,
|
|
19
|
+
data?: Payload,
|
|
20
|
+
stream: string
|
|
21
|
+
metadata: EventMetadata
|
|
22
|
+
id: number
|
|
23
|
+
timestamp: string
|
|
24
|
+
version: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type CommandParams<Body=any> = {
|
|
28
|
+
id: string,
|
|
29
|
+
query?: {
|
|
30
|
+
expectedVersion?: string
|
|
31
|
+
correlationId?: string
|
|
32
|
+
},
|
|
33
|
+
body?: Body
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type CommandExecutionResponse<Model = any, Event = any> = {
|
|
37
|
+
state?: Model,
|
|
38
|
+
events: CommittedEvent<Event>[]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ReadModelChange<T = any> = {
|
|
42
|
+
type: 'insert' | 'update' | 'delete',
|
|
43
|
+
data: T
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type QueryParams<Query=any,Params=any> = {
|
|
47
|
+
// params?: Partial<Params>,
|
|
48
|
+
query?: Partial<Query>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type FetchResponse<T = any> = Response & {
|
|
52
|
+
bodyParsed: T
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type Document = {
|
|
56
|
+
id: string | number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type QueryFilter<Model extends Document = any> = {
|
|
60
|
+
field: keyof Model;
|
|
61
|
+
op: 'eq' | 'neq' | 'lt' | 'gt' | 'lte' | 'gte' | 'in' | 'nin' | 'contains' | 'notContains' | 'some' | 'every' | 'exists'| 'notExists';
|
|
62
|
+
value: any;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type QuerySort<Model extends Document = any> = {
|
|
66
|
+
field: keyof Model;
|
|
67
|
+
direction?: 'asc' | 'desc';
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type ReadModelQueryBase<Model extends Document = any> = {
|
|
71
|
+
access_token?: string;
|
|
72
|
+
apikey?: string;
|
|
73
|
+
limit?: number;
|
|
74
|
+
after?: string | number;
|
|
75
|
+
sort?: QuerySort<Model>[];
|
|
76
|
+
filter?: QueryFilter<Model>[];
|
|
77
|
+
select?: keyof Model | ( keyof Model )[]
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const parseResponseBody = ( type:'json'|'text' ,response: Response, method: 'reject'| 'resolve' ): Promise<void|FetchResponse> =>{
|
|
81
|
+
return response[type]()
|
|
82
|
+
.then(( bodyParsed ) => {
|
|
83
|
+
return Promise[method]( Object.assign( response, {
|
|
84
|
+
bodyParsed
|
|
85
|
+
}) as FetchResponse );
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
export const processFetchResponse = <T = any>( response: Response ): Promise<void|FetchResponse<T>> =>{
|
|
89
|
+
if ( response.ok === true )
|
|
90
|
+
return parseResponseBody( 'json', response, 'resolve' );
|
|
91
|
+
else
|
|
92
|
+
return parseResponseBody( 'json', response, 'reject' );
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const processQueryPropertyMap = {
|
|
96
|
+
filter: ( filter: QueryFilter[], params: URLSearchParams )=>{
|
|
97
|
+
return filter.reduce(( acc, filterItem ) => {
|
|
98
|
+
acc.append( 'filter', `${filterItem.field as string},${filterItem.op},${filterItem.value}` );
|
|
99
|
+
return acc;
|
|
100
|
+
}, params );
|
|
101
|
+
},
|
|
102
|
+
sort: ( sort: QuerySort[], params: URLSearchParams )=>{
|
|
103
|
+
return sort.reduce(( acc, sortItem ) => {
|
|
104
|
+
acc.append( 'sort', `${sortItem.field as string},${sortItem.direction || 'asc'}` );
|
|
105
|
+
return acc;
|
|
106
|
+
}, params );
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const parseQueryParams = ( query?: Record<string, any> ) =>{
|
|
111
|
+
if ( query && Object.keys( query ).length ){
|
|
112
|
+
return Object.keys( query ).reduce(( acc, key ) => {
|
|
113
|
+
if ([ 'filter', 'sort' ].includes( key )){
|
|
114
|
+
return processQueryPropertyMap[key as keyof typeof processQueryPropertyMap]( query[key], acc );
|
|
115
|
+
} else if ( Array.isArray( query[key])){
|
|
116
|
+
( query[key] as string[]).forEach(( value ) => acc.append( key, value ));
|
|
117
|
+
return acc;
|
|
118
|
+
} else {
|
|
119
|
+
acc.append( key, query[key]);
|
|
120
|
+
}
|
|
121
|
+
return acc;
|
|
122
|
+
}, new URLSearchParams());
|
|
123
|
+
}
|
|
124
|
+
return '';
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type Requests = ReturnType<typeof requests>;
|
|
128
|
+
export const requests = ( params: BackendConfig, _fetch = fetch ) => {
|
|
129
|
+
const defaultHeaders = {
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
'Authorization': `Bearer ${params.token}`
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const post = ( path: string, body?: any, headers: Record<string, string> = {}) => {
|
|
135
|
+
return _fetch( `${params.baseUrl}${path}`, { method: 'post',
|
|
136
|
+
headers: { ...defaultHeaders, ...headers }, ...( body
|
|
137
|
+
? { body: JSON.stringify( body ) }
|
|
138
|
+
: {}),
|
|
139
|
+
})
|
|
140
|
+
.then( processFetchResponse )
|
|
141
|
+
.then(( response: FetchResponse | void ) => { return response?.bodyParsed; });
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const get = ( path: string, headers: Record<string, string> = {}) => {
|
|
145
|
+
return _fetch( `${params.baseUrl}${path}`, { method: 'get',
|
|
146
|
+
headers: { ...defaultHeaders, ...headers }, })
|
|
147
|
+
.then( processFetchResponse )
|
|
148
|
+
.then(( response: FetchResponse | void ) => { return response?.bodyParsed; });
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const subscribe = ( path:string, name: string, onChange: ( change: ReadModelChange )=>void ) => {
|
|
152
|
+
console.log( `Stablishing connection with subscription ${name}...` );
|
|
153
|
+
const source = new EventSource( `${params.baseUrl}${path}` );
|
|
154
|
+
source.addEventListener( 'open', ( e ) => console.log( `Connections to the server established for subscription ${name}` ), false );
|
|
155
|
+
source.onmessage = ( e ) => {
|
|
156
|
+
if ( e.data === 'Connected' ) return;
|
|
157
|
+
onChange( JSON.parse( e.data ));
|
|
158
|
+
};
|
|
159
|
+
return source.close.bind( source );
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
post,
|
|
164
|
+
get,
|
|
165
|
+
subscribe
|
|
166
|
+
};
|
|
167
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BackendConfig, requests, CommandParams } from './base';
|
|
2
|
+
import * as service from './services/service';
|
|
3
|
+
export * as service from './services/service';
|
|
4
|
+
// TODO: Export service as service
|
|
5
|
+
|
|
6
|
+
export { CommandParams, BackendConfig };
|
|
7
|
+
|
|
8
|
+
export const create = ( params: BackendConfig, fetch?: any ) => {
|
|
9
|
+
const req = requests( params, fetch );
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
commands: {
|
|
13
|
+
...service.commands( req, params ),
|
|
14
|
+
|
|
15
|
+
},queries: {
|
|
16
|
+
...service.queries( req, params ),
|
|
17
|
+
|
|
18
|
+
},subscriptions: {
|
|
19
|
+
...service.subscriptions( req, params ),
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|