@may-db/core 0.1.1 → 0.1.3

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 (85) hide show
  1. package/README.md +117 -5
  2. package/dist/IndexRuntime.d.ts +60 -0
  3. package/dist/IndexRuntime.d.ts.map +1 -0
  4. package/dist/IndexRuntime.js +340 -0
  5. package/dist/IndexRuntime.js.map +1 -0
  6. package/dist/MayDb.d.ts +26 -7
  7. package/dist/MayDb.d.ts.map +1 -1
  8. package/dist/MayDb.js +197 -54
  9. package/dist/MayDb.js.map +1 -1
  10. package/dist/Room.d.ts +32 -0
  11. package/dist/Room.d.ts.map +1 -1
  12. package/dist/Room.js +35 -0
  13. package/dist/Room.js.map +1 -1
  14. package/dist/RuntimeIndexHandle.d.ts +29 -0
  15. package/dist/RuntimeIndexHandle.d.ts.map +1 -0
  16. package/dist/RuntimeIndexHandle.js +48 -0
  17. package/dist/RuntimeIndexHandle.js.map +1 -0
  18. package/dist/errors.d.ts +12 -0
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/errors.js +15 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +1 -0
  25. package/dist/index.js.map +1 -1
  26. package/dist/indexing/collaborativeSync.d.ts +25 -0
  27. package/dist/indexing/collaborativeSync.d.ts.map +1 -0
  28. package/dist/indexing/collaborativeSync.js +56 -0
  29. package/dist/indexing/collaborativeSync.js.map +1 -0
  30. package/dist/indexing/descriptor.d.ts +6 -0
  31. package/dist/indexing/descriptor.d.ts.map +1 -0
  32. package/dist/indexing/descriptor.js +2 -0
  33. package/dist/indexing/descriptor.js.map +1 -0
  34. package/dist/indexing/errors.d.ts +9 -0
  35. package/dist/indexing/errors.d.ts.map +1 -0
  36. package/dist/indexing/errors.js +11 -0
  37. package/dist/indexing/errors.js.map +1 -0
  38. package/dist/indexing/handle.d.ts +29 -0
  39. package/dist/indexing/handle.d.ts.map +1 -0
  40. package/dist/indexing/handle.js +48 -0
  41. package/dist/indexing/handle.js.map +1 -0
  42. package/dist/indexing/indexRoomStore.d.ts +18 -0
  43. package/dist/indexing/indexRoomStore.d.ts.map +1 -0
  44. package/dist/indexing/indexRoomStore.js +71 -0
  45. package/dist/indexing/indexRoomStore.js.map +1 -0
  46. package/dist/indexing/roomRegistry.d.ts +26 -0
  47. package/dist/indexing/roomRegistry.d.ts.map +1 -0
  48. package/dist/indexing/roomRegistry.js +125 -0
  49. package/dist/indexing/roomRegistry.js.map +1 -0
  50. package/dist/indexing/rows.d.ts +8 -0
  51. package/dist/indexing/rows.d.ts.map +1 -0
  52. package/dist/indexing/rows.js +86 -0
  53. package/dist/indexing/rows.js.map +1 -0
  54. package/dist/indexing/runtime.d.ts +61 -0
  55. package/dist/indexing/runtime.d.ts.map +1 -0
  56. package/dist/indexing/runtime.js +376 -0
  57. package/dist/indexing/runtime.js.map +1 -0
  58. package/dist/indexing.d.ts +93 -0
  59. package/dist/indexing.d.ts.map +1 -0
  60. package/dist/indexing.js +394 -0
  61. package/dist/indexing.js.map +1 -0
  62. package/dist/indexingErrors.d.ts +9 -0
  63. package/dist/indexingErrors.d.ts.map +1 -0
  64. package/dist/indexingErrors.js +11 -0
  65. package/dist/indexingErrors.js.map +1 -0
  66. package/dist/indexingRoomStore.d.ts +26 -0
  67. package/dist/indexingRoomStore.d.ts.map +1 -0
  68. package/dist/indexingRoomStore.js +125 -0
  69. package/dist/indexingRoomStore.js.map +1 -0
  70. package/dist/indexingRows.d.ts +8 -0
  71. package/dist/indexingRows.d.ts.map +1 -0
  72. package/dist/indexingRows.js +114 -0
  73. package/dist/indexingRows.js.map +1 -0
  74. package/dist/indexingTypes.d.ts +9 -0
  75. package/dist/indexingTypes.d.ts.map +1 -0
  76. package/dist/indexingTypes.js +2 -0
  77. package/dist/indexingTypes.js.map +1 -0
  78. package/dist/roomMetadata.d.ts +3 -0
  79. package/dist/roomMetadata.d.ts.map +1 -0
  80. package/dist/roomMetadata.js +3 -0
  81. package/dist/roomMetadata.js.map +1 -0
  82. package/dist/types.d.ts +56 -7
  83. package/dist/types.d.ts.map +1 -1
  84. package/package.json +6 -5
  85. package/patches/matrix-crdt+0.2.1-alpha.1.patch +108 -0
