@adonisjs/session 7.5.1 → 7.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/build/chunk-5ECC6OWF.js +8 -0
  2. package/build/{chunk-ZVSEMDIC.js.map → chunk-5ECC6OWF.js.map} +1 -1
  3. package/build/{chunk-TZLOND27.js → chunk-6BSSM3HO.js} +2 -2
  4. package/build/chunk-G7KFHA57.js +59 -0
  5. package/build/chunk-G7KFHA57.js.map +1 -0
  6. package/build/{chunk-GB5FBZCV.js → chunk-GCO66PQD.js} +2 -2
  7. package/build/{chunk-ZVSEMDIC.js → chunk-PZ5AY32C.js} +2 -7
  8. package/build/chunk-PZ5AY32C.js.map +1 -0
  9. package/build/{chunk-WUWXIKIB.js → chunk-Q24L5XPC.js} +51 -12
  10. package/build/chunk-Q24L5XPC.js.map +1 -0
  11. package/build/chunk-V3OAEXMJ.js +8 -0
  12. package/build/chunk-V3OAEXMJ.js.map +1 -0
  13. package/build/{chunk-OCQGCVXK.js → chunk-XP3CBOXR.js} +24 -4
  14. package/build/chunk-XP3CBOXR.js.map +1 -0
  15. package/build/commands/commands.json +1 -0
  16. package/build/commands/main.d.ts +4 -0
  17. package/build/commands/main.js +36 -0
  18. package/build/commands/make_session_table.d.ts +9 -0
  19. package/build/commands/make_session_table.js +21 -0
  20. package/build/commands/make_session_table.js.map +1 -0
  21. package/build/{cookie-WBWYVEDW.js → cookie-3C33DMWA.js} +3 -2
  22. package/build/{cookie-WBWYVEDW.js.map → cookie-3C33DMWA.js.map} +1 -1
  23. package/build/database-443FB7MM.js +118 -0
  24. package/build/database-443FB7MM.js.map +1 -0
  25. package/build/{dynamodb-3PG52TE3.js → dynamodb-53YXEFIJ.js} +3 -2
  26. package/build/{dynamodb-3PG52TE3.js.map → dynamodb-53YXEFIJ.js.map} +1 -1
  27. package/build/factories/main.js +7 -4
  28. package/build/factories/main.js.map +1 -1
  29. package/build/{file-B6QKOZXW.js → file-K3GBSVSU.js} +5 -4
  30. package/build/{file-B6QKOZXW.js.map → file-K3GBSVSU.js.map} +1 -1
  31. package/build/index.d.ts +1 -0
  32. package/build/index.js +11 -4
  33. package/build/make/migration/sessions.stub +26 -0
  34. package/build/providers/session_provider.d.ts +2 -1
  35. package/build/providers/session_provider.js +26 -11
  36. package/build/providers/session_provider.js.map +1 -1
  37. package/build/redis-YGX2CNE2.js +119 -0
  38. package/build/redis-YGX2CNE2.js.map +1 -0
  39. package/build/src/client.js +3 -2
  40. package/build/src/define_config.d.ts +2 -1
  41. package/build/src/errors.d.ts +5 -0
  42. package/build/src/plugins/edge.js +2 -1
  43. package/build/src/plugins/edge.js.map +1 -1
  44. package/build/src/plugins/japa/api_client.js +3 -2
  45. package/build/src/plugins/japa/api_client.js.map +1 -1
  46. package/build/src/plugins/japa/browser_client.js +3 -2
  47. package/build/src/plugins/japa/browser_client.js.map +1 -1
  48. package/build/src/session.d.ts +8 -0
  49. package/build/src/session_collection.d.ts +55 -0
  50. package/build/src/session_middleware.js +4 -3
  51. package/build/src/stores/database.d.ts +55 -0
  52. package/build/src/stores/memory.d.ts +14 -2
  53. package/build/src/stores/redis.d.ts +15 -8
  54. package/build/src/types.d.ts +45 -0
  55. package/package.json +39 -28
  56. package/build/chunk-OCQGCVXK.js.map +0 -1
  57. package/build/chunk-WUWXIKIB.js.map +0 -1
  58. package/build/redis-CAY24YIA.js +0 -58
  59. package/build/redis-CAY24YIA.js.map +0 -1
  60. /package/build/{chunk-TZLOND27.js.map → chunk-6BSSM3HO.js.map} +0 -0
  61. /package/build/{chunk-GB5FBZCV.js.map → chunk-GCO66PQD.js.map} +0 -0
@@ -0,0 +1,8 @@
1
+ // src/debug.ts
2
+ import { debuglog } from "util";
3
+ var debug_default = debuglog("adonisjs:session");
4
+
5
+ export {
6
+ debug_default
7
+ };
8
+ //# sourceMappingURL=chunk-5ECC6OWF.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/debug.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 { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:session')\n"],"mappings":";;;;;;;AASA,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,kBAAkB;","names":[]}
1
+ {"version":3,"sources":["../src/debug.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 { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:session')\n"],"mappings":";AASA,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,kBAAkB;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Session
3
- } from "./chunk-OCQGCVXK.js";
3
+ } from "./chunk-XP3CBOXR.js";
4
4
 
5
5
  // src/session_middleware.ts
6
6
  import { ExceptionHandler } from "@adonisjs/core/http";
