@graffy/core 0.16.13-NaN.2 → 0.16.13

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 (3) hide show
  1. package/index.cjs +14 -2
  2. package/index.mjs +15 -3
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -46,8 +46,20 @@ async function mapStream(stream2, fn) {
46
46
  }
47
47
  }
48
48
  const unchanged = Symbol("Payload or result unchanged by handler");
49
+ const decodeCache = /* @__PURE__ */ new WeakMap();
50
+ function memoizeDecode(origDecode) {
51
+ return (payload) => {
52
+ if (decodeCache.has(payload))
53
+ return decodeCache.get(payload);
54
+ const decoded = origDecode(payload);
55
+ decodeCache.set(payload, decoded);
56
+ return decoded;
57
+ };
58
+ }
59
+ const decodeGraph = memoizeDecode(common.decodeGraph);
60
+ const decodeQuery = memoizeDecode(common.decodeQuery);
49
61
  function wrapProvider(fn, decodedPath, isRead) {
50
- const decodePayload = isRead ? common.decodeQuery : common.decodeGraph;
62
+ const decodePayload = isRead ? decodeQuery : decodeGraph;
51
63
  const encodePayload = isRead ? common.encodeQuery : common.encodeGraph;
52
64
  const path = common.encodePath(decodedPath);
53
65
  return async function wrappedProvider(payload, options, next) {
@@ -70,7 +82,7 @@ function wrapProvider(fn, decodedPath, isRead) {
70
82
  }
71
83
  nextResult = await next(nextPayload, nextOptions);
72
84
  remainingNextResult = common.remove(nextResult, path) || [];
73
- return common.unwrapObject(common.decodeGraph(nextResult), decodedPath);
85
+ return common.unwrapObject(decodeGraph(nextResult), decodedPath);
74
86
  }
75
87
  const porcelainResult = await fn(porcelainPayload, options, shiftedNext);
76
88
  let result;
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { encodePath, unwrap, unwrapObject, remove, encodeGraph, wrapObject, wrap, finalize, merge, mergeStreams, decodeQuery, decodeGraph, encodeQuery, isPlainObject, decorate } from "@graffy/common";
1
+ import { encodePath, unwrap, unwrapObject, remove, encodeGraph, wrapObject, wrap, finalize, merge, mergeStreams, encodeQuery, decodeGraph as decodeGraph$1, decodeQuery as decodeQuery$1, isPlainObject, decorate } from "@graffy/common";
2
2
  import { makeStream, mapStream as mapStream$1 } from "@graffy/stream";
3
3
  import debug from "debug";
4
4
  const log = debug("graffy:core");
@@ -45,6 +45,18 @@ async function mapStream(stream, fn) {
45
45
  }
46
46
  }
47
47
  const unchanged = Symbol("Payload or result unchanged by handler");
48
+ const decodeCache = /* @__PURE__ */ new WeakMap();
49
+ function memoizeDecode(origDecode) {
50
+ return (payload) => {
51
+ if (decodeCache.has(payload))
52
+ return decodeCache.get(payload);
53
+ const decoded = origDecode(payload);
54
+ decodeCache.set(payload, decoded);
55
+ return decoded;
56
+ };
57
+ }
58
+ const decodeGraph = memoizeDecode(decodeGraph$1);
59
+ const decodeQuery = memoizeDecode(decodeQuery$1);
48
60
  function wrapProvider(fn, decodedPath, isRead) {
49
61
  const decodePayload = isRead ? decodeQuery : decodeGraph;
50
62
  const encodePayload = isRead ? encodeQuery : encodeGraph;
@@ -192,7 +204,7 @@ class Graffy {
192
204
  path,
193
205
  shiftGen(function porcelainWatch(query, options) {
194
206
  return makeStream((push, end) => {
195
- const subscription = handle(decodeQuery(query), options, () => {
207
+ const subscription = handle(decodeQuery$1(query), options, () => {
196
208
  throw Error(`porcelain.watch_next_unsupported: ${path}`);
197
209
  });
198
210
  (async () => {
@@ -245,7 +257,7 @@ class Graffy {
245
257
  const [path, porcelainChange, options] = validateCall(...args);
246
258
  const change = encodeGraph(wrapObject(porcelainChange, path));
247
259
  const writtenChange = await this.core.call("write", change, options || {});
248
- return unwrapObject(decodeGraph(writtenChange), path);
260
+ return unwrapObject(decodeGraph$1(writtenChange), path);
249
261
  }
250
262
  }
251
263
  Graffy.unchanged = unchanged;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/core",
3
3
  "description": "The main module for Graffy, a library for intuitive real-time data APIs.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.16.13-NaN.2",
5
+ "version": "0.16.13",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
- "@graffy/common": "0.16.13-NaN.2",
20
- "@graffy/stream": "0.16.13-NaN.2",
19
+ "@graffy/common": "0.16.13",
20
+ "@graffy/stream": "0.16.13",
21
21
  "debug": "^4.3.3"
22
22
  }
23
23
  }