@adonisjs/session 8.0.0-next.0 → 8.0.0-next.2

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 (50) hide show
  1. package/build/commands/commands.json +1 -0
  2. package/build/commands/main.d.ts +4 -0
  3. package/build/commands/main.js +36 -0
  4. package/build/commands/make_session_table.d.ts +9 -0
  5. package/build/commands/make_session_table.js +13 -0
  6. package/build/cookie--JOJxrtW.js +31 -0
  7. package/build/database-vbrhCOPd.js +86 -0
  8. package/build/debug-BZVg83L1.js +3 -0
  9. package/build/dynamodb-BFVgTQSf.js +72 -0
  10. package/build/factories/main.js +27 -45
  11. package/build/file-BBU02j4z.js +71 -0
  12. package/build/index.d.ts +1 -0
  13. package/build/index.js +7 -25
  14. package/build/main-kn40V-hF.js +2 -0
  15. package/build/make/migration/sessions.stub +26 -0
  16. package/build/providers/session_provider.d.ts +2 -1
  17. package/build/providers/session_provider.js +34 -48
  18. package/build/redis-D8D9UtiD.js +91 -0
  19. package/build/session-C9DdRahS.js +215 -0
  20. package/build/session-Cb9-DoMh.js +139 -0
  21. package/build/session_collection-CvS5yIq6.js +31 -0
  22. package/build/session_middleware-gegOBxmm.js +27 -0
  23. package/build/src/client.js +38 -7
  24. package/build/src/debug.d.ts +1 -1
  25. package/build/src/define_config.d.ts +14 -6
  26. package/build/src/errors.d.ts +9 -0
  27. package/build/src/plugins/edge.d.ts +5 -1
  28. package/build/src/plugins/edge.js +74 -124
  29. package/build/src/plugins/japa/api_client.js +76 -96
  30. package/build/src/plugins/japa/browser_client.js +58 -81
  31. package/build/src/session.d.ts +12 -0
  32. package/build/src/session_collection.d.ts +81 -0
  33. package/build/src/session_middleware.js +5 -9
  34. package/build/src/stores/database.d.ts +70 -0
  35. package/build/src/stores/memory.d.ts +19 -2
  36. package/build/src/stores/redis.d.ts +15 -2
  37. package/build/src/types.d.ts +62 -8
  38. package/build/src/types.js +1 -0
  39. package/build/values_store-CvR1Sn37.js +78 -0
  40. package/package.json +65 -42
  41. package/build/chunk-DFXWYDMY.js +0 -62
  42. package/build/chunk-HAD4PFFM.js +0 -229
  43. package/build/chunk-MVBWJOEG.js +0 -187
  44. package/build/chunk-SBOMJK4T.js +0 -14
  45. package/build/chunk-SHD6OX52.js +0 -488
  46. package/build/chunk-Y566BNUT.js +0 -113
  47. package/build/cookie-YBBGLCO5.js +0 -88
  48. package/build/dynamodb-PLZABBFD.js +0 -153
  49. package/build/file-CCJ5ESE2.js +0 -151
  50. package/build/redis-NXJWWWVB.js +0 -89