@@ -41,4 +41,4 @@ var SessionMiddleware = class {
41
41
  export {
42
42
  SessionMiddleware
43
43
  };
44
- //# sourceMappingURL=chunk-TZLOND27.js.map
44
+ //# sourceMappingURL=chunk-6BSSM3HO.js.map
@@ -0,0 +1,59 @@
1
+ import {
2
+ E_SESSION_TAGGING_NOT_SUPPORTED
3
+ } from "./chunk-XP3CBOXR.js";
4
+ import {
5
+ debug_default
6
+ } from "./chunk-5ECC6OWF.js";
7
+
8
+ // src/session_collection.ts
9
+ var SessionCollection = class {
10
+ #store;
11
+ constructor(config) {
12
+ const storeFactory = config.stores[config.store];
13
+ this.#store = storeFactory(null, config);
14
+ }
15
+ /**
16
+ * Check if the current store supports tagging
17
+ */
18
+ supportsTagging() {
19
+ return "tag" in this.#store && "tagged" in this.#store;
20
+ }
21
+ /**
22
+ * Returns the session data for the given session ID,
23
+ * or null if the session does not exist
24
+ */
25
+ async get(sessionId) {
26
+ debug_default("session collection: getting session data %s", sessionId);
27
+ return this.#store.read(sessionId);
28
+ }
29
+ /**
30
+ * Destroys a session by its ID
31
+ */
32
+ async destroy(sessionId) {
33
+ debug_default("session collection: destroying session %s", sessionId);
34
+ return this.#store.destroy(sessionId);
35
+ }
36
+ /**
37
+ * Tag a session with a user ID.
38
+ * Only supported by Memory, Redis and Database stores.
39
+ */
40
+ async tag(sessionId, userId) {
41
+ debug_default("session collection: tagging session %s with user %s", sessionId, userId);
42
+ if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
43
+ return this.#store.tag(sessionId, userId);
44
+ }
45
+ /**
46
+ * Get all sessions for a given user ID (tag).
47
+ * Only supported by Memory, Redis and Database stores.
48
+ */
49
+ async tagged(userId) {
50
+ debug_default("session collection: getting sessions tagged with user %s", userId);
51
+ if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
52
+ return this.#store.tagged(userId);
53
+ }
54
+ };
55
+
56
+ export {
57
+ SessionCollection
58
+ };
59
+ //# sourceMappingURL=chunk-G7KFHA57.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/session_collection.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 debug from './debug.js'\nimport { E_SESSION_TAGGING_NOT_SUPPORTED } from './errors.js'\nimport type {\n ResolvedSessionConfig,\n SessionData,\n SessionStoreWithTaggingContract,\n TaggedSession,\n} from './types.js'\n\n/**\n * SessionCollection provides APIs for programmatic session\n * management. It allows reading, destroying, and tagging\n * sessions without an HTTP context.\n *\n * @example\n * ```ts\n * import app from '@adonisjs/core/services/app'\n * import { SessionCollection } from '@adonisjs/session'\n *\n * const sessionCollection = await app.container.make(SessionCollection)\n *\n * // List all sessions for a user\n * const sessions = await sessionCollection.tagged(String(user.id))\n *\n * // Destroy a specific session\n * await sessionCollection.destroy(sessionId)\n * ```\n */\nexport class SessionCollection {\n #store: SessionStoreWithTaggingContract\n\n constructor(config: ResolvedSessionConfig) {\n const storeFactory = config.stores[config.store]\n this.#store = storeFactory(null as any, config) as SessionStoreWithTaggingContract\n }\n\n /**\n * Check if the current store supports tagging\n */\n supportsTagging(): boolean {\n return 'tag' in this.#store && 'tagged' in this.#store\n }\n\n /**\n * Returns the session data for the given session ID,\n * or null if the session does not exist\n */\n async get(sessionId: string): Promise<SessionData | null> {\n debug('session collection: getting session data %s', sessionId)\n return this.#store.read(sessionId)\n }\n\n /**\n * Destroys a session by its ID\n */\n async destroy(sessionId: string): Promise<void> {\n debug('session collection: destroying session %s', sessionId)\n return this.#store.destroy(sessionId)\n }\n\n /**\n * Tag a session with a user ID.\n * Only supported by Memory, Redis and Database stores.\n */\n async tag(sessionId: string, userId: string): Promise<void> {\n debug('session collection: tagging session %s with user %s', sessionId, userId)\n if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED()\n\n return (this.#store as SessionStoreWithTaggingContract).tag(sessionId, userId)\n }\n\n /**\n * Get all sessions for a given user ID (tag).\n * Only supported by Memory, Redis and Database stores.\n */\n async tagged(userId: string): Promise<TaggedSession[]> {\n debug('session collection: getting sessions tagged with user %s', userId)\n if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED()\n\n return (this.#store as SessionStoreWithTaggingContract).tagged(userId)\n }\n}\n"],"mappings":";;;;;;;;AAqCO,IAAM,oBAAN,MAAwB;AAAA,EAC7B;AAAA,EAEA,YAAY,QAA+B;AACzC,UAAM,eAAe,OAAO,OAAO,OAAO,KAAK;AAC/C,SAAK,SAAS,aAAa,MAAa,MAAM;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,kBAA2B;AACzB,WAAO,SAAS,KAAK,UAAU,YAAY,KAAK;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,WAAgD;AACxD,kBAAM,+CAA+C,SAAS;AAC9D,WAAO,KAAK,OAAO,KAAK,SAAS;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,WAAkC;AAC9C,kBAAM,6CAA6C,SAAS;AAC5D,WAAO,KAAK,OAAO,QAAQ,SAAS;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,WAAmB,QAA+B;AAC1D,kBAAM,uDAAuD,WAAW,MAAM;AAC9E,QAAI,CAAC,KAAK,gBAAgB,EAAG,OAAM,IAAI,gCAAgC;AAEvE,WAAQ,KAAK,OAA2C,IAAI,WAAW,MAAM;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,QAA0C;AACrD,kBAAM,4DAA4D,MAAM;AACxE,QAAI,CAAC,KAAK,gBAAgB,EAAG,OAAM,IAAI,gCAAgC;AAEvE,WAAQ,KAAK,OAA2C,OAAO,MAAM;AAAA,EACvE;AACF;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-TE5JP3SX.js";
4
4
  import {
5
5
  debug_default
6
- } from "./chunk-ZVSEMDIC.js";
6
+ } from "./chunk-5ECC6OWF.js";
7
7
 
