matrix-nodejs-homeserver 0.0.0-stage → 0.3.1

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.
Files changed (141) hide show
  1. package/LICENSE +75 -0
  2. package/README.md +479 -2
  3. package/dist/adapters/auth.d.ts +50 -0
  4. package/dist/adapters/auth.js +18 -0
  5. package/dist/adapters/cluster.d.ts +55 -0
  6. package/dist/adapters/cluster.js +249 -0
  7. package/dist/adapters/media.d.ts +50 -0
  8. package/dist/adapters/media.js +63 -0
  9. package/dist/adapters/s3.d.ts +33 -0
  10. package/dist/adapters/s3.js +95 -0
  11. package/dist/api/account.js +594 -0
  12. package/dist/api/admin.js +267 -0
  13. package/dist/api/appservice.js +45 -0
  14. package/dist/api/backup.js +280 -0
  15. package/dist/api/federation.js +826 -0
  16. package/dist/api/filters.js +88 -0
  17. package/dist/api/index.js +47 -0
  18. package/dist/api/legacy.js +183 -0
  19. package/dist/api/media.js +271 -0
  20. package/dist/api/misc.js +95 -0
  21. package/dist/api/preview.js +201 -0
  22. package/dist/api/profile.js +176 -0
  23. package/dist/api/push.js +202 -0
  24. package/dist/api/relationships.js +270 -0
  25. package/dist/api/rooms.js +1487 -0
  26. package/dist/api/rtc.d.ts +23 -0
  27. package/dist/api/rtc.js +66 -0
  28. package/dist/api/search.js +161 -0
  29. package/dist/api/slidingsync.js +474 -0
  30. package/dist/api/spaces.js +177 -0
  31. package/dist/api/sync.js +609 -0
  32. package/dist/api/threadsubs.js +140 -0
  33. package/dist/api/threepid.js +155 -0
  34. package/dist/api/uia.js +127 -0
  35. package/dist/api/user.js +329 -0
  36. package/dist/core/admin.d.ts +84 -0
  37. package/dist/core/admin.js +308 -0
  38. package/dist/core/adminroom.d.ts +49 -0
  39. package/dist/core/adminroom.js +483 -0
  40. package/dist/core/appservices.d.ts +74 -0
  41. package/dist/core/appservices.js +369 -0
  42. package/dist/core/audit.d.ts +50 -0
  43. package/dist/core/audit.js +86 -0
  44. package/dist/core/auth.d.ts +48 -0
  45. package/dist/core/auth.js +237 -0
  46. package/dist/core/authrules.d.ts +4 -0
  47. package/dist/core/authrules.js +348 -0
  48. package/dist/core/cluster.d.ts +66 -0
  49. package/dist/core/cluster.js +191 -0
  50. package/dist/core/crypto.d.ts +10 -0
  51. package/dist/core/crypto.js +100 -0
  52. package/dist/core/delayed.d.ts +39 -0
  53. package/dist/core/delayed.js +160 -0
  54. package/dist/core/errors.d.ts +9 -0
  55. package/dist/core/errors.js +45 -0
  56. package/dist/core/events.d.ts +32 -0
  57. package/dist/core/events.js +186 -0
  58. package/dist/core/glob.js +66 -0
  59. package/dist/core/identity.d.ts +24 -0
  60. package/dist/core/identity.js +96 -0
  61. package/dist/core/ids.js +36 -0
  62. package/dist/core/invitefilter.js +36 -0
  63. package/dist/core/json.js +16 -0
  64. package/dist/core/keys.d.ts +36 -0
  65. package/dist/core/keys.js +450 -0
  66. package/dist/core/m.d.ts +209 -0
  67. package/dist/core/m.js +182 -0
  68. package/dist/core/notifier.d.ts +17 -0
  69. package/dist/core/notifier.js +54 -0
  70. package/dist/core/oauth.d.ts +38 -0
  71. package/dist/core/oauth.js +108 -0
  72. package/dist/core/partialstate.d.ts +32 -0
  73. package/dist/core/partialstate.js +198 -0
  74. package/dist/core/phone.js +268 -0
  75. package/dist/core/policy.d.ts +29 -0
  76. package/dist/core/policy.js +97 -0
  77. package/dist/core/profile.js +39 -0
  78. package/dist/core/push.d.ts +46 -0
  79. package/dist/core/push.js +307 -0
  80. package/dist/core/pushrules.js +229 -0
  81. package/dist/core/ratelimit.d.ts +23 -0
  82. package/dist/core/ratelimit.js +77 -0
  83. package/dist/core/rooms.d.ts +215 -0
  84. package/dist/core/rooms.js +1731 -0
  85. package/dist/core/settings.d.ts +11 -0
  86. package/dist/core/settings.js +29 -0
  87. package/dist/core/sso.d.ts +46 -0
  88. package/dist/core/sso.js +165 -0
  89. package/dist/core/stateres.d.ts +4 -0
  90. package/dist/core/stateres.js +209 -0
  91. package/dist/core/threepid.d.ts +80 -0
  92. package/dist/core/threepid.js +275 -0
  93. package/dist/core/typing.d.ts +16 -0
  94. package/dist/core/typing.js +60 -0
  95. package/dist/federation/client.d.ts +51 -0
  96. package/dist/federation/client.js +279 -0
  97. package/dist/federation/index.d.ts +153 -0
  98. package/dist/federation/index.js +1059 -0
  99. package/dist/federation/keyring.d.ts +26 -0
  100. package/dist/federation/keyring.js +122 -0
  101. package/dist/federation/sender.d.ts +26 -0
  102. package/dist/federation/sender.js +164 -0
  103. package/dist/homeserver.d.ts +224 -0
  104. package/dist/homeserver.js +302 -0
  105. package/dist/http/adapters.d.ts +40 -0
  106. package/dist/http/adapters.js +130 -0
  107. package/dist/http/handler.d.ts +8 -0
  108. package/dist/http/handler.js +181 -0
  109. package/dist/http/input.js +24 -0
  110. package/dist/http/procedure.js +25 -0
  111. package/dist/http/router.d.ts +43 -0
  112. package/dist/http/router.js +56 -0
  113. package/dist/index.d.ts +26 -0
  114. package/dist/index.js +15 -0
  115. package/dist/storage/memory.d.ts +5 -0
  116. package/dist/storage/memory.js +122 -0
  117. package/dist/storage/schema.d.ts +4 -0
  118. package/dist/storage/schema.js +664 -0
  119. package/dist/storage/sql.d.ts +72 -0
  120. package/dist/storage/sql.js +274 -0
  121. package/dist/storage/types.d.ts +55 -0
  122. package/dist/vendor/zod/LICENSE +21 -0
  123. package/dist/vendor/zod/v4/classic/errors.js +54 -0
  124. package/dist/vendor/zod/v4/classic/parse.js +17 -0
  125. package/dist/vendor/zod/v4/classic/schemas.js +865 -0
  126. package/dist/vendor/zod/v4/core/api.js +512 -0
  127. package/dist/vendor/zod/v4/core/checks.js +300 -0
  128. package/dist/vendor/zod/v4/core/core.js +109 -0
  129. package/dist/vendor/zod/v4/core/doc.js +35 -0
  130. package/dist/vendor/zod/v4/core/errors.js +118 -0
  131. package/dist/vendor/zod/v4/core/json-schema-processors.js +428 -0
  132. package/dist/vendor/zod/v4/core/memoizer.js +255 -0
  133. package/dist/vendor/zod/v4/core/parse.js +206 -0
  134. package/dist/vendor/zod/v4/core/regexes.js +73 -0
  135. package/dist/vendor/zod/v4/core/registries.js +48 -0
  136. package/dist/vendor/zod/v4/core/schemas.js +1378 -0
  137. package/dist/vendor/zod/v4/core/to-json-schema.js +448 -0
  138. package/dist/vendor/zod/v4/core/util.js +537 -0
  139. package/dist/vendor/zod/v4/core/versions.js +8 -0
  140. package/dist/vendor/zod/v4/locales/en.js +110 -0
  141. package/package.json +65 -4
