@lakutata/cache 3.0.0-beta.0

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 (116) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +175 -0
  3. package/dist/cjs/cache/Cacher.d.ts +446 -0
  4. package/dist/cjs/cache/Cacher.js +523 -0
  5. package/dist/cjs/cache/exceptions/CacheDriverNotFoundException.d.ts +10 -0
  6. package/dist/cjs/cache/exceptions/CacheDriverNotFoundException.js +17 -0
  7. package/dist/cjs/cache/interfaces/CacherOptions.d.ts +42 -0
  8. package/dist/cjs/cache/interfaces/CacherOptions.js +2 -0
  9. package/dist/cjs/cache/lib/LikePrefix.d.ts +5 -0
  10. package/dist/cjs/cache/lib/LikePrefix.js +10 -0
  11. package/dist/cjs/cache/lib/LoadDriver.d.ts +6 -0
  12. package/dist/cjs/cache/lib/LoadDriver.js +66 -0
  13. package/dist/cjs/cache/lib/Serializer.d.ts +18 -0
  14. package/dist/cjs/cache/lib/Serializer.js +46 -0
  15. package/dist/cjs/cache/lib/WithTimeout.d.ts +7 -0
  16. package/dist/cjs/cache/lib/WithTimeout.js +23 -0
  17. package/dist/cjs/cache/options/FileCacheOptions.d.ts +54 -0
  18. package/dist/cjs/cache/options/FileCacheOptions.js +62 -0
  19. package/dist/cjs/cache/options/MemcacheCacheOptions.d.ts +57 -0
  20. package/dist/cjs/cache/options/MemcacheCacheOptions.js +66 -0
  21. package/dist/cjs/cache/options/MemoryCacheOptions.d.ts +39 -0
  22. package/dist/cjs/cache/options/MemoryCacheOptions.js +52 -0
  23. package/dist/cjs/cache/options/MongoCacheOptions.d.ts +72 -0
  24. package/dist/cjs/cache/options/MongoCacheOptions.js +81 -0
  25. package/dist/cjs/cache/options/MysqlCacheOptions.d.ts +73 -0
  26. package/dist/cjs/cache/options/MysqlCacheOptions.js +82 -0
  27. package/dist/cjs/cache/options/PostgresCacheOptions.d.ts +87 -0
  28. package/dist/cjs/cache/options/PostgresCacheOptions.js +92 -0
  29. package/dist/cjs/cache/options/RedisCacheOptions.d.ts +120 -0
  30. package/dist/cjs/cache/options/RedisCacheOptions.js +113 -0
  31. package/dist/cjs/cache/options/SqliteCacheOptions.d.ts +53 -0
  32. package/dist/cjs/cache/options/SqliteCacheOptions.js +61 -0
  33. package/dist/cjs/cache/stores/CacheStore.d.ts +44 -0
  34. package/dist/cjs/cache/stores/CacheStore.js +42 -0
  35. package/dist/cjs/cache/stores/CreateCacheStore.d.ts +7 -0
  36. package/dist/cjs/cache/stores/CreateCacheStore.js +37 -0
  37. package/dist/cjs/cache/stores/FileStore.d.ts +51 -0
  38. package/dist/cjs/cache/stores/FileStore.js +143 -0
  39. package/dist/cjs/cache/stores/MemcacheStore.d.ts +42 -0
  40. package/dist/cjs/cache/stores/MemcacheStore.js +69 -0
  41. package/dist/cjs/cache/stores/MemoryStore.d.ts +34 -0
  42. package/dist/cjs/cache/stores/MemoryStore.js +75 -0
  43. package/dist/cjs/cache/stores/MongoStore.d.ts +55 -0
  44. package/dist/cjs/cache/stores/MongoStore.js +72 -0
  45. package/dist/cjs/cache/stores/MysqlStore.d.ts +27 -0
  46. package/dist/cjs/cache/stores/MysqlStore.js +71 -0
  47. package/dist/cjs/cache/stores/PostgresStore.d.ts +30 -0
  48. package/dist/cjs/cache/stores/PostgresStore.js +85 -0
  49. package/dist/cjs/cache/stores/RedisStore.d.ts +58 -0
  50. package/dist/cjs/cache/stores/RedisStore.js +131 -0
  51. package/dist/cjs/cache/stores/SerializedCacheStore.d.ts +48 -0
  52. package/dist/cjs/cache/stores/SerializedCacheStore.js +80 -0
  53. package/dist/cjs/cache/stores/SqliteStore.d.ts +44 -0
  54. package/dist/cjs/cache/stores/SqliteStore.js +91 -0
  55. package/dist/cjs/cache/types/CacheStoreOptions.d.ts +15 -0
  56. package/dist/cjs/cache/types/CacheStoreOptions.js +2 -0
  57. package/dist/cjs/exports/Cache.d.ts +12 -0
  58. package/dist/cjs/exports/Cache.js +31 -0
  59. package/dist/cjs/package.json +1 -0
  60. package/dist/esm/cache/Cacher.js +518 -0
  61. package/dist/esm/cache/exceptions/CacheDriverNotFoundException.js +13 -0
  62. package/dist/esm/cache/interfaces/CacherOptions.js +1 -0
  63. package/dist/esm/cache/lib/LikePrefix.js +7 -0
  64. package/dist/esm/cache/lib/LoadDriver.js +30 -0
  65. package/dist/esm/cache/lib/Serializer.js +42 -0
  66. package/dist/esm/cache/lib/WithTimeout.js +20 -0
  67. package/dist/esm/cache/options/FileCacheOptions.js +58 -0
  68. package/dist/esm/cache/options/MemcacheCacheOptions.js +62 -0
  69. package/dist/esm/cache/options/MemoryCacheOptions.js +48 -0
  70. package/dist/esm/cache/options/MongoCacheOptions.js +77 -0
  71. package/dist/esm/cache/options/MysqlCacheOptions.js +78 -0
  72. package/dist/esm/cache/options/PostgresCacheOptions.js +88 -0
  73. package/dist/esm/cache/options/RedisCacheOptions.js +109 -0
  74. package/dist/esm/cache/options/SqliteCacheOptions.js +57 -0
  75. package/dist/esm/cache/stores/CacheStore.js +36 -0
  76. package/dist/esm/cache/stores/CreateCacheStore.js +34 -0
  77. package/dist/esm/cache/stores/FileStore.js +136 -0
  78. package/dist/esm/cache/stores/MemcacheStore.js +65 -0
  79. package/dist/esm/cache/stores/MemoryStore.js +71 -0
  80. package/dist/esm/cache/stores/MongoStore.js +68 -0
  81. package/dist/esm/cache/stores/MysqlStore.js +67 -0
  82. package/dist/esm/cache/stores/PostgresStore.js +81 -0
  83. package/dist/esm/cache/stores/RedisStore.js +127 -0
  84. package/dist/esm/cache/stores/SerializedCacheStore.js +76 -0
  85. package/dist/esm/cache/stores/SqliteStore.js +87 -0
  86. package/dist/esm/cache/types/CacheStoreOptions.js +1 -0
  87. package/dist/esm/exports/Cache.js +12 -0
  88. package/dist/types/cache/Cacher.d.ts +446 -0
  89. package/dist/types/cache/exceptions/CacheDriverNotFoundException.d.ts +10 -0
  90. package/dist/types/cache/interfaces/CacherOptions.d.ts +42 -0
  91. package/dist/types/cache/lib/LikePrefix.d.ts +5 -0
  92. package/dist/types/cache/lib/LoadDriver.d.ts +6 -0
  93. package/dist/types/cache/lib/Serializer.d.ts +18 -0
  94. package/dist/types/cache/lib/WithTimeout.d.ts +7 -0
  95. package/dist/types/cache/options/FileCacheOptions.d.ts +54 -0
  96. package/dist/types/cache/options/MemcacheCacheOptions.d.ts +57 -0
  97. package/dist/types/cache/options/MemoryCacheOptions.d.ts +39 -0
  98. package/dist/types/cache/options/MongoCacheOptions.d.ts +72 -0
  99. package/dist/types/cache/options/MysqlCacheOptions.d.ts +73 -0
  100. package/dist/types/cache/options/PostgresCacheOptions.d.ts +87 -0
  101. package/dist/types/cache/options/RedisCacheOptions.d.ts +120 -0
  102. package/dist/types/cache/options/SqliteCacheOptions.d.ts +53 -0
  103. package/dist/types/cache/stores/CacheStore.d.ts +44 -0
  104. package/dist/types/cache/stores/CreateCacheStore.d.ts +7 -0
  105. package/dist/types/cache/stores/FileStore.d.ts +51 -0
  106. package/dist/types/cache/stores/MemcacheStore.d.ts +42 -0
  107. package/dist/types/cache/stores/MemoryStore.d.ts +34 -0
  108. package/dist/types/cache/stores/MongoStore.d.ts +55 -0
  109. package/dist/types/cache/stores/MysqlStore.d.ts +27 -0
  110. package/dist/types/cache/stores/PostgresStore.d.ts +30 -0
  111. package/dist/types/cache/stores/RedisStore.d.ts +58 -0
  112. package/dist/types/cache/stores/SerializedCacheStore.d.ts +48 -0
  113. package/dist/types/cache/stores/SqliteStore.d.ts +44 -0
  114. package/dist/types/cache/types/CacheStoreOptions.d.ts +15 -0
  115. package/dist/types/exports/Cache.d.ts +12 -0
  116. package/package.json +72 -0
