@adonisjs/session 7.0.0-13 → 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-2X5L327N.js +28 -0
- package/build/chunk-2X5L327N.js.map +1 -0
- package/build/chunk-HIQQAMXD.js +133 -0
- package/build/chunk-HIQQAMXD.js.map +1 -0
- package/build/chunk-K4OSGJVW.js +402 -0
- package/build/chunk-K4OSGJVW.js.map +1 -0
- package/build/chunk-S6P3TBEK.js +85 -0
- package/build/chunk-S6P3TBEK.js.map +1 -0
- package/build/chunk-TE5JP3SX.js +151 -0
- package/build/chunk-TE5JP3SX.js.map +1 -0
- package/build/chunk-WBAYBMJJ.js +15 -0
- package/build/chunk-WBAYBMJJ.js.map +1 -0
- package/build/{stubs/config.stub → config/session.stub} +3 -1
- package/build/cookie-H7KRZB4T.js +56 -0
- package/build/cookie-H7KRZB4T.js.map +1 -0
- package/build/factories/main.js +50 -9
- package/build/factories/main.js.map +1 -0
- package/build/file-YO7C2QWO.js +112 -0
- package/build/file-YO7C2QWO.js.map +1 -0
- package/build/index.d.ts +0 -1
- package/build/index.js +16 -12
- package/build/index.js.map +1 -0
- package/build/providers/session_provider.js +51 -59
- package/build/providers/session_provider.js.map +1 -0
- package/build/redis-KDWIBKUQ.js +58 -0
- package/build/redis-KDWIBKUQ.js.map +1 -0
- package/build/src/client.js +9 -85
- package/build/src/client.js.map +1 -0
- package/build/src/plugins/edge.js +101 -91
- package/build/src/plugins/edge.js.map +1 -0
- package/build/src/plugins/japa/api_client.js +99 -140
- package/build/src/plugins/japa/api_client.js.map +1 -0
- package/build/src/plugins/japa/browser_client.js +82 -109
- package/build/src/plugins/japa/browser_client.js.map +1 -0
- package/build/src/session.d.ts +14 -5
- package/build/src/session_middleware.js +10 -58
- package/build/src/session_middleware.js.map +1 -0
- package/build/src/values_store.d.ts +7 -7
- package/package.json +60 -43
- package/build/configure.js +0 -45
- package/build/factories/session_middleware_factory.js +0 -48
- package/build/src/debug.js +0 -10
- package/build/src/define_config.js +0 -105
- package/build/src/errors.js +0 -17
- package/build/src/session.js +0 -387
- package/build/src/stores/cookie.js +0 -60
- package/build/src/stores/file.js +0 -133
- package/build/src/stores/memory.js +0 -33
- package/build/src/stores/redis.js +0 -66
- package/build/src/types.js +0 -9
- package/build/src/values_store.js +0 -159
- package/build/stubs/main.js +0 -10
|
@@ -1,60 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { configProvider } from
|
|
10
|
-
import { RuntimeException } from
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import {
|
|
2
|
+
SessionMiddleware
|
|
3
|
+
} from "../chunk-K4OSGJVW.js";
|
|
4
|
+
import "../chunk-2X5L327N.js";
|
|
5
|
+
import "../chunk-TE5JP3SX.js";
|
|
6
|
+
import "../chunk-WBAYBMJJ.js";
|
|
7
|
+
|
|
8
|
+
// providers/session_provider.ts
|
|
9
|
+
import { configProvider } from "@adonisjs/core";
|
|
10
|
+
import { RuntimeException } from "@poppinss/utils";
|
|
11
|
+
var SessionProvider = class {
|
|
12
|
+
constructor(app) {
|
|
13
|
+
this.app = app;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Registers edge plugin when edge is installed
|
|
17
|
+
* in the user application.
|
|
18
|
+
*/
|
|
19
|
+
async registerEdgePlugin() {
|
|
20
|
+
if (this.app.usingEdgeJS) {
|
|
21
|
+
const edge = await import("edge.js");
|
|
22
|
+
const { edgePluginSession } = await import("../src/plugins/edge.js");
|
|
23
|
+
edge.default.use(edgePluginSession);
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
const emitter = await resolver.make('emitter');
|
|
51
|
-
return new SessionMiddleware(config, emitter);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Adding edge tags (if edge is installed)
|
|
56
|
-
*/
|
|
57
|
-
async boot() {
|
|
58
|
-
await this.registerEdgePlugin();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Registering muddleware
|
|
28
|
+
*/
|
|
29
|
+
register() {
|
|
30
|
+
this.app.container.singleton(SessionMiddleware, async (resolver) => {
|
|
31
|
+
const sessionConfigProvider = this.app.config.get("session", {});
|
|
32
|
+
const config = await configProvider.resolve(this.app, sessionConfigProvider);
|
|
33
|
+
if (!config) {
|
|
34
|
+
throw new RuntimeException(
|
|
35
|
+
'Invalid "config/session.ts" file. Make sure you are using the "defineConfig" method'
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const emitter = await resolver.make("emitter");
|
|
39
|
+
return new SessionMiddleware(config, emitter);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adding edge tags (if edge is installed)
|
|
44
|
+
*/
|
|
45
|
+
async boot() {
|
|
46
|
+
await this.registerEdgePlugin();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
SessionProvider as default
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=session_provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../providers/session_provider.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 { configProvider } from '@adonisjs/core'\nimport { RuntimeException } from '@poppinss/utils'\nimport type { ApplicationService } from '@adonisjs/core/types'\n\nimport type { Session } from '../src/session.js'\nimport SessionMiddleware from '../src/session_middleware.js'\n\n/**\n * Events emitted by the session class\n */\ndeclare module '@adonisjs/core/types' {\n interface EventsList {\n 'session:initiated': { session: Session }\n 'session:committed': { session: Session }\n 'session:migrated': { fromSessionId: string; toSessionId: string; session: Session }\n }\n}\n\n/**\n * Session provider configures the session management inside an\n * AdonisJS application\n */\nexport default class SessionProvider {\n constructor(protected app: ApplicationService) {}\n\n /**\n * Registers edge plugin when edge is installed\n * in the user application.\n */\n protected async registerEdgePlugin() {\n if (this.app.usingEdgeJS) {\n const edge = await import('edge.js')\n const { edgePluginSession } = await import('../src/plugins/edge.js')\n edge.default.use(edgePluginSession)\n }\n }\n\n /**\n * Registering muddleware\n */\n register() {\n this.app.container.singleton(SessionMiddleware, async (resolver) => {\n const sessionConfigProvider = this.app.config.get('session', {})\n\n /**\n * Resolve config from the provider\n */\n const config = await configProvider.resolve<any>(this.app, sessionConfigProvider)\n if (!config) {\n throw new RuntimeException(\n 'Invalid \"config/session.ts\" file. Make sure you are using the \"defineConfig\" method'\n )\n }\n\n const emitter = await resolver.make('emitter')\n return new SessionMiddleware(config, emitter)\n })\n }\n\n /**\n * Adding edge tags (if edge is installed)\n */\n async boot() {\n await this.registerEdgePlugin()\n }\n}\n"],"mappings":";;;;;;;;AASA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAqBjC,IAAqB,kBAArB,MAAqC;AAAA,EACnC,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAgB,qBAAqB;AACnC,QAAI,KAAK,IAAI,aAAa;AACxB,YAAM,OAAO,MAAM,OAAO,SAAS;AACnC,YAAM,EAAE,kBAAkB,IAAI,MAAM,OAAO,wBAAwB;AACnE,WAAK,QAAQ,IAAI,iBAAiB;AAAA,IACpC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,WAAW;AACT,SAAK,IAAI,UAAU,UAAU,mBAAmB,OAAO,aAAa;AAClE,YAAM,wBAAwB,KAAK,IAAI,OAAO,IAAI,WAAW,CAAC,CAAC;AAK/D,YAAM,SAAS,MAAM,eAAe,QAAa,KAAK,KAAK,qBAAqB;AAChF,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,YAAM,UAAU,MAAM,SAAS,KAAK,SAAS;AAC7C,aAAO,IAAI,kBAAkB,QAAQ,OAAO;AAAA,IAC9C,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO;AACX,UAAM,KAAK,mBAAmB;AAAA,EAChC;AACF;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debug_default
|
|
3
|
+
} from "./chunk-WBAYBMJJ.js";
|
|
4
|
+
|
|
5
|
+
// src/stores/redis.ts
|
|
6
|
+
import string from "@poppinss/utils/string";
|
|
7
|
+
import { MessageBuilder } from "@adonisjs/core/helpers";
|
|
8
|
+
var RedisStore = class {
|
|
9
|
+
#connection;
|
|
10
|
+
#ttlSeconds;
|
|
11
|
+
constructor(connection, age) {
|
|
12
|
+
this.#connection = connection;
|
|
13
|
+
this.#ttlSeconds = string.seconds.parse(age);
|
|
14
|
+
debug_default("initiating redis store");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns file contents. A new file will be created if it's
|
|
18
|
+
* missing.
|
|
19
|
+
*/
|
|
20
|
+
async read(sessionId) {
|
|
21
|
+
debug_default("redis store: reading session data %s", sessionId);
|
|
22
|
+
const contents = await this.#connection.get(sessionId);
|
|
23
|
+
if (!contents) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return new MessageBuilder().verify(contents, sessionId);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Write session values to a file
|
|
34
|
+
*/
|
|
35
|
+
async write(sessionId, values) {
|
|
36
|
+
debug_default("redis store: writing session data %s, %O", sessionId, values);
|
|
37
|
+
const message = new MessageBuilder().build(values, void 0, sessionId);
|
|
38
|
+
await this.#connection.setex(sessionId, this.#ttlSeconds, message);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Cleanup session file by removing it
|
|
42
|
+
*/
|
|
43
|
+
async destroy(sessionId) {
|
|
44
|
+
debug_default("redis store: destroying session data %s", sessionId);
|
|
45
|
+
await this.#connection.del(sessionId);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Updates the value expiry
|
|
49
|
+
*/
|
|
50
|
+
async touch(sessionId) {
|
|
51
|
+
debug_default("redis store: touching session data %s", sessionId);
|
|
52
|
+
await this.#connection.expire(sessionId, this.#ttlSeconds);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
RedisStore
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=redis-KDWIBKUQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/stores/redis.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 string from '@poppinss/utils/string'\nimport { MessageBuilder } from '@adonisjs/core/helpers'\nimport type { Connection } from '@adonisjs/redis/types'\n\nimport debug from '../debug.js'\nimport type { SessionStoreContract, SessionData } from '../types.js'\n\n/**\n * File store to read/write session to filesystem\n */\nexport class RedisStore implements SessionStoreContract {\n #connection: Connection\n #ttlSeconds: number\n\n constructor(connection: Connection, age: string | number) {\n this.#connection = connection\n this.#ttlSeconds = string.seconds.parse(age)\n debug('initiating redis store')\n }\n\n /**\n * Returns file contents. A new file will be created if it's\n * missing.\n */\n async read(sessionId: string): Promise<SessionData | null> {\n debug('redis store: reading session data %s', sessionId)\n\n const contents = await this.#connection.get(sessionId)\n if (!contents) {\n return null\n }\n\n /**\n * Verify contents with the session id and return them as an object. The verify\n * method can fail when the contents is not JSON>\n */\n try {\n return new MessageBuilder().verify<SessionData>(contents, sessionId)\n } catch {\n return null\n }\n }\n\n /**\n * Write session values to a file\n */\n async write(sessionId: string, values: Object): Promise<void> {\n debug('redis store: writing session data %s, %O', sessionId, values)\n\n const message = new MessageBuilder().build(values, undefined, sessionId)\n await this.#connection.setex(sessionId, this.#ttlSeconds, message)\n }\n\n /**\n * Cleanup session file by removing it\n */\n async destroy(sessionId: string): Promise<void> {\n debug('redis store: destroying session data %s', sessionId)\n await this.#connection.del(sessionId)\n }\n\n /**\n * Updates the value expiry\n */\n async touch(sessionId: string): Promise<void> {\n debug('redis store: touching session data %s', sessionId)\n await this.#connection.expire(sessionId, this.#ttlSeconds)\n }\n}\n"],"mappings":";;;;;AASA,OAAO,YAAY;AACnB,SAAS,sBAAsB;AASxB,IAAM,aAAN,MAAiD;AAAA,EACtD;AAAA,EACA;AAAA,EAEA,YAAY,YAAwB,KAAsB;AACxD,SAAK,cAAc;AACnB,SAAK,cAAc,OAAO,QAAQ,MAAM,GAAG;AAC3C,kBAAM,wBAAwB;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,KAAK,WAAgD;AACzD,kBAAM,wCAAwC,SAAS;AAEvD,UAAM,WAAW,MAAM,KAAK,YAAY,IAAI,SAAS;AACrD,QAAI,CAAC,UAAU;AACb,aAAO;AAAA,IACT;AAMA,QAAI;AACF,aAAO,IAAI,eAAe,EAAE,OAAoB,UAAU,SAAS;AAAA,IACrE,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAM,WAAmB,QAA+B;AAC5D,kBAAM,4CAA4C,WAAW,MAAM;AAEnE,UAAM,UAAU,IAAI,eAAe,EAAE,MAAM,QAAQ,QAAW,SAAS;AACvE,UAAM,KAAK,YAAY,MAAM,WAAW,KAAK,aAAa,OAAO;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAQ,WAAkC;AAC9C,kBAAM,2CAA2C,SAAS;AAC1D,UAAM,KAAK,YAAY,IAAI,SAAS;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,MAAM,WAAkC;AAC5C,kBAAM,yCAAyC,SAAS;AACxD,UAAM,KAAK,YAAY,OAAO,WAAW,KAAK,WAAW;AAAA,EAC3D;AACF;","names":[]}
|
package/build/src/client.js
CHANGED
|
@@ -1,85 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import debug from './debug.js';
|
|
11
|
-
import { ValuesStore } from './values_store.js';
|
|
12
|
-
/**
|
|
13
|
-
* Session client exposes the API to set session data as a client
|
|
14
|
-
*/
|
|
15
|
-
export class SessionClient {
|
|
16
|
-
/**
|
|
17
|
-
* Data store
|
|
18
|
-
*/
|
|
19
|
-
#valuesStore = new ValuesStore({});
|
|
20
|
-
/**
|
|
21
|
-
* Flash messages store
|
|
22
|
-
*/
|
|
23
|
-
#flashMessagesStore = new ValuesStore({});
|
|
24
|
-
/**
|
|
25
|
-
* The session store to use for reading and writing session data
|
|
26
|
-
*/
|
|
27
|
-
#store;
|
|
28
|
-
/**
|
|
29
|
-
* Session key for setting flash messages
|
|
30
|
-
*/
|
|
31
|
-
flashKey = '__flash__';
|
|
32
|
-
/**
|
|
33
|
-
* Session to use when no explicit session id is
|
|
34
|
-
* defined
|
|
35
|
-
*/
|
|
36
|
-
sessionId = cuid();
|
|
37
|
-
constructor(store) {
|
|
38
|
-
this.#store = store;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Merge session data
|
|
42
|
-
*/
|
|
43
|
-
merge(values) {
|
|
44
|
-
this.#valuesStore.merge(values);
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Merge flash messages
|
|
49
|
-
*/
|
|
50
|
-
flash(values) {
|
|
51
|
-
this.#flashMessagesStore.merge(values);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Commits data to the session store.
|
|
56
|
-
*/
|
|
57
|
-
async commit() {
|
|
58
|
-
if (!this.#flashMessagesStore.isEmpty) {
|
|
59
|
-
this.#valuesStore.set(this.flashKey, this.#flashMessagesStore.toJSON());
|
|
60
|
-
}
|
|
61
|
-
debug('committing session data during api request');
|
|
62
|
-
if (!this.#valuesStore.isEmpty) {
|
|
63
|
-
this.#store.write(this.sessionId, this.#valuesStore.toJSON());
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Destroys the session data with the store
|
|
68
|
-
*/
|
|
69
|
-
async destroy(sessionId) {
|
|
70
|
-
debug('destroying session data during api request');
|
|
71
|
-
this.#store.destroy(sessionId || this.sessionId);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Loads session data from the session store
|
|
75
|
-
*/
|
|
76
|
-
async load(sessionId) {
|
|
77
|
-
const contents = await this.#store.read(sessionId || this.sessionId);
|
|
78
|
-
const store = new ValuesStore(contents);
|
|
79
|
-
const flashMessages = store.pull(this.flashKey, {});
|
|
80
|
-
return {
|
|
81
|
-
values: store.all(),
|
|
82
|
-
flashMessages,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
SessionClient
|
|
3
|
+
} from "../chunk-S6P3TBEK.js";
|
|
4
|
+
import "../chunk-TE5JP3SX.js";
|
|
5
|
+
import "../chunk-WBAYBMJJ.js";
|
|
6
|
+
export {
|
|
7
|
+
SessionClient
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,92 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
1
|
+
import {
|
|
2
|
+
debug_default
|
|
3
|
+
} from "../../chunk-WBAYBMJJ.js";
|
|
4
|
+
|
|
5
|
+
// src/plugins/edge.ts
|
|
6
|
+
var edgePluginSession = (edge) => {
|
|
7
|
+
debug_default("registering session tags with edge");
|
|
8
|
+
edge.registerTag({
|
|
9
|
+
tagName: "flashMessage",
|
|
10
|
+
seekable: true,
|
|
11
|
+
block: true,
|
|
12
|
+
compile(parser, buffer, token) {
|
|
13
|
+
const expression = parser.utils.transformAst(
|
|
14
|
+
parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),
|
|
15
|
+
token.filename,
|
|
16
|
+
parser
|
|
17
|
+
);
|
|
18
|
+
const key = parser.utils.stringify(expression);
|
|
19
|
+
buffer.writeStatement(
|
|
20
|
+
`if (state.flashMessages.has(${key})) {`,
|
|
21
|
+
token.filename,
|
|
22
|
+
token.loc.start.line
|
|
23
|
+
);
|
|
24
|
+
buffer.writeExpression(
|
|
25
|
+
`let $message = state.flashMessages.get(${key})`,
|
|
26
|
+
token.filename,
|
|
27
|
+
token.loc.start.line
|
|
28
|
+
);
|
|
29
|
+
parser.stack.defineScope();
|
|
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");
|
|
61
|
+
token.children.forEach((child) => {
|
|
62
|
+
parser.processToken(child, buffer);
|
|
63
|
+
});
|
|
64
|
+
parser.stack.clearScope();
|
|
65
|
+
buffer.writeStatement(`}`, token.filename, token.loc.start.line);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
edge.registerTag({
|
|
69
|
+
tagName: "error",
|
|
70
|
+
seekable: true,
|
|
71
|
+
block: true,
|
|
72
|
+
compile(parser, buffer, token) {
|
|
73
|
+
const expression = parser.utils.transformAst(
|
|
74
|
+
parser.utils.generateAST(token.properties.jsArg, token.loc, token.filename),
|
|
75
|
+
token.filename,
|
|
76
|
+
parser
|
|
77
|
+
);
|
|
78
|
+
const key = parser.utils.stringify(expression);
|
|
79
|
+
buffer.writeStatement(
|
|
80
|
+
`if (state.flashMessages.has(['errorsBag', ${key}])) {`,
|
|
81
|
+
token.filename,
|
|
82
|
+
token.loc.start.line
|
|
83
|
+
);
|
|
84
|
+
buffer.writeExpression(
|
|
85
|
+
`let $message = state.flashMessages.get(['errorsBag', ${key}])`,
|
|
86
|
+
token.filename,
|
|
87
|
+
token.loc.start.line
|
|
88
|
+
);
|
|
89
|
+
parser.stack.defineScope();
|
|
90
|
+
parser.stack.defineVariable("$message");
|
|
91
|
+
token.children.forEach((child) => {
|
|
92
|
+
parser.processToken(child, buffer);
|
|
93
|
+
});
|
|
94
|
+
parser.stack.clearScope();
|
|
95
|
+
buffer.writeStatement(`}`, token.filename, token.loc.start.line);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
92
98
|
};
|
|
99
|
+
export {
|
|
100
|
+
edgePluginSession
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=edge.js.map
|
|
@@ -0,0 +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: '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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