@uploadista/event-emitter-durable-object 0.0.3 → 0.0.6

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/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@uploadista/core/errors`);c=s(c);let l=require(`@uploadista/core/types`);l=s(l);let u=require(`effect`);u=s(u);function d({durableObject:e}){function t(t){let n=e.idFromName(t);return e.get(n)}return{emit:(e,n)=>{let r=t(e);return u.Effect.tryPromise({try:async()=>{await r.emit(n)},catch:e=>c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:e})})},subscribe:(e,n)=>u.Effect.tryPromise({try:async()=>{await t(e).subscribe(n)},catch:e=>c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:e})}),unsubscribe:e=>u.Effect.tryPromise({try:async()=>{await t(e).unsubscribe()},catch:e=>c.UploadistaError.fromCode(`UNKNOWN_ERROR`,{cause:e})})}}const f=e=>u.Layer.succeed(l.UploadEventEmitter,d(e));exports.uploadEventEmitterDurableObjectStore=f;
@@ -0,0 +1,20 @@
1
+ import { UploadEvent, UploadEventEmitter, WebSocketConnection } from "@uploadista/core/types";
2
+ import { Layer } from "effect";
3
+ import { DurableObjectNamespace, Rpc } from "@cloudflare/workers-types";
4
+
5
+ //#region src/event-emitter-durable-object.d.ts
6
+ type EventEmitterDurableObjectBranded<T> = Rpc.DurableObjectBranded & {
7
+ emit: (event: T) => Promise<void>;
8
+ subscribe: (connection: WebSocketConnection) => Promise<void>;
9
+ unsubscribe: () => Promise<void>;
10
+ };
11
+ type EventEmitterDurableObject<T> = DurableObjectNamespace<EventEmitterDurableObjectBranded<T>>;
12
+ //#endregion
13
+ //#region src/do-event-emitter.d.ts
14
+ type UploadEventEmitterDurableObjectStoreConfig = {
15
+ durableObject: EventEmitterDurableObject<UploadEvent>;
16
+ };
17
+ declare const uploadEventEmitterDurableObjectStore: (config: UploadEventEmitterDurableObjectStoreConfig) => Layer.Layer<UploadEventEmitter, never, never>;
18
+ //#endregion
19
+ export { type EventEmitterDurableObject, uploadEventEmitterDurableObjectStore };
20
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/event-emitter-durable-object.ts","../src/do-event-emitter.ts"],"sourcesContent":[],"mappings":";;;;;KAGY,sCAAsC,GAAA,CAAI;gBACtC,MAAM;0BACI,wBAAwB;EAFtC,WAAA,EAAA,GAAA,GAGS,OAHT,CAAA,IAAA,CAAA;CAAsC;AAClC,KAMJ,yBANI,CAAA,CAAA,CAAA,GAM2B,sBAN3B,CAOd,gCAPc,CAOmB,CAPnB,CAAA,CAAA;;;KCQJ,0CAAA;iBACK,0BAA0B;ADV3C,CAAA;AACgB,cC8DH,oCD9DG,EAAA,CAAA,MAAA,EC+DN,0CD/DM,EAAA,GC+DoC,KAAA,CAAA,KD/DpC,CC+DoC,kBD/DpC,EAAA,KAAA,EAAA,KAAA,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,20 @@
1
- export { uploadEventEmitterDurableObjectStore } from "./do-event-emitter";
2
- export type { EventEmitterDurableObject } from "./event-emitter-durable-object";
1
+ import { UploadEvent, UploadEventEmitter, WebSocketConnection } from "@uploadista/core/types";
2
+ import { Layer } from "effect";
3
+ import { DurableObjectNamespace, Rpc } from "@cloudflare/workers-types";
4
+
5
+ //#region src/event-emitter-durable-object.d.ts
6
+ type EventEmitterDurableObjectBranded<T> = Rpc.DurableObjectBranded & {
7
+ emit: (event: T) => Promise<void>;
8
+ subscribe: (connection: WebSocketConnection) => Promise<void>;
9
+ unsubscribe: () => Promise<void>;
10
+ };
11
+ type EventEmitterDurableObject<T> = DurableObjectNamespace<EventEmitterDurableObjectBranded<T>>;
12
+ //#endregion
13
+ //#region src/do-event-emitter.d.ts
14
+ type UploadEventEmitterDurableObjectStoreConfig = {
15
+ durableObject: EventEmitterDurableObject<UploadEvent>;
16
+ };
17
+ declare const uploadEventEmitterDurableObjectStore: (config: UploadEventEmitterDurableObjectStoreConfig) => Layer.Layer<UploadEventEmitter, never, never>;
18
+ //#endregion
19
+ export { type EventEmitterDurableObject, uploadEventEmitterDurableObjectStore };
3
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,oBAAoB,CAAC;AAE1E,YAAY,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/event-emitter-durable-object.ts","../src/do-event-emitter.ts"],"sourcesContent":[],"mappings":";;;;;KAGY,sCAAsC,GAAA,CAAI;gBACtC,MAAM;0BACI,wBAAwB;EAFtC,WAAA,EAAA,GAAA,GAGS,OAHT,CAAA,IAAA,CAAA;CAAsC;AAClC,KAMJ,yBANI,CAAA,CAAA,CAAA,GAM2B,sBAN3B,CAOd,gCAPc,CAOmB,CAPnB,CAAA,CAAA;;;KCQJ,0CAAA;iBACK,0BAA0B;ADV3C,CAAA;AACgB,cC8DH,oCD9DG,EAAA,CAAA,MAAA,EC+DN,0CD/DM,EAAA,GC+DoC,KAAA,CAAA,KD/DpC,CC+DoC,kBD/DpC,EAAA,KAAA,EAAA,KAAA,CAAA"}
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- export { uploadEventEmitterDurableObjectStore } from "./do-event-emitter";
1
+ import{UploadistaError as e}from"@uploadista/core/errors";import{UploadEventEmitter as t}from"@uploadista/core/types";import{Effect as n,Layer as r}from"effect";function i({durableObject:t}){function r(e){let n=t.idFromName(e);return t.get(n)}return{emit:(t,i)=>{let a=r(t);return n.tryPromise({try:async()=>{await a.emit(i)},catch:t=>e.fromCode(`UNKNOWN_ERROR`,{cause:t})})},subscribe:(t,i)=>n.tryPromise({try:async()=>{await r(t).subscribe(i)},catch:t=>e.fromCode(`UNKNOWN_ERROR`,{cause:t})}),unsubscribe:t=>n.tryPromise({try:async()=>{await r(t).unsubscribe()},catch:t=>e.fromCode(`UNKNOWN_ERROR`,{cause:t})})}}const a=e=>r.succeed(t,i(e));export{a as uploadEventEmitterDurableObjectStore};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/do-event-emitter.ts"],"sourcesContent":["import { UploadistaError } from \"@uploadista/core/errors\";\nimport {\n type EventEmitter,\n type UploadEvent,\n UploadEventEmitter,\n} from \"@uploadista/core/types\";\nimport { Effect, Layer } from \"effect\";\nimport type {\n EventEmitterDurableObject,\n EventEmitterDurableObjectBranded,\n} from \"./event-emitter-durable-object\";\n\nexport type UploadEventEmitterDurableObjectStoreConfig = {\n durableObject: EventEmitterDurableObject<UploadEvent>;\n};\n\nexport function makeEventEmitterDurableObjectStore<T>({\n durableObject,\n}: UploadEventEmitterDurableObjectStoreConfig): EventEmitter<T> {\n function getStub(key: string) {\n const id = durableObject.idFromName(key);\n return durableObject.get(\n id,\n ) as unknown as EventEmitterDurableObjectBranded<T>;\n }\n\n return {\n emit: (key: string, event: T) => {\n const stub = getStub(key);\n return Effect.tryPromise({\n try: async () => {\n await stub.emit(event);\n return;\n },\n catch: (cause) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", { cause });\n },\n });\n },\n subscribe: (key: string, connection) => {\n return Effect.tryPromise({\n try: async () => {\n const stub = getStub(key);\n await stub.subscribe(connection);\n return;\n },\n catch: (cause) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", { cause });\n },\n });\n },\n unsubscribe: (key: string) => {\n return Effect.tryPromise({\n try: async () => {\n const stub = getStub(key);\n await stub.unsubscribe();\n return;\n },\n catch: (cause) => {\n return UploadistaError.fromCode(\"UNKNOWN_ERROR\", { cause });\n },\n });\n },\n };\n}\n\nexport const uploadEventEmitterDurableObjectStore = (\n config: UploadEventEmitterDurableObjectStoreConfig,\n) =>\n Layer.succeed(\n UploadEventEmitter,\n makeEventEmitterDurableObjectStore<UploadEvent>(config),\n );\n"],"mappings":"iKAgBA,SAAgB,EAAsC,CACpD,iBAC8D,CAC9D,SAAS,EAAQ,EAAa,CAC5B,IAAM,EAAK,EAAc,WAAW,EAAI,CACxC,OAAO,EAAc,IACnB,EACD,CAGH,MAAO,CACL,MAAO,EAAa,IAAa,CAC/B,IAAM,EAAO,EAAQ,EAAI,CACzB,OAAO,EAAO,WAAW,CACvB,IAAK,SAAY,CACf,MAAM,EAAK,KAAK,EAAM,EAGxB,MAAQ,GACC,EAAgB,SAAS,gBAAiB,CAAE,QAAO,CAAC,CAE9D,CAAC,EAEJ,WAAY,EAAa,IAChB,EAAO,WAAW,CACvB,IAAK,SAAY,CAEf,MADa,EAAQ,EAAI,CACd,UAAU,EAAW,EAGlC,MAAQ,GACC,EAAgB,SAAS,gBAAiB,CAAE,QAAO,CAAC,CAE9D,CAAC,CAEJ,YAAc,GACL,EAAO,WAAW,CACvB,IAAK,SAAY,CAEf,MADa,EAAQ,EAAI,CACd,aAAa,EAG1B,MAAQ,GACC,EAAgB,SAAS,gBAAiB,CAAE,QAAO,CAAC,CAE9D,CAAC,CAEL,CAGH,MAAa,EACX,GAEA,EAAM,QACJ,EACA,EAAgD,EAAO,CACxD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uploadista/event-emitter-durable-object",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.6",
5
5
  "description": "Durable Object event emitter for Uploadista",
6
6
  "license": "MIT",
7
7
  "author": "Uploadista",
@@ -13,15 +13,16 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@cloudflare/workers-types": "4.20251011.0",
16
+ "@cloudflare/workers-types": "4.20251014.0",
17
17
  "effect": "3.18.4",
18
- "@uploadista/core": "0.0.3"
18
+ "@uploadista/core": "0.0.6"
19
19
  },
20
20
  "devDependencies": {
21
- "@uploadista/typescript-config": "0.0.3"
21
+ "tsdown": "0.15.9",
22
+ "@uploadista/typescript-config": "0.0.6"
22
23
  },
23
24
  "scripts": {
24
- "build": "tsc -b",
25
+ "build": "tsdown",
25
26
  "format": "biome format --write ./src",
26
27
  "lint": "biome lint --write ./src",
27
28
  "check": "biome check --write ./src"
@@ -0,0 +1,11 @@
1
+ import { defineConfig } from "tsdown";
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: "src/index.ts",
6
+ },
7
+ minify: true,
8
+ format: ["esm", "cjs"],
9
+ dts: true,
10
+ outDir: "dist",
11
+ });
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > @uploadista/event-emitter-durable-object@0.0.2 build /Users/denislaboureyras/Documents/uploadista/dev/uploadista-workspace/uploadista-sdk/packages/event-emitters/durable-object
4
- > tsc -b
5
-
@@ -1,5 +0,0 @@
1
-
2
- > @uploadista/event-emitter-durable-object@ check /Users/denislaboureyras/Documents/uploadista/dev/uploadista/packages/uploadista/event-emitters/durable-object
3
- > biome check --write ./src
4
-
5
- Checked 4 files in 78ms. No fixes applied.
@@ -1,9 +0,0 @@
1
- import { type EventEmitter, type UploadEvent, UploadEventEmitter } from "@uploadista/core/types";
2
- import { Layer } from "effect";
3
- import type { EventEmitterDurableObject } from "./event-emitter-durable-object";
4
- export type UploadEventEmitterDurableObjectStoreConfig = {
5
- durableObject: EventEmitterDurableObject<UploadEvent>;
6
- };
7
- export declare function makeEventEmitterDurableObjectStore<T>({ durableObject, }: UploadEventEmitterDurableObjectStoreConfig): EventEmitter<T>;
8
- export declare const uploadEventEmitterDurableObjectStore: (config: UploadEventEmitterDurableObjectStoreConfig) => Layer.Layer<UploadEventEmitter, never, never>;
9
- //# sourceMappingURL=do-event-emitter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"do-event-emitter.d.ts","sourceRoot":"","sources":["../src/do-event-emitter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,EACV,yBAAyB,EAE1B,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,0CAA0C,GAAG;IACvD,aAAa,EAAE,yBAAyB,CAAC,WAAW,CAAC,CAAC;CACvD,CAAC;AAEF,wBAAgB,kCAAkC,CAAC,CAAC,EAAE,EACpD,aAAa,GACd,EAAE,0CAA0C,GAAG,YAAY,CAAC,CAAC,CAAC,CA8C9D;AAED,eAAO,MAAM,oCAAoC,GAC/C,QAAQ,0CAA0C,kDAKjD,CAAC"}
@@ -1,48 +0,0 @@
1
- import { UploadistaError } from "@uploadista/core/errors";
2
- import { UploadEventEmitter, } from "@uploadista/core/types";
3
- import { Effect, Layer } from "effect";
4
- export function makeEventEmitterDurableObjectStore({ durableObject, }) {
5
- function getStub(key) {
6
- const id = durableObject.idFromName(key);
7
- return durableObject.get(id);
8
- }
9
- return {
10
- emit: (key, event) => {
11
- const stub = getStub(key);
12
- return Effect.tryPromise({
13
- try: async () => {
14
- await stub.emit(event);
15
- return;
16
- },
17
- catch: (cause) => {
18
- return UploadistaError.fromCode("UNKNOWN_ERROR", { cause });
19
- },
20
- });
21
- },
22
- subscribe: (key, connection) => {
23
- return Effect.tryPromise({
24
- try: async () => {
25
- const stub = getStub(key);
26
- await stub.subscribe(connection);
27
- return;
28
- },
29
- catch: (cause) => {
30
- return UploadistaError.fromCode("UNKNOWN_ERROR", { cause });
31
- },
32
- });
33
- },
34
- unsubscribe: (key) => {
35
- return Effect.tryPromise({
36
- try: async () => {
37
- const stub = getStub(key);
38
- await stub.unsubscribe();
39
- return;
40
- },
41
- catch: (cause) => {
42
- return UploadistaError.fromCode("UNKNOWN_ERROR", { cause });
43
- },
44
- });
45
- },
46
- };
47
- }
48
- export const uploadEventEmitterDurableObjectStore = (config) => Layer.succeed(UploadEventEmitter, makeEventEmitterDurableObjectStore(config));
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=durable-object-impl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"durable-object-impl.d.ts","sourceRoot":"","sources":["../src/durable-object-impl.ts"],"names":[],"mappings":""}
@@ -1,53 +0,0 @@
1
- // import { DurableObject } from "cloudflare:workers";
2
- // import { WebSocketPair } from "@cloudflare/workers-types";
3
- // import type { UploadEvent } from "@uploadista/core/types";
4
- export {};
5
- // export class UploadEventDurableObject extends DurableObject {
6
- // async fetch(_request: Request): Promise<Response> {
7
- // // Creates two ends of a WebSocket connection.
8
- // const webSocketPair = new WebSocketPair();
9
- // const [client, server] = Object.values(webSocketPair);
10
- // // Calling `acceptWebSocket()` informs the runtime that this WebSocket is to begin terminating
11
- // // request within the Durable Object. It has the effect of "accepting" the connection,
12
- // // and allowing the WebSocket to send and receive messages.
13
- // // Unlike `ws.accept()`, `state.acceptWebSocket(ws)` informs the Workers Runtime that the WebSocket
14
- // // is "hibernatable", so the runtime does not need to pin this Durable Object to memory while
15
- // // the connection is open. During periods of inactivity, the Durable Object can be evicted
16
- // // from memory, but the WebSocket connection will remain open. If at some later point the
17
- // // WebSocket receives a message, the runtime will recreate the Durable Object
18
- // // (run the `constructor`) and deliver the message to the appropriate handler.
19
- // this.ctx.acceptWebSocket(server);
20
- // return new Response(null, {
21
- // status: 101,
22
- // webSocket: client,
23
- // });
24
- // }
25
- // emit(event: UploadEvent) {
26
- // for (const ws of this.ctx.getWebSockets()) {
27
- // ws.send(JSON.stringify(event satisfies UploadEvent));
28
- // }
29
- // }
30
- // async webSocketMessage(ws: WebSocket, message: ArrayBuffer | string) {
31
- // // Upon receiving a message from the client, the server replies with the same message,
32
- // // and the total number of connections with the "[Durable Object]: " prefix
33
- // ws.send(
34
- // `[Durable Object] message: ${message}, connections: ${this.ctx.getWebSockets().length}`,
35
- // );
36
- // }
37
- // async webSocketClose(
38
- // ws: WebSocket,
39
- // code: number,
40
- // _reason: string,
41
- // _wasClean: boolean,
42
- // ) {
43
- // // If the client closes the connection, the runtime will invoke the webSocketClose() handler.
44
- // // Don't try to close an already closed WebSocket or use reserved close codes
45
- // if (ws.readyState === WebSocket.OPEN) {
46
- // // Use a valid close code instead of the potentially reserved one from the client
47
- // // 1000 = Normal Closure, 1001 = Going Away are safe codes to use
48
- // const validCloseCode =
49
- // code === 1006 || code < 1000 || code > 4999 ? 1000 : code;
50
- // ws.close(validCloseCode, "Durable Object is closing WebSocket");
51
- // }
52
- // }
53
- // }
@@ -1,9 +0,0 @@
1
- import type { DurableObjectNamespace, Rpc } from "@cloudflare/workers-types";
2
- import type { WebSocketConnection } from "@uploadista/core/types";
3
- export type EventEmitterDurableObjectBranded<T> = Rpc.DurableObjectBranded & {
4
- emit: (event: T) => Promise<void>;
5
- subscribe: (connection: WebSocketConnection) => Promise<void>;
6
- unsubscribe: () => Promise<void>;
7
- };
8
- export type EventEmitterDurableObject<T> = DurableObjectNamespace<EventEmitterDurableObjectBranded<T>>;
9
- //# sourceMappingURL=event-emitter-durable-object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"event-emitter-durable-object.d.ts","sourceRoot":"","sources":["../src/event-emitter-durable-object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE,MAAM,MAAM,gCAAgC,CAAC,CAAC,IAAI,GAAG,CAAC,oBAAoB,GAAG;IAC3E,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,SAAS,EAAE,CAAC,UAAU,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC,CAAC;AAGF,MAAM,MAAM,yBAAyB,CAAC,CAAC,IAAI,sBAAsB,CAC/D,gCAAgC,CAAC,CAAC,CAAC,CACpC,CAAC"}
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- {"root":["./src/do-event-emitter.ts","./src/durable-object-impl.ts","./src/event-emitter-durable-object.ts","./src/index.ts","./worker-configuration.d.ts"],"version":"5.9.3"}