@wovin/core 0.0.0-ciao-mobx-955482e8

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 (180) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +3 -0
  3. package/dist/applog/applog-helpers.d.ts +47 -0
  4. package/dist/applog/applog-helpers.d.ts.map +1 -0
  5. package/dist/applog/applog-utils.d.ts +57 -0
  6. package/dist/applog/applog-utils.d.ts.map +1 -0
  7. package/dist/applog/datom-types.d.ts +128 -0
  8. package/dist/applog/datom-types.d.ts.map +1 -0
  9. package/dist/applog.d.ts +4 -0
  10. package/dist/applog.d.ts.map +1 -0
  11. package/dist/applog.js +101 -0
  12. package/dist/applog.js.map +1 -0
  13. package/dist/blockstore/index.d.ts +21 -0
  14. package/dist/blockstore/index.d.ts.map +1 -0
  15. package/dist/blockstore.d.ts +2 -0
  16. package/dist/blockstore.d.ts.map +1 -0
  17. package/dist/blockstore.js +24 -0
  18. package/dist/blockstore.js.map +1 -0
  19. package/dist/chunk-6MQKRL6W.js +86 -0
  20. package/dist/chunk-6MQKRL6W.js.map +1 -0
  21. package/dist/chunk-7MW34UEO.js +40 -0
  22. package/dist/chunk-7MW34UEO.js.map +1 -0
  23. package/dist/chunk-7Z5YDQKK.js +1 -0
  24. package/dist/chunk-7Z5YDQKK.js.map +1 -0
  25. package/dist/chunk-CY4NLISM.js +144 -0
  26. package/dist/chunk-CY4NLISM.js.map +1 -0
  27. package/dist/chunk-E46VTKTZ.js +1 -0
  28. package/dist/chunk-E46VTKTZ.js.map +1 -0
  29. package/dist/chunk-O43W7UW6.js +434 -0
  30. package/dist/chunk-O43W7UW6.js.map +1 -0
  31. package/dist/chunk-XIQSYEV3.js +1604 -0
  32. package/dist/chunk-XIQSYEV3.js.map +1 -0
  33. package/dist/chunk-XVGW4QC3.js +55 -0
  34. package/dist/chunk-XVGW4QC3.js.map +1 -0
  35. package/dist/chunk-YDAKBU6Q.js +9 -0
  36. package/dist/chunk-YDAKBU6Q.js.map +1 -0
  37. package/dist/chunk-ZAADLBSB.js +36 -0
  38. package/dist/chunk-ZAADLBSB.js.map +1 -0
  39. package/dist/chunk-ZXCJRYD7.js +883 -0
  40. package/dist/chunk-ZXCJRYD7.js.map +1 -0
  41. package/dist/index.d.ts +8 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +354 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/ipfs/car.d.ts +59 -0
  46. package/dist/ipfs/car.d.ts.map +1 -0
  47. package/dist/ipfs/fetch-snapshot-chain.d.ts +32 -0
  48. package/dist/ipfs/fetch-snapshot-chain.d.ts.map +1 -0
  49. package/dist/ipfs/ipfs-utils.d.ts +35 -0
  50. package/dist/ipfs/ipfs-utils.d.ts.map +1 -0
  51. package/dist/ipfs.d.ts +4 -0
  52. package/dist/ipfs.d.ts.map +1 -0
  53. package/dist/ipfs.js +60 -0
  54. package/dist/ipfs.js.map +1 -0
  55. package/dist/ipns/ipns-record.d.ts +34 -0
  56. package/dist/ipns/ipns-record.d.ts.map +1 -0
  57. package/dist/ipns.d.ts +2 -0
  58. package/dist/ipns.d.ts.map +1 -0
  59. package/dist/ipns.js +64 -0
  60. package/dist/ipns.js.map +1 -0
  61. package/dist/pubsub/connector.d.ts +9 -0
  62. package/dist/pubsub/connector.d.ts.map +1 -0
  63. package/dist/pubsub/pub-pull.d.ts +14 -0
  64. package/dist/pubsub/pub-pull.d.ts.map +1 -0
  65. package/dist/pubsub/pubsub-types.d.ts +72 -0
  66. package/dist/pubsub/pubsub-types.d.ts.map +1 -0
  67. package/dist/pubsub/snap-push.d.ts +41 -0
  68. package/dist/pubsub/snap-push.d.ts.map +1 -0
  69. package/dist/pubsub/ucan-example.d.ts +3 -0
  70. package/dist/pubsub/ucan-example.d.ts.map +1 -0
  71. package/dist/pubsub/ucan.d.ts +16 -0
  72. package/dist/pubsub/ucan.d.ts.map +1 -0
  73. package/dist/pubsub.d.ts +5 -0
  74. package/dist/pubsub.d.ts.map +1 -0
  75. package/dist/pubsub.js +31 -0
  76. package/dist/pubsub.js.map +1 -0
  77. package/dist/query/basic.d.ts +105 -0
  78. package/dist/query/basic.d.ts.map +1 -0
  79. package/dist/query/divergences.d.ts +12 -0
  80. package/dist/query/divergences.d.ts.map +1 -0
  81. package/dist/query/matchers.d.ts +4 -0
  82. package/dist/query/matchers.d.ts.map +1 -0
  83. package/dist/query/memoized.d.ts +66 -0
  84. package/dist/query/memoized.d.ts.map +1 -0
  85. package/dist/query/query-steps.d.ts +4 -0
  86. package/dist/query/query-steps.d.ts.map +1 -0
  87. package/dist/query/situations.d.ts +80 -0
  88. package/dist/query/situations.d.ts.map +1 -0
  89. package/dist/query/subscribable.d.ts +102 -0
  90. package/dist/query/subscribable.d.ts.map +1 -0
  91. package/dist/query/types.d.ts +70 -0
  92. package/dist/query/types.d.ts.map +1 -0
  93. package/dist/query.d.ts +8 -0
  94. package/dist/query.d.ts.map +1 -0
  95. package/dist/query.js +108 -0
  96. package/dist/query.js.map +1 -0
  97. package/dist/retrieve/index.d.ts +2 -0
  98. package/dist/retrieve/index.d.ts.map +1 -0
  99. package/dist/retrieve/update-thread.d.ts +64 -0
  100. package/dist/retrieve/update-thread.d.ts.map +1 -0
  101. package/dist/retrieve.d.ts +2 -0
  102. package/dist/retrieve.d.ts.map +1 -0
  103. package/dist/retrieve.js +14 -0
  104. package/dist/retrieve.js.map +1 -0
  105. package/dist/thread/basic.d.ts +60 -0
  106. package/dist/thread/basic.d.ts.map +1 -0
  107. package/dist/thread/filters.d.ts +47 -0
  108. package/dist/thread/filters.d.ts.map +1 -0
  109. package/dist/thread/mapped.d.ts +31 -0
  110. package/dist/thread/mapped.d.ts.map +1 -0
  111. package/dist/thread/utils.d.ts +23 -0
  112. package/dist/thread/utils.d.ts.map +1 -0
  113. package/dist/thread/writeable.d.ts +41 -0
  114. package/dist/thread/writeable.d.ts.map +1 -0
  115. package/dist/thread.d.ts +6 -0
  116. package/dist/thread.d.ts.map +1 -0
  117. package/dist/thread.js +54 -0
  118. package/dist/thread.js.map +1 -0
  119. package/dist/types/typescript-utils.d.ts +34 -0
  120. package/dist/types/typescript-utils.d.ts.map +1 -0
  121. package/dist/types.d.ts +2 -0
  122. package/dist/types.d.ts.map +1 -0
  123. package/dist/types.js +26 -0
  124. package/dist/types.js.map +1 -0
  125. package/dist/utils/debug-name.d.ts +13 -0
  126. package/dist/utils/debug-name.d.ts.map +1 -0
  127. package/dist/utils.d.ts +4 -0
  128. package/dist/utils.d.ts.map +1 -0
  129. package/dist/utils.js +9 -0
  130. package/dist/utils.js.map +1 -0
  131. package/package.json +110 -0
  132. package/src/applog/applog-helpers.ts +150 -0
  133. package/src/applog/applog-utils.ts +398 -0
  134. package/src/applog/datom-types.ts +148 -0
  135. package/src/applog.ts +3 -0
  136. package/src/blockstore/index.ts +36 -0
  137. package/src/blockstore.ts +1 -0
  138. package/src/index.ts +8 -0
  139. package/src/ipfs/car.ts +291 -0
  140. package/src/ipfs/fetch-snapshot-chain.ts +135 -0
  141. package/src/ipfs/ipfs-utils.ts +132 -0
  142. package/src/ipfs.ts +3 -0
  143. package/src/ipns/ipns-record.ts +115 -0
  144. package/src/ipns.ts +1 -0
  145. package/src/pubsub/UCAN Specs Overview.md +217 -0
  146. package/src/pubsub/connector.ts +9 -0
  147. package/src/pubsub/pub-pull.ts +31 -0
  148. package/src/pubsub/pubsub-types.ts +90 -0
  149. package/src/pubsub/snap-push.ts +277 -0
  150. package/src/pubsub/ucan-example.ts +61 -0
  151. package/src/pubsub/ucan.ts +56 -0
  152. package/src/pubsub.ts +4 -0
  153. package/src/query/basic.ts +1061 -0
  154. package/src/query/divergences.ts +50 -0
  155. package/src/query/matchers.ts +8 -0
  156. package/src/query/memoized.test.ts +151 -0
  157. package/src/query/memoized.ts +180 -0
  158. package/src/query/query-steps.ts +4 -0
  159. package/src/query/query.test.ts +536 -0
  160. package/src/query/situations.ts +261 -0
  161. package/src/query/subscribable.test.ts +245 -0
  162. package/src/query/subscribable.ts +225 -0
  163. package/src/query/types.ts +155 -0
  164. package/src/query.ts +7 -0
  165. package/src/retrieve/index.ts +1 -0
  166. package/src/retrieve/update-thread.ts +248 -0
  167. package/src/retrieve.ts +1 -0
  168. package/src/test/perf/query.1m.perf.test.ts +94 -0
  169. package/src/test/perf/query.perf.test.ts +389 -0
  170. package/src/test/perf/query.realdata.perf.test.ts +175 -0
  171. package/src/thread/basic.ts +209 -0
  172. package/src/thread/filters.ts +234 -0
  173. package/src/thread/mapped.ts +166 -0
  174. package/src/thread/utils.ts +146 -0
  175. package/src/thread/writeable.ts +163 -0
  176. package/src/thread.ts +5 -0
  177. package/src/types/typescript-utils.ts +64 -0
  178. package/src/types.ts +1 -0
  179. package/src/utils/debug-name.ts +54 -0
  180. package/src/utils.ts +4 -0
