@adonisjs/session 7.7.0 → 8.0.0-next.1

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 (85) hide show
  1. package/build/cookie-aLBno-zS.js +31 -0
  2. package/build/debug-Ba-0Cgn9.js +3 -0
  3. package/build/dynamodb-CU8BrQfU.js +72 -0
  4. package/build/factories/main.d.ts +1 -1
  5. package/build/factories/main.js +25 -49
  6. package/build/factories/session_middleware_factory.d.ts +2 -2
  7. package/build/file-CNxCs957.js +71 -0
  8. package/build/index.d.ts +6 -7
  9. package/build/index.js +5 -33
  10. package/build/providers/session_provider.d.ts +2 -3
  11. package/build/providers/session_provider.js +27 -64
  12. package/build/redis-Bcjum7z7.js +36 -0
  13. package/build/session-CBqhcnvJ.js +209 -0
  14. package/build/session-Cc1LPXRc.js +107 -0
  15. package/build/session_middleware-CS0R7hmq.js +27 -0
  16. package/build/src/client.d.ts +46 -10
  17. package/build/src/client.js +38 -9
  18. package/build/src/debug.d.ts +1 -1
  19. package/build/src/define_config.d.ts +49 -10
  20. package/build/src/errors.d.ts +20 -9
  21. package/build/src/plugins/edge.d.ts +16 -2
  22. package/build/src/plugins/edge.js +74 -126
  23. package/build/src/plugins/japa/api_client.d.ts +22 -4
  24. package/build/src/plugins/japa/api_client.js +76 -97
  25. package/build/src/plugins/japa/browser_client.d.ts +18 -4
  26. package/build/src/plugins/japa/browser_client.js +58 -82
  27. package/build/src/session.d.ts +170 -65
  28. package/build/src/session_middleware.d.ts +28 -5
  29. package/build/src/session_middleware.js +5 -11
  30. package/build/src/stores/cookie.d.ts +41 -7
  31. package/build/src/stores/dynamodb.d.ts +44 -8
  32. package/build/src/stores/file.d.ts +34 -8
  33. package/build/src/stores/memory.d.ts +32 -15
  34. package/build/src/stores/redis.d.ts +39 -16
  35. package/build/src/types.d.ts +151 -82
  36. package/build/src/types.js +1 -1
  37. package/build/src/values_store.d.ts +113 -21
  38. package/build/values_store-smX0sQBJ.js +78 -0
  39. package/package.json +57 -56
  40. package/build/chunk-5ECC6OWF.js +0 -8
  41. package/build/chunk-5ECC6OWF.js.map +0 -1
  42. package/build/chunk-6BSSM3HO.js +0 -44
  43. package/build/chunk-6BSSM3HO.js.map +0 -1
  44. package/build/chunk-G7KFHA57.js +0 -59
  45. package/build/chunk-G7KFHA57.js.map +0 -1
  46. package/build/chunk-GCO66PQD.js +0 -85
  47. package/build/chunk-GCO66PQD.js.map +0 -1
  48. package/build/chunk-PZ5AY32C.js +0 -10
  49. package/build/chunk-PZ5AY32C.js.map +0 -1
  50. package/build/chunk-Q24L5XPC.js +0 -186
  51. package/build/chunk-Q24L5XPC.js.map +0 -1
  52. package/build/chunk-TE5JP3SX.js +0 -151
  53. package/build/chunk-TE5JP3SX.js.map +0 -1
  54. package/build/chunk-V3OAEXMJ.js +0 -8
  55. package/build/chunk-V3OAEXMJ.js.map +0 -1
  56. package/build/chunk-XP3CBOXR.js +0 -414
  57. package/build/chunk-XP3CBOXR.js.map +0 -1
  58. package/build/commands/commands.json +0 -1
  59. package/build/commands/main.d.ts +0 -4
  60. package/build/commands/main.js +0 -36
  61. package/build/commands/make_session_table.d.ts +0 -9
  62. package/build/commands/make_session_table.js +0 -21
  63. package/build/commands/make_session_table.js.map +0 -1
  64. package/build/cookie-3C33DMWA.js +0 -57
  65. package/build/cookie-3C33DMWA.js.map +0 -1
  66. package/build/database-443FB7MM.js +0 -118
  67. package/build/database-443FB7MM.js.map +0 -1
  68. package/build/dynamodb-53YXEFIJ.js +0 -108
  69. package/build/dynamodb-53YXEFIJ.js.map +0 -1
  70. package/build/factories/main.js.map +0 -1
  71. package/build/file-K3GBSVSU.js +0 -117
  72. package/build/file-K3GBSVSU.js.map +0 -1
  73. package/build/index.js.map +0 -1
  74. package/build/make/migration/sessions.stub +0 -26
  75. package/build/providers/session_provider.js.map +0 -1
  76. package/build/redis-YGX2CNE2.js +0 -119
  77. package/build/redis-YGX2CNE2.js.map +0 -1
  78. package/build/src/client.js.map +0 -1
  79. package/build/src/plugins/edge.js.map +0 -1
  80. package/build/src/plugins/japa/api_client.js.map +0 -1
  81. package/build/src/plugins/japa/browser_client.js.map +0 -1
  82. package/build/src/session_collection.d.ts +0 -55
  83. package/build/src/session_middleware.js.map +0 -1
  84. package/build/src/stores/database.d.ts +0 -55
  85. package/build/src/types.js.map +0 -1
