@seip/bluebird-js 0.1.1 → 0.1.4

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 (49) hide show
  1. package/.vscode/extensions.json +7 -0
  2. package/.vscode/settings.json +10 -0
  3. package/AGENTS.md +124 -64
  4. package/README.md +236 -103
  5. package/app/routes/web.js +47 -55
  6. package/app/views/about.jsx +98 -0
  7. package/app/views/components/Header.jsx +42 -0
  8. package/app/views/components/LiveCounter.jsx +67 -0
  9. package/app/views/dashboard.jsx +300 -0
  10. package/app/views/index.jsx +123 -0
  11. package/app/views/layouts/main/view.jsx +201 -0
  12. package/app/views/legal/terms.html +29 -19
  13. package/app/views/login.jsx +141 -0
  14. package/core/actions.d.ts +4 -0
  15. package/core/actions.js +329 -0
  16. package/core/app.js +129 -22
  17. package/core/auth.js +1 -1
  18. package/core/cli/doctor.js +3 -4
  19. package/core/cli/init.js +153 -6
  20. package/core/cli/migrate.js +418 -145
  21. package/core/cli/view.js +76 -11
  22. package/core/config.js +35 -5
  23. package/core/csrf.js +1 -1
  24. package/core/database.js +52 -17
  25. package/core/debug.js +1 -1
  26. package/core/html.d.ts +54 -42
  27. package/core/html.js +473 -217
  28. package/core/index.d.ts +187 -85
  29. package/core/jsx.d.ts +38 -0
  30. package/core/jsx.js +1180 -0
  31. package/core/model.js +282 -61
  32. package/core/queue.js +7 -4
  33. package/core/render-cache.js +212 -212
  34. package/core/render.d.ts +20 -2
  35. package/core/render.js +320 -43
  36. package/core/upload.js +7 -1
  37. package/core/validate.js +1 -1
  38. package/core/view-loader.js +341 -19
  39. package/core/vite.js +1 -1
  40. package/package.json +9 -3
  41. package/public/js/bluebird-client.js +2313 -1049
  42. package/public/js/tailwind.js +8 -0
  43. package/app/views/about.js +0 -63
  44. package/app/views/dashboard.js +0 -147
  45. package/app/views/index.js +0 -80
  46. package/app/views/layouts/main/view.js +0 -81
  47. package/app/views/login.js +0 -80
  48. package/public/css/bluebird.min.css +0 -2
  49. package/public/js/bluebird.min.js +0 -1073
package/core/index.d.ts CHANGED
@@ -256,8 +256,12 @@ export interface AppOptions {
256
256
  compression?: boolean;
257
257
  security?: boolean | SecurityHeadersOptions;
258
258
  rateLimit?: boolean | RateLimitOptions;
259
+ autoRoutes?: boolean;
260
+ noAutoDiscoverRoutes?: boolean;
259
261
  desktop?: boolean;
260
262
  userDataPath?: string;
263
+ appPath?: string;
264
+ allowLan?: boolean;
261
265
  trustProxy?: boolean | number | string;
262
266
  }
263
267
 
