prunelle 0.8.0 → 0.10.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 (209) hide show
  1. package/llms.txt +68 -51
  2. package/package.json +7 -2
  3. package/src/a11y/declaration.ts +10 -17
  4. package/src/a11y/index.ts +69 -125
  5. package/src/animate.ts +127 -0
  6. package/src/build/asides.ts +51 -0
  7. package/src/build/bundle.ts +94 -136
  8. package/src/build/client-entries.ts +6 -6
  9. package/src/build/client-outputs.ts +75 -0
  10. package/src/build/client-plugin.ts +9 -4
  11. package/src/build/ecoindex.ts +4 -2
  12. package/src/build/files.ts +18 -0
  13. package/src/build/graph.ts +14 -6
  14. package/src/build/index.ts +23 -11
  15. package/src/build/island-promote.ts +42 -2
  16. package/src/build/islands.ts +63 -9
  17. package/src/build/key-types.ts +31 -0
  18. package/src/build/manifest.ts +117 -1
  19. package/src/build/plugin-host.ts +13 -1
  20. package/src/build/prerender.ts +8 -3
  21. package/src/build/reach.ts +18 -4
  22. package/src/build/report.ts +1 -1
  23. package/src/build/resolve.ts +5 -1
  24. package/src/build/route-types.ts +16 -0
  25. package/src/build/routes.ts +42 -15
  26. package/src/build/seed-ids.ts +65 -0
  27. package/src/build/seed-writes.ts +111 -0
  28. package/src/build/static-headers.ts +2 -2
  29. package/src/build/static.ts +1 -1
  30. package/src/cli/check-cache.ts +51 -0
  31. package/src/cli/check-consent.ts +95 -0
  32. package/src/cli/check-forms.ts +10 -2
  33. package/src/cli/check-links-patterns.ts +101 -0
  34. package/src/cli/check-links.ts +30 -105
  35. package/src/cli/check-regions.ts +185 -0
  36. package/src/cli/check-security.ts +50 -6
  37. package/src/cli/check.ts +49 -21
  38. package/src/cli/commands.ts +138 -16
  39. package/src/cli/docs.ts +21 -2
  40. package/src/cli/form-opaque-children.ts +40 -0
  41. package/src/cli/index.ts +1 -1
  42. package/src/cli/inspect.ts +2 -0
  43. package/src/cli/mcp-tools.ts +2 -2
  44. package/src/cli/new.ts +9 -5
  45. package/src/cli/upgrade-names.ts +14 -2
  46. package/src/cli/upgrade.ts +3 -0
  47. package/src/compiler/analyze.ts +22 -16
  48. package/src/compiler/cacheability-private.ts +13 -3
  49. package/src/compiler/cacheability.ts +24 -2
  50. package/src/compiler/compliance-contrast.ts +322 -0
  51. package/src/compiler/compliance-empty.ts +24 -0
  52. package/src/compiler/compliance-rgaa-content.ts +95 -0
  53. package/src/compiler/compliance-rgaa-criteria.ts +45 -0
  54. package/src/compiler/compliance-rgaa-pages.ts +140 -0
  55. package/src/compiler/compliance-rgaa.ts +19 -0
  56. package/src/compiler/compliance-rules.ts +72 -0
  57. package/src/compiler/compliance-third-party.ts +59 -0
  58. package/src/compiler/compliance-urls.ts +52 -0
  59. package/src/compiler/compliance.ts +61 -93
  60. package/src/compiler/cookie-inventory.ts +119 -0
  61. package/src/compiler/dom-attrs.ts +178 -22
  62. package/src/compiler/dom.ts +31 -44
  63. package/src/compiler/emit.ts +17 -6
  64. package/src/compiler/expr-context.ts +260 -207
  65. package/src/compiler/foreign-imports.ts +5 -3
  66. package/src/compiler/mistakes.ts +18 -9
  67. package/src/compiler/props-body.ts +263 -21
  68. package/src/compiler/props-pattern.ts +211 -0
  69. package/src/compiler/props.ts +324 -343
  70. package/src/compiler/signal-reads.ts +142 -29
  71. package/src/compiler/spread-handlers.ts +25 -13
  72. package/src/compiler/ssr-emit.ts +510 -0
  73. package/src/compiler/ssr-helpers.ts +165 -121
  74. package/src/compiler/ssr.ts +28 -441
  75. package/src/context.ts +14 -1
  76. package/src/dev/child.ts +1 -1
  77. package/src/dev/host-check.ts +2 -1
  78. package/src/dev/hot-islands.ts +71 -0
  79. package/src/dev/index.ts +31 -18
  80. package/src/dev/protocol.ts +1 -1
  81. package/src/dev/queue.ts +3 -2
  82. package/src/dev/reload.ts +5 -2
  83. package/src/dev/supervisor.ts +3 -1
  84. package/src/dev/watchers.ts +6 -2
  85. package/src/dom/action.ts +97 -14
  86. package/src/dom/attrs.ts +93 -25
  87. package/src/dom/extras.ts +91 -50
  88. package/src/dom/field-marks.ts +32 -0
  89. package/src/dom/hot.ts +9 -0
  90. package/src/dom/index.ts +44 -18
  91. package/src/dom/island-hot.ts +29 -0
  92. package/src/dom/island.ts +13 -2
  93. package/src/dom/loop.ts +259 -188
  94. package/src/dom/prefetch.ts +135 -0
  95. package/src/dom/regions.ts +515 -0
  96. package/src/dom/swap.ts +246 -0
  97. package/src/dom/trusted.ts +22 -0
  98. package/src/dom/upload.ts +44 -0
  99. package/src/eco/declaration.ts +44 -41
  100. package/src/eco/index.ts +8 -5
  101. package/src/href.ts +31 -0
  102. package/src/index.ts +12 -5
  103. package/src/plugins/config.ts +1 -1
  104. package/src/plugins/context.ts +7 -1
  105. package/src/plugins/daily.ts +27 -0
  106. package/src/plugins/index.ts +3 -3
  107. package/src/plugins/order.ts +1 -1
  108. package/src/plugins/public.ts +12 -5
  109. package/src/plugins/services.ts +88 -14
  110. package/src/plugins/types.ts +128 -10
  111. package/src/reactivity/graph.ts +244 -41
  112. package/src/reactivity/hmr.ts +101 -0
  113. package/src/reactivity/index.ts +243 -239
  114. package/src/reactivity/resource.ts +129 -0
  115. package/src/reactivity/seed.ts +141 -0
  116. package/src/reactivity/selector.ts +85 -47
  117. package/src/reactivity/server-seed.ts +202 -0
  118. package/src/reactivity/store.ts +331 -97
  119. package/src/rgpd/draft.ts +171 -0
  120. package/src/rgpd/forms.ts +85 -0
  121. package/src/rgpd/index.ts +57 -0
  122. package/src/server/action-flash.ts +1 -0
  123. package/src/server/action-protect.ts +3 -0
  124. package/src/server/action-registry.ts +11 -9
  125. package/src/server/action.ts +51 -19
  126. package/src/server/app-secret.ts +14 -8
  127. package/src/server/cache-invalidation.ts +97 -0
  128. package/src/server/compress.ts +55 -18
  129. package/src/server/consent.ts +21 -5
  130. package/src/server/cookie-inventory.ts +78 -0
  131. package/src/server/cookies.ts +77 -8
  132. package/src/server/cors.ts +98 -0
  133. package/src/server/csp-report.ts +90 -0
  134. package/src/server/discard.ts +13 -0
  135. package/src/server/document.ts +2 -2
  136. package/src/server/env.ts +1 -1
  137. package/src/server/errors.ts +9 -2
  138. package/src/server/field-errors.ts +91 -0
  139. package/src/server/form-schema.ts +16 -11
  140. package/src/server/health.ts +41 -11
  141. package/src/server/http.ts +28 -11
  142. package/src/server/index.ts +122 -307
  143. package/src/server/loader.ts +2 -0
  144. package/src/server/page.ts +3 -9
  145. package/src/server/plugin-host.ts +66 -16
  146. package/src/server/plugin-route-shadow.ts +24 -0
  147. package/src/server/public.ts +14 -3
  148. package/src/server/rate-limit.ts +49 -10
  149. package/src/server/region.ts +22 -2
  150. package/src/server/request-handler.ts +406 -0
  151. package/src/server/request-log.ts +94 -0
  152. package/src/server/route-cache.ts +55 -8
  153. package/src/server/route-input.ts +54 -0
  154. package/src/server/route-table.ts +53 -27
  155. package/src/server/router.ts +2 -1
  156. package/src/server/routing.ts +104 -45
  157. package/src/server/sanitize-html.ts +4 -2
  158. package/src/server/security.ts +38 -8
  159. package/src/server/serve-handlers.ts +16 -6
  160. package/src/server/served-file.ts +19 -14
  161. package/src/server/shared-store.ts +323 -0
  162. package/src/server/start.ts +12 -5
  163. package/src/server/static-dir.ts +34 -12
  164. package/src/server/stream.ts +2 -1
  165. package/src/server/surface.ts +39 -0
  166. package/src/server/webhook.ts +50 -0
  167. package/src/server/workers.ts +168 -0
  168. package/src/ssr/consent-banner.ts +20 -16
  169. package/src/ssr/consent-texts.ts +40 -0
  170. package/src/ssr/context.ts +174 -53
  171. package/src/ssr/cookie-table.ts +75 -0
  172. package/src/ssr/index.ts +63 -58
  173. package/src/ssr/navigation.ts +161 -14
  174. package/src/ssr/region.ts +9 -3
  175. package/src/style.ts +12 -5
  176. package/src/test/browser.ts +53 -23
  177. package/src/test/build-reuse.ts +85 -0
  178. package/src/test/index.ts +51 -8
  179. package/src/test/mount.ts +53 -0
  180. package/src/test/outside.ts +94 -0
  181. package/src/ts-plugin/diagnostics.ts +56 -18
  182. package/templates/_shared/AGENTS.md +1 -1
  183. package/templates/_shared/Dockerfile +22 -0
  184. package/templates/_shared/dockerignore +9 -0
  185. package/templates/_shared/gitignore +2 -0
  186. package/templates/app/.env.example +3 -1
  187. package/templates/app/compose.yaml +32 -0
  188. package/templates/app/db/migrations/001_notes.sql +7 -0
  189. package/templates/app/db/schema.ts +11 -0
  190. package/templates/app/package.json +1 -0
  191. package/templates/app/prunelle.config.ts +6 -0
  192. package/templates/app/src/actions/notes.ts +26 -0
  193. package/templates/app/src/auth.ts +4 -2
  194. package/templates/app/src/db.ts +5 -0
  195. package/templates/app/src/routes/dashboard/index.tsx +26 -1
  196. package/templates/app/src/routes/privacy.tsx +6 -2
  197. package/templates/app/tests/app.test.ts +14 -3
  198. package/templates/plugin/AGENTS.md +11 -0
  199. package/templates/plugin/CLAUDE.md +1 -0
  200. package/templates/plugin/README.md +27 -0
  201. package/templates/plugin/gitignore +2 -0
  202. package/templates/plugin/llms.txt +19 -0
  203. package/templates/plugin/package.json +33 -0
  204. package/templates/plugin/src/index.ts +40 -0
  205. package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
  206. package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
  207. package/templates/plugin/tests/plugin.test.ts +42 -0
  208. package/templates/plugin/tsconfig.json +19 -0
  209. package/ts-plugin.cjs +4058 -2246
