@fireproof/core 0.20.3 → 0.20.4-dev-preview-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -1904,7 +1904,6 @@ var Index = class {
1904
1904
  this.mapFnString = "";
1905
1905
  this.byKey = new IndexTree();
1906
1906
  this.byId = new IndexTree();
1907
- this.includeDocsDefault = true;
1908
1907
  this.logger = ensureLogger(sthis, "Index");
1909
1908
  this.blockstore = crdt.indexBlockstore;
1910
1909
  this.crdt = crdt;
@@ -1920,18 +1919,19 @@ var Index = class {
1920
1919
  if (mapFn && meta) throw this.logger.Error().Msg("cannot provide both mapFn and meta").AsError();
1921
1920
  if (this.name && this.name !== name) throw this.logger.Error().Msg("cannot change name").AsError();
1922
1921
  try {
1922
+ let mapFnChanged = false;
1923
1923
  if (meta) {
1924
1924
  if (this.indexHead && this.indexHead.map((c) => c.toString()).join() !== meta.head.map((c) => c.toString()).join()) {
1925
1925
  throw this.logger.Error().Msg("cannot apply different head meta").AsError();
1926
1926
  }
1927
1927
  if (this.mapFnString) {
1928
1928
  if (this.mapFnString !== meta.map) {
1929
- this.logger.Warn().Msg(`cannot apply different mapFn meta: old mapFnString ${this.mapFnString} new mapFnString ${meta.map}`);
1930
- } else {
1931
- this.byId.cid = meta.byId;
1932
- this.byKey.cid = meta.byKey;
1933
- this.indexHead = meta.head;
1929
+ this.mapFnString = meta.map;
1930
+ mapFnChanged = true;
1934
1931
  }
1932
+ this.byId.cid = meta.byId;
1933
+ this.byKey.cid = meta.byKey;
1934
+ this.indexHead = meta.head;
1935
1935
  } else {
1936
1936
  this.mapFnString = meta.map;
1937
1937
  this.byId.cid = meta.byId;
@@ -1942,7 +1942,9 @@ var Index = class {
1942
1942
  if (this.mapFn) {
1943
1943
  if (mapFn) {
1944
1944
  if (this.mapFn.toString() !== mapFn.toString()) {
1945
- this.logger.Error().Msg("cannot apply different mapFn app2");
1945
+ this.mapFn = mapFn;
1946
+ this.mapFnString = mapFn.toString();
1947
+ mapFnChanged = true;
1946
1948
  }
1947
1949
  }
1948
1950
  } else {
@@ -1951,7 +1953,7 @@ var Index = class {
1951
1953
  }
1952
1954
  if (this.mapFnString) {
1953
1955
  if (this.mapFnString !== mapFn.toString()) {
1954
- this.logger.Error().Str("mapFnString", this.mapFnString).Str("mapFn", mapFn.toString()).Msg("cannot apply different mapFn app");
1956
+ mapFnChanged = true;
1955
1957
  }
1956
1958
  } else {
1957
1959
  this.mapFnString = mapFn.toString();
@@ -1959,8 +1961,9 @@ var Index = class {
1959
1961
  this.mapFn = mapFn;
1960
1962
  }
1961
1963
  }
1962
- const matches = /=>\s*(.*)/.test(this.mapFnString);
1963
- this.includeDocsDefault = matches;
1964
+ if (mapFnChanged) {
1965
+ this._resetIndex();
1966
+ }
1964
1967
  } catch (e) {
1965
1968
  this.initError = e;
1966
1969
  }
@@ -1976,7 +1979,7 @@ var Index = class {
1976
1979
  if (!this.byKey.root) {
1977
1980
  return await applyQuery(this.crdt, { result: [] }, opts);
1978
1981
  }
1979
- if (this.includeDocsDefault && opts.includeDocs === void 0) opts.includeDocs = true;
1982
+ if (opts.includeDocs === void 0) opts.includeDocs = true;
1980
1983
  if (opts.range) {
1981
1984
  const eRange = encodeRange(opts.range);
1982
1985
  return await applyQuery(this.crdt, await throwFalsy(this.byKey.root).range(eRange[0], eRange[1]), opts);
@@ -7265,6 +7268,6 @@ function buildResDelWAL(msgCtx, req, ctx) {
7265
7268
 
7266
7269
  // src/version.ts
7267
7270
  var PACKAGE_VERSION = Object.keys({
7268
- "0.20.3": "xxxx"
7271
+ "0.20.4-dev-preview-2": "xxxx"
7269
7272
  })[0];
7270
7273
  //# sourceMappingURL=index.cjs.map