@guren/core 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/internal/deploy-build.d.ts +192 -0
- package/dist/internal/deploy-build.js +155 -0
- package/dist/internal/zod-compat.d.ts +141 -0
- package/dist/internal/zod-compat.js +89 -0
- package/package.json +12 -4
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @guren/core
|
|
2
|
+
|
|
3
|
+
The framework entry point for [Guren](https://guren.dev/) — a Laravel-inspired fullstack TypeScript framework, built for Bun. Application code imports the whole framework API from this one package.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
bun add @guren/core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Starting a new app? Scaffold one instead — it wires all of this up for you:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bunx create-guren-app my-app --auth
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Controller, Router, defineModel } from '@guren/core'
|
|
19
|
+
import { z } from 'zod'
|
|
20
|
+
import { posts } from '@/db/schema'
|
|
21
|
+
|
|
22
|
+
class Post extends defineModel(posts) {
|
|
23
|
+
static fillable = ['title', 'body']
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class PostController extends Controller {
|
|
27
|
+
async store() {
|
|
28
|
+
const data = await this.validateBody(
|
|
29
|
+
z.object({ title: z.string().min(1), body: z.string().min(1) }),
|
|
30
|
+
)
|
|
31
|
+
const post = await Post.create(data)
|
|
32
|
+
return this.redirect(`/posts/${post.id}`)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function registerWebRoutes(router: Router): void {
|
|
37
|
+
router.post('/posts', [PostController, 'store'])
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Boot the app with `createApp({ routes, providers })`, then `app.boot()` and `app.listen()`.
|
|
42
|
+
|
|
43
|
+
## Entry points
|
|
44
|
+
|
|
45
|
+
| Import | Contents |
|
|
46
|
+
|--------|----------|
|
|
47
|
+
| `@guren/core` | The framework API: controllers, routing, middleware, auth, models, queues, mail, events, notifications, cache, validation |
|
|
48
|
+
| `@guren/core/runtime` | Bun server helpers used by the scaffolded `bin/serve.ts` |
|
|
49
|
+
| `@guren/core/vite` | The Vite plugin: Inertia + React integration, codegen watching, SSR builds |
|
|
50
|
+
| `@guren/core/lambda` | AWS Lambda adapters: `createLambdaHandler`, `createSqsHandler`, `createScheduleHandler`, `createConsoleHandler` |
|
|
51
|
+
| `@guren/core/redis` | Redis-backed session, cache, and queue stores |
|
|
52
|
+
|
|
53
|
+
## CLI
|
|
54
|
+
|
|
55
|
+
The `guren` CLI ships with this package. `bunx guren` inside an app gives you scaffolding (`make:*`), codegen, migrations, and the integrity checks (`check`, `audit`, `doctor`).
|
|
56
|
+
|
|
57
|
+
## Documentation
|
|
58
|
+
|
|
59
|
+
Guides, API reference, and deployment docs (Cloudflare Workers, AWS Lambda, Vercel, Docker) live at [guren.dev/docs](https://guren.dev/docs).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiTokenStore, ApiToken, SessionStore, SessionData, OAuthStateStore, OAuthStatePayload } from '@guren/server';
|
|
2
2
|
export * from '@guren/server';
|
|
3
|
-
export { AccessorDefinitions, AccessorFn, BelongsToManyRecord, BelongsToManyRelationResult, BelongsToRecord, BelongsToRelationResult, BelongsToRequiredRecord, CastType, D1DatabaseHandle, D1DatabaseOptions, DrizzleAdapter, FindManyOptions, GroupCondition, HasManyRecord, HasManyRelationResult, HasManyThroughRecord, HasManyThroughRelationResult, HasOneRecord, HasOneRelationResult, HookCallback, HookName, InferModelInsert, InferModelRecord, MassAssignmentException, Model, ModelHooks, ModelNotFoundException, ModelObserver, ModelObserverConstructor, ModelPaginationMeta, MorphManyRecord, MorphManyRelationResult, MorphToRecord, MorphToRelationResult, MutatorDefinitions, MutatorFn, MySqlDatabase, MySqlDatabaseOptions, ORMAdapter, ORMAdapterAdvanced, OrderByClause, OrderByInput, OrderDefinition, OrderDirection, PaginateOptions, PaginatedResult, PlainObject, PostgresDatabase, PostgresDatabaseOptions, QueryBuilder, QueryBuilderOptions, ScopeFunction, SeederContext, SeederHandler, SimpleCondition, SoftDeletes, SoftDeletesStatic, SqliteDatabase, SqliteDatabaseOptions, TransactionHandle, TransactionModelScope, WhereClause, WhereCondition, WhereOperator, WithRelations, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from '@guren/orm';
|
|
3
|
+
export { AccessorDefinitions, AccessorFn, AwsDataApiDatabase, AwsDataApiDatabaseOptions, AwsDataApiSeederContext, BelongsToManyRecord, BelongsToManyRelationResult, BelongsToRecord, BelongsToRelationResult, BelongsToRequiredRecord, CastType, D1DatabaseHandle, D1DatabaseOptions, DrizzleAdapter, FindManyOptions, GroupCondition, HasManyRecord, HasManyRelationResult, HasManyThroughRecord, HasManyThroughRelationResult, HasOneRecord, HasOneRelationResult, HookCallback, HookName, InferModelInsert, InferModelRecord, MassAssignmentException, Model, ModelHooks, ModelNotFoundException, ModelObserver, ModelObserverConstructor, ModelPaginationMeta, MorphManyRecord, MorphManyRelationResult, MorphToRecord, MorphToRelationResult, MutatorDefinitions, MutatorFn, MySqlDatabase, MySqlDatabaseOptions, MySqlSeederContext, ORMAdapter, ORMAdapterAdvanced, OrderByClause, OrderByInput, OrderDefinition, OrderDirection, PaginateOptions, PaginatedResult, PlainObject, PostgresDatabase, PostgresDatabaseOptions, PostgresSeederContext, QueryBuilder, QueryBuilderOptions, ScopeFunction, SeederContext, SeederHandler, SimpleCondition, SoftDeletes, SoftDeletesStatic, SqliteDatabase, SqliteDatabaseOptions, SqliteSeederContext, TransactionHandle, TransactionModelScope, WhereClause, WhereCondition, WhereOperator, WithRelations, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from '@guren/orm';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Options for DatabaseApiTokenStore.
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
createMySqlDatabase,
|
|
13
13
|
createSqliteDatabase,
|
|
14
14
|
createD1Database,
|
|
15
|
+
createAwsDataApiDatabase,
|
|
15
16
|
runSeeders,
|
|
16
17
|
defineSeeder
|
|
17
18
|
} from "@guren/orm";
|
|
@@ -294,6 +295,7 @@ export {
|
|
|
294
295
|
ModelNotFoundException,
|
|
295
296
|
QueryBuilder,
|
|
296
297
|
SoftDeletes,
|
|
298
|
+
createAwsDataApiDatabase,
|
|
297
299
|
createD1Database,
|
|
298
300
|
createMySqlDatabase,
|
|
299
301
|
createPostgresDatabase,
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
type PathLike = string | URL;
|
|
2
|
+
type ManifestEntry = {
|
|
3
|
+
file?: string;
|
|
4
|
+
css?: string[];
|
|
5
|
+
};
|
|
6
|
+
type Manifest = Record<string, ManifestEntry>;
|
|
7
|
+
declare function resolvePathLike(value: PathLike): string;
|
|
8
|
+
/**
|
|
9
|
+
* Read the first manifest that parses, tolerating both Vite layouts
|
|
10
|
+
* (`.vite/manifest.json` and the flat `manifest.json` older configs emit), and
|
|
11
|
+
* report which path it was. A malformed file is skipped rather than fatal —
|
|
12
|
+
* the caller decides what a missing manifest means for its platform. The path
|
|
13
|
+
* is part of the result because a caller publishing the manifest location to
|
|
14
|
+
* the runtime has to name the file that was actually parsed: testing which one
|
|
15
|
+
* *exists* picks the malformed one that was just skipped.
|
|
16
|
+
*/
|
|
17
|
+
declare function readManifest(...paths: string[]): {
|
|
18
|
+
manifest: Manifest;
|
|
19
|
+
path: string;
|
|
20
|
+
} | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Throw unless `out` is safe to delete: it must be neither the app root nor a
|
|
23
|
+
* directory containing it.
|
|
24
|
+
*
|
|
25
|
+
* Relates two paths, so it canonicalizes both: comparing lexically would
|
|
26
|
+
* accept `outputDir` values that reach the app root the long way, and the
|
|
27
|
+
* delete that follows resolves the links regardless.
|
|
28
|
+
*
|
|
29
|
+
* Containment is then decided with `relative` rather than a string prefix
|
|
30
|
+
* because `out + sep` is `//` at the filesystem root, which no absolute path
|
|
31
|
+
* is prefixed by — a prefix test lets `outputDir: '/'` through. The escape
|
|
32
|
+
* test is `'..'` exactly or a `'../'` prefix, not `startsWith('..')`: a
|
|
33
|
+
* directory legitimately named `..-source` inside `out` yields the relative
|
|
34
|
+
* path `..-source`, which the looser test would read as an escape.
|
|
35
|
+
*
|
|
36
|
+
* Exported separately from `resetOutputDir` so a caller can validate the
|
|
37
|
+
* option early and delete later, but the delete itself should always go
|
|
38
|
+
* through `resetOutputDir`.
|
|
39
|
+
*
|
|
40
|
+
* @param label Platform name for the error message, e.g. `'Lambda build'`.
|
|
41
|
+
*/
|
|
42
|
+
declare function assertOutputDirOutsideRoot(out: string, root: string, label: string): void;
|
|
43
|
+
/**
|
|
44
|
+
* Delete the output directory so the build starts from a clean slate, after
|
|
45
|
+
* checking it is safe to delete.
|
|
46
|
+
*
|
|
47
|
+
* The check and the delete are one call on purpose: they were separate
|
|
48
|
+
* statements in each plugin, and a plugin that had only the delete has already
|
|
49
|
+
* shipped.
|
|
50
|
+
*
|
|
51
|
+
* @param label Platform name for the error message, e.g. `'Lambda build'`.
|
|
52
|
+
*/
|
|
53
|
+
declare function resetOutputDir(out: string, root: string, label: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Relative specifier for importing `target` from a module written into
|
|
56
|
+
* `fromDir`, in POSIX form so the emitted source is platform-agnostic.
|
|
57
|
+
*
|
|
58
|
+
* Relates two paths, so it canonicalizes both: the bundler resolves the
|
|
59
|
+
* emitted module from its real path, and a link that changes depth would
|
|
60
|
+
* otherwise leave the specifier short a `..` segment.
|
|
61
|
+
*
|
|
62
|
+
* @param label Platform name for the error message, e.g. `'Lambda build'`.
|
|
63
|
+
*/
|
|
64
|
+
declare function importSpecifier(fromDir: string, target: string, label: string): string;
|
|
65
|
+
interface ClientAssetEnv {
|
|
66
|
+
entry?: string;
|
|
67
|
+
styles?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Locate the built client entry and its CSS in the Vite client manifest, as
|
|
71
|
+
* the `/assets/`-prefixed URLs the Inertia head expects.
|
|
72
|
+
*
|
|
73
|
+
* Takes the public directory rather than the app root so a caller passing a
|
|
74
|
+
* custom `publicDir` is honoured.
|
|
75
|
+
*
|
|
76
|
+
* @param label Platform name for the warning message, e.g. `'Lambda build'`.
|
|
77
|
+
*/
|
|
78
|
+
declare function resolveClientAssetEnv(publicDir: string, clientEntryKey: string, label: string): ClientAssetEnv;
|
|
79
|
+
/**
|
|
80
|
+
* Absolute path of the built SSR entry chunk, or undefined when the app has no
|
|
81
|
+
* SSR build. Verifying that the chunk actually exports a renderer is left to
|
|
82
|
+
* the caller: the platforms disagree on whether importing it during a build is
|
|
83
|
+
* acceptable.
|
|
84
|
+
*
|
|
85
|
+
* @param label Platform name for the error messages, e.g. `'Lambda build'`.
|
|
86
|
+
*/
|
|
87
|
+
declare function resolveSsrEntryFile(ssrDir: string, ssrEntryKey: string, label: string): string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Runtime locations of a staged SSR bundle, for platforms that copy `ssrDir`
|
|
90
|
+
* under the function root and hand the layout to the server through
|
|
91
|
+
* environment variables. `prefix` is where the caller stages the directory —
|
|
92
|
+
* it cannot be derived here because staging happens later in the caller's own
|
|
93
|
+
* flow.
|
|
94
|
+
*
|
|
95
|
+
* The manifest path is derived from the file that parsed rather than the
|
|
96
|
+
* first one that exists: both Vite layouts occur in the wild, and a malformed
|
|
97
|
+
* `.vite/manifest.json` alongside a valid flat one would otherwise publish the
|
|
98
|
+
* path to the file that was skipped. It is optional only for the mid-build
|
|
99
|
+
* race where the manifest vanishes between `resolveSsrEntryFile` and this
|
|
100
|
+
* call — callers already hold a chunk path that manifest produced.
|
|
101
|
+
*/
|
|
102
|
+
declare function ssrRuntimePaths(ssrDir: string, ssrFile: string, prefix: string): {
|
|
103
|
+
entry: string;
|
|
104
|
+
manifest?: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Copy `public/` into a platform's static-asset staging directory.
|
|
108
|
+
*
|
|
109
|
+
* Two pieces of Guren-specific knowledge, not platform policy, which is why
|
|
110
|
+
* this is shared: the dev-mode `index.html` shell must never ship (it would
|
|
111
|
+
* shadow the app's root route on any host that serves static files first), and
|
|
112
|
+
* built assets self-reference the Vite plugin's derived base `/public/assets/`
|
|
113
|
+
* while HTML references use `/assets/` — so on a host without rewrites the
|
|
114
|
+
* built-assets directory has to appear under both prefixes.
|
|
115
|
+
*/
|
|
116
|
+
declare function stageStaticAssets(publicDir: string, assetsOut: string): void;
|
|
117
|
+
/** What a dev-only module is needed for, so a plugin can word its own message. */
|
|
118
|
+
type DevOnlyModuleKind = 'sqlite' | 'vite' | 'mcp';
|
|
119
|
+
interface DevOnlyModule {
|
|
120
|
+
readonly specifier: string;
|
|
121
|
+
readonly kind: DevOnlyModuleKind;
|
|
122
|
+
/**
|
|
123
|
+
* Names the importing code destructures. A stub must declare every one of
|
|
124
|
+
* them: an empty module fails the bundle with "no matching export" rather
|
|
125
|
+
* than at runtime. Empty means the module is only ever read through
|
|
126
|
+
* namespace property access, so an empty module suffices.
|
|
127
|
+
*/
|
|
128
|
+
readonly exportNames: readonly string[];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Modules that cannot run off Bun but sit in the graph of any app importing
|
|
132
|
+
* `@guren/core`, reached only through dev-time branches. Core aggregates
|
|
133
|
+
* `@guren/server` and `@guren/orm`, where these imports actually live, so it
|
|
134
|
+
* is the one package that sees the whole set — which is why the list lives
|
|
135
|
+
* here rather than in each plugin, where two copies had already drifted apart.
|
|
136
|
+
*
|
|
137
|
+
* Bundlers follow these imports even when they are dynamic, so without stubs
|
|
138
|
+
* the build either fails to resolve them or ships megabytes of dev tooling.
|
|
139
|
+
*
|
|
140
|
+
* - `sqlite` — the local sqlite ORM factory, opposite the platform's own
|
|
141
|
+
* database branch in `config/database.ts`.
|
|
142
|
+
* - `vite` — the dev asset server `Application` starts when serving locally.
|
|
143
|
+
* - `mcp` — the opt-in MCP endpoint's lazy imports, which drag the CLI
|
|
144
|
+
* generators (and Babel) plus the MCP SDK in behind them.
|
|
145
|
+
*
|
|
146
|
+
* `as const` so a consumer can key an exhaustive table on the specifiers and
|
|
147
|
+
* have a new entry here surface as a compile error there.
|
|
148
|
+
*/
|
|
149
|
+
declare const DEV_ONLY_MODULES: readonly [{
|
|
150
|
+
readonly specifier: "bun:sqlite";
|
|
151
|
+
readonly kind: "sqlite";
|
|
152
|
+
readonly exportNames: readonly ["Database"];
|
|
153
|
+
}, {
|
|
154
|
+
readonly specifier: "vite";
|
|
155
|
+
readonly kind: "vite";
|
|
156
|
+
readonly exportNames: readonly ["createServer"];
|
|
157
|
+
}, {
|
|
158
|
+
readonly specifier: "@guren/cli";
|
|
159
|
+
readonly kind: "mcp";
|
|
160
|
+
readonly exportNames: readonly [];
|
|
161
|
+
}, {
|
|
162
|
+
readonly specifier: "@modelcontextprotocol/sdk/server/mcp.js";
|
|
163
|
+
readonly kind: "mcp";
|
|
164
|
+
readonly exportNames: readonly ["McpServer", "ResourceTemplate"];
|
|
165
|
+
}, {
|
|
166
|
+
readonly specifier: "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
167
|
+
readonly kind: "mcp";
|
|
168
|
+
readonly exportNames: readonly ["WebStandardStreamableHTTPServerTransport"];
|
|
169
|
+
}];
|
|
170
|
+
type DevOnlySpecifier = (typeof DEV_ONLY_MODULES)[number]['specifier'];
|
|
171
|
+
/**
|
|
172
|
+
* Source for a stub replacing one dev-only module. Shared because what it
|
|
173
|
+
* encodes is a bundler constraint, not a platform choice: every name the
|
|
174
|
+
* importer destructures must be present or the bundle fails with "no matching
|
|
175
|
+
* export", and each is emitted as a throwing *function* because the stubbed
|
|
176
|
+
* names mix constructors (`new Database()`) with plain calls
|
|
177
|
+
* (`createServer()`) — a class invoked without `new` reports "Class
|
|
178
|
+
* constructor cannot be invoked without 'new'" instead of the real reason.
|
|
179
|
+
*
|
|
180
|
+
* @param message Platform-specific explanation, including the replacement API.
|
|
181
|
+
*/
|
|
182
|
+
declare function renderDevOnlyStub(module: DevOnlyModule, message: string): string;
|
|
183
|
+
/**
|
|
184
|
+
* The MCP SDK is only ever reached through subpaths, and a bundler alias on a
|
|
185
|
+
* package name does not cover them — which is why `DEV_ONLY_MODULES` lists
|
|
186
|
+
* each one. A platform whose aliasing supports prefixes should also route
|
|
187
|
+
* unlisted subpaths under this prefix to a stub, so a new subpath added
|
|
188
|
+
* upstream cannot pull the real SDK into a deployed bundle.
|
|
189
|
+
*/
|
|
190
|
+
declare const MCP_SDK_SUBPATH_PREFIX = "@modelcontextprotocol/sdk/";
|
|
191
|
+
|
|
192
|
+
export { type ClientAssetEnv, DEV_ONLY_MODULES, type DevOnlyModule, type DevOnlyModuleKind, type DevOnlySpecifier, MCP_SDK_SUBPATH_PREFIX, type Manifest, type ManifestEntry, type PathLike, assertOutputDirOutsideRoot, importSpecifier, readManifest, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// src/internal/deploy-build.ts
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync } from "fs";
|
|
3
|
+
import { basename, dirname, isAbsolute, relative, resolve, sep } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
function resolvePathLike(value) {
|
|
6
|
+
return value instanceof URL ? fileURLToPath(value) : resolve(String(value));
|
|
7
|
+
}
|
|
8
|
+
function readManifest(...paths) {
|
|
9
|
+
for (const path of paths) {
|
|
10
|
+
if (!existsSync(path)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
return { manifest: JSON.parse(readFileSync(path, "utf8")), path };
|
|
15
|
+
} catch {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
function manifestPaths(dir) {
|
|
22
|
+
return [resolve(dir, ".vite/manifest.json"), resolve(dir, "manifest.json")];
|
|
23
|
+
}
|
|
24
|
+
function realpathOfNearestExisting(path) {
|
|
25
|
+
try {
|
|
26
|
+
return realpathSync(path);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error.code !== "ENOENT") {
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const parent = dirname(path);
|
|
33
|
+
if (parent === path) {
|
|
34
|
+
return path;
|
|
35
|
+
}
|
|
36
|
+
return resolve(realpathOfNearestExisting(parent), basename(path));
|
|
37
|
+
}
|
|
38
|
+
function assertOutputDirOutsideRoot(out, root, label) {
|
|
39
|
+
const outToRoot = relative(realpathOfNearestExisting(out), realpathOfNearestExisting(root));
|
|
40
|
+
const rootIsInsideOut = outToRoot !== ".." && !outToRoot.startsWith(`..${sep}`) && !isAbsolute(outToRoot);
|
|
41
|
+
if (outToRoot === "" || rootIsInsideOut) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`${label}: outputDir (${out}) must be a directory outside or below the app root, never the root itself or a parent of it \u2014 it is deleted on every build.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function resetOutputDir(out, root, label) {
|
|
48
|
+
assertOutputDirOutsideRoot(out, root, label);
|
|
49
|
+
if (existsSync(out)) {
|
|
50
|
+
rmSync(out, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function importSpecifier(fromDir, target, label) {
|
|
54
|
+
const rel = relative(realpathOfNearestExisting(fromDir), realpathOfNearestExisting(target));
|
|
55
|
+
if (isAbsolute(rel)) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`${label}: ${target} cannot be imported relative to ${fromDir} (different drive or root?). Keep the app, SSR output, and outputDir on the same volume.`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const specifier = rel.split(sep).join("/");
|
|
61
|
+
return specifier.startsWith(".") ? specifier : `./${specifier}`;
|
|
62
|
+
}
|
|
63
|
+
function resolveClientAssetEnv(publicDir, clientEntryKey, label) {
|
|
64
|
+
const manifest = readManifest(...manifestPaths(resolve(publicDir, "assets")))?.manifest;
|
|
65
|
+
const entry = manifest?.[clientEntryKey];
|
|
66
|
+
if (!entry?.file) {
|
|
67
|
+
console.warn(
|
|
68
|
+
`${label}: no client manifest entry for "${clientEntryKey}"; GUREN_INERTIA_ENTRY will not be set.`
|
|
69
|
+
);
|
|
70
|
+
return {};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
entry: `/assets/${entry.file}`,
|
|
74
|
+
styles: entry.css?.length ? entry.css.map((file) => `/assets/${file}`).join(",") : void 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function resolveSsrEntryFile(ssrDir, ssrEntryKey, label) {
|
|
78
|
+
const manifest = readManifest(...manifestPaths(ssrDir))?.manifest;
|
|
79
|
+
const entryFile = manifest?.[ssrEntryKey]?.file;
|
|
80
|
+
if (!entryFile) {
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
const file = resolve(ssrDir, entryFile);
|
|
84
|
+
if (!file.startsWith(ssrDir + sep)) {
|
|
85
|
+
throw new Error(`${label}: SSR manifest entry "${entryFile}" escapes the SSR output directory ${ssrDir}.`);
|
|
86
|
+
}
|
|
87
|
+
if (!existsSync(file)) {
|
|
88
|
+
throw new Error(`${label}: SSR manifest points at ${file}, but the file does not exist.`);
|
|
89
|
+
}
|
|
90
|
+
return file;
|
|
91
|
+
}
|
|
92
|
+
function ssrRuntimePaths(ssrDir, ssrFile, prefix) {
|
|
93
|
+
const under = (target) => `${prefix}/${relative(ssrDir, target).split(sep).join("/")}`;
|
|
94
|
+
const read = readManifest(...manifestPaths(ssrDir));
|
|
95
|
+
return {
|
|
96
|
+
entry: under(ssrFile),
|
|
97
|
+
manifest: read ? under(read.path) : void 0
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function stageStaticAssets(publicDir, assetsOut) {
|
|
101
|
+
mkdirSync(assetsOut, { recursive: true });
|
|
102
|
+
if (!existsSync(publicDir)) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
cpSync(publicDir, assetsOut, { recursive: true });
|
|
106
|
+
const shadowingIndex = resolve(assetsOut, "index.html");
|
|
107
|
+
if (existsSync(shadowingIndex)) {
|
|
108
|
+
rmSync(shadowingIndex);
|
|
109
|
+
}
|
|
110
|
+
const clientAssetsDir = resolve(publicDir, "assets");
|
|
111
|
+
if (existsSync(clientAssetsDir)) {
|
|
112
|
+
cpSync(clientAssetsDir, resolve(assetsOut, "public/assets"), { recursive: true });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
var DEV_ONLY_MODULES = [
|
|
116
|
+
{ specifier: "bun:sqlite", kind: "sqlite", exportNames: ["Database"] },
|
|
117
|
+
{ specifier: "vite", kind: "vite", exportNames: ["createServer"] },
|
|
118
|
+
{ specifier: "@guren/cli", kind: "mcp", exportNames: [] },
|
|
119
|
+
{
|
|
120
|
+
specifier: "@modelcontextprotocol/sdk/server/mcp.js",
|
|
121
|
+
kind: "mcp",
|
|
122
|
+
exportNames: ["McpServer", "ResourceTemplate"]
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
specifier: "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js",
|
|
126
|
+
kind: "mcp",
|
|
127
|
+
exportNames: ["WebStandardStreamableHTTPServerTransport"]
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
function renderDevOnlyStub(module, message) {
|
|
131
|
+
if (module.exportNames.length === 0) {
|
|
132
|
+
return `// ${message}
|
|
133
|
+
export {}
|
|
134
|
+
`;
|
|
135
|
+
}
|
|
136
|
+
const throwing = module.exportNames.map((name) => `export function ${name}() { throw new Error(${JSON.stringify(message)}) }`).join("\n");
|
|
137
|
+
return `${throwing}
|
|
138
|
+
export default { ${module.exportNames.join(", ")} }
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
var MCP_SDK_SUBPATH_PREFIX = "@modelcontextprotocol/sdk/";
|
|
142
|
+
export {
|
|
143
|
+
DEV_ONLY_MODULES,
|
|
144
|
+
MCP_SDK_SUBPATH_PREFIX,
|
|
145
|
+
assertOutputDirOutsideRoot,
|
|
146
|
+
importSpecifier,
|
|
147
|
+
readManifest,
|
|
148
|
+
renderDevOnlyStub,
|
|
149
|
+
resetOutputDir,
|
|
150
|
+
resolveClientAssetEnv,
|
|
151
|
+
resolvePathLike,
|
|
152
|
+
resolveSsrEntryFile,
|
|
153
|
+
ssrRuntimePaths,
|
|
154
|
+
stageStaticAssets
|
|
155
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod 4 schema-reading primitives shared by `@guren/cli`'s TypeScript-type
|
|
3
|
+
* renderer (`src/schema-type-extractor.ts`) and the OpenAPI schema-object
|
|
4
|
+
* renderer (`@guren/openapi`).
|
|
5
|
+
*
|
|
6
|
+
* Internal by the rules in `contributing/api-stability.md`: reachable only
|
|
7
|
+
* through a deep import under `internal/`, never re-exported from
|
|
8
|
+
* `@guren/core`'s index.
|
|
9
|
+
*
|
|
10
|
+
* Zod 4 only. The zod 3 API (whether from the old `zod@3` package or the
|
|
11
|
+
* `zod/v3` subpath that zod 4 ships for migration) tags every node with
|
|
12
|
+
* `_def.typeName` and overloads `_def.type` to hold a nested schema — the
|
|
13
|
+
* ambiguity behind a bug this module's predecessors fixed twice. Rather than
|
|
14
|
+
* carrying both dialects forever, a v3 node is detected up front
|
|
15
|
+
* (`isZod3Schema`) and refused with `ZOD3_UNSUPPORTED_MESSAGE`; everything
|
|
16
|
+
* below it assumes the v4 layout, where `_def.type` is always the type name.
|
|
17
|
+
*
|
|
18
|
+
* What does NOT belong here: the two type switches that turn a node into an
|
|
19
|
+
* output (a TypeScript type string vs. an OpenAPI schema object). Their leaf
|
|
20
|
+
* vocabularies have legitimately diverged — the CLI renders `void`/`any`/
|
|
21
|
+
* `never`, which OpenAPI has no way to express — and that is a rendering
|
|
22
|
+
* decision, not schema-reading knowledge.
|
|
23
|
+
*
|
|
24
|
+
* Neither walker's `isOptional` belongs here either, but for a weaker reason
|
|
25
|
+
* than "they are both right": the CLI reads only the side of a `.pipe()` it
|
|
26
|
+
* renders, the OpenAPI walker requires both sides to permit omission, and
|
|
27
|
+
* *both* are approximations that a sufficiently odd pipeline can fool. Fixing
|
|
28
|
+
* them properly means simulating a parse, which is well beyond reading a
|
|
29
|
+
* `_def`. They stay with their callers until someone does that.
|
|
30
|
+
*/
|
|
31
|
+
interface ZodSchemaLike {
|
|
32
|
+
_def?: Record<string, unknown>;
|
|
33
|
+
/** zod 4's internal container; `values` is its own computed set of accepted literals. */
|
|
34
|
+
_zod?: {
|
|
35
|
+
values?: Set<unknown>;
|
|
36
|
+
};
|
|
37
|
+
type?: string;
|
|
38
|
+
shape?: Record<string, ZodSchemaLike>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Which side of a schema is being read.
|
|
42
|
+
*
|
|
43
|
+
* - `output` — the parsed value, i.e. what a controller receives after
|
|
44
|
+
* validation, or what a response body looks like.
|
|
45
|
+
* - `input` — the value a client has to send over the wire. Coercing and
|
|
46
|
+
* piped schemas can differ here from their output side.
|
|
47
|
+
*/
|
|
48
|
+
type SchemaIo = 'input' | 'output';
|
|
49
|
+
/**
|
|
50
|
+
* Whether this node was authored with the zod 3 API. Only v3 sets
|
|
51
|
+
* `_def.typeName` (`"ZodString"`), so its presence is the discriminator —
|
|
52
|
+
* checked before any other read, because on a v3 node `_def.type` holds a
|
|
53
|
+
* nested *schema* and every v4-shaped read below would misfire on it.
|
|
54
|
+
*/
|
|
55
|
+
declare function isZod3Schema(schema: ZodSchemaLike): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The one refusal message, stated once so the CLI's console warning and the
|
|
58
|
+
* OpenAPI document's warnings array cannot drift apart.
|
|
59
|
+
*/
|
|
60
|
+
declare const ZOD3_UNSUPPORTED_MESSAGE = "this schema was authored with the zod v3 API (zod@3 or the zod/v3 subpath), which Guren does not support. Rewrite it with the zod 4 API (`import { z } from 'zod'`).";
|
|
61
|
+
/** The node's type name: `_def.type` (`"string"`, `"object"`, …) or the schema's own `.type`. */
|
|
62
|
+
declare function getTypeName(schema: ZodSchemaLike): string | undefined;
|
|
63
|
+
/** `getTypeName` with `'unknown'` for a node that has no readable name. */
|
|
64
|
+
declare function typeOf(schema: ZodSchemaLike): string;
|
|
65
|
+
/**
|
|
66
|
+
* The schema at `def[key]`, if it actually holds one. The object check is
|
|
67
|
+
* load-bearing: `_def` is untyped data from someone else's package, and a key
|
|
68
|
+
* holding a string or function must read as absent, not as a schema. (The
|
|
69
|
+
* v3-era version of this helper took a key *list* and returned the first
|
|
70
|
+
* match; with one dialect there is no precedence left to encode.)
|
|
71
|
+
*/
|
|
72
|
+
declare function schemaAt(def: Record<string, unknown>, key: string): ZodSchemaLike | undefined;
|
|
73
|
+
/** The schema wrapped by a single-child wrapper (`.optional()`, `.readonly()`, `.catch()`, …) — always `_def.innerType` in zod 4. */
|
|
74
|
+
declare function innerSchema(def: Record<string, unknown>): ZodSchemaLike | undefined;
|
|
75
|
+
/** An array's element schema — `_def.element`, never `_def.type`, which holds the string `'array'`. */
|
|
76
|
+
declare function arrayElement(def: Record<string, unknown>): ZodSchemaLike | undefined;
|
|
77
|
+
/** A record's value schema — `_def.valueType`. */
|
|
78
|
+
declare function recordValueType(def: Record<string, unknown>): ZodSchemaLike | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Whether this node is a `.transform()`'s output half — a wrapped function
|
|
81
|
+
* with no type to read, as opposed to a schema that genuinely parses to
|
|
82
|
+
* `unknown`.
|
|
83
|
+
*/
|
|
84
|
+
declare function isTransform(schema: ZodSchemaLike): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Both halves of a `.pipe()`. Zod 4 uses one `pipe` node for both `.pipe()`
|
|
87
|
+
* and `.transform()`: `_def.in` is what a caller sends, `_def.out` what a
|
|
88
|
+
* controller receives — except for a transform, whose out side is the
|
|
89
|
+
* transform function itself and so has no type to read. `to` is therefore
|
|
90
|
+
* absent for a transform, leaving `from` as the only readable answer.
|
|
91
|
+
*/
|
|
92
|
+
declare function pipeSides(def: Record<string, unknown>): {
|
|
93
|
+
from: ZodSchemaLike | undefined;
|
|
94
|
+
to: ZodSchemaLike | undefined;
|
|
95
|
+
};
|
|
96
|
+
/** The one side of a `.pipe()` that describes the `io` direction being rendered. */
|
|
97
|
+
declare function pipeSide(def: Record<string, unknown>, io: SchemaIo): ZodSchemaLike | undefined;
|
|
98
|
+
/** An object's property map — `_def.shape`, or the schema's own `.shape`. */
|
|
99
|
+
declare function objectShape(schema: ZodSchemaLike): Record<string, ZodSchemaLike> | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* An enum's accepted values, read from zod's own computed set at
|
|
102
|
+
* `_zod.values` rather than re-derived from `_def.entries`. The distinction
|
|
103
|
+
* matters because `z.nativeEnum` produces the same node and a real TypeScript
|
|
104
|
+
* numeric enum's runtime object carries reverse mappings (`{ A: 0, '0': 'A' }`)
|
|
105
|
+
* — and any hand-rolled filter for those has a false positive: in
|
|
106
|
+
* `{ A: 'B', B: 1 }`, the key `A` *looks* like a reverse entry (`entries['B']`
|
|
107
|
+
* is a number) but zod accepts `'B'`. Reading zod's set makes what we document
|
|
108
|
+
* what zod parses, by construction. The `entries` fallback (values unfiltered)
|
|
109
|
+
* only runs if a future zod 4.x stops exposing the set.
|
|
110
|
+
*/
|
|
111
|
+
declare function enumValues(schema: ZodSchemaLike): Array<string | number>;
|
|
112
|
+
/** A literal's values — always the `_def.values` array in zod 4, which may hold more than one. */
|
|
113
|
+
declare function literalValues(def: Record<string, unknown>): unknown[];
|
|
114
|
+
/**
|
|
115
|
+
* Wrappers that neither add to a rendered type nor decide whether a field may
|
|
116
|
+
* be omitted — whatever they wrap answers both questions. (`lazy` is here for
|
|
117
|
+
* membership only: its child hides behind `_def.getter`, which no walker
|
|
118
|
+
* calls, so looking through it reads as "contents unavailable" rather than
|
|
119
|
+
* "unsupported type".)
|
|
120
|
+
*/
|
|
121
|
+
declare const TRANSPARENT_WRAPPERS: ReadonlySet<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Wrappers that pass their type through but *do* decide presence: each makes a
|
|
124
|
+
* field omissible, or (in `nonoptional`'s case) re-requires one.
|
|
125
|
+
*/
|
|
126
|
+
declare const PRESENCE_WRAPPERS: ReadonlySet<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Every type name that carries exactly one nested schema and no shape of its
|
|
129
|
+
* own — the union of the two sets above plus the two that render specially
|
|
130
|
+
* (`nullable` becomes a union with null; a pipe holds one schema per side).
|
|
131
|
+
*
|
|
132
|
+
* This is the vocabulary, not a policy: callers partition it however their
|
|
133
|
+
* rendering needs (the CLI splits transparent from presence-deciding because
|
|
134
|
+
* it walks types and presence separately; the OpenAPI walker looks through all
|
|
135
|
+
* of them uniformly). What none of them may do is disagree about *membership*
|
|
136
|
+
* — a name known to one walker and not the other silently changes an output,
|
|
137
|
+
* which is why the list lives here rather than once per package.
|
|
138
|
+
*/
|
|
139
|
+
declare const SINGLE_CHILD_WRAPPERS: ReadonlySet<string>;
|
|
140
|
+
|
|
141
|
+
export { PRESENCE_WRAPPERS, SINGLE_CHILD_WRAPPERS, type SchemaIo, TRANSPARENT_WRAPPERS, ZOD3_UNSUPPORTED_MESSAGE, type ZodSchemaLike, arrayElement, enumValues, getTypeName, innerSchema, isTransform, isZod3Schema, literalValues, objectShape, pipeSide, pipeSides, recordValueType, schemaAt, typeOf };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/internal/zod-compat.ts
|
|
2
|
+
function isZod3Schema(schema) {
|
|
3
|
+
return typeof schema._def?.typeName === "string";
|
|
4
|
+
}
|
|
5
|
+
var ZOD3_UNSUPPORTED_MESSAGE = "this schema was authored with the zod v3 API (zod@3 or the zod/v3 subpath), which Guren does not support. Rewrite it with the zod 4 API (`import { z } from 'zod'`).";
|
|
6
|
+
function getTypeName(schema) {
|
|
7
|
+
const name = schema._def?.type ?? schema.type;
|
|
8
|
+
return typeof name === "string" ? name : void 0;
|
|
9
|
+
}
|
|
10
|
+
function typeOf(schema) {
|
|
11
|
+
return getTypeName(schema) ?? "unknown";
|
|
12
|
+
}
|
|
13
|
+
function schemaAt(def, key) {
|
|
14
|
+
const candidate = def[key];
|
|
15
|
+
return candidate && typeof candidate === "object" ? candidate : void 0;
|
|
16
|
+
}
|
|
17
|
+
function innerSchema(def) {
|
|
18
|
+
return schemaAt(def, "innerType");
|
|
19
|
+
}
|
|
20
|
+
function arrayElement(def) {
|
|
21
|
+
return schemaAt(def, "element");
|
|
22
|
+
}
|
|
23
|
+
function recordValueType(def) {
|
|
24
|
+
return schemaAt(def, "valueType");
|
|
25
|
+
}
|
|
26
|
+
function isTransform(schema) {
|
|
27
|
+
return typeOf(schema) === "transform";
|
|
28
|
+
}
|
|
29
|
+
function pipeSides(def) {
|
|
30
|
+
const to = schemaAt(def, "out");
|
|
31
|
+
return { from: schemaAt(def, "in"), to: to && !isTransform(to) ? to : void 0 };
|
|
32
|
+
}
|
|
33
|
+
function pipeSide(def, io) {
|
|
34
|
+
const { from, to } = pipeSides(def);
|
|
35
|
+
return io === "output" && to ? to : from;
|
|
36
|
+
}
|
|
37
|
+
function objectShape(schema) {
|
|
38
|
+
const def = schema._def ?? {};
|
|
39
|
+
return def.shape ?? schema.shape;
|
|
40
|
+
}
|
|
41
|
+
function enumValues(schema) {
|
|
42
|
+
const values = schema._zod?.values;
|
|
43
|
+
if (values) {
|
|
44
|
+
return [...values].filter(
|
|
45
|
+
(value) => typeof value === "string" || typeof value === "number"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const entries = schema._def?.entries;
|
|
49
|
+
return entries ? Object.values(entries) : [];
|
|
50
|
+
}
|
|
51
|
+
function literalValues(def) {
|
|
52
|
+
return Array.isArray(def.values) ? def.values : [];
|
|
53
|
+
}
|
|
54
|
+
var TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set([
|
|
55
|
+
"catch",
|
|
56
|
+
"readonly",
|
|
57
|
+
"lazy"
|
|
58
|
+
]);
|
|
59
|
+
var PRESENCE_WRAPPERS = /* @__PURE__ */ new Set([
|
|
60
|
+
"optional",
|
|
61
|
+
"default",
|
|
62
|
+
"prefault",
|
|
63
|
+
"nonoptional"
|
|
64
|
+
]);
|
|
65
|
+
var SINGLE_CHILD_WRAPPERS = /* @__PURE__ */ new Set([
|
|
66
|
+
...TRANSPARENT_WRAPPERS,
|
|
67
|
+
...PRESENCE_WRAPPERS,
|
|
68
|
+
"nullable",
|
|
69
|
+
"pipe"
|
|
70
|
+
]);
|
|
71
|
+
export {
|
|
72
|
+
PRESENCE_WRAPPERS,
|
|
73
|
+
SINGLE_CHILD_WRAPPERS,
|
|
74
|
+
TRANSPARENT_WRAPPERS,
|
|
75
|
+
ZOD3_UNSUPPORTED_MESSAGE,
|
|
76
|
+
arrayElement,
|
|
77
|
+
enumValues,
|
|
78
|
+
getTypeName,
|
|
79
|
+
innerSchema,
|
|
80
|
+
isTransform,
|
|
81
|
+
isZod3Schema,
|
|
82
|
+
literalValues,
|
|
83
|
+
objectShape,
|
|
84
|
+
pipeSide,
|
|
85
|
+
pipeSides,
|
|
86
|
+
recordValueType,
|
|
87
|
+
schemaAt,
|
|
88
|
+
typeOf
|
|
89
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,6 +40,14 @@
|
|
|
40
40
|
"./redis": {
|
|
41
41
|
"types": "./dist/redis.d.ts",
|
|
42
42
|
"default": "./dist/redis.js"
|
|
43
|
+
},
|
|
44
|
+
"./internal/deploy-build": {
|
|
45
|
+
"types": "./dist/internal/deploy-build.d.ts",
|
|
46
|
+
"default": "./dist/internal/deploy-build.js"
|
|
47
|
+
},
|
|
48
|
+
"./internal/zod-compat": {
|
|
49
|
+
"types": "./dist/internal/zod-compat.d.ts",
|
|
50
|
+
"default": "./dist/internal/zod-compat.js"
|
|
43
51
|
}
|
|
44
52
|
},
|
|
45
53
|
"bin": {
|
|
@@ -52,9 +60,9 @@
|
|
|
52
60
|
"typecheck": "tsc --noEmit"
|
|
53
61
|
},
|
|
54
62
|
"dependencies": {
|
|
55
|
-
"@guren/cli": "^
|
|
56
|
-
"@guren/orm": "^
|
|
57
|
-
"@guren/server": "^
|
|
63
|
+
"@guren/cli": "^2.0.0",
|
|
64
|
+
"@guren/orm": "^2.0.0",
|
|
65
|
+
"@guren/server": "^2.0.0"
|
|
58
66
|
},
|
|
59
67
|
"devDependencies": {
|
|
60
68
|
"@types/node": "^20.14.10",
|