@@ -1,229 +0,0 @@
1
- // src/values_store.ts
2
- import lodash from "@poppinss/utils/lodash";
3
- import { RuntimeException } from "@adonisjs/core/exceptions";
4
- var ReadOnlyValuesStore = class {
5
- /**
6
- * Underlying store values containing session data
7
- */
8
- values;
9
- /**
10
- * Returns true if the store is empty
11
- */
12
- get isEmpty() {
13
- return !this.values || Object.keys(this.values).length === 0;
14
- }
15
- /**
16
- * Creates a new readonly values store
17
- *
18
- * @param values - Initial session data or null
19
- */
20
- constructor(values) {
21
- this.values = values || {};
22
- }
23
- /**
24
- * Gets value for a given key
25
- *
26
- * @param key - The key or key path to retrieve
27
- * @param defaultValue - Default value if key doesn't exist
28
- *
29
- * @example
30
- * store.get('username', 'guest')
31
- * store.get(['user', 'preferences', 'theme'], 'light')
32
- */
33
- get(key, defaultValue) {
34
- const value = lodash.get(this.values, key);
35
- if (defaultValue !== void 0 && (value === null || value === void 0)) {
36
- return defaultValue;
37
- }
38
- return value;
39
- }
40
- /**
41
- * Checks if a value exists. Includes extra guards to check arrays for length.
42
- *
43
- * @param key - The key or key path to check
44
- * @param checkForArraysLength - Whether to check array length (default: true)
45
- *
46
- * @example
47
- * store.has('username') // Check if key exists
48
- * store.has(['user', 'roles']) // Check nested key
49
- * store.has('items', false) // Don't check array length
50
- */
51
- has(key, checkForArraysLength = true) {
52
- const value = this.get(key);
53
- if (!Array.isArray(value)) {
54
- return !!value;
55
- }
56
- return checkForArraysLength ? value.length > 0 : !!value;
57
- }
58
- /**
59
- * Gets all values from the store
60
- *
61
- * @example
62
- * const allData = store.all()
63
- */
64
- all() {
65
- return this.values;
66
- }
67
- /**
68
- * Returns object representation of values
69
- *
70
- * @example
71
- * const obj = store.toObject()
72
- */
73
- toObject() {
74
- return this.all();
75
- }
76
- /**
77
- * Returns the store values as JSON-serializable data
78
- *
79
- * @example
80
- * const json = store.toJSON()
81
- */
82
- toJSON() {
83
- return this.all();
84
- }
85
- /**
86
- * Returns string representation of the store
87
- *
88
- * @example
89
- * const str = store.toString()
90
- */
91
- toString() {
92
- return JSON.stringify(this.all());
93
- }
94
- };
95
- var ValuesStore = class extends ReadOnlyValuesStore {
96
- /**
97
- * Flag to track if the store has been modified
98
- */
99
- #modified = false;
100
- /**
101
- * Creates a new values store
102
- *
103
- * @param values - Initial session data or null
104
- */
105
- constructor(values) {
106
- super(values);
107
- }
108
- /**
109
- * Returns true if the store has been modified
110
- */
111
- get hasBeenModified() {
112
- return this.#modified;
113
- }
114
- /**
115
- * Sets a key/value pair in the store
116
- *
117
- * @param key - The key or key path to set
118
- * @param value - The value to set
119
- *
120
- * @example
121
- * store.set('username', 'john')
122
- * store.set(['user', 'preferences'], { theme: 'dark' })
123
- */
124
- set(key, value) {
125
- this.#modified = true;
126
- lodash.set(this.values, key, value);
127
- }
128
- /**
129
- * Removes a key from the store
130
- *
131
- * @param key - The key or key path to remove
132
- *
133
- * @example
134
- * store.unset('temp_data')
135
- * store.unset(['user', 'cache'])
136
- */
137
- unset(key) {
138
- this.#modified = true;
139
- lodash.unset(this.values, key);
140
- }
141
- /**
142
- * Pulls value from the store. Same as calling store.get then store.unset.
143
- *
144
- * @param key - The key or key path to pull
145
- * @param defaultValue - Default value if key doesn't exist
146
- *
147
- * @example
148
- * const message = store.pull('notification', 'No messages')
149
- * const data = store.pull(['temp', 'data'])
150
- */
151
- pull(key, defaultValue) {
152
- return ((value) => {
153
- this.unset(key);
154
- return value;
155
- })(this.get(key, defaultValue));
156
- }
157
- /**
158
- * Increments a numeric value. Raises an error when underlying value is not a number.
159
- *
160
- * @param key - The key or key path to increment
161
- * @param steps - Number of steps to increment (default: 1)
162
- *
163
- * @example
164
- * store.increment('page_views') // Increments by 1
165
- * store.increment('score', 10) // Increments by 10
166
- */
167
- increment(key, steps = 1) {
168
- const value = this.get(key, 0);
169
- if (typeof value !== "number") {
170
- throw new RuntimeException(`Cannot increment "${key}". Existing value is not a number`);
171
- }
172
- this.set(key, value + steps);
173
- }
174
- /**
175
- * Decrements a numeric value. Raises an error when underlying value is not a number.
176
- *
177
- * @param key - The key or key path to decrement
178
- * @param steps - Number of steps to decrement (default: 1)
179
- *
180
- * @example
181
- * store.decrement('attempts') // Decrements by 1
182
- * store.decrement('credits', 5) // Decrements by 5
183
- */
184
- decrement(key, steps = 1) {
185
- const value = this.get(key, 0);
186
- if (typeof value !== "number") {
187
- throw new RuntimeException(`Cannot decrement "${key}". Existing value is not a number`);
188
- }
189
- this.set(key, value - steps);
190
- }
191
- /**
192
- * Overwrites existing store data with new values
193
- *
194
- * @param values - New values to replace existing data
195
- *
196
- * @example
197
- * store.update({ username: 'jane', theme: 'light' })
198
- */
199
- update(values) {
200
- this.#modified = true;
201
- this.values = values;
202
- }
203
- /**
204
- * Merges values with existing store data
205
- *
206
- * @param values - Values to merge with existing data
207
- *
208
- * @example
209
- * store.merge({ newField: 'value', existingField: 'updated' })
210
- */
211
- merge(values) {
212
- this.#modified = true;
213
- lodash.merge(this.values, values);
214
- }
215
- /**
216
- * Resets store by clearing all values
217
- *
218
- * @example
219
- * store.clear() // Removes all data from store
220
- */
221
- clear() {
222
- this.update({});
223
- }
224
- };
225
-
226
- export {
227
- ReadOnlyValuesStore,
228
- ValuesStore
229
- };
@@ -1,187 +0,0 @@
1
- import {
2
- debug_default
3
- } from "./chunk-SBOMJK4T.js";
4
-
5
- // stubs/main.ts
6
- var stubsRoot = import.meta.dirname;
7
-
8
- // configure.ts
9
- async function configure(command) {
10
- const codemods = await command.createCodemods();
11
- await codemods.makeUsingStub(stubsRoot, "config/session.stub", {});
12
- await codemods.defineEnvVariables({ SESSION_DRIVER: "cookie" });
13
- await codemods.defineEnvValidations({
14
- variables: {
15
- SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`
16
- },
17
- leadingComment: "Variables for configuring session package"
18
- });
19
- await codemods.registerMiddleware("router", [
20
- {
21
- path: "@adonisjs/session/session_middleware"
22
- }
23
- ]);
24
- await codemods.updateRcFile((rcFile) => {
25
- rcFile.addProvider("@adonisjs/session/session_provider");
26
- });
27
- }
28
-
29
- // src/define_config.ts
30
- import { configProvider } from "@adonisjs/core";
31
- import string from "@adonisjs/core/helpers/string";
32
- import { InvalidArgumentsException } from "@adonisjs/core/exceptions";
33
-
34
- // src/stores/memory.ts
35
- var MemoryStore = class _MemoryStore {
36
- /**
37
- * Static map to store all session data in memory
38
- */
39
- static sessions = /* @__PURE__ */ new Map();
40
- /**
41
- * Reads session value from memory
42
- *
43
- * @param sessionId - Session identifier
44
- *
45
- * @example
46
- * const data = store.read('sess_abc123')
47
- */
48
- read(sessionId) {
49
- return _MemoryStore.sessions.get(sessionId) || null;
50
- }
51
- /**
52
- * Saves session value in memory for a given session id
53
- *
54
- * @param sessionId - Session identifier
55
- * @param values - Session data to store
56
- *
57
- * @example
58
- * store.write('sess_abc123', { userId: 123, theme: 'dark' })
59
- */
60
- write(sessionId, values) {
61
- _MemoryStore.sessions.set(sessionId, values);
62
- }
63
- /**
64
- * Removes a single session from memory
65
- *
66
- * @param sessionId - Session identifier to remove
67
- *
68
- * @example
69
- * store.destroy('sess_abc123')
70
- */
71
- destroy(sessionId) {
72
- _MemoryStore.sessions.delete(sessionId);
73
- }
74
- /**
75
- * No-op for memory store as there's no expiry mechanism
76
- *
77
- * @param sessionId - Session identifier (unused)
78
- */
79
- touch(_) {
80
- }
81
- };
82
-
83
- // src/define_config.ts
84
- function defineConfig(config) {
85
- debug_default("processing session config %O", config);
86
- if (!config.store) {
87
- throw new InvalidArgumentsException('Missing "store" property inside the session config');
88
- }
89
- const { stores: stores2, cookie, ...rest } = {
90
- enabled: true,
91
- age: "2h",
92
- cookieName: "adonis_session",
93
- clearWithBrowser: false,
94
- ...config
95
- };
96
- const cookieOptions = { ...cookie };
97
- if (!rest.clearWithBrowser) {
98
- cookieOptions.maxAge = string.seconds.parse(rest.age);
99
- debug_default('computing maxAge "%s" for session id cookie', cookieOptions.maxAge);
100
- }
101
- return configProvider.create(async (app) => {
102
- const storesNames = Object.keys(config.stores);
103
- const storesList = {
104
- memory: () => new MemoryStore()
105
- };
106
- for (let storeName of storesNames) {
107
- const store = config.stores[storeName];
108
- if (typeof store === "function") {
109
- storesList[storeName] = store;
110
- } else {
111
- storesList[storeName] = await store.resolver(app);
112
- }
113
- }
114
- const transformedConfig = {
115
- ...rest,
116
- cookie: cookieOptions,
117
- stores: storesList
118
- };
119
- debug_default("transformed session config %O", transformedConfig);
120
- return transformedConfig;
121
- });
122
- }
123
- var stores = {
124
- /**
125
- * Creates a file-based session store
126
- *
127
- * @param config - File store configuration
128
- */
129
- file: (config) => {
130
- return configProvider.create(async () => {
131
- const { FileStore } = await import("./file-CCJ5ESE2.js");
132
- return (_, sessionConfig) => {
133
- return new FileStore(config, sessionConfig.age);
134
- };
135
- });
136
- },
137
- /**
138
- * Creates a Redis-based session store
139
- *
140
- * @param config - Redis store configuration
141
- */
142
- redis: (config) => {
143
- return configProvider.create(async (app) => {
144
- const { RedisStore } = await import("./redis-NXJWWWVB.js");
145
- const redis = await app.container.make("redis");
146
- return (_, sessionConfig) => {
147
- return new RedisStore(redis.connection(config.connection), sessionConfig.age);
148
- };
149
- });
150
- },
151
- /**
152
- * Creates a cookie-based session store
153
- */
154
- cookie: () => {
155
- return configProvider.create(async () => {
156
- const { CookieStore } = await import("./cookie-YBBGLCO5.js");
157
- return (ctx, sessionConfig) => {
158
- return new CookieStore(sessionConfig.cookie, ctx);
159
- };
160
- });
161
- },
162
- /**
163
- * Creates a DynamoDB-based session store
164
- *
165
- * @param config - DynamoDB store configuration
166
- */
167
- dynamodb: (config) => {
168
- return configProvider.create(async () => {
169
- const { DynamoDBStore } = await import("./dynamodb-PLZABBFD.js");
170
- const { DynamoDBClient } = await import("@aws-sdk/client-dynamodb");
171
- const client = "clientConfig" in config ? new DynamoDBClient(config.clientConfig) : config.client;
172
- return (_, sessionConfig) => {
173
- return new DynamoDBStore(client, sessionConfig.age, {
174
- tableName: config.tableName,
175
- keyAttribute: config.keyAttribute
176
- });
177
- };
178
- });
179
- }
180
- };
181
-
182
- export {
183
- stubsRoot,
184
- configure,
185
- defineConfig,
186
- stores
187
- };
@@ -1,14 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/debug.ts
8
- import { debuglog } from "util";
9
- var debug_default = debuglog("adonisjs:session");
10
-
11
- export {
12
- __export,
13
- debug_default
14
- };