@adonisjs/session 7.0.0-2 → 7.0.0-3

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 (45) hide show
  1. package/README.md +5 -8
  2. package/build/index.d.ts +5 -3
  3. package/build/index.js +5 -3
  4. package/build/providers/session_provider.d.ts +5 -8
  5. package/build/providers/session_provider.js +13 -35
  6. package/build/src/client.d.ts +13 -25
  7. package/build/src/client.js +24 -43
  8. package/build/src/debug.d.ts +3 -0
  9. package/build/src/debug.js +10 -0
  10. package/build/src/define_config.d.ts +6 -3
  11. package/build/src/define_config.js +34 -5
  12. package/build/src/drivers/cookie.d.ts +7 -9
  13. package/build/src/drivers/cookie.js +10 -6
  14. package/build/src/drivers/file.d.ts +11 -14
  15. package/build/src/drivers/file.js +64 -41
  16. package/build/src/drivers/memory.d.ts +4 -8
  17. package/build/src/drivers/memory.js +0 -3
  18. package/build/src/drivers/redis.d.ts +4 -6
  19. package/build/src/drivers/redis.js +24 -28
  20. package/build/src/drivers_collection.d.ts +22 -0
  21. package/build/src/drivers_collection.js +38 -0
  22. package/build/src/errors.d.ts +8 -0
  23. package/build/src/errors.js +17 -0
  24. package/build/src/helpers.d.ts +6 -0
  25. package/build/src/helpers.js +37 -0
  26. package/build/src/session.d.ts +86 -59
  27. package/build/src/session.js +221 -221
  28. package/build/src/session_middleware.d.ts +19 -5
  29. package/build/src/session_middleware.js +42 -6
  30. package/build/src/store.d.ts +17 -14
  31. package/build/src/store.js +33 -17
  32. package/build/src/types/extended.d.ts +19 -0
  33. package/build/src/types/main.d.ts +106 -0
  34. package/build/src/types/main.js +9 -0
  35. package/package.json +23 -20
  36. package/build/src/bindings/api_client.d.ts +0 -2
  37. package/build/src/bindings/api_client.js +0 -135
  38. package/build/src/bindings/http_context.d.ts +0 -5
  39. package/build/src/bindings/http_context.js +0 -17
  40. package/build/src/bindings/types.d.ts +0 -77
  41. package/build/src/session_manager.d.ts +0 -38
  42. package/build/src/session_manager.js +0 -149
  43. package/build/src/types.d.ts +0 -61
  44. package/build/src/types.js +0 -1
  45. /package/build/src/{bindings/types.js → types/extended.js} +0 -0
@@ -1,132 +1,159 @@
1
- import type { SessionConfig, SessionDriverContract, AllowedSessionValues } from './types.js';
1
+ import { EmitterService } from '@adonisjs/core/types';
2
2
  import type { HttpContext } from '@adonisjs/core/http';
3
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';
4
6
  /**
5
- * Session class exposes the API to read/write values to the session for
6
- * a given request.
7
+ * The session class exposes the API to read and write values to
8
+ * the session store.
9
+ *
10
+ * A session instance is isolated between requests but
11
+ * uses a centralized persistence store and
7
12
  */
