@nekm/svelte-core 1.7.19 → 1.8.0
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.
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SessionStoreData, Store } from 'svelte-kit-sessions';
|
|
2
|
+
import type { Collection } from 'mongodb';
|
|
3
|
+
interface SessionStoreDataWithId extends SessionStoreData {
|
|
4
|
+
readonly _id: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SvelteKitSessionMongoDbConfig {
|
|
7
|
+
readonly defaultTtlSeconds?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class SvelteKitSessionMongoDb implements Store {
|
|
10
|
+
private readonly collection;
|
|
11
|
+
private readonly config?;
|
|
12
|
+
private readonly ttlName;
|
|
13
|
+
constructor(collection: Promise<Collection<SessionStoreDataWithId>> | Collection<SessionStoreDataWithId>, config?: SvelteKitSessionMongoDbConfig | undefined);
|
|
14
|
+
destroy(_id: string): Promise<void>;
|
|
15
|
+
get(_id: string): Promise<SessionStoreData | null>;
|
|
16
|
+
set(_id: string, storeData: SessionStoreData, ttl: number): Promise<void>;
|
|
17
|
+
touch(_id: string, ttl: number): Promise<void>;
|
|
18
|
+
private fixTtl;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class SvelteKitSessionMongoDb {
|
|
2
|
+
collection;
|
|
3
|
+
config;
|
|
4
|
+
ttlName = 'expireAt';
|
|
5
|
+
constructor(collection, config) {
|
|
6
|
+
this.collection = collection;
|
|
7
|
+
this.config = config;
|
|
8
|
+
}
|
|
9
|
+
async destroy(_id) {
|
|
10
|
+
const collection = await this.collection;
|
|
11
|
+
await collection.deleteOne({ _id });
|
|
12
|
+
}
|
|
13
|
+
async get(_id) {
|
|
14
|
+
const collection = await this.collection;
|
|
15
|
+
return collection.findOne({ _id });
|
|
16
|
+
}
|
|
17
|
+
async set(_id, storeData, ttl) {
|
|
18
|
+
const collection = await this.collection;
|
|
19
|
+
await collection.updateOne({ _id }, {
|
|
20
|
+
$set: {
|
|
21
|
+
...storeData,
|
|
22
|
+
[this.ttlName]: this.fixTtl(ttl),
|
|
23
|
+
}
|
|
24
|
+
}, { upsert: true });
|
|
25
|
+
}
|
|
26
|
+
async touch(_id, ttl) {
|
|
27
|
+
const collection = await this.collection;
|
|
28
|
+
await collection.updateOne({ _id }, {
|
|
29
|
+
$set: { [this.ttlName]: this.fixTtl(ttl) }
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
fixTtl(ttl) {
|
|
33
|
+
if (ttl === Infinity) {
|
|
34
|
+
ttl = this.config?.defaultTtlSeconds ?? Infinity;
|
|
35
|
+
}
|
|
36
|
+
const ttlDate = new Date();
|
|
37
|
+
ttlDate.setUTCSeconds(ttlDate.getUTCSeconds() + ttl);
|
|
38
|
+
return ttlDate;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@nekm/svelte-core",
|
|
3
3
|
"description": "Code I find myself re-writing over-and-over, Svelte edition.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.8.0",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite dev",
|
|
8
8
|
"build": "vite build && npm run prepack",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
29
|
"svelte": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./svelte-kit-session-mongodb": {
|
|
32
|
+
"types": "./dist/svelte-kit-session-mongodb/index.d.ts",
|
|
33
|
+
"svelte": "./dist/svelte-kit-session-mongodb/index.js"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
@@ -34,8 +38,10 @@
|
|
|
34
38
|
"@sveltejs/package": "^2.5.7",
|
|
35
39
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
36
40
|
"@types/node": "^25.0.10",
|
|
41
|
+
"mongodb": "^7.1.0",
|
|
37
42
|
"publint": "^0.3.15",
|
|
38
43
|
"svelte-check": "^4.3.4",
|
|
44
|
+
"svelte-kit-sessions": "^0.4.0",
|
|
39
45
|
"typescript": "^5.9.3",
|
|
40
46
|
"vite": "^7.2.7",
|
|
41
47
|
"vite-plugin-devtools-json": "^1.0.0"
|
|
@@ -48,5 +54,9 @@
|
|
|
48
54
|
"@sveltejs/kit": "2.*",
|
|
49
55
|
"jose": "6.*",
|
|
50
56
|
"svelte": "5.*"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"mongodb": "7.*",
|
|
60
|
+
"svelte-kit-sessions": "0.4.*"
|
|
51
61
|
}
|
|
52
62
|
}
|