@guren/core 1.11.0 → 1.13.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/dist/agent.d.ts +1 -0
- package/dist/agent.js +2 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +28 -7
- package/dist/internal/deploy-build.d.ts +114 -1
- package/dist/internal/deploy-build.js +129 -12
- package/dist/internal/route-path.d.ts +1 -0
- package/dist/internal/route-path.js +2 -0
- package/dist/internal/zod-compat.d.ts +1 -142
- package/dist/internal/zod-compat.js +2 -141
- package/dist/internal/zod-json-schema.d.ts +1 -0
- package/dist/internal/zod-json-schema.js +2 -0
- package/package.json +16 -4
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@guren/server/agent";
|
package/dist/agent.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -578,6 +578,24 @@ interface DeliveryOptions {
|
|
|
578
578
|
*/
|
|
579
579
|
routeName?: string;
|
|
580
580
|
}
|
|
581
|
+
/**
|
|
582
|
+
* The single storage key prefix every attachment object lives under:
|
|
583
|
+
* `attachments/<id>/<name>` for an original, `attachments/<id>/variants/…`
|
|
584
|
+
* for a derivative, and `attachments/` itself for the prune sweep's
|
|
585
|
+
* directory listing.
|
|
586
|
+
*
|
|
587
|
+
* Exported, and re-exported from `@guren/core`, because the layout is not
|
|
588
|
+
* private to this file. `guren check`'s attachments rules judge, from
|
|
589
|
+
* another package, whether uploaded bytes land somewhere the app serves
|
|
590
|
+
* statically — and the ones that reach the objects themselves have to name
|
|
591
|
+
* `<disk root>/attachments` to do it. A restated copy of the prefix over
|
|
592
|
+
* there does not fail loudly when this layout moves (a shard level, a
|
|
593
|
+
* rename): it stops matching, answers "not reachable", and reports an
|
|
594
|
+
* exposed app as safe. A build-failing security rule failing *open*, with
|
|
595
|
+
* nothing going red anywhere. Import this instead of restating it.
|
|
596
|
+
*/
|
|
597
|
+
declare const ATTACHMENT_OBJECT_PREFIX = "attachments";
|
|
598
|
+
declare const DEFAULT_DELIVERY_ROUTE_NAME = "attachments.show";
|
|
581
599
|
interface PruneOptions {
|
|
582
600
|
/** Also delete `attachments/` storage prefixes that no row references. */
|
|
583
601
|
objects?: boolean;
|
|
@@ -853,4 +871,4 @@ declare class GenerateVariantsJob extends Job<GenerateVariantsPayload> {
|
|
|
853
871
|
failed(payload: GenerateVariantsPayload, _error: Error): Promise<void>;
|
|
854
872
|
}
|
|
855
873
|
//#endregion
|
|
856
|
-
export { type AccessorDefinitions, type AccessorFn, type AttachOptions, Attachable, type AttachableRecordId, type AttachableStatic, type AttachedCollectionOptions, type AttachmentCollectionSpec, type AttachmentData, AttachmentDeliveryController, type AttachmentRecord, type AttachmentSource, type AttachmentUrlOptions, type AttachmentVariantRecord, type AttachmentsDeclaration, AttachmentsPruneCommand, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type ConfigureAttachmentsOptions, type ConfiguredAttachments, type D1DatabaseHandle, type D1DatabaseOptions, DatabaseApiTokenStore, type DatabaseApiTokenStoreOptions, DatabaseOAuthStateStore, DatabaseSessionStore, type DatabaseSessionStoreOptions, type DeliveryOptions, type DeliveryServeMode, type DiskDeliveryConfig, DrizzleAdapter, type EagerLoadConstraint, type FindManyOptions, GenerateVariantsJob, type GenerateVariantsPayload, type GroupCondition, type HasManyRecord, type HasManyRelationResult, type HasManyThroughRecord, type HasManyThroughRelationResult, type HasOneRecord, type HasOneRelationResult, type HeicPolicy, type HookCallback, type HookName, type ImagePolicy, type ImageProcessor, type InferModelInsert, type InferModelRecord, MassAssignmentException, type MigrationRunSummary, type MigrationStatusEntry, Model, type ModelHooks, ModelNotFoundException, type ModelObserver, type ModelObserverConstructor, type ModelPaginationMeta, type ModelQueryOptions, type MorphManyRecord, type MorphManyRelationResult, type MorphToRecord, type MorphToRelationResult, type MutatorDefinitions, type MutatorFn, type MySqlDatabase, type MySqlDatabaseOptions, type MySqlSeederContext, type ORMAdapter, type ORMAdapterAdvanced, type OrderByClause, type OrderByInput, type OrderDefinition, type OrderDirection, type PaginateOptions, type PaginatedResult, type PlainObject, type PostgresDatabase, type PostgresDatabaseOptions, type PostgresSeederContext, type PruneOptions, type PruneReport, QueryBuilder, type QueryBuilderOptions, type ScopeFunction, type SeederContext, type SeederHandler, type SeederRunSummary, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type TransactionHandle, type TransactionModelScope, type VariantSpec, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, hasManyAttached, hasOneAttached, registerAttachmentRoutes, runSeeders };
|
|
874
|
+
export { ATTACHMENT_OBJECT_PREFIX, type AccessorDefinitions, type AccessorFn, type AttachOptions, Attachable, type AttachableRecordId, type AttachableStatic, type AttachedCollectionOptions, type AttachmentCollectionSpec, type AttachmentData, AttachmentDeliveryController, type AttachmentRecord, type AttachmentSource, type AttachmentUrlOptions, type AttachmentVariantRecord, type AttachmentsDeclaration, AttachmentsPruneCommand, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type ConfigureAttachmentsOptions, type ConfiguredAttachments, type D1DatabaseHandle, type D1DatabaseOptions, DEFAULT_DELIVERY_ROUTE_NAME, DatabaseApiTokenStore, type DatabaseApiTokenStoreOptions, DatabaseOAuthStateStore, DatabaseSessionStore, type DatabaseSessionStoreOptions, type DeliveryOptions, type DeliveryServeMode, type DiskDeliveryConfig, DrizzleAdapter, type EagerLoadConstraint, type FindManyOptions, GenerateVariantsJob, type GenerateVariantsPayload, type GroupCondition, type HasManyRecord, type HasManyRelationResult, type HasManyThroughRecord, type HasManyThroughRelationResult, type HasOneRecord, type HasOneRelationResult, type HeicPolicy, type HookCallback, type HookName, type ImagePolicy, type ImageProcessor, type InferModelInsert, type InferModelRecord, MassAssignmentException, type MigrationRunSummary, type MigrationStatusEntry, Model, type ModelHooks, ModelNotFoundException, type ModelObserver, type ModelObserverConstructor, type ModelPaginationMeta, type ModelQueryOptions, type MorphManyRecord, type MorphManyRelationResult, type MorphToRecord, type MorphToRelationResult, type MutatorDefinitions, type MutatorFn, type MySqlDatabase, type MySqlDatabaseOptions, type MySqlSeederContext, type ORMAdapter, type ORMAdapterAdvanced, type OrderByClause, type OrderByInput, type OrderDefinition, type OrderDirection, type PaginateOptions, type PaginatedResult, type PlainObject, type PostgresDatabase, type PostgresDatabaseOptions, type PostgresSeederContext, type PruneOptions, type PruneReport, QueryBuilder, type QueryBuilderOptions, type ScopeFunction, type SeederContext, type SeederHandler, type SeederRunSummary, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type TransactionHandle, type TransactionModelScope, type VariantSpec, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, hasManyAttached, hasOneAttached, registerAttachmentRoutes, runSeeders };
|
package/dist/index.js
CHANGED
|
@@ -665,6 +665,26 @@ function ulid(now = Date.now()) {
|
|
|
665
665
|
for (let i = 0; i < 16; i++) chars += ENCODING[lastRandom[i]];
|
|
666
666
|
return chars;
|
|
667
667
|
}
|
|
668
|
+
//#endregion
|
|
669
|
+
//#region src/attachments/engine.ts
|
|
670
|
+
/**
|
|
671
|
+
* The single storage key prefix every attachment object lives under:
|
|
672
|
+
* `attachments/<id>/<name>` for an original, `attachments/<id>/variants/…`
|
|
673
|
+
* for a derivative, and `attachments/` itself for the prune sweep's
|
|
674
|
+
* directory listing.
|
|
675
|
+
*
|
|
676
|
+
* Exported, and re-exported from `@guren/core`, because the layout is not
|
|
677
|
+
* private to this file. `guren check`'s attachments rules judge, from
|
|
678
|
+
* another package, whether uploaded bytes land somewhere the app serves
|
|
679
|
+
* statically — and the ones that reach the objects themselves have to name
|
|
680
|
+
* `<disk root>/attachments` to do it. A restated copy of the prefix over
|
|
681
|
+
* there does not fail loudly when this layout moves (a shard level, a
|
|
682
|
+
* rename): it stops matching, answers "not reachable", and reports an
|
|
683
|
+
* exposed app as safe. A build-failing security rule failing *open*, with
|
|
684
|
+
* nothing going red anywhere. Import this instead of restating it.
|
|
685
|
+
*/
|
|
686
|
+
const ATTACHMENT_OBJECT_PREFIX = "attachments";
|
|
687
|
+
const DEFAULT_DELIVERY_ROUTE_NAME = "attachments.show";
|
|
668
688
|
/**
|
|
669
689
|
* The inner (presigned) TTL behind a redirect. Fixed rather than derived
|
|
670
690
|
* from `urlExpiresIn`: the inner credential is minted per request, so it
|
|
@@ -769,7 +789,7 @@ var AttachmentEngine = class {
|
|
|
769
789
|
const inspection = await this.inspectImage(spec, collection, normalized, queued);
|
|
770
790
|
const id = ulid();
|
|
771
791
|
const name = inspection.name;
|
|
772
|
-
const path =
|
|
792
|
+
const path = `${ATTACHMENT_OBJECT_PREFIX}/${id}/${name}`;
|
|
773
793
|
const diskName = options.disk ?? this.defaultDisk;
|
|
774
794
|
const disk = this.storage().disk(diskName);
|
|
775
795
|
const contentType = inspection.contentType ?? normalized.declaredContentType ?? "application/octet-stream";
|
|
@@ -980,7 +1000,8 @@ var AttachmentEngine = class {
|
|
|
980
1000
|
}
|
|
981
1001
|
try {
|
|
982
1002
|
const result = await this.processor.process(inspection.bytes, variantSpec);
|
|
983
|
-
const
|
|
1003
|
+
const extension = VARIANT_EXTENSION[result.format] ?? result.format;
|
|
1004
|
+
const path = `${ATTACHMENT_OBJECT_PREFIX}/${id}/variants/${name}.${extension}`;
|
|
984
1005
|
await disk.put(path, Buffer.from(result.bytes), { contentType: IMAGE_MIME[result.format] ?? "application/octet-stream" });
|
|
985
1006
|
variants[name] = {
|
|
986
1007
|
status: "ready",
|
|
@@ -1043,7 +1064,7 @@ var AttachmentEngine = class {
|
|
|
1043
1064
|
if (sniffed?.format === "heic" && payload.heic === "convert") {
|
|
1044
1065
|
const converted = await this.processor.process(bytes, { format: "jpeg" });
|
|
1045
1066
|
const name = replaceExtension(row.name, "jpg");
|
|
1046
|
-
const path =
|
|
1067
|
+
const path = `${ATTACHMENT_OBJECT_PREFIX}/${row.id}/${name}`;
|
|
1047
1068
|
await disk.put(path, Buffer.from(converted.bytes), { contentType: "image/jpeg" });
|
|
1048
1069
|
if (path !== row.path) supersededPath = row.path;
|
|
1049
1070
|
bytes = converted.bytes;
|
|
@@ -1061,7 +1082,7 @@ var AttachmentEngine = class {
|
|
|
1061
1082
|
if (variants) updates.variants = variants;
|
|
1062
1083
|
updates.updatedAt = /* @__PURE__ */ new Date();
|
|
1063
1084
|
if (!await this.model.where({ id: row.id }).first()) {
|
|
1064
|
-
await disk.deleteDirectory(
|
|
1085
|
+
await disk.deleteDirectory(`${ATTACHMENT_OBJECT_PREFIX}/${row.id}`);
|
|
1065
1086
|
return;
|
|
1066
1087
|
}
|
|
1067
1088
|
await this.model.forceUpdate({ id: row.id }, updates);
|
|
@@ -1151,7 +1172,7 @@ var AttachmentEngine = class {
|
|
|
1151
1172
|
* reverse would leave invisible orphaned objects only a bucket audit finds.
|
|
1152
1173
|
*/
|
|
1153
1174
|
async purgeRows(rows) {
|
|
1154
|
-
for (const row of rows) await this.storage().disk(String(row.disk)).deleteDirectory(
|
|
1175
|
+
for (const row of rows) await this.storage().disk(String(row.disk)).deleteDirectory(`${ATTACHMENT_OBJECT_PREFIX}/${String(row.id)}`);
|
|
1155
1176
|
const ids = rows.map((row) => String(row.id));
|
|
1156
1177
|
for (let start = 0; start < ids.length; start += PRUNE_LOOKUP_CHUNK) await this.model.where({ id: ids.slice(start, start + PRUNE_LOOKUP_CHUNK) }).delete();
|
|
1157
1178
|
}
|
|
@@ -1242,7 +1263,7 @@ var AttachmentEngine = class {
|
|
|
1242
1263
|
let disk;
|
|
1243
1264
|
try {
|
|
1244
1265
|
disk = this.storage().disk(diskName);
|
|
1245
|
-
prefixes = await disk.directories(
|
|
1266
|
+
prefixes = await disk.directories(ATTACHMENT_OBJECT_PREFIX);
|
|
1246
1267
|
} catch (error) {
|
|
1247
1268
|
report.skippedDisks.push({
|
|
1248
1269
|
disk: diskName,
|
|
@@ -1873,4 +1894,4 @@ function hasManyAttached(options = {}) {
|
|
|
1873
1894
|
return buildSpec("many", options);
|
|
1874
1895
|
}
|
|
1875
1896
|
//#endregion
|
|
1876
|
-
export { Attachable, AttachmentDeliveryController, AttachmentsPruneCommand, DatabaseApiTokenStore, DatabaseOAuthStateStore, DatabaseSessionStore, DrizzleAdapter, GenerateVariantsJob, MassAssignmentException, Model, ModelNotFoundException, QueryBuilder, SoftDeletes, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, hasManyAttached, hasOneAttached, registerAttachmentRoutes, runSeeders };
|
|
1897
|
+
export { ATTACHMENT_OBJECT_PREFIX, Attachable, AttachmentDeliveryController, AttachmentsPruneCommand, DEFAULT_DELIVERY_ROUTE_NAME, DatabaseApiTokenStore, DatabaseOAuthStateStore, DatabaseSessionStore, DrizzleAdapter, GenerateVariantsJob, MassAssignmentException, Model, ModelNotFoundException, QueryBuilder, SoftDeletes, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, hasManyAttached, hasOneAttached, registerAttachmentRoutes, runSeeders };
|
|
@@ -139,6 +139,38 @@ declare function ssrRuntimePaths(ssrDir: string, ssrFile: string, prefix: string
|
|
|
139
139
|
* built-assets directory has to appear under both prefixes.
|
|
140
140
|
*/
|
|
141
141
|
declare function stageStaticAssets(publicDir: string, assetsOut: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Extensions a browser renders as a *document* in the serving origin, for a
|
|
144
|
+
* platform that answers for `public/` before the app ever runs.
|
|
145
|
+
*
|
|
146
|
+
* Exactly the set `@guren/server`'s `rendersAsDocument` matches over Hono's
|
|
147
|
+
* mime table — the same two inputs the framework's own static guard reads, so
|
|
148
|
+
* a file that downloads locally downloads on a deploy target too. Written out
|
|
149
|
+
* rather than derived because this module imports nothing from the framework
|
|
150
|
+
* (see the header); `packages/server/tests/http/static-documents.test.ts`
|
|
151
|
+
* recomputes it from that table and fails when the two disagree, so a document
|
|
152
|
+
* type Hono adds cannot pass unnoticed.
|
|
153
|
+
*
|
|
154
|
+
* Two things the list does not reach, both of them the framework's own
|
|
155
|
+
* blind spots rather than new ones. `text/xsl` is a document type
|
|
156
|
+
* `rendersAsDocument` matches, but Hono's table names no extension for it, so
|
|
157
|
+
* `getMimeType` returns nothing for a `.xsl` file and the framework serves it
|
|
158
|
+
* unguarded too — adding it here would make a deploy target stricter than the
|
|
159
|
+
* app it deployed. And extension *case*: `getMimeType` lowercases before its
|
|
160
|
+
* lookup, so the framework guard does fire for `logo.SVG`, and a platform
|
|
161
|
+
* matching a literal pattern does not. Each plugin closes that where its own
|
|
162
|
+
* matcher allows, and the three answers differ — see each one's own comment
|
|
163
|
+
* rather than a list here that goes stale on the next target.
|
|
164
|
+
*/
|
|
165
|
+
declare const DOCUMENT_ASSET_EXTENSIONS: readonly ['htm', 'html', 'svg', 'xhtml', 'xml'];
|
|
166
|
+
/**
|
|
167
|
+
* The pair `applyDocumentDisposition` sets, for a platform to set on the same
|
|
168
|
+
* files. Same reasoning as the framework's: `attachment` is honoured for
|
|
169
|
+
* navigations and ignored for subresource loads, so `<img src="/logo.svg">`
|
|
170
|
+
* and a CSS `url()` keep working while the URL opened directly downloads;
|
|
171
|
+
* `nosniff` stops the promotion a browser would otherwise do on its own.
|
|
172
|
+
*/
|
|
173
|
+
declare const DOCUMENT_ASSET_HEADERS: Readonly<Record<string, string>>;
|
|
142
174
|
/** What a dev-only module is needed for, so a plugin can word its own message. */
|
|
143
175
|
type DevOnlyModuleKind = 'sqlite' | 'vite' | 'mcp' | 'sql-driver';
|
|
144
176
|
interface DevOnlyModule {
|
|
@@ -196,6 +228,76 @@ declare const DEV_ONLY_MODULES: readonly [{
|
|
|
196
228
|
readonly kind: 'mcp';
|
|
197
229
|
readonly exportNames: readonly ["WebStandardStreamableHTTPServerTransport"];
|
|
198
230
|
}];
|
|
231
|
+
/** One entry of `DEV_ONLY_MODULES`, with its `kind` still narrowed. */
|
|
232
|
+
type DevOnlyModuleEntry = (typeof DEV_ONLY_MODULES)[number];
|
|
233
|
+
/**
|
|
234
|
+
* The specifier `@guren/plugin-mcp` dynamically imports to serve the App MCP
|
|
235
|
+
* endpoint (RFC 0016 §7). Named here rather than inline in three plugins
|
|
236
|
+
* because it is the one entry of `DEV_ONLY_MODULES` whose stubbing is
|
|
237
|
+
* conditional, and each platform has to recognise it.
|
|
238
|
+
*/
|
|
239
|
+
declare const MCP_TRANSPORT_SPECIFIER = "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
240
|
+
/** The package an app declares to opt into the App MCP endpoint. */
|
|
241
|
+
declare const MCP_PLUGIN_PACKAGE = "@guren/plugin-mcp";
|
|
242
|
+
/**
|
|
243
|
+
* Whether the app has opted into the App MCP endpoint (RFC 0016 §7).
|
|
244
|
+
*
|
|
245
|
+
* Resolves the RFC's Open Question 5 — how a build learns that an app wants
|
|
246
|
+
* the MCP transport — as **dependency sniffing**: declaring
|
|
247
|
+
* `@guren/plugin-mcp` in `dependencies` *is* the opt-in. Nothing else is
|
|
248
|
+
* asked of the developer, because there is nothing else to ask: an app that
|
|
249
|
+
* installed the plugin and mounted it wants the endpoint to work, and a build
|
|
250
|
+
* flag it must also remember to pass is a way for the endpoint to be silently
|
|
251
|
+
* compiled shut on a platform. The build does not *enable* anything here — it
|
|
252
|
+
* stops sabotaging what the app already configured.
|
|
253
|
+
*
|
|
254
|
+
* `dependencies` only, never `devDependencies`: a devDependency does not ship,
|
|
255
|
+
* so an app that has one has no MCP endpoint at runtime to protect. Reading
|
|
256
|
+
* both would keep the transport in the bundle of every app that merely
|
|
257
|
+
* develops against the plugin.
|
|
258
|
+
*
|
|
259
|
+
* Absent, unreadable, or malformed manifest answers `false` — no opt-in
|
|
260
|
+
* evidence is not the same as opt-in, and the false direction is the safe
|
|
261
|
+
* one: the transport stays stubbed, which is exactly today's behaviour.
|
|
262
|
+
*/
|
|
263
|
+
declare function appUsesMcpPlugin(root: string): boolean;
|
|
264
|
+
/**
|
|
265
|
+
* The dev-only modules that must stay stubbed for this app.
|
|
266
|
+
*
|
|
267
|
+
* The policy layer over `DEV_ONLY_MODULES`, which stays exported and
|
|
268
|
+
* unchanged: it is the full inventory, and other consumers (the wrangler
|
|
269
|
+
* bundle probe, the stub-filename table) read it as such. What varies per app
|
|
270
|
+
* is only whether the *transport* entry is in force.
|
|
271
|
+
*
|
|
272
|
+
* `@guren/plugin-mcp` reaches the App MCP endpoint through exactly one lazy
|
|
273
|
+
* import — `MCP_TRANSPORT_SPECIFIER` — plus static imports of the SDK's
|
|
274
|
+
* `server/index.js` and `types.js`, which no entry here names. Stubbing the
|
|
275
|
+
* transport therefore compiles the endpoint shut on every platform, which is
|
|
276
|
+
* what the three deploy plugins did until RFC 0016 Phase 4a. Dropping the
|
|
277
|
+
* entry for an app that declared the plugin is the whole of the fix.
|
|
278
|
+
*
|
|
279
|
+
* `@modelcontextprotocol/sdk/server/mcp.js` stays stubbed regardless, and the
|
|
280
|
+
* distinction matters: that is the **Dev** MCP's `McpServer`, reached from
|
|
281
|
+
* `@guren/server`'s `McpServiceProvider`, which drives the CLI's code
|
|
282
|
+
* generators against the filesystem. It is compiled shut by the `NODE_ENV`
|
|
283
|
+
* define anyway; the stub is the second guard, and a deployed app has no use
|
|
284
|
+
* for it either way. Same for `@guren/cli` behind it, and for `bun:sqlite`
|
|
285
|
+
* and `vite`, none of which the App MCP endpoint touches.
|
|
286
|
+
*
|
|
287
|
+
* The return type keeps each entry's narrow `kind` so that a platform can
|
|
288
|
+
* index its `Record<kind, message>` table with `module.kind` at all. What
|
|
289
|
+
* makes those tables exhaustive is not this function — each is keyed off
|
|
290
|
+
* `DEV_ONLY_MODULES` directly (on Workers, that list plus
|
|
291
|
+
* `SQL_CLIENT_MODULES`), which is what turns a new kind there into a compile
|
|
292
|
+
* error there. Widening the return to `readonly DevOnlyModule[]` would leave
|
|
293
|
+
* that exhaustiveness untouched and instead break every one of the lookups,
|
|
294
|
+
* since `DevOnlyModuleKind` includes `'sql-driver'` — a kind Lambda's and
|
|
295
|
+
* Vercel's tables deliberately omit, because those two platforms decide the
|
|
296
|
+
* SQL clients per app rather than per platform.
|
|
297
|
+
*/
|
|
298
|
+
declare function stubbableDevOnlyModules(options: {
|
|
299
|
+
mcpPlugin: boolean;
|
|
300
|
+
}): readonly DevOnlyModuleEntry[];
|
|
199
301
|
/**
|
|
200
302
|
* A database `@guren/orm` can connect through, named after the factory an
|
|
201
303
|
* app's database config calls to declare it.
|
|
@@ -346,6 +448,17 @@ declare function unusedSqlClients(input: {
|
|
|
346
448
|
dialects?: readonly DatabaseDialect[];
|
|
347
449
|
}): readonly UnusedSqlClient[];
|
|
348
450
|
type DevOnlySpecifier = (typeof DEV_ONLY_MODULES)[number]['specifier'];
|
|
451
|
+
/**
|
|
452
|
+
* Source for a stub replacing one dev-only module. Shared because what it
|
|
453
|
+
* encodes is a bundler constraint, not a platform choice: every name the
|
|
454
|
+
* importer destructures must be present or the bundle fails with "no matching
|
|
455
|
+
* export", and each is emitted as a throwing *function* because the stubbed
|
|
456
|
+
* names mix constructors (`new Database()`) with plain calls
|
|
457
|
+
* (`createServer()`) — a class invoked without `new` reports "Class
|
|
458
|
+
* constructor cannot be invoked without 'new'" instead of the real reason.
|
|
459
|
+
*
|
|
460
|
+
* @param message Platform-specific explanation, including the replacement API.
|
|
461
|
+
*/
|
|
349
462
|
declare function renderDevOnlyStub(module: DevOnlyModule, message: string): string;
|
|
350
463
|
/**
|
|
351
464
|
* The MCP SDK is only ever reached through subpaths, and a bundler alias on a
|
|
@@ -356,4 +469,4 @@ declare function renderDevOnlyStub(module: DevOnlyModule, message: string): stri
|
|
|
356
469
|
*/
|
|
357
470
|
declare const MCP_SDK_SUBPATH_PREFIX = "@modelcontextprotocol/sdk/";
|
|
358
471
|
//#endregion
|
|
359
|
-
export { ClientAssetEnv, DATABASE_CONFIG_CANDIDATES, DATABASE_DIALECTS, DATABASE_FACTORIES, DEV_ONLY_MODULES, DatabaseDialect, DatabaseDialectDetection, DevOnlyModule, DevOnlyModuleKind, DevOnlySpecifier, MCP_SDK_SUBPATH_PREFIX, Manifest, ManifestEntry, PathLike, SQL_CLIENT_MODULES, SqlClientModule, SqlClientSpecifier, UnusedSqlClient, assertOutputDirOutsideRoot, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, unusedSqlClients };
|
|
472
|
+
export { ClientAssetEnv, DATABASE_CONFIG_CANDIDATES, DATABASE_DIALECTS, DATABASE_FACTORIES, DEV_ONLY_MODULES, DOCUMENT_ASSET_EXTENSIONS, DOCUMENT_ASSET_HEADERS, DatabaseDialect, DatabaseDialectDetection, DevOnlyModule, DevOnlyModuleEntry, DevOnlyModuleKind, DevOnlySpecifier, MCP_PLUGIN_PACKAGE, MCP_SDK_SUBPATH_PREFIX, MCP_TRANSPORT_SPECIFIER, Manifest, ManifestEntry, PathLike, SQL_CLIENT_MODULES, SqlClientModule, SqlClientSpecifier, UnusedSqlClient, appUsesMcpPlugin, assertOutputDirOutsideRoot, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, unusedSqlClients };
|
|
@@ -282,6 +282,47 @@ function stageStaticAssets(publicDir, assetsOut) {
|
|
|
282
282
|
if (existsSync(clientAssetsDir)) cpSync(clientAssetsDir, resolve(assetsOut, "public/assets"), { recursive: true });
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
|
+
* Extensions a browser renders as a *document* in the serving origin, for a
|
|
286
|
+
* platform that answers for `public/` before the app ever runs.
|
|
287
|
+
*
|
|
288
|
+
* Exactly the set `@guren/server`'s `rendersAsDocument` matches over Hono's
|
|
289
|
+
* mime table — the same two inputs the framework's own static guard reads, so
|
|
290
|
+
* a file that downloads locally downloads on a deploy target too. Written out
|
|
291
|
+
* rather than derived because this module imports nothing from the framework
|
|
292
|
+
* (see the header); `packages/server/tests/http/static-documents.test.ts`
|
|
293
|
+
* recomputes it from that table and fails when the two disagree, so a document
|
|
294
|
+
* type Hono adds cannot pass unnoticed.
|
|
295
|
+
*
|
|
296
|
+
* Two things the list does not reach, both of them the framework's own
|
|
297
|
+
* blind spots rather than new ones. `text/xsl` is a document type
|
|
298
|
+
* `rendersAsDocument` matches, but Hono's table names no extension for it, so
|
|
299
|
+
* `getMimeType` returns nothing for a `.xsl` file and the framework serves it
|
|
300
|
+
* unguarded too — adding it here would make a deploy target stricter than the
|
|
301
|
+
* app it deployed. And extension *case*: `getMimeType` lowercases before its
|
|
302
|
+
* lookup, so the framework guard does fire for `logo.SVG`, and a platform
|
|
303
|
+
* matching a literal pattern does not. Each plugin closes that where its own
|
|
304
|
+
* matcher allows, and the three answers differ — see each one's own comment
|
|
305
|
+
* rather than a list here that goes stale on the next target.
|
|
306
|
+
*/
|
|
307
|
+
const DOCUMENT_ASSET_EXTENSIONS = [
|
|
308
|
+
"htm",
|
|
309
|
+
"html",
|
|
310
|
+
"svg",
|
|
311
|
+
"xhtml",
|
|
312
|
+
"xml"
|
|
313
|
+
];
|
|
314
|
+
/**
|
|
315
|
+
* The pair `applyDocumentDisposition` sets, for a platform to set on the same
|
|
316
|
+
* files. Same reasoning as the framework's: `attachment` is honoured for
|
|
317
|
+
* navigations and ignored for subresource loads, so `<img src="/logo.svg">`
|
|
318
|
+
* and a CSS `url()` keep working while the URL opened directly downloads;
|
|
319
|
+
* `nosniff` stops the promotion a browser would otherwise do on its own.
|
|
320
|
+
*/
|
|
321
|
+
const DOCUMENT_ASSET_HEADERS = {
|
|
322
|
+
"Content-Disposition": "attachment",
|
|
323
|
+
"X-Content-Type-Options": "nosniff"
|
|
324
|
+
};
|
|
325
|
+
/**
|
|
285
326
|
* Modules that cannot run off Bun but sit in the graph of any app importing
|
|
286
327
|
* `@guren/core`, reached only through dev-time branches. Core aggregates
|
|
287
328
|
* `@guren/server` and `@guren/orm`, where these imports actually live, so it
|
|
@@ -332,6 +373,82 @@ const DEV_ONLY_MODULES = [
|
|
|
332
373
|
}
|
|
333
374
|
];
|
|
334
375
|
/**
|
|
376
|
+
* The specifier `@guren/plugin-mcp` dynamically imports to serve the App MCP
|
|
377
|
+
* endpoint (RFC 0016 §7). Named here rather than inline in three plugins
|
|
378
|
+
* because it is the one entry of `DEV_ONLY_MODULES` whose stubbing is
|
|
379
|
+
* conditional, and each platform has to recognise it.
|
|
380
|
+
*/
|
|
381
|
+
const MCP_TRANSPORT_SPECIFIER = "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
382
|
+
/** The package an app declares to opt into the App MCP endpoint. */
|
|
383
|
+
const MCP_PLUGIN_PACKAGE = "@guren/plugin-mcp";
|
|
384
|
+
/**
|
|
385
|
+
* Whether the app has opted into the App MCP endpoint (RFC 0016 §7).
|
|
386
|
+
*
|
|
387
|
+
* Resolves the RFC's Open Question 5 — how a build learns that an app wants
|
|
388
|
+
* the MCP transport — as **dependency sniffing**: declaring
|
|
389
|
+
* `@guren/plugin-mcp` in `dependencies` *is* the opt-in. Nothing else is
|
|
390
|
+
* asked of the developer, because there is nothing else to ask: an app that
|
|
391
|
+
* installed the plugin and mounted it wants the endpoint to work, and a build
|
|
392
|
+
* flag it must also remember to pass is a way for the endpoint to be silently
|
|
393
|
+
* compiled shut on a platform. The build does not *enable* anything here — it
|
|
394
|
+
* stops sabotaging what the app already configured.
|
|
395
|
+
*
|
|
396
|
+
* `dependencies` only, never `devDependencies`: a devDependency does not ship,
|
|
397
|
+
* so an app that has one has no MCP endpoint at runtime to protect. Reading
|
|
398
|
+
* both would keep the transport in the bundle of every app that merely
|
|
399
|
+
* develops against the plugin.
|
|
400
|
+
*
|
|
401
|
+
* Absent, unreadable, or malformed manifest answers `false` — no opt-in
|
|
402
|
+
* evidence is not the same as opt-in, and the false direction is the safe
|
|
403
|
+
* one: the transport stays stubbed, which is exactly today's behaviour.
|
|
404
|
+
*/
|
|
405
|
+
function appUsesMcpPlugin(root) {
|
|
406
|
+
try {
|
|
407
|
+
const dependencies = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8")).dependencies;
|
|
408
|
+
return typeof dependencies === "object" && dependencies !== null && "@guren/plugin-mcp" in dependencies;
|
|
409
|
+
} catch {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* The dev-only modules that must stay stubbed for this app.
|
|
415
|
+
*
|
|
416
|
+
* The policy layer over `DEV_ONLY_MODULES`, which stays exported and
|
|
417
|
+
* unchanged: it is the full inventory, and other consumers (the wrangler
|
|
418
|
+
* bundle probe, the stub-filename table) read it as such. What varies per app
|
|
419
|
+
* is only whether the *transport* entry is in force.
|
|
420
|
+
*
|
|
421
|
+
* `@guren/plugin-mcp` reaches the App MCP endpoint through exactly one lazy
|
|
422
|
+
* import — `MCP_TRANSPORT_SPECIFIER` — plus static imports of the SDK's
|
|
423
|
+
* `server/index.js` and `types.js`, which no entry here names. Stubbing the
|
|
424
|
+
* transport therefore compiles the endpoint shut on every platform, which is
|
|
425
|
+
* what the three deploy plugins did until RFC 0016 Phase 4a. Dropping the
|
|
426
|
+
* entry for an app that declared the plugin is the whole of the fix.
|
|
427
|
+
*
|
|
428
|
+
* `@modelcontextprotocol/sdk/server/mcp.js` stays stubbed regardless, and the
|
|
429
|
+
* distinction matters: that is the **Dev** MCP's `McpServer`, reached from
|
|
430
|
+
* `@guren/server`'s `McpServiceProvider`, which drives the CLI's code
|
|
431
|
+
* generators against the filesystem. It is compiled shut by the `NODE_ENV`
|
|
432
|
+
* define anyway; the stub is the second guard, and a deployed app has no use
|
|
433
|
+
* for it either way. Same for `@guren/cli` behind it, and for `bun:sqlite`
|
|
434
|
+
* and `vite`, none of which the App MCP endpoint touches.
|
|
435
|
+
*
|
|
436
|
+
* The return type keeps each entry's narrow `kind` so that a platform can
|
|
437
|
+
* index its `Record<kind, message>` table with `module.kind` at all. What
|
|
438
|
+
* makes those tables exhaustive is not this function — each is keyed off
|
|
439
|
+
* `DEV_ONLY_MODULES` directly (on Workers, that list plus
|
|
440
|
+
* `SQL_CLIENT_MODULES`), which is what turns a new kind there into a compile
|
|
441
|
+
* error there. Widening the return to `readonly DevOnlyModule[]` would leave
|
|
442
|
+
* that exhaustiveness untouched and instead break every one of the lookups,
|
|
443
|
+
* since `DevOnlyModuleKind` includes `'sql-driver'` — a kind Lambda's and
|
|
444
|
+
* Vercel's tables deliberately omit, because those two platforms decide the
|
|
445
|
+
* SQL clients per app rather than per platform.
|
|
446
|
+
*/
|
|
447
|
+
function stubbableDevOnlyModules(options) {
|
|
448
|
+
if (!options.mcpPlugin) return DEV_ONLY_MODULES;
|
|
449
|
+
return DEV_ONLY_MODULES.filter((module) => module.specifier !== MCP_TRANSPORT_SPECIFIER);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
335
452
|
* The `@guren/orm` factory names an app's database config calls, and the
|
|
336
453
|
* dialect each one declares.
|
|
337
454
|
*
|
|
@@ -520,17 +637,6 @@ function unusedSqlClients(input) {
|
|
|
520
637
|
}));
|
|
521
638
|
}
|
|
522
639
|
/**
|
|
523
|
-
* Source for a stub replacing one dev-only module. Shared because what it
|
|
524
|
-
* encodes is a bundler constraint, not a platform choice: every name the
|
|
525
|
-
* importer destructures must be present or the bundle fails with "no matching
|
|
526
|
-
* export", and each is emitted as a throwing *function* because the stubbed
|
|
527
|
-
* names mix constructors (`new Database()`) with plain calls
|
|
528
|
-
* (`createServer()`) — a class invoked without `new` reports "Class
|
|
529
|
-
* constructor cannot be invoked without 'new'" instead of the real reason.
|
|
530
|
-
*
|
|
531
|
-
* @param message Platform-specific explanation, including the replacement API.
|
|
532
|
-
*/
|
|
533
|
-
/**
|
|
534
640
|
* A JavaScript string literal for `value`.
|
|
535
641
|
*
|
|
536
642
|
* `JSON.stringify` alone is not one: JSON and JavaScript disagree about
|
|
@@ -541,6 +647,17 @@ function unusedSqlClients(input) {
|
|
|
541
647
|
function toJsStringLiteral(value) {
|
|
542
648
|
return JSON.stringify(value).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
543
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* Source for a stub replacing one dev-only module. Shared because what it
|
|
652
|
+
* encodes is a bundler constraint, not a platform choice: every name the
|
|
653
|
+
* importer destructures must be present or the bundle fails with "no matching
|
|
654
|
+
* export", and each is emitted as a throwing *function* because the stubbed
|
|
655
|
+
* names mix constructors (`new Database()`) with plain calls
|
|
656
|
+
* (`createServer()`) — a class invoked without `new` reports "Class
|
|
657
|
+
* constructor cannot be invoked without 'new'" instead of the real reason.
|
|
658
|
+
*
|
|
659
|
+
* @param message Platform-specific explanation, including the replacement API.
|
|
660
|
+
*/
|
|
544
661
|
function renderDevOnlyStub(module, message) {
|
|
545
662
|
const comment = message.replace(/[\r\n\u2028\u2029]+/g, " ");
|
|
546
663
|
const error = `throw new Error(${toJsStringLiteral(message)})`;
|
|
@@ -557,4 +674,4 @@ function renderDevOnlyStub(module, message) {
|
|
|
557
674
|
*/
|
|
558
675
|
const MCP_SDK_SUBPATH_PREFIX = "@modelcontextprotocol/sdk/";
|
|
559
676
|
//#endregion
|
|
560
|
-
export { DATABASE_CONFIG_CANDIDATES, DATABASE_DIALECTS, DATABASE_FACTORIES, DEV_ONLY_MODULES, MCP_SDK_SUBPATH_PREFIX, SQL_CLIENT_MODULES, assertOutputDirOutsideRoot, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, unusedSqlClients };
|
|
677
|
+
export { DATABASE_CONFIG_CANDIDATES, DATABASE_DIALECTS, DATABASE_FACTORIES, DEV_ONLY_MODULES, DOCUMENT_ASSET_EXTENSIONS, DOCUMENT_ASSET_HEADERS, MCP_PLUGIN_PACKAGE, MCP_SDK_SUBPATH_PREFIX, MCP_TRANSPORT_SPECIFIER, SQL_CLIENT_MODULES, appUsesMcpPlugin, assertOutputDirOutsideRoot, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, unusedSqlClients };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@guren/server/internal/route-path";
|
|
@@ -1,142 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Zod 4 schema-reading primitives shared by `@guren/cli`'s TypeScript-type
|
|
4
|
-
* renderer (`src/schema-type-extractor.ts`) and the OpenAPI schema-object
|
|
5
|
-
* renderer (`@guren/openapi`).
|
|
6
|
-
*
|
|
7
|
-
* Internal by the rules in `contributing/api-stability.md`: reachable only
|
|
8
|
-
* through a deep import under `internal/`, never re-exported from
|
|
9
|
-
* `@guren/core`'s index.
|
|
10
|
-
*
|
|
11
|
-
* Zod 4 only. The zod 3 API (whether from the old `zod@3` package or the
|
|
12
|
-
* `zod/v3` subpath that zod 4 ships for migration) tags every node with
|
|
13
|
-
* `_def.typeName` and overloads `_def.type` to hold a nested schema — the
|
|
14
|
-
* ambiguity behind a bug this module's predecessors fixed twice. Rather than
|
|
15
|
-
* carrying both dialects forever, a v3 node is detected up front
|
|
16
|
-
* (`isZod3Schema`) and refused with `ZOD3_UNSUPPORTED_MESSAGE`; everything
|
|
17
|
-
* below it assumes the v4 layout, where `_def.type` is always the type name.
|
|
18
|
-
*
|
|
19
|
-
* What does NOT belong here: the two type switches that turn a node into an
|
|
20
|
-
* output (a TypeScript type string vs. an OpenAPI schema object). Their leaf
|
|
21
|
-
* vocabularies have legitimately diverged — the CLI renders `void`/`any`/
|
|
22
|
-
* `never`, which OpenAPI has no way to express — and that is a rendering
|
|
23
|
-
* decision, not schema-reading knowledge.
|
|
24
|
-
*
|
|
25
|
-
* Neither walker's `isOptional` belongs here either, but for a weaker reason
|
|
26
|
-
* than "they are both right": the CLI reads only the side of a `.pipe()` it
|
|
27
|
-
* renders, the OpenAPI walker requires both sides to permit omission, and
|
|
28
|
-
* *both* are approximations that a sufficiently odd pipeline can fool. Fixing
|
|
29
|
-
* them properly means simulating a parse, which is well beyond reading a
|
|
30
|
-
* `_def`. They stay with their callers until someone does that.
|
|
31
|
-
*/
|
|
32
|
-
interface ZodSchemaLike {
|
|
33
|
-
_def?: Record<string, unknown>;
|
|
34
|
-
/** zod 4's internal container; `values` is its own computed set of accepted literals. */
|
|
35
|
-
_zod?: {
|
|
36
|
-
values?: Set<unknown>;
|
|
37
|
-
};
|
|
38
|
-
type?: string;
|
|
39
|
-
shape?: Record<string, ZodSchemaLike>;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Which side of a schema is being read.
|
|
43
|
-
*
|
|
44
|
-
* - `output` — the parsed value, i.e. what a controller receives after
|
|
45
|
-
* validation, or what a response body looks like.
|
|
46
|
-
* - `input` — the value a client has to send over the wire. Coercing and
|
|
47
|
-
* piped schemas can differ here from their output side.
|
|
48
|
-
*/
|
|
49
|
-
type SchemaIo = 'input' | 'output';
|
|
50
|
-
/**
|
|
51
|
-
* Whether this node was authored with the zod 3 API. Only v3 sets
|
|
52
|
-
* `_def.typeName` (`"ZodString"`), so its presence is the discriminator —
|
|
53
|
-
* checked before any other read, because on a v3 node `_def.type` holds a
|
|
54
|
-
* nested *schema* and every v4-shaped read below would misfire on it.
|
|
55
|
-
*/
|
|
56
|
-
declare function isZod3Schema(schema: ZodSchemaLike): boolean;
|
|
57
|
-
/**
|
|
58
|
-
* The one refusal message, stated once so the CLI's console warning and the
|
|
59
|
-
* OpenAPI document's warnings array cannot drift apart.
|
|
60
|
-
*/
|
|
61
|
-
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'`).";
|
|
62
|
-
/** The node's type name: `_def.type` (`"string"`, `"object"`, …) or the schema's own `.type`. */
|
|
63
|
-
declare function getTypeName(schema: ZodSchemaLike): string | undefined;
|
|
64
|
-
/** `getTypeName` with `'unknown'` for a node that has no readable name. */
|
|
65
|
-
declare function typeOf(schema: ZodSchemaLike): string;
|
|
66
|
-
/**
|
|
67
|
-
* The schema at `def[key]`, if it actually holds one. The object check is
|
|
68
|
-
* load-bearing: `_def` is untyped data from someone else's package, and a key
|
|
69
|
-
* holding a string or function must read as absent, not as a schema. (The
|
|
70
|
-
* v3-era version of this helper took a key *list* and returned the first
|
|
71
|
-
* match; with one dialect there is no precedence left to encode.)
|
|
72
|
-
*/
|
|
73
|
-
declare function schemaAt(def: Record<string, unknown>, key: string): ZodSchemaLike | undefined;
|
|
74
|
-
/** The schema wrapped by a single-child wrapper (`.optional()`, `.readonly()`, `.catch()`, …) — always `_def.innerType` in zod 4. */
|
|
75
|
-
declare function innerSchema(def: Record<string, unknown>): ZodSchemaLike | undefined;
|
|
76
|
-
/** An array's element schema — `_def.element`, never `_def.type`, which holds the string `'array'`. */
|
|
77
|
-
declare function arrayElement(def: Record<string, unknown>): ZodSchemaLike | undefined;
|
|
78
|
-
/** A record's value schema — `_def.valueType`. */
|
|
79
|
-
declare function recordValueType(def: Record<string, unknown>): ZodSchemaLike | undefined;
|
|
80
|
-
/**
|
|
81
|
-
* Whether this node is a `.transform()`'s output half — a wrapped function
|
|
82
|
-
* with no type to read, as opposed to a schema that genuinely parses to
|
|
83
|
-
* `unknown`.
|
|
84
|
-
*/
|
|
85
|
-
declare function isTransform(schema: ZodSchemaLike): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* Both halves of a `.pipe()`. Zod 4 uses one `pipe` node for both `.pipe()`
|
|
88
|
-
* and `.transform()`: `_def.in` is what a caller sends, `_def.out` what a
|
|
89
|
-
* controller receives — except for a transform, whose out side is the
|
|
90
|
-
* transform function itself and so has no type to read. `to` is therefore
|
|
91
|
-
* absent for a transform, leaving `from` as the only readable answer.
|
|
92
|
-
*/
|
|
93
|
-
declare function pipeSides(def: Record<string, unknown>): {
|
|
94
|
-
from: ZodSchemaLike | undefined;
|
|
95
|
-
to: ZodSchemaLike | undefined;
|
|
96
|
-
};
|
|
97
|
-
/** The one side of a `.pipe()` that describes the `io` direction being rendered. */
|
|
98
|
-
declare function pipeSide(def: Record<string, unknown>, io: SchemaIo): ZodSchemaLike | undefined;
|
|
99
|
-
/** An object's property map — `_def.shape`, or the schema's own `.shape`. */
|
|
100
|
-
declare function objectShape(schema: ZodSchemaLike): Record<string, ZodSchemaLike> | undefined;
|
|
101
|
-
/**
|
|
102
|
-
* An enum's accepted values, read from zod's own computed set at
|
|
103
|
-
* `_zod.values` rather than re-derived from `_def.entries`. The distinction
|
|
104
|
-
* matters because `z.nativeEnum` produces the same node and a real TypeScript
|
|
105
|
-
* numeric enum's runtime object carries reverse mappings (`{ A: 0, '0': 'A' }`)
|
|
106
|
-
* — and any hand-rolled filter for those has a false positive: in
|
|
107
|
-
* `{ A: 'B', B: 1 }`, the key `A` *looks* like a reverse entry (`entries['B']`
|
|
108
|
-
* is a number) but zod accepts `'B'`. Reading zod's set makes what we document
|
|
109
|
-
* what zod parses, by construction. The `entries` fallback (values unfiltered)
|
|
110
|
-
* only runs if a future zod 4.x stops exposing the set.
|
|
111
|
-
*/
|
|
112
|
-
declare function enumValues(schema: ZodSchemaLike): Array<string | number>;
|
|
113
|
-
/** A literal's values — always the `_def.values` array in zod 4, which may hold more than one. */
|
|
114
|
-
declare function literalValues(def: Record<string, unknown>): unknown[];
|
|
115
|
-
/**
|
|
116
|
-
* Wrappers that neither add to a rendered type nor decide whether a field may
|
|
117
|
-
* be omitted — whatever they wrap answers both questions. (`lazy` is here for
|
|
118
|
-
* membership only: its child hides behind `_def.getter`, which no walker
|
|
119
|
-
* calls, so looking through it reads as "contents unavailable" rather than
|
|
120
|
-
* "unsupported type".)
|
|
121
|
-
*/
|
|
122
|
-
declare const TRANSPARENT_WRAPPERS: ReadonlySet<string>;
|
|
123
|
-
/**
|
|
124
|
-
* Wrappers that pass their type through but *do* decide presence: each makes a
|
|
125
|
-
* field omissible, or (in `nonoptional`'s case) re-requires one.
|
|
126
|
-
*/
|
|
127
|
-
declare const PRESENCE_WRAPPERS: ReadonlySet<string>;
|
|
128
|
-
/**
|
|
129
|
-
* Every type name that carries exactly one nested schema and no shape of its
|
|
130
|
-
* own — the union of the two sets above plus the two that render specially
|
|
131
|
-
* (`nullable` becomes a union with null; a pipe holds one schema per side).
|
|
132
|
-
*
|
|
133
|
-
* This is the vocabulary, not a policy: callers partition it however their
|
|
134
|
-
* rendering needs (the CLI splits transparent from presence-deciding because
|
|
135
|
-
* it walks types and presence separately; the OpenAPI walker looks through all
|
|
136
|
-
* of them uniformly). What none of them may do is disagree about *membership*
|
|
137
|
-
* — a name known to one walker and not the other silently changes an output,
|
|
138
|
-
* which is why the list lives here rather than once per package.
|
|
139
|
-
*/
|
|
140
|
-
declare const SINGLE_CHILD_WRAPPERS: ReadonlySet<string>;
|
|
141
|
-
//#endregion
|
|
142
|
-
export { PRESENCE_WRAPPERS, SINGLE_CHILD_WRAPPERS, SchemaIo, TRANSPARENT_WRAPPERS, ZOD3_UNSUPPORTED_MESSAGE, ZodSchemaLike, arrayElement, enumValues, getTypeName, innerSchema, isTransform, isZod3Schema, literalValues, objectShape, pipeSide, pipeSides, recordValueType, schemaAt, typeOf };
|
|
1
|
+
export * from "@guren/server/internal/zod-compat";
|
|
@@ -1,141 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Whether this node was authored with the zod 3 API. Only v3 sets
|
|
4
|
-
* `_def.typeName` (`"ZodString"`), so its presence is the discriminator —
|
|
5
|
-
* checked before any other read, because on a v3 node `_def.type` holds a
|
|
6
|
-
* nested *schema* and every v4-shaped read below would misfire on it.
|
|
7
|
-
*/
|
|
8
|
-
function isZod3Schema(schema) {
|
|
9
|
-
return typeof schema._def?.typeName === "string";
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* The one refusal message, stated once so the CLI's console warning and the
|
|
13
|
-
* OpenAPI document's warnings array cannot drift apart.
|
|
14
|
-
*/
|
|
15
|
-
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'`).";
|
|
16
|
-
/** The node's type name: `_def.type` (`"string"`, `"object"`, …) or the schema's own `.type`. */
|
|
17
|
-
function getTypeName(schema) {
|
|
18
|
-
const name = schema._def?.type ?? schema.type;
|
|
19
|
-
return typeof name === "string" ? name : void 0;
|
|
20
|
-
}
|
|
21
|
-
/** `getTypeName` with `'unknown'` for a node that has no readable name. */
|
|
22
|
-
function typeOf(schema) {
|
|
23
|
-
return getTypeName(schema) ?? "unknown";
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The schema at `def[key]`, if it actually holds one. The object check is
|
|
27
|
-
* load-bearing: `_def` is untyped data from someone else's package, and a key
|
|
28
|
-
* holding a string or function must read as absent, not as a schema. (The
|
|
29
|
-
* v3-era version of this helper took a key *list* and returned the first
|
|
30
|
-
* match; with one dialect there is no precedence left to encode.)
|
|
31
|
-
*/
|
|
32
|
-
function schemaAt(def, key) {
|
|
33
|
-
const candidate = def[key];
|
|
34
|
-
return candidate && typeof candidate === "object" ? candidate : void 0;
|
|
35
|
-
}
|
|
36
|
-
/** The schema wrapped by a single-child wrapper (`.optional()`, `.readonly()`, `.catch()`, …) — always `_def.innerType` in zod 4. */
|
|
37
|
-
function innerSchema(def) {
|
|
38
|
-
return schemaAt(def, "innerType");
|
|
39
|
-
}
|
|
40
|
-
/** An array's element schema — `_def.element`, never `_def.type`, which holds the string `'array'`. */
|
|
41
|
-
function arrayElement(def) {
|
|
42
|
-
return schemaAt(def, "element");
|
|
43
|
-
}
|
|
44
|
-
/** A record's value schema — `_def.valueType`. */
|
|
45
|
-
function recordValueType(def) {
|
|
46
|
-
return schemaAt(def, "valueType");
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Whether this node is a `.transform()`'s output half — a wrapped function
|
|
50
|
-
* with no type to read, as opposed to a schema that genuinely parses to
|
|
51
|
-
* `unknown`.
|
|
52
|
-
*/
|
|
53
|
-
function isTransform(schema) {
|
|
54
|
-
return typeOf(schema) === "transform";
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Both halves of a `.pipe()`. Zod 4 uses one `pipe` node for both `.pipe()`
|
|
58
|
-
* and `.transform()`: `_def.in` is what a caller sends, `_def.out` what a
|
|
59
|
-
* controller receives — except for a transform, whose out side is the
|
|
60
|
-
* transform function itself and so has no type to read. `to` is therefore
|
|
61
|
-
* absent for a transform, leaving `from` as the only readable answer.
|
|
62
|
-
*/
|
|
63
|
-
function pipeSides(def) {
|
|
64
|
-
const to = schemaAt(def, "out");
|
|
65
|
-
return {
|
|
66
|
-
from: schemaAt(def, "in"),
|
|
67
|
-
to: to && !isTransform(to) ? to : void 0
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/** The one side of a `.pipe()` that describes the `io` direction being rendered. */
|
|
71
|
-
function pipeSide(def, io) {
|
|
72
|
-
const { from, to } = pipeSides(def);
|
|
73
|
-
return io === "output" && to ? to : from;
|
|
74
|
-
}
|
|
75
|
-
/** An object's property map — `_def.shape`, or the schema's own `.shape`. */
|
|
76
|
-
function objectShape(schema) {
|
|
77
|
-
return (schema._def ?? {}).shape ?? schema.shape;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* An enum's accepted values, read from zod's own computed set at
|
|
81
|
-
* `_zod.values` rather than re-derived from `_def.entries`. The distinction
|
|
82
|
-
* matters because `z.nativeEnum` produces the same node and a real TypeScript
|
|
83
|
-
* numeric enum's runtime object carries reverse mappings (`{ A: 0, '0': 'A' }`)
|
|
84
|
-
* — and any hand-rolled filter for those has a false positive: in
|
|
85
|
-
* `{ A: 'B', B: 1 }`, the key `A` *looks* like a reverse entry (`entries['B']`
|
|
86
|
-
* is a number) but zod accepts `'B'`. Reading zod's set makes what we document
|
|
87
|
-
* what zod parses, by construction. The `entries` fallback (values unfiltered)
|
|
88
|
-
* only runs if a future zod 4.x stops exposing the set.
|
|
89
|
-
*/
|
|
90
|
-
function enumValues(schema) {
|
|
91
|
-
const values = schema._zod?.values;
|
|
92
|
-
if (values) return [...values].filter((value) => typeof value === "string" || typeof value === "number");
|
|
93
|
-
const entries = schema._def?.entries;
|
|
94
|
-
return entries ? Object.values(entries) : [];
|
|
95
|
-
}
|
|
96
|
-
/** A literal's values — always the `_def.values` array in zod 4, which may hold more than one. */
|
|
97
|
-
function literalValues(def) {
|
|
98
|
-
return Array.isArray(def.values) ? def.values : [];
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Wrappers that neither add to a rendered type nor decide whether a field may
|
|
102
|
-
* be omitted — whatever they wrap answers both questions. (`lazy` is here for
|
|
103
|
-
* membership only: its child hides behind `_def.getter`, which no walker
|
|
104
|
-
* calls, so looking through it reads as "contents unavailable" rather than
|
|
105
|
-
* "unsupported type".)
|
|
106
|
-
*/
|
|
107
|
-
const TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set([
|
|
108
|
-
"catch",
|
|
109
|
-
"readonly",
|
|
110
|
-
"lazy"
|
|
111
|
-
]);
|
|
112
|
-
/**
|
|
113
|
-
* Wrappers that pass their type through but *do* decide presence: each makes a
|
|
114
|
-
* field omissible, or (in `nonoptional`'s case) re-requires one.
|
|
115
|
-
*/
|
|
116
|
-
const PRESENCE_WRAPPERS = /* @__PURE__ */ new Set([
|
|
117
|
-
"optional",
|
|
118
|
-
"default",
|
|
119
|
-
"prefault",
|
|
120
|
-
"nonoptional"
|
|
121
|
-
]);
|
|
122
|
-
/**
|
|
123
|
-
* Every type name that carries exactly one nested schema and no shape of its
|
|
124
|
-
* own — the union of the two sets above plus the two that render specially
|
|
125
|
-
* (`nullable` becomes a union with null; a pipe holds one schema per side).
|
|
126
|
-
*
|
|
127
|
-
* This is the vocabulary, not a policy: callers partition it however their
|
|
128
|
-
* rendering needs (the CLI splits transparent from presence-deciding because
|
|
129
|
-
* it walks types and presence separately; the OpenAPI walker looks through all
|
|
130
|
-
* of them uniformly). What none of them may do is disagree about *membership*
|
|
131
|
-
* — a name known to one walker and not the other silently changes an output,
|
|
132
|
-
* which is why the list lives here rather than once per package.
|
|
133
|
-
*/
|
|
134
|
-
const SINGLE_CHILD_WRAPPERS = /* @__PURE__ */ new Set([
|
|
135
|
-
...TRANSPARENT_WRAPPERS,
|
|
136
|
-
...PRESENCE_WRAPPERS,
|
|
137
|
-
"nullable",
|
|
138
|
-
"pipe"
|
|
139
|
-
]);
|
|
140
|
-
//#endregion
|
|
141
|
-
export { PRESENCE_WRAPPERS, SINGLE_CHILD_WRAPPERS, TRANSPARENT_WRAPPERS, ZOD3_UNSUPPORTED_MESSAGE, arrayElement, enumValues, getTypeName, innerSchema, isTransform, isZod3Schema, literalValues, objectShape, pipeSide, pipeSides, recordValueType, schemaAt, typeOf };
|
|
1
|
+
export * from "@guren/server/internal/zod-compat";
|
|
2
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@guren/server/internal/zod-json-schema";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./src/bin.ts",
|
|
@@ -45,14 +45,26 @@
|
|
|
45
45
|
"types": "./dist/redis.d.ts",
|
|
46
46
|
"default": "./dist/redis.js"
|
|
47
47
|
},
|
|
48
|
+
"./agent": {
|
|
49
|
+
"types": "./dist/agent.d.ts",
|
|
50
|
+
"default": "./dist/agent.js"
|
|
51
|
+
},
|
|
48
52
|
"./internal/deploy-build": {
|
|
49
53
|
"types": "./dist/internal/deploy-build.d.ts",
|
|
50
54
|
"default": "./dist/internal/deploy-build.js"
|
|
51
55
|
},
|
|
56
|
+
"./internal/route-path": {
|
|
57
|
+
"types": "./dist/internal/route-path.d.ts",
|
|
58
|
+
"default": "./dist/internal/route-path.js"
|
|
59
|
+
},
|
|
52
60
|
"./internal/zod-compat": {
|
|
53
61
|
"types": "./dist/internal/zod-compat.d.ts",
|
|
54
62
|
"default": "./dist/internal/zod-compat.js"
|
|
55
63
|
},
|
|
64
|
+
"./internal/zod-json-schema": {
|
|
65
|
+
"types": "./dist/internal/zod-json-schema.d.ts",
|
|
66
|
+
"default": "./dist/internal/zod-json-schema.js"
|
|
67
|
+
},
|
|
56
68
|
"./jsx-runtime": {
|
|
57
69
|
"types": "./dist/jsx-runtime.d.ts",
|
|
58
70
|
"default": "./dist/jsx-runtime.js"
|
|
@@ -72,9 +84,9 @@
|
|
|
72
84
|
"typecheck": "tsc --noEmit"
|
|
73
85
|
},
|
|
74
86
|
"dependencies": {
|
|
75
|
-
"@guren/cli": "^2.
|
|
76
|
-
"@guren/orm": "^2.6.
|
|
77
|
-
"@guren/server": "^2.
|
|
87
|
+
"@guren/cli": "^2.14.0",
|
|
88
|
+
"@guren/orm": "^2.6.2",
|
|
89
|
+
"@guren/server": "^2.15.0"
|
|
78
90
|
},
|
|
79
91
|
"devDependencies": {
|
|
80
92
|
"@types/node": "^20.14.10",
|