8
13
  export declare class Session {
9
14
  #private;
10
15
  /**
11
- * Set to true inside the `initiate` method
16
+ * Store of flash messages that be written during the
17
+ * HTTP request
12
18
  */
13
- initiated: boolean;
19
+ responseFlashMessages: Store;
14
20
  /**
15
- * A boolean to know if it's a fresh session or not. Fresh
16
- * sessions are those, whose session id is not present
17
- * in cookie
21
+ * Store of flash messages for the current HTTP request.
18
22
  */
19
- fresh: boolean;
23
+ flashMessages: Store;
20
24
  /**
21
- * A boolean to know if store is initiated in readonly mode
22
- * or not. This is done during Websocket requests
25
+ * The key to use for storing flash messages inside
26
+ * the session store.
23
27
  */
24
- readonly: boolean;
28
+ flashKey: string;
25
29
  /**
26
- * Session id for the given request. A new session id is only
27
- * generated when the cookie for the session id is missing
30
+ * Session id for the current HTTP request
28
31
  */
29
- sessionId: string;
32
+ get sessionId(): string;
30
33
  /**
31
- * A copy of previously set flash messages
34
+ * A boolean to know if a fresh session is created during
35
+ * the request
32
36
  */
33
- flashMessages: Store;
37
+ get fresh(): boolean;
34
38
  /**
35
- * A copy of flash messages. The `input` messages
36
- * are overwritten when any of the input related
37
- * methods are used.
38
- *
39
- * The `others` object is expanded with each call.
39
+ * A boolean to know if session is in readonly
40
+ * state
40
41
  */
41
- responseFlashMessages: Store;
42
- constructor(ctx: HttpContext, config: SessionConfig, driver: SessionDriverContract);
42
+ get readonly(): boolean;
43
43
  /**
44
- * Initiating the session by reading it's value from the
45
- * driver and feeding it to a store.
46
- *
47
- * Multiple calls to `initiate` results in a noop.
44
+ * A boolean to know if session store has been initiated
48
45
  */
49
- initiate(readonly: boolean): Promise<void>;
46
+ get initiated(): boolean;
50
47
  /**
51
- * Re-generates the session id. This can is used to avoid
52
- * session fixation attacks.
48
+ * A boolean to know if the session id has been re-generated
49
+ * during the current request
53
50
  */
54
- regenerate(): void;
51
+ get hasRegeneratedSession(): boolean;
52
+ /**
53
+ * A boolean to know if the session store is empty
54
+ */
55
+ get isEmpty(): boolean;
56
+ /**
57
+ * A boolean to know if the session store has been
58
+ * modified
59
+ */
60
+ get hasBeenModified(): boolean;
61
+ constructor(config: SessionConfig, driver: SessionDriverContract, emitter: EmitterService, ctx: HttpContext);
62
+ /**
63
+ * Initiates the session store. The method results in a noop
64
+ * when called multiple times
65
+ */
66
+ initiate(readonly: boolean): Promise<void>;
55
67
  /**
56
- * Set/update session value
68
+ * Put a key-value pair to the session data store
57
69
  */
58
70
  put(key: string, value: AllowedSessionValues): void;
59
71
  /**
60
- * Find if the value exists in the session
72
+ * Check if a key exists inside the datastore
61
73
  */
62
74
  has(key: string): boolean;
63
75
  /**
64
- * Get value from the session. The default value is returned
65
- * when actual value is `undefined`
76
+ * Get the value of a key from the session datastore.
77
+ * You can specify a default value to use, when key
78
+ * does not exists or has undefined value.
66
79
  */
67
80
  get(key: string, defaultValue?: any): any;
68
81
  /**
69
- * Returns everything from the session
82
+ * Get everything from the session store
70
83
  */
71
84
  all(): any;
72
85
  /**
73
- * Remove value for a given key from the session
86
+ * Remove a key from the session datastore
74
87
  */
75
88
  forget(key: string): void;
76
89
  /**
77
- * The method is equivalent to calling `session.get` followed
78
- * by `session.forget`
90
+ * Read value for a key from the session datastore
91
+ * and remove it simultaneously.
79
92
  */
80
93
  pull(key: string, defaultValue?: any): any;
81
94
  /**
82
- * Increment value for a number inside the session store. The
83
- * method raises an error when underlying value is not
84
- * a number
95
+ * Increment the value of a key inside the session
96
+ * store.
97
+ *
98
+ * A new key will be defined if does not exists already.
99
+ * The value of a new key will be 1
85
100
  */
86
101
  increment(key: string, steps?: number): void;
87
102
  /**
88
- * Decrement value for a number inside the session store. The
89
- * method raises an error when underlying value is not
90
- * a number
103
+ * Increment the value of a key inside the session
104
+ * store.
105
+ *
106
+ * A new key will be defined if does not exists already.
107
+ * The value of a new key will be -1
91
108
  */
92
109
  decrement(key: string, steps?: number): void;
93
110
  /**
94
- * Remove everything from the session
111
+ * Empty the session store
95
112
  */
96
113
  clear(): void;
97
114
  /**
98
- * Add a new flash message
115
+ * Flash validation error messages. Make sure the error
116
+ * is an instance of VineJS ValidationException
99
117
  */
100
- flash(key: string | {
101
- [key: string]: AllowedSessionValues;
102
- }, value?: AllowedSessionValues): void;
118
+ flashValidationErrors(error: HttpError): void;
103
119
  /**
104
- * Flash all form values
120
+ * Add a key-value pair to flash messages
121
+ */
122
+ flash(key: string, value: AllowedSessionValues): void;
123
+ flash(keyValue: SessionData): void;
124
+ /**
125
+ * Flash form input data to the flash messages store
105
126
  */
106
127
  flashAll(): void;
107
128
  /**
108
- * Flash all form values except mentioned keys
129
+ * Flash form input data (except some keys) to the flash messages store
109
130
  */
110
131
  flashExcept(keys: string[]): void;
111
132
  /**
112
- * Flash only defined keys from the form values
133
+ * Flash form input data (only some keys) to the flash messages store
113
134
  */
114
135
  flashOnly(keys: string[]): void;
115
136
  /**
116
- * Reflash existing flash messages
137
+ * Reflash messages from the last request in the current response
117
138
  */
118
139
  reflash(): void;
119
140
  /**
120
- * Reflash selected keys from the existing flash messages
141
+ * Reflash messages (only some keys) from the last
142
+ * request in the current response
121
143
  */
122
144
  reflashOnly(keys: string[]): void;
123
145
  /**
124
- * Omit selected keys from the existing flash messages
125
- * and flash the rest of values
146
+ * Reflash messages (except some keys) from the last
147
+ * request in the current response
126
148
  */
127
149
  reflashExcept(keys: string[]): void;
128
150
  /**
129
- * Writes value to the underlying session driver.
151
+ * Re-generate the session id and migrate data to it.
152
+ */
153
+ regenerate(): void;
154
+ /**
155
+ * Commit session changes. No more mutations will be
156
+ * allowed after commit.
130
157
  */
131
158
  commit(): Promise<void>;
132
159
  }