@moku-labs/web 0.1.0-alpha.3 → 0.2.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.
Files changed (38) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +71 -23
  3. package/dist/chunk-DQk6qfdC.mjs +18 -0
  4. package/dist/index.cjs +5514 -36
  5. package/dist/index.d.cts +2078 -104
  6. package/dist/index.d.mts +2078 -104
  7. package/dist/index.mjs +5394 -28
  8. package/package.json +60 -60
  9. package/dist/bin/moku.cjs +0 -1383
  10. package/dist/bin/moku.d.cts +0 -1
  11. package/dist/bin/moku.d.mts +0 -1
  12. package/dist/bin/moku.mjs +0 -1383
  13. package/dist/factory-BHhulW27.d.mts +0 -90
  14. package/dist/factory-D0m7Xil2.d.cts +0 -90
  15. package/dist/factory-DVcAQYEZ.cjs +0 -1710
  16. package/dist/factory-DwpBwjDk.mjs +0 -1602
  17. package/dist/index-CddOHo8I.d.mts +0 -413
  18. package/dist/plugins/head/build.cjs +0 -35
  19. package/dist/plugins/head/build.d.cts +0 -17
  20. package/dist/plugins/head/build.d.mts +0 -17
  21. package/dist/plugins/head/build.mjs +0 -27
  22. package/dist/plugins/spa/index.cjs +0 -26
  23. package/dist/plugins/spa/index.d.cts +0 -30
  24. package/dist/plugins/spa/index.d.mts +0 -30
  25. package/dist/plugins/spa/index.mjs +0 -24
  26. package/dist/primitives-BBo4wxUL.d.cts +0 -69
  27. package/dist/primitives-BYUp6kae.cjs +0 -100
  28. package/dist/primitives-Dlfi3JTx.d.mts +0 -69
  29. package/dist/primitives-gO5i1tD8.mjs +0 -58
  30. package/dist/project-1pAh4RxJ.cjs +0 -1270
  31. package/dist/project-BaG_ipVz.mjs +0 -1203
  32. package/dist/route-builder-CKvvehVO.d.cts +0 -413
  33. package/dist/test.cjs +0 -82
  34. package/dist/test.d.cts +0 -61
  35. package/dist/test.d.mts +0 -61
  36. package/dist/test.mjs +0 -79
  37. package/dist/wrangler-BHdkyMRj.cjs +0 -423
  38. package/dist/wrangler-Coyrznz4.mjs +0 -369
