@adonisjs/session 8.0.0-next.0 → 8.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/commands.json +1 -0
- package/build/commands/main.d.ts +4 -0
- package/build/commands/main.js +36 -0
- package/build/commands/make_session_table.d.ts +9 -0
- package/build/commands/make_session_table.js +13 -0
- package/build/cookie--JOJxrtW.js +31 -0
- package/build/database-vbrhCOPd.js +86 -0
- package/build/debug-BZVg83L1.js +3 -0
- package/build/dynamodb-BFVgTQSf.js +72 -0
- package/build/factories/main.js +27 -45
- package/build/file-BBU02j4z.js +71 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +7 -25
- package/build/main-kn40V-hF.js +2 -0
- package/build/make/migration/sessions.stub +26 -0
- package/build/providers/session_provider.d.ts +2 -1
- package/build/providers/session_provider.js +34 -48
- package/build/redis-D8D9UtiD.js +91 -0
- package/build/session-C9DdRahS.js +215 -0
- package/build/session-Cb9-DoMh.js +139 -0
- package/build/session_collection-CvS5yIq6.js +31 -0
- package/build/session_middleware-gegOBxmm.js +27 -0
- package/build/src/client.js +38 -7
- package/build/src/debug.d.ts +1 -1
- package/build/src/define_config.d.ts +14 -6
- package/build/src/errors.d.ts +9 -0
- package/build/src/plugins/edge.d.ts +5 -1
- package/build/src/plugins/edge.js +74 -124
- package/build/src/plugins/japa/api_client.js +76 -96
- package/build/src/plugins/japa/browser_client.js +58 -81
- package/build/src/session.d.ts +12 -0
- package/build/src/session_collection.d.ts +81 -0
- package/build/src/session_middleware.js +5 -9
- package/build/src/stores/database.d.ts +70 -0
- package/build/src/stores/memory.d.ts +19 -2
- package/build/src/stores/redis.d.ts +15 -2
- package/build/src/types.d.ts +62 -8
- package/build/src/types.js +1 -0
- package/build/values_store-CvR1Sn37.js +78 -0
- package/package.json +65 -42
- package/build/chunk-DFXWYDMY.js +0 -62
- package/build/chunk-HAD4PFFM.js +0 -229
- package/build/chunk-MVBWJOEG.js +0 -187
- package/build/chunk-SBOMJK4T.js +0 -14
- package/build/chunk-SHD6OX52.js +0 -488
- package/build/chunk-Y566BNUT.js +0 -113
- package/build/cookie-YBBGLCO5.js +0 -88
- package/build/dynamodb-PLZABBFD.js +0 -153
- package/build/file-CCJ5ESE2.js +0 -151
- package/build/redis-NXJWWWVB.js +0 -89
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"commands":[{"commandName":"make:session-table","description":"Create a migration for the sessions database table","help":"","namespace":"make","aliases":[],"flags":[],"args":[],"options":{},"filePath":"make_session_table.js"}],"version":1}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* In-memory cache of commands after they have been loaded
|
|
5
|
+
*/
|
|
6
|
+
let commandsMetaData
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Reads the commands from the "./commands.json" file. Since, the commands.json
|
|
10
|
+
* file is generated automatically, we do not have to validate its contents
|
|
11
|
+
*/
|
|
12
|
+
export async function getMetaData() {
|
|
13
|
+
if (commandsMetaData) {
|
|
14
|
+
return commandsMetaData
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
|
|
18
|
+
commandsMetaData = JSON.parse(commandsIndex).commands
|
|
19
|
+
|
|
20
|
+
return commandsMetaData
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Imports the command by lookingup its path from the commands
|
|
25
|
+
* metadata
|
|
26
|
+
*/
|
|
27
|
+
export async function getCommand(metaData) {
|
|
28
|
+
const commands = await getMetaData()
|
|
29
|
+
const command = commands.find(({ commandName }) => metaData.commandName === commandName)
|
|
30
|
+
if (!command) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
|
|
35
|
+
return commandConstructor
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as stubsRoot } from "../main-kn40V-hF.js";
|
|
2
|
+
import { BaseCommand } from "@adonisjs/core/ace";
|
|
3
|
+
var MakeSessionTable = class extends BaseCommand {
|
|
4
|
+
static commandName = "make:session-table";
|
|
5
|
+
static description = "Create a migration for the sessions database table";
|
|
6
|
+
async run() {
|
|
7
|
+
await (await this.createCodemods()).makeUsingStub(stubsRoot, "make/migration/sessions.stub", { migration: {
|
|
8
|
+
tableName: "sessions",
|
|
9
|
+
prefix: Date.now()
|
|
10
|
+
} });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export { MakeSessionTable as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as debug_default } from "./debug-BZVg83L1.js";
|
|
2
|
+
var CookieStore = class {
|
|
3
|
+
#ctx;
|
|
4
|
+
#config;
|
|
5
|
+
constructor(config, ctx) {
|
|
6
|
+
this.#config = config;
|
|
7
|
+
this.#ctx = ctx;
|
|
8
|
+
debug_default("initiating cookie store %O", this.#config);
|
|
9
|
+
}
|
|
10
|
+
read(sessionId) {
|
|
11
|
+
debug_default("cookie store: reading session data %s", sessionId);
|
|
12
|
+
const cookieValue = this.#ctx.request.encryptedCookie(sessionId);
|
|
13
|
+
if (typeof cookieValue !== "object") return null;
|
|
14
|
+
return cookieValue;
|
|
15
|
+
}
|
|
16
|
+
write(sessionId, values) {
|
|
17
|
+
debug_default("cookie store: writing session data %s: %O", sessionId, values);
|
|
18
|
+
this.#ctx.response.encryptedCookie(sessionId, values, this.#config);
|
|
19
|
+
}
|
|
20
|
+
destroy(sessionId) {
|
|
21
|
+
debug_default("cookie store: destroying session data %s", sessionId);
|
|
22
|
+
if (this.#ctx.request.cookiesList()[sessionId]) this.#ctx.response.clearCookie(sessionId);
|
|
23
|
+
}
|
|
24
|
+
touch(sessionId) {
|
|
25
|
+
const value = this.read(sessionId);
|
|
26
|
+
debug_default("cookie store: touching session data %s", sessionId);
|
|
27
|
+
if (!value) return;
|
|
28
|
+
this.write(sessionId, value);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export { CookieStore };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { t as debug_default } from "./debug-BZVg83L1.js";
|
|
2
|
+
import string from "@poppinss/utils/string";
|
|
3
|
+
import { MessageBuilder } from "@adonisjs/core/helpers";
|
|
4
|
+
var DatabaseStore = class {
|
|
5
|
+
#client;
|
|
6
|
+
#tableName;
|
|
7
|
+
#ttlSeconds;
|
|
8
|
+
#gcProbability;
|
|
9
|
+
constructor(client, age, options) {
|
|
10
|
+
this.#client = client;
|
|
11
|
+
this.#tableName = options?.tableName ?? "sessions";
|
|
12
|
+
this.#ttlSeconds = string.seconds.parse(age);
|
|
13
|
+
this.#gcProbability = options?.gcProbability ?? 2;
|
|
14
|
+
debug_default("initiating database store");
|
|
15
|
+
}
|
|
16
|
+
async #collectGarbage() {
|
|
17
|
+
if (this.#gcProbability <= 0) return;
|
|
18
|
+
if (Math.random() * 100 < this.#gcProbability) {
|
|
19
|
+
debug_default("database store: running garbage collection");
|
|
20
|
+
const expiredBefore = new Date(Date.now());
|
|
21
|
+
await this.#client.from(this.#tableName).where("expires_at", "<=", expiredBefore).delete();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
#parseSessionData(contents, sessionId) {
|
|
25
|
+
try {
|
|
26
|
+
return new MessageBuilder().verify(contents, sessionId);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async read(sessionId) {
|
|
32
|
+
debug_default("database store: reading session data %s", sessionId);
|
|
33
|
+
const row = await this.#client.from(this.#tableName).where("id", sessionId).first();
|
|
34
|
+
if (!row) return null;
|
|
35
|
+
const expiresAt = new Date(row.expires_at).getTime();
|
|
36
|
+
if (Date.now() > expiresAt) {
|
|
37
|
+
await this.destroy(sessionId);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return this.#parseSessionData(row.data, sessionId);
|
|
41
|
+
}
|
|
42
|
+
async write(sessionId, values) {
|
|
43
|
+
debug_default("database store: writing session data %s, %O", sessionId, values);
|
|
44
|
+
const message = new MessageBuilder().build(values, void 0, sessionId);
|
|
45
|
+
const expiresAt = new Date(Date.now() + this.#ttlSeconds * 1e3);
|
|
46
|
+
await this.#client.insertQuery().table(this.#tableName).insert({
|
|
47
|
+
id: sessionId,
|
|
48
|
+
data: message,
|
|
49
|
+
expires_at: expiresAt
|
|
50
|
+
}).knexQuery.onConflict("id").merge(["data", "expires_at"]);
|
|
51
|
+
await this.#collectGarbage();
|
|
52
|
+
}
|
|
53
|
+
async destroy(sessionId) {
|
|
54
|
+
debug_default("database store: destroying session data %s", sessionId);
|
|
55
|
+
await this.#client.from(this.#tableName).where("id", sessionId).delete();
|
|
56
|
+
}
|
|
57
|
+
async touch(sessionId) {
|
|
58
|
+
debug_default("database store: touching session data %s", sessionId);
|
|
59
|
+
const expiresAt = new Date(Date.now() + this.#ttlSeconds * 1e3);
|
|
60
|
+
await this.#client.from(this.#tableName).where("id", sessionId).update({ expires_at: expiresAt });
|
|
61
|
+
}
|
|
62
|
+
async tag(sessionId, userId) {
|
|
63
|
+
debug_default("database store: tagging session %s with user %s", sessionId, userId);
|
|
64
|
+
const data = new MessageBuilder().build({}, void 0, sessionId);
|
|
65
|
+
const expiresAt = new Date(Date.now() + this.#ttlSeconds * 1e3);
|
|
66
|
+
await this.#client.insertQuery().table(this.#tableName).insert({
|
|
67
|
+
id: sessionId,
|
|
68
|
+
user_id: userId,
|
|
69
|
+
data,
|
|
70
|
+
expires_at: expiresAt
|
|
71
|
+
}).knexQuery.onConflict("id").merge(["user_id"]);
|
|
72
|
+
}
|
|
73
|
+
#rowToTaggedSession(row) {
|
|
74
|
+
const data = this.#parseSessionData(row.data, row.id);
|
|
75
|
+
if (!data) return null;
|
|
76
|
+
return {
|
|
77
|
+
id: row.id,
|
|
78
|
+
data
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async tagged(userId) {
|
|
82
|
+
debug_default("database store: getting sessions tagged with user %s", userId);
|
|
83
|
+
return (await this.#client.from(this.#tableName).select("id", "data").where("user_id", userId).where("expires_at", ">", /* @__PURE__ */ new Date())).map((row) => this.#rowToTaggedSession(row)).filter((session) => session !== null);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
export { DatabaseStore };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { t as debug_default } from "./debug-BZVg83L1.js";
|
|
2
|
+
import string from "@adonisjs/core/helpers/string";
|
|
3
|
+
import { MessageBuilder } from "@adonisjs/core/helpers";
|
|
4
|
+
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
|
|
5
|
+
import { DeleteItemCommand, GetItemCommand, PutItemCommand, UpdateItemCommand } from "@aws-sdk/client-dynamodb";
|
|
6
|
+
var DynamoDBStore = class {
|
|
7
|
+
#client;
|
|
8
|
+
#tableName;
|
|
9
|
+
#keyAttribute;
|
|
10
|
+
#ttlSeconds;
|
|
11
|
+
#valueAttribute = "value";
|
|
12
|
+
#expiresAtAttribute = "expires_at";
|
|
13
|
+
constructor(client, age, options) {
|
|
14
|
+
this.#client = client;
|
|
15
|
+
this.#tableName = options?.tableName ?? "Session";
|
|
16
|
+
this.#keyAttribute = options?.keyAttribute ?? "key";
|
|
17
|
+
this.#ttlSeconds = string.seconds.parse(age);
|
|
18
|
+
debug_default("initiating dynamodb store");
|
|
19
|
+
}
|
|
20
|
+
async read(sessionId) {
|
|
21
|
+
debug_default("dynamodb store: reading session data %s", sessionId);
|
|
22
|
+
const command = new GetItemCommand({
|
|
23
|
+
TableName: this.#tableName,
|
|
24
|
+
Key: marshall({ [this.#keyAttribute]: sessionId })
|
|
25
|
+
});
|
|
26
|
+
const response = await this.#client.send(command);
|
|
27
|
+
if (!response.Item) return null;
|
|
28
|
+
if (!response.Item[this.#valueAttribute]) return null;
|
|
29
|
+
const item = unmarshall(response.Item);
|
|
30
|
+
const contents = item[this.#valueAttribute];
|
|
31
|
+
const expiresAt = item[this.#expiresAtAttribute];
|
|
32
|
+
if (Date.now() > expiresAt) return null;
|
|
33
|
+
try {
|
|
34
|
+
return new MessageBuilder().verify(contents, sessionId);
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async write(sessionId, values) {
|
|
40
|
+
debug_default("dynamodb store: writing session data %s, %O", sessionId, values);
|
|
41
|
+
const message = new MessageBuilder().build(values, void 0, sessionId);
|
|
42
|
+
const command = new PutItemCommand({
|
|
43
|
+
TableName: this.#tableName,
|
|
44
|
+
Item: marshall({
|
|
45
|
+
[this.#keyAttribute]: sessionId,
|
|
46
|
+
[this.#valueAttribute]: message,
|
|
47
|
+
[this.#expiresAtAttribute]: Date.now() + this.#ttlSeconds * 1e3
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
await this.#client.send(command);
|
|
51
|
+
}
|
|
52
|
+
async destroy(sessionId) {
|
|
53
|
+
debug_default("dynamodb store: destroying session data %s", sessionId);
|
|
54
|
+
const command = new DeleteItemCommand({
|
|
55
|
+
TableName: this.#tableName,
|
|
56
|
+
Key: marshall({ [this.#keyAttribute]: sessionId })
|
|
57
|
+
});
|
|
58
|
+
await this.#client.send(command);
|
|
59
|
+
}
|
|
60
|
+
async touch(sessionId) {
|
|
61
|
+
debug_default("dynamodb store: touching session data %s", sessionId);
|
|
62
|
+
const command = new UpdateItemCommand({
|
|
63
|
+
TableName: this.#tableName,
|
|
64
|
+
Key: marshall({ [this.#keyAttribute]: sessionId }),
|
|
65
|
+
UpdateExpression: "SET #expires_at = :expires_at",
|
|
66
|
+
ExpressionAttributeNames: { "#expires_at": this.#expiresAtAttribute },
|
|
67
|
+
ExpressionAttributeValues: marshall({ ":expires_at": Date.now() + this.#ttlSeconds * 1e3 })
|
|
68
|
+
});
|
|
69
|
+
await this.#client.send(command);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
export { DynamoDBStore };
|
package/build/factories/main.js
CHANGED
|
@@ -1,49 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
} from "../
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import "../
|
|
8
|
-
import "../chunk-HAD4PFFM.js";
|
|
9
|
-
import "../chunk-SBOMJK4T.js";
|
|
10
|
-
|
|
11
|
-
// factories/session_middleware_factory.ts
|
|
1
|
+
import "../session-C9DdRahS.js";
|
|
2
|
+
import "../main-kn40V-hF.js";
|
|
3
|
+
import { t as defineConfig } from "../session-Cb9-DoMh.js";
|
|
4
|
+
import "../debug-BZVg83L1.js";
|
|
5
|
+
import "../values_store-CvR1Sn37.js";
|
|
6
|
+
import "../session_collection-CvS5yIq6.js";
|
|
7
|
+
import { t as SessionMiddleware } from "../session_middleware-gegOBxmm.js";
|
|
12
8
|
import { Emitter } from "@adonisjs/core/events";
|
|
13
9
|
import { AppFactory } from "@adonisjs/core/factories/app";
|
|
14
10
|
var SessionMiddlewareFactory = class {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (options.emitter) {
|
|
35
|
-
this.#emitter = options.emitter;
|
|
36
|
-
}
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Creates an instance of the session middleware
|
|
41
|
-
*/
|
|
42
|
-
async create() {
|
|
43
|
-
const config = await defineConfig(this.#config).resolver(this.#getApp());
|
|
44
|
-
return new SessionMiddleware(config, this.#getEmitter());
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
export {
|
|
48
|
-
SessionMiddlewareFactory
|
|
11
|
+
#config = {
|
|
12
|
+
store: "memory",
|
|
13
|
+
stores: {}
|
|
14
|
+
};
|
|
15
|
+
#emitter;
|
|
16
|
+
#getApp() {
|
|
17
|
+
return new AppFactory().create(new URL("./", import.meta.url), () => {});
|
|
18
|
+
}
|
|
19
|
+
#getEmitter() {
|
|
20
|
+
return this.#emitter || new Emitter(this.#getApp());
|
|
21
|
+
}
|
|
22
|
+
merge(options) {
|
|
23
|
+
if (options.config) this.#config = options.config;
|
|
24
|
+
if (options.emitter) this.#emitter = options.emitter;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
async create() {
|
|
28
|
+
return new SessionMiddleware(await defineConfig(this.#config).resolver(this.#getApp()), this.#getEmitter());
|
|
29
|
+
}
|
|
49
30
|
};
|
|
31
|
+
export { SessionMiddlewareFactory };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as debug_default } from "./debug-BZVg83L1.js";
|
|
2
|
+
import string from "@adonisjs/core/helpers/string";
|
|
3
|
+
import { MessageBuilder } from "@adonisjs/core/helpers";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { access, mkdir, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
|
|
6
|
+
var FileStore = class {
|
|
7
|
+
#config;
|
|
8
|
+
#age;
|
|
9
|
+
constructor(config, age) {
|
|
10
|
+
this.#config = config;
|
|
11
|
+
this.#age = age;
|
|
12
|
+
debug_default("initiating file store %O", this.#config);
|
|
13
|
+
}
|
|
14
|
+
#getFilePath(sessionId) {
|
|
15
|
+
return join(this.#config.location, `${sessionId}.txt`);
|
|
16
|
+
}
|
|
17
|
+
async #pathExists(path) {
|
|
18
|
+
try {
|
|
19
|
+
await access(path);
|
|
20
|
+
return true;
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async #stats(path) {
|
|
26
|
+
try {
|
|
27
|
+
return await stat(path);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async #outputFile(path, contents) {
|
|
33
|
+
const pathDirname = dirname(path);
|
|
34
|
+
if (!await this.#pathExists(pathDirname)) await mkdir(pathDirname, { recursive: true });
|
|
35
|
+
await writeFile(path, contents, "utf-8");
|
|
36
|
+
}
|
|
37
|
+
async read(sessionId) {
|
|
38
|
+
const filePath = this.#getFilePath(sessionId);
|
|
39
|
+
debug_default("file store: reading session data %", sessionId);
|
|
40
|
+
const stats = await this.#stats(filePath);
|
|
41
|
+
if (!stats) return null;
|
|
42
|
+
const sessionWillExpireAt = stats.mtimeMs + string.seconds.parse(this.#age) * 1e3;
|
|
43
|
+
if (Date.now() > sessionWillExpireAt) {
|
|
44
|
+
debug_default("file store: expired session data %s", sessionId);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
let contents = await readFile(filePath, "utf-8");
|
|
48
|
+
contents = contents.trim();
|
|
49
|
+
if (!contents) return null;
|
|
50
|
+
try {
|
|
51
|
+
return new MessageBuilder().verify(contents, sessionId);
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async write(sessionId, values) {
|
|
57
|
+
debug_default("file store: writing session data %s: %O", sessionId, values);
|
|
58
|
+
const filePath = this.#getFilePath(sessionId);
|
|
59
|
+
const message = new MessageBuilder().build(values, void 0, sessionId);
|
|
60
|
+
await this.#outputFile(filePath, message);
|
|
61
|
+
}
|
|
62
|
+
async destroy(sessionId) {
|
|
63
|
+
debug_default("file store: destroying session data %s", sessionId);
|
|
64
|
+
await rm(this.#getFilePath(sessionId), { force: true });
|
|
65
|
+
}
|
|
66
|
+
async touch(sessionId) {
|
|
67
|
+
debug_default("file store: touching session data %s", sessionId);
|
|
68
|
+
await utimes(this.#getFilePath(sessionId), /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export { FileStore };
|
package/build/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { configure } from './configure.ts';
|
|
|
11
11
|
export { Session } from './src/session.ts';
|
|
12
12
|
export { stubsRoot } from './stubs/main.ts';
|
|
13
13
|
export { defineConfig, stores } from './src/define_config.ts';
|
|
14
|
+
export { SessionCollection } from './src/session_collection.ts';
|
|
14
15
|
export { ReadOnlyValuesStore, ValuesStore } from './src/values_store.ts';
|
package/build/index.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "./
|
|
7
|
-
|
|
8
|
-
Session,
|
|
9
|
-
errors_exports
|
|
10
|
-
} from "./chunk-SHD6OX52.js";
|
|
11
|
-
import {
|
|
12
|
-
ReadOnlyValuesStore,
|
|
13
|
-
ValuesStore
|
|
14
|
-
} from "./chunk-HAD4PFFM.js";
|
|
15
|
-
import "./chunk-SBOMJK4T.js";
|
|
16
|
-
export {
|
|
17
|
-
ReadOnlyValuesStore,
|
|
18
|
-
Session,
|
|
19
|
-
ValuesStore,
|
|
20
|
-
configure,
|
|
21
|
-
defineConfig,
|
|
22
|
-
errors_exports as errors,
|
|
23
|
-
stores,
|
|
24
|
-
stubsRoot
|
|
25
|
-
};
|
|
1
|
+
import { r as errors_exports, t as Session } from "./session-C9DdRahS.js";
|
|
2
|
+
import { t as stubsRoot } from "./main-kn40V-hF.js";
|
|
3
|
+
import { n as stores, r as configure, t as defineConfig } from "./session-Cb9-DoMh.js";
|
|
4
|
+
import "./debug-BZVg83L1.js";
|
|
5
|
+
import { n as ValuesStore, t as ReadOnlyValuesStore } from "./values_store-CvR1Sn37.js";
|
|
6
|
+
import { t as SessionCollection } from "./session_collection-CvS5yIq6.js";
|
|
7
|
+
export { ReadOnlyValuesStore, Session, SessionCollection, ValuesStore, configure, defineConfig, errors_exports as errors, stores, stubsRoot };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{{{
|
|
2
|
+
exports({
|
|
3
|
+
to: app.makePath(
|
|
4
|
+
'database/migrations',
|
|
5
|
+
`${migration.prefix}_create_${migration.tableName}_table.ts`
|
|
6
|
+
)
|
|
7
|
+
})
|
|
8
|
+
}}}
|
|
9
|
+
import { BaseSchema } from '@adonisjs/lucid/schema'
|
|
10
|
+
|
|
11
|
+
export default class extends BaseSchema {
|
|
12
|
+
protected tableName = '{{ migration.tableName }}'
|
|
13
|
+
|
|
14
|
+
async up() {
|
|
15
|
+
this.schema.createTable(this.tableName, (table) => {
|
|
16
|
+
table.string('id').primary()
|
|
17
|
+
table.text('data').notNullable()
|
|
18
|
+
table.string('user_id').nullable().index()
|
|
19
|
+
table.timestamp('expires_at').notNullable().index()
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async down() {
|
|
24
|
+
this.schema.dropTable(this.tableName)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -23,6 +23,7 @@ declare module '@adonisjs/core/types' {
|
|
|
23
23
|
* AdonisJS application
|
|
24
24
|
*/
|
|
25
25
|
export default class SessionProvider {
|
|
26
|
+
#private;
|
|
26
27
|
protected app: ApplicationService;
|
|
27
28
|
constructor(app: ApplicationService);
|
|
28
29
|
/**
|
|
@@ -31,7 +32,7 @@ export default class SessionProvider {
|
|
|
31
32
|
*/
|
|
32
33
|
protected registerEdgePlugin(): Promise<void>;
|
|
33
34
|
/**
|
|
34
|
-
* Registering
|
|
35
|
+
* Registering bindings
|
|
35
36
|
*/
|
|
36
37
|
register(): void;
|
|
37
38
|
/**
|
|
@@ -1,51 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import "../
|
|
5
|
-
import "../
|
|
6
|
-
import "../chunk-SBOMJK4T.js";
|
|
7
|
-
|
|
8
|
-
// providers/session_provider.ts
|
|
9
|
-
import { configProvider } from "@adonisjs/core";
|
|
1
|
+
import "../session-C9DdRahS.js";
|
|
2
|
+
import "../debug-BZVg83L1.js";
|
|
3
|
+
import "../values_store-CvR1Sn37.js";
|
|
4
|
+
import { t as SessionCollection } from "../session_collection-CvS5yIq6.js";
|
|
5
|
+
import { t as SessionMiddleware } from "../session_middleware-gegOBxmm.js";
|
|
10
6
|
import { RuntimeException } from "@adonisjs/core/exceptions";
|
|
7
|
+
import { configProvider } from "@adonisjs/core";
|
|
11
8
|
var SessionProvider = class {
|
|
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
|
-
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
|
|
9
|
+
constructor(app) {
|
|
10
|
+
this.app = app;
|
|
11
|
+
}
|
|
12
|
+
async registerEdgePlugin() {
|
|
13
|
+
if (this.app.usingEdgeJS) {
|
|
14
|
+
const edge = await import("edge.js");
|
|
15
|
+
const { edgePluginSession } = await import("../src/plugins/edge.js");
|
|
16
|
+
edge.default.use(edgePluginSession);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async #resolveConfig() {
|
|
20
|
+
const sessionConfigProvider = this.app.config.get("session", {});
|
|
21
|
+
const config = await configProvider.resolve(this.app, sessionConfigProvider);
|
|
22
|
+
if (!config) throw new RuntimeException("Invalid \"config/session.ts\" file. Make sure you are using the \"defineConfig\" method");
|
|
23
|
+
return config;
|
|
24
|
+
}
|
|
25
|
+
register() {
|
|
26
|
+
this.app.container.singleton(SessionMiddleware, async (resolver) => {
|
|
27
|
+
return new SessionMiddleware(await this.#resolveConfig(), await resolver.make("emitter"));
|
|
28
|
+
});
|
|
29
|
+
this.app.container.singleton(SessionCollection, async () => {
|
|
30
|
+
return new SessionCollection(await this.#resolveConfig());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async boot() {
|
|
34
|
+
await this.registerEdgePlugin();
|
|
35
|
+
}
|
|
51
36
|
};
|
|
37
|
+
export { SessionProvider as default };
|