bullmq 5.66.5 → 5.66.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 (36) hide show
  1. package/dist/cjs/commands/includes/moveChildFromDependenciesIfNeeded.lua +4 -11
  2. package/dist/cjs/commands/includes/removeJobsByMaxAge.lua +2 -3
  3. package/dist/cjs/commands/moveToFinished-14.lua +2 -1
  4. package/dist/cjs/interfaces/index.js +0 -1
  5. package/dist/cjs/interfaces/index.js.map +1 -1
  6. package/dist/cjs/scripts/moveToFinished-14.js +152 -186
  7. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  8. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  9. package/dist/cjs/types/index.js +1 -0
  10. package/dist/cjs/types/index.js.map +1 -1
  11. package/dist/{esm/interfaces → cjs/types}/keep-jobs.js.map +1 -1
  12. package/dist/cjs/version.js +1 -1
  13. package/dist/esm/classes/scripts.d.ts +2 -2
  14. package/dist/esm/commands/includes/moveChildFromDependenciesIfNeeded.lua +4 -11
  15. package/dist/esm/commands/includes/removeJobsByMaxAge.lua +2 -3
  16. package/dist/esm/commands/moveToFinished-14.lua +2 -1
  17. package/dist/esm/interfaces/base-job-options.d.ts +1 -1
  18. package/dist/esm/interfaces/index.d.ts +0 -1
  19. package/dist/esm/interfaces/index.js +0 -1
  20. package/dist/esm/interfaces/index.js.map +1 -1
  21. package/dist/esm/interfaces/worker-options.d.ts +1 -1
  22. package/dist/esm/scripts/moveToFinished-14.js +152 -186
  23. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  24. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  25. package/dist/esm/types/index.d.ts +1 -0
  26. package/dist/esm/types/index.js +1 -0
  27. package/dist/esm/types/index.js.map +1 -1
  28. package/dist/esm/{interfaces → types}/keep-jobs.d.ts +12 -3
  29. package/dist/{cjs/interfaces → esm/types}/keep-jobs.js.map +1 -1
  30. package/dist/esm/version.d.ts +1 -1
  31. package/dist/esm/version.js +1 -1
  32. package/package.json +6 -6
  33. package/dist/cjs/commands/includes/removeJobsOnFail.lua +0 -36
  34. package/dist/esm/commands/includes/removeJobsOnFail.lua +0 -36
  35. /package/dist/cjs/{interfaces → types}/keep-jobs.js +0 -0
  36. /package/dist/esm/{interfaces → types}/keep-jobs.js +0 -0
@@ -7,7 +7,6 @@ export * from './flow-job';
7
7
  export * from './ioredis-events';
8
8
  export * from './job-json';
9
9
  export * from './job-scheduler-json';
10
- export * from './keep-jobs';
11
10
  export * from './lock-manager-worker-context';
12
11
  export * from './metrics-options';
13
12
  export * from './metrics';
@@ -7,7 +7,6 @@ export * from './flow-job';
7
7
  export * from './ioredis-events';
8
8
  export * from './job-json';
9
9
  export * from './job-scheduler-json';
10
- export * from './keep-jobs';
11
10
  export * from './lock-manager-worker-context';
12
11
  export * from './metrics-options';
13
12
  export * from './metrics';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,aAAa,CAAC;AAC5B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,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@@ -2,7 +2,7 @@ import { AdvancedOptions } from './advanced-options';
2
2
  import { QueueBaseOptions } from './queue-options';
3
3
  import { RateLimiterOptions } from './rate-limiter-options';
4
4
  import { MetricsOptions } from './metrics-options';
5
- import { KeepJobs } from './keep-jobs';
5
+ import { KeepJobs } from '../types/keep-jobs';
6
6
  import { Telemetry } from './telemetry';
7
7
  import { SandboxedOptions } from './sandboxed-options';
