atom.io 0.25.5 → 0.26.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.
Files changed (54) hide show
  1. package/data/dist/index.js +33 -25
  2. package/data/package.json +1 -4
  3. package/data/src/join.ts +0 -1
  4. package/dist/{chunk-HYXKCFVY.js → chunk-IBTHB2PI.js} +59 -60
  5. package/dist/{chunk-MR5NETHW.js → chunk-IW6WYRS7.js} +4 -5
  6. package/dist/chunk-XWL6SNVU.js +7 -0
  7. package/dist/index.js +33 -21
  8. package/ephemeral/dist/index.js +1 -1
  9. package/ephemeral/package.json +1 -4
  10. package/eslint-plugin/dist/index.d.ts +1 -1
  11. package/eslint-plugin/dist/index.js +7 -8
  12. package/eslint-plugin/package.json +1 -4
  13. package/immortal/dist/index.js +1 -1
  14. package/immortal/package.json +1 -4
  15. package/internal/dist/index.js +173 -160
  16. package/internal/package.json +1 -4
  17. package/introspection/dist/index.js +32 -30
  18. package/introspection/package.json +1 -4
  19. package/json/dist/index.js +1 -1
  20. package/json/package.json +1 -4
  21. package/package.json +27 -58
  22. package/react/dist/index.js +2 -2
  23. package/react/package.json +1 -4
  24. package/react-devtools/dist/index.js +75 -68
  25. package/react-devtools/package.json +1 -4
  26. package/realtime/dist/index.js +8 -9
  27. package/realtime/package.json +1 -4
  28. package/realtime-client/dist/index.js +6 -6
  29. package/realtime-client/package.json +1 -4
  30. package/realtime-react/dist/index.js +9 -11
  31. package/realtime-react/package.json +1 -4
  32. package/realtime-server/dist/index.js +59 -54
  33. package/realtime-server/package.json +1 -4
  34. package/realtime-testing/dist/index.js +3 -3
  35. package/realtime-testing/package.json +1 -4
  36. package/transceivers/set-rtx/dist/index.js +11 -11
  37. package/transceivers/set-rtx/package.json +1 -4
  38. package/data/dist/index.cjs +0 -953
  39. package/dist/chunk-S4N6XNPH.js +0 -38
  40. package/dist/index.cjs +0 -215
  41. package/ephemeral/dist/index.cjs +0 -11
  42. package/eslint-plugin/dist/index.cjs +0 -388
  43. package/immortal/dist/index.cjs +0 -14
  44. package/internal/dist/index.cjs +0 -3405
  45. package/introspection/dist/index.cjs +0 -449
  46. package/json/dist/index.cjs +0 -128
  47. package/react/dist/index.cjs +0 -118
  48. package/react-devtools/dist/index.cjs +0 -2191
  49. package/realtime/dist/index.cjs +0 -120
  50. package/realtime-client/dist/index.cjs +0 -569
  51. package/realtime-react/dist/index.cjs +0 -189
  52. package/realtime-server/dist/index.cjs +0 -965
  53. package/realtime-testing/dist/index.cjs +0 -201
  54. package/transceivers/set-rtx/dist/index.cjs +0 -215
