@wovin/core 0.0.8 → 0.0.9-RC1

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,5 +1,17 @@
1
1
  import { MappedThread, Thread, ThreadOnlyCurrent } from '../thread';
2
2
  import { ApplogForInsert, ApplogForInsertOptionalAgent, ApplogNoCid, Timestamp } from './datom-types';
3
+ export declare function finalizeApplogForInsert(log: ApplogForInsert, { ts, threadForPv }?: {
4
+ ts?: string;
5
+ threadForPv?: ThreadOnlyCurrent;
6
+ }): Readonly<{
7
+ at: string;
8
+ cid: string;
9
+ pv: string;
10
+ ts: string;
11
+ ag: string;
12
+ en: string;
13
+ vl: string | number | boolean;
14
+ }>;
3
15
  export declare function hasAg(log: ApplogForInsertOptionalAgent): log is ApplogForInsert;
4
16
  export declare function hasTs(log: ApplogForInsert): log is Omit<ApplogForInsert, 'ts'> & {
5
17
  ts: Timestamp;
@@ -10,13 +22,6 @@ export declare function hasPv(log: ApplogForInsert): log is ApplogForInsert & {
10
22
  export declare function withTs(log: ApplogForInsert, ts: Timestamp): Omit<ApplogForInsert, "ts"> & {
11
23
  ts: string;
12
24
  };
13
- export declare function withPvFrom(log: ApplogNoCid, thread: ThreadOnlyCurrent): {
14
- pv: import("./datom-types").CidString;
15
- at: string;
16
- ts: string;
17
- ag: import("./datom-types").AgentHash;
18
- en: string;
19
- vl: import("./datom-types").ApplogValue;
20
- };
25
+ export declare function withPvFrom(log: ApplogNoCid, thread: ThreadOnlyCurrent | null): ApplogNoCid;
21
26
  export declare function joinThreads(threads: ReadonlyArray<Thread>): MappedThread;
22
27
  //# sourceMappingURL=applog-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"applog-helpers.d.ts","sourceRoot":"","sources":["../../src/applog/applog-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkC,YAAY,EAAiB,MAAM,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAElH,OAAO,EAAE,e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om {
21
21
  cid: CidString;
22
- pv?: CidString;
22
+ pv: CidString | null;
23
23
  ts: Timestamp;
24
24
  ag: AgentHash;
25
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"datom-types.d.ts","sourceRoot":"","sources":["../../src/applog/datom-types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,MAAM,EAAE,OAAO,EAAQ,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAElE,eAAO,MAAM,QAAQ,8GAAsE,CAAA;AAC3F,eAAO,MAAM,eAAe,IAAI,CAAA;AAShC,eAAO,MAAM,QAAQ,qCAAgB,CAAA;AAErC,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAA;AAE9C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AACnD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAC9B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC3C,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAA;AAC9B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAC9B,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAA;AAG1D,MAAM,WAAW,IAAI;IACpB,EAAE,EAAE,QAAQ,CAAA;IACZ,EAAE,EAAE,SAAS,CAAA;IACb,EAAE,EAAE,WAAW,CAAA;CACf;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAC9B,MAAM,WAAW,MAAO,SAAQ,IAAI;IACnC,GAAG,EAAE,SAAS,CAAA;IACd,EAAE,CAAC,EAAE,SAAS,CAAA;IACd,EAAE,EAAE,SAAS,CAAA;IACb,EAAE,EAAE,SAAS,CAA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7 +42,7 @@ import {
41
42
  variableNameWithoutQuestionmark,
42
43
  withPvFrom,
43
44
  withTs
44
- } from "./chunk-N4QMZPZF.min.js";
45
+ } from "./chunk-IFQLMJQZ.min.js";
45
46
  import "./chunk-2J7BWXZ3.min.js";
46
47
  import "./chunk-PTGUFZ3Q.min.js";
47
48
  import "./chunk-KRQZ6V4Y.min.js";
@@ -62,6 +63,7 @@ export {
62
63
  compareApplogsByTs,
63
64
  cyrb53hash,
64
65
  dateNowIso,
66
+ finalizeApplogForInsert,
65
67
  getApplogNoCidTypeErrors,
66
68
  getApplogTypeErrors,
67
69
  getHashID,
@@ -9944,8 +9944,149 @@ function dateNowIso() {
9944
9944
  return now.toISOString();
9945
9945
  }
9946
9946
 
9947
- // src/thread/mapped.ts
9947
+ // src/applog/datom-types.ts
9948
+ var import_typebox = __toESM(require_typebox(), 1);
9949
+ var import_compiler = __toESM(require_compiler2(), 1);
9950
+ var Nullable = (schema) => import_typebox.Type.Union([schema, import_typebox.Type.Null()]);
9951
+ var EntityID_LENGTH = 7;
9952
+ var isCID = /^(k51qz|baguq)[0-9a-z]{56,57}$/;
9953
+ var isShortHash = /^[0-9A-Fa-f]{7,8}$/g;
9954
+ import_typebox.FormatRegistry.Set("EntityID", (value) => !!value.match(isShortHash) || !!value.match(isCID));
9955
+ var EntityID = import_typebox.Type.String();
9956
+ import_typebox.FormatRegistry.Set("CID", (value) => !!value.match(isCID));
9957
+ var CIDTB = import_typebox.Type.String({ format: "CID" });
9958
+ var isURL = /^http([s]?):\/\/.*\..*/;
9959
+ import_typebox.FormatRegistry.Set("URL", (value) => !!value.match(isURL));
9960
+ var URL = import_typebox.Type.String({ format: "URL" });
9961
+ var AppLogNoCidTB = import_typebox.Type.Object({
9962
+ en: EntityID,
9963
+ // EntityID
9964
+ at: import_typebox.Type.String(),
9965
+ // Attribute
9966
+ vl: Nullable(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Boolean(), import_typebox.Type.Number()])),
9967
+ // TODO refactor to semantic typesafe ApplogValue
9968
+ ts: import_typebox.Type.String(),
9969
+ // Timestamp
9970
+ ag: import_typebox.Type.String(),
9971
+ // AgentHash
9972
+ pv: CIDTB
9973
+ // CidString
9974
+ });
9975
+ var AppLogNoCidTBC = import_compiler.TypeCompiler.Compile(AppLogNoCidTB);
9976
+ var getApplogNoCidTypeErrors = (obj) => Array.from(AppLogNoCidTBC.Errors(obj));
9977
+ var isValidApplogNoCid = AppLogNoCidTBC.Check.bind(AppLogNoCidTBC);
9978
+ var AppLogTB = import_typebox.Type.Object({
9979
+ cid: CIDTB,
9980
+ // TODO: how to ...AppLogNoCidTB
9981
+ en: EntityID,
9982
+ // EntityID
9983
+ at: import_typebox.Type.String(),
9984
+ // Attribute
9985
+ vl: Nullable(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Boolean(), import_typebox.Type.Number()])),
9986
+ // TODO refactor to semantic typesafe ApplogValue
9987
+ ts: import_typebox.Type.String(),
9988
+ // Timestamp
9989
+ ag: import_typebox.Type.String(),
9990
+ // AgentHash
9991
+ pv: Nullable(CIDTB)
9992
+ // CidString
9993
+ });
9994
+ var AppLogTBC = import_compiler.TypeCompiler.Compile(AppLogTB);
9995
+ var getApplogTypeErrors = (obj) => Array.from(AppLogTBC.Errors(obj));
9996
+ var isValidApplog = AppLogTBC.Check.bind(AppLogTBC);
9997
+
9998
+ // src/applog/applog-helpers.ts
9948
9999
  var { WARN: WARN4, LOG: LOG4, DEBUG: DEBUG4, VERBOSE: VERBOSE4, ERROR: ERROR4 } = Logger.setup(Logger.INFO);
