alepha 0.7.3 → 0.7.4

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/lock.d.ts CHANGED
@@ -3,7 +3,46 @@ import { AsyncFn, KIND, OPTIONS, Static, Alepha } from '@alepha/core';
3
3
  import { DurationLike, DateTimeProvider, DateTime, Timeout } from '@alepha/datetime';
4
4
  import * as _alepha_topic from '@alepha/topic';
5
5
  import { TopicProvider } from '@alepha/topic';
6
- import { RedisProvider, RedisClient } from '@alepha/redis';
6
+
7
+ declare const KEY = "LOCK";
8
+ interface LockDescriptorOptions<TFunc extends AsyncFn> {
9
+ /**
10
+ * Function executed when the lock is acquired.
11
+ */
12
+ handler: TFunc;
13
+ /**
14
+ * If true, the handler will wait for the lock to be released.
15
+ *
16
+ * @default false
17
+ */
18
+ wait?: boolean;
19
+ key?: string | ((...args: Parameters<TFunc>) => string);
20
+ maxDuration?: DurationLike;
21
+ gracePeriod?: (...args: Parameters<TFunc>) => DurationLike | undefined;
22
+ }
23
+ interface LockDescriptor<TFunc extends AsyncFn> {
24
+ [KIND]: typeof KEY;
25
+ [OPTIONS]: LockDescriptorOptions<TFunc>;
26
+ /**
27
+ * Apply the lock.
28
+ *
29
+ * @param args
30
+ */
31
+ (...args: Parameters<TFunc>): Promise<void>;
32
+ }
33
+ /**
34
+ * Lock descriptor
35
+ *
36
+ * Make sure that only one instance of the handler is running at a time.
37
+ *
38
+ * When connected to a remote store, the lock is shared across all processes.
39
+ *
40
+ * @param options
41
+ */
42
+ declare const $lock: {
43
+ <TFunc extends AsyncFn>(options: LockDescriptorOptions<TFunc>): LockDescriptor<TFunc>;
44
+ [KIND]: string;
45
+ };
7
46
 
8
47
  /** Symbol key applied to readonly types */
9
48
  declare const ReadonlyKind: unique symbol;
@@ -14,11 +53,6 @@ declare const Hint: unique symbol;
14
53
  /** Symbol key applied to types */
15
54
  declare const Kind: unique symbol;
16
55
 
17
- interface TUnsafe<T> extends TSchema {
18
- [Kind]: string;
19
- static: T;
20
- }
21
-
22
56
  type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
23
57
  type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
