atom.io 0.11.0 → 0.12.1
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/data/dist/index.cjs +614 -0
- package/data/dist/index.cjs.map +1 -0
- package/data/dist/index.d.cts +158 -0
- package/data/dist/index.d.ts +118 -1
- package/data/dist/index.js +551 -30
- package/data/dist/index.js.map +1 -1
- package/data/dist/metafile-cjs.json +1 -0
- package/data/dist/metafile-esm.json +1 -0
- package/data/package.json +4 -3
- package/data/src/index.ts +1 -0
- package/data/src/join.ts +450 -0
- package/data/src/struct-family.ts +34 -24
- package/data/src/struct.ts +6 -8
- package/dist/index.cjs +257 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +10 -11
- package/dist/index.d.ts +10 -11
- package/dist/index.js +63 -104
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/internal/dist/{index.mjs → index.cjs} +716 -495
- package/internal/dist/index.cjs.map +1 -0
- package/internal/dist/{index.d.mts → index.d.cts} +124 -105
- package/internal/dist/index.d.ts +124 -105
- package/internal/dist/index.js +651 -555
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/metafile-cjs.json +1 -0
- package/internal/dist/metafile-esm.json +1 -0
- package/internal/package.json +4 -3
- package/internal/src/atom/create-atom.ts +29 -16
- package/internal/src/atom/delete-atom.ts +25 -6
- package/internal/src/atom/is-default.ts +4 -17
- package/internal/src/caching.ts +28 -23
- package/internal/src/families/create-atom-family.ts +3 -2
- package/internal/src/families/create-readonly-selector-family.ts +1 -1
- package/internal/src/families/create-selector-family.ts +4 -4
- package/internal/src/index.ts +4 -2
- package/internal/src/lazy-map.ts +33 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/create-mutable-atom.ts +1 -2
- package/internal/src/mutable/get-json-family.ts +22 -0
- package/internal/src/mutable/get-json-token.ts +1 -0
- package/internal/src/mutable/index.ts +1 -0
- package/internal/src/mutable/tracker-family.ts +1 -2
- package/internal/src/mutable/tracker.ts +8 -6
- package/internal/src/mutable/transceiver.ts +2 -0
- package/internal/src/not-found-error.ts +27 -0
- package/internal/src/operation.ts +2 -3
- package/internal/src/{get-state-internal.ts → read-or-compute-value.ts} +13 -6
- package/internal/src/selector/create-selector.ts +6 -7
- package/internal/src/selector/delete-selector.ts +37 -0
- package/internal/src/selector/index.ts +2 -1
- package/internal/src/selector/register-selector.ts +7 -7
- package/internal/src/set-state/copy-mutable-in-transaction.ts +3 -2
- package/internal/src/set-state/emit-update.ts +1 -3
- package/internal/src/set-state/evict-downstream.ts +6 -8
- package/internal/src/set-state/index.ts +1 -1
- package/internal/src/set-state/{set-state-internal.ts → set-atom-or-selector.ts} +2 -3
- package/internal/src/set-state/set-atom.ts +5 -6
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw-new-family-member.ts +6 -6
- package/internal/src/subscribe/recall-state.ts +1 -2
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +2 -2
- package/internal/src/timeline/add-atom-to-timeline.ts +5 -16
- package/internal/src/timeline/{timeline-internal.ts → create-timeline.ts} +4 -5
- package/internal/src/timeline/index.ts +2 -2
- package/internal/src/timeline/time-travel.ts +89 -0
- package/internal/src/transaction/build-transaction.ts +8 -7
- package/internal/src/transaction/{transaction-internal.ts → create-transaction.ts} +6 -5
- package/internal/src/transaction/index.ts +2 -3
- package/introspection/dist/{index.mjs → index.cjs} +54 -29
- package/introspection/dist/index.cjs.map +1 -0
- package/introspection/dist/{index.d.mts → index.d.cts} +2 -2
- package/introspection/dist/index.d.ts +2 -2
- package/introspection/dist/index.js +32 -49
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/metafile-cjs.json +1 -0
- package/introspection/dist/metafile-esm.json +1 -0
- package/introspection/package.json +4 -3
- package/introspection/src/attach-introspection-states.ts +2 -2
- package/introspection/src/attach-selector-index.ts +8 -4
- package/json/dist/{index.mjs → index.cjs} +20 -7
- package/json/dist/{index.mjs.map → index.cjs.map} +1 -1
- package/json/dist/{index.d.mts → index.d.cts} +1 -1
- package/json/dist/index.d.ts +1 -1
- package/json/dist/index.js +6 -19
- package/json/dist/index.js.map +1 -1
- package/json/dist/metafile-cjs.json +1 -0
- package/json/dist/metafile-esm.json +1 -0
- package/json/package.json +4 -3
- package/package.json +48 -47
- package/react/dist/index.cjs +59 -0
- package/react/dist/index.cjs.map +1 -0
- package/react/dist/index.js +20 -42
- package/react/dist/index.js.map +1 -1
- package/react/dist/metafile-cjs.json +1 -0
- package/react/dist/metafile-esm.json +1 -0
- package/react/package.json +4 -3
- package/react/src/store-hooks.ts +8 -2
- package/react-devtools/dist/{index.mjs → index.cjs} +286 -240
- package/react-devtools/dist/index.cjs.map +1 -0
- package/react-devtools/dist/{index.d.mts → index.d.cts} +29 -17
- package/react-devtools/dist/index.d.ts +29 -17
- package/react-devtools/dist/index.js +251 -273
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/metafile-cjs.json +1 -0
- package/react-devtools/dist/metafile-esm.json +1 -0
- package/react-devtools/package.json +4 -3
- package/react-devtools/src/StateEditor.tsx +8 -8
- package/realtime-client/dist/{index.mjs → index.cjs} +50 -21
- package/realtime-client/dist/index.js +20 -49
- package/realtime-client/dist/metafile-cjs.json +1 -0
- package/realtime-client/dist/metafile-esm.json +1 -0
- package/realtime-client/package.json +4 -3
- package/realtime-react/dist/index.cjs +99 -0
- package/realtime-react/dist/index.js +35 -66
- package/realtime-react/dist/metafile-cjs.json +1 -0
- package/realtime-react/dist/metafile-esm.json +1 -0
- package/realtime-react/package.json +4 -3
- package/realtime-server/dist/{index.mjs → index.cjs} +67 -40
- package/realtime-server/dist/index.js +39 -66
- package/realtime-server/dist/metafile-cjs.json +1 -0
- package/realtime-server/dist/metafile-esm.json +1 -0
- package/realtime-server/package.json +4 -3
- package/realtime-testing/dist/{index.mjs → index.cjs} +54 -23
- package/realtime-testing/dist/index.js +22 -53
- package/realtime-testing/dist/metafile-cjs.json +1 -0
- package/realtime-testing/dist/metafile-esm.json +1 -0
- package/realtime-testing/package.json +4 -3
- package/src/atom.ts +6 -8
- package/src/dispose.ts +18 -0
- package/src/get-state.ts +16 -0
- package/src/index.ts +3 -1
- package/src/logger.ts +1 -1
- package/src/selector.ts +3 -3
- package/src/set-state.ts +22 -0
- package/src/silo.ts +7 -8
- package/src/timeline.ts +6 -11
- package/src/transaction.ts +2 -2
- package/transceivers/set-rtx/dist/{index.mjs → index.cjs} +40 -36
- package/transceivers/set-rtx/dist/index.cjs.map +1 -0
- package/transceivers/set-rtx/dist/{index.d.mts → index.d.cts} +2 -1
- package/transceivers/set-rtx/dist/index.d.ts +2 -1
- package/transceivers/set-rtx/dist/index.js +37 -37
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/dist/metafile-cjs.json +1 -0
- package/transceivers/set-rtx/dist/metafile-esm.json +1 -0
- package/transceivers/set-rtx/package.json +4 -3
- package/transceivers/set-rtx/src/set-rtx.ts +29 -26
- package/data/dist/index.d.mts +0 -41
- package/data/dist/index.mjs +0 -82
- package/data/dist/index.mjs.map +0 -1
- package/dist/index.mjs +0 -215
- package/dist/index.mjs.map +0 -1
- package/internal/dist/index.mjs.map +0 -1
- package/internal/src/set-state/set-selector-state.ts +0 -8
- package/internal/src/timeline/time-travel-internal.ts +0 -109
- package/introspection/dist/index.mjs.map +0 -1
- package/react/dist/index.mjs +0 -29
- package/react/dist/index.mjs.map +0 -1
- package/react-devtools/dist/index.mjs.map +0 -1
- package/realtime-react/dist/index.mjs +0 -68
- package/src/get-set.ts +0 -48
- package/transceivers/set-rtx/dist/index.mjs.map +0 -1
- /package/react/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-client/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-client/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-react/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-react/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-server/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-server/dist/{index.d.mts → index.d.cts} +0 -0
- /package/realtime-testing/dist/{index.mjs.map → index.cjs.map} +0 -0
- /package/realtime-testing/dist/{index.d.mts → index.d.cts} +0 -0
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internal = require('atom.io/internal');
|
|
4
|
+
var atom_io = require('atom.io');
|
|
5
|
+
var setRtx = require('atom.io/transceivers/set-rtx');
|
|
6
|
+
|
|
7
|
+
// src/dict.ts
|
|
8
|
+
function dict(findState, index, store = internal.IMPLICIT.STORE) {
|
|
9
|
+
return internal.createSelector(
|
|
10
|
+
{
|
|
11
|
+
key: `${findState.key}Dict`,
|
|
12
|
+
get: ({ get }) => {
|
|
13
|
+
const keys = get(index);
|
|
14
|
+
return keys.reduce((acc, key) => {
|
|
15
|
+
acc[key] = get(findState(key));
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
void 0,
|
|
21
|
+
store
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ../../rel8/junction/src/junction.ts
|
|
26
|
+
var Junction = class {
|
|
27
|
+
constructor(data, config) {
|
|
28
|
+
this.relations = /* @__PURE__ */ new Map();
|
|
29
|
+
this.contents = /* @__PURE__ */ new Map();
|
|
30
|
+
this.makeContentKey = (a, b) => `${a}:${b}`;
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
|
+
this.a = data.between[0];
|
|
33
|
+
this.b = data.between[1];
|
|
34
|
+
this.cardinality = data.cardinality;
|
|
35
|
+
if (!(config == null ? void 0 : config.externalStore)) {
|
|
36
|
+
this.relations = new Map((_a = data.relations) == null ? void 0 : _a.map(([a, b]) => [a, new Set(b)]));
|
|
37
|
+
this.contents = new Map(data.contents);
|
|
38
|
+
}
|
|
39
|
+
this.isContent = (_b = config == null ? void 0 : config.isContent) != null ? _b : null;
|
|
40
|
+
if (config == null ? void 0 : config.makeContentKey) {
|
|
41
|
+
this.makeContentKey = config.makeContentKey;
|
|
42
|
+
}
|
|
43
|
+
if (config == null ? void 0 : config.externalStore) {
|
|
44
|
+
const externalStore = config.externalStore;
|
|
45
|
+
this.has = (a, b) => externalStore.has(a, b);
|
|
46
|
+
this.addRelation = (a, b) => {
|
|
47
|
+
externalStore.addRelation(a, b);
|
|
48
|
+
};
|
|
49
|
+
this.deleteRelation = (a, b) => {
|
|
50
|
+
externalStore.deleteRelation(a, b);
|
|
51
|
+
};
|
|
52
|
+
this.replaceRelationsSafely = (a, bs) => {
|
|
53
|
+
externalStore.replaceRelationsSafely(a, bs);
|
|
54
|
+
};
|
|
55
|
+
this.replaceRelationsUnsafely = (a, bs) => {
|
|
56
|
+
externalStore.replaceRelationsUnsafely(a, bs);
|
|
57
|
+
};
|
|
58
|
+
this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
|
|
59
|
+
if (externalStore.getContent) {
|
|
60
|
+
this.getContentInternal = (contentKey) => {
|
|
61
|
+
return externalStore.getContent(contentKey);
|
|
62
|
+
};
|
|
63
|
+
this.setContent = (contentKey, content) => {
|
|
64
|
+
externalStore.setContent(contentKey, content);
|
|
65
|
+
};
|
|
66
|
+
this.deleteContent = (contentKey) => {
|
|
67
|
+
externalStore.deleteContent(contentKey);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
for (const [x, ys] of (_c = data.relations) != null ? _c : []) {
|
|
71
|
+
for (const y of ys)
|
|
72
|
+
this.addRelation(x, y);
|
|
73
|
+
}
|
|
74
|
+
for (const [contentKey, content] of (_d = data.contents) != null ? _d : []) {
|
|
75
|
+
this.setContent(contentKey, content);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getRelatedKeys(key) {
|
|
80
|
+
return this.relations.get(key);
|
|
81
|
+
}
|
|
82
|
+
addRelation(a, b) {
|
|
83
|
+
let aRelations = this.relations.get(a);
|
|
84
|
+
let bRelations = this.relations.get(b);
|
|
85
|
+
if (aRelations) {
|
|
86
|
+
aRelations.add(b);
|
|
87
|
+
} else {
|
|
88
|
+
aRelations = /* @__PURE__ */ new Set([b]);
|
|
89
|
+
this.relations.set(a, aRelations);
|
|
90
|
+
}
|
|
91
|
+
if (bRelations) {
|
|
92
|
+
bRelations.add(a);
|
|
93
|
+
} else {
|
|
94
|
+
bRelations = /* @__PURE__ */ new Set([a]);
|
|
95
|
+
this.relations.set(b, bRelations);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
deleteRelation(a, b) {
|
|
99
|
+
const aRelations = this.relations.get(a);
|
|
100
|
+
if (aRelations) {
|
|
101
|
+
aRelations.delete(b);
|
|
102
|
+
if (aRelations.size === 0) {
|
|
103
|
+
this.relations.delete(a);
|
|
104
|
+
}
|
|
105
|
+
const bRelations = this.relations.get(b);
|
|
106
|
+
if (bRelations) {
|
|
107
|
+
bRelations.delete(a);
|
|
108
|
+
if (bRelations.size === 0) {
|
|
109
|
+
this.relations.delete(b);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
replaceRelationsUnsafely(a, bs) {
|
|
115
|
+
this.relations.set(a, new Set(bs));
|
|
116
|
+
for (const b of bs) {
|
|
117
|
+
const bRelations = /* @__PURE__ */ new Set([a]);
|
|
118
|
+
this.relations.set(b, bRelations);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
replaceRelationsSafely(a, bs) {
|
|
122
|
+
const aRelationsPrev = this.relations.get(a);
|
|
123
|
+
if (aRelationsPrev) {
|
|
124
|
+
for (const b of aRelationsPrev) {
|
|
125
|
+
const bRelations = this.relations.get(b);
|
|
126
|
+
if (bRelations) {
|
|
127
|
+
if (bRelations.size === 1) {
|
|
128
|
+
this.relations.delete(b);
|
|
129
|
+
} else {
|
|
130
|
+
bRelations.delete(a);
|
|
131
|
+
}
|
|
132
|
+
this.contents.delete(this.makeContentKey(a, b));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
this.relations.set(a, new Set(bs));
|
|
137
|
+
for (const b of bs) {
|
|
138
|
+
let bRelations = this.relations.get(b);
|
|
139
|
+
if (bRelations) {
|
|
140
|
+
bRelations.add(a);
|
|
141
|
+
} else {
|
|
142
|
+
bRelations = /* @__PURE__ */ new Set([a]);
|
|
143
|
+
this.relations.set(b, bRelations);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
getContentInternal(contentKey) {
|
|
148
|
+
return this.contents.get(contentKey);
|
|
149
|
+
}
|
|
150
|
+
setContent(contentKey, content) {
|
|
151
|
+
this.contents.set(contentKey, content);
|
|
152
|
+
}
|
|
153
|
+
deleteContent(contentKey) {
|
|
154
|
+
this.contents.delete(contentKey);
|
|
155
|
+
}
|
|
156
|
+
toJSON() {
|
|
157
|
+
return {
|
|
158
|
+
between: [this.a, this.b],
|
|
159
|
+
cardinality: this.cardinality,
|
|
160
|
+
relations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),
|
|
161
|
+
contents: [...this.contents.entries()]
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
set(a, ...rest) {
|
|
165
|
+
var _a;
|
|
166
|
+
const b = typeof rest[0] === `string` ? rest[0] : a[this.b];
|
|
167
|
+
const content = ((_a = rest[1]) != null ? _a : typeof rest[0] === `string`) ? void 0 : rest[0];
|
|
168
|
+
a = typeof a === `string` ? a : a[this.a];
|
|
169
|
+
switch (this.cardinality) {
|
|
170
|
+
case `1:1`: {
|
|
171
|
+
const bPrev = this.getRelatedKey(a);
|
|
172
|
+
if (bPrev && bPrev !== b)
|
|
173
|
+
this.delete(bPrev, a);
|
|
174
|
+
}
|
|
175
|
+
case `1:n`: {
|
|
176
|
+
const aPrev = this.getRelatedKey(b);
|
|
177
|
+
if (aPrev && aPrev !== a)
|
|
178
|
+
this.delete(aPrev, b);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (content) {
|
|
182
|
+
const contentKey = this.makeContentKey(a, b);
|
|
183
|
+
this.setContent(contentKey, content);
|
|
184
|
+
}
|
|
185
|
+
this.addRelation(a, b);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
delete(x, b) {
|
|
189
|
+
b = typeof b === `string` ? b : x[this.b];
|
|
190
|
+
const a = typeof x === `string` ? x : x[this.a];
|
|
191
|
+
if (a === void 0 && typeof b === `string`) {
|
|
192
|
+
const bRelations = this.getRelatedKeys(b);
|
|
193
|
+
if (bRelations) {
|
|
194
|
+
for (const a2 of bRelations) {
|
|
195
|
+
this.delete(a2, b);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (typeof a === `string` && b === void 0) {
|
|
200
|
+
const aRelations = this.getRelatedKeys(a);
|
|
201
|
+
if (aRelations) {
|
|
202
|
+
for (const b2 of aRelations) {
|
|
203
|
+
this.delete(a, b2);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (typeof a === `string` && typeof b === `string`) {
|
|
208
|
+
this.deleteRelation(a, b);
|
|
209
|
+
const contentKey = this.makeContentKey(a, b);
|
|
210
|
+
this.deleteContent(contentKey);
|
|
211
|
+
}
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
getRelatedKey(key) {
|
|
215
|
+
const relations = this.getRelatedKeys(key);
|
|
216
|
+
if (relations) {
|
|
217
|
+
if (relations.size > 1) {
|
|
218
|
+
console.warn(
|
|
219
|
+
`${relations.size} related keys were found for key "${key}": (${[
|
|
220
|
+
...relations
|
|
221
|
+
].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
for (const relation of relations) {
|
|
225
|
+
return relation;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
replaceRelations(a, relations, config) {
|
|
230
|
+
const hasContent = !Array.isArray(relations);
|
|
231
|
+
const bs = hasContent ? Object.keys(relations) : relations;
|
|
232
|
+
if (config == null ? void 0 : config.reckless) {
|
|
233
|
+
this.replaceRelationsUnsafely(a, bs);
|
|
234
|
+
} else {
|
|
235
|
+
this.replaceRelationsSafely(a, bs);
|
|
236
|
+
}
|
|
237
|
+
if (hasContent) {
|
|
238
|
+
for (const b of bs) {
|
|
239
|
+
const contentKey = this.makeContentKey(a, b);
|
|
240
|
+
const content = relations[b];
|
|
241
|
+
this.setContent(contentKey, content);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
getContent(a, b) {
|
|
247
|
+
const contentKey = this.makeContentKey(a, b);
|
|
248
|
+
return this.getContentInternal(contentKey);
|
|
249
|
+
}
|
|
250
|
+
getRelationEntries(input) {
|
|
251
|
+
const a = input[this.a];
|
|
252
|
+
const b = input[this.b];
|
|
253
|
+
if (a !== void 0 && b === void 0) {
|
|
254
|
+
const aRelations = this.getRelatedKeys(a);
|
|
255
|
+
if (aRelations) {
|
|
256
|
+
return [...aRelations].map((b2) => {
|
|
257
|
+
var _a;
|
|
258
|
+
return [b2, (_a = this.getContent(a, b2)) != null ? _a : null];
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (a === void 0 && b !== void 0) {
|
|
263
|
+
const bRelations = this.getRelatedKeys(b);
|
|
264
|
+
if (bRelations) {
|
|
265
|
+
return [...bRelations].map((a2) => {
|
|
266
|
+
var _a;
|
|
267
|
+
return [a2, (_a = this.getContent(a2, b)) != null ? _a : null];
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
has(a, b) {
|
|
274
|
+
var _a;
|
|
275
|
+
if (b) {
|
|
276
|
+
const setA = this.getRelatedKeys(a);
|
|
277
|
+
return (_a = setA == null ? void 0 : setA.has(b)) != null ? _a : false;
|
|
278
|
+
}
|
|
279
|
+
return this.relations.has(a);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/join.ts
|
|
284
|
+
var TRANSACTORS = { get: atom_io.getState, set: atom_io.setState };
|
|
285
|
+
function capitalize(string) {
|
|
286
|
+
return string[0].toUpperCase() + string.slice(1);
|
|
287
|
+
}
|
|
288
|
+
function join(options, defaultContent, store = internal.IMPLICIT.STORE) {
|
|
289
|
+
const a = options.between[0];
|
|
290
|
+
const b = options.between[1];
|
|
291
|
+
const findRelatedKeysState = internal.createMutableAtomFamily(
|
|
292
|
+
{
|
|
293
|
+
key: `${options.key}/relatedKeys`,
|
|
294
|
+
default: () => new setRtx.SetRTX(),
|
|
295
|
+
mutable: true,
|
|
296
|
+
fromJson: (json) => new setRtx.SetRTX(json),
|
|
297
|
+
toJson: (set) => [...set]
|
|
298
|
+
},
|
|
299
|
+
store
|
|
300
|
+
);
|
|
301
|
+
const getRelatedKeys = ({ get }, key) => get(findRelatedKeysState(key));
|
|
302
|
+
const addRelation = (transactors, a2, b2) => {
|
|
303
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
304
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
305
|
+
if (aKeys) {
|
|
306
|
+
transactors.set(findRelatedKeysState(a2), aKeys.add(b2));
|
|
307
|
+
} else {
|
|
308
|
+
transactors.set(findRelatedKeysState(a2), new setRtx.SetRTX([b2]));
|
|
309
|
+
}
|
|
310
|
+
if (bKeys) {
|
|
311
|
+
transactors.set(findRelatedKeysState(b2), bKeys.add(a2));
|
|
312
|
+
} else {
|
|
313
|
+
transactors.set(findRelatedKeysState(b2), new setRtx.SetRTX([a2]));
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
const deleteRelation = (transactors, a2, b2) => {
|
|
317
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
318
|
+
if (aKeys) {
|
|
319
|
+
aKeys.delete(b2);
|
|
320
|
+
if (aKeys.size === 0) {
|
|
321
|
+
transactors.set(findRelatedKeysState(a2), void 0);
|
|
322
|
+
}
|
|
323
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
324
|
+
if (bKeys) {
|
|
325
|
+
bKeys.delete(a2);
|
|
326
|
+
if (bKeys.size === 0) {
|
|
327
|
+
transactors.set(findRelatedKeysState(b2), void 0);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
const replaceRelationsSafely = (transactors, a2, bs) => {
|
|
333
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
334
|
+
if (aKeys) {
|
|
335
|
+
for (const b2 of aKeys) {
|
|
336
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
337
|
+
if (bKeys) {
|
|
338
|
+
bKeys.delete(a2);
|
|
339
|
+
if (bKeys.size === 0) {
|
|
340
|
+
transactors.set(findRelatedKeysState(b2), void 0);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
transactors.set(findRelatedKeysState(a2), new setRtx.SetRTX(bs));
|
|
346
|
+
for (const b2 of bs) {
|
|
347
|
+
const bKeys = getRelatedKeys(transactors, b2);
|
|
348
|
+
if (bKeys) {
|
|
349
|
+
bKeys.add(a2);
|
|
350
|
+
} else {
|
|
351
|
+
transactors.set(findRelatedKeysState(b2), new setRtx.SetRTX([a2]));
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const replaceRelationsUnsafely = (transactors, a2, bs) => {
|
|
356
|
+
transactors.set(findRelatedKeysState(a2), new setRtx.SetRTX(bs));
|
|
357
|
+
for (const b2 of bs) {
|
|
358
|
+
let bKeys = getRelatedKeys(transactors, b2);
|
|
359
|
+
if (bKeys) {
|
|
360
|
+
bKeys.add(a2);
|
|
361
|
+
} else {
|
|
362
|
+
bKeys = new setRtx.SetRTX([a2]);
|
|
363
|
+
transactors.set(findRelatedKeysState(b2), bKeys);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
const has = (transactors, a2, b2) => {
|
|
368
|
+
var _a, _b;
|
|
369
|
+
const aKeys = getRelatedKeys(transactors, a2);
|
|
370
|
+
return b2 ? (_a = aKeys == null ? void 0 : aKeys.has(b2)) != null ? _a : false : ((_b = aKeys == null ? void 0 : aKeys.size) != null ? _b : 0) > 0;
|
|
371
|
+
};
|
|
372
|
+
const baseExternalStoreConfiguration = {
|
|
373
|
+
getRelatedKeys: (key) => getRelatedKeys(TRANSACTORS, key),
|
|
374
|
+
addRelation: (a2, b2) => addRelation(TRANSACTORS, a2, b2),
|
|
375
|
+
deleteRelation: (a2, b2) => deleteRelation(TRANSACTORS, a2, b2),
|
|
376
|
+
replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(TRANSACTORS, a2, bs),
|
|
377
|
+
replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(TRANSACTORS, a2, bs),
|
|
378
|
+
has: (a2, b2) => has(TRANSACTORS, a2, b2)
|
|
379
|
+
};
|
|
380
|
+
let externalStore;
|
|
381
|
+
let findContentState;
|
|
382
|
+
if (defaultContent) {
|
|
383
|
+
findContentState = internal.createAtomFamily(
|
|
384
|
+
{
|
|
385
|
+
key: `${options.key}/content`,
|
|
386
|
+
default: defaultContent
|
|
387
|
+
},
|
|
388
|
+
store
|
|
389
|
+
);
|
|
390
|
+
const getContent = ({ get }, key) => get(findContentState(key));
|
|
391
|
+
const setContent = (transactors, key, content) => transactors.set(findContentState(key), content);
|
|
392
|
+
const deleteContent = (transactors, key) => transactors.set(findContentState(key), void 0);
|
|
393
|
+
const externalStoreWithContentConfiguration = {
|
|
394
|
+
getContent: (contentKey) => {
|
|
395
|
+
const content = getContent(TRANSACTORS, contentKey);
|
|
396
|
+
return content;
|
|
397
|
+
},
|
|
398
|
+
setContent: (contentKey, content) => {
|
|
399
|
+
setContent(TRANSACTORS, contentKey, content);
|
|
400
|
+
},
|
|
401
|
+
deleteContent: (contentKey) => {
|
|
402
|
+
deleteContent(TRANSACTORS, contentKey);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
externalStore = Object.assign(
|
|
406
|
+
baseExternalStoreConfiguration,
|
|
407
|
+
externalStoreWithContentConfiguration
|
|
408
|
+
);
|
|
409
|
+
} else {
|
|
410
|
+
externalStore = baseExternalStoreConfiguration;
|
|
411
|
+
}
|
|
412
|
+
const relations = new Junction(options, {
|
|
413
|
+
externalStore,
|
|
414
|
+
makeContentKey: (...args) => args.sort().join(`:`)
|
|
415
|
+
});
|
|
416
|
+
const createSingleKeyStateFamily = () => internal.createSelectorFamily(
|
|
417
|
+
{
|
|
418
|
+
key: `${options.key}/singleRelatedKey`,
|
|
419
|
+
get: (key) => ({ get }) => {
|
|
420
|
+
const relatedKeys = get(findRelatedKeysState(key));
|
|
421
|
+
for (const relatedKey of relatedKeys) {
|
|
422
|
+
return relatedKey;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
store
|
|
427
|
+
);
|
|
428
|
+
const getMultipleKeyStateFamily = () => internal.getJsonFamily(findRelatedKeysState, store);
|
|
429
|
+
const createSingleEntryStateFamily = () => internal.createSelectorFamily(
|
|
430
|
+
{
|
|
431
|
+
key: `${options.key}/singleRelatedEntry`,
|
|
432
|
+
get: (key) => ({ get }) => {
|
|
433
|
+
const relatedKeys = get(findRelatedKeysState(key));
|
|
434
|
+
for (const relatedKey of relatedKeys) {
|
|
435
|
+
const contentKey = relations.makeContentKey(key, relatedKey);
|
|
436
|
+
return [relatedKey, get(findContentState(contentKey))];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
store
|
|
441
|
+
);
|
|
442
|
+
const getMultipleEntryStateFamily = () => internal.createSelectorFamily(
|
|
443
|
+
{
|
|
444
|
+
key: `${options.key}/multipleRelatedEntries`,
|
|
445
|
+
get: (key) => ({ get }) => {
|
|
446
|
+
const relatedKeys = get(findRelatedKeysState(key));
|
|
447
|
+
return [...relatedKeys].map((relatedKey) => {
|
|
448
|
+
const contentKey = relations.makeContentKey(key, relatedKey);
|
|
449
|
+
return [relatedKey, get(findContentState(contentKey))];
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
store
|
|
454
|
+
);
|
|
455
|
+
switch (options.cardinality) {
|
|
456
|
+
case `1:1`: {
|
|
457
|
+
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
458
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
459
|
+
const stateKeyB = `${b}KeyOf${capitalize(a)}`;
|
|
460
|
+
const findStateBase = {
|
|
461
|
+
[stateKeyA]: findSingleRelatedKeyState,
|
|
462
|
+
[stateKeyB]: findSingleRelatedKeyState
|
|
463
|
+
};
|
|
464
|
+
let findState;
|
|
465
|
+
if (defaultContent) {
|
|
466
|
+
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
467
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
468
|
+
const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
|
|
469
|
+
const findStateWithContent = {
|
|
470
|
+
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
471
|
+
[entriesStateKeyB]: findSingleRelatedEntryState
|
|
472
|
+
};
|
|
473
|
+
findState = Object.assign(findStateBase, findStateWithContent);
|
|
474
|
+
} else {
|
|
475
|
+
findState = findStateBase;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
relations,
|
|
479
|
+
findState
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
case `1:n`: {
|
|
483
|
+
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
484
|
+
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
485
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
486
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
487
|
+
const findStateBase = {
|
|
488
|
+
[stateKeyA]: findSingleRelatedKeyState,
|
|
489
|
+
[stateKeyB]: findMultipleRelatedKeysState
|
|
490
|
+
};
|
|
491
|
+
let findState;
|
|
492
|
+
if (defaultContent) {
|
|
493
|
+
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
494
|
+
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
495
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
496
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
497
|
+
const findStateWithContent = {
|
|
498
|
+
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
499
|
+
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
500
|
+
};
|
|
501
|
+
findState = Object.assign(findStateBase, findStateWithContent);
|
|
502
|
+
} else {
|
|
503
|
+
findState = findStateBase;
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
relations,
|
|
507
|
+
findState
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
case `n:n`: {
|
|
511
|
+
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
512
|
+
const stateKeyA = `${a}KeysOf${capitalize(b)}`;
|
|
513
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
514
|
+
const findStateBase = {
|
|
515
|
+
[stateKeyA]: findMultipleRelatedKeysState,
|
|
516
|
+
[stateKeyB]: findMultipleRelatedKeysState
|
|
517
|
+
};
|
|
518
|
+
let findState;
|
|
519
|
+
if (defaultContent) {
|
|
520
|
+
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
521
|
+
const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
|
|
522
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
523
|
+
const findStateWithContent = {
|
|
524
|
+
[entriesStateKeyA]: findMultipleRelatedEntriesState,
|
|
525
|
+
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
526
|
+
};
|
|
527
|
+
findState = Object.assign(findStateBase, findStateWithContent);
|
|
528
|
+
} else {
|
|
529
|
+
findState = findStateBase;
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
relations,
|
|
533
|
+
findState
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
default:
|
|
537
|
+
throw new Error(`Invalid cardinality: ${options.cardinality}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
541
|
+
function struct(options, store = internal.IMPLICIT.STORE) {
|
|
542
|
+
const atoms = Object.keys(options.default).reduce((acc, key) => {
|
|
543
|
+
const atomName = options.key + capitalize2(key) + `State`;
|
|
544
|
+
acc[atomName] = internal.createAtom(
|
|
545
|
+
{
|
|
546
|
+
key: `${options.key}.${key}`,
|
|
547
|
+
default: options.default[key]
|
|
548
|
+
},
|
|
549
|
+
void 0,
|
|
550
|
+
store
|
|
551
|
+
);
|
|
552
|
+
return acc;
|
|
553
|
+
}, {});
|
|
554
|
+
const structState = internal.createSelector(
|
|
555
|
+
{
|
|
556
|
+
key: options.key,
|
|
557
|
+
get: ({ get }) => {
|
|
558
|
+
return Object.keys(options.default).reduce((acc, key) => {
|
|
559
|
+
acc[key] = get(atoms[options.key + capitalize2(key) + `State`]);
|
|
560
|
+
return acc;
|
|
561
|
+
}, {});
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
void 0,
|
|
565
|
+
store
|
|
566
|
+
);
|
|
567
|
+
return [atoms, structState];
|
|
568
|
+
}
|
|
569
|
+
var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
570
|
+
var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(subKey) + `State`;
|
|
571
|
+
function structFamily(options) {
|
|
572
|
+
const atoms = Object.keys(options.default).reduce((acc, subKey) => {
|
|
573
|
+
const atomFamilyName = nameFamily(options.key, subKey);
|
|
574
|
+
acc[atomFamilyName] = internal.createAtomFamily(
|
|
575
|
+
{
|
|
576
|
+
key: `${options.key}.${subKey}`,
|
|
577
|
+
default: options.default[subKey]
|
|
578
|
+
},
|
|
579
|
+
internal.IMPLICIT.STORE
|
|
580
|
+
);
|
|
581
|
+
return acc;
|
|
582
|
+
}, {});
|
|
583
|
+
const findStructState = internal.createSelectorFamily(
|
|
584
|
+
{
|
|
585
|
+
key: options.key,
|
|
586
|
+
get: (id) => ({ get }) => {
|
|
587
|
+
return Object.keys(options.default).reduce((acc, subKey) => {
|
|
588
|
+
acc[subKey] = get(
|
|
589
|
+
atoms[nameFamily(options.key, subKey)](id)
|
|
590
|
+
);
|
|
591
|
+
return acc;
|
|
592
|
+
}, {});
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
internal.IMPLICIT.STORE
|
|
596
|
+
);
|
|
597
|
+
return [atoms, findStructState];
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/until.ts
|
|
601
|
+
function until(loadable, fallback) {
|
|
602
|
+
if (loadable instanceof Promise) {
|
|
603
|
+
return fallback;
|
|
604
|
+
}
|
|
605
|
+
return loadable;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
exports.dict = dict;
|
|
609
|
+
exports.join = join;
|
|
610
|
+
exports.struct = struct;
|
|
611
|
+
exports.structFamily = structFamily;
|
|
612
|
+
exports.until = until;
|
|
613
|
+
//# sourceMappingURL=out.js.map
|
|
614
|
+
//# sourceMappingURL=index.cjs.map
|