alepha 0.15.2 → 0.15.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 (180) hide show
  1. package/README.md +68 -80
  2. package/dist/api/audits/index.d.ts.map +1 -1
  3. package/dist/api/audits/index.js +8 -0
  4. package/dist/api/audits/index.js.map +1 -1
  5. package/dist/api/files/index.d.ts +170 -170
  6. package/dist/api/files/index.d.ts.map +1 -1
  7. package/dist/api/files/index.js +1 -0
  8. package/dist/api/files/index.js.map +1 -1
  9. package/dist/api/jobs/index.d.ts.map +1 -1
  10. package/dist/api/jobs/index.js +3 -0
  11. package/dist/api/jobs/index.js.map +1 -1
  12. package/dist/api/notifications/index.browser.js +1 -0
  13. package/dist/api/notifications/index.browser.js.map +1 -1
  14. package/dist/api/notifications/index.js +1 -0
  15. package/dist/api/notifications/index.js.map +1 -1
  16. package/dist/api/parameters/index.d.ts +260 -260
  17. package/dist/api/parameters/index.d.ts.map +1 -1
  18. package/dist/api/parameters/index.js +10 -0
  19. package/dist/api/parameters/index.js.map +1 -1
  20. package/dist/api/users/index.d.ts +12 -1
  21. package/dist/api/users/index.d.ts.map +1 -1
  22. package/dist/api/users/index.js +18 -2
  23. package/dist/api/users/index.js.map +1 -1
  24. package/dist/batch/index.d.ts +4 -4
  25. package/dist/bucket/index.d.ts +8 -0
  26. package/dist/bucket/index.d.ts.map +1 -1
  27. package/dist/bucket/index.js +7 -2
  28. package/dist/bucket/index.js.map +1 -1
  29. package/dist/cli/index.d.ts +196 -74
  30. package/dist/cli/index.d.ts.map +1 -1
  31. package/dist/cli/index.js +234 -50
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/command/index.d.ts +10 -0
  34. package/dist/command/index.d.ts.map +1 -1
  35. package/dist/command/index.js +67 -13
  36. package/dist/command/index.js.map +1 -1
  37. package/dist/core/index.browser.js +28 -21
  38. package/dist/core/index.browser.js.map +1 -1
  39. package/dist/core/index.d.ts.map +1 -1
  40. package/dist/core/index.js +28 -21
  41. package/dist/core/index.js.map +1 -1
  42. package/dist/core/index.native.js +28 -21
  43. package/dist/core/index.native.js.map +1 -1
  44. package/dist/email/index.d.ts +21 -13
  45. package/dist/email/index.d.ts.map +1 -1
  46. package/dist/email/index.js +10561 -4
  47. package/dist/email/index.js.map +1 -1
  48. package/dist/lock/core/index.d.ts +6 -1
  49. package/dist/lock/core/index.d.ts.map +1 -1
  50. package/dist/lock/core/index.js +9 -1
  51. package/dist/lock/core/index.js.map +1 -1
  52. package/dist/mcp/index.d.ts +5 -5
  53. package/dist/orm/index.bun.js +32 -16
  54. package/dist/orm/index.bun.js.map +1 -1
  55. package/dist/orm/index.d.ts +4 -1
  56. package/dist/orm/index.d.ts.map +1 -1
  57. package/dist/orm/index.js +34 -22
  58. package/dist/orm/index.js.map +1 -1
  59. package/dist/react/auth/index.browser.js +2 -1
  60. package/dist/react/auth/index.browser.js.map +1 -1
  61. package/dist/react/auth/index.js +2 -1
  62. package/dist/react/auth/index.js.map +1 -1
  63. package/dist/react/core/index.d.ts +3 -3
  64. package/dist/react/router/index.browser.js +9 -15
  65. package/dist/react/router/index.browser.js.map +1 -1
  66. package/dist/react/router/index.d.ts +305 -407
  67. package/dist/react/router/index.d.ts.map +1 -1
  68. package/dist/react/router/index.js +581 -781
  69. package/dist/react/router/index.js.map +1 -1
  70. package/dist/scheduler/index.d.ts +13 -1
  71. package/dist/scheduler/index.d.ts.map +1 -1
  72. package/dist/scheduler/index.js +42 -4
  73. package/dist/scheduler/index.js.map +1 -1
  74. package/dist/security/index.d.ts +42 -42
  75. package/dist/security/index.d.ts.map +1 -1
  76. package/dist/security/index.js +8 -7
  77. package/dist/security/index.js.map +1 -1
  78. package/dist/server/auth/index.d.ts +167 -167
  79. package/dist/server/compress/index.d.ts.map +1 -1
  80. package/dist/server/compress/index.js +1 -0
  81. package/dist/server/compress/index.js.map +1 -1
  82. package/dist/server/health/index.d.ts +17 -17
  83. package/dist/server/links/index.d.ts +39 -39
  84. package/dist/server/links/index.js +1 -1
  85. package/dist/server/links/index.js.map +1 -1
  86. package/dist/server/static/index.js +7 -2
  87. package/dist/server/static/index.js.map +1 -1
  88. package/dist/server/swagger/index.d.ts +8 -0
  89. package/dist/server/swagger/index.d.ts.map +1 -1
  90. package/dist/server/swagger/index.js +7 -2
  91. package/dist/server/swagger/index.js.map +1 -1
  92. package/dist/sms/index.d.ts +8 -0
  93. package/dist/sms/index.d.ts.map +1 -1
  94. package/dist/sms/index.js +7 -2
  95. package/dist/sms/index.js.map +1 -1
  96. package/dist/system/index.browser.js +734 -12
  97. package/dist/system/index.browser.js.map +1 -1
  98. package/dist/system/index.d.ts +8 -0
  99. package/dist/system/index.d.ts.map +1 -1
  100. package/dist/system/index.js +7 -2
  101. package/dist/system/index.js.map +1 -1
  102. package/dist/vite/index.d.ts +3 -2
  103. package/dist/vite/index.d.ts.map +1 -1
  104. package/dist/vite/index.js +42 -8
  105. package/dist/vite/index.js.map +1 -1
  106. package/dist/websocket/index.d.ts +34 -34
  107. package/dist/websocket/index.d.ts.map +1 -1
  108. package/package.json +9 -4
  109. package/src/api/audits/controllers/AdminAuditController.ts +8 -0
  110. package/src/api/files/controllers/AdminFileStatsController.ts +1 -0
  111. package/src/api/jobs/controllers/AdminJobController.ts +3 -0
  112. package/src/api/logs/TODO.md +13 -10
  113. package/src/api/notifications/controllers/AdminNotificationController.ts +1 -0
  114. package/src/api/parameters/controllers/AdminConfigController.ts +10 -0
  115. package/src/api/users/controllers/AdminIdentityController.ts +3 -0
  116. package/src/api/users/controllers/AdminSessionController.ts +3 -0
  117. package/src/api/users/controllers/AdminUserController.ts +5 -0
  118. package/src/cli/apps/AlephaPackageBuilderCli.ts +9 -0
  119. package/src/cli/atoms/buildOptions.ts +99 -9
  120. package/src/cli/commands/build.ts +150 -32
  121. package/src/cli/commands/db.ts +5 -7
  122. package/src/cli/commands/init.spec.ts +50 -6
  123. package/src/cli/commands/init.ts +28 -5
  124. package/src/cli/providers/ViteDevServerProvider.ts +31 -9
  125. package/src/cli/services/AlephaCliUtils.ts +16 -0
  126. package/src/cli/services/PackageManagerUtils.ts +2 -0
  127. package/src/cli/services/ProjectScaffolder.spec.ts +97 -0
  128. package/src/cli/services/ProjectScaffolder.ts +28 -6
  129. package/src/cli/templates/agentMd.ts +6 -1
  130. package/src/cli/templates/apiAppSecurityTs.ts +11 -0
  131. package/src/cli/templates/apiIndexTs.ts +18 -4
  132. package/src/cli/templates/webAppRouterTs.ts +25 -1
  133. package/src/cli/templates/webHelloComponentTsx.ts +15 -5
  134. package/src/command/helpers/Runner.spec.ts +135 -0
  135. package/src/command/helpers/Runner.ts +4 -1
  136. package/src/command/providers/CliProvider.spec.ts +325 -0
  137. package/src/command/providers/CliProvider.ts +117 -7
  138. package/src/core/Alepha.ts +32 -25
  139. package/src/email/index.workerd.ts +36 -0
  140. package/src/email/providers/WorkermailerEmailProvider.ts +221 -0
  141. package/src/lock/core/primitives/$lock.ts +13 -1
  142. package/src/orm/index.bun.ts +1 -1
  143. package/src/orm/index.ts +2 -6
  144. package/src/orm/providers/drivers/BunSqliteProvider.ts +4 -1
  145. package/src/orm/providers/drivers/CloudflareD1Provider.ts +57 -30
  146. package/src/orm/providers/drivers/DatabaseProvider.ts +9 -1
  147. package/src/orm/providers/drivers/NodeSqliteProvider.ts +4 -1
  148. package/src/react/auth/services/ReactAuth.ts +3 -1
  149. package/src/react/router/atoms/ssrManifestAtom.ts +7 -0
  150. package/src/react/router/hooks/useActive.ts +1 -1
  151. package/src/react/router/hooks/useRouter.ts +1 -1
  152. package/src/react/router/index.ts +4 -0
  153. package/src/react/router/primitives/$page.browser.spec.tsx +24 -24
  154. package/src/react/router/primitives/$page.spec.tsx +0 -32
  155. package/src/react/router/primitives/$page.ts +6 -14
  156. package/src/react/router/providers/ReactBrowserProvider.ts +6 -3
  157. package/src/react/router/providers/ReactPageProvider.ts +1 -1
  158. package/src/react/router/providers/ReactPreloadProvider.spec.ts +142 -0
  159. package/src/react/router/providers/ReactPreloadProvider.ts +85 -0
  160. package/src/react/router/providers/ReactServerProvider.ts +21 -82
  161. package/src/react/router/providers/ReactServerTemplateProvider.spec.ts +210 -0
  162. package/src/react/router/providers/ReactServerTemplateProvider.ts +228 -665
  163. package/src/react/router/providers/SSRManifestProvider.ts +7 -0
  164. package/src/react/router/services/ReactRouter.ts +13 -13
  165. package/src/scheduler/index.workerd.ts +43 -0
  166. package/src/scheduler/providers/CronProvider.ts +53 -6
  167. package/src/scheduler/providers/WorkerdCronProvider.ts +102 -0
  168. package/src/security/__tests__/ServerSecurityProvider.spec.ts +77 -0
  169. package/src/security/providers/ServerSecurityProvider.ts +30 -22
  170. package/src/server/compress/providers/ServerCompressProvider.ts +6 -0
  171. package/src/server/core/providers/NodeHttpServerProvider.spec.ts +9 -3
  172. package/src/server/links/providers/ServerLinksProvider.spec.ts +332 -0
  173. package/src/server/links/providers/ServerLinksProvider.ts +1 -1
  174. package/src/system/index.browser.ts +25 -0
  175. package/src/system/index.workerd.ts +1 -0
  176. package/src/system/providers/FileSystemProvider.ts +8 -0
  177. package/src/system/providers/NodeFileSystemProvider.ts +11 -2
  178. package/src/vite/tasks/buildServer.ts +2 -12
  179. package/src/vite/tasks/generateCloudflare.ts +47 -8
  180. package/src/vite/tasks/generateDocker.ts +4 -0