24
58
  interface StringOptions extends SchemaOptions {
@@ -70,51 +104,10 @@ interface TSchema extends TKind, SchemaOptions {
70
104
  static: unknown;
71
105
  }
72
106
 
73
- declare const KEY = "LOCK";
74
- interface LockDescriptorOptions<TFunc extends AsyncFn> {
75
- /**
76
- * Function executed when the lock is acquired.
77
- */
78
- handler: TFunc;
79
- /**
80
- * If true, the handler will wait for the lock to be released.
81
- *
82
- * @default false
83
- */
84
- wait?: boolean;
85
- key?: string | ((...args: Parameters<TFunc>) => string);
86
- maxDuration?: DurationLike;
87
- gracePeriod?: (...args: Parameters<TFunc>) => DurationLike | undefined;
88
- }
89
- interface LockDescriptor<TFunc extends AsyncFn> {
90
- [KIND]: typeof KEY;
91
- [OPTIONS]: LockDescriptorOptions<TFunc>;
92
- /**
93
- * Apply the lock.
94
- *
95
- * @param args
96
- */
97
- (...args: Parameters<TFunc>): Promise<void>;
98
- }
99
- /**
100
- * Lock descriptor
101
- *
102
- * Make sure that only one instance of the handler is running at a time.
103
- *
104
- * When connected to a remote store, the lock is shared across all processes.
105
- *
106
- * @param options
107
- */
108
- declare const $lock: {
109
- <TFunc extends AsyncFn>(options: LockDescriptorOptions<TFunc>): LockDescriptor<TFunc>;
110
- [KIND]: string;
111
- };
112
-
113
107
  /**
114
108
  * Store Provider Interface
115
109
  */
116
- declare class LockProvider {
117
- constructor();
110
+ declare abstract class LockProvider {
118
111
  /**
119
112
  * Set the string value of a key.
120
113
  *
@@ -123,23 +116,23 @@ declare class LockProvider {
123
116
  * @param nx If set to true, the key will only be set if it does not already exist.
124
117
  * @param px Set the specified expire time, in milliseconds.
125
118
  */
126
- set(_key: string, _value: string, _nx?: boolean, _px?: number): Promise<string>;
119
+ abstract set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
127
120
  /**
128
121
  * Remove the specified keys.
129
122
  *
130
123
  * @param keys The keys to delete.
131
124
  */
132
- del(..._keys: string[]): Promise<void>;
125
+ abstract del(...keys: string[]): Promise<void>;
133
126
  }
134
127
 
135
128
  declare class LockTopicProvider extends TopicProvider {
136
129
  }
137
130
 
138
- declare const envSchema$1: _alepha_core.TObject<{
131
+ declare const envSchema: _alepha_core.TObject<{
139
132
  LOCK_PREFIX_KEY: TString;
140
133
  }>;
141
134
  declare module "alepha" {
142
- interface Env extends Partial<Static<typeof envSchema$1>> {
135
+ interface Env extends Partial<Static<typeof envSchema>> {
143
136
  }
144
137
  }
145
138
  declare class LockDescriptorProvider {
@@ -203,68 +196,25 @@ declare class MemoryLockProvider implements LockProvider {
203
196
  * Timeouts used to expire keys.
204
197
  */
205
198
  protected storeTimeout: Record<string, Timeout>;
206
- /**
207
- * Set the string value of a key.
208
- *
209
- * @param key The key of the value to set.
210
- * @param value The value to set.
211
- * @param nx If set to true, the key will only be set if it does not already exist.
212
- * @param px Set the specified expire time, in milliseconds.
213
- */
214
199
  set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
215
- /**
216
- * Remove the specified keys.
217
- *
218
- * @param keys The keys to delete.
219
- */
220
200
  del(...keys: string[]): Promise<void>;
221
- /**
222
- * Set a timeout for a key.
223
- *
224
- * @param key The key to set the timeout for.
225
- * @param ms The number of milliseconds to wait before deleting the key.
226
- */
227
201
  private ttl;
228
202
  }
229
203
 
230
204
  /**
231
- * A store provider that uses Redis.
205
+ * Alepha Lock Module
206
+ *
207
+ * Lock a resource for a certain period of time.
208
+ *
209
+ * This module provides a memory implementation of the lock provider.
210
+ * You probably want to use an implementation like RedisLockProvider for distributed systems.
211
+ *
212
+ * @see {@link $lock}
213
+ * @module alepha.lock
232
214
  */
233
- declare class RedisLockProvider implements LockProvider {
234
- protected readonly log: _alepha_core.Logger;
235
- protected readonly redisProvider: RedisProvider;
236
- /**
237
- * Get the Redis publisher.
238
- */
239
- protected get publisher(): RedisClient;
240
- /**
241
- * Set the string value of a key.
242
- *
243
- * @param key The key of the value to set.
244
- * @param value The value to set.
245
- * @param nx If set to true, the key will only be set if it does not already exist.
246
- * @param px Set the specified expire time, in milliseconds.
247
- */
248
- set(key: string, value: string, nx?: boolean, px?: number): Promise<string>;
249
- /**
250
- * Remove the specified keys.
251
- */
252
- del(...keys: string[]): Promise<void>;
253
- }
254
-
255
- declare const envSchema: _alepha_core.TObject<{
256
- LOCK_PROVIDER: TUnsafe<"memory" | "redis">;
257
- }>;
258
- declare module "alepha/core" {
259
- interface Env extends Partial<Static<typeof envSchema>> {
260
- }
261
- }
262
- declare class LockModule {
263
- protected readonly alepha: Alepha;
264
- protected readonly env: {
265
- LOCK_PROVIDER: "memory" | "redis";
266
- };
267
- constructor();
215
+ declare class AlephaLock {
216
+ readonly name = "alepha.lock";
217
+ readonly $services: (alepha: Alepha) => Alepha;
268
218
  }
269
219
 
270
- export { $lock, type LockDescriptor, type LockDescriptorOptions, LockDescriptorProvider, type LockDescriptorValue, LockModule, type LockObject, LockProvider, LockTopicProvider, MemoryLockProvider, RedisLockProvider };
220
+ export { $lock, AlephaLock, type LockDescriptor, type LockDescriptorOptions, LockDescriptorProvider, type LockDescriptorValue, type LockObject, LockProvider, LockTopicProvider, MemoryLockProvider };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "alepha",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
- "description": "TypeScript framework for building full-stack apps with strict conventions, custom schemas, and React-based SPA or SSR without filesystem-based routing.",
6
+ "description": "TypeScript framework for building full-stack apps with strict conventions, and React-based SPA or SSR without filesystem-based routing.",
7
7
  "homepage": "https://github.com/feunard/alepha",
8
8
  "repository": {
9
9
  "type": "git",
@@ -12,42 +12,30 @@
12
12
  "main": "./core.js",
13
13
  "types": "./core.d.ts",
14
14
  "dependencies": {
15
- "@alepha/cache": "0.7.3",
16
- "@alepha/core": "0.7.3",
17
- "@alepha/datetime": "0.7.3",
18
- "@alepha/lock": "0.7.3",
19
- "@alepha/postgres": "0.7.3",
20
- "@alepha/queue": "0.7.3",
21
- "@alepha/react": "0.7.3",
22
- "@alepha/react-auth": "0.7.3",
23
- "@alepha/redis": "0.7.3",
24
- "@alepha/retry": "0.7.3",
25
- "@alepha/scheduler": "0.7.3",
26
- "@alepha/security": "0.7.3",
27
- "@alepha/server": "0.7.3",
28
- "@alepha/server-cache": "0.7.3",
29
- "@alepha/server-cookies": "0.7.3",
30
- "@alepha/server-static": "0.7.3",
31
- "@alepha/server-swagger": "0.7.3",
32
- "@alepha/testing": "0.7.3",
33
- "@alepha/topic": "0.7.3",
34
- "@alepha/vite": "0.7.3"
35
- },
36
- "peerDependencies": {
37
- "@types/react": "^19",
38
- "react": "^19",
39
- "vite": "^6"
40
- },
41
- "peerDependenciesMeta": {
42
- "@types/react": {
43
- "optional": true
44
- },
45
- "react": {
46
- "optional": true
47
- },
48
- "vite": {
49
- "optional": true
50
- }
15
+ "@alepha/cache": "0.7.4",
16
+ "@alepha/cache-redis": "0.7.4",
17
+ "@alepha/core": "0.7.4",
18
+ "@alepha/datetime": "0.7.4",
19
+ "@alepha/lock": "0.7.4",
20
+ "@alepha/postgres": "0.7.4",
21
+ "@alepha/queue": "0.7.4",
22
+ "@alepha/react": "0.7.4",
23
+ "@alepha/react-auth": "0.7.4",
24
+ "@alepha/redis": "0.7.4",
25
+ "@alepha/retry": "0.7.4",
26
+ "@alepha/scheduler": "0.7.4",
27
+ "@alepha/security": "0.7.4",
28
+ "@alepha/server": "0.7.4",
29
+ "@alepha/server-cache": "0.7.4",
30
+ "@alepha/server-cookies": "0.7.4",
31
+ "@alepha/server-static": "0.7.4",
32
+ "@alepha/server-swagger": "0.7.4",
33
+ "@alepha/testing": "0.7.4",
34
+ "@alepha/topic": "0.7.4",
35
+ "@alepha/topic-redis": "0.7.4",
36
+ "@alepha/vite": "0.7.4",
37
+ "@types/react": "^19.1.8",
38
+ "react": "^19.1.0"
51
39
  },
52
40
  "devDependencies": {
53
41
  "@types/react": "^19.1.8",
@@ -76,6 +64,11 @@
76
64
  "require": "./cache.cjs",
77
65
  "types": "./cache.d.ts"
78
66
  },
67
+ "./cache/redis": {
68
+ "import": "./cache/redis.js",
69
+ "require": "./cache/redis.cjs",
70
+ "types": "./cache/redis.d.ts"
71
+ },
79
72
  "./core": {
80
73
  "import": "./core.js",
81
74
  "require": "./core.cjs",
@@ -91,6 +84,11 @@
91
84
  "require": "./lock.cjs",
92
85
  "types": "./lock.d.ts"
93
86
  },
87
+ "./lock/redis": {
88
+ "import": "./lock/redis.js",
89
+ "require": "./lock/redis.cjs",
90
+ "types": "./lock/redis.d.ts"
91
+ },
94
92
  "./postgres": {
95
93
  "import": "./postgres.js",
96
94
  "require": "./postgres.cjs",
package/postgres.d.ts CHANGED
@@ -1,27 +1,27 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { TObject as TObject$1, Static as Static$1, Alepha, KIND, OPTIONS } from '@alepha/core';
3
- import * as _sinclair_typebox from '@sinclair/typebox';
4
- import { TObject, TSchema, ObjectOptions, Kind, TProperties, Evaluate, TReadonly, TOptional, Static, TAdditionalProperties, OptionalKind, TArray, TIntersect, TRecord, TBoolean, TInteger, TOptionalWithFlag, IntegerOptions, NumberOptions, StringOptions } from '@sinclair/typebox';
2
+ import { TObject as TObject$1, Static as Static$1, Alepha, KIND, OPTIONS, Module } from '@alepha/core';
5
3
  import * as drizzle_orm from 'drizzle-orm';
6
4
  import { TableConfig, BuildColumns, BuildExtraConfigColumns as BuildExtraConfigColumns$1, SQLWrapper, SQL } from 'drizzle-orm';
7
5
  export { sql } from 'drizzle-orm';
8
6
  import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
9
7
  import { PgSequenceOptions, AnyPgTable, AnyPgColumn, UpdateDeleteAction, PgTableWithColumns, PgColumnBuilderBase, PgTableExtraConfigValue, PgDatabase, TableConfig as TableConfig$1, PgColumn, PgTransaction, PgTransactionConfig, LockStrength, LockConfig, PgInsertValue, PgSelectJoinFn } from 'drizzle-orm/pg-core';
10
8
  export * from 'drizzle-orm/pg-core';
9
+ import * as _sinclair_typebox from '@sinclair/typebox';
10
+ import { TObject, TSchema, ObjectOptions, Kind, TProperties, Evaluate, TReadonly, TOptional, Static, TAdditionalProperties, OptionalKind, TArray, TIntersect, TRecord, TBoolean, TInteger, TOptionalWithFlag, IntegerOptions, NumberOptions, StringOptions } from '@sinclair/typebox';
11
11
  import { BuildExtraConfigColumns } from 'drizzle-orm/column-builder';
12
- import * as _alepha_retry from '@alepha/retry';
13
- import { PgTransactionConfig as PgTransactionConfig$1 } from 'drizzle-orm/pg-core/session';
12
+ import * as _alepha_lock from '@alepha/lock';
13
+ import { MigrationConfig } from 'drizzle-orm/migrator';
14
+ import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
15
+ import postgres from 'postgres';
14
16
  import { LibSQLDatabase } from 'drizzle-orm/libsql';
15
17
  import { MySql2Database } from 'drizzle-orm/mysql2';
16
18
  import { SingleStoreDriverDatabase } from 'drizzle-orm/singlestore';
17
19
  import { ConnectionOptions } from 'tls';
18
20
  import * as zod from 'zod';
19
21
  import { TypeOf } from 'zod';
20
- import * as _alepha_lock from '@alepha/lock';
21
- import { MigrationConfig } from 'drizzle-orm/migrator';
22
- import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
23
- import postgres from 'postgres';
24
22
  import { UpdateDeleteAction as UpdateDeleteAction$1 } from 'drizzle-orm/pg-core/foreign-keys';
23
+ import * as _alepha_retry from '@alepha/retry';
24
+ import { PgTransactionConfig as PgTransactionConfig$1 } from 'drizzle-orm/pg-core/session';
25
25
 
26
26
  /**
27
27
  *
@@ -4349,10 +4349,10 @@ declare class DrizzleKitProvider {
4349
4349
  }
4350
4350
 
4351
4351
  declare module "alepha" {
4352
- interface Env extends Partial<Static$1<typeof envSchema$1>> {
4352
+ interface Env extends Partial<Static$1<typeof envSchema>> {
4353
4353
  }
4354
4354
  }
4355
- declare const envSchema$1: _alepha_core.TObject<{
4355
+ declare const envSchema: _alepha_core.TObject<{
4356
4356
  PG_HOST: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
4357
4357
  PG_USERNAME: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
4358
4358
  PG_DATABASE: _sinclair_typebox.TOptional<_sinclair_typebox.TString>;
@@ -4585,20 +4585,9 @@ declare const schema: <TDocument extends TSchema>(name: string, document: TDocum
4585
4585
  params: [];
4586
4586
  })["static"]>;
4587
4587
 
4588
- declare const envSchema: _alepha_core.TObject<{
4589
- POSTGRES_PROVIDER: _sinclair_typebox.TOptional<_sinclair_typebox.TUnsafe<"pg">>;
4590
- }>;
4591
- declare module "@alepha/core" {
4592
- interface Env extends Partial<Static$1<typeof envSchema>> {
4593
- }
4594
- }
4595
- declare class PostgresModule {
4596
- protected readonly alepha: Alepha;
4597
- protected readonly env: {
4598
- POSTGRES_PROVIDER?: "pg" | undefined;
4599
- };
4600
- constructor();
4601
- protected getDefaultProviderName(): "pg";
4588
+ declare class AlephaPostgres implements Module {
4589
+ readonly name = "alepha.postgres";
4590
+ readonly $services: (alepha: Alepha) => Alepha;
4602
4591
  }
4603
4592
 
4604
- export { $entity, $repository, $sequence, $transaction, type BaseEntity, type BaseEntityKeys, DrizzleKitProvider, type Entity, type EntityDescriptorOptions, EntityNotFoundError, type ExtractManyRelations, type FilterOperators, type FromSchema, NodePostgresProvider, type NodePostgresProviderState, type NullToUndefined, type NullifyIfOptional, PG_CREATED_AT, PG_DEFAULT, PG_IDENTITY, PG_MANY, PG_ONE, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, type Page, type PageQuery, type PgAttrField, type PgDefault, type PgIdentityOptions, type PgMany, type PgManyOptions, type PgPrimaryKey, type PgQuery, type PgQueryWhere, type PgQueryWhereWithMany, type PgQueryWith, type PgQueryWithMap, type PgRef, type PgRefOptions, type PgSymbolKeys, type PgSymbols, type PgTableConfig, type PgTableWithColumnsAndSchema, PostgresModule, PostgresProvider, PostgresTypeProvider, type RemoveManyRelations, Repository, type RepositoryDescriptorOptions, RepositoryDescriptorProvider, type SQLLike, type SequenceDescriptor, type SequenceDescriptorOptions, type StatementOptions, type TEntity, type TInsertObject, type TPage, type TransactionContext, type TransactionDescriptorOptions, entityKeys, entitySchema, nullToUndefined, pageQuerySchema, pageSchema, pg, pgTableSchema, schema, schemaToColumns };
4593
+ export { $entity, $repository, $sequence, $transaction, AlephaPostgres, type BaseEntity, type BaseEntityKeys, DrizzleKitProvider, type Entity, type EntityDescriptorOptions, EntityNotFoundError, type ExtractManyRelations, type FilterOperators, type FromSchema, NodePostgresProvider, type NodePostgresProviderState, type NullToUndefined, type NullifyIfOptional, PG_CREATED_AT, PG_DEFAULT, PG_IDENTITY, PG_MANY, PG_ONE, PG_PRIMARY_KEY, PG_REF, PG_SCHEMA, PG_SERIAL, PG_UPDATED_AT, PG_VERSION, type Page, type PageQuery, type PgAttrField, type PgDefault, type PgIdentityOptions, type PgMany, type PgManyOptions, type PgPrimaryKey, type PgQuery, type PgQueryWhere, type PgQueryWhereWithMany, type PgQueryWith, type PgQueryWithMap, type PgRef, type PgRefOptions, type PgSymbolKeys, type PgSymbols, type PgTableConfig, type PgTableWithColumnsAndSchema, PostgresProvider, PostgresTypeProvider, type RemoveManyRelations, Repository, type RepositoryDescriptorOptions, RepositoryDescriptorProvider, type SQLLike, type SequenceDescriptor, type SequenceDescriptorOptions, type StatementOptions, type TEntity, type TInsertObject, type TPage, type TransactionContext, type TransactionDescriptorOptions, entityKeys, entitySchema, nullToUndefined, pageQuerySchema, pageSchema, pg, pgTableSchema, schema, schemaToColumns };