vestjs-runtime 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/IsolateSerializer.development.js +114 -26
  2. package/dist/cjs/IsolateSerializer.development.js.map +1 -1
  3. package/dist/cjs/IsolateSerializer.production.js +1 -1
  4. package/dist/cjs/IsolateSerializer.production.js.map +1 -1
  5. package/dist/cjs/test-utils.development.js +22 -6
  6. package/dist/cjs/test-utils.development.js.map +1 -1
  7. package/dist/cjs/test-utils.production.js +1 -1
  8. package/dist/cjs/test-utils.production.js.map +1 -1
  9. package/dist/cjs/vestjs-runtime.development.js +114 -27
  10. package/dist/cjs/vestjs-runtime.development.js.map +1 -1
  11. package/dist/cjs/vestjs-runtime.production.js +1 -1
  12. package/dist/cjs/vestjs-runtime.production.js.map +1 -1
  13. package/dist/es/IsolateSerializer.development.js +115 -28
  14. package/dist/es/IsolateSerializer.development.js.map +1 -1
  15. package/dist/es/IsolateSerializer.production.js +1 -1
  16. package/dist/es/IsolateSerializer.production.js.map +1 -1
  17. package/dist/es/test-utils.development.js +22 -6
  18. package/dist/es/test-utils.development.js.map +1 -1
  19. package/dist/es/test-utils.production.js +1 -1
  20. package/dist/es/test-utils.production.js.map +1 -1
  21. package/dist/es/vestjs-runtime.development.js +115 -28
  22. package/dist/es/vestjs-runtime.development.js.map +1 -1
  23. package/dist/es/vestjs-runtime.production.js +1 -1
  24. package/dist/es/vestjs-runtime.production.js.map +1 -1
  25. package/dist/umd/IsolateSerializer.development.js +117 -30
  26. package/dist/umd/IsolateSerializer.development.js.map +1 -1
  27. package/dist/umd/IsolateSerializer.production.js +1 -1
  28. package/dist/umd/IsolateSerializer.production.js.map +1 -1
  29. package/dist/umd/test-utils.development.js +24 -10
  30. package/dist/umd/test-utils.development.js.map +1 -1
  31. package/dist/umd/test-utils.production.js +1 -1
  32. package/dist/umd/test-utils.production.js.map +1 -1
  33. package/dist/umd/vestjs-runtime.development.js +117 -31
  34. package/dist/umd/vestjs-runtime.development.js.map +1 -1
  35. package/dist/umd/vestjs-runtime.production.js +1 -1
  36. package/dist/umd/vestjs-runtime.production.js.map +1 -1
  37. package/package.json +3 -3
  38. package/types/IsolateSerializer.d.ts +22 -7
  39. package/types/IsolateSerializer.d.ts.map +1 -1
  40. package/types/test-utils.d.ts +5 -1
  41. package/types/test-utils.d.ts.map +1 -1
  42. package/types/vestjs-runtime.d.ts +51 -21
  43. package/types/vestjs-runtime.d.ts.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"vestjs-runtime.production.js","sources":["../../src/RuntimeEvents.ts","../../src/errors/ErrorStrings.ts","../../src/Isolate/IsolateInspector.ts","../../src/Isolate/IsolateMutator.ts","../../src/VestRuntime.ts","../../src/Bus.ts","../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateSelectors.ts","../../src/Reconciler.ts","../../src/Isolate/Isolate.ts","../../src/IsolateWalker.ts","../../src/exports/IsolateSerializer.ts"],"sourcesContent":["export const RuntimeEvents = {\n ISOLATE_ENTER: 'ISOLATE_ENTER',\n ISOLATE_PENDING: 'ISOLATE_PENDING',\n ISOLATE_DONE: 'ISOLATE_DONE',\n};\n","export enum ErrorStrings {\n NO_ACTIVE_ISOLATE = 'Not within an active isolate',\n UNABLE_TO_PICK_NEXT_ISOLATE = 'Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.',\n ENCOUNTERED_THE_SAME_KEY_TWICE = `Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.`,\n INVALID_ISOLATE_CANNOT_PARSE = `Invalid isolate was passed to IsolateSerializer. Cannot proceed.`,\n}\n","import { Nullable, isNotNullish, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateInspector {\n static at(isolate: Nullable<TIsolate>, at: number): Nullable<TIsolate> {\n if (isNullish(isolate)) {\n return null;\n }\n return isolate.children?.[at] ?? null;\n }\n\n static cursor(isolate: Nullable<TIsolate>): number {\n if (isNullish(isolate)) {\n return 0;\n }\n return isolate.children?.length ?? 0;\n }\n\n static canReorder<I extends TIsolate>(isolate: Nullable<I>): boolean {\n if (isNullish(isolate)) {\n return false;\n }\n\n return IsolateInspector.allowsReorder(isolate.parent);\n }\n\n static allowsReorder<I extends Record<any, any>>(\n isolate: Nullable<I>\n ): boolean {\n return isolate?.allowReorder === true;\n }\n\n static usesKey(isolate: Nullable<TIsolate>): boolean {\n if (isNullish(isolate)) {\n return false;\n }\n return isNotNullish(isolate.key);\n }\n\n static getChildByKey(\n isolate: Nullable<TIsolate>,\n key: string\n ): Nullable<TIsolate> {\n if (isNullish(isolate)) {\n return null;\n }\n return isolate.keys?.[key] ?? null;\n }\n}\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateMutator {\n static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {\n isolate.parent = parent;\n return isolate;\n }\n\n static saveOutput(isolate: TIsolate, output: any): TIsolate {\n isolate.output = output;\n return isolate;\n }\n\n static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {\n isolate.key = key;\n return isolate;\n }\n\n static addChild(isolate: TIsolate, child: TIsolate): void {\n invariant(isolate);\n\n isolate.children = isolate.children ?? [];\n\n isolate.children.push(child);\n IsolateMutator.setParent(child, isolate);\n }\n\n static removeChild(isolate: TIsolate, node: TIsolate): void {\n isolate.children =\n isolate.children?.filter(child => child !== node) ?? null;\n }\n\n static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {\n invariant(isolate);\n\n isolate.keys = isolate.keys ?? {};\n\n isolate.keys[key] = node;\n }\n\n static slice(isolate: TIsolate, at: number): void {\n if (isNullish(isolate.children)) {\n return;\n }\n isolate.children.length = at;\n }\n\n static setData(isolate: TIsolate, data: any): void {\n isolate.data = data;\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport { createCascade } from 'context';\nimport {\n invariant,\n deferThrow,\n isNullish,\n assign,\n TinyState,\n text,\n optionalFunctionValue,\n tinyState,\n BusType,\n bus,\n Nullable,\n DynamicValue,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateInspector } from 'IsolateInspector';\nimport { IsolateMutator } from 'IsolateMutator';\nimport { IRecociler } from 'Reconciler';\n\ntype CTXType = StateRefType & {\n historyNode: Nullable<TIsolate>;\n runtimeNode: Nullable<TIsolate>;\n runtimeRoot: Nullable<TIsolate>;\n stateRef: StateRefType;\n};\n\nexport type StateRefType = {\n Bus: BusType;\n appData: Record<string, any>;\n historyRoot: TinyState<Nullable<TIsolate>>;\n Reconciler: IRecociler;\n};\n\nconst PersistedContext = createCascade<CTXType>((stateRef, parentContext) => {\n if (parentContext) {\n return null;\n }\n\n invariant(stateRef.historyRoot);\n\n const [historyRootNode] = stateRef.historyRoot();\n\n const ctxRef = {} as CTXType;\n\n assign(ctxRef, {\n historyNode: historyRootNode,\n runtimeNode: null,\n runtimeRoot: null,\n stateRef,\n });\n\n return ctxRef;\n});\n\nexport const Run = PersistedContext.run;\n\nexport const RuntimeApi = {\n Run,\n addNodeToHistory,\n createRef,\n persist,\n reset,\n useAvailableRoot,\n useCurrentCursor,\n useHistoryRoot,\n useLoadRootNode,\n useXAppData,\n};\n\nexport function useXAppData<T = object>() {\n return useX().stateRef.appData as T;\n}\n\nexport function createRef(\n Reconciler: IRecociler,\n setter: DynamicValue<Record<string, any>>\n): StateRefType {\n return Object.freeze({\n Bus: bus.createBus(),\n Reconciler,\n appData: optionalFunctionValue(setter),\n historyRoot: tinyState.createTinyState<Nullable<TIsolate>>(null),\n });\n}\n\nexport function useReconciler() {\n return useX().stateRef.Reconciler;\n}\n\nexport function persist<T extends (...args: any[]) => any>(cb: T): T {\n const prev = PersistedContext.useX();\n\n return ((...args: Parameters<T>): ReturnType<T> => {\n const ctxToUse = PersistedContext.use() ?? prev;\n return PersistedContext.run(ctxToUse.stateRef, () => cb(...args));\n }) as T;\n}\nexport function useX<T = object>(): CTXType & T {\n return PersistedContext.useX() as CTXType & T;\n}\n\nexport function useHistoryRoot() {\n return useX().stateRef.historyRoot();\n}\nexport function useHistoryIsolate() {\n return useX().historyNode;\n}\n\n/**\n * Returns the history isolate at the current position.\n * If there is a parent isolate, it returns the history node from the parent's children.\n * Otherwise, it returns the history node.\n * @returns {Nullable<TIsolate>} The history isolate at the current position.\n */\nexport function useHistoryIsolateAtCurrentPosition() {\n const parent = useIsolate();\n\n // This is most likely the historic counterpart of the parent node\n\n const historyNode = useHistoryIsolate();\n\n if (parent) {\n // If we have a parent, we need to get the history node from the parent's children\n // We take the history node from the cursor of the active node's children\n return IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));\n }\n\n return historyNode;\n}\n\nexport function addNodeToHistory(node: TIsolate): void {\n const parent = useIsolate();\n if (parent) {\n useSetNextIsolateChild(node);\n } else {\n useSetHistory(node);\n }\n\n IsolateMutator.setParent(node, parent);\n}\n\nexport function useSetHistory(history: TIsolate) {\n const [, setHistoryRoot] = useHistoryRoot();\n setHistoryRoot(history);\n}\nexport function useHistoryKey(key?: Nullable<string>): Nullable<TIsolate> {\n if (isNullish(key)) {\n return null;\n }\n\n const historyNode = useX().historyNode;\n\n return IsolateInspector.getChildByKey(historyNode, key);\n}\n\nexport function useIsolate() {\n return useX().runtimeNode ?? null;\n}\nexport function useCurrentCursor() {\n const isolate = useIsolate();\n return isolate ? IsolateInspector.cursor(isolate) : 0;\n}\nexport function useRuntimeRoot() {\n return useX().runtimeRoot;\n}\nexport function useSetNextIsolateChild(child: TIsolate): void {\n const currentIsolate = useIsolate();\n\n invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);\n\n IsolateMutator.addChild(currentIsolate, child);\n}\nexport function useSetIsolateKey(key: Nullable<string>, node: TIsolate): void {\n if (!key) {\n return;\n }\n\n const currentIsolate = useIsolate();\n\n invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);\n\n if (isNullish(IsolateInspector.getChildByKey(currentIsolate, key))) {\n IsolateMutator.addChildKey(currentIsolate, key, node);\n\n return;\n }\n\n deferThrow(text(ErrorStrings.ENCOUNTERED_THE_SAME_KEY_TWICE, { key }));\n}\nexport function useAvailableRoot<I extends TIsolate = TIsolate>(): I {\n const root = useRuntimeRoot();\n\n if (root) {\n return root as I;\n }\n\n const [historyRoot] = useHistoryRoot();\n\n return historyRoot as I;\n}\n\nexport function reset() {\n const [, , resetHistoryRoot] = useHistoryRoot();\n\n resetHistoryRoot();\n}\n\nexport function useLoadRootNode(root: TIsolate): void {\n useSetHistory(root);\n}\n","import { isNullish } from 'vest-utils';\n\nimport { persist, useX } from 'VestRuntime';\n\nexport function useBus() {\n return useX().stateRef.Bus;\n}\n\n/*\n Returns an emitter, but it also has a shortcut for emitting an event immediately\n by passing an event name.\n*/\nexport function useEmit(event?: string, data?: any) {\n const emit = useBus().emit;\n\n if (!isNullish(event)) {\n emit(event, data);\n }\n\n return persist(emit);\n}\n\nexport function usePrepareEmitter<T = void>(event: string): (arg: T) => void {\n const emit = useEmit();\n\n return (arg: T) => emit(event, arg);\n}\n","export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\n Status = 'S',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","import { Maybe } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys } from 'IsolateKeys';\n\nexport function isIsolateType<I extends TIsolate>(\n node: Maybe<TIsolate>,\n type: string\n): node is I {\n return node?.[IsolateKeys.Type] === type;\n}\n\nexport function isSameIsolateType<A extends TIsolate, B extends TIsolate>(\n a: A,\n b: B\n): boolean {\n return isIsolateType(a, b[IsolateKeys.Type]);\n}\n\nexport function isSameIsolateIdentity<A extends TIsolate, B extends TIsolate>(\n a: A,\n b: B\n): boolean {\n return Object.is(a, b) || (isSameIsolateType(a, b) && a.key === b.key);\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport { Maybe, Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { type TIsolate } from 'Isolate';\nimport { IsolateInspector } from 'IsolateInspector';\nimport { IsolateMutator } from 'IsolateMutator';\nimport { isSameIsolateType } from 'IsolateSelectors';\nimport * as VestRuntime from 'VestRuntime';\n// import { isSameIsolateType } from 'IsolateSelectors';\n\n// I would rather not use `any` here, but instead use `Isolate`.\n// The problem is that it breaks the actual implementation of `Isolate` in `IsolateTest`\n// As it is not properly extending `Isolate`.\nexport interface IRecociler<I = any> {\n (currentNode: I, historyNode: I): Nullable<I>;\n}\n\nfunction BaseReconciler(\n currentNode: TIsolate,\n historyNode: TIsolate\n): TIsolate {\n if (isNullish(historyNode)) {\n return currentNode;\n }\n return currentNode;\n}\n\nexport class Reconciler {\n /**\n * Reconciles the current isolate with the history isolate.\n * If the current isolate is of a different type than the history isolate,\n * the current isolate is returned.\n * Otherwise, the reconciler function is called to determine the next isolate.\n * If the reconciler function returns null or undefined, the base reconciler is used.\n * If no history isolate exists, the current isolate is returned.\n * @param node The current isolate to reconcile.\n * @returns The next isolate after reconciliation.\n */\n static reconcile(node: TIsolate): TIsolate {\n const localHistoryNode = VestRuntime.useHistoryIsolateAtCurrentPosition();\n\n const nextNodeResult = pickNextNode(node, localHistoryNode);\n\n invariant(nextNodeResult, ErrorStrings.UNABLE_TO_PICK_NEXT_ISOLATE);\n\n return nextNodeResult;\n }\n\n static dropNextNodesOnReorder<I extends TIsolate>(\n reorderLogic: (newNode: I, prevNode: Maybe<TIsolate>) => boolean,\n newNode: I,\n prevNode: Maybe<TIsolate>\n ): boolean {\n const didReorder = reorderLogic(newNode, prevNode);\n\n if (didReorder) {\n removeAllNextNodesInIsolate();\n }\n\n return didReorder;\n }\n\n static handleIsolateNodeWithKey(node: TIsolate): TIsolate {\n invariant(IsolateInspector.usesKey(node));\n\n const prevNodeByKey = VestRuntime.useHistoryKey(node.key);\n\n let nextNode = node;\n\n if (!isNullish(prevNodeByKey)) {\n nextNode = prevNodeByKey;\n }\n\n VestRuntime.useSetIsolateKey(node.key, node);\n\n return nextNode;\n }\n}\n\nfunction pickNextNode(\n currentNode: TIsolate,\n historyNode: Nullable<TIsolate>\n): TIsolate {\n if (isNullish(historyNode)) {\n return handleNoHistoryNode(currentNode);\n }\n\n if (!isSameIsolateType(currentNode, historyNode)) {\n return currentNode;\n }\n\n const reconciler = VestRuntime.useReconciler();\n\n return (\n reconciler(currentNode, historyNode) ??\n BaseReconciler(currentNode, historyNode)\n );\n}\n\nfunction handleNoHistoryNode<I extends TIsolate>(newNode: I): I {\n if (IsolateInspector.usesKey(newNode)) {\n return Reconciler.handleIsolateNodeWithKey(newNode) as I;\n }\n\n return newNode;\n}\n\nfunction removeAllNextNodesInIsolate() {\n const currentNode = VestRuntime.useIsolate();\n const historyNode = VestRuntime.useHistoryIsolate();\n\n if (!historyNode || !currentNode) {\n // This is probably unreachable, but TS is not convinced.\n // Let's play it safe.\n /* istanbul ignore next */\n return;\n }\n\n IsolateMutator.slice(historyNode, IsolateInspector.cursor(currentNode));\n}\n","import { CB, Maybe, Nullable, isNotNullish, isPromise } from 'vest-utils';\n\nimport { useEmit } from 'Bus';\nimport { IsolateKeys } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\nimport { Reconciler } from 'Reconciler';\nimport { RuntimeEvents } from 'RuntimeEvents';\nimport * as VestRuntime from 'VestRuntime';\n\nexport type IsolateKey = Nullable<string>;\n\nexport type TIsolate<P extends IsolatePayload = IsolatePayload> = {\n [IsolateKeys.AllowReorder]?: boolean;\n [IsolateKeys.Parent]: Nullable<TIsolate>;\n [IsolateKeys.Type]: string;\n [IsolateKeys.Keys]: Nullable<Record<string, TIsolate>>;\n [IsolateKeys.Data]: DataOnly<P>;\n [IsolateKeys.Status]?: string;\n children: Nullable<TIsolate[]>;\n key: IsolateKey;\n output: any;\n} & UsedFeaturesOnly<P>;\n\ntype DataOnly<P extends IsolatePayload> = Omit<P, keyof IsolateFeatures>;\ntype UsedFeaturesOnly<P extends IsolatePayload> = Pick<\n P,\n keyof IsolateFeatures\n>;\n\nexport class Isolate {\n static create<Payload extends IsolatePayload>(\n type: string,\n callback: CB,\n payload: Maybe<Payload> = undefined,\n key?: IsolateKey\n ): TIsolate<Payload> {\n const parent = VestRuntime.useIsolate();\n\n const newCreatedNode = IsolateMutator.setParent(\n baseIsolate(type, payload, key),\n parent\n );\n\n const nextIsolateChild = Reconciler.reconcile(newCreatedNode);\n\n const localHistoryNode = VestRuntime.useHistoryIsolateAtCurrentPosition();\n\n const output = Object.is(nextIsolateChild, newCreatedNode)\n ? useRunAsNew(localHistoryNode, newCreatedNode, callback)\n : nextIsolateChild.output;\n\n IsolateMutator.setParent(nextIsolateChild, parent);\n IsolateMutator.saveOutput(nextIsolateChild, output);\n VestRuntime.addNodeToHistory(nextIsolateChild);\n\n return nextIsolateChild as TIsolate<Payload>;\n }\n\n static isIsolate(node: any): node is TIsolate {\n return isNotNullish(node) && node[IsolateKeys.Type];\n }\n}\n\n/**\n * Creates a new child isolate context where the local history node is the current history node, thus advancing the history cursor.\n * Runs the callback function and returns its output.\n * @param localHistoryNode The local history node.\n * @param current The current isolate.\n * @param callback The callback function to execute.\n * @returns The output of the callback function.\n */\nfunction useRunAsNew<Callback extends CB = CB>(\n localHistoryNode: Nullable<TIsolate>,\n current: TIsolate,\n callback: CB\n): ReturnType<Callback> {\n const runtimeRoot = VestRuntime.useRuntimeRoot();\n const emit = useEmit();\n\n // We're creating a new child isolate context where the local history node\n // is the current history node, thus advancing the history cursor.\n const output = VestRuntime.Run(\n {\n historyNode: localHistoryNode,\n runtimeNode: current,\n ...(!runtimeRoot && { runtimeRoot: current }),\n },\n () => {\n emit(RuntimeEvents.ISOLATE_ENTER, current);\n const output = callback(current);\n\n if (isPromise(output)) {\n emit(RuntimeEvents.ISOLATE_PENDING, current);\n output.then(iso => {\n if (Isolate.isIsolate(iso)) {\n IsolateMutator.addChild(current, iso);\n }\n\n emit(RuntimeEvents.ISOLATE_DONE, current);\n });\n } else {\n emit(RuntimeEvents.ISOLATE_DONE, current);\n }\n\n return output;\n }\n );\n\n current.output = output;\n return output;\n}\n\nfunction baseIsolate(\n type: string,\n payload: Maybe<IsolatePayload> = undefined,\n key: IsolateKey = null\n): TIsolate {\n const { allowReorder, status, ...data } = payload ?? {};\n return {\n [IsolateKeys.AllowReorder]: allowReorder,\n [IsolateKeys.Keys]: null,\n [IsolateKeys.Parent]: null,\n [IsolateKeys.Type]: type,\n [IsolateKeys.Data]: data as IsolateData,\n ...(status && { [IsolateKeys.Status]: status }),\n children: null,\n key,\n output: null,\n };\n}\n\ntype IsolateData = Record<string, any>;\ntype IsolatePayload = IsolateData & IsolateFeatures;\ntype IsolateFeatures = {\n [IsolateKeys.AllowReorder]?: boolean;\n [IsolateKeys.Status]?: string;\n};\n","import { CB, Nullable, isNullish, optionalFunctionValue } from 'vest-utils';\n\nimport { type TIsolate } from 'Isolate';\nimport { IsolateMutator } from 'IsolateMutator';\n\ntype VisitOnlyPredicate = (isolate: TIsolate) => boolean;\n\n// eslint-disable-next-line\nexport function walk(\n startNode: TIsolate,\n callback: (isolate: TIsolate, breakout: CB<void>) => void,\n visitOnly?: VisitOnlyPredicate\n): void {\n // If the startNode has no children, there is nothing to walk.\n if (isNullish(startNode.children)) {\n return;\n }\n\n let broke = false;\n\n // For each child Isolate object, call the callback function.\n for (const isolate of startNode.children) {\n if (broke) {\n return;\n }\n\n // If visitOnly is not provided or the predicate is satisfied, call the callback function.\n if (isNullish(visitOnly) || optionalFunctionValue(visitOnly, isolate)) {\n callback(isolate, breakout);\n }\n\n // If the breakout function has been called, stop the walk.\n if (broke) {\n return;\n }\n\n // Recursively walk through the child Isolate object.\n walk(\n isolate,\n (child, innerBreakout) => {\n callback(child, () => {\n innerBreakout();\n breakout();\n });\n },\n visitOnly\n );\n }\n\n function breakout() {\n broke = true;\n }\n}\n\n// This function returns true if the given predicate function returns true for any Isolate object in the tree.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function some(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): boolean {\n let hasMatch = false;\n\n // Call the walk function with a callback function that sets hasMatch to true if the predicate is satisfied.\n walk(\n startNode,\n (node, breakout) => {\n if (predicate(node)) {\n breakout();\n hasMatch = true;\n }\n },\n visitOnly\n );\n\n return hasMatch;\n}\n\n// This function returns true if the given predicate function returns true for any Isolate object in the tree.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function has(startNode: TIsolate, match: VisitOnlyPredicate): boolean {\n return some(startNode, () => true, match);\n}\n\n// traverses up to a parent node that satisfies the predicate\n// and returns the first direct descendant that satisfies the predicate\nexport function findClosest<I extends TIsolate = TIsolate>(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean\n): Nullable<I> {\n let found: Nullable<TIsolate> = null;\n let current: Nullable<TIsolate> = startNode;\n\n while (current) {\n found = current.children?.find(predicate) ?? null;\n\n if (found) {\n break;\n }\n\n current = current.parent;\n }\n\n return found as Nullable<I>;\n}\n\n// This function returns the first Isolate object in the tree that satisfies the given predicate function.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function find(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): Nullable<TIsolate> {\n let found = null;\n\n // Call the walk function with a callback function that sets found to the current node if the predicate is satisfied.\n walk(\n startNode,\n (node, breakout) => {\n if (predicate(node)) {\n breakout();\n found = node;\n }\n },\n visitOnly\n );\n\n return found;\n}\n\n// This function returns true if the given predicate function returns true for every Isolate object in the tree.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function every(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): boolean {\n let hasMatch = true;\n walk(\n startNode,\n (node, breakout) => {\n if (!predicate(node)) {\n breakout();\n hasMatch = false;\n }\n },\n visitOnly\n );\n\n return hasMatch;\n}\n\n// This function removes all Isolate objects in the tree that\n// satisfy the given predicate function and have a parent.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function pluck(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): void {\n walk(\n startNode,\n node => {\n if (predicate(node) && node.parent) {\n IsolateMutator.removeChild(node.parent, node);\n }\n },\n visitOnly\n );\n}\n\n// Returns the closest ancestor Isolate object of the given\n//startNode that satisfies the given predicate function.\nexport function closest(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean\n): Nullable<TIsolate> {\n let current: Nullable<TIsolate> = startNode;\n do {\n if (predicate(current)) {\n return current;\n }\n current = current.parent;\n } while (current);\n return null;\n}\n\n// This function returns true if the closest ancestor Isolates of the\n// given startNode that satisfies the given predicate function exists.\nexport function closestExists(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean\n): boolean {\n return !!closest(startNode, predicate);\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Nullable,\n hasOwnProperty,\n invariant,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys, KeyToMinified, MinifiedToKey } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity\n static deserialize(node: Record<string, any> | TIsolate | string): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n while (queue.length) {\n const current = queue.shift();\n\n const children = IsolateSerializer.getChildren(current);\n\n for (const key in MinifiedToKey) {\n const value = current[key];\n if (isNotNullish(value)) {\n current[MinifiedToKey[key]] = value;\n delete current[key];\n }\n }\n\n if (!children) {\n continue;\n }\n\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(isolate: Nullable<TIsolate>): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate));\n }\n\n static getChildren(node: TIsolate): Nullable<TIsolate[]> {\n return node.children ? [...node.children] : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(isolate: TIsolate): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next.children = isolate.children.map(transformIsolate);\n }\n\n for (const key in isolate) {\n if (key === 'children') {\n continue;\n }\n\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n if (hasOwnProperty(KeyToMinified, key)) {\n next[KeyToMinified[key]] = value;\n } else {\n next[key] = value;\n }\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return [IsolateKeys.Parent, IsolateKeys.Keys].includes(key as IsolateKeys);\n}\n"],"names":["RuntimeEvents","ISOLATE_ENTER","ISOLATE_PENDING","ISOLATE_DONE","ErrorStrings","IsolateInspector","static","isolate","at","isNullish","_b","_a","children","length","allowsReorder","parent","allowReorder","isNotNullish","key","keys","IsolateMutator","output","child","invariant","push","setParent","node","filter","data","PersistedContext","createCascade","stateRef","parentContext","historyRoot","historyRootNode","ctxRef","assign","historyNode","runtimeNode","runtimeRoot","Run","run","RuntimeApi","addNodeToHistory","createRef","Reconciler","setter","Object","freeze","Bus","bus","createBus","appData","optionalFunctionValue","tinyState","createTinyState","persist","reset","resetHistoryRoot","useHistoryRoot","useAvailableRoot","root","useRuntimeRoot","useCurrentCursor","useIsolate","cursor","useLoadRootNode","useSetHistory","useXAppData","useX","cb","prev","args","ctxToUse","use","useHistoryIsolate","useHistoryIsolateAtCurrentPosition","currentIsolate","NO_ACTIVE_ISOLATE","addChild","useSetNextIsolateChild","history","setHistoryRoot","useBus","useEmit","event","emit","IsolateKeys","MinifiedKeys","arg","KeyToMinified","Type","Keys","Parent","Data","Key","AllowReorder","Status","MinifiedToKey","entries","reduce","acc","minified","isIsolateType","type","isSameIsolateType","a","b","is","nextNodeResult","currentNode","newNode","usesKey","handleIsolateNodeWithKey","handleNoHistoryNode","reconciler","BaseReconciler","pickNextNode","VestRuntime.useHistoryIsolateAtCurrentPosition","UNABLE_TO_PICK_NEXT_ISOLATE","reorderLogic","prevNode","didReorder","VestRuntime.useIsolate","VestRuntime.useHistoryIsolate","slice","removeAllNextNodesInIsolate","prevNodeByKey","getChildByKey","VestRuntime.useHistoryKey","nextNode","addChildKey","deferThrow","text","ENCOUNTERED_THE_SAME_KEY_TWICE","VestRuntime.useSetIsolateKey","Isolate","callback","payload","newCreatedNode","status","__rest","baseIsolate","nextIsolateChild","reconcile","localHistoryNode","current","VestRuntime.useRuntimeRoot","VestRuntime.Run","isPromise","then","iso","isIsolate","useRunAsNew","saveOutput","VestRuntime.addNodeToHistory","walk","startNode","visitOnly","broke","breakout","innerBreakout","some","predicate","hasMatch","closest","found","find","match","removeChild","IsolateSerializer","isStringValue","JSON","parse","validateIsolate","queue","shift","getChildren","value","map","nextChild","stringify","transformIsolate","hasOwnProperty","INVALID_ISOLATE_CANNOT_PARSE","next","isKeyExcluededFromDump","includes"],"mappings":"8DAAa,MAAAA,EAAgB,CAC3BC,cAAe,gBACfC,gBAAiB,kBACjBC,aAAc,gBCHhB,IAAYC,sDAAZ,SAAYA,GACVA,EAAA,kBAAA,+BACAA,EAAA,4BAAA,wFACAA,EAAA,+BAAA,kGACAA,EAAA,6BAAA,kEACD,CALD,CAAYA,IAAAA,EAKX,CAAA,UCDYC,EACXC,UAAUC,EAA6BC,WACrC,OAAIC,EAAAA,UAAUF,GACL,KAEwB,QAA1BG,UAAAC,EAAAJ,EAAQK,+BAAWJ,UAAO,IAAAE,EAAAA,EAAA,IAClC,CAEDJ,cAAcC,WACZ,OAAIE,EAAAA,UAAUF,GACL,EAE0B,QAA5BG,EAAkB,UAAlBH,EAAQK,gBAAU,IAAAD,OAAA,EAAAA,EAAAE,cAAU,IAAAH,EAAAA,EAAA,CACpC,CAEDJ,kBAAsCC,GACpC,OAAIE,EAAAA,UAAUF,IAIPF,EAAiBS,cAAcP,EAAQQ,OAC/C,CAEDT,qBACEC,GAEA,OAAiC,KAA1BA,aAAO,EAAPA,EAASS,aACjB,CAEDV,eAAeC,GACb,OAAIE,EAAAA,UAAUF,IAGPU,EAAYA,aAACV,EAAQW,IAC7B,CAEDZ,qBACEC,EACAW,WAEA,OAAIT,EAAAA,UAAUF,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ACvBhC,EAAQhI,GAElB,CAEIN,IAILsI,EAAQtI,SAAWA,EAASuK,KAAI7J,UAC9B,MAAM8J,EAASrI,OAAAX,OAAA,CAAA,EAAQd,GAEvBF,EAAeK,UAAU2J,EAAWlC,GACpC6B,EAAMvJ,KAAK4J,GAEX,MAAMlK,EAAMkK,EAAUlK,IAOtB,OALIA,IACFgI,EAAQ/H,KAAuB,QAAhBR,EAAAuI,EAAQ/H,YAAQ,IAAAR,EAAAA,EAAA,CAAA,EAC/BuI,EAAQ/H,KAAKD,GAAOkK,GAGfA,CAAS,IAEnB,CAED,OAAOvH,CACR,CAEDvD,iBAAiBC,GACf,OAAIE,EAAAA,UAAUF,GACL,GAGFqK,KAAKS,UAAUC,EAAiB/K,GACxC,CAEDD,mBAAmBoB,GACjB,OAAOA,EAAKd,SAAW,IAAIc,EAAKd,UAAY,IAC7C,CAEDN,uBAAuBoB,GACrBH,EAAAA,UACEgK,EAAcA,eAAC7J,EAAM6D,EAAYI,OAC/B4F,iBAAe7J,EAAMgE,EAAcH,EAAYI,OACjD0C,OAAKjI,EAAaoL,8BAErB,EAIH,SAASF,EAAiB/K,GACxB,MAAMkL,EAA4B,CAAA,EAE9BlL,EAAQK,WACV6K,EAAK7K,SAAWL,EAAQK,SAASuK,IAAIG,IAGvC,IAAK,MAAMpK,KAAOX,EAAS,CACzB,GAAY,aAARW,EACF,SAGF,GAAIwK,EAAuBxK,GACzB,SAEF,MAAMgK,EAAQ3K,EAAQW,GAElBT,EAAAA,UAAUyK,KAIVK,EAAcA,eAAC7F,EAAexE,GAChCuK,EAAK/F,EAAcxE,IAAQgK,EAE3BO,EAAKvK,GAAOgK,EAEf,CAED,OAAOO,CACT,CAEA,SAASC,EAAuBxK,GAC9B,MAAO,CAACqE,EAAYM,OAAQN,EAAYK,MAAM+F,SAASzK,EACzD"}
