@bedrock-rbx/ocale 0.3.0 → 0.3.2
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 +13 -1
- package/dist/badges.d.mts +1 -1
- package/dist/badges.mjs +3 -3
- package/dist/{polling-Bs0GDvEa.d.mts → capacity-admission-BvnJjY0S.d.mts} +53 -14
- package/dist/capacity-admission-BvnJjY0S.d.mts.map +1 -0
- package/dist/developer-products.d.mts +1 -1
- package/dist/developer-products.mjs +4 -4
- package/dist/game-passes.d.mts +1 -1
- package/dist/game-passes.mjs +4 -4
- package/dist/index.d.mts +217 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +70 -5
- package/dist/index.mjs.map +1 -0
- package/dist/luau-execution.d.mts +39 -5
- package/dist/luau-execution.d.mts.map +1 -1
- package/dist/luau-execution.mjs +8 -13
- package/dist/luau-execution.mjs.map +1 -1
- package/dist/{rate-limit-Df55K34f.mjs → network-error-DR9FX5hb.mjs} +81 -36
- package/dist/network-error-DR9FX5hb.mjs.map +1 -0
- package/dist/places.d.mts +4 -4
- package/dist/places.d.mts.map +1 -1
- package/dist/places.mjs +8 -13
- package/dist/places.mjs.map +1 -1
- package/dist/{poll-timeout-DpEY-gAc.mjs → poll-timeout-3PXLsabj.mjs} +2 -2
- package/dist/{poll-timeout-DpEY-gAc.mjs.map → poll-timeout-3PXLsabj.mjs.map} +1 -1
- package/dist/{polling-helpers-BjFXyaOm.mjs → polling-helpers-CFuSt2O5.mjs} +349 -67
- package/dist/polling-helpers-CFuSt2O5.mjs.map +1 -0
- package/dist/{price-information-Brs8ebsh.mjs → price-information-D8BxwgTS.mjs} +2 -2
- package/dist/{price-information-Brs8ebsh.mjs.map → price-information-D8BxwgTS.mjs.map} +1 -1
- package/dist/resource-client--yYybltk.mjs +899 -0
- package/dist/resource-client--yYybltk.mjs.map +1 -0
- package/dist/resource-client-BivRq3JZ.d.mts +164 -0
- package/dist/resource-client-BivRq3JZ.d.mts.map +1 -0
- package/dist/retry-Cc4LcXYZ.mjs +1456 -0
- package/dist/retry-Cc4LcXYZ.mjs.map +1 -0
- package/dist/{retry-CdpA3z4A.d.mts → retry-DXEklFrt.d.mts} +51 -16
- package/dist/{retry-CdpA3z4A.d.mts.map → retry-DXEklFrt.d.mts.map} +1 -1
- package/dist/storage.d.mts +2 -157
- package/dist/storage.d.mts.map +1 -1
- package/dist/storage.mjs +3 -3
- package/dist/testing.d.mts +9 -17
- package/dist/testing.d.mts.map +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/{types-mhEalVsR.d.mts → types-C3Egi37J.d.mts} +86 -10
- package/dist/types-C3Egi37J.d.mts.map +1 -0
- package/dist/universes.d.mts +1 -1
- package/dist/universes.mjs +4 -4
- package/dist/{validation-Cg2lBhpQ.mjs → validation-B_Zs1So2.mjs} +2 -2
- package/dist/{validation-Cg2lBhpQ.mjs.map → validation-B_Zs1So2.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/polling-Bs0GDvEa.d.mts.map +0 -1
- package/dist/polling-helpers-BjFXyaOm.mjs.map +0 -1
- package/dist/rate-limit-Df55K34f.mjs.map +0 -1
- package/dist/resource-client-DtfDWglY.mjs +0 -1177
- package/dist/resource-client-DtfDWglY.mjs.map +0 -1
- package/dist/retry-DM2-tlR8.mjs +0 -458
- package/dist/retry-DM2-tlR8.mjs.map +0 -1
- package/dist/types-mhEalVsR.d.mts.map +0 -1
|
@@ -1,8 +1,104 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { a as TRANSIENT_TRANSPORT_CODES, d as findErrorCode, r as IDEMPOTENT_METHOD_DEFAULTS, t as CREATE_METHOD_DEFAULTS } from "./retry-
|
|
3
|
-
import { n as PollAbortedError, t as PollTimeoutError } from "./poll-timeout-
|
|
4
|
-
import { t as ValidationError } from "./validation-
|
|
5
|
-
import { a as
|
|
1
|
+
import { a as ApiError, n as RateLimitError, s as OpenCloudError, t as NetworkError } from "./network-error-DR9FX5hb.mjs";
|
|
2
|
+
import { _ as ABORTED, a as TRANSIENT_TRANSPORT_CODES, d as findErrorCode, r as IDEMPOTENT_METHOD_DEFAULTS, t as CREATE_METHOD_DEFAULTS, v as raceWithAbortAsync } from "./retry-Cc4LcXYZ.mjs";
|
|
3
|
+
import { n as PollAbortedError, t as PollTimeoutError } from "./poll-timeout-3PXLsabj.mjs";
|
|
4
|
+
import { t as ValidationError } from "./validation-B_Zs1So2.mjs";
|
|
5
|
+
import { a as observeAdmissionWaitAsync, c as isDateTimeString, i as waitDeadlineFailure, n as okRequest, o as toJsonDetails, s as isRecord } from "./resource-client--yYybltk.mjs";
|
|
6
|
+
//#region src/resources/luau-execution/capacity-error.ts
|
|
7
|
+
const UUID_PATTERN = "[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
|
8
|
+
/**
|
|
9
|
+
* A Luau task submission refused because validated tasks occupy the target
|
|
10
|
+
* place's execution capacity.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { LuauExecutionCapacityError } from "@bedrock-rbx/ocale/luau-execution";
|
|
16
|
+
*
|
|
17
|
+
* const error = new LuauExecutionCapacityError([{
|
|
18
|
+
* placeId: "456",
|
|
19
|
+
* sessionId: "11111111-1111-4111-8111-111111111111",
|
|
20
|
+
* taskId: "22222222-2222-4222-8222-222222222222",
|
|
21
|
+
* universeId: "123",
|
|
22
|
+
* versionId: "789",
|
|
23
|
+
* }]);
|
|
24
|
+
* expect(error.blockers).toHaveLength(1);
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @since 0.3.2
|
|
28
|
+
*/
|
|
29
|
+
var LuauExecutionCapacityError = class extends OpenCloudError {
|
|
30
|
+
/** Validated task references reported as occupying the target place. */
|
|
31
|
+
blockers;
|
|
32
|
+
name = "LuauExecutionCapacityError";
|
|
33
|
+
/**
|
|
34
|
+
* Creates a capacity failure from validated blocker references.
|
|
35
|
+
*
|
|
36
|
+
* @param blockers - Tasks reported as occupying the submitted place.
|
|
37
|
+
*/
|
|
38
|
+
constructor(blockers) {
|
|
39
|
+
super("Luau execution capacity is occupied", { code: "RESOURCE_EXHAUSTED" });
|
|
40
|
+
this.blockers = Object.freeze(blockers.map((blocker) => Object.freeze({ ...blocker })));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Builds the identity key shared by capacity blocker collections.
|
|
45
|
+
*
|
|
46
|
+
* @param ref - Luau task reference to identify.
|
|
47
|
+
* @returns The version, session, and task identity components.
|
|
48
|
+
*/
|
|
49
|
+
function luauTaskRefKey(ref) {
|
|
50
|
+
return `${ref.versionId}/${ref.sessionId}/${ref.taskId}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Converts a positively identified Luau capacity response into its typed
|
|
54
|
+
* error.
|
|
55
|
+
*
|
|
56
|
+
* @param error - The response error to inspect.
|
|
57
|
+
* @param parameters - The submitted target used to validate blocker refs.
|
|
58
|
+
* @returns A typed capacity error, or `undefined` without positive evidence.
|
|
59
|
+
*/
|
|
60
|
+
function capacityErrorFrom(error, parameters) {
|
|
61
|
+
if (!(error instanceof RateLimitError) || error.code !== "RESOURCE_EXHAUSTED") return;
|
|
62
|
+
const message = capacityMessage(error.details);
|
|
63
|
+
if (message === void 0) return;
|
|
64
|
+
const blockers = blockerRefsFrom(message, parameters);
|
|
65
|
+
return blockers.length === 0 ? void 0 : new LuauExecutionCapacityError(blockers);
|
|
66
|
+
}
|
|
67
|
+
function capacityMessage(details) {
|
|
68
|
+
if (details === null || typeof details !== "object" || Array.isArray(details)) return;
|
|
69
|
+
const code = Reflect.get(details, "code");
|
|
70
|
+
const message = Reflect.get(details, "message");
|
|
71
|
+
return code === "RESOURCE_EXHAUSTED" && typeof message === "string" ? message : void 0;
|
|
72
|
+
}
|
|
73
|
+
function escapeRegExp(value) {
|
|
74
|
+
return value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
75
|
+
}
|
|
76
|
+
function compareTaskRefs(left, right) {
|
|
77
|
+
return luauTaskRefKey(left).localeCompare(luauTaskRefKey(right));
|
|
78
|
+
}
|
|
79
|
+
function blockerRefsFrom(message, parameters) {
|
|
80
|
+
const universeId = escapeRegExp(parameters.universeId);
|
|
81
|
+
const placeId = escapeRegExp(parameters.placeId);
|
|
82
|
+
const pattern = new RegExp(`universes/(${universeId})/places/(${placeId})/versions/([1-9][0-9]*)/luau-execution-sessions/(${UUID_PATTERN})/tasks/(${UUID_PATTERN})(?=$|[^A-Za-z0-9_-])`, "giu");
|
|
83
|
+
const unique = /* @__PURE__ */ new Map();
|
|
84
|
+
for (const match of message.matchAll(pattern)) {
|
|
85
|
+
const matchedUniverseId = String(match[1]);
|
|
86
|
+
const matchedPlaceId = String(match[2]);
|
|
87
|
+
const versionId = String(match[3]);
|
|
88
|
+
const sessionId = String(match[4]);
|
|
89
|
+
const taskId = String(match[5]);
|
|
90
|
+
const ref = Object.freeze({
|
|
91
|
+
placeId: matchedPlaceId,
|
|
92
|
+
sessionId,
|
|
93
|
+
taskId,
|
|
94
|
+
universeId: matchedUniverseId,
|
|
95
|
+
versionId
|
|
96
|
+
});
|
|
97
|
+
unique.set(luauTaskRefKey(ref), ref);
|
|
98
|
+
}
|
|
99
|
+
return Object.freeze([...unique.values()].toSorted(compareTaskRefs));
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
6
102
|
//#region src/domains/cloud-v2/luau-execution-task-logs/builders.ts
|
|
7
103
|
/**
|
|
8
104
|
* Builds a `GET` request for the Open Cloud "list Luau execution session
|
|
@@ -74,8 +170,7 @@ const MALFORMED_LOGS_MESSAGE = "Malformed list-luau-execution-task-logs response
|
|
|
74
170
|
/**
|
|
75
171
|
* Parses a successful Open Cloud list-luau-execution-task-logs response
|
|
76
172
|
* body into the public {@link LogPage} shape. Chunks are flattened into
|
|
77
|
-
* a single ordered array of {@link LogMessage} values.
|
|
78
|
-
* `MESSAGE_TYPE_UNSPECIFIED` sentinel is rejected.
|
|
173
|
+
* a single ordered array of {@link LogMessage} values.
|
|
79
174
|
*
|
|
80
175
|
* @param response - The full {@link HttpResponse} from the Open Cloud API.
|
|
81
176
|
* @returns A success result wrapping the parsed {@link LogPage}, or an
|
|
@@ -106,7 +201,7 @@ function parseListLogsResponse({ body, status: statusCode }) {
|
|
|
106
201
|
};
|
|
107
202
|
}
|
|
108
203
|
function isAcceptedMessageType(value) {
|
|
109
|
-
return value === "OUTPUT" || value === "INFO" || value === "WARNING" || value === "ERROR";
|
|
204
|
+
return value === "MESSAGE_TYPE_UNSPECIFIED" || value === "OUTPUT" || value === "INFO" || value === "WARNING" || value === "ERROR";
|
|
110
205
|
}
|
|
111
206
|
function isLogMessageWire(value) {
|
|
112
207
|
return isRecord(value) && typeof value["createTime"] === "string" && typeof value["message"] === "string" && isAcceptedMessageType(value["messageType"]);
|
|
@@ -232,7 +327,7 @@ function buildSubmitBody({ binaryInput, enableBinaryOutput: shouldEnableBinaryOu
|
|
|
232
327
|
}
|
|
233
328
|
//#endregion
|
|
234
329
|
//#region src/domains/cloud-v2/luau-execution-tasks/operations.ts
|
|
235
|
-
const SUBMIT_AT_HEAD_PER_MINUTE =
|
|
330
|
+
const SUBMIT_AT_HEAD_PER_MINUTE = 5;
|
|
236
331
|
const SUBMIT_AT_VERSION_PER_MINUTE = 5;
|
|
237
332
|
const GET_PER_MINUTE = 200;
|
|
238
333
|
const SECONDS_PER_MINUTE = 60;
|
|
@@ -241,7 +336,7 @@ const SECONDS_PER_MINUTE = 60;
|
|
|
241
336
|
* place's head version, sourced from
|
|
242
337
|
* `x-roblox-rate-limits.perApiKeyOwner` on the
|
|
243
338
|
* `Cloud_CreateLuauExecutionSessionTask__Using_Universes` operation
|
|
244
|
-
* (
|
|
339
|
+
* (5 requests per minute per API key owner), which is also the burst
|
|
245
340
|
* the server allows.
|
|
246
341
|
*/
|
|
247
342
|
const SUBMIT_HEAD_OPERATION_LIMIT = Object.freeze({
|
|
@@ -258,7 +353,8 @@ const SUBMIT_HEAD_OPERATION_LIMIT = Object.freeze({
|
|
|
258
353
|
* the burst the server allows. Carries its own operation key so the
|
|
259
354
|
* version-pinned URL shape is paced from its own quota: the server
|
|
260
355
|
* meters the two shapes in separate buckets whose ceilings are
|
|
261
|
-
* additive, and pinned traffic does not consume head budget.
|
|
356
|
+
* additive, and pinned traffic does not consume head budget. The two
|
|
357
|
+
* ceilings are equal (5 each), but equal is not shared.
|
|
262
358
|
*/
|
|
263
359
|
const SUBMIT_VERSION_OPERATION_LIMIT = Object.freeze({
|
|
264
360
|
burstCapacity: SUBMIT_AT_VERSION_PER_MINUTE,
|
|
@@ -340,10 +436,10 @@ function parseLuauExecutionTaskResponse({ body, status: statusCode }) {
|
|
|
340
436
|
});
|
|
341
437
|
}
|
|
342
438
|
function isAcceptedWireState(state) {
|
|
343
|
-
return state === "QUEUED" || state === "PROCESSING" || state === "CANCELLED" || state === "COMPLETE" || state === "FAILED";
|
|
439
|
+
return state === "STATE_UNSPECIFIED" || state === "QUEUED" || state === "PROCESSING" || state === "CANCELLED" || state === "COMPLETE" || state === "FAILED";
|
|
344
440
|
}
|
|
345
441
|
function isErrorWireCode(code) {
|
|
346
|
-
return code === "SCRIPT_ERROR" || code === "DEADLINE_EXCEEDED" || code === "OUTPUT_SIZE_LIMIT_EXCEEDED" || code === "INTERNAL_ERROR";
|
|
442
|
+
return code === "ERROR_CODE_UNSPECIFIED" || code === "SCRIPT_ERROR" || code === "DEADLINE_EXCEEDED" || code === "OUTPUT_SIZE_LIMIT_EXCEEDED" || code === "INTERNAL_ERROR";
|
|
347
443
|
}
|
|
348
444
|
function isErrorWire(value) {
|
|
349
445
|
return isRecord(value) && isErrorWireCode(value["code"]) && typeof value["message"] === "string";
|
|
@@ -483,8 +579,8 @@ const SUBMIT_HEAD_SPEC = makeSpec({
|
|
|
483
579
|
* Per-method dispatch spec for submitting a Luau execution task at a
|
|
484
580
|
* specific place version. Shares the required scope set with {@link
|
|
485
581
|
* SUBMIT_HEAD_SPEC} but carries its own rate-limit queue: the server
|
|
486
|
-
* meters the version-pinned URL shape
|
|
487
|
-
*
|
|
582
|
+
* meters the version-pinned URL shape in a bucket separate from the
|
|
583
|
+
* head shape's.
|
|
488
584
|
*/
|
|
489
585
|
const SUBMIT_VERSION_SPEC = makeSpec({
|
|
490
586
|
buildRequest: (parameters) => okRequest(buildSubmitAtVersionRequest(parameters)),
|
|
@@ -557,17 +653,26 @@ function defaultPollDelay(elapsedMs) {
|
|
|
557
653
|
* already agreed to wait for the whole operation, so the backend can answer or
|
|
558
654
|
* surface a retryable status instead.
|
|
559
655
|
*
|
|
656
|
+
* @template TOptions - The concrete polling option shape to preserve.
|
|
560
657
|
* @param options - The caller's poll and per-request options.
|
|
561
658
|
* @returns The options with `timeout` filled from the budget when it was unset.
|
|
562
659
|
*/
|
|
563
660
|
function withBudgetRequestTimeout(options) {
|
|
564
|
-
|
|
661
|
+
const timeout = options.timeout ?? options.timeoutMs ?? 3e5;
|
|
565
662
|
return {
|
|
566
663
|
...options,
|
|
567
|
-
timeout
|
|
664
|
+
timeout
|
|
568
665
|
};
|
|
569
666
|
}
|
|
570
|
-
|
|
667
|
+
/**
|
|
668
|
+
* Reports whether a Luau task can no longer change execution state.
|
|
669
|
+
*
|
|
670
|
+
* @param task - Task whose state should be classified.
|
|
671
|
+
* @returns Whether the task is complete, failed, or cancelled.
|
|
672
|
+
*/
|
|
673
|
+
function isTerminalTask(task) {
|
|
674
|
+
return task.state === "COMPLETE" || task.state === "FAILED" || task.state === "CANCELLED";
|
|
675
|
+
}
|
|
571
676
|
/**
|
|
572
677
|
* Core polling loop. Calls `deps.fetch()` repeatedly, sleeping
|
|
573
678
|
* `pollDelay(elapsedMs)` ms between iterations, until a terminal state
|
|
@@ -583,11 +688,8 @@ const ABORTED = Symbol("poll-aborted");
|
|
|
583
688
|
* @returns The terminal task, or an error if aborted, timed out, or the transport keeps failing.
|
|
584
689
|
*/
|
|
585
690
|
async function pollUntilDoneCoreAsync(deps, options = {}) {
|
|
586
|
-
const timeoutMs = options
|
|
587
|
-
|
|
588
|
-
const maxFailures = options.maxConsecutivePollFailures ?? 3;
|
|
589
|
-
const sig = options.signal;
|
|
590
|
-
if (sig?.aborted === true) return abortedResult(sig);
|
|
691
|
+
const { maxFailures, pollDelay, signal, timeoutMs } = resolvePollOptions(options);
|
|
692
|
+
if (signal?.aborted === true) return abortedResult(signal);
|
|
591
693
|
const startedAt = deps.now();
|
|
592
694
|
let state = {
|
|
593
695
|
consecutiveFailures: 0,
|
|
@@ -599,20 +701,28 @@ async function pollUntilDoneCoreAsync(deps, options = {}) {
|
|
|
599
701
|
err: makeTimeout(state.lastTask, timeoutMs),
|
|
600
702
|
success: false
|
|
601
703
|
};
|
|
602
|
-
const action = applyOutcome(await fetchOnceAsync(deps,
|
|
704
|
+
const action = applyOutcome(await fetchOnceAsync(deps, signal), {
|
|
603
705
|
maxFailures,
|
|
604
|
-
signal
|
|
706
|
+
signal,
|
|
605
707
|
state
|
|
606
708
|
});
|
|
607
709
|
if (action.kind === "return") return action.result;
|
|
608
710
|
({state} = action);
|
|
609
711
|
if (await sleepWithAbortAsync({
|
|
610
712
|
ms: pollDelay(elapsedMs),
|
|
611
|
-
signal
|
|
713
|
+
signal,
|
|
612
714
|
sleep: deps.sleep
|
|
613
|
-
})) return abortedResult(
|
|
715
|
+
})) return abortedResult(signal);
|
|
614
716
|
}
|
|
615
717
|
}
|
|
718
|
+
function resolvePollOptions(options) {
|
|
719
|
+
return {
|
|
720
|
+
maxFailures: options.maxConsecutivePollFailures ?? 3,
|
|
721
|
+
pollDelay: options.pollDelay ?? defaultPollDelay,
|
|
722
|
+
signal: options.signal,
|
|
723
|
+
timeoutMs: options.timeoutMs ?? 3e5
|
|
724
|
+
};
|
|
725
|
+
}
|
|
616
726
|
function makeAborted(signal) {
|
|
617
727
|
return new PollAbortedError("Polling was aborted", { reason: signal?.reason });
|
|
618
728
|
}
|
|
@@ -678,32 +788,8 @@ function applyOutcome(outcome, { maxFailures, signal, state }) {
|
|
|
678
788
|
}
|
|
679
789
|
}
|
|
680
790
|
}
|
|
681
|
-
function abortObserver(signal) {
|
|
682
|
-
const { promise, resolve } = Promise.withResolvers();
|
|
683
|
-
function onAbort() {
|
|
684
|
-
resolve(ABORTED);
|
|
685
|
-
}
|
|
686
|
-
signal.addEventListener("abort", onAbort);
|
|
687
|
-
function cleanup() {
|
|
688
|
-
signal.removeEventListener("abort", onAbort);
|
|
689
|
-
}
|
|
690
|
-
return {
|
|
691
|
-
cleanup,
|
|
692
|
-
promise
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
async function raceWithAbortAsync(promise, signal) {
|
|
696
|
-
if (signal === void 0) return promise;
|
|
697
|
-
if (signal.aborted) return ABORTED;
|
|
698
|
-
const observer = abortObserver(signal);
|
|
699
|
-
try {
|
|
700
|
-
return await Promise.race([promise, observer.promise]);
|
|
701
|
-
} finally {
|
|
702
|
-
observer.cleanup();
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
791
|
async function sleepWithAbortAsync({ ms, signal, sleep }) {
|
|
706
|
-
return await raceWithAbortAsync(sleep(ms), signal) === ABORTED;
|
|
792
|
+
return await raceWithAbortAsync(async () => sleep(ms, signal), signal) === ABORTED;
|
|
707
793
|
}
|
|
708
794
|
function makeTimeout(task, timeoutMs) {
|
|
709
795
|
return new PollTimeoutError(`Polling timed out after ${timeoutMs} ms`, {
|
|
@@ -711,9 +797,6 @@ function makeTimeout(task, timeoutMs) {
|
|
|
711
797
|
timeoutMs
|
|
712
798
|
});
|
|
713
799
|
}
|
|
714
|
-
function isTerminal(task) {
|
|
715
|
-
return task.state === "COMPLETE" || task.state === "FAILED" || task.state === "CANCELLED";
|
|
716
|
-
}
|
|
717
800
|
/**
|
|
718
801
|
* A failed poll is worth re-polling only when it is a `NetworkError` carrying a
|
|
719
802
|
* known transient transport code. A self-aborted request timeout has no
|
|
@@ -739,7 +822,7 @@ function isTransientTransport(error) {
|
|
|
739
822
|
return code !== void 0 && TRANSIENT_TRANSPORT_CODES.includes(code);
|
|
740
823
|
}
|
|
741
824
|
async function fetchOnceAsync(dependencies, signal) {
|
|
742
|
-
const fetchResult = await raceWithAbortAsync(dependencies.fetch
|
|
825
|
+
const fetchResult = await raceWithAbortAsync(dependencies.fetch, signal);
|
|
743
826
|
if (fetchResult === ABORTED) return { kind: "aborted" };
|
|
744
827
|
if (!fetchResult.success) return isTransientTransport(fetchResult.err) ? {
|
|
745
828
|
error: fetchResult.err,
|
|
@@ -748,7 +831,7 @@ async function fetchOnceAsync(dependencies, signal) {
|
|
|
748
831
|
error: fetchResult.err,
|
|
749
832
|
kind: "failed"
|
|
750
833
|
};
|
|
751
|
-
return
|
|
834
|
+
return isTerminalTask(fetchResult.data) ? {
|
|
752
835
|
kind: "terminal",
|
|
753
836
|
task: fetchResult.data
|
|
754
837
|
} : {
|
|
@@ -757,6 +840,209 @@ async function fetchOnceAsync(dependencies, signal) {
|
|
|
757
840
|
};
|
|
758
841
|
}
|
|
759
842
|
//#endregion
|
|
843
|
+
//#region src/resources/luau-execution/capacity-admission.ts
|
|
844
|
+
const MAX_CAPACITY_WAIT_MS = 2147483647;
|
|
845
|
+
/**
|
|
846
|
+
* Submits through capacity admission when the caller opts in.
|
|
847
|
+
*
|
|
848
|
+
* @param call - Resource client, submit parameters, and per-request options.
|
|
849
|
+
* @returns The submitted task or the failure that stopped admission.
|
|
850
|
+
*/
|
|
851
|
+
async function submitWithCapacityAsync({ inner, options, parameters }) {
|
|
852
|
+
const { capacityWaitMs, ...requestOptions } = options ?? {};
|
|
853
|
+
if (capacityWaitMs === void 0) return submitOnceAsync({
|
|
854
|
+
inner,
|
|
855
|
+
options: requestOptions,
|
|
856
|
+
parameters
|
|
857
|
+
});
|
|
858
|
+
function refineError(error) {
|
|
859
|
+
return capacityErrorFrom(error, parameters) ?? error;
|
|
860
|
+
}
|
|
861
|
+
const submitCall = {
|
|
862
|
+
inner,
|
|
863
|
+
options: requestOptions,
|
|
864
|
+
parameters,
|
|
865
|
+
refineError
|
|
866
|
+
};
|
|
867
|
+
const first = await submitOnceAsync(submitCall);
|
|
868
|
+
if (!isCapacityFailure(first)) return first;
|
|
869
|
+
if (!Number.isFinite(capacityWaitMs) || capacityWaitMs < 1 || capacityWaitMs > MAX_CAPACITY_WAIT_MS) return first;
|
|
870
|
+
return admitWithinCapacityAsync({
|
|
871
|
+
capacityError: first.err,
|
|
872
|
+
options: requestOptions,
|
|
873
|
+
submitCall,
|
|
874
|
+
waitMs: capacityWaitMs
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
function isCapacityFailure(result) {
|
|
878
|
+
return !result.success && result.err instanceof LuauExecutionCapacityError;
|
|
879
|
+
}
|
|
880
|
+
async function submitOnceAsync({ inner, options, parameters, refineError }) {
|
|
881
|
+
return "versionId" in parameters ? inner.executeAsync({
|
|
882
|
+
options,
|
|
883
|
+
parameters,
|
|
884
|
+
refineError,
|
|
885
|
+
spec: SUBMIT_VERSION_SPEC
|
|
886
|
+
}) : inner.executeAsync({
|
|
887
|
+
options,
|
|
888
|
+
parameters,
|
|
889
|
+
refineError,
|
|
890
|
+
spec: SUBMIT_HEAD_SPEC
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
function capacityBoundAborted(options, callerSignal) {
|
|
894
|
+
return options.signal?.aborted === true && callerSignal?.aborted !== true;
|
|
895
|
+
}
|
|
896
|
+
async function observeBlockersAsync({ blockers, inner, options }) {
|
|
897
|
+
for (const blocker of blockers) {
|
|
898
|
+
const observed = await inner.executeAsync({
|
|
899
|
+
options,
|
|
900
|
+
parameters: {
|
|
901
|
+
ref: blocker,
|
|
902
|
+
view: "BASIC"
|
|
903
|
+
},
|
|
904
|
+
spec: GET_SPEC
|
|
905
|
+
});
|
|
906
|
+
if (!observed.success) return observed;
|
|
907
|
+
if (isTerminalTask(observed.data)) return {
|
|
908
|
+
data: blocker,
|
|
909
|
+
success: true
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
return {
|
|
913
|
+
data: void 0,
|
|
914
|
+
success: true
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
async function sleepForCapacityAsync({ inner, options, waitMs }) {
|
|
918
|
+
await observeAdmissionWaitAsync({
|
|
919
|
+
durationMs: waitMs,
|
|
920
|
+
observer: options.onAdmissionWait,
|
|
921
|
+
reason: "operation-capacity",
|
|
922
|
+
waitAsync: async () => {
|
|
923
|
+
return raceWithAbortAsync(async () => inner.sleep(waitMs, options.signal), options.signal);
|
|
924
|
+
}
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
async function observeWithinCapacityAsync({ blockers, capacityError, deadlineAt, inner, options, startedAt }) {
|
|
928
|
+
while (Date.now() < deadlineAt) {
|
|
929
|
+
const observed = await observeBlockersAsync({
|
|
930
|
+
blockers,
|
|
931
|
+
inner,
|
|
932
|
+
options
|
|
933
|
+
});
|
|
934
|
+
if (!observed.success) return observed;
|
|
935
|
+
if (observed.data !== void 0) return {
|
|
936
|
+
data: observed.data,
|
|
937
|
+
success: true
|
|
938
|
+
};
|
|
939
|
+
const pollWaitMs = defaultPollDelay(Date.now() - startedAt);
|
|
940
|
+
const deadlineFailure = waitDeadlineFailure({
|
|
941
|
+
cause: capacityError,
|
|
942
|
+
deadlineMs: options.deadlineMs,
|
|
943
|
+
waitMs: pollWaitMs,
|
|
944
|
+
waitReason: "operation-capacity"
|
|
945
|
+
});
|
|
946
|
+
if (deadlineFailure !== void 0) return {
|
|
947
|
+
err: deadlineFailure,
|
|
948
|
+
success: false
|
|
949
|
+
};
|
|
950
|
+
await sleepForCapacityAsync({
|
|
951
|
+
inner,
|
|
952
|
+
options,
|
|
953
|
+
waitMs: Math.min(pollWaitMs, deadlineAt - Date.now())
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
return {
|
|
957
|
+
err: capacityError,
|
|
958
|
+
success: false
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
function hasSameBlockers(left, right) {
|
|
962
|
+
if (left.blockers.length !== right.blockers.length) return false;
|
|
963
|
+
const rightKeys = new Set(right.blockers.map(luauTaskRefKey));
|
|
964
|
+
return left.blockers.every((blocker) => rightKeys.has(luauTaskRefKey(blocker)));
|
|
965
|
+
}
|
|
966
|
+
async function retryAfterCapacityAsync({ callerSignal, current, options, submitCall }) {
|
|
967
|
+
const retried = await submitOnceAsync(submitCall);
|
|
968
|
+
if (!retried.success && capacityBoundAborted(options, callerSignal)) return {
|
|
969
|
+
continue: false,
|
|
970
|
+
result: {
|
|
971
|
+
err: current,
|
|
972
|
+
success: false
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
if (!isCapacityFailure(retried) || hasSameBlockers(current, retried.err)) return {
|
|
976
|
+
continue: false,
|
|
977
|
+
result: retried
|
|
978
|
+
};
|
|
979
|
+
return {
|
|
980
|
+
capacityError: retried.err,
|
|
981
|
+
continue: true
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
async function runCapacityAdmissionAsync({ callerSignal, capacityError, deadlineAt, options, startedAt, submitCall }) {
|
|
985
|
+
const cleared = /* @__PURE__ */ new Set();
|
|
986
|
+
let current = capacityError;
|
|
987
|
+
while (true) {
|
|
988
|
+
const pending = current.blockers.filter((blocker) => !cleared.has(luauTaskRefKey(blocker)));
|
|
989
|
+
if (pending.length === 0) return {
|
|
990
|
+
err: current,
|
|
991
|
+
success: false
|
|
992
|
+
};
|
|
993
|
+
const observed = await observeWithinCapacityAsync({
|
|
994
|
+
blockers: pending,
|
|
995
|
+
capacityError: current,
|
|
996
|
+
deadlineAt,
|
|
997
|
+
inner: submitCall.inner,
|
|
998
|
+
options,
|
|
999
|
+
startedAt
|
|
1000
|
+
});
|
|
1001
|
+
if (!observed.success) return capacityBoundAborted(options, callerSignal) ? {
|
|
1002
|
+
err: current,
|
|
1003
|
+
success: false
|
|
1004
|
+
} : observed;
|
|
1005
|
+
cleared.add(luauTaskRefKey(observed.data));
|
|
1006
|
+
const retry = await retryAfterCapacityAsync({
|
|
1007
|
+
callerSignal,
|
|
1008
|
+
current,
|
|
1009
|
+
options,
|
|
1010
|
+
submitCall
|
|
1011
|
+
});
|
|
1012
|
+
if (!retry.continue) return retry.result;
|
|
1013
|
+
current = retry.capacityError;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
async function admitWithinCapacityAsync({ capacityError, options, submitCall, waitMs }) {
|
|
1017
|
+
const deadline = new AbortController();
|
|
1018
|
+
const timer = setTimeout(() => {
|
|
1019
|
+
deadline.abort();
|
|
1020
|
+
}, waitMs);
|
|
1021
|
+
const signal = options.signal === void 0 ? deadline.signal : AbortSignal.any([options.signal, deadline.signal]);
|
|
1022
|
+
const startedAt = Date.now();
|
|
1023
|
+
try {
|
|
1024
|
+
return await runCapacityAdmissionAsync({
|
|
1025
|
+
callerSignal: options.signal,
|
|
1026
|
+
capacityError,
|
|
1027
|
+
deadlineAt: startedAt + waitMs,
|
|
1028
|
+
options: {
|
|
1029
|
+
...options,
|
|
1030
|
+
signal
|
|
1031
|
+
},
|
|
1032
|
+
startedAt,
|
|
1033
|
+
submitCall: {
|
|
1034
|
+
...submitCall,
|
|
1035
|
+
options: {
|
|
1036
|
+
...submitCall.options,
|
|
1037
|
+
signal
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
} finally {
|
|
1042
|
+
clearTimeout(timer);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
//#endregion
|
|
760
1046
|
//#region src/resources/luau-execution/polling-helpers.ts
|
|
761
1047
|
/**
|
|
762
1048
|
* Builds the {@link PollDependencies} bundle used by {@link
|
|
@@ -794,15 +1080,11 @@ function buildPollDependencies(inner, args) {
|
|
|
794
1080
|
* the {@link OpenCloudError} that caused submit or polling to fail.
|
|
795
1081
|
*/
|
|
796
1082
|
async function submitAndPollAsync(inner, { options, parameters }) {
|
|
797
|
-
const submitResult = await (
|
|
1083
|
+
const submitResult = await submitWithCapacityAsync({
|
|
1084
|
+
inner,
|
|
798
1085
|
options,
|
|
799
|
-
parameters
|
|
800
|
-
|
|
801
|
-
}) : inner.executeAsync({
|
|
802
|
-
options,
|
|
803
|
-
parameters,
|
|
804
|
-
spec: SUBMIT_HEAD_SPEC
|
|
805
|
-
}));
|
|
1086
|
+
parameters
|
|
1087
|
+
});
|
|
806
1088
|
if (!submitResult.success) return submitResult;
|
|
807
1089
|
return pollUntilDoneCoreAsync(buildPollDependencies(inner, {
|
|
808
1090
|
options,
|
|
@@ -810,6 +1092,6 @@ async function submitAndPollAsync(inner, { options, parameters }) {
|
|
|
810
1092
|
}), options);
|
|
811
1093
|
}
|
|
812
1094
|
//#endregion
|
|
813
|
-
export {
|
|
1095
|
+
export { pollUntilDoneCoreAsync as a, LIST_LOGS_SPEC as c, defaultPollDelay as i, LuauExecutionCapacityError as l, submitAndPollAsync as n, withBudgetRequestTimeout as o, submitWithCapacityAsync as r, GET_SPEC as s, buildPollDependencies as t };
|
|
814
1096
|
|
|
815
|
-
//# sourceMappingURL=polling-helpers-
|
|
1097
|
+
//# sourceMappingURL=polling-helpers-CFuSt2O5.mjs.map
|