@kodycodes/cli 3.46.5 → 3.46.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.
Files changed (41) hide show
  1. package/dist/bin.js +1 -1
  2. package/dist/{chunk-IQSN4HQY.js → chunk-2NSRT4L5.js} +2 -2
  3. package/dist/{chunk-Y4BGJG3R.js → chunk-E6XVOBCF.js} +14 -14
  4. package/dist/{chunk-VUVCPMIE.js → chunk-M5L4EUF2.js} +2 -2
  5. package/dist/{chunk-OZG2CY42.js → chunk-S3MKSHYO.js} +2 -2
  6. package/dist/{chunk-57WUSXRH.js → chunk-VEFYSWT4.js} +1 -1
  7. package/dist/{chunk-57WUSXRH.js.map → chunk-VEFYSWT4.js.map} +1 -1
  8. package/dist/{chunk-7P4IRMKT.js → chunk-WRCYQJ57.js} +1 -1
  9. package/dist/{chunk-7P4IRMKT.js.map → chunk-WRCYQJ57.js.map} +1 -1
  10. package/dist/{chunk-NZDTFELD.js → chunk-XGYBIVUK.js} +2 -2
  11. package/dist/cli.js +1 -1
  12. package/dist/{commands-HHKFMPWI.js → commands-PEKGP2T7.js} +2 -2
  13. package/dist/{dev-command-RFPDAF7A.js → dev-command-BSXKCSEH.js} +6 -6
  14. package/dist/{execute-local-package-ILH7ARJT.js → execute-local-package-LBUVTXNQ.js} +4 -4
  15. package/dist/{local-execute-PM2TBMAH.js → local-execute-WU2VVDEQ.js} +2 -2
  16. package/dist/{local-kody-BOIWOFLS.js → local-kody-JHFC4YKZ.js} +3 -3
  17. package/dist/{local-package-run-62YJYFJF.js → local-package-run-JYHWVV77.js} +3 -3
  18. package/dist/{local-publish-build-7CVDXIQE.js → local-publish-build-UNITM4LN.js} +2 -2
  19. package/dist/local-publish-build.d.ts +1 -1
  20. package/dist/{mock-fetch-gateway-5FABDZ5I.js → mock-fetch-gateway-3QFVMR6R.js} +2 -2
  21. package/dist/{mock-server-GCDZFOQN.js → mock-server-TZLF3XME.js} +3 -3
  22. package/dist/publish-builder.js +341 -309
  23. package/dist/{publish-offload-BKKDBDH3.js → publish-offload-BVDWUYEF.js} +2 -2
  24. package/dist/{run-executor-IOKD2CQI.js → run-executor-H7WSZMLV.js} +3 -3
  25. package/package.json +1 -1
  26. /package/dist/{chunk-IQSN4HQY.js.map → chunk-2NSRT4L5.js.map} +0 -0
  27. /package/dist/{chunk-Y4BGJG3R.js.map → chunk-E6XVOBCF.js.map} +0 -0
  28. /package/dist/{chunk-VUVCPMIE.js.map → chunk-M5L4EUF2.js.map} +0 -0
  29. /package/dist/{chunk-OZG2CY42.js.map → chunk-S3MKSHYO.js.map} +0 -0
  30. /package/dist/{chunk-NZDTFELD.js.map → chunk-XGYBIVUK.js.map} +0 -0
  31. /package/dist/{commands-HHKFMPWI.js.map → commands-PEKGP2T7.js.map} +0 -0
  32. /package/dist/{dev-command-RFPDAF7A.js.map → dev-command-BSXKCSEH.js.map} +0 -0
  33. /package/dist/{execute-local-package-ILH7ARJT.js.map → execute-local-package-LBUVTXNQ.js.map} +0 -0
  34. /package/dist/{local-execute-PM2TBMAH.js.map → local-execute-WU2VVDEQ.js.map} +0 -0
  35. /package/dist/{local-kody-BOIWOFLS.js.map → local-kody-JHFC4YKZ.js.map} +0 -0
  36. /package/dist/{local-package-run-62YJYFJF.js.map → local-package-run-JYHWVV77.js.map} +0 -0
  37. /package/dist/{local-publish-build-7CVDXIQE.js.map → local-publish-build-UNITM4LN.js.map} +0 -0
  38. /package/dist/{mock-fetch-gateway-5FABDZ5I.js.map → mock-fetch-gateway-3QFVMR6R.js.map} +0 -0
  39. /package/dist/{mock-server-GCDZFOQN.js.map → mock-server-TZLF3XME.js.map} +0 -0
  40. /package/dist/{publish-offload-BKKDBDH3.js.map → publish-offload-BVDWUYEF.js.map} +0 -0
  41. /package/dist/{run-executor-IOKD2CQI.js.map → run-executor-H7WSZMLV.js.map} +0 -0
