atom.io 0.31.1 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.d.ts +867 -101
- package/data/dist/index.js +10 -558
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +622 -26
- package/dist/index.js +1 -228
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +783 -64
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +2 -0
- package/internal/src/install-into-store.ts +1 -1
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/pretty-print.ts +1 -1
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +6 -9
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +22 -22
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +17 -37
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -80
- package/json/src/select-json-family.ts +3 -14
- package/package.json +24 -42
- package/react/dist/index.d.ts +921 -3
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.d.ts +166 -12
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +971 -28
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +20 -22
- package/realtime-testing/src/setup-realtime-test.tsx +2 -1
- package/src/index.ts +4 -0
- package/src/join.ts +218 -0
- package/src/silo.ts +4 -4
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -215
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/ephemeral/dist/index.d.ts +0 -67
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- /package/{ephemeral/src → src}/find-state.ts +0 -0
|
@@ -1,15 +1,13 @@
|
|
|
1
|
+
import { RealtimeProvider } from '../../dist/chunk-354XQWHH.js';
|
|
2
|
+
import { myUsernameState } from '../../dist/chunk-Z2UJW4NQ.js';
|
|
3
|
+
import { socketAtoms, usersOfSockets, userIndex, socketIndex, roomSelectors } from '../../dist/chunk-R3ZUK5EH.js';
|
|
4
|
+
import { roomIndex } from '../../dist/chunk-NF7FJKJD.js';
|
|
5
|
+
import '../../dist/chunk-4LWKCEW3.js';
|
|
6
|
+
import { StoreProvider } from '../../dist/chunk-5F2V7S3B.js';
|
|
7
|
+
import { Silo, IMPLICIT, Realm, findInStore, setIntoStore, editRelationsInStore, toEntries, findRelationsInStore, getFromStore, AtomIOLogger, clearStore } from '../../dist/chunk-GY2XQYZY.js';
|
|
1
8
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
2
9
|
import * as http from 'node:http';
|
|
3
10
|
import { render, prettyDOM } from '@testing-library/react';
|
|
4
|
-
import * as AtomIO from 'atom.io';
|
|
5
|
-
import { editRelationsInStore, findRelationsInStore } from 'atom.io/data';
|
|
6
|
-
import { IMPLICIT, findInStore, setIntoStore, getFromStore, clearStore } from 'atom.io/internal';
|
|
7
|
-
import { toEntries } from 'atom.io/json';
|
|
8
|
-
import * as AR from 'atom.io/react';
|
|
9
|
-
import * as RT from 'atom.io/realtime';
|
|
10
|
-
import * as RTC from 'atom.io/realtime-client';
|
|
11
|
-
import * as RTR from 'atom.io/realtime-react';
|
|
12
|
-
import * as RTS from 'atom.io/realtime-server';
|
|
13
11
|
import * as Happy from 'happy-dom';
|
|
14
12
|
import * as SocketIO from 'socket.io';
|
|
15
13
|
import { io } from 'socket.io-client';
|
|
@@ -17,7 +15,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
17
15
|
|
|
18
16
|
var testNumber = 0;
|
|
19
17
|
function prefixLogger(store, prefix) {
|
|
20
|
-
store.loggers[0] = new
|
|
18
|
+
store.loggers[0] = new AtomIOLogger(`info`, undefined, {
|
|
21
19
|
info: (...args) => {
|
|
22
20
|
console.info(prefix, ...args);
|
|
23
21
|
},
|
|
@@ -31,14 +29,14 @@ function prefixLogger(store, prefix) {
|
|
|
31
29
|
}
|
|
32
30
|
var setupRealtimeTestServer = (options) => {
|
|
33
31
|
++testNumber;
|
|
34
|
-
const silo = new
|
|
32
|
+
const silo = new Silo(
|
|
35
33
|
{
|
|
36
34
|
name: `SERVER-${testNumber}`,
|
|
37
35
|
lifespan: options.immortal?.server ? `immortal` : `ephemeral`
|
|
38
36
|
},
|
|
39
37
|
IMPLICIT.STORE
|
|
40
38
|
);
|
|
41
|
-
const socketRealm = new
|
|
39
|
+
const socketRealm = new Realm(silo.store);
|
|
42
40
|
const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
|
|
43
41
|
const address = httpServer.listen(options.port).address();
|
|
44
42
|
const port = typeof address === `string` ? null : address === null ? null : address.port;
|
|
@@ -48,19 +46,19 @@ var setupRealtimeTestServer = (options) => {
|
|
|
48
46
|
if (token === `test` && socket.id) {
|
|
49
47
|
const userClaim = socketRealm.allocate(`root`, `user::${username}`);
|
|
50
48
|
const socketClaim = socketRealm.allocate(`root`, `socket::${socket.id}`);
|
|
51
|
-
const socketState = findInStore(silo.store,
|
|
49
|
+
const socketState = findInStore(silo.store, socketAtoms, socketClaim);
|
|
52
50
|
setIntoStore(silo.store, socketState, socket);
|
|
53
51
|
editRelationsInStore(
|
|
54
|
-
|
|
52
|
+
usersOfSockets,
|
|
55
53
|
(relations) => {
|
|
56
54
|
relations.set(userClaim, socketClaim);
|
|
57
55
|
},
|
|
58
56
|
silo.store
|
|
59
57
|
);
|
|
60
|
-
setIntoStore(silo.store,
|
|
58
|
+
setIntoStore(silo.store, userIndex, (index) => index.add(userClaim));
|
|
61
59
|
setIntoStore(
|
|
62
60
|
silo.store,
|
|
63
|
-
|
|
61
|
+
socketIndex,
|
|
64
62
|
(index) => index.add(socketClaim)
|
|
65
63
|
);
|
|
66
64
|
next();
|
|
@@ -72,7 +70,7 @@ var setupRealtimeTestServer = (options) => {
|
|
|
72
70
|
let userKey = null;
|
|
73
71
|
function enableLogging() {
|
|
74
72
|
const userKeyState = findRelationsInStore(
|
|
75
|
-
|
|
73
|
+
usersOfSockets,
|
|
76
74
|
`socket::${socket.id}`,
|
|
77
75
|
silo.store
|
|
78
76
|
).userKeyOfSocket;
|
|
@@ -92,9 +90,9 @@ var setupRealtimeTestServer = (options) => {
|
|
|
92
90
|
});
|
|
93
91
|
const dispose = async () => {
|
|
94
92
|
await server.close();
|
|
95
|
-
const roomKeys = getFromStore(silo.store,
|
|
93
|
+
const roomKeys = getFromStore(silo.store, roomIndex);
|
|
96
94
|
for (const roomKey of roomKeys) {
|
|
97
|
-
const roomState = findInStore(silo.store,
|
|
95
|
+
const roomState = findInStore(silo.store, roomSelectors, roomKey);
|
|
98
96
|
const room = getFromStore(silo.store, roomState);
|
|
99
97
|
if (room && !(room instanceof Promise)) {
|
|
100
98
|
room.process.kill();
|
|
@@ -116,17 +114,17 @@ var setupRealtimeTestClient = (options, name, port) => {
|
|
|
116
114
|
const socket = io(`http://localhost:${port}/`, {
|
|
117
115
|
auth: { token: `test`, username: `${name}-${testNumber}` }
|
|
118
116
|
});
|
|
119
|
-
const silo = new
|
|
117
|
+
const silo = new Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE);
|
|
120
118
|
for (const [key, value] of silo.store.valueMap.entries()) {
|
|
121
119
|
if (Array.isArray(value)) {
|
|
122
120
|
silo.store.valueMap.set(key, [...value]);
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
|
-
silo.setState(
|
|
123
|
+
silo.setState(myUsernameState, `${name}-${testNumber}`);
|
|
126
124
|
const { document } = new Happy.Window();
|
|
127
125
|
document.body.innerHTML = `<div id="app"></div>`;
|
|
128
126
|
const renderResult = render(
|
|
129
|
-
/* @__PURE__ */ jsx(
|
|
127
|
+
/* @__PURE__ */ jsx(StoreProvider, { store: silo.store, children: /* @__PURE__ */ jsx(RealtimeProvider, { socket, children: /* @__PURE__ */ jsx(options.client, {}) }) }),
|
|
130
128
|
{
|
|
131
129
|
container: document.querySelector(`#app`)
|
|
132
130
|
}
|
|
@@ -3,11 +3,12 @@ import * as http from "node:http"
|
|
|
3
3
|
import type { RenderResult } from "@testing-library/react"
|
|
4
4
|
import { prettyDOM, render } from "@testing-library/react"
|
|
5
5
|
import * as AtomIO from "atom.io"
|
|
6
|
-
import { editRelationsInStore, findRelationsInStore } from "atom.io/data"
|
|
7
6
|
import type { Store } from "atom.io/internal"
|
|
8
7
|
import {
|
|
9
8
|
clearStore,
|
|
9
|
+
editRelationsInStore,
|
|
10
10
|
findInStore,
|
|
11
|
+
findRelationsInStore,
|
|
11
12
|
getFromStore,
|
|
12
13
|
IMPLICIT,
|
|
13
14
|
setIntoStore,
|
package/src/index.ts
CHANGED
|
@@ -17,7 +17,9 @@ import type {
|
|
|
17
17
|
|
|
18
18
|
export * from "./atom"
|
|
19
19
|
export * from "./dispose-state"
|
|
20
|
+
export * from "./find-state"
|
|
20
21
|
export * from "./get-state"
|
|
22
|
+
export * from "./join"
|
|
21
23
|
export * from "./logger"
|
|
22
24
|
export * from "./realm"
|
|
23
25
|
export * from "./selector"
|
|
@@ -146,3 +148,5 @@ export type FamilyMetadata<K extends Canonical = any> = {
|
|
|
146
148
|
/** The family member's unique identifier, in the form of a string. */
|
|
147
149
|
subKey: stringified<K>
|
|
148
150
|
}
|
|
151
|
+
|
|
152
|
+
export type Loadable<T> = Promise<T> | T
|
package/src/join.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import type { MutableAtomFamilyToken, ReadonlySelectorToken } from "atom.io"
|
|
2
|
+
import type {
|
|
3
|
+
Junction,
|
|
4
|
+
JunctionEntriesBase,
|
|
5
|
+
JunctionSchemaBase,
|
|
6
|
+
Refinement,
|
|
7
|
+
Store,
|
|
8
|
+
} from "atom.io/internal"
|
|
9
|
+
import {
|
|
10
|
+
editRelationsInStore,
|
|
11
|
+
findRelationsInStore,
|
|
12
|
+
getInternalRelationsFromStore,
|
|
13
|
+
IMPLICIT,
|
|
14
|
+
Join,
|
|
15
|
+
} from "atom.io/internal"
|
|
16
|
+
import type { Json } from "atom.io/json"
|
|
17
|
+
import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
|
|
18
|
+
|
|
19
|
+
export interface JoinOptions<
|
|
20
|
+
ASide extends string,
|
|
21
|
+
AType extends string,
|
|
22
|
+
BSide extends string,
|
|
23
|
+
BType extends string,
|
|
24
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
25
|
+
Content extends Json.Object | null,
|
|
26
|
+
> extends JunctionSchemaBase<ASide, BSide>,
|
|
27
|
+
Partial<JunctionEntriesBase<AType, BType, Content>> {
|
|
28
|
+
readonly key: string
|
|
29
|
+
readonly cardinality: Cardinality
|
|
30
|
+
readonly isAType: Refinement<string, AType>
|
|
31
|
+
readonly isBType: Refinement<string, BType>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type JoinToken<
|
|
35
|
+
ASide extends string,
|
|
36
|
+
AType extends string,
|
|
37
|
+
BSide extends string,
|
|
38
|
+
BType extends string,
|
|
39
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
40
|
+
Content extends Json.Object | null = null,
|
|
41
|
+
> = {
|
|
42
|
+
key: string
|
|
43
|
+
type: `join`
|
|
44
|
+
cardinality: Cardinality
|
|
45
|
+
a: ASide
|
|
46
|
+
b: BSide
|
|
47
|
+
__aType?: AType
|
|
48
|
+
__bType?: BType
|
|
49
|
+
__content?: Content
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function join<
|
|
53
|
+
const ASide extends string,
|
|
54
|
+
const AType extends string,
|
|
55
|
+
const BSide extends string,
|
|
56
|
+
const BType extends string,
|
|
57
|
+
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
58
|
+
>(
|
|
59
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>,
|
|
60
|
+
defaultContent?: undefined,
|
|
61
|
+
store?: Store,
|
|
62
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
|
|
63
|
+
export function join<
|
|
64
|
+
const ASide extends string,
|
|
65
|
+
const AType extends string,
|
|
66
|
+
const BSide extends string,
|
|
67
|
+
const BType extends string,
|
|
68
|
+
const Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
69
|
+
const Content extends Json.Object,
|
|
70
|
+
>(
|
|
71
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
72
|
+
defaultContent: Content,
|
|
73
|
+
store?: Store,
|
|
74
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>
|
|
75
|
+
export function join<
|
|
76
|
+
ASide extends string,
|
|
77
|
+
AType extends string,
|
|
78
|
+
BSide extends string,
|
|
79
|
+
BType extends string,
|
|
80
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
81
|
+
Content extends Json.Object,
|
|
82
|
+
>(
|
|
83
|
+
options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
84
|
+
defaultContent: Content | undefined,
|
|
85
|
+
store: Store = IMPLICIT.STORE,
|
|
86
|
+
): JoinToken<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
87
|
+
store.joins.set(options.key, new Join(options, defaultContent, store))
|
|
88
|
+
const token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content> = {
|
|
89
|
+
key: options.key,
|
|
90
|
+
type: `join`,
|
|
91
|
+
a: options.between[0],
|
|
92
|
+
b: options.between[1],
|
|
93
|
+
cardinality: options.cardinality,
|
|
94
|
+
}
|
|
95
|
+
return token
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type JoinStates<
|
|
99
|
+
ASide extends string,
|
|
100
|
+
AType extends string,
|
|
101
|
+
BSide extends string,
|
|
102
|
+
BType extends string,
|
|
103
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
104
|
+
Content extends Json.Object | null,
|
|
105
|
+
> = Cardinality extends `1:1`
|
|
106
|
+
? (Content extends Json.Object
|
|
107
|
+
? {
|
|
108
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
109
|
+
[AType, Content] | null,
|
|
110
|
+
BType
|
|
111
|
+
>
|
|
112
|
+
} & {
|
|
113
|
+
readonly [B in BSide as `${B}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
114
|
+
[BType, Content] | null,
|
|
115
|
+
AType
|
|
116
|
+
>
|
|
117
|
+
}
|
|
118
|
+
: {}) & {
|
|
119
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
120
|
+
AType | null,
|
|
121
|
+
BType
|
|
122
|
+
>
|
|
123
|
+
} & {
|
|
124
|
+
readonly [B in BSide as `${B}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
125
|
+
BType | null,
|
|
126
|
+
AType
|
|
127
|
+
>
|
|
128
|
+
}
|
|
129
|
+
: Cardinality extends `1:n`
|
|
130
|
+
? (Content extends Json.Object
|
|
131
|
+
? {
|
|
132
|
+
readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
133
|
+
[AType, Content] | null,
|
|
134
|
+
BType
|
|
135
|
+
>
|
|
136
|
+
} & {
|
|
137
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
138
|
+
[BType, Content][],
|
|
139
|
+
AType
|
|
140
|
+
>
|
|
141
|
+
}
|
|
142
|
+
: {}) & {
|
|
143
|
+
readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
144
|
+
AType | null,
|
|
145
|
+
BType
|
|
146
|
+
>
|
|
147
|
+
} & {
|
|
148
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
149
|
+
BType[],
|
|
150
|
+
AType
|
|
151
|
+
>
|
|
152
|
+
}
|
|
153
|
+
: Cardinality extends `n:n`
|
|
154
|
+
? (Content extends Json.Object
|
|
155
|
+
? {
|
|
156
|
+
readonly [A in ASide as `${A}EntriesOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
157
|
+
[AType, Content][],
|
|
158
|
+
BType
|
|
159
|
+
>
|
|
160
|
+
} & {
|
|
161
|
+
readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
162
|
+
[BType, Content][],
|
|
163
|
+
AType
|
|
164
|
+
>
|
|
165
|
+
}
|
|
166
|
+
: {}) & {
|
|
167
|
+
readonly [A in ASide as `${A}KeysOf${Capitalize<BSide>}`]: ReadonlySelectorToken<
|
|
168
|
+
AType[],
|
|
169
|
+
BType
|
|
170
|
+
>
|
|
171
|
+
} & {
|
|
172
|
+
readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<
|
|
173
|
+
BType[],
|
|
174
|
+
AType
|
|
175
|
+
>
|
|
176
|
+
}
|
|
177
|
+
: never
|
|
178
|
+
|
|
179
|
+
export function findRelations<
|
|
180
|
+
ASide extends string,
|
|
181
|
+
AType extends string,
|
|
182
|
+
BSide extends string,
|
|
183
|
+
BType extends string,
|
|
184
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
185
|
+
Content extends Json.Object | null,
|
|
186
|
+
>(
|
|
187
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
188
|
+
key: AType | BType,
|
|
189
|
+
): JoinStates<ASide, AType, BSide, BType, Cardinality, Content> {
|
|
190
|
+
return findRelationsInStore(token, key, IMPLICIT.STORE)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function editRelations<
|
|
194
|
+
ASide extends string,
|
|
195
|
+
AType extends string,
|
|
196
|
+
BSide extends string,
|
|
197
|
+
BType extends string,
|
|
198
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
199
|
+
Content extends Json.Object | null,
|
|
200
|
+
>(
|
|
201
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
202
|
+
change: (relations: Junction<ASide, AType, BSide, BType, Content>) => void,
|
|
203
|
+
): void {
|
|
204
|
+
editRelationsInStore(token, change, IMPLICIT.STORE)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function getInternalRelations<
|
|
208
|
+
ASide extends string,
|
|
209
|
+
AType extends string,
|
|
210
|
+
BSide extends string,
|
|
211
|
+
BType extends string,
|
|
212
|
+
Cardinality extends `1:1` | `1:n` | `n:n`,
|
|
213
|
+
Content extends Json.Object | null,
|
|
214
|
+
>(
|
|
215
|
+
token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
|
|
216
|
+
): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
|
|
217
|
+
return getInternalRelationsFromStore(token, IMPLICIT.STORE)
|
|
218
|
+
}
|
package/src/silo.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { findState } from "atom.io
|
|
1
|
+
import type { findState } from "atom.io"
|
|
2
2
|
import {
|
|
3
3
|
actUponStore,
|
|
4
4
|
arbitrary,
|
|
@@ -61,8 +61,8 @@ export class Silo {
|
|
|
61
61
|
createStandaloneSelector(s, options)) as typeof selector
|
|
62
62
|
this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
|
|
63
63
|
createSelectorFamily(s, options)) as typeof selectorFamily
|
|
64
|
-
this.transaction = (options) => createTransaction(
|
|
65
|
-
this.timeline = (options) => createTimeline(
|
|
64
|
+
this.transaction = (options) => createTransaction(s, options)
|
|
65
|
+
this.timeline = (options) => createTimeline(s, options)
|
|
66
66
|
this.findState = ((...params: Parameters<typeof findState>) =>
|
|
67
67
|
findInStore(s, ...params)) as typeof findState
|
|
68
68
|
this.getState = ((...params: Parameters<typeof getState>) =>
|
|
@@ -81,7 +81,7 @@ export class Silo {
|
|
|
81
81
|
this.redo = (token) => {
|
|
82
82
|
timeTravel(s, `redo`, token)
|
|
83
83
|
}
|
|
84
|
-
this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id
|
|
84
|
+
this.runTransaction = (token, id = arbitrary()) => actUponStore(s, token, id)
|
|
85
85
|
this.install = (tokens, source = IMPLICIT.STORE) => {
|
|
86
86
|
installIntoStore(tokens, s, source)
|
|
87
87
|
}
|
package/src/timeline.ts
CHANGED
|
@@ -49,7 +49,7 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
|
|
|
49
49
|
export const timeline = <ManagedAtom extends TimelineManageable>(
|
|
50
50
|
options: TimelineOptions<ManagedAtom>,
|
|
51
51
|
): TimelineToken<ManagedAtom> => {
|
|
52
|
-
return createTimeline(
|
|
52
|
+
return createTimeline(IMPLICIT.STORE, options)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
export const redo = (tl: TimelineToken<any>): void => {
|
package/src/transaction.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { getState, setState } from "atom.io"
|
|
2
|
-
import type { findState } from "atom.io/ephemeral"
|
|
3
|
-
import type { seekState } from "atom.io/immortal"
|
|
1
|
+
import type { findState, getState, setState } from "atom.io"
|
|
4
2
|
import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
|
|
5
3
|
import {
|
|
6
4
|
actUponStore,
|
|
@@ -83,12 +81,11 @@ export type TransactionUpdate<F extends Func> = {
|
|
|
83
81
|
output: ReturnType<F>
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json
|
|
84
|
+
export type GetterToolkit = Pick<SetterToolkit, `find` | `get` | `json`>
|
|
87
85
|
export type SetterToolkit = Readonly<{
|
|
88
86
|
get: typeof getState
|
|
89
87
|
set: typeof setState
|
|
90
88
|
find: typeof findState
|
|
91
|
-
seek: typeof seekState
|
|
92
89
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
93
90
|
state: MutableAtomToken<T, J>,
|
|
94
91
|
) => WritableSelectorToken<J>
|
|
@@ -97,7 +94,6 @@ export type ActorToolkit = Readonly<{
|
|
|
97
94
|
get: typeof getState
|
|
98
95
|
set: typeof setState
|
|
99
96
|
find: typeof findState
|
|
100
|
-
seek: typeof seekState
|
|
101
97
|
json: <T extends Transceiver<any>, J extends Json.Serializable>(
|
|
102
98
|
state: MutableAtomToken<T, J>,
|
|
103
99
|
) => WritableSelectorToken<J>
|
|
@@ -132,12 +128,12 @@ export type TransactionIO<Token extends TransactionToken<any>> =
|
|
|
132
128
|
export function transaction<F extends Func>(
|
|
133
129
|
options: TransactionOptions<F>,
|
|
134
130
|
): TransactionToken<F> {
|
|
135
|
-
return createTransaction(
|
|
131
|
+
return createTransaction(IMPLICIT.STORE, options)
|
|
136
132
|
}
|
|
137
133
|
|
|
138
134
|
export function runTransaction<F extends Func>(
|
|
139
135
|
token: TransactionToken<F>,
|
|
140
136
|
id = arbitrary(),
|
|
141
137
|
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
142
|
-
return actUponStore(token, id
|
|
138
|
+
return actUponStore(IMPLICIT.STORE, token, id)
|
|
143
139
|
}
|
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type primitive = boolean | number | string | null;
|
|
2
|
+
declare namespace Json {
|
|
3
|
+
namespace Tree {
|
|
4
|
+
type Array<Element = unknown> = ReadonlyArray<Element>;
|
|
5
|
+
type Object<K extends string = string, V = unknown> = Record<K, V>;
|
|
6
|
+
type Fork = Array | Object;
|
|
7
|
+
type Leaf = primitive;
|
|
8
|
+
type Node = Fork | Leaf;
|
|
9
|
+
}
|
|
10
|
+
type Serializable = primitive | Readonly<{
|
|
11
|
+
[key: string]: Serializable;
|
|
12
|
+
}> | ReadonlyArray<Serializable>;
|
|
13
|
+
type Object<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
|
|
14
|
+
type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class Subject<T> {
|
|
18
|
+
Subscriber: (value: T) => void;
|
|
19
|
+
subscribers: Map<string, this[`Subscriber`]>;
|
|
20
|
+
subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
|
|
21
|
+
private unsubscribe;
|
|
22
|
+
next(value: T): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface Lineage {
|
|
26
|
+
parent: typeof this | null;
|
|
27
|
+
child: typeof this | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface Transceiver<S extends Json.Serializable> {
|
|
31
|
+
do: (update: S) => number | `OUT_OF_RANGE` | null;
|
|
32
|
+
undo: (update: S) => void;
|
|
33
|
+
subscribe: (key: string, fn: (update: S) => void) => () => void;
|
|
34
|
+
cacheUpdateNumber: number;
|
|
35
|
+
getUpdateNumber: (update: S) => number;
|
|
36
|
+
}
|
|
37
|
+
type TransceiverMode = `playback` | `record` | `transaction`;
|
|
3
38
|
|
|
4
39
|
type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
|
|
5
40
|
type NumberedSetUpdate = `${number}=${SetUpdate}`;
|