atom.io 0.14.8 → 0.15.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/README.md +5 -0
- package/data/dist/index.cjs +216 -218
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +30 -11
- package/data/dist/index.js +218 -221
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +337 -296
- package/data/src/struct-family.ts +2 -2
- package/data/src/struct.ts +2 -2
- package/dist/chunk-S7R5MU6A.js +137 -0
- package/dist/chunk-S7R5MU6A.js.map +1 -0
- package/dist/index.cjs +3 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1 -151
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +278 -201
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +43 -36
- package/internal/dist/index.js +224 -194
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-atom.ts +5 -86
- package/internal/src/atom/create-regular-atom.ts +92 -0
- package/internal/src/atom/index.ts +16 -0
- package/internal/src/atom/is-default.ts +0 -5
- package/internal/src/caching.ts +14 -16
- package/internal/src/families/create-atom-family.ts +20 -46
- package/internal/src/families/create-readonly-selector-family.ts +4 -1
- package/internal/src/families/create-regular-atom-family.ts +72 -0
- package/internal/src/families/create-selector-family.ts +2 -0
- package/internal/src/families/index.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/create-mutable-atom.ts +8 -3
- package/internal/src/mutable/get-update-family.ts +1 -1
- package/internal/src/mutable/is-mutable.ts +3 -30
- package/internal/src/mutable/tracker-family.ts +2 -2
- package/internal/src/mutable/tracker.ts +5 -5
- package/internal/src/operation.ts +14 -18
- package/internal/src/selector/create-read-write-selector.ts +2 -3
- package/internal/src/selector/create-selector.ts +1 -1
- package/internal/src/selector/register-selector.ts +9 -14
- package/internal/src/set-state/evict-downstream.ts +3 -5
- package/internal/src/set-state/set-atom.ts +14 -17
- package/internal/src/store/store.ts +23 -19
- package/internal/src/store/withdraw.ts +32 -70
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +5 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -3
- package/internal/src/transaction/apply-transaction.ts +20 -2
- package/internal/src/transaction/build-transaction.ts +19 -11
- package/internal/src/transaction/create-transaction.ts +6 -11
- package/internal/src/transaction/index.ts +2 -3
- package/introspection/dist/index.cjs +6 -6
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js +7 -7
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +7 -2
- package/introspection/src/attach-selector-index.ts +7 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-timeline-index.ts +2 -2
- package/introspection/src/attach-transaction-index.ts +2 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/package.json +10 -8
- package/react-devtools/dist/index.d.ts +17 -11
- package/realtime-client/dist/index.cjs +3 -0
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +3 -3
- package/realtime-client/dist/index.js +3 -0
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +6 -6
- package/realtime-client/src/{use-pull-family-member.ts → pull-family-member.ts} +1 -1
- package/realtime-client/src/{use-pull-mutable-family-member.ts → pull-mutable-family-member.ts} +1 -1
- package/realtime-client/src/{use-pull-mutable.ts → pull-mutable.ts} +1 -1
- package/realtime-client/src/{use-server-action.ts → server-action.ts} +3 -0
- package/realtime-react/dist/index.cjs +31 -17
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +3 -3
- package/realtime-react/dist/index.js +31 -17
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/realtime-context.tsx +2 -3
- package/realtime-react/src/use-pull-family-member.ts +6 -2
- package/realtime-react/src/use-pull-mutable-family-member.ts +5 -4
- package/realtime-react/src/use-pull-mutable.ts +6 -2
- package/realtime-react/src/use-pull.ts +5 -1
- package/realtime-react/src/use-push.ts +5 -4
- package/realtime-react/src/use-server-action.ts +5 -4
- package/src/atom.ts +8 -17
- package/src/selector.ts +3 -1
- package/src/set-state.ts +1 -3
- package/src/silo.ts +2 -14
- package/src/transaction.ts +17 -6
- package/transceivers/set-rtx/dist/index.cjs +2 -1
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.js +2 -1
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/src/set-rtx.ts +2 -1
- package/internal/src/transaction/redo-transaction.ts +0 -27
- package/internal/src/transaction/undo-transaction.ts +0 -27
- /package/realtime-client/src/{use-pull.ts → pull.ts} +0 -0
- /package/realtime-client/src/{use-push.ts → push.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
2
|
import {
|
|
3
3
|
IMPLICIT,
|
|
4
|
-
|
|
4
|
+
createRegularAtomFamily,
|
|
5
5
|
createSelectorFamily,
|
|
6
6
|
} from "atom.io/internal"
|
|
7
7
|
|
|
@@ -29,7 +29,7 @@ export function structFamily<
|
|
|
29
29
|
>}State`]: AtomIO.AtomFamily<Struct[K], string>
|
|
30
30
|
} = Object.keys(options.default).reduce((acc, subKey) => {
|
|
31
31
|
const atomFamilyName = nameFamily(options.key, subKey)
|
|
32
|
-
acc[atomFamilyName] =
|
|
32
|
+
acc[atomFamilyName] = createRegularAtomFamily(
|
|
33
33
|
{
|
|
34
34
|
key: `${options.key}.${subKey}`,
|
|
35
35
|
default: (options.default as any)[subKey],
|
package/data/src/struct.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type * as AtomIO from "atom.io"
|
|
|
2
2
|
import type { Store } from "atom.io/internal"
|
|
3
3
|
import { IMPLICIT } from "atom.io/internal"
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { createRegularAtom, createSelector } from "atom.io/internal"
|
|
6
6
|
|
|
7
7
|
const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
|
|
8
8
|
|
|
@@ -29,7 +29,7 @@ export function struct<
|
|
|
29
29
|
>}State`]: AtomIO.AtomToken<Struct[K]>
|
|
30
30
|
} = Object.keys(options.default).reduce((acc, key) => {
|
|
31
31
|
const atomName = options.key + capitalize(key) + `State`
|
|
32
|
-
acc[atomName] =
|
|
32
|
+
acc[atomName] = createRegularAtom(
|
|
33
33
|
{
|
|
34
34
|
key: `${options.key}.${key}`,
|
|
35
35
|
default: options.default[key],
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import * as Internal3 from 'atom.io/internal';
|
|
2
|
+
import { createAtom, IMPLICIT, createAtomFamily, createSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
|
|
3
|
+
|
|
4
|
+
// src/atom.ts
|
|
5
|
+
function atom(options) {
|
|
6
|
+
return createAtom(options, void 0, IMPLICIT.STORE);
|
|
7
|
+
}
|
|
8
|
+
function atomFamily(options) {
|
|
9
|
+
return createAtomFamily(options, IMPLICIT.STORE);
|
|
10
|
+
}
|
|
11
|
+
function dispose(token, store = Internal3.IMPLICIT.STORE) {
|
|
12
|
+
switch (token.type) {
|
|
13
|
+
case `atom`:
|
|
14
|
+
Internal3.deleteAtom(token, store);
|
|
15
|
+
break;
|
|
16
|
+
case `selector`:
|
|
17
|
+
case `readonly_selector`:
|
|
18
|
+
Internal3.deleteSelector(token, store);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function getState(token, store = Internal3.IMPLICIT.STORE) {
|
|
23
|
+
var _a;
|
|
24
|
+
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
25
|
+
if (state === void 0) {
|
|
26
|
+
throw new Internal3.NotFoundError(token, store);
|
|
27
|
+
}
|
|
28
|
+
return Internal3.readOrComputeValue(state, store);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/logger.ts
|
|
32
|
+
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
33
|
+
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
34
|
+
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
35
|
+
};
|
|
36
|
+
var simpleLogger = {
|
|
37
|
+
error: simpleLog(`error`),
|
|
38
|
+
info: simpleLog(`info`),
|
|
39
|
+
warn: simpleLog(`warn`)
|
|
40
|
+
};
|
|
41
|
+
var AtomIOLogger = class {
|
|
42
|
+
constructor(logLevel, filter, logger = simpleLogger) {
|
|
43
|
+
this.logLevel = logLevel;
|
|
44
|
+
this.filter = filter;
|
|
45
|
+
this.logger = logger;
|
|
46
|
+
this.error = (...args) => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
49
|
+
this.logger.error(...args);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.info = (...args) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
55
|
+
this.logger.info(...args);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this.warn = (...args) => {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
61
|
+
this.logger.warn(...args);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
function selector(options) {
|
|
67
|
+
return createSelector(options, void 0, IMPLICIT.STORE);
|
|
68
|
+
}
|
|
69
|
+
function selectorFamily(options) {
|
|
70
|
+
return createSelectorFamily(options, IMPLICIT.STORE);
|
|
71
|
+
}
|
|
72
|
+
function setState(token, value, store = Internal3.IMPLICIT.STORE) {
|
|
73
|
+
const rejection = Internal3.openOperation(token, store);
|
|
74
|
+
if (rejection) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const state = Internal3.withdraw(token, store);
|
|
78
|
+
if (state === void 0) {
|
|
79
|
+
throw new Internal3.NotFoundError(token, store);
|
|
80
|
+
}
|
|
81
|
+
Internal3.setAtomOrSelector(state, value, store);
|
|
82
|
+
Internal3.closeOperation(store);
|
|
83
|
+
}
|
|
84
|
+
var Silo = class {
|
|
85
|
+
constructor(name, fromStore = null) {
|
|
86
|
+
const s = new Store(name, fromStore);
|
|
87
|
+
this.store = s;
|
|
88
|
+
this.atom = (options) => createAtom(options, void 0, s);
|
|
89
|
+
this.atomFamily = (options) => createAtomFamily(options, s);
|
|
90
|
+
this.selector = (options) => createSelector(options, void 0, s);
|
|
91
|
+
this.selectorFamily = (options) => createSelectorFamily(options, s);
|
|
92
|
+
this.transaction = (options) => createTransaction(options, s);
|
|
93
|
+
this.timeline = (options) => createTimeline(options, s);
|
|
94
|
+
this.getState = (token) => getState(token, s);
|
|
95
|
+
this.setState = (token, newValue) => setState(token, newValue, s);
|
|
96
|
+
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
|
97
|
+
this.undo = (token) => timeTravel(`backward`, token, s);
|
|
98
|
+
this.redo = (token) => timeTravel(`forward`, token, s);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
|
|
102
|
+
switch (token.type) {
|
|
103
|
+
case `atom`:
|
|
104
|
+
case `readonly_selector`:
|
|
105
|
+
case `selector`:
|
|
106
|
+
return subscribeToState(token, handleUpdate, key, store);
|
|
107
|
+
case `transaction`:
|
|
108
|
+
return subscribeToTransaction(token, handleUpdate, key, store);
|
|
109
|
+
case `timeline`:
|
|
110
|
+
return subscribeToTimeline(token, handleUpdate, key, store);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var timeline = (options) => {
|
|
114
|
+
return createTimeline(options, IMPLICIT.STORE);
|
|
115
|
+
};
|
|
116
|
+
var redo = (timeline2) => {
|
|
117
|
+
timeTravel(`forward`, timeline2, IMPLICIT.STORE);
|
|
118
|
+
};
|
|
119
|
+
var undo = (timeline2) => {
|
|
120
|
+
timeTravel(`backward`, timeline2, IMPLICIT.STORE);
|
|
121
|
+
};
|
|
122
|
+
function transaction(options) {
|
|
123
|
+
return createTransaction(options, IMPLICIT.STORE);
|
|
124
|
+
}
|
|
125
|
+
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
126
|
+
const tx = withdraw(token, store);
|
|
127
|
+
if (tx) {
|
|
128
|
+
return tx.run(...parameters);
|
|
129
|
+
}
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
136
|
+
//# sourceMappingURL=out.js.map
|
|
137
|
+
//# sourceMappingURL=chunk-S7R5MU6A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AAC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;;ACnCA,SAAS,YAAAA,WAAU,qBAAAQ,oBAAmB,YAAAC,iBAAgB;AAyD/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAASR,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeA,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKS,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state = Internal.withdraw(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken:\n\t\t| ReadonlySelectorToken<any>\n\t\t| StateToken<any>\n\t\t| TimelineToken\n\t\t| TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n}>\nexport type TransactorsWithRun = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\trun: typeof runTransaction\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRun,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -24,15 +24,9 @@ var Internal3__namespace = /*#__PURE__*/_interopNamespace(Internal3);
|
|
|
24
24
|
|
|
25
25
|
// src/atom.ts
|
|
26
26
|
function atom(options) {
|
|
27
|
-
if (`mutable` in options) {
|
|
28
|
-
return Internal3.createMutableAtom(options, Internal3.IMPLICIT.STORE);
|
|
29
|
-
}
|
|
30
27
|
return Internal3.createAtom(options, void 0, Internal3.IMPLICIT.STORE);
|
|
31
28
|
}
|
|
32
29
|
function atomFamily(options) {
|
|
33
|
-
if (`mutable` in options) {
|
|
34
|
-
return Internal3.createMutableAtomFamily(options, Internal3.IMPLICIT.STORE);
|
|
35
|
-
}
|
|
36
30
|
return Internal3.createAtomFamily(options, Internal3.IMPLICIT.STORE);
|
|
37
31
|
}
|
|
38
32
|
function dispose(token, store = Internal3__namespace.IMPLICIT.STORE) {
|
|
@@ -97,12 +91,11 @@ function selectorFamily(options) {
|
|
|
97
91
|
return Internal3.createSelectorFamily(options, Internal3.IMPLICIT.STORE);
|
|
98
92
|
}
|
|
99
93
|
function setState(token, value, store = Internal3__namespace.IMPLICIT.STORE) {
|
|
100
|
-
var _a;
|
|
101
94
|
const rejection = Internal3__namespace.openOperation(token, store);
|
|
102
95
|
if (rejection) {
|
|
103
96
|
return;
|
|
104
97
|
}
|
|
105
|
-
const state =
|
|
98
|
+
const state = Internal3__namespace.withdraw(token, store);
|
|
106
99
|
if (state === void 0) {
|
|
107
100
|
throw new Internal3__namespace.NotFoundError(token, store);
|
|
108
101
|
}
|
|
@@ -113,18 +106,8 @@ var Silo = class {
|
|
|
113
106
|
constructor(name, fromStore = null) {
|
|
114
107
|
const s = new Internal3.Store(name, fromStore);
|
|
115
108
|
this.store = s;
|
|
116
|
-
this.atom = (options) =>
|
|
117
|
-
|
|
118
|
-
return Internal3.createMutableAtom(options, s);
|
|
119
|
-
}
|
|
120
|
-
return Internal3.createAtom(options, void 0, s);
|
|
121
|
-
};
|
|
122
|
-
this.atomFamily = (options) => {
|
|
123
|
-
if (`mutable` in options) {
|
|
124
|
-
return Internal3.createMutableAtomFamily(options, s);
|
|
125
|
-
}
|
|
126
|
-
return Internal3.createAtomFamily(options, s);
|
|
127
|
-
};
|
|
109
|
+
this.atom = (options) => Internal3.createAtom(options, void 0, s);
|
|
110
|
+
this.atomFamily = (options) => Internal3.createAtomFamily(options, s);
|
|
128
111
|
this.selector = (options) => Internal3.createSelector(options, void 0, s);
|
|
129
112
|
this.selectorFamily = (options) => Internal3.createSelectorFamily(options, s);
|
|
130
113
|
this.transaction = (options) => Internal3.createTransaction(options, s);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,SAAS,SAAS,KAAK;AAAA,EACjD;AACA,SAAO,WAAc,SAAS,QAAW,SAAS,KAAK;AACxD;AAiDO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,SAAS,SAAS,KAAK;AAAA,EACvD;AACA,SAAO,iBAAuB,SAAS,SAAS,KAAK;AACtD;;;ACpGA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACjBA,YAAYA,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,OAAO,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ACZ,CAAe,OAA4B,QAAeA,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKW,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options, IMPLICIT.STORE)\n\t}\n\treturn createAtom<T>(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options, IMPLICIT.STORE)\n\t}\n\treturn createAtomFamily<T, K>(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken:\n\t\t| ReadonlySelectorToken<any>\n\t\t| StateToken<any>\n\t\t| TimelineToken\n\t\t| TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Act<ƒ extends ƒn> = (\n\ttransactors: Transactors & { run: typeof runTransaction },\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Act<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AACrD;AAoDO,SAAS,WACf,SACsD;AACtD,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;AC3FA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACjBA,YAAYA,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,OAAO,KAAK,MAA9B,YACS,kCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAa,wBAAc,OAAO,KAAK;AAAA,EAC9C;AACA,SAAgB,6BAAmB,OAAO,KAAK;AAChD;;;AC0BO,IAAM,aAAa,CAAC,QAAQ,QAAQ,OAAO;AAqB3C,IAAM,YACZ,CAAC,aACD,CAAC,MAAM,WAAW,UAAU,YAAY,SAAS;AAChD,UAAQ,QAAQ,EAAE,GAAG,IAAI,IAAI,SAAS,KAAK,QAAQ,KAAK,OAAO,IAAI,GAAG,IAAI;AAC3E;AACM,IAAM,eAAuB;AAAA,EACnC,OAAO,UAAU,OAAO;AAAA,EACxB,MAAM,UAAU,MAAM;AAAA,EACtB,MAAM,UAAU,MAAM;AACvB;AAEO,IAAM,eAAN,MAAqC;AAAA,EACpC,YACC,UACU,QACA,SAAiB,cACjC;AAHM;AACU;AACA;AAGlB,SAAO,QAAe,IAAI,SAAS;AAhFpC;AAiFE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AACpE,SAAOD,gBAAe,SAASL,UAAS,KAAK;AAC9C;AAEO,IAAM,OAAO,CAACO,cAAkC;AACtD,EAAAD,YAAW,WAAWC,WAAUP,UAAS,KAAK;AAC/C;AAEO,IAAM,OAAO,CAACO,cAAkC;AACtD,EAAAD,YAAW,YAAYC,WAAUP,UAAS,KAAK;AAChD;;;ACnCA,SAAS,YAAAA,WAAU,qBAAAQ,oBAAmB,YAAAC,iBAAgB;AAyD/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAASR,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeA,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKS,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state = Internal.withdraw(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken:\n\t\t| ReadonlySelectorToken<any>\n\t\t| StateToken<any>\n\t\t| TimelineToken\n\t\t| TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n}>\nexport type TransactorsWithRun = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\trun: typeof runTransaction\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRun,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K)
|
|
|
31
31
|
type: `atom_family`;
|
|
32
32
|
subject: Subject<AtomToken<T>>;
|
|
33
33
|
mutable?: boolean;
|
|
34
|
+
install: (store: Store) => void;
|
|
34
35
|
};
|
|
35
36
|
type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = AtomFamilyOptions<T, K> & JsonInterface<T, J> & {
|
|
36
37
|
mutable: true;
|
|
@@ -40,6 +41,7 @@ type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends J
|
|
|
40
41
|
type: `atom_family`;
|
|
41
42
|
subject: Subject<MutableAtomToken<Core, SerializableCore>>;
|
|
42
43
|
mutable: true;
|
|
44
|
+
install: (store: Store) => void;
|
|
43
45
|
};
|
|
44
46
|
declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
|
|
45
47
|
declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
|
|
@@ -116,19 +118,22 @@ type TransactionUpdate<ƒ extends ƒn> = {
|
|
|
116
118
|
params: Parameters<ƒ>;
|
|
117
119
|
output: ReturnType<ƒ>;
|
|
118
120
|
};
|
|
119
|
-
type Transactors = {
|
|
121
|
+
type Transactors = Readonly<{
|
|
120
122
|
get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S;
|
|
121
|
-
set: <S>(state: StateToken<S>, newValue:
|
|
122
|
-
}
|
|
123
|
+
set: <S, New extends S>(state: StateToken<S>, newValue: New | ((oldValue: S) => New)) => void;
|
|
124
|
+
}>;
|
|
125
|
+
type TransactorsWithRun = Readonly<{
|
|
126
|
+
get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S;
|
|
127
|
+
set: <S, New extends S>(state: StateToken<S>, newValue: New | ((oldValue: S) => New)) => void;
|
|
128
|
+
run: typeof runTransaction;
|
|
129
|
+
}>;
|
|
123
130
|
type ReadonlyTransactors = Pick<Transactors, `get`>;
|
|
124
131
|
type Read<ƒ extends ƒn> = (transactors: ReadonlyTransactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
125
132
|
type Write<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
126
|
-
type
|
|
127
|
-
run: typeof runTransaction;
|
|
128
|
-
}, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
133
|
+
type Transact<ƒ extends ƒn> = (transactors: TransactorsWithRun, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
129
134
|
type TransactionOptions<ƒ extends ƒn> = {
|
|
130
135
|
key: string;
|
|
131
|
-
do:
|
|
136
|
+
do: Transact<ƒ>;
|
|
132
137
|
};
|
|
133
138
|
type TransactionIO<Token extends TransactionToken<any>> = Token extends TransactionToken<infer ƒ> ? ƒ : never;
|
|
134
139
|
declare function transaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>): TransactionToken<ƒ>;
|
|
@@ -158,11 +163,13 @@ type SelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key:
|
|
|
158
163
|
key: string;
|
|
159
164
|
type: `selector_family`;
|
|
160
165
|
subject: Subject<SelectorToken<T>>;
|
|
166
|
+
install: (store: Store) => void;
|
|
161
167
|
};
|
|
162
168
|
type ReadonlySelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
|
|
163
169
|
key: string;
|
|
164
170
|
type: `readonly_selector_family`;
|
|
165
171
|
subject: Subject<ReadonlySelectorToken<T>>;
|
|
172
|
+
install: (store: Store) => void;
|
|
166
173
|
};
|
|
167
174
|
declare function selectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
|
|
168
175
|
declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
|
|
@@ -242,4 +249,4 @@ type FamilyMetadata = {
|
|
|
242
249
|
subKey: string;
|
|
243
250
|
};
|
|
244
251
|
|
|
245
|
-
export { type
|
|
252
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, AtomIOLogger, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type SelectorFamily, type SelectorFamilyOptions, type SelectorOptions, type SelectorToken, Silo, type StateToken, type StateUpdate, type TimelineOptions, type TimelineToken, type TimelineUpdate, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type TransactorsWithRun, type UpdateHandler, type Write, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, type ƒn };
|
package/dist/index.js
CHANGED
|
@@ -1,154 +1,4 @@
|
|
|
1
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo } from './chunk-S7R5MU6A.js';
|
|
1
2
|
import './chunk-PZLG2HP3.js';
|
|
2
|
-
import * as Internal3 from 'atom.io/internal';
|
|
3
|
-
import { createMutableAtom, IMPLICIT, createAtom, createMutableAtomFamily, createAtomFamily, createSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
|
|
4
|
-
|
|
5
|
-
function atom(options) {
|
|
6
|
-
if (`mutable` in options) {
|
|
7
|
-
return createMutableAtom(options, IMPLICIT.STORE);
|
|
8
|
-
}
|
|
9
|
-
return createAtom(options, void 0, IMPLICIT.STORE);
|
|
10
|
-
}
|
|
11
|
-
function atomFamily(options) {
|
|
12
|
-
if (`mutable` in options) {
|
|
13
|
-
return createMutableAtomFamily(options, IMPLICIT.STORE);
|
|
14
|
-
}
|
|
15
|
-
return createAtomFamily(options, IMPLICIT.STORE);
|
|
16
|
-
}
|
|
17
|
-
function dispose(token, store = Internal3.IMPLICIT.STORE) {
|
|
18
|
-
switch (token.type) {
|
|
19
|
-
case `atom`:
|
|
20
|
-
Internal3.deleteAtom(token, store);
|
|
21
|
-
break;
|
|
22
|
-
case `selector`:
|
|
23
|
-
case `readonly_selector`:
|
|
24
|
-
Internal3.deleteSelector(token, store);
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function getState(token, store = Internal3.IMPLICIT.STORE) {
|
|
29
|
-
var _a;
|
|
30
|
-
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
31
|
-
if (state === void 0) {
|
|
32
|
-
throw new Internal3.NotFoundError(token, store);
|
|
33
|
-
}
|
|
34
|
-
return Internal3.readOrComputeValue(state, store);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// src/logger.ts
|
|
38
|
-
var LOG_LEVELS = [`info`, `warn`, `error`];
|
|
39
|
-
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
40
|
-
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
41
|
-
};
|
|
42
|
-
var simpleLogger = {
|
|
43
|
-
error: simpleLog(`error`),
|
|
44
|
-
info: simpleLog(`info`),
|
|
45
|
-
warn: simpleLog(`warn`)
|
|
46
|
-
};
|
|
47
|
-
var AtomIOLogger = class {
|
|
48
|
-
constructor(logLevel, filter, logger = simpleLogger) {
|
|
49
|
-
this.logLevel = logLevel;
|
|
50
|
-
this.filter = filter;
|
|
51
|
-
this.logger = logger;
|
|
52
|
-
this.error = (...args) => {
|
|
53
|
-
var _a, _b;
|
|
54
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
55
|
-
this.logger.error(...args);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
this.info = (...args) => {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
61
|
-
this.logger.info(...args);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
this.warn = (...args) => {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
67
|
-
this.logger.warn(...args);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
function selector(options) {
|
|
73
|
-
return createSelector(options, void 0, IMPLICIT.STORE);
|
|
74
|
-
}
|
|
75
|
-
function selectorFamily(options) {
|
|
76
|
-
return createSelectorFamily(options, IMPLICIT.STORE);
|
|
77
|
-
}
|
|
78
|
-
function setState(token, value, store = Internal3.IMPLICIT.STORE) {
|
|
79
|
-
var _a;
|
|
80
|
-
const rejection = Internal3.openOperation(token, store);
|
|
81
|
-
if (rejection) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
|
|
85
|
-
if (state === void 0) {
|
|
86
|
-
throw new Internal3.NotFoundError(token, store);
|
|
87
|
-
}
|
|
88
|
-
Internal3.setAtomOrSelector(state, value, store);
|
|
89
|
-
Internal3.closeOperation(store);
|
|
90
|
-
}
|
|
91
|
-
var Silo = class {
|
|
92
|
-
constructor(name, fromStore = null) {
|
|
93
|
-
const s = new Store(name, fromStore);
|
|
94
|
-
this.store = s;
|
|
95
|
-
this.atom = (options) => {
|
|
96
|
-
if (`mutable` in options) {
|
|
97
|
-
return createMutableAtom(options, s);
|
|
98
|
-
}
|
|
99
|
-
return createAtom(options, void 0, s);
|
|
100
|
-
};
|
|
101
|
-
this.atomFamily = (options) => {
|
|
102
|
-
if (`mutable` in options) {
|
|
103
|
-
return createMutableAtomFamily(options, s);
|
|
104
|
-
}
|
|
105
|
-
return createAtomFamily(options, s);
|
|
106
|
-
};
|
|
107
|
-
this.selector = (options) => createSelector(options, void 0, s);
|
|
108
|
-
this.selectorFamily = (options) => createSelectorFamily(options, s);
|
|
109
|
-
this.transaction = (options) => createTransaction(options, s);
|
|
110
|
-
this.timeline = (options) => createTimeline(options, s);
|
|
111
|
-
this.getState = (token) => getState(token, s);
|
|
112
|
-
this.setState = (token, newValue) => setState(token, newValue, s);
|
|
113
|
-
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
|
114
|
-
this.undo = (token) => timeTravel(`backward`, token, s);
|
|
115
|
-
this.redo = (token) => timeTravel(`forward`, token, s);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
|
|
119
|
-
switch (token.type) {
|
|
120
|
-
case `atom`:
|
|
121
|
-
case `readonly_selector`:
|
|
122
|
-
case `selector`:
|
|
123
|
-
return subscribeToState(token, handleUpdate, key, store);
|
|
124
|
-
case `transaction`:
|
|
125
|
-
return subscribeToTransaction(token, handleUpdate, key, store);
|
|
126
|
-
case `timeline`:
|
|
127
|
-
return subscribeToTimeline(token, handleUpdate, key, store);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
var timeline = (options) => {
|
|
131
|
-
return createTimeline(options, IMPLICIT.STORE);
|
|
132
|
-
};
|
|
133
|
-
var redo = (timeline2) => {
|
|
134
|
-
timeTravel(`forward`, timeline2, IMPLICIT.STORE);
|
|
135
|
-
};
|
|
136
|
-
var undo = (timeline2) => {
|
|
137
|
-
timeTravel(`backward`, timeline2, IMPLICIT.STORE);
|
|
138
|
-
};
|
|
139
|
-
function transaction(options) {
|
|
140
|
-
return createTransaction(options, IMPLICIT.STORE);
|
|
141
|
-
}
|
|
142
|
-
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
143
|
-
const tx = withdraw(token, store);
|
|
144
|
-
if (tx) {
|
|
145
|
-
return tx.run(...parameters);
|
|
146
|
-
}
|
|
147
|
-
throw new Error(
|
|
148
|
-
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|
|
153
3
|
//# sourceMappingURL=out.js.map
|
|
154
4
|
//# sourceMappingURL=index.js.map
|