vestjs-runtime 1.0.5 → 1.0.6

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 +16 -0
  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 +11 -0
  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 +148 -120
  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 +16 -0
  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 +11 -0
  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 +150 -122
  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 +16 -0
  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 +11 -0
  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 +148 -120
  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 +8 -1
  39. package/types/IsolateSerializer.d.ts.map +1 -1
  40. package/types/test-utils.d.ts +8 -1
  41. package/types/test-utils.d.ts.map +1 -1
  42. package/types/vestjs-runtime.d.ts +35 -7
  43. package/types/vestjs-runtime.d.ts.map +1 -1
@@ -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}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\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};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateMutator {\n static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {\n isolate.parent = parent;\n return isolate;\n }\n\n static saveOutput(isolate: TIsolate, output: any): TIsolate {\n isolate.output = output;\n return isolate;\n }\n\n static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {\n isolate.key = key;\n return isolate;\n }\n\n static addChild(isolate: TIsolate, child: TIsolate): void {\n invariant(isolate);\n\n isolate.children = isolate.children ?? [];\n\n isolate.children.push(child);\n IsolateMutator.setParent(child, isolate);\n }\n\n static removeChild(isolate: TIsolate, node: TIsolate): void {\n isolate.children =\n isolate.children?.filter(child => child !== node) ?? null;\n }\n\n static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {\n invariant(isolate);\n\n isolate.keys = isolate.keys ?? {};\n\n isolate.keys[key] = node;\n }\n\n static slice(isolate: TIsolate, at: number): void {\n if (isNullish(isolate.children)) {\n return;\n }\n isolate.children.length = at;\n }\n\n static setData(isolate: TIsolate, data: any): void {\n isolate.data = data;\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Nullable,\n hasOwnProperty,\n invariant,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys, KeyToMinified, MinifiedToKey } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity\n static deserialize(node: Record<string, any> | TIsolate | string): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n while (queue.length) {\n const current = queue.shift();\n\n const children = IsolateSerializer.getChildren(current);\n\n for (const key in MinifiedToKey) {\n const value = current[key];\n if (isNotNullish(value)) {\n current[MinifiedToKey[key]] = value;\n delete current[key];\n }\n }\n\n if (!children) {\n continue;\n }\n\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(isolate: Nullable<TIsolate>): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate));\n }\n\n static getChildren(node: TIsolate): Nullable<TIsolate[]> {\n return node.children ? [...node.children] : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(isolate: TIsolate): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next.children = isolate.children.map(transformIsolate);\n }\n\n for (const key in isolate) {\n if (key === 'children') {\n continue;\n }\n\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n if (hasOwnProperty(KeyToMinified, key)) {\n next[KeyToMinified[key]] = value;\n } else {\n next[key] = value;\n }\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return [IsolateKeys.Parent, IsolateKeys.Keys].includes(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AAgB,CAAC,CAAC;EACxD,KAAA;EAED,IAAA,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;UACzB,IAAI,GAAG,KAAK,UAAU,EAAE;cACtB,SAAS;EACV,SAAA;EAED,QAAA,IAAI,sBAAsB,CAAC,GAAG,CAAC,EAAE;cAC/B,SAAS;EACV,SAAA;EACD,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,GAAqB,CAAC,CAAC;EAE7C,QAAA,IAAIJ,mBAAS,CAAC,KAAK,CAAC,EAAE;cACpB,SAAS;EACV,SAAA;EAED,QAAA,IAAIG,wBAAc,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE;cACtC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;EAClC,SAAA;EAAM,aAAA;EACL,YAAA,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;EACnB,SAAA;EACF,KAAA;EAED,IAAA,OAAO,IAAI,CAAC;EACd,CAAC;EAED,SAAS,sBAAsB,CAAC,GAAW,EAAA;EACzC,IAAA,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;EAC7E;;;;;;;;"}
1
+ {"version":3,"file":"IsolateSerializer.development.js","sources":["../../src/errors/ErrorStrings.ts","../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateStatus.ts","../../src/Isolate/IsolateMutator.ts","../../src/exports/IsolateSerializer.ts"],"sourcesContent":["export enum ErrorStrings {\n NO_ACTIVE_ISOLATE = 'Not within an active isolate',\n UNABLE_TO_PICK_NEXT_ISOLATE = 'Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.',\n ENCOUNTERED_THE_SAME_KEY_TWICE = `Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.`,\n INVALID_ISOLATE_CANNOT_PARSE = `Invalid isolate was passed to IsolateSerializer. Cannot proceed.`,\n}\n","export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\n Status = 'S',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","export enum IsolateStatus {\n PENDING = 'PENDING',\n DONE = 'DONE',\n INITIAL = 'INITIAL',\n}\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateStatus } from 'IsolateStatus';\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 setPending(isolate: TIsolate): void {\n isolate.status = IsolateStatus.PENDING;\n }\n\n static setDone(isolate: TIsolate): void {\n isolate.status = IsolateStatus.DONE;\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Nullable,\n hasOwnProperty,\n invariant,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys, KeyToMinified, MinifiedToKey } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity\n static deserialize(node: Record<string, any> | TIsolate | string): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n while (queue.length) {\n const current = queue.shift();\n\n const children = IsolateSerializer.getChildren(current);\n\n for (const key in MinifiedToKey) {\n const value = current[key];\n if (isNotNullish(value)) {\n current[MinifiedToKey[key]] = value;\n delete current[key];\n }\n }\n\n if (!children) {\n continue;\n }\n\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(isolate: Nullable<TIsolate>): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate));\n }\n\n static getChildren(node: TIsolate): Nullable<TIsolate[]> {\n return node.children ? [...node.children] : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(isolate: TIsolate): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next.children = isolate.children.map(transformIsolate);\n }\n\n for (const key in isolate) {\n if (key === 'children') {\n continue;\n }\n\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n if (hasOwnProperty(KeyToMinified, key)) {\n next[KeyToMinified[key]] = value;\n } else {\n next[key] = value;\n }\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return [IsolateKeys.Parent, IsolateKeys.Keys].includes(key as IsolateKeys);\n}\n"],"names":["invariant","isNullish","isStringValue","isNotNullish","hasOwnProperty","text"],"mappings":";;;;;;EAAA,IAAY,YAKX,CAAA;EALD,CAAA,UAAY,YAAY,EAAA;EACtB,IAAA,YAAA,CAAA,mBAAA,CAAA,GAAA,8BAAkD,CAAA;EAClD,IAAA,YAAA,CAAA,6BAAA,CAAA,GAAA,uFAAqH,CAAA;EACrH,IAAA,YAAA,CAAA,gCAAA,CAAA,GAAA,mGAAkI,CAAA;EAClI,IAAA,YAAA,CAAA,8BAAA,CAAA,GAAA,kEAAiG,CAAA;EACnG,CAAC,EALW,YAAY,KAAZ,YAAY,GAKvB,EAAA,CAAA,CAAA;;ECLD,IAAY,WAQX,CAAA;EARD,CAAA,UAAY,WAAW,EAAA;EACrB,IAAA,WAAA,CAAA,MAAA,CAAA,G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,IAAI,GAAwB,EAAE,CAAC;MAErC,IAAI,OAAO,CAAC,QAAQ,EAAE;UACpB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;EACxD,KAAA;EAED,IAAA,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;UACzB,IAAI,GAAG,KAAK,UAAU,EAAE;cACtB,SAAS;EACV,SAAA;EAED,QAAA,IAAI,sBAAsB,CAAC,GAAG,CAAC,EAAE;cAC/B,SAAS;EACV,SAAA;EACD,QAAA,MAAM,KAAK,GAAG,OAAO,CAAC,GAAqB,CAAC,CAAC;EAE7C,QAAA,IAAIJ,mBAAS,CAAC,KAAK,CAAC,EAAE;cACpB,SAAS;EACV,SAAA;EAED,QAAA,IAAIG,wBAAc,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE;cACtC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;EAClC,SAAA;EAAM,aAAA;EACL,YAAA,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;EACnB,SAAA;EACF,KAAA;EAED,IAAA,OAAO,IAAI,CAAC;EACd,CAAC;EAED,SAAS,sBAAsB,CAAC,GAAW,EAAA;EACzC,IAAA,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAkB,CAAC,CAAC;EAC7E;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vest-utils")):"function"==typeof define&&define.amd?define(["exports","vest-utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IsolateSerializer={},e["vest-utils"])}(this,(function(e,t){"use strict";var i,n,s;!function(e){e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.UNABLE_TO_PICK_NEXT_ISOLATE="Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.",e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same key "{key}" twice. This may lead to inconsistent or overriding of results.',e.INVALID_ISOLATE_CANNOT_PARSE="Invalid isolate was passed to IsolateSerializer. Cannot proceed."}(i||(i={})),function(e){e.Type="$type",e.Keys="keys",e.Key="key",e.Parent="parent",e.Data="data",e.AllowReorder="allowReorder"}(n||(n={})),function(e){e.Type="$",e.Keys="K",e.Key="k",e.Parent="P",e.Data="D",e.AllowReorder="aR"}(s||(s={}));const r={[n.Type]:s.Type,[n.Keys]:s.Keys,[n.Parent]:s.Parent,[n.Data]:s.Data,[n.Key]:s.Key,[n.AllowReorder]:s.AllowReorder},a=Object.entries(r).reduce(((e,[t,i])=>Object.assign(e,{[i]:t})),{});class l{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(e,i){var n;t.invariant(e),e.children=null!==(n=e.children)&&void 0!==n?n:[],e.children.push(i),l.setParent(i,e)}static removeChild(e,t){var i,n;e.children=null!==(n=null===(i=e.children)||void 0===i?void 0:i.filter((e=>e!==t)))&&void 0!==n?n:null}static addChildKey(e,i,n){var s;t.invariant(e),e.keys=null!==(s=e.keys)&&void 0!==s?s:{},e.keys[i]=n}static slice(e,i){t.isNullish(e.children)||(e.children.length=i)}static setData(e,t){e.data=t}}class o{static deserialize(e){const i=t.isStringValue(e)?JSON.parse(e):Object.assign({},e);o.validateIsolate(i);const n=[i];for(;n.length;){const e=n.shift(),i=o.getChildren(e);for(const i in a){const n=e[i];t.isNotNullish(n)&&(e[a[i]]=n,delete e[i])}i&&(e.children=i.map((t=>{var i;const s=Object.assign({},t);l.setParent(s,e),n.push(s);const r=s.key;return r&&(e.keys=null!==(i=e.keys)&&void 0!==i?i:{},e.keys[r]=s),s})))}return i}static serialize(e){return t.isNullish(e)?"":JSON.stringify(c(e))}static getChildren(e){return e.children?[...e.children]:null}static validateIsolate(e){t.invariant(t.hasOwnProperty(e,n.Type)||t.hasOwnProperty(e,r[n.Type]),t.text(i.INVALID_ISOLATE_CANNOT_PARSE))}}function c(e){const i={};e.children&&(i.children=e.children.map(c));for(const n in e){if("children"===n)continue;if(d(n))continue;const s=e[n];t.isNullish(s)||(t.hasOwnProperty(r,n)?i[r[n]]=s:i[n]=s)}return i}function d(e){return[n.Parent,n.Keys].includes(e)}e.IsolateSerializer=o}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vest-utils")):"function"==typeof define&&define.amd?define(["exports","vest-utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).IsolateSerializer={},e["vest-utils"])}(this,(function(e,t){"use strict";var i,s,n;!function(e){e.NO_ACTIVE_ISOLATE="Not within an active isolate",e.UNABLE_TO_PICK_NEXT_ISOLATE="Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.",e.ENCOUNTERED_THE_SAME_KEY_TWICE='Encountered the same key "{key}" twice. This may lead to inconsistent or overriding of results.',e.INVALID_ISOLATE_CANNOT_PARSE="Invalid isolate was passed to IsolateSerializer. Cannot proceed."}(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"}(s||(s={})),function(e){e.Type="$",e.Keys="K",e.Key="k",e.Parent="P",e.Data="D",e.AllowReorder="aR",e.Status="S"}(n||(n={}));const a={[s.Type]:n.Type,[s.Keys]:n.Keys,[s.Parent]:n.Parent,[s.Data]:n.Data,[s.Key]:n.Key,[s.AllowReorder]:n.AllowReorder,[s.Status]:n.Status},r=Object.entries(a).reduce(((e,[t,i])=>Object.assign(e,{[i]:t})),{});var l;!function(e){e.PENDING="PENDING",e.DONE="DONE",e.INITIAL="INITIAL"}(l||(l={}));class o{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(e,i){var s;t.invariant(e),e.children=null!==(s=e.children)&&void 0!==s?s:[],e.children.push(i),o.setParent(i,e)}static removeChild(e,t){var i,s;e.children=null!==(s=null===(i=e.children)||void 0===i?void 0:i.filter((e=>e!==t)))&&void 0!==s?s:null}static addChildKey(e,i,s){var n;t.invariant(e),e.keys=null!==(n=e.keys)&&void 0!==n?n:{},e.keys[i]=s}static slice(e,i){t.isNullish(e.children)||(e.children.length=i)}static setData(e,t){e.data=t}static setPending(e){e.status=l.PENDING}static setDone(e){e.status=l.DONE}}class c{static deserialize(e){const i=t.isStringValue(e)?JSON.parse(e):Object.assign({},e);c.validateIsolate(i);const s=[i];for(;s.length;){const e=s.shift(),i=c.getChildren(e);for(const i in r){const s=e[i];t.isNotNullish(s)&&(e[r[i]]=s,delete e[i])}i&&(e.children=i.map((t=>{var i;const n=Object.assign({},t);o.setParent(n,e),s.push(n);const a=n.key;return a&&(e.keys=null!==(i=e.keys)&&void 0!==i?i:{},e.keys[a]=n),n})))}return i}static serialize(e){return t.isNullish(e)?"":JSON.stringify(d(e))}static getChildren(e){return e.children?[...e.children]:null}static validateIsolate(e){t.invariant(t.hasOwnProperty(e,s.Type)||t.hasOwnProperty(e,a[s.Type]),t.text(i.INVALID_ISOLATE_CANNOT_PARSE))}}function d(e){const i={};e.children&&(i.children=e.children.map(d));for(const s in e){if("children"===s)continue;if(u(s))continue;const n=e[s];t.isNullish(n)||(t.hasOwnProperty(a,s)?i[a[s]]=n:i[s]=n)}return i}function u(e){return[s.Parent,s.Keys].includes(e)}e.IsolateSerializer=c}));
2
2
  //# sourceMappingURL=IsolateSerializer.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IsolateSerializer.production.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}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\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};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\n\nexport class IsolateMutator {\n static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {\n isolate.parent = parent;\n return isolate;\n }\n\n static saveOutput(isolate: TIsolate, output: any): TIsolate {\n isolate.output = output;\n return isolate;\n }\n\n static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {\n isolate.key = key;\n return isolate;\n }\n\n static addChild(isolate: TIsolate, child: TIsolate): void {\n invariant(isolate);\n\n isolate.children = isolate.children ?? [];\n\n isolate.children.push(child);\n IsolateMutator.setParent(child, isolate);\n }\n\n static removeChild(isolate: TIsolate, node: TIsolate): void {\n isolate.children =\n isolate.children?.filter(child => child !== node) ?? null;\n }\n\n static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {\n invariant(isolate);\n\n isolate.keys = isolate.keys ?? {};\n\n isolate.keys[key] = node;\n }\n\n static slice(isolate: TIsolate, at: number): void {\n if (isNullish(isolate.children)) {\n return;\n }\n isolate.children.length = at;\n }\n\n static setData(isolate: TIsolate, data: any): void {\n isolate.data = data;\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Nullable,\n hasOwnProperty,\n invariant,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys, KeyToMinified, MinifiedToKey } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity\n static deserialize(node: Record<string, any> | TIsolate | string): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n while (queue.length) {\n const current = queue.shift();\n\n const children = IsolateSerializer.getChildren(current);\n\n for (const key in MinifiedToKey) {\n const value = current[key];\n if (isNotNullish(value)) {\n current[MinifiedToKey[key]] = value;\n delete current[key];\n }\n }\n\n if (!children) {\n continue;\n }\n\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(isolate: Nullable<TIsolate>): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate));\n }\n\n static getChildren(node: TIsolate): Nullable<TIsolate[]> {\n return node.children ? [...node.children] : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(isolate: TIsolate): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next.children = isolate.children.map(transformIsolate);\n }\n\n for (const key in isolate) {\n if (key === 'children') {\n continue;\n }\n\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n if (hasOwnProperty(KeyToMinified, key)) {\n next[KeyToMinified[key]] = value;\n } else {\n next[key] = value;\n }\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return [IsolateKeys.Parent, IsolateKeys.Keys].includes(key as IsolateKeys);\n}\n"],"names":["ErrorStrings","IsolateKeys","MinifiedKeys","KeyToMinified","Type","Keys","Parent","Data","Key","AllowReorder","MinifiedToKey","Object","entries","reduce","acc","key","minified","assign","IsolateMutator","static","isolate","parent","output","child","invariant","children","_a","push","setParent","node","_b","filter","keys","at","isNullish","length","data","IsolateSerializer","root","isStringValue","JSON","parse","validateIsolate","queue","current","shift","getChildren","value","isNotNullish","map","nextChild","stringify","transformIsolate","hasOwnProperty","text","INVALID_ISOLATE_CANNOT_PARSE","next","isKeyExcluededFromDump","includes"],"mappings":"8SAAA,IAAYA,ECAAC,EASPC,GDTL,SAAYF,GACVA,EAAA,kBAAA,+BACAA,EAAA,4BAAA,wFACAA,EAAA,+BAAA,kGACAA,EAAA,6BAAA,kEACD,CALD,CAAYA,IAAAA,EAKX,CAAA,ICLD,SAAYC,GACVA,EAAA,KAAA,QACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,OAAA,SACAA,EAAA,KAAA,OACAA,EAAA,aAAA,cACD,CAPD,CAAYA,IAA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AA,EAE9BpC,EAAQK,WACV+B,EAAK/B,SAAWL,EAAQK,SAASwB,IAAIG,IAGvC,IAAK,MAAMrC,KAAOK,EAAS,CACzB,GAAY,aAARL,EACF,SAGF,GAAI0C,EAAuB1C,GACzB,SAEF,MAAMgC,EAAQ3B,EAAQL,GAElBmB,EAAAA,UAAUa,KAIVM,EAAcA,eAAClD,EAAeY,GAChCyC,EAAKrD,EAAcY,IAAQgC,EAE3BS,EAAKzC,GAAOgC,EAEf,CAED,OAAOS,CACT,CAEA,SAASC,EAAuB1C,GAC9B,MAAO,CAACd,EAAYK,OAAQL,EAAYI,MAAMqD,SAAS3C,EACzD"}
