@graffy/testing 0.15.8-alpha.5 → 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.
Files changed (3) hide show
  1. package/index.cjs +88 -1
  2. package/index.mjs +82 -1
  3. package/package.json +2 -2
package/index.cjs CHANGED
@@ -1 +1,88 @@
1
- "use strict";var e=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,t=Object.prototype.propertyIsEnumerable;Object.defineProperty(exports,"__esModule",{value:!0}),exports[Symbol.toStringTag]="Module";var n=require("@graffy/common");function o(e){return""===e?"''":e.replace(/\uffff/g,"𝖋𝖋").replace(/\0/g,"𝖔𝖔")}function a(e,r){return e===r?`${e} ×`:[o(e)," ⋯ ",o(r)].join("")}let i;function c(n,u=""){return n?(""===u&&(i=null),Array.isArray(n)||(n=[n]),n.length?"\n"+n.map((n=>{var l=n,{key:p,end:s,children:f,version:y,path:d,value:g}=l,h=((n,o)=>{var a={};for(var i in n)r.call(n,i)&&o.indexOf(i)<0&&(a[i]=n[i]);if(null!=n&&e)for(var i of e(n))o.indexOf(i)<0&&t.call(n,i)&&(a[i]=n[i]);return a})(l,["key","end","children","version","path","value"]);return[i===y?"":"<@"+(i=y)+">\n",u,s?a(p,s):o(p),d?` ➚${d.join(".")}`:"",g?` ${JSON.stringify(g)}`:"",Object.keys(h).length>0?" "+JSON.stringify(h):"",f?" {":"",f?c(f,u+" "):"",f?" }":""].join("")})).join("\n"):"[]"):n}exports.format=c,exports.inspect=function(){return c(this)},exports.mockBackend=function(e={}){const r=[],t=n.makeWatcher(),o={state:r,read:()=>r,watch:()=>t.watch(e.liveQuery?r:void 0),write:e=>(n.merge(r,e),t.write(e),e),middleware:e=>{e.on("read",o.read),e.on("watch",o.watch),e.on("write",o.write)}};return o},exports.pretty=function(e){return JSON.stringify(e,null,4).replace(/\[(\s*)([\s\S]*?)\},*/g,((e,r,t)=>"["+r+t.replace(/\n\s+/g," ")+"},")).replace(/[^\u0020-\u007e,\u000a]/g,(e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4)))};
1
+ "use strict";
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __objRest = (source, exclude) => {
6
+ var target = {};
7
+ for (var prop in source)
8
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
9
+ target[prop] = source[prop];
10
+ if (source != null && __getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(source)) {
12
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
13
+ target[prop] = source[prop];
14
+ }
15
+ return target;
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports[Symbol.toStringTag] = "Module";
19
+ var common = require("@graffy/common");
20
+ function mockBackend(options = {}) {
21
+ const state = [];
22
+ const watcher = common.makeWatcher();
23
+ const backend = {
24
+ state,
25
+ read: () => state,
26
+ watch: () => watcher.watch(options.liveQuery ? state : void 0),
27
+ write: (change) => {
28
+ common.merge(state, change);
29
+ watcher.write(change);
30
+ return change;
31
+ }
32
+ };
33
+ backend.middleware = (store) => {
34
+ store.on("read", backend.read);
35
+ store.on("watch", backend.watch);
36
+ store.on("write", backend.write);
37
+ };
38
+ return backend;
39
+ }
40
+ function escape(string) {
41
+ if (string === "")
42
+ return "''";
43
+ return string.replace(/\uffff/g, "\u{1D58B}\u{1D58B}").replace(/\0/g, "\u{1D594}\u{1D594}");
44
+ }
45
+ function interval(key, end) {
46
+ if (key === end)
47
+ return `${key} \xD7`;
48
+ return [
49
+ escape(key),
50
+ " \u22EF ",
51
+ escape(end)
52
+ ].join("");
53
+ }
54
+ let lastPrintedVersion;
55
+ function format(graph, indent = "") {
56
+ if (!graph)
57
+ return graph;
58
+ if (indent === "")
59
+ lastPrintedVersion = null;
60
+ if (!Array.isArray(graph))
61
+ graph = [graph];
62
+ if (!graph.length)
63
+ return "[]";
64
+ return "\n" + graph.map((_a) => {
65
+ var _b = _a, { key, end, children, version, path, value } = _b, rest = __objRest(_b, ["key", "end", "children", "version", "path", "value"]);
66
+ return [
67
+ lastPrintedVersion === version ? "" : "<@" + (lastPrintedVersion = version) + ">\n",
68
+ indent,
69
+ end ? interval(key, end) : escape(key),
70
+ path ? ` \u279A${path.join(".")}` : "",
71
+ value ? ` ${JSON.stringify(value)}` : "",
72
+ Object.keys(rest).length > 0 ? " " + JSON.stringify(rest) : "",
73
+ children ? " {" : "",
74
+ children ? format(children, indent + " ") : "",
75
+ children ? " }" : ""
76
+ ].join("");
77
+ }).join("\n");
78
+ }
79
+ function inspect() {
80
+ return format(this);
81
+ }
82
+ function pretty(query) {
83
+ return JSON.stringify(query, null, 4).replace(/\[(\s*)([\s\S]*?)\},*/g, (_, space, inner) => "[" + space + inner.replace(/\n\s+/g, " ") + "},").replace(/[^\u0020-\u007e,\u000a]/g, (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4));
84
+ }
85
+ exports.format = format;
86
+ exports.inspect = inspect;
87
+ exports.mockBackend = mockBackend;
88
+ exports.pretty = pretty;
package/index.mjs CHANGED
@@ -1 +1,82 @@
1
- var r=Object.getOwnPropertySymbols,e=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;import{makeWatcher as t,merge as a}from"@graffy/common";function i(r={}){const e=[],n=t(),i={state:e,read:()=>e,watch:()=>n.watch(r.liveQuery?e:void 0),write:r=>(a(e,r),n.write(r),r),middleware:r=>{r.on("read",i.read),r.on("watch",i.watch),r.on("write",i.write)}};return i}function o(r){return""===r?"''":r.replace(/\uffff/g,"𝖋𝖋").replace(/\0/g,"𝖔𝖔")}function c(r,e){return r===e?`${r} ×`:[o(r)," ⋯ ",o(e)].join("")}let l;function u(t,a=""){return t?(""===a&&(l=null),Array.isArray(t)||(t=[t]),t.length?"\n"+t.map((t=>{var i=t,{key:f,end:p,children:s,version:y,path:d,value:g}=i,h=((t,a)=>{var i={};for(var o in t)e.call(t,o)&&a.indexOf(o)<0&&(i[o]=t[o]);if(null!=t&&r)for(var o of r(t))a.indexOf(o)<0&&n.call(t,o)&&(i[o]=t[o]);return i})(i,["key","end","children","version","path","value"]);return[l===y?"":"<@"+(l=y)+">\n",a,p?c(f,p):o(f),d?` ➚${d.join(".")}`:"",g?` ${JSON.stringify(g)}`:"",Object.keys(h).length>0?" "+JSON.stringify(h):"",s?" {":"",s?u(s,a+" "):"",s?" }":""].join("")})).join("\n"):"[]"):t}function f(){return u(this)}function p(r){return JSON.stringify(r,null,4).replace(/\[(\s*)([\s\S]*?)\},*/g,((r,e,n)=>"["+e+n.replace(/\n\s+/g," ")+"},")).replace(/[^\u0020-\u007e,\u000a]/g,(r=>"\\u"+r.charCodeAt(0).toString(16).padStart(4)))}export{u as format,f as inspect,i as mockBackend,p as pretty};
1
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
4
+ var __objRest = (source, exclude) => {
5
+ var target = {};
6
+ for (var prop in source)
7
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
8
+ target[prop] = source[prop];
9
+ if (source != null && __getOwnPropSymbols)
10
+ for (var prop of __getOwnPropSymbols(source)) {
11
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12
+ target[prop] = source[prop];
13
+ }
14
+ return target;
15
+ };
16
+ import { makeWatcher, merge } from "@graffy/common";
17
+ function mockBackend(options = {}) {
18
+ const state = [];
19
+ const watcher = makeWatcher();
20
+ const backend = {
21
+ state,
22
+ read: () => state,
23
+ watch: () => watcher.watch(options.liveQuery ? state : void 0),
24
+ write: (change) => {
25
+ merge(state, change);
26
+ watcher.write(change);
27
+ return change;
28
+ }
29
+ };
30
+ backend.middleware = (store) => {
31
+ store.on("read", backend.read);
32
+ store.on("watch", backend.watch);
33
+ store.on("write", backend.write);
34
+ };
35
+ return backend;
36
+ }
37
+ function escape(string) {
38
+ if (string === "")
39
+ return "''";
40
+ return string.replace(/\uffff/g, "\u{1D58B}\u{1D58B}").replace(/\0/g, "\u{1D594}\u{1D594}");
41
+ }
42
+ function interval(key, end) {
43
+ if (key === end)
44
+ return `${key} \xD7`;
45
+ return [
46
+ escape(key),
47
+ " \u22EF ",
48
+ escape(end)
49
+ ].join("");
50
+ }
51
+ let lastPrintedVersion;
52
+ function format(graph, indent = "") {
53
+ if (!graph)
54
+ return graph;
55
+ if (indent === "")
56
+ lastPrintedVersion = null;
57
+ if (!Array.isArray(graph))
58
+ graph = [graph];
59
+ if (!graph.length)
60
+ return "[]";
61
+ return "\n" + graph.map((_a) => {
62
+ var _b = _a, { key, end, children, version, path, value } = _b, rest = __objRest(_b, ["key", "end", "children", "version", "path", "value"]);
63
+ return [
64
+ lastPrintedVersion === version ? "" : "<@" + (lastPrintedVersion = version) + ">\n",
65
+ indent,
66
+ end ? interval(key, end) : escape(key),
67
+ path ? ` \u279A${path.join(".")}` : "",
68
+ value ? ` ${JSON.stringify(value)}` : "",
69
+ Object.keys(rest).length > 0 ? " " + JSON.stringify(rest) : "",
70
+ children ? " {" : "",
71
+ children ? format(children, indent + " ") : "",
72
+ children ? " }" : ""
73
+ ].join("");
74
+ }).join("\n");
75
+ }
76
+ function inspect() {
77
+ return format(this);
78
+ }
79
+ function pretty(query) {
80
+ return JSON.stringify(query, null, 4).replace(/\[(\s*)([\s\S]*?)\},*/g, (_, space, inner) => "[" + space + inner.replace(/\n\s+/g, " ") + "},").replace(/[^\u0020-\u007e,\u000a]/g, (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4));
81
+ }
82
+ export { format, inspect, mockBackend, pretty };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graffy/testing",
3
3
  "description": "Testing and debugging utilities for Graffy.",
4
4
  "author": "aravind (https://github.com/aravindet)",
5
- "version": "0.15.8-alpha.5",
5
+ "version": "0.15.8",
6
6
  "main": "./index.cjs",
7
7
  "exports": {
8
8
  "import": "./index.mjs",
@@ -16,6 +16,6 @@
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "dependencies": {
19
- "@graffy/common": "0.15.8-alpha.5"
19
+ "@graffy/common": "0.15.8"
20
20
  }
21
21
  }