@fougere/core 0.3.0-alpha.0 → 0.5.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 +1 -1
- package/dist/boot/Emissions.js +1 -1
- package/dist/boot/Emissions.js.map +1 -1
- package/dist/boot/HandlerFacade.js +2 -2
- package/dist/boot/HandlerFacade.js.map +1 -1
- package/dist/boot/apply.d.ts.map +1 -1
- package/dist/boot/apply.js +2 -12
- package/dist/boot/apply.js.map +1 -1
- package/dist/boot/binding.d.ts +1 -1
- package/dist/boot/binding.d.ts.map +1 -1
- package/dist/boot/binding.js +4 -4
- package/dist/boot/binding.js.map +1 -1
- package/dist/boot/boot.d.ts +1 -1
- package/dist/boot/boot.d.ts.map +1 -1
- package/dist/boot/bootstrap.d.ts.map +1 -1
- package/dist/boot/bootstrap.js +26 -17
- package/dist/boot/bootstrap.js.map +1 -1
- package/dist/boot/frame.d.ts +1 -1
- package/dist/boot/frame.d.ts.map +1 -1
- package/dist/boot/frame.js +5 -14
- package/dist/boot/frame.js.map +1 -1
- package/dist/boot/hosted.d.ts +29 -0
- package/dist/boot/hosted.d.ts.map +1 -0
- package/dist/boot/hosted.js +38 -0
- package/dist/boot/hosted.js.map +1 -0
- package/dist/boot/ownership.d.ts +0 -3
- package/dist/boot/ownership.d.ts.map +1 -1
- package/dist/boot/ownership.js +5 -5
- package/dist/boot/ownership.js.map +1 -1
- package/dist/boot/remote.d.ts +1 -1
- package/dist/boot/remote.d.ts.map +1 -1
- package/dist/boot/remote.js +3 -3
- package/dist/boot/remote.js.map +1 -1
- package/dist/boot/statement-drift.d.ts +24 -0
- package/dist/boot/statement-drift.d.ts.map +1 -0
- package/dist/boot/statement-drift.js +38 -0
- package/dist/boot/statement-drift.js.map +1 -0
- package/dist/boot/together.d.ts.map +1 -1
- package/dist/boot/together.js +6 -6
- package/dist/boot/together.js.map +1 -1
- package/dist/boot/types.d.ts +17 -4
- package/dist/boot/types.d.ts.map +1 -1
- package/dist/contract/CallLog.d.ts +57 -0
- package/dist/contract/CallLog.d.ts.map +1 -0
- package/dist/contract/CallLog.js +2 -0
- package/dist/contract/CallLog.js.map +1 -0
- package/dist/contract.d.ts +9 -4
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +12 -5
- package/dist/contract.js.map +1 -1
- package/dist/dispatch/DispatchLifecycle.d.ts +9 -1
- package/dist/dispatch/DispatchLifecycle.d.ts.map +1 -1
- package/dist/dispatch/DispatchLifecycle.js +17 -2
- package/dist/dispatch/DispatchLifecycle.js.map +1 -1
- package/dist/dispatch/InFlight.d.ts +0 -1
- package/dist/dispatch/InFlight.d.ts.map +1 -1
- package/dist/dispatch/InFlight.js +0 -3
- package/dist/dispatch/InFlight.js.map +1 -1
- package/dist/dispatch/InputValidator.d.ts.map +1 -1
- package/dist/dispatch/InputValidator.js +3 -2
- package/dist/dispatch/InputValidator.js.map +1 -1
- package/dist/dispatch/OutputProjector.js +2 -2
- package/dist/dispatch/OutputProjector.js.map +1 -1
- package/dist/dispatch/StorageGuard.d.ts.map +1 -1
- package/dist/dispatch/StorageGuard.js +2 -2
- package/dist/dispatch/StorageGuard.js.map +1 -1
- package/dist/effective-operation.d.ts.map +1 -1
- package/dist/effective-operation.js +8 -5
- package/dist/effective-operation.js.map +1 -1
- 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/identity.js +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/imports.d.ts +1 -1
- package/dist/imports.d.ts.map +1 -1
- package/dist/imports.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +2 -0
- package/dist/node.js.map +1 -1
- package/dist/orm.d.ts.map +1 -1
- package/dist/orm.js +4 -4
- package/dist/orm.js.map +1 -1
- package/dist/prefab/collector.js +2 -2
- package/dist/prefab/collector.js.map +1 -1
- package/dist/prefab/mirror.d.ts.map +1 -1
- package/dist/prefab/mirror.js +2 -2
- package/dist/prefab/mirror.js.map +1 -1
- package/dist/prefab/presenter.d.ts.map +1 -1
- package/dist/prefab/presenter.js +2 -2
- package/dist/prefab/presenter.js.map +1 -1
- package/dist/prefab/repository.d.ts.map +1 -1
- package/dist/prefab/repository.js +2 -2
- package/dist/prefab/repository.js.map +1 -1
- package/dist/scan/bundling.d.ts +14 -0
- package/dist/scan/bundling.d.ts.map +1 -0
- package/dist/scan/bundling.js +26 -0
- package/dist/scan/bundling.js.map +1 -0
- package/dist/scan/declare.d.ts +71 -0
- package/dist/scan/declare.d.ts.map +1 -0
- package/dist/scan/declare.js +125 -0
- package/dist/scan/declare.js.map +1 -0
- package/dist/scan/emit.d.ts.map +1 -1
- package/dist/scan/emit.js +3 -2
- package/dist/scan/emit.js.map +1 -1
- package/dist/scan/handler-parser.d.ts +2 -0
- package/dist/scan/handler-parser.d.ts.map +1 -1
- package/dist/scan/handler-parser.js +52 -13
- package/dist/scan/handler-parser.js.map +1 -1
- package/dist/scan/scanner.d.ts.map +1 -1
- package/dist/scan/scanner.js +37 -11
- package/dist/scan/scanner.js.map +1 -1
- package/dist/scan/statement.d.ts +4 -0
- package/dist/scan/statement.d.ts.map +1 -0
- package/dist/scan/statement.js +112 -0
- package/dist/scan/statement.js.map +1 -0
- package/dist/verify.js +2 -2
- package/dist/verify.js.map +1 -1
- package/dist/wire/call.d.ts +19 -8
- package/dist/wire/call.d.ts.map +1 -1
- package/dist/wire/call.js +17 -6
- package/dist/wire/call.js.map +1 -1
- package/dist/wire/drift.d.ts +55 -0
- package/dist/wire/drift.d.ts.map +1 -0
- package/dist/wire/drift.js +121 -0
- package/dist/wire/drift.js.map +1 -0
- package/dist/wire/middleware.d.ts +1 -1
- package/dist/wire/middleware.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/boot/AppLifecycle.ts +50 -0
- package/src/boot/Emissions.ts +263 -0
- package/src/boot/HandlerFacade.ts +242 -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 +847 -0
- package/src/boot/frame.ts +210 -0
- package/src/boot/hosted.ts +77 -0
- package/src/boot/ownership.ts +137 -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/statement-drift.ts +60 -0
- package/src/boot/together.ts +215 -0
- package/src/boot/types.ts +274 -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/CallLog.ts +55 -0
- package/src/contract/Invocation.ts +72 -0
- package/src/contract/RouteAddress.ts +49 -0
- package/src/contract.ts +83 -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 +43 -0
- package/src/dispatch/DispatchPort.ts +6 -0
- package/src/dispatch/Dispatcher.ts +48 -0
- package/src/dispatch/InFlight.ts +45 -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 +601 -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 +120 -0
- package/src/loader.ts +41 -0
- package/src/node.ts +30 -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/bundling.ts +25 -0
- package/src/scan/conventions.ts +122 -0
- package/src/scan/declare.ts +188 -0
- package/src/scan/emit.ts +231 -0
- package/src/scan/frond.ts +235 -0
- package/src/scan/handler-parser.ts +817 -0
- package/src/scan/scanner.ts +757 -0
- package/src/scan/statement.ts +126 -0
- package/src/verify.ts +193 -0
- package/src/wire/call.ts +381 -0
- package/src/wire/drift.ts +131 -0
- package/src/wire/errors.ts +124 -0
- package/src/wire/http-error.ts +77 -0
- package/src/wire/loggerMiddleware.ts +29 -0
- package/src/wire/middleware.ts +47 -0
- package/src/wire/operation.ts +258 -0
- package/dist/boot/Lifecycle.d.ts +0 -4
- package/dist/boot/Lifecycle.d.ts.map +0 -1
- package/dist/boot/Lifecycle.js +0 -3
- package/dist/boot/Lifecycle.js.map +0 -1
- package/dist/boot/egress.d.ts +0 -8
- package/dist/boot/egress.d.ts.map +0 -1
- package/dist/boot/egress.js +0 -11
- package/dist/boot/egress.js.map +0 -1
- package/dist/scan/scan-cache.d.ts +0 -16
- package/dist/scan/scan-cache.d.ts.map +0 -1
- package/dist/scan/scan-cache.js +0 -99
- package/dist/scan/scan-cache.js.map +0 -1
- package/dist/wire/invocation.d.ts +0 -4
- package/dist/wire/invocation.d.ts.map +0 -1
- package/dist/wire/invocation.js +0 -3
- package/dist/wire/invocation.js.map +0 -1
|
@@ -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,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a Fougere boot loads at RUNTIME, so a bundler must leave it alone.
|
|
3
|
+
*
|
|
4
|
+
* Stated once because it was stated twice and the two had already drifted: the Vite plugin
|
|
5
|
+
* listed `@fougere/schema`, `@fougere/adapter-graphql` and `@fougere/auth-better`, the Next
|
|
6
|
+
* one did not, and BOTH omitted the two packages `@fougere/app`'s boot actually imports
|
|
7
|
+
* dynamically — `@fougere/defaults` and `@fougere/transport-http`. A list a bundler reads
|
|
8
|
+
* has no way to notice it is wrong: nothing fails at build time, the app fails at boot.
|
|
9
|
+
*
|
|
10
|
+
* It sits here rather than beside the dynamic imports because both readers are BUILD-TIME
|
|
11
|
+
* plugins that already depend on core, and neither may pull the boot into a bundler config.
|
|
12
|
+
*/
|
|
13
|
+
export const RUNTIME_PACKAGES: readonly string[] = [
|
|
14
|
+
'@fougere/app',
|
|
15
|
+
'@fougere/core',
|
|
16
|
+
'@fougere/schema',
|
|
17
|
+
'@fougere/defaults',
|
|
18
|
+
'@fougere/transport-http',
|
|
19
|
+
'@fougere/adapter-sql',
|
|
20
|
+
'@fougere/adapter-graphql',
|
|
21
|
+
'@fougere/auth-better',
|
|
22
|
+
'better-sqlite3',
|
|
23
|
+
'jiti',
|
|
24
|
+
'typescript',
|
|
25
|
+
];
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A frond stated by its author, for an app that will not scan.
|
|
3
|
+
*
|
|
4
|
+
* The scan reads the type checker because a signature IS a declaration — and that reading
|
|
5
|
+
* has to happen while the types still exist, which is build time. An app that wants
|
|
6
|
+
* neither a build step nor `typescript` at runtime says the same thing here instead, and
|
|
7
|
+
* `createApp` cannot tell the difference: it consumes a `ScanResult`, never a scanner.
|
|
8
|
+
*
|
|
9
|
+
* What it does NOT ask for is the point. Every name the scan derives from a class is
|
|
10
|
+
* derived here the same way — `PostHandler` answers at `post`, `Post` is stored as `post`
|
|
11
|
+
* — so a declaration states classes and nothing else. `filePath` is empty because there is
|
|
12
|
+
* no file to point at, and a diagnostic that would have quoted one says so plainly.
|
|
13
|
+
*
|
|
14
|
+
* Measured on `demos/nuxt-blog`: 23 of its 29 operations need no word here at all, because
|
|
15
|
+
* `Crud.__ops` declares them at runtime. Only the six the author wrote by hand cost
|
|
16
|
+
* anything, and they cost `frond.config.ts` — where what is not derivable is stated.
|
|
17
|
+
*/
|
|
18
|
+
import { lowerFirst, type SchemaView } from '@fougere/schema';
|
|
19
|
+
import type {
|
|
20
|
+
CollectorEntry, EntityEntry, FrondDescriptor, HandlerEntry,
|
|
21
|
+
PresenterEntry, ProviderEntry, SeedEntry,
|
|
22
|
+
} from './frond.js';
|
|
23
|
+
import { DEFAULT_CONVENTIONS } from './conventions.js';
|
|
24
|
+
import { getPresenterFields } from '../prefab/presenter.js';
|
|
25
|
+
|
|
26
|
+
/** A class, as a declaration hands it over: the constructor itself. */
|
|
27
|
+
type Ctor = new (...args: never[]) => unknown;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What a subject needs beyond its class, when its constructor names a frame or a port.
|
|
31
|
+
*
|
|
32
|
+
* `deps` is the one thing no runtime can recover: TypeScript erases the parameter types,
|
|
33
|
+
* and `registerFrames` reads them to know which frames to build — asking for one IS
|
|
34
|
+
* declaring it. A handler that takes only its own entity's ORM needs nothing here.
|
|
35
|
+
*/
|
|
36
|
+
export interface DeclaredSubject {
|
|
37
|
+
ctor: Ctor;
|
|
38
|
+
deps?: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A handler, and the surface it answers on when it is not the default one. */
|
|
42
|
+
export interface DeclaredHandler extends DeclaredSubject {
|
|
43
|
+
/**
|
|
44
|
+
* The scan reads this from the directory (`handlers/public/`), so a statement has to
|
|
45
|
+
* say it: two handlers over one entity collide on their address otherwise, and the
|
|
46
|
+
* refusal names the same route twice.
|
|
47
|
+
*/
|
|
48
|
+
surface?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A class on its own, or a class with what it asks for. */
|
|
52
|
+
export type Declared = Ctor | DeclaredSubject;
|
|
53
|
+
|
|
54
|
+
const ctorOf = (d: Declared): Ctor => (typeof d === 'function' ? d : d.ctor);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What a prefab was BUILT ON — `Presenter(Post)` and `Collector(User)` both keep it under
|
|
58
|
+
* `__entity`, which is the only place it survives: nothing in the FORM of `PostPresenter`
|
|
59
|
+
* says `Post`. Absent, the class did not come through the prefab, and the refusal says so
|
|
60
|
+
* rather than yielding a frond whose presenter belongs to no entity.
|
|
61
|
+
*/
|
|
62
|
+
function subjectOf(ctor: Ctor, kind: string): { name: string } {
|
|
63
|
+
const subject = (ctor as unknown as { __entity?: { name: string } }).__entity;
|
|
64
|
+
if (!subject?.name) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`${ctor.name} is declared as a ${kind} but does not extend ${kind === 'presenter' ? 'Presenter(Entity)' : 'Collector(Type)'}, `
|
|
67
|
+
+ `so what it is about cannot be read.`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return subject;
|
|
72
|
+
}
|
|
73
|
+
const depsOf = (d: Declared): string[] => (typeof d === 'function' ? [] : d.deps ?? []);
|
|
74
|
+
|
|
75
|
+
/** `PostHandler` answers at `post` — the same rule the scan applies to a file it found. */
|
|
76
|
+
function addressOf(className: string): string {
|
|
77
|
+
const base = className.endsWith('Handler') ? className.slice(0, -7) : className;
|
|
78
|
+
|
|
79
|
+
return lowerFirst(base);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What a declaration states about one frond. Everything else is derived from the classes. */
|
|
83
|
+
export interface FrondDeclaration {
|
|
84
|
+
entities?: SchemaView[];
|
|
85
|
+
handlers?: (Ctor | DeclaredHandler)[];
|
|
86
|
+
presenters?: (Ctor | DeclaredSubject)[];
|
|
87
|
+
collectors?: (Ctor | DeclaredSubject)[];
|
|
88
|
+
providers?: Declared[];
|
|
89
|
+
seeds?: { entityName: string; data: SeedEntry['data'] }[];
|
|
90
|
+
/** Per-surface entity lists — the same key `frond.config.ts` states. */
|
|
91
|
+
surfaces?: Record<string, string[]>;
|
|
92
|
+
/** The import scope this frond answers under. Defaults to the conventional one. */
|
|
93
|
+
scope?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* State a frond without reading a disk.
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* createApp({
|
|
101
|
+
* scan: { fronds: Fronds.scanned([frond('blog', { entities: [Post], handlers: [PostHandler] })]), diagnostics: [] },
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function frond(name: string, declared: FrondDeclaration = {}): FrondDescriptor {
|
|
106
|
+
const scope = declared.scope ?? DEFAULT_CONVENTIONS.scope;
|
|
107
|
+
|
|
108
|
+
const entities: EntityEntry[] = (declared.entities ?? []).map((entityClass) => ({
|
|
109
|
+
name: lowerFirst((entityClass as { name: string }).name),
|
|
110
|
+
entityClass,
|
|
111
|
+
filePath: '',
|
|
112
|
+
exposed: true,
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
const handlers: HandlerEntry[] = (declared.handlers ?? []).map((h) => {
|
|
116
|
+
const ctor = ctorOf(h);
|
|
117
|
+
const surface = typeof h === 'function' ? undefined : h.surface;
|
|
118
|
+
const address = addressOf(ctor.name);
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
name: ctor.name,
|
|
122
|
+
address,
|
|
123
|
+
ctor,
|
|
124
|
+
// A handler about no stored row is ordinary — the address is not a promise that an
|
|
125
|
+
// entity carries it, which is why this is not looked up.
|
|
126
|
+
entityName: address,
|
|
127
|
+
operations: new Map(),
|
|
128
|
+
deps: depsOf(h),
|
|
129
|
+
filePath: '',
|
|
130
|
+
exposed: true,
|
|
131
|
+
...(surface ? { surface } : {}),
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Read off the class, never restated: `Presenter(Post)` keeps `Post` in `__entity` and a
|
|
136
|
+
// computed field IS a method, which `getPresenterFields` already reads from the prototype.
|
|
137
|
+
// Asking for `entityName` and `fields` made a statement copy what the class carries — and
|
|
138
|
+
// a copy that drifts silently, since nothing compares the two.
|
|
139
|
+
const presenters: PresenterEntry[] = (declared.presenters ?? []).map((p) => {
|
|
140
|
+
const ctor = ctorOf(p);
|
|
141
|
+
const fields = getPresenterFields(ctor);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
entityName: lowerFirst(subjectOf(ctor, 'presenter').name),
|
|
145
|
+
ctor,
|
|
146
|
+
fields,
|
|
147
|
+
fieldMeta: fields.map((field) => ({ name: field })),
|
|
148
|
+
deps: depsOf(p),
|
|
149
|
+
filePath: '',
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// `Collector(User)` keeps `User` the same way — the type a handler names to receive it.
|
|
154
|
+
const collectors: CollectorEntry[] = (declared.collectors ?? []).map((c) => {
|
|
155
|
+
const ctor = ctorOf(c);
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
typeName: subjectOf(ctor, 'collector').name,
|
|
159
|
+
ctor,
|
|
160
|
+
deps: depsOf(c),
|
|
161
|
+
filePath: '',
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const providers: ProviderEntry[] = (declared.providers ?? []).map((p) => ({
|
|
166
|
+
ctor: ctorOf(p),
|
|
167
|
+
deps: depsOf(p),
|
|
168
|
+
filePath: '',
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
const seeds: SeedEntry[] = (declared.seeds ?? []).map((s) => ({
|
|
172
|
+
entityName: s.entityName,
|
|
173
|
+
data: s.data,
|
|
174
|
+
filePath: '',
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
name,
|
|
179
|
+
source: { path: '', package: `${scope}/${name}` },
|
|
180
|
+
providers,
|
|
181
|
+
entities,
|
|
182
|
+
handlers,
|
|
183
|
+
presenters,
|
|
184
|
+
collectors,
|
|
185
|
+
seeds,
|
|
186
|
+
...(declared.surfaces ? { surfaces: declared.surfaces } : {}),
|
|
187
|
+
};
|
|
188
|
+
}
|