Initial commit - Event Planner application

This commit is contained in:
mberlin
2026-03-18 14:55:56 -03:00
commit 86d779eb4d
7548 changed files with 1006324 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import type { DatabaseConnection } from './database-connection.js';
export interface ConnectionProvider {
/**
* Provides a connection for the callback and takes care of disposing
* the connection after the callback has been run.
*/
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,35 @@
import type { CompiledQuery } from '../query-compiler/compiled-query.js';
/**
* A single connection to the database engine.
*
* These are created by an instance of {@link Driver}.
*/
export interface DatabaseConnection {
executeQuery<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
streamQuery<R>(compiledQuery: CompiledQuery, chunkSize?: number): AsyncIterableIterator<QueryResult<R>>;
}
export interface QueryResult<O> {
/**
* This is defined for insert, update, delete and merge queries and contains
* the number of rows the query inserted/updated/deleted.
*/
readonly numAffectedRows?: bigint;
/**
* This is defined for update queries and contains the number of rows
* the query changed.
*
* This is **optional** and only provided in dialects such as MySQL.
* You would probably use {@link numAffectedRows} in most cases.
*/
readonly numChangedRows?: bigint;
/**
* This is defined for insert queries on dialects that return
* the auto incrementing primary key from an insert.
*/
readonly insertId?: bigint;
/**
* The rows returned by the query. This is always defined and is
* empty if the query returned no rows.
*/
readonly rows: O[];
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,12 @@
import type { DatabaseConnection } from './database-connection.js';
import type { ConnectionProvider } from './connection-provider.js';
import type { Driver } from './driver.js';
export declare class DefaultConnectionProvider implements ConnectionProvider {
#private;
constructor(driver: Driver);
/**
* Provides a connection for the callback and takes care of disposing
* the connection after the callback has been run.
*/
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
}

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultConnectionProvider = void 0;
class DefaultConnectionProvider {
#driver;
constructor(driver) {
this.#driver = driver;
}
async provideConnection(consumer) {
const connection = await this.#driver.acquireConnection();
try {
return await consumer(connection);
}
finally {
await this.#driver.releaseConnection(connection);
}
}
}
exports.DefaultConnectionProvider = DefaultConnectionProvider;

61
node_modules/kysely/dist/cjs/driver/driver.d.ts generated vendored Normal file
View File

@@ -0,0 +1,61 @@
import type { QueryCompiler } from '../query-compiler/query-compiler.js';
import type { ArrayItemType } from '../util/type-utils.js';
import type { DatabaseConnection } from './database-connection.js';
/**
* A Driver creates and releases {@link DatabaseConnection | database connections}
* and is also responsible for connection pooling (if the dialect supports pooling).
*/
export interface Driver {
/**
* Initializes the driver.
*
* After calling this method the driver should be usable and `acquireConnection` etc.
* methods should be callable.
*/
init(): Promise<void>;
/**
* Acquires a new connection from the pool.
*/
acquireConnection(): Promise<DatabaseConnection>;
/**
* Begins a transaction.
*/
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
/**
* Commits a transaction.
*/
commitTransaction(connection: DatabaseConnection): Promise<void>;
/**
* Rolls back a transaction.
*/
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
/**
* Establishses a new savepoint within a transaction.
*/
savepoint?(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
/**
* Rolls back to a savepoint within a transaction.
*/
rollbackToSavepoint?(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
/**
* Releases a savepoint within a transaction.
*/
releaseSavepoint?(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
/**
* Releases a connection back to the pool.
*/
releaseConnection(connection: DatabaseConnection): Promise<void>;
/**
* Destroys the driver and releases all resources.
*/
destroy(): Promise<void>;
}
export interface TransactionSettings {
readonly accessMode?: AccessMode;
readonly isolationLevel?: IsolationLevel;
}
export declare const TRANSACTION_ACCESS_MODES: readonly ["read only", "read write"];
export type AccessMode = ArrayItemType<typeof TRANSACTION_ACCESS_MODES>;
export declare const TRANSACTION_ISOLATION_LEVELS: readonly ["read uncommitted", "read committed", "repeatable read", "serializable", "snapshot"];
export type IsolationLevel = ArrayItemType<typeof TRANSACTION_ISOLATION_LEVELS>;
export declare function validateTransactionSettings(settings: TransactionSettings): void;

22
node_modules/kysely/dist/cjs/driver/driver.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TRANSACTION_ISOLATION_LEVELS = exports.TRANSACTION_ACCESS_MODES = void 0;
exports.validateTransactionSettings = validateTransactionSettings;
exports.TRANSACTION_ACCESS_MODES = ['read only', 'read write'];
exports.TRANSACTION_ISOLATION_LEVELS = [
'read uncommitted',
'read committed',
'repeatable read',
'serializable',
'snapshot',
];
function validateTransactionSettings(settings) {
if (settings.accessMode &&
!exports.TRANSACTION_ACCESS_MODES.includes(settings.accessMode)) {
throw new Error(`invalid transaction access mode ${settings.accessMode}`);
}
if (settings.isolationLevel &&
!exports.TRANSACTION_ISOLATION_LEVELS.includes(settings.isolationLevel)) {
throw new Error(`invalid transaction isolation level ${settings.isolationLevel}`);
}
}

75
node_modules/kysely/dist/cjs/driver/dummy-driver.d.ts generated vendored Normal file
View File

@@ -0,0 +1,75 @@
import type { DatabaseConnection } from './database-connection.js';
import type { Driver } from './driver.js';
/**
* A driver that does absolutely nothing.
*
* You can use this to create Kysely instances solely for building queries
*
* ### Examples
*
* This example creates a Kysely instance for building postgres queries:
*
* ```ts
* import {
* DummyDriver,
* Kysely,
* PostgresAdapter,
* PostgresIntrospector,
* PostgresQueryCompiler
* } from 'kysely'
* import type { Database } from 'type-editor' // imaginary module
*
* const db = new Kysely<Database>({
* dialect: {
* createAdapter: () => new PostgresAdapter(),
* createDriver: () => new DummyDriver(),
* createIntrospector: (db: Kysely<any>) => new PostgresIntrospector(db),
* createQueryCompiler: () => new PostgresQueryCompiler(),
* },
* })
* ```
*
* You can use it to build a query and compile it to SQL but trying to
* execute the query will throw an error.
*
* ```ts
* const { sql } = db.selectFrom('person').selectAll().compile()
* console.log(sql) // select * from "person"
* ```
*/
export declare class DummyDriver implements Driver {
/**
* Initializes the driver.
*
* After calling this method the driver should be usable and `acquireConnection` etc.
* methods should be callable.
*/
init(): Promise<void>;
/**
* Acquires a new connection from the pool.
*/
acquireConnection(): Promise<DatabaseConnection>;
/**
* Begins a transaction.
*/
beginTransaction(): Promise<void>;
/**
* Commits a transaction.
*/
commitTransaction(): Promise<void>;
/**
* Rolls back a transaction.
*/
rollbackTransaction(): Promise<void>;
/**
* Releases a connection back to the pool.
*/
releaseConnection(): Promise<void>;
/**
* Destroys the driver and releases all resources.
*/
destroy(): Promise<void>;
releaseSavepoint(): Promise<void>;
rollbackToSavepoint(): Promise<void>;
savepoint(): Promise<void>;
}

83
node_modules/kysely/dist/cjs/driver/dummy-driver.js generated vendored Normal file
View File

@@ -0,0 +1,83 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DummyDriver = void 0;
/**
* A driver that does absolutely nothing.
*
* You can use this to create Kysely instances solely for building queries
*
* ### Examples
*
* This example creates a Kysely instance for building postgres queries:
*
* ```ts
* import {
* DummyDriver,
* Kysely,
* PostgresAdapter,
* PostgresIntrospector,
* PostgresQueryCompiler
* } from 'kysely'
* import type { Database } from 'type-editor' // imaginary module
*
* const db = new Kysely<Database>({
* dialect: {
* createAdapter: () => new PostgresAdapter(),
* createDriver: () => new DummyDriver(),
* createIntrospector: (db: Kysely<any>) => new PostgresIntrospector(db),
* createQueryCompiler: () => new PostgresQueryCompiler(),
* },
* })
* ```
*
* You can use it to build a query and compile it to SQL but trying to
* execute the query will throw an error.
*
* ```ts
* const { sql } = db.selectFrom('person').selectAll().compile()
* console.log(sql) // select * from "person"
* ```
*/
class DummyDriver {
async init() {
// Nothing to do here.
}
async acquireConnection() {
return new DummyConnection();
}
async beginTransaction() {
// Nothing to do here.
}
async commitTransaction() {
// Nothing to do here.
}
async rollbackTransaction() {
// Nothing to do here.
}
async releaseConnection() {
// Nothing to do here.
}
async destroy() {
// Nothing to do here.
}
async releaseSavepoint() {
// Nothing to do here.
}
async rollbackToSavepoint() {
// Nothing to do here.
}
async savepoint() {
// Nothing to do here.
}
}
exports.DummyDriver = DummyDriver;
class DummyConnection {
async executeQuery() {
return {
rows: [],
};
}
async *streamQuery() {
// Nothing to do here.
}
}

View File

@@ -0,0 +1,47 @@
import type { QueryCompiler } from '../query-compiler/query-compiler.js';
import type { Log } from '../util/log.js';
import type { DatabaseConnection } from './database-connection.js';
import type { Driver, TransactionSettings } from './driver.js';
/**
* A small wrapper around {@link Driver} that makes sure the driver is
* initialized before it is used, only initialized and destroyed
* once etc.
*/
export declare class RuntimeDriver implements Driver {
#private;
constructor(driver: Driver, log: Log);
/**
* Initializes the driver.
*
* After calling this method the driver should be usable and `acquireConnection` etc.
* methods should be callable.
*/
init(): Promise<void>;
/**
* Acquires a new connection from the pool.
*/
acquireConnection(): Promise<DatabaseConnection>;
/**
* Releases a connection back to the pool.
*/
releaseConnection(connection: DatabaseConnection): Promise<void>;
/**
* Begins a transaction.
*/
beginTransaction(connection: DatabaseConnection, settings: TransactionSettings): Promise<void>;
/**
* Commits a transaction.
*/
commitTransaction(connection: DatabaseConnection): Promise<void>;
/**
* Rolls back a transaction.
*/
rollbackTransaction(connection: DatabaseConnection): Promise<void>;
savepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
rollbackToSavepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
releaseSavepoint(connection: DatabaseConnection, savepointName: string, compileQuery: QueryCompiler['compileQuery']): Promise<void>;
/**
* Destroys the driver and releases all resources.
*/
destroy(): Promise<void>;
}

165
node_modules/kysely/dist/cjs/driver/runtime-driver.js generated vendored Normal file
View File

@@ -0,0 +1,165 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RuntimeDriver = void 0;
const performance_now_js_1 = require("../util/performance-now.js");
/**
* A small wrapper around {@link Driver} that makes sure the driver is
* initialized before it is used, only initialized and destroyed
* once etc.
*/
class RuntimeDriver {
#driver;
#log;
#initPromise;
#initDone;
#destroyPromise;
#connections = new WeakSet();
constructor(driver, log) {
this.#initDone = false;
this.#driver = driver;
this.#log = log;
}
async init() {
if (this.#destroyPromise) {
throw new Error('driver has already been destroyed');
}
if (!this.#initPromise) {
this.#initPromise = this.#driver
.init()
.then(() => {
this.#initDone = true;
})
.catch((err) => {
this.#initPromise = undefined;
return Promise.reject(err);
});
}
await this.#initPromise;
}
async acquireConnection() {
if (this.#destroyPromise) {
throw new Error('driver has already been destroyed');
}
if (!this.#initDone) {
await this.init();
}
const connection = await this.#driver.acquireConnection();
if (!this.#connections.has(connection)) {
if (this.#needsLogging()) {
this.#addLogging(connection);
}
this.#connections.add(connection);
}
return connection;
}
async releaseConnection(connection) {
await this.#driver.releaseConnection(connection);
}
beginTransaction(connection, settings) {
return this.#driver.beginTransaction(connection, settings);
}
commitTransaction(connection) {
return this.#driver.commitTransaction(connection);
}
rollbackTransaction(connection) {
return this.#driver.rollbackTransaction(connection);
}
savepoint(connection, savepointName, compileQuery) {
if (this.#driver.savepoint) {
return this.#driver.savepoint(connection, savepointName, compileQuery);
}
throw new Error('The `savepoint` method is not supported by this driver');
}
rollbackToSavepoint(connection, savepointName, compileQuery) {
if (this.#driver.rollbackToSavepoint) {
return this.#driver.rollbackToSavepoint(connection, savepointName, compileQuery);
}
throw new Error('The `rollbackToSavepoint` method is not supported by this driver');
}
releaseSavepoint(connection, savepointName, compileQuery) {
if (this.#driver.releaseSavepoint) {
return this.#driver.releaseSavepoint(connection, savepointName, compileQuery);
}
throw new Error('The `releaseSavepoint` method is not supported by this driver');
}
async destroy() {
if (!this.#initPromise) {
return;
}
await this.#initPromise;
if (!this.#destroyPromise) {
this.#destroyPromise = this.#driver.destroy().catch((err) => {
this.#destroyPromise = undefined;
return Promise.reject(err);
});
}
await this.#destroyPromise;
}
#needsLogging() {
return (this.#log.isLevelEnabled('query') || this.#log.isLevelEnabled('error'));
}
// This method monkey patches the database connection's executeQuery method
// by adding logging code around it. Monkey patching is not pretty, but it's
// the best option in this case.
#addLogging(connection) {
const executeQuery = connection.executeQuery;
const streamQuery = connection.streamQuery;
const dis = this;
connection.executeQuery = async (compiledQuery) => {
let caughtError;
const startTime = (0, performance_now_js_1.performanceNow)();
try {
return await executeQuery.call(connection, compiledQuery);
}
catch (error) {
caughtError = error;
await dis.#logError(error, compiledQuery, startTime);
throw error;
}
finally {
if (!caughtError) {
await dis.#logQuery(compiledQuery, startTime);
}
}
};
connection.streamQuery = async function* (compiledQuery, chunkSize) {
let caughtError;
const startTime = (0, performance_now_js_1.performanceNow)();
try {
for await (const result of streamQuery.call(connection, compiledQuery, chunkSize)) {
yield result;
}
}
catch (error) {
caughtError = error;
await dis.#logError(error, compiledQuery, startTime);
throw error;
}
finally {
if (!caughtError) {
await dis.#logQuery(compiledQuery, startTime, true);
}
}
};
}
async #logError(error, compiledQuery, startTime) {
await this.#log.error(() => ({
level: 'error',
error,
query: compiledQuery,
queryDurationMillis: this.#calculateDurationMillis(startTime),
}));
}
async #logQuery(compiledQuery, startTime, isStream = false) {
await this.#log.query(() => ({
level: 'query',
isStream,
query: compiledQuery,
queryDurationMillis: this.#calculateDurationMillis(startTime),
}));
}
#calculateDurationMillis(startTime) {
return (0, performance_now_js_1.performanceNow)() - startTime;
}
}
exports.RuntimeDriver = RuntimeDriver;

View File

@@ -0,0 +1,11 @@
import type { DatabaseConnection } from './database-connection.js';
import type { ConnectionProvider } from './connection-provider.js';
export declare class SingleConnectionProvider implements ConnectionProvider {
#private;
constructor(connection: DatabaseConnection);
/**
* Provides a connection for the callback and takes care of disposing
* the connection after the callback has been run.
*/
provideConnection<T>(consumer: (connection: DatabaseConnection) => Promise<T>): Promise<T>;
}

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SingleConnectionProvider = void 0;
const ignoreError = () => { };
class SingleConnectionProvider {
#connection;
#runningPromise;
constructor(connection) {
this.#connection = connection;
}
async provideConnection(consumer) {
while (this.#runningPromise) {
await this.#runningPromise.catch(ignoreError);
}
// `#runningPromise` must be set to undefined before it's
// resolved or rejected. Otherwise the while loop above
// will misbehave.
this.#runningPromise = this.#run(consumer).finally(() => {
this.#runningPromise = undefined;
});
return this.#runningPromise;
}
// Run the runner in an async function to make sure it doesn't
// throw synchronous errors.
async #run(runner) {
return await runner(this.#connection);
}
}
exports.SingleConnectionProvider = SingleConnectionProvider;