@weft-framework/server 0.0.0-stage → 0.0.1

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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/account.d.ts +124 -0
  4. package/dist/account.js +344 -0
  5. package/dist/action.d.ts +43 -0
  6. package/dist/action.js +135 -0
  7. package/dist/admin.d.ts +99 -0
  8. package/dist/admin.js +431 -0
  9. package/dist/api.d.ts +21 -0
  10. package/dist/api.js +72 -0
  11. package/dist/app.d.ts +202 -0
  12. package/dist/app.js +3692 -0
  13. package/dist/assets.d.ts +4 -0
  14. package/dist/assets.js +91 -0
  15. package/dist/auth.d.ts +150 -0
  16. package/dist/auth.js +215 -0
  17. package/dist/backup.d.ts +46 -0
  18. package/dist/backup.js +345 -0
  19. package/dist/build.d.ts +33 -0
  20. package/dist/build.js +274 -0
  21. package/dist/bun.d.ts +30 -0
  22. package/dist/bun.js +53 -0
  23. package/dist/calendar.d.ts +161 -0
  24. package/dist/calendar.js +690 -0
  25. package/dist/compiler.d.ts +13 -0
  26. package/dist/compiler.js +58 -0
  27. package/dist/compress.d.ts +6 -0
  28. package/dist/compress.js +78 -0
  29. package/dist/config.d.ts +26 -0
  30. package/dist/config.js +317 -0
  31. package/dist/context.d.ts +9 -0
  32. package/dist/context.js +1 -0
  33. package/dist/contract.d.ts +18 -0
  34. package/dist/contract.js +171 -0
  35. package/dist/datamap.d.ts +24 -0
  36. package/dist/datamap.js +365 -0
  37. package/dist/db-backup.d.ts +27 -0
  38. package/dist/db-backup.js +115 -0
  39. package/dist/dev-events.d.ts +14 -0
  40. package/dist/dev-events.js +135 -0
  41. package/dist/dev.d.ts +1 -0
  42. package/dist/dev.js +240 -0
  43. package/dist/devtools-client.d.ts +1 -0
  44. package/dist/devtools-client.js +362 -0
  45. package/dist/devtools.d.ts +87 -0
  46. package/dist/devtools.js +68 -0
  47. package/dist/edge.d.ts +3 -0
  48. package/dist/edge.js +7 -0
  49. package/dist/email-signin.d.ts +92 -0
  50. package/dist/email-signin.js +259 -0
  51. package/dist/env.d.ts +1 -0
  52. package/dist/env.js +15 -0
  53. package/dist/explain.d.ts +12 -0
  54. package/dist/explain.js +217 -0
  55. package/dist/files.d.ts +6 -0
  56. package/dist/files.js +170 -0
  57. package/dist/grants.d.ts +69 -0
  58. package/dist/grants.js +206 -0
  59. package/dist/image/bitmap.d.ts +11 -0
  60. package/dist/image/bitmap.js +172 -0
  61. package/dist/image/jpeg.d.ts +10 -0
  62. package/dist/image/jpeg.js +697 -0
  63. package/dist/image/png.d.ts +8 -0
  64. package/dist/image/png.js +282 -0
  65. package/dist/image/transform.d.ts +20 -0
  66. package/dist/image/transform.js +52 -0
  67. package/dist/image/worker.d.ts +1 -0
  68. package/dist/image/worker.js +11 -0
  69. package/dist/images.d.ts +39 -0
  70. package/dist/images.js +283 -0
  71. package/dist/index.d.ts +64 -0
  72. package/dist/index.js +31 -0
  73. package/dist/inspect-hub.d.ts +42 -0
  74. package/dist/inspect-hub.js +14 -0
  75. package/dist/inspector.d.ts +51 -0
  76. package/dist/inspector.js +193 -0
  77. package/dist/job-admin.d.ts +55 -0
  78. package/dist/job-admin.js +89 -0
  79. package/dist/jobs.d.ts +222 -0
  80. package/dist/jobs.js +789 -0
  81. package/dist/live.d.ts +72 -0
  82. package/dist/live.js +481 -0
  83. package/dist/load-config.d.ts +2 -0
  84. package/dist/load-config.js +41 -0
  85. package/dist/log.d.ts +20 -0
  86. package/dist/log.js +143 -0
  87. package/dist/mail.d.ts +189 -0
  88. package/dist/mail.js +999 -0
  89. package/dist/media.d.ts +129 -0
  90. package/dist/media.js +470 -0
  91. package/dist/meta.d.ts +54 -0
  92. package/dist/meta.js +146 -0
  93. package/dist/middleware.d.ts +20 -0
  94. package/dist/middleware.js +101 -0
  95. package/dist/migrate.d.ts +12 -0
  96. package/dist/migrate.js +88 -0
  97. package/dist/node.d.ts +26 -0
  98. package/dist/node.js +96 -0
  99. package/dist/notice.d.ts +21 -0
  100. package/dist/notice.js +48 -0
  101. package/dist/npm.d.ts +16 -0
  102. package/dist/npm.js +347 -0
  103. package/dist/oauth.d.ts +76 -0
  104. package/dist/oauth.js +408 -0
  105. package/dist/otel.d.ts +57 -0
  106. package/dist/otel.js +293 -0
  107. package/dist/passkey.d.ts +99 -0
  108. package/dist/passkey.js +572 -0
  109. package/dist/password.d.ts +8 -0
  110. package/dist/password.js +65 -0
  111. package/dist/pdf.d.ts +46 -0
  112. package/dist/pdf.js +332 -0
  113. package/dist/personal-data.d.ts +22 -0
  114. package/dist/personal-data.js +148 -0
  115. package/dist/pointers.d.ts +9 -0
  116. package/dist/pointers.js +148 -0
  117. package/dist/postcss.d.ts +3 -0
  118. package/dist/postcss.js +89 -0
  119. package/dist/presence.d.ts +27 -0
  120. package/dist/presence.js +161 -0
  121. package/dist/preview.d.ts +25 -0
  122. package/dist/preview.js +353 -0
  123. package/dist/production.d.ts +16 -0
  124. package/dist/production.js +119 -0
  125. package/dist/project.d.ts +23 -0
  126. package/dist/project.js +536 -0
  127. package/dist/regions.d.ts +47 -0
  128. package/dist/regions.js +511 -0
  129. package/dist/replay.d.ts +44 -0
  130. package/dist/replay.js +259 -0
  131. package/dist/router.d.ts +29 -0
  132. package/dist/router.js +146 -0
  133. package/dist/rules-diff.d.ts +18 -0
  134. package/dist/rules-diff.js +165 -0
  135. package/dist/rules-test.d.ts +17 -0
  136. package/dist/rules-test.js +108 -0
  137. package/dist/saml.d.ts +160 -0
  138. package/dist/saml.js +959 -0
  139. package/dist/seal.d.ts +35 -0
  140. package/dist/seal.js +107 -0
  141. package/dist/secret.d.ts +14 -0
  142. package/dist/secret.js +110 -0
  143. package/dist/security.d.ts +53 -0
  144. package/dist/security.js +250 -0
  145. package/dist/seed.d.ts +16 -0
  146. package/dist/seed.js +94 -0
  147. package/dist/seo.d.ts +42 -0
  148. package/dist/seo.js +175 -0
  149. package/dist/settings.d.ts +79 -0
  150. package/dist/settings.js +212 -0
  151. package/dist/shared.d.ts +15 -0
  152. package/dist/shared.js +283 -0
  153. package/dist/shell.d.ts +12 -0
  154. package/dist/shell.js +118 -0
  155. package/dist/storage.d.ts +13 -0
  156. package/dist/storage.js +55 -0
  157. package/dist/support.d.ts +83 -0
  158. package/dist/support.js +236 -0
  159. package/dist/sync.d.ts +35 -0
  160. package/dist/sync.js +167 -0
  161. package/dist/tailwind.d.ts +14 -0
  162. package/dist/tailwind.js +117 -0
  163. package/dist/two-factor.d.ts +103 -0
  164. package/dist/two-factor.js +435 -0
  165. package/dist/uploads.d.ts +185 -0
  166. package/dist/uploads.js +991 -0
  167. package/dist/webhooks.d.ts +169 -0
  168. package/dist/webhooks.js +758 -0
  169. package/dist/webpush.d.ts +97 -0
  170. package/dist/webpush.js +372 -0
  171. package/dist/wizard.d.ts +141 -0
  172. package/dist/wizard.js +410 -0
  173. package/dist/workflows.d.ts +134 -0
  174. package/dist/workflows.js +511 -0
  175. package/package.json +186 -4