@@ -1,7 +1,8 @@
1
1
  // Per-build / per-server scoped runtime context (AsyncLocalStorage-backed, zero mutable process globals).
2
2
 
3
- import type { ServiceKey } from './services'
3
+ import type { ServiceKey, UserDataService } from './services'
4
4
  import { AsyncLocalStorage } from 'node:async_hooks'
5
+ import { mergeUserDataServices, USER_DATA_SERVICE } from './services'
5
6
 
6
7
  export interface AppRuntimeContext {
7
8
  readonly root: string
@@ -46,6 +47,11 @@ export function createAppContext(options: CreateAppContextOptions): AppRuntimeCo
46
47
  ...(options.nodeEnv !== undefined ? { nodeEnv: options.nodeEnv } : {}),
47
48
  // Keyed by name: the natively loaded config and the bundled app each hold their own key object.
48
49
  provide<T>(key: ServiceKey<T>, value: T): void {
50
+ if (key.name === USER_DATA_SERVICE.name && value !== undefined) {
51
+ const existing = services.get(key.name) as UserDataService | undefined
52
+ services.set(key.name, mergeUserDataServices(existing, value as unknown as UserDataService))
53
+ return
54
+ }
49
55
  services.set(key.name, value)
50
56
  },
51
57
  inject<T>(key: ServiceKey<T>): T | undefined {
@@ -0,0 +1,27 @@
1
+ // A plugin's daily chore (a retention purge): on `@prunellejs/jobs` when the app has it, else in each process.
2
+
3
+ import type { ServerPluginAPI } from './types'
4
+ import { JOBS_SERVICE } from './services'
5
+
6
+ const DAY_MS = 86_400_000
7
+ // `prunelle check` and `prunelle inspect` start each plugin's server to list its routes and stop it at once: a chore waiting a minute never runs there.
8
+ const FIRST_RUN_MS = 60_000
9
+
10
+ /** Runs `chore` daily at `cron` on `@prunellejs/jobs` when the app has it; without it, a minute after start then every day in this process, logging `failure` when it throws. */
11
+ export function scheduleDaily(api: ServerPluginAPI, name: string, cron: string, chore: () => Promise<unknown>, failure: string): void {
12
+ const jobs = api.inject(JOBS_SERVICE)
13
+ if (jobs?.schedule !== undefined) {
14
+ jobs.schedule(name, cron, async () => {
15
+ await chore()
16
+ })
17
+ return
18
+ }
19
+ const run = (): void => void chore().catch((error: unknown) => console.error(failure, error))
20
+ let timer = setTimeout(() => {
21
+ run()
22
+ timer = setInterval(run, DAY_MS)
23
+ timer.unref()
24
+ }, FIRST_RUN_MS)
25
+ timer.unref()
26
+ api.onShutdown(() => clearTimeout(timer))
27
+ }
@@ -7,8 +7,8 @@ export { createAppContext, getAppContext, runWithAppContext } from './context'
7
7
  export type { AppRuntimeContext, CreateAppContextOptions } from './context'
8
8
  export { loadConfig } from './load'
9
9
  export { resolvePlugins } from './order'
10
- export { CMS_INLINE_ENABLED_SERVICE, CONTENT_COLLECTIONS_SERVICE, CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, JOBS_SERVICE, WEB_MANIFEST_SERVICE, serviceKey } from './services'
11
- export type { AccessedContentEntry, ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, ServiceKey, WebManifestIcon, WebManifestInfo } from './services'
10
+ export { CONTENT_COLLECTIONS_SERVICE, CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, JOBS_SERVICE, registerUserDataService, USER_DATA_SERVICE, WEB_MANIFEST_SERVICE, serviceKey } from './services'
11
+ export type { ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, ServiceKey, UserDataService, WebManifestIcon, WebManifestInfo } from './services'
12
12
  export type { ComplianceConfig, ComplianceRule } from '../compiler/compliance'
13
13
  export type { ConsentConfig } from '../server/consent'
14
- export type { BuildPluginContext, BuildPluginTarget, CheckPluginContext, DocumentHeadContext, FinalizeBuildContext, PrunelleConfig, PrunellePlugin, MiddlewareOptions, PluginRouteOptions, RequiresPluginContext, ServerErrorInfo, ServerPluginAPI, ServerRuntimeConfig } from './types'
14
+ export type { AppSurface, BuildPluginContext, BuildPluginTarget, CheckPluginContext, CookieDeclaration, DocumentHeadContext, FinalizeBuildContext, ProcessingDeclaration, PrunelleConfig, PrunellePlugin, MiddlewareOptions, PluginRouteOptions, RequestPhase, RequestRecord, RequiresPluginContext, ServerErrorInfo, ServerPluginAPI, ServerRuntimeConfig, SurfaceAction, SurfaceInput, SurfaceRoute, LogConfig } from './types'
@@ -16,7 +16,7 @@ function splitScope(name: string): { scope: string | undefined, pkg: string } {
16
16
  return { scope: undefined, pkg: name }
17
17
  }
18
18
 
19
- // Compares scoped plugin names without their shared `@scope/` prefix so short official plugins (`@prunellejs/cms` vs `@prunellejs/mcp`, `@prunellejs/seo` vs `@prunellejs/spa`) never false-positive as typos.
19
+ // Compares scoped plugin names without their shared `@scope/` prefix so short official plugins (`@prunellejs/pwa` vs `@prunellejs/spa`, `@prunellejs/seo` vs `@prunellejs/spa`) never false-positive as typos.
20
20
  function closestPluginName(depName: string, names: readonly string[]): string | undefined {
21
21
  const dep = splitScope(depName)
22
22
  if (dep.scope === undefined)
@@ -1,15 +1,22 @@
1
1
  // `prunelle/config`: what `prunelle.config.ts` and plugin packages use.
2
2
 
3
- export { a11y, auditAccessibility, draftAccessibilityStatement, formatA11yReport, rgaaCriteriaForAxeRule } from '../a11y/index'
4
- export type { A11yAuditOptions, A11yAuditReport, A11yImpact, A11yPluginOptions, A11yRouteReport, A11yViolation, A11yViolationNode, AccessibilityDeclarationOptions, AccessibilityDeclarationResult, ComplianceStatus, RgaaCriterion } from '../a11y/index'
3
+ // Declared here, the file `prunelle/config` resolves to: an augmentation reaches an interface only where it is declared, not through a re-export.
4
+ /** The warning rules plugins report from `check(ctx)`, each a key `compliance.ignore` accepts; a plugin adds its own with `declare module 'prunelle/config' { interface PrunellePluginRules { 'pwa/manifest-missing': true } }`. */
5
+ export interface PrunellePluginRules {}
6
+
7
+ export { auditAccessibility, draftAccessibilityStatement, formatA11yReport, rgaaCriteriaForAxeRule } from '../a11y/index'
8
+ export type { A11yAuditOptions, A11yAuditReport, A11yImpact, A11yRouteReport, A11yViolation, A11yViolationNode, AccessibilityDeclarationOptions, AccessibilityDeclarationResult, ComplianceStatus, RgaaCriterion } from '../a11y/index'
5
9
  export { isInside } from '../build/is-inside'
6
10
  export { distLocator, firstLoadUrls, measureFirstLoad } from '../build/first-load'
7
11
  export type { FirstLoad, Locate } from '../build/first-load'
8
12
  export { brotliSize } from '../build/precompress'
13
+ export { writeKeyTypes } from '../build/key-types'
14
+ export type { KeyTypes } from '../build/key-types'
9
15
  export { minifyCss } from '../build/style-bundles'
10
16
  export { defineConfig, definePlugin } from './config'
11
- export { CMS_INLINE_ENABLED_SERVICE, CONTENT_COLLECTIONS_SERVICE, CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, JOBS_SERVICE, serviceKey, UI_KUI_LAYER_SERVICE, WEB_MANIFEST_SERVICE } from './services'
12
- export type { AccessedContentEntry, ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, ServiceKey, WebManifestIcon, WebManifestInfo } from './services'
17
+ export { scheduleDaily } from './daily'
18
+ export { CONTENT_COLLECTIONS_SERVICE, CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, JOBS_SERVICE, PUBLIC_FILES_SERVICE, registerUserDataService, serviceKey, UI_LAYER_SERVICE, USER_DATA_SERVICE, WEB_MANIFEST_SERVICE } from './services'
19
+ export type { ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, PublicFile, PublicFilesService, ServiceKey, UserDataService, WebManifestIcon, WebManifestInfo } from './services'
13
20
  export type { ComplianceConfig, ComplianceRule } from '../compiler/compliance'
14
21
  export type { ConsentConfig } from '../server/consent'
15
- export type { BudgetConfig, BuildPluginContext, BuildPluginTarget, CheckPluginContext, DocumentHeadContext, FinalizeBuildContext, PrunelleConfig, PrunellePlugin, MiddlewareOptions, PluginRouteOptions, RequiresPluginContext, ServerErrorInfo, ServerPluginAPI, ServerRuntimeConfig } from './types'
22
+ export type { AppSurface, BudgetConfig, BuildPluginContext, BuildPluginTarget, CheckPluginContext, CookieDeclaration, DocumentHeadContext, FinalizeBuildContext, ProcessingDeclaration, PrunelleConfig, PrunellePlugin, MiddlewareOptions, PluginRouteOptions, RequestPhase, RequestRecord, RequiresPluginContext, ServerErrorInfo, ServerPluginAPI, ServerRuntimeConfig, SurfaceAction, SurfaceInput, SurfaceRoute, LogConfig } from './types'
@@ -1,6 +1,5 @@
1
1
  // Service keys: `serviceKey` for any plugin, and the keys shared between two plugins, kept in core as contracts so neither depends on the other.
2
2
 
3
- import type { RequestContext } from '../server/http'
4
3
  import type { StandardSchemaV1 } from '../server/standard-schema'
5
4
 
6
5
  declare const SERVICE_TYPE: unique symbol
@@ -23,8 +22,8 @@ export interface ActiveI18nConfig {
23
22
 
24
23
  export const I18N_CONFIG_SERVICE = serviceKey<ActiveI18nConfig>('prunelle.i18n.config')
25
24
 
26
- /** Set by `@prunellejs/ui` when it emits its grammar layer, so `@prunellejs/tailwind` places the `kui` layer between its base and utilities layers. */
27
- export const UI_KUI_LAYER_SERVICE = serviceKey<boolean>('prunelle.ui.kuiLayer')
25
+ /** Set by `@prunellejs/ui` when it emits its grammar layer, so `@prunellejs/tailwind` places the `pru-ui` layer between its base and utilities layers. */
26
+ export const UI_LAYER_SERVICE = serviceKey<boolean>('prunelle.ui.layer')
28
27
 
29
28
  export interface ContentImageResult {
30
29
  src: string
@@ -64,24 +63,13 @@ export interface ContentCollectionDescriptor {
64
63
  clearCache(): void
65
64
  }
66
65
 
67
- export interface AccessedContentEntry {
68
- readonly collection: string
69
- readonly slug: string
70
- readonly locale?: string | undefined
71
- }
72
-
73
66
  export interface ContentCollectionsService {
74
67
  list(root?: string): readonly ContentCollectionDescriptor[] | Promise<readonly ContentCollectionDescriptor[]>
75
68
  discover?(root: string): Promise<readonly ContentCollectionDescriptor[]>
76
- /** Returns file-backed content entries accessed during the given dev request (primary `get()` entries first). */
77
- accessedEntries?(ctx: RequestContext): readonly AccessedContentEntry[]
78
69
  }
79
70
 
80
71
  export const CONTENT_COLLECTIONS_SERVICE = serviceKey<ContentCollectionsService>('prunelle.content.collections')
81
72
 
82
- /** Provided by `@prunellejs/cms` in dev mode when in-page editing is enabled so `@prunellejs/content` emits body anchor comments. */
83
- export const CMS_INLINE_ENABLED_SERVICE = serviceKey<boolean>('prunelle.cms.inline')
84
-
85
73
  export interface JobsQueueOptions {
86
74
  attempts?: number | undefined
87
75
  backoff?: 'exponential' | 'fixed' | number | undefined
@@ -97,10 +85,80 @@ export interface JobsService {
97
85
  queue<T = unknown>(name: string, handler: (data: T) => void | Promise<void>, options?: JobsQueueOptions): void
98
86
  enqueue<T = unknown>(name: string, data: T, options?: JobsEnqueueOptions): Promise<void> | void
99
87
  drain?(options?: { now?: number | undefined, includeDelayed?: boolean | undefined }): Promise<number>
88
+ /** Runs `handler` on a 5-field cron, in one process of the app per tick. */
89
+ schedule?(name: string, cron: string, handler: () => void | Promise<void>, options?: { timeZone?: string | undefined }): void
100
90
  }
101
91
 
102
92
  export const JOBS_SERVICE = serviceKey<JobsService>('prunelle.jobs.service')
103
93
 
94
+ /** The rows a plugin keeps about one user, which `@prunellejs/auth` adds to an account's export and erases with it. */
95
+ export interface UserDataService {
96
+ /** Keyed by where the rows come from, such as a table name. */
97
+ exportUser(userId: string): Promise<Record<string, unknown>>
98
+ /** A throw keeps the account. */
99
+ deleteUser(userId: string): Promise<void>
100
+ }
101
+
102
+ /** Provided by plugins keeping personal data (such as `@prunellejs/db` and `@prunellejs/files`), read by `@prunellejs/auth` when it exports or deletes an account. */
103
+ export const USER_DATA_SERVICE = serviceKey<UserDataService>('prunelle.userData')
104
+
105
+ const USER_DATA_PROVIDERS = Symbol.for('prunelle.userData.providers')
106
+
107
+ interface CompositeUserDataService extends UserDataService {
108
+ readonly [USER_DATA_PROVIDERS]: UserDataService[]
109
+ }
110
+
111
+ function providersOf(service: UserDataService): readonly UserDataService[] {
112
+ return USER_DATA_PROVIDERS in service ? (service as CompositeUserDataService)[USER_DATA_PROVIDERS] : [service]
113
+ }
114
+
115
+ /** Merges two `UserDataService` providers into one that runs every registered provider's `exportUser` and `deleteUser`. */
116
+ export function mergeUserDataServices(existing: UserDataService | undefined, added: UserDataService): UserDataService {
117
+ if (existing === undefined)
118
+ return added
119
+ const incoming = providersOf(added)
120
+ if (USER_DATA_PROVIDERS in existing) {
121
+ const list = (existing as CompositeUserDataService)[USER_DATA_PROVIDERS]
122
+ for (const provider of incoming) {
123
+ if (!list.includes(provider))
124
+ list.push(provider)
125
+ }
126
+ return existing
127
+ }
128
+ const providers: UserDataService[] = [existing]
129
+ for (const provider of incoming) {
130
+ if (!providers.includes(provider))
131
+ providers.push(provider)
132
+ }
133
+ if (providers.length === 1)
134
+ return existing
135
+ const composite: CompositeUserDataService = {
136
+ [USER_DATA_PROVIDERS]: providers,
137
+ async exportUser(userId) {
138
+ const out: Record<string, unknown> = {}
139
+ for (const provider of providers)
140
+ Object.assign(out, await provider.exportUser(userId))
141
+ return out
142
+ },
143
+ async deleteUser(userId) {
144
+ for (const provider of providers)
145
+ await provider.deleteUser(userId)
146
+ },
147
+ }
148
+ return composite
149
+ }
150
+
151
+ /** Registers an RGPD user-data provider so `api.inject(USER_DATA_SERVICE)` merges exports and runs deletions across every registered plugin. */
152
+ export function registerUserDataService(
153
+ api: { provide<T>(key: ServiceKey<T>, value: T): void, inject<T>(key: ServiceKey<T>): T | undefined },
154
+ service: UserDataService,
155
+ ): void {
156
+ const existing = api.inject(USER_DATA_SERVICE)
157
+ const merged = mergeUserDataServices(existing, service)
158
+ if (merged !== existing)
159
+ api.provide(USER_DATA_SERVICE, merged)
160
+ }
161
+
104
162
  export interface WebManifestIcon {
105
163
  readonly src: string
106
164
  readonly sizes?: string | undefined
@@ -118,3 +176,19 @@ export interface WebManifestInfo {
118
176
  }
119
177
 
120
178
  export const WEB_MANIFEST_SERVICE = serviceKey<WebManifestInfo>('prunelle.webManifest')
179
+
180
+ /** A public uploaded file, found by the path it is served at. */
181
+ export interface PublicFile {
182
+ readonly contentType: string
183
+ /** Changes whenever the bytes do. */
184
+ readonly etag: string
185
+ bytes(): Promise<Uint8Array<ArrayBuffer>>
186
+ }
187
+
188
+ export interface PublicFilesService {
189
+ /** The public file served at `path` (`/files/avatars/a.jpg`); undefined for a path it does not serve, a missing file and a private one. */
190
+ find(path: string): Promise<PublicFile | undefined>
191
+ }
192
+
193
+ /** Provided by `@prunellejs/files`, read by `@prunellejs/images` to resize an upload. */
194
+ export const PUBLIC_FILES_SERVICE = serviceKey<PublicFilesService>('prunelle.files.public')
@@ -4,7 +4,8 @@ import type { BunPlugin } from 'bun'
4
4
  import type { RouteManifestEntry } from '../build/index'
5
5
  import type { ComplianceConfig } from '../compiler/compliance'
6
6
  import type { ConsentConfig } from '../server/consent'
7
- import type { HealthCheckConfig, HealthCheckFn, HealthCheckResult } from '../server/health'
7
+ import type { CorsConfig } from '../server/cors'
8
+ import type { HealthCheckConfig, HealthCheckFn, HealthCheckResult, RequestPhaseName } from '../server/health'
8
9
  import type { Middleware, RequestContext } from '../server/index'
9
10
  import type { RateLimit, RateLimiter } from '../server/rate-limit'
10
11
  import type { RouteCacheOptions } from '../server/route-cache'
@@ -18,6 +19,8 @@ export type BuildPluginTarget = 'client' | 'server' | 'compile'
18
19
 
19
20
  export interface BuildPluginContext {
20
21
  readonly root: string
22
+ /** The app's routes folder, absolute (`src/routes` unless the config moves it). */
23
+ readonly routesDir?: string | undefined
21
24
  readonly outDir: string
22
25
  readonly assetPrefix: string
23
26
  readonly site?: string | undefined
@@ -86,6 +89,8 @@ export interface CheckPluginContext {
86
89
  readonly routesDir: string
87
90
  /** The app's own static folder (`publicDir`, `public/` by default), as `prunelle check` resolved it. */
88
91
  readonly publicDir?: string | undefined
92
+ /** The app's `site` from `prunelle.config.ts`, left out when it sets none. */
93
+ readonly site?: string | undefined
89
94
  /** Report a validation error from `prunelle check`. */
90
95
  error(message: string): void
91
96
  /** Report what may be intended but usually is not; `prunelle check --strict` fails on it. */
@@ -102,6 +107,8 @@ export interface RequiresPluginContext {
102
107
  readonly site: string | undefined
103
108
  /** The categories `consent.categories` declares, `essential` left out; empty when the app declares none. */
104
109
  readonly consentCategories: readonly string[]
110
+ /** `PrunelleConfig.store`, when the app sets it: a plugin that keeps data can use the same database. */
111
+ readonly store?: string | undefined
105
112
  }
106
113
 
107
114
  export interface PluginRouteOptions {
@@ -128,6 +135,37 @@ export interface MiddlewareOptions {
128
135
  * A path prefix runs on the pathnames under it.
129
136
  */
130
137
  scope?: 'all' | 'rendered' | 'dynamic' | string | undefined
138
+ /** When `scope` is a path, match only that exact path rather than its subpaths (e.g. `{ scope: '/', exact: true }`). */
139
+ exact?: boolean | undefined
140
+ }
141
+
142
+ /** What an action or an API route takes: no schema, a schema with its JSON Schema, or a schema whose library gives none (`vendor` names it). */
143
+ export type SurfaceInput =
144
+ | { readonly kind: 'none' }
145
+ | { readonly kind: 'json', readonly schema: Readonly<Record<string, unknown>> }
146
+ | { readonly kind: 'unsupported', readonly vendor: string, /** What the library threw converting the schema, when it has a converter that failed. */ readonly reason?: string | undefined }
147
+
148
+ /** A server action as an outside client calls it: `POST url`. */
149
+ export interface SurfaceAction {
150
+ /** The export's name. */
151
+ readonly name: string
152
+ readonly url: string
153
+ readonly input: SurfaceInput
154
+ /** The calls one client may make, when the action limits them. */
155
+ readonly rateLimited: boolean
156
+ }
157
+
158
+ /** An API route (a route with method exports and no page): `input` is its `export const schema`, the body of a method that takes one and the query of `GET`. */
159
+ export interface SurfaceRoute {
160
+ /** Such as `/api/users/:id`. */
161
+ readonly path: string
162
+ readonly methods: readonly string[]
163
+ readonly input: SurfaceInput
164
+ }
165
+
166
+ export interface AppSurface {
167
+ readonly actions: readonly SurfaceAction[]
168
+ readonly routes: readonly SurfaceRoute[]
131
169
  }
132
170
 
133
171
  export interface ServerPluginAPI {
@@ -138,7 +176,7 @@ export interface ServerPluginAPI {
138
176
  readonly dev: boolean
139
177
  /** True when `prunelle dev --host` binds an address other machines reach (`0.0.0.0`, a LAN address): a dev-only route that writes or reveals data then needs a guard. */
140
178
  readonly devExposed: boolean
141
- /** Readonly server security configuration so plugins inherit `trustProxy` / `trustedOrigins` without overriding them. */
179
+ /** Readonly server security configuration so plugins inherit `trustProxy` / `trustedOrigins` without overriding them; `trustedOrigins` also holds the origins `cors` lists. */
142
180
  readonly trustProxy: TrustProxy
143
181
  readonly trustedOrigins: readonly string[]
144
182
  /** Readonly runtime config forwarded from `prunelle.config.ts` (minus build-only keys). */
@@ -147,8 +185,8 @@ export interface ServerPluginAPI {
147
185
  use(middleware: Middleware, options?: MiddlewareOptions): void
148
186
  /** Register a custom HTTP route (e.g. GET /sitemap.xml, POST /auth/callback). */
149
187
  route(method: string, path: string, handler: (ctx: RequestContext) => Response | Promise<Response>, options?: PluginRouteOptions): void
150
- /** A limiter counting in this server's store, for limits a route option cannot express (per account, per email): `hit(key)` returns 0, or the seconds to wait, and `peek(key)` answers the same without counting. */
151
- rateLimiter(limit: Pick<RateLimit, 'max' | 'windowMs'>): RateLimiter
188
+ /** A limiter counting in this server's store, for limits a route option cannot express (per account, per email): `await hit(key)` returns 0, or the seconds to wait, and `peek(key)` answers the same without counting. With a shared `store`, every process counts one window per `name` (default: the plugin's name and the call's order). */
189
+ rateLimiter(limit: Pick<RateLimit, 'max' | 'windowMs'>, name?: string): RateLimiter
152
190
  /** Rewrite an incoming pathname before route matching (e.g. strip /fr locale prefix). */
153
191
  rewrite(fn: (pathname: string, ctx: RequestContext) => string | undefined): void
154
192
  /** Register a server-scoped service for other plugins or render-time helpers (isolated per server instance). */
@@ -161,12 +199,47 @@ export interface ServerPluginAPI {
161
199
  healthCheck(name: string, fn: HealthCheckFn): void
162
200
  /** Register a shutdown cleanup callback run when `app.dispose()` is called (dev reloads, tests, graceful exit). */
163
201
  onShutdown(fn: () => void | Promise<void>): void
202
+ /** The app's server actions and API routes with the JSON Schema of their input, for a plugin that describes them to outside clients. Read it when a request needs it: a dev server reloads the modules. */
203
+ surface(): AppSurface
204
+ /** Hear each request once its response is ready, with its status, duration and phases (traces, metrics). A server with no such hook and no access log measures nothing. */
205
+ onRequestEnd(fn: (record: RequestRecord) => void): void
206
+ }
207
+
208
+ /** One phase of a request: `middleware` is the time spent in middlewares before and after the page, drawn from where the chain began. */
209
+ export interface RequestPhase {
210
+ name: RequestPhaseName
211
+ /** Milliseconds since the epoch. */
212
+ start: number
213
+ duration: number
214
+ }
215
+
216
+ /** A request the server answered, as the access log and `onRequestEnd` hooks hear it. */
217
+ export interface RequestRecord {
218
+ request: Request
219
+ requestId: string | undefined
220
+ status: number
221
+ /** When the request arrived, in milliseconds since the epoch. */
222
+ start: number
223
+ /** Milliseconds until the response was ready to send; a streamed body goes on after. */
224
+ duration: number
225
+ /** The phases the request went through, in the order they began: none for a file or a prerendered page. */
226
+ phases: readonly RequestPhase[]
227
+ /** The route template that answered (`/reset/:token`), a page's or a plugin's: none for a file, a prerendered page or no match. */
228
+ route?: string | undefined
229
+ }
230
+
231
+ export interface LogConfig {
232
+ /** `'json'` prints each unhandled error as one JSON line with its request id, source, method and path (default `'text'`). */
233
+ format?: 'text' | 'json' | undefined
234
+ /** Prints one line per request to stdout: method, path (never the query), status, duration and request id. */
235
+ access?: boolean | undefined
164
236
  }
165
237
 
166
238
  export interface ServerErrorInfo {
167
239
  error: unknown
168
240
  request: Request
169
- source: 'route' | 'action' | 'plugin'
241
+ /** `'csp'` is a violation report the browser sent under `security.cspReports`: `error.cause` holds its `directive`, `blockedUrl`, `page`, and `sourceFile` and `line` when the browser gave them. */
242
+ source: 'route' | 'action' | 'plugin' | 'csp'
170
243
  requestId?: string | undefined
171
244
  }
172
245
 
@@ -183,6 +256,39 @@ export interface DocumentHeadContext {
183
256
  add(html: string): void
184
257
  }
185
258
 
259
+ /** A cookie a plugin sets, listed by `<CookieTable>`. */
260
+ export interface CookieDeclaration {
261
+ name: string
262
+ /** What the cookie is for: one text, or one per language such as `{ en: 'Keeps you signed in.', fr: 'Vous garde connecté.' }`. */
263
+ purpose: string | Readonly<Record<string, string>>
264
+ /** `'essential'`, or the consent category the cookie waits for. */
265
+ category: string
266
+ /** Lifetime in seconds; left out for a cookie that ends with the browser session. */
267
+ maxAge?: number | undefined
268
+ }
269
+
270
+ /** Personal data a plugin processes, which `prunelle rgpd --draft` writes into the privacy notice and the record of processing; in French, as both are. */
271
+ export interface ProcessingDeclaration {
272
+ /** Such as `'Comptes et connexion'`. */
273
+ name: string
274
+ /** What the data is used for (finalité). */
275
+ purpose: string
276
+ /** Whose data it is, such as `'les personnes inscrites'`; left out, the publisher writes it. */
277
+ people?: string | undefined
278
+ /** One item per kind of data, such as `['adresse e-mail', 'empreinte du mot de passe']`. */
279
+ data: readonly string[]
280
+ /** The RGPD art. 6 basis, when the plugin can tell; left out, the publisher writes it. */
281
+ legalBasis?: string | undefined
282
+ /** How long the data is kept. */
283
+ retention?: string | undefined
284
+ /** Who else receives it, such as the mail provider. */
285
+ recipients?: readonly string[] | undefined
286
+ /** What protects it, for the record of processing. */
287
+ security?: readonly string[] | undefined
288
+ /** Paths whose forms feed this processing, such as `'/auth/'`: a form posting under one is not listed again as the app's own. */
289
+ formActions?: readonly string[] | undefined
290
+ }
291
+
186
292
  export interface PrunellePlugin {
187
293
  name: string
188
294
  /** Execution phase: `'pre'` runs before normal plugins, `'post'` runs after them. */
@@ -204,9 +310,11 @@ export interface PrunellePlugin {
204
310
  /** Code transform run during client & server compilation (`.ts` and `.tsx`). */
205
311
  transform?: (code: string, id: string, target: 'server' | 'client') => string | undefined | void
206
312
  /** Native Bun.build plugins (e.g. bun-plugin-tailwind, images, icons). Factory is invoked per build target. */
207
- bunPlugins?: BunPlugin[] | ((info: { root: string, assetPrefix: string, minify: boolean, target: BuildPluginTarget, lang?: string | undefined }) => BunPlugin[]) | undefined
313
+ bunPlugins?: BunPlugin[] | ((info: { root: string, assetPrefix: string, minify: boolean, target: BuildPluginTarget, lang?: string | undefined, multiLocale?: boolean | undefined }) => BunPlugin[]) | undefined
208
314
  /** Global CSS files to bundle and inject as <link rel="stylesheet"> in <head>. */
209
315
  css?: string[] | undefined
316
+ /** Set `true` when this plugin scans app source files (e.g. Tailwind utility classes) to produce client CSS, so `prunelle dev` rebuilds client CSS on static `.tsx`/`.ts` edits. */
317
+ affectsClientCss?: boolean | undefined
210
318
  /** Mutate `<html lang>`, `htmlAttrs`, `<title>`, or append tags to `<head>` before core renders the document once. */
211
319
  head?: (head: DocumentHeadContext, ctx: RequestContext) => void | Promise<void>
212
320
  /** Post-process rendered HTML before sending (applies to pages, `<Suspense>` shells, `_error.tsx`, and `_404.tsx`). */
@@ -217,8 +325,12 @@ export interface PrunellePlugin {
217
325
  clientEntry?: string | undefined
218
326
  /** Inline scripts the plugin writes into pages (from `head`, `transformHtml` or `addHead`), each as it stands between its tags: the CSP of every page allows them by hash. */
219
327
  inlineScripts?: readonly string[] | undefined
220
- /** Client module bundled on its own and loaded only on routes whose tree renders a `<Region>`; every other page stays free of it. */
221
- regionClientEntry?: string | undefined
328
+ /** The cookies the plugin sets, for `<CookieTable>`; a function gets the app's `site`, for a name that depends on https. */
329
+ cookies?: readonly CookieDeclaration[] | ((app: { site: string | undefined }) => readonly CookieDeclaration[]) | undefined
330
+ /** The personal data the plugin processes, for the privacy notice and the record of processing `prunelle rgpd --draft` writes. */
331
+ processing?: readonly ProcessingDeclaration[] | ((app: { site: string | undefined }) => readonly ProcessingDeclaration[]) | undefined
332
+ /** What goes wrong when several processes serve the app with no `store`, as a clause (`"publish() reaches the streams of its own process only"`): `prunelle start --workers` warns with it. */
333
+ perProcess?: string | undefined
222
334
  /**
223
335
  * What the plugin needs to run in production, read from its options, the app's config and the environment: one message per unmet setting, naming it and its fix.
224
336
  * A production start refuses while any is unmet, listing them all; `prunelle dev`, tests and `prunelle check` warn.
@@ -228,8 +340,8 @@ export interface PrunellePlugin {
228
340
  check?: (ctx: CheckPluginContext) => void | Promise<void>
229
341
  /** Extra directories or files (relative to app root or absolute) for `prunelle dev` to watch. */
230
342
  watchPaths?: string[] | ((root: string) => string[]) | undefined
231
- /** Register custom CLI subcommands (e.g. `prunelle i18n check`). */
232
- commands?: Record<string, (args: string[], root: string) => void | Promise<void>> | undefined
343
+ /** Register custom CLI subcommands (e.g. `prunelle i18n check`); `app.store` is `PrunelleConfig.store`, for a command that opens the app's database. */
344
+ commands?: Record<string, (args: string[], root: string, app: { store: string | undefined }) => void | Promise<void>> | undefined
233
345
  }
234
346
 
235
347
  /** Shared runtime server options inherited from `prunelle.config.ts` and overridable by `createServer`, `testApp`, `devServer`, and `--compile`. */
@@ -240,6 +352,8 @@ export interface ServerRuntimeConfig {
240
352
  assetPrefix?: string | undefined
241
353
  security?: SecurityHeadersOptions | false | undefined
242
354
  trustedOrigins?: string[] | undefined
355
+ /** The origins whose scripts may call this app, answered with CORS headers and their preflight; unset, no other origin may. */
356
+ cors?: CorsConfig | undefined
243
357
  trustProxy?: boolean | number | undefined
244
358
  maxRequestBodySize?: number | undefined
245
359
  /** How plain page changes feel without client JS: view transitions between pages, Speculation Rules prefetch on hover, opt-in prerender. */
@@ -251,9 +365,13 @@ export interface ServerRuntimeConfig {
251
365
  compress?: boolean | undefined
252
366
  /** Bounded in-memory cache for routes exporting `export const cache = ...` (default: 500 entries / 32 MiB; set `false` to disable). */
253
367
  routeCache?: RouteCacheOptions | false | undefined
368
+ /** The store every process of the app shares, for rate limits, live messages and cache invalidation: a SQLite file (`'data/app.db'`, resolved against the app root) or a `postgres://` URL. Unset, each process keeps them in its own memory. */
369
+ store?: string | undefined
254
370
  /** Health check function or named check map evaluated on `GET ${assetPrefix}/health`. */
255
371
  healthCheck?: HealthCheckConfig | undefined
256
372
  onError?: ((info: ServerErrorInfo) => void) | undefined
373
+ /** How the server logs: unhandled errors as JSON lines, and an access log. */
374
+ log?: LogConfig | undefined
257
375
  plugins?: PrunellePlugin[] | undefined
258
376
  }
259
377