1
+ {"version":3,"file":"IsolateSerializer.production.js","sources":["../../src/errors/ErrorStrings.ts","../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateStatus.ts","../../src/Isolate/IsolateMutator.ts","../../src/exports/IsolateSerializer.ts"],"sourcesContent":["export enum ErrorStrings {\n NO_ACTIVE_ISOLATE = 'Not within an active isolate',\n UNABLE_TO_PICK_NEXT_ISOLATE = 'Unable to pick next isolate. This is a bug, please report it to the Vest maintainers.',\n ENCOUNTERED_THE_SAME_KEY_TWICE = `Encountered the same key \"{key}\" twice. This may lead to inconsistent or overriding of results.`,\n INVALID_ISOLATE_CANNOT_PARSE = `Invalid isolate was passed to IsolateSerializer. Cannot proceed.`,\n}\n","export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\n Status = 'S',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","export enum IsolateStatus {\n PENDING = 'PENDING',\n DONE = 'DONE',\n INITIAL = 'INITIAL',\n}\n","import { Nullable, invariant, isNullish } from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateStatus } from 'IsolateStatus';\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 setPending(isolate: TIsolate): void {\n isolate.status = IsolateStatus.PENDING;\n }\n\n static setDone(isolate: TIsolate): void {\n isolate.status = IsolateStatus.DONE;\n }\n}\n","import { ErrorStrings } from 'ErrorStrings';\nimport {\n Nullable,\n hasOwnProperty,\n invariant,\n isNotNullish,\n isNullish,\n isStringValue,\n text,\n} from 'vest-utils';\n\nimport { TIsolate } from 'Isolate';\nimport { IsolateKeys, KeyToMinified, MinifiedToKey } from 'IsolateKeys';\nimport { IsolateMutator } from 'IsolateMutator';\n\nexport class IsolateSerializer {\n // eslint-disable-next-line max-statements, complexity\n static deserialize(node: Record<string, any> | TIsolate | string): TIsolate {\n // the assumption is that the tree is built correctly,\n // but the children are missing the parent property to\n // avoid circular references during serialization.\n // in the same way, the parents are missing the `keys` property\n // to avoid circular references during serialization.\n // we need to rebuild the tree and add back the parent property to the children\n // and the keys property to the parents.\n\n const root = isStringValue(node)\n ? JSON.parse(node)\n : ({ ...node } as TIsolate);\n\n IsolateSerializer.validateIsolate(root);\n\n const queue = [root];\n\n while (queue.length) {\n const current = queue.shift();\n\n const children = IsolateSerializer.getChildren(current);\n\n for (const key in MinifiedToKey) {\n const value = current[key];\n if (isNotNullish(value)) {\n current[MinifiedToKey[key]] = value;\n delete current[key];\n }\n }\n\n if (!children) {\n continue;\n }\n\n current.children = children.map(child => {\n const nextChild = { ...child };\n\n IsolateMutator.setParent(nextChild, current);\n queue.push(nextChild);\n\n const key = nextChild.key;\n\n if (key) {\n current.keys = current.keys ?? {};\n current.keys[key] = nextChild;\n }\n\n return nextChild;\n });\n }\n\n return root as TIsolate;\n }\n\n static serialize(isolate: Nullable<TIsolate>): string {\n if (isNullish(isolate)) {\n return '';\n }\n\n return JSON.stringify(transformIsolate(isolate));\n }\n\n static getChildren(node: TIsolate): Nullable<TIsolate[]> {\n return node.children ? [...node.children] : null;\n }\n\n static validateIsolate(node: Record<string, any> | TIsolate): void {\n invariant(\n hasOwnProperty(node, IsolateKeys.Type) ||\n hasOwnProperty(node, KeyToMinified[IsolateKeys.Type]),\n text(ErrorStrings.INVALID_ISOLATE_CANNOT_PARSE)\n );\n }\n}\n\n// eslint-disable-next-line max-statements, complexity\nfunction transformIsolate(isolate: TIsolate): Record<string, any> {\n const next: Record<string, any> = {};\n\n if (isolate.children) {\n next.children = isolate.children.map(transformIsolate);\n }\n\n for (const key in isolate) {\n if (key === 'children') {\n continue;\n }\n\n if (isKeyExcluededFromDump(key)) {\n continue;\n }\n const value = isolate[key as keyof TIsolate];\n\n if (isNullish(value)) {\n continue;\n }\n\n if (hasOwnProperty(KeyToMinified, key)) {\n next[KeyToMinified[key]] = value;\n } else {\n next[key] = value;\n }\n }\n\n return next;\n}\n\nfunction isKeyExcluededFromDump(key: string): boolean {\n return [IsolateKeys.Parent, IsolateKeys.Keys].includes(key as IsolateKeys);\n}\n"],"names":["ErrorStrings","IsolateKeys","MinifiedKeys","KeyToMinified","Type","Keys","Parent","Data","Key","AllowReorder","Status","MinifiedToKey","Object","entries","reduce","acc","key","minified","assign","IsolateStatus","IsolateMutator","static","isolate","parent","output","child","invariant","children","_a","push","setParent","node","_b","filter","keys","at","isNullish","length","data","status","PENDING","DONE","IsolateSerializer","root","isStringValue","JSON","parse","validateIsolate","queue","current","shift","getChildren","value","isNotNullish","map","nextChild","stringify","transformIsolate","hasOwnProperty","text","INVALID_ISOLATE_CANNOT_PARSE","next","isKeyExcluededFromDump","includes"],"mappings":"8SAAA,IAAYA,ECAAC,EAUPC,GDVL,SAAYF,GACVA,EAAA,kBAAA,+BACAA,EAAA,4BAAA,wFACAA,EAAA,+BAAA,kGACAA,EAAA,6BAAA,kEACD,CALD,CAAYA,IAAAA,EAKX,CAAA,ICLD,SAAYC,GACVA,EAAA,KAAA,QACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,OAAA,SACAA,EAAA,KAAA,OACAA,EAAA,aAAA,eACAA,EAAA,OAAA,QACD,CARD,CAAYA,IAAAA,EAQX,CAAA,IAED,SAAKC,GACHA,EAAA,KAAA,IACAA,EAAA,KAAA,IACAA,EAAA,IAAA,IACAA,EAAA,OAAA,IACAA,EAAA,KAAA,IACAA,EAAA,aAAA,KACAA,EAAA,OAAA,GACD,CARD,CAAKA,IAAAA,EAQJ,CAA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EAAYG,OACjDuD,OAAK3D,EAAa4D,8BAErB,EAIH,SAASH,EAAiBnC,GACxB,MAAMuC,EAA4B,CAAA,EAE9BvC,EAAQK,WACVkC,EAAKlC,SAAWL,EAAQK,SAAS2B,IAAIG,IAGvC,IAAK,MAAMzC,KAAOM,EAAS,CACzB,GAAY,aAARN,EACF,SAGF,GAAI8C,EAAuB9C,GACzB,SAEF,MAAMoC,EAAQ9B,EAAQN,GAElBoB,EAAAA,UAAUgB,KAIVM,EAAcA,eAACvD,EAAea,GAChC6C,EAAK1D,EAAca,IAAQoC,EAE3BS,EAAK7C,GAAOoC,EAEf,CAED,OAAOS,CACT,CAEA,SAASC,EAAuB9C,GAC9B,MAAO,CAACf,EAAYK,OAAQL,EAAYI,MAAM0D,SAAS/C,EACzD"}
@@ -12,6 +12,7 @@
12
12
  IsolateKeys["Parent"] = "parent";