@@ -274,6 +278,7 @@ export class App {
274
278
  logger: boolean;
275
279
  notFound: boolean;
276
280
  desktop: boolean;
281
+ allowLan: boolean;
277
282
  trustProxy: boolean | number | string;
278
283
 
279
284
  constructor(options?: AppOptions);
@@ -288,7 +293,13 @@ export class App {
288
293
  getPort(): number;
289
294
  getUrl(): string;
290
295
  run(): Promise<any>;
291
- runDesktop(): Promise<{ server: HttpServer; port: number; url: string }>;
296
+ runDesktop(options?: {
297
+ appPath?: string;
298
+ userDataPath?: string;
299
+ allowLan?: boolean;
300
+ host?: string;
301
+ port?: number;
302
+ }): Promise<{ server: HttpServer; port: number; url: string; lanUrl?: string; lanIp?: string }>;
292
303
  close(): Promise<void>;
293
304
 
294
305
  static helmet(options?: any): (req: Request, res: Response, next: NextFunction) => void;
@@ -497,29 +508,115 @@ export class Cache {
497
508
  export function getRedisClient(): any;
498
509
 
499
510
  /**
500
- * Render island options.
511
+ * Render island / client component options.
501
512
  */
502
513
  export interface RenderIslandOptions {
503
514
  persist?: boolean;
504
- fallback?: string;
515
+ persistent?: boolean;
516
+ fallback?: any;
517
+ skeleton?: any;
518
+ minHeight?: string | number;
519
+ minWidth?: string | number;
520
+ className?: string;
521
+ style?: Record<string, any> | string;
522
+ ssr?: boolean;
505
523
  tag?: string;
524
+ client?: Function;
525
+ onMount?: Function;
526
+ }
527
+
528
+ /**
529
+ * Server Action definition options.
530
+ */
531
+ export interface ActionDefinitionOptions {
532
+ schema?: ValidationSchema | Validator;
533
+ maxBytes?: number | string;
534
+ limit?: number | string;
535
+ maxDepth?: number;
536
+ maxKeys?: number;
537
+ csrf?: boolean;
538
+ }
539
+
540
+ /**
541
+ * Server Action execution context.
542
+ */
543
+ export interface ActionContext<TBody = Record<string, any>> {
544
+ req: Request;
545
+ res: Response;
546
+ user?: any;
547
+ body: TBody;
548
+ params: Record<string, string>;
549
+ query: Record<string, any>;
550
+ action: string;
551
+ }
552
+
553
+ export class Actions {
554
+ static define<TBody = Record<string, any>, TResult = any>(
555
+ optionsOrHandler: ActionDefinitionOptions | ((ctx: ActionContext<TBody>, body: TBody) => Promise<TResult> | TResult),
556
+ handlerFn?: (ctx: ActionContext<TBody>, body: TBody) => Promise<TResult> | TResult
557
+ ): any;
558
+ static createDispatcher(viewName: string, actionsMap: Record<string, any>): (req: Request, res: Response) => Promise<any>;
559
+ }
560
+
561
+ /**
562
+ * Props for `<Island>` / `<Client>` JSX components.
563
+ */
564
+ export interface IslandComponentProps extends RenderIslandOptions {
565
+ component?: string | Function;
566
+ name?: string;
567
+ props?: Record<string, any>;
568
+ children?: any;
569
+ [key: string]: any;
570
+ }
571
+
572
+ export function h(type: any, props?: Record<string, any> | null, ...children: any[]): any;
573
+ export function createElement(type: any, props?: Record<string, any> | null, ...children: any[]): any;
574
+ export function jsx(type: any, props: Record<string, any>, key?: string | number): any;
575
+ export function jsxs(type: any, props: Record<string, any>, key?: string | number): any;
576
+ export const Fragment: symbol;
577
+ export function Island(options?: IslandComponentProps): Promise<any>;
578
+ export function Client(options?: IslandComponentProps): Promise<any>;
579
+ export function isJsxElement(val: any): boolean;
580
+ export function renderJsxToString(node: any, ctx?: Record<string, any>): Promise<string>;
581
+ export function compileJsx(source: string): string;
582
+ export function registerJsxLoader(): void;
583
+ export function useState<T>(initial?: T | (() => T)): [T, (value: T | ((prev: T) => T)) => void];
584
+ export function useEffect(effectFn: () => void | (() => void), deps?: any[]): void;
585
+ export function useRef<T>(initial?: T): { current: T };
586
+ export function useMemo<T>(fn: () => T, deps?: any[]): T;
587
+ export function useCallback<T extends (...args: any[]) => any>(fn: T, deps?: any[]): T;
588
+
589
+ /**
590
+ * Options for serving raw static HTML files.
591
+ */
592
+ export interface RenderHtmlOptions {
593
+ ttl?: number;
506
594
  }
507
595
 
508
596
  export class Render {
509
597
  static island(
510
- name: string,
598
+ name: string | Function,
511
599
  props?: Record<string, any>,
512
600
  options?: RenderIslandOptions
513
601
  ): string;
514
602
  static component(partialName: string, props?: Record<string, any>): Promise<string>;
515
- static html(res: Response, relativePath: string, options?: { ttl?: number }): Promise<void>;
603
+ static html(res: Response, relativePath: string, options?: RenderHtmlOptions): Promise<void>;
516
604
  static send(res: Response, viewName: string, data?: Record<string, any>, ttl?: number): Promise<void>;
517
605
  static partial(res: Response, partialName: string, data?: Record<string, any>, ttl?: number): Promise<void>;
518
606
  static stream(res: Response, viewName: string, data?: Record<string, any>): Promise<void>;
519
- static view(viewName: string, staticData?: Record<string, any>): (req: Request, res: Response) => void;
520
- static cache(seconds?: number): (req: Request, res: Response, next: NextFunction) => Promise<any>;
607
+ static view(
608
+ viewName: string,
609
+ dataOrFn?: Record<string, any> | ((req: Request, res: Response) => any),
610
+ ttl?: number
611
+ ): (req: Request, res: Response) => Promise<void>;
612
+ static cache(
613
+ seconds?: number,
614
+ options?: { allowAuthenticated?: boolean }
615
+ ): (req: Request, res: Response, next: NextFunction) => Promise<any>;
616
+ static redirect(req: Request, res: Response, url: string, status?: number): void;
521
617
  static clearTemplateCache(): void;
522
618
  static invalidate(keys?: string | string[]): Promise<void>;
619
+ static autoRoutes(targetRouter?: Router): Promise<Array<{ viewName: string; routePath: string; cache: number; seo: boolean }>>;
523
620
  }
524
621
 
525
622
  export * from "./html.js";
@@ -581,6 +678,7 @@ export class Database {
581
678
  transaction<T = any>(callback: (tx: DatabaseTransactionClient) => Promise<T>): Promise<T>;
582
679
  executeTransaction<T = any>(callback: (tx: DatabaseTransactionClient) => Promise<T>): Promise<T>;
583
680
  close(): Promise<void>;
681
+ static closeAll(): Promise<void>;
584
682
  }
585
683
 
586
684
  /**
@@ -643,6 +741,7 @@ export interface ModelSchemaColumn {
643
741
  hash?: boolean;
644
742
  in?: any[];
645
743
  references?: string;
744
+ onDelete?: "cascade" | "set null" | "restrict" | "no action" | (string & {});
646
745
  }
647
746
 
648
747
  /**
@@ -698,9 +797,12 @@ export class Model {
698
797
  static timestamps: boolean;
699
798
  static softDelete: boolean;
700
799
  static schema: Record<string, ModelSchemaColumn>;
800
+ static fillable: string[];
801
+ static guarded: string[];
701
802
 
702
803
  static getDatabase(): Database;
703
804
  static setDatabase(db: Database): void;
805
+ static close(): Promise<void>;
704
806
  static query<T = any>(sql: string, params?: any[], options?: any): Promise<T>;
705
807
  static transaction<T = any>(callback: (tx: DatabaseTransactionClient | any) => Promise<T>): Promise<T>;
706
808
  static invalidateCache(): Promise<void>;
@@ -708,16 +810,29 @@ export class Model {
708
810
  idOrConditions: number | string | Record<string, any>,
709
811
  options?: ModelFindOptions
710
812
  ): Promise<T | null>;
813
+ static first<T = any>(
814
+ idOrConditions?: number | string | Record<string, any>,
815
+ options?: ModelFindOptions
816
+ ): Promise<T | null>;
817
+ static count(where?: Record<string, any>): Promise<number>;
818
+ static exists(where?: Record<string, any>): Promise<boolean>;
819
+ static firstOrCreate<T = any>(where: Record<string, any>, defaults?: Record<string, any>): Promise<T>;
820
+ static updateOrCreate<T = any>(where: Record<string, any>, values?: Record<string, any>): Promise<T>;
711
821
  static all<T = any>(options?: ModelAllOptions): Promise<T[]>;
712
822
  static paginate<T = any>(options?: ModelPaginateOptions): Promise<PaginatedResult<T>>;
713
- static create(data: Record<string, any>): Promise<number | string>;
714
- static update(idOrConditions: number | string | Record<string, any>, data: Record<string, any>): Promise<number>;
823
+ static create(data: Record<string, any>, options?: { only?: string[]; except?: string[] }): Promise<number | string>;
824
+ static update(
825
+ idOrConditions: number | string | Record<string, any>,
826
+ data: Record<string, any>,
827
+ options?: { only?: string[]; except?: string[] }
828
+ ): Promise<number>;
715
829
  static delete(
716
830
  idOrConditions: number | string | Record<string, any>,
717
831
  options?: ModelDeleteOptions
718
832
  ): Promise<number>;
719
833
  static restore(idOrConditions: number | string | Record<string, any>): Promise<number>;
720
834
  static validator(mode?: "create" | "update", lang?: string): Validator;
835
+ static columnToSQL(col: string, def: ModelSchemaColumn, dialect?: "sqlite" | "mysql" | "postgres"): string;
721
836
  static toDDL(dialect?: "sqlite" | "mysql" | "postgres"): string;
722
837
  }
723
838
 
@@ -760,6 +875,7 @@ export interface AppProps {
760
875
  debug: boolean;
761
876
  desktop: boolean;
762
877
  userDataDir: string;
878
+ appDir: string;
763
879
  title: string;
764
880
  description: string;
765
881
  version: string;
@@ -777,6 +893,8 @@ export interface AppProps {
777
893
 
778
894
  export class Config {
779
895
  static dirname(): string;
896
+ static appDir(): string;
897
+ static setAppDir(dirPath: string): void;
780
898
  static isDesktop(): boolean;
781
899
  static setUserDataDir(customDir: string): void;
782
900
  static userDataDir(): string;
@@ -813,80 +931,6 @@ export interface CommonMiddleware {
813
931
 
814
932
  export const Middleware: CommonMiddleware;
815
933
 
816
- /**
817
- * Options for declarative client-side island hydration.
818
- */
819
- export interface RenderIslandOptions {
820
- tag?: string;
821
- persist?: boolean;
822
- fallback?: string;
823
- }
824
-
825
- /**
826
- * Options for serving raw static HTML files.
827
- */
828
- export interface RenderHtmlOptions {
829
- ttl?: number;
830
- }
831
-
832
- /**
833
- * Modern HTML and view rendering engine for Bluebird.js.
834
- */
835
- export class Render {
836
- static island(name: string, props?: Record<string, any>, options?: RenderIslandOptions): string;
837
- static component(viewName: string, data?: Record<string, any>): Promise<string>;
838
- static partial(res: Response, partialName: string, data?: Record<string, any>): Promise<any>;
839
- static html(res: Response, relativePath: string, options?: RenderHtmlOptions): Promise<any>;
840
- static send(res: Response, viewName: string, data?: Record<string, any>, ttl?: number): Promise<any>;
841
- static view(viewName: string, staticData?: Record<string, any>): (req: Request, res: Response) => Promise<any>;
842
- static cache(seconds?: number): (req: Request, res: Response, next: NextFunction) => Promise<void>;
843
- static stream(res: Response, viewName: string, data?: Record<string, any>): Promise<void>;
844
- static clearTemplateCache(): void;
845
- static invalidate(keys?: string | string[]): Promise<void>;
846
- }
847
-
848
- /**
849
- * SafeHtml container class wrapping trusted or sanitized HTML markup.
850
- */
851
- export class SafeHtml {
852
- value: string;
853
- constructor(value: string);
854
- toString(): string;
855
- }
856
-
857
- export function isSafeHtml(val: any): val is SafeHtml;
858
- export function escapeHtml(value: any): string;
859
- export function safeJson(data: any): string;
860
-
861
- export interface HtmlTag {
862
- (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
863
- raw(str: string): SafeHtml;
864
- json(obj: any): SafeHtml;
865
- script: typeof script;
866
- }
867
-
868
- export const html: HtmlTag;
869
-
870
- export interface ScriptTag {
871
- (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
872
- (src: string): SafeHtml;
873
- (options: { src: string; defer?: boolean; module?: boolean }): SafeHtml;
874
- }
875
-
876
- export const script: ScriptTag;
877
-
878
- export function cached(
879
- key: string,
880
- options: number | { ttl?: number; vary?: string[] },
881
- renderFn: () => SafeHtml | string | Promise<SafeHtml | string>
882
- ): Promise<SafeHtml>;
883
-
884
- export function defer<T>(
885
- promise: Promise<T>,
886
- fallback: SafeHtml | string,
887
- renderer: (data: T) => SafeHtml | string | Promise<SafeHtml | string>
888
- ): { __bluebird_deferred__: true; promise: Promise<T>; fallback: string; renderer: Function };
889
-
890
934
  export default App;
891
935
 
892
936
  declare module "@seip/bluebird-js/core/model.js" {
@@ -939,11 +983,60 @@ declare module "@seip/bluebird-js/core/router.js" {
939
983
  }
940
984
 
941
985
  declare module "@seip/bluebird-js/core/render.js" {
942
- import { Render, RenderIslandOptions, RenderHtmlOptions } from "@seip/bluebird-js";
943
- export { Render, RenderIslandOptions, RenderHtmlOptions };
986
+ import {
987
+ Render,
988
+ RenderIslandOptions,
989
+ RenderHtmlOptions,
990
+ IslandComponentProps,
991
+ h,
992
+ Fragment,
993
+ Island,
994
+ Client,
995
+ } from "@seip/bluebird-js";
996
+ export {
997
+ Render,
998
+ RenderIslandOptions,
999
+ RenderHtmlOptions,
1000
+ IslandComponentProps,
1001
+ h,
1002
+ Fragment,
1003
+ Island,
1004
+ Client,
1005
+ };
944
1006
  export default Render;
945
1007
  }
946
1008
 
1009
+ declare module "@seip/bluebird-js/core/jsx.js" {
1010
+ import {
1011
+ h,
1012
+ createElement,
1013
+ jsx,
1014
+ jsxs,
1015
+ Fragment,
1016
+ Island,
1017
+ Client,
1018
+ IslandComponentProps,
1019
+ isJsxElement,
1020
+ renderJsxToString,
1021
+ compileJsx,
1022
+ registerJsxLoader,
1023
+ } from "@seip/bluebird-js";
1024
+ export {
1025
+ h,
1026
+ createElement,
1027
+ jsx,
1028
+ jsxs,
1029
+ Fragment,
1030
+ Island,
1031
+ Client,
1032
+ IslandComponentProps,
1033
+ isJsxElement,
1034
+ renderJsxToString,
1035
+ compileJsx,
1036
+ registerJsxLoader,
1037
+ };
1038
+ }
1039
+
947
1040
  declare module "@seip/bluebird-js/core/html.js" {
948
1041
  import {
949
1042
  SafeHtml,
@@ -954,6 +1047,7 @@ declare module "@seip/bluebird-js/core/html.js" {
954
1047
  html,
955
1048
  ScriptTag,
956
1049
  script,
1050
+ each,
957
1051
  cached,
958
1052
  defer,
959
1053
  } from "@seip/bluebird-js";
@@ -966,6 +1060,7 @@ declare module "@seip/bluebird-js/core/html.js" {
966
1060
  html,
967
1061
  ScriptTag,
968
1062
  script,
1063
+ each,
969
1064
  cached,
970
1065
  defer,
971
1066
  };
@@ -1174,3 +1269,10 @@ declare module "@seip/bluebird-js/core/seo.js" {
1174
1269
  export { Seo };
1175
1270
  export default Seo;
1176
1271
  }
1272
+
1273
+ declare module "@seip/bluebird-js/core/actions.js" {
1274
+ import { Actions, ActionDefinitionOptions, ActionContext } from "@seip/bluebird-js";
1275
+ export { Actions, ActionDefinitionOptions, ActionContext };
1276
+ export default Actions;
1277
+ }
1278
+
package/core/jsx.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import {
2
+ h,
3
+ createElement,
4
+ jsx,
5
+ jsxs,
6
+ Fragment,
7
+ Island,
8
+ Client,
9
+ IslandComponentProps,
10
+ isJsxElement,
11
+ renderJsxToString,
12
+ compileJsx,
13
+ registerJsxLoader,
14
+ useState,
15
+ useEffect,
16
+ useRef,
17
+ useMemo,
18
+ useCallback,
19
+ } from "./index.js";
20
+ export {
21
+ h,
22
+ createElement,
23
+ jsx,
24
+ jsxs,
25
+ Fragment,
26
+ Island,
27
+ Client,
28
+ IslandComponentProps,
29
+ isJsxElement,
30
+ renderJsxToString,
31
+ compileJsx,
32
+ registerJsxLoader,
33
+ useState,
34
+ useEffect,
35
+ useRef,
36
+ useMemo,
37
+ useCallback,
38
+ };