@gravito/signal 1.0.0-beta.1 → 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # @gravito/signal
2
+
3
+ ## 1.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @gravito/core@1.0.0
9
+ - @gravito/stream@1.0.0
10
+ - @gravito/prism@1.0.0
@@ -0,0 +1,28 @@
1
+ import "./chunk-EBO3CZXG.mjs";
2
+
3
+ // src/renderers/ReactRenderer.ts
4
+ var ReactRenderer = class {
5
+ constructor(component, props, deps = {}) {
6
+ this.component = component;
7
+ this.props = props;
8
+ this.deps = deps;
9
+ }
10
+ async render(data) {
11
+ const createElement = this.deps.createElement ?? (await import("react")).createElement;
12
+ const renderToStaticMarkup = this.deps.renderToStaticMarkup ?? (await import("react-dom/server")).renderToStaticMarkup;
13
+ const mergedProps = { ...this.props, ...data };
14
+ const element = createElement(this.component, mergedProps);
15
+ const html = renderToStaticMarkup(element);
16
+ const fullHtml = html.startsWith("<!DOCTYPE") ? html : `<!DOCTYPE html>${html}`;
17
+ return {
18
+ html: fullHtml,
19
+ text: this.stripHtml(html)
20
+ };
21
+ }
22
+ stripHtml(html) {
23
+ return html.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
24
+ }
25
+ };
26
+ export {
27
+ ReactRenderer
28
+ };
@@ -0,0 +1,31 @@
1
+ import "./chunk-EBO3CZXG.mjs";
2
+
3
+ // src/renderers/VueRenderer.ts
4
+ var VueRenderer = class {
5
+ constructor(component, props, deps = {}) {
6
+ this.component = component;
7
+ this.props = props;
8
+ this.deps = deps;
9
+ }
10
+ async render(data) {
11
+ const createSSRApp = this.deps.createSSRApp ?? (await import("vue")).createSSRApp;
12
+ const h = this.deps.h ?? (await import("vue")).h;
13
+ const renderToString = this.deps.renderToString ?? (await import("./server-renderer-4W4FI7YG.mjs")).renderToString;
14
+ const mergedProps = { ...this.props, ...data };
15
+ const app = createSSRApp({
16
+ render: () => h(this.component, mergedProps)
17
+ });
18
+ const html = await renderToString(app);
19
+ const fullHtml = html.startsWith("<!DOCTYPE") ? html : `<!DOCTYPE html>${html}`;
20
+ return {
21
+ html: fullHtml,
22
+ text: this.stripHtml(html)
23
+ };
24
+ }
25
+ stripHtml(html) {
26
+ return html.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
27
+ }
28
+ };
29
+ export {
30
+ VueRenderer
31
+ };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Queueable } from '@gravito/stream';
2
2
  export { Queueable } from '@gravito/stream';
3
- import { GravitoOrbit, PlanetCore } from 'gravito-core';
3
+ import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
4
4
 
