@sleepy-hollow/framework 0.3.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 (52) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +373 -0
  3. package/README.md +95 -0
  4. package/dist/chunk-53TZY5YP.js +470 -0
  5. package/dist/chunk-53TZY5YP.js.map +1 -0
  6. package/dist/chunk-5WRI5ZAA.js +31 -0
  7. package/dist/chunk-5WRI5ZAA.js.map +1 -0
  8. package/dist/chunk-BAKXP7IR.js +85 -0
  9. package/dist/chunk-BAKXP7IR.js.map +1 -0
  10. package/dist/chunk-BJONRVDG.js +429 -0
  11. package/dist/chunk-BJONRVDG.js.map +1 -0
  12. package/dist/chunk-CAPFDC25.js +598 -0
  13. package/dist/chunk-CAPFDC25.js.map +1 -0
  14. package/dist/chunk-D4U3ZY4O.js +4585 -0
  15. package/dist/chunk-D4U3ZY4O.js.map +1 -0
  16. package/dist/chunk-DGTHFZPZ.js +830 -0
  17. package/dist/chunk-DGTHFZPZ.js.map +1 -0
  18. package/dist/chunk-LNJDFJGT.js +47 -0
  19. package/dist/chunk-LNJDFJGT.js.map +1 -0
  20. package/dist/cli.d.ts +427 -0
  21. package/dist/cli.js +5910 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/database.d.ts +25 -0
  24. package/dist/database.js +16 -0
  25. package/dist/database.js.map +1 -0
  26. package/dist/dist-DUSC2237.js +546 -0
  27. package/dist/dist-DUSC2237.js.map +1 -0
  28. package/dist/index.d.ts +241 -0
  29. package/dist/index.js +71 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/magic-string.es-GTFBNHZR.js +1309 -0
  32. package/dist/magic-string.es-GTFBNHZR.js.map +1 -0
  33. package/dist/routing.d.ts +89 -0
  34. package/dist/routing.js +17 -0
  35. package/dist/routing.js.map +1 -0
  36. package/dist/security.d.ts +319 -0
  37. package/dist/security.js +21 -0
  38. package/dist/security.js.map +1 -0
  39. package/dist/server.d.ts +10 -0
  40. package/dist/server.js +8 -0
  41. package/dist/server.js.map +1 -0
  42. package/dist/testing.d.ts +157 -0
  43. package/dist/testing.js +29 -0
  44. package/dist/testing.js.map +1 -0
  45. package/dist/types-BC7LJJ6G.d.ts +131 -0
  46. package/dist/types-BUXw3UwN.d.ts +54 -0
  47. package/dist/types-Bet36nZS.d.ts +390 -0
  48. package/dist/types-DmzdxsaA.d.ts +113 -0
  49. package/dist/validation.d.ts +57 -0
  50. package/dist/validation.js +20 -0
  51. package/dist/validation.js.map +1 -0
  52. package/package.json +84 -0
@@ -0,0 +1,241 @@
1
+ export { createRouter, defineRoute, discoverRoutes } from './routing.js';
2
+ import { N as NormalizedRoute } from './types-BC7LJJ6G.js';
3
+ export { H as HTTP_METHODS, a as HttpMethod, R as RouteDiscoveryError, b as RouteHandlerContext, c as RouteModule, d as RouteOperation, e as RoutePrincipal, f as RoutingDiagnostic } from './types-BC7LJJ6G.js';
4
+ import { z } from 'zod';
5
+ export { z } from 'zod';
6
+ export { PreparedRoute, createValidatedRouter, formatValidationDiagnostic, normalizeRoutes, validationDiagnosticResult } from './validation.js';
7
+ export { N as NormalizedBodySchema, a as NormalizedOperationSchemas, b as NormalizedSchema, c as NormalizedValidationRoute, S as SchemaNormalizationError, V as ValidatedRouter, d as ValidationDiagnostic, e as ValidationIssue, f as ValidationLocation, g as ValidationOptions } from './types-DmzdxsaA.js';
8
+ export { AuthProvider, AuthorizationContext, CorsConfiguration, MemoryRateLimiterOptions, NormalizedSecurityRoute, Principal, ProjectSecurityOptions, RateLimitDecision, RateLimitInput, RateLimitPolicy, RateLimiter, RouteSecurity, SecuredHandlerContext, SecurityConfigurationError, SecurityDeclaration, SecurityDiagnostic, SecurityMode, SecurityOptions, SecurityRouter, composeProjectSecurity, createMemoryRateLimiter, createSecurityRouter, defineSecurity, redactSecurityData } from './security.js';
9
+ export { DatabaseConfigurationError, defineResource, openEmbeddedSqlite, openPostgres } from './database.js';
10
+ export { sql } from 'drizzle-orm';
11
+ export { D as DatabaseProfile, E as EmbeddedSqliteDatabase, a as EmbeddedSqliteOptions, P as PostgresDatabase, b as PostgresOptions, R as ResourceDefinition, c as ResourceField, d as ResourceRepository } from './types-BUXw3UwN.js';
12
+ import 'drizzle-orm/better-sqlite3';
13
+ import 'better-sqlite3';
14
+ import 'drizzle-orm/node-postgres';
15
+ import 'pg';
16
+
17
+ /** The runtime modes a project may be configured for. */
18
+ declare const RUNTIME_MODES: readonly ["development", "test", "preview", "production"];
19
+ /** One of the {@linkcode RUNTIME_MODES} a process may run in. */
20
+ type RuntimeMode = (typeof RUNTIME_MODES)[number];
21
+ /** One schema per runtime mode: what configuration that mode requires. */
22
+ type ModeSchemas = Readonly<Record<RuntimeMode, z.ZodObject>>;
23
+ /**
24
+ * A project's configuration contract.
25
+ *
26
+ * Each mode carries its own schema, so production can demand values that
27
+ * development supplies a default for, and the difference is stated rather than
28
+ * discovered on deployment.
29
+ */
30
+ interface ConfigurationDefinition<Schemas extends ModeSchemas> {
31
+ /** The schema each runtime mode must satisfy. */
32
+ readonly modes: Schemas;
33
+ /** Keys whose values are redacted from metadata and logs. */
34
+ readonly sensitiveKeys?: readonly string[];
35
+ /** Env files read in the named modes; never consulted in production. */
36
+ readonly localEnvFiles?: Readonly<Partial<Record<"development" | "test", string>>>;
37
+ }
38
+ /** One reason configuration could not be resolved. */
39
+ interface ConfigurationDiagnostic {
40
+ /** Stable machine-readable identifier for this kind of fault. */
41
+ readonly code: string;
42
+ /** Configuration faults are always fatal; there are no warnings. */
43
+ readonly severity: "error";
44
+ /** The mode being resolved, when the fault is specific to one. */
45
+ readonly mode?: RuntimeMode;
46
+ /** The configuration key concerned; omitted for whole-shape faults. */
47
+ readonly key?: string;
48
+ /** What was required of the value. */
49
+ readonly expected: string;
50
+ /** What to change to resolve it. */
51
+ readonly correction: string;
52
+ }
53
+ /**
54
+ * Thrown when configuration cannot be resolved.
55
+ *
56
+ * Raised at startup rather than at first use, so a missing value stops the
57
+ * process instead of failing the first request that happens to need it. The
58
+ * message names keys but never their values, which may be secrets.
59
+ */
60
+ declare class ConfigurationError extends Error {
61
+ readonly diagnostics: readonly ConfigurationDiagnostic[];
62
+ /**
63
+ * Builds an error whose message lists every diagnostic, one per line.
64
+ *
65
+ * @param diagnostics Every fault found, in the order detected.
66
+ */
67
+ constructor(diagnostics: readonly ConfigurationDiagnostic[]);
68
+ }
69
+ /** Where one configuration key's value came from, without the value. */
70
+ interface ConfigurationKeyMetadata {
71
+ /** The key's name. */
72
+ readonly name: string;
73
+ /** Which source supplied it, or `absent` when nothing did. */
74
+ readonly source: "absent" | "default" | "env-file" | "environment";
75
+ /** Whether a value was supplied at all. */
76
+ readonly present: boolean;
77
+ /** Whether the key was declared sensitive, and so never reported. */
78
+ readonly sensitive: boolean;
79
+ }
80
+ /**
81
+ * Provenance for a resolved configuration: which keys were set and from where,
82
+ * safe to log because it carries no values.
83
+ */
84
+ interface ConfigurationMetadata<M extends RuntimeMode = RuntimeMode> {
85
+ /** The mode this configuration was resolved for. */
86
+ readonly mode: M;
87
+ /** One entry per declared key. */
88
+ readonly keys: readonly ConfigurationKeyMetadata[];
89
+ }
90
+ /** How to resolve configuration, and where to read it from. */
91
+ interface ResolveConfigurationOptions<M extends RuntimeMode> {
92
+ /** The mode to resolve for. */
93
+ readonly mode: M;
94
+ /** Environment to read; defaults to the process environment. */
95
+ readonly environment?: Readonly<Record<string, string | undefined>>;
96
+ /** Reads env files; supply your own to resolve without disk access. */
97
+ readonly readTextFile?: (path: string) => Promise<string>;
98
+ }
99
+ /** Configuration after resolution: the values, and where they came from. */
100
+ interface ResolvedConfiguration<M extends RuntimeMode, Values> {
101
+ /** The mode these values were resolved for. */
102
+ readonly mode: M;
103
+ /** The parsed values, typed by that mode's schema. */
104
+ readonly values: Readonly<Values>;
105
+ /** Provenance for each key, without values. */
106
+ readonly metadata: ConfigurationMetadata<M>;
107
+ }
108
+ /** The value type a definition yields in a given mode. */
109
+ type ConfigurationValues<Definition extends ConfigurationDefinition<ModeSchemas>, M extends RuntimeMode> = z.output<Definition["modes"][M]>;
110
+ /** Severity of a log line. */
111
+ type LogLevel = "debug" | "error" | "info" | "warn";
112
+ /** How to build a JSON logger. */
113
+ interface JsonLoggerOptions {
114
+ /** The mode being run in; recorded on every line. */
115
+ readonly mode: RuntimeMode;
116
+ /** Receives each serialized line. */
117
+ readonly sink: (line: string) => void;
118
+ /** Supplies timestamps; override to make log output deterministic. */
119
+ readonly clock?: () => Date;
120
+ /** Field names redacted from every line's context. */
121
+ readonly sensitiveFields?: readonly string[];
122
+ }
123
+ /**
124
+ * A logger that emits one JSON object per line.
125
+ *
126
+ * Declared sensitive fields are redacted from context before serialization, so
127
+ * a secret passed to a log call does not reach the sink.
128
+ */
129
+ interface JsonLogger {
130
+ /**
131
+ * Logs at debug severity.
132
+ *
133
+ * @param event Stable event name, not a sentence.
134
+ * @param context Structured detail; sensitive fields are redacted.
135
+ */
136
+ debug(event: string, context?: unknown): void;
137
+ /**
138
+ * Logs at info severity.
139
+ *
140
+ * @param event Stable event name, not a sentence.
141
+ * @param context Structured detail; sensitive fields are redacted.
142
+ */
143
+ info(event: string, context?: unknown): void;
144
+ /**
145
+ * Logs at warning severity.
146
+ *
147
+ * @param event Stable event name, not a sentence.
148
+ * @param context Structured detail; sensitive fields are redacted.
149
+ */
150
+ warn(event: string, context?: unknown): void;
151
+ /**
152
+ * Logs at error severity.
153
+ *
154
+ * @param event Stable event name, not a sentence.
155
+ * @param context Structured detail; sensitive fields are redacted.
156
+ */
157
+ error(event: string, context?: unknown): void;
158
+ /**
159
+ * Derives a logger that stamps every line with a request identifier.
160
+ *
161
+ * @param requestId Correlates lines belonging to one request.
162
+ * @returns A logger writing to the same sink.
163
+ */
164
+ withRequest(requestId: string): JsonLogger;
165
+ }
166
+ /** One dependency readiness probes before reporting the process ready. */
167
+ interface ReadinessCheck {
168
+ /** Names the dependency in the readiness response. */
169
+ readonly name: string;
170
+ /** How long this check may take before it counts as failed. */
171
+ readonly timeoutMs: number;
172
+ /**
173
+ * Probes the dependency.
174
+ *
175
+ * @param signal Aborts when the check exceeds its timeout.
176
+ * @returns Whether the dependency is usable.
177
+ */
178
+ check(signal: AbortSignal): Promise<boolean>;
179
+ }
180
+ /** Which operational endpoints to expose, and what they report. */
181
+ interface OperationalRouteOptions {
182
+ /** Path of the liveness endpoint. */
183
+ readonly healthPath: string;
184
+ /** Reports whether the process itself is healthy; defaults to always. */
185
+ readonly isHealthy?: () => boolean;
186
+ /** Path of the readiness endpoint; omit to expose liveness only. */
187
+ readonly readinessPath?: string;
188
+ /** Dependencies probed before reporting ready. */
189
+ readonly readiness?: readonly ReadinessCheck[];
190
+ }
191
+
192
+ /**
193
+ * Declares what configuration each runtime mode requires.
194
+ *
195
+ * The definition itself is validated here, so a mode missing a schema or a
196
+ * sensitive key naming nothing is caught before any value is read.
197
+ *
198
+ * @param definition The per-mode schemas, sensitive keys, and env files.
199
+ * @returns The validated definition, for {@linkcode resolveConfiguration}.
200
+ * @throws {ConfigurationError} When the definition is malformed.
201
+ */
202
+ declare function defineConfiguration<const Schemas extends ModeSchemas>(definition: ConfigurationDefinition<Schemas>): ConfigurationDefinition<Schemas>;
203
+ /**
204
+ * Resolves configuration for one mode, from env files and the environment.
205
+ *
206
+ * Every fault is collected and thrown together, so one startup reports the
207
+ * whole set of missing or malformed values rather than the first. Env files
208
+ * are consulted only in the modes the definition names, never in production.
209
+ *
210
+ * @param definition The contract, from {@linkcode defineConfiguration}.
211
+ * @param options The mode to resolve, and where to read values from.
212
+ * @returns The parsed values, and provenance for each key.
213
+ * @throws {ConfigurationError} When any required value is missing or invalid.
214
+ */
215
+ declare function resolveConfiguration<const Schemas extends ModeSchemas, const M extends RuntimeMode>(definition: ConfigurationDefinition<Schemas>, options: ResolveConfigurationOptions<M>): Promise<ResolvedConfiguration<M, ConfigurationValues<ConfigurationDefinition<Schemas>, M>>>;
216
+
217
+ /**
218
+ * Builds a logger that writes one JSON object per line.
219
+ *
220
+ * Fields named as sensitive are redacted before serialization, so a secret
221
+ * passed in context never reaches the sink.
222
+ *
223
+ * @param options The mode, the sink, and which fields to redact.
224
+ * @returns A logger, derivable per request with `withRequest`.
225
+ */
226
+ declare function createJsonLogger(options: JsonLoggerOptions): JsonLogger;
227
+
228
+ /**
229
+ * Builds liveness and readiness routes, ready to add to the route table.
230
+ *
231
+ * Liveness answers whether the process is up; readiness probes the declared
232
+ * dependencies, each under its own timeout, and reports which one failed. A
233
+ * probe that exceeds its timeout counts as failed rather than hanging.
234
+ *
235
+ * @param options The paths to expose, and the dependencies to probe.
236
+ * @returns Routes to include alongside the discovered ones.
237
+ * @throws {ConfigurationError} When a path or readiness check is malformed.
238
+ */
239
+ declare function createOperationalRoutes(options: OperationalRouteOptions): readonly NormalizedRoute[];
240
+
241
+ export { type ConfigurationDefinition, type ConfigurationDiagnostic, ConfigurationError, type ConfigurationKeyMetadata, type ConfigurationMetadata, type ConfigurationValues, type JsonLogger, type JsonLoggerOptions, type LogLevel, type ModeSchemas, NormalizedRoute, type OperationalRouteOptions, RUNTIME_MODES, type ReadinessCheck, type ResolveConfigurationOptions, type ResolvedConfiguration, type RuntimeMode, createJsonLogger, createOperationalRoutes, defineConfiguration, resolveConfiguration };
package/dist/index.js ADDED
@@ -0,0 +1,71 @@
1
+ import {
2
+ ConfigurationError,
3
+ RUNTIME_MODES,
4
+ createJsonLogger,
5
+ createOperationalRoutes,
6
+ defineConfiguration,
7
+ resolveConfiguration
8
+ } from "./chunk-BJONRVDG.js";
9
+ import {
10
+ DatabaseConfigurationError,
11
+ defineResource,
12
+ openEmbeddedSqlite,
13
+ openPostgres,
14
+ sql
15
+ } from "./chunk-BAKXP7IR.js";
16
+ import {
17
+ SecurityConfigurationError,
18
+ composeProjectSecurity,
19
+ createMemoryRateLimiter,
20
+ createSecurityRouter,
21
+ defineSecurity,
22
+ redactSecurityData
23
+ } from "./chunk-DGTHFZPZ.js";
24
+ import {
25
+ SchemaNormalizationError,
26
+ createValidatedRouter,
27
+ formatValidationDiagnostic,
28
+ normalizeRoutes,
29
+ validationDiagnosticResult,
30
+ z
31
+ } from "./chunk-CAPFDC25.js";
32
+ import {
33
+ HTTP_METHODS,
34
+ RouteDiscoveryError,
35
+ createRouter,
36
+ defineRoute,
37
+ discoverRoutes
38
+ } from "./chunk-53TZY5YP.js";
39
+ import "./chunk-LNJDFJGT.js";
40
+ import "./chunk-5WRI5ZAA.js";
41
+ export {
42
+ ConfigurationError,
43
+ DatabaseConfigurationError,
44
+ HTTP_METHODS,
45
+ RUNTIME_MODES,
46
+ RouteDiscoveryError,
47
+ SchemaNormalizationError,
48
+ SecurityConfigurationError,
49
+ composeProjectSecurity,
50
+ createJsonLogger,
51
+ createMemoryRateLimiter,
52
+ createOperationalRoutes,
53
+ createRouter,
54
+ createSecurityRouter,
55
+ createValidatedRouter,
56
+ defineConfiguration,
57
+ defineResource,
58
+ defineRoute,
59
+ defineSecurity,
60
+ discoverRoutes,
61
+ formatValidationDiagnostic,
62
+ normalizeRoutes,
63
+ openEmbeddedSqlite,
64
+ openPostgres,
65
+ redactSecurityData,
66
+ resolveConfiguration,
67
+ sql,
68
+ validationDiagnosticResult,
69
+ z
70
+ };
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}