@@ -1,413 +0,0 @@
1
- import { p as OGImageConfig } from "./primitives-BBo4wxUL.cjs";
2
- import { n as ComponentDef } from "./factory-D0m7Xil2.cjs";
3
- import { Processor } from "unified";
4
-
5
- //#region src/plugins/log/types.d.ts
6
- /** @file log plugin types — LogEntry, LogSink, ExpectChain, LogState, LogApi. */
7
- type LogLevel = 'debug' | 'info' | 'warn' | 'error';
8
- type LogEntry = {
9
- level: LogLevel;
10
- event: string;
11
- data?: unknown;
12
- ts: number;
13
- plugin?: string;
14
- };
15
- type LogSink = {
16
- write(entry: LogEntry): void;
17
- };
18
- type ExpectChain = {
19
- toHaveEvent(event: string, partial?: Record<string, unknown>): ExpectChain;
20
- toHaveEventInOrder(events: string[]): ExpectChain;
21
- toNotHaveEvent(event: string, partial?: Record<string, unknown>): ExpectChain;
22
- };
23
- type LogState = {
24
- entries: LogEntry[];
25
- sinks: LogSink[];
26
- };
27
- type LogApi = {
28
- info(event: string, data?: unknown): void;
29
- debug(event: string, data?: unknown): void;
30
- warn(event: string, data?: unknown): void;
31
- error(event: string, data?: unknown, error?: Error): void;
32
- trace(): readonly LogEntry[];
33
- expect(): ExpectChain;
34
- addSink(sink: LogSink): void;
35
- reset(): void;
36
- };
37
- //#endregion
38
- //#region src/plugins/env/types.d.ts
39
- /** @file env plugin types — schema, provider, EnvApi. */
40
- type EnvVarSpec = {
41
- public: boolean;
42
- required?: boolean;
43
- default?: string;
44
- secret?: boolean;
45
- };
46
- type EnvProvider = {
47
- name: string;
48
- load(): Record<string, string | undefined>;
49
- };
50
- type EnvConfig = {
51
- schema: Record<string, EnvVarSpec>;
52
- providers: EnvProvider[];
53
- publicPrefix: string;
54
- };
55
- type EnvState = {
56
- resolved: Map<string, string>;
57
- publicMap: Map<string, string>;
58
- };
59
- type EnvApi = {
60
- get<K extends string>(key: K): string | undefined;
61
- require(key: string): string;
62
- getPublic(): Readonly<Record<string, string>>;
63
- getPublicMap(): ReadonlyMap<string, string>;
64
- has(key: string): boolean;
65
- };
66
- //#endregion
67
- //#region src/config.d.ts
68
- /** Top-level framework config — flows to all plugins via context. */
69
- type Config = {
70
- mode: 'production' | 'development';
71
- };
72
- /** Framework-level event map — plugin-specific events added by each plugin's events field. */
73
- type Events = {
74
- 'content:ready': {
75
- articles: Map<string, unknown[]>;
76
- };
77
- 'content:invalidated': {
78
- paths: string[];
79
- };
80
- 'router:registered': {
81
- routeCount: number;
82
- };
83
- 'build:phase': {
84
- phase: 'bundle' | 'content' | 'pages' | 'feeds' | 'sitemap' | 'og' | 'images';
85
- };
86
- 'build:complete': {
87
- pages: number;
88
- durationMs: number;
89
- };
90
- 'component:create': {
91
- name: string;
92
- element: Element;
93
- };
94
- 'component:mount': {
95
- name: string;
96
- element: Element;
97
- };
98
- 'component:unmount': {
99
- name: string;
100
- reason: 'navigation' | 'destroy';
101
- };
102
- 'component:destroy': {
103
- name: string;
104
- };
105
- 'nav:start': {
106
- url: string;
107
- fromUrl: string;
108
- };
109
- 'nav:end': {
110
- url: string;
111
- };
112
- };
113
- //#endregion
114
- //#region src/plugins/site/types.d.ts
115
- /** @file site plugin types — SiteConfig + SiteState + SiteApi. */
116
- type SiteConfig = {
117
- /** Display name of the site. */name: string; /** Base URL of the site (no trailing slash). */
118
- url: string; /** Default author name for content. */
119
- author: string; /** Site description for feeds, meta tags, and preview pages. */
120
- description: string;
121
- };
122
- type SiteState = {
123
- config: Readonly<SiteConfig>;
124
- };
125
- type SiteApi = {
126
- get(): Readonly<SiteConfig>;
127
- name(): string;
128
- url(): string;
129
- author(): string;
130
- description(): string;
131
- };
132
- //#endregion
133
- //#region src/plugins/i18n/types.d.ts
134
- /** @file i18n plugin types — I18nConfig (generic over locale tuple), I18nState, I18nApi. */
135
- type I18nConfig<TLocales extends readonly string[] = readonly string[]> = {
136
- /** Active locale codes (literal tuple preserved). */locales: TLocales; /** Default locale (must be member of locales). */
137
- defaultLocale: TLocales[number]; /** Display names per locale. */
138
- localeNames: Record<TLocales[number], string>; /** OG locale format mapping (e.g., { en: 'en_US' }). */
139
- ogLocaleMap?: Partial<Record<TLocales[number], string>>; /** UI translation strings per locale. */
140
- translations?: Record<TLocales[number], Record<string, string>>;
141
- };
142
- type I18nState<TLocales extends readonly string[] = readonly string[]> = {
143
- config: Readonly<I18nConfig<TLocales>>;
144
- };
145
- type I18nApi<TLocales extends readonly string[] = readonly string[]> = {
146
- locales(): TLocales;
147
- defaultLocale(): TLocales[number];
148
- localeName(locale: TLocales[number]): string;
149
- ogLocale(locale: TLocales[number]): string;
150
- t(locale: TLocales[number], key: string): string;
151
- };
152
- //#endregion
153
- //#region src/plugins/content/types.d.ts
154
- type Frontmatter = {
155
- title: string;
156
- date: string;
157
- description: string;
158
- tags: string[];
159
- language: string;
160
- author?: string;
161
- draft?: boolean;
162
- [key: string]: unknown;
163
- };
164
- type ComputedFields = {
165
- contentId: string;
166
- readingTimeMinutes: number;
167
- wordCount: number;
168
- };
169
- type Article = {
170
- slug: string;
171
- locale: string;
172
- frontmatter: Frontmatter;
173
- html: string;
174
- computed: ComputedFields;
175
- };
176
- type RehypePluginEntry = readonly [unknown, Record<string, unknown>?];
177
- type RemarkPluginEntry = readonly [unknown, Record<string, unknown>?];
178
- type ContentConfig = {
179
- dir: string;
180
- defaultAuthor?: string;
181
- trustedContent: boolean;
182
- rehypePlugins?: RehypePluginEntry[];
183
- remarkPlugins?: RemarkPluginEntry[];
184
- };
185
- type ContentState = {
186
- processor: Processor | null;
187
- articles: Map<string, Map<string, Article>>;
188
- slugs: string[] | null;
189
- lastPaths: Set<string>; /** Paths marked stale by `invalidate()` — re-read on next `loadAll()` then cleared. */
190
- dirtyPaths: Set<string>;
191
- };
192
- type ContentApi = {
193
- loadAll(): Promise<Map<string, Article[]>>;
194
- load(slug: string, locale: string): Promise<Article | null>;
195
- discoverSlugs(): Promise<string[]>;
196
- render(markdown: string): Promise<string>;
197
- invalidate(paths: string[]): void;
198
- reset(): void;
199
- };
200
- //#endregion
201
- //#region src/plugins/router/types.d.ts
202
- /** @file router plugin types — RouteSpec (non-accumulating), RouteBuilder, RouterApi. */
203
- /** Render context passed to route handlers. */
204
- type RenderContext = {
205
- url: string;
206
- locale: string;
207
- params: Record<string, string>;
208
- data?: unknown;
209
- };
210
- type LayoutComponent = unknown;
211
- type VNode = unknown;
212
- type HeadConfig = unknown;
213
- type RouteSpec = {
214
- pattern: string;
215
- load?: (params: Record<string, string>) => unknown;
216
- layout?: LayoutComponent;
217
- render?: (ctx: RenderContext) => VNode;
218
- generate?: (locale: string) => Array<{
219
- params: Record<string, string>;
220
- }>;
221
- head?: (ctx: RenderContext) => HeadConfig;
222
- meta?: Record<string, unknown>;
223
- toJson?: (ctx: RenderContext) => object;
224
- toFile?: (ctx: RenderContext) => {
225
- name: string;
226
- content: string | Uint8Array;
227
- };
228
- };
229
- /**
230
- * Non-accumulating fluent builder. Methods mutate an internal spec and return `this`
231
- * typed as the same `RouteBuilder` — type information captured in `RouteSpec` shape,
232
- * not builder generics. Prevents TS inference performance collapse at 50+ routes.
233
- */
234
- type RouteBuilder = {
235
- load<T>(fn: (params: Record<string, string>) => T | Promise<T>): RouteBuilder;
236
- layout(component: LayoutComponent): RouteBuilder;
237
- render(fn: (ctx: RenderContext) => VNode): RouteBuilder;
238
- generate(fn: (locale: string) => Array<{
239
- params: Record<string, string>;
240
- }>): RouteBuilder;
241
- head(fn: (ctx: RenderContext) => HeadConfig): RouteBuilder;
242
- meta(data: Record<string, unknown>): RouteBuilder;
243
- toJson(fn: (ctx: RenderContext) => object): RouteBuilder;
244
- toFile(fn: (ctx: RenderContext) => {
245
- name: string;
246
- content: string | Uint8Array;
247
- }): RouteBuilder; /** Internal: produce the RouteSpec object. */
248
- _spec(): RouteSpec;
249
- };
250
- type RouteEntry = {
251
- name: string;
252
- spec: RouteSpec;
253
- specificity: number;
254
- };
255
- type RouterConfig<Routes extends Record<string, RouteSpec> = Record<string, RouteSpec>> = {
256
- routes: Routes;
257
- defaultPage?: keyof Routes & string;
258
- };
259
- type RouterState<Routes extends Record<string, RouteSpec> = Record<string, RouteSpec>> = {
260
- routes: Routes;
261
- entries: ReadonlyArray<RouteEntry>;
262
- };
263
- type RouterApi<Routes extends Record<string, RouteSpec> = Record<string, RouteSpec>> = {
264
- routes: Routes;
265
- toUrl<K extends keyof Routes>(name: K, params: Record<string, string>): string;
266
- match(url: string): {
267
- entry: RouteEntry;
268
- params: Record<string, string>;
269
- } | null;
270
- entries(): ReadonlyArray<RouteEntry>;
271
- };
272
- //#endregion
273
- //#region src/plugins/build/types.d.ts
274
- type BuildConfig = {
275
- outdir: string;
276
- mode: 'production' | 'development';
277
- renderMode: 'ssg' | 'spa' | 'hybrid';
278
- cssEntry?: string;
279
- jsEntry?: string;
280
- articleRouteKey?: string;
281
- sourcemap?: 'none' | 'external' | 'inline';
282
- };
283
- type BundleManifest = {
284
- cssPaths: string[];
285
- jsPaths: string[];
286
- assets: Map<string, string>;
287
- };
288
- type BuildState = {
289
- manifest: BundleManifest | null;
290
- lastResult: BuildResult | null;
291
- };
292
- type BuildResult = {
293
- pages: number;
294
- durationMs: number;
295
- manifest: BundleManifest;
296
- };
297
- type BuildApi = {
298
- run(): Promise<BuildResult>;
299
- getManifest(): Readonly<BundleManifest> | null;
300
- };
301
- //#endregion
302
- //#region src/plugins/deploy/types.d.ts
303
- /** @file deploy plugin types — DeployConfig, DeployState, DeployResult, RunOptions, DeployApi. */
304
- /**
305
- * Deployment target. Phase 1 ships `'pages'` only; `'workers'` is reserved
306
- * for the Workers Static Assets expansion path and `buildWranglerArgs`
307
- * throws "not implemented in Phase 1" if invoked with it.
308
- */
309
- type DeployTarget = 'pages' | 'workers';
310
- /**
311
- * deploy plugin config.
312
- *
313
- * `outdir` precedence at deploy time: `wrangler.jsonc#pages_build_output_dir`
314
- * (written by `moku deploy init`) — this is the deploy-time single source of
315
- * truth, NOT `DeployConfig.outdir`. The config field is the *init-time* default;
316
- * once `wrangler.jsonc` exists, it owns the value.
317
- *
318
- * Forbidden: reading the `build` plugin's config via `ctx.has(build)` /
319
- * `ctx.require(build).config.outdir`. The core `HasFunction` takes a name
320
- * string and returns a non-narrowing boolean; `RequireFunction` returns the
321
- * API surface only (`BuildApi = { run, getManifest }`). The optional coupling
322
- * is a `ctx.log.warn` at init time when divergence is detectable through the
323
- * directly-imported `build` plugin instance, never via the core API.
324
- */
325
- type DeployConfig = {
326
- /** Deployment target. Default: `'pages'`. */target: DeployTarget; /** Build output directory used at init only. Default: `'dist'` (matches build plugin default). */
327
- outdir: string; /** Production branch name. Default: `'main'`. Overwritten by `init` via `git symbolic-ref`. */
328
- productionBranch: string; /** Optional explicit override for the Cloudflare Pages project name. Default: derived from `site.name`. */
329
- projectName?: string;
330
- };
331
- /**
332
- * In-memory deploy plugin state.
333
- *
334
- * `lastDeployment` is reset per `createApp()` call and captures the most
335
- * recent deploy's metadata (URL, deployment ID, branch, duration). Used by
336
- * the future REST-API-based rollback command (deferred from Phase 1).
337
- */
338
- type DeployState = {
339
- lastDeployment: DeployResult | null;
340
- };
341
- /** Result of a successful `app.deploy.run()` invocation. */
342
- type DeployResult = {
343
- /** Production URL (e.g., `https://<project>.pages.dev`) or branch-alias preview URL. */url: string; /** Cloudflare deployment ID — captured for future rollback support. */
344
- deploymentId: string; /** Branch the deploy was published to. */
345
- branch: string; /** Total subprocess duration in milliseconds (init + upload + finalize). */
346
- durationMs: number;
347
- };
348
- /**
349
- * Options accepted by `app.deploy.run()`.
350
- *
351
- * `branch` overrides the production branch from wrangler.jsonc (defaults to
352
- * `DeployConfig.productionBranch`). `build` runs `app.build.run()` first
353
- * when true — used only for local convenience; the generated CI workflow
354
- * always issues the two-step `moku build` then `moku deploy` pattern.
355
- */
356
- type RunOptions = {
357
- /** Override the production branch for this deploy. */branch?: string; /** Run `app.build.run()` first (local convenience). Default: `false`. */
358
- build?: boolean;
359
- };
360
- /** Public deploy plugin API surface, attached as `app.deploy`. */
361
- type DeployApi = {
362
- /** Run a deploy. Reads outdir from wrangler.jsonc; errors if missing. */run(options?: RunOptions): Promise<DeployResult>; /** Read the last deployment result without re-running. */
363
- getLastDeployment(): Readonly<DeployResult> | null;
364
- };
365
- //#endregion
366
- //#region src/project.d.ts
367
- /**
368
- * Map each consumer `RouteBuilder` to the `RouteSpec` shape the router stores.
369
- *
370
- * Keys are preserved so `toUrl(name, ...)` and `defaultPage` stay typed.
371
- */
372
- type RouteSpecMap<Routes extends Record<string, RouteBuilder>> = { [K in keyof Routes]: RouteSpec };
373
- /**
374
- * Consumer-facing flat config shape.
375
- *
376
- * Generic over Routes (a record of `RouteBuilder`) so the literal route-name
377
- * keys flow through to `app.router.routes` after the wrapper assembles the app.
378
- */
379
- type WebAppConfig<Routes extends Record<string, RouteBuilder>> = {
380
- mode?: 'production' | 'development';
381
- site: SiteConfig;
382
- i18n: I18nConfig;
383
- routes: Routes;
384
- components?: ComponentDef[];
385
- spa?: {
386
- viewTransitions?: boolean;
387
- progressBar?: boolean;
388
- };
389
- ogImage?: OGImageConfig;
390
- contentDir: string;
391
- defaultPage?: keyof Routes & string;
392
- trustedContent?: boolean;
393
- };
394
- //#endregion
395
- //#region src/plugins/router/route-builder.d.ts
396
- /**
397
- * Build a `RouteSpec` via a fluent, non-accumulating builder.
398
- *
399
- * Methods mutate a single internal `RouteSpec` and return the same builder typed
400
- * as `RouteBuilder` (NOT `RouteBuilder<T>`). Type information lives on the
401
- * `RouteSpec` shape, not in builder generics — this keeps TS inference O(1) per
402
- * route and prevents the 50+ route inference collapse described in D5.
403
- *
404
- * @param pattern - URL pattern (e.g. `/about`, `/{slug}`, `/{lang:?}/{slug}/`).
405
- * @returns A `RouteBuilder` that mutates an internal spec.
406
- * @example
407
- * ```ts
408
- * const home = route('/{lang:?}/').render(({ locale }) => <Home locale={locale} />)
409
- * ```
410
- */
411
- declare function route(pattern: string): RouteBuilder;
412
- //#endregion
413
- export { EnvVarSpec as A, SiteState as C, EnvConfig as D, EnvApi as E, LogState as M, EnvProvider as O, SiteApi as S, Events as T, ContentConfig as _, DeployConfig as a, I18nConfig as b, BuildConfig as c, RouteSpec as d, RouterApi as f, ContentApi as g, Article as h, DeployApi as i, LogApi as j, EnvState as k, BuildState as l, RouterState as m, RouteSpecMap as n, DeployState as o, RouterConfig as p, WebAppConfig as r, BuildApi as s, route as t, RouteBuilder as u, ContentState as v, Config as w, I18nState as x, I18nApi as y };
package/dist/test.cjs DELETED
@@ -1,82 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_project = require('./project-1pAh4RxJ.cjs');
3
- const require_factory = require('./factory-DVcAQYEZ.cjs');
4
- const require_index = require('./index.cjs');
5
- let _moku_labs_core = require("@moku-labs/core");
6
-
7
- //#region src/test.ts
8
- /** @file Test sub-path — createTestApp + createTestLog + createTestEnv factories. NEVER module-level singletons. */
9
- /**
10
- * Returns a FRESH log core-plugin instance per call — never a shared singleton.
11
- *
12
- * Each invocation constructs a new `createCorePlugin('log', ...)` so two calls
13
- * produce two distinct plugin instances with isolated state. Use when you
14
- * need a standalone trace separate from a running app's log.
15
- *
16
- * @returns A new log core-plugin instance, forced to `mode: 'test'`.
17
- * @example
18
- * ```ts
19
- * import { createTestLog } from '@moku-labs/web/test'
20
- * const log = createTestLog()
21
- * // pass to createCore({ plugins: [log] }) for an isolated test app
22
- * ```
23
- */
24
- const createTestLog = () => (0, _moku_labs_core.createCorePlugin)("log", {
25
- config: {
26
- level: "debug",
27
- mode: "test"
28
- },
29
- createState: require_factory.createLogState,
30
- api: require_factory.createLogApi
31
- });
32
- /**
33
- * Returns a FRESH env core-plugin instance per call — never a shared singleton.
34
- *
35
- * Useful for testing env-dependent behavior in isolation: pass a stub `providers`
36
- * array of inline `{ name, load }` objects to inject deterministic values without
37
- * touching `process.env`, `.env.local`, or Cloudflare globals.
38
- *
39
- * @param config - Partial EnvConfig overrides. Defaults: empty schema, no providers, `PUBLIC_` prefix.
40
- * @returns A new env core-plugin instance.
41
- * @example
42
- * ```ts
43
- * import { createTestEnv } from '@moku-labs/web/test'
44
- * const env = createTestEnv({
45
- * schema: { PUBLIC_X: { public: true, required: true } },
46
- * providers: [{ name: 'inline', load: () => ({ PUBLIC_X: 'value' }) }],
47
- * })
48
- * // pass to createCore({ plugins: [env] }) for an isolated test app
49
- * ```
50
- */
51
- const createTestEnv = (config = {}) => (0, _moku_labs_core.createCorePlugin)("env", {
52
- config: {
53
- schema: {},
54
- providers: [],
55
- publicPrefix: "PUBLIC_",
56
- ...config
57
- },
58
- createState: require_factory.createEnvState,
59
- api: require_factory.createEnvApi,
60
- onInit: require_factory.validateSchema
61
- });
62
- /**
63
- * Returns a fresh app instance configured for tests.
64
- *
65
- * Forces `mode: 'development'` so plugins skip production-only side effects
66
- * (eager bundle, watchers) and routes consumers through the standard Layer-2
67
- * assembly so cross-plugin wiring is exercised the same way a real app would.
68
- *
69
- * @param input - The same flat `WebAppConfig` you'd pass to `createApp`.
70
- * @returns The assembled app with the consumer's typed routes.
71
- */
72
- function createTestApp(input) {
73
- return require_index.createApp({
74
- ...input,
75
- mode: "development"
76
- });
77
- }
78
-
79
- //#endregion
80
- exports.createTestApp = createTestApp;
81
- exports.createTestEnv = createTestEnv;
82
- exports.createTestLog = createTestLog;
package/dist/test.d.cts DELETED
@@ -1,61 +0,0 @@
1
- import { A as EnvVarSpec, D as EnvConfig, E as EnvApi, M as LogState, O as EnvProvider, j as LogApi, k as EnvState, r as WebAppConfig, u as RouteBuilder } from "./route-builder-CKvvehVO.cjs";
2
- import { WebApp } from "./index.cjs";
3
- import * as _moku_labs_core0 from "@moku-labs/core";
4
-
5
- //#region src/test.d.ts
6
- /**
7
- * Returns a FRESH log core-plugin instance per call — never a shared singleton.
8
- *
9
- * Each invocation constructs a new `createCorePlugin('log', ...)` so two calls
10
- * produce two distinct plugin instances with isolated state. Use when you
11
- * need a standalone trace separate from a running app's log.
12
- *
13
- * @returns A new log core-plugin instance, forced to `mode: 'test'`.
14
- * @example
15
- * ```ts
16
- * import { createTestLog } from '@moku-labs/web/test'
17
- * const log = createTestLog()
18
- * // pass to createCore({ plugins: [log] }) for an isolated test app
19
- * ```
20
- */
21
- declare const createTestLog: () => _moku_labs_core0.CorePluginInstance<"log", {
22
- level: "debug";
23
- mode: "test";
24
- }, LogState, LogApi>;
25
- /**
26
- * Returns a FRESH env core-plugin instance per call — never a shared singleton.
27
- *
28
- * Useful for testing env-dependent behavior in isolation: pass a stub `providers`
29
- * array of inline `{ name, load }` objects to inject deterministic values without
30
- * touching `process.env`, `.env.local`, or Cloudflare globals.
31
- *
32
- * @param config - Partial EnvConfig overrides. Defaults: empty schema, no providers, `PUBLIC_` prefix.
33
- * @returns A new env core-plugin instance.
34
- * @example
35
- * ```ts
36
- * import { createTestEnv } from '@moku-labs/web/test'
37
- * const env = createTestEnv({
38
- * schema: { PUBLIC_X: { public: true, required: true } },
39
- * providers: [{ name: 'inline', load: () => ({ PUBLIC_X: 'value' }) }],
40
- * })
41
- * // pass to createCore({ plugins: [env] }) for an isolated test app
42
- * ```
43
- */
44
- declare const createTestEnv: (config?: Partial<EnvConfig>) => _moku_labs_core0.CorePluginInstance<"env", {
45
- schema: Record<string, EnvVarSpec>;
46
- providers: EnvProvider[];
47
- publicPrefix: string;
48
- }, EnvState, EnvApi>;
49
- /**
50
- * Returns a fresh app instance configured for tests.
51
- *
52
- * Forces `mode: 'development'` so plugins skip production-only side effects
53
- * (eager bundle, watchers) and routes consumers through the standard Layer-2
54
- * assembly so cross-plugin wiring is exercised the same way a real app would.
55
- *
56
- * @param input - The same flat `WebAppConfig` you'd pass to `createApp`.
57
- * @returns The assembled app with the consumer's typed routes.
58
- */
59
- declare function createTestApp<Routes extends Record<string, RouteBuilder>>(input: WebAppConfig<Routes>): WebApp<Routes>;
60
- //#endregion
61
- export { createTestApp, createTestEnv, createTestLog };
package/dist/test.d.mts DELETED
@@ -1,61 +0,0 @@
1
- import { A as EnvVarSpec, D as EnvConfig, E as EnvApi, M as LogState, O as EnvProvider, j as LogApi, k as EnvState, r as WebAppConfig, u as RouteBuilder } from "./index-CddOHo8I.mjs";
2
- import { WebApp } from "./index.mjs";
3
- import * as _moku_labs_core0 from "@moku-labs/core";
4
-
5
- //#region src/test.d.ts
6
- /**
7
- * Returns a FRESH log core-plugin instance per call — never a shared singleton.
8
- *
9
- * Each invocation constructs a new `createCorePlugin('log', ...)` so two calls
10
- * produce two distinct plugin instances with isolated state. Use when you
11
- * need a standalone trace separate from a running app's log.
12
- *
13
- * @returns A new log core-plugin instance, forced to `mode: 'test'`.
14
- * @example
15
- * ```ts
16
- * import { createTestLog } from '@moku-labs/web/test'
17
- * const log = createTestLog()
18
- * // pass to createCore({ plugins: [log] }) for an isolated test app
19
- * ```
20
- */
21
- declare const createTestLog: () => _moku_labs_core0.CorePluginInstance<"log", {
22
- level: "debug";
23
- mode: "test";
24
- }, LogState, LogApi>;
25
- /**
26
- * Returns a FRESH env core-plugin instance per call — never a shared singleton.
27
- *
28
- * Useful for testing env-dependent behavior in isolation: pass a stub `providers`
29
- * array of inline `{ name, load }` objects to inject deterministic values without
30
- * touching `process.env`, `.env.local`, or Cloudflare globals.
31
- *
32
- * @param config - Partial EnvConfig overrides. Defaults: empty schema, no providers, `PUBLIC_` prefix.
33
- * @returns A new env core-plugin instance.
34
- * @example
35
- * ```ts
36
- * import { createTestEnv } from '@moku-labs/web/test'
37
- * const env = createTestEnv({
38
- * schema: { PUBLIC_X: { public: true, required: true } },
39
- * providers: [{ name: 'inline', load: () => ({ PUBLIC_X: 'value' }) }],
40
- * })
41
- * // pass to createCore({ plugins: [env] }) for an isolated test app
42
- * ```
43
- */
44
- declare const createTestEnv: (config?: Partial<EnvConfig>) => _moku_labs_core0.CorePluginInstance<"env", {
45
- schema: Record<string, EnvVarSpec>;
46
- providers: EnvProvider[];
47
- publicPrefix: string;
48
- }, EnvState, EnvApi>;
49
- /**
50
- * Returns a fresh app instance configured for tests.
51
- *
52
- * Forces `mode: 'development'` so plugins skip production-only side effects
53
- * (eager bundle, watchers) and routes consumers through the standard Layer-2
54
- * assembly so cross-plugin wiring is exercised the same way a real app would.
55
- *
56
- * @param input - The same flat `WebAppConfig` you'd pass to `createApp`.
57
- * @returns The assembled app with the consumer's typed routes.
58
- */
59
- declare function createTestApp<Routes extends Record<string, RouteBuilder>>(input: WebAppConfig<Routes>): WebApp<Routes>;
60
- //#endregion
61
- export { createTestApp, createTestEnv, createTestLog };
package/dist/test.mjs DELETED
@@ -1,79 +0,0 @@
1
- import { _ as createEnvState, g as validateSchema, h as createLogApi, m as createLogState, v as createEnvApi } from "./factory-DwpBwjDk.mjs";
2
- import "./project-BaG_ipVz.mjs";
3
- import { createApp } from "./index.mjs";
4
- import { createCorePlugin } from "@moku-labs/core";
5
-
6
- //#region src/test.ts
7
- /** @file Test sub-path — createTestApp + createTestLog + createTestEnv factories. NEVER module-level singletons. */
8
- /**
9
- * Returns a FRESH log core-plugin instance per call — never a shared singleton.
10
- *
11
- * Each invocation constructs a new `createCorePlugin('log', ...)` so two calls
12
- * produce two distinct plugin instances with isolated state. Use when you
13
- * need a standalone trace separate from a running app's log.
14
- *
15
- * @returns A new log core-plugin instance, forced to `mode: 'test'`.
16
- * @example
17
- * ```ts
18
- * import { createTestLog } from '@moku-labs/web/test'
19
- * const log = createTestLog()
20
- * // pass to createCore({ plugins: [log] }) for an isolated test app
21
- * ```
22
- */
23
- const createTestLog = () => createCorePlugin("log", {
24
- config: {
25
- level: "debug",
26
- mode: "test"
27
- },
28
- createState: createLogState,
29
- api: createLogApi
30
- });
31
- /**
32
- * Returns a FRESH env core-plugin instance per call — never a shared singleton.
33
- *
34
- * Useful for testing env-dependent behavior in isolation: pass a stub `providers`
35
- * array of inline `{ name, load }` objects to inject deterministic values without
36
- * touching `process.env`, `.env.local`, or Cloudflare globals.
37
- *
38
- * @param config - Partial EnvConfig overrides. Defaults: empty schema, no providers, `PUBLIC_` prefix.
39
- * @returns A new env core-plugin instance.
40
- * @example
41
- * ```ts
42
- * import { createTestEnv } from '@moku-labs/web/test'
43
- * const env = createTestEnv({
44
- * schema: { PUBLIC_X: { public: true, required: true } },
45
- * providers: [{ name: 'inline', load: () => ({ PUBLIC_X: 'value' }) }],
46
- * })
47
- * // pass to createCore({ plugins: [env] }) for an isolated test app
48
- * ```
49
- */
50
- const createTestEnv = (config = {}) => createCorePlugin("env", {
51
- config: {
52
- schema: {},
53
- providers: [],
54
- publicPrefix: "PUBLIC_",
55
- ...config
56
- },
57
- createState: createEnvState,
58
- api: createEnvApi,
59
- onInit: validateSchema
60
- });
61
- /**
62
- * Returns a fresh app instance configured for tests.
63
- *
64
- * Forces `mode: 'development'` so plugins skip production-only side effects
65
- * (eager bundle, watchers) and routes consumers through the standard Layer-2
66
- * assembly so cross-plugin wiring is exercised the same way a real app would.
67
- *
68
- * @param input - The same flat `WebAppConfig` you'd pass to `createApp`.
69
- * @returns The assembled app with the consumer's typed routes.
70
- */
71
- function createTestApp(input) {
72
- return createApp({
73
- ...input,
74
- mode: "development"
75
- });
76
- }
77
-
78
- //#endregion
79
- export { createTestApp, createTestEnv, createTestLog };