Move many files to diachron subdir
This commit is contained in:
@@ -3,13 +3,13 @@ import express, {
|
|||||||
type Response as ExpressResponse,
|
type Response as ExpressResponse,
|
||||||
} from "express";
|
} from "express";
|
||||||
import { match } from "path-to-regexp";
|
import { match } from "path-to-regexp";
|
||||||
import { Session } from "./auth";
|
import { Session } from "./diachron/auth";
|
||||||
import { cli } from "./cli";
|
import { cli } from "./diachron/cli";
|
||||||
import { contentTypes } from "./content-types";
|
import { contentTypes } from "./diachron/content-types";
|
||||||
import { runWithContext } from "./context";
|
import { runWithContext } from "./diachron/context";
|
||||||
import { core } from "./core";
|
import { core } from "./diachron/core";
|
||||||
import { httpCodes } from "./http-codes";
|
import { httpCodes } from "./diachron/http-codes";
|
||||||
import { request } from "./request";
|
import { request } from "./diachron/request";
|
||||||
import { routes } from "./routes";
|
import { routes } from "./routes";
|
||||||
|
|
||||||
// import { URLPattern } from 'node:url';
|
// import { URLPattern } from 'node:url';
|
||||||
@@ -25,7 +25,7 @@ import {
|
|||||||
type ProcessedRoute,
|
type ProcessedRoute,
|
||||||
type Result,
|
type Result,
|
||||||
type Route,
|
type Route,
|
||||||
} from "./types";
|
} from "./diachron/types";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { DateTime } from "ts-luxon";
|
import { DateTime } from "ts-luxon";
|
||||||
import { get, User } from "../diachron/hydrators/user";
|
import { get, User } from "../hydrators/user";
|
||||||
import { request } from "../request";
|
import { request } from "../request";
|
||||||
import { html, render } from "../request/util";
|
import { html, render } from "../request/util";
|
||||||
import type { Call, Result, Route } from "../types";
|
import type { Call, Result, Route } from "../types";
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Kysely, PostgresDialect } from "kysely";
|
import { Kysely, PostgresDialect } from "kysely";
|
||||||
import { Pool } from "pg";
|
import { Pool } from "pg";
|
||||||
import { connectionConfig } from "../../database";
|
import { connectionConfig } from "../database";
|
||||||
import type { DB } from "../../generated/db";
|
import type { DB } from "../../generated/db";
|
||||||
|
|
||||||
const db = new Kysely<DB>({
|
const db = new Kysely<DB>({
|
||||||
|
|||||||
1
express/diachron/hydrators/index.ts
Normal file
1
express/diachron/hydrators/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export type Hydrators = {};
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Run: DB_PORT=5433 DB_USER=diachron_test DB_PASSWORD=diachron_test DB_NAME=diachron_test npx tsx --test tests/*.test.ts
|
// Run: DB_PORT=5433 DB_USER=diachron_test DB_PASSWORD=diachron_test DB_NAME=diachron_test npx tsx --test tests/*.test.ts
|
||||||
|
|
||||||
import { Pool } from "pg";
|
import { Pool } from "pg";
|
||||||
import { connectionConfig, migrate } from "../../../database";
|
import { connectionConfig, migrate } from "../../database";
|
||||||
|
|
||||||
const pool = new Pool(connectionConfig);
|
const pool = new Pool(connectionConfig);
|
||||||
|
|
||||||
|
|||||||
59
express/diachron/hydrators/user.ts
Normal file
59
express/diachron/hydrators/user.ts
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import {
|
||||||
|
ColumnType,
|
||||||
|
Generated,
|
||||||
|
Insertable,
|
||||||
|
JSONColumnType,
|
||||||
|
Selectable,
|
||||||
|
Updateable,
|
||||||
|
} from "kysely";
|
||||||
|
import type { TypeID } from "typeid-js";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db, Hydrator } from "./hydrator";
|
||||||
|
|
||||||
|
const parser = z.object({
|
||||||
|
// id: z.uuidv7(),
|
||||||
|
id: z.uuid(),
|
||||||
|
display_name: z.string(),
|
||||||
|
// FIXME: status is duplicated elsewhere
|
||||||
|
status: z.union([
|
||||||
|
z.literal("active"),
|
||||||
|
z.literal("suspended"),
|
||||||
|
z.literal("pending"),
|
||||||
|
]),
|
||||||
|
email: z.email(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const tp = parser.parse({
|
||||||
|
id: "cfae0a19-6515-4813-bc2d-1e032b72b203",
|
||||||
|
display_name: "foo",
|
||||||
|
status: "active",
|
||||||
|
email: "mw@philologue.net",
|
||||||
|
});
|
||||||
|
|
||||||
|
export type User = z.infer<typeof parser>;
|
||||||
|
|
||||||
|
const get = async (id: string): Promise<null | User> => {
|
||||||
|
const ret = await db
|
||||||
|
.selectFrom("users")
|
||||||
|
.where("users.id", "=", id)
|
||||||
|
.innerJoin("user_emails", "user_emails.user_id", "users.id")
|
||||||
|
.select([
|
||||||
|
"users.id",
|
||||||
|
"users.status",
|
||||||
|
"users.display_name",
|
||||||
|
"user_emails.email",
|
||||||
|
])
|
||||||
|
.executeTakeFirst();
|
||||||
|
|
||||||
|
if (ret === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.dir(ret);
|
||||||
|
|
||||||
|
const parsed = parser.parse(ret);
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
};
|
||||||
|
|
||||||
|
export { get };
|
||||||
0
express/generated/.gitignore
vendored
Normal file
0
express/generated/.gitignore
vendored
Normal file
109
express/generated/db.d.ts
vendored
Normal file
109
express/generated/db.d.ts
vendored
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
* This file was generated by kysely-codegen.
|
||||||
|
* Please do not edit it manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { ColumnType } from "kysely";
|
||||||
|
|
||||||
|
export type Generated<T> =
|
||||||
|
T extends ColumnType<infer S, infer I, infer U>
|
||||||
|
? ColumnType<S, I | undefined, U>
|
||||||
|
: ColumnType<T, T | undefined, T>;
|
||||||
|
|
||||||
|
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
|
||||||
|
|
||||||
|
export interface _Migrations {
|
||||||
|
applied_at: Generated<Timestamp>;
|
||||||
|
id: Generated<number>;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Capabilities {
|
||||||
|
description: string | null;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Groups {
|
||||||
|
created_at: Generated<Timestamp>;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RoleCapabilities {
|
||||||
|
capability_id: string;
|
||||||
|
granted_at: Generated<Timestamp>;
|
||||||
|
revoked_at: Timestamp | null;
|
||||||
|
role_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Roles {
|
||||||
|
description: string | null;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Sessions {
|
||||||
|
auth_method: string;
|
||||||
|
created_at: Generated<Timestamp>;
|
||||||
|
expires_at: Timestamp;
|
||||||
|
id: Generated<string>;
|
||||||
|
ip_address: string | null;
|
||||||
|
is_used: Generated<boolean | null>;
|
||||||
|
revoked_at: Timestamp | null;
|
||||||
|
token_hash: string;
|
||||||
|
token_type: string;
|
||||||
|
user_agent: string | null;
|
||||||
|
user_email_id: string | null;
|
||||||
|
user_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserCredentials {
|
||||||
|
created_at: Generated<Timestamp>;
|
||||||
|
credential_type: Generated<string>;
|
||||||
|
id: string;
|
||||||
|
password_hash: string | null;
|
||||||
|
updated_at: Generated<Timestamp>;
|
||||||
|
user_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserEmails {
|
||||||
|
created_at: Generated<Timestamp>;
|
||||||
|
email: string;
|
||||||
|
id: string;
|
||||||
|
is_primary: Generated<boolean>;
|
||||||
|
is_verified: Generated<boolean>;
|
||||||
|
normalized_email: string;
|
||||||
|
revoked_at: Timestamp | null;
|
||||||
|
user_id: string;
|
||||||
|
verified_at: Timestamp | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserGroupRoles {
|
||||||
|
granted_at: Generated<Timestamp>;
|
||||||
|
group_id: string;
|
||||||
|
revoked_at: Timestamp | null;
|
||||||
|
role_id: string;
|
||||||
|
user_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Users {
|
||||||
|
created_at: Generated<Timestamp>;
|
||||||
|
display_name: string | null;
|
||||||
|
id: string;
|
||||||
|
status: Generated<string>;
|
||||||
|
updated_at: Generated<Timestamp>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DB {
|
||||||
|
_migrations: _Migrations;
|
||||||
|
capabilities: Capabilities;
|
||||||
|
groups: Groups;
|
||||||
|
role_capabilities: RoleCapabilities;
|
||||||
|
roles: Roles;
|
||||||
|
sessions: Sessions;
|
||||||
|
user_credentials: UserCredentials;
|
||||||
|
user_emails: UserEmails;
|
||||||
|
user_group_roles: UserGroupRoles;
|
||||||
|
users: Users;
|
||||||
|
}
|
||||||
0
express/group.ts
Normal file
0
express/group.ts
Normal file
0
express/migrations/.gitignore
vendored
Normal file
0
express/migrations/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE test_application_table ();
|
||||||
1
express/migrations/2026-01-15_01.sql
Normal file
1
express/migrations/2026-01-15_01.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE test_application_table ();
|
||||||
@@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
import nunjucks from "nunjucks";
|
import nunjucks from "nunjucks";
|
||||||
import { DateTime } from "ts-luxon";
|
import { DateTime } from "ts-luxon";
|
||||||
import { authRoutes } from "./auth/routes";
|
import { authRoutes } from "./diachron/auth/routes";
|
||||||
import { routes as basicRoutes } from "./basic/routes";
|
import { routes as basicRoutes } from "./diachron/basic/routes";
|
||||||
import { contentTypes } from "./content-types";
|
import { contentTypes } from "./diachron/content-types";
|
||||||
import { core } from "./core";
|
import { core } from "./diachron/core";
|
||||||
import { multiHandler } from "./handlers";
|
import { multiHandler } from "./diachron/handlers";
|
||||||
import { httpCodes } from "./http-codes";
|
import { httpCodes } from "./diachron/http-codes";
|
||||||
import type { Call, Result, Route } from "./types";
|
import type { Call, Result, Route } from "./diachron/types";
|
||||||
|
|
||||||
// FIXME: Obviously put this somewhere else
|
// FIXME: Obviously put this somewhere else
|
||||||
const okText = (result: string): Result => {
|
const okText = (result: string): Result => {
|
||||||
|
|||||||
Reference in New Issue
Block a user