vestjs-runtime 1.6.0 → 1.7.0

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 (136) hide show
  1. package/IsolateSerializer/package.json +8 -12
  2. package/README.md +1 -3
  3. package/dist/cjs/IsolateSerializer.development.js +135 -0
  4. package/dist/cjs/IsolateSerializer.development.js.map +1 -0
  5. package/dist/cjs/IsolateSerializer.js +6 -0
  6. package/dist/cjs/IsolateSerializer.production.js +2 -0
  7. package/dist/cjs/IsolateSerializer.production.js.map +1 -0
  8. package/dist/cjs/package.json +1 -0
  9. package/dist/cjs/test-utils.development.js +61 -0
  10. package/dist/cjs/test-utils.development.js.map +1 -0
  11. package/dist/cjs/test-utils.js +6 -0
  12. package/dist/cjs/test-utils.production.js +2 -0
  13. package/dist/cjs/test-utils.production.js.map +1 -0
  14. package/dist/cjs/vestjs-runtime.development.js +686 -0
  15. package/dist/cjs/vestjs-runtime.development.js.map +1 -0
  16. package/dist/cjs/vestjs-runtime.js +6 -0
  17. package/dist/cjs/vestjs-runtime.production.js +2 -0
  18. package/dist/cjs/vestjs-runtime.production.js.map +1 -0
  19. package/dist/es/IsolateSerializer.development.js +133 -0
  20. package/dist/es/IsolateSerializer.development.js.map +1 -0
  21. package/dist/es/IsolateSerializer.production.js +2 -0
  22. package/dist/es/IsolateSerializer.production.js.map +1 -0
  23. package/dist/es/package.json +1 -0
  24. package/dist/es/test-utils.development.js +59 -0
  25. package/dist/es/test-utils.development.js.map +1 -0
  26. package/dist/es/test-utils.production.js +2 -0
  27. package/dist/es/test-utils.production.js.map +1 -0
  28. package/dist/es/vestjs-runtime.development.js +675 -0
  29. package/dist/es/vestjs-runtime.development.js.map +1 -0
  30. package/dist/es/vestjs-runtime.production.js +2 -0
  31. package/dist/es/vestjs-runtime.production.js.map +1 -0
  32. package/dist/umd/IsolateSerializer.development.js +138 -0
  33. package/dist/umd/IsolateSerializer.development.js.map +1 -0
  34. package/dist/umd/IsolateSerializer.production.js +2 -0
  35. package/dist/umd/IsolateSerializer.production.js.map +1 -0
  36. package/dist/umd/test-utils.development.js +67 -0
  37. package/dist/umd/test-utils.development.js.map +1 -0
  38. package/dist/umd/test-utils.production.js +2 -0
  39. package/dist/umd/test-utils.production.js.map +1 -0
  40. package/dist/umd/vestjs-runtime.development.js +688 -0
  41. package/dist/umd/vestjs-runtime.development.js.map +1 -0
  42. package/dist/umd/vestjs-runtime.production.js +2 -0
  43. package/dist/umd/vestjs-runtime.production.js.map +1 -0
  44. package/package.json +87 -42
  45. package/test-utils/package.json +8 -12
  46. package/types/IsolateSerializer.d.ts +42 -0
  47. package/types/IsolateSerializer.d.ts.map +1 -0
  48. package/types/test-utils.d.ts +37 -0
  49. package/types/test-utils.d.ts.map +1 -0
  50. package/types/vestjs-runtime.d.ts +257 -351
  51. package/types/vestjs-runtime.d.ts.map +1 -0
  52. package/vitest.config.ts +17 -9
  53. package/dist/IsolateKeys-B21aPuBk.mjs +0 -23
  54. package/dist/IsolateKeys-B21aPuBk.mjs.map +0 -1
  55. package/dist/IsolateKeys-CCvALpZC.cjs +0 -35
  56. package/dist/IsolateKeys-CCvALpZC.cjs.map +0 -1
  57. package/dist/IsolateSerializer-B1hE3gmT.mjs +0 -1004
  58. package/dist/IsolateSerializer-B1hE3gmT.mjs.map +0 -1
  59. package/dist/IsolateSerializer-pbEf5gB2.cjs +0 -1121
  60. package/dist/IsolateSerializer-pbEf5gB2.cjs.map +0 -1
  61. package/dist/chunk-CLMFDpHK.mjs +0 -18
  62. package/dist/exports/IsolateSerializer.cjs +0 -4
  63. package/dist/exports/IsolateSerializer.mjs +0 -4
  64. package/dist/exports/test-utils.cjs +0 -21
  65. package/dist/exports/test-utils.cjs.map +0 -1
  66. package/dist/exports/test-utils.mjs +0 -21
  67. package/dist/exports/test-utils.mjs.map +0 -1
  68. package/dist/vestjs-runtime.cjs +0 -153
  69. package/dist/vestjs-runtime.cjs.map +0 -1
  70. package/dist/vestjs-runtime.mjs +0 -117
  71. package/dist/vestjs-runtime.mjs.map +0 -1
  72. package/docs/IsolateRegistry.docs.md +0 -146
  73. package/docs/Isolates.md +0 -97
  74. package/src/Bus.ts +0 -46
  75. package/src/Isolate/Isolate.ts +0 -163
  76. package/src/Isolate/IsolateFocused.ts +0 -93
  77. package/src/Isolate/IsolateIndexer.ts +0 -42
  78. package/src/Isolate/IsolateInspector.ts +0 -93
  79. package/src/Isolate/IsolateKeys.ts +0 -18
  80. package/src/Isolate/IsolateMutator.ts +0 -165
  81. package/src/Isolate/IsolateRegistry.ts +0 -176
  82. package/src/Isolate/IsolateReorderable.ts +0 -11
  83. package/src/Isolate/IsolateSelectors.ts +0 -25
  84. package/src/Isolate/IsolateStateMachine.ts +0 -30
  85. package/src/Isolate/IsolateStatus.ts +0 -8
  86. package/src/Isolate/IsolateTransient.ts +0 -27
  87. package/src/Isolate/IsolateTypes.ts +0 -33
  88. package/src/Isolate/__tests__/Isolate.test.ts +0 -123
  89. package/src/Isolate/__tests__/IsolateFocused.test.ts +0 -199
  90. package/src/Isolate/__tests__/IsolateInspector.test.ts +0 -136
  91. package/src/Isolate/__tests__/IsolateMutator.test.ts +0 -164
  92. package/src/Isolate/__tests__/IsolatePropagation.test.ts +0 -170
  93. package/src/Isolate/__tests__/IsolateReorderable.test.ts +0 -111
  94. package/src/Isolate/__tests__/IsolateSelectors.test.ts +0 -72
  95. package/src/Isolate/__tests__/IsolateStatus.test.ts +0 -44
  96. package/src/Isolate/__tests__/IsolateTransient.test.ts +0 -58
  97. package/src/Isolate/__tests__/__snapshots__/asyncIsolate.test.ts.snap +0 -71
  98. package/src/Isolate/__tests__/asyncIsolate.test.ts +0 -85
  99. package/src/IsolateWalker.ts +0 -359
  100. package/src/Orchestrator/RuntimeStates.ts +0 -4
  101. package/src/Reconciler.ts +0 -178
  102. package/src/RuntimeEvents.ts +0 -9
  103. package/src/VestRuntime.ts +0 -421
  104. package/src/__tests__/Bus.test.ts +0 -57
  105. package/src/__tests__/IsolateWalker.iterative.test.ts +0 -77
  106. package/src/__tests__/IsolateWalker.test.ts +0 -418
  107. package/src/__tests__/Reconciler.test.ts +0 -193
  108. package/src/__tests__/Reconciler.transient.test.ts +0 -166
  109. package/src/__tests__/VestRuntime.test.ts +0 -212
  110. package/src/__tests__/VestRuntimeStateMachine.test.ts +0 -36
  111. package/src/__tests__/vestjs-runtime.test.ts +0 -19
  112. package/src/errors/ErrorStrings.ts +0 -6
  113. package/src/exports/IsolateSerializer.ts +0 -131
  114. package/src/exports/__tests__/IsolateSerializer.test.ts +0 -334
  115. package/src/exports/__tests__/IsolateSerializer.transient.test.ts +0 -101
  116. package/src/exports/__tests__/__snapshots__/IsolateSerializer.test.ts.snap +0 -5
  117. package/src/exports/test-utils.ts +0 -17
  118. package/src/vestjs-runtime.ts +0 -28
  119. package/types/Isolate-DChR7h5K.d.mts +0 -58
  120. package/types/Isolate-DChR7h5K.d.mts.map +0 -1
  121. package/types/Isolate-HYIh82M8.d.cts +0 -58
  122. package/types/Isolate-HYIh82M8.d.cts.map +0 -1
  123. package/types/IsolateSerializer-BCg01Px5.d.mts +0 -13
  124. package/types/IsolateSerializer-BCg01Px5.d.mts.map +0 -1
  125. package/types/IsolateSerializer-CQpP6A4m.d.cts +0 -13
  126. package/types/IsolateSerializer-CQpP6A4m.d.cts.map +0 -1
  127. package/types/exports/IsolateSerializer.d.cts +0 -3
  128. package/types/exports/IsolateSerializer.d.mts +0 -3
  129. package/types/exports/test-utils.d.cts +0 -7
  130. package/types/exports/test-utils.d.cts.map +0 -1
  131. package/types/exports/test-utils.d.mts +0 -7
  132. package/types/exports/test-utils.d.mts.map +0 -1
  133. package/types/vestjs-runtime.d.cts +0 -372
  134. package/types/vestjs-runtime.d.cts.map +0 -1
  135. package/types/vestjs-runtime.d.mts +0 -370
  136. package/types/vestjs-runtime.d.mts.map +0 -1
