@lssm/lib.jobs 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217072406

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 (144) hide show
  1. package/dist/_virtual/rolldown_runtime.js +42 -1
  2. package/dist/contracts/dist/capabilities/openbanking.js +88 -1
  3. package/dist/contracts/dist/client/index.js +5 -1
  4. package/dist/contracts/dist/client/react/feature-render.js +2 -1
  5. package/dist/contracts/dist/client/react/form-render.js +4 -1
  6. package/dist/contracts/dist/client/react/index.js +4 -1
  7. package/dist/contracts/dist/contract-registry/index.js +1 -1
  8. package/dist/contracts/dist/contract-registry/schemas.js +60 -1
  9. package/dist/contracts/dist/docs/PUBLISHING.docblock.js +16 -76
  10. package/dist/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -350
  11. package/dist/contracts/dist/docs/index.js +29 -1
  12. package/dist/contracts/dist/docs/presentations.js +71 -1
  13. package/dist/contracts/dist/docs/registry.js +44 -1
  14. package/dist/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -383
  15. package/dist/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -68
  16. package/dist/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -140
  17. package/dist/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -86
  18. package/dist/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -1
  19. package/dist/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +24 -2
  20. package/dist/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +21 -2
  21. package/dist/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -213
  22. package/dist/contracts/dist/docs/tech/llm/llm-integration.docblock.js +73 -5
  23. package/dist/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -1
  24. package/dist/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -1
  25. package/dist/contracts/dist/docs/tech/schema/README.docblock.js +20 -262
  26. package/dist/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -1
  27. package/dist/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +24 -2
  28. package/dist/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +23 -2
  29. package/dist/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +25 -16
  30. package/dist/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -1
  31. package/dist/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +22 -2
  32. package/dist/contracts/dist/docs/tech/studio/team-invitations.docblock.js +40 -36
  33. package/dist/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -1
  34. package/dist/contracts/dist/docs/tech/studio/workspaces.docblock.js +23 -2
  35. package/dist/contracts/dist/docs/tech/telemetry-ingest.docblock.js +36 -3
  36. package/dist/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -1
  37. package/dist/contracts/dist/docs/tech/vscode-extension.docblock.js +36 -3
  38. package/dist/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -1
  39. package/dist/contracts/dist/events.js +10 -1
  40. package/dist/contracts/dist/experiments/evaluator.js +1 -1
  41. package/dist/contracts/dist/index.js +71 -1
  42. package/dist/contracts/dist/install.js +2 -1
  43. package/dist/contracts/dist/integrations/contracts.js +377 -1
  44. package/dist/contracts/dist/integrations/index.js +18 -1
  45. package/dist/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -1
  46. package/dist/contracts/dist/integrations/openbanking/contracts/balances.js +159 -1
  47. package/dist/contracts/dist/integrations/openbanking/contracts/index.js +3 -1
  48. package/dist/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -1
  49. package/dist/contracts/dist/integrations/openbanking/models.js +242 -1
  50. package/dist/contracts/dist/integrations/openbanking/telemetry.js +13 -1
  51. package/dist/contracts/dist/integrations/providers/elevenlabs.js +52 -1
  52. package/dist/contracts/dist/integrations/providers/gcs-storage.js +75 -1
  53. package/dist/contracts/dist/integrations/providers/gmail.js +87 -1
  54. package/dist/contracts/dist/integrations/providers/google-calendar.js +66 -1
  55. package/dist/contracts/dist/integrations/providers/index.js +11 -1
  56. package/dist/contracts/dist/integrations/providers/mistral.js +68 -1
  57. package/dist/contracts/dist/integrations/providers/postmark.js +68 -1
  58. package/dist/contracts/dist/integrations/providers/powens.js +116 -1
  59. package/dist/contracts/dist/integrations/providers/qdrant.js +73 -1
  60. package/dist/contracts/dist/integrations/providers/registry.js +10 -1
  61. package/dist/contracts/dist/integrations/providers/stripe.js +83 -1
  62. package/dist/contracts/dist/integrations/providers/twilio-sms.js +61 -1
  63. package/dist/contracts/dist/jobs/queue.js +33 -1
  64. package/dist/contracts/dist/jsonschema.js +1 -1
  65. package/dist/contracts/dist/knowledge/contracts.js +306 -1
  66. package/dist/contracts/dist/knowledge/index.js +7 -1
  67. package/dist/contracts/dist/knowledge/spaces/email-threads.js +34 -1
  68. package/dist/contracts/dist/knowledge/spaces/financial-docs.js +34 -1
  69. package/dist/contracts/dist/knowledge/spaces/financial-overview.js +38 -1
  70. package/dist/contracts/dist/knowledge/spaces/index.js +6 -1
  71. package/dist/contracts/dist/knowledge/spaces/product-canon.js +34 -1
  72. package/dist/contracts/dist/knowledge/spaces/support-faq.js +37 -1
  73. package/dist/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -1
  74. package/dist/contracts/dist/llm/exporters.js +19 -1
  75. package/dist/contracts/dist/llm/index.js +2 -1
  76. package/dist/contracts/dist/llm/prompts.js +1 -1
  77. package/dist/contracts/dist/onboarding-base.js +196 -1
  78. package/dist/contracts/dist/openapi.js +1 -1
  79. package/dist/contracts/dist/ownership.js +21 -1
  80. package/dist/contracts/dist/presentations.js +1 -1
  81. package/dist/contracts/dist/presentations.v2.js +11 -1
  82. package/dist/contracts/dist/prompt.js +1 -1
  83. package/dist/contracts/dist/promptRegistry.js +1 -1
  84. package/dist/contracts/dist/regenerator/index.js +1 -1
  85. package/dist/contracts/dist/regenerator/service.js +6 -1
  86. package/dist/contracts/dist/registry.js +2 -1
  87. package/dist/contracts/dist/resources.js +1 -1
  88. package/dist/contracts/dist/schema/dist/EnumType.js +2 -1
  89. package/dist/contracts/dist/schema/dist/FieldType.js +49 -1
  90. package/dist/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -1
  91. package/dist/contracts/dist/schema/dist/SchemaModel.js +34 -1
  92. package/dist/contracts/dist/schema/dist/entity/defineEntity.js +1 -1
  93. package/dist/contracts/dist/schema/dist/entity/index.js +2 -1
  94. package/dist/contracts/dist/schema/dist/entity/types.js +1 -1
  95. package/dist/contracts/dist/schema/dist/index.js +6 -1
  96. package/dist/contracts/dist/server/graphql-pothos.js +6 -1
  97. package/dist/contracts/dist/server/index.js +8 -1
  98. package/dist/contracts/dist/server/mcp/createMcpServer.js +4 -1
  99. package/dist/contracts/dist/server/mcp/registerPresentations.js +2 -1
  100. package/dist/contracts/dist/server/mcp/registerPrompts.js +1 -1
  101. package/dist/contracts/dist/server/mcp/registerResources.js +2 -1
  102. package/dist/contracts/dist/server/mcp/registerTools.js +1 -1
  103. package/dist/contracts/dist/server/provider-mcp.js +1 -1
  104. package/dist/contracts/dist/server/rest-elysia.js +1 -1
  105. package/dist/contracts/dist/server/rest-express.js +1 -1
  106. package/dist/contracts/dist/server/rest-generic.js +1 -1
  107. package/dist/contracts/dist/server/rest-next-app.js +1 -1
  108. package/dist/contracts/dist/server/rest-next-pages.js +1 -1
  109. package/dist/contracts/dist/spec.js +34 -1
  110. package/dist/contracts/dist/telemetry/index.js +1 -1
  111. package/dist/contracts/dist/telemetry/tracker.js +1 -1
  112. package/dist/contracts/dist/tests/index.js +1 -1
  113. package/dist/contracts/dist/tests/runner.js +2 -1
  114. package/dist/contracts/dist/workflow/index.js +1 -1
  115. package/dist/contracts/dist/workflow/runner.js +1 -1
  116. package/dist/contracts/index.d.ts +138 -138
  117. package/dist/contracts/index.js +484 -1
  118. package/dist/entities/index.d.ts +116 -116
  119. package/dist/entities/index.js +198 -1
  120. package/dist/events.js +303 -1
  121. package/dist/handlers/gmail-sync-handler.js +9 -1
  122. package/dist/handlers/index.js +12 -1
  123. package/dist/handlers/ping-job.d.ts +3 -3
  124. package/dist/handlers/ping-job.js +13 -1
  125. package/dist/handlers/storage-document-handler.js +14 -1
  126. package/dist/index.js +18 -1
  127. package/dist/jobs.feature.js +101 -1
  128. package/dist/queue/gcp-cloud-tasks.js +61 -1
  129. package/dist/queue/gcp-pubsub.js +47 -1
  130. package/dist/queue/index.js +9 -1
  131. package/dist/queue/memory-queue.js +140 -1
  132. package/dist/queue/register-defined-job.js +15 -1
  133. package/dist/queue/scaleway-sqs-queue.js +175 -1
  134. package/dist/queue/types.js +3 -1
  135. package/dist/scheduler/index.js +145 -1
  136. package/dist/schema/dist/EnumType.js +2 -1
  137. package/dist/schema/dist/FieldType.js +49 -1
  138. package/dist/schema/dist/ScalarTypeEnum.js +236 -1
  139. package/dist/schema/dist/SchemaModel.js +39 -1
  140. package/dist/schema/dist/entity/defineEntity.js +236 -1
  141. package/dist/schema/dist/entity/index.js +2 -1
  142. package/dist/schema/dist/entity/types.js +1 -1
  143. package/dist/schema/dist/index.js +6 -1
  144. package/package.json +7 -6
