@guren/server 2.25.1 → 2.26.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.
Files changed (79) hide show
  1. package/dist/{Gate-YOt54xGF.js → Gate-BL_zW82W.js} +1 -1
  2. package/dist/{Job-COMzBNOL.js → Job-DsFMcXVk.js} +35 -3
  3. package/dist/{Resource-BdYd4J9a.js → Resource-gki0_2B6.js} +172 -37
  4. package/dist/agent/scopes.d.ts +1 -3
  5. package/dist/auth/email-verification.d.ts +6 -0
  6. package/dist/auth/index.js +1 -1
  7. package/dist/auth/password-reset.d.ts +8 -2
  8. package/dist/{auth-vFeem6uM.js → auth-DiyWALZT.js} +38 -9
  9. package/dist/authorization/index.js +2 -2
  10. package/dist/{authorization-BLhwA2Yh.js → authorization-E6X6Y-B6.js} +1 -1
  11. package/dist/broadcasting/index.js +1 -1
  12. package/dist/{broadcasting-BUBCPCnu.js → broadcasting-D0vMkKcq.js} +1 -1
  13. package/dist/cache/index.js +1 -1
  14. package/dist/cache/stores/FileStore.d.ts +2 -0
  15. package/dist/cache/stores/MemoryStore.d.ts +1 -0
  16. package/dist/cache/stores/RedisStore.d.ts +1 -0
  17. package/dist/cache/types.d.ts +2 -0
  18. package/dist/{cache-93n2PCnB.js → cache-DcnRufMe.js} +94 -25
  19. package/dist/contained-path-BkNSBljW.js +78 -0
  20. package/dist/container/Container.d.ts +6 -2
  21. package/dist/container/defineModule.d.ts +10 -0
  22. package/dist/{default-application-D5ezhhiV.js → default-application-DWwscxfW.js} +14 -18
  23. package/dist/encryption/index.js +1 -1
  24. package/dist/{encryption-D1dxfMqD.js → encryption-CWK5l22W.js} +1 -1
  25. package/dist/events/EventManager.d.ts +2 -0
  26. package/dist/events/index.js +1 -1
  27. package/dist/{events-c94CdUFc.js → events-DQavGm8W.js} +20 -7
  28. package/dist/health/HealthManager.d.ts +0 -1
  29. package/dist/health/index.js +1 -1
  30. package/dist/{health-CB0oS_UE.js → health-Bg0Xj3aD.js} +8 -8
  31. package/dist/http/Application.d.ts +12 -1
  32. package/dist/http/middleware/rate-limit.d.ts +1 -4
  33. package/dist/i18n/index.js +1 -1
  34. package/dist/{i18n-DqcRD4qL.js → i18n-DmMKcbqj.js} +1 -1
  35. package/dist/index.d.ts +3 -1
  36. package/dist/index.js +61 -50
  37. package/dist/internal/app-conventions.d.ts +6 -0
  38. package/dist/internal/app-conventions.js +9 -0
  39. package/dist/internal/testing.d.ts +1 -1
  40. package/dist/internal/testing.js +2 -2
  41. package/dist/lambda/index.js +66 -28
  42. package/dist/logging/index.js +1 -1
  43. package/dist/{logging-YbKmbAd7.js → logging-Ci0mBk5k.js} +1 -1
  44. package/dist/mail/index.js +1 -1
  45. package/dist/{mail-uRBrUl9q.js → mail-CI2Kfe8P.js} +2 -2
  46. package/dist/mvc/Controller.d.ts +3 -2
  47. package/dist/mvc/inertia/InertiaEngine.d.ts +31 -0
  48. package/dist/mvc/inertia/props.d.ts +71 -0
  49. package/dist/notifications/index.js +1 -1
  50. package/dist/notifications/registry.d.ts +2 -2
  51. package/dist/{notifications-LHuujttf.js → notifications-Bp2uamzD.js} +7 -5
  52. package/dist/providers/ConfigServiceProvider.d.ts +5 -5
  53. package/dist/queue/Job.d.ts +5 -0
  54. package/dist/queue/Worker.d.ts +6 -1
  55. package/dist/queue/drivers/RedisDriver.d.ts +4 -2
  56. package/dist/queue/drivers/SqsDriver.d.ts +31 -2
  57. package/dist/queue/drivers/redis-queue-scripts.d.ts +83 -0
  58. package/dist/queue/index.js +2 -2
  59. package/dist/queue/serialize.d.ts +7 -0
  60. package/dist/queue/types.d.ts +13 -2
  61. package/dist/{queue-BiBn5Sff.js → queue-Bo4Q857L.js} +294 -125
  62. package/dist/redis/RedisEmailVerificationStore.d.ts +2 -0
  63. package/dist/redis/RedisPasswordResetStore.d.ts +2 -0
  64. package/dist/redis/auth-token-scripts.d.ts +4 -0
  65. package/dist/redis/index.js +50 -0
  66. package/dist/runtime/index.js +3 -36
  67. package/dist/scheduling/ScheduledTask.d.ts +2 -1
  68. package/dist/scheduling/index.js +1 -1
  69. package/dist/{scheduling-DhYfbJFj.js → scheduling-DNV5tj44.js} +32 -38
  70. package/dist/serialize-CKXek0Tr.js +17 -0
  71. package/dist/storage/drivers/LocalDriver.d.ts +15 -0
  72. package/dist/storage/index.js +1 -1
  73. package/dist/storage/url-path.d.ts +2 -0
  74. package/dist/{storage-6HLaUf9j.js → storage-wFsUJHZW.js} +78 -28
  75. package/dist/support/contained-path.d.ts +8 -0
  76. package/dist/support/registry-collision.d.ts +12 -0
  77. package/dist/{vite-manifest-DK55BTLk.js → vite-manifest-DlU94f3Z.js} +2 -2
  78. package/package.json +6 -2
  79. package/dist/trim-slashes-BLY9hKAa.js +0 -22
