@graffy/core 0.16.11 → 0.16.12-alpha.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
@@ -45,38 +45,50 @@ async function mapStream(stream2, fn) {
45
45
  fn(value);
46
46
  }
47
47
  }
48
+ const unchanged = Symbol("Payload or result unchanged by handler");
48
49
  function wrapProvider(fn, decodedPath, isRead) {
49
50
  const decodePayload = isRead ? common.decodeQuery : common.decodeGraph;
50
51
  const encodePayload = isRead ? common.encodeQuery : common.encodeGraph;
51
52
  const path = common.encodePath(decodedPath);
52
53
  return async function wrappedProvider(payload, options, next) {
53
54
  let nextCalled = false;
55
+ let nextResult;
54
56
  let remainingNextResult;
55
57
  const porcelainPayload = common.unwrapObject(decodePayload(payload), decodedPath);
56
58
  const remainingPayload = common.remove(payload, path) || [];
57
59
  async function shiftedNext(porcelainNextPayload, nextOptions) {
58
60
  nextCalled = true;
59
- const nextPayload = encodePayload(
60
- common.wrapObject(porcelainNextPayload, decodedPath)
61
- );
62
- if (remainingPayload.length)
63
- common.merge(nextPayload, remainingPayload);
64
- const nextResult = await next(nextPayload, nextOptions);
61
+ let nextPayload;
62
+ if (porcelainNextPayload === unchanged) {
63
+ nextPayload = payload;
64
+ } else {
65
+ nextPayload = encodePayload(
66
+ common.wrapObject(porcelainNextPayload, decodedPath)
67
+ );
68
+ if (remainingPayload.length)
69
+ common.merge(nextPayload, remainingPayload);
70
+ }
71
+ nextResult = await next(nextPayload, nextOptions);
65
72
  remainingNextResult = common.remove(nextResult, path) || [];
66
73
  return common.unwrapObject(common.decodeGraph(nextResult), decodedPath);
67
74
  }
68
75
  const porcelainResult = await fn(porcelainPayload, options, shiftedNext);
69
- let result = common.encodeGraph(common.wrapObject(porcelainResult, decodedPath));
70
- if (isRead && !nextCalled) {
71
- const appliedQuery = common.wrap(common.unwrap(payload, path), path);
72
- result = common.finalize(result, appliedQuery);
73
- result = common.wrap(common.unwrap(result, path), path);
74
- }
75
- if (!nextCalled && remainingPayload.length) {
76
- remainingNextResult = await next(remainingPayload);
77
- }
78
- if (remainingNextResult == null ? void 0 : remainingNextResult.length) {
79
- common.merge(result, remainingNextResult);
76
+ let result;
77
+ if (porcelainResult === unchanged) {
78
+ result = nextResult;
79
+ } else {
80
+ result = common.encodeGraph(common.wrapObject(porcelainResult, decodedPath));
81
+ if (isRead && !nextCalled) {
82
+ const appliedQuery = common.wrap(common.unwrap(payload, path), path);
83
+ result = common.finalize(result, appliedQuery);
84
+ result = common.wrap(common.unwrap(result, path), path);
85
+ }
86
+ if (!nextCalled && remainingPayload.length) {
87
+ remainingNextResult = await next(remainingPayload);
88
+ }
89
+ if (remainingNextResult == null ? void 0 : remainingNextResult.length) {
90
+ common.merge(result, remainingNextResult);
91
+ }
80
92
  }
81
93
  return result;
82
94
  };
@@ -237,4 +249,5 @@ class Graffy {
237
249
  return common.unwrapObject(common.decodeGraph(writtenChange), path);
238
250
  }
239
251
  }
252
+ Graffy.unchanged = unchanged;
240
253
  module.exports = Graffy;
package/index.mjs CHANGED
@@ -44,38 +44,50 @@ async function mapStream(stream, fn) {
44
44
  fn(value);
45
45
  }
46
46
  }
