@nekm/svelte-core 1.7.19 → 1.9.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.
package/dist/seo.svelte CHANGED
@@ -1,5 +1,11 @@
1
1
  <script lang="ts">
2
- import {type QueryParams, queryParamsCreate, strTrimEnd, strTrimStart} from "@nekm/core";
2
+ import { page } from "$app/state";
3
+ import {
4
+ type QueryParams,
5
+ queryParamsCreate,
6
+ strTrimStart,
7
+ urlSetOrigin,
8
+ } from "@nekm/core";
3
9
 
4
10
  export interface SeoCanonical {
5
11
  readonly path?: string;
@@ -13,46 +19,48 @@
13
19
  readonly mimeContentType: string;
14
20
  }
15
21
 
22
+ export interface SeoTwitter {
23
+ readonly creator?: string;
24
+ readonly site?: string;
25
+ }
26
+
16
27
  export interface SeoProps {
17
28
  readonly siteTitle: string;
18
29
  readonly pageTitle: string;
19
30
  readonly description: string;
20
- readonly origin: string;
31
+ readonly origin?: string;
21
32
  readonly icon: SeoIcon;
22
33
  readonly canonical?: SeoCanonical;
23
34
  readonly next?: SeoCanonical;
35
+ readonly twitter?: SeoTwitter;
24
36
  }
25
37
 
26
- const { siteTitle, description, pageTitle, icon, canonical, next, origin }: SeoProps = $props();
38
+ const {
39
+ siteTitle,
40
+ pageTitle,
41
+ description,
42
+ icon,
43
+ canonical,
44
+ next,
45
+ origin: propsOrigin,
46
+ twitter,
47
+ }: SeoProps = $props();
27
48
 
28
- function createCanonical(canonical?: SeoCanonical, includeBaseUrl = false): string | undefined {
29
- let url;
49
+ function createCanonical(canonical: SeoCanonical): string | undefined {
50
+ if (!canonical.path) return origin;
30
51
 
31
- if (canonical || includeBaseUrl) {
32
- url = origin;
33
- }
52
+ const path = strTrimStart(canonical.path, "/");
53
+ const canonicalWithPath = `${origin}/${path}`;
34
54
 
35
- if (canonical?.path) {
36
- url += `/${canonical.path}`;
37
- }
55
+ if (!canonical.queryParams) return canonicalWithPath;
38
56
 
39
- if (canonical?.queryParams) {
40
- const queryParamsStr = queryParamsCreate(canonical.queryParams)
41
- url += `?${queryParamsStr}`;
42
- }
43
-
44
- return url;
57
+ return `${canonicalWithPath}?${queryParamsCreate(canonical.queryParams)}`;
45
58
  }
46
59
 
47
- // Starts with http or https. I.e, is an absolute URL.
48
- const iconHref = $derived.by(() => {
49
- return !icon.href.match(/^https?:\/\//ig)
50
- ? `${strTrimEnd(origin, "/")}/${strTrimStart(icon.href, "/")}`
51
- : icon.href;
52
- });
53
-
54
- const canonicalUrl = $derived(createCanonical(canonical, true));
55
- const nextUrl = $derived(createCanonical(next));
60
+ const origin = $derived(propsOrigin ?? page.url.origin);
61
+ const iconHref = $derived(urlSetOrigin(origin, icon.href));
62
+ const canonicalUrl = $derived(!canonical ? origin : createCanonical(canonical));
63
+ const nextUrl = $derived(!next ? undefined : createCanonical(next));
56
64
  </script>
57
65
 
58
66
  <svelte:head>
@@ -76,9 +84,16 @@
76
84
  <meta property="og:url" content={canonicalUrl} />
77
85
  <meta property="og:type" content="website" />
78
86
 
79
- <meta name="twitter:card" content="summary_large_image">
87
+ <meta name="twitter:card" content="summary_large_image" />
80
88
  <meta name="twitter:title" content={pageTitle} />
81
89
  <meta name="twitter:description" content={description} />
82
90
  <meta name="twitter:image" content={iconHref} />
83
- <meta name="twitter:creator" content="@iamBraska" />
91
+
92
+ {#if twitter?.creator}
93
+ <meta name="twitter:creator" content="@{twitter.creator}" />
94
+ {/if}
95
+
96
+ {#if twitter?.site}
97
+ <meta name="twitter:site" content="@{twitter.site}" />
98
+ {/if}
84
99
  </svelte:head>
@@ -9,14 +9,19 @@ export interface SeoIcon {
9
9
  readonly width: number;
10
10
  readonly mimeContentType: string;
11
11
  }
12
+ export interface SeoTwitter {
13
+ readonly creator?: string;
14
+ readonly site?: string;
15
+ }
12
16
  export interface SeoProps {
13
17
  readonly siteTitle: string;
14
18
  readonly pageTitle: string;
15
19
  readonly description: string;
16
- readonly origin: string;
20
+ readonly origin?: string;
17
21
  readonly icon: SeoIcon;
18
22
  readonly canonical?: SeoCanonical;
19
23
  readonly next?: SeoCanonical;
24
+ readonly twitter?: SeoTwitter;
20
25
  }
21
26
  declare const Seo: import("svelte").Component<SeoProps, {}, "">;
22
27
  type Seo = ReturnType<typeof Seo>;
@@ -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.7.19",
5
+ "version": "1.9.0",
6
6
  "scripts": {
7
7
  "dev": "vite dev",
8
8
  "build": "vite build && npm run prepack",
@@ -27,17 +27,23 @@
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": {
33
- "@sveltejs/adapter-auto": "^7.0.0",
37
+ "@sveltejs/adapter-auto": "^7.0.1",
34
38
  "@sveltejs/package": "^2.5.7",
35
- "@sveltejs/vite-plugin-svelte": "^6.2.1",
36
- "@types/node": "^25.0.10",
37
- "publint": "^0.3.15",
38
- "svelte-check": "^4.3.4",
39
- "typescript": "^5.9.3",
40
- "vite": "^7.2.7",
39
+ "@sveltejs/vite-plugin-svelte": "^6",
40
+ "@types/node": "^25.5.0",
41
+ "mongodb": "^7.1.1",
42
+ "publint": "^0.3.18",
43
+ "svelte-check": "^4.4.5",
44
+ "svelte-kit-sessions": "^0.4.0",
45
+ "typescript": "^5",
46
+ "vite": "^7",
41
47
  "vite-plugin-devtools-json": "^1.0.0"
42
48
  },
43
49
  "keywords": [
@@ -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
  }