8
8
  export interface WorkerOptions extends QueueBaseOptions, SandboxedOptions {
@@ -289,200 +289,19 @@ local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDep
289
289
  moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
290
290
  end
291
291
  end
292
- --[[
293
- Functions to remove jobs when removeOnFail option is provided.
294
- ]]
295
- -- Includes
296
- --[[
297
- Function to remove job.
298
- ]]
299
- -- Includes
300
- --[[
301
- Function to remove deduplication key if needed
302
- when a job is being removed.
303
- ]]
304
- local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
305
- jobId, deduplicationId)
306
- if deduplicationId then
307
- local deduplicationKey = prefixKey .. "de:" .. deduplicationId
308
- local currentJobId = rcall('GET', deduplicationKey)
309
- if currentJobId and currentJobId == jobId then
310
- return rcall("DEL", deduplicationKey)
311
- end
312
- end
313
- end
314
- --[[
315
- Function to remove job keys.
316
- ]]
317
- local function removeJobKeys(jobKey)
318
- return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
319
- jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
320
- end
321
- --[[
322
- Check if this job has a parent. If so we will just remove it from
323
- the parent child list, but if it is the last child we should move the parent to "wait/paused"
324
- which requires code from "moveToFinished"
325
- ]]
326
- -- Includes
327
- --[[
328
- Functions to destructure job key.
329
- Just a bit of warning, these functions may be a bit slow and affect performance significantly.
330
- ]]
331
- local getJobIdFromKey = function (jobKey)
332
- return string.match(jobKey, ".*:(.*)")
333
- end
334
- local getJobKeyPrefix = function (jobKey, jobId)
335
- return string.sub(jobKey, 0, #jobKey - #jobId)
336
- end
337
- local function _moveParentToWait(parentPrefix, parentId, emitEvent)
338
- local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
339
- parentPrefix .. "wait", parentPrefix .. "paused")
340
- addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
341
- if emitEvent then
342
- local parentEventStream = parentPrefix .. "events"
343
- rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
344
- end
345
- end
346
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
347
- if parentKey then
348
- local parentDependenciesKey = parentKey .. ":dependencies"
349
- local result = rcall("SREM", parentDependenciesKey, jobKey)
350
- if result > 0 then
351
- local pendingDependencies = rcall("SCARD", parentDependenciesKey)
352
- if pendingDependencies == 0 then
353
- local parentId = getJobIdFromKey(parentKey)
354
- local parentPrefix = getJobKeyPrefix(parentKey, parentId)
355
- local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
356
- if numRemovedElements == 1 then
357
- if hard then -- remove parent in same queue
358
- if parentPrefix == baseKey then
359
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
360
- removeJobKeys(parentKey)
361
- if debounceId then
362
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
363
- end
364
- else
365
- _moveParentToWait(parentPrefix, parentId)
366
- end
367
- else
368
- _moveParentToWait(parentPrefix, parentId, true)
369
- end
370
- end
371
- end
372
- return true
373
- end
374
- else
375
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
376
- local missedParentKey = parentAttributes[1]
377
- if( (type(missedParentKey) == "string") and missedParentKey ~= ""
378
- and (rcall("EXISTS", missedParentKey) == 1)) then
379
- local parentDependenciesKey = missedParentKey .. ":dependencies"
380
- local result = rcall("SREM", parentDependenciesKey, jobKey)
381
- if result > 0 then
382
- local pendingDependencies = rcall("SCARD", parentDependenciesKey)
383
- if pendingDependencies == 0 then
384
- local parentId = getJobIdFromKey(missedParentKey)
385
- local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
386
- local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
387
- if numRemovedElements == 1 then
388
- if hard then
389
- if parentPrefix == baseKey then
390
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
391
- removeJobKeys(missedParentKey)
392
- if parentAttributes[2] then
393
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
394
- end
395
- else
396
- _moveParentToWait(parentPrefix, parentId)
397
- end
398
- else
399
- _moveParentToWait(parentPrefix, parentId, true)
400
- end
401
- end
402
- end
403
- return true
404
- end
405
- end
406
- end
407
- return false
408
- end
409
- local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
410
- local jobKey = baseKey .. jobId
411
- removeParentDependencyKey(jobKey, hard, nil, baseKey)
412
- if shouldRemoveDeduplicationKey then
413
- local deduplicationId = rcall("HGET", jobKey, "deid")
414
- removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobId, deduplicationId)
415
- end
416
- removeJobKeys(jobKey)
417
- end
418
- --[[
419
- Functions to remove jobs by max age.
420
- ]]
421
- -- Includes
422
- local function removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix,
423
- shouldRemoveDebounceKey)
424
- local start = timestamp - maxAge * 1000
425
- local jobIds = rcall("ZREVRANGEBYSCORE", targetSet, start, "-inf")
426
- for i, jobId in ipairs(jobIds) do
427
- removeJob(jobId, false, prefix, false --[[remove debounce key]])
428
- end
429
- rcall("ZREMRANGEBYSCORE", targetSet, "-inf", start)
430
- end
431
- --[[
432
- Functions to remove jobs by max count.
433
- ]]
434
- -- Includes
435
- local function removeJobsByMaxCount(maxCount, targetSet, prefix)
436
- local start = maxCount
437
- local jobIds = rcall("ZREVRANGE", targetSet, start, -1)
438
- for i, jobId in ipairs(jobIds) do
439
- removeJob(jobId, false, prefix, false --[[remove debounce key]])
440
- end
441
- rcall("ZREMRANGEBYRANK", targetSet, 0, -(maxCount + 1))
442
- end
443
- local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestamp)
444
- local removeOnFailType = type(opts["removeOnFail"])
445
- if removeOnFailType == "number" then
446
- removeJobsByMaxCount(opts["removeOnFail"],
447
- failedKey, queueKeyPrefix)
448
- elseif removeOnFailType == "boolean" then
449
- if opts["removeOnFail"] then
450
- removeJob(jobId, false, queueKeyPrefix,
451
- false --[[remove debounce key]])
452
- rcall("ZREM", failedKey, jobId)
453
- end
454
- elseif removeOnFailType ~= "nil" then
455
- local maxAge = opts["removeOnFail"]["age"]
456
- local maxCount = opts["removeOnFail"]["count"]
457
- if maxAge ~= nil then
458
- removeJobsByMaxAge(timestamp, maxAge,
459
- failedKey, queueKeyPrefix)
460
- end
461
- if maxCount ~= nil and maxCount > 0 then
462
- removeJobsByMaxCount(maxCount, failedKey,
463
- queueKeyPrefix)
464
- end
465
- end
466
- end
467
- local moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
292
+ local handleChildFailureAndMoveParentToWait = function (parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
468
293
  if rcall("EXISTS", parentKey) == 1 then
469
294
  local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
470
295
  local parentDelayedKey = parentQueueKey .. ":delayed"
471
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
472
296
  local parentWaitingChildrenOrDelayedKey
473
- local prevState
474
297
  if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
475
298
  parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
476
- prevState = "waiting-children"
477
299
  elseif rcall("ZSCORE", parentDelayedKey, parentId) then
478
300
  parentWaitingChildrenOrDelayedKey = parentDelayedKey
479
- prevState = "delayed"
480
301
  rcall("HSET", parentKey, "delay", 0)
481
302
  end
482
303
  if parentWaitingChildrenOrDelayedKey then
483
304
  rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
484
- local parentQueuePrefix = parentQueueKey .. ":"
485
- local parentFailedKey = parentQueueKey .. ":failed"
486
305
  local deferredFailure = "child " .. jobIdKey .. " failed"
487
306
  rcall("HSET", parentKey, "defa", deferredFailure)
488
307
  moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
@@ -501,9 +320,9 @@ local moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, fai
501
320
  local parentDependenciesChildrenKey = parentKey .. ":dependencies"
502
321
  if parentData['fpof'] then
503
322
  if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
504
- local parentUnsuccesssfulChildrenKey = parentKey .. ":unsuccessful"
505
- rcall("ZADD", parentUnsuccesssfulChildrenKey, timestamp, childKey)
506
- moveParentToFailedIfNeeded(
323
+ local parentUnsuccessfulChildrenKey = parentKey .. ":unsuccessful"
324
+ rcall("ZADD", parentUnsuccessfulChildrenKey, timestamp, childKey)
325
+ handleChildFailureAndMoveParentToWait(
507
326
  parentData['queueKey'],
508
327
  parentKey,
509
328
  parentData['id'],
@@ -619,6 +438,152 @@ local function removeDeduplicationKeyIfNeededOnFinalization(prefixKey,
619
438
  end
620
439
  end
621
440
  end
441
+ --[[
442
+ Function to remove job keys.
443
+ ]]
444
+ local function removeJobKeys(jobKey)
445
+ return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
446
+ jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
447
+ end
448
+ --[[
449
+ Functions to remove jobs by max age.
450
+ ]]
451
+ -- Includes
452
+ --[[
453
+ Function to remove job.
454
+ ]]
455
+ -- Includes
456
+ --[[
457
+ Function to remove deduplication key if needed
458
+ when a job is being removed.
459
+ ]]
460
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
461
+ jobId, deduplicationId)
462
+ if deduplicationId then
463
+ local deduplicationKey = prefixKey .. "de:" .. deduplicationId
464
+ local currentJobId = rcall('GET', deduplicationKey)
465
+ if currentJobId and currentJobId == jobId then
466
+ return rcall("DEL", deduplicationKey)
467
+ end
468
+ end
469
+ end
470
+ --[[
471
+ Check if this job has a parent. If so we will just remove it from
472
+ the parent child list, but if it is the last child we should move the parent to "wait/paused"
473
+ which requires code from "moveToFinished"
474
+ ]]
475
+ -- Includes
476
+ --[[
477
+ Functions to destructure job key.
478
+ Just a bit of warning, these functions may be a bit slow and affect performance significantly.
479
+ ]]
480
+ local getJobIdFromKey = function (jobKey)
481
+ return string.match(jobKey, ".*:(.*)")
482
+ end
483
+ local getJobKeyPrefix = function (jobKey, jobId)
484
+ return string.sub(jobKey, 0, #jobKey - #jobId)
485
+ end
486
+ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
487
+ local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
488
+ parentPrefix .. "wait", parentPrefix .. "paused")
489
+ addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
490
+ if emitEvent then
491
+ local parentEventStream = parentPrefix .. "events"
492
+ rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
493
+ end
494
+ end
495
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
496
+ if parentKey then
497
+ local parentDependenciesKey = parentKey .. ":dependencies"
498
+ local result = rcall("SREM", parentDependenciesKey, jobKey)
499
+ if result > 0 then
500
+ local pendingDependencies = rcall("SCARD", parentDependenciesKey)
501
+ if pendingDependencies == 0 then
502
+ local parentId = getJobIdFromKey(parentKey)
503
+ local parentPrefix = getJobKeyPrefix(parentKey, parentId)
504
+ local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
505
+ if numRemovedElements == 1 then
506
+ if hard then -- remove parent in same queue
507
+ if parentPrefix == baseKey then
508
+ removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
509
+ removeJobKeys(parentKey)
510
+ if debounceId then
511
+ rcall("DEL", parentPrefix .. "de:" .. debounceId)
512
+ end
513
+ else
514
+ _moveParentToWait(parentPrefix, parentId)
515
+ end
516
+ else
517
+ _moveParentToWait(parentPrefix, parentId, true)
518
+ end
519
+ end
520
+ end
521
+ return true
522
+ end
523
+ else
524
+ local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
525
+ local missedParentKey = parentAttributes[1]
526
+ if( (type(missedParentKey) == "string") and missedParentKey ~= ""
527
+ and (rcall("EXISTS", missedParentKey) == 1)) then
528
+ local parentDependenciesKey = missedParentKey .. ":dependencies"
529
+ local result = rcall("SREM", parentDependenciesKey, jobKey)
530
+ if result > 0 then
531
+ local pendingDependencies = rcall("SCARD", parentDependenciesKey)
532
+ if pendingDependencies == 0 then
533
+ local parentId = getJobIdFromKey(missedParentKey)
534
+ local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
535
+ local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
536
+ if numRemovedElements == 1 then
537
+ if hard then
538
+ if parentPrefix == baseKey then
539
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
540
+ removeJobKeys(missedParentKey)
541
+ if parentAttributes[2] then
542
+ rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
543
+ end
544
+ else
545
+ _moveParentToWait(parentPrefix, parentId)
546
+ end
547
+ else
548
+ _moveParentToWait(parentPrefix, parentId, true)
549
+ end
550
+ end
551
+ end
552
+ return true
553
+ end
554
+ end
555
+ end
556
+ return false
557
+ end
558
+ local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
559
+ local jobKey = baseKey .. jobId
560
+ removeParentDependencyKey(jobKey, hard, nil, baseKey)
561
+ if shouldRemoveDeduplicationKey then
562
+ local deduplicationId = rcall("HGET", jobKey, "deid")
563
+ removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobId, deduplicationId)
564
+ end
565
+ removeJobKeys(jobKey)
566
+ end
567
+ local function removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix, maxLimit)
568
+ local start = timestamp - maxAge * 1000
569
+ local jobIds = rcall("ZREVRANGEBYSCORE", targetSet, start, "-inf", "LIMIT", 0, maxLimit)
570
+ for i, jobId in ipairs(jobIds) do
571
+ removeJob(jobId, false, prefix, false --[[remove debounce key]])
572
+ end
573
+ rcall("ZREMRANGEBYSCORE", targetSet, "-inf", start)
574
+ end
575
+ --[[
576
+ Functions to remove jobs by max count.
577
+ ]]
578
+ -- Includes
579
+ local function removeJobsByMaxCount(maxCount, targetSet, prefix)
580
+ local start = maxCount
581
+ local jobIds = rcall("ZREVRANGE", targetSet, start, -1)
582
+ for i, jobId in ipairs(jobIds) do
583
+ removeJob(jobId, false, prefix, false --[[remove debounce key]])
584
+ end
585
+ rcall("ZREMRANGEBYRANK", targetSet, 0, -(maxCount + 1))
586
+ end
622
587
  local function removeLock(jobKey, stalledKey, token, jobId)
623
588
  if token ~= "0" then
624
589
  local lockKey = jobKey .. ':lock'
@@ -705,6 +670,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
705
670
  local maxMetricsSize = opts['maxMetricsSize']
706
671
  local maxCount = opts['keepJobs']['count']
707
672
  local maxAge = opts['keepJobs']['age']
673
+ local maxLimit = opts['keepJobs']['limit'] or 1000
708
674
  local jobAttributes = rcall("HMGET", jobIdKey, "parentKey", "parent", "deid")
709
675
  local parentKey = jobAttributes[1] or ""
710
676
  local parentId = ""
@@ -760,7 +726,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
760
726
  end
761
727
  -- Remove old jobs?
762
728
  if maxAge ~= nil then
763
- removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix)
729
+ removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix, maxLimit)
764
730
  end
765
731
  if maxCount ~= nil and maxCount > 0 then
766
732
  removeJobsByMaxCount(maxCount, targetSet, prefix)
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;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