@adonisjs/cache 1.2.0 → 1.3.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.
- package/build/commands/cache_delete.js +70 -0
- package/build/commands/cache_delete.js.map +1 -0
- package/build/commands/cache_prune.d.ts +17 -0
- package/build/commands/cache_prune.js +63 -0
- package/build/commands/cache_prune.js.map +1 -0
- package/build/commands/commands.json +1 -1
- package/build/config.stub +2 -0
- package/build/index.js +24 -3
- package/build/index.js.map +1 -1
- package/build/metafile-esm.json +1 -1
- package/build/migration.stub +22 -0
- package/build/providers/cache_provider.d.ts +5 -1
- package/build/providers/cache_provider.js +9 -4
- package/build/providers/cache_provider.js.map +1 -1
- package/build/src/bindings/edge.d.ts +1 -1
- package/build/src/drivers.d.ts +4 -4
- package/build/src/store.d.ts +1 -14
- package/build/src/types.js.map +1 -1
- package/package.json +17 -15
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass
|
|
3
|
+
} from "../chunk-EUXUH3YW.js";
|
|
4
|
+
|
|
5
|
+
// commands/cache_delete.ts
|
|
6
|
+
import { args, BaseCommand } from "@adonisjs/core/ace";
|
|
7
|
+
var CacheDelete = class extends BaseCommand {
|
|
8
|
+
static commandName = "cache:delete";
|
|
9
|
+
static description = "Delete a specific cache entry by key";
|
|
10
|
+
static options = {
|
|
11
|
+
startApp: true
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Prompts to take consent when deleting cache entry in production
|
|
15
|
+
*/
|
|
16
|
+
async #takeProductionConsent() {
|
|
17
|
+
const question = `You are in production environment. Want to continue deleting cache key "${this.key}"?`;
|
|
18
|
+
try {
|
|
19
|
+
return await this.prompt.confirm(question);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if the given cache exist
|
|
26
|
+
*/
|
|
27
|
+
#cacheExists(cache, cacheName) {
|
|
28
|
+
try {
|
|
29
|
+
cache.use(cacheName);
|
|
30
|
+
return true;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Handle command
|
|
37
|
+
*/
|
|
38
|
+
async run() {
|
|
39
|
+
const cache = await this.app.container.make("cache.manager");
|
|
40
|
+
this.store = this.store || cache.defaultStoreName;
|
|
41
|
+
if (!this.#cacheExists(cache, this.store)) {
|
|
42
|
+
this.logger.error(
|
|
43
|
+
`"${this.store}" is not a valid cache store. Double check config/cache.ts file`
|
|
44
|
+
);
|
|
45
|
+
this.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.app.inProduction) {
|
|
49
|
+
const shouldDelete = await this.#takeProductionConsent();
|
|
50
|
+
if (!shouldDelete) return;
|
|
51
|
+
}
|
|
52
|
+
const cacheHandler = cache.use(this.store);
|
|
53
|
+
const deleted = await cacheHandler.delete({ key: this.key });
|
|
54
|
+
if (deleted) {
|
|
55
|
+
this.logger.success(`Deleted cache key "${this.key}" from "${this.store}" cache successfully`);
|
|
56
|
+
} else {
|
|
57
|
+
this.logger.warning(`Cache key "${this.key}" not found in "${this.store}" cache`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
__decorateClass([
|
|
62
|
+
args.string({ description: "The cache key to delete" })
|
|
63
|
+
], CacheDelete.prototype, "key", 2);
|
|
64
|
+
__decorateClass([
|
|
65
|
+
args.string({ description: "Define a custom cache store to delete from", required: false })
|
|
66
|
+
], CacheDelete.prototype, "store", 2);
|
|
67
|
+
export {
|
|
68
|
+
CacheDelete as default
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=cache_delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../commands/cache_delete.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { args, BaseCommand } from '@adonisjs/core/ace'\n\nimport { CacheService } from '../src/types.js'\nimport { CommandOptions } from '@adonisjs/core/types/ace'\n\nexport default class CacheDelete extends BaseCommand {\n static commandName = 'cache:delete'\n static description = 'Delete a specific cache entry by key'\n static options: CommandOptions = {\n startApp: true,\n }\n\n /**\n * The cache key to delete\n */\n @args.string({ description: 'The cache key to delete' })\n declare key: string\n\n /**\n * Choose a custom cache store to delete from. Otherwise, we use the\n * default one\n */\n @args.string({ description: 'Define a custom cache store to delete from', required: false })\n declare store: string\n\n /**\n * Prompts to take consent when deleting cache entry in production\n */\n async #takeProductionConsent(): Promise<boolean> {\n const question = `You are in production environment. Want to continue deleting cache key \"${this.key}\"?`\n try {\n return await this.prompt.confirm(question)\n } catch (error) {\n return false\n }\n }\n\n /**\n * Check if the given cache exist\n */\n #cacheExists(cache: CacheService, cacheName: string) {\n try {\n cache.use(cacheName)\n return true\n } catch (error) {\n return false\n }\n }\n\n /**\n * Handle command\n */\n async run() {\n const cache = await this.app.container.make('cache.manager')\n this.store = this.store || cache.defaultStoreName\n\n /**\n * Exit if cache store doesn't exist\n */\n if (!this.#cacheExists(cache, this.store)) {\n this.logger.error(\n `\"${this.store}\" is not a valid cache store. Double check config/cache.ts file`\n )\n this.exitCode = 1\n return\n }\n\n /**\n * Take consent when deleting cache entry in production\n */\n if (this.app.inProduction) {\n const shouldDelete = await this.#takeProductionConsent()\n if (!shouldDelete) return\n }\n\n /**\n * Finally delete the cache entry\n */\n const cacheHandler = cache.use(this.store)\n const deleted = await cacheHandler.delete({ key: this.key })\n\n if (deleted) {\n this.logger.success(`Deleted cache key \"${this.key}\" from \"${this.store}\" cache successfully`)\n } else {\n this.logger.warning(`Cache key \"${this.key}\" not found in \"${this.store}\" cache`)\n }\n }\n}\n"],"mappings":";;;;;AASA,SAAS,MAAM,mBAAmB;AAKlC,IAAqB,cAArB,cAAyC,YAAY;AAAA,EACnD,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,EADP,KAAK,OAAO,EAAE,aAAa,8CAA8C,UAAU,MAAM,CAAC;AAAA,GAjBxE,YAkBX;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
+
import { CommandOptions } from '@adonisjs/core/types/ace';
|
|
3
|
+
export default class CachePrune extends BaseCommand {
|
|
4
|
+
#private;
|
|
5
|
+
static commandName: string;
|
|
6
|
+
static description: string;
|
|
7
|
+
static options: CommandOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Choose a custom cache store to prune. Otherwise, we use the
|
|
10
|
+
* default one
|
|
11
|
+
*/
|
|
12
|
+
store: string;
|
|
13
|
+
/**
|
|
14
|
+
* Handle command
|
|
15
|
+
*/
|
|
16
|
+
run(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass
|
|
3
|
+
} from "../chunk-EUXUH3YW.js";
|
|
4
|
+
|
|
5
|
+
// commands/cache_prune.ts
|
|
6
|
+
import { args, BaseCommand } from "@adonisjs/core/ace";
|
|
7
|
+
var CachePrune = class extends BaseCommand {
|
|
8
|
+
static commandName = "cache:prune";
|
|
9
|
+
static description = "Remove expired cache entries from the selected store. This command is only useful for stores without native TTL support, like Database or File drivers.";
|
|
10
|
+
static options = {
|
|
11
|
+
startApp: true
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Prompts to take consent when pruning the cache in production
|
|
15
|
+
*/
|
|
16
|
+
async #takeProductionConsent() {
|
|
17
|
+
const question = "You are in production environment. Want to continue pruning expired cache entries?";
|
|
18
|
+
try {
|
|
19
|
+
return await this.prompt.confirm(question);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Check if the given cache exist
|
|
26
|
+
*/
|
|
27
|
+
#cacheExists(cache, cacheName) {
|
|
28
|
+
try {
|
|
29
|
+
cache.use(cacheName);
|
|
30
|
+
return true;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Handle command
|
|
37
|
+
*/
|
|
38
|
+
async run() {
|
|
39
|
+
const cache = await this.app.container.make("cache.manager");
|
|
40
|
+
this.store = this.store || cache.defaultStoreName;
|
|
41
|
+
if (!this.#cacheExists(cache, this.store)) {
|
|
42
|
+
this.logger.error(
|
|
43
|
+
`"${this.store}" is not a valid cache store. Double check config/cache.ts file`
|
|
44
|
+
);
|
|
45
|
+
this.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (this.app.inProduction) {
|
|
49
|
+
const shouldPrune = await this.#takeProductionConsent();
|
|
50
|
+
if (!shouldPrune) return;
|
|
51
|
+
}
|
|
52
|
+
const cacheHandler = cache.use(this.store);
|
|
53
|
+
await cacheHandler.prune();
|
|
54
|
+
this.logger.success(`Pruned expired entries from "${this.store}" cache successfully`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__decorateClass([
|
|
58
|
+
args.string({ description: "Define a custom cache store to prune", required: false })
|
|
59
|
+
], CachePrune.prototype, "store", 2);
|
|
60
|
+
export {
|
|
61
|
+
CachePrune as default
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=cache_prune.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../commands/cache_prune.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { args, BaseCommand } from '@adonisjs/core/ace'\n\nimport { CacheService } from '../src/types.js'\nimport { CommandOptions } from '@adonisjs/core/types/ace'\n\nexport default class CachePrune extends BaseCommand {\n static commandName = 'cache:prune'\n static description =\n 'Remove expired cache entries from the selected store. This command is only useful for stores without native TTL support, like Database or File drivers.'\n static options: CommandOptions = {\n startApp: true,\n }\n\n /**\n * Choose a custom cache store to prune. Otherwise, we use the\n * default one\n */\n @args.string({ description: 'Define a custom cache store to prune', required: false })\n declare store: string\n\n /**\n * Prompts to take consent when pruning the cache in production\n */\n async #takeProductionConsent(): Promise<boolean> {\n const question =\n 'You are in production environment. Want to continue pruning expired cache entries?'\n try {\n return await this.prompt.confirm(question)\n } catch (error) {\n return false\n }\n }\n\n /**\n * Check if the given cache exist\n */\n #cacheExists(cache: CacheService, cacheName: string) {\n try {\n cache.use(cacheName)\n return true\n } catch (error) {\n return false\n }\n }\n\n /**\n * Handle command\n */\n async run() {\n const cache = await this.app.container.make('cache.manager')\n this.store = this.store || cache.defaultStoreName\n\n /**\n * Exit if cache store doesn't exist\n */\n if (!this.#cacheExists(cache, this.store)) {\n this.logger.error(\n `\"${this.store}\" is not a valid cache store. Double check config/cache.ts file`\n )\n this.exitCode = 1\n return\n }\n\n /**\n * Take consent when pruning the cache in production\n */\n if (this.app.inProduction) {\n const shouldPrune = await this.#takeProductionConsent()\n if (!shouldPrune) return\n }\n\n /**\n * Finally prune the cache\n */\n const cacheHandler = cache.use(this.store)\n await cacheHandler.prune()\n\n this.logger.success(`Pruned expired entries from \"${this.store}\" cache successfully`)\n }\n}\n"],"mappings":";;;;;AASA,SAAS,MAAM,mBAAmB;AAKlC,IAAqB,aAArB,cAAwC,YAAY;AAAA,EAClD,OAAO,cAAc;AAAA,EACrB,OAAO,cACL;AAAA,EACF,OAAO,UAA0B;AAAA,IAC/B,UAAU;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,yBAA2C;AAC/C,UAAM,WACJ;AACF,QAAI;AACF,aAAO,MAAM,KAAK,OAAO,QAAQ,QAAQ;AAAA,IAC3C,SAAS,OAAO;AACd,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,aAAa,OAAqB,WAAmB;AACnD,QAAI;AACF,YAAM,IAAI,SAAS;AACnB,aAAO;AAAA,IACT,SAAS,OAAO;AACd,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAM;AACV,UAAM,QAAQ,MAAM,KAAK,IAAI,UAAU,KAAK,eAAe;AAC3D,SAAK,QAAQ,KAAK,SAAS,MAAM;AAKjC,QAAI,CAAC,KAAK,aAAa,OAAO,KAAK,KAAK,GAAG;AACzC,WAAK,OAAO;AAAA,QACV,IAAI,KAAK,KAAK;AAAA,MAChB;AACA,WAAK,WAAW;AAChB;AAAA,IACF;AAKA,QAAI,KAAK,IAAI,cAAc;AACzB,YAAM,cAAc,MAAM,KAAK,uBAAuB;AACtD,UAAI,CAAC,YAAa;AAAA,IACpB;AAKA,UAAM,eAAe,MAAM,IAAI,KAAK,KAAK;AACzC,UAAM,aAAa,MAAM;AAEzB,SAAK,OAAO,QAAQ,gCAAgC,KAAK,KAAK,sBAAsB;AAAA,EACtF;AACF;AA7DU;AAAA,EADP,KAAK,OAAO,EAAE,aAAa,wCAAwC,UAAU,MAAM,CAAC;AAAA,GAZlE,WAaX;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commands":[{"commandName":"cache:clear","description":"Clear the application cache","help":"","namespace":"cache","aliases":[],"flags":[{"name":"namespace","flagName":"namespace","required":false,"type":"string","description":"Select a cache namespace to clear","alias":"n"},{"name":"tags","flagName":"tags","required":false,"type":"array","description":"Specify tags to invalidate","alias":"t"}],"args":[{"name":"store","argumentName":"store","required":false,"description":"Define a custom cache store to clear","type":"string"}],"options":{"startApp":true},"filePath":"cache_clear.js"}],"version":1}
|
|
1
|
+
{"commands":[{"commandName":"cache:clear","description":"Clear the application cache","help":"","namespace":"cache","aliases":[],"flags":[{"name":"namespace","flagName":"namespace","required":false,"type":"string","description":"Select a cache namespace to clear","alias":"n"},{"name":"tags","flagName":"tags","required":false,"type":"array","description":"Specify tags to invalidate","alias":"t"}],"args":[{"name":"store","argumentName":"store","required":false,"description":"Define a custom cache store to clear","type":"string"}],"options":{"startApp":true},"filePath":"cache_clear.js"},{"commandName":"cache:delete","description":"Delete a specific cache entry by key","help":"","namespace":"cache","aliases":[],"flags":[],"args":[{"name":"key","argumentName":"key","required":true,"description":"The cache key to delete","type":"string"},{"name":"store","argumentName":"store","required":false,"description":"Define a custom cache store to delete from","type":"string"}],"options":{"startApp":true},"filePath":"cache_delete.js"},{"commandName":"cache:prune","description":"Remove expired cache entries from the selected store. This command is only useful for stores without native TTL support, like Database or File drivers.","help":"","namespace":"cache","aliases":[],"flags":[],"args":[{"name":"store","argumentName":"store","required":false,"description":"Define a custom cache store to prune","type":"string"}],"options":{"startApp":true},"filePath":"cache_prune.js"}],"version":1}
|
package/build/config.stub
CHANGED
package/build/index.js
CHANGED
|
@@ -100,6 +100,15 @@ async function configure(command) {
|
|
|
100
100
|
await codemods.defineEnvValidations({ variables: envValidations });
|
|
101
101
|
}
|
|
102
102
|
await codemods.makeUsingStub(stubsRoot, "config.stub", { driver });
|
|
103
|
+
if (driver === "database") {
|
|
104
|
+
await codemods.makeUsingStub(stubsRoot, "migration.stub", {
|
|
105
|
+
entity: command.app.generators.createEntity("cache"),
|
|
106
|
+
migration: {
|
|
107
|
+
folder: "database/migrations",
|
|
108
|
+
fileName: `${(/* @__PURE__ */ new Date()).getTime()}_create_cache_table.ts`
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
// src/define_config.ts
|
|
@@ -120,7 +129,10 @@ var drivers = {
|
|
|
120
129
|
const redis = await app.container.make("redis");
|
|
121
130
|
const { redisDriver } = await import("bentocache/drivers/redis");
|
|
122
131
|
const redisConnection = redis.connection(config.connectionName);
|
|
123
|
-
return redisDriver({
|
|
132
|
+
return redisDriver({
|
|
133
|
+
connection: redisConnection.ioConnection,
|
|
134
|
+
prefix: config.prefix || "bentocache"
|
|
135
|
+
});
|
|
124
136
|
});
|
|
125
137
|
},
|
|
126
138
|
/**
|
|
@@ -132,7 +144,10 @@ var drivers = {
|
|
|
132
144
|
const redis = await app.container.make("redis");
|
|
133
145
|
const { redisBusDriver } = await import("bentocache/drivers/redis");
|
|
134
146
|
const redisConnection = redis.connection(config.connectionName);
|
|
135
|
-
return redisBusDriver({
|
|
147
|
+
return redisBusDriver({
|
|
148
|
+
connection: redisConnection.ioConnection.options,
|
|
149
|
+
retryQueue: config.retryQueue
|
|
150
|
+
});
|
|
136
151
|
});
|
|
137
152
|
},
|
|
138
153
|
/**
|
|
@@ -159,7 +174,13 @@ var drivers = {
|
|
|
159
174
|
);
|
|
160
175
|
}
|
|
161
176
|
const { knexDriver } = await import("bentocache/drivers/knex");
|
|
162
|
-
return knexDriver({
|
|
177
|
+
return knexDriver({
|
|
178
|
+
connection: db.connection(connectionName).getWriteClient(),
|
|
179
|
+
autoCreateTable: config?.autoCreateTable ?? true,
|
|
180
|
+
tableName: config?.tableName || "bentocache",
|
|
181
|
+
pruneInterval: config?.pruneInterval ?? false,
|
|
182
|
+
prefix: config?.prefix || "bentocache"
|
|
183
|
+
});
|
|
163
184
|
});
|
|
164
185
|
},
|
|
165
186
|
/**
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../index.ts","../src/store.ts","../stubs/main.ts","../configure.ts","../src/define_config.ts","../src/drivers.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * from 'bentocache'\n\nexport { store } from './src/store.js'\nexport { configure } from './configure.js'\nexport { defineConfig } from './src/define_config.js'\nexport { drivers } from './src/drivers.js'\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { bentostore } from 'bentocache'\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport {\n RawCommonOptions,\n CreateDriverResult,\n L1CacheDriver,\n CreateBusDriverResult,\n L2CacheDriver,\n} from 'bentocache/types'\n\n/**\n * Create a new store\n */\nexport function store(options?: RawCommonOptions & { prefix?: string }) {\n return new Store(options)\n}\n\nexport class Store {\n #baseOptions: RawCommonOptions & { prefix?: string } = {}\n #l1?: ConfigProvider<CreateDriverResult<L1CacheDriver>>\n #l2?: ConfigProvider<CreateDriverResult<L2CacheDriver>>\n #bus?: ConfigProvider<CreateBusDriverResult>\n\n constructor(baseOptions: RawCommonOptions & { prefix?: string } = {}) {\n this.#baseOptions = baseOptions\n }\n\n /**\n * Add a L1 layer to your store. This is usually a memory driver\n * for fast access purposes.\n */\n useL1Layer(driver: ConfigProvider<CreateDriverResult<L1CacheDriver>>) {\n this.#l1 = driver\n return this\n }\n\n /**\n * Add a L2 layer to your store. This is usually something\n * distributed like Redis, DynamoDB, Sql database, etc.\n */\n useL2Layer(driver: ConfigProvider<CreateDriverResult<L2CacheDriver>>) {\n this.#l2 = driver\n return this\n }\n\n /**\n * Add a bus to your store. It will be used to synchronize L1 layers between\n * different instances of your application.\n */\n useBus(bus: ConfigProvider<CreateBusDriverResult>) {\n this.#bus = bus\n return this\n }\n\n /**\n * Create a config provider for the store\n */\n entry() {\n return configProvider.create(async (app) => {\n const storeInstance = bentostore(this.#baseOptions)\n\n if (this.#l1) storeInstance.useL1Layer(await this.#l1?.resolver(app))\n if (this.#l2) storeInstance.useL2Layer(await this.#l2?.resolver(app))\n if (this.#bus) storeInstance.useBus(await this.#bus?.resolver(app))\n\n return storeInstance\n })\n }\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport const stubsRoot = dirname(fileURLToPath(import.meta.url))\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\n\nimport { stubsRoot } from './stubs/main.js'\n\nconst DRIVERS = ['redis', 'file', 'database', 'dynamodb'] as const\nconst DRIVERS_INFO: {\n [K in (typeof DRIVERS)[number]]: {\n envVars?: Record<string, number | string>\n envValidations?: Record<string, string>\n }\n} = {\n file: {},\n redis: {},\n database: {},\n dynamodb: {\n envValidations: {\n AWS_ACCESS_KEY_ID: `Env.schema.string()`,\n AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,\n AWS_REGION: `Env.schema.string()`,\n DYNAMODB_ENDPOINT: `Env.schema.string()`,\n },\n envVars: {\n AWS_ACCESS_KEY_ID: '',\n AWS_SECRET_ACCESS_KEY: '',\n AWS_REGION: '',\n DYNAMODB_ENDPOINT: '',\n },\n },\n}\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n const driver = await command.prompt.choice(\n 'Select the cache driver you plan to use',\n ['redis', 'file', 'database', 'dynamodb'],\n {\n hint: 'You can always change it later',\n }\n )\n\n const codemods = await command.createCodemods()\n\n /**\n * Publish provider\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/cache/cache_provider').addCommand('@adonisjs/cache/commands')\n })\n\n const { envVars, envValidations } = DRIVERS_INFO[driver]\n\n /**\n * Define environment variables\n */\n if (envVars) {\n await codemods.defineEnvVariables(envVars)\n }\n\n /**\n * Define environment validations\n */\n if (envValidations) {\n await codemods.defineEnvValidations({ variables: envValidations })\n }\n\n /**\n * Publish config\n */\n await codemods.makeUsingStub(stubsRoot, 'config.stub', { driver: driver })\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Store } from './store.js'\nimport { CacheOptions } from './types.js'\n\n/**\n * Define cache configuration\n */\nexport function defineConfig<KnownCaches extends Record<string, Store>>(\n config: CacheOptions & {\n default: keyof KnownCaches\n stores: KnownCaches\n }\n) {\n return config\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference types=\"@adonisjs/redis/redis_provider\" />\n/// <reference types=\"@adonisjs/lucid/database_provider\" />\n\nimport { configProvider } from '@adonisjs/core'\nimport type { RedisConnection } from '@adonisjs/redis'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport type { RedisConnections } from '@adonisjs/redis/types'\nimport {\n MemoryConfig,\n CreateDriverResult,\n L1CacheDriver,\n L2CacheDriver,\n CreateBusDriverResult,\n DynamoDBConfig,\n FileConfig,\n KyselyConfig,\n OrchidConfig,\n} from 'bentocache/types'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\n\n/**\n * Different drivers supported by the cache module\n */\nexport const drivers: {\n memory: (config?: MemoryConfig) => ConfigProvider<CreateDriverResult<L1CacheDriver>>\n redis: (config: {\n connectionName?: keyof RedisConnections\n }) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n redisBus: (config: {\n connectionName?: keyof RedisConnections\n }) => ConfigProvider<CreateBusDriverResult>\n database: (config?: {\n connectionName?: string\n }) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n dynamodb: (config: DynamoDBConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n file: (config: FileConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n kysely: (config: KyselyConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n orchid: (config: OrchidConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n} = {\n /**\n * Redis driver for L2 layer\n * You must install @adonisjs/redis to use this driver\n */\n redis(config) {\n return configProvider.create(async (app) => {\n const redis = await app.container.make('redis')\n const { redisDriver } = await import('bentocache/drivers/redis')\n\n const redisConnection = redis.connection(config.connectionName) as any as RedisConnection\n return redisDriver({ connection: redisConnection.ioConnection })\n })\n },\n\n /**\n * Redis driver for the sync bus\n * You must install @adonisjs/redis to use this driver\n */\n redisBus(config) {\n return configProvider.create(async (app) => {\n const redis = await app.container.make('redis')\n const { redisBusDriver } = await import('bentocache/drivers/redis')\n\n const redisConnection = redis.connection(config.connectionName) as any as RedisConnection\n return redisBusDriver({ connection: redisConnection.ioConnection.options })\n })\n },\n\n /**\n * Memory driver for L1 layer\n */\n memory(config) {\n return configProvider.create(async () => {\n const { memoryDriver } = await import('bentocache/drivers/memory')\n return memoryDriver(config)\n })\n },\n\n /**\n * Database driver for L2 layer\n * You must install @adonisjs/lucid to use this driver\n */\n database(config) {\n return configProvider.create(async (app) => {\n const db = await app.container.make('lucid.db')\n const connectionName = config?.connectionName || db.primaryConnectionName\n const connection = db.manager.get(connectionName)\n\n /**\n * Throw error when mentioned connection is not specified\n * in the database file\n */\n if (!connection) {\n throw new RuntimeException(\n `Invalid connection name \"${connectionName}\" referenced by \"config/cache.ts\" file. First register the connection inside \"config/database.ts\" file`\n )\n }\n\n const { knexDriver } = await import('bentocache/drivers/knex')\n return knexDriver({ connection: db.connection(connectionName).getWriteClient() })\n })\n },\n\n /**\n * DynamoDB driver for L2 layer\n * You must install @aws-sdk/client-dynamodb to use this driver\n */\n dynamodb(config) {\n return configProvider.create(async () => {\n const { dynamoDbDriver } = await import('bentocache/drivers/dynamodb')\n return dynamoDbDriver(config)\n })\n },\n\n /**\n * File driver for L2 layer\n */\n file(config) {\n return configProvider.create(async () => {\n const { fileDriver } = await import('bentocache/drivers/file')\n return fileDriver(config)\n })\n },\n\n /**\n * Kysely driver for L2 layer\n */\n kysely(config) {\n return configProvider.create(async () => {\n const { kyselyDriver } = await import('bentocache/drivers/kysely')\n return kyselyDriver(config)\n })\n },\n\n /**\n * Orchid driver for L2 layer\n */\n orchid(config) {\n return configProvider.create(async () => {\n const { orchidDriver } = await import('bentocache/drivers/orchid')\n return orchidDriver(config)\n })\n },\n}\n"],"mappings":";;;AASA,cAAc;;;ACAd,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAaxB,SAAS,MAAM,SAAkD;AACtE,SAAO,IAAI,MAAM,OAAO;AAC1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,aAAa,MAAM;AAAA,IAC5B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,QAAQ;AACb,WAAOA,gBAAe,OAAO,YAAY;AACvC,YAAM,EAAE,aAAa,IAAI,MAAM,OAAO,2BAA2B;AACjE,aAAO,aAAa,MAAM;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;","names":["configProvider"]}
|
|
1
|
+
{"version":3,"sources":["../index.ts","../src/store.ts","../stubs/main.ts","../configure.ts","../src/define_config.ts","../src/drivers.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * from 'bentocache'\n\nexport { store } from './src/store.js'\nexport { configure } from './configure.js'\nexport { defineConfig } from './src/define_config.js'\nexport { drivers } from './src/drivers.js'\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { bentostore } from 'bentocache'\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport {\n RawCommonOptions,\n CreateDriverResult,\n L1CacheDriver,\n CreateBusDriverResult,\n L2CacheDriver,\n} from 'bentocache/types'\n\n/**\n * Create a new store\n */\nexport function store(options?: RawCommonOptions & { prefix?: string }) {\n return new Store(options)\n}\n\nexport class Store {\n #baseOptions: RawCommonOptions & { prefix?: string } = {}\n #l1?: ConfigProvider<CreateDriverResult<L1CacheDriver>>\n #l2?: ConfigProvider<CreateDriverResult<L2CacheDriver>>\n #bus?: ConfigProvider<CreateBusDriverResult>\n\n constructor(baseOptions: RawCommonOptions & { prefix?: string } = {}) {\n this.#baseOptions = baseOptions\n }\n\n /**\n * Add a L1 layer to your store. This is usually a memory driver\n * for fast access purposes.\n */\n useL1Layer(driver: ConfigProvider<CreateDriverResult<L1CacheDriver>>) {\n this.#l1 = driver\n return this\n }\n\n /**\n * Add a L2 layer to your store. This is usually something\n * distributed like Redis, DynamoDB, Sql database, etc.\n */\n useL2Layer(driver: ConfigProvider<CreateDriverResult<L2CacheDriver>>) {\n this.#l2 = driver\n return this\n }\n\n /**\n * Add a bus to your store. It will be used to synchronize L1 layers between\n * different instances of your application.\n */\n useBus(bus: ConfigProvider<CreateBusDriverResult>) {\n this.#bus = bus\n return this\n }\n\n /**\n * Create a config provider for the store\n */\n entry() {\n return configProvider.create(async (app) => {\n const storeInstance = bentostore(this.#baseOptions)\n\n if (this.#l1) storeInstance.useL1Layer(await this.#l1?.resolver(app))\n if (this.#l2) storeInstance.useL2Layer(await this.#l2?.resolver(app))\n if (this.#bus) storeInstance.useBus(await this.#bus?.resolver(app))\n\n return storeInstance\n })\n }\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport const stubsRoot = dirname(fileURLToPath(import.meta.url))\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type Configure from '@adonisjs/core/commands/configure'\n\nimport { stubsRoot } from './stubs/main.js'\n\nconst DRIVERS = ['redis', 'file', 'database', 'dynamodb'] as const\nconst DRIVERS_INFO: {\n [K in (typeof DRIVERS)[number]]: {\n envVars?: Record<string, number | string>\n envValidations?: Record<string, string>\n }\n} = {\n file: {},\n redis: {},\n database: {},\n dynamodb: {\n envValidations: {\n AWS_ACCESS_KEY_ID: `Env.schema.string()`,\n AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,\n AWS_REGION: `Env.schema.string()`,\n DYNAMODB_ENDPOINT: `Env.schema.string()`,\n },\n envVars: {\n AWS_ACCESS_KEY_ID: '',\n AWS_SECRET_ACCESS_KEY: '',\n AWS_REGION: '',\n DYNAMODB_ENDPOINT: '',\n },\n },\n}\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n const driver = await command.prompt.choice(\n 'Select the cache driver you plan to use',\n ['redis', 'file', 'database', 'dynamodb'],\n {\n hint: 'You can always change it later',\n }\n )\n\n const codemods = await command.createCodemods()\n\n /**\n * Publish provider\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/cache/cache_provider').addCommand('@adonisjs/cache/commands')\n })\n\n const { envVars, envValidations } = DRIVERS_INFO[driver]\n\n /**\n * Define environment variables\n */\n if (envVars) {\n await codemods.defineEnvVariables(envVars)\n }\n\n /**\n * Define environment validations\n */\n if (envValidations) {\n await codemods.defineEnvValidations({ variables: envValidations })\n }\n\n /**\n * Publish config\n */\n await codemods.makeUsingStub(stubsRoot, 'config.stub', { driver: driver })\n\n /**\n * Create migration for database driver\n */\n if (driver === 'database') {\n await codemods.makeUsingStub(stubsRoot, 'migration.stub', {\n entity: command.app.generators.createEntity('cache'),\n migration: {\n folder: 'database/migrations',\n fileName: `${new Date().getTime()}_create_cache_table.ts`,\n },\n })\n }\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { Store } from './store.js'\nimport { CacheOptions } from './types.js'\n\n/**\n * Define cache configuration\n */\nexport function defineConfig<KnownCaches extends Record<string, Store>>(\n config: CacheOptions & {\n default: keyof KnownCaches\n stores: KnownCaches\n }\n) {\n return config\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\n/// <reference types=\"@adonisjs/redis/redis_provider\" />\n/// <reference types=\"@adonisjs/lucid/database_provider\" />\n\nimport { configProvider } from '@adonisjs/core'\nimport type { RedisConnection } from '@adonisjs/redis'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport type { RedisConnections } from '@adonisjs/redis/types'\nimport {\n MemoryConfig,\n CreateDriverResult,\n L1CacheDriver,\n L2CacheDriver,\n CreateBusDriverResult,\n DynamoDBConfig,\n FileConfig,\n RedisConfig,\n BusOptions,\n KyselyConfig,\n OrchidConfig,\n DatabaseConfig,\n} from 'bentocache/types'\nimport { RuntimeException } from '@adonisjs/core/exceptions'\n\n/**\n * Different drivers supported by the cache module\n */\nexport const drivers: {\n memory: (config?: MemoryConfig) => ConfigProvider<CreateDriverResult<L1CacheDriver>>\n redis: (\n config: Omit<RedisConfig, 'connection'> & { connectionName?: keyof RedisConnections }\n ) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n redisBus: (\n config: BusOptions & { connectionName?: keyof RedisConnections }\n ) => ConfigProvider<CreateBusDriverResult>\n database: (\n config?: DatabaseConfig & { connectionName?: string }\n ) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n dynamodb: (config: DynamoDBConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n file: (config: FileConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n kysely: (config: KyselyConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n orchid: (config: OrchidConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>\n} = {\n /**\n * Redis driver for L2 layer\n * You must install @adonisjs/redis to use this driver\n */\n redis(config) {\n return configProvider.create(async (app) => {\n const redis = await app.container.make('redis')\n const { redisDriver } = await import('bentocache/drivers/redis')\n\n const redisConnection = redis.connection(config.connectionName) as any as RedisConnection\n return redisDriver({\n connection: redisConnection.ioConnection,\n prefix: config.prefix || 'bentocache',\n })\n })\n },\n\n /**\n * Redis driver for the sync bus\n * You must install @adonisjs/redis to use this driver\n */\n redisBus(config) {\n return configProvider.create(async (app) => {\n const redis = await app.container.make('redis')\n const { redisBusDriver } = await import('bentocache/drivers/redis')\n\n const redisConnection = redis.connection(config.connectionName) as any as RedisConnection\n return redisBusDriver({\n connection: redisConnection.ioConnection.options,\n retryQueue: config.retryQueue,\n })\n })\n },\n\n /**\n * Memory driver for L1 layer\n */\n memory(config) {\n return configProvider.create(async () => {\n const { memoryDriver } = await import('bentocache/drivers/memory')\n return memoryDriver(config)\n })\n },\n\n /**\n * Database driver for L2 layer\n * You must install @adonisjs/lucid to use this driver\n */\n database(config) {\n return configProvider.create(async (app) => {\n const db = await app.container.make('lucid.db')\n const connectionName = config?.connectionName || db.primaryConnectionName\n const connection = db.manager.get(connectionName)\n\n /**\n * Throw error when mentioned connection is not specified\n * in the database file\n */\n if (!connection) {\n throw new RuntimeException(\n `Invalid connection name \"${connectionName}\" referenced by \"config/cache.ts\" file. First register the connection inside \"config/database.ts\" file`\n )\n }\n\n const { knexDriver } = await import('bentocache/drivers/knex')\n return knexDriver({\n connection: db.connection(connectionName).getWriteClient(),\n autoCreateTable: config?.autoCreateTable ?? true,\n tableName: config?.tableName || 'bentocache',\n pruneInterval: config?.pruneInterval ?? false,\n prefix: config?.prefix || 'bentocache',\n })\n })\n },\n\n /**\n * DynamoDB driver for L2 layer\n * You must install @aws-sdk/client-dynamodb to use this driver\n */\n dynamodb(config) {\n return configProvider.create(async () => {\n const { dynamoDbDriver } = await import('bentocache/drivers/dynamodb')\n return dynamoDbDriver(config)\n })\n },\n\n /**\n * File driver for L2 layer\n */\n file(config) {\n return configProvider.create(async () => {\n const { fileDriver } = await import('bentocache/drivers/file')\n return fileDriver(config)\n })\n },\n\n /**\n * Kysely driver for L2 layer\n */\n kysely(config) {\n return configProvider.create(async () => {\n const { kyselyDriver } = await import('bentocache/drivers/kysely')\n return kyselyDriver(config)\n })\n },\n\n /**\n * Orchid driver for L2 layer\n */\n orchid(config) {\n return configProvider.create(async () => {\n const { orchidDriver } = await import('bentocache/drivers/orchid')\n return orchidDriver(config)\n })\n },\n}\n"],"mappings":";;;AASA,cAAc;;;ACAd,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAaxB,SAAS,MAAM,SAAkD;AACtE,SAAO,IAAI,MAAM,OAAO;AAC1B;AAEO,IAAM,QAAN,MAAY;AAAA,EACjB,eAAuD,CAAC;AAAA,EACxD;AAAA,EACA;AAAA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AM,OAAO,6BAA6B;AACrE,aAAO,eAAe,MAAM;AAAA,IAC9B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,QAAQ;AACX,WAAOA,gBAAe,OAAO,YAAY;AACvC,YAAM,EAAE,WAAW,IAAI,MAAM,OAAO,yBAAyB;AAC7D,aAAO,WAAW,MAAM;AAAA,IAC1B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,QAAQ;AACb,WAAOA,gBAAe,OAAO,YAAY;AACvC,YAAM,EAAE,aAAa,IAAI,MAAM,OAAO,2BAA2B;AACjE,aAAO,aAAa,MAAM;AAAA,IAC5B,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,QAAQ;AACb,WAAOA,gBAAe,OAAO,YAAY;AACvC,YAAM,EAAE,aAAa,IAAI,MAAM,OAAO,2BAA2B;AACjE,aAAO,aAAa,MAAM;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;","names":["configProvider"]}
|
package/build/metafile-esm.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/store.ts":{"bytes":2107,"imports":[{"path":"bentocache","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"bentocache/types","kind":"import-statement","external":true}],"format":"esm"},"stubs/main.ts":{"bytes":319,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/store.ts":{"bytes":2107,"imports":[{"path":"bentocache","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"bentocache/types","kind":"import-statement","external":true}],"format":"esm"},"stubs/main.ts":{"bytes":319,"imports":[{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":2238,"imports":[{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/define_config.ts":{"bytes":473,"imports":[{"path":"./store.js","kind":"import-statement","external":true},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/drivers.ts":{"bytes":5176,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"bentocache/types","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"bentocache/drivers/redis","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/redis","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/memory","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/knex","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/dynamodb","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/file","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/kysely","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/orchid","kind":"dynamic-import","external":true}],"format":"esm"},"index.ts":{"bytes":383,"imports":[{"path":"bentocache","kind":"import-statement","external":true},{"path":"src/store.ts","kind":"import-statement","original":"./src/store.js"},{"path":"configure.ts","kind":"import-statement","original":"./configure.js"},{"path":"src/define_config.ts","kind":"import-statement","original":"./src/define_config.js"},{"path":"src/drivers.ts","kind":"import-statement","original":"./src/drivers.js"}],"format":"esm"},"commands/cache_clear.ts":{"bytes":3317,"imports":[{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true},{"path":"@adonisjs/core/types/ace","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"commands/cache_delete.ts":{"bytes":2514,"imports":[{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true},{"path":"@adonisjs/core/types/ace","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"commands/cache_prune.ts":{"bytes":2313,"imports":[{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true},{"path":"@adonisjs/core/types/ace","kind":"import-statement","external":true},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/bindings/repl.ts":{"bytes":910,"imports":[],"format":"esm"},"src/debug.ts":{"bytes":256,"imports":[{"path":"util","kind":"import-statement","external":true}],"format":"esm"},"src/bindings/edge.ts":{"bytes":479,"imports":[{"path":"src/debug.ts","kind":"import-statement","original":"../debug.js"},{"path":"../types.js","kind":"import-statement","external":true},{"path":"edge.js","kind":"dynamic-import","external":true}],"format":"esm"},"providers/cache_provider.ts":{"bytes":3119,"imports":[{"path":"../index.js","kind":"import-statement","external":true},{"path":"src/bindings/repl.ts","kind":"import-statement","original":"../src/bindings/repl.js"},{"path":"src/bindings/edge.ts","kind":"import-statement","original":"../src/bindings/edge.js"},{"path":"bentocache","kind":"dynamic-import","external":true}],"format":"esm"},"services/main.ts":{"bytes":476,"imports":[{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":1041,"imports":[{"path":"bentocache/types","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"build/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":15172},"build/index.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"bentocache","kind":"import-statement","external":true},{"path":"bentocache","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"bentocache/drivers/redis","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/redis","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/memory","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/knex","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/dynamodb","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/file","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/kysely","kind":"dynamic-import","external":true},{"path":"bentocache/drivers/orchid","kind":"dynamic-import","external":true}],"exports":["configure","defineConfig","drivers","store"],"entryPoint":"index.ts","inputs":{"index.ts":{"bytesInOutput":28},"src/store.ts":{"bytesInOutput":1304},"stubs/main.ts":{"bytesInOutput":126},"configure.ts":{"bytesInOutput":1487},"src/define_config.ts":{"bytesInOutput":51},"src/drivers.ts":{"bytesInOutput":3424}},"bytes":6619},"build/commands/cache_clear.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":5125},"build/commands/cache_clear.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/cache_clear.ts","inputs":{"commands/cache_clear.ts":{"bytesInOutput":2556}},"bytes":2678},"build/commands/cache_delete.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":3932},"build/commands/cache_delete.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/cache_delete.ts","inputs":{"commands/cache_delete.ts":{"bytesInOutput":1914}},"bytes":2038},"build/commands/cache_prune.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":3481},"build/commands/cache_prune.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/cache_prune.ts","inputs":{"commands/cache_prune.ts":{"bytesInOutput":1727}},"bytes":1849},"build/providers/cache_provider.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6846},"build/providers/cache_provider.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"util","kind":"import-statement","external":true},{"path":"edge.js","kind":"dynamic-import","external":true},{"path":"bentocache","kind":"dynamic-import","external":true}],"exports":["default"],"entryPoint":"providers/cache_provider.ts","inputs":{"src/bindings/repl.ts":{"bytesInOutput":443},"src/debug.ts":{"bytesInOutput":81},"src/bindings/edge.ts":{"bytesInOutput":211},"providers/cache_provider.ts":{"bytesInOutput":1692}},"bytes":2596},"build/services/main.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":718},"build/services/main.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"services/main.ts","inputs":{"services/main.ts":{"bytesInOutput":146}},"bytes":229},"build/chunk-EUXUH3YW.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/chunk-EUXUH3YW.js":{"imports":[],"exports":["__decorateClass"],"inputs":{},"bytes":524},"build/src/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1207},"build/src/types.js":{"imports":[{"path":"bentocache/types","kind":"import-statement","external":true}],"exports":[],"entryPoint":"src/types.ts","inputs":{"src/types.ts":{"bytesInOutput":34}},"bytes":50}}}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({
|
|
3
|
+
to: app.makePath(migration.folder, entity.path, migration.fileName)
|
|
4
|
+
})
|
|
5
|
+
}}}
|
|
6
|
+
import { BaseSchema } from '@adonisjs/lucid/schema'
|
|
7
|
+
|
|
8
|
+
export default class extends BaseSchema {
|
|
9
|
+
protected tableName = 'cache'
|
|
10
|
+
|
|
11
|
+
async up() {
|
|
12
|
+
this.schema.createTable(this.tableName, (table) => {
|
|
13
|
+
table.string('key', 255).notNullable().primary()
|
|
14
|
+
table.text('value', 'longtext')
|
|
15
|
+
table.timestamp('expires_at').nullable()
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async down() {
|
|
20
|
+
this.schema.dropTable(this.tableName)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -34,7 +34,7 @@ var CacheProvider = class {
|
|
|
34
34
|
/**
|
|
35
35
|
* Register the cache manager to the container
|
|
36
36
|
*/
|
|
37
|
-
|
|
37
|
+
#registerCacheManager() {
|
|
38
38
|
const cacheConfig = this.app.config.get("cache");
|
|
39
39
|
this.app.container.singleton("cache.manager", async () => {
|
|
40
40
|
const { BentoCache } = await import("bentocache");
|
|
@@ -71,10 +71,15 @@ var CacheProvider = class {
|
|
|
71
71
|
/**
|
|
72
72
|
* Register bindings
|
|
73
73
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
register() {
|
|
75
|
+
this.#registerCacheManager();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Boot provider
|
|
79
|
+
*/
|
|
80
|
+
async boot() {
|
|
77
81
|
await this.#registerEdgeBindings();
|
|
82
|
+
await this.#registerReplBindings();
|
|
78
83
|
}
|
|
79
84
|
/**
|
|
80
85
|
* Gracefully shutdown connections when app goes down
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bindings/repl.ts","../../src/debug.ts","../../src/bindings/edge.ts","../../providers/cache_provider.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { Repl } from '@adonisjs/core/repl'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\n/**\n * Helper to define REPL state\n */\nfunction setupReplState(repl: any, key: string, value: any) {\n repl.server.context[key] = value\n repl.notify(\n `Loaded ${key} module. You can access it using the \"${repl.colors.underline(key)}\" variable`\n )\n}\n\n/**\n * Define REPL bindings\n */\nexport function defineReplBindings(app: ApplicationService, Repl: Repl) {\n /**\n * Load cache provider to the cache property\n */\n Repl.addMethod(\n 'loadCache',\n async (repl) => setupReplState(repl, 'cache', await app.container.make('cache.manager')),\n { description: 'Load cache provider to the \"cache\" property' }\n )\n}\n","/*\n * @adonisjs/drive\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:cache')\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport debug from '../debug.js'\nimport { CacheService } from '../types.js'\n\nexport async function registerViewBindings(manager: CacheService) {\n const edge = await import('edge.js')\n debug('detected edge installation. Registering cache global helpers')\n\n edge.default.global('cache', manager)\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport { defineConfig } from '../index.js'\nimport type { CacheEvents } from 'bentocache/types'\nimport type { CacheService } from '../src/types.js'\nimport { defineReplBindings } from '../src/bindings/repl.js'\nimport { registerViewBindings } from '../src/bindings/edge.js'\n\n/**\n * Extend Adonis.js types to include cache\n */\ndeclare module '@adonisjs/core/types' {\n /**\n * Adding cache type to the application container\n */\n export interface ContainerBindings {\n 'cache.manager': CacheService\n }\n\n /**\n * Add cache events to the application events list\n */\n export interface EventsList {\n 'cache:cleared': CacheEvents['cache:cleared']\n 'cache:deleted': CacheEvents['cache:deleted']\n 'cache:hit': CacheEvents['cache:hit']\n 'cache:miss': CacheEvents['cache:miss']\n 'cache:written': CacheEvents['cache:written']\n 'bus:message:published': CacheEvents['bus:message:published']\n 'bus:message:received': CacheEvents['bus:message:received']\n }\n}\n\n/**\n * Cache provider to register cache specific bindings\n */\nexport default class CacheProvider {\n constructor(protected app: ApplicationService) {}\n\n /**\n * Register the cache manager to the container\n */\n
|
|
1
|
+
{"version":3,"sources":["../../src/bindings/repl.ts","../../src/debug.ts","../../src/bindings/edge.ts","../../providers/cache_provider.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { Repl } from '@adonisjs/core/repl'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\n/**\n * Helper to define REPL state\n */\nfunction setupReplState(repl: any, key: string, value: any) {\n repl.server.context[key] = value\n repl.notify(\n `Loaded ${key} module. You can access it using the \"${repl.colors.underline(key)}\" variable`\n )\n}\n\n/**\n * Define REPL bindings\n */\nexport function defineReplBindings(app: ApplicationService, Repl: Repl) {\n /**\n * Load cache provider to the cache property\n */\n Repl.addMethod(\n 'loadCache',\n async (repl) => setupReplState(repl, 'cache', await app.container.make('cache.manager')),\n { description: 'Load cache provider to the \"cache\" property' }\n )\n}\n","/*\n * @adonisjs/drive\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:cache')\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport debug from '../debug.js'\nimport { type CacheService } from '../types.js'\n\nexport async function registerViewBindings(manager: CacheService) {\n const edge = await import('edge.js')\n debug('detected edge installation. Registering cache global helpers')\n\n edge.default.global('cache', manager)\n}\n","/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport { type defineConfig } from '../index.js'\nimport type { CacheEvents } from 'bentocache/types'\nimport type { CacheService } from '../src/types.js'\nimport { defineReplBindings } from '../src/bindings/repl.js'\nimport { registerViewBindings } from '../src/bindings/edge.js'\n\n/**\n * Extend Adonis.js types to include cache\n */\ndeclare module '@adonisjs/core/types' {\n /**\n * Adding cache type to the application container\n */\n export interface ContainerBindings {\n 'cache.manager': CacheService\n }\n\n /**\n * Add cache events to the application events list\n */\n export interface EventsList {\n 'cache:cleared': CacheEvents['cache:cleared']\n 'cache:deleted': CacheEvents['cache:deleted']\n 'cache:hit': CacheEvents['cache:hit']\n 'cache:miss': CacheEvents['cache:miss']\n 'cache:written': CacheEvents['cache:written']\n 'bus:message:published': CacheEvents['bus:message:published']\n 'bus:message:received': CacheEvents['bus:message:received']\n }\n}\n\n/**\n * Cache provider to register cache specific bindings\n */\nexport default class CacheProvider {\n constructor(protected app: ApplicationService) {}\n\n /**\n * Register the cache manager to the container\n */\n #registerCacheManager() {\n const cacheConfig = this.app.config.get<ReturnType<typeof defineConfig>>('cache')\n\n this.app.container.singleton('cache.manager', async () => {\n const { BentoCache } = await import('bentocache')\n const emitter = await this.app.container.make('emitter')\n\n /**\n * Resolve all store config providers\n */\n const resolvedStores = Object.entries(cacheConfig.stores).map(async ([name, store]) => {\n return [name, await store.entry().resolver(this.app)]\n })\n\n return new BentoCache({\n ...cacheConfig,\n emitter: emitter as any,\n default: cacheConfig.default,\n stores: Object.fromEntries(await Promise.all(resolvedStores)),\n })\n })\n }\n\n /**\n * Register REPL bindings\n */\n async #registerReplBindings() {\n if (this.app.getEnvironment() !== 'repl') {\n return\n }\n\n const repl = await this.app.container.make('repl')\n defineReplBindings(this.app, repl)\n }\n\n /**\n * Register edge bindings\n */\n async #registerEdgeBindings() {\n if (!this.app.usingEdgeJS) return\n\n const manager = await this.app.container.make('cache.manager')\n await registerViewBindings(manager)\n }\n\n /**\n * Register bindings\n */\n register() {\n this.#registerCacheManager()\n }\n\n /**\n * Boot provider\n */\n async boot() {\n await this.#registerEdgeBindings()\n await this.#registerReplBindings()\n }\n\n /**\n * Gracefully shutdown connections when app goes down\n */\n async shutdown() {\n try {\n const cache = await this.app.container.make('cache.manager')\n await cache.disconnectAll()\n } catch (_e) {\n // Ignore errors\n }\n }\n}\n"],"mappings":";;;AAeA,SAAS,eAAe,MAAW,KAAa,OAAY;AAC1D,OAAK,OAAO,QAAQ,GAAG,IAAI;AAC3B,OAAK;AAAA,IACH,UAAU,GAAG,yCAAyC,KAAK,OAAO,UAAU,GAAG,CAAC;AAAA,EAClF;AACF;AAKO,SAAS,mBAAmB,KAAyB,MAAY;AAItE,OAAK;AAAA,IACH;AAAA,IACA,OAAO,SAAS,eAAe,MA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CAAC,KAAK,IAAI,YAAa;AAE3B,UAAM,UAAU,MAAM,KAAK,IAAI,UAAU,KAAK,eAAe;AAC7D,UAAM,qBAAqB,OAAO;AAAA,EACpC;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACT,SAAK,sBAAsB;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO;AACX,UAAM,KAAK,sBAAsB;AACjC,UAAM,KAAK,sBAAsB;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW;AACf,QAAI;AACF,YAAM,QAAQ,MAAM,KAAK,IAAI,UAAU,KAAK,eAAe;AAC3D,YAAM,MAAM,cAAc;AAAA,IAC5B,SAAS,IAAI;AAAA,IAEb;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CacheService } from '../types.js';
|
|
1
|
+
import { type CacheService } from '../types.js';
|
|
2
2
|
export declare function registerViewBindings(manager: CacheService): Promise<void>;
|
package/build/src/drivers.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { ConfigProvider } from '@adonisjs/core/types';
|
|
2
2
|
import type { RedisConnections } from '@adonisjs/redis/types';
|
|
3
|
-
import { MemoryConfig, CreateDriverResult, L1CacheDriver, L2CacheDriver, CreateBusDriverResult, DynamoDBConfig, FileConfig, KyselyConfig, OrchidConfig } from 'bentocache/types';
|
|
3
|
+
import { MemoryConfig, CreateDriverResult, L1CacheDriver, L2CacheDriver, CreateBusDriverResult, DynamoDBConfig, FileConfig, RedisConfig, BusOptions, KyselyConfig, OrchidConfig, DatabaseConfig } from 'bentocache/types';
|
|
4
4
|
/**
|
|
5
5
|
* Different drivers supported by the cache module
|
|
6
6
|
*/
|
|
7
7
|
export declare const drivers: {
|
|
8
8
|
memory: (config?: MemoryConfig) => ConfigProvider<CreateDriverResult<L1CacheDriver>>;
|
|
9
|
-
redis: (config: {
|
|
9
|
+
redis: (config: Omit<RedisConfig, 'connection'> & {
|
|
10
10
|
connectionName?: keyof RedisConnections;
|
|
11
11
|
}) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
12
|
-
redisBus: (config: {
|
|
12
|
+
redisBus: (config: BusOptions & {
|
|
13
13
|
connectionName?: keyof RedisConnections;
|
|
14
14
|
}) => ConfigProvider<CreateBusDriverResult>;
|
|
15
|
-
database: (config?: {
|
|
15
|
+
database: (config?: DatabaseConfig & {
|
|
16
16
|
connectionName?: string;
|
|
17
17
|
}) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
18
18
|
dynamodb: (config: DynamoDBConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
package/build/src/store.d.ts
CHANGED
|
@@ -29,18 +29,5 @@ export declare class Store {
|
|
|
29
29
|
/**
|
|
30
30
|
* Create a config provider for the store
|
|
31
31
|
*/
|
|
32
|
-
entry(): ConfigProvider<
|
|
33
|
-
"__#117@#private": any;
|
|
34
|
-
useL1Layer(driver: CreateDriverResult<L1CacheDriver>): /*elided*/ any;
|
|
35
|
-
useL2Layer(driver: CreateDriverResult<L2CacheDriver>): /*elided*/ any;
|
|
36
|
-
useBus(bus: CreateBusDriverResult): /*elided*/ any;
|
|
37
|
-
readonly entry: {
|
|
38
|
-
options: RawCommonOptions & {
|
|
39
|
-
prefix?: string;
|
|
40
|
-
};
|
|
41
|
-
l1: CreateDriverResult<L1CacheDriver> | undefined;
|
|
42
|
-
l2: CreateDriverResult<L2CacheDriver> | undefined;
|
|
43
|
-
bus: CreateBusDriverResult | undefined;
|
|
44
|
-
};
|
|
45
|
-
}>;
|
|
32
|
+
entry(): ConfigProvider<import("bentocache").BentoStore>;
|
|
46
33
|
}
|
package/build/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * from 'bentocache/types'\n\nimport type { BentoCache, bentostore } from 'bentocache'\nimport type { RawBentoCacheOptions } from 'bentocache/types'\n\nimport type { store } from './store.js'\n\n/**\n * The options accepted by the cache module\n */\nexport type CacheOptions = Omit<RawBentoCacheOptions, 'logger' | 'emitter'>\n\n/**\n * Infer the stores from the user config\n */\nexport type InferStores<T extends { stores: Record<string, ReturnType<typeof store>> }> = {\n [K in keyof T['stores']]: any\n}\n\n/**\n * A list of known caches stores inferred from the user config\n * This interface must be extended in user-land\n */\nexport interface CacheStores {}\n\n/**\n * The cache service interface registered with the container\n */\nexport interface CacheService
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["/*\n * @adonisjs/cache\n *\n * (c) AdonisJS\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\n\nexport * from 'bentocache/types'\n\nimport type { BentoCache, bentostore } from 'bentocache'\nimport type { RawBentoCacheOptions } from 'bentocache/types'\n\nimport type { store } from './store.js'\n\n/**\n * The options accepted by the cache module\n */\nexport type CacheOptions = Omit<RawBentoCacheOptions, 'logger' | 'emitter'>\n\n/**\n * Infer the stores from the user config\n */\nexport type InferStores<T extends { stores: Record<string, ReturnType<typeof store>> }> = {\n [K in keyof T['stores']]: any\n}\n\n/**\n * A list of known caches stores inferred from the user config\n * This interface must be extended in user-land\n */\nexport interface CacheStores {}\n\n/**\n * The cache service interface registered with the container\n */\nexport interface CacheService extends BentoCache<\n CacheStores extends Record<string, ReturnType<typeof bentostore>> ? CacheStores : never\n> {}\n"],"mappings":";AASA,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/cache",
|
|
3
3
|
"description": "Official caching module for AdonisJS framework",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.6.0"
|
|
7
7
|
},
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@adonisjs/assembler": "^7.8.2",
|
|
42
|
-
"@adonisjs/core": "^6.
|
|
42
|
+
"@adonisjs/core": "^6.19.0",
|
|
43
43
|
"@adonisjs/eslint-config": "^2.1.0",
|
|
44
|
-
"@adonisjs/lucid": "^21.
|
|
44
|
+
"@adonisjs/lucid": "^21.7.0",
|
|
45
45
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
46
46
|
"@adonisjs/redis": "^9.2.0",
|
|
47
47
|
"@adonisjs/tsconfig": "^1.4.1",
|
|
@@ -51,28 +51,28 @@
|
|
|
51
51
|
"@japa/runner": "^4.2.0",
|
|
52
52
|
"@japa/snapshot": "^2.0.8",
|
|
53
53
|
"@release-it/conventional-changelog": "^10.0.1",
|
|
54
|
-
"@swc/core": "^1.
|
|
55
|
-
"@types/node": "~24.0.
|
|
56
|
-
"better-sqlite3": "^
|
|
54
|
+
"@swc/core": "^1.13.1",
|
|
55
|
+
"@types/node": "~24.0.15",
|
|
56
|
+
"better-sqlite3": "^12.2.0",
|
|
57
57
|
"c8": "^10.1.3",
|
|
58
58
|
"copyfiles": "^2.4.1",
|
|
59
59
|
"del-cli": "^6.0.0",
|
|
60
60
|
"edge.js": "^6.2.1",
|
|
61
|
-
"eslint": "^9.
|
|
61
|
+
"eslint": "^9.31.0",
|
|
62
62
|
"ioredis": "^5.6.1",
|
|
63
63
|
"knex": "^3.1.0",
|
|
64
|
-
"luxon": "^3.
|
|
65
|
-
"mysql2": "^3.14.
|
|
64
|
+
"luxon": "^3.7.1",
|
|
65
|
+
"mysql2": "^3.14.2",
|
|
66
66
|
"p-event": "^6.0.1",
|
|
67
|
-
"pg": "^8.16.
|
|
68
|
-
"prettier": "^3.
|
|
69
|
-
"release-it": "^19.0.
|
|
67
|
+
"pg": "^8.16.3",
|
|
68
|
+
"prettier": "^3.6.2",
|
|
69
|
+
"release-it": "^19.0.4",
|
|
70
70
|
"ts-node-maintained": "^10.9.5",
|
|
71
71
|
"tsup": "^8.5.0",
|
|
72
72
|
"typescript": "~5.8.3"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"bentocache": "^1.
|
|
75
|
+
"bentocache": "^1.5.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"@adonisjs/assembler": "^7.0.0",
|
|
@@ -151,7 +151,9 @@
|
|
|
151
151
|
"src/types.ts",
|
|
152
152
|
"providers/cache_provider.ts",
|
|
153
153
|
"services/main.ts",
|
|
154
|
-
"commands/cache_clear.ts"
|
|
154
|
+
"commands/cache_clear.ts",
|
|
155
|
+
"commands/cache_delete.ts",
|
|
156
|
+
"commands/cache_prune.ts"
|
|
155
157
|
],
|
|
156
158
|
"outDir": "./build",
|
|
157
159
|
"clean": true,
|
|
@@ -160,5 +162,5 @@
|
|
|
160
162
|
"sourcemap": true,
|
|
161
163
|
"target": "esnext"
|
|
162
164
|
},
|
|
163
|
-
"packageManager": "pnpm@10.
|
|
165
|
+
"packageManager": "pnpm@10.13.1"
|
|
164
166
|
}
|