@graffy/fill 0.16.19 → 0.16.20-alpha.1

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 +13 -26
  2. package/index.mjs +13 -26
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -25,10 +25,8 @@ function subscribe(store, originalQuery, { raw }) {
25
25
  try {
26
26
  const changed = common.add(query, unknown);
27
27
  log$1(changed ? "Resubscribing" : "Not resubscribing", unknown);
28
- if (!changed)
29
- return;
30
- if (upstream)
31
- upstream.return();
28
+ if (!changed) return;
29
+ if (upstream) upstream.return();
32
30
  upstream = store.call("watch", query, { skipFill: true });
33
31
  let { value } = await upstream.next();
34
32
  log$1("First payload", typeof value, value);
@@ -46,15 +44,13 @@ function subscribe(store, originalQuery, { raw }) {
46
44
  async function putStream(stream2) {
47
45
  log$1("Start putting stream");
48
46
  try {
49
- for await (const value of stream2)
50
- putValue(value, true);
47
+ for await (const value of stream2) putValue(value, true);
51
48
  } catch (e) {
52
49
  error(e);
53
50
  }
54
51
  }
55
52
  function putValue(value, isChange) {
56
- if (typeof value === "undefined")
57
- return;
53
+ if (typeof value === "undefined") return;
58
54
  log$1("Put", isChange ? "Change" : "Value", typeof value);
59
55
  if (value === null) {
60
56
  data = empty();
@@ -66,8 +62,7 @@ function subscribe(store, originalQuery, { raw }) {
66
62
  sieved = common.sieve(data, value);
67
63
  } else {
68
64
  sieved = common.slice(value, query).known;
69
- if (sieved)
70
- common.merge(data, sieved);
65
+ if (sieved) common.merge(data, sieved);
71
66
  }
72
67
  log$1("Sieved: ", sieved && sieved);
73
68
  if (raw && sieved) {
@@ -81,29 +76,24 @@ function subscribe(store, originalQuery, { raw }) {
81
76
  const valueParts = common.slice(value, unknown);
82
77
  if (valueParts.known) {
83
78
  common.merge(data, valueParts.known);
84
- if (raw)
85
- common.merge(payload, valueParts.known);
79
+ if (raw) common.merge(payload, valueParts.known);
86
80
  unknown = valueParts.unknown;
87
81
  }
88
82
  }
89
- if (unknown)
90
- return resubscribe(unknown);
83
+ if (unknown) return resubscribe(unknown);
91
84
  if (!raw) {
92
- if (!isChange || (sieved == null ? void 0 : sieved.length))
93
- push(data);
85
+ if (!isChange || (sieved == null ? void 0 : sieved.length)) push(data);
94
86
  } else if (payload.length) {
95
87
  push(payload);
96
88
  payload = [];
97
89
  }
98
90
  }
99
91
  function error(e) {
100
- if (end)
101
- end(e);
92
+ if (end) end(e);
102
93
  unsubscribe();
103
94
  }
104
95
  function unsubscribe() {
105
- if (upstream)
106
- upstream.return();
96
+ if (upstream) upstream.return();
107
97
  }
108
98
  }
109
99
  const log = debug("graffy:fill");
@@ -112,8 +102,7 @@ function fill(_) {
112
102
  return (store) => {
113
103
  store.on("read", [], async function fillOnRead(query, options, next) {
114
104
  let value = await next(query);
115
- if (options.skipFill)
116
- return value;
105
+ if (options.skipFill) return value;
117
106
  if (!(value == null ? void 0 : value.length)) {
118
107
  log("No progress", query);
119
108
  throw Error("fill.no_progress");
@@ -122,8 +111,7 @@ function fill(_) {
122
111
  while (budget-- > 1) {
123
112
  const { known, unknown } = common.slice(value, query);
124
113
  value = known;
125
- if (!unknown)
126
- break;
114
+ if (!unknown) break;
127
115
  const res = await store.call("read", unknown, { skipFill: true });
128
116
  common.merge(value, res);
129
117
  }
@@ -134,8 +122,7 @@ function fill(_) {
134
122
  return value;
135
123
  });
136
124
  store.on("watch", [], function fillOnWatch(query, options, next) {
137
- if (options.skipFill)
138
- return next(query);
125
+ if (options.skipFill) return next(query);
139
126
  return subscribe(store, query, options);
140
127
  });
141
128
  };
package/index.mjs CHANGED
@@ -24,10 +24,8 @@ function subscribe(store, originalQuery, { raw }) {
24
24
  try {
25
25
  const changed = add(query, unknown);
26
26
  log$1(changed ? "Resubscribing" : "Not resubscribing", unknown);
27
- if (!changed)
28
- return;
29
- if (upstream)
30
- upstream.return();
27
+ if (!changed) return;
28
+ if (upstream) upstream.return();
31
29
  upstream = store.call("watch", query, { skipFill: true });
32
30
  let { value } = await upstream.next();
33
31
  log$1("First payload", typeof value, value);
@@ -45,15 +43,13 @@ function subscribe(store, originalQuery, { raw }) {
45
43
  async function putStream(stream2) {
46
44
  log$1("Start putting stream");
47
45
  try {
48
- for await (const value of stream2)
49
- putValue(value, true);
46
+ for await (const value of stream2) putValue(value, true);
50
47
  } catch (e) {
51
48
  error(e);
52
49
  }
53
50
  }
54
51
  function putValue(value, isChange) {
55
- if (typeof value === "undefined")
56
- return;
52
+ if (typeof value === "undefined") return;
57
53
  log$1("Put", isChange ? "Change" : "Value", typeof value);
58
54
  if (value === null) {
59
55
  data = empty();
@@ -65,8 +61,7 @@ function subscribe(store, originalQuery, { raw }) {
65
61
  sieved = sieve(data, value);
66
62
  } else {
67
63
  sieved = slice(value, query).known;
68
- if (sieved)
69
- merge(data, sieved);
64
+ if (sieved) merge(data, sieved);
70
65
  }
71
66
  log$1("Sieved: ", sieved && sieved);
72
67
  if (raw && sieved) {
@@ -80,29 +75,24 @@ function subscribe(store, originalQuery, { raw }) {
80
75
  const valueParts = slice(value, unknown);
81
76
  if (valueParts.known) {
82
77
  merge(data, valueParts.known);
83
- if (raw)
84
- merge(payload, valueParts.known);
78
+ if (raw) merge(payload, valueParts.known);
85
79
  unknown = valueParts.unknown;
86
80
  }
87
81
  }
88
- if (unknown)
89
- return resubscribe(unknown);
82
+ if (unknown) return resubscribe(unknown);
90
83
  if (!raw) {
91
- if (!isChange || (sieved == null ? void 0 : sieved.length))
92
- push(data);
84
+ if (!isChange || (sieved == null ? void 0 : sieved.length)) push(data);
93
85
  } else if (payload.length) {
94
86
  push(payload);
95
87
  payload = [];
96
88
  }
97
89
  }
98
90
  function error(e) {
99
- if (end)
100
- end(e);
91
+ if (end) end(e);
101
92
  unsubscribe();
102
93
  }
103
94
  function unsubscribe() {
104
- if (upstream)
105
- upstream.return();
95
+ if (upstream) upstream.return();
106
96
  }
107
97
  }
108
98
  const log = debug("graffy:fill");
@@ -111,8 +101,7 @@ function fill(_) {
111
101
  return (store) => {
112
102
  store.on("read", [], async function fillOnRead(query, options, next) {
113
103
  let value = await next(query);
114
- if (options.skipFill)
115
- return value;
104
+ if (options.skipFill) return value;
116
105
  if (!(value == null ? void 0 : value.length)) {
117
106
  log("No progress", query);
118
107
  throw Error("fill.no_progress");
@@ -121,8 +110,7 @@ function fill(_) {
121
110
  while (budget-- > 1) {
122
111
  const { known, unknown } = slice(value, query);
123
112
  value = known;
124
- if (!unknown)
125
- break;
113
+ if (!unknown) break;
126
114
  const res = await store.call("read", unknown, { skipFill: true });
127
115
  merge(value, res);
128
116
  }
@@ -133,8 +121,7 @@ function fill(_) {
133
121
  return value;
134
122
  });
135
123
  store.on("watch", [], function fillOnWatch(query, options, next) {
136
- if (options.skipFill)
137
- return next(query);
124
+ if (options.skipFill) return next(query);
138
125
  return subscribe(store, query, options);
139
126
  });
140
127
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/fill",
3
3
  "description": "Graffy module for fulfilling queries using multiple backends, traversing links and turning subscriptions into live queries.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.16.19",
5
+ "version": "0.16.20-alpha.1",
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.19",
20
- "debug": "^4.3.3",
21
- "@graffy/stream": "0.16.19"
19
+ "@graffy/common": "0.16.20-alpha.1",
20
+ "debug": "^4.3.7",
21
+ "@graffy/stream": "0.16.20-alpha.1"
22
22
  }
23
23
  }