47
+ const unchanged = Symbol("Payload or result unchanged by handler");
47
48
  function wrapProvider(fn, decodedPath, isRead) {
48
49
  const decodePayload = isRead ? decodeQuery : decodeGraph;
49
50
  const encodePayload = isRead ? encodeQuery : encodeGraph;
50
51
  const path = encodePath(decodedPath);
51
52
  return async function wrappedProvider(payload, options, next) {
52
53
  let nextCalled = false;
54
+ let nextResult;
53
55
  let remainingNextResult;
54
56
  const porcelainPayload = unwrapObject(decodePayload(payload), decodedPath);
55
57
  const remainingPayload = remove(payload, path) || [];
56
58
  async function shiftedNext(porcelainNextPayload, nextOptions) {
57
59
  nextCalled = true;
58
- const nextPayload = encodePayload(
59
- wrapObject(porcelainNextPayload, decodedPath)
60
- );
61
- if (remainingPayload.length)
62
- merge(nextPayload, remainingPayload);
63
- const nextResult = await next(nextPayload, nextOptions);
60
+ let nextPayload;
61
+ if (porcelainNextPayload === unchanged) {
62
+ nextPayload = payload;
63
+ } else {
64
+ nextPayload = encodePayload(
65
+ wrapObject(porcelainNextPayload, decodedPath)
66
+ );
67
+ if (remainingPayload.length)
68
+ merge(nextPayload, remainingPayload);
69
+ }
70
+ nextResult = await next(nextPayload, nextOptions);
64
71
  remainingNextResult = remove(nextResult, path) || [];
65
72
  return unwrapObject(decodeGraph(nextResult), decodedPath);
66
73
  }
67
74
  const porcelainResult = await fn(porcelainPayload, options, shiftedNext);
68
- let result = encodeGraph(wrapObject(porcelainResult, decodedPath));
69
- if (isRead && !nextCalled) {
70
- const appliedQuery = wrap(unwrap(payload, path), path);
71
- result = finalize(result, appliedQuery);
72
- result = wrap(unwrap(result, path), path);
73
- }
74
- if (!nextCalled && remainingPayload.length) {
75
- remainingNextResult = await next(remainingPayload);
76
- }
77
- if (remainingNextResult == null ? void 0 : remainingNextResult.length) {
78
- merge(result, remainingNextResult);
75
+ let result;
76
+ if (porcelainResult === unchanged) {
77
+ result = nextResult;
78
+ } else {
79
+ result = encodeGraph(wrapObject(porcelainResult, decodedPath));
80
+ if (isRead && !nextCalled) {
81
+ const appliedQuery = wrap(unwrap(payload, path), path);
82
+ result = finalize(result, appliedQuery);
83
+ result = wrap(unwrap(result, path), path);
84
+ }
85
+ if (!nextCalled && remainingPayload.length) {
86
+ remainingNextResult = await next(remainingPayload);
87
+ }
88
+ if (remainingNextResult == null ? void 0 : remainingNextResult.length) {
89
+ merge(result, remainingNextResult);
90
+ }
79
91
  }
80
92
  return result;
81
93
  };
@@ -236,6 +248,7 @@ class Graffy {
236
248
  return unwrapObject(decodeGraph(writtenChange), path);
237
249
  }
238
250
  }
251
+ Graffy.unchanged = unchanged;
239
252
  export {
240
253
  Graffy as default
241
254
  };
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.11",
5
+ "version": "0.16.12-alpha.2",
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.11",
20
- "@graffy/stream": "0.16.11",
19
+ "@graffy/common": "0.16.12-alpha.2",
20
+ "@graffy/stream": "0.16.12-alpha.2",
21
21
  "debug": "^4.3.3"
22
22
  }
23
23
  }
package/types/Graffy.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export default class Graffy {
1
+ export { unchanged } from "./shift.js";
2
+ declare class Graffy {
2
3
  constructor(path?: any[], core?: Core);
3
4
  core: Core;
4
5
  path: any[];
@@ -12,4 +13,9 @@ export default class Graffy {
12
13
  watch(...args: any[]): any;
13
14
  write(...args: any[]): Promise<any>;
14
15
  }
16
+ declare namespace Graffy {
17
+ export { unchanged };
18
+ }
19
+ export default Graffy;
15
20
  import Core from "./Core.js";
21
+ import { unchanged } from "./shift.js";
package/types/shift.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export function wrapProvider(fn: any, decodedPath: any, isRead: any): (payload: any, options: any, next: any) => Promise<any>;
2
2
  export function shiftGen(fn: any, path: any): (payload: any, options: any, next: any) => AsyncGenerator<any, void, any>;
3
+ export const unchanged: unique symbol;