atom.io 0.9.9 â 0.10.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/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +36 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -55
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +52 -25
- package/internal/dist/index.d.ts +52 -25
- package/internal/dist/index.js +352 -385
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +349 -385
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/create-atom.ts +5 -5
- package/internal/src/atom/delete-atom.ts +9 -2
- package/internal/src/atom/is-default.ts +2 -2
- package/internal/src/caching.ts +7 -5
- package/internal/src/get-state-internal.ts +4 -4
- package/internal/src/index.ts +1 -0
- package/internal/src/keys.ts +30 -0
- package/internal/src/mutable/create-mutable-atom.ts +2 -2
- package/internal/src/mutable/tracker.ts +1 -1
- package/internal/src/operation.ts +7 -7
- package/internal/src/selector/create-read-write-selector.ts +2 -8
- package/internal/src/selector/create-readonly-selector.ts +1 -1
- package/internal/src/selector/create-selector.ts +5 -3
- package/internal/src/selector/get-selector-dependency-keys.ts +20 -0
- package/internal/src/selector/index.ts +1 -1
- package/internal/src/selector/register-selector.ts +4 -11
- package/internal/src/selector/trace-selector-atoms.ts +26 -26
- package/internal/src/selector/update-selector-atoms.ts +14 -14
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +5 -6
- package/internal/src/set-state/set-atom.ts +1 -4
- package/internal/src/set-state/stow-update.ts +10 -4
- package/internal/src/store/index.ts +0 -1
- package/internal/src/store/store.ts +27 -10
- package/internal/src/store/withdraw-new-family-member.ts +1 -1
- package/internal/src/store/withdraw.ts +1 -1
- package/internal/src/subscribe/recall-state.ts +2 -2
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +7 -8
- package/internal/src/timeline/add-atom-to-timeline.ts +8 -8
- package/internal/src/timeline/time-travel-internal.ts +12 -12
- package/internal/src/timeline/timeline-internal.ts +2 -2
- package/internal/src/transaction/abort-transaction.ts +3 -3
- package/internal/src/transaction/apply-transaction.ts +6 -6
- package/internal/src/transaction/build-transaction.ts +2 -3
- package/internal/src/transaction/redo-transaction.ts +1 -1
- package/internal/src/transaction/transaction-internal.ts +2 -2
- package/internal/src/transaction/undo-transaction.ts +1 -1
- package/package.json +3 -3
- package/react-devtools/dist/index.d.mts +3 -3
- package/react-devtools/dist/index.d.ts +3 -3
- package/realtime-client/dist/index.js +6 -9
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/dist/index.mjs +6 -9
- package/realtime-client/dist/index.mjs.map +1 -1
- package/realtime-client/src/use-server-action.ts +6 -8
- package/src/atom.ts +3 -0
- package/src/logger.ts +25 -36
- package/src/subscribe.ts +7 -7
- package/internal/src/selector/lookup-selector-sources.ts +0 -20
- package/internal/src/store/lookup.ts +0 -26
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Internal from 'atom.io/internal';
|
|
2
2
|
import { Transceiver, Subject, Store, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
3
|
+
export { deleteAtom } from 'atom.io/internal';
|
|
3
4
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
4
5
|
|
|
5
6
|
type Effectors<T> = {
|
|
@@ -48,11 +49,17 @@ declare class NotFoundError extends Error {
|
|
|
48
49
|
constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Internal.Store);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
declare const NO_OP: () => void;
|
|
52
52
|
type Logger = Pick<Console, `error` | `info` | `warn`>;
|
|
53
53
|
declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
|
|
54
|
-
declare
|
|
55
|
-
|
|
54
|
+
declare class AtomIOLogger implements Logger {
|
|
55
|
+
private readonly logger;
|
|
56
|
+
logLevel: `error` | `info` | `warn` | null;
|
|
57
|
+
private readonly filter?;
|
|
58
|
+
constructor(logger: Logger, logLevel: `error` | `info` | `warn` | null, filter?: ((message: string) => boolean) | undefined);
|
|
59
|
+
error(...args: any[]): void;
|
|
60
|
+
info(...args: any[]): void;
|
|
61
|
+
warn(...args: any[]): void;
|
|
62
|
+
}
|
|
56
63
|
|
|
57
64
|
type TransactionToken<_> = {
|
|
58
65
|
key: string;
|
|
@@ -186,4 +193,4 @@ type FamilyMetadata = {
|
|
|
186
193
|
subKey: string;
|
|
187
194
|
};
|
|
188
195
|
|
|
189
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type Logger, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken,
|
|
196
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, AtomIOLogger, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type Logger, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, NotFoundError, 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 TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type UpdateHandler, type Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, type Æn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Internal from 'atom.io/internal';
|
|
2
2
|
import { Transceiver, Subject, Store, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
3
|
+
export { deleteAtom } from 'atom.io/internal';
|
|
3
4
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
4
5
|
|
|
5
6
|
type Effectors<T> = {
|
|
@@ -48,11 +49,17 @@ declare class NotFoundError extends Error {
|
|
|
48
49
|
constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Internal.Store);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
declare const NO_OP: () => void;
|
|
52
52
|
type Logger = Pick<Console, `error` | `info` | `warn`>;
|
|
53
53
|
declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
|
|
54
|
-
declare
|
|
55
|
-
|
|
54
|
+
declare class AtomIOLogger implements Logger {
|
|
55
|
+
private readonly logger;
|
|
56
|
+
logLevel: `error` | `info` | `warn` | null;
|
|
57
|
+
private readonly filter?;
|
|
58
|
+
constructor(logger: Logger, logLevel: `error` | `info` | `warn` | null, filter?: ((message: string) => boolean) | undefined);
|
|
59
|
+
error(...args: any[]): void;
|
|
60
|
+
info(...args: any[]): void;
|
|
61
|
+
warn(...args: any[]): void;
|
|
62
|
+
}
|
|
56
63
|
|
|
57
64
|
type TransactionToken<_> = {
|
|
58
65
|
key: string;
|
|
@@ -186,4 +193,4 @@ type FamilyMetadata = {
|
|
|
186
193
|
subKey: string;
|
|
187
194
|
};
|
|
188
195
|
|
|
189
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type Logger, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken,
|
|
196
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, AtomIOLogger, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type Logger, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, NotFoundError, 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 TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type UpdateHandler, type Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, type Æn };
|
package/dist/index.js
CHANGED
|
@@ -22,22 +22,7 @@ function _interopNamespace(e) {
|
|
|
22
22
|
|
|
23
23
|
var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
27
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
28
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
29
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
30
|
-
var __spreadValues = (a, b) => {
|
|
31
|
-
for (var prop in b || (b = {}))
|
|
32
|
-
if (__hasOwnProp.call(b, prop))
|
|
33
|
-
__defNormalProp(a, prop, b[prop]);
|
|
34
|
-
if (__getOwnPropSymbols)
|
|
35
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
36
|
-
if (__propIsEnum.call(b, prop))
|
|
37
|
-
__defNormalProp(a, prop, b[prop]);
|
|
38
|
-
}
|
|
39
|
-
return a;
|
|
40
|
-
};
|
|
25
|
+
// src/atom.ts
|
|
41
26
|
function atom(options) {
|
|
42
27
|
if (`mutable` in options) {
|
|
43
28
|
return Internal.createMutableAtom(options);
|
|
@@ -79,37 +64,37 @@ var NotFoundError = class extends Error {
|
|
|
79
64
|
);
|
|
80
65
|
}
|
|
81
66
|
};
|
|
82
|
-
|
|
67
|
+
|
|
68
|
+
// src/logger.ts
|
|
83
69
|
var LOG_LEVELS = [
|
|
84
70
|
`info`,
|
|
85
71
|
`warn`,
|
|
86
72
|
`error`
|
|
87
73
|
];
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
store.config.logger[logLevel] = logger__INTERNAL[logLevel];
|
|
99
|
-
}
|
|
74
|
+
var AtomIOLogger = class {
|
|
75
|
+
constructor(logger, logLevel, filter) {
|
|
76
|
+
this.logger = logger;
|
|
77
|
+
this.logLevel = logLevel;
|
|
78
|
+
this.filter = filter;
|
|
79
|
+
}
|
|
80
|
+
error(...args) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, args[0])) != null ? _b : true) && this.logLevel !== null) {
|
|
83
|
+
this.logger.error(...args);
|
|
100
84
|
}
|
|
101
85
|
}
|
|
102
|
-
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
(logLevel) => {
|
|
107
|
-
var _a2;
|
|
108
|
-
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !== NO_OP;
|
|
86
|
+
info(...args) {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, args[0])) != null ? _b : true) && this.logLevel === `info`) {
|
|
89
|
+
this.logger.info(...args);
|
|
109
90
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
91
|
+
}
|
|
92
|
+
warn(...args) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, args[0])) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
95
|
+
this.logger.warn(...args);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
113
98
|
};
|
|
114
99
|
function selector(options) {
|
|
115
100
|
return Internal.createSelector(options);
|
|
@@ -145,7 +130,6 @@ var Silo = class {
|
|
|
145
130
|
}
|
|
146
131
|
};
|
|
147
132
|
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = Internal.IMPLICIT.STORE) {
|
|
148
|
-
var _a;
|
|
149
133
|
const state = Internal.withdraw(token, store);
|
|
150
134
|
if (state === void 0) {
|
|
151
135
|
throw new Error(
|
|
@@ -153,15 +137,13 @@ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2
|
|
|
153
137
|
);
|
|
154
138
|
}
|
|
155
139
|
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
156
|
-
|
|
140
|
+
store.logger.info(`\u{1F440} adding subscription "${key}" to "${state.key}"`);
|
|
157
141
|
const dependencyUnsubFunctions = state.type !== `atom` ? Internal.subscribeToRootAtoms(state, store) : null;
|
|
158
142
|
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
159
|
-
|
|
160
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
143
|
+
store.logger.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
161
144
|
unsubFunction();
|
|
162
145
|
} : () => {
|
|
163
|
-
|
|
164
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
146
|
+
store.logger.info(
|
|
165
147
|
`\u{1F648} unsubscribe from "${state.key}" and its dependencies`
|
|
166
148
|
);
|
|
167
149
|
unsubFunction();
|
|
@@ -172,34 +154,30 @@ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2
|
|
|
172
154
|
return unsubscribe;
|
|
173
155
|
}
|
|
174
156
|
var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = Internal.IMPLICIT.STORE) => {
|
|
175
|
-
var _a;
|
|
176
157
|
const tx = Internal.withdraw(token, store);
|
|
177
158
|
if (tx === void 0) {
|
|
178
159
|
throw new Error(
|
|
179
160
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
180
161
|
);
|
|
181
162
|
}
|
|
182
|
-
|
|
163
|
+
store.logger.info(`\u{1F440} subscribe to transaction "${token.key}"`);
|
|
183
164
|
const unsubscribe = tx.subject.subscribe(key, handleUpdate);
|
|
184
165
|
return () => {
|
|
185
|
-
|
|
186
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from transaction "${token.key}"`);
|
|
166
|
+
store.logger.info(`\u{1F648} unsubscribe from transaction "${token.key}"`);
|
|
187
167
|
unsubscribe();
|
|
188
168
|
};
|
|
189
169
|
};
|
|
190
170
|
var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = Internal.IMPLICIT.STORE) => {
|
|
191
|
-
var _a;
|
|
192
171
|
const tl = Internal.withdraw(token, store);
|
|
193
172
|
if (tl === void 0) {
|
|
194
173
|
throw new Error(
|
|
195
174
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
196
175
|
);
|
|
197
176
|
}
|
|
198
|
-
|
|
177
|
+
store.logger.info(`\u{1F440} subscribe to timeline "${token.key}"`);
|
|
199
178
|
const unsubscribe = tl.subject.subscribe(key, handleUpdate);
|
|
200
179
|
return () => {
|
|
201
|
-
|
|
202
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from timeline "${token.key}"`);
|
|
180
|
+
store.logger.info(`\u{1F648} unsubscribe from timeline "${token.key}"`);
|
|
203
181
|
unsubscribe();
|
|
204
182
|
};
|
|
205
183
|
};
|
|
@@ -225,8 +203,12 @@ var runTransaction = (token, store = Internal.IMPLICIT.STORE) => (...parameters)
|
|
|
225
203
|
);
|
|
226
204
|
};
|
|
227
205
|
|
|
206
|
+
Object.defineProperty(exports, 'deleteAtom', {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function () { return Internal.deleteAtom; }
|
|
209
|
+
});
|
|
210
|
+
exports.AtomIOLogger = AtomIOLogger;
|
|
228
211
|
exports.LOG_LEVELS = LOG_LEVELS;
|
|
229
|
-
exports.NO_OP = NO_OP;
|
|
230
212
|
exports.NotFoundError = NotFoundError;
|
|
231
213
|
exports.Silo = Silo;
|
|
232
214
|
exports.atom = atom;
|
|
@@ -236,7 +218,6 @@ exports.redo = redo;
|
|
|
236
218
|
exports.runTransaction = runTransaction;
|
|
237
219
|
exports.selector = selector;
|
|
238
220
|
exports.selectorFamily = selectorFamily;
|
|
239
|
-
exports.setLogLevel = setLogLevel;
|
|
240
221
|
exports.setState = setState;
|
|
241
222
|
exports.subscribe = subscribe;
|
|
242
223
|
exports.subscribeToTimeline = subscribeToTimeline;
|
|
@@ -244,6 +225,5 @@ exports.subscribeToTransaction = subscribeToTransaction;
|
|
|
244
225
|
exports.timeline = timeline;
|
|
245
226
|
exports.transaction = transaction;
|
|
246
227
|
exports.undo = undo;
|
|
247
|
-
exports.useLogger = useLogger;
|
|
248
228
|
//# sourceMappingURL=out.js.map
|
|
249
229
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,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AAK,YAAY;AAC1D,SAAO,MAAM;AA/Fd,QAAAP;AAgGE,KAAAA,MAAA,MAAM,OAAO,WAAb,gBAAAA,IAAqB,KAAK,wCAAiC,MAAM,GAAG;AACpE,gBAAY;AAAA,EACb;AACD;;;AC7FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAS;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAoBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACxCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,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\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\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)\n\t}\n\treturn createAtom<T>(options)\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}\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}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\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)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const 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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { 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)\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)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\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) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(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) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } 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 function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`ð adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`ð unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`ð unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<Æ extends Æn> = (\n\tdata: TransactionUpdate<Æ>,\n) => void\n\nexport const subscribeToTransaction = <Æ extends Æn>(\n\ttoken: TransactionToken<Æ>,\n\thandleUpdate: TransactionUpdateHandler<Æ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} 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 timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, 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\tatomUpdates: KeyedStateUpdate<unknown>[]\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 TransactionOptions<Æ extends Æn> = {\n\tkey: string\n\tdo: Write<Æ>\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 transaction__INTERNAL(options)\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/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","IMPLICIT","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAgCA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACpGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC,kBAAS,UACnC;AANR;AAOC,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,SAAgB,4BAAmB,OAAO,KAAK;AAChD;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAiC,kBAAS,UAChC;AApBX;AAqBC,QAAM,YAAqB,uBAAc,OAAO,KAAK;AACrD,MAAI,WAAW;AACd;AAAA,EACD;AACA,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,EAAS,4BAAmB,OAAO,OAAO,KAAK;AAC/C,EAAS,wBAAe,KAAK;AAC9B;AAEA,IAAM,aAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,C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M,cAAc,GAAG,QAAQ,UAAU,KAAK,YAAY;AAC1D,SAAO,MAAM;AACZ,UAAM,OAAO,KAAK,wCAAiC,MAAM,GAAG,GAAG;AAC/D,gBAAY;AAAA,EACb;AACD;;;AC7FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAE;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAoBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOF,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAI,gBAAe,OAAOJ,UAAS,KAAK;AACrC;;;ACxCA,SAAS,YAAAA,WAAU,yBAAAK,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeL,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKC,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\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tdeleteAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport { deleteAtom }\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\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)\n\t}\n\treturn createAtom<T>(options)\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}\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}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\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)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const 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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","export type Logger = Pick<Console, `error` | `info` | `warn`>\n\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tprivate readonly logger: Logger,\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: (message: string) => boolean,\n\t) {}\n\n\tpublic error(...args: any[]): void {\n\t\tif ((this.filter?.(args[0]) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info(...args: any[]): void {\n\t\tif ((this.filter?.(args[0]) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn(...args: any[]): void {\n\t\tif (\n\t\t\t(this.filter?.(args[0]) ?? 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 { 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)\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)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\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) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(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) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } 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 function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.logger.info(`ð adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.logger.info(`ð unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`ð unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<Æ extends Æn> = (\n\tdata: TransactionUpdate<Æ>,\n) => void\n\nexport const subscribeToTransaction = <Æ extends Æn>(\n\ttoken: TransactionToken<Æ>,\n\thandleUpdate: TransactionUpdateHandler<Æ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(`ð subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(`ð unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(`ð subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(`ð unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} 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 timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, 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\tatomUpdates: KeyedStateUpdate<unknown>[]\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 TransactionOptions<Æ extends Æn> = {\n\tkey: string\n\tdo: Write<Æ>\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 transaction__INTERNAL(options)\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.mjs
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import * as Internal from 'atom.io/internal';
|
|
2
|
-
import { createMutableAtom, createAtom, createMutableAtomFamily, createAtomFamily,
|
|
2
|
+
import { createMutableAtom, createAtom, createMutableAtomFamily, createAtomFamily, createSelector, createSelectorFamily, Store, transaction__INTERNAL, timeline__INTERNAL, undo__INTERNAL, redo__INTERNAL, withdraw, subscribeToRootAtoms, IMPLICIT } from 'atom.io/internal';
|
|
3
|
+
export { deleteAtom } from 'atom.io/internal';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
5
|
+
// src/atom.ts
|
|
20
6
|
function atom(options) {
|
|
21
7
|
if (`mutable` in options) {
|
|
22
8
|
return createMutableAtom(options);
|
|
@@ -58,37 +44,37 @@ var NotFoundError = class extends Error {
|
|
|
58
44
|
);
|
|
59
45
|
}
|
|
60
46
|
};
|
|
61
|
-
|
|
47
|
+
|
|
48
|
+
// src/logger.ts
|
|
62
49
|
var LOG_LEVELS = [
|
|
63
50
|
`info`,
|
|
64
51
|
`warn`,
|
|
65
52
|
`error`
|
|
66
53
|
];
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
store.config.logger[logLevel] = logger__INTERNAL[logLevel];
|
|
78
|
-
}
|
|
54
|
+
var AtomIOLogger = class {
|
|
55
|
+
constructor(logger, logLevel, filter) {
|
|
56
|
+
this.logger = logger;
|
|
57
|
+
this.logLevel = logLevel;
|
|
58
|
+
this.filter = filter;
|
|
59
|
+
}
|
|
60
|
+
error(...args) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, args[0])) != null ? _b : true) && this.logLevel !== null) {
|
|
63
|
+
this.logger.error(...args);
|
|
79
64
|
}
|
|
80
65
|
}
|
|
81
|
-
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
(logLevel) => {
|
|
86
|
-
var _a2;
|
|
87
|
-
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !== NO_OP;
|
|
66
|
+
info(...args) {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, args[0])) != null ? _b : true) && this.logLevel === `info`) {
|
|
69
|
+
this.logger.info(...args);
|
|
88
70
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
71
|
+
}
|
|
72
|
+
warn(...args) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, args[0])) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
75
|
+
this.logger.warn(...args);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
92
78
|
};
|
|
93
79
|
function selector(options) {
|
|
94
80
|
return createSelector(options);
|
|
@@ -124,7 +110,6 @@ var Silo = class {
|
|
|
124
110
|
}
|
|
125
111
|
};
|
|
126
112
|
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
|
|
127
|
-
var _a;
|
|
128
113
|
const state = withdraw(token, store);
|
|
129
114
|
if (state === void 0) {
|
|
130
115
|
throw new Error(
|
|
@@ -132,15 +117,13 @@ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2
|
|
|
132
117
|
);
|
|
133
118
|
}
|
|
134
119
|
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
135
|
-
|
|
120
|
+
store.logger.info(`\u{1F440} adding subscription "${key}" to "${state.key}"`);
|
|
136
121
|
const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
137
122
|
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
138
|
-
|
|
139
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
123
|
+
store.logger.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
140
124
|
unsubFunction();
|
|
141
125
|
} : () => {
|
|
142
|
-
|
|
143
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
126
|
+
store.logger.info(
|
|
144
127
|
`\u{1F648} unsubscribe from "${state.key}" and its dependencies`
|
|
145
128
|
);
|
|
146
129
|
unsubFunction();
|
|
@@ -151,34 +134,30 @@ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2
|
|
|
151
134
|
return unsubscribe;
|
|
152
135
|
}
|
|
153
136
|
var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) => {
|
|
154
|
-
var _a;
|
|
155
137
|
const tx = withdraw(token, store);
|
|
156
138
|
if (tx === void 0) {
|
|
157
139
|
throw new Error(
|
|
158
140
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
159
141
|
);
|
|
160
142
|
}
|
|
161
|
-
|
|
143
|
+
store.logger.info(`\u{1F440} subscribe to transaction "${token.key}"`);
|
|
162
144
|
const unsubscribe = tx.subject.subscribe(key, handleUpdate);
|
|
163
145
|
return () => {
|
|
164
|
-
|
|
165
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from transaction "${token.key}"`);
|
|
146
|
+
store.logger.info(`\u{1F648} unsubscribe from transaction "${token.key}"`);
|
|
166
147
|
unsubscribe();
|
|
167
148
|
};
|
|
168
149
|
};
|
|
169
150
|
var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) => {
|
|
170
|
-
var _a;
|
|
171
151
|
const tl = withdraw(token, store);
|
|
172
152
|
if (tl === void 0) {
|
|
173
153
|
throw new Error(
|
|
174
154
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
175
155
|
);
|
|
176
156
|
}
|
|
177
|
-
|
|
157
|
+
store.logger.info(`\u{1F440} subscribe to timeline "${token.key}"`);
|
|
178
158
|
const unsubscribe = tl.subject.subscribe(key, handleUpdate);
|
|
179
159
|
return () => {
|
|
180
|
-
|
|
181
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from timeline "${token.key}"`);
|
|
160
|
+
store.logger.info(`\u{1F648} unsubscribe from timeline "${token.key}"`);
|
|
182
161
|
unsubscribe();
|
|
183
162
|
};
|
|
184
163
|
};
|
|
@@ -204,6 +183,6 @@ var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
|
204
183
|
);
|
|
205
184
|
};
|
|
206
185
|
|
|
207
|
-
export {
|
|
186
|
+
export { AtomIOLogger, LOG_LEVELS, NotFoundError, Silo, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo };
|
|
208
187
|
//# sourceMappingURL=out.js.map
|
|
209
188
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB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;AAChE,QAAM,cAAc,GAAG,QAAQ,UAAU,KAAK,YAAY;AAC1D,SAAO,MAAM;AA/Fd,QAAAP;AAgGE,KAAAA,MAAA,MAAM,OAAO,WAAb,gBAAAA,IAAqB,KAAK,wCAAiC,MAAM,GAAG;AACpE,gBAAY;AAAA,EACb;AACD;;;AC7FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAS;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAoBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACxCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,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\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\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)\n\t}\n\treturn createAtom<T>(options)\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}\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}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\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)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const 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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tfor (const logLevel of LOG_LEVELS) {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { 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)\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)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\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) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(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) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } 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 function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`ð adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`ð unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`ð unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<Æ extends Æn> = (\n\tdata: TransactionUpdate<Æ>,\n) => void\n\nexport const subscribeToTransaction = <Æ extends Æn>(\n\ttoken: TransactionToken<Æ>,\n\thandleUpdate: TransactionUpdateHandler<Æ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`ð subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`ð unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} 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 timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, 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\tatomUpdates: KeyedStateUpdate<unknown>[]\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 TransactionOptions<Æ extends Æn> = {\n\tkey: string\n\tdo: Write<Æ>\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 transaction__INTERNAL(options)\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/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","IMPLICIT","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAgCA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,OAAO;AAAA,EACjC;AACA,SAAO,WAAc,OAAO;AAC7B;AA+CO,SAAS,WACf,SACsD;AACtD,MAAI,aAAa,SAAS;AACzB,WAAO,wBAAwB,OAAO;AAAA,EACvC;AACA,SAAO,iBAAuB,OAAO;AACtC;;;ACpGA,YAAY,cAAc;AAGnB,IAAM,WAAW,CACvB,OACA,QAAiC,kBAAS,UACnC;AANR;AAOC,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,SAAgB,4BAAmB,OAAO,KAAK;AAChD;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAiC,kBAAS,UAChC;AApBX;AAqBC,QAAM,YAAqB,uBAAc,OAAO,KAAK;AACrD,MAAI,WAAW;AACd;AAAA,EACD;AACA,QAAM,SACL,KAAS,kBAAS,OAAO,KAAK,MAA9B,YACS,iCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAI,cAAc,OAAO,KAAK;AAAA,EACrC;AACA,EAAS,4BAAmB,OAAO,OAAO,KAAK;AAC/C,EAAS,wBAAe,KAAK;AAC9B;AAEA,IAAM,aAAa,CAAC,QAAgB,IAA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K,oCAA6B,MAAM,GAAG,GAAG;AAC3D,QAAM,cAAc,GAAG,QAAQ,UAAU,KAAK,YAAY;AAC1D,SAAO,MAAM;AACZ,UAAM,OAAO,KAAK,wCAAiC,MAAM,GAAG,GAAG;AAC/D,gBAAY;AAAA,EACb;AACD;;;AC7FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAE;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAoBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOF,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAI,gBAAe,OAAOJ,UAAS,KAAK;AACrC;;;ACxCA,SAAS,YAAAA,WAAU,yBAAAK,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeL,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKC,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\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tdeleteAtom,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport { deleteAtom }\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\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)\n\t}\n\treturn createAtom<T>(options)\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}\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}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\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)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const 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 NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const 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 NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","export type Logger = Pick<Console, `error` | `info` | `warn`>\n\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tprivate readonly logger: Logger,\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: (message: string) => boolean,\n\t) {}\n\n\tpublic error(...args: any[]): void {\n\t\tif ((this.filter?.(args[0]) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info(...args: any[]): void {\n\t\tif ((this.filter?.(args[0]) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn(...args: any[]): void {\n\t\tif (\n\t\t\t(this.filter?.(args[0]) ?? 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 { 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)\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)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\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) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(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) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } 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 function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.logger.info(`ð adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.logger.info(`ð unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`ð unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<Æ extends Æn> = (\n\tdata: TransactionUpdate<Æ>,\n) => void\n\nexport const subscribeToTransaction = <Æ extends Æn>(\n\ttoken: TransactionToken<Æ>,\n\thandleUpdate: TransactionUpdateHandler<Æ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(`ð subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(`ð unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.logger.info(`ð subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(`ð unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} 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 timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, 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\tatomUpdates: KeyedStateUpdate<unknown>[]\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 TransactionOptions<Æ extends Æn> = {\n\tkey: string\n\tdo: Write<Æ>\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 transaction__INTERNAL(options)\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"]}
|