@syncular/server-hono 0.0.2-138 → 0.0.2-140
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/console/routes.d.ts +23 -2
- package/dist/console/routes.d.ts.map +1 -1
- package/dist/console/routes.js +1129 -219
- package/dist/console/routes.js.map +1 -1
- package/dist/console/schemas.d.ts +153 -0
- package/dist/console/schemas.d.ts.map +1 -1
- package/dist/console/schemas.js +80 -0
- package/dist/console/schemas.js.map +1 -1
- package/dist/create-server.d.ts +5 -0
- package/dist/create-server.d.ts.map +1 -1
- package/dist/create-server.js +17 -7
- package/dist/create-server.js.map +1 -1
- package/dist/routes.d.ts +11 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +514 -10
- package/dist/routes.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/console-routes.test.ts +1468 -0
- package/src/__tests__/create-server.test.ts +75 -0
- package/src/console/routes.ts +1471 -241
- package/src/console/schemas.ts +106 -0
- package/src/create-server.ts +28 -10
- package/src/routes.ts +616 -17
|
@@ -35,6 +35,16 @@ describe('createSyncServer console configuration', () => {
|
|
|
35
35
|
beforeEach(async () => {
|
|
36
36
|
db = createPgliteDb<ServerDb>();
|
|
37
37
|
await ensureSyncSchema(db, createPostgresServerDialect());
|
|
38
|
+
await db.schema
|
|
39
|
+
.createTable('tasks')
|
|
40
|
+
.ifNotExists()
|
|
41
|
+
.addColumn('id', 'text', (col) => col.primaryKey())
|
|
42
|
+
.addColumn('user_id', 'text', (col) => col.notNull())
|
|
43
|
+
.addColumn('title', 'text', (col) => col.notNull())
|
|
44
|
+
.addColumn('server_version', 'integer', (col) =>
|
|
45
|
+
col.notNull().defaultTo(0)
|
|
46
|
+
)
|
|
47
|
+
.execute();
|
|
38
48
|
previousConsoleToken = process.env.SYNC_CONSOLE_TOKEN;
|
|
39
49
|
delete process.env.SYNC_CONSOLE_TOKEN;
|
|
40
50
|
});
|
|
@@ -84,6 +94,33 @@ describe('createSyncServer console configuration', () => {
|
|
|
84
94
|
};
|
|
85
95
|
}
|
|
86
96
|
|
|
97
|
+
function createPushRequest(): Request {
|
|
98
|
+
return new Request('http://localhost/sync', {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: { 'content-type': 'application/json' },
|
|
101
|
+
body: JSON.stringify({
|
|
102
|
+
clientId: 'client-1',
|
|
103
|
+
push: {
|
|
104
|
+
clientCommitId: 'commit-1',
|
|
105
|
+
schemaVersion: 1,
|
|
106
|
+
operations: [
|
|
107
|
+
{
|
|
108
|
+
table: 'tasks',
|
|
109
|
+
row_id: 'task-1',
|
|
110
|
+
op: 'upsert',
|
|
111
|
+
payload: {
|
|
112
|
+
id: 'task-1',
|
|
113
|
+
user_id: 'u1',
|
|
114
|
+
title: 'Task 1',
|
|
115
|
+
server_version: 0,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
87
124
|
it('keeps console routes disabled when console config is omitted', () => {
|
|
88
125
|
const server = createSyncServer(createOptions());
|
|
89
126
|
expect(server.consoleRoutes).toBeUndefined();
|
|
@@ -184,4 +221,42 @@ describe('createSyncServer console configuration', () => {
|
|
|
184
221
|
error: 'WEBSOCKET_CONNECTION_LIMIT_TOTAL',
|
|
185
222
|
});
|
|
186
223
|
});
|
|
224
|
+
|
|
225
|
+
it('emits live console events from sync lifecycle when console is enabled', async () => {
|
|
226
|
+
process.env.SYNC_CONSOLE_TOKEN = 'env-token';
|
|
227
|
+
const options = createOptions();
|
|
228
|
+
const server = createSyncServer({
|
|
229
|
+
...options,
|
|
230
|
+
console: {},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const liveEvents: Array<{
|
|
234
|
+
type: string;
|
|
235
|
+
data: Record<string, unknown>;
|
|
236
|
+
}> = [];
|
|
237
|
+
const listener = (event: {
|
|
238
|
+
type: 'push' | 'pull' | 'commit' | 'client_update';
|
|
239
|
+
timestamp: string;
|
|
240
|
+
data: Record<string, unknown>;
|
|
241
|
+
}) => {
|
|
242
|
+
liveEvents.push({ type: event.type, data: event.data });
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
server.consoleEventEmitter?.addListener(listener);
|
|
246
|
+
const app = new Hono();
|
|
247
|
+
app.route('/sync', server.syncRoutes);
|
|
248
|
+
|
|
249
|
+
const response = await app.request(createPushRequest());
|
|
250
|
+
expect(response.status).toBe(200);
|
|
251
|
+
|
|
252
|
+
const emittedTypes = liveEvents.map((event) => event.type);
|
|
253
|
+
expect(emittedTypes).toContain('push');
|
|
254
|
+
expect(emittedTypes).toContain('commit');
|
|
255
|
+
|
|
256
|
+
const pushEvent = liveEvents.find((event) => event.type === 'push');
|
|
257
|
+
expect(pushEvent?.data.actorId).toBe('u1');
|
|
258
|
+
expect(pushEvent?.data.clientId).toBe('client-1');
|
|
259
|
+
|
|
260
|
+
server.consoleEventEmitter?.removeListener(listener);
|
|
261
|
+
});
|
|
187
262
|
});
|