@@ -28104,13 +28104,328 @@ var init_reserved_usernames2 = __esm({
28104
28104
  }
28105
28105
  });
28106
28106
 
28107
+ // ../worker/src/package-registry/published-package-cache.ts
28108
+ function createPublishedPackageCacheKey(input3) {
28109
+ if (!input3.source.published_commit) {
28110
+ return null;
28111
+ }
28112
+ return JSON.stringify([
28113
+ input3.userId,
28114
+ input3.source.id,
28115
+ input3.source.published_commit,
28116
+ input3.source.manifest_path,
28117
+ input3.source.source_root,
28118
+ input3.entryPoint?.trim() || null
28119
+ ]);
28120
+ }
28121
+ function estimateRetainedBytes(value) {
28122
+ const seen = /* @__PURE__ */ new Set();
28123
+ const stack = [value];
28124
+ let bytes = 0;
28125
+ while (stack.length > 0) {
28126
+ const next2 = stack.pop();
28127
+ if (typeof next2 === "string") {
28128
+ bytes += next2.length;
28129
+ continue;
28130
+ }
28131
+ if (next2 === null || typeof next2 !== "object" || seen.has(next2)) {
28132
+ continue;
28133
+ }
28134
+ seen.add(next2);
28135
+ if (ArrayBuffer.isView(next2) || next2 instanceof ArrayBuffer) {
28136
+ bytes += next2.byteLength;
28137
+ continue;
28138
+ }
28139
+ if (Array.isArray(next2)) {
28140
+ stack.push(...next2);
28141
+ continue;
28142
+ }
28143
+ const prototype = Object.getPrototypeOf(next2);
28144
+ if (prototype !== Object.prototype && prototype !== null) {
28145
+ continue;
28146
+ }
28147
+ for (const [key, child] of Object.entries(next2)) {
28148
+ bytes += key.length;
28149
+ stack.push(child);
28150
+ }
28151
+ }
28152
+ return bytes;
28153
+ }
28154
+ function createPromiseLruCacheByBinding(options) {
28155
+ const caches = /* @__PURE__ */ new WeakMap();
28156
+ return {
28157
+ for(binding) {
28158
+ let cache = caches.get(binding);
28159
+ if (!cache) {
28160
+ cache = new PromiseLruCache(options);
28161
+ caches.set(binding, cache);
28162
+ }
28163
+ return cache;
28164
+ },
28165
+ clear(binding) {
28166
+ caches.get(binding)?.clear();
28167
+ }
28168
+ };
28169
+ }
28170
+ function createPublishedPackagePromiseCache() {
28171
+ return new PromiseLruCache({ byteBudget: packageArtifactCacheBudget });
28172
+ }
28173
+ var publishedPackageCacheLimit, publishedPackageCacheTtlMs, promiseLruCacheInFlightWaitMs, RetainedByteBudget, packageArtifactCacheMaxBytes, packageArtifactCacheBudget, PromiseLruCache;
28174
+ var init_published_package_cache = __esm({
28175
+ "../worker/src/package-registry/published-package-cache.ts"() {
28176
+ "use strict";
28177
+ publishedPackageCacheLimit = 50;
28178
+ publishedPackageCacheTtlMs = 5 * 60 * 1e3;
28179
+ promiseLruCacheInFlightWaitMs = 5e3;
28180
+ RetainedByteBudget = class {
28181
+ constructor(maxBytes) {
28182
+ this.maxBytes = maxBytes;
28183
+ }
28184
+ maxBytes;
28185
+ caches = /* @__PURE__ */ new Set();
28186
+ usedBytes = 0;
28187
+ clock = 0;
28188
+ get retainedBytes() {
28189
+ return this.usedBytes;
28190
+ }
28191
+ /** @internal */
28192
+ tick() {
28193
+ this.clock += 1;
28194
+ return this.clock;
28195
+ }
28196
+ /** @internal */
28197
+ register(cache) {
28198
+ this.caches.add(cache);
28199
+ }
28200
+ /** @internal */
28201
+ adjust(delta) {
28202
+ this.usedBytes += delta;
28203
+ }
28204
+ /** @internal */
28205
+ enforce() {
28206
+ while (this.usedBytes > this.maxBytes) {
28207
+ let oldest = null;
28208
+ let oldestUsed = Number.POSITIVE_INFINITY;
28209
+ for (const cache of this.caches) {
28210
+ const candidate = cache.oldestSizedEntry();
28211
+ if (candidate && candidate.lastUsed < oldestUsed) {
28212
+ oldestUsed = candidate.lastUsed;
28213
+ oldest = { cache, key: candidate.key };
28214
+ }
28215
+ }
28216
+ if (!oldest) {
28217
+ break;
28218
+ }
28219
+ oldest.cache.delete(oldest.key);
28220
+ }
28221
+ }
28222
+ };
28223
+ packageArtifactCacheMaxBytes = 24 * 1024 * 1024;
28224
+ packageArtifactCacheBudget = new RetainedByteBudget(
28225
+ packageArtifactCacheMaxBytes
28226
+ );
28227
+ PromiseLruCache = class {
28228
+ cache = /* @__PURE__ */ new Map();
28229
+ constructor(input3) {
28230
+ this.ttlMs = input3?.ttlMs ?? publishedPackageCacheTtlMs;
28231
+ this.limit = input3?.limit ?? publishedPackageCacheLimit;
28232
+ this.inFlightWaitMs = input3?.inFlightWaitMs ?? promiseLruCacheInFlightWaitMs;
28233
+ this.byteBudget = input3?.byteBudget ?? null;
28234
+ this.sizeOf = input3?.sizeOf ?? estimateRetainedBytes;
28235
+ this.retainSettled = input3?.retainSettled ?? true;
28236
+ this.byteBudget?.register(this);
28237
+ }
28238
+ ttlMs;
28239
+ limit;
28240
+ inFlightWaitMs;
28241
+ byteBudget;
28242
+ sizeOf;
28243
+ retainSettled;
28244
+ /** @internal Least recently used settled entry that holds sized bytes. */
28245
+ oldestSizedEntry() {
28246
+ for (const [key, entry] of this.cache) {
28247
+ if (entry.bytes > 0) {
28248
+ return { key, lastUsed: entry.lastUsed };
28249
+ }
28250
+ }
28251
+ return null;
28252
+ }
28253
+ touch(entry) {
28254
+ if (this.byteBudget) {
28255
+ entry.lastUsed = this.byteBudget.tick();
28256
+ }
28257
+ }
28258
+ getEntry(key) {
28259
+ const cached2 = this.cache.get(key);
28260
+ if (!cached2) {
28261
+ return null;
28262
+ }
28263
+ if (cached2.expiresAt <= Date.now()) {
28264
+ this.delete(key);
28265
+ return null;
28266
+ }
28267
+ this.cache.delete(key);
28268
+ this.cache.set(key, cached2);
28269
+ this.touch(cached2);
28270
+ return cached2;
28271
+ }
28272
+ /**
28273
+ * A settled value, as a promise owned by the caller's request. Never
28274
+ * another request's in-flight promise: use `getOrCreate` to wait on one.
28275
+ */
28276
+ get(key) {
28277
+ const settled = this.getEntry(key)?.settled;
28278
+ return settled ? Promise.resolve(settled.value) : null;
28279
+ }
28280
+ set(key, pending) {
28281
+ const entry = {
28282
+ expiresAt: Date.now() + this.ttlMs,
28283
+ pending,
28284
+ settled: null,
28285
+ bytes: 0,
28286
+ lastUsed: 0
28287
+ };
28288
+ this.delete(key);
28289
+ this.cache.set(key, entry);
28290
+ this.touch(entry);
28291
+ void pending.then(
28292
+ (value) => {
28293
+ if (!this.retainSettled) {
28294
+ if (this.cache.get(key) === entry) this.delete(key);
28295
+ return;
28296
+ }
28297
+ entry.settled = { value };
28298
+ this.recordSize(key, entry, value);
28299
+ },
28300
+ () => {
28301
+ }
28302
+ );
28303
+ this.enforceLimit();
28304
+ return pending;
28305
+ }
28306
+ getOrCreate(input3) {
28307
+ const cached2 = this.getEntry(input3.cacheKey);
28308
+ if (cached2?.settled) {
28309
+ return Promise.resolve(cached2.settled.value);
28310
+ }
28311
+ if (cached2) {
28312
+ return this.waitForInFlight(cached2, input3, { retried: false });
28313
+ }
28314
+ return this.createEntry(input3);
28315
+ }
28316
+ delete(key) {
28317
+ const entry = this.cache.get(key);
28318
+ if (!entry) {
28319
+ return;
28320
+ }
28321
+ this.cache.delete(key);
28322
+ if (entry.bytes > 0) {
28323
+ this.byteBudget?.adjust(-entry.bytes);
28324
+ entry.bytes = 0;
28325
+ }
28326
+ }
28327
+ /** Drop every entry whose key matches, e.g. one owner's prefix. */
28328
+ deleteWhere(matches) {
28329
+ for (const key of [...this.cache.keys()]) {
28330
+ if (matches(key)) this.delete(key);
28331
+ }
28332
+ }
28333
+ clear() {
28334
+ this.deleteWhere(() => true);
28335
+ }
28336
+ recordSize(key, entry, value) {
28337
+ const budget = this.byteBudget;
28338
+ if (!budget || this.cache.get(key) !== entry) {
28339
+ return;
28340
+ }
28341
+ const bytes = Math.max(1, this.sizeOf(value));
28342
+ if (bytes > budget.maxBytes) {
28343
+ this.delete(key);
28344
+ return;
28345
+ }
28346
+ entry.bytes = bytes;
28347
+ budget.adjust(bytes);
28348
+ budget.enforce();
28349
+ }
28350
+ createEntry(input3) {
28351
+ let pending;
28352
+ pending = input3.create().catch((error2) => {
28353
+ if (this.cache.get(input3.cacheKey)?.pending === pending) {
28354
+ this.delete(input3.cacheKey);
28355
+ }
28356
+ throw error2;
28357
+ });
28358
+ this.set(input3.cacheKey, pending);
28359
+ return pending;
28360
+ }
28361
+ /**
28362
+ * Await an entry another request may own. If it has not settled within
28363
+ * `inFlightWaitMs`, or it rejects, treat it as orphaned: replace it (when
28364
+ * it is still the cached entry) and run `create()` in this request. The
28365
+ * owner may have ended, and its failure is not this request's. A waiter
28366
+ * shares at most one other rebuild; if that one also fails or stalls, it
28367
+ * runs its own `create()`, so the only rejection a caller sees is one
28368
+ * from a `create()` it ran.
28369
+ */
28370
+ waitForInFlight(entry, input3, options) {
28371
+ return new Promise((resolve, reject) => {
28372
+ let done = false;
28373
+ const takeOver = () => {
28374
+ if (this.cache.get(input3.cacheKey) === entry) {
28375
+ this.delete(input3.cacheKey);
28376
+ }
28377
+ const current = this.getEntry(input3.cacheKey);
28378
+ const next2 = current?.settled ? Promise.resolve(current.settled.value) : !current || options.retried ? this.createEntry(input3) : this.waitForInFlight(current, input3, { retried: true });
28379
+ next2.then(resolve, reject);
28380
+ };
28381
+ const timer = Number.isFinite(this.inFlightWaitMs) ? setTimeout(() => {
28382
+ if (done) return;
28383
+ done = true;
28384
+ takeOver();
28385
+ }, this.inFlightWaitMs) : void 0;
28386
+ entry.pending.then(
28387
+ (value) => {
28388
+ if (done) return;
28389
+ done = true;
28390
+ clearTimeout(timer);
28391
+ resolve(value);
28392
+ },
28393
+ () => {
28394
+ if (done) return;
28395
+ done = true;
28396
+ clearTimeout(timer);
28397
+ takeOver();
28398
+ }
28399
+ );
28400
+ });
28401
+ }
28402
+ enforceLimit() {
28403
+ while (this.cache.size > this.limit) {
28404
+ const oldestKey = this.cache.keys().next().value;
28405
+ if (oldestKey === void 0) {
28406
+ break;
28407
+ }
28408
+ this.delete(oldestKey);
28409
+ }
28410
+ }
28411
+ };
28412
+ }
28413
+ });
28414
+
28107
28415
  // ../worker/src/identity/reserved-username-settings.ts