8
8
  // src/client.ts
9
9
  import { cuid } from "@adonisjs/core/helpers";
@@ -82,4 +82,4 @@ var SessionClient = class {
82
82
  export {
83
83
  SessionClient
84
84
  };
85
- //# sourceMappingURL=chunk-GB5FBZCV.js.map
85
+ //# sourceMappingURL=chunk-GCO66PQD.js.map
@@ -4,12 +4,7 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // src/debug.ts
8
- import { debuglog } from "node:util";
9
- var debug_default = debuglog("adonisjs:session");
10
-
11
7
  export {
12
- __export,
13
- debug_default
8
+ __export
14
9
  };
15
- //# sourceMappingURL=chunk-ZVSEMDIC.js.map
10
+ //# sourceMappingURL=chunk-PZ5AY32C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,10 +1,9 @@
1
+ import {
2
+ stubsRoot
3
+ } from "./chunk-V3OAEXMJ.js";
1
4
  import {
2
5
  debug_default
3
- } from "./chunk-ZVSEMDIC.js";
4
-
5
- // stubs/main.ts
6
- import { getDirname } from "@poppinss/utils";
7
- var stubsRoot = getDirname(import.meta.url);
6
+ } from "./chunk-5ECC6OWF.js";
8
7
 
9
8
  // configure.ts
10
9
  async function configure(command) {
@@ -24,17 +23,22 @@ async function configure(command) {
24
23
  ]);
25
24
  await codemods.updateRcFile((rcFile) => {
26
25
  rcFile.addProvider("@adonisjs/session/session_provider");
26
+ rcFile.addCommand("@adonisjs/session/commands");
27
27
  });
28
28
  }
29
29
 
30
30
  // src/define_config.ts
31
31
  import string from "@poppinss/utils/string";
32
32
  import { configProvider } from "@adonisjs/core";
33
- import { InvalidArgumentsException } from "@poppinss/utils";
33
+ import { InvalidArgumentsException, RuntimeException } from "@poppinss/utils";
34
34
 
35
35
  // src/stores/memory.ts
