@adonisjs/session 7.0.0-14 → 7.0.0-15
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.
- package/build/{chunk-QH2GQQKL.js → chunk-HIQQAMXD.js} +6 -7
- package/build/chunk-HIQQAMXD.js.map +1 -0
- package/build/{chunk-C6BYE7BG.js → chunk-K4OSGJVW.js} +24 -12
- package/build/chunk-K4OSGJVW.js.map +1 -0
- package/build/{chunk-4TGV4EVQ.js → chunk-S6P3TBEK.js} +2 -2
- package/build/{chunk-KM6IRYLY.js → chunk-TE5JP3SX.js} +1 -1
- package/build/chunk-TE5JP3SX.js.map +1 -0
- package/build/factories/main.js +3 -3
- package/build/index.d.ts +0 -1
- package/build/index.js +3 -5
- package/build/providers/session_provider.js +2 -2
- package/build/src/client.js +2 -2
- package/build/src/plugins/edge.js +35 -5
- package/build/src/plugins/edge.js.map +1 -1
- package/build/src/plugins/japa/api_client.js +2 -2
- package/build/src/plugins/japa/browser_client.js +2 -2
- package/build/src/session.d.ts +14 -5
- package/build/src/session_middleware.js +2 -2
- package/build/src/values_store.d.ts +7 -7
- package/package.json +27 -27
- package/build/chunk-C6BYE7BG.js.map +0 -1
- package/build/chunk-KM6IRYLY.js.map +0 -1
- package/build/chunk-QH2GQQKL.js.map +0 -1
- /package/build/{chunk-4TGV4EVQ.js.map → chunk-S6P3TBEK.js.map} +0 -0
- /package/build/{config.stub → config/session.stub} +0 -0
|
@@ -2,10 +2,14 @@ import {
|
|
|
2
2
|
debug_default
|
|
3
3
|
} from "./chunk-WBAYBMJJ.js";
|
|
4
4
|
|
|
5
|
+
// stubs/main.ts
|
|
6
|
+
import { getDirname } from "@poppinss/utils";
|
|
7
|
+
var stubsRoot = getDirname(import.meta.url);
|
|
8
|
+
|
|
5
9
|
// configure.ts
|
|
6
10
|
async function configure(command) {
|
|
7
|
-
await command.publishStub("config.stub");
|
|
8
11
|
const codemods = await command.createCodemods();
|
|
12
|
+
await codemods.makeUsingStub(stubsRoot, "config/session.stub", {});
|
|
9
13
|
await codemods.defineEnvVariables({ SESSION_DRIVER: "cookie" });
|
|
10
14
|
await codemods.defineEnvValidations({
|
|
11
15
|
variables: {
|
|
@@ -23,10 +27,6 @@ async function configure(command) {
|
|
|
23
27
|
});
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
// stubs/main.ts
|
|
27
|
-
import { getDirname } from "@poppinss/utils";
|
|
28
|
-
var stubsRoot = getDirname(import.meta.url);
|
|
29
|
-
|
|
30
30
|
// src/define_config.ts
|
|
31
31
|
import string from "@poppinss/utils/string";
|
|
32
32
|
import { configProvider } from "@adonisjs/core";
|
|
@@ -127,8 +127,7 @@ var stores = {
|
|
|
127
127
|
|
|
128
128
|
export {
|
|
129
129
|
configure,
|
|
130
|
-
stubsRoot,
|
|
131
130
|
defineConfig,
|
|
132
131
|
stores
|
|
133
132
|
};
|
|
134
|
-
//# sourceMappingURL=chunk-
|
|
133
|
+
//# sourceMappingURL=chunk-HIQQAMXD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../stubs/main.ts","../configure.ts","../src/define_config.ts","../src/stores/memory.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 { getDirname } from '@poppinss/utils'\n\nexport const stubsRoot = getDirname(import.meta.url)\n","/*\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 type Configure from '@adonisjs/core/commands/configure'\nimport { stubsRoot } from './stubs/main.js'\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n const codemods = await command.createCodemods()\n\n /**\n * Publish config file\n */\n await codemods.makeUsingStub(stubsRoot, 'config/session.stub', {})\n\n /**\n * Define environment variables\n */\n await codemods.defineEnvVariables({ SESSION_DRIVER: 'cookie' })\n\n /**\n * Define environment variables validations\n */\n await codemods.defineEnvValidations({\n variables: {\n SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`,\n },\n leadingComment: 'Variables for configuring session package',\n })\n\n /**\n * Register middleware\n */\n await codemods.registerMiddleware('router', [\n {\n path: '@adonisjs/session/session_middleware',\n },\n ])\n\n /**\n * Register provider\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/session/session_provider')\n })\n}\n","/*\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\n/// <reference types=\"@adonisjs/redis/redis_provider\" />\n\nimport string from '@poppinss/utils/string'\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport { InvalidArgumentsException } from '@poppinss/utils'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport { MemoryStore } from './stores/memory.js'\nimport type {\n SessionConfig,\n FileStoreConfig,\n RedisStoreConfig,\n SessionStoreFactory,\n} from './types.js'\n\n/**\n * Resolved config with stores\n */\ntype ResolvedConfig<KnownStores extends Record<string, SessionStoreFactory>> = SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n cookie: Partial<CookieOptions>\n}\n\n/**\n * Helper to normalize session config\n */\nexport function defineConfig<\n KnownStores extends Record<string, SessionStoreFactory | ConfigProvider<SessionStoreFactory>>,\n>(\n config: Partial<SessionConfig> & {\n store: keyof KnownStores | 'memory'\n stores: KnownStores\n }\n): ConfigProvider<\n ResolvedConfig<{\n [K in keyof KnownStores]: SessionStoreFactory\n }>\n> {\n debug('processing session config %O', config)\n\n /**\n * Make sure a store is defined\n */\n if (!config.store) {\n throw new InvalidArgumentsException('Missing \"store\" property inside the session config')\n }\n\n /**\n * Destructuring config with the default values. We pull out\n * stores and cookie values, since we have to transform\n * them in the output value.\n */\n const { stores, cookie, ...rest } = {\n enabled: true,\n age: '2h',\n cookieName: 'adonis_session',\n clearWithBrowser: false,\n ...config,\n }\n\n const cookieOptions: Partial<CookieOptions> = { ...cookie }\n\n /**\n * Define maxAge property when session id cookie is\n * not a session cookie.\n */\n if (!rest.clearWithBrowser) {\n cookieOptions.maxAge = string.seconds.parse(rest.age)\n debug('computing maxAge \"%s\" for session id cookie', cookieOptions.maxAge)\n }\n\n return configProvider.create(async (app) => {\n const storesNames = Object.keys(config.stores)\n\n /**\n * List of stores with memory store always configured\n */\n const storesList = {\n memory: () => new MemoryStore(),\n } as Record<string, SessionStoreFactory>\n\n /**\n * Looping for stores and resolving them\n */\n for (let storeName of storesNames) {\n const store = config.stores[storeName]\n if (typeof store === 'function') {\n storesList[storeName] = store\n } else {\n storesList[storeName] = await store.resolver(app)\n }\n }\n\n const transformedConfig = {\n ...rest,\n cookie: cookieOptions,\n stores: storesList as { [K in keyof KnownStores]: SessionStoreFactory },\n }\n\n debug('transformed session config %O', transformedConfig)\n return transformedConfig\n })\n}\n\n/**\n * Inbuilt stores to store the session data.\n */\nexport const stores: {\n file: (config: FileStoreConfig) => ConfigProvider<SessionStoreFactory>\n redis: (config: RedisStoreConfig) => ConfigProvider<SessionStoreFactory>\n cookie: () => ConfigProvider<SessionStoreFactory>\n} = {\n file: (config) => {\n return configProvider.create(async () => {\n const { FileStore } = await import('./stores/file.js')\n return (_, sessionConfig: SessionConfig) => {\n return new FileStore(config, sessionConfig.age)\n }\n })\n },\n redis: (config) => {\n return configProvider.create(async (app) => {\n const { RedisStore } = await import('./stores/redis.js')\n const redis = await app.container.make('redis')\n\n return (_, sessionConfig: SessionConfig) => {\n return new RedisStore(redis.connection(config.connection), sessionConfig.age)\n }\n })\n },\n cookie: () => {\n return configProvider.create(async () => {\n const { CookieStore } = await import('./stores/cookie.js')\n return (ctx, sessionConfig: SessionConfig) => {\n return new CookieStore(sessionConfig.cookie, ctx)\n }\n })\n },\n}\n","/**\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 type { SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * Memory store is meant to be used for writing tests.\n */\nexport class MemoryStore implements SessionStoreContract {\n static sessions: Map<string, SessionData> = new Map()\n\n /**\n * Read session id value from the memory\n */\n read(sessionId: string): SessionData | null {\n return MemoryStore.sessions.get(sessionId) || null\n }\n\n /**\n * Save in memory value for a given session id\n */\n write(sessionId: string, values: SessionData): void {\n MemoryStore.sessions.set(sessionId, values)\n }\n\n /**\n * Cleanup for a single session\n */\n destroy(sessionId: string): void {\n MemoryStore.sessions.delete(sessionId)\n }\n\n touch(): void {}\n}\n"],"mappings":";;;;;AASA,SAAS,kBAAkB;AAEpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACInD,eAAsB,UAAU,SAAoB;AAClD,QAAM,WAAW,MAAM,QAAQ,eAAe;AAK9C,QAAM,SAAS,cAAc,WAAW,uBAAuB,CAAC,CAAC;AAKjE,QAAM,SAAS,mBAAmB,EAAE,gBAAgB,SAAS,CAAC;AAK9D,QAAM,SAAS,qBAAqB;AAAA,IAClC,WAAW;AAAA,MACT,gBAAgB;AAAA,IAClB;AAAA,IACA,gBAAgB;AAAA,EAClB,CAAC;AAKD,QAAM,SAAS,mBAAmB,UAAU;AAAA,IAC1C;AAAA,MACE,MAAM;AAAA,IACR;AAAA,EACF,CAAC;AAKD,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,YAAY,oCAAoC;AAAA,EACzD,CAAC;AACH;;;AC1CA,OAAO,YAAY;AACnB,SAAS,sBAAsB;AAE/B,SAAS,iCAAiC;;;ACAnC,IAAM,cAAN,MAAM,aAA4C;AAAA,EACvD,OAAO,WAAqC,oBAAI,IAAI;AAAA;AAAA;AAAA;AAAA,EAKpD,KAAK,WAAuC;AAC1C,WAAO,aAAY,SAAS,IAAI,SAAS,KAAK;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAmB,QAA2B;AAClD,iBAAY,SAAS,IAAI,WAAW,MAAM;A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;AACrD,aAAO,CAAC,GAAG,kBAAiC;AAC1C,eAAO,IAAI,UAAU,QAAQ,cAAc,GAAG;AAAA,MAChD;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,OAAO,CAAC,WAAW;AACjB,WAAO,eAAe,OAAO,OAAO,QAAQ;AAC1C,YAAM,EAAE,WAAW,IAAI,MAAM,OAAO,qBAAmB;AACvD,YAAM,QAAQ,MAAM,IAAI,UAAU,KAAK,OAAO;AAE9C,aAAO,CAAC,GAAG,kBAAiC;AAC1C,eAAO,IAAI,WAAW,MAAM,WAAW,OAAO,UAAU,GAAG,cAAc,GAAG;AAAA,MAC9E;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EACA,QAAQ,MAAM;AACZ,WAAO,eAAe,OAAO,YAAY;AACvC,YAAM,EAAE,YAAY,IAAI,MAAM,OAAO,sBAAoB;AACzD,aAAO,CAAC,KAAK,kBAAiC;AAC5C,eAAO,IAAI,YAAY,cAAc,QAAQ,GAAG;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["stores"]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
ReadOnlyValuesStore,
|
|
7
7
|
ValuesStore
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TE5JP3SX.js";
|
|
9
9
|
import {
|
|
10
10
|
debug_default
|
|
11
11
|
} from "./chunk-WBAYBMJJ.js";
|
|
@@ -229,9 +229,29 @@ var Session = class {
|
|
|
229
229
|
clear() {
|
|
230
230
|
return this.#getValuesStore("write").clear();
|
|
231
231
|
}
|
|
232
|
+
flash(key, value) {
|
|
233
|
+
if (typeof key === "string") {
|
|
234
|
+
if (value) {
|
|
235
|
+
this.#getFlashStore("write").set(key, value);
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
this.#getFlashStore("write").merge(key);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Flash errors to the errorsBag. You can read these
|
|
243
|
+
* errors via the "@error" tag.
|
|
244
|
+
*
|
|
245
|
+
* Appends new messages to the existing collection.
|
|
246
|
+
*/
|
|
247
|
+
flashErrors(errorsCollection) {
|
|
248
|
+
this.flash({ errorsBag: errorsCollection });
|
|
249
|
+
}
|
|
232
250
|
/**
|
|
233
251
|
* Flash validation error messages. Make sure the error
|
|
234
|
-
* is an instance of VineJS ValidationException
|
|
252
|
+
* is an instance of VineJS ValidationException.
|
|
253
|
+
*
|
|
254
|
+
* Overrides existing inputErrors
|
|
235
255
|
*/
|
|
236
256
|
flashValidationErrors(error) {
|
|
237
257
|
const errorsBag = error.messages.reduce((result, message) => {
|
|
@@ -243,17 +263,9 @@ var Session = class {
|
|
|
243
263
|
return result;
|
|
244
264
|
}, {});
|
|
245
265
|
this.flashExcept(["_csrf", "_method"]);
|
|
266
|
+
this.flash("inputErrorsBag", errorsBag);
|
|
246
267
|
this.flash("errors", errorsBag);
|
|
247
268
|
}
|
|
248
|
-
flash(key, value) {
|
|
249
|
-
if (typeof key === "string") {
|
|
250
|
-
if (value) {
|
|
251
|
-
this.#getFlashStore("write").set(key, value);
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
this.#getFlashStore("write").merge(key);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
269
|
/**
|
|
258
270
|
* Flash form input data to the flash messages store
|
|
259
271
|
*/
|
|
@@ -387,4 +399,4 @@ var SessionMiddleware = class {
|
|
|
387
399
|
export {
|
|
388
400
|
SessionMiddleware
|
|
389
401
|
};
|
|
390
|
-
//# sourceMappingURL=chunk-
|
|
402
|
+
//# sourceMappingURL=chunk-K4OSGJVW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/session_middleware.ts","../src/session.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","/*\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 lodash from '@poppinss/utils/lodash'\nimport { cuid } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterService } from '@adonisjs/core/types'\nimport type { HttpError } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport * as errors from './errors.js'\nimport { ReadOnlyValuesStore, ValuesStore } from './values_store.js'\nimport type {\n SessionData,\n SessionConfig,\n SessionStoreFactory,\n AllowedSessionValues,\n SessionStoreContract,\n} from './types.js'\n\n/**\n * The session class exposes the API to read and write values to\n * the session store.\n *\n * A session instance is isolated between requests but\n * uses a centralized persistence store and\n */\nexport class Session {\n #config: SessionConfig\n #store: SessionStoreContract\n #emitter: EmitterService\n #ctx: HttpContext\n #readonly: boolean = false\n\n /**\n * Session values store\n */\n #valuesStore?: ValuesStore\n\n /**\n * Session id refers to the session id that will be committed\n * as a cookie during the response.\n */\n #sessionId: string\n\n /**\n * Session id from cookie refers to the value we read from the\n * cookie during the HTTP request.\n *\n * This only might not exist during the first request. Also during\n * session id re-generation, this value will be different from\n * the session id.\n */\n #sessionIdFromCookie?: string\n\n /**\n * Store of flash messages that be written during the\n * HTTP request\n */\n responseFlashMessages = new ValuesStore({})\n\n /**\n * Store of flash messages for the current HTTP request.\n */\n flashMessages = new ValuesStore({})\n\n /**\n * The key to use for storing flash messages inside\n * the session store.\n */\n flashKey: string = '__flash__'\n\n /**\n * Session id for the current HTTP request\n */\n get sessionId() {\n return this.#sessionId\n }\n\n /**\n * A boolean to know if a fresh session is created during\n * the request\n */\n get fresh(): boolean {\n return this.#sessionIdFromCookie === undefined\n }\n\n /**\n * A boolean to know if session is in readonly\n * state\n */\n get readonly() {\n return this.#readonly\n }\n\n /**\n * A boolean to know if session store has been initiated\n */\n get initiated() {\n return !!this.#valuesStore\n }\n\n /**\n * A boolean to know if the session id has been re-generated\n * during the current request\n */\n get hasRegeneratedSession() {\n return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId)\n }\n\n /**\n * A boolean to know if the session store is empty\n */\n get isEmpty() {\n return this.#valuesStore?.isEmpty ?? true\n }\n\n /**\n * A boolean to know if the session store has been\n * modified\n */\n get hasBeenModified() {\n return this.#valuesStore?.hasBeenModified ?? false\n }\n\n constructor(\n config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n this.#ctx = ctx\n this.#config = config\n this.#emitter = emitter\n this.#store = storeFactory(ctx, config)\n this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, undefined)\n this.#sessionId = this.#sessionIdFromCookie || cuid()\n }\n\n /**\n * Returns the flash messages store for a given\n * mode\n */\n #getFlashStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.responseFlashMessages\n }\n\n /**\n * Returns the store instance for a given mode\n */\n #getValuesStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.#valuesStore\n }\n\n /**\n * Initiates the session store. The method results in a noop\n * when called multiple times\n */\n async initiate(readonly: boolean): Promise<void> {\n if (this.#valuesStore) {\n return\n }\n\n debug('initiating session (readonly: %s)', readonly)\n\n this.#readonly = readonly\n const contents = await this.#store.read(this.#sessionId)\n this.#valuesStore = new ValuesStore(contents)\n\n /**\n * Extract flash messages from the store and keep a local\n * copy of it.\n */\n if (this.has(this.flashKey)) {\n debug('reading flash data')\n if (this.#readonly) {\n this.flashMessages.update(this.get(this.flashKey, null))\n } else {\n this.flashMessages.update(this.pull(this.flashKey, null))\n }\n }\n\n /**\n * Share session with the templates. We assume the view property\n * is a reference to edge templates\n */\n if ('view' in this.#ctx) {\n this.#ctx.view.share({\n session: new ReadOnlyValuesStore(this.#valuesStore.all()),\n flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),\n old: function (key: string, defaultValue?: any) {\n return this.flashMessages.get(key, defaultValue)\n },\n })\n }\n\n this.#emitter.emit('session:initiated', { session: this })\n }\n\n /**\n * Put a key-value pair to the session data store\n */\n put(key: string, value: AllowedSessionValues) {\n this.#getValuesStore('write').set(key, value)\n }\n\n /**\n * Check if a key exists inside the datastore\n */\n has(key: string): boolean {\n return this.#getValuesStore('read').has(key)\n }\n\n /**\n * Get the value of a key from the session datastore.\n * You can specify a default value to use, when key\n * does not exists or has undefined value.\n */\n get(key: string, defaultValue?: any) {\n return this.#getValuesStore('read').get(key, defaultValue)\n }\n\n /**\n * Get everything from the session store\n */\n all() {\n return this.#getValuesStore('read').all()\n }\n\n /**\n * Remove a key from the session datastore\n */\n forget(key: string) {\n return this.#getValuesStore('write').unset(key)\n }\n\n /**\n * Read value for a key from the session datastore\n * and remove it simultaneously.\n */\n pull(key: string, defaultValue?: any) {\n return this.#getValuesStore('write').pull(key, defaultValue)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be 1\n */\n increment(key: string, steps: number = 1) {\n return this.#getValuesStore('write').increment(key, steps)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be -1\n */\n decrement(key: string, steps: number = 1) {\n return this.#getValuesStore('write').decrement(key, steps)\n }\n\n /**\n * Empty the session store\n */\n clear() {\n return this.#getValuesStore('write').clear()\n }\n\n /**\n * Add a key-value pair to flash messages\n */\n flash(key: string, value: AllowedSessionValues): void\n flash(keyValue: SessionData): void\n flash(key: string | SessionData, value?: AllowedSessionValues): void {\n if (typeof key === 'string') {\n if (value) {\n this.#getFlashStore('write').set(key, value)\n }\n } else {\n this.#getFlashStore('write').merge(key)\n }\n }\n\n /**\n * Flash errors to the errorsBag. You can read these\n * errors via the \"@error\" tag.\n *\n * Appends new messages to the existing collection.\n */\n flashErrors(errorsCollection: Record<string, string | string[]>) {\n this.flash({ errorsBag: errorsCollection })\n }\n\n /**\n * Flash validation error messages. Make sure the error\n * is an instance of VineJS ValidationException.\n *\n * Overrides existing inputErrors\n */\n flashValidationErrors(error: HttpError) {\n const errorsBag = error.messages.reduce((result: Record<string, string[]>, message: any) => {\n if (result[message.field]) {\n result[message.field].push(message.message)\n } else {\n result[message.field] = [message.message]\n }\n return result\n }, {})\n\n this.flashExcept(['_csrf', '_method'])\n\n /**\n * Adding to inputErrorsBag for \"@inputError\" tag\n * to read validation errors\n */\n this.flash('inputErrorsBag', errorsBag)\n\n /**\n * For legacy support and not to break apps using\n * the older version of @adonisjs/session package\n */\n this.flash('errors', errorsBag)\n }\n\n /**\n * Flash form input data to the flash messages store\n */\n flashAll() {\n return this.#getFlashStore('write').set('input', this.#ctx.request.original())\n }\n\n /**\n * Flash form input data (except some keys) to the flash messages store\n */\n flashExcept(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.omit(this.#ctx.request.original(), keys))\n }\n\n /**\n * Flash form input data (only some keys) to the flash messages store\n */\n flashOnly(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.pick(this.#ctx.request.original(), keys))\n }\n\n /**\n * Reflash messages from the last request in the current response\n */\n reflash(): void {\n this.#getFlashStore('write').set('reflashed', this.flashMessages.all())\n }\n\n /**\n * Reflash messages (only some keys) from the last\n * request in the current response\n */\n reflashOnly(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.pick(this.flashMessages.all(), keys))\n }\n\n /**\n * Reflash messages (except some keys) from the last\n * request in the current response\n */\n reflashExcept(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.omit(this.flashMessages.all(), keys))\n }\n\n /**\n * Re-generate the session id and migrate data to it.\n */\n regenerate() {\n this.#sessionId = cuid()\n }\n\n /**\n * Commit session changes. No more mutations will be\n * allowed after commit.\n */\n async commit() {\n if (!this.#valuesStore || this.readonly) {\n return\n }\n\n /**\n * If the flash messages store is not empty, we should put\n * its messages inside main session store.\n */\n if (!this.responseFlashMessages.isEmpty) {\n const { input, reflashed, ...others } = this.responseFlashMessages.all()\n this.put(this.flashKey, { ...reflashed, ...input, ...others })\n }\n\n debug('committing session data')\n\n /**\n * Touch the session id cookie to stay alive\n */\n this.#ctx.response.cookie(this.#config.cookieName, this.#sessionId, this.#config.cookie!)\n\n /**\n * Delete the session data when the session store\n * is empty.\n *\n * Also we only destroy the session id we read from the cookie.\n * If there was no session id in the cookie, there won't be\n * any data inside the store either.\n */\n if (this.isEmpty) {\n if (this.#sessionIdFromCookie) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Touch the store expiry when the session store was\n * not modified.\n */\n if (!this.hasBeenModified) {\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.touch(this.#sessionId)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Otherwise commit to the session store\n */\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n }\n\n this.#emitter.emit('session:committed', { session: this })\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAS,wBAAqC;;;ACF9C,OAAO,YAAY;AACnB,SAAS,YAAY;AAuBd,IAAM,UAAN,MAAc;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,wBAAwB,IAAI,YAAY,CAAC,CAAC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k-
|
|
3
|
+
} from "./chunk-TE5JP3SX.js";
|
|
4
4
|
import {
|
|
5
5
|
debug_default
|
|
6
6
|
} from "./chunk-WBAYBMJJ.js";
|
|
@@ -82,4 +82,4 @@ var SessionClient = class {
|
|
|
82
82
|
export {
|
|
83
83
|
SessionClient
|
|
84
84
|
};
|
|
85
|
-
//# sourceMappingURL=chunk-
|
|
85
|
+
//# sourceMappingURL=chunk-S6P3TBEK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/values_store.ts"],"sourcesContent":["/*\n * @adonisjs/redis\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 lodash from '@poppinss/utils/lodash'\nimport { RuntimeException } from '@poppinss/utils'\nimport type { AllowedSessionValues, SessionData } from './types.js'\n\n/**\n * Readonly session store\n */\nexport class ReadOnlyValuesStore {\n /**\n * Underlying store values\n */\n protected values: SessionData\n\n /**\n * Find if store is empty or not\n */\n get isEmpty() {\n return !this.values || Object.keys(this.values).length === 0\n }\n\n constructor(values: SessionData | null) {\n this.values = values || {}\n }\n\n /**\n * Get value for a given key\n */\n get(key: string | string[], defaultValue?: any): any {\n const value = lodash.get(this.values, key)\n if (defaultValue !== undefined && (value === null || value === undefined)) {\n return defaultValue\n }\n\n return value\n }\n\n /**\n * A boolean to know if value exists. Extra guards to check\n * arrays for it's length as well.\n */\n has(key: string | string[], checkForArraysLength: boolean = true): boolean {\n const value = this.get(key)\n if (!Array.isArray(value)) {\n return !!value\n }\n\n return checkForArraysLength ? value.length > 0 : !!value\n }\n\n /**\n * Get all values\n */\n all(): any {\n return this.values\n }\n\n /**\n * Returns object representation of values\n */\n toObject() {\n return this.all()\n }\n\n /**\n * Returns the store values\n */\n toJSON(): any {\n return this.all()\n }\n\n /**\n * Returns string representation of the store\n */\n toString() {\n return JSON.stringify(this.all())\n }\n}\n\n/**\n * Session store encapsulates the session data and offers a\n * declarative API to mutate it.\n */\nexport class ValuesStore extends ReadOnlyValuesStore {\n /**\n * A boolean to know if store has been\n * modified\n */\n #modified: boolean = false\n\n constructor(values: SessionData | null) {\n super(values)\n }\n\n /**\n * Find if the store has been modified.\n */\n get hasBeenModified(): boolean {\n return this.#modified\n }\n\n /**\n * Set key/value pair\n */\n set(key: string | string[], value: AllowedSessionValues): void {\n this.#modified = true\n lodash.set(this.values, key, value)\n }\n\n /**\n * Remove key\n */\n unset(key: string | string[]): void {\n this.#modified = true\n lodash.unset(this.values, key)\n }\n\n /**\n * Pull value from the store. It is same as calling\n * store.get and then store.unset\n */\n pull(key: string | string[], defaultValue?: any): any {\n return ((value): any => {\n this.unset(key)\n return value\n })(this.get(key, defaultValue))\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n increment(key: string | string[], steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot increment \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value + steps)\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n decrement(key: string | string[], steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot decrement \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value - steps)\n }\n\n /**\n * Overwrite existing store data with new values.\n */\n update(values: { [key: string]: any }): void {\n this.#modified = true\n this.values = values\n }\n\n /**\n * Update to merge values\n */\n merge(values: { [key: string]: any }): any {\n this.#modified = true\n lodash.merge(this.values, values)\n }\n\n /**\n * Reset store by clearing it's values.\n */\n clear(): void {\n this.update({})\n }\n}\n"],"mappings":";AASA,OAAO,YAAY;AACnB,SAAS,wBAAwB;AAM1B,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA,EAIrB;AAAA;AAAA;AAAA;AAAA,EAKV,IAAI,UAAU;AACZ,WAAO,CAAC,KAAK,UAAU,OAAO,KAAK,KAAK,MAAM,EAAE,WAAW;AAAA,EAC7D;AAA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GAAG;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,KAAwB,cAAyB;AACpD,YAAQ,CAAC,UAAe;AACtB,WAAK,MAAM,GAAG;AACd,aAAO;AAAA,IACT,GAAG,KAAK,IAAI,KAAK,YAAY,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,KAAwB,QAAgB,GAAS;AACzD,UAAM,QAAQ,KAAK,IAAI,KAAK,CAAC;AAC7B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,iBAAiB,qBAAqB,GAAG,mCAAmC;AAAA,IACxF;AAEA,SAAK,IAAI,KAAK,QAAQ,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,KAAwB,QAAgB,GAAS;AACzD,UAAM,QAAQ,KAAK,IAAI,KAAK,CAAC;AAC7B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,iBAAiB,qBAAqB,GAAG,mCAAmC;AAAA,IACxF;AAEA,SAAK,IAAI,KAAK,QAAQ,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,QAAsC;AAC3C,SAAK,YAAY;AACjB,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqC;AACzC,SAAK,YAAY;AACjB,WAAO,MAAM,KAAK,QAAQ,MAAM;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,OAAO,CAAC,CAAC;AAAA,EAChB;AACF;","names":[]}
|
package/build/factories/main.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineConfig
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-HIQQAMXD.js";
|
|
4
4
|
import {
|
|
5
5
|
SessionMiddleware
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-K4OSGJVW.js";
|
|
7
7
|
import "../chunk-2X5L327N.js";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-TE5JP3SX.js";
|
|
9
9
|
import "../chunk-WBAYBMJJ.js";
|
|
10
10
|
|
|
11
11
|
// factories/session_middleware_factory.ts
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
configure,
|
|
3
3
|
defineConfig,
|
|
4
|
-
stores
|
|
5
|
-
|
|
6
|
-
} from "./chunk-QH2GQQKL.js";
|
|
4
|
+
stores
|
|
5
|
+
} from "./chunk-HIQQAMXD.js";
|
|
7
6
|
import {
|
|
8
7
|
errors_exports
|
|
9
8
|
} from "./chunk-2X5L327N.js";
|
|
@@ -12,7 +11,6 @@ export {
|
|
|
12
11
|
configure,
|
|
13
12
|
defineConfig,
|
|
14
13
|
errors_exports as errors,
|
|
15
|
-
stores
|
|
16
|
-
stubsRoot
|
|
14
|
+
stores
|
|
17
15
|
};
|
|
18
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionMiddleware
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-K4OSGJVW.js";
|
|
4
4
|
import "../chunk-2X5L327N.js";
|
|
5
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-TE5JP3SX.js";
|
|
6
6
|
import "../chunk-WBAYBMJJ.js";
|
|
7
7
|
|
|
8
8
|
// providers/session_provider.ts
|
package/build/src/client.js
CHANGED
|
@@ -22,12 +22,42 @@ var edgePluginSession = (edge) => {
|
|
|
22
22
|
token.loc.start.line
|
|
23
23
|
);
|
|
24
24
|
buffer.writeExpression(
|
|
25
|
-
`let message = state.flashMessages.get(${key})`,
|
|
25
|
+
`let $message = state.flashMessages.get(${key})`,
|
|
26
26
|
token.filename,
|
|
27
27
|
token.loc.start.line
|
|
28
28
|
);
|
|
29
29
|
parser.stack.defineScope();
|
|
30
|
-
parser.stack.defineVariable("message");
|
|
30
|
+
parser.stack.defineVariable("$message");
|
|
31
|
+
token.children.forEach((child) => {
|
|
32
|
+
parser.processToken(child, buffer);
|
|
33
|
+
});
|
|
34
|
+
parser.stack.clearScope();
|
|
35
|
+
buffer.writeStatement(`}`, token.filename, token.loc.start.line);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
edge.registerTag({
|
|
39
|
+
tagName: "inputError",
|
|
40
|
+
seekable: true,
|
|
41
|
+
block: true,
|
|
42
|
+
compile(parser, buffer, token) {
|
|
43
|
+
const expression = parser.utils.transformAst(
|
|
44
|
+
parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),
|
|
45
|
+
token.filename,
|
|
46
|
+
parser
|
|
47
|
+
);
|
|
48
|
+
const key = parser.utils.stringify(expression);
|
|
49
|
+
buffer.writeStatement(
|
|
50
|
+
`if (!!state.flashMessages.get('inputErrorsBag', {})[${key}]) {`,
|
|
51
|
+
token.filename,
|
|
52
|
+
token.loc.start.line
|
|
53
|
+
);
|
|
54
|
+
buffer.writeExpression(
|
|
55
|
+
`let $messages = state.flashMessages.get('inputErrorsBag', {})[${key}]`,
|
|
56
|
+
token.filename,
|
|
57
|
+
token.loc.start.line
|
|
58
|
+
);
|
|
59
|
+
parser.stack.defineScope();
|
|
60
|
+
parser.stack.defineVariable("$messages");
|
|
31
61
|
token.children.forEach((child) => {
|
|
32
62
|
parser.processToken(child, buffer);
|
|
33
63
|
});
|
|
@@ -47,17 +77,17 @@ var edgePluginSession = (edge) => {
|
|
|
47
77
|
);
|
|
48
78
|
const key = parser.utils.stringify(expression);
|
|
49
79
|
buffer.writeStatement(
|
|
50
|
-
`if (
|
|
80
|
+
`if (state.flashMessages.has(['errorsBag', ${key}])) {`,
|
|
51
81
|
token.filename,
|
|
52
82
|
token.loc.start.line
|
|
53
83
|
);
|
|
54
84
|
buffer.writeExpression(
|
|
55
|
-
`let
|
|
85
|
+
`let $message = state.flashMessages.get(['errorsBag', ${key}])`,
|
|
56
86
|
token.filename,
|
|
57
87
|
token.loc.start.line
|
|
58
88
|
);
|
|
59
89
|
parser.stack.defineScope();
|
|
60
|
-
parser.stack.defineVariable("
|
|
90
|
+
parser.stack.defineVariable("$message");
|
|
61
91
|
token.children.forEach((child) => {
|
|
62
92
|
parser.processToken(child, buffer);
|
|
63
93
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/edge.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 type { PluginFn } from 'edge.js/types'\nimport debug from '../debug.js'\n\n/**\n * The edge plugin for AdonisJS Session adds tags to read\n * flash messages\n */\nexport const edgePluginSession: PluginFn<undefined> = (edge) => {\n debug('registering session tags with edge')\n\n edge.registerTag({\n tagName: 'flashMessage',\n seekable: true,\n block: true,\n compile(parser, buffer, token) {\n const expression = parser.utils.transformAst(\n parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),\n token.filename,\n parser\n )\n\n const key = parser.utils.stringify(expression)\n\n /**\n * Write an if statement\n */\n buffer.writeStatement(\n `if (state.flashMessages.has(${key})) {`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Define a local variable\n */\n buffer.writeExpression(\n `let message = state.flashMessages.get(${key})`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Create a local variables scope and tell the parser about\n * the existence of the \"message\" variable\n */\n parser.stack.defineScope()\n parser.stack.defineVariable('message')\n\n /**\n * Process component children using the parser\n */\n token.children.forEach((child) => {\n parser.processToken(child, buffer)\n })\n\n /**\n * Clear the scope of the local variables before we\n * close the if statement\n */\n parser.stack.clearScope()\n\n /**\n * Close if statement\n */\n buffer.writeStatement(`}`, token.filename, token.loc.start.line)\n },\n })\n\n edge.registerTag({\n tagName: '
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/edge.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 type { PluginFn } from 'edge.js/types'\nimport debug from '../debug.js'\n\n/**\n * The edge plugin for AdonisJS Session adds tags to read\n * flash messages\n */\nexport const edgePluginSession: PluginFn<undefined> = (edge) => {\n debug('registering session tags with edge')\n\n edge.registerTag({\n tagName: 'flashMessage',\n seekable: true,\n block: true,\n compile(parser, buffer, token) {\n const expression = parser.utils.transformAst(\n parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),\n token.filename,\n parser\n )\n\n const key = parser.utils.stringify(expression)\n\n /**\n * Write an if statement\n */\n buffer.writeStatement(\n `if (state.flashMessages.has(${key})) {`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Define a local variable\n */\n buffer.writeExpression(\n `let $message = state.flashMessages.get(${key})`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Create a local variables scope and tell the parser about\n * the existence of the \"message\" variable\n */\n parser.stack.defineScope()\n parser.stack.defineVariable('$message')\n\n /**\n * Process component children using the parser\n */\n token.children.forEach((child) => {\n parser.processToken(child, buffer)\n })\n\n /**\n * Clear the scope of the local variables before we\n * close the if statement\n */\n parser.stack.clearScope()\n\n /**\n * Close if statement\n */\n buffer.writeStatement(`}`, token.filename, token.loc.start.line)\n },\n })\n\n edge.registerTag({\n tagName: 'inputError',\n seekable: true,\n block: true,\n compile(parser, buffer, token) {\n const expression = parser.utils.transformAst(\n parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),\n token.filename,\n parser\n )\n\n const key = parser.utils.stringify(expression)\n\n /**\n * Write an if statement\n */\n buffer.writeStatement(\n `if (!!state.flashMessages.get('inputErrorsBag', {})[${key}]) {`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Define a local variable\n */\n buffer.writeExpression(\n `let $messages = state.flashMessages.get('inputErrorsBag', {})[${key}]`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Create a local variables scope and tell the parser about\n * the existence of the \"messages\" variable\n */\n parser.stack.defineScope()\n parser.stack.defineVariable('$messages')\n\n /**\n * Process component children using the parser\n */\n token.children.forEach((child) => {\n parser.processToken(child, buffer)\n })\n\n /**\n * Clear the scope of the local variables before we\n * close the if statement\n */\n parser.stack.clearScope()\n\n /**\n * Close if statement\n */\n buffer.writeStatement(`}`, token.filename, token.loc.start.line)\n },\n })\n\n edge.registerTag({\n tagName: 'error',\n seekable: true,\n block: true,\n compile(parser, buffer, token) {\n const expression = parser.utils.transformAst(\n parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),\n token.filename,\n parser\n )\n\n const key = parser.utils.stringify(expression)\n\n /**\n * Write an if statement\n */\n buffer.writeStatement(\n `if (state.flashMessages.has(['errorsBag', ${key}])) {`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Define a local variable\n */\n buffer.writeExpression(\n `let $message = state.flashMessages.get(['errorsBag', ${key}])`,\n token.filename,\n token.loc.start.line\n )\n\n /**\n * Create a local variables scope and tell the parser about\n * the existence of the \"messages\" variable\n */\n parser.stack.defineScope()\n parser.stack.defineVariable('$message')\n\n /**\n * Process component children using the parser\n */\n token.children.forEach((child) => {\n parser.processToken(child, buffer)\n })\n\n /**\n * Clear the scope of the local variables before we\n * close the if statement\n */\n parser.stack.clearScope()\n\n /**\n * Close if statement\n */\n buffer.writeStatement(`}`, token.filename, token.loc.start.line)\n },\n })\n}\n"],"mappings":";;;;;AAgBO,IAAM,oBAAyC,CAAC,SAAS;AAC9D,gBAAM,oCAAoC;AAE1C,OAAK,YAAY;AAAA,IACf,SAAS;AAAA,IACT,UAAU;AAAA,IACV,OAAO;AAAA,IACP,QAAQ,QAAQ,QAAQ,OAAO;AAC7B,YAAM,aAAa,OAAO,MAAM;AAAA,QAC9B,OAAO,MAAM,YAAY,MAAM,WAAW,OAAO,MAAM,KAAK,MAAM,QAAQ;AAAA,QAC1E,MAAM;AAAA,QACN;AAAA,MACF;AAEA,YAAM,MAAM,OAAO,MAAM,UAAU,UAAU;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A,IACT,UAAU;AAAA,IACV,OAAO;AAAA,IACP,QAAQ,QAAQ,QAAQ,OAAO;AAC7B,YAAM,aAAa,OAAO,MAAM;AAAA,QAC9B,OAAO,MAAM,YAAY,MAAM,WAAW,OAAO,MAAM,KAAK,MAAM,QAAQ;AAAA,QAC1E,MAAM;AAAA,QACN;AAAA,MACF;AAEA,YAAM,MAAM,OAAO,MAAM,UAAU,UAAU;AAK7C,aAAO;AAAA,QACL,6CAA6C,GAAG;AAAA,QAChD,MAAM;AAAA,QACN,MAAM,IAAI,MAAM;AAAA,MAClB;AAKA,aAAO;AAAA,QACL,wDAAwD,GAAG;AAAA,QAC3D,MAAM;AAAA,QACN,MAAM,IAAI,MAAM;AAAA,MAClB;AAMA,aAAO,MAAM,YAAY;AACzB,aAAO,MAAM,eAAe,UAAU;AAKtC,YAAM,SAAS,QAAQ,CAAC,UAAU;AAChC,eAAO,aAAa,OAAO,MAAM;AAAA,MACnC,CAAC;AAMD,aAAO,MAAM,WAAW;AAKxB,aAAO,eAAe,KAAK,MAAM,UAAU,MAAM,IAAI,MAAM,IAAI;AAAA,IACjE;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/build/src/session.d.ts
CHANGED
|
@@ -111,16 +111,25 @@ export declare class Session {
|
|
|
111
111
|
* Empty the session store
|
|
112
112
|
*/
|
|
113
113
|
clear(): void;
|
|
114
|
-
/**
|
|
115
|
-
* Flash validation error messages. Make sure the error
|
|
116
|
-
* is an instance of VineJS ValidationException
|
|
117
|
-
*/
|
|
118
|
-
flashValidationErrors(error: HttpError): void;
|
|
119
114
|
/**
|
|
120
115
|
* Add a key-value pair to flash messages
|
|
121
116
|
*/
|
|
122
117
|
flash(key: string, value: AllowedSessionValues): void;
|
|
123
118
|
flash(keyValue: SessionData): void;
|
|
119
|
+
/**
|
|
120
|
+
* Flash errors to the errorsBag. You can read these
|
|
121
|
+
* errors via the "@error" tag.
|
|
122
|
+
*
|
|
123
|
+
* Appends new messages to the existing collection.
|
|
124
|
+
*/
|
|
125
|
+
flashErrors(errorsCollection: Record<string, string | string[]>): void;
|
|
126
|
+
/**
|
|
127
|
+
* Flash validation error messages. Make sure the error
|
|
128
|
+
* is an instance of VineJS ValidationException.
|
|
129
|
+
*
|
|
130
|
+
* Overrides existing inputErrors
|
|
131
|
+
*/
|
|
132
|
+
flashValidationErrors(error: HttpError): void;
|
|
124
133
|
/**
|
|
125
134
|
* Flash form input data to the flash messages store
|
|
126
135
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SessionMiddleware
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-K4OSGJVW.js";
|
|
4
4
|
import "../chunk-2X5L327N.js";
|
|
5
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-TE5JP3SX.js";
|
|
6
6
|
import "../chunk-WBAYBMJJ.js";
|
|
7
7
|
export {
|
|
8
8
|
SessionMiddleware as default
|
|
@@ -15,12 +15,12 @@ export declare class ReadOnlyValuesStore {
|
|
|
15
15
|
/**
|
|
16
16
|
* Get value for a given key
|
|
17
17
|
*/
|
|
18
|
-
get(key: string, defaultValue?: any): any;
|
|
18
|
+
get(key: string | string[], defaultValue?: any): any;
|
|
19
19
|
/**
|
|
20
20
|
* A boolean to know if value exists. Extra guards to check
|
|
21
21
|
* arrays for it's length as well.
|
|
22
22
|
*/
|
|
23
|
-
has(key: string, checkForArraysLength?: boolean): boolean;
|
|
23
|
+
has(key: string | string[], checkForArraysLength?: boolean): boolean;
|
|
24
24
|
/**
|
|
25
25
|
* Get all values
|
|
26
26
|
*/
|
|
@@ -52,26 +52,26 @@ export declare class ValuesStore extends ReadOnlyValuesStore {
|
|
|
52
52
|
/**
|
|
53
53
|
* Set key/value pair
|
|
54
54
|
*/
|
|
55
|
-
set(key: string, value: AllowedSessionValues): void;
|
|
55
|
+
set(key: string | string[], value: AllowedSessionValues): void;
|
|
56
56
|
/**
|
|
57
57
|
* Remove key
|
|
58
58
|
*/
|
|
59
|
-
unset(key: string): void;
|
|
59
|
+
unset(key: string | string[]): void;
|
|
60
60
|
/**
|
|
61
61
|
* Pull value from the store. It is same as calling
|
|
62
62
|
* store.get and then store.unset
|
|
63
63
|
*/
|
|
64
|
-
pull(key: string, defaultValue?: any): any;
|
|
64
|
+
pull(key: string | string[], defaultValue?: any): any;
|
|
65
65
|
/**
|
|
66
66
|
* Increment number. The method raises an error when
|
|
67
67
|
* nderlying value is not a number
|
|
68
68
|
*/
|
|
69
|
-
increment(key: string, steps?: number): void;
|
|
69
|
+
increment(key: string | string[], steps?: number): void;
|
|
70
70
|
/**
|
|
71
71
|
* Increment number. The method raises an error when
|
|
72
72
|
* nderlying value is not a number
|
|
73
73
|
*/
|
|
74
|
-
decrement(key: string, steps?: number): void;
|
|
74
|
+
decrement(key: string | string[], steps?: number): void;
|
|
75
75
|
/**
|
|
76
76
|
* Overwrite existing store data with new values.
|
|
77
77
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/session",
|
|
3
3
|
"description": "Session provider for AdonisJS",
|
|
4
|
-
"version": "7.0.0-
|
|
4
|
+
"version": "7.0.0-15",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18.16.0"
|
|
7
7
|
},
|
|
@@ -43,50 +43,50 @@
|
|
|
43
43
|
"quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@adonisjs/assembler": "^
|
|
47
|
-
"@adonisjs/core": "^6.1.5-
|
|
48
|
-
"@adonisjs/eslint-config": "^1.
|
|
49
|
-
"@adonisjs/prettier-config": "^1.
|
|
50
|
-
"@adonisjs/redis": "^8.0.0-
|
|
51
|
-
"@adonisjs/tsconfig": "^1.
|
|
52
|
-
"@japa/api-client": "^2.0.
|
|
53
|
-
"@japa/assert": "^2.0
|
|
54
|
-
"@japa/browser-client": "^2.0.
|
|
55
|
-
"@japa/file-system": "^2.
|
|
46
|
+
"@adonisjs/assembler": "^7.0.0-1",
|
|
47
|
+
"@adonisjs/core": "^6.1.5-36",
|
|
48
|
+
"@adonisjs/eslint-config": "^1.2.0",
|
|
49
|
+
"@adonisjs/prettier-config": "^1.2.0",
|
|
50
|
+
"@adonisjs/redis": "^8.0.0-14",
|
|
51
|
+
"@adonisjs/tsconfig": "^1.2.0",
|
|
52
|
+
"@japa/api-client": "^2.0.2",
|
|
53
|
+
"@japa/assert": "^2.1.0",
|
|
54
|
+
"@japa/browser-client": "^2.0.2",
|
|
55
|
+
"@japa/file-system": "^2.1.1",
|
|
56
56
|
"@japa/plugin-adonisjs": "^2.0.1",
|
|
57
|
-
"@japa/runner": "^3.1.
|
|
58
|
-
"@japa/snapshot": "^2.0.
|
|
59
|
-
"@swc/core": "^1.3.
|
|
60
|
-
"@types/node": "^20.
|
|
57
|
+
"@japa/runner": "^3.1.1",
|
|
58
|
+
"@japa/snapshot": "^2.0.4",
|
|
59
|
+
"@swc/core": "^1.3.101",
|
|
60
|
+
"@types/node": "^20.10.5",
|
|
61
61
|
"@types/set-cookie-parser": "^2.4.7",
|
|
62
|
-
"@types/supertest": "^
|
|
62
|
+
"@types/supertest": "^6.0.1",
|
|
63
63
|
"@vinejs/vine": "^1.7.0",
|
|
64
64
|
"c8": "^8.0.0",
|
|
65
65
|
"copyfiles": "^2.4.1",
|
|
66
66
|
"cross-env": "^7.0.3",
|
|
67
67
|
"del-cli": "^5.0.0",
|
|
68
68
|
"edge.js": "^6.0.0",
|
|
69
|
-
"eslint": "^8.
|
|
69
|
+
"eslint": "^8.56.0",
|
|
70
70
|
"get-port": "^7.0.0",
|
|
71
71
|
"github-label-sync": "^2.3.1",
|
|
72
72
|
"husky": "^8.0.3",
|
|
73
|
-
"np": "^
|
|
74
|
-
"playwright": "^1.40.
|
|
75
|
-
"prettier": "^3.1.
|
|
73
|
+
"np": "^9.2.0",
|
|
74
|
+
"playwright": "^1.40.1",
|
|
75
|
+
"prettier": "^3.1.1",
|
|
76
76
|
"set-cookie-parser": "^2.6.0",
|
|
77
77
|
"supertest": "^6.3.3",
|
|
78
|
-
"ts-node": "^10.9.
|
|
78
|
+
"ts-node": "^10.9.2",
|
|
79
79
|
"tsup": "^8.0.1",
|
|
80
|
-
"typescript": "5.
|
|
80
|
+
"typescript": "^5.3.3"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@poppinss/utils": "^6.
|
|
83
|
+
"@poppinss/utils": "^6.7.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
|
-
"@adonisjs/core": "^6.1.5-
|
|
87
|
-
"@adonisjs/redis": "^8.0.0-
|
|
88
|
-
"@japa/api-client": "^2.0.
|
|
89
|
-
"@japa/browser-client": "^2.0.
|
|
86
|
+
"@adonisjs/core": "^6.1.5-36",
|
|
87
|
+
"@adonisjs/redis": "^8.0.0-14",
|
|
88
|
+
"@japa/api-client": "^2.0.2",
|
|
89
|
+
"@japa/browser-client": "^2.0.2",
|
|
90
90
|
"edge.js": "^6.0.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependenciesMeta": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/session_middleware.ts","../src/session.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","/*\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 lodash from '@poppinss/utils/lodash'\nimport { cuid } from '@adonisjs/core/helpers'\nimport type { HttpContext } from '@adonisjs/core/http'\nimport type { EmitterService } from '@adonisjs/core/types'\nimport type { HttpError } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport * as errors from './errors.js'\nimport { ReadOnlyValuesStore, ValuesStore } from './values_store.js'\nimport type {\n SessionData,\n SessionConfig,\n SessionStoreFactory,\n AllowedSessionValues,\n SessionStoreContract,\n} from './types.js'\n\n/**\n * The session class exposes the API to read and write values to\n * the session store.\n *\n * A session instance is isolated between requests but\n * uses a centralized persistence store and\n */\nexport class Session {\n #config: SessionConfig\n #store: SessionStoreContract\n #emitter: EmitterService\n #ctx: HttpContext\n #readonly: boolean = false\n\n /**\n * Session values store\n */\n #valuesStore?: ValuesStore\n\n /**\n * Session id refers to the session id that will be committed\n * as a cookie during the response.\n */\n #sessionId: string\n\n /**\n * Session id from cookie refers to the value we read from the\n * cookie during the HTTP request.\n *\n * This only might not exist during the first request. Also during\n * session id re-generation, this value will be different from\n * the session id.\n */\n #sessionIdFromCookie?: string\n\n /**\n * Store of flash messages that be written during the\n * HTTP request\n */\n responseFlashMessages = new ValuesStore({})\n\n /**\n * Store of flash messages for the current HTTP request.\n */\n flashMessages = new ValuesStore({})\n\n /**\n * The key to use for storing flash messages inside\n * the session store.\n */\n flashKey: string = '__flash__'\n\n /**\n * Session id for the current HTTP request\n */\n get sessionId() {\n return this.#sessionId\n }\n\n /**\n * A boolean to know if a fresh session is created during\n * the request\n */\n get fresh(): boolean {\n return this.#sessionIdFromCookie === undefined\n }\n\n /**\n * A boolean to know if session is in readonly\n * state\n */\n get readonly() {\n return this.#readonly\n }\n\n /**\n * A boolean to know if session store has been initiated\n */\n get initiated() {\n return !!this.#valuesStore\n }\n\n /**\n * A boolean to know if the session id has been re-generated\n * during the current request\n */\n get hasRegeneratedSession() {\n return !!(this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId)\n }\n\n /**\n * A boolean to know if the session store is empty\n */\n get isEmpty() {\n return this.#valuesStore?.isEmpty ?? true\n }\n\n /**\n * A boolean to know if the session store has been\n * modified\n */\n get hasBeenModified() {\n return this.#valuesStore?.hasBeenModified ?? false\n }\n\n constructor(\n config: SessionConfig,\n storeFactory: SessionStoreFactory,\n emitter: EmitterService,\n ctx: HttpContext\n ) {\n this.#ctx = ctx\n this.#config = config\n this.#emitter = emitter\n this.#store = storeFactory(ctx, config)\n this.#sessionIdFromCookie = ctx.request.cookie(config.cookieName, undefined)\n this.#sessionId = this.#sessionIdFromCookie || cuid()\n }\n\n /**\n * Returns the flash messages store for a given\n * mode\n */\n #getFlashStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.responseFlashMessages\n }\n\n /**\n * Returns the store instance for a given mode\n */\n #getValuesStore(mode: 'write' | 'read'): ValuesStore {\n if (!this.#valuesStore) {\n throw new errors.E_SESSION_NOT_READY()\n }\n\n if (mode === 'write' && this.readonly) {\n throw new errors.E_SESSION_NOT_MUTABLE()\n }\n\n return this.#valuesStore\n }\n\n /**\n * Initiates the session store. The method results in a noop\n * when called multiple times\n */\n async initiate(readonly: boolean): Promise<void> {\n if (this.#valuesStore) {\n return\n }\n\n debug('initiating session (readonly: %s)', readonly)\n\n this.#readonly = readonly\n const contents = await this.#store.read(this.#sessionId)\n this.#valuesStore = new ValuesStore(contents)\n\n /**\n * Extract flash messages from the store and keep a local\n * copy of it.\n */\n if (this.has(this.flashKey)) {\n debug('reading flash data')\n if (this.#readonly) {\n this.flashMessages.update(this.get(this.flashKey, null))\n } else {\n this.flashMessages.update(this.pull(this.flashKey, null))\n }\n }\n\n /**\n * Share session with the templates. We assume the view property\n * is a reference to edge templates\n */\n if ('view' in this.#ctx) {\n this.#ctx.view.share({\n session: new ReadOnlyValuesStore(this.#valuesStore.all()),\n flashMessages: new ReadOnlyValuesStore(this.flashMessages.all()),\n old: function (key: string, defaultValue?: any) {\n return this.flashMessages.get(key, defaultValue)\n },\n })\n }\n\n this.#emitter.emit('session:initiated', { session: this })\n }\n\n /**\n * Put a key-value pair to the session data store\n */\n put(key: string, value: AllowedSessionValues) {\n this.#getValuesStore('write').set(key, value)\n }\n\n /**\n * Check if a key exists inside the datastore\n */\n has(key: string): boolean {\n return this.#getValuesStore('read').has(key)\n }\n\n /**\n * Get the value of a key from the session datastore.\n * You can specify a default value to use, when key\n * does not exists or has undefined value.\n */\n get(key: string, defaultValue?: any) {\n return this.#getValuesStore('read').get(key, defaultValue)\n }\n\n /**\n * Get everything from the session store\n */\n all() {\n return this.#getValuesStore('read').all()\n }\n\n /**\n * Remove a key from the session datastore\n */\n forget(key: string) {\n return this.#getValuesStore('write').unset(key)\n }\n\n /**\n * Read value for a key from the session datastore\n * and remove it simultaneously.\n */\n pull(key: string, defaultValue?: any) {\n return this.#getValuesStore('write').pull(key, defaultValue)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be 1\n */\n increment(key: string, steps: number = 1) {\n return this.#getValuesStore('write').increment(key, steps)\n }\n\n /**\n * Increment the value of a key inside the session\n * store.\n *\n * A new key will be defined if does not exists already.\n * The value of a new key will be -1\n */\n decrement(key: string, steps: number = 1) {\n return this.#getValuesStore('write').decrement(key, steps)\n }\n\n /**\n * Empty the session store\n */\n clear() {\n return this.#getValuesStore('write').clear()\n }\n\n /**\n * Flash validation error messages. Make sure the error\n * is an instance of VineJS ValidationException\n */\n flashValidationErrors(error: HttpError) {\n const errorsBag = error.messages.reduce((result: Record<string, string[]>, message: any) => {\n if (result[message.field]) {\n result[message.field].push(message.message)\n } else {\n result[message.field] = [message.message]\n }\n return result\n }, {})\n\n this.flashExcept(['_csrf', '_method'])\n this.flash('errors', errorsBag)\n }\n\n /**\n * Add a key-value pair to flash messages\n */\n flash(key: string, value: AllowedSessionValues): void\n flash(keyValue: SessionData): void\n flash(key: string | SessionData, value?: AllowedSessionValues): void {\n if (typeof key === 'string') {\n if (value) {\n this.#getFlashStore('write').set(key, value)\n }\n } else {\n this.#getFlashStore('write').merge(key)\n }\n }\n\n /**\n * Flash form input data to the flash messages store\n */\n flashAll() {\n return this.#getFlashStore('write').set('input', this.#ctx.request.original())\n }\n\n /**\n * Flash form input data (except some keys) to the flash messages store\n */\n flashExcept(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.omit(this.#ctx.request.original(), keys))\n }\n\n /**\n * Flash form input data (only some keys) to the flash messages store\n */\n flashOnly(keys: string[]): void {\n this.#getFlashStore('write').set('input', lodash.pick(this.#ctx.request.original(), keys))\n }\n\n /**\n * Reflash messages from the last request in the current response\n */\n reflash(): void {\n this.#getFlashStore('write').set('reflashed', this.flashMessages.all())\n }\n\n /**\n * Reflash messages (only some keys) from the last\n * request in the current response\n */\n reflashOnly(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.pick(this.flashMessages.all(), keys))\n }\n\n /**\n * Reflash messages (except some keys) from the last\n * request in the current response\n */\n reflashExcept(keys: string[]) {\n this.#getFlashStore('write').set('reflashed', lodash.omit(this.flashMessages.all(), keys))\n }\n\n /**\n * Re-generate the session id and migrate data to it.\n */\n regenerate() {\n this.#sessionId = cuid()\n }\n\n /**\n * Commit session changes. No more mutations will be\n * allowed after commit.\n */\n async commit() {\n if (!this.#valuesStore || this.readonly) {\n return\n }\n\n /**\n * If the flash messages store is not empty, we should put\n * its messages inside main session store.\n */\n if (!this.responseFlashMessages.isEmpty) {\n const { input, reflashed, ...others } = this.responseFlashMessages.all()\n this.put(this.flashKey, { ...reflashed, ...input, ...others })\n }\n\n debug('committing session data')\n\n /**\n * Touch the session id cookie to stay alive\n */\n this.#ctx.response.cookie(this.#config.cookieName, this.#sessionId, this.#config.cookie!)\n\n /**\n * Delete the session data when the session store\n * is empty.\n *\n * Also we only destroy the session id we read from the cookie.\n * If there was no session id in the cookie, there won't be\n * any data inside the store either.\n */\n if (this.isEmpty) {\n if (this.#sessionIdFromCookie) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Touch the store expiry when the session store was\n * not modified.\n */\n if (!this.hasBeenModified) {\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.touch(this.#sessionId)\n }\n this.#emitter.emit('session:committed', { session: this })\n return\n }\n\n /**\n * Otherwise commit to the session store\n */\n if (this.#sessionIdFromCookie && this.#sessionIdFromCookie !== this.#sessionId) {\n await this.#store.destroy(this.#sessionIdFromCookie)\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n this.#emitter.emit('session:migrated', {\n fromSessionId: this.#sessionIdFromCookie,\n toSessionId: this.sessionId,\n session: this,\n })\n } else {\n await this.#store.write(this.#sessionId, this.#valuesStore.toJSON())\n }\n\n this.#emitter.emit('session:committed', { session: this })\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAS,wBAAqC;;;ACF9C,OAAO,YAAY;AACnB,SAAS,YAAY;AAuBd,IAAM,UAAN,MAAc;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAqB;AAAA;AAAA;AAAA;AAAA,EAKrB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,wBAAwB,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAK1C,gBAAgB,IAAI,YAAY,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMlC,WAAmB;AAAA;AAAA;AAAA;AAAA,EAKnB,IAAI,YAAY;AACd,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,QAAiB;AACnB,WAAO,KAAK,yBAAyB;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,WAAW;AACb,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,YAAY;AACd,WAAO,CAAC,CAAC,KAAK;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,wBAAwB;AAC1B,WAAO,CAAC,EAAE,KAAK,wBAAwB,KAAK,yBAAyB,KAAK;AAAA,EAC5E;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,UAAU;AACZ,WAAO,KA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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 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/values_store.ts"],"sourcesContent":["/*\n * @adonisjs/redis\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 lodash from '@poppinss/utils/lodash'\nimport { RuntimeException } from '@poppinss/utils'\nimport type { AllowedSessionValues, SessionData } from './types.js'\n\n/**\n * Readonly session store\n */\nexport class ReadOnlyValuesStore {\n /**\n * Underlying store values\n */\n protected values: SessionData\n\n /**\n * Find if store is empty or not\n */\n get isEmpty() {\n return !this.values || Object.keys(this.values).length === 0\n }\n\n constructor(values: SessionData | null) {\n this.values = values || {}\n }\n\n /**\n * Get value for a given key\n */\n get(key: string, defaultValue?: any): any {\n const value = lodash.get(this.values, key)\n if (defaultValue !== undefined && (value === null || value === undefined)) {\n return defaultValue\n }\n\n return value\n }\n\n /**\n * A boolean to know if value exists. Extra guards to check\n * arrays for it's length as well.\n */\n has(key: string, checkForArraysLength: boolean = true): boolean {\n const value = this.get(key)\n if (!Array.isArray(value)) {\n return !!value\n }\n\n return checkForArraysLength ? value.length > 0 : !!value\n }\n\n /**\n * Get all values\n */\n all(): any {\n return this.values\n }\n\n /**\n * Returns object representation of values\n */\n toObject() {\n return this.all()\n }\n\n /**\n * Returns the store values\n */\n toJSON(): any {\n return this.all()\n }\n\n /**\n * Returns string representation of the store\n */\n toString() {\n return JSON.stringify(this.all())\n }\n}\n\n/**\n * Session store encapsulates the session data and offers a\n * declarative API to mutate it.\n */\nexport class ValuesStore extends ReadOnlyValuesStore {\n /**\n * A boolean to know if store has been\n * modified\n */\n #modified: boolean = false\n\n constructor(values: SessionData | null) {\n super(values)\n }\n\n /**\n * Find if the store has been modified.\n */\n get hasBeenModified(): boolean {\n return this.#modified\n }\n\n /**\n * Set key/value pair\n */\n set(key: string, value: AllowedSessionValues): void {\n this.#modified = true\n lodash.set(this.values, key, value)\n }\n\n /**\n * Remove key\n */\n unset(key: string): void {\n this.#modified = true\n lodash.unset(this.values, key)\n }\n\n /**\n * Pull value from the store. It is same as calling\n * store.get and then store.unset\n */\n pull(key: string, defaultValue?: any): any {\n return ((value): any => {\n this.unset(key)\n return value\n })(this.get(key, defaultValue))\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n increment(key: string, steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot increment \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value + steps)\n }\n\n /**\n * Increment number. The method raises an error when\n * nderlying value is not a number\n */\n decrement(key: string, steps: number = 1): void {\n const value = this.get(key, 0)\n if (typeof value !== 'number') {\n throw new RuntimeException(`Cannot decrement \"${key}\". Existing value is not a number`)\n }\n\n this.set(key, value - steps)\n }\n\n /**\n * Overwrite existing store data with new values.\n */\n update(values: { [key: string]: any }): void {\n this.#modified = true\n this.values = values\n }\n\n /**\n * Update to merge values\n */\n merge(values: { [key: string]: any }): any {\n this.#modified = true\n lodash.merge(this.values, values)\n }\n\n /**\n * Reset store by clearing it's values.\n */\n clear(): void {\n this.update({})\n }\n}\n"],"mappings":";AASA,OAAO,YAAY;AACnB,SAAS,wBAAwB;AAM1B,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA,EAIrB;AAAA;AAAA;AAAA;AAAA,EAKV,IAAI,UAAU;AACZ,WAAO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EAKA,MAAM,KAAmB;AACvB,SAAK,YAAY;AACjB,WAAO,MAAM,KAAK,QAAQ,GAAG;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,KAAa,cAAyB;AACzC,YAAQ,CAAC,UAAe;AACtB,WAAK,MAAM,GAAG;AACd,aAAO;AAAA,IACT,GAAG,KAAK,IAAI,KAAK,YAAY,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,KAAa,QAAgB,GAAS;AAC9C,UAAM,QAAQ,KAAK,IAAI,KAAK,CAAC;AAC7B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,iBAAiB,qBAAqB,GAAG,mCAAmC;AAAA,IACxF;AAEA,SAAK,IAAI,KAAK,QAAQ,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAU,KAAa,QAAgB,GAAS;AAC9C,UAAM,QAAQ,KAAK,IAAI,KAAK,CAAC;AAC7B,QAAI,OAAO,UAAU,UAAU;AAC7B,YAAM,IAAI,iBAAiB,qBAAqB,GAAG,mCAAmC;AAAA,IACxF;AAEA,SAAK,IAAI,KAAK,QAAQ,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,QAAsC;AAC3C,SAAK,YAAY;AACjB,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAqC;AACzC,SAAK,YAAY;AACjB,WAAO,MAAM,KAAK,QAAQ,MAAM;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,OAAO,CAAC,CAAC;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../configure.ts","../stubs/main.ts","../src/define_config.ts","../src/stores/memory.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 type Configure from '@adonisjs/core/commands/configure'\n\n/**\n * Configures the package\n */\nexport async function configure(command: Configure) {\n /**\n * Publish config file\n */\n await command.publishStub('config.stub')\n\n const codemods = await command.createCodemods()\n\n /**\n * Define environment variables\n */\n await codemods.defineEnvVariables({ SESSION_DRIVER: 'cookie' })\n\n /**\n * Define environment variables validations\n */\n await codemods.defineEnvValidations({\n variables: {\n SESSION_DRIVER: `Env.schema.enum(['cookie', 'memory'] as const)`,\n },\n leadingComment: 'Variables for configuring session package',\n })\n\n /**\n * Register middleware\n */\n await codemods.registerMiddleware('router', [\n {\n path: '@adonisjs/session/session_middleware',\n },\n ])\n\n /**\n * Register provider\n */\n await codemods.updateRcFile((rcFile) => {\n rcFile.addProvider('@adonisjs/session/session_provider')\n })\n}\n","/*\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 { getDirname } from '@poppinss/utils'\n\nexport const stubsRoot = getDirname(import.meta.url)\n","/*\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\n/// <reference types=\"@adonisjs/redis/redis_provider\" />\n\nimport string from '@poppinss/utils/string'\nimport { configProvider } from '@adonisjs/core'\nimport type { ConfigProvider } from '@adonisjs/core/types'\nimport { InvalidArgumentsException } from '@poppinss/utils'\nimport type { CookieOptions } from '@adonisjs/core/types/http'\n\nimport debug from './debug.js'\nimport { MemoryStore } from './stores/memory.js'\nimport type {\n SessionConfig,\n FileStoreConfig,\n RedisStoreConfig,\n SessionStoreFactory,\n} from './types.js'\n\n/**\n * Resolved config with stores\n */\ntype ResolvedConfig<KnownStores extends Record<string, SessionStoreFactory>> = SessionConfig & {\n store: keyof KnownStores\n stores: KnownStores\n cookie: Partial<CookieOptions>\n}\n\n/**\n * Helper to normalize session config\n */\nexport function defineConfig<\n KnownStores extends Record<string, SessionStoreFactory | ConfigProvider<SessionStoreFactory>>,\n>(\n config: Partial<SessionConfig> & {\n store: keyof KnownStores | 'memory'\n stores: KnownStores\n }\n): ConfigProvider<\n ResolvedConfig<{\n [K in keyof KnownStores]: SessionStoreFactory\n }>\n> {\n debug('processing session config %O', config)\n\n /**\n * Make sure a store is defined\n */\n if (!config.store) {\n throw new InvalidArgumentsException('Missing \"store\" property inside the session config')\n }\n\n /**\n * Destructuring config with the default values. We pull out\n * stores and cookie values, since we have to transform\n * them in the output value.\n */\n const { stores, cookie, ...rest } = {\n enabled: true,\n age: '2h',\n cookieName: 'adonis_session',\n clearWithBrowser: false,\n ...config,\n }\n\n const cookieOptions: Partial<CookieOptions> = { ...cookie }\n\n /**\n * Define maxAge property when session id cookie is\n * not a session cookie.\n */\n if (!rest.clearWithBrowser) {\n cookieOptions.maxAge = string.seconds.parse(rest.age)\n debug('computing maxAge \"%s\" for session id cookie', cookieOptions.maxAge)\n }\n\n return configProvider.create(async (app) => {\n const storesNames = Object.keys(config.stores)\n\n /**\n * List of stores with memory store always configured\n */\n const storesList = {\n memory: () => new MemoryStore(),\n } as Record<string, SessionStoreFactory>\n\n /**\n * Looping for stores and resolving them\n */\n for (let storeName of storesNames) {\n const store = config.stores[storeName]\n if (typeof store === 'function') {\n storesList[storeName] = store\n } else {\n storesList[storeName] = await store.resolver(app)\n }\n }\n\n const transformedConfig = {\n ...rest,\n cookie: cookieOptions,\n stores: storesList as { [K in keyof KnownStores]: SessionStoreFactory },\n }\n\n debug('transformed session config %O', transformedConfig)\n return transformedConfig\n })\n}\n\n/**\n * Inbuilt stores to store the session data.\n */\nexport const stores: {\n file: (config: FileStoreConfig) => ConfigProvider<SessionStoreFactory>\n redis: (config: RedisStoreConfig) => ConfigProvider<SessionStoreFactory>\n cookie: () => ConfigProvider<SessionStoreFactory>\n} = {\n file: (config) => {\n return configProvider.create(async () => {\n const { FileStore } = await import('./stores/file.js')\n return (_, sessionConfig: SessionConfig) => {\n return new FileStore(config, sessionConfig.age)\n }\n })\n },\n redis: (config) => {\n return configProvider.create(async (app) => {\n const { RedisStore } = await import('./stores/redis.js')\n const redis = await app.container.make('redis')\n\n return (_, sessionConfig: SessionConfig) => {\n return new RedisStore(redis.connection(config.connection), sessionConfig.age)\n }\n })\n },\n cookie: () => {\n return configProvider.create(async () => {\n const { CookieStore } = await import('./stores/cookie.js')\n return (ctx, sessionConfig: SessionConfig) => {\n return new CookieStore(sessionConfig.cookie, ctx)\n }\n })\n },\n}\n","/**\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 type { SessionData, SessionStoreContract } from '../types.js'\n\n/**\n * Memory store is meant to be used for writing tests.\n */\nexport class MemoryStore implements SessionStoreContract {\n static sessions: Map<string, SessionData> = new Map()\n\n /**\n * Read session id value from the memory\n */\n read(sessionId: string): SessionData | null {\n return MemoryStore.sessions.get(sessionId) || null\n }\n\n /**\n * Save in memory value for a given session id\n */\n write(sessionId: string, values: SessionData): void {\n MemoryStore.sessions.set(sessionId, values)\n }\n\n /**\n * Cleanup for a single session\n */\n destroy(sessionId: string): void {\n MemoryStore.sessions.delete(sessionId)\n }\n\n touch(): void {}\n}\n"],"mappings":";;;;;AAcA,eAAsB,UAAU,SAAoB;AAIlD,QAAM,QAAQ,YAAY,aAAa;AAEvC,QAAM,WAAW,MAAM,QAAQ,eAAe;AAK9C,QAAM,SAAS,mBAAmB,EAAE,gBAAgB,SAAS,CAAC;AAK9D,QAAM,SAAS,qBAAqB;AAAA,IAClC,WAAW;AAAA,MACT,gBAAgB;AAAA,IAClB;AAAA,IACA,gBAAgB;AAAA,EAClB,CAAC;AAKD,QAAM,SAAS,mBAAmB,UAAU;AAAA,IAC1C;AAAA,MACE,MAAM;AAAA,IACR;AAAA,EACF,CAAC;AAKD,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,YAAY,oCAAoC;AAAA,EACzD,CAAC;AACH;;;AC3CA,SAAS,kBAAkB;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