@mrxsys/mrx-core 2.3.3-canary-20250514-a17e993

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.
Files changed (99) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE +21 -0
  3. package/README.md +20 -0
  4. package/dist/chunk-0pft81dh.js +2 -0
  5. package/dist/chunk-6sa6shm6.js +2 -0
  6. package/dist/chunk-7map0v4a.js +2 -0
  7. package/dist/chunk-dppgkz92.js +2 -0
  8. package/dist/chunk-kn1300vm.js +2 -0
  9. package/dist/chunk-nntk6mwx.js +2 -0
  10. package/dist/chunk-rr6e20n5.js +2 -0
  11. package/dist/chunk-s3xqwymw.js +2 -0
  12. package/dist/chunk-t411e41y.js +2 -0
  13. package/dist/chunk-wggj590m.js +2 -0
  14. package/dist/chunk-xcz2fxzt.js +2 -0
  15. package/dist/chunk-yeyzc9n2.js +2 -0
  16. package/dist/database/enums/databaseKeyError.d.ts +56 -0
  17. package/dist/database/enums/index.d.ts +2 -0
  18. package/dist/database/enums/index.js +2 -0
  19. package/dist/database/enums/mssqlErrorCode.d.ts +25 -0
  20. package/dist/database/events/index.d.ts +2 -0
  21. package/dist/database/events/index.js +2 -0
  22. package/dist/database/events/mssqlEvent.d.ts +3 -0
  23. package/dist/database/events/tableEvent.d.ts +6 -0
  24. package/dist/database/index.d.ts +5 -0
  25. package/dist/database/index.js +2 -0
  26. package/dist/database/mssql.d.ts +163 -0
  27. package/dist/database/table.d.ts +58 -0
  28. package/dist/database/types/index.d.ts +2 -0
  29. package/dist/database/types/index.js +1 -0
  30. package/dist/database/types/mssqlDatabaseOption.d.ts +92 -0
  31. package/dist/database/types/mssqlEventLog.d.ts +29 -0
  32. package/dist/elysia/advancedSearch.d.ts +460 -0
  33. package/dist/elysia/crud.d.ts +609 -0
  34. package/dist/elysia/dynamicDatabaseSelector.d.ts +352 -0
  35. package/dist/elysia/enums/elysiaKeyError.d.ts +16 -0
  36. package/dist/elysia/enums/httpStatusCode.d.ts +241 -0
  37. package/dist/elysia/enums/index.d.ts +2 -0
  38. package/dist/elysia/enums/index.js +2 -0
  39. package/dist/elysia/error.d.ts +50 -0
  40. package/dist/elysia/index.d.ts +7 -0
  41. package/dist/elysia/index.js +2 -0
  42. package/dist/elysia/jwt.d.ts +46 -0
  43. package/dist/elysia/microservice.d.ts +102 -0
  44. package/dist/elysia/ratelimit.d.ts +76 -0
  45. package/dist/elysia/schemas/index.d.ts +2 -0
  46. package/dist/elysia/schemas/index.js +2 -0
  47. package/dist/elysia/schemas/info.d.ts +9 -0
  48. package/dist/elysia/schemas/ping.d.ts +3 -0
  49. package/dist/elysia/types/crudOptions.d.ts +126 -0
  50. package/dist/elysia/types/crudRoutes.d.ts +2 -0
  51. package/dist/elysia/types/dynamicDatabaseSelectorPluginOptions.d.ts +30 -0
  52. package/dist/elysia/types/index.d.ts +5 -0
  53. package/dist/elysia/types/index.js +1 -0
  54. package/dist/elysia/types/jwtOptions.d.ts +92 -0
  55. package/dist/elysia/types/rateLimitOptions.d.ts +44 -0
  56. package/dist/error/coreError.d.ts +109 -0
  57. package/dist/error/index.d.ts +1 -0
  58. package/dist/error/index.js +2 -0
  59. package/dist/index.d.ts +18 -0
  60. package/dist/index.js +2 -0
  61. package/dist/mailer/enums/index.d.ts +1 -0
  62. package/dist/mailer/enums/index.js +2 -0
  63. package/dist/mailer/enums/mailerKeyError.d.ts +12 -0
  64. package/dist/mailer/index.d.ts +1 -0
  65. package/dist/mailer/index.js +2 -0
  66. package/dist/mailer/smtp.d.ts +62 -0
  67. package/dist/mailer/types/index.d.ts +3 -0
  68. package/dist/mailer/types/index.js +1 -0
  69. package/dist/mailer/types/smtpCredentials.d.ts +10 -0
  70. package/dist/mailer/types/smtpOptions.d.ts +26 -0
  71. package/dist/mailer/types/smtpPoolOptions.d.ts +7 -0
  72. package/dist/repository/index.d.ts +1 -0
  73. package/dist/repository/index.js +2 -0
  74. package/dist/repository/repository.d.ts +381 -0
  75. package/dist/repository/types/advancedSearch.d.ts +47 -0
  76. package/dist/repository/types/index.d.ts +8 -0
  77. package/dist/repository/types/index.js +1 -0
  78. package/dist/repository/types/orderBy.d.ts +21 -0
  79. package/dist/repository/types/queryOptions.d.ts +33 -0
  80. package/dist/repository/types/queryOptionsExtendPagination.d.ts +21 -0
  81. package/dist/repository/types/queryOptionsExtendStream.d.ts +16 -0
  82. package/dist/repository/types/selectedFields.d.ts +16 -0
  83. package/dist/repository/types/transaction.d.ts +10 -0
  84. package/dist/repository/types/whereClause.d.ts +15 -0
  85. package/dist/store/index.d.ts +1 -0
  86. package/dist/store/index.js +2 -0
  87. package/dist/store/redis.d.ts +6 -0
  88. package/dist/utils/enums/index.d.ts +1 -0
  89. package/dist/utils/enums/index.js +2 -0
  90. package/dist/utils/enums/utilKeyError.d.ts +8 -0
  91. package/dist/utils/env.d.ts +10 -0
  92. package/dist/utils/index.d.ts +3 -0
  93. package/dist/utils/index.js +2 -0
  94. package/dist/utils/isIsoDateString.d.ts +1 -0
  95. package/dist/utils/stream.d.ts +11 -0
  96. package/dist/utils/types/index.d.ts +1 -0
  97. package/dist/utils/types/index.js +1 -0
  98. package/dist/utils/types/streamWithAsyncIterable.d.ts +26 -0
  99. package/package.json +119 -0
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Represents the options for the Core error.
3
+ */
4
+ export interface CoreErrorOptions<T = unknown> {
5
+ /**
6
+ * The error message describing what went wrong.
7
+ */
8
+ message?: string;
9
+ /**
10
+ * A unique key identifying the type of error, useful for localization or error handling.
11
+ */
12
+ key?: string;
13
+ /**
14
+ * The HTTP status code associated with the error, typically used in API responses.
15
+ */
16
+ httpStatusCode?: number;
17
+ /**
18
+ * The cause of the error, which can be an original error or additional context.
19
+ */
20
+ cause?: T;
21
+ }
22
+ /**
23
+ * A custom error class that extends the native {@link Error} class, providing additional properties
24
+ * such as a unique identifier, error key, HTTP status code, and cause.
25
+ *
26
+ * @template T - The type of the cause of the error, which can be any object or error.
27
+ *
28
+ * @example
29
+ * The following example demonstrates how to throw and catch a CoreError.
30
+ * ```typescript
31
+ * try {
32
+ * throw new CoreError({
33
+ * message: 'An error occurred',
34
+ * key: 'example.error',
35
+ * httpStatusCode: 400,
36
+ * cause: new Error('Original error')
37
+ * });
38
+ * } catch (error) {
39
+ * if (error instanceof CoreError) {
40
+ * console.error(`Error UUID: ${error.uuid}`);
41
+ * console.error(`Error Date: ${error.date}`);
42
+ * console.error(`Error Key: ${error.key}`);
43
+ * console.error(`HTTP Status Code: ${error.httpStatusCode}`);
44
+ * console.error(`Cause: ${error.cause}`);
45
+ * }
46
+ * }
47
+ * ```
48
+ *
49
+ * @example
50
+ * The following example demonstrates how to create a CoreError with a custom cause type.
51
+ * ```typescript
52
+ * const coreError = new CoreError<{ foo: string }>({
53
+ * message: 'Custom error with cause',
54
+ * key: 'core-package.error.custom_error',
55
+ * httpStatusCode: 500,
56
+ * cause: { foo: 'bar' },
57
+ * });
58
+ * console.log(coreError.cause); // { foo: 'bar' }
59
+ * ```
60
+ */
61
+ export declare class CoreError<const T = unknown> extends Error {
62
+ /**
63
+ * The cause of the error, typically used to store the original error or additional context.
64
+ */
65
+ readonly cause: T | undefined;
66
+ /**
67
+ * The unique identifier of the error, automatically generated using UUID v7.
68
+ * This identifier is particularly useful for tracking errors in logs.
69
+ */
70
+ private readonly _uuid;
71
+ /**
72
+ * The date when the error was created, automatically set to the current date and time.
73
+ */
74
+ private readonly _date;
75
+ /**
76
+ * A unique key identifying the type of error, useful for localization or error handling.
77
+ */
78
+ private readonly _key;
79
+ /**
80
+ * The HTTP status code associated with the error, typically used in API responses.
81
+ */
82
+ private readonly _httpStatusCode;
83
+ /**
84
+ * Creates a new instance of the CoreError class.
85
+ *
86
+ * @param coreErrorOptions - The options for the Core error. ({@link CoreErrorOptions})
87
+ */
88
+ constructor(coreErrorOptions?: Readonly<CoreErrorOptions<T>>);
89
+ /**
90
+ * Gets the unique identifier of the error.
91
+ * @returns The UUID of the error.
92
+ */
93
+ get uuid(): string;
94
+ /**
95
+ * Gets the date when the error was created.
96
+ * @returns The creation date of the error.
97
+ */
98
+ get date(): Date;
99
+ /**
100
+ * Gets the error key, which identifies the type of error.
101
+ * @returns The key associated with the error.
102
+ */
103
+ get key(): string;
104
+ /**
105
+ * Gets the HTTP status code associated with the error.
106
+ * @returns The HTTP status code.
107
+ */
108
+ get httpStatusCode(): number;
109
+ }
@@ -0,0 +1 @@
1
+ export * from './coreError';
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{_ as e}from"../chunk-6sa6shm6.js";import"../chunk-rr6e20n5.js";export{e as CoreError};
@@ -0,0 +1,18 @@
1
+ export * from './database';
2
+ export * from './database/enums';
3
+ export * from './database/events';
4
+ export type * from './database/types';
5
+ export * from './elysia';
6
+ export * from './elysia/enums';
7
+ export * from './elysia/schemas';
8
+ export type * from './elysia/types';
9
+ export * from './error';
10
+ export * from './mailer';
11
+ export * from './mailer/enums';
12
+ export type * from './mailer/types';
13
+ export * from './repository';
14
+ export type * from './repository/types';
15
+ export * from './store';
16
+ export * from './utils';
17
+ export * from './utils/enums';
18
+ export type * from './utils/types';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import"./utils/enums/index.js";import"./error/index.js";import{a as P}from"./mailer/index.js";import"./mailer/enums/index.js";import{b as O}from"./chunk-s3xqwymw.js";import"./repository/index.js";import{c as Q}from"./store/index.js";import{d as S}from"./utils/index.js";import{e as R}from"./chunk-0pft81dh.js";import"./database/index.js";import"./database/enums/index.js";import"./database/events/index.js";import{f as v,g as w,h as z,i as B,j as C,k as F,l as G,m as H,n as I,o as L,p as N}from"./elysia/index.js";import"./chunk-kn1300vm.js";import{U as n,V as q}from"./chunk-wggj590m.js";import{W as j,X as k}from"./chunk-t411e41y.js";import{Y as g,Z as h}from"./chunk-7map0v4a.js";import{_ as c}from"./chunk-6sa6shm6.js";import{$ as d,aa as u}from"./chunk-dppgkz92.js";import{ba as D,ca as E}from"./chunk-yeyzc9n2.js";import"./elysia/enums/index.js";import{da as A,ea as M}from"./chunk-nntk6mwx.js";import"./elysia/schemas/index.js";import{fa as J,ga as K}from"./chunk-xcz2fxzt.js";import"./chunk-rr6e20n5.js";export{S as validateEnv,R as utilKeyError,E as tableEvent,N as rateLimitPlugin,K as pingResponse200Schema,j as operators,D as mssqlEvent,u as mssqlErrorCode,L as microservicePlugin,h as makeStreamAsyncIterable,O as mailerKeyError,I as jwtPlugin,g as isIsoDateString,J as infoResponse200Schema,M as httpStatusCode,H as errorPlugin,A as elysiaKeyError,B as dynamicDatabaseSelectorPlugin,d as databaseKeyError,G as crudPlugin,C as createResponse200Schema,F as createInsertBodySchema,w as createBaseSearchSchemaWithPagination,v as createBaseSearchSchema,z as advancedSearchPlugin,n as Table,P as SMTP,k as Repository,Q as Redis,q as MSSQL,c as CoreError};
@@ -0,0 +1 @@
1
+ export * from './mailerKeyError';
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{b as e}from"../../chunk-s3xqwymw.js";import"../../chunk-rr6e20n5.js";export{e as mailerKeyError};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Mailer error key is a list of errors in the mailer context.
3
+ * Each property represents a specific mailer error scenario.
4
+ */
5
+ export declare const mailerKeyError: {
6
+ /** Error when failing to connect to SMTP server. */
7
+ readonly smtpConnectionError: "core.error.mailer.smtp.connection_error";
8
+ /** Error when SMTP server is not connected. */
9
+ readonly smtpNotConnected: "core.error.mailer.smtp.not_connected";
10
+ /** Error when SMTP server is already connected. */
11
+ readonly smtpAlreadyConnected: "core.error.mailer.smtp.already_connected";
12
+ };
@@ -0,0 +1 @@
1
+ export * from './smtp';
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{b as z}from"../chunk-s3xqwymw.js";import{_ as q}from"../chunk-6sa6shm6.js";import"../chunk-rr6e20n5.js";import{createTransport as B}from"nodemailer";class D{_config;_transporter=null;constructor(x){this._config={port:587,secure:!1,...x}}async connect(){if(this._transporter)throw new q({key:z.smtpAlreadyConnected,message:"SMTP transporter is already connected."});this._transporter=B({host:this._config.host,port:this._config.port,secure:this._config.secure,auth:{user:this._config.credentials.user,pass:this._config.credentials.pass},pool:!0,maxConnections:this._config.pool?.maxConnections??5});try{await this._transporter.verify()}catch(x){throw new q({key:z.smtpConnectionError,message:"An error occurred while connecting to the SMTP server",cause:x})}}disconnect(){if(this._transporter)this._transporter.close(),this._transporter=null}async sendMail(x){if(!this._transporter)throw new q({key:z.smtpNotConnected,message:"SMTP transporter is not connected."});return this._transporter.sendMail(x)}}export{D as SMTP};export{D as a};
@@ -0,0 +1,62 @@
1
+ import { type SendMailOptions } from 'nodemailer';
2
+ import type { SMTPOptions } from './types/smtpOptions';
3
+ /**
4
+ * The `SMTP` class manages the connection and operations with an SMTP server.
5
+ *
6
+ * This class provides methods to connect, disconnect, and send emails using
7
+ * the Nodemailer library. It supports connection pooling and error handling ({@link CoreError}).
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const smtp = new SMTP({
12
+ * host: 'smtp.example.com',
13
+ * credentials: { user: 'user', pass: 'pass' }
14
+ * });
15
+ * await smtp.connect();
16
+ * await smtp.sendMail({ to: 'dest@example.com', subject: 'Hello', text: 'Hi!' });
17
+ * smtp.disconnect();
18
+ * ```
19
+ */
20
+ export declare class SMTP {
21
+ /**
22
+ * The configuration options for the SMTP connection.
23
+ */
24
+ private readonly _config;
25
+ /**
26
+ * The Nodemailer transporter instance for sending emails.
27
+ */
28
+ private _transporter;
29
+ /**
30
+ * Creates an instance of the SMTP class.
31
+ *
32
+ * @param config - The configuration options for the SMTP connection. (see {@link SMTPOptions}).
33
+ */
34
+ constructor(config: SMTPOptions);
35
+ /**
36
+ * Establishes a pool of connections to the SMTP server and verifies the connection.
37
+ *
38
+ * This method creates a Nodemailer transporter using the configuration provided to the class.
39
+ * It enables connection pooling for efficient resource usage and sets the maximum number of
40
+ * concurrent connections as specified in the configuration (default: 5).
41
+ *
42
+ * @throws ({@link CoreError}): If the transporter is already connected. ({@link mailerKeyError.smtpAlreadyConnected})
43
+ * @throws ({@link CoreError}): If the connection or verification fails. ({@link mailerKeyError.smtpConnectionError})
44
+ */
45
+ connect(): Promise<void>;
46
+ /**
47
+ * Closes the SMTP connection and releases resources.
48
+ *
49
+ * If the transporter is not connected, this method does nothing.
50
+ */
51
+ disconnect(): void;
52
+ /**
53
+ * Sends an email using the established SMTP connection.
54
+ *
55
+ * @param options - The mail options, such as recipient, subject, and content.
56
+ *
57
+ * @throws ({@link CoreError}) - If the transporter is not connected. ({@link mailerKeyError.smtpNotConnected})
58
+ *
59
+ * @returns A promise resolving to the result of the send operation.
60
+ */
61
+ sendMail(options: SendMailOptions): Promise<unknown>;
62
+ }
@@ -0,0 +1,3 @@
1
+ export type * from './smtpCredentials';
2
+ export type * from './smtpOptions';
3
+ export type * from './smtpPoolOptions';
@@ -0,0 +1 @@
1
+ // @bun
@@ -0,0 +1,10 @@
1
+ export interface SMTPCredentials {
2
+ /**
3
+ * The username for SMTP authentication.
4
+ */
5
+ user: string;
6
+ /**
7
+ * The password for SMTP authentication.
8
+ */
9
+ pass: string;
10
+ }
@@ -0,0 +1,26 @@
1
+ import type { SMTPCredentials } from './smtpCredentials';
2
+ import type { SMTPPoolOptions } from './smtpPoolOptions';
3
+ export interface SMTPOptions {
4
+ /**
5
+ * The hostname or IP address of the SMTP server.
6
+ */
7
+ host: string;
8
+ /**
9
+ * The port number to connect to.
10
+ * @defaultValue 587
11
+ */
12
+ port?: number;
13
+ /**
14
+ * Whether to use a secure (TLS) connection.
15
+ * @defaultValue false
16
+ */
17
+ secure?: boolean;
18
+ /**
19
+ * The credentials for SMTP authentication.
20
+ */
21
+ credentials: SMTPCredentials;
22
+ /**
23
+ * Optional pool configuration.
24
+ */
25
+ pool?: SMTPPoolOptions;
26
+ }
@@ -0,0 +1,7 @@
1
+ export interface SMTPPoolOptions {
2
+ /**
3
+ * The maximum number of concurrent SMTP connections.
4
+ * @defaultValue 5
5
+ */
6
+ maxConnections?: number;
7
+ }
@@ -0,0 +1 @@
1
+ export * from './repository';
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{W as e,X as f}from"../chunk-t411e41y.js";import"../chunk-7map0v4a.js";import"../chunk-6sa6shm6.js";import"../chunk-dppgkz92.js";import"../chunk-rr6e20n5.js";export{e as operators,f as Repository};