@adonisjs/session 6.4.0 → 7.0.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 (58) hide show
  1. package/build/configure.d.ts +5 -0
  2. package/build/configure.js +18 -0
  3. package/build/index.d.ts +12 -0
  4. package/build/index.js +12 -0
  5. package/build/providers/session_provider.d.ts +13 -0
  6. package/build/providers/session_provider.js +43 -0
  7. package/build/src/bindings/api_client.d.ts +2 -0
  8. package/build/src/{Bindings/Tests.js → bindings/api_client.js} +8 -13
  9. package/build/src/bindings/http_context.d.ts +5 -0
  10. package/build/src/bindings/http_context.js +17 -0
  11. package/build/{adonis-typings/tests.d.ts → src/bindings/types.d.ts} +26 -5
  12. package/build/{adonis-typings/session.js → src/bindings/types.js} +2 -1
  13. package/build/src/{Client/index.d.ts → client.d.ts} +7 -15
  14. package/build/src/client.js +100 -0
  15. package/build/src/define_config.d.ts +5 -0
  16. package/build/src/define_config.js +13 -0
  17. package/build/src/{Drivers/Cookie.d.ts → drivers/cookie.d.ts} +4 -6
  18. package/build/src/{Drivers/Cookie.js → drivers/cookie.js} +10 -12
  19. package/build/src/{Drivers/File.d.ts → drivers/file.d.ts} +3 -8
  20. package/build/src/{Drivers/File.js → drivers/file.js} +20 -23
  21. package/build/src/{Drivers/Memory.d.ts → drivers/memory.d.ts} +2 -3
  22. package/build/src/{Drivers/Memory.js → drivers/memory.js} +3 -7
  23. package/build/src/{Drivers/Redis.d.ts → drivers/redis.d.ts} +5 -15
  24. package/build/src/drivers/redis.js +74 -0
  25. package/build/src/{Session/index.d.ts → session.d.ts} +6 -67
  26. package/build/src/session.js +373 -0
  27. package/build/src/session_manager.d.ts +38 -0
  28. package/build/src/session_manager.js +149 -0
  29. package/build/src/session_middleware.d.ts +5 -0
  30. package/build/src/session_middleware.js +20 -0
  31. package/build/src/{Store/index.d.ts → store.d.ts} +3 -7
  32. package/build/src/{Store/index.js → store.js} +18 -18
  33. package/build/src/types.d.ts +61 -0
  34. package/build/src/types.js +1 -0
  35. package/build/{templates/session.txt → stubs/config.stub} +12 -15
  36. package/build/stubs/main.d.ts +1 -0
  37. package/build/{adonis-typings/tests.js → stubs/main.js} +2 -3
  38. package/package.json +96 -134
  39. package/build/adonis-typings/container.d.ts +0 -14
  40. package/build/adonis-typings/container.js +0 -8
  41. package/build/adonis-typings/context.d.ts +0 -14
  42. package/build/adonis-typings/context.js +0 -8
  43. package/build/adonis-typings/index.d.ts +0 -4
  44. package/build/adonis-typings/index.js +0 -12
  45. package/build/adonis-typings/session.d.ts +0 -265
  46. package/build/config.d.ts +0 -13
  47. package/build/config.js +0 -18
  48. package/build/instructions.md +0 -10
  49. package/build/providers/SessionProvider.d.ts +0 -31
  50. package/build/providers/SessionProvider.js +0 -56
  51. package/build/src/Bindings/Server.d.ts +0 -10
  52. package/build/src/Bindings/Server.js +0 -42
  53. package/build/src/Bindings/Tests.d.ts +0 -7
  54. package/build/src/Client/index.js +0 -93
  55. package/build/src/Drivers/Redis.js +0 -73
  56. package/build/src/Session/index.js +0 -352
  57. package/build/src/SessionManager/index.d.ts +0 -78
  58. package/build/src/SessionManager/index.js +0 -148