10000
+ function finalizeApplogForInsert(log, { ts, threadForPv } = {}) {
10001
+ const logWithTs = withTs(log, ts ?? dateNowIso());
10002
+ const logWithPv = withPvFrom(logWithTs, threadForPv);
10003
+ const cid = encodeApplogAndGetCid(logWithPv).toString();
10004
+ if (log.cid && log.cid !== cid)
10005
+ WARN4(`[finalizeApplogForInsert] overwriting wrong CID`, { log, cid, logWithPv });
10006
+ const logWithCid = { ...logWithPv, cid };
10007
+ if (!isValidApplog(logWithCid)) {
10008
+ throw ERROR4(`Bogus Applog ${JSON.stringify(logWithCid)}`, getApplogTypeErrors(logWithCid));
10009
+ }
10010
+ return Object.freeze(logWithCid);
10011
+ }
10012
+ function hasAg(log) {
10013
+ return !!log.ag;
10014
+ }
10015
+ function hasTs(log) {
10016
+ return !!log.ts;
10017
+ }
10018
+ function hasPv(log) {
10019
+ return !!log.pv;
10020
+ }
10021
+ function withTs(log, ts) {
10022
+ return hasTs(log) ? log : { ...log, ts };
10023
+ }
10024
+ function withPvFrom(log, thread) {
10025
+ if (!thread) {
10026
+ if (log.pv === void 0)
10027
+ throw ERROR4(`[withPvFrom] no thread and no pv:`, log);
10028
+ return log;
10029
+ } else {
10030
+ const { en, at } = log;
10031
+ const prevLogs = rollingFilter(thread, { en, at });
10032
+ if (prevLogs.size > 1)
10033
+ throw ERROR4(`[withPvFrom] unexpected previous count:`, prevLogs.size, { log, prevLogs, thread });
10034
+ let prevLog = prevLogs.isEmpty ? null : prevLogs.applogs[0];
10035
+ const isMatchingPv = prevLog?.cid === log.pv;
10036
+ if (objEqualByKeys(log, prevLog, ["en", "at", "vl", "ts", "ag"])) {
10037
+ throw ERROR4(`[withPvFrom] Same as previous:`, { log, pv: prevLog, thread });
10038
+ }
10039
+ if (log.pv && !isMatchingPv) {
10040
+ WARN4(`[withPvFrom] different than pre-set pv:`, { queriedPv: prevLog, logPv: log.pv });
10041
+ }
10042
+ const prevLogCid = (log.pv !== void 0 ? log.pv : prevLog?.cid) ?? null;
10043
+ return { ...log, pv: prevLogCid };
10044
+ }
10045
+ }
10046
+ function joinThreads(threads) {
10047
+ const fullJoin = () => {
10048
+ untracked(() => threads.length < 2 && DEBUG4(`joinThreads with count=${threads.length}`));
10049
+ return sortApplogsByTs(
10050
+ removeDuplicateAppLogs(threads.flatMap((s) => {
10051
+ const logs = s.applogs;
10052
+ if (!logs) {
10053
+ ERROR4(`falsy applogs of thread`, s);
10054
+ throw new Error(`falsy applogs of thread`);
10055
+ }
10056
+ return logs;
10057
+ }))
10058
+ );
10059
+ };
10060
+ let initialMergeResult = untracked(() => fullJoin());
10061
+ const eventMapper = action(function(event, sourceThread) {
10062
+ if (isInitEvent(event)) {
10063
+ return { init: untracked(() => fullJoin()) };
10064
+ } else {
10065
+ return {
10066
+ // TODO: test this stuff
10067
+ added: event.added.filter((addedLog) => !this.hasApplog(addedLog, true)),
10068
+ removed: event.added.filter(
10069
+ (addedLog) => !this.parents.some((parent) => {
10070
+ if (parent === sourceThread)
10071
+ return false;
10072
+ return parent.hasApplog(addedLog, true);
10073
+ })
10074
+ )
10075
+ };
10076
+ }
10077
+ });
10078
+ return new MappedThread(
10079
+ untracked(() => `join(~ ${threads.map((s) => s.name).join(", ")})`),
10080
+ threads,
10081
+ ["?"],
10082
+ // HACK this basically says "we're not sure what filters are applied"
10083
+ initialMergeResult,
10084
+ eventMapper
10085
+ );
10086
+ }
10087
+
10088
+ // src/thread/mapped.ts
10089
+ var { WARN: WARN5, LOG: LOG5, DEBUG: DEBUG5, VERBOSE: VERBOSE5, ERROR: ERROR5 } = Logger.setup(Logger.INFO);
9949
10090
  var MappedThread = class extends Thread {
9950
10091
  // mapped to unsubscribe function
9951
10092
  constructor(name, parents, filters, _initialLogs, _eventMapper) {
@@ -9969,21 +10110,21 @@ var MappedThread = class extends Thread {
9969
10110
  subscribeToParents() {
9970
10111
  const autorunDisposer = autorun(() => {
9971
10112
  if (!this.parents.length) {
9972
- WARN4(`MappedThread has no parents`, this);
10113
+ WARN5(`MappedThread has no parents`, this);
9973
10114
  }
9974
- VERBOSE4(`[MappedThread: ${this.name}] subscribing to parents:`, this.parents.map((p) => p.name));
10115
+ VERBOSE5(`[MappedThread: ${this.name}] subscribing to parents:`, this.parents.map((p) => p.name));
9975
10116
  const unseen = /* @__PURE__ */ new Set([...this._parentSubscriptions.keys()]);
9976
10117
  for (const p of this.parents) {
9977
10118
  let existed = unseen.delete(p);
9978
10119
  if (existed)
9979
- VERBOSE4(`[MappedThread: ${this.name}] Skipping re-sub to parent`, p.nameAndSizeUntracked);
9980
- VERBOSE4(`[MappedThread: ${this.name}] sub to new parent`, p.nameAndSizeUntracked);
10120
+ VERBOSE5(`[MappedThread: ${this.name}] Skipping re-sub to parent`, p.nameAndSizeUntracked);
10121
+ VERBOSE5(`[MappedThread: ${this.name}] sub to new parent`, p.nameAndSizeUntracked);
9981
10122
  const sub = this.onParentUpdate.bind(this, p);
9982
10123
  const unsubscribe = p.subscribe(sub);
9983
10124
  this._parentSubscriptions.set(p, unsubscribe);
9984
10125
  }
9985
10126
  for (const p of unseen) {
9986
- VERBOSE4(`[MappedThread: ${this.name}] un-subscribing from old parent`, p.nameAndSizeUntracked);
10127
+ VERBOSE5(`[MappedThread: ${this.name}] un-subscribing from old parent`, p.nameAndSizeUntracked);
9987
10128
  let unsubscribe = this._parentSubscriptions.get(p);
9988
10129
  unsubscribe();
9989
10130
  this._parentSubscriptions.delete(p);
@@ -9995,18 +10136,18 @@ var MappedThread = class extends Thread {
9995
10136
  * should not be used lightly
9996
10137
  */
9997
10138
  triggerRemap() {
9998
- DEBUG4(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap`);
10139
+ DEBUG5(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap`);
9999
10140
  if (this.parents.length !== 1) {
10000
- WARN4(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap with parentCount=${this.parents.length} - not meant for this`);
10141
+ WARN5(`MappedThread{${this.nameAndSizeUntracked}} triggerRemap with parentCount=${this.parents.length} - not meant for this`);
10001
10142
  }
10002
10143
  this.parents.forEach((p) => {
10003
10144
  this.onParentUpdate(p, { init: untracked(() => toJS(p.applogs)) });
10004
10145
  });
10005
10146
  }
10006
10147
  onParentUpdate(thread, event) {
10007
- VERBOSE4(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate`, event);
10148
+ VERBOSE5(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate`, event);
10008
10149
  const mapResult = this._eventMapper(event, thread);
10009
- VERBOSE4(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => mapped`, mapResult);
10150
+ VERBOSE5(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => mapped`, mapResult);
10010
10151
  if (isInitEvent(mapResult)) {
10011
10152
  ;
10012
10153
  this._applogs.replace([...mapResult.init]);
@@ -10018,9 +10159,9 @@ var MappedThread = class extends Thread {
10018
10159
  for (const toRemove of mapResult.removed) {
10019
10160
  if (!this._applogs.remove(toRemove)) {
10020
10161
  if (!isInitEvent(event) && event.removed?.includes(toRemove)) {
10021
- DEBUG4(`Ignoring remove event for non-existent because it was part of parent event's removed`, toRemove, event);
10162
+ DEBUG5(`Ignoring remove event for non-existent because it was part of parent event's removed`, toRemove, event);
10022
10163
  } else {
10023
- throw ERROR4(`MappedThread{${this.name}} toRemove contained log that doesn't exist`, toRemove, {
10164
+ throw ERROR5(`MappedThread{${this.name}} toRemove contained log that doesn't exist`, toRemove, {
10024
10165
  thread: this,
10025
10166
  event,
10026
10167
  mapResult
@@ -10030,13 +10171,13 @@ var MappedThread = class extends Thread {
10030
10171
  }
10031
10172
  }
10032
10173
  }
10033
- VERBOSE4(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => deps?`, getDependencyTree(this._applogs));
10174
+ VERBOSE5(`MappedThread{${this.nameAndSizeUntracked}} parentUpdate => deps?`, getDependencyTree(this._applogs));
10034
10175
  this.notifySubscribers(mapResult);
10035
10176
  }
10036
10177
  };
10037
10178
 
10038
10179
  // src/thread/filters.ts
10039
- var { WARN: WARN5, LOG: LOG5, DEBUG: DEBUG5, VERBOSE: VERBOSE5, ERROR: ERROR5 } = Logger.setup(Logger.INFO);
10180
+ var { WARN: WARN6, LOG: LOG6, DEBUG: DEBUG6, VERBOSE: VERBOSE6, ERROR: ERROR6 } = Logger.setup(Logger.INFO);
10040
10181
  var rollingFilter = computedFnDeepCompare("rollingFilter", function rollingFilter2(thread, pattern, opts = {}) {
10041
10182
  let untrackedPattern = getUntrackedPattern(pattern);
10042
10183
  let filter = makeFilter(untrackedPattern);
@@ -10044,7 +10185,7 @@ var rollingFilter = computedFnDeepCompare("rollingFilter", function rollingFilte
10044
10185
  untracked(() => filter(thread.applogs)),
10045
10186
  { deep: false, name: `${thread.name} | ${opts.name || `rollingFilter.array{${wrapper_default(untrackedPattern)}}`}` }
10046
10187
  );
10047
- const filterAdded = (event) => {
10188
+ const handleUpdateEvent = (event) => {
10048
10189
  let mappedEvent;
10049
10190
  if (isInitEvent(event)) {
10050
10191
  mappedEvent = { init: filter(event.init) };
@@ -10055,7 +10196,7 @@ var rollingFilter = computedFnDeepCompare("rollingFilter", function rollingFilte
10055
10196
  // whatever's removed shall be removed
10056
10197
  };
10057
10198
  }
10058
- VERBOSE5(
10199
+ VERBOSE6(
10059
10200
  `rollingFilter{${thread.nameAndSizeUntracked} | ${opts.name ? ` '${opts.name}'}` : ""} parentUpdate`,
10060
10201
  untrackedPattern,
10061
10202
  event,
@@ -10069,10 +10210,10 @@ var rollingFilter = computedFnDeepCompare("rollingFilter", function rollingFilte
10069
10210
  thread,
10070
10211
  [...thread.filters, ...opts.extraFilterName ? [opts.extraFilterName] : []],
10071
10212
  observableArr,
10072
- filterAdded
10213
+ handleUpdateEvent
10073
10214
  );
10074
10215
  const cancelPatternReaction = reaction(() => JSON.parse(JSON.stringify(pattern)), (pat) => {
10075
- VERBOSE5(
10216
+ VERBOSE6(
10076
10217
  `rollingFilter<${thread.nameAndSizeUntracked}>${opts.name ? ` '${opts.name}'` : ""} patternUpdate`,
10077
10218
  untrackedPattern,
10078
10219
  "=>",
@@ -10084,7 +10225,7 @@ var rollingFilter = computedFnDeepCompare("rollingFilter", function rollingFilte
10084
10225
  mappedThread.triggerRemap();
10085
10226
  });
10086
10227
  const unobserveUnobserving = onBecomeUnobserved(observableArr, () => {
10087
- VERBOSE5(`rollingFilter<${untracked(() => thread.name)}>${opts.name ? ` '${opts.name}'` : ""} unobserve`, untrackedPattern);
10228
+ VERBOSE6(`rollingFilter<${untracked(() => thread.name)}>${opts.name ? ` '${opts.name}'` : ""} unobserve`, untrackedPattern);
10088
10229
  cancelPatternReaction();
10089
10230
  unobserveUnobserving();
10090
10231
  });
@@ -10096,7 +10237,7 @@ var rollingFilter = computedFnDeepCompare("rollingFilter", function rollingFilte
10096
10237
  var rollingMapper = computedFnDeepCompare("rollingMapper", function rollingMapper2(thread, eventMapper, opts = {}) {
10097
10238
  const initialMapResult = untracked(() => eventMapper.call(null, { init: thread.applogs }, thread));
10098
10239
  if (!isInitEvent(initialMapResult)) {
10099
- throw ERROR5("Initial run must return init event");
10240
+ throw ERROR6("Initial run must return init event");
10100
10241
  }
10101
10242
  const initialLogs = initialMapResult.init;
10102
10243
  return new MappedThread(
@@ -10151,138 +10292,54 @@ function hasFilter(thread, filter) {
10151
10292
  }
10152
10293
  function assertRaw(thread) {
10153
10294
  if (thread.filters.length) {
10154
- throw ERROR5(`should be unfiltered thread, but is:`, thread.filters);
10295
+ throw ERROR6(`should be unfiltered thread, but is:`, thread.filters);
10155
10296
  }
10156
10297
  return thread;
10157
10298
  }
10158
10299
  function assertOnlyCurrent(thread) {
10159
10300
  if (!hasFilter(thread, "lastWriteWins") || !hasFilter(thread, "withoutDeleted"))
10160
- throw ERROR5(`should be filtered thread, but is:`, thread.filters);
10301
+ throw ERROR6(`should be filtered thread, but is:`, thread.filters);
10161
10302
  return thread;
10162
10303
  }
10163
-
10164
- // src/applog/applog-helpers.ts
10165
- var { WARN: WARN6, LOG: LOG6, DEBUG: DEBUG6, VERBOSE: VERBOSE6, ERROR: ERROR6 } = Logger.setup(Logger.INFO);
10166
- function hasAg(log) {
10167
- return !!log.ag;
10168
- }
10169
- function hasTs(log) {
10170
- return !!log.ts;
10171
- }
10172
- function hasPv(log) {
10173
- return !!log.pv;
10174
- }
10175
- function withTs(log, ts) {
10176
- return hasTs(log) ? log : { ...log, ts };
10177
- }
10178
- function withPvFrom(log, thread) {
10179
- const { en, at } = log;
10180
- const prevLogs = rollingFilter(thread, { en, at });
10181
- if (prevLogs.size > 1)
10182
- throw ERROR6(`[withPvFrom] unexpected previous count:`, prevLogs.size, { log, prevLogs, thread });
10183
- let prevLog = prevLogs.isEmpty ? null : prevLogs.applogs[0];
10184
- const isMatchingPv = prevLog?.cid === log.pv;
10185
- if (objEqualByKeys(log, prevLog, ["en", "at", "vl", "ts", "ag"])) {
10186
- throw ERROR6(`[withPvFrom] Same as previous:`, { log, pv: prevLog, thread });
10187
- }
10188
- if (log.pv && !isMatchingPv) {
10189
- WARN6(`[withPvFrom] different than pre-set pv:`, { queriedPv: prevLog, logPv: log.pv });
10190
- }
10191
- const prevLogCid = (log.pv !== void 0 ? log.pv : prevLog?.cid) ?? null;
10192
- return { ...log, pv: prevLogCid };
10193
- }
10194
- function joinThreads(threads) {
10195
- const fullJoin = () => {
10196
- untracked(() => threads.length < 2 && DEBUG6(`joinThreads with count=${threads.length}`));
10197
- return sortApplogsByTs(
10198
- removeDuplicateAppLogs(threads.flatMap((s) => {
10199
- const logs = s.applogs;
10200
- if (!logs) {
10201
- ERROR6(`falsy applogs of thread`, s);
10202
- throw new Error(`falsy applogs of thread`);
10203
- }
10204
- return logs;
10205
- }))
10206
- );
10207
- };
10208
- let initialMergeResult = untracked(() => fullJoin());
10209
- const eventMapper = action(function(event, sourceThread) {
10304
+ var simpleApplogMapper = function simpleApplogMapper2(thread, logMapper, opts = {}) {
10305
+ const mappedTo = /* @__PURE__ */ new Map();
10306
+ const mapLogs = (applogs, thread2) => applogs.map((log) => {
10307
+ const mapped = logMapper(log, thread2);
10308
+ const finalized = finalizeApplogForInsert(mapped, {});
10309
+ mappedTo.set(log.cid, finalized);
10310
+ return finalized;
10311
+ });
10312
+ const handleUpdateEvent = (event) => {
10313
+ let mappedEvent;
10210
10314
  if (isInitEvent(event)) {
10211
- return { init: untracked(() => fullJoin()) };
10315
+ mappedEvent = { init: mapLogs(event.init, thread) };
10212
10316
  } else {
10213
- return {
10214
- // TODO: test this stuff
10215
- added: event.added.filter((addedLog) => !this.hasApplog(addedLog, true)),
10216
- removed: event.added.filter(
10217
- (addedLog) => !this.parents.some((parent) => {
10218
- if (parent === sourceThread)
10219
- return false;
10220
- return parent.hasApplog(addedLog, true);
10221
- })
10222
- )
10317
+ mappedEvent = {
10318
+ added: mapLogs(event.added, thread),
10319
+ removed: event.removed.map((removedSourceLog) => {
10320
+ const mappedLog = mappedTo.get(removedSourceLog.cid);
10321
+ if (!mappedLog) {
10322
+ throw ERROR6(`[simpleApplogMapper] Parent remove event for Applog that we don't know about`, { removedSourceLog });
10323
+ }
10324
+ mappedTo.delete(removedSourceLog.cid);
10325
+ return mappedLog;
10326
+ })
10223
10327
  };
10224
10328
  }
10329
+ VERBOSE6(
10330
+ `simpleApplogMapper{${thread.nameAndSizeUntracked} | ${opts?.name ? ` '${opts?.name}'}` : ""} parentUpdate`,
10331
+ event,
10332
+ "=>",
10333
+ mappedEvent
10334
+ );
10335
+ return mappedEvent;
10336
+ };
10337
+ const mappedThread = rollingMapper(thread, handleUpdateEvent, opts);
10338
+ VERBOSE6.isDisabled || autorun(() => {
10339
+ VERBOSE6(`simpleApplogMapper<${thread.nameAndSizeUntracked}> mapped to`, mappedThread.applogs);
10225
10340
  });
10226
- return new MappedThread(
10227
- untracked(() => `join(~ ${threads.map((s) => s.name).join(", ")})`),
10228
- threads,
10229
- ["?"],
10230
- // HACK this basically says "we're not sure what filters are applied"
10231
- initialMergeResult,
10232
- eventMapper
10233
- );
10234
- }
10235
-
10236
- // src/applog/datom-types.ts
10237
- var import_typebox = __toESM(require_typebox(), 1);
10238
- var import_compiler = __toESM(require_compiler2(), 1);
10239
- var Nullable = (schema) => import_typebox.Type.Union([schema, import_typebox.Type.Null()]);
10240
- var EntityID_LENGTH = 7;
10241
- var isCID = /^(k51qz|baguq)[0-9a-z]{56,57}$/;
10242
- var isShortHash = /^[0-9A-Fa-f]{7,8}$/g;
10243
- import_typebox.FormatRegistry.Set("EntityID", (value) => !!value.match(isShortHash) || !!value.match(isCID));
10244
- var EntityID = import_typebox.Type.String();
10245
- import_typebox.FormatRegistry.Set("CID", (value) => !!value.match(isCID));
10246
- var CIDTB = import_typebox.Type.String({ format: "CID" });
10247
- var isURL = /^http([s]?):\/\/.*\..*/;
10248
- import_typebox.FormatRegistry.Set("URL", (value) => !!value.match(isURL));
10249
- var URL = import_typebox.Type.String({ format: "URL" });
10250
- var AppLogNoCidTB = import_typebox.Type.Object({
10251
- en: EntityID,
10252
- // EntityID
10253
- at: import_typebox.Type.String(),
10254
- // Attribute
10255
- vl: Nullable(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Boolean(), import_typebox.Type.Number()])),
10256
- // TODO refactor to semantic typesafe ApplogValue
10257
- ts: import_typebox.Type.String(),
10258
- // Timestamp
10259
- ag: import_typebox.Type.String(),
10260
- // AgentHash
10261
- pv: CIDTB
10262
- // CidString
10263
- });
10264
- var AppLogNoCidTBC = import_compiler.TypeCompiler.Compile(AppLogNoCidTB);
10265
- var getApplogNoCidTypeErrors = (obj) => Array.from(AppLogNoCidTBC.Errors(obj));
10266
- var isValidApplogNoCid = AppLogNoCidTBC.Check.bind(AppLogNoCidTBC);
10267
- var AppLogTB = import_typebox.Type.Object({
10268
- cid: CIDTB,
10269
- // TODO: how to ...AppLogNoCidTB
10270
- en: EntityID,
10271
- // EntityID
10272
- at: import_typebox.Type.String(),
10273
- // Attribute
10274
- vl: Nullable(import_typebox.Type.Union([import_typebox.Type.String(), import_typebox.Type.Boolean(), import_typebox.Type.Number()])),
10275
- // TODO refactor to semantic typesafe ApplogValue
10276
- ts: import_typebox.Type.String(),
10277
- // Timestamp
10278
- ag: import_typebox.Type.String(),
10279
- // AgentHash
10280
- pv: Nullable(CIDTB)
10281
- // CidString
10282
- });
10283
- var AppLogTBC = import_compiler.TypeCompiler.Compile(AppLogTB);
10284
- var getApplogTypeErrors = (obj) => Array.from(AppLogTBC.Errors(obj));
10285
- var isValidApplog = AppLogTBC.Check.bind(AppLogTBC);
10341
+ return mappedThread;
10342
+ };
10286
10343
 
10287
10344
  // src/query/types.ts
10288
10345
  var QueryNode = class {
@@ -10667,14 +10724,7 @@ var WriteableThread = class extends Thread {
10667
10724
  const ts = dateNowIso();
10668
10725
  const currentThread = lastWriteWins(this);
10669
10726
  const mapped = appLogsToInsert.map((log) => {
10670
- const logWithTs = withTs(log, ts);
10671
- const logWithPv = withPvFrom(logWithTs, currentThread);
10672
- const cid = encodeApplogAndGetCid(logWithPv).toString();
10673
- const logWithCid = { ...logWithPv, cid };
10674
- if (!isValidApplog(logWithCid)) {
10675
- throw ERROR8(`Bogus Applog ${JSON.stringify(logWithCid)}`, getApplogTypeErrors(logWithCid));
10676
- }
10677
- return Object.freeze(logWithCid);
10727
+ return finalizeApplogForInsert(log, { ts, threadForPv: currentThread });
10678
10728
  });
10679
10729
  return this.insertRaw(mapped);
10680
10730
  }
@@ -10788,6 +10838,7 @@ export {
10788
10838
  hasFilter,
10789
10839
  assertRaw,
10790
10840
  assertOnlyCurrent,
10841
+ simpleApplogMapper,
10791
10842
  Nullable,
10792
10843
  EntityID_LENGTH,
10793
10844
  EntityID,
@@ -10821,6 +10872,7 @@ export {
10821
10872
  prefixAt,
10822
10873
  WriteableThread,
10823
10874
  ThreadInMemory,
10875
+ finalizeApplogForInsert,
10824
10876
  hasAg,
10825
10877
  hasTs,
10826
10878
  hasPv,
@@ -10841,4 +10893,4 @@ lodash-es/lodash.js:
10841
10893
  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
10842
10894
  *)
10843
10895
  */
10844
- //# sourceMappingURL=chunk-N4QMZPZF.min.js.map
10896
+ //# sourceMappingURL=chunk-IFQLMJQZ.min.js.map