13
13
  IsolateKeys["Data"] = "data";
14
14
  IsolateKeys["AllowReorder"] = "allowReorder";
15
+ IsolateKeys["Status"] = "status";
15
16
  })(IsolateKeys || (IsolateKeys = {}));
16
17
  var MinifiedKeys;
17
18
  (function (MinifiedKeys) {
@@ -21,6 +22,7 @@
21
22
  MinifiedKeys["Parent"] = "P";
22
23
  MinifiedKeys["Data"] = "D";
23
24
  MinifiedKeys["AllowReorder"] = "aR";
25
+ MinifiedKeys["Status"] = "S";
24
26
  })(MinifiedKeys || (MinifiedKeys = {}));
25
27
  const KeyToMinified = {
26
28
  [IsolateKeys.Type]: MinifiedKeys.Type,
@@ -29,6 +31,7 @@
29
31
  [IsolateKeys.Data]: MinifiedKeys.Data,
30
32
  [IsolateKeys.Key]: MinifiedKeys.Key,
31
33
  [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
34
+ [IsolateKeys.Status]: MinifiedKeys.Status,
32
35
  };
33
36
  // This const is an object that looks like this:
34
37
  // {
@@ -41,6 +44,13 @@
41
44
  [minified]: key,
42
45
  }), {});