@@ -1 +1,140 @@
1
- import{e,t}from"../contracts/dist/jobs/queue.js";import"./types.js";import{randomUUID as n}from"node:crypto";var r=class{jobs=new Map;handlers=new Map;timer;activeCount=0;pollIntervalMs;concurrency;retryPolicy;constructor(t={}){this.pollIntervalMs=t.pollIntervalMs??200,this.concurrency=t.concurrency??5,this.retryPolicy=t.retryPolicy??e}async enqueue(e,t,r={}){if(r.dedupeKey){let e=Array.from(this.jobs.values()).find(e=>e.dedupeKey===r.dedupeKey&&e.status===`pending`);if(e)return e}let i=new Date,a=r.delaySeconds?new Date(i.getTime()+r.delaySeconds*1e3):i,o={id:n(),type:e,version:1,payload:t,status:`pending`,priority:r.priority??0,attempts:0,maxRetries:r.maxRetries??this.retryPolicy.maxRetries,createdAt:i,updatedAt:i,scheduledAt:a,dedupeKey:r.dedupeKey,tenantId:r.tenantId,userId:r.userId,traceId:r.traceId,metadata:r.metadata};return r.timeoutMs&&(o.timeoutAt=new Date(i.getTime()+r.timeoutMs)),this.jobs.set(o.id,o),o}register(e,t){this.handlers.set(e,t)}start(){this.timer||=setInterval(()=>{this.processNext()},this.pollIntervalMs)}async stop(){for(this.timer&&=(clearInterval(this.timer),void 0);this.activeCount>0;)await new Promise(e=>setTimeout(e,50))}async getJob(e){return this.jobs.get(e)??null}async cancelJob(e){let t=this.jobs.get(e);return!t||t.status!==`pending`?!1:(t.status=`cancelled`,t.updatedAt=new Date,!0)}async getStats(){let e={pending:0,running:0,completed:0,failed:0,deadLetter:0};for(let t of this.jobs.values())switch(t.status){case`pending`:e.pending++;break;case`running`:e.running++;break;case`completed`:e.completed++;break;case`failed`:e.failed++;break;case`dead_letter`:e.deadLetter++;break}return e}async processNext(){if(this.activeCount>=this.concurrency)return;let e=new Date,n=Array.from(this.jobs.values()).filter(t=>t.status===`pending`&&(!t.scheduledAt||t.scheduledAt<=e)).sort((e,t)=>e.priority===t.priority?(e.scheduledAt?.getTime()??0)-(t.scheduledAt?.getTime()??0):t.priority-e.priority)[0];if(!n)return;let r=this.handlers.get(n.type);if(r){this.activeCount++,n.status=`running`,n.startedAt=new Date,n.updatedAt=new Date,n.attempts+=1;try{let e=await r(n);n.status=`completed`,n.completedAt=new Date,n.result=e}catch(e){if(n.lastError=e instanceof Error?e.message:`Unknown error`,n.attempts>=n.maxRetries)n.status=`dead_letter`;else{let e=t(n.attempts,this.retryPolicy);n.status=`pending`,n.scheduledAt=new Date(Date.now()+e)}}finally{n.updatedAt=new Date,this.activeCount--}}}};export{r as MemoryJobQueue};
1
+ import { DEFAULT_RETRY_POLICY, calculateBackoff } from "../contracts/dist/jobs/queue.js";
2
+ import "./types.js";
3
+ import { randomUUID } from "node:crypto";
4
+
5
+ //#region src/queue/memory-queue.ts
6
+ /**
7
+ * In-memory job queue for development and testing.
8
+ */
9
+ var MemoryJobQueue = class {
10
+ jobs = /* @__PURE__ */ new Map();
11
+ handlers = /* @__PURE__ */ new Map();
12
+ timer;
13
+ activeCount = 0;
14
+ pollIntervalMs;
15
+ concurrency;
16
+ retryPolicy;
17
+ constructor(options = {}) {
18
+ this.pollIntervalMs = options.pollIntervalMs ?? 200;
19
+ this.concurrency = options.concurrency ?? 5;
20
+ this.retryPolicy = options.retryPolicy ?? DEFAULT_RETRY_POLICY;
21
+ }
22
+ async enqueue(jobType, payload, options = {}) {
23
+ if (options.dedupeKey) {
24
+ const existing = Array.from(this.jobs.values()).find((j) => j.dedupeKey === options.dedupeKey && j.status === "pending");
25
+ if (existing) return existing;
26
+ }
27
+ const now = /* @__PURE__ */ new Date();
28
+ const scheduledAt = options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now;
29
+ const job = {
30
+ id: randomUUID(),
31
+ type: jobType,
32
+ version: 1,
33
+ payload,
34
+ status: "pending",
35
+ priority: options.priority ?? 0,
36
+ attempts: 0,
37
+ maxRetries: options.maxRetries ?? this.retryPolicy.maxRetries,
38
+ createdAt: now,
39
+ updatedAt: now,
40
+ scheduledAt,
41
+ dedupeKey: options.dedupeKey,
42
+ tenantId: options.tenantId,
43
+ userId: options.userId,
44
+ traceId: options.traceId,
45
+ metadata: options.metadata
46
+ };
47
+ if (options.timeoutMs) job.timeoutAt = new Date(now.getTime() + options.timeoutMs);
48
+ this.jobs.set(job.id, job);
49
+ return job;
50
+ }
51
+ register(jobType, handler) {
52
+ this.handlers.set(jobType, handler);
53
+ }
54
+ start() {
55
+ if (this.timer) return;
56
+ this.timer = setInterval(() => {
57
+ this.processNext();
58
+ }, this.pollIntervalMs);
59
+ }
60
+ async stop() {
61
+ if (this.timer) {
62
+ clearInterval(this.timer);
63
+ this.timer = void 0;
64
+ }
65
+ while (this.activeCount > 0) await new Promise((resolve) => setTimeout(resolve, 50));
66
+ }
67
+ async getJob(jobId) {
68
+ return this.jobs.get(jobId) ?? null;
69
+ }
70
+ async cancelJob(jobId) {
71
+ const job = this.jobs.get(jobId);
72
+ if (!job || job.status !== "pending") return false;
73
+ job.status = "cancelled";
74
+ job.updatedAt = /* @__PURE__ */ new Date();
75
+ return true;
76
+ }
77
+ async getStats() {
78
+ const stats = {
79
+ pending: 0,
80
+ running: 0,
81
+ completed: 0,
82
+ failed: 0,
83
+ deadLetter: 0
84
+ };
85
+ for (const job of this.jobs.values()) switch (job.status) {
86
+ case "pending":
87
+ stats.pending++;
88
+ break;
89
+ case "running":
90
+ stats.running++;
91
+ break;
92
+ case "completed":
93
+ stats.completed++;
94
+ break;
95
+ case "failed":
96
+ stats.failed++;
97
+ break;
98
+ case "dead_letter":
99
+ stats.deadLetter++;
100
+ break;
101
+ }
102
+ return stats;
103
+ }
104
+ async processNext() {
105
+ if (this.activeCount >= this.concurrency) return;
106
+ const now = /* @__PURE__ */ new Date();
107
+ const job = Array.from(this.jobs.values()).filter((j) => j.status === "pending" && (!j.scheduledAt || j.scheduledAt <= now)).sort((a, b) => {
108
+ if (a.priority !== b.priority) return b.priority - a.priority;
109
+ return (a.scheduledAt?.getTime() ?? 0) - (b.scheduledAt?.getTime() ?? 0);
110
+ })[0];
111
+ if (!job) return;
112
+ const handler = this.handlers.get(job.type);
113
+ if (!handler) return;
114
+ this.activeCount++;
115
+ job.status = "running";
116
+ job.startedAt = /* @__PURE__ */ new Date();
117
+ job.updatedAt = /* @__PURE__ */ new Date();
118
+ job.attempts += 1;
119
+ try {
120
+ const result = await handler(job);
121
+ job.status = "completed";
122
+ job.completedAt = /* @__PURE__ */ new Date();
123
+ job.result = result;
124
+ } catch (error) {
125
+ job.lastError = error instanceof Error ? error.message : "Unknown error";
126
+ if (job.attempts >= job.maxRetries) job.status = "dead_letter";
127
+ else {
128
+ const backoff = calculateBackoff(job.attempts, this.retryPolicy);
129
+ job.status = "pending";
130
+ job.scheduledAt = new Date(Date.now() + backoff);
131
+ }
132
+ } finally {
133
+ job.updatedAt = /* @__PURE__ */ new Date();
134
+ this.activeCount--;
135
+ }
136
+ }
137
+ };
138
+
139
+ //#endregion
140
+ export { MemoryJobQueue };
@@ -1 +1,15 @@
1
- function e(e,t){e.register(t.type,async e=>{let n=t.schema.parse(e.payload),r={...e,payload:n};await t.handler(n,r)})}export{e as registerDefinedJob};
1
+ //#region src/queue/register-defined-job.ts
2
+ function registerDefinedJob(queue, def) {
3
+ const wrapped = async (job) => {
4
+ const payload = def.schema.parse(job.payload);
5
+ const typedJob = {
6
+ ...job,
7
+ payload
8
+ };
9
+ await def.handler(payload, typedJob);
10
+ };
11
+ queue.register(def.type, wrapped);
12
+ }
13
+
14
+ //#endregion
15
+ export { registerDefinedJob };
@@ -1 +1,175 @@
1
- import{e}from"../contracts/dist/jobs/queue.js";import"./types.js";import{randomUUID as t}from"node:crypto";import{DeleteMessageCommand as n,ReceiveMessageCommand as r,SQSClient as i,SendMessageCommand as a}from"@aws-sdk/client-sqs";var o=class{sqs;queueUrl;waitTimeSeconds;maxNumberOfMessages;visibilityTimeoutSeconds;handlers=new Map;logger;running=!1;constructor(e){this.logger=e.logger;let t=e.credentials?.accessKeyId??process.env.SCALEWAY_ACCESS_KEY_QUEUE,n=e.credentials?.secretAccessKey??process.env.SCALEWAY_SECRET_KEY_QUEUE;if(!t||!n)throw Error(`Missing SCALEWAY_ACCESS_KEY_QUEUE / SCALEWAY_SECRET_KEY_QUEUE in env`);this.sqs=new i({region:e.region??process.env.SCALEWAY_REGION??`par`,endpoint:e.endpoint??`https://sqs.mnq.fr-par.scaleway.com`,credentials:{accessKeyId:t,secretAccessKey:n}}),this.queueUrl=e.queueUrl,this.waitTimeSeconds=e.waitTimeSeconds??20,this.maxNumberOfMessages=e.maxNumberOfMessages??5,this.visibilityTimeoutSeconds=e.visibilityTimeoutSeconds??60}async enqueue(n,r,i={}){let o=t(),s=new Date,c=i.delaySeconds?new Date(s.getTime()+i.delaySeconds*1e3):s,l={id:o,type:n,payload:r};return await this.sqs.send(new a({QueueUrl:this.queueUrl,MessageBody:JSON.stringify(l),DelaySeconds:i.delaySeconds??0})),{id:o,type:n,version:1,payload:r,status:`pending`,priority:i.priority??0,attempts:0,maxRetries:i.maxRetries??e.maxRetries,createdAt:s,updatedAt:s,scheduledAt:c,dedupeKey:i.dedupeKey,tenantId:i.tenantId,userId:i.userId,traceId:i.traceId,metadata:i.metadata}}register(e,t){if(this.handlers.has(e))throw Error(`Handler already registered for job type "${e}"`);this.handlers.set(e,t)}start(){this.running||(this.running=!0,this.pollLoop().catch(e=>{this.logger?.error?.(`jobs.queue.scaleway_sqs.poll_loop_fatal`,{error:e instanceof Error?e.message:String(e)}),this.running=!1}))}async stop(){this.running=!1}async pollLoop(){for(this.logger?.info?.(`jobs.queue.scaleway_sqs.started`,{queueUrl:this.queueUrl});this.running;)try{let t=(await this.sqs.send(new r({QueueUrl:this.queueUrl,MaxNumberOfMessages:this.maxNumberOfMessages,WaitTimeSeconds:this.waitTimeSeconds,VisibilityTimeout:this.visibilityTimeoutSeconds,MessageSystemAttributeNames:[`ApproximateReceiveCount`]}))).Messages??[];if(t.length===0)continue;for(let n of t){if(!n.Body||!n.ReceiptHandle){this.logger?.warn?.(`jobs.queue.scaleway_sqs.invalid_message`,{messageId:n.MessageId,reason:`missing_body_or_receipt`});continue}let t;try{t=JSON.parse(n.Body)}catch(e){this.logger?.warn?.(`jobs.queue.scaleway_sqs.parse_failed`,{messageId:n.MessageId,error:e instanceof Error?e.message:String(e)}),await this.deleteMessage(n.ReceiptHandle);continue}let r=this.handlers.get(t.type);if(!r){this.logger?.warn?.(`jobs.queue.scaleway_sqs.missing_handler`,{jobType:t.type,messageId:n.MessageId}),await this.deleteMessage(n.ReceiptHandle);continue}let i=new Date,a=parseInt(n.Attributes?.ApproximateReceiveCount??`1`,10),o={id:t.id,type:t.type,version:1,payload:t.payload,status:`pending`,priority:0,attempts:a,maxRetries:e.maxRetries,createdAt:i,updatedAt:i};o.status=`running`,o.updatedAt=new Date;try{await r(o),o.status=`completed`,o.updatedAt=new Date,await this.deleteMessage(n.ReceiptHandle)}catch(e){o.status=`failed`,o.lastError=e instanceof Error?e.message:`Unknown job error`,o.updatedAt=new Date,this.logger?.error?.(`jobs.queue.scaleway_sqs.job_failed`,{jobType:o.type,jobId:o.id,error:e instanceof Error?e.message:String(e)})}}}catch(e){this.logger?.error?.(`jobs.queue.scaleway_sqs.poll_error`,{error:e instanceof Error?e.message:String(e)}),await this.sleep(5e3)}this.logger?.info?.(`jobs.queue.scaleway_sqs.stopped`,{queueUrl:this.queueUrl})}async deleteMessage(e){try{await this.sqs.send(new n({QueueUrl:this.queueUrl,ReceiptHandle:e}))}catch(e){this.logger?.warn?.(`jobs.queue.scaleway_sqs.delete_failed`,{error:e instanceof Error?e.message:String(e)})}}async sleep(e){await new Promise(t=>setTimeout(t,e))}};export{o as ScalewaySqsJobQueue};
1
+ import { DEFAULT_RETRY_POLICY } from "../contracts/dist/jobs/queue.js";
2
+ import "./types.js";
3
+ import { randomUUID } from "node:crypto";
4
+ import { DeleteMessageCommand, ReceiveMessageCommand, SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
5
+
6
+ //#region src/queue/scaleway-sqs-queue.ts
7
+ var ScalewaySqsJobQueue = class {
8
+ sqs;
9
+ queueUrl;
10
+ waitTimeSeconds;
11
+ maxNumberOfMessages;
12
+ visibilityTimeoutSeconds;
13
+ handlers = /* @__PURE__ */ new Map();
14
+ logger;
15
+ running = false;
16
+ constructor(config) {
17
+ this.logger = config.logger;
18
+ const accessKeyId = config.credentials?.accessKeyId ?? process.env.SCALEWAY_ACCESS_KEY_QUEUE;
19
+ const secretAccessKey = config.credentials?.secretAccessKey ?? process.env.SCALEWAY_SECRET_KEY_QUEUE;
20
+ if (!accessKeyId || !secretAccessKey) throw new Error("Missing SCALEWAY_ACCESS_KEY_QUEUE / SCALEWAY_SECRET_KEY_QUEUE in env");
21
+ this.sqs = new SQSClient({
22
+ region: config.region ?? process.env.SCALEWAY_REGION ?? "par",
23
+ endpoint: config.endpoint ?? "https://sqs.mnq.fr-par.scaleway.com",
24
+ credentials: {
25
+ accessKeyId,
26
+ secretAccessKey
27
+ }
28
+ });
29
+ this.queueUrl = config.queueUrl;
30
+ this.waitTimeSeconds = config.waitTimeSeconds ?? 20;
31
+ this.maxNumberOfMessages = config.maxNumberOfMessages ?? 5;
32
+ this.visibilityTimeoutSeconds = config.visibilityTimeoutSeconds ?? 60;
33
+ }
34
+ async enqueue(jobType, payload, options = {}) {
35
+ const id = randomUUID();
36
+ const now = /* @__PURE__ */ new Date();
37
+ const scheduledAt = options.delaySeconds ? new Date(now.getTime() + options.delaySeconds * 1e3) : now;
38
+ const envelope = {
39
+ id,
40
+ type: jobType,
41
+ payload
42
+ };
43
+ await this.sqs.send(new SendMessageCommand({
44
+ QueueUrl: this.queueUrl,
45
+ MessageBody: JSON.stringify(envelope),
46
+ DelaySeconds: options.delaySeconds ?? 0
47
+ }));
48
+ return {
49
+ id,
50
+ type: jobType,
51
+ version: 1,
52
+ payload,
53
+ status: "pending",
54
+ priority: options.priority ?? 0,
55
+ attempts: 0,
56
+ maxRetries: options.maxRetries ?? DEFAULT_RETRY_POLICY.maxRetries,
57
+ createdAt: now,
58
+ updatedAt: now,
59
+ scheduledAt,
60
+ dedupeKey: options.dedupeKey,
61
+ tenantId: options.tenantId,
62
+ userId: options.userId,
63
+ traceId: options.traceId,
64
+ metadata: options.metadata
65
+ };
66
+ }
67
+ register(jobType, handler) {
68
+ if (this.handlers.has(jobType)) throw new Error(`Handler already registered for job type "${jobType}"`);
69
+ this.handlers.set(jobType, handler);
70
+ }
71
+ start() {
72
+ if (this.running) return;
73
+ this.running = true;
74
+ this.pollLoop().catch((error) => {
75
+ this.logger?.error?.("jobs.queue.scaleway_sqs.poll_loop_fatal", { error: error instanceof Error ? error.message : String(error) });
76
+ this.running = false;
77
+ });
78
+ }
79
+ async stop() {
80
+ this.running = false;
81
+ }
82
+ async pollLoop() {
83
+ this.logger?.info?.("jobs.queue.scaleway_sqs.started", { queueUrl: this.queueUrl });
84
+ while (this.running) try {
85
+ const messages = (await this.sqs.send(new ReceiveMessageCommand({
86
+ QueueUrl: this.queueUrl,
87
+ MaxNumberOfMessages: this.maxNumberOfMessages,
88
+ WaitTimeSeconds: this.waitTimeSeconds,
89
+ VisibilityTimeout: this.visibilityTimeoutSeconds,
90
+ MessageSystemAttributeNames: ["ApproximateReceiveCount"]
91
+ }))).Messages ?? [];
92
+ if (messages.length === 0) continue;
93
+ for (const msg of messages) {
94
+ if (!msg.Body || !msg.ReceiptHandle) {
95
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.invalid_message", {
96
+ messageId: msg.MessageId,
97
+ reason: "missing_body_or_receipt"
98
+ });
99
+ continue;
100
+ }
101
+ let envelope;
102
+ try {
103
+ envelope = JSON.parse(msg.Body);
104
+ } catch (err) {
105
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.parse_failed", {
106
+ messageId: msg.MessageId,
107
+ error: err instanceof Error ? err.message : String(err)
108
+ });
109
+ await this.deleteMessage(msg.ReceiptHandle);
110
+ continue;
111
+ }
112
+ const handler = this.handlers.get(envelope.type);
113
+ if (!handler) {
114
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.missing_handler", {
115
+ jobType: envelope.type,
116
+ messageId: msg.MessageId
117
+ });
118
+ await this.deleteMessage(msg.ReceiptHandle);
119
+ continue;
120
+ }
121
+ const now = /* @__PURE__ */ new Date();
122
+ const attempts = parseInt(msg.Attributes?.ApproximateReceiveCount ?? "1", 10);
123
+ const job = {
124
+ id: envelope.id,
125
+ type: envelope.type,
126
+ version: 1,
127
+ payload: envelope.payload,
128
+ status: "pending",
129
+ priority: 0,
130
+ attempts,
131
+ maxRetries: DEFAULT_RETRY_POLICY.maxRetries,
132
+ createdAt: now,
133
+ updatedAt: now
134
+ };
135
+ job.status = "running";
136
+ job.updatedAt = /* @__PURE__ */ new Date();
137
+ try {
138
+ await handler(job);
139
+ job.status = "completed";
140
+ job.updatedAt = /* @__PURE__ */ new Date();
141
+ await this.deleteMessage(msg.ReceiptHandle);
142
+ } catch (err) {
143
+ job.status = "failed";
144
+ job.lastError = err instanceof Error ? err.message : "Unknown job error";
145
+ job.updatedAt = /* @__PURE__ */ new Date();
146
+ this.logger?.error?.("jobs.queue.scaleway_sqs.job_failed", {
147
+ jobType: job.type,
148
+ jobId: job.id,
149
+ error: err instanceof Error ? err.message : String(err)
150
+ });
151
+ }
152
+ }
153
+ } catch (err) {
154
+ this.logger?.error?.("jobs.queue.scaleway_sqs.poll_error", { error: err instanceof Error ? err.message : String(err) });
155
+ await this.sleep(5e3);
156
+ }
157
+ this.logger?.info?.("jobs.queue.scaleway_sqs.stopped", { queueUrl: this.queueUrl });
158
+ }
159
+ async deleteMessage(receiptHandle) {
160
+ try {
161
+ await this.sqs.send(new DeleteMessageCommand({
162
+ QueueUrl: this.queueUrl,
163
+ ReceiptHandle: receiptHandle
164
+ }));
165
+ } catch (err) {
166
+ this.logger?.warn?.("jobs.queue.scaleway_sqs.delete_failed", { error: err instanceof Error ? err.message : String(err) });
167
+ }
168
+ }
169
+ async sleep(ms) {
170
+ await new Promise((resolve) => setTimeout(resolve, ms));
171
+ }
172
+ };
173
+
174
+ //#endregion
175
+ export { ScalewaySqsJobQueue };
@@ -1 +1,3 @@
1
- import{e,n as t,t as n}from"../contracts/dist/jobs/queue.js";export{e as DEFAULT_RETRY_POLICY,n as calculateBackoff,t as defineJobType};
1
+ import { DEFAULT_RETRY_POLICY, calculateBackoff, defineJobType } from "../contracts/dist/jobs/queue.js";
2
+
3
+ export { DEFAULT_RETRY_POLICY, calculateBackoff, defineJobType };
@@ -1 +1,145 @@
1
- function e(e,t=new Date){try{let n=e.trim().split(/\s+/);if(n.length!==5)return console.warn(`Invalid cron expression: ${e}`),null;let r=n[0],i=n[1],a=n[2],o=n[3],s=new Date(t);if(s.setSeconds(0),s.setMilliseconds(0),r&&i&&r!==`*`&&i!==`*`&&a===`*`&&o===`*`){let e=Number.parseInt(r,10),n=Number.parseInt(i,10);return s.setHours(n,e,0,0),s<=t&&s.setDate(s.getDate()+1),s}return s.setMinutes(s.getMinutes()+1),s}catch{return null}}var t=class{schedules=new Map;timer;checkIntervalMs;constructor(e,t={}){this.queue=e,this.checkIntervalMs=t.checkIntervalMs??6e4}schedule(t){let n=t.enabled===!1?null:e(t.cronExpression);this.schedules.set(t.name,{...t,enabled:t.enabled??!0,nextRun:n,lastRun:null})}unschedule(e){return this.schedules.delete(e)}enable(t){let n=this.schedules.get(t);return n?(n.enabled=!0,n.nextRun=e(n.cronExpression),!0):!1}disable(e){let t=this.schedules.get(e);return t?(t.enabled=!1,t.nextRun=null,!0):!1}getSchedules(){return Array.from(this.schedules.values())}getSchedule(e){return this.schedules.get(e)}start(){this.timer||=(this.checkSchedules(),setInterval(()=>{this.checkSchedules()},this.checkIntervalMs))}stop(){this.timer&&=(clearInterval(this.timer),void 0)}async checkSchedules(){let t=new Date;for(let n of this.schedules.values())if(!(!n.enabled||!n.nextRun)&&n.nextRun<=t)try{let r=typeof n.payload==`function`?await n.payload():n.payload;await this.queue.enqueue(n.jobType,r,n.options),n.lastRun=t,n.nextRun=e(n.cronExpression,t)}catch(e){console.error(`Failed to enqueue scheduled job ${n.name}:`,e)}}};function n(e,n){return new t(e,n)}function r(e){return e}export{t as JobScheduler,n as createScheduler,r as defineSchedule};
1
+ //#region src/scheduler/index.ts
2
+ /**
3
+ * Parse a cron expression to get the next run time.
4
+ * Simple implementation supporting: minute hour day month weekday
5
+ */
6
+ function getNextCronRun(cronExpression, after = /* @__PURE__ */ new Date()) {
7
+ try {
8
+ const parts = cronExpression.trim().split(/\s+/);
9
+ if (parts.length !== 5) {
10
+ console.warn(`Invalid cron expression: ${cronExpression}`);
11
+ return null;
12
+ }
13
+ const minute = parts[0];
14
+ const hour = parts[1];
15
+ const dayOfMonth = parts[2];
16
+ const month = parts[3];
17
+ const next = new Date(after);
18
+ next.setSeconds(0);
19
+ next.setMilliseconds(0);
20
+ if (minute && hour && minute !== "*" && hour !== "*" && dayOfMonth === "*" && month === "*") {
21
+ const targetMinute = Number.parseInt(minute, 10);
22
+ const targetHour = Number.parseInt(hour, 10);
23
+ next.setHours(targetHour, targetMinute, 0, 0);
24
+ if (next <= after) next.setDate(next.getDate() + 1);
25
+ return next;
26
+ }
27
+ next.setMinutes(next.getMinutes() + 1);
28
+ return next;
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ /**
34
+ * Job scheduler for recurring jobs.
35
+ */
36
+ var JobScheduler = class {
37
+ schedules = /* @__PURE__ */ new Map();
38
+ timer;
39
+ checkIntervalMs;
40
+ constructor(queue, options = {}) {
41
+ this.queue = queue;
42
+ this.checkIntervalMs = options.checkIntervalMs ?? 6e4;
43
+ }
44
+ /**
45
+ * Add a scheduled job.
46
+ */
47
+ schedule(config) {
48
+ const nextRun = config.enabled !== false ? getNextCronRun(config.cronExpression) : null;
49
+ this.schedules.set(config.name, {
50
+ ...config,
51
+ enabled: config.enabled ?? true,
52
+ nextRun,
53
+ lastRun: null
54
+ });
55
+ }
56
+ /**
57
+ * Remove a scheduled job.
58
+ */
59
+ unschedule(name) {
60
+ return this.schedules.delete(name);
61
+ }
62
+ /**
63
+ * Enable a scheduled job.
64
+ */
65
+ enable(name) {
66
+ const schedule = this.schedules.get(name);
67
+ if (!schedule) return false;
68
+ schedule.enabled = true;
69
+ schedule.nextRun = getNextCronRun(schedule.cronExpression);
70
+ return true;
71
+ }
72
+ /**
73
+ * Disable a scheduled job.
74
+ */
75
+ disable(name) {
76
+ const schedule = this.schedules.get(name);
77
+ if (!schedule) return false;
78
+ schedule.enabled = false;
79
+ schedule.nextRun = null;
80
+ return true;
81
+ }
82
+ /**
83
+ * Get all schedules.
84
+ */
85
+ getSchedules() {
86
+ return Array.from(this.schedules.values());
87
+ }
88
+ /**
89
+ * Get a specific schedule.
90
+ */
91
+ getSchedule(name) {
92
+ return this.schedules.get(name);
93
+ }
94
+ /**
95
+ * Start the scheduler.
96
+ */
97
+ start() {
98
+ if (this.timer) return;
99
+ this.checkSchedules();
100
+ this.timer = setInterval(() => {
101
+ this.checkSchedules();
102
+ }, this.checkIntervalMs);
103
+ }
104
+ /**
105
+ * Stop the scheduler.
106
+ */
107
+ stop() {
108
+ if (this.timer) {
109
+ clearInterval(this.timer);
110
+ this.timer = void 0;
111
+ }
112
+ }
113
+ /**
114
+ * Check and enqueue due schedules.
115
+ */
116
+ async checkSchedules() {
117
+ const now = /* @__PURE__ */ new Date();
118
+ for (const schedule of this.schedules.values()) {
119
+ if (!schedule.enabled || !schedule.nextRun) continue;
120
+ if (schedule.nextRun <= now) try {
121
+ const payload = typeof schedule.payload === "function" ? await schedule.payload() : schedule.payload;
122
+ await this.queue.enqueue(schedule.jobType, payload, schedule.options);
123
+ schedule.lastRun = now;
124
+ schedule.nextRun = getNextCronRun(schedule.cronExpression, now);
125
+ } catch (error) {
126
+ console.error(`Failed to enqueue scheduled job ${schedule.name}:`, error);
127
+ }
128
+ }
129
+ }
130
+ };
131
+ /**
132
+ * Create a job scheduler instance.
133
+ */
134
+ function createScheduler(queue, options) {
135
+ return new JobScheduler(queue, options);
136
+ }
137
+ /**
138
+ * Helper to define a scheduled job configuration.
139
+ */
140
+ function defineSchedule(config) {
141
+ return config;
142
+ }
143
+
144
+ //#endregion
145
+ export { JobScheduler, createScheduler, defineSchedule };
@@ -1 +1,2 @@
1
- import"zod";import"graphql";
1
+ import "zod";
2
+ import "graphql";
@@ -1 +1,49 @@
1
- import"zod";import{GraphQLScalarType as e}from"graphql";var t=class extends e{zodSchema;jsonSchemaDef;constructor(e){super(e),this.zodSchema=e.zod,this.jsonSchemaDef=e.jsonSchema}getZod(){return this.zodSchema}getPothos(){return this}getJson(){return typeof this.jsonSchemaDef==`function`?this.jsonSchemaDef():this.jsonSchemaDef}getJsonSchemaDef(){return this.jsonSchemaDef}getJsonSchema(){let e=t=>{let n=typeof t==`function`?t():t;if(Array.isArray(n))return n.map(t=>e(t));if(n&&typeof n==`object`){let t={};for(let[r,i]of Object.entries(n))t[r]=e(i);return t}return n};return e(this.getJson())}};export{t};
1
+ import "zod";
2
+ import { GraphQLScalarType } from "graphql";
3
+
4
+ //#region ../schema/dist/FieldType.js
5
+ /**
6
+ * GraphQL scalar wrapper that carries zod and JSON Schema metadata.
7
+ *
8
+ * TInternal is the runtime representation; TExternal is the GraphQL output.
9
+ */
10
+ var FieldType = class extends GraphQLScalarType {
11
+ zodSchema;
12
+ jsonSchemaDef;
13
+ constructor(config) {
14
+ super(config);
15
+ this.zodSchema = config.zod;
16
+ this.jsonSchemaDef = config.jsonSchema;
17
+ }
18
+ /** Return the attached zod schema for validation. */
19
+ getZod() {
20
+ return this.zodSchema;
21
+ }
22
+ /** GraphQL scalar instance usable by Pothos or vanilla GraphQL. */
23
+ getPothos() {
24
+ return this;
25
+ }
26
+ /** Return the JSON Schema (evaluates factory if provided). */
27
+ getJson() {
28
+ return typeof this.jsonSchemaDef === "function" ? this.jsonSchemaDef() : this.jsonSchemaDef;
29
+ }
30
+ getJsonSchemaDef() {
31
+ return this.jsonSchemaDef;
32
+ }
33
+ getJsonSchema() {
34
+ const deepResolve = (v) => {
35
+ const value = typeof v === "function" ? v() : v;
36
+ if (Array.isArray(value)) return value.map((item) => deepResolve(item));
37
+ if (value && typeof value === "object") {
38
+ const obj = {};
39
+ for (const [k, val] of Object.entries(value)) obj[k] = deepResolve(val);
40
+ return obj;
41
+ }
42
+ return value;
43
+ };
44
+ return deepResolve(this.getJson());
45
+ }
46
+ };
47
+
48
+ //#endregion
49
+ export { FieldType };