@@ -1,78 +0,0 @@
1
- /**
2
- * @adonisjs/session
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference types="@adonisjs/application/build/adonis-typings" />
10
- import { ApplicationContract } from '@ioc:Adonis/Core/Application';
11
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
12
- import { SessionConfig, ExtendCallback, SessionManagerContract, SessionClientContract } from '@ioc:Adonis/Addons/Session';
13
- import { Session } from '../Session';
14
- /**
15
- * Session manager exposes the API to create session instance for a given
16
- * request and also add new drivers.
17
- */
18
- export declare class SessionManager implements SessionManagerContract {
19
- application: ApplicationContract;
20
- /**
21
- * A private map of drivers added from outside in.
22
- */
23
- private extendedDrivers;
24
- /**
25
- * Reference to session config
26
- */
27
- private config;
28
- constructor(application: ApplicationContract, config: SessionConfig);
29
- /**
30
- * Validates the config
31
- */
32
- private validateConfig;
33
- /**
34
- * Processes the config and decides the `expires` option for the cookie
35
- */
36
- private processConfig;
37
- /**
38
- * Returns an instance of cookie driver
39
- */
40
- private createCookieDriver;
41
- /**
42
- * Returns an instance of the memory driver
43
- */
44
- private createMemoryDriver;
45
- /**
46
- * Returns an instance of file driver
47
- */
48
- private createFileDriver;
49
- /**
50
- * Returns an instance of redis driver
51
- */
52
- private createRedisDriver;
53
- /**
54
- * Creates an instance of extended driver
55
- */
56
- private createExtendedDriver;
57
- /**
58
- * Creates an instance of driver by looking at the config value `driver`.
59
- * An hard exception is raised in case of invalid driver name
60
- */
61
- private createDriver;
62
- /**
63
- * Find if the sessions are enabled
64
- */
65
- isEnabled(): boolean;
66
- /**
67
- * Creates an instance of the session client
68
- */
69
- client(): SessionClientContract;
70
- /**
71
- * Creates a new session instance for a given HTTP request
72
- */
73
- create(ctx: HttpContextContract): Session;
74
- /**
75
- * Extend the drivers list by adding a new one.
76
- */
77
- extend(driver: string, callback: ExtendCallback): void;
78
- }
@@ -1,148 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/session
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.SessionManager = void 0;
12
- const helpers_1 = require("@poppinss/utils/build/helpers");
13
- const utils_1 = require("@poppinss/utils");
14
- const Session_1 = require("../Session");
15
- /**
16
- * Session manager exposes the API to create session instance for a given
17
- * request and also add new drivers.
18
- */
19
- class SessionManager {
20
- constructor(application, config) {
21
- this.application = application;
22
- /**
23
- * A private map of drivers added from outside in.
24
- */
25
- this.extendedDrivers = new Map();
26
- this.validateConfig(config);
27
- this.processConfig(config);
28
- }
29
- /**
30
- * Validates the config
31
- */
32
- validateConfig(config) {
33
- const validator = new utils_1.ManagerConfigValidator(config, 'session', 'config/session');
34
- validator.validateDefault('driver');
35
- }
36
- /**
37
- * Processes the config and decides the `expires` option for the cookie
38
- */
39
- processConfig(config) {
40
- /**
41
- * Explicitly overwriting `cookie.expires` and `cookie.maxAge` from
42
- * the user defined config
43
- */
44
- const processedConfig = Object.assign({ enabled: true }, config, {
45
- cookie: {
46
- ...config.cookie,
47
- expires: undefined,
48
- maxAge: undefined,
49
- },
50
- });
51
- /**
52
- * Set the max age when `clearWithBrowser = false`. Otherwise cookie
53
- * is a session cookie
54
- */
55
- if (!processedConfig.clearWithBrowser) {
56
- const age = typeof processedConfig.age === 'string'
57
- ? Math.round(helpers_1.string.toMs(processedConfig.age) / 1000)
58
- : processedConfig.age;
59
- processedConfig.cookie.maxAge = age;
60
- }
61
- this.config = processedConfig;
62
- }
63
- /**
64
- * Returns an instance of cookie driver
65
- */
66
- createCookieDriver(ctx) {
67
- const { CookieDriver } = require('../Drivers/Cookie');
68
- return new CookieDriver(this.config, ctx);
69
- }
70
- /**
71
- * Returns an instance of the memory driver
72
- */
73
- createMemoryDriver() {
74
- const { MemoryDriver } = require('../Drivers/Memory');
75
- return new MemoryDriver();
76
- }
77
- /**
78
- * Returns an instance of file driver
79
- */
80
- createFileDriver() {
81
- const { FileDriver } = require('../Drivers/File');
82
- return new FileDriver(this.config);
83
- }
84
- /**
85
- * Returns an instance of redis driver
86
- */
87
- createRedisDriver() {
88
- const { RedisDriver } = require('../Drivers/Redis');
89
- if (!this.application.container.hasBinding('Adonis/Addons/Redis')) {
90
- throw new Error('Install "@adonisjs/redis" in order to use the redis driver for storing sessions');
91
- }
92
- return new RedisDriver(this.config, this.application.container.use('Adonis/Addons/Redis'));
93
- }
94
- /**
95
- * Creates an instance of extended driver
96
- */
97
- createExtendedDriver(ctx) {
98
- if (!this.extendedDrivers.has(this.config.driver)) {
99
- throw new utils_1.Exception(`"${this.config.driver}" is not a valid session driver`, 500, 'E_INVALID_SESSION_DRIVER');
100
- }
101
- return this.extendedDrivers.get(this.config.driver)(this, this.config, ctx);
102
- }
103
- /**
104
- * Creates an instance of driver by looking at the config value `driver`.
105
- * An hard exception is raised in case of invalid driver name
106
- */
107
- createDriver(ctx) {
108
- switch (this.config.driver) {
109
- case 'cookie':
110
- return this.createCookieDriver(ctx);
111
- case 'file':
112
- return this.createFileDriver();
113
- case 'redis':
114
- return this.createRedisDriver();
115
- case 'memory':
116
- return this.createMemoryDriver();
117
- default:
118
- return this.createExtendedDriver(ctx);
119
- }
120
- }
121
- /**
122
- * Find if the sessions are enabled
123
- */
124
- isEnabled() {
125
- return this.config.enabled;
126
- }
127
- /**
128
- * Creates an instance of the session client
129
- */
130
- client() {
131
- const { SessionClient } = require('../Client');
132
- const CookieClient = this.application.container.resolveBinding('Adonis/Core/CookieClient');
133
- return new SessionClient(this.config, this.createMemoryDriver(), CookieClient, {});
134
- }
135
- /**
136
- * Creates a new session instance for a given HTTP request
137
- */
138
- create(ctx) {
139
- return new Session_1.Session(ctx, this.config, this.createDriver(ctx));
140
- }
141
- /**
142
- * Extend the drivers list by adding a new one.
143
- */
144
- extend(driver, callback) {
145
- this.extendedDrivers.set(driver, callback);
146
- }
147
- }
148
- exports.SessionManager = SessionManager;