@graffy/core 0.16.10-alpha.1 → 0.16.11

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 +64 -62
  2. package/index.mjs +65 -63
  3. package/package.json +3 -3
package/index.cjs CHANGED
@@ -2,40 +2,43 @@
2
2
  const common = require("@graffy/common");
3
3
  const stream = require("@graffy/stream");
4
4
  const debug = require("debug");
5
- const splitPath = (path) => Array.isArray(path) ? path : path === "" ? [] : String(path).split(".");
6
- function validateCall(...args) {
7
- if (args.length === 1) {
8
- return [[], args[0], {}];
9
- } else if (args.length === 2) {
10
- if (common.isPlainObject(args[0])) {
11
- if (!common.isPlainObject(args[1])) {
12
- throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
13
- }
14
- return [[], args[0], args[1]];
15
- } else {
16
- return [splitPath(args[0]), args[1], {}];
5
+ const log = debug("graffy:core");
6
+ function resolve(handlers, firstPayload, firstOptions) {
7
+ if (!(handlers == null ? void 0 : handlers.length))
8
+ throw Error("resolve.no_provider");
9
+ function run(i, payload, options) {
10
+ if (i >= handlers.length) {
11
+ throw Error(`resolve.no_providers_for ${JSON.stringify(payload)}`);
17
12
  }
18
- } else if (args.length === 3) {
19
- if (!common.isPlainObject(args[2])) {
20
- throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
13
+ const { path, handle } = handlers[i];
14
+ if (!common.unwrap(payload, path)) {
15
+ return run(i + 1, payload, options);
21
16
  }
22
- return [splitPath(args[0]), args[1], args[2]];
17
+ let nextCalled = false;
18
+ return handle(payload, options, (nextPayload, nextOptions) => {
19
+ if (nextCalled) {
20
+ throw Error(`resolve.duplicate_next_call: ${handlers[i].name}`);
21
+ }
22
+ nextCalled = true;
23
+ if (typeof nextPayload === "undefined" || !nextPayload.length)
24
+ return;
25
+ return run(i + 1, nextPayload, nextOptions || options);
26
+ });
23
27
  }
24
- throw Error(`validateCall.invalid_args: ${JSON.stringify(args)}`);
28
+ return run(0, firstPayload, firstOptions);
25
29
  }
26
- function validateOn(...args) {
27
- if (args.length === 1) {
28
- if (typeof args[0] !== "function") {
29
- throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[0])}`);
30
- }
31
- return [[], args[0]];
32
- } else if (args.length === 2) {
33
- if (typeof args[1] !== "function") {
34
- throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[1])}`);
35
- }
36
- return [splitPath(args[0]), args[1]];
30
+ class Core {
31
+ constructor() {
32
+ this.handlers = {};
33
+ }
34
+ on(type, path, handle) {
35
+ this.handlers[type] = this.handlers[type] || [];
36
+ this.handlers[type].push({ path: common.encodePath(path), handle });
37
+ }
38
+ call(type, payload, options = {}) {
39
+ log("call", type, payload);
40
+ return resolve(this.handlers[type], payload, options);
37
41
  }
38
- throw Error(`validateOn.invalid_args: ${JSON.stringify(args)}`);
39
42
  }
40
43
  async function mapStream(stream2, fn) {
41
44
  for await (const value of stream2) {
@@ -118,43 +121,42 @@ function shiftGen(fn, path) {
118
121
  yield* remainingNextStream ? common.mergeStreams(resultStream, remainingNextStream) : resultStream;
119
122
  };
120
123
  }
121
- const log = debug("graffy:core");
122
- function resolve(handlers, firstPayload, firstOptions) {
123
- if (!(handlers == null ? void 0 : handlers.length))
124
- throw Error("resolve.no_provider");
125
- function run(i, payload, options) {
126
- if (i >= handlers.length) {
127
- throw Error(`resolve.no_providers_for ${JSON.stringify(payload)}`);
124
+ const splitPath = (path) => Array.isArray(path) ? path : path === "" ? [] : String(path).split(".");
125
+ function validateCall(...args) {
126
+ if (args.length === 1) {
127
+ return [[], args[0], {}];
128
+ }
129
+ if (args.length === 2) {
130
+ if (common.isPlainObject(args[0])) {
131
+ if (!common.isPlainObject(args[1])) {
132
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
133
+ }
134
+ return [[], args[0], args[1]];
128
135
  }
129
- const { path, handle } = handlers[i];
130
- if (!common.unwrap(payload, path)) {
131
- return run(i + 1, payload, options);
136
+ return [splitPath(args[0]), args[1], {}];
137
+ }
138
+ if (args.length === 3) {
139
+ if (!common.isPlainObject(args[2])) {
140
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
132
141
  }
133
- let nextCalled = false;
134
- return handle(payload, options, (nextPayload, nextOptions) => {
135
- if (nextCalled) {
136
- throw Error(`resolve.duplicate_next_call: ${handlers[i].name}`);
137
- }
138
- nextCalled = true;
139
- if (typeof nextPayload === "undefined" || !nextPayload.length)
140
- return;
141
- return run(i + 1, nextPayload, nextOptions || options);
142
- });
142
+ return [splitPath(args[0]), args[1], args[2]];
143
143
  }
144
- return run(0, firstPayload, firstOptions);
144
+ throw Error(`validateCall.invalid_args: ${JSON.stringify(args)}`);
145
145
  }
146
- class Core {
147
- constructor() {
148
- this.handlers = {};
149
- }
150
- on(type, path, handle) {
151
- this.handlers[type] = this.handlers[type] || [];
152
- this.handlers[type].push({ path: common.encodePath(path), handle });
146
+ function validateOn(...args) {
147
+ if (args.length === 1) {
148
+ if (typeof args[0] !== "function") {
149
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[0])}`);
150
+ }
151
+ return [[], args[0]];
153
152
  }
154
- call(type, payload, options = {}) {
155
- log("call", type, payload);
156
- return resolve(this.handlers[type], payload, options);
153
+ if (args.length === 2) {
154
+ if (typeof args[1] !== "function") {
155
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[1])}`);
156
+ }
157
+ return [splitPath(args[0]), args[1]];
157
158
  }
159
+ throw Error(`validateOn.invalid_args: ${JSON.stringify(args)}`);
158
160
  }
159
161
  class Graffy {
160
162
  constructor(path = [], core = new Core()) {
@@ -182,9 +184,9 @@ class Graffy {
182
184
  const subscription = handle(common.decodeQuery(query), options, () => {
183
185
  throw Error(`porcelain.watch_next_unsupported: ${path}`);
184
186
  });
185
- (async function() {
187
+ (async () => {
186
188
  try {
187
- let firstValue = (await subscription.next()).value;
189
+ const firstValue = (await subscription.next()).value;
188
190
  push(firstValue && common.finalize(common.encodeGraph(firstValue), query));
189
191
  for await (const value of subscription) {
190
192
  push(value && common.encodeGraph(value));
package/index.mjs CHANGED
@@ -1,40 +1,43 @@
1
- import { isPlainObject, encodePath, unwrapObject, remove, encodeGraph, wrapObject, wrap, unwrap, finalize, merge, mergeStreams, decodeQuery, decodeGraph, encodeQuery, decorate } from "@graffy/common";
1
+ import { encodePath, unwrap, unwrapObject, remove, encodeGraph, wrapObject, wrap, finalize, merge, mergeStreams, decodeQuery, decodeGraph, encodeQuery, isPlainObject, decorate } from "@graffy/common";
2
2
  import { makeStream, mapStream as mapStream$1 } from "@graffy/stream";
3
3
  import debug from "debug";
4
- const splitPath = (path) => Array.isArray(path) ? path : path === "" ? [] : String(path).split(".");
5
- function validateCall(...args) {
6
- if (args.length === 1) {
7
- return [[], args[0], {}];
8
- } else if (args.length === 2) {
9
- if (isPlainObject(args[0])) {
10
- if (!isPlainObject(args[1])) {
11
- throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
12
- }
13
- return [[], args[0], args[1]];
14
- } else {
15
- return [splitPath(args[0]), args[1], {}];
4
+ const log = debug("graffy:core");
5
+ function resolve(handlers, firstPayload, firstOptions) {
6
+ if (!(handlers == null ? void 0 : handlers.length))
7
+ throw Error("resolve.no_provider");
8
+ function run(i, payload, options) {
9
+ if (i >= handlers.length) {
10
+ throw Error(`resolve.no_providers_for ${JSON.stringify(payload)}`);
16
11
  }
17
- } else if (args.length === 3) {
18
- if (!isPlainObject(args[2])) {
19
- throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
12
+ const { path, handle } = handlers[i];
13
+ if (!unwrap(payload, path)) {
14
+ return run(i + 1, payload, options);
20
15
  }
21
- return [splitPath(args[0]), args[1], args[2]];
16
+ let nextCalled = false;
17
+ return handle(payload, options, (nextPayload, nextOptions) => {
18
+ if (nextCalled) {
19
+ throw Error(`resolve.duplicate_next_call: ${handlers[i].name}`);
20
+ }
21
+ nextCalled = true;
22
+ if (typeof nextPayload === "undefined" || !nextPayload.length)
23
+ return;
24
+ return run(i + 1, nextPayload, nextOptions || options);
25
+ });
22
26
  }
23
- throw Error(`validateCall.invalid_args: ${JSON.stringify(args)}`);
27
+ return run(0, firstPayload, firstOptions);
24
28
  }
25
- function validateOn(...args) {
26
- if (args.length === 1) {
27
- if (typeof args[0] !== "function") {
28
- throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[0])}`);
29
- }
30
- return [[], args[0]];
31
- } else if (args.length === 2) {
32
- if (typeof args[1] !== "function") {
33
- throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[1])}`);
34
- }
35
- return [splitPath(args[0]), args[1]];
29
+ class Core {
30
+ constructor() {
31
+ this.handlers = {};
32
+ }
33
+ on(type, path, handle) {
34
+ this.handlers[type] = this.handlers[type] || [];
35
+ this.handlers[type].push({ path: encodePath(path), handle });
36
+ }
37
+ call(type, payload, options = {}) {
38
+ log("call", type, payload);
39
+ return resolve(this.handlers[type], payload, options);
36
40
  }
37
- throw Error(`validateOn.invalid_args: ${JSON.stringify(args)}`);
38
41
  }
39
42
  async function mapStream(stream, fn) {
40
43
  for await (const value of stream) {
@@ -117,43 +120,42 @@ function shiftGen(fn, path) {
117
120
  yield* remainingNextStream ? mergeStreams(resultStream, remainingNextStream) : resultStream;
118
121
  };
119
122
  }
120
- const log = debug("graffy:core");
121
- function resolve(handlers, firstPayload, firstOptions) {
122
- if (!(handlers == null ? void 0 : handlers.length))
123
- throw Error("resolve.no_provider");
124
- function run(i, payload, options) {
125
- if (i >= handlers.length) {
126
- throw Error(`resolve.no_providers_for ${JSON.stringify(payload)}`);
123
+ const splitPath = (path) => Array.isArray(path) ? path : path === "" ? [] : String(path).split(".");
124
+ function validateCall(...args) {
125
+ if (args.length === 1) {
126
+ return [[], args[0], {}];
127
+ }
128
+ if (args.length === 2) {
129
+ if (isPlainObject(args[0])) {
130
+ if (!isPlainObject(args[1])) {
131
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
132
+ }
133
+ return [[], args[0], args[1]];
127
134
  }
128
- const { path, handle } = handlers[i];
129
- if (!unwrap(payload, path)) {
130
- return run(i + 1, payload, options);
135
+ return [splitPath(args[0]), args[1], {}];
136
+ }
137
+ if (args.length === 3) {
138
+ if (!isPlainObject(args[2])) {
139
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
131
140
  }
132
- let nextCalled = false;
133
- return handle(payload, options, (nextPayload, nextOptions) => {
134
- if (nextCalled) {
135
- throw Error(`resolve.duplicate_next_call: ${handlers[i].name}`);
136
- }
137
- nextCalled = true;
138
- if (typeof nextPayload === "undefined" || !nextPayload.length)
139
- return;
140
- return run(i + 1, nextPayload, nextOptions || options);
141
- });
141
+ return [splitPath(args[0]), args[1], args[2]];
142
142
  }
143
- return run(0, firstPayload, firstOptions);
143
+ throw Error(`validateCall.invalid_args: ${JSON.stringify(args)}`);
144
144
  }
145
- class Core {
146
- constructor() {
147
- this.handlers = {};
148
- }
149
- on(type, path, handle) {
150
- this.handlers[type] = this.handlers[type] || [];
151
- this.handlers[type].push({ path: encodePath(path), handle });
145
+ function validateOn(...args) {
146
+ if (args.length === 1) {
147
+ if (typeof args[0] !== "function") {
148
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[0])}`);
149
+ }
150
+ return [[], args[0]];
152
151
  }
153
- call(type, payload, options = {}) {
154
- log("call", type, payload);
155
- return resolve(this.handlers[type], payload, options);
152
+ if (args.length === 2) {
153
+ if (typeof args[1] !== "function") {
154
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[1])}`);
155
+ }
156
+ return [splitPath(args[0]), args[1]];
156
157
  }
158
+ throw Error(`validateOn.invalid_args: ${JSON.stringify(args)}`);
157
159
  }
158
160
  class Graffy {
159
161
  constructor(path = [], core = new Core()) {
@@ -181,9 +183,9 @@ class Graffy {
181
183
  const subscription = handle(decodeQuery(query), options, () => {
182
184
  throw Error(`porcelain.watch_next_unsupported: ${path}`);
183
185
  });
184
- (async function() {
186
+ (async () => {
185
187
  try {
186
- let firstValue = (await subscription.next()).value;
188
+ const firstValue = (await subscription.next()).value;
187
189
  push(firstValue && finalize(encodeGraph(firstValue), query));
188
190
  for await (const value of subscription) {
189
191
  push(value && encodeGraph(value));
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.10-alpha.1",
5
+ "version": "0.16.11",
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.10-alpha.1",
20
- "@graffy/stream": "0.16.10-alpha.1",
19
+ "@graffy/common": "0.16.11",
20
+ "@graffy/stream": "0.16.11",
21
21
  "debug": "^4.3.3"
22
22
  }
23
23
  }