eventsourcingdb 1.2.0 → 1.2.2
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 +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -94,17 +94,17 @@ 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 `
|
|
97
|
+
#### Using the `isEventQlQueryTrue` precondition
|
|
98
98
|
|
|
99
|
-
If you want to write events depending on an EventQL query, import the `
|
|
99
|
+
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:
|
|
100
100
|
|
|
101
101
|
```typescript
|
|
102
|
-
import {
|
|
102
|
+
import { isEventQlQueryTrue } from 'eventsourcingdb';
|
|
103
103
|
|
|
104
104
|
const writtenEvents = await client.writeEvents([
|
|
105
105
|
// events
|
|
106
106
|
], [
|
|
107
|
-
|
|
107
|
+
isEventQlQueryTrue(`FROM e IN events WHERE e.type == 'io.eventsourcingdb.library.book-borrowed' PROJECT INTO COUNT() < 10`)
|
|
108
108
|
]);
|
|
109
109
|
```
|
|
110
110
|
|
package/dist/index.d.mts
CHANGED
|
@@ -53,7 +53,7 @@ interface IsSubjectOnEventIdPrecondition {
|
|
|
53
53
|
subject: string;
|
|
54
54
|
eventId: string;
|
|
55
55
|
}
|
|
56
|
-
interface
|
|
56
|
+
interface IsEventQlQueryTruePrecondition {
|
|
57
57
|
query: string;
|
|
58
58
|
}
|
|
59
59
|
type Precondition = {
|
|
@@ -63,8 +63,8 @@ type Precondition = {
|
|
|
63
63
|
type: 'isSubjectOnEventId';
|
|
64
64
|
payload: IsSubjectOnEventIdPrecondition;
|
|
65
65
|
} | {
|
|
66
|
-
type: '
|
|
67
|
-
payload:
|
|
66
|
+
type: 'isEventQlQueryTrue';
|
|
67
|
+
payload: IsEventQlQueryTruePrecondition;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
type Order = 'chronological' | 'antichronological';
|
|
@@ -116,4 +116,4 @@ declare const isSubjectOnEventId: (subject: string, eventId: string) => Precondi
|
|
|
116
116
|
|
|
117
117
|
declare const isSubjectPristine: (subject: string) => Precondition;
|
|
118
118
|
|
|
119
|
-
export { Client, Container, type Event, type EventCandidate, type EventType, type ObserveEventsOptions, type ReadEventsOptions, isSubjectOnEventId, isSubjectPristine };
|
|
119
|
+
export { Client, Container, type Event, type EventCandidate, type EventType, type ObserveEventsOptions, type Precondition, type ReadEventsOptions, isSubjectOnEventId, isSubjectPristine };
|
package/dist/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ interface IsSubjectOnEventIdPrecondition {
|
|
|
53
53
|
subject: string;
|
|
54
54
|
eventId: string;
|
|
55
55
|
}
|
|
56
|
-
interface
|
|
56
|
+
interface IsEventQlQueryTruePrecondition {
|
|
57
57
|
query: string;
|
|
58
58
|
}
|
|
59
59
|
type Precondition = {
|
|
@@ -63,8 +63,8 @@ type Precondition = {
|
|
|
63
63
|
type: 'isSubjectOnEventId';
|
|
64
64
|
payload: IsSubjectOnEventIdPrecondition;
|
|
65
65
|
} | {
|
|
66
|
-
type: '
|
|
67
|
-
payload:
|
|
66
|
+
type: 'isEventQlQueryTrue';
|
|
67
|
+
payload: IsEventQlQueryTruePrecondition;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
type Order = 'chronological' | 'antichronological';
|
|
@@ -116,4 +116,4 @@ declare const isSubjectOnEventId: (subject: string, eventId: string) => Precondi
|
|
|
116
116
|
|
|
117
117
|
declare const isSubjectPristine: (subject: string) => Precondition;
|
|
118
118
|
|
|
119
|
-
export { Client, Container, type Event, type EventCandidate, type EventType, type ObserveEventsOptions, type ReadEventsOptions, isSubjectOnEventId, isSubjectPristine };
|
|
119
|
+
export { Client, Container, type Event, type EventCandidate, type EventType, type ObserveEventsOptions, type Precondition, type ReadEventsOptions, isSubjectOnEventId, isSubjectPristine };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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
|
|
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
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
|
|
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.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "The official JavaScript client SDK for EventSourcingDB.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "the native web GmbH",
|
|
@@ -14,15 +14,15 @@
|
|
|
14
14
|
},
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"testcontainers": "11.
|
|
17
|
+
"testcontainers": "11.5.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@biomejs/biome": "2.
|
|
21
|
-
"@types/node": "24.
|
|
20
|
+
"@biomejs/biome": "2.2.2",
|
|
21
|
+
"@types/node": "24.3.0",
|
|
22
22
|
"get-port": "7.1.0",
|
|
23
23
|
"tsup": "8.5.0",
|
|
24
|
-
"tsx": "4.20.
|
|
25
|
-
"typescript": "5.
|
|
24
|
+
"tsx": "4.20.5",
|
|
25
|
+
"typescript": "5.9.2"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"analyze": "npx biome check --error-on-warnings .",
|