@@ -0,0 +1,12 @@
1
+ import type { RoomSource } from "./types";
2
+ export declare class RoomIndexWriteError extends Error {
3
+ readonly roomId: string;
4
+ readonly source: RoomSource;
5
+ readonly cause: unknown;
6
+ constructor(options: {
7
+ roomId: string;
8
+ source: RoomSource;
9
+ cause: unknown;
10
+ });
11
+ }
12
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBAEZ,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,UAAU,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE;CAW5E"}
package/dist/errors.js ADDED
@@ -0,0 +1,15 @@
1
+ export class RoomIndexWriteError extends Error {
2
+ roomId;
3
+ source;
4
+ cause;
5
+ constructor(options) {
6
+ const { roomId, source, cause } = options;
7
+ const detail = cause instanceof Error ? cause.message : String(cause);
8
+ super(`Failed to persist room ${roomId} in SDK index during ${source}: ${detail}`);
9
+ this.name = "RoomIndexWriteError";
10
+ this.roomId = roomId;
11
+ this.source = source;
12
+ this.cause = cause;
13
+ }
14
+ }
15
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IACnC,MAAM,CAAS;IACf,MAAM,CAAa;IACnB,KAAK,CAAU;IAExB,YAAY,OAA+D;QACzE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC1C,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtE,KAAK,CACH,0BAA0B,MAAM,wBAAwB,MAAM,KAAK,MAAM,EAAE,CAC5E,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { MayDb } from "./MayDb";
2
+ export { IndexCapacityError } from "./indexing/errors";
2
3
  export { Room, type RoomDelegate } from "./Room";
3
4
  export { Auth, startSsoLogin, completeSsoLogin, } from "./loginFlow";
4
5
  export { getStoredSession, saveStoredSession, clearStoredSession, getStoredHomeserver, saveStoredHomeserver, clearStoredHomeserver, } from "./authStorage";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,EACjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { MayDb } from "./MayDb";
2
+ export { IndexCapacityError } from "./indexing/errors";
2
3
  export { Room } from "./Room";
3
4
  export { Auth, startSsoLogin, completeSsoLogin, } from "./loginFlow";
4
5
  export { getStoredSession, saveStoredSession, clearStoredSession, getStoredHomeserver, saveStoredHomeserver, clearStoredHomeserver, } from "./authStorage";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,IAAI,EAAqB,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,GAKlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAqB,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,IAAI,EACJ,aAAa,EACb,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAC5B,iBAAiB,GAKlB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,SAAS,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Room } from "../Room";
