weifuwu 0.23.3 → 0.24.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/dist/cli.js CHANGED
@@ -74,6 +74,9 @@ async function cmdInit(name, opts) {
74
74
  const deps = { weifuwu: `^${v}` };
75
75
  const devDeps = {};
76
76
  if (!opts.minimal) {
77
+ deps["react"] = "^19";
78
+ deps["react-dom"] = "^19";
79
+ deps["tailwindcss"] = "^4";
77
80
  devDeps["@types/react"] = depVer("@types/react");
78
81
  devDeps["@types/react-dom"] = depVer("@types/react-dom");
79
82
  }
package/dist/csrf.d.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  import type { Context, Middleware } from './types.ts';
2
+ declare module './types.ts' {
3
+ interface Context {
4
+ csrf: CsrfInjected;
5
+ }
6
+ }
7
+ export interface CsrfInjected {
8
+ token: string;
9
+ }
2
10
  /** Options for {@link csrf}. */
3
11
  export interface CsrfOptions {
4
12
  /** Cookie name for CSRF token (default: `'_csrf'`). */
@@ -17,7 +25,7 @@ export interface CsrfOptions {
17
25
  * in a cookie. On other methods, validates the token from header or body
18
26
  * against the cookie.
19
27
  *
20
- * Injects `ctx.csrfToken` for use in forms.
28
+ * Injects `ctx.csrf.token` for use in forms.
21
29
  *
22
30
  * ```ts
23
31
  * import { csrf } from 'weifuwu'
@@ -27,13 +35,11 @@ export interface CsrfOptions {
27
35
  * app.get('/form', (req, ctx) => {
28
36
  * return new Response(`
29
37
  * <form method="POST">
30
- * <input type="hidden" name="_csrf" value="${ctx.csrfToken}" />
38
+ * <input type="hidden" name="_csrf" value="${ctx.csrf.token}" />
31
39
  * <input type="submit" />
32
40
  * </form>
33
41
  * `, { headers: { 'content-type': 'text/html' } })
34
42
  * })
35
43
  * ```
36
44
  */
37
- export declare function csrf(options?: CsrfOptions): Middleware<Context, Context & {
38
- csrfToken: string;
39
- }>;
45
+ export declare function csrf(options?: CsrfOptions): Middleware<Context, Context & CsrfInjected>;
package/dist/env.d.ts CHANGED
@@ -1,3 +1,27 @@
1
+ import type { Context, Middleware } from './types.ts';
2
+ /**
3
+ * Get all public environment variables (those prefixed with `WEIFUWU_PUBLIC_`),
4
+ * with the prefix stripped.
5
+ *
6
+ * ```ts
7
+ * const pub = getPublicEnv()
8
+ * // WEIFUWU_PUBLIC_API_URL=http://api.example.com → { API_URL: 'http://api.example.com' }
9
+ * ```
10
+ */
11
+ export declare function getPublicEnv(): Record<string, string>;
12
+ declare module './types.ts' {
13
+ interface Context {
14
+ env?: Record<string, string>;
15
+ }
16
+ }
17
+ /**
18
+ * Whether this code is running from the compiled `dist/index.js` bundle.
19
+ * `false` when running TypeScript source directly (dev workflow in weifuwu repo).
20
+ *
21
+ * Used by modules that need to resolve package-internal files differently
22
+ * depending on whether they are compiled (published npm package) or raw TS.
23
+ */
24
+ export declare function isBundled(): boolean;
1
25
  /**
2
26
  * Whether `NODE_ENV` is explicitly set to `'development'`.
3
27
  *
@@ -26,3 +50,20 @@ export declare function isProd(): boolean;
26
50
  * ```
27
51
  */
28
52
  export declare function loadEnv(path?: string): void;
53
+ /**
54
+ * Public env middleware.
55
+ *
56
+ * Injects `ctx.env` with all environment variables prefixed with `WEIFUWU_PUBLIC_`,
57
+ * with the prefix stripped. Safe to expose to the client.
58
+ *
59
+ * ```ts
60
+ * import { env } from 'weifuwu'
61
+ * app.use(env())
62
+ *
63
+ * // .env: WEIFUWU_PUBLIC_API_URL=https://api.example.com
64
+ * // ctx: ctx.env.API_URL === 'https://api.example.com'
65
+ * ```
66
+ */
67
+ export declare function env(): Middleware<Context, Context & {
68
+ env: Record<string, string>;
69
+ }>;
package/dist/flash.d.ts CHANGED
@@ -24,6 +24,11 @@
24
24
  * ```
25
25
  */
26
26
  import type { Context, Middleware } from './types.ts';
27
+ declare module './types.ts' {
28
+ interface Context {
29
+ flash: FlashInjected;
30
+ }
31
+ }
27
32
  /** Options for {@link flash}. */
28
33
  export interface FlashOptions {
29
34
  /**
package/dist/i18n.d.ts CHANGED
@@ -1,4 +1,16 @@
1
- import type { Middleware } from './types.ts';
1
+ import type { Context, Middleware } from './types.ts';
2
+ import { Router } from './router.ts';
3
+ declare module './types.ts' {
4
+ interface Context {
5
+ i18n: I18nInjected;
6
+ }
7
+ }
8
+ export interface I18nInjected {
9
+ locale: string;
10
+ messages?: Record<string, unknown>;
11
+ t: (key: string, params?: Record<string, string>, fallback?: string) => string;
12
+ set?: (value: string, loc?: string) => Response;
13
+ }
2
14
  export interface I18nOptions {
3
15
  /** Default locale (default: 'en'). */
4
16
  default?: string;
@@ -11,4 +23,17 @@ export interface I18nOptions {
11
23
  /** Whether to detect locale from Accept-Language header (default: true). */
12
24
  fromAcceptLanguage?: boolean;
13
25
  }
14
- export declare function i18n(options?: I18nOptions): Middleware;
26
+ /**
27
+ * i18n module. Returns a Router with an attached `.middleware()` method.
28
+ *
29
+ * ```ts
30
+ * const l = i18n({ dir: './locales' })
31
+ * app.use(l.middleware()) // → ctx.i18n = { locale, t, set }
32
+ * app.use('/', l) // → GET /__lang/:locale (switch route)
33
+ * ```
34
+ */
35
+ export interface I18nModule extends Router {
36
+ /** Middleware that injects `ctx.i18n = { locale, t, set }`. */
37
+ middleware: () => Middleware<Context, Context & I18nInjected>;
38
+ }
39
+ export declare function i18n(options?: I18nOptions): I18nModule;
@@ -40,6 +40,8 @@ export interface IIIModule extends Router {
40
40
  listTriggers: () => TriggerInfo[];
41
41
  migrate: () => Promise<void>;
42
42
  shutdown: () => Promise<void>;
43
+ /** Alias for shutdown(). */
44
+ close: () => Promise<void>;
43
45
  }
44
46
  export interface WorkerInfo {
45
47
  id: string;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type { Context, Handler, Middleware, ErrorHandler } from './types.ts';
2
- export { currentTraceId, currentTrace, runWithTrace, traceElapsed } from './trace.ts';
3
- export type { TraceContext } from './trace.ts';
4
- export { loadEnv, isDev, isProd } from './env.ts';
2
+ export { currentTraceId, currentTrace, runWithTrace, traceElapsed, trace } from './trace.ts';
3
+ export type { TraceContext, TraceInjected, TraceOptions } from './trace.ts';
4
+ export { loadEnv, isDev, isProd, isBundled, getPublicEnv, env } from './env.ts';
5
5
  export { serve, createTestServer, DEFAULT_MAX_BODY } from './serve.ts';
6
6
  export type { ServeOptions, Server } from './serve.ts';
7
7
  export { Router } from './router.ts';
@@ -11,8 +11,6 @@ export { logger } from './logger.ts';
11
11
  export type { LoggerOptions } from './logger.ts';
12
12
  export { cors } from './cors.ts';
13
13
  export type { CORSOptions } from './cors.ts';
14
- export { auth } from './auth.ts';
15
- export type { AuthOptions } from './auth.ts';
16
14
  export { serveStatic } from './static.ts';
17
15
  export type { ServeStaticOptions } from './static.ts';
18
16
  export { validate } from './validate.ts';
@@ -39,7 +37,7 @@ export { aiStream } from './ai.ts';
39
37
  export type { AIHandler } from './ai.ts';
40
38
  export { runWorkflow } from './ai/workflow.ts';
41
39
  export { aiProvider } from './ai/provider.ts';
42
- export type { AIProvider, AIProviderOptions } from './ai/provider.ts';
40
+ export type { AIProvider, AIProviderOptions, AIProviderInjected } from './ai/provider.ts';
43
41
  export { streamText, generateText, generateObject, streamObject, tool, embed, embedMany, smoothStream, openai, createOpenAI, } from './ai-sdk.ts';
44
42
  export { postgres, MIGRATIONS_TABLE } from './postgres/index.ts';
45
43
  export type { PostgresOptions, PostgresClient, PostgresInjected } from './postgres/types.ts';
@@ -67,17 +65,17 @@ export type { HealthOptions } from './health.ts';
67
65
  export { analytics } from './analytics.ts';
68
66
  export type { AnalyticsOptions, AnalyticsModule } from './analytics.ts';
69
67
  export { theme } from './theme.ts';
70
- export type { ThemeOptions } from './theme.ts';
68
+ export type { ThemeOptions, ThemeInjected } from './theme.ts';
71
69
  export { i18n } from './i18n.ts';
72
- export type { I18nOptions } from './i18n.ts';
70
+ export type { I18nOptions, I18nInjected } from './i18n.ts';
73
71
  export { flash } from './flash.ts';
74
- export type { FlashOptions } from './flash.ts';
72
+ export type { FlashOptions, FlashInjected } from './flash.ts';
75
73
  export { seo, seoMiddleware, seoTags } from './seo.ts';
76
74
  export type { SeoOptions, RobotsRule, SitemapUrl, SitemapConfig, SeoHeadersConfig, SeoTagsConfig, } from './seo.ts';
77
75
  export { mailer } from './mailer.ts';
78
76
  export type { MailerOptions, MailOptions, Mailer } from './mailer.ts';
79
77
  export { csrf } from './csrf.ts';
80
- export type { CsrfOptions } from './csrf.ts';
78
+ export type { CsrfOptions, CsrfInjected } from './csrf.ts';
81
79
  export { logdb } from './logdb/index.ts';
82
80
  export type { LogdbOptions, LogdbModule, LogEntry, LogEntryInput, } from './logdb/types.ts';
83
81
  export { iii, createWorker, registerWorker } from './iii/index.ts';