@@ -0,0 +1,78 @@
1
+ import { RuntimeException } from "@adonisjs/core/exceptions";
2
+ import lodash from "@poppinss/utils/lodash";
3
+ var ReadOnlyValuesStore = class {
4
+ values;
5
+ get isEmpty() {
6
+ return !this.values || Object.keys(this.values).length === 0;
7
+ }
8
+ constructor(values) {
9
+ this.values = values || {};
10
+ }
11
+ get(key, defaultValue) {
12
+ const value = lodash.get(this.values, key);
13
+ if (defaultValue !== void 0 && (value === null || value === void 0)) return defaultValue;
14
+ return value;
15
+ }
16
+ has(key, checkForArraysLength = true) {
17
+ const value = this.get(key);
18
+ if (!Array.isArray(value)) return !!value;
19
+ return checkForArraysLength ? value.length > 0 : !!value;
20
+ }
21
+ all() {
22
+ return this.values;
23
+ }
24
+ toObject() {
25
+ return this.all();
26
+ }
27
+ toJSON() {
28
+ return this.all();
29
+ }
30
+ toString() {
31
+ return JSON.stringify(this.all());
32
+ }
33
+ };
34
+ var ValuesStore = class extends ReadOnlyValuesStore {
35
+ #modified = false;
36
+ constructor(values) {
37
+ super(values);
38
+ }
39
+ get hasBeenModified() {
40
+ return this.#modified;
41
+ }
42
+ set(key, value) {
43
+ this.#modified = true;
44
+ lodash.set(this.values, key, value);
45
+ }
46
+ unset(key) {
47
+ this.#modified = true;
48
+ lodash.unset(this.values, key);
49
+ }
50
+ pull(key, defaultValue) {
51
+ return ((value) => {
52
+ this.unset(key);
53
+ return value;
54
+ })(this.get(key, defaultValue));
55
+ }
56
+ increment(key, steps = 1) {
57
+ const value = this.get(key, 0);
58
+ if (typeof value !== "number") throw new RuntimeException(`Cannot increment "${key}". Existing value is not a number`);
59
+ this.set(key, value + steps);
60
+ }
61
+ decrement(key, steps = 1) {
62
+ const value = this.get(key, 0);
63
+ if (typeof value !== "number") throw new RuntimeException(`Cannot decrement "${key}". Existing value is not a number`);
64
+ this.set(key, value - steps);
65
+ }
66
+ update(values) {
67
+ this.#modified = true;
68
+ this.values = values;
69
+ }
70
+ merge(values) {
71
+ this.#modified = true;
72
+ lodash.merge(this.values, values);
73
+ }
74
+ clear() {
75
+ this.update({});
76
+ }
77
+ };
78
+ export { ValuesStore as n, ReadOnlyValuesStore as t };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@adonisjs/session",
3
3
  "description": "Session provider for AdonisJS",
