@adonisjs/session 7.7.0 → 8.0.0-next.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/cookie-aLBno-zS.js +31 -0
- package/build/debug-Ba-0Cgn9.js +3 -0
- package/build/dynamodb-CU8BrQfU.js +72 -0
- package/build/factories/main.d.ts +1 -1
- package/build/factories/main.js +25 -49
- package/build/factories/session_middleware_factory.d.ts +2 -2
- package/build/file-CNxCs957.js +71 -0
- package/build/index.d.ts +6 -7
- package/build/index.js +5 -33
- package/build/providers/session_provider.d.ts +2 -3
- package/build/providers/session_provider.js +27 -64
- package/build/redis-Bcjum7z7.js +36 -0
- package/build/session-CBqhcnvJ.js +209 -0
- package/build/session-Cc1LPXRc.js +107 -0
- package/build/session_middleware-CS0R7hmq.js +27 -0
- package/build/src/client.d.ts +46 -10
- package/build/src/client.js +38 -9
- package/build/src/debug.d.ts +1 -1
- package/build/src/define_config.d.ts +49 -10
- package/build/src/errors.d.ts +20 -9
- package/build/src/plugins/edge.d.ts +16 -2
- package/build/src/plugins/edge.js +74 -126
- package/build/src/plugins/japa/api_client.d.ts +22 -4
- package/build/src/plugins/japa/api_client.js +76 -97
- package/build/src/plugins/japa/browser_client.d.ts +18 -4
- package/build/src/plugins/japa/browser_client.js +58 -82
- package/build/src/session.d.ts +170 -65
- package/build/src/session_middleware.d.ts +28 -5
- package/build/src/session_middleware.js +5 -11
- package/build/src/stores/cookie.d.ts +41 -7
- package/build/src/stores/dynamodb.d.ts +44 -8
- package/build/src/stores/file.d.ts +34 -8
- package/build/src/stores/memory.d.ts +32 -15
- package/build/src/stores/redis.d.ts +39 -16
- package/build/src/types.d.ts +151 -82
- package/build/src/types.js +1 -1
- package/build/src/values_store.d.ts +113 -21
- package/build/values_store-smX0sQBJ.js +78 -0
- package/package.json +57 -56
- package/build/chunk-5ECC6OWF.js +0 -8
- package/build/chunk-5ECC6OWF.js.map +0 -1
- package/build/chunk-6BSSM3HO.js +0 -44
- package/build/chunk-6BSSM3HO.js.map +0 -1
- package/build/chunk-G7KFHA57.js +0 -59
- package/build/chunk-G7KFHA57.js.map +0 -1
- package/build/chunk-GCO66PQD.js +0 -85
- package/build/chunk-GCO66PQD.js.map +0 -1
- package/build/chunk-PZ5AY32C.js +0 -10
- package/build/chunk-PZ5AY32C.js.map +0 -1
- package/build/chunk-Q24L5XPC.js +0 -186
- package/build/chunk-Q24L5XPC.js.map +0 -1
- package/build/chunk-TE5JP3SX.js +0 -151
- package/build/chunk-TE5JP3SX.js.map +0 -1
- package/build/chunk-V3OAEXMJ.js +0 -8
- package/build/chunk-V3OAEXMJ.js.map +0 -1
- package/build/chunk-XP3CBOXR.js +0 -414
- package/build/chunk-XP3CBOXR.js.map +0 -1
- package/build/commands/commands.json +0 -1
- package/build/commands/main.d.ts +0 -4
- package/build/commands/main.js +0 -36
- package/build/commands/make_session_table.d.ts +0 -9
- package/build/commands/make_session_table.js +0 -21
- package/build/commands/make_session_table.js.map +0 -1
- package/build/cookie-3C33DMWA.js +0 -57
- package/build/cookie-3C33DMWA.js.map +0 -1
- package/build/database-443FB7MM.js +0 -118
- package/build/database-443FB7MM.js.map +0 -1
- package/build/dynamodb-53YXEFIJ.js +0 -108
- package/build/dynamodb-53YXEFIJ.js.map +0 -1
- package/build/factories/main.js.map +0 -1
- package/build/file-K3GBSVSU.js +0 -117
- package/build/file-K3GBSVSU.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/make/migration/sessions.stub +0 -26
- package/build/providers/session_provider.js.map +0 -1
- package/build/redis-YGX2CNE2.js +0 -119
- package/build/redis-YGX2CNE2.js.map +0 -1
- package/build/src/client.js.map +0 -1
- package/build/src/plugins/edge.js.map +0 -1
- package/build/src/plugins/japa/api_client.js.map +0 -1
- package/build/src/plugins/japa/browser_client.js.map +0 -1
- package/build/src/session_collection.d.ts +0 -55
- package/build/src/session_middleware.js.map +0 -1
- package/build/src/stores/database.d.ts +0 -55
- package/build/src/types.js.map +0 -1
package/build/chunk-Q24L5XPC.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
stubsRoot
|
|
3
|
-
} from "./chunk-V3OAEXMJ.js";
|
|
4
|
-
import {
|
|
5
|
-
debug_default
|
|
6
|
-
} from "./chunk-5ECC6OWF.js";
|
|
7
|
-
|
|
8
|
-
// configure.ts
|
|
9
|
-
async function configure(command) {
|
|
10
|
-
const codemods = await command.createCodemods();
|
|
11
|
-
await codemods.makeUsingStub(stubsRoot, "config/session.stub", {});
|
|
12
|
-
await codemods.defineEnvVariables({ SESSION_DRIVER: "cookie" });
|
|
13
|
-
await codemods.defineEnvValidations({
|
|
14
|
-
variables: {
|
|
15
|
-
SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`
|
|
16
|
-
},
|
|
17
|
-
leadingComment: "Variables for configuring session package"
|
|
18
|
-
});
|
|
19
|
-
await codemods.registerMiddleware("router", [
|
|
20
|
-
{
|
|
21
|
-
path: "@adonisjs/session/session_middleware"
|
|
22
|
-
}
|
|
23
|
-
]);
|
|
24
|
-
await codemods.updateRcFile((rcFile) => {
|
|
25
|
-
rcFile.addProvider("@adonisjs/session/session_provider");
|
|
26
|
-
rcFile.addCommand("@adonisjs/session/commands");
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/define_config.ts
|
|
31
|
-
import string from "@poppinss/utils/string";
|
|
32
|
-
import { configProvider } from "@adonisjs/core";
|
|
33
|
-
import { InvalidArgumentsException, RuntimeException } from "@poppinss/utils";
|
|
34
|
-
|
|
35
|
-
// src/stores/memory.ts
|
|
36
|
-
var MemoryStore = class _MemoryStore {
|
|
37
|
-
static sessions = /* @__PURE__ */ new Map();
|
|
38
|
-
/**
|
|
39
|
-
* Maps session IDs to user IDs (for tagging)
|
|
40
|
-
*/
|
|
41
|
-
static tags = /* @__PURE__ */ new Map();
|
|
42
|
-
/**
|
|
43
|
-
* Read session id value from the memory
|
|
44
|
-
*/
|
|
45
|
-
read(sessionId) {
|
|
46
|
-
return _MemoryStore.sessions.get(sessionId) || null;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Save in memory value for a given session id
|
|
50
|
-
*/
|
|
51
|
-
write(sessionId, values) {
|
|
52
|
-
_MemoryStore.sessions.set(sessionId, values);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Cleanup for a single session
|
|
56
|
-
*/
|
|
57
|
-
destroy(sessionId) {
|
|
58
|
-
_MemoryStore.sessions.delete(sessionId);
|
|
59
|
-
_MemoryStore.tags.delete(sessionId);
|
|
60
|
-
}
|
|
61
|
-
touch() {
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Tag a session with a user ID
|
|
65
|
-
*/
|
|
66
|
-
async tag(sessionId, userId) {
|
|
67
|
-
_MemoryStore.tags.set(sessionId, userId);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Get all sessions for a given user ID (tag)
|
|
71
|
-
*/
|
|
72
|
-
async tagged(userId) {
|
|
73
|
-
const sessions = [];
|
|
74
|
-
for (const [sessionId, taggedUserId] of _MemoryStore.tags) {
|
|
75
|
-
const data = _MemoryStore.sessions.get(sessionId);
|
|
76
|
-
if (taggedUserId === userId && data) sessions.push({ id: sessionId, data });
|
|
77
|
-
}
|
|
78
|
-
return sessions;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/define_config.ts
|
|
83
|
-
function defineConfig(config) {
|
|
84
|
-
debug_default("processing session config %O", config);
|
|
85
|
-
if (!config.store) {
|
|
86
|
-
throw new InvalidArgumentsException('Missing "store" property inside the session config');
|
|
87
|
-
}
|
|
88
|
-
const { stores: stores2, cookie, ...rest } = {
|
|
89
|
-
enabled: true,
|
|
90
|
-
age: "2h",
|
|
91
|
-
cookieName: "adonis_session",
|
|
92
|
-
clearWithBrowser: false,
|
|
93
|
-
...config
|
|
94
|
-
};
|
|
95
|
-
const cookieOptions = { ...cookie };
|
|
96
|
-
if (!rest.clearWithBrowser) {
|
|
97
|
-
cookieOptions.maxAge = string.seconds.parse(rest.age);
|
|
98
|
-
debug_default('computing maxAge "%s" for session id cookie', cookieOptions.maxAge);
|
|
99
|
-
}
|
|
100
|
-
return configProvider.create(async (app) => {
|
|
101
|
-
const storesNames = Object.keys(config.stores);
|
|
102
|
-
const storesList = {
|
|
103
|
-
memory: () => new MemoryStore()
|
|
104
|
-
};
|
|
105
|
-
for (let storeName of storesNames) {
|
|
106
|
-
const store = config.stores[storeName];
|
|
107
|
-
if (typeof store === "function") {
|
|
108
|
-
storesList[storeName] = store;
|
|
109
|
-
} else {
|
|
110
|
-
storesList[storeName] = await store.resolver(app);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
const transformedConfig = {
|
|
114
|
-
...rest,
|
|
115
|
-
cookie: cookieOptions,
|
|
116
|
-
stores: storesList
|
|
117
|
-
};
|
|
118
|
-
debug_default("transformed session config %O", transformedConfig);
|
|
119
|
-
return transformedConfig;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
var stores = {
|
|
123
|
-
file: (config) => {
|
|
124
|
-
return configProvider.create(async () => {
|
|
125
|
-
const { FileStore } = await import("./file-K3GBSVSU.js");
|
|
126
|
-
return (_, sessionConfig) => {
|
|
127
|
-
return new FileStore(config, sessionConfig.age);
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
redis: (config) => {
|
|
132
|
-
return configProvider.create(async (app) => {
|
|
133
|
-
const { RedisStore } = await import("./redis-YGX2CNE2.js");
|
|
134
|
-
const redis = await app.container.make("redis");
|
|
135
|
-
return (_, sessionConfig) => {
|
|
136
|
-
return new RedisStore(redis.connection(config.connection), sessionConfig.age);
|
|
137
|
-
};
|
|
138
|
-
});
|
|
139
|
-
},
|
|
140
|
-
cookie: () => {
|
|
141
|
-
return configProvider.create(async () => {
|
|
142
|
-
const { CookieStore } = await import("./cookie-3C33DMWA.js");
|
|
143
|
-
return (ctx, sessionConfig) => {
|
|
144
|
-
return new CookieStore(sessionConfig.cookie, ctx);
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
dynamodb: (config) => {
|
|
149
|
-
return configProvider.create(async () => {
|
|
150
|
-
const { DynamoDBStore } = await import("./dynamodb-53YXEFIJ.js");
|
|
151
|
-
const { DynamoDBClient } = await import("@aws-sdk/client-dynamodb");
|
|
152
|
-
const client = "clientConfig" in config ? new DynamoDBClient(config.clientConfig) : config.client;
|
|
153
|
-
return (_, sessionConfig) => {
|
|
154
|
-
return new DynamoDBStore(client, sessionConfig.age, {
|
|
155
|
-
tableName: config.tableName,
|
|
156
|
-
keyAttribute: config.keyAttribute
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
database: (config) => {
|
|
162
|
-
return configProvider.create(async (app) => {
|
|
163
|
-
const { DatabaseStore } = await import("./database-443FB7MM.js");
|
|
164
|
-
const db = await app.container.make("lucid.db");
|
|
165
|
-
const connectionName = config?.connectionName || db.primaryConnectionName;
|
|
166
|
-
if (!db.manager.has(connectionName)) {
|
|
167
|
-
throw new RuntimeException(
|
|
168
|
-
`Invalid database connection "${connectionName}" referenced in session config`
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
return (_, sessionConfig) => {
|
|
172
|
-
return new DatabaseStore(db.connection(connectionName), sessionConfig.age, {
|
|
173
|
-
tableName: config?.tableName,
|
|
174
|
-
gcProbability: config?.gcProbability
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export {
|
|
182
|
-
configure,
|
|
183
|
-
defineConfig,
|
|
184
|
-
stores
|
|
185
|
-
};
|
|
186
|
-
//# sourceMappingURL=chunk-Q24L5XPC.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../configure.ts","../src/define_config.ts","../src/stores/memory.ts"],"sourcesContent":["/*\n * @adonisjs/session\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'\nimport { stubsRoot } from './stubs/main.js'\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n const codemods = await command.createCodemods()\n\n /**\n * Publish config file\n */\n await codemods.makeUsingStub(stubsRoot, 'config/session.stub', {})\n\n /**\n * Define environment variables\n */\n await codemods.defineEnvVariables({ SESSION_DRIVER: 'cookie' })\n\n /**\n * Define environment variables validations\n */\n await codemods.defineEnvValidations({\n variables: {\n SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`,\n },\n leadingComment: 'Variables for configuring session package',\n })\n\n /**\n * Register middleware\n */\n await codemods.registerMiddleware('router', [\n {\n path: '@adonisjs/session/session_middleware',\n },\n ])\n\n /**\n * Register provider and commands\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/session/session_provider')\n rcFile.addCommand('@adonisjs/session/commands')\n })\n}\n","/*\n * @adonisjs/session\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 string from '@poppinss/utils/string'\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport { InvalidArgumentsException, RuntimeException } from '@poppinss/utils'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport { MemoryStore } from './stores/memory.js'\nimport type {\n SessionConfig,\n FileStoreConfig,\n RedisStoreConfig,\n SessionStoreFactory,\n DynamoDBStoreConfig,\n DatabaseStoreConfig,\n} from './types.js'\n\n/**\n * Resolved config with stores\n */\ntype ResolvedConfig<KnownStores extends Record<string, SessionStoreFactory>> = SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n cookie: Partial<CookieOptions>\n}\n\n/**\n * Helper to normalize session config\n */\nexport function defineConfig<\n KnownStores extends Record<string, SessionStoreFactory | ConfigProvider<SessionStoreFactory>>,\n>(\n config: Partial<SessionConfig> & {\n store: keyof KnownStores | 'memory'\n stores: KnownStores\n }\n): ConfigProvider<\n ResolvedConfig<{\n [K in keyof KnownStores]: SessionStoreFactory\n }>\n> {\n debug('processing session config %O', config)\n\n /**\n * Make sure a store is defined\n */\n if (!config.store) {\n throw new InvalidArgumentsException('Missing \"store\" property inside the session config')\n }\n\n /**\n * Destructuring config with the default values. We pull out\n * stores and cookie values, since we have to transform\n * them in the output value.\n */\n const { stores, cookie, ...rest } = {\n enabled: true,\n age: '2h',\n cookieName: 'adonis_session',\n clearWithBrowser: false,\n ...config,\n }\n\n const cookieOptions: Partial<CookieOptions> = { ...cookie }\n\n /**\n * Define maxAge property when session id cookie is\n * not a session cookie.\n */\n if (!rest.clearWithBrowser) {\n cookieOptions.maxAge = string.seconds.parse(rest.age)\n debug('computing maxAge \"%s\" for session id cookie', cookieOptions.maxAge)\n }\n\n return configProvider.create(async (app) => {\n const storesNames = Object.keys(config.stores)\n\n /**\n * List of stores with memory store always configured\n */\n const storesList = {\n memory: () => new MemoryStore(),\n } as Record<string, SessionStoreFactory>\n\n /**\n * Looping for stores and resolving them\n */\n for (let storeName of storesNames) {\n const store = config.stores[storeName]\n if (typeof store === 'function') {\n storesList[storeName] = store\n } else {\n storesList[storeName] = await store.resolver(app)\n }\n }\n\n const transformedConfig = {\n ...rest,\n cookie: cookieOptions,\n stores: storesList as { [K in keyof KnownStores]: SessionStoreFactory },\n }\n\n debug('transformed session config %O', transformedConfig)\n return transformedConfig\n })\n}\n\n/**\n * Inbuilt stores to store the session data.\n */\nexport const stores: {\n file: (config: FileStoreConfig) => ConfigProvider<SessionStoreFactory>\n redis: (config: RedisStoreConfig) => ConfigProvider<SessionStoreFactory>\n cookie: () => ConfigProvider<SessionStoreFactory>\n dynamodb: (config: DynamoDBStoreConfig) => ConfigProvider<SessionStoreFactory>\n database: (config?: DatabaseStoreConfig) => ConfigProvider<SessionStoreFactory>\n} = {\n file: (config) => {\n return configProvider.create(async () => {\n const { FileStore } = await import('./stores/file.js')\n return (_, sessionConfig: SessionConfig) => {\n return new FileStore(config, sessionConfig.age)\n }\n })\n },\n redis: (config) => {\n return configProvider.create(async (app) => {\n const { RedisStore } = await import('./stores/redis.js')\n const redis = await app.container.make('redis')\n\n return (_, sessionConfig: SessionConfig) => {\n return new RedisStore(redis.connection(config.connection), sessionConfig.age)\n }\n })\n },\n cookie: () => {\n return configProvider.create(async () => {\n const { CookieStore } = await import('./stores/cookie.js')\n return (ctx, sessionConfig: SessionConfig) => {\n return new CookieStore(sessionConfig.cookie, ctx)\n }\n })\n },\n dynamodb: (config) => {\n return configProvider.create(async () => {\n const { DynamoDBStore } = await import('./stores/dynamodb.js')\n const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb')\n\n const client =\n 'clientConfig' in config ? new DynamoDBClient(config.clientConfig) : config.client\n\n return (_, sessionConfig: SessionConfig) => {\n return new DynamoDBStore(client, sessionConfig.age, {\n tableName: config.tableName,\n keyAttribute: config.keyAttribute,\n })\n }\n })\n },\n database: (config) => {\n return configProvider.create(async (app) => {\n const { DatabaseStore } = await import('./stores/database.js')\n const db = await app.container.make('lucid.db')\n const connectionName = config?.connectionName || db.primaryConnectionName\n\n if (!db.manager.has(connectionName)) {\n throw new RuntimeException(\n `Invalid database connection \"${connectionName}\" referenced in session config`\n )\n }\n\n return (_, sessionConfig: SessionConfig) => {\n return new DatabaseStore(db.connection(connectionName), sessionConfig.age, {\n tableName: config?.tableName,\n gcProbability: config?.gcProbability,\n })\n }\n })\n },\n}\n","/**\n * @adonisjs/session\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 { SessionData, SessionStoreWithTaggingContract, TaggedSession } from '../types.js'\n\n/**\n * Memory store is meant to be used for writing tests.\n */\nexport class MemoryStore implements SessionStoreWithTaggingContract {\n static sessions: Map<string, SessionData> = new Map()\n\n /**\n * Maps session IDs to user IDs (for tagging)\n */\n static tags: Map<string, string> = new Map()\n\n /**\n * Read session id value from the memory\n */\n read(sessionId: string): SessionData | null {\n return MemoryStore.sessions.get(sessionId) || null\n }\n\n /**\n * Save in memory value for a given session id\n */\n write(sessionId: string, values: SessionData): void {\n MemoryStore.sessions.set(sessionId, values)\n }\n\n /**\n * Cleanup for a single session\n */\n destroy(sessionId: string): void {\n MemoryStore.sessions.delete(sessionId)\n MemoryStore.tags.delete(sessionId)\n }\n\n touch(): void {}\n\n /**\n * Tag a session with a user ID\n */\n async tag(sessionId: string, userId: string): Promise<void> {\n MemoryStore.tags.set(sessionId, userId)\n }\n\n /**\n * Get all sessions for a given user ID (tag)\n */\n async tagged(userId: string): Promise<TaggedSession[]> {\n const sessions: TaggedSession[] = []\n\n for (const [sessionId, taggedUserId] of MemoryStore.tags) {\n const data = MemoryStore.sessions.get(sessionId)\n if (taggedUserId === userId && data) sessions.push({ id: sessionId, data })\n }\n\n return sessions\n }\n}\n"],"mappings":";;;;;;;;AAeA,eAAsB,UAAU,SAAoB;AAClD,QAAM,WAAW,MAAM,QAAQ,eAAe;AAK9C,QAAM,SAAS,cAAc,WAAW,uBAAuB,CAAC,CAAC;AAKjE,QAAM,SAAS,mBAAmB,EAAE,gBAAgB,SAAS,CAAC;AAK9D,QAAM,SAAS,qBAAqB;AAAA,IAClC,WAAW;AAAA,MACT,gBAAgB;AAAA,IAClB;AAAA,IACA,gBAAgB;AAAA,EAClB,CAAC;AAKD,QAAM,SAAS,mBAAmB,UAAU;AAAA,IAC1C;AAAA,MACE,MAAM;AAAA,IACR;AAAA,EACF,CAAC;AAKD,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,YAAY,oCAAoC;AACvD,WAAO,WAAW,4BAA4B;AAAA,EAChD,CAAC;AACH;;;AC1CA,OAAO,YAAY;AACnB,SAAS,sBA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|
-
import lodash from "@poppinss/utils/lodash";
|
|
3
|
-
import { RuntimeException } from "@poppinss/utils";
|
|
4
|
-
var ReadOnlyValuesStore = class {
|
|
5
|
-
/**
|
|
6
|
-
* Underlying store values
|
|
7
|
-
*/
|
|
8
|
-
values;
|
|
9
|
-
/**
|
|
10
|
-
* Find if store is empty or not
|
|
11
|
-
*/
|
|
12
|
-
get isEmpty() {
|
|
13
|
-
return !this.values || Object.keys(this.values).length === 0;
|
|
14
|
-
}
|
|
15
|
-
constructor(values) {
|
|
16
|
-
this.values = values || {};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get value for a given key
|
|
20
|
-
*/
|
|
21
|
-
get(key, defaultValue) {
|
|
22
|
-
const value = lodash.get(this.values, key);
|
|
23
|
-
if (defaultValue !== void 0 && (value === null || value === void 0)) {
|
|
24
|
-
return defaultValue;
|
|
25
|
-
}
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* A boolean to know if value exists. Extra guards to check
|
|
30
|
-
* arrays for it's length as well.
|
|
31
|
-
*/
|
|
32
|
-
has(key, checkForArraysLength = true) {
|
|
33
|
-
const value = this.get(key);
|
|
34
|
-
if (!Array.isArray(value)) {
|
|
35
|
-
return !!value;
|
|
36
|
-
}
|
|
37
|
-
return checkForArraysLength ? value.length > 0 : !!value;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Get all values
|
|
41
|
-
*/
|
|
42
|
-
all() {
|
|
43
|
-
return this.values;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Returns object representation of values
|
|
47
|
-
*/
|
|
48
|
-
toObject() {
|
|
49
|
-
return this.all();
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns the store values
|
|
53
|
-
*/
|
|
54
|
-
toJSON() {
|
|
55
|
-
return this.all();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns string representation of the store
|
|
59
|
-
*/
|
|
60
|
-
toString() {
|
|
61
|
-
return JSON.stringify(this.all());
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var ValuesStore = class extends ReadOnlyValuesStore {
|
|
65
|
-
/**
|
|
66
|
-
* A boolean to know if store has been
|
|
67
|
-
* modified
|
|
68
|
-
*/
|
|
69
|
-
#modified = false;
|
|
70
|
-
constructor(values) {
|
|
71
|
-
super(values);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Find if the store has been modified.
|
|
75
|
-
*/
|
|
76
|
-
get hasBeenModified() {
|
|
77
|
-
return this.#modified;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Set key/value pair
|
|
81
|
-
*/
|
|
82
|
-
set(key, value) {
|
|
83
|
-
this.#modified = true;
|
|
84
|
-
lodash.set(this.values, key, value);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Remove key
|
|
88
|
-
*/
|
|
89
|
-
unset(key) {
|
|
90
|
-
this.#modified = true;
|
|
91
|
-
lodash.unset(this.values, key);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Pull value from the store. It is same as calling
|
|
95
|
-
* store.get and then store.unset
|
|
96
|
-
*/
|
|
97
|
-
pull(key, defaultValue) {
|
|
98
|
-
return ((value) => {
|
|
99
|
-
this.unset(key);
|
|
100
|
-
return value;
|
|
101
|
-
})(this.get(key, defaultValue));
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Increment number. The method raises an error when
|
|
105
|
-
* nderlying value is not a number
|
|
106
|
-
*/
|
|
107
|
-
increment(key, steps = 1) {
|
|
108
|
-
const value = this.get(key, 0);
|
|
109
|
-
if (typeof value !== "number") {
|
|
110
|
-
throw new RuntimeException(`Cannot increment "${key}". Existing value is not a number`);
|
|
111
|
-
}
|
|
112
|
-
this.set(key, value + steps);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Increment number. The method raises an error when
|
|
116
|
-
* nderlying value is not a number
|
|
117
|
-
*/
|
|
118
|
-
decrement(key, steps = 1) {
|
|
119
|
-
const value = this.get(key, 0);
|
|
120
|
-
if (typeof value !== "number") {
|
|
121
|
-
throw new RuntimeException(`Cannot decrement "${key}". Existing value is not a number`);
|
|
122
|
-
}
|
|
123
|
-
this.set(key, value - steps);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Overwrite existing store data with new values.
|
|
127
|
-
*/
|
|
128
|
-
update(values) {
|
|
129
|
-
this.#modified = true;
|
|
130
|
-
this.values = values;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Update to merge values
|
|
134
|
-
*/
|
|
135
|
-
merge(values) {
|
|
136
|
-
this.#modified = true;
|
|
137
|
-
lodash.merge(this.values, values);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Reset store by clearing it's values.
|
|
141
|
-
*/
|
|
142
|
-
clear() {
|
|
143
|
-
this.update({});
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
export {
|
|
148
|
-
ReadOnlyValuesStore,
|
|
149
|
-
ValuesStore
|
|
150
|
-
};
|
|
151
|
-
//# sourceMappingURL=chunk-TE5JP3SX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/values_store.ts"],"sourcesContent":["/*\n * @adonisjs/redis\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 lodash from '@poppinss/utils/lodash'\nimport { RuntimeException } from '@poppinss/utils'\nimport type { AllowedSessionValues, SessionData } from './types.js'\n\n/**\n * Readonly session store\n */\nexport class ReadOnlyValuesStore {\n /**\n * Underlying store values\n */\n protected values: SessionData\n\n /**\n * Find if store is empty or not\n */\n get isEmpty() {\n return !this.values || Object.keys(this.values).length === 0\n }\n\n constructor(values: SessionData | null) {\n this.values = values || {}\n }\n\n /**\n * Get value for a given key\n */\n get(key: string | string[], defaultValue?: any): any {\n const value = lodash.get(this.values, key)\n if (defaultValue !== undefined && (value === null || value === undefined)) {\n return defaultValue\n }\n\n return value\n }\n\n /**\n * A boolean to know if value exists. Extra guards to check\n * arrays for it's length as well.\n */\n has(key: string | string[], checkForArraysLength: boolean = true): boolean {\n const value = this.get(key)\n if (!Array.isArray(value)) {\n return !!value\n }\n\n return checkForArraysLength ? value.length > 0 : !!value\n }\n\n /**\n * Get all values\n */\n all(): any {\n return this.values\n }\n\n /**\n * Returns object representation of values\n */\n toObject() {\n return this.all()\n }\n\n /**\n * Returns the store values\n */\n toJSON(): any {\n return this.all()\n }\n\n /**\n * Returns string representation of the store\n */\n toString() {\n return JSON.stringify(this.all())\n }\n}\n\n/**\n * Session store encapsulates the session data and offers a\n * declarative API to mutate it.\n */\nexport class ValuesStore extends ReadOnlyValuesStore {\n /**\n * A boolean to know if store has been\n * modified\n */\n #modified: boolean = false\n\n constructor(values: SessionData | null) {\n super(values)\n }\n\n /**\n * Find if the store has been modified.\n */\n get hasBeenModified(): boolean {\n return this.#modified\n }\n\n /**\n * Set key/value pair\n */\n set(key: string | string[], value: AllowedSessionValues): void {\n this.#modified = true\n lodash.set(this.values, key, value)\n }\n\n /**\n * Remove key\n */\n unset(key: string | string[]): void {\n this.#modified = true\n lodash.unset(this.values, key)\n }\n\n /**\n * Pull value from the store. It is same as calling\n * store.get and then store.unset\n */\n pull(key: string | string[], defaultValue?: any): any {\n return ((value): any => {\n this.unset(key)\n return value\n })(this.get(key, defaultValue))\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n increment(key: string | string[], steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot increment \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value + steps)\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n decrement(key: string | string[], steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot decrement \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value - steps)\n }\n\n /**\n * Overwrite existing store data with new values.\n */\n update(values: { [key: string]: any }): void {\n this.#modified = true\n this.values = values\n }\n\n /**\n * Update to merge values\n */\n merge(values: { [key: string]: any }): any {\n this.#modified = true\n lodash.merge(this.values, values)\n }\n\n /**\n * Reset store by clearing it's values.\n */\n clear(): void {\n this.update({})\n }\n}\n"],"mappings":";AASA,OAAO,YAAY;AACnB,SAAS,wBAAwB;AAM1B,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA,EAIrB;AAAA;AAAA;AAAA;AAAA,EAKV,IAAI,UAAU;AACZ,WAAO,CAAC,KAAK,UAAU,OAAO,KAAK,KAAK,MAAM,EAAE,WAAW;AAAA,EAC7D;AAAA,EAEA,YAAY,QAA4B;AACtC,SAAK,SAAS,UAAU,CAAC;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,KAAwB,cAAyB;AACnD,UAAM,QAAQ,OAAO,IAAI,KAAK,QAAQ,GAAG;AACzC,QAAI,iBAAiB,WAAc,UAAU,QAAQ,UAAU,SAAY;AACzE,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,KAAwB,uBAAgC,MAAe;AACzE,UAAM,QAAQ,KAAK,IAAI,GAAG;AAC1B,QAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,aAAO,CAAC,CAAC;AAAA,IACX;AAEA,WAAO,uBAAuB,MAAM,SAAS,IAAI,CAAC,CAAC;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAW;AACT,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACT,WAAO,KAAK,IAAI;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,SAAc;AACZ,WAAO,KAAK,IAAI;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACT,WAAO,KAA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SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqC;AACzC,SAAK,YAAY;AACjB,WAAO,MAAM,KAAK,QAAQ,MAAM;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,OAAO,CAAC,CAAC;AAAA,EAChB;AACF;","names":[]}
|
package/build/chunk-V3OAEXMJ.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../stubs/main.ts"],"sourcesContent":["/*\n * @adonisjs/session\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 { getDirname } from '@poppinss/utils'\n\nexport const stubsRoot = getDirname(import.meta.url)\n"],"mappings":";AASA,SAAS,kBAAkB;AAEpB,IAAM,YAAY,WAAW,YAAY,GAAG;","names":[]}
|