@zapier/zapier-sdk 0.13.5 → 0.13.7
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.
- package/CHANGELOG.md +15 -0
- package/dist/api/schemas.d.ts +38 -38
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts +170 -177
- package/dist/index.mjs +1 -1
- package/dist/plugins/fetch/schemas.d.ts +4 -4
- package/dist/plugins/getAction/schemas.d.ts +2 -2
- package/dist/plugins/listActions/schemas.d.ts +6 -6
- package/dist/plugins/listApps/schemas.d.ts +6 -6
- package/dist/plugins/listAuthentications/schemas.d.ts +4 -4
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +8 -8
- package/dist/plugins/listInputFields/schemas.d.ts +8 -8
- package/dist/plugins/request/schemas.d.ts +8 -8
- package/dist/plugins/runAction/schemas.d.ts +8 -8
- package/dist/schemas/Action.d.ts +2 -2
- package/dist/schemas/App.d.ts +8 -8
- package/dist/types/sdk.d.ts +2 -8
- package/dist/types/sdk.d.ts.map +1 -1
- package/package.json +8 -3
- package/src/api/auth.ts +0 -28
- package/src/api/client.ts +0 -491
- package/src/api/debug.test.ts +0 -76
- package/src/api/debug.ts +0 -154
- package/src/api/index.ts +0 -90
- package/src/api/polling.test.ts +0 -405
- package/src/api/polling.ts +0 -253
- package/src/api/schemas.ts +0 -465
- package/src/api/types.ts +0 -152
- package/src/auth.ts +0 -72
- package/src/constants.ts +0 -16
- package/src/index.ts +0 -111
- package/src/plugins/api/index.ts +0 -43
- package/src/plugins/apps/index.ts +0 -203
- package/src/plugins/apps/schemas.ts +0 -64
- package/src/plugins/eventEmission/builders.ts +0 -115
- package/src/plugins/eventEmission/index.test.ts +0 -169
- package/src/plugins/eventEmission/index.ts +0 -294
- package/src/plugins/eventEmission/transport.test.ts +0 -214
- package/src/plugins/eventEmission/transport.ts +0 -135
- package/src/plugins/eventEmission/types.ts +0 -58
- package/src/plugins/eventEmission/utils.ts +0 -121
- package/src/plugins/fetch/index.ts +0 -83
- package/src/plugins/fetch/schemas.ts +0 -37
- package/src/plugins/findFirstAuthentication/index.test.ts +0 -209
- package/src/plugins/findFirstAuthentication/index.ts +0 -68
- package/src/plugins/findFirstAuthentication/schemas.ts +0 -47
- package/src/plugins/findUniqueAuthentication/index.test.ts +0 -197
- package/src/plugins/findUniqueAuthentication/index.ts +0 -77
- package/src/plugins/findUniqueAuthentication/schemas.ts +0 -49
- package/src/plugins/getAction/index.test.ts +0 -239
- package/src/plugins/getAction/index.ts +0 -75
- package/src/plugins/getAction/schemas.ts +0 -41
- package/src/plugins/getApp/index.test.ts +0 -181
- package/src/plugins/getApp/index.ts +0 -60
- package/src/plugins/getApp/schemas.ts +0 -33
- package/src/plugins/getAuthentication/index.test.ts +0 -294
- package/src/plugins/getAuthentication/index.ts +0 -95
- package/src/plugins/getAuthentication/schemas.ts +0 -38
- package/src/plugins/getProfile/index.ts +0 -60
- package/src/plugins/getProfile/schemas.ts +0 -24
- package/src/plugins/listActions/index.test.ts +0 -526
- package/src/plugins/listActions/index.ts +0 -132
- package/src/plugins/listActions/schemas.ts +0 -55
- package/src/plugins/listApps/index.test.ts +0 -378
- package/src/plugins/listApps/index.ts +0 -159
- package/src/plugins/listApps/schemas.ts +0 -41
- package/src/plugins/listAuthentications/index.test.ts +0 -739
- package/src/plugins/listAuthentications/index.ts +0 -152
- package/src/plugins/listAuthentications/schemas.ts +0 -77
- package/src/plugins/listInputFieldChoices/index.test.ts +0 -653
- package/src/plugins/listInputFieldChoices/index.ts +0 -173
- package/src/plugins/listInputFieldChoices/schemas.ts +0 -125
- package/src/plugins/listInputFields/index.test.ts +0 -439
- package/src/plugins/listInputFields/index.ts +0 -294
- package/src/plugins/listInputFields/schemas.ts +0 -68
- package/src/plugins/manifest/index.test.ts +0 -776
- package/src/plugins/manifest/index.ts +0 -461
- package/src/plugins/manifest/schemas.ts +0 -60
- package/src/plugins/registry/index.ts +0 -160
- package/src/plugins/request/index.test.ts +0 -333
- package/src/plugins/request/index.ts +0 -105
- package/src/plugins/request/schemas.ts +0 -69
- package/src/plugins/runAction/index.test.ts +0 -388
- package/src/plugins/runAction/index.ts +0 -215
- package/src/plugins/runAction/schemas.ts +0 -60
- package/src/resolvers/actionKey.ts +0 -37
- package/src/resolvers/actionType.ts +0 -34
- package/src/resolvers/appKey.ts +0 -7
- package/src/resolvers/authenticationId.ts +0 -54
- package/src/resolvers/index.ts +0 -11
- package/src/resolvers/inputFieldKey.ts +0 -70
- package/src/resolvers/inputs.ts +0 -69
- package/src/schemas/Action.ts +0 -52
- package/src/schemas/App.ts +0 -45
- package/src/schemas/Auth.ts +0 -59
- package/src/schemas/Field.ts +0 -169
- package/src/schemas/Run.ts +0 -40
- package/src/schemas/UserProfile.ts +0 -60
- package/src/sdk.test.ts +0 -212
- package/src/sdk.ts +0 -178
- package/src/types/domain.test.ts +0 -50
- package/src/types/domain.ts +0 -66
- package/src/types/errors.ts +0 -278
- package/src/types/events.ts +0 -43
- package/src/types/functions.ts +0 -28
- package/src/types/optional-zapier-sdk-cli-login.d.ts +0 -37
- package/src/types/plugin.ts +0 -125
- package/src/types/properties.ts +0 -80
- package/src/types/sdk.ts +0 -117
- package/src/types/telemetry-events.ts +0 -85
- package/src/utils/array-utils.test.ts +0 -131
- package/src/utils/array-utils.ts +0 -41
- package/src/utils/domain-utils.test.ts +0 -433
- package/src/utils/domain-utils.ts +0 -267
- package/src/utils/file-utils.test.ts +0 -73
- package/src/utils/file-utils.ts +0 -94
- package/src/utils/function-utils.test.ts +0 -141
- package/src/utils/function-utils.ts +0 -245
- package/src/utils/pagination-utils.test.ts +0 -620
- package/src/utils/pagination-utils.ts +0 -242
- package/src/utils/schema-utils.ts +0 -207
- package/src/utils/string-utils.test.ts +0 -45
- package/src/utils/string-utils.ts +0 -54
- package/src/utils/validation.test.ts +0 -51
- package/src/utils/validation.ts +0 -44
- package/tsconfig.build.json +0 -18
- package/tsconfig.json +0 -20
- package/tsconfig.tsbuildinfo +0 -1
- package/tsup.config.ts +0 -23
package/src/types/sdk.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SDK-related types and interfaces
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { EventCallback } from "./events";
|
|
6
|
-
import type { EventEmissionConfig } from "../plugins/eventEmission";
|
|
7
|
-
|
|
8
|
-
// SDK Configuration Types
|
|
9
|
-
export interface BaseSdkOptions {
|
|
10
|
-
token?: string;
|
|
11
|
-
getToken?: () => Promise<string | undefined>;
|
|
12
|
-
onEvent?: EventCallback;
|
|
13
|
-
fetch?: typeof fetch;
|
|
14
|
-
baseUrl?: string;
|
|
15
|
-
debug?: boolean;
|
|
16
|
-
manifestPath?: string;
|
|
17
|
-
manifest?: {
|
|
18
|
-
apps: {
|
|
19
|
-
[appKey: string]: {
|
|
20
|
-
implementationName: string;
|
|
21
|
-
version?: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
eventEmission?: EventEmissionConfig;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// SDK interface composed from individual function interfaces
|
|
29
|
-
import type { ListInputFieldsSdkFunction } from "../plugins/listInputFields/schemas";
|
|
30
|
-
import type { GetAuthenticationSdkFunction } from "../plugins/getAuthentication/schemas";
|
|
31
|
-
import type { FindFirstAuthenticationSdkFunction } from "../plugins/findFirstAuthentication/schemas";
|
|
32
|
-
import type { FindUniqueAuthenticationSdkFunction } from "../plugins/findUniqueAuthentication/schemas";
|
|
33
|
-
import type { RelayRequestSdkFunction } from "../plugins/request/schemas";
|
|
34
|
-
|
|
35
|
-
import type { z } from "zod";
|
|
36
|
-
import type { RegistryPluginProvides } from "../plugins/registry";
|
|
37
|
-
import type { GetProfilePluginProvides } from "../plugins/getProfile";
|
|
38
|
-
import type { EventEmissionProvides } from "../plugins/eventEmission";
|
|
39
|
-
import type { ApiPluginProvides } from "../plugins/api";
|
|
40
|
-
import type { AppsPluginProvides, ZapierSdkApps } from "../plugins/apps";
|
|
41
|
-
import type { ActionProxy } from "../plugins/apps/schemas";
|
|
42
|
-
import type { FetchPluginProvides } from "../plugins/fetch";
|
|
43
|
-
import type { ListAppsPluginProvides } from "../plugins/listApps";
|
|
44
|
-
import type { GetAppPluginProvides } from "../plugins/getApp";
|
|
45
|
-
import type { ListActionsPluginProvides } from "../plugins/listActions";
|
|
46
|
-
import type { GetActionPluginProvides } from "../plugins/getAction";
|
|
47
|
-
import type { RunActionPluginProvides } from "../plugins/runAction";
|
|
48
|
-
import type { ListAuthenticationsPluginProvides } from "../plugins/listAuthentications";
|
|
49
|
-
import type { GetAuthenticationPluginProvides } from "../plugins/getAuthentication";
|
|
50
|
-
import type { FindFirstAuthenticationPluginProvides } from "../plugins/findFirstAuthentication";
|
|
51
|
-
import type { FindUniqueAuthenticationPluginProvides } from "../plugins/findUniqueAuthentication";
|
|
52
|
-
import type { ListInputFieldsPluginProvides } from "../plugins/listInputFields";
|
|
53
|
-
import type { ListInputFieldChoicesPluginProvides } from "../plugins/listInputFieldChoices";
|
|
54
|
-
import type { RequestPluginProvides } from "../plugins/request";
|
|
55
|
-
import type { GetSdkType } from "./plugin";
|
|
56
|
-
import type { ManifestPluginProvides } from "../plugins/manifest";
|
|
57
|
-
|
|
58
|
-
// Plugin interfaces
|
|
59
|
-
// Note: Plugin extension types removed - now using new plugin system
|
|
60
|
-
|
|
61
|
-
// Registry entry interface with proper types
|
|
62
|
-
export interface FunctionRegistryEntry {
|
|
63
|
-
name: string;
|
|
64
|
-
type?: "list" | "item";
|
|
65
|
-
itemType?: string;
|
|
66
|
-
returnType?: string;
|
|
67
|
-
inputSchema?: z.ZodSchema;
|
|
68
|
-
inputParameters?: Array<{ name: string; schema: z.ZodSchema }>;
|
|
69
|
-
outputSchema?: z.ZodSchema;
|
|
70
|
-
categories: string[];
|
|
71
|
-
resolvers?: Record<string, any>;
|
|
72
|
-
packages?: string[];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Compose SDK functions from individual function interfaces
|
|
76
|
-
export interface ZapierSdkFunctions
|
|
77
|
-
extends ListInputFieldsSdkFunction,
|
|
78
|
-
GetAuthenticationSdkFunction,
|
|
79
|
-
FindFirstAuthenticationSdkFunction,
|
|
80
|
-
FindUniqueAuthenticationSdkFunction,
|
|
81
|
-
RelayRequestSdkFunction {
|
|
82
|
-
// All functions now properly typed!
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Note: ZapierSdkPlugins removed - plugins are now handled by the plugin builder system
|
|
86
|
-
|
|
87
|
-
// Note: BaseZapierSdk removed - all functions now provided by individual plugins
|
|
88
|
-
// The registry is provided by RegistryPlugin
|
|
89
|
-
|
|
90
|
-
// Note: ZapierSdk type removed - use ReturnType<typeof createZapierSdk> instead
|
|
91
|
-
// This ensures the type matches exactly what the builder produces
|
|
92
|
-
|
|
93
|
-
export interface ZapierSdk
|
|
94
|
-
extends GetSdkType<
|
|
95
|
-
RegistryPluginProvides &
|
|
96
|
-
FetchPluginProvides &
|
|
97
|
-
AppsPluginProvides &
|
|
98
|
-
ListAppsPluginProvides &
|
|
99
|
-
ManifestPluginProvides &
|
|
100
|
-
GetAppPluginProvides &
|
|
101
|
-
ListActionsPluginProvides &
|
|
102
|
-
GetActionPluginProvides &
|
|
103
|
-
RunActionPluginProvides &
|
|
104
|
-
ListAuthenticationsPluginProvides &
|
|
105
|
-
GetAuthenticationPluginProvides &
|
|
106
|
-
FindFirstAuthenticationPluginProvides &
|
|
107
|
-
FindUniqueAuthenticationPluginProvides &
|
|
108
|
-
ListInputFieldsPluginProvides &
|
|
109
|
-
ListInputFieldChoicesPluginProvides &
|
|
110
|
-
RequestPluginProvides &
|
|
111
|
-
GetProfilePluginProvides &
|
|
112
|
-
EventEmissionProvides &
|
|
113
|
-
ApiPluginProvides
|
|
114
|
-
> {
|
|
115
|
-
// Override apps property to intersect ActionProxy with our typed apps
|
|
116
|
-
apps: ActionProxy & ZapierSdkApps;
|
|
117
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Event emission types matching Avro schemas for SDK telemetry
|
|
3
|
-
*
|
|
4
|
-
* These interfaces correspond to the Avro schemas:
|
|
5
|
-
* - application_lifecycle_event.avsc
|
|
6
|
-
* - error_occurred_event.avsc
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Common fields present in all events
|
|
10
|
-
export interface BaseEvent {
|
|
11
|
-
event_id: string;
|
|
12
|
-
timestamp_ms: number;
|
|
13
|
-
release_id: string;
|
|
14
|
-
customuser_id?: number | null;
|
|
15
|
-
account_id?: number | null;
|
|
16
|
-
identity_id?: number | null;
|
|
17
|
-
visitor_id?: string | null;
|
|
18
|
-
correlation_id?: string | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Error Event - tracks SDK errors and exceptions
|
|
22
|
-
export interface ErrorOccurredEvent extends BaseEvent {
|
|
23
|
-
zap_id?: number | null;
|
|
24
|
-
node_id?: number | null;
|
|
25
|
-
selected_api?: string | null;
|
|
26
|
-
app_id?: number | null;
|
|
27
|
-
app_version_id?: number | null;
|
|
28
|
-
error_message: string;
|
|
29
|
-
error_type?: string | null;
|
|
30
|
-
error_status_code?: number | null;
|
|
31
|
-
error_stack_trace?: string | null;
|
|
32
|
-
error_source_method?: string | null;
|
|
33
|
-
error_source_file?: string | null;
|
|
34
|
-
error_line_number?: number | null;
|
|
35
|
-
operation_type?: string | null;
|
|
36
|
-
operation_key?: string | null;
|
|
37
|
-
error_severity?: string | null;
|
|
38
|
-
is_user_facing: boolean;
|
|
39
|
-
is_recoverable?: boolean | null;
|
|
40
|
-
sdk_version?: string | null;
|
|
41
|
-
error_metadata?: Record<string, string | null> | null;
|
|
42
|
-
parent_error_id?: string | null;
|
|
43
|
-
error_occurred_timestamp_ms?: number | null;
|
|
44
|
-
error_code?: string | null;
|
|
45
|
-
recovery_attempted?: boolean | null;
|
|
46
|
-
recovery_action?: string | null;
|
|
47
|
-
recovery_successful?: boolean | null;
|
|
48
|
-
environment?: string | null;
|
|
49
|
-
execution_time_before_error_ms?: number | null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Application Lifecycle Event - tracks SDK application lifecycle transitions
|
|
53
|
-
export interface ApplicationLifecycleEvent extends BaseEvent {
|
|
54
|
-
lifecycle_event_type: "startup" | "exit" | "signal_termination";
|
|
55
|
-
selected_api?: string | null;
|
|
56
|
-
app_id?: number | null;
|
|
57
|
-
app_version_id?: number | null;
|
|
58
|
-
sdk_version?: string | null;
|
|
59
|
-
cli_version?: string | null;
|
|
60
|
-
exit_code?: number | null;
|
|
61
|
-
signal_name?: string | null;
|
|
62
|
-
uptime_ms?: number | null;
|
|
63
|
-
memory_usage_bytes?: number | null;
|
|
64
|
-
peak_memory_usage_bytes?: number | null;
|
|
65
|
-
cpu_time_ms?: number | null;
|
|
66
|
-
os_platform?: string | null;
|
|
67
|
-
os_release?: string | null;
|
|
68
|
-
os_architecture?: string | null;
|
|
69
|
-
platform_versions?: Record<string, string | null> | null;
|
|
70
|
-
environment?: string | null;
|
|
71
|
-
is_ci_environment?: boolean | null;
|
|
72
|
-
ci_platform?: string | null;
|
|
73
|
-
session_id?: string | null;
|
|
74
|
-
metadata?: Record<string, string | null> | null;
|
|
75
|
-
process_argv?: (string | null)[] | null;
|
|
76
|
-
is_graceful_shutdown?: boolean | null;
|
|
77
|
-
shutdown_duration_ms?: number | null;
|
|
78
|
-
active_requests_count?: number | null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Union type for all telemetry events
|
|
82
|
-
export type TelemetryEvent = ErrorOccurredEvent | ApplicationLifecycleEvent;
|
|
83
|
-
|
|
84
|
-
// Event type discriminator
|
|
85
|
-
export type TelemetryEventType = "error_occurred" | "application_lifecycle";
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { toArrayFromAsync } from "./array-utils";
|
|
3
|
-
|
|
4
|
-
describe("array-utils", () => {
|
|
5
|
-
describe("fromAsync", () => {
|
|
6
|
-
it("should convert async generator to array", async () => {
|
|
7
|
-
async function* generateNumbers() {
|
|
8
|
-
yield 1;
|
|
9
|
-
yield 2;
|
|
10
|
-
yield 3;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const result = await toArrayFromAsync(generateNumbers());
|
|
14
|
-
expect(result).toEqual([1, 2, 3]);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should handle empty async generator", async () => {
|
|
18
|
-
async function* generateNothing() {
|
|
19
|
-
// yield nothing
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const result = await toArrayFromAsync(generateNothing());
|
|
23
|
-
expect(result).toEqual([]);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should handle async generator with async operations", async () => {
|
|
27
|
-
async function* generateWithDelay() {
|
|
28
|
-
for (let i = 1; i <= 3; i++) {
|
|
29
|
-
await new Promise((resolve) => setTimeout(resolve, 1)); // Small delay
|
|
30
|
-
yield i * 10;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const result = await toArrayFromAsync(generateWithDelay());
|
|
35
|
-
expect(result).toEqual([10, 20, 30]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should handle async generator that yields different types", async () => {
|
|
39
|
-
async function* generateMixed() {
|
|
40
|
-
yield "hello";
|
|
41
|
-
yield 42;
|
|
42
|
-
yield { name: "test" };
|
|
43
|
-
yield [1, 2, 3];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const result = await toArrayFromAsync(generateMixed());
|
|
47
|
-
expect(result).toEqual(["hello", 42, { name: "test" }, [1, 2, 3]]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should handle async generator with error", async () => {
|
|
51
|
-
async function* generateWithError() {
|
|
52
|
-
yield 1;
|
|
53
|
-
yield 2;
|
|
54
|
-
throw new Error("Test error");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
await expect(toArrayFromAsync(generateWithError())).rejects.toThrow(
|
|
58
|
-
"Test error",
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should handle async iterable from array with Symbol.asyncIterator", async () => {
|
|
63
|
-
const asyncIterable = {
|
|
64
|
-
async *[Symbol.asyncIterator]() {
|
|
65
|
-
for (const item of ["a", "b", "c"]) {
|
|
66
|
-
yield item;
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const result = await toArrayFromAsync(asyncIterable);
|
|
72
|
-
expect(result).toEqual(["a", "b", "c"]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("should handle large async generator efficiently", async () => {
|
|
76
|
-
async function* generateLargeSequence() {
|
|
77
|
-
for (let i = 0; i < 1000; i++) {
|
|
78
|
-
yield i;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const result = await toArrayFromAsync(generateLargeSequence());
|
|
83
|
-
expect(result).toHaveLength(1000);
|
|
84
|
-
expect(result[0]).toBe(0);
|
|
85
|
-
expect(result[999]).toBe(999);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("should handle async generator that yields promises (promises are auto-awaited)", async () => {
|
|
89
|
-
async function* generatePromises() {
|
|
90
|
-
yield Promise.resolve("first");
|
|
91
|
-
yield Promise.resolve("second");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const result = await toArrayFromAsync(generatePromises());
|
|
95
|
-
// for await automatically awaits promises, so we get resolved values
|
|
96
|
-
expect(result).toEqual(["first", "second"]);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("should handle async generator that yields already resolved values", async () => {
|
|
100
|
-
async function* generateResolvedValues() {
|
|
101
|
-
yield await Promise.resolve("first");
|
|
102
|
-
yield await Promise.resolve("second");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const result = await toArrayFromAsync(generateResolvedValues());
|
|
106
|
-
// The resolved values are yielded directly
|
|
107
|
-
expect(result).toEqual(["first", "second"]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("should maintain order of async generator items", async () => {
|
|
111
|
-
async function* generateInOrder() {
|
|
112
|
-
for (let i = 1; i <= 5; i++) {
|
|
113
|
-
// Simulate varying delays
|
|
114
|
-
await new Promise((resolve) =>
|
|
115
|
-
setTimeout(resolve, Math.random() * 10),
|
|
116
|
-
);
|
|
117
|
-
yield `item-${i}`;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const result = await toArrayFromAsync(generateInOrder());
|
|
122
|
-
expect(result).toEqual([
|
|
123
|
-
"item-1",
|
|
124
|
-
"item-2",
|
|
125
|
-
"item-3",
|
|
126
|
-
"item-4",
|
|
127
|
-
"item-5",
|
|
128
|
-
]);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
package/src/utils/array-utils.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Array utility functions for working with async iterators and arrays
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates an array from an async iterable, similar to Array.from() but for async iterables
|
|
7
|
-
*
|
|
8
|
-
* @param asyncIterable - An async iterable to convert to an array
|
|
9
|
-
* @returns Promise that resolves to an array containing all items from the async iterable
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* async function* generateNumbers() {
|
|
13
|
-
* yield 1;
|
|
14
|
-
* yield 2;
|
|
15
|
-
* yield 3;
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* const numbers = await fromAsync(generateNumbers()); // [1, 2, 3]
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* // With async generator that fetches data
|
|
22
|
-
* async function* fetchUsers() {
|
|
23
|
-
* for (let page = 1; page <= 3; page++) {
|
|
24
|
-
* const users = await fetchUsersPage(page);
|
|
25
|
-
* yield* users;
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* const allUsers = await fromAsync(fetchUsers());
|
|
30
|
-
*/
|
|
31
|
-
export async function toArrayFromAsync<T>(
|
|
32
|
-
asyncIterable: AsyncIterable<T>,
|
|
33
|
-
): Promise<T[]> {
|
|
34
|
-
const result: T[] = [];
|
|
35
|
-
|
|
36
|
-
for await (const item of asyncIterable) {
|
|
37
|
-
result.push(item);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return result;
|
|
41
|
-
}
|