@kubun/store-p2p 0.18.0 → 0.18.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.
package/lib/migrations.js CHANGED
@@ -76,6 +76,8 @@ import { sql } from 'kysely';
76
76
  'catalog_id',
77
77
  'group_id'
78
78
  ]).execute();
79
+ // Groups whose document data this device does not serve; absence means served.
80
+ await db.schema.createTable('kubun_p2p_unserved_groups').ifNotExists().addColumn('group_id', t.text, (col)=>col.notNull().primaryKey()).execute();
79
81
  // Document-sync progress with one peer in one group: the last resolved
80
82
  // document key, whether the current cycle's examined ranges were all clear,
81
83
  // the hash of the accepted rule set without absolute bounds, and the
@@ -293,6 +295,7 @@ import { sql } from 'kysely';
293
295
  await db.schema.dropTable('kubun_p2p_document_repairs').ifExists().execute();
294
296
  await db.schema.dropTable('kubun_p2p_catalog_cursors').ifExists().execute();
295
297
  await db.schema.dropTable('kubun_p2p_catalog_routes').ifExists().execute();
298
+ await db.schema.dropTable('kubun_p2p_unserved_groups').ifExists().execute();
296
299
  await db.schema.dropTable('kubun_p2p_catalog_offers').ifExists().execute();
297
300
  await db.schema.dropTable('kubun_p2p_pending_join_requests').ifExists().execute();
298
301
  await db.schema.dropTable('kubun_p2p_local_peer_profile').ifExists().execute();
@@ -13,5 +13,13 @@ export type CatalogRouteOps = {
13
13
  allCatalogRoutes(groupID?: string): Promise<Array<CatalogRoute>>;
14
14
  deleteCatalogRoutes(owner: string, catalogID: string): Promise<void>;
15
15
  deleteGroupCatalogRoutes(groupID: string): Promise<void>;
16
+ /** Whether this device serves the group's document data; true unless turned off. */
17
+ getGroupServing(params: {
18
+ groupID: string;
19
+ }): Promise<boolean>;
20
+ setGroupServing(params: {
21
+ groupID: string;
22
+ enabled: boolean;
23
+ }): Promise<void>;
16
24
  };
17
25
  export declare function createCatalogRouteOps(db: Kysely<P2PStoreTables>): CatalogRouteOps;
@@ -27,6 +27,19 @@ export function createCatalogRouteOps(db) {
27
27
  push: Number(push)
28
28
  })).execute();
29
29
  },
30
+ async getGroupServing ({ groupID }) {
31
+ const row = await db.selectFrom('kubun_p2p_unserved_groups').select('group_id').where('group_id', '=', groupID).executeTakeFirst();
32
+ return row == null;
33
+ },
34
+ async setGroupServing ({ groupID, enabled }) {
35
+ if (enabled) {
36
+ await db.deleteFrom('kubun_p2p_unserved_groups').where('group_id', '=', groupID).execute();
37
+ return;
38
+ }
39
+ await db.insertInto('kubun_p2p_unserved_groups').values({
40
+ group_id: groupID
41
+ }).onConflict((oc)=>oc.column('group_id').doNothing()).execute();
42
+ },
30
43
  async catalogRoutes (owner, catalogID) {
31
44
  const rows = await db.selectFrom('kubun_p2p_catalog_routes').selectAll().where('owner', '=', owner).where('catalog_id', '=', catalogID).orderBy('group_id').execute();
32
45
  return rows.map(project);
package/lib/tables.d.ts CHANGED
@@ -74,6 +74,10 @@ export type CatalogRouteTable = {
74
74
  pull: number;
75
75
  push: number;
76
76
  };
77
+ /** A group this device has stopped serving document data for; absence means served. */
78
+ export type UnservedGroupTable = {
79
+ group_id: string;
80
+ };
77
81
  export type CatalogCursorTable = {
78
82
  peer_did: string;
79
83
  group_id: string;
@@ -398,6 +402,7 @@ export type P2PStoreTables = {
398
402
  kubun_p2p_group_members: GroupMemberTable;
399
403
  kubun_p2p_catalog_offers: CatalogOfferTable;
400
404
  kubun_p2p_catalog_routes: CatalogRouteTable;
405
+ kubun_p2p_unserved_groups: UnservedGroupTable;
401
406
  kubun_p2p_catalog_cursors: CatalogCursorTable;
402
407
  kubun_p2p_document_repairs: DocumentRepairTable;
403
408
  kubun_p2p_document_repair_answers: DocumentRepairAnswerTable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/store-p2p",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,