@adonisjs/session 7.0.0-9 → 7.0.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 (76) hide show
  1. package/build/chunk-2X5L327N.js +28 -0
  2. package/build/chunk-2X5L327N.js.map +1 -0
  3. package/build/chunk-7YIO32ZH.js +134 -0
  4. package/build/chunk-7YIO32ZH.js.map +1 -0
  5. package/build/chunk-K4OSGJVW.js +402 -0
  6. package/build/chunk-K4OSGJVW.js.map +1 -0
  7. package/build/chunk-S6P3TBEK.js +85 -0
  8. package/build/chunk-S6P3TBEK.js.map +1 -0
  9. package/build/chunk-TE5JP3SX.js +151 -0
  10. package/build/chunk-TE5JP3SX.js.map +1 -0
  11. package/build/chunk-WBAYBMJJ.js +15 -0
  12. package/build/chunk-WBAYBMJJ.js.map +1 -0
  13. package/build/config/session.stub +51 -0
  14. package/build/cookie-H7KRZB4T.js +56 -0
  15. package/build/cookie-H7KRZB4T.js.map +1 -0
  16. package/build/factories/main.d.ts +1 -0
  17. package/build/factories/main.js +50 -0
  18. package/build/factories/main.js.map +1 -0
  19. package/build/factories/session_middleware_factory.d.ts +27 -0
  20. package/build/file-YO7C2QWO.js +112 -0
  21. package/build/file-YO7C2QWO.js.map +1 -0
  22. package/build/index.d.ts +1 -3
  23. package/build/index.js +18 -14
  24. package/build/index.js.map +1 -0
  25. package/build/providers/session_provider.d.ts +22 -5
  26. package/build/providers/session_provider.js +51 -59
  27. package/build/providers/session_provider.js.map +1 -0
  28. package/build/redis-KDWIBKUQ.js +58 -0
  29. package/build/redis-KDWIBKUQ.js.map +1 -0
  30. package/build/src/client.d.ts +24 -19
  31. package/build/src/client.js +9 -81
  32. package/build/src/client.js.map +1 -0
  33. package/build/src/debug.d.ts +1 -1
  34. package/build/src/define_config.d.ts +24 -3
  35. package/build/src/{edge_plugin_adonisjs_session.d.ts → plugins/edge.d.ts} +1 -1
  36. package/build/src/plugins/edge.js +102 -0
  37. package/build/src/plugins/edge.js.map +1 -0
  38. package/build/src/plugins/japa/api_client.d.ts +75 -0
  39. package/build/src/plugins/japa/api_client.js +100 -0
  40. package/build/src/plugins/japa/api_client.js.map +1 -0
  41. package/build/src/plugins/japa/browser_client.d.ts +36 -0
  42. package/build/src/plugins/japa/browser_client.js +88 -0
  43. package/build/src/plugins/japa/browser_client.js.map +1 -0
  44. package/build/src/session.d.ts +21 -12
  45. package/build/src/session_middleware.d.ts +7 -4
  46. package/build/src/session_middleware.js +10 -59
  47. package/build/src/session_middleware.js.map +1 -0
  48. package/build/src/{drivers → stores}/cookie.d.ts +4 -4
  49. package/build/src/{drivers → stores}/file.d.ts +4 -4
  50. package/build/src/{drivers → stores}/memory.d.ts +3 -3
  51. package/build/src/{drivers → stores}/redis.d.ts +5 -5
  52. package/build/src/{types/main.d.ts → types.d.ts} +11 -31
  53. package/build/src/types.js +1 -0
  54. package/build/src/types.js.map +1 -0
  55. package/build/src/{store.d.ts → values_store.d.ts} +10 -10
  56. package/package.json +74 -43
  57. package/build/configure.js +0 -45
  58. package/build/src/debug.js +0 -10
  59. package/build/src/define_config.js +0 -42
  60. package/build/src/drivers/cookie.js +0 -60
  61. package/build/src/drivers/file.js +0 -133
  62. package/build/src/drivers/memory.js +0 -33
  63. package/build/src/drivers/redis.js +0 -70
  64. package/build/src/drivers_collection.d.ts +0 -22
  65. package/build/src/drivers_collection.js +0 -38
  66. package/build/src/edge_plugin_adonisjs_session.js +0 -92
  67. package/build/src/errors.js +0 -17
  68. package/build/src/helpers.d.ts +0 -6
  69. package/build/src/helpers.js +0 -43
  70. package/build/src/session.js +0 -384
  71. package/build/src/store.js +0 -159
  72. package/build/src/types/extended.d.ts +0 -19
  73. package/build/src/types/extended.js +0 -9
  74. package/build/src/types/main.js +0 -9
  75. package/build/stubs/config.stub +0 -49
  76. package/build/stubs/main.js +0 -10
