Skip to content

Commit

Permalink
fix: remove System
Browse files Browse the repository at this point in the history
  • Loading branch information
rotorsoft committed Sep 21, 2024
1 parent 7265c77 commit 1dd6311
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 211 deletions.
5 changes: 2 additions & 3 deletions libs/calculator-artifacts/src/__tests__/calculator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import {
} from "@rotorsoft/eventually";
import { Chance } from "chance";
import { Calculator } from "../calculator.aggregate";
import { Forget } from "../forget.system";
import { CalculatorCommands } from "../calculator.schemas";
import { ExternalPayload, PressKeyAdapter } from "../presskey.adapter";
import { pressKey } from "./messages";
import { CalculatorCommands } from "../calculator.schemas";

// app setup
const chance = new Chance();
app().with(Forget).with(Calculator).with(PressKeyAdapter).build();
app().with(Calculator).with(PressKeyAdapter).build();

describe("Calculator", () => {
beforeAll(async () => {
Expand Down
25 changes: 0 additions & 25 deletions libs/calculator-artifacts/src/forget.system.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/eventually-aws/src/lambda/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const command = async ({
system,
parsedPath: `/${system}/${stream}/${command}`
});
if (!(md.type === "aggregate" || md.type === "system"))
if (!(md.type === "aggregate"))
return BadRequest("Invalid system", {
system,
type: md.type,
Expand Down
6 changes: 1 addition & 5 deletions libs/eventually-openapi/src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ export const HttpClient = (
const headers = {} as Record<string, string>;
target.expectedVersion &&
(headers["If-Match"] = target.expectedVersion.toString());
const path = httpPostPath(
factory.name,
"reduce" in factory("") ? "aggregate" : "system",
name as string
);
const path = httpPostPath(factory.name, "aggregate", name as string);
const { data } = await axios.default.post(
url(path.replace(":id", target?.stream || "")),
payload,
Expand Down
4 changes: 1 addition & 3 deletions libs/eventually-openapi/src/home/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const _color = (type: ArtifactType): string => {
return "primary";
case "projector":
return "success";
case "system":
return "secondary";
default:
return "danger";
}
Expand All @@ -47,7 +45,7 @@ export const artifacts = (): string =>
<p class="m-0 fw-lighter fst-italic" style="font-size:75%">${
factory("").description
}</p>
${_inputs(type === "aggregate" || type === "system", inputs)}
${_inputs(type === "aggregate", inputs)}
<hr />
${_outputs(outputs)}
</div></div></div>`
Expand Down
6 changes: 3 additions & 3 deletions libs/eventually-openapi/src/home/esml.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { app, camelize } from "@rotorsoft/eventually";
import { config } from "..";
import { z } from "zod";
import { config } from "..";

const ZOD2TYPE: { [K in z.ZodFirstPartyTypeKind]?: string } = {
[z.ZodFirstPartyTypeKind.ZodString]: "string",
Expand Down Expand Up @@ -93,12 +93,12 @@ export const esml = (): Record<string, any> => {
[...app().artifacts.values()]
.filter((a) => a.type !== "command-adapter")
.forEach((a) => {
const sys = a.type === "aggregate" || a.type === "system";
const agg = a.type === "aggregate";
const art = (model[a.factory.name] = {
type: a.type
} as Record<string, any>);
if (a.inputs.length) art.handles = a.inputs.map((i) => i.name);
if (a.outputs.length) art[sys ? "emits" : "invokes"] = a.outputs;
if (a.outputs.length) art[agg ? "emits" : "invokes"] = a.outputs;
if (a.schema) art.schema = toSchema(a.schema, model);
});

Expand Down
10 changes: 5 additions & 5 deletions libs/eventually-openapi/src/utils/oas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ const toResponse = (
: {}
}
: ref
? {
$ref: `#/components/schemas/${ref}`
}
: {}
? {
$ref: `#/components/schemas/${ref}`
}
: {}
}
},
headers
Expand Down Expand Up @@ -312,7 +312,7 @@ const getArtifactPaths = (
}
};
}
if (type === "aggregate" || type === "system") {
if (type === "aggregate") {
endpoints.forEach((message) => {
const path = httpPostPath(factory.name, type, message);
paths[path.replace("/:id/", "/{id}/")] = {
Expand Down
2 changes: 0 additions & 2 deletions libs/eventually-openapi/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export const httpPostPath = (
switch (type) {
case "aggregate":
return "/".concat(decamelize(name), "/:id/", decamelize(message));
case "system":
return "/".concat(decamelize(name), "/", decamelize(message));
default:
return "/".concat(decamelize(name));
}
Expand Down
33 changes: 0 additions & 33 deletions libs/eventually/src/__tests__/projection/Match.system.ts

This file was deleted.

52 changes: 0 additions & 52 deletions libs/eventually/src/__tests__/projection/broker.async.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/eventually/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export abstract class Builder extends EventEmitter implements Disposable {
});
});
return {
type: reducible ? "aggregate" : "system",
type: "aggregate",
factory,
schema,
inputs: inputs.map((name) => ({ name, scope })),
Expand Down
4 changes: 2 additions & 2 deletions libs/eventually/src/handlers/command.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { randomUUID } from "crypto";
import { app, log } from "../ports";
import {
AggregateFactory,
InvariantError,
RegistrationError,
type CommandHandlerFactory,
type CommittedEventMetadata,
type Message,
type Messages,
Expand Down Expand Up @@ -35,7 +35,7 @@ export default async function command<
if (!msg?.handlers.length) throw new RegistrationError(command);

const factory = app().artifacts.get(msg.handlers[0])
?.factory as unknown as CommandHandlerFactory<S, C, E>;
?.factory as unknown as AggregateFactory<S, C, E>;
if (!factory) throw new RegistrationError(command);

log().blue().trace(`\n>>> ${factory.name}`, command, metadata);
Expand Down
2 changes: 1 addition & 1 deletion libs/eventually/src/port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const disposers: Disposer[] = [];
const disposeAndExit = async (code: ExitCode = "UNIT_TEST"): Promise<void> => {
await Promise.all(disposers.map((disposer) => disposer()));
await Promise.all(
[...adapters].map(async ([key, adapter]) => {
[...adapters].reverse().map(async ([key, adapter]) => {
log(`♻️ ${adapter.name || key}`);
await adapter.dispose();
})
Expand Down
76 changes: 19 additions & 57 deletions libs/eventually/src/types/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type { Projection } from "./projection";

/** All artifact types */
export type ArtifactType =
| "system"
| "aggregate"
| "policy"
| "process-manager"
Expand All @@ -34,16 +33,6 @@ export type Schemas<M extends Messages> = { [K in keyof M]: ZodType<M[K]> };
/** Schema defines state validation */
export type Schema<S extends State> = ZodType<S>;

/**
* System schemas for
* - `schemas.commands` input validation
* - `schemas.events` output validation
*/
export type SystemSchemas<C extends Messages, E extends Messages> = {
commands: Schemas<C>;
events: Schemas<E>;
};

/**
* Aggregate schemas for
* - `schemas.state` state documentation
Expand Down Expand Up @@ -125,19 +114,6 @@ export type Reducible<
reducer?: StateReducer<S>;
};

/**
* Systems handle commands and produce a stream of committed events
* - `schemas` for message validation and documentation
* - `on` command handlers
*/
export type System<
C extends Messages = Messages,
E extends Messages = Messages
> = Streamable & {
schemas: SystemSchemas<C, E>;
on: { [K in keyof C]: CommandHandler<State, C, E, K> };
};

/**
* Aggregates handle commands and produce committed events while holding an internal reducible state.
* Aggregates enforce a consistency boundaries around business models.
Expand Down Expand Up @@ -230,7 +206,7 @@ export type CommandHandlingArtifact<
S extends State = State,
C extends Messages = Messages,
E extends Messages = Messages
> = Aggregate<S, C, E> | System<C, E>;
> = Aggregate<S, C, E>;

/** All event handling artifacts */
export type EventHandlingArtifact<
Expand Down Expand Up @@ -258,45 +234,31 @@ export type Infer<T> = T extends ZodRawShape
[K in keyof T]: z.infer<T[K]>;
}
: T extends ZodTypeAny
? z.infer<T>
: never;

/** Helper to infer system types from schemas */
export type InferSystem<Z> = Z extends SystemSchemas<infer C, infer E>
? System<C, E>
: never;
? z.infer<T>
: never;

/** Helper to infer aggregate types from schemas */
export type InferAggregate<Z> = Z extends AggregateSchemas<
infer S,
infer C,
infer E
>
? Aggregate<S, C, E>
: never;
export type InferAggregate<Z> =
Z extends AggregateSchemas<infer S, infer C, infer E>
? Aggregate<S, C, E>
: never;

/** Helper to infer policy types from schemas */
export type InferPolicy<Z> = Z extends PolicySchemas<infer C, infer E>
? Policy<C, E>
: never;
export type InferPolicy<Z> =
Z extends PolicySchemas<infer C, infer E> ? Policy<C, E> : never;

/** Helper to infer process manager types from schemas */
export type InferProcessManager<
Z,
O extends Messages
> = Z extends ProcessManagerSchemas<infer S, infer C, infer E>
? ProcessManager<S, C, E, O>
: never;
export type InferProcessManager<Z, O extends Messages> =
Z extends ProcessManagerSchemas<infer S, infer C, infer E>
? ProcessManager<S, C, E, O>
: never;

/** Helper to infer command adapter types from schemas */
export type InferCommandAdapter<Z> = Z extends CommandAdapterSchemas<
infer S,
infer C
>
? CommandAdapter<S, C>
: never;
export type InferCommandAdapter<Z> =
Z extends CommandAdapterSchemas<infer S, infer C>
? CommandAdapter<S, C>
: never;

/** Helper to infer projector types from schemas */
export type InferProjector<Z> = Z extends ProjectorSchemas<infer S, infer E>
? Projector<S, E>
: never;
export type InferProjector<Z> =
Z extends ProjectorSchemas<infer S, infer E> ? Projector<S, E> : never;
Loading

1 comment on commit 1dd6311

@TomKaltz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rotorsoft fix?

Please sign in to comment.