@graffy/testing 0.15.25-alpha.5 → 0.15.25-alpha.6

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 (2) hide show
  1. package/index.cjs +93 -0
  2. package/package.json +8 -3
package/index.cjs ADDED
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const common = require("@graffy/common");
4
+ function mockBackend(options = {}) {
5
+ const state = [];
6
+ const watcher = common.makeWatcher();
7
+ const backend = {
8
+ state,
9
+ read: (query) => common.slice(state, query).known,
10
+ watch: () => watcher.watch(options.liveQuery ? state : void 0),
11
+ write: (change) => {
12
+ common.merge(state, change);
13
+ watcher.write(change);
14
+ return change;
15
+ }
16
+ };
17
+ backend.middleware = (store) => {
18
+ store.on("read", backend.read);
19
+ store.on("watch", backend.watch);
20
+ store.on("write", backend.write);
21
+ };
22
+ return backend;
23
+ }
24
+ function escape(string) {
25
+ if (string === "")
26
+ return "''";
27
+ return string.replace(/\uffff/g, "\u{1D58B}\u{1D58B}").replace(/\0/g, "\u{1D594}\u{1D594}");
28
+ }
29
+ function interval(key, end) {
30
+ if (key === end)
31
+ return `${key} \xD7`;
32
+ return [
33
+ escape(key),
34
+ " \u22EF ",
35
+ escape(end)
36
+ ].join("");
37
+ }
38
+ let lastPrintedVersion;
39
+ function format(graph, indent = "") {
40
+ if (!graph)
41
+ return graph;
42
+ if (indent === "")
43
+ lastPrintedVersion = null;
44
+ if (!Array.isArray(graph))
45
+ graph = [graph];
46
+ if (!graph.length)
47
+ return "[]";
48
+ return "\n" + graph.map(
49
+ ({ key, end, children, version, path, value, ...rest }) => [
50
+ lastPrintedVersion === version ? "" : "<@" + (lastPrintedVersion = version) + ">\n",
51
+ indent,
52
+ end ? interval(key, end) : escape(key),
53
+ path ? ` \u279A${path.join(".")}` : "",
54
+ value ? ` ${JSON.stringify(value)}` : "",
55
+ Object.keys(rest).length > 0 ? " " + JSON.stringify(rest) : "",
56
+ children ? " {" : "",
57
+ children ? format(children, indent + " ") : "",
58
+ children ? " }" : ""
59
+ ].join("")
60
+ ).join("\n");
61
+ }
62
+ function inspect() {
63
+ return format(this);
64
+ }
65
+ function pretty(query) {
66
+ return JSON.stringify(query, null, 4).replace(
67
+ /\[(\s*)([\s\S]*?)\},*/g,
68
+ (_, space, inner) => "[" + space + inner.replace(/\n\s+/g, " ") + "},"
69
+ ).replace(
70
+ /[^\u0020-\u007e,\u000a]/g,
71
+ (char) => "\\u" + char.charCodeAt(0).toString(16).padStart(4)
72
+ );
73
+ }
74
+ const put = (obj) => {
75
+ Object.defineProperty(obj, "$put", { value: true });
76
+ return obj;
77
+ };
78
+ const ref = ($ref, obj = {}) => {
79
+ Object.defineProperty(obj, "$ref", { value: $ref });
80
+ return obj;
81
+ };
82
+ const keyref = ($key, $ref, obj = {}) => {
83
+ obj.$key = $key;
84
+ ref($ref, obj);
85
+ return obj;
86
+ };
87
+ exports.format = format;
88
+ exports.inspect = inspect;
89
+ exports.keyref = keyref;
90
+ exports.mockBackend = mockBackend;
91
+ exports.pretty = pretty;
92
+ exports.put = put;
93
+ exports.ref = ref;
package/package.json CHANGED
@@ -2,8 +2,13 @@
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.25-alpha.5",
6
- "main": "./index.mjs",
5
+ "version": "0.15.25-alpha.6",
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,6 +16,6 @@
11
16
  },
12
17
  "license": "Apache-2.0",
13
18
  "dependencies": {
14
- "@graffy/common": "0.15.25-alpha.5"
19
+ "@graffy/common": "0.15.25-alpha.6"
15
20
  }
16
21
  }