@@ -0,0 +1,73 @@
1
+ import { DTO } from '@lakutata/core';
2
+ /**
3
+ * The options of the MySQL store (MySQL or MariaDB): one row per entry in a table. It needs the optional peer
4
+ * dependency `mysql2` (`npm install mysql2`): without it, the cache's creation fails with
5
+ * `CacheDriverNotFoundException`.
6
+ *
7
+ * When the cache starts, it creates the table when missing: `(id VARCHAR(255) PRIMARY KEY, value MEDIUMTEXT)`, the
8
+ * keys case sensitive (`utf8mb4_bin`); a failure (an unreachable server, a denied creation) fails the cache's
9
+ * creation. A key longer than 255 characters, its namespace prefix included, fails its write (in the strict SQL mode,
10
+ * the default), and a value is limited to 16 MB of JSON. An expired row is a miss; it stays in the table until it is read, overwritten or cleared. The
11
+ * values are kept as JSON.
12
+ * @example
13
+ * ```typescript
14
+ * import {Application} from 'lakutata'
15
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
16
+ *
17
+ * Application.run(() => ({
18
+ * id: 'mysql-cache.app',
19
+ * name: 'MysqlCache',
20
+ * components: {
21
+ * cache: buildCacherOptions({
22
+ * stores: {
23
+ * type: 'mysql',
24
+ * host: '127.0.0.1',
25
+ * database: 'app',
26
+ * table: 'cache',
27
+ * username: 'app',
28
+ * password: process.env.MYSQL_PASSWORD ?? ''
29
+ * }
30
+ * })
31
+ * }
32
+ * }))
33
+ * ```
34
+ */
35
+ export declare class MysqlCacheOptions extends DTO {
36
+ /**
37
+ * The store type: `'mysql'`.
38
+ */
39
+ type: 'mysql';
40
+ /**
41
+ * The host name or IP address of the MySQL server.
42
+ */
43
+ host: string;
44
+ /**
45
+ * The database holding the table.
46
+ */
47
+ database: string;
48
+ /**
49
+ * The table of the entries, created when missing (the name is quoted: kept as written).
50
+ */
51
+ table: string;
52
+ /**
53
+ * The port of the MySQL server.
54
+ * @default 3306
55
+ */
56
+ port?: number;
57
+ /**
58
+ * The user name; without it, the driver's default.
59
+ * @default the driver's default
60
+ */
61
+ username?: string;
62
+ /**
63
+ * The user's password; empty or omitted for a user without password (trust authentication).
64
+ * @default none
65
+ */
66
+ password?: string;
67
+ /**
68
+ * The namespace of the entries: the keys are stored as `{namespace}:{key}`, and `clear()` deletes only the
69
+ * namespace's rows. Without it, `clear()` deletes all the table's rows.
70
+ * @default none
71
+ */
72
+ namespace?: string;
73
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MysqlCacheOptions = void 0;
13
+ const core_1 = require("@lakutata/core");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ /**
16
+ * The options of the MySQL store (MySQL or MariaDB): one row per entry in a table. It needs the optional peer
17
+ * dependency `mysql2` (`npm install mysql2`): without it, the cache's creation fails with
18
+ * `CacheDriverNotFoundException`.
19
+ *
20
+ * When the cache starts, it creates the table when missing: `(id VARCHAR(255) PRIMARY KEY, value MEDIUMTEXT)`, the
21
+ * keys case sensitive (`utf8mb4_bin`); a failure (an unreachable server, a denied creation) fails the cache's
22
+ * creation. A key longer than 255 characters, its namespace prefix included, fails its write (in the strict SQL mode,
23
+ * the default), and a value is limited to 16 MB of JSON. An expired row is a miss; it stays in the table until it is read, overwritten or cleared. The
24
+ * values are kept as JSON.
25
+ * @example
26
+ * ```typescript
27
+ * import {Application} from 'lakutata'
28
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
29
+ *
30
+ * Application.run(() => ({
31
+ * id: 'mysql-cache.app',
32
+ * name: 'MysqlCache',
33
+ * components: {
34
+ * cache: buildCacherOptions({
35
+ * stores: {
36
+ * type: 'mysql',
37
+ * host: '127.0.0.1',
38
+ * database: 'app',
39
+ * table: 'cache',
40
+ * username: 'app',
41
+ * password: process.env.MYSQL_PASSWORD ?? ''
42
+ * }
43
+ * })
44
+ * }
45
+ * }))
46
+ * ```
47
+ */
48
+ class MysqlCacheOptions extends core_1.DTO {
49
+ }
50
+ exports.MysqlCacheOptions = MysqlCacheOptions;
51
+ __decorate([
52
+ (0, dto_1.Expect)(core_1.DTO.String().allow('mysql').only().required()),
53
+ __metadata("design:type", String)
54
+ ], MysqlCacheOptions.prototype, "type", void 0);
55
+ __decorate([
56
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
57
+ __metadata("design:type", String)
58
+ ], MysqlCacheOptions.prototype, "host", void 0);
59
+ __decorate([
60
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
61
+ __metadata("design:type", String)
62
+ ], MysqlCacheOptions.prototype, "database", void 0);
63
+ __decorate([
64
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
65
+ __metadata("design:type", String)
66
+ ], MysqlCacheOptions.prototype, "table", void 0);
67
+ __decorate([
68
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().port().optional().default(3306)),
69
+ __metadata("design:type", Number)
70
+ ], MysqlCacheOptions.prototype, "port", void 0);
71
+ __decorate([
72
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
73
+ __metadata("design:type", String)
74
+ ], MysqlCacheOptions.prototype, "username", void 0);
75
+ __decorate([
76
+ (0, dto_1.Expect)(core_1.DTO.String().allow('').optional()),
77
+ __metadata("design:type", String)
78
+ ], MysqlCacheOptions.prototype, "password", void 0);
79
+ __decorate([
80
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
81
+ __metadata("design:type", String)
82
+ ], MysqlCacheOptions.prototype, "namespace", void 0);
@@ -0,0 +1,87 @@
1
+ import { DTO } from '@lakutata/core';
2
+ /**
3
+ * The options of the PostgreSQL store: one row per entry in a table. It needs the optional peer dependency `pg`
4
+ * (`npm install pg`): without it, the cache's creation fails with `CacheDriverNotFoundException`.
5
+ *
6
+ * When the cache starts, it creates the schema (other than `public`) and the table when missing:
7
+ * `(key VARCHAR(255) PRIMARY KEY, value TEXT)`; a failure (an unreachable server, a denied creation) fails the cache's
8
+ * creation. A key longer than 255 characters, its namespace prefix included, fails its write. An expired row is a
9
+ * miss; it stays in the table until it is read, overwritten or cleared. The errors of the idle connections are emitted
10
+ * as `'error'` events of the cache. The values are kept as JSON.
11
+ * @example
12
+ * ```typescript
13
+ * import {Application} from 'lakutata'
14
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
15
+ *
16
+ * Application.run(() => ({
17
+ * id: 'postgres-cache.app',
18
+ * name: 'PostgresCache',
19
+ * components: {
20
+ * cache: buildCacherOptions({
21
+ * stores: {
22
+ * type: 'postgres',
23
+ * host: '127.0.0.1',
24
+ * database: 'app',
25
+ * schema: 'cache',
26
+ * table: 'entries',
27
+ * username: 'app',
28
+ * password: process.env.PGPASSWORD ?? '',
29
+ * maxPoolSize: 5
30
+ * },
31
+ * ttl: 600000
32
+ * })
33
+ * }
34
+ * }))
35
+ * ```
36
+ */
37
+ export declare class PostgresCacheOptions extends DTO {
38
+ /**
39
+ * The store type: `'postgres'`.
40
+ */
41
+ type: 'postgres';
42
+ /**
43
+ * The host name or IP address of the PostgreSQL server.
44
+ */
45
+ host: string;
46
+ /**
47
+ * The database holding the table.
48
+ */
49
+ database: string;
50
+ /**
51
+ * The table of the entries, created when missing. A plain name (letters, digits, `_`, `$`) is folded to lower
52
+ * case by PostgreSQL; any other name is quoted and kept as written.
53
+ */
54
+ table: string;
55
+ /**
56
+ * The port of the PostgreSQL server.
57
+ * @default 5432
58
+ */
59
+ port?: number;
60
+ /**
61
+ * The schema of the table, created when missing. Named as the table (a plain name folded to lower case).
62
+ * @default 'public'
63
+ */
64
+ schema?: string;
65
+ /**
66
+ * The user name; without it, the driver's default: the `PGUSER` environment variable, else the user of the
67
+ * process.
68
+ * @default the driver's default
69
+ */
70
+ username?: string;
71
+ /**
72
+ * The user's password; empty or omitted for a user without password (trust authentication).
73
+ * @default none
74
+ */
75
+ password?: string;
76
+ /**
77
+ * The maximum number of connections of the pool (a positive integer).
78
+ * @default 10 (the default of `pg`)
79
+ */
80
+ maxPoolSize?: number;
81
+ /**
82
+ * The namespace of the entries: the keys are stored as `{namespace}:{key}`, and `clear()` deletes only the
83
+ * namespace's rows. Without it, `clear()` deletes all the table's rows.
84
+ * @default none
85
+ */
86
+ namespace?: string;
87
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PostgresCacheOptions = void 0;
13
+ const core_1 = require("@lakutata/core");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ /**
16
+ * The options of the PostgreSQL store: one row per entry in a table. It needs the optional peer dependency `pg`
17
+ * (`npm install pg`): without it, the cache's creation fails with `CacheDriverNotFoundException`.
18
+ *
19
+ * When the cache starts, it creates the schema (other than `public`) and the table when missing:
20
+ * `(key VARCHAR(255) PRIMARY KEY, value TEXT)`; a failure (an unreachable server, a denied creation) fails the cache's
21
+ * creation. A key longer than 255 characters, its namespace prefix included, fails its write. An expired row is a
22
+ * miss; it stays in the table until it is read, overwritten or cleared. The errors of the idle connections are emitted
23
+ * as `'error'` events of the cache. The values are kept as JSON.
24
+ * @example
25
+ * ```typescript
26
+ * import {Application} from 'lakutata'
27
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
28
+ *
29
+ * Application.run(() => ({
30
+ * id: 'postgres-cache.app',
31
+ * name: 'PostgresCache',
32
+ * components: {
33
+ * cache: buildCacherOptions({
34
+ * stores: {
35
+ * type: 'postgres',
36
+ * host: '127.0.0.1',
37
+ * database: 'app',
38
+ * schema: 'cache',
39
+ * table: 'entries',
40
+ * username: 'app',
41
+ * password: process.env.PGPASSWORD ?? '',
42
+ * maxPoolSize: 5
43
+ * },
44
+ * ttl: 600000
45
+ * })
46
+ * }
47
+ * }))
48
+ * ```
49
+ */
50
+ class PostgresCacheOptions extends core_1.DTO {
51
+ }
52
+ exports.PostgresCacheOptions = PostgresCacheOptions;
53
+ __decorate([
54
+ (0, dto_1.Expect)(core_1.DTO.String().allow('postgres').only().required()),
55
+ __metadata("design:type", String)
56
+ ], PostgresCacheOptions.prototype, "type", void 0);
57
+ __decorate([
58
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
59
+ __metadata("design:type", String)
60
+ ], PostgresCacheOptions.prototype, "host", void 0);
61
+ __decorate([
62
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
63
+ __metadata("design:type", String)
64
+ ], PostgresCacheOptions.prototype, "database", void 0);
65
+ __decorate([
66
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
67
+ __metadata("design:type", String)
68
+ ], PostgresCacheOptions.prototype, "table", void 0);
69
+ __decorate([
70
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().port().optional().default(5432)),
71
+ __metadata("design:type", Number)
72
+ ], PostgresCacheOptions.prototype, "port", void 0);
73
+ __decorate([
74
+ (0, dto_1.Expect)(core_1.DTO.String().optional().default('public')),
75
+ __metadata("design:type", String)
76
+ ], PostgresCacheOptions.prototype, "schema", void 0);
77
+ __decorate([
78
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
79
+ __metadata("design:type", String)
80
+ ], PostgresCacheOptions.prototype, "username", void 0);
81
+ __decorate([
82
+ (0, dto_1.Expect)(core_1.DTO.String().allow('').optional()),
83
+ __metadata("design:type", String)
84
+ ], PostgresCacheOptions.prototype, "password", void 0);
85
+ __decorate([
86
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().integer().optional()),
87
+ __metadata("design:type", Number)
88
+ ], PostgresCacheOptions.prototype, "maxPoolSize", void 0);
89
+ __decorate([
90
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
91
+ __metadata("design:type", String)
92
+ ], PostgresCacheOptions.prototype, "namespace", void 0);
@@ -0,0 +1,120 @@
1
+ import { DTO } from '@lakutata/core';
2
+ /**
3
+ * The options of the Redis store (Redis, Valkey or a compatible server). It needs the optional peer dependency
4
+ * `redis` (`npm install redis`, version 4 or 5; `@redis/client` is used when `redis` is not installed): without it,
5
+ * the cache's creation fails with `CacheDriverNotFoundException`.
6
+ *
7
+ * The store connects when the cache starts. While it is disconnected, its commands fail at once instead of waiting:
8
+ * the reads are misses (emitted as `'error'` events), the writes reject. The connection errors are emitted as
9
+ * `'error'` events of the cache. The entries expire in Redis (`PSETEX`). The values are kept as JSON.
10
+ * @example
11
+ * ```typescript
12
+ * import {Application} from 'lakutata'
13
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
14
+ *
15
+ * Application.run(() => ({
16
+ * id: 'redis-cache.app',
17
+ * name: 'RedisCache',
18
+ * components: {
19
+ * cache: buildCacherOptions({
20
+ * stores: {
21
+ * type: 'redis',
22
+ * host: '127.0.0.1',
23
+ * password: process.env.REDIS_PASSWORD,
24
+ * namespace: 'app',
25
+ * //Start even when Redis is down, and keep reconnecting
26
+ * throwOnConnectError: false
27
+ * },
28
+ * ttl: 60000
29
+ * })
30
+ * }
31
+ * }))
32
+ * ```
33
+ */
34
+ export declare class RedisCacheOptions extends DTO {
35
+ /**
36
+ * The store type: `'redis'`.
37
+ */
38
+ type: 'redis';
39
+ /**
40
+ * The host name or IP address of the Redis server.
41
+ */
42
+ host: string;
43
+ /**
44
+ * The port of the Redis server.
45
+ * @default 6379
46
+ */
47
+ port?: number;
48
+ /**
49
+ * The index of the Redis database.
50
+ * @default 0
51
+ */
52
+ database?: number;
53
+ /**
54
+ * Whether to connect with TLS (with the system's certificate authorities).
55
+ * @default false
56
+ */
57
+ tls?: boolean;
58
+ /**
59
+ * The delay, in milliseconds, before the first TCP keep-alive probe of the idle connection.
60
+ * @default the driver's default
61
+ */
62
+ keepAlive?: number;
63
+ /**
64
+ * The user name (Redis 6 ACL).
65
+ * @default none (the default user)
66
+ */
67
+ username?: string;
68
+ /**
69
+ * The password.
70
+ * @default none
71
+ */
72
+ password?: string;
73
+ /**
74
+ * Whether to reconnect after the connection is lost, after `100 ms × attempt` (3 seconds at most). When false, the
75
+ * store stays disconnected.
76
+ * @default true
77
+ */
78
+ reconnect?: boolean;
79
+ /**
80
+ * The namespace of the entries: the keys are stored as `{namespace}{keyPrefixSeparator}{namespace}:{key}` (the
81
+ * format of lakutata 2.x), and `clear()` deletes only the namespace's keys. Without it, the keys are stored as
82
+ * they are, and `clear()` deletes all the database's string keys except the ones containing the
83
+ * `keyPrefixSeparator` (unless `noNamespaceAffectsAll`).
84
+ * @default none
85
+ */
86
+ namespace?: string;
87
+ /**
88
+ * The separator between the namespace and the rest of a key.
89
+ * @default '::'
90
+ */
91
+ keyPrefixSeparator?: string;
92
+ /**
93
+ * The number of keys `clear()` scans and deletes per batch; `0` for the default.
94
+ * @default 1000
95
+ */
96
+ clearBatchSize?: number;
97
+ /**
98
+ * Whether to delete with `UNLINK` (the memory reclaimed in the background) rather than `DEL`.
99
+ * @default true
100
+ */
101
+ useUnlink?: boolean;
102
+ /**
103
+ * Whether `clear()` without namespace flushes the whole Redis database (`FLUSHDB`, every key of every type and
104
+ * namespace included), instead of scanning for its string keys outside the namespaces.
105
+ * @default false
106
+ */
107
+ noNamespaceAffectsAll?: boolean;
108
+ /**
109
+ * How long, in milliseconds, the first connection may take before it fails.
110
+ * @default 5000
111
+ */
112
+ connectTimeout?: number;
113
+ /**
114
+ * Whether a failed first connection fails the cache's creation (and so the application's start). When false, the
115
+ * failure is emitted as an `'error'` event of the cache and the store keeps trying to connect in the background
116
+ * (as `reconnect` allows), its commands failing meanwhile.
117
+ * @default true
118
+ */
119
+ throwOnConnectError?: boolean;
120
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RedisCacheOptions = void 0;
13
+ const core_1 = require("@lakutata/core");
14
+ const dto_1 = require("@lakutata/core/decorator/dto");
15
+ /**
16
+ * The options of the Redis store (Redis, Valkey or a compatible server). It needs the optional peer dependency
17
+ * `redis` (`npm install redis`, version 4 or 5; `@redis/client` is used when `redis` is not installed): without it,
18
+ * the cache's creation fails with `CacheDriverNotFoundException`.
19
+ *
20
+ * The store connects when the cache starts. While it is disconnected, its commands fail at once instead of waiting:
21
+ * the reads are misses (emitted as `'error'` events), the writes reject. The connection errors are emitted as
22
+ * `'error'` events of the cache. The entries expire in Redis (`PSETEX`). The values are kept as JSON.
23
+ * @example
24
+ * ```typescript
25
+ * import {Application} from 'lakutata'
26
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
27
+ *
28
+ * Application.run(() => ({
29
+ * id: 'redis-cache.app',
30
+ * name: 'RedisCache',
31
+ * components: {
32
+ * cache: buildCacherOptions({
33
+ * stores: {
34
+ * type: 'redis',
35
+ * host: '127.0.0.1',
36
+ * password: process.env.REDIS_PASSWORD,
37
+ * namespace: 'app',
38
+ * //Start even when Redis is down, and keep reconnecting
39
+ * throwOnConnectError: false
40
+ * },
41
+ * ttl: 60000
42
+ * })
43
+ * }
44
+ * }))
45
+ * ```
46
+ */
47
+ class RedisCacheOptions extends core_1.DTO {
48
+ }
49
+ exports.RedisCacheOptions = RedisCacheOptions;
50
+ __decorate([
51
+ (0, dto_1.Expect)(core_1.DTO.String().allow('redis').only().required()),
52
+ __metadata("design:type", String)
53
+ ], RedisCacheOptions.prototype, "type", void 0);
54
+ __decorate([
55
+ (0, dto_1.Expect)(core_1.DTO.String().required()),
56
+ __metadata("design:type", String)
57
+ ], RedisCacheOptions.prototype, "host", void 0);
58
+ __decorate([
59
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().port().optional().default(6379)),
60
+ __metadata("design:type", Number)
61
+ ], RedisCacheOptions.prototype, "port", void 0);
62
+ __decorate([
63
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().allow(0).default(0).optional()),
64
+ __metadata("design:type", Number)
65
+ ], RedisCacheOptions.prototype, "database", void 0);
66
+ __decorate([
67
+ (0, dto_1.Expect)(core_1.DTO.Boolean().optional().default(false)),
68
+ __metadata("design:type", Boolean)
69
+ ], RedisCacheOptions.prototype, "tls", void 0);
70
+ __decorate([
71
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().allow(0).optional()),
72
+ __metadata("design:type", Number)
73
+ ], RedisCacheOptions.prototype, "keepAlive", void 0);
74
+ __decorate([
75
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
76
+ __metadata("design:type", String)
77
+ ], RedisCacheOptions.prototype, "username", void 0);
78
+ __decorate([
79
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
80
+ __metadata("design:type", String)
81
+ ], RedisCacheOptions.prototype, "password", void 0);
82
+ __decorate([
83
+ (0, dto_1.Expect)(core_1.DTO.Boolean().optional().default(true)),
84
+ __metadata("design:type", Boolean)
85
+ ], RedisCacheOptions.prototype, "reconnect", void 0);
86
+ __decorate([
87
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
88
+ __metadata("design:type", String)
89
+ ], RedisCacheOptions.prototype, "namespace", void 0);
90
+ __decorate([
91
+ (0, dto_1.Expect)(core_1.DTO.String().optional()),
92
+ __metadata("design:type", String)
93
+ ], RedisCacheOptions.prototype, "keyPrefixSeparator", void 0);
94
+ __decorate([
95
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().allow(0).optional()),
96
+ __metadata("design:type", Number)
97
+ ], RedisCacheOptions.prototype, "clearBatchSize", void 0);
98
+ __decorate([
99
+ (0, dto_1.Expect)(core_1.DTO.Boolean().optional()),
100
+ __metadata("design:type", Boolean)
101
+ ], RedisCacheOptions.prototype, "useUnlink", void 0);
102
+ __decorate([
103
+ (0, dto_1.Expect)(core_1.DTO.Boolean().optional()),
104
+ __metadata("design:type", Boolean)
105
+ ], RedisCacheOptions.prototype, "noNamespaceAffectsAll", void 0);
106
+ __decorate([
107
+ (0, dto_1.Expect)(core_1.DTO.Number().positive().optional()),
108
+ __metadata("design:type", Number)
109
+ ], RedisCacheOptions.prototype, "connectTimeout", void 0);
110
+ __decorate([
111
+ (0, dto_1.Expect)(core_1.DTO.Boolean().optional().default(true)),
112
+ __metadata("design:type", Boolean)
113
+ ], RedisCacheOptions.prototype, "throwOnConnectError", void 0);
@@ -0,0 +1,53 @@
1
+ import { DTO } from '@lakutata/core';
2
+ /**
3
+ * The options of the SQLite store: one row per entry in a table of a SQLite database file. It needs the optional peer
4
+ * dependency `sqlite3` (`npm install sqlite3`): without it, the cache's creation fails with
5
+ * `CacheDriverNotFoundException`.
6
+ *
7
+ * When the cache starts, it opens the database (creating the file) and creates the table when missing:
8
+ * `(key VARCHAR(255) PRIMARY KEY, value TEXT)`. An expired row is a miss; it stays in the table until it is read,
9
+ * overwritten or cleared. The values are kept as JSON.
10
+ * @example
11
+ * ```typescript
12
+ * import {Application} from 'lakutata'
13
+ * import {buildCacherOptions} from 'lakutata/com/cacher'
14
+ *
15
+ * Application.run(() => ({
16
+ * id: 'sqlite-cache.app',
17
+ * name: 'SqliteCache',
18
+ * components: {
19
+ * cache: buildCacherOptions({
20
+ * stores: {type: 'sqlite', database: './cache.db', table: 'cache', namespace: 'app'}
21
+ * })
22
+ * }
23
+ * }))
24
+ * ```
25
+ */
26
+ export declare class SqliteCacheOptions extends DTO {
27
+ /**
28
+ * The store type: `'sqlite'`.
29
+ */
30
+ type: 'sqlite';
31
+ /**
32
+ * The path of the database file, relative to the working directory (its directory must exist), or `':memory:'`
33
+ * for a database in memory.
34
+ */
35
+ database: string;
36
+ /**
37
+ * The table of the entries, created when missing. The characters other than letters, digits and `_` are removed
38
+ * from the name, and `_` is prefixed when it does not start with a letter; a name left empty fails the cache's
39
+ * creation.
40
+ */
41
+ table: string;
42
+ /**
43
+ * How long a statement waits for a database locked by another connection, in milliseconds, before failing.
44
+ * @default 10000
45
+ */
46
+ busyTimeout?: number;
47
+ /**
48
+ * The namespace of the entries: the keys are stored as `{namespace}:{key}`, and `clear()` deletes only the
49
+ * namespace's rows. Without it, `clear()` deletes all the table's rows.
50
+ * @default none
51
+ */
52
+ namespace?: string;
53
+ }