@adonisjs/session 7.0.0-11 → 7.0.0-13

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 (40) hide show
  1. package/build/configure.js +1 -1
  2. package/build/factories/session_middleware_factory.d.ts +9 -4
  3. package/build/factories/session_middleware_factory.js +5 -4
  4. package/build/index.d.ts +1 -3
  5. package/build/index.js +1 -3
  6. package/build/providers/session_provider.d.ts +22 -5
  7. package/build/providers/session_provider.js +21 -21
  8. package/build/src/client.d.ts +2 -2
  9. package/build/src/client.js +14 -14
  10. package/build/src/debug.d.ts +1 -1
  11. package/build/src/define_config.d.ts +24 -3
  12. package/build/src/define_config.js +80 -17
  13. package/build/src/plugins/japa/api_client.d.ts +2 -2
  14. package/build/src/plugins/japa/api_client.js +8 -12
  15. package/build/src/plugins/japa/browser_client.d.ts +2 -2
  16. package/build/src/plugins/japa/browser_client.js +8 -12
  17. package/build/src/session.d.ts +7 -7
  18. package/build/src/session.js +40 -37
  19. package/build/src/session_middleware.d.ts +7 -4
  20. package/build/src/session_middleware.js +2 -3
  21. package/build/src/{drivers → stores}/cookie.d.ts +4 -4
  22. package/build/src/{drivers → stores}/cookie.js +7 -7
  23. package/build/src/{drivers → stores}/file.d.ts +4 -4
  24. package/build/src/{drivers → stores}/file.js +8 -8
  25. package/build/src/{drivers → stores}/memory.d.ts +3 -3
  26. package/build/src/{drivers → stores}/memory.js +5 -5
  27. package/build/src/{drivers → stores}/redis.d.ts +5 -5
  28. package/build/src/{drivers → stores}/redis.js +14 -18
  29. package/build/src/{types/main.d.ts → types.d.ts} +11 -31
  30. package/build/src/{store.d.ts → values_store.d.ts} +3 -3
  31. package/build/src/{store.js → values_store.js} +2 -2
  32. package/build/stubs/config.stub +18 -18
  33. package/package.json +20 -20
  34. package/build/src/drivers_collection.d.ts +0 -21
  35. package/build/src/drivers_collection.js +0 -38
  36. package/build/src/helpers.d.ts +0 -6
  37. package/build/src/helpers.js +0 -43
  38. package/build/src/types/extended.d.ts +0 -19
  39. package/build/src/types/main.js +0 -9
  40. /package/build/src/{types/extended.js → types.js} +0 -0