@@ -0,0 +1,47 @@
1
+ import { Applog, ApplogForInsert, DatalogQueryPattern } from '../applog/datom-types.ts';
2
+ import type { Subscribable } from '../query/subscribable.ts';
3
+ import { Thread, ThreadEvent } from './basic.ts';
4
+ import { ApplogEventMapper, MappedThread } from './mapped.ts';
5
+ export declare const rollingFilter: (thread: Thread, pattern: DatalogQueryPattern, opts?: {
6
+ name?: string;
7
+ extraFilterName?: string;
8
+ }) => MappedThread;
9
+ export declare const rollingMapper: (thread: Thread, eventMapper: ApplogEventMapper, opts?: {
10
+ name?: string;
11
+ extraFilterName?: string;
12
+ }) => MappedThread;
13
+ export declare const rollingAcc: <ACC>(thread: Thread, acc: ACC, eventMapper: (event: ThreadEvent, acc: ACC) => void, opts?: {
14
+ name?: string;
15
+ }) => Subscribable<ACC>;
16
+ export declare const getUntrackedPattern: (pattern: DatalogQueryPattern) => Partial<import("../applog.ts").WithMatchers<Applog>>;
17
+ export declare function makeFilter(pattern: DatalogQueryPattern): (logs: readonly Applog[]) => Applog[];
18
+ /**
19
+ * // ! think twice before using
20
+ */
21
+ export declare const getUntrackedFilterResults: (thread: Thread, pattern: DatalogQueryPattern, opts?: {
22
+ name?: string;
23
+ }) => Applog[];
24
+ export type ThreadWithFilter<T extends string> = Thread & {
25
+ filters: readonly T[];
26
+ };
27
+ export declare function hasFilter<T extends string>(thread: Thread, filter: T): thread is ThreadWithFilter<T>;
28
+ export declare function assertRaw(thread: Thread): ThreadWithoutFilters;
29
+ export declare function assertOnlyCurrent(thread: Thread): Thread & {
30
+ filters: readonly "lastWriteWins"[];
31
+ } & {
32
+ filters: readonly "withoutDeleted"[];
33
+ };
34
+ export type ThreadOnlyCurrent = ThreadWithFilter<'lastWriteWins'>;
35
+ export type ThreadNoDeleted = ThreadWithFilter<'withoutDeleted'>;
36
+ export type ThreadOnlyCurrentNoDeleted = ThreadWithFilter<'lastWriteWins' | 'withoutDeleted'>;
37
+ export type ThreadWithoutFilters = Thread & {
38
+ filters: [];
39
+ };
40
+ /** Re-export for convenience */
41
+ export declare const asReadOnly: typeof MappedThread.asReadOnly;
42
+ export type ApplogMapper = (log: Applog, sourceThread: Thread) => ApplogForInsert;
43
+ export declare const simpleApplogMapper: (thread: Thread, logMapper: ApplogMapper, opts?: {
44
+ name?: string;
45
+ extraFilterName?: string;
46
+ }) => MappedThread;
47
+ //# sourceMappingURL=filters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../src/thread/filters.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,eAAe,EAA0B,mBAAmB,EAAkB,MAAM,0BAA0B,CAAA;AAI/H,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAe,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAI7D,eAAO,MAAM,aAAa,WACjB,MAAM,WACL,mBAAmB,SACtB;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,iBAoChD,CAA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AC,CAAA;AAC7F,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG;IAAE,OAAO,EAAE,EAAE,CAAA;CAAE,CAAA;AAE3D,gCAAgC;AAChC,eAAO,MAAM,UAAU,gCAA0B,CAAA;AAMjD,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,eAAe,CAAA;AACjF,eAAO,MAAM,kBAAkB,GAC9B,QAAQ,MAAM,EACd,WAAW,YAAY,EACvB,OAAM;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAO,iBAsDtD,CAAA"}
@@ -0,0 +1,31 @@
1
+ import { Applog, ApplogForInsert } from '../applog/datom-types.ts';
2
+ import { Thread, ThreadEvent } from './basic.ts';
3
+ export type ApplogEventMapper = (this: MappedThread, event: ThreadEvent, sourceThread: Thread) => ThreadEvent;
4
+ export type ApplogWriteMapper = (this: MappedThread, applogs: Applog[] | ApplogForInsert[]) => Applog[] | ApplogForInsert[] | null;
5
+ export declare class MappedThread extends Thread {
6
+ readonly name: string;
7
+ readonly _initialLogs: Applog[];
8
+ private _eventMapper;
9
+ private _writeMapper;
10
+ private _readOnly?;
11
+ static mapWrites(parent: Thread, name: string, mapper: ApplogWriteMapper): MappedThread;
12
+ static asReadOnly(parent: Thread): Thread;
13
+ private _parentSubscriptions;
14
+ constructor(name: string, parents: Thread | readonly Thread[], filters: readonly string[], _initialLogs: Applog[], _eventMapper: ApplogEventMapper | null, _writeMapper?: ApplogWriteMapper, _readOnly?: boolean);
15
+ insert(appLogsToInsert: ApplogForInsert[]): void;
16
+ insertRaw(appLogsToInsert: Applog[]): void;
17
+ private subscribeToParents;
18
+ /** Tear down parent subscriptions and clear internal state */
19
+ dispose(): void;
20
+ /** Swap parents at runtime — re-subscribes and recomputes applogs, notifying downstream */
21
+ setParents(newParents: readonly Thread[]): void;
22
+ subscribe(callback: (event: ThreadEvent) => void, type?: 'derived' | 'reaction'): () => void;
23
+ /**
24
+ * // HACK to trigger remap on pattern change in rollingFilter
25
+ * should not be used lightly
26
+ */
27
+ triggerRemap(): void;
28
+ protected onParentUpdate(thread: Thread, event: ThreadEvent): void;
29
+ get readOnly(): boolean;
30
+ }
31
+ //# sourceMappingURL=mapped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapped.d.ts","sourceRoot":"","sources":["../../src/thread/mapped.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAClE,OAAO,EAAe,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAI7D,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,KAAK,WAAW,CAAA;AAE7G,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,eAAe,EAAE,KAAK,MAAM,EAAE,GAAG,eAAe,EAAE,GAAG,IAAI,CAAA;AAElI,qBAAa,YAAa,SAAQ,MAAM;IA4BtC,QAAQ,CAAC,IAAI,EAAE,MAAM;IAGrB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE;IAC/B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,SAAS,CAAC;IAjCnB,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB;IAWxE,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM;IAahC,OAAO,CAAC,oBAAoB,CAAkC;gBAGpD,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EACnC,OAAO,EAAE,SAAS,MAAM,EAAE,EACjB,YAAY,EAAE,MAAM,EAAE,EACvB,YAAY,EAAE,iBAAiB,GAAG,IAAI,EACtC,YAAY,GAAE,iBAAwB,EACtC,SAAS,CAAC,EAAE,OAAO;IAgBrB,MAAM,CAAC,eAAe,EAAE,eAAe,EAAE;IAMzC,SAAS,CAAC,eAAe,EAAE,MAAM,EAAE;IAO1C,OAAO,CAAC,kBAAkB;IAe1B,8DAA8D;IAC9D,OAAO;IASP,2FAA2F;IAC3F,UAAU,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE;IAOxC,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU;IAO/E;;;OAGG;IACH,YAAY;IAWZ,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW;IAiC3D,IAAI,QAAQ,YAEX;CACD"}
@@ -0,0 +1,23 @@
1
+ import { CID } from 'multiformats';
2
+ import { compareApplogsByEnAt } from '../applog/applog-utils.ts';
3
+ import { Applog, ApplogForInsert, CidString } from '../applog/datom-types.ts';
4
+ import { Thread } from './basic.ts';
5
+ import { MappedThread } from './mapped.ts';
6
+ export declare function entityCount(thread: Thread): number;
7
+ export declare function allEntityIDs(thread: Thread): Set<string>;
8
+ export declare function debounceWrites(thread: Thread, wait?: number, removeDuplicatesWith?: (objA: object, objB: object) => boolean): MappedThread;
9
+ /**
10
+ * @param deduplicateHoldItemsWith called with (heldLog, realLog), if it returns true, the held log is skipped
11
+ * @param onFirstWrite called with held logs about to be inserted, if it returns an array, those logs will be inserted instead
12
+ */
13
+ export declare function holdTillFirstWrite(thread: Thread, applogsToHold: ApplogForInsert[], opts: {
14
+ deduplicateHoldItemsWith?: typeof compareApplogsByEnAt;
15
+ onFirstWrite: (heldLogsToInsert: Applog[]) => Applog[] | undefined;
16
+ }): MappedThread;
17
+ export declare function getAgents(thread: Thread): import("../applog.ts").AgentHash[];
18
+ /**
19
+ * Returns applogs NOT contained in the exclusion set.
20
+ * Uses CID-based comparison (consistent with removeDuplicateAppLogs).
21
+ */
22
+ export declare const excludeApplogsContainedIn: (applogs: readonly Applog[], exclude: Thread | readonly Applog[] | Set<CID | CidString>) => Applog[];
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/thread/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA;AAElC,OAAO,EAAE,oBAAoB,EAAsC,MAAM,2BAA2B,CAAA;AACpG,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAY,MAAM,0BAA0B,CAAA;AACvF,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAK1C,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,UAEzC;AACD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,eAE1C;AAcD,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,SAAM,EACV,oBAAoB,0CAAuB,gBA4B3C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,eAAe,EAAE,EAChC,IAAI,EAAE;IACL,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAA;IACtD,YAAY,EAAE,CAAC,gBAAgB,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,GAAG,SAAS,CAAA;CAClE,gBA2CD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,sCAEvC;AAED;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,SAAS,MAAM,EAAE,EAC1B,SAAS,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,GAAG,CAAC,GAAG,GAAG,SAAS,CAAC,KACxD,MAAM,EAcR,CAAA"}
@@ -0,0 +1,41 @@
1
+ import { type Applog, ApplogForInsert, CidString } from '../applog/datom-types.ts';
2
+ import { Thread } from './basic.ts';
3
+ export declare abstract class WriteableThread extends Thread {
4
+ constructor(name: string, applogs: Applog[], filters: readonly string[]);
5
+ purge(cidsToPurge: CidString[]): number;
6
+ insert(appLogsToInsert: ApplogForInsert[]): Applog[];
7
+ /**
8
+ * Insert only applogs not already in this thread.
9
+ * @param byRef If true, compares by reference; if false, compares by CID (default)
10
+ * @returns The applogs that were actually inserted
11
+ */
12
+ insertMissing(appLogsToInsert: readonly Applog[], byRef?: boolean): Applog[];
13
+ /**
14
+ * Insert raw applogs directly into the thread.
15
+ *
16
+ * STRICT VALIDATION: This method throws errors for:
17
+ * - Duplicate applogs in input array (programming error)
18
+ * - Invalid applogs (missing required fields)
19
+ * - Applogs already in thread (programming error)
20
+ *
21
+ * For external imports where duplicates are expected, use removeDuplicateAppLogs(..., 'cleanup')
22
+ * before calling this method.
23
+ *
24
+ * @param appLogsToInsert Must be deduplicated and validated. Needs to be mutable because it will be sorted
25
+ * (and if you need to clone it, so do it when you need to) - this is weird as TS is slathering type safety onto ducks
26
+ * @throws Error if validation fails
27
+ */
28
+ insertRaw(appLogsToInsert: Applog[]): Applog[];
29
+ get readOnly(): boolean;
30
+ protected abstract persist(logs: Applog[]): Promise<void>;
31
+ }
32
+ export declare class ThreadInMemory extends WriteableThread {
33
+ readonly _readOnly: boolean;
34
+ static empty(name?: string): ThreadInMemory;
35
+ static fromArray(applogs: Applog[], name?: string, readOnly?: boolean): ThreadInMemory;
36
+ static fromReadOnlyArray(applogs: readonly Applog[], name?: string): ThreadInMemory;
37
+ constructor(name: string, applogs: Applog[], filters: readonly string[], _readOnly: boolean);
38
+ get readOnly(): boolean;
39
+ protected persist(logs: Applog[]): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=writeable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeable.d.ts","sourceRoot":"","sources":["../../src/thread/writeable.ts"],"names":[],"mappings":"AAGA,OAAO,EAA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';
4
+ export * from './thread/writeable.ts';
5
+ export * from './thread/utils.ts';
6
+ //# sourceMappingURL=thread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,mBAAmB,CAAA"}
package/dist/thread.js ADDED
@@ -0,0 +1,54 @@
1
+ import {
2
+ MappedThread,
3
+ StaticThread,
4
+ Thread,
5
+ ThreadInMemory,
6
+ WriteableThread,
7
+ allEntityIDs,
8
+ asReadOnly,
9
+ assertOnlyCurrent,
10
+ assertRaw,
11
+ debounceWrites,
12
+ entityCount,
13
+ excludeApplogsContainedIn,
14
+ getAgents,
15
+ getLogsFromThread,
16
+ getUntrackedFilterResults,
17
+ getUntrackedPattern,
18
+ hasFilter,
19
+ holdTillFirstWrite,
20
+ isInitEvent,
21
+ makeFilter,
22
+ rollingAcc,
23
+ rollingFilter,
24
+ rollingMapper,
25
+ simpleApplogMapper
26
+ } from "./chunk-XIQSYEV3.js";
27
+ import "./chunk-ZAADLBSB.js";
28
+ export {
29
+ MappedThread,
30
+ StaticThread,
31
+ Thread,
32
+ ThreadInMemory,
33
+ WriteableThread,
34
+ allEntityIDs,
35
+ asReadOnly,
36
+ assertOnlyCurrent,
37
+ assertRaw,
38
+ debounceWrites,
39
+ entityCount,
40
+ excludeApplogsContainedIn,
41
+ getAgents,
42
+ getLogsFromThread,
43
+ getUntrackedFilterResults,
44
+ getUntrackedPattern,
45
+ hasFilter,
46
+ holdTillFirstWrite,
47
+ isInitEvent,
48
+ makeFilter,
49
+ rollingAcc,
50
+ rollingFilter,
51
+ rollingMapper,
52
+ simpleApplogMapper
53
+ };
54
+ //# sourceMappingURL=thread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,34 @@
1
+ import { Type as T } from '@sinclair/typebox';
2
+ declare const StringTB: (options?: import("@sinclair/typebox").StringOptions) => import("@sinclair/typebox").TString, OptionalTB: <T extends import("@sinclair/typebox").TSchema>(schema: T) => import("@sinclair/typebox").TOptional<T>, BooleanTB: (options?: import("@sinclair/typebox").SchemaOptions) => import("@sinclair/typebox").TBoolean, ObjectTB: <T extends import("@sinclair/typebox").TProperties>(properties: T, options?: import("@sinclair/typebox").ObjectOptions) => import("@sinclair/typebox").TObject<T>, NumberTB: (options?: import("@sinclair/typebox").NumericOptions<number>) => import("@sinclair/typebox").TNumber;
3
+ export declare const Str: typeof StringTB;
4
+ export declare const Num: typeof NumberTB;
5
+ export declare const Obj: typeof ObjectTB;
6
+ export declare const Opt: typeof OptionalTB;
7
+ export declare const Bool: typeof BooleanTB;
8
+ export declare const STR: ReturnType<typeof T.String>;
9
+ export declare const NUM: ReturnType<typeof T.Number>;
10
+ export declare const BOOL: ReturnType<typeof T.Boolean>;
11
+ export type GenericObject = Record<string, any>;
12
+ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
13
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
14
+ export type PromiseType<T extends Promise<any>> = T extends Promise<infer U> ? U : never;
15
+ export type CoerceToString<T> = T extends string ? T : never;
16
+ /**
17
+ * Define nominal type of U based on type of T. Similar to Opaque types in Flow
18
+ */
19
+ export type Tagged<T, Tag> = T & {
20
+ tag?: Tag;
21
+ };
22
+ export type LastElementOf<T extends readonly unknown[]> = T extends readonly [...unknown[], infer Last] ? Last : never;
23
+ export declare function checkParityTB(): void;
24
+ /** solidjs Setter requires returning something, which I often don't */
25
+ export type GenericSetter<T> = (newValue: T) => void;
26
+ export type ArrayOrSingle<T> = T | T[] | readonly T[];
27
+ export declare function arrayIfSingle<T>(arrOrSingle: ArrayOrSingle<T>): readonly T[];
28
+ export type ArrayType<T> = T extends (infer U)[] ? U : T;
29
+ export type ArrayElementType<T> = T extends readonly (infer U)[] ? Extract<U, string> : never;
30
+ export type ConstructorType<T, S = {}> = {
31
+ new (...args: any[]): T;
32
+ } & S;
33
+ export {};
34
+ //# sourceMappingURL=typescript-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-utils.d.ts","sourceRoot":"","sources":["../../src/types/typescript-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,MAAM,mBAAmB,CAAA;AAO7C,QAAA,MAAgB,QAAQ,gGAAY,UAAU,0GAAW,SAAS,iGAAU,QAAQ,qKAAU,QAAQ,uGAAM,CAAA;AAC5G,eAAO,MAAM,GAAG,EAAE,OAAO,QAA2B,CAAA;AACpD,eAAO,MAAM,GAAG,EAAE,OAAO,QAA2B,CAAA;AACpD,eAAO,MAAM,GAAG,EAAE,OAAO,QAA2B,CAAA;AACpD,eAAO,MAAM,GAAG,EAAE,OAAO,UAA+B,CAAA;AACxD,eAAO,MAAM,IAAI,EAAE,OAAO,SAA6B,CAAA;AAEvD,eAAO,MAAM,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAAS,CAAA;AACrD,eAAO,MAAM,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAAS,CAAA;AACrD,eAAO,MAAM,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAU,CAAA;AAExD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC/C,MAAM,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACrE,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,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,GAAG,EAAE,IAAI;IACxC,KAAI,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;CACtB,GAAG,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './types/typescript-utils.ts';
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
package/dist/types.js ADDED
@@ -0,0 +1,26 @@
1
+ import "./chunk-E46VTKTZ.js";
2
+ import {
3
+ BOOL,
4
+ Bool,
5
+ NUM,
6
+ Num,
7
+ Obj,
8
+ Opt,
9
+ STR,
10
+ Str,
11
+ arrayIfSingle,
12
+ checkParityTB
13
+ } from "./chunk-ZAADLBSB.js";
14
+ export {
15
+ BOOL,
16
+ Bool,
17
+ NUM,
18
+ Num,
19
+ Obj,
20
+ Opt,
21
+ STR,
22
+ Str,
23
+ arrayIfSingle,
24
+ checkParityTB
25
+ };
26
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,13 @@
1
+ import type { Applog, DatalogQueryPattern } from '../applog/datom-types.ts';
2
+ import type { Thread } from '../thread/basic.ts';
3
+ export declare const createDebugName: ({ caller, thread, pattern, args }: {
4
+ caller?: string;
5
+ thread?: Thread | Applog[];
6
+ pattern?: DatalogQueryPattern | DatalogQueryPattern[] | string;
7
+ args?: any;
8
+ }) => string;
9
+ export declare const createDebugNameObj: (args: Parameters<typeof createDebugName>[0]) => {
10
+ readonly name: string;
11
+ };
12
+ export declare function prettifyThreadName(input: string): string;
13
+ //# sourceMappingURL=debug-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-name.d.ts","sourceRoot":"","sources":["../../src/utils/debug-name.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAEhD,eAAO,MAAM,eAAe,GAAI,mCAAmC;IAClE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC1B,OAAO,CAAC,EAAE,mBAAmB,GAAG,mBAAmB,EAAE,GAAG,MAAM,CAAA;IAC9D,IAAI,CAAC,EAAE,GAAG,CAAA;CACV,WAMA,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,MAAM,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC;;CAE7E,CAAA;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgCxD"}
@@ -0,0 +1,4 @@
1
+ import { Applog, ApplogEncNoCid } from './applog/datom-types.ts';
2
+ export declare const isTruthy: (l: Applog | ApplogEncNoCid) => boolean;
3
+ export declare const keepTruthy: (arr: readonly any[]) => any[];
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAEhE,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,GAAG,cAAc,KAAG,OAAc,CAAA;AACpE,eAAO,MAAM,UAAU,GAAI,KAAK,SAAS,GAAG,EAAE,KAAG,GAAG,EAA0B,CAAA"}
package/dist/utils.js ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ isTruthy,
3
+ keepTruthy
4
+ } from "./chunk-YDAKBU6Q.js";
5
+ export {
6
+ isTruthy,
7
+ keepTruthy
8
+ };
9
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "@wovin/core",
3
+ "version": "0.0.0-ciao-mobx-955482e8",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "browser": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./applog": {
15
+ "import": "./dist/applog.js",
16
+ "types": "./dist/applog.d.ts"
17
+ },
18
+ "./blockstore": {
19
+ "import": "./dist/blockstore.js",
20
+ "types": "./dist/blockstore.d.ts"
21
+ },
22
+ "./ipfs": {
23
+ "import": "./dist/ipfs.js",
24
+ "types": "./dist/ipfs.d.ts"
25
+ },
26
+ "./pubsub": {
27
+ "import": "./dist/pubsub.js",
28
+ "types": "./dist/pubsub.d.ts"
29
+ },
30
+ "./query": {
31
+ "import": "./dist/query.js",
32
+ "types": "./dist/query.d.ts"
33
+ },
34
+ "./retrieve": {
35
+ "import": "./dist/retrieve.js",
36
+ "types": "./dist/retrieve.d.ts"
37
+ },
38
+ "./thread": {
39
+ "import": "./dist/thread.js",
40
+ "types": "./dist/thread.d.ts"
41
+ },
42
+ "./types": {
43
+ "import": "./dist/types.js",
44
+ "types": "./dist/types.d.ts"
45
+ },
46
+ "./utils": {
47
+ "import": "./dist/utils.js",
48
+ "types": "./dist/utils.d.ts"
49
+ },
50
+ "./ipns": {
51
+ "import": "./dist/ipns.js",
52
+ "types": "./dist/ipns.d.ts"
53
+ }
54
+ },
55
+ "files": [
56
+ "./dist/",
57
+ "./src/"
58
+ ],
59
+ "packageManager": "pnpm",
60
+ "esm.sh": {
61
+ "bundle": false
62
+ },
63
+ "peerDependencies": {
64
+ "@sinclair/typebox": "^0.31.28"
65
+ },
66
+ "dependencies": {
67
+ "@ipld/car": "^5.4.2",
68
+ "@ipld/dag-json": "^10.2.5",
69
+ "@noble/hashes": "^2.0.1",
70
+ "@oddjs/odd": "^0.37.2",
71
+ "besonders-logger": "1.0.2",
72
+ "date-fns": "^3.3.1",
73
+ "hash-wasm": "^4.12.0",
74
+ "iso-kv": "^3.1.1",
75
+ "iso-signatures": "^0.5.1",
76
+ "iso-ucan": "^0.4.2",
77
+ "lodash-es": "^4.17.21",
78
+ "@libp2p/crypto": "^5.0.0",
79
+ "ipns": "^10.1.2",
80
+ "multiformats": "^13.4.1",
81
+ "safe-stable-stringify": "^2.5.0",
82
+ "zod": "^4.3.6"
83
+ },
84
+ "devDependencies": {
85
+ "@types/lodash-es": "^4.17.12",
86
+ "concurrently": "^8.2.2",
87
+ "esbuild-plugin-polyfill-node": "^0.3.0",
88
+ "tsup": "^8.5.0",
89
+ "typescript": "^5.9.2",
90
+ "vite": "^7.1.7",
91
+ "tsupconfig": "^0.0.0"
92
+ },
93
+ "repository": {
94
+ "type": "git",
95
+ "url": "git+https://gitlab.com/wovin/wovin.git",
96
+ "directory": "packages/@wovin/core"
97
+ },
98
+ "license": "AGPL-3.0-or-later",
99
+ "scripts": {
100
+ "build": "rm -rf dist/ && concurrently \"pnpm build:code\" \"pnpm build:types\"",
101
+ "build:code": "tsup --external esbuild",
102
+ "build:types": "tsc --emitDeclarationOnly --declaration",
103
+ "dev": "concurrently \"pnpm dev:code\" \"pnpm dev:types\"",
104
+ "dev:code": "tsup --watch",
105
+ "dev:types": "tsc --emitDeclarationOnly --declaration --watch",
106
+ "lint": "eslint .",
107
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
108
+ "pub": "npm publish --tag latest --access=public"
109
+ }
110
+ }
@@ -0,0 +1,150 @@
1
+ import { Logger } from 'besonders-logger'
2
+ import { encodeApplogAndGetCid } from '../ipfs/ipfs-utils.ts'
3
+ import { lastWriteWins } from '../query/basic.ts'
4
+ import { ApplogEventMapper, isInitEvent, MappedThread, rollingFilter, Thread, ThreadOnlyCurrent } from '../thread.ts'
5
+ import { PartialBy } from '../types/typescript-utils.ts'
6
+ import { dateNowIso, objEqualByKeys, removeDuplicateAppLogs, sortApplogsByTs } from './applog-utils.ts'
7
+ import {
8
+ Applog,
9
+ ApplogForInsert,
10
+ ApplogForInsertOptionalAgent,
11
+ ApplogNoCid,
12
+ AgentHash,
13
+ CidString,
14
+ getApplogTypeErrors,
15
+ isValidApplog,
16
+ Timestamp,
17
+ } from './datom-types.ts'
18
+
19
+ const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line no-unused-vars
20
+
21
+ export function ensureTsPvAndFinalizeApplogs(appLogsToInsert: ApplogForInsert[], threadForPv: Thread) {
22
+ DEBUG(`[ensureTsPvAndFinalizeApplogs] ENTER - ${appLogsToInsert.length} applogs, thread size=${threadForPv.size}`)
23
+ const ts = dateNowIso()
24
+ // const currentThread = lastWriteWins(threadForPv, { tolerateAlreadyFiltered: true }) // HACK to get `pv` from last write
25
+ const currentThread = threadForPv // HACK to not do un-cached lastWriteWins
26
+
27
+ DEBUG(`[ensureTsPvAndFinalizeApplogs] About to map over applogs`)
28
+ const mapped = appLogsToInsert.map((log, idx) => {
29
+ DEBUG(`[ensureTsPvAndFinalizeApplogs] Processing applog ${idx + 1}/${appLogsToInsert.length}`)
30
+ const result = finalizeApplogForInsert(log, { ts, threadForPv: currentThread })
31
+ DEBUG(`[ensureTsPvAndFinalizeApplogs] Finalized applog ${idx + 1}/${appLogsToInsert.length}`)
32
+ return result
33
+ })
34
+ DEBUG(`[ensureTsPvAndFinalizeApplogs] EXIT - mapped ${mapped.length} applogs`)
35
+ return mapped
36
+ }
37
+ export function ensureTsPvAndFinalizeApplog(applogToInsert: ApplogForInsert, threadForPv: Thread) {
38
+ return ensureTsPvAndFinalizeApplogs([applogToInsert], threadForPv)[0]
39
+ }
40
+
41
+ export function finalizeApplogForInsert(
42
+ log: ApplogForInsert,
43
+ { ts, threadForPv }: { ts?: string; threadForPv?: Thread /*OnlyCurrent*/ } = {},
44
+ ) {
45
+ DEBUG(`[finalizeApplogForInsert] ENTER - en=${log.en}, at=${log.at}`)
46
+ DEBUG(`[finalizeApplogForInsert] About to call withTs`)
47
+ const logWithTs = withTs(log, ts ?? dateNowIso())
48
+ DEBUG(`[finalizeApplogForInsert] About to call withPvFrom (thread size=${threadForPv?.size ?? 'null'})`)
49
+ const logWithPv = withPvFrom(logWithTs, threadForPv)
50
+ DEBUG(`[finalizeApplogForInsert] About to call encodeApplogAndGetCid`)
51
+ const cid = encodeApplogAndGetCid(logWithPv).toString() as CidString
52
+ DEBUG(`[finalizeApplogForInsert] CID created: ${cid}`)
53
+ if ((log as Applog).cid && (log as Applog).cid !== cid) WARN(`[finalizeApplogForInsert] overwriting wrong CID`, { log, cid, logWithPv })
54
+ const logWithCid = { ...logWithPv, cid } satisfies Applog
55
+ DEBUG(`[finalizeApplogForInsert] About to validate applog`)
56
+ if (!isValidApplog(logWithCid)) {
57
+ throw ERROR(`Bogus Applog ${JSON.stringify(logWithCid)}`, getApplogTypeErrors(logWithCid))
58
+ }
59
+ DEBUG(`[finalizeApplogForInsert] EXIT - CID=${cid}`)
60
+ return Object.freeze(logWithCid)
61
+ }
62
+
63
+ export function hasAg(log: ApplogForInsertOptionalAgent): log is ApplogForInsert {
64
+ return !!log.ag
65
+ }
66
+ export function hasTs(log: ApplogForInsert): log is Omit<ApplogForInsert, 'ts'> & { ts: Timestamp } {
67
+ return !!log.ts
68
+ }
69
+ export function hasPv(log: ApplogForInsert): log is ApplogForInsert & { pv: string } {
70
+ return !!log.pv
71
+ }
72
+
73
+ export function withTs(log: ApplogForInsert, ts: Timestamp) {
74
+ return hasTs(log) ? log : { ...log, ts }
75
+ }
76
+ export function withAg(log: ApplogForInsertOptionalAgent, ag: AgentHash) {
77
+ return hasAg(log) ? log : { ...log, ag }
78
+ }
79
+ export function withPvFrom(log: PartialBy<ApplogNoCid, 'pv'>, thread: Thread /*OnlyCurrent*/ | null) {
80
+ DEBUG(`[withPvFrom] ENTER - en=${log.en}, at=${log.at}, hasPv=${log.pv !== undefined}`)
81
+ if (log.pv !== undefined) {
82
+ DEBUG(`[withPvFrom] EXIT early - pv already set`)
83
+ return log as ApplogNoCid // TODO: ? devMode WARN if it's different for catching bugs)
84
+ }
85
+ if (!thread) {
86
+ if (!hasPv(log)) throw ERROR(`[withPvFrom] no thread and no pv:`, log)
87
+ DEBUG(`[withPvFrom] EXIT - no thread, returning log with existing pv`)
88
+ return log // satisfies Pick<Applog, 'pv'>
89
+ } else {
90
+ const { en, at } = log
91
+ DEBUG(`[withPvFrom] About to call thread.findLast for en=${en}, at=${at}, thread.size=${thread.size}`)
92
+ const prevLog = thread.findLast(l => l.en == en && l.at == at) // HACK to not do lastWriteWins calc
93
+ DEBUG(`[withPvFrom] findLast completed, found=${!!prevLog}`)
94
+ // const prevLogs = rollingFilter(thread, { en, at }) // ? use some non-reactive filter here?
95
+ // if (prevLogs.size > 1) throw ERROR(`[withPvFrom] unexpected previous count:`, prevLogs.size, { log, prevLogs, thread }) // `thread` arg must be only current
96
+ // let prevLog = prevLogs.isEmpty ? null : prevLogs.applogs[0]
97
+ // const isMatchingPv = prevLog?.cid === log.pv
98
+ DEBUG(`[withPvFrom] About to check equality`)
99
+ if (objEqualByKeys(['en', 'at', 'vl', 'ts', 'ag'], log, prevLog)) {
100
+ throw ERROR(`[withPvFrom] Same as previous:`, { log, pv: prevLog, thread }) // bug catcher
101
+ }
102
+ // if (log.pv && !isMatchingPv) { // ineffective bc. shortcut in the beginning of this func
103
+ // WARN(`[withPvFrom] different than pre-set pv:`, { queriedPv: prevLog, logPv: log.pv })
104
+ // }
105
+ const prevLogCid = (log.pv !== undefined ? log.pv : prevLog?.cid) ?? null
106
+ DEBUG(`[withPvFrom] EXIT - prevLogCid=${prevLogCid}`)
107
+ return { ...log, pv: prevLogCid }
108
+ }
109
+ }
110
+ export function joinThreads(threads: ReadonlyArray<Thread>) {
111
+ const fullJoin = () => {
112
+ if (threads.length < 2) DEBUG(`joinThreads with count=${threads.length}`) // ? EmptyThread
113
+ return sortApplogsByTs(
114
+ removeDuplicateAppLogs(threads.flatMap(s => {
115
+ const logs = s.applogs
116
+ if (!logs) {
117
+ ERROR(`falsy applogs of thread`, s)
118
+ throw new Error(`falsy applogs of thread`)
119
+ }
120
+ return logs
121
+ }), 'cleanup'),
122
+ )
123
+ }
124
+ let initialMergeResult = fullJoin()
125
+ const eventMapper: ApplogEventMapper = function(event, sourceThread) {
126
+ if (isInitEvent(event)) {
127
+ return { init: fullJoin() }
128
+ } else {
129
+ // if (event.removed) WARN(`JoinThreads with parents removing stuff - NOT IMPLEMENTED CORRECTLY`, { event, joined: this, sourceThread }) // TODO: joinTHreads & removed?
130
+ return {
131
+ // TODO: test this stuff
132
+ added: event.added.filter(addedLog => !this.hasApplog(addedLog, true)),
133
+ removed: event.removed?.filter(removedLog => {
134
+ const otherParentHasLog = !this.parents.some(parent => {
135
+ if (parent === sourceThread) return false
136
+ return parent.hasApplog(removedLog, true)
137
+ })
138
+ return !otherParentHasLog
139
+ }),
140
+ }
141
+ }
142
+ }
143
+ return new MappedThread(
144
+ `join(~ ${threads.map(s => s.name).join(', ')})`,
145
+ threads,
146
+ ['?'], // HACK this basically says "we're not sure what filters are applied"
147
+ initialMergeResult,
148
+ eventMapper,
149
+ )
150
+ }