@guren/core 1.24.0 → 1.25.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
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";
|
|
2
|
+
import { AccessorDefinitions, AccessorFn, AggregateFunction, AvgValue, AwsDataApiDatabase, AwsDataApiDatabaseOptions, AwsDataApiSeederContext, BelongsToManyRecord, BelongsToManyRelationResult, BelongsToRecord, BelongsToRelationResult, BelongsToRequiredRecord, CastType, ConnectionContext, ConnectionContext as ConnectionContext$1, D1DatabaseHandle, D1DatabaseOptions, DatabaseDescription, DestructiveMigrationError, DestructiveMigrationMode, 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 {
|
|
@@ -126,6 +126,8 @@ interface ConfigurableDatabase {
|
|
|
126
126
|
configureOrm(context?: ConnectionContext$1): Promise<void>;
|
|
127
127
|
seedDatabase(): Promise<unknown>;
|
|
128
128
|
hasMigrations(): boolean;
|
|
129
|
+
/** Where the database lives, read by introspection (RFC 0033 §3); absent leaves the manifest's `database` unverified. */
|
|
130
|
+
describe?(context?: ConnectionContext$1): DatabaseDescription;
|
|
129
131
|
}
|
|
130
132
|
interface DatabaseConfig {
|
|
131
133
|
readonly database: ConfigurableDatabase;
|
|
@@ -866,4 +868,4 @@ declare class GenerateVariantsJob extends Job<GenerateVariantsPayload> {
|
|
|
866
868
|
failed(payload: GenerateVariantsPayload, _error: Error): Promise<void>;
|
|
867
869
|
}
|
|
868
870
|
//#endregion
|
|
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 };
|
|
871
|
+
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, DestructiveMigrationError, type DestructiveMigrationMode, 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, Controller, HttpException, Job, SessionManager, ValidationException, ambientBinding, ambientContainer, defineConfig, deriveAppKeyring, getAppKeyringFromEnv, registerJob, resolveQueueDriver, signUrl, tryGetRequestContainer, verifySignedUrl } from "@guren/server";
|
|
2
|
-
import { DrizzleAdapter, MassAssignmentException, Model, Model as Model$1, ModelNotFoundException, QueryBuilder, SoftDeletes, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, runSeeders } from "@guren/orm";
|
|
2
|
+
import { DestructiveMigrationError, 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";
|
|
5
5
|
export * from "@guren/server";
|
|
@@ -254,8 +254,8 @@ function defineDatabaseConfig(database, options = {}) {
|
|
|
254
254
|
bind: (container, config) => {
|
|
255
255
|
container.instance("database", config.database);
|
|
256
256
|
},
|
|
257
|
-
boot: async (container, config
|
|
258
|
-
await config.database.configureOrm(container.has("env") ? { env } : void 0);
|
|
257
|
+
boot: async (container, config) => {
|
|
258
|
+
await config.database.configureOrm(container.has("env") ? { env: container.make("env") } : void 0);
|
|
259
259
|
if (config.seedOnBoot && config.database.hasMigrations()) await config.database.seedDatabase();
|
|
260
260
|
}
|
|
261
261
|
});
|
|
@@ -1881,4 +1881,4 @@ function hasManyAttached(options = {}) {
|
|
|
1881
1881
|
return buildSpec("many", options);
|
|
1882
1882
|
}
|
|
1883
1883
|
//#endregion
|
|
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 };
|
|
1884
|
+
export { ATTACHMENT_OBJECT_PREFIX, Attachable, AttachmentDeliveryController, AttachmentsPruneCommand, DEFAULT_DELIVERY_ROUTE_NAME, DatabaseApiTokenStore, DatabaseOAuthStateStore, DatabaseSessionStore, DestructiveMigrationError, 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 };
|
|
@@ -8,11 +8,27 @@
|
|
|
8
8
|
* The CLI reads the introspected app, and reports a verdict it cannot vouch for as unverified (RFC 0026 §5).
|
|
9
9
|
* Warns, never throws: a wrong guess must not block a deploy.
|
|
10
10
|
*/
|
|
11
|
+
/**
|
|
12
|
+
* Restates `DeployTargetApp` in @guren/cli's deploy-runtime.ts structurally, since this module imports
|
|
13
|
+
* no CLI type: the CLI an app installs may be older or newer than this core.
|
|
14
|
+
* The app as the target runs it, for the deploy plugin to read its bindings from (RFC 0035 §2):
|
|
15
|
+
* the introspected `storage` and `database` sections the CLI vouches for, or why they could not be read.
|
|
16
|
+
*/
|
|
17
|
+
type DeployTargetApp = {
|
|
18
|
+
status: 'read';
|
|
19
|
+
storage?: unknown;
|
|
20
|
+
database?: unknown;
|
|
21
|
+
} | {
|
|
22
|
+
status: 'unread';
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
11
25
|
interface ReportDeployRuntimeHazardsOptions {
|
|
12
26
|
/** App root the scan reads. */
|
|
13
27
|
root: string;
|
|
14
28
|
/** Prefix of every line, e.g. `Cloudflare build`. */
|
|
15
29
|
label: string;
|
|
30
|
+
/** Judge the app's branch for this platform (RFC 0035 §2.1), for a plugin whose `env` subpath honours it. */
|
|
31
|
+
target?: 'cloudflare';
|
|
16
32
|
}
|
|
17
33
|
/**
|
|
18
34
|
* Print one `console.log` line naming the evidence, then every non-passing verdict
|
|
@@ -20,5 +36,13 @@ interface ReportDeployRuntimeHazardsOptions {
|
|
|
20
36
|
* prints one line saying so rather than nothing: silence would read as a clean report.
|
|
21
37
|
*/
|
|
22
38
|
declare function reportDeployRuntimeHazards(options: ReportDeployRuntimeHazardsOptions): Promise<string[]>;
|
|
39
|
+
/**
|
|
40
|
+
* {@link reportDeployRuntimeHazards}, also returning the introspected app when `target` is set, from
|
|
41
|
+
* the same child. A CLI that cannot return it leaves `app` unread, which fails nothing.
|
|
42
|
+
*/
|
|
43
|
+
declare function inspectDeployRuntime(options: ReportDeployRuntimeHazardsOptions): Promise<{
|
|
44
|
+
hazards: string[];
|
|
45
|
+
app?: DeployTargetApp;
|
|
46
|
+
}>;
|
|
23
47
|
//#endregion
|
|
24
|
-
export { ReportDeployRuntimeHazardsOptions, reportDeployRuntimeHazards };
|
|
48
|
+
export { DeployTargetApp, ReportDeployRuntimeHazardsOptions, inspectDeployRuntime, reportDeployRuntimeHazards };
|
|
@@ -8,32 +8,57 @@ function describeError(error) {
|
|
|
8
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
|
+
return (await inspectDeployRuntime(options)).hazards;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* {@link reportDeployRuntimeHazards}, also returning the introspected app when `target` is set, from
|
|
15
|
+
* the same child. A CLI that cannot return it leaves `app` unread, which fails nothing.
|
|
16
|
+
*/
|
|
17
|
+
async function inspectDeployRuntime(options) {
|
|
18
|
+
const { root, label, target } = options;
|
|
19
|
+
const bail = (reason) => ({
|
|
20
|
+
hazards: skipped(label, reason),
|
|
21
|
+
...target ? { app: unread(reason) } : {}
|
|
22
|
+
});
|
|
12
23
|
let cli;
|
|
13
24
|
try {
|
|
14
25
|
cli = await import("@guren/cli");
|
|
15
26
|
} catch (error) {
|
|
16
|
-
return
|
|
27
|
+
return bail(`@guren/cli could not be loaded (${describeError(error)})`);
|
|
17
28
|
}
|
|
18
|
-
if (typeof cli.checkDeployRuntime !== "function") return
|
|
29
|
+
if (typeof cli.checkDeployRuntime !== "function") return bail("the installed @guren/cli predates them; upgrade it");
|
|
19
30
|
let verdicts;
|
|
31
|
+
let app;
|
|
20
32
|
try {
|
|
21
|
-
verdicts = await cli.
|
|
33
|
+
if (target && typeof cli.inspectDeployTarget === "function") ({verdicts, app} = await cli.inspectDeployTarget(root, { target }));
|
|
34
|
+
else {
|
|
35
|
+
verdicts = await cli.checkDeployRuntime(root, { target });
|
|
36
|
+
if (target) app = unread("the installed @guren/cli predates inspectDeployTarget(); upgrade it");
|
|
37
|
+
}
|
|
22
38
|
} catch (error) {
|
|
23
|
-
return
|
|
39
|
+
return bail(`the scan failed (${describeError(error)})`);
|
|
24
40
|
}
|
|
25
41
|
const evidence = describeEvidence(label, verdicts);
|
|
26
42
|
if (evidence) console.log(evidence);
|
|
27
43
|
const lines = verdicts.filter((verdict) => verdict.status !== "pass").map((verdict) => `${label}: ${verdict.message}${verdict.fix ? ` ${verdict.fix}` : ""}`);
|
|
28
44
|
for (const line of lines) console.warn(line);
|
|
29
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
hazards: lines,
|
|
47
|
+
...app ? { app } : {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function unread(reason) {
|
|
51
|
+
return {
|
|
52
|
+
status: "unread",
|
|
53
|
+
reason
|
|
54
|
+
};
|
|
30
55
|
}
|
|
31
56
|
/** One line naming what each verdict was judged from, and why the source when the app could not be read. */
|
|
32
57
|
function describeEvidence(label, verdicts) {
|
|
33
58
|
const judged = [];
|
|
34
|
-
for (const { title, evidence } of verdicts) {
|
|
59
|
+
for (const { title, evidence, introspectedAs } of verdicts) {
|
|
35
60
|
if (evidence === void 0) return void 0;
|
|
36
|
-
judged.push(`${title} from ${EVIDENCE_LABELS[evidence]}`);
|
|
61
|
+
judged.push(`${title} from ${EVIDENCE_LABELS[evidence]}${introspectedAs ? ` as ${TARGET_LABELS[introspectedAs]} runs it` : ""}`);
|
|
37
62
|
}
|
|
38
63
|
if (judged.length === 0) return void 0;
|
|
39
64
|
const reasons = [...new Set(verdicts.flatMap((verdict) => verdict.evidenceReason ? [verdict.evidenceReason] : []))];
|
|
@@ -44,10 +69,12 @@ const EVIDENCE_LABELS = {
|
|
|
44
69
|
static: "source",
|
|
45
70
|
none: "nothing verifiable"
|
|
46
71
|
};
|
|
72
|
+
/** Matches `SERVERLESS_RUNTIME_LABELS` in @guren/server, which this module does not import. */
|
|
73
|
+
const TARGET_LABELS = { cloudflare: "Cloudflare Workers" };
|
|
47
74
|
function skipped(label, reason) {
|
|
48
75
|
const line = `${label}: deploy-runtime checks skipped — ${reason}. Run \`bunx guren doctor\` before deploying.`;
|
|
49
76
|
console.warn(line);
|
|
50
77
|
return [line];
|
|
51
78
|
}
|
|
52
79
|
//#endregion
|
|
53
|
-
export { reportDeployRuntimeHazards };
|
|
80
|
+
export { inspectDeployRuntime, reportDeployRuntimeHazards };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ALLOW_DESTRUCTIVE_ENV } from "@guren/orm/internal/migration-guard";
|
|
2
|
+
//#region src/internal/deploy-plan.d.ts
|
|
3
|
+
interface PendingMigrationVerdict {
|
|
4
|
+
/** `file:line: message (kind)` per statement no marker covers. */
|
|
5
|
+
unacknowledged: string[];
|
|
6
|
+
/** Migrations whose marker covers their findings, with its reason. */
|
|
7
|
+
acknowledged: Array<{
|
|
8
|
+
migration: string;
|
|
9
|
+
reason?: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Judges the pending migration folders under `migrationsFolder`, in the order they
|
|
14
|
+
* would apply. Throws when a file cannot be read: a skipped file would pass exactly
|
|
15
|
+
* the migration the guard could not judge.
|
|
16
|
+
*/
|
|
17
|
+
declare function judgePendingMigrations(migrationsFolder: string, pending: readonly string[], displayFolder: string): PendingMigrationVerdict;
|
|
18
|
+
type DeployEnvRequirement = {
|
|
19
|
+
status: 'loaded';
|
|
20
|
+
required: readonly string[];
|
|
21
|
+
} | {
|
|
22
|
+
status: 'absent';
|
|
23
|
+
} | {
|
|
24
|
+
status: 'unreadable';
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
/** Whether the app schedules tasks, read as `schedule:list` reads them; `unreadable` is never "none". */
|
|
28
|
+
type ScheduledTasks = {
|
|
29
|
+
status: 'none';
|
|
30
|
+
} |
|
|
31
|
+
/** `warnings` names registrars that threw while others registered tasks. */
|
|
32
|
+
{
|
|
33
|
+
status: 'loaded';
|
|
34
|
+
count: number;
|
|
35
|
+
warnings: string[];
|
|
36
|
+
} | {
|
|
37
|
+
status: 'unreadable';
|
|
38
|
+
message: string;
|
|
39
|
+
};
|
|
40
|
+
declare function readScheduledTasks(root: string): Promise<ScheduledTasks>;
|
|
41
|
+
/** The `config/env.ts` keys a production deploy must set, as the app's own schema decides. */
|
|
42
|
+
declare function readRequiredDeployEnv(root: string): Promise<DeployEnvRequirement>;
|
|
43
|
+
/** The keys a dotenv file assigns a non-blank value to, read the way Bun reads it; the values are never kept. */
|
|
44
|
+
declare function readEnvFileKeys(content: string): Promise<Set<string> | string>;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { ALLOW_DESTRUCTIVE_ENV, DeployEnvRequirement, PendingMigrationVerdict, ScheduledTasks, judgePendingMigrations, readEnvFileKeys, readRequiredDeployEnv, readScheduledTasks };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ALLOW_DESTRUCTIVE_ENV, formatDestructiveFinding, judgeMigrations, readMigrationSources } from "@guren/orm/internal/migration-guard";
|
|
2
|
+
//#region src/internal/deploy-plan.ts
|
|
3
|
+
/**
|
|
4
|
+
* What a deploy plugin's plan needs from the ORM and the CLI (RFC 0035 §5, §6),
|
|
5
|
+
* published as `@guren/core/internal/deploy-plan` so a plugin depends on core alone.
|
|
6
|
+
* The destructive-migration judgement is the ORM's own (RFC 0034). The CLI is
|
|
7
|
+
* reached lazily, as in `deploy-check`, and a CLI that cannot answer is reported
|
|
8
|
+
* as such, never as "nothing required".
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Judges the pending migration folders under `migrationsFolder`, in the order they
|
|
12
|
+
* would apply. Throws when a file cannot be read: a skipped file would pass exactly
|
|
13
|
+
* the migration the guard could not judge.
|
|
14
|
+
*/
|
|
15
|
+
function judgePendingMigrations(migrationsFolder, pending, displayFolder) {
|
|
16
|
+
const report = judgeMigrations(readMigrationSources(migrationsFolder, pending, displayFolder));
|
|
17
|
+
return {
|
|
18
|
+
unacknowledged: report.unacknowledged.map(formatDestructiveFinding),
|
|
19
|
+
acknowledged: report.acknowledged.map(({ migration, reason }) => ({
|
|
20
|
+
migration,
|
|
21
|
+
...reason ? { reason } : {}
|
|
22
|
+
}))
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async function readScheduledTasks(root) {
|
|
26
|
+
const cli = await loadCli();
|
|
27
|
+
if (typeof cli === "string") return {
|
|
28
|
+
status: "unreadable",
|
|
29
|
+
message: cli
|
|
30
|
+
};
|
|
31
|
+
if (typeof cli.loadScheduleKernel !== "function") return {
|
|
32
|
+
status: "unreadable",
|
|
33
|
+
message: "the installed @guren/cli predates loadScheduleKernel; upgrade it"
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
const kernel = await cli.loadScheduleKernel({ appRoot: root });
|
|
37
|
+
if (kernel.kind === "missing") return { status: "none" };
|
|
38
|
+
if (kernel.kind === "loaded") return {
|
|
39
|
+
status: "loaded",
|
|
40
|
+
count: kernel.tasks?.length ?? 0,
|
|
41
|
+
warnings: kernel.warnings ?? []
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
status: "unreadable",
|
|
45
|
+
message: `${kernel.path ?? "the schedule kernel"} could not be read (${kernel.kind}${kernel.reasons?.length ? `: ${kernel.reasons.join("; ")}` : ""})`
|
|
46
|
+
};
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return {
|
|
49
|
+
status: "unreadable",
|
|
50
|
+
message: error instanceof Error ? error.message : String(error)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
let cliLoad;
|
|
55
|
+
/** Loaded once per process: both readers below run in one plan. */
|
|
56
|
+
function loadCli() {
|
|
57
|
+
cliLoad ??= import("@guren/cli").then((cli) => cli, (error) => `@guren/cli could not be loaded (${error instanceof Error ? error.message : String(error)})`);
|
|
58
|
+
return cliLoad;
|
|
59
|
+
}
|
|
60
|
+
/** The `config/env.ts` keys a production deploy must set, as the app's own schema decides. */
|
|
61
|
+
async function readRequiredDeployEnv(root) {
|
|
62
|
+
const cli = await loadCli();
|
|
63
|
+
if (typeof cli === "string") return {
|
|
64
|
+
status: "unreadable",
|
|
65
|
+
message: cli
|
|
66
|
+
};
|
|
67
|
+
if (typeof cli.requiredDeployEnv !== "function") return {
|
|
68
|
+
status: "unreadable",
|
|
69
|
+
message: "the installed @guren/cli predates the deploy env check; upgrade it"
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
return await cli.requiredDeployEnv(root);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
status: "unreadable",
|
|
76
|
+
message: error instanceof Error ? error.message : String(error)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** The keys a dotenv file assigns a non-blank value to, read the way Bun reads it; the values are never kept. */
|
|
81
|
+
async function readEnvFileKeys(content) {
|
|
82
|
+
const cli = await loadCli();
|
|
83
|
+
if (typeof cli === "string") return cli;
|
|
84
|
+
if (typeof cli.assignedEnvKeys !== "function") return "the installed @guren/cli predates assignedEnvKeys; upgrade it";
|
|
85
|
+
return cli.assignedEnvKeys(content);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { ALLOW_DESTRUCTIVE_ENV, judgePendingMigrations, readEnvFileKeys, readRequiredDeployEnv, readScheduledTasks };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.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",
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
"types": "./dist/internal/deploy-check.d.ts",
|
|
74
74
|
"default": "./dist/internal/deploy-check.js"
|
|
75
75
|
},
|
|
76
|
+
"./internal/deploy-plan": {
|
|
77
|
+
"types": "./dist/internal/deploy-plan.d.ts",
|
|
78
|
+
"default": "./dist/internal/deploy-plan.js"
|
|
79
|
+
},
|
|
76
80
|
"./internal/route-path": {
|
|
77
81
|
"types": "./dist/internal/route-path.d.ts",
|
|
78
82
|
"default": "./dist/internal/route-path.js"
|
|
@@ -104,9 +108,9 @@
|
|
|
104
108
|
"typecheck": "tsc --noEmit"
|
|
105
109
|
},
|
|
106
110
|
"dependencies": {
|
|
107
|
-
"@guren/cli": "^2.
|
|
108
|
-
"@guren/orm": "^2.
|
|
109
|
-
"@guren/server": "^2.
|
|
111
|
+
"@guren/cli": "^2.32.0",
|
|
112
|
+
"@guren/orm": "^2.15.0",
|
|
113
|
+
"@guren/server": "^2.31.0"
|
|
110
114
|
},
|
|
111
115
|
"devDependencies": {
|
|
112
116
|
"@types/node": "^20.14.10",
|