@seip/bluebird-js 0.1.2 → 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 (43) hide show
  1. package/.vscode/extensions.json +7 -0
  2. package/.vscode/settings.json +10 -0
  3. package/AGENTS.md +92 -60
  4. package/README.md +224 -152
  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 +38 -6
  17. package/core/cli/doctor.js +3 -4
  18. package/core/cli/init.js +20 -6
  19. package/core/cli/migrate.js +418 -145
  20. package/core/cli/view.js +76 -11
  21. package/core/database.js +6 -10
  22. package/core/debug.js +1 -1
  23. package/core/html.d.ts +54 -42
  24. package/core/html.js +473 -217
  25. package/core/index.d.ts +172 -84
  26. package/core/jsx.d.ts +38 -0
  27. package/core/jsx.js +1180 -0
  28. package/core/model.js +271 -61
  29. package/core/render-cache.js +212 -212
  30. package/core/render.d.ts +20 -2
  31. package/core/render.js +320 -43
  32. package/core/validate.js +1 -1
  33. package/core/view-loader.js +313 -22
  34. package/package.json +9 -3
  35. package/public/js/bluebird-client.js +2313 -1049
  36. package/public/js/tailwind.js +8 -0
  37. package/app/views/about.js +0 -63
  38. package/app/views/dashboard.js +0 -147
  39. package/app/views/index.js +0 -80
  40. package/app/views/layouts/main/view.js +0 -81
  41. package/app/views/login.js +0 -80
  42. package/public/css/bluebird.min.css +0 -2
  43. package/public/js/bluebird.min.js +0 -1073
package/core/index.d.ts CHANGED
@@ -256,6 +256,8 @@ 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;
261
263
  appPath?: string;
