@interncom/diplomatic 0.0.57 → 0.0.59

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.
@@ -1,14 +1,15 @@
1
1
  import { type DBSchema } from "idb";
2
2
  import type { Applier } from "./types";
3
- import { type GroupID } from "./shared/types";
3
+ import { type EntityID, type GroupID } from "./shared/types";
4
4
  import { StateManager } from "./state";
5
5
  export declare const entityTableName = "entities";
6
6
  export declare const typeIndexName = "entity_type_created_at";
7
7
  export declare const typeGroupIndexName = "entity_type_group_id";
8
+ export declare const typeParentIndexName = "entity_type_parent_id";
8
9
  export interface IEntity<T> {
9
- eid: Uint8Array;
10
+ eid: EntityID;
10
11
  gid?: GroupID;
11
- pid?: Uint8Array;
12
+ pid?: EntityID;
12
13
  type: string;
13
14
  updatedAt: Date;
14
15
  createdAt: Date;
@@ -19,8 +20,9 @@ interface IEntityDB extends DBSchema {
19
20
  key: Uint8Array;
20
21
  value: IEntity<unknown>;
21
22
  indexes: {
22
- "entity_type_created_at": [string, Date];
23
- "entity_type_group_id": [string, GroupID];
23
+ [typeIndexName]: [string, Date];
24
+ [typeGroupIndexName]: [string, GroupID];
25
+ [typeParentIndexName]: [string, EntityID];
24
26
  };
25
27
  };
26
28
  }
package/dist/index.mjs CHANGED
@@ -2846,17 +2846,6 @@ function openDB(name, version, { blocked, upgrade, blocking, terminated } = {})
2846
2846
  });
2847
2847
  return openPromise;
2848
2848
  }
2849
- function deleteDB(name, { blocked } = {}) {
2850
- const request = indexedDB.deleteDatabase(name);
2851
- if (blocked) {
2852
- request.addEventListener("blocked", (event) => blocked(
2853
- // Casting due to https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1405
2854
- event.oldVersion,
2855
- event
2856
- ));
2857
- }
2858
- return wrap(request).then(() => void 0);
2859
- }
2860
2849
  var readMethods = ["get", "getKey", "getAll", "getAllKeys", "count"];
2861
2850
  var writeMethods = ["put", "add", "delete", "clear"];
2862
2851
  var cachedMethods = /* @__PURE__ */ new Map();
@@ -2943,39 +2932,38 @@ replaceTraps((oldTraps) => ({
2943
2932
  }));
2944
2933
 
2945
2934
  // src/idbStore.ts
2946
- var initDB = () => {
2947
- return openDB("client-store-db", 6, {
2948
- upgrade(db3) {
2949
- if (!db3.objectStoreNames.contains("metaKV")) {
2950
- db3.createObjectStore("metaKV");
2951
- }
2952
- if (!db3.objectStoreNames.contains("ops")) {
2953
- db3.createObjectStore("ops", {
2954
- keyPath: "sha256"
2955
- });
2956
- }
2957
- if (!db3.objectStoreNames.contains("uploadQueue")) {
2958
- db3.createObjectStore("uploadQueue", {
2959
- keyPath: "sha256"
2960
- });
2961
- }
2962
- if (!db3.objectStoreNames.contains("downloadQueue")) {
2963
- db3.createObjectStore("downloadQueue", {
2964
- keyPath: "sha256"
2965
- });
2966
- }
2935
+ var db = await openDB("client-store-db", 6, {
2936
+ upgrade(db3) {
2937
+ if (!db3.objectStoreNames.contains("metaKV")) {
2938
+ db3.createObjectStore("metaKV");
2967
2939
  }
2968
- });
2969
- };
2970
- var db = await initDB();
2940
+ if (!db3.objectStoreNames.contains("ops")) {
2941
+ db3.createObjectStore("ops", {
2942
+ keyPath: "sha256"
2943
+ });
2944
+ }
2945
+ if (!db3.objectStoreNames.contains("uploadQueue")) {
2946
+ db3.createObjectStore("uploadQueue", {
2947
+ keyPath: "sha256"
2948
+ });
2949
+ }
2950
+ if (!db3.objectStoreNames.contains("downloadQueue")) {
2951
+ db3.createObjectStore("downloadQueue", {
2952
+ keyPath: "sha256"
2953
+ });
2954
+ }
2955
+ }
2956
+ });
2971
2957
  var IDBStore = class {
2972
2958
  seed;
2973
2959
  hostURL;
2974
2960
  hostID;
2975
2961
  lastFetchedAt;
2976
2962
  async wipe() {
2977
- await deleteDB("client-store-db");
2978
- db = await initDB();
2963
+ await db.clear("metaKV");
2964
+ await db.clear("uploadQueue");
2965
+ await db.clear("downloadQueue");
2966
+ await db.clear("ops");
2979
2967
  }
2980
2968
  async getSeed() {
2981
2969
  const hex = await db.get("metaKV", "seed");
@@ -11780,12 +11768,14 @@ __export(entityDB_exports, {
11780
11768
  entityTableName: () => entityTableName,
11781
11769
  stateManager: () => stateManager,
11782
11770
  typeGroupIndexName: () => typeGroupIndexName,
11783
- typeIndexName: () => typeIndexName
11771
+ typeIndexName: () => typeIndexName,
11772
+ typeParentIndexName: () => typeParentIndexName
11784
11773
  });
11785
11774
  var entityTableName = "entities";
11786
11775
  var typeIndexName = "entity_type_created_at";
11787
11776
  var typeGroupIndexName = "entity_type_group_id";
11788
- var db2 = await openDB("db", 7, {
11777
+ var typeParentIndexName = "entity_type_parent_id";
11778
+ var db2 = await openDB("db", 8, {
11789
11779
  upgrade(db3, prevVersion, currVersion, tx) {
11790
11780
  if (!db3.objectStoreNames.contains(entityTableName)) {
11791
11781
  const store2 = db3.createObjectStore(entityTableName, {
@@ -11804,6 +11794,11 @@ var db2 = await openDB("db", 7, {
11804
11794
  unique: false
11805
11795
  });
11806
11796
  }
11797
+ if (!store.indexNames.contains(typeParentIndexName)) {
11798
+ store.createIndex(typeGroupIndexName, ["type", "pid"], {
11799
+ unique: false
11800
+ });
11801
+ }
11807
11802
  }
11808
11803
  });
11809
11804
  var applier = async (op) => {
@@ -4,8 +4,9 @@ export declare enum Verb {
4
4
  }
5
5
  type Timestamp = string;
6
6
  export type GroupID = Uint8Array | string;
7
+ export type EntityID = Uint8Array;
7
8
  export interface IBaseOp {
8
- eid: Uint8Array;
9
+ eid: EntityID;
9
10
  gid?: GroupID;
10
11
  ts: Timestamp;
11
12
  type: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interncom/diplomatic",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "type": "module",
5
5
  "description": "Secure sync layer",
6
6
  "main": "dist/index.mjs",