@iamjulianacosta/mobx-data 1.1.0 → 1.4.0
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/README.md +273 -102
- package/dist/{CacheHandler-BTU_rYkv.js → CacheHandler-BhfbVHed.js} +17 -20
- package/dist/CacheHandler-BhfbVHed.js.map +1 -0
- package/dist/{CacheHandler-CXgY9IJo.cjs → CacheHandler-Q5VXOgh9.cjs} +2 -2
- package/dist/CacheHandler-Q5VXOgh9.cjs.map +1 -0
- package/dist/EmbeddedRecordsMixin-6mSCXsJ3.js +173 -0
- package/dist/EmbeddedRecordsMixin-6mSCXsJ3.js.map +1 -0
- package/dist/EmbeddedRecordsMixin-BkF7MdbY.cjs +2 -0
- package/dist/EmbeddedRecordsMixin-BkF7MdbY.cjs.map +1 -0
- package/dist/{JsonApiSerializer-BLoE046A.js → JsonApiSerializer-BV61cFAZ.js} +3 -3
- package/dist/JsonApiSerializer-BV61cFAZ.js.map +1 -0
- package/dist/{JsonApiSerializer-DKemcyw-.cjs → JsonApiSerializer-Dt_Y_FIo.cjs} +2 -2
- package/dist/JsonApiSerializer-Dt_Y_FIo.cjs.map +1 -0
- package/dist/JsonSerializer-BzUCyUSf.cjs +2 -0
- package/dist/JsonSerializer-BzUCyUSf.cjs.map +1 -0
- package/dist/JsonSerializer-CFqo6GjC.js +98 -0
- package/dist/JsonSerializer-CFqo6GjC.js.map +1 -0
- package/dist/MdqlMemoryExecutor-BUlsalKm.cjs +2 -0
- package/dist/MdqlMemoryExecutor-BUlsalKm.cjs.map +1 -0
- package/dist/MdqlMemoryExecutor-BWMP31zG.js +127 -0
- package/dist/MdqlMemoryExecutor-BWMP31zG.js.map +1 -0
- package/dist/{MemoryAdapter-Bp-BGHH3.js → MemoryAdapter-BW1HKixm.js} +2 -2
- package/dist/{MemoryAdapter-Bp-BGHH3.js.map → MemoryAdapter-BW1HKixm.js.map} +1 -1
- package/dist/{MemoryAdapter-DH-gzSSl.cjs → MemoryAdapter-C8iXAa2v.cjs} +2 -2
- package/dist/{MemoryAdapter-DH-gzSSl.cjs.map → MemoryAdapter-C8iXAa2v.cjs.map} +1 -1
- package/dist/{ODataAdapter-RQUjVTcf.js → ODataAdapter-CeBJblLQ.js} +25 -22
- package/dist/ODataAdapter-CeBJblLQ.js.map +1 -0
- package/dist/{ODataAdapter-CrDFvBEZ.cjs → ODataAdapter-DdE6MWkG.cjs} +2 -2
- package/dist/ODataAdapter-DdE6MWkG.cjs.map +1 -0
- package/dist/RestAdapter-D7GSrsJo.cjs +2 -0
- package/dist/RestAdapter-D7GSrsJo.cjs.map +1 -0
- package/dist/{RestAdapter-D6bGIHZT.js → RestAdapter-DYUoyV5h.js} +112 -77
- package/dist/RestAdapter-DYUoyV5h.js.map +1 -0
- package/dist/SchemaService-C_pkh-vI.js +180 -0
- package/dist/SchemaService-C_pkh-vI.js.map +1 -0
- package/dist/SchemaService-DbJLoYb9.cjs +2 -0
- package/dist/SchemaService-DbJLoYb9.cjs.map +1 -0
- package/dist/Serializer-Bap9U-kR.cjs +2 -0
- package/dist/Serializer-Bap9U-kR.cjs.map +1 -0
- package/dist/{Serializer-FxJbsZ50.js → Serializer-Ca6w_QNQ.js} +63 -49
- package/dist/Serializer-Ca6w_QNQ.js.map +1 -0
- package/dist/adapter/index.cjs +1 -1
- package/dist/adapter/index.js +2 -2
- package/dist/createStore-7PecKT54.cjs +2 -0
- package/dist/createStore-7PecKT54.cjs.map +1 -0
- package/dist/createStore-BfmRfZ_2.js +1229 -0
- package/dist/createStore-BfmRfZ_2.js.map +1 -0
- package/dist/date-Bj4O2W1F.js.map +1 -1
- package/dist/date-CRCe-9gf.cjs.map +1 -1
- package/dist/decorators-CKneHgoF.js +56 -0
- package/dist/decorators-CKneHgoF.js.map +1 -0
- package/dist/decorators-DCVYKzrL.cjs +2 -0
- package/dist/decorators-DCVYKzrL.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -90
- package/dist/index.js.map +1 -1
- package/dist/inspector/ConsoleInspector.d.ts +49 -0
- package/dist/inspector/ConsoleInspector.d.ts.map +1 -0
- package/dist/inspector/DevToolsBridge.d.ts +21 -0
- package/dist/inspector/DevToolsBridge.d.ts.map +1 -0
- package/dist/inspector/QueryParser.d.ts +21 -0
- package/dist/inspector/QueryParser.d.ts.map +1 -0
- package/dist/inspector/StoreInspector.d.ts +31 -0
- package/dist/inspector/StoreInspector.d.ts.map +1 -0
- package/dist/inspector/index.cjs +17 -0
- package/dist/inspector/index.cjs.map +1 -0
- package/dist/inspector/index.d.ts +9 -0
- package/dist/inspector/index.d.ts.map +1 -0
- package/dist/inspector/index.js +896 -0
- package/dist/inspector/index.js.map +1 -0
- package/dist/inspector/integration.d.ts +15 -0
- package/dist/inspector/integration.d.ts.map +1 -0
- package/dist/inspector/serialization.d.ts +7 -0
- package/dist/inspector/serialization.d.ts.map +1 -0
- package/dist/inspector/types.d.ts +139 -0
- package/dist/inspector/types.d.ts.map +1 -0
- package/dist/json-api/index.cjs +1 -1
- package/dist/json-api/index.js +1 -1
- package/dist/mdql/MdqlMemoryExecutor.d.ts +17 -0
- package/dist/mdql/MdqlMemoryExecutor.d.ts.map +1 -0
- package/dist/mdql/MdqlQueryBuilder.d.ts +38 -0
- package/dist/mdql/MdqlQueryBuilder.d.ts.map +1 -0
- package/dist/mdql/MdqlValidator.d.ts +13 -0
- package/dist/mdql/MdqlValidator.d.ts.map +1 -0
- package/dist/mdql/index.d.ts +6 -0
- package/dist/mdql/index.d.ts.map +1 -0
- package/dist/mdql/types.d.ts +48 -0
- package/dist/mdql/types.d.ts.map +1 -0
- package/dist/model/Model.d.ts +4 -0
- package/dist/model/Model.d.ts.map +1 -1
- package/dist/model/Snapshot.d.ts +2 -0
- package/dist/model/Snapshot.d.ts.map +1 -1
- package/dist/model/index.cjs +1 -1
- package/dist/model/index.js +1 -1
- package/dist/odata/ODataAdapter.d.ts.map +1 -1
- package/dist/odata/index.cjs +1 -1
- package/dist/odata/index.js +1 -1
- package/dist/relationships-BgM0NKdb.cjs +2 -0
- package/dist/relationships-BgM0NKdb.cjs.map +1 -0
- package/dist/{relationships-BEXANmWg.js → relationships-DvSi8fVN.js} +37 -28
- package/dist/relationships-DvSi8fVN.js.map +1 -0
- package/dist/request/CacheHandler.d.ts.map +1 -1
- package/dist/request/index.cjs +1 -1
- package/dist/request/index.js +1 -1
- package/dist/schema/SchemaService.d.ts +38 -1
- package/dist/schema/SchemaService.d.ts.map +1 -1
- package/dist/schema/decorators.d.ts +20 -1
- package/dist/schema/decorators.d.ts.map +1 -1
- package/dist/schema/index.cjs +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +10 -8
- package/dist/schema/types.d.ts +31 -0
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/serializer/JsonSerializer.d.ts +2 -0
- package/dist/serializer/JsonSerializer.d.ts.map +1 -1
- package/dist/serializer/Serializer.d.ts +9 -0
- package/dist/serializer/Serializer.d.ts.map +1 -1
- package/dist/serializer/index.cjs +1 -1
- package/dist/serializer/index.js +6 -5
- package/dist/serializer/index.js.map +1 -1
- package/dist/store/Store.d.ts +3 -0
- package/dist/store/Store.d.ts.map +1 -1
- package/dist/store/createStore.d.ts +12 -0
- package/dist/store/createStore.d.ts.map +1 -0
- package/dist/store/index.cjs +1 -1
- package/dist/store/index.d.ts +1 -0
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +5 -4
- package/dist/types-CC2fG3FP.js +8 -0
- package/dist/types-CC2fG3FP.js.map +1 -0
- package/dist/types-DCLy5XYj.cjs +2 -0
- package/dist/types-DCLy5XYj.cjs.map +1 -0
- package/package.json +7 -1
- package/src/index.ts +3 -0
- package/src/inspector/ConsoleInspector.ts +470 -0
- package/src/inspector/DevToolsBridge.ts +214 -0
- package/src/inspector/QueryParser.ts +343 -0
- package/src/inspector/StoreInspector.ts +162 -0
- package/src/inspector/index.ts +20 -0
- package/src/inspector/integration.ts +56 -0
- package/src/inspector/serialization.ts +100 -0
- package/src/inspector/types.ts +161 -0
- package/src/mdql/MdqlMemoryExecutor.ts +229 -0
- package/src/mdql/MdqlQueryBuilder.ts +170 -0
- package/src/mdql/MdqlValidator.ts +193 -0
- package/src/mdql/index.ts +21 -0
- package/src/mdql/types.ts +107 -0
- package/src/model/Model.ts +15 -0
- package/src/model/Snapshot.ts +3 -0
- package/src/odata/ODataAdapter.ts +4 -1
- package/src/request/CacheHandler.ts +2 -6
- package/src/schema/SchemaService.ts +123 -1
- package/src/schema/decorators.ts +29 -0
- package/src/schema/index.ts +1 -1
- package/src/schema/types.ts +34 -0
- package/src/serializer/JsonSerializer.ts +14 -2
- package/src/serializer/Serializer.ts +24 -1
- package/src/store/Store.ts +57 -14
- package/src/store/createStore.ts +39 -0
- package/src/store/index.ts +1 -0
- package/dist/CacheHandler-BTU_rYkv.js.map +0 -1
- package/dist/CacheHandler-CXgY9IJo.cjs.map +0 -1
- package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs +0 -2
- package/dist/EmbeddedRecordsMixin-CBvqNdgC.cjs.map +0 -1
- package/dist/EmbeddedRecordsMixin-VoHluHCT.js +0 -261
- package/dist/EmbeddedRecordsMixin-VoHluHCT.js.map +0 -1
- package/dist/JsonApiSerializer-BLoE046A.js.map +0 -1
- package/dist/JsonApiSerializer-DKemcyw-.cjs.map +0 -1
- package/dist/ODataAdapter-CrDFvBEZ.cjs.map +0 -1
- package/dist/ODataAdapter-RQUjVTcf.js.map +0 -1
- package/dist/RestAdapter-CSoJg7D2.cjs +0 -2
- package/dist/RestAdapter-CSoJg7D2.cjs.map +0 -1
- package/dist/RestAdapter-D6bGIHZT.js.map +0 -1
- package/dist/SchemaService-DZwkFgZu.js +0 -102
- package/dist/SchemaService-DZwkFgZu.js.map +0 -1
- package/dist/SchemaService-Di_yjVzU.cjs +0 -2
- package/dist/SchemaService-Di_yjVzU.cjs.map +0 -1
- package/dist/Serializer-95gi5edy.cjs +0 -2
- package/dist/Serializer-95gi5edy.cjs.map +0 -1
- package/dist/Serializer-FxJbsZ50.js.map +0 -1
- package/dist/Store-Bm5JivTc.js +0 -957
- package/dist/Store-Bm5JivTc.js.map +0 -1
- package/dist/Store-DX9D0Mmy.cjs +0 -2
- package/dist/Store-DX9D0Mmy.cjs.map +0 -1
- package/dist/cache-utils-B2wFhisx.js +0 -39
- package/dist/cache-utils-B2wFhisx.js.map +0 -1
- package/dist/cache-utils-CSwsqOi3.cjs +0 -2
- package/dist/cache-utils-CSwsqOi3.cjs.map +0 -1
- package/dist/decorators-HQ1KnRdh.cjs +0 -2
- package/dist/decorators-HQ1KnRdh.cjs.map +0 -1
- package/dist/decorators-Zr35qr6A.js +0 -50
- package/dist/decorators-Zr35qr6A.js.map +0 -1
- package/dist/relationships-B55LBaCW.cjs +0 -2
- package/dist/relationships-B55LBaCW.cjs.map +0 -1
- package/dist/relationships-BEXANmWg.js.map +0 -1
- package/dist/types-C9NB2gRj.js +0 -7
- package/dist/types-C9NB2gRj.js.map +0 -1
- package/dist/types-uWOXMPWW.cjs +0 -2
- package/dist/types-uWOXMPWW.cjs.map +0 -1
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
import { reaction as C } from "mobx";
|
|
2
|
+
import { M as D } from "../MdqlMemoryExecutor-BWMP31zG.js";
|
|
3
|
+
const L = /* @__PURE__ */ new Set([
|
|
4
|
+
"where",
|
|
5
|
+
"and",
|
|
6
|
+
"or",
|
|
7
|
+
"not",
|
|
8
|
+
"order",
|
|
9
|
+
"by",
|
|
10
|
+
"sort",
|
|
11
|
+
"limit",
|
|
12
|
+
"offset",
|
|
13
|
+
"is",
|
|
14
|
+
"null",
|
|
15
|
+
"in",
|
|
16
|
+
"between",
|
|
17
|
+
"asc",
|
|
18
|
+
"desc",
|
|
19
|
+
"contains",
|
|
20
|
+
"startswith",
|
|
21
|
+
"endswith"
|
|
22
|
+
]), S = {
|
|
23
|
+
"=": "equals",
|
|
24
|
+
"==": "equals",
|
|
25
|
+
"!=": "notEquals",
|
|
26
|
+
"<>": "notEquals",
|
|
27
|
+
">": "greaterThan",
|
|
28
|
+
">=": "greaterThanOrEquals",
|
|
29
|
+
"<": "lessThan",
|
|
30
|
+
"<=": "lessThanOrEquals",
|
|
31
|
+
"~": "contains",
|
|
32
|
+
"^=": "startsWith",
|
|
33
|
+
"$=": "endsWith",
|
|
34
|
+
contains: "contains",
|
|
35
|
+
startswith: "startsWith",
|
|
36
|
+
endswith: "endsWith"
|
|
37
|
+
}, $ = /* @__PURE__ */ new Set(["=", "!", "<", ">", "~", "^", "$"]);
|
|
38
|
+
class b {
|
|
39
|
+
static parse(e) {
|
|
40
|
+
return new b(e).parseQuery();
|
|
41
|
+
}
|
|
42
|
+
constructor(e) {
|
|
43
|
+
this.tokens = b.tokenize(e), this.position = 0;
|
|
44
|
+
}
|
|
45
|
+
static tokenize(e) {
|
|
46
|
+
const s = [];
|
|
47
|
+
let t = 0;
|
|
48
|
+
for (; t < e.length; ) {
|
|
49
|
+
if (e[t] === " " || e[t] === " ") {
|
|
50
|
+
t++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (e[t] === "[" || e[t] === "]" || e[t] === ",") {
|
|
54
|
+
s.push({ type: "bracket", value: e[t], raw: e[t] }), t++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (e[t] === '"' || e[t] === "'") {
|
|
58
|
+
const o = e[t];
|
|
59
|
+
let i = "";
|
|
60
|
+
for (t++; t < e.length && e[t] !== o; )
|
|
61
|
+
e[t] === "\\" && t + 1 < e.length && t++, i += e[t], t++;
|
|
62
|
+
t++, s.push({ type: "string", value: i, raw: i });
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if ($.has(e[t])) {
|
|
66
|
+
let o = "";
|
|
67
|
+
for (; t < e.length && $.has(e[t]); )
|
|
68
|
+
o += e[t], t++;
|
|
69
|
+
s.push({ type: "operator", value: o, raw: o });
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
let r = "";
|
|
73
|
+
for (; t < e.length && e[t] !== " " && e[t] !== " " && !$.has(e[t]) && e[t] !== "[" && e[t] !== "]" && e[t] !== ","; )
|
|
74
|
+
r += e[t], t++;
|
|
75
|
+
if (r === "") {
|
|
76
|
+
t++;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const n = r.toLowerCase();
|
|
80
|
+
if (n === "null")
|
|
81
|
+
s.push({ type: "null", value: "null", raw: null });
|
|
82
|
+
else if (L.has(n))
|
|
83
|
+
s.push({ type: "keyword", value: n, raw: r });
|
|
84
|
+
else {
|
|
85
|
+
const o = Number(r);
|
|
86
|
+
!Number.isNaN(o) && r !== "" ? s.push({ type: "number", value: r, raw: o }) : s.push({ type: "identifier", value: r, raw: r });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return s;
|
|
90
|
+
}
|
|
91
|
+
peek() {
|
|
92
|
+
return this.tokens[this.position] ?? null;
|
|
93
|
+
}
|
|
94
|
+
advance() {
|
|
95
|
+
const e = this.tokens[this.position] ?? null;
|
|
96
|
+
return this.position++, e;
|
|
97
|
+
}
|
|
98
|
+
expect(e, s) {
|
|
99
|
+
const t = this.advance();
|
|
100
|
+
if (!t || t.type !== e || s !== void 0 && t.value !== s) {
|
|
101
|
+
const r = t ? `${t.type}:${t.value}` : "end of input";
|
|
102
|
+
throw new Error(`Expected ${e}${s ? `:${s}` : ""}, got ${r}`);
|
|
103
|
+
}
|
|
104
|
+
return t;
|
|
105
|
+
}
|
|
106
|
+
expectNullToken() {
|
|
107
|
+
const e = this.advance();
|
|
108
|
+
if (!e || e.type !== "null" && e.value !== "null") {
|
|
109
|
+
const s = e ? `${e.type}:${e.value}` : "end of input";
|
|
110
|
+
throw new Error(`Expected null, got ${s}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
matchKeyword(e) {
|
|
114
|
+
const s = this.peek();
|
|
115
|
+
return (s == null ? void 0 : s.type) === "keyword" && s.value === e ? (this.advance(), !0) : !1;
|
|
116
|
+
}
|
|
117
|
+
parseQuery() {
|
|
118
|
+
const e = this.advance();
|
|
119
|
+
if (!e) throw new Error("Expected model name");
|
|
120
|
+
const s = e.value;
|
|
121
|
+
let t = { kind: "and", children: [] };
|
|
122
|
+
const r = [];
|
|
123
|
+
let n = null, o = null;
|
|
124
|
+
return this.matchKeyword("where") && (t = this.parseFilterExpression()), this.matchKeyword("order") ? (this.expect("keyword", "by"), this.parseOrderBy(r)) : this.matchKeyword("sort") && this.parseOrderBy(r), this.matchKeyword("limit") && (n = this.expect("number").raw), this.matchKeyword("offset") && (o = this.expect("number").raw), { modelName: s, filters: t, orderBy: r, limit: n, offset: o, includes: [] };
|
|
125
|
+
}
|
|
126
|
+
parseFilterExpression() {
|
|
127
|
+
const e = this.parseCondition(), s = [e];
|
|
128
|
+
let t = "and";
|
|
129
|
+
for (; this.peek(); ) {
|
|
130
|
+
const r = this.peek();
|
|
131
|
+
if (r.type === "keyword" && r.value === "and")
|
|
132
|
+
this.advance(), t = "and", s.push(this.parseCondition());
|
|
133
|
+
else if (r.type === "keyword" && r.value === "or")
|
|
134
|
+
this.advance(), t = "or", s.push(this.parseCondition());
|
|
135
|
+
else
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
return s.length === 1 && e.kind !== "condition" ? e : { kind: t, children: s };
|
|
139
|
+
}
|
|
140
|
+
parseCondition() {
|
|
141
|
+
var o, i, l, h, p, u;
|
|
142
|
+
if (this.matchKeyword("not"))
|
|
143
|
+
return { kind: "not", children: [this.parseCondition()] };
|
|
144
|
+
const e = this.advance();
|
|
145
|
+
if (!e) throw new Error("Expected field name");
|
|
146
|
+
const s = e.value;
|
|
147
|
+
if (((o = this.peek()) == null ? void 0 : o.type) === "keyword" && ((i = this.peek()) == null ? void 0 : i.value) === "is")
|
|
148
|
+
return this.advance(), this.matchKeyword("not") ? (this.expectNullToken(), { kind: "condition", field: s, operator: "isNotNull", value: void 0 }) : (this.expectNullToken(), { kind: "condition", field: s, operator: "isNull", value: void 0 });
|
|
149
|
+
if (((l = this.peek()) == null ? void 0 : l.type) === "keyword" && ((h = this.peek()) == null ? void 0 : h.value) === "in") {
|
|
150
|
+
this.advance();
|
|
151
|
+
const f = this.parseArray();
|
|
152
|
+
return { kind: "condition", field: s, operator: "in", value: f };
|
|
153
|
+
}
|
|
154
|
+
if (((p = this.peek()) == null ? void 0 : p.type) === "keyword" && ((u = this.peek()) == null ? void 0 : u.value) === "between") {
|
|
155
|
+
this.advance();
|
|
156
|
+
const f = this.parseValue(), _ = this.parseValue();
|
|
157
|
+
return { kind: "condition", field: s, operator: "between", value: [f, _] };
|
|
158
|
+
}
|
|
159
|
+
const t = this.advance();
|
|
160
|
+
if (!t) throw new Error(`Expected operator after field "${s}"`);
|
|
161
|
+
let r;
|
|
162
|
+
if (t.type === "operator") {
|
|
163
|
+
if (r = S[t.value], !r) throw new Error(`Unknown operator: ${t.value}`);
|
|
164
|
+
} else if (t.type === "keyword" && S[t.value])
|
|
165
|
+
r = S[t.value];
|
|
166
|
+
else
|
|
167
|
+
throw new Error(`Expected operator, got ${t.type}:${t.value}`);
|
|
168
|
+
const n = this.parseValue();
|
|
169
|
+
return { kind: "condition", field: s, operator: r, value: n };
|
|
170
|
+
}
|
|
171
|
+
parseOrderBy(e) {
|
|
172
|
+
var t, r;
|
|
173
|
+
const s = this.advance();
|
|
174
|
+
if (!s) throw new Error("Expected field name after order by / sort");
|
|
175
|
+
for (e.push({
|
|
176
|
+
field: s.value,
|
|
177
|
+
direction: this.parseDirection()
|
|
178
|
+
}); ((t = this.peek()) == null ? void 0 : t.type) === "bracket" && ((r = this.peek()) == null ? void 0 : r.value) === ","; ) {
|
|
179
|
+
this.advance();
|
|
180
|
+
const n = this.advance();
|
|
181
|
+
if (!n) break;
|
|
182
|
+
e.push({
|
|
183
|
+
field: n.value,
|
|
184
|
+
direction: this.parseDirection()
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
parseDirection() {
|
|
189
|
+
const e = this.peek();
|
|
190
|
+
return (e == null ? void 0 : e.type) === "keyword" && (e.value === "asc" || e.value === "desc") ? (this.advance(), e.value) : "asc";
|
|
191
|
+
}
|
|
192
|
+
parseValue() {
|
|
193
|
+
const e = this.advance();
|
|
194
|
+
if (!e) throw new Error("Expected value");
|
|
195
|
+
if (e.type === "string" || e.type === "number") return e.raw;
|
|
196
|
+
if (e.type === "null" || e.type === "keyword" && e.value === "null") return null;
|
|
197
|
+
if (e.type === "identifier") return e.value;
|
|
198
|
+
throw new Error(`Unexpected value token: ${e.type}:${e.value}`);
|
|
199
|
+
}
|
|
200
|
+
parseArray() {
|
|
201
|
+
var s, t, r, n, o, i, l, h, p, u, f;
|
|
202
|
+
const e = [];
|
|
203
|
+
if (((s = this.peek()) == null ? void 0 : s.type) === "bracket" && ((t = this.peek()) == null ? void 0 : t.value) === "[") {
|
|
204
|
+
for (this.advance(); this.peek() && !(((r = this.peek()) == null ? void 0 : r.type) === "bracket" && ((n = this.peek()) == null ? void 0 : n.value) === "]"); ) {
|
|
205
|
+
if (((o = this.peek()) == null ? void 0 : o.type) === "bracket" && ((i = this.peek()) == null ? void 0 : i.value) === ",") {
|
|
206
|
+
this.advance();
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
e.push(this.parseValue());
|
|
210
|
+
}
|
|
211
|
+
((l = this.peek()) == null ? void 0 : l.type) === "bracket" && ((h = this.peek()) == null ? void 0 : h.value) === "]" && this.advance();
|
|
212
|
+
} else
|
|
213
|
+
for (; this.peek() && ((p = this.peek()) == null ? void 0 : p.type) !== "keyword"; ) {
|
|
214
|
+
if (((u = this.peek()) == null ? void 0 : u.type) === "bracket" && ((f = this.peek()) == null ? void 0 : f.value) === ",") {
|
|
215
|
+
this.advance();
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
e.push(this.parseValue());
|
|
219
|
+
}
|
|
220
|
+
return e;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function y(a) {
|
|
224
|
+
return {
|
|
225
|
+
modelName: a.modelName,
|
|
226
|
+
id: a.id,
|
|
227
|
+
clientId: a._clientId,
|
|
228
|
+
currentState: a.currentState,
|
|
229
|
+
isNew: a.isNew,
|
|
230
|
+
isDirty: a.isDirty,
|
|
231
|
+
isDeleted: a.isDeleted,
|
|
232
|
+
isError: a.isError,
|
|
233
|
+
isLoading: a.isLoading,
|
|
234
|
+
isSaving: a.isSaving,
|
|
235
|
+
hasDirtyAttributes: a.hasDirtyAttributes,
|
|
236
|
+
hasErrors: !a.isValid
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function E(a) {
|
|
240
|
+
const e = a, s = {};
|
|
241
|
+
if (e._relationships)
|
|
242
|
+
for (const [o, i] of e._relationships)
|
|
243
|
+
s[o] = i;
|
|
244
|
+
const t = [];
|
|
245
|
+
for (const [o, i] of a.errors)
|
|
246
|
+
t.push({
|
|
247
|
+
attribute: o,
|
|
248
|
+
messages: i.map((l) => l.message)
|
|
249
|
+
});
|
|
250
|
+
const r = /* @__PURE__ */ Object.create(null);
|
|
251
|
+
for (const o of Object.keys(e._data))
|
|
252
|
+
o === "__proto__" || o === "constructor" || (r[o] = e._data[o]);
|
|
253
|
+
const n = /* @__PURE__ */ Object.create(null);
|
|
254
|
+
for (const o of Object.keys(e._originalData))
|
|
255
|
+
o === "__proto__" || o === "constructor" || (n[o] = e._originalData[o]);
|
|
256
|
+
return {
|
|
257
|
+
...y(a),
|
|
258
|
+
attributes: r,
|
|
259
|
+
originalAttributes: n,
|
|
260
|
+
changedAttributes: a.changedAttributes(),
|
|
261
|
+
relationships: s,
|
|
262
|
+
errors: t
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function I(a, e) {
|
|
266
|
+
const s = a.schema.attributesDefinitionFor(e), t = a.schema.relationshipsDefinitionFor(e), r = a.schema.discriminatorFor(e), n = [];
|
|
267
|
+
for (const [i, l] of s)
|
|
268
|
+
n.push({ name: i, type: l.type });
|
|
269
|
+
const o = [];
|
|
270
|
+
for (const [i, l] of t)
|
|
271
|
+
o.push({
|
|
272
|
+
name: i,
|
|
273
|
+
kind: l.kind,
|
|
274
|
+
type: l.type,
|
|
275
|
+
async: l.options.async ?? !1,
|
|
276
|
+
inverse: l.options.inverse ?? null,
|
|
277
|
+
polymorphic: l.options.polymorphic ?? !1
|
|
278
|
+
});
|
|
279
|
+
return {
|
|
280
|
+
modelName: e,
|
|
281
|
+
isAbstract: a.schema.isAbstract(e),
|
|
282
|
+
discriminator: r ? { key: r.key } : null,
|
|
283
|
+
attributes: n,
|
|
284
|
+
relationships: o
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
class q {
|
|
288
|
+
constructor(e) {
|
|
289
|
+
this.store = e;
|
|
290
|
+
}
|
|
291
|
+
summary() {
|
|
292
|
+
const e = [];
|
|
293
|
+
let s = 0;
|
|
294
|
+
for (const t of this.store.schema.registeredNames()) {
|
|
295
|
+
const r = this.store.peekAll(t).length;
|
|
296
|
+
r > 0 && e.push({ modelName: t, count: r }), s += r;
|
|
297
|
+
}
|
|
298
|
+
return e.sort((t, r) => t.modelName.localeCompare(r.modelName)), { types: e, totalRecords: s };
|
|
299
|
+
}
|
|
300
|
+
records(e) {
|
|
301
|
+
return this.store.peekAll(e).toArray().map(y);
|
|
302
|
+
}
|
|
303
|
+
record(e, s) {
|
|
304
|
+
const t = this.store.identityMap.get(e, s);
|
|
305
|
+
return t ? E(t) : null;
|
|
306
|
+
}
|
|
307
|
+
dirty() {
|
|
308
|
+
return this.allRecordsWhere((e) => e.isDirty);
|
|
309
|
+
}
|
|
310
|
+
newRecords() {
|
|
311
|
+
return this.allRecordsWhere((e) => e.isNew);
|
|
312
|
+
}
|
|
313
|
+
errored() {
|
|
314
|
+
return this.allRecordsWhere((e) => e.isError || !e.isValid);
|
|
315
|
+
}
|
|
316
|
+
saving() {
|
|
317
|
+
return this.allRecordsWhere((e) => e.isSaving);
|
|
318
|
+
}
|
|
319
|
+
schema(e) {
|
|
320
|
+
return I(this.store, e);
|
|
321
|
+
}
|
|
322
|
+
types() {
|
|
323
|
+
return this.store.schema.registeredNames().sort();
|
|
324
|
+
}
|
|
325
|
+
query(e) {
|
|
326
|
+
const s = b.parse(e), t = this.store.peekAll(s.modelName).toArray();
|
|
327
|
+
return D.executeMany(t, s);
|
|
328
|
+
}
|
|
329
|
+
queryWithMeta(e) {
|
|
330
|
+
const s = b.parse(e), t = this.store.peekAll(s.modelName).toArray();
|
|
331
|
+
return {
|
|
332
|
+
modelName: s.modelName,
|
|
333
|
+
results: D.executeMany(t, s)
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
liveModels(e) {
|
|
337
|
+
return this.store.peekAll(e).toArray();
|
|
338
|
+
}
|
|
339
|
+
liveModel(e, s) {
|
|
340
|
+
return this.store.peekRecord(e, s);
|
|
341
|
+
}
|
|
342
|
+
snapshot() {
|
|
343
|
+
return this.store.serialize();
|
|
344
|
+
}
|
|
345
|
+
observe(e) {
|
|
346
|
+
let s = this.captureState();
|
|
347
|
+
return C(
|
|
348
|
+
() => this.captureState(),
|
|
349
|
+
(t) => {
|
|
350
|
+
this.diffAndEmit(s, t, e), s = t;
|
|
351
|
+
},
|
|
352
|
+
{ delay: 100 }
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
allRecordsWhere(e) {
|
|
356
|
+
const s = [];
|
|
357
|
+
for (const t of this.store.schema.registeredNames())
|
|
358
|
+
for (const r of this.store.peekAll(t).toArray())
|
|
359
|
+
e(r) && s.push(y(r));
|
|
360
|
+
return s;
|
|
361
|
+
}
|
|
362
|
+
captureState() {
|
|
363
|
+
const e = /* @__PURE__ */ new Map();
|
|
364
|
+
for (const [s, t] of this.store.identityMap._buckets) {
|
|
365
|
+
const r = /* @__PURE__ */ new Map();
|
|
366
|
+
for (const [n, o] of t)
|
|
367
|
+
r.set(n, o.currentState);
|
|
368
|
+
e.set(s, r);
|
|
369
|
+
}
|
|
370
|
+
return e;
|
|
371
|
+
}
|
|
372
|
+
diffAndEmit(e, s, t) {
|
|
373
|
+
for (const [r, n] of s) {
|
|
374
|
+
const o = e.get(r);
|
|
375
|
+
for (const [i, l] of n)
|
|
376
|
+
o != null && o.has(i) ? o.get(i) !== l && t({ type: "updated", modelName: r, id: i }) : t({ type: "added", modelName: r, id: i });
|
|
377
|
+
}
|
|
378
|
+
for (const [r, n] of e) {
|
|
379
|
+
const o = s.get(r);
|
|
380
|
+
for (const [i] of n)
|
|
381
|
+
o != null && o.has(i) || t({ type: "removed", modelName: r, id: i });
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const m = "color: #2196f3; font-weight: bold", d = "color: #ff9800; font-weight: bold", w = "color: #f44336; font-weight: bold", v = "color: #4caf50", c = "color: inherit";
|
|
386
|
+
function k(a) {
|
|
387
|
+
return a.isError ? "ERROR" : a.isSaving ? "SAVING" : a.isNew ? "NEW" : a.isDirty ? "DIRTY" : a.isDeleted ? "DELETED" : a.isLoading ? "LOADING" : "SAVED";
|
|
388
|
+
}
|
|
389
|
+
function j(a) {
|
|
390
|
+
return a.isError || a.hasErrors ? w : a.isDirty || a.isNew ? d : v;
|
|
391
|
+
}
|
|
392
|
+
const A = /* @__PURE__ */ new Set(["show", "toJSON", "inspect", "summary"]);
|
|
393
|
+
function V(a, e) {
|
|
394
|
+
const s = {
|
|
395
|
+
show() {
|
|
396
|
+
e(a);
|
|
397
|
+
},
|
|
398
|
+
toJSON() {
|
|
399
|
+
const t = E(a);
|
|
400
|
+
return { ...t.attributes, id: t.id, _state: t.currentState };
|
|
401
|
+
},
|
|
402
|
+
inspect() {
|
|
403
|
+
return E(a);
|
|
404
|
+
},
|
|
405
|
+
summary() {
|
|
406
|
+
return y(a);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
return new Proxy(a, {
|
|
410
|
+
get(t, r) {
|
|
411
|
+
return typeof r == "string" && A.has(r) ? s[r] : Reflect.get(t, r);
|
|
412
|
+
},
|
|
413
|
+
has(t, r) {
|
|
414
|
+
return typeof r == "string" && A.has(r) ? !0 : Reflect.has(t, r);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
class P {
|
|
419
|
+
constructor(e, s = "default") {
|
|
420
|
+
this.inspector = new q(e), this.storeName = s;
|
|
421
|
+
}
|
|
422
|
+
summary() {
|
|
423
|
+
const e = this.inspector.summary(), s = this;
|
|
424
|
+
return Object.assign(e, {
|
|
425
|
+
show() {
|
|
426
|
+
s.renderSummary(e);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
records(e) {
|
|
431
|
+
const s = this.inspector.liveModels(e);
|
|
432
|
+
return this.createResultSet(s, () => this.renderRecords(e, this.inspector.records(e)));
|
|
433
|
+
}
|
|
434
|
+
record(e, s) {
|
|
435
|
+
const t = this.inspector.liveModel(e, s);
|
|
436
|
+
return t ? this.wrapModel(t) : null;
|
|
437
|
+
}
|
|
438
|
+
query(e) {
|
|
439
|
+
const { modelName: s, results: t } = this.inspector.queryWithMeta(e);
|
|
440
|
+
return this.createResultSet(t, () => {
|
|
441
|
+
const r = this.inspector.records(s), n = new Map(r.map((i) => [i.id, i])), o = t.map((i) => n.get(i.id)).filter(Boolean);
|
|
442
|
+
this.renderRecords(`${s} (query)`, o.length > 0 ? o : r);
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
dirty() {
|
|
446
|
+
const e = this.collectModels((s) => s.isDirty);
|
|
447
|
+
return this.createResultSet(e, () => this.renderFilteredRecords("Dirty records", e.map(y)));
|
|
448
|
+
}
|
|
449
|
+
newRecords() {
|
|
450
|
+
const e = this.collectModels((s) => s.isNew);
|
|
451
|
+
return this.createResultSet(e, () => this.renderFilteredRecords("New records", e.map(y)));
|
|
452
|
+
}
|
|
453
|
+
saving() {
|
|
454
|
+
const e = this.collectModels((s) => s.isSaving);
|
|
455
|
+
return this.createResultSet(e, () => this.renderFilteredRecords("Saving records", e.map(y)));
|
|
456
|
+
}
|
|
457
|
+
errored() {
|
|
458
|
+
const e = this.collectModels((s) => s.isError || !s.isValid);
|
|
459
|
+
return this.createResultSet(e, () => this.renderFilteredRecords("Errored records", e.map(y)));
|
|
460
|
+
}
|
|
461
|
+
collectModels(e) {
|
|
462
|
+
const s = [];
|
|
463
|
+
for (const t of this.inspector.types())
|
|
464
|
+
for (const r of this.inspector.liveModels(t))
|
|
465
|
+
e(r) && s.push(r);
|
|
466
|
+
return s;
|
|
467
|
+
}
|
|
468
|
+
schema(e) {
|
|
469
|
+
const s = this.inspector.schema(e), t = this;
|
|
470
|
+
return Object.assign(s, {
|
|
471
|
+
show() {
|
|
472
|
+
t.renderSchema(e, s);
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
types() {
|
|
477
|
+
const e = this.inspector.types(), s = this, t = [...e];
|
|
478
|
+
return t.show = () => {
|
|
479
|
+
const r = s.inspector.summary(), n = new Map(r.types.map((o) => [o.modelName, o.count]));
|
|
480
|
+
console.log(`%c[mobx-data] Registered types (${e.length})`, m);
|
|
481
|
+
for (const o of e)
|
|
482
|
+
console.log(` ${o} (${n.get(o) ?? 0})`);
|
|
483
|
+
}, t;
|
|
484
|
+
}
|
|
485
|
+
snapshot() {
|
|
486
|
+
return this.inspector.snapshot();
|
|
487
|
+
}
|
|
488
|
+
observe() {
|
|
489
|
+
return console.log("%c[mobx-data] Live observation started. Call the returned function to stop.", m), this.inspector.observe((e) => {
|
|
490
|
+
const s = e.type === "removed" ? w : e.type === "added" ? v : d, t = e.type.toUpperCase(), r = e.id ?? "(new)", n = e.record ? ` [${k(e.record)}]` : "";
|
|
491
|
+
console.log(`%c[mobx-data] %c${t}%c ${e.modelName}:${r}${n}`, m, s, c);
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
raw() {
|
|
495
|
+
return this.inspector;
|
|
496
|
+
}
|
|
497
|
+
command(e) {
|
|
498
|
+
var o;
|
|
499
|
+
const s = e.trim();
|
|
500
|
+
if (this.isQueryCommand(s)) {
|
|
501
|
+
const i = this.query(s);
|
|
502
|
+
return i.show(), i;
|
|
503
|
+
}
|
|
504
|
+
const t = s.split(/\s+/), r = ((o = t[0]) == null ? void 0 : o.toLowerCase()) ?? "", n = t[1];
|
|
505
|
+
switch (r) {
|
|
506
|
+
case "help":
|
|
507
|
+
case "h":
|
|
508
|
+
case "?":
|
|
509
|
+
this.help();
|
|
510
|
+
return;
|
|
511
|
+
case "summary":
|
|
512
|
+
case "s": {
|
|
513
|
+
const i = this.summary();
|
|
514
|
+
return i.show(), i;
|
|
515
|
+
}
|
|
516
|
+
case "types":
|
|
517
|
+
case "t": {
|
|
518
|
+
const i = this.types();
|
|
519
|
+
return i.show(), i;
|
|
520
|
+
}
|
|
521
|
+
case "dirty":
|
|
522
|
+
case "d": {
|
|
523
|
+
const i = this.dirty();
|
|
524
|
+
return i.show(), i;
|
|
525
|
+
}
|
|
526
|
+
case "saving": {
|
|
527
|
+
const i = this.saving();
|
|
528
|
+
return i.show(), i;
|
|
529
|
+
}
|
|
530
|
+
case "errored":
|
|
531
|
+
case "errors":
|
|
532
|
+
case "e": {
|
|
533
|
+
const i = this.errored();
|
|
534
|
+
return i.show(), i;
|
|
535
|
+
}
|
|
536
|
+
case "schema":
|
|
537
|
+
if (n) {
|
|
538
|
+
const i = this.schema(n);
|
|
539
|
+
return i.show(), i;
|
|
540
|
+
}
|
|
541
|
+
console.log("%c[mobx-data] Usage: schema <type>", w);
|
|
542
|
+
return;
|
|
543
|
+
case "snap":
|
|
544
|
+
case "snapshot":
|
|
545
|
+
return this.snapshot();
|
|
546
|
+
case "watch":
|
|
547
|
+
case "observe":
|
|
548
|
+
return this.observe();
|
|
549
|
+
default:
|
|
550
|
+
return this.resolveModelCommand(r, n);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
help() {
|
|
554
|
+
console.log("%c[mobx-data] CLI commands:", m), console.log(
|
|
555
|
+
`
|
|
556
|
+
%c$m('help')%c Show this help
|
|
557
|
+
%c$m('summary')%c Overview of all types and counts
|
|
558
|
+
%c$m('types')%c List registered model names
|
|
559
|
+
%c$m('user')%c All records (returns live refs)
|
|
560
|
+
%c$m('user 1')%c Single record (live ref)
|
|
561
|
+
%c$m('user where age > 25')%c Query with filters
|
|
562
|
+
%c$m('user where name ~ "Al"')%c Contains search
|
|
563
|
+
%c$m('post where title ~ h sort title')%c Query + sort
|
|
564
|
+
%c$m('dirty')%c All dirty records
|
|
565
|
+
%c$m('saving')%c All records being saved
|
|
566
|
+
%c$m('errored')%c All records with errors
|
|
567
|
+
%c$m('schema user')%c Attribute/relationship metadata
|
|
568
|
+
%c$m('snapshot')%c Full store snapshot
|
|
569
|
+
%c$m('watch')%c Live change logging (returns stop fn)
|
|
570
|
+
`,
|
|
571
|
+
d,
|
|
572
|
+
c,
|
|
573
|
+
d,
|
|
574
|
+
c,
|
|
575
|
+
d,
|
|
576
|
+
c,
|
|
577
|
+
d,
|
|
578
|
+
c,
|
|
579
|
+
d,
|
|
580
|
+
c,
|
|
581
|
+
d,
|
|
582
|
+
c,
|
|
583
|
+
d,
|
|
584
|
+
c,
|
|
585
|
+
d,
|
|
586
|
+
c,
|
|
587
|
+
d,
|
|
588
|
+
c,
|
|
589
|
+
d,
|
|
590
|
+
c,
|
|
591
|
+
d,
|
|
592
|
+
c,
|
|
593
|
+
d,
|
|
594
|
+
c,
|
|
595
|
+
d,
|
|
596
|
+
c,
|
|
597
|
+
d,
|
|
598
|
+
c
|
|
599
|
+
), console.log("%c Operators: = != > >= < <= ~ (contains) ^= (startsWith) $= (endsWith) in between is null", v), console.log("%c All methods return live objects. Use .show() to render, [0] for refs.", v), console.log("%c Shortcuts: s=summary, t=types, d=dirty, e=errored, h=help", v);
|
|
600
|
+
}
|
|
601
|
+
isQueryCommand(e) {
|
|
602
|
+
const s = e.toLowerCase();
|
|
603
|
+
return s.includes(" where ") || s.includes(" sort ") || / order by /i.test(s) || / limit /i.test(s) || / offset /i.test(s);
|
|
604
|
+
}
|
|
605
|
+
resolveModelCommand(e, s) {
|
|
606
|
+
const t = this.inspector.types(), r = t.includes(e) ? e : t.includes(`${e}s`) ? `${e}s` : null;
|
|
607
|
+
if (r) {
|
|
608
|
+
if (s) {
|
|
609
|
+
const o = this.record(r, s);
|
|
610
|
+
return o ? o.show() : console.log(`%c[mobx-data] ${r}:${s} not found`, w), o;
|
|
611
|
+
}
|
|
612
|
+
const n = this.records(r);
|
|
613
|
+
return n.show(), n;
|
|
614
|
+
}
|
|
615
|
+
if (e === "") {
|
|
616
|
+
const n = this.summary();
|
|
617
|
+
return n.show(), n;
|
|
618
|
+
}
|
|
619
|
+
console.log(`%c[mobx-data] Unknown command: "${e}". Try $m('help')`, w);
|
|
620
|
+
}
|
|
621
|
+
wrapModel(e) {
|
|
622
|
+
return V(e, (s) => {
|
|
623
|
+
const t = E(s);
|
|
624
|
+
this.renderRecordDetail(t.modelName, t.id ?? t.clientId, t);
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
createResultSet(e, s) {
|
|
628
|
+
const t = e.map((n) => this.wrapModel(n)), r = t;
|
|
629
|
+
return r.show = s, r.toJSON = () => t.map((n) => n.toJSON()), r;
|
|
630
|
+
}
|
|
631
|
+
renderSummary(e) {
|
|
632
|
+
if (console.log(`%c[mobx-data] Store "${this.storeName}" — ${e.totalRecords} records`, m), e.types.length === 0) {
|
|
633
|
+
console.log(" (empty)");
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
console.table(
|
|
637
|
+
e.types.reduce((s, t) => (s[t.modelName] = { count: t.count }, s), {})
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
renderRecords(e, s) {
|
|
641
|
+
if (console.log(`%c[mobx-data] ${e} — ${s.length} records`, m), s.length === 0) {
|
|
642
|
+
console.log(" (none)");
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
console.table(
|
|
646
|
+
s.map((t) => ({
|
|
647
|
+
id: t.id ?? t.clientId,
|
|
648
|
+
state: k(t),
|
|
649
|
+
isDirty: t.isDirty,
|
|
650
|
+
isNew: t.isNew,
|
|
651
|
+
isSaving: t.isSaving,
|
|
652
|
+
hasErrors: t.hasErrors
|
|
653
|
+
}))
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
renderRecordDetail(e, s, t) {
|
|
657
|
+
const r = k(t), n = j(t);
|
|
658
|
+
console.groupCollapsed(`%c[mobx-data] %c${e}:${s}%c — %c${r}%c (${t.currentState})`, m, c, c, n, c), console.groupCollapsed("Attributes");
|
|
659
|
+
const o = new Set(Object.keys(t.changedAttributes)), i = {};
|
|
660
|
+
for (const [l, h] of Object.entries(t.attributes))
|
|
661
|
+
i[l] = {
|
|
662
|
+
current: h,
|
|
663
|
+
original: t.originalAttributes[l],
|
|
664
|
+
changed: o.has(l) ? "YES" : ""
|
|
665
|
+
};
|
|
666
|
+
if (console.table(i), console.groupEnd(), Object.keys(t.relationships).length > 0) {
|
|
667
|
+
console.groupCollapsed("Relationships");
|
|
668
|
+
for (const [l, h] of Object.entries(t.relationships)) {
|
|
669
|
+
const p = h == null ? void 0 : h.data;
|
|
670
|
+
if (Array.isArray(p)) {
|
|
671
|
+
const u = p.map((f) => `${f.type}:${f.id}`);
|
|
672
|
+
console.log(` ${l} → [${u.join(", ")}]`);
|
|
673
|
+
} else if (p && typeof p == "object") {
|
|
674
|
+
const u = p;
|
|
675
|
+
console.log(` ${l} → ${u.type}:${u.id}`);
|
|
676
|
+
} else
|
|
677
|
+
console.log(` ${l} → null`);
|
|
678
|
+
}
|
|
679
|
+
console.groupEnd();
|
|
680
|
+
}
|
|
681
|
+
if (t.errors.length > 0) {
|
|
682
|
+
console.groupCollapsed(`%cErrors (${t.errors.length})`, w);
|
|
683
|
+
for (const l of t.errors)
|
|
684
|
+
console.log(` ${l.attribute}: ${l.messages.join(", ")}`);
|
|
685
|
+
console.groupEnd();
|
|
686
|
+
}
|
|
687
|
+
console.groupEnd();
|
|
688
|
+
}
|
|
689
|
+
renderSchema(e, s) {
|
|
690
|
+
console.log(`%c[mobx-data] Schema: ${e}${s.isAbstract ? " (abstract)" : ""}`, m), s.discriminator && console.log(` Discriminator key: ${s.discriminator.key}`), s.attributes.length > 0 && (console.log("%cAttributes:", m), console.table(
|
|
691
|
+
s.attributes.map((t) => ({ name: t.name, type: t.type ?? "(untyped)" }))
|
|
692
|
+
)), s.relationships.length > 0 && (console.log("%cRelationships:", m), console.table(
|
|
693
|
+
s.relationships.map((t) => ({
|
|
694
|
+
name: t.name,
|
|
695
|
+
kind: t.kind,
|
|
696
|
+
type: t.type,
|
|
697
|
+
async: t.async,
|
|
698
|
+
inverse: t.inverse ?? "(none)"
|
|
699
|
+
}))
|
|
700
|
+
));
|
|
701
|
+
}
|
|
702
|
+
renderFilteredRecords(e, s) {
|
|
703
|
+
if (console.log(`%c[mobx-data] ${e} — ${s.length} total`, m), s.length === 0) {
|
|
704
|
+
console.log(" (none)");
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
console.table(
|
|
708
|
+
s.map((t) => ({
|
|
709
|
+
type: t.modelName,
|
|
710
|
+
id: t.id ?? t.clientId,
|
|
711
|
+
state: k(t),
|
|
712
|
+
isDirty: t.isDirty,
|
|
713
|
+
isNew: t.isNew,
|
|
714
|
+
hasErrors: t.hasErrors
|
|
715
|
+
}))
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const T = "__MOBX_DATA_DEVTOOLS_HOOK__", x = "mobx-data-devtools", O = "1.4.0";
|
|
720
|
+
function N() {
|
|
721
|
+
return typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : {};
|
|
722
|
+
}
|
|
723
|
+
function R() {
|
|
724
|
+
const a = N();
|
|
725
|
+
return typeof a.addEventListener == "function" ? a : null;
|
|
726
|
+
}
|
|
727
|
+
class W {
|
|
728
|
+
constructor() {
|
|
729
|
+
this.stores = /* @__PURE__ */ new Map(), this.disposers = /* @__PURE__ */ new Map(), this.messageHandler = null;
|
|
730
|
+
}
|
|
731
|
+
install() {
|
|
732
|
+
const e = N(), s = {
|
|
733
|
+
stores: this.stores,
|
|
734
|
+
version: O,
|
|
735
|
+
registerStore: (r, n) => this.registerStore(r, n),
|
|
736
|
+
unregisterStore: (r) => this.unregisterStore(r)
|
|
737
|
+
};
|
|
738
|
+
Object.defineProperty(e, T, {
|
|
739
|
+
value: s,
|
|
740
|
+
writable: !0,
|
|
741
|
+
enumerable: !1,
|
|
742
|
+
configurable: !0
|
|
743
|
+
});
|
|
744
|
+
const t = R();
|
|
745
|
+
t != null && t.addEventListener && (this.messageHandler = (r) => {
|
|
746
|
+
var o, i, l;
|
|
747
|
+
const n = r;
|
|
748
|
+
n.origin && typeof location < "u" && n.origin !== location.origin || ((o = n.data) == null ? void 0 : o.source) !== x || ((i = n.data) == null ? void 0 : i.direction) !== "panel-to-page" || this.isValidPayload((l = n.data) == null ? void 0 : l.payload) && this.handleMessage(n);
|
|
749
|
+
}, t.addEventListener("message", this.messageHandler));
|
|
750
|
+
}
|
|
751
|
+
registerStore(e, s) {
|
|
752
|
+
const t = new q(s);
|
|
753
|
+
this.stores.set(e, t);
|
|
754
|
+
const r = t.observe((n) => {
|
|
755
|
+
this.sendToPanel({
|
|
756
|
+
type: "changeEvent",
|
|
757
|
+
storeId: e,
|
|
758
|
+
event: n
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
this.disposers.set(e, r), this.sendToPanel({
|
|
762
|
+
type: "init",
|
|
763
|
+
storeId: e,
|
|
764
|
+
storeCount: this.stores.size,
|
|
765
|
+
version: O
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
unregisterStore(e) {
|
|
769
|
+
const s = this.disposers.get(e);
|
|
770
|
+
s && (s(), this.disposers.delete(e)), this.stores.delete(e);
|
|
771
|
+
}
|
|
772
|
+
destroy() {
|
|
773
|
+
for (const t of this.disposers.values())
|
|
774
|
+
t();
|
|
775
|
+
this.disposers.clear(), this.stores.clear();
|
|
776
|
+
const e = R();
|
|
777
|
+
e != null && e.removeEventListener && this.messageHandler && (e.removeEventListener("message", this.messageHandler), this.messageHandler = null);
|
|
778
|
+
const s = N();
|
|
779
|
+
delete s[T];
|
|
780
|
+
}
|
|
781
|
+
handleMessage(e) {
|
|
782
|
+
const { payload: s } = e.data, t = "storeId" in s ? s.storeId : void 0, r = t ? this.stores.get(t) : void 0;
|
|
783
|
+
switch (s.type) {
|
|
784
|
+
case "requestSummary": {
|
|
785
|
+
if (!r) return;
|
|
786
|
+
this.sendToPanel({ type: "summary", storeId: t, data: r.summary() });
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
case "requestRecords": {
|
|
790
|
+
if (!r || !("modelName" in s)) return;
|
|
791
|
+
this.sendToPanel({
|
|
792
|
+
type: "records",
|
|
793
|
+
storeId: t,
|
|
794
|
+
modelName: s.modelName,
|
|
795
|
+
data: r.records(s.modelName)
|
|
796
|
+
});
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
case "requestRecordDetail": {
|
|
800
|
+
if (!r || !("modelName" in s) || !("id" in s)) return;
|
|
801
|
+
const n = r.record(s.modelName, s.id);
|
|
802
|
+
if (!n) return;
|
|
803
|
+
this.sendToPanel({
|
|
804
|
+
type: "recordDetail",
|
|
805
|
+
storeId: t,
|
|
806
|
+
modelName: s.modelName,
|
|
807
|
+
id: s.id,
|
|
808
|
+
data: n
|
|
809
|
+
});
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
case "requestSchema": {
|
|
813
|
+
if (!r || !("modelName" in s)) return;
|
|
814
|
+
this.sendToPanel({
|
|
815
|
+
type: "schema",
|
|
816
|
+
storeId: t,
|
|
817
|
+
modelName: s.modelName,
|
|
818
|
+
data: r.schema(s.modelName)
|
|
819
|
+
});
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
case "requestSnapshot": {
|
|
823
|
+
if (!r) return;
|
|
824
|
+
this.sendToPanel({ type: "snapshot", storeId: t, data: r.snapshot() });
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
case "requestQuery": {
|
|
828
|
+
if (!r || !("queryText" in s)) return;
|
|
829
|
+
const n = s.queryText;
|
|
830
|
+
try {
|
|
831
|
+
const { modelName: o, results: i } = r.queryWithMeta(n), l = r.records(o), h = new Map(l.map((u) => [u.id, u])), p = i.map((u) => h.get(u.id)).filter(Boolean);
|
|
832
|
+
this.sendToPanel({
|
|
833
|
+
type: "queryResult",
|
|
834
|
+
storeId: t,
|
|
835
|
+
queryText: n,
|
|
836
|
+
data: p,
|
|
837
|
+
error: null
|
|
838
|
+
});
|
|
839
|
+
} catch (o) {
|
|
840
|
+
this.sendToPanel({
|
|
841
|
+
type: "queryResult",
|
|
842
|
+
storeId: t,
|
|
843
|
+
queryText: n,
|
|
844
|
+
data: [],
|
|
845
|
+
error: o instanceof Error ? o.message : String(o)
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
isValidPayload(e) {
|
|
853
|
+
if (!e || typeof e != "object") return !1;
|
|
854
|
+
const s = e, t = ["requestSummary", "requestRecords", "requestRecordDetail", "requestSchema", "requestSnapshot", "requestQuery"];
|
|
855
|
+
return typeof s.type == "string" && t.includes(s.type) && typeof s.storeId == "string";
|
|
856
|
+
}
|
|
857
|
+
sendToPanel(e) {
|
|
858
|
+
const s = R();
|
|
859
|
+
if (!(s != null && s.postMessage)) return;
|
|
860
|
+
const t = {
|
|
861
|
+
source: x,
|
|
862
|
+
direction: "page-to-panel",
|
|
863
|
+
payload: e
|
|
864
|
+
}, r = typeof location < "u" ? location.origin : "*";
|
|
865
|
+
s.postMessage(t, r);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
let g = null, M = 0;
|
|
869
|
+
function K(a, e = "default") {
|
|
870
|
+
const s = new P(a, e);
|
|
871
|
+
return typeof window < "u" && (window.$mobxData = s, window.$m = (t) => s.command(t)), s;
|
|
872
|
+
}
|
|
873
|
+
function F(a, e) {
|
|
874
|
+
if (typeof window > "u")
|
|
875
|
+
return () => {
|
|
876
|
+
};
|
|
877
|
+
g || (g = new W(), g.install()), M += 1;
|
|
878
|
+
const s = e ?? `store-${M}`;
|
|
879
|
+
return g.registerStore(s, a), () => {
|
|
880
|
+
g == null || g.unregisterStore(s);
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
function B(a, e = "default") {
|
|
884
|
+
const s = K(a, e), t = F(a, e);
|
|
885
|
+
return { consoleInspector: s, cleanup: t };
|
|
886
|
+
}
|
|
887
|
+
export {
|
|
888
|
+
P as ConsoleInspector,
|
|
889
|
+
W as DevToolsBridge,
|
|
890
|
+
b as QueryParser,
|
|
891
|
+
q as StoreInspector,
|
|
892
|
+
K as enableConsoleInspector,
|
|
893
|
+
F as enableDevTools,
|
|
894
|
+
B as enableInspector
|
|
895
|
+
};
|
|
896
|
+
//# sourceMappingURL=index.js.map
|