@@ -11,8 +11,8 @@ export interface NotificationConstructor {
11
11
  /**
12
12
  * Register a notification class so queued instances can be rebuilt. Queueing
13
13
  * registers automatically, which covers a worker in the same process; a worker
14
- * in a separate process must register at boot. Type names must be unique — a
15
- * second class under an existing type replaces the first.
14
+ * in a separate process must register at boot. A second class under a taken
15
+ * type warns and replaces the first.
16
16
  */
17
17
  export declare function registerNotification(notificationClass: NotificationConstructor, type?: string): void;
18
18
  export declare function getNotification(type: string): NotificationConstructor | undefined;
@@ -1,5 +1,5 @@
1
- import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-D5ezhhiV.js";
2
- import { l as registerJob, t as Job } from "./Job-COMzBNOL.js";
1
+ import { h as warnDeprecatedSetter, i as bindAmbient, m as warnDeprecatedGetter, n as ambientBinding } from "./default-application-DWwscxfW.js";
2
+ import { l as registerJob, p as reportRegistryCollision, t as Job } from "./Job-DsFMcXVk.js";
3
3
  import { t as parseMailAddress } from "./address-D0Iq-XIH.js";
4
4
  //#region src/notifications/Notification.ts
5
5
  /**
@@ -54,11 +54,13 @@ function resolveRegistryKey(notificationClass) {
54
54
  /**
55
55
  * Register a notification class so queued instances can be rebuilt. Queueing
56
56
  * registers automatically, which covers a worker in the same process; a worker
57
- * in a separate process must register at boot. Type names must be unique — a
58
- * second class under an existing type replaces the first.
57
+ * in a separate process must register at boot. A second class under a taken
58
+ * type warns and replaces the first.
59
59
  */
60
60
  function registerNotification(notificationClass, type) {
61
- notificationRegistry.set(type ?? resolveRegistryKey(notificationClass), notificationClass);
61
+ const key = type ?? resolveRegistryKey(notificationClass);
62
+ reportRegistryCollision("notification", key, notificationRegistry.get(key), notificationClass);
63
+ notificationRegistry.set(key, notificationClass);
62
64
  }
63
65
  function getNotification(type) {
64
66
  return notificationRegistry.get(type);
@@ -1,10 +1,10 @@
1
1
  import { ServiceProvider, type OwnedBinding } from '../container/ServiceProvider.js';
2
2
  /**
3
- * Validates `createApp({ env })` and binds it as `env`, then resolves and binds
4
- * each `createApp({ config })` definition (RFC 0027 §1-§3). Registered before
5
- * every other provider: a bad environment fails the boot before anything
6
- * registers, every later register() sees the configured managers, and a later
7
- * provider that rebinds one fails the boot through {@link ownedBindings}.
3
+ * Validates `createApp({ env })` and binds it as `env`, then resolves and binds each
4
+ * `createApp({ config })` definition, then each module's (RFC 0027 §1-§3, RFC 0002).
5
+ * Registered first: a bad environment fails the boot before anything registers,
6
+ * every later register() sees the configured managers, and a later provider that
7
+ * rebinds one fails the boot through {@link ownedBindings}.
8
8
  */
9
9
  export declare class ConfigServiceProvider extends ServiceProvider {
10
10
  private env;
@@ -53,6 +53,11 @@ export declare abstract class Job<T = unknown> {
53
53
  */
54
54
  static backoff: 'exponential' | 'linear' | number;
55
55
  private container?;
56
+ private executionSignal?;
57
+ /** Aborted when the worker times out or loses its reservation. Pass it to cancellable I/O. */
58
+ protected get signal(): AbortSignal;
59
+ /** @internal Installed by the worker before handle(). */
60
+ setExecutionSignal(signal: AbortSignal): void;
56
61
  /** @internal Called by the Worker with the container of the app it drains, before `handle()`. */
57
62
  setContainer(container: ContainerLike): void;
58
63
  /** Resolves from the worker's container, else from the default application. */
@@ -32,7 +32,12 @@ export declare class Worker {
32
32
  private processJob;
33
33
  private handleFailedJob;
34
34
  private instantiate;
35
- private executeWithTimeout;
35
+ /**
36
+ * Runs `handle()` under the timeout while renewing the driver's reservation. A
37
+ * timeout requests cancellation through the job's signal and then waits for the
38
+ * handler to settle, so a retry never runs beside its predecessor.
39
+ */
40
+ private runHandler;
36
41
  private sleepMs;
37
42
  }
38
43
  /** Process one job without a running worker, for tests and one-off execution. */
@@ -17,15 +17,17 @@ export declare class RedisDriver implements QueueDriver {
17
17
  private readonly prefix;
18
18
  private readonly visibilityTimeout;
19
19
  constructor(redis: Redis, options?: RedisDriverOptions);
20
+ private run;
21
+ get heartbeatInterval(): number;
22
+ extendReservation(job: QueuedJob): Promise<boolean>;
20
23
  private pendingKey;
21
24
  private reservedKey;
22
25
  private failedKey;
23
26
  private jobKey;
24
27
  push(job: QueuedJob): Promise<void>;
25
28
  pop(queue: string): Promise<QueuedJob | null>;
26
- private releaseTimedOutJobs;
27
29
  release(job: QueuedJob, delayMs?: number): Promise<void>;
28
- delete(jobId: string): Promise<void>;
30
+ delete(jobId: string, reservationToken?: string): Promise<void>;
29
31
  fail(job: QueuedJob, error: Error): Promise<void>;
30
32
  size(queue: string): Promise<number>;
31
33
  getFailedJobs(queue?: string): Promise<FailedJob[]>;
@@ -11,18 +11,37 @@ export interface SqsAdapter {
11
11
  messageGroupId?: string;
12
12
  messageDeduplicationId?: string;
13
13
  }): Promise<void>;
14
+ /**
15
+ * `receiveCount` is the SQS `ApproximateReceiveCount`; polling workers count
16
+ * retries with it, since the message body is never rewritten on redelivery.
17
+ * Omitting it warns once and falls back to the count in the body.
18
+ */
14
19
  receiveMessage(params: {
15
20
  queueUrl: string;
16
21
  waitTimeSeconds?: number;
17
22
  }): Promise<{
18
23
  body: string;
19
24
  receiptHandle: string;
25
+ receiveCount?: number;
20
26
  } | null>;
27
+ /**
28
+ * Optional so adapters written before this method keep compiling; without it
29
+ * SQS redelivers every acknowledged job once the visibility timeout expires.
30
+ */
31
+ deleteMessage?(params: {
32
+ queueUrl: string;
33
+ receiptHandle: string;
34
+ }): Promise<void>;
35
+ /**
36
+ * Resolves `false` when SQS reports the receipt handle expired (`ReceiptHandleIsInvalid`,
37
+ * `MessageNotInflight`): the message is visible to other consumers again. `void` counts
38
+ * as success, so an adapter written before this return existed keeps working.
39
+ */
21
40
  changeMessageVisibility(params: {
22
41
  queueUrl: string;
23
42
  receiptHandle: string;
24
43
  visibilityTimeout: number;
25
- }): Promise<void>;
44
+ }): Promise<void | boolean>;
26
45
  getApproximateMessageCount(queueUrl: string): Promise<number>;
27
46
  }
28
47
  export interface SqsDriverOptions {
@@ -31,6 +50,11 @@ export interface SqsDriverOptions {
31
50
  queueUrls?: Record<string, string>;
32
51
  /** Setting this enables FIFO mode. */
33
52
  messageGroupId?: string;
53
+ /**
54
+ * The queue's visibility timeout in seconds, re-applied to the in-flight message
55
+ * while `handle()` runs. Must match the SQS queue attribute. @default 30 (the SQS default)
56
+ */
57
+ visibilityTimeout?: number;
34
58
  }
35
59
  /** Builds an SqsAdapter over an @aws-sdk/client-sqs SQSClient. */
36
60
  export declare function createSqsAdapter(client: {
@@ -41,8 +65,11 @@ export declare class SqsDriver implements QueueDriver {
41
65
  private readonly adapter;
42
66
  private readonly options;
43
67
  private readonly failedJobs;
44
- private readonly receiptHandles;
68
+ private readonly reservations;
45
69
  constructor(adapter: SqsAdapter, options: SqsDriverOptions);
70
+ get heartbeatInterval(): number;
71
+ extendReservation(job: QueuedJob): Promise<boolean>;
72
+ private get visibilityTimeout();
46
73
  push(job: QueuedJob): Promise<void>;
47
74
  pop(queue: string): Promise<QueuedJob | null>;
48
75
  release(job: QueuedJob, delayMs?: number): Promise<void>;
@@ -53,5 +80,7 @@ export declare class SqsDriver implements QueueDriver {
53
80
  retryFailedJob(jobId: string): Promise<void>;
54
81
  deleteFailedJob(jobId: string): Promise<void>;
55
82
  clear(): Promise<void>;
83
+ /** Drops the reservation only once SQS has accepted the deletion. */
84
+ private acknowledge;
56
85
  private resolveQueueUrl;
57
86
  }
@@ -0,0 +1,83 @@
1
+ export declare const QUEUE_SCRIPTS: {
2
+ /** KEYS: job, pending. ARGV: id, availableAt, ...hash fields. */
3
+ readonly gurenQueuePush: {
4
+ readonly numberOfKeys: 2;
5
+ readonly lua: `
6
+ redis.call('HSET', KEYS[1], unpack(ARGV, 3))
7
+ redis.call('ZADD', KEYS[2], ARGV[2], ARGV[1])
8
+ return 1
9
+ `;
10
+ };
11
+ /** KEYS: pending, reserved. ARGV: now, expiresAt, reservedAt, token, job key prefix. */
12
+ readonly gurenQueuePop: {
13
+ readonly numberOfKeys: 2;
14
+ readonly lua: `
15
+ local expired = redis.call('ZRANGEBYSCORE', KEYS[2], '-inf', ARGV[1], 'LIMIT', 0, 100)
16
+ for _, id in ipairs(expired) do
17
+ redis.call('ZREM', KEYS[2], id)
18
+ local key = ARGV[5] .. id
19
+ if redis.call('HEXISTS', key, 'id') == 1 then
20
+ redis.call('ZADD', KEYS[1], ARGV[1], id)
21
+ redis.call('HDEL', key, 'reservedAt', 'reservationToken')
22
+ end
23
+ end
24
+ while true do
25
+ local ids = redis.call('ZRANGEBYSCORE', KEYS[1], '-inf', ARGV[1], 'LIMIT', 0, 1)
26
+ if #ids == 0 then return {} end
27
+ local id = ids[1]
28
+ local key = ARGV[5] .. id
29
+ redis.call('ZREM', KEYS[1], id)
30
+ if redis.call('HEXISTS', key, 'id') == 1 then
31
+ redis.call('ZADD', KEYS[2], ARGV[2], id)
32
+ redis.call('HSET', key, 'reservedAt', ARGV[3], 'reservationToken', ARGV[4])
33
+ return redis.call('HGETALL', key)
34
+ end
35
+ end
36
+ `;
37
+ };
38
+ /** KEYS: job, pending, reserved. ARGV: id, token, attempts, availableAt ISO, lastError, availableAt ms. */
39
+ readonly gurenQueueRelease: {
40
+ readonly numberOfKeys: 3;
41
+ readonly lua: string;
42
+ };
43
+ /** KEYS: job. ARGV: id, token, queue key prefix. */
44
+ readonly gurenQueueDelete: {
45
+ readonly numberOfKeys: 1;
46
+ readonly lua: string;
47
+ };
48
+ /** KEYS: job, pending, reserved, failed. ARGV: id, token, failedAt, error, stack, attempts. */
49
+ readonly gurenQueueFail: {
50
+ readonly numberOfKeys: 4;
51
+ readonly lua: string;
52
+ };
53
+ /** KEYS: job, reserved. ARGV: id, token, expiresAt. */
54
+ readonly gurenQueueExtend: {
55
+ readonly numberOfKeys: 2;
56
+ readonly lua: string;
57
+ };
58
+ /** KEYS: job. ARGV: id, now ISO, now ms, queue key prefix. */
59
+ readonly gurenQueueRetry: {
60
+ readonly numberOfKeys: 1;
61
+ readonly lua: `
62
+ local queue = redis.call('HGET', KEYS[1], 'queue')
63
+ if not queue or redis.call('HEXISTS', KEYS[1], 'failedAt') == 0 then return 0 end
64
+ redis.call('LREM', ARGV[4] .. queue .. ':failed', 0, ARGV[1])
65
+ redis.call('HSET', KEYS[1], 'attempts', '0', 'availableAt', ARGV[2], 'createdAt', ARGV[2])
66
+ redis.call('HDEL', KEYS[1], 'reservedAt', 'reservationToken', 'failedAt', 'error', 'stack', 'lastError')
67
+ redis.call('ZADD', ARGV[4] .. queue .. ':pending', ARGV[3], ARGV[1])
68
+ return 1
69
+ `;
70
+ };
71
+ /** KEYS: job. ARGV: id, queue key prefix. */
72
+ readonly gurenQueueDeleteFailed: {
73
+ readonly numberOfKeys: 1;
74
+ readonly lua: `
75
+ local queue = redis.call('HGET', KEYS[1], 'queue')
76
+ if not queue or redis.call('HEXISTS', KEYS[1], 'failedAt') == 0 then return 0 end
77
+ redis.call('LREM', ARGV[2] .. queue .. ':failed', 0, ARGV[1])
78
+ redis.call('DEL', KEYS[1])
79
+ return 1
80
+ `;
81
+ };
82
+ };
83
+ export type QueueScriptName = keyof typeof QUEUE_SCRIPTS;
@@ -1,3 +1,3 @@
1
- import { a as getJob, d as resolveQueueDriver, f as setQueueDriver, l as registerJob, n as clearJobRegistry, o as getQueueDriver, r as clearQueueDriver, s as getRegisteredJobs, t as Job, u as resolveJobName } from "../Job-COMzBNOL.js";
2
- import { a as processJob, c as RedisDriver, i as Worker, l as SyncDriver, n as createQueueManager, o as SqsDriver, r as FailedJobReporter, s as createSqsAdapter, t as QueueManager, u as MemoryDriver } from "../queue-BiBn5Sff.js";
1
+ import { a as getJob, d as resolveQueueDriver, f as setQueueDriver, l as registerJob, n as clearJobRegistry, o as getQueueDriver, r as clearQueueDriver, s as getRegisteredJobs, t as Job, u as resolveJobName } from "../Job-DsFMcXVk.js";
2
+ import { a as processJob, c as RedisDriver, i as Worker, l as SyncDriver, n as createQueueManager, o as SqsDriver, r as FailedJobReporter, s as createSqsAdapter, t as QueueManager, u as MemoryDriver } from "../queue-Bo4Q857L.js";
3
3
  export { FailedJobReporter, Job, MemoryDriver, QueueManager, RedisDriver, SqsDriver, SyncDriver, Worker, clearJobRegistry, clearQueueDriver, createQueueManager, createSqsAdapter, getJob, getQueueDriver, getRegisteredJobs, processJob, registerJob, resolveJobName, resolveQueueDriver, setQueueDriver };
@@ -0,0 +1,7 @@
1
+ import type { QueuedJob } from './types.js';
2
+ /**
3
+ * Read a queued job out of a JSON message body. The dates are strings on the
4
+ * wire, so a reader that skips them hands callers a `QueuedJob` whose date
5
+ * fields are not dates.
6
+ */
7
+ export declare function deserializeQueuedJob(body: string): QueuedJob;
@@ -6,12 +6,15 @@ export interface QueuedJob<T = unknown> {
6
6
  name: string;
7
7
  payload: T;
8
8
  queue: string;
9
+ /** Deliveries already completed; the worker adds one for the run it starts. */
9
10
  attempts: number;
10
11
  maxAttempts: number;
11
12
  availableAt: Date;
12
13
  createdAt: Date;
13
14
  reservedAt: Date | null;
14
15
  lastError?: string;
16
+ /** Opaque reservation owner, supplied by drivers that fence stale workers. */
17
+ reservationToken?: string;
15
18
  }
16
19
  /** Failed job record. */
17
20
  export interface FailedJob<T = unknown> extends QueuedJob<T> {
@@ -22,13 +25,21 @@ export interface FailedJob<T = unknown> extends QueuedJob<T> {
22
25
  /** Implement to add a queue backend. */
23
26
  export interface QueueDriver {
24
27
  push(job: QueuedJob): Promise<void>;
28
+ /**
29
+ * Reconcile `attempts` here when the backend counts redeliveries itself:
30
+ * a driver that leaves the body's count alone restarts the retry limit on
31
+ * every redelivery, since nothing rewrites a message already on the queue.
32
+ */
25
33
  pop(queue: string): Promise<QueuedJob | null>;
26
34
  /**
27
35
  * Release a job for retry. The driver owns the delay: one with nothing to wait
28
36
  * in (`SyncDriver`) may run the job again before this resolves.
29
37
  */
30
38
  release(job: QueuedJob, delayMs?: number): Promise<void>;
31
- delete(jobId: string): Promise<void>;
39
+ delete(jobId: string, reservationToken?: string): Promise<void>;
40
+ /** Drivers with expiring reservations renew them while handle() is still running. */
41
+ readonly heartbeatInterval?: number;
42
+ extendReservation?(job: QueuedJob): Promise<boolean>;
32
43
  fail(job: QueuedJob, error: Error): Promise<void>;
33
44
  size(queue: string): Promise<number>;
34
45
  getFailedJobs(queue?: string): Promise<FailedJob[]>;
@@ -79,7 +90,7 @@ export interface WorkerOptions {
79
90
  */
80
91
  maxJobs?: number;
81
92
  /**
82
- * Timeout for each job in milliseconds.
93
+ * Requests cancellation after this many milliseconds. Retries wait for handle() to settle.
83
94
  * @default 60000
84
95
  */
85
96
  timeout?: number;