@fougere/core 0.2.0-alpha.2 → 0.4.0-alpha.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/README.md +3 -2
- package/dist/boot/AppLifecycle.d.ts +18 -0
- package/dist/boot/AppLifecycle.d.ts.map +1 -0
- package/dist/boot/AppLifecycle.js +42 -0
- package/dist/boot/AppLifecycle.js.map +1 -0
- package/dist/boot/Emissions.d.ts +126 -0
- package/dist/boot/Emissions.d.ts.map +1 -0
- package/dist/boot/Emissions.js +233 -0
- package/dist/boot/Emissions.js.map +1 -0
- package/dist/boot/HandlerFacade.d.ts +72 -0
- package/dist/boot/HandlerFacade.d.ts.map +1 -0
- package/dist/boot/HandlerFacade.js +174 -0
- package/dist/boot/HandlerFacade.js.map +1 -0
- package/dist/boot/Lifecycle.d.ts +4 -0
- package/dist/boot/Lifecycle.d.ts.map +1 -0
- package/dist/boot/Lifecycle.js +3 -0
- package/dist/boot/Lifecycle.js.map +1 -0
- package/dist/boot/ambient-port.d.ts +38 -0
- package/dist/boot/ambient-port.d.ts.map +1 -0
- package/dist/boot/ambient-port.js +2 -0
- package/dist/boot/ambient-port.js.map +1 -0
- package/dist/boot/ambient.als.d.ts +3 -0
- package/dist/boot/ambient.als.d.ts.map +1 -0
- package/dist/boot/ambient.als.js +34 -0
- package/dist/boot/ambient.als.js.map +1 -0
- package/dist/boot/ambient.queue.d.ts +10 -0
- package/dist/boot/ambient.queue.d.ts.map +1 -0
- package/dist/boot/ambient.queue.js +60 -0
- package/dist/boot/ambient.queue.js.map +1 -0
- package/dist/boot/apply.d.ts +22 -0
- package/dist/boot/apply.d.ts.map +1 -0
- package/dist/boot/apply.js +38 -0
- package/dist/boot/apply.js.map +1 -0
- package/dist/boot/auth.d.ts +53 -0
- package/dist/boot/auth.d.ts.map +1 -0
- package/dist/boot/auth.js +2 -0
- package/dist/boot/auth.js.map +1 -0
- package/dist/{binding.d.ts → boot/binding.d.ts} +14 -17
- package/dist/boot/binding.d.ts.map +1 -0
- package/dist/{binding.js → boot/binding.js} +19 -10
- package/dist/boot/binding.js.map +1 -0
- package/dist/{boot.d.ts → boot/boot.d.ts} +25 -5
- package/dist/boot/boot.d.ts.map +1 -0
- package/dist/boot/boot.js +70 -0
- package/dist/boot/boot.js.map +1 -0
- package/dist/boot/bootstrap.d.ts.map +1 -0
- package/dist/boot/bootstrap.js +722 -0
- package/dist/boot/bootstrap.js.map +1 -0
- package/dist/boot/frame.d.ts +44 -0
- package/dist/boot/frame.d.ts.map +1 -0
- package/dist/boot/frame.js +172 -0
- package/dist/boot/frame.js.map +1 -0
- package/dist/boot/ownership.d.ts +42 -0
- package/dist/boot/ownership.d.ts.map +1 -0
- package/dist/boot/ownership.js +127 -0
- package/dist/boot/ownership.js.map +1 -0
- package/dist/boot/ports.d.ts +17 -0
- package/dist/boot/ports.d.ts.map +1 -0
- package/dist/boot/ports.js +57 -0
- package/dist/boot/ports.js.map +1 -0
- package/dist/{remote.d.ts → boot/remote.d.ts} +11 -3
- package/dist/boot/remote.d.ts.map +1 -0
- package/dist/{remote.js → boot/remote.js} +26 -28
- package/dist/boot/remote.js.map +1 -0
- package/dist/{seed.d.ts → boot/seed.d.ts} +13 -1
- package/dist/boot/seed.d.ts.map +1 -0
- package/dist/{seed.js → boot/seed.js} +24 -3
- package/dist/boot/seed.js.map +1 -0
- package/dist/boot/together.d.ts +26 -0
- package/dist/boot/together.d.ts.map +1 -0
- package/dist/boot/together.js +163 -0
- package/dist/boot/together.js.map +1 -0
- package/dist/boot/types.d.ts +260 -0
- package/dist/boot/types.d.ts.map +1 -0
- package/dist/boot/types.js.map +1 -0
- package/dist/builtins/config.d.ts +9 -0
- package/dist/builtins/config.d.ts.map +1 -1
- package/dist/builtins/config.js +16 -1
- package/dist/builtins/config.js.map +1 -1
- package/dist/builtins/logger.d.ts +37 -4
- package/dist/builtins/logger.d.ts.map +1 -1
- package/dist/builtins/logger.js +66 -7
- package/dist/builtins/logger.js.map +1 -1
- package/dist/config-loader.d.ts +39 -35
- package/dist/config-loader.d.ts.map +1 -1
- package/dist/config-loader.js +15 -54
- package/dist/config-loader.js.map +1 -1
- package/dist/contract/Call.d.ts +10 -0
- package/dist/contract/Call.d.ts.map +1 -0
- package/dist/contract/Call.js +15 -0
- package/dist/contract/Call.js.map +1 -0
- package/dist/contract/Invocation.d.ts +27 -0
- package/dist/contract/Invocation.d.ts.map +1 -0
- package/dist/contract/Invocation.js +59 -0
- package/dist/contract/Invocation.js.map +1 -0
- package/dist/contract/RouteAddress.d.ts +17 -0
- package/dist/contract/RouteAddress.d.ts.map +1 -0
- package/dist/contract/RouteAddress.js +38 -0
- package/dist/contract/RouteAddress.js.map +1 -0
- package/dist/contract.d.ts +25 -19
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +25 -10
- package/dist/contract.js.map +1 -1
- package/dist/crypto/encoding.d.ts +25 -0
- package/dist/crypto/encoding.d.ts.map +1 -0
- package/dist/crypto/encoding.js +58 -0
- package/dist/crypto/encoding.js.map +1 -0
- package/dist/crypto/node.d.ts +4 -0
- package/dist/crypto/node.d.ts.map +1 -0
- package/dist/crypto/node.js +25 -0
- package/dist/crypto/node.js.map +1 -0
- package/dist/crypto/port.d.ts +42 -0
- package/dist/crypto/port.d.ts.map +1 -0
- package/dist/crypto/port.js +19 -0
- package/dist/crypto/port.js.map +1 -0
- package/dist/crypto/webcrypto.d.ts +4 -0
- package/dist/crypto/webcrypto.d.ts.map +1 -0
- package/dist/crypto/webcrypto.js +34 -0
- package/dist/crypto/webcrypto.js.map +1 -0
- package/dist/dispatch/ArgumentResolver.d.ts +10 -0
- package/dist/dispatch/ArgumentResolver.d.ts.map +1 -0
- package/dist/dispatch/ArgumentResolver.js +12 -0
- package/dist/dispatch/ArgumentResolver.js.map +1 -0
- package/dist/dispatch/ArrayResult.d.ts +3 -0
- package/dist/dispatch/ArrayResult.d.ts.map +1 -0
- package/dist/dispatch/ArrayResult.js +11 -0
- package/dist/dispatch/ArrayResult.js.map +1 -0
- package/dist/dispatch/DispatchEvent.d.ts +18 -0
- package/dist/dispatch/DispatchEvent.d.ts.map +1 -0
- package/dist/dispatch/DispatchEvent.js +30 -0
- package/dist/dispatch/DispatchEvent.js.map +1 -0
- package/dist/dispatch/DispatchLifecycle.d.ts +9 -0
- package/dist/dispatch/DispatchLifecycle.d.ts.map +1 -0
- package/dist/dispatch/DispatchLifecycle.js +25 -0
- package/dist/dispatch/DispatchLifecycle.js.map +1 -0
- package/dist/dispatch/DispatchPort.d.ts +6 -0
- package/dist/dispatch/DispatchPort.d.ts.map +1 -0
- package/dist/dispatch/DispatchPort.js +2 -0
- package/dist/dispatch/DispatchPort.js.map +1 -0
- package/dist/dispatch/Dispatcher.d.ts +16 -0
- package/dist/dispatch/Dispatcher.d.ts.map +1 -0
- package/dist/dispatch/Dispatcher.js +44 -0
- package/dist/dispatch/Dispatcher.js.map +1 -0
- package/dist/dispatch/InFlight.d.ts +12 -0
- package/dist/dispatch/InFlight.d.ts.map +1 -0
- package/dist/dispatch/InFlight.js +46 -0
- package/dist/dispatch/InFlight.js.map +1 -0
- package/dist/dispatch/InputValidator.d.ts +7 -0
- package/dist/dispatch/InputValidator.d.ts.map +1 -0
- package/dist/dispatch/InputValidator.js +22 -0
- package/dist/dispatch/InputValidator.js.map +1 -0
- package/dist/dispatch/LocalRoutePolicy.d.ts +11 -0
- package/dist/dispatch/LocalRoutePolicy.d.ts.map +1 -0
- package/dist/dispatch/LocalRoutePolicy.js +32 -0
- package/dist/dispatch/LocalRoutePolicy.js.map +1 -0
- package/dist/dispatch/OperationExecutor.d.ts +25 -0
- package/dist/dispatch/OperationExecutor.d.ts.map +1 -0
- package/dist/dispatch/OperationExecutor.js +32 -0
- package/dist/dispatch/OperationExecutor.js.map +1 -0
- package/dist/dispatch/OperationRoute.d.ts +13 -0
- package/dist/dispatch/OperationRoute.d.ts.map +1 -0
- package/dist/dispatch/OperationRoute.js +15 -0
- package/dist/dispatch/OperationRoute.js.map +1 -0
- package/dist/dispatch/OutputProjector.d.ts +12 -0
- package/dist/dispatch/OutputProjector.d.ts.map +1 -0
- package/dist/dispatch/OutputProjector.js +30 -0
- package/dist/dispatch/OutputProjector.js.map +1 -0
- package/dist/dispatch/OutputView.d.ts +8 -0
- package/dist/dispatch/OutputView.d.ts.map +1 -0
- package/dist/dispatch/OutputView.js +10 -0
- package/dist/dispatch/OutputView.js.map +1 -0
- package/dist/dispatch/PresenterArgumentResolver.d.ts +12 -0
- package/dist/dispatch/PresenterArgumentResolver.d.ts.map +1 -0
- package/dist/dispatch/PresenterArgumentResolver.js +20 -0
- package/dist/dispatch/PresenterArgumentResolver.js.map +1 -0
- package/dist/dispatch/PresenterExecutor.d.ts +11 -0
- package/dist/dispatch/PresenterExecutor.d.ts.map +1 -0
- package/dist/dispatch/PresenterExecutor.js +56 -0
- package/dist/dispatch/PresenterExecutor.js.map +1 -0
- package/dist/dispatch/RemoteRouteResolver.d.ts +13 -0
- package/dist/dispatch/RemoteRouteResolver.d.ts.map +1 -0
- package/dist/dispatch/RemoteRouteResolver.js +18 -0
- package/dist/dispatch/RemoteRouteResolver.js.map +1 -0
- package/dist/dispatch/Route.d.ts +10 -0
- package/dist/dispatch/Route.d.ts.map +1 -0
- package/dist/dispatch/Route.js +2 -0
- package/dist/dispatch/Route.js.map +1 -0
- package/dist/dispatch/RouteNotFoundError.d.ts +10 -0
- package/dist/dispatch/RouteNotFoundError.d.ts.map +1 -0
- package/dist/dispatch/RouteNotFoundError.js +24 -0
- package/dist/dispatch/RouteNotFoundError.js.map +1 -0
- package/dist/dispatch/RoutePolicy.d.ts +8 -0
- package/dist/dispatch/RoutePolicy.d.ts.map +1 -0
- package/dist/dispatch/RoutePolicy.js +2 -0
- package/dist/dispatch/RoutePolicy.js.map +1 -0
- package/dist/dispatch/RouteRegistry.d.ts +18 -0
- package/dist/dispatch/RouteRegistry.d.ts.map +1 -0
- package/dist/dispatch/RouteRegistry.js +62 -0
- package/dist/dispatch/RouteRegistry.js.map +1 -0
- package/dist/dispatch/RouteResolver.d.ts +7 -0
- package/dist/dispatch/RouteResolver.d.ts.map +1 -0
- package/dist/dispatch/RouteResolver.js +2 -0
- package/dist/dispatch/RouteResolver.js.map +1 -0
- package/dist/dispatch/StorageGuard.d.ts +15 -0
- package/dist/dispatch/StorageGuard.d.ts.map +1 -0
- package/dist/dispatch/StorageGuard.js +63 -0
- package/dist/dispatch/StorageGuard.js.map +1 -0
- package/dist/effective-operation.d.ts +90 -0
- package/dist/effective-operation.d.ts.map +1 -0
- package/dist/effective-operation.js +449 -0
- package/dist/effective-operation.js.map +1 -0
- package/dist/emit.d.ts +2 -2
- package/dist/emit.d.ts.map +1 -1
- package/dist/emit.js +2 -2
- package/dist/emit.js.map +1 -1
- package/dist/entry/DynamicFacade.d.ts +10 -0
- package/dist/entry/DynamicFacade.d.ts.map +1 -0
- package/dist/entry/DynamicFacade.js +27 -0
- package/dist/entry/DynamicFacade.js.map +1 -0
- package/dist/entry/FacadeEntry.d.ts +11 -0
- package/dist/entry/FacadeEntry.d.ts.map +1 -0
- package/dist/entry/FacadeEntry.js +26 -0
- package/dist/entry/FacadeEntry.js.map +1 -0
- package/dist/entry/TransportEntry.d.ts +13 -0
- package/dist/entry/TransportEntry.d.ts.map +1 -0
- package/dist/entry/TransportEntry.js +24 -0
- package/dist/entry/TransportEntry.js.map +1 -0
- package/dist/frond-config.d.ts +24 -7
- package/dist/frond-config.d.ts.map +1 -1
- package/dist/frond-config.js.map +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +3 -2
- package/dist/graph.js.map +1 -1
- package/dist/identity-keys.d.ts +14 -0
- package/dist/identity-keys.d.ts.map +1 -0
- package/dist/identity-keys.js +37 -0
- package/dist/identity-keys.js.map +1 -0
- package/dist/identity.d.ts +58 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +182 -0
- package/dist/identity.js.map +1 -0
- package/dist/imports.d.ts +2 -2
- package/dist/imports.d.ts.map +1 -1
- package/dist/imports.js +7 -3
- package/dist/imports.js.map +1 -1
- package/dist/index.d.ts +57 -38
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -32
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +16 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +25 -0
- package/dist/loader.js.map +1 -0
- package/dist/node.d.ts +21 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +24 -0
- package/dist/node.js.map +1 -0
- package/dist/orm.d.ts +69 -8
- package/dist/orm.d.ts.map +1 -1
- package/dist/orm.js +35 -2
- package/dist/orm.js.map +1 -1
- package/dist/prefab/collector.d.ts +29 -0
- package/dist/prefab/collector.d.ts.map +1 -0
- package/dist/prefab/collector.js +34 -0
- package/dist/prefab/collector.js.map +1 -0
- package/dist/{crud.d.ts → prefab/crud.d.ts} +7 -8
- package/dist/prefab/crud.d.ts.map +1 -0
- package/dist/{crud.js → prefab/crud.js} +39 -5
- package/dist/prefab/crud.js.map +1 -0
- package/dist/prefab/mirror.d.ts +52 -0
- package/dist/prefab/mirror.d.ts.map +1 -0
- package/dist/prefab/mirror.js +66 -0
- package/dist/prefab/mirror.js.map +1 -0
- package/dist/prefab/prefab.d.ts +15 -0
- package/dist/prefab/prefab.d.ts.map +1 -0
- package/dist/prefab/prefab.js +19 -0
- package/dist/prefab/prefab.js.map +1 -0
- package/dist/{presenter.d.ts → prefab/presenter.d.ts} +6 -17
- package/dist/prefab/presenter.d.ts.map +1 -0
- package/dist/{presenter.js → prefab/presenter.js} +5 -23
- package/dist/prefab/presenter.js.map +1 -0
- package/dist/prefab/repository.d.ts +104 -0
- package/dist/prefab/repository.d.ts.map +1 -0
- package/dist/prefab/repository.js +62 -0
- package/dist/prefab/repository.js.map +1 -0
- package/dist/scan/Fronds.d.ts +45 -0
- package/dist/scan/Fronds.d.ts.map +1 -0
- package/dist/scan/Fronds.js +66 -0
- package/dist/scan/Fronds.js.map +1 -0
- package/dist/scan/conventions.d.ts +74 -0
- package/dist/scan/conventions.d.ts.map +1 -0
- package/dist/scan/conventions.js +82 -0
- package/dist/scan/conventions.js.map +1 -0
- package/dist/scan/emit.d.ts +14 -0
- package/dist/scan/emit.d.ts.map +1 -0
- package/dist/scan/emit.js +212 -0
- package/dist/scan/emit.js.map +1 -0
- package/dist/scan/frond.d.ts +224 -0
- package/dist/scan/frond.d.ts.map +1 -0
- package/dist/scan/frond.js +2 -0
- package/dist/scan/frond.js.map +1 -0
- package/dist/{handler-parser.d.ts → scan/handler-parser.d.ts} +20 -9
- package/dist/scan/handler-parser.d.ts.map +1 -0
- package/dist/scan/handler-parser.js +665 -0
- package/dist/scan/handler-parser.js.map +1 -0
- package/dist/scan/scan-cache.d.ts +16 -0
- package/dist/scan/scan-cache.d.ts.map +1 -0
- package/dist/{scan-cache.js → scan/scan-cache.js} +27 -20
- package/dist/scan/scan-cache.js.map +1 -0
- package/dist/scan/scanner.d.ts +20 -0
- package/dist/scan/scanner.d.ts.map +1 -0
- package/dist/{scanner.js → scan/scanner.js} +212 -167
- package/dist/scan/scanner.js.map +1 -0
- package/dist/verify.d.ts +16 -3
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +21 -18
- package/dist/verify.js.map +1 -1
- package/dist/{call.d.ts → wire/call.d.ts} +76 -7
- package/dist/wire/call.d.ts.map +1 -0
- package/dist/{call.js → wire/call.js} +53 -80
- package/dist/wire/call.js.map +1 -0
- package/dist/{middleware.d.ts → wire/errors.d.ts} +18 -19
- package/dist/wire/errors.d.ts.map +1 -0
- package/dist/{middleware.js → wire/errors.js} +26 -14
- package/dist/wire/errors.js.map +1 -0
- package/dist/{errors.d.ts → wire/http-error.d.ts} +5 -6
- package/dist/wire/http-error.d.ts.map +1 -0
- package/dist/{errors.js → wire/http-error.js} +7 -6
- package/dist/wire/http-error.js.map +1 -0
- package/dist/wire/invocation.d.ts +4 -0
- package/dist/wire/invocation.d.ts.map +1 -0
- package/dist/wire/invocation.js +3 -0
- package/dist/wire/invocation.js.map +1 -0
- package/dist/{middleware/logger.d.ts → wire/loggerMiddleware.d.ts} +3 -3
- package/dist/wire/loggerMiddleware.d.ts.map +1 -0
- package/dist/{middleware/logger.js → wire/loggerMiddleware.js} +2 -2
- package/dist/wire/loggerMiddleware.js.map +1 -0
- package/dist/wire/middleware.d.ts +29 -0
- package/dist/wire/middleware.d.ts.map +1 -0
- package/dist/wire/middleware.js +20 -0
- package/dist/wire/middleware.js.map +1 -0
- package/dist/{operation.d.ts → wire/operation.d.ts} +39 -10
- package/dist/wire/operation.d.ts.map +1 -0
- package/dist/wire/operation.js +167 -0
- package/dist/wire/operation.js.map +1 -0
- package/package.json +27 -8
- package/src/boot/AppLifecycle.ts +50 -0
- package/src/boot/Emissions.ts +263 -0
- package/src/boot/HandlerFacade.ts +242 -0
- package/src/boot/Lifecycle.ts +3 -0
- package/src/boot/ambient-port.ts +41 -0
- package/src/boot/ambient.als.ts +43 -0
- package/src/boot/ambient.queue.ts +75 -0
- package/src/boot/apply.ts +47 -0
- package/src/boot/auth.ts +55 -0
- package/src/boot/binding.ts +182 -0
- package/src/boot/boot.ts +125 -0
- package/src/boot/bootstrap.ts +839 -0
- package/src/boot/frame.ts +210 -0
- package/src/boot/ownership.ts +140 -0
- package/src/boot/ports.ts +66 -0
- package/src/boot/remote.ts +179 -0
- package/src/boot/seed.ts +158 -0
- package/src/boot/together.ts +215 -0
- package/src/boot/types.ts +261 -0
- package/src/builtins/config.ts +19 -0
- package/src/builtins/logger.ts +175 -0
- package/src/config-loader.ts +146 -0
- package/src/contract/Call.ts +18 -0
- package/src/contract/Invocation.ts +72 -0
- package/src/contract/RouteAddress.ts +49 -0
- package/src/contract.ts +74 -0
- package/src/crypto/encoding.ts +59 -0
- package/src/crypto/node.ts +30 -0
- package/src/crypto/port.ts +45 -0
- package/src/crypto/webcrypto.ts +55 -0
- package/src/define.ts +10 -0
- package/src/dispatch/ArgumentResolver.ts +17 -0
- package/src/dispatch/ArrayResult.ts +10 -0
- package/src/dispatch/DispatchEvent.ts +38 -0
- package/src/dispatch/DispatchLifecycle.ts +23 -0
- package/src/dispatch/DispatchPort.ts +6 -0
- package/src/dispatch/Dispatcher.ts +48 -0
- package/src/dispatch/InFlight.ts +49 -0
- package/src/dispatch/InputValidator.ts +28 -0
- package/src/dispatch/LocalRoutePolicy.ts +34 -0
- package/src/dispatch/OperationExecutor.ts +60 -0
- package/src/dispatch/OperationRoute.ts +18 -0
- package/src/dispatch/OutputProjector.ts +32 -0
- package/src/dispatch/OutputView.ts +9 -0
- package/src/dispatch/PresenterArgumentResolver.ts +25 -0
- package/src/dispatch/PresenterExecutor.ts +55 -0
- package/src/dispatch/RemoteRouteResolver.ts +21 -0
- package/src/dispatch/Route.ts +11 -0
- package/src/dispatch/RouteNotFoundError.ts +29 -0
- package/src/dispatch/RoutePolicy.ts +8 -0
- package/src/dispatch/RouteRegistry.ts +73 -0
- package/src/dispatch/RouteResolver.ts +7 -0
- package/src/dispatch/StorageGuard.ts +71 -0
- package/src/effective-operation.ts +597 -0
- package/src/emit.ts +90 -0
- package/src/entry/DynamicFacade.ts +28 -0
- package/src/entry/FacadeEntry.ts +32 -0
- package/src/entry/TransportEntry.ts +30 -0
- package/src/frond-config.ts +138 -0
- package/src/graph.ts +180 -0
- package/src/identity-keys.ts +43 -0
- package/src/identity.ts +235 -0
- package/src/imports.ts +123 -0
- package/src/index.ts +106 -0
- package/src/loader.ts +41 -0
- package/src/node.ts +28 -0
- package/src/orm.ts +252 -0
- package/src/prefab/collector.ts +36 -0
- package/src/prefab/crud.ts +188 -0
- package/src/prefab/mirror.ts +122 -0
- package/src/prefab/prefab.ts +46 -0
- package/src/prefab/presenter.ts +63 -0
- package/src/prefab/repository.ts +170 -0
- package/src/scan/Fronds.ts +73 -0
- package/src/scan/conventions.ts +122 -0
- package/src/scan/emit.ts +231 -0
- package/src/scan/frond.ts +235 -0
- package/src/scan/handler-parser.ts +818 -0
- package/src/scan/scan-cache.ts +115 -0
- package/src/scan/scanner.ts +758 -0
- package/src/verify.ts +193 -0
- package/src/wire/call.ts +369 -0
- package/src/wire/errors.ts +124 -0
- package/src/wire/http-error.ts +77 -0
- package/src/wire/invocation.ts +10 -0
- package/src/wire/loggerMiddleware.ts +29 -0
- package/src/wire/middleware.ts +47 -0
- package/src/wire/operation.ts +258 -0
- package/dist/binding.d.ts.map +0 -1
- package/dist/binding.js.map +0 -1
- package/dist/boot.d.ts.map +0 -1
- package/dist/boot.js +0 -53
- package/dist/boot.js.map +0 -1
- package/dist/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap.js +0 -879
- package/dist/bootstrap.js.map +0 -1
- package/dist/call.d.ts.map +0 -1
- package/dist/call.js.map +0 -1
- package/dist/collector.d.ts +0 -28
- package/dist/collector.d.ts.map +0 -1
- package/dist/collector.js +0 -32
- package/dist/collector.js.map +0 -1
- package/dist/crud.d.ts.map +0 -1
- package/dist/crud.js.map +0 -1
- package/dist/egress.d.ts +0 -52
- package/dist/egress.d.ts.map +0 -1
- package/dist/egress.js +0 -186
- package/dist/egress.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/handler-parser.d.ts.map +0 -1
- package/dist/handler-parser.js +0 -505
- package/dist/handler-parser.js.map +0 -1
- package/dist/invocation.d.ts +0 -20
- package/dist/invocation.d.ts.map +0 -1
- package/dist/invocation.js +0 -15
- package/dist/invocation.js.map +0 -1
- package/dist/middleware/error-handler.d.ts +0 -15
- package/dist/middleware/error-handler.d.ts.map +0 -1
- package/dist/middleware/error-handler.js +0 -29
- package/dist/middleware/error-handler.js.map +0 -1
- package/dist/middleware/logger.d.ts.map +0 -1
- package/dist/middleware/logger.js.map +0 -1
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js.map +0 -1
- package/dist/mirror.d.ts +0 -93
- package/dist/mirror.d.ts.map +0 -1
- package/dist/mirror.js +0 -96
- package/dist/mirror.js.map +0 -1
- package/dist/operation.d.ts.map +0 -1
- package/dist/operation.js +0 -95
- package/dist/operation.js.map +0 -1
- package/dist/presenter.d.ts.map +0 -1
- package/dist/presenter.js.map +0 -1
- package/dist/remote.d.ts.map +0 -1
- package/dist/remote.js.map +0 -1
- package/dist/repository.d.ts +0 -55
- package/dist/repository.d.ts.map +0 -1
- package/dist/repository.js +0 -26
- package/dist/repository.js.map +0 -1
- package/dist/scan-cache.d.ts +0 -10
- package/dist/scan-cache.d.ts.map +0 -1
- package/dist/scan-cache.js.map +0 -1
- package/dist/scanner.d.ts +0 -34
- package/dist/scanner.d.ts.map +0 -1
- package/dist/scanner.js.map +0 -1
- package/dist/seed.d.ts.map +0 -1
- package/dist/seed.js.map +0 -1
- package/dist/types.d.ts +0 -421
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dist/{bootstrap.d.ts → boot/bootstrap.d.ts} +0 -0
- /package/dist/{types.js → boot/types.js} +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presenter(Entity) — enriches an entity's output with computed fields.
|
|
3
|
+
*
|
|
4
|
+
* Each method on the presenter is a computed field resolver:
|
|
5
|
+
* - Receives the entity record as first argument
|
|
6
|
+
* - Can be sync or async
|
|
7
|
+
* - Injected via DI (constructor params resolved by the container)
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* ```ts
|
|
11
|
+
* export default class PostPresenter extends Presenter(Post) {
|
|
12
|
+
* constructor(private commentOrm: CommentOrm) { super(); }
|
|
13
|
+
*
|
|
14
|
+
* excerpt(post: Post) {
|
|
15
|
+
* return post.body.slice(0, 200);
|
|
16
|
+
* }
|
|
17
|
+
*
|
|
18
|
+
* async commentCount(post: Post) {
|
|
19
|
+
* return this.commentOrm.countFor(post.id);
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { upperFirst, type EntityConstructor } from '@fougere/schema';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The view a computed field emits — `OrderItemView` for one, `[OrderItemView]` for many.
|
|
29
|
+
* A view is a schema, so it derives: `Order.pick('id', 'status')`, never a hand-written type.
|
|
30
|
+
*/
|
|
31
|
+
export type PresenterViews = Record<string, EntityConstructor | [EntityConstructor]>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `Presenter(Order, { items: [OrderItemView], user: UserCard })` — the second argument names
|
|
35
|
+
* the view each computed field emits, exactly as `Crud(Post, { list: PostCard })` names an
|
|
36
|
+
* op's. What fabricates a field declares its contract, and it declares it **once**: the
|
|
37
|
+
* façade applies the presenter (see `PresenterExecutor`), and every surface reads the same statement
|
|
38
|
+
* instead of guessing.
|
|
39
|
+
*
|
|
40
|
+
* Guessing was the cost of not stating it. The scan can read a scalar off a return type and
|
|
41
|
+
* nothing more, so a field returning an object had no derivable shape: the GraphQL projection
|
|
42
|
+
* fell back to a serialized `String`, and a client asking `items { quantity }` got a schema
|
|
43
|
+
* error on a field REST served whole. Declaring is optional — a scalar field needs nothing,
|
|
44
|
+
* and an undeclared object keeps the old behaviour.
|
|
45
|
+
*/
|
|
46
|
+
export function Presenter<E extends EntityConstructor>(entity: E, views?: PresenterViews) {
|
|
47
|
+
class PresenterBase {
|
|
48
|
+
static readonly __entity = entity;
|
|
49
|
+
static readonly __views = views;
|
|
50
|
+
}
|
|
51
|
+
return PresenterBase;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** List computed field names from a presenter class (own methods minus constructor). */
|
|
55
|
+
export function getPresenterFields(ctor: Function): string[] {
|
|
56
|
+
return Object.getOwnPropertyNames(ctor.prototype)
|
|
57
|
+
.filter((name) => name !== 'constructor' && typeof ctor.prototype[name] === 'function');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Container key of an entity's presenter — 'post' → 'PostPresenter'. */
|
|
61
|
+
export function presenterKeyOf(entity: string): string {
|
|
62
|
+
return `${upperFirst(entity)}Presenter`;
|
|
63
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { upperFirst, type EntityConstructor } from '@fougere/schema';
|
|
2
|
+
import type { EntityOrm, ListOptions, ListResult, SelectOption } from '../orm.js';
|
|
3
|
+
import type { SchemaView } from '@fougere/schema';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Repository(…entities) — who owns an entity's storage, and where its questions are named.
|
|
7
|
+
*
|
|
8
|
+
* **The arity decides**, which is the second reading of what `orm.ts` already states for
|
|
9
|
+
* `EntityOrm` against `Together`: the arity of the unit is the whole distinction.
|
|
10
|
+
*
|
|
11
|
+
* ONE entity — the repository IS that entity's storage, with your methods added. The port's
|
|
12
|
+
* thirteen gestures are forwarded, so a handler reads `this.posts.list()` whether or not
|
|
13
|
+
* anyone wrote the file, and a named question sits beside them:
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* // repositories/PostRepository.ts
|
|
17
|
+
* export default class PostRepository extends Repository(Post) {
|
|
18
|
+
* published() {
|
|
19
|
+
* return this.list({ where: { status: 'published' }, orderBy: 'publishedAt', order: 'desc' });
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* TWO OR MORE — an aggregate. It owns them: nothing else in the app is handed their
|
|
25
|
+
* storage, and no gesture is forwarded (which entity would `create` write to?), so the only
|
|
26
|
+
* way in is a method this class names. That is what lets a rule spanning two tables exist:
|
|
27
|
+
* it is ordinary TypeScript inside the method that does the writing.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* // repositories/CommandeRepository.ts
|
|
31
|
+
* export default class CommandeRepository extends Repository(Commande, Stock) {
|
|
32
|
+
* avecLignes(id: string) {
|
|
33
|
+
* const [commandes, stock] = this.orms;
|
|
34
|
+
* …
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* `this.orms` is protected, because the whole point is that the storage stops at this file.
|
|
40
|
+
* `protected` is erased at runtime, like `abstract` on a port: a compile-time guarantee, not
|
|
41
|
+
* a barrier. The same bargain, already accepted.
|
|
42
|
+
*
|
|
43
|
+
* **The boundary is not the unit of work.** An aggregate says the rules of these entities
|
|
44
|
+
* hold together; a frame says these writes land together, and the two lists coincide only
|
|
45
|
+
* often. Deriving the frame from the membership would make a read-only aggregate carry one
|
|
46
|
+
* — refusals included, and `registerFrames` refuses without storage or over `remotes:` —
|
|
47
|
+
* and would put `Together<[Commande, Stock], [StockMirror]>` out of reach forever. So a
|
|
48
|
+
* frame is ASKED FOR here as anywhere else, which is what makes it declared:
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* constructor(commandes: CommandeOrm, stock: StockOrm, private frame: Together<[Commande, Stock]>) {
|
|
52
|
+
* super(commandes, stock);
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* The ORM words come back in that line, and only there: this class IS the holder, which is
|
|
57
|
+
* the one case `boot/ownership.ts` lets name the storage it was built on.
|
|
58
|
+
*
|
|
59
|
+
* A repository is NOT a door: it has no façade, so nothing here is reachable from the wire.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The shape a repository of ONE entity has — the port itself, plus whatever the subclass
|
|
64
|
+
* names on top. Written by an author who has not written the file: `RepositoryOf<Post>` is
|
|
65
|
+
* to `PostRepository` what `EntityOrm<Post>` is to `PostOrm`, one spelling of one key, and
|
|
66
|
+
* `depKeyOf` reads both.
|
|
67
|
+
*/
|
|
68
|
+
export type RepositoryOf<T> = EntityOrm<T>;
|
|
69
|
+
|
|
70
|
+
/** The single-entity form: the port, plus whatever the subclass names. */
|
|
71
|
+
export interface RepositoryConstructor<T> {
|
|
72
|
+
new (orm: EntityOrm<T>): EntityOrm<T>;
|
|
73
|
+
readonly __entity: unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* What an aggregate's subclass sees: the storage of the members it owns, in declared order,
|
|
78
|
+
* and `protected` — the storage stops at that file, which is the whole mechanism.
|
|
79
|
+
*
|
|
80
|
+
* A class and not an interface, because `protected` cannot be spelled in one. Ambient: the
|
|
81
|
+
* value it describes is fabricated by `many()` for an arity only known at the call.
|
|
82
|
+
*/
|
|
83
|
+
declare abstract class AggregateShape<E extends readonly EntityConstructor[]> {
|
|
84
|
+
protected orms: { [K in keyof E]: EntityOrm<InstanceType<E[K]>> };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The tuple an aggregate holds — the readable form of {@link AggregateShape}'s member. */
|
|
88
|
+
export type AggregateOf<E extends readonly EntityConstructor[]> =
|
|
89
|
+
{ [K in keyof E]: EntityOrm<InstanceType<E[K]>> };
|
|
90
|
+
|
|
91
|
+
export type AggregateConstructor<E extends readonly EntityConstructor[]> =
|
|
92
|
+
(new (...orms: unknown[]) => AggregateShape<E>) & {
|
|
93
|
+
readonly __entity: unknown;
|
|
94
|
+
/** The entities this class owns. Present from two on — an owner of one owns nothing. */
|
|
95
|
+
readonly __owns: E;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export function Repository<E extends EntityConstructor>(entity: E): RepositoryConstructor<InstanceType<E>>;
|
|
99
|
+
export function Repository<E extends readonly [EntityConstructor, EntityConstructor, ...EntityConstructor[]]>(
|
|
100
|
+
...entities: E
|
|
101
|
+
): AggregateConstructor<E>;
|
|
102
|
+
export function Repository(...entities: EntityConstructor[]): unknown {
|
|
103
|
+
return entities.length === 1 ? one(entities[0]) : many(entities);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The port forwarded, member by member. Written out rather than proxied: a Proxy would
|
|
108
|
+
* answer every name including the ones the port does not have, and this file would then
|
|
109
|
+
* state the surface nowhere. Thirteen lines against one declaration that can be read.
|
|
110
|
+
*/
|
|
111
|
+
function one<E extends EntityConstructor>(entity: E): RepositoryConstructor<InstanceType<E>> {
|
|
112
|
+
type T = InstanceType<E>;
|
|
113
|
+
|
|
114
|
+
class RepositoryBase implements EntityOrm<T> {
|
|
115
|
+
static readonly __entity = entity;
|
|
116
|
+
|
|
117
|
+
constructor(protected orm: EntityOrm<T>) {}
|
|
118
|
+
|
|
119
|
+
list(options?: ListOptions & SelectOption): Promise<ListResult<T>> { return this.orm.list(options); }
|
|
120
|
+
findById(id: string, options?: SelectOption) { return this.orm.findById(id, options); }
|
|
121
|
+
findBy(criteria: Partial<T> | Record<string, unknown>, options?: SelectOption) { return this.orm.findBy(criteria, options); }
|
|
122
|
+
findAllBy(criteria: Partial<T> | Record<string, unknown>, options?: SelectOption) { return this.orm.findAllBy(criteria, options); }
|
|
123
|
+
findByKeys(ids: readonly string[], options?: SelectOption) { return this.orm.findByKeys(ids, options); }
|
|
124
|
+
findAllByKeys(field: string, keys: readonly string[], options?: SelectOption) { return this.orm.findAllByKeys(field, keys, options); }
|
|
125
|
+
create(input: Partial<T>, options?: SelectOption) { return this.orm.create(input, options); }
|
|
126
|
+
upsert(input: Partial<T>, options?: SelectOption) { return this.orm.upsert(input, options); }
|
|
127
|
+
upsertAll(inputs: readonly Partial<T>[], options?: SelectOption) { return this.orm.upsertAll(inputs, options); }
|
|
128
|
+
update(id: string, input: Partial<T>, options?: SelectOption) { return this.orm.update(id, input, options); }
|
|
129
|
+
delete(id: string) { return this.orm.delete(id); }
|
|
130
|
+
output(schema: SchemaView) { return this.orm.output(schema); }
|
|
131
|
+
get client(): unknown { return this.orm.client; }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return RepositoryBase as unknown as RepositoryConstructor<T>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The aggregate. Its constructor takes the members' storage in the DECLARED order — the
|
|
139
|
+
* order `toProvider` fills its `deps` with, and the order a subclass hands back to `super()`
|
|
140
|
+
* when it declares a constructor of its own.
|
|
141
|
+
*/
|
|
142
|
+
function many<E extends readonly EntityConstructor[]>(entities: E): AggregateConstructor<E> {
|
|
143
|
+
class AggregateBase {
|
|
144
|
+
static readonly __entity = entities[0];
|
|
145
|
+
static readonly __owns = entities;
|
|
146
|
+
|
|
147
|
+
protected orms: AggregateOf<E>;
|
|
148
|
+
|
|
149
|
+
constructor(...orms: unknown[]) {
|
|
150
|
+
this.orms = orms.slice(0, entities.length) as AggregateOf<E>;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return AggregateBase as unknown as AggregateConstructor<E>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Container key of an entity's repository — 'reading' → 'ReadingRepository'. */
|
|
158
|
+
export function repositoryKeyOf(entity: string): string {
|
|
159
|
+
return `${upperFirst(entity)}Repository`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The entities a class owns — empty for anything that is not an aggregate.
|
|
164
|
+
*
|
|
165
|
+
* Read from the mark rather than from the constructor, for the reason `Crud.__ops` exists:
|
|
166
|
+
* the AST scan is workspace-only, so an installed prefab resolves to nothing.
|
|
167
|
+
*/
|
|
168
|
+
export function ownedBy(ctor: unknown): readonly EntityConstructor[] {
|
|
169
|
+
return (ctor as { __owns?: readonly EntityConstructor[] } | undefined)?.__owns ?? [];
|
|
170
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { SchemaView } from '@fougere/schema';
|
|
2
|
+
import type { EntityEntry, FrondDescriptor } from './frond.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What this app hosts — the scan's answer, with the questions everyone was asking it
|
|
6
|
+
* by hand.
|
|
7
|
+
*
|
|
8
|
+
* The list was a bare array, so every reader re-walked it: "which frond owns this
|
|
9
|
+
* entity" was spelled four times, "every entity by name" three times as three literal
|
|
10
|
+
* copies of the same `Map`, and the two inside the boot even carried comments saying so.
|
|
11
|
+
* A concept nobody can question is a concept everyone rebuilds.
|
|
12
|
+
*
|
|
13
|
+
* It IS an array — the same reason `ListResult` is one: twenty call sites iterate,
|
|
14
|
+
* filter and spread it, and none of them is wrong to. `Symbol.species` is `Array` so a
|
|
15
|
+
* `.map()` over it answers a plain array rather than something that claims to be a
|
|
16
|
+
* hosting table and holds strings.
|
|
17
|
+
*/
|
|
18
|
+
export class Fronds extends Array<FrondDescriptor> {
|
|
19
|
+
static override get [Symbol.species](): ArrayConstructor {
|
|
20
|
+
return Array;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** What one scan run found. The only gate in — `Array.of` is taken, and named. */
|
|
24
|
+
static scanned(fronds: readonly FrondDescriptor[]): Fronds {
|
|
25
|
+
const held = new Fronds();
|
|
26
|
+
held.push(...fronds);
|
|
27
|
+
return held;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The frond that hosts an entity — `undefined` when no loaded frond does. */
|
|
31
|
+
owner(entity: string): FrondDescriptor | undefined {
|
|
32
|
+
return this.find((frond) => frond.entities.some((e) => e.name === entity));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The entity of that name, wherever it was scanned. */
|
|
36
|
+
entity(name: string): EntityEntry | undefined {
|
|
37
|
+
for (const frond of this) {
|
|
38
|
+
const found = frond.entities.find((e) => e.name === name);
|
|
39
|
+
if (found) return found;
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Every scanned entity class, by name — across all fronds and never per-frond.
|
|
46
|
+
*
|
|
47
|
+
* A fact is announced in one frond and heard in another, so the subscriber's own
|
|
48
|
+
* frond does not hold the shape it must judge; a `reads:` clause names entities
|
|
49
|
+
* that belong to neighbours by definition.
|
|
50
|
+
*/
|
|
51
|
+
schemas(): Map<string, SchemaView> {
|
|
52
|
+
return new Map(this.flatMap((frond) => frond.entities.map((e) => [e.name, e.entityClass] as const)));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Every scanned entity, sorted. What was FOUND, not what answers. */
|
|
56
|
+
entityNames(): string[] {
|
|
57
|
+
return this.flatMap((frond) => frond.entities.map((e) => e.name)).sort();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The names a call may address, sorted — what a NOT_FOUND must print.
|
|
62
|
+
*
|
|
63
|
+
* Not `entityNames()`, which is what the scan found: an entity with no handler is
|
|
64
|
+
* scanned and serves nothing, so the refusal read *"Entity 'indexed' is not hosted
|
|
65
|
+
* here. Hosted here: indexed."* — naming the very thing it had just refused. A façade
|
|
66
|
+
* is keyed on a HANDLER's address, and that is what this lists.
|
|
67
|
+
*/
|
|
68
|
+
servedNames(surface?: string): string[] {
|
|
69
|
+
return this.flatMap((frond) => frond.handlers
|
|
70
|
+
.filter((handler) => (handler.surface ?? undefined) === surface)
|
|
71
|
+
.map((handler) => handler.address)).sort();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names the scan READS instead of deriving them.
|
|
3
|
+
*
|
|
4
|
+
* Everything else a frond states, it states by its shape; these seven directories and the
|
|
5
|
+
* import prefix are the one place where a name is the declaration. They were spelled as
|
|
6
|
+
* literals in five packages, so a project could not move any of them and `frondsDir` was
|
|
7
|
+
* a declared key with no reader.
|
|
8
|
+
*/
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
|
|
11
|
+
export interface Conventions {
|
|
12
|
+
/**
|
|
13
|
+
* The scope a frond's package name carries — `@fronds/blog`.
|
|
14
|
+
*
|
|
15
|
+
* A real package name, not only an alias: the CLI writes it as `name` in a scaffolded
|
|
16
|
+
* frond and as a `workspace:*` dependency in the app that consumes it.
|
|
17
|
+
*/
|
|
18
|
+
scope: string;
|
|
19
|
+
/** The directory holding fronds, below the project root. */
|
|
20
|
+
fronds: string;
|
|
21
|
+
/** Directory per role. The role is the key; the name on disk is the value. */
|
|
22
|
+
dirs: {
|
|
23
|
+
entities: string;
|
|
24
|
+
handlers: string;
|
|
25
|
+
services: string;
|
|
26
|
+
repositories: string;
|
|
27
|
+
presenters: string;
|
|
28
|
+
collectors: string;
|
|
29
|
+
seeds: string;
|
|
30
|
+
/** What its shapes used to be — written by `fougere freeze`, replayed by `migrate`. */
|
|
31
|
+
versions: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What a project means when it declares nothing — the convention itself.
|
|
37
|
+
*
|
|
38
|
+
* `@fronds` and not `@frond`: the npm org for the singular belongs to someone else, and a
|
|
39
|
+
* scope is a name that must be ownable.
|
|
40
|
+
*/
|
|
41
|
+
export const DEFAULT_CONVENTIONS: Conventions = {
|
|
42
|
+
scope: '@fronds',
|
|
43
|
+
fronds: 'fronds',
|
|
44
|
+
dirs: {
|
|
45
|
+
entities: 'entities',
|
|
46
|
+
handlers: 'handlers',
|
|
47
|
+
services: 'services',
|
|
48
|
+
repositories: 'repositories',
|
|
49
|
+
presenters: 'presenters',
|
|
50
|
+
collectors: 'collectors',
|
|
51
|
+
seeds: 'seeds',
|
|
52
|
+
versions: 'versions',
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** What a `fougere.config.ts` may state: only the names that differ. */
|
|
57
|
+
export type ConventionsInput = {
|
|
58
|
+
scope?: string;
|
|
59
|
+
fronds?: string;
|
|
60
|
+
dirs?: Partial<Conventions['dirs']>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The convention, with a project's exceptions folded in.
|
|
65
|
+
*
|
|
66
|
+
* Merged one level into `dirs` so renaming one directory does not require restating the
|
|
67
|
+
* other six — the same reading `sources:` and `ports:` get, where only the exception is
|
|
68
|
+
* declared.
|
|
69
|
+
*/
|
|
70
|
+
export function resolveConventions(input?: ConventionsInput): Conventions {
|
|
71
|
+
return {
|
|
72
|
+
scope: input?.scope ?? DEFAULT_CONVENTIONS.scope,
|
|
73
|
+
fronds: input?.fronds ?? DEFAULT_CONVENTIONS.fronds,
|
|
74
|
+
dirs: { ...DEFAULT_CONVENTIONS.dirs, ...input?.dirs },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The package name a frond answers to. */
|
|
79
|
+
export function frondPackage(name: string, conventions: Conventions): string {
|
|
80
|
+
return `${conventions.scope}/${name}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Directories whose classes register as providers — two spellings, one behaviour.
|
|
85
|
+
*
|
|
86
|
+
* A project may point both roles at one directory; the scan must then read it once, or
|
|
87
|
+
* every provider would be registered twice.
|
|
88
|
+
*/
|
|
89
|
+
export function providerDirsOf(conventions: Conventions): string[] {
|
|
90
|
+
return [...new Set([conventions.dirs.services, conventions.dirs.repositories])];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The frond vocabulary — every directory the scan reads.
|
|
95
|
+
*
|
|
96
|
+
* What a reader needs to bound a frond: the Nuxt module watches these for the root frond
|
|
97
|
+
* (watching the root itself would match every write), and a flat app's tsconfig lists
|
|
98
|
+
* them instead of `["."]`, which would swallow `app/` and `nuxt.config.ts`.
|
|
99
|
+
*/
|
|
100
|
+
export function frondDirsOf(conventions: Conventions): string[] {
|
|
101
|
+
const { entities, handlers, presenters, collectors, seeds, versions } = conventions.dirs;
|
|
102
|
+
return [...new Set([
|
|
103
|
+
entities, handlers, presenters, collectors, seeds, versions, ...providerDirsOf(conventions),
|
|
104
|
+
])];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* What changes when a frond's domain changes — the paths a dev loop watches.
|
|
109
|
+
*
|
|
110
|
+
* The root frond IS the scan root, so watching its path would match every write in the
|
|
111
|
+
* project: `.nuxt/`, `node_modules/`, the build output. Its convention directories are
|
|
112
|
+
* the frond, and they are what a scan re-reads.
|
|
113
|
+
*/
|
|
114
|
+
export function watchPathsOf(
|
|
115
|
+
frond: { source: { path: string } },
|
|
116
|
+
scanRoot: string,
|
|
117
|
+
conventions: Conventions,
|
|
118
|
+
): string[] {
|
|
119
|
+
return frond.source.path === scanRoot
|
|
120
|
+
? frondDirsOf(conventions).map((dir) => join(scanRoot, dir))
|
|
121
|
+
: [frond.source.path];
|
|
122
|
+
}
|
package/src/scan/emit.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The scan, written down as a module — what `createApp` is handed where there is no disk.
|
|
3
|
+
*
|
|
4
|
+
* It RE-RESOLVES NOTHING. By the time this runs the scan has already decided what every
|
|
5
|
+
* slot holds, and `resolveSchema` put the entity's own class in `contract.output` — the
|
|
6
|
+
* very object `EntityEntry.entityClass` holds. So the emitter keeps a table from object
|
|
7
|
+
* to import alias and writes the alias. Identity is preserved because it is the same
|
|
8
|
+
* object that becomes the same import, which is what three call sites depend on
|
|
9
|
+
* (`adapter/graphql`'s `view === entity.entityClass` and its WeakMap, and `bootstrap`'s
|
|
10
|
+
* `outputSchema !== entity.entityClass`). An emitter that re-resolved instead would build
|
|
11
|
+
* a second class for `Post` and those three would silently take the other branch.
|
|
12
|
+
*
|
|
13
|
+
* Measured on three real projects: every live reference is either a class the descriptor
|
|
14
|
+
* already names by `filePath`, a named export of the file that declared the signature, or
|
|
15
|
+
* `Partial<X>` — the one derivation `resolveSchema` fabricates.
|
|
16
|
+
*/
|
|
17
|
+
import { dirname, relative } from 'node:path';
|
|
18
|
+
import { ANONYMOUS_SCHEMA_NAME, Card, type SchemaView } from '@fougere/schema';
|
|
19
|
+
import type {
|
|
20
|
+
ScanResult, FrondDescriptor, EntityEntry, HandlerEntry,
|
|
21
|
+
PresenterEntry, CollectorEntry, ProviderEntry, SeedEntry,
|
|
22
|
+
} from './frond.js';
|
|
23
|
+
import type { OperationContract } from '../wire/operation.js';
|
|
24
|
+
|
|
25
|
+
export interface EmitOptions {
|
|
26
|
+
/** Where the generated module will sit. Imports are written relative to it. */
|
|
27
|
+
outFile: string;
|
|
28
|
+
/** How `@fougere/core` is reached from there. Default: the package name. */
|
|
29
|
+
core?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type Live = object;
|
|
33
|
+
|
|
34
|
+
/** Is a TypeScript compiler going to read this module? Its name is the only thing that says. */
|
|
35
|
+
const isTypeScript = (outFile: string): boolean => /\.tsx?$/.test(outFile);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A source file becomes a specifier its reader can follow — and the two readers differ.
|
|
39
|
+
*
|
|
40
|
+
* A `.ts` destination is compiled by tsc under Node16 resolution, which spells a
|
|
41
|
+
* TypeScript source with `.js`. A `.mjs` destination is read by a bundler, which resolves
|
|
42
|
+
* the path AS IT IS ON DISK — measured, Nitro's rollup refused `Post.seed.js` because no
|
|
43
|
+
* such file exists. One rule, read off the destination, exactly like the type annotation.
|
|
44
|
+
*/
|
|
45
|
+
function specifierOf(filePath: string, outFile: string): string {
|
|
46
|
+
const path = relative(dirname(outFile), filePath);
|
|
47
|
+
const rel = isTypeScript(outFile) ? path.replace(/\.tsx?$/, '.js') : path;
|
|
48
|
+
return rel.startsWith('.') ? rel : `./${rel}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const lit = (v: unknown): string => JSON.stringify(v ?? null);
|
|
52
|
+
|
|
53
|
+
class Imports {
|
|
54
|
+
private readonly byValue = new Map<Live, string>();
|
|
55
|
+
private readonly lines: string[] = [];
|
|
56
|
+
/** Entity classes by their class name — what a `Partial<X>` names as its source. */
|
|
57
|
+
readonly byClassName = new Map<string, Live>();
|
|
58
|
+
|
|
59
|
+
constructor(private readonly outFile: string) {}
|
|
60
|
+
|
|
61
|
+
/** Register `value` as the default export of `filePath`, and answer its alias. */
|
|
62
|
+
default(value: Live, filePath: string): string {
|
|
63
|
+
const known = this.byValue.get(value);
|
|
64
|
+
if (known) return known;
|
|
65
|
+
const alias = `_${this.lines.length}`;
|
|
66
|
+
this.lines.push(`import ${alias} from '${specifierOf(filePath, this.outFile)}';`);
|
|
67
|
+
this.byValue.set(value, alias);
|
|
68
|
+
return alias;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Register `value` as a NAMED export of `filePath` — its class name is the export. */
|
|
72
|
+
named(value: Live, filePath: string, name: string): string {
|
|
73
|
+
const known = this.byValue.get(value);
|
|
74
|
+
if (known) return known;
|
|
75
|
+
const alias = `_${this.lines.length}`;
|
|
76
|
+
this.lines.push(`import { ${name} as ${alias} } from '${specifierOf(filePath, this.outFile)}';`);
|
|
77
|
+
this.byValue.set(value, alias);
|
|
78
|
+
return alias;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
has(value: Live): boolean { return this.byValue.has(value); }
|
|
82
|
+
aliasOf(value: Live): string | undefined { return this.byValue.get(value); }
|
|
83
|
+
render(): string { return this.lines.join('\n'); }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* What a schema slot becomes in the generated module.
|
|
88
|
+
*
|
|
89
|
+
* Three answers, and the third is the only rule: a class already imported is its alias; a
|
|
90
|
+
* named export of the file that declared the signature is imported by its own name — it
|
|
91
|
+
* IS exported there, because that is where `resolveSchema` found it; and an anonymous
|
|
92
|
+
* schema is `Partial<X>`, the one derivation `resolveSchema` builds, so it is written as
|
|
93
|
+
* the derivation rather than as a value.
|
|
94
|
+
*/
|
|
95
|
+
function schemaRef(schema: SchemaView | undefined, declaredIn: string, imports: Imports): string | undefined {
|
|
96
|
+
if (!schema) return undefined;
|
|
97
|
+
const known = imports.aliasOf(schema as Live);
|
|
98
|
+
if (known) return known;
|
|
99
|
+
|
|
100
|
+
const name = (schema as { name?: string }).name;
|
|
101
|
+
if (name && name !== ANONYMOUS_SCHEMA_NAME) return imports.named(schema as Live, declaredIn, name);
|
|
102
|
+
|
|
103
|
+
const card = Card.fromSchema(schema);
|
|
104
|
+
const source = card.origin?.from ?? card.descriptor.title;
|
|
105
|
+
const from = source ? imports.byClassName.get(source) : undefined;
|
|
106
|
+
if (from) return `${imports.aliasOf(from)}.partial()`;
|
|
107
|
+
|
|
108
|
+
throw new Error(
|
|
109
|
+
`A scan cannot be written down: an anonymous schema in ${declaredIn} names no source. `
|
|
110
|
+
+ 'Only `Partial<X>` is derivable here, and it says which X it came from.',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function contractOf(op: string, c: OperationContract, declaredIn: string, imports: Imports): string {
|
|
115
|
+
const parts: string[] = [];
|
|
116
|
+
const input = schemaRef(c.input, declaredIn, imports);
|
|
117
|
+
const output = schemaRef(c.output, declaredIn, imports);
|
|
118
|
+
if (input) parts.push(`input: ${input}`);
|
|
119
|
+
if (output) parts.push(`output: ${output}`);
|
|
120
|
+
if (c.binding !== undefined) parts.push(`binding: ${lit(c.binding)}`);
|
|
121
|
+
if (c.description !== undefined) parts.push(`description: ${lit(c.description)}`);
|
|
122
|
+
if (c.cardinality !== undefined) parts.push(`cardinality: ${lit(c.cardinality)}`);
|
|
123
|
+
if (c.signature !== undefined) parts.push(`signature: ${lit(c.signature)}`);
|
|
124
|
+
return `[${lit(op)}, { ${parts.join(', ')} }]`;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function entityOf(e: EntityEntry, imports: Imports): string {
|
|
128
|
+
return `{ name: ${lit(e.name)}, entityClass: ${imports.aliasOf(e.entityClass as Live)}, `
|
|
129
|
+
+ `filePath: ${lit(e.filePath)}, exposed: ${lit(e.exposed)} }`;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function handlerOf(h: HandlerEntry, imports: Imports): string {
|
|
133
|
+
const ops = [...h.operations].map(([op, c]) => contractOf(op, c, h.filePath, imports));
|
|
134
|
+
const override = schemaRef(h.outputOverride, h.filePath, imports);
|
|
135
|
+
return `{ name: ${lit(h.name)}, address: ${lit(h.address)}, ctor: ${imports.aliasOf(h.ctor as Live)}, `
|
|
136
|
+
+ `deps: ${lit(h.deps)}, filePath: ${lit(h.filePath)}, exposed: ${lit(h.exposed)}, `
|
|
137
|
+
+ (h.surface ? `surface: ${lit(h.surface)}, ` : '')
|
|
138
|
+
+ (override ? `outputOverride: ${override}, ` : '')
|
|
139
|
+
+ `operations: new Map([\n ${ops.join(',\n ')}\n ]) }`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function presenterOf(p: PresenterEntry, imports: Imports): string {
|
|
143
|
+
// `views` is not written: it is read back off the constructor (`__views`), so emitting
|
|
144
|
+
// it would be a second copy of a statement the imported class already carries.
|
|
145
|
+
return `{ entityName: ${lit(p.entityName)}, ctor: ${imports.aliasOf(p.ctor as Live)}, `
|
|
146
|
+
+ `fields: ${lit(p.fields)}, fieldMeta: ${lit(p.fieldMeta)}, deps: ${lit(p.deps)}, `
|
|
147
|
+
+ `filePath: ${lit(p.filePath)} }`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function collectorOf(c: CollectorEntry, imports: Imports): string {
|
|
151
|
+
return `{ typeName: ${lit(c.typeName)}, ctor: ${imports.aliasOf(c.ctor as Live)}, `
|
|
152
|
+
+ `deps: ${lit(c.deps)}, filePath: ${lit(c.filePath)} }`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function providerOf(p: ProviderEntry, imports: Imports): string {
|
|
156
|
+
return `{ ctor: ${imports.aliasOf(p.ctor as Live)}, deps: ${lit(p.deps)}, filePath: ${lit(p.filePath)} }`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function seedOf(s: SeedEntry, imports: Imports): string {
|
|
160
|
+
const data = typeof s.data === 'function' ? imports.aliasOf(s.data as Live) : lit(s.data);
|
|
161
|
+
return `{ entityName: ${lit(s.entityName)}, data: ${data}, filePath: ${lit(s.filePath)} }`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function frondOf(f: FrondDescriptor, imports: Imports): string {
|
|
165
|
+
const list = (label: string, items: string[]) =>
|
|
166
|
+
` ${label}: [${items.length ? `\n ${items.join(',\n ')},\n ` : ''}],`;
|
|
167
|
+
return [
|
|
168
|
+
' {',
|
|
169
|
+
` name: ${lit(f.name)},`,
|
|
170
|
+
` source: ${lit(f.source)},`,
|
|
171
|
+
list('providers', f.providers.map((p) => providerOf(p, imports))),
|
|
172
|
+
list('entities', f.entities.map((e) => entityOf(e, imports))),
|
|
173
|
+
list('handlers', f.handlers.map((h) => handlerOf(h, imports))),
|
|
174
|
+
list('presenters', f.presenters.map((p) => presenterOf(p, imports))),
|
|
175
|
+
list('collectors', f.collectors.map((c) => collectorOf(c, imports))),
|
|
176
|
+
list('seeds', f.seeds.map((s) => seedOf(s, imports))),
|
|
177
|
+
f.surfaces ? ` surfaces: ${lit(f.surfaces)},` : '',
|
|
178
|
+
f.reads ? ` reads: ${lit(f.reads)},` : '',
|
|
179
|
+
' }',
|
|
180
|
+
].filter(Boolean).join('\n');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Write a scan down. The result is a TypeScript module whose only imports are the classes
|
|
185
|
+
* the scan found — static, so a bundler traces them — and whose only value is the
|
|
186
|
+
* descriptor `createApp` asks for.
|
|
187
|
+
*/
|
|
188
|
+
export function emitScan(result: ScanResult, options: EmitOptions): string {
|
|
189
|
+
const imports = new Imports(options.outFile);
|
|
190
|
+
const core = options.core ?? '@fougere/core';
|
|
191
|
+
|
|
192
|
+
// Every class the descriptor names by a file comes first: a schema slot holding one of
|
|
193
|
+
// them then finds it in the table instead of being imported a second time.
|
|
194
|
+
for (const f of result.fronds) {
|
|
195
|
+
for (const e of f.entities) {
|
|
196
|
+
imports.default(e.entityClass as Live, e.filePath);
|
|
197
|
+
const name = (e.entityClass as { name?: string }).name;
|
|
198
|
+
if (name) imports.byClassName.set(name, e.entityClass as Live);
|
|
199
|
+
}
|
|
200
|
+
for (const p of f.providers) imports.default(p.ctor as Live, p.filePath);
|
|
201
|
+
for (const h of f.handlers) imports.default(h.ctor as Live, h.filePath);
|
|
202
|
+
for (const p of f.presenters) imports.default(p.ctor as Live, p.filePath);
|
|
203
|
+
for (const c of f.collectors) imports.default(c.ctor as Live, c.filePath);
|
|
204
|
+
for (const s of f.seeds) if (typeof s.data === 'function') imports.default(s.data as Live, s.filePath);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const fronds = result.fronds.map((f) => frondOf(f, imports)).join(',\n');
|
|
208
|
+
// `cause` is dropped: it is an Error, and the build that produced this already reported
|
|
209
|
+
// it. What a boot logs is the message, and that travels.
|
|
210
|
+
const diagnostics = result.diagnostics.map(({ cause: _cause, ...rest }) => lit(rest));
|
|
211
|
+
|
|
212
|
+
// The annotation is a convenience for a file a human's tsc will read; it is never what
|
|
213
|
+
// makes the value correct. A bundler parses a `.mjs` as JavaScript and `import type`
|
|
214
|
+
// stops it dead — measured, Nitro's rollup refused the Nuxt template at that line.
|
|
215
|
+
const typed = isTypeScript(options.outFile);
|
|
216
|
+
|
|
217
|
+
return `// Generated by \`fougere build\` — the scan, written down. Do not edit.
|
|
218
|
+
//
|
|
219
|
+
// \`createApp\` reads this instead of a disk. Everything here was decided by the scan that
|
|
220
|
+
// produced it; nothing is resolved a second time.
|
|
221
|
+
import { Fronds } from '${core}';
|
|
222
|
+
${typed ? `import type { ScanResult } from '${core}';\n` : ''}${imports.render()}
|
|
223
|
+
|
|
224
|
+
export const scan${typed ? ': ScanResult' : ''} = {
|
|
225
|
+
fronds: Fronds.scanned([
|
|
226
|
+
${fronds}
|
|
227
|
+
]),
|
|
228
|
+
diagnostics: [${diagnostics.join(', ')}],
|
|
229
|
+
};
|
|
230
|
+
`;
|
|
231
|
+
}
|