36
36
  var MemoryStore = class _MemoryStore {
37
37
  static sessions = /* @__PURE__ */ new Map();
38
+ /**
39
+ * Maps session IDs to user IDs (for tagging)
40
+ */
41
+ static tags = /* @__PURE__ */ new Map();
38
42
  /**
39
43
  * Read session id value from the memory
40
44
  */
@@ -52,9 +56,27 @@ var MemoryStore = class _MemoryStore {
52
56
  */
53
57
  destroy(sessionId) {
54
58
  _MemoryStore.sessions.delete(sessionId);
59
+ _MemoryStore.tags.delete(sessionId);
55
60
  }
56
61
  touch() {
57
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
+ }
58
80
  };
59
81
 
60
82
  // src/define_config.ts
@@ -100,7 +122,7 @@ function defineConfig(config) {
100
122
  var stores = {
101
123
  file: (config) => {
102
124
  return configProvider.create(async () => {
103
- const { FileStore } = await import("./file-B6QKOZXW.js");
125
+ const { FileStore } = await import("./file-K3GBSVSU.js");
104
126
  return (_, sessionConfig) => {
105
127
  return new FileStore(config, sessionConfig.age);
106
128
  };
@@ -108,7 +130,7 @@ var stores = {
108
130
  },
109
131
  redis: (config) => {
110
132
  return configProvider.create(async (app) => {
111
- const { RedisStore } = await import("./redis-CAY24YIA.js");
133
+ const { RedisStore } = await import("./redis-YGX2CNE2.js");
112
134
  const redis = await app.container.make("redis");
113
135
  return (_, sessionConfig) => {
114
136
  return new RedisStore(redis.connection(config.connection), sessionConfig.age);
@@ -117,7 +139,7 @@ var stores = {
117
139
  },
118
140
  cookie: () => {
119
141
  return configProvider.create(async () => {
120
- const { CookieStore } = await import("./cookie-WBWYVEDW.js");
142
+ const { CookieStore } = await import("./cookie-3C33DMWA.js");
121
143
  return (ctx, sessionConfig) => {
122
144
  return new CookieStore(sessionConfig.cookie, ctx);
123
145
  };
@@ -125,7 +147,7 @@ var stores = {
125
147
  },
126
148
  dynamodb: (config) => {
127
149
  return configProvider.create(async () => {
128
- const { DynamoDBStore } = await import("./dynamodb-3PG52TE3.js");
150
+ const { DynamoDBStore } = await import("./dynamodb-53YXEFIJ.js");
129
151
  const { DynamoDBClient } = await import("@aws-sdk/client-dynamodb");
130
152
  const client = "clientConfig" in config ? new DynamoDBClient(config.clientConfig) : config.client;
131
153
  return (_, sessionConfig) => {
@@ -135,13 +157,30 @@ var stores = {
135
157
  });
136
158
  };
137
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
+ });
138
178
  }
139
179
  };
140
180
 
141
181
  export {
142
- stubsRoot,
143
182
  configure,
144
183
  defineConfig,
145
184
  stores
146
185
  };
147
- //# sourceMappingURL=chunk-WUWXIKIB.js.map
186
+ //# sourceMappingURL=chunk-Q24L5XPC.js.map
@@ -0,0 +1 @@
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,QA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G,QAAQ,IAAI,cAAc,GAAG;AACnC,cAAM,IAAI;AAAA,UACR,gCAAgC,cAAc;AAAA,QAChD;AAAA,MACF;AAEA,aAAO,CAAC,GAAG,kBAAiC;AAC1C,eAAO,IAAI,cAAc,GAAG,WAAW,cAAc,GAAG,cAAc,KAAK;AAAA,UACzE,WAAW,QAAQ;AAAA,UACnB,eAAe,QAAQ;AAAA,QACzB,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["stores"]}
@@ -0,0 +1,8 @@
1
+ // stubs/main.ts
2
+ import { getDirname } from "@poppinss/utils";
3
+ var stubsRoot = getDirname(import.meta.url);
4
+
5
+ export {
6
+ stubsRoot
7
+ };
8
+ //# sourceMappingURL=chunk-V3OAEXMJ.js.map
@@ -0,0 +1 @@
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":[]}
@@ -3,15 +3,18 @@ import {
3
3
  ValuesStore
4
4
  } from "./chunk-TE5JP3SX.js";
5
5
  import {
6
- __export,
7
6
  debug_default
8
- } from "./chunk-ZVSEMDIC.js";
7
+ } from "./chunk-5ECC6OWF.js";
8
+ import {
9
+ __export
10
+ } from "./chunk-PZ5AY32C.js";
9
11
 
10
12
  // src/errors.ts
11
13
  var errors_exports = {};
12
14
  __export(errors_exports, {
13
15
  E_SESSION_NOT_MUTABLE: () => E_SESSION_NOT_MUTABLE,
14
- E_SESSION_NOT_READY: () => E_SESSION_NOT_READY
16
+ E_SESSION_NOT_READY: () => E_SESSION_NOT_READY,
17
+ E_SESSION_TAGGING_NOT_SUPPORTED: () => E_SESSION_TAGGING_NOT_SUPPORTED
15
18
  });
16
19
  import { createError } from "@poppinss/utils";
17
20
  var E_SESSION_NOT_MUTABLE = createError(
@@ -24,6 +27,11 @@ var E_SESSION_NOT_READY = createError(
24
27
  "E_SESSION_NOT_READY",
25
28
  500
26
29
  );
30
+ var E_SESSION_TAGGING_NOT_SUPPORTED = createError(
31
+ "Session store does not support tagging operations. Only Redis, Database and Memory stores support tagging.",
32
+ "E_SESSION_TAGGING_NOT_SUPPORTED",
33
+ 500
34
+ );
27
35
 
28
36
  // src/session.ts
29
37
  import Macroable from "@poppinss/macroable";
@@ -336,6 +344,17 @@ var Session = class extends Macroable {
336
344
  regenerate() {
337
345
  this.#sessionId = cuid();
338
346
  }
347
+ /**
348
+ * Tag the current session with a user ID. This allows you to
349
+ * later retrieve all sessions for a given user via SessionCollection.
350
+ *
351
+ * Only Memory, Redis and Database stores support tagging. Other stores
352
+ * will throw an error.
353
+ */
354
+ async tag(userId) {
355
+ if (!("tag" in this.#store)) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
356
+ await this.#store.tag(this.#sessionId, userId);
357
+ }
339
358
  /**
340
359
  * Commit session changes. No more mutations will be
341
360
  * allowed after commit.
@@ -388,7 +407,8 @@ var Session = class extends Macroable {
388
407
  };
389
408
 
390
409
  export {
410
+ E_SESSION_TAGGING_NOT_SUPPORTED,
391
411
  errors_exports,
392
412
  Session
393
413
  };
394
- //# sourceMappingURL=chunk-OCQGCVXK.js.map
414
+ //# sourceMappingURL=chunk-XP3CBOXR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/session.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 { createError } from '@poppinss/utils'\n\n/**\n * Raised when session store is not mutable\n */\nexport const E_SESSION_NOT_MUTABLE = createError(\n 'Session store is in readonly mode and cannot be mutated',\n 'E_SESSION_NOT_MUTABLE',\n 500\n)\n\n/**\n * Raised when session store has been initiated\n */\nexport const E_SESSION_NOT_READY = createError(\n 'Session store has not been initiated. Make sure you have registered the session middleware',\n 'E_SESSION_NOT_READY',\n 500\n)\n\n/**\n * Raised when trying to use tagging with a store that\n * doesn't support tagging operations\n */\nexport const E_SESSION_TAGGING_NOT_SUPPORTED = createError(\n 'Session store does not support tagging operations. Only Redis, Database and Memory stores support tagging.',\n 'E_SESSION_TAGGING_NOT_SUPPORTED',\n 500\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 { I18n } from '@adonisjs/i18n'\nimport Macroable from '@poppinss/macroable'\nimport lodash from '@poppinss/utils/lodash'\nimport { cuid } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterService } from '@adonisjs/core/types'\nimport type { HttpError } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport * as errors from './errors.js'\nimport { ReadOnlyValuesStore, ValuesStore } from './values_store.js'\nimport type {\n SessionData,\n SessionConfig,\n SessionStoreFactory,\n AllowedSessionValues,\n SessionStoreContract,\n SessionStoreWithTaggingContract,\n} from './types.js'\n\n/**\n * The session class exposes the API to read and write values to\n * the session store.\n *\n * A session instance is isolated between requests but\n * uses a centralized persistence store and\n */\nexport class Session extends Macroable {\n #store: SessionStoreContract | SessionStoreWithTaggingContract\n #emitter: EmitterService\n #ctx: HttpContext\n #readonly: boolean = false\n\n /**\n * Session values store\n */\n #valuesStore?: ValuesStore\n\n /**\n * Session id refers to the session id that will be committed\n * as a cookie during the response.\n */\n #sessionId: string\n\n /**\n * Session id from cookie refers to the value we read from the\n * cookie during the HTTP request.\n *\n * This only might not exist during the first request. Also during\n * session id re-generation, this value will be different from\n * the session id.\n */\n #sessionIdFromCookie?: string\n\n /**\n * Store of flash messages that be written during the\n * HTTP request\n */\n responseFlashMessages = new ValuesStore({})\n\n /**\n * Store of flash messages for the current HTTP request.\n */\n flashMessages = new ValuesStore({})\n\n /**\n * The key to use for storing flash messages inside\n * the session store.\n */\n flashKey: string = '__flash__'\n\n /**\n * Session id for the current HTTP request\n */\n get sessionId() {\n return this.#sessionId\n }\n\n /**\n * A boolean to know if a fresh session is created during\n * the request\n */\n get fresh(): boolean {\n return this.#sessionIdFromCookie === undefined\n }\n\n /**\n * A boolean to know if session is in readonly\n * state\n */\n get readonly() {\n return this.#readonly\n }\n\n /**\n * A boolean to know if session store has been initiated\n */\n get initiated() {\n return !!this.#valuesStore\n }\n\n /**\n * A boolean to know if the session id has been re-generated\n * during the current request\n */\n get hasRegeneratedSession() {\n return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId)\n }\n\n /**\n * A boolean to know if the session store is empty\n */\n get isEmpty() {\n return this.#valuesStore?.isEmpty ?? true\n }\n\n /**\n * A boolean to know if the session store has been\n * modified\n */\n get hasBeenModified() {\n return this.#valuesStore?.hasBeenModified ?? false\n }\n\n constructor(\n public config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n super()\n this.#ctx = ctx\n this.#emitter = emitter\n this.#store = storeFactory(ctx, config)\n this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, undefined)\n this.#sessionId = this.#sessionIdFromCookie || cuid()\n }\n\n /**\n * Returns the flash messages store for a given\n * mode\n */\n #getFlashStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.responseFlashMessages\n }\n\n /**\n * Returns the store instance for a given mode\n */\n #getValuesStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.#valuesStore\n }\n\n /**\n * Initiates the session store. The method results in a noop\n * when called multiple times\n */\n async initiate(readonly: boolean): Promise<void> {\n if (this.#valuesStore) {\n return\n }\n\n debug('initiating session (readonly: %s)', readonly)\n\n this.#readonly = readonly\n const contents = await this.#store.read(this.#sessionId)\n this.#valuesStore = new ValuesStore(contents)\n\n /**\n * Extract flash messages from the store and keep a local\n * copy of it.\n */\n if (this.has(this.flashKey)) {\n debug('reading flash data')\n if (this.#readonly) {\n this.flashMessages.update(this.get(this.flashKey, null))\n } else {\n this.flashMessages.update(this.pull(this.flashKey, null))\n }\n }\n\n /**\n * Share session with the templates. We assume the view property\n * is a reference to edge templates\n */\n if ('view' in this.#ctx) {\n this.#ctx.view.share({\n session: new ReadOnlyValuesStore(this.#valuesStore.all()),\n flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),\n old: function (key: string, defaultValue?: any) {\n return this.flashMessages.get(key, defaultValue)\n },\n })\n }\n\n this.#emitter.emit('session:initiated', { session: this })\n }\n\n /**\n * Put a key-value pair to the session data store\n */\n put(key: string, value: AllowedSessionValues) {\n this.#getValuesStore('write').set(key, value)\n }\n\n /**\n * Check if a key exists inside the datastore\n */\n has(key: string): boolean {\n return this.#getValuesStore('read').has(key)\n }\n\n /**\n * Get the value of a key from the session datastore.\n * You can specify a default value to use, when key\n * does not exists or has undefined value.\n */\n get(key: string, defaultValue?: any) {\n return this.#getValuesStore('read').get(key, defaultValue)\n }\n\n /**\n * Get everything from the session store\n */\n all() {\n return this.#getValuesStore('read').all()\n }\n\n /**\n * Remove a key from the session datastore\n */\n forget(key: string) {\n return this.#getValuesStore('write').unset(key)\n }\n\n /**\n * Read value for a key from the session datastore\n * and remove it simultaneously.\n */\n pull(key: string, defaultValue?: any) {\n return this.#getValuesStore('write').pull(key, defaultValue)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be 1\n */\n increment(key: string, steps: number = 1) {\n return this.#getValuesStore('write').increment(key, steps)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be -1\n */\n decrement(key: string, steps: number = 1) {\n return this.#getValuesStore('write').decrement(key, steps)\n }\n\n /**\n * Empty the session store\n */\n clear() {\n return this.#getValuesStore('write').clear()\n }\n\n /**\n * Add a key-value pair to flash messages\n */\n flash(key: string, value: AllowedSessionValues): void\n flash(keyValue: SessionData): void\n flash(key: string | SessionData, value?: AllowedSessionValues): void {\n if (typeof key === 'string') {\n if (value) {\n this.#getFlashStore('write').set(key, value)\n }\n } else {\n this.#getFlashStore('write').merge(key)\n }\n }\n\n /**\n * Flash errors to the errorsBag. You can read these\n * errors via the \"@error\" tag.\n *\n * Appends new messages to the existing collection.\n */\n flashErrors(errorsCollection: Record<string, string | string[]>) {\n this.flash({ errorsBag: errorsCollection })\n }\n\n /**\n * Flash validation error messages. Make sure the error\n * is an instance of VineJS ValidationException.\n *\n * Overrides existing inputErrors\n */\n flashValidationErrors(error: HttpError) {\n const errorsBag = error.messages.reduce((result: Record<string, string[]>, message: any) => {\n if (result[message.field]) {\n result[message.field].push(message.message)\n } else {\n result[message.field] = [message.message]\n }\n return result\n }, {})\n\n this.flashExcept(['_csrf', '_method', 'password', 'password_confirmation'])\n\n /**\n * Adding the error summary to the \"errorsBag\" so that\n * we display the validation error globally using\n * the \"@error\" tag.\n */\n let summary = 'The form could not be saved. Please check the errors below.'\n if ('i18n' in this.#ctx) {\n summary = (this.#ctx.i18n as I18n).t(\n `errors.${error.code}`,\n {\n count: error.messages.length,\n },\n summary\n )\n }\n\n this.flashErrors({\n [String(error.code)]: summary,\n })\n\n /**\n * Adding to inputErrorsBag for \"@inputError\" tag\n * to read validation errors\n */\n this.flash('inputErrorsBag', errorsBag)\n\n /**\n * For legacy support and not to break apps using\n * the older version of @adonisjs/session package\n */\n this.flash('errors', errorsBag)\n }\n\n /**\n * Flash form input data to the flash messages store\n */\n flashAll() {\n return this.#getFlashStore('write').set('input', this.#ctx.request.original())\n }\n\n /**\n * Flash form input data (except some keys) to the flash messages store\n */\n flashExcept(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.omit(this.#ctx.request.original(), keys))\n }\n\n /**\n * Flash form input data (only some keys) to the flash messages store\n */\n flashOnly(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.pick(this.#ctx.request.original(), keys))\n }\n\n /**\n * Reflash messages from the last request in the current response\n */\n reflash(): void {\n this.#getFlashStore('write').set('reflashed', this.flashMessages.all())\n }\n\n /**\n * Reflash messages (only some keys) from the last\n * request in the current response\n */\n reflashOnly(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.pick(this.flashMessages.all(), keys))\n }\n\n /**\n * Reflash messages (except some keys) from the last\n * request in the current response\n */\n reflashExcept(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.omit(this.flashMessages.all(), keys))\n }\n\n /**\n * Re-generate the session id and migrate data to it.\n */\n regenerate() {\n this.#sessionId = cuid()\n }\n\n /**\n * Tag the current session with a user ID. This allows you to\n * later retrieve all sessions for a given user via SessionCollection.\n *\n * Only Memory, Redis and Database stores support tagging. Other stores\n * will throw an error.\n */\n async tag(userId: string): Promise<void> {\n if (!('tag' in this.#store)) throw new errors.E_SESSION_TAGGING_NOT_SUPPORTED()\n await this.#store.tag(this.#sessionId, userId)\n }\n\n /**\n * Commit session changes. No more mutations will be\n * allowed after commit.\n */\n async commit() {\n if (!this.#valuesStore || this.readonly) {\n return\n }\n\n /**\n * If the flash messages store is not empty, we should put\n * its messages inside main session store.\n */\n if (!this.responseFlashMessages.isEmpty) {\n const { input, reflashed, ...others } = this.responseFlashMessages.all()\n this.put(this.flashKey, { ...reflashed, ...input, ...others })\n }\n\n debug('committing session data')\n\n /**\n * Touch the session id cookie to stay alive\n */\n this.#ctx.response.cookie(this.config.cookieName, this.#sessionId, this.config.cookie!)\n\n /**\n * Delete the session data when the session store\n * is empty.\n *\n * Also we only destroy the session id we read from the cookie.\n * If there was no session id in the cookie, there won't be\n * any data inside the store either.\n */\n if (this.isEmpty) {\n if (this.#sessionIdFromCookie) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Touch the store expiry when the session store was\n * not modified.\n */\n if (!this.hasBeenModified) {\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.touch(this.#sessionId)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Otherwise commit to the session store\n */\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n }\n\n this.#emitter.emit('session:committed', { session: this })\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,SAAS,mBAAmB;AAKrB,IAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF;AAKO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF;AAMO,IAAM,kCAAkC;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF;;;AC3BA,OAAO,eAAe;AACtB,OAAO,YAAY;AACnB,SAAS,YAAY;AAwBd,IAAM,UAAN,cAAsB,UAAU;AAAA,EAiGrC,YACS,QACP,cACA,SACA,KACA;AACA,UAAM;AALC;AAMP,SAAK,OAAO;AACZ,SAAK,WAAW;AAChB,SAAK,SAAS,aAAa,KAAK,MAAM;AACtC,SAAK,uBAAuB,IAAI,QAA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AAS,KAAK,qBAAqB,EAAE,SAAS,KAAK,CAAC;AACzD;AAAA,IACF;AAMA,QAAI,CAAC,KAAK,iBAAiB;AACzB,UAAI,KAAK,wBAAwB,KAAK,yBAAyB,KAAK,YAAY;AAC9E,cAAM,KAAK,OAAO,QAAQ,KAAK,oBAAoB;AACnD,cAAM,KAAK,OAAO,MAAM,KAAK,YAAY,KAAK,aAAa,OAAO,CAAC;AACnE,aAAK,SAAS,KAAK,oBAAoB;AAAA,UACrC,eAAe,KAAK;AAAA,UACpB,aAAa,KAAK;AAAA,UAClB,SAAS;AAAA,QACX,CAAC;AAAA,MACH,OAAO;AACL,cAAM,KAAK,OAAO,MAAM,KAAK,UAAU;AAAA,MACzC;AACA,WAAK,SAAS,KAAK,qBAAqB,EAAE,SAAS,KAAK,CAAC;AACzD;AAAA,IACF;AAKA,QAAI,KAAK,wBAAwB,KAAK,yBAAyB,KAAK,YAAY;AAC9E,YAAM,KAAK,OAAO,QAAQ,KAAK,oBAAoB;AACnD,YAAM,KAAK,OAAO,MAAM,KAAK,YAAY,KAAK,aAAa,OAAO,CAAC;AACnE,WAAK,SAAS,KAAK,oBAAoB;AAAA,QACrC,eAAe,KAAK;AAAA,QACpB,aAAa,KAAK;AAAA,QAClB,SAAS;AAAA,MACX,CAAC;AAAA,IACH,OAAO;AACL,YAAM,KAAK,OAAO,MAAM,KAAK,YAAY,KAAK,aAAa,OAAO,CAAC;AAAA,IACrE;AAEA,SAAK,SAAS,KAAK,qBAAqB,EAAE,SAAS,KAAK,CAAC;AAAA,EAC3D;AACF;","names":[]}
@@ -0,0 +1 @@
1
+ {"commands":[{"commandName":"make:session-table","description":"Create a migration for the sessions database table","help":"","namespace":"make","aliases":[],"flags":[],"args":[],"options":{},"filePath":"make_session_table.js"}],"version":1}
@@ -0,0 +1,4 @@
1
+ import { CommandMetaData, Command } from '@adonisjs/ace/types';
2
+
3
+ export function getMetaData(): Promise<CommandMetaData[]>
4
+ export function getCommand(metaData: CommandMetaData): Promise<Command | null>
@@ -0,0 +1,36 @@
1
+ import { readFile } from 'node:fs/promises'
2
+
3
+ /**
4
+ * In-memory cache of commands after they have been loaded
5
+ */
6
+ let commandsMetaData
7
+
8
+ /**
9
+ * Reads the commands from the "./commands.json" file. Since, the commands.json
10
+ * file is generated automatically, we do not have to validate its contents
11
+ */
12
+ export async function getMetaData() {
13
+ if (commandsMetaData) {
14
+ return commandsMetaData
15
+ }
16
+
17
+ const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
18
+ commandsMetaData = JSON.parse(commandsIndex).commands
19
+
20
+ return commandsMetaData
21
+ }
22
+
23
+ /**
24
+ * Imports the command by lookingup its path from the commands
25
+ * metadata
26
+ */
27
+ export async function getCommand(metaData) {
28
+ const commands = await getMetaData()
29
+ const command = commands.find(({ commandName }) => metaData.commandName === commandName)
30
+ if (!command) {
31
+ return null
32
+ }
33
+
34
+ const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
35
+ return commandConstructor
36
+ }
@@ -0,0 +1,9 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ /**
3
+ * Command to create the sessions table migration
4
+ */
5
+ export default class MakeSessionTable extends BaseCommand {
6
+ static commandName: string;
7
+ static description: string;
8
+ run(): Promise<void>;
9
+ }
@@ -0,0 +1,21 @@
1
+ import {
2
+ stubsRoot
3
+ } from "../chunk-V3OAEXMJ.js";
4
+ import "../chunk-PZ5AY32C.js";
5
+
6
+ // commands/make_session_table.ts
7
+ import { BaseCommand } from "@adonisjs/core/ace";
8
+ var MakeSessionTable = class extends BaseCommand {
9
+ static commandName = "make:session-table";
10
+ static description = "Create a migration for the sessions database table";
11
+ async run() {
12
+ const codemods = await this.createCodemods();
13
+ await codemods.makeUsingStub(stubsRoot, "make/migration/sessions.stub", {
14
+ migration: { tableName: "sessions", prefix: Date.now() }
15
+ });
16
+ }
17
+ };
18
+ export {
19
+ MakeSessionTable as default
20
+ };
21
+ //# sourceMappingURL=make_session_table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../commands/make_session_table.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 { stubsRoot } from '../stubs/main.js'\nimport { BaseCommand } from '@adonisjs/core/ace'\n\n/**\n * Command to create the sessions table migration\n */\nexport default class MakeSessionTable extends BaseCommand {\n static commandName = 'make:session-table'\n static description = 'Create a migration for the sessions database table'\n\n async run() {\n const codemods = await this.createCodemods()\n await codemods.makeUsingStub(stubsRoot, 'make/migration/sessions.stub', {\n migration: { tableName: 'sessions', prefix: Date.now() },\n })\n }\n}\n"],"mappings":";;;;;;AAUA,SAAS,mBAAmB;AAK5B,IAAqB,mBAArB,cAA8C,YAAY;AAAA,EACxD,OAAO,cAAc;AAAA,EACrB,OAAO,cAAc;AAAA,EAErB,MAAM,MAAM;AACV,UAAM,WAAW,MAAM,KAAK,eAAe;AAC3C,UAAM,SAAS,cAAc,WAAW,gCAAgC;AAAA,MACtE,WAAW,EAAE,WAAW,YAAY,QAAQ,KAAK,IAAI,EAAE;AAAA,IACzD,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  debug_default
3
- } from "./chunk-ZVSEMDIC.js";
3
+ } from "./chunk-5ECC6OWF.js";
4
+ import "./chunk-PZ5AY32C.js";
4
5
 
5
6
  // src/stores/cookie.ts
6
7
  var CookieStore = class {
@@ -53,4 +54,4 @@ var CookieStore = class {
53
54
  export {
54
55
  CookieStore
55
56
  };
56
- //# sourceMappingURL=cookie-WBWYVEDW.js.map
57
+ //# sourceMappingURL=cookie-3C33DMWA.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/stores/cookie.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 { HttpContext } from '@adonisjs/core/http'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from '../debug.js'\nimport type { SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * Cookie store stores the session data inside an encrypted\n * cookie.\n */\nexport class CookieStore implements SessionStoreContract {\n #ctx: HttpContext\n #config: Partial<CookieOptions>\n\n constructor(config: Partial<CookieOptions>, ctx: HttpContext) {\n this.#config = config\n this.#ctx = ctx\n debug('initiating cookie store %O', this.#config)\n }\n\n /**\n * Read session value from the cookie\n */\n read(sessionId: string): SessionData | null {\n debug('cookie store: reading session data %s', sessionId)\n\n const cookieValue = this.#ctx.request.encryptedCookie(sessionId)\n if (typeof cookieValue !== 'object') {\n return null\n }\n\n return cookieValue\n }\n\n /**\n * Write session values to the cookie\n */\n write(sessionId: string, values: SessionData): void {\n debug('cookie store: writing session data %s: %O', sessionId, values)\n this.#ctx.response.encryptedCookie(sessionId, values, this.#config)\n }\n\n /**\n * Removes the session cookie\n */\n destroy(sessionId: string): void {\n debug('cookie store: destroying session data %s', sessionId)\n if (this.#ctx.request.cookiesList()[sessionId]) {\n this.#ctx.response.clearCookie(sessionId)\n }\n }\n\n /**\n * Updates the cookie with existing cookie values\n */\n touch(sessionId: string): void {\n const value = this.read(sessionId)\n debug('cookie store: touching session data %s', sessionId)\n if (!value) {\n return\n }\n\n this.write(sessionId, value)\n }\n}\n"],"mappings":";;;;;AAmBO,IAAM,cAAN,MAAkD;AAAA,EACvD;AAAA,EACA;AAAA,EAEA,YAAY,QAAgC,KAAkB;AAC5D,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,kBAAM,8BAA8B,KAAK,OAAO;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,WAAuC;AAC1C,kBAAM,yCAAyC,SAAS;AAExD,UAAM,cAAc,KAAK,KAAK,QAAQ,gBAAgB,SAAS;AAC/D,QAAI,OAAO,gBAAgB,UAAU;AACnC,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAmB,QAA2B;AAClD,kBAAM,6CAA6C,WAAW,MAAM;AACpE,SAAK,KAAK,SAAS,gBAAgB,WAAW,QAAQ,KAAK,OAAO;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,WAAyB;AAC/B,kBAAM,4CAA4C,SAAS;AAC3D,QAAI,KAAK,KAAK,QAAQ,YAAY,EAAE,SAAS,GAAG;AAC9C,WAAK,KAAK,SAAS,YAAY,SAAS;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAyB;AAC7B,UAAM,QAAQ,KAAK,KAAK,SAAS;AACjC,kBAAM,0CAA0C,SAAS;AACzD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,SAAK,MAAM,WAAW,KAAK;AAAA,EAC7B;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/stores/cookie.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 { HttpContext } from '@adonisjs/core/http'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from '../debug.js'\nimport type { SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * Cookie store stores the session data inside an encrypted\n * cookie.\n */\nexport class CookieStore implements SessionStoreContract {\n #ctx: HttpContext\n #config: Partial<CookieOptions>\n\n constructor(config: Partial<CookieOptions>, ctx: HttpContext) {\n this.#config = config\n this.#ctx = ctx\n debug('initiating cookie store %O', this.#config)\n }\n\n /**\n * Read session value from the cookie\n */\n read(sessionId: string): SessionData | null {\n debug('cookie store: reading session data %s', sessionId)\n\n const cookieValue = this.#ctx.request.encryptedCookie(sessionId)\n if (typeof cookieValue !== 'object') {\n return null\n }\n\n return cookieValue\n }\n\n /**\n * Write session values to the cookie\n */\n write(sessionId: string, values: SessionData): void {\n debug('cookie store: writing session data %s: %O', sessionId, values)\n this.#ctx.response.encryptedCookie(sessionId, values, this.#config)\n }\n\n /**\n * Removes the session cookie\n */\n destroy(sessionId: string): void {\n debug('cookie store: destroying session data %s', sessionId)\n if (this.#ctx.request.cookiesList()[sessionId]) {\n this.#ctx.response.clearCookie(sessionId)\n }\n }\n\n /**\n * Updates the cookie with existing cookie values\n */\n touch(sessionId: string): void {\n const value = this.read(sessionId)\n debug('cookie store: touching session data %s', sessionId)\n if (!value) {\n return\n }\n\n this.write(sessionId, value)\n }\n}\n"],"mappings":";;;;;;AAmBO,IAAM,cAAN,MAAkD;AAAA,EACvD;AAAA,EACA;AAAA,EAEA,YAAY,QAAgC,KAAkB;AAC5D,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,kBAAM,8BAA8B,KAAK,OAAO;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA,EAKA,KAAK,WAAuC;AAC1C,kBAAM,yCAAyC,SAAS;AAExD,UAAM,cAAc,KAAK,KAAK,QAAQ,gBAAgB,SAAS;AAC/D,QAAI,OAAO,gBAAgB,UAAU;AACnC,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAmB,QAA2B;AAClD,kBAAM,6CAA6C,WAAW,MAAM;AACpE,SAAK,KAAK,SAAS,gBAAgB,WAAW,QAAQ,KAAK,OAAO;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ,WAAyB;AAC/B,kBAAM,4CAA4C,SAAS;AAC3D,QAAI,KAAK,KAAK,QAAQ,YAAY,EAAE,SAAS,GAAG;AAC9C,WAAK,KAAK,SAAS,YAAY,SAAS;AAAA,IAC1C;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAyB;AAC7B,UAAM,QAAQ,KAAK,KAAK,SAAS;AACjC,kBAAM,0CAA0C,SAAS;AACzD,QAAI,CAAC,OAAO;AACV;AAAA,IACF;AAEA,SAAK,MAAM,WAAW,KAAK;AAAA,EAC7B;AACF;","names":[]}