@guren/core 1.14.0 → 1.16.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 +41 -2
- package/dist/index.js +38 -2
- package/dist/internal/deploy-check.d.ts +24 -0
- package/dist/internal/deploy-check.js +35 -0
- package/package.json +8 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiToken, ApiTokenStore, Command, Controller, Job, OAuthStatePayload, OAuthStateStore, Router, SessionData, SessionStore, StorageManager } from "@guren/server";
|
|
1
|
+
import { ApiToken, ApiTokenStore, Command, Controller, Job, OAuthStatePayload, OAuthStateStore, Router, SessionConfig, SessionData, SessionManager, SessionStore, StorageManager } from "@guren/server";
|
|
2
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";
|
|
3
3
|
export * from "@guren/server";
|
|
4
4
|
//#region src/api-token-store.d.ts
|
|
@@ -76,6 +76,45 @@ declare class DatabaseSessionStore implements SessionStore {
|
|
|
76
76
|
private expiryDate;
|
|
77
77
|
}
|
|
78
78
|
//#endregion
|
|
79
|
+
//#region src/session-manager.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* The `database` driver's config. `table` is the app's own drizzle `sessions`
|
|
82
|
+
* table: core cannot name one for it, since a table drizzle-kit does not see
|
|
83
|
+
* in `db/schema.ts` gets no migration (RFC 0020 §1).
|
|
84
|
+
*/
|
|
85
|
+
interface DatabaseSessionDriverOptions extends DatabaseSessionStoreOptions {
|
|
86
|
+
/** The `sessions` table, with `id`, `data` and `expiresAt` columns. */
|
|
87
|
+
table: unknown;
|
|
88
|
+
}
|
|
89
|
+
declare module '@guren/server' {
|
|
90
|
+
interface SessionDrivers {
|
|
91
|
+
database: DatabaseSessionDriverOptions;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A `SessionManager` that knows the `database` driver, which `@guren/server`
|
|
96
|
+
* cannot register itself: the store wraps the table in an ORM model, and
|
|
97
|
+
* server must not depend on `@guren/orm` (RFC 0003, Alternatives). Registered
|
|
98
|
+
* here rather than by importing this module for its side effect, so a bundler
|
|
99
|
+
* that drops an unused import cannot drop the driver with it.
|
|
100
|
+
*/
|
|
101
|
+
declare function createSessionManager(config?: SessionConfig): SessionManager;
|
|
102
|
+
/** Adds the `database` driver to a manager built elsewhere (a plugin's, or a subclass). */
|
|
103
|
+
declare function registerDatabaseSessionDriver(manager: SessionManager): void;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/session-prune-command.d.ts
|
|
106
|
+
/**
|
|
107
|
+
* Console sweeper for session stores (RFC 0020 §2). `read()` already treats an
|
|
108
|
+
* expired session as missing, so this only keeps the table from growing;
|
|
109
|
+
* schedule it. Stores that cannot sweep (Redis expires its own keys) are
|
|
110
|
+
* skipped by the manager.
|
|
111
|
+
*/
|
|
112
|
+
declare class SessionsPruneCommand extends Command {
|
|
113
|
+
static signature: string;
|
|
114
|
+
static description: string;
|
|
115
|
+
handle(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
79
118
|
//#region src/oauth-state-store.d.ts
|
|
80
119
|
/**
|
|
81
120
|
* Database-backed OAuth state store built on the Guren ORM, for serverless, where
|
|
@@ -598,4 +637,4 @@ declare class GenerateVariantsJob extends Job<GenerateVariantsPayload> {
|
|
|
598
637
|
failed(payload: GenerateVariantsPayload, _error: Error): Promise<void>;
|
|
599
638
|
}
|
|
600
639
|
//#endregion
|
|
601
|
-
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, Controller, HttpException, Job, ValidationException, deriveAppKeyring, getAppKeyringFromEnv, getQueueDriver, registerJob, setQueueDriver, signUrl, verifySignedUrl } from "@guren/server";
|
|
1
|
+
import { Command, Controller, HttpException, Job, SessionManager, ValidationException, deriveAppKeyring, getAppKeyringFromEnv, getQueueDriver, registerJob, setQueueDriver, signUrl, 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";
|
|
@@ -152,6 +152,42 @@ var DatabaseSessionStore = class {
|
|
|
152
152
|
}
|
|
153
153
|
};
|
|
154
154
|
//#endregion
|
|
155
|
+
//#region src/session-manager.ts
|
|
156
|
+
/**
|
|
157
|
+
* A `SessionManager` that knows the `database` driver, which `@guren/server`
|
|
158
|
+
* cannot register itself: the store wraps the table in an ORM model, and
|
|
159
|
+
* server must not depend on `@guren/orm` (RFC 0003, Alternatives). Registered
|
|
160
|
+
* here rather than by importing this module for its side effect, so a bundler
|
|
161
|
+
* that drops an unused import cannot drop the driver with it.
|
|
162
|
+
*/
|
|
163
|
+
function createSessionManager(config = {}) {
|
|
164
|
+
const manager = new SessionManager(config);
|
|
165
|
+
registerDatabaseSessionDriver(manager);
|
|
166
|
+
return manager;
|
|
167
|
+
}
|
|
168
|
+
/** Adds the `database` driver to a manager built elsewhere (a plugin's, or a subclass). */
|
|
169
|
+
function registerDatabaseSessionDriver(manager) {
|
|
170
|
+
manager.registerDriver("database", ({ table, ...options }) => new DatabaseSessionStore(table, options));
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/session-prune-command.ts
|
|
174
|
+
/**
|
|
175
|
+
* Console sweeper for session stores (RFC 0020 §2). `read()` already treats an
|
|
176
|
+
* expired session as missing, so this only keeps the table from growing;
|
|
177
|
+
* schedule it. Stores that cannot sweep (Redis expires its own keys) are
|
|
178
|
+
* skipped by the manager.
|
|
179
|
+
*/
|
|
180
|
+
var SessionsPruneCommand = class extends Command {
|
|
181
|
+
static signature = "sessions:prune";
|
|
182
|
+
static description = "Delete expired sessions from the configured session stores";
|
|
183
|
+
async handle() {
|
|
184
|
+
const manager = this.resolveOptional("session");
|
|
185
|
+
if (!manager) throw new Error("sessions:prune requires a session manager. Register a provider that binds createSessionManager(sessionConfig) as `session` (run `bunx guren add session`).");
|
|
186
|
+
await manager.pruneExpired();
|
|
187
|
+
this.info("Expired sessions removed.");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
155
191
|
//#region src/oauth-state-store.ts
|
|
156
192
|
/**
|
|
157
193
|
* Database-backed OAuth state store built on the Guren ORM, for serverless, where
|
|
@@ -1643,4 +1679,4 @@ function hasManyAttached(options = {}) {
|
|
|
1643
1679
|
return buildSpec("many", options);
|
|
1644
1680
|
}
|
|
1645
1681
|
//#endregion
|
|
1646
|
-
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 };
|
|
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 };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/internal/deploy-check.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The deploy-runtime verdicts at build time (RFC 0020 Part 0), published as
|
|
4
|
+
* `@guren/core/internal/deploy-check` for the deploy plugins' build commands.
|
|
5
|
+
* Its own entry, not part of `deploy-build`: that one imports node builtins
|
|
6
|
+
* only (its test scans the built artifact), while the scan lives in
|
|
7
|
+
* `@guren/cli`, reached here lazily so nothing loads until a build asks.
|
|
8
|
+
* Warns, never throws: the scan reads constructions, not intent, and a wrong
|
|
9
|
+
* guess must not block a deploy.
|
|
10
|
+
*/
|
|
11
|
+
interface ReportDeployRuntimeHazardsOptions {
|
|
12
|
+
/** App root the scan reads. */
|
|
13
|
+
root: string;
|
|
14
|
+
/** Prefix of every line, e.g. `Cloudflare build`. */
|
|
15
|
+
label: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Print every non-passing verdict through `console.warn`, one line each, and
|
|
19
|
+
* return the lines. A scan that cannot run prints one line saying so rather
|
|
20
|
+
* than nothing: silence would read as a clean report.
|
|
21
|
+
*/
|
|
22
|
+
declare function reportDeployRuntimeHazards(options: ReportDeployRuntimeHazardsOptions): Promise<string[]>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ReportDeployRuntimeHazardsOptions, reportDeployRuntimeHazards };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/internal/deploy-check.ts
|
|
2
|
+
function describeError(error) {
|
|
3
|
+
return error instanceof Error ? error.message : String(error);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Print every non-passing verdict through `console.warn`, one line each, and
|
|
7
|
+
* return the lines. A scan that cannot run prints one line saying so rather
|
|
8
|
+
* than nothing: silence would read as a clean report.
|
|
9
|
+
*/
|
|
10
|
+
async function reportDeployRuntimeHazards(options) {
|
|
11
|
+
const { root, label } = options;
|
|
12
|
+
let cli;
|
|
13
|
+
try {
|
|
14
|
+
cli = await import("@guren/cli");
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return skipped(label, `@guren/cli could not be loaded (${describeError(error)})`);
|
|
17
|
+
}
|
|
18
|
+
if (typeof cli.checkDeployRuntime !== "function") return skipped(label, "the installed @guren/cli predates them; upgrade it");
|
|
19
|
+
let verdicts;
|
|
20
|
+
try {
|
|
21
|
+
verdicts = await cli.checkDeployRuntime(root);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return skipped(label, `the scan failed (${describeError(error)})`);
|
|
24
|
+
}
|
|
25
|
+
const lines = verdicts.filter((verdict) => verdict.status !== "pass").map((verdict) => `${label}: ${verdict.message}${verdict.fix ? ` ${verdict.fix}` : ""}`);
|
|
26
|
+
for (const line of lines) console.warn(line);
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
function skipped(label, reason) {
|
|
30
|
+
const line = `${label}: deploy-runtime checks skipped — ${reason}. Run \`bunx guren doctor\` before deploying.`;
|
|
31
|
+
console.warn(line);
|
|
32
|
+
return [line];
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { reportDeployRuntimeHazards };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./src/bin.ts",
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
"types": "./dist/internal/deploy-build.d.ts",
|
|
54
54
|
"default": "./dist/internal/deploy-build.js"
|
|
55
55
|
},
|
|
56
|
+
"./internal/deploy-check": {
|
|
57
|
+
"types": "./dist/internal/deploy-check.d.ts",
|
|
58
|
+
"default": "./dist/internal/deploy-check.js"
|
|
59
|
+
},
|
|
56
60
|
"./internal/route-path": {
|
|
57
61
|
"types": "./dist/internal/route-path.d.ts",
|
|
58
62
|
"default": "./dist/internal/route-path.js"
|
|
@@ -84,9 +88,9 @@
|
|
|
84
88
|
"typecheck": "tsc --noEmit"
|
|
85
89
|
},
|
|
86
90
|
"dependencies": {
|
|
87
|
-
"@guren/cli": "^2.
|
|
88
|
-
"@guren/orm": "^2.
|
|
89
|
-
"@guren/server": "^2.
|
|
91
|
+
"@guren/cli": "^2.20.0",
|
|
92
|
+
"@guren/orm": "^2.7.1",
|
|
93
|
+
"@guren/server": "^2.21.0"
|
|
90
94
|
},
|
|
91
95
|
"devDependencies": {
|
|
92
96
|
"@types/node": "^20.14.10",
|