4
- "version": "7.7.0",
4
+ "version": "8.0.0-next.1",
5
5
  "engines": {
6
- "node": ">=18.16.0"
6
+ "node": ">=24.0.0"
7
7
  },
8
8
  "main": "build/index.js",
9
9
  "type": "module",
@@ -22,8 +22,7 @@
22
22
  "./plugins/api_client": "./build/src/plugins/japa/api_client.js",
23
23
  "./plugins/browser_client": "./build/src/plugins/japa/browser_client.js",
24
24
  "./client": "./build/src/client.js",
25
- "./types": "./build/src/types.js",
26
- "./commands": "./build/commands/main.js"
25
+ "./types": "./build/src/types.js"
27
26
  },
28
27
  "scripts": {
29
28
  "pretest": "npm run lint",
@@ -33,73 +32,70 @@
33
32
  "typecheck": "tsc --noEmit",
34
33
  "copy:templates": "copyfiles \"stubs/**/*.stub\" --up=\"1\" build",
35
34
  "precompile": "npm run lint",
36
- "compile": "tsup-node && tsc --emitDeclarationOnly --declaration",
37
- "postcompile": "npm run copy:templates && npm run index:commands",
38
- "index:commands": "adonis-kit index build/commands",
35
+ "compile": "tsdown && tsc --emitDeclarationOnly --declaration",
36
+ "postcompile": "npm run copy:templates",
39
37
  "build": "npm run compile",
38
+ "docs": "typedoc",
40
39
  "version": "npm run build",
41
40
  "prepublishOnly": "npm run build",
42
41
  "release": "release-it",
43
- "quick:test": "node --import=ts-node-maintained/register/esm --enable-source-maps bin/test.ts"
42
+ "quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts"
44
43
  },
45
44
  "devDependencies": {
46
- "@adonisjs/assembler": "^7.8.2",
47
- "@adonisjs/core": "^6.18.0",
48
- "@adonisjs/eslint-config": "^2.1.0",
49
- "@adonisjs/i18n": "^2.2.0",
50
- "@adonisjs/lucid": "^21.6.0",
51
- "better-sqlite3": "^12.5.0",
52
- "mysql2": "^3.15.3",
53
- "pg": "^8.16.3",
45
+ "@adonisjs/assembler": "^8.0.0-next.26",
46
+ "@adonisjs/core": "^7.0.0-next.16",
47
+ "@adonisjs/eslint-config": "^3.0.0-next.5",
48
+ "@adonisjs/i18n": "^3.0.0-next.2",
54
49
  "@adonisjs/prettier-config": "^1.4.5",
55
- "@adonisjs/redis": "^9.2.0",
56
- "@adonisjs/tsconfig": "^1.4.1",
57
- "@aws-sdk/client-dynamodb": "^3.830.0",
58
- "@aws-sdk/util-dynamodb": "^3.830.0",
59
- "@japa/api-client": "^3.1.0",
60
- "@japa/assert": "^4.0.1",
61
- "@japa/browser-client": "^2.1.1",
62
- "@japa/file-system": "^2.3.2",
63
- "@japa/plugin-adonisjs": "^4.0.0",
64
- "@japa/runner": "^4.2.0",
65
- "@japa/snapshot": "^2.0.8",
66
- "@release-it/conventional-changelog": "^10.0.1",
67
- "@swc/core": "1.10.7",
68
- "@types/node": "^24.0.3",
50
+ "@adonisjs/redis": "^10.0.0-next.2",
51
+ "@adonisjs/tsconfig": "^2.0.0-next.3",
52
+ "@aws-sdk/client-dynamodb": "^3.955.0",
53
+ "@aws-sdk/util-dynamodb": "^3.955.0",
54
+ "@japa/api-client": "^3.1.1",
55
+ "@japa/assert": "^4.2.0",
56
+ "@japa/browser-client": "^2.2.0",
57
+ "@japa/file-system": "^3.0.0",
58
+ "@japa/plugin-adonisjs": "^5.1.0-next.0",
59
+ "@japa/runner": "^5.0.0",
60
+ "@japa/snapshot": "^2.0.10",
61
+ "@poppinss/ts-exec": "^1.4.1",
62
+ "@release-it/conventional-changelog": "^10.0.4",
63
+ "@types/node": "^25.0.3",
69
64
  "@types/set-cookie-parser": "^2.4.10",
70
65
  "@types/supertest": "^6.0.3",
71
- "@vinejs/vine": "^3.0.1",
66
+ "@vinejs/vine": "^4.2.0",
72
67
  "c8": "^10.1.3",
73
68
  "copyfiles": "^2.4.1",
74
- "cross-env": "^7.0.3",
75
- "edge.js": "^6.2.1",
76
- "eslint": "^9.29.0",
69
+ "cross-env": "^10.1.0",
70
+ "edge.js": "^6.4.0",
71
+ "eslint": "^9.39.2",
77
72
  "get-port": "^7.1.0",
78
- "playwright": "^1.53.0",
79
- "prettier": "^3.5.3",
80
- "release-it": "^19.0.3",
81
- "set-cookie-parser": "^2.7.1",
82
- "supertest": "^7.1.1",
83
- "ts-node-maintained": "^10.9.5",
84
- "tsup": "^8.5.0",
85
- "typescript": "^5.8.3"
73
+ "playwright": "^1.57.0",
74
+ "prettier": "^3.7.4",
75
+ "release-it": "^19.1.0",
76
+ "set-cookie-parser": "^2.7.2",
77
+ "supertest": "^7.1.4",
78
+ "tsdown": "^0.18.1",
79
+ "typedoc": "^0.28.15",
80
+ "typescript": "^5.9.3"
86
81
  },
