atom.io 0.41.1 → 0.42.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internal/index.d.ts +30 -47
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +116 -287
- package/dist/internal/index.js.map +1 -1
- package/dist/main/index.d.ts +52 -56
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +45 -8
- package/dist/main/index.js.map +1 -1
- package/dist/realtime/index.d.ts +2 -3
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +1 -1
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-server/index.js +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/realtime-testing/index.js +1 -1
- package/dist/struct/index.d.ts +14 -0
- package/dist/struct/index.d.ts.map +1 -0
- package/dist/struct/index.js +35 -0
- package/dist/struct/index.js.map +1 -0
- package/dist/transceivers/o-list/index.d.ts +8 -4
- package/dist/transceivers/o-list/index.d.ts.map +1 -1
- package/dist/transceivers/o-list/index.js +2 -1
- package/dist/transceivers/o-list/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -0
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/dist/transceivers/u-list/index.d.ts +12 -4
- package/dist/transceivers/u-list/index.d.ts.map +1 -1
- package/dist/transceivers/u-list/index.js +34 -2
- package/dist/transceivers/u-list/index.js.map +1 -1
- package/dist/utility-types-aZkJVERa.d.ts +10 -0
- package/dist/utility-types-aZkJVERa.d.ts.map +1 -0
- package/package.json +20 -16
- package/src/internal/atom/create-regular-atom.ts +3 -1
- package/src/internal/index.ts +0 -1
- package/src/internal/join/create-join.ts +8 -11
- package/src/internal/join/edit-relations-in-store.ts +6 -8
- package/src/internal/join/find-relations-in-store.ts +11 -67
- package/src/internal/join/get-internal-relations-from-store.ts +11 -5
- package/src/internal/join/get-join.ts +7 -9
- package/src/internal/join/join-internal.ts +143 -412
- package/src/internal/molecule.ts +44 -25
- package/src/internal/mutable/create-mutable-atom.ts +15 -11
- package/src/internal/mutable/transceiver.ts +1 -5
- package/src/internal/set-state/dispatch-state-update.ts +1 -1
- package/src/internal/store/store.ts +16 -15
- package/src/internal/transaction/build-transaction.ts +1 -1
- package/src/main/atom.ts +15 -6
- package/src/main/join.ts +68 -151
- package/src/main/realm.ts +58 -17
- package/src/realtime/shared-room-store.ts +5 -15
- package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +1 -1
- package/src/struct/index.ts +1 -0
- package/src/{internal → struct}/micro.ts +1 -1
- package/src/transceivers/o-list/o-list.ts +13 -9
- package/src/transceivers/set-rtx/set-rtx.ts +4 -0
- package/src/transceivers/u-list/index.ts +1 -0
- package/src/transceivers/u-list/u-list-disposed-key-cleanup-effect.ts +47 -0
- package/src/transceivers/u-list/u-list.ts +13 -9
package/dist/internal/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AtomIOLogger, PRETTY_TOKEN_TYPES, decomposeCompound, simpleCompound } from "atom.io";
|
|
2
2
|
import { parseJson, stringifyJson } from "atom.io/json";
|
|
3
|
-
import {
|
|
3
|
+
import { UList } from "atom.io/transceivers/u-list";
|
|
4
4
|
|
|
5
5
|
//#region src/internal/arbitrary.ts
|
|
6
6
|
function arbitrary(random = Math.random) {
|
|
@@ -625,7 +625,8 @@ function makeRootMoleculeInStore(store, key) {
|
|
|
625
625
|
const molecule = {
|
|
626
626
|
key,
|
|
627
627
|
stringKey: stringifyJson(key),
|
|
628
|
-
dependsOn: `any
|
|
628
|
+
dependsOn: `any`,
|
|
629
|
+
subject: new Subject()
|
|
629
630
|
};
|
|
630
631
|
store.molecules.set(stringifyJson(key), molecule);
|
|
631
632
|
return key;
|
|
@@ -645,10 +646,12 @@ function allocateIntoStore(store, provenance, key, dependsOn = `any`) {
|
|
|
645
646
|
if (target.molecules.get(claimString)) store.moleculeGraph.set(claimString, stringKey, { source: claimString });
|
|
646
647
|
else invalidKeys.push(claimString);
|
|
647
648
|
}
|
|
649
|
+
const subject = new Subject();
|
|
648
650
|
if (invalidKeys.length === 0) target.molecules.set(stringKey, {
|
|
649
651
|
key,
|
|
650
652
|
stringKey,
|
|
651
|
-
dependsOn
|
|
653
|
+
dependsOn,
|
|
654
|
+
subject
|
|
652
655
|
});
|
|
653
656
|
const creationEvent = {
|
|
654
657
|
type: `molecule_creation`,
|
|
@@ -685,12 +688,24 @@ function deallocateFromStore(target, claim) {
|
|
|
685
688
|
target.logger.error(`❌`, `key`, claim, `deallocation failed:`, `Could not find allocation for ${stringKey} in store "${target.config.name}".`, disposal ? `\n This state was most recently deallocated\n${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`);
|
|
686
689
|
return;
|
|
687
690
|
}
|
|
688
|
-
|
|
691
|
+
molecule.subject.next();
|
|
692
|
+
const joinKeys = target.keyRefsInJoins.getRelatedKeys(stringKey);
|
|
689
693
|
if (joinKeys) for (const joinKey of joinKeys) {
|
|
690
694
|
const join$1 = target.joins.get(joinKey);
|
|
691
695
|
if (join$1) join$1.relations.delete(claim);
|
|
692
696
|
}
|
|
693
|
-
|
|
697
|
+
else {
|
|
698
|
+
const compound = decomposeCompound(claim);
|
|
699
|
+
if (compound) {
|
|
700
|
+
const [, a, b] = compound;
|
|
701
|
+
const joinKey = target.keyRefsInJoins.getRelatedKey(simpleCompound(a, b));
|
|
702
|
+
if (joinKey) {
|
|
703
|
+
const join$1 = target.joins.get(joinKey);
|
|
704
|
+
if (join$1) join$1.relations.delete(a, b);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
target.keyRefsInJoins.delete(stringKey);
|
|
694
709
|
const provenance = [];
|
|
695
710
|
const values = [];
|
|
696
711
|
const relatedMolecules = target.moleculeGraph.getRelationEntries({ downstreamMoleculeKey: stringKey });
|
|
@@ -716,7 +731,7 @@ function deallocateFromStore(target, claim) {
|
|
|
716
731
|
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
717
732
|
if (isTransaction) target.transactionMeta.update.subEvents.push(disposalEvent);
|
|
718
733
|
target.moleculeGraph.delete(molecule.stringKey);
|
|
719
|
-
target.
|
|
734
|
+
target.keyRefsInJoins.delete(molecule.stringKey);
|
|
720
735
|
target.moleculeData.delete(molecule.stringKey);
|
|
721
736
|
if (!isTransaction) target.on.moleculeDisposal.next(disposalEvent);
|
|
722
737
|
target.molecules.delete(molecule.stringKey);
|
|
@@ -983,7 +998,7 @@ const buildTransaction = (store, token, params, id) => {
|
|
|
983
998
|
molecules: new MapOverlay(parent.molecules),
|
|
984
999
|
moleculeGraph: parent.moleculeGraph.overlay(),
|
|
985
1000
|
moleculeData: parent.moleculeData.overlay(),
|
|
986
|
-
|
|
1001
|
+
keyRefsInJoins: parent.keyRefsInJoins.overlay(),
|
|
987
1002
|
miscResources: new MapOverlay(parent.miscResources)
|
|
988
1003
|
};
|
|
989
1004
|
const epoch = getEpochNumberOfAction(store, token.key);
|
|
@@ -1098,10 +1113,6 @@ var Store = class {
|
|
|
1098
1113
|
});
|
|
1099
1114
|
disposalTraces = new CircularBuffer(100);
|
|
1100
1115
|
molecules = /* @__PURE__ */ new Map();
|
|
1101
|
-
moleculeJoins = new Junction({
|
|
1102
|
-
between: [`moleculeKey`, `joinKey`],
|
|
1103
|
-
cardinality: `n:n`
|
|
1104
|
-
}, { makeContentKey: (...keys) => keys.sort().join(`:`) });
|
|
1105
1116
|
moleculeGraph = new Junction({
|
|
1106
1117
|
between: [`upstreamMoleculeKey`, `downstreamMoleculeKey`],
|
|
1107
1118
|
cardinality: `n:n`
|
|
@@ -1110,6 +1121,10 @@ var Store = class {
|
|
|
1110
1121
|
between: [`moleculeKey`, `stateFamilyKey`],
|
|
1111
1122
|
cardinality: `n:n`
|
|
1112
1123
|
}, { makeContentKey: (...keys) => keys.sort().join(`:`) });
|
|
1124
|
+
keyRefsInJoins = new Junction({
|
|
1125
|
+
between: [`moleculeKey`, `joinKey`],
|
|
1126
|
+
cardinality: `n:n`
|
|
1127
|
+
}, { makeContentKey: (...keys) => keys.sort().join(`:`) });
|
|
1113
1128
|
miscResources = /* @__PURE__ */ new Map();
|
|
1114
1129
|
on = {
|
|
1115
1130
|
atomCreation: new Subject(),
|
|
@@ -2655,6 +2670,14 @@ function createMutableAtom(store, options, family) {
|
|
|
2655
2670
|
if (family) newAtom.family = family;
|
|
2656
2671
|
target.atoms.set(newAtom.key, newAtom);
|
|
2657
2672
|
const token = deposit(newAtom);
|
|
2673
|
+
new Tracker(token, store);
|
|
2674
|
+
if (!family) createStandaloneSelector(store, {
|
|
2675
|
+
key: `${key}:JSON`,
|
|
2676
|
+
get: ({ get }) => get(token).toJSON(),
|
|
2677
|
+
set: ({ set }, newValue) => {
|
|
2678
|
+
set(token, options.class.fromJSON(newValue));
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2658
2681
|
if (options.effects) {
|
|
2659
2682
|
let effectIndex = 0;
|
|
2660
2683
|
const cleanupFunctions = [];
|
|
@@ -2666,7 +2689,9 @@ function createMutableAtom(store, options, family) {
|
|
|
2666
2689
|
setSelf: (next) => {
|
|
2667
2690
|
setIntoStore(store, token, next);
|
|
2668
2691
|
},
|
|
2669
|
-
onSet: (handle) => subscribeToState(store, token, `effect[${effectIndex}]`, handle)
|
|
2692
|
+
onSet: (handle) => subscribeToState(store, token, `effect[${effectIndex}]`, handle),
|
|
2693
|
+
token,
|
|
2694
|
+
store: eldest(store)
|
|
2670
2695
|
});
|
|
2671
2696
|
if (cleanup) cleanupFunctions.push(cleanup);
|
|
2672
2697
|
++effectIndex;
|
|
@@ -2675,14 +2700,6 @@ function createMutableAtom(store, options, family) {
|
|
|
2675
2700
|
for (const cleanup of cleanupFunctions) cleanup();
|
|
2676
2701
|
};
|
|
2677
2702
|
}
|
|
2678
|
-
new Tracker(token, store);
|
|
2679
|
-
if (!family) createStandaloneSelector(store, {
|
|
2680
|
-
key: `${key}:JSON`,
|
|
2681
|
-
get: ({ get }) => get(token).toJSON(),
|
|
2682
|
-
set: ({ set }, newValue) => {
|
|
2683
|
-
set(token, options.class.fromJSON(newValue));
|
|
2684
|
-
}
|
|
2685
|
-
});
|
|
2686
2703
|
store.on.atomCreation.next(token);
|
|
2687
2704
|
return token;
|
|
2688
2705
|
}
|
|
@@ -2966,7 +2983,9 @@ function createRegularAtom(store, options, family, internalRoles) {
|
|
|
2966
2983
|
setSelf: (next) => {
|
|
2967
2984
|
setIntoStore(store, token, next);
|
|
2968
2985
|
},
|
|
2969
|
-
onSet: (handle) => subscribeToState(store, token, `effect[${effectIndex}]`, handle)
|
|
2986
|
+
onSet: (handle) => subscribeToState(store, token, `effect[${effectIndex}]`, handle),
|
|
2987
|
+
token,
|
|
2988
|
+
store: eldest(store)
|
|
2970
2989
|
});
|
|
2971
2990
|
if (cleanup) cleanupFunctions.push(cleanup);
|
|
2972
2991
|
++effectIndex;
|
|
@@ -3064,10 +3083,9 @@ function installIntoStore(tokens, target, source) {
|
|
|
3064
3083
|
var Join = class {
|
|
3065
3084
|
toolkit;
|
|
3066
3085
|
options;
|
|
3067
|
-
defaultContent;
|
|
3068
3086
|
relations;
|
|
3069
3087
|
states;
|
|
3070
|
-
|
|
3088
|
+
relatedKeysAtoms;
|
|
3071
3089
|
transact(toolkit, run) {
|
|
3072
3090
|
const originalToolkit = this.toolkit;
|
|
3073
3091
|
this.toolkit = toolkit;
|
|
@@ -3075,15 +3093,11 @@ var Join = class {
|
|
|
3075
3093
|
this.toolkit = originalToolkit;
|
|
3076
3094
|
}
|
|
3077
3095
|
store;
|
|
3078
|
-
realm;
|
|
3079
3096
|
[Symbol.dispose]() {}
|
|
3080
|
-
constructor(options,
|
|
3097
|
+
constructor(options, store = IMPLICIT.STORE) {
|
|
3081
3098
|
this.store = store;
|
|
3082
|
-
this.realm = new Anarchy(store);
|
|
3083
3099
|
this.options = options;
|
|
3084
|
-
this.defaultContent = defaultContent;
|
|
3085
3100
|
this.store.miscResources.set(`join:${options.key}`, this);
|
|
3086
|
-
this.realm.allocate(`root`, options.key);
|
|
3087
3101
|
this.toolkit = {
|
|
3088
3102
|
get: ((...ps) => getFromStore(store, ...ps)),
|
|
3089
3103
|
set: ((...ps) => {
|
|
@@ -3096,28 +3110,9 @@ var Join = class {
|
|
|
3096
3110
|
const bSide = options.between[1];
|
|
3097
3111
|
const relatedKeysAtoms = createMutableAtomFamily(store, {
|
|
3098
3112
|
key: `${options.key}/relatedKeys`,
|
|
3099
|
-
class:
|
|
3113
|
+
class: UList
|
|
3100
3114
|
}, [`join`, `relations`]);
|
|
3101
|
-
this.
|
|
3102
|
-
const getRelatedKeys = ({ get }, key) => get(relatedKeysAtoms, key);
|
|
3103
|
-
const addRelation = ({ set }, a, b) => {
|
|
3104
|
-
if (!this.store.molecules.has(stringifyJson(a))) this.realm.allocate(options.key, a);
|
|
3105
|
-
set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b));
|
|
3106
|
-
set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a));
|
|
3107
|
-
};
|
|
3108
|
-
const deleteRelation = ({ set }, a, b) => {
|
|
3109
|
-
set(relatedKeysAtoms, a, (aKeys) => {
|
|
3110
|
-
aKeys.delete(b);
|
|
3111
|
-
return aKeys;
|
|
3112
|
-
});
|
|
3113
|
-
set(relatedKeysAtoms, b, (bKeys) => {
|
|
3114
|
-
bKeys.delete(a);
|
|
3115
|
-
return bKeys;
|
|
3116
|
-
});
|
|
3117
|
-
const [x, y] = [a, b].sort();
|
|
3118
|
-
const compositeKey = `${x}:${y}`;
|
|
3119
|
-
this.store.moleculeJoins.delete(compositeKey);
|
|
3120
|
-
};
|
|
3115
|
+
this.relatedKeysAtoms = relatedKeysAtoms;
|
|
3121
3116
|
const replaceRelationsSafely = (toolkit, a, newRelationsOfA) => {
|
|
3122
3117
|
const { find, get, set } = toolkit;
|
|
3123
3118
|
const relationsOfAState = find(relatedKeysAtoms, a);
|
|
@@ -3130,41 +3125,42 @@ var Join = class {
|
|
|
3130
3125
|
});
|
|
3131
3126
|
}
|
|
3132
3127
|
set(relationsOfAState, (relationsOfA) => {
|
|
3133
|
-
relationsOfA.
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
const compositeKey = `${x}:${y}`;
|
|
3150
|
-
store.moleculeJoins.delete(compositeKey);
|
|
3151
|
-
}
|
|
3128
|
+
relationsOfA.clear();
|
|
3129
|
+
for (const newRelationB of newRelationsOfA) {
|
|
3130
|
+
const relationsOfBAtom = find(relatedKeysAtoms, newRelationB);
|
|
3131
|
+
const relationsOfB = get(relationsOfBAtom);
|
|
3132
|
+
const newRelationBIsAlreadyRelated = relationsOfB.has(a);
|
|
3133
|
+
if (this.relations.cardinality === `1:n`) {
|
|
3134
|
+
const previousOwnersToDispose = [];
|
|
3135
|
+
for (const previousOwner of relationsOfB) {
|
|
3136
|
+
if (previousOwner === a) continue;
|
|
3137
|
+
let previousOwnerSize;
|
|
3138
|
+
operateOnStore(JOIN_OP, this.store, relatedKeysAtoms, previousOwner, (relations$1) => {
|
|
3139
|
+
relations$1.delete(newRelationB);
|
|
3140
|
+
previousOwnerSize = relations$1.size;
|
|
3141
|
+
return relations$1;
|
|
3142
|
+
});
|
|
3143
|
+
if (previousOwnerSize === 0) previousOwnersToDispose.push(previousOwner);
|
|
3152
3144
|
}
|
|
3153
|
-
if (!newRelationBIsAlreadyRelated
|
|
3154
|
-
|
|
3145
|
+
if (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) set(relationsOfBAtom, (relations$1) => {
|
|
3146
|
+
relations$1.clear();
|
|
3147
|
+
return relations$1;
|
|
3148
|
+
});
|
|
3149
|
+
for (const previousOwner of previousOwnersToDispose) store.keyRefsInJoins.delete(simpleCompound(newRelationB, previousOwner));
|
|
3155
3150
|
}
|
|
3156
|
-
|
|
3157
|
-
|
|
3151
|
+
if (!newRelationBIsAlreadyRelated) set(relationsOfBAtom, (relations$1) => {
|
|
3152
|
+
relations$1.add(a);
|
|
3153
|
+
return relations$1;
|
|
3154
|
+
});
|
|
3155
|
+
relationsOfA.add(newRelationB);
|
|
3156
|
+
}
|
|
3158
3157
|
return relationsOfA;
|
|
3159
3158
|
});
|
|
3160
3159
|
};
|
|
3161
3160
|
const replaceRelationsUnsafely = (toolkit, a, newRelationsOfA) => {
|
|
3162
3161
|
const { set } = toolkit;
|
|
3163
3162
|
set(relatedKeysAtoms, a, (relationsOfA) => {
|
|
3164
|
-
relationsOfA.
|
|
3165
|
-
for (const newRelationB of newRelationsOfA) nextRelationsOfA.add(newRelationB);
|
|
3166
|
-
return true;
|
|
3167
|
-
});
|
|
3163
|
+
for (const newRelationB of newRelationsOfA) relationsOfA.add(newRelationB);
|
|
3168
3164
|
return relationsOfA;
|
|
3169
3165
|
});
|
|
3170
3166
|
for (const newRelationB of newRelationsOfA) set(relatedKeysAtoms, newRelationB, (newRelationsB) => {
|
|
@@ -3173,66 +3169,41 @@ var Join = class {
|
|
|
3173
3169
|
});
|
|
3174
3170
|
return true;
|
|
3175
3171
|
};
|
|
3176
|
-
const
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
addRelation(this.toolkit, a, b);
|
|
3186
|
-
},
|
|
3187
|
-
deleteRelation: (a, b) => {
|
|
3188
|
-
deleteRelation(this.toolkit, a, b);
|
|
3189
|
-
},
|
|
3190
|
-
replaceRelationsSafely: (a, bs) => {
|
|
3191
|
-
replaceRelationsSafely(this.toolkit, a, bs);
|
|
3192
|
-
},
|
|
3193
|
-
replaceRelationsUnsafely: (a, bs) => {
|
|
3194
|
-
replaceRelationsUnsafely(this.toolkit, a, bs);
|
|
3195
|
-
},
|
|
3196
|
-
has: (a, b) => has(this.toolkit, a, b)
|
|
3197
|
-
};
|
|
3198
|
-
let externalStore;
|
|
3199
|
-
let contentAtoms;
|
|
3200
|
-
if (defaultContent) {
|
|
3201
|
-
contentAtoms = createRegularAtomFamily(store, {
|
|
3202
|
-
key: `${options.key}/content`,
|
|
3203
|
-
default: defaultContent
|
|
3204
|
-
}, [`join`, `content`]);
|
|
3205
|
-
const getContent = ({ get }, key) => get(contentAtoms, key);
|
|
3206
|
-
const setContent = ({ set }, key, content) => {
|
|
3207
|
-
set(contentAtoms, key, content);
|
|
3208
|
-
};
|
|
3209
|
-
externalStore = Object.assign(baseExternalStoreConfiguration, {
|
|
3210
|
-
getContent: (contentKey) => {
|
|
3211
|
-
return getContent(this.toolkit, contentKey);
|
|
3172
|
+
const relations = new Junction(options, {
|
|
3173
|
+
externalStore: {
|
|
3174
|
+
getRelatedKeys: (key) => this.toolkit.get(relatedKeysAtoms, key),
|
|
3175
|
+
addRelation: (a, b) => {
|
|
3176
|
+
this.store.keyRefsInJoins.set(`"${a}"`, options.key);
|
|
3177
|
+
this.store.keyRefsInJoins.set(`"${b}"`, options.key);
|
|
3178
|
+
this.store.keyRefsInJoins.set(simpleCompound(a, b), options.key);
|
|
3179
|
+
this.toolkit.set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b));
|
|
3180
|
+
this.toolkit.set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a));
|
|
3212
3181
|
},
|
|
3213
|
-
|
|
3214
|
-
|
|
3182
|
+
deleteRelation: (a, b) => {
|
|
3183
|
+
this.toolkit.set(relatedKeysAtoms, a, (aKeys) => {
|
|
3184
|
+
aKeys.delete(b);
|
|
3185
|
+
return aKeys;
|
|
3186
|
+
});
|
|
3187
|
+
this.toolkit.set(relatedKeysAtoms, b, (bKeys) => {
|
|
3188
|
+
bKeys.delete(a);
|
|
3189
|
+
return bKeys;
|
|
3190
|
+
});
|
|
3191
|
+
const compositeKey = simpleCompound(a, b);
|
|
3192
|
+
this.store.keyRefsInJoins.delete(compositeKey);
|
|
3215
3193
|
},
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3194
|
+
replaceRelationsSafely: (a, bs) => {
|
|
3195
|
+
replaceRelationsSafely(this.toolkit, a, bs);
|
|
3196
|
+
},
|
|
3197
|
+
replaceRelationsUnsafely: (a, bs) => {
|
|
3198
|
+
replaceRelationsUnsafely(this.toolkit, a, bs);
|
|
3199
|
+
},
|
|
3200
|
+
has: (a, b) => {
|
|
3201
|
+
const aKeys = this.toolkit.get(relatedKeysAtoms, a);
|
|
3202
|
+
return b ? aKeys.has(b) : aKeys.size > 0;
|
|
3203
|
+
}
|
|
3204
|
+
},
|
|
3221
3205
|
isAType: options.isAType,
|
|
3222
|
-
isBType: options.isBType
|
|
3223
|
-
makeContentKey: (...args) => {
|
|
3224
|
-
const [a, b] = args;
|
|
3225
|
-
const [x, y] = args.sort();
|
|
3226
|
-
const compositeKey = `${x}:${y}`;
|
|
3227
|
-
const aMolecule = store.molecules.get(stringifyJson(a));
|
|
3228
|
-
const bMolecule = store.molecules.get(stringifyJson(b));
|
|
3229
|
-
if (!aMolecule) this.realm.allocate(options.key, a);
|
|
3230
|
-
if (!bMolecule) this.realm.allocate(options.key, b);
|
|
3231
|
-
this.realm.allocate(a, compositeKey, `all`);
|
|
3232
|
-
this.realm.claim(b, compositeKey);
|
|
3233
|
-
this.store.moleculeJoins.set(compositeKey, options.key);
|
|
3234
|
-
return compositeKey;
|
|
3235
|
-
}
|
|
3206
|
+
isBType: options.isBType
|
|
3236
3207
|
});
|
|
3237
3208
|
const createSingleKeySelectorFamily = () => createReadonlyPureSelectorFamily(store, {
|
|
3238
3209
|
key: `${options.key}/singleRelatedKey`,
|
|
@@ -3247,63 +3218,20 @@ var Join = class {
|
|
|
3247
3218
|
key: `${options.key}/multipleRelatedKeys`,
|
|
3248
3219
|
get: (key) => ({ get }) => {
|
|
3249
3220
|
const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
|
|
3250
|
-
return get(jsonFamily, key)
|
|
3221
|
+
return get(jsonFamily, key);
|
|
3251
3222
|
}
|
|
3252
3223
|
}, [`join`, `keys`]);
|
|
3253
3224
|
};
|
|
3254
|
-
const createSingleEntrySelectorFamily = () => createReadonlyPureSelectorFamily(store, {
|
|
3255
|
-
key: `${options.key}/singleRelatedEntry`,
|
|
3256
|
-
get: (x) => ({ get }) => {
|
|
3257
|
-
const relatedKeys = get(relatedKeysAtoms, x);
|
|
3258
|
-
for (const y of relatedKeys) {
|
|
3259
|
-
let a = relations.isAType?.(x) ? x : void 0;
|
|
3260
|
-
let b = a === void 0 ? x : void 0;
|
|
3261
|
-
a ??= y;
|
|
3262
|
-
b ??= y;
|
|
3263
|
-
const contentKey = relations.makeContentKey(a, b);
|
|
3264
|
-
const content = get(contentAtoms, contentKey);
|
|
3265
|
-
return [y, content];
|
|
3266
|
-
}
|
|
3267
|
-
return null;
|
|
3268
|
-
}
|
|
3269
|
-
}, [`join`, `entries`]);
|
|
3270
|
-
const getMultipleEntrySelectorFamily = () => createReadonlyPureSelectorFamily(store, {
|
|
3271
|
-
key: `${options.key}/multipleRelatedEntries`,
|
|
3272
|
-
get: (x) => ({ get }) => {
|
|
3273
|
-
const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
|
|
3274
|
-
return get(jsonFamily, x).members.map((y) => {
|
|
3275
|
-
let a = relations.isAType?.(x) ? x : void 0;
|
|
3276
|
-
let b = a === void 0 ? x : void 0;
|
|
3277
|
-
a ??= y;
|
|
3278
|
-
b ??= y;
|
|
3279
|
-
const contentKey = relations.makeContentKey(a, b);
|
|
3280
|
-
const content = get(contentAtoms, contentKey);
|
|
3281
|
-
return [y, content];
|
|
3282
|
-
});
|
|
3283
|
-
}
|
|
3284
|
-
}, [`join`, `entries`]);
|
|
3285
3225
|
switch (options.cardinality) {
|
|
3286
3226
|
case `1:1`: {
|
|
3287
3227
|
const singleRelatedKeySelectors = createSingleKeySelectorFamily();
|
|
3288
3228
|
const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
|
|
3289
3229
|
const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}`;
|
|
3290
|
-
|
|
3230
|
+
this.relations = relations;
|
|
3231
|
+
this.states = {
|
|
3291
3232
|
[stateKeyA]: singleRelatedKeySelectors,
|
|
3292
3233
|
[stateKeyB]: singleRelatedKeySelectors
|
|
3293
3234
|
};
|
|
3294
|
-
let states;
|
|
3295
|
-
if (defaultContent) {
|
|
3296
|
-
const singleEntrySelectors = createSingleEntrySelectorFamily();
|
|
3297
|
-
const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
|
|
3298
|
-
const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}`;
|
|
3299
|
-
const contentStates = {
|
|
3300
|
-
[entriesStateKeyA]: singleEntrySelectors,
|
|
3301
|
-
[entriesStateKeyB]: singleEntrySelectors
|
|
3302
|
-
};
|
|
3303
|
-
states = Object.assign(baseStates, contentStates);
|
|
3304
|
-
} else states = baseStates;
|
|
3305
|
-
this.relations = relations;
|
|
3306
|
-
this.states = states;
|
|
3307
3235
|
break;
|
|
3308
3236
|
}
|
|
3309
3237
|
case `1:n`: {
|
|
@@ -3315,43 +3243,19 @@ var Join = class {
|
|
|
3315
3243
|
[stateKeyA]: singleRelatedKeySelectors,
|
|
3316
3244
|
[stateKeyB]: multipleRelatedKeysSelectors
|
|
3317
3245
|
};
|
|
3318
|
-
let states;
|
|
3319
|
-
if (defaultContent) {
|
|
3320
|
-
const singleRelatedEntrySelectors = createSingleEntrySelectorFamily();
|
|
3321
|
-
const multipleRelatedEntriesSelectors = getMultipleEntrySelectorFamily();
|
|
3322
|
-
const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
|
|
3323
|
-
const entriesStateKeyB = `${bSide}EntriesOf${capitalize(aSide)}`;
|
|
3324
|
-
const contentStates = {
|
|
3325
|
-
[entriesStateKeyA]: singleRelatedEntrySelectors,
|
|
3326
|
-
[entriesStateKeyB]: multipleRelatedEntriesSelectors
|
|
3327
|
-
};
|
|
3328
|
-
states = Object.assign(baseStates, contentStates);
|
|
3329
|
-
} else states = baseStates;
|
|
3330
3246
|
this.relations = relations;
|
|
3331
|
-
this.states =
|
|
3247
|
+
this.states = baseStates;
|
|
3332
3248
|
break;
|
|
3333
3249
|
}
|
|
3334
3250
|
case `n:n`: {
|
|
3335
3251
|
const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily();
|
|
3336
3252
|
const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}`;
|
|
3337
3253
|
const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
|
|
3338
|
-
|
|
3254
|
+
this.relations = relations;
|
|
3255
|
+
this.states = {
|
|
3339
3256
|
[stateKeyA]: multipleRelatedKeysSelectors,
|
|
3340
3257
|
[stateKeyB]: multipleRelatedKeysSelectors
|
|
3341
3258
|
};
|
|
3342
|
-
let states;
|
|
3343
|
-
if (defaultContent) {
|
|
3344
|
-
const multipleRelatedEntriesSelectors = getMultipleEntrySelectorFamily();
|
|
3345
|
-
const entriesStateKeyA = `${aSide}EntriesOf${capitalize(bSide)}`;
|
|
3346
|
-
const entriesStateKeyB = `${bSide}EntriesOf${capitalize(aSide)}`;
|
|
3347
|
-
const contentStates = {
|
|
3348
|
-
[entriesStateKeyA]: multipleRelatedEntriesSelectors,
|
|
3349
|
-
[entriesStateKeyB]: multipleRelatedEntriesSelectors
|
|
3350
|
-
};
|
|
3351
|
-
states = Object.assign(baseStates, contentStates);
|
|
3352
|
-
} else states = baseStates;
|
|
3353
|
-
this.relations = relations;
|
|
3354
|
-
this.states = states;
|
|
3355
3259
|
}
|
|
3356
3260
|
}
|
|
3357
3261
|
}
|
|
@@ -3359,8 +3263,8 @@ var Join = class {
|
|
|
3359
3263
|
|
|
3360
3264
|
//#endregion
|
|
3361
3265
|
//#region src/internal/join/create-join.ts
|
|
3362
|
-
function createJoin(store, options
|
|
3363
|
-
store.joins.set(options.key, new Join(options
|
|
3266
|
+
function createJoin(store, options) {
|
|
3267
|
+
store.joins.set(options.key, new Join(options));
|
|
3364
3268
|
return {
|
|
3365
3269
|
key: options.key,
|
|
3366
3270
|
type: `join`,
|
|
@@ -3378,7 +3282,7 @@ function getJoin(token, store) {
|
|
|
3378
3282
|
const rootJoin = IMPLICIT.STORE.joins.get(token.key);
|
|
3379
3283
|
if (rootJoin === void 0) throw new Error(`Join "${token.key}" not found in store "${store.config.name}"`);
|
|
3380
3284
|
const root = eldest(store);
|
|
3381
|
-
myJoin = new Join(rootJoin.options,
|
|
3285
|
+
myJoin = new Join(rootJoin.options, root);
|
|
3382
3286
|
store.joins.set(token.key, myJoin);
|
|
3383
3287
|
}
|
|
3384
3288
|
return myJoin;
|
|
@@ -3416,20 +3320,6 @@ function findRelationsInStore(token, key, store) {
|
|
|
3416
3320
|
return findInStore(store, familyBA, key);
|
|
3417
3321
|
}
|
|
3418
3322
|
};
|
|
3419
|
-
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
|
|
3420
|
-
if (entryAB in myJoin.states) {
|
|
3421
|
-
const entryBA = `${token.b}EntryOf${capitalize(token.a)}`;
|
|
3422
|
-
Object.assign(relations, {
|
|
3423
|
-
get [entryAB]() {
|
|
3424
|
-
const familyAB = myJoin.states[entryAB];
|
|
3425
|
-
return findInStore(store, familyAB, key);
|
|
3426
|
-
},
|
|
3427
|
-
get [entryBA]() {
|
|
3428
|
-
const familyBA = myJoin.states[entryBA];
|
|
3429
|
-
return findInStore(store, familyBA, key);
|
|
3430
|
-
}
|
|
3431
|
-
});
|
|
3432
|
-
}
|
|
3433
3323
|
break;
|
|
3434
3324
|
}
|
|
3435
3325
|
case `1:n`: {
|
|
@@ -3445,20 +3335,6 @@ function findRelationsInStore(token, key, store) {
|
|
|
3445
3335
|
return findInStore(store, familyBA, key);
|
|
3446
3336
|
}
|
|
3447
3337
|
};
|
|
3448
|
-
const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
|
|
3449
|
-
if (entryAB in myJoin.states) {
|
|
3450
|
-
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
|
|
3451
|
-
Object.assign(relations, {
|
|
3452
|
-
get [entryAB]() {
|
|
3453
|
-
const familyAB = myJoin.states[entryAB];
|
|
3454
|
-
return findInStore(store, familyAB, key);
|
|
3455
|
-
},
|
|
3456
|
-
get [entriesBA]() {
|
|
3457
|
-
const familyBA = myJoin.states[entriesBA];
|
|
3458
|
-
return findInStore(store, familyBA, key);
|
|
3459
|
-
}
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
3338
|
break;
|
|
3463
3339
|
}
|
|
3464
3340
|
case `n:n`: {
|
|
@@ -3474,20 +3350,6 @@ function findRelationsInStore(token, key, store) {
|
|
|
3474
3350
|
return findInStore(store, familyBA, key);
|
|
3475
3351
|
}
|
|
3476
3352
|
};
|
|
3477
|
-
const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`;
|
|
3478
|
-
if (entriesAB in myJoin.states) {
|
|
3479
|
-
const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
|
|
3480
|
-
Object.assign(relations, {
|
|
3481
|
-
get [entriesAB]() {
|
|
3482
|
-
const familyAB = myJoin.states[entriesAB];
|
|
3483
|
-
return findInStore(store, familyAB, key);
|
|
3484
|
-
},
|
|
3485
|
-
get [entriesBA]() {
|
|
3486
|
-
const familyBA = myJoin.states[entriesBA];
|
|
3487
|
-
return findInStore(store, familyBA, key);
|
|
3488
|
-
}
|
|
3489
|
-
});
|
|
3490
|
-
}
|
|
3491
3353
|
}
|
|
3492
3354
|
}
|
|
3493
3355
|
return relations;
|
|
@@ -3496,42 +3358,9 @@ function findRelationsInStore(token, key, store) {
|
|
|
3496
3358
|
//#endregion
|
|
3497
3359
|
//#region src/internal/join/get-internal-relations-from-store.ts
|
|
3498
3360
|
function getInternalRelationsFromStore(token, store) {
|
|
3499
|
-
return getJoin(token, store).
|
|
3361
|
+
return getJoin(token, store).relatedKeysAtoms;
|
|
3500
3362
|
}
|
|
3501
3363
|
|
|
3502
|
-
//#endregion
|
|
3503
|
-
//#region src/internal/micro.ts
|
|
3504
|
-
function enumeration(values) {
|
|
3505
|
-
const result = {};
|
|
3506
|
-
let i = 0;
|
|
3507
|
-
for (const value of values) {
|
|
3508
|
-
result[value] = i;
|
|
3509
|
-
result[i] = value;
|
|
3510
|
-
++i;
|
|
3511
|
-
}
|
|
3512
|
-
return result;
|
|
3513
|
-
}
|
|
3514
|
-
const BOOL = `\u0001`;
|
|
3515
|
-
const NULL = `\u0002`;
|
|
3516
|
-
const STRING = `\u0003`;
|
|
3517
|
-
const NUMBER = `\u0004`;
|
|
3518
|
-
const packValue = (value) => {
|
|
3519
|
-
switch (typeof value) {
|
|
3520
|
-
case `string`: return STRING + value;
|
|
3521
|
-
case `number`: return NUMBER + value;
|
|
3522
|
-
case `boolean`: return BOOL + +value;
|
|
3523
|
-
case `object`: return NULL;
|
|
3524
|
-
}
|
|
3525
|
-
};
|
|
3526
|
-
const unpackValue = (value) => {
|
|
3527
|
-
switch (value[0]) {
|
|
3528
|
-
case STRING: return value.slice(1);
|
|
3529
|
-
case NUMBER: return +value.slice(1);
|
|
3530
|
-
case BOOL: return value.slice(1) === `1`;
|
|
3531
|
-
case NULL: return null;
|
|
3532
|
-
}
|
|
3533
|
-
};
|
|
3534
|
-
|
|
3535
3364
|
//#endregion
|
|
3536
3365
|
//#region src/internal/timeline/create-timeline.ts
|
|
3537
3366
|
function createTimeline(store, options, data) {
|
|
@@ -3809,5 +3638,5 @@ const timeTravel = (store, action, token) => {
|
|
|
3809
3638
|
};
|
|
3810
3639
|
|
|
3811
3640
|
//#endregion
|
|
3812
|
-
export { CircularBuffer, FamilyTracker, Future, IMPLICIT, INTERNAL_ROLES, JOIN_OP, Join, Junction, MapOverlay, NotFoundError, OWN_OP, RESET_STATE, RelationsOverlay, SetOverlay, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, capitalize, claimWithinStore, clearStore, closeOperation, createClaimTX, createDeallocateTX, createJoin, createMutableAtom, createMutableAtomFamily, createReadonlyHeldSelector, createReadonlyPureSelector, createReadonlyPureSelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneSelector, createTimeline, createTransaction, createWritableHeldSelector, createWritablePureSelector, createWritablePureSelectorFamily, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, eldest,
|
|
3641
|
+
export { CircularBuffer, FamilyTracker, Future, IMPLICIT, INTERNAL_ROLES, JOIN_OP, Join, Junction, MapOverlay, NotFoundError, OWN_OP, RESET_STATE, RelationsOverlay, SetOverlay, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, capitalize, claimWithinStore, clearStore, closeOperation, createClaimTX, createDeallocateTX, createJoin, createMutableAtom, createMutableAtomFamily, createReadonlyHeldSelector, createReadonlyPureSelector, createReadonlyPureSelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneSelector, createTimeline, createTransaction, createWritableHeldSelector, createWritablePureSelector, createWritablePureSelectorFamily, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, eldest, evictCachedValue, evictDownstreamFromAtom, evictDownstreamFromSelector, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFamilyOfToken, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, hasRole, ingestAtomUpdateEvent, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdateEvent, ingestTransactionOutcomeEvent, installIntoStore, isAtomKey, isChildStore, isDone, isFn, isReadonlySelectorKey, isReservedIntrospectionKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markDone, newest, openOperation, operateOnStore, readFromCache, readOrComputeValue, recallState, registerSelector, resetAtomOrSelector, resetInStore, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootDependency, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceRootSelectorAtoms, updateSelectorAtoms, withdraw, writeToCache };
|
|
3813
3642
|
//# sourceMappingURL=index.js.map
|