@livestore/sync-cf 0.3.0-dev.6 → 0.3.0-dev.7
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/.tsbuildinfo +1 -1
- package/dist/cf-worker/durable-object.d.ts +18 -22
- package/dist/cf-worker/durable-object.d.ts.map +1 -1
- package/dist/cf-worker/durable-object.js +114 -107
- package/dist/cf-worker/durable-object.js.map +1 -1
- package/dist/cf-worker/index.d.ts +1 -6
- package/dist/cf-worker/index.d.ts.map +1 -1
- package/dist/cf-worker/index.js +30 -64
- package/dist/cf-worker/index.js.map +1 -1
- package/dist/cf-worker/make-worker.d.ts +6 -0
- package/dist/cf-worker/make-worker.d.ts.map +1 -0
- package/dist/cf-worker/make-worker.js +31 -0
- package/dist/cf-worker/make-worker.js.map +1 -0
- package/dist/cf-worker/mod.d.ts +3 -0
- package/dist/cf-worker/mod.d.ts.map +1 -0
- package/dist/cf-worker/mod.js +3 -0
- package/dist/cf-worker/mod.js.map +1 -0
- package/dist/cf-worker/types.d.ts +2 -0
- package/dist/cf-worker/types.d.ts.map +1 -0
- package/dist/cf-worker/types.js +2 -0
- package/dist/cf-worker/types.js.map +1 -0
- package/dist/cf-worker/worker.d.ts +6 -0
- package/dist/cf-worker/worker.d.ts.map +1 -0
- package/dist/cf-worker/worker.js +31 -0
- package/dist/cf-worker/worker.js.map +1 -0
- package/dist/common/mod.d.ts +2 -0
- package/dist/common/mod.d.ts.map +1 -0
- package/dist/common/mod.js +2 -0
- package/dist/common/mod.js.map +1 -0
- package/dist/sync-impl/mod.d.ts +2 -0
- package/dist/sync-impl/mod.d.ts.map +1 -0
- package/dist/sync-impl/mod.js +2 -0
- package/dist/sync-impl/mod.js.map +1 -0
- package/dist/sync-impl/ws-impl.js +3 -3
- package/dist/sync-impl/ws-impl.js.map +1 -1
- package/package.json +10 -9
- package/src/cf-worker/durable-object.ts +154 -132
- package/src/cf-worker/mod.ts +2 -0
- package/src/cf-worker/worker.ts +41 -0
- package/src/sync-impl/ws-impl.ts +3 -3
- package/src/cf-worker/index.ts +0 -84
- /package/src/common/{index.ts → mod.ts} +0 -0
- /package/src/sync-impl/{index.ts → mod.ts} +0 -0
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { DbSchema
|
|
2
|
-
import { Option, Schema } from '@livestore/utils/effect';
|
|
1
|
+
import { DbSchema } from '@livestore/common/schema';
|
|
2
|
+
import { Effect, Option, Schema } from '@livestore/utils/effect';
|
|
3
3
|
import { DurableObject } from 'cloudflare:workers';
|
|
4
|
-
import
|
|
4
|
+
import { WSMessage } from '../common/mod.js';
|
|
5
5
|
export interface Env {
|
|
6
|
-
WEBSOCKET_SERVER: DurableObjectNamespace
|
|
6
|
+
WEBSOCKET_SERVER: DurableObjectNamespace;
|
|
7
7
|
DB: D1Database;
|
|
8
8
|
ADMIN_SECRET: string;
|
|
9
9
|
}
|
|
10
|
-
type WebSocketClient = WebSocket;
|
|
11
10
|
export declare const mutationLogTable: DbSchema.TableDef<{
|
|
12
11
|
name: "__unused";
|
|
13
12
|
columns: {
|
|
@@ -68,21 +67,18 @@ export declare const mutationLogTable: DbSchema.TableDef<{
|
|
|
68
67
|
readonly args: string;
|
|
69
68
|
readonly createdAt: string;
|
|
70
69
|
}, never>>;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
webSocketClose: (ws: WebSocketClient, code: number, _reason: string, _wasClean: boolean) => Promise<void>;
|
|
86
|
-
}
|
|
87
|
-
export {};
|
|
70
|
+
/**
|
|
71
|
+
* Needs to be bumped when the storage format changes (e.g. mutationLogTable schema changes)
|
|
72
|
+
*
|
|
73
|
+
* Changing this version number will lead to a "soft reset".
|
|
74
|
+
*/
|
|
75
|
+
export declare const PERSISTENCE_FORMAT_VERSION = 2;
|
|
76
|
+
export type MakeDurableObjectClassOptions = {
|
|
77
|
+
onPush?: (message: WSMessage.PushReq) => Effect.Effect<void> | Promise<void>;
|
|
78
|
+
onPull?: (message: WSMessage.PullReq) => Effect.Effect<void> | Promise<void>;
|
|
79
|
+
};
|
|
80
|
+
export type MakeDurableObjectClass = (options?: MakeDurableObjectClassOptions) => {
|
|
81
|
+
new (ctx: DurableObjectState, env: Env): DurableObject<Env>;
|
|
82
|
+
};
|
|
83
|
+
export declare const makeDurableObject: MakeDurableObjectClass;
|
|
88
84
|
//# sourceMappingURL=durable-object.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-object.d.ts","sourceRoot":"","sources":["../../src/cf-worker/durable-object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"durable-object.d.ts","sourceRoot":"","sources":["../../src/cf-worker/durable-object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAA+B,MAAM,0BAA0B,CAAA;AAEhF,OAAO,EAAE,MAAM,EAAoB,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAG5C,MAAM,WAAW,GAAG;IAClB,gBAAgB,EAAE,sBAAsB,CAAA;IACxC,EAAE,EAAE,UAAU,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;CACrB;AASD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAO3B,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAA;AAE3C,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5E,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7E,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,CAAC,EAAE,6BAA6B,KAAK;IAChF,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;CAC5D,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,sBAuL/B,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { DbSchema, EventId } from '@livestore/common/schema';
|
|
|
3
3
|
import { shouldNeverHappen } from '@livestore/utils';
|
|
4
4
|
import { Effect, Logger, LogLevel, Option, Schema } from '@livestore/utils/effect';
|
|
5
5
|
import { DurableObject } from 'cloudflare:workers';
|
|
6
|
-
import { WSMessage } from '../common/
|
|
6
|
+
import { WSMessage } from '../common/mod.js';
|
|
7
7
|
const encodeOutgoingMessage = Schema.encodeSync(Schema.parseJson(WSMessage.BackendToClientMessage));
|
|
8
8
|
const encodeIncomingMessage = Schema.encodeSync(Schema.parseJson(WSMessage.ClientToBackendMessage));
|
|
9
9
|
const decodeIncomingMessage = Schema.decodeUnknownEither(Schema.parseJson(WSMessage.ClientToBackendMessage));
|
|
@@ -21,124 +21,131 @@ export const mutationLogTable = DbSchema.table('__unused', {
|
|
|
21
21
|
*
|
|
22
22
|
* Changing this version number will lead to a "soft reset".
|
|
23
23
|
*/
|
|
24
|
-
const PERSISTENCE_FORMAT_VERSION = 2;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
fetch = async (_request) => Effect.gen(this, function* () {
|
|
33
|
-
const { 0: client, 1: server } = new WebSocketPair();
|
|
34
|
-
// See https://developers.cloudflare.com/durable-objects/examples/websocket-hibernation-server
|
|
35
|
-
this.ctx.acceptWebSocket(server);
|
|
36
|
-
this.ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair(encodeIncomingMessage(WSMessage.Ping.make({ requestId: 'ping' })), encodeOutgoingMessage(WSMessage.Pong.make({ requestId: 'ping' }))));
|
|
37
|
-
const colSpec = makeColumnSpec(mutationLogTable.sqliteDef.ast);
|
|
38
|
-
this.env.DB.exec(`CREATE TABLE IF NOT EXISTS ${this.dbName} (${colSpec}) strict`);
|
|
39
|
-
return new Response(null, {
|
|
40
|
-
status: 101,
|
|
41
|
-
webSocket: client,
|
|
42
|
-
});
|
|
43
|
-
}).pipe(Effect.tapCauseLogPretty, Effect.runPromise);
|
|
44
|
-
webSocketMessage = (ws, message) => Effect.gen(this, function* () {
|
|
45
|
-
const decodedMessageRes = decodeIncomingMessage(message);
|
|
46
|
-
if (decodedMessageRes._tag === 'Left') {
|
|
47
|
-
console.error('Invalid message received', decodedMessageRes.left);
|
|
48
|
-
return;
|
|
24
|
+
export const PERSISTENCE_FORMAT_VERSION = 2;
|
|
25
|
+
export const makeDurableObject = (options) => {
|
|
26
|
+
return class WebSocketServerBase extends DurableObject {
|
|
27
|
+
dbName = `mutation_log_${PERSISTENCE_FORMAT_VERSION}_${this.ctx.id.toString()}`;
|
|
28
|
+
storage = makeStorage(this.ctx, this.env, this.dbName);
|
|
29
|
+
constructor(ctx, env) {
|
|
30
|
+
super(ctx, env);
|
|
49
31
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
32
|
+
fetch = async (_request) => Effect.gen(this, function* () {
|
|
33
|
+
const { 0: client, 1: server } = new WebSocketPair();
|
|
34
|
+
// See https://developers.cloudflare.com/durable-objects/examples/websocket-hibernation-server
|
|
35
|
+
this.ctx.acceptWebSocket(server);
|
|
36
|
+
this.ctx.setWebSocketAutoResponse(new WebSocketRequestResponsePair(encodeIncomingMessage(WSMessage.Ping.make({ requestId: 'ping' })), encodeOutgoingMessage(WSMessage.Pong.make({ requestId: 'ping' }))));
|
|
37
|
+
const colSpec = makeColumnSpec(mutationLogTable.sqliteDef.ast);
|
|
38
|
+
this.env.DB.exec(`CREATE TABLE IF NOT EXISTS ${this.dbName} (${colSpec}) strict`);
|
|
39
|
+
return new Response(null, {
|
|
40
|
+
status: 101,
|
|
41
|
+
webSocket: client,
|
|
42
|
+
});
|
|
43
|
+
}).pipe(Effect.tapCauseLogPretty, Effect.runPromise);
|
|
44
|
+
webSocketMessage = (ws, message) => Effect.gen(this, function* () {
|
|
45
|
+
const decodedMessageRes = decodeIncomingMessage(message);
|
|
46
|
+
if (decodedMessageRes._tag === 'Left') {
|
|
47
|
+
console.error('Invalid message received', decodedMessageRes.left);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const decodedMessage = decodedMessageRes.right;
|
|
51
|
+
const requestId = decodedMessage.requestId;
|
|
52
|
+
try {
|
|
53
|
+
switch (decodedMessage._tag) {
|
|
54
|
+
case 'WSMessage.PullReq': {
|
|
55
|
+
if (options?.onPull) {
|
|
56
|
+
yield* Effect.tryAll(() => options.onPull(decodedMessage));
|
|
57
|
+
}
|
|
58
|
+
const cursor = decodedMessage.cursor;
|
|
59
|
+
const CHUNK_SIZE = 100;
|
|
60
|
+
// TODO use streaming
|
|
61
|
+
const remainingEvents = [...(yield* Effect.promise(() => this.storage.getEvents(cursor)))];
|
|
62
|
+
// NOTE we want to make sure the WS server responds at least once with `InitRes` even if `events` is empty
|
|
63
|
+
while (true) {
|
|
64
|
+
const events = remainingEvents.splice(0, CHUNK_SIZE);
|
|
65
|
+
ws.send(encodeOutgoingMessage(WSMessage.PullRes.make({ events, remaining: remainingEvents.length, requestId })));
|
|
66
|
+
if (remainingEvents.length === 0) {
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
65
69
|
}
|
|
70
|
+
break;
|
|
66
71
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// TODO check whether we could use the Durable Object storage for this to speed up the lookup
|
|
71
|
-
const latestEvent = yield* Effect.promise(() => this.storage.getLatestEvent());
|
|
72
|
-
const expectedParentId = latestEvent?.id ?? EventId.ROOT.global;
|
|
73
|
-
let i = 0;
|
|
74
|
-
for (const mutationEventEncoded of decodedMessage.batch) {
|
|
75
|
-
if (mutationEventEncoded.parentId !== expectedParentId + i) {
|
|
76
|
-
const err = WSMessage.Error.make({
|
|
77
|
-
message: `Invalid parent id. Received ${mutationEventEncoded.parentId} but expected ${expectedParentId}`,
|
|
78
|
-
requestId,
|
|
79
|
-
});
|
|
80
|
-
yield* Effect.fail(err).pipe(Effect.ignoreLogged);
|
|
81
|
-
ws.send(encodeOutgoingMessage(err));
|
|
82
|
-
return;
|
|
72
|
+
case 'WSMessage.PushReq': {
|
|
73
|
+
if (options?.onPush) {
|
|
74
|
+
yield* Effect.tryAll(() => options.onPush(decodedMessage));
|
|
83
75
|
}
|
|
84
|
-
// TODO
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}));
|
|
98
|
-
for (const conn of connectedClients) {
|
|
99
|
-
console.log('Broadcasting to client', conn === ws ? 'self' : 'other');
|
|
100
|
-
// if (conn !== ws) {
|
|
101
|
-
conn.send(broadcastMessage);
|
|
102
|
-
// }
|
|
76
|
+
// TODO check whether we could use the Durable Object storage for this to speed up the lookup
|
|
77
|
+
const latestEvent = yield* Effect.promise(() => this.storage.getLatestEvent());
|
|
78
|
+
const expectedParentId = latestEvent?.id ?? EventId.ROOT.global;
|
|
79
|
+
let i = 0;
|
|
80
|
+
for (const mutationEventEncoded of decodedMessage.batch) {
|
|
81
|
+
if (mutationEventEncoded.parentId !== expectedParentId + i) {
|
|
82
|
+
const err = WSMessage.Error.make({
|
|
83
|
+
message: `Invalid parent id. Received ${mutationEventEncoded.parentId} but expected ${expectedParentId}`,
|
|
84
|
+
requestId,
|
|
85
|
+
});
|
|
86
|
+
yield* Effect.fail(err).pipe(Effect.ignoreLogged);
|
|
87
|
+
ws.send(encodeOutgoingMessage(err));
|
|
88
|
+
return;
|
|
103
89
|
}
|
|
90
|
+
// TODO handle clientId unique conflict
|
|
91
|
+
const createdAt = new Date().toISOString();
|
|
92
|
+
// NOTE we're currently not blocking on this to allow broadcasting right away
|
|
93
|
+
const storePromise = this.storage.appendEvent(mutationEventEncoded, createdAt);
|
|
94
|
+
ws.send(encodeOutgoingMessage(WSMessage.PushAck.make({ mutationId: mutationEventEncoded.id, requestId })));
|
|
95
|
+
// console.debug(`Broadcasting mutation event to ${this.subscribedWebSockets.size} clients`)
|
|
96
|
+
const connectedClients = this.ctx.getWebSockets();
|
|
97
|
+
if (connectedClients.length > 0) {
|
|
98
|
+
const broadcastMessage = encodeOutgoingMessage(
|
|
99
|
+
// TODO refactor to batch api
|
|
100
|
+
WSMessage.PushBroadcast.make({
|
|
101
|
+
mutationEventEncoded,
|
|
102
|
+
metadata: Option.some({ createdAt }),
|
|
103
|
+
}));
|
|
104
|
+
for (const conn of connectedClients) {
|
|
105
|
+
console.log('Broadcasting to client', conn === ws ? 'self' : 'other');
|
|
106
|
+
// if (conn !== ws) {
|
|
107
|
+
conn.send(broadcastMessage);
|
|
108
|
+
// }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
yield* Effect.promise(() => storePromise);
|
|
112
|
+
i++;
|
|
104
113
|
}
|
|
105
|
-
|
|
106
|
-
i++;
|
|
114
|
+
break;
|
|
107
115
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
case 'WSMessage.AdminResetRoomReq': {
|
|
117
|
+
if (decodedMessage.adminSecret !== this.env.ADMIN_SECRET) {
|
|
118
|
+
ws.send(encodeOutgoingMessage(WSMessage.Error.make({ message: 'Invalid admin secret', requestId })));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
yield* Effect.promise(() => this.storage.resetRoom());
|
|
122
|
+
ws.send(encodeOutgoingMessage(WSMessage.AdminResetRoomRes.make({ requestId })));
|
|
123
|
+
break;
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
case 'WSMessage.AdminInfoReq': {
|
|
126
|
+
if (decodedMessage.adminSecret !== this.env.ADMIN_SECRET) {
|
|
127
|
+
ws.send(encodeOutgoingMessage(WSMessage.Error.make({ message: 'Invalid admin secret', requestId })));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
ws.send(encodeOutgoingMessage(WSMessage.AdminInfoRes.make({ requestId, info: { durableObjectId: this.ctx.id.toString() } })));
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
default: {
|
|
134
|
+
console.error('unsupported message', decodedMessage);
|
|
135
|
+
return shouldNeverHappen();
|
|
123
136
|
}
|
|
124
|
-
ws.send(encodeOutgoingMessage(WSMessage.AdminInfoRes.make({ requestId, info: { durableObjectId: this.ctx.id.toString() } })));
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
default: {
|
|
128
|
-
console.error('unsupported message', decodedMessage);
|
|
129
|
-
return shouldNeverHappen();
|
|
130
137
|
}
|
|
131
138
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
catch (error) {
|
|
140
|
+
ws.send(encodeOutgoingMessage(WSMessage.Error.make({ message: error.message, requestId })));
|
|
141
|
+
}
|
|
142
|
+
}).pipe(Effect.withSpan('@livestore/sync-cf:durable-object:webSocketMessage'), Effect.tapCauseLogPretty, Logger.withMinimumLogLevel(LogLevel.Debug), Effect.provide(Logger.pretty), Effect.runPromise);
|
|
143
|
+
webSocketClose = async (ws, code, _reason, _wasClean) => {
|
|
144
|
+
// If the client closes the connection, the runtime will invoke the webSocketClose() handler.
|
|
145
|
+
ws.close(code, 'Durable Object is closing WebSocket');
|
|
146
|
+
};
|
|
140
147
|
};
|
|
141
|
-
}
|
|
148
|
+
};
|
|
142
149
|
const makeStorage = (ctx, env, dbName) => {
|
|
143
150
|
const getLatestEvent = async () => {
|
|
144
151
|
const rawEvents = await env.DB.prepare(`SELECT * FROM ${dbName} ORDER BY id DESC LIMIT 1`).all();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durable-object.js","sourceRoot":"","sources":["../../src/cf-worker/durable-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAsB,MAAM,0BAA0B,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"durable-object.js","sourceRoot":"","sources":["../../src/cf-worker/durable-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAsB,MAAM,0BAA0B,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE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E,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,CAAA;AAC9D,CAAC,CAAA"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
/// <reference no-default-lib="true"/>
|
|
2
|
-
|
|
3
|
-
export * from './durable-object.js';
|
|
4
|
-
declare const _default: {
|
|
5
|
-
fetch: (request: Request, env: Env, _ctx: ExecutionContext) => Promise<Response>;
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|
|
2
|
+
export {};
|
|
8
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cf-worker/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cf-worker/index.ts"],"names":[],"mappings":""}
|
package/dist/cf-worker/index.js
CHANGED
|
@@ -1,67 +1,33 @@
|
|
|
1
1
|
/// <reference no-default-lib="true"/>
|
|
2
2
|
/// <reference lib="esnext" />
|
|
3
|
-
export
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
// }
|
|
30
|
-
// )
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
// return HttpServer.response.empty({ status: 400 })
|
|
34
|
-
// }),
|
|
35
|
-
// (_) => HttpServer.app.toWebHandler(_)(request),
|
|
36
|
-
// // request
|
|
37
|
-
// )
|
|
38
|
-
// Worker
|
|
39
|
-
export default {
|
|
40
|
-
fetch: async (request, env, _ctx) => {
|
|
41
|
-
const url = new URL(request.url);
|
|
42
|
-
const searchParams = url.searchParams;
|
|
43
|
-
const roomId = searchParams.get('room');
|
|
44
|
-
if (roomId === null) {
|
|
45
|
-
return new Response('Room ID is required', { status: 400 });
|
|
46
|
-
}
|
|
47
|
-
// This example will refer to the same Durable Object instance,
|
|
48
|
-
// since the name "foo" is hardcoded.
|
|
49
|
-
const id = env.WEBSOCKET_SERVER.idFromName(roomId);
|
|
50
|
-
const durableObject = env.WEBSOCKET_SERVER.get(id);
|
|
51
|
-
if (url.pathname.endsWith('/websocket')) {
|
|
52
|
-
const upgradeHeader = request.headers.get('Upgrade');
|
|
53
|
-
if (!upgradeHeader || upgradeHeader !== 'websocket') {
|
|
54
|
-
return new Response('Durable Object expected Upgrade: websocket', { status: 426 });
|
|
55
|
-
}
|
|
56
|
-
return durableObject.fetch(request);
|
|
57
|
-
}
|
|
58
|
-
return new Response(null, {
|
|
59
|
-
status: 400,
|
|
60
|
-
statusText: 'Bad Request',
|
|
61
|
-
headers: {
|
|
62
|
-
'Content-Type': 'text/plain',
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
};
|
|
3
|
+
export {};
|
|
4
|
+
// export * from './durable-object.js'
|
|
5
|
+
// export default {
|
|
6
|
+
// fetch: async (request: Request, env: Env, _ctx: ExecutionContext): Promise<Response> => {
|
|
7
|
+
// const url = new URL(request.url)
|
|
8
|
+
// const searchParams = url.searchParams
|
|
9
|
+
// const roomId = searchParams.get('room')
|
|
10
|
+
// if (roomId === null) {
|
|
11
|
+
// return new Response('Room ID is required', { status: 400 })
|
|
12
|
+
// }
|
|
13
|
+
// // This example will refer to the same Durable Object instance,
|
|
14
|
+
// // since the name "foo" is hardcoded.
|
|
15
|
+
// const id = env.WEBSOCKET_SERVER.idFromName(roomId)
|
|
16
|
+
// const durableObject = env.WEBSOCKET_SERVER.get(id)
|
|
17
|
+
// if (url.pathname.endsWith('/websocket')) {
|
|
18
|
+
// const upgradeHeader = request.headers.get('Upgrade')
|
|
19
|
+
// if (!upgradeHeader || upgradeHeader !== 'websocket') {
|
|
20
|
+
// return new Response('Durable Object expected Upgrade: websocket', { status: 426 })
|
|
21
|
+
// }
|
|
22
|
+
// return durableObject.fetch(request)
|
|
23
|
+
// }
|
|
24
|
+
// return new Response(null, {
|
|
25
|
+
// status: 400,
|
|
26
|
+
// statusText: 'Bad Request',
|
|
27
|
+
// headers: {
|
|
28
|
+
// 'Content-Type': 'text/plain',
|
|
29
|
+
// },
|
|
30
|
+
// })
|
|
31
|
+
// },
|
|
32
|
+
// }
|
|
67
33
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cf-worker/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,8BAA8B
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cf-worker/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,8BAA8B;;AAI9B,sCAAsC;AAEtC,mBAAmB;AACnB,8FAA8F;AAC9F,uCAAuC;AACvC,4CAA4C;AAC5C,8CAA8C;AAE9C,6BAA6B;AAC7B,oEAAoE;AACpE,QAAQ;AAER,sEAAsE;AACtE,4CAA4C;AAC5C,yDAAyD;AACzD,yDAAyD;AAEzD,iDAAiD;AACjD,6DAA6D;AAC7D,+DAA+D;AAC/D,6FAA6F;AAC7F,UAAU;AAEV,4CAA4C;AAC5C,QAAQ;AAER,kCAAkC;AAClC,qBAAqB;AACrB,mCAAmC;AACnC,mBAAmB;AACnB,wCAAwC;AACxC,WAAW;AACX,SAAS;AACT,OAAO;AACP,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-worker.d.ts","sourceRoot":"","sources":["../../src/cf-worker/make-worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAE9C,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAChF,CAAA;AAED,eAAO,MAAM,UAAU,QAAO,QAkC7B,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const makeWorker = () => {
|
|
2
|
+
return {
|
|
3
|
+
fetch: async (request, env, _ctx) => {
|
|
4
|
+
const url = new URL(request.url);
|
|
5
|
+
const searchParams = url.searchParams;
|
|
6
|
+
const roomId = searchParams.get('room');
|
|
7
|
+
if (roomId === null) {
|
|
8
|
+
return new Response('Room ID is required', { status: 400 });
|
|
9
|
+
}
|
|
10
|
+
// This example will refer to the same Durable Object instance,
|
|
11
|
+
// since the name "foo" is hardcoded.
|
|
12
|
+
const id = env.WEBSOCKET_SERVER.idFromName(roomId);
|
|
13
|
+
const durableObject = env.WEBSOCKET_SERVER.get(id);
|
|
14
|
+
if (url.pathname.endsWith('/websocket')) {
|
|
15
|
+
const upgradeHeader = request.headers.get('Upgrade');
|
|
16
|
+
if (!upgradeHeader || upgradeHeader !== 'websocket') {
|
|
17
|
+
return new Response('Durable Object expected Upgrade: websocket', { status: 426 });
|
|
18
|
+
}
|
|
19
|
+
return durableObject.fetch(request);
|
|
20
|
+
}
|
|
21
|
+
return new Response(null, {
|
|
22
|
+
status: 400,
|
|
23
|
+
statusText: 'Bad Request',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'text/plain',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=make-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-worker.js","sourceRoot":"","sources":["../../src/cf-worker/make-worker.ts"],"names":[],"mappings":"AAMA,MA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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/cf-worker/mod.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/cf-worker/mod.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cf-worker/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/cf-worker/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/cf-worker/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAE9C,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAChF,CAAA;AAED,eAAO,MAAM,UAAU,QAAO,QAkC7B,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const makeWorker = () => {
|
|
2
|
+
return {
|
|
3
|
+
fetch: async (request, env, _ctx) => {
|
|
4
|
+
const url = new URL(request.url);
|
|
5
|
+
const searchParams = url.searchParams;
|
|
6
|
+
const roomId = searchParams.get('room');
|
|
7
|
+
if (roomId === null) {
|
|
8
|
+
return new Response('Room ID is required', { status: 400 });
|
|
9
|
+
}
|
|
10
|
+
// This example will refer to the same Durable Object instance,
|
|
11
|
+
// since the name "foo" is hardcoded.
|
|
12
|
+
const id = env.WEBSOCKET_SERVER.idFromName(roomId);
|
|
13
|
+
const durableObject = env.WEBSOCKET_SERVER.get(id);
|
|
14
|
+
if (url.pathname.endsWith('/websocket')) {
|
|
15
|
+
const upgradeHeader = request.headers.get('Upgrade');
|
|
16
|
+
if (!upgradeHeader || upgradeHeader !== 'websocket') {
|
|
17
|
+
return new Response('Durable Object expected Upgrade: websocket', { status: 426 });
|
|
18
|
+
}
|
|
19
|
+
return durableObject.fetch(request);
|
|
20
|
+
}
|
|
21
|
+
return new Response(null, {
|
|
22
|
+
status: 400,
|
|
23
|
+
statusText: 'Bad Request',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'text/plain',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=worker.js.map
|