alepha 0.9.3 → 0.9.5
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/LICENSE +21 -21
- package/README.md +93 -47
- package/batch.d.ts +492 -19
- package/bucket.d.ts +449 -19
- package/cache/redis.d.ts +7 -7
- package/cache.d.ts +134 -7
- package/command.d.ts +11 -9
- package/core.d.ts +184 -291
- package/datetime.d.ts +3 -7
- package/email.cjs +8 -0
- package/email.d.ts +246 -0
- package/email.js +1 -0
- package/file.d.ts +0 -3
- package/lock/redis.d.ts +2 -5
- package/lock.d.ts +420 -38
- package/logger.cjs +8 -0
- package/logger.d.ts +227 -0
- package/logger.js +1 -0
- package/package.json +57 -42
- package/postgres.d.ts +1827 -344
- package/queue/redis.d.ts +0 -2
- package/queue.d.ts +662 -21
- package/react/auth.d.ts +214 -134
- package/react/form.d.ts +119 -71
- package/react/head.d.ts +8 -15
- package/react/i18n.d.ts +27 -29
- package/react.d.ts +412 -349
- package/redis.d.ts +12 -12
- package/retry.d.ts +0 -4
- package/router.d.ts +1 -1
- package/scheduler.d.ts +9 -13
- package/security.d.ts +68 -86
- package/server/cache.d.ts +3 -5
- package/server/compress.d.ts +0 -3
- package/server/cookies.d.ts +4 -7
- package/server/cors.d.ts +1 -5
- package/server/health.d.ts +0 -3
- package/server/helmet.d.ts +28 -28
- package/server/links.d.ts +143 -30
- package/server/metrics.d.ts +1 -5
- package/server/multipart.d.ts +0 -2
- package/server/proxy.d.ts +195 -7
- package/server/security.d.ts +6 -7
- package/server/static.d.ts +4 -8
- package/server/swagger.d.ts +2 -6
- package/server.d.ts +656 -108
- package/topic/redis.d.ts +3 -6
- package/topic.d.ts +808 -24
- package/vite.d.ts +7 -5
package/cache.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _alepha_core1 from "alepha";
|
|
2
1
|
import * as _alepha_core0 from "alepha";
|
|
3
2
|
import { Descriptor, InstantiableClass, KIND } from "alepha";
|
|
4
3
|
import { DateTimeProvider, DurationLike, Timeout } from "alepha/datetime";
|
|
4
|
+
import * as _alepha_logger0 from "alepha/logger";
|
|
5
5
|
|
|
6
6
|
//#region src/providers/CacheProvider.d.ts
|
|
7
7
|
/**
|
|
@@ -41,11 +41,141 @@ declare abstract class CacheProvider {
|
|
|
41
41
|
abstract has(name: string, key: string): Promise<boolean>;
|
|
42
42
|
abstract keys(name: string, filter?: string): Promise<string[]>;
|
|
43
43
|
}
|
|
44
|
-
//# sourceMappingURL=CacheProvider.d.ts.map
|
|
45
44
|
//#endregion
|
|
46
45
|
//#region src/descriptors/$cache.d.ts
|
|
47
46
|
/**
|
|
48
|
-
* Creates a cache
|
|
47
|
+
* Creates a cache descriptor for high-performance data caching with automatic cache management.
|
|
48
|
+
*
|
|
49
|
+
* This descriptor provides a powerful caching layer that can significantly improve application performance
|
|
50
|
+
* by storing frequently accessed data in memory or external cache stores like Redis. It supports both
|
|
51
|
+
* function result caching and manual cache operations with intelligent serialization and TTL management.
|
|
52
|
+
*
|
|
53
|
+
* **Key Features**
|
|
54
|
+
*
|
|
55
|
+
* - **Function Result Caching**: Automatically cache function results based on input parameters
|
|
56
|
+
* - **Multiple Storage Backends**: Support for in-memory, Redis, and custom cache providers
|
|
57
|
+
* - **Intelligent Serialization**: Automatic handling of JSON, strings, and binary data
|
|
58
|
+
* - **TTL Management**: Configurable time-to-live with automatic expiration
|
|
59
|
+
* - **Cache Invalidation**: Pattern-based cache invalidation with wildcard support
|
|
60
|
+
* - **Environment Controls**: Enable/disable caching via environment variables
|
|
61
|
+
* - **Type Safety**: Full TypeScript support with generic type parameters
|
|
62
|
+
*
|
|
63
|
+
* ## Cache Strategies
|
|
64
|
+
*
|
|
65
|
+
* ### 1. Function Result Caching (Memoization)
|
|
66
|
+
* Automatically cache the results of expensive operations based on input parameters.
|
|
67
|
+
*
|
|
68
|
+
* ### 2. Manual Cache Operations
|
|
69
|
+
* Direct cache operations for custom caching logic and data storage.
|
|
70
|
+
*
|
|
71
|
+
* ## Storage Backends
|
|
72
|
+
*
|
|
73
|
+
* - **Memory**: Fast in-memory cache (default for development)
|
|
74
|
+
* - **Redis**: Distributed cache for production environments
|
|
75
|
+
* - **Custom Providers**: Implement your own cache storage backend
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* **Basic function result caching:**
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { $cache } from "alepha/cache";
|
|
81
|
+
*
|
|
82
|
+
* class DataService {
|
|
83
|
+
* // Cache expensive database queries
|
|
84
|
+
* getUserData = $cache({
|
|
85
|
+
* name: "user-data",
|
|
86
|
+
* ttl: [10, "minutes"],
|
|
87
|
+
* handler: async (userId: string) => {
|
|
88
|
+
* // Expensive database operation
|
|
89
|
+
* return await database.users.findById(userId);
|
|
90
|
+
* }
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* async getUser(id: string) {
|
|
94
|
+
* // This will hit cache on subsequent calls with same ID
|
|
95
|
+
* return await this.getUserData(id);
|
|
96
|
+
* }
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* **API response caching with custom key generation:**
|
|
102
|
+
* ```ts
|
|
103
|
+
* class ApiService {
|
|
104
|
+
* fetchUserPosts = $cache({
|
|
105
|
+
* name: "user-posts",
|
|
106
|
+
* ttl: [5, "minutes"],
|
|
107
|
+
* key: (userId: string, page: number) => `${userId}:page:${page}`,
|
|
108
|
+
* handler: async (userId: string, page: number = 1) => {
|
|
109
|
+
* const response = await fetch(`/api/users/${userId}/posts?page=${page}`);
|
|
110
|
+
* return await response.json();
|
|
111
|
+
* }
|
|
112
|
+
* });
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* **Manual cache operations for custom logic:**
|
|
118
|
+
* ```ts
|
|
119
|
+
* class SessionService {
|
|
120
|
+
* sessionCache = $cache<UserSession>({
|
|
121
|
+
* name: "user-sessions",
|
|
122
|
+
* ttl: [1, "hour"],
|
|
123
|
+
* provider: "memory" // Use memory cache for sessions
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* async storeSession(sessionId: string, session: UserSession) {
|
|
127
|
+
* await this.sessionCache.set(sessionId, session);
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
130
|
+
* async getSession(sessionId: string): Promise<UserSession | undefined> {
|
|
131
|
+
* return await this.sessionCache.get(sessionId);
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* async invalidateUserSessions(userId: string) {
|
|
135
|
+
* // Invalidate all sessions for a user using wildcards
|
|
136
|
+
* await this.sessionCache.invalidate(`user:${userId}:*`);
|
|
137
|
+
* }
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* **Redis-backed caching for production:**
|
|
143
|
+
* ```ts
|
|
144
|
+
* class ProductService {
|
|
145
|
+
* productCache = $cache({
|
|
146
|
+
* name: "products",
|
|
147
|
+
* ttl: [1, "hour"],
|
|
148
|
+
* provider: RedisCacheProvider, // Use Redis for distributed caching
|
|
149
|
+
* handler: async (productId: string) => {
|
|
150
|
+
* return await this.database.products.findById(productId);
|
|
151
|
+
* }
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* async invalidateProduct(productId: string) {
|
|
155
|
+
* await this.productCache.invalidate(productId);
|
|
156
|
+
* }
|
|
157
|
+
*
|
|
158
|
+
* async invalidateAllProducts() {
|
|
159
|
+
* await this.productCache.invalidate("*");
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* **Conditional caching with environment controls:**
|
|
166
|
+
* ```ts
|
|
167
|
+
* class ExpensiveService {
|
|
168
|
+
* computation = $cache({
|
|
169
|
+
* name: "heavy-computation",
|
|
170
|
+
* ttl: [1, "day"],
|
|
171
|
+
* disabled: process.env.NODE_ENV === "development", // Disable in dev
|
|
172
|
+
* handler: async (input: ComplexInput) => {
|
|
173
|
+
* // Very expensive computation that should be cached in production
|
|
174
|
+
* return await performHeavyComputation(input);
|
|
175
|
+
* }
|
|
176
|
+
* });
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
49
179
|
*/
|
|
50
180
|
declare const $cache: {
|
|
51
181
|
<TReturn = string, TParameter extends any[] = any[]>(options?: CacheDescriptorOptions<TReturn, TParameter>): CacheDescriptorFn<TReturn, TParameter>;
|
|
@@ -116,7 +246,6 @@ interface CacheDescriptorFn<TReturn = any, TParameter extends any[] = any[]> ext
|
|
|
116
246
|
*/
|
|
117
247
|
(...args: TParameter): Promise<TReturn>;
|
|
118
248
|
}
|
|
119
|
-
//# sourceMappingURL=$cache.d.ts.map
|
|
120
249
|
//#endregion
|
|
121
250
|
//#region src/providers/MemoryCacheProvider.d.ts
|
|
122
251
|
type CacheName = string;
|
|
@@ -127,7 +256,7 @@ type CacheValue = {
|
|
|
127
256
|
};
|
|
128
257
|
declare class MemoryCacheProvider implements CacheProvider {
|
|
129
258
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
130
|
-
protected readonly log:
|
|
259
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
131
260
|
protected store: Record<CacheName, Record<CacheKey, CacheValue>>;
|
|
132
261
|
get(name: string, key: string): Promise<Uint8Array | undefined>;
|
|
133
262
|
set(name: string, key: string, value: Uint8Array, ttl?: number): Promise<Uint8Array>;
|
|
@@ -149,8 +278,6 @@ declare class MemoryCacheProvider implements CacheProvider {
|
|
|
149
278
|
* @module alepha.cache
|
|
150
279
|
*/
|
|
151
280
|
declare const AlephaCache: _alepha_core0.Service<_alepha_core0.Module>;
|
|
152
|
-
//# sourceMappingURL=index.d.ts.map
|
|
153
|
-
|
|
154
281
|
//#endregion
|
|
155
282
|
export { $cache, AlephaCache, CacheDescriptor, CacheDescriptorFn, CacheDescriptorOptions, CacheProvider, MemoryCacheProvider };
|
|
156
283
|
//# sourceMappingURL=index.d.ts.map
|
package/command.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _alepha_core1 from "alepha";
|
|
2
|
-
import
|
|
3
|
-
import { Alepha, AlephaError, Async, Descriptor, KIND, Logger, Static, TObject, TSchema } from "alepha";
|
|
2
|
+
import { Alepha, AlephaError, Async, Descriptor, KIND, Static, TObject, TSchema } from "alepha";
|
|
4
3
|
import * as fs from "node:fs/promises";
|
|
5
4
|
import { glob } from "node:fs/promises";
|
|
5
|
+
import * as _alepha_logger0 from "alepha/logger";
|
|
6
6
|
import * as _sinclair_typebox0 from "@sinclair/typebox";
|
|
7
7
|
|
|
8
8
|
//#region src/helpers/Runner.d.ts
|
|
@@ -30,11 +30,11 @@ interface RunnerMethod {
|
|
|
30
30
|
cp: (source: string, dest: string, options?: RunOptions) => Promise<string>;
|
|
31
31
|
}
|
|
32
32
|
declare class Runner {
|
|
33
|
-
protected readonly log: Logger;
|
|
33
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
34
34
|
protected readonly timers: Timer[];
|
|
35
35
|
protected readonly startTime: number;
|
|
36
36
|
readonly run: RunnerMethod;
|
|
37
|
-
constructor(
|
|
37
|
+
constructor();
|
|
38
38
|
protected createRunMethod(): RunnerMethod;
|
|
39
39
|
protected exec(cmd: string): Promise<string>;
|
|
40
40
|
/**
|
|
@@ -101,13 +101,11 @@ interface CommandHandlerArgs<T extends TObject> {
|
|
|
101
101
|
glob: typeof glob;
|
|
102
102
|
fs: typeof fs;
|
|
103
103
|
}
|
|
104
|
-
//# sourceMappingURL=$command.d.ts.map
|
|
105
104
|
//#endregion
|
|
106
105
|
//#region src/errors/CommandError.d.ts
|
|
107
106
|
declare class CommandError extends AlephaError {
|
|
108
107
|
readonly name = "CommandError";
|
|
109
108
|
}
|
|
110
|
-
//# sourceMappingURL=CommandError.d.ts.map
|
|
111
109
|
//#endregion
|
|
112
110
|
//#region src/providers/CliProvider.d.ts
|
|
113
111
|
declare const envSchema: TObject<{
|
|
@@ -118,9 +116,13 @@ declare module "alepha" {
|
|
|
118
116
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
119
117
|
}
|
|
120
118
|
declare class CliProvider {
|
|
121
|
-
protected readonly env:
|
|
119
|
+
protected readonly env: {
|
|
120
|
+
CLI_NAME: string;
|
|
121
|
+
CLI_DESCRIPTION: string;
|
|
122
|
+
};
|
|
122
123
|
protected readonly alepha: Alepha;
|
|
123
|
-
protected readonly log: Logger;
|
|
124
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
125
|
+
protected readonly runner: Runner;
|
|
124
126
|
options: {
|
|
125
127
|
name: string;
|
|
126
128
|
description: string;
|
|
@@ -157,7 +159,7 @@ declare class CliProvider {
|
|
|
157
159
|
* @see {@link $command}
|
|
158
160
|
* @module alepha.command
|
|
159
161
|
*/
|
|
160
|
-
declare const AlephaCommand:
|
|
162
|
+
declare const AlephaCommand: _alepha_core1.Service<_alepha_core1.Module>;
|
|
161
163
|
declare module "@sinclair/typebox" {
|
|
162
164
|
interface StringOptions {
|
|
163
165
|
/**
|