@hatchet-dev/typescript-sdk 1.34.0-alpha.1 → 1.34.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.
- package/README.md +1 -0
- package/clients/admin/rpc.d.ts +1 -1
- package/clients/admin/rpc.js +3 -3
- package/clients/admin/trigger-request.d.ts +18 -0
- package/clients/admin/trigger-request.js +66 -0
- package/clients/event/event-client.d.ts +4 -17
- package/clients/event/event-client.js +5 -43
- package/clients/event/rpc.d.ts +22 -3
- package/clients/event/rpc.js +66 -3
- package/clients/transport/fetch-transport.d.ts +73 -0
- package/clients/transport/fetch-transport.js +152 -0
- package/clients/transport/grpc-target.js +48 -3
- package/clients/transport/index.d.ts +2 -1
- package/clients/transport/index.js +6 -1
- package/clients/transport/node-transport.js +1 -2
- package/clients/transport/transport.d.ts +6 -0
- package/clients/transport/transport.js +7 -0
- package/clients/transport/ts-proto-client.js +16 -2
- package/core/client.d.ts +102 -0
- package/core/client.js +250 -0
- package/core/features/events.d.ts +25 -0
- package/core/features/events.js +57 -0
- package/core/features/logs.d.ts +26 -0
- package/core/features/logs.js +51 -0
- package/core/features/rate-limits.d.ts +19 -0
- package/core/features/rate-limits.js +30 -0
- package/core/features/runs.d.ts +33 -0
- package/core/features/runs.js +84 -0
- package/core/features/streams.d.ts +11 -0
- package/core/features/streams.js +23 -0
- package/core/features/workflows.d.ts +22 -0
- package/core/features/workflows.js +46 -0
- package/core/index.d.ts +42 -4
- package/core/index.js +79 -5
- package/core/logger.d.ts +19 -0
- package/core/logger.js +45 -0
- package/core/run-detail.d.ts +14 -0
- package/core/run-detail.js +79 -0
- package/core/run-ref.d.ts +63 -0
- package/core/run-ref.js +217 -0
- package/core/types.d.ts +182 -0
- package/core/types.js +2 -0
- package/dist/check-edge-entry.mjs +72 -14
- package/dist/check-edge-entry.test.ts +57 -0
- package/package.json +5 -2
- package/protoc/v1/streams.d.ts +79 -0
- package/protoc/v1/streams.js +511 -0
- package/protoc-es/v1/streams_pb.d.ts +133 -0
- package/protoc-es/v1/streams_pb.js +41 -0
- package/scripts/check-edge-entry.mjs +72 -14
- package/scripts/check-edge-entry.test.ts +57 -0
- package/util/batch.js +2 -1
- package/util/config-loader/token.d.ts +5 -0
- package/util/config-loader/token.js +8 -0
- package/util/errors/bulk-trigger-partial-error.d.ts +17 -0
- package/util/errors/bulk-trigger-partial-error.js +55 -0
- package/v1/client/admin.d.ts +4 -54
- package/v1/client/admin.js +9 -72
- package/v1/client/client.d.ts +14 -1
- package/v1/client/client.js +18 -0
- package/v1/client/features/index.d.ts +1 -0
- package/v1/client/features/index.js +1 -0
- package/v1/client/features/runs.d.ts +9 -27
- package/v1/client/features/runs.js +10 -55
- package/v1/client/features/streams.d.ts +47 -0
- package/v1/client/features/streams.js +210 -0
- package/v1/examples/durable-streams/publish-latency.d.ts +15 -0
- package/v1/examples/durable-streams/publish-latency.js +50 -0
- package/v1/examples/durable_callback_ordering/workflow.js +5 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
|
|
2
|
+
import type { Timestamp } from "@bufbuild/protobuf/wkt";
|
|
3
|
+
import type { Message } from "@bufbuild/protobuf";
|
|
4
|
+
/**
|
|
5
|
+
* Describes the file v1/streams.proto.
|
|
6
|
+
*/
|
|
7
|
+
export declare const file_v1_streams: GenFile;
|
|
8
|
+
/**
|
|
9
|
+
* @generated from message v1.PublishStreamMessageRequest
|
|
10
|
+
*/
|
|
11
|
+
export type PublishStreamMessageRequest = Message<"v1.PublishStreamMessageRequest"> & {
|
|
12
|
+
/**
|
|
13
|
+
* @generated from field: string namespace = 1;
|
|
14
|
+
*/
|
|
15
|
+
namespace: string;
|
|
16
|
+
/**
|
|
17
|
+
* @generated from field: string topic = 2;
|
|
18
|
+
*/
|
|
19
|
+
topic: string;
|
|
20
|
+
/**
|
|
21
|
+
* @generated from field: bytes payload = 3;
|
|
22
|
+
*/
|
|
23
|
+
payload: Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* @generated from field: string producer_id = 4;
|
|
26
|
+
*/
|
|
27
|
+
producerId: string;
|
|
28
|
+
/**
|
|
29
|
+
* @generated from field: int64 producer_seq = 5;
|
|
30
|
+
*/
|
|
31
|
+
producerSeq: bigint;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Describes the message v1.PublishStreamMessageRequest.
|
|
35
|
+
* Use `create(PublishStreamMessageRequestSchema)` to create a new message.
|
|
36
|
+
*/
|
|
37
|
+
export declare const PublishStreamMessageRequestSchema: GenMessage<PublishStreamMessageRequest>;
|
|
38
|
+
/**
|
|
39
|
+
* @generated from message v1.PublishStreamMessageResponse
|
|
40
|
+
*/
|
|
41
|
+
export type PublishStreamMessageResponse = Message<"v1.PublishStreamMessageResponse"> & {};
|
|
42
|
+
/**
|
|
43
|
+
* Describes the message v1.PublishStreamMessageResponse.
|
|
44
|
+
* Use `create(PublishStreamMessageResponseSchema)` to create a new message.
|
|
45
|
+
*/
|
|
46
|
+
export declare const PublishStreamMessageResponseSchema: GenMessage<PublishStreamMessageResponse>;
|
|
47
|
+
/**
|
|
48
|
+
* @generated from message v1.SubscribeStreamRequest
|
|
49
|
+
*/
|
|
50
|
+
export type SubscribeStreamRequest = Message<"v1.SubscribeStreamRequest"> & {
|
|
51
|
+
/**
|
|
52
|
+
* @generated from field: string namespace = 1;
|
|
53
|
+
*/
|
|
54
|
+
namespace: string;
|
|
55
|
+
/**
|
|
56
|
+
* @generated from field: string topic = 2;
|
|
57
|
+
*/
|
|
58
|
+
topic: string;
|
|
59
|
+
/**
|
|
60
|
+
* @generated from field: optional string cursor = 3;
|
|
61
|
+
*/
|
|
62
|
+
cursor?: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Describes the message v1.SubscribeStreamRequest.
|
|
66
|
+
* Use `create(SubscribeStreamRequestSchema)` to create a new message.
|
|
67
|
+
*/
|
|
68
|
+
export declare const SubscribeStreamRequestSchema: GenMessage<SubscribeStreamRequest>;
|
|
69
|
+
/**
|
|
70
|
+
* @generated from message v1.StreamMessage
|
|
71
|
+
*/
|
|
72
|
+
export type StreamMessage = Message<"v1.StreamMessage"> & {
|
|
73
|
+
/**
|
|
74
|
+
* @generated from field: repeated v1.StreamEntry entries = 1;
|
|
75
|
+
*/
|
|
76
|
+
entries: StreamEntry[];
|
|
77
|
+
/**
|
|
78
|
+
* @generated from field: bool hangup = 2;
|
|
79
|
+
*/
|
|
80
|
+
hangup: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* @generated from field: string cursor = 3;
|
|
83
|
+
*/
|
|
84
|
+
cursor: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Describes the message v1.StreamMessage.
|
|
88
|
+
* Use `create(StreamMessageSchema)` to create a new message.
|
|
89
|
+
*/
|
|
90
|
+
export declare const StreamMessageSchema: GenMessage<StreamMessage>;
|
|
91
|
+
/**
|
|
92
|
+
* @generated from message v1.StreamEntry
|
|
93
|
+
*/
|
|
94
|
+
export type StreamEntry = Message<"v1.StreamEntry"> & {
|
|
95
|
+
/**
|
|
96
|
+
* @generated from field: bytes payload = 1;
|
|
97
|
+
*/
|
|
98
|
+
payload: Uint8Array;
|
|
99
|
+
/**
|
|
100
|
+
* @generated from field: string cursor = 2;
|
|
101
|
+
*/
|
|
102
|
+
cursor: string;
|
|
103
|
+
/**
|
|
104
|
+
* @generated from field: google.protobuf.Timestamp created_at = 3;
|
|
105
|
+
*/
|
|
106
|
+
createdAt?: Timestamp | undefined;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Describes the message v1.StreamEntry.
|
|
110
|
+
* Use `create(StreamEntrySchema)` to create a new message.
|
|
111
|
+
*/
|
|
112
|
+
export declare const StreamEntrySchema: GenMessage<StreamEntry>;
|
|
113
|
+
/**
|
|
114
|
+
* @generated from service v1.V1Streams
|
|
115
|
+
*/
|
|
116
|
+
export declare const V1Streams: GenService<{
|
|
117
|
+
/**
|
|
118
|
+
* @generated from rpc v1.V1Streams.Publish
|
|
119
|
+
*/
|
|
120
|
+
publish: {
|
|
121
|
+
methodKind: "unary";
|
|
122
|
+
input: typeof PublishStreamMessageRequestSchema;
|
|
123
|
+
output: typeof PublishStreamMessageResponseSchema;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* @generated from rpc v1.V1Streams.Subscribe
|
|
127
|
+
*/
|
|
128
|
+
subscribe: {
|
|
129
|
+
methodKind: "server_streaming";
|
|
130
|
+
input: typeof SubscribeStreamRequestSchema;
|
|
131
|
+
output: typeof StreamMessageSchema;
|
|
132
|
+
};
|
|
133
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @generated by protoc-gen-es v2.15.0 with parameter "target=ts"
|
|
3
|
+
// @generated from file v1/streams.proto (package v1, syntax proto3)
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.V1Streams = exports.StreamEntrySchema = exports.StreamMessageSchema = exports.SubscribeStreamRequestSchema = exports.PublishStreamMessageResponseSchema = exports.PublishStreamMessageRequestSchema = exports.file_v1_streams = void 0;
|
|
7
|
+
const codegenv2_1 = require("@bufbuild/protobuf/codegenv2");
|
|
8
|
+
const wkt_1 = require("@bufbuild/protobuf/wkt");
|
|
9
|
+
/**
|
|
10
|
+
* Describes the file v1/streams.proto.
|
|
11
|
+
*/
|
|
12
|
+
exports.file_v1_streams = (0, codegenv2_1.fileDesc)("ChB2MS9zdHJlYW1zLnByb3RvEgJ2MSJ7ChtQdWJsaXNoU3RyZWFtTWVzc2FnZVJlcXVlc3QSEQoJbmFtZXNwYWNlGAEgASgJEg0KBXRvcGljGAIgASgJEg8KB3BheWxvYWQYAyABKAwSEwoLcHJvZHVjZXJfaWQYBCABKAkSFAoMcHJvZHVjZXJfc2VxGAUgASgDIh4KHFB1Ymxpc2hTdHJlYW1NZXNzYWdlUmVzcG9uc2UiWgoWU3Vic2NyaWJlU3RyZWFtUmVxdWVzdBIRCgluYW1lc3BhY2UYASABKAkSDQoFdG9waWMYAiABKAkSEwoGY3Vyc29yGAMgASgJSACIAQFCCQoHX2N1cnNvciJRCg1TdHJlYW1NZXNzYWdlEiAKB2VudHJpZXMYASADKAsyDy52MS5TdHJlYW1FbnRyeRIOCgZoYW5ndXAYAiABKAgSDgoGY3Vyc29yGAMgASgJIl4KC1N0cmVhbUVudHJ5Eg8KB3BheWxvYWQYASABKAwSDgoGY3Vyc29yGAIgASgJEi4KCmNyZWF0ZWRfYXQYAyABKAsyGi5nb29nbGUucHJvdG9idWYuVGltZXN0YW1wMpsBCglWMVN0cmVhbXMSTgoHUHVibGlzaBIfLnYxLlB1Ymxpc2hTdHJlYW1NZXNzYWdlUmVxdWVzdBogLnYxLlB1Ymxpc2hTdHJlYW1NZXNzYWdlUmVzcG9uc2UiABI+CglTdWJzY3JpYmUSGi52MS5TdWJzY3JpYmVTdHJlYW1SZXF1ZXN0GhEudjEuU3RyZWFtTWVzc2FnZSIAMAFCQlpAZ2l0aHViLmNvbS9oYXRjaGV0LWRldi9oYXRjaGV0L2ludGVybmFsL3NlcnZpY2VzL3NoYXJlZC9wcm90by92MWIGcHJvdG8z", [wkt_1.file_google_protobuf_timestamp]);
|
|
13
|
+
/**
|
|
14
|
+
* Describes the message v1.PublishStreamMessageRequest.
|
|
15
|
+
* Use `create(PublishStreamMessageRequestSchema)` to create a new message.
|
|
16
|
+
*/
|
|
17
|
+
exports.PublishStreamMessageRequestSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 0);
|
|
18
|
+
/**
|
|
19
|
+
* Describes the message v1.PublishStreamMessageResponse.
|
|
20
|
+
* Use `create(PublishStreamMessageResponseSchema)` to create a new message.
|
|
21
|
+
*/
|
|
22
|
+
exports.PublishStreamMessageResponseSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 1);
|
|
23
|
+
/**
|
|
24
|
+
* Describes the message v1.SubscribeStreamRequest.
|
|
25
|
+
* Use `create(SubscribeStreamRequestSchema)` to create a new message.
|
|
26
|
+
*/
|
|
27
|
+
exports.SubscribeStreamRequestSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 2);
|
|
28
|
+
/**
|
|
29
|
+
* Describes the message v1.StreamMessage.
|
|
30
|
+
* Use `create(StreamMessageSchema)` to create a new message.
|
|
31
|
+
*/
|
|
32
|
+
exports.StreamMessageSchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 3);
|
|
33
|
+
/**
|
|
34
|
+
* Describes the message v1.StreamEntry.
|
|
35
|
+
* Use `create(StreamEntrySchema)` to create a new message.
|
|
36
|
+
*/
|
|
37
|
+
exports.StreamEntrySchema = (0, codegenv2_1.messageDesc)(exports.file_v1_streams, 4);
|
|
38
|
+
/**
|
|
39
|
+
* @generated from service v1.V1Streams
|
|
40
|
+
*/
|
|
41
|
+
exports.V1Streams = (0, codegenv2_1.serviceDesc)(exports.file_v1_streams, 0);
|
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
|
-
// Verifies
|
|
4
|
-
//
|
|
5
|
-
// any
|
|
3
|
+
// Verifies that an entry point imports nothing from Node. Bundles the entry for a
|
|
4
|
+
// workerd-like browser target and fails on any `node:` specifier or Node builtin reached
|
|
5
|
+
// from it, transitively, on any package named with `--forbid`, and on any SDK module in the
|
|
6
|
+
// bundle that touches a Node-only global (which a bundler cannot see, since nothing imports
|
|
7
|
+
// them): `process`, `Buffer`, `setImmediate`, a timer's `.unref()`, `AbortSignal.timeout`
|
|
8
|
+
// and `AbortSignal.any`. A use the module feature-detects (`typeof setImmediate`,
|
|
9
|
+
// `timer.unref?.()`, `globalThis.Buffer`) is allowed.
|
|
6
10
|
//
|
|
7
|
-
// Run after `pnpm run tsc:build
|
|
8
|
-
// entry
|
|
9
|
-
//
|
|
11
|
+
// Run after `pnpm run tsc:build`:
|
|
12
|
+
// node scripts/check-edge-entry.mjs # dist/edge/index.js
|
|
13
|
+
// node scripts/check-edge-entry.mjs dist/core/index.js --forbid axios,nice-grpc
|
|
14
|
+
// The `check:edge` and `check:core` scripts build first and then run the two entries.
|
|
10
15
|
import { builtinModules } from 'node:module';
|
|
11
|
-
import { existsSync } from 'node:fs';
|
|
16
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
12
17
|
import { resolve, dirname } from 'node:path';
|
|
13
18
|
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import { build } from 'esbuild';
|
|
19
|
+
import { build, transformSync } from 'esbuild';
|
|
15
20
|
|
|
16
21
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
17
|
-
|
|
22
|
+
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const forbidden = new Set();
|
|
25
|
+
let entryArg = 'dist/edge/index.js';
|
|
26
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
27
|
+
if (args[i] === '--forbid') {
|
|
28
|
+
for (const pkg of (args[i + 1] ?? '').split(',')) if (pkg) forbidden.add(pkg);
|
|
29
|
+
i += 1;
|
|
30
|
+
} else {
|
|
31
|
+
entryArg = args[i];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const entry = resolve(root, entryArg);
|
|
36
|
+
const label = entryArg.replace(/^dist\//, '').replace(/\/index\.js$/, '');
|
|
18
37
|
|
|
19
38
|
if (!existsSync(entry)) {
|
|
20
39
|
console.error(`entry not built: ${entry} is missing. Run \`pnpm run tsc:build\` first.`);
|
|
@@ -63,22 +82,61 @@ const result = await build({
|
|
|
63
82
|
});
|
|
64
83
|
|
|
65
84
|
const bundled = Object.keys(result.metafile.inputs);
|
|
66
|
-
const sdkInputs = bundled.filter((f) => f.
|
|
85
|
+
const sdkInputs = bundled.filter((f) => !f.includes('node_modules/'));
|
|
67
86
|
const packageInputs = [...new Set(bundled.filter((f) => f.includes('node_modules/')).map((f) => {
|
|
68
87
|
const m = f.match(/node_modules\/(?:\.pnpm\/[^/]+\/node_modules\/)?((?:@[^/]+\/)?[^/]+)/);
|
|
69
88
|
return m ? m[1] : f;
|
|
70
89
|
}))].sort();
|
|
71
90
|
|
|
72
|
-
console.log(
|
|
91
|
+
console.log(`${label} entry: bundled ${sdkInputs.length} SDK module(s) and ${packageInputs.length} package(s)`);
|
|
73
92
|
if (packageInputs.length) console.log(`packages: ${packageInputs.join(', ')}`);
|
|
74
93
|
|
|
94
|
+
let failed = false;
|
|
95
|
+
|
|
75
96
|
if (violations.size > 0) {
|
|
76
|
-
|
|
97
|
+
failed = true;
|
|
98
|
+
console.error(`\n${label} entry reaches Node builtins:`);
|
|
77
99
|
for (const [specifier, importers] of [...violations.entries()].sort()) {
|
|
78
100
|
console.error(` ${specifier}`);
|
|
79
101
|
for (const importer of [...importers].sort()) console.error(` from ${importer}`);
|
|
80
102
|
}
|
|
81
|
-
process.exit(1);
|
|
82
103
|
}
|
|
83
104
|
|
|
84
|
-
|
|
105
|
+
const forbiddenHits = packageInputs.filter((pkg) => forbidden.has(pkg));
|
|
106
|
+
if (forbiddenHits.length > 0) {
|
|
107
|
+
failed = true;
|
|
108
|
+
console.error(`\n${label} entry bundles forbidden package(s): ${forbiddenHits.join(', ')}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// These are globals in Node that workerd and browsers lack, or that some runtimes the entry
|
|
112
|
+
// targets lack (`AbortSignal.any`, `AbortSignal.timeout`); a module that reads them fails at
|
|
113
|
+
// runtime without ever importing anything. A module that feature-detects one may use it: a
|
|
114
|
+
// `globalThis.Buffer` access (which the generated bindings guard) and an optional
|
|
115
|
+
// `.unref?.()` call are their own guards, and a `typeof` check of the global anywhere in the
|
|
116
|
+
// module allows its use in that module.
|
|
117
|
+
const nodeGlobals = [
|
|
118
|
+
{ what: 'the process or Buffer globals', pattern: /(?<!globalThis\.)\b(?:process|Buffer)\s*\./ },
|
|
119
|
+
{ what: 'setImmediate', pattern: /(?<![.\w$])setImmediate\s*\(/, guard: /typeof\s+setImmediate\b/ },
|
|
120
|
+
{ what: "a timer's .unref()", pattern: /(?<!\?)\.unref\s*\(/ },
|
|
121
|
+
{
|
|
122
|
+
what: 'AbortSignal.timeout or AbortSignal.any',
|
|
123
|
+
pattern: /\bAbortSignal\s*\.\s*(?:timeout|any)\b/,
|
|
124
|
+
guard: /typeof\s+AbortSignal\s*\.\s*(?:timeout|any)\b/,
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
// Comments describe these globals without touching them, so they are stripped first. esbuild
|
|
128
|
+
// drops them while leaving string literals alone, which a regex over `//` cannot promise.
|
|
129
|
+
const stripComments = (source) => transformSync(source, { loader: 'js', legalComments: 'none' }).code;
|
|
130
|
+
const sources = new Map(sdkInputs.map((f) => [f, stripComments(readFileSync(resolve(root, f), 'utf8'))]));
|
|
131
|
+
for (const { what, pattern, guard } of nodeGlobals) {
|
|
132
|
+
const hits = sdkInputs.filter((f) => pattern.test(sources.get(f)) && !(guard && guard.test(sources.get(f))));
|
|
133
|
+
if (hits.length > 0) {
|
|
134
|
+
failed = true;
|
|
135
|
+
console.error(`\n${label} entry bundles SDK module(s) that use ${what}:`);
|
|
136
|
+
for (const f of hits) console.error(` ${f}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (failed) process.exit(1);
|
|
141
|
+
|
|
142
|
+
console.log(`${label} entry is free of Node builtins${forbidden.size ? ' and forbidden packages' : ''}`);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const script = resolve(__dirname, 'check-edge-entry.mjs');
|
|
7
|
+
|
|
8
|
+
/** Runs the checker on a module holding `source`, as if it were an SDK module in the bundle. */
|
|
9
|
+
function check(source: string): { status: number | null; stderr: string } {
|
|
10
|
+
const dir = mkdtempSync(join(tmpdir(), 'check-edge-entry-'));
|
|
11
|
+
try {
|
|
12
|
+
const entry = join(dir, 'entry.js');
|
|
13
|
+
writeFileSync(entry, source);
|
|
14
|
+
const result = spawnSync(process.execPath, [script, entry], { encoding: 'utf8' });
|
|
15
|
+
return { status: result.status, stderr: result.stderr };
|
|
16
|
+
} finally {
|
|
17
|
+
rmSync(dir, { recursive: true, force: true });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('check-edge-entry', () => {
|
|
22
|
+
it('passes a module that uses none of the Node-only globals', () => {
|
|
23
|
+
const result = check(`
|
|
24
|
+
// setImmediate(() => {}) in a comment is fine, as is AbortSignal.any in prose.
|
|
25
|
+
/* process.exit() described here is fine too */
|
|
26
|
+
export const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
27
|
+
export const url = 'https://example.com//path';
|
|
28
|
+
`);
|
|
29
|
+
expect(result.stderr).toBe('');
|
|
30
|
+
expect(result.status).toBe(0);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it.each([
|
|
34
|
+
['setImmediate', 'export const tick = () => setImmediate(() => {});', /setImmediate/],
|
|
35
|
+
['process.nextTick', 'export const tick = () => process.nextTick(() => {});', /process or Buffer/],
|
|
36
|
+
['Buffer', "export const bytes = Buffer.from('x');", /process or Buffer/],
|
|
37
|
+
['Buffer after // inside a string', "export const p = 'a//b'; export const bytes = Buffer.from('x');", /process or Buffer/],
|
|
38
|
+
['.unref(', 'export const timer = setTimeout(() => {}, 1); timer.unref();', /\.unref\(\)/],
|
|
39
|
+
['AbortSignal.timeout', 'export const signal = AbortSignal.timeout(5);', /AbortSignal\.timeout or AbortSignal\.any/],
|
|
40
|
+
['AbortSignal.any', 'export const signal = AbortSignal.any([]);', /AbortSignal\.timeout or AbortSignal\.any/],
|
|
41
|
+
])('fails a module that uses %s', (_name, source, message) => {
|
|
42
|
+
const result = check(source);
|
|
43
|
+
expect(result.status).toBe(1);
|
|
44
|
+
expect(result.stderr).toMatch(message);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it.each([
|
|
48
|
+
['typeof setImmediate', "export const tick = typeof setImmediate === 'function' ? (f) => setImmediate(f) : (f) => setTimeout(f, 0);"],
|
|
49
|
+
['an optional .unref?.()', 'export const timer = setTimeout(() => {}, 1); timer.unref?.();'],
|
|
50
|
+
['typeof AbortSignal.any', "export const has = typeof AbortSignal.any === 'function';"],
|
|
51
|
+
['globalThis.Buffer', "export const bytes = globalThis.Buffer ? globalThis.Buffer.from('x') : new Uint8Array();"],
|
|
52
|
+
])('allows a feature-detected %s', (_name, source) => {
|
|
53
|
+
const result = check(source);
|
|
54
|
+
expect(result.stderr).toBe('');
|
|
55
|
+
expect(result.status).toBe(0);
|
|
56
|
+
});
|
|
57
|
+
});
|
package/util/batch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.batch = batch;
|
|
4
|
+
const utf8 = new TextEncoder();
|
|
4
5
|
function batch(payloads, numElm, maxBytes) {
|
|
5
6
|
const batches = [];
|
|
6
7
|
let currentBatchPayloads = [];
|
|
@@ -8,7 +9,7 @@ function batch(payloads, numElm, maxBytes) {
|
|
|
8
9
|
let currentBatchSize = 0;
|
|
9
10
|
for (let i = 0; i < payloads.length; i += 1) {
|
|
10
11
|
const request = payloads[i];
|
|
11
|
-
const requestSize =
|
|
12
|
+
const requestSize = utf8.encode(JSON.stringify(request)).byteLength;
|
|
12
13
|
// Check if adding this request would exceed either the payload limit or batch size
|
|
13
14
|
if (currentBatchPayloads.length > 0 &&
|
|
14
15
|
(currentBatchSize + requestSize > maxBytes || currentBatchPayloads.length >= numElm)) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export declare function getTenantIdFromJWT(token: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* The engine address a token was issued with, or `undefined` when the claim is absent. The
|
|
4
|
+
* core client needs only this claim, so it must not fail on a token that lacks `server_url`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getGrpcBroadcastAddressFromJWT(token: string): string | undefined;
|
|
2
7
|
export declare function getAddressesFromJWT(token: string): {
|
|
3
8
|
serverUrl: string;
|
|
4
9
|
grpcBroadcastAddress: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTenantIdFromJWT = getTenantIdFromJWT;
|
|
4
|
+
exports.getGrpcBroadcastAddressFromJWT = getGrpcBroadcastAddressFromJWT;
|
|
4
5
|
exports.getAddressesFromJWT = getAddressesFromJWT;
|
|
5
6
|
const parse_1 = require("../parse");
|
|
6
7
|
function getTenantIdFromJWT(token) {
|
|
@@ -10,6 +11,13 @@ function getTenantIdFromJWT(token) {
|
|
|
10
11
|
}
|
|
11
12
|
return claims.sub;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* The engine address a token was issued with, or `undefined` when the claim is absent. The
|
|
16
|
+
* core client needs only this claim, so it must not fail on a token that lacks `server_url`.
|
|
17
|
+
*/
|
|
18
|
+
function getGrpcBroadcastAddressFromJWT(token) {
|
|
19
|
+
return extractClaimsFromJWT(token).grpc_broadcast_address || undefined;
|
|
20
|
+
}
|
|
13
21
|
function getAddressesFromJWT(token) {
|
|
14
22
|
const claims = extractClaimsFromJWT(token);
|
|
15
23
|
if (claims.server_url === undefined || claims.grpc_broadcast_address === undefined) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import HatchetError from './hatchet-error';
|
|
2
|
+
/**
|
|
3
|
+
* A bulk trigger that failed after at least one of its batches was accepted. The runs the
|
|
4
|
+
* accepted batches created exist and are running; a caller that retries the whole request
|
|
5
|
+
* would create them again, so `refs` carries their references, in input order, for the
|
|
6
|
+
* caller to keep or cancel. `cause` is the error the failed batch raised, which is a
|
|
7
|
+
* `BulkTriggerIdempotencyCollisionError` when that batch collided on an idempotency key.
|
|
8
|
+
*/
|
|
9
|
+
export declare class BulkTriggerPartialError<Ref = unknown> extends HatchetError {
|
|
10
|
+
/** The references of every run created before the failed batch, in input order. */
|
|
11
|
+
refs: Ref[];
|
|
12
|
+
/** The zero-based index of the batch that failed. */
|
|
13
|
+
failedBatchIndex: number;
|
|
14
|
+
/** The error the failed batch raised. */
|
|
15
|
+
cause: unknown;
|
|
16
|
+
constructor(refs: Ref[], failedBatchIndex: number, cause: unknown);
|
|
17
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.BulkTriggerPartialError = void 0;
|
|
37
|
+
const hatchet_error_1 = __importStar(require("./hatchet-error"));
|
|
38
|
+
/**
|
|
39
|
+
* A bulk trigger that failed after at least one of its batches was accepted. The runs the
|
|
40
|
+
* accepted batches created exist and are running; a caller that retries the whole request
|
|
41
|
+
* would create them again, so `refs` carries their references, in input order, for the
|
|
42
|
+
* caller to keep or cancel. `cause` is the error the failed batch raised, which is a
|
|
43
|
+
* `BulkTriggerIdempotencyCollisionError` when that batch collided on an idempotency key.
|
|
44
|
+
*/
|
|
45
|
+
class BulkTriggerPartialError extends hatchet_error_1.default {
|
|
46
|
+
constructor(refs, failedBatchIndex, cause) {
|
|
47
|
+
super(`bulk trigger failed at batch ${failedBatchIndex} after ${refs.length} runs were created: ${(0, hatchet_error_1.getErrorMessage)(cause)}`, { cause });
|
|
48
|
+
this.name = 'BulkTriggerPartialError';
|
|
49
|
+
this.refs = refs;
|
|
50
|
+
this.failedBatchIndex = failedBatchIndex;
|
|
51
|
+
this.cause = cause;
|
|
52
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.BulkTriggerPartialError = BulkTriggerPartialError;
|
package/v1/client/admin.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { ClientConfig } from '../../clients/hatchet-client/client-config';
|
|
2
2
|
import WorkflowRunRef from '../../util/workflow-run-ref';
|
|
3
|
-
import {
|
|
3
|
+
import { RateLimitDuration, RunsClient } from './..';
|
|
4
4
|
import { RunListenerClient } from '../../clients/listeners/run-listener/child-listener-client';
|
|
5
5
|
import { Api } from '../../clients/rest/generated/Api';
|
|
6
6
|
import { WorkflowServiceClient } from '../../protoc/workflows';
|
|
7
7
|
import { AdminServiceClient, CreateWorkflowVersionRequest } from '../../protoc/v1/workflows';
|
|
8
8
|
import { type Transport } from '../../clients/transport';
|
|
9
|
+
import type { TriggerRun, TriggerRunOptions } from '../../core/types';
|
|
9
10
|
import { Logger } from '../../util/logger';
|
|
10
|
-
type DesiredWorkerLabelOpt = {
|
|
11
|
-
value: string | number;
|
|
12
|
-
required?: boolean;
|
|
13
|
-
weight?: number;
|
|
14
|
-
comparator?: WorkerLabelComparator;
|
|
15
|
-
};
|
|
16
11
|
export type WorkflowRun<T = object> = {
|
|
17
12
|
workflowName: string;
|
|
18
13
|
input: T;
|
|
@@ -58,27 +53,7 @@ export declare class AdminClient {
|
|
|
58
53
|
* @important This method is instrumented by HatchetInstrumentor._patchRunWorkflow.
|
|
59
54
|
* Keep the signature in sync with the instrumentor wrapper.
|
|
60
55
|
*/
|
|
61
|
-
runWorkflow<Q = object, P = object>(workflowName: string, input: Q, options?:
|
|
62
|
-
parentId?: string | undefined;
|
|
63
|
-
/**
|
|
64
|
-
* (optional) the parent task run external id.
|
|
65
|
-
*
|
|
66
|
-
* This is the field understood by the workflows gRPC API (`parent_task_run_external_id`).
|
|
67
|
-
*/
|
|
68
|
-
parentTaskRunExternalId?: string | undefined;
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
71
|
-
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
72
|
-
*/
|
|
73
|
-
parentStepRunId?: string | undefined;
|
|
74
|
-
childIndex?: number | undefined;
|
|
75
|
-
childKey?: string | undefined;
|
|
76
|
-
additionalMetadata?: Record<string, string> | undefined;
|
|
77
|
-
desiredWorkerId?: string | undefined;
|
|
78
|
-
priority?: Priority;
|
|
79
|
-
desiredWorkerLabels?: Record<string, DesiredWorkerLabelOpt>;
|
|
80
|
-
_standaloneTaskName?: string | undefined;
|
|
81
|
-
}): Promise<WorkflowRunRef<P>>;
|
|
56
|
+
runWorkflow<Q = object, P = object>(workflowName: string, input: Q, options?: TriggerRunOptions): Promise<WorkflowRunRef<P>>;
|
|
82
57
|
/**
|
|
83
58
|
* Run multiple workflows runs with the given input and options. This will create new workflow runs and return their IDs.
|
|
84
59
|
* Order is preserved in the response.
|
|
@@ -88,31 +63,6 @@ export declare class AdminClient {
|
|
|
88
63
|
* @important This method is instrumented by HatchetInstrumentor._patchRunWorkflows.
|
|
89
64
|
* Keep the signature in sync with the instrumentor wrapper.
|
|
90
65
|
*/
|
|
91
|
-
runWorkflows<Q = object, P = object>(workflowRuns: Array<
|
|
92
|
-
workflowName: string;
|
|
93
|
-
input: Q;
|
|
94
|
-
options?: {
|
|
95
|
-
parentId?: string | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* (optional) the parent task run external id.
|
|
98
|
-
*
|
|
99
|
-
* This is the field understood by the workflows gRPC API (`parent_task_run_external_id`).
|
|
100
|
-
*/
|
|
101
|
-
parentTaskRunExternalId?: string | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* @deprecated Use `parentTaskRunExternalId` instead.
|
|
104
|
-
* Kept for backward compatibility; will be mapped to `parentTaskRunExternalId`.
|
|
105
|
-
*/
|
|
106
|
-
parentStepRunId?: string | undefined;
|
|
107
|
-
childIndex?: number | undefined;
|
|
108
|
-
childKey?: string | undefined;
|
|
109
|
-
additionalMetadata?: Record<string, string> | undefined;
|
|
110
|
-
desiredWorkerId?: string | undefined;
|
|
111
|
-
priority?: Priority;
|
|
112
|
-
desiredWorkerLabels?: Record<string, DesiredWorkerLabelOpt>;
|
|
113
|
-
_standaloneTaskName?: string | undefined;
|
|
114
|
-
};
|
|
115
|
-
}>, batchSize?: number): Promise<WorkflowRunRef<P>[]>;
|
|
66
|
+
runWorkflows<Q = object, P = object>(workflowRuns: Array<TriggerRun<Q>>, batchSize?: number): Promise<WorkflowRunRef<P>[]>;
|
|
116
67
|
putRateLimit(key: string, limit: number, duration?: RateLimitDuration): Promise<void>;
|
|
117
68
|
}
|
|
118
|
-
export {};
|