1
+ {"version":3,"file":"vestjs-runtime.production.js","sources":["../../src/RuntimeEvents.ts","../../src/errors/ErrorStrings.ts","../../src/Isolate/IsolateInspector.ts","../../src/Isolate/IsolateMutator.ts","../../src/VestRuntime.ts","../../src/Bus.ts","../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateSelectors.ts","../../src/Reconciler.ts","../../src/Isolate/Isolate.ts","../../src/IsolateWalker.ts","../../src/exports/IsolateSerializer.ts"],"sourcesContent":["export const RuntimeEvents = {\n ISOLATE_ENTER: 'ISOLATE_ENTER',\n ISOLATE_PENDING: 'ISOLATE_PENDING',\n ISOLATE_DONE: 'ISOLATE_DONE',\n};\n","export enum ErrorStrings {\n NO_ACTIVE_ISOLATE = 'Not within an active isolate',\n UNABLE_TO_PICK_NEXT_ISOLATE = 'Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.',\n ENCOUNTERED_THE_SAME_KEY_TWICE = `Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.`,\n INVALID_ISOLATE_CANNOT_PARSE = `Invalid isolate was passed to IsolateSerializer. Cannot proceed.`,\n}\n","import { Nullable, isNotNullish, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateInspector {\n static at(isolate: Nullable<TIsolate>, at: number): Nullable<TIsolate> {\n if (isNullish(isolate)) {\n return null;\n }\n return isolate.children?.[at] ?? null;\n }\n\n static cursor(isolate: Nullable<TIsolate>): number {\n if (isNullish(isolate)) {\n return 0;\n }\n return isolate.children?.length ?? 0;\n }\n\n static canReorder<I extends TIsolate>(isolate: Nullable<I>): boolean {\n if (isNullish(isolate)) {\n return false;\n }\n\n return IsolateInspector.allowsReorder(isolate.parent);\n }\n\n static allowsReorder<I extends Record<any, any>>(\n isolate: Nullable<I>\n ): boolean {\n return isolate?.allowReorder === true;\n }\n\n static usesKey(isolate: Nullable<TIsolate>): boolean {\n if (isNullish(isolate)) {\n return false;\n }\n return isNotNullish(isolate.key);\n }\n\n static getChildByKey(\n isolate: Nullable<TIsolate>,\n key: string\n ): Nullable<TIsolate> {\n if (isNullish(isolate)) {\n return null;\n }\n return isolate.keys?.[key] ?? null;\n }\n}\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateMutator {\n static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {\n isolate.parent = parent;\n return isolate;\n }\n\n static saveOutput(isolate: TIsolate, output: any): TIsolate {\n isolate.output = output;\n return isolate;\n }\n\n static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {\n isolate.key = key;\n return isolate;\n }\n\n static addChild(isolate: TIsolate, child: TIsolate): void {\n invariant(isolate);\n\n isolate.children = isolate.children ?? [];\n\n isolate.children.push(child);\n IsolateMutator.setParent(child, isolate);\n }\n\n static removeChild(isolate: TIsolate, node: TIsolate): void {\n isolate.children =\n isolate.children?.filter(child => child !== node) ?? null;\n }\n\n static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {\n invariant(isolate);\n\n isolate.keys = isolate.keys ?? {};\n\n isolate.keys[key] = node;\n }\n\n static slice(isolate: TIsolate, at: number): void {\n if (isNullish(isolate.children)) {\n return;\n }\n isolate.children.length = at;\n }\n\n static setData(isolate: TIsolate, data: any): void {\n isolate.data = data;\n }\n\n static abort(isolate: TIsolate, reason?: string): void {\n if (isNullish(isolate.abortController)) {\n return;\n }\n isolate.abortController.abort(reason);\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport { createCascade } from 'context';\nimport {\n invariant,\n deferThrow,\n isNullish,\n assign,\n TinyState,\n text,\n optionalFunctionValue,\n tinyState,\n BusType,\n bus,\n Nullable,\n DynamicValue,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateInspector } from 'IsolateInspector';\nimport { IsolateMutator } from 'IsolateMutator';\nimport { IRecociler } from 'Reconciler';\n\ntype CTXType = StateRefType & {\n historyNode: Nullable<TIsolate>;\n runtimeNode: Nullable<TIsolate>;\n runtimeRoot: Nullable<TIsolate>;\n stateRef: StateRefType;\n};\n\nexport type StateRefType = {\n Bus: BusType;\n appData: Record<string, any>;\n historyRoot: TinyState<Nullable<TIsolate>>;\n Reconciler: IRecociler;\n};\n\nconst PersistedContext = createCascade<CTXType>((stateRef, parentContext) => {\n if (parentContext) {\n return null;\n }\n\n invariant(stateRef.historyRoot);\n\n const [historyRootNode] = stateRef.historyRoot();\n\n const ctxRef = {} as CTXType;\n\n assign(ctxRef, {\n historyNode: historyRootNode,\n runtimeNode: null,\n runtimeRoot: null,\n stateRef,\n });\n\n return ctxRef;\n});\n\nexport const Run = PersistedContext.run;\n\nexport const RuntimeApi = {\n Run,\n addNodeToHistory,\n createRef,\n persist,\n reset,\n useAvailableRoot,\n useCurrentCursor,\n useHistoryRoot,\n useLoadRootNode,\n useXAppData,\n};\n\nexport function useXAppData<T = object>() {\n return useX().stateRef.appData as T;\n}\n\nexport function createRef(\n Reconciler: IRecociler,\n setter: DynamicValue<Record<string, any>>\n): StateRefType {\n return Object.freeze({\n Bus: bus.createBus(),\n Reconciler,\n appData: optionalFunctionValue(setter),\n historyRoot: tinyState.createTinyState<Nullable<TIsolate>>(null),\n });\n}\n\nexport function useReconciler() {\n return useX().stateRef.Reconciler;\n}\n\nexport function persist<T extends (...args: any[]) => any>(cb: T): T {\n const prev = PersistedContext.useX();\n\n return ((...args: Parameters<T>): ReturnType<T> => {\n const ctxToUse = PersistedContext.use() ?? prev;\n return PersistedContext.run(ctxToUse.stateRef, () => cb(...args));\n }) as T;\n}\nexport function useX<T = object>(): CTXType & T {\n return PersistedContext.useX() as CTXType & T;\n}\n\nexport function useHistoryRoot() {\n return useX().stateRef.historyRoot();\n}\nexport function useHistoryIsolate() {\n return useX().historyNode;\n}\n\n/**\n * Returns the history isolate at the current position.\n * If there is a parent isolate, it returns the history node from the parent's children.\n * Otherwise, it returns the history node.\n * @returns {Nullable<TIsolate>} The history isolate at the current position.\n */\nexport function useHistoryIsolateAtCurrentPosition() {\n const parent = useIsolate();\n\n // This is most likely the historic counterpart of the parent node\n\n const historyNode = useHistoryIsolate();\n\n if (parent) {\n // If we have a parent, we need to get the history node from the parent's children\n // We take the history node from the cursor of the active node's children\n return IsolateInspector.at(historyNode, IsolateInspector.cursor(parent));\n }\n\n return historyNode;\n}\n\nexport function addNodeToHistory(node: TIsolate): void {\n const parent = useIsolate();\n if (parent) {\n useSetNextIsolateChild(node);\n } else {\n useSetHistory(node);\n }\n\n IsolateMutator.setParent(node, parent);\n}\n\nexport function useSetHistory(history: TIsolate) {\n const [, setHistoryRoot] = useHistoryRoot();\n setHistoryRoot(history);\n}\nexport function useHistoryKey(key?: Nullable<string>): Nullable<TIsolate> {\n if (isNullish(key)) {\n return null;\n }\n\n const historyNode = useX().historyNode;\n\n return IsolateInspector.getChildByKey(historyNode, key);\n}\n\nexport function useIsolate() {\n return useX().runtimeNode ?? null;\n}\nexport function useCurrentCursor() {\n const isolate = useIsolate();\n return isolate ? IsolateInspector.cursor(isolate) : 0;\n}\nexport function useRuntimeRoot() {\n return useX().runtimeRoot;\n}\nexport function useSetNextIsolateChild(child: TIsolate): void {\n const currentIsolate = useIsolate();\n\n invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);\n\n IsolateMutator.addChild(currentIsolate, child);\n}\nexport function useSetIsolateKey(key: Nullable<string>, node: TIsolate): void {\n if (!key) {\n return;\n }\n\n const currentIsolate = useIsolate();\n\n invariant(currentIsolate, ErrorStrings.NO_ACTIVE_ISOLATE);\n\n if (isNullish(IsolateInspector.getChildByKey(currentIsolate, key))) {\n IsolateMutator.addChildKey(currentIsolate, key, node);\n\n return;\n }\n\n deferThrow(text(ErrorStrings.ENCOUNTERED_THE_SAME_KEY_TWICE, { key }));\n}\nexport function useAvailableRoot<I extends TIsolate = TIsolate>(): I {\n const root = useRuntimeRoot();\n\n if (root) {\n return root as I;\n }\n\n const [historyRoot] = useHistoryRoot();\n\n return historyRoot as I;\n}\n\nexport function reset() {\n const [, , resetHistoryRoot] = useHistoryRoot();\n\n resetHistoryRoot();\n}\n\nexport function useLoadRootNode(root: TIsolate): void {\n useSetHistory(root);\n}\n","import { isNullish } from 'vest-utils';\n\nimport { persist, useX } from 'VestRuntime';\n\nexport function useBus() {\n return useX().stateRef.Bus;\n}\n\n/*\n Returns an emitter, but it also has a shortcut for emitting an event immediately\n by passing an event name.\n*/\nexport function useEmit(event?: string, data?: any) {\n const emit = useBus().emit;\n\n if (!isNullish(event)) {\n emit(event, data);\n }\n\n return persist(emit);\n}\n\nexport function usePrepareEmitter<T = void>(event: string): (arg: T) => void {\n const emit = useEmit();\n\n return (arg: T) => emit(event, arg);\n}\n","import { assign } from 'lodash';\n\nexport enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n AbortController = 'abortController',\n Children = 'children',\n}\n\nexport enum MinifiedKeys {\n Type = '$',\n Keys = 'Ks',\n Key = 'ky',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'AR',\n Status = 'S',\n Children = 'C',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n [IsolateKeys.Children]: MinifiedKeys.Children,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = invertKeyMap(KeyToMinified);\n\nexport function invertKeyMap(miniMap: Record<string, string> = {}) {\n return Object.entries(miniMap).reduce(\n (acc, [key, minified]) =>\n assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, string>\n );\n}\n\nexport const ExcludedFromDump = [\n IsolateKeys.AbortController,\n IsolateKeys.Parent,\n IsolateKeys.Keys,\n IsolateKeys.Children,\n IsolateKeys.Data,\n];\n","import { Maybe } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys } from 'IsolateKeys';\n\nexport function isIsolateType<I extends TIsolate>(\n node: Maybe<TIsolate>,\n type: string\n): node is I {\n return node?.[IsolateKeys.Type] === type;\n}\n\nexport function isSameIsolateType<A extends TIsolate, B extends TIsolate>(\n a: A,\n b: B\n): boolean {\n return isIsolateType(a, b[IsolateKeys.Type]);\n}\n\nexport function isSameIsolateIdentity<A extends TIsolate, B extends TIsolate>(\n a: A,\n b: B\n): boolean {\n return Object.is(a, b) || (isSameIsolateType(a, b) && a.key === b.key);\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport { Maybe, Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { type TIsolate } from 'Isolate';\nimport { IsolateInspector } from 'IsolateInspector';\nimport { IsolateMutator } from 'IsolateMutator';\nimport { isSameIsolateType } from 'IsolateSelectors';\nimport * as VestRuntime from 'VestRuntime';\n// import { isSameIsolateType } from 'IsolateSelectors';\n\n// I would rather not use `any` here, but instead use `Isolate`.\n// The problem is that it breaks the actual implementation of `Isolate` in `IsolateTest`\n// As it is not properly extending `Isolate`.\nexport interface IRecociler<I = any> {\n (currentNode: I, historyNode: I): Nullable<I>;\n}\n\nfunction BaseReconciler(\n currentNode: TIsolate,\n historyNode: TIsolate\n): TIsolate {\n if (isNullish(historyNode)) {\n return currentNode;\n }\n return currentNode;\n}\n\nexport class Reconciler {\n /**\n * Reconciles the current isolate with the history isolate.\n * If the current isolate is of a different type than the history isolate,\n * the current isolate is returned.\n * Otherwise, the reconciler function is called to determine the next isolate.\n * If the reconciler function returns null or undefined, the base reconciler is used.\n * If no history isolate exists, the current isolate is returned.\n * @param node The current isolate to reconcile.\n * @returns The next isolate after reconciliation.\n */\n static reconcile(node: TIsolate): TIsolate {\n const localHistoryNode = VestRuntime.useHistoryIsolateAtCurrentPosition();\n\n const nextNodeResult = pickNextNode(node, localHistoryNode);\n\n invariant(nextNodeResult, ErrorStrings.UNABLE_TO_PICK_NEXT_ISOLATE);\n\n return nextNodeResult;\n }\n\n static dropNextNodesOnReorder<I extends TIsolate>(\n reorderLogic: (newNode: I, prevNode: Maybe<TIsolate>) => boolean,\n newNode: I,\n prevNode: Maybe<TIsolate>\n ): boolean {\n const didReorder = reorderLogic(newNode, prevNode);\n\n if (didReorder) {\n removeAllNextNodesInIsolate();\n }\n\n return didReorder;\n }\n\n static handleIsolateNodeWithKey(node: TIsolate): TIsolate {\n invariant(IsolateInspector.usesKey(node));\n\n const prevNodeByKey = VestRuntime.useHistoryKey(node.key);\n\n let nextNode = node;\n\n if (!isNullish(prevNodeByKey)) {\n nextNode = prevNodeByKey;\n }\n\n VestRuntime.useSetIsolateKey(node.key, node);\n\n return nextNode;\n }\n}\n\nfunction pickNextNode(\n currentNode: TIsolate,\n historyNode: Nullable<TIsolate>\n): TIsolate {\n if (isNullish(historyNode)) {\n return handleNoHistoryNode(currentNode);\n }\n\n if (!isSameIsolateType(currentNode, historyNode)) {\n return currentNode;\n }\n\n const reconciler = VestRuntime.useReconciler();\n\n return (\n reconciler(currentNode, historyNode) ??\n BaseReconciler(currentNode, historyNode)\n );\n}\n\nfunction handleNoHistoryNode<I extends TIsolate>(newNode: I): I {\n if (IsolateInspector.usesKey(newNode)) {\n return Reconciler.handleIsolateNodeWithKey(newNode) as I;\n }\n\n return newNode;\n}\n\nfunction removeAllNextNodesInIsolate() {\n const currentNode = VestRuntime.useIsolate();\n const historyNode = VestRuntime.useHistoryIsolate();\n\n if (!historyNode || !currentNode) {\n // This is probably unreachable, but TS is not convinced.\n // Let's play it safe.\n /* istanbul ignore next */\n return;\n }\n\n IsolateMutator.slice(historyNode, IsolateInspector.cursor(currentNode));\n}\n","import { CB, Maybe, Nullable, isNotNullish, isPromise } from 'vest-utils';\n\nimport { useEmit } from 'Bus';\nimport { IsolateKeys } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\nimport { Reconciler } from 'Reconciler';\nimport { RuntimeEvents } from 'RuntimeEvents';\nimport * as VestRuntime from 'VestRuntime';\n\nexport type IsolateKey = Nullable<string>;\n\nexport type TIsolate<P extends IsolatePayload = IsolatePayload> = {\n [IsolateKeys.AllowReorder]?: boolean;\n [IsolateKeys.Parent]: Nullable<TIsolate>;\n [IsolateKeys.Type]: string;\n [IsolateKeys.Keys]: Nullable<Record<string, TIsolate>>;\n [IsolateKeys.Data]: DataOnly<P>;\n [IsolateKeys.Status]?: string;\n [IsolateKeys.AbortController]: AbortController;\n children: Nullable<TIsolate[]>;\n key: IsolateKey;\n output: any;\n} & UsedFeaturesOnly<P>;\n\ntype DataOnly<P extends IsolatePayload> = Omit<P, keyof IsolateFeatures>;\ntype UsedFeaturesOnly<P extends IsolatePayload> = Pick<\n P,\n keyof IsolateFeatures\n>;\n\nexport class Isolate {\n static create<Payload extends IsolatePayload>(\n type: string,\n callback: CB,\n payload: Maybe<Payload> = undefined,\n key?: IsolateKey\n ): TIsolate<Payload> {\n const parent = VestRuntime.useIsolate();\n\n const newCreatedNode = IsolateMutator.setParent(\n baseIsolate(type, payload, key),\n parent\n );\n\n const nextIsolateChild = Reconciler.reconcile(newCreatedNode);\n\n const localHistoryNode = VestRuntime.useHistoryIsolateAtCurrentPosition();\n\n const output = Object.is(nextIsolateChild, newCreatedNode)\n ? useRunAsNew(localHistoryNode, newCreatedNode, callback)\n : nextIsolateChild.output;\n\n IsolateMutator.setParent(nextIsolateChild, parent);\n IsolateMutator.saveOutput(nextIsolateChild, output);\n VestRuntime.addNodeToHistory(nextIsolateChild);\n\n return nextIsolateChild as TIsolate<Payload>;\n }\n\n static isIsolate(node: any): node is TIsolate {\n return isNotNullish(node) && node[IsolateKeys.Type];\n }\n}\n\n/**\n * Creates a new child isolate context where the local history node is the current history node, thus advancing the history cursor.\n * Runs the callback function and returns its output.\n * @param localHistoryNode The local history node.\n * @param current The current isolate.\n * @param callback The callback function to execute.\n * @returns The output of the callback function.\n */\nfunction useRunAsNew<Callback extends CB = CB>(\n localHistoryNode: Nullable<TIsolate>,\n current: TIsolate,\n callback: CB\n): ReturnType<Callback> {\n const runtimeRoot = VestRuntime.useRuntimeRoot();\n const emit = useEmit();\n\n // We're creating a new child isolate context where the local history node\n // is the current history node, thus advancing the history cursor.\n const output = VestRuntime.Run(\n {\n historyNode: localHistoryNode,\n runtimeNode: current,\n ...(!runtimeRoot && { runtimeRoot: current }),\n },\n () => {\n emit(RuntimeEvents.ISOLATE_ENTER, current);\n const output = callback(current);\n\n if (isPromise(output)) {\n emit(RuntimeEvents.ISOLATE_PENDING, current);\n output.then(iso => {\n if (Isolate.isIsolate(iso)) {\n IsolateMutator.addChild(current, iso);\n }\n\n emit(RuntimeEvents.ISOLATE_DONE, current);\n });\n } else {\n emit(RuntimeEvents.ISOLATE_DONE, current);\n }\n\n return output;\n }\n );\n\n current.output = output;\n return output;\n}\n\nfunction baseIsolate(\n type: string,\n payload: Maybe<IsolatePayload> = undefined,\n key: IsolateKey = null\n): TIsolate {\n const { allowReorder, status, ...data } = payload ?? {};\n return {\n [IsolateKeys.AllowReorder]: allowReorder,\n [IsolateKeys.AbortController]: new AbortController(),\n [IsolateKeys.Keys]: null,\n [IsolateKeys.Parent]: null,\n [IsolateKeys.Type]: type,\n [IsolateKeys.Data]: data as IsolateData,\n ...(status && { [IsolateKeys.Status]: status }),\n children: null,\n key,\n output: null,\n };\n}\n\ntype IsolateData = Record<string, any>;\ntype IsolatePayload = IsolateData & IsolateFeatures;\ntype IsolateFeatures = {\n [IsolateKeys.AllowReorder]?: boolean;\n [IsolateKeys.Status]?: string;\n};\n","import { CB, Nullable, isNullish, optionalFunctionValue } from 'vest-utils';\n\nimport { type TIsolate } from 'Isolate';\nimport { IsolateMutator } from 'IsolateMutator';\n\ntype VisitOnlyPredicate = (isolate: TIsolate) => boolean;\n\n// eslint-disable-next-line\nexport function walk(\n startNode: TIsolate,\n callback: (isolate: TIsolate, breakout: CB<void>) => void,\n visitOnly?: VisitOnlyPredicate\n): void {\n // If the startNode has no children, there is nothing to walk.\n if (isNullish(startNode.children)) {\n return;\n }\n\n let broke = false;\n\n // For each child Isolate object, call the callback function.\n for (const isolate of startNode.children) {\n if (broke) {\n return;\n }\n\n // If visitOnly is not provided or the predicate is satisfied, call the callback function.\n if (isNullish(visitOnly) || optionalFunctionValue(visitOnly, isolate)) {\n callback(isolate, breakout);\n }\n\n // If the breakout function has been called, stop the walk.\n if (broke) {\n return;\n }\n\n // Recursively walk through the child Isolate object.\n walk(\n isolate,\n (child, innerBreakout) => {\n callback(child, () => {\n innerBreakout();\n breakout();\n });\n },\n visitOnly\n );\n }\n\n function breakout() {\n broke = true;\n }\n}\n\n// This function returns true if the given predicate function returns true for any Isolate object in the tree.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function some(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): boolean {\n let hasMatch = false;\n\n // Call the walk function with a callback function that sets hasMatch to true if the predicate is satisfied.\n walk(\n startNode,\n (node, breakout) => {\n if (predicate(node)) {\n breakout();\n hasMatch = true;\n }\n },\n visitOnly\n );\n\n return hasMatch;\n}\n\n// This function returns true if the given predicate function returns true for any Isolate object in the tree.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function has(startNode: TIsolate, match: VisitOnlyPredicate): boolean {\n return some(startNode, () => true, match);\n}\n\n// traverses up to a parent node that satisfies the predicate\n// and returns the first direct descendant that satisfies the predicate\nexport function findClosest<I extends TIsolate = TIsolate>(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean\n): Nullable<I> {\n let found: Nullable<TIsolate> = null;\n let current: Nullable<TIsolate> = startNode;\n\n while (current) {\n found = current.children?.find(predicate) ?? null;\n\n if (found) {\n break;\n }\n\n current = current.parent;\n }\n\n return found as Nullable<I>;\n}\n\n// This function returns the first Isolate object in the tree that satisfies the given predicate function.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function find(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): Nullable<TIsolate> {\n let found = null;\n\n // Call the walk function with a callback function that sets found to the current node if the predicate is satisfied.\n walk(\n startNode,\n (node, breakout) => {\n if (predicate(node)) {\n breakout();\n found = node;\n }\n },\n visitOnly\n );\n\n return found;\n}\n\n// This function returns true if the given predicate function returns true for every Isolate object in the tree.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function every(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): boolean {\n let hasMatch = true;\n walk(\n startNode,\n (node, breakout) => {\n if (!predicate(node)) {\n breakout();\n hasMatch = false;\n }\n },\n visitOnly\n );\n\n return hasMatch;\n}\n\n// This function removes all Isolate objects in the tree that\n// satisfy the given predicate function and have a parent.\n// If visitOnly is provided, only Isolate objects that satisfy the predicate are visited.\nexport function pluck(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean,\n visitOnly?: VisitOnlyPredicate\n): void {\n walk(\n startNode,\n node => {\n if (predicate(node) && node.parent) {\n IsolateMutator.removeChild(node.parent, node);\n }\n },\n visitOnly\n );\n}\n\n// Returns the closest ancestor Isolate object of the given\n//startNode that satisfies the given predicate function.\nexport function closest(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean\n): Nullable<TIsolate> {\n let current: Nullable<TIsolate> = startNode;\n do {\n if (predicate(current)) {\n return current;\n }\n current = current.parent;\n } while (current);\n return null;\n}\n\n// This function returns true if the closest ancestor Isolates of the\n// given startNode that satisfies the given predicate function exists.\nexport function closestExists(\n startNode: TIsolate,\n predicate: (node: TIsolate) => boolean\n): boolean {\n return !!closest(startNode, predicate);\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Maybe,\n Nullable,\n assign,\n hasOwnProperty,\n invariant,\n isEmpty,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport {\n ExcludedFromDump,\n IsolateKeys,\n KeyToMinified,\n MinifiedKeys,\n MinifiedToKey,\n} from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity, max-lines-per-function\n static deserialize(\n node: Record<string, any> | TIsolate | string,\n miniMaps: Maybe<MiniMaps>\n ): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n const inverseMinimap = deeplyInvertKeyMap(miniMaps);\n\n // Validate the root object\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n // Iterate over the queue until it's empty\n while (queue.length) {\n // Get the next item from the queue\n const current = queue.shift();\n\n // Get the children of the current item\n const children = IsolateSerializer.expandChildren(current);\n\n // Iterate over the minified keys\n for (const key in MinifiedToKey) {\n // Get the value for the current key\n const value = current[key];\n\n // If the value is not null or undefined\n if (isNotNullish(value)) {\n // Get the key to use\n const keyToUse = MinifiedToKey[key];\n\n // If the key is data, then we may need to transform the keys\n // eslint-disable-next-line max-depth\n if (keyToUse === IsolateKeys.Data) {\n // Transform the keys\n current[keyToUse] = transformKeys(\n value,\n inverseMinimap?.keys?.data\n );\n } else {\n // Otherwise, just set the key\n current[keyToUse] = transformValueByKey(\n keyToUse,\n value,\n inverseMinimap\n );\n }\n\n // Remove the old key\n delete current[key];\n }\n }\n\n // If there are no children, nothing to do.\n if (!children) {\n continue;\n }\n\n // Copy the children and set their parent to the current node.\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n // If the child has a key, add it to the parent's keys.\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(\n isolate: Nullable<TIsolate>,\n miniMaps: Maybe<MiniMaps>\n ): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate, miniMaps));\n }\n\n static expandChildren(node: Record<string, any>): Nullable<TIsolate[]> {\n return node[MinifiedKeys.Children]\n ? [...node[MinifiedKeys.Children]]\n : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(\n isolate: TIsolate,\n miniMaps: Maybe<MiniMaps>\n): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next[MinifiedKeys.Children] = isolate.children.map(isolate =>\n transformIsolate(isolate, miniMaps)\n );\n }\n\n if (!isEmpty(isolate.data)) {\n next[MinifiedKeys.Data] = transformKeys(isolate.data, miniMaps?.keys?.data);\n }\n\n for (const key in isolate) {\n // Skip keys that should be excluded from the dump.\n // While we're excluding children from the dump, they'll actually remain there\n // due to the fact that we've already transformed them recursively beforehand\n // thus renaming them to the minified key.\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n const keyToUse = minifyKey(key);\n next[keyToUse] = transformValueByKey(key, value, miniMaps);\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return ExcludedFromDump.includes(key as IsolateKeys);\n}\n\nfunction minifyKey(key: string): string {\n return KeyToMinified[key as keyof typeof KeyToMinified] ?? key;\n}\n\nfunction transformValueByKey(\n key: string,\n value: any,\n miniMaps: Maybe<MiniMaps>\n): any {\n if (isNullish(value)) {\n return value;\n }\n\n const keyMap = miniMaps?.values?.[key as keyof MiniMaps['values']];\n\n return keyMap ? keyMap[value] ?? value : value;\n}\n\nfunction transformKeys(\n data: Record<string, any>,\n keyMap: Maybe<MiniMap>\n): Record<string, any> {\n const next: Record<string, any> = {};\n\n // Loop over each key in the data.\n for (const key in data) {\n // Find the key to use for the next object.\n // If there is no key map, use the original key.\n // If there is a key map, use the key map entry for the current key.\n const keyToUse = (keyMap ? keyMap[key] : key) ?? key;\n\n // Add the key and value to the next object.\n next[keyToUse] = data[key];\n }\n\n // Return the next object.\n return next;\n}\n\ntype MiniMap = Record<string, string>;\n\ntype MiniMaps = Partial<{\n keys: Partial<{\n [IsolateKeys.Data]: MiniMap;\n }>;\n values: Partial<{\n [IsolateKeys.Status]: MiniMap;\n [IsolateKeys.Type]: MiniMap;\n }>;\n}>;\n\nexport function deeplyInvertKeyMap(miniMaps: Maybe<MiniMaps> = {}): MiniMaps {\n return Object.entries(miniMaps).reduce((acc, [key, value]) => {\n if (typeof value === 'object') {\n return assign(acc, {\n [key]: deeplyInvertKeyMap(value as MiniMaps),\n });\n }\n return assign(acc, {\n [value]: key,\n });\n }, {} as MiniMaps);\n}\n"],"names":["RuntimeEvents","ISOLATE_ENTER","ISOLATE_PENDING","ISOLATE_DONE","ErrorStrings","IsolateInspector","static","isolate","at","isNullish","_b","_a","children","length","allowsReorder","parent","allowReorder","isNotNullish","key","keys","IsolateMutator","output","child","invariant","push","setParent","node","filter","data","reason","abortController","abort","PersistedContext","createCascade","stateRef","parentContext","historyRoot","historyRootNode","ctxRef","assign","historyNode","runtimeNode","runtimeRoot","Run","run","RuntimeApi","addNodeToHistory","createRef","Reconciler","setter","Object","freeze","Bus","bus","createBus","appData","optionalFunctionValue","tinyState","createTinyState","persist","reset","resetHistoryRoot","useHistoryRoot","useAvailableRoot","root","useRuntimeRoot","useCurrentCursor","useIsolate","cursor","useLoadRootNode","useSetHistory","useXAppData","useX","cb","prev","args","ctxToUse","use","useHistoryIsolate","useHistoryIsolateAtCurrentPosition","currentIsolate","NO_ACTIVE_ISOLATE","addChild","useSetNextIsolateChild","history","setHistoryRoot","useBus","useEmit","event","emit","IsolateKeys","MinifiedKeys","arg","KeyToMinified","Type","Keys","Parent","Data","Key","AllowReorder","Status","Children","MinifiedToKey","miniMap","entries","reduce","acc","minified","invertKeyMap","ExcludedFromDump","AbortController","isIsolateType","type","isSameIsolateType","a","b","is","nextNodeResult","currentNode","newNode","usesKey","handleIsolateNodeWithKey","handleNoHistoryNode","reconciler","BaseReconciler","pickNextNode","VestRuntime.useHistoryIsolateAtCurrentPosition","UNABLE_TO_PICK_NEXT_ISOLATE","reorderLogic","prevNode","didReorder","VestRuntime.useIsolate","VestRuntime.useHistoryIsolate","slice","removeAllNextNodesInIsolate","prevNodeByKey","getChildByKey","VestRuntime.useHistoryKey","nextNode","addChildKey","deferThrow","text","ENCOUNTERED_THE_SAME_KEY_TWICE","VestRuntime.useSetIsolateKey","Isolate","callback","payload","newCreatedNode","status","__rest","baseIsolate","nextIsolateChild","reconcile","localHistoryNode","current","VestRuntime.useRuntimeRoot","VestRuntime.Run","isPromise","then","iso","isIsolate","useRunAsNew","saveOutput","VestRuntime.addNodeToHistory","walk","startNode","visitOnly","broke","breakout","innerBreakout","some","predicate","hasMatch","closest","found","find","match","removeChild","IsolateSerializer","miniMaps","inverseMinimap","deeplyInvertKeyMap","isStringValue","JSON","parse","validateIsolate","queue","shift","expandChildren","value","keyToUse","transformKeys","transformValueByKey","map","nextChild","stringify","transformIsolate","hasOwnProperty","INVALID_ISOLATE_CANNOT_PARSE","next","isEmpty","isKeyExcluededFromDump","minifyKey","includes","keyMap","values"],"mappings":"kFAAa,MAAAA,EAAgB,CAC3BC,cAAe,gBACfC,gBAAiB,kBACjBC,aAAc,gBCHhB,IAAYC,sDAAZ,SAAYA,GACVA,EAAA,kBAAA,+BACAA,EAAA,4BAAA,wFACAA,EAAA,+BAAA,kGACAA,EAAA,6BAAA,kEACD,CALD,CAAYA,IAAAA,EAKX,CAAA,UCDYC,EACXC,UAAUC,EAA6BC,WACrC,OAAIC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L,SACjB,OAAuD,UAAhD2E,EAAc3E,UAAkC,IAAAP,EAAAA,EAAIO,CAC7D,CAEA,SAAS8K,EACP9K,EACA2K,EACAV,WAEA,GAAI1K,EAAAA,UAAUoL,GACZ,OAAOA,EAGT,MAAMe,EAA4B,QAAnBjM,EAAAwK,aAAA,EAAAA,EAAU0B,cAAS,IAAAlM,OAAA,EAAAA,EAAAO,GAElC,OAAO0L,aAASA,EAAOf,kBAAkBA,CAC3C,CAEA,SAASE,EACPnK,EACAgL,SAEA,MAAML,EAA4B,CAAA,EAGlC,IAAK,MAAMrL,KAAOU,EAAM,CAOtB2K,EAH6C,QAA5B5L,EAACiM,EAASA,EAAO1L,GAAOA,SAAI,IAAAP,EAAAA,EAAIO,GAGhCU,EAAKV,EACvB,CAGD,OAAOqL,CACT,CAcgB,SAAAlB,EAAmBF,EAA4B,IAC7D,OAAOjI,OAAOsD,QAAQ2E,GAAU1E,QAAO,CAACC,GAAMxF,EAAK2K,KAC5B,iBAAVA,EACFtJ,EAAAA,OAAOmE,EAAK,CACjBxF,CAACA,GAAMmK,EAAmBQ,KAGvBtJ,EAAAA,OAAOmE,EAAK,CACjBmF,CAACA,GAAQ3K,KAEV,CAAc,EACnB"}
@@ -1,4 +1,5 @@
1
- import { invariant, isNullish, isStringValue, isNotNullish, hasOwnProperty, text } from 'vest-utils';
1
+ import { invariant, isNullish, isStringValue, isNotNullish, hasOwnProperty, text, isEmpty, assign as assign$1 } from 'vest-utils';
2
+ import { assign } from 'lodash';
2
3
 