@@ -1,4 +1,4 @@
1
- import * as alepha181 from "alepha";
1
+ import * as alepha206 from "alepha";
2
2
  import { Alepha, Async, KIND, Primitive, Static } from "alepha";
3
3
  import * as alepha_server_cookies0 from "alepha/server/cookies";
4
4
  import { Cookies, ServerCookiesProvider } from "alepha/server/cookies";
@@ -19,45 +19,45 @@ declare const alephaServerAuthRoutes: {
19
19
  };
20
20
  //#endregion
21
21
  //#region ../../src/server/auth/schemas/authenticationProviderSchema.d.ts
22
- declare const authenticationProviderSchema: alepha181.TObject<{
23
- name: alepha181.TString;
24
- type: alepha181.TUnsafe<"OAUTH2" | "OIDC" | "CREDENTIALS">;
22
+ declare const authenticationProviderSchema: alepha206.TObject<{
23
+ name: alepha206.TString;
24
+ type: alepha206.TUnsafe<"OAUTH2" | "OIDC" | "CREDENTIALS">;
25
25
  }>;
26
26
  type AuthenticationProvider = Static<typeof authenticationProviderSchema>;
27
27
  //#endregion
28
28
  //#region ../../src/server/auth/schemas/tokenResponseSchema.d.ts
29
- declare const tokenResponseSchema: alepha181.TObject<{
30
- provider: alepha181.TString;
31
- access_token: alepha181.TString;
32
- issued_at: alepha181.TNumber;
33
- expires_in: alepha181.TOptional<alepha181.TNumber>;
34
- refresh_token: alepha181.TOptional<alepha181.TString>;
35
- refresh_token_expires_in: alepha181.TOptional<alepha181.TNumber>;
36
- refresh_expires_in: alepha181.TOptional<alepha181.TNumber>;
37
- id_token: alepha181.TOptional<alepha181.TString>;
38
- scope: alepha181.TOptional<alepha181.TString>;
39
- user: alepha181.TObject<{
40
- id: alepha181.TString;
41
- name: alepha181.TOptional<alepha181.TString>;
42
- email: alepha181.TOptional<alepha181.TString>;
43
- username: alepha181.TOptional<alepha181.TString>;
44
- picture: alepha181.TOptional<alepha181.TString>;
45
- sessionId: alepha181.TOptional<alepha181.TString>;
46
- organizations: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
47
- roles: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
29
+ declare const tokenResponseSchema: alepha206.TObject<{
30
+ provider: alepha206.TString;
31
+ access_token: alepha206.TString;
32
+ issued_at: alepha206.TNumber;
33
+ expires_in: alepha206.TOptional<alepha206.TNumber>;
34
+ refresh_token: alepha206.TOptional<alepha206.TString>;
35
+ refresh_token_expires_in: alepha206.TOptional<alepha206.TNumber>;
36
+ refresh_expires_in: alepha206.TOptional<alepha206.TNumber>;
37
+ id_token: alepha206.TOptional<alepha206.TString>;
38
+ scope: alepha206.TOptional<alepha206.TString>;
39
+ user: alepha206.TObject<{
40
+ id: alepha206.TString;
41
+ name: alepha206.TOptional<alepha206.TString>;
42
+ email: alepha206.TOptional<alepha206.TString>;
43
+ username: alepha206.TOptional<alepha206.TString>;
44
+ picture: alepha206.TOptional<alepha206.TString>;
45
+ sessionId: alepha206.TOptional<alepha206.TString>;
46
+ organizations: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
47
+ roles: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
48
48
  }>;
49
- api: alepha181.TObject<{
50
- prefix: alepha181.TOptional<alepha181.TString>;
51
- links: alepha181.TArray<alepha181.TObject<{
52
- name: alepha181.TString;
53
- group: alepha181.TOptional<alepha181.TString>;
54
- path: alepha181.TString;
55
- method: alepha181.TOptional<alepha181.TString>;
56
- requestBodyType: alepha181.TOptional<alepha181.TString>;
57
- service: alepha181.TOptional<alepha181.TString>;
58
- rawSchema: alepha181.TOptional<alepha181.TObject<{
59
- body: alepha181.TOptional<alepha181.TString>;
60
- response: alepha181.TOptional<alepha181.TString>;
49
+ api: alepha206.TObject<{
50
+ prefix: alepha206.TOptional<alepha206.TString>;
51
+ links: alepha206.TArray<alepha206.TObject<{
52
+ name: alepha206.TString;
53
+ group: alepha206.TOptional<alepha206.TString>;
54
+ path: alepha206.TString;
55
+ method: alepha206.TOptional<alepha206.TString>;
56
+ requestBodyType: alepha206.TOptional<alepha206.TString>;
57
+ service: alepha206.TOptional<alepha206.TString>;
58
+ rawSchema: alepha206.TOptional<alepha206.TObject<{
59
+ body: alepha206.TOptional<alepha206.TString>;
60
+ response: alepha206.TOptional<alepha206.TString>;
61
61
  }>>;
62
62
  }>>;
63
63
  }>;
@@ -65,43 +65,43 @@ declare const tokenResponseSchema: alepha181.TObject<{
65
65
  type TokenResponse = Static<typeof tokenResponseSchema>;
66
66
  //#endregion
67
67
  //#region ../../src/server/auth/schemas/tokensSchema.d.ts
68
- declare const tokensSchema: alepha181.TObject<{
69
- provider: alepha181.TString;
70
- access_token: alepha181.TString;
71
- issued_at: alepha181.TNumber;
72
- expires_in: alepha181.TOptional<alepha181.TNumber>;
73
- refresh_token: alepha181.TOptional<alepha181.TString>;
74
- refresh_token_expires_in: alepha181.TOptional<alepha181.TNumber>;
75
- refresh_expires_in: alepha181.TOptional<alepha181.TNumber>;
76
- id_token: alepha181.TOptional<alepha181.TString>;
77
- scope: alepha181.TOptional<alepha181.TString>;
68
+ declare const tokensSchema: alepha206.TObject<{
69
+ provider: alepha206.TString;
70
+ access_token: alepha206.TString;
71
+ issued_at: alepha206.TNumber;
72
+ expires_in: alepha206.TOptional<alepha206.TNumber>;
73
+ refresh_token: alepha206.TOptional<alepha206.TString>;
74
+ refresh_token_expires_in: alepha206.TOptional<alepha206.TNumber>;
75
+ refresh_expires_in: alepha206.TOptional<alepha206.TNumber>;
76
+ id_token: alepha206.TOptional<alepha206.TString>;
77
+ scope: alepha206.TOptional<alepha206.TString>;
78
78
  }>;
79
79
  type Tokens = Static<typeof tokensSchema>;
80
80
  //#endregion
81
81
  //#region ../../src/server/auth/schemas/userinfoResponseSchema.d.ts
82
- declare const userinfoResponseSchema: alepha181.TObject<{
83
- user: alepha181.TOptional<alepha181.TObject<{
84
- id: alepha181.TString;
85
- name: alepha181.TOptional<alepha181.TString>;
86
- email: alepha181.TOptional<alepha181.TString>;
87
- username: alepha181.TOptional<alepha181.TString>;
88
- picture: alepha181.TOptional<alepha181.TString>;
89
- sessionId: alepha181.TOptional<alepha181.TString>;
90
- organizations: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
91
- roles: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
82
+ declare const userinfoResponseSchema: alepha206.TObject<{
83
+ user: alepha206.TOptional<alepha206.TObject<{
84
+ id: alepha206.TString;
85
+ name: alepha206.TOptional<alepha206.TString>;
86
+ email: alepha206.TOptional<alepha206.TString>;
87
+ username: alepha206.TOptional<alepha206.TString>;
88
+ picture: alepha206.TOptional<alepha206.TString>;
89
+ sessionId: alepha206.TOptional<alepha206.TString>;
90
+ organizations: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
91
+ roles: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
92
92
  }>>;
93
- api: alepha181.TObject<{
94
- prefix: alepha181.TOptional<alepha181.TString>;
95
- links: alepha181.TArray<alepha181.TObject<{
96
- name: alepha181.TString;
97
- group: alepha181.TOptional<alepha181.TString>;
98
- path: alepha181.TString;
99
- method: alepha181.TOptional<alepha181.TString>;
100
- requestBodyType: alepha181.TOptional<alepha181.TString>;
101
- service: alepha181.TOptional<alepha181.TString>;
102
- rawSchema: alepha181.TOptional<alepha181.TObject<{
103
- body: alepha181.TOptional<alepha181.TString>;
104
- response: alepha181.TOptional<alepha181.TString>;
93
+ api: alepha206.TObject<{
94
+ prefix: alepha206.TOptional<alepha206.TString>;
95
+ links: alepha206.TArray<alepha206.TObject<{
96
+ name: alepha206.TString;
97
+ group: alepha206.TOptional<alepha206.TString>;
98
+ path: alepha206.TString;
99
+ method: alepha206.TOptional<alepha206.TString>;
100
+ requestBodyType: alepha206.TOptional<alepha206.TString>;
101
+ service: alepha206.TOptional<alepha206.TString>;
102
+ rawSchema: alepha206.TOptional<alepha206.TObject<{
103
+ body: alepha206.TOptional<alepha206.TString>;
104
+ response: alepha206.TOptional<alepha206.TString>;
105
105
  }>>;
106
106
  }>>;
107
107
  }>;
@@ -1141,35 +1141,35 @@ declare class ServerAuthProvider {
1141
1141
  protected readonly serverCookiesProvider: ServerCookiesProvider;
1142
1142
  protected readonly dateTimeProvider: DateTimeProvider;
1143
1143
  protected readonly serverLinksProvider: ServerLinksProvider;
1144
- protected readonly authorizationCode: alepha_server_cookies0.AbstractCookiePrimitive<alepha181.TObject<{
1145
- provider: alepha181.TString;
1146
- realm: alepha181.TOptional<alepha181.TString>;
1147
- codeVerifier: alepha181.TOptional<alepha181.TString>;
1148
- redirectUri: alepha181.TOptional<alepha181.TString>;
1149
- state: alepha181.TOptional<alepha181.TString>;
1150
- nonce: alepha181.TOptional<alepha181.TString>;
1144
+ protected readonly authorizationCode: alepha_server_cookies0.AbstractCookiePrimitive<alepha206.TObject<{
1145
+ provider: alepha206.TString;
1146
+ realm: alepha206.TOptional<alepha206.TString>;
1147
+ codeVerifier: alepha206.TOptional<alepha206.TString>;
1148
+ redirectUri: alepha206.TOptional<alepha206.TString>;
1149
+ state: alepha206.TOptional<alepha206.TString>;
1150
+ nonce: alepha206.TOptional<alepha206.TString>;
1151
1151
  }>>;
1152
- readonly tokens: alepha_server_cookies0.AbstractCookiePrimitive<alepha181.TObject<{
1153
- provider: alepha181.TString;
1154
- access_token: alepha181.TString;
1155
- issued_at: alepha181.TNumber;
1156
- expires_in: alepha181.TOptional<alepha181.TNumber>;
1157
- refresh_token: alepha181.TOptional<alepha181.TString>;
1158
- refresh_token_expires_in: alepha181.TOptional<alepha181.TNumber>;
1159
- refresh_expires_in: alepha181.TOptional<alepha181.TNumber>;
1160
- id_token: alepha181.TOptional<alepha181.TString>;
1161
- scope: alepha181.TOptional<alepha181.TString>;
1152
+ readonly tokens: alepha_server_cookies0.AbstractCookiePrimitive<alepha206.TObject<{
1153
+ provider: alepha206.TString;
1154
+ access_token: alepha206.TString;
1155
+ issued_at: alepha206.TNumber;
1156
+ expires_in: alepha206.TOptional<alepha206.TNumber>;
1157
+ refresh_token: alepha206.TOptional<alepha206.TString>;
1158
+ refresh_token_expires_in: alepha206.TOptional<alepha206.TNumber>;
1159
+ refresh_expires_in: alepha206.TOptional<alepha206.TNumber>;
1160
+ id_token: alepha206.TOptional<alepha206.TString>;
1161
+ scope: alepha206.TOptional<alepha206.TString>;
1162
1162
  }>>;
1163
1163
  get identities(): Array<AuthPrimitive>;
1164
1164
  getAuthenticationProviders(filters?: {
1165
1165
  realmName?: string;
1166
1166
  }): AuthenticationProvider[];
1167
- protected readonly configure: alepha181.HookPrimitive<"configure">;
1167
+ protected readonly configure: alepha206.HookPrimitive<"configure">;
1168
1168
  protected getAccessTokens(tokens: Tokens): string | undefined;
1169
1169
  /**
1170
1170
  * Fill request headers with access token from cookies or fallback to provider's fallback function.
1171
1171
  */
1172
- protected readonly onRequest: alepha181.HookPrimitive<"server:onRequest">;
1172
+ protected readonly onRequest: alepha206.HookPrimitive<"server:onRequest">;
1173
1173
  /**
1174
1174
  * Convert cookies to tokens.
1175
1175
  * If the tokens are expired, try to refresh them using the refresh token.
@@ -1180,29 +1180,29 @@ declare class ServerAuthProvider {
1180
1180
  * Get user information.
1181
1181
  */
1182
1182
  readonly userinfo: alepha_server0.RoutePrimitive<{
1183
- response: alepha181.TObject<{
1184
- user: alepha181.TOptional<alepha181.TObject<{
1185
- id: alepha181.TString;
1186
- name: alepha181.TOptional<alepha181.TString>;
1187
- email: alepha181.TOptional<alepha181.TString>;
1188
- username: alepha181.TOptional<alepha181.TString>;
1189
- picture: alepha181.TOptional<alepha181.TString>;
1190
- sessionId: alepha181.TOptional<alepha181.TString>;
1191
- organizations: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
1192
- roles: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
1183
+ response: alepha206.TObject<{
1184
+ user: alepha206.TOptional<alepha206.TObject<{
1185
+ id: alepha206.TString;
1186
+ name: alepha206.TOptional<alepha206.TString>;
1187
+ email: alepha206.TOptional<alepha206.TString>;
1188
+ username: alepha206.TOptional<alepha206.TString>;
1189
+ picture: alepha206.TOptional<alepha206.TString>;
1190
+ sessionId: alepha206.TOptional<alepha206.TString>;
1191
+ organizations: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
1192
+ roles: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
1193
1193
  }>>;
1194
- api: alepha181.TObject<{
1195
- prefix: alepha181.TOptional<alepha181.TString>;
1196
- links: alepha181.TArray<alepha181.TObject<{
1197
- name: alepha181.TString;
1198
- group: alepha181.TOptional<alepha181.TString>;
1199
- path: alepha181.TString;
1200
- method: alepha181.TOptional<alepha181.TString>;
1201
- requestBodyType: alepha181.TOptional<alepha181.TString>;
1202
- service: alepha181.TOptional<alepha181.TString>;
1203
- rawSchema: alepha181.TOptional<alepha181.TObject<{
1204
- body: alepha181.TOptional<alepha181.TString>;
1205
- response: alepha181.TOptional<alepha181.TString>;
1194
+ api: alepha206.TObject<{
1195
+ prefix: alepha206.TOptional<alepha206.TString>;
1196
+ links: alepha206.TArray<alepha206.TObject<{
1197
+ name: alepha206.TString;
1198
+ group: alepha206.TOptional<alepha206.TString>;
1199
+ path: alepha206.TString;
1200
+ method: alepha206.TOptional<alepha206.TString>;
1201
+ requestBodyType: alepha206.TOptional<alepha206.TString>;
1202
+ service: alepha206.TOptional<alepha206.TString>;
1203
+ rawSchema: alepha206.TOptional<alepha206.TObject<{
1204
+ body: alepha206.TOptional<alepha206.TString>;
1205
+ response: alepha206.TOptional<alepha206.TString>;
1206
1206
  }>>;
1207
1207
  }>>;
1208
1208
  }>;
@@ -1212,69 +1212,69 @@ declare class ServerAuthProvider {
1212
1212
  * Refresh a token for internal providers.
1213
1213
  */
1214
1214
  readonly refresh: alepha_server0.RoutePrimitive<{
1215
- query: alepha181.TObject<{
1216
- provider: alepha181.TString;
1215
+ query: alepha206.TObject<{
1216
+ provider: alepha206.TString;
1217
1217
  }>;
1218
- body: alepha181.TObject<{
1219
- refresh_token: alepha181.TString;
1220
- access_token: alepha181.TOptional<alepha181.TString>;
1218
+ body: alepha206.TObject<{
1219
+ refresh_token: alepha206.TString;
1220
+ access_token: alepha206.TOptional<alepha206.TString>;
1221
1221
  }>;
1222
- response: alepha181.TObject<{
1223
- provider: alepha181.TString;
1224
- access_token: alepha181.TString;
1225
- issued_at: alepha181.TNumber;
1226
- expires_in: alepha181.TOptional<alepha181.TNumber>;
1227
- refresh_token: alepha181.TOptional<alepha181.TString>;
1228
- refresh_token_expires_in: alepha181.TOptional<alepha181.TNumber>;
1229
- refresh_expires_in: alepha181.TOptional<alepha181.TNumber>;
1230
- id_token: alepha181.TOptional<alepha181.TString>;
1231
- scope: alepha181.TOptional<alepha181.TString>;
1222
+ response: alepha206.TObject<{
1223
+ provider: alepha206.TString;
1224
+ access_token: alepha206.TString;
1225
+ issued_at: alepha206.TNumber;
1226
+ expires_in: alepha206.TOptional<alepha206.TNumber>;
1227
+ refresh_token: alepha206.TOptional<alepha206.TString>;
1228
+ refresh_token_expires_in: alepha206.TOptional<alepha206.TNumber>;
1229
+ refresh_expires_in: alepha206.TOptional<alepha206.TNumber>;
1230
+ id_token: alepha206.TOptional<alepha206.TString>;
1231
+ scope: alepha206.TOptional<alepha206.TString>;
1232
1232
  }>;
1233
1233
  }>;
1234
1234
  /**
1235
1235
  * Login for local password-based authentication.
1236
1236
  */
1237
1237
  readonly token: alepha_server0.RoutePrimitive<{
1238
- query: alepha181.TObject<{
1239
- provider: alepha181.TString;
1240
- realm: alepha181.TOptional<alepha181.TString>;
1238
+ query: alepha206.TObject<{
1239
+ provider: alepha206.TString;
1240
+ realm: alepha206.TOptional<alepha206.TString>;
1241
1241
  }>;
1242
- body: alepha181.TObject<{
1243
- username: alepha181.TString;
1244
- password: alepha181.TString;
1242
+ body: alepha206.TObject<{
1243
+ username: alepha206.TString;
1244
+ password: alepha206.TString;
1245
1245
  }>;
1246
- response: alepha181.TObject<{
1247
- provider: alepha181.TString;
1248
- access_token: alepha181.TString;
1249
- issued_at: alepha181.TNumber;
1250
- expires_in: alepha181.TOptional<alepha181.TNumber>;
1251
- refresh_token: alepha181.TOptional<alepha181.TString>;
1252
- refresh_token_expires_in: alepha181.TOptional<alepha181.TNumber>;
1253
- refresh_expires_in: alepha181.TOptional<alepha181.TNumber>;
1254
- id_token: alepha181.TOptional<alepha181.TString>;
1255
- scope: alepha181.TOptional<alepha181.TString>;
1256
- user: alepha181.TObject<{
1257
- id: alepha181.TString;
1258
- name: alepha181.TOptional<alepha181.TString>;
1259
- email: alepha181.TOptional<alepha181.TString>;
1260
- username: alepha181.TOptional<alepha181.TString>;
1261
- picture: alepha181.TOptional<alepha181.TString>;
1262
- sessionId: alepha181.TOptional<alepha181.TString>;
1263
- organizations: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
1264
- roles: alepha181.TOptional<alepha181.TArray<alepha181.TString>>;
1246
+ response: alepha206.TObject<{
1247
+ provider: alepha206.TString;
1248
+ access_token: alepha206.TString;
1249
+ issued_at: alepha206.TNumber;
1250
+ expires_in: alepha206.TOptional<alepha206.TNumber>;
1251
+ refresh_token: alepha206.TOptional<alepha206.TString>;
1252
+ refresh_token_expires_in: alepha206.TOptional<alepha206.TNumber>;
1253
+ refresh_expires_in: alepha206.TOptional<alepha206.TNumber>;
1254
+ id_token: alepha206.TOptional<alepha206.TString>;
1255
+ scope: alepha206.TOptional<alepha206.TString>;
1256
+ user: alepha206.TObject<{
1257
+ id: alepha206.TString;
1258
+ name: alepha206.TOptional<alepha206.TString>;
1259
+ email: alepha206.TOptional<alepha206.TString>;
1260
+ username: alepha206.TOptional<alepha206.TString>;
1261
+ picture: alepha206.TOptional<alepha206.TString>;
1262
+ sessionId: alepha206.TOptional<alepha206.TString>;
1263
+ organizations: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
1264
+ roles: alepha206.TOptional<alepha206.TArray<alepha206.TString>>;
1265
1265
  }>;
1266
- api: alepha181.TObject<{
1267
- prefix: alepha181.TOptional<alepha181.TString>;
1268
- links: alepha181.TArray<alepha181.TObject<{
1269
- name: alepha181.TString;
1270
- group: alepha181.TOptional<alepha181.TString>;
1271
- path: alepha181.TString;
1272
- method: alepha181.TOptional<alepha181.TString>;
1273
- requestBodyType: alepha181.TOptional<alepha181.TString>;
1274
- service: alepha181.TOptional<alepha181.TString>;
1275
- rawSchema: alepha181.TOptional<alepha181.TObject<{
1276
- body: alepha181.TOptional<alepha181.TString>;
1277
- response: alepha181.TOptional<alepha181.TString>;
1266
+ api: alepha206.TObject<{
1267
+ prefix: alepha206.TOptional<alepha206.TString>;
1268
+ links: alepha206.TArray<alepha206.TObject<{
1269
+ name: alepha206.TString;
1270
+ group: alepha206.TOptional<alepha206.TString>;
1271
+ path: alepha206.TString;
1272
+ method: alepha206.TOptional<alepha206.TString>;
1273
+ requestBodyType: alepha206.TOptional<alepha206.TString>;
1274
+ service: alepha206.TOptional<alepha206.TString>;
1275
+ rawSchema: alepha206.TOptional<alepha206.TObject<{
1276
+ body: alepha206.TOptional<alepha206.TString>;
1277
+ response: alepha206.TOptional<alepha206.TString>;
1278
1278
  }>>;
1279
1279
  }>>;
1280
1280
  }>;
@@ -1284,10 +1284,10 @@ declare class ServerAuthProvider {
1284
1284
  * Oauth2/OIDC login route.
1285
1285
  */
1286
1286
  readonly login: alepha_server0.RoutePrimitive<{
1287
- query: alepha181.TObject<{
1288
- provider: alepha181.TString;
1289
- realm: alepha181.TOptional<alepha181.TString>;
1290
- redirect_uri: alepha181.TOptional<alepha181.TString>;
1287
+ query: alepha206.TObject<{
1288
+ provider: alepha206.TString;
1289
+ realm: alepha206.TOptional<alepha206.TString>;
1290
+ redirect_uri: alepha206.TOptional<alepha206.TString>;
1291
1291
  }>;
1292
1292
  }>;
1293
1293
  /**
@@ -1299,8 +1299,8 @@ declare class ServerAuthProvider {
1299
1299
  * Logout route for OAuth2/OIDC providers.
1300
1300
  */
1301
1301
  readonly logout: alepha_server0.RoutePrimitive<{
1302
- query: alepha181.TObject<{
1303
- post_logout_redirect_uri: alepha181.TOptional<alepha181.TString>;
1302
+ query: alepha206.TObject<{
1303
+ post_logout_redirect_uri: alepha206.TOptional<alepha206.TString>;
1304
1304
  }>;
1305
1305
  }>;
1306
1306
  /**
@@ -1634,7 +1634,7 @@ declare module "alepha" {
1634
1634
  *
1635
1635
  * @module alepha.server.auth
1636
1636
  */
1637
- declare const AlephaServerAuth: alepha181.Service<alepha181.Module>;
1637
+ declare const AlephaServerAuth: alepha206.Service<alepha206.Module>;
1638
1638
  //#endregion
1639
1639
  export { $auth, $authCredentials, $authGithub, $authGoogle, AccessToken, AlephaServerAuth, AuthExternal, AuthInternal, AuthPrimitive, AuthPrimitiveOptions, AuthenticationProvider, Credentials, CredentialsFn, CredentialsOptions, LinkAccountFn, LinkAccountOptions, OAuth2Options, OAuth2Profile, OidcOptions, ServerAuthProvider, TokenResponse, Tokens, UserinfoResponse, WithLinkFn, WithLoginFn, alephaServerAuthRoutes, authenticationProviderSchema, tokenResponseSchema, tokensSchema, userinfoResponseSchema };
1640
1640
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/server/compress/providers/ServerCompressProvider.ts","../../../src/server/compress/index.ts"],"mappings":";;;;;;;;YAeY,KAAA;IACR,gCAAA,GAAmC,6BAAA;EAAA;AAAA;AAAA,cAI1B,sBAAA;EAAA,OACJ,WAAA,EAAa,MAAA;IAGd,QAAA,MAAc,IAAA,YAAgB,OAAA,CAAQ,MAAA;IACtC,MAAA,GAAS,OAAA,WAAkB,SAAA;EAAA;EAAA,mBAqBd,MAAA,EAAM,MAAA;EAAA,cAEX,OAAA,CAAA,GAAW,6BAAA;EAAA,SAaT,UAAA,EAbsC,OAAA,CAa5B,aAAA;EAAA,UA8BhB,oBAAA,CAAqB,WAAA;EAAA,UAYf,QAAA,CACd,QAAA,eAAuB,sBAAA,CAAuB,WAAA,EAC9C,QAAA,EAAU,cAAA,GACT,OAAA;;;;;YA8CO,4BAAA,CACR,KAAA,EAAO,cAAA,EACP,gBAAA,GAAmB,OAAA,WAAkB,SAAA,EACrC,QAAA,UACA,MAAA,EAAQ,MAAA,gBACP,cAAA,CAAe,UAAA;EAAA,UA8CR,SAAA,CACR,QAAA,eAAuB,sBAAA,CAAuB,WAAA,GAC7C,MAAA;EAAA,UAeO,UAAA,CACR,QAAA,EAAU,cAAA,EACV,QAAA,eAAuB,sBAAA,CAAuB,WAAA;AAAA;AAAA,UAQjC,6BAAA;EACf,mBAAA;AAAA;;;;;;;;;AAlOkD;;;;;;;cCkBvC,oBAAA,EAAoB,OAAA,CAAA,OAAA,CAG/B,OAAA,CAH+B,MAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/server/compress/providers/ServerCompressProvider.ts","../../../src/server/compress/index.ts"],"mappings":";;;;;;;;YAeY,KAAA;IACR,gCAAA,GAAmC,6BAAA;EAAA;AAAA;AAAA,cAI1B,sBAAA;EAAA,OACJ,WAAA,EAAa,MAAA;IAGd,QAAA,MAAc,IAAA,YAAgB,OAAA,CAAQ,MAAA;IACtC,MAAA,GAAS,OAAA,WAAkB,SAAA;EAAA;EAAA,mBAqBd,MAAA,EAAM,MAAA;EAAA,cAEX,OAAA,CAAA,GAAW,6BAAA;EAAA,SAaT,UAAA,EAbsC,OAAA,CAa5B,aAAA;EAAA,UAoChB,oBAAA,CAAqB,WAAA;EAAA,UAYf,QAAA,CACd,QAAA,eAAuB,sBAAA,CAAuB,WAAA,EAC9C,QAAA,EAAU,cAAA,GACT,OAAA;;;;;YA8CO,4BAAA,CACR,KAAA,EAAO,cAAA,EACP,gBAAA,GAAmB,OAAA,WAAkB,SAAA,EACrC,QAAA,UACA,MAAA,EAAQ,MAAA,gBACP,cAAA,CAAe,UAAA;EAAA,UA8CR,SAAA,CACR,QAAA,eAAuB,sBAAA,CAAuB,WAAA,GAC7C,MAAA;EAAA,UAeO,UAAA,CACR,QAAA,EAAU,cAAA,EACV,QAAA,eAAuB,sBAAA,CAAuB,WAAA;AAAA;AAAA,UAQjC,6BAAA;EACf,mBAAA;AAAA;;;;;;;;;AAxOkD;;;;;;;cCkBvC,oBAAA,EAAoB,OAAA,CAAA,OAAA,CAG/B,OAAA,CAH+B,MAAA"}
@@ -43,6 +43,7 @@ var ServerCompressProvider = class ServerCompressProvider {
43
43
  onResponse = $hook({
44
44
  on: "server:onResponse",
45
45
  handler: async ({ request, response }) => {
46
+ if (this.alepha.isServerless()) return;
46
47
  if (response.headers["content-encoding"]) return;
47
48
  const acceptEncoding = request.headers["accept-encoding"];
48
49
  if (!acceptEncoding) return;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/server/compress/providers/ServerCompressProvider.ts","../../../src/server/compress/index.ts"],"sourcesContent":["import { Readable, type Transform } from \"node:stream\";\nimport { ReadableStream } from \"node:stream/web\";\nimport { promisify } from \"node:util\";\nimport * as zlib from \"node:zlib\";\nimport { $hook, $inject, Alepha } from \"alepha\";\nimport type { ServerResponse } from \"alepha/server\";\n\nconst gzip = promisify(zlib.gzip);\nconst createGzip = zlib.createGzip;\nconst brotli = promisify(zlib.brotliCompress);\nconst createBrotliCompress = zlib.createBrotliCompress;\nconst zstd = zlib.zstdCompress ? promisify(zlib.zstdCompress) : undefined;\nconst createZstdCompress = zstd ? zlib.createZstdCompress : undefined;\n\ndeclare module \"alepha\" {\n interface State {\n \"alepha.server.compress.options\"?: ServerCompressProviderOptions;\n }\n}\n\nexport class ServerCompressProvider {\n static compressors: Record<\n string,\n | {\n compress: (...args: any[]) => Promise<Buffer>;\n stream: (options?: any) => Transform;\n }\n | undefined\n > = {\n gzip: {\n compress: gzip,\n stream: createGzip,\n },\n br: {\n compress: brotli,\n stream: createBrotliCompress,\n },\n zstd:\n zstd && createZstdCompress\n ? {\n compress: zstd,\n stream: createZstdCompress,\n }\n : undefined,\n };\n\n protected readonly alepha = $inject(Alepha);\n\n protected get options(): ServerCompressProviderOptions {\n return {\n allowedContentTypes: [\n \"application/json\",\n \"text/html\",\n \"application/javascript\",\n \"text/plain\",\n \"text/css\",\n ],\n ...this.alepha.store.get(\"alepha.server.compress.options\"),\n };\n }\n\n public readonly onResponse = $hook({\n on: \"server:onResponse\",\n handler: async ({ request, response }) => {\n // skip if already compressed\n if (response.headers[\"content-encoding\"]) {\n return;\n }\n\n const acceptEncoding = request.headers[\"accept-encoding\"]; // skip if no accept-encoding header\n if (!acceptEncoding) {\n return;\n }\n\n // skip if not json or html (for now)\n if (!this.isAllowedContentType(response.headers[\"content-type\"])) {\n return;\n }\n\n for (const encoding of [\"zstd\", \"br\", \"gzip\"] as const) {\n if (\n acceptEncoding.includes(encoding) &&\n ServerCompressProvider.compressors[encoding]\n ) {\n await this.compress(encoding, response);\n return;\n }\n }\n },\n });\n\n protected isAllowedContentType(contentType: string | undefined): boolean {\n if (!contentType) {\n return false;\n }\n\n const lowerContentType = contentType.toLowerCase();\n\n return !!this.options.allowedContentTypes.find((it) =>\n lowerContentType.includes(it),\n );\n }\n\n protected async compress(\n encoding: keyof typeof ServerCompressProvider.compressors,\n response: ServerResponse,\n ): Promise<void> {\n const body = response.body; // can be string or Buffer or ArrayBuffer or Readable\n\n const compressor = ServerCompressProvider.compressors[encoding];\n if (!compressor) {\n return;\n }\n\n const params = this.getParams(encoding);\n\n if (\n typeof body === \"string\" ||\n Buffer.isBuffer(body) ||\n body instanceof ArrayBuffer\n ) {\n const compressed = await compressor.compress(body, {\n params,\n });\n this.setHeaders(response, encoding);\n response.headers[\"content-length\"] = compressed.length.toString();\n response.body = compressed;\n return;\n }\n\n if (typeof body === \"object\" && body instanceof Readable) {\n this.setHeaders(response, encoding);\n response.body = body.pipe(compressor.stream({ params }));\n return;\n }\n\n if (typeof body === \"object\" && body instanceof ReadableStream) {\n this.setHeaders(response, encoding);\n // For streaming responses, use flush mode to avoid buffering\n response.body = this.createFlushingCompressStream(\n body,\n compressor.stream,\n encoding,\n params,\n );\n }\n }\n\n /**\n * Create a compressed stream that flushes after each chunk.\n * This is essential for streaming SSR - ensures each chunk is sent immediately.\n */\n protected createFlushingCompressStream(\n input: ReadableStream,\n createCompressor: (options?: any) => Transform,\n encoding: string,\n params: Record<number, any>,\n ): ReadableStream<Uint8Array> {\n const compressor = createCompressor({\n params,\n flush: zlib.constants.Z_SYNC_FLUSH,\n });\n const reader = Readable.fromWeb(input);\n\n return new ReadableStream<Uint8Array>({\n start(controller) {\n compressor.on(\"data\", (chunk: Buffer) => {\n controller.enqueue(new Uint8Array(chunk));\n });\n\n compressor.on(\"end\", () => {\n controller.close();\n });\n\n compressor.on(\"error\", (err) => {\n controller.error(err);\n });\n\n reader.on(\"data\", (chunk: Buffer) => {\n compressor.write(chunk);\n // Force flush after each chunk for streaming\n // Cast to any because flush() exists on zlib streams but not in Transform type\n const zlibStream = compressor as any;\n if (encoding === \"gzip\") {\n zlibStream.flush(zlib.constants.Z_SYNC_FLUSH);\n } else if (encoding === \"br\") {\n zlibStream.flush(zlib.constants.BROTLI_OPERATION_FLUSH);\n } else if (encoding === \"zstd\") {\n zlibStream.flush();\n }\n });\n\n reader.on(\"end\", () => {\n compressor.end();\n });\n\n reader.on(\"error\", (err) => {\n controller.error(err);\n });\n },\n });\n }\n\n protected getParams(\n encoding: keyof typeof ServerCompressProvider.compressors,\n ): Record<number, any> {\n if (encoding === \"zstd\") {\n return {\n [zlib.constants.ZSTD_c_compressionLevel]: 3, // default compression level for zstd\n };\n }\n if (encoding === \"br\") {\n return {};\n }\n if (encoding === \"gzip\") {\n return {};\n }\n return {};\n }\n\n protected setHeaders(\n response: ServerResponse,\n encoding: keyof typeof ServerCompressProvider.compressors,\n ): void {\n response.headers.vary = \"content-encoding\";\n response.headers[\"content-encoding\"] = encoding;\n response.headers[\"cache-control\"] = \"no-cache\";\n }\n}\n\nexport interface ServerCompressProviderOptions {\n allowedContentTypes: string[];\n}\n","import { $module } from \"alepha\";\nimport { AlephaServer } from \"alepha/server\";\nimport { ServerCompressProvider } from \"./providers/ServerCompressProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./providers/ServerCompressProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * | type | quality | stability |\n * |------|---------|-----------|\n * | backend | standard | stable |\n *\n * Response compression.\n *\n * **Features:**\n * - Gzip compression\n * - Brotli compression\n *\n * @module alepha.server.compress\n */\nexport const AlephaServerCompress = $module({\n name: \"alepha.server.compress\",\n services: [AlephaServer, ServerCompressProvider],\n});\n"],"mappings":";;;;;;;;AAOA,MAAM,OAAO,UAAU,KAAK,KAAK;AACjC,MAAM,aAAa,KAAK;AACxB,MAAM,SAAS,UAAU,KAAK,eAAe;AAC7C,MAAM,uBAAuB,KAAK;AAClC,MAAM,OAAO,KAAK,eAAe,UAAU,KAAK,aAAa,GAAG;AAChE,MAAM,qBAAqB,OAAO,KAAK,qBAAqB;AAQ5D,IAAa,yBAAb,MAAa,uBAAuB;CAClC,OAAO,cAOH;EACF,MAAM;GACJ,UAAU;GACV,QAAQ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B;AACvC,WAAS,QAAQ,mBAAmB;;;;;;;;;;;;;;;;;;;AC3MxC,MAAa,uBAAuB,QAAQ;CAC1C,MAAM;CACN,UAAU,CAAC,cAAc,uBAAuB;CACjD,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/server/compress/providers/ServerCompressProvider.ts","../../../src/server/compress/index.ts"],"sourcesContent":["import { Readable, type Transform } from \"node:stream\";\nimport { ReadableStream } from \"node:stream/web\";\nimport { promisify } from \"node:util\";\nimport * as zlib from \"node:zlib\";\nimport { $hook, $inject, Alepha } from \"alepha\";\nimport type { ServerResponse } from \"alepha/server\";\n\nconst gzip = promisify(zlib.gzip);\nconst createGzip = zlib.createGzip;\nconst brotli = promisify(zlib.brotliCompress);\nconst createBrotliCompress = zlib.createBrotliCompress;\nconst zstd = zlib.zstdCompress ? promisify(zlib.zstdCompress) : undefined;\nconst createZstdCompress = zstd ? zlib.createZstdCompress : undefined;\n\ndeclare module \"alepha\" {\n interface State {\n \"alepha.server.compress.options\"?: ServerCompressProviderOptions;\n }\n}\n\nexport class ServerCompressProvider {\n static compressors: Record<\n string,\n | {\n compress: (...args: any[]) => Promise<Buffer>;\n stream: (options?: any) => Transform;\n }\n | undefined\n > = {\n gzip: {\n compress: gzip,\n stream: createGzip,\n },\n br: {\n compress: brotli,\n stream: createBrotliCompress,\n },\n zstd:\n zstd && createZstdCompress\n ? {\n compress: zstd,\n stream: createZstdCompress,\n }\n : undefined,\n };\n\n protected readonly alepha = $inject(Alepha);\n\n protected get options(): ServerCompressProviderOptions {\n return {\n allowedContentTypes: [\n \"application/json\",\n \"text/html\",\n \"application/javascript\",\n \"text/plain\",\n \"text/css\",\n ],\n ...this.alepha.store.get(\"alepha.server.compress.options\"),\n };\n }\n\n public readonly onResponse = $hook({\n on: \"server:onResponse\",\n handler: async ({ request, response }) => {\n // In serverless (Cloudflare Workers), skip compression entirely:\n // Cloudflare's edge network automatically compresses responses\n if (this.alepha.isServerless()) {\n return;\n }\n\n // skip if already compressed\n if (response.headers[\"content-encoding\"]) {\n return;\n }\n\n const acceptEncoding = request.headers[\"accept-encoding\"]; // skip if no accept-encoding header\n if (!acceptEncoding) {\n return;\n }\n\n // skip if not json or html (for now)\n if (!this.isAllowedContentType(response.headers[\"content-type\"])) {\n return;\n }\n\n for (const encoding of [\"zstd\", \"br\", \"gzip\"] as const) {\n if (\n acceptEncoding.includes(encoding) &&\n ServerCompressProvider.compressors[encoding]\n ) {\n await this.compress(encoding, response);\n return;\n }\n }\n },\n });\n\n protected isAllowedContentType(contentType: string | undefined): boolean {\n if (!contentType) {\n return false;\n }\n\n const lowerContentType = contentType.toLowerCase();\n\n return !!this.options.allowedContentTypes.find((it) =>\n lowerContentType.includes(it),\n );\n }\n\n protected async compress(\n encoding: keyof typeof ServerCompressProvider.compressors,\n response: ServerResponse,\n ): Promise<void> {\n const body = response.body; // can be string or Buffer or ArrayBuffer or Readable\n\n const compressor = ServerCompressProvider.compressors[encoding];\n if (!compressor) {\n return;\n }\n\n const params = this.getParams(encoding);\n\n if (\n typeof body === \"string\" ||\n Buffer.isBuffer(body) ||\n body instanceof ArrayBuffer\n ) {\n const compressed = await compressor.compress(body, {\n params,\n });\n this.setHeaders(response, encoding);\n response.headers[\"content-length\"] = compressed.length.toString();\n response.body = compressed;\n return;\n }\n\n if (typeof body === \"object\" && body instanceof Readable) {\n this.setHeaders(response, encoding);\n response.body = body.pipe(compressor.stream({ params }));\n return;\n }\n\n if (typeof body === \"object\" && body instanceof ReadableStream) {\n this.setHeaders(response, encoding);\n // For streaming responses, use flush mode to avoid buffering\n response.body = this.createFlushingCompressStream(\n body,\n compressor.stream,\n encoding,\n params,\n );\n }\n }\n\n /**\n * Create a compressed stream that flushes after each chunk.\n * This is essential for streaming SSR - ensures each chunk is sent immediately.\n */\n protected createFlushingCompressStream(\n input: ReadableStream,\n createCompressor: (options?: any) => Transform,\n encoding: string,\n params: Record<number, any>,\n ): ReadableStream<Uint8Array> {\n const compressor = createCompressor({\n params,\n flush: zlib.constants.Z_SYNC_FLUSH,\n });\n const reader = Readable.fromWeb(input);\n\n return new ReadableStream<Uint8Array>({\n start(controller) {\n compressor.on(\"data\", (chunk: Buffer) => {\n controller.enqueue(new Uint8Array(chunk));\n });\n\n compressor.on(\"end\", () => {\n controller.close();\n });\n\n compressor.on(\"error\", (err) => {\n controller.error(err);\n });\n\n reader.on(\"data\", (chunk: Buffer) => {\n compressor.write(chunk);\n // Force flush after each chunk for streaming\n // Cast to any because flush() exists on zlib streams but not in Transform type\n const zlibStream = compressor as any;\n if (encoding === \"gzip\") {\n zlibStream.flush(zlib.constants.Z_SYNC_FLUSH);\n } else if (encoding === \"br\") {\n zlibStream.flush(zlib.constants.BROTLI_OPERATION_FLUSH);\n } else if (encoding === \"zstd\") {\n zlibStream.flush();\n }\n });\n\n reader.on(\"end\", () => {\n compressor.end();\n });\n\n reader.on(\"error\", (err) => {\n controller.error(err);\n });\n },\n });\n }\n\n protected getParams(\n encoding: keyof typeof ServerCompressProvider.compressors,\n ): Record<number, any> {\n if (encoding === \"zstd\") {\n return {\n [zlib.constants.ZSTD_c_compressionLevel]: 3, // default compression level for zstd\n };\n }\n if (encoding === \"br\") {\n return {};\n }\n if (encoding === \"gzip\") {\n return {};\n }\n return {};\n }\n\n protected setHeaders(\n response: ServerResponse,\n encoding: keyof typeof ServerCompressProvider.compressors,\n ): void {\n response.headers.vary = \"content-encoding\";\n response.headers[\"content-encoding\"] = encoding;\n response.headers[\"cache-control\"] = \"no-cache\";\n }\n}\n\nexport interface ServerCompressProviderOptions {\n allowedContentTypes: string[];\n}\n","import { $module } from \"alepha\";\nimport { AlephaServer } from \"alepha/server\";\nimport { ServerCompressProvider } from \"./providers/ServerCompressProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./providers/ServerCompressProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * | type | quality | stability |\n * |------|---------|-----------|\n * | backend | standard | stable |\n *\n * Response compression.\n *\n * **Features:**\n * - Gzip compression\n * - Brotli compression\n *\n * @module alepha.server.compress\n */\nexport const AlephaServerCompress = $module({\n name: \"alepha.server.compress\",\n services: [AlephaServer, ServerCompressProvider],\n});\n"],"mappings":";;;;;;;;AAOA,MAAM,OAAO,UAAU,KAAK,KAAK;AACjC,MAAM,aAAa,KAAK;AACxB,MAAM,SAAS,UAAU,KAAK,eAAe;AAC7C,MAAM,uBAAuB,KAAK;AAClC,MAAM,OAAO,KAAK,eAAe,UAAU,KAAK,aAAa,GAAG;AAChE,MAAM,qBAAqB,OAAO,KAAK,qBAAqB;AAQ5D,IAAa,yBAAb,MAAa,uBAAuB;CAClC,OAAO,cAOH;EACF,MAAM;GACJ,UAAU;GACV,QAAQ;GACT;EACD,IAAI;GACF,UAAU;GACV,QAAQ;GACT;EACD,MACE,QAAQ,qBACJ;GACE,UAAU;GACV,QAAQ;GACT,GACD;EACP;CAED,AAAmB,SAAS,QAAQ,OAAO;CAE3C,IAAc,UAAyC;AACrD,SAAO;GACL,qBAAqB;IACnB;IACA;IACA;IACA;IACA;IACD;GACD,GAAG,KAAK,OAAO,MAAM,IAAI,iCAAiC;GAC3D;;CAGH,AAAgB,aAAa,MAAM;EACjC,IAAI;EACJ,SAAS,OAAO,EAAE,SAAS,eAAe;AAGxC,OAAI,KAAK,OAAO,cAAc,CAC5B;AAIF,OAAI,SAAS,QAAQ,oBACnB;GAGF,MAAM,iBAAiB,QAAQ,QAAQ;AACvC,OAAI,CAAC,eACH;AAIF,OAAI,CAAC,KAAK,qBAAqB,SAAS,QAAQ,gBAAgB,CAC9D;AAGF,QAAK,MAAM,YAAY;IAAC;IAAQ;IAAM;IAAO,CAC3C,KACE,eAAe,SAAS,SAAS,IACjC,uBAAuB,YAAY,WACnC;AACA,UAAM,KAAK,SAAS,UAAU,SAAS;AACvC;;;EAIP,CAAC;CAEF,AAAU,qBAAqB,aAA0C;AACvE,MAAI,CAAC,YACH,QAAO;EAGT,MAAM,mBAAmB,YAAY,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f,YAAW,MAAM,KAAK,UAAU,aAAa;aACpC,aAAa,KACtB,YAAW,MAAM,KAAK,UAAU,uBAAuB;aAC9C,aAAa,OACtB,YAAW,OAAO;KAEpB;AAEF,UAAO,GAAG,aAAa;AACrB,eAAW,KAAK;KAChB;AAEF,UAAO,GAAG,UAAU,QAAQ;AAC1B,eAAW,MAAM,IAAI;KACrB;KAEL,CAAC;;CAGJ,AAAU,UACR,UACqB;AACrB,MAAI,aAAa,OACf,QAAO,GACJ,KAAK,UAAU,0BAA0B,GAC3C;AAEH,MAAI,aAAa,KACf,QAAO,EAAE;AAEX,MAAI,aAAa,OACf,QAAO,EAAE;AAEX,SAAO,EAAE;;CAGX,AAAU,WACR,UACA,UACM;AACN,WAAS,QAAQ,OAAO;AACxB,WAAS,QAAQ,sBAAsB;AACvC,WAAS,QAAQ,mBAAmB;;;;;;;;;;;;;;;;;;;ACjNxC,MAAa,uBAAuB,QAAQ;CAC1C,MAAM;CACN,UAAU,CAAC,cAAc,uBAAuB;CACjD,CAAC"}
@@ -1,4 +1,4 @@
1
- import * as alepha1 from "alepha";
1
+ import * as alepha6 from "alepha";
2
2
  import { Alepha } from "alepha";
3
3
  import * as alepha_server0 from "alepha/server";
4
4
  import { DateTimeProvider } from "alepha/datetime";
@@ -13,19 +13,19 @@ declare class ServerHealthProvider {
13
13
  protected readonly time: DateTimeProvider;
14
14
  protected readonly alepha: Alepha;
15
15
  readonly health: alepha_server0.RoutePrimitive<{
16
- response: alepha1.TObject<{
17
- message: alepha1.TString;
18
- uptime: alepha1.TNumber;
19
- date: alepha1.TString;
20
- ready: alepha1.TBoolean;
16
+ response: alepha6.TObject<{
17
+ message: alepha6.TString;
18
+ uptime: alepha6.TNumber;
19
+ date: alepha6.TString;
20
+ ready: alepha6.TBoolean;
21
21
  }>;
22
22
  }>;
23
23
  readonly healthz: alepha_server0.RoutePrimitive<{
24
- response: alepha1.TObject<{
25
- message: alepha1.TString;
26
- uptime: alepha1.TNumber;
27
- date: alepha1.TString;
28
- ready: alepha1.TBoolean;
24
+ response: alepha6.TObject<{
25
+ message: alepha6.TString;
26
+ uptime: alepha6.TNumber;
27
+ date: alepha6.TString;
28
+ ready: alepha6.TBoolean;
29
29
  }>;
30
30
  }>;
31
31
  protected healthCheck(): {
@@ -37,11 +37,11 @@ declare class ServerHealthProvider {
37
37
  }
38
38
  //#endregion
39
39
  //#region ../../src/server/health/schemas/healthSchema.d.ts
40
- declare const healthSchema: alepha1.TObject<{
41
- message: alepha1.TString;
42
- uptime: alepha1.TNumber;
43
- date: alepha1.TString;
44
- ready: alepha1.TBoolean;
40
+ declare const healthSchema: alepha6.TObject<{
41
+ message: alepha6.TString;
42
+ uptime: alepha6.TNumber;
43
+ date: alepha6.TString;
44
+ ready: alepha6.TBoolean;
45
45
  }>;
46
46
  //#endregion
47
47
  //#region ../../src/server/health/index.d.ts
@@ -57,7 +57,7 @@ declare const healthSchema: alepha1.TObject<{
57
57
  *
58
58
  * @module alepha.server.health
59
59
  */
60
- declare const AlephaServerHealth: alepha1.Service<alepha1.Module>;
60
+ declare const AlephaServerHealth: alepha6.Service<alepha6.Module>;
61
61
  //#endregion
62
62
  export { AlephaServerHealth, ServerHealthProvider, healthSchema };
63
63
  //# sourceMappingURL=index.d.ts.map