feat: add epoch event stream to aggregate id
This commit is contained in:
@@ -2,7 +2,6 @@ import { assertEquals, assertObjectMatch, assertRejects } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
|
||||
import { EventInsertionError, EventValidationError } from "../../libraries/errors.ts";
|
||||
import { makeId } from "../../libraries/nanoid.ts";
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
import { describe } from "../utilities/describe.ts";
|
||||
|
||||
@@ -58,7 +57,7 @@ export default describe<Events>(".addEvent", (getEventStore) => {
|
||||
it("should insert and project 'user:created' event", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
|
||||
const stream = makeId();
|
||||
const stream = crypto.randomUUID();
|
||||
const event = store.event({
|
||||
stream,
|
||||
type: "user:created",
|
||||
@@ -93,7 +92,7 @@ export default describe<Events>(".addEvent", (getEventStore) => {
|
||||
},
|
||||
});
|
||||
|
||||
const stream = makeId();
|
||||
const stream = crypto.randomUUID();
|
||||
const event = store.event({
|
||||
stream,
|
||||
type: "user:created",
|
||||
@@ -121,7 +120,7 @@ export default describe<Events>(".addEvent", (getEventStore) => {
|
||||
it("should insert 'user:created' and add it to 'tenant:xyz' relation", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
|
||||
const key = `tenant:${makeId()}`;
|
||||
const key = `tenant:${crypto.randomUUID()}`;
|
||||
|
||||
projector.on("user:created", async ({ stream }) => {
|
||||
await store.relations.insert(key, stream);
|
||||
@@ -171,7 +170,7 @@ export default describe<Events>(".addEvent", (getEventStore) => {
|
||||
it("should insert 'user:email-set' and remove it from 'tenant:xyz' relations", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
|
||||
const key = `tenant:${makeId()}`;
|
||||
const key = `tenant:${crypto.randomUUID()}`;
|
||||
|
||||
projector.on("user:created", async ({ stream }) => {
|
||||
await store.relations.insert(key, stream);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { assertEquals, assertObjectMatch, assertRejects } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import { EventValidationError } from "../../mod.ts";
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
@@ -10,7 +9,7 @@ import { describe } from "../utilities/describe.ts";
|
||||
export default describe<Events>(".addSequence", (getEventStore) => {
|
||||
it("should insert 'user:created', 'user:name:given-set', and 'user:email-set' in a sequence of events", async () => {
|
||||
const { store } = await getEventStore();
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
const events = [
|
||||
store.event({
|
||||
@@ -63,7 +62,7 @@ export default describe<Events>(".addSequence", (getEventStore) => {
|
||||
|
||||
it("should not commit any events when insert fails", async () => {
|
||||
const { store } = await getEventStore();
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
await assertRejects(
|
||||
async () =>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { assertEquals, assertNotEquals, assertObjectMatch } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
import { userReducer } from "../mocks/user-reducer.ts";
|
||||
@@ -9,7 +8,7 @@ import { describe } from "../utilities/describe.ts";
|
||||
export default describe<Events>(".createSnapshot", (getEventStore) => {
|
||||
it("should create a new snapshot", async () => {
|
||||
const { store } = await getEventStore();
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
await store.pushEvent(
|
||||
store.event({
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import { makeId } from "../../libraries/nanoid.ts";
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
import { userPostReducer } from "../mocks/user-posts-reducer.ts";
|
||||
import { userReducer } from "../mocks/user-reducer.ts";
|
||||
@@ -12,8 +10,8 @@ export default describe<Events>(".makeReducer", (getEventStore) => {
|
||||
it("should create a 'user' reducer and only reduce filtered events", async () => {
|
||||
const { store } = await getEventStore();
|
||||
|
||||
const streamA = nanoid();
|
||||
const streamB = nanoid();
|
||||
const streamA = crypto.randomUUID();
|
||||
const streamB = crypto.randomUUID();
|
||||
|
||||
await store.pushEvent(
|
||||
store.event({
|
||||
@@ -95,15 +93,15 @@ export default describe<Events>(".makeReducer", (getEventStore) => {
|
||||
|
||||
it("should create a 'post:count' reducer and retrieve post correct post count", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
const auditor = nanoid();
|
||||
const auditor = crypto.randomUUID();
|
||||
|
||||
projector.on("post:created", async ({ stream, meta: { auditor } }) => {
|
||||
await store.relations.insert(`user:${auditor}:posts`, stream);
|
||||
});
|
||||
|
||||
const post1 = makeId();
|
||||
const post2 = makeId();
|
||||
const post3 = makeId();
|
||||
const post1 = crypto.randomUUID();
|
||||
const post2 = crypto.randomUUID();
|
||||
const post3 = crypto.randomUUID();
|
||||
|
||||
await store.pushEvent(
|
||||
store.event({
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { assertEquals, assertObjectMatch } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
|
||||
import { makeId } from "../../libraries/nanoid.ts";
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
import { describe } from "../utilities/describe.ts";
|
||||
|
||||
@@ -9,7 +8,7 @@ export default describe<Events>("projector.once", (getEventStore) => {
|
||||
it("should handle successfull projection", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
|
||||
const stream = makeId();
|
||||
const stream = crypto.randomUUID();
|
||||
const event = store.event({
|
||||
stream,
|
||||
type: "user:created",
|
||||
@@ -51,7 +50,7 @@ export default describe<Events>("projector.once", (getEventStore) => {
|
||||
it("should handle failed projection", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
|
||||
const stream = makeId();
|
||||
const stream = crypto.randomUUID();
|
||||
const event = store.event({
|
||||
stream,
|
||||
type: "user:created",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import type { Events } from "../../mocks/events.ts";
|
||||
import { describe } from "../../utilities/describe.ts";
|
||||
@@ -10,7 +9,7 @@ export default describe<Events>("relations", (getEventStore) => {
|
||||
const { store } = await getEventStore();
|
||||
|
||||
const key = "sample";
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
await store.relations.insert(key, stream);
|
||||
|
||||
@@ -21,7 +20,7 @@ export default describe<Events>("relations", (getEventStore) => {
|
||||
const { store } = await getEventStore();
|
||||
|
||||
const key = "sample";
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
await store.relations.insertMany([
|
||||
{ key, stream },
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
import { userReducer } from "../mocks/user-reducer.ts";
|
||||
@@ -9,7 +8,7 @@ import { describe } from "../utilities/describe.ts";
|
||||
export default describe<Events>(".reduce", (getEventStore) => {
|
||||
it("should return reduced state", async () => {
|
||||
const { store } = await getEventStore();
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
await store.pushEvent(
|
||||
store.event({
|
||||
@@ -51,7 +50,7 @@ export default describe<Events>(".reduce", (getEventStore) => {
|
||||
|
||||
it("should return snapshot if it exists and no new events were found", async () => {
|
||||
const { store } = await getEventStore();
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
await store.pushEvent(
|
||||
store.event({
|
||||
@@ -94,7 +93,7 @@ export default describe<Events>(".reduce", (getEventStore) => {
|
||||
});
|
||||
|
||||
it("should return undefined if stream does not have events", async () => {
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
const { store } = await getEventStore();
|
||||
const state = await store.reduce({ name: "user", stream, reducer: userReducer });
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { assertObjectMatch } from "@std/assert";
|
||||
import { it } from "@std/testing/bdd";
|
||||
import { nanoid } from "nanoid";
|
||||
|
||||
import type { Events } from "../mocks/events.ts";
|
||||
import { describe } from "../utilities/describe.ts";
|
||||
@@ -8,7 +7,7 @@ import { describe } from "../utilities/describe.ts";
|
||||
export default describe<Events>(".replayEvents", (getEventStore) => {
|
||||
it("should replay events", async () => {
|
||||
const { store, projector } = await getEventStore();
|
||||
const stream = nanoid();
|
||||
const stream = crypto.randomUUID();
|
||||
|
||||
const record: Record<string, any> = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user