@@ -1,165 +0,0 @@
1
- import {
2
- Nullable,
3
- invariant,
4
- isNullish,
5
- makeResult,
6
- Result,
7
- isFailure,
8
- } from 'vest-utils';
9
-
10
- import { RuntimeApi } from '../VestRuntime';
11
-
12
- import { IsolateStateMachine } from './IsolateStateMachine';
13
- import { IsolateStatus } from './IsolateStatus';
14
- import { IsolateInspector } from './IsolateInspector';
15
-
16
- import { TIsolate } from './Isolate';
17
-
18
- function bubbleUpPending(isolate: Nullable<TIsolate>): void {
19
- if (isNullish(isolate)) {
20
- return;
21
- }
22
- // If parent is already HAS_PENDING, we can stop the upward traversal.
23
- if (IsolateInspector.isHasPending(isolate)) {
24
- return;
25
- }
26
-
27
- const result = IsolateMutator.setHasPending(isolate);
28
-
29
- if (isFailure(result)) {
30
- return;
31
- }
32
-
33
- bubbleUpPending(isolate.parent);
34
- }
35
-
36
- function bubbleUpDone(isolate: Nullable<TIsolate>): void {
37
- if (isNullish(isolate)) {
38
- return;
39
- }
40
-
41
- if (!IsolateInspector.isHasPending(isolate)) {
42
- return;
43
- }
44
-
45
- const result = IsolateMutator.setStatus(isolate, IsolateStatus.DONE, isolate);
46
-
47
- if (isFailure(result)) {
48
- return;
49
- }
50
-
51
- bubbleUpDone(isolate.parent);
52
- }
53
-
54
- export class IsolateMutator {
55
- static setParent(isolate: TIsolate, parent: Nullable<TIsolate>): TIsolate {
56
- isolate.parent = parent;
57
- return isolate;
58
- }
59
-
60
- static saveOutput(isolate: TIsolate, output: any): TIsolate {
61
- isolate.output = output;
62
- return isolate;
63
- }
64
-
65
- static setKey(isolate: TIsolate, key: Nullable<string>): TIsolate {
66
- isolate.key = key;
67
- return isolate;
68
- }
69
-
70
- static addChild(isolate: TIsolate, child: TIsolate): void {
71
- invariant(isolate);
72
-
73
- isolate.children = isolate.children ?? [];
74
-
75
- isolate.children.push(child);
76
- IsolateMutator.setParent(child, isolate);
77
-
78
- if (IsolateInspector.hasPending(child)) {
79
- bubbleUpPending(isolate);
80
- }
81
- }
82
-
83
- static removeChild(isolate: TIsolate, node: TIsolate): void {
84
- isolate.children =
85
- isolate.children?.filter(child => child !== node) ?? null;
86
- }
87
-
88
- static addChildKey(isolate: TIsolate, key: string, node: TIsolate): void {
89
- invariant(isolate);
90
-
91
- isolate.keys = isolate.keys ?? {};
92
-
93
- isolate.keys[key] = node;
94
- }
95
-
96
- static slice(isolate: TIsolate, at: number): void {
97
- if (isNullish(isolate.children)) {
98
- return;
99
- }
100
- isolate.children.length = at;
101
- }
102
-
103
- static setData(isolate: TIsolate, data: any): void {
104
- isolate.data = data;
105
- }
106
-
107
- static abort(isolate: TIsolate, reason?: string): void {
108
- if (isNullish(isolate.abortController)) {
109
- return;
110
- }
111
- isolate.abortController.abort(reason);
112
- }
113
-
114
- static setStatus(
115
- isolate: TIsolate,
116
- status: IsolateStatus,
117
- payload?: any,
118
- ): Result<IsolateStatus, string> {
119
- if (isolate.status === status) {
120
- return makeResult.Err(`Isolate status is already ${status}`);
121
- }
122
-
123
- isolate.status = IsolateStateMachine.staticTransition(
124
- isolate.status ?? IsolateStatus.INITIAL,
125
- status,
126
- payload,
127
- ) as IsolateStatus;
128
-
129
- return makeResult.Ok(isolate.status);
130
- }
131
-
132
- static setPending(isolate: TIsolate): void {
133
- const result = IsolateMutator.setStatus(isolate, IsolateStatus.PENDING);
134
-
135
- if (isFailure(result)) {
136
- return;
137
- }
138
-
139
- RuntimeApi.registerPending(isolate);
140
-
141
- // Bubble up the HAS_PENDING status to all ancestors.
142
- bubbleUpPending(isolate.parent);
143
- }
144
-
145
- static setHasPending(isolate: TIsolate): Result<IsolateStatus, string> {
146
- return IsolateMutator.setStatus(isolate, IsolateStatus.HAS_PENDING);
147
- }
148
-
149
- static setDone(isolate: TIsolate): void {
150
- const result = IsolateMutator.setStatus(
151
- isolate,
152
- IsolateStatus.DONE,
153
- isolate,
154
- );
155
-
156
- if (isFailure(result)) {
157
- return;
158
- }
159
-
160
- // Bubble up the DONE status to ancestors if no other children are pending.
161
- bubbleUpDone(isolate.parent);
162
-
163
- RuntimeApi.removePending(isolate);
164
- }
165
- }
@@ -1,176 +0,0 @@
1
- import { Nullable, isEmptySet, isNotEmptySet } from 'vest-utils';
2
-
3
- import { useAvailableRoot } from '../VestRuntime';
4
- import { TIsolate } from './Isolate';
5
-
6
- /**
7
- * A registry index, mapping group keys (like field names) to sets of isolates.
8
- */
9
- export type RegistryIndex = Map<string, Set<TIsolate>>;
10
-
11
- /**
12
- * Configuration for a registry category.
13
- */
14
- export type RegistryCategoryConfig = {
15
- predicate: (isolate: TIsolate) => boolean;
16
- getKey: (isolate: TIsolate) => string;
17
- };
18
-
19
- /**
20
- * Updates the registration of an isolate in all relevant indices based on provided predicates.
21
- *
22
- * @param isolate - The isolate node to update.
23
- * @param predicates - A record of category keys and their corresponding predicate configurations.
24
- */
25
- export function useUpdateRegistry(
26
- isolate: TIsolate,
27
- predicates: Record<string, RegistryCategoryConfig>,
28
- ) {
29
- const root = useGetAvailableRoot();
30
-
31
- if (!root) return;
32
-
33
- for (const key in predicates) {
34
- useUpdateCategoryInRegistry(root, key, predicates[key], isolate);
35
- }
36
- }
37
-
38
- /**
39
- * Retrieves isolates from the registry based on a category and an optional key.
40
- */
41
- export function useGetFromRegistry(
42
- category: string,
43
- key?: string,
44
- ): Set<TIsolate> {
45
- const root = useGetAvailableRoot();
46
- if (!root) return new Set();
47
-
48
- const index = useEnsureRegistryIndex(root, category);
49
-
50
- if (key) {
51
- return index.get(key) ?? new Set();
52
- }
53
-
54
- const allNodes = new Set<TIsolate>();
55
- index.forEach(set => set.forEach(node => allNodes.add(node)));
56
- return allNodes;
57
- }
58
-
59
- /**
60
- * Checks if the registry contains any isolates for a given category and optional key.
61
- */
62
- export function useHasFromRegistry(category: string, key?: string): boolean {
63
- return isNotEmptySet(useGetFromRegistry(category, key));
64
- }
65
-
66
- /**
67
- * Removes all entries for a specific key from the registry.
68
- */
69
- export function useRemoveFieldFromRegistry(key: string): void {
70
- const root = useGetAvailableRoot();
71
-
72
- if (!root) return;
73
-
74
- useForEachRegistryIndex(root, index => index.delete(key));
75
- }
76
-
77
- /**
78
- * Clears all registry entries from the root isolate.
79
- */
80
- export function useClearRegistry(root: TIsolate) {
81
- useForEachRegistryIndex(root, index => index.clear());
82
- }
83
-
84
- // Internal Helpers
85
-
86
- const GENERIC_REGISTRY_KEY = '_generic';
87
-
88
- function useGetAvailableRoot(): TIsolate | undefined {
89
- try {
90
- return useAvailableRoot();
91
- } catch {
92
- return undefined;
93
- }
94
- }
95
-
96
- function useUpdateCategoryInRegistry(
97
- root: TIsolate,
98
- category: string,
99
- config: RegistryCategoryConfig,
100
- isolate: TIsolate,
101
- ) {
102
- const isMatching = config.predicate(isolate);
103
- const index = useEnsureRegistryIndex(root, category);
104
- const key = config.getKey(isolate);
105
-
106
- if (isMatching) {
107
- useAddNodeToRegistryIndex(index, key, isolate);
108
- } else {
109
- useRemoveNodeFromRegistryIndex(index, key, isolate);
110
- }
111
- }
112
-
113
- function useEnsureRegistryIndex(
114
- root: TIsolate,
115
- category: string,
116
- ): RegistryIndex {
117
- const registryKey = `registry_${category}`;
118
-
119
- if (!root.data[registryKey]) {
120
- useDefineEnumerable(root.data, registryKey, new Map());
121
- }
122
-
123
- return root.data[registryKey];
124
- }
125
-
126
- function useForEachRegistryIndex(
127
- root: TIsolate,
128
- callback: (index: RegistryIndex) => void,
129
- ) {
130
- for (const key in root.data) {
131
- if (key.startsWith('registry_')) {
132
- callback(root.data[key]);
133
- }
134
- }
135
- }
136
-
137
- function useAddNodeToRegistryIndex(
138
- index: RegistryIndex,
139
- key: Nullable<string>,
140
- isolate: TIsolate,
141
- ) {
142
- const indexKey = key ?? GENERIC_REGISTRY_KEY;
143
- let entry = index.get(indexKey);
144
-
145
- if (!entry) {
146
- entry = new Set();
147
- index.set(indexKey, entry);
148
- }
149
-
150
- entry.add(isolate);
151
- }
152
-
153
- function useRemoveNodeFromRegistryIndex(
154
- index: RegistryIndex,
155
- key: Nullable<string>,
156
- isolate: TIsolate,
157
- ) {
158
- const indexKey = key ?? GENERIC_REGISTRY_KEY;
159
- const entry = index.get(indexKey);
160
-
161
- if (entry) {
162
- entry.delete(isolate);
163
- if (isEmptySet(entry)) {
164
- index.delete(indexKey);
165
- }
166
- }
167
- }
168
-
169
- function useDefineEnumerable(obj: any, key: string, value: any) {
170
- Object.defineProperty(obj, key, {
171
- configurable: true,
172
- enumerable: true,
173
- value,
174
- writable: true,
175
- });
176
- }
@@ -1,11 +0,0 @@
1
- import { CB } from 'vest-utils';
2
-
3
- import { Isolate } from './Isolate';
4
-
5
- export function IsolateReorderable(
6
- callback: CB,
7
- type = 'Reorderable',
8
- payload: Record<string, any> = {},
9
- ) {
10
- return Isolate.create(type, callback, { ...payload, allowReorder: true });
11
- }
@@ -1,25 +0,0 @@
1
- import { Maybe } from 'vest-utils';
2
-
3
- import { TIsolate } from './Isolate';
4
- import { IsolateKeys } from './IsolateKeys';
5
-
6
- export function isIsolateType<I extends TIsolate>(
7
- node: Maybe<TIsolate>,
8
- type: string,
9
- ): node is I {
10
- return node?.[IsolateKeys.Type] === type;
11
- }
12
-
13
- export function isSameIsolateType<A extends TIsolate, B extends TIsolate>(
14
- a: A,
15
- b: B,
16
- ): boolean {
17
- return isIsolateType(a, b[IsolateKeys.Type]);
18
- }
19
-
20
- export function isSameIsolateIdentity<A extends TIsolate, B extends TIsolate>(
21
- a: A,
22
- b: B,
23
- ): boolean {
24
- return Object.is(a, b) || (isSameIsolateType(a, b) && a.key === b.key);
25
- }
@@ -1,30 +0,0 @@
1
- import { StateMachine, TStateMachine } from 'vest-utils';
2
-
3
- import { TIsolate } from './Isolate';
4
- import { IsolateInspector } from './IsolateInspector';
5
-
6
- import { IsolateStatus } from './IsolateStatus';
7
-
8
- const machine: TStateMachine<IsolateStatus> = {
9
- initial: IsolateStatus.INITIAL,
10
- states: {
11
- [IsolateStatus.DONE]: {},
12
- [IsolateStatus.INITIAL]: {
13
- [IsolateStatus.PENDING]: IsolateStatus.PENDING,
14
- [IsolateStatus.HAS_PENDING]: IsolateStatus.HAS_PENDING,
15
- [IsolateStatus.DONE]: IsolateStatus.DONE,
16
- },
17
- [IsolateStatus.PENDING]: {
18
- [IsolateStatus.DONE]: IsolateStatus.DONE,
19
- },
20
- [IsolateStatus.HAS_PENDING]: {
21
- [IsolateStatus.DONE]: [
22
- IsolateStatus.DONE,
23
- (isolate: TIsolate) => !IsolateInspector.hasActiveChildren(isolate),
24
- ],
25
- [IsolateStatus.PENDING]: IsolateStatus.PENDING,
26
- },
27
- },
28
- };
29
-
30
- export const IsolateStateMachine = StateMachine(machine);
@@ -1,8 +0,0 @@
1
- export const IsolateStatus = {
2
- DONE: 'DONE',
3
- HAS_PENDING: 'HAS_PENDING',
4
- INITIAL: 'INITIAL',
5
- PENDING: 'PENDING',
6
- } as const;
7
-
8
- export type IsolateStatus = (typeof IsolateStatus)[keyof typeof IsolateStatus];
@@ -1,27 +0,0 @@
1
- import { CB } from 'vest-utils';
2
-
3
- import { Isolate } from './Isolate';
4
- import type { IsolatePayload, TIsolate } from './IsolateTypes';
5
-
6
- /**
7
- * Creates a transient isolate.
8
- *
9
- * Transient isolates are isolates that:
10
- * 1. Do not persist in the history tree.
11
- * 2. Are not reconciled with previous runs.
12
- * 3. Do not appear in the serialized suite dump.
13
- * 4. Do not interfere with the index of their siblings (they are skipped by the reconciler).
14
- *
15
- * This is useful for "structural" isolates that are used for control flow or grouping
16
- * but do not hold state that needs to be preserved between runs, such as `focused` (skip/only) isolates.
17
- */
18
- export function IsolateTransient<Payload extends IsolatePayload>(
19
- callback: CB,
20
- type = 'Transient',
21
- payload: Payload = {} as Payload,
22
- ): TIsolate<Payload> {
23
- return Isolate.create<Payload>(type, callback, {
24
- ...payload,
25
- transient: true,
26
- });
27
- }
@@ -1,33 +0,0 @@
1
- import { Nullable } from 'vest-utils';
2
-
3
- import { IsolateKeys } from './IsolateKeys';
4
- import { IsolateStatus } from './IsolateStatus';
5
-
6
- export type IsolateKey = Nullable<string>;
7
-
8
- export type TIsolate<P extends IsolatePayload = IsolatePayload> = {
9
- [IsolateKeys.AllowReorder]?: boolean;
10
- [IsolateKeys.Transient]?: boolean;
11
- [IsolateKeys.Parent]: Nullable<TIsolate>;
12
- [IsolateKeys.Type]: string;
13
- [IsolateKeys.Keys]: Nullable<Record<string, TIsolate>>;
14
- [IsolateKeys.Data]: DataOnly<P>;
15
- [IsolateKeys.Status]: IsolateStatus;
16
- [IsolateKeys.AbortController]: Nullable<AbortController>;
17
- children: Nullable<TIsolate[]>;
18
- key: IsolateKey;
19
- output: any;
20
- } & UsedFeaturesOnly<P>;
21
-
22
- type DataOnly<P extends IsolatePayload> = Omit<P, keyof IsolateFeatures>;
23
- type UsedFeaturesOnly<P extends IsolatePayload> = Pick<
24
- P,
25
- keyof IsolateFeatures
26
- >;
27
-
28
- export type IsolatePayload<P = Record<string, any>> = P & IsolateFeatures;
29
- export type IsolateFeatures = {
30
- [IsolateKeys.AllowReorder]?: boolean;
31
- [IsolateKeys.Transient]?: boolean;
32
- [IsolateKeys.Status]?: IsolateStatus;
33
- };
@@ -1,123 +0,0 @@
1
- import { CB } from 'vest-utils';
2
- import { describe, it, expect, beforeEach, vi } from 'vitest';
3
-
4
- import { TIsolate, Isolate } from '../Isolate';
5
- import { StateRefType, useAvailableRoot } from '../../VestRuntime';
6
- import { IsolateMutator, VestRuntime, IReconciler } from '../../vestjs-runtime';
7
-
8
- enum IsolateType {
9
- Isolate = 'Isolate',
10
- Child = 'Child',
11
- }
12
-
13
- describe('Isolate', () => {
14
- let stateRef: StateRefType;
15
-
16
- beforeEach(() => {
17
- stateRef = VestRuntime.createRef({} as IReconciler, v => v);
18
- });
19
-
20
- describe('Isolate.create', () => {
21
- it('should return an instance of Isolate', () => {
22
- const isolate = withRunTime(() => {
23
- return Isolate.create(IsolateType.Isolate, () => {});
24
- });
25
- expect(isolate).toBeInstanceOf(Object);
26
- });
27
-
28
- it('Should run the passed callback', () => {
29
- const spy = vi.fn();
30
- withRunTime(() => {
31
- Isolate.create(IsolateType.Isolate, spy);
32
- });
33
- expect(spy).toHaveBeenCalled();
34
- });
35
-
36
- it('Should store the callback result in the output property', () => {
37
- const isolate = withRunTime(() => {
38
- return Isolate.create(
39
- IsolateType.Isolate,
40
- () => {
41
- return 'foo';
42
- },
43
- {},
44
- );
45
- });
46
- expect(isolate.output).toBe('foo');
47
- });
48
-
49
- describe('When there is no parent', () => {
50
- it('Parent should be null', () => {
51
- const isolate = withRunTime(() => {
52
- return Isolate.create(IsolateType.Isolate, () => {});
53
- });
54
- expect(isolate.parent).toBeNull();
55
- });
56
-
57
- it('Should set the history root to the current isolate', () => {
58
- const isolate = withRunTime(() => {
59
- const isolate = Isolate.create(IsolateType.Isolate, () => {});
60
-
61
- expect(useAvailableRoot()).toBe(isolate);
62
-
63
- return isolate;
64
- });
65
- // Just verifying that we did not throw and catch inside the runtime
66
- expect(isolate).toBeDefined();
67
- });
68
- });
69
-
70
- describe('When there is a parent', () => {
71
- it('Should add the isolate to the parent children', () => {
72
- const [parent, children] = withRunTime(() => {
73
- const children = [] as TIsolate[];
74
- const parent = Isolate.create(IsolateType.Isolate, () => {
75
- children.push(Isolate.create(IsolateType.Child, () => {}));
76
- children.push(Isolate.create(IsolateType.Child, () => {}));
77
- children.push(Isolate.create(IsolateType.Child, () => {}));
78
- children.push(Isolate.create(IsolateType.Child, () => {}));
79
- });
80
- return [parent, children];
81
- });
82
- expect(parent.children).toEqual(children);
83
- });
84
-
85
- it('Should set the parent property', () => {
86
- const [parent, child] = withRunTime(() => {
87
- let child = {} as TIsolate;
88
- const parent = Isolate.create(IsolateType.Isolate, () => {
89
- child = Isolate.create(IsolateType.Child, () => null);
90
- });
91
-
92
- return [parent, child];
93
- });
94
- expect(child.parent).toBe(parent);
95
- });
96
- });
97
- });
98
-
99
- describe('AbortController', () => {
100
- it('Should be initially null', () => {
101
- const isolate = withRunTime(() => {
102
- return Isolate.create(IsolateType.Isolate, () => {});
103
- });
104
- expect(isolate.abortController).toBeNull();
105
- });
106
-
107
- it('Should abort the controller with the passed reason', () => {
108
- const isolate = withRunTime(() => {
109
- return Isolate.create(IsolateType.Isolate, () => {});
110
- });
111
- isolate.abortController = new AbortController();
112
- const spy = vi.spyOn(isolate.abortController, 'abort');
113
- IsolateMutator.abort(isolate, 'foo');
114
- expect(spy).toHaveBeenCalledWith('foo');
115
- });
116
- });
117
-
118
- function withRunTime<T>(fn: CB<T>) {
119
- return VestRuntime.Run(stateRef, () => {
120
- return fn();
121
- });
122
- }
123
- });