semola 0.6.0 → 0.6.2
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.
- package/README.md +19 -5
- package/dist/index-DISN0WKZ.d.mts +78 -0
- package/dist/lib/api/index.cjs +1 -537
- package/dist/lib/api/index.d.cts +1 -271
- package/dist/lib/api/index.d.mts +100 -164
- package/dist/lib/api/index.mjs +1 -535
- package/dist/lib/cache/index.cjs +1 -99
- package/dist/lib/cache/index.d.cts +1 -27
- package/dist/lib/cache/index.mjs +1 -98
- package/dist/lib/cli/index.cjs +3 -0
- package/dist/lib/cli/index.d.cts +1 -0
- package/dist/lib/cli/index.d.mts +90 -0
- package/dist/lib/cli/index.mjs +3 -0
- package/dist/lib/cron/index.cjs +1 -735
- package/dist/lib/cron/index.d.cts +1 -146
- package/dist/lib/cron/index.d.mts +99 -36
- package/dist/lib/cron/index.mjs +1 -726
- package/dist/lib/errors/index.cjs +1 -30
- package/dist/lib/errors/index.d.cts +1 -13
- package/dist/lib/errors/index.mjs +1 -26
- package/dist/lib/i18n/index.cjs +1 -42
- package/dist/lib/i18n/index.d.cts +1 -28
- package/dist/lib/i18n/index.d.mts +2 -2
- package/dist/lib/i18n/index.mjs +1 -41
- package/dist/lib/logging/index.cjs +1 -388
- package/dist/lib/logging/index.d.cts +1 -108
- package/dist/lib/logging/index.mjs +1 -374
- package/dist/lib/orm/index.cjs +1 -1642
- package/dist/lib/orm/index.d.cts +1 -402
- package/dist/lib/orm/index.d.mts +27 -25
- package/dist/lib/orm/index.mjs +1 -1630
- package/dist/lib/policy/index.cjs +1 -285
- package/dist/lib/policy/index.d.cts +1 -77
- package/dist/lib/policy/index.d.mts +1 -1
- package/dist/lib/policy/index.mjs +1 -265
- package/dist/lib/prompts/index.cjs +6 -769
- package/dist/lib/prompts/index.d.cts +1 -75
- package/dist/lib/prompts/index.mjs +6 -762
- package/dist/lib/pubsub/index.cjs +1 -141
- package/dist/lib/pubsub/index.d.cts +1 -26
- package/dist/lib/pubsub/index.mjs +1 -140
- package/dist/lib/queue/index.cjs +1 -212
- package/dist/lib/queue/index.d.cts +1 -81
- package/dist/lib/queue/index.mjs +1 -209
- package/dist/lib/workflow/index.cjs +1 -537
- package/dist/lib/workflow/index.d.cts +1 -150
- package/dist/lib/workflow/index.d.mts +0 -1
- package/dist/lib/workflow/index.mjs +1 -527
- package/dist/rolldown-runtime-CMqjfN_6.cjs +1 -0
- package/package.json +17 -5
- package/dist/chunk-CKQMccvm.cjs +0 -28
package/README.md
CHANGED
|
@@ -26,11 +26,12 @@ Type-safe APIs, Redis queues, pub/sub, i18n, caching & auth with tree-shakeable
|
|
|
26
26
|
| **🔐 Policy** | Policy-based authorization with type-safe guards | `semola/policy` |
|
|
27
27
|
| **🌍 i18n** | Compile-time validated internationalization | `semola/i18n` |
|
|
28
28
|
| **💾 Cache** | Redis cache wrapper with TTL & automatic serialization | `semola/cache` |
|
|
29
|
-
| **⏰ Cron** | In-memory cron scheduler for periodic task execution | `semola/cron` |
|
|
29
|
+
| **⏰ Cron** | In-memory and OS cron scheduler for periodic task execution | `semola/cron` |
|
|
30
30
|
| **🔁 Workflow** | Durable resumable workflows with retries and hooks | `semola/workflow` |
|
|
31
31
|
| **⚠️ Errors** | Result-based error handling without try/catch | `semola/errors` |
|
|
32
32
|
| **📃 Logging** | A simple logging utility | `semola/logging` |
|
|
33
33
|
| **⌨️ Prompts** | Interactive zero-dependency CLI prompts | `semola/prompts` |
|
|
34
|
+
| **🖥️ CLI** | Non-interactive CLI builder with schema validation | `semola/cli` |
|
|
34
35
|
| **🗄️ ORM** | Type-safe data layer with query APIs | `semola/orm` |
|
|
35
36
|
|
|
36
37
|
---
|
|
@@ -153,18 +154,30 @@ console.log(user);
|
|
|
153
154
|
### Schedule Recurring Tasks
|
|
154
155
|
|
|
155
156
|
```typescript
|
|
156
|
-
import { Cron } from "semola/cron";
|
|
157
|
+
import { Cron, RetryCronJob } from "semola/cron";
|
|
157
158
|
|
|
158
159
|
const cleanup = new Cron({
|
|
159
160
|
name: "daily-cleanup",
|
|
160
|
-
schedule: "
|
|
161
|
+
schedule: "@daily",
|
|
161
162
|
handler: async () => {
|
|
162
163
|
await deleteOldLogs();
|
|
163
164
|
await archiveInactiveUsers();
|
|
164
165
|
},
|
|
166
|
+
retry: new RetryCronJob({
|
|
167
|
+
maxAttempts: 2,
|
|
168
|
+
onError: (err) => console.log(`An error: ${err.error.message}`),
|
|
169
|
+
onFailedAttempt: async ({ attemptNumber, delay, error, retriesLeft }) => {
|
|
170
|
+
console.log(
|
|
171
|
+
`Attempt ${attemptNumber} failed. Retrying in ${delay}ms. ${retriesLeft} retries left.`,
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
await recover();
|
|
175
|
+
},
|
|
176
|
+
}),
|
|
165
177
|
});
|
|
166
178
|
|
|
167
|
-
cleanup.
|
|
179
|
+
cleanup.run();
|
|
180
|
+
|
|
168
181
|
```
|
|
169
182
|
|
|
170
183
|
### Query a Database
|
|
@@ -317,7 +330,7 @@ _Higher is better for req/sec, lower is better for latency._
|
|
|
317
330
|
- [API Framework](./docs/api.md) - Type-safe REST API framework with OpenAPI
|
|
318
331
|
- [Queue](./docs/queue.md) - Redis-backed job queue with timeouts & concurrency
|
|
319
332
|
- [PubSub](./docs/pubsub.md) - Type-safe Redis pub/sub
|
|
320
|
-
- [Cron](./docs/cron.md) - In-memory cron scheduler for periodic task execution
|
|
333
|
+
- [Cron](./docs/cron.md) - In-memory and OS cron scheduler for periodic task execution
|
|
321
334
|
- [Workflow](./docs/workflow.md) - Durable and resumable workflows with retries and hooks
|
|
322
335
|
- [Policy](./docs/policy.md) - Policy-based authorization
|
|
323
336
|
- [i18n](./docs/i18n.md) - Type-safe internationalization
|
|
@@ -325,6 +338,7 @@ _Higher is better for req/sec, lower is better for latency._
|
|
|
325
338
|
- [Errors](./docs/errors.md) - Result-based error handling
|
|
326
339
|
- [Logging](./docs/logging.md) - Logging utility
|
|
327
340
|
- [Prompts](./docs/prompts.md) - Interactive CLI prompts
|
|
341
|
+
- [CLI](./docs/cli.md) - Non-interactive CLI builder
|
|
328
342
|
- [ORM](./docs/orm.md) - Type-safe data layer with SQLite support
|
|
329
343
|
|
|
330
344
|
---
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region node_modules/@standard-schema/spec/dist/index.d.ts
|
|
2
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
3
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
4
|
+
/** The Standard properties. */
|
|
5
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
6
|
+
}
|
|
7
|
+
declare namespace StandardTypedV1 {
|
|
8
|
+
/** The Standard Typed properties interface. */
|
|
9
|
+
interface Props<Input = unknown, Output = Input> {
|
|
10
|
+
/** The version number of the standard. */
|
|
11
|
+
readonly version: 1;
|
|
12
|
+
/** The vendor name of the schema library. */
|
|
13
|
+
readonly vendor: string;
|
|
14
|
+
/** Inferred types associated with the schema. */
|
|
15
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The Standard Typed types interface. */
|
|
18
|
+
interface Types<Input = unknown, Output = Input> {
|
|
19
|
+
/** The input type of the schema. */
|
|
20
|
+
readonly input: Input;
|
|
21
|
+
/** The output type of the schema. */
|
|
22
|
+
readonly output: Output;
|
|
23
|
+
}
|
|
24
|
+
/** Infers the input type of a Standard Typed. */
|
|
25
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
26
|
+
/** Infers the output type of a Standard Typed. */
|
|
27
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
28
|
+
}
|
|
29
|
+
/** The Standard Schema interface. */
|
|
30
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
31
|
+
/** The Standard Schema properties. */
|
|
32
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
33
|
+
}
|
|
34
|
+
declare namespace StandardSchemaV1 {
|
|
35
|
+
/** The Standard Schema properties interface. */
|
|
36
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
37
|
+
/** Validates unknown input values. */
|
|
38
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
39
|
+
}
|
|
40
|
+
/** The result interface of the validate function. */
|
|
41
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
42
|
+
/** The result interface if validation succeeds. */
|
|
43
|
+
interface SuccessResult<Output> {
|
|
44
|
+
/** The typed output value. */
|
|
45
|
+
readonly value: Output;
|
|
46
|
+
/** A falsy value for `issues` indicates success. */
|
|
47
|
+
readonly issues?: undefined;
|
|
48
|
+
}
|
|
49
|
+
interface Options {
|
|
50
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
51
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** The result interface if validation fails. */
|
|
54
|
+
interface FailureResult {
|
|
55
|
+
/** The issues of failed validation. */
|
|
56
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
57
|
+
}
|
|
58
|
+
/** The issue interface of the failure output. */
|
|
59
|
+
interface Issue {
|
|
60
|
+
/** The error message of the issue. */
|
|
61
|
+
readonly message: string;
|
|
62
|
+
/** The path of the issue, if any. */
|
|
63
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
64
|
+
}
|
|
65
|
+
/** The path segment interface of the issue. */
|
|
66
|
+
interface PathSegment {
|
|
67
|
+
/** The key representing a path segment. */
|
|
68
|
+
readonly key: PropertyKey;
|
|
69
|
+
}
|
|
70
|
+
/** The Standard types interface. */
|
|
71
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
72
|
+
/** Infers the input type of a Standard. */
|
|
73
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
74
|
+
/** Infers the output type of a Standard. */
|
|
75
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { StandardSchemaV1 as t };
|