@graffy/core 0.15.24-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.
- package/index.cjs +47 -34
- package/index.mjs +45 -28
- package/package.json +3 -3
package/index.cjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
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(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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(
|
|
198
|
-
|
|
199
|
-
|
|
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(
|
|
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,
|
|
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(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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(
|
|
193
|
-
|
|
194
|
-
|
|
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(
|
|
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 {
|
|
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.
|
|
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.
|
|
20
|
-
"@graffy/stream": "0.15.
|
|
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
|
}
|