@@ -0,0 +1,664 @@
1
+ //#region src/storage/schema.ts
2
+ const s = { type: "string" };
3
+ const sn = {
4
+ type: "string",
5
+ required: false
6
+ };
7
+ const n = { type: "number" };
8
+ const nn = {
9
+ type: "number",
10
+ required: false
11
+ };
12
+ const b = { type: "boolean" };
13
+ const bn = {
14
+ type: "boolean",
15
+ required: false
16
+ };
17
+ const j = { type: "json" };
18
+ const schema = {
19
+ users: {
20
+ fields: {
21
+ user_id: s,
22
+ localpart: s,
23
+ password_hash: sn,
24
+ displayname: sn,
25
+ avatar_url: sn,
26
+ is_guest: b,
27
+ is_admin: b,
28
+ deactivated: b,
29
+ created_ts: n,
30
+ locked: bn,
31
+ suspended: bn
32
+ },
33
+ primaryKey: ["user_id"]
34
+ },
35
+ devices: {
36
+ fields: {
37
+ user_id: s,
38
+ device_id: s,
39
+ display_name: sn,
40
+ last_seen_ts: nn,
41
+ last_seen_ip: sn
42
+ },
43
+ primaryKey: ["user_id", "device_id"]
44
+ },
45
+ access_tokens: {
46
+ fields: {
47
+ token: s,
48
+ user_id: s,
49
+ device_id: s,
50
+ refresh_token: sn,
51
+ expires_ts: nn
52
+ },
53
+ primaryKey: ["token"],
54
+ indexes: [["user_id"], ["refresh_token"]]
55
+ },
56
+ rooms: {
57
+ fields: {
58
+ room_id: s,
59
+ room_version: s,
60
+ creator: s,
61
+ is_public: b,
62
+ created_ts: n
63
+ },
64
+ primaryKey: ["room_id"]
65
+ },
66
+ events: {
67
+ fields: {
68
+ event_id: s,
69
+ room_id: s,
70
+ stream: n,
71
+ depth: n,
72
+ type: s,
73
+ state_key: sn,
74
+ sender: s,
75
+ json: j,
76
+ state_snapshot: n,
77
+ txn_id: sn,
78
+ txn_token: sn,
79
+ redacted_by: sn,
80
+ /** Some prev_events were never fetched: clients must treat the timeline as limited here. */
81
+ gap: {
82
+ type: "boolean",
83
+ required: false
84
+ }
85
+ },
86
+ primaryKey: ["event_id"],
87
+ indexes: [
88
+ ["room_id", "stream"],
89
+ ["stream"],
90
+ ["txn_id"]
91
+ ]
92
+ },
93
+ state_snapshots: {
94
+ fields: {
95
+ id: n,
96
+ room_id: s,
97
+ prev: nn,
98
+ depth: nn,
99
+ state: j
100
+ },
101
+ primaryKey: ["id"]
102
+ },
103
+ relations: {
104
+ fields: {
105
+ event_id: s,
106
+ room_id: s,
107
+ parent_id: s,
108
+ rel_type: s,
109
+ type: s,
110
+ sender: s,
111
+ stream: n
112
+ },
113
+ primaryKey: ["event_id"],
114
+ indexes: [["parent_id"], ["room_id", "rel_type"]]
115
+ },
116
+ partial_state_rooms: {
117
+ fields: {
118
+ room_id: s,
119
+ join_event_id: s,
120
+ origin: s,
121
+ servers: j,
122
+ created_ts: n,
123
+ completed_stream: nn,
124
+ pending_device_users: {
125
+ type: "json",
126
+ required: false
127
+ }
128
+ },
129
+ primaryKey: ["room_id"]
130
+ },
131
+ event_edges: {
132
+ fields: {
133
+ event_id: s,
134
+ room_id: s,
135
+ parent_id: s,
136
+ rel_type: s,
137
+ ts: n,
138
+ depth: n
139
+ },
140
+ primaryKey: ["event_id"],
141
+ indexes: [["parent_id"]]
142
+ },
143
+ profile_fields: {
144
+ fields: {
145
+ user_id: s,
146
+ field: s,
147
+ value: {
148
+ type: "json",
149
+ required: false
150
+ },
151
+ stream: n
152
+ },
153
+ primaryKey: ["user_id", "field"],
154
+ indexes: [["stream"]]
155
+ },
156
+ thread_subscriptions: {
157
+ fields: {
158
+ user_id: s,
159
+ room_id: s,
160
+ thread_id: s,
161
+ subscribed: b,
162
+ automatic: b,
163
+ unsubscribed_after: nn,
164
+ stream: n
165
+ },
166
+ primaryKey: [
167
+ "user_id",
168
+ "room_id",
169
+ "thread_id"
170
+ ],
171
+ indexes: [["user_id", "stream"]]
172
+ },
173
+ registration_tokens: {
174
+ fields: {
175
+ token: s,
176
+ uses_allowed: nn,
177
+ pending: n,
178
+ completed: n,
179
+ expiry_time: nn
180
+ },
181
+ primaryKey: ["token"]
182
+ },
183
+ notifications: {
184
+ fields: {
185
+ user_id: s,
186
+ room_id: s,
187
+ event_id: s,
188
+ stream: n,
189
+ highlight: b,
190
+ thread_id: s,
191
+ actions: j,
192
+ ts: n
193
+ },
194
+ primaryKey: ["user_id", "event_id"],
195
+ indexes: [["user_id", "room_id"], ["user_id", "stream"]]
196
+ },
197
+ sso_identities: {
198
+ fields: {
199
+ idp_id: s,
200
+ subject: s,
201
+ user_id: s
202
+ },
203
+ primaryKey: ["idp_id", "subject"],
204
+ indexes: [["user_id"]]
205
+ },
206
+ login_tokens: {
207
+ fields: {
208
+ token: s,
209
+ user_id: s,
210
+ expires_ts: n
211
+ },
212
+ primaryKey: ["token"]
213
+ },
214
+ sliding_sync_connections: {
215
+ fields: {
216
+ user_id: s,
217
+ device_id: s,
218
+ conn_id: s,
219
+ pos: n,
220
+ state: j,
221
+ updated_ts: n
222
+ },
223
+ primaryKey: [
224
+ "user_id",
225
+ "device_id",
226
+ "conn_id"
227
+ ]
228
+ },
229
+ current_state: {
230
+ fields: {
231
+ room_id: s,
232
+ type: s,
233
+ state_key: s,
234
+ event_id: s
235
+ },
236
+ primaryKey: [
237
+ "room_id",
238
+ "type",
239
+ "state_key"
240
+ ]
241
+ },
242
+ memberships: {
243
+ fields: {
244
+ room_id: s,
245
+ user_id: s,
246
+ membership: s,
247
+ event_id: s,
248
+ stream: n,
249
+ forgotten: b
250
+ },
251
+ primaryKey: ["room_id", "user_id"],
252
+ indexes: [["user_id"]]
253
+ },
254
+ room_aliases: {
255
+ fields: {
256
+ alias: s,
257
+ room_id: s,
258
+ creator: s
259
+ },
260
+ primaryKey: ["alias"],
261
+ indexes: [["room_id"]]
262
+ },
263
+ account_data: {
264
+ fields: {
265
+ user_id: s,
266
+ room_id: s,
267
+ type: s,
268
+ content: j,
269
+ stream: n
270
+ },
271
+ primaryKey: [
272
+ "user_id",
273
+ "room_id",
274
+ "type"
275
+ ]
276
+ },
277
+ receipts: {
278
+ fields: {
279
+ room_id: s,
280
+ user_id: s,
281
+ receipt_type: s,
282
+ thread_id: s,
283
+ event_id: s,
284
+ ts: n,
285
+ stream: n
286
+ },
287
+ primaryKey: [
288
+ "room_id",
289
+ "user_id",
290
+ "receipt_type",
291
+ "thread_id"
292
+ ],
293
+ indexes: [["stream"]]
294
+ },
295
+ to_device: {
296
+ fields: {
297
+ stream: n,
298
+ user_id: s,
299
+ device_id: s,
300
+ sender: s,
301
+ type: s,
302
+ content: j
303
+ },
304
+ primaryKey: [
305
+ "stream",
306
+ "user_id",
307
+ "device_id"
308
+ ],
309
+ indexes: [["user_id", "device_id"]]
310
+ },
311
+ filters: {
312
+ fields: {
313
+ user_id: s,
314
+ filter_id: s,
315
+ filter: j
316
+ },
317
+ primaryKey: ["user_id", "filter_id"]
318
+ },
319
+ device_keys: {
320
+ fields: {
321
+ user_id: s,
322
+ device_id: s,
323
+ keys: j,
324
+ stream: n
325
+ },
326
+ primaryKey: ["user_id", "device_id"]
327
+ },
328
+ one_time_keys: {
329
+ fields: {
330
+ user_id: s,
331
+ device_id: s,
332
+ key_id: s,
333
+ algorithm: s,
334
+ key: j,
335
+ fallback: b,
336
+ used: b,
337
+ seq: n
338
+ },
339
+ primaryKey: [
340
+ "user_id",
341
+ "device_id",
342
+ "key_id"
343
+ ]
344
+ },
345
+ fallback_keys: {
346
+ fields: {
347
+ user_id: s,
348
+ device_id: s,
349
+ algorithm: s,
350
+ key_id: s,
351
+ key: j,
352
+ used: b
353
+ },
354
+ primaryKey: [
355
+ "user_id",
356
+ "device_id",
357
+ "algorithm"
358
+ ]
359
+ },
360
+ cross_signing_keys: {
361
+ fields: {
362
+ user_id: s,
363
+ key_type: s,
364
+ key: j,
365
+ stream: n
366
+ },
367
+ primaryKey: ["user_id", "key_type"]
368
+ },
369
+ key_signatures: {
370
+ fields: {
371
+ user_id: s,
372
+ key_id: s,
373
+ signer: s,
374
+ signer_key_id: s,
375
+ signature: s
376
+ },
377
+ primaryKey: [
378
+ "user_id",
379
+ "key_id",
380
+ "signer",
381
+ "signer_key_id"
382
+ ]
383
+ },
384
+ device_list_changes: {
385
+ fields: {
386
+ user_id: s,
387
+ stream: n
388
+ },
389
+ primaryKey: ["user_id"],
390
+ indexes: [["stream"]]
391
+ },
392
+ presence: {
393
+ fields: {
394
+ user_id: s,
395
+ presence: s,
396
+ status_msg: sn,
397
+ last_active_ts: n,
398
+ stream: n
399
+ },
400
+ primaryKey: ["user_id"]
401
+ },
402
+ media: {
403
+ fields: {
404
+ media_id: s,
405
+ content_type: sn,
406
+ filename: sn,
407
+ size: n,
408
+ uploader: s,
409
+ created_ts: n,
410
+ pending: b
411
+ },
412
+ primaryKey: ["media_id"]
413
+ },
414
+ pushers: {
415
+ fields: {
416
+ user_id: s,
417
+ app_id: s,
418
+ pushkey: s,
419
+ device_id: sn,
420
+ pusher: j
421
+ },
422
+ primaryKey: [
423
+ "user_id",
424
+ "app_id",
425
+ "pushkey"
426
+ ]
427
+ },
428
+ backup_versions: {
429
+ fields: {
430
+ user_id: s,
431
+ version: n,
432
+ algorithm: s,
433
+ auth_data: j,
434
+ etag: n,
435
+ deleted: b
436
+ },
437
+ primaryKey: ["user_id", "version"]
438
+ },
439
+ backup_keys: {
440
+ fields: {
441
+ user_id: s,
442
+ version: n,
443
+ room_id: s,
444
+ session_id: s,
445
+ data: j
446
+ },
447
+ primaryKey: [
448
+ "user_id",
449
+ "version",
450
+ "room_id",
451
+ "session_id"
452
+ ]
453
+ },
454
+ remote_server_keys: {
455
+ fields: {
456
+ server_name: s,
457
+ key_id: s,
458
+ key: s,
459
+ valid_until_ts: n
460
+ },
461
+ primaryKey: ["server_name", "key_id"]
462
+ },
463
+ outliers: {
464
+ fields: {
465
+ event_id: s,
466
+ room_id: s,
467
+ json: j,
468
+ state_snapshot: nn,
469
+ rejected: sn,
470
+ soft_failed: b
471
+ },
472
+ primaryKey: ["event_id"]
473
+ },
474
+ forward_extremities: {
475
+ fields: {
476
+ room_id: s,
477
+ event_id: s
478
+ },
479
+ primaryKey: ["room_id", "event_id"]
480
+ },
481
+ federation_outbox: {
482
+ fields: {
483
+ id: n,
484
+ destination: s,
485
+ kind: s,
486
+ payload: j,
487
+ created_ts: n
488
+ },
489
+ primaryKey: ["id"],
490
+ indexes: [["destination"]]
491
+ },
492
+ destination_status: {
493
+ fields: {
494
+ destination: s,
495
+ failures: n,
496
+ retry_after_ts: n
497
+ },
498
+ primaryKey: ["destination"]
499
+ },
500
+ remote_devices: {
501
+ fields: {
502
+ user_id: s,
503
+ device_id: s,
504
+ keys: j,
505
+ display_name: sn,
506
+ stream_id: n
507
+ },
508
+ primaryKey: ["user_id", "device_id"]
509
+ },
510
+ remote_device_lists: {
511
+ fields: {
512
+ user_id: s,
513
+ stream_id: n,
514
+ stale: b
515
+ },
516
+ primaryKey: ["user_id"]
517
+ },
518
+ remote_media: {
519
+ fields: {
520
+ server_name: s,
521
+ media_id: s,
522
+ local_id: s,
523
+ content_type: sn,
524
+ filename: sn,
525
+ size: n,
526
+ fetched_ts: n
527
+ },
528
+ primaryKey: ["server_name", "media_id"]
529
+ },
530
+ delayed_events: {
531
+ fields: {
532
+ delay_id: s,
533
+ user_id: s,
534
+ device_id: s,
535
+ room_id: s,
536
+ event_type: s,
537
+ state_key: sn,
538
+ content: j,
539
+ delay_ms: n,
540
+ send_at: n,
541
+ running_since: n,
542
+ txn_key: sn
543
+ },
544
+ primaryKey: ["delay_id"],
545
+ indexes: [
546
+ ["user_id"],
547
+ ["send_at"],
548
+ ["room_id"]
549
+ ]
550
+ },
551
+ audit_log: {
552
+ fields: {
553
+ id: n,
554
+ ts: n,
555
+ action: s,
556
+ actor: sn,
557
+ target: sn,
558
+ ip: sn,
559
+ user_agent: sn,
560
+ outcome: s,
561
+ details: j
562
+ },
563
+ primaryKey: ["id"],
564
+ indexes: [
565
+ ["ts"],
566
+ ["actor"],
567
+ ["action"]
568
+ ]
569
+ },
570
+ threepid_sessions: {
571
+ fields: {
572
+ sid: s,
573
+ client_secret: s,
574
+ medium: s,
575
+ address: s,
576
+ token: s,
577
+ send_attempt: n,
578
+ next_link: sn,
579
+ created_ts: n,
580
+ validated_ts: nn
581
+ },
582
+ primaryKey: ["sid"],
583
+ indexes: [["client_secret"]]
584
+ },
585
+ user_threepids: {
586
+ fields: {
587
+ user_id: s,
588
+ medium: s,
589
+ address: s,
590
+ validated_ts: n,
591
+ added_ts: n
592
+ },
593
+ primaryKey: ["medium", "address"],
594
+ indexes: [["user_id"]]
595
+ },
596
+ /** Identity servers a user's 3PIDs were bound on through this server (to unbind them later). */
597
+ threepid_bindings: {
598
+ fields: {
599
+ user_id: s,
600
+ medium: s,
601
+ address: s,
602
+ id_server: s
603
+ },
604
+ primaryKey: [
605
+ "user_id",
606
+ "medium",
607
+ "address",
608
+ "id_server"
609
+ ]
610
+ },
611
+ user_reports: {
612
+ fields: {
613
+ id: n,
614
+ ts: n,
615
+ user_id: s,
616
+ reporter: s,
617
+ reason: s,
618
+ resolved: b
619
+ },
620
+ primaryKey: ["id"],
621
+ indexes: [["ts"]]
622
+ },
623
+ event_reports: {
624
+ fields: {
625
+ id: n,
626
+ ts: n,
627
+ room_id: s,
628
+ event_id: sn,
629
+ reporter: s,
630
+ reason: sn,
631
+ score: nn,
632
+ resolved: b
633
+ },
634
+ primaryKey: ["id"],
635
+ indexes: [["room_id"], ["ts"]]
636
+ },
637
+ server_settings: {
638
+ fields: {
639
+ key: s,
640
+ value: j
641
+ },
642
+ primaryKey: ["key"]
643
+ },
644
+ appservice_outbox: {
645
+ fields: {
646
+ id: n,
647
+ as_id: s,
648
+ kind: s,
649
+ payload: j,
650
+ created_ts: n
651
+ },
652
+ primaryKey: ["id"],
653
+ indexes: [["as_id"]]
654
+ },
655
+ server_keys: {
656
+ fields: {
657
+ key_id: s,
658
+ seed: s
659
+ },
660
+ primaryKey: ["key_id"]
661
+ }
662
+ };
663
+ //#endregion
664
+ export { schema };
@@ -0,0 +1,72 @@
1
+ import { DatabaseAdapter, Row } from "./types.js";
2
+ //#region src/storage/sql.d.ts
3
+ export type SqlDialect = "sqlite" | "postgres" | "mysql";
4
+ export interface SqlExecutor {
5
+ /** Run a query that returns rows. */
6
+ query(sql: string, params: unknown[]): Promise<Row[]>;
7
+ /** Run a statement; resolve with the number of affected rows. */
8
+ execute(sql: string, params: unknown[]): Promise<number>;
9
+ }
10
+ export interface SqlAdapterOptions {
11
+ dialect: SqlDialect;
12
+ executor: SqlExecutor;
13
+ /** Optional prefix for all table names. */
14
+ tablePrefix?: string;
15
+ /**
16
+ * Run `fn` inside a database transaction, passing an executor bound to it.
17
+ * Without this, the adapter does not support transactions.
18
+ */
19
+ transaction?<T>(fn: (executor: SqlExecutor) => Promise<T>): Promise<T>;
20
+ }
21
+ /**
22
+ * Generic SQL adapter. Works with any driver that can run parameterised
23
+ * queries; see `sqliteAdapter` and `postgresAdapter` for ready-made wrappers.
24
+ */
25
+ export declare function sqlAdapter({ dialect, executor: rootExecutor, tablePrefix, transaction }: SqlAdapterOptions): DatabaseAdapter;
26
+ /** Minimal structural type matching `node:sqlite` DatabaseSync and `better-sqlite3`. */
27
+ export interface SqliteDatabaseLike {
28
+ exec(sql: string): unknown;
29
+ prepare(sql: string): {
30
+ all(...params: any[]): unknown[];
31
+ run(...params: any[]): {
32
+ changes: number | bigint;
33
+ };
34
+ };
35
+ }
36
+ /** SQLite adapter for `node:sqlite` (`new DatabaseSync(path)`) or `better-sqlite3`. */
37
+ export declare function sqliteAdapter(db: SqliteDatabaseLike, options?: {
38
+ tablePrefix?: string;
39
+ }): DatabaseAdapter;
40
+ interface PgQueryable {
41
+ query(text: string, values?: unknown[]): Promise<{
42
+ rows: Row[];
43
+ rowCount: number | null;
44
+ }>;
45
+ }
46
+ /** Minimal structural type matching `pg.Pool` (or a single `pg.Client`). */
47
+ export interface PgPoolLike extends PgQueryable {
48
+ /** Present on pools; enables transactions on a dedicated connection. */
49
+ connect?(): Promise<PgQueryable & {
50
+ release(): void;
51
+ }>;
52
+ }
53
+ /** PostgreSQL adapter for `pg` (node-postgres). Pass a `Pool` to get transactions. */
54
+ export declare function postgresAdapter(pool: PgPoolLike, options?: {
55
+ tablePrefix?: string;
56
+ }): DatabaseAdapter;
57
+ interface MysqlQueryable {
58
+ query(sql: string, values?: unknown[]): Promise<[any, unknown]>;
59
+ }
60
+ /** Minimal structural type matching `mysql2/promise` pools. */
61
+ export interface MysqlPoolLike extends MysqlQueryable {
62
+ /** Present on pools; enables transactions on a dedicated connection. */
63
+ getConnection?(): Promise<MysqlQueryable & {
64
+ release(): void;
65
+ }>;
66
+ }
67
+ /** MySQL / MariaDB adapter for `mysql2/promise` pools. */
68
+ export declare function mysqlAdapter(pool: MysqlPoolLike, options?: {
69
+ tablePrefix?: string;
70
+ }): DatabaseAdapter;
71
+ //#endregion
72
+ export {};