@getstrata/bootstrap 0.2.4 → 0.2.5
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/bootstrap/web/session.d.ts +1 -0
- package/dist/core/admin/formatValue.d.ts +3 -0
- package/dist/core/admin/index.d.ts +3 -0
- package/dist/core/admin/registry.d.ts +10 -0
- package/dist/core/admin/types.d.ts +24 -0
- package/dist/core/database/baseRepository.d.ts +4 -1
- package/dist/core/database/index.d.ts +2 -2
- package/dist/core/database/relationships.d.ts +46 -2
- package/dist/core/database/repositoryQuery.d.ts +4 -1
- package/dist/core/mail/mailer.d.ts +3 -1
- package/dist/core/mail/markdownMail.d.ts +15 -0
- package/dist/core/mail/markdownMailable.d.ts +12 -0
- package/dist/core/notifications/dispatcher.d.ts +13 -0
- package/dist/core/notifications/index.d.ts +3 -0
- package/dist/core/notifications/notification.d.ts +7 -0
- package/dist/core/notifications/types.d.ts +25 -0
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/core/queue/publicQueue.d.ts +2 -1
- package/dist/framework/public-api.d.ts +12 -4
- package/dist/index.js +152 -5
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AdminResource, AdminResourceDefinition } from "./types.ts";
|
|
2
|
+
declare class AdminResourceRegistry {
|
|
3
|
+
private readonly resources;
|
|
4
|
+
register<TEntity extends object>(resource: AdminResource<TEntity>): void;
|
|
5
|
+
get(name: string): AdminResource<object> | undefined;
|
|
6
|
+
list(): AdminResourceDefinition[];
|
|
7
|
+
all(): AdminResource<object>[];
|
|
8
|
+
clear(): void;
|
|
9
|
+
}
|
|
10
|
+
export { AdminResourceRegistry };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PaginatedResult } from "../pagination/index.ts";
|
|
2
|
+
type AdminColumnType = "text" | "number" | "boolean" | "datetime" | "code";
|
|
3
|
+
interface AdminColumn {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
type?: AdminColumnType;
|
|
7
|
+
}
|
|
8
|
+
interface AdminResourceHandlers<TEntity extends object> {
|
|
9
|
+
paginate(options: {
|
|
10
|
+
page: number;
|
|
11
|
+
perPage: number;
|
|
12
|
+
}): Promise<PaginatedResult<TEntity>>;
|
|
13
|
+
findById?(id: number): Promise<TEntity | null>;
|
|
14
|
+
}
|
|
15
|
+
interface AdminResourceDefinition {
|
|
16
|
+
name: string;
|
|
17
|
+
label: string;
|
|
18
|
+
labelPlural: string;
|
|
19
|
+
columns: AdminColumn[];
|
|
20
|
+
}
|
|
21
|
+
interface AdminResource<TEntity extends object> extends AdminResourceDefinition {
|
|
22
|
+
handlers: AdminResourceHandlers<TEntity>;
|
|
23
|
+
}
|
|
24
|
+
export type { AdminColumn, AdminColumnType, AdminResource, AdminResourceDefinition, AdminResourceHandlers, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CursorPaginatedResult, type PaginatedResult } from "../pagination/index.ts";
|
|
2
|
-
import { type BelongsToRelation, type HasManyRelation } from "./relationships.ts";
|
|
2
|
+
import { type BelongsToRelation, type HasManyRelation, type MorphManyRelation, type MorphOneRelation, type MorphToRelation } from "./relationships.ts";
|
|
3
3
|
import { RepositoryQuery } from "./repositoryQuery.ts";
|
|
4
4
|
import type { TableDefinition } from "./table.ts";
|
|
5
5
|
import type { MutationValues, QueryOptions, QueryWhere, UpdateValues } from "./types.ts";
|
|
@@ -54,6 +54,9 @@ declare class BaseRepository<TEntity extends object, PrimaryKey extends keyof TE
|
|
|
54
54
|
findByHasManyRelation<TParent extends object, LocalKey extends keyof TParent & string, ForeignKey extends keyof TEntity & string>(relation: HasManyRelation<TParent, TEntity, LocalKey, ForeignKey>, parentId: TParent[LocalKey], options?: Omit<QueryOptions<TEntity>, "where">): Promise<TEntity[]>;
|
|
55
55
|
loadHasManyForParents<TParent extends object, LocalKey extends keyof TParent & string, ForeignKey extends keyof TEntity & string>(parents: readonly TParent[], relation: HasManyRelation<TParent, TEntity, LocalKey, ForeignKey>, options?: Omit<QueryOptions<TEntity>, "where">): Promise<Map<TParent[LocalKey], TEntity[]>>;
|
|
56
56
|
loadBelongsToForParents<TChild extends object, TParent extends object, ForeignKey extends keyof TChild & string, OwnerKey extends keyof TParent & string>(children: readonly TChild[], relation: BelongsToRelation<TChild, TParent, ForeignKey, OwnerKey>, parentRepository: BaseRepository<TParent, OwnerKey>, options?: Omit<QueryOptions<TParent>, "where">): Promise<Map<TChild[ForeignKey], TParent>>;
|
|
57
|
+
loadMorphManyForParents<TParent extends object, LocalKey extends keyof TParent & string, MorphTypeKey extends keyof TEntity & string, MorphIdKey extends keyof TEntity & string>(parents: readonly TParent[], relation: MorphManyRelation<TParent, TEntity, LocalKey, MorphTypeKey, MorphIdKey>, options?: Omit<QueryOptions<TEntity>, "where">): Promise<Map<TParent[LocalKey], TEntity[]>>;
|
|
58
|
+
loadMorphOneForParents<TParent extends object, LocalKey extends keyof TParent & string, MorphTypeKey extends keyof TEntity & string, MorphIdKey extends keyof TEntity & string>(parents: readonly TParent[], relation: MorphOneRelation<TParent, TEntity, LocalKey, MorphTypeKey, MorphIdKey>, options?: Omit<QueryOptions<TEntity>, "where">): Promise<Map<TParent[LocalKey], TEntity | undefined>>;
|
|
59
|
+
loadMorphToForChildren<TChild extends object, TParent extends object, MorphTypeKey extends keyof TChild & string, MorphIdKey extends keyof TChild & string, OwnerKey extends keyof TParent & string>(children: readonly TChild[], relation: MorphToRelation<TChild, MorphTypeKey, MorphIdKey>, repositoriesByType: ReadonlyMap<string, BaseRepository<TParent, OwnerKey>>, options?: Omit<QueryOptions<TParent>, "where">): Promise<Map<TChild[MorphIdKey], TParent>>;
|
|
57
60
|
}
|
|
58
61
|
export default BaseRepository;
|
|
59
62
|
export type { DatabaseConnection };
|
|
@@ -5,8 +5,8 @@ export { mapDatabaseError, withDatabaseErrorHandling } from "./errors.ts";
|
|
|
5
5
|
export type { CastType, GlobalScopeFn, ModelConstructor } from "./model.ts";
|
|
6
6
|
export { applyCasts, dehydrateValue, filterMassAssignable, hydrateValue, Model, registerModelRepository, } from "./model.ts";
|
|
7
7
|
export { buildAdvancedWhereClause, buildCountQuery, buildDeleteByIdQuery, buildGroupedCountQuery, buildInsertQuery, buildJoinClause, buildOrderByClause, buildProjectionQuery, buildQueryWhereClause, buildRestoreByIdQuery, buildSelectQuery, buildSoftDeleteByIdQuery, buildUpdateQuery, buildWhereClause, parseQualifiedColumn, qualifyColumn, quoteIdentifier, resolveQualifiedColumn, resolveSoftDeleteColumn, } from "./query.ts";
|
|
8
|
-
export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation, } from "./relationships.ts";
|
|
9
|
-
export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, } from "./relationships.ts";
|
|
8
|
+
export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation, MorphManyRelation, MorphOneRelation, MorphToRelation, } from "./relationships.ts";
|
|
9
|
+
export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, indexMorphManyRelation, indexMorphOneRelation, indexMorphToRelation, morphMany, morphOne, morphTo, } from "./relationships.ts";
|
|
10
10
|
export { RepositoryQuery } from "./repositoryQuery.ts";
|
|
11
11
|
export type { BlueprintAction, BlueprintCallback, ColumnKind, DatabaseDriver, ForeignKeyOptions, Grammar, IndexDefinition, IndexKind, ResolveDatabaseDriverOptions, SchemaBuilder, } from "./schema/index.ts";
|
|
12
12
|
export { Blueprint, ColumnDefinition, compileBlueprint, createSchemaBuilder, ForeignIdColumnDefinition, grammarForDriver, inferReferencedTable, MySqlGrammar, PostgresGrammar, resolveDatabaseDriver, Schema, SqliteGrammar, UnsupportedSchemaFeatureError, } from "./schema/index.ts";
|
|
@@ -52,5 +52,49 @@ declare function indexHasManyRelation<TParent, TChild, LocalKey extends keyof TP
|
|
|
52
52
|
declare function indexHasOneRelation<TParent, TChild, LocalKey extends keyof TParent & string, ForeignKey extends keyof TChild & string>(parents: readonly TParent[], children: readonly TChild[], relation: HasOneRelation<TParent, TChild, LocalKey, ForeignKey>): Map<TParent[LocalKey], TChild | undefined>;
|
|
53
53
|
declare function indexBelongsToRelation<TChild, TParent, ForeignKey extends keyof TChild & string, OwnerKey extends keyof TParent & string>(children: readonly TChild[], parents: readonly TParent[], relation: BelongsToRelation<TChild, TParent, ForeignKey, OwnerKey>): Map<TChild[ForeignKey], TParent>;
|
|
54
54
|
declare function indexBelongsToManyRelation<TParent, TRelated, Pivot extends object, ParentKey extends keyof TParent & string, RelatedKey extends keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string>(parents: readonly TParent[], pivotRows: readonly Pivot[], relatedRows: readonly TRelated[], relation: BelongsToManyRelation<TParent, TRelated, Pivot, ParentKey, RelatedKey, ForeignPivotKey, RelatedPivotKey>): Map<TParent[ParentKey], TRelated[]>;
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
interface MorphManyRelation<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, MorphTypeKey extends keyof TChild & string = keyof TChild & string, MorphIdKey extends keyof TChild & string = keyof TChild & string> {
|
|
56
|
+
type: "morphMany";
|
|
57
|
+
name: string;
|
|
58
|
+
localKey: LocalKey;
|
|
59
|
+
morphTypeKey: MorphTypeKey;
|
|
60
|
+
morphIdKey: MorphIdKey;
|
|
61
|
+
morphType: string;
|
|
62
|
+
}
|
|
63
|
+
interface MorphOneRelation<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, MorphTypeKey extends keyof TChild & string = keyof TChild & string, MorphIdKey extends keyof TChild & string = keyof TChild & string> {
|
|
64
|
+
type: "morphOne";
|
|
65
|
+
name: string;
|
|
66
|
+
localKey: LocalKey;
|
|
67
|
+
morphTypeKey: MorphTypeKey;
|
|
68
|
+
morphIdKey: MorphIdKey;
|
|
69
|
+
morphType: string;
|
|
70
|
+
}
|
|
71
|
+
interface MorphToRelation<TChild, MorphTypeKey extends keyof TChild & string = keyof TChild & string, MorphIdKey extends keyof TChild & string = keyof TChild & string> {
|
|
72
|
+
type: "morphTo";
|
|
73
|
+
name: string;
|
|
74
|
+
morphTypeKey: MorphTypeKey;
|
|
75
|
+
morphIdKey: MorphIdKey;
|
|
76
|
+
}
|
|
77
|
+
declare function morphMany<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, MorphTypeKey extends keyof TChild & string = keyof TChild & string, MorphIdKey extends keyof TChild & string = keyof TChild & string>(definition: {
|
|
78
|
+
name: string;
|
|
79
|
+
localKey: LocalKey;
|
|
80
|
+
morphTypeKey: MorphTypeKey;
|
|
81
|
+
morphIdKey: MorphIdKey;
|
|
82
|
+
morphType: string;
|
|
83
|
+
}): MorphManyRelation<TParent, TChild, LocalKey, MorphTypeKey, MorphIdKey>;
|
|
84
|
+
declare function morphOne<TParent, TChild, LocalKey extends keyof TParent & string = keyof TParent & string, MorphTypeKey extends keyof TChild & string = keyof TChild & string, MorphIdKey extends keyof TChild & string = keyof TChild & string>(definition: {
|
|
85
|
+
name: string;
|
|
86
|
+
localKey: LocalKey;
|
|
87
|
+
morphTypeKey: MorphTypeKey;
|
|
88
|
+
morphIdKey: MorphIdKey;
|
|
89
|
+
morphType: string;
|
|
90
|
+
}): MorphOneRelation<TParent, TChild, LocalKey, MorphTypeKey, MorphIdKey>;
|
|
91
|
+
declare function morphTo<TChild, MorphTypeKey extends keyof TChild & string = keyof TChild & string, MorphIdKey extends keyof TChild & string = keyof TChild & string>(definition: {
|
|
92
|
+
name: string;
|
|
93
|
+
morphTypeKey: MorphTypeKey;
|
|
94
|
+
morphIdKey: MorphIdKey;
|
|
95
|
+
}): MorphToRelation<TChild, MorphTypeKey, MorphIdKey>;
|
|
96
|
+
declare function indexMorphManyRelation<TParent, TChild, LocalKey extends keyof TParent & string, MorphTypeKey extends keyof TChild & string, MorphIdKey extends keyof TChild & string>(parents: readonly TParent[], children: readonly TChild[], relation: MorphManyRelation<TParent, TChild, LocalKey, MorphTypeKey, MorphIdKey>): Map<TParent[LocalKey], TChild[]>;
|
|
97
|
+
declare function indexMorphOneRelation<TParent, TChild, LocalKey extends keyof TParent & string, MorphTypeKey extends keyof TChild & string, MorphIdKey extends keyof TChild & string>(parents: readonly TParent[], children: readonly TChild[], relation: MorphOneRelation<TParent, TChild, LocalKey, MorphTypeKey, MorphIdKey>): Map<TParent[LocalKey], TChild | undefined>;
|
|
98
|
+
declare function indexMorphToRelation<TChild, TParent extends object, MorphTypeKey extends keyof TChild & string, MorphIdKey extends keyof TChild & string, OwnerKey extends keyof TParent & string>(children: readonly TChild[], parentsByType: ReadonlyMap<string, ReadonlyMap<TParent[OwnerKey], TParent>>, relation: MorphToRelation<TChild, MorphTypeKey, MorphIdKey>): Map<TChild[MorphIdKey], TParent>;
|
|
99
|
+
export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation, MorphManyRelation, MorphOneRelation, MorphToRelation, };
|
|
100
|
+
export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, indexMorphManyRelation, indexMorphOneRelation, indexMorphToRelation, morphMany, morphOne, morphTo, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PaginatedResult } from "../pagination/index.ts";
|
|
2
2
|
import type BaseRepository from "./baseRepository.ts";
|
|
3
|
-
import type { BelongsToRelation, HasManyRelation } from "./relationships.ts";
|
|
3
|
+
import type { BelongsToRelation, HasManyRelation, MorphManyRelation, MorphOneRelation, MorphToRelation } from "./relationships.ts";
|
|
4
4
|
import type { QueryOptions, QueryWhere } from "./types.ts";
|
|
5
5
|
import { WhereBuilder } from "./whereBuilder.ts";
|
|
6
6
|
type LoadedRow = Record<string, unknown>;
|
|
@@ -22,6 +22,9 @@ declare class RepositoryQuery<TEntity extends object, PrimaryKey extends keyof T
|
|
|
22
22
|
having(having: QueryWhere<TEntity>): this;
|
|
23
23
|
withHasMany<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasManyRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): this;
|
|
24
24
|
withBelongsTo<TParent extends object, ForeignKey extends keyof TEntity & string, OwnerKey extends keyof TParent & string, Alias extends string>(as: Alias, relation: BelongsToRelation<TEntity, TParent, ForeignKey, OwnerKey>, parentRepository: BaseRepository<TParent, OwnerKey>, options?: Omit<QueryOptions<TParent>, "where">): this;
|
|
25
|
+
withMorphMany<TChild extends object, LocalKey extends keyof TEntity & string, MorphTypeKey extends keyof TChild & string, MorphIdKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: MorphManyRelation<TEntity, TChild, LocalKey, MorphTypeKey, MorphIdKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): this;
|
|
26
|
+
withMorphOne<TChild extends object, LocalKey extends keyof TEntity & string, MorphTypeKey extends keyof TChild & string, MorphIdKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: MorphOneRelation<TEntity, TChild, LocalKey, MorphTypeKey, MorphIdKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): this;
|
|
27
|
+
withMorphTo<TParent extends object, MorphTypeKey extends keyof TEntity & string, MorphIdKey extends keyof TEntity & string, Alias extends string>(as: Alias, relation: MorphToRelation<TEntity, MorphTypeKey, MorphIdKey>, repositoriesByType: ReadonlyMap<string, BaseRepository<TParent, keyof TParent & string>>, options?: Omit<QueryOptions<TParent>, "where">): this;
|
|
25
28
|
get(): Promise<Array<TEntity & LoadedRow>>;
|
|
26
29
|
first(): Promise<(TEntity & LoadedRow) | null>;
|
|
27
30
|
paginate(options: {
|
|
@@ -2,6 +2,7 @@ interface MailMessage {
|
|
|
2
2
|
to: string;
|
|
3
3
|
subject: string;
|
|
4
4
|
body: string;
|
|
5
|
+
html?: string;
|
|
5
6
|
}
|
|
6
7
|
interface MailDriver {
|
|
7
8
|
send(message: MailMessage): Promise<void>;
|
|
@@ -16,6 +17,7 @@ interface SmtpConfig {
|
|
|
16
17
|
}
|
|
17
18
|
type SmtpTransport = (config: SmtpConfig, message: MailMessage) => Promise<void>;
|
|
18
19
|
declare function resolveSmtpConfig(): SmtpConfig;
|
|
20
|
+
declare function buildSmtpPayload(from: string, message: MailMessage): string;
|
|
19
21
|
declare class LogMailDriver implements MailDriver {
|
|
20
22
|
send(message: MailMessage): Promise<void>;
|
|
21
23
|
}
|
|
@@ -33,4 +35,4 @@ declare class Mailer {
|
|
|
33
35
|
declare function createMailDriver(): MailDriver;
|
|
34
36
|
declare function mailer(): Mailer;
|
|
35
37
|
export type { MailDriver, MailMessage, SmtpConfig, SmtpTransport };
|
|
36
|
-
export { createMailDriver, LogMailDriver, Mailer, mailer, resolveSmtpConfig, SmtpMailDriver };
|
|
38
|
+
export { buildSmtpPayload, createMailDriver, LogMailDriver, Mailer, mailer, resolveSmtpConfig, SmtpMailDriver, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface MarkdownMailLayoutOptions {
|
|
2
|
+
title?: string;
|
|
3
|
+
preview?: string;
|
|
4
|
+
footer?: string;
|
|
5
|
+
}
|
|
6
|
+
interface RenderedMarkdownMail {
|
|
7
|
+
html: string;
|
|
8
|
+
text: string;
|
|
9
|
+
}
|
|
10
|
+
declare function stripMarkdown(markdown: string): string;
|
|
11
|
+
declare function markdownToHtml(markdown: string): string;
|
|
12
|
+
declare function wrapMarkdownMailLayout(bodyHtml: string, options?: MarkdownMailLayoutOptions): string;
|
|
13
|
+
declare function renderMarkdownMail(markdown: string, options?: MarkdownMailLayoutOptions): RenderedMarkdownMail;
|
|
14
|
+
export type { MarkdownMailLayoutOptions, RenderedMarkdownMail };
|
|
15
|
+
export { markdownToHtml, renderMarkdownMail, stripMarkdown, wrapMarkdownMailLayout };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Mailer, MailMessage } from "./mailer.ts";
|
|
2
|
+
import { type MarkdownMailLayoutOptions } from "./markdownMail.ts";
|
|
3
|
+
interface MarkdownMailableInput {
|
|
4
|
+
to: string;
|
|
5
|
+
subject: string;
|
|
6
|
+
markdown: string;
|
|
7
|
+
layout?: MarkdownMailLayoutOptions;
|
|
8
|
+
}
|
|
9
|
+
declare function buildMarkdownMailMessage(input: MarkdownMailableInput): MailMessage;
|
|
10
|
+
declare function sendMarkdownMail(mailer: Mailer, input: MarkdownMailableInput): Promise<void>;
|
|
11
|
+
export type { MarkdownMailableInput };
|
|
12
|
+
export { buildMarkdownMailMessage, sendMarkdownMail };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Mailer } from "../mail/mailer.ts";
|
|
2
|
+
import type { Notification } from "./notification.ts";
|
|
3
|
+
import type { DatabaseNotificationStore, Notifiable } from "./types.ts";
|
|
4
|
+
declare class NotificationDispatcher {
|
|
5
|
+
private readonly mailer;
|
|
6
|
+
private readonly databaseStore;
|
|
7
|
+
constructor(mailer: Mailer, databaseStore?: DatabaseNotificationStore | null);
|
|
8
|
+
send(notifiable: Notifiable, notification: Notification): Promise<void>;
|
|
9
|
+
private sendMail;
|
|
10
|
+
private sendDatabase;
|
|
11
|
+
}
|
|
12
|
+
declare function createNotificationDispatcher(mailer: Mailer, databaseStore?: DatabaseNotificationStore): NotificationDispatcher;
|
|
13
|
+
export { createNotificationDispatcher, NotificationDispatcher };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createNotificationDispatcher, NotificationDispatcher } from "./dispatcher.ts";
|
|
2
|
+
export { Notification } from "./notification.ts";
|
|
3
|
+
export type { DatabaseNotificationPayload, DatabaseNotificationStore, MailNotificationMessage, Notifiable, NotificationChannelName, } from "./types.ts";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DatabaseNotificationPayload, MailNotificationMessage, NotificationChannelName } from "./types.ts";
|
|
2
|
+
declare abstract class Notification<TNotifiable = unknown> {
|
|
3
|
+
via(_notifiable: TNotifiable): NotificationChannelName[];
|
|
4
|
+
toMail(_notifiable: TNotifiable): MailNotificationMessage | null;
|
|
5
|
+
toDatabase(_notifiable: TNotifiable): DatabaseNotificationPayload | null;
|
|
6
|
+
}
|
|
7
|
+
export { Notification };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type NotificationChannelName = "mail" | "database";
|
|
2
|
+
interface MailNotificationMessage {
|
|
3
|
+
subject: string;
|
|
4
|
+
markdown?: string;
|
|
5
|
+
body?: string;
|
|
6
|
+
html?: string;
|
|
7
|
+
}
|
|
8
|
+
interface DatabaseNotificationPayload {
|
|
9
|
+
type: string;
|
|
10
|
+
title: string;
|
|
11
|
+
body: string;
|
|
12
|
+
data?: Record<string, unknown>;
|
|
13
|
+
notifiableType?: string | null;
|
|
14
|
+
notifiableId?: number | null;
|
|
15
|
+
}
|
|
16
|
+
interface DatabaseNotificationStore {
|
|
17
|
+
create(input: DatabaseNotificationPayload & {
|
|
18
|
+
userId: number;
|
|
19
|
+
}): Promise<Record<string, unknown>>;
|
|
20
|
+
}
|
|
21
|
+
interface Notifiable {
|
|
22
|
+
getNotificationKey(): string | number;
|
|
23
|
+
routeNotificationFor(channel: NotificationChannelName): string | number | null;
|
|
24
|
+
}
|
|
25
|
+
export type { DatabaseNotificationPayload, DatabaseNotificationStore, MailNotificationMessage, Notifiable, NotificationChannelName, };
|
|
@@ -10,6 +10,7 @@ declare class FailedJobService {
|
|
|
10
10
|
}): Promise<FailedJobRecord>;
|
|
11
11
|
listRecent(limit?: number): Promise<FailedJobRecord[]>;
|
|
12
12
|
retry(id: number): Promise<FailedJobRecord>;
|
|
13
|
+
delete(id: number): Promise<void>;
|
|
13
14
|
flush(): Promise<number>;
|
|
14
15
|
}
|
|
15
16
|
export default FailedJobService;
|
|
@@ -2,6 +2,7 @@ import FailedJobRepository from "./failedJobRepository.ts";
|
|
|
2
2
|
import FailedJobService from "./failedJobService.ts";
|
|
3
3
|
import type { Job, Queue } from "./index.ts";
|
|
4
4
|
import { jobRegistry } from "./jobRegistry.ts";
|
|
5
|
+
import { runQueueJob } from "./jobRunner.ts";
|
|
5
6
|
import { QueueWorker, RedisQueue } from "./redisQueue.ts";
|
|
6
7
|
import { ResilientQueue } from "./resilientQueue.ts";
|
|
7
8
|
declare function createFailedJobService(): FailedJobService;
|
|
@@ -12,4 +13,4 @@ declare function createProductionQueue(driver: "sync" | "async" | "redis", optio
|
|
|
12
13
|
registerJobs?: () => void;
|
|
13
14
|
}): Queue;
|
|
14
15
|
declare function createQueueWorker(redisUrl: string, failedJobs?: FailedJobService): QueueWorker;
|
|
15
|
-
export { createFailedJobService, createProductionQueue, createQueueWorker, createTrackedJob, FailedJobRepository, FailedJobService, jobRegistry, QueueWorker, RedisQueue, ResilientQueue, };
|
|
16
|
+
export { createFailedJobService, createProductionQueue, createQueueWorker, createTrackedJob, FailedJobRepository, FailedJobService, jobRegistry, QueueWorker, RedisQueue, ResilientQueue, runQueueJob, };
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
export { resolveApplicationAuth, resolveApplicationCache, resolveApplicationConfig, resolveApplicationDependencies, resolveApplicationLogger, resolveApplicationPolicyGate, resolveApplicationQueue, setActiveApplicationContext, } from "../bootstrap/applicationRegistry.ts";
|
|
6
6
|
export type { ServiceProvider } from "../bootstrap/contracts.ts";
|
|
7
7
|
export { ConfigStore, resolveService, ServiceContainer, } from "../bootstrap/contracts.ts";
|
|
8
|
+
export type { AdminColumn, AdminColumnType, AdminResource, AdminResourceDefinition, AdminResourceHandlers, } from "../core/admin/index.ts";
|
|
9
|
+
export { AdminResourceRegistry, formatAdminValue, } from "../core/admin/index.ts";
|
|
8
10
|
export type { AbilityChecker } from "../core/auth/abilityChecker.ts";
|
|
9
11
|
export type { AuthUser } from "../core/auth/authContext.ts";
|
|
10
12
|
export { currentAuthUser, runWithAuthUser } from "../core/auth/authContext.ts";
|
|
@@ -21,8 +23,8 @@ export { freshDatabase, getMigrationStatus, loadMigrationsFromDirectory, migrate
|
|
|
21
23
|
export type { Migration, MigrationDatabase, MigrationStatus, } from "../core/database/migrations/types.ts";
|
|
22
24
|
export type { CastType, GlobalScopeFn, ModelConstructor } from "../core/database/model.ts";
|
|
23
25
|
export { applyCasts, dehydrateValue, filterMassAssignable, hydrateValue, Model, registerModelRepository, } from "../core/database/model.ts";
|
|
24
|
-
export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation, } from "../core/database/relationships.ts";
|
|
25
|
-
export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, } from "../core/database/relationships.ts";
|
|
26
|
+
export type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation, MorphManyRelation, MorphOneRelation, MorphToRelation, } from "../core/database/relationships.ts";
|
|
27
|
+
export { belongsTo, belongsToMany, hasMany, hasOne, indexBelongsToManyRelation, indexBelongsToRelation, indexHasManyRelation, indexHasOneRelation, indexMorphManyRelation, indexMorphOneRelation, indexMorphToRelation, morphMany, morphOne, morphTo, } from "../core/database/relationships.ts";
|
|
26
28
|
export { RepositoryQuery } from "../core/database/repositoryQuery.ts";
|
|
27
29
|
export type { BlueprintAction, BlueprintCallback, ColumnKind, DatabaseDriver, ForeignKeyOptions, Grammar, IndexDefinition, IndexKind, ResolveDatabaseDriverOptions, SchemaBuilder, } from "../core/database/schema/index.ts";
|
|
28
30
|
export { Blueprint, ColumnDefinition, compileBlueprint, createSchemaBuilder, ForeignIdColumnDefinition, grammarForDriver, inferReferencedTable, MySqlGrammar, PostgresGrammar, resolveDatabaseDriver, Schema, SqliteGrammar, UnsupportedSchemaFeatureError, } from "../core/database/schema/index.ts";
|
|
@@ -56,13 +58,19 @@ export { createThrottleMiddleware } from "../core/http/throttleMiddleware.ts";
|
|
|
56
58
|
export { WebFormRequest } from "../core/http/webFormRequest.ts";
|
|
57
59
|
export { installGracefulShutdownSignals, registerShutdownHandler, runGracefulShutdown, } from "../core/lifecycle/gracefulShutdown.ts";
|
|
58
60
|
export type { MailDriver, MailMessage } from "../core/mail/mailer.ts";
|
|
59
|
-
export { LogMailDriver, Mailer, mailer } from "../core/mail/mailer.ts";
|
|
61
|
+
export { buildSmtpPayload, LogMailDriver, Mailer, mailer, } from "../core/mail/mailer.ts";
|
|
62
|
+
export type { MarkdownMailLayoutOptions, RenderedMarkdownMail } from "../core/mail/markdownMail.ts";
|
|
63
|
+
export { markdownToHtml, renderMarkdownMail, stripMarkdown, wrapMarkdownMailLayout, } from "../core/mail/markdownMail.ts";
|
|
64
|
+
export type { MarkdownMailableInput } from "../core/mail/markdownMailable.ts";
|
|
65
|
+
export { buildMarkdownMailMessage, sendMarkdownMail } from "../core/mail/markdownMailable.ts";
|
|
60
66
|
export type { MetricLabels } from "../core/metrics/prometheus.ts";
|
|
61
67
|
export { PrometheusRegistry, prometheusRegistry } from "../core/metrics/prometheus.ts";
|
|
68
|
+
export type { DatabaseNotificationPayload, DatabaseNotificationStore, MailNotificationMessage, Notifiable, NotificationChannelName, } from "../core/notifications/index.ts";
|
|
69
|
+
export { createNotificationDispatcher, Notification, NotificationDispatcher, } from "../core/notifications/index.ts";
|
|
62
70
|
export type { CursorPaginatedResult, PaginatedResult, PaginationMeta, } from "../core/pagination/index.ts";
|
|
63
71
|
export type { Queue, QueuePriority } from "../core/queue/index.ts";
|
|
64
72
|
export { AsyncQueue, createQueue, Job, SyncQueue } from "../core/queue/index.ts";
|
|
65
|
-
export { createFailedJobService, createProductionQueue, createQueueWorker, createTrackedJob, FailedJobRepository, FailedJobService, jobRegistry, QueueWorker, RedisQueue, ResilientQueue, } from "../core/queue/publicQueue.ts";
|
|
73
|
+
export { createFailedJobService, createProductionQueue, createQueueWorker, createTrackedJob, FailedJobRepository, FailedJobService, jobRegistry, QueueWorker, RedisQueue, ResilientQueue, runQueueJob, } from "../core/queue/publicQueue.ts";
|
|
66
74
|
export type { ScheduledTask } from "../core/scheduler/schedule.ts";
|
|
67
75
|
export { appSchedule, runDueScheduledTasks, Schedule } from "../core/scheduler/schedule.ts";
|
|
68
76
|
export type { StorageDriver } from "../core/storage/storage.ts";
|
package/dist/index.js
CHANGED
|
@@ -2347,6 +2347,39 @@ function indexBelongsToRelation(children, parents, relation) {
|
|
|
2347
2347
|
}
|
|
2348
2348
|
return result;
|
|
2349
2349
|
}
|
|
2350
|
+
function indexMorphManyRelation(parents, children, relation) {
|
|
2351
|
+
const groups = new Map;
|
|
2352
|
+
for (const parent of parents) {
|
|
2353
|
+
groups.set(parent[relation.localKey], []);
|
|
2354
|
+
}
|
|
2355
|
+
for (const child of children) {
|
|
2356
|
+
if (child[relation.morphTypeKey] !== relation.morphType) {
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
const key = child[relation.morphIdKey];
|
|
2360
|
+
const group = groups.get(key);
|
|
2361
|
+
if (!group) {
|
|
2362
|
+
continue;
|
|
2363
|
+
}
|
|
2364
|
+
group.push(child);
|
|
2365
|
+
}
|
|
2366
|
+
return groups;
|
|
2367
|
+
}
|
|
2368
|
+
function indexMorphToRelation(children, parentsByType, relation) {
|
|
2369
|
+
const result = new Map;
|
|
2370
|
+
for (const child of children) {
|
|
2371
|
+
const morphType = String(child[relation.morphTypeKey]);
|
|
2372
|
+
const parents = parentsByType.get(morphType);
|
|
2373
|
+
if (!parents) {
|
|
2374
|
+
continue;
|
|
2375
|
+
}
|
|
2376
|
+
const parent = parents.get(child[relation.morphIdKey]);
|
|
2377
|
+
if (parent) {
|
|
2378
|
+
result.set(child[relation.morphIdKey], parent);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
return result;
|
|
2382
|
+
}
|
|
2350
2383
|
|
|
2351
2384
|
// ../../src/core/database/boundConnection.ts
|
|
2352
2385
|
var boundConnectionHolder = {
|
|
@@ -2477,6 +2510,37 @@ class RepositoryQuery {
|
|
|
2477
2510
|
});
|
|
2478
2511
|
return this;
|
|
2479
2512
|
}
|
|
2513
|
+
withMorphMany(as, relation, childRepository, options = {}) {
|
|
2514
|
+
this.eagerLoads.push({
|
|
2515
|
+
kind: "morphMany",
|
|
2516
|
+
as,
|
|
2517
|
+
relation,
|
|
2518
|
+
repository: childRepository,
|
|
2519
|
+
options
|
|
2520
|
+
});
|
|
2521
|
+
return this;
|
|
2522
|
+
}
|
|
2523
|
+
withMorphOne(as, relation, childRepository, options = {}) {
|
|
2524
|
+
this.eagerLoads.push({
|
|
2525
|
+
kind: "morphOne",
|
|
2526
|
+
as,
|
|
2527
|
+
relation,
|
|
2528
|
+
repository: childRepository,
|
|
2529
|
+
options
|
|
2530
|
+
});
|
|
2531
|
+
return this;
|
|
2532
|
+
}
|
|
2533
|
+
withMorphTo(as, relation, repositoriesByType, options = {}) {
|
|
2534
|
+
this.eagerLoads.push({
|
|
2535
|
+
kind: "morphTo",
|
|
2536
|
+
as,
|
|
2537
|
+
relation,
|
|
2538
|
+
repository: this.repository,
|
|
2539
|
+
morphRepositories: repositoriesByType,
|
|
2540
|
+
options
|
|
2541
|
+
});
|
|
2542
|
+
return this;
|
|
2543
|
+
}
|
|
2480
2544
|
async get() {
|
|
2481
2545
|
const rows = await this.repository.findAll(this.buildOptions());
|
|
2482
2546
|
return await this.attach(rows);
|
|
@@ -2537,6 +2601,33 @@ class RepositoryQuery {
|
|
|
2537
2601
|
}));
|
|
2538
2602
|
continue;
|
|
2539
2603
|
}
|
|
2604
|
+
if (load.kind === "morphMany") {
|
|
2605
|
+
const relation2 = load.relation;
|
|
2606
|
+
const grouped2 = await load.repository.withConnection(this.repository.getConnection()).loadMorphManyForParents(rows, relation2, load.options);
|
|
2607
|
+
result = result.map((row) => ({
|
|
2608
|
+
...row,
|
|
2609
|
+
[load.as]: grouped2.get(row[relation2.localKey]) ?? []
|
|
2610
|
+
}));
|
|
2611
|
+
continue;
|
|
2612
|
+
}
|
|
2613
|
+
if (load.kind === "morphOne") {
|
|
2614
|
+
const relation2 = load.relation;
|
|
2615
|
+
const grouped2 = await load.repository.withConnection(this.repository.getConnection()).loadMorphOneForParents(rows, relation2, load.options);
|
|
2616
|
+
result = result.map((row) => ({
|
|
2617
|
+
...row,
|
|
2618
|
+
[load.as]: grouped2.get(row[relation2.localKey])
|
|
2619
|
+
}));
|
|
2620
|
+
continue;
|
|
2621
|
+
}
|
|
2622
|
+
if (load.kind === "morphTo") {
|
|
2623
|
+
const relation2 = load.relation;
|
|
2624
|
+
const grouped2 = await this.repository.loadMorphToForChildren(rows, relation2, load.morphRepositories ?? new Map, load.options);
|
|
2625
|
+
result = result.map((row) => ({
|
|
2626
|
+
...row,
|
|
2627
|
+
[load.as]: grouped2.get(row[relation2.morphIdKey])
|
|
2628
|
+
}));
|
|
2629
|
+
continue;
|
|
2630
|
+
}
|
|
2540
2631
|
const relation = load.relation;
|
|
2541
2632
|
const grouped = await this.repository.loadBelongsToForParents(rows, relation, load.repository, load.options);
|
|
2542
2633
|
result = result.map((row) => ({
|
|
@@ -2813,6 +2904,56 @@ class BaseRepository5 {
|
|
|
2813
2904
|
}, options);
|
|
2814
2905
|
return indexBelongsToRelation(children, parents, relation);
|
|
2815
2906
|
}
|
|
2907
|
+
async loadMorphManyForParents(parents, relation, options = {}) {
|
|
2908
|
+
if (parents.length === 0) {
|
|
2909
|
+
return indexMorphManyRelation(parents, [], relation);
|
|
2910
|
+
}
|
|
2911
|
+
const parentIds = [...new Set(parents.map((parent) => parent[relation.localKey]))];
|
|
2912
|
+
const children = await this.findWhere({
|
|
2913
|
+
[relation.morphTypeKey]: relation.morphType,
|
|
2914
|
+
[relation.morphIdKey]: parentIds
|
|
2915
|
+
}, options);
|
|
2916
|
+
return indexMorphManyRelation(parents, children, relation);
|
|
2917
|
+
}
|
|
2918
|
+
async loadMorphOneForParents(parents, relation, options = {}) {
|
|
2919
|
+
const grouped = await this.loadMorphManyForParents(parents, relation, options);
|
|
2920
|
+
const result = new Map;
|
|
2921
|
+
for (const parent of parents) {
|
|
2922
|
+
const matches = grouped.get(parent[relation.localKey]) ?? [];
|
|
2923
|
+
result.set(parent[relation.localKey], matches[0]);
|
|
2924
|
+
}
|
|
2925
|
+
return result;
|
|
2926
|
+
}
|
|
2927
|
+
async loadMorphToForChildren(children, relation, repositoriesByType, options = {}) {
|
|
2928
|
+
if (children.length === 0) {
|
|
2929
|
+
return new Map;
|
|
2930
|
+
}
|
|
2931
|
+
const idsByType = new Map;
|
|
2932
|
+
for (const child of children) {
|
|
2933
|
+
const morphType = String(child[relation.morphTypeKey]);
|
|
2934
|
+
const morphId = child[relation.morphIdKey];
|
|
2935
|
+
const ids = idsByType.get(morphType) ?? new Set;
|
|
2936
|
+
ids.add(morphId);
|
|
2937
|
+
idsByType.set(morphType, ids);
|
|
2938
|
+
}
|
|
2939
|
+
const parentsByType = new Map;
|
|
2940
|
+
for (const [morphType, ids] of idsByType) {
|
|
2941
|
+
const repository = repositoriesByType.get(morphType);
|
|
2942
|
+
if (!repository) {
|
|
2943
|
+
continue;
|
|
2944
|
+
}
|
|
2945
|
+
const ownerKey = repository.getTable().primaryKey;
|
|
2946
|
+
const parents = await repository.withConnection(this.connection).findWhere({
|
|
2947
|
+
[ownerKey]: [...ids]
|
|
2948
|
+
}, options);
|
|
2949
|
+
const indexed = new Map;
|
|
2950
|
+
for (const parent of parents) {
|
|
2951
|
+
indexed.set(parent[ownerKey], parent);
|
|
2952
|
+
}
|
|
2953
|
+
parentsByType.set(morphType, indexed);
|
|
2954
|
+
}
|
|
2955
|
+
return indexMorphToRelation(children, parentsByType, relation);
|
|
2956
|
+
}
|
|
2816
2957
|
}
|
|
2817
2958
|
var baseRepository_default = BaseRepository5;
|
|
2818
2959
|
// ../../src/core/database/model.ts
|
|
@@ -3429,6 +3570,12 @@ class FailedJobService {
|
|
|
3429
3570
|
await this.repository.deleteById(id);
|
|
3430
3571
|
return failedJob;
|
|
3431
3572
|
}
|
|
3573
|
+
async delete(id) {
|
|
3574
|
+
const deleted = await this.repository.deleteById(id);
|
|
3575
|
+
if (!deleted) {
|
|
3576
|
+
throw new Error(`Failed job ${id} not found.`);
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3432
3579
|
async flush() {
|
|
3433
3580
|
const jobs = await this.repository.findAll();
|
|
3434
3581
|
let deleted = 0;
|
|
@@ -3442,9 +3589,6 @@ class FailedJobService {
|
|
|
3442
3589
|
}
|
|
3443
3590
|
var failedJobService_default = FailedJobService;
|
|
3444
3591
|
|
|
3445
|
-
// ../../src/core/queue/redisQueue.ts
|
|
3446
|
-
var {RedisClient: RedisClient2 } = globalThis.Bun;
|
|
3447
|
-
|
|
3448
3592
|
// ../../src/core/queue/jobRunner.ts
|
|
3449
3593
|
async function runQueueJob(envelope, failedJobs) {
|
|
3450
3594
|
const job = jobRegistry.create(envelope.name);
|
|
@@ -3476,6 +3620,7 @@ async function runQueueJob(envelope, failedJobs) {
|
|
|
3476
3620
|
}
|
|
3477
3621
|
|
|
3478
3622
|
// ../../src/core/queue/redisQueue.ts
|
|
3623
|
+
var {RedisClient: RedisClient2 } = globalThis.Bun;
|
|
3479
3624
|
var QUEUE_LIST_KEY = "workhub:queue:default";
|
|
3480
3625
|
var QUEUE_HIGH_KEY = "workhub:queue:high";
|
|
3481
3626
|
var QUEUE_LOW_KEY = "workhub:queue:low";
|
|
@@ -5478,7 +5623,8 @@ class CookieSessionStore {
|
|
|
5478
5623
|
if (!sessionId || !signature || signature !== this.sign(sessionId)) {
|
|
5479
5624
|
return null;
|
|
5480
5625
|
}
|
|
5481
|
-
const rows = await this.sql.unsafe(`SELECT s.id, s.user_id, s.expires_at, u.name, u.email, u.learn_subscriber
|
|
5626
|
+
const rows = await this.sql.unsafe(`SELECT s.id, s.user_id, s.expires_at, u.name, u.email, u.learn_subscriber,
|
|
5627
|
+
COALESCE(u.is_admin, false) AS is_admin
|
|
5482
5628
|
FROM sessions s
|
|
5483
5629
|
INNER JOIN users u ON u.id = s.user_id
|
|
5484
5630
|
WHERE s.id = $1 AND s.expires_at > NOW()`, [sessionId]);
|
|
@@ -5489,7 +5635,8 @@ class CookieSessionStore {
|
|
|
5489
5635
|
id: row.user_id,
|
|
5490
5636
|
name: row.name,
|
|
5491
5637
|
email: row.email,
|
|
5492
|
-
learn_subscriber: row.learn_subscriber
|
|
5638
|
+
learn_subscriber: row.learn_subscriber,
|
|
5639
|
+
is_admin: row.is_admin
|
|
5493
5640
|
};
|
|
5494
5641
|
}
|
|
5495
5642
|
sign(value) {
|