atom.io 0.0.0 → 0.1.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 +30 -11
- package/dist/index-3b5d305c.d.ts +257 -0
- package/dist/index.d.ts +4 -257
- package/dist/index.js +35 -23
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +35 -23
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.ts +21 -0
- package/dist/react/index.js +780 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +751 -0
- package/dist/react/index.mjs.map +1 -0
- package/package.json +7 -6
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __export = (target, all) => {
|
|
33
|
+
for (var name in all)
|
|
34
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/react/useSubject.ts
|
|
38
|
+
var eq = (oldValue, newValue) => oldValue === newValue;
|
|
39
|
+
var composeSubjectHook = (useState, useEffect) => {
|
|
40
|
+
function useSubject(subject, initialValue, compareFn = eq) {
|
|
41
|
+
const [state, setState2] = useState(initialValue);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const subscription = subject.subscribe(({ newValue, oldValue }) => {
|
|
44
|
+
if (!compareFn(oldValue, newValue)) {
|
|
45
|
+
setState2(newValue);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
subscription.unsubscribe();
|
|
50
|
+
};
|
|
51
|
+
}, [state, compareFn, subject]);
|
|
52
|
+
const updateState = (newValue) => {
|
|
53
|
+
subject.next({ newValue, oldValue: state });
|
|
54
|
+
};
|
|
55
|
+
return [state, updateState];
|
|
56
|
+
}
|
|
57
|
+
return useSubject;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/internal/index.ts
|
|
61
|
+
var internal_exports = {};
|
|
62
|
+
__export(internal_exports, {
|
|
63
|
+
IMPLICIT: () => IMPLICIT,
|
|
64
|
+
abortTransaction: () => abortTransaction,
|
|
65
|
+
clearStore: () => clearStore,
|
|
66
|
+
configure: () => configure,
|
|
67
|
+
createStore: () => createStore,
|
|
68
|
+
deposit: () => deposit,
|
|
69
|
+
finishAction: () => finishAction,
|
|
70
|
+
finishTransaction: () => finishTransaction,
|
|
71
|
+
getCachedState: () => getCachedState,
|
|
72
|
+
getSelectorState: () => getSelectorState,
|
|
73
|
+
getState__INTERNAL: () => getState__INTERNAL,
|
|
74
|
+
isDone: () => isDone,
|
|
75
|
+
markDone: () => markDone,
|
|
76
|
+
propagateDown: () => propagateDown,
|
|
77
|
+
recall: () => recall,
|
|
78
|
+
setAtomState: () => setAtomState,
|
|
79
|
+
setSelectorState: () => setSelectorState,
|
|
80
|
+
setState__INTERNAL: () => setState__INTERNAL,
|
|
81
|
+
startAction: () => startAction,
|
|
82
|
+
startTransaction: () => startTransaction,
|
|
83
|
+
withdraw: () => withdraw
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// src/internal/get.ts
|
|
87
|
+
import HAMT2 from "hamt_plus";
|
|
88
|
+
|
|
89
|
+
// src/internal/store.ts
|
|
90
|
+
import HAMT from "hamt_plus";
|
|
91
|
+
|
|
92
|
+
// ../anvl/src/join/core-relation-data.ts
|
|
93
|
+
import { isString } from "fp-ts/string";
|
|
94
|
+
|
|
95
|
+
// ../anvl/src/array/venn.ts
|
|
96
|
+
var includesAll = (items) => (array) => {
|
|
97
|
+
for (const item of items) {
|
|
98
|
+
if (!array.includes(item))
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
var comprises = (items) => (array) => includesAll(items)(array) && includesAll(array)(items);
|
|
104
|
+
|
|
105
|
+
// ../anvl/src/array/index.ts
|
|
106
|
+
var isArray = (isType) => (input) => Array.isArray(input) && input.every((item) => isType(item));
|
|
107
|
+
var map = (f) => (a) => a.map(f);
|
|
108
|
+
var every = (f = Boolean) => (a) => a.every(f);
|
|
109
|
+
var allTrue = every((x) => x === true);
|
|
110
|
+
var addTo = (a) => (x) => a.includes(x) ? a : [...a, x];
|
|
111
|
+
var isEmptyArray = (input) => Array.isArray(input) && input.length === 0;
|
|
112
|
+
var isOneOf = (...args) => (input) => args.includes(input);
|
|
113
|
+
|
|
114
|
+
// ../anvl/src/object/refinement.ts
|
|
115
|
+
import { pipe as pipe2 } from "fp-ts/function";
|
|
116
|
+
|
|
117
|
+
// ../anvl/src/object/access.ts
|
|
118
|
+
var access = (k) => Object.assign((obj) => obj[k], {
|
|
119
|
+
in: (obj) => obj[k]
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// ../anvl/src/object/entries.ts
|
|
123
|
+
var recordToEntries = (obj) => Object.entries(obj);
|
|
124
|
+
var entriesToRecord = (entries) => Object.fromEntries(entries);
|
|
125
|
+
|
|
126
|
+
// ../anvl/src/object/mapObject.ts
|
|
127
|
+
import { pipe } from "fp-ts/lib/function";
|
|
128
|
+
var mapObject = (obj, fn) => pipe(
|
|
129
|
+
obj,
|
|
130
|
+
recordToEntries,
|
|
131
|
+
map(([key, val]) => [key, fn(val, key)]),
|
|
132
|
+
entriesToRecord
|
|
133
|
+
);
|
|
134
|
+
var mob = (fn) => (obj) => mapObject(obj, fn);
|
|
135
|
+
|
|
136
|
+
// ../anvl/src/function/index.ts
|
|
137
|
+
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
138
|
+
originalThing instanceof Function ? originalThing() : originalThing
|
|
139
|
+
) : nextVersionOfThing;
|
|
140
|
+
var pass = (...params) => (fn) => fn(...params);
|
|
141
|
+
|
|
142
|
+
// ../anvl/src/nullish/index.ts
|
|
143
|
+
var isUndefined = (input) => input === void 0;
|
|
144
|
+
var ifNullish = (alt) => (input) => input != null ? input : alt;
|
|
145
|
+
|
|
146
|
+
// ../anvl/src/object/refinement.ts
|
|
147
|
+
var isNonNullObject = (input) => typeof input === `object` && input !== null;
|
|
148
|
+
var isPlainObject = (input) => isNonNullObject(input) && Object.getPrototypeOf(input) === Object.prototype;
|
|
149
|
+
var isEmptyObject = (input) => isPlainObject(input) && Object.keys(input).length === 0;
|
|
150
|
+
var isRecord = (isKey, isValue) => (input) => isPlainObject(input) && Object.entries(input).every(([k, v]) => isKey(k) && isValue(v));
|
|
151
|
+
var hasProperties = (isValue, options = { allowExtraProperties: false }) => {
|
|
152
|
+
const name = `{${recordToEntries(
|
|
153
|
+
isValue
|
|
154
|
+
).map(([k, v]) => String(k) + `:` + v.name).join(`,`)}}`;
|
|
155
|
+
const _ = {
|
|
156
|
+
[name]: (input) => isPlainObject(input) && pipe2(
|
|
157
|
+
isValue,
|
|
158
|
+
Object.entries,
|
|
159
|
+
every(([key, val]) => key in input || val(void 0))
|
|
160
|
+
) && pipe2(
|
|
161
|
+
input,
|
|
162
|
+
mob(
|
|
163
|
+
(val, key) => pipe2(
|
|
164
|
+
isValue,
|
|
165
|
+
access(key),
|
|
166
|
+
ifNullish(() => options.allowExtraProperties),
|
|
167
|
+
pass(val)
|
|
168
|
+
)
|
|
169
|
+
),
|
|
170
|
+
Object.values,
|
|
171
|
+
allTrue
|
|
172
|
+
)
|
|
173
|
+
};
|
|
174
|
+
return _[name];
|
|
175
|
+
};
|
|
176
|
+
var hasExactProperties = (
|
|
177
|
+
/* alias for hasProperties without allowExtraProperties */
|
|
178
|
+
(isValue) => hasProperties(isValue, { allowExtraProperties: false })
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// ../anvl/src/join/core-relation-data.ts
|
|
182
|
+
var RELATION_TYPES = [`1:1`, `1:n`, `n:n`];
|
|
183
|
+
var isRelationType = (x) => RELATION_TYPES.includes(x);
|
|
184
|
+
var EMPTY_RELATION_DATA = {
|
|
185
|
+
contents: {},
|
|
186
|
+
relations: {},
|
|
187
|
+
relationType: `n:n`
|
|
188
|
+
};
|
|
189
|
+
var isRelationData = (isContent) => (input) => hasExactProperties({
|
|
190
|
+
contents: isContent ? isRecord(isString, isContent) : hasExactProperties({}),
|
|
191
|
+
relations: isRecord(isString, isArray(isString)),
|
|
192
|
+
relationType: isRelationType
|
|
193
|
+
})(input);
|
|
194
|
+
|
|
195
|
+
// ../anvl/src/join/get-related-ids.ts
|
|
196
|
+
var getRelatedIds = (relationMap, id) => {
|
|
197
|
+
var _a;
|
|
198
|
+
return (_a = relationMap.relations[id]) != null ? _a : [];
|
|
199
|
+
};
|
|
200
|
+
var getRelatedId = (relationMap, id) => {
|
|
201
|
+
const relations = getRelatedIds(relationMap, id);
|
|
202
|
+
if (relations.length > 1) {
|
|
203
|
+
console.warn(
|
|
204
|
+
`entry with id ${id} was not expected to have multiple relations`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return relations[0];
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// ../anvl/src/join/relation-contents.ts
|
|
211
|
+
import { pipe as pipe5 } from "fp-ts/function";
|
|
212
|
+
|
|
213
|
+
// ../anvl/src/join/relation-record.ts
|
|
214
|
+
var getRelationEntries = (relationMap, idA) => getRelatedIds(relationMap, idA).map((idB) => [
|
|
215
|
+
idB,
|
|
216
|
+
getContent(relationMap, idA, idB)
|
|
217
|
+
]);
|
|
218
|
+
var getRelationRecord = (relationMap, id) => Object.fromEntries(getRelationEntries(relationMap, id));
|
|
219
|
+
|
|
220
|
+
// ../anvl/src/join/remove-relation.ts
|
|
221
|
+
import { pipe as pipe4 } from "fp-ts/function";
|
|
222
|
+
import { isString as isString2 } from "fp-ts/string";
|
|
223
|
+
|
|
224
|
+
// ../anvl/src/object/index.ts
|
|
225
|
+
import { pipe as pipe3 } from "fp-ts/function";
|
|
226
|
+
var treeShake = (shouldDiscard = isUndefined) => (obj) => {
|
|
227
|
+
const newObj = {};
|
|
228
|
+
const entries = Object.entries(obj);
|
|
229
|
+
entries.forEach(
|
|
230
|
+
([key, val]) => !shouldDiscard(val, key) ? newObj[key] = val : null
|
|
231
|
+
);
|
|
232
|
+
return newObj;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// ../anvl/src/string/split.ts
|
|
236
|
+
var split = (separator) => (str) => str.split(separator);
|
|
237
|
+
|
|
238
|
+
// ../anvl/src/join/remove-relation.ts
|
|
239
|
+
var removeSpecific = (current, idA, idB) => {
|
|
240
|
+
const isIdForRemoval = isOneOf(idA, idB);
|
|
241
|
+
return __spreadProps(__spreadValues({}, current), {
|
|
242
|
+
relations: pipe4(
|
|
243
|
+
current.relations,
|
|
244
|
+
recordToEntries,
|
|
245
|
+
map(([id, relations]) => [
|
|
246
|
+
id,
|
|
247
|
+
isIdForRemoval(id) ? relations.filter((relation) => !isIdForRemoval(relation)) : relations
|
|
248
|
+
]),
|
|
249
|
+
entriesToRecord,
|
|
250
|
+
treeShake(isEmptyArray)
|
|
251
|
+
),
|
|
252
|
+
contents: pipe4(
|
|
253
|
+
current.contents,
|
|
254
|
+
treeShake(
|
|
255
|
+
(_, key) => isString2(key) && pipe4(key, split(`/`), comprises([idA, idB]))
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
var removeAll = (current, idToRemove) => {
|
|
261
|
+
const next = __spreadProps(__spreadValues({}, current), {
|
|
262
|
+
relations: pipe4(
|
|
263
|
+
current.relations,
|
|
264
|
+
recordToEntries,
|
|
265
|
+
map(([id, relations]) => [
|
|
266
|
+
id,
|
|
267
|
+
relations.filter((relation) => relation !== idToRemove)
|
|
268
|
+
]),
|
|
269
|
+
entriesToRecord,
|
|
270
|
+
treeShake((val, key) => key === idToRemove || isEmptyArray(val))
|
|
271
|
+
),
|
|
272
|
+
contents: pipe4(
|
|
273
|
+
current.contents,
|
|
274
|
+
treeShake(
|
|
275
|
+
(_, key) => isString2(key) && key.split(`/`).includes(idToRemove)
|
|
276
|
+
)
|
|
277
|
+
)
|
|
278
|
+
});
|
|
279
|
+
return next;
|
|
280
|
+
};
|
|
281
|
+
var removeRelation = (current, idA, idB) => idB ? removeSpecific(current, idA, idB) : removeAll(current, idA);
|
|
282
|
+
|
|
283
|
+
// ../anvl/src/join/set-relation.ts
|
|
284
|
+
var setManyToMany = (map2, idA, idB, ...rest) => {
|
|
285
|
+
var _a, _b;
|
|
286
|
+
const next = __spreadProps(__spreadValues({}, map2), {
|
|
287
|
+
relations: __spreadProps(__spreadValues({}, map2.relations), {
|
|
288
|
+
[idA]: addTo((_a = map2.relations[idA]) != null ? _a : [])(idB),
|
|
289
|
+
[idB]: addTo((_b = map2.relations[idB]) != null ? _b : [])(idA)
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
const content = rest[0];
|
|
293
|
+
return content ? setContent(next, idA, idB, content) : next;
|
|
294
|
+
};
|
|
295
|
+
var removeEmpties = treeShake(isEmptyArray);
|
|
296
|
+
var set1ToMany = (current, leaderId, followerId, ...rest) => {
|
|
297
|
+
var _a;
|
|
298
|
+
const relations = __spreadValues({}, current.relations);
|
|
299
|
+
const prevLeaderId = getRelatedId(current, followerId);
|
|
300
|
+
const next = __spreadProps(__spreadValues({}, current), {
|
|
301
|
+
relations: removeEmpties(__spreadProps(__spreadValues(__spreadValues({}, relations), prevLeaderId && prevLeaderId !== leaderId && {
|
|
302
|
+
[prevLeaderId]: relations[prevLeaderId].filter(
|
|
303
|
+
(id) => id !== followerId
|
|
304
|
+
)
|
|
305
|
+
}), {
|
|
306
|
+
[followerId]: [leaderId],
|
|
307
|
+
[leaderId]: addTo((_a = relations[leaderId]) != null ? _a : [])(followerId)
|
|
308
|
+
}))
|
|
309
|
+
});
|
|
310
|
+
const content = rest[0];
|
|
311
|
+
return content ? setContent(next, leaderId, followerId, content) : next;
|
|
312
|
+
};
|
|
313
|
+
var set1To1 = (current, wifeId, husbandId, ...rest) => {
|
|
314
|
+
const prevWifeId = getRelatedId(current, husbandId);
|
|
315
|
+
const prevHusbandId = getRelatedId(current, wifeId);
|
|
316
|
+
const next = __spreadProps(__spreadValues({}, current), {
|
|
317
|
+
relations: removeEmpties(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, current.relations), prevWifeId && { [prevWifeId]: [] }), prevHusbandId && { [prevHusbandId]: [] }), {
|
|
318
|
+
[wifeId]: [husbandId],
|
|
319
|
+
[husbandId]: [wifeId]
|
|
320
|
+
}))
|
|
321
|
+
});
|
|
322
|
+
const content = rest[0];
|
|
323
|
+
return content ? setContent(next, wifeId, husbandId, content) : next;
|
|
324
|
+
};
|
|
325
|
+
var setRelationWithContent = (current, idA, idB, ...rest) => {
|
|
326
|
+
switch (current.relationType) {
|
|
327
|
+
case `1:1`:
|
|
328
|
+
return set1To1(current, idA, idB, ...rest);
|
|
329
|
+
case `1:n`:
|
|
330
|
+
return set1ToMany(current, idA, idB, ...rest);
|
|
331
|
+
case `n:n`:
|
|
332
|
+
return setManyToMany(current, idA, idB, ...rest);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// ../anvl/src/join/relation-contents.ts
|
|
337
|
+
var makeContentId = (idA, idB) => [idA, idB].sort().join(`/`);
|
|
338
|
+
var getContent = (relationMap, idA, idB) => relationMap.contents[makeContentId(idA, idB)];
|
|
339
|
+
var setContent = (map2, idA, idB, content) => __spreadProps(__spreadValues({}, map2), {
|
|
340
|
+
contents: __spreadProps(__spreadValues({}, map2.contents), {
|
|
341
|
+
[makeContentId(idA, idB)]: content
|
|
342
|
+
})
|
|
343
|
+
});
|
|
344
|
+
var getRelations = (relationMap, id) => getRelationEntries(relationMap, id).map(
|
|
345
|
+
([id2, content]) => __spreadValues({
|
|
346
|
+
id: id2
|
|
347
|
+
}, content)
|
|
348
|
+
);
|
|
349
|
+
var setRelations = (current, idA, relations) => pipe5(
|
|
350
|
+
current,
|
|
351
|
+
(relationData) => {
|
|
352
|
+
const relatedIds = getRelatedIds(current, idA);
|
|
353
|
+
const removedIds = relatedIds.filter(
|
|
354
|
+
(id) => !relations.some((r) => r.id === id)
|
|
355
|
+
);
|
|
356
|
+
let step = relationData;
|
|
357
|
+
for (const idB of removedIds)
|
|
358
|
+
step = removeRelation(step, idA, idB);
|
|
359
|
+
return step;
|
|
360
|
+
},
|
|
361
|
+
(relationData) => {
|
|
362
|
+
let step = relationData;
|
|
363
|
+
for (const _a of relations) {
|
|
364
|
+
const _b = _a, { id: idB } = _b, rest = __objRest(_b, ["id"]);
|
|
365
|
+
const content = isEmptyObject(rest) ? void 0 : rest;
|
|
366
|
+
step = setRelationWithContent(step, idA, idB, content);
|
|
367
|
+
}
|
|
368
|
+
return step;
|
|
369
|
+
},
|
|
370
|
+
(relationData) => {
|
|
371
|
+
const newlyOrderedIds = relations.map((r) => r.id);
|
|
372
|
+
return __spreadProps(__spreadValues({}, relationData), {
|
|
373
|
+
relations: __spreadProps(__spreadValues({}, relationData.relations), {
|
|
374
|
+
[idA]: newlyOrderedIds
|
|
375
|
+
})
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
// ../anvl/src/refinement/index.ts
|
|
381
|
+
var canExist = (_) => true;
|
|
382
|
+
var cannotExist = (_) => false;
|
|
383
|
+
var couldBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
|
|
384
|
+
const name = `(${refinements.map((r) => r.name || `anon`).join(` | `)})`;
|
|
385
|
+
const _ = {
|
|
386
|
+
[name]: (input) => refinements.some(
|
|
387
|
+
(refinement) => {
|
|
388
|
+
var _a;
|
|
389
|
+
return logging && console.log(
|
|
390
|
+
refinements.map((r) => r.name || `anon`).join(` | `),
|
|
391
|
+
`>`,
|
|
392
|
+
(_a = refinement.name) != null ? _a : `anon`,
|
|
393
|
+
`:`,
|
|
394
|
+
refinement(input)
|
|
395
|
+
), refinement(input);
|
|
396
|
+
}
|
|
397
|
+
)
|
|
398
|
+
};
|
|
399
|
+
const checkTypes = Object.assign(_[name], {
|
|
400
|
+
or: (isTypeB) => couldBe(isTypeB, logging, [...refinements, isTypeB])
|
|
401
|
+
});
|
|
402
|
+
return checkTypes;
|
|
403
|
+
};
|
|
404
|
+
var isUnion = couldBe(cannotExist);
|
|
405
|
+
var mustBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
|
|
406
|
+
const name = `(${refinements.map((r) => r.name || `anon`).join(` & `)})`;
|
|
407
|
+
const _ = {
|
|
408
|
+
[name]: (input) => refinements.every(
|
|
409
|
+
(refinement) => (logging && console.log(
|
|
410
|
+
refinements.map((r) => r.name || `anon`).join(` & `),
|
|
411
|
+
`>`,
|
|
412
|
+
refinement.name || `anon`,
|
|
413
|
+
`:`,
|
|
414
|
+
refinement(input)
|
|
415
|
+
), refinement(input))
|
|
416
|
+
)
|
|
417
|
+
};
|
|
418
|
+
const checkTypes = Object.assign(_[name], {
|
|
419
|
+
and: (isTypeB) => mustBe(isTypeB, logging, [...refinements, isTypeB])
|
|
420
|
+
});
|
|
421
|
+
return checkTypes;
|
|
422
|
+
};
|
|
423
|
+
var isIntersection = mustBe(canExist);
|
|
424
|
+
|
|
425
|
+
// ../anvl/src/join/index.ts
|
|
426
|
+
var Join = class {
|
|
427
|
+
constructor(json) {
|
|
428
|
+
Object.assign(this, __spreadValues(__spreadValues({}, EMPTY_RELATION_DATA), json));
|
|
429
|
+
}
|
|
430
|
+
toJSON() {
|
|
431
|
+
return {
|
|
432
|
+
relationType: this.relationType,
|
|
433
|
+
relations: this.relations,
|
|
434
|
+
contents: this.contents
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
static fromJSON(json, isContent = cannotExist) {
|
|
438
|
+
const isValid = isRelationData(isContent)(json);
|
|
439
|
+
if (isValid) {
|
|
440
|
+
return new Join(json);
|
|
441
|
+
}
|
|
442
|
+
throw new Error(
|
|
443
|
+
`Saved JSON for this Join is invalid: ${JSON.stringify(json)}`
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
getRelatedId(id) {
|
|
447
|
+
return getRelatedId(this, id);
|
|
448
|
+
}
|
|
449
|
+
getRelatedIds(id) {
|
|
450
|
+
return getRelatedIds(this, id);
|
|
451
|
+
}
|
|
452
|
+
getContent(idA, idB) {
|
|
453
|
+
return getContent(this, idA, idB);
|
|
454
|
+
}
|
|
455
|
+
getRelationEntries(id) {
|
|
456
|
+
return getRelationEntries(this, id);
|
|
457
|
+
}
|
|
458
|
+
getRelationRecord(id) {
|
|
459
|
+
return getRelationRecord(this, id);
|
|
460
|
+
}
|
|
461
|
+
getRelation(id) {
|
|
462
|
+
return getRelations(this, id)[0];
|
|
463
|
+
}
|
|
464
|
+
getRelations(id) {
|
|
465
|
+
return getRelations(this, id);
|
|
466
|
+
}
|
|
467
|
+
setRelations(id, relations) {
|
|
468
|
+
return new Join(setRelations(this, id, relations));
|
|
469
|
+
}
|
|
470
|
+
set(idA, idB, ...rest) {
|
|
471
|
+
return new Join(setRelationWithContent(this, idA, idB, ...rest));
|
|
472
|
+
}
|
|
473
|
+
remove(idA, idB) {
|
|
474
|
+
return new Join(removeRelation(this, idA, idB));
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// src/internal/store.ts
|
|
479
|
+
var createStore = (name) => ({
|
|
480
|
+
valueMap: HAMT.make(),
|
|
481
|
+
selectorGraph: new Join({ relationType: `n:n` }),
|
|
482
|
+
atoms: HAMT.make(),
|
|
483
|
+
selectors: HAMT.make(),
|
|
484
|
+
readonlySelectors: HAMT.make(),
|
|
485
|
+
operation: {
|
|
486
|
+
open: false
|
|
487
|
+
},
|
|
488
|
+
transaction: {
|
|
489
|
+
open: false
|
|
490
|
+
},
|
|
491
|
+
config: {
|
|
492
|
+
name,
|
|
493
|
+
logger: null
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
var IMPLICIT = {
|
|
497
|
+
STORE_INTERNAL: void 0,
|
|
498
|
+
get STORE() {
|
|
499
|
+
var _a;
|
|
500
|
+
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = createStore(`DEFAULT`);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
var configure = (config, store = IMPLICIT.STORE) => {
|
|
504
|
+
Object.assign(store.config, config);
|
|
505
|
+
};
|
|
506
|
+
var clearStore = (store = IMPLICIT.STORE) => {
|
|
507
|
+
const { config } = store;
|
|
508
|
+
Object.assign(store, createStore(config.name));
|
|
509
|
+
store.config = config;
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
// src/internal/get.ts
|
|
513
|
+
var getCachedState = (state, store = IMPLICIT.STORE) => {
|
|
514
|
+
const value = HAMT2.get(state.key, store.valueMap);
|
|
515
|
+
return value;
|
|
516
|
+
};
|
|
517
|
+
var getSelectorState = (selector) => selector.get();
|
|
518
|
+
function withdraw(token, store) {
|
|
519
|
+
var _a, _b;
|
|
520
|
+
return (_b = (_a = HAMT2.get(token.key, store.atoms)) != null ? _a : HAMT2.get(token.key, store.selectors)) != null ? _b : HAMT2.get(token.key, store.readonlySelectors);
|
|
521
|
+
}
|
|
522
|
+
function deposit(state) {
|
|
523
|
+
if (`get` in state) {
|
|
524
|
+
if (`set` in state) {
|
|
525
|
+
return { key: state.key, type: `selector` };
|
|
526
|
+
}
|
|
527
|
+
return { key: state.key, type: `readonly_selector` };
|
|
528
|
+
}
|
|
529
|
+
return { key: state.key, type: `atom` };
|
|
530
|
+
}
|
|
531
|
+
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
532
|
+
var _a;
|
|
533
|
+
if (HAMT2.has(state.key, store.valueMap)) {
|
|
534
|
+
return getCachedState(state, store);
|
|
535
|
+
}
|
|
536
|
+
if (`get` in state) {
|
|
537
|
+
return getSelectorState(state);
|
|
538
|
+
}
|
|
539
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
540
|
+
`Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
541
|
+
);
|
|
542
|
+
return state.default;
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// src/internal/set.ts
|
|
546
|
+
import HAMT4 from "hamt_plus";
|
|
547
|
+
|
|
548
|
+
// src/internal/operation.ts
|
|
549
|
+
import HAMT3 from "hamt_plus";
|
|
550
|
+
var startAction = (store) => {
|
|
551
|
+
var _a;
|
|
552
|
+
store.operation = {
|
|
553
|
+
open: true,
|
|
554
|
+
done: /* @__PURE__ */ new Set(),
|
|
555
|
+
prev: store.valueMap
|
|
556
|
+
};
|
|
557
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u2610`, `operation start`);
|
|
558
|
+
};
|
|
559
|
+
var finishAction = (store) => {
|
|
560
|
+
var _a;
|
|
561
|
+
store.operation = { open: false };
|
|
562
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u2611\uFE0F`, `operation done`);
|
|
563
|
+
};
|
|
564
|
+
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
565
|
+
var _a;
|
|
566
|
+
if (!store.operation.open) {
|
|
567
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
568
|
+
`isDone called outside of an action. This is probably a bug.`
|
|
569
|
+
);
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
return store.operation.done.has(key);
|
|
573
|
+
};
|
|
574
|
+
var markDone = (key, store = IMPLICIT.STORE) => {
|
|
575
|
+
var _a;
|
|
576
|
+
if (!store.operation.open) {
|
|
577
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
578
|
+
`markDone called outside of an action. This is probably a bug.`
|
|
579
|
+
);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
store.operation.done.add(key);
|
|
583
|
+
};
|
|
584
|
+
var recall = (state, store = IMPLICIT.STORE) => {
|
|
585
|
+
var _a;
|
|
586
|
+
if (!store.operation.open) {
|
|
587
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
588
|
+
`recall called outside of an action. This is probably a bug.`
|
|
589
|
+
);
|
|
590
|
+
return HAMT3.get(state.key, store.valueMap);
|
|
591
|
+
}
|
|
592
|
+
return HAMT3.get(state.key, store.operation.prev);
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// src/internal/set.ts
|
|
596
|
+
var propagateDown = (state, store = IMPLICIT.STORE) => {
|
|
597
|
+
var _a, _b;
|
|
598
|
+
const relatedStateKeys = store.selectorGraph.getRelations(state.key);
|
|
599
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
600
|
+
` ||`,
|
|
601
|
+
`bumping`,
|
|
602
|
+
relatedStateKeys.length,
|
|
603
|
+
`states:`,
|
|
604
|
+
relatedStateKeys.map(({ id }) => id)
|
|
605
|
+
);
|
|
606
|
+
if (store.operation.open) {
|
|
607
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(` ||`, `done:`, store.operation.done);
|
|
608
|
+
}
|
|
609
|
+
relatedStateKeys.forEach(({ id: stateKey }) => {
|
|
610
|
+
var _a2, _b2, _c, _d, _e;
|
|
611
|
+
if (isDone(stateKey, store)) {
|
|
612
|
+
(_a2 = store.config.logger) == null ? void 0 : _a2.info(` ||`, stateKey, `already done`);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
(_b2 = store.config.logger) == null ? void 0 : _b2.info(`->`, `bumping`, stateKey);
|
|
616
|
+
const state2 = (_c = HAMT4.get(stateKey, store.selectors)) != null ? _c : HAMT4.get(stateKey, store.readonlySelectors);
|
|
617
|
+
if (!state2) {
|
|
618
|
+
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
619
|
+
` ||`,
|
|
620
|
+
stateKey,
|
|
621
|
+
`is an atom - no need to propagate down`
|
|
622
|
+
);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
store.valueMap = HAMT4.remove(stateKey, store.valueMap);
|
|
626
|
+
const newValue = getState__INTERNAL(state2, store);
|
|
627
|
+
(_e = store.config.logger) == null ? void 0 : _e.info(` <-`, stateKey, `became`, newValue);
|
|
628
|
+
const oldValue = recall(state2, store);
|
|
629
|
+
state2.subject.next({ newValue, oldValue });
|
|
630
|
+
markDone(stateKey, store);
|
|
631
|
+
if (`set` in state2)
|
|
632
|
+
propagateDown(state2, store);
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
|
|
636
|
+
var _a, _b;
|
|
637
|
+
const oldValue = getState__INTERNAL(atom, store);
|
|
638
|
+
const newValue = become(next)(oldValue);
|
|
639
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
640
|
+
`->`,
|
|
641
|
+
`setting atom`,
|
|
642
|
+
`"${atom.key}"`,
|
|
643
|
+
`to`,
|
|
644
|
+
newValue
|
|
645
|
+
);
|
|
646
|
+
store.valueMap = HAMT4.set(atom.key, newValue, store.valueMap);
|
|
647
|
+
markDone(atom.key, store);
|
|
648
|
+
atom.subject.next({ newValue, oldValue });
|
|
649
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
650
|
+
` ||`,
|
|
651
|
+
`propagating change made to`,
|
|
652
|
+
`"${atom.key}"`
|
|
653
|
+
);
|
|
654
|
+
propagateDown(atom, store);
|
|
655
|
+
};
|
|
656
|
+
var setSelectorState = (selector, next, store = IMPLICIT.STORE) => {
|
|
657
|
+
var _a, _b;
|
|
658
|
+
const oldValue = getState__INTERNAL(selector, store);
|
|
659
|
+
const newValue = become(next)(oldValue);
|
|
660
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
661
|
+
`->`,
|
|
662
|
+
`setting selector`,
|
|
663
|
+
`"${selector.key}"`,
|
|
664
|
+
`to`,
|
|
665
|
+
newValue
|
|
666
|
+
);
|
|
667
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
668
|
+
` ||`,
|
|
669
|
+
`propagating change made to`,
|
|
670
|
+
`"${selector.key}"`
|
|
671
|
+
);
|
|
672
|
+
selector.set(newValue);
|
|
673
|
+
propagateDown(selector, store);
|
|
674
|
+
};
|
|
675
|
+
var setState__INTERNAL = (token, value, store = IMPLICIT.STORE) => {
|
|
676
|
+
const state = withdraw(token, store);
|
|
677
|
+
if (`set` in state) {
|
|
678
|
+
setSelectorState(state, value, store);
|
|
679
|
+
} else {
|
|
680
|
+
setAtomState(state, value, store);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// src/internal/transaction-internal.ts
|
|
685
|
+
var finishTransaction = (store) => {
|
|
686
|
+
var _a;
|
|
687
|
+
store.transaction = { open: false };
|
|
688
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F6EC}`, `transaction done`);
|
|
689
|
+
};
|
|
690
|
+
var startTransaction = (store) => {
|
|
691
|
+
var _a;
|
|
692
|
+
store.transaction = {
|
|
693
|
+
open: true,
|
|
694
|
+
prev: {
|
|
695
|
+
atoms: store.atoms,
|
|
696
|
+
readonlySelectors: store.readonlySelectors,
|
|
697
|
+
selectorGraph: store.selectorGraph,
|
|
698
|
+
selectors: store.selectors,
|
|
699
|
+
valueMap: store.valueMap
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F6EB}`, `transaction start`);
|
|
703
|
+
};
|
|
704
|
+
var abortTransaction = (store) => {
|
|
705
|
+
var _a, _b;
|
|
706
|
+
if (!store.transaction.open) {
|
|
707
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
708
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
709
|
+
);
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
store.atoms = store.transaction.prev.atoms;
|
|
713
|
+
store.readonlySelectors = store.transaction.prev.readonlySelectors;
|
|
714
|
+
store.selectorGraph = store.transaction.prev.selectorGraph;
|
|
715
|
+
store.selectors = store.transaction.prev.selectors;
|
|
716
|
+
store.valueMap = store.transaction.prev.valueMap;
|
|
717
|
+
store.transaction = { open: false };
|
|
718
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
// src/index.ts
|
|
722
|
+
var setState = (state, value, store = IMPLICIT.STORE) => {
|
|
723
|
+
startAction(store);
|
|
724
|
+
setState__INTERNAL(state, value, store);
|
|
725
|
+
finishAction(store);
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
// src/react/index.ts
|
|
729
|
+
var composeStoreHook = ({
|
|
730
|
+
useState,
|
|
731
|
+
useEffect,
|
|
732
|
+
store = internal_exports.IMPLICIT.STORE
|
|
733
|
+
}) => {
|
|
734
|
+
const useSubject = composeSubjectHook(useState, useEffect);
|
|
735
|
+
function useStore(token) {
|
|
736
|
+
const { type } = token;
|
|
737
|
+
const state = withdraw(token, store);
|
|
738
|
+
const initialValue = internal_exports.getState__INTERNAL(state, store);
|
|
739
|
+
const [value] = useSubject(state.subject, initialValue);
|
|
740
|
+
if (type === `readonly_selector`) {
|
|
741
|
+
return value;
|
|
742
|
+
}
|
|
743
|
+
const updateState = (next) => setState(token, next, store);
|
|
744
|
+
return [value, updateState];
|
|
745
|
+
}
|
|
746
|
+
return { useStore };
|
|
747
|
+
};
|
|
748
|
+
export {
|
|
749
|
+
composeStoreHook
|
|
750
|
+
};
|
|
751
|
+
//# sourceMappingURL=index.mjs.map
|