3
4
  var ErrorStrings;
4
5
  (function (ErrorStrings) {
@@ -17,16 +18,19 @@ var IsolateKeys;
17
18
  IsolateKeys["Data"] = "data";
18
19
  IsolateKeys["AllowReorder"] = "allowReorder";
19
20
  IsolateKeys["Status"] = "status";
21
+ IsolateKeys["AbortController"] = "abortController";
22
+ IsolateKeys["Children"] = "children";
20
23
  })(IsolateKeys || (IsolateKeys = {}));
21
24
  var MinifiedKeys;
22
25
  (function (MinifiedKeys) {
23
26
  MinifiedKeys["Type"] = "$";
24
- MinifiedKeys["Keys"] = "K";
25
- MinifiedKeys["Key"] = "k";
27
+ MinifiedKeys["Keys"] = "Ks";
28
+ MinifiedKeys["Key"] = "ky";
26
29
  MinifiedKeys["Parent"] = "P";
27
30
  MinifiedKeys["Data"] = "D";
28
- MinifiedKeys["AllowReorder"] = "aR";
31
+ MinifiedKeys["AllowReorder"] = "AR";
29
32
  MinifiedKeys["Status"] = "S";
33
+ MinifiedKeys["Children"] = "C";
30
34
  })(MinifiedKeys || (MinifiedKeys = {}));