@@ -24,7 +24,7 @@ export async function configure(command) {
24
24
  */
25
25
  await codemods.defineEnvValidations({
26
26
  variables: {
27
- SESSION_DRIVER: `Env.schema.enum(['cookie', 'redis', 'file', 'memory'] as const)`,
27
+ SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`,
28
28
  },
29
29
  leadingComment: 'Variables for configuring session package',
30
30
  });
@@ -1,7 +1,7 @@
1
1
  import { Emitter } from '@adonisjs/core/events';
2
- import { EventsList } from '@adonisjs/core/types';
3
- import { SessionConfig } from '../src/types/main.js';
2
+ import type { EventsList } from '@adonisjs/core/types';
4
3
  import SessionMiddleware from '../src/session_middleware.js';
4
+ import type { SessionConfig, SessionStoreFactory } from '../src/types.js';
5
5
  /**
6
6
  * Exposes the API to create an instance of the session middleware
7
7
  * without additional plumbing
@@ -12,11 +12,16 @@ export declare class SessionMiddlewareFactory {
12
12
  * Merge custom options
13
13
  */
14
14
  merge(options: {
15
- config?: Partial<SessionConfig>;
15
+ config?: Partial<SessionConfig> & {
16
+ store: string;
17
+ stores: Record<string, SessionStoreFactory>;
18
+ };
16
19
  emitter?: Emitter<EventsList>;
17
20
  }): this;
18
21
  /**
19
22
  * Creates an instance of the session middleware
20
23
  */
21
- create(): Promise<SessionMiddleware>;
24
+ create(): Promise<SessionMiddleware<{
25
+ [x: string]: SessionStoreFactory;
26
+ }>>;
22
27
  }
@@ -9,14 +9,16 @@
9
9
  import { Emitter } from '@adonisjs/core/events';
10
10
  import { AppFactory } from '@adonisjs/core/factories/app';
11
11
  import { defineConfig } from '../index.js';
12
- import { registerSessionDriver } from '../src/helpers.js';
13
12
  import SessionMiddleware from '../src/session_middleware.js';
14
13
  /**
15
14
  * Exposes the API to create an instance of the session middleware
16
15
  * without additional plumbing
17
16
  */
18
17
  export class SessionMiddlewareFactory {
19
- #config = { driver: 'memory' };
18
+ #config = {
19
+ store: 'memory',
20
+ stores: {},
21
+ };
20
22
  #emitter;
21
23
  #getApp() {
22
24
  return new AppFactory().create(new URL('./', import.meta.url), () => { });
@@ -40,8 +42,7 @@ export class SessionMiddlewareFactory {
40
42
  * Creates an instance of the session middleware
41
43
  */
42
44
  async create() {
43
- const config = defineConfig(this.#config);
44
- await registerSessionDriver(this.#getApp(), config.driver);
45
+ const config = await defineConfig(this.#config).resolver(this.#getApp());
45
46
  return new SessionMiddleware(config, this.#getEmitter());
46
47
  }
47
48
  }
package/build/index.d.ts CHANGED
@@ -6,9 +6,7 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import './src/types/extended.js';
10
9
  export * as errors from './src/errors.js';
11
10
  export { configure } from './configure.js';
12
11
  export { stubsRoot } from './stubs/main.js';
13
- export { defineConfig } from './src/define_config.js';
14
- export { default as driversList } from './src/drivers_collection.js';
12
+ export { defineConfig, stores } from './src/define_config.js';
package/build/index.js CHANGED
@@ -6,9 +6,7 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import './src/types/extended.js';
10
9
  export * as errors from './src/errors.js';
11
10
  export { configure } from './configure.js';
12
11
  export { stubsRoot } from './stubs/main.js';
13
- export { defineConfig } from './src/define_config.js';
14
- export { default as driversList } from './src/drivers_collection.js';
12
+ export { defineConfig, stores } from './src/define_config.js';
@@ -1,5 +1,23 @@
1
- import type { Edge } from 'edge.js';
2
1
  import type { ApplicationService } from '@adonisjs/core/types';
2
+ import type { Session } from '../src/session.js';
3
+ /**
4
+ * Events emitted by the session class
5
+ */
6
+ declare module '@adonisjs/core/types' {
7
+ interface EventsList {
8
+ 'session:initiated': {
9
+ session: Session;
10
+ };
11
+ 'session:committed': {
12
+ session: Session;
13
+ };
14
+ 'session:migrated': {
15
+ fromSessionId: string;
16
+ toSessionId: string;
17
+ session: Session;
18
+ };
19
+ }
20
+ }
3
21
  /**
4
22
  * Session provider configures the session management inside an
5
23
  * AdonisJS application
@@ -8,16 +26,15 @@ export default class SessionProvider {
8
26
  protected app: ApplicationService;
9
27
  constructor(app: ApplicationService);
10
28
  /**
11
- * Returns edge when it's installed
29
+ * Registers edge plugin when edge is installed
30
+ * in the user application.
12
31
  */
13
- protected getEdge(): Promise<Edge | null>;
32
+ protected registerEdgePlugin(): Promise<void>;
14
33
  /**
15
34
  * Registering muddleware
16
35
  */
17
36
  register(): void;
18
37
  /**
19
- * Registering the active driver when middleware is used
20
- * +
21
38
  * Adding edge tags (if edge is installed)
22
39
  */
23
40
  boot(): Promise<void>;
@@ -6,8 +6,8 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import debug from '../src/debug.js';
10
- import { registerSessionDriver } from '../src/helpers.js';
9
+ import { configProvider } from '@adonisjs/core';
10
+ import { RuntimeException } from '@poppinss/utils';
11
11
  import SessionMiddleware from '../src/session_middleware.js';
12
12
  /**
13
13
  * Session provider configures the session management inside an
@@ -19,16 +19,19 @@ export default class SessionProvider {
19
19
  this.app = app;
20
20
  }
21
21
  /**
22
- * Returns edge when it's installed
22
+ * Registers edge plugin when edge is installed
23
+ * in the user application.
23
24
  */
24
- async getEdge() {
25
+ async registerEdgePlugin() {
26
+ let edge = null;
25
27
  try {
26
- const { default: edge } = await import('edge.js');
27
- debug('Detected edge.js package. Adding session primitives to it');
28
- return edge;
28
+ const edgeExports = await import('edge.js');
29
+ edge = edgeExports.default;
29
30
  }
30
- catch {
31
- return null;
31
+ catch { }
32
+ if (edge) {
33
+ const { edgePluginSession } = await import('../src/plugins/edge.js');
34
+ edge.use(edgePluginSession);
32
35
  }
33
36
  }
34
37
  /**
@@ -36,25 +39,22 @@ export default class SessionProvider {
36
39
  */
37
40
  register() {
38
41
  this.app.container.singleton(SessionMiddleware, async (resolver) => {
39
- const config = this.app.config.get('session', {});
42
+ const sessionConfigProvider = this.app.config.get('session', {});
43
+ /**
44
+ * Resolve config from the provider
45
+ */
46
+ const config = await configProvider.resolve(this.app, sessionConfigProvider);
47
+ if (!config) {
48
+ throw new RuntimeException('Invalid "config/session.ts" file. Make sure you are using the "defineConfig" method');
49
+ }
40
50
  const emitter = await resolver.make('emitter');
41
51
  return new SessionMiddleware(config, emitter);
42
52
  });
43
53
  }
44
54
  /**
45
- * Registering the active driver when middleware is used
46
- * +
47
55
  * Adding edge tags (if edge is installed)
48
56
  */
49
57
  async boot() {
50
- this.app.container.resolving(SessionMiddleware, async () => {
51
- const config = this.app.config.get('session');
52
- await registerSessionDriver(this.app, config.driver);
53
- });
54
- const edge = await this.getEdge();
55
- if (edge) {
56
- const { edgePluginSession } = await import('../src/plugins/edge.js');
57
- edge.use(edgePluginSession);
58
- }
58
+ await this.registerEdgePlugin();
59
59
  }
60
60
  }
@@ -1,4 +1,4 @@
1
- import type { SessionData, SessionDriverContract } from './types/main.js';
1
+ import type { SessionData, SessionStoreContract } from './types.js';
2
2
  /**
3
3
  * Session client exposes the API to set session data as a client
4
4
  */
@@ -13,7 +13,7 @@ export declare class SessionClient {
13
13
  * defined
14
14
  */
15
15
  sessionId: string;
16
- constructor(driver: SessionDriverContract);
16
+ constructor(store: SessionStoreContract);
17
17
  /**
18
18
  * Merge session data
19
19
  */
@@ -8,7 +8,7 @@
8
8
  */
9
9
  import { cuid } from '@adonisjs/core/helpers';
10
10
  import debug from './debug.js';
11
- import { Store } from './store.js';
11
+ import { ValuesStore } from './values_store.js';
12
12
  /**
13
13
  * Session client exposes the API to set session data as a client
14
14
  */
@@ -16,15 +16,15 @@ export class SessionClient {
16
16
  /**
17
17
  * Data store
18
18
  */
19
- #store = new Store({});
19
+ #valuesStore = new ValuesStore({});
20
20
  /**
21
21
  * Flash messages store
22
22
  */
23
- #flashMessagesStore = new Store({});
23
+ #flashMessagesStore = new ValuesStore({});
24
24
  /**
25
- * The session driver to use for reading and writing session data
25
+ * The session store to use for reading and writing session data
26
26
  */
27
- #driver;
27
+ #store;
28
28
  /**
29
29
  * Session key for setting flash messages
30
30
  */
@@ -34,14 +34,14 @@ export class SessionClient {
34
34
  * defined
35
35
  */
36
36
  sessionId = cuid();
37
- constructor(driver) {
38
- this.#driver = driver;
37
+ constructor(store) {
38
+ this.#store = store;
39
39
  }
40
40
  /**
41
41
  * Merge session data
42
42
  */
43
43
  merge(values) {
44
- this.#store.merge(values);
44
+ this.#valuesStore.merge(values);
45
45
  return this;
46
46
  }
47
47
  /**
@@ -56,11 +56,11 @@ export class SessionClient {
56
56
  */
57
57
  async commit() {
58
58
  if (!this.#flashMessagesStore.isEmpty) {
59
- this.#store.set(this.flashKey, this.#flashMessagesStore.toJSON());
59
+ this.#valuesStore.set(this.flashKey, this.#flashMessagesStore.toJSON());
60
60
  }
61
61
  debug('committing session data during api request');
62
- if (!this.#store.isEmpty) {
63
- this.#driver.write(this.sessionId, this.#store.toJSON());
62
+ if (!this.#valuesStore.isEmpty) {
63
+ this.#store.write(this.sessionId, this.#valuesStore.toJSON());
64
64
  }
65
65
  }
66
66
  /**
@@ -68,14 +68,14 @@ export class SessionClient {
68
68
  */
69
69
  async destroy(sessionId) {
70
70
  debug('destroying session data during api request');
71
- this.#driver.destroy(sessionId || this.sessionId);
71
+ this.#store.destroy(sessionId || this.sessionId);
72
72
  }
73
73
  /**
74
74
  * Loads session data from the session store
75
75
  */
76
76
  async load(sessionId) {
77
- const contents = await this.#driver.read(sessionId || this.sessionId);
78
- const store = new Store(contents);
77
+ const contents = await this.#store.read(sessionId || this.sessionId);
78
+ const store = new ValuesStore(contents);
79
79
  const flashMessages = store.pull(this.flashKey, {});
80
80
  return {
81
81
  values: store.all(),
@@ -1,3 +1,3 @@
1
- /// <reference types="@types/node" resolution-mode="require"/>
1
+ /// <reference types="node" resolution-mode="require"/>
2
2
  declare const _default: import("util").DebugLogger;
3
3
  export default _default;
@@ -1,8 +1,29 @@
1
+ import type { ConfigProvider } from '@adonisjs/core/types';
1
2
  import type { CookieOptions } from '@adonisjs/core/types/http';
2
- import type { SessionConfig } from './types/main.js';
3
+ import type { SessionConfig, FileStoreConfig, RedisStoreConfig, SessionStoreFactory } from './types.js';
3
4
  /**
4
- * Helper to normalize session config
5
+ * Resolved config with stores
5
6
  */
6
- export declare function defineConfig(config: Partial<SessionConfig>): SessionConfig & {
7
+ type ResolvedConfig<KnownStores extends Record<string, SessionStoreFactory>> = SessionConfig & {
8
+ store: keyof KnownStores;
9
+ stores: KnownStores;
7
10
  cookie: Partial<CookieOptions>;
8
11
  };
12
+ /**
13
+ * Helper to normalize session config
14
+ */
15
+ export declare function defineConfig<KnownStores extends Record<string, SessionStoreFactory | ConfigProvider<SessionStoreFactory>>>(config: Partial<SessionConfig> & {
16
+ store: keyof KnownStores | 'memory';
17
+ stores: KnownStores;
18
+ }): ConfigProvider<ResolvedConfig<{
19
+ [K in keyof KnownStores]: SessionStoreFactory;
20
+ }>>;
21
+ /**
22
+ * Inbuilt stores to store the session data.
23
+ */
24
+ export declare const stores: {
25
+ file: (config: FileStoreConfig) => ConfigProvider<SessionStoreFactory>;
26
+ redis: (config: RedisStoreConfig) => ConfigProvider<SessionStoreFactory>;
27
+ cookie: () => ConfigProvider<SessionStoreFactory>;
28
+ };
29
+ export {};
@@ -6,37 +6,100 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ /// <reference types="@adonisjs/redis/redis_provider" />
9
10
  import string from '@poppinss/utils/string';
11
+ import { configProvider } from '@adonisjs/core';
10
12
  import { InvalidArgumentsException } from '@poppinss/utils';
11
13
  import debug from './debug.js';
14
+ import { MemoryStore } from './stores/memory.js';
12
15
  /**
13
16
  * Helper to normalize session config
14
17
  */
15
18
  export function defineConfig(config) {
19
+ debug('processing session config %O', config);
16
20
  /**
17
- * Make sure a driver is defined
21
+ * Make sure a store is defined
18
22
  */
19
- if (!config.driver) {
20
- throw new InvalidArgumentsException('Missing "driver" property inside the session config');
23
+ if (!config.store) {
24
+ throw new InvalidArgumentsException('Missing "store" property inside the session config');
21
25
  }
22
- const age = config.age || '2h';
23
- const clearWithBrowser = config.clearWithBrowser ?? false;
24
- const cookieOptions = { ...config.cookie };
25
26
  /**
26
- * Define maxAge property when session id cookie is
27
- * not a session cookie.
27
+ * Destructuring config with the default values. We pull out
28
+ * stores and cookie values, since we have to transform
29
+ * them in the output value.
28
30
  */
29
- if (!clearWithBrowser) {
30
- debug('computing maxAge for session id cookie');
31
- cookieOptions.maxAge = string.seconds.parse(config.age || age);
32
- }
33
- return {
31
+ const { stores, cookie, ...rest } = {
34
32
  enabled: true,
35
- age,
36
- clearWithBrowser,
33
+ age: '2h',
37
34
  cookieName: 'adonis_session',
38
- cookie: cookieOptions,
39
- driver: config.driver,
35
+ clearWithBrowser: false,
40
36
  ...config,
41
37
  };
38
+ const cookieOptions = { ...cookie };
39
+ /**
40
+ * Define maxAge property when session id cookie is
41
+ * not a session cookie.
42
+ */
43
+ if (!rest.clearWithBrowser) {
44
+ cookieOptions.maxAge = string.seconds.parse(rest.age);
45
+ debug('computing maxAge "%s" for session id cookie', cookieOptions.maxAge);
46
+ }
47
+ return configProvider.create(async (app) => {
48
+ const storesNames = Object.keys(config.stores);
49
+ /**
50
+ * List of stores with memory store always configured
51
+ */
52
+ const storesList = {
53
+ memory: () => new MemoryStore(),
54
+ };
55
+ /**
56
+ * Looping for stores and resolving them
57
+ */
58
+ for (let storeName of storesNames) {
59
+ const store = config.stores[storeName];
60
+ if (typeof store === 'function') {
61
+ storesList[storeName] = store;
62
+ }
63
+ else {
64
+ storesList[storeName] = await store.resolver(app);
65
+ }
66
+ }
67
+ const transformedConfig = {
68
+ ...rest,
69
+ cookie: cookieOptions,
70
+ stores: storesList,
71
+ };
72
+ debug('transformed session config %O', transformedConfig);
73
+ return transformedConfig;
74
+ });
42
75
  }
76
+ /**
77
+ * Inbuilt stores to store the session data.
78
+ */
79
+ export const stores = {
80
+ file: (config) => {
81
+ return configProvider.create(async () => {
82
+ const { FileStore } = await import('./stores/file.js');
83
+ return (_, sessionConfig) => {
84
+ return new FileStore(config, sessionConfig.age);
85
+ };
86
+ });
87
+ },
88
+ redis: (config) => {
89
+ return configProvider.create(async (app) => {
90
+ const { RedisStore } = await import('./stores/redis.js');
91
+ const redis = await app.container.make('redis');
92
+ return (_, sessionConfig) => {
93
+ return new RedisStore(redis.connection(config.connection), sessionConfig.age);
94
+ };
95
+ });
96
+ },
97
+ cookie: () => {
98
+ return configProvider.create(async () => {
99
+ const { CookieStore } = await import('./stores/cookie.js');
100
+ return (ctx, sessionConfig) => {
101
+ return new CookieStore(sessionConfig.cookie, ctx);
102
+ };
103
+ });
104
+ },
105
+ };
@@ -1,7 +1,7 @@
1
1
  import type { PluginFn } from '@japa/runner/types';
2
2
  import type { ApplicationService } from '@adonisjs/core/types';
3
3
  import { SessionClient } from '../../client.js';
4
- import type { SessionData } from '../../types/main.js';
4
+ import type { SessionData } from '../../types.js';
5
5
  declare module '@japa/api-client' {
6
6
  interface ApiRequest {
7
7
  sessionClient: SessionClient;
@@ -69,7 +69,7 @@ declare module '@japa/api-client' {
69
69
  }
70
70
  }
71
71
  /**
72
- * Hooks AdonisJS Session with the Japa API Client
72
+ * Hooks AdonisJS Session with the Japa API client
73
73
  * plugin
74
74
  */
75
75
  export declare const sessionApiClient: (app: ApplicationService) => PluginFn;
@@ -7,35 +7,31 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import lodash from '@poppinss/utils/lodash';
10
+ import { configProvider } from '@adonisjs/core';
10
11
  import { RuntimeException } from '@poppinss/utils';
11
12
  import { ApiClient, ApiRequest, ApiResponse } from '@japa/api-client';
12
13
  import { SessionClient } from '../../client.js';
13
- import { registerSessionDriver } from '../../helpers.js';
14
- import sessionDriversList from '../../drivers_collection.js';
15
14
  /**
16
- * Hooks AdonisJS Session with the Japa API Client
15
+ * Hooks AdonisJS Session with the Japa API client
17
16
  * plugin
18
17
  */
19
18
  export const sessionApiClient = (app) => {
20
19
  const pluginFn = async function () {
21
- const config = app.config.get('session');
20
+ const sessionConfigProvider = app.config.get('session', {});
22
21
  /**
23
- * Disallow usage of driver other than memory during testing
22
+ * Resolve config from the provider
24
23
  */
25
- if (config.driver !== 'memory') {
26
- throw new RuntimeException(`Cannot use session driver "${config.driver}" during testing. Switch to memory driver`);
24
+ const config = await configProvider.resolve(app, sessionConfigProvider);
25
+ if (!config) {
26
+ throw new RuntimeException('Invalid "config/session.ts" file. Make sure you are using the "defineConfig" method');
27
27
  }
28
- /**
29
- * Register the memory driver if not already registered
30
- */
31
- await registerSessionDriver(app, 'memory');
32
28
  /**
33
29
  * Stick an singleton session client to APIRequest. The session
34
30
  * client is used to keep a track of session data we have
35
31
  * to send during the request.
36
32
  */
37
33
  ApiRequest.getter('sessionClient', function () {
38
- return new SessionClient(sessionDriversList.create('memory', config));
34
+ return new SessionClient(config.stores.memory());
39
35
  }, true);
40
36
  /**
41
37
  * Define session data
@@ -2,7 +2,7 @@ import type { PluginFn } from '@japa/runner/types';
2
2
  import type { ApplicationService } from '@adonisjs/core/types';
3
3
  import type { CookieOptions as AdonisCookieOptions } from '@adonisjs/core/types/http';
4
4
  import { SessionClient } from '../../client.js';
5
- import type { SessionData } from '../../types/main.js';
5
+ import type { SessionData } from '../../types.js';
6
6
  declare module 'playwright' {
7
7
  interface BrowserContext {
8
8
  sessionClient: SessionClient;
@@ -30,7 +30,7 @@ declare module 'playwright' {
30
30
  }
31
31
  }
32
32
  /**
33
- * Hooks AdonisJS Session with the Japa API Client
33
+ * Hooks AdonisJS Session with the Japa browser client
34
34
  * plugin
35
35
  */
36
36
  export declare const sessionBrowserClient: (app: ApplicationService) => PluginFn;
@@ -6,11 +6,10 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import { configProvider } from '@adonisjs/core';
9
10
  import { RuntimeException } from '@poppinss/utils';
10
11
  import { decoratorsCollection } from '@japa/browser-client';
11
12
  import { SessionClient } from '../../client.js';
12
- import { registerSessionDriver } from '../../helpers.js';
13
- import sessionDriversList from '../../drivers_collection.js';
14
13
  /**
15
14
  * Transforming AdonisJS same site option to playwright
16
15
  * same site option.
@@ -41,28 +40,25 @@ function getSessionCookieOptions(config, cookieOptions) {
41
40
  };
42
41
  }
43
42
  /**
44
- * Hooks AdonisJS Session with the Japa API Client
43
+ * Hooks AdonisJS Session with the Japa browser client
45
44
  * plugin
46
45
  */
47
46
  export const sessionBrowserClient = (app) => {
48
47
  const pluginFn = async function () {
49
- const config = app.config.get('session');
48
+ const sessionConfigProvider = app.config.get('session', {});
50
49
  /**
51
- * Disallow usage of driver other than memory during testing
50
+ * Resolve config from the provider
52
51
  */
53
- if (config.driver !== 'memory') {
54
- throw new RuntimeException(`Cannot use session driver "${config.driver}" during testing. Switch to memory driver`);
52
+ const config = await configProvider.resolve(app, sessionConfigProvider);
53
+ if (!config) {
54
+ throw new RuntimeException('Invalid "config/session.ts" file. Make sure you are using the "defineConfig" method');
55
55
  }
56
- /**
57
- * Register the memory driver if not already registered
58
- */
59
- await registerSessionDriver(app, 'memory');
60
56
  decoratorsCollection.register({
61
57
  context(context) {
62
58
  /**
63
59
  * Reference to session client per browser context
64
60
  */
65
- context.sessionClient = new SessionClient(sessionDriversList.create('memory', config));
61
+ context.sessionClient = new SessionClient(config.stores.memory());
66
62
  /**
67
63
  * Initiating session store
68
64
  */
@@ -1,8 +1,8 @@
1
- import { EmitterService } from '@adonisjs/core/types';
2
1
  import type { HttpContext } from '@adonisjs/core/http';
3
- import { Store } from './store.js';
4
- import type { SessionData, SessionConfig, AllowedSessionValues, SessionDriverContract } from './types/main.js';
5
- import { HttpError } from '@adonisjs/core/types/http';
2
+ import type { EmitterService } from '@adonisjs/core/types';
3
+ import type { HttpError } from '@adonisjs/core/types/http';
4
+ import { ValuesStore } from './values_store.js';
5
+ import type { SessionData, SessionConfig, SessionStoreFactory, AllowedSessionValues } from './types.js';
6
6
  /**
7
7
  * The session class exposes the API to read and write values to
8
8
  * the session store.
@@ -16,11 +16,11 @@ export declare class Session {
16
16
  * Store of flash messages that be written during the
17
17
  * HTTP request
18
18
  */
19
- responseFlashMessages: Store;
19
+ responseFlashMessages: ValuesStore;
20
20
  /**
21
21
  * Store of flash messages for the current HTTP request.
22
22
  */
23
- flashMessages: Store;
23
+ flashMessages: ValuesStore;
24
24
  /**
25
25
  * The key to use for storing flash messages inside
26
26
  * the session store.
@@ -58,7 +58,7 @@ export declare class Session {
58
58
  * modified
59
59
  */
60
60
  get hasBeenModified(): boolean;
61
- constructor(config: SessionConfig, driver: SessionDriverContract, emitter: EmitterService, ctx: HttpContext);
61
+ constructor(config: SessionConfig, storeFactory: SessionStoreFactory, emitter: EmitterService, ctx: HttpContext);
62
62
  /**
63
63
  * Initiates the session store. The method results in a noop
64
64
  * when called multiple times