atom.io 0.17.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.cjs +62 -40
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +8 -2
- package/data/dist/index.js +64 -42
- package/data/dist/index.js.map +1 -1
- package/data/src/dict.ts +8 -4
- package/data/src/join.ts +74 -33
- package/data/src/struct-family.ts +18 -17
- package/dist/chunk-IZHOMSXA.js +331 -0
- package/dist/chunk-IZHOMSXA.js.map +1 -0
- package/dist/chunk-JDUNWJFB.js +18 -0
- package/dist/chunk-JDUNWJFB.js.map +1 -0
- package/dist/index.cjs +4 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -51
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +187 -58
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +95 -71
- package/internal/dist/index.js +179 -53
- package/internal/dist/index.js.map +1 -1
- package/internal/src/arbitrary.ts +3 -0
- package/internal/src/atom/delete-atom.ts +7 -6
- package/internal/src/caching.ts +6 -4
- package/internal/src/families/find-in-store.ts +16 -0
- package/internal/src/get-environment-data.ts +4 -7
- package/internal/src/index.ts +6 -5
- package/internal/src/ingest-updates/ingest-atom-update.ts +6 -2
- package/internal/src/ingest-updates/ingest-transaction-update.ts +0 -1
- package/internal/src/selector/create-standalone-selector.ts +0 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +5 -0
- package/internal/src/set-state/emit-update.ts +25 -11
- package/internal/src/set-state/set-atom.ts +15 -18
- package/internal/src/store/store.ts +14 -2
- package/internal/src/store/withdraw.ts +72 -2
- package/internal/src/subscribe/subscribe-to-timeline.ts +2 -2
- package/internal/src/subscribe/subscribe-to-transaction.ts +2 -2
- package/internal/src/timeline/create-timeline.ts +12 -1
- package/internal/src/transaction/act-upon-store.ts +19 -0
- package/internal/src/transaction/apply-transaction.ts +6 -1
- package/internal/src/transaction/assign-transaction-to-continuity.ts +18 -0
- package/internal/src/transaction/build-transaction.ts +7 -6
- package/internal/src/transaction/create-transaction.ts +1 -1
- package/internal/src/transaction/get-epoch-number.ts +40 -0
- package/internal/src/transaction/index.ts +10 -1
- package/internal/src/transaction/set-epoch-number.ts +30 -0
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-introspection-states.ts +6 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/json/dist/index.d.ts +3 -1
- package/json/src/index.ts +4 -0
- package/package.json +241 -230
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js.map +1 -1
- package/react/src/use-json.ts +1 -1
- package/react-devtools/dist/index.cjs +131 -134
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.css +2 -2
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.ts +3 -3
- package/react-devtools/dist/index.js +91 -108
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +4 -4
- package/react-devtools/src/StateIndex.tsx +1 -4
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +9 -8
- package/react-devtools/src/index.ts +2 -2
- package/realtime/dist/index.cjs +120 -0
- package/realtime/dist/index.cjs.map +1 -0
- package/realtime/dist/index.d.ts +146 -0
- package/realtime/dist/index.js +111 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/package.json +16 -0
- package/realtime/src/index.ts +2 -0
- package/realtime/src/realtime-continuity.ts +162 -0
- package/realtime/src/shared-room-store.ts +48 -0
- package/realtime-client/dist/index.cjs +424 -170
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +15 -11
- package/realtime-client/dist/index.js +96 -177
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +8 -7
- package/realtime-client/src/{pull-family-member.ts → pull-atom-family-member.ts} +2 -2
- package/realtime-client/src/{pull-state.ts → pull-atom.ts} +2 -2
- package/realtime-client/src/{pull-mutable-family-member.ts → pull-mutable-atom-family-member.ts} +6 -6
- package/realtime-client/src/{pull-mutable.ts → pull-mutable-atom.ts} +1 -1
- package/realtime-client/src/pull-selector-family-member.ts +42 -0
- package/realtime-client/src/pull-selector.ts +38 -0
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +12 -2
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +7 -7
- package/realtime-client/src/sync-continuity.ts +368 -0
- package/realtime-react/dist/index.cjs +367 -27
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +24 -8
- package/realtime-react/dist/index.js +38 -22
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +6 -5
- package/realtime-react/src/use-pull-atom-family-member.ts +21 -0
- package/realtime-react/src/{use-sync.ts → use-pull-atom.ts} +4 -4
- package/realtime-react/src/{use-pull-mutable.ts → use-pull-mutable-atom.ts} +4 -3
- package/realtime-react/src/use-pull-mutable-family-member.ts +9 -4
- package/realtime-react/src/use-pull-selector-family-member.ts +21 -0
- package/realtime-react/src/{use-pull.ts → use-pull-selector.ts} +7 -5
- package/realtime-react/src/use-push.ts +3 -2
- package/realtime-react/src/use-server-action.ts +3 -2
- package/realtime-react/src/use-sync-continuity.ts +12 -0
- package/realtime-server/dist/index.cjs +769 -371
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +130 -60
- package/realtime-server/dist/index.js +753 -361
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +17 -3
- package/realtime-server/src/ipc-sockets/child-socket.ts +135 -0
- package/realtime-server/src/ipc-sockets/custom-socket.ts +90 -0
- package/realtime-server/src/ipc-sockets/index.ts +3 -0
- package/realtime-server/src/ipc-sockets/parent-socket.ts +185 -0
- package/realtime-server/src/realtime-action-receiver.ts +8 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +376 -0
- package/realtime-server/src/realtime-family-provider.ts +30 -71
- package/realtime-server/src/realtime-mutable-family-provider.ts +24 -86
- package/realtime-server/src/realtime-server-stores/index.ts +4 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +109 -0
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +64 -0
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +42 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +51 -98
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +14 -29
- package/realtime-server/src/realtime-state-receiver.ts +0 -1
- package/realtime-testing/dist/index.cjs +34 -32
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +1 -0
- package/realtime-testing/dist/index.js +33 -31
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +44 -32
- package/src/atom.ts +49 -31
- package/src/logger.ts +14 -5
- package/src/selector.ts +44 -25
- package/src/subscribe.ts +2 -1
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +13 -17
- package/src/validators.ts +15 -9
- package/dist/chunk-H4Q5FTPZ.js +0 -11
- package/dist/chunk-H4Q5FTPZ.js.map +0 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +0 -19
- package/realtime-client/src/sync-server-action.ts +0 -170
- package/realtime-client/src/sync-state.ts +0 -19
- package/realtime-react/src/use-pull-family-member.ts +0 -16
- package/realtime-react/src/use-sync-server-action.ts +0 -16
- package/realtime-server/src/realtime-action-synchronizer.ts +0 -152
|
@@ -4,10 +4,10 @@ import type { FC } from "react"
|
|
|
4
4
|
|
|
5
5
|
import { fallback } from "~/packages/anvl/src/function"
|
|
6
6
|
import { Join } from "~/packages/anvl/src/join"
|
|
7
|
-
import { isJson } from "~/packages/anvl/src/refinement
|
|
8
|
-
import { RelationEditor } from "~/packages/hamr/
|
|
9
|
-
import { ElasticInput } from "~/packages/hamr/
|
|
10
|
-
import { JsonEditor } from "~/packages/hamr/
|
|
7
|
+
import { isJson } from "~/packages/anvl/src/refinement"
|
|
8
|
+
import { RelationEditor } from "~/packages/hamr/react-data-designer/src"
|
|
9
|
+
import { ElasticInput } from "~/packages/hamr/react-elastic-input/src"
|
|
10
|
+
import { JsonEditor } from "~/packages/hamr/react-json-editor/src"
|
|
11
11
|
|
|
12
12
|
export const StateEditor: FC<{
|
|
13
13
|
token: WritableToken<unknown>
|
|
@@ -9,10 +9,7 @@ import { useI, useO } from "atom.io/react"
|
|
|
9
9
|
import type { FC } from "react"
|
|
10
10
|
|
|
11
11
|
import { recordToEntries } from "~/packages/anvl/src/object"
|
|
12
|
-
import {
|
|
13
|
-
isJson,
|
|
14
|
-
refineJsonType,
|
|
15
|
-
} from "~/packages/anvl/src/refinement/refine-json"
|
|
12
|
+
import { isJson, refineJsonType } from "~/packages/anvl/src/refinement"
|
|
16
13
|
|
|
17
14
|
import { findViewIsOpenState, primitiveRefinery } from "."
|
|
18
15
|
import { button } from "./Button"
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
RegularAtomToken,
|
|
4
4
|
TimelineToken,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import { redo, undo } from "atom.io"
|
|
6
|
+
import { findState, redo, undo } from "atom.io"
|
|
7
7
|
import type { Timeline } from "atom.io/internal"
|
|
8
8
|
import { useI, useO } from "atom.io/react"
|
|
9
9
|
import { type FC, Fragment } from "react"
|
|
@@ -82,8 +82,8 @@ export const TimelineIndex: FC = () => {
|
|
|
82
82
|
<TimelineLog
|
|
83
83
|
key={token.key}
|
|
84
84
|
token={token}
|
|
85
|
-
isOpenState={findViewIsOpenState
|
|
86
|
-
timelineState={findTimelineState
|
|
85
|
+
isOpenState={findState(findViewIsOpenState, token.key)}
|
|
86
|
+
timelineState={findState(findTimelineState, token.key)}
|
|
87
87
|
/>
|
|
88
88
|
)
|
|
89
89
|
})}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
ReadonlySelectorToken,
|
|
3
|
-
RegularAtomToken,
|
|
4
|
-
TransactionToken,
|
|
5
|
-
TransactionUpdate,
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
type ReadonlySelectorToken,
|
|
3
|
+
type RegularAtomToken,
|
|
4
|
+
type TransactionToken,
|
|
5
|
+
type TransactionUpdate,
|
|
6
|
+
findState,
|
|
7
|
+
type ƒn,
|
|
7
8
|
} from "atom.io"
|
|
8
9
|
import { useI, useO } from "atom.io/react"
|
|
9
10
|
import type { FC } from "react"
|
|
@@ -60,8 +61,8 @@ export const TransactionIndex: FC = () => {
|
|
|
60
61
|
<TransactionLog
|
|
61
62
|
key={token.key}
|
|
62
63
|
token={token}
|
|
63
|
-
isOpenState={findViewIsOpenState
|
|
64
|
-
logState={findTransactionLogState
|
|
64
|
+
isOpenState={findState(findViewIsOpenState, token.key)}
|
|
65
|
+
logState={findState(findTransactionLogState, token.key)}
|
|
65
66
|
/>
|
|
66
67
|
)
|
|
67
68
|
})}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { atom, atomFamily } from "atom.io"
|
|
2
2
|
import { attachIntrospectionStates } from "atom.io/introspection"
|
|
3
|
-
import { lazyLocalStorageEffect } from "~/packages/atom.io/__unstable__/web-effects/src"
|
|
4
3
|
|
|
5
4
|
import { isPlainObject } from "~/packages/anvl/src/object"
|
|
6
|
-
import { Refinery } from "~/packages/anvl/src/refinement
|
|
5
|
+
import { Refinery } from "~/packages/anvl/src/refinement"
|
|
7
6
|
import {
|
|
8
7
|
Differ,
|
|
9
8
|
diffArray,
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
diffObject,
|
|
13
12
|
diffString,
|
|
14
13
|
} from "~/packages/anvl/src/tree/differ"
|
|
14
|
+
import { lazyLocalStorageEffect } from "~/packages/atom.io/__unstable__/web-effects/src"
|
|
15
15
|
|
|
16
16
|
export * from "./AtomIODevtools"
|
|
17
17
|
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internal = require('atom.io/internal');
|
|
4
|
+
var atom_io = require('atom.io');
|
|
5
|
+
var data = require('atom.io/data');
|
|
6
|
+
var setRtx = require('atom.io/transceivers/set-rtx');
|
|
7
|
+
|
|
8
|
+
// realtime/src/realtime-continuity.ts
|
|
9
|
+
var InvariantMap = class extends Map {
|
|
10
|
+
set(key, value) {
|
|
11
|
+
if (this.has(key)) {
|
|
12
|
+
console.warn(`Tried to set a key that already exists in an InvariantMap`, {
|
|
13
|
+
key,
|
|
14
|
+
value
|
|
15
|
+
});
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
return super.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
clear() {
|
|
21
|
+
throw new Error(`Cannot clear an InvariantMap`);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
var _SyncGroup = class _SyncGroup {
|
|
25
|
+
constructor(key) {
|
|
26
|
+
this.key = key;
|
|
27
|
+
this.type = `continuity`;
|
|
28
|
+
this.globals = [];
|
|
29
|
+
this.actions = [];
|
|
30
|
+
this.perspectives = [];
|
|
31
|
+
}
|
|
32
|
+
static create(key, builder) {
|
|
33
|
+
const group = new _SyncGroup(key);
|
|
34
|
+
const { type, globals, actions, perspectives } = builder(group);
|
|
35
|
+
const token = { type, key, globals, actions, perspectives };
|
|
36
|
+
_SyncGroup.existing.set(key, token);
|
|
37
|
+
return token;
|
|
38
|
+
}
|
|
39
|
+
add(...args) {
|
|
40
|
+
const zeroth = args[0];
|
|
41
|
+
if (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {
|
|
42
|
+
const globals = args;
|
|
43
|
+
for (const global of globals) {
|
|
44
|
+
switch (global.type) {
|
|
45
|
+
case `atom`:
|
|
46
|
+
this.globals.push(global);
|
|
47
|
+
break;
|
|
48
|
+
case `mutable_atom`:
|
|
49
|
+
this.globals.push(internal.getUpdateToken(global));
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
} else if (zeroth.type === `transaction`) {
|
|
54
|
+
const actions = args;
|
|
55
|
+
this.actions.push(...actions);
|
|
56
|
+
} else {
|
|
57
|
+
const [family, index] = args;
|
|
58
|
+
this.perspectives.push({
|
|
59
|
+
type: `realtime_perspective`,
|
|
60
|
+
resourceAtoms: family,
|
|
61
|
+
viewAtoms: index
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
_SyncGroup.existing = new InvariantMap();
|
|
68
|
+
var SyncGroup = _SyncGroup;
|
|
69
|
+
function continuity(options) {
|
|
70
|
+
const { key, config } = options;
|
|
71
|
+
const token = SyncGroup.create(key, config);
|
|
72
|
+
const { actions } = token;
|
|
73
|
+
for (const action of actions) {
|
|
74
|
+
internal.assignTransactionToContinuity(key, action.key, internal.IMPLICIT.STORE);
|
|
75
|
+
}
|
|
76
|
+
internal.setEpochNumberOfContinuity(key, -1, internal.IMPLICIT.STORE);
|
|
77
|
+
return token;
|
|
78
|
+
}
|
|
79
|
+
var usersInThisRoomIndex = atom_io.atom({
|
|
80
|
+
key: `usersInRoomIndex`,
|
|
81
|
+
mutable: true,
|
|
82
|
+
default: () => new setRtx.SetRTX(),
|
|
83
|
+
toJson: (set) => set.toJSON(),
|
|
84
|
+
fromJson: (json) => setRtx.SetRTX.fromJSON(json)
|
|
85
|
+
});
|
|
86
|
+
var roomIndex = atom_io.atom({
|
|
87
|
+
key: `roomIndex`,
|
|
88
|
+
default: () => new setRtx.SetRTX(),
|
|
89
|
+
mutable: true,
|
|
90
|
+
toJson: (set) => set.toJSON(),
|
|
91
|
+
fromJson: (json) => setRtx.SetRTX.fromJSON(json)
|
|
92
|
+
});
|
|
93
|
+
var DEFAULT_USER_IN_ROOM_META = {
|
|
94
|
+
enteredAtEpoch: 0
|
|
95
|
+
};
|
|
96
|
+
var usersInRooms = data.join(
|
|
97
|
+
{
|
|
98
|
+
key: `usersInRooms`,
|
|
99
|
+
between: [`room`, `user`],
|
|
100
|
+
cardinality: `1:n`
|
|
101
|
+
},
|
|
102
|
+
DEFAULT_USER_IN_ROOM_META
|
|
103
|
+
);
|
|
104
|
+
var usersInMyRoomView = atom_io.selectorFamily({
|
|
105
|
+
key: `usersInMyRoomView`,
|
|
106
|
+
get: (username) => ({ find }) => {
|
|
107
|
+
return [find(usersInRooms.core.findRelatedKeysState, username)];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
exports.DEFAULT_USER_IN_ROOM_META = DEFAULT_USER_IN_ROOM_META;
|
|
112
|
+
exports.InvariantMap = InvariantMap;
|
|
113
|
+
exports.SyncGroup = SyncGroup;
|
|
114
|
+
exports.continuity = continuity;
|
|
115
|
+
exports.roomIndex = roomIndex;
|
|
116
|
+
exports.usersInMyRoomView = usersInMyRoomView;
|
|
117
|
+
exports.usersInRooms = usersInRooms;
|
|
118
|
+
exports.usersInThisRoomIndex = usersInThisRoomIndex;
|
|
119
|
+
//# sourceMappingURL=out.js.map
|
|
120
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/realtime-continuity.ts","../src/shared-room-store.ts"],"names":[],"mappings":";AAOA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGA,IAAM,eAAN,cAAiC,IAAU;AAAA,EAC1C,IAAI,KAAQ,OAAgB;AAClC,QAAI,KAAK,IAAI,GAAG,GAAG;AAClB,cAAQ,KAAK,6DAA6D;AAAA,QACzE;AAAA,QACA;AAAA,MACD,CAAC;AACD,aAAO;AAAA,IACR;AACA,WAAO,MAAM,IAAI,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEO,QAAc;AACpB,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAC/C;AACD;AAsBO,IAAM,aAAN,MAA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AAO,KAAK,SAAS,KAAK;AAAA,EAC9D;AACA,6BAA2B,KAAK,IAAI,SAAS,KAAK;AAClD,SAAO;AACR;;;ACrIA,SAAS,MAAM,sBAAsB;AACrC,SAAS,YAAY;AAErB,SAAS,cAAc;AAEhB,IAAM,uBAAuB,KAAyC;AAAA,EAC5E,KAAK;AAAA,EACL,SAAS;AAAA,EACT,SAAS,MAAM,IAAI,OAAe;AAAA,EAClC,QAAQ,CAAC,QAAQ,IAAI,OAAO;AAAA,EAC5B,UAAU,CAAC,SAAS,OAAO,SAAS,IAAI;AACzC,CAAC;AAEM,IAAM,YAAY,KAAK;AAAA,EAC7B,KAAK;AAAA,EACL,SAAS,MAAM,IAAI,OAAe;AAAA,EAClC,SAAS;AAAA,EACT,QAAQ,CAAC,QAAQ,IAAI,OAAO;AAAA,EAC5B,UAAU,CAAC,SAAS,OAAO,SAAS,IAAI;AACzC,CAAC;AAKM,IAAM,4BAA4C;AAAA,EACxD,gBAAgB;AACjB;AACO,IAAM,eAAe;AAAA,EAC3B;AAAA,IACC,KAAK;AAAA,IACL,SAAS,CAAC,QAAQ,MAAM;AAAA,IACxB,aAAa;AAAA,EACd;AAAA,EACA;AACD;AAEO,IAAM,oBAAoB,eAG/B;AAAA,EACD,KAAK;AAAA,EACL,KACC,CAAC,aACD,CAAC,EAAE,KAAK,MAAM;AACb,WAAO,CAAC,KAAK,aAAa,KAAK,sBAAsB,QAAQ,CAAC;AAAA,EAC/D;AACF,CAAC","sourcesContent":["import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tTransactionToken,\n} from \"atom.io\"\nimport {\n\tIMPLICIT,\n\tassignTransactionToContinuity,\n\tgetUpdateToken,\n\tsetEpochNumberOfContinuity,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport class InvariantMap<K, V> extends Map<K, V> {\n\tpublic set(key: K, value: V): this {\n\t\tif (this.has(key)) {\n\t\t\tconsole.warn(`Tried to set a key that already exists in an InvariantMap`, {\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t})\n\t\t\treturn this\n\t\t}\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic clear(): void {\n\t\tthrow new Error(`Cannot clear an InvariantMap`)\n\t}\n}\n\nexport type PerspectiveToken<\n\tF extends AtomFamilyToken<any>,\n\tT extends F extends AtomFamilyToken<infer T, any> ? T : never,\n> = {\n\ttype: `realtime_perspective`\n\tresourceAtoms: F\n\tviewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>\n}\n\nexport type ContinuityToken = {\n\treadonly type: `continuity`\n\treadonly key: string\n\treadonly globals: AtomToken<any>[]\n\treadonly actions: TransactionToken<any>[]\n\treadonly perspectives: PerspectiveToken<\n\t\tAtomFamilyToken<any, Json.Serializable>,\n\t\tJson.Serializable\n\t>[]\n}\n\nexport class SyncGroup {\n\tprotected type = `continuity` as const\n\n\tprotected globals: AtomToken<any>[] = []\n\tprotected actions: TransactionToken<any>[] = []\n\tprotected perspectives: PerspectiveToken<any, any>[] = []\n\n\tprotected constructor(protected readonly key: string) {}\n\n\tpublic static existing: InvariantMap<string, ContinuityToken> =\n\t\tnew InvariantMap()\n\tpublic static create(\n\t\tkey: string,\n\t\tbuilder: (group: SyncGroup) => SyncGroup,\n\t): ContinuityToken {\n\t\tconst group = new SyncGroup(key)\n\t\tconst { type, globals, actions, perspectives } = builder(group)\n\t\tconst token = { type, key, globals, actions, perspectives }\n\t\tSyncGroup.existing.set(key, token)\n\t\treturn token\n\t}\n\n\tpublic add(...atoms: AtomToken<any>[]): SyncGroup\n\tpublic add(...args: TransactionToken<any>[]): SyncGroup\n\tpublic add<\n\t\tF extends AtomFamilyToken<any>,\n\t\tT extends F extends AtomFamilyToken<infer T> ? T : never,\n\t>(\n\t\tfamily: AtomFamilyToken<T, any>,\n\t\tindex: ReadableFamilyToken<Iterable<AtomToken<T>>, string>,\n\t): SyncGroup\n\tpublic add(\n\t\t...args:\n\t\t\t| readonly AtomToken<any>[]\n\t\t\t| readonly TransactionToken<any>[]\n\t\t\t| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]\n\t): SyncGroup {\n\t\tconst zeroth = args[0]\n\t\tif (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {\n\t\t\tconst globals = args as AtomToken<any>[]\n\t\t\tfor (const global of globals) {\n\t\t\t\tswitch (global.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\t\tthis.globals.push(global)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\tthis.globals.push(getUpdateToken(global))\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (zeroth.type === `transaction`) {\n\t\t\tconst actions = args as TransactionToken<any>[]\n\t\t\tthis.actions.push(...actions)\n\t\t} else {\n\t\t\tconst [family, index] = args as [\n\t\t\t\tAtomFamilyToken<any, any>,\n\t\t\t\tReadableFamilyToken<ReadableToken<any>[], string>,\n\t\t\t]\n\t\t\tthis.perspectives.push({\n\t\t\t\ttype: `realtime_perspective`,\n\t\t\t\tresourceAtoms: family,\n\t\t\t\tviewAtoms: index,\n\t\t\t})\n\t\t}\n\t\treturn this\n\t}\n}\n\nexport type ContinuityOptions = {\n\tkey: string\n\tconfig: (group: SyncGroup) => SyncGroup\n}\n\nexport function continuity(options: ContinuityOptions): ContinuityToken {\n\tconst { key, config } = options\n\tconst token = SyncGroup.create(key, config)\n\tconst { actions } = token\n\tfor (const action of actions) {\n\t\tassignTransactionToContinuity(key, action.key, IMPLICIT.STORE)\n\t}\n\tsetEpochNumberOfContinuity(key, -1, IMPLICIT.STORE)\n\treturn token\n}\n\n// const counterStates = atomFamily<number, { c: string }>({\n// \tkey: `counter`,\n// \tdefault: 0,\n// })\n// const counterIndices = atomFamily<{ c: string }[], string>({\n// \tkey: `counterIndex`,\n// \tdefault: [],\n// })\n// const nameStates = atomFamily<number, { n: string }>({\n// \tkey: `name`,\n// \tdefault: 0,\n// })\n// const nameIndices = atomFamily<{ n: string }[], string>({\n// \tkey: `nameIndex`,\n// \tdefault: [],\n// })\n\n// const counterContinuity = continuity({\n// \tkey: `counter`,\n// \tconfig: (group) =>\n// \t\tgroup\n// \t\t\t.add(counterStates, counterIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices),\n// })\n","import type { MutableAtomToken } from \"atom.io\"\nimport { atom, selectorFamily } from \"atom.io\"\nimport { join } from \"atom.io/data\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nexport const usersInThisRoomIndex = atom<SetRTX<string>, SetRTXJson<string>>({\n\tkey: `usersInRoomIndex`,\n\tmutable: true,\n\tdefault: () => new SetRTX<string>(),\n\ttoJson: (set) => set.toJSON(),\n\tfromJson: (json) => SetRTX.fromJSON(json),\n})\n\nexport const roomIndex = atom({\n\tkey: `roomIndex`,\n\tdefault: () => new SetRTX<string>(),\n\tmutable: true,\n\ttoJson: (set) => set.toJSON(),\n\tfromJson: (json) => SetRTX.fromJSON(json),\n})\n\nexport type UserInRoomMeta = {\n\tenteredAtEpoch: number\n}\nexport const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta = {\n\tenteredAtEpoch: 0,\n}\nexport const usersInRooms = join(\n\t{\n\t\tkey: `usersInRooms`,\n\t\tbetween: [`room`, `user`],\n\t\tcardinality: `1:n`,\n\t},\n\tDEFAULT_USER_IN_ROOM_META,\n)\n\nexport const usersInMyRoomView = selectorFamily<\n\tMutableAtomToken<SetRTX<string>, SetRTXJson<string>>[],\n\tstring\n>({\n\tkey: `usersInMyRoomView`,\n\tget:\n\t\t(username) =>\n\t\t({ find }) => {\n\t\t\treturn [find(usersInRooms.core.findRelatedKeysState, username)]\n\t\t},\n})\n"]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as atom_io from 'atom.io';
|
|
2
|
+
import { AtomFamilyToken, ReadableFamilyToken, ReadableToken, AtomToken, TransactionToken, MutableAtomToken } from 'atom.io';
|
|
3
|
+
import { Json } from 'atom.io/json';
|
|
4
|
+
import * as atom_io_data from 'atom.io/data';
|
|
5
|
+
import * as atom_io_internal from 'atom.io/internal';
|
|
6
|
+
import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
|
|
7
|
+
|
|
8
|
+
declare class InvariantMap<K, V> extends Map<K, V> {
|
|
9
|
+
set(key: K, value: V): this;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
|
12
|
+
type PerspectiveToken<F extends AtomFamilyToken<any>, T extends F extends AtomFamilyToken<infer T, any> ? T : never> = {
|
|
13
|
+
type: `realtime_perspective`;
|
|
14
|
+
resourceAtoms: F;
|
|
15
|
+
viewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>;
|
|
16
|
+
};
|
|
17
|
+
type ContinuityToken = {
|
|
18
|
+
readonly type: `continuity`;
|
|
19
|
+
readonly key: string;
|
|
20
|
+
readonly globals: AtomToken<any>[];
|
|
21
|
+
readonly actions: TransactionToken<any>[];
|
|
22
|
+
readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Json.Serializable>, Json.Serializable>[];
|
|
23
|
+
};
|
|
24
|
+
declare class SyncGroup {
|
|
25
|
+
protected readonly key: string;
|
|
26
|
+
protected type: "continuity";
|
|
27
|
+
protected globals: AtomToken<any>[];
|
|
28
|
+
protected actions: TransactionToken<any>[];
|
|
29
|
+
protected perspectives: PerspectiveToken<any, any>[];
|
|
30
|
+
protected constructor(key: string);
|
|
31
|
+
static existing: InvariantMap<string, ContinuityToken>;
|
|
32
|
+
static create(key: string, builder: (group: SyncGroup) => SyncGroup): ContinuityToken;
|
|
33
|
+
add(...atoms: AtomToken<any>[]): SyncGroup;
|
|
34
|
+
add(...args: TransactionToken<any>[]): SyncGroup;
|
|
35
|
+
add<F extends AtomFamilyToken<any>, T extends F extends AtomFamilyToken<infer T> ? T : never>(family: AtomFamilyToken<T, any>, index: ReadableFamilyToken<Iterable<AtomToken<T>>, string>): SyncGroup;
|
|
36
|
+
}
|
|
37
|
+
type ContinuityOptions = {
|
|
38
|
+
key: string;
|
|
39
|
+
config: (group: SyncGroup) => SyncGroup;
|
|
40
|
+
};
|
|
41
|
+
declare function continuity(options: ContinuityOptions): ContinuityToken;
|
|
42
|
+
|
|
43
|
+
type primitive = boolean | number | string | null;
|
|
44
|
+
|
|
45
|
+
type Serializable = primitive | Readonly<{
|
|
46
|
+
[key: string]: Serializable;
|
|
47
|
+
}> | ReadonlyArray<Serializable>;
|
|
48
|
+
type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
49
|
+
|
|
50
|
+
type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
|
|
51
|
+
type Cardinality = `1:1` | `1:n` | `n:n`;
|
|
52
|
+
|
|
53
|
+
interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
|
|
54
|
+
readonly relations: [string, string[]][];
|
|
55
|
+
readonly contents: [string, Content][];
|
|
56
|
+
}
|
|
57
|
+
interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
|
|
58
|
+
readonly between: [a: ASide, b: BSide];
|
|
59
|
+
readonly cardinality: Cardinality;
|
|
60
|
+
}
|
|
61
|
+
type BaseExternalStoreConfiguration = {
|
|
62
|
+
addRelation: (a: string, b: string) => void;
|
|
63
|
+
deleteRelation: (a: string, b: string) => void;
|
|
64
|
+
replaceRelationsSafely: (a: string, bs: string[]) => void;
|
|
65
|
+
replaceRelationsUnsafely: (a: string, bs: string[]) => void;
|
|
66
|
+
getRelatedKeys: (key: string) => Set<string> | undefined;
|
|
67
|
+
has: (a: string, b?: string) => boolean;
|
|
68
|
+
};
|
|
69
|
+
type ExternalStoreWithContentConfiguration<Content extends Object$1> = {
|
|
70
|
+
getContent: (contentKey: string) => Content | undefined;
|
|
71
|
+
setContent: (contentKey: string, content: Content) => void;
|
|
72
|
+
deleteContent: (contentKey: string) => void;
|
|
73
|
+
};
|
|
74
|
+
type Empty<Obj extends object> = {
|
|
75
|
+
[Key in keyof Obj]?: undefined;
|
|
76
|
+
};
|
|
77
|
+
type ExternalStoreConfiguration<Content extends Object$1 | null> = Content extends Object$1 ? BaseExternalStoreConfiguration & ExternalStoreWithContentConfiguration<Content> : BaseExternalStoreConfiguration & Empty<ExternalStoreWithContentConfiguration<Object$1>>;
|
|
78
|
+
type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
|
|
79
|
+
externalStore?: ExternalStoreConfiguration<Content>;
|
|
80
|
+
isContent?: Refinement<unknown, Content>;
|
|
81
|
+
makeContentKey?: (a: string, b: string) => string;
|
|
82
|
+
};
|
|
83
|
+
type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
|
|
84
|
+
declare class Junction<const ASide extends string, const BSide extends string, const Content extends Object$1 | null = null> {
|
|
85
|
+
readonly a: ASide;
|
|
86
|
+
readonly b: BSide;
|
|
87
|
+
readonly cardinality: Cardinality;
|
|
88
|
+
readonly relations: Map<string, Set<string>>;
|
|
89
|
+
readonly contents: Map<string, Content>;
|
|
90
|
+
isContent: Refinement<unknown, Content> | null;
|
|
91
|
+
makeContentKey: (a: string, b: string) => string;
|
|
92
|
+
getRelatedKeys(key: string): Set<string> | undefined;
|
|
93
|
+
protected addRelation(a: string, b: string): void;
|
|
94
|
+
protected deleteRelation(a: string, b: string): void;
|
|
95
|
+
protected replaceRelationsUnsafely(a: string, bs: string[]): void;
|
|
96
|
+
protected replaceRelationsSafely(a: string, bs: string[]): void;
|
|
97
|
+
protected getContentInternal(contentKey: string): Content | undefined;
|
|
98
|
+
protected setContent(contentKey: string, content: Content): void;
|
|
99
|
+
protected deleteContent(contentKey: string): void;
|
|
100
|
+
constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
|
|
101
|
+
toJSON(): JunctionJSON<ASide, BSide, Content>;
|
|
102
|
+
set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
|
|
103
|
+
set(relation: {
|
|
104
|
+
[Key in ASide | BSide]: string;
|
|
105
|
+
}, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
|
|
106
|
+
delete(a: string, b?: string): this;
|
|
107
|
+
delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
|
|
108
|
+
getRelatedKey(key: string): string | undefined;
|
|
109
|
+
replaceRelations(a: string, relations: Content extends null ? string[] : Record<string, Content>, config?: {
|
|
110
|
+
reckless: boolean;
|
|
111
|
+
}): this;
|
|
112
|
+
getContent(a: string, b: string): Content | undefined;
|
|
113
|
+
getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
|
|
114
|
+
has(a: string, b?: string): boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
declare const usersInThisRoomIndex: MutableAtomToken<SetRTX<string>, SetRTXJson<string>>;
|
|
118
|
+
declare const roomIndex: MutableAtomToken<SetRTX<string>, SetRTXJson<string>>;
|
|
119
|
+
type UserInRoomMeta = {
|
|
120
|
+
enteredAtEpoch: number;
|
|
121
|
+
};
|
|
122
|
+
declare const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta;
|
|
123
|
+
declare const usersInRooms: {
|
|
124
|
+
readonly relations: Junction<"room", "user", UserInRoomMeta>;
|
|
125
|
+
readonly states: {
|
|
126
|
+
readonly roomEntryOfUser: atom_io.ReadonlySelectorFamily<[string, UserInRoomMeta] | null, string>;
|
|
127
|
+
} & {
|
|
128
|
+
readonly userEntriesOfRoom: atom_io.ReadonlySelectorFamily<[string, UserInRoomMeta][], string>;
|
|
129
|
+
} & {
|
|
130
|
+
readonly roomKeyOfUser: atom_io.ReadonlySelectorFamily<string | null, string>;
|
|
131
|
+
} & {
|
|
132
|
+
readonly userKeysOfRoom: atom_io.ReadonlySelectorFamily<string[], string>;
|
|
133
|
+
};
|
|
134
|
+
readonly in: (store: atom_io_internal.Store) => atom_io_data.Join<"room", "user", "1:n", UserInRoomMeta>;
|
|
135
|
+
readonly transact: (transactors: Readonly<{
|
|
136
|
+
get: <S>(state: atom_io.ReadonlySelectorToken<S> | atom_io.WritableToken<S>) => S;
|
|
137
|
+
set: <S_1, New extends S_1>(state: atom_io.WritableToken<S_1>, newValue: New | ((oldValue: S_1) => New)) => void;
|
|
138
|
+
find: typeof atom_io.findState;
|
|
139
|
+
}>, run: (join: atom_io_data.Join<"room", "user", "1:n", UserInRoomMeta>) => void) => void;
|
|
140
|
+
readonly core: {
|
|
141
|
+
readonly findRelatedKeysState: atom_io.MutableAtomFamily<SetRTX<string>, SetRTXJson<string>, string>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
declare const usersInMyRoomView: atom_io.ReadonlySelectorFamilyTokenWithCall<MutableAtomToken<SetRTX<string>, SetRTXJson<string>>[], string>;
|
|
145
|
+
|
|
146
|
+
export { type ContinuityOptions, type ContinuityToken, DEFAULT_USER_IN_ROOM_META, InvariantMap, type PerspectiveToken, SyncGroup, type UserInRoomMeta, continuity, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import '../../dist/chunk-PZLG2HP3.js';
|
|
2
|
+
import { assignTransactionToContinuity, IMPLICIT, setEpochNumberOfContinuity, getUpdateToken } from 'atom.io/internal';
|
|
3
|
+
import { atom, selectorFamily } from 'atom.io';
|
|
4
|
+
import { join } from 'atom.io/data';
|
|
5
|
+
import { SetRTX } from 'atom.io/transceivers/set-rtx';
|
|
6
|
+
|
|
7
|
+
var InvariantMap = class extends Map {
|
|
8
|
+
set(key, value) {
|
|
9
|
+
if (this.has(key)) {
|
|
10
|
+
console.warn(`Tried to set a key that already exists in an InvariantMap`, {
|
|
11
|
+
key,
|
|
12
|
+
value
|
|
13
|
+
});
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
return super.set(key, value);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
throw new Error(`Cannot clear an InvariantMap`);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var _SyncGroup = class _SyncGroup {
|
|
23
|
+
constructor(key) {
|
|
24
|
+
this.key = key;
|
|
25
|
+
this.type = `continuity`;
|
|
26
|
+
this.globals = [];
|
|
27
|
+
this.actions = [];
|
|
28
|
+
this.perspectives = [];
|
|
29
|
+
}
|
|
30
|
+
static create(key, builder) {
|
|
31
|
+
const group = new _SyncGroup(key);
|
|
32
|
+
const { type, globals, actions, perspectives } = builder(group);
|
|
33
|
+
const token = { type, key, globals, actions, perspectives };
|
|
34
|
+
_SyncGroup.existing.set(key, token);
|
|
35
|
+
return token;
|
|
36
|
+
}
|
|
37
|
+
add(...args) {
|
|
38
|
+
const zeroth = args[0];
|
|
39
|
+
if (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {
|
|
40
|
+
const globals = args;
|
|
41
|
+
for (const global of globals) {
|
|
42
|
+
switch (global.type) {
|
|
43
|
+
case `atom`:
|
|
44
|
+
this.globals.push(global);
|
|
45
|
+
break;
|
|
46
|
+
case `mutable_atom`:
|
|
47
|
+
this.globals.push(getUpdateToken(global));
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else if (zeroth.type === `transaction`) {
|
|
52
|
+
const actions = args;
|
|
53
|
+
this.actions.push(...actions);
|
|
54
|
+
} else {
|
|
55
|
+
const [family, index] = args;
|
|
56
|
+
this.perspectives.push({
|
|
57
|
+
type: `realtime_perspective`,
|
|
58
|
+
resourceAtoms: family,
|
|
59
|
+
viewAtoms: index
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
_SyncGroup.existing = new InvariantMap();
|
|
66
|
+
var SyncGroup = _SyncGroup;
|
|
67
|
+
function continuity(options) {
|
|
68
|
+
const { key, config } = options;
|
|
69
|
+
const token = SyncGroup.create(key, config);
|
|
70
|
+
const { actions } = token;
|
|
71
|
+
for (const action of actions) {
|
|
72
|
+
assignTransactionToContinuity(key, action.key, IMPLICIT.STORE);
|
|
73
|
+
}
|
|
74
|
+
setEpochNumberOfContinuity(key, -1, IMPLICIT.STORE);
|
|
75
|
+
return token;
|
|
76
|
+
}
|
|
77
|
+
var usersInThisRoomIndex = atom({
|
|
78
|
+
key: `usersInRoomIndex`,
|
|
79
|
+
mutable: true,
|
|
80
|
+
default: () => new SetRTX(),
|
|
81
|
+
toJson: (set) => set.toJSON(),
|
|
82
|
+
fromJson: (json) => SetRTX.fromJSON(json)
|
|
83
|
+
});
|
|
84
|
+
var roomIndex = atom({
|
|
85
|
+
key: `roomIndex`,
|
|
86
|
+
default: () => new SetRTX(),
|
|
87
|
+
mutable: true,
|
|
88
|
+
toJson: (set) => set.toJSON(),
|
|
89
|
+
fromJson: (json) => SetRTX.fromJSON(json)
|
|
90
|
+
});
|
|
91
|
+
var DEFAULT_USER_IN_ROOM_META = {
|
|
92
|
+
enteredAtEpoch: 0
|
|
93
|
+
};
|
|
94
|
+
var usersInRooms = join(
|
|
95
|
+
{
|
|
96
|
+
key: `usersInRooms`,
|
|
97
|
+
between: [`room`, `user`],
|
|
98
|
+
cardinality: `1:n`
|
|
99
|
+
},
|
|
100
|
+
DEFAULT_USER_IN_ROOM_META
|
|
101
|
+
);
|
|
102
|
+
var usersInMyRoomView = selectorFamily({
|
|
103
|
+
key: `usersInMyRoomView`,
|
|
104
|
+
get: (username) => ({ find }) => {
|
|
105
|
+
return [find(usersInRooms.core.findRelatedKeysState, username)];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
|
|
110
|
+
//# sourceMappingURL=out.js.map
|
|
111
|
+
//# sourceMappingURL=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;AAEO,IAAM,oBAAoB,eAG/B;AAAA,EACD,KAAK;AAAA,EACL,KACC,CAAC,aACD,CAAC,EAAE,KAAK,MAAM;AACb,WAAO,CAAC,KAAK,aAAa,KAAK,sBAAsB,QAAQ,CAAC;AAAA,EAC/D;AACF,CAAC","sourcesContent":["import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tTransactionToken,\n} from \"atom.io\"\nimport {\n\tIMPLICIT,\n\tassignTransactionToContinuity,\n\tgetUpdateToken,\n\tsetEpochNumberOfContinuity,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport class InvariantMap<K, V> extends Map<K, V> {\n\tpublic set(key: K, value: V): this {\n\t\tif (this.has(key)) {\n\t\t\tconsole.warn(`Tried to set a key that already exists in an InvariantMap`, {\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t})\n\t\t\treturn this\n\t\t}\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic clear(): void {\n\t\tthrow new Error(`Cannot clear an InvariantMap`)\n\t}\n}\n\nexport type PerspectiveToken<\n\tF extends AtomFamilyToken<any>,\n\tT extends F extends AtomFamilyToken<infer T, any> ? T : never,\n> = {\n\ttype: `realtime_perspective`\n\tresourceAtoms: F\n\tviewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>\n}\n\nexport type ContinuityToken = {\n\treadonly type: `continuity`\n\treadonly key: string\n\treadonly globals: AtomToken<any>[]\n\treadonly actions: TransactionToken<any>[]\n\treadonly perspectives: PerspectiveToken<\n\t\tAtomFamilyToken<any, Json.Serializable>,\n\t\tJson.Serializable\n\t>[]\n}\n\nexport class SyncGroup {\n\tprotected type = `continuity` as const\n\n\tprotected globals: AtomToken<any>[] = []\n\tprotected actions: TransactionToken<any>[] = []\n\tprotected perspectives: PerspectiveToken<any, any>[] = []\n\n\tprotected constructor(protected readonly key: string) {}\n\n\tpublic static existing: InvariantMap<string, ContinuityToken> =\n\t\tnew InvariantMap()\n\tpublic static create(\n\t\tkey: string,\n\t\tbuilder: (group: SyncGroup) => SyncGroup,\n\t): ContinuityToken {\n\t\tconst group = new SyncGroup(key)\n\t\tconst { type, globals, actions, perspectives } = builder(group)\n\t\tconst token = { type, key, globals, actions, perspectives }\n\t\tSyncGroup.existing.set(key, token)\n\t\treturn token\n\t}\n\n\tpublic add(...atoms: AtomToken<any>[]): SyncGroup\n\tpublic add(...args: TransactionToken<any>[]): SyncGroup\n\tpublic add<\n\t\tF extends AtomFamilyToken<any>,\n\t\tT extends F extends AtomFamilyToken<infer T> ? T : never,\n\t>(\n\t\tfamily: AtomFamilyToken<T, any>,\n\t\tindex: ReadableFamilyToken<Iterable<AtomToken<T>>, string>,\n\t): SyncGroup\n\tpublic add(\n\t\t...args:\n\t\t\t| readonly AtomToken<any>[]\n\t\t\t| readonly TransactionToken<any>[]\n\t\t\t| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]\n\t): SyncGroup {\n\t\tconst zeroth = args[0]\n\t\tif (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {\n\t\t\tconst globals = args as AtomToken<any>[]\n\t\t\tfor (const global of globals) {\n\t\t\t\tswitch (global.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\t\tthis.globals.push(global)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\tthis.globals.push(getUpdateToken(global))\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (zeroth.type === `transaction`) {\n\t\t\tconst actions = args as TransactionToken<any>[]\n\t\t\tthis.actions.push(...actions)\n\t\t} else {\n\t\t\tconst [family, index] = args as [\n\t\t\t\tAtomFamilyToken<any, any>,\n\t\t\t\tReadableFamilyToken<ReadableToken<any>[], string>,\n\t\t\t]\n\t\t\tthis.perspectives.push({\n\t\t\t\ttype: `realtime_perspective`,\n\t\t\t\tresourceAtoms: family,\n\t\t\t\tviewAtoms: index,\n\t\t\t})\n\t\t}\n\t\treturn this\n\t}\n}\n\nexport type ContinuityOptions = {\n\tkey: string\n\tconfig: (group: SyncGroup) => SyncGroup\n}\n\nexport function continuity(options: ContinuityOptions): ContinuityToken {\n\tconst { key, config } = options\n\tconst token = SyncGroup.create(key, config)\n\tconst { actions } = token\n\tfor (const action of actions) {\n\t\tassignTransactionToContinuity(key, action.key, IMPLICIT.STORE)\n\t}\n\tsetEpochNumberOfContinuity(key, -1, IMPLICIT.STORE)\n\treturn token\n}\n\n// const counterStates = atomFamily<number, { c: string }>({\n// \tkey: `counter`,\n// \tdefault: 0,\n// })\n// const counterIndices = atomFamily<{ c: string }[], string>({\n// \tkey: `counterIndex`,\n// \tdefault: [],\n// })\n// const nameStates = atomFamily<number, { n: string }>({\n// \tkey: `name`,\n// \tdefault: 0,\n// })\n// const nameIndices = atomFamily<{ n: string }[], string>({\n// \tkey: `nameIndex`,\n// \tdefault: [],\n// })\n\n// const counterContinuity = continuity({\n// \tkey: `counter`,\n// \tconfig: (group) =>\n// \t\tgroup\n// \t\t\t.add(counterStates, counterIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices),\n// })\n","import type { MutableAtomToken } from \"atom.io\"\nimport { atom, selectorFamily } from \"atom.io\"\nimport { join } from \"atom.io/data\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nexport const usersInThisRoomIndex = atom<SetRTX<string>, SetRTXJson<string>>({\n\tkey: `usersInRoomIndex`,\n\tmutable: true,\n\tdefault: () => new SetRTX<string>(),\n\ttoJson: (set) => set.toJSON(),\n\tfromJson: (json) => SetRTX.fromJSON(json),\n})\n\nexport const roomIndex = atom({\n\tkey: `roomIndex`,\n\tdefault: () => new SetRTX<string>(),\n\tmutable: true,\n\ttoJson: (set) => set.toJSON(),\n\tfromJson: (json) => SetRTX.fromJSON(json),\n})\n\nexport type UserInRoomMeta = {\n\tenteredAtEpoch: number\n}\nexport const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta = {\n\tenteredAtEpoch: 0,\n}\nexport const usersInRooms = join(\n\t{\n\t\tkey: `usersInRooms`,\n\t\tbetween: [`room`, `user`],\n\t\tcardinality: `1:n`,\n\t},\n\tDEFAULT_USER_IN_ROOM_META,\n)\n\nexport const usersInMyRoomView = selectorFamily<\n\tMutableAtomToken<SetRTX<string>, SetRTXJson<string>>[],\n\tstring\n>({\n\tkey: `usersInMyRoomView`,\n\tget:\n\t\t(username) =>\n\t\t({ find }) => {\n\t\t\treturn [find(usersInRooms.core.findRelatedKeysState, username)]\n\t\t},\n})\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "atom.io-realtime",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"browser": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|