43
46
 
47
+ var IsolateStatus;
48
+ (function (IsolateStatus) {
49
+ IsolateStatus["PENDING"] = "PENDING";
50
+ IsolateStatus["DONE"] = "DONE";
51
+ IsolateStatus["INITIAL"] = "INITIAL";
52
+ })(IsolateStatus || (IsolateStatus = {}));
53
+
44
54
  function genTestIsolate(data = {}) {
45
55
  return {
46
56
  children: [],
@@ -49,6 +59,7 @@
49
59
  keys: {},
50
60
  output: null,
51
61
  parent: null,
62
+ status: IsolateStatus.INITIAL,
52
63
  [IsolateKeys.Type]: 'UnitTest',
53
64
  };
54
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.development.js","sources":["../../src/Isolate/IsolateKeys.ts","../../src/exports/test-utils.ts"],"sourcesContent":["export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\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};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","import { TIsolate } from 'Isolate';\nimport { IsolateKeys } from 'IsolateKeys';\n\nexport function genTestIsolate(data: Record<string, any> = {}): TIsolate {\n return {\n children: [],\n data,\n key: null,\n keys: {},\n output: null,\n parent: null,\n [IsolateKeys.Type]: 'UnitTest',\n };\n}\n"],"names":[],"mappings":";;;;;;EAAA,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CAAC,YAAY,GAAG,YAAY,CAAC,YAAY;GACtD,CAAC;EAEF;EACA;EACA;EACA;EACA;EACA;EACA;EAC6B,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,MAAM,CAC/D,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,QAAQ,CAAC,KACnB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;MACjB,CAAC,QAAQ,GAAG,GAAG;GAChB,CAAC,EACJ,EAAiC;;ECpCnB,SAAA,cAAc,CAAC,IAAA,GAA4B,EAAE,EAAA;MAC3D,OAAO;EACL,QAAA,QAAQ,EAAE,EAAE;UACZ,IAAI;EACJ,QAAA,GAAG,EAAE,IAAI;EACT,QAAA,IAAI,EAAE,EAAE;EACR,QAAA,MAAM,EAAE,IAAI;EACZ,QAAA,MAAM,EAAE,IAAI;EACZ,QAAA,CAAC,WAAW,CAAC,IAAI,GAAG,UAAU;OAC/B,CAAC;EACJ;;;;;;;;"}
1
+ {"version":3,"file":"test-utils.development.js","sources":["../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateStatus.ts","../../src/exports/test-utils.ts"],"sourcesContent":["export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\n Status = 'S',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","export enum IsolateStatus {\n PENDING = 'PENDING',\n DONE = 'DONE',\n INITIAL = 'INITIAL',\n}\n","import { TIsolate } from 'Isolate';\nimport { IsolateKeys } from 'IsolateKeys';\nimport { IsolateStatus } from 'IsolateStatus';\n\nexport function genTestIsolate(data: Record<string, any> = {}): TIsolate {\n return {\n children: [],\n data,\n key: null,\n keys: {},\n output: null,\n parent: null,\n status: IsolateStatus.INITIAL,\n [IsolateKeys.Type]: 'UnitTest',\n };\n}\n"],"names":[],"mappings":";;;;;;EAAA,IAAY,WAQX,CAAA;EARD,CAAA,UAAY,WAAW,EAAA;EACrB,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,OAAc,CAAA;EACd,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;EACb,IAAA,WAAA,CAAA,KAAA,CAAA,GAAA,KAAW,CAAA;EACX,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;EACjB,IAAA,WAAA,CAAA,MAAA,CAAA,GAAA,MAAa,CAAA;EACb,IAAA,WAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;EAC7B,IAAA,WAAA,CAAA,QAAA,CAAA,GAAA,QAAiB,CAAA;EACnB,CAAC,EARW,WAAW,KAAX,WAAW,GAQtB,EAAA,CAAA,CAAA,CAAA;EAED,IAAK,YAQJ,CAAA;EARD,CAAA,UAAK,YAAY,EAAA;EACf,IAAA,YAAA,CAAA,MAAA,CAAA,GAAA,GAAU,CAAA;EACV,IAAA,YAAA,CAAA,MAAA,CAAA,GAAA,GAAU,CAAA;EACV,IAAA,YAAA,CAAA,KAAA,CAAA,GAAA,GAAS,CAAA;EACT,IAAA,YAAA,CAAA,QAAA,CAAA,GAAA,GAAY,CAAA;EACZ,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AC,IAAA,GAA4B,EAAE,EAAA;MAC3D,OAAO;EACL,QAAA,QAAQ,EAAE,EAAE;UACZ,IAAI;EACJ,QAAA,GAAG,EAAE,IAAI;EACT,QAAA,IAAI,EAAE,EAAE;EACR,QAAA,MAAM,EAAE,IAAI;EACZ,QAAA,MAAM,EAAE,IAAI;UACZ,MAAM,EAAE,aAAa,CAAC,OAAO;EAC7B,QAAA,CAAC,WAAW,CAAC,IAAI,GAAG,UAAU;OAC/B,CAAC;EACJ;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["test-utils"]={})}(this,(function(e){"use strict";var t,n;!function(e){e.Type="$type",e.Keys="keys",e.Key="key",e.Parent="parent",e.Data="data",e.AllowReorder="allowReorder"}(t||(t={})),function(e){e.Type="$",e.Keys="K",e.Key="k",e.Parent="P",e.Data="D",e.AllowReorder="aR"}(n||(n={}));const o={[t.Type]:n.Type,[t.Keys]:n.Keys,[t.Parent]:n.Parent,[t.Data]:n.Data,[t.Key]:n.Key,[t.AllowReorder]:n.AllowReorder};Object.entries(o).reduce(((e,[t,n])=>Object.assign(e,{[n]:t})),{}),e.genTestIsolate=function(e={}){return{children:[],data:e,key:null,keys:{},output:null,parent:null,[t.Type]:"UnitTest"}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["test-utils"]={})}(this,(function(e){"use strict";var t,n;!function(e){e.Type="$type",e.Keys="keys",e.Key="key",e.Parent="parent",e.Data="data",e.AllowReorder="allowReorder",e.Status="status"}(t||(t={})),function(e){e.Type="$",e.Keys="K",e.Key="k",e.Parent="P",e.Data="D",e.AllowReorder="aR",e.Status="S"}(n||(n={}));const a={[t.Type]:n.Type,[t.Keys]:n.Keys,[t.Parent]:n.Parent,[t.Data]:n.Data,[t.Key]:n.Key,[t.AllowReorder]:n.AllowReorder,[t.Status]:n.Status};var s;Object.entries(a).reduce(((e,[t,n])=>Object.assign(e,{[n]:t})),{}),function(e){e.PENDING="PENDING",e.DONE="DONE",e.INITIAL="INITIAL"}(s||(s={})),e.genTestIsolate=function(e={}){return{children:[],data:e,key:null,keys:{},output:null,parent:null,status:s.INITIAL,[t.Type]:"UnitTest"}}}));
2
2
  //# sourceMappingURL=test-utils.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.production.js","sources":["../../src/Isolate/IsolateKeys.ts","../../src/exports/test-utils.ts"],"sourcesContent":["export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\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};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","import { TIsolate } from 'Isolate';\nimport { IsolateKeys } from 'IsolateKeys';\n\nexport function genTestIsolate(data: Record<string, any> = {}): TIsolate {\n return {\n children: [],\n data,\n key: null,\n keys: {},\n output: null,\n parent: null,\n [IsolateKeys.Type]: 'UnitTest',\n };\n}\n"],"names":["IsolateKeys","MinifiedKeys","KeyToMinified","Type","Keys","Parent","Data","Key","AllowReorder","Object","entries","reduce","acc","key","minified","assign","data","children","keys","output","parent"],"mappings":"qPAAA,IAAYA,EASPC,GATL,SAAYD,GACVA,EAAA,KAAA,QACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,OAAA,SACAA,EAAA,KAAA,OACAA,EAAA,aAAA,cACD,CAPD,CAAYA,IAAAA,EAOX,CAAA,IAED,SAAKC,GACHA,EAAA,KAAA,IACAA,EAAA,KAAA,IACAA,EAAA,IAAA,IACAA,EAAA,OAAA,IACAA,EAAA,KAAA,IACAA,EAAA,aAAA,IACD,CAPD,CAAKA,IAAAA,EAOJ,CAAA,IAEM,MAAMC,EAAgB,CAC3B,CAACF,EAAYG,MAAOF,EAAaE,KACjC,CAACH,EAAYI,MAAOH,EAAaG,KACjC,CAACJ,EAAYK,QAASJ,EAAaI,OACnC,CAACL,EAAYM,MAAOL,EAAaK,KACjC,CAACN,EAAYO,KAAMN,EAAaM,IAChC,CAACP,EAAYQ,cAAeP,EAAaO,cAUdC,OAAOC,QAAQR,GAAeS,QACzD,CAACC,GAAMC,EAAKC,KACVL,OAAOM,OAAOH,EAAK,CACjBE,CAACA,GAAWD,KAEhB,CAAiC,oBCpCnB,SAAeG,EAA4B,IACzD,MAAO,CACLC,SAAU,GACVD,OACAH,IAAK,KACLK,KAAM,CAAE,EACRC,OAAQ,KACRC,OAAQ,KACR,CAACpB,EAAYG,MAAO,WAExB"}
1
+ {"version":3,"file":"test-utils.production.js","sources":["../../src/Isolate/IsolateKeys.ts","../../src/Isolate/IsolateStatus.ts","../../src/exports/test-utils.ts"],"sourcesContent":["export enum IsolateKeys {\n Type = '$type',\n Keys = 'keys',\n Key = 'key',\n Parent = 'parent',\n Data = 'data',\n AllowReorder = 'allowReorder',\n Status = 'status',\n}\n\nenum MinifiedKeys {\n Type = '$',\n Keys = 'K',\n Key = 'k',\n Parent = 'P',\n Data = 'D',\n AllowReorder = 'aR',\n Status = 'S',\n}\n\nexport const KeyToMinified = {\n [IsolateKeys.Type]: MinifiedKeys.Type,\n [IsolateKeys.Keys]: MinifiedKeys.Keys,\n [IsolateKeys.Parent]: MinifiedKeys.Parent,\n [IsolateKeys.Data]: MinifiedKeys.Data,\n [IsolateKeys.Key]: MinifiedKeys.Key,\n [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,\n [IsolateKeys.Status]: MinifiedKeys.Status,\n};\n\n// This const is an object that looks like this:\n// {\n// '$': '$type',\n// 'K': 'keys',\n// 'P': 'parent',\n// ...\n// }\nexport const MinifiedToKey = Object.entries(KeyToMinified).reduce(\n (acc, [key, minified]) =>\n Object.assign(acc, {\n [minified]: key,\n }),\n {} as Record<string, IsolateKeys>\n);\n","export enum IsolateStatus {\n PENDING = 'PENDING',\n DONE = 'DONE',\n INITIAL = 'INITIAL',\n}\n","import { TIsolate } from 'Isolate';\nimport { IsolateKeys } from 'IsolateKeys';\nimport { IsolateStatus } from 'IsolateStatus';\n\nexport function genTestIsolate(data: Record<string, any> = {}): TIsolate {\n return {\n children: [],\n data,\n key: null,\n keys: {},\n output: null,\n parent: null,\n status: IsolateStatus.INITIAL,\n [IsolateKeys.Type]: 'UnitTest',\n };\n}\n"],"names":["IsolateKeys","MinifiedKeys","KeyToMinified","Type","Keys","Parent","Data","Key","AllowReorder","Status","IsolateStatus","Object","entries","reduce","acc","key","minified","assign","data","children","keys","output","parent","status","INITIAL"],"mappings":"qPAAA,IAAYA,EAUPC,GAVL,SAAYD,GACVA,EAAA,KAAA,QACAA,EAAA,KAAA,OACAA,EAAA,IAAA,MACAA,EAAA,OAAA,SACAA,EAAA,KAAA,OACAA,EAAA,aAAA,eACAA,EAAA,OAAA,QACD,CARD,CAAYA,IAAAA,EAQX,CAAA,IAED,SAAKC,GACHA,EAAA,KAAA,IACAA,EAAA,KAAA,IACAA,EAAA,IAAA,IACAA,EAAA,OAAA,IACAA,EAAA,KAAA,IACAA,EAAA,aAAA,KACAA,EAAA,OAAA,GACD,CARD,CAAKA,IAAAA,EAQJ,CAAA,IAEM,MAAMC,EAAgB,CAC3B,CAACF,EAAYG,MAAOF,EAAaE,KACjC,CAACH,EAAYI,MAAOH,EAAaG,KACjC,CAACJ,EAAYK,QAASJ,EAAaI,OACnC,CAACL,EAAYM,MAAOL,EAAaK,KACjC,CAACN,EAAYO,KAAMN,EAAaM,IAChC,CAACP,EAAYQ,cAAeP,EAAaO,aACzC,CAACR,EAAYS,QAASR,EAAaQ,QC3BrC,IAAYC,EDqCiBC,OAAOC,QAAQV,GAAeW,QACzD,CAACC,GAAMC,EAAKC,KACVL,OAAOM,OAAOH,EAAK,CACjBE,CAACA,GAAWD,KAEhB,CAAiC,GC1CnC,SAAYL,GACVA,EAAA,QAAA,UACAA,EAAA,KAAA,OACAA,EAAA,QAAA,SACD,CAJD,CAAYA,IAAAA,EAIX,CAAA,qBCAe,SAAeQ,EAA4B,IACzD,MAAO,CACLC,SAAU,GACVD,OACAH,IAAK,KACLK,KAAM,CAAE,EACRC,OAAQ,KACRC,OAAQ,KACRC,OAAQb,EAAcc,QACtB,CAACxB,EAAYG,MAAO,WAExB"}
@@ -38,85 +38,6 @@
38
38
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
39
39
  };
