@guren/core 1.17.0 → 1.19.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/index.d.ts +214 -10
- package/dist/index.js +131 -24
- package/dist/internal/deploy-build.d.ts +60 -16
- package/dist/internal/deploy-build.js +103 -31
- package/dist/redis.d.ts +2 -2
- package/dist/redis.js +2 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ApiToken, ApiTokenStore, Command, Controller, Job, OAuthStatePayload, OAuthStateStore, Router, SessionConfig, SessionData, SessionManager, SessionStore, StorageManager } from "@guren/server";
|
|
2
|
-
import { AccessorDefinitions, AccessorFn, AwsDataApiDatabase, AwsDataApiDatabaseOptions, AwsDataApiSeederContext, BelongsToManyRecord, BelongsToManyRelationResult, BelongsToRecord, BelongsToRelationResult, BelongsToRequiredRecord, CastType, D1DatabaseHandle, D1DatabaseOptions, DrizzleAdapter, EagerLoadConstraint, FindManyOptions, GroupCondition, HasManyRecord, HasManyRelationResult, HasManyThroughRecord, HasManyThroughRelationResult, HasOneRecord, HasOneRelationResult, HookCallback, HookName, InferModelInsert, InferModelRecord, MassAssignmentException, MigrationRunSummary, MigrationStatusEntry, Model, Model as Model$1, ModelHooks, ModelNotFoundException, ModelObserver, ModelObserverConstructor, ModelPaginationMeta, ModelQueryOptions, MorphManyRecord, MorphManyRelationResult, MorphToRecord, MorphToRelationResult, MutatorDefinitions, MutatorFn, MySqlDatabase, MySqlDatabaseOptions, MySqlSeederContext, ORMAdapter, ORMAdapterAdvanced, OrderByClause, OrderByInput, OrderDefinition, OrderDirection, PaginateOptions, PaginatedResult, PlainObject, PlainObject as PlainObject$1, PostgresDatabase, PostgresDatabaseOptions, PostgresSeederContext, QueryBuilder, QueryBuilderOptions, ScopeFunction, SeederContext, SeederHandler, SeederRunSummary, SimpleCondition, SoftDeletes, SoftDeletesStatic, SqliteDatabase, SqliteDatabaseOptions, SqliteSeederContext, TransactionHandle, TransactionModelScope, WhereClause, WhereCondition, WhereGroupCallback, WhereOperator, WithRelations, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from "@guren/orm";
|
|
1
|
+
import { ApiToken, ApiTokenStore, AppEnv, Command, ConfigDefinition, Container, Controller, Job, OAuthStatePayload, OAuthStateStore, QueueManager, Router, SessionConfig, SessionData, SessionManager, SessionStore, StorageManager } from "@guren/server";
|
|
2
|
+
import { AccessorDefinitions, AccessorFn, AggregateFunction, AvgValue, AwsDataApiDatabase, AwsDataApiDatabaseOptions, AwsDataApiSeederContext, BelongsToManyRecord, BelongsToManyRelationResult, BelongsToRecord, BelongsToRelationResult, BelongsToRequiredRecord, CastType, ConnectionContext, ConnectionContext as ConnectionContext$1, D1DatabaseHandle, D1DatabaseOptions, DrizzleAdapter, DrizzleSelectQuery, EagerLoadConstraint, FindManyOptions, GroupCondition, HasManyRecord, HasManyRelationResult, HasManyThroughRecord, HasManyThroughRelationResult, HasOneRecord, HasOneRelationResult, HookCallback, HookName, InferModelInsert, InferModelRecord, MassAssignmentException, MigrationRunSummary, MigrationStatusEntry, Model, Model as Model$1, ModelHooks, ModelNotFoundException, ModelObserver, ModelObserverConstructor, ModelPaginationMeta, ModelQueryOptions, MorphManyRecord, MorphManyRelationResult, MorphToRecord, MorphToRelationResult, MutatorDefinitions, MutatorFn, MySqlDatabase, MySqlDatabaseOptions, MySqlSeederContext, ORMAdapter, ORMAdapterAdvanced, OrderByClause, OrderByInput, OrderDefinition, OrderDirection, PaginateOptions, PaginatedResult, PlainObject, PlainObject as PlainObject$1, PostgresDatabase, PostgresDatabaseOptions, PostgresSeederContext, QueryBuilder, QueryBuilderOptions, ScopeFunction, SeederContext, SeederHandler, SeederRunSummary, SimpleCondition, SoftDeletes, SoftDeletesStatic, SqliteDatabase, SqliteDatabaseOptions, SqliteSeederContext, SumValue, TransactionHandle, TransactionModelScope, WhereClause, WhereCondition, WhereGroupCallback, WhereOperator, WithRelations, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from "@guren/orm";
|
|
3
3
|
export * from "@guren/server";
|
|
4
4
|
//#region src/api-token-store.d.ts
|
|
5
5
|
interface DatabaseApiTokenStoreOptions {
|
|
@@ -115,6 +115,47 @@ declare class SessionsPruneCommand extends Command {
|
|
|
115
115
|
handle(): Promise<void>;
|
|
116
116
|
}
|
|
117
117
|
//#endregion
|
|
118
|
+
//#region src/config.d.ts
|
|
119
|
+
/** What `defineDatabaseConfig()` needs from a dialect factory's result. */
|
|
120
|
+
interface ConfigurableDatabase {
|
|
121
|
+
configureOrm(context?: ConnectionContext$1): Promise<void>;
|
|
122
|
+
seedDatabase(): Promise<unknown>;
|
|
123
|
+
hasMigrations(): boolean;
|
|
124
|
+
}
|
|
125
|
+
interface DatabaseConfig {
|
|
126
|
+
readonly database: ConfigurableDatabase;
|
|
127
|
+
/** Run the seeders at boot when the migrations folder holds migrations. */
|
|
128
|
+
readonly seedOnBoot: boolean;
|
|
129
|
+
}
|
|
130
|
+
declare module '@guren/server' {
|
|
131
|
+
interface ConfigDefinitions {
|
|
132
|
+
session: SessionConfig;
|
|
133
|
+
database: DatabaseConfig;
|
|
134
|
+
}
|
|
135
|
+
interface ServiceBindings {
|
|
136
|
+
/** Bound by `defineDatabaseConfig()` (RFC 0027 §2). */
|
|
137
|
+
database: ConfigurableDatabase;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
declare module '@guren/orm' {
|
|
141
|
+
interface OrmConnectionEnv extends AppEnv {}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* `config/session.ts` (RFC 0027 §2). Written in core because the manager it
|
|
145
|
+
* binds knows the `database` driver, which `@guren/server` cannot resolve, and
|
|
146
|
+
* it binds the same `session` key an app's SessionProvider does (RFC 0020 §2).
|
|
147
|
+
*/
|
|
148
|
+
declare function defineSessionConfig(resolve: (env: AppEnv) => SessionConfig): ConfigDefinition<'session'>;
|
|
149
|
+
/**
|
|
150
|
+
* `config/database.ts` (RFC 0027 §2). Binds `database`, and at boot connects
|
|
151
|
+
* through `configureOrm({ env })`, so a connection resolver reads the validated
|
|
152
|
+
* env (a test's `envSource` included) rather than `process.env`. Without an env
|
|
153
|
+
* schema the context is omitted, so a resolver's own fallback runs.
|
|
154
|
+
*/
|
|
155
|
+
declare function defineDatabaseConfig(database: ConfigurableDatabase, options?: {
|
|
156
|
+
readonly seedOnBoot?: boolean;
|
|
157
|
+
}): ConfigDefinition<'database'>;
|
|
158
|
+
//#endregion
|
|
118
159
|
//#region src/oauth-state-store.d.ts
|
|
119
160
|
/**
|
|
120
161
|
* Database-backed OAuth state store built on the Guren ORM, for serverless, where
|
|
@@ -146,6 +187,20 @@ declare class DatabaseOAuthStateStore implements OAuthStateStore {
|
|
|
146
187
|
deleteExpired(now?: Date): Promise<void>;
|
|
147
188
|
}
|
|
148
189
|
//#endregion
|
|
190
|
+
//#region src/oauth-states-prune-command.d.ts
|
|
191
|
+
/**
|
|
192
|
+
* Console sweeper for the OAuth state store. `handleCallback()` already rejects
|
|
193
|
+
* an expired state, so this only keeps the table from growing; schedule it. A
|
|
194
|
+
* flow abandoned before the callback is never looked up again, so its row is
|
|
195
|
+
* only removed here. Stores that expire their own entries (Redis, memory) are
|
|
196
|
+
* skipped by the manager.
|
|
197
|
+
*/
|
|
198
|
+
declare class OAuthStatesPruneCommand extends Command {
|
|
199
|
+
static signature: string;
|
|
200
|
+
static description: string;
|
|
201
|
+
handle(): Promise<void>;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
149
204
|
//#region src/attachments/types.d.ts
|
|
150
205
|
/**
|
|
151
206
|
* Public types for the attachments layer (RFC 0013): attachments ride the ORM's
|
|
@@ -337,6 +392,12 @@ interface AttachOptions {
|
|
|
337
392
|
*/
|
|
338
393
|
queued?: boolean;
|
|
339
394
|
}
|
|
395
|
+
declare module '@guren/server' {
|
|
396
|
+
interface ServiceBindings {
|
|
397
|
+
/** Bound by `AttachmentEngine.bindTo()` (RFC 0023 §4); absent until then. The runtime spelling lives in `ATTACHMENTS_BINDING` — rename here and there together. */
|
|
398
|
+
attachments: AttachmentEngine;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
340
401
|
interface ConfigureAttachmentsOptions {
|
|
341
402
|
/**
|
|
342
403
|
* The app's Drizzle `attachments` table. Column property names must match the
|
|
@@ -345,8 +406,12 @@ interface ConfigureAttachmentsOptions {
|
|
|
345
406
|
* `variants` (JSON-capable), `placeholder`, `createdAt`, `updatedAt`.
|
|
346
407
|
*/
|
|
347
408
|
table: unknown;
|
|
348
|
-
/**
|
|
349
|
-
|
|
409
|
+
/**
|
|
410
|
+
* The app's StorageManager, resolved lazily: `(container) => container.make('storage')`.
|
|
411
|
+
* The container is the one `bindTo()` was given, else the default
|
|
412
|
+
* application's (RFC 0023 §4).
|
|
413
|
+
*/
|
|
414
|
+
storage: (container: Container) => StorageManager;
|
|
350
415
|
/** Default disk name for new attachments. */
|
|
351
416
|
disk: string;
|
|
352
417
|
/**
|
|
@@ -382,10 +447,9 @@ interface ConfigureAttachmentsOptions {
|
|
|
382
447
|
processor?: ImageProcessor | null;
|
|
383
448
|
/**
|
|
384
449
|
* The app's QueueManager, resolved lazily; enables `attach(..., { queued })`.
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
* falls back to the globally configured driver.
|
|
450
|
+
* Variant generation is dispatched through it, so the job lands on its driver
|
|
451
|
+
* whatever else the process has resolved. Without this option, the default
|
|
452
|
+
* application's queue carries the job.
|
|
389
453
|
*/
|
|
390
454
|
queue?: () => unknown;
|
|
391
455
|
/**
|
|
@@ -484,6 +548,138 @@ interface PruneReport {
|
|
|
484
548
|
reason: string;
|
|
485
549
|
}>;
|
|
486
550
|
}
|
|
551
|
+
/** What `configureAttachments({ queue })` must resolve to: the `QueueManager` surface the engine dispatches through. */
|
|
552
|
+
type QueueDispatcher = Pick<QueueManager, 'driver' | 'dispatch'>;
|
|
553
|
+
/** Installed by `configureAttachments()`; `queue` is the engine's own manager when it has one. */
|
|
554
|
+
type JobDispatcher = (payload: GenerateVariantsPayload, queue: QueueDispatcher | undefined) => Promise<unknown>;
|
|
555
|
+
declare class AttachmentEngine {
|
|
556
|
+
readonly model: typeof Model$1;
|
|
557
|
+
private readonly storageFactory;
|
|
558
|
+
private container?;
|
|
559
|
+
private readonly defaultDisk;
|
|
560
|
+
private readonly diskDelivery;
|
|
561
|
+
private readonly delivery;
|
|
562
|
+
private deliveryKeys;
|
|
563
|
+
private readonly maxPixels;
|
|
564
|
+
private readonly maxImageBytes;
|
|
565
|
+
private readonly processor;
|
|
566
|
+
private readonly urlExpiresIn;
|
|
567
|
+
private readonly queue?;
|
|
568
|
+
private dispatchJob;
|
|
569
|
+
constructor(options: ConfigureAttachmentsOptions);
|
|
570
|
+
/**
|
|
571
|
+
* Bind this engine on `container` as `attachments` *and* resolve its storage
|
|
572
|
+
* there. One call rather than two: an app that bound the instance alone would
|
|
573
|
+
* still read storage from whichever app is the default (RFC 0023 §4).
|
|
574
|
+
*/
|
|
575
|
+
bindTo(container: Container): void;
|
|
576
|
+
/** Wired by `configureAttachments()`, so this module never imports the job. */
|
|
577
|
+
setJobDispatcher(dispatch: JobDispatcher): void;
|
|
578
|
+
private storage;
|
|
579
|
+
attach(model: typeof Model$1, declaration: AttachmentsDeclaration, recordId: string | number, collection: string, source: AttachmentSource, options?: AttachOptions): Promise<AttachmentRecord>;
|
|
580
|
+
detach(model: typeof Model$1, declaration: AttachmentsDeclaration, recordId: string | number, collection: string, attachmentId?: string): Promise<void>;
|
|
581
|
+
withAttachments(model: typeof Model$1, declaration: AttachmentsDeclaration, records: readonly PlainObject$1[], names: readonly string[]): Promise<PlainObject$1[]>;
|
|
582
|
+
attachmentUrl(model: typeof Model$1, declaration: AttachmentsDeclaration, recordOrId: PlainObject$1 | string | number, collection: string, options?: AttachmentUrlOptions & {
|
|
583
|
+
variant?: string;
|
|
584
|
+
}): Promise<string | null>;
|
|
585
|
+
purgeAttachments(model: typeof Model$1, recordId: string | number): Promise<void>;
|
|
586
|
+
private specFor;
|
|
587
|
+
/**
|
|
588
|
+
* The three-gate image pipeline (RFC 0013 §6): encoded-byte cap, header
|
|
589
|
+
* dimensions, full decode. The first two plus the HEIC signature rejection are
|
|
590
|
+
* pure JS; only the full decode needs a processor.
|
|
591
|
+
*/
|
|
592
|
+
private inspectImage;
|
|
593
|
+
/**
|
|
594
|
+
* Seed one entry per *declared* variant, generating inline where a processor
|
|
595
|
+
* exists. Recording declared names is what lets `attachmentUrl()` tell "not
|
|
596
|
+
* yet generated" from "never declared" after a reload.
|
|
597
|
+
*/
|
|
598
|
+
private buildVariants;
|
|
599
|
+
/**
|
|
600
|
+
* Worker-side completion of a deferred attach: the skipped full decode, any
|
|
601
|
+
* opted-in HEIC conversion, the declared variants, and settling every
|
|
602
|
+
* `pending` record. A row or object purged meanwhile is nothing to do.
|
|
603
|
+
*/
|
|
604
|
+
generateVariants(payload: GenerateVariantsPayload): Promise<void>;
|
|
605
|
+
/** `GenerateVariantsJob.failed()`: settle `pending` records after the last retry. */
|
|
606
|
+
markDeferredFailed(attachmentId: string): Promise<void>;
|
|
607
|
+
/**
|
|
608
|
+
* Flip every `pending` variant to a terminal status. Works on a *fresh* read
|
|
609
|
+
* of the row: under at-least-once delivery a duplicate execution holding a
|
|
610
|
+
* stale copy would clobber variants a completed run already marked `ready`.
|
|
611
|
+
*/
|
|
612
|
+
private settleDeferred;
|
|
613
|
+
/**
|
|
614
|
+
* The manager `configureAttachments({ queue })` resolves, validated, or
|
|
615
|
+
* undefined without the option (the default application's queue then
|
|
616
|
+
* carries the job). Dispatching through the manager itself keeps the job on
|
|
617
|
+
* this engine's driver whatever another manager in the process resolved.
|
|
618
|
+
*/
|
|
619
|
+
private queueManager;
|
|
620
|
+
private dispatchGeneration;
|
|
621
|
+
/**
|
|
622
|
+
* The single indexed query behind `withAttachments()`. Empty `records` or
|
|
623
|
+
* `names` short-circuits: either would send an empty `IN ()` to the adapter.
|
|
624
|
+
*/
|
|
625
|
+
private rowsForPage;
|
|
626
|
+
private rowsFor;
|
|
627
|
+
/**
|
|
628
|
+
* Objects first, rows after (RFC 0013 §8): a crash between the two leaves a
|
|
629
|
+
* row pointing at nothing, which the next `url()` surfaces loudly. The reverse
|
|
630
|
+
* leaves orphaned objects only a bucket audit finds.
|
|
631
|
+
*/
|
|
632
|
+
private purgeRows;
|
|
633
|
+
/**
|
|
634
|
+
* The sweeper behind `attachments:prune` (RFC 0013 §8): no DB cascade exists
|
|
635
|
+
* for a polymorphic pair. Rows are removed only on *positive* evidence the
|
|
636
|
+
* record is gone; anything unverifiable is reported and left alone.
|
|
637
|
+
*/
|
|
638
|
+
pruneOrphans(options?: PruneOptions): Promise<PruneReport>;
|
|
639
|
+
/** With `--objects`: storage prefixes under `attachments/` that no surviving row references. */
|
|
640
|
+
private pruneOrphanObjects;
|
|
641
|
+
private visibilityOf;
|
|
642
|
+
private serveModeFor;
|
|
643
|
+
/** Whether URL minting for this disk goes through the delivery route (`serve: 'direct'` opts out). */
|
|
644
|
+
private routeEnabledFor;
|
|
645
|
+
/** The normalized delivery route config, for `resolveDeliveryRoute()`. */
|
|
646
|
+
get deliveryRoute(): {
|
|
647
|
+
prefix: string;
|
|
648
|
+
routeName: string;
|
|
649
|
+
} | null;
|
|
650
|
+
private deliveryKeyring;
|
|
651
|
+
/**
|
|
652
|
+
* The one URL policy (RFC 0015 §7): public disks stay on `disk.url()`; private
|
|
653
|
+
* disks get signed route URLs when `delivery` is configured and the disk did
|
|
654
|
+
* not opt out with `serve: 'direct'`, else v1's `temporaryUrl()`.
|
|
655
|
+
*/
|
|
656
|
+
private usesDeliveryRoute;
|
|
657
|
+
/**
|
|
658
|
+
* The one variant-resolution rule (RFC 0013 §7 / RFC 0015 §1), shared by URL
|
|
659
|
+
* minting, resource payloads, and the delivery route. A `ready` entry resolves
|
|
660
|
+
* to the variant's key and *format-derived* MIME type — variants are
|
|
661
|
+
* transcoded, and serving them under the original's type with `nosniff` would
|
|
662
|
+
* be self-sabotage. Anything else falls back to the original.
|
|
663
|
+
*/
|
|
664
|
+
private resolveVariantTarget;
|
|
665
|
+
private urlForRow;
|
|
666
|
+
/**
|
|
667
|
+
* Path-relative: the `Host` header never participates in URL construction (RFC
|
|
668
|
+
* 0015 T6). The variant rides as a signed query parameter resolved at *serve*
|
|
669
|
+
* time, so the same URL starts serving it once generation completes.
|
|
670
|
+
*/
|
|
671
|
+
private signDeliveryUrl;
|
|
672
|
+
/**
|
|
673
|
+
* Serve one delivery-route request (RFC 0015 §1). Every failure is the same
|
|
674
|
+
* 404: invalid signature, expired URL, and unknown id stay indistinguishable.
|
|
675
|
+
* Takes the raw `Request` so each parameter is re-read from the *same*
|
|
676
|
+
* `URLSearchParams` parse the signature canonicalizes with; a route decoder
|
|
677
|
+
* disagrees on malformed percent-encoding, a signed-URL rewrite primitive.
|
|
678
|
+
*/
|
|
679
|
+
handleDeliveryRequest(request: Request): Promise<Response>;
|
|
680
|
+
private toData;
|
|
681
|
+
private toRecord;
|
|
682
|
+
}
|
|
487
683
|
//#endregion
|
|
488
684
|
//#region src/attachments/Attachable.d.ts
|
|
489
685
|
/** A record id accepted by the attachment statics (int and uuid/text PKs). */
|
|
@@ -577,13 +773,19 @@ interface ConfiguredAttachments {
|
|
|
577
773
|
* attachment vocabulary.
|
|
578
774
|
*/
|
|
579
775
|
Attachment: typeof Model$1;
|
|
776
|
+
/**
|
|
777
|
+
* The engine this call built. Hand it to the app's container from a service
|
|
778
|
+
* provider (`engine.bindTo(this.container)`): this function runs at module
|
|
779
|
+
* scope, where no `Application` exists yet (RFC 0023 §4).
|
|
780
|
+
*/
|
|
781
|
+
engine: AttachmentEngine;
|
|
580
782
|
}
|
|
581
783
|
/**
|
|
582
784
|
* Wire the attachments layer, once per app: the app owns the table, the
|
|
583
785
|
* framework returns the model. `Attachable` statics resolve this lazily and
|
|
584
786
|
* throw a clear error when it was never called.
|
|
585
787
|
* @example
|
|
586
|
-
* export const { Attachment } = configureAttachments({ table: attachments, storage: () => container.make('storage'), disk: 'media' })
|
|
788
|
+
* export const { Attachment, engine } = configureAttachments({ table: attachments, storage: (container) => container.make('storage'), disk: 'media' })
|
|
587
789
|
*/
|
|
588
790
|
declare function configureAttachments(options: ConfigureAttachmentsOptions): ConfiguredAttachments;
|
|
589
791
|
//#endregion
|
|
@@ -632,9 +834,11 @@ declare class AttachmentsPruneCommand extends Command {
|
|
|
632
834
|
declare class GenerateVariantsJob extends Job<GenerateVariantsPayload> {
|
|
633
835
|
/** Pinned: queued messages must survive identifier mangling and renames. */
|
|
634
836
|
static jobName: string;
|
|
837
|
+
/** The app whose queue the worker drains, which a worker serving two is not free to guess. */
|
|
838
|
+
private engine;
|
|
635
839
|
handle(payload: GenerateVariantsPayload): Promise<void>;
|
|
636
840
|
/** After the last retry, stop `pending` variants looking in-flight forever. */
|
|
637
841
|
failed(payload: GenerateVariantsPayload, _error: Error): Promise<void>;
|
|
638
842
|
}
|
|
639
843
|
//#endregion
|
|
640
|
-
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, type DatabaseSessionDriverOptions, 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, SessionsPruneCommand, 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, createSessionManager, createSqliteDatabase, defineModel, defineSeeder, hasManyAttached, hasOneAttached, registerAttachmentRoutes, registerDatabaseSessionDriver, runSeeders };
|
|
844
|
+
export { ATTACHMENT_OBJECT_PREFIX, type AccessorDefinitions, type AccessorFn, type AggregateFunction, type AttachOptions, Attachable, type AttachableRecordId, type AttachableStatic, type AttachedCollectionOptions, type AttachmentCollectionSpec, type AttachmentData, AttachmentDeliveryController, type AttachmentEngine, type AttachmentRecord, type AttachmentSource, type AttachmentUrlOptions, type AttachmentVariantRecord, type AttachmentsDeclaration, AttachmentsPruneCommand, type AvgValue, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type ConfigureAttachmentsOptions, type ConfiguredAttachments, type ConnectionContext, type D1DatabaseHandle, type D1DatabaseOptions, DEFAULT_DELIVERY_ROUTE_NAME, DatabaseApiTokenStore, type DatabaseApiTokenStoreOptions, DatabaseOAuthStateStore, type DatabaseSessionDriverOptions, DatabaseSessionStore, type DatabaseSessionStoreOptions, type DeliveryOptions, type DeliveryServeMode, type DiskDeliveryConfig, DrizzleAdapter, type DrizzleSelectQuery, 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, OAuthStatesPruneCommand, 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, SessionsPruneCommand, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type SumValue, type TransactionHandle, type TransactionModelScope, type VariantSpec, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSessionManager, createSqliteDatabase, defineDatabaseConfig, defineModel, defineSeeder, defineSessionConfig, hasManyAttached, hasOneAttached, registerAttachmentRoutes, registerDatabaseSessionDriver, runSeeders };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, Controller, HttpException, Job, SessionManager, ValidationException, deriveAppKeyring, getAppKeyringFromEnv,
|
|
1
|
+
import { Command, Controller, HttpException, Job, SessionManager, ValidationException, ambientBinding, ambientContainer, defineConfig, deriveAppKeyring, getAppKeyringFromEnv, registerJob, resolveQueueDriver, signUrl, tryGetRequestContainer, verifySignedUrl } from "@guren/server";
|
|
2
2
|
import { DrizzleAdapter, MassAssignmentException, Model, Model as Model$1, ModelNotFoundException, QueryBuilder, SoftDeletes, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from "@guren/orm";
|
|
3
3
|
import { isExpired, toDate, toOptionalExpiry } from "@guren/server/support/expiry";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
@@ -188,6 +188,44 @@ var SessionsPruneCommand = class extends Command {
|
|
|
188
188
|
}
|
|
189
189
|
};
|
|
190
190
|
//#endregion
|
|
191
|
+
//#region src/config.ts
|
|
192
|
+
/**
|
|
193
|
+
* `config/session.ts` (RFC 0027 §2). Written in core because the manager it
|
|
194
|
+
* binds knows the `database` driver, which `@guren/server` cannot resolve, and
|
|
195
|
+
* it binds the same `session` key an app's SessionProvider does (RFC 0020 §2).
|
|
196
|
+
*/
|
|
197
|
+
function defineSessionConfig(resolve) {
|
|
198
|
+
return defineConfig({
|
|
199
|
+
key: "session",
|
|
200
|
+
resolve,
|
|
201
|
+
bind: (container, config) => {
|
|
202
|
+
container.singleton("session", () => createSessionManager(config));
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* `config/database.ts` (RFC 0027 §2). Binds `database`, and at boot connects
|
|
208
|
+
* through `configureOrm({ env })`, so a connection resolver reads the validated
|
|
209
|
+
* env (a test's `envSource` included) rather than `process.env`. Without an env
|
|
210
|
+
* schema the context is omitted, so a resolver's own fallback runs.
|
|
211
|
+
*/
|
|
212
|
+
function defineDatabaseConfig(database, options = {}) {
|
|
213
|
+
return defineConfig({
|
|
214
|
+
key: "database",
|
|
215
|
+
resolve: () => ({
|
|
216
|
+
database,
|
|
217
|
+
seedOnBoot: options.seedOnBoot ?? false
|
|
218
|
+
}),
|
|
219
|
+
bind: (container, config) => {
|
|
220
|
+
container.instance("database", config.database);
|
|
221
|
+
},
|
|
222
|
+
boot: async (container, config, env) => {
|
|
223
|
+
await config.database.configureOrm(container.has("env") ? { env } : void 0);
|
|
224
|
+
if (config.seedOnBoot && config.database.hasMigrations()) await config.database.seedDatabase();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
191
229
|
//#region src/oauth-state-store.ts
|
|
192
230
|
/**
|
|
193
231
|
* Database-backed OAuth state store built on the Guren ORM, for serverless, where
|
|
@@ -285,6 +323,25 @@ function deleteRemovedRow(result) {
|
|
|
285
323
|
return Boolean(result);
|
|
286
324
|
}
|
|
287
325
|
//#endregion
|
|
326
|
+
//#region src/oauth-states-prune-command.ts
|
|
327
|
+
/**
|
|
328
|
+
* Console sweeper for the OAuth state store. `handleCallback()` already rejects
|
|
329
|
+
* an expired state, so this only keeps the table from growing; schedule it. A
|
|
330
|
+
* flow abandoned before the callback is never looked up again, so its row is
|
|
331
|
+
* only removed here. Stores that expire their own entries (Redis, memory) are
|
|
332
|
+
* skipped by the manager.
|
|
333
|
+
*/
|
|
334
|
+
var OAuthStatesPruneCommand = class extends Command {
|
|
335
|
+
static signature = "oauth-states:prune";
|
|
336
|
+
static description = "Delete expired OAuth states from the configured state store";
|
|
337
|
+
async handle() {
|
|
338
|
+
const manager = this.resolveOptional("oauth");
|
|
339
|
+
if (!manager) throw new Error("oauth-states:prune requires an OAuth manager. Register a provider that binds createOAuthManager({ stateStore }) as `oauth` (run `bunx guren add oauth`).");
|
|
340
|
+
await manager.pruneExpiredStates();
|
|
341
|
+
this.info("Expired OAuth states removed.");
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
//#endregion
|
|
288
345
|
//#region src/attachments/bun-image-processor.ts
|
|
289
346
|
/**
|
|
290
347
|
* The default {@link ImageProcessor}, backed by `Bun.Image`. Resolved by feature
|
|
@@ -595,6 +652,14 @@ function ulid(now = Date.now()) {
|
|
|
595
652
|
* copy there would stop matching when this moves and report an exposed app safe.
|
|
596
653
|
*/
|
|
597
654
|
const ATTACHMENT_OBJECT_PREFIX = "attachments";
|
|
655
|
+
/**
|
|
656
|
+
* The key the engine binds under, and the one every consumer holding a
|
|
657
|
+
* container reads before falling back (RFC 0023 §4). Its own constant because
|
|
658
|
+
* the word means three unrelated things here (this key, the object-key prefix
|
|
659
|
+
* above, the route's URL prefix), and because `Container.instance()` is
|
|
660
|
+
* unkeyed: a typo would compile and read back as an absent binding.
|
|
661
|
+
*/
|
|
662
|
+
const ATTACHMENTS_BINDING = "attachments";
|
|
598
663
|
const DEFAULT_DELIVERY_ROUTE_NAME = "attachments.show";
|
|
599
664
|
/**
|
|
600
665
|
* The inner (presigned) TTL behind a redirect. Fixed, not derived from
|
|
@@ -650,9 +715,25 @@ const VARIANT_EXTENSION = {
|
|
|
650
715
|
webp: "webp",
|
|
651
716
|
avif: "avif"
|
|
652
717
|
};
|
|
718
|
+
/**
|
|
719
|
+
* What a storage factory receives when no Application exists at all: a
|
|
720
|
+
* factory that ignores its argument (`() => storage`) keeps working, and one
|
|
721
|
+
* that reads it gets the error `getContainer()` would have thrown.
|
|
722
|
+
*/
|
|
723
|
+
function unavailableContainer() {
|
|
724
|
+
const unavailable = () => {
|
|
725
|
+
throw new Error("Container not initialized. Construct the app with createApp(), or bind the engine on one from a provider (attachmentEngine.bindTo(this.container)).");
|
|
726
|
+
};
|
|
727
|
+
return {
|
|
728
|
+
make: unavailable,
|
|
729
|
+
makeOptional: unavailable,
|
|
730
|
+
has: unavailable
|
|
731
|
+
};
|
|
732
|
+
}
|
|
653
733
|
var AttachmentEngine = class {
|
|
654
734
|
model;
|
|
655
|
-
|
|
735
|
+
storageFactory;
|
|
736
|
+
container;
|
|
656
737
|
defaultDisk;
|
|
657
738
|
diskDelivery;
|
|
658
739
|
delivery;
|
|
@@ -669,7 +750,7 @@ var AttachmentEngine = class {
|
|
|
669
750
|
static table = table;
|
|
670
751
|
};
|
|
671
752
|
this.model.morphTo("attachable", "attachable");
|
|
672
|
-
this.
|
|
753
|
+
this.storageFactory = options.storage;
|
|
673
754
|
this.defaultDisk = options.disk;
|
|
674
755
|
this.diskDelivery = normalizeDiskDelivery(options.disks ?? {});
|
|
675
756
|
this.delivery = options.delivery ? {
|
|
@@ -682,15 +763,27 @@ var AttachmentEngine = class {
|
|
|
682
763
|
this.urlExpiresIn = options.urlExpiresIn ?? DEFAULT_URL_EXPIRES_IN;
|
|
683
764
|
this.queue = options.queue;
|
|
684
765
|
}
|
|
766
|
+
/**
|
|
767
|
+
* Bind this engine on `container` as `attachments` *and* resolve its storage
|
|
768
|
+
* there. One call rather than two: an app that bound the instance alone would
|
|
769
|
+
* still read storage from whichever app is the default (RFC 0023 §4).
|
|
770
|
+
*/
|
|
771
|
+
bindTo(container) {
|
|
772
|
+
this.container = container;
|
|
773
|
+
container.instance(ATTACHMENTS_BINDING, this);
|
|
774
|
+
}
|
|
685
775
|
/** Wired by `configureAttachments()`, so this module never imports the job. */
|
|
686
776
|
setJobDispatcher(dispatch) {
|
|
687
777
|
this.dispatchJob = dispatch;
|
|
688
778
|
}
|
|
779
|
+
storage() {
|
|
780
|
+
return this.storageFactory(this.container ?? ambientContainer() ?? unavailableContainer());
|
|
781
|
+
}
|
|
689
782
|
async attach(model, declaration, recordId, collection, source, options = {}) {
|
|
690
783
|
const spec = this.specFor(model, declaration, collection);
|
|
691
784
|
const normalized = await normalizeSource(source, options.name);
|
|
692
785
|
const queued = options.queued === true;
|
|
693
|
-
if (queued) this.
|
|
786
|
+
if (queued) this.queueManager();
|
|
694
787
|
const inspection = await this.inspectImage(spec, collection, normalized, queued);
|
|
695
788
|
const id = ulid();
|
|
696
789
|
const name = inspection.name;
|
|
@@ -1024,22 +1117,23 @@ var AttachmentEngine = class {
|
|
|
1024
1117
|
await this.model.forceUpdate({ id: row.id }, updates);
|
|
1025
1118
|
}
|
|
1026
1119
|
/**
|
|
1027
|
-
* The
|
|
1028
|
-
*
|
|
1120
|
+
* The manager `configureAttachments({ queue })` resolves, validated, or
|
|
1121
|
+
* undefined without the option (the default application's queue then
|
|
1122
|
+
* carries the job). Dispatching through the manager itself keeps the job on
|
|
1123
|
+
* this engine's driver whatever another manager in the process resolved.
|
|
1029
1124
|
*/
|
|
1030
|
-
|
|
1125
|
+
queueManager() {
|
|
1031
1126
|
if (!this.dispatchJob) throw new Error("Attachments queue dispatch is not wired. Call configureAttachments() before attaching.");
|
|
1032
1127
|
if (this.queue) {
|
|
1033
1128
|
const manager = this.queue();
|
|
1034
|
-
if (typeof manager?.driver !== "function") throw new Error("configureAttachments({ queue }) must resolve to a QueueManager (an object with
|
|
1035
|
-
|
|
1036
|
-
return;
|
|
1129
|
+
if (typeof manager?.driver !== "function" || typeof manager.dispatch !== "function") throw new Error("configureAttachments({ queue }) must resolve to a QueueManager (an object with driver() and dispatch() methods).");
|
|
1130
|
+
return manager;
|
|
1037
1131
|
}
|
|
1038
|
-
if (!
|
|
1132
|
+
if (!resolveQueueDriver()) throw new Error("attach() with queued: true requires a queue. Pass configureAttachments({ queue: () => queueManager }) or boot the app's queue before attaching.");
|
|
1039
1133
|
}
|
|
1040
1134
|
async dispatchGeneration(payload) {
|
|
1041
|
-
this.
|
|
1042
|
-
await this.dispatchJob(payload);
|
|
1135
|
+
const queue = this.queueManager();
|
|
1136
|
+
await this.dispatchJob(payload, queue);
|
|
1043
1137
|
}
|
|
1044
1138
|
/**
|
|
1045
1139
|
* The single indexed query behind `withAttachments()`. Empty `records` or
|
|
@@ -1369,7 +1463,12 @@ var AttachmentEngine = class {
|
|
|
1369
1463
|
}
|
|
1370
1464
|
};
|
|
1371
1465
|
let activeEngine = null;
|
|
1372
|
-
/**
|
|
1466
|
+
/**
|
|
1467
|
+
* Install the engine `configureAttachments()` built. Last call wins; `null`
|
|
1468
|
+
* unconfigures (tests). Neither this nor its getter is exported from
|
|
1469
|
+
* `@guren/core`, so RFC 0023's deprecation window does not reach them: they go
|
|
1470
|
+
* with the slot in Part 3.
|
|
1471
|
+
*/
|
|
1373
1472
|
function setActiveAttachmentEngine(engine) {
|
|
1374
1473
|
activeEngine = engine;
|
|
1375
1474
|
}
|
|
@@ -1385,8 +1484,9 @@ function resolveDeliveryRoute() {
|
|
|
1385
1484
|
};
|
|
1386
1485
|
}
|
|
1387
1486
|
function resolveAttachmentEngine(caller) {
|
|
1388
|
-
|
|
1389
|
-
|
|
1487
|
+
const engine = ambientBinding("attachments") ?? activeEngine;
|
|
1488
|
+
if (!engine) throw new Error(`${caller} requires attachments to be configured. Call configureAttachments({ table, storage, disk }) once at boot (e.g. in config/attachments.ts) before using the attachment statics.`);
|
|
1489
|
+
return engine;
|
|
1390
1490
|
}
|
|
1391
1491
|
async function normalizeSource(source, nameOverride) {
|
|
1392
1492
|
if (source instanceof Uint8Array) return {
|
|
@@ -1563,13 +1663,17 @@ function Attachable(Base, declaration) {
|
|
|
1563
1663
|
var GenerateVariantsJob = class extends Job {
|
|
1564
1664
|
/** Pinned: queued messages must survive identifier mangling and renames. */
|
|
1565
1665
|
static jobName = "GenerateVariantsJob";
|
|
1666
|
+
/** The app whose queue the worker drains, which a worker serving two is not free to guess. */
|
|
1667
|
+
engine() {
|
|
1668
|
+
return this.makeOptional("attachments") ?? resolveAttachmentEngine("GenerateVariantsJob");
|
|
1669
|
+
}
|
|
1566
1670
|
async handle(payload) {
|
|
1567
|
-
await
|
|
1671
|
+
await this.engine().generateVariants(payload);
|
|
1568
1672
|
}
|
|
1569
1673
|
/** After the last retry, stop `pending` variants looking in-flight forever. */
|
|
1570
1674
|
async failed(payload, _error) {
|
|
1571
1675
|
try {
|
|
1572
|
-
await
|
|
1676
|
+
await this.engine().markDeferredFailed(payload.attachmentId);
|
|
1573
1677
|
} catch {}
|
|
1574
1678
|
}
|
|
1575
1679
|
};
|
|
@@ -1580,14 +1684,17 @@ var GenerateVariantsJob = class extends Job {
|
|
|
1580
1684
|
* framework returns the model. `Attachable` statics resolve this lazily and
|
|
1581
1685
|
* throw a clear error when it was never called.
|
|
1582
1686
|
* @example
|
|
1583
|
-
* export const { Attachment } = configureAttachments({ table: attachments, storage: () => container.make('storage'), disk: 'media' })
|
|
1687
|
+
* export const { Attachment, engine } = configureAttachments({ table: attachments, storage: (container) => container.make('storage'), disk: 'media' })
|
|
1584
1688
|
*/
|
|
1585
1689
|
function configureAttachments(options) {
|
|
1586
1690
|
const engine = new AttachmentEngine(options);
|
|
1587
|
-
engine.setJobDispatcher((payload) => GenerateVariantsJob.dispatch(payload));
|
|
1691
|
+
engine.setJobDispatcher((payload, queue) => queue ? queue.dispatch(GenerateVariantsJob, payload) : GenerateVariantsJob.dispatch(payload));
|
|
1588
1692
|
registerJob(GenerateVariantsJob);
|
|
1589
1693
|
setActiveAttachmentEngine(engine);
|
|
1590
|
-
return {
|
|
1694
|
+
return {
|
|
1695
|
+
Attachment: engine.model,
|
|
1696
|
+
engine
|
|
1697
|
+
};
|
|
1591
1698
|
}
|
|
1592
1699
|
//#endregion
|
|
1593
1700
|
//#region src/attachments/delivery.ts
|
|
@@ -1600,7 +1707,7 @@ function configureAttachments(options) {
|
|
|
1600
1707
|
*/
|
|
1601
1708
|
var AttachmentDeliveryController = class extends Controller {
|
|
1602
1709
|
async show() {
|
|
1603
|
-
return resolveAttachmentEngine("The attachments delivery route").handleDeliveryRequest(this.ctx.req.raw);
|
|
1710
|
+
return (tryGetRequestContainer(this.ctx)?.makeOptional("attachments") ?? resolveAttachmentEngine("The attachments delivery route")).handleDeliveryRequest(this.ctx.req.raw);
|
|
1604
1711
|
}
|
|
1605
1712
|
};
|
|
1606
1713
|
/**
|
|
@@ -1627,7 +1734,7 @@ var AttachmentsPruneCommand = class extends Command {
|
|
|
1627
1734
|
static signature = "attachments:prune {--objects : Also delete attachments/ storage prefixes that no row references} {--dry-run : Report what would be removed without deleting}";
|
|
1628
1735
|
static description = "Remove attachment rows whose owning record no longer exists";
|
|
1629
1736
|
async handle() {
|
|
1630
|
-
const engine = resolveAttachmentEngine("attachments:prune");
|
|
1737
|
+
const engine = this.resolveOptional("attachments") ?? resolveAttachmentEngine("attachments:prune");
|
|
1631
1738
|
const dryRun = this.hasOption("dry-run");
|
|
1632
1739
|
const objects = this.hasOption("objects");
|
|
1633
1740
|
const report = await engine.pruneOrphans({
|
|
@@ -1679,4 +1786,4 @@ function hasManyAttached(options = {}) {
|
|
|
1679
1786
|
return buildSpec("many", options);
|
|
1680
1787
|
}
|
|
1681
1788
|
//#endregion
|
|
1682
|
-
export { ATTACHMENT_OBJECT_PREFIX, Attachable, AttachmentDeliveryController, AttachmentsPruneCommand, DEFAULT_DELIVERY_ROUTE_NAME, DatabaseApiTokenStore, DatabaseOAuthStateStore, DatabaseSessionStore, DrizzleAdapter, GenerateVariantsJob, MassAssignmentException, Model, ModelNotFoundException, QueryBuilder, SessionsPruneCommand, SoftDeletes, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSessionManager, createSqliteDatabase, defineModel, defineSeeder, hasManyAttached, hasOneAttached, registerAttachmentRoutes, registerDatabaseSessionDriver, runSeeders };
|
|
1789
|
+
export { ATTACHMENT_OBJECT_PREFIX, Attachable, AttachmentDeliveryController, AttachmentsPruneCommand, DEFAULT_DELIVERY_ROUTE_NAME, DatabaseApiTokenStore, DatabaseOAuthStateStore, DatabaseSessionStore, DrizzleAdapter, GenerateVariantsJob, MassAssignmentException, Model, ModelNotFoundException, OAuthStatesPruneCommand, QueryBuilder, SessionsPruneCommand, SoftDeletes, configureAttachments, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSessionManager, createSqliteDatabase, defineDatabaseConfig, defineModel, defineSeeder, defineSessionConfig, hasManyAttached, hasOneAttached, registerAttachmentRoutes, registerDatabaseSessionDriver, runSeeders };
|
|
@@ -45,14 +45,22 @@ declare function resetOutputDir(out: string, root: string, label: string): void;
|
|
|
45
45
|
* @param label Platform name for the error message, e.g. `'Lambda build'`.
|
|
46
46
|
*/
|
|
47
47
|
declare function importSpecifier(fromDir: string, target: string, label: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* The URL prefix built client assets are addressed by: the Vite `base` the Guren
|
|
50
|
+
* plugin derives from `outDir: 'public/assets'`, which its modulepreload helper
|
|
51
|
+
* prefixes. Must equal `PUBLIC_ASSETS_URL_PREFIX` in @guren/server's
|
|
52
|
+
* http/vite-manifest.ts; an entry under another prefix loads every lazy chunk
|
|
53
|
+
* twice, once per URL. `deploy-build.test.ts` pins it against the Vite plugin.
|
|
54
|
+
*/
|
|
55
|
+
declare const CLIENT_ASSETS_URL_PREFIX = "/public/assets/";
|
|
48
56
|
interface ClientAssetEnv {
|
|
49
57
|
entry?: string;
|
|
50
58
|
styles?: string;
|
|
51
59
|
}
|
|
52
60
|
/**
|
|
53
|
-
* Locate the built client entry and its CSS in the Vite client manifest, as
|
|
54
|
-
*
|
|
55
|
-
* a custom `publicDir` is honoured.
|
|
61
|
+
* Locate the built client entry and its CSS in the Vite client manifest, as
|
|
62
|
+
* `CLIENT_ASSETS_URL_PREFIX` URLs for the Inertia head. Takes the public directory
|
|
63
|
+
* so a custom `publicDir` is honoured.
|
|
56
64
|
* @param label Platform name for the warning message, e.g. `'Lambda build'`.
|
|
57
65
|
*/
|
|
58
66
|
declare function resolveClientAssetEnv(publicDir: string, clientEntryKey: string, label: string): ClientAssetEnv;
|
|
@@ -64,6 +72,22 @@ declare function resolveClientAssetEnv(publicDir: string, clientEntryKey: string
|
|
|
64
72
|
* size and Workers caps bundles); a parseable non-manifest is rejected here.
|
|
65
73
|
*/
|
|
66
74
|
declare function clientManifestJson(publicDir: string): string | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Every `lang/<locale>/<namespace>.json` as `{ locale: { namespace: messages } }`
|
|
77
|
+
* JSON, for runtime injection (`GUREN_TRANSLATIONS`): no deploy target ships
|
|
78
|
+
* `lang/`. Same walk and parse tolerance as `JsonLoader` in @guren/server and
|
|
79
|
+
* `readTranslationCatalogs` in @guren/cli. Undefined when nothing is readable.
|
|
80
|
+
* @param label Platform name for the warning message, e.g. `'Lambda build'`.
|
|
81
|
+
*/
|
|
82
|
+
declare function translationCatalogJson(root: string, label: string): string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* What a deploy build bakes into the bundle, keyed by the `process.env` name
|
|
85
|
+
* @guren/server reads: the client manifest for viteAsset() and the lang/ catalogs
|
|
86
|
+
* for createApp({ i18n }). No target ships those files, and platform environment
|
|
87
|
+
* configuration is size-capped (Lambda: 4KB total), so neither goes there.
|
|
88
|
+
* @param label Platform name for warning messages, e.g. `'Lambda build'`.
|
|
89
|
+
*/
|
|
90
|
+
declare function bundledRuntimeEnv(root: string, publicDir: string, label: string): Record<string, string>;
|
|
67
91
|
/**
|
|
68
92
|
* Absolute path of the built SSR entry chunk, or undefined without an SSR build.
|
|
69
93
|
* Whether the chunk exports a renderer is the caller's check: platforms disagree
|
|
@@ -91,10 +115,11 @@ declare function ssrRuntimePaths(ssrDir: string, ssrFile: string, prefix: string
|
|
|
91
115
|
*/
|
|
92
116
|
declare function removeShadowingIndex(assetsOut: string): void;
|
|
93
117
|
/**
|
|
94
|
-
* Copy `public/` into a platform's static staging directory
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* `
|
|
118
|
+
* Copy `public/` into a platform's static staging directory, with the built assets
|
|
119
|
+
* only under `CLIENT_ASSETS_URL_PREFIX`, the one prefix the HTML and the chunks
|
|
120
|
+
* address: a second copy at `assets/` would answer, and so hide, a URL that drifted
|
|
121
|
+
* off it. Vite empties `public/assets/` on every build, so it holds nothing else.
|
|
122
|
+
* Also applies `removeShadowingIndex`.
|
|
98
123
|
*/
|
|
99
124
|
declare function stageStaticAssets(publicDir: string, assetsOut: string): void;
|
|
100
125
|
/**
|
|
@@ -121,6 +146,14 @@ interface DevOnlyModule {
|
|
|
121
146
|
* bundle fails with "no matching export". Empty means namespace access only.
|
|
122
147
|
*/
|
|
123
148
|
readonly exportNames: readonly string[];
|
|
149
|
+
/**
|
|
150
|
+
* The package source that reaches this module, repo-relative. An entry is here
|
|
151
|
+
* because one package imports it, so the module-graph check searches that package
|
|
152
|
+
* alone: a stale entry cannot be kept alive by an unrelated package's import.
|
|
153
|
+
* `null`: no package imports it any more, and it stays only so the stub file a
|
|
154
|
+
* committed `wrangler.jsonc` aliases keeps being written (RFC 0028 §4).
|
|
155
|
+
*/
|
|
156
|
+
readonly importedBy: string | null;
|
|
124
157
|
}
|
|
125
158
|
/**
|
|
126
159
|
* Dev-only modules in the graph of any app importing `@guren/core`, listed here
|
|
@@ -133,28 +166,34 @@ declare const DEV_ONLY_MODULES: readonly [{
|
|
|
133
166
|
readonly specifier: 'bun:sqlite';
|
|
134
167
|
readonly kind: 'sqlite';
|
|
135
168
|
readonly exportNames: readonly ["Database"];
|
|
169
|
+
readonly importedBy: 'packages/orm/src';
|
|
136
170
|
}, {
|
|
137
171
|
readonly specifier: 'vite';
|
|
138
172
|
readonly kind: 'vite';
|
|
139
173
|
readonly exportNames: readonly ["createServer"];
|
|
174
|
+
readonly importedBy: 'packages/server/src';
|
|
140
175
|
}, {
|
|
141
176
|
readonly specifier: '@guren/cli';
|
|
142
177
|
readonly kind: 'mcp';
|
|
143
178
|
readonly exportNames: readonly [];
|
|
179
|
+
readonly importedBy: 'packages/server/src';
|
|
144
180
|
}, {
|
|
145
181
|
readonly specifier: '@modelcontextprotocol/sdk/server/mcp.js';
|
|
146
182
|
readonly kind: 'mcp';
|
|
147
183
|
readonly exportNames: readonly ["McpServer", "ResourceTemplate"];
|
|
184
|
+
readonly importedBy: 'packages/server/src';
|
|
148
185
|
}, {
|
|
149
186
|
readonly specifier: '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
|
|
150
187
|
readonly kind: 'mcp';
|
|
151
188
|
readonly exportNames: readonly ["WebStandardStreamableHTTPServerTransport"];
|
|
189
|
+
readonly importedBy: null;
|
|
152
190
|
}];
|
|
153
191
|
/** One entry of `DEV_ONLY_MODULES`, with its `kind` still narrowed. */
|
|
154
192
|
type DevOnlyModuleEntry = (typeof DEV_ONLY_MODULES)[number];
|
|
155
193
|
/**
|
|
156
|
-
* The
|
|
157
|
-
*
|
|
194
|
+
* The v1 transport `@guren/plugin-mcp` imported before SDK v2 (RFC 0016 §7): the
|
|
195
|
+
* one `DEV_ONLY_MODULES` entry whose stubbing is conditional. Nothing imports it
|
|
196
|
+
* now, so the condition changes no bundle; it goes in RFC 0028's removal PR.
|
|
158
197
|
*/
|
|
159
198
|
declare const MCP_TRANSPORT_SPECIFIER = "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
160
199
|
/** The package an app declares to opt into the App MCP endpoint. */
|
|
@@ -169,9 +208,9 @@ declare const MCP_PLUGIN_PACKAGE = "@guren/plugin-mcp";
|
|
|
169
208
|
declare function appUsesMcpPlugin(root: string): boolean;
|
|
170
209
|
/**
|
|
171
210
|
* The dev-only modules that must stay stubbed for this app: `DEV_ONLY_MODULES`
|
|
172
|
-
* minus the transport entry when the app declared `@guren/plugin-mcp` (
|
|
173
|
-
*
|
|
174
|
-
*
|
|
211
|
+
* minus the v1 transport entry when the app declared `@guren/plugin-mcp` (RFC 0016
|
|
212
|
+
* Phase 4a). Since the plugin moved to SDK v2 that entry has no importer, so the
|
|
213
|
+
* split changes no bundle (RFC 0028 §4). `server/mcp.js` stays stubbed: the Dev MCP. Each entry keeps
|
|
175
214
|
* its narrow `kind` so platform `Record<kind, message>` tables stay indexable.
|
|
176
215
|
*/
|
|
177
216
|
declare function stubbableDevOnlyModules(options: {
|
|
@@ -208,21 +247,25 @@ declare const SQL_CLIENT_MODULES: readonly [{
|
|
|
208
247
|
readonly kind: 'sql-driver';
|
|
209
248
|
readonly dialect: 'postgres';
|
|
210
249
|
readonly exportNames: readonly [];
|
|
250
|
+
readonly importedBy: 'packages/orm/src';
|
|
211
251
|
}, {
|
|
212
252
|
readonly specifier: 'mysql2';
|
|
213
253
|
readonly kind: 'sql-driver';
|
|
214
254
|
readonly dialect: 'mysql';
|
|
215
255
|
readonly exportNames: readonly [];
|
|
256
|
+
readonly importedBy: 'packages/orm/src';
|
|
216
257
|
}, {
|
|
217
258
|
readonly specifier: 'mysql2/promise';
|
|
218
259
|
readonly kind: 'sql-driver';
|
|
219
260
|
readonly dialect: 'mysql';
|
|
220
261
|
readonly exportNames: readonly ["createPool"];
|
|
262
|
+
readonly importedBy: 'packages/orm/src';
|
|
221
263
|
}, {
|
|
222
264
|
readonly specifier: '@aws-sdk/client-rds-data';
|
|
223
265
|
readonly kind: 'sql-driver';
|
|
224
266
|
readonly dialect: 'aws-data-api';
|
|
225
267
|
readonly exportNames: readonly ["RDSDataClient", "BeginTransactionCommand", "CommitTransactionCommand", "ExecuteStatementCommand", "RollbackTransactionCommand"];
|
|
268
|
+
readonly importedBy: 'packages/orm/src';
|
|
226
269
|
}];
|
|
227
270
|
type SqlClientSpecifier = (typeof SQL_CLIENT_MODULES)[number]['specifier'];
|
|
228
271
|
/**
|
|
@@ -284,10 +327,11 @@ type DevOnlySpecifier = (typeof DEV_ONLY_MODULES)[number]['specifier'];
|
|
|
284
327
|
*/
|
|
285
328
|
declare function renderDevOnlyStub(module: DevOnlyModule, message: string): string;
|
|
286
329
|
/**
|
|
287
|
-
* The MCP SDK is reached only through subpaths, which a package-name alias does
|
|
288
|
-
* cover (hence each one in `DEV_ONLY_MODULES`). A platform whose aliasing supports
|
|
289
|
-
* prefixes
|
|
330
|
+
* The v1 MCP SDK is reached only through subpaths, which a package-name alias does
|
|
331
|
+
* not cover (hence each one in `DEV_ONLY_MODULES`). A platform whose aliasing supports
|
|
332
|
+
* prefixes routes unlisted subpaths under this prefix to a stub too. SDK v2 lives
|
|
333
|
+
* under other package names, so `@guren/plugin-mcp`'s import is never matched.
|
|
290
334
|
*/
|
|
291
335
|
declare const MCP_SDK_SUBPATH_PREFIX = "@modelcontextprotocol/sdk/";
|
|
292
336
|
//#endregion
|
|
293
|
-
export { AGENTS_CONFIG_FILE, 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, removeShadowingIndex, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, unusedSqlClients };
|
|
337
|
+
export { AGENTS_CONFIG_FILE, CLIENT_ASSETS_URL_PREFIX, 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, bundledRuntimeEnv, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, removeShadowingIndex, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, translationCatalogJson, unusedSqlClients };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
1
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
//#region src/internal/deploy-build.ts
|
|
5
5
|
/**
|
|
@@ -111,9 +111,17 @@ function importSpecifier(fromDir, target, label) {
|
|
|
111
111
|
return specifier.startsWith(".") ? specifier : `./${specifier}`;
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
114
|
+
* The URL prefix built client assets are addressed by: the Vite `base` the Guren
|
|
115
|
+
* plugin derives from `outDir: 'public/assets'`, which its modulepreload helper
|
|
116
|
+
* prefixes. Must equal `PUBLIC_ASSETS_URL_PREFIX` in @guren/server's
|
|
117
|
+
* http/vite-manifest.ts; an entry under another prefix loads every lazy chunk
|
|
118
|
+
* twice, once per URL. `deploy-build.test.ts` pins it against the Vite plugin.
|
|
119
|
+
*/
|
|
120
|
+
const CLIENT_ASSETS_URL_PREFIX = "/public/assets/";
|
|
121
|
+
/**
|
|
122
|
+
* Locate the built client entry and its CSS in the Vite client manifest, as
|
|
123
|
+
* `CLIENT_ASSETS_URL_PREFIX` URLs for the Inertia head. Takes the public directory
|
|
124
|
+
* so a custom `publicDir` is honoured.
|
|
117
125
|
* @param label Platform name for the warning message, e.g. `'Lambda build'`.
|
|
118
126
|
*/
|
|
119
127
|
function resolveClientAssetEnv(publicDir, clientEntryKey, label) {
|
|
@@ -123,8 +131,8 @@ function resolveClientAssetEnv(publicDir, clientEntryKey, label) {
|
|
|
123
131
|
return {};
|
|
124
132
|
}
|
|
125
133
|
return {
|
|
126
|
-
entry:
|
|
127
|
-
styles: entry.css?.length ? entry.css.map((file) =>
|
|
134
|
+
entry: `${CLIENT_ASSETS_URL_PREFIX}${entry.file}`,
|
|
135
|
+
styles: entry.css?.length ? entry.css.map((file) => `${CLIENT_ASSETS_URL_PREFIX}${file}`).join(",") : void 0
|
|
128
136
|
};
|
|
129
137
|
}
|
|
130
138
|
/**
|
|
@@ -152,6 +160,55 @@ function clientManifestJson(publicDir) {
|
|
|
152
160
|
}
|
|
153
161
|
return JSON.stringify(trimmed);
|
|
154
162
|
}
|
|
163
|
+
const TRANSLATIONS_DIR = "lang";
|
|
164
|
+
/**
|
|
165
|
+
* Every `lang/<locale>/<namespace>.json` as `{ locale: { namespace: messages } }`
|
|
166
|
+
* JSON, for runtime injection (`GUREN_TRANSLATIONS`): no deploy target ships
|
|
167
|
+
* `lang/`. Same walk and parse tolerance as `JsonLoader` in @guren/server and
|
|
168
|
+
* `readTranslationCatalogs` in @guren/cli. Undefined when nothing is readable.
|
|
169
|
+
* @param label Platform name for the warning message, e.g. `'Lambda build'`.
|
|
170
|
+
*/
|
|
171
|
+
function translationCatalogJson(root, label) {
|
|
172
|
+
const base = resolve(root, TRANSLATIONS_DIR);
|
|
173
|
+
let locales;
|
|
174
|
+
try {
|
|
175
|
+
locales = readdirSync(base, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
176
|
+
} catch {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const catalog = {};
|
|
180
|
+
for (const locale of locales) {
|
|
181
|
+
const messages = {};
|
|
182
|
+
let files;
|
|
183
|
+
try {
|
|
184
|
+
files = readdirSync(resolve(base, locale)).filter((file) => extname(file) === ".json").sort();
|
|
185
|
+
} catch {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
for (const file of files) try {
|
|
189
|
+
messages[basename(file, ".json")] = JSON.parse(readFileSync(resolve(base, locale, file), "utf8"));
|
|
190
|
+
} catch {
|
|
191
|
+
console.warn(`${label}: ${TRANSLATIONS_DIR}/${locale}/${file} is not valid JSON and is left out of the deployed translations.`);
|
|
192
|
+
}
|
|
193
|
+
if (Object.keys(messages).length > 0) catalog[locale] = messages;
|
|
194
|
+
}
|
|
195
|
+
return Object.keys(catalog).length > 0 ? JSON.stringify(catalog) : void 0;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* What a deploy build bakes into the bundle, keyed by the `process.env` name
|
|
199
|
+
* @guren/server reads: the client manifest for viteAsset() and the lang/ catalogs
|
|
200
|
+
* for createApp({ i18n }). No target ships those files, and platform environment
|
|
201
|
+
* configuration is size-capped (Lambda: 4KB total), so neither goes there.
|
|
202
|
+
* @param label Platform name for warning messages, e.g. `'Lambda build'`.
|
|
203
|
+
*/
|
|
204
|
+
function bundledRuntimeEnv(root, publicDir, label) {
|
|
205
|
+
const env = {};
|
|
206
|
+
const manifest = clientManifestJson(publicDir);
|
|
207
|
+
if (manifest) env.GUREN_VITE_MANIFEST = manifest;
|
|
208
|
+
const translations = translationCatalogJson(root, label);
|
|
209
|
+
if (translations) env.GUREN_TRANSLATIONS = translations;
|
|
210
|
+
return env;
|
|
211
|
+
}
|
|
155
212
|
/**
|
|
156
213
|
* Absolute path of the built SSR entry chunk, or undefined without an SSR build.
|
|
157
214
|
* Whether the chunk exports a renderer is the caller's check: platforms disagree
|
|
@@ -193,17 +250,21 @@ function removeShadowingIndex(assetsOut) {
|
|
|
193
250
|
if (existsSync(shadowingIndex)) rmSync(shadowingIndex);
|
|
194
251
|
}
|
|
195
252
|
/**
|
|
196
|
-
* Copy `public/` into a platform's static staging directory
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* `
|
|
253
|
+
* Copy `public/` into a platform's static staging directory, with the built assets
|
|
254
|
+
* only under `CLIENT_ASSETS_URL_PREFIX`, the one prefix the HTML and the chunks
|
|
255
|
+
* address: a second copy at `assets/` would answer, and so hide, a URL that drifted
|
|
256
|
+
* off it. Vite empties `public/assets/` on every build, so it holds nothing else.
|
|
257
|
+
* Also applies `removeShadowingIndex`.
|
|
200
258
|
*/
|
|
201
259
|
function stageStaticAssets(publicDir, assetsOut) {
|
|
202
260
|
mkdirSync(assetsOut, { recursive: true });
|
|
203
261
|
if (!existsSync(publicDir)) return;
|
|
204
|
-
cpSync(publicDir, assetsOut, { recursive: true });
|
|
205
|
-
removeShadowingIndex(assetsOut);
|
|
206
262
|
const clientAssetsDir = resolve(publicDir, "assets");
|
|
263
|
+
cpSync(publicDir, assetsOut, {
|
|
264
|
+
recursive: true,
|
|
265
|
+
filter: (source) => resolve(source) !== clientAssetsDir
|
|
266
|
+
});
|
|
267
|
+
removeShadowingIndex(assetsOut);
|
|
207
268
|
if (existsSync(clientAssetsDir)) cpSync(clientAssetsDir, resolve(assetsOut, "public/assets"), { recursive: true });
|
|
208
269
|
}
|
|
209
270
|
/**
|
|
@@ -240,32 +301,38 @@ const DEV_ONLY_MODULES = [
|
|
|
240
301
|
{
|
|
241
302
|
specifier: "bun:sqlite",
|
|
242
303
|
kind: "sqlite",
|
|
243
|
-
exportNames: ["Database"]
|
|
304
|
+
exportNames: ["Database"],
|
|
305
|
+
importedBy: "packages/orm/src"
|
|
244
306
|
},
|
|
245
307
|
{
|
|
246
308
|
specifier: "vite",
|
|
247
309
|
kind: "vite",
|
|
248
|
-
exportNames: ["createServer"]
|
|
310
|
+
exportNames: ["createServer"],
|
|
311
|
+
importedBy: "packages/server/src"
|
|
249
312
|
},
|
|
250
313
|
{
|
|
251
314
|
specifier: "@guren/cli",
|
|
252
315
|
kind: "mcp",
|
|
253
|
-
exportNames: []
|
|
316
|
+
exportNames: [],
|
|
317
|
+
importedBy: "packages/server/src"
|
|
254
318
|
},
|
|
255
319
|
{
|
|
256
320
|
specifier: "@modelcontextprotocol/sdk/server/mcp.js",
|
|
257
321
|
kind: "mcp",
|
|
258
|
-
exportNames: ["McpServer", "ResourceTemplate"]
|
|
322
|
+
exportNames: ["McpServer", "ResourceTemplate"],
|
|
323
|
+
importedBy: "packages/server/src"
|
|
259
324
|
},
|
|
260
325
|
{
|
|
261
326
|
specifier: "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js",
|
|
262
327
|
kind: "mcp",
|
|
263
|
-
exportNames: ["WebStandardStreamableHTTPServerTransport"]
|
|
328
|
+
exportNames: ["WebStandardStreamableHTTPServerTransport"],
|
|
329
|
+
importedBy: null
|
|
264
330
|
}
|
|
265
331
|
];
|
|
266
332
|
/**
|
|
267
|
-
* The
|
|
268
|
-
*
|
|
333
|
+
* The v1 transport `@guren/plugin-mcp` imported before SDK v2 (RFC 0016 §7): the
|
|
334
|
+
* one `DEV_ONLY_MODULES` entry whose stubbing is conditional. Nothing imports it
|
|
335
|
+
* now, so the condition changes no bundle; it goes in RFC 0028's removal PR.
|
|
269
336
|
*/
|
|
270
337
|
const MCP_TRANSPORT_SPECIFIER = "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
271
338
|
/** The package an app declares to opt into the App MCP endpoint. */
|
|
@@ -287,9 +354,9 @@ function appUsesMcpPlugin(root) {
|
|
|
287
354
|
}
|
|
288
355
|
/**
|
|
289
356
|
* The dev-only modules that must stay stubbed for this app: `DEV_ONLY_MODULES`
|
|
290
|
-
* minus the transport entry when the app declared `@guren/plugin-mcp` (
|
|
291
|
-
*
|
|
292
|
-
*
|
|
357
|
+
* minus the v1 transport entry when the app declared `@guren/plugin-mcp` (RFC 0016
|
|
358
|
+
* Phase 4a). Since the plugin moved to SDK v2 that entry has no importer, so the
|
|
359
|
+
* split changes no bundle (RFC 0028 §4). `server/mcp.js` stays stubbed: the Dev MCP. Each entry keeps
|
|
293
360
|
* its narrow `kind` so platform `Record<kind, message>` tables stay indexable.
|
|
294
361
|
*/
|
|
295
362
|
function stubbableDevOnlyModules(options) {
|
|
@@ -321,19 +388,22 @@ const SQL_CLIENT_MODULES = [
|
|
|
321
388
|
specifier: "postgres",
|
|
322
389
|
kind: "sql-driver",
|
|
323
390
|
dialect: "postgres",
|
|
324
|
-
exportNames: []
|
|
391
|
+
exportNames: [],
|
|
392
|
+
importedBy: "packages/orm/src"
|
|
325
393
|
},
|
|
326
394
|
{
|
|
327
395
|
specifier: "mysql2",
|
|
328
396
|
kind: "sql-driver",
|
|
329
397
|
dialect: "mysql",
|
|
330
|
-
exportNames: []
|
|
398
|
+
exportNames: [],
|
|
399
|
+
importedBy: "packages/orm/src"
|
|
331
400
|
},
|
|
332
401
|
{
|
|
333
402
|
specifier: "mysql2/promise",
|
|
334
403
|
kind: "sql-driver",
|
|
335
404
|
dialect: "mysql",
|
|
336
|
-
exportNames: ["createPool"]
|
|
405
|
+
exportNames: ["createPool"],
|
|
406
|
+
importedBy: "packages/orm/src"
|
|
337
407
|
},
|
|
338
408
|
{
|
|
339
409
|
specifier: "@aws-sdk/client-rds-data",
|
|
@@ -345,7 +415,8 @@ const SQL_CLIENT_MODULES = [
|
|
|
345
415
|
"CommitTransactionCommand",
|
|
346
416
|
"ExecuteStatementCommand",
|
|
347
417
|
"RollbackTransactionCommand"
|
|
348
|
-
]
|
|
418
|
+
],
|
|
419
|
+
importedBy: "packages/orm/src"
|
|
349
420
|
}
|
|
350
421
|
];
|
|
351
422
|
/**
|
|
@@ -445,10 +516,11 @@ function renderDevOnlyStub(module, message) {
|
|
|
445
516
|
return `// ${comment}\n${throwing}\n${`function unavailable() { ${error} }`}\nexport default Object.assign(unavailable${named})\n`;
|
|
446
517
|
}
|
|
447
518
|
/**
|
|
448
|
-
* The MCP SDK is reached only through subpaths, which a package-name alias does
|
|
449
|
-
* cover (hence each one in `DEV_ONLY_MODULES`). A platform whose aliasing supports
|
|
450
|
-
* prefixes
|
|
519
|
+
* The v1 MCP SDK is reached only through subpaths, which a package-name alias does
|
|
520
|
+
* not cover (hence each one in `DEV_ONLY_MODULES`). A platform whose aliasing supports
|
|
521
|
+
* prefixes routes unlisted subpaths under this prefix to a stub too. SDK v2 lives
|
|
522
|
+
* under other package names, so `@guren/plugin-mcp`'s import is never matched.
|
|
451
523
|
*/
|
|
452
524
|
const MCP_SDK_SUBPATH_PREFIX = "@modelcontextprotocol/sdk/";
|
|
453
525
|
//#endregion
|
|
454
|
-
export { AGENTS_CONFIG_FILE, 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, removeShadowingIndex, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, unusedSqlClients };
|
|
526
|
+
export { AGENTS_CONFIG_FILE, CLIENT_ASSETS_URL_PREFIX, 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, bundledRuntimeEnv, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, removeShadowingIndex, renderDevOnlyStub, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, translationCatalogJson, unusedSqlClients };
|
package/dist/redis.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Redis, RedisApiTokenStore, RedisApiTokenStoreOptions, RedisClientOptions, RedisEmailVerificationStore, RedisEmailVerificationStoreOptions, RedisOAuthStateStore, RedisOAuthStateStoreOptions, RedisOptions, RedisPasswordResetStore, RedisPasswordResetStoreOptions, RedisRateLimitStore, RedisRateLimitStoreOptions, RedisSessionStore, RedisSessionStoreOptions, RedisSlidingWindowRateLimitStore, createRedisClient } from "@guren/server/redis";
|
|
2
|
-
export { Redis, RedisApiTokenStore, type RedisApiTokenStoreOptions, type RedisClientOptions, RedisEmailVerificationStore, type RedisEmailVerificationStoreOptions, RedisOAuthStateStore, type RedisOAuthStateStoreOptions, type RedisOptions, RedisPasswordResetStore, type RedisPasswordResetStoreOptions, RedisRateLimitStore, type RedisRateLimitStoreOptions, RedisSessionStore, type RedisSessionStoreOptions, RedisSlidingWindowRateLimitStore, createRedisClient };
|
|
1
|
+
import { Redis, RedisApiTokenStore, RedisApiTokenStoreOptions, RedisClientOptions, RedisEmailVerificationStore, RedisEmailVerificationStoreOptions, RedisOAuthStateStore, RedisOAuthStateStoreOptions, RedisOptions, RedisPasswordResetStore, RedisPasswordResetStoreOptions, RedisRateLimitStore, RedisRateLimitStoreOptions, RedisSchedulerLock, RedisSchedulerLockOptions, RedisSessionStore, RedisSessionStoreOptions, RedisSlidingWindowRateLimitStore, createRedisClient } from "@guren/server/redis";
|
|
2
|
+
export { Redis, RedisApiTokenStore, type RedisApiTokenStoreOptions, type RedisClientOptions, RedisEmailVerificationStore, type RedisEmailVerificationStoreOptions, RedisOAuthStateStore, type RedisOAuthStateStoreOptions, type RedisOptions, RedisPasswordResetStore, type RedisPasswordResetStoreOptions, RedisRateLimitStore, type RedisRateLimitStoreOptions, RedisSchedulerLock, type RedisSchedulerLockOptions, RedisSessionStore, type RedisSessionStoreOptions, RedisSlidingWindowRateLimitStore, createRedisClient };
|
package/dist/redis.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Redis, RedisApiTokenStore, RedisEmailVerificationStore, RedisOAuthStateStore, RedisPasswordResetStore, RedisRateLimitStore, RedisSessionStore, RedisSlidingWindowRateLimitStore, createRedisClient } from "@guren/server/redis";
|
|
2
|
-
export { Redis, RedisApiTokenStore, RedisEmailVerificationStore, RedisOAuthStateStore, RedisPasswordResetStore, RedisRateLimitStore, RedisSessionStore, RedisSlidingWindowRateLimitStore, createRedisClient };
|
|
1
|
+
import { Redis, RedisApiTokenStore, RedisEmailVerificationStore, RedisOAuthStateStore, RedisPasswordResetStore, RedisRateLimitStore, RedisSchedulerLock, RedisSessionStore, RedisSlidingWindowRateLimitStore, createRedisClient } from "@guren/server/redis";
|
|
2
|
+
export { Redis, RedisApiTokenStore, RedisEmailVerificationStore, RedisOAuthStateStore, RedisPasswordResetStore, RedisRateLimitStore, RedisSchedulerLock, RedisSessionStore, RedisSlidingWindowRateLimitStore, createRedisClient };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./src/bin.ts",
|
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
"typecheck": "tsc --noEmit"
|
|
89
89
|
},
|
|
90
90
|
"dependencies": {
|
|
91
|
-
"@guren/cli": "^2.
|
|
92
|
-
"@guren/orm": "^2.
|
|
93
|
-
"@guren/server": "^2.
|
|
91
|
+
"@guren/cli": "^2.24.0",
|
|
92
|
+
"@guren/orm": "^2.11.0",
|
|
93
|
+
"@guren/server": "^2.24.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@types/node": "^20.14.10",
|