@guren/core 1.20.1 → 1.21.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 +6 -0
- package/dist/index.js +25 -0
- package/dist/internal/deploy-build.d.ts +62 -13
- package/dist/internal/deploy-build.js +174 -14
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -399,6 +399,8 @@ declare module '@guren/server' {
|
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
interface ConfigureAttachmentsOptions {
|
|
402
|
+
/** Shared exclusion for hasOne writes across processes; run callback while holding the key's lock. */
|
|
403
|
+
withCollectionLock?: <T>(key: string, callback: () => Promise<T>) => Promise<T>;
|
|
402
404
|
/**
|
|
403
405
|
* The app's Drizzle `attachments` table. Column property names must match the
|
|
404
406
|
* documented contract: `id`, `attachableType`, `attachableId`, `collection`,
|
|
@@ -554,6 +556,8 @@ type QueueDispatcher = Pick<QueueManager, 'driver' | 'dispatch'>;
|
|
|
554
556
|
type JobDispatcher = (payload: GenerateVariantsPayload, queue: QueueDispatcher | undefined) => Promise<unknown>;
|
|
555
557
|
declare class AttachmentEngine {
|
|
556
558
|
readonly model: typeof Model$1;
|
|
559
|
+
private readonly collectionLocks;
|
|
560
|
+
private readonly sharedCollectionLock;
|
|
557
561
|
private readonly storageFactory;
|
|
558
562
|
private container?;
|
|
559
563
|
private readonly defaultDisk;
|
|
@@ -576,7 +580,9 @@ declare class AttachmentEngine {
|
|
|
576
580
|
/** Wired by `configureAttachments()`, so this module never imports the job. */
|
|
577
581
|
setJobDispatcher(dispatch: JobDispatcher): void;
|
|
578
582
|
private storage;
|
|
583
|
+
private withCollectionWrite;
|
|
579
584
|
attach(model: typeof Model$1, declaration: AttachmentsDeclaration, recordId: string | number, collection: string, source: AttachmentSource, options?: AttachOptions): Promise<AttachmentRecord>;
|
|
585
|
+
private attachUnlocked;
|
|
580
586
|
detach(model: typeof Model$1, declaration: AttachmentsDeclaration, recordId: string | number, collection: string, attachmentId?: string): Promise<void>;
|
|
581
587
|
withAttachments(model: typeof Model$1, declaration: AttachmentsDeclaration, records: readonly PlainObject$1[], names: readonly string[]): Promise<PlainObject$1[]>;
|
|
582
588
|
attachmentUrl(model: typeof Model$1, declaration: AttachmentsDeclaration, recordOrId: PlainObject$1 | string | number, collection: string, options?: AttachmentUrlOptions & {
|
package/dist/index.js
CHANGED
|
@@ -730,8 +730,11 @@ function unavailableContainer() {
|
|
|
730
730
|
has: unavailable
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
|
+
const collectionWrites = /* @__PURE__ */ new WeakMap();
|
|
733
734
|
var AttachmentEngine = class {
|
|
734
735
|
model;
|
|
736
|
+
collectionLocks;
|
|
737
|
+
sharedCollectionLock;
|
|
735
738
|
storageFactory;
|
|
736
739
|
container;
|
|
737
740
|
defaultDisk;
|
|
@@ -746,6 +749,10 @@ var AttachmentEngine = class {
|
|
|
746
749
|
dispatchJob = null;
|
|
747
750
|
constructor(options) {
|
|
748
751
|
const table = options.table;
|
|
752
|
+
const locks = collectionWrites.get(table) ?? /* @__PURE__ */ new Map();
|
|
753
|
+
collectionWrites.set(table, locks);
|
|
754
|
+
this.collectionLocks = locks;
|
|
755
|
+
this.sharedCollectionLock = options.withCollectionLock ?? ((_key, callback) => callback());
|
|
749
756
|
this.model = class AttachmentModel extends Model$1 {
|
|
750
757
|
static table = table;
|
|
751
758
|
};
|
|
@@ -779,8 +786,26 @@ var AttachmentEngine = class {
|
|
|
779
786
|
storage() {
|
|
780
787
|
return this.storageFactory(this.container ?? ambientContainer() ?? unavailableContainer());
|
|
781
788
|
}
|
|
789
|
+
async withCollectionWrite(model, recordId, collection, callback) {
|
|
790
|
+
const key = JSON.stringify([
|
|
791
|
+
model.name,
|
|
792
|
+
String(recordId),
|
|
793
|
+
collection
|
|
794
|
+
]);
|
|
795
|
+
const operation = (this.collectionLocks.get(key) ?? Promise.resolve()).catch(() => void 0).then(() => this.sharedCollectionLock(key, callback));
|
|
796
|
+
this.collectionLocks.set(key, operation);
|
|
797
|
+
try {
|
|
798
|
+
return await operation;
|
|
799
|
+
} finally {
|
|
800
|
+
if (this.collectionLocks.get(key) === operation) this.collectionLocks.delete(key);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
782
803
|
async attach(model, declaration, recordId, collection, source, options = {}) {
|
|
783
804
|
const spec = this.specFor(model, declaration, collection);
|
|
805
|
+
const write = () => this.attachUnlocked(model, spec, recordId, collection, source, options);
|
|
806
|
+
return spec.kind === "one" ? this.withCollectionWrite(model, recordId, collection, write) : write();
|
|
807
|
+
}
|
|
808
|
+
async attachUnlocked(model, spec, recordId, collection, source, options) {
|
|
784
809
|
const normalized = await normalizeSource(source, options.name);
|
|
785
810
|
const queued = options.queued === true;
|
|
786
811
|
if (queued) this.queueManager();
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
+
import { AGENTS_CONFIG_FILE } from "@guren/server/internal/app-conventions";
|
|
1
2
|
//#region src/internal/deploy-build.d.ts
|
|
2
3
|
type PathLike = string | URL;
|
|
3
|
-
/**
|
|
4
|
-
* The agent registry (RFC 0017 §3), at a path neither side may choose. Shared
|
|
5
|
-
* rather than spelled twice: `guren check` reads it as source and a deploy build
|
|
6
|
-
* reads it to generate the worker's Durable Object exports, so a second spelling
|
|
7
|
-
* is a deploy exporting no agents while the check calls them registered.
|
|
8
|
-
*/
|
|
9
|
-
declare const AGENTS_CONFIG_FILE = "config/agents.ts";
|
|
10
4
|
type ManifestEntry = {
|
|
11
5
|
file?: string;
|
|
12
6
|
css?: string[];
|
|
@@ -221,10 +215,10 @@ interface SqlClientModule extends DevOnlyModule {
|
|
|
221
215
|
}
|
|
222
216
|
/**
|
|
223
217
|
* Client libraries the Postgres, MySQL and Aurora Data API factories reach for.
|
|
224
|
-
* Apart from `DEV_ONLY_MODULES
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
218
|
+
* Apart from `DEV_ONLY_MODULES`: unreachable on Workers (D1 only), load-bearing on
|
|
219
|
+
* Lambda/Vercel, which stub only undeclared dialects (`unusedSqlClients`). Stub the
|
|
220
|
+
* client *and* drizzle's entry importing it, or a D1 app fails to resolve `postgres`.
|
|
221
|
+
* `mysql2/promise` lists its whole public API, not just drizzle's `createPool` (#507).
|
|
228
222
|
*/
|
|
229
223
|
declare const SQL_CLIENT_MODULES: readonly [{
|
|
230
224
|
readonly specifier: 'postgres';
|
|
@@ -242,7 +236,7 @@ declare const SQL_CLIENT_MODULES: readonly [{
|
|
|
242
236
|
readonly specifier: 'mysql2/promise';
|
|
243
237
|
readonly kind: 'sql-driver';
|
|
244
238
|
readonly dialect: 'mysql';
|
|
245
|
-
readonly exportNames: readonly ["createPool"];
|
|
239
|
+
readonly exportNames: readonly ["createConnection", "createPool", "createPoolCluster", "escape", "escapeId", "format", "raw", "Connection", "PoolConnection", "PromisePool", "PromiseConnection", "PromisePoolConnection", "Types", "Charsets", "CharsetToEncoding", "setMaxParserCache", "clearParserCache", "TypedParameter"];
|
|
246
240
|
readonly importedBy: 'packages/orm/src';
|
|
247
241
|
}, {
|
|
248
242
|
readonly specifier: '@aws-sdk/client-rds-data';
|
|
@@ -310,5 +304,60 @@ type DevOnlySpecifier = (typeof DEV_ONLY_MODULES)[number]['specifier'];
|
|
|
310
304
|
* @param message Platform-specific explanation, including the replacement API.
|
|
311
305
|
*/
|
|
312
306
|
declare function renderDevOnlyStub(module: Pick<DevOnlyModule, 'exportNames'>, message: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* `Bun.build` minify options for a deploy bundle. Jobs, events, notifications and
|
|
309
|
+
* agents are stored under their class name, so identifiers stay unmangled, and
|
|
310
|
+
* `keepNames` restores the name syntax minification drops from a named class or
|
|
311
|
+
* function expression. It never replaces `identifiers: false`: on Bun 1.3.14 and
|
|
312
|
+
* 1.4.2 mangling wins. Neither restores a cross-module rename (`renamedNameKeyedClasses`).
|
|
313
|
+
*/
|
|
314
|
+
declare const BUN_DEPLOY_MINIFY: {
|
|
315
|
+
readonly whitespace: true;
|
|
316
|
+
readonly syntax: true;
|
|
317
|
+
readonly identifiers: false;
|
|
318
|
+
readonly keepNames: true;
|
|
319
|
+
};
|
|
320
|
+
type NameKeyedKind = 'record' | 'model';
|
|
321
|
+
interface RenamedNameKeyedClass {
|
|
322
|
+
/** The name in source, which `bun run` reports. */
|
|
323
|
+
readonly name: string;
|
|
324
|
+
/** The name the bundle declares instead, and so the class's runtime `.name`. */
|
|
325
|
+
readonly bundledAs: string;
|
|
326
|
+
/** `record`: a job, event, notification or agent, which can pin its name. */
|
|
327
|
+
readonly kind: NameKeyedKind;
|
|
328
|
+
/** The app files declaring such a class called `name`. */
|
|
329
|
+
readonly files: readonly string[];
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* App models and unpinned records the bundle renamed to `<name><n>`, which happens when
|
|
333
|
+
* another module declares the same top-level name. A declaration counts only when the
|
|
334
|
+
* numbered class extends its base, so a renamed dependency class is not the app's. Read
|
|
335
|
+
* with regexes, since this module imports only builtins: a base built by an expression
|
|
336
|
+
* the patterns above do not match (a mixin they do not name) is missed, not guessed.
|
|
337
|
+
*/
|
|
338
|
+
declare function renamedNameKeyedClasses(bundle: string, sources: ReadonlyArray<{
|
|
339
|
+
readonly file: string;
|
|
340
|
+
readonly text: string;
|
|
341
|
+
}>): RenamedNameKeyedClass[];
|
|
342
|
+
/** The part of a `Bun.build` result the reporter reads, structural so this module needs no bun-types. */
|
|
343
|
+
interface BundleResultLike {
|
|
344
|
+
readonly outputs: ReadonlyArray<{
|
|
345
|
+
readonly kind: string;
|
|
346
|
+
text(): Promise<string>;
|
|
347
|
+
}>;
|
|
348
|
+
readonly metafile?: {
|
|
349
|
+
readonly inputs: Readonly<Record<string, unknown>>;
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Warns about each `renamedNameKeyedClasses` result of a `Bun.build` run with
|
|
354
|
+
* `metafile: true`, whose input paths (relative to the cwd) are the sources read.
|
|
355
|
+
* Module dependencies are skipped, and so is an input that will not read, such as a
|
|
356
|
+
* plugin namespace.
|
|
357
|
+
*/
|
|
358
|
+
declare function reportRenamedNameKeyedClasses(result: BundleResultLike, options: {
|
|
359
|
+
root: string;
|
|
360
|
+
label: string;
|
|
361
|
+
}): Promise<void>;
|
|
313
362
|
//#endregion
|
|
314
|
-
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 };
|
|
363
|
+
export { AGENTS_CONFIG_FILE, BUN_DEPLOY_MINIFY, BundleResultLike, 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, RenamedNameKeyedClass, SQL_CLIENT_MODULES, SqlClientModule, SqlClientSpecifier, UnusedSqlClient, appUsesMcpPlugin, assertOutputDirOutsideRoot, bundledRuntimeEnv, clientManifestJson, detectDatabaseDialects, importSpecifier, parseDatabaseDialects, readManifest, removeShadowingIndex, renamedNameKeyedClasses, renderDevOnlyStub, reportRenamedNameKeyedClasses, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, translationCatalogJson, unusedSqlClients };
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { AGENTS_CONFIG_FILE } from "@guren/server/internal/app-conventions";
|
|
4
5
|
//#region src/internal/deploy-build.ts
|
|
5
6
|
/**
|
|
6
7
|
* Build-time helpers shared by the deploy plugins (cloudflare, lambda, vercel).
|
|
7
8
|
* Internal (`contributing/api-stability.md`): deep import only, never re-exported
|
|
8
|
-
* from `@guren/core`. Imports only
|
|
9
|
+
* from `@guren/core`. Imports only builtins and shared constants so a plugin build never drags
|
|
9
10
|
* the runtime in; `deploy-build.test.ts` asserts that of the built artifact.
|
|
10
11
|
* Platform decisions (messages, stub delivery, whether a missing `build` script is
|
|
11
12
|
* fatal, SSR renderer verification) stay per-plugin. A helper that *relates* two
|
|
12
13
|
* paths canonicalizes both first; one that reads or writes a single path does not.
|
|
13
14
|
*/
|
|
14
|
-
/**
|
|
15
|
-
* The agent registry (RFC 0017 §3), at a path neither side may choose. Shared
|
|
16
|
-
* rather than spelled twice: `guren check` reads it as source and a deploy build
|
|
17
|
-
* reads it to generate the worker's Durable Object exports, so a second spelling
|
|
18
|
-
* is a deploy exporting no agents while the check calls them registered.
|
|
19
|
-
*/
|
|
20
|
-
const AGENTS_CONFIG_FILE = "config/agents.ts";
|
|
21
15
|
function resolvePathLike(value) {
|
|
22
16
|
return value instanceof URL ? fileURLToPath(value) : resolve(String(value));
|
|
23
17
|
}
|
|
@@ -357,10 +351,10 @@ const DATABASE_FACTORIES = {
|
|
|
357
351
|
};
|
|
358
352
|
/**
|
|
359
353
|
* Client libraries the Postgres, MySQL and Aurora Data API factories reach for.
|
|
360
|
-
* Apart from `DEV_ONLY_MODULES
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
354
|
+
* Apart from `DEV_ONLY_MODULES`: unreachable on Workers (D1 only), load-bearing on
|
|
355
|
+
* Lambda/Vercel, which stub only undeclared dialects (`unusedSqlClients`). Stub the
|
|
356
|
+
* client *and* drizzle's entry importing it, or a D1 app fails to resolve `postgres`.
|
|
357
|
+
* `mysql2/promise` lists its whole public API, not just drizzle's `createPool` (#507).
|
|
364
358
|
*/
|
|
365
359
|
const SQL_CLIENT_MODULES = [
|
|
366
360
|
{
|
|
@@ -381,7 +375,26 @@ const SQL_CLIENT_MODULES = [
|
|
|
381
375
|
specifier: "mysql2/promise",
|
|
382
376
|
kind: "sql-driver",
|
|
383
377
|
dialect: "mysql",
|
|
384
|
-
exportNames: [
|
|
378
|
+
exportNames: [
|
|
379
|
+
"createConnection",
|
|
380
|
+
"createPool",
|
|
381
|
+
"createPoolCluster",
|
|
382
|
+
"escape",
|
|
383
|
+
"escapeId",
|
|
384
|
+
"format",
|
|
385
|
+
"raw",
|
|
386
|
+
"Connection",
|
|
387
|
+
"PoolConnection",
|
|
388
|
+
"PromisePool",
|
|
389
|
+
"PromiseConnection",
|
|
390
|
+
"PromisePoolConnection",
|
|
391
|
+
"Types",
|
|
392
|
+
"Charsets",
|
|
393
|
+
"CharsetToEncoding",
|
|
394
|
+
"setMaxParserCache",
|
|
395
|
+
"clearParserCache",
|
|
396
|
+
"TypedParameter"
|
|
397
|
+
],
|
|
385
398
|
importedBy: "packages/orm/src"
|
|
386
399
|
},
|
|
387
400
|
{
|
|
@@ -494,5 +507,152 @@ function renderDevOnlyStub(module, message) {
|
|
|
494
507
|
const named = module.exportNames.length > 0 ? `, { ${module.exportNames.join(", ")} }` : "";
|
|
495
508
|
return `// ${comment}\n${throwing}\n${`function unavailable() { ${error} }`}\nexport default Object.assign(unavailable${named})\n`;
|
|
496
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* `Bun.build` minify options for a deploy bundle. Jobs, events, notifications and
|
|
512
|
+
* agents are stored under their class name, so identifiers stay unmangled, and
|
|
513
|
+
* `keepNames` restores the name syntax minification drops from a named class or
|
|
514
|
+
* function expression. It never replaces `identifiers: false`: on Bun 1.3.14 and
|
|
515
|
+
* 1.4.2 mangling wins. Neither restores a cross-module rename (`renamedNameKeyedClasses`).
|
|
516
|
+
*/
|
|
517
|
+
const BUN_DEPLOY_MINIFY = {
|
|
518
|
+
whitespace: true,
|
|
519
|
+
syntax: true,
|
|
520
|
+
identifiers: false,
|
|
521
|
+
keepNames: true
|
|
522
|
+
};
|
|
523
|
+
/**
|
|
524
|
+
* Framework bases whose subclasses are stored under their class name. A record kind
|
|
525
|
+
* can pin that name; a model cannot: attachments and `morphMany` write `model.name`
|
|
526
|
+
* while `Model.morphMap` finds the model by its source name, so a rename splits them.
|
|
527
|
+
*/
|
|
528
|
+
const NAME_KEYED_BASES = new Map([...[
|
|
529
|
+
"Job",
|
|
530
|
+
"Event",
|
|
531
|
+
"Notification",
|
|
532
|
+
"Agent"
|
|
533
|
+
].map((base) => [base, "record"]), ...[
|
|
534
|
+
"Model",
|
|
535
|
+
"AuthenticatableModel",
|
|
536
|
+
"defineModel",
|
|
537
|
+
"Attachable",
|
|
538
|
+
"SoftDeletes"
|
|
539
|
+
].map((base) => [base, "model"])]);
|
|
540
|
+
const NAME_PIN = /\bstatic\s+(?:override\s+)?(?:jobName|eventName|agentName)\b|\bget\s+type\s*\(/;
|
|
541
|
+
const HERITAGE = String.raw`\s+extends\s+(?:[A-Za-z_$][\w$]*\.)*([A-Za-z_$][\w$]*)`;
|
|
542
|
+
const SOURCE_CLASS = new RegExp(String.raw`^[ \t]*(?:export[ \t]+(?:default[ \t]+)?)?(?:abstract[ \t]+)?class[ \t]+([A-Za-z_$][\w$]*)(?:[ \t]*<[^{>\n]*>)?(?:${HERITAGE})?`, "gm");
|
|
543
|
+
const BUNDLED_CLASS = new RegExp(String.raw`(?:^|[^\w$.])class\s+([A-Za-z_$][\w$]*)(?:${HERITAGE})?`, "g");
|
|
544
|
+
const NAMED_IMPORTS = /import\s+(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^{}]*)\}\s*from\s*['"]([^'"]+)['"]/g;
|
|
545
|
+
const IMPORT_SPECIFIER = /^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/;
|
|
546
|
+
/**
|
|
547
|
+
* App models and unpinned records the bundle renamed to `<name><n>`, which happens when
|
|
548
|
+
* another module declares the same top-level name. A declaration counts only when the
|
|
549
|
+
* numbered class extends its base, so a renamed dependency class is not the app's. Read
|
|
550
|
+
* with regexes, since this module imports only builtins: a base built by an expression
|
|
551
|
+
* the patterns above do not match (a mixin they do not name) is missed, not guessed.
|
|
552
|
+
*/
|
|
553
|
+
function renamedNameKeyedClasses(bundle, sources) {
|
|
554
|
+
const declared = /* @__PURE__ */ new Map();
|
|
555
|
+
for (const { file, text } of sources) {
|
|
556
|
+
const imports = namedImports(text);
|
|
557
|
+
const pinned = NAME_PIN.test(text);
|
|
558
|
+
for (const [, name, local] of text.matchAll(SOURCE_CLASS)) {
|
|
559
|
+
const imported = local === void 0 ? void 0 : imports.get(local);
|
|
560
|
+
const entries = declared.get(name) ?? [];
|
|
561
|
+
entries.push({
|
|
562
|
+
file,
|
|
563
|
+
base: imported?.name ?? local,
|
|
564
|
+
fromFramework: imported?.fromFramework ?? false,
|
|
565
|
+
pinned
|
|
566
|
+
});
|
|
567
|
+
declared.set(name, entries);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const kindOf = (entry, seen = /* @__PURE__ */ new Set()) => {
|
|
571
|
+
if (entry.base === void 0) return void 0;
|
|
572
|
+
const own = entry.fromFramework ? void 0 : declared.get(entry.base);
|
|
573
|
+
if (own === void 0) return NAME_KEYED_BASES.get(entry.base);
|
|
574
|
+
if (seen.has(entry.base)) return void 0;
|
|
575
|
+
seen.add(entry.base);
|
|
576
|
+
for (const parent of own) {
|
|
577
|
+
const inherited = kindOf(parent, seen);
|
|
578
|
+
if (inherited !== void 0) return inherited;
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
const bundledBases = /* @__PURE__ */ new Map();
|
|
582
|
+
for (const [, bundledAs, base] of bundle.matchAll(BUNDLED_CLASS)) {
|
|
583
|
+
if (base === void 0) continue;
|
|
584
|
+
const bases = bundledBases.get(bundledAs) ?? /* @__PURE__ */ new Set();
|
|
585
|
+
bases.add(stem(base));
|
|
586
|
+
bundledBases.set(bundledAs, bases);
|
|
587
|
+
}
|
|
588
|
+
const renamed = [];
|
|
589
|
+
for (const [bundledAs, bases] of bundledBases) {
|
|
590
|
+
const name = withoutNumericSuffix(bundledAs);
|
|
591
|
+
if (name === void 0 || declared.has(bundledAs)) continue;
|
|
592
|
+
const files = /* @__PURE__ */ new Map();
|
|
593
|
+
for (const entry of declared.get(name) ?? []) {
|
|
594
|
+
if (entry.base === void 0 || !bases.has(stem(entry.base))) continue;
|
|
595
|
+
const kind = kindOf(entry);
|
|
596
|
+
if (kind === void 0 || kind === "record" && entry.pinned) continue;
|
|
597
|
+
files.set(kind, [...files.get(kind) ?? [], entry.file]);
|
|
598
|
+
}
|
|
599
|
+
for (const [kind, list] of files) renamed.push({
|
|
600
|
+
name,
|
|
601
|
+
bundledAs,
|
|
602
|
+
kind,
|
|
603
|
+
files: list.sort()
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return renamed;
|
|
607
|
+
}
|
|
608
|
+
function withoutNumericSuffix(name) {
|
|
609
|
+
let end = name.length;
|
|
610
|
+
while (end > 0 && name.charCodeAt(end - 1) >= 48 && name.charCodeAt(end - 1) <= 57) end--;
|
|
611
|
+
return end > 0 && end < name.length ? name.slice(0, end) : void 0;
|
|
612
|
+
}
|
|
613
|
+
function stem(name) {
|
|
614
|
+
return withoutNumericSuffix(name) ?? name;
|
|
615
|
+
}
|
|
616
|
+
/** Local name → exported name, for a file's `import { A as B } from '…'` statements. */
|
|
617
|
+
function namedImports(text) {
|
|
618
|
+
const imports = /* @__PURE__ */ new Map();
|
|
619
|
+
for (const [, specifiers, from] of text.matchAll(NAMED_IMPORTS)) for (const specifier of specifiers.split(",")) {
|
|
620
|
+
const match = IMPORT_SPECIFIER.exec(specifier.trim());
|
|
621
|
+
if (match) imports.set(match[2] ?? match[1], {
|
|
622
|
+
name: match[1],
|
|
623
|
+
fromFramework: from.startsWith("@guren/")
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
return imports;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Warns about each `renamedNameKeyedClasses` result of a `Bun.build` run with
|
|
630
|
+
* `metafile: true`, whose input paths (relative to the cwd) are the sources read.
|
|
631
|
+
* Module dependencies are skipped, and so is an input that will not read, such as a
|
|
632
|
+
* plugin namespace.
|
|
633
|
+
*/
|
|
634
|
+
async function reportRenamedNameKeyedClasses(result, options) {
|
|
635
|
+
const code = result.outputs.filter((output) => output.kind === "entry-point" || output.kind === "chunk");
|
|
636
|
+
const bundle = (await Promise.all(code.map((output) => output.text()))).join("\n");
|
|
637
|
+
const root = realpathOfNearestExisting(options.root);
|
|
638
|
+
const sources = [];
|
|
639
|
+
for (const input of Object.keys(result.metafile?.inputs ?? {})) {
|
|
640
|
+
if (/(?:^|[\\/])node_modules[\\/]/.test(input)) continue;
|
|
641
|
+
try {
|
|
642
|
+
const path = realpathSync(resolve(input));
|
|
643
|
+
sources.push({
|
|
644
|
+
file: relative(root, path),
|
|
645
|
+
text: readFileSync(path, "utf8")
|
|
646
|
+
});
|
|
647
|
+
} catch {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
for (const { name, bundledAs, kind, files } of renamedNameKeyedClasses(bundle, sources)) {
|
|
652
|
+
const declares = `${files.join(", ")} ${files.length === 1 ? "declares" : "declare"}`;
|
|
653
|
+
const found = kind === "record" ? `${declares} a job, event, notification or agent named ${name}, which is stored under its class name: rename it, or pin \`static jobName\`, \`static eventName\`, \`get type()\` or \`static agentName\`.` : `${declares} a model named ${name}. Its attachments and polymorphic relations, if it has any, are stored as ${bundledAs} while \`Model.morphMap\` looks it up as ${name}: a model has no name to pin, so rename the class (rows already stored as ${bundledAs} need updating).`;
|
|
654
|
+
console.warn(`${options.label}: the bundle names a class ${name} as ${bundledAs}, because another module declares ${name} too and import order picks which one keeps it. ${found}`);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
497
657
|
//#endregion
|
|
498
|
-
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 };
|
|
658
|
+
export { AGENTS_CONFIG_FILE, BUN_DEPLOY_MINIFY, 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, renamedNameKeyedClasses, renderDevOnlyStub, reportRenamedNameKeyedClasses, resetOutputDir, resolveClientAssetEnv, resolvePathLike, resolveSsrEntryFile, ssrRuntimePaths, stageStaticAssets, stubbableDevOnlyModules, translationCatalogJson, unusedSqlClients };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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.
|
|
108
|
-
"@guren/orm": "^2.
|
|
109
|
-
"@guren/server": "^2.
|
|
107
|
+
"@guren/cli": "^2.27.0",
|
|
108
|
+
"@guren/orm": "^2.12.0",
|
|
109
|
+
"@guren/server": "^2.26.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/node": "^20.14.10",
|