40
40
 
41
- var IsolateKeys;
42
- (function (IsolateKeys) {
43
- IsolateKeys["Type"] = "$type";
44
- IsolateKeys["Keys"] = "keys";
45
- IsolateKeys["Key"] = "key";
46
- IsolateKeys["Parent"] = "parent";
47
- IsolateKeys["Data"] = "data";
48
- IsolateKeys["AllowReorder"] = "allowReorder";
49
- })(IsolateKeys || (IsolateKeys = {}));
50
- var MinifiedKeys;
51
- (function (MinifiedKeys) {
52
- MinifiedKeys["Type"] = "$";
53
- MinifiedKeys["Keys"] = "K";
54
- MinifiedKeys["Key"] = "k";
55
- MinifiedKeys["Parent"] = "P";
56
- MinifiedKeys["Data"] = "D";
57
- MinifiedKeys["AllowReorder"] = "aR";
58
- })(MinifiedKeys || (MinifiedKeys = {}));
59
- const KeyToMinified = {
60
- [IsolateKeys.Type]: MinifiedKeys.Type,
61
- [IsolateKeys.Keys]: MinifiedKeys.Keys,
62
- [IsolateKeys.Parent]: MinifiedKeys.Parent,
63
- [IsolateKeys.Data]: MinifiedKeys.Data,
64
- [IsolateKeys.Key]: MinifiedKeys.Key,
65
- [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
66
- };
67
- // This const is an object that looks like this:
68
- // {
69
- // '$': '$type',
70
- // 'K': 'keys',
71
- // 'P': 'parent',
72
- // ...
73
- // }
74
- const MinifiedToKey = Object.entries(KeyToMinified).reduce((acc, [key, minified]) => Object.assign(acc, {
75
- [minified]: key,
76
- }), {});
77
-
78
- class IsolateMutator {
79
- static setParent(isolate, parent) {
80
- isolate.parent = parent;
81
- return isolate;
82
- }
83
- static saveOutput(isolate, output) {
84
- isolate.output = output;
85
- return isolate;
86
- }
87
- static setKey(isolate, key) {
88
- isolate.key = key;
89
- return isolate;
90
- }
91
- static addChild(isolate, child) {
92
- var _a;
93
- vestUtils.invariant(isolate);
94
- isolate.children = (_a = isolate.children) !== null && _a !== void 0 ? _a : [];
95
- isolate.children.push(child);
96
- IsolateMutator.setParent(child, isolate);
97
- }
98
- static removeChild(isolate, node) {
99
- var _a, _b;
100
- isolate.children =
101
- (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
102
- }
103
- static addChildKey(isolate, key, node) {
104
- var _a;
105
- vestUtils.invariant(isolate);
106
- isolate.keys = (_a = isolate.keys) !== null && _a !== void 0 ? _a : {};
107
- isolate.keys[key] = node;
108
- }
109
- static slice(isolate, at) {
110
- if (vestUtils.isNullish(isolate.children)) {
111
- return;
112
- }
113
- isolate.children.length = at;
114
- }
115
- static setData(isolate, data) {
116
- isolate.data = data;
117
- }
118
- }
119
-
120
41
  var ErrorStrings;
121
42
  (function (ErrorStrings) {
122
43
  ErrorStrings["NO_ACTIVE_ISOLATE"] = "Not within an active isolate";
@@ -164,22 +85,60 @@
164
85
  }
165
86
  }
166
87
 
167
- function isIsolateType(node, type) {
168
- return (node === null || node === void 0 ? void 0 : node[IsolateKeys.Type]) === type;
169
- }
170
- function isSameIsolateType(a, b) {
171
- return isIsolateType(a, b[IsolateKeys.Type]);
172
- }
173
- function isSameIsolateIdentity(a, b) {
174
- return Object.is(a, b) || (isSameIsolateType(a, b) && a.key === b.key);
175
- }
88
+ exports.IsolateStatus = void 0;
89
+ (function (IsolateStatus) {
90
+ IsolateStatus["PENDING"] = "PENDING";
91
+ IsolateStatus["DONE"] = "DONE";
92
+ IsolateStatus["INITIAL"] = "INITIAL";
93
+ })(exports.IsolateStatus || (exports.IsolateStatus = {}));
176
94
 
177
- var IsolateSelectors = /*#__PURE__*/Object.freeze({
178
- __proto__: null,
179
- isIsolateType: isIsolateType,
180
- isSameIsolateIdentity: isSameIsolateIdentity,
181
- isSameIsolateType: isSameIsolateType
182
- });
95
+ class IsolateMutator {
96
+ static setParent(isolate, parent) {
97
+ isolate.parent = parent;
98
+ return isolate;
99
+ }
100
+ static saveOutput(isolate, output) {
101
+ isolate.output = output;
102
+ return isolate;
103
+ }
104
+ static setKey(isolate, key) {
105
+ isolate.key = key;
106
+ return isolate;
107
+ }
108
+ static addChild(isolate, child) {
109
+ var _a;
110
+ vestUtils.invariant(isolate);
111
+ isolate.children = (_a = isolate.children) !== null && _a !== void 0 ? _a : [];
112
+ isolate.children.push(child);
113
+ IsolateMutator.setParent(child, isolate);
114
+ }
115
+ static removeChild(isolate, node) {
116
+ var _a, _b;
117
+ isolate.children =
118
+ (_b = (_a = isolate.children) === null || _a === void 0 ? void 0 : _a.filter(child => child !== node)) !== null && _b !== void 0 ? _b : null;
119
+ }
120
+ static addChildKey(isolate, key, node) {
121
+ var _a;
122
+ vestUtils.invariant(isolate);
123
+ isolate.keys = (_a = isolate.keys) !== null && _a !== void 0 ? _a : {};
124
+ isolate.keys[key] = node;
125
+ }
126
+ static slice(isolate, at) {
127
+ if (vestUtils.isNullish(isolate.children)) {
128
+ return;
129
+ }
130
+ isolate.children.length = at;
131
+ }
132
+ static setData(isolate, data) {
133
+ isolate.data = data;
134
+ }
135
+ static setPending(isolate) {
136
+ isolate.status = exports.IsolateStatus.PENDING;
137
+ }
138
+ static setDone(isolate) {
139
+ isolate.status = exports.IsolateStatus.DONE;
140
+ }
141
+ }
183
142
 
184
143
  const PersistedContext = context.createCascade((stateRef, parentContext) => {
185
144
  if (parentContext) {
@@ -322,6 +281,89 @@
322
281
  useSetHistory(root);
323
282
  }
324
283
 
284
+ function useBus() {
285
+ return useX().stateRef.Bus;
286
+ }
287
+ /*
288
+ Returns an emitter, but it also has a shortcut for emitting an event immediately
289
+ by passing an event name.
290
+ */
291
+ function useEmit(event, data) {
292
+ const emit = useBus().emit;
293
+ if (!vestUtils.isNullish(event)) {
294
+ emit(event, data);
295
+ }
296
+ return persist(emit);
297
+ }
298
+ function usePrepareEmitter(event) {
299
+ const emit = useEmit();
300
+ return (arg) => emit(event, arg);
301
+ }
302
+
303
+ var Bus = /*#__PURE__*/Object.freeze({
304
+ __proto__: null,
305
+ useBus: useBus,
306
+ useEmit: useEmit,
307
+ usePrepareEmitter: usePrepareEmitter
308
+ });
309
+
310
+ var IsolateKeys;
311
+ (function (IsolateKeys) {
312
+ IsolateKeys["Type"] = "$type";
313
+ IsolateKeys["Keys"] = "keys";
314
+ IsolateKeys["Key"] = "key";
315
+ IsolateKeys["Parent"] = "parent";
316
+ IsolateKeys["Data"] = "data";
317
+ IsolateKeys["AllowReorder"] = "allowReorder";
318
+ IsolateKeys["Status"] = "status";
319
+ })(IsolateKeys || (IsolateKeys = {}));
320
+ var MinifiedKeys;
321
+ (function (MinifiedKeys) {
322
+ MinifiedKeys["Type"] = "$";
323
+ MinifiedKeys["Keys"] = "K";
324
+ MinifiedKeys["Key"] = "k";
325
+ MinifiedKeys["Parent"] = "P";
326
+ MinifiedKeys["Data"] = "D";
327
+ MinifiedKeys["AllowReorder"] = "aR";
328
+ MinifiedKeys["Status"] = "S";
329
+ })(MinifiedKeys || (MinifiedKeys = {}));
330
+ const KeyToMinified = {
331
+ [IsolateKeys.Type]: MinifiedKeys.Type,
332
+ [IsolateKeys.Keys]: MinifiedKeys.Keys,
333
+ [IsolateKeys.Parent]: MinifiedKeys.Parent,
334
+ [IsolateKeys.Data]: MinifiedKeys.Data,
335
+ [IsolateKeys.Key]: MinifiedKeys.Key,
336
+ [IsolateKeys.AllowReorder]: MinifiedKeys.AllowReorder,
337
+ [IsolateKeys.Status]: MinifiedKeys.Status,
338
+ };
339
+ // This const is an object that looks like this:
340
+ // {
341
+ // '$': '$type',
342
+ // 'K': 'keys',
343
+ // 'P': 'parent',
344
+ // ...
345
+ // }
346
+ const MinifiedToKey = Object.entries(KeyToMinified).reduce((acc, [key, minified]) => Object.assign(acc, {
347
+ [minified]: key,
348
+ }), {});
349
+
350
+ function isIsolateType(node, type) {
351
+ return (node === null || node === void 0 ? void 0 : node[IsolateKeys.Type]) === type;
352
+ }
353
+ function isSameIsolateType(a, b) {
354
+ return isIsolateType(a, b[IsolateKeys.Type]);
355
+ }
356
+ function isSameIsolateIdentity(a, b) {
357
+ return Object.is(a, b) || (isSameIsolateType(a, b) && a.key === b.key);
358
+ }
359
+
360
+ var IsolateSelectors = /*#__PURE__*/Object.freeze({
361
+ __proto__: null,
362
+ isIsolateType: isIsolateType,
363
+ isSameIsolateIdentity: isSameIsolateIdentity,
364
+ isSameIsolateType: isSameIsolateType
365
+ });
366
+
325
367
  function BaseReconciler(currentNode, historyNode) {
326
368
  if (vestUtils.isNullish(historyNode)) {
327
369
  return currentNode;
@@ -392,6 +434,10 @@
392
434
  IsolateMutator.slice(historyNode, IsolateInspector.cursor(currentNode));
393
435
  }
394
436
 
437
+ const RuntimeEvents = {
438
+ ASYNC_ISOLATE_DONE: 'ASYNC_ISOLATE_DONE',
439
+ };
440
+
395
441
  class Isolate {
396
442
  static create(type, callback, payload = undefined, key) {
397
443
  const parent = useIsolate();
@@ -420,17 +466,24 @@
420
466
  */
421
467
  function useRunAsNew(localHistoryNode, current, callback) {
422
468
  const runtimeRoot = useRuntimeRoot();
469
+ const emit = useEmit();
423
470
  // We're creating a new child isolate context where the local history node
424
471
  // is the current history node, thus advancing the history cursor.
425
472
  const output = Run(Object.assign({ historyNode: localHistoryNode, runtimeNode: current }, (!runtimeRoot && { runtimeRoot: current })), () => {
426
473
  const output = callback(current);
427
474
  if (vestUtils.isPromise(output)) {
475
+ IsolateMutator.setPending(current);
428
476
  output.then(iso => {
429
477
  if (Isolate.isIsolate(iso)) {
430
478
  IsolateMutator.addChild(current, iso);
431
479
  }
480
+ IsolateMutator.setDone(current);
481
+ emit(RuntimeEvents.ASYNC_ISOLATE_DONE, current);
432
482
  });
433
483
  }
484
+ else {
485
+ IsolateMutator.setDone(current);
486
+ }
434
487
  return output;
435
488
  });
436
489
  current.output = output;
@@ -444,6 +497,7 @@
444
497
  [IsolateKeys.Parent]: null,
445
498
  [IsolateKeys.Type]: type,
446
499
  [IsolateKeys.Data]: data,
500
+ [IsolateKeys.Status]: exports.IsolateStatus.INITIAL,
447
501
  children: null,
448
502
  key,
449
503
  output: null,
@@ -581,32 +635,6 @@
581
635
  walk: walk
582
636
  });
583
637
 
584
- function useBus() {
585
- return useX().stateRef.Bus;
586
- }
587
- /*
588
- Returns an emitter, but it also has a shortcut for emitting an event immediately
589
- by passing an event name.
590
- */
591
- function useEmit(event, data) {
592
- const emit = useBus().emit;
593
- if (!vestUtils.isNullish(event)) {
594
- emit(event, data);
595
- }
596
- return persist(emit);
597
- }
598
- function usePrepareEmitter(event) {
599
- const emit = useEmit();
600
- return (arg) => emit(event, arg);
601
- }
602
-
603
- var Bus = /*#__PURE__*/Object.freeze({
604
- __proto__: null,
605
- useBus: useBus,
606
- useEmit: useEmit,
607
- usePrepareEmitter: usePrepareEmitter
608
- });
609
-
610
638
  class IsolateSerializer {
611
639
  // eslint-disable-next-line max-statements, complexity
612
640
  static deserialize(node) {