31
35
  const KeyToMinified = {
32
36
  [IsolateKeys.Type]: MinifiedKeys.Type,
@@ -36,6 +40,7 @@ const KeyToMinified = {
36
40
  [IsolateKeys.Key]: MinifiedKeys.Key,
37
41
  [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
38
42
  [IsolateKeys.Status]: MinifiedKeys.Status,
43
+ [IsolateKeys.Children]: MinifiedKeys.Children,
39
44
  };
40
45
  // This const is an object that looks like this:
41
46
  // {
@@ -44,9 +49,19 @@ const KeyToMinified = {
44
49
  // 'P': 'parent',
45
50
  // ...
46
51
  // }
47
- const MinifiedToKey = Object.entries(KeyToMinified).reduce((acc, [key, minified]) => Object.assign(acc, {
48
- [minified]: key,
49
- }), {});
52
+ const MinifiedToKey = invertKeyMap(KeyToMinified);
53
+ function invertKeyMap(miniMap = {}) {
54
+ return Object.entries(miniMap).reduce((acc, [key, minified]) => assign(acc, {
55
+ [minified]: key,
56
+ }), {});
57
+ }
58
+ const ExcludedFromDump = [
59
+ IsolateKeys.AbortController,
60
+ IsolateKeys.Parent,
61
+ IsolateKeys.Keys,
62
+ IsolateKeys.Children,
63
+ IsolateKeys.Data,
64
+ ];
50
65
 
51
66
  class IsolateMutator {
52
67
  static setParent(isolate, parent) {
@@ -88,11 +103,18 @@ class IsolateMutator {
88
103
  static setData(isolate, data) {
89
104
  isolate.data = data;
90
105
  }
106
+ static abort(isolate, reason) {
107
+ if (isNullish(isolate.abortController)) {
108
+ return;
109
+ }
110
+ isolate.abortController.abort(reason);
111
+ }
91
112
  }
92
113
 
93
114
  class IsolateSerializer {
94
- // eslint-disable-next-line max-statements, complexity
95
- static deserialize(node) {
115
+ // eslint-disable-next-line max-statements, complexity, max-lines-per-function
116
+ static deserialize(node, miniMaps) {
117
+ var _a;
96
118
  // the assumption is that the tree is built correctly,
97
119
  // but the children are missing the parent property to
98
120
  // avoid circular references during serialization.
@@ -100,29 +122,52 @@ class IsolateSerializer {
100
122
  // to avoid circular references during serialization.
101
123
  // we need to rebuild the tree and add back the parent property to the children
102
124
  // and the keys property to the parents.
125
+ const inverseMinimap = deeplyInvertKeyMap(miniMaps);
126
+ // Validate the root object
103
127
  const root = isStringValue(node)
104
128
  ? JSON.parse(node)
105
129
  : Object.assign({}, node);
106
130
  IsolateSerializer.validateIsolate(root);
107
131
  const queue = [root];
132
+ // Iterate over the queue until it's empty
108
133
  while (queue.length) {
134
+ // Get the next item from the queue
109
135
  const current = queue.shift();
110
- const children = IsolateSerializer.getChildren(current);
136
+ // Get the children of the current item
137
+ const children = IsolateSerializer.expandChildren(current);
138
+ // Iterate over the minified keys
111
139
  for (const key in MinifiedToKey) {
140
+ // Get the value for the current key
112
141
  const value = current[key];
142
+ // If the value is not null or undefined
113
143
  if (isNotNullish(value)) {
114
- current[MinifiedToKey[key]] = value;
144
+ // Get the key to use
145
+ const keyToUse = MinifiedToKey[key];
146
+ // If the key is data, then we may need to transform the keys
147
+ // eslint-disable-next-line max-depth
148
+ if (keyToUse === IsolateKeys.Data) {
149
+ // Transform the keys
150
+ current[keyToUse] = transformKeys(value, (_a = inverseMinimap === null || inverseMinimap === void 0 ? void 0 : inverseMinimap.keys) === null || _a === void 0 ? void 0 : _a.data);
151
+ }
152
+ else {
153
+ // Otherwise, just set the key
154
+ current[keyToUse] = transformValueByKey(keyToUse, value, inverseMinimap);
155
+ }
156
+ // Remove the old key
115
157
  delete current[key];
116
158
  }
117
159
  }
160
+ // If there are no children, nothing to do.
118
161
  if (!children) {
119
162
  continue;
120
163
  }
164
+ // Copy the children and set their parent to the current node.
121
165
  current.children = children.map(child => {
122
166
  var _a;
123
167
  const nextChild = Object.assign({}, child);
124
168
  IsolateMutator.setParent(nextChild, current);
125
169
  queue.push(nextChild);
170
+ // If the child has a key, add it to the parent's keys.
126
171
  const key = nextChild.key;
127
172
  if (key) {
128
173
  current.keys = (_a = current.keys) !== null && _a !== void 0 ? _a : {};
@@ -133,14 +178,16 @@ class IsolateSerializer {
133
178
  }
134
179
  return root;
135
180
  }
136
- static serialize(isolate) {
181
+ static serialize(isolate, miniMaps) {
137
182
  if (isNullish(isolate)) {
138
183
  return '';
139
184
  }
140
- return JSON.stringify(transformIsolate(isolate));
185
+ return JSON.stringify(transformIsolate(isolate, miniMaps));
141
186
  }
142
- static getChildren(node) {
143
- return node.children ? [...node.children] : null;
187
+ static expandChildren(node) {
188
+ return node[MinifiedKeys.Children]
189
+ ? [...node[MinifiedKeys.Children]]
190
+ : null;
144
191
  }
145
192
  static validateIsolate(node) {
146
193
  invariant(hasOwnProperty(node, IsolateKeys.Type) ||
@@ -148,15 +195,20 @@ class IsolateSerializer {
148
195
  }
149
196
  }
150
197
  // eslint-disable-next-line max-statements, complexity
151
- function transformIsolate(isolate) {
198
+ function transformIsolate(isolate, miniMaps) {
199
+ var _a;
152
200
  const next = {};
153
201
  if (isolate.children) {
154
- next.children = isolate.children.map(transformIsolate);
202
+ next[MinifiedKeys.Children] = isolate.children.map(isolate => transformIsolate(isolate, miniMaps));
203
+ }
204
+ if (!isEmpty(isolate.data)) {
205
+ next[MinifiedKeys.Data] = transformKeys(isolate.data, (_a = miniMaps === null || miniMaps === void 0 ? void 0 : miniMaps.keys) === null || _a === void 0 ? void 0 : _a.data);
155
206
  }
156
207
  for (const key in isolate) {
157
- if (key === 'children') {
158
- continue;
159
- }
208
+ // Skip keys that should be excluded from the dump.
209
+ // While we're excluding children from the dump, they'll actually remain there
210
+ // due to the fact that we've already transformed them recursively beforehand
211
+ // thus renaming them to the minified key.
160
212
  if (isKeyExcluededFromDump(key)) {
161
213
  continue;
162
214
  }
@@ -164,18 +216,53 @@ function transformIsolate(isolate) {
164
216
  if (isNullish(value)) {
165
217
  continue;
166
218
  }
167
- if (hasOwnProperty(KeyToMinified, key)) {
168
- next[KeyToMinified[key]] = value;
169
- }
170
- else {
171
- next[key] = value;
172
- }
219
+ const keyToUse = minifyKey(key);
220
+ next[keyToUse] = transformValueByKey(key, value, miniMaps);
173
221
  }
174
222
  return next;
175
223
  }
176
224
  function isKeyExcluededFromDump(key) {
177
- return [IsolateKeys.Parent, IsolateKeys.Keys].includes(key);
225
+ return ExcludedFromDump.includes(key);
226
+ }
227
+ function minifyKey(key) {
228
+ var _a;
229
+ return (_a = KeyToMinified[key]) !== null && _a !== void 0 ? _a : key;
230
+ }
231
+ function transformValueByKey(key, value, miniMaps) {
232
+ var _a, _b;
233
+ if (isNullish(value)) {
234
+ return value;
235
+ }
236
+ const keyMap = (_a = miniMaps === null || miniMaps === void 0 ? void 0 : miniMaps.values) === null || _a === void 0 ? void 0 : _a[key];
237
+ return keyMap ? (_b = keyMap[value]) !== null && _b !== void 0 ? _b : value : value;
238
+ }
239
+ function transformKeys(data, keyMap) {
240
+ var _a;
241
+ const next = {};
242
+ // Loop over each key in the data.
243
+ for (const key in data) {
244
+ // Find the key to use for the next object.
245
+ // If there is no key map, use the original key.
246
+ // If there is a key map, use the key map entry for the current key.
247
+ const keyToUse = (_a = (keyMap ? keyMap[key] : key)) !== null && _a !== void 0 ? _a : key;
248
+ // Add the key and value to the next object.
249
+ next[keyToUse] = data[key];
250
+ }
251
+ // Return the next object.
252
+ return next;
253
+ }
254
+ function deeplyInvertKeyMap(miniMaps = {}) {
255
+ return Object.entries(miniMaps).reduce((acc, [key, value]) => {
256
+ if (typeof value === 'object') {
257
+ return assign$1(acc, {
258
+ [key]: deeplyInvertKeyMap(value),
259
+ });
260
+ }
261
+ return assign$1(acc, {
262
+ [value]: key,
263
+ });
264
+ }, {});
178
265
  }
179
266
 
180
- export { IsolateSerializer };
267
+ export { IsolateSerializer, deeplyInvertKeyMap };
181
268
  //# sourceMappingURL=IsolateSerializer.development.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IsolateSerializer.development.js","sources":["../../src/errors/ErrorStrings.ts","../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateMutator.ts","../../src/exports/IsolateSerializer.ts"],"sourcesContent":["export enum ErrorStrings {\n NO_ACTIVE_ISOLATE = 'Not within an active isolate',\n UNABLE_TO_PICK_NEXT_ISOLATE = 'Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.',\n ENCOUNTERED_THE_SAME_KEY_TWICE = `Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.`,\n INVALID_ISOLATE_CANNOT_PARSE = `Invalid isolate was passed to IsolateSerializer. Cannot proceed.`,\n}\n","export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\n Status = 'S',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateMutator {\n static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {\n isolate.parent = parent;\n return isolate;\n }\n\n static saveOutput(isolate: TIsolate, output: any): TIsolate {\n isolate.output = output;\n return isolate;\n }\n\n static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {\n isolate.key = key;\n return isolate;\n }\n\n static addChild(isolate: TIsolate, child: TIsolate): void {\n invariant(isolate);\n\n isolate.children = isolate.children ?? [];\n\n isolate.children.push(child);\n IsolateMutator.setParent(child, isolate);\n }\n\n static removeChild(isolate: TIsolate, node: TIsolate): void {\n isolate.children =\n isolate.children?.filter(child => child !== node) ?? null;\n }\n\n static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {\n invariant(isolate);\n\n isolate.keys = isolate.keys ?? {};\n\n isolate.keys[key] = node;\n }\n\n static slice(isolate: TIsolate, at: number): void {\n if (isNullish(isolate.children)) {\n return;\n }\n isolate.children.length = at;\n }\n\n static setData(isolate: TIsolate, data: any): void {\n isolate.data = data;\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Nullable,\n hasOwnProperty,\n invariant,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys, KeyToMinified, MinifiedToKey } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity\n static deserialize(node: Record<string, any> | TIsolate | string): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n while (queue.length) {\n const current = queue.shift();\n\n const children = IsolateSerializer.getChildren(current);\n\n for (const key in MinifiedToKey) {\n const value = current[key];\n if (isNotNullish(value)) {\n current[MinifiedToKey[key]] = value;\n delete current[key];\n }\n }\n\n if (!children) {\n continue;\n }\n\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(isolate: Nullable<TIsolate>): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate));\n }\n\n static getChildren(node: TIsolate): Nullable<TIsolate[]> {\n return node.children ? [...node.children] : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(isolate: TIsolate): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next.children = isolate.children.map(transformIsolate);\n }\n\n for (const key in isolate) {\n if (key === 'children') {\n continue;\n }\n\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n if (hasOwnProperty(KeyToMinified, key)) {\n next[KeyToMinified[key]] = value;\n } else {\n next[key] = value;\n }\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return [IsolateKeys.Parent, IsolateKeys.Keys].includes(key as IsolateKeys);\n}\n"],"names":[],"mappings":";;AAAA,IAAY,YAKX,CAAA;AALD,CAAA,UAAY,YAAY,EAAA;AACtB,IAAA,YAAA,CAAA,mBAAA,CAAA,GAAA,8BAAkD,CAAA;AAClD,IAAA,YAAA,CA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O,EAAE;QACzB,IAAI,GAAG,KAAK,UAAU,EAAE;YACtB,SAAS;AACV,SAAA;AAED,QAAA,IAAI,sBAAsB,CAAC,GAAG,CAAC,EAAE;YAC/B,SAAS;AACV,SAAA;AACD,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,GAAqB,CAAC,CAAC;AAE7C,QAAA,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;YACpB,SAAS;AACV,SAAA;AAED,QAAA,IAAI,cAAc,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE;YACtC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AAClC,SAAA;AAAM,aAAA;AACL,YAAA,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACnB,SAAA;AACF,KAAA;AAED,IAAA,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAW,EAAA;AACzC,IAAA,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;AAC7E;;;;"}
1
+ {"version":3,"file":"IsolateSerializer.development.js","sources":["../../src/errors/ErrorStrings.ts","../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateMutator.ts","../../src/exports/IsolateSerializer.ts"],"sourcesContent":["export enum ErrorStrings {\n NO_ACTIVE_ISOLATE = 'Not within an active isolate',\n UNABLE_TO_PICK_NEXT_ISOLATE = 'Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.',\n ENCOUNTERED_THE_SAME_KEY_TWICE = `Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.`,\n INVALID_ISOLATE_CANNOT_PARSE = `Invalid isolate was passed to IsolateSerializer. Cannot proceed.`,\n}\n","import { assign } from 'lodash';\n\nexport enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n AbortController = 'abortController',\n Children = 'children',\n}\n\nexport enum MinifiedKeys {\n Type = '$',\n Keys = 'Ks',\n Key = 'ky',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'AR',\n Status = 'S',\n Children = 'C',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n [IsolateKeys.Children]: MinifiedKeys.Children,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = invertKeyMap(KeyToMinified);\n\nexport function invertKeyMap(miniMap: Record<string, string> = {}) {\n return Object.entries(miniMap).reduce(\n (acc, [key, minified]) =>\n assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, string>\n );\n}\n\nexport const ExcludedFromDump = [\n IsolateKeys.AbortController,\n IsolateKeys.Parent,\n IsolateKeys.Keys,\n IsolateKeys.Children,\n IsolateKeys.Data,\n];\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateMutator {\n static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {\n isolate.parent = parent;\n return isolate;\n }\n\n static saveOutput(isolate: TIsolate, output: any): TIsolate {\n isolate.output = output;\n return isolate;\n }\n\n static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {\n isolate.key = key;\n return isolate;\n }\n\n static addChild(isolate: TIsolate, child: TIsolate): void {\n invariant(isolate);\n\n isolate.children = isolate.children ?? [];\n\n isolate.children.push(child);\n IsolateMutator.setParent(child, isolate);\n }\n\n static removeChild(isolate: TIsolate, node: TIsolate): void {\n isolate.children =\n isolate.children?.filter(child => child !== node) ?? null;\n }\n\n static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {\n invariant(isolate);\n\n isolate.keys = isolate.keys ?? {};\n\n isolate.keys[key] = node;\n }\n\n static slice(isolate: TIsolate, at: number): void {\n if (isNullish(isolate.children)) {\n return;\n }\n isolate.children.length = at;\n }\n\n static setData(isolate: TIsolate, data: any): void {\n isolate.data = data;\n }\n\n static abort(isolate: TIsolate, reason?: string): void {\n if (isNullish(isolate.abortController)) {\n return;\n }\n isolate.abortController.abort(reason);\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Maybe,\n Nullable,\n assign,\n hasOwnProperty,\n invariant,\n isEmpty,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport {\n ExcludedFromDump,\n IsolateKeys,\n KeyToMinified,\n MinifiedKeys,\n MinifiedToKey,\n} from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity, max-lines-per-function\n static deserialize(\n node: Record<string, any> | TIsolate | string,\n miniMaps: Maybe<MiniMaps>\n ): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n const inverseMinimap = deeplyInvertKeyMap(miniMaps);\n\n // Validate the root object\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n // Iterate over the queue until it's empty\n while (queue.length) {\n // Get the next item from the queue\n const current = queue.shift();\n\n // Get the children of the current item\n const children = IsolateSerializer.expandChildren(current);\n\n // Iterate over the minified keys\n for (const key in MinifiedToKey) {\n // Get the value for the current key\n const value = current[key];\n\n // If the value is not null or undefined\n if (isNotNullish(value)) {\n // Get the key to use\n const keyToUse = MinifiedToKey[key];\n\n // If the key is data, then we may need to transform the keys\n // eslint-disable-next-line max-depth\n if (keyToUse === IsolateKeys.Data) {\n // Transform the keys\n current[keyToUse] = transformKeys(\n value,\n inverseMinimap?.keys?.data\n );\n } else {\n // Otherwise, just set the key\n current[keyToUse] = transformValueByKey(\n keyToUse,\n value,\n inverseMinimap\n );\n }\n\n // Remove the old key\n delete current[key];\n }\n }\n\n // If there are no children, nothing to do.\n if (!children) {\n continue;\n }\n\n // Copy the children and set their parent to the current node.\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n // If the child has a key, add it to the parent's keys.\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(\n isolate: Nullable<TIsolate>,\n miniMaps: Maybe<MiniMaps>\n ): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate, miniMaps));\n }\n\n static expandChildren(node: Record<string, any>): Nullable<TIsolate[]> {\n return node[MinifiedKeys.Children]\n ? [...node[MinifiedKeys.Children]]\n : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(\n isolate: TIsolate,\n miniMaps: Maybe<MiniMaps>\n): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next[MinifiedKeys.Children] = isolate.children.map(isolate =>\n transformIsolate(isolate, miniMaps)\n );\n }\n\n if (!isEmpty(isolate.data)) {\n next[MinifiedKeys.Data] = transformKeys(isolate.data, miniMaps?.keys?.data);\n }\n\n for (const key in isolate) {\n // Skip keys that should be excluded from the dump.\n // While we're excluding children from the dump, they'll actually remain there\n // due to the fact that we've already transformed them recursively beforehand\n // thus renaming them to the minified key.\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n const keyToUse = minifyKey(key);\n next[keyToUse] = transformValueByKey(key, value, miniMaps);\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return ExcludedFromDump.includes(key as IsolateKeys);\n}\n\nfunction minifyKey(key: string): string {\n return KeyToMinified[key as keyof typeof KeyToMinified] ?? key;\n}\n\nfunction transformValueByKey(\n key: string,\n value: any,\n miniMaps: Maybe<MiniMaps>\n): any {\n if (isNullish(value)) {\n return value;\n }\n\n const keyMap = miniMaps?.values?.[key as keyof MiniMaps['values']];\n\n return keyMap ? keyMap[value] ?? value : value;\n}\n\nfunction transformKeys(\n data: Record<string, any>,\n keyMap: Maybe<MiniMap>\n): Record<string, any> {\n const next: Record<string, any> = {};\n\n // Loop over each key in the data.\n for (const key in data) {\n // Find the key to use for the next object.\n // If there is no key map, use the original key.\n // If there is a key map, use the key map entry for the current key.\n const keyToUse = (keyMap ? keyMap[key] : key) ?? key;\n\n // Add the key and value to the next object.\n next[keyToUse] = data[key];\n }\n\n // Return the next object.\n return next;\n}\n\ntype MiniMap = Record<string, string>;\n\ntype MiniMaps = Partial<{\n keys: Partial<{\n [IsolateKeys.Data]: MiniMap;\n }>;\n values: Partial<{\n [IsolateKeys.Status]: MiniMap;\n [IsolateKeys.Type]: MiniMap;\n }>;\n}>;\n\nexport function deeplyInvertKeyMap(miniMaps: Maybe<MiniMaps> = {}): MiniMaps {\n return Object.entries(miniMaps).reduce((acc, [key, value]) => {\n if (typeof value === 'object') {\n return assign(acc, {\n [key]: deeplyInvertKeyMap(value as MiniMaps),\n });\n }\n return assign(acc, {\n [value]: key,\n });\n }, {} as MiniMaps);\n}\n"],"names":["assign"],"mappings":";;;A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AAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;AAC3D,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAOA,QAAM,CAAC,GAAG,EAAE;AACjB,gBAAA,CAAC,GAAG,GAAG,kBAAkB,CAAC,KAAiB,CAAC;AAC7C,aAAA,CAAC,CAAC;AACJ,SAAA;QACD,OAAOA,QAAM,CAAC,GAAG,EAAE;YACjB,CAAC,KAAK,GAAG,GAAG;AACb,SAAA,CAAC,CAAC;KACJ,EAAE,EAAc,CAAC,CAAC;AACrB;;;;"}
@@ -1,2 +1,2 @@
1
- import{invariant as e,isNullish as t,isStringValue as n,isNotNullish as s,hasOwnProperty as i,text as a}from"vest-utils";var r,l,o;!function(e){e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.UNABLE_TO_PICK_NEXT_ISOLATE="Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.",e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same key "{key}" twice. This may lead to inconsistent or overriding of results.',e.INVALID_ISOLATE_CANNOT_PARSE="Invalid isolate was passed to IsolateSerializer. Cannot proceed."}(r||(r={})),function(e){e.Type="$type",e.Keys="keys",e.Key="key",e.Parent="parent",e.Data="data",e.AllowReorder="allowReorder",e.Status="status"}(l||(l={})),function(e){e.Type="$",e.Keys="K",e.Key="k",e.Parent="P",e.Data="D",e.AllowReorder="aR",e.Status="S"}(o||(o={}));const c={[l.Type]:o.Type,[l.Keys]:o.Keys,[l.Parent]:o.Parent,[l.Data]:o.Data,[l.Key]:o.Key,[l.AllowReorder]:o.AllowReorder,[l.Status]:o.Status},d=Object.entries(c).reduce(((e,[t,n])=>Object.assign(e,{[n]:t})),{});class u{static setParent(e,t){return e.parent=t,e}static saveOutput(e,t){return e.output=t,e}static setKey(e,t){return e.key=t,e}static addChild(t,n){var s;e(t),t.children=null!==(s=t.children)&&void 0!==s?s:[],t.children.push(n),u.setParent(n,t)}static removeChild(e,t){var n,s;e.children=null!==(s=null===(n=e.children)||void 0===n?void 0:n.filter((e=>e!==t)))&&void 0!==s?s:null}static addChildKey(t,n,s){var i;e(t),t.keys=null!==(i=t.keys)&&void 0!==i?i:{},t.keys[n]=s}static slice(e,n){t(e.children)||(e.children.length=n)}static setData(e,t){e.data=t}}class y{static deserialize(e){const t=n(e)?JSON.parse(e):Object.assign({},e);y.validateIsolate(t);const i=[t];for(;i.length;){const e=i.shift(),t=y.getChildren(e);for(const t in d){const n=e[t];s(n)&&(e[d[t]]=n,delete e[t])}t&&(e.children=t.map((t=>{var n;const s=Object.assign({},t);u.setParent(s,e),i.push(s);const a=s.key;return a&&(e.keys=null!==(n=e.keys)&&void 0!==n?n:{},e.keys[a]=s),s})))}return t}static serialize(e){return t(e)?"":JSON.stringify(h(e))}static getChildren(e){return e.children?[...e.children]:null}static validateIsolate(t){e(i(t,l.Type)||i(t,c[l.Type]),a(r.INVALID_ISOLATE_CANNOT_PARSE))}}function h(e){const n={};e.children&&(n.children=e.children.map(h));for(const s in e){if("children"===s)continue;if(p(s))continue;const a=e[s];t(a)||(i(c,s)?n[c[s]]=a:n[s]=a)}return n}function p(e){return[l.Parent,l.Keys].includes(e)}export{y as IsolateSerializer};
1
+ import{invariant as t,isNullish as e,isStringValue as n,isNotNullish as r,hasOwnProperty as a,text as i,isEmpty as o,assign as l}from"vest-utils";import{assign as s}from"lodash";var d,c,u;!function(t){t.NO_ACTIVE_ISOLATE="Not within an active isolate",t.UNABLE_TO_PICK_NEXT_ISOLATE="Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.",t.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same key "{key}" twice. This may lead to inconsistent or overriding of results.',t.INVALID_ISOLATE_CANNOT_PARSE="Invalid isolate was passed to IsolateSerializer. Cannot proceed."}(d||(d={})),function(t){t.Type="$type",t.Keys="keys",t.Key="key",t.Parent="parent",t.Data="data",t.AllowReorder="allowReorder",t.Status="status",t.AbortController="abortController",t.Children="children"}(c||(c={})),function(t){t.Type="$",t.Keys="Ks",t.Key="ky",t.Parent="P",t.Data="D",t.AllowReorder="AR",t.Status="S",t.Children="C"}(u||(u={}));const v={[c.Type]:u.Type,[c.Keys]:u.Keys,[c.Parent]:u.Parent,[c.Data]:u.Data,[c.Key]:u.Key,[c.AllowReorder]:u.AllowReorder,[c.Status]:u.Status,[c.Children]:u.Children},y=function(t={}){return Object.entries(t).reduce(((t,[e,n])=>s(t,{[n]:e})),{})}(v);const h=[c.AbortController,c.Parent,c.Keys,c.Children,c.Data];class p{static setParent(t,e){return t.parent=e,t}static saveOutput(t,e){return t.output=e,t}static setKey(t,e){return t.key=e,t}static addChild(e,n){var r;t(e),e.children=null!==(r=e.children)&&void 0!==r?r:[],e.children.push(n),p.setParent(n,e)}static removeChild(t,e){var n,r;t.children=null!==(r=null===(n=t.children)||void 0===n?void 0:n.filter((t=>t!==e)))&&void 0!==r?r:null}static addChildKey(e,n,r){var a;t(e),e.keys=null!==(a=e.keys)&&void 0!==a?a:{},e.keys[n]=r}static slice(t,n){e(t.children)||(t.children.length=n)}static setData(t,e){t.data=e}static abort(t,n){e(t.abortController)||t.abortController.abort(n)}}class C{static deserialize(t,e){var a;const i=O(e),o=n(t)?JSON.parse(t):Object.assign({},t);C.validateIsolate(o);const l=[o];for(;l.length;){const t=l.shift(),e=C.expandChildren(t);for(const e in y){const n=t[e];if(r(n)){const r=y[e];r===c.Data?t[r]=k(n,null===(a=null==i?void 0:i.keys)||void 0===a?void 0:a.data):t[r]=E(r,n,i),delete t[e]}}e&&(t.children=e.map((e=>{var n;const r=Object.assign({},e);p.setParent(r,t),l.push(r);const a=r.key;return a&&(t.keys=null!==(n=t.keys)&&void 0!==n?n:{},t.keys[a]=r),r})))}return o}static serialize(t,n){return e(t)?"":JSON.stringify(f(t,n))}static expandChildren(t){return t[u.Children]?[...t[u.Children]]:null}static validateIsolate(e){t(a(e,c.Type)||a(e,v[c.Type]),i(d.INVALID_ISOLATE_CANNOT_PARSE))}}function f(t,n){var r;const a={};t.children&&(a[u.Children]=t.children.map((t=>f(t,n)))),o(t.data)||(a[u.Data]=k(t.data,null===(r=null==n?void 0:n.keys)||void 0===r?void 0:r.data));for(const r in t){if(A(r))continue;const i=t[r];if(e(i))continue;a[T(r)]=E(r,i,n)}return a}function A(t){return h.includes(t)}function T(t){var e;return null!==(e=v[t])&&void 0!==e?e:t}function E(t,n,r){var a,i;if(e(n))return n;const o=null===(a=null==r?void 0:r.values)||void 0===a?void 0:a[t];return o&&null!==(i=o[n])&&void 0!==i?i:n}function k(t,e){var n;const r={};for(const a in t){r[null!==(n=e?e[a]:a)&&void 0!==n?n:a]=t[a]}return r}function O(t={}){return Object.entries(t).reduce(((t,[e,n])=>l(t,"object"==typeof n?{[e]:O(n)}:{[n]:e})),{})}export{C as IsolateSerializer,O as deeplyInvertKeyMap};
2
2
  //# sourceMappingURL=IsolateSerializer.production.js.map