28416
+ var reservedUsernamesCacheTtlMs, reservedUsernameRecords;
28108
28417
  var init_reserved_username_settings = __esm({
28109
28418
  "../worker/src/identity/reserved-username-settings.ts"() {
28110
28419
  "use strict";
28111
28420
  init_public_urls();
28112
28421
  init_reserved_usernames2();
28113
28422
  init_live_sql();
28423
+ init_published_package_cache();
28424
+ reservedUsernamesCacheTtlMs = 3e4;
28425
+ reservedUsernameRecords = createPromiseLruCacheByBinding({
28426
+ ttlMs: reservedUsernamesCacheTtlMs,
28427
+ limit: 1
28428
+ });
28114
28429
  }
28115
28430
  });
28116
28431
 
@@ -28205,10 +28520,17 @@ LIMIT 1`;
28205
28520
  });
28206
28521
 
28207
28522
  // ../worker/src/package-app-custom-hostnames/lookup-cache.ts
28523
+ var packageAppCustomHostnameLookupCacheTtlMs, lookupCaches;
28208
28524
  var init_lookup_cache = __esm({
28209
28525
  "../worker/src/package-app-custom-hostnames/lookup-cache.ts"() {
28210
28526
  "use strict";
28211
28527
  init_lookup();
28528
+ init_published_package_cache();
28529
+ packageAppCustomHostnameLookupCacheTtlMs = 6e4;
28530
+ lookupCaches = createPromiseLruCacheByBinding({
28531
+ ttlMs: packageAppCustomHostnameLookupCacheTtlMs,
28532
+ limit: 2e3
28533
+ });
28212
28534
  }
28213
28535
  });
28214
28536
 
@@ -29038,283 +29360,6 @@ var init_service = __esm({
29038
29360
  }
29039
29361
  });
29040
29362
 
29041
- // ../worker/src/package-registry/published-package-cache.ts
29042
- function createPublishedPackageCacheKey(input3) {
29043
- if (!input3.source.published_commit) {
29044
- return null;
29045
- }
29046
- return JSON.stringify([
29047
- input3.userId,
29048
- input3.source.id,
29049
- input3.source.published_commit,
29050
- input3.source.manifest_path,
29051
- input3.source.source_root,
29052
- input3.entryPoint?.trim() || null
29053
- ]);
29054
- }
29055
- function estimateRetainedBytes(value) {
29056
- const seen = /* @__PURE__ */ new Set();
29057
- const stack = [value];
29058
- let bytes = 0;
29059
- while (stack.length > 0) {
29060
- const next2 = stack.pop();
29061
- if (typeof next2 === "string") {
29062
- bytes += next2.length;
29063
- continue;
29064
- }
29065
- if (next2 === null || typeof next2 !== "object" || seen.has(next2)) {
29066
- continue;
29067
- }
29068
- seen.add(next2);
29069
- if (ArrayBuffer.isView(next2) || next2 instanceof ArrayBuffer) {
29070
- bytes += next2.byteLength;
29071
- continue;
29072
- }
29073
- if (Array.isArray(next2)) {
29074
- stack.push(...next2);
29075
- continue;
29076
- }
29077
- const prototype = Object.getPrototypeOf(next2);
29078
- if (prototype !== Object.prototype && prototype !== null) {
29079
- continue;
29080
- }
29081
- for (const [key, child] of Object.entries(next2)) {
29082
- bytes += key.length;
29083
- stack.push(child);
29084
- }
29085
- }
29086
- return bytes;
29087
- }
29088
- function createPublishedPackagePromiseCache() {
29089
- return new PromiseLruCache({ byteBudget: packageArtifactCacheBudget });
29090
- }
29091
- var publishedPackageCacheLimit, publishedPackageCacheTtlMs, promiseLruCacheInFlightWaitMs, RetainedByteBudget, packageArtifactCacheMaxBytes, packageArtifactCacheBudget, PromiseLruCache;
29092
- var init_published_package_cache = __esm({
29093
- "../worker/src/package-registry/published-package-cache.ts"() {
29094
- "use strict";
29095
- publishedPackageCacheLimit = 50;
29096
- publishedPackageCacheTtlMs = 5 * 60 * 1e3;
29097
- promiseLruCacheInFlightWaitMs = 5e3;
29098
- RetainedByteBudget = class {
29099
- constructor(maxBytes) {
29100
- this.maxBytes = maxBytes;
29101
- }
29102
- maxBytes;
29103
- caches = /* @__PURE__ */ new Set();
29104
- usedBytes = 0;
29105
- clock = 0;
29106
- get retainedBytes() {
29107
- return this.usedBytes;
29108
- }
29109
- /** @internal */
29110
- tick() {
29111
- this.clock += 1;
29112
- return this.clock;
29113
- }
29114
- /** @internal */
29115
- register(cache) {
29116
- this.caches.add(cache);
29117
- }
29118
- /** @internal */
29119
- adjust(delta) {
29120
- this.usedBytes += delta;
29121
- }
29122
- /** @internal */
29123
- enforce() {
29124
- while (this.usedBytes > this.maxBytes) {
29125
- let oldest = null;
29126
- let oldestUsed = Number.POSITIVE_INFINITY;
29127
- for (const cache of this.caches) {
29128
- const candidate = cache.oldestSizedEntry();
29129
- if (candidate && candidate.lastUsed < oldestUsed) {
29130
- oldestUsed = candidate.lastUsed;
29131
- oldest = { cache, key: candidate.key };
29132
- }
29133
- }
29134
- if (!oldest) {
29135
- break;
29136
- }
29137
- oldest.cache.delete(oldest.key);
29138
- }
29139
- }
29140
- };
29141
- packageArtifactCacheMaxBytes = 24 * 1024 * 1024;
29142
- packageArtifactCacheBudget = new RetainedByteBudget(
29143
- packageArtifactCacheMaxBytes
29144
- );
29145
- PromiseLruCache = class {
29146
- cache = /* @__PURE__ */ new Map();
29147
- constructor(input3) {
29148
- this.ttlMs = input3?.ttlMs ?? publishedPackageCacheTtlMs;
29149
- this.limit = input3?.limit ?? publishedPackageCacheLimit;
29150
- this.inFlightWaitMs = input3?.inFlightWaitMs ?? promiseLruCacheInFlightWaitMs;
29151
- this.byteBudget = input3?.byteBudget ?? null;
29152
- this.sizeOf = input3?.sizeOf ?? estimateRetainedBytes;
29153
- this.byteBudget?.register(this);
29154
- }
29155
- ttlMs;
29156
- limit;
29157
- inFlightWaitMs;
29158
- byteBudget;
29159
- sizeOf;
29160
- /** @internal Least recently used settled entry that holds sized bytes. */
29161
- oldestSizedEntry() {
29162
- for (const [key, entry] of this.cache) {
29163
- if (entry.bytes > 0) {
29164
- return { key, lastUsed: entry.lastUsed };
29165
- }
29166
- }
29167
- return null;
29168
- }
29169
- touch(entry) {
29170
- if (this.byteBudget) {
29171
- entry.lastUsed = this.byteBudget.tick();
29172
- }
29173
- }
29174
- getEntry(key) {
29175
- const cached2 = this.cache.get(key);
29176
- if (!cached2) {
29177
- return null;
29178
- }
29179
- if (cached2.expiresAt <= Date.now()) {
29180
- this.delete(key);
29181
- return null;
29182
- }
29183
- this.cache.delete(key);
29184
- this.cache.set(key, cached2);
29185
- this.touch(cached2);
29186
- return cached2;
29187
- }
29188
- /**
29189
- * A settled value, as a promise owned by the caller's request. Never
29190
- * another request's in-flight promise: use `getOrCreate` to wait on one.
29191
- */
29192
- get(key) {
29193
- const settled = this.getEntry(key)?.settled;
29194
- return settled ? Promise.resolve(settled.value) : null;
29195
- }
29196
- set(key, pending) {
29197
- const entry = {
29198
- expiresAt: Date.now() + this.ttlMs,
29199
- pending,
29200
- settled: null,
29201
- bytes: 0,
29202
- lastUsed: 0
29203
- };
29204
- this.delete(key);
29205
- this.cache.set(key, entry);
29206
- this.touch(entry);
29207
- void pending.then(
29208
- (value) => {
29209
- entry.settled = { value };
29210
- this.recordSize(key, entry, value);
29211
- },
29212
- () => {
29213
- }
29214
- );
29215
- this.enforceLimit();
29216
- return pending;
29217
- }
29218
- getOrCreate(input3) {
29219
- const cached2 = this.getEntry(input3.cacheKey);
29220
- if (cached2?.settled) {
29221
- return Promise.resolve(cached2.settled.value);
29222
- }
29223
- if (cached2) {
29224
- return this.waitForInFlight(cached2, input3, { retried: false });
29225
- }
29226
- return this.createEntry(input3);
29227
- }
29228
- delete(key) {
29229
- const entry = this.cache.get(key);
29230
- if (!entry) {
29231
- return;
29232
- }
29233
- this.cache.delete(key);
29234
- if (entry.bytes > 0) {
29235
- this.byteBudget?.adjust(-entry.bytes);
29236
- entry.bytes = 0;
29237
- }
29238
- }
29239
- recordSize(key, entry, value) {
29240
- const budget = this.byteBudget;
29241
- if (!budget || this.cache.get(key) !== entry) {
29242
- return;
29243
- }
29244
- const bytes = Math.max(1, this.sizeOf(value));
29245
- if (bytes > budget.maxBytes) {
29246
- this.delete(key);
29247
- return;
29248
- }
29249
- entry.bytes = bytes;
29250
- budget.adjust(bytes);
29251
- budget.enforce();
29252
- }
29253
- createEntry(input3) {
29254
- let pending;
29255
- pending = input3.create().catch((error2) => {
29256
- if (this.cache.get(input3.cacheKey)?.pending === pending) {
29257
- this.delete(input3.cacheKey);
29258
- }
29259
- throw error2;
29260
- });
29261
- this.set(input3.cacheKey, pending);
29262
- return pending;
29263
- }
29264
- /**
29265
- * Await an entry another request may own. If it has not settled within
29266
- * `inFlightWaitMs`, or it rejects, treat it as orphaned: replace it (when
29267
- * it is still the cached entry) and run `create()` in this request. The
29268
- * owner may have ended, and its failure is not this request's. A waiter
29269
- * shares at most one other rebuild; if that one also fails or stalls, it
29270
- * runs its own `create()`, so the only rejection a caller sees is one
29271
- * from a `create()` it ran.
29272
- */
29273
- waitForInFlight(entry, input3, options) {
29274
- return new Promise((resolve, reject) => {
29275
- let done = false;
29276
- const takeOver = () => {
29277
- if (this.cache.get(input3.cacheKey) === entry) {
29278
- this.delete(input3.cacheKey);
29279
- }
29280
- const current = this.getEntry(input3.cacheKey);
29281
- const next2 = current?.settled ? Promise.resolve(current.settled.value) : !current || options.retried ? this.createEntry(input3) : this.waitForInFlight(current, input3, { retried: true });
29282
- next2.then(resolve, reject);
29283
- };
29284
- const timer = setTimeout(() => {
29285
- if (done) return;
29286
- done = true;
29287
- takeOver();
29288
- }, this.inFlightWaitMs);
29289
- entry.pending.then(
29290
- (value) => {
29291
- if (done) return;
29292
- done = true;
29293
- clearTimeout(timer);
29294
- resolve(value);
29295
- },
29296
- () => {
29297
- if (done) return;
29298
- done = true;
29299
- clearTimeout(timer);
29300
- takeOver();
29301
- }
29302
- );
29303
- });
29304
- }
29305
- enforceLimit() {
29306
- while (this.cache.size > this.limit) {
29307
- const oldestKey = this.cache.keys().next().value;
29308
- if (oldestKey === void 0) {
29309
- break;
29310
- }
29311
- this.delete(oldestKey);
29312
- }
29313
- }
29314
- };
29315
- }
29316
- });
29317
-
29318
29363
  // ../worker/src/credentials/credential-suppliers-flag.ts
29319
29364
  function createEnabledByOrgCache() {
29320
29365
  return new PromiseLruCache({
@@ -198748,7 +198793,7 @@ var init_disconnected = __esm({
198748
198793
  });
198749
198794
 
198750
198795
  // ../worker/src/mcp/secrets/repo.ts
198751
- var newCredentialPlacementJson;
198796
+ var newCredentialPlacementJson, inflightSecretBuckets;
198752
198797
  var init_repo3 = __esm({
198753
198798
  "../worker/src/mcp/secrets/repo.ts"() {
198754
198799
  "use strict";
@@ -198760,10 +198805,14 @@ var init_repo3 = __esm({
198760
198805
  init_placement_origin();
198761
198806
  init_disconnected();
198762
198807
  init_live_sql();
198808
+ init_published_package_cache();
198763
198809
  init_types6();
198764
198810
  newCredentialPlacementJson = serializeCredentialFillPlacement(
198765
198811
  defaultNewCredentialFillPlacement
198766
198812
  );
198813
+ inflightSecretBuckets = createPromiseLruCacheByBinding({
198814
+ retainSettled: false
198815
+ });
198767
198816
  }
198768
198817
  });
198769
198818
 
@@ -201883,6 +201932,7 @@ var init_package_app_owner = __esm({
201883
201932
  init_personal_org_id();
201884
201933
  init_invoke_contract_cache();
201885
201934
  init_published_package_cache();
201935
+ init_request_context();
201886
201936
  init_owner_person_ids();
201887
201937
  packageAppOwnerRowCache = new PromiseLruCache({
201888
201938
  ttlMs: invokeContractFreshnessTtlMs,
@@ -202184,6 +202234,7 @@ var init_service3 = __esm({
202184
202234
  });
202185
202235
 
202186
202236
  // ../worker/src/integrations/token-refresh.ts
202237
+ var inFlightIntegrationTokenRefreshes;
202187
202238
  var init_token_refresh = __esm({
202188
202239
  "../worker/src/integrations/token-refresh.ts"() {
202189
202240
  "use strict";
@@ -202199,6 +202250,8 @@ var init_token_refresh = __esm({
202199
202250
  init_secure_credential_url();
202200
202251
  init_service3();
202201
202252
  init_live_sql();
202253
+ init_published_package_cache();
202254
+ inFlightIntegrationTokenRefreshes = new PromiseLruCache({ retainSettled: false });
202202
202255
  }
202203
202256
  });
202204
202257
 
@@ -203078,39 +203131,16 @@ var init_d1_storage_reconciliation = __esm({
203078
203131
 
203079
203132
  // ../worker/src/entitlements/service.ts
203080
203133
  function createEntitlementLookupCache() {
203081
- const cachesByDb = /* @__PURE__ */ new WeakMap();
203134
+ const caches = createPromiseLruCacheByBinding({
203135
+ ttlMs: entitlementLookupCacheTtlMs,
203136
+ limit: entitlementLookupCacheMaxEntries
203137
+ });
203082
203138
  return {
203083
- async getOrCreate(db, key, create) {
203084
- let cache = cachesByDb.get(db);
203085
- if (!cache) {
203086
- cache = /* @__PURE__ */ new Map();
203087
- cachesByDb.set(db, cache);
203088
- }
203089
- const nowMs = Date.now();
203090
- const existing = cache.get(key);
203091
- if (existing && existing.expiresAtMs > nowMs) {
203092
- return await existing.value;
203093
- }
203094
- const value = create();
203095
- value.catch(() => {
203096
- if (cache.get(key)?.value === value) cache.delete(key);
203097
- });
203098
- if (cache.size >= entitlementLookupCacheMaxEntries) {
203099
- const oldestKey = cache.keys().next().value;
203100
- if (oldestKey !== void 0) cache.delete(oldestKey);
203101
- }
203102
- cache.set(key, {
203103
- value,
203104
- expiresAtMs: nowMs + entitlementLookupCacheTtlMs
203105
- });
203106
- return await value;
203139
+ getOrCreate(db, key, create) {
203140
+ return caches.for(db).getOrCreate({ cacheKey: key, create });
203107
203141
  },
203108
203142
  deleteByKeyPrefix(db, keyPrefix) {
203109
- const cache = cachesByDb.get(db);
203110
- if (!cache) return;
203111
- for (const key of [...cache.keys()]) {
203112
- if (key.startsWith(keyPrefix)) cache.delete(key);
203113
- }
203143
+ caches.for(db).deleteWhere((key) => key.startsWith(keyPrefix));
203114
203144
  }
203115
203145
  };
203116
203146
  }
@@ -203124,6 +203154,7 @@ var init_service5 = __esm({
203124
203154
  init_referral_program();
203125
203155
  init_second_agent_standard_gift();
203126
203156
  init_mailbox_internal_read();
203157
+ init_published_package_cache();
203127
203158
  init_jobs_data();
203128
203159
  init_repo_sessions();
203129
203160
  init_service4();
@@ -207098,6 +207129,7 @@ var init_login_resolver = __esm({
207098
207129
  "../worker/src/credentials/login-resolver.ts"() {
207099
207130
  "use strict";
207100
207131
  init_isolate_state();
207132
+ init_published_package_cache();
207101
207133
  init_zod();
207102
207134
  init_read_bounded_body();
207103
207135
  init_ssrf();
@@ -207175,7 +207207,7 @@ var init_login_resolver = __esm({
207175
207207
  ]);
207176
207208
  sessions = isolateCollection(/* @__PURE__ */ new Map());
207177
207209
  pendingSessions = isolateCollection(
207178
- /* @__PURE__ */ new Map()
207210
+ new PromiseLruCache({ retainSettled: false })
207179
207211
  );
207180
207212
  }
207181
207213
  });