@@ -506,29 +508,115 @@ export class Cache {
506
508
  export function getRedisClient(): any;
507
509
 
508
510
  /**
509
- * Render island options.
511
+ * Render island / client component options.
510
512
  */
511
513
  export interface RenderIslandOptions {
512
514
  persist?: boolean;
513
- 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;
514
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;
515
594
  }
516
595
 
517
596
  export class Render {
518
597
  static island(
519
- name: string,
598
+ name: string | Function,
520
599
  props?: Record<string, any>,
521
600
  options?: RenderIslandOptions
522
601
  ): string;
523
602
  static component(partialName: string, props?: Record<string, any>): Promise<string>;
524
- static html(res: Response, relativePath: string, options?: { ttl?: number }): Promise<void>;
603
+ static html(res: Response, relativePath: string, options?: RenderHtmlOptions): Promise<void>;
525
604
  static send(res: Response, viewName: string, data?: Record<string, any>, ttl?: number): Promise<void>;
526
605
  static partial(res: Response, partialName: string, data?: Record<string, any>, ttl?: number): Promise<void>;
527
606
  static stream(res: Response, viewName: string, data?: Record<string, any>): Promise<void>;
528
- static view(viewName: string, staticData?: Record<string, any>): (req: Request, res: Response) => void;
529
- 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;
530
617
  static clearTemplateCache(): void;
531
618
  static invalidate(keys?: string | string[]): Promise<void>;
619
+ static autoRoutes(targetRouter?: Router): Promise<Array<{ viewName: string; routePath: string; cache: number; seo: boolean }>>;
532
620
  }
533
621
 
534
622
  export * from "./html.js";
@@ -653,6 +741,7 @@ export interface ModelSchemaColumn {
653
741
  hash?: boolean;
654
742
  in?: any[];
655
743
  references?: string;
744
+ onDelete?: "cascade" | "set null" | "restrict" | "no action" | (string & {});
656
745
  }
657
746
 
658
747
  /**
@@ -708,6 +797,8 @@ export class Model {
708
797
  static timestamps: boolean;
709
798
  static softDelete: boolean;
710
799
  static schema: Record<string, ModelSchemaColumn>;
800
+ static fillable: string[];
801
+ static guarded: string[];
711
802
 
712
803
  static getDatabase(): Database;
713
804
  static setDatabase(db: Database): void;
@@ -719,16 +810,29 @@ export class Model {
719
810
  idOrConditions: number | string | Record<string, any>,
720
811
  options?: ModelFindOptions
721
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>;
722
821
  static all<T = any>(options?: ModelAllOptions): Promise<T[]>;
723
822
  static paginate<T = any>(options?: ModelPaginateOptions): Promise<PaginatedResult<T>>;
724
- static create(data: Record<string, any>): Promise<number | string>;
725
- 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>;
726
829
  static delete(
727
830
  idOrConditions: number | string | Record<string, any>,
728
831
  options?: ModelDeleteOptions
729
832
  ): Promise<number>;
730
833
  static restore(idOrConditions: number | string | Record<string, any>): Promise<number>;
731
834
  static validator(mode?: "create" | "update", lang?: string): Validator;
835
+ static columnToSQL(col: string, def: ModelSchemaColumn, dialect?: "sqlite" | "mysql" | "postgres"): string;
732
836
  static toDDL(dialect?: "sqlite" | "mysql" | "postgres"): string;
733
837
  }
734
838
 
@@ -827,80 +931,6 @@ export interface CommonMiddleware {
827
931
 
828
932
  export const Middleware: CommonMiddleware;
829
933
 
830
- /**
831
- * Options for declarative client-side island hydration.
832
- */
833
- export interface RenderIslandOptions {
834
- tag?: string;
835
- persist?: boolean;
836
- fallback?: string;
837
- }
838
-
839
- /**
840
- * Options for serving raw static HTML files.
841
- */
842
- export interface RenderHtmlOptions {
843
- ttl?: number;
844
- }
845
-
846
- /**
847
- * Modern HTML and view rendering engine for Bluebird.js.
848
- */
849
- export class Render {
850
- static island(name: string, props?: Record<string, any>, options?: RenderIslandOptions): string;
851
- static component(viewName: string, data?: Record<string, any>): Promise<string>;
852
- static partial(res: Response, partialName: string, data?: Record<string, any>): Promise<any>;
853
- static html(res: Response, relativePath: string, options?: RenderHtmlOptions): Promise<any>;
854
- static send(res: Response, viewName: string, data?: Record<string, any>, ttl?: number): Promise<any>;
855
- static view(viewName: string, staticData?: Record<string, any>): (req: Request, res: Response) => Promise<any>;
856
- static cache(seconds?: number): (req: Request, res: Response, next: NextFunction) => Promise<void>;
857
- static stream(res: Response, viewName: string, data?: Record<string, any>): Promise<void>;
858
- static clearTemplateCache(): void;
859
- static invalidate(keys?: string | string[]): Promise<void>;
860
- }
861
-
862
- /**
863
- * SafeHtml container class wrapping trusted or sanitized HTML markup.
864
- */
865
- export class SafeHtml {
866
- value: string;
867
- constructor(value: string);
868
- toString(): string;
869
- }
870
-
871
- export function isSafeHtml(val: any): val is SafeHtml;
872
- export function escapeHtml(value: any): string;
873
- export function safeJson(data: any): string;
874
-
875
- export interface HtmlTag {
876
- (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
877
- raw(str: string): SafeHtml;
878
- json(obj: any): SafeHtml;
879
- script: typeof script;
880
- }
881
-
882
- export const html: HtmlTag;
883
-
884
- export interface ScriptTag {
885
- (strings: TemplateStringsArray, ...values: any[]): SafeHtml;
886
- (src: string): SafeHtml;
887
- (options: { src: string; defer?: boolean; module?: boolean }): SafeHtml;
888
- }
889
-
890
- export const script: ScriptTag;
891
-
892
- export function cached(
893
- key: string,
894
- options: number | { ttl?: number; vary?: string[] },
895
- renderFn: () => SafeHtml | string | Promise<SafeHtml | string>
896
- ): Promise<SafeHtml>;
897
-
898
- export function defer<T>(
899
- promise: Promise<T>,
900
- fallback: SafeHtml | string,
901
- renderer: (data: T) => SafeHtml | string | Promise<SafeHtml | string>
902
- ): { __bluebird_deferred__: true; promise: Promise<T>; fallback: string; renderer: Function };
903
-
904
934
  export default App;
905
935
 
906
936
  declare module "@seip/bluebird-js/core/model.js" {
@@ -953,11 +983,60 @@ declare module "@seip/bluebird-js/core/router.js" {
953
983
  }
954
984
 
955
985
  declare module "@seip/bluebird-js/core/render.js" {
956
- import { Render, RenderIslandOptions, RenderHtmlOptions } from "@seip/bluebird-js";
957
- 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
+ };
958
1006
  export default Render;
959
1007
  }
960
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
+
961
1040
  declare module "@seip/bluebird-js/core/html.js" {
962
1041
  import {
963
1042
  SafeHtml,
@@ -968,6 +1047,7 @@ declare module "@seip/bluebird-js/core/html.js" {
968
1047
  html,
969
1048
  ScriptTag,
970
1049
  script,
1050
+ each,
971
1051
  cached,
972
1052
  defer,
973
1053
  } from "@seip/bluebird-js";
@@ -980,6 +1060,7 @@ declare module "@seip/bluebird-js/core/html.js" {
980
1060
  html,
981
1061
  ScriptTag,
982
1062
  script,
1063
+ each,
983
1064
  cached,
984
1065
  defer,
985
1066
  };
@@ -1188,3 +1269,10 @@ declare module "@seip/bluebird-js/core/seo.js" {
1188
1269
  export { Seo };
1189
1270
  export default Seo;
1190
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
+ };