tsdf 7.1.0 → 8.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/.eslintrc.cjs +79 -16
  2. package/.vscode/tasks.json +11 -1
  3. package/fetch-orquestrator-scenarios.excalidraw +10115 -0
  4. package/package.json +21 -13
  5. package/src/collectionFetchOrquestrator.ts +23 -0
  6. package/src/collectionStore.ts +608 -0
  7. package/src/documentStore.ts +272 -0
  8. package/src/fetchOrquestrator.ts +335 -0
  9. package/src/listQueryStore.ts +1190 -0
  10. package/src/main.ts +22 -1
  11. package/src/storeShared.ts +5 -0
  12. package/src/useEnsureIsLoaded.ts +50 -0
  13. package/src/utils/filterAndMap.ts +20 -0
  14. package/src/utils/getCacheId.ts +19 -0
  15. package/src/utils/hooks.ts +110 -0
  16. package/src/utils/isObject.ts +3 -0
  17. package/src/utils/math.ts +7 -0
  18. package/src/utils/serializableClone.ts +3 -0
  19. package/src/utils/useLatestValue.ts +16 -0
  20. package/test/__snapshots__/listQueryStore.test.ts.snap +146 -0
  21. package/test/__snapshots__/listQueryStoreHooks.test.ts.snap +9 -0
  22. package/test/collectionStore.test.ts +523 -0
  23. package/test/collectionStoreHooks.test.tsx +651 -0
  24. package/test/documentStore.test.ts +183 -0
  25. package/test/documentStoreHooks.test.tsx +857 -0
  26. package/test/fetchOrquestrator.test.ts +913 -0
  27. package/test/listQueryStore.test.ts +1158 -0
  28. package/test/listQueryStoreHooks.test.tsx +662 -0
  29. package/test/listQueryStoreHooks2.test.tsx +483 -0
  30. package/test/listQueryStoreHooksMutations.test.tsx +764 -0
  31. package/test/mocks/fetchMock.ts +296 -0
  32. package/test/mocks/fetchOrquestratorEnv.ts +370 -0
  33. package/test/setup/setup.ts +95 -1
  34. package/test/testHelpers.test.ts +88 -0
  35. package/test/utils/RenderObjValues.tsx +23 -0
  36. package/test/utils/arrayUtils.ts +13 -0
  37. package/test/utils/createDefaultListQueryStore.ts +275 -0
  38. package/test/utils/createOrVariations.ts +48 -0
  39. package/test/utils/dedent.ts +50 -0
  40. package/test/utils/delayCall.ts +25 -0
  41. package/test/utils/math.ts +3 -0
  42. package/test/utils/objectUtils.ts +18 -0
  43. package/test/utils/range.ts +19 -0
  44. package/test/utils/sleep.ts +3 -0
  45. package/test/utils/storeUtils.ts +460 -0
  46. package/tsconfig.prod.json +1 -1
  47. package/tsup.config.ts +1 -1
  48. package/vitest.config.ts +2 -1
  49. package/test/test.test.ts +0 -5
@@ -1,11 +1,27 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
3
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-argument */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
1
6
  /* eslint-disable @typescript-eslint/no-namespace */
2
- import { expect } from 'vitest';
3
7
  import matchers, {
4
8
  TestingLibraryMatchers,
5
9
  } from '@testing-library/jest-dom/matchers';
10
+ import { format } from 'pretty-format';
11
+ import { expect } from 'vitest';
12
+ import { filterAndMap } from '../../src/utils/filterAndMap';
13
+ import { createOrVariations } from '../utils/createOrVariations';
14
+ import { dedent } from '../utils/dedent';
15
+
16
+ interface ToMatchTimeline<R = unknown> {
17
+ toMatchTimeline(timeline: string): R;
18
+ toMatchSnapshotString(snapshot: string): R;
19
+ }
6
20
 