87
82
  "dependencies": {
88
- "@poppinss/macroable": "^1.0.4",
89
- "@poppinss/utils": "^6.10.0"
83
+ "@poppinss/macroable": "^1.1.0",
84
+ "@poppinss/utils": "^7.0.0-next.4"
90
85
  },
91
86
  "peerDependencies": {
92
- "@adonisjs/core": "^6.6.0",
93
- "@adonisjs/lucid": "^21.0.0",
94
- "@adonisjs/redis": "^8.0.1 || ^9.0.0",
95
- "@aws-sdk/client-dynamodb": "^3.658.0",
96
- "@aws-sdk/util-dynamodb": "^3.658.0",
97
- "@japa/api-client": "^2.0.3 || ^3.0.0",
87
+ "@adonisjs/assembler": "^8.0.0-next.26",
88
+ "@adonisjs/core": "^7.0.0-next.16",
89
+ "@adonisjs/redis": "^10.0.0-next.2",
90
+ "@aws-sdk/client-dynamodb": "^3.955.0",
91
+ "@aws-sdk/util-dynamodb": "^3.955.0",
92
+ "@japa/api-client": "^3.1.0",
98
93
  "@japa/browser-client": "^2.0.3",
99
- "edge.js": "^6.0.2"
94
+ "@japa/plugin-adonisjs": "^5.1.0-next.0",
95
+ "edge.js": "^6.4.0"
100
96
  },
101
97
  "peerDependenciesMeta": {
102
- "@adonisjs/lucid": {
98
+ "@adonisjs/assembler": {
103
99
  "optional": true
104
100
  },
105
101
  "@adonisjs/redis": {
@@ -119,6 +115,9 @@
119
115
  },
120
116
  "@japa/browser-client": {
121
117
  "optional": true
118
+ },
119
+ "@japa/plugin-adonisjs": {
120
+ "optional": true
122
121
  }
123
122
  },
124
123
  "author": "virk,adonisjs",
@@ -139,7 +138,7 @@
139
138
  "access": "public",
140
139
  "provenance": true
141
140
  },