package/dist/jobs.d.ts ADDED
@@ -0,0 +1,222 @@
1
+ import { type Model, type SqlDatabase } from "@weft-framework/data";
2
+ import { type ParamSpec } from "./action.js";
3
+ import type { PageContext } from "./context.js";
4
+ import type { Telemetry } from "./otel.js";
5
+ type Maybe<T> = T | Promise<T>;
6
+ export type JobStatus = "queued" | "running" | "done" | "dead" | "cancelled";
7
+ export interface JobActor {
8
+ user: string;
9
+ tenant?: string;
10
+ }
11
+ export interface JobRecord {
12
+ id: string;
13
+ name: string;
14
+ args: unknown[];
15
+ actor: JobActor | null;
16
+ status: JobStatus;
17
+ attempts: number;
18
+ maxAttempts: number;
19
+ runAt: number;
20
+ created: number;
21
+ updated: number;
22
+ worker: string | null;
23
+ leaseUntil: number;
24
+ error: string | null;
25
+ key: string | null;
26
+ keepKey: boolean;
27
+ progress: number | null;
28
+ }
29
+ export interface JobFilter {
30
+ status?: JobStatus;
31
+ name?: string;
32
+ limit?: number;
33
+ }
34
+ export interface JobStore {
35
+ add(r: JobRecord): Maybe<boolean>;
36
+ get(id: string): Maybe<JobRecord | null | undefined>;
37
+ claim(now: number, worker: string, leaseUntil: number): Maybe<JobRecord | null | undefined>;
38
+ extend(id: string, worker: string, leaseUntil: number, progress: number | null): Maybe<boolean>;
39
+ settle(id: string, worker: string, to: {
40
+ status: "queued" | "done" | "dead";
41
+ runAt?: number;
42
+ error?: string | null;
43
+ }, now: number): Maybe<boolean>;
44
+ move(id: string, from: JobStatus[], to: {
45
+ status: "queued" | "cancelled";
46
+ runAt?: number;
47
+ attempts?: number;
48
+ }, now: number): Maybe<boolean>;
49
+ list(f: JobFilter): Maybe<JobRecord[]>;
50
+ counts(): Maybe<Record<JobStatus, number>>;
51
+ sweep(before: number): Maybe<void>;
52
+ }
53
+ export declare class MemoryJobStore implements JobStore {
54
+ #private;
55
+ add(r: JobRecord): boolean;
56
+ get(id: string): JobRecord | null;
57
+ claim(now: number, worker: string, leaseUntil: number): JobRecord | null;
58
+ extend(id: string, worker: string, leaseUntil: number, progress: number | null): boolean;
59
+ settle(id: string, worker: string, to: {
60
+ status: "queued" | "done" | "dead";
61
+ runAt?: number;
62
+ error?: string | null;
63
+ }, now: number): boolean;
64
+ move(id: string, from: JobStatus[], to: {
65
+ status: "queued" | "cancelled";
66
+ runAt?: number;
67
+ attempts?: number;
68
+ }, now: number): boolean;
69
+ list(f: JobFilter): JobRecord[];
70
+ counts(): Record<JobStatus, number>;
71
+ sweep(before: number): void;
72
+ }
73
+ export declare class SqlJobStore implements JobStore {
74
+ #private;
75
+ constructor(db: SqlDatabase, table?: string);
76
+ add(r: JobRecord): boolean;
77
+ get(id: string): JobRecord | null;
78
+ claim(now: number, worker: string, leaseUntil: number): JobRecord | null;
79
+ extend(id: string, worker: string, leaseUntil: number, progress: number | null): boolean;
80
+ settle(id: string, worker: string, to: {
81
+ status: "queued" | "done" | "dead";
82
+ runAt?: number;
83
+ error?: string | null;
84
+ }, now: number): boolean;
85
+ move(id: string, from: JobStatus[], to: {
86
+ status: "queued" | "cancelled";
87
+ runAt?: number;
88
+ attempts?: number;
89
+ }, now: number): boolean;
90
+ list(f: JobFilter): JobRecord[];
91
+ counts(): Record<JobStatus, number>;
92
+ sweep(before: number): void;
93
+ }
94
+ export interface PgQueryable {
95
+ query(text: string, values?: unknown[]): Promise<{
96
+ rows: Record<string, unknown>[];
97
+ }>;
98
+ }
99
+ export declare class PgJobStore implements JobStore {
100
+ #private;
101
+ constructor(db: PgQueryable, table?: string);
102
+ ready(): Promise<void>;
103
+ add(r: JobRecord): Promise<boolean>;
104
+ get(id: string): Promise<JobRecord | null>;
105
+ claim(now: number, worker: string, leaseUntil: number): Promise<JobRecord | null>;
106
+ extend(id: string, worker: string, leaseUntil: number, progress: number | null): Promise<boolean>;
107
+ settle(id: string, worker: string, to: {
108
+ status: "queued" | "done" | "dead";
109
+ runAt?: number;
110
+ error?: string | null;
111
+ }, now: number): Promise<boolean>;
112
+ move(id: string, from: JobStatus[], to: {
113
+ status: "queued" | "cancelled";
114
+ runAt?: number;
115
+ attempts?: number;
116
+ }, now: number): Promise<boolean>;
117
+ list(f: JobFilter): Promise<JobRecord[]>;
118
+ counts(): Promise<Record<JobStatus, number>>;
119
+ sweep(before: number): Promise<void>;
120
+ }
121
+ export interface JobContext {
122
+ user: unknown;
123
+ job: {
124
+ id: string;
125
+ name: string;
126
+ attempt: number;
127
+ maxAttempts: number;
128
+ };
129
+ signal: AbortSignal;
130
+ progress(fraction: number): void;
131
+ }
132
+ export interface JobOptions {
133
+ attempts?: number;
134
+ backoff?(attempt: number): number;
135
+ timeoutMs?: number;
136
+ }
137
+ declare const JOB: unique symbol;
138
+ export interface Job<A extends unknown[] = never[]> {
139
+ readonly [JOB]: true;
140
+ readonly name: string;
141
+ readonly params: readonly ParamSpec[];
142
+ readonly options: Required<Omit<JobOptions, "backoff">> & Pick<JobOptions, "backoff">;
143
+ run(ctx: JobContext, ...args: A): unknown;
144
+ }
145
+ export declare class JobError extends Error {
146
+ readonly retry: boolean;
147
+ constructor(message: string, opts?: {
148
+ retry?: boolean;
149
+ cause?: unknown;
150
+ });
151
+ }
152
+ export declare function defineJob<A extends unknown[]>(name: string, params: readonly ParamSpec[], run: (ctx: JobContext, ...args: A) => unknown, opts?: JobOptions): Job<A>;
153
+ export declare function isJob(v: unknown): v is Job<unknown[]>;
154
+ export interface Cron {
155
+ readonly expression: string;
156
+ next(after: number): number;
157
+ }
158
+ export declare function parseCron(expression: string): Cron;
159
+ export interface Schedule {
160
+ name?: string;
161
+ cron: string;
162
+ job: Job<never[]> | Job<unknown[]>;
163
+ args?: Record<string, unknown>;
164
+ as?: JobActor;
165
+ }
166
+ export interface JobProgressRow {
167
+ id: string;
168
+ user: string;
169
+ name: string;
170
+ status: string;
171
+ progress: number | null;
172
+ updated: number;
173
+ }
174
+ export interface JobsOptions {
175
+ jobs: readonly Job<never[]>[] | readonly Job<unknown[]>[] | Record<string, unknown>;
176
+ track?: {
177
+ prefix?: string;
178
+ };
179
+ store?: JobStore;
180
+ user?(id: string, tenant?: string): unknown;
181
+ concurrency?: number;
182
+ pollMs?: number;
183
+ leaseMs?: number;
184
+ schedule?: readonly Schedule[];
185
+ keepDoneMs?: number;
186
+ onError?(err: unknown, job: JobRecord | null): void;
187
+ telemetry?: Pick<Telemetry, "span">;
188
+ now?(): number;
189
+ random?(): number;
190
+ }
191
+ export interface EnqueueOptions {
192
+ delayMs?: number;
193
+ runAt?: number;
194
+ key?: string;
195
+ as?: JobActor | null;
196
+ track?: boolean;
197
+ }
198
+ export declare class Jobs {
199
+ #private;
200
+ readonly models: {
201
+ JobProgress?: Model<JobProgressRow>;
202
+ };
203
+ constructor(o: JobsOptions);
204
+ enqueue<A extends unknown[]>(ctx: PageContext | null, job: Job<A>, args?: Record<string, unknown>, o?: EnqueueOptions): Promise<string | false>;
205
+ progress(actor: unknown, id: string): {
206
+ name: string;
207
+ status: string;
208
+ progress: number | null;
209
+ } | null;
210
+ names(): string[];
211
+ get(id: string): Promise<JobRecord | null>;
212
+ list(f?: JobFilter): Promise<JobRecord[]>;
213
+ counts(): Promise<Record<JobStatus, number>>;
214
+ retry(id: string): Promise<boolean>;
215
+ cancel(id: string): Promise<boolean>;
216
+ start(): void;
217
+ stop(): Promise<void>;
218
+ tick(): Promise<void>;
219
+ drain(max?: number): Promise<void>;
220
+ }
221
+ export declare function createJobs(o: JobsOptions): Jobs;
222
+ export {};