@limitry/cli 1.0.0-rc.10 → 1.0.0-rc.11
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 +8 -0
- package/dist/limitry.mjs +75 -47
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in the Limitry CLI (`@limitry/cli`). Generated from the source on each release; newest first.
|
|
4
4
|
|
|
5
|
+
## 1.0.0-rc.11 (2026-10-27)
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Each limit in a check's answer (`limitry checks create`, `POST /v1/checks`)
|
|
10
|
+
now includes its `amount`: units per window, or for a `concurrent` limit
|
|
11
|
+
how many at once.
|
|
12
|
+
|
|
5
13
|
## 1.0.0-rc.10 (2026-10-27)
|
|
6
14
|
|
|
7
15
|
### Added
|
package/dist/limitry.mjs
CHANGED
|
@@ -936,7 +936,18 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
936
936
|
const remembered = /* @__PURE__ */ new Map();
|
|
937
937
|
const key = (s, action) => `${s.kind}\0${s.id}\0${action}`;
|
|
938
938
|
const failMode = (s, action) => options.failMode ?? remembered.get(key(s, action)) ?? "open";
|
|
939
|
+
const concurrentAmounts = /* @__PURE__ */ new Map();
|
|
940
|
+
const running = /* @__PURE__ */ new Map();
|
|
939
941
|
const remember = (s, action, decision) => {
|
|
942
|
+
const amounts = decision.limits.filter((r) => r.window === "concurrent" && typeof r.amount === "number").map((r) => r.amount);
|
|
943
|
+
if (amounts.length > 0) {
|
|
944
|
+
concurrentAmounts.set(key(s, action), Math.min(...amounts));
|
|
945
|
+
if (concurrentAmounts.size > 1e4) {
|
|
946
|
+
concurrentAmounts.delete(concurrentAmounts.keys().next().value);
|
|
947
|
+
}
|
|
948
|
+
} else {
|
|
949
|
+
concurrentAmounts.delete(key(s, action));
|
|
950
|
+
}
|
|
940
951
|
if (options.failMode)
|
|
941
952
|
return;
|
|
942
953
|
const closed = decision.limits.some((r) => r.failMode === "closed");
|
|
@@ -1113,57 +1124,74 @@ function createLimits(client, options = {}, internals = {}) {
|
|
|
1113
1124
|
ttlSeconds: request.ttlSeconds
|
|
1114
1125
|
};
|
|
1115
1126
|
const idempotencyKey = crypto.randomUUID();
|
|
1116
|
-
const
|
|
1117
|
-
const
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
await unheard();
|
|
1128
|
-
throw new Unavailable();
|
|
1129
|
-
}
|
|
1130
|
-
try {
|
|
1131
|
-
return await fn(unmetered);
|
|
1132
|
-
} finally {
|
|
1133
|
-
await unheard();
|
|
1134
|
-
}
|
|
1127
|
+
const slot = key(request.subject, request.action);
|
|
1128
|
+
const before = running.get(slot) ?? 0;
|
|
1129
|
+
running.set(slot, before + 1);
|
|
1130
|
+
try {
|
|
1131
|
+
return await reserveOnce(request, fn, body, idempotencyKey, before);
|
|
1132
|
+
} finally {
|
|
1133
|
+
const left2 = (running.get(slot) ?? 1) - 1;
|
|
1134
|
+
if (left2 > 0)
|
|
1135
|
+
running.set(slot, left2);
|
|
1136
|
+
else
|
|
1137
|
+
running.delete(slot);
|
|
1135
1138
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
async function reserveOnce(request, fn, body, idempotencyKey, before) {
|
|
1142
|
+
const reserved = request.cost ?? 1;
|
|
1143
|
+
const decision = await check(body, idempotencyKey);
|
|
1144
|
+
const unmetered = {
|
|
1145
|
+
// Checked even unmetered: the mistake shows whether or not
|
|
1146
|
+
// Limitry answered.
|
|
1147
|
+
cost: (units) => void checkedCost(units),
|
|
1148
|
+
extend: async () => {
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
if (decision === UNREACHABLE || decision === TIMED_OUT) {
|
|
1152
|
+
const unheard = () => decision === TIMED_OUT ? releaseUnheard(body, idempotencyKey) : Promise.resolve();
|
|
1153
|
+
const amount = concurrentAmounts.get(key(request.subject, request.action));
|
|
1154
|
+
if (failMode(request.subject, request.action) === "closed" || // Open, but never past a concurrent limit's amount here.
|
|
1155
|
+
amount !== void 0 && before >= amount) {
|
|
1156
|
+
await unheard();
|
|
1157
|
+
throw new Unavailable();
|
|
1139
1158
|
}
|
|
1140
|
-
const id = decision.reservation.id;
|
|
1141
|
-
let used = reserved;
|
|
1142
|
-
const reservation = {
|
|
1143
|
-
cost(units) {
|
|
1144
|
-
used = checkedCost(units);
|
|
1145
|
-
},
|
|
1146
|
-
async extend(ttlSeconds) {
|
|
1147
|
-
const { error, response } = await client.POST("/reservations/{reservationId}/extend", {
|
|
1148
|
-
params: { path: { reservationId: id } },
|
|
1149
|
-
body: ttlSeconds === void 0 ? {} : { ttlSeconds },
|
|
1150
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
1151
|
-
});
|
|
1152
|
-
if (error !== void 0)
|
|
1153
|
-
throw apiErrorFrom(error, response);
|
|
1154
|
-
}
|
|
1155
|
-
};
|
|
1156
|
-
let result;
|
|
1157
1159
|
try {
|
|
1158
|
-
|
|
1159
|
-
}
|
|
1160
|
-
await
|
|
1161
|
-
throw error;
|
|
1160
|
+
return await fn(unmetered);
|
|
1161
|
+
} finally {
|
|
1162
|
+
await unheard();
|
|
1162
1163
|
}
|
|
1163
|
-
await settle(id, "commit", used);
|
|
1164
|
-
return result;
|
|
1165
1164
|
}
|
|
1166
|
-
|
|
1165
|
+
remember(request.subject, request.action, decision);
|
|
1166
|
+
if (!decision.allowed || !decision.reservation) {
|
|
1167
|
+
throw new LimitReached(decision);
|
|
1168
|
+
}
|
|
1169
|
+
const id = decision.reservation.id;
|
|
1170
|
+
let used = reserved;
|
|
1171
|
+
const reservation = {
|
|
1172
|
+
cost(units) {
|
|
1173
|
+
used = checkedCost(units);
|
|
1174
|
+
},
|
|
1175
|
+
async extend(ttlSeconds) {
|
|
1176
|
+
const { error, response } = await client.POST("/reservations/{reservationId}/extend", {
|
|
1177
|
+
params: { path: { reservationId: id } },
|
|
1178
|
+
body: ttlSeconds === void 0 ? {} : { ttlSeconds },
|
|
1179
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
1180
|
+
});
|
|
1181
|
+
if (error !== void 0)
|
|
1182
|
+
throw apiErrorFrom(error, response);
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
let result;
|
|
1186
|
+
try {
|
|
1187
|
+
result = await fn(reservation);
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
await settle(id, "release");
|
|
1190
|
+
throw error;
|
|
1191
|
+
}
|
|
1192
|
+
await settle(id, "commit", used);
|
|
1193
|
+
return result;
|
|
1194
|
+
}
|
|
1167
1195
|
}
|
|
1168
1196
|
function isRetryLater(response, error) {
|
|
1169
1197
|
const code2 = error?.error?.code;
|
|
@@ -8271,7 +8299,7 @@ function tokenEnvVar() {
|
|
|
8271
8299
|
function build(io) {
|
|
8272
8300
|
let actedIn = null;
|
|
8273
8301
|
let sending;
|
|
8274
|
-
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.
|
|
8302
|
+
const program2 = new Command().name(brand.name).description(`${brand.productName} command line`).version("1.0.0-rc.11").addHelpText(
|
|
8275
8303
|
"after",
|
|
8276
8304
|
`
|
|
8277
8305
|
Token: \`${brand.name} login\` stores it in ~/.config/${brand.name}/; ${tokenEnvVar()} overrides.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@limitry/cli",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.11",
|
|
4
4
|
"description": "Limitry command line",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"typecheck": "tsc --noEmit"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@limitry/sdk": "1.0.0-rc.
|
|
20
|
+
"@limitry/sdk": "1.0.0-rc.11",
|
|
21
21
|
"@types/node": "26.6.5",
|
|
22
22
|
"commander": "15.0.0",
|
|
23
23
|
"esbuild": "0.28.2",
|