Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ const writtenEvents = await client.writeEvents([

*Note that according to the CloudEvents standard, event IDs must be of type string.*

#### Using the `isEventQlTrue` precondition
#### Using the `isEventQlQueryTrue` precondition

If you want to write events depending on an EventQL query, import the `isEventQlTrue` function and pass it as an array of preconditions in the second argument:
If you want to write events depending on an EventQL query, import the `isEventQlQueryTrue` function and pass it as an array of preconditions in the second argument:

```typescript
import { isEventQlTrue } from 'eventsourcingdb';
import { isEventQlQueryTrue } from 'eventsourcingdb';

const writtenEvents = await client.writeEvents([
// events
], [
isEventQlTrue(`FROM e IN events WHERE e.type == 'io.eventsourcingdb.library.book-borrowed' PROJECT INTO COUNT() < 10`)
isEventQlQueryTrue(`FROM e IN events WHERE e.type == 'io.eventsourcingdb.library.book-borrowed' PROJECT INTO COUNT() < 10`)
]);
```

Expand Down
6 changes: 3 additions & 3 deletions src/Precondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface IsSubjectOnEventIdPrecondition {
eventId: string;
}

interface IsEventQlTruePrecondition {
interface IsEventQlQueryTruePrecondition {
query: string;
}

Expand All @@ -21,8 +21,8 @@ type Precondition =
payload: IsSubjectOnEventIdPrecondition;
}
| {
type: 'isEventQlTrue';
payload: IsEventQlTruePrecondition;
type: 'isEventQlQueryTrue';
payload: IsEventQlQueryTruePrecondition;
};

export type { Precondition };
10 changes: 10 additions & 0 deletions src/isEventQlQueryTrue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Precondition } from './Precondition.js';

const isEventQlQueryTrue = (query: string): Precondition => {
return {
type: 'isEventQlQueryTrue',
payload: { query },
};
};

export { isEventQlQueryTrue };
10 changes: 0 additions & 10 deletions src/isEventQlTrue.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/writeEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeEach, suite, test } from 'node:test';
import { Container } from './Container.js';
import type { EventCandidate } from './EventCandidate.js';
import { getImageVersionFromDockerfile } from './getImageVersionFromDockerfile.js';
import { isEventQlTrue } from './isEventQlTrue.js';
import { isEventQlQueryTrue } from './isEventQlQueryTrue.js';
import { isSubjectOnEventId } from './isSubjectOnEventId.js';
import { isSubjectPristine } from './isSubjectPristine.js';

Expand Down Expand Up @@ -145,7 +145,7 @@ suite('writeEvents', { timeout: 30_000 }, () => {
);
});

test('supports the isEventQlTrue precondition.', async (): Promise<void> => {
test('supports the isEventQlQueryTrue precondition.', async (): Promise<void> => {
const client = container.getClient();

const firstEvent: EventCandidate = {
Expand All @@ -172,7 +172,7 @@ suite('writeEvents', { timeout: 30_000 }, () => {
async () => {
await client.writeEvents(
[secondEvent],
[isEventQlTrue('FROM e IN events PROJECT INTO COUNT() == 0')],
[isEventQlQueryTrue('FROM e IN events PROJECT INTO COUNT() == 0')],
);
},
error => {
Expand Down