2
+ import type { MayDbIndexDefinition } from "../types";
3
+ import type { RoomDescriptor } from "./descriptor";
4
+ import type { RuntimeIndexHandle } from "./handle";
5
+ type IndexOps = {
6
+ getOrCreateHandle(indexName: string, indexRoomId: string): RuntimeIndexHandle;
7
+ upsertRoomToIndex(handle: RuntimeIndexHandle, descriptor: RoomDescriptor, room: Room): Promise<void>;
8
+ removeRoomFromIndex(handle: RuntimeIndexHandle, roomId: string): Promise<void>;
9
+ };
10
+ export declare class CollaborativeIndexSync {
11
+ private readonly memberships;
12
+ private readonly ops;
13
+ constructor(ops: IndexOps);
14
+ clear(): void;
15
+ sync(options: {
16
+ indexName: string;
17
+ definition: MayDbIndexDefinition;
18
+ roomDescriptor: RoomDescriptor;
19
+ sourceRoom: Room;
20
+ }): Promise<void>;
21
+ private resolveIndexRoomIds;
22
+ private reconcile;
23
+ }
24
+ export {};
25
+ //# sourceMappingURL=collaborativeSync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collaborativeSync.d.ts","sourceRoot":"","sources":["../../src/indexing/collaborativeSync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,KAAK,QAAQ,GAAG;IACd,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,kBAAkB,CAAC;IAC9E,iBAAiB,CACf,MAAM,EAAE,kBAAkB,EAC1B,UAAU,EAAE,cAAc,EAC1B,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChF,CAAC;AAEF,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAkC;IAC9D,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAW;gBAEnB,GAAG,EAAE,QAAQ;IAIzB,KAAK,IAAI,IAAI;IAIP,IAAI,CAAC,OAAO,EAAE;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,oBAAoB,CAAC;QACjC,cAAc,EAAE,cAAc,CAAC;QAC/B,UAAU,EAAE,IAAI,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjB,OAAO,CAAC,mBAAmB;YAsBb,SAAS;CA2BxB"}
@@ -0,0 +1,56 @@
1
+ export class CollaborativeIndexSync {
2
+ memberships = new Map();
3
+ ops;
4
+ constructor(ops) {
5
+ this.ops = ops;
6
+ }
7
+ clear() {
8
+ this.memberships.clear();
9
+ }
10
+ async sync(options) {
11
+ const { indexName, definition, roomDescriptor, sourceRoom } = options;
12
+ const indexRoomIds = this.resolveIndexRoomIds(definition, roomDescriptor, sourceRoom);
13
+ await this.reconcile(indexName, roomDescriptor, sourceRoom, indexRoomIds);
14
+ }
15
+ resolveIndexRoomIds(definition, roomDescriptor, sourceRoom) {
16
+ const resolved = definition.resolveIndexRoomIds?.({
17
+ roomId: roomDescriptor.roomId,
18
+ roomName: roomDescriptor.roomName,
19
+ roomType: roomDescriptor.roomType,
20
+ doc: sourceRoom.doc,
21
+ });
22
+ const values = Array.isArray(resolved) ? resolved : [resolved];
23
+ const roomIds = new Set();
24
+ for (const value of values) {
25
+ if (typeof value !== "string")
26
+ continue;
27
+ const roomId = value.trim();
28
+ if (!roomId)
29
+ continue;
30
+ roomIds.add(roomId);
31
+ }
32
+ return [...roomIds];
33
+ }
34
+ async reconcile(indexName, roomDescriptor, sourceRoom, indexRoomIds) {
35
+ const key = `${indexName}::${roomDescriptor.roomId}`;
36
+ const previous = this.memberships.get(key) ?? new Set();
37
+ const next = new Set(indexRoomIds);
38
+ for (const indexRoomId of previous) {
39
+ if (next.has(indexRoomId))
40
+ continue;
41
+ const handle = this.ops.getOrCreateHandle(indexName, indexRoomId);
42
+ await this.ops.removeRoomFromIndex(handle, roomDescriptor.roomId);
43
+ }
44
+ for (const indexRoomId of next) {
45
+ const handle = this.ops.getOrCreateHandle(indexName, indexRoomId);
46
+ await this.ops.upsertRoomToIndex(handle, roomDescriptor, sourceRoom);
47
+ }
48
+ if (next.size === 0) {
49
+ this.memberships.delete(key);
50
+ }
51
+ else {
52
+ this.memberships.set(key, next);
53
+ }
54
+ }
55
+ }
56
+ //# sourceMappingURL=collaborativeSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collaborativeSync.js","sourceRoot":"","sources":["../../src/indexing/collaborativeSync.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,sBAAsB;IAChB,WAAW,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC7C,GAAG,CAAW;IAE/B,YAAY,GAAa;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAKV;QACC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QACtE,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,CAC3C,UAAU,EACV,cAAc,EACd,UAAU,CACX,CAAC;QACF,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,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AAM,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAClE,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,CAAC;QACpE,CAAC;QAED,KAAK,MAAM,WAAW,IAAI,IAAI,EAAE,CAAC;YAC/B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;YAClE,MAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export type RoomDescriptor = {
2
+ roomId: string;
3
+ roomName: string;
4
+ roomType: string;
5
+ };
6
+ //# sourceMappingURL=descriptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../../src/indexing/descriptor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=descriptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../../src/indexing/descriptor.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export declare class IndexCapacityError extends Error {
2
+ readonly indexName: string;
3
+ readonly indexRoomId: string | null;
4
+ constructor(options: {
5
+ indexName: string;
6
+ indexRoomId: string | null;
7
+ });
8
+ }
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/indexing/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;gBAExB,OAAO,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE;CAMvE"}
@@ -0,0 +1,11 @@
1
+ export class IndexCapacityError extends Error {
2
+ indexName;
3
+ indexRoomId;
4
+ constructor(options) {
5
+ super(`Index "${options.indexName}" has reached capacity`);
6
+ this.name = "IndexCapacityError";
7
+ this.indexName = options.indexName;
8
+ this.indexRoomId = options.indexRoomId;
9
+ }
10
+ }
11
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/indexing/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,SAAS,CAAS;IAClB,WAAW,CAAgB;IAEpC,YAAY,OAA0D;QACpE,KAAK,CAAC,UAAU,OAAO,CAAC,SAAS,wBAAwB,CAAC,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import * as Y from "yjs";
2
+ import type { IndexRuntime } from "./runtime";
3
+ import type { Room } from "../Room";
4
+ import type { MayDbIndexDefinition, MayDbIndexHandle, MayDbIndexQueryPageOptions, MayDbIndexQueryPageResult } from "../types";
5
+ export declare class RuntimeIndexHandle implements MayDbIndexHandle {
6
+ readonly indexName: string;
7
+ readonly indexRoomId: string | null;
8
+ readonly definition: MayDbIndexDefinition;
9
+ activeCount: number;
10
+ paused: boolean;
11
+ indexRoom: Room | null;
12
+ rowsMap: Y.Map<string> | null;
13
+ roomObserverCleanup: (() => void) | null;
14
+ readyPromise: Promise<void> | null;
15
+ private readonly runtime;
16
+ private readonly listeners;
17
+ constructor(options: {
18
+ runtime: IndexRuntime;
19
+ indexName: string;
20
+ indexRoomId: string | null;
21
+ definition: MayDbIndexDefinition;
22
+ });
23
+ activate(): () => void;
24
+ ensureReady(): Promise<void>;
25
+ queryPage(options: MayDbIndexQueryPageOptions): Promise<MayDbIndexQueryPageResult>;
26
+ subscribe(listener: () => void): () => void;
27
+ notifyChange(): void;
28
+ }
29
+ //# sourceMappingURL=handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/indexing/handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAChB,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAElB,qBAAa,kBAAmB,YAAW,gBAAgB;IACzD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,UAAU,EAAE,oBAAoB,CAAC;IAC1C,WAAW,SAAK;IAChB,MAAM,UAAS;IAEf,SAAS,EAAE,IAAI,GAAG,IAAI,CAAQ;IAC9B,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAAQ;IACrC,mBAAmB,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IAChD,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAQ;IAE1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;gBAEvC,OAAO,EAAE;QACnB,OAAO,EAAE,YAAY,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,UAAU,EAAE,oBAAoB,CAAC;KAClC;IAOD,QAAQ,IAAI,MAAM,IAAI;IAahB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,SAAS,CACb,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,yBAAyB,CAAC;IAIrC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAK3C,YAAY,IAAI,IAAI;CAKrB"}
@@ -0,0 +1,48 @@
1
+ import * as Y from "yjs";
2
+ export class RuntimeIndexHandle {
3
+ indexName;
4
+ indexRoomId;
5
+ definition;
6
+ activeCount = 0;
7
+ paused = false;
8
+ indexRoom = null;
9
+ rowsMap = null;
10
+ roomObserverCleanup = null;
11
+ readyPromise = null;
12
+ runtime;
13
+ listeners = new Set();
14
+ constructor(options) {
15
+ this.runtime = options.runtime;
16
+ this.indexName = options.indexName;
17
+ this.indexRoomId = options.indexRoomId;
18
+ this.definition = options.definition;
19
+ }
20
+ activate() {
21
+ this.activeCount += 1;
22
+ this.runtime.onHandleActivated(this);
23
+ let disposed = false;
24
+ return () => {
25
+ if (disposed)
26
+ return;
27
+ disposed = true;
28
+ this.activeCount = Math.max(0, this.activeCount - 1);
29
+ this.runtime.onHandleDeactivated(this);
30
+ };
31
+ }
32
+ async ensureReady() {
33
+ await this.runtime.ensureHandleReady(this);
34
+ }
35
+ async queryPage(options) {
36
+ return this.runtime.queryHandlePage(this, options);
37
+ }
38
+ subscribe(listener) {
39
+ this.listeners.add(listener);
40
+ return () => this.listeners.delete(listener);
41
+ }
42
+ notifyChange() {
43
+ for (const listener of this.listeners) {
44
+ listener();
45
+ }
46
+ }
47
+ }
48
+ //# sourceMappingURL=handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.js","sourceRoot":"","sources":["../../src/indexing/handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAUzB,MAAM,OAAO,kBAAkB;IACpB,SAAS,CAAS;IAClB,WAAW,CAAgB;IAC3B,UAAU,CAAuB;IAC1C,WAAW,GAAG,CAAC,CAAC;IAChB,MAAM,GAAG,KAAK,CAAC;IAEf,SAAS,GAAgB,IAAI,CAAC;IAC9B,OAAO,GAAyB,IAAI,CAAC;IACrC,mBAAmB,GAAwB,IAAI,CAAC;IAChD,YAAY,GAAyB,IAAI,CAAC;IAEzB,OAAO,CAAe;IACtB,SAAS,GAAG,IAAI,GAAG,EAAc,CAAC;IAEnD,YAAY,OAKX;QACC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACvC,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAErC,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,OAAO,GAAG,EAAE;YACV,IAAI,QAAQ;gBAAE,OAAO;YACrB,QAAQ,GAAG,IAAI,CAAC;YAChB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;YACrD,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACzC,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,WAAW;QACf,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK,CAAC,SAAS,CACb,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;IAED,SAAS,CAAC,QAAoB;QAC5B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED,YAAY;QACV,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ import type { MatrixClient, MayDbIndexScope } from "../types";
2
+ export declare class IndexRoomStore {
3
+ private readonly namespace;
4
+ private readonly matrixClient;
5
+ constructor(options: {
6
+ namespace: string;
7
+ matrixClient: MatrixClient;
8
+ });
9
+ resolveOrCreatePrivateIndexRoomId(indexName: string): Promise<string>;
10
+ ensureJoined(roomId: string): Promise<void>;
11
+ private getAccountDataMapping;
12
+ createIndexMatrixRoom(options: {
13
+ indexName: string;
14
+ scope: MayDbIndexScope;
15
+ }): Promise<string>;
16
+ private privateIndexAccountDataType;
17
+ }
18
+ //# sourceMappingURL=indexRoomStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexRoomStore.d.ts","sourceRoot":"","sources":["../../src/indexing/indexRoomStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE9D,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,OAAO,EAAE;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,YAAY,CAAC;KAC5B;IAKK,iCAAiC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBrE,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAKnC,qBAAqB;IAc7B,qBAAqB,CAAC,OAAO,EAAE;QACnC,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,eAAe,CAAC;KACxB,GAAG,OAAO,CAAC,MAAM,CAAC;IA4BnB,OAAO,CAAC,2BAA2B;CAGpC"}
@@ -0,0 +1,71 @@
1
+ import * as sdk from "matrix-js-sdk";
2
+ export class IndexRoomStore {
3
+ namespace;
4
+ matrixClient;
5
+ constructor(options) {
6
+ this.namespace = options.namespace;
7
+ this.matrixClient = options.matrixClient;
8
+ }
9
+ async resolveOrCreatePrivateIndexRoomId(indexName) {
10
+ const eventType = this.privateIndexAccountDataType();
11
+ let mapping = await this.getAccountDataMapping(eventType);
12
+ const existing = mapping[indexName];
13
+ if (typeof existing === "string") {
14
+ return existing;
15
+ }
16
+ const roomId = await this.createIndexMatrixRoom({
17
+ indexName,
18
+ scope: "private",
19
+ });
20
+ mapping = { ...mapping, [indexName]: roomId };
21
+ await this.matrixClient.setAccountData(eventType, mapping);
22
+ return roomId;
23
+ }
24
+ async ensureJoined(roomId) {
25
+ if (this.matrixClient.getRoom(roomId))
26
+ return;
27
+ await this.matrixClient.joinRoom(roomId);
28
+ }
29
+ async getAccountDataMapping(eventType) {
30
+ try {
31
+ const data = await this.matrixClient.getAccountDataFromServer(eventType);
32
+ if (!data || typeof data !== "object")
33
+ return {};
34
+ return data;
35
+ }
36
+ catch {
37
+ return {};
38
+ }
39
+ }
40
+ async createIndexMatrixRoom(options) {
41
+ const timestamp = Date.now();
42
+ const randomSuffix = Math.random().toString(36).substring(2, 8);
43
+ const localAlias = `${this.namespace}-index-${timestamp}-${randomSuffix}`;
44
+ const response = await this.matrixClient.createRoom({
45
+ name: `Index: ${options.indexName}`,
46
+ room_alias_name: localAlias,
47
+ visibility: sdk.Visibility.Private,
48
+ preset: sdk.Preset.PrivateChat,
49
+ initial_state: [
50
+ {
51
+ type: "m.room.history_visibility",
52
+ content: { history_visibility: "shared" },
53
+ },
54
+ {
55
+ type: this.namespace,
56
+ state_key: "",
57
+ content: {
58
+ version: 1,
59
+ indexName: options.indexName,
60
+ indexScope: options.scope,
61
+ },
62
+ },
63
+ ],
64
+ });
65
+ return response.room_id;
66
+ }
67
+ privateIndexAccountDataType() {
68
+ return `${this.namespace}.private_indexes`;
69
+ }
70
+ }
71
+ //# sourceMappingURL=indexRoomStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexRoomStore.js","sourceRoot":"","sources":["../../src/indexing/indexRoomStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAGrC,MAAM,OAAO,cAAc;IACR,SAAS,CAAS;IAClB,YAAY,CAAe;IAE5C,YAAY,OAGX;QACC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,iCAAiC,CAAC,SAAiB;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACrD,IAAI,OAAO,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;QAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACjC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,MAAM,MAAM,GAAG,MAA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EAAE,UAAU;YAC3B,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,OAAO;YAClC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,WAAW;YAC9B,aAAa,EAAE;gBACb;oBACE,IAAI,EAAE,2BAA2B;oBACjC,OAAO,EAAE,EAAE,kBAAkB,EAAE,QAAQ,EAAE;iBAC1C;gBACD;oBACE,IAAI,EAAE,IAAI,CAAC,SAAS;oBACpB,SAAS,EAAE,EAAE;oBACb,OAAO,EAAE;wBACP,OAAO,EAAE,CAAC;wBACV,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,UAAU,EAAE,OAAO,CAAC,KAAK;qBAC1B;iBACF;aACF;SACF,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC1B,CAAC;IAEO,2BAA2B;QACjC,OAAO,GAAG,IAAI,CAAC,SAAS,kBAAkB,CAAC;IAC7C,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import { Room } from "../Room";
2
+ import type { MatrixClient, MayDbIndexScope } from "../types";
3
+ export declare class IndexRoomStore {
4
+ private readonly namespace;
5
+ private readonly matrixClient;
6
+ private readonly openRoom;
7
+ constructor(options: {
8
+ namespace: string;
9
+ matrixClient: MatrixClient;
10
+ openRoom: (roomId: string) => Room;
11
+ });
12
+ resolveIndexRoomId(options: {
13
+ indexName: string;
14
+ scope: MayDbIndexScope;
15
+ ownerRoomId: string | null;
16
+ }): Promise<string>;
17
+ private resolvePrivateIndexRoomId;
18
+ private resolveCollaborativeIndexRoomId;
19
+ private ensureJoined;
20
+ private getAccountDataMapping;
21
+ private getOwnerRoomIndexMapping;
22
+ private createIndexMatrixRoom;
23
+ private privateIndexAccountDataType;
24
+ private ownerIndexMappingStateType;
25
+ }
26
+ //# sourceMappingURL=roomRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roomRegistry.d.ts","sourceRoot":"","sources":["../../src/indexing/roomRegistry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE9D,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2B;gBAExC,OAAO,EAAE;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,YAAY,CAAC;QAC3B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;KACpC;IAMK,kBAAkB,CAAC,OAAO,EAAE;QAChC,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,eAAe,CAAC;QACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;KAC5B,GAAG,OAAO,CAAC,MAAM,CAAC;YAOL,yBAAyB;YAoBzB,+BAA+B;YA4C/B,YAAY;YAKZ,qBAAqB;YAcrB,wBAAwB;YAiBxB,qBAAqB;IAgCnC,OAAO,CAAC,2BAA2B;IAInC,OAAO,CAAC,0BAA0B;CAGnC"}
@@ -0,0 +1,125 @@
1
+ import * as sdk from "matrix-js-sdk";
2
+ import { Room } from "../Room";
3
+ export class IndexRoomStore {
4
+ namespace;
5
+ matrixClient;
6
+ openRoom;
7
+ constructor(options) {
8
+ this.namespace = options.namespace;
9
+ this.matrixClient = options.matrixClient;
10
+ this.openRoom = options.openRoom;
11
+ }
12
+ async resolveIndexRoomId(options) {
13
+ if (options.scope === "private") {
14
+ return this.resolvePrivateIndexRoomId(options.indexName);
15
+ }
16
+ return this.resolveCollaborativeIndexRoomId(options.indexName, options.ownerRoomId);
17
+ }
18
+ async resolvePrivateIndexRoomId(indexName) {
19
+ const eventType = this.privateIndexAccountDataType();
20
+ let mapping = await this.getAccountDataMapping(eventType);
21
+ const existing = mapping[indexName];
22
+ if (typeof existing === "string") {
23
+ return existing;
24
+ }
25
+ const roomId = await this.createIndexMatrixRoom({
26
+ indexName,
27
+ scope: "private",
28
+ });
29
+ mapping = { ...mapping, [indexName]: roomId };
30
+ await this.matrixClient.setAccountData(eventType, mapping);
31
+ return roomId;
32
+ }
33
+ async resolveCollaborativeIndexRoomId(indexName, ownerRoomId) {
34
+ if (!ownerRoomId) {
35
+ throw new Error(`Collaborative index "${indexName}" missing ownerRoomId`);
36
+ }
37
+ let mapping = await this.getOwnerRoomIndexMapping(ownerRoomId);
38
+ const existing = mapping[indexName];
39
+ if (typeof existing === "string") {
40
+ await this.ensureJoined(existing);
41
+ return existing;
42
+ }
43
+ const ownerRoom = this.openRoom(ownerRoomId);
44
+ await ownerRoom.ensureJoined();
45
+ await ownerRoom.connect();
46
+ if (!ownerRoom.canEdit) {
47
+ throw new Error(`Cannot create index "${indexName}" without owner room write access`);
48
+ }
49
+ const roomId = await this.createIndexMatrixRoom({
50
+ indexName,
51
+ scope: "collaborative",
52
+ });
53
+ const indexRoom = this.openRoom(roomId);
54
+ await indexRoom.ensureJoined();
55
+ await indexRoom.connect();
56
+ await indexRoom.delegates.add(ownerRoomId);
57
+ mapping = { ...mapping, [indexName]: roomId };
58
+ await this.matrixClient.sendStateEvent(ownerRoomId, this.ownerIndexMappingStateType(), mapping, "");
59
+ return roomId;
60
+ }
61
+ async ensureJoined(roomId) {
62
+ if (this.matrixClient.getRoom(roomId))
63
+ return;
64
+ await this.matrixClient.joinRoom(roomId);
65
+ }
66
+ async getAccountDataMapping(eventType) {
67
+ try {
68
+ const data = await this.matrixClient.getAccountDataFromServer(eventType);
69
+ if (!data || typeof data !== "object")
70
+ return {};
71
+ return data;
72
+ }
73
+ catch {
74
+ return {};
75
+ }
76
+ }
77
+ async getOwnerRoomIndexMapping(ownerRoomId) {
78
+ try {
79
+ const state = await this.matrixClient.roomState(ownerRoomId);
80
+ const event = state.find((entry) => entry.type === this.ownerIndexMappingStateType() &&
81
+ entry.state_key === "");
82
+ if (!event || typeof event.content !== "object")
83
+ return {};
84
+ return event.content;
85
+ }
86
+ catch {
87
+ return {};
88
+ }
89
+ }
90
+ async createIndexMatrixRoom(options) {
91
+ const timestamp = Date.now();
92
+ const randomSuffix = Math.random().toString(36).substring(2, 8);
93
+ const localAlias = `${this.namespace}-index-${timestamp}-${randomSuffix}`;
94
+ const response = await this.matrixClient.createRoom({
95
+ name: `Index: ${options.indexName}`,
96
+ room_alias_name: localAlias,
97
+ visibility: sdk.Visibility.Private,
98
+ preset: sdk.Preset.PrivateChat,
99
+ initial_state: [
100
+ {
101
+ type: "m.room.history_visibility",
102
+ content: { history_visibility: "shared" },
103
+ },
104
+ {
105
+ type: this.namespace,
106
+ state_key: "",
107
+ content: {
108
+ version: 1,
109
+ roomType: "__index__",
110
+ indexName: options.indexName,
111
+ indexScope: options.scope,
112
+ },
113
+ },
114
+ ],
115
+ });
116
+ return response.room_id;
117
+ }
118
+ privateIndexAccountDataType() {
119
+ return `${this.namespace}.private_indexes`;
120
+ }
121
+ ownerIndexMappingStateType() {
122
+ return `${this.namespace}.index_rooms`;
123
+ }
124
+ }
125
+ //# sourceMappingURL=roomRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roomRegistry.js","sourceRoot":"","sources":["../../src/indexing/roomRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG/B,MAAM,OAAO,cAAc;IACR,SAAS,CAAS;IAClB,YAAY,CAAe;IAC3B,QAAQ,CAA2B;IAEpD,YAAY,OAIX;QACC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,OAIxB;QACC,IAAI,OAAO,CAAC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G,CAAC,MAAM,CAAC,WAAW;YAC9B,aAAa,EAAE;gBACb;oBACE,IAAI,EAAE,2BAA2B;oBACjC,OAAO,EAAE,EAAE,kBAAkB,EAAE,QAAQ,EAAE;iBAC1C;gBACD;oBACE,IAAI,EAAE,IAAI,CAAC,SAAS;oBACpB,SAAS,EAAE,EAAE;oBACb,OAAO,EAAE;wBACP,OAAO,EAAE,CAAC;wBACV,QAAQ,EAAE,WAAW;wBACrB,SAAS,EAAE,OAAO,CAAC,SAAS;wBAC5B,UAAU,EAAE,OAAO,CAAC,KAAK;qBAC1B;iBACF;aACF;SACF,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC1B,CAAC;IAEO,2BAA2B;QACjC,OAAO,GAAG,IAAI,CAAC,SAAS,kBAAkB,CAAC;IAC7C,CAAC;IAEO,0BAA0B;QAChC,OAAO,GAAG,IAAI,CAAC,SAAS,cAAc,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ import * as Y from "yjs";
2
+ import type { RoomDescriptor } from "./descriptor";
3
+ import type { MayDbIndexDefinition, MayDbIndexItem, MayDbIndexOrderBy, MayDbIndexPrimitive, MayDbIndexQueryPageResult } from "../types";
4
+ export declare function buildIndexItem(definition: MayDbIndexDefinition, roomDescriptor: RoomDescriptor, doc: Y.Doc): MayDbIndexItem;
5
+ export declare function readQueryRows(rowsMap: Y.Map<string>, where: Record<string, MayDbIndexPrimitive>): MayDbIndexItem[];
6
+ export declare function pageRows(rows: MayDbIndexItem[], limit: number, afterRoomId: string | null): MayDbIndexQueryPageResult;
7
+ export declare function compareIndexItems(left: MayDbIndexItem, right: MayDbIndexItem, orderBy: MayDbIndexOrderBy): number;
8
+ //# sourceMappingURL=rows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../../src/indexing/rows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAElB,wBAAgB,cAAc,CAC5B,UAAU,EAAE,oBAAoB,EAChC,cAAc,EAAE,cAAc,EAC9B,GAAG,EAAE,CAAC,CAAC,GAAG,GACT,cAAc,CAahB;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,EACtB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,GACzC,cAAc,EAAE,CAKlB;AAED,wBAAgB,QAAQ,CACtB,IAAI,EAAE,cAAc,EAAE,EACtB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,IAAI,GACzB,yBAAyB,CAU3B;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAOR"}