@axium/server 0.11.4 → 0.12.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/auth.d.ts +1 -1
- package/dist/auth.js +2 -3
- package/dist/database.d.ts +16 -3
- package/dist/database.js +11 -0
- package/dist/plugins.d.ts +1 -1
- package/package.json +3 -3
package/dist/auth.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Passkey, Session, Verification } from '@axium/core/api';
|
|
2
2
|
import type { User } from '@axium/core/user';
|
|
3
3
|
import type { RequestEvent } from '@sveltejs/kit';
|
|
4
|
-
import { type Schema } from './database.js';
|
|
5
4
|
import type { Insertable } from 'kysely';
|
|
5
|
+
import { type Schema } from './database.js';
|
|
6
6
|
export interface UserInternal extends User {
|
|
7
7
|
isAdmin: boolean;
|
|
8
8
|
/** Tags are internal, roles are public */
|
package/dist/auth.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { jsonObjectFrom } from 'kysely/helpers/postgres';
|
|
2
1
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
3
|
-
import { connect, database as db } from './database.js';
|
|
2
|
+
import { connect, database as db, userFromId } from './database.js';
|
|
4
3
|
export async function getUser(id) {
|
|
5
4
|
connect();
|
|
6
5
|
return await db.selectFrom('users').selectAll().where('id', '=', id).executeTakeFirstOrThrow();
|
|
@@ -30,7 +29,7 @@ export async function getSessionAndUser(token) {
|
|
|
30
29
|
const result = await db
|
|
31
30
|
.selectFrom('sessions')
|
|
32
31
|
.selectAll()
|
|
33
|
-
.select(
|
|
32
|
+
.select(userFromId)
|
|
34
33
|
.where('sessions.token', '=', token)
|
|
35
34
|
.where('sessions.expires', '>', new Date())
|
|
36
35
|
.executeTakeFirstOrThrow();
|
package/dist/database.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Preferences } from '@axium/core';
|
|
2
2
|
import type { AuthenticatorTransportFuture, CredentialDeviceType } from '@simplewebauthn/server';
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
3
|
+
import type * as Kys from 'kysely';
|
|
4
|
+
import type { GeneratedAlways } from 'kysely';
|
|
5
|
+
import { Kysely } from 'kysely';
|
|
6
|
+
import type { UserInternal, VerificationRole } from './auth.js';
|
|
5
7
|
export interface Schema {
|
|
6
8
|
users: {
|
|
7
9
|
id: string;
|
|
@@ -44,12 +46,22 @@ export interface Schema {
|
|
|
44
46
|
export type Database = Kysely<Schema> & AsyncDisposable;
|
|
45
47
|
export declare let database: Database;
|
|
46
48
|
export declare function connect(): Database;
|
|
49
|
+
export declare function count<const T extends keyof Schema>(table: T): Promise<number>;
|
|
50
|
+
export type TablesMatching<T> = (string & keyof Schema) & keyof {
|
|
51
|
+
[K in keyof Schema as Schema[K] extends T ? K : never]: null;
|
|
52
|
+
};
|
|
53
|
+
type TableWithId = TablesMatching<{
|
|
54
|
+
userId: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Select the user with the id from the userId column of a table, placing it in the `user` property.
|
|
58
|
+
*/
|
|
59
|
+
export declare function userFromId(eb: Kys.ExpressionBuilder<Schema, TableWithId>): Kys.AliasedRawBuilder<UserInternal, 'user'>;
|
|
47
60
|
export interface Stats {
|
|
48
61
|
users: number;
|
|
49
62
|
passkeys: number;
|
|
50
63
|
sessions: number;
|
|
51
64
|
}
|
|
52
|
-
export declare function count<const T extends keyof Schema>(table: T): Promise<number>;
|
|
53
65
|
export declare function status(): Promise<Stats>;
|
|
54
66
|
export declare function statusText(): Promise<string>;
|
|
55
67
|
export interface OpOptions {
|
|
@@ -73,3 +85,4 @@ export declare function uninstall(opt: OpOptions): Promise<void>;
|
|
|
73
85
|
* Removes all data from tables.
|
|
74
86
|
*/
|
|
75
87
|
export declare function wipe(opt: OpOptions): Promise<void>;
|
|
88
|
+
export {};
|
package/dist/database.js
CHANGED
|
@@ -51,6 +51,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
53
|
import { Kysely, PostgresDialect, sql } from 'kysely';
|
|
54
|
+
import { jsonObjectFrom } from 'kysely/helpers/postgres';
|
|
54
55
|
import { randomBytes } from 'node:crypto';
|
|
55
56
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
56
57
|
import pg from 'pg';
|
|
@@ -75,12 +76,22 @@ export function connect() {
|
|
|
75
76
|
globalThis[sym] = database;
|
|
76
77
|
return database;
|
|
77
78
|
}
|
|
79
|
+
// Helpers
|
|
78
80
|
export async function count(table) {
|
|
79
81
|
const db = connect();
|
|
80
82
|
return (await db.selectFrom(table)
|
|
81
83
|
.select(db.fn.countAll().as('count'))
|
|
82
84
|
.executeTakeFirstOrThrow()).count;
|
|
83
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Select the user with the id from the userId column of a table, placing it in the `user` property.
|
|
88
|
+
*/
|
|
89
|
+
export function userFromId(eb) {
|
|
90
|
+
return jsonObjectFrom(eb.selectFrom('users').selectAll().whereRef('id', '=', 'userId'))
|
|
91
|
+
.$notNull()
|
|
92
|
+
.$castTo()
|
|
93
|
+
.as('user');
|
|
94
|
+
}
|
|
84
95
|
export async function status() {
|
|
85
96
|
return {
|
|
86
97
|
users: await count('users'),
|
package/dist/plugins.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const Plugin: z.ZodObject<{
|
|
|
12
12
|
description: z.ZodOptional<z.ZodString>;
|
|
13
13
|
routes: z.ZodOptional<z.ZodString>;
|
|
14
14
|
statusText: z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.core.$ZodTuple<[], null>, z.ZodString>, z.core.$InferInnerFunctionTypeAsync<z.core.$ZodTuple<[], null>, z.ZodString>>;
|
|
15
|
-
hooks: z.ZodOptional<z.ZodRecord<z.
|
|
15
|
+
hooks: z.ZodOptional<z.ZodRecord<z.ZodLiteral<"remove" | "db_init" | "db_wipe" | "clean"> & z.core.$partial, z.ZodCustom<(...args: any[]) => any, (...args: any[]) => any>>>;
|
|
16
16
|
}, z.core.$loose>;
|
|
17
17
|
declare const kSpecifier: unique symbol;
|
|
18
18
|
export type Plugin = z.infer<typeof Plugin>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axium/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"author": "James Prevett <axium@jamespre.dev> (https://jamespre.dev)",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"@axium/client": ">=0.1.0",
|
|
45
45
|
"@axium/core": ">=0.4.0",
|
|
46
46
|
"utilium": "^2.3.8",
|
|
47
|
-
"zod": "^3.25.
|
|
47
|
+
"zod": "^3.25.76"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@axium/server": "file:.",
|
|
51
51
|
"@simplewebauthn/server": "^13.1.1",
|
|
52
52
|
"@sveltejs/kit": "^2.20.2",
|
|
53
53
|
"@types/pg": "^8.11.11",
|
|
54
|
-
"commander": "^
|
|
54
|
+
"commander": "^14.0.0",
|
|
55
55
|
"cookie": "^1.0.2",
|
|
56
56
|
"kysely": "^0.28.0",
|
|
57
57
|
"logzen": "^0.7.0",
|