@guren/core 1.21.0 → 1.23.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 CHANGED
@@ -1,5 +1,5 @@
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";
1
+ import { ApiToken, ApiTokenStore, AppEnv, AttachmentsDescription, 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, ModelSetOptions, 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 {
@@ -13,13 +13,15 @@ interface DatabaseApiTokenStoreOptions {
13
13
  abilitiesMode?: 'json' | 'text';
14
14
  }
15
15
  /**
16
- * Database-backed API token store built on the Guren ORM. Pass the Drizzle
17
- * table for your `api_tokens` schema; column property names must match the
18
- * {@link ApiToken} fields. Configure the ORM before use.
16
+ * Database-backed API token store built on the Guren ORM. Pass the Drizzle table
17
+ * for your `api_tokens` schema; column property names must match the {@link ApiToken}
18
+ * fields, and each timestamp is written as its column declares (timestamp mode,
19
+ * text as ISO, integer as epoch ms). Configure the ORM before use.
19
20
  * @example `new DatabaseApiTokenStore(apiTokens)`
20
21
  */
21
22
  declare class DatabaseApiTokenStore implements ApiTokenStore {
22
23
  private readonly model;
24
+ private readonly table;
23
25
  private readonly abilitiesMode;
24
26
  constructor(table: unknown, options?: DatabaseApiTokenStoreOptions);
25
27
  store(token: ApiToken): Promise<void>;
@@ -33,6 +35,7 @@ declare class DatabaseApiTokenStore implements ApiTokenStore {
33
35
  * them; this only keeps the table small.
34
36
  */
35
37
  deleteExpired(now?: Date): Promise<void>;
38
+ private timestamp;
36
39
  private deserialize;
37
40
  }
38
41
  //#endregion
@@ -51,11 +54,12 @@ interface DatabaseSessionStoreOptions {
51
54
  * Database-backed session store built on the Guren ORM, the serverless default
52
55
  * (no Redis on Lambda, Vercel, or Workers; reads are strongly consistent). Column
53
56
  * property names of the `sessions` table must be `id` (text primary key), `data`,
54
- * and `expiresAt`. Values must be JSON-serializable, unlike `MemorySessionStore`:
55
- * Dates return as ISO strings, `undefined` properties drop, `bigint` throws.
57
+ * and `expiresAt`, written as its column declares (timestamp mode, text or integer).
58
+ * Values must be JSON-serializable, unlike `MemorySessionStore`: Dates return as ISO strings, `undefined` drops, `bigint` throws.
56
59
  */
57
60
  declare class DatabaseSessionStore implements SessionStore {
58
61
  private readonly model;
62
+ private readonly table;
59
63
  private readonly dataMode;
60
64
  constructor(table: unknown, options?: DatabaseSessionStoreOptions);
61
65
  read(id: string): Promise<SessionData | undefined>;
@@ -74,6 +78,7 @@ declare class DatabaseSessionStore implements SessionStore {
74
78
  deleteExpired(now?: Date): Promise<void>;
75
79
  private deserialize;
76
80
  private expiryDate;
81
+ private expiresAt;
77
82
  }
78
83
  //#endregion
79
84
  //#region src/session-manager.d.ts
@@ -159,13 +164,14 @@ declare function defineDatabaseConfig(database: ConfigurableDatabase, options?:
159
164
  //#region src/oauth-state-store.d.ts
160
165
  /**
161
166
  * Database-backed OAuth state store built on the Guren ORM, for serverless, where
162
- * authorize and callback can land on different instances. Column property names
163
- * of the `oauth_states` table must be `stateHash` (text primary key), `provider`,
164
- * `redirectTo`, `expiresAt`, and `binding` (else `authorize({ bindTo })` states come back unbound).
167
+ * authorize and callback can land on different instances. Column property names of
168
+ * the `oauth_states` table must be `stateHash` (text primary key), `provider`, `redirectTo`,
169
+ * `expiresAt` (written as its column declares) and `binding` (else `authorize({ bindTo })` states come back unbound).
165
170
  * @example `new DatabaseOAuthStateStore(oauthStates)`
166
171
  */
167
172
  declare class DatabaseOAuthStateStore implements OAuthStateStore {
168
173
  private readonly model;
174
+ private readonly table;
169
175
  constructor(table: unknown);
170
176
  store(stateHash: string, payload: OAuthStatePayload): Promise<void>;
171
177
  find(stateHash: string): Promise<OAuthStatePayload | null>;
@@ -570,6 +576,7 @@ declare class AttachmentEngine {
570
576
  private readonly urlExpiresIn;
571
577
  private readonly queue?;
572
578
  private dispatchJob;
579
+ private readonly table;
573
580
  constructor(options: ConfigureAttachmentsOptions);
574
581
  /**
575
582
  * Bind this engine on `container` as `attachments` *and* resolve its storage
@@ -653,6 +660,11 @@ declare class AttachmentEngine {
653
660
  prefix: string;
654
661
  routeName: string;
655
662
  } | null;
663
+ /**
664
+ * The configuration as RFC 0026's manifest reports it, touching no disk. The
665
+ * manifest adds `delivery.mounted`, which only the route registry knows.
666
+ */
667
+ describe(): AttachmentsDescription;
656
668
  private deliveryKeyring;
657
669
  /**
658
670
  * The one URL policy (RFC 0015 §7): public disks stay on `disk.url()`; private
@@ -686,6 +698,13 @@ declare class AttachmentEngine {
686
698
  private toData;
687
699
  private toRecord;
688
700
  }
701
+ /**
702
+ * The engine an `Attachable` static would use, described (RFC 0026 §1): the
703
+ * default application's registered binding, else the one `configureAttachments()`
704
+ * built last. A deferred provider is not activated to find out, so an engine it
705
+ * binds at its first resolution is not the one described.
706
+ */
707
+ declare function describeActiveAttachmentEngine(): AttachmentsDescription;
689
708
  //#endregion
690
709
  //#region src/attachments/Attachable.d.ts
691
710
  /** A record id accepted by the attachment statics (int and uuid/text PKs). */
@@ -847,4 +866,4 @@ declare class GenerateVariantsJob extends Job<GenerateVariantsPayload> {
847
866
  failed(payload: GenerateVariantsPayload, _error: Error): Promise<void>;
848
867
  }
849
868
  //#endregion
850
- 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 };
869
+ 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 ModelSetOptions, 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, describeActiveAttachmentEngine, hasManyAttached, hasOneAttached, registerAttachmentRoutes, registerDatabaseSessionDriver, runSeeders };
package/dist/index.js CHANGED
@@ -17,18 +17,42 @@ function decodeJsonColumn(value, fallback) {
17
17
  }
18
18
  return value ?? fallback;
19
19
  }
20
+ /** `timestamp with time zone`, `timestamp(3)`, `datetime`, `date`, `time`: every driver binds a Date to these itself. */
21
+ const TEMPORAL_SQL_TYPE = /^(?:timestamp|datetime|date|time)\b/i;
22
+ /**
23
+ * A Date as the column declares it: temporal columns take the Date (drizzle and
24
+ * the pg/mysql drivers encode it), text takes the ISO string the SQLite scaffold's
25
+ * `$defaultFn` writes, integer takes epoch ms (`timestamp_ms`, what `toDate` reads).
26
+ * bun:sqlite cannot bind a Date, and a where clause binding one matches no row.
27
+ * `dataType` is split the way the ORM's `columnKind()` splits it (1.x: `number int53`).
28
+ */
29
+ function toColumnValue(table, field, value) {
30
+ if (!(value instanceof Date)) return value;
31
+ const column = table?.[field];
32
+ if (!column || typeof column !== "object") return value;
33
+ const sqlType = typeof column.getSQLType === "function" ? column.getSQLType() : "";
34
+ if (TEMPORAL_SQL_TYPE.test(sqlType)) return value;
35
+ const kind = typeof column.dataType === "string" ? column.dataType.split(" ")[0] : "";
36
+ if (kind === "string") return value.toISOString();
37
+ if (kind === "number") return value.getTime();
38
+ if (kind === "bigint") return BigInt(value.getTime());
39
+ return value;
40
+ }
20
41
  //#endregion
21
42
  //#region src/api-token-store.ts
22
43
  /**
23
- * Database-backed API token store built on the Guren ORM. Pass the Drizzle
24
- * table for your `api_tokens` schema; column property names must match the
25
- * {@link ApiToken} fields. Configure the ORM before use.
44
+ * Database-backed API token store built on the Guren ORM. Pass the Drizzle table
45
+ * for your `api_tokens` schema; column property names must match the {@link ApiToken}
46
+ * fields, and each timestamp is written as its column declares (timestamp mode,
47
+ * text as ISO, integer as epoch ms). Configure the ORM before use.
26
48
  * @example `new DatabaseApiTokenStore(apiTokens)`
27
49
  */
28
50
  var DatabaseApiTokenStore = class {
29
51
  model;
52
+ table;
30
53
  abilitiesMode;
31
54
  constructor(table, options = {}) {
55
+ this.table = table;
32
56
  this.abilitiesMode = options.abilitiesMode ?? "json";
33
57
  this.model = class ApiTokenModel extends Model$1 {
34
58
  static table = table;
@@ -37,7 +61,10 @@ var DatabaseApiTokenStore = class {
37
61
  async store(token) {
38
62
  await this.model.forceCreate({
39
63
  ...token,
40
- abilities: this.abilitiesMode === "text" ? JSON.stringify(token.abilities) : token.abilities
64
+ abilities: this.abilitiesMode === "text" ? JSON.stringify(token.abilities) : token.abilities,
65
+ lastUsedAt: this.timestamp("lastUsedAt", token.lastUsedAt),
66
+ expiresAt: this.timestamp("expiresAt", token.expiresAt),
67
+ createdAt: this.timestamp("createdAt", token.createdAt)
41
68
  });
42
69
  }
43
70
  async findByHashedToken(hashedToken) {
@@ -54,14 +81,17 @@ var DatabaseApiTokenStore = class {
54
81
  await this.model.where({ userId }).delete();
55
82
  }
56
83
  async updateLastUsed(id, timestamp) {
57
- await this.model.forceUpdate({ id }, { lastUsedAt: timestamp });
84
+ await this.model.forceUpdate({ id }, { lastUsedAt: this.timestamp("lastUsedAt", timestamp) });
58
85
  }
59
86
  /**
60
87
  * Delete tokens whose expiration has passed. `verifyApiToken` already rejects
61
88
  * them; this only keeps the table small.
62
89
  */
63
90
  async deleteExpired(now = /* @__PURE__ */ new Date()) {
64
- await this.model.where("expiresAt", "<", now).delete();
91
+ await this.model.where("expiresAt", "<", this.timestamp("expiresAt", now)).delete();
92
+ }
93
+ timestamp(field, value) {
94
+ return toColumnValue(this.table, field, value);
65
95
  }
66
96
  deserialize(record) {
67
97
  const abilities = decodeJsonColumn(record.abilities, []);
@@ -83,13 +113,15 @@ var DatabaseApiTokenStore = class {
83
113
  * Database-backed session store built on the Guren ORM, the serverless default
84
114
  * (no Redis on Lambda, Vercel, or Workers; reads are strongly consistent). Column
85
115
  * property names of the `sessions` table must be `id` (text primary key), `data`,
86
- * and `expiresAt`. Values must be JSON-serializable, unlike `MemorySessionStore`:
87
- * Dates return as ISO strings, `undefined` properties drop, `bigint` throws.
116
+ * and `expiresAt`, written as its column declares (timestamp mode, text or integer).
117
+ * Values must be JSON-serializable, unlike `MemorySessionStore`: Dates return as ISO strings, `undefined` drops, `bigint` throws.
88
118
  */
89
119
  var DatabaseSessionStore = class {
90
120
  model;
121
+ table;
91
122
  dataMode;
92
123
  constructor(table, options = {}) {
124
+ this.table = table;
93
125
  this.dataMode = options.dataMode ?? "json";
94
126
  this.model = class SessionModel extends Model$1 {
95
127
  static table = table;
@@ -135,20 +167,23 @@ var DatabaseSessionStore = class {
135
167
  * `SessionStore.touch` contract.
136
168
  */
137
169
  async touch(id, ttlSeconds) {
138
- await this.model.where({ id }).where("expiresAt", ">", /* @__PURE__ */ new Date()).forceUpdate({ expiresAt: this.expiryDate(ttlSeconds) });
170
+ await this.model.where({ id }).where("expiresAt", ">", this.expiresAt(/* @__PURE__ */ new Date())).forceUpdate({ expiresAt: this.expiryDate(ttlSeconds) });
139
171
  }
140
172
  /**
141
173
  * Delete sessions whose expiration has passed. `read` already treats them as
142
174
  * missing; this only keeps the table small.
143
175
  */
144
176
  async deleteExpired(now = /* @__PURE__ */ new Date()) {
145
- await this.model.where("expiresAt", "<=", now).delete();
177
+ await this.model.where("expiresAt", "<=", this.expiresAt(now)).delete();
146
178
  }
147
179
  deserialize(record) {
148
180
  return decodeJsonColumn(record.data, {});
149
181
  }
150
182
  expiryDate(ttlSeconds) {
151
- return new Date(Date.now() + ttlSeconds * 1e3);
183
+ return this.expiresAt(new Date(Date.now() + ttlSeconds * 1e3));
184
+ }
185
+ expiresAt(value) {
186
+ return toColumnValue(this.table, "expiresAt", value);
152
187
  }
153
188
  };
154
189
  //#endregion
@@ -229,14 +264,16 @@ function defineDatabaseConfig(database, options = {}) {
229
264
  //#region src/oauth-state-store.ts
230
265
  /**
231
266
  * Database-backed OAuth state store built on the Guren ORM, for serverless, where
232
- * authorize and callback can land on different instances. Column property names
233
- * of the `oauth_states` table must be `stateHash` (text primary key), `provider`,
234
- * `redirectTo`, `expiresAt`, and `binding` (else `authorize({ bindTo })` states come back unbound).
267
+ * authorize and callback can land on different instances. Column property names of
268
+ * the `oauth_states` table must be `stateHash` (text primary key), `provider`, `redirectTo`,
269
+ * `expiresAt` (written as its column declares) and `binding` (else `authorize({ bindTo })` states come back unbound).
235
270
  * @example `new DatabaseOAuthStateStore(oauthStates)`
236
271
  */
237
272
  var DatabaseOAuthStateStore = class {
238
273
  model;
274
+ table;
239
275
  constructor(table) {
276
+ this.table = table;
240
277
  this.model = class OAuthStateModel extends Model$1 {
241
278
  static table = table;
242
279
  };
@@ -246,7 +283,7 @@ var DatabaseOAuthStateStore = class {
246
283
  stateHash,
247
284
  provider: payload.provider,
248
285
  redirectTo: payload.redirectTo ?? null,
249
- expiresAt: payload.expiresAt,
286
+ expiresAt: toColumnValue(this.table, "expiresAt", payload.expiresAt),
250
287
  binding: payload.binding ?? null
251
288
  });
252
289
  }
@@ -290,7 +327,7 @@ var DatabaseOAuthStateStore = class {
290
327
  * only keeps the table small.
291
328
  */
292
329
  async deleteExpired(now = /* @__PURE__ */ new Date()) {
293
- await this.model.where("expiresAt", "<=", now).delete();
330
+ await this.model.where("expiresAt", "<=", toColumnValue(this.table, "expiresAt", now)).delete();
294
331
  }
295
332
  };
296
333
  /** Build the public payload from a live (non-expired) row. */
@@ -747,8 +784,10 @@ var AttachmentEngine = class {
747
784
  urlExpiresIn;
748
785
  queue;
749
786
  dispatchJob = null;
787
+ table;
750
788
  constructor(options) {
751
789
  const table = options.table;
790
+ this.table = table;
752
791
  const locks = collectionWrites.get(table) ?? /* @__PURE__ */ new Map();
753
792
  collectionWrites.set(table, locks);
754
793
  this.collectionLocks = locks;
@@ -1318,6 +1357,20 @@ var AttachmentEngine = class {
1318
1357
  get deliveryRoute() {
1319
1358
  return this.delivery;
1320
1359
  }
1360
+ /**
1361
+ * The configuration as RFC 0026's manifest reports it, touching no disk. The
1362
+ * manifest adds `delivery.mounted`, which only the route registry knows.
1363
+ */
1364
+ describe() {
1365
+ const table = drizzleTableName(this.table);
1366
+ return {
1367
+ configured: true,
1368
+ ...table === void 0 ? {} : { table },
1369
+ disk: this.defaultDisk,
1370
+ disks: Object.fromEntries(Object.entries(this.diskDelivery).map(([name, disk]) => [name, { ...disk }])),
1371
+ ...this.delivery ? { delivery: { ...this.delivery } } : {}
1372
+ };
1373
+ }
1321
1374
  deliveryKeyring() {
1322
1375
  if (!this.deliveryKeys) this.deliveryKeys = deriveAppKeyring(getAppKeyringFromEnv(), "attachment-delivery");
1323
1376
  return this.deliveryKeys;
@@ -1508,6 +1561,23 @@ function resolveDeliveryRoute() {
1508
1561
  routeName: "attachments.show"
1509
1562
  };
1510
1563
  }
1564
+ /**
1565
+ * The engine an `Attachable` static would use, described (RFC 0026 §1): the
1566
+ * default application's registered binding, else the one `configureAttachments()`
1567
+ * built last. A deferred provider is not activated to find out, so an engine it
1568
+ * binds at its first resolution is not the one described.
1569
+ */
1570
+ function describeActiveAttachmentEngine() {
1571
+ const container = ambientContainer();
1572
+ const engine = (container?.has("attachments") ? container.make("attachments") : void 0) ?? activeEngine;
1573
+ return engine ? engine.describe() : { configured: false };
1574
+ }
1575
+ /** drizzle's `getTableName()` through its registry symbol; `session-manager.ts` in server reads it the same way. */
1576
+ function drizzleTableName(table) {
1577
+ if (!table || typeof table !== "object") return void 0;
1578
+ const name = table[Symbol.for("drizzle:Name")];
1579
+ return typeof name === "string" ? name : void 0;
1580
+ }
1511
1581
  function resolveAttachmentEngine(caller) {
1512
1582
  const engine = ambientBinding("attachments") ?? activeEngine;
1513
1583
  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.`);
@@ -1811,4 +1881,4 @@ function hasManyAttached(options = {}) {
1811
1881
  return buildSpec("many", options);
1812
1882
  }
1813
1883
  //#endregion
1814
- 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 };
1884
+ 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, describeActiveAttachmentEngine, hasManyAttached, hasOneAttached, registerAttachmentRoutes, registerDatabaseSessionDriver, runSeeders };
@@ -5,8 +5,8 @@
5
5
  * Its own entry, not part of `deploy-build`: that one imports node builtins
6
6
  * only (its test scans the built artifact), while the scan lives in
7
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.
8
+ * The CLI reads the introspected app, and reports a verdict it cannot vouch for as unverified (RFC 0026 §5).
9
+ * Warns, never throws: a wrong guess must not block a deploy.
10
10
  */
11
11
  interface ReportDeployRuntimeHazardsOptions {
12
12
  /** App root the scan reads. */
@@ -15,9 +15,9 @@ interface ReportDeployRuntimeHazardsOptions {
15
15
  label: string;
16
16
  }
17
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.
18
+ * Print one `console.log` line naming the evidence, then every non-passing verdict
19
+ * through `console.warn`, one line each, and return those. A scan that cannot run
20
+ * prints one line saying so rather than nothing: silence would read as a clean report.
21
21
  */
22
22
  declare function reportDeployRuntimeHazards(options: ReportDeployRuntimeHazardsOptions): Promise<string[]>;
23
23
  //#endregion
@@ -3,9 +3,9 @@ function describeError(error) {
3
3
  return error instanceof Error ? error.message : String(error);
4
4
  }
5
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.
6
+ * Print one `console.log` line naming the evidence, then every non-passing verdict
7
+ * through `console.warn`, one line each, and return those. A scan that cannot run
8
+ * prints one line saying so rather than nothing: silence would read as a clean report.
9
9
  */
10
10
  async function reportDeployRuntimeHazards(options) {
11
11
  const { root, label } = options;
@@ -22,10 +22,28 @@ async function reportDeployRuntimeHazards(options) {
22
22
  } catch (error) {
23
23
  return skipped(label, `the scan failed (${describeError(error)})`);
24
24
  }
25
+ const evidence = describeEvidence(label, verdicts);
26
+ if (evidence) console.log(evidence);
25
27
  const lines = verdicts.filter((verdict) => verdict.status !== "pass").map((verdict) => `${label}: ${verdict.message}${verdict.fix ? ` ${verdict.fix}` : ""}`);
26
28
  for (const line of lines) console.warn(line);
27
29
  return lines;
28
30
  }
31
+ /** One line naming what each verdict was judged from, and why the source when the app could not be read. */
32
+ function describeEvidence(label, verdicts) {
33
+ const judged = [];
34
+ for (const { title, evidence } of verdicts) {
35
+ if (evidence === void 0) return void 0;
36
+ judged.push(`${title} from ${EVIDENCE_LABELS[evidence]}`);
37
+ }
38
+ if (judged.length === 0) return void 0;
39
+ const reasons = [...new Set(verdicts.flatMap((verdict) => verdict.evidenceReason ? [verdict.evidenceReason] : []))];
40
+ return `${label}: deploy-runtime checks judged ${judged.join(", ")}${reasons.length > 0 ? ` (${reasons.join("; ")})` : ""}.`;
41
+ }
42
+ const EVIDENCE_LABELS = {
43
+ manifest: "the introspected app",
44
+ static: "source",
45
+ none: "nothing verifiable"
46
+ };
29
47
  function skipped(label, reason) {
30
48
  const line = `${label}: deploy-runtime checks skipped — ${reason}. Run \`bunx guren doctor\` before deploying.`;
31
49
  console.warn(line);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/core",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "description": "Guren: the Bun-first fullstack TypeScript framework. Laravel-style MVC on Hono, Drizzle ORM and Inertia.js + React. Develop on Bun; deploy to Bun, AWS Lambda (Node.js), Vercel or Cloudflare Workers.",
5
5
  "keywords": [
6
6
  "guren",
@@ -104,9 +104,9 @@
104
104
  "typecheck": "tsc --noEmit"
105
105
  },
106
106
  "dependencies": {
107
- "@guren/cli": "^2.27.0",
108
- "@guren/orm": "^2.12.0",
109
- "@guren/server": "^2.26.0"
107
+ "@guren/cli": "^2.28.1",
108
+ "@guren/orm": "^2.13.0",
109
+ "@guren/server": "^2.28.0"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@types/node": "^20.14.10",