@graffy/core 0.15.25-alpha.1 → 0.15.25-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.
Files changed (3) hide show
  1. package/index.cjs +47 -34
  2. package/index.mjs +45 -28
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
- var common = require("@graffy/common");
3
- var stream = require("@graffy/stream");
4
- var debug = require("debug");
5
- function _interopDefaultLegacy(e) {
6
- return e && typeof e === "object" && "default" in e ? e : { "default": e };
7
- }
8
- var debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
2
+ const common = require("@graffy/common");
3
+ const stream = require("@graffy/stream");
4
+ const debug = require("debug");
5
+ const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
6
+ const debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
9
7
  function isPlainObject(obj) {
10
8
  return obj && typeof obj === "object" && !Array.isArray(obj);
11
9
  }
@@ -113,7 +111,7 @@ function shiftGen(fn, path) {
113
111
  yield* remainingNextStream ? common.mergeStreams(resultStream, remainingNextStream) : resultStream;
114
112
  };
115
113
  }
116
- const log = debug__default["default"]("graffy:core");
114
+ const log = debug__default.default("graffy:core");
117
115
  function resolve(handlers, firstPayload, firstOptions) {
118
116
  if (!handlers || !handlers.length)
119
117
  throw Error("resolve.no_provider");
@@ -163,40 +161,52 @@ class Graffy {
163
161
  onRead(...args) {
164
162
  const [pathArg, handle] = validateOn(...args);
165
163
  const path = this.path.concat(pathArg);
166
- this.core.on("read", path, shiftFn(async function porcelainRead(query, options) {
167
- const decoded = common.decodeQuery(query);
168
- const encoded = common.encodeGraph(await handle(decoded, options));
169
- const finalized = common.finalize(encoded, query);
170
- return finalized;
171
- }, path));
164
+ this.core.on(
165
+ "read",
166
+ path,
167
+ shiftFn(async function porcelainRead(query, options) {
168
+ const decoded = common.decodeQuery(query);
169
+ const encoded = common.encodeGraph(await handle(decoded, options));
170
+ const finalized = common.finalize(encoded, query);
171
+ return finalized;
172
+ }, path)
173
+ );
172
174
  }
173
175
  onWatch(...args) {
174
176
  const [pathArg, handle] = validateOn(...args);
175
177
  const path = this.path.concat(pathArg);
176
- this.core.on("watch", path, shiftGen(function porcelainWatch(query, options) {
177
- return stream.makeStream((push, end) => {
178
- const subscription = handle(common.decodeQuery(query), options);
179
- (async function() {
180
- try {
181
- let firstValue = (await subscription.next()).value;
182
- push(firstValue && common.finalize(common.encodeGraph(firstValue), query));
183
- for await (const value of subscription) {
184
- push(value && common.encodeGraph(value));
178
+ this.core.on(
179
+ "watch",
180
+ path,
181
+ shiftGen(function porcelainWatch(query, options) {
182
+ return stream.makeStream((push, end) => {
183
+ const subscription = handle(common.decodeQuery(query), options);
184
+ (async function() {
185
+ try {
186
+ let firstValue = (await subscription.next()).value;
187
+ push(firstValue && common.finalize(common.encodeGraph(firstValue), query));
188
+ for await (const value of subscription) {
189
+ push(value && common.encodeGraph(value));
190
+ }
191
+ } catch (e) {
192
+ end(e);
185
193
  }
186
- } catch (e) {
187
- end(e);
188
- }
189
- })();
190
- return () => subscription.return();
191
- });
192
- }, path));
194
+ })();
195
+ return () => subscription.return();
196
+ });
197
+ }, path)
198
+ );
193
199
  }
194
200
  onWrite(...args) {
195
201
  const [pathArg, handle] = validateOn(...args);
196
202
  const path = this.path.concat(pathArg);
197
- this.core.on("write", path, shiftFn(async function porcelainWrite(change, options) {
198
- return common.encodeGraph(await handle(common.decodeGraph(change), options));
199
- }, path));
203
+ this.core.on(
204
+ "write",
205
+ path,
206
+ shiftFn(async function porcelainWrite(change, options) {
207
+ return common.encodeGraph(await handle(common.decodeGraph(change), options));
208
+ }, path)
209
+ );
200
210
  }
201
211
  use(...args) {
202
212
  const [pathArg, provider] = validateOn(...args);
@@ -218,7 +228,10 @@ class Graffy {
218
228
  const rootQuery = common.wrapObject(porcelainQuery, path);
219
229
  const query = common.encodeQuery(rootQuery);
220
230
  const stream$1 = this.core.call("watch", query, options || {});
221
- return stream.mapStream(stream$1, (value) => common.unwrapObject(common.decorate(value, rootQuery), common.decodePath(path)));
231
+ return stream.mapStream(
232
+ stream$1,
233
+ (value) => common.unwrapObject(common.decorate(value, rootQuery), common.decodePath(path))
234
+ );
222
235
  }
223
236
  async write(...args) {
224
237
  const [path, porcelainChange, options] = validateCall(...args);
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { encodePath, unwrap, remove, wrap, merge, mergeStreams, encodeGraph, decodeGraph, wrapObject, encodeQuery, unwrapObject, decorate, decodePath, decodeQuery, finalize } from "@graffy/common";
1
+ import { encodePath, unwrap, remove, wrap, merge, mergeStreams, wrapObject, encodeQuery, unwrapObject, decorate, decodePath, encodeGraph, decodeGraph, decodeQuery, finalize } from "@graffy/common";
2
2
  import { makeStream, mapStream as mapStream$1 } from "@graffy/stream";
3
3
  import debug from "debug";
4
4
  function isPlainObject(obj) {
@@ -158,40 +158,52 @@ class Graffy {
158
158
  onRead(...args) {
159
159
  const [pathArg, handle] = validateOn(...args);
160
160
  const path = this.path.concat(pathArg);
161
- this.core.on("read", path, shiftFn(async function porcelainRead(query, options) {
162
- const decoded = decodeQuery(query);
163
- const encoded = encodeGraph(await handle(decoded, options));
164
- const finalized = finalize(encoded, query);
165
- return finalized;
166
- }, path));
161
+ this.core.on(
162
+ "read",
163
+ path,
164
+ shiftFn(async function porcelainRead(query, options) {
165
+ const decoded = decodeQuery(query);
166
+ const encoded = encodeGraph(await handle(decoded, options));
167
+ const finalized = finalize(encoded, query);
168
+ return finalized;
169
+ }, path)
170
+ );
167
171
  }
168
172
  onWatch(...args) {
169
173
  const [pathArg, handle] = validateOn(...args);
170
174
  const path = this.path.concat(pathArg);
171
- this.core.on("watch", path, shiftGen(function porcelainWatch(query, options) {
172
- return makeStream((push, end) => {
173
- const subscription = handle(decodeQuery(query), options);
174
- (async function() {
175
- try {
176
- let firstValue = (await subscription.next()).value;
177
- push(firstValue && finalize(encodeGraph(firstValue), query));
178
- for await (const value of subscription) {
179
- push(value && encodeGraph(value));
175
+ this.core.on(
176
+ "watch",
177
+ path,
178
+ shiftGen(function porcelainWatch(query, options) {
179
+ return makeStream((push, end) => {
180
+ const subscription = handle(decodeQuery(query), options);
181
+ (async function() {
182
+ try {
183
+ let firstValue = (await subscription.next()).value;
184
+ push(firstValue && finalize(encodeGraph(firstValue), query));
185
+ for await (const value of subscription) {
186
+ push(value && encodeGraph(value));
187
+ }
188
+ } catch (e) {
189
+ end(e);
180
190
  }
181
- } catch (e) {
182
- end(e);
183
- }
184
- })();
185
- return () => subscription.return();
186
- });
187
- }, path));
191
+ })();
192
+ return () => subscription.return();
193
+ });
194
+ }, path)
195
+ );
188
196
  }
189
197
  onWrite(...args) {
190
198
  const [pathArg, handle] = validateOn(...args);
191
199
  const path = this.path.concat(pathArg);
192
- this.core.on("write", path, shiftFn(async function porcelainWrite(change, options) {
193
- return encodeGraph(await handle(decodeGraph(change), options));
194
- }, path));
200
+ this.core.on(
201
+ "write",
202
+ path,
203
+ shiftFn(async function porcelainWrite(change, options) {
204
+ return encodeGraph(await handle(decodeGraph(change), options));
205
+ }, path)
206
+ );
195
207
  }
196
208
  use(...args) {
197
209
  const [pathArg, provider] = validateOn(...args);
@@ -213,7 +225,10 @@ class Graffy {
213
225
  const rootQuery = wrapObject(porcelainQuery, path);
214
226
  const query = encodeQuery(rootQuery);
215
227
  const stream = this.core.call("watch", query, options || {});
216
- return mapStream$1(stream, (value) => unwrapObject(decorate(value, rootQuery), decodePath(path)));
228
+ return mapStream$1(
229
+ stream,
230
+ (value) => unwrapObject(decorate(value, rootQuery), decodePath(path))
231
+ );
217
232
  }
218
233
  async write(...args) {
219
234
  const [path, porcelainChange, options] = validateCall(...args);
@@ -222,4 +237,6 @@ class Graffy {
222
237
  return unwrapObject(decodeGraph(writtenChange), decodePath(path));
223
238
  }
224
239
  }
225
- export { Graffy as default };
240
+ export {
241
+ Graffy as default
242
+ };
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.15.25-alpha.1",
5
+ "version": "0.15.25-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.15.25-alpha.1",
20
- "@graffy/stream": "0.15.25-alpha.1",
19
+ "@graffy/common": "0.15.25-alpha.2",
20
+ "@graffy/stream": "0.15.25-alpha.2",
21
21
  "debug": "^4.3.3"
22
22
  }
23
23
  }