7
21
  declare global {
8
22
  namespace Vi {
23
+ interface Assertion extends ToMatchTimeline {}
24
+
9
25
  interface JestAssertion<T = any>
10
26
  extends jest.Matchers<void, T>,
11
27
  TestingLibraryMatchers<T, void> {}
@@ -13,3 +29,81 @@ declare global {
13
29
  }
14
30
 
15
31
  expect.extend(matchers);
32
+
33
+ expect.extend({
34
+ toMatchTimeline(received, expected) {
35
+ const expectedPossibleValues: string[] = createOrVariations(expected);
36
+
37
+ function checkIfPass(_received: any, _expected: any) {
38
+ let normalizedExpected: string = dedent`${_expected}`;
39
+
40
+ normalizedExpected = filterAndMap(
41
+ normalizedExpected.split('\n'),
42
+ (action, ignore) => {
43
+ if (action === '.') {
44
+ return dedent`fetch-started : 1
45
+ fetch-finished : 1
46
+ fetch-ui-commit`;
47
+ }
48
+
49
+ if (action.trim() === '' || action === '"') {
50
+ return ignore;
51
+ }
52
+
53
+ return dedent`${action}`;
54
+ },
55
+ ).join('\n');
56
+
57
+ normalizedExpected = `\n${normalizedExpected}\n`;
58
+
59
+ const normalizedReceived = String(_received)
60
+ .split('\n')
61
+ .map((action) => dedent`${action}`)
62
+ .join('\n');
63
+
64
+ return {
65
+ pass: normalizedReceived === normalizedExpected,
66
+ normalizedExpected,
67
+ normalizedReceived,
68
+ };
69
+ }
70
+
71
+ for (const possibleValue of expectedPossibleValues) {
72
+ const {
73
+ pass: possiblePass,
74
+ normalizedExpected,
75
+ normalizedReceived,
76
+ } = checkIfPass(received, possibleValue);
77
+
78
+ if (possiblePass || possibleValue === expectedPossibleValues.at(-1)) {
79
+ return {
80
+ pass: possiblePass,
81
+ message: () => `Timeline does not match`,
82
+ actual: normalizedReceived,
83
+ expected: normalizedExpected,
84
+ };
85
+ }
86
+ }
87
+
88
+ return {
89
+ pass: false,
90
+ message: () => `Timeline does not match`,
91
+ actual: received,
92
+ expected,
93
+ };
94
+ },
95
+ toMatchSnapshotString(received, expected) {
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
97
+ const normalizedExpected = dedent(expected);
98
+ const normalizedReceived = format(received, {
99
+ printBasicPrototype: false,
100
+ });
101
+
102
+ return {
103
+ pass: normalizedReceived === normalizedExpected,
104
+ message: () => `Snapshot string does not match`,
105
+ actual: normalizedReceived,
106
+ expected: normalizedExpected,
107
+ };
108
+ },
109
+ });
@@ -0,0 +1,88 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { createOrVariations } from './utils/createOrVariations';
3
+
4
+ describe('createOrVariations', () => {
5
+ test('case 1', () => {
6
+ expect(
7
+ createOrVariations(`
8
+ 4 - mutation-started
9
+ ---
10
+ fetch-aborted : 3
11
+ 4 - mutation-finished
12
+ OR
13
+ 4 - mutation-finished
14
+ fetch-aborted : 3
15
+ ---
16
+
17
+ fetch-started : 5
18
+ `),
19
+ ).toMatchInlineSnapshot(`
20
+ [
21
+ "
22
+ 4 - mutation-started
23
+ fetch-aborted : 3
24
+ 4 - mutation-finished
25
+
26
+ fetch-started : 5
27
+ ",
28
+ "
29
+ 4 - mutation-started
30
+ 4 - mutation-finished
31
+ fetch-aborted : 3
32
+
33
+ fetch-started : 5
34
+ ",
35
+ ]
36
+ `);
37
+ });
38
+
39
+ test('case 2', () => {
40
+ expect(
41
+ createOrVariations(`
42
+ 4 - mutation-started
43
+ ---
44
+ fetch-aborted : 3
45
+ 4 - mutation-finished
46
+ test
47
+ OR
48
+ 4 - mutation-finished
49
+ fetch-aborted : 3
50
+ test
51
+ OR
52
+ test
53
+ 4 - mutation-finished
54
+ fetch-aborted : 3
55
+ ---
56
+
57
+ fetch-started : 5
58
+ `),
59
+ ).toMatchInlineSnapshot(`
60
+ [
61
+ "
62
+ 4 - mutation-started
63
+ fetch-aborted : 3
64
+ 4 - mutation-finished
65
+ test
66
+
67
+ fetch-started : 5
68
+ ",
69
+ "
70
+ 4 - mutation-started
71
+ 4 - mutation-finished
72
+ fetch-aborted : 3
73
+ test
74
+
75
+ fetch-started : 5
76
+ ",
77
+ "
78
+ 4 - mutation-started
79
+ test
80
+ 4 - mutation-finished
81
+ fetch-aborted : 3
82
+
83
+ fetch-started : 5
84
+ ",
85
+ ]
86
+ `);
87
+ });
88
+ });
@@ -0,0 +1,23 @@
1
+ import { isObject } from '../../src/utils/isObject';
2
+
3
+ export const RenderObjValues = ({
4
+ testIdPrefix = '',
5
+ onRender,
6
+ renderObj,
7
+ }: {
8
+ testIdPrefix?: string;
9
+ renderObj: Record<string, any>;
10
+ onRender?: (renderObj: any) => void;
11
+ }) => {
12
+ onRender?.(renderObj);
13
+
14
+ return (
15
+ <div>
16
+ {Object.entries(renderObj).map(([key, value]) => (
17
+ <div key={key} data-testid={`${testIdPrefix}${key}`}>
18
+ {isObject(value) ? JSON.stringify(value) : String(value)}
19
+ </div>
20
+ ))}
21
+ </div>
22
+ );
23
+ };
@@ -0,0 +1,13 @@
1
+ export function arrayWithPrev<T>(array: T[]): [current: T, prev: T | null][] {
2
+ return array.map((item, i) => [item, array[i - 1] ?? null]);
3
+ }
4
+
5
+ export function arrayWithPrevAndIndex<T>(
6
+ array: T[],
7
+ ): { item: T; prev: T | null; index: number }[] {
8
+ return array.map((item, i) => ({
9
+ item,
10
+ prev: array[i - 1] ?? null,
11
+ index: i,
12
+ }));
13
+ }
@@ -0,0 +1,275 @@
1
+ import { deepEqual } from 't-state';
2
+ import {
3
+ newTSDFListQueryStore,
4
+ TSFDListQueryState,
5
+ } from '../../src/listQueryStore';
6
+ import { getCacheId } from '../../src/utils/getCacheId';
7
+ import { mockServerResource } from '../mocks/fetchMock';
8
+ import { normalizeError, StoreError } from './storeUtils';
9
+
10
+ type Row = {
11
+ id: number;
12
+ name: string;
13
+ type?: string;
14
+ archived?: boolean;
15
+ };
16
+
17
+ export type Tables = {
18
+ [id: string]: Row[];
19
+ };
20
+
21
+ export type ListQueryParams = {
22
+ tableId: string;
23
+ filters?: { idIsGreaterThan?: number };
24
+ };
25
+
26
+ export type DefaultListQueryState = TSFDListQueryState<
27
+ Row,
28
+ StoreError,
29
+ ListQueryParams
30
+ >;
31
+
32
+ export function createDefaultListQueryStore({
33
+ initialServerData = {},
34
+ useLoadedSnapshot,
35
+ defaultQuerySize,
36
+ debug,
37
+ dynamicRTUThrottleMs,
38
+ debugRequests: debuFetchs,
39
+ emulateRTU,
40
+ }: {
41
+ initialServerData?: Tables;
42
+ useLoadedSnapshot?: {
43
+ tables?: string[];
44
+ items?: string[];
45
+ queries?: ListQueryParams[];
46
+ };
47
+ defaultQuerySize?: number;
48
+ dynamicRTUThrottleMs?: (duration: number) => number;
49
+ debug?: never;
50
+ debugRequests?: never;
51
+ emulateRTU?: boolean;
52
+ } = {}) {
53
+ const serverMock = mockServerResource<Tables, Row[] | Row>({
54
+ initialData: initialServerData,
55
+ logFetchs: (debug as any) || (debuFetchs as any),
56
+ fetchSelector: (data, param) => {
57
+ if (param.includes('||')) {
58
+ const [tableId, id] = param.split('||');
59
+
60
+ const item = data?.[tableId!]?.find((item) => item.id === Number(id));
61
+
62
+ if (!item) {
63
+ return 'notFound';
64
+ }
65
+
66
+ return item;
67
+ }
68
+
69
+ return data?.[param] ?? 'notFound';
70
+ },
71
+ });
72
+
73
+ function getItemId({ tableId, id }: { tableId: string; id: number }) {
74
+ return `${tableId}||${id}`;
75
+ }
76
+
77
+ const listQueryStore = newTSDFListQueryStore<
78
+ Row,
79
+ StoreError,
80
+ ListQueryParams
81
+ >({
82
+ fetchListFn: async ({ tableId, filters }, size) => {
83
+ let result = await serverMock.fetch(tableId);
84
+ let hasMore = false;
85
+
86
+ if (!Array.isArray(result)) {
87
+ throw new Error('Invalid server response');
88
+ }
89
+
90
+ hasMore = result.length > size;
91
+ result = result.slice(0, size);
92
+
93
+ if (filters?.idIsGreaterThan) {
94
+ result = result.filter((item) => item.id > filters.idIsGreaterThan!);
95
+ }
96
+
97
+ return {
98
+ items: result.map((item) => ({
99
+ id: getItemId({ tableId, id: item.id }),
100
+ data: item,
101
+ })),
102
+ hasMore,
103
+ };
104
+ },
105
+ fetchItemFn: async (itemId) => {
106
+ const result = await serverMock.fetch(itemId);
107
+
108
+ if (Array.isArray(result)) {
109
+ throw new Error('Invalid server response');
110
+ }
111
+
112
+ return result;
113
+ },
114
+ errorNormalizer: normalizeError,
115
+ defaultQuerySize,
116
+ dynamicRealtimeThrottleMs: dynamicRTUThrottleMs,
117
+ syncMutationsAndInvalidations: {
118
+ syncItemAndQuery(itemId, query) {
119
+ return query.tableId === itemId.split('||')[0];
120
+ },
121
+ syncQueries(query1, query2) {
122
+ return query1.tableId === query2.tableId;
123
+ },
124
+ },
125
+ });
126
+
127
+ if (useLoadedSnapshot) {
128
+ const tablesToSnapshot = useLoadedSnapshot.tables ?? [];
129
+
130
+ if (useLoadedSnapshot.tables) {
131
+ const allIdsExist = tablesToSnapshot.every((tableId) =>
132
+ initialServerData.hasOwnProperty(tableId),
133
+ );
134
+
135
+ if (!allIdsExist) {
136
+ throw new Error(
137
+ `loadTablesSnapshot: Some tableId doesn't exist in initialServerData`,
138
+ );
139
+ }
140
+ }
141
+
142
+ const state: DefaultListQueryState = {
143
+ items: {},
144
+ queries: {},
145
+ itemQueries: {},
146
+ };
147
+
148
+ for (const [tableId, items] of Object.entries(initialServerData)) {
149
+ const queryId = `[{"tableId":"${tableId}"}]`;
150
+
151
+ if (!tablesToSnapshot.includes(tableId)) {
152
+ continue;
153
+ }
154
+
155
+ state.queries[queryId] = {
156
+ status: 'success',
157
+ items: items.map((item) => getItemId({ tableId, id: item.id })),
158
+ hasMore: false,
159
+ payload: { tableId },
160
+ wasLoaded: true,
161
+ refetchOnMount: false,
162
+ error: null,
163
+ };
164
+
165
+ for (const item of items) {
166
+ state.items[getItemId({ tableId, id: item.id })] = item;
167
+ state.itemQueries[getItemId({ tableId, id: item.id })] = {
168
+ status: 'success',
169
+ error: null,
170
+ refetchOnMount: false,
171
+ wasLoaded: true,
172
+ };
173
+ }
174
+ }
175
+
176
+ for (const query of useLoadedSnapshot.queries ?? []) {
177
+ const queryId = getCacheId(query);
178
+
179
+ const { tableId } = query;
180
+
181
+ const items =
182
+ initialServerData[query.tableId]?.filter((item) => {
183
+ if (query.filters?.idIsGreaterThan) {
184
+ return item.id > query.filters.idIsGreaterThan;
185
+ }
186
+
187
+ return true;
188
+ }) ?? [];
189
+
190
+ state.queries[queryId] = {
191
+ status: 'success',
192
+ items: items.map((item) => getItemId({ tableId, id: item.id })),
193
+ hasMore: false,
194
+ payload: query,
195
+ wasLoaded: true,
196
+ refetchOnMount: false,
197
+ error: null,
198
+ };
199
+
200
+ for (const item of items) {
201
+ state.items[getItemId({ tableId, id: item.id })] = item;
202
+ state.itemQueries[getItemId({ tableId, id: item.id })] = {
203
+ status: 'success',
204
+ error: null,
205
+ refetchOnMount: false,
206
+ wasLoaded: true,
207
+ };
208
+ }
209
+ }
210
+
211
+ if (useLoadedSnapshot.items) {
212
+ for (const itemId of useLoadedSnapshot.items) {
213
+ const itemData = initialServerData[itemId.split('||')[0]!]?.find(
214
+ (item) => item.id === Number(itemId.split('||')[1]),
215
+ );
216
+
217
+ if (!itemData) {
218
+ throw new Error(
219
+ `loadItemsSnapshot: Item doesn't exist in initialServerData`,
220
+ );
221
+ }
222
+
223
+ state.itemQueries[itemId] = {
224
+ status: 'success',
225
+ refetchOnMount: false,
226
+ wasLoaded: true,
227
+ error: null,
228
+ };
229
+ state.items[itemId] = itemData;
230
+ }
231
+ }
232
+
233
+ listQueryStore.store.setState(state);
234
+ }
235
+
236
+ if (debug as any) {
237
+ listQueryStore.store.subscribe(({ current }) => {
238
+ // eslint-disable-next-line no-console
239
+ console.log(serverMock.relativeTime(), current);
240
+ });
241
+ }
242
+
243
+ function forceListUpdate(params: ListQueryParams) {
244
+ const scheduleResult = listQueryStore.scheduleListQueryFetch(
245
+ 'highPriority',
246
+ params,
247
+ );
248
+
249
+ if (scheduleResult !== 'started') {
250
+ throw new Error(`error forceListUpdate: ${scheduleResult}`);
251
+ }
252
+ }
253
+
254
+ if (emulateRTU) {
255
+ serverMock.addOnUpdateServerData(({ prev, data }) => {
256
+ for (const tableId of Object.keys(data)) {
257
+ if (!deepEqual(prev[tableId], data[tableId])) {
258
+ listQueryStore.invalidateQuery({ tableId }, 'realtimeUpdate');
259
+ }
260
+ }
261
+ });
262
+ }
263
+
264
+ return {
265
+ serverMock,
266
+ store: listQueryStore,
267
+ getItemId,
268
+ forceListUpdate,
269
+ shouldNotSkip(this: void, scheduleResult: any) {
270
+ if (scheduleResult === 'skipped') {
271
+ throw new Error('Should not skip');
272
+ }
273
+ },
274
+ };
275
+ }
@@ -0,0 +1,48 @@
1
+ export function createOrVariations(multilineString: string): string[] {
2
+ if (multilineString.includes('OR')) {
3
+ const baseLines: string[] = [];
4
+
5
+ const lines = multilineString.split('\n');
6
+ const orVariations: string[][] = [[]];
7
+ let currentOrVariationIndex = 0;
8
+ let isOrBlock = false;
9
+
10
+ for (const line of lines) {
11
+ const trimmedLine = line.trimStart();
12
+
13
+ if (!isOrBlock && trimmedLine.startsWith('---')) {
14
+ isOrBlock = true;
15
+ baseLines.push('---block-placeholder---');
16
+ continue;
17
+ }
18
+
19
+ if (isOrBlock && trimmedLine.startsWith('OR')) {
20
+ orVariations.push([]);
21
+ currentOrVariationIndex++;
22
+ continue;
23
+ }
24
+
25
+ if (isOrBlock && trimmedLine.startsWith('---')) {
26
+ isOrBlock = false;
27
+ continue;
28
+ }
29
+
30
+ if (isOrBlock) {
31
+ orVariations[currentOrVariationIndex]!.push(line);
32
+ continue;
33
+ }
34
+
35
+ baseLines.push(line);
36
+ }
37
+
38
+ return orVariations.map((variation) =>
39
+ baseLines
40
+ .flatMap((line) =>
41
+ line === '---block-placeholder---' ? variation : [line],
42
+ )
43
+ .join('\n'),
44
+ );
45
+ } else {
46
+ return [multilineString];
47
+ }
48
+ }
@@ -0,0 +1,50 @@
1
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
2
+ // fork of https://github.com/dmnd/dedent
3
+
4
+ export function dedent(strings: TemplateStringsArray, ...values: string[]) {
5
+ // $FlowFixMe: Flow doesn't undestand .raw
6
+ const raw = typeof strings === 'string' ? [strings] : strings.raw;
7
+
8
+ // first, perform interpolation
9
+ let result = '';
10
+ for (let i = 0; i < raw.length; i++) {
11
+ result += raw[i]!
12
+ // join lines when there is a suppressed newline
13
+ .replace(/\\\n[ \t]*/g, '')
14
+ // handle escaped backticks
15
+ .replace(/\\`/g, '`');
16
+
17
+ if (i < values.length) {
18
+ result += values[i];
19
+ }
20
+ }
21
+
22
+ // now strip indentation
23
+ const lines = result.split('\n');
24
+ let mindent: number | null = null;
25
+ lines.forEach((l) => {
26
+ const m = l.match(/^(\s+)\S+/);
27
+ if (m) {
28
+ const indent = m[1]!.length;
29
+ if (!mindent) {
30
+ // this is the first indented line
31
+ mindent = indent;
32
+ } else {
33
+ mindent = Math.min(mindent, indent);
34
+ }
35
+ }
36
+ });
37
+
38
+ if (mindent !== null) {
39
+ const m = mindent; // appease Flow
40
+ result = lines.map((l) => (l.startsWith(' ') ? l.slice(m) : l)).join('\n');
41
+ }
42
+
43
+ return (
44
+ result
45
+ // dedent eats leading and trailing whitespace too
46
+ .trim()
47
+ // handle escaped newlines at the end to ensure they don't get stripped too
48
+ .replace(/\\n/g, '\n')
49
+ );
50
+ }
@@ -0,0 +1,25 @@
1
+ import { sleep } from './sleep';
2
+
3
+ export async function delayCall(delay: number, callback: () => void) {
4
+ await sleep(delay);
5
+
6
+ callback();
7
+ }
8
+
9
+ export async function waitTimeline(
10
+ calls: [number, () => void][],
11
+ waitUntil = 0,
12
+ ): Promise<void> {
13
+ const startTime = Date.now();
14
+ const promisses: Promise<void>[] = [];
15
+
16
+ for (const [delay, callback] of calls) {
17
+ promisses.push(delayCall(delay, callback));
18
+ }
19
+
20
+ await Promise.all(promisses);
21
+
22
+ if (waitUntil) {
23
+ await sleep(waitUntil - (Date.now() - startTime));
24
+ }
25
+ }
@@ -0,0 +1,3 @@
1
+ export function randomInt(min: number, max: number) {
2
+ return Math.floor(Math.random() * (max - min + 1) + min);
3
+ }
@@ -0,0 +1,18 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
3
+ export function pick<T, K extends keyof T>(
4
+ obj: T | undefined,
5
+ keys: K[],
6
+ rename?: Partial<Record<K, string>>,
7
+ ): Record<string, unknown> {
8
+ const result: any = {};
9
+
10
+ if (!obj) {
11
+ return result;
12
+ }
13
+
14
+ for (const key of keys) {
15
+ result[rename?.[key] || key] = obj[key];
16
+ }
17
+ return result;
18
+ }
@@ -0,0 +1,19 @@
1
+ export function range(start: number, end: number, step?: number): number[] {
2
+ const result = [];
3
+
4
+ if (start > end) {
5
+ for (let i = start; i >= end; i--) {
6
+ if (step && i % step !== 0) continue;
7
+
8
+ result.push(i);
9
+ }
10
+ } else {
11
+ for (let i = start; i <= end; i++) {
12
+ if (step && i % step !== 0) continue;
13
+
14
+ result.push(i);
15
+ }
16
+ }
17
+
18
+ return result;
19
+ }
@@ -0,0 +1,3 @@
1
+ export function sleep(ms: number) {
2
+ return new Promise((resolve) => setTimeout(resolve, ms));
3
+ }