@@ -0,0 +1,28 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-WBAYBMJJ.js";
4
+
5
+ // src/errors.ts
6
+ var errors_exports = {};
7
+ __export(errors_exports, {
8
+ E_SESSION_NOT_MUTABLE: () => E_SESSION_NOT_MUTABLE,
9
+ E_SESSION_NOT_READY: () => E_SESSION_NOT_READY
10
+ });
11
+ import { createError } from "@poppinss/utils";
12
+ var E_SESSION_NOT_MUTABLE = createError(
13
+ "Session store is in readonly mode and cannot be mutated",
14
+ "E_SESSION_NOT_MUTABLE",
15
+ 500
16
+ );
17
+ var E_SESSION_NOT_READY = createError(
18
+ "Session store has not been initiated. Make sure you have registered the session middleware",
19
+ "E_SESSION_NOT_READY",
20
+ 500
21
+ );
22
+
23
+ export {
24
+ E_SESSION_NOT_MUTABLE,
25
+ E_SESSION_NOT_READY,
26
+ errors_exports
27
+ };
28
+ //# sourceMappingURL=chunk-2X5L327N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.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"],"mappings":";;;;;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;","names":[]}
@@ -0,0 +1,134 @@
1
+ import {
2
+ debug_default
3
+ } from "./chunk-WBAYBMJJ.js";
4
+
5
+ // stubs/main.ts
6
+ import { getDirname } from "@poppinss/utils";
7
+ var stubsRoot = getDirname(import.meta.url);
8
+
9
+ // configure.ts
10
+ async function configure(command) {
11
+ const codemods = await command.createCodemods();
12
+ await codemods.makeUsingStub(stubsRoot, "config/session.stub", {});
13
+ await codemods.defineEnvVariables({ SESSION_DRIVER: "cookie" });
14
+ await codemods.defineEnvValidations({
15
+ variables: {
16
+ SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`
17
+ },
18
+ leadingComment: "Variables for configuring session package"
19
+ });
20
+ await codemods.registerMiddleware("router", [
21
+ {
22
+ path: "@adonisjs/session/session_middleware"
23
+ }
24
+ ]);
25
+ await codemods.updateRcFile((rcFile) => {
26
+ rcFile.addProvider("@adonisjs/session/session_provider");
27
+ });
28
+ }
29
+
30
+ // src/define_config.ts
31
+ import string from "@poppinss/utils/string";
32
+ import { configProvider } from "@adonisjs/core";
33
+ import { InvalidArgumentsException } from "@poppinss/utils";
34
+
35
+ // src/stores/memory.ts
36
+ var MemoryStore = class _MemoryStore {
37
+ static sessions = /* @__PURE__ */ new Map();
38
+ /**
39
+ * Read session id value from the memory
40
+ */
41
+ read(sessionId) {
42
+ return _MemoryStore.sessions.get(sessionId) || null;
43
+ }
44
+ /**
45
+ * Save in memory value for a given session id
46
+ */
47
+ write(sessionId, values) {
48
+ _MemoryStore.sessions.set(sessionId, values);
49
+ }
50
+ /**
51
+ * Cleanup for a single session
52
+ */
53
+ destroy(sessionId) {
54
+ _MemoryStore.sessions.delete(sessionId);
55
+ }
56
+ touch() {
57
+ }
58
+ };
59
+
60
+ // src/define_config.ts
61
+ function defineConfig(config) {
62
+ debug_default("processing session config %O", config);
63
+ if (!config.store) {
64
+ throw new InvalidArgumentsException('Missing "store" property inside the session config');
65
+ }
66
+ const { stores: stores2, cookie, ...rest } = {
67
+ enabled: true,
68
+ age: "2h",
69
+ cookieName: "adonis_session",
70
+ clearWithBrowser: false,
71
+ ...config
72
+ };
73
+ const cookieOptions = { ...cookie };
74
+ if (!rest.clearWithBrowser) {
75
+ cookieOptions.maxAge = string.seconds.parse(rest.age);
76
+ debug_default('computing maxAge "%s" for session id cookie', cookieOptions.maxAge);
77
+ }
78
+ return configProvider.create(async (app) => {
79
+ const storesNames = Object.keys(config.stores);
80
+ const storesList = {
81
+ memory: () => new MemoryStore()
82
+ };
83
+ for (let storeName of storesNames) {
84
+ const store = config.stores[storeName];
85
+ if (typeof store === "function") {
86
+ storesList[storeName] = store;
87
+ } else {
88
+ storesList[storeName] = await store.resolver(app);
89
+ }
90
+ }
91
+ const transformedConfig = {
92
+ ...rest,
93
+ cookie: cookieOptions,
94
+ stores: storesList
95
+ };
96
+ debug_default("transformed session config %O", transformedConfig);
97
+ return transformedConfig;
98
+ });
99
+ }
100
+ var stores = {
101
+ file: (config) => {
102
+ return configProvider.create(async () => {
103
+ const { FileStore } = await import("./file-YO7C2QWO.js");
104
+ return (_, sessionConfig) => {
105
+ return new FileStore(config, sessionConfig.age);
106
+ };
107
+ });
108
+ },
109
+ redis: (config) => {
110
+ return configProvider.create(async (app) => {
111
+ const { RedisStore } = await import("./redis-KDWIBKUQ.js");
112
+ const redis = await app.container.make("redis");
113
+ return (_, sessionConfig) => {
114
+ return new RedisStore(redis.connection(config.connection), sessionConfig.age);
115
+ };
116
+ });
117
+ },
118
+ cookie: () => {
119
+ return configProvider.create(async () => {
120
+ const { CookieStore } = await import("./cookie-H7KRZB4T.js");
121
+ return (ctx, sessionConfig) => {
122
+ return new CookieStore(sessionConfig.cookie, ctx);
123
+ };
124
+ });
125
+ }
126
+ };
127
+
128
+ export {
129
+ stubsRoot,
130
+ configure,
131
+ defineConfig,
132
+ stores
133
+ };
134
+ //# sourceMappingURL=chunk-7YIO32ZH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../stubs/main.ts","../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 { getDirname } from '@poppinss/utils'\n\nexport const stubsRoot = getDirname(import.meta.url)\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 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\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/session/session_provider')\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\nimport string from '@poppinss/utils/string'\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport { InvalidArgumentsException } 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} 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} = {\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}\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, SessionStoreContract } from '../types.js'\n\n/**\n * Memory store is meant to be used for writing tests.\n */\nexport class MemoryStore implements SessionStoreContract {\n static sessions: Map<string, SessionData> = 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 }\n\n touch(): void {}\n}\n"],"mappings":";;;;;AASA,SAAS,kBAAkB;AAEpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACInD,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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AAI;AAAA,MAC1B,OAAO;AACL,mBAAW,SAAS,IAAI,MAAM,MAAM,SAAS,GAAG;AAAA,MAClD;AAAA,IACF;AAEA,UAAM,oBAAoB;AAAA,MACxB,GAAG;AAAA,MACH,QAAQ;AAAA,MACR,QAAQ;AAAA,IACV;AAEA,kBAAM,iCAAiC,iBAAiB;AACxD,WAAO;AAAA,EACT,CAAC;AACH;AAKO,IAAM,SAIT;AAAA,EACF,MAAM,CAAC,WAAW;AAChB,WAAO,eAAe,OAAO,YAAY;AACvC,YAAM,EAAE,UAAU,IAAI,MAAM,OAAO,oBAAkB;AACrD,aAAO,CAAC,GAAG,kBAAiC;AAC1C,eAAO,IAAI,UAAU,QAAQ,cAAc,GAAG;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,OAAO,CAAC,WAAW;AACjB,WAAO,eAAe,OAAO,OAAO,QAAQ;AAC1C,YAAM,EAAE,WAAW,IAAI,MAAM,OAAO,qBAAmB;AACvD,YAAM,QAAQ,MAAM,IAAI,UAAU,KAAK,OAAO;AAE9C,aAAO,CAAC,GAAG,kBAAiC;AAC1C,eAAO,IAAI,WAAW,MAAM,WAAW,OAAO,UAAU,GAAG,cAAc,GAAG;AAAA,MAC9E;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,QAAQ,MAAM;AACZ,WAAO,eAAe,OAAO,YAAY;AACvC,YAAM,EAAE,YAAY,IAAI,MAAM,OAAO,sBAAoB;AACzD,aAAO,CAAC,KAAK,kBAAiC;AAC5C,eAAO,IAAI,YAAY,cAAc,QAAQ,GAAG;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["stores"]}
@@ -0,0 +1,402 @@
1
+ import {
2
+ E_SESSION_NOT_MUTABLE,
3
+ E_SESSION_NOT_READY
4
+ } from "./chunk-2X5L327N.js";
5
+ import {
6
+ ReadOnlyValuesStore,
7
+ ValuesStore
8
+ } from "./chunk-TE5JP3SX.js";
9
+ import {
10
+ debug_default
11
+ } from "./chunk-WBAYBMJJ.js";
12
+
13
+ // src/session_middleware.ts
14
+ import { ExceptionHandler } from "@adonisjs/core/http";
15
+
16
+ // src/session.ts
17
+ import lodash from "@poppinss/utils/lodash";
18
+ import { cuid } from "@adonisjs/core/helpers";
19
+ var Session = class {
20
+ #config;
21
+ #store;
22
+ #emitter;
23
+ #ctx;
24
+ #readonly = false;
25
+ /**
26
+ * Session values store
27
+ */
28
+ #valuesStore;
29
+ /**
30
+ * Session id refers to the session id that will be committed
31
+ * as a cookie during the response.
32
+ */
33
+ #sessionId;
34
+ /**
35
+ * Session id from cookie refers to the value we read from the
36
+ * cookie during the HTTP request.
37
+ *
38
+ * This only might not exist during the first request. Also during
39
+ * session id re-generation, this value will be different from
40
+ * the session id.
41
+ */
42
+ #sessionIdFromCookie;
43
+ /**
44
+ * Store of flash messages that be written during the
45
+ * HTTP request
46
+ */
47
+ responseFlashMessages = new ValuesStore({});
48
+ /**
49
+ * Store of flash messages for the current HTTP request.
50
+ */
51
+ flashMessages = new ValuesStore({});
52
+ /**
53
+ * The key to use for storing flash messages inside
54
+ * the session store.
55
+ */
56
+ flashKey = "__flash__";
57
+ /**
58
+ * Session id for the current HTTP request
59
+ */
60
+ get sessionId() {
61
+ return this.#sessionId;
62
+ }
63
+ /**
64
+ * A boolean to know if a fresh session is created during
65
+ * the request
66
+ */
67
+ get fresh() {
68
+ return this.#sessionIdFromCookie === void 0;
69
+ }
70
+ /**
71
+ * A boolean to know if session is in readonly
72
+ * state
73
+ */
74
+ get readonly() {
75
+ return this.#readonly;
76
+ }
77
+ /**
78
+ * A boolean to know if session store has been initiated
79
+ */
80
+ get initiated() {
81
+ return !!this.#valuesStore;
82
+ }
83
+ /**
84
+ * A boolean to know if the session id has been re-generated
85
+ * during the current request
86
+ */
87
+ get hasRegeneratedSession() {
88
+ return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId);
89
+ }
90
+ /**
91
+ * A boolean to know if the session store is empty
92
+ */
93
+ get isEmpty() {
94
+ return this.#valuesStore?.isEmpty ?? true;
95
+ }
96
+ /**
97
+ * A boolean to know if the session store has been
98
+ * modified
99
+ */
100
+ get hasBeenModified() {
101
+ return this.#valuesStore?.hasBeenModified ?? false;
102
+ }
103
+ constructor(config, storeFactory, emitter, ctx) {
104
+ this.#ctx = ctx;
105
+ this.#config = config;
106
+ this.#emitter = emitter;
107
+ this.#store = storeFactory(ctx, config);
108
+ this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, void 0);
109
+ this.#sessionId = this.#sessionIdFromCookie || cuid();
110
+ }
111
+ /**
112
+ * Returns the flash messages store for a given
113
+ * mode
114
+ */
115
+ #getFlashStore(mode) {
116
+ if (!this.#valuesStore) {
117
+ throw new E_SESSION_NOT_READY();
118
+ }
119
+ if (mode === "write" && this.readonly) {
120
+ throw new E_SESSION_NOT_MUTABLE();
121
+ }
122
+ return this.responseFlashMessages;
123
+ }
124
+ /**
125
+ * Returns the store instance for a given mode
126
+ */
127
+ #getValuesStore(mode) {
128
+ if (!this.#valuesStore) {
129
+ throw new E_SESSION_NOT_READY();
130
+ }
131
+ if (mode === "write" && this.readonly) {
132
+ throw new E_SESSION_NOT_MUTABLE();
133
+ }
134
+ return this.#valuesStore;
135
+ }
136
+ /**
137
+ * Initiates the session store. The method results in a noop
138
+ * when called multiple times
139
+ */
140
+ async initiate(readonly) {
141
+ if (this.#valuesStore) {
142
+ return;
143
+ }
144
+ debug_default("initiating session (readonly: %s)", readonly);
145
+ this.#readonly = readonly;
146
+ const contents = await this.#store.read(this.#sessionId);
147
+ this.#valuesStore = new ValuesStore(contents);
148
+ if (this.has(this.flashKey)) {
149
+ debug_default("reading flash data");
150
+ if (this.#readonly) {
151
+ this.flashMessages.update(this.get(this.flashKey, null));
152
+ } else {
153
+ this.flashMessages.update(this.pull(this.flashKey, null));
154
+ }
155
+ }
156
+ if ("view" in this.#ctx) {
157
+ this.#ctx.view.share({
158
+ session: new ReadOnlyValuesStore(this.#valuesStore.all()),
159
+ flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),
160
+ old: function(key, defaultValue) {
161
+ return this.flashMessages.get(key, defaultValue);
162
+ }
163
+ });
164
+ }
165
+ this.#emitter.emit("session:initiated", { session: this });
166
+ }
167
+ /**
168
+ * Put a key-value pair to the session data store
169
+ */
170
+ put(key, value) {
171
+ this.#getValuesStore("write").set(key, value);
172
+ }
173
+ /**
174
+ * Check if a key exists inside the datastore
175
+ */
176
+ has(key) {
177
+ return this.#getValuesStore("read").has(key);
178
+ }
179
+ /**
180
+ * Get the value of a key from the session datastore.
181
+ * You can specify a default value to use, when key
182
+ * does not exists or has undefined value.
183
+ */
184
+ get(key, defaultValue) {
185
+ return this.#getValuesStore("read").get(key, defaultValue);
186
+ }
187
+ /**
188
+ * Get everything from the session store
189
+ */
190
+ all() {
191
+ return this.#getValuesStore("read").all();
192
+ }
193
+ /**
194
+ * Remove a key from the session datastore
195
+ */
196
+ forget(key) {
197
+ return this.#getValuesStore("write").unset(key);
198
+ }
199
+ /**
200
+ * Read value for a key from the session datastore
201
+ * and remove it simultaneously.
202
+ */
203
+ pull(key, defaultValue) {
204
+ return this.#getValuesStore("write").pull(key, defaultValue);
205
+ }
206
+ /**
207
+ * Increment the value of a key inside the session
208
+ * store.
209
+ *
210
+ * A new key will be defined if does not exists already.
211
+ * The value of a new key will be 1
212
+ */
213
+ increment(key, steps = 1) {
214
+ return this.#getValuesStore("write").increment(key, steps);
215
+ }
216
+ /**
217
+ * Increment the value of a key inside the session
218
+ * store.
219
+ *
220
+ * A new key will be defined if does not exists already.
221
+ * The value of a new key will be -1
222
+ */
223
+ decrement(key, steps = 1) {
224
+ return this.#getValuesStore("write").decrement(key, steps);
225
+ }
226
+ /**
227
+ * Empty the session store
228
+ */
229
+ clear() {
230
+ return this.#getValuesStore("write").clear();
231
+ }
232
+ flash(key, value) {
233
+ if (typeof key === "string") {
234
+ if (value) {
235
+ this.#getFlashStore("write").set(key, value);
236
+ }
237
+ } else {
238
+ this.#getFlashStore("write").merge(key);
239
+ }
240
+ }
241
+ /**
242
+ * Flash errors to the errorsBag. You can read these
243
+ * errors via the "@error" tag.
244
+ *
245
+ * Appends new messages to the existing collection.
246
+ */
247
+ flashErrors(errorsCollection) {
248
+ this.flash({ errorsBag: errorsCollection });
249
+ }
250
+ /**
251
+ * Flash validation error messages. Make sure the error
252
+ * is an instance of VineJS ValidationException.
253
+ *
254
+ * Overrides existing inputErrors
255
+ */
256
+ flashValidationErrors(error) {
257
+ const errorsBag = error.messages.reduce((result, message) => {
258
+ if (result[message.field]) {
259
+ result[message.field].push(message.message);
260
+ } else {
261
+ result[message.field] = [message.message];
262
+ }
263
+ return result;
264
+ }, {});
265
+ this.flashExcept(["_csrf", "_method"]);
266
+ this.flash("inputErrorsBag", errorsBag);
267
+ this.flash("errors", errorsBag);
268
+ }
269
+ /**
270
+ * Flash form input data to the flash messages store
271
+ */
272
+ flashAll() {
273
+ return this.#getFlashStore("write").set("input", this.#ctx.request.original());
274
+ }
275
+ /**
276
+ * Flash form input data (except some keys) to the flash messages store
277
+ */
278
+ flashExcept(keys) {
279
+ this.#getFlashStore("write").set("input", lodash.omit(this.#ctx.request.original(), keys));
280
+ }
281
+ /**
282
+ * Flash form input data (only some keys) to the flash messages store
283
+ */
284
+ flashOnly(keys) {
285
+ this.#getFlashStore("write").set("input", lodash.pick(this.#ctx.request.original(), keys));
286
+ }
287
+ /**
288
+ * Reflash messages from the last request in the current response
289
+ */
290
+ reflash() {
291
+ this.#getFlashStore("write").set("reflashed", this.flashMessages.all());
292
+ }
293
+ /**
294
+ * Reflash messages (only some keys) from the last
295
+ * request in the current response
296
+ */
297
+ reflashOnly(keys) {
298
+ this.#getFlashStore("write").set("reflashed", lodash.pick(this.flashMessages.all(), keys));
299
+ }
300
+ /**
301
+ * Reflash messages (except some keys) from the last
302
+ * request in the current response
303
+ */
304
+ reflashExcept(keys) {
305
+ this.#getFlashStore("write").set("reflashed", lodash.omit(this.flashMessages.all(), keys));
306
+ }
307
+ /**
308
+ * Re-generate the session id and migrate data to it.
309
+ */
310
+ regenerate() {
311
+ this.#sessionId = cuid();
312
+ }
313
+ /**
314
+ * Commit session changes. No more mutations will be
315
+ * allowed after commit.
316
+ */
317
+ async commit() {
318
+ if (!this.#valuesStore || this.readonly) {
319
+ return;
320
+ }
321
+ if (!this.responseFlashMessages.isEmpty) {
322
+ const { input, reflashed, ...others } = this.responseFlashMessages.all();
323
+ this.put(this.flashKey, { ...reflashed, ...input, ...others });
324
+ }
325
+ debug_default("committing session data");
326
+ this.#ctx.response.cookie(this.#config.cookieName, this.#sessionId, this.#config.cookie);
327
+ if (this.isEmpty) {
328
+ if (this.#sessionIdFromCookie) {
329
+ await this.#store.destroy(this.#sessionIdFromCookie);
330
+ }
331
+ this.#emitter.emit("session:committed", { session: this });
332
+ return;
333
+ }
334
+ if (!this.hasBeenModified) {
335
+ if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {
336
+ await this.#store.destroy(this.#sessionIdFromCookie);
337
+ await this.#store.write(this.#sessionId, this.#valuesStore.toJSON());
338
+ this.#emitter.emit("session:migrated", {
339
+ fromSessionId: this.#sessionIdFromCookie,
340
+ toSessionId: this.sessionId,
341
+ session: this
342
+ });
343
+ } else {
344
+ await this.#store.touch(this.#sessionId);
345
+ }
346
+ this.#emitter.emit("session:committed", { session: this });
347
+ return;
348
+ }
349
+ if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {
350
+ await this.#store.destroy(this.#sessionIdFromCookie);
351
+ await this.#store.write(this.#sessionId, this.#valuesStore.toJSON());
352
+ this.#emitter.emit("session:migrated", {
353
+ fromSessionId: this.#sessionIdFromCookie,
354
+ toSessionId: this.sessionId,
355
+ session: this
356
+ });
357
+ } else {
358
+ await this.#store.write(this.#sessionId, this.#valuesStore.toJSON());
359
+ }
360
+ this.#emitter.emit("session:committed", { session: this });
361
+ }
362
+ };
363
+
364
+ // src/session_middleware.ts
365
+ var originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML;
366
+ ExceptionHandler.macro("renderValidationErrorAsHTML", async function(error, ctx) {
367
+ if (ctx.session) {
368
+ ctx.session.flashValidationErrors(error);
369
+ ctx.response.redirect("back", true);
370
+ } else {
371
+ return originalErrorHandler(error, ctx);
372
+ }
373
+ });
374
+ var SessionMiddleware = class {
375
+ #config;
376
+ #emitter;
377
+ constructor(config, emitter) {
378
+ this.#config = config;
379
+ this.#emitter = emitter;
380
+ }
381
+ async handle(ctx, next) {
382
+ if (!this.#config.enabled) {
383
+ return next();
384
+ }
385
+ ctx.session = new Session(
386
+ this.#config,
387
+ this.#config.stores[this.#config.store],
388
+ // reference to store factory
389
+ this.#emitter,
390
+ ctx
391
+ );
392
+ await ctx.session.initiate(false);
393
+ const response = await next();
394
+ await ctx.session.commit();
395
+ return response;
396
+ }
397
+ };
398
+
399
+ export {
400
+ SessionMiddleware
401
+ };
402
+ //# sourceMappingURL=chunk-K4OSGJVW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/session_middleware.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 { EmitterService } from '@adonisjs/core/types'\nimport type { NextFn } from '@adonisjs/core/types/http'\nimport { ExceptionHandler, HttpContext } from '@adonisjs/core/http'\n\nimport { Session } from './session.js'\nimport type { SessionConfig, SessionStoreFactory } from './types.js'\n\n/**\n * HttpContext augmentations\n */\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n session: Session\n }\n}\n\n/**\n * Overwriting validation exception renderer\n */\nconst originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML\nExceptionHandler.macro('renderValidationErrorAsHTML', async function (error, ctx) {\n if (ctx.session) {\n ctx.session.flashValidationErrors(error)\n ctx.response.redirect('back', true)\n } else {\n return originalErrorHandler(error, ctx)\n }\n})\n\n/**\n * Session middleware is used to initiate the session store\n * and commit its values during an HTTP request\n */\nexport default class SessionMiddleware<KnownStores extends Record<string, SessionStoreFactory>> {\n #config: SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n }\n #emitter: EmitterService\n\n constructor(\n config: SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n },\n emitter: EmitterService\n ) {\n this.#config = config\n this.#emitter = emitter\n }\n\n async handle(ctx: HttpContext, next: NextFn) {\n if (!this.#config.enabled) {\n return next()\n }\n\n ctx.session = new Session(\n this.#config,\n this.#config.stores[this.#config.store], // reference to store factory\n this.#emitter,\n ctx\n )\n\n /**\n * Initiate session store\n */\n await ctx.session.initiate(false)\n\n /**\n * Call next middlewares or route handler\n */\n const response = await next()\n\n /**\n * Commit store mutations\n */\n await ctx.session.commit()\n\n /**\n * Return response\n */\n return response\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 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} 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 {\n #config: SessionConfig\n #store: SessionStoreContract\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 config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n this.#ctx = ctx\n this.#config = config\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'])\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 * 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":";;;;;;;;;;;;;AAWA,SAAS,wBAAqC;;;ACF9C,OAAO,YAAY;AACnB,SAAS,YAAY;AAuBd,IAAM,UAAN,MAAc;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,wBAAwB,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAK1C,gBAAgB,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlC,WAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,IAAI,YAAY;AACd,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,QAAiB;AACnB,WAAO,KAAK,yBAAyB;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,WAAW;AACb,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,YAAY;AACd,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA;AAA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