atom.io 0.30.0 → 0.30.2
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.d.ts +84 -51
- package/data/dist/index.js +45 -39
- package/data/src/join.ts +250 -142
- package/dist/chunk-ADMEAXYU.js +167 -0
- package/dist/{chunk-7PUUHSXC.js → chunk-LSCRHXLI.js} +67 -176
- package/dist/index.d.ts +53 -5
- package/dist/index.js +1 -1
- package/internal/dist/index.d.ts +64 -35
- package/internal/dist/index.js +2 -2
- package/internal/src/junction.ts +170 -86
- package/internal/src/molecule/make-molecule-in-store.ts +3 -1
- package/internal/src/molecule/molecule-internal.ts +1 -1
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/get-json-family.ts +2 -2
- package/internal/src/store/store.ts +4 -0
- package/internal/src/transaction/index.ts +1 -1
- package/json/dist/index.js +2 -2
- package/package.json +15 -15
- package/realtime/dist/index.d.ts +1 -1
- package/realtime/dist/index.js +3 -1
- package/realtime/src/shared-room-store.ts +2 -0
- package/realtime-server/dist/index.d.ts +15 -6
- package/realtime-server/dist/index.js +4 -2
- package/realtime-server/src/realtime-continuity-synchronizer.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +21 -5
- package/realtime-testing/dist/index.d.ts +3 -0
- package/realtime-testing/dist/index.js +17 -6
- package/realtime-testing/src/setup-realtime-test.tsx +16 -6
- package/src/allocate.ts +7 -8
- package/src/index.ts +1 -0
- package/src/molecule.ts +5 -3
- package/dist/chunk-ZKG6ZA4I.js +0 -20
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { createMoleculeFamily, IMPLICIT, makeMoleculeInStore, Molecule, newest, isChildStore, disposeFromStore } from 'atom.io/internal';
|
|
2
|
+
import { stringifyJson } from 'atom.io/json';
|
|
3
|
+
|
|
4
|
+
// src/molecule.ts
|
|
5
|
+
function moleculeFamily(options) {
|
|
6
|
+
return createMoleculeFamily(IMPLICIT.STORE, options);
|
|
7
|
+
}
|
|
8
|
+
function makeMolecule(context, family, key, ...params) {
|
|
9
|
+
return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
|
|
10
|
+
}
|
|
11
|
+
function makeRootMoleculeInStore(key, store = IMPLICIT.STORE) {
|
|
12
|
+
const molecule = new Molecule(void 0, key);
|
|
13
|
+
store.molecules.set(stringifyJson(key), molecule);
|
|
14
|
+
return {
|
|
15
|
+
key,
|
|
16
|
+
type: `molecule`
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var $provenance = Symbol(`provenance`);
|
|
20
|
+
function allocateIntoStore(store, provenance, key) {
|
|
21
|
+
const stringKey = stringifyJson(key);
|
|
22
|
+
try {
|
|
23
|
+
const above = [];
|
|
24
|
+
let allocationAttachmentStyle;
|
|
25
|
+
if (provenance === `root`) {
|
|
26
|
+
above.push(store.molecules.get(`"root"`));
|
|
27
|
+
allocationAttachmentStyle = `all`;
|
|
28
|
+
} else if (typeof provenance === `string` && provenance.startsWith(T$)) {
|
|
29
|
+
allocationAttachmentStyle = `any`;
|
|
30
|
+
const provenanceKey = stringifyJson(provenance);
|
|
31
|
+
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
32
|
+
if (!provenanceMolecule) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
above.push(provenanceMolecule);
|
|
38
|
+
} else {
|
|
39
|
+
const allocationIsCompound = key.startsWith(`T$--`);
|
|
40
|
+
if (allocationIsCompound) {
|
|
41
|
+
allocationAttachmentStyle = `all`;
|
|
42
|
+
for (const claim of provenance) {
|
|
43
|
+
const provenanceKey = stringifyJson(claim);
|
|
44
|
+
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
45
|
+
if (!provenanceMolecule) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
above.push(provenanceMolecule);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
allocationAttachmentStyle = `any`;
|
|
54
|
+
const provenanceKey = stringifyJson(provenance);
|
|
55
|
+
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
56
|
+
if (!provenanceMolecule) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
above.push(provenanceMolecule);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const molecule = new Molecule(above, key);
|
|
65
|
+
molecule._dependsOn = allocationAttachmentStyle;
|
|
66
|
+
store.molecules.set(stringKey, molecule);
|
|
67
|
+
for (const aboveMolecule of above) {
|
|
68
|
+
aboveMolecule.below.set(molecule.stringKey, molecule);
|
|
69
|
+
}
|
|
70
|
+
const creationEvent = {
|
|
71
|
+
type: `molecule_creation`,
|
|
72
|
+
subType: `modern`,
|
|
73
|
+
key: molecule.key,
|
|
74
|
+
provenance
|
|
75
|
+
};
|
|
76
|
+
const target = newest(store);
|
|
77
|
+
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
78
|
+
if (isTransaction) {
|
|
79
|
+
target.transactionMeta.update.updates.push(creationEvent);
|
|
80
|
+
} else {
|
|
81
|
+
target.on.moleculeCreationStart.next(creationEvent);
|
|
82
|
+
}
|
|
83
|
+
} catch (thrown) {
|
|
84
|
+
if (thrown instanceof Error) {
|
|
85
|
+
store.logger.error(
|
|
86
|
+
`\u274C`,
|
|
87
|
+
`molecule`,
|
|
88
|
+
stringKey,
|
|
89
|
+
`allocation failed:`,
|
|
90
|
+
thrown.message
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return key;
|
|
95
|
+
}
|
|
96
|
+
function deallocateFromStore(store, claim) {
|
|
97
|
+
const stringKey = stringifyJson(claim);
|
|
98
|
+
const molecule = store.molecules.get(stringKey);
|
|
99
|
+
if (!molecule) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Molecule ${stringKey} not found in store "${store.config.name}"`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
for (const join of molecule.joins.values()) {
|
|
105
|
+
join.relations.delete(molecule.key);
|
|
106
|
+
join.molecules.delete(molecule.stringKey);
|
|
107
|
+
}
|
|
108
|
+
let provenance;
|
|
109
|
+
if (molecule.above.size === 1) {
|
|
110
|
+
const above = molecule.above.values().next().value;
|
|
111
|
+
provenance = above.key;
|
|
112
|
+
} else {
|
|
113
|
+
provenance = [...molecule.above.values()].map(({ key }) => key);
|
|
114
|
+
}
|
|
115
|
+
const values = [];
|
|
116
|
+
for (const stateToken of molecule.tokens.values()) {
|
|
117
|
+
const tokenFamily = stateToken.family;
|
|
118
|
+
values.push([tokenFamily.key, store.valueMap.get(stateToken.key)]);
|
|
119
|
+
}
|
|
120
|
+
for (const state of molecule.tokens.values()) {
|
|
121
|
+
disposeFromStore(store, state);
|
|
122
|
+
}
|
|
123
|
+
for (const child of molecule.below.values()) {
|
|
124
|
+
if (child.dependsOn === `all`) {
|
|
125
|
+
deallocateFromStore(store, child.key);
|
|
126
|
+
} else {
|
|
127
|
+
child.above.delete(molecule.stringKey);
|
|
128
|
+
if (child.above.size === 0) {
|
|
129
|
+
deallocateFromStore(store, child.key);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
molecule.below.clear();
|
|
134
|
+
const disposalEvent = {
|
|
135
|
+
type: `molecule_disposal`,
|
|
136
|
+
subType: `modern`,
|
|
137
|
+
key: molecule.key,
|
|
138
|
+
values,
|
|
139
|
+
provenance
|
|
140
|
+
};
|
|
141
|
+
const target = newest(store);
|
|
142
|
+
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
143
|
+
if (isTransaction) {
|
|
144
|
+
target.transactionMeta.update.updates.push(disposalEvent);
|
|
145
|
+
} else {
|
|
146
|
+
target.on.moleculeDisposal.next(disposalEvent);
|
|
147
|
+
}
|
|
148
|
+
target.molecules.delete(molecule.stringKey);
|
|
149
|
+
for (const parent of molecule.above.values()) {
|
|
150
|
+
parent.below.delete(molecule.stringKey);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function realm(store) {
|
|
154
|
+
const root = makeRootMoleculeInStore(`root`, store);
|
|
155
|
+
return {
|
|
156
|
+
root,
|
|
157
|
+
allocate: (provenance, key) => {
|
|
158
|
+
return allocateIntoStore(store, provenance, key);
|
|
159
|
+
},
|
|
160
|
+
deallocate: (claim) => {
|
|
161
|
+
deallocateFromStore(store, claim);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
var T$ = `T$`;
|
|
166
|
+
|
|
167
|
+
export { $provenance, T$, allocateIntoStore, deallocateFromStore, makeMolecule, makeRootMoleculeInStore, moleculeFamily, realm };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { deallocateFromStore, allocateIntoStore } from './chunk-ADMEAXYU.js';
|
|
1
2
|
import { stringifyJson, parseJson, selectJson, selectJsonFamily } from 'atom.io/json';
|
|
2
3
|
import { AtomIOLogger } from 'atom.io';
|
|
3
4
|
import { getJoin, findRelations } from 'atom.io/data';
|
|
4
|
-
import { subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary as arbitrary$1
|
|
5
|
+
import { subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary as arbitrary$1 } from 'atom.io/internal';
|
|
5
6
|
|
|
6
7
|
// internal/src/arbitrary.ts
|
|
7
8
|
function arbitrary(random = Math.random) {
|
|
@@ -120,6 +121,8 @@ var Junction = class {
|
|
|
120
121
|
cardinality;
|
|
121
122
|
relations = /* @__PURE__ */ new Map();
|
|
122
123
|
contents = /* @__PURE__ */ new Map();
|
|
124
|
+
isAType;
|
|
125
|
+
isBType;
|
|
123
126
|
isContent;
|
|
124
127
|
makeContentKey = (a, b) => `${a}:${b}`;
|
|
125
128
|
warn;
|
|
@@ -158,36 +161,40 @@ var Junction = class {
|
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
163
|
}
|
|
161
|
-
replaceRelationsUnsafely(
|
|
162
|
-
this.relations.set(
|
|
163
|
-
for (const
|
|
164
|
-
const
|
|
165
|
-
this.relations.set(
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
replaceRelationsSafely(
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
164
|
+
replaceRelationsUnsafely(x, ys) {
|
|
165
|
+
this.relations.set(x, new Set(ys));
|
|
166
|
+
for (const y of ys) {
|
|
167
|
+
const yRelations = (/* @__PURE__ */ new Set()).add(x);
|
|
168
|
+
this.relations.set(y, yRelations);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
replaceRelationsSafely(x, ys) {
|
|
172
|
+
const xRelationsPrev = this.relations.get(x);
|
|
173
|
+
let a = this.isAType?.(x) ? x : void 0;
|
|
174
|
+
let b = a === void 0 ? x : void 0;
|
|
175
|
+
if (xRelationsPrev) {
|
|
176
|
+
for (const y of xRelationsPrev) {
|
|
177
|
+
a ??= y;
|
|
178
|
+
b ??= y;
|
|
179
|
+
const yRelations = this.relations.get(y);
|
|
180
|
+
if (yRelations) {
|
|
181
|
+
if (yRelations.size === 1) {
|
|
182
|
+
this.relations.delete(y);
|
|
176
183
|
} else {
|
|
177
|
-
|
|
184
|
+
yRelations.delete(x);
|
|
178
185
|
}
|
|
179
186
|
this.contents.delete(this.makeContentKey(a, b));
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
189
|
}
|
|
183
|
-
this.relations.set(
|
|
184
|
-
for (const
|
|
185
|
-
let
|
|
186
|
-
if (
|
|
187
|
-
|
|
190
|
+
this.relations.set(x, new Set(ys));
|
|
191
|
+
for (const y of ys) {
|
|
192
|
+
let yRelations = this.relations.get(y);
|
|
193
|
+
if (yRelations) {
|
|
194
|
+
yRelations.add(x);
|
|
188
195
|
} else {
|
|
189
|
-
|
|
190
|
-
this.relations.set(
|
|
196
|
+
yRelations = (/* @__PURE__ */ new Set()).add(x);
|
|
197
|
+
this.relations.set(y, yRelations);
|
|
191
198
|
}
|
|
192
199
|
}
|
|
193
200
|
}
|
|
@@ -205,9 +212,13 @@ var Junction = class {
|
|
|
205
212
|
this.b = data.between[1];
|
|
206
213
|
this.cardinality = data.cardinality;
|
|
207
214
|
if (!config?.externalStore) {
|
|
208
|
-
this.relations = new Map(
|
|
215
|
+
this.relations = new Map(
|
|
216
|
+
data.relations?.map(([x, ys]) => [x, new Set(ys)])
|
|
217
|
+
);
|
|
209
218
|
this.contents = new Map(data.contents);
|
|
210
219
|
}
|
|
220
|
+
this.isAType = config?.isAType ?? null;
|
|
221
|
+
this.isBType = config?.isBType ?? null;
|
|
211
222
|
this.isContent = config?.isContent ?? null;
|
|
212
223
|
if (config?.makeContentKey) {
|
|
213
224
|
this.makeContentKey = config.makeContentKey;
|
|
@@ -227,7 +238,9 @@ var Junction = class {
|
|
|
227
238
|
this.replaceRelationsUnsafely = (a, bs) => {
|
|
228
239
|
externalStore.replaceRelationsUnsafely(a, bs);
|
|
229
240
|
};
|
|
230
|
-
this.getRelatedKeys = (key) => externalStore.getRelatedKeys(
|
|
241
|
+
this.getRelatedKeys = (key) => externalStore.getRelatedKeys(
|
|
242
|
+
key
|
|
243
|
+
);
|
|
231
244
|
if (externalStore.getContent) {
|
|
232
245
|
this.getContentInternal = (contentKey) => {
|
|
233
246
|
return externalStore.getContent(contentKey);
|
|
@@ -240,7 +253,13 @@ var Junction = class {
|
|
|
240
253
|
};
|
|
241
254
|
}
|
|
242
255
|
for (const [x, ys] of data.relations ?? []) {
|
|
243
|
-
|
|
256
|
+
let a = this.isAType?.(x) ? x : void 0;
|
|
257
|
+
let b = a === void 0 ? x : void 0;
|
|
258
|
+
for (const y of ys) {
|
|
259
|
+
a ??= y;
|
|
260
|
+
b ??= y;
|
|
261
|
+
this.addRelation(a, b);
|
|
262
|
+
}
|
|
244
263
|
}
|
|
245
264
|
for (const [contentKey, content] of data.contents ?? []) {
|
|
246
265
|
this.setContent(contentKey, content);
|
|
@@ -254,7 +273,9 @@ var Junction = class {
|
|
|
254
273
|
return {
|
|
255
274
|
between: [this.a, this.b],
|
|
256
275
|
cardinality: this.cardinality,
|
|
257
|
-
relations: [...this.relations.entries()].map(
|
|
276
|
+
relations: [...this.relations.entries()].map(
|
|
277
|
+
([a, b]) => [a, [...b]]
|
|
278
|
+
),
|
|
258
279
|
contents: [...this.contents.entries()]
|
|
259
280
|
};
|
|
260
281
|
}
|
|
@@ -266,7 +287,7 @@ var Junction = class {
|
|
|
266
287
|
// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here
|
|
267
288
|
case `1:1`: {
|
|
268
289
|
const bPrev = this.getRelatedKey(a);
|
|
269
|
-
if (bPrev && bPrev !== b) this.delete(
|
|
290
|
+
if (bPrev && bPrev !== b) this.delete(a, bPrev);
|
|
270
291
|
}
|
|
271
292
|
case `1:n`: {
|
|
272
293
|
const aPrev = this.getRelatedKey(b);
|
|
@@ -282,7 +303,10 @@ var Junction = class {
|
|
|
282
303
|
}
|
|
283
304
|
delete(x, b) {
|
|
284
305
|
b = typeof b === `string` ? b : x[this.b];
|
|
285
|
-
const a =
|
|
306
|
+
const a = (
|
|
307
|
+
// @ts-expect-error we deduce that this.a may index x
|
|
308
|
+
typeof x === `string` ? x : x[this.a]
|
|
309
|
+
);
|
|
286
310
|
if (a === void 0 && typeof b === `string`) {
|
|
287
311
|
const bRelations = this.getRelatedKeys(b);
|
|
288
312
|
if (bRelations) {
|
|
@@ -316,23 +340,26 @@ var Junction = class {
|
|
|
316
340
|
].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
|
|
317
341
|
);
|
|
318
342
|
}
|
|
343
|
+
let singleRelation;
|
|
319
344
|
for (const relation of relations) {
|
|
320
|
-
|
|
345
|
+
singleRelation = relation;
|
|
346
|
+
break;
|
|
321
347
|
}
|
|
348
|
+
return singleRelation;
|
|
322
349
|
}
|
|
323
350
|
}
|
|
324
|
-
replaceRelations(
|
|
351
|
+
replaceRelations(x, relations, config) {
|
|
325
352
|
const hasContent = !Array.isArray(relations);
|
|
326
|
-
const
|
|
353
|
+
const ys = hasContent ? Object.keys(relations) : relations;
|
|
327
354
|
if (config?.reckless) {
|
|
328
|
-
this.replaceRelationsUnsafely(
|
|
355
|
+
this.replaceRelationsUnsafely(x, ys);
|
|
329
356
|
} else {
|
|
330
|
-
this.replaceRelationsSafely(
|
|
357
|
+
this.replaceRelationsSafely(x, ys);
|
|
331
358
|
}
|
|
332
359
|
if (hasContent) {
|
|
333
|
-
for (const
|
|
334
|
-
const contentKey = this.makeContentKey(
|
|
335
|
-
const content = relations[
|
|
360
|
+
for (const y of ys) {
|
|
361
|
+
const contentKey = this.makeContentKey(x, y);
|
|
362
|
+
const content = relations[y];
|
|
336
363
|
this.setContent(contentKey, content);
|
|
337
364
|
}
|
|
338
365
|
}
|
|
@@ -349,7 +376,7 @@ var Junction = class {
|
|
|
349
376
|
const aRelations = this.getRelatedKeys(a);
|
|
350
377
|
if (aRelations) {
|
|
351
378
|
return [...aRelations].map((aRelation) => {
|
|
352
|
-
return [aRelation, this.getContent(a, aRelation)
|
|
379
|
+
return [aRelation, this.getContent(a, aRelation)];
|
|
353
380
|
});
|
|
354
381
|
}
|
|
355
382
|
}
|
|
@@ -357,7 +384,7 @@ var Junction = class {
|
|
|
357
384
|
const bRelations = this.getRelatedKeys(b);
|
|
358
385
|
if (bRelations) {
|
|
359
386
|
return [...bRelations].map((bRelation) => {
|
|
360
|
-
return [bRelation, this.getContent(bRelation, b)
|
|
387
|
+
return [bRelation, this.getContent(bRelation, b)];
|
|
361
388
|
});
|
|
362
389
|
}
|
|
363
390
|
}
|
|
@@ -1729,142 +1756,6 @@ function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
|
1729
1756
|
}
|
|
1730
1757
|
setIntoStore(store, token, value);
|
|
1731
1758
|
}
|
|
1732
|
-
function allocateIntoStore(store, provenance, key) {
|
|
1733
|
-
const stringKey = stringifyJson(key);
|
|
1734
|
-
try {
|
|
1735
|
-
const above = [];
|
|
1736
|
-
let allocationAttachmentStyle;
|
|
1737
|
-
if (provenance === `root`) {
|
|
1738
|
-
above.push(store.molecules.get(`"root"`));
|
|
1739
|
-
allocationAttachmentStyle = `all`;
|
|
1740
|
-
} else if (provenance[0][0] === T$) {
|
|
1741
|
-
allocationAttachmentStyle = `any`;
|
|
1742
|
-
const provenanceKey = stringifyJson(provenance);
|
|
1743
|
-
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
1744
|
-
if (!provenanceMolecule) {
|
|
1745
|
-
throw new Error(
|
|
1746
|
-
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
1747
|
-
);
|
|
1748
|
-
}
|
|
1749
|
-
above.push(provenanceMolecule);
|
|
1750
|
-
} else {
|
|
1751
|
-
const allocationIsCompound = key[0][0] === T$;
|
|
1752
|
-
if (allocationIsCompound) {
|
|
1753
|
-
allocationAttachmentStyle = `all`;
|
|
1754
|
-
for (const claim of provenance) {
|
|
1755
|
-
const provenanceKey = stringifyJson(claim);
|
|
1756
|
-
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
1757
|
-
if (!provenanceMolecule) {
|
|
1758
|
-
throw new Error(
|
|
1759
|
-
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
1760
|
-
);
|
|
1761
|
-
}
|
|
1762
|
-
above.push(provenanceMolecule);
|
|
1763
|
-
}
|
|
1764
|
-
} else {
|
|
1765
|
-
allocationAttachmentStyle = `any`;
|
|
1766
|
-
const provenanceKey = stringifyJson(provenance);
|
|
1767
|
-
const provenanceMolecule = store.molecules.get(provenanceKey);
|
|
1768
|
-
if (!provenanceMolecule) {
|
|
1769
|
-
throw new Error(
|
|
1770
|
-
`Molecule ${provenanceKey} not found in store "${store.config.name}"`
|
|
1771
|
-
);
|
|
1772
|
-
}
|
|
1773
|
-
above.push(provenanceMolecule);
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
const molecule = new Molecule$1(above, key);
|
|
1777
|
-
molecule._dependsOn = allocationAttachmentStyle;
|
|
1778
|
-
store.molecules.set(stringKey, molecule);
|
|
1779
|
-
for (const aboveMolecule of above) {
|
|
1780
|
-
aboveMolecule.below.set(molecule.stringKey, molecule);
|
|
1781
|
-
}
|
|
1782
|
-
const creationEvent = {
|
|
1783
|
-
type: `molecule_creation`,
|
|
1784
|
-
subType: `modern`,
|
|
1785
|
-
key: molecule.key,
|
|
1786
|
-
provenance
|
|
1787
|
-
};
|
|
1788
|
-
const target = newest$1(store);
|
|
1789
|
-
const isTransaction = isChildStore$1(target) && target.transactionMeta.phase === `building`;
|
|
1790
|
-
if (isTransaction) {
|
|
1791
|
-
target.transactionMeta.update.updates.push(creationEvent);
|
|
1792
|
-
} else {
|
|
1793
|
-
target.on.moleculeCreationStart.next(creationEvent);
|
|
1794
|
-
}
|
|
1795
|
-
} catch (thrown) {
|
|
1796
|
-
if (thrown instanceof Error) {
|
|
1797
|
-
store.logger.error(
|
|
1798
|
-
`\u274C`,
|
|
1799
|
-
`molecule`,
|
|
1800
|
-
stringKey,
|
|
1801
|
-
`allocation failed:`,
|
|
1802
|
-
thrown.message
|
|
1803
|
-
);
|
|
1804
|
-
}
|
|
1805
|
-
}
|
|
1806
|
-
return key;
|
|
1807
|
-
}
|
|
1808
|
-
function deallocateFromStore(store, claim) {
|
|
1809
|
-
const stringKey = stringifyJson(claim);
|
|
1810
|
-
const molecule = store.molecules.get(stringKey);
|
|
1811
|
-
if (!molecule) {
|
|
1812
|
-
throw new Error(
|
|
1813
|
-
`Molecule ${stringKey} not found in store "${store.config.name}"`
|
|
1814
|
-
);
|
|
1815
|
-
}
|
|
1816
|
-
for (const join of molecule.joins.values()) {
|
|
1817
|
-
join.relations.delete(molecule.key);
|
|
1818
|
-
join.molecules.delete(molecule.stringKey);
|
|
1819
|
-
}
|
|
1820
|
-
let provenance;
|
|
1821
|
-
if (molecule.above.size === 1) {
|
|
1822
|
-
const above = molecule.above.values().next().value;
|
|
1823
|
-
provenance = above.key;
|
|
1824
|
-
} else {
|
|
1825
|
-
provenance = [...molecule.above.values()].map(({ key }) => key);
|
|
1826
|
-
}
|
|
1827
|
-
const values = [];
|
|
1828
|
-
for (const stateToken of molecule.tokens.values()) {
|
|
1829
|
-
const tokenFamily = stateToken.family;
|
|
1830
|
-
values.push([tokenFamily.key, store.valueMap.get(stateToken.key)]);
|
|
1831
|
-
}
|
|
1832
|
-
for (const state of molecule.tokens.values()) {
|
|
1833
|
-
disposeFromStore$1(store, state);
|
|
1834
|
-
}
|
|
1835
|
-
for (const child of molecule.below.values()) {
|
|
1836
|
-
if (child.dependsOn === `all`) {
|
|
1837
|
-
deallocateFromStore(store, child.key);
|
|
1838
|
-
} else {
|
|
1839
|
-
child.above.delete(molecule.stringKey);
|
|
1840
|
-
if (child.above.size === 0) {
|
|
1841
|
-
deallocateFromStore(store, child.key);
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1845
|
-
molecule.below.clear();
|
|
1846
|
-
const disposalEvent = {
|
|
1847
|
-
type: `molecule_disposal`,
|
|
1848
|
-
subType: `modern`,
|
|
1849
|
-
key: molecule.key,
|
|
1850
|
-
values,
|
|
1851
|
-
provenance
|
|
1852
|
-
};
|
|
1853
|
-
const target = newest$1(store);
|
|
1854
|
-
const isTransaction = isChildStore$1(target) && target.transactionMeta.phase === `building`;
|
|
1855
|
-
if (isTransaction) {
|
|
1856
|
-
target.transactionMeta.update.updates.push(disposalEvent);
|
|
1857
|
-
} else {
|
|
1858
|
-
target.on.moleculeDisposal.next(disposalEvent);
|
|
1859
|
-
}
|
|
1860
|
-
target.molecules.delete(molecule.stringKey);
|
|
1861
|
-
for (const parent of molecule.above.values()) {
|
|
1862
|
-
parent.below.delete(molecule.stringKey);
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
var T$ = `T$`;
|
|
1866
|
-
|
|
1867
|
-
// internal/src/ingest-updates/ingest-creation-disposal.ts
|
|
1868
1759
|
function ingestCreationEvent(update, applying, store) {
|
|
1869
1760
|
switch (applying) {
|
|
1870
1761
|
case `newValue`: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Transceiver, Func, EnvironmentData, Flat, Subject, Store, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
1
|
+
import { Transceiver, Func, EnvironmentData, Flat, Subject, Store, Each, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
2
2
|
import { Json, JsonInterface, Canonical, stringified } from 'atom.io/json';
|
|
3
3
|
import { MoleculeConstructor as MoleculeConstructor$1, MoleculeToken as MoleculeToken$1, MoleculeFamilyToken as MoleculeFamilyToken$1, MoleculeParams as MoleculeParams$1, getState as getState$1, setState as setState$1, makeMolecule as makeMolecule$1, ActorToolkit as ActorToolkit$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MoleculeCreationClassic as MoleculeCreationClassic$1, MoleculeDisposalClassic as MoleculeDisposalClassic$1 } from 'atom.io';
|
|
4
4
|
import { findState } from 'atom.io/ephemeral';
|
|
@@ -196,9 +196,9 @@ type CtorToolkit<K extends Canonical> = Flat<Omit<ActorToolkit$1, `find`> & {
|
|
|
196
196
|
bond<T>(family: ReadonlySelectorFamilyToken$1<T, K>): ReadonlySelectorToken$1<T>;
|
|
197
197
|
bond<T>(family: WritableFamilyToken$1<T, K>): WritableToken$1<T>;
|
|
198
198
|
bond<T>(family: ReadableFamilyToken$1<T, K>): ReadableToken$1<T>;
|
|
199
|
-
bond<J extends JoinToken<any, any, any, any>>(joinToken: J, role: {
|
|
200
|
-
as: J extends JoinToken<infer A, infer B, any, any> ? A | B : never;
|
|
201
|
-
}): J extends JoinToken<any, any, any, infer Content> ? Content extends null ? {
|
|
199
|
+
bond<J extends JoinToken<any, any, any, any, any, any>>(joinToken: J, role: {
|
|
200
|
+
as: J extends JoinToken<infer A, string, infer B, string, any, any> ? A | B : never;
|
|
201
|
+
}): J extends JoinToken<any, any, any, any, any, infer Content> ? Content extends null ? {
|
|
202
202
|
relatedKeys: ReadonlySelectorToken$1<string[]>;
|
|
203
203
|
} : {
|
|
204
204
|
relatedKeys: ReadonlySelectorToken$1<string[]>;
|
|
@@ -243,6 +243,54 @@ type MoleculeType<T extends MoleculeFamilyToken<any>> = T extends MoleculeFamily
|
|
|
243
243
|
type MoleculeKey<M extends MoleculeConstructor> = InstanceType<M>[`key`];
|
|
244
244
|
declare function makeRootMoleculeInStore(key: string, store?: Store): MoleculeToken<ObjectConstructor>;
|
|
245
245
|
|
|
246
|
+
declare const $provenance: unique symbol;
|
|
247
|
+
type Claim<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>> = V & {
|
|
248
|
+
[$provenance]?: A;
|
|
249
|
+
};
|
|
250
|
+
declare function allocateIntoStore<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>>(store: Store, provenance: A, key: V): Claim<H, V, A>;
|
|
251
|
+
declare function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>>(store: Store, claim: Claim<H, V, A>): void;
|
|
252
|
+
declare function realm<H extends Hierarchy>(store: Store): {
|
|
253
|
+
root: MoleculeToken<ObjectConstructor>;
|
|
254
|
+
allocate: <V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V) => Claim<H, V, A>;
|
|
255
|
+
deallocate: <V extends Vassal<H>, A extends Above<V, H>>(claim: Claim<H, V, A>) => void;
|
|
256
|
+
};
|
|
257
|
+
declare const T$ = "T$";
|
|
258
|
+
type T$ = typeof T$;
|
|
259
|
+
type TypeTag<T extends string> = `${T$}--${T}`;
|
|
260
|
+
type SingularTypedKey<T extends string = string> = `${T}::${string}`;
|
|
261
|
+
type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
|
|
262
|
+
type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
|
|
263
|
+
type Scope = SingularTypedKey[];
|
|
264
|
+
type MutualFealty = {
|
|
265
|
+
above: Scope;
|
|
266
|
+
below: CompoundTypedKey;
|
|
267
|
+
style: `all` | `any`;
|
|
268
|
+
};
|
|
269
|
+
type ExclusiveFealty = {
|
|
270
|
+
above: TypedKey | `root`;
|
|
271
|
+
below: Scope;
|
|
272
|
+
};
|
|
273
|
+
type Fealty = ExclusiveFealty | MutualFealty;
|
|
274
|
+
type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
|
|
275
|
+
type Vassal<H extends Hierarchy> = {
|
|
276
|
+
[K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
|
|
277
|
+
below: Array<infer V>;
|
|
278
|
+
} ? V extends TypedKey ? V : never : never;
|
|
279
|
+
}[keyof H];
|
|
280
|
+
type Above<TK extends TypedKey, H extends Hierarchy> = {
|
|
281
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
|
|
282
|
+
below: Array<infer V>;
|
|
283
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
|
|
284
|
+
}[keyof H];
|
|
285
|
+
type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
286
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
|
|
287
|
+
above: infer V;
|
|
288
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never;
|
|
289
|
+
}[keyof H];
|
|
290
|
+
type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
291
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never;
|
|
292
|
+
}[keyof H];
|
|
293
|
+
|
|
246
294
|
declare function disposeState(token: MoleculeToken<any> | ReadableToken<any>): void;
|
|
247
295
|
declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
|
|
248
296
|
declare function disposeState<M extends MoleculeConstructor>(token: MoleculeFamilyToken<M>, key: MoleculeKey<M>): void;
|
|
@@ -444,4 +492,4 @@ type FamilyMetadata<K extends Canonical = any> = {
|
|
|
444
492
|
subKey: stringified<K>;
|
|
445
493
|
};
|
|
446
494
|
|
|
447
|
-
export { type ActorToolkit, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type CtorToolkit, type Effectors, type FamilyMetadata, type GetterToolkit, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeConstructor, type MoleculeCreation, type MoleculeCreationClassic, type MoleculeCreationModern, type MoleculeDisposal, type MoleculeDisposalClassic, type MoleculeDisposalModern, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeType, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamilyToken, type SelectorToken, type SetterToolkit, Silo, type StateCreation, type StateDisposal, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type UpdateHandler, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMoleculeInStore, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
495
|
+
export { $provenance, type Above, type ActorToolkit, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Below, type Claim, type CompoundTypedKey, type CtorToolkit, type Effectors, type FamilyMetadata, type GetterToolkit, type Hierarchy, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeConstructor, type MoleculeCreation, type MoleculeCreationClassic, type MoleculeCreationModern, type MoleculeDisposal, type MoleculeDisposalClassic, type MoleculeDisposalModern, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeType, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Mutuals, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamilyToken, type SelectorToken, type SetterToolkit, Silo, type SingularTypedKey, type StateCreation, type StateDisposal, type StateUpdate, T$, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type TypeTag, type TypedKey, type UpdateHandler, type Vassal, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, allocateIntoStore, atom, atomFamily, belongsTo, deallocateFromStore, disposeState, getState, isToken, makeMolecule, makeRootMoleculeInStore, moleculeFamily, realm, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { makeMolecule, makeRootMoleculeInStore, moleculeFamily } from './chunk-
|
|
1
|
+
export { $provenance, T$, allocateIntoStore, deallocateFromStore, makeMolecule, makeRootMoleculeInStore, moleculeFamily, realm } from './chunk-ADMEAXYU.js';
|
|
2
2
|
import './chunk-XWL6SNVU.js';
|
|
3
3
|
import * as Internal from 'atom.io/internal';
|
|
4
4
|
import { createStandaloneAtom, IMPLICIT, createAtomFamily, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, subscribeInStore, timeTravel, createMoleculeFamily, makeMoleculeInStore, actUponStore, arbitrary } from 'atom.io/internal';
|