@@ -1,953 +0,0 @@
1
- 'use strict';
2
-
3
- var internal = require('atom.io/internal');
4
- var json = require('atom.io/json');
5
- var setRtx = require('atom.io/transceivers/set-rtx');
6
-
7
- // data/src/dict.ts
8
- function dict(findState, index, store = internal.IMPLICIT.STORE) {
9
- return internal.createStandaloneSelector(
10
- {
11
- key: `${findState.key}Dict`,
12
- get: ({ get }) => {
13
- const keys = get(index);
14
- return keys.reduce((acc, key) => {
15
- acc[key] = get(internal.findInStore(findState, key, store));
16
- return acc;
17
- }, {});
18
- }
19
- },
20
- store
21
- );
22
- }
23
-
24
- // ../rel8/junction/src/junction.ts
25
- var Junction = class {
26
- constructor(data, config) {
27
- this.relations = /* @__PURE__ */ new Map();
28
- this.contents = /* @__PURE__ */ new Map();
29
- this.makeContentKey = (a, b) => `${a}:${b}`;
30
- var _a, _b, _c, _d;
31
- this.a = data.between[0];
32
- this.b = data.between[1];
33
- this.cardinality = data.cardinality;
34
- if (!(config == null ? void 0 : config.externalStore)) {
35
- this.relations = new Map((_a = data.relations) == null ? void 0 : _a.map(([a, b]) => [a, new Set(b)]));
36
- this.contents = new Map(data.contents);
37
- }
38
- this.isContent = (_b = config == null ? void 0 : config.isContent) != null ? _b : null;
39
- if (config == null ? void 0 : config.makeContentKey) {
40
- this.makeContentKey = config.makeContentKey;
41
- }
42
- if (config == null ? void 0 : config.externalStore) {
43
- const externalStore = config.externalStore;
44
- this.has = (a, b) => externalStore.has(a, b);
45
- this.addRelation = (a, b) => {
46
- externalStore.addRelation(a, b);
47
- };
48
- this.deleteRelation = (a, b) => {
49
- externalStore.deleteRelation(a, b);
50
- };
51
- this.replaceRelationsSafely = (a, bs) => {
52
- externalStore.replaceRelationsSafely(a, bs);
53
- };
54
- this.replaceRelationsUnsafely = (a, bs) => {
55
- externalStore.replaceRelationsUnsafely(a, bs);
56
- };
57
- this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
58
- if (externalStore.getContent) {
59
- this.getContentInternal = (contentKey) => {
60
- return externalStore.getContent(contentKey);
61
- };
62
- this.setContent = (contentKey, content) => {
63
- externalStore.setContent(contentKey, content);
64
- };
65
- this.deleteContent = (contentKey) => {
66
- externalStore.deleteContent(contentKey);
67
- };
68
- }
69
- for (const [x, ys] of (_c = data.relations) != null ? _c : []) {
70
- for (const y of ys) this.addRelation(x, y);
71
- }
72
- for (const [contentKey, content] of (_d = data.contents) != null ? _d : []) {
73
- this.setContent(contentKey, content);
74
- }
75
- }
76
- }
77
- getRelatedKeys(key) {
78
- return this.relations.get(key);
79
- }
80
- addRelation(a, b) {
81
- let aRelations = this.relations.get(a);
82
- let bRelations = this.relations.get(b);
83
- if (aRelations) {
84
- aRelations.add(b);
85
- } else {
86
- aRelations = /* @__PURE__ */ new Set([b]);
87
- this.relations.set(a, aRelations);
88
- }
89
- if (bRelations) {
90
- bRelations.add(a);
91
- } else {
92
- bRelations = /* @__PURE__ */ new Set([a]);
93
- this.relations.set(b, bRelations);
94
- }
95
- }
96
- deleteRelation(a, b) {
97
- const aRelations = this.relations.get(a);
98
- if (aRelations) {
99
- aRelations.delete(b);
100
- if (aRelations.size === 0) {
101
- this.relations.delete(a);
102
- }
103
- const bRelations = this.relations.get(b);
104
- if (bRelations) {
105
- bRelations.delete(a);
106
- if (bRelations.size === 0) {
107
- this.relations.delete(b);
108
- }
109
- }
110
- }
111
- }
112
- replaceRelationsUnsafely(a, bs) {
113
- this.relations.set(a, new Set(bs));
114
- for (const b of bs) {
115
- const bRelations = /* @__PURE__ */ new Set([a]);
116
- this.relations.set(b, bRelations);
117
- }
118
- }
119
- replaceRelationsSafely(a, bs) {
120
- const aRelationsPrev = this.relations.get(a);
121
- if (aRelationsPrev) {
122
- for (const b of aRelationsPrev) {
123
- const bRelations = this.relations.get(b);
124
- if (bRelations) {
125
- if (bRelations.size === 1) {
126
- this.relations.delete(b);
127
- } else {
128
- bRelations.delete(a);
129
- }
130
- this.contents.delete(this.makeContentKey(a, b));
131
- }
132
- }
133
- }
134
- this.relations.set(a, new Set(bs));
135
- for (const b of bs) {
136
- let bRelations = this.relations.get(b);
137
- if (bRelations) {
138
- bRelations.add(a);
139
- } else {
140
- bRelations = /* @__PURE__ */ new Set([a]);
141
- this.relations.set(b, bRelations);
142
- }
143
- }
144
- }
145
- getContentInternal(contentKey) {
146
- return this.contents.get(contentKey);
147
- }
148
- setContent(contentKey, content) {
149
- this.contents.set(contentKey, content);
150
- }
151
- deleteContent(contentKey) {
152
- this.contents.delete(contentKey);
153
- }
154
- toJSON() {
155
- return {
156
- between: [this.a, this.b],
157
- cardinality: this.cardinality,
158
- relations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),
159
- contents: [...this.contents.entries()]
160
- };
161
- }
162
- set(a, ...rest) {
163
- var _a;
164
- const b = typeof rest[0] === `string` ? rest[0] : a[this.b];
165
- const content = ((_a = rest[1]) != null ? _a : typeof rest[0] === `string`) ? void 0 : rest[0];
166
- a = typeof a === `string` ? a : a[this.a];
167
- switch (this.cardinality) {
168
- case `1:1`: {
169
- const bPrev = this.getRelatedKey(a);
170
- if (bPrev && bPrev !== b) this.delete(bPrev, a);
171
- }
172
- case `1:n`: {
173
- const aPrev = this.getRelatedKey(b);
174
- if (aPrev && aPrev !== a) this.delete(aPrev, b);
175
- }
176
- }
177
- if (content) {
178
- const contentKey = this.makeContentKey(a, b);
179
- this.setContent(contentKey, content);
180
- }
181
- this.addRelation(a, b);
182
- return this;
183
- }
184
- delete(x, b) {
185
- b = typeof b === `string` ? b : x[this.b];
186
- const a = typeof x === `string` ? x : x[this.a];
187
- if (a === void 0 && typeof b === `string`) {
188
- const bRelations = this.getRelatedKeys(b);
189
- if (bRelations) {
190
- for (const bRelation of bRelations) {
191
- this.delete(bRelation, b);
192
- }
193
- }
194
- }
195
- if (typeof a === `string` && b === void 0) {
196
- const aRelations = this.getRelatedKeys(a);
197
- if (aRelations) {
198
- for (const aRelation of aRelations) {
199
- this.delete(a, aRelation);
200
- }
201
- }
202
- }
203
- if (typeof a === `string` && typeof b === `string`) {
204
- this.deleteRelation(a, b);
205
- const contentKey = this.makeContentKey(a, b);
206
- this.deleteContent(contentKey);
207
- }
208
- return this;
209
- }
210
- getRelatedKey(key) {
211
- const relations = this.getRelatedKeys(key);
212
- if (relations) {
213
- if (relations.size > 1) {
214
- console.warn(
215
- `${relations.size} related keys were found for key "${key}": (${[
216
- ...relations
217
- ].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
218
- );
219
- }
220
- for (const relation of relations) {
221
- return relation;
222
- }
223
- }
224
- }
225
- replaceRelations(a, relations, config) {
226
- const hasContent = !Array.isArray(relations);
227
- const bs = hasContent ? Object.keys(relations) : relations;
228
- if (config == null ? void 0 : config.reckless) {
229
- this.replaceRelationsUnsafely(a, bs);
230
- } else {
231
- this.replaceRelationsSafely(a, bs);
232
- }
233
- if (hasContent) {
234
- for (const b of bs) {
235
- const contentKey = this.makeContentKey(a, b);
236
- const content = relations[b];
237
- this.setContent(contentKey, content);
238
- }
239
- }
240
- return this;
241
- }
242
- getContent(a, b) {
243
- const contentKey = this.makeContentKey(a, b);
244
- return this.getContentInternal(contentKey);
245
- }
246
- getRelationEntries(input) {
247
- const a = input[this.a];
248
- const b = input[this.b];
249
- if (a !== void 0 && b === void 0) {
250
- const aRelations = this.getRelatedKeys(a);
251
- if (aRelations) {
252
- return [...aRelations].map((aRelation) => {
253
- var _a;
254
- return [aRelation, (_a = this.getContent(a, aRelation)) != null ? _a : null];
255
- });
256
- }
257
- }
258
- if (a === void 0 && b !== void 0) {
259
- const bRelations = this.getRelatedKeys(b);
260
- if (bRelations) {
261
- return [...bRelations].map((bRelation) => {
262
- var _a;
263
- return [bRelation, (_a = this.getContent(bRelation, b)) != null ? _a : null];
264
- });
265
- }
266
- }
267
- return [];
268
- }
269
- has(a, b) {
270
- var _a;
271
- if (b) {
272
- const setA = this.getRelatedKeys(a);
273
- return (_a = setA == null ? void 0 : setA.has(b)) != null ? _a : false;
274
- }
275
- return this.relations.has(a);
276
- }
277
- };
278
-
279
- // data/src/join.ts
280
- function capitalize(string) {
281
- return string[0].toUpperCase() + string.slice(1);
282
- }
283
- var Join = class _Join {
284
- constructor(options, defaultContent, store = internal.IMPLICIT.STORE) {
285
- this.molecules = /* @__PURE__ */ new Map();
286
- this.store = store;
287
- this.options = options;
288
- this.defaultContent = defaultContent;
289
- this.alternates = /* @__PURE__ */ new Map();
290
- this.alternates.set(store.config.name, this);
291
- this.store.miscResources.set(`join:${options.key}`, this);
292
- this.toolkit = {
293
- get: (...ps) => internal.getFromStore(...ps, store),
294
- set: (...ps) => {
295
- internal.setIntoStore(...ps, store);
296
- },
297
- find: (token, key) => internal.findInStore(token, key, store),
298
- seek: (token, key) => internal.seekInStore(token, key, store),
299
- json: (token) => internal.getJsonToken(token, store),
300
- dispose: (...ps) => {
301
- internal.disposeFromStore(...ps, store);
302
- }
303
- };
304
- this.retrieve = (token, key) => {
305
- const maybeToken = this.toolkit.seek(token, key);
306
- if (maybeToken) {
307
- return maybeToken;
308
- }
309
- const molecule = this.molecules.get(json.stringifyJson(key));
310
- if (molecule) {
311
- const family = internal.withdraw(token, store);
312
- return internal.growMoleculeInStore(molecule, family, store);
313
- }
314
- if (store.config.lifespan === `immortal`) {
315
- throw new internal.NotFoundError(token, key, store);
316
- }
317
- return internal.initFamilyMemberInStore(token, key, store);
318
- };
319
- const aSide = options.between[0];
320
- const bSide = options.between[1];
321
- const relatedKeysAtoms = internal.createMutableAtomFamily(
322
- {
323
- key: `${options.key}/relatedKeys`,
324
- default: () => new setRtx.SetRTX(),
325
- mutable: true,
326
- fromJson: (json) => setRtx.SetRTX.fromJSON(json),
327
- toJson: (set) => set.toJSON()
328
- },
329
- store
330
- );
331
- this.core = { findRelatedKeysState: relatedKeysAtoms };
332
- const getRelatedKeys = ({ get }, key) => get(this.retrieve(relatedKeysAtoms, key));
333
- const addRelation = (toolkit, a, b) => {
334
- const { set } = toolkit;
335
- const aKeysState = this.retrieve(relatedKeysAtoms, a);
336
- const bKeysState = this.retrieve(relatedKeysAtoms, b);
337
- set(aKeysState, (aKeys) => aKeys.add(b));
338
- set(bKeysState, (bKeys) => bKeys.add(a));
339
- };
340
- const deleteRelation = (toolkit, a, b) => {
341
- const { set } = toolkit;
342
- const aKeysState = this.retrieve(relatedKeysAtoms, a);
343
- const bKeysState = this.retrieve(relatedKeysAtoms, b);
344
- set(aKeysState, (aKeys) => {
345
- aKeys.delete(b);
346
- if (aKeys.size === 0) ;
347
- return aKeys;
348
- });
349
- set(bKeysState, (bKeys) => {
350
- bKeys.delete(a);
351
- if (bKeys.size === 0) ;
352
- return bKeys;
353
- });
354
- };
355
- const replaceRelationsSafely = (toolkit, a, newRelationsOfA) => {
356
- const { get, set } = toolkit;
357
- const relationsOfAState = this.retrieve(relatedKeysAtoms, a);
358
- const currentRelationsOfA = get(relationsOfAState);
359
- for (const currentRelationB of currentRelationsOfA) {
360
- const remainsRelated = newRelationsOfA.includes(currentRelationB);
361
- if (remainsRelated) {
362
- continue;
363
- }
364
- const relationsOfBState = this.retrieve(
365
- relatedKeysAtoms,
366
- currentRelationB
367
- );
368
- set(relationsOfBState, (relationsOfB) => {
369
- relationsOfB.delete(a);
370
- return relationsOfB;
371
- });
372
- }
373
- set(relationsOfAState, (relationsOfA) => {
374
- relationsOfA.transaction((nextRelationsOfA) => {
375
- nextRelationsOfA.clear();
376
- for (const newRelationB of newRelationsOfA) {
377
- const relationsOfB = getRelatedKeys(toolkit, newRelationB);
378
- const newRelationBIsAlreadyRelated = relationsOfB.has(a);
379
- if (this.relations.cardinality === `1:n`) {
380
- const previousOwnersToDispose = [];
381
- for (const previousOwner of relationsOfB) {
382
- if (previousOwner === a) {
383
- continue;
384
- }
385
- const previousOwnerRelations = getRelatedKeys(
386
- toolkit,
387
- previousOwner
388
- );
389
- previousOwnerRelations.delete(newRelationB);
390
- if (previousOwnerRelations.size === 0) {
391
- previousOwnersToDispose.push(previousOwner);
392
- }
393
- }
394
- if (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {
395
- relationsOfB.clear();
396
- }
397
- for (const previousOwner of previousOwnersToDispose) {
398
- const sorted = [newRelationB, previousOwner].sort();
399
- const compositeKey = `"${sorted[0]}:${sorted[1]}"`;
400
- this.molecules.delete(compositeKey);
401
- }
402
- }
403
- if (!newRelationBIsAlreadyRelated) {
404
- relationsOfB.add(a);
405
- }
406
- nextRelationsOfA.add(newRelationB);
407
- }
408
- return true;
409
- });
410
- return relationsOfA;
411
- });
412
- };
413
- const replaceRelationsUnsafely = (toolkit, a, newRelationsOfA) => {
414
- const { set } = toolkit;
415
- const relationsOfAState = this.retrieve(relatedKeysAtoms, a);
416
- set(relationsOfAState, (relationsOfA) => {
417
- relationsOfA.transaction((nextRelationsOfA) => {
418
- for (const newRelationB of newRelationsOfA) {
419
- nextRelationsOfA.add(newRelationB);
420
- }
421
- return true;
422
- });
423
- return relationsOfA;
424
- });
425
- for (const newRelationB of newRelationsOfA) {
426
- const newRelationsBState = this.retrieve(relatedKeysAtoms, newRelationB);
427
- set(newRelationsBState, (newRelationsB) => {
428
- newRelationsB.add(a);
429
- return newRelationsB;
430
- });
431
- }
432
- return true;
433
- };
434
- const has = (toolkit, a, b) => {
435
- const aKeys = getRelatedKeys(toolkit, a);
436
- return b ? aKeys.has(b) : aKeys.size > 0;
437
- };
438
- const baseExternalStoreConfiguration = {
439
- getRelatedKeys: (key) => getRelatedKeys(this.toolkit, key),
440
- addRelation: (a, b) => {
441
- addRelation(this.toolkit, a, b);
442
- },
443
- deleteRelation: (a, b) => {
444
- deleteRelation(this.toolkit, a, b);
445
- },
446
- replaceRelationsSafely: (a, bs) => {
447
- replaceRelationsSafely(this.toolkit, a, bs);
448
- },
449
- replaceRelationsUnsafely: (a, bs) => {
450
- replaceRelationsUnsafely(this.toolkit, a, bs);
451
- },
452
- has: (a, b) => has(this.toolkit, a, b)
453
- };
454
- let externalStore;
455
- let contentAtoms;
456
- let contentMolecules;
457
- if (defaultContent) {
458
- contentAtoms = internal.createRegularAtomFamily(
459
- {
460
- key: `${options.key}/content`,
461
- default: defaultContent
462
- },
463
- store
464
- );
465
- const joinToken = {
466
- key: options.key,
467
- type: `join`,
468
- a: options.between[0],
469
- b: options.between[1],
470
- cardinality: options.cardinality
471
- };
472
- contentMolecules = internal.createMoleculeFamily(
473
- {
474
- key: `${options.key}/content-molecules`,
475
- new: class ContentMolecule {
476
- constructor(toolkit, key) {
477
- this.key = key;
478
- toolkit.bond(joinToken, { as: null });
479
- }
480
- }
481
- },
482
- store
483
- );
484
- const getContent = ({ get }, key) => get(this.retrieve(contentAtoms, key));
485
- const setContent = ({ set }, key, content) => {
486
- set(this.retrieve(contentAtoms, key), content);
487
- };
488
- const deleteContent = (_, compositeKey) => {
489
- const contentMolecule = store.molecules.get(`"${compositeKey}"`);
490
- if (contentMolecule) {
491
- this.toolkit.dispose(contentMolecule);
492
- this.molecules.delete(`"${compositeKey}"`);
493
- }
494
- };
495
- const externalStoreWithContentConfiguration = {
496
- getContent: (contentKey) => {
497
- const content = getContent(this.toolkit, contentKey);
498
- return content;
499
- },
500
- setContent: (contentKey, content) => {
501
- setContent(this.toolkit, contentKey, content);
502
- },
503
- deleteContent: (contentKey) => {
504
- deleteContent(this.toolkit, contentKey);
505
- }
506
- };
507
- externalStore = Object.assign(
508
- baseExternalStoreConfiguration,
509
- externalStoreWithContentConfiguration
510
- );
511
- } else {
512
- externalStore = baseExternalStoreConfiguration;
513
- }
514
- const relations = new Junction(options, {
515
- externalStore,
516
- makeContentKey: (...args) => {
517
- const sorted = args.sort();
518
- const compositeKey = `${sorted[0]}:${sorted[1]}`;
519
- const [m0, m1] = sorted.map(
520
- (key) => this.molecules.get(json.stringifyJson(key))
521
- );
522
- if (store.config.lifespan === `immortal` && m0 && m1) {
523
- const target = internal.newest(store);
524
- const moleculeToken = internal.makeMoleculeInStore(
525
- target,
526
- [m0, m1],
527
- contentMolecules,
528
- compositeKey
529
- );
530
- this.molecules.set(
531
- `"${compositeKey}"`,
532
- internal.withdraw(moleculeToken, target)
533
- );
534
- }
535
- return compositeKey;
536
- }
537
- });
538
- const createSingleKeyStateFamily = () => internal.createSelectorFamily(
539
- {
540
- key: `${options.key}/singleRelatedKey`,
541
- get: (key) => ({ get }) => {
542
- const relatedKeysState = this.retrieve(relatedKeysAtoms, key);
543
- const relatedKeys = get(relatedKeysState);
544
- for (const relatedKey of relatedKeys) {
545
- return relatedKey;
546
- }
547
- return null;
548
- }
549
- },
550
- store
551
- );
552
- const getMultipleKeyStateFamily = () => {
553
- return internal.createSelectorFamily(
554
- {
555
- key: `${options.key}/multipleRelatedKeys`,
556
- get: (key) => ({ get }) => {
557
- const jsonFamily = internal.getJsonFamily(relatedKeysAtoms, store);
558
- const jsonState = this.retrieve(jsonFamily, key);
559
- const json = get(jsonState);
560
- return json.members;
561
- }
562
- },
563
- store
564
- );
565
- };
566
- const createSingleEntryStateFamily = () => internal.createSelectorFamily(
567
- {
568
- key: `${options.key}/singleRelatedEntry`,
569
- get: (key) => ({ get }) => {
570
- const relatedKeysState = this.retrieve(relatedKeysAtoms, key);
571
- const relatedKeys = get(relatedKeysState);
572
- for (const relatedKey of relatedKeys) {
573
- const contentKey = relations.makeContentKey(key, relatedKey);
574
- const contentState = this.retrieve(contentAtoms, contentKey);
575
- const content = get(contentState);
576
- return [relatedKey, content];
577
- }
578
- return null;
579
- }
580
- },
581
- store
582
- );
583
- const getMultipleEntryStateFamily = () => internal.createSelectorFamily(
584
- {
585
- key: `${options.key}/multipleRelatedEntries`,
586
- get: (key) => ({ get }) => {
587
- const jsonFamily = internal.getJsonFamily(relatedKeysAtoms, store);
588
- const jsonState = this.retrieve(jsonFamily, key);
589
- const json = get(jsonState);
590
- return json.members.map((relatedKey) => {
591
- const contentKey = relations.makeContentKey(key, relatedKey);
592
- const contentState = this.retrieve(contentAtoms, contentKey);
593
- const content = get(contentState);
594
- return [relatedKey, content];
595
- });
596
- }
597
- },
598
- store
599
- );
600
- switch (options.cardinality) {
601
- case `1:1`: {
602
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
603
- const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
604
- const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}`;
605
- const baseStates = {
606
- [stateKeyA]: findSingleRelatedKeyState,
607
- [stateKeyB]: findSingleRelatedKeyState
608
- };
609
- let states;
610
- if (defaultContent) {
611
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
612
- const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
613
- const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}`;
614
- const contentStates = {
615
- [entriesStateKeyA]: findSingleRelatedEntryState,
616
- [entriesStateKeyB]: findSingleRelatedEntryState
617
- };
618
- states = Object.assign(baseStates, contentStates);
619
- } else {
620
- states = baseStates;
621
- }
622
- this.relations = relations;
623
- this.states = states;
624
- break;
625
- }
626
- case `1:n`: {
627
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
628
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
629
- const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
630
- const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
631
- const baseStates = {
632
- [stateKeyA]: findSingleRelatedKeyState,
633
- [stateKeyB]: findMultipleRelatedKeysState
634
- };
635
- let states;
636
- if (defaultContent) {
637
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
638
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
639
- const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
640
- const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
641
- aSide
642
- )}`;
643
- const contentStates = {
644
- [entriesStateKeyA]: findSingleRelatedEntryState,
645
- [entriesStateKeyB]: findMultipleRelatedEntriesState
646
- };
647
- states = Object.assign(baseStates, contentStates);
648
- } else {
649
- states = baseStates;
650
- }
651
- this.relations = relations;
652
- this.states = states;
653
- break;
654
- }
655
- default: {
656
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
657
- const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}`;
658
- const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
659
- const baseStates = {
660
- [stateKeyA]: findMultipleRelatedKeysState,
661
- [stateKeyB]: findMultipleRelatedKeysState
662
- };
663
- let states;
664
- if (defaultContent) {
665
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
666
- const entriesStateKeyA = `${aSide}EntriesOf${capitalize(
667
- bSide
668
- )}`;
669
- const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
670
- aSide
671
- )}`;
672
- const contentStates = {
673
- [entriesStateKeyA]: findMultipleRelatedEntriesState,
674
- [entriesStateKeyB]: findMultipleRelatedEntriesState
675
- };
676
- states = Object.assign(baseStates, contentStates);
677
- } else {
678
- states = baseStates;
679
- }
680
- this.relations = relations;
681
- this.states = states;
682
- }
683
- }
684
- }
685
- transact(toolkit, run) {
686
- const originalToolkit = this.toolkit;
687
- this.toolkit = toolkit;
688
- run(this);
689
- this.toolkit = originalToolkit;
690
- }
691
- [Symbol.dispose]() {
692
- this.alternates.delete(this.store.config.name);
693
- }
694
- in(store) {
695
- const key = store.config.name;
696
- const alternate = this.alternates.get(key);
697
- if (alternate) {
698
- return alternate;
699
- }
700
- const join2 = new _Join(this.options, this.defaultContent, store);
701
- this.alternates.set(key, join2);
702
- join2.alternates = this.alternates;
703
- return join2;
704
- }
705
- };
706
- function join(options, defaultContent, store = internal.IMPLICIT.STORE) {
707
- const joins = getJoinMap(store);
708
- joins.set(options.key, new Join(options, defaultContent, store));
709
- const token = {
710
- key: options.key,
711
- type: `join`,
712
- a: options.between[0],
713
- b: options.between[1],
714
- cardinality: options.cardinality
715
- };
716
- return token;
717
- }
718
- function getJoinMap(store) {
719
- if (`joins` in store && store.joins instanceof Map) {
720
- return store.joins;
721
- }
722
- const joins = /* @__PURE__ */ new Map();
723
- store.joins = joins;
724
- return joins;
725
- }
726
- function getJoin(token, store) {
727
- var _a;
728
- const joinMap = getJoinMap(store);
729
- let myJoin = joinMap.get(token.key);
730
- if (myJoin === void 0) {
731
- const rootJoinMap = getJoinMap(internal.IMPLICIT.STORE);
732
- myJoin = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
733
- if (myJoin === void 0) {
734
- throw new Error(
735
- `Join "${token.key}" not found in store "${store.config.name}"`
736
- );
737
- }
738
- joinMap.set(token.key, myJoin);
739
- }
740
- return myJoin;
741
- }
742
- function findRelationsInStore(token, key, store) {
743
- const myJoin = getJoin(token, store);
744
- let relations;
745
- switch (token.cardinality) {
746
- case `1:1`: {
747
- const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
748
- const keyBA = `${token.b}KeyOf${capitalize(token.a)}`;
749
- relations = {
750
- get [keyAB]() {
751
- const familyAB = myJoin.states[keyAB];
752
- const state = myJoin.retrieve(familyAB, key);
753
- return state;
754
- },
755
- get [keyBA]() {
756
- const familyBA = myJoin.states[keyBA];
757
- const state = myJoin.retrieve(familyBA, key);
758
- return state;
759
- }
760
- };
761
- const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
762
- if (entryAB in myJoin.states) {
763
- const entryBA = `${token.b}EntryOf${capitalize(token.a)}`;
764
- Object.assign(relations, {
765
- get [entryAB]() {
766
- const familyAB = myJoin.states[entryAB];
767
- const state = myJoin.retrieve(familyAB, key);
768
- return state;
769
- },
770
- get [entryBA]() {
771
- const familyBA = myJoin.states[entryBA];
772
- const state = myJoin.retrieve(familyBA, key);
773
- return state;
774
- }
775
- });
776
- }
777
- break;
778
- }
779
- case `1:n`: {
780
- const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
781
- const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
782
- relations = {
783
- get [keyAB]() {
784
- const familyAB = myJoin.states[keyAB];
785
- const state = myJoin.retrieve(familyAB, key);
786
- return state;
787
- },
788
- get [keysBA]() {
789
- const familyBA = myJoin.states[keysBA];
790
- const state = myJoin.retrieve(familyBA, key);
791
- return state;
792
- }
793
- };
794
- const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
795
- if (entryAB in myJoin.states) {
796
- const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
797
- Object.assign(relations, {
798
- get [entryAB]() {
799
- const familyAB = myJoin.states[entryAB];
800
- const state = myJoin.retrieve(familyAB, key);
801
- return state;
802
- },
803
- get [entriesBA]() {
804
- const familyBA = myJoin.states[entriesBA];
805
- const state = myJoin.retrieve(familyBA, key);
806
- return state;
807
- }
808
- });
809
- }
810
- break;
811
- }
812
- case `n:n`: {
813
- const keysAB = `${token.a}KeysOf${capitalize(token.b)}`;
814
- const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
815
- relations = {
816
- get [keysAB]() {
817
- const familyAB = myJoin.states[keysAB];
818
- const state = myJoin.retrieve(familyAB, key);
819
- return state;
820
- },
821
- get [keysBA]() {
822
- const familyBA = myJoin.states[keysBA];
823
- const state = myJoin.retrieve(familyBA, key);
824
- return state;
825
- }
826
- };
827
- const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`;
828
- if (entriesAB in myJoin.states) {
829
- const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
830
- Object.assign(relations, {
831
- get [entriesAB]() {
832
- const familyAB = myJoin.states[entriesAB];
833
- const state = myJoin.retrieve(familyAB, key);
834
- return state;
835
- },
836
- get [entriesBA]() {
837
- const familyBA = myJoin.states[entriesBA];
838
- const state = myJoin.retrieve(familyBA, key);
839
- return state;
840
- }
841
- });
842
- }
843
- }
844
- }
845
- return relations;
846
- }
847
- function findRelations(token, key) {
848
- return findRelationsInStore(token, key, internal.IMPLICIT.STORE);
849
- }
850
- function editRelationsInStore(token, change, store) {
851
- const myJoin = getJoin(token, store);
852
- const target = internal.newest(store);
853
- if (internal.isChildStore(target)) {
854
- const { toolkit } = target.transactionMeta;
855
- myJoin.transact(toolkit, ({ relations }) => {
856
- change(relations);
857
- });
858
- } else {
859
- change(myJoin.relations);
860
- }
861
- }
862
- function editRelations(token, change) {
863
- editRelationsInStore(token, change, internal.IMPLICIT.STORE);
864
- }
865
- function getInternalRelationsFromStore(token, store) {
866
- const myJoin = getJoin(token, store);
867
- const family = myJoin.core.findRelatedKeysState;
868
- return family;
869
- }
870
- function getInternalRelations(token) {
871
- return getInternalRelationsFromStore(token, internal.IMPLICIT.STORE);
872
- }
873
- var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
874
- function struct(options, store = internal.IMPLICIT.STORE) {
875
- const atoms = Object.keys(options.default).reduce((acc, key) => {
876
- const atomName = options.key + capitalize2(key) + `State`;
877
- acc[atomName] = internal.createRegularAtom(
878
- {
879
- key: `${options.key}.${key}`,
880
- default: options.default[key]
881
- },
882
- void 0,
883
- store
884
- );
885
- return acc;
886
- }, {});
887
- const structState = internal.createStandaloneSelector(
888
- {
889
- key: options.key,
890
- get: ({ get }) => {
891
- return Object.keys(options.default).reduce((acc, key) => {
892
- acc[key] = get(atoms[options.key + capitalize2(key) + `State`]);
893
- return acc;
894
- }, {});
895
- }
896
- },
897
- store
898
- );
899
- return [atoms, structState];
900
- }
901
- var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
902
- var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(subKey) + `State`;
903
- function structFamily(options) {
904
- const atoms = Object.keys(options.default).reduce((acc, subKey) => {
905
- const atomFamilyName = nameFamily(options.key, subKey);
906
- acc[atomFamilyName] = internal.createRegularAtomFamily(
907
- {
908
- key: `${options.key}.${subKey}`,
909
- default: options.default[subKey]
910
- },
911
- internal.IMPLICIT.STORE
912
- );
913
- return acc;
914
- }, {});
915
- const findStructState = internal.createSelectorFamily(
916
- {
917
- key: options.key,
918
- get: (id) => ({ find, get }) => {
919
- return Object.keys(options.default).reduce((acc, subKey) => {
920
- acc[subKey] = get(
921
- find(atoms[nameFamily(options.key, subKey)], id)
922
- );
923
- return acc;
924
- }, {});
925
- }
926
- },
927
- internal.IMPLICIT.STORE
928
- );
929
- return [atoms, findStructState];
930
- }
931
-
932
- // data/src/until.ts
933
- function until(loadable, fallback) {
934
- if (loadable instanceof Promise) {
935
- return fallback;
936
- }
937
- return loadable;
938
- }
939
-
940
- exports.Join = Join;
941
- exports.dict = dict;
942
- exports.editRelations = editRelations;
943
- exports.editRelationsInStore = editRelationsInStore;
944
- exports.findRelations = findRelations;
945
- exports.findRelationsInStore = findRelationsInStore;
946
- exports.getInternalRelations = getInternalRelations;
947
- exports.getInternalRelationsFromStore = getInternalRelationsFromStore;
948
- exports.getJoin = getJoin;
949
- exports.getJoinMap = getJoinMap;
950
- exports.join = join;
951
- exports.struct = struct;
952
- exports.structFamily = structFamily;
953
- exports.until = until;