@adonisjs/cache 1.0.0-4 → 1.0.0-6
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/commands.json +1 -1
- package/build/index.js +216 -13
- package/build/index.js.map +1 -0
- package/build/metafile-esm.json +1 -0
- package/build/providers/cache_provider.d.ts +1 -5
- package/build/providers/cache_provider.js +80 -63
- package/build/providers/cache_provider.js.map +1 -0
- package/build/services/main.js +8 -15
- package/build/services/main.js.map +1 -0
- package/build/src/bindings/edge.d.ts +2 -0
- package/build/src/debug.d.ts +2 -0
- package/build/src/drivers.d.ts +4 -2
- package/build/src/store.d.ts +5 -5
- package/build/src/types.d.ts +1 -0
- package/build/src/types.js +3 -9
- package/build/src/types.js.map +1 -0
- package/build/stubs/config.stub +1 -1
- package/package.json +65 -42
- package/build/commands/cache_clear.js +0 -77
- package/build/configure.js +0 -62
- package/build/src/bindings/repl.js +0 -28
- package/build/src/define_config.js +0 -14
- package/build/src/drivers.js +0 -103
- package/build/src/store.js +0 -64
- package/build/stubs/main.js +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commands":[
|
|
1
|
+
{"commands":[],"version":1}
|
package/build/index.js
CHANGED
|
@@ -1,13 +1,216 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
// index.ts
|
|
2
|
+
import { errors } from "bentocache";
|
|
3
|
+
|
|
4
|
+
// stubs/main.ts
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
var stubsRoot = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
|
|
9
|
+
// configure.ts
|
|
10
|
+
var DRIVERS_INFO = {
|
|
11
|
+
file: {},
|
|
12
|
+
memory: {},
|
|
13
|
+
redis: {},
|
|
14
|
+
database: {},
|
|
15
|
+
dynamodb: {
|
|
16
|
+
envValidations: {
|
|
17
|
+
AWS_ACCESS_KEY_ID: `Env.schema.string()`,
|
|
18
|
+
AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,
|
|
19
|
+
AWS_REGION: `Env.schema.string()`,
|
|
20
|
+
DYNAMODB_ENDPOINT: `Env.schema.string()`
|
|
21
|
+
},
|
|
22
|
+
envVars: {
|
|
23
|
+
AWS_ACCESS_KEY_ID: "",
|
|
24
|
+
AWS_SECRET_ACCESS_KEY: "",
|
|
25
|
+
AWS_REGION: "",
|
|
26
|
+
DYNAMODB_ENDPOINT: ""
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
async function configure(command) {
|
|
31
|
+
const driver = await command.prompt.choice(
|
|
32
|
+
"Select the cache driver you plan to use",
|
|
33
|
+
["redis", "file", "memory", "database", "dynamodb"],
|
|
34
|
+
{
|
|
35
|
+
hint: "You can always change it later"
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
const { envVars, envValidations } = DRIVERS_INFO[driver];
|
|
39
|
+
const codemods = await command.createCodemods();
|
|
40
|
+
await codemods.updateRcFile((rcFile) => {
|
|
41
|
+
rcFile.addProvider("@adonisjs/cache/cache_provider").addCommand("@adonisjs/cache/commands");
|
|
42
|
+
});
|
|
43
|
+
if (envVars) {
|
|
44
|
+
codemods.defineEnvVariables(envVars);
|
|
45
|
+
}
|
|
46
|
+
if (envValidations) {
|
|
47
|
+
codemods.defineEnvValidations({ variables: envValidations });
|
|
48
|
+
}
|
|
49
|
+
await codemods.makeUsingStub(stubsRoot, "config.stub", { driver });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/define_config.ts
|
|
53
|
+
function defineConfig(config) {
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/drivers.ts
|
|
58
|
+
import { configProvider } from "@adonisjs/core";
|
|
59
|
+
var drivers = {
|
|
60
|
+
/**
|
|
61
|
+
* Redis driver for L2 layer
|
|
62
|
+
* You must install @adonisjs/redis to use this driver
|
|
63
|
+
*/
|
|
64
|
+
redis(config) {
|
|
65
|
+
return configProvider.create(async (app) => {
|
|
66
|
+
const redis = await app.container.make("redis");
|
|
67
|
+
const { redisDriver } = await import("bentocache/drivers/redis");
|
|
68
|
+
const redisConnection = redis.connection(config.connectionName);
|
|
69
|
+
return redisDriver({ connection: redisConnection.ioConnection });
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
/**
|
|
73
|
+
* Redis driver for the sync bus
|
|
74
|
+
* You must install @adonisjs/redis to use this driver
|
|
75
|
+
*/
|
|
76
|
+
redisBus(config) {
|
|
77
|
+
return configProvider.create(async (app) => {
|
|
78
|
+
const redis = await app.container.make("redis");
|
|
79
|
+
const { redisBusDriver } = await import("bentocache/drivers/redis");
|
|
80
|
+
const redisConnection = redis.connection(config.connectionName);
|
|
81
|
+
return redisBusDriver({ connection: redisConnection.ioConnection.options });
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Memory driver for L1 layer
|
|
86
|
+
*/
|
|
87
|
+
memory(config) {
|
|
88
|
+
return configProvider.create(async () => {
|
|
89
|
+
const { memoryDriver } = await import("bentocache/drivers/memory");
|
|
90
|
+
return memoryDriver(config);
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Database driver for L2 layer
|
|
95
|
+
* You must install @adonisjs/lucid to use this driver
|
|
96
|
+
*/
|
|
97
|
+
database(config) {
|
|
98
|
+
return configProvider.create(async (app) => {
|
|
99
|
+
const db = await app.container.make("lucid.db");
|
|
100
|
+
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
101
|
+
const dialect = db.connection(connectionName).dialect.name;
|
|
102
|
+
const supportedDialects = ["pg", "postgres", "mysql", "better-sqlite3", "sqlite3"];
|
|
103
|
+
if (!supportedDialects.includes(dialect)) {
|
|
104
|
+
throw new Error(`Unsupported dialect "${dialect}"`);
|
|
105
|
+
}
|
|
106
|
+
const rawConnection = db.getRawConnection(connectionName);
|
|
107
|
+
if (!rawConnection?.connection?.client) {
|
|
108
|
+
throw new Error(`Unable to get raw connection for "${connectionName}"`);
|
|
109
|
+
}
|
|
110
|
+
const { default: knex } = await import("knex");
|
|
111
|
+
const knexClient = knex({
|
|
112
|
+
...rawConnection.config,
|
|
113
|
+
client: ["postgres", "pg"].includes(dialect) ? "pg" : dialect
|
|
114
|
+
});
|
|
115
|
+
const { knexDriver } = await import("bentocache/drivers/knex");
|
|
116
|
+
return knexDriver({ connection: knexClient });
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
/**
|
|
120
|
+
* DynamoDB driver for L2 layer
|
|
121
|
+
* You must install @aws-sdk/client-dynamodb to use this driver
|
|
122
|
+
*/
|
|
123
|
+
dynamodb(config) {
|
|
124
|
+
return configProvider.create(async () => {
|
|
125
|
+
const { dynamoDbDriver } = await import("bentocache/drivers/dynamodb");
|
|
126
|
+
return dynamoDbDriver(config);
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* File driver for L2 layer
|
|
131
|
+
*/
|
|
132
|
+
file(config) {
|
|
133
|
+
return configProvider.create(async () => {
|
|
134
|
+
const { fileDriver } = await import("bentocache/drivers/file");
|
|
135
|
+
return fileDriver(config);
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Kysely driver for L2 layer
|
|
140
|
+
*/
|
|
141
|
+
kysely(config) {
|
|
142
|
+
return configProvider.create(async () => {
|
|
143
|
+
const { kyselyDriver } = await import("bentocache/drivers/kysely");
|
|
144
|
+
return kyselyDriver(config);
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* Orchid driver for L2 layer
|
|
149
|
+
*/
|
|
150
|
+
orchid(config) {
|
|
151
|
+
return configProvider.create(async () => {
|
|
152
|
+
const { orchidDriver } = await import("bentocache/drivers/orchid");
|
|
153
|
+
return orchidDriver(config);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/store.ts
|
|
159
|
+
import { bentostore } from "bentocache";
|
|
160
|
+
import { configProvider as configProvider2 } from "@adonisjs/core";
|
|
161
|
+
function store(options) {
|
|
162
|
+
return new Store(options);
|
|
163
|
+
}
|
|
164
|
+
var Store = class {
|
|
165
|
+
#baseOptions = {};
|
|
166
|
+
#l1;
|
|
167
|
+
#l2;
|
|
168
|
+
#bus;
|
|
169
|
+
constructor(baseOptions = {}) {
|
|
170
|
+
this.#baseOptions = baseOptions;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Add a L1 layer to your store. This is usually a memory driver
|
|
174
|
+
* for fast access purposes.
|
|
175
|
+
*/
|
|
176
|
+
useL1Layer(driver) {
|
|
177
|
+
this.#l1 = driver;
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Add a L2 layer to your store. This is usually something
|
|
182
|
+
* distributed like Redis, DynamoDB, Sql database, etc.
|
|
183
|
+
*/
|
|
184
|
+
useL2Layer(driver) {
|
|
185
|
+
this.#l2 = driver;
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Add a bus to your store. It will be used to synchronize L1 layers between
|
|
190
|
+
* different instances of your application.
|
|
191
|
+
*/
|
|
192
|
+
useBus(bus) {
|
|
193
|
+
this.#bus = bus;
|
|
194
|
+
return this;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Create a config provider for the store
|
|
198
|
+
*/
|
|
199
|
+
entry() {
|
|
200
|
+
return configProvider2.create(async (app) => {
|
|
201
|
+
const storeInstance = bentostore(this.#baseOptions);
|
|
202
|
+
if (this.#l1) storeInstance.useL1Layer(await this.#l1?.resolver(app));
|
|
203
|
+
if (this.#l2) storeInstance.useL2Layer(await this.#l2?.resolver(app));
|
|
204
|
+
if (this.#bus) storeInstance.useBus(await this.#bus?.resolver(app));
|
|
205
|
+
return storeInstance;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
export {
|
|
210
|
+
configure,
|
|
211
|
+
defineConfig,
|
|
212
|
+
drivers,
|
|
213
|
+
errors,
|
|
214
|
+
store
|
|
215
|
+
};
|
|
216
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts","../stubs/main.ts","../configure.ts","../src/define_config.ts","../src/drivers.ts","../src/store.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 { errors } from 'bentocache'\nexport { configure } from './configure.js'\n\nexport { defineConfig } from './src/define_config.js'\nexport { drivers } from './src/drivers.js'\nexport { store } from './src/store.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 { 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', 'memory', '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 memory: {},\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', 'memory', 'database', 'dynamodb'],\n {\n hint: 'You can always change it later',\n }\n )\n const { envVars, envValidations } = DRIVERS_INFO[driver]\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 /**\n * Define environment variables\n */\n if (envVars) {\n codemods.defineEnvVariables(envVars)\n }\n\n /**\n * Define environment validations\n */\n if (envValidations) {\n 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 DialectName,\n CreateBusDriverResult,\n DynamoDBConfig,\n FileConfig,\n KyselyConfig,\n OrchidConfig,\n} from 'bentocache/types'\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 dialect = db.connection(connectionName).dialect.name\n\n /**\n * We only support pg, mysql, better-sqlite3 and sqlite3 dialects for now\n */\n const supportedDialects = ['pg', 'postgres', 'mysql', 'better-sqlite3', 'sqlite3']\n if (!supportedDialects.includes(dialect)) {\n throw new Error(`Unsupported dialect \"${dialect}\"`)\n }\n\n /**\n * Get the knex connection for the given connection name\n */\n const rawConnection = db.getRawConnection(connectionName)\n if (!rawConnection?.connection?.client) {\n throw new Error(`Unable to get raw connection for \"${connectionName}\"`)\n }\n\n /**\n * Create the driver\n */\n const { default: knex } = await import('knex')\n const knexClient = knex({\n ...rawConnection.config,\n client: ['postgres', 'pg'].includes(dialect) ? 'pg' : (dialect as DialectName),\n })\n\n const { knexDriver } = await import('bentocache/drivers/knex')\n return knexDriver({ connection: knexClient })\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","/*\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"],"mappings":";AASA,SAAS,cAAc;;;ACAvB,SAAS,eAAe;AACxB,SAAS,qBAAqB;AAEvB,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;;;ACE/D,IAAM,eAKF;AAAA,EACF,MAAM,CAAC;AAAA,EACP,QAAQ,CAAC;AAAA,EACT,OAAO,CAAC;AAAA,EACR,UAAU,CAAC;AAAA,EACX,UAAU;AAAA,IACR,gBAAgB;AAAA,MACd,mBAAmB;AAAA,MACnB,uBAAuB;AAAA,MAC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,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ;AACN,WAAOA,gBAAe,OAAO,OAAO,QAAQ;AAC1C,YAAM,gBAAgB,WAAW,KAAK,YAAY;AAElD,UAAI,KAAK,IAAK,eAAc,WAAW,MAAM,KAAK,KAAK,SAAS,GAAG,CAAC;AACpE,UAAI,KAAK,IAAK,eAAc,WAAW,MAAM,KAAK,KAAK,SAAS,GAAG,CAAC;AACpE,UAAI,KAAK,KAAM,eAAc,OAAO,MAAM,KAAK,MAAM,SAAS,GAAG,CAAC;AAElE,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;","names":["configProvider"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"inputs":{"stubs/main.ts":{"bytes":319,"imports":[{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":1904,"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":5144,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"bentocache/types","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":"knex","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"},"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"},"index.ts":{"bytes":392,"imports":[{"path":"bentocache","kind":"import-statement","external":true},{"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"},{"path":"src/store.ts","kind":"import-statement","original":"./src/store.js"}],"format":"esm"},"src/bindings/repl.ts":{"bytes":910,"imports":[],"format":"esm"},"src/debug.ts":{"bytes":256,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"src/bindings/edge.ts":{"bytes":474,"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":2802,"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":1047,"imports":[{"path":"bentocache/types","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"build/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":14701},"build/index.js":{"imports":[{"path":"bentocache","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:url","kind":"import-statement","external":true},{"path":"@adonisjs/core","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":"knex","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},{"path":"bentocache","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true}],"exports":["configure","defineConfig","drivers","errors","store"],"entryPoint":"index.ts","inputs":{"index.ts":{"bytesInOutput":37},"stubs/main.ts":{"bytesInOutput":136},"configure.ts":{"bytesInOutput":1182},"src/define_config.ts":{"bytesInOutput":51},"src/drivers.ts":{"bytesInOutput":3338},"src/store.ts":{"bytesInOutput":1324}},"bytes":6246},"build/providers/cache_provider.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":6302},"build/providers/cache_provider.js":{"imports":[{"path":"node: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":86},"src/bindings/edge.ts":{"bytesInOutput":211},"providers/cache_provider.ts":{"bytesInOutput":1403}},"bytes":2280},"build/services/main.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":716},"build/services/main.js":{"imports":[{"path":"@adonisjs/core/services/app","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"services/main.ts","inputs":{"services/main.ts":{"bytesInOutput":146}},"bytes":197},"build/src/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1214},"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}}}
|
|
@@ -9,7 +9,7 @@ declare module '@adonisjs/core/types' {
|
|
|
9
9
|
* Adding cache type to the application container
|
|
10
10
|
*/
|
|
11
11
|
interface ContainerBindings {
|
|
12
|
-
cache: CacheService;
|
|
12
|
+
'cache.manager': CacheService;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Add cache events to the application events list
|
|
@@ -35,8 +35,4 @@ export default class CacheProvider {
|
|
|
35
35
|
* Register bindings
|
|
36
36
|
*/
|
|
37
37
|
register(): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Disconnect all cache stores when shutting down the app
|
|
40
|
-
*/
|
|
41
|
-
shutdown(): Promise<void>;
|
|
42
38
|
}
|
|
@@ -1,64 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
app;
|
|
15
|
-
constructor(app) {
|
|
16
|
-
this.app = app;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Register the cache manager to the container
|
|
20
|
-
*/
|
|
21
|
-
async #registerCacheManager() {
|
|
22
|
-
const cacheConfig = this.app.config.get('cache');
|
|
23
|
-
this.app.container.singleton('cache', async () => {
|
|
24
|
-
const { BentoCache } = await import('bentocache');
|
|
25
|
-
const emitter = await this.app.container.make('emitter');
|
|
26
|
-
/**
|
|
27
|
-
* Resolve all store config providers
|
|
28
|
-
*/
|
|
29
|
-
const resolvedStores = Object.entries(cacheConfig.stores).map(async ([name, store]) => {
|
|
30
|
-
return [name, await store.entry().resolver(this.app)];
|
|
31
|
-
});
|
|
32
|
-
return new BentoCache({
|
|
33
|
-
...cacheConfig,
|
|
34
|
-
emitter: emitter,
|
|
35
|
-
default: cacheConfig.default,
|
|
36
|
-
stores: Object.fromEntries(await Promise.all(resolvedStores)),
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Register REPL bindings
|
|
42
|
-
*/
|
|
43
|
-
async #registerReplBindings() {
|
|
44
|
-
if (this.app.getEnvironment() !== 'repl') {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const repl = await this.app.container.make('repl');
|
|
48
|
-
defineReplBindings(this.app, repl);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Register bindings
|
|
52
|
-
*/
|
|
53
|
-
async register() {
|
|
54
|
-
this.#registerCacheManager();
|
|
55
|
-
this.#registerReplBindings();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Disconnect all cache stores when shutting down the app
|
|
59
|
-
*/
|
|
60
|
-
async shutdown() {
|
|
61
|
-
const cache = await this.app.container.make('cache');
|
|
62
|
-
await cache.disconnectAll().catch(() => { });
|
|
63
|
-
}
|
|
1
|
+
// src/bindings/repl.ts
|
|
2
|
+
function setupReplState(repl, key, value) {
|
|
3
|
+
repl.server.context[key] = value;
|
|
4
|
+
repl.notify(
|
|
5
|
+
`Loaded ${key} module. You can access it using the "${repl.colors.underline(key)}" variable`
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
function defineReplBindings(app, Repl) {
|
|
9
|
+
Repl.addMethod(
|
|
10
|
+
"loadCache",
|
|
11
|
+
async (repl) => setupReplState(repl, "cache", await app.container.make("cache.manager")),
|
|
12
|
+
{ description: 'Load cache provider to the "cache" property' }
|
|
13
|
+
);
|
|
64
14
|
}
|
|
15
|
+
|
|
16
|
+
// src/debug.ts
|
|
17
|
+
import { debuglog } from "node:util";
|
|
18
|
+
var debug_default = debuglog("adonisjs:cache");
|
|
19
|
+
|
|
20
|
+
// src/bindings/edge.ts
|
|
21
|
+
async function registerViewBindings(manager) {
|
|
22
|
+
const edge = await import("edge.js");
|
|
23
|
+
debug_default("detected edge installation. Registering cache global helpers");
|
|
24
|
+
edge.default.global("cache", manager);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// providers/cache_provider.ts
|
|
28
|
+
var CacheProvider = class {
|
|
29
|
+
constructor(app) {
|
|
30
|
+
this.app = app;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Register the cache manager to the container
|
|
34
|
+
*/
|
|
35
|
+
async #registerCacheManager() {
|
|
36
|
+
const cacheConfig = this.app.config.get("cache");
|
|
37
|
+
this.app.container.singleton("cache.manager", async () => {
|
|
38
|
+
const { BentoCache } = await import("bentocache");
|
|
39
|
+
const emitter = await this.app.container.make("emitter");
|
|
40
|
+
const resolvedStores = Object.entries(cacheConfig.stores).map(async ([name, store]) => {
|
|
41
|
+
return [name, await store.entry().resolver(this.app)];
|
|
42
|
+
});
|
|
43
|
+
return new BentoCache({
|
|
44
|
+
...cacheConfig,
|
|
45
|
+
emitter,
|
|
46
|
+
default: cacheConfig.default,
|
|
47
|
+
stores: Object.fromEntries(await Promise.all(resolvedStores))
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Register REPL bindings
|
|
53
|
+
*/
|
|
54
|
+
async #registerReplBindings() {
|
|
55
|
+
if (this.app.getEnvironment() !== "repl") {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const repl = await this.app.container.make("repl");
|
|
59
|
+
defineReplBindings(this.app, repl);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Register edge bindings
|
|
63
|
+
*/
|
|
64
|
+
async #registerEdgeBindings() {
|
|
65
|
+
if (!this.app.usingEdgeJS) return;
|
|
66
|
+
const manager = await this.app.container.make("cache.manager");
|
|
67
|
+
registerViewBindings(manager);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Register bindings
|
|
71
|
+
*/
|
|
72
|
+
async register() {
|
|
73
|
+
this.#registerCacheManager();
|
|
74
|
+
this.#registerReplBindings();
|
|
75
|
+
this.#registerEdgeBindings();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export {
|
|
79
|
+
CacheProvider as default
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=cache_provider.js.map
|
|
@@ -0,0 +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 async #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 registerViewBindings(manager)\n }\n\n /**\n * Register bindings\n */\n async register() {\n this.#registerCacheManager()\n this.#registerReplBindings()\n this.#registerEdgeBindings()\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,EACl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AACjD,uBAAmB,KAAK,KAAK,IAAI;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,wBAAwB;AAC5B,QAAI,CAAC,KAAK,IAAI,YAAa;AAE3B,UAAM,UAAU,MAAM,KAAK,IAAI,UAAU,KAAK,eAAe;AAC7D,yBAAqB,OAAO;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAW;AACf,SAAK,sBAAsB;AAC3B,SAAK,sBAAsB;AAC3B,SAAK,sBAAsB;AAAA,EAC7B;AACF;","names":[]}
|
package/build/services/main.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import app from '@adonisjs/core/services/app';
|
|
10
|
-
let cache;
|
|
11
|
-
/**
|
|
12
|
-
* Returns a singleton instance of the Cache manager
|
|
13
|
-
*/
|
|
1
|
+
// services/main.ts
|
|
2
|
+
import app from "@adonisjs/core/services/app";
|
|
3
|
+
var cache;
|
|
14
4
|
await app.booted(async () => {
|
|
15
|
-
|
|
5
|
+
cache = await app.container.make("cache.manager");
|
|
16
6
|
});
|
|
17
|
-
export {
|
|
7
|
+
export {
|
|
8
|
+
cache as default
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../services/main.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 { CacheService } from '../src/types.js'\nimport app from '@adonisjs/core/services/app'\n\nlet cache: CacheService\n\n/**\n * Returns a singleton instance of the Cache manager\n */\nawait app.booted(async () => {\n cache = await app.container.make('cache.manager')\n})\n\nexport { cache as default }\n"],"mappings":";AAUA,OAAO,SAAS;AAEhB,IAAI;AAKJ,MAAM,IAAI,OAAO,YAAY;AAC3B,UAAQ,MAAM,IAAI,UAAU,KAAK,eAAe;AAClD,CAAC;","names":[]}
|
package/build/src/drivers.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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 } from 'bentocache/types';
|
|
3
|
+
import { MemoryConfig, CreateDriverResult, L1CacheDriver, L2CacheDriver, CreateBusDriverResult, DynamoDBConfig, FileConfig, KyselyConfig, OrchidConfig } from 'bentocache/types';
|
|
4
4
|
/**
|
|
5
5
|
* Different drivers supported by the cache module
|
|
6
6
|
*/
|
|
7
7
|
export declare const drivers: {
|
|
8
|
-
memory: (config
|
|
8
|
+
memory: (config?: MemoryConfig) => ConfigProvider<CreateDriverResult<L1CacheDriver>>;
|
|
9
9
|
redis: (config: {
|
|
10
10
|
connectionName?: keyof RedisConnections;
|
|
11
11
|
}) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
@@ -17,4 +17,6 @@ export declare const drivers: {
|
|
|
17
17
|
}) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
18
18
|
dynamodb: (config: DynamoDBConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
19
19
|
file: (config: FileConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
20
|
+
kysely: (config: KyselyConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
21
|
+
orchid: (config: OrchidConfig) => ConfigProvider<CreateDriverResult<L2CacheDriver>>;
|
|
20
22
|
};
|
package/build/src/store.d.ts
CHANGED
|
@@ -30,13 +30,13 @@ export declare class Store {
|
|
|
30
30
|
* Create a config provider for the store
|
|
31
31
|
*/
|
|
32
32
|
entry(): ConfigProvider<{
|
|
33
|
-
"__#
|
|
34
|
-
useL1Layer(driver: CreateDriverResult<L1CacheDriver>): any;
|
|
35
|
-
useL2Layer(driver: CreateDriverResult<L2CacheDriver>): any;
|
|
36
|
-
useBus(bus: CreateBusDriverResult): any;
|
|
33
|
+
"__#116@#private": any;
|
|
34
|
+
useL1Layer(driver: CreateDriverResult<L1CacheDriver>): /*elided*/ any;
|
|
35
|
+
useL2Layer(driver: CreateDriverResult<L2CacheDriver>): /*elided*/ any;
|
|
36
|
+
useBus(bus: CreateBusDriverResult): /*elided*/ any;
|
|
37
37
|
readonly entry: {
|
|
38
38
|
options: RawCommonOptions & {
|
|
39
|
-
prefix?: string
|
|
39
|
+
prefix?: string;
|
|
40
40
|
};
|
|
41
41
|
l1: CreateDriverResult<L1CacheDriver> | undefined;
|
|
42
42
|
l2: CreateDriverResult<L2CacheDriver> | undefined;
|
package/build/src/types.d.ts
CHANGED
package/build/src/types.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
1
|
+
// src/types.ts
|
|
2
|
+
export * from "bentocache/types";
|
|
3
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +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\n extends BentoCache<\n CacheStores extends Record<string, ReturnType<typeof bentostore>> ? CacheStores : never\n > {}\n"],"mappings":";AASA,cAAc;","names":[]}
|
package/build/stubs/config.stub
CHANGED
|
@@ -16,7 +16,7 @@ const cacheConfig = defineConfig({
|
|
|
16
16
|
}))
|
|
17
17
|
{{#elif driver === 'redis'}}
|
|
18
18
|
redis: store().useL2Layer(drivers.redis({
|
|
19
|
-
connectionName: '
|
|
19
|
+
connectionName: 'main',
|
|
20
20
|
}))
|
|
21
21
|
{{#elif driver === 'memory'}}
|
|
22
22
|
memory: store().useL1Layer(drivers.memory())
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/cache",
|
|
3
3
|
"description": "Official caching module for AdonisJS framework",
|
|
4
|
-
"version": "1.0.0-
|
|
4
|
+
"version": "1.0.0-6",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=20.6.0"
|
|
7
7
|
},
|
|
8
8
|
"main": "build/index.js",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"files": [
|
|
11
11
|
"build",
|
|
12
12
|
"!build/bin",
|
|
13
|
-
"!build/tests"
|
|
14
|
-
"!build/test_helpers"
|
|
13
|
+
"!build/tests"
|
|
15
14
|
],
|
|
16
15
|
"exports": {
|
|
17
16
|
".": "./build/index.js",
|
|
@@ -26,54 +25,58 @@
|
|
|
26
25
|
"copy:templates": "copyfiles \"stubs/**/*.stub\" build",
|
|
27
26
|
"typecheck": "tsc --noEmit",
|
|
28
27
|
"index:commands": "adonis-kit index build/commands",
|
|
29
|
-
"lint": "eslint
|
|
28
|
+
"lint": "eslint",
|
|
30
29
|
"format": "prettier --write .",
|
|
31
|
-
"quick:test": "node --
|
|
30
|
+
"quick:test": "node --import=ts-node-maintained/register/esm bin/test.ts",
|
|
32
31
|
"pretest": "npm run lint",
|
|
33
32
|
"test": "c8 npm run quick:test",
|
|
34
33
|
"prebuild": "npm run lint && npm run clean",
|
|
35
|
-
"build": "tsc",
|
|
34
|
+
"build": "tsup-node --metafile && tsc --emitDeclarationOnly --declaration",
|
|
36
35
|
"postbuild": "npm run copy:templates && npm run index:commands",
|
|
37
36
|
"release": "npx release-it",
|
|
38
37
|
"version": "npm run build",
|
|
39
38
|
"prepublishOnly": "npm run build"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
|
-
"@adonisjs/assembler": "^7.
|
|
43
|
-
"@adonisjs/core": "^6.
|
|
44
|
-
"@adonisjs/eslint-config": "^
|
|
45
|
-
"@adonisjs/lucid": "21.
|
|
46
|
-
"@adonisjs/prettier-config": "^1.
|
|
47
|
-
"@adonisjs/redis": "
|
|
48
|
-
"@adonisjs/tsconfig": "^1.
|
|
49
|
-
"@japa/assert": "
|
|
41
|
+
"@adonisjs/assembler": "^7.8.2",
|
|
42
|
+
"@adonisjs/core": "^6.17.0",
|
|
43
|
+
"@adonisjs/eslint-config": "^2.0.0-beta.7",
|
|
44
|
+
"@adonisjs/lucid": "21.6.0",
|
|
45
|
+
"@adonisjs/prettier-config": "^1.4.0",
|
|
46
|
+
"@adonisjs/redis": "9.1.0",
|
|
47
|
+
"@adonisjs/tsconfig": "^1.4.0",
|
|
48
|
+
"@japa/assert": "4.0.0",
|
|
50
49
|
"@japa/expect-type": "^2.0.2",
|
|
51
|
-
"@japa/file-system": "^2.3.
|
|
50
|
+
"@japa/file-system": "^2.3.1",
|
|
52
51
|
"@japa/runner": "^3.1.4",
|
|
53
|
-
"@japa/snapshot": "^2.0.
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"
|
|
57
|
-
"
|
|
52
|
+
"@japa/snapshot": "^2.0.7",
|
|
53
|
+
"@release-it/conventional-changelog": "^9.0.4",
|
|
54
|
+
"@swc/core": "^1.10.4",
|
|
55
|
+
"@types/node": "^22.10.5",
|
|
56
|
+
"better-sqlite3": "^11.7.2",
|
|
57
|
+
"c8": "^10.1.3",
|
|
58
58
|
"copyfiles": "^2.4.1",
|
|
59
|
-
"del-cli": "^
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
59
|
+
"del-cli": "^6.0.0",
|
|
60
|
+
"edge.js": "^6.2.0",
|
|
61
|
+
"eslint": "^9.17.0",
|
|
62
|
+
"ioredis": "^5.4.2",
|
|
63
|
+
"knex": "^3.1.0",
|
|
64
|
+
"luxon": "^3.5.0",
|
|
63
65
|
"p-event": "^6.0.1",
|
|
64
|
-
"prettier": "^3.
|
|
65
|
-
"release-it": "^17.
|
|
66
|
-
"ts-node": "^10.9.
|
|
67
|
-
"
|
|
66
|
+
"prettier": "^3.4.2",
|
|
67
|
+
"release-it": "^17.11.0",
|
|
68
|
+
"ts-node-maintained": "^10.9.4",
|
|
69
|
+
"tsup": "^8.3.5",
|
|
70
|
+
"typescript": "~5.7.2"
|
|
68
71
|
},
|
|
69
72
|
"dependencies": {
|
|
70
|
-
"bentocache": "1.0.0-beta.
|
|
73
|
+
"bentocache": "1.0.0-beta.11"
|
|
71
74
|
},
|
|
72
75
|
"peerDependencies": {
|
|
73
76
|
"@adonisjs/assembler": "^7.0.0",
|
|
74
77
|
"@adonisjs/core": "^6.2.0",
|
|
75
78
|
"@adonisjs/lucid": "^20.0.0 || ^21.0.0",
|
|
76
|
-
"@adonisjs/redis": "^8.0.0"
|
|
79
|
+
"@adonisjs/redis": "^8.0.0 || ^9.0.0"
|
|
77
80
|
},
|
|
78
81
|
"peerDependenciesMeta": {
|
|
79
82
|
"@adonisjs/redis": {
|
|
@@ -91,24 +94,29 @@
|
|
|
91
94
|
"caching",
|
|
92
95
|
"bentocache"
|
|
93
96
|
],
|
|
94
|
-
"eslintConfig": {
|
|
95
|
-
"extends": "@adonisjs/eslint-config/package"
|
|
96
|
-
},
|
|
97
97
|
"prettier": "@adonisjs/prettier-config",
|
|
98
|
-
"publishConfig": {
|
|
99
|
-
"access": "public",
|
|
100
|
-
"tag": "latest"
|
|
101
|
-
},
|
|
102
98
|
"release-it": {
|
|
103
99
|
"git": {
|
|
100
|
+
"requireCleanWorkingDir": true,
|
|
101
|
+
"requireUpstream": true,
|
|
104
102
|
"commitMessage": "chore(release): ${version}",
|
|
105
103
|
"tagAnnotation": "v${version}",
|
|
104
|
+
"push": true,
|
|
106
105
|
"tagName": "v${version}"
|
|
107
106
|
},
|
|
108
107
|
"github": {
|
|
109
|
-
"release": true
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
"release": true
|
|
109
|
+
},
|
|
110
|
+
"npm": {
|
|
111
|
+
"publish": true,
|
|
112
|
+
"skipChecks": true
|
|
113
|
+
},
|
|
114
|
+
"plugins": {
|
|
115
|
+
"@release-it/conventional-changelog": {
|
|
116
|
+
"preset": {
|
|
117
|
+
"name": "angular"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
112
120
|
}
|
|
113
121
|
},
|
|
114
122
|
"c8": {
|
|
@@ -119,5 +127,20 @@
|
|
|
119
127
|
"exclude": [
|
|
120
128
|
"tests/**"
|
|
121
129
|
]
|
|
122
|
-
}
|
|
130
|
+
},
|
|
131
|
+
"tsup": {
|
|
132
|
+
"entry": [
|
|
133
|
+
"index.ts",
|
|
134
|
+
"src/types.ts",
|
|
135
|
+
"providers/cache_provider.ts",
|
|
136
|
+
"services/main.ts"
|
|
137
|
+
],
|
|
138
|
+
"outDir": "./build",
|
|
139
|
+
"clean": true,
|
|
140
|
+
"format": "esm",
|
|
141
|
+
"dts": false,
|
|
142
|
+
"sourcemap": true,
|
|
143
|
+
"target": "esnext"
|
|
144
|
+
},
|
|
145
|
+
"packageManager": "pnpm@9.15.2"
|
|
123
146
|
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
10
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
11
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
12
|
-
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;
|
|
13
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
|
-
};
|
|
15
|
-
import { BaseCommand, flags } from '@adonisjs/core/ace';
|
|
16
|
-
export default class CacheClear extends BaseCommand {
|
|
17
|
-
static commandName = 'cache:clear';
|
|
18
|
-
static description = 'Clear the application cache';
|
|
19
|
-
static options = {
|
|
20
|
-
startApp: true,
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Prompts to take consent when clearing the cache in production
|
|
24
|
-
*/
|
|
25
|
-
async #takeProductionConsent() {
|
|
26
|
-
const question = 'You are in production environment. Want to continue clearing the cache?';
|
|
27
|
-
try {
|
|
28
|
-
return await this.prompt.confirm(question);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Check if the given cache exist
|
|
36
|
-
*/
|
|
37
|
-
#cacheExists(cache, cacheName) {
|
|
38
|
-
try {
|
|
39
|
-
cache.use(cacheName);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Handle command
|
|
48
|
-
*/
|
|
49
|
-
async run() {
|
|
50
|
-
const cache = await this.app.container.make('cache');
|
|
51
|
-
this.store = this.store || cache.defaultStoreName;
|
|
52
|
-
/**
|
|
53
|
-
* Exit if cache store doesn't exists
|
|
54
|
-
*/
|
|
55
|
-
if (!this.#cacheExists(cache, this.store)) {
|
|
56
|
-
this.logger.error(`"${this.store}" is not a valid cache store. Double check config/cache.ts file`);
|
|
57
|
-
this.exitCode = 1;
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Take consent when clearing the cache in production
|
|
62
|
-
*/
|
|
63
|
-
if (this.app.inProduction) {
|
|
64
|
-
const shouldClear = await this.#takeProductionConsent();
|
|
65
|
-
if (!shouldClear)
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Finally clear the cache
|
|
70
|
-
*/
|
|
71
|
-
await cache.use(this.store).clear();
|
|
72
|
-
this.logger.success(`Cleared "${this.store}" cache successfully`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
__decorate([
|
|
76
|
-
flags.string({ description: 'Define a custom cache store to clear', alias: 's' })
|
|
77
|
-
], CacheClear.prototype, "store", void 0);
|
package/build/configure.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { stubsRoot } from './stubs/main.js';
|
|
10
|
-
const DRIVERS = ['redis', 'file', 'memory', 'database', 'dynamodb'];
|
|
11
|
-
const DRIVERS_INFO = {
|
|
12
|
-
file: {},
|
|
13
|
-
memory: {},
|
|
14
|
-
redis: {},
|
|
15
|
-
database: {},
|
|
16
|
-
dynamodb: {
|
|
17
|
-
envValidations: {
|
|
18
|
-
AWS_ACCESS_KEY_ID: `Env.schema.string()`,
|
|
19
|
-
AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,
|
|
20
|
-
AWS_REGION: `Env.schema.string()`,
|
|
21
|
-
DYNAMODB_ENDPOINT: `Env.schema.string()`,
|
|
22
|
-
},
|
|
23
|
-
envVars: {
|
|
24
|
-
AWS_ACCESS_KEY_ID: '',
|
|
25
|
-
AWS_SECRET_ACCESS_KEY: '',
|
|
26
|
-
AWS_REGION: '',
|
|
27
|
-
DYNAMODB_ENDPOINT: '',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Configures the package
|
|
33
|
-
*/
|
|
34
|
-
export async function configure(command) {
|
|
35
|
-
const driver = await command.prompt.choice('Select the cache driver you plan to use', ['redis', 'file', 'memory', 'database', 'dynamodb'], {
|
|
36
|
-
hint: 'You can always change it later',
|
|
37
|
-
});
|
|
38
|
-
const { envVars, envValidations } = DRIVERS_INFO[driver];
|
|
39
|
-
const codemods = await command.createCodemods();
|
|
40
|
-
/**
|
|
41
|
-
* Publish provider
|
|
42
|
-
*/
|
|
43
|
-
await codemods.updateRcFile((rcFile) => {
|
|
44
|
-
rcFile.addProvider('@adonisjs/cache/cache_provider').addCommand('@adonisjs/cache/commands');
|
|
45
|
-
});
|
|
46
|
-
/**
|
|
47
|
-
* Define environment variables
|
|
48
|
-
*/
|
|
49
|
-
if (envVars) {
|
|
50
|
-
codemods.defineEnvVariables(envVars);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Define environment validations
|
|
54
|
-
*/
|
|
55
|
-
if (envValidations) {
|
|
56
|
-
codemods.defineEnvValidations({ variables: envValidations });
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Publish config
|
|
60
|
-
*/
|
|
61
|
-
await codemods.makeUsingStub(stubsRoot, 'config.stub', { driver: driver });
|
|
62
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Helper to define REPL state
|
|
11
|
-
*/
|
|
12
|
-
function setupReplState(repl, key, value) {
|
|
13
|
-
repl.server.context[key] = value;
|
|
14
|
-
repl.notify(`Loaded ${key} module. You can access it using the "${repl.colors.underline(key)}" variable`);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Define REPL bindings
|
|
18
|
-
*/
|
|
19
|
-
export function defineReplBindings(app, Repl) {
|
|
20
|
-
/**
|
|
21
|
-
* Load cache provider to the cache property
|
|
22
|
-
*/
|
|
23
|
-
Repl.addMethod('loadCache', async (repl) => {
|
|
24
|
-
setupReplState(repl, 'cache', await app.container.make('cache'));
|
|
25
|
-
}, {
|
|
26
|
-
description: 'Load cache provider to the "cache" property',
|
|
27
|
-
});
|
|
28
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Define cache configuration
|
|
11
|
-
*/
|
|
12
|
-
export function defineConfig(config) {
|
|
13
|
-
return config;
|
|
14
|
-
}
|
package/build/src/drivers.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
/// <reference types="@adonisjs/redis/redis_provider" />
|
|
10
|
-
/// <reference types="@adonisjs/lucid/database_provider" />
|
|
11
|
-
import { configProvider } from '@adonisjs/core';
|
|
12
|
-
/**
|
|
13
|
-
* Different drivers supported by the cache module
|
|
14
|
-
*/
|
|
15
|
-
export const drivers = {
|
|
16
|
-
/**
|
|
17
|
-
* Redis driver for L2 layer
|
|
18
|
-
* You must install @adonisjs/redis to use this driver
|
|
19
|
-
*/
|
|
20
|
-
redis(config) {
|
|
21
|
-
return configProvider.create(async (app) => {
|
|
22
|
-
const redis = await app.container.make('redis');
|
|
23
|
-
const { redisDriver } = await import('bentocache/drivers/redis');
|
|
24
|
-
const redisConnection = redis.connection(config.connectionName);
|
|
25
|
-
return redisDriver({ connection: redisConnection.ioConnection });
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
/**
|
|
29
|
-
* Redis driver for the sync bus
|
|
30
|
-
* You must install @adonisjs/redis to use this driver
|
|
31
|
-
*/
|
|
32
|
-
redisBus(config) {
|
|
33
|
-
return configProvider.create(async (app) => {
|
|
34
|
-
const redis = await app.container.make('redis');
|
|
35
|
-
const { redisBusDriver } = await import('bentocache/drivers/redis');
|
|
36
|
-
const redisConnection = redis.connection(config.connectionName);
|
|
37
|
-
return redisBusDriver({ connection: redisConnection.ioConnection.options });
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
/**
|
|
41
|
-
* Memory driver for L1 layer
|
|
42
|
-
*/
|
|
43
|
-
memory(config) {
|
|
44
|
-
return configProvider.create(async () => {
|
|
45
|
-
const { memoryDriver } = await import('bentocache/drivers/memory');
|
|
46
|
-
return memoryDriver(config);
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* Database driver for L2 layer
|
|
51
|
-
* You must install @adonisjs/lucid to use this driver
|
|
52
|
-
*/
|
|
53
|
-
database(config) {
|
|
54
|
-
return configProvider.create(async (app) => {
|
|
55
|
-
const db = await app.container.make('lucid.db');
|
|
56
|
-
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
57
|
-
const dialect = db.connection(connectionName).dialect.name;
|
|
58
|
-
/**
|
|
59
|
-
* We only support pg, mysql, better-sqlite3 and sqlite3 dialects for now
|
|
60
|
-
*/
|
|
61
|
-
const supportedDialects = ['pg', 'mysql', 'better-sqlite3', 'sqlite3'];
|
|
62
|
-
if (!supportedDialects.includes(dialect)) {
|
|
63
|
-
throw new Error(`Unsupported dialect "${dialect}"`);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get the knex connection for the given connection name
|
|
67
|
-
*/
|
|
68
|
-
const rawConnection = db.getRawConnection(connectionName);
|
|
69
|
-
if (!rawConnection?.connection?.client) {
|
|
70
|
-
throw new Error(`Unable to get raw connection for "${connectionName}"`);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Create the driver
|
|
74
|
-
*/
|
|
75
|
-
const { default: knex } = await import('knex');
|
|
76
|
-
const knexClient = knex({
|
|
77
|
-
...rawConnection.config,
|
|
78
|
-
client: dialect === 'postgres' ? 'pg' : dialect,
|
|
79
|
-
});
|
|
80
|
-
const { knexDriver } = await import('bentocache/drivers/knex');
|
|
81
|
-
return knexDriver({ connection: knexClient });
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
/**
|
|
85
|
-
* DynamoDB driver for L2 layer
|
|
86
|
-
* You must install @aws-sdk/client-dynamodb to use this driver
|
|
87
|
-
*/
|
|
88
|
-
dynamodb(config) {
|
|
89
|
-
return configProvider.create(async () => {
|
|
90
|
-
const { dynamoDbDriver } = await import('bentocache/drivers/dynamodb');
|
|
91
|
-
return dynamoDbDriver(config);
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* File driver for L2 layer
|
|
96
|
-
*/
|
|
97
|
-
file(config) {
|
|
98
|
-
return configProvider.create(async () => {
|
|
99
|
-
const { fileDriver } = await import('bentocache/drivers/file');
|
|
100
|
-
return fileDriver(config);
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
};
|
package/build/src/store.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { bentostore } from 'bentocache';
|
|
10
|
-
import { configProvider } from '@adonisjs/core';
|
|
11
|
-
/**
|
|
12
|
-
* Create a new store
|
|
13
|
-
*/
|
|
14
|
-
export function store(options) {
|
|
15
|
-
return new Store(options);
|
|
16
|
-
}
|
|
17
|
-
export class Store {
|
|
18
|
-
#baseOptions = {};
|
|
19
|
-
#l1;
|
|
20
|
-
#l2;
|
|
21
|
-
#bus;
|
|
22
|
-
constructor(baseOptions = {}) {
|
|
23
|
-
this.#baseOptions = baseOptions;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Add a L1 layer to your store. This is usually a memory driver
|
|
27
|
-
* for fast access purposes.
|
|
28
|
-
*/
|
|
29
|
-
useL1Layer(driver) {
|
|
30
|
-
this.#l1 = driver;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Add a L2 layer to your store. This is usually something
|
|
35
|
-
* distributed like Redis, DynamoDB, Sql database, etc.
|
|
36
|
-
*/
|
|
37
|
-
useL2Layer(driver) {
|
|
38
|
-
this.#l2 = driver;
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Add a bus to your store. It will be used to synchronize L1 layers between
|
|
43
|
-
* different instances of your application.
|
|
44
|
-
*/
|
|
45
|
-
useBus(bus) {
|
|
46
|
-
this.#bus = bus;
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Create a config provider for the store
|
|
51
|
-
*/
|
|
52
|
-
entry() {
|
|
53
|
-
return configProvider.create(async (app) => {
|
|
54
|
-
const storeInstance = bentostore(this.#baseOptions);
|
|
55
|
-
if (this.#l1)
|
|
56
|
-
storeInstance.useL1Layer(await this.#l1?.resolver(app));
|
|
57
|
-
if (this.#l2)
|
|
58
|
-
storeInstance.useL2Layer(await this.#l2?.resolver(app));
|
|
59
|
-
if (this.#bus)
|
|
60
|
-
storeInstance.useBus(await this.#bus?.resolver(app));
|
|
61
|
-
return storeInstance;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
package/build/stubs/main.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @adonisjs/cache
|
|
3
|
-
*
|
|
4
|
-
* (c) AdonisJS
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { dirname } from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
export const stubsRoot = dirname(fileURLToPath(import.meta.url));
|