eventsourcingdb 1.0.2 → 1.2.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 +24 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -94,6 +94,22 @@ const writtenEvents = await client.writeEvents([
|
|
|
94
94
|
|
|
95
95
|
*Note that according to the CloudEvents standard, event IDs must be of type string.*
|
|
96
96
|
|
|
97
|
+
#### Using the `isEventQlTrue` precondition
|
|
98
|
+
|
|
99
|
+
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:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { isEventQlTrue } from 'eventsourcingdb';
|
|
103
|
+
|
|
104
|
+
const writtenEvents = await client.writeEvents([
|
|
105
|
+
// events
|
|
106
|
+
], [
|
|
107
|
+
isEventQlTrue(`FROM e IN events WHERE e.type == 'io.eventsourcingdb.library.book-borrowed' PROJECT INTO COUNT() < 10`)
|
|
108
|
+
]);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
*Note that the query must return a single row with a single value, which is interpreted as a boolean.*
|
|
112
|
+
|
|
97
113
|
### Reading Events
|
|
98
114
|
|
|
99
115
|
To read all events of a subject, call the `readEvents` function with the subject as the first argument and an options object as the second argument. Set the `recursive` option to `false`. This ensures that only events of the given subject are returned, not events of nested subjects.
|
|
@@ -401,6 +417,14 @@ for await (const eventType of client.readEventTypes()) {
|
|
|
401
417
|
controller.abort();
|
|
402
418
|
```
|
|
403
419
|
|
|
420
|
+
### Listing a Specific Event Type
|
|
421
|
+
|
|
422
|
+
To list a specific event type, call the `readEventType` function with the event type as an argument. The function returns the detailed event type, which includes the schema:
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
eventType = await client.readEventType("io.eventsourcingdb.library.book-acquired")
|
|
426
|
+
```
|
|
427
|
+
|
|
404
428
|
### Using Testcontainers
|
|
405
429
|
|
|
406
430
|
Import the `Container` class, create an instance, call the `start` function to run a test container, get a client, run your test code, and finally call the `stop` function to stop the test container:
|
package/dist/index.d.mts
CHANGED
|
@@ -53,12 +53,18 @@ interface IsSubjectOnEventIdPrecondition {
|
|
|
53
53
|
subject: string;
|
|
54
54
|
eventId: string;
|
|
55
55
|
}
|
|
56
|
+
interface IsEventQlTruePrecondition {
|
|
57
|
+
query: string;
|
|
58
|
+
}
|
|
56
59
|
type Precondition = {
|
|
57
60
|
type: 'isSubjectPristine';
|
|
58
61
|
payload: IsSubjectPristinePrecondition;
|
|
59
62
|
} | {
|
|
60
63
|
type: 'isSubjectOnEventId';
|
|
61
64
|
payload: IsSubjectOnEventIdPrecondition;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'isEventQlTrue';
|
|
67
|
+
payload: IsEventQlTruePrecondition;
|
|
62
68
|
};
|
|
63
69
|
|
|
64
70
|
type Order = 'chronological' | 'antichronological';
|
|
@@ -87,6 +93,7 @@ declare class Client {
|
|
|
87
93
|
observeEvents(subject: string, options: ObserveEventsOptions, signal?: AbortSignal): AsyncGenerator<Event, void, void>;
|
|
88
94
|
registerEventSchema(eventType: string, schema: Record<string, unknown>): Promise<void>;
|
|
89
95
|
readSubjects(baseSubject: string, signal?: AbortSignal): AsyncGenerator<string, void, void>;
|
|
96
|
+
readEventType(eventType: string): Promise<EventType>;
|
|
90
97
|
readEventTypes(signal?: AbortSignal): AsyncGenerator<EventType, void, void>;
|
|
91
98
|
}
|
|
92
99
|
|
package/dist/index.d.ts
CHANGED
|
@@ -53,12 +53,18 @@ interface IsSubjectOnEventIdPrecondition {
|
|
|
53
53
|
subject: string;
|
|
54
54
|
eventId: string;
|
|
55
55
|
}
|
|
56
|
+
interface IsEventQlTruePrecondition {
|
|
57
|
+
query: string;
|
|
58
|
+
}
|
|
56
59
|
type Precondition = {
|
|
57
60
|
type: 'isSubjectPristine';
|
|
58
61
|
payload: IsSubjectPristinePrecondition;
|
|
59
62
|
} | {
|
|
60
63
|
type: 'isSubjectOnEventId';
|
|
61
64
|
payload: IsSubjectOnEventIdPrecondition;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'isEventQlTrue';
|
|
67
|
+
payload: IsEventQlTruePrecondition;
|
|
62
68
|
};
|
|
63
69
|
|
|
64
70
|
type Order = 'chronological' | 'antichronological';
|
|
@@ -87,6 +93,7 @@ declare class Client {
|
|
|
87
93
|
observeEvents(subject: string, options: ObserveEventsOptions, signal?: AbortSignal): AsyncGenerator<Event, void, void>;
|
|
88
94
|
registerEventSchema(eventType: string, schema: Record<string, unknown>): Promise<void>;
|
|
89
95
|
readSubjects(baseSubject: string, signal?: AbortSignal): AsyncGenerator<string, void, void>;
|
|
96
|
+
readEventType(eventType: string): Promise<EventType>;
|
|
90
97
|
readEventTypes(signal?: AbortSignal): AsyncGenerator<EventType, void, void>;
|
|
91
98
|
}
|
|
92
99
|
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var
|
|
2
|
-
`),a!==-1;){let
|
|
1
|
+
"use strict";var E=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var F=(r,t)=>{for(var e in t)E(r,e,{get:t[e],enumerable:!0})},L=(r,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of k(t))!$.call(r,i)&&i!==e&&E(r,i,{get:()=>t[i],enumerable:!(o=x(t,i))||o.enumerable});return r};var R=r=>L(E({},"__esModule",{value:!0}),r);var M={};F(M,{Client:()=>y,Container:()=>b,isSubjectOnEventId:()=>O,isSubjectPristine:()=>C});module.exports=R(M);var v=r=>({...r,time:new Date(r.time)});var c=(r,t)=>{if(typeof t!=typeof r)return!1;if(t===null||r===null)return t===null&&r===null;if(typeof t=="object"){if(Array.isArray(t)||Array.isArray(r))return!1;let e=t,o=r;for(let i of Object.keys(e))if(!(i in o)||!c(o[i],e[i]))return!1;return!0}return!0};var H={specversion:"string",id:"string",time:"string",source:"string",subject:"string",type:"string",datacontenttype:"string",data:{},hash:"string",predecessorhash:"string"},S=r=>c(r,H);var l=async function*(r,t){let e=r.getReader(),o=new TextDecoder("utf-8"),i="",p=()=>{e.cancel().catch(()=>{})};if(t.aborted){await e.cancel().catch(()=>{});return}t.addEventListener("abort",p);try{for(;!t.aborted;){let{done:d,value:u}=await e.read();if(d)break;i+=o.decode(u,{stream:!0});let a;for(;a=i.indexOf(`
|
|
2
|
+
`),a!==-1;){let n=i.slice(0,a).trim();i=i.slice(a+1),n&&(yield JSON.parse(n))}}}finally{t.removeEventListener("abort",p),await e.cancel().catch(()=>{})}};var B={type:"event",payload:{specversion:"string",id:"string",time:"string",source:"string",subject:"string",type:"string",datacontenttype:"string",data:{},hash:"string",predecessorhash:"string"}},g=r=>!(!c(r,B)||r.type!=="event");var I={type:"error",payload:{error:"string"}},m=r=>!(!c(r,I)||r.type!=="error");var N={type:"eventType",payload:{eventType:"string",isPhantom:!0}},T=r=>!(!c(r,N)||r.type!=="eventType");var J={type:"heartbeat"},h=r=>!(!c(r,J)||r.type!=="heartbeat");var z={type:"row"},j=r=>!(!c(r,z)||r.type!=="row"||!("payload"in r));var U={type:"subject",payload:{subject:"string"}},A=r=>!(!c(r,U)||r.type!=="subject");var y=class{#o;#e;#t(t){return new URL(t,this.#o).toString()}constructor(t,e){this.#o=t,this.#e=e}async ping(){let t=this.#t("/api/v1/ping"),e=await fetch(t,{method:"get"});if(e.status!==200)throw new Error(`Failed to ping, got HTTP status code '${e.status}', expected '200'.`);let o=await e.json();if(!c(o,{type:"string"}))throw new Error("Failed to parse response.");if(o.type!=="io.eventsourcingdb.api.ping-received")throw new Error("Failed to ping.")}async verifyApiToken(){let t=this.#t("/api/v1/verify-api-token"),e=await fetch(t,{method:"post",headers:{authorization:`Bearer ${this.#e}`}});if(e.status!==200)throw new Error(`Failed to verify API token, got HTTP status code '${e.status}', expected '200'.`);let o=await e.json();if(!c(o,{type:"string"}))throw new Error("Failed to parse response.");if(o.type!=="io.eventsourcingdb.api.api-token-verified")throw new Error("Failed to verify API token.")}async writeEvents(t,e=[]){let o=this.#t("/api/v1/write-events"),i=await fetch(o,{method:"post",headers:{authorization:`Bearer ${this.#e}`,"content-type":"application/json"},body:JSON.stringify({events:t,preconditions:e})});if(i.status!==200)throw new Error(`Failed to write events, got HTTP status code '${i.status}', expected '200'.`);let p=await i.json();if(!Array.isArray(p))throw new Error("Failed to parse response.");return p.map(u=>{if(!S(u))throw new Error("Failed to parse response item.");return v(u)})}readEvents(t,e,o){let i=this.#t("/api/v1/read-events"),p=this.#e;return async function*(){let d=new AbortController,u=o??d.signal,a=!o,n;if(o&&!o.aborted){let s=()=>d.abort();o.addEventListener("abort",s,{once:!0}),n=()=>o.removeEventListener("abort",s)}try{let s=await fetch(i,{method:"post",headers:{authorization:`Bearer ${p}`,"content-type":"application/json"},body:JSON.stringify({subject:t,options:e}),signal:u});if(s.status!==200)throw new Error(`Failed to read events, got HTTP status code '${s.status}', expected '200'.`);if(!s.body)throw new Error("Failed to read events.");for await(let f of l(s.body,u)){if(m(f))throw new Error(`${f.payload.error}.`);if(g(f)){yield v(f.payload);continue}throw new Error("Failed to read events.")}}catch(s){if(s instanceof DOMException&&s.name==="AbortError")return;throw s}finally{n&&n(),a&&d.abort()}}()}runEventQlQuery(t,e){let o=this.#t("/api/v1/run-eventql-query"),i=this.#e;return async function*(){let p=new AbortController,d=e??p.signal,u=!e,a;if(e&&!e.aborted){let n=()=>p.abort();e.addEventListener("abort",n,{once:!0}),a=()=>e.removeEventListener("abort",n)}try{let n=await fetch(o,{method:"post",headers:{authorization:`Bearer ${i}`,"content-type":"application/json"},body:JSON.stringify({query:t}),signal:d});if(n.status!==200)throw new Error(`Failed to run EventQL query, got HTTP status code '${n.status}', expected '200'.`);if(!n.body)throw new Error("Failed to run EventQL query.");for await(let s of l(n.body,d))if(!h(s)){if(m(s))throw new Error(`${s.payload.error}.`);if(j(s)){yield s.payload;continue}throw new Error("Failed to run EventQL query.")}}catch(n){if(n instanceof DOMException&&n.name==="AbortError")return;throw n}finally{a&&a(),u&&p.abort()}}()}observeEvents(t,e,o){let i=this.#t("/api/v1/observe-events"),p=this.#e;return async function*(){let d=new AbortController,u=o??d.signal,a=!o,n;if(o&&!o.aborted){let s=()=>d.abort();o.addEventListener("abort",s,{once:!0}),n=()=>o.removeEventListener("abort",s)}try{let s=await fetch(i,{method:"post",headers:{authorization:`Bearer ${p}`,"content-type":"application/json"},body:JSON.stringify({subject:t,options:e}),signal:u});if(s.status!==200)throw new Error(`Failed to observe events, got HTTP status code '${s.status}', expected '200'.`);if(!s.body)throw new Error("Failed to observe events.");for await(let f of l(s.body,u))if(!h(f)){if(m(f))throw new Error(`${f.payload.error}.`);if(g(f)){yield v(f.payload);continue}throw new Error("Failed to observe events.")}}catch(s){if(s instanceof DOMException&&s.name==="AbortError")return;throw s}finally{n&&n(),a&&d.abort()}}()}async registerEventSchema(t,e){let o=this.#t("/api/v1/register-event-schema"),i=await fetch(o,{method:"post",headers:{authorization:`Bearer ${this.#e}`,"content-type":"application/json"},body:JSON.stringify({eventType:t,schema:e})});if(i.status!==200)throw new Error(`Failed to register event schema, got HTTP status code '${i.status}', expected '200'.`)}readSubjects(t,e){let o=this.#t("/api/v1/read-subjects"),i=this.#e;return async function*(){let p=new AbortController,d=e??p.signal,u=!e,a;if(e&&!e.aborted){let n=()=>p.abort();e.addEventListener("abort",n,{once:!0}),a=()=>e.removeEventListener("abort",n)}try{let n=await fetch(o,{method:"post",headers:{authorization:`Bearer ${i}`,"content-type":"application/json"},body:JSON.stringify({baseSubject:t}),signal:d});if(n.status!==200)throw new Error(`Failed to read subjects, got HTTP status code '${n.status}', expected '200'.`);if(!n.body)throw new Error("Failed to read subjects.");for await(let s of l(n.body,d)){if(m(s))throw new Error(`${s.payload.error}.`);if(A(s)){yield s.payload.subject;continue}throw new Error("Failed to read subjects.")}}catch(n){if(n instanceof DOMException&&n.name==="AbortError")return;throw n}finally{a&&a(),u&&p.abort()}}()}async readEventType(t){let e=this.#t("/api/v1/read-event-type"),o=await fetch(e,{method:"post",headers:{authorization:`Bearer ${this.#e}`,"content-type":"application/json"},body:JSON.stringify({eventType:t})});if(o.status!==200)throw new Error(`Failed to read event type, got HTTP status code '${o.status}', expected '200'.`);let i=await o.json();if(!c(i,{eventType:"string",isPhantom:!0}))throw new Error("Failed to parse response.");return i}readEventTypes(t){let e=this.#t("/api/v1/read-event-types"),o=this.#e;return async function*(){let i=new AbortController,p=t??i.signal,d=!t,u;if(t&&!t.aborted){let a=()=>i.abort();t.addEventListener("abort",a,{once:!0}),u=()=>t.removeEventListener("abort",a)}try{let a=await fetch(e,{method:"post",headers:{authorization:`Bearer ${o}`},signal:p});if(a.status!==200)throw new Error(`Failed to read event types, got HTTP status code '${a.status}', expected '200'.`);if(!a.body)throw new Error("Failed to read event types.");for await(let n of l(a.body,p))if(!h(n)){if(m(n))throw new Error(`${n.payload.error}.`);if(T(n)){yield n.payload;continue}throw new Error("Failed to read event types.")}}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;throw a}finally{u&&u(),d&&i.abort()}}()}};var w=require("testcontainers");var b=class{#o="thenativeweb/eventsourcingdb";#e="latest";#t=3e3;#n="secret";#r;withImageTag(t){return this.#e=t,this}withApiToken(t){return this.#n=t,this}withPort(t){return this.#t=t,this}async start(){this.#r=await new w.GenericContainer(`${this.#o}:${this.#e}`).withExposedPorts(this.#t).withCommand(["run","--api-token",this.#n,"--data-directory-temporary","--http-enabled","--https-enabled=false"]).withWaitStrategy(w.Wait.forHttp("/api/v1/ping",this.#t).withStartupTimeout(1e4)).start()}getHost(){if(this.#r===void 0)throw new Error("Container must be running.");return this.#r.getHost()}getMappedPort(){if(this.#r===void 0)throw new Error("Container must be running.");return this.#r.getMappedPort(this.#t)}getBaseUrl(){if(this.#r===void 0)throw new Error("Container must be running.");let t=this.getHost(),e=this.getMappedPort();return new URL(`http://${t}:${e}`)}getApiToken(){return this.#n}isRunning(){return this.#r!==void 0}async stop(){this.#r!==void 0&&(await this.#r.stop(),this.#r=void 0)}getClient(){return new y(this.getBaseUrl(),this.getApiToken())}};var O=(r,t)=>({type:"isSubjectOnEventId",payload:{subject:r,eventId:t}});var C=r=>({type:"isSubjectPristine",payload:{subject:r}});0&&(module.exports={Client,Container,isSubjectOnEventId,isSubjectPristine});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),a!==-1;){let r=s.slice(0,a).trim();s=s.slice(a+1),r&&(yield JSON.parse(r))}}}finally{t.removeEventListener("abort",p),await e.cancel().catch(()=>{})}};var O={type:"event",payload:{specversion:"string",id:"string",time:"string",source:"string",subject:"string",type:"string",datacontenttype:"string",data:{},hash:"string",predecessorhash:"string"}},b=
|
|
1
|
+
var v=n=>({...n,time:new Date(n.time)});var c=(n,t)=>{if(typeof t!=typeof n)return!1;if(t===null||n===null)return t===null&&n===null;if(typeof t=="object"){if(Array.isArray(t)||Array.isArray(n))return!1;let e=t,o=n;for(let s of Object.keys(e))if(!(s in o)||!c(o[s],e[s]))return!1;return!0}return!0};var A={specversion:"string",id:"string",time:"string",source:"string",subject:"string",type:"string",datacontenttype:"string",data:{},hash:"string",predecessorhash:"string"},E=n=>c(n,A);var l=async function*(n,t){let e=n.getReader(),o=new TextDecoder("utf-8"),s="",p=()=>{e.cancel().catch(()=>{})};if(t.aborted){await e.cancel().catch(()=>{});return}t.addEventListener("abort",p);try{for(;!t.aborted;){let{done:d,value:u}=await e.read();if(d)break;s+=o.decode(u,{stream:!0});let a;for(;a=s.indexOf(`
|
|
2
|
+
`),a!==-1;){let r=s.slice(0,a).trim();s=s.slice(a+1),r&&(yield JSON.parse(r))}}}finally{t.removeEventListener("abort",p),await e.cancel().catch(()=>{})}};var O={type:"event",payload:{specversion:"string",id:"string",time:"string",source:"string",subject:"string",type:"string",datacontenttype:"string",data:{},hash:"string",predecessorhash:"string"}},b=n=>!(!c(n,O)||n.type!=="event");var C={type:"error",payload:{error:"string"}},m=n=>!(!c(n,C)||n.type!=="error");var P={type:"eventType",payload:{eventType:"string",isPhantom:!0}},g=n=>!(!c(n,P)||n.type!=="eventType");var x={type:"heartbeat"},h=n=>!(!c(n,x)||n.type!=="heartbeat");var k={type:"row"},S=n=>!(!c(n,k)||n.type!=="row"||!("payload"in n));var $={type:"subject",payload:{subject:"string"}},T=n=>!(!c(n,$)||n.type!=="subject");var y=class{#o;#e;#t(t){return new URL(t,this.#o).toString()}constructor(t,e){this.#o=t,this.#e=e}async ping(){let t=this.#t("/api/v1/ping"),e=await fetch(t,{method:"get"});if(e.status!==200)throw new Error(`Failed to ping, got HTTP status code '${e.status}', expected '200'.`);let o=await e.json();if(!c(o,{type:"string"}))throw new Error("Failed to parse response.");if(o.type!=="io.eventsourcingdb.api.ping-received")throw new Error("Failed to ping.")}async verifyApiToken(){let t=this.#t("/api/v1/verify-api-token"),e=await fetch(t,{method:"post",headers:{authorization:`Bearer ${this.#e}`}});if(e.status!==200)throw new Error(`Failed to verify API token, got HTTP status code '${e.status}', expected '200'.`);let o=await e.json();if(!c(o,{type:"string"}))throw new Error("Failed to parse response.");if(o.type!=="io.eventsourcingdb.api.api-token-verified")throw new Error("Failed to verify API token.")}async writeEvents(t,e=[]){let o=this.#t("/api/v1/write-events"),s=await fetch(o,{method:"post",headers:{authorization:`Bearer ${this.#e}`,"content-type":"application/json"},body:JSON.stringify({events:t,preconditions:e})});if(s.status!==200)throw new Error(`Failed to write events, got HTTP status code '${s.status}', expected '200'.`);let p=await s.json();if(!Array.isArray(p))throw new Error("Failed to parse response.");return p.map(u=>{if(!E(u))throw new Error("Failed to parse response item.");return v(u)})}readEvents(t,e,o){let s=this.#t("/api/v1/read-events"),p=this.#e;return async function*(){let d=new AbortController,u=o??d.signal,a=!o,r;if(o&&!o.aborted){let i=()=>d.abort();o.addEventListener("abort",i,{once:!0}),r=()=>o.removeEventListener("abort",i)}try{let i=await fetch(s,{method:"post",headers:{authorization:`Bearer ${p}`,"content-type":"application/json"},body:JSON.stringify({subject:t,options:e}),signal:u});if(i.status!==200)throw new Error(`Failed to read events, got HTTP status code '${i.status}', expected '200'.`);if(!i.body)throw new Error("Failed to read events.");for await(let f of l(i.body,u)){if(m(f))throw new Error(`${f.payload.error}.`);if(b(f)){yield v(f.payload);continue}throw new Error("Failed to read events.")}}catch(i){if(i instanceof DOMException&&i.name==="AbortError")return;throw i}finally{r&&r(),a&&d.abort()}}()}runEventQlQuery(t,e){let o=this.#t("/api/v1/run-eventql-query"),s=this.#e;return async function*(){let p=new AbortController,d=e??p.signal,u=!e,a;if(e&&!e.aborted){let r=()=>p.abort();e.addEventListener("abort",r,{once:!0}),a=()=>e.removeEventListener("abort",r)}try{let r=await fetch(o,{method:"post",headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},body:JSON.stringify({query:t}),signal:d});if(r.status!==200)throw new Error(`Failed to run EventQL query, got HTTP status code '${r.status}', expected '200'.`);if(!r.body)throw new Error("Failed to run EventQL query.");for await(let i of l(r.body,d))if(!h(i)){if(m(i))throw new Error(`${i.payload.error}.`);if(S(i)){yield i.payload;continue}throw new Error("Failed to run EventQL query.")}}catch(r){if(r instanceof DOMException&&r.name==="AbortError")return;throw r}finally{a&&a(),u&&p.abort()}}()}observeEvents(t,e,o){let s=this.#t("/api/v1/observe-events"),p=this.#e;return async function*(){let d=new AbortController,u=o??d.signal,a=!o,r;if(o&&!o.aborted){let i=()=>d.abort();o.addEventListener("abort",i,{once:!0}),r=()=>o.removeEventListener("abort",i)}try{let i=await fetch(s,{method:"post",headers:{authorization:`Bearer ${p}`,"content-type":"application/json"},body:JSON.stringify({subject:t,options:e}),signal:u});if(i.status!==200)throw new Error(`Failed to observe events, got HTTP status code '${i.status}', expected '200'.`);if(!i.body)throw new Error("Failed to observe events.");for await(let f of l(i.body,u))if(!h(f)){if(m(f))throw new Error(`${f.payload.error}.`);if(b(f)){yield v(f.payload);continue}throw new Error("Failed to observe events.")}}catch(i){if(i instanceof DOMException&&i.name==="AbortError")return;throw i}finally{r&&r(),a&&d.abort()}}()}async registerEventSchema(t,e){let o=this.#t("/api/v1/register-event-schema"),s=await fetch(o,{method:"post",headers:{authorization:`Bearer ${this.#e}`,"content-type":"application/json"},body:JSON.stringify({eventType:t,schema:e})});if(s.status!==200)throw new Error(`Failed to register event schema, got HTTP status code '${s.status}', expected '200'.`)}readSubjects(t,e){let o=this.#t("/api/v1/read-subjects"),s=this.#e;return async function*(){let p=new AbortController,d=e??p.signal,u=!e,a;if(e&&!e.aborted){let r=()=>p.abort();e.addEventListener("abort",r,{once:!0}),a=()=>e.removeEventListener("abort",r)}try{let r=await fetch(o,{method:"post",headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},body:JSON.stringify({baseSubject:t}),signal:d});if(r.status!==200)throw new Error(`Failed to read subjects, got HTTP status code '${r.status}', expected '200'.`);if(!r.body)throw new Error("Failed to read subjects.");for await(let i of l(r.body,d)){if(m(i))throw new Error(`${i.payload.error}.`);if(T(i)){yield i.payload.subject;continue}throw new Error("Failed to read subjects.")}}catch(r){if(r instanceof DOMException&&r.name==="AbortError")return;throw r}finally{a&&a(),u&&p.abort()}}()}async readEventType(t){let e=this.#t("/api/v1/read-event-type"),o=await fetch(e,{method:"post",headers:{authorization:`Bearer ${this.#e}`,"content-type":"application/json"},body:JSON.stringify({eventType:t})});if(o.status!==200)throw new Error(`Failed to read event type, got HTTP status code '${o.status}', expected '200'.`);let s=await o.json();if(!c(s,{eventType:"string",isPhantom:!0}))throw new Error("Failed to parse response.");return s}readEventTypes(t){let e=this.#t("/api/v1/read-event-types"),o=this.#e;return async function*(){let s=new AbortController,p=t??s.signal,d=!t,u;if(t&&!t.aborted){let a=()=>s.abort();t.addEventListener("abort",a,{once:!0}),u=()=>t.removeEventListener("abort",a)}try{let a=await fetch(e,{method:"post",headers:{authorization:`Bearer ${o}`},signal:p});if(a.status!==200)throw new Error(`Failed to read event types, got HTTP status code '${a.status}', expected '200'.`);if(!a.body)throw new Error("Failed to read event types.");for await(let r of l(a.body,p))if(!h(r)){if(m(r))throw new Error(`${r.payload.error}.`);if(g(r)){yield r.payload;continue}throw new Error("Failed to read event types.")}}catch(a){if(a instanceof DOMException&&a.name==="AbortError")return;throw a}finally{u&&u(),d&&s.abort()}}()}};import{GenericContainer as F,Wait as L}from"testcontainers";var w=class{#o="thenativeweb/eventsourcingdb";#e="latest";#t=3e3;#n="secret";#r;withImageTag(t){return this.#e=t,this}withApiToken(t){return this.#n=t,this}withPort(t){return this.#t=t,this}async start(){this.#r=await new F(`${this.#o}:${this.#e}`).withExposedPorts(this.#t).withCommand(["run","--api-token",this.#n,"--data-directory-temporary","--http-enabled","--https-enabled=false"]).withWaitStrategy(L.forHttp("/api/v1/ping",this.#t).withStartupTimeout(1e4)).start()}getHost(){if(this.#r===void 0)throw new Error("Container must be running.");return this.#r.getHost()}getMappedPort(){if(this.#r===void 0)throw new Error("Container must be running.");return this.#r.getMappedPort(this.#t)}getBaseUrl(){if(this.#r===void 0)throw new Error("Container must be running.");let t=this.getHost(),e=this.getMappedPort();return new URL(`http://${t}:${e}`)}getApiToken(){return this.#n}isRunning(){return this.#r!==void 0}async stop(){this.#r!==void 0&&(await this.#r.stop(),this.#r=void 0)}getClient(){return new y(this.getBaseUrl(),this.getApiToken())}};var R=(n,t)=>({type:"isSubjectOnEventId",payload:{subject:n,eventId:t}});var H=n=>({type:"isSubjectPristine",payload:{subject:n}});export{y as Client,w as Container,R as isSubjectOnEventId,H as isSubjectPristine};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eventsourcingdb",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "The official JavaScript client SDK for EventSourcingDB.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "the native web GmbH",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
},
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"testcontainers": "11.
|
|
17
|
+
"testcontainers": "11.4.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@biomejs/biome": "2.1.2",
|
|
21
|
-
"@types/node": "24.0
|
|
21
|
+
"@types/node": "24.1.0",
|
|
22
22
|
"get-port": "7.1.0",
|
|
23
23
|
"tsup": "8.5.0",
|
|
24
24
|
"tsx": "4.20.3",
|