5
- declare module 'gravito-core' {
5
+ declare module '@gravito/core' {
6
6
  interface GravitoVariables {
7
7
  /** Mail service for sending emails */
8
8
  mail?: {
@@ -71,6 +71,14 @@ interface MailConfig {
71
71
  * Default: /__mail
72
72
  */
73
73
  devUiPrefix?: string | undefined;
74
+ /**
75
+ * Allow Dev UI in production. Default: false.
76
+ */
77
+ devUiAllowInProduction?: boolean | undefined;
78
+ /**
79
+ * Gate access to Dev UI (required in production unless allowInProduction is true).
80
+ */
81
+ devUiGate?: ((ctx: GravitoContext) => boolean | Promise<boolean>) | undefined;
74
82
  /**
75
83
  * Translation function for i18n support
76
84
  */
@@ -111,13 +119,14 @@ declare abstract class Mailable implements Queueable {
111
119
  protected renderer?: Renderer;
112
120
  private rendererResolver?;
113
121
  protected renderData: Record<string, unknown>;
122
+ protected config?: MailConfig;
114
123
  from(address: string | Address): this;
115
124
  to(address: string | Address | (string | Address)[]): this;
116
125
  cc(address: string | Address | (string | Address)[]): this;
117
126
  bcc(address: string | Address | (string | Address)[]): this;
118
127
  replyTo(address: string | Address): this;
119
128
  subject(subject: string): this;
120
- priority(level: 'high' | 'normal' | 'low'): this;
129
+ emailPriority(level: 'high' | 'normal' | 'low'): this;
121
130
  attach(attachment: Attachment): this;
122
131
  /**
123
132
  * Set the content using raw HTML string.
@@ -133,12 +142,19 @@ declare abstract class Mailable implements Queueable {
133
142
  * Set the content using a React component.
134
143
  * Dynamically imports ReactRenderer to avoid hard dependency errors if React is not installed.
135
144
  */
136
- react<P extends object>(component: ComponentType, props?: P): this;
145
+ react<P extends object>(component: ComponentType, props?: P, deps?: {
146
+ createElement?: (...args: any[]) => any;
147
+ renderToStaticMarkup?: (element: any) => string;
148
+ }): this;
137
149
  /**
138
150
  * Set the content using a Vue component.
139
151
  * Dynamically imports VueRenderer to avoid hard dependency errors if Vue is not installed.
140
152
  */
141
- vue<P extends object>(component: ComponentType, props?: P): this;
153
+ vue<P extends object>(component: ComponentType, props?: P, deps?: {
154
+ createSSRApp?: (...args: any[]) => any;
155
+ h?: (...args: any[]) => any;
156
+ renderToString?: (app: any) => Promise<string>;
157
+ }): this;
142
158
  /**
143
159
  * Setup the mailable. This is where you call from(), to(), view(), etc.
144
160
  */
@@ -146,9 +162,11 @@ declare abstract class Mailable implements Queueable {
146
162
  queueName?: string;
147
163
  connectionName?: string;
148
164
  delaySeconds?: number;
165
+ priority?: number | string;
149
166
  onQueue(queue: string): this;
150
167
  onConnection(connection: string): this;
151
168
  delay(seconds: number): this;
169
+ withPriority(priority: string | number): this;
152
170
  /**
153
171
  * Queue the mailable for sending.
154
172
  */
@@ -182,24 +200,10 @@ declare abstract class Mailable implements Queueable {
182
200
  }
183
201
 
184
202
  declare class OrbitSignal implements GravitoOrbit {
185
- private static instance?;
186
203
  private config;
187
204
  private devMailbox?;
205
+ private core?;
188
206
  constructor(config?: MailConfig);
189
- /**
190
- * Get the singleton instance of OrbitSignal
191
- *
192
- * @returns The singleton instance of OrbitSignal.
193
- * @throws {Error} If OrbitSignal has not been initialized.
194
- */
195
- static getInstance(): OrbitSignal;
196
- /**
197
- * Configure the OrbitSignal instance
198
- *
199
- * @param config - The mail configuration object.
200
- * @returns A new instance of OrbitSignal.
201
- */
202
- static configure(config: MailConfig): OrbitSignal;
203
207
  /**
204
208
  * Install the orbit into PlanetCore
205
209
  *
@@ -216,12 +220,6 @@ declare class OrbitSignal implements GravitoOrbit {
216
220
  send(mailable: Mailable): Promise<void>;
217
221
  /**
218
222
  * Queue a mailable instance
219
- *
220
- * Push a mailable into the queue for execution.
221
- * Requires OrbitStream to be installed and available in the context.
222
- *
223
- * @param mailable - The mailable object to queue.
224
- * @returns A promise that resolves when the job is pushed to the queue or sent immediately if no queue service is found.
225
223
  */
226
224
  queue(mailable: Mailable): Promise<void>;
227
225
  }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Queueable } from '@gravito/stream';
2
2
  export { Queueable } from '@gravito/stream';
3
- import { GravitoOrbit, PlanetCore } from 'gravito-core';
3
+ import { GravitoContext, GravitoOrbit, PlanetCore } from '@gravito/core';
4
4
 
5
- declare module 'gravito-core' {
5
+ declare module '@gravito/core' {
6
6
  interface GravitoVariables {
7
7
  /** Mail service for sending emails */
8
8
  mail?: {
@@ -71,6 +71,14 @@ interface MailConfig {
71
71
  * Default: /__mail
72
72
  */
73
73
  devUiPrefix?: string | undefined;
74
+ /**
75
+ * Allow Dev UI in production. Default: false.
76
+ */
77
+ devUiAllowInProduction?: boolean | undefined;
78
+ /**
79
+ * Gate access to Dev UI (required in production unless allowInProduction is true).
80
+ */
81
+ devUiGate?: ((ctx: GravitoContext) => boolean | Promise<boolean>) | undefined;
74
82
  /**
75
83
  * Translation function for i18n support
76
84
  */
@@ -111,13 +119,14 @@ declare abstract class Mailable implements Queueable {
111
119
  protected renderer?: Renderer;
112
120
  private rendererResolver?;
113
121
  protected renderData: Record<string, unknown>;
122
+ protected config?: MailConfig;
114
123
  from(address: string | Address): this;
115
124
  to(address: string | Address | (string | Address)[]): this;
116
125
  cc(address: string | Address | (string | Address)[]): this;
117
126
  bcc(address: string | Address | (string | Address)[]): this;
118
127
  replyTo(address: string | Address): this;
119
128
  subject(subject: string): this;
120
- priority(level: 'high' | 'normal' | 'low'): this;
129
+ emailPriority(level: 'high' | 'normal' | 'low'): this;
121
130
  attach(attachment: Attachment): this;
122
131
  /**
123
132
  * Set the content using raw HTML string.
@@ -133,12 +142,19 @@ declare abstract class Mailable implements Queueable {
133
142
  * Set the content using a React component.
134
143
  * Dynamically imports ReactRenderer to avoid hard dependency errors if React is not installed.
135
144
  */
136
- react<P extends object>(component: ComponentType, props?: P): this;
145
+ react<P extends object>(component: ComponentType, props?: P, deps?: {
146
+ createElement?: (...args: any[]) => any;
147
+ renderToStaticMarkup?: (element: any) => string;
148
+ }): this;
137
149
  /**
138
150
  * Set the content using a Vue component.
139
151
  * Dynamically imports VueRenderer to avoid hard dependency errors if Vue is not installed.
140
152
  */
141
- vue<P extends object>(component: ComponentType, props?: P): this;
153
+ vue<P extends object>(component: ComponentType, props?: P, deps?: {
154
+ createSSRApp?: (...args: any[]) => any;
155
+ h?: (...args: any[]) => any;
156
+ renderToString?: (app: any) => Promise<string>;
157
+ }): this;
142
158
  /**
143
159
  * Setup the mailable. This is where you call from(), to(), view(), etc.
144
160
  */
@@ -146,9 +162,11 @@ declare abstract class Mailable implements Queueable {
146
162
  queueName?: string;
147
163
  connectionName?: string;
148
164
  delaySeconds?: number;
165
+ priority?: number | string;
149
166
  onQueue(queue: string): this;
150
167
  onConnection(connection: string): this;
151
168
  delay(seconds: number): this;
169
+ withPriority(priority: string | number): this;
152
170
  /**
153
171
  * Queue the mailable for sending.
154
172
  */
@@ -182,24 +200,10 @@ declare abstract class Mailable implements Queueable {
182
200
  }
183
201
 
184
202
  declare class OrbitSignal implements GravitoOrbit {
185
- private static instance?;
186
203
  private config;
187
204
  private devMailbox?;
205
+ private core?;
188
206
  constructor(config?: MailConfig);
189
- /**
190
- * Get the singleton instance of OrbitSignal
191
- *
192
- * @returns The singleton instance of OrbitSignal.
193
- * @throws {Error} If OrbitSignal has not been initialized.
194
- */
195
- static getInstance(): OrbitSignal;
196
- /**
197
- * Configure the OrbitSignal instance
198
- *
199
- * @param config - The mail configuration object.
200
- * @returns A new instance of OrbitSignal.
201
- */
202
- static configure(config: MailConfig): OrbitSignal;
203
207
  /**
204
208
  * Install the orbit into PlanetCore
205
209
  *
@@ -216,12 +220,6 @@ declare class OrbitSignal implements GravitoOrbit {
216
220
  send(mailable: Mailable): Promise<void>;
217
221
  /**
218
222
  * Queue a mailable instance
219
- *
220
- * Push a mailable into the queue for execution.
221
- * Requires OrbitStream to be installed and available in the context.
222
- *
223
- * @param mailable - The mailable object to queue.
224
- * @returns A promise that resolves when the job is pushed to the queue or sent immediately if no queue service is found.
225
223
  */
226
224
  queue(mailable: Mailable): Promise<void>;
227
225
  }