142
- "tsup": {
141
+ "tsdown": {
143
142
  "entry": [
144
143
  "./index.ts",
145
144
  "./factories/main.ts",
@@ -149,14 +148,16 @@
149
148
  "./src/plugins/edge.ts",
150
149
  "./src/plugins/japa/api_client.ts",
151
150
  "./src/plugins/japa/browser_client.ts",
152
- "./src/client.ts",
153
- "./commands/make_session_table.ts"
151
+ "./src/client.ts"
154
152
  ],
155
153
  "outDir": "./build",
156
154
  "clean": true,
157
155
  "format": "esm",
156
+ "minify": "dce-only",
157
+ "fixedExtension": false,
158
158
  "dts": false,
159
- "sourcemap": true,
159
+ "treeshake": false,
160
+ "sourcemaps": false,
160
161
  "target": "esnext"
161
162
  },
162
163
  "release-it": {
@@ -1,8 +0,0 @@
1
- // src/debug.ts
2
- import { debuglog } from "util";
3
- var debug_default = debuglog("adonisjs:session");
4
-
5
- export {
6
- debug_default
7
- };
8
- //# sourceMappingURL=chunk-5ECC6OWF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/debug.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 { debuglog } from 'node:util'\n\nexport default debuglog('adonisjs:session')\n"],"mappings":";AASA,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,kBAAkB;","names":[]}
@@ -1,44 +0,0 @@
1
- import {
2
- Session
3
- } from "./chunk-XP3CBOXR.js";
4
-
5
- // src/session_middleware.ts
6
- import { ExceptionHandler } from "@adonisjs/core/http";
7
- var originalErrorHandler = ExceptionHandler.prototype.renderValidationErrorAsHTML;
8
- ExceptionHandler.macro("renderValidationErrorAsHTML", async function(error, ctx) {
9
- if (ctx.session) {
10
- ctx.session.flashValidationErrors(error);
11
- ctx.response.redirect("back", true);
12
- } else {
13
- return originalErrorHandler(error, ctx);
14
- }
15
- });
16
- var SessionMiddleware = class {
17
- #config;
18
- #emitter;
19
- constructor(config, emitter) {
20
- this.#config = config;
21
- this.#emitter = emitter;
22
- }
23
- async handle(ctx, next) {
24
- if (!this.#config.enabled) {
25
- return next();
26
- }
27
- ctx.session = new Session(
28
- this.#config,
29
- this.#config.stores[this.#config.store],
30
- // reference to store factory
31
- this.#emitter,
32
- ctx
33
- );
34
- await ctx.session.initiate(false);
35
- const response = await next();
36
- await ctx.session.commit();
37
- return response;
38
- }
39
- };
40
-
41
- export {
42
- SessionMiddleware
43
- };
44
- //# sourceMappingURL=chunk-6BSSM3HO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/session_middleware.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"],"mappings":";;;;;AAWA,SAAS,wBAAqC;AAiB9C,IAAM,uBAAuB,iBAAiB,UAAU;AACxD,iBAAiB,MAAM,+BAA+B,eAAgB,OAAO,KAAK;AAChF,MAAI,IAAI,SAAS;AACf,QAAI,QAAQ,sBAAsB,KAAK;AACvC,QAAI,SAAS,SAAS,QAAQ,IAAI;AAAA,EACpC,OAAO;AACL,WAAO,qBAAqB,OAAO,GAAG;AAAA,EACxC;AACF,CAAC;AAMD,IAAqB,oBAArB,MAAgG;AAAA,EAC9F;AAAA,EAIA;AAAA,EAEA,YACE,QAIA,SACA;AACA,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,MAAM,OAAO,KAAkB,MAAc;AAC3C,QAAI,CAAC,KAAK,QAAQ,SAAS;AACzB,aAAO,KAAK;AAAA,IACd;AAEA,QAAI,UAAU,IAAI;AAAA,MAChB,KAAK;AAAA,MACL,KAAK,QAAQ,OAAO,KAAK,QAAQ,KAAK;AAAA;AAAA,MACtC,KAAK;AAAA,MACL;AAAA,IACF;AAKA,UAAM,IAAI,QAAQ,SAAS,KAAK;AAKhC,UAAM,WAAW,MAAM,KAAK;AAK5B,UAAM,IAAI,QAAQ,OAAO;AAKzB,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,59 +0,0 @@
1
- import {
2
- E_SESSION_TAGGING_NOT_SUPPORTED
3
- } from "./chunk-XP3CBOXR.js";
4
- import {
5
- debug_default
6
- } from "./chunk-5ECC6OWF.js";
7
-
8
- // src/session_collection.ts
9
- var SessionCollection = class {
10
- #store;
11
- constructor(config) {
12
- const storeFactory = config.stores[config.store];
13
- this.#store = storeFactory(null, config);
14
- }
15
- /**
16
- * Check if the current store supports tagging
17
- */
18
- supportsTagging() {
19
- return "tag" in this.#store && "tagged" in this.#store;
20
- }
21
- /**
22
- * Returns the session data for the given session ID,
23
- * or null if the session does not exist
24
- */
25
- async get(sessionId) {
26
- debug_default("session collection: getting session data %s", sessionId);
27
- return this.#store.read(sessionId);
28
- }
29
- /**
30
- * Destroys a session by its ID
31
- */
32
- async destroy(sessionId) {
33
- debug_default("session collection: destroying session %s", sessionId);
34
- return this.#store.destroy(sessionId);
35
- }
36
- /**
37
- * Tag a session with a user ID.
38
- * Only supported by Memory, Redis and Database stores.
39
- */
40
- async tag(sessionId, userId) {
41
- debug_default("session collection: tagging session %s with user %s", sessionId, userId);
42
- if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
43
- return this.#store.tag(sessionId, userId);
44
- }
45
- /**
46
- * Get all sessions for a given user ID (tag).
47
- * Only supported by Memory, Redis and Database stores.
48
- */
49
- async tagged(userId) {
50
- debug_default("session collection: getting sessions tagged with user %s", userId);
51
- if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED();
52
- return this.#store.tagged(userId);
53
- }
54
- };
55
-
56
- export {
57
- SessionCollection
58
- };
59
- //# sourceMappingURL=chunk-G7KFHA57.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/session_collection.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 debug from './debug.js'\nimport { E_SESSION_TAGGING_NOT_SUPPORTED } from './errors.js'\nimport type {\n ResolvedSessionConfig,\n SessionData,\n SessionStoreWithTaggingContract,\n TaggedSession,\n} from './types.js'\n\n/**\n * SessionCollection provides APIs for programmatic session\n * management. It allows reading, destroying, and tagging\n * sessions without an HTTP context.\n *\n * @example\n * ```ts\n * import app from '@adonisjs/core/services/app'\n * import { SessionCollection } from '@adonisjs/session'\n *\n * const sessionCollection = await app.container.make(SessionCollection)\n *\n * // List all sessions for a user\n * const sessions = await sessionCollection.tagged(String(user.id))\n *\n * // Destroy a specific session\n * await sessionCollection.destroy(sessionId)\n * ```\n */\nexport class SessionCollection {\n #store: SessionStoreWithTaggingContract\n\n constructor(config: ResolvedSessionConfig) {\n const storeFactory = config.stores[config.store]\n this.#store = storeFactory(null as any, config) as SessionStoreWithTaggingContract\n }\n\n /**\n * Check if the current store supports tagging\n */\n supportsTagging(): boolean {\n return 'tag' in this.#store && 'tagged' in this.#store\n }\n\n /**\n * Returns the session data for the given session ID,\n * or null if the session does not exist\n */\n async get(sessionId: string): Promise<SessionData | null> {\n debug('session collection: getting session data %s', sessionId)\n return this.#store.read(sessionId)\n }\n\n /**\n * Destroys a session by its ID\n */\n async destroy(sessionId: string): Promise<void> {\n debug('session collection: destroying session %s', sessionId)\n return this.#store.destroy(sessionId)\n }\n\n /**\n * Tag a session with a user ID.\n * Only supported by Memory, Redis and Database stores.\n */\n async tag(sessionId: string, userId: string): Promise<void> {\n debug('session collection: tagging session %s with user %s', sessionId, userId)\n if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED()\n\n return (this.#store as SessionStoreWithTaggingContract).tag(sessionId, userId)\n }\n\n /**\n * Get all sessions for a given user ID (tag).\n * Only supported by Memory, Redis and Database stores.\n */\n async tagged(userId: string): Promise<TaggedSession[]> {\n debug('session collection: getting sessions tagged with user %s', userId)\n if (!this.supportsTagging()) throw new E_SESSION_TAGGING_NOT_SUPPORTED()\n\n return (this.#store as SessionStoreWithTaggingContract).tagged(userId)\n }\n}\n"],"mappings":";;;;;;;;AAqCO,IAAM,oBAAN,MAAwB;AAAA,EAC7B;AAAA,EAEA,YAAY,QAA+B;AACzC,UAAM,eAAe,OAAO,OAAO,OAAO,KAAK;AAC/C,SAAK,SAAS,aAAa,MAAa,MAAM;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,kBAA2B;AACzB,WAAO,SAAS,KAAK,UAAU,YAAY,KAAK;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,WAAgD;AACxD,kBAAM,+CAA+C,SAAS;AAC9D,WAAO,KAAK,OAAO,KAAK,SAAS;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,WAAkC;AAC9C,kBAAM,6CAA6C,SAAS;AAC5D,WAAO,KAAK,OAAO,QAAQ,SAAS;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,IAAI,WAAmB,QAA+B;AAC1D,kBAAM,uDAAuD,WAAW,MAAM;AAC9E,QAAI,CAAC,KAAK,gBAAgB,EAAG,OAAM,IAAI,gCAAgC;AAEvE,WAAQ,KAAK,OAA2C,IAAI,WAAW,MAAM;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,QAA0C;AACrD,kBAAM,4DAA4D,MAAM;AACxE,QAAI,CAAC,KAAK,gBAAgB,EAAG,OAAM,IAAI,gCAAgC;AAEvE,WAAQ,KAAK,OAA2C,OAAO,MAAM;AAAA,EACvE;AACF;","names":[]}
@@ -1,85 +0,0 @@
1
- import {
2
- ValuesStore
3
- } from "./chunk-TE5JP3SX.js";
4
- import {
5
- debug_default
6
- } from "./chunk-5ECC6OWF.js";
7
-
8
- // src/client.ts
9
- import { cuid } from "@adonisjs/core/helpers";
10
- var SessionClient = class {
11
- /**
12
- * Data store
13
- */
14
- #valuesStore = new ValuesStore({});
15
- /**
16
- * Flash messages store
17
- */
18
- #flashMessagesStore = new ValuesStore({});
19
- /**
20
- * The session store to use for reading and writing session data
21
- */
22
- #store;
23
- /**
24
- * Session key for setting flash messages
25
- */
26
- flashKey = "__flash__";
27
- /**
28
- * Session to use when no explicit session id is
29
- * defined
30
- */
31
- sessionId = cuid();
32
- constructor(store) {
33
- this.#store = store;
34
- }
35
- /**
36
- * Merge session data
37
- */
38
- merge(values) {
39
- this.#valuesStore.merge(values);
40
- return this;
41
- }
42
- /**
43
- * Merge flash messages
44
- */
45
- flash(values) {
46
- this.#flashMessagesStore.merge(values);
47
- return this;
48
- }
49
- /**
50
- * Commits data to the session store.
51
- */
52
- async commit() {
53
- if (!this.#flashMessagesStore.isEmpty) {
54
- this.#valuesStore.set(this.flashKey, this.#flashMessagesStore.toJSON());
55
- }
56
- debug_default("committing session data during api request");
57
- if (!this.#valuesStore.isEmpty) {
58
- this.#store.write(this.sessionId, this.#valuesStore.toJSON());
59
- }
60
- }
61
- /**
62
- * Destroys the session data with the store
63
- */
64
- async destroy(sessionId) {
65
- debug_default("destroying session data during api request");
66
- this.#store.destroy(sessionId || this.sessionId);
67
- }
68
- /**
69
- * Loads session data from the session store
70
- */
71
- async load(sessionId) {
72
- const contents = await this.#store.read(sessionId || this.sessionId);
73
- const store = new ValuesStore(contents);
74
- const flashMessages = store.pull(this.flashKey, {});
75
- return {
76
- values: store.all(),
77
- flashMessages
78
- };
79
- }
80
- };
81
-
82
- export {
83
- SessionClient
84
- };
85
- //# sourceMappingURL=chunk-GCO66PQD.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/client.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 { cuid } from '@adonisjs/core/helpers'\n\nimport debug from './debug.js'\nimport { ValuesStore } from './values_store.js'\nimport type { SessionData, SessionStoreContract } from './types.js'\n\n/**\n * Session client exposes the API to set session data as a client\n */\nexport class SessionClient {\n /**\n * Data store\n */\n #valuesStore = new ValuesStore({})\n\n /**\n * Flash messages store\n */\n #flashMessagesStore = new ValuesStore({})\n\n /**\n * The session store to use for reading and writing session data\n */\n #store: SessionStoreContract\n\n /**\n * Session key for setting flash messages\n */\n flashKey = '__flash__'\n\n /**\n * Session to use when no explicit session id is\n * defined\n */\n sessionId = cuid()\n\n constructor(store: SessionStoreContract) {\n this.#store = store\n }\n\n /**\n * Merge session data\n */\n merge(values: SessionData) {\n this.#valuesStore.merge(values)\n return this\n }\n\n /**\n * Merge flash messages\n */\n flash(values: SessionData) {\n this.#flashMessagesStore.merge(values)\n return this\n }\n\n /**\n * Commits data to the session store.\n */\n async commit() {\n if (!this.#flashMessagesStore.isEmpty) {\n this.#valuesStore.set(this.flashKey, this.#flashMessagesStore.toJSON())\n }\n\n debug('committing session data during api request')\n if (!this.#valuesStore.isEmpty) {\n this.#store.write(this.sessionId, this.#valuesStore.toJSON())\n }\n }\n\n /**\n * Destroys the session data with the store\n */\n async destroy(sessionId?: string) {\n debug('destroying session data during api request')\n this.#store.destroy(sessionId || this.sessionId)\n }\n\n /**\n * Loads session data from the session store\n */\n async load(sessionId?: string) {\n const contents = await this.#store.read(sessionId || this.sessionId)\n const store = new ValuesStore(contents)\n const flashMessages = store.pull(this.flashKey, {})\n\n return {\n values: store.all(),\n flashMessages,\n }\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAS,YAAY;AASd,IAAM,gBAAN,MAAoB;AAAA;AAAA;AAAA;AAAA,EAIzB,eAAe,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAKjC,sBAAsB,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAKxC;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAMX,YAAY,KAAK;AAAA,EAEjB,YAAY,OAA6B;AACvC,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqB;AACzB,SAAK,aAAa,MAAM,MAAM;AAC9B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqB;AACzB,SAAK,oBAAoB,MAAM,MAAM;AACrC,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,SAAS;AACb,QAAI,CAAC,KAAK,oBAAoB,SAAS;AACrC,WAAK,aAAa,IAAI,KAAK,UAAU,KAAK,oBAAoB,OAAO,CAAC;AAAA,IACxE;AAEA,kBAAM,4CAA4C;AAClD,QAAI,CAAC,KAAK,aAAa,SAAS;AAC9B,WAAK,OAAO,MAAM,KAAK,WAAW,KAAK,aAAa,OAAO,CAAC;AAAA,IAC9D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,WAAoB;AAChC,kBAAM,4CAA4C;AAClD,SAAK,OAAO,QAAQ,aAAa,KAAK,SAAS;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,WAAoB;AAC7B,UAAM,WAAW,MAAM,KAAK,OAAO,KAAK,aAAa,KAAK,SAAS;AACnE,UAAM,QAAQ,IAAI,YAAY,QAAQ;AACtC,UAAM,gBAAgB,MAAM,KAAK,KAAK,UAAU,CAAC,CAAC;AAElD,WAAO;AAAA,MACL,QAAQ,MAAM,IAAI;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,10 +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
- export {
8
- __export
9
- };
10
- //# sourceMappingURL=chunk-PZ5AY32C.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}