@graffy/core 0.15.8-alpha.2 → 0.15.8

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 ADDED
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ var common = require("@graffy/common");
3
+ var stream = require("@graffy/stream");
4
+ var debug = require("debug");
5
+ var testing = require("@graffy/testing");
6
+ function _interopDefaultLegacy(e) {
7
+ return e && typeof e === "object" && "default" in e ? e : { "default": e };
8
+ }
9
+ var debug__default = /* @__PURE__ */ _interopDefaultLegacy(debug);
10
+ function isPlainObject(obj) {
11
+ return obj && typeof obj === "object" && !Array.isArray(obj);
12
+ }
13
+ function validateCall(...args) {
14
+ if (args.length === 1) {
15
+ return [[], args[0], {}];
16
+ } else if (args.length === 2) {
17
+ if (isPlainObject(args[0])) {
18
+ if (!isPlainObject(args[1])) {
19
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
20
+ }
21
+ return [[], args[0], args[1]];
22
+ } else {
23
+ return [common.encodePath(args[0]), args[1], {}];
24
+ }
25
+ } else if (args.length === 3) {
26
+ if (!isPlainObject(args[2])) {
27
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
28
+ }
29
+ return [common.encodePath(args[0]), args[1], args[2]];
30
+ }
31
+ throw Error(`validateCall.invalid_args: ${JSON.stringify(args)}`);
32
+ }
33
+ function validateOn(...args) {
34
+ if (args.length === 1) {
35
+ if (typeof args[0] !== "function") {
36
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[0])}`);
37
+ }
38
+ return [[], args[0]];
39
+ } else if (args.length === 2) {
40
+ if (typeof args[1] !== "function") {
41
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[1])}`);
42
+ }
43
+ return [common.encodePath(args[0]), args[1]];
44
+ }
45
+ throw Error(`validateOn.invalid_args: ${JSON.stringify(args)}`);
46
+ }
47
+ async function mapStream(stream2, fn) {
48
+ for await (const value of stream2) {
49
+ fn(value);
50
+ }
51
+ }
52
+ function shiftFn(fn, path) {
53
+ return async function shiftedFn(payload, options, next) {
54
+ let nextCalled = false;
55
+ let remainingNextResult;
56
+ const unwrappedPayload = common.unwrap(payload, path);
57
+ const remainingPayload = common.remove(payload, path) || [];
58
+ async function shiftedNext(unwrappedNextPayload) {
59
+ nextCalled = true;
60
+ const nextPayload = common.wrap(unwrappedNextPayload, path);
61
+ if (remainingPayload.length)
62
+ common.merge(nextPayload, remainingPayload);
63
+ const nextResult = await next(nextPayload);
64
+ remainingNextResult = common.remove(nextResult, path) || [];
65
+ return common.unwrap(nextResult, path);
66
+ }
67
+ const rawResult = await fn(unwrappedPayload, options, shiftedNext);
68
+ const result = common.wrap(rawResult, path);
69
+ if (!nextCalled && remainingPayload.length) {
70
+ remainingNextResult = await next(remainingPayload);
71
+ }
72
+ if (remainingNextResult && remainingNextResult.length) {
73
+ common.merge(result, remainingNextResult);
74
+ }
75
+ return result;
76
+ };
77
+ }
78
+ function shiftGen(fn, path) {
79
+ return async function* shiftedGen(payload, options, next) {
80
+ let nextCalled = false;
81
+ let remainingNextStream;
82
+ const unwrappedPayload = common.unwrap(payload, path);
83
+ const remainingPayload = common.remove(payload, path) || [];
84
+ const shiftedNext = async function* shiftedNextFn(unwrappedNextPayload) {
85
+ nextCalled = true;
86
+ const nextPayload = common.wrap(unwrappedNextPayload, path);
87
+ if (remainingPayload.length)
88
+ common.merge(nextPayload, remainingPayload);
89
+ let pushRemaining;
90
+ remainingNextStream = stream.makeStream((push) => {
91
+ pushRemaining = push;
92
+ });
93
+ for await (const value of next(nextPayload)) {
94
+ const unwrappedValue = common.unwrap(value, path);
95
+ const remainingValue = common.remove(value, path);
96
+ if (remainingValue)
97
+ pushRemaining(remainingValue);
98
+ if (unwrappedValue)
99
+ yield unwrappedValue;
100
+ }
101
+ };
102
+ const unwrappedStream = fn(unwrappedPayload, options, shiftedNext);
103
+ const firstValue = await (await unwrappedStream.next()).value;
104
+ const resultStream = stream.makeStream((push) => {
105
+ push(common.wrap(firstValue, path));
106
+ mapStream(unwrappedStream, (value) => {
107
+ push(common.wrap(value, path));
108
+ });
109
+ return () => unwrappedStream.return();
110
+ });
111
+ if (!nextCalled && remainingPayload.length) {
112
+ remainingNextStream = next(remainingPayload);
113
+ }
114
+ yield* remainingNextStream ? common.mergeStreams(resultStream, remainingNextStream) : resultStream;
115
+ };
116
+ }
117
+ const log = debug__default["default"]("graffy:core");
118
+ function resolve(handlers, firstPayload, options) {
119
+ if (!handlers || !handlers.length)
120
+ throw Error("resolve.no_provider");
121
+ function run(i, payload) {
122
+ if (i >= handlers.length) {
123
+ throw Error("resolve.no_providers_for " + JSON.stringify(payload));
124
+ }
125
+ const { path, handle } = handlers[i];
126
+ if (!common.unwrap(payload, path))
127
+ return run(i + 1, payload);
128
+ let nextCalled = false;
129
+ return handle(payload, options, (nextPayload) => {
130
+ if (nextCalled) {
131
+ throw Error("resolve.duplicate_next_call: " + handlers[i].name);
132
+ }
133
+ if (typeof nextPayload === "undefined") {
134
+ throw Error("resolve.next_without_payload: " + handlers[i].name);
135
+ }
136
+ nextCalled = true;
137
+ return run(i + 1, nextPayload);
138
+ });
139
+ }
140
+ return run(0, firstPayload);
141
+ }
142
+ class Core {
143
+ constructor() {
144
+ this.handlers = {};
145
+ }
146
+ on(type, path, handle) {
147
+ this.handlers[type] = this.handlers[type] || [];
148
+ this.handlers[type].push({ path, handle });
149
+ }
150
+ call(type, payload, options = {}) {
151
+ log("call", type, testing.format(payload));
152
+ return resolve(this.handlers[type], payload, options);
153
+ }
154
+ }
155
+ class Graffy {
156
+ constructor(path = [], core = new Core()) {
157
+ this.core = core;
158
+ this.path = path;
159
+ }
160
+ on(type, ...args) {
161
+ const [pathArg, handler] = validateOn(...args);
162
+ const path = this.path.concat(pathArg);
163
+ this.core.on(type, path, handler);
164
+ }
165
+ onRead(...args) {
166
+ const [pathArg, handle] = validateOn(...args);
167
+ const path = this.path.concat(pathArg);
168
+ this.core.on("read", path, shiftFn(async function porcelainRead(query, options) {
169
+ const decoded = common.decodeQuery(query);
170
+ const encoded = common.encodeGraph(await handle(decoded, options));
171
+ const finalized = common.finalize(encoded, query);
172
+ return finalized;
173
+ }, path));
174
+ }
175
+ onWatch(...args) {
176
+ const [pathArg, handle] = validateOn(...args);
177
+ const path = this.path.concat(pathArg);
178
+ this.core.on("watch", path, shiftGen(function porcelainWatch(query, options) {
179
+ return stream.makeStream((push, end) => {
180
+ const subscription = handle(common.decodeQuery(query), options);
181
+ (async function() {
182
+ try {
183
+ let firstValue = (await subscription.next()).value;
184
+ push(firstValue && common.finalize(common.encodeGraph(firstValue), query));
185
+ for await (const value of subscription) {
186
+ push(value && common.encodeGraph(value));
187
+ }
188
+ } catch (e) {
189
+ end(e);
190
+ }
191
+ })();
192
+ return () => subscription.return();
193
+ });
194
+ }, path));
195
+ }
196
+ onWrite(...args) {
197
+ const [pathArg, handle] = validateOn(...args);
198
+ const path = this.path.concat(pathArg);
199
+ this.core.on("write", path, shiftFn(async function porcelainWrite(change, options) {
200
+ return common.encodeGraph(await handle(common.decodeGraph(change), options));
201
+ }, path));
202
+ }
203
+ use(...args) {
204
+ const [path, provider] = validateOn(...args);
205
+ provider(new Graffy(path, this.core));
206
+ }
207
+ call(type, payload, options = {}) {
208
+ return this.core.call(type, payload, options);
209
+ }
210
+ async read(...args) {
211
+ const [path, porcelainQuery, options] = validateCall(...args);
212
+ const rootQuery = common.wrapObject(porcelainQuery, path);
213
+ const query = common.encodeQuery(rootQuery);
214
+ const result = await this.core.call("read", query, options || {});
215
+ return common.unwrapObject(common.decorate(result, rootQuery), common.decodePath(path));
216
+ }
217
+ watch(...args) {
218
+ const [path, porcelainQuery, options] = validateCall(...args);
219
+ const rootQuery = common.wrapObject(porcelainQuery, path);
220
+ const query = common.encodeQuery(rootQuery);
221
+ const stream$1 = this.core.call("watch", query, options || {});
222
+ return stream.mapStream(stream$1, (value) => common.unwrapObject(common.decorate(value, rootQuery), common.decodePath(path)));
223
+ }
224
+ async write(...args) {
225
+ const [path, porcelainChange, options] = validateCall(...args);
226
+ const change = common.wrap(common.encodeGraph(porcelainChange), path);
227
+ const writtenChange = await this.core.call("write", change, options || {});
228
+ return common.unwrapObject(common.decodeGraph(writtenChange), common.decodePath(path));
229
+ }
230
+ }
231
+ module.exports = Graffy;
package/index.mjs ADDED
@@ -0,0 +1,226 @@
1
+ import { encodePath, unwrap, remove, wrap, merge, mergeStreams, encodeGraph, decodeGraph, wrapObject, encodeQuery, unwrapObject, decorate, decodePath, decodeQuery, finalize } from "@graffy/common";
2
+ import { makeStream, mapStream as mapStream$1 } from "@graffy/stream";
3
+ import debug from "debug";
4
+ import { format } from "@graffy/testing";
5
+ function isPlainObject(obj) {
6
+ return obj && typeof obj === "object" && !Array.isArray(obj);
7
+ }
8
+ function validateCall(...args) {
9
+ if (args.length === 1) {
10
+ return [[], args[0], {}];
11
+ } else if (args.length === 2) {
12
+ if (isPlainObject(args[0])) {
13
+ if (!isPlainObject(args[1])) {
14
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
15
+ }
16
+ return [[], args[0], args[1]];
17
+ } else {
18
+ return [encodePath(args[0]), args[1], {}];
19
+ }
20
+ } else if (args.length === 3) {
21
+ if (!isPlainObject(args[2])) {
22
+ throw Error(`validateCall.invalid_options: ${JSON.stringify(args[1])}`);
23
+ }
24
+ return [encodePath(args[0]), args[1], args[2]];
25
+ }
26
+ throw Error(`validateCall.invalid_args: ${JSON.stringify(args)}`);
27
+ }
28
+ function validateOn(...args) {
29
+ if (args.length === 1) {
30
+ if (typeof args[0] !== "function") {
31
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[0])}`);
32
+ }
33
+ return [[], args[0]];
34
+ } else if (args.length === 2) {
35
+ if (typeof args[1] !== "function") {
36
+ throw Error(`validateOn.invalid_handler: ${JSON.stringify(args[1])}`);
37
+ }
38
+ return [encodePath(args[0]), args[1]];
39
+ }
40
+ throw Error(`validateOn.invalid_args: ${JSON.stringify(args)}`);
41
+ }
42
+ async function mapStream(stream, fn) {
43
+ for await (const value of stream) {
44
+ fn(value);
45
+ }
46
+ }
47
+ function shiftFn(fn, path) {
48
+ return async function shiftedFn(payload, options, next) {
49
+ let nextCalled = false;
50
+ let remainingNextResult;
51
+ const unwrappedPayload = unwrap(payload, path);
52
+ const remainingPayload = remove(payload, path) || [];
53
+ async function shiftedNext(unwrappedNextPayload) {
54
+ nextCalled = true;
55
+ const nextPayload = wrap(unwrappedNextPayload, path);
56
+ if (remainingPayload.length)
57
+ merge(nextPayload, remainingPayload);
58
+ const nextResult = await next(nextPayload);
59
+ remainingNextResult = remove(nextResult, path) || [];
60
+ return unwrap(nextResult, path);
61
+ }
62
+ const rawResult = await fn(unwrappedPayload, options, shiftedNext);
63
+ const result = wrap(rawResult, path);
64
+ if (!nextCalled && remainingPayload.length) {
65
+ remainingNextResult = await next(remainingPayload);
66
+ }
67
+ if (remainingNextResult && remainingNextResult.length) {
68
+ merge(result, remainingNextResult);
69
+ }
70
+ return result;
71
+ };
72
+ }
73
+ function shiftGen(fn, path) {
74
+ return async function* shiftedGen(payload, options, next) {
75
+ let nextCalled = false;
76
+ let remainingNextStream;
77
+ const unwrappedPayload = unwrap(payload, path);
78
+ const remainingPayload = remove(payload, path) || [];
79
+ const shiftedNext = async function* shiftedNextFn(unwrappedNextPayload) {
80
+ nextCalled = true;
81
+ const nextPayload = wrap(unwrappedNextPayload, path);
82
+ if (remainingPayload.length)
83
+ merge(nextPayload, remainingPayload);
84
+ let pushRemaining;
85
+ remainingNextStream = makeStream((push) => {
86
+ pushRemaining = push;
87
+ });
88
+ for await (const value of next(nextPayload)) {
89
+ const unwrappedValue = unwrap(value, path);
90
+ const remainingValue = remove(value, path);
91
+ if (remainingValue)
92
+ pushRemaining(remainingValue);
93
+ if (unwrappedValue)
94
+ yield unwrappedValue;
95
+ }
96
+ };
97
+ const unwrappedStream = fn(unwrappedPayload, options, shiftedNext);
98
+ const firstValue = await (await unwrappedStream.next()).value;
99
+ const resultStream = makeStream((push) => {
100
+ push(wrap(firstValue, path));
101
+ mapStream(unwrappedStream, (value) => {
102
+ push(wrap(value, path));
103
+ });
104
+ return () => unwrappedStream.return();
105
+ });
106
+ if (!nextCalled && remainingPayload.length) {
107
+ remainingNextStream = next(remainingPayload);
108
+ }
109
+ yield* remainingNextStream ? mergeStreams(resultStream, remainingNextStream) : resultStream;
110
+ };
111
+ }
112
+ const log = debug("graffy:core");
113
+ function resolve(handlers, firstPayload, options) {
114
+ if (!handlers || !handlers.length)
115
+ throw Error("resolve.no_provider");
116
+ function run(i, payload) {
117
+ if (i >= handlers.length) {
118
+ throw Error("resolve.no_providers_for " + JSON.stringify(payload));
119
+ }
120
+ const { path, handle } = handlers[i];
121
+ if (!unwrap(payload, path))
122
+ return run(i + 1, payload);
123
+ let nextCalled = false;
124
+ return handle(payload, options, (nextPayload) => {
125
+ if (nextCalled) {
126
+ throw Error("resolve.duplicate_next_call: " + handlers[i].name);
127
+ }
128
+ if (typeof nextPayload === "undefined") {
129
+ throw Error("resolve.next_without_payload: " + handlers[i].name);
130
+ }
131
+ nextCalled = true;
132
+ return run(i + 1, nextPayload);
133
+ });
134
+ }
135
+ return run(0, firstPayload);
136
+ }
137
+ class Core {
138
+ constructor() {
139
+ this.handlers = {};
140
+ }
141
+ on(type, path, handle) {
142
+ this.handlers[type] = this.handlers[type] || [];
143
+ this.handlers[type].push({ path, handle });
144
+ }
145
+ call(type, payload, options = {}) {
146
+ log("call", type, format(payload));
147
+ return resolve(this.handlers[type], payload, options);
148
+ }
149
+ }
150
+ class Graffy {
151
+ constructor(path = [], core = new Core()) {
152
+ this.core = core;
153
+ this.path = path;
154
+ }
155
+ on(type, ...args) {
156
+ const [pathArg, handler] = validateOn(...args);
157
+ const path = this.path.concat(pathArg);
158
+ this.core.on(type, path, handler);
159
+ }
160
+ onRead(...args) {
161
+ const [pathArg, handle] = validateOn(...args);
162
+ const path = this.path.concat(pathArg);
163
+ this.core.on("read", path, shiftFn(async function porcelainRead(query, options) {
164
+ const decoded = decodeQuery(query);
165
+ const encoded = encodeGraph(await handle(decoded, options));
166
+ const finalized = finalize(encoded, query);
167
+ return finalized;
168
+ }, path));
169
+ }
170
+ onWatch(...args) {
171
+ const [pathArg, handle] = validateOn(...args);
172
+ const path = this.path.concat(pathArg);
173
+ this.core.on("watch", path, shiftGen(function porcelainWatch(query, options) {
174
+ return makeStream((push, end) => {
175
+ const subscription = handle(decodeQuery(query), options);
176
+ (async function() {
177
+ try {
178
+ let firstValue = (await subscription.next()).value;
179
+ push(firstValue && finalize(encodeGraph(firstValue), query));
180
+ for await (const value of subscription) {
181
+ push(value && encodeGraph(value));
182
+ }
183
+ } catch (e) {
184
+ end(e);
185
+ }
186
+ })();
187
+ return () => subscription.return();
188
+ });
189
+ }, path));
190
+ }
191
+ onWrite(...args) {
192
+ const [pathArg, handle] = validateOn(...args);
193
+ const path = this.path.concat(pathArg);
194
+ this.core.on("write", path, shiftFn(async function porcelainWrite(change, options) {
195
+ return encodeGraph(await handle(decodeGraph(change), options));
196
+ }, path));
197
+ }
198
+ use(...args) {
199
+ const [path, provider] = validateOn(...args);
200
+ provider(new Graffy(path, this.core));
201
+ }
202
+ call(type, payload, options = {}) {
203
+ return this.core.call(type, payload, options);
204
+ }
205
+ async read(...args) {
206
+ const [path, porcelainQuery, options] = validateCall(...args);
207
+ const rootQuery = wrapObject(porcelainQuery, path);
208
+ const query = encodeQuery(rootQuery);
209
+ const result = await this.core.call("read", query, options || {});
210
+ return unwrapObject(decorate(result, rootQuery), decodePath(path));
211
+ }
212
+ watch(...args) {
213
+ const [path, porcelainQuery, options] = validateCall(...args);
214
+ const rootQuery = wrapObject(porcelainQuery, path);
215
+ const query = encodeQuery(rootQuery);
216
+ const stream = this.core.call("watch", query, options || {});
217
+ return mapStream$1(stream, (value) => unwrapObject(decorate(value, rootQuery), decodePath(path)));
218
+ }
219
+ async write(...args) {
220
+ const [path, porcelainChange, options] = validateCall(...args);
221
+ const change = wrap(encodeGraph(porcelainChange), path);
222
+ const writtenChange = await this.core.call("write", change, options || {});
223
+ return unwrapObject(decodeGraph(writtenChange), decodePath(path));
224
+ }
225
+ }
226
+ export { Graffy as default };
package/package.json CHANGED
@@ -2,8 +2,13 @@
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.8-alpha.2",
6
- "main": "./cjs/index.js",
5
+ "version": "0.15.8",
6
+ "main": "./index.cjs",
7
+ "exports": {
8
+ "import": "./index.mjs",
9
+ "require": "./index.cjs"
10
+ },
11
+ "module": "./index.mjs",
7
12
  "types": "./types/index.d.ts",
8
13
  "repository": {
9
14
  "type": "git",
@@ -11,10 +16,9 @@
11
16
  },
12
17
  "license": "Apache-2.0",
13
18
  "dependencies": {
14
- "@babel/runtime-corejs3": "^7.15.3",
15
- "@graffy/common": "0.15.8-alpha.2",
19
+ "@graffy/common": "0.15.8",
20
+ "@graffy/stream": "0.15.8",
16
21
  "debug": "^4.3.2",
17
- "@graffy/testing": "0.15.8-alpha.2",
18
- "@graffy/stream": "0.15.8-alpha.2"
22
+ "@graffy/testing": "0.15.8"
19
23
  }
20
24
  }
package/cjs/Core.js DELETED
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
9
-
10
- var _common = require("@graffy/common");
11
-
12
- var _debug = _interopRequireDefault(require("debug"));
13
-
14
- var _testing = require("@graffy/testing");
15
-
16
- var log = (0, _debug.default)('graffy:core');
17
-
18
- function resolve(handlers, firstPayload, options) {
19
- if (!handlers || !handlers.length) throw Error('resolve.no_provider');
20
-
21
- function run(i, payload) {
22
- if (i >= handlers.length) {
23
- throw Error('resolve.no_providers_for ' + (0, _stringify.default)(payload));
24
- }
25
-
26
- var _handlers$i = handlers[i],
27
- path = _handlers$i.path,
28
- handle = _handlers$i.handle;
29
- if (!(0, _common.unwrap)(payload, path)) return run(i + 1, payload);
30
- var nextCalled = false;
31
- return handle(payload, options, function (nextPayload) {
32
- if (nextCalled) {
33
- throw Error('resolve.duplicate_next_call: ' + handlers[i].name);
34
- }
35
-
36
- if (typeof nextPayload === 'undefined') {
37
- throw Error('resolve.next_without_payload: ' + handlers[i].name);
38
- }
39
-
40
- nextCalled = true;
41
- return run(i + 1, nextPayload);
42
- });
43
- }
44
-
45
- return run(0, firstPayload);
46
- }
47
-
48
- var Core = /*#__PURE__*/function () {
49
- function Core() {
50
- this.handlers = {};
51
- }
52
-
53
- var _proto = Core.prototype;
54
-
55
- _proto.on = function on(type, path, handle) {
56
- this.handlers[type] = this.handlers[type] || [];
57
- this.handlers[type].push({
58
- path: path,
59
- handle: handle
60
- });
61
- };
62
-
63
- _proto.call = function call(type, payload, options) {
64
- if (options === void 0) {
65
- options = {};
66
- }
67
-
68
- log('call', type, (0, _testing.format)(payload));
69
- return resolve(this.handlers[type], payload, options);
70
- };
71
-
72
- return Core;
73
- }();
74
-
75
- exports.default = Core;
76
- module.exports = exports.default;
package/cjs/Graffy.js DELETED
@@ -1,362 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
9
-
10
- var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
13
-
14
- var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncIterator"));
15
-
16
- var _common = require("@graffy/common");
17
-
18
- var _stream = require("@graffy/stream");
19
-
20
- var _validate = require("./validate.js");
21
-
22
- var _shift = require("./shift.js");
23
-
24
- var _Core = _interopRequireDefault(require("./Core.js"));
25
-
26
- var Graffy = /*#__PURE__*/function () {
27
- function Graffy(path, core) {
28
- if (path === void 0) {
29
- path = [];
30
- }
31
-
32
- if (core === void 0) {
33
- core = new _Core.default();
34
- }
35
-
36
- this.core = core;
37
- this.path = path;
38
- }
39
-
40
- var _proto = Graffy.prototype;
41
-
42
- _proto.on = function on(type) {
43
- var _context;
44
-
45
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
46
- args[_key - 1] = arguments[_key];
47
- }
48
-
49
- var _validateOn = _validate.validateOn.apply(void 0, args),
50
- pathArg = _validateOn[0],
51
- handler = _validateOn[1];
52
-
53
- var path = (0, _concat.default)(_context = this.path).call(_context, pathArg);
54
- this.core.on(type, path, handler);
55
- };
56
-
57
- _proto.onRead = function onRead() {
58
- var _context2;
59
-
60
- var _validateOn2 = _validate.validateOn.apply(void 0, arguments),
61
- pathArg = _validateOn2[0],
62
- handle = _validateOn2[1];
63
-
64
- var path = (0, _concat.default)(_context2 = this.path).call(_context2, pathArg);
65
- this.core.on('read', path, (0, _shift.shiftFn)( /*#__PURE__*/function () {
66
- var _porcelainRead = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(query, options) {
67
- var decoded, encoded, finalized;
68
- return _regenerator.default.wrap(function _callee$(_context3) {
69
- while (1) {
70
- switch (_context3.prev = _context3.next) {
71
- case 0:
72
- // console.log('onRead', path, query);
73
- decoded = (0, _common.decodeQuery)(query); // console.log('decoded', path, decoded);
74
-
75
- _context3.t0 = _common.encodeGraph;
76
- _context3.next = 4;
77
- return handle(decoded, options);
78
-
79
- case 4:
80
- _context3.t1 = _context3.sent;
81
- encoded = (0, _context3.t0)(_context3.t1);
82
- // console.log({ encoded });
83
- finalized = (0, _common.finalize)(encoded, query); // console.log({ finalized });
84
-
85
- return _context3.abrupt("return", finalized);
86
-
87
- case 8:
88
- case "end":
89
- return _context3.stop();
90
- }
91
- }
92
- }, _callee);
93
- }));
94
-
95
- function porcelainRead(_x, _x2) {
96
- return _porcelainRead.apply(this, arguments);
97
- }
98
-
99
- return porcelainRead;
100
- }(), path));
101
- };
102
-
103
- _proto.onWatch = function onWatch() {
104
- var _context4;
105
-
106
- var _validateOn3 = _validate.validateOn.apply(void 0, arguments),
107
- pathArg = _validateOn3[0],
108
- handle = _validateOn3[1];
109
-
110
- var path = (0, _concat.default)(_context4 = this.path).call(_context4, pathArg);
111
- this.core.on('watch', path, (0, _shift.shiftGen)(function porcelainWatch(query, options) {
112
- return (0, _stream.makeStream)(function (push, end) {
113
- var subscription = handle((0, _common.decodeQuery)(query), options);
114
- (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
115
- var firstValue, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, value;
116
-
117
- return _regenerator.default.wrap(function _callee2$(_context5) {
118
- while (1) {
119
- switch (_context5.prev = _context5.next) {
120
- case 0:
121
- _context5.prev = 0;
122
- _context5.next = 3;
123
- return subscription.next();
124
-
125
- case 3:
126
- firstValue = _context5.sent.value;
127
- push(firstValue && (0, _common.finalize)((0, _common.encodeGraph)(firstValue), query));
128
- _iteratorAbruptCompletion = false;
129
- _didIteratorError = false;
130
- _context5.prev = 7;
131
- _iterator = (0, _asyncIterator2.default)(subscription);
132
-
133
- case 9:
134
- _context5.next = 11;
135
- return _iterator.next();
136
-
137
- case 11:
138
- if (!(_iteratorAbruptCompletion = !(_step = _context5.sent).done)) {
139
- _context5.next = 17;
140
- break;
141
- }
142
-
143
- value = _step.value;
144
- push(value && (0, _common.encodeGraph)(value));
145
-
146
- case 14:
147
- _iteratorAbruptCompletion = false;
148
- _context5.next = 9;
149
- break;
150
-
151
- case 17:
152
- _context5.next = 23;
153
- break;
154
-
155
- case 19:
156
- _context5.prev = 19;
157
- _context5.t0 = _context5["catch"](7);
158
- _didIteratorError = true;
159
- _iteratorError = _context5.t0;
160
-
161
- case 23:
162
- _context5.prev = 23;
163
- _context5.prev = 24;
164
-
165
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
166
- _context5.next = 28;
167
- break;
168
- }
169
-
170
- _context5.next = 28;
171
- return _iterator.return();
172
-
173
- case 28:
174
- _context5.prev = 28;
175
-
176
- if (!_didIteratorError) {
177
- _context5.next = 31;
178
- break;
179
- }
180
-
181
- throw _iteratorError;
182
-
183
- case 31:
184
- return _context5.finish(28);
185
-
186
- case 32:
187
- return _context5.finish(23);
188
-
189
- case 33:
190
- _context5.next = 38;
191
- break;
192
-
193
- case 35:
194
- _context5.prev = 35;
195
- _context5.t1 = _context5["catch"](0);
196
- end(_context5.t1);
197
-
198
- case 38:
199
- case "end":
200
- return _context5.stop();
201
- }
202
- }
203
- }, _callee2, null, [[0, 35], [7, 19, 23, 33], [24,, 28, 32]]);
204
- }))();
205
- return function () {
206
- return subscription.return();
207
- };
208
- });
209
- }, path));
210
- };
211
-
212
- _proto.onWrite = function onWrite() {
213
- var _context6;
214
-
215
- var _validateOn4 = _validate.validateOn.apply(void 0, arguments),
216
- pathArg = _validateOn4[0],
217
- handle = _validateOn4[1];
218
-
219
- var path = (0, _concat.default)(_context6 = this.path).call(_context6, pathArg);
220
- this.core.on('write', path, (0, _shift.shiftFn)( /*#__PURE__*/function () {
221
- var _porcelainWrite = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(change, options) {
222
- return _regenerator.default.wrap(function _callee3$(_context7) {
223
- while (1) {
224
- switch (_context7.prev = _context7.next) {
225
- case 0:
226
- _context7.t0 = _common.encodeGraph;
227
- _context7.next = 3;
228
- return handle((0, _common.decodeGraph)(change), options);
229
-
230
- case 3:
231
- _context7.t1 = _context7.sent;
232
- return _context7.abrupt("return", (0, _context7.t0)(_context7.t1));
233
-
234
- case 5:
235
- case "end":
236
- return _context7.stop();
237
- }
238
- }
239
- }, _callee3);
240
- }));
241
-
242
- function porcelainWrite(_x3, _x4) {
243
- return _porcelainWrite.apply(this, arguments);
244
- }
245
-
246
- return porcelainWrite;
247
- }(), path));
248
- };
249
-
250
- _proto.use = function use() {
251
- var _validateOn5 = _validate.validateOn.apply(void 0, arguments),
252
- path = _validateOn5[0],
253
- provider = _validateOn5[1];
254
-
255
- provider(new Graffy(path, this.core));
256
- };
257
-
258
- _proto.call = function call(type, payload, options) {
259
- if (options === void 0) {
260
- options = {};
261
- }
262
-
263
- return this.core.call(type, payload, options);
264
- };
265
-
266
- _proto.read = /*#__PURE__*/function () {
267
- var _read = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4() {
268
- var _validateCall,
269
- path,
270
- porcelainQuery,
271
- options,
272
- rootQuery,
273
- query,
274
- result,
275
- _args4 = arguments;
276
-
277
- return _regenerator.default.wrap(function _callee4$(_context8) {
278
- while (1) {
279
- switch (_context8.prev = _context8.next) {
280
- case 0:
281
- _validateCall = _validate.validateCall.apply(void 0, _args4), path = _validateCall[0], porcelainQuery = _validateCall[1], options = _validateCall[2];
282
- rootQuery = (0, _common.wrapObject)(porcelainQuery, path);
283
- query = (0, _common.encodeQuery)(rootQuery);
284
- _context8.next = 5;
285
- return this.core.call('read', query, options || {});
286
-
287
- case 5:
288
- result = _context8.sent;
289
- return _context8.abrupt("return", (0, _common.unwrapObject)((0, _common.decorate)(result, rootQuery), (0, _common.decodePath)(path)));
290
-
291
- case 7:
292
- case "end":
293
- return _context8.stop();
294
- }
295
- }
296
- }, _callee4, this);
297
- }));
298
-
299
- function read() {
300
- return _read.apply(this, arguments);
301
- }
302
-
303
- return read;
304
- }();
305
-
306
- _proto.watch = function watch() {
307
- var _validateCall2 = _validate.validateCall.apply(void 0, arguments),
308
- path = _validateCall2[0],
309
- porcelainQuery = _validateCall2[1],
310
- options = _validateCall2[2];
311
-
312
- var rootQuery = (0, _common.wrapObject)(porcelainQuery, path);
313
- var query = (0, _common.encodeQuery)(rootQuery);
314
- var stream = this.core.call('watch', query, options || {});
315
- return (0, _stream.mapStream)(stream, function (value) {
316
- return (0, _common.unwrapObject)((0, _common.decorate)(value, rootQuery), (0, _common.decodePath)(path));
317
- });
318
- };
319
-
320
- _proto.write = /*#__PURE__*/function () {
321
- var _write = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
322
- var _validateCall3,
323
- path,
324
- porcelainChange,
325
- options,
326
- change,
327
- writtenChange,
328
- _args5 = arguments;
329
-
330
- return _regenerator.default.wrap(function _callee5$(_context9) {
331
- while (1) {
332
- switch (_context9.prev = _context9.next) {
333
- case 0:
334
- _validateCall3 = _validate.validateCall.apply(void 0, _args5), path = _validateCall3[0], porcelainChange = _validateCall3[1], options = _validateCall3[2];
335
- change = (0, _common.wrap)((0, _common.encodeGraph)(porcelainChange), path);
336
- _context9.next = 4;
337
- return this.core.call('write', change, options || {});
338
-
339
- case 4:
340
- writtenChange = _context9.sent;
341
- return _context9.abrupt("return", (0, _common.unwrapObject)((0, _common.decodeGraph)(writtenChange), (0, _common.decodePath)(path)));
342
-
343
- case 6:
344
- case "end":
345
- return _context9.stop();
346
- }
347
- }
348
- }, _callee5, this);
349
- }));
350
-
351
- function write() {
352
- return _write.apply(this, arguments);
353
- }
354
-
355
- return write;
356
- }();
357
-
358
- return Graffy;
359
- }();
360
-
361
- exports.default = Graffy;
362
- module.exports = exports.default;
package/cjs/index.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.default = void 0;
7
-
8
- var _Graffy = _interopRequireDefault(require("./Graffy.js"));
9
-
10
- var _default = _Graffy.default;
11
- exports.default = _default;
12
- module.exports = exports.default;
package/cjs/shift.js DELETED
@@ -1,350 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.shiftFn = shiftFn;
7
- exports.shiftGen = shiftGen;
8
-
9
- var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
10
-
11
- var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
12
-
13
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
14
-
15
- var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/wrapAsyncGenerator"));
16
-
17
- var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/awaitAsyncGenerator"));
18
-
19
- var _asyncGeneratorDelegate2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncGeneratorDelegate"));
20
-
21
- var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncIterator"));
22
-
23
- var _common = require("@graffy/common");
24
-
25
- var _stream = require("@graffy/stream");
26
-
27
- // import { format } from '@graffy/testing';
28
- function mapStream(stream, fn) {
29
- var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, value;
30
-
31
- return _regenerator.default.async(function mapStream$(_context) {
32
- while (1) {
33
- switch (_context.prev = _context.next) {
34
- case 0:
35
- _iteratorAbruptCompletion = false;
36
- _didIteratorError = false;
37
- _context.prev = 2;
38
- _iterator = (0, _asyncIterator2.default)(stream);
39
-
40
- case 4:
41
- _context.next = 6;
42
- return _regenerator.default.awrap(_iterator.next());
43
-
44
- case 6:
45
- if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
46
- _context.next = 12;
47
- break;
48
- }
49
-
50
- value = _step.value;
51
- fn(value);
52
-
53
- case 9:
54
- _iteratorAbruptCompletion = false;
55
- _context.next = 4;
56
- break;
57
-
58
- case 12:
59
- _context.next = 18;
60
- break;
61
-
62
- case 14:
63
- _context.prev = 14;
64
- _context.t0 = _context["catch"](2);
65
- _didIteratorError = true;
66
- _iteratorError = _context.t0;
67
-
68
- case 18:
69
- _context.prev = 18;
70
- _context.prev = 19;
71
-
72
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
73
- _context.next = 23;
74
- break;
75
- }
76
-
77
- _context.next = 23;
78
- return _regenerator.default.awrap(_iterator.return());
79
-
80
- case 23:
81
- _context.prev = 23;
82
-
83
- if (!_didIteratorError) {
84
- _context.next = 26;
85
- break;
86
- }
87
-
88
- throw _iteratorError;
89
-
90
- case 26:
91
- return _context.finish(23);
92
-
93
- case 27:
94
- return _context.finish(18);
95
-
96
- case 28:
97
- case "end":
98
- return _context.stop();
99
- }
100
- }
101
- }, null, null, [[2, 14, 18, 28], [19,, 23, 27]], _promise.default);
102
- }
103
-
104
- function shiftFn(fn, path) {
105
- return /*#__PURE__*/function () {
106
- var _shiftedFn = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(payload, options, next) {
107
- var nextCalled, remainingNextResult, unwrappedPayload, remainingPayload, shiftedNext, _shiftedNext, rawResult, result;
108
-
109
- return _regenerator.default.wrap(function _callee2$(_context3) {
110
- while (1) {
111
- switch (_context3.prev = _context3.next) {
112
- case 0:
113
- _shiftedNext = function _shiftedNext3() {
114
- _shiftedNext = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(unwrappedNextPayload) {
115
- var nextPayload, nextResult;
116
- return _regenerator.default.wrap(function _callee$(_context2) {
117
- while (1) {
118
- switch (_context2.prev = _context2.next) {
119
- case 0:
120
- nextCalled = true;
121
- nextPayload = (0, _common.wrap)(unwrappedNextPayload, path);
122
- if (remainingPayload.length) (0, _common.merge)(nextPayload, remainingPayload);
123
- _context2.next = 5;
124
- return next(nextPayload);
125
-
126
- case 5:
127
- nextResult = _context2.sent;
128
- // Remember the next() results that are not returned to this provider.
129
- // These will be merged into the result later.
130
- remainingNextResult = (0, _common.remove)(nextResult, path) || [];
131
- return _context2.abrupt("return", (0, _common.unwrap)(nextResult, path));
132
-
133
- case 8:
134
- case "end":
135
- return _context2.stop();
136
- }
137
- }
138
- }, _callee);
139
- }));
140
- return _shiftedNext.apply(this, arguments);
141
- };
142
-
143
- shiftedNext = function _shiftedNext2(_x8) {
144
- return _shiftedNext.apply(this, arguments);
145
- };
146
-
147
- nextCalled = false;
148
- unwrappedPayload = (0, _common.unwrap)(payload, path);
149
- remainingPayload = (0, _common.remove)(payload, path) || []; // This next function is offered to the provider function.
150
-
151
- _context3.next = 7;
152
- return fn(unwrappedPayload, options, shiftedNext);
153
-
154
- case 7:
155
- rawResult = _context3.sent;
156
- // console.log(rawResult, path);
157
- result = (0, _common.wrap)(rawResult, path); // console.log(result);
158
-
159
- if (!(!nextCalled && remainingPayload.length)) {
160
- _context3.next = 13;
161
- break;
162
- }
163
-
164
- _context3.next = 12;
165
- return next(remainingPayload);
166
-
167
- case 12:
168
- remainingNextResult = _context3.sent;
169
-
170
- case 13:
171
- if (remainingNextResult && remainingNextResult.length) {
172
- (0, _common.merge)(result, remainingNextResult);
173
- } // console.log('Shifted', path, format(payload), format(result));
174
-
175
-
176
- return _context3.abrupt("return", result);
177
-
178
- case 15:
179
- case "end":
180
- return _context3.stop();
181
- }
182
- }
183
- }, _callee2);
184
- }));
185
-
186
- function shiftedFn(_x5, _x6, _x7) {
187
- return _shiftedFn.apply(this, arguments);
188
- }
189
-
190
- return shiftedFn;
191
- }();
192
- } // TODO: Provider calling next in a subscription function is not tested.
193
-
194
-
195
- function shiftGen(fn, path) {
196
- return /*#__PURE__*/function () {
197
- var _shiftedGen = (0, _wrapAsyncGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(payload, options, next) {
198
- var nextCalled, remainingNextStream, unwrappedPayload, remainingPayload, shiftedNext, unwrappedStream, firstValue, resultStream;
199
- return _regenerator.default.wrap(function _callee4$(_context5) {
200
- while (1) {
201
- switch (_context5.prev = _context5.next) {
202
- case 0:
203
- nextCalled = false;
204
- unwrappedPayload = (0, _common.unwrap)(payload, path);
205
- remainingPayload = (0, _common.remove)(payload, path) || []; // TODO: This should probably use makeStream and propagate returns.
206
-
207
- shiftedNext = /*#__PURE__*/function () {
208
- var _shiftedNextFn = (0, _wrapAsyncGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(unwrappedNextPayload) {
209
- var nextPayload, pushRemaining, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, value, unwrappedValue, remainingValue;
210
-
211
- return _regenerator.default.wrap(function _callee3$(_context4) {
212
- while (1) {
213
- switch (_context4.prev = _context4.next) {
214
- case 0:
215
- nextCalled = true;
216
- nextPayload = (0, _common.wrap)(unwrappedNextPayload, path);
217
- if (remainingPayload.length) (0, _common.merge)(nextPayload, remainingPayload);
218
- remainingNextStream = (0, _stream.makeStream)(function (push) {
219
- pushRemaining = push;
220
- });
221
- _iteratorAbruptCompletion2 = false;
222
- _didIteratorError2 = false;
223
- _context4.prev = 6;
224
- _iterator2 = (0, _asyncIterator2.default)(next(nextPayload));
225
-
226
- case 8:
227
- _context4.next = 10;
228
- return (0, _awaitAsyncGenerator2.default)(_iterator2.next());
229
-
230
- case 10:
231
- if (!(_iteratorAbruptCompletion2 = !(_step2 = _context4.sent).done)) {
232
- _context4.next = 21;
233
- break;
234
- }
235
-
236
- value = _step2.value;
237
- unwrappedValue = (0, _common.unwrap)(value, path);
238
- remainingValue = (0, _common.remove)(value, path);
239
- if (remainingValue) pushRemaining(remainingValue);
240
-
241
- if (!unwrappedValue) {
242
- _context4.next = 18;
243
- break;
244
- }
245
-
246
- _context4.next = 18;
247
- return unwrappedValue;
248
-
249
- case 18:
250
- _iteratorAbruptCompletion2 = false;
251
- _context4.next = 8;
252
- break;
253
-
254
- case 21:
255
- _context4.next = 27;
256
- break;
257
-
258
- case 23:
259
- _context4.prev = 23;
260
- _context4.t0 = _context4["catch"](6);
261
- _didIteratorError2 = true;
262
- _iteratorError2 = _context4.t0;
263
-
264
- case 27:
265
- _context4.prev = 27;
266
- _context4.prev = 28;
267
-
268
- if (!(_iteratorAbruptCompletion2 && _iterator2.return != null)) {
269
- _context4.next = 32;
270
- break;
271
- }
272
-
273
- _context4.next = 32;
274
- return (0, _awaitAsyncGenerator2.default)(_iterator2.return());
275
-
276
- case 32:
277
- _context4.prev = 32;
278
-
279
- if (!_didIteratorError2) {
280
- _context4.next = 35;
281
- break;
282
- }
283
-
284
- throw _iteratorError2;
285
-
286
- case 35:
287
- return _context4.finish(32);
288
-
289
- case 36:
290
- return _context4.finish(27);
291
-
292
- case 37:
293
- case "end":
294
- return _context4.stop();
295
- }
296
- }
297
- }, _callee3, null, [[6, 23, 27, 37], [28,, 32, 36]]);
298
- }));
299
-
300
- function shiftedNextFn(_x4) {
301
- return _shiftedNextFn.apply(this, arguments);
302
- }
303
-
304
- return shiftedNextFn;
305
- }();
306
-
307
- unwrappedStream = fn(unwrappedPayload, options, shiftedNext); // We expect next() to be called before the first value is yielded.
308
-
309
- _context5.t0 = _awaitAsyncGenerator2.default;
310
- _context5.next = 8;
311
- return (0, _awaitAsyncGenerator2.default)(unwrappedStream.next());
312
-
313
- case 8:
314
- _context5.t1 = _context5.sent.value;
315
- _context5.next = 11;
316
- return (0, _context5.t0)(_context5.t1);
317
-
318
- case 11:
319
- firstValue = _context5.sent;
320
- resultStream = (0, _stream.makeStream)(function (push) {
321
- push((0, _common.wrap)(firstValue, path));
322
- mapStream(unwrappedStream, function (value) {
323
- push((0, _common.wrap)(value, path));
324
- });
325
- return function () {
326
- return unwrappedStream.return();
327
- };
328
- });
329
-
330
- if (!nextCalled && remainingPayload.length) {
331
- remainingNextStream = next(remainingPayload);
332
- }
333
-
334
- return _context5.delegateYield((0, _asyncGeneratorDelegate2.default)((0, _asyncIterator2.default)(remainingNextStream ? (0, _common.mergeStreams)(resultStream, remainingNextStream) : resultStream), _awaitAsyncGenerator2.default), "t2", 15);
335
-
336
- case 15:
337
- case "end":
338
- return _context5.stop();
339
- }
340
- }
341
- }, _callee4);
342
- }));
343
-
344
- function shiftedGen(_x, _x2, _x3) {
345
- return _shiftedGen.apply(this, arguments);
346
- }
347
-
348
- return shiftedGen;
349
- }();
350
- }
package/cjs/validate.js DELETED
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.validateCall = validateCall;
7
- exports.validateOn = validateOn;
8
-
9
- var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
10
-
11
- var _stringify = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/json/stringify"));
12
-
13
- var _common = require("@graffy/common");
14
-
15
- function isPlainObject(obj) {
16
- return obj && typeof obj === 'object' && !(0, _isArray.default)(obj);
17
- }
18
- /*
19
- any -> payload
20
-
21
- object, object -> payload, options
22
- string | array, any -> path, payload
23
-
24
- string | array, any, object -> path, payload, options
25
- */
26
-
27
-
28
- function validateCall() {
29
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
- args[_key] = arguments[_key];
31
- }
32
-
33
- if (args.length === 1) {
34
- return [[], args[0], {}];
35
- } else if (args.length === 2) {
36
- if (isPlainObject(args[0])) {
37
- if (!isPlainObject(args[1])) {
38
- throw Error("validateCall.invalid_options: " + (0, _stringify.default)(args[1]));
39
- }
40
-
41
- return [[], args[0], args[1]];
42
- } else {
43
- return [(0, _common.encodePath)(args[0]), args[1], {}];
44
- }
45
- } else if (args.length === 3) {
46
- if (!isPlainObject(args[2])) {
47
- throw Error("validateCall.invalid_options: " + (0, _stringify.default)(args[1]));
48
- }
49
-
50
- return [(0, _common.encodePath)(args[0]), args[1], args[2]];
51
- }
52
-
53
- throw Error("validateCall.invalid_args: " + (0, _stringify.default)(args));
54
- }
55
-
56
- function validateOn() {
57
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
58
- args[_key2] = arguments[_key2];
59
- }
60
-
61
- if (args.length === 1) {
62
- if (typeof args[0] !== 'function') {
63
- throw Error("validateOn.invalid_handler: " + (0, _stringify.default)(args[0]));
64
- }
65
-
66
- return [[], args[0]];
67
- } else if (args.length === 2) {
68
- if (typeof args[1] !== 'function') {
69
- throw Error("validateOn.invalid_handler: " + (0, _stringify.default)(args[1]));
70
- }
71
-
72
- return [(0, _common.encodePath)(args[0]), args[1]];
73
- }
74
-
75
- throw Error("validateOn.invalid_args: " + (0, _stringify.default)(args));
76
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
4
-
5
- exports.__esModule = true;
6
- exports.default = wrapProvider;
7
-
8
- var _wrappers = _interopRequireDefault(require("./wrappers.js"));
9
-
10
- function wrapProvider(provider, options) {
11
- if (options === void 0) {
12
- options = {};
13
- }
14
-
15
- var _options = options,
16
- decode = _options.decode,
17
- shift = _options.shift,
18
- finalize = _options.finalize,
19
- _debounce = _options._debounce,
20
- link = _options.link,
21
- _fetch = _options._fetch,
22
- _watch = _options._watch;
23
- /*
24
- The wrapper closest to the user-supplied provider should be applied first.
25
- */
26
-
27
- if (shift) provider = _wrappers.default.shift(provider, shift);
28
- if (link) provider = _wrappers.default.link(provider, link);
29
- if (finalize) provider = _wrappers.default.finalize(provider);
30
- if (decode) provider = _wrappers.default.decode(provider);
31
- }
32
-
33
- module.exports = exports.default;