atom.io 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.cjs +9 -0
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.js +9 -0
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +9 -0
- package/dist/{chunk-K22LR3V6.js → chunk-RLZQ6IIY.js} +11 -2
- package/dist/chunk-RLZQ6IIY.js.map +1 -0
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +89 -72
- package/dist/index.js +1 -1
- package/internal/dist/index.cjs +16 -16
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +18 -18
- package/internal/dist/index.js +17 -17
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-regular-atom.ts +1 -1
- package/internal/src/mutable/tracker.ts +3 -3
- package/internal/src/operation.ts +1 -1
- package/internal/src/selector/create-read-write-selector.ts +1 -1
- package/internal/src/selector/create-readonly-selector.ts +1 -1
- package/internal/src/store/store.ts +4 -4
- package/internal/src/store/withdraw.ts +7 -9
- package/internal/src/subscribe/subscribe-to-timeline.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +7 -7
- package/internal/src/timeline/create-timeline.ts +29 -21
- package/internal/src/timeline/time-travel.ts +1 -1
- package/internal/src/transaction/apply-transaction.ts +2 -2
- package/internal/src/transaction/build-transaction.ts +1 -1
- package/internal/src/transaction/create-transaction.ts +1 -1
- package/introspection/dist/index.cjs +9 -9
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +2 -2
- package/introspection/dist/index.js +9 -9
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +2 -2
- package/introspection/src/attach-introspection-states.ts +2 -2
- package/introspection/src/attach-selector-index.ts +2 -2
- package/introspection/src/attach-timeline-family.ts +6 -6
- package/introspection/src/attach-timeline-index.ts +6 -4
- package/introspection/src/attach-transaction-index.ts +1 -1
- package/package.json +8 -9
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js.map +1 -1
- package/react/src/store-hooks.ts +1 -1
- package/react-devtools/dist/index.cjs +7 -9
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.ts +7 -262
- package/react-devtools/dist/index.js +7 -9
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/TimelineIndex.tsx +2 -2
- package/react-devtools/src/Updates.tsx +1 -1
- package/realtime-client/dist/index.cjs +1 -1
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +2 -2
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/realtime-state.ts +3 -3
- package/realtime-react/dist/index.cjs +2 -4
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.js +2 -4
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/realtime-context.tsx +2 -4
- package/src/index.ts +10 -0
- package/src/subscribe.ts +7 -11
- package/src/timeline.ts +18 -10
- package/src/validators.ts +74 -0
- package/dist/chunk-K22LR3V6.js.map +0 -1
- package/internal/src/set-state/copy-mutable-into-new-store.ts +0 -34
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AACrD;AAoDO,SAAS,WACf,SACsD;AACtD,SAAO,iBAAiB,SA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SAAS,YAAAA,WAAU,qBAAAQ,oBAAmB,YAAAC,iBAAgB;AAyD/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAASR,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeA,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKS,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken:\n\t\t| ReadonlySelectorToken<any>\n\t\t| StateToken<any>\n\t\t| TimelineToken\n\t\t| TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n\tshouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n}>\nexport type TransactorsWithRun = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\trun: typeof runTransaction\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRun,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AACrD;AAoDO,SAAS,WACf,SACsD;AACtD,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;AC3FA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACjBA,YAAYA,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,OAAO,KAAK,MAA9B,YACS,kCAAwB,OAAO,KAAK;AAC9C,MAAI,UAAU,QAAW;AACxB,UAAM,IAAa,wBAAc,OAAO,KAAK;AAAA,EAC9C;AACA,SAAgB,6BAAmB,OAAO,KAAK;AAChD;;;AC0BO,IAAM,aAAa,CAAC,QAAQ,QAAQ,OAAO;AAqB3C,IAAM,YACZ,CAAC,aACD,CAAC,MAAM,WAAW,UAAU,YAAY,SAAS;AAChD,UAAQ,QAAQ,EAAE,GAAG,IAAI,IAAI,SAAS,KAAK,QAAQ,KAAK,OAAO,IAAI,GAAG,IAAI;AAC3E;AACM,IAAM,eAAuB;AAAA,EACnC,OAAO,UAAU,OAAO;AAAA,EACxB,MAAM,UAAU,MAAM;AAAA,EACtB,MAAM,UAAU,MAAM;AACvB;AAEO,IAAM,eAAN,MAAqC;AAAA,EACpC,YACC,UACU,QACA,SAAiB,cACjC;AAHM;AACU;AACA;AAGlB,SAAO,QAA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U,kBAAAK,iBAAgB,cAAAC,mBAAkB;AA0B9C,IAAM,WAAW,CACvB,YACgC;AAChC,SAAOD,gBAAe,SAASL,UAAS,KAAK;AAC9C;AAEO,IAAM,OAAO,CAACO,cAAuC;AAC3D,EAAAD,YAAW,WAAWC,WAAUP,UAAS,KAAK;AAC/C;AAEO,IAAM,OAAO,CAACO,cAAuC;AAC3D,EAAAD,YAAW,YAAYC,WAAUP,UAAS,KAAK;AAChD;;;AC3CA,SAAS,YAAAA,WAAU,qBAAAQ,oBAAmB,YAAAC,iBAAgB;AAyD/C,SAAS,YACf,SACsB;AACtB,SAAOD,mBAAkB,SAASR,UAAS,KAAK;AACjD;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeA,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKS,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;ACjCM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AAsBO,SAAS,UACf,QACA,cACmD;AAvEpD;AAwEC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n}>\nexport type TransactorsWithRun = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\trun: typeof runTransaction\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRun,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n","import type {\n\tAtomFamily,\n\tAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tSelectorFamily,\n\tSelectorToken,\n\tWritableFamily,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends AtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends SelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends AtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<Family>>\nexport function belongsTo<Family extends SelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as Internal from 'atom.io/internal';
|
|
2
2
|
import { Transceiver, Subject, Store, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
3
3
|
import { Json, JsonInterface } from 'atom.io/json';
|
|
4
|
+
import { ReadableFamily as ReadableFamily$1, ReadableToken as ReadableToken$1, AtomToken as AtomToken$1, SelectorToken as SelectorToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableToken as WritableToken$1, AtomFamily as AtomFamily$1, SelectorFamily as SelectorFamily$1, ReadonlySelectorFamily as ReadonlySelectorFamily$1, WritableFamily as WritableFamily$1 } from 'atom.io';
|
|
4
5
|
|
|
5
6
|
type Effectors<T> = {
|
|
6
7
|
setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
|
|
@@ -46,67 +47,6 @@ type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends J
|
|
|
46
47
|
declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
|
|
47
48
|
declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
|
|
48
49
|
|
|
49
|
-
declare function dispose(token: ReadonlySelectorToken<any> | StateToken<any>, store?: Internal.Store): void;
|
|
50
|
-
|
|
51
|
-
declare function getState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Internal.Store): T;
|
|
52
|
-
|
|
53
|
-
declare const LoggerIconDictionary: {
|
|
54
|
-
readonly "\u231B": "Timeline event fully captured";
|
|
55
|
-
readonly "\u23E9": "Timeline redo";
|
|
56
|
-
readonly "\u23EA": "Timeline undo";
|
|
57
|
-
readonly "\u23ED\uFE0F": "Transaction redo";
|
|
58
|
-
readonly "\u23EE\uFE0F": "Transaction undo";
|
|
59
|
-
readonly "\u23F3": "Timeline event partially captured";
|
|
60
|
-
readonly "\u23F9\uFE0F": "Time-travel complete";
|
|
61
|
-
readonly "\uD83D\uDC81": "Notice";
|
|
62
|
-
readonly "\uD83D\uDD04": "Realtime transaction synchronized";
|
|
63
|
-
readonly "\u2705": "Realtime transaction success";
|
|
64
|
-
readonly "\u2728": "Computation complete";
|
|
65
|
-
readonly "\u274C": "Conflict prevents attempted action";
|
|
66
|
-
readonly "\u2B55": "Operation start";
|
|
67
|
-
readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
|
|
68
|
-
readonly "\uD83D\uDC40": "Subscription added";
|
|
69
|
-
readonly "\uD83D\uDC6A": "Family member added";
|
|
70
|
-
readonly "\uD83D\uDCC1": "Stow update";
|
|
71
|
-
readonly "\uD83D\uDCC3": "Copy mutable";
|
|
72
|
-
readonly "\uD83D\uDCD6": "Read state";
|
|
73
|
-
readonly "\uD83D\uDCDD": "Write state";
|
|
74
|
-
readonly "\uD83D\uDCE2": "Notify subscribers";
|
|
75
|
-
readonly "\uD83D\uDD0C": "Register dependency";
|
|
76
|
-
readonly "\uD83D\uDD0D": "Discover root";
|
|
77
|
-
readonly "\uD83D\uDD25": "Delete state";
|
|
78
|
-
readonly "\uD83D\uDD27": "Create mutable atom";
|
|
79
|
-
readonly "\uD83D\uDD28": "Create immutable atom";
|
|
80
|
-
readonly "\uD83D\uDD34": "Operation complete";
|
|
81
|
-
readonly "\uD83D\uDDD1": "Evict cached value";
|
|
82
|
-
readonly "\uD83D\uDCA5": "Caught";
|
|
83
|
-
readonly "\uD83D\uDE48": "Subscription canceled";
|
|
84
|
-
readonly "\uD83D\uDEC4": "Apply transaction";
|
|
85
|
-
readonly "\uD83D\uDEE0\uFE0F": "Install atom into store";
|
|
86
|
-
readonly "\uD83D\uDEEB": "Begin transaction";
|
|
87
|
-
readonly "\uD83D\uDEEC": "Complete transaction";
|
|
88
|
-
readonly "\uD83E\uDDEE": "Computing selector";
|
|
89
|
-
readonly "\uD83E\uDDF9": "Prepare to evict";
|
|
90
|
-
readonly "\uD83E\uDE82": "Abort transaction";
|
|
91
|
-
};
|
|
92
|
-
type LoggerIcon = keyof typeof LoggerIconDictionary;
|
|
93
|
-
declare const LOG_LEVELS: readonly ["info", "warn", "error"];
|
|
94
|
-
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
95
|
-
type LogFn = (icon: LoggerIcon, tokenType: `atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
96
|
-
type LogFilter = (...params: Parameters<LogFn>) => boolean;
|
|
97
|
-
type Logger = Record<LogLevel, LogFn>;
|
|
98
|
-
declare const simpleLog: (logLevel: keyof Logger) => LogFn;
|
|
99
|
-
declare const simpleLogger: Logger;
|
|
100
|
-
declare class AtomIOLogger implements Logger {
|
|
101
|
-
logLevel: `error` | `info` | `warn` | null;
|
|
102
|
-
private readonly filter?;
|
|
103
|
-
private readonly logger;
|
|
104
|
-
constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter | undefined, logger?: Logger);
|
|
105
|
-
error: LogFn;
|
|
106
|
-
info: LogFn;
|
|
107
|
-
warn: LogFn;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
50
|
type TransactionToken<_> = {
|
|
111
51
|
key: string;
|
|
112
52
|
type: `transaction`;
|
|
@@ -174,6 +114,67 @@ type ReadonlySelectorFamily<T, K extends Json.Serializable = Json.Serializable>
|
|
|
174
114
|
declare function selectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
|
|
175
115
|
declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
|
|
176
116
|
|
|
117
|
+
declare function dispose(token: ReadonlySelectorToken<any> | StateToken<any>, store?: Internal.Store): void;
|
|
118
|
+
|
|
119
|
+
declare function getState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Internal.Store): T;
|
|
120
|
+
|
|
121
|
+
declare const LoggerIconDictionary: {
|
|
122
|
+
readonly "\u231B": "Timeline event fully captured";
|
|
123
|
+
readonly "\u23E9": "Timeline redo";
|
|
124
|
+
readonly "\u23EA": "Timeline undo";
|
|
125
|
+
readonly "\u23ED\uFE0F": "Transaction redo";
|
|
126
|
+
readonly "\u23EE\uFE0F": "Transaction undo";
|
|
127
|
+
readonly "\u23F3": "Timeline event partially captured";
|
|
128
|
+
readonly "\u23F9\uFE0F": "Time-travel complete";
|
|
129
|
+
readonly "\uD83D\uDC81": "Notice";
|
|
130
|
+
readonly "\uD83D\uDD04": "Realtime transaction synchronized";
|
|
131
|
+
readonly "\u2705": "Realtime transaction success";
|
|
132
|
+
readonly "\u2728": "Computation complete";
|
|
133
|
+
readonly "\u274C": "Conflict prevents attempted action";
|
|
134
|
+
readonly "\u2B55": "Operation start";
|
|
135
|
+
readonly "\uD83D\uDC1E": "Possible bug in AtomIO";
|
|
136
|
+
readonly "\uD83D\uDC40": "Subscription added";
|
|
137
|
+
readonly "\uD83D\uDC6A": "Family member added";
|
|
138
|
+
readonly "\uD83D\uDCC1": "Stow update";
|
|
139
|
+
readonly "\uD83D\uDCC3": "Copy mutable";
|
|
140
|
+
readonly "\uD83D\uDCD6": "Read state";
|
|
141
|
+
readonly "\uD83D\uDCDD": "Write state";
|
|
142
|
+
readonly "\uD83D\uDCE2": "Notify subscribers";
|
|
143
|
+
readonly "\uD83D\uDD0C": "Register dependency";
|
|
144
|
+
readonly "\uD83D\uDD0D": "Discover root";
|
|
145
|
+
readonly "\uD83D\uDD25": "Delete state";
|
|
146
|
+
readonly "\uD83D\uDD27": "Create mutable atom";
|
|
147
|
+
readonly "\uD83D\uDD28": "Create immutable atom";
|
|
148
|
+
readonly "\uD83D\uDD34": "Operation complete";
|
|
149
|
+
readonly "\uD83D\uDDD1": "Evict cached value";
|
|
150
|
+
readonly "\uD83D\uDCA5": "Caught";
|
|
151
|
+
readonly "\uD83D\uDE48": "Subscription canceled";
|
|
152
|
+
readonly "\uD83D\uDEC4": "Apply transaction";
|
|
153
|
+
readonly "\uD83D\uDEE0\uFE0F": "Install atom into store";
|
|
154
|
+
readonly "\uD83D\uDEEB": "Begin transaction";
|
|
155
|
+
readonly "\uD83D\uDEEC": "Complete transaction";
|
|
156
|
+
readonly "\uD83E\uDDEE": "Computing selector";
|
|
157
|
+
readonly "\uD83E\uDDF9": "Prepare to evict";
|
|
158
|
+
readonly "\uD83E\uDE82": "Abort transaction";
|
|
159
|
+
};
|
|
160
|
+
type LoggerIcon = keyof typeof LoggerIconDictionary;
|
|
161
|
+
declare const LOG_LEVELS: readonly ["info", "warn", "error"];
|
|
162
|
+
type LogLevel = (typeof LOG_LEVELS)[number];
|
|
163
|
+
type LogFn = (icon: LoggerIcon, tokenType: `atom` | `readonly_selector` | `selector` | `state` | `timeline` | `transaction` | `unknown`, tokenKey: string, message: string, ...rest: unknown[]) => void;
|
|
164
|
+
type LogFilter = (...params: Parameters<LogFn>) => boolean;
|
|
165
|
+
type Logger = Record<LogLevel, LogFn>;
|
|
166
|
+
declare const simpleLog: (logLevel: keyof Logger) => LogFn;
|
|
167
|
+
declare const simpleLogger: Logger;
|
|
168
|
+
declare class AtomIOLogger implements Logger {
|
|
169
|
+
logLevel: `error` | `info` | `warn` | null;
|
|
170
|
+
private readonly filter?;
|
|
171
|
+
private readonly logger;
|
|
172
|
+
constructor(logLevel: `error` | `info` | `warn` | null, filter?: LogFilter | undefined, logger?: Logger);
|
|
173
|
+
error: LogFn;
|
|
174
|
+
info: LogFn;
|
|
175
|
+
warn: LogFn;
|
|
176
|
+
}
|
|
177
|
+
|
|
177
178
|
declare function setState<T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Internal.Store): void;
|
|
178
179
|
|
|
179
180
|
declare class Silo {
|
|
@@ -202,23 +203,37 @@ type KeyedStateUpdate<T> = StateUpdate<T> & {
|
|
|
202
203
|
};
|
|
203
204
|
type UpdateHandler<T> = (update: StateUpdate<T>) => void;
|
|
204
205
|
type TransactionUpdateHandler<ƒ extends ƒn> = (data: TransactionUpdate<ƒ>) => void;
|
|
205
|
-
declare function subscribe<T>(token:
|
|
206
|
+
declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string, store?: Store): () => void;
|
|
206
207
|
declare function subscribe<ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, key?: string, store?: Store): () => void;
|
|
207
|
-
declare function subscribe(token: TimelineToken
|
|
208
|
+
declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string, store?: Store): () => void;
|
|
208
209
|
|
|
209
|
-
type
|
|
210
|
+
type TimelineManageable = AtomFamily<any, any> | AtomToken<any>;
|
|
211
|
+
type TimelineToken<_> = {
|
|
210
212
|
key: string;
|
|
211
213
|
type: `timeline`;
|
|
214
|
+
__brand?: _;
|
|
212
215
|
};
|
|
213
|
-
type TimelineOptions = {
|
|
216
|
+
type TimelineOptions<ManagedAtom extends TimelineManageable> = {
|
|
214
217
|
key: string;
|
|
215
|
-
atoms:
|
|
216
|
-
shouldCapture?: (update: TimelineUpdate
|
|
218
|
+
atoms: ManagedAtom[];
|
|
219
|
+
shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
|
|
217
220
|
};
|
|
218
|
-
type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
|
|
219
|
-
declare const timeline: (options: TimelineOptions) => TimelineToken
|
|
220
|
-
declare const redo: (timeline: TimelineToken) => void;
|
|
221
|
-
declare const undo: (timeline: TimelineToken) => void;
|
|
221
|
+
type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineSelectorUpdate<ManagedAtom> | TimelineTransactionUpdate;
|
|
222
|
+
declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
|
|
223
|
+
declare const redo: (timeline: TimelineToken<any>) => void;
|
|
224
|
+
declare const undo: (timeline: TimelineToken<any>) => void;
|
|
225
|
+
|
|
226
|
+
type TokenType<Comparison extends ReadableFamily$1<any, any> | ReadableToken$1<any>> = Comparison extends ReadableToken$1<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamily$1<infer RepresentedValue, any> ? RepresentedValue : never;
|
|
227
|
+
declare function isToken<KnownToken extends AtomToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<unknown>): unknownToken is AtomToken$1<TokenType<KnownToken>>;
|
|
228
|
+
declare function isToken<KnownToken extends SelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<unknown>): unknownToken is SelectorToken$1<TokenType<KnownToken>>;
|
|
229
|
+
declare function isToken<KnownToken extends ReadonlySelectorToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<unknown>): unknownToken is ReadonlySelectorToken$1<TokenType<KnownToken>>;
|
|
230
|
+
declare function isToken<KnownToken extends WritableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<unknown>): unknownToken is WritableToken$1<TokenType<KnownToken>>;
|
|
231
|
+
declare function isToken<KnownToken extends WritableToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<unknown>): unknownToken is ReadableToken$1<TokenType<KnownToken>>;
|
|
232
|
+
declare function belongsTo<Family extends AtomFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<unknown>): unknownToken is AtomToken$1<TokenType<Family>>;
|
|
233
|
+
declare function belongsTo<Family extends SelectorFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<unknown>): unknownToken is SelectorToken$1<TokenType<Family>>;
|
|
234
|
+
declare function belongsTo<Family extends ReadonlySelectorFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<unknown>): unknownToken is ReadonlySelectorToken$1<TokenType<Family>>;
|
|
235
|
+
declare function belongsTo<Family extends WritableFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<unknown>): unknownToken is WritableToken$1<TokenType<Family>>;
|
|
236
|
+
declare function belongsTo<Family extends ReadableFamily$1<any, any>>(family: Family, unknownToken: ReadableToken$1<unknown>): unknownToken is ReadableToken$1<TokenType<Family>>;
|
|
222
237
|
|
|
223
238
|
type ƒn = (...parameters: any[]) => any;
|
|
224
239
|
type AtomToken<_> = {
|
|
@@ -243,6 +258,8 @@ type SelectorToken<_> = {
|
|
|
243
258
|
type StateToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
244
259
|
type WritableToken<T> = AtomToken<T> | SelectorToken<T>;
|
|
245
260
|
type ReadableToken<T> = ReadonlySelectorToken<T> | WritableToken<T>;
|
|
261
|
+
type WritableFamily<T, K extends Json.Serializable> = AtomFamily<T, K> | SelectorFamily<T, K>;
|
|
262
|
+
type ReadableFamily<T, K extends Json.Serializable> = ReadonlySelectorFamily<T, K> | WritableFamily<T, K>;
|
|
246
263
|
type ReadonlySelectorToken<_> = {
|
|
247
264
|
key: string;
|
|
248
265
|
type: `readonly_selector`;
|
|
@@ -254,4 +271,4 @@ type FamilyMetadata = {
|
|
|
254
271
|
subKey: string;
|
|
255
272
|
};
|
|
256
273
|
|
|
257
|
-
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, AtomIOLogger, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type SelectorFamily, type SelectorFamilyOptions, type SelectorOptions, type SelectorToken, Silo, type StateToken, type StateUpdate, type TimelineOptions, type TimelineToken, type TimelineUpdate, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type TransactorsWithRun, type UpdateHandler, type WritableToken, type Write, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, type ƒn };
|
|
274
|
+
export { type AtomEffect, type AtomFamily, type AtomFamilyOptions, AtomIOLogger, type AtomOptions, type AtomToken, type Effectors, type FamilyMetadata, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type SelectorFamily, type SelectorFamilyOptions, type SelectorOptions, type SelectorToken, Silo, type StateToken, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateHandler, type Transactors, type TransactorsWithRun, type UpdateHandler, type WritableFamily, type WritableToken, type Write, atom, atomFamily, belongsTo, dispose, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo, type ƒn };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo } from './chunk-
|
|
1
|
+
export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, dispose, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo } from './chunk-RLZQ6IIY.js';
|
|
2
2
|
import './chunk-PZLG2HP3.js';
|
|
3
3
|
//# sourceMappingURL=out.js.map
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/internal/dist/index.cjs
CHANGED
|
@@ -226,7 +226,7 @@ var closeOperation = (store) => {
|
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
store.operation = { open: false };
|
|
229
|
-
store.
|
|
229
|
+
store.on.operationClose.next(store.operation);
|
|
230
230
|
};
|
|
231
231
|
var isDone = (key, store) => {
|
|
232
232
|
if (!store.operation.open) {
|
|
@@ -712,13 +712,13 @@ var Store = class {
|
|
|
712
712
|
makeContentKey: (...keys) => keys.sort().join(`:`)
|
|
713
713
|
}
|
|
714
714
|
);
|
|
715
|
-
this.
|
|
715
|
+
this.on = {
|
|
716
716
|
atomCreation: new Subject(),
|
|
717
717
|
selectorCreation: new Subject(),
|
|
718
718
|
transactionCreation: new Subject(),
|
|
719
719
|
timelineCreation: new Subject(),
|
|
720
720
|
transactionApplying: new StatefulSubject(null),
|
|
721
|
-
|
|
721
|
+
operationClose: new Subject()
|
|
722
722
|
};
|
|
723
723
|
this.operation = { open: false };
|
|
724
724
|
this.transactionMeta = null;
|
|
@@ -1011,7 +1011,7 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
1011
1011
|
if (family) {
|
|
1012
1012
|
token.family = family;
|
|
1013
1013
|
}
|
|
1014
|
-
store.
|
|
1014
|
+
store.on.selectorCreation.next(token);
|
|
1015
1015
|
return token;
|
|
1016
1016
|
};
|
|
1017
1017
|
|
|
@@ -1047,7 +1047,7 @@ var createReadonlySelector = (options, family, store) => {
|
|
|
1047
1047
|
if (family) {
|
|
1048
1048
|
token.family = family;
|
|
1049
1049
|
}
|
|
1050
|
-
store.
|
|
1050
|
+
store.on.selectorCreation.next(token);
|
|
1051
1051
|
return token;
|
|
1052
1052
|
};
|
|
1053
1053
|
|
|
@@ -1258,7 +1258,7 @@ var Tracker = class {
|
|
|
1258
1258
|
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
1259
1259
|
(update) => {
|
|
1260
1260
|
if (target.operation.open) {
|
|
1261
|
-
const unsubscribe = target.
|
|
1261
|
+
const unsubscribe = target.on.operationClose.subscribe(
|
|
1262
1262
|
mutableState.key,
|
|
1263
1263
|
() => {
|
|
1264
1264
|
unsubscribe();
|
|
@@ -1281,7 +1281,7 @@ var Tracker = class {
|
|
|
1281
1281
|
`tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
|
|
1282
1282
|
(update2) => {
|
|
1283
1283
|
if (target2.operation.open) {
|
|
1284
|
-
const unsubscribe = target2.
|
|
1284
|
+
const unsubscribe = target2.on.operationClose.subscribe(
|
|
1285
1285
|
mutableState.key,
|
|
1286
1286
|
() => {
|
|
1287
1287
|
unsubscribe();
|
|
@@ -1333,7 +1333,7 @@ var Tracker = class {
|
|
|
1333
1333
|
return;
|
|
1334
1334
|
}
|
|
1335
1335
|
}
|
|
1336
|
-
const unsubscribe = store.
|
|
1336
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
1337
1337
|
latestUpdateState.key,
|
|
1338
1338
|
() => {
|
|
1339
1339
|
unsubscribe();
|
|
@@ -1691,7 +1691,7 @@ function createRegularAtom(options, family, store) {
|
|
|
1691
1691
|
}
|
|
1692
1692
|
};
|
|
1693
1693
|
}
|
|
1694
|
-
store.
|
|
1694
|
+
store.on.atomCreation.next(token);
|
|
1695
1695
|
return token;
|
|
1696
1696
|
}
|
|
1697
1697
|
|
|
@@ -1804,8 +1804,8 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1804
1804
|
const target = newest(store);
|
|
1805
1805
|
const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
|
|
1806
1806
|
const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
|
|
1807
|
-
const currentTransactionKey = (_a = target.
|
|
1808
|
-
const currentTransactionTime = (_b = target.
|
|
1807
|
+
const currentTransactionKey = (_a = target.on.transactionApplying.state) == null ? void 0 : _a.update.key;
|
|
1808
|
+
const currentTransactionTime = (_b = target.on.transactionApplying.state) == null ? void 0 : _b.time;
|
|
1809
1809
|
store.logger.info(
|
|
1810
1810
|
`\u23F3`,
|
|
1811
1811
|
`timeline`,
|
|
@@ -2085,7 +2085,7 @@ function createTimeline(options, store, data) {
|
|
|
2085
2085
|
key: timelineKey,
|
|
2086
2086
|
type: `timeline`
|
|
2087
2087
|
};
|
|
2088
|
-
store.
|
|
2088
|
+
store.on.timelineCreation.next(token);
|
|
2089
2089
|
return token;
|
|
2090
2090
|
}
|
|
2091
2091
|
var timeTravel = (direction, token, store) => {
|
|
@@ -2239,7 +2239,7 @@ var applyTransaction = (output, store) => {
|
|
|
2239
2239
|
child.transactionMeta.phase = `applying`;
|
|
2240
2240
|
child.transactionMeta.update.output = output;
|
|
2241
2241
|
parent.child = null;
|
|
2242
|
-
parent.
|
|
2242
|
+
parent.on.transactionApplying.next(child.transactionMeta);
|
|
2243
2243
|
const { updates } = child.transactionMeta.update;
|
|
2244
2244
|
store.logger.info(
|
|
2245
2245
|
`\u{1F6C4}`,
|
|
@@ -2284,7 +2284,7 @@ var applyTransaction = (output, store) => {
|
|
|
2284
2284
|
} else {
|
|
2285
2285
|
parent.transactionMeta.update.updates.push(child.transactionMeta.update);
|
|
2286
2286
|
}
|
|
2287
|
-
parent.
|
|
2287
|
+
parent.on.transactionApplying.next(null);
|
|
2288
2288
|
};
|
|
2289
2289
|
function getState2(token, store = Internal2__namespace.IMPLICIT.STORE) {
|
|
2290
2290
|
var _a;
|
|
@@ -2323,7 +2323,7 @@ var buildTransaction = (key, params, store) => {
|
|
|
2323
2323
|
const child = {
|
|
2324
2324
|
parent,
|
|
2325
2325
|
child: null,
|
|
2326
|
-
|
|
2326
|
+
on: parent.on,
|
|
2327
2327
|
loggers: parent.loggers,
|
|
2328
2328
|
logger: parent.logger,
|
|
2329
2329
|
config: parent.config,
|
|
@@ -2394,7 +2394,7 @@ function createTransaction2(options, store) {
|
|
|
2394
2394
|
const target = newest(store);
|
|
2395
2395
|
target.transactions.set(newTransaction.key, newTransaction);
|
|
2396
2396
|
const token = deposit(newTransaction);
|
|
2397
|
-
store.
|
|
2397
|
+
store.on.transactionCreation.next(token);
|
|
2398
2398
|
return token;
|
|
2399
2399
|
}
|
|
2400
2400
|
|