cross-state 0.6.10 → 0.7.2

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.
Files changed (79) hide show
  1. package/dist/cjs/hash.cjs +0 -682
  2. package/dist/cjs/hash.cjs.map +1 -1
  3. package/dist/cjs/immer/index.cjs +6 -0
  4. package/dist/cjs/immer/index.cjs.map +1 -0
  5. package/dist/cjs/immer/register.cjs +6 -0
  6. package/dist/cjs/immer/register.cjs.map +1 -0
  7. package/dist/cjs/immerMethods.cjs +23 -0
  8. package/dist/cjs/immerMethods.cjs.map +1 -0
  9. package/dist/cjs/index.cjs +387 -278
  10. package/dist/cjs/index.cjs.map +1 -1
  11. package/dist/cjs/react/index.cjs +54 -0
  12. package/dist/cjs/react/index.cjs.map +1 -0
  13. package/dist/cjs/react/register.cjs +30 -0
  14. package/dist/cjs/react/register.cjs.map +1 -0
  15. package/dist/cjs/scope.cjs +399 -0
  16. package/dist/cjs/scope.cjs.map +1 -0
  17. package/dist/cjs/scope2.cjs +513 -0
  18. package/dist/cjs/scope2.cjs.map +1 -0
  19. package/dist/cjs/store.cjs +798 -0
  20. package/dist/cjs/store.cjs.map +1 -0
  21. package/dist/es/hash.mjs +1 -683
  22. package/dist/es/hash.mjs.map +1 -1
  23. package/dist/es/immer/index.mjs +6 -0
  24. package/dist/es/immer/index.mjs.map +1 -0
  25. package/dist/es/immer/register.mjs +5 -0
  26. package/dist/es/immer/register.mjs.map +1 -0
  27. package/dist/es/immerMethods.mjs +24 -0
  28. package/dist/es/immerMethods.mjs.map +1 -0
  29. package/dist/es/index.mjs +383 -273
  30. package/dist/es/index.mjs.map +1 -1
  31. package/dist/es/react/index.mjs +55 -0
  32. package/dist/es/react/index.mjs.map +1 -0
  33. package/dist/es/react/register.mjs +29 -0
  34. package/dist/es/react/register.mjs.map +1 -0
  35. package/dist/es/scope.mjs +400 -0
  36. package/dist/es/scope.mjs.map +1 -0
  37. package/dist/es/scope2.mjs +514 -0
  38. package/dist/es/scope2.mjs.map +1 -0
  39. package/dist/es/store.mjs +799 -0
  40. package/dist/es/store.mjs.map +1 -0
  41. package/dist/types/core/cache.d.ts +7 -2
  42. package/dist/types/core/commonTypes.d.ts +8 -0
  43. package/dist/types/core/index.d.ts +6 -6
  44. package/dist/types/core/resourceGroup.d.ts +2 -2
  45. package/dist/types/core/scope.d.ts +5 -0
  46. package/dist/types/core/store.d.ts +8 -10
  47. package/dist/types/core/subscriptionCache.d.ts +51 -0
  48. package/dist/types/core/urlStore.d.ts +26 -0
  49. package/dist/types/immer/immerMethods.d.ts +10 -0
  50. package/dist/types/immer/index.d.ts +1 -1
  51. package/dist/types/immer/register.d.ts +7 -0
  52. package/dist/types/index.d.ts +3 -1
  53. package/dist/types/lib/calculationHelper.d.ts +15 -10
  54. package/dist/types/lib/equals.d.ts +3 -3
  55. package/dist/types/lib/path.d.ts +3 -3
  56. package/dist/types/lib/promiseWithState.d.ts +9 -0
  57. package/dist/types/lib/standardMethods.d.ts +2 -1
  58. package/dist/types/lib/trackingProxy.d.ts +2 -1
  59. package/dist/types/lib/typeHelpers.d.ts +3 -1
  60. package/dist/types/lib/updateHelpers.d.ts +1 -0
  61. package/dist/types/react/index.d.ts +3 -1
  62. package/dist/types/react/reactMethods.d.ts +9 -0
  63. package/dist/types/react/register.d.ts +29 -0
  64. package/dist/types/react/scope.d.ts +16 -0
  65. package/dist/types/react/useCache.d.ts +2 -1
  66. package/dist/types/react/useDecoupledState.d.ts +7 -0
  67. package/dist/types/react/useProp.d.ts +1 -2
  68. package/package.json +105 -27
  69. package/dist/cjs/immer.cjs +0 -10
  70. package/dist/cjs/immer.cjs.map +0 -1
  71. package/dist/cjs/react.cjs +0 -292
  72. package/dist/cjs/react.cjs.map +0 -1
  73. package/dist/es/immer.mjs +0 -10
  74. package/dist/es/immer.mjs.map +0 -1
  75. package/dist/es/react.mjs +0 -292
  76. package/dist/es/react.mjs.map +0 -1
  77. package/dist/types/core/storeScope.d.ts +0 -4
  78. package/dist/types/immer/immerActions.d.ts +0 -5
  79. package/dist/types/react/storeScope.d.ts +0 -12
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.mjs","sources":["../../src/lib/calcDuration.ts","../../src/lib/queue.ts","../../src/lib/equals.ts","../../src/lib/trackingProxy.ts","../../src/lib/calculationHelper.ts","../../src/lib/callable.ts","../../src/lib/debounce.ts","../../src/lib/forwardError.ts","../../src/lib/clone.ts","../../src/lib/propAccess.ts","../../src/lib/makeSelector.ts","../../src/lib/standardMethods.ts","../../src/lib/throttle.ts","../../src/core/store.ts"],"sourcesContent":["import type { Duration } from '../core/commonTypes';\n\nexport function calcDuration(t: Duration) {\n if (typeof t === 'number') return t;\n return (\n (t.milliseconds ?? 0) +\n (t.seconds ?? 0) * 1000 +\n (t.minutes ?? 0) * 60 * 1000 +\n (t.hours ?? 0) * 60 * 60 * 1000 +\n (t.days ?? 0) * 24 * 60 * 60 * 1000\n );\n}\n","import type { MaybePromise } from './maybePromise';\nimport type { Listener } from '@core';\n\ntype Action<T> = () => MaybePromise<T>;\n\nexport interface Queue {\n <T>(action: Action<T>, ref?: any): Promise<T>;\n clear: () => void;\n whenDone: () => Promise<void>;\n size: number;\n getRefs: () => any[];\n}\n\nexport function queue(): Queue {\n const q: {\n action: Action<any>;\n resolve: (value: any) => void;\n reject: (error: unknown) => void;\n ref?: any;\n }[] = [];\n const completionListeners = new Set<Listener<void>>();\n let active = false;\n\n const notify = () => {\n for (const listener of completionListeners) {\n listener();\n }\n\n completionListeners.clear();\n };\n\n const run = async () => {\n if (!active) {\n active = true;\n\n let next;\n while ((next = q.shift())) {\n try {\n let result = next.action();\n if (result instanceof Promise) {\n result = await result;\n }\n\n next.resolve(result);\n } catch (error) {\n next.reject(error);\n }\n }\n\n active = false;\n notify();\n }\n };\n\n return Object.assign(\n <T>(action: Action<T>, ref?: any) => {\n return new Promise<T>((resolve, reject) => {\n q.push({ action, resolve, reject, ref });\n run();\n });\n },\n {\n clear() {\n q.length = 0;\n },\n\n whenDone() {\n if (!active) {\n return Promise.resolve();\n }\n\n return new Promise<void>((resolve) => {\n completionListeners.add(resolve);\n });\n },\n\n get size() {\n return q.length;\n },\n\n getRefs() {\n return q.map((item) => item.ref).filter((x) => x !== undefined);\n },\n },\n );\n}\n","export function defaultEqual(a: any, b: any) {\n return a === b;\n}\n\nexport function shallowEqual(a: any, b: any): boolean {\n return internalEqual(defaultEqual)(a, b);\n}\n\nexport function deepEqual(a: any, b: any): boolean {\n return internalEqual(deepEqual)(a, b);\n}\n\nconst internalEqual = (comp: (a: any, b: any) => boolean) => (a: any, b: any) => {\n if (a === b) {\n return true;\n }\n\n if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {\n // eslint-disable-next-line no-self-compare\n return a !== a && b !== b;\n }\n\n if (a.constructor !== b.constructor) {\n return false;\n }\n\n if (a.constructor === Object) {\n const entries1 = Object.entries(a);\n const entries2 = Object.entries(b);\n return (\n entries1.length === entries2.length && entries1.every(([key, value]) => comp(value, b[key]))\n );\n }\n\n if (Array.isArray(a)) {\n return a.length === b.length && a.every((value, i) => comp(value, b[i]));\n }\n\n if (a instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n if (a instanceof RegExp) {\n return a.source === b.source && a.flags === b.flags;\n }\n\n if (a instanceof Map) {\n return a.size === b.size && [...a.entries()].every(([key, value]) => comp(value, b.get(key)));\n }\n\n if (a instanceof Set) {\n return a.size === b.size && [...a.values()].every((value) => b.has(value));\n }\n\n if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(a)) {\n if (a.byteLength !== b.byteLength) {\n return false;\n }\n\n const a_ = new Int8Array(a.buffer);\n const b_ = new Int8Array(b.buffer);\n return a_.every((value, i) => value === b_[i]);\n }\n\n return false;\n};\n","import { deepEqual } from './equals';\n\nexport type TrackingProxy<T> = [value: T, equals: (newValue: T) => boolean];\ntype Object_ = Record<string | symbol, unknown>;\n\nfunction isPlainObject(value: unknown) {\n return (\n typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype\n );\n}\n\nexport function trackingProxy<T>(value: T, equals = deepEqual): TrackingProxy<T> {\n if (!isPlainObject(value) && !Array.isArray(value)) {\n return [value, (other) => equals(value, other)];\n }\n\n const deps = new Array<TrackingProxy<any>[1]>();\n\n function trackComplexProp(function_: any, ...args: any[]) {\n const [proxiedValue, equals] = trackingProxy(function_(value, ...args));\n\n deps.push((otherValue) => {\n if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {\n return false;\n }\n\n return equals(function_(otherValue, ...args));\n });\n\n return proxiedValue;\n }\n\n function trackSimpleProp(function_: any, ...args: any[]) {\n const calculatedValue = function_(value, ...args);\n\n deps.push((otherValue) => {\n return function_(otherValue, ...args) === calculatedValue;\n });\n\n return calculatedValue;\n }\n\n const proxy = new Proxy(value as T & Object_, {\n get(target, p, receiver) {\n const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};\n if (writable === false && configurable === false) {\n return target[p];\n }\n\n return trackComplexProp(Reflect.get, p, receiver);\n },\n\n getOwnPropertyDescriptor(target, p) {\n const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};\n if (writable === false && configurable === false) {\n return Reflect.getOwnPropertyDescriptor(target, p);\n }\n\n return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);\n },\n\n ownKeys() {\n return trackComplexProp(Reflect.ownKeys);\n },\n\n getPrototypeOf() {\n return trackSimpleProp(Reflect.getPrototypeOf);\n },\n\n has(_target, p) {\n return trackSimpleProp(Reflect.has, p);\n },\n\n isExtensible() {\n return trackSimpleProp(Reflect.isExtensible);\n },\n });\n\n return [proxy, (other) => !!other && deps.every((equals) => equals(other))];\n}\n","import type { MaybePromise } from './maybePromise';\nimport { queue } from './queue';\nimport { trackingProxy } from './trackingProxy';\nimport { deepEqual } from './equals';\nimport type { Store } from '@core/store';\nimport type {\n CalculationHelpers,\n Cancel,\n ConnectionState,\n UpdateFrom,\n Use,\n} from '@core/commonTypes';\n\nexport class CalculationHelper<T> {\n private current?: {\n cancel: Cancel;\n check: () => void;\n invalidateDependencies: () => void;\n };\n\n constructor(\n public options: {\n calculate: (helpers: CalculationHelpers<T>) => Cancel | void;\n addEffect: (effect: () => Cancel | void) => Cancel;\n getValue?: () => T | undefined;\n onValue?: (value: T) => void;\n onError?: (error: unknown) => void;\n onConnectionState?: (state: ConnectionState) => void;\n onInvalidate?: () => void;\n },\n ) {\n options.addEffect(() => {\n if (this.current) {\n this.current.check();\n } else {\n this.execute();\n }\n });\n }\n\n execute() {\n this.stop();\n\n const { calculate, addEffect, getValue, onValue, onError, onConnectionState, onInvalidate } =\n this.options;\n const checks = new Array<() => boolean>();\n const deps = new Map<Store<any>, { on: () => void; off: () => void; invalidate: () => void }>();\n const q = queue();\n let isActive = false;\n let isCancled = false;\n\n const cancelEffect = addEffect(() => {\n isActive = true;\n\n for (const dep of deps.values()) {\n dep.on();\n }\n\n return () => {\n isActive = false;\n\n for (const dep of deps.values()) {\n dep.off();\n }\n\n if (cancelSubscription) {\n cancelSubscription();\n cancelSubscription = undefined;\n cancel();\n onInvalidate?.();\n }\n };\n });\n\n const cancel = () => {\n isCancled = true;\n cancelSubscription?.();\n cancelEffect();\n delete this.current;\n };\n\n const checkAll = () => {\n if (!checks.every((check) => check())) {\n cancel();\n onInvalidate?.();\n }\n };\n\n const invalidateDependencies = () => {\n for (const dep of deps.values()) {\n dep.invalidate();\n }\n };\n\n const use: Use = (store, { disableProxy } = {}) => {\n if (isCancled) {\n return store.get();\n }\n\n let value = store.get();\n let equals = (newValue: any) => {\n return deepEqual(newValue, value);\n };\n\n if (!disableProxy) {\n [value, equals] = trackingProxy(value);\n }\n\n const check = () => equals(store.get());\n let sub: Cancel | undefined;\n\n const dep = {\n on() {\n this.off();\n\n sub = store.subscribe(\n () => {\n if (sub && !check()) {\n cancel();\n onInvalidate?.();\n }\n },\n { runNow: false },\n );\n },\n off() {\n sub?.();\n sub = undefined;\n },\n invalidate() {\n if ('invalidate' in store && store.invalidate instanceof Function) {\n store.invalidate();\n }\n },\n };\n\n if (isActive) {\n dep.on();\n }\n\n checks.push(check);\n deps.set(store, dep);\n\n return value;\n };\n\n const updateValue = (update: UpdateFrom<MaybePromise<T>, [T | undefined]>) =>\n q(async () => {\n if (isCancled) {\n return;\n }\n\n if (update instanceof Function) {\n try {\n update = update(getValue?.());\n } catch (error) {\n onError?.(error);\n return;\n }\n }\n\n if (update instanceof Promise) {\n try {\n update = await update;\n } catch (error) {\n if (!isCancled) {\n onError?.(error);\n }\n return;\n }\n }\n\n if (!isCancled) {\n onValue?.(update);\n }\n });\n\n const updateError = (error: unknown) =>\n q(() => {\n if (!isCancled) {\n onError?.(error);\n }\n });\n\n const updateConnectionState = (state: ConnectionState) =>\n q(() => {\n if (!isCancled) {\n onConnectionState?.(state);\n }\n });\n\n let cancelSubscription: Cancel | void;\n try {\n cancelSubscription = calculate({ use, updateValue, updateError, updateConnectionState });\n } catch (error) {\n onError?.(error);\n }\n\n this.current = { cancel, check: checkAll, invalidateDependencies };\n }\n\n stop() {\n this.current?.cancel();\n }\n\n check() {\n this.current?.check();\n }\n\n checkOrExecute() {\n if (this.current) {\n this.check();\n } else {\n this.execute();\n }\n }\n\n invalidateDependencies() {\n this.current?.invalidateDependencies();\n }\n}\n","export class Callable<Args extends any[], T> extends Function {\n constructor(protected _call: (...args: Args) => T) {\n super('...args', 'return this._call(...args)');\n\n // eslint-disable-next-line no-constructor-return\n return this.bind(this);\n }\n}\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport type DebounceOptions =\n | Duration\n | {\n wait: Duration;\n maxWait?: Duration;\n };\n\nexport function debounce<Args extends any[]>(\n action: (...args: Args) => void,\n options: Duration | DebounceOptions,\n): (...args: Args) => void {\n const wait =\n typeof options === 'object' && 'wait' in options\n ? calcDuration(options.wait)\n : calcDuration(options);\n\n const maxWait =\n typeof options === 'object' && 'maxWait' in options && options.maxWait !== undefined\n ? calcDuration(options.maxWait)\n : undefined;\n\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let timeoutStarted: number | undefined;\n\n return (...args: Args) => {\n const now = Date.now();\n timeoutStarted ??= now;\n\n const deadline = Math.min(\n //\n now + wait,\n timeoutStarted + (maxWait ?? Number.POSITIVE_INFINITY),\n );\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n timeout = setTimeout(() => {\n timeout = undefined;\n timeoutStarted = undefined;\n action(...args);\n }, deadline - now);\n };\n}\n","export function forwardError(error: unknown) {\n setTimeout(() => {\n throw error;\n });\n}\n","export function flatClone<T>(object: T): T {\n if (object instanceof Map) {\n return new Map(object) as any;\n }\n\n if (object instanceof Set) {\n return new Set(object) as any;\n }\n\n if (Array.isArray(object)) {\n return [...object] as any;\n }\n\n if (object instanceof Object) {\n return { ...object };\n }\n\n return object;\n}\n","import type { Update } from '../core/commonTypes';\nimport { flatClone } from './clone';\nimport type { Path, Value } from './path';\n\nexport function castArrayPath(path: string | KeyType[]): KeyType[] {\n if (Array.isArray(path)) {\n return path as any;\n }\n\n if (path === '') {\n return [] as any;\n }\n\n return (path as string).split('.') as any;\n}\n\nexport function get<T, P extends Path<T>>(object: T, path: P): Value<T, P> {\n const _path = castArrayPath(path as any);\n const [first, ...rest] = _path;\n\n if (first === undefined || !object) {\n return object as Value<T, P>;\n }\n\n if (object instanceof Map) {\n return get(object.get(first), rest as any);\n }\n\n if (object instanceof Set) {\n return get(Array.from(object)[Number(first)], rest as any);\n }\n\n if (object instanceof Object) {\n return get(object[first as keyof T], rest as any) as Value<T, P>;\n }\n\n throw new Error(`Could not get ${path} of ${object}`);\n}\n\nexport function set<T, P extends Path<T>>(\n object: T,\n path: P,\n value: Update<Value<T, P>>,\n rootPath = path,\n): T {\n const _path = castArrayPath(path as any);\n const [first, ...rest] = _path;\n\n if (first === undefined) {\n return value as any;\n }\n\n const updateChild = (child: any) => {\n if (!child && rest.length > 0) {\n const _rootPath = castArrayPath(rootPath as any);\n\n const prefix = _rootPath.slice(0, -rest.length) as KeyType[];\n throw new Error(`Cannot set ${rootPath} because ${prefix.join('.')} is ${child}`);\n }\n\n return set(child, rest as any, value, rootPath);\n };\n\n if (object instanceof Map) {\n const copy = flatClone(object);\n const child = copy.get(first);\n copy.set(first, updateChild(child));\n return copy;\n }\n\n if (object instanceof Set) {\n const copy = [...object];\n const child = copy[Number(first)];\n copy[Number(first)] = updateChild(child);\n return new Set(copy) as any;\n }\n\n if (object instanceof Object || object === undefined) {\n const copy = flatClone(object ?? ({} as T));\n copy[first as keyof T] = updateChild(copy[first as keyof T]);\n return copy;\n }\n\n throw new Error(`Could not set ${path} of ${object}`);\n}\n\nexport function remove<T, P extends Path<T, true>>(object: T, path: P): T {\n const _path = castArrayPath(path as any);\n\n if (_path.length === 0) {\n return undefined as any;\n }\n\n const parentPath = _path.slice(0, -1);\n const key = _path[_path.length - 1];\n\n const parent = flatClone(get(object, parentPath as any));\n\n if (parent instanceof Map) {\n parent.delete(key);\n } else if (parent instanceof Set) {\n const value = Array.from(parent)[Number(key)];\n parent.delete(value);\n } else {\n delete parent[key as keyof typeof parent];\n }\n\n return set(object, parentPath as any, parent);\n}\n","import type { Path } from './path';\nimport { get } from './propAccess';\n\nexport function makeSelector<T, S>(selector?: ((value: T) => S) | Path<any>): (value: T) => S {\n if (!selector) {\n return (x) => x as any;\n }\n\n if (selector instanceof Function) {\n return selector;\n }\n\n return (x) => get(x, selector as any) as any;\n}\n","import type { Store } from '../core/store';\nimport type { OptionalPropertyOf } from './typeHelpers';\n\ntype Function_ = (...args: any) => any;\n\nfunction createArrayAction<P extends keyof Array<any>>(prop: P) {\n return function arrayAction<T extends Array<any>>(\n this: Store<T>,\n ...args: T[P] extends Function_ ? Parameters<T[P]> : never\n ): T[P] extends Function_ ? ReturnType<T[P]> : never {\n const newArray = this.get().slice() as T;\n const result = (newArray[prop] as Function_)(...(args as any));\n this.set(newArray);\n return result;\n };\n}\nexport const arrayMethods = {\n splice: /* @__PURE__ */ createArrayAction('splice'),\n push: /* @__PURE__ */ createArrayAction('push'),\n pop: /* @__PURE__ */ createArrayAction('pop'),\n shift: /* @__PURE__ */ createArrayAction('shift'),\n unshift: /* @__PURE__ */ createArrayAction('unshift'),\n reverse: /* @__PURE__ */ createArrayAction('reverse'),\n sort: /* @__PURE__ */ createArrayAction('sort'),\n};\n\nexport const recordMethods = {\n delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(this: Store<T>, key: K) {\n const copy = { ...this.get() };\n delete copy[key];\n this.set(copy);\n },\n\n clear<T extends Record<any, any>>(this: Store<Partial<T>>) {\n this.set({} as T);\n },\n};\n\nexport const mapMethods = {\n delete<K, V>(this: Store<Map<K, V>>, key: K) {\n const newMap = new Map(this.get());\n const result = newMap.delete(key);\n this.set(newMap);\n return result;\n },\n\n clear<K, V>(this: Store<Map<K, V>>) {\n this.set(new Map());\n },\n};\n\nexport const setMethods = {\n add<T>(this: Store<Set<T>>, value: T) {\n const newSet = new Set(this.get());\n newSet.add(value);\n this.set(newSet);\n },\n\n delete<T>(this: Store<Set<T>>, value: T) {\n const newSet = new Set(this.get());\n newSet.delete(value);\n this.set(newSet);\n },\n\n clear<T>(this: Store<Set<T>>) {\n this.set(new Set());\n },\n};\n","import { calcDuration } from './calcDuration';\nimport type { Duration } from '@core';\n\nexport function throttle<Args extends any[]>(\n action: (...args: Args) => void,\n duration: Duration,\n): (...args: Args) => void {\n const ms = calcDuration(duration);\n\n let t = 0;\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n return (...args: Args) => {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n const dt = t + ms - Date.now();\n if (dt <= 0) {\n action(...args);\n t = Date.now();\n return;\n }\n\n timeout = setTimeout(() => {\n action(...args);\n t = Date.now();\n }, dt);\n };\n}\n","import type {\n CalculationHelpers,\n Cancel,\n Duration,\n Effect,\n Listener,\n Selector,\n SubscribeOptions,\n Update,\n Use,\n UseOptions,\n} from './commonTypes';\nimport { calcDuration } from '@lib/calcDuration';\nimport { CalculationHelper } from '@lib/calculationHelper';\nimport { Callable } from '@lib/callable';\nimport { debounce } from '@lib/debounce';\nimport { deepEqual } from '@lib/equals';\nimport { forwardError } from '@lib/forwardError';\nimport { makeSelector } from '@lib/makeSelector';\nimport type { Path, Value } from '@lib/path';\nimport { get, set } from '@lib/propAccess';\nimport { arrayMethods, mapMethods, recordMethods, setMethods } from '@lib/standardMethods';\nimport { throttle } from '@lib/throttle';\n\nexport type StoreMethods = Record<string, (...args: any[]) => any>;\n\nexport type BoundStoreMethods<T, Methods extends StoreMethods> = Methods &\n ThisType<Store<T> & Methods>;\n\nexport interface StoreOptions {\n retain?: Duration;\n}\n\nexport interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions {\n methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;\n}\n\nexport type Calculate<T> = (this: CalculationHelpers<T>, helpers: CalculationHelpers<T>) => T;\n\ntype StandardMethods<T> = T extends Map<any, any>\n ? typeof mapMethods\n : T extends Set<any>\n ? typeof setMethods\n : T extends Array<any>\n ? typeof arrayMethods\n : T extends Record<any, any>\n ? typeof recordMethods\n : Record<string, never>;\n\ntype StoreWithMethods<T, Methods extends StoreMethods> = Store<T> &\n Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> &\n StandardMethods<T>;\n\nfunction noop() {\n return undefined;\n}\n\nexport class Store<T> extends Callable<any, any> {\n protected _value?: { v: T };\n\n protected listeners = new Map<Listener, boolean>();\n\n protected effects = new Map<\n Effect,\n { handle?: Cancel; retain?: number; timeout?: ReturnType<typeof setTimeout> }\n >();\n\n protected notifyId = {};\n\n protected calculationHelper = new CalculationHelper<T>({\n calculate: (helpers) => {\n if (this.getter instanceof Function) {\n const value = this.getter.apply(helpers, [helpers]);\n this._value = { v: value };\n this.notify();\n }\n },\n addEffect: (effect) => this.addEffect(effect, this.options.retain),\n getValue: () => this._value?.v,\n onInvalidate: () => this.reset(),\n });\n\n constructor(\n public readonly getter: T | Calculate<T>,\n public readonly options: StoreOptions = {},\n public readonly derivedFrom?: {\n store: Store<any>;\n selectors: (Selector<any, any> | Path<any>)[];\n updater: (state: any) => void;\n },\n protected readonly _call: (...args: any[]) => any = () => undefined,\n ) {\n super(_call);\n this.get = this.get.bind(this);\n this.set = this.set.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.once = this.once.bind(this);\n this.map = this.map.bind(this);\n this.addEffect = this.addEffect.bind(this);\n this.isActive = this.isActive.bind(this);\n\n if (!(getter instanceof Function)) {\n this._value = { v: getter };\n }\n }\n\n get(): T {\n this.calculationHelper.check();\n\n if (!this._value) {\n this.calculationHelper.execute();\n return this.get();\n }\n\n return this._value.v;\n }\n\n set(update: Update<T>): void;\n\n set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;\n\n set(...args: any[]): void {\n const path: any = args.length > 1 ? args[0] : [];\n let update: Update<any> = args.length > 1 ? args[1] : args[0];\n\n if (update instanceof Function) {\n const before = this.get();\n const valueBefore = get(before, path);\n const valueAfter = update(valueBefore);\n update = set(before, path, valueAfter);\n } else if (path.length > 0) {\n update = set(this.get(), path, update);\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n return;\n }\n\n this._value = { v: update };\n this.notify();\n }\n\n protected reset() {\n this._value = undefined;\n\n if (this.isActive()) {\n this.calculationHelper.execute();\n }\n }\n\n subscribe(listener: Listener<T>, options?: SubscribeOptions): Cancel {\n const {\n passive,\n runNow = true,\n throttle: throttleOption,\n debounce: debounceOption,\n equals = deepEqual,\n } = options ?? {};\n\n let compareToValue = this._value?.v;\n let previousValue: T | undefined;\n let hasRun = false;\n\n let innerListener = (force?: boolean | void) => {\n if (!this._value) {\n return;\n }\n\n const value = this._value.v;\n\n if (!force && equals(value, compareToValue)) {\n return;\n }\n\n compareToValue = value;\n const _previousValue = previousValue;\n previousValue = value;\n hasRun = true;\n\n try {\n listener(value, _previousValue);\n } catch (error) {\n forwardError(error);\n }\n };\n\n if (throttleOption) {\n innerListener = throttle(innerListener, throttleOption);\n } else if (debounceOption) {\n innerListener = debounce(innerListener, debounceOption);\n }\n\n this.listeners.set(innerListener, !passive);\n if (!passive) {\n this.onSubscribe();\n }\n\n if (runNow && !hasRun) {\n innerListener(true);\n }\n\n return () => {\n this.listeners.delete(innerListener);\n if (!passive) {\n this.onUnsubscribe();\n }\n };\n }\n\n once<S extends T>(condition: (value: T) => value is S): Promise<S>;\n\n once(condition?: (value: T) => boolean): Promise<T>;\n\n once(condition: (value: T) => boolean = (value) => !!value): Promise<any> {\n return new Promise<T>((resolve) => {\n let stopped = false;\n const cancel = this.subscribe(\n (value) => {\n if (stopped || (condition && !condition(value))) {\n return;\n }\n\n resolve(value);\n stopped = true;\n setTimeout(() => cancel());\n },\n {\n runNow: !!condition,\n },\n );\n });\n }\n\n map<S>(\n selector: Selector<T, S>,\n updater?: (value: S) => Update<T>,\n options?: UseOptions,\n ): Store<S>;\n\n map<P extends Path<T>>(selector: P, options?: UseOptions): Store<Value<T, P>>;\n\n map(_selector: Selector<T, any> | Path<any>, ...args: any[]): Store<any> {\n const updater: ((value: any) => Update<T>) | undefined =\n _selector instanceof Function\n ? args[0]\n : (value) => (state) => set(state, _selector as Path<T>, value);\n\n const options = _selector instanceof Function ? args[1] : args[0];\n\n const selector = makeSelector(_selector);\n\n const derivedFrom = {\n store: this.derivedFrom ? this.derivedFrom.store : this,\n selectors: this.derivedFrom ? [...this.derivedFrom.selectors, _selector] : [_selector],\n\n updater: (value: any) => {\n if (!updater) {\n throw new TypeError(\n 'Can only updated computed stores that either are derived from other stores using string selectors or have an updater function.',\n );\n }\n\n let update = updater(value);\n\n if (update instanceof Function) {\n update = update(this.get());\n }\n\n if (this.derivedFrom) {\n this.derivedFrom.updater(update);\n } else {\n this.set(update);\n }\n },\n };\n\n return new Store(\n ({ use }) => {\n return selector(use(this, options));\n },\n this.options,\n derivedFrom,\n );\n }\n\n /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.\n * @param effect\n * If there is already a subscriber, the effect will be executed immediately.\n * Otherweise it will be executed as soon as the first subscription is created.\n * Every time all subscriptions are removed and the first is created again, the effect will be executed again.\n * @param retain\n * If provided, delay tearing down effects when the last subscriber is removed. This is useful if a short gap in subscriber coverage is supposed to be ignored. E.g. when switching pages, the old page might unsubscribe, while the new page subscribes immediately after.\n * @returns\n * The effect can return a teardown callback, which will be executed when the last subscription is removed and potentially the ratain time has passed.\n */\n addEffect(effect: Effect, retain?: Duration) {\n this.effects.set(effect, {\n handle: this.isActive() ? effect() ?? noop : undefined,\n retain: retain !== undefined ? calcDuration(retain) : undefined,\n });\n\n return () => {\n const { handle, timeout } = this.effects.get(effect) ?? {};\n handle?.();\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.delete(effect);\n };\n }\n\n /** Return whether the store is currently active, which means whether it has at least one subscriber. */\n isActive() {\n return [...this.listeners.values()].some(Boolean);\n }\n\n protected onSubscribe() {\n if ([...this.listeners.values()].filter(Boolean).length > 1) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: handle ?? effect() ?? noop,\n retain,\n timeout: undefined,\n });\n }\n }\n\n protected onUnsubscribe() {\n if ([...this.listeners.values()].some(Boolean)) return;\n\n for (const [effect, { handle, retain, timeout }] of this.effects.entries()) {\n if (!retain) {\n handle?.();\n }\n\n if (timeout !== undefined) {\n clearTimeout(timeout);\n }\n\n this.effects.set(effect, {\n handle: retain ? handle : undefined,\n retain,\n timeout: retain && handle ? setTimeout(handle, retain) : undefined,\n });\n }\n }\n\n protected notify() {\n const n = {};\n this.notifyId = n;\n\n const snapshot = [...this.listeners.keys()];\n for (const listener of snapshot) {\n listener();\n if (n !== this.notifyId) break;\n }\n }\n}\n\nconst defaultOptions: StoreOptions = {};\n\nfunction create<T>(\n calculate: (this: { use: Use }, fns: { use: Use }) => T,\n options?: StoreOptions,\n): Store<T>;\nfunction create<T, Methods extends StoreMethods = {}>(\n initialState: T,\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods>;\nfunction create<T, Methods extends StoreMethods>(\n initialState: T | ((this: { use: Use }, fns: { use: Use }) => T),\n options?: StoreOptionsWithMethods<T, Methods>,\n): StoreWithMethods<T, Methods> | Store<T> {\n const store = new Store(initialState, options);\n\n if (initialState instanceof Function) {\n return store;\n }\n\n let methods: StoreMethods | undefined = options?.methods;\n\n if (initialState instanceof Map) {\n methods = { ...mapMethods, ...methods };\n } else if (initialState instanceof Set) {\n methods = { ...setMethods, ...methods };\n } else if (Array.isArray(initialState)) {\n methods = { ...arrayMethods, ...methods };\n } else if (initialState instanceof Object) {\n methods = { ...recordMethods, ...methods };\n }\n\n const boundMethods = Object.fromEntries(\n Object.entries(methods ?? ({} as BoundStoreMethods<T, any>))\n .filter(([name]) => !(name in store))\n .map(([name, action]) => [name, (action as any).bind(store)]),\n ) as BoundStoreMethods<T, any>;\n\n return Object.assign(store, boundMethods);\n}\n\nexport const createStore = /* @__PURE__ */ Object.assign(create, { defaultOptions });\n"],"names":["equals"],"mappings":"AAEO,SAAS,aAAa,GAAa;AACxC,MAAI,OAAO,MAAM;AAAiB,WAAA;AAE/B,UAAA,EAAE,gBAAgB,MAClB,EAAE,WAAW,KAAK,OAClB,EAAE,WAAW,KAAK,KAAK,OACvB,EAAE,SAAS,KAAK,KAAK,KAAK,OAC1B,EAAE,QAAQ,KAAK,KAAK,KAAK,KAAK;AAEnC;ACEO,SAAS,QAAe;AAC7B,QAAM,IAKA,CAAA;AACA,QAAA,0CAA0B;AAChC,MAAI,SAAS;AAEb,QAAM,SAAS,MAAM;AACnB,eAAW,YAAY,qBAAqB;AACjC;IACX;AAEA,wBAAoB,MAAM;AAAA,EAAA;AAG5B,QAAM,MAAM,YAAY;AACtB,QAAI,CAAC,QAAQ;AACF,eAAA;AAEL,UAAA;AACI,aAAA,OAAO,EAAE,SAAU;AACrB,YAAA;AACE,cAAA,SAAS,KAAK;AAClB,cAAI,kBAAkB,SAAS;AAC7B,qBAAS,M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AAM,WAAW,CAAC,GAAG,KAAK,UAAU,KAAM,CAAA;AAC1C,eAAW,YAAY,UAAU;AACtB;AACT,UAAI,MAAM,KAAK;AAAU;AAAA,IAC3B;AAAA,EACF;AACF;AAEA,MAAM,iBAA+B,CAAA;AAUrC,SAAS,OACP,cACA,SACyC;AACzC,QAAM,QAAQ,IAAI,MAAM,cAAc,OAAO;AAE7C,MAAI,wBAAwB,UAAU;AAC7B,WAAA;AAAA,EACT;AAEA,MAAI,UAAoC,mCAAS;AAEjD,MAAI,wBAAwB,KAAK;AAC/B,cAAU,EAAE,GAAG,YAAY,GAAG,QAAQ;AAAA,EAAA,WAC7B,wBAAwB,KAAK;AACtC,cAAU,EAAE,GAAG,YAAY,GAAG,QAAQ;AAAA,EAC7B,WAAA,MAAM,QAAQ,YAAY,GAAG;AACtC,cAAU,EAAE,GAAG,cAAc,GAAG,QAAQ;AAAA,EAAA,WAC/B,wBAAwB,QAAQ;AACzC,cAAU,EAAE,GAAG,eAAe,GAAG,QAAQ;AAAA,EAC3C;AAEA,QAAM,eAAe,OAAO;AAAA,IAC1B,OAAO,QAAQ,WAAY,EAAgC,EACxD,OAAO,CAAC,CAAC,IAAI,MAAM,EAAE,QAAQ,MAAM,EACnC,IAAI,CAAC,CAAC,MAAM,MAAM,MAAM,CAAC,MAAO,OAAe,KAAK,KAAK,CAAC,CAAC;AAAA,EAAA;AAGzD,SAAA,OAAO,OAAO,OAAO,YAAY;AAC1C;AAEO,MAAM,cAAqC,uBAAA,OAAO,QAAQ,EAAE,eAAgB,CAAA;"}
@@ -2,6 +2,7 @@ import type { Duration, Selector, Use } from './commonTypes';
2
2
  import { type ResourceGroup } from './resourceGroup';
3
3
  import { Store } from './store';
4
4
  import type { CacheState, ErrorState, ValueState } from '../lib/cacheState';
5
+ import { type MaybePromise } from '../lib/maybePromise';
5
6
  import type { Path, Value } from '../lib/path';
6
7
  export interface CacheGetOptions {
7
8
  update?: 'whenMissing' | 'whenStale' | 'force';
@@ -10,7 +11,9 @@ export interface CacheGetOptions {
10
11
  export interface CacheFunction<T, Args extends any[] = []> {
11
12
  (this: {
12
13
  use: Use;
13
- }, ...args: Args): Promise<T>;
14
+ }, ...args: Args): Promise<T> | ((cache: {
15
+ use: Use;
16
+ }) => Promise<T>);
14
17
  }
15
18
  export interface CacheOptions<T> {
16
19
  invalidateAfter?: Duration | ((state: ValueState<T> | ErrorState) => Duration | null) | null;
@@ -28,7 +31,7 @@ export declare class Cache<T> extends Store<Promise<T>> {
28
31
  selectors: (Selector<any, any> | Path<any>)[];
29
32
  } | undefined;
30
33
  readonly state: Store<CacheState<T>> & Omit<ThisType<Store<CacheState<T>>>, keyof Store<T_1>> & {
31
- delete<T_2 extends Record<any, any>, K_1 extends Exclude<{ [K in keyof T_2]: T_2 extends Record<K, T_2[K]> ? never : K; }[keyof T_2], undefined>>(this: Store<T_2>, key: K_1): void;
34
+ delete<T_2 extends Record<any, any>, K extends import("../lib/typeHelpers").OptionalPropertyOf<T_2>>(this: Store<T_2>, key: K): void;
32
35
  clear<T_3 extends Record<any, any>>(this: Store<Partial<T_3>>): void;
33
36
  };
34
37
  protected stalePromise?: Promise<T>;
@@ -38,6 +41,8 @@ export declare class Cache<T> extends Store<Promise<T>> {
38
41
  selectors: (Selector<any, any> | Path<any>)[];
39
42
  } | undefined, _call?: (...args: any[]) => any);
40
43
  get({ update, backgroundUpdate }?: CacheGetOptions): Promise<T>;
44
+ updateValue(value: MaybePromise<T>): void;
45
+ updateError(error: unknown): void;
41
46
  invalidate({ invalidateDependencies }?: {
42
47
  invalidateDependencies?: boolean;
43
48
  }): void;
@@ -1,5 +1,6 @@
1
1
  import type { Store } from './store';
2
2
  import type { DebounceOptions } from '../lib/debounce';
3
+ import { type MaybePromise } from '../lib/maybePromise';
3
4
  export interface Listener<T = void> {
4
5
  (value: T, previouseValue?: T): void;
5
6
  }
@@ -49,3 +50,10 @@ export interface UseOptions {
49
50
  export interface Use {
50
51
  <T>(store: Store<T>, options?: UseOptions): T;
51
52
  }
53
+ export type ConnectionState = 'connecting' | 'open' | 'closing' | 'closed';
54
+ export interface CalculationHelpers<T> {
55
+ use: Use;
56
+ updateValue: (update: UpdateFrom<MaybePromise<T>, [T | undefined]>) => void;
57
+ updateError: (error: unknown) => void;
58
+ updateConnectionState: (state: ConnectionState) => void;
59
+ }
@@ -1,7 +1,7 @@
1
- export type { CacheFunction, CacheGetOptions, CacheOptions } from './cache';
2
- export { Cache, createCache } from './cache';
1
+ export { Cache, createCache, type CacheFunction, type CacheGetOptions, type CacheOptions, } from './cache';
3
2
  export type { Cancel, Duration, Effect, Listener, SubscribeOptions } from './commonTypes';
4
- export type { Resource } from './resourceGroup';
5
- export { allResources, createResourceGroup, ResourceGroup } from './resourceGroup';
6
- export type { BoundStoreMethods, StoreMethods, StoreOptions, StoreOptionsWithMethods, } from './store';
7
- export { createStore, Store } from './store';
3
+ export { ResourceGroup, allResources, createResourceGroup, type Resource } from './resourceGroup';
4
+ export { Scope, createScope } from './scope';
5
+ export { Store, createStore, type BoundStoreMethods, type StoreMethods, type StoreOptions, type StoreOptionsWithMethods, } from './store';
6
+ export { SubstriptionCache, createSubscriptionCache, type SubscriptionCacheFunction, type SubstriptionCacheOptions, } from './subscriptionCache';
7
+ export { createUrlStore, type UrlStore, type UrlStoreOptions } from './urlStore';
@@ -1,6 +1,6 @@
1
1
  export interface Resource {
2
- invalidate(): void;
3
- clear(): void;
2
+ invalidateAll(): void;
3
+ clearAll(): void;
4
4
  }
5
5
  export declare class ResourceGroup {
6
6
  readonly name?: string | undefined;
@@ -0,0 +1,5 @@
1
+ export declare class Scope<T> {
2
+ readonly defaultValue: T;
3
+ constructor(defaultValue: T);
4
+ }
5
+ export declare function createScope<T>(defaultValue: T): Scope<T>;
@@ -1,4 +1,4 @@
1
- import type { Cancel, Duration, Effect, Listener, Selector, SubscribeOptions, Update, Use, UseOptions } from './commonTypes';
1
+ import type { CalculationHelpers, Cancel, Duration, Effect, Listener, Selector, SubscribeOptions, Update, Use, UseOptions } from './commonTypes';
2
2
  import { CalculationHelper } from '../lib/calculationHelper';
3
3
  import { Callable } from '../lib/callable';
4
4
  import type { Path, Value } from '../lib/path';
@@ -6,16 +6,12 @@ import { arrayMethods, mapMethods, recordMethods, setMethods } from '../lib/stan
6
6
  export type StoreMethods = Record<string, (...args: any[]) => any>;
7
7
  export type BoundStoreMethods<T, Methods extends StoreMethods> = Methods & ThisType<Store<T> & Methods>;
8
8
  export interface StoreOptions {
9
- retain?: number;
9
+ retain?: Duration;
10
10
  }
11
11
  export interface StoreOptionsWithMethods<T, Methods extends StoreMethods> extends StoreOptions {
12
12
  methods?: Methods & ThisType<Store<T> & Methods & StandardMethods<T>>;
13
13
  }
14
- export type Calculate<T> = (this: {
15
- use: Use;
16
- }, fns: {
17
- use: Use;
18
- }) => T;
14
+ export type Calculate<T> = (this: CalculationHelpers<T>, helpers: CalculationHelpers<T>) => T;
19
15
  type StandardMethods<T> = T extends Map<any, any> ? typeof mapMethods : T extends Set<any> ? typeof setMethods : T extends Array<any> ? typeof arrayMethods : T extends Record<any, any> ? typeof recordMethods : Record<string, never>;
20
16
  type StoreWithMethods<T, Methods extends StoreMethods> = Store<T> & Omit<BoundStoreMethods<T, Methods>, keyof Store<T>> & StandardMethods<T>;
21
17
  export declare class Store<T> extends Callable<any, any> {
@@ -24,6 +20,7 @@ export declare class Store<T> extends Callable<any, any> {
24
20
  readonly derivedFrom?: {
25
21
  store: Store<any>;
26
22
  selectors: (Selector<any, any> | Path<any>)[];
23
+ updater: (state: any) => void;
27
24
  } | undefined;
28
25
  protected readonly _call: (...args: any[]) => any;
29
26
  protected _value?: {
@@ -36,19 +33,20 @@ export declare class Store<T> extends Callable<any, any> {
36
33
  timeout?: number | undefined;
37
34
  }>;
38
35
  protected notifyId: {};
39
- protected calculationHelper: CalculationHelper<unknown>;
36
+ protected calculationHelper: CalculationHelper<T>;
40
37
  constructor(getter: T | Calculate<T>, options?: StoreOptions, derivedFrom?: {
41
38
  store: Store<any>;
42
39
  selectors: (Selector<any, any> | Path<any>)[];
40
+ updater: (state: any) => void;
43
41
  } | undefined, _call?: (...args: any[]) => any);
44
42
  get(): T;
45
43
  set(update: Update<T>): void;
46
44
  set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;
47
45
  protected reset(): void;
48
- sub(listener: Listener<T>, options?: SubscribeOptions): Cancel;
46
+ subscribe(listener: Listener<T>, options?: SubscribeOptions): Cancel;
49
47
  once<S extends T>(condition: (value: T) => value is S): Promise<S>;
50
48
  once(condition?: (value: T) => boolean): Promise<T>;
51
- map<S>(selector: Selector<T, S>, options?: UseOptions): Store<S>;
49
+ map<S>(selector: Selector<T, S>, updater?: (value: S) => Update<T>, options?: UseOptions): Store<S>;
52
50
  map<P extends Path<T>>(selector: P, options?: UseOptions): Store<Value<T, P>>;
53
51
  /** Add an effect that will be executed when the store becomes active, which means when it has at least one subscriber.
54
52
  * @param effect
@@ -0,0 +1,51 @@
1
+ import { type CalculationHelpers, type Cancel, type ConnectionState, type Duration, type Selector } from './commonTypes';
2
+ import { type ResourceGroup } from './resourceGroup';
3
+ import { Store } from './store';
4
+ import { type Path } from '../lib/path';
5
+ export interface SubscriptionCacheFunction<T, Args extends any[] = []> {
6
+ (this: CalculationHelpers<T | undefined>, ...args: Args): Cancel | void | ((cache: CalculationHelpers<T | undefined>) => Cancel | void);
7
+ }
8
+ export interface SubstriptionCacheOptions {
9
+ clearOnInvalidate?: boolean;
10
+ clearUnusedAfter?: Duration | null;
11
+ resourceGroup?: ResourceGroup | ResourceGroup[];
12
+ retain?: Duration;
13
+ }
14
+ export declare class SubstriptionCache<T> extends Store<T | undefined> {
15
+ readonly connectFunction: SubscriptionCacheFunction<T>;
16
+ readonly options: SubstriptionCacheOptions;
17
+ readonly derivedFromSubscriptionCache?: {
18
+ subscriptionCache: SubstriptionCache<any>;
19
+ selectors: (Selector<any, any> | Path<any>)[];
20
+ } | undefined;
21
+ readonly state: Store<{
22
+ connectionState: ConnectionState;
23
+ error: unknown;
24
+ }> & Omit<ThisType<Store<{
25
+ connectionState: ConnectionState;
26
+ error: unknown;
27
+ }>>, keyof Store<T_1>> & {
28
+ delete<T_2 extends Record<any, any>, K extends import("../lib/typeHelpers").OptionalPropertyOf<T_2>>(this: Store<T_2>, key: K): void;
29
+ clear<T_3 extends Record<any, any>>(this: Store<Partial<T_3>>): void;
30
+ };
31
+ constructor(connectFunction: SubscriptionCacheFunction<T>, options?: SubstriptionCacheOptions, derivedFromSubscriptionCache?: {
32
+ subscriptionCache: SubstriptionCache<any>;
33
+ selectors: (Selector<any, any> | Path<any>)[];
34
+ } | undefined, _call?: (...args: any[]) => any);
35
+ invalidate({ invalidateDependencies }?: {
36
+ invalidateDependencies?: boolean;
37
+ }): void;
38
+ clear({ invalidateDependencies }?: {
39
+ invalidateDependencies?: boolean;
40
+ }): void;
41
+ }
42
+ type CreateReturnType<T, Args extends any[]> = {
43
+ (...args: Args): SubstriptionCache<T>;
44
+ invalidateAll: () => void;
45
+ clearAll: () => void;
46
+ } & ([] extends Args ? SubstriptionCache<T> : {});
47
+ declare function create<T, Args extends any[] = []>(cacheFunction: SubscriptionCacheFunction<T, Args>, options?: SubstriptionCacheOptions): CreateReturnType<T, Args>;
48
+ export declare const createSubscriptionCache: typeof create & {
49
+ defaultOptions: SubstriptionCacheOptions;
50
+ };
51
+ export {};
@@ -0,0 +1,26 @@
1
+ import { type Update } from './commonTypes';
2
+ import { Store, type StoreOptions } from './store';
3
+ import { type Path, type Value } from '../lib/path';
4
+ export interface UrlStoreOptions<T> extends StoreOptions {
5
+ key: string;
6
+ type?: 'search' | 'hash';
7
+ serialize?: (value: T) => string;
8
+ deserialize?: (value: string) => T;
9
+ defaultValue?: T;
10
+ onCommit?: (value: T | undefined) => void;
11
+ }
12
+ export interface UrlStoreOptionsWithDefaults<T> extends UrlStoreOptions<T> {
13
+ defaultValue: T;
14
+ }
15
+ export type UrlStoreOptionsRequired<T> = UrlStoreOptions<T> & Required<Pick<UrlStoreOptions<T>, 'type' | 'serialize' | 'deserialize' | 'defaultValue'>>;
16
+ export declare class UrlStore<T> extends Store<T> {
17
+ readonly options: UrlStoreOptionsRequired<T>;
18
+ private serializedDefaultValue;
19
+ constructor(options: UrlStoreOptionsRequired<T>);
20
+ set(update: Update<T>): void;
21
+ set<P extends Path<T>>(path: P, update: Update<Value<T, P>>): void;
22
+ protected watchUrl(): () => void;
23
+ protected updateUrl(value: T | undefined): void;
24
+ }
25
+ export declare function createUrlStore<T>(options: UrlStoreOptionsWithDefaults<T>): UrlStore<T>;
26
+ export declare function createUrlStore<T>(options: UrlStoreOptions<T>): UrlStore<T | undefined>;
@@ -0,0 +1,10 @@
1
+ import type { Draft } from 'immer';
2
+ import type { Store } from '../core/store';
3
+ import { type Path, type Value } from '../lib/path';
4
+ type Recipe<T> = (draft: Draft<T>) => void;
5
+ declare function update<T>(this: Store<T>, recipe: Recipe<T>): void;
6
+ declare function update<T, P extends Path<T>>(this: Store<T>, path: P, recipe: Recipe<Value<T, P>>): void;
7
+ export declare const immerMethods: {
8
+ update: typeof update;
9
+ };
10
+ export {};
@@ -1 +1 @@
1
- export { immerActions } from './immerActions';
1
+ export { immerMethods } from './immerMethods';
@@ -0,0 +1,7 @@
1
+ import { immerMethods } from './immerMethods';
2
+ type ImmerMethods = typeof immerMethods;
3
+ declare module '../core' {
4
+ interface Store<T> extends ImmerMethods {
5
+ }
6
+ }
7
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from './core';
2
- export { InstanceCache } from './lib/instanceCache';
3
2
  export { calcDuration } from './lib/calcDuration';
3
+ export { InstanceCache } from './lib/instanceCache';
4
4
  export { arrayMethods, mapMethods, recordMethods, setMethods } from './lib/standardMethods';
5
+ export * from './lib/updateHelpers';
6
+ export * from './persist';
@@ -1,22 +1,27 @@
1
- import type { MaybePromise } from './maybePromise';
2
- import type { Cancel, UpdateFrom, Use } from '../core/commonTypes';
1
+ import type { CalculationHelpers, Cancel, ConnectionState } from '../core/commonTypes';
3
2
  export declare class CalculationHelper<T> {
4
- private options;
3
+ options: {
4
+ calculate: (helpers: CalculationHelpers<T>) => Cancel | void;
5
+ addEffect: (effect: () => Cancel | void) => Cancel;
6
+ getValue?: () => T | undefined;
7
+ onValue?: (value: T) => void;
8
+ onError?: (error: unknown) => void;
9
+ onConnectionState?: (state: ConnectionState) => void;
10
+ onInvalidate?: () => void;
11
+ };
5
12
  private current?;
6
13
  constructor(options: {
7
- calculate: (fns: {
8
- use: Use;
9
- updateValue: (update: UpdateFrom<MaybePromise<T>, [T | undefined]>) => void;
10
- updateError: (error: unknown) => void;
11
- }) => Cancel | void;
14
+ calculate: (helpers: CalculationHelpers<T>) => Cancel | void;
12
15
  addEffect: (effect: () => Cancel | void) => Cancel;
13
16
  getValue?: () => T | undefined;
14
- setValue?: (value: T) => void;
15
- setError?: (error: unknown) => void;
17
+ onValue?: (value: T) => void;
18
+ onError?: (error: unknown) => void;
19
+ onConnectionState?: (state: ConnectionState) => void;
16
20
  onInvalidate?: () => void;
17
21
  });
18
22
  execute(): void;
19
23
  stop(): void;
20
24
  check(): void;
25
+ checkOrExecute(): void;
21
26
  invalidateDependencies(): void;
22
27
  }
@@ -1,3 +1,3 @@
1
- export declare function defaultEquals(a: any, b: any): boolean;
2
- export declare function simpleShallowEquals(a: any, b: any): boolean;
3
- export declare function simpleDeepEquals(a: any, b: any): boolean;
1
+ export declare function defaultEqual(a: any, b: any): boolean;
2
+ export declare function shallowEqual(a: any, b: any): boolean;
3
+ export declare function deepEqual(a: any, b: any): boolean;
@@ -1,12 +1,12 @@
1
- import type { ArrayToStringPath, Array_, Object_, OptionalPropertyOf, StringToArrayPath, StringToNumber } from './typeHelpers';
2
- export type KeyType = string | number;
1
+ import type { ArrayToStringPath, Array_, IsAny, IsNever, Object_, OptionalPropertyOf, StringToArrayPath, StringToNumber } from './typeHelpers';
2
+ export type KeyType = string | number | symbol;
3
3
  export type GetKeys<T extends Object_ | Array_> = T extends Array_ ? T extends readonly [] ? never : '0' extends keyof T ? StringToNumber<keyof T> : number : keyof T;
4
4
  export type PathAsArray<T, Optional = false> = 0 extends 1 & T ? KeyType[] : T extends never ? never : T extends Object_ | Array_ ? {
5
5
  [K in GetKeys<T>]: (Optional extends true ? (K extends OptionalPropertyOf<T> ? [K] : never) : [K]) | [K, ...PathAsArray<T[K], Optional>];
6
6
  }[GetKeys<T>] : T extends Map<infer K extends KeyType, infer V> ? [K] | [K, ...PathAsArray<V, Optional>] : T extends Set<any> ? [number] : never;
7
7
  export type PathAsString<T, Optional = false> = ArrayToStringPath<PathAsArray<T, Optional>>;
8
8
  export type Path<T, Optional = false> = PathAsString<T, Optional> | PathAsArray<T, Optional>;
9
- export type Value<T, P> = 0 extends 1 & T ? any : P extends string ? Value<T, StringToArrayPath<P>> : P extends [infer First extends KeyType, ...infer Rest extends KeyType[]] ? T extends Object_ ? Record<any, any> extends T ? Value<T[First], Rest> | undefined : Value<T[First], Rest> : T extends Array_ ? any[] extends T ? Value<T[First & keyof T], Rest> | undefined : Value<T[First & keyof T], Rest> : T extends Map<any, infer V> | Set<infer V> ? Value<V, Rest> | undefined : never : T;
9
+ export type Value<T, P> = true extends IsAny<T> | IsAny<P> ? any : true extends IsNever<T> | IsNever<P> ? never : P extends string ? Value<T, StringToArrayPath<P>> : P extends [infer First extends KeyType, ...infer Rest extends KeyType[]] ? T extends Object_ ? Record<any, any> extends T ? Value<T[First], Rest> | undefined : Value<T[First], Rest> : T extends Array_ ? any[] extends T ? Value<T[First & keyof T], Rest> | undefined : Value<T[First & keyof T], Rest> : T extends Map<any, infer V> | Set<infer V> ? Value<V, Rest> | undefined : never : T;
10
10
  export type WildcardPathAsArray<T> = [] | (0 extends 1 & T ? KeyType[] : T extends never ? never : T extends Object_ | Array_ ? {
11
11
  [K in GetKeys<T>]: ['*'] | [K] | [K, ...WildcardPathAsArray<T[K]>];
12
12
  }[GetKeys<T>] : T extends Map<infer K extends KeyType, infer V> ? ['*'] | [K] | [K, ...WildcardPathAsArray<V>] : T extends Set<any> ? ['*'] | [number] : never);
@@ -0,0 +1,9 @@
1
+ import { type ErrorState, type PendingState, type ValueState } from './cacheState';
2
+ import { type MaybePromise } from './maybePromise';
3
+ export declare class PromiseWithState<T> extends Promise<T> {
4
+ state: ValueState<T> | ErrorState | PendingState;
5
+ static resolve(): PromiseWithState<void>;
6
+ static resolve<T>(value: MaybePromise<T>): PromiseWithState<T>;
7
+ static reject<T = never>(error: unknown): PromiseWithState<T>;
8
+ constructor(value: Promise<T>, state?: ValueState<T> | ErrorState | PendingState);
9
+ }
@@ -1,4 +1,5 @@
1
1
  import type { Store } from '../core/store';
2
+ import type { OptionalPropertyOf } from './typeHelpers';
2
3
  type Function_ = (...args: any) => any;
3
4
  export declare const arrayMethods: {
4
5
  splice: <T extends any[]>(this: Store<T>, ...args: T["splice"] extends Function_ ? Parameters<T["splice"]> : never) => T["splice"] extends Function_ ? ReturnType<T["splice"]> : never;
@@ -10,7 +11,7 @@ export declare const arrayMethods: {
10
11
  sort: <T_6 extends any[]>(this: Store<T_6>, ...args: T_6["sort"] extends Function_ ? Parameters<T_6["sort"]> : never) => T_6["sort"] extends Function_ ? ReturnType<T_6["sort"]> : never;
11
12
  };
12
13
  export declare const recordMethods: {
13
- delete<T extends Record<any, any>, K_1 extends Exclude<{ [K in keyof T]: T extends Record<K, T[K]> ? never : K; }[keyof T], undefined>>(this: Store<T>, key: K_1): void;
14
+ delete<T extends Record<any, any>, K extends OptionalPropertyOf<T>>(this: Store<T>, key: K): void;
14
15
  clear<T_1 extends Record<any, any>>(this: Store<Partial<T_1>>): void;
15
16
  };
16
17
  export declare const mapMethods: {
@@ -1,2 +1,3 @@
1
+ import { deepEqual } from './equals';
1
2
  export type TrackingProxy<T> = [value: T, equals: (newValue: T) => boolean];
2
- export declare function trackingProxy<T>(value: T): TrackingProxy<T>;
3
+ export declare function trackingProxy<T>(value: T, equals?: typeof deepEqual): TrackingProxy<T>;
@@ -1,4 +1,4 @@
1
- export type Object_ = Record<string | number, unknown>;
1
+ export type Object_ = Record<string | number | symbol, unknown>;
2
2
  export type Array_ = readonly unknown[];
3
3
  export type StringToNumber<T> = T extends `${infer K extends number}` ? K : never;
4
4
  export type ArrayToStringPath<T> = T extends [] ? '' : T extends [infer First extends string, ...infer Rest] ? First extends `${string}.${string}` ? never : Rest['length'] extends 0 ? First : `${First}.${ArrayToStringPath<Rest>}` : never;
@@ -6,3 +6,5 @@ export type StringToArrayPath<T> = T extends '' ? [] : T extends `${infer First}
6
6
  export type OptionalPropertyOf<T> = Exclude<{
7
7
  [K in keyof T]: T extends Record<K, T[K]> ? never : K;
8
8
  }[keyof T], undefined>;
9
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
10
+ export type IsNever<T> = [T] extends [never] ? true : false;
@@ -0,0 +1 @@
1
+ export declare function findOrDefault<T>(array: T[], predicate: (item: T) => boolean, defaultValue: T | (() => T)): T;
@@ -1,5 +1,7 @@
1
+ export { reactMethods } from './reactMethods';
1
2
  export { read } from './read';
2
- export { type StoreScopeProps, StoreScopeProvider, useStoreScope } from './storeScope';
3
+ export { ScopeProvider, useScope, type ScopeProps } from './scope';
3
4
  export { useCache, type UseCacheArray, type UseCacheValue } from './useCache';
5
+ export { useDecoupledState, type UseDecoupledStateOptions } from './useDecoupledState';
4
6
  export { useProp } from './useProp';
5
7
  export { useStore, type UseStoreOptions } from './useStore';
@@ -0,0 +1,9 @@
1
+ import { type UseStoreOptions } from './useStore';
2
+ import type { Store } from '../core/store';
3
+ export declare const reactMethods: {
4
+ useStore<T>(this: Store<T>, options?: UseStoreOptions): T;
5
+ useProp<T_1>(this: Store<T_1>, options?: UseStoreOptions): [value: T_1, setValue: {
6
+ (update: import("../core/commonTypes").Update<T_1>): void;
7
+ <P extends import("../lib/path").Path<T_1>>(path: P, update: import("../core/commonTypes").Update<import("../lib/path").Value<T_1, P>>): void;
8
+ }];
9
+ };
@@ -0,0 +1,29 @@
1
+ import { reactMethods } from './reactMethods';
2
+ import { type ScopeProps } from './scope';
3
+ import { type UseCacheOptions } from './useCache';
4
+ import { type UseStoreOptions } from './useStore';
5
+ import { Cache, Scope, Store } from '../core';
6
+ type StoreMethods = typeof reactMethods;
7
+ type CacheMethods = typeof cacheMethods;
8
+ type ScopeMethods = typeof scopeMethods;
9
+ declare module '../core' {
10
+ interface Store<T> extends StoreMethods {
11
+ }
12
+ interface Cache<T> extends CacheMethods {
13
+ }
14
+ interface Scope<T> extends ScopeMethods {
15
+ }
16
+ }
17
+ declare const cacheMethods: {
18
+ useCache<T>(this: Cache<T>, options?: UseCacheOptions): import("./useCache").UseCacheValue<T>;
19
+ };
20
+ declare const scopeMethods: {
21
+ useScope<T>(this: Scope<T>): Store<T>;
22
+ useStore<T_1>(this: Scope<T_1>, options?: UseStoreOptions): T_1;
23
+ useProp<T_2>(this: Scope<T_2>, options?: UseStoreOptions): [value: T_2, setValue: {
24
+ (update: import("../core/commonTypes").Update<T_2>): void;
25
+ <P extends import("../lib/path").Path<T_2>>(path: P, update: import("../core/commonTypes").Update<import("../lib/path").Value<T_2, P>>): void;
26
+ }];
27
+ Provider<T_3>(this: Scope<T_3>, props: Omit<ScopeProps<T_3>, "scope">): JSX.Element;
28
+ };
29
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { ReactNode } from 'react';
2
+ import { type UseStoreOptions } from './useStore';
3
+ import type { Store } from '../core/store';
4
+ import type { Scope } from '../core';
5
+ export type ScopeProps<T> = {
6
+ scope: Scope<T>;
7
+ store?: Store<T>;
8
+ children?: ReactNode;
9
+ };
10
+ export declare function ScopeProvider<T>({ scope, store: inputStore, children }: ScopeProps<T>): JSX.Element;
11
+ export declare function useScope<T>(scope: Scope<T>): Store<T>;
12
+ export declare function useScopeStore<T>(scope: Scope<T>, options?: UseStoreOptions): T;
13
+ export declare function useScopeProp<T>(scope: Scope<T>, options?: UseStoreOptions): [value: T, setValue: {
14
+ (update: import("../core/commonTypes").Update<T>): void;
15
+ <P extends import("../lib/path").Path<T>>(path: P, update: import("../core/commonTypes").Update<import("../lib/path").Value<T, P>>): void;
16
+ }];
@@ -10,5 +10,6 @@ export type UseCacheArray<T> = [
10
10
  export type UseCacheValue<T> = UseCacheArray<T> & CacheState<T>;
11
11
  export interface UseCacheOptions extends UseStoreOptions {
12
12
  passive?: boolean;
13
+ updateOnMount?: boolean;
13
14
  }
14
- export declare function useCache<T>(cache: Cache<T>, { passive, ...options }?: UseCacheOptions): UseCacheValue<T>;
15
+ export declare function useCache<T>(cache: Cache<T>, { passive, updateOnMount, ...options }?: UseCacheOptions): UseCacheValue<T>;
@@ -0,0 +1,7 @@
1
+ import { type Duration } from '../core';
2
+ export interface UseDecoupledStateOptions<T> {
3
+ debounce?: Duration;
4
+ throttle?: Duration;
5
+ onCommit?: (value: T) => void;
6
+ }
7
+ export declare function useDecoupledState<T>(value: T, onChange: (value: T) => void, options?: UseDecoupledStateOptions<T>): [state: T, setState: (value: T) => void];
@@ -1,4 +1,3 @@
1
1
  import type { UseStoreOptions } from './useStore';
2
2
  import type { Store } from '../core/store';
3
- import type { UpdateFunction } from '../core/commonTypes';
4
- export declare function useProp<T>(store: Store<T>, options?: UseStoreOptions): [value: T, setValue: UpdateFunction<T>];
3
+ export declare function useProp<T>(store: Store<T>, options?: UseStoreOptions): [value: T, setValue: typeof store.set];