@atproto/bsync 0.0.19 → 0.0.21
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/CHANGELOG.md +13 -0
- package/LICENSE.txt +1 -1
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -0
- package/dist/context.js.map +1 -1
- package/dist/db/migrations/20250527T022203400Z-add-operation.d.ts +4 -0
- package/dist/db/migrations/20250527T022203400Z-add-operation.d.ts.map +1 -0
- package/dist/db/migrations/20250527T022203400Z-add-operation.js +21 -0
- package/dist/db/migrations/20250527T022203400Z-add-operation.js.map +1 -0
- package/dist/db/migrations/20250603T163446567Z-alter-operation.d.ts +4 -0
- package/dist/db/migrations/20250603T163446567Z-alter-operation.d.ts.map +1 -0
- package/dist/db/migrations/20250603T163446567Z-alter-operation.js +19 -0
- package/dist/db/migrations/20250603T163446567Z-alter-operation.js.map +1 -0
- package/dist/db/migrations/index.d.ts +2 -0
- package/dist/db/migrations/index.d.ts.map +1 -1
- package/dist/db/migrations/index.js +3 -1
- package/dist/db/migrations/index.js.map +1 -1
- package/dist/db/schema/index.d.ts +2 -1
- package/dist/db/schema/index.d.ts.map +1 -1
- package/dist/db/schema/operation.d.ts +18 -0
- package/dist/db/schema/operation.d.ts.map +1 -0
- package/dist/db/schema/operation.js +6 -0
- package/dist/db/schema/operation.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/proto/bsync_connect.d.ts +19 -1
- package/dist/proto/bsync_connect.d.ts.map +1 -1
- package/dist/proto/bsync_connect.js +18 -0
- package/dist/proto/bsync_connect.js.map +1 -1
- package/dist/proto/bsync_pb.d.ts +150 -0
- package/dist/proto/bsync_pb.d.ts.map +1 -1
- package/dist/proto/bsync_pb.js +401 -1
- package/dist/proto/bsync_pb.js.map +1 -1
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +4 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/put-operation.d.ts +6 -0
- package/dist/routes/put-operation.d.ts.map +1 -0
- package/dist/routes/put-operation.js +91 -0
- package/dist/routes/put-operation.js.map +1 -0
- package/dist/routes/scan-operations.d.ts +6 -0
- package/dist/routes/scan-operations.d.ts.map +1 -0
- package/dist/routes/scan-operations.js +59 -0
- package/dist/routes/scan-operations.js.map +1 -0
- package/package.json +2 -2
- package/proto/bsync.proto +40 -0
- package/src/context.ts +2 -0
- package/src/db/migrations/20250527T022203400Z-add-operation.ts +20 -0
- package/src/db/migrations/20250603T163446567Z-alter-operation.ts +19 -0
- package/src/db/migrations/index.ts +2 -0
- package/src/db/schema/index.ts +3 -1
- package/src/db/schema/operation.ts +20 -0
- package/src/index.ts +5 -0
- package/src/proto/bsync_connect.ts +22 -0
- package/src/proto/bsync_pb.ts +355 -0
- package/src/routes/index.ts +4 -0
- package/src/routes/put-operation.ts +127 -0
- package/src/routes/scan-operations.ts +67 -0
- package/tests/operations.test.ts +327 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.tests.tsbuildinfo +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const node_events_1 = require("node:events");
|
|
4
|
+
const operation_1 = require("../db/schema/operation");
|
|
5
|
+
const bsync_pb_1 = require("../proto/bsync_pb");
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
const util_1 = require("./util");
|
|
8
|
+
exports.default = (ctx) => ({
|
|
9
|
+
async scanOperations(req, handlerCtx) {
|
|
10
|
+
(0, auth_1.authWithApiKey)(ctx, handlerCtx);
|
|
11
|
+
const { db, events } = ctx;
|
|
12
|
+
const limit = req.limit || 1000;
|
|
13
|
+
const cursor = (0, util_1.validCursor)(req.cursor);
|
|
14
|
+
const nextOpPromise = (0, node_events_1.once)(events, operation_1.createOperationChannel, {
|
|
15
|
+
signal: (0, util_1.combineSignals)(ctx.shutdown, AbortSignal.timeout(ctx.cfg.service.longPollTimeoutMs)),
|
|
16
|
+
});
|
|
17
|
+
nextOpPromise.catch(() => null); // ensure timeout is always handled
|
|
18
|
+
const nextOpPageQb = db.db
|
|
19
|
+
.selectFrom('operation')
|
|
20
|
+
.selectAll()
|
|
21
|
+
.where('id', '>', cursor ?? -1)
|
|
22
|
+
.orderBy('id', 'asc')
|
|
23
|
+
.limit(limit);
|
|
24
|
+
let ops = await nextOpPageQb.execute();
|
|
25
|
+
if (!ops.length) {
|
|
26
|
+
// if there were no ops on the page, wait for an event then try again.
|
|
27
|
+
try {
|
|
28
|
+
await nextOpPromise;
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
ctx.shutdown.throwIfAborted();
|
|
32
|
+
return new bsync_pb_1.ScanOperationsResponse({
|
|
33
|
+
operations: [],
|
|
34
|
+
cursor: req.cursor,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
ops = await nextOpPageQb.execute();
|
|
38
|
+
if (!ops.length) {
|
|
39
|
+
return new bsync_pb_1.ScanOperationsResponse({
|
|
40
|
+
operations: [],
|
|
41
|
+
cursor: req.cursor,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const lastOp = ops[ops.length - 1];
|
|
46
|
+
return new bsync_pb_1.ScanOperationsResponse({
|
|
47
|
+
operations: ops.map((op) => ({
|
|
48
|
+
id: op.id.toString(),
|
|
49
|
+
actorDid: op.actorDid,
|
|
50
|
+
namespace: op.namespace,
|
|
51
|
+
key: op.key,
|
|
52
|
+
method: op.method,
|
|
53
|
+
payload: op.payload,
|
|
54
|
+
})),
|
|
55
|
+
cursor: lastOp.id.toString(),
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=scan-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan-operations.js","sourceRoot":"","sources":["../../src/routes/scan-operations.ts"],"names":[],"mappings":";;AAAA,6CAAkC;AAGlC,sDAA+D;AAE/D,gDAA0D;AAC1D,iCAAuC;AACvC,iCAAoD;AAEpD,kBAAe,CAAC,GAAe,EAAwC,EAAE,CAAC,CAAC;IACzE,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU;QAClC,IAAA,qBAAc,EAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QAC/B,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,GAAG,CAAA;QAC1B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,IAAI,CAAA;QAC/B,MAAM,MAAM,GAAG,IAAA,kBAAW,EAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACtC,MAAM,aAAa,GAAG,IAAA,kBAAI,EAAC,MAAM,EAAE,kCAAsB,EAAE;YACzD,MAAM,EAAE,IAAA,qBAAc,EACpB,GAAG,CAAC,QAAQ,EACZ,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CACvD;SACF,CAAC,CAAA;QACF,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA,CAAC,mCAAmC;QAEnE,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE;aACvB,UAAU,CAAC,WAAW,CAAC;aACvB,SAAS,EAAE;aACX,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,IAAI,CAAC,CAAC,CAAC;aAC9B,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC;aACpB,KAAK,CAAC,KAAK,CAAC,CAAA;QAEf,IAAI,GAAG,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;QAEtC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YAChB,sEAAsE;YACtE,IAAI,CAAC;gBACH,MAAM,aAAa,CAAA;YACrB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,GAAG,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAA;gBAC7B,OAAO,IAAI,iCAAsB,CAAC;oBAChC,UAAU,EAAE,EAAE;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;iBACnB,CAAC,CAAA;YACJ,CAAC;YACD,GAAG,GAAG,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;YAClC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;gBAChB,OAAO,IAAI,iCAAsB,CAAC;oBAChC,UAAU,EAAE,EAAE;oBACd,MAAM,EAAE,GAAG,CAAC,MAAM;iBACnB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAElC,OAAO,IAAI,iCAAsB,CAAC;YAChC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC3B,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE;gBACpB,QAAQ,EAAE,EAAE,CAAC,QAAQ;gBACrB,SAAS,EAAE,EAAE,CAAC,SAAS;gBACvB,GAAG,EAAE,EAAE,CAAC,GAAG;gBACX,MAAM,EAAE,EAAE,CAAC,MAAM;gBACjB,OAAO,EAAE,EAAE,CAAC,OAAO;aACpB,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE;SAC7B,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/bsync",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Sychronizing service for app.bsky App View (Bluesky API)",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"pino-http": "^8.2.1",
|
|
29
29
|
"typed-emitter": "^2.1.0",
|
|
30
30
|
"@atproto/common": "^0.4.11",
|
|
31
|
-
"@atproto/syntax": "^0.4.
|
|
31
|
+
"@atproto/syntax": "^0.4.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@bufbuild/buf": "^1.28.1",
|
package/proto/bsync.proto
CHANGED
|
@@ -67,6 +67,44 @@ message ScanNotifOperationsResponse {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
|
|
70
|
+
enum Method {
|
|
71
|
+
METHOD_UNSPECIFIED = 0;
|
|
72
|
+
METHOD_CREATE = 1;
|
|
73
|
+
METHOD_UPDATE = 2;
|
|
74
|
+
METHOD_DELETE = 3;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
message Operation {
|
|
78
|
+
string id = 1;
|
|
79
|
+
string actor_did = 2;
|
|
80
|
+
string namespace = 3;
|
|
81
|
+
string key = 4;
|
|
82
|
+
Method method = 5;
|
|
83
|
+
bytes payload = 6;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
message PutOperationRequest {
|
|
87
|
+
string actor_did = 1;
|
|
88
|
+
string namespace = 2;
|
|
89
|
+
string key = 3;
|
|
90
|
+
Method method = 4;
|
|
91
|
+
bytes payload = 5;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
message PutOperationResponse {
|
|
95
|
+
Operation operation = 1;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
message ScanOperationsRequest {
|
|
99
|
+
string cursor = 1;
|
|
100
|
+
int32 limit = 2;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
message ScanOperationsResponse {
|
|
104
|
+
repeated Operation operations = 1;
|
|
105
|
+
string cursor = 2;
|
|
106
|
+
}
|
|
107
|
+
|
|
70
108
|
|
|
71
109
|
// Ping
|
|
72
110
|
message PingRequest {}
|
|
@@ -79,6 +117,8 @@ service Service {
|
|
|
79
117
|
rpc ScanMuteOperations(ScanMuteOperationsRequest) returns (ScanMuteOperationsResponse);
|
|
80
118
|
rpc AddNotifOperation(AddNotifOperationRequest) returns (AddNotifOperationResponse);
|
|
81
119
|
rpc ScanNotifOperations(ScanNotifOperationsRequest) returns (ScanNotifOperationsResponse);
|
|
120
|
+
rpc PutOperation(PutOperationRequest) returns (PutOperationResponse);
|
|
121
|
+
rpc ScanOperations(ScanOperationsRequest) returns (ScanOperationsResponse);
|
|
82
122
|
// Ping
|
|
83
123
|
rpc Ping(PingRequest) returns (PingResponse);
|
|
84
124
|
}
|
package/src/context.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ServerConfig } from './config'
|
|
|
4
4
|
import { Database } from './db'
|
|
5
5
|
import { createMuteOpChannel } from './db/schema/mute_op'
|
|
6
6
|
import { createNotifOpChannel } from './db/schema/notif_op'
|
|
7
|
+
import { createOperationChannel } from './db/schema/operation'
|
|
7
8
|
|
|
8
9
|
export type AppContextOptions = {
|
|
9
10
|
db: Database
|
|
@@ -43,4 +44,5 @@ export class AppContext {
|
|
|
43
44
|
export type AppEvents = {
|
|
44
45
|
[createMuteOpChannel]: () => void
|
|
45
46
|
[createNotifOpChannel]: () => void
|
|
47
|
+
[createOperationChannel]: () => void
|
|
46
48
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Kysely, sql } from 'kysely'
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await db.schema
|
|
5
|
+
.createTable('operation')
|
|
6
|
+
.addColumn('id', 'bigserial', (col) => col.primaryKey())
|
|
7
|
+
.addColumn('collection', 'varchar', (col) => col.notNull())
|
|
8
|
+
.addColumn('actorDid', 'varchar', (col) => col.notNull())
|
|
9
|
+
.addColumn('rkey', 'varchar', (col) => col.notNull())
|
|
10
|
+
.addColumn('method', 'int2', (col) => col.notNull())
|
|
11
|
+
.addColumn('payload', sql`bytea`)
|
|
12
|
+
.addColumn('createdAt', 'timestamptz', (col) =>
|
|
13
|
+
col.notNull().defaultTo(sql`CURRENT_TIMESTAMP`),
|
|
14
|
+
)
|
|
15
|
+
.execute()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
19
|
+
await db.schema.dropTable('operation').execute()
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Kysely } from 'kysely'
|
|
2
|
+
|
|
3
|
+
export async function up(db: Kysely<unknown>): Promise<void> {
|
|
4
|
+
await db.schema
|
|
5
|
+
.alterTable('operation')
|
|
6
|
+
.renameColumn('collection', 'namespace')
|
|
7
|
+
.execute()
|
|
8
|
+
|
|
9
|
+
await db.schema.alterTable('operation').renameColumn('rkey', 'key').execute()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function down(db: Kysely<unknown>): Promise<void> {
|
|
13
|
+
await db.schema
|
|
14
|
+
.alterTable('operation')
|
|
15
|
+
.renameColumn('namespace', 'collection')
|
|
16
|
+
.execute()
|
|
17
|
+
|
|
18
|
+
await db.schema.alterTable('operation').renameColumn('key', 'rkey').execute()
|
|
19
|
+
}
|
|
@@ -4,3 +4,5 @@
|
|
|
4
4
|
|
|
5
5
|
export * as _20240108T220751294Z from './20240108T220751294Z-init'
|
|
6
6
|
export * as _20240717T224303472Z from './20240717T224303472Z-notif-ops'
|
|
7
|
+
export * as _20250527T022203400Z from './20250527T022203400Z-add-operation'
|
|
8
|
+
export * as _20250603T163446567Z from './20250603T163446567Z-alter-operation'
|
package/src/db/schema/index.ts
CHANGED
|
@@ -3,11 +3,13 @@ import * as muteItem from './mute_item'
|
|
|
3
3
|
import * as muteOp from './mute_op'
|
|
4
4
|
import * as notifItem from './notif_item'
|
|
5
5
|
import * as notifOp from './notif_op'
|
|
6
|
+
import * as op from './operation'
|
|
6
7
|
|
|
7
8
|
export type DatabaseSchemaType = muteItem.PartialDB &
|
|
8
9
|
muteOp.PartialDB &
|
|
9
10
|
notifItem.PartialDB &
|
|
10
|
-
notifOp.PartialDB
|
|
11
|
+
notifOp.PartialDB &
|
|
12
|
+
op.PartialDB
|
|
11
13
|
|
|
12
14
|
export type DatabaseSchema = Kysely<DatabaseSchemaType>
|
|
13
15
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GeneratedAlways } from 'kysely'
|
|
2
|
+
import { Method } from '../../proto/bsync_pb'
|
|
3
|
+
|
|
4
|
+
export type OperationMethod = Method.CREATE | Method.UPDATE | Method.DELETE
|
|
5
|
+
|
|
6
|
+
export interface Operation {
|
|
7
|
+
id: GeneratedAlways<number>
|
|
8
|
+
actorDid: string
|
|
9
|
+
namespace: string
|
|
10
|
+
key: string
|
|
11
|
+
method: OperationMethod
|
|
12
|
+
payload: Uint8Array
|
|
13
|
+
createdAt: GeneratedAlways<Date>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const tableName = 'operation'
|
|
17
|
+
|
|
18
|
+
export type PartialDB = { [tableName]: Operation }
|
|
19
|
+
|
|
20
|
+
export const createOperationChannel = 'operation_create' // used with listen/notify
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ServerConfig } from './config'
|
|
|
6
6
|
import { AppContext, AppContextOptions } from './context'
|
|
7
7
|
import { createMuteOpChannel } from './db/schema/mute_op'
|
|
8
8
|
import { createNotifOpChannel } from './db/schema/notif_op'
|
|
9
|
+
import { createOperationChannel } from './db/schema/operation'
|
|
9
10
|
import { dbLogger, loggerMiddleware } from './logger'
|
|
10
11
|
import routes from './routes'
|
|
11
12
|
|
|
@@ -92,6 +93,7 @@ export class BsyncService {
|
|
|
92
93
|
// if these error, unhandled rejection should cause process to exit
|
|
93
94
|
conn.query(`listen ${createMuteOpChannel}`)
|
|
94
95
|
conn.query(`listen ${createNotifOpChannel}`)
|
|
96
|
+
conn.query(`listen ${createOperationChannel}`)
|
|
95
97
|
conn.on('notification', (notif) => {
|
|
96
98
|
if (notif.channel === createMuteOpChannel) {
|
|
97
99
|
this.ctx.events.emit(createMuteOpChannel)
|
|
@@ -99,6 +101,9 @@ export class BsyncService {
|
|
|
99
101
|
if (notif.channel === createNotifOpChannel) {
|
|
100
102
|
this.ctx.events.emit(createNotifOpChannel)
|
|
101
103
|
}
|
|
104
|
+
if (notif.channel === createOperationChannel) {
|
|
105
|
+
this.ctx.events.emit(createOperationChannel)
|
|
106
|
+
}
|
|
102
107
|
})
|
|
103
108
|
}
|
|
104
109
|
}
|
|
@@ -10,10 +10,14 @@ import {
|
|
|
10
10
|
AddNotifOperationResponse,
|
|
11
11
|
PingRequest,
|
|
12
12
|
PingResponse,
|
|
13
|
+
PutOperationRequest,
|
|
14
|
+
PutOperationResponse,
|
|
13
15
|
ScanMuteOperationsRequest,
|
|
14
16
|
ScanMuteOperationsResponse,
|
|
15
17
|
ScanNotifOperationsRequest,
|
|
16
18
|
ScanNotifOperationsResponse,
|
|
19
|
+
ScanOperationsRequest,
|
|
20
|
+
ScanOperationsResponse,
|
|
17
21
|
} from './bsync_pb'
|
|
18
22
|
import { MethodKind } from '@bufbuild/protobuf'
|
|
19
23
|
|
|
@@ -61,6 +65,24 @@ export const Service = {
|
|
|
61
65
|
O: ScanNotifOperationsResponse,
|
|
62
66
|
kind: MethodKind.Unary,
|
|
63
67
|
},
|
|
68
|
+
/**
|
|
69
|
+
* @generated from rpc bsync.Service.PutOperation
|
|
70
|
+
*/
|
|
71
|
+
putOperation: {
|
|
72
|
+
name: 'PutOperation',
|
|
73
|
+
I: PutOperationRequest,
|
|
74
|
+
O: PutOperationResponse,
|
|
75
|
+
kind: MethodKind.Unary,
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* @generated from rpc bsync.Service.ScanOperations
|
|
79
|
+
*/
|
|
80
|
+
scanOperations: {
|
|
81
|
+
name: 'ScanOperations',
|
|
82
|
+
I: ScanOperationsRequest,
|
|
83
|
+
O: ScanOperationsResponse,
|
|
84
|
+
kind: MethodKind.Unary,
|
|
85
|
+
},
|
|
64
86
|
/**
|
|
65
87
|
* Ping
|
|
66
88
|
*
|
package/src/proto/bsync_pb.ts
CHANGED
|
@@ -13,6 +13,38 @@ import type {
|
|
|
13
13
|
} from '@bufbuild/protobuf'
|
|
14
14
|
import { Message, proto3 } from '@bufbuild/protobuf'
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @generated from enum bsync.Method
|
|
18
|
+
*/
|
|
19
|
+
export enum Method {
|
|
20
|
+
/**
|
|
21
|
+
* @generated from enum value: METHOD_UNSPECIFIED = 0;
|
|
22
|
+
*/
|
|
23
|
+
UNSPECIFIED = 0,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @generated from enum value: METHOD_CREATE = 1;
|
|
27
|
+
*/
|
|
28
|
+
CREATE = 1,
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @generated from enum value: METHOD_UPDATE = 2;
|
|
32
|
+
*/
|
|
33
|
+
UPDATE = 2,
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @generated from enum value: METHOD_DELETE = 3;
|
|
37
|
+
*/
|
|
38
|
+
DELETE = 3,
|
|
39
|
+
}
|
|
40
|
+
// Retrieve enum metadata with: proto3.getEnumType(Method)
|
|
41
|
+
proto3.util.setEnumType(Method, 'bsync.Method', [
|
|
42
|
+
{ no: 0, name: 'METHOD_UNSPECIFIED' },
|
|
43
|
+
{ no: 1, name: 'METHOD_CREATE' },
|
|
44
|
+
{ no: 2, name: 'METHOD_UPDATE' },
|
|
45
|
+
{ no: 3, name: 'METHOD_DELETE' },
|
|
46
|
+
])
|
|
47
|
+
|
|
16
48
|
/**
|
|
17
49
|
* @generated from message bsync.MuteOperation
|
|
18
50
|
*/
|
|
@@ -689,6 +721,329 @@ export class ScanNotifOperationsResponse extends Message<ScanNotifOperationsResp
|
|
|
689
721
|
}
|
|
690
722
|
}
|
|
691
723
|
|
|
724
|
+
/**
|
|
725
|
+
* @generated from message bsync.Operation
|
|
726
|
+
*/
|
|
727
|
+
export class Operation extends Message<Operation> {
|
|
728
|
+
/**
|
|
729
|
+
* @generated from field: string id = 1;
|
|
730
|
+
*/
|
|
731
|
+
id = ''
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* @generated from field: string actor_did = 2;
|
|
735
|
+
*/
|
|
736
|
+
actorDid = ''
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* @generated from field: string namespace = 3;
|
|
740
|
+
*/
|
|
741
|
+
namespace = ''
|
|
742
|
+
|
|
743
|
+
/**
|
|
744
|
+
* @generated from field: string key = 4;
|
|
745
|
+
*/
|
|
746
|
+
key = ''
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* @generated from field: bsync.Method method = 5;
|
|
750
|
+
*/
|
|
751
|
+
method = Method.UNSPECIFIED
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* @generated from field: bytes payload = 6;
|
|
755
|
+
*/
|
|
756
|
+
payload = new Uint8Array(0)
|
|
757
|
+
|
|
758
|
+
constructor(data?: PartialMessage<Operation>) {
|
|
759
|
+
super()
|
|
760
|
+
proto3.util.initPartial(data, this)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
static readonly runtime: typeof proto3 = proto3
|
|
764
|
+
static readonly typeName = 'bsync.Operation'
|
|
765
|
+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
|
766
|
+
{ no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
767
|
+
{ no: 2, name: 'actor_did', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
768
|
+
{ no: 3, name: 'namespace', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
769
|
+
{ no: 4, name: 'key', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
770
|
+
{ no: 5, name: 'method', kind: 'enum', T: proto3.getEnumType(Method) },
|
|
771
|
+
{ no: 6, name: 'payload', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
|
|
772
|
+
])
|
|
773
|
+
|
|
774
|
+
static fromBinary(
|
|
775
|
+
bytes: Uint8Array,
|
|
776
|
+
options?: Partial<BinaryReadOptions>,
|
|
777
|
+
): Operation {
|
|
778
|
+
return new Operation().fromBinary(bytes, options)
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
static fromJson(
|
|
782
|
+
jsonValue: JsonValue,
|
|
783
|
+
options?: Partial<JsonReadOptions>,
|
|
784
|
+
): Operation {
|
|
785
|
+
return new Operation().fromJson(jsonValue, options)
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
static fromJsonString(
|
|
789
|
+
jsonString: string,
|
|
790
|
+
options?: Partial<JsonReadOptions>,
|
|
791
|
+
): Operation {
|
|
792
|
+
return new Operation().fromJsonString(jsonString, options)
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
static equals(
|
|
796
|
+
a: Operation | PlainMessage<Operation> | undefined,
|
|
797
|
+
b: Operation | PlainMessage<Operation> | undefined,
|
|
798
|
+
): boolean {
|
|
799
|
+
return proto3.util.equals(Operation, a, b)
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* @generated from message bsync.PutOperationRequest
|
|
805
|
+
*/
|
|
806
|
+
export class PutOperationRequest extends Message<PutOperationRequest> {
|
|
807
|
+
/**
|
|
808
|
+
* @generated from field: string actor_did = 1;
|
|
809
|
+
*/
|
|
810
|
+
actorDid = ''
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* @generated from field: string namespace = 2;
|
|
814
|
+
*/
|
|
815
|
+
namespace = ''
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* @generated from field: string key = 3;
|
|
819
|
+
*/
|
|
820
|
+
key = ''
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* @generated from field: bsync.Method method = 4;
|
|
824
|
+
*/
|
|
825
|
+
method = Method.UNSPECIFIED
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* @generated from field: bytes payload = 5;
|
|
829
|
+
*/
|
|
830
|
+
payload = new Uint8Array(0)
|
|
831
|
+
|
|
832
|
+
constructor(data?: PartialMessage<PutOperationRequest>) {
|
|
833
|
+
super()
|
|
834
|
+
proto3.util.initPartial(data, this)
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
static readonly runtime: typeof proto3 = proto3
|
|
838
|
+
static readonly typeName = 'bsync.PutOperationRequest'
|
|
839
|
+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
|
840
|
+
{ no: 1, name: 'actor_did', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
841
|
+
{ no: 2, name: 'namespace', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
842
|
+
{ no: 3, name: 'key', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
843
|
+
{ no: 4, name: 'method', kind: 'enum', T: proto3.getEnumType(Method) },
|
|
844
|
+
{ no: 5, name: 'payload', kind: 'scalar', T: 12 /* ScalarType.BYTES */ },
|
|
845
|
+
])
|
|
846
|
+
|
|
847
|
+
static fromBinary(
|
|
848
|
+
bytes: Uint8Array,
|
|
849
|
+
options?: Partial<BinaryReadOptions>,
|
|
850
|
+
): PutOperationRequest {
|
|
851
|
+
return new PutOperationRequest().fromBinary(bytes, options)
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
static fromJson(
|
|
855
|
+
jsonValue: JsonValue,
|
|
856
|
+
options?: Partial<JsonReadOptions>,
|
|
857
|
+
): PutOperationRequest {
|
|
858
|
+
return new PutOperationRequest().fromJson(jsonValue, options)
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
static fromJsonString(
|
|
862
|
+
jsonString: string,
|
|
863
|
+
options?: Partial<JsonReadOptions>,
|
|
864
|
+
): PutOperationRequest {
|
|
865
|
+
return new PutOperationRequest().fromJsonString(jsonString, options)
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
static equals(
|
|
869
|
+
a: PutOperationRequest | PlainMessage<PutOperationRequest> | undefined,
|
|
870
|
+
b: PutOperationRequest | PlainMessage<PutOperationRequest> | undefined,
|
|
871
|
+
): boolean {
|
|
872
|
+
return proto3.util.equals(PutOperationRequest, a, b)
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* @generated from message bsync.PutOperationResponse
|
|
878
|
+
*/
|
|
879
|
+
export class PutOperationResponse extends Message<PutOperationResponse> {
|
|
880
|
+
/**
|
|
881
|
+
* @generated from field: bsync.Operation operation = 1;
|
|
882
|
+
*/
|
|
883
|
+
operation?: Operation
|
|
884
|
+
|
|
885
|
+
constructor(data?: PartialMessage<PutOperationResponse>) {
|
|
886
|
+
super()
|
|
887
|
+
proto3.util.initPartial(data, this)
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
static readonly runtime: typeof proto3 = proto3
|
|
891
|
+
static readonly typeName = 'bsync.PutOperationResponse'
|
|
892
|
+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
|
893
|
+
{ no: 1, name: 'operation', kind: 'message', T: Operation },
|
|
894
|
+
])
|
|
895
|
+
|
|
896
|
+
static fromBinary(
|
|
897
|
+
bytes: Uint8Array,
|
|
898
|
+
options?: Partial<BinaryReadOptions>,
|
|
899
|
+
): PutOperationResponse {
|
|
900
|
+
return new PutOperationResponse().fromBinary(bytes, options)
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
static fromJson(
|
|
904
|
+
jsonValue: JsonValue,
|
|
905
|
+
options?: Partial<JsonReadOptions>,
|
|
906
|
+
): PutOperationResponse {
|
|
907
|
+
return new PutOperationResponse().fromJson(jsonValue, options)
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
static fromJsonString(
|
|
911
|
+
jsonString: string,
|
|
912
|
+
options?: Partial<JsonReadOptions>,
|
|
913
|
+
): PutOperationResponse {
|
|
914
|
+
return new PutOperationResponse().fromJsonString(jsonString, options)
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
static equals(
|
|
918
|
+
a: PutOperationResponse | PlainMessage<PutOperationResponse> | undefined,
|
|
919
|
+
b: PutOperationResponse | PlainMessage<PutOperationResponse> | undefined,
|
|
920
|
+
): boolean {
|
|
921
|
+
return proto3.util.equals(PutOperationResponse, a, b)
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* @generated from message bsync.ScanOperationsRequest
|
|
927
|
+
*/
|
|
928
|
+
export class ScanOperationsRequest extends Message<ScanOperationsRequest> {
|
|
929
|
+
/**
|
|
930
|
+
* @generated from field: string cursor = 1;
|
|
931
|
+
*/
|
|
932
|
+
cursor = ''
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* @generated from field: int32 limit = 2;
|
|
936
|
+
*/
|
|
937
|
+
limit = 0
|
|
938
|
+
|
|
939
|
+
constructor(data?: PartialMessage<ScanOperationsRequest>) {
|
|
940
|
+
super()
|
|
941
|
+
proto3.util.initPartial(data, this)
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
static readonly runtime: typeof proto3 = proto3
|
|
945
|
+
static readonly typeName = 'bsync.ScanOperationsRequest'
|
|
946
|
+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
|
947
|
+
{ no: 1, name: 'cursor', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
948
|
+
{ no: 2, name: 'limit', kind: 'scalar', T: 5 /* ScalarType.INT32 */ },
|
|
949
|
+
])
|
|
950
|
+
|
|
951
|
+
static fromBinary(
|
|
952
|
+
bytes: Uint8Array,
|
|
953
|
+
options?: Partial<BinaryReadOptions>,
|
|
954
|
+
): ScanOperationsRequest {
|
|
955
|
+
return new ScanOperationsRequest().fromBinary(bytes, options)
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
static fromJson(
|
|
959
|
+
jsonValue: JsonValue,
|
|
960
|
+
options?: Partial<JsonReadOptions>,
|
|
961
|
+
): ScanOperationsRequest {
|
|
962
|
+
return new ScanOperationsRequest().fromJson(jsonValue, options)
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
static fromJsonString(
|
|
966
|
+
jsonString: string,
|
|
967
|
+
options?: Partial<JsonReadOptions>,
|
|
968
|
+
): ScanOperationsRequest {
|
|
969
|
+
return new ScanOperationsRequest().fromJsonString(jsonString, options)
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
static equals(
|
|
973
|
+
a: ScanOperationsRequest | PlainMessage<ScanOperationsRequest> | undefined,
|
|
974
|
+
b: ScanOperationsRequest | PlainMessage<ScanOperationsRequest> | undefined,
|
|
975
|
+
): boolean {
|
|
976
|
+
return proto3.util.equals(ScanOperationsRequest, a, b)
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* @generated from message bsync.ScanOperationsResponse
|
|
982
|
+
*/
|
|
983
|
+
export class ScanOperationsResponse extends Message<ScanOperationsResponse> {
|
|
984
|
+
/**
|
|
985
|
+
* @generated from field: repeated bsync.Operation operations = 1;
|
|
986
|
+
*/
|
|
987
|
+
operations: Operation[] = []
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* @generated from field: string cursor = 2;
|
|
991
|
+
*/
|
|
992
|
+
cursor = ''
|
|
993
|
+
|
|
994
|
+
constructor(data?: PartialMessage<ScanOperationsResponse>) {
|
|
995
|
+
super()
|
|
996
|
+
proto3.util.initPartial(data, this)
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
static readonly runtime: typeof proto3 = proto3
|
|
1000
|
+
static readonly typeName = 'bsync.ScanOperationsResponse'
|
|
1001
|
+
static readonly fields: FieldList = proto3.util.newFieldList(() => [
|
|
1002
|
+
{
|
|
1003
|
+
no: 1,
|
|
1004
|
+
name: 'operations',
|
|
1005
|
+
kind: 'message',
|
|
1006
|
+
T: Operation,
|
|
1007
|
+
repeated: true,
|
|
1008
|
+
},
|
|
1009
|
+
{ no: 2, name: 'cursor', kind: 'scalar', T: 9 /* ScalarType.STRING */ },
|
|
1010
|
+
])
|
|
1011
|
+
|
|
1012
|
+
static fromBinary(
|
|
1013
|
+
bytes: Uint8Array,
|
|
1014
|
+
options?: Partial<BinaryReadOptions>,
|
|
1015
|
+
): ScanOperationsResponse {
|
|
1016
|
+
return new ScanOperationsResponse().fromBinary(bytes, options)
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
static fromJson(
|
|
1020
|
+
jsonValue: JsonValue,
|
|
1021
|
+
options?: Partial<JsonReadOptions>,
|
|
1022
|
+
): ScanOperationsResponse {
|
|
1023
|
+
return new ScanOperationsResponse().fromJson(jsonValue, options)
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
static fromJsonString(
|
|
1027
|
+
jsonString: string,
|
|
1028
|
+
options?: Partial<JsonReadOptions>,
|
|
1029
|
+
): ScanOperationsResponse {
|
|
1030
|
+
return new ScanOperationsResponse().fromJsonString(jsonString, options)
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
static equals(
|
|
1034
|
+
a:
|
|
1035
|
+
| ScanOperationsResponse
|
|
1036
|
+
| PlainMessage<ScanOperationsResponse>
|
|
1037
|
+
| undefined,
|
|
1038
|
+
b:
|
|
1039
|
+
| ScanOperationsResponse
|
|
1040
|
+
| PlainMessage<ScanOperationsResponse>
|
|
1041
|
+
| undefined,
|
|
1042
|
+
): boolean {
|
|
1043
|
+
return proto3.util.equals(ScanOperationsResponse, a, b)
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
692
1047
|
/**
|
|
693
1048
|
* Ping
|
|
694
1049
|
*
|
package/src/routes/index.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { AppContext } from '../context'
|
|
|
4
4
|
import { Service } from '../proto/bsync_connect'
|
|
5
5
|
import addMuteOperation from './add-mute-operation'
|
|
6
6
|
import addNotifOperation from './add-notif-operation'
|
|
7
|
+
import putOperation from './put-operation'
|
|
7
8
|
import scanMuteOperations from './scan-mute-operations'
|
|
8
9
|
import scanNotifOperations from './scan-notif-operations'
|
|
10
|
+
import scanOperations from './scan-operations'
|
|
9
11
|
|
|
10
12
|
export default (ctx: AppContext) => (router: ConnectRouter) => {
|
|
11
13
|
return router.service(Service, {
|
|
@@ -13,6 +15,8 @@ export default (ctx: AppContext) => (router: ConnectRouter) => {
|
|
|
13
15
|
...scanMuteOperations(ctx),
|
|
14
16
|
...addNotifOperation(ctx),
|
|
15
17
|
...scanNotifOperations(ctx),
|
|
18
|
+
...putOperation(ctx),
|
|
19
|
+
...scanOperations(ctx),
|
|
16
20
|
async ping() {
|
|
17
21
|
const { db } = ctx
|
|
18
22
|
await sql`select 1`.execute(db.db)
|