vestjs-runtime 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/cjs/IsolateSerializer.development.js +100 -25
  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 +16 -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 +99 -25
  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 +101 -27
  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 +16 -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 +100 -26
  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 +100 -25
  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 +18 -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 +99 -25
  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 +19 -7
  39. package/types/IsolateSerializer.d.ts.map +1 -1
  40. package/types/test-utils.d.ts +2 -1
  41. package/types/test-utils.d.ts.map +1 -1
  42. package/types/vestjs-runtime.d.ts +41 -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 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","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 AbortController = 'abortController',\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\nexport const ExcludedFromDump = [\n IsolateKeys.AbortController,\n IsolateKeys.Parent,\n IsolateKeys.Keys,\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 Nullable,\n hasOwnProperty,\n invariant,\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 MinifiedToKey,\n} 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 ExcludedFromDump.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","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","MinifiedToKey","entries","reduce","acc","minified","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","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,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L,EAAQK,WACVkL,EAAKlL,SAAWL,EAAQK,SAAS4K,IAAIG,IAGvC,IAAK,MAAMzK,KAAOX,EAAS,CACzB,GAAY,aAARW,EACF,SAGF,GAAI6K,EAAuB7K,GACzB,SAEF,MAAMqK,EAAQhL,EAAQW,GAElBT,EAAAA,UAAU8K,KAIVK,EAAcA,eAAC/F,EAAe3E,GAChC4K,EAAKjG,EAAc3E,IAAQqK,EAE3BO,EAAK5K,GAAOqK,EAEf,CAED,OAAOO,CACT,CAEA,SAASC,EAAuB7K,GAC9B,OAAOwF,EAAiBsF,SAAS9K,EACnC"}
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 'vest-utils';\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":"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,GACL,KAEqB,QAAvBG,UAAAC,EAAAJ,EAAQY,2BAAOD,UAAQ,IAAAR,EAAAA,EAAA,IAC/B,QC5CUU,EACXd,iBAAiBC,EAAmBQ,GAElC,OADAR,EAAQQ,OAASA,EACVR,CACR,CAEDD,kBAAkBC,EAAmBc,GAEnC,OADAd,EAAQc,OAASA,EACVd,CACR,CAEDD,cAAcC,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1,4 +1,4 @@
1
- import { invariant, isNullish, isStringValue, isNotNullish, hasOwnProperty, text } from 'vest-utils';
1
+ import { assign, invariant, isNullish, isStringValue, isNotNullish, hasOwnProperty, text, isEmpty } from 'vest-utils';
2
2
 
3
3
  var ErrorStrings;
4
4
  (function (ErrorStrings) {
@@ -18,16 +18,18 @@ var IsolateKeys;
18
18
  IsolateKeys["AllowReorder"] = "allowReorder";
19
19
  IsolateKeys["Status"] = "status";
20
20
  IsolateKeys["AbortController"] = "abortController";
21
+ IsolateKeys["Children"] = "children";
21
22
  })(IsolateKeys || (IsolateKeys = {}));
22
23
  var MinifiedKeys;
23
24
  (function (MinifiedKeys) {
24
25
  MinifiedKeys["Type"] = "$";
25
- MinifiedKeys["Keys"] = "K";
26
- MinifiedKeys["Key"] = "k";
26
+ MinifiedKeys["Keys"] = "Ks";
27
+ MinifiedKeys["Key"] = "ky";
27
28
  MinifiedKeys["Parent"] = "P";
28
29
  MinifiedKeys["Data"] = "D";
29
- MinifiedKeys["AllowReorder"] = "aR";
30
+ MinifiedKeys["AllowReorder"] = "AR";
30
31
  MinifiedKeys["Status"] = "S";
32
+ MinifiedKeys["Children"] = "C";
31
33
  })(MinifiedKeys || (MinifiedKeys = {}));
32
34
  const KeyToMinified = {
33
35
  [IsolateKeys.Type]: MinifiedKeys.Type,
@@ -37,6 +39,7 @@ const KeyToMinified = {
37
39
  [IsolateKeys.Key]: MinifiedKeys.Key,
38
40
  [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
39
41
  [IsolateKeys.Status]: MinifiedKeys.Status,
42
+ [IsolateKeys.Children]: MinifiedKeys.Children,
40
43
  };
41
44
  // This const is an object that looks like this:
42
45
  // {
@@ -45,13 +48,18 @@ const KeyToMinified = {
45
48
  // 'P': 'parent',
46
49
  // ...
47
50
  // }
48
- const MinifiedToKey = Object.entries(KeyToMinified).reduce((acc, [key, minified]) => Object.assign(acc, {
49
- [minified]: key,
50
- }), {});
51
+ const MinifiedToKey = invertKeyMap(KeyToMinified);
52
+ function invertKeyMap(miniMap = {}) {
53
+ return Object.entries(miniMap).reduce((acc, [key, minified]) => assign(acc, {
54
+ [minified]: key,
55
+ }), {});
56
+ }
51
57
  const ExcludedFromDump = [
52
58
  IsolateKeys.AbortController,
53
59
  IsolateKeys.Parent,
54
60
  IsolateKeys.Keys,
61
+ IsolateKeys.Children,
62
+ IsolateKeys.Data,
55
63
  ];
56
64
 
57
65
  class IsolateMutator {
@@ -103,8 +111,9 @@ class IsolateMutator {
103
111
  }
104
112
 
105
113
  class IsolateSerializer {
106
- // eslint-disable-next-line max-statements, complexity
107
- static deserialize(node) {
114
+ // eslint-disable-next-line max-statements, complexity, max-lines-per-function
115
+ static deserialize(node, miniMaps) {
116
+ var _a;
108
117
  // the assumption is that the tree is built correctly,
109
118
  // but the children are missing the parent property to
110
119
  // avoid circular references during serialization.
@@ -112,29 +121,52 @@ class IsolateSerializer {
112
121
  // to avoid circular references during serialization.
113
122
  // we need to rebuild the tree and add back the parent property to the children
114
123
  // and the keys property to the parents.
124
+ const inverseMinimap = deeplyInvertKeyMap(miniMaps);
125
+ // Validate the root object
115
126
  const root = isStringValue(node)
116
127
  ? JSON.parse(node)
117
128
  : Object.assign({}, node);
118
129
  IsolateSerializer.validateIsolate(root);
119
130
  const queue = [root];
131
+ // Iterate over the queue until it's empty
120
132
  while (queue.length) {
133
+ // Get the next item from the queue
121
134
  const current = queue.shift();
122
- const children = IsolateSerializer.getChildren(current);
135
+ // Get the children of the current item
136
+ const children = IsolateSerializer.expandChildren(current);
137
+ // Iterate over the minified keys
123
138
  for (const key in MinifiedToKey) {
139
+ // Get the value for the current key
124
140
  const value = current[key];
141
+ // If the value is not null or undefined
125
142
  if (isNotNullish(value)) {
126
- current[MinifiedToKey[key]] = value;
143
+ // Get the key to use
144
+ const keyToUse = MinifiedToKey[key];
145
+ // If the key is data, then we may need to transform the keys
146
+ // eslint-disable-next-line max-depth
147
+ if (keyToUse === IsolateKeys.Data) {
148
+ // Transform the keys
149
+ current[keyToUse] = transformKeys(value, (_a = inverseMinimap === null || inverseMinimap === void 0 ? void 0 : inverseMinimap.keys) === null || _a === void 0 ? void 0 : _a.data);
150
+ }
151
+ else {
152
+ // Otherwise, just set the key
153
+ current[keyToUse] = transformValueByKey(keyToUse, value, inverseMinimap);
154
+ }
155
+ // Remove the old key
127
156
  delete current[key];
128
157
  }
129
158
  }
159
+ // If there are no children, nothing to do.
130
160
  if (!children) {
131
161
  continue;
132
162
  }
163
+ // Copy the children and set their parent to the current node.
133
164
  current.children = children.map(child => {
134
165
  var _a;
135
166
  const nextChild = Object.assign({}, child);
136
167
  IsolateMutator.setParent(nextChild, current);
137
168
  queue.push(nextChild);
169
+ // If the child has a key, add it to the parent's keys.
138
170
  const key = nextChild.key;
139
171
  if (key) {
140
172
  current.keys = (_a = current.keys) !== null && _a !== void 0 ? _a : {};
@@ -145,14 +177,16 @@ class IsolateSerializer {
145
177
  }
146
178
  return root;
147
179
  }
148
- static serialize(isolate) {
180
+ static serialize(isolate, miniMaps) {
149
181
  if (isNullish(isolate)) {
150
182
  return '';
151
183
  }
152
- return JSON.stringify(transformIsolate(isolate));
184
+ return JSON.stringify(transformIsolate(isolate, miniMaps));
153
185
  }
154
- static getChildren(node) {
155
- return node.children ? [...node.children] : null;
186
+ static expandChildren(node) {
187
+ return node[MinifiedKeys.Children]
188
+ ? [...node[MinifiedKeys.Children]]
189
+ : null;
156
190
  }
157
191
  static validateIsolate(node) {
158
192
  invariant(hasOwnProperty(node, IsolateKeys.Type) ||
@@ -160,15 +194,20 @@ class IsolateSerializer {
160
194
  }
161
195
  }
162
196
  // eslint-disable-next-line max-statements, complexity
163
- function transformIsolate(isolate) {
197
+ function transformIsolate(isolate, miniMaps) {
198
+ var _a;
164
199
  const next = {};
165
200
  if (isolate.children) {
166
- next.children = isolate.children.map(transformIsolate);
201
+ next[MinifiedKeys.Children] = isolate.children.map(isolate => transformIsolate(isolate, miniMaps));
202
+ }
203
+ if (!isEmpty(isolate.data)) {
204
+ next[MinifiedKeys.Data] = transformKeys(isolate.data, (_a = miniMaps === null || miniMaps === void 0 ? void 0 : miniMaps.keys) === null || _a === void 0 ? void 0 : _a.data);
167
205
  }
168
206
  for (const key in isolate) {
169
- if (key === 'children') {
170
- continue;
171
- }
207
+ // Skip keys that should be excluded from the dump.
208
+ // While we're excluding children from the dump, they'll actually remain there
209
+ // due to the fact that we've already transformed them recursively beforehand
210
+ // thus renaming them to the minified key.
172
211
  if (isKeyExcluededFromDump(key)) {
173
212
  continue;
174
213
  }
@@ -176,18 +215,53 @@ function transformIsolate(isolate) {
176
215
  if (isNullish(value)) {
177
216
  continue;
178
217
  }
179
- if (hasOwnProperty(KeyToMinified, key)) {
180
- next[KeyToMinified[key]] = value;
181
- }
182
- else {
183
- next[key] = value;
184
- }
218
+ const keyToUse = minifyKey(key);
219
+ next[keyToUse] = transformValueByKey(key, value, miniMaps);
185
220
  }
186
221
  return next;
187
222
  }
188
223
  function isKeyExcluededFromDump(key) {
189
224
  return ExcludedFromDump.includes(key);
190
225
  }
226
+ function minifyKey(key) {
227
+ var _a;
228
+ return (_a = KeyToMinified[key]) !== null && _a !== void 0 ? _a : key;
229
+ }
230
+ function transformValueByKey(key, value, miniMaps) {
231
+ var _a, _b;
232
+ if (isNullish(value)) {
233
+ return value;
234
+ }
235
+ const keyMap = (_a = miniMaps === null || miniMaps === void 0 ? void 0 : miniMaps.values) === null || _a === void 0 ? void 0 : _a[key];
236
+ return keyMap ? (_b = keyMap[value]) !== null && _b !== void 0 ? _b : value : value;
237
+ }
238
+ function transformKeys(data, keyMap) {
239
+ var _a;
240
+ const next = {};
241
+ // Loop over each key in the data.
242
+ for (const key in data) {
243
+ // Find the key to use for the next object.
244
+ // If there is no key map, use the original key.
245
+ // If there is a key map, use the key map entry for the current key.
246
+ const keyToUse = (_a = (keyMap ? keyMap[key] : key)) !== null && _a !== void 0 ? _a : key;
247
+ // Add the key and value to the next object.
248
+ next[keyToUse] = data[key];
249
+ }
250
+ // Return the next object.
251
+ return next;
252
+ }
253
+ function deeplyInvertKeyMap(miniMaps = {}) {
254
+ return Object.entries(miniMaps).reduce((acc, [key, value]) => {
255
+ if (typeof value === 'object') {
256
+ return assign(acc, {
257
+ [key]: deeplyInvertKeyMap(value),
258
+ });
259
+ }
260
+ return assign(acc, {
261
+ [value]: key,
262
+ });
263
+ }, {});
264
+ }
191
265
 
192
- export { IsolateSerializer };
266
+ export { IsolateSerializer, deeplyInvertKeyMap };
193
267
  //# 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 AbortController = 'abortController',\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\nexport const ExcludedFromDump = [\n IsolateKeys.AbortController,\n IsolateKeys.Parent,\n IsolateKeys.Keys,\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 Nullable,\n hasOwnProperty,\n invariant,\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 MinifiedToKey,\n} 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 ExcludedFromDump.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,CAAA,6BAAA,CAAA,GAAA,uFAAqH,CAAA;AACrH,IAAA,YAAA,CAAA,gCAAA,CAAA,GAAA,mGAAkI,CAAA;AAClI,IAAA,YAAA,CAAA,8BAAA,CAAA,GAAA,kEAAiG,CAAA;AACnG,CAAC,EALW,YAAY,KAAZ,YAAY,GAKvB,EAAA,CAAA,CAAA;;ACLD,IAAY,WASX,CAAA;AATD,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,OAAc,CAAA;AACd,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,WAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;AACX,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;AACb,IAAA,WAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC7B,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;AACjB,IAAA,WAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC,CAAA;AACrC,CAAC,EATW,WAAW,KAAX,WAAW,GAStB,EAAA,CAAA,CAAA,CAAA;AAED,IAAK,YAQJ,CAAA;AARD,CAAA,UAAK,YAAY,EAAA;AACf,IA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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,gBAAgB,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;AACvD;;;;"}
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 'vest-utils';\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":[],"mappings":";;AAAA,IAAY,YAKX,CAAA;AALD,CAAA,UAAY,YAAY,EAAA;AACtB,IAAA,YAAA,CAAA,mBAAA,CAAA,GAAA,8BAAkD,CAAA;AAClD,IAAA,YAAA,CAAA,6BAAA,CAAA,GAAA,uFAAqH,CAAA;AACrH,IAAA,YAAA,CAAA,gCAAA,CAAA,GAAA,mGAAkI,CAAA;AAClI,IAAA,YAAA,CAAA,8BAAA,CAAA,GAAA,kEAAiG,CAAA;AACnG,CAAC,EALW,YAAY,KAAZ,YAAY,GAKvB,EAAA,CAAA,CAAA;;ACHD,IAAY,WAUX,CAAA;AAVD,CAAA,UAAY,WAAW,EAAA;AACrB,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,OAAc,CAAA;AACd,IAAA,WAAA,CAAA,MAAA,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_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."}(i||(i={})),function(e){e.Type="$type",e.Keys="keys",e.Key="key",e.Parent="parent",e.Data="data",e.AllowReorder="allowReorder",e.Status="status",e.AbortController="abortController"}(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,r])=>Object.assign(e,{[r]:t})),{}),u=[l.AbortController,l.Parent,l.Keys];class y{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,r){var n;e(t),t.children=null!==(n=t.children)&&void 0!==n?n:[],t.children.push(r),y.setParent(r,t)}static removeChild(e,t){var r,n;e.children=null!==(n=null===(r=e.children)||void 0===r?void 0:r.filter((e=>e!==t)))&&void 0!==n?n:null}static addChildKey(t,r,n){var a;e(t),t.keys=null!==(a=t.keys)&&void 0!==a?a:{},t.keys[r]=n}static slice(e,r){t(e.children)||(e.children.length=r)}static setData(e,t){e.data=t}static abort(e,r){t(e.abortController)||e.abortController.abort(r)}}class h{static deserialize(e){const t=r(e)?JSON.parse(e):Object.assign({},e);h.validateIsolate(t);const a=[t];for(;a.length;){const e=a.shift(),t=h.getChildren(e);for(const t in d){const r=e[t];n(r)&&(e[d[t]]=r,delete e[t])}t&&(e.children=t.map((t=>{var r;const n=Object.assign({},t);y.setParent(n,e),a.push(n);const s=n.key;return s&&(e.keys=null!==(r=e.keys)&&void 0!==r?r:{},e.keys[s]=n),n})))}return t}static serialize(e){return t(e)?"":JSON.stringify(p(e))}static getChildren(e){return e.children?[...e.children]:null}static validateIsolate(t){e(a(t,l.Type)||a(t,c[l.Type]),s(i.INVALID_ISOLATE_CANNOT_PARSE))}}function p(e){const r={};e.children&&(r.children=e.children.map(p));for(const n in e){if("children"===n)continue;if(T(n))continue;const s=e[n];t(s)||(a(c,n)?r[c[n]]=s:r[n]=s)}return r}function T(e){return u.includes(e)}export{h as IsolateSerializer};
1
+ import{assign as t,invariant as e,isNullish as n,isStringValue as r,isNotNullish as i,hasOwnProperty as a,text as o,isEmpty as l}from"vest-utils";var s,d,c;!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."}(s||(s={})),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"}(d||(d={})),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"}(c||(c={}));const u={[d.Type]:c.Type,[d.Keys]:c.Keys,[d.Parent]:c.Parent,[d.Data]:c.Data,[d.Key]:c.Key,[d.AllowReorder]:c.AllowReorder,[d.Status]:c.Status,[d.Children]:c.Children},v=function(e={}){return Object.entries(e).reduce(((e,[n,r])=>t(e,{[r]:n})),{})}(u);const y=[d.AbortController,d.Parent,d.Keys,d.Children,d.Data];class h{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(t,n){var r;e(t),t.children=null!==(r=t.children)&&void 0!==r?r:[],t.children.push(n),h.setParent(n,t)}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(t,n,r){var i;e(t),t.keys=null!==(i=t.keys)&&void 0!==i?i:{},t.keys[n]=r}static slice(t,e){n(t.children)||(t.children.length=e)}static setData(t,e){t.data=e}static abort(t,e){n(t.abortController)||t.abortController.abort(e)}}class p{static deserialize(t,e){var n;const a=k(e),o=r(t)?JSON.parse(t):Object.assign({},t);p.validateIsolate(o);const l=[o];for(;l.length;){const t=l.shift(),e=p.expandChildren(t);for(const e in v){const r=t[e];if(i(r)){const i=v[e];i===d.Data?t[i]=E(r,null===(n=null==a?void 0:a.keys)||void 0===n?void 0:n.data):t[i]=T(i,r,a),delete t[e]}}e&&(t.children=e.map((e=>{var n;const r=Object.assign({},e);h.setParent(r,t),l.push(r);const i=r.key;return i&&(t.keys=null!==(n=t.keys)&&void 0!==n?n:{},t.keys[i]=r),r})))}return o}static serialize(t,e){return n(t)?"":JSON.stringify(C(t,e))}static expandChildren(t){return t[c.Children]?[...t[c.Children]]:null}static validateIsolate(t){e(a(t,d.Type)||a(t,u[d.Type]),o(s.INVALID_ISOLATE_CANNOT_PARSE))}}function C(t,e){var r;const i={};t.children&&(i[c.Children]=t.children.map((t=>C(t,e)))),l(t.data)||(i[c.Data]=E(t.data,null===(r=null==e?void 0:e.keys)||void 0===r?void 0:r.data));for(const r in t){if(f(r))continue;const a=t[r];if(n(a))continue;i[A(r)]=T(r,a,e)}return i}function f(t){return y.includes(t)}function A(t){var e;return null!==(e=u[t])&&void 0!==e?e:t}function T(t,e,r){var i,a;if(n(e))return e;const o=null===(i=null==r?void 0:r.values)||void 0===i?void 0:i[t];return o&&null!==(a=o[e])&&void 0!==a?a:e}function E(t,e){var n;const r={};for(const i in t){r[null!==(n=e?e[i]:i)&&void 0!==n?n:i]=t[i]}return r}function k(e={}){return Object.entries(e).reduce(((e,[n,r])=>t(e,"object"==typeof r?{[n]:k(r)}:{[r]:n})),{})}export{p as IsolateSerializer,k as deeplyInvertKeyMap};
2
2
  //# sourceMappingURL=IsolateSerializer.production.js.map