theokit 0.12.0 → 0.12.1
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/adapters/web-shim.d.ts +67 -0
- package/dist/adapters/ws-shim.d.ts +55 -0
- package/dist/agent-events-DosDXkSV.d.ts +94 -0
- package/dist/audit-log-BQWM5YLG.d.ts +60 -0
- package/dist/boot/index.d.ts +39 -0
- package/dist/client/index.d.ts +362 -0
- package/dist/csrf-BBrEZSBW.d.ts +107 -0
- package/dist/csrf-readiness-store-CjIoub3U.d.ts +43 -0
- package/dist/define-websocket-CdK94O-D.d.ts +64 -0
- package/dist/devtools/entry.d.ts +5 -0
- package/dist/error-envelope-BsNzzAV5.d.ts +62 -0
- package/dist/health-route-C0hk64_U.d.ts +57 -0
- package/dist/index-B40qUSrQ.d.ts +575 -0
- package/dist/index.d.ts +361 -0
- package/dist/job-backend-CgC8Xf33.d.ts +68 -0
- package/dist/match-CfbEFRG4.d.ts +26 -0
- package/dist/plugin-runner-BGBkzgi0.d.ts +95 -0
- package/dist/plugin-types-DNJGxr4Z.d.ts +79 -0
- package/dist/rate-limit-BdNDZ3vt.d.ts +58 -0
- package/dist/rate-limit-store-BEJnhWdw.d.ts +72 -0
- package/dist/react-query/index.d.ts +33 -0
- package/dist/schema-BpH6ivDY.d.ts +74 -0
- package/dist/server/agent/index.d.ts +229 -0
- package/dist/server/auth/index.d.ts +419 -0
- package/dist/server/cost/index.d.ts +177 -0
- package/dist/server/cron/index.d.ts +208 -0
- package/dist/server/define/index.d.ts +313 -0
- package/dist/server/http/index.d.ts +11 -0
- package/dist/server/index.d.ts +848 -0
- package/dist/server/jobs/index.d.ts +348 -0
- package/dist/server/observability/index.d.ts +324 -0
- package/dist/server/plugins/index.d.ts +17 -0
- package/dist/server/rate-limit/index.d.ts +105 -0
- package/dist/server/realtime/index.d.ts +15 -0
- package/dist/server/scan/index.d.ts +106 -0
- package/dist/server/security/index.d.ts +193 -0
- package/dist/server/storage/index.d.ts +22 -0
- package/dist/server/webhook/index.d.ts +148 -0
- package/dist/storage-manager-C4jsO0Tp.d.ts +89 -0
- package/dist/storage-types-DsDTCPbp.d.ts +96 -0
- package/dist/vite-plugin/index.d.ts +115 -0
- package/package.json +4 -4
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { S as ServerConfig, P as PostgresDatabaseConfig, a as PoolLike, b as StorageConfig, R as RedisServerConfig, c as RedisLike, d as StorageAdapter } from './storage-types-DsDTCPbp.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* StorageManager — per-process singleton coordinating pluggable storage
|
|
5
|
+
* adapters (Postgres pools, Redis clients, in-memory adapters).
|
|
6
|
+
*
|
|
7
|
+
* Architectural decisions: see ADR-0007 (docs/adr/0007-storage-manager-singleton.md).
|
|
8
|
+
*
|
|
9
|
+
* Lifecycle:
|
|
10
|
+
* 1. `getStorageManager()` returns the singleton (D1).
|
|
11
|
+
* 2. `configure(storageConfig)` honored once per process (D3). Second call
|
|
12
|
+
* warns and is ignored.
|
|
13
|
+
* 3. `usePostgres(dbName, factory)` / `useRedis(serverName, factory)`
|
|
14
|
+
* lazily create + cache (D2). Factory invoked exactly once per name.
|
|
15
|
+
* 4. `register(adapter)` opts the adapter into the SIGTERM drain (D6).
|
|
16
|
+
* 5. `dispose()` drains in parallel — adapters + pools + Redis (D5).
|
|
17
|
+
* Idempotent. Adapter errors logged + swallowed (do not block shutdown).
|
|
18
|
+
*
|
|
19
|
+
* Test seam: `__resetForTests()` resets state. Test files MUST call it from
|
|
20
|
+
* `beforeEach` to avoid pollution across `it` blocks (EC-3).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
type PostgresFactory = (server: ServerConfig, db: PostgresDatabaseConfig) => PoolLike;
|
|
24
|
+
type RedisFactory = (config: RedisServerConfig) => RedisLike;
|
|
25
|
+
declare class StorageManager {
|
|
26
|
+
#private;
|
|
27
|
+
/**
|
|
28
|
+
* Apply the storage config block from `theo.config.ts`. Second call warns
|
|
29
|
+
* and is ignored (D3). Reset only via `__resetForTests()`.
|
|
30
|
+
*/
|
|
31
|
+
configure(config: StorageConfig): void;
|
|
32
|
+
/**
|
|
33
|
+
* Generic cache + factory for ANY client (MySQL, Mongo, Turso, DynamoDB, …).
|
|
34
|
+
* Returns the cached client OR invokes the factory and caches its return.
|
|
35
|
+
*
|
|
36
|
+
* EC-1 FIX: cache-hit check uses `Map.has(name)`, NOT `cached !== undefined`.
|
|
37
|
+
* Factories returning `null` or `undefined` are valid (lazy connect, stubs);
|
|
38
|
+
* the `!== undefined` check would re-invoke the factory infinitely for
|
|
39
|
+
* undefined returns AND silently cache `null` cast as `T`.
|
|
40
|
+
*
|
|
41
|
+
* EC-2 (documented type hole): `useStorage<A>('x', fA)` followed by
|
|
42
|
+
* `useStorage<B>('x', fB)` returns the cached A cast as B. Same trade-off
|
|
43
|
+
* as `Map<string, unknown>` — caller is responsible for using unique names
|
|
44
|
+
* per type.
|
|
45
|
+
*
|
|
46
|
+
* Lifecycle: generic clients are NOT auto-drained by `dispose()`. Call
|
|
47
|
+
* `manager.register({ name, dispose })` separately to participate.
|
|
48
|
+
*
|
|
49
|
+
* Reserved name prefixes (do NOT use): `__pg:`, `__redis:`, `__unstorage:`,
|
|
50
|
+
* `__db0:` — these are used internally by the typed helpers.
|
|
51
|
+
*/
|
|
52
|
+
useStorage<T>(name: string, factory: () => T): T;
|
|
53
|
+
/**
|
|
54
|
+
* Return a Postgres pool for the named database. Lazy + cached. Factory
|
|
55
|
+
* invoked exactly once per `dbName` (D2).
|
|
56
|
+
*
|
|
57
|
+
* Throws if:
|
|
58
|
+
* - manager is disposed
|
|
59
|
+
* - `dbName` is not in `config.databases`
|
|
60
|
+
* - the referenced server is not in `config.servers` (EC-2: deferred
|
|
61
|
+
* cross-field validation surfaces here, not at configure time)
|
|
62
|
+
*/
|
|
63
|
+
usePostgres(dbName: string, factory: PostgresFactory): PoolLike;
|
|
64
|
+
/**
|
|
65
|
+
* Return a Redis client for the named server. Lazy + cached. Factory
|
|
66
|
+
* invoked exactly once per `serverName`.
|
|
67
|
+
*/
|
|
68
|
+
useRedis(serverName: string, factory: RedisFactory): RedisLike;
|
|
69
|
+
/**
|
|
70
|
+
* Register an adapter for graceful shutdown coordination (D6).
|
|
71
|
+
*
|
|
72
|
+
* EC-4: throws if the manager is already disposed — prevents silent
|
|
73
|
+
* leaks in test seams that reset+reuse the manager.
|
|
74
|
+
*/
|
|
75
|
+
register(adapter: StorageAdapter): void;
|
|
76
|
+
/**
|
|
77
|
+
* Drain in parallel — registered adapters, then PG pools, then Redis
|
|
78
|
+
* clients. Idempotent (D5). Errors per resource are logged and swallowed
|
|
79
|
+
* — they do NOT prevent shutdown of the remaining resources.
|
|
80
|
+
*
|
|
81
|
+
* Caller must wrap in a timeout if a bound is needed (EC-7: documented).
|
|
82
|
+
* In production, `start.ts` wraps the whole shutdown sequence in a 25 s
|
|
83
|
+
* force-exit timer.
|
|
84
|
+
*/
|
|
85
|
+
dispose(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
declare function getStorageManager(): StorageManager;
|
|
88
|
+
|
|
89
|
+
export { type PostgresFactory as P, type RedisFactory as R, StorageManager as S, getStorageManager as g };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical structural types for the StorageManager (ADR-0007).
|
|
3
|
+
*
|
|
4
|
+
* `PoolLike` is the minimal pg.Pool subset TheoKit consumes — defined here as
|
|
5
|
+
* single source of truth (D7). Adapters that need a Postgres pool import this
|
|
6
|
+
* type instead of duplicating the shape.
|
|
7
|
+
*
|
|
8
|
+
* `RedisLike` is the minimal ioredis subset the manager calls during dispose.
|
|
9
|
+
*
|
|
10
|
+
* `StorageAdapter` is the lifecycle contract — anything that wants to
|
|
11
|
+
* participate in the StorageManager drain on SIGTERM implements this.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Minimal subset of `pg.Pool` we depend on. Accepting this narrower interface
|
|
15
|
+
* lets us:
|
|
16
|
+
* - test with `pg-mem` (in-memory) without dragging real Postgres into CI
|
|
17
|
+
* - swap to any wire-compatible client (postgres.js, slonik, etc.)
|
|
18
|
+
*
|
|
19
|
+
* Optional `end()` lets the manager call it during dispose; not required for
|
|
20
|
+
* pools that handle their own lifecycle (e.g., serverless drivers).
|
|
21
|
+
*/
|
|
22
|
+
interface PoolLike {
|
|
23
|
+
query<R = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<{
|
|
24
|
+
rows: R[];
|
|
25
|
+
rowCount?: number | null;
|
|
26
|
+
}>;
|
|
27
|
+
/** Optional — manager calls this during dispose(). Pools without end() are silently skipped (EC-5). */
|
|
28
|
+
end?: () => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Minimal subset of ioredis we depend on during graceful shutdown. The full
|
|
32
|
+
* Redis API is the user's responsibility — manager only needs lifecycle.
|
|
33
|
+
*/
|
|
34
|
+
interface RedisLike {
|
|
35
|
+
/** Graceful close — drains pending commands. */
|
|
36
|
+
quit(): Promise<unknown>;
|
|
37
|
+
/** Hard close — used as fallback if `quit()` rejects. */
|
|
38
|
+
disconnect(): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Lifecycle contract for any adapter that participates in StorageManager
|
|
42
|
+
* graceful shutdown. Call `manager.register(this)` from your adapter's
|
|
43
|
+
* constructor to opt in.
|
|
44
|
+
*
|
|
45
|
+
* Errors thrown from `dispose()` are swallowed by the manager (D5/D6 — log +
|
|
46
|
+
* continue). Do not rely on `dispose()` rejection propagating.
|
|
47
|
+
*/
|
|
48
|
+
interface StorageAdapter {
|
|
49
|
+
readonly name: string;
|
|
50
|
+
dispose(): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generic factory signature for `StorageManager.useStorage<T>(name, factory)`.
|
|
54
|
+
* Useful for typing externally-defined factory functions:
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* const mongoFactory: GenericFactory<MongoClient> = () => new MongoClient({...})
|
|
58
|
+
* manager.useStorage('mongo', mongoFactory)
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
type GenericFactory<T> = () => T;
|
|
62
|
+
interface TlsConfig {
|
|
63
|
+
rejectUnauthorized?: boolean;
|
|
64
|
+
caCert?: string;
|
|
65
|
+
clientCert?: string;
|
|
66
|
+
clientKey?: string;
|
|
67
|
+
}
|
|
68
|
+
interface ServerConfig {
|
|
69
|
+
host: string;
|
|
70
|
+
port?: number;
|
|
71
|
+
user: string;
|
|
72
|
+
password: string;
|
|
73
|
+
tls?: TlsConfig;
|
|
74
|
+
}
|
|
75
|
+
interface PostgresDatabaseConfig {
|
|
76
|
+
/** References a key in `StorageConfig.servers`. */
|
|
77
|
+
server: string;
|
|
78
|
+
database: string;
|
|
79
|
+
pool?: {
|
|
80
|
+
min?: number;
|
|
81
|
+
max?: number;
|
|
82
|
+
connectionTimeoutMillis?: number;
|
|
83
|
+
idleTimeoutMillis?: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
interface RedisServerConfig extends ServerConfig {
|
|
87
|
+
db?: number;
|
|
88
|
+
maxRetriesPerRequest?: number;
|
|
89
|
+
}
|
|
90
|
+
interface StorageConfig {
|
|
91
|
+
servers?: Record<string, ServerConfig>;
|
|
92
|
+
databases?: Record<string, PostgresDatabaseConfig>;
|
|
93
|
+
redis?: Record<string, RedisServerConfig>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type { GenericFactory as G, PostgresDatabaseConfig as P, RedisServerConfig as R, ServerConfig as S, TlsConfig as T, PoolLike as a, StorageConfig as b, RedisLike as c, StorageAdapter as d };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { R as RateLimitConfig } from '../rate-limit-BdNDZ3vt.js';
|
|
3
|
+
import { C as CsrfReadinessStore } from '../csrf-readiness-store-CjIoub3U.js';
|
|
4
|
+
import { S as ServicesConfig } from '../schema-BpH6ivDY.js';
|
|
5
|
+
import 'node:http';
|
|
6
|
+
import '../rate-limit-store-BEJnhWdw.js';
|
|
7
|
+
import 'zod';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* T3.1 — Vite integration extension API (`defineTheoIntegration`).
|
|
11
|
+
*
|
|
12
|
+
* Build-time extension system (mirrors Astro Integrations). Lets third
|
|
13
|
+
* parties hook into Theo's Vite lifecycle without forking the plugin.
|
|
14
|
+
*
|
|
15
|
+
* Strictly separated from runtime `defineTheoPlugin` (Phase 4) — different
|
|
16
|
+
* concerns, different surfaces. See ADR D7 in the plan.
|
|
17
|
+
*/
|
|
18
|
+
type HookName = 'theo:config:setup' | 'theo:build:start' | 'theo:build:done' | 'theo:dev:start';
|
|
19
|
+
interface HookContext {
|
|
20
|
+
addVirtualModule?: (id: string, code: string) => void;
|
|
21
|
+
addRoute?: (path: string, handler: RouteHandler) => void;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
type Hook = (ctx: HookContext) => void | Promise<void>;
|
|
25
|
+
type RouteHandler = (request: Request) => Response | Promise<Response>;
|
|
26
|
+
interface TheoIntegration {
|
|
27
|
+
name: string;
|
|
28
|
+
hooks: Partial<Record<HookName, Hook>>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Identity factory for type-checking against TheoIntegration shape.
|
|
32
|
+
*/
|
|
33
|
+
declare function defineTheoIntegration(integration: TheoIntegration): TheoIntegration;
|
|
34
|
+
declare class IntegrationVirtualModulePrefixError extends Error {
|
|
35
|
+
constructor(integrationName: string, id: string);
|
|
36
|
+
}
|
|
37
|
+
declare class IntegrationRouteCollisionError extends Error {
|
|
38
|
+
constructor(integrationName: string, path: string);
|
|
39
|
+
}
|
|
40
|
+
interface IntegrationRegistryOptions {
|
|
41
|
+
/** Routes already scanned from `server/routes/`. Used to detect collisions. */
|
|
42
|
+
existingRoutes: string[];
|
|
43
|
+
}
|
|
44
|
+
interface IntegrationRoute {
|
|
45
|
+
path: string;
|
|
46
|
+
owner: string;
|
|
47
|
+
}
|
|
48
|
+
interface IntegrationRegistry {
|
|
49
|
+
registerIntegration(integration: TheoIntegration): void;
|
|
50
|
+
fire(hookName: HookName, baseCtx: Record<string, unknown>): Promise<void>;
|
|
51
|
+
addVirtualModule(integrationName: string, id: string, code: string): void;
|
|
52
|
+
addRoute(integrationName: string, path: string, handler: RouteHandler): void;
|
|
53
|
+
getVirtualModule(id: string): string | undefined;
|
|
54
|
+
listVirtualModules(): string[];
|
|
55
|
+
listRoutes(): IntegrationRoute[];
|
|
56
|
+
/** Test helper: invoke hook surface directly without firing the lifecycle. */
|
|
57
|
+
callHook(integrationName: string, hookName: HookName, extraCtx: Partial<HookContext>): Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
declare function createIntegrationRegistry(options: IntegrationRegistryOptions): IntegrationRegistry;
|
|
60
|
+
|
|
61
|
+
interface TheoPluginOptions {
|
|
62
|
+
root?: string;
|
|
63
|
+
rateLimit?: RateLimitConfig;
|
|
64
|
+
ssr?: boolean;
|
|
65
|
+
ssrStreaming?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Wave 2 (T3.1) — polyglot services config. When passed, the
|
|
68
|
+
* services-typed-client plugin is wired and generates `clients/<name>.ts`
|
|
69
|
+
* per service with an OpenAPI URL. Empty `{}` → no-op.
|
|
70
|
+
*/
|
|
71
|
+
services?: ServicesConfig;
|
|
72
|
+
/**
|
|
73
|
+
* T4.1 (canvas-ecosystem-refactor / ADR D6) — extra package names appended
|
|
74
|
+
* to Vite `optimizeDeps.include`. Required when an installed plugin
|
|
75
|
+
* peer-dep is consumed via a literal `import('<pkg>')` (dynamic specifier)
|
|
76
|
+
* — Vite cannot trace those without a hint, and the browser receives a
|
|
77
|
+
* `Failed to resolve module specifier '<pkg>'` error.
|
|
78
|
+
*
|
|
79
|
+
* Default targets pre-bundled regardless: `@theokit/ui`, `lucide-react`.
|
|
80
|
+
*
|
|
81
|
+
* Example:
|
|
82
|
+
* viteOptimizeDeps: ['mermaid']
|
|
83
|
+
*/
|
|
84
|
+
viteOptimizeDeps?: string[];
|
|
85
|
+
/**
|
|
86
|
+
* Optional override for the in-memory CSRF readiness store consumed by
|
|
87
|
+
* the `/__theo/csrf-readiness` endpoint and the devtools CSRF Readiness
|
|
88
|
+
* tab. When omitted, the plugin auto-instantiates a default in-process
|
|
89
|
+
* `CsrfReadinessStore` so the tab works out-of-the-box in dev.
|
|
90
|
+
*
|
|
91
|
+
* Override with a custom impl when you need cross-worker telemetry
|
|
92
|
+
* (e.g., Redis-backed store) or want to silence the tab entirely
|
|
93
|
+
* (pass an inert store that discards writes).
|
|
94
|
+
*/
|
|
95
|
+
csrfReadinessStore?: CsrfReadinessStore;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Async factory companion. Returns `[theoPlugin, ...autoChainedPlugins]`.
|
|
99
|
+
*
|
|
100
|
+
* Why this exists alongside the sync `theoPlugin()` factory: Vite does NOT
|
|
101
|
+
* reliably merge plugins returned from a child plugin's `config()` hook
|
|
102
|
+
* (verified empirically 2026-05-23 — plugins were silently dropped from
|
|
103
|
+
* the resolved chain despite being returned correctly). The canonical
|
|
104
|
+
* Vite pattern for plugin-from-plugin is to return `Plugin[]` from the
|
|
105
|
+
* plugin factory itself, which Vite flattens into the consumer's
|
|
106
|
+
* `plugins` array.
|
|
107
|
+
*
|
|
108
|
+
* Consumers should prefer `await theoPluginAsync(...)` over `theoPlugin(...)`
|
|
109
|
+
* when they want @theokit/ui + @tailwindcss/vite auto-chaining. The sync
|
|
110
|
+
* factory remains for backward compatibility and tests.
|
|
111
|
+
*/
|
|
112
|
+
declare function theoPluginAsync(rootOrOptions?: string | TheoPluginOptions): Promise<Plugin[]>;
|
|
113
|
+
declare function theoPlugin(rootOrOptions?: string | TheoPluginOptions): Plugin;
|
|
114
|
+
|
|
115
|
+
export { type Hook as IntegrationHook, type HookContext as IntegrationHookContext, type HookName as IntegrationHookName, type IntegrationRegistry, type IntegrationRegistryOptions, type IntegrationRoute, IntegrationRouteCollisionError, type RouteHandler as IntegrationRouteHandler, IntegrationVirtualModulePrefixError, type TheoIntegration, type TheoPluginOptions, createIntegrationRegistry, defineTheoIntegration, theoPlugin, theoPluginAsync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theokit",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -105,8 +105,6 @@
|
|
|
105
105
|
"dist"
|
|
106
106
|
],
|
|
107
107
|
"dependencies": {
|
|
108
|
-
"@theokit/agents": "^0.27.0",
|
|
109
|
-
"@theokit/http": "^0.5.4",
|
|
110
108
|
"@vitejs/plugin-react": "^4.7.0",
|
|
111
109
|
"busboy": "^1.6.0",
|
|
112
110
|
"cac": "^6.7.14",
|
|
@@ -120,7 +118,9 @@
|
|
|
120
118
|
"superjson": "^2.2.6",
|
|
121
119
|
"tsx": "^4.22.4",
|
|
122
120
|
"typescript": "^5.9.3",
|
|
123
|
-
"vite": "^6.4.3"
|
|
121
|
+
"vite": "^6.4.3",
|
|
122
|
+
"@theokit/http": "^0.5.4",
|
|
123
|
+
"@theokit/agents": "^0.28.0"
|
|
124
124
|
},
|
|
125
125
|
"peerDependencies": {
|
|
126
126
|
"@theokit/sdk": ">=2.9.0",
|