@gravito/pulse 1.0.1 → 2.1.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.
Files changed (2) hide show
  1. package/dist/index.js +973 -102
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7153,6 +7153,59 @@ var init_src = __esm(() => {
7153
7153
  init_dist();
7154
7154
  });
7155
7155
 
7156
+ // ../atlas/src/errors/index.ts
7157
+ var DatabaseError, ConstraintViolationError, UniqueConstraintError, ForeignKeyConstraintError, NotNullConstraintError, TableNotFoundError, ConnectionError;
7158
+ var init_errors = __esm(() => {
7159
+ DatabaseError = class DatabaseError extends Error {
7160
+ originalError;
7161
+ query;
7162
+ bindings;
7163
+ constructor(message, originalError, query, bindings) {
7164
+ super(message);
7165
+ this.name = "DatabaseError";
7166
+ this.originalError = originalError;
7167
+ this.query = query;
7168
+ this.bindings = bindings;
7169
+ }
7170
+ };
7171
+ ConstraintViolationError = class ConstraintViolationError extends DatabaseError {
7172
+ constructor(message, originalError, query, bindings) {
7173
+ super(message, originalError, query, bindings);
7174
+ this.name = "ConstraintViolationError";
7175
+ }
7176
+ };
7177
+ UniqueConstraintError = class UniqueConstraintError extends ConstraintViolationError {
7178
+ constructor(message, originalError, query, bindings) {
7179
+ super(message, originalError, query, bindings);
7180
+ this.name = "UniqueConstraintError";
7181
+ }
7182
+ };
7183
+ ForeignKeyConstraintError = class ForeignKeyConstraintError extends ConstraintViolationError {
7184
+ constructor(message, originalError, query, bindings) {
7185
+ super(message, originalError, query, bindings);
7186
+ this.name = "ForeignKeyConstraintError";
7187
+ }
7188
+ };
7189
+ NotNullConstraintError = class NotNullConstraintError extends ConstraintViolationError {
7190
+ constructor(message, originalError, query, bindings) {
7191
+ super(message, originalError, query, bindings);
7192
+ this.name = "NotNullConstraintError";
7193
+ }
7194
+ };
7195
+ TableNotFoundError = class TableNotFoundError extends DatabaseError {
7196
+ constructor(message, originalError, query, bindings) {
7197
+ super(message, originalError, query, bindings);
7198
+ this.name = "TableNotFoundError";
7199
+ }
7200
+ };
7201
+ ConnectionError = class ConnectionError extends DatabaseError {
7202
+ constructor(message, originalError) {
7203
+ super(message, originalError);
7204
+ this.name = "ConnectionError";
7205
+ }
7206
+ };
7207
+ });
7208
+
7156
7209
  // ../../node_modules/.bun/bson@6.10.4/node_modules/bson/lib/bson.cjs
7157
7210
  var require_bson = __commonJS((exports) => {
7158
7211
  var TypedArrayPrototypeGetSymbolToStringTag = (() => {
@@ -40473,71 +40526,20 @@ var require_lib4 = __commonJS((exports) => {
40473
40526
  } });
40474
40527
  });
40475
40528
 
40476
- // ../atlas/src/errors/index.ts
40477
- var DatabaseError, ConstraintViolationError, UniqueConstraintError, ForeignKeyConstraintError, NotNullConstraintError, TableNotFoundError, ConnectionError;
40478
- var init_errors = __esm(() => {
40479
- DatabaseError = class DatabaseError extends Error {
40480
- originalError;
40481
- query;
40482
- bindings;
40483
- constructor(message, originalError, query, bindings) {
40484
- super(message);
40485
- this.name = "DatabaseError";
40486
- this.originalError = originalError;
40487
- this.query = query;
40488
- this.bindings = bindings;
40489
- }
40490
- };
40491
- ConstraintViolationError = class ConstraintViolationError extends DatabaseError {
40492
- constructor(message, originalError, query, bindings) {
40493
- super(message, originalError, query, bindings);
40494
- this.name = "ConstraintViolationError";
40495
- }
40496
- };
40497
- UniqueConstraintError = class UniqueConstraintError extends ConstraintViolationError {
40498
- constructor(message, originalError, query, bindings) {
40499
- super(message, originalError, query, bindings);
40500
- this.name = "UniqueConstraintError";
40501
- }
40502
- };
40503
- ForeignKeyConstraintError = class ForeignKeyConstraintError extends ConstraintViolationError {
40504
- constructor(message, originalError, query, bindings) {
40505
- super(message, originalError, query, bindings);
40506
- this.name = "ForeignKeyConstraintError";
40507
- }
40508
- };
40509
- NotNullConstraintError = class NotNullConstraintError extends ConstraintViolationError {
40510
- constructor(message, originalError, query, bindings) {
40511
- super(message, originalError, query, bindings);
40512
- this.name = "NotNullConstraintError";
40513
- }
40514
- };
40515
- TableNotFoundError = class TableNotFoundError extends DatabaseError {
40516
- constructor(message, originalError, query, bindings) {
40517
- super(message, originalError, query, bindings);
40518
- this.name = "TableNotFoundError";
40519
- }
40520
- };
40521
- ConnectionError = class ConnectionError extends DatabaseError {
40522
- constructor(message, originalError) {
40523
- super(message, originalError);
40524
- this.name = "ConnectionError";
40525
- }
40526
- };
40527
- });
40528
-
40529
40529
  // ../atlas/src/drivers/MongoDBDriver.ts
40530
40530
  class MongoDBDriver {
40531
40531
  config;
40532
40532
  client = null;
40533
40533
  db = null;
40534
40534
  MongoClientCtor;
40535
- constructor(config, deps = {}) {
40535
+ constructor(config, deps) {
40536
40536
  if (config.driver !== "mongodb") {
40537
- throw new Error(`Invalid driver type '\${config.driver}' for MongoDBDriver`);
40537
+ throw new Error(`Invalid driver type '${config.driver}' for MongoDBDriver`);
40538
40538
  }
40539
40539
  this.config = config;
40540
- this.MongoClientCtor = deps.MongoClient ?? import_mongodb.MongoClient;
40540
+ if (deps?.MongoClient) {
40541
+ this.MongoClientCtor = deps.MongoClient;
40542
+ }
40541
40543
  }
40542
40544
  getDriverName() {
40543
40545
  return "mongodb";
@@ -40547,13 +40549,22 @@ class MongoDBDriver {
40547
40549
  return;
40548
40550
  }
40549
40551
  try {
40550
- this.client = new this.MongoClientCtor(this.config.uri ?? `mongodb://\${this.config.host}:\${this.config.port}/\${this.config.database}`);
40552
+ const Ctor = this.MongoClientCtor || (await this.loadMongoModule()).MongoClient;
40553
+ this.client = new Ctor(this.config.uri ?? `mongodb://${this.config.host}:${this.config.port}/${this.config.database}`);
40551
40554
  await this.client.connect();
40552
40555
  this.db = this.client.db(this.config.database);
40553
40556
  } catch (error) {
40554
40557
  throw new ConnectionError("Could not connect to MongoDB cluster", error);
40555
40558
  }
40556
40559
  }
40560
+ async loadMongoModule() {
40561
+ try {
40562
+ const mongodb = await Promise.resolve().then(() => __toESM(require_lib4(), 1));
40563
+ return mongodb;
40564
+ } catch (e) {
40565
+ throw new Error(`MongoDB driver requires the "mongodb" package. Please install it: bun add mongodb. Original Error: ${e}`);
40566
+ }
40567
+ }
40557
40568
  async disconnect() {
40558
40569
  if (this.client) {
40559
40570
  await this.client.close();
@@ -40646,10 +40657,8 @@ class MongoDBDriver {
40646
40657
  return doc;
40647
40658
  }
40648
40659
  }
40649
- var import_mongodb;
40650
40660
  var init_MongoDBDriver = __esm(() => {
40651
40661
  init_errors();
40652
- import_mongodb = __toESM(require_lib4(), 1);
40653
40662
  });
40654
40663
 
40655
40664
  // ../../node_modules/.bun/sqlstring@2.3.3/node_modules/sqlstring/lib/SqlString.js
@@ -74589,12 +74598,14 @@ class RedisDriver {
74589
74598
  config;
74590
74599
  client = null;
74591
74600
  RedisCtor;
74592
- constructor(config, deps = {}) {
74601
+ constructor(config, deps) {
74593
74602
  if (config.driver !== "redis") {
74594
74603
  throw new Error(`Invalid driver type '${config.driver}' for RedisDriver`);
74595
74604
  }
74596
74605
  this.config = config;
74597
- this.RedisCtor = deps.Redis ?? import_ioredis.default;
74606
+ if (deps?.Redis) {
74607
+ this.RedisCtor = deps.Redis;
74608
+ }
74598
74609
  }
74599
74610
  getDriverName() {
74600
74611
  return "redis";
@@ -74604,7 +74615,8 @@ class RedisDriver {
74604
74615
  return;
74605
74616
  }
74606
74617
  try {
74607
- this.client = new this.RedisCtor({
74618
+ const Ctor = this.RedisCtor || (await this.loadRedisModule()).default;
74619
+ this.client = new Ctor({
74608
74620
  host: this.config.host,
74609
74621
  port: this.config.port ?? 6379,
74610
74622
  password: this.config.password,
@@ -74616,6 +74628,14 @@ class RedisDriver {
74616
74628
  throw new ConnectionError("Could not connect to Redis host", error);
74617
74629
  }
74618
74630
  }
74631
+ async loadRedisModule() {
74632
+ try {
74633
+ const ioredis = await Promise.resolve().then(() => __toESM(require_built3(), 1));
74634
+ return ioredis;
74635
+ } catch (e) {
74636
+ throw new Error(`Redis driver requires the "ioredis" package. Please install it: bun add ioredis. Original Error: ${e}`);
74637
+ }
74638
+ }
74619
74639
  async disconnect() {
74620
74640
  if (this.client) {
74621
74641
  await this.client.quit();
@@ -74687,10 +74707,8 @@ class RedisDriver {
74687
74707
  return false;
74688
74708
  }
74689
74709
  }
74690
- var import_ioredis;
74691
74710
  var init_RedisDriver = __esm(() => {
74692
74711
  init_errors();
74693
- import_ioredis = __toESM(require_built3(), 1);
74694
74712
  });
74695
74713
 
74696
74714
  // ../../node_modules/.bun/better-sqlite3@11.10.0/node_modules/better-sqlite3/lib/util.js
@@ -75485,11 +75503,15 @@ class SQLiteDriver {
75485
75503
  });
75486
75504
  this.client.exec("PRAGMA journal_mode = WAL;");
75487
75505
  } else {
75488
- const { default: Database } = await Promise.resolve().then(() => __toESM(require_lib11(), 1));
75489
- this.client = new Database(this.config.database, {
75490
- readonly: this.config.readonly ?? false
75491
- });
75492
- this.client.pragma("journal_mode = WAL");
75506
+ try {
75507
+ const { default: Database } = await Promise.resolve().then(() => __toESM(require_lib11(), 1));
75508
+ this.client = new Database(this.config.database, {
75509
+ readonly: this.config.readonly ?? false
75510
+ });
75511
+ this.client.pragma("journal_mode = WAL");
75512
+ } catch (e) {
75513
+ throw new Error(`SQLite driver requires "better-sqlite3" when running in Node.js. Please install it: bun add better-sqlite3. Original Error: ${e}`);
75514
+ }
75493
75515
  }
75494
75516
  } catch (error) {
75495
75517
  throw new ConnectionError("Could not connect to SQLite database", error);
@@ -77756,7 +77778,7 @@ var init_Connection = __esm(() => {
77756
77778
  return new Proxy(this, {
77757
77779
  get(target, prop) {
77758
77780
  if (prop in target) {
77759
- return target[prop];
77781
+ return Reflect.get(target, prop);
77760
77782
  }
77761
77783
  if (typeof prop === "string" && target.driver && typeof target.driver[prop] === "function") {
77762
77784
  return target.driver[prop].bind(target.driver);
@@ -81111,6 +81133,26 @@ class BaseGenerator {
81111
81133
  await this.writeFile(context.targetDir, ".dockerignore", this.generateDockerIgnore());
81112
81134
  await this.writeFile(context.targetDir, "ARCHITECTURE.md", this.generateArchitectureDoc(context));
81113
81135
  await this.generateCheckScripts(context);
81136
+ await this.generateSkills(context);
81137
+ }
81138
+ async generateSkills(context) {
81139
+ const skillsDir = path2.resolve(this.config.templatesDir, "skills");
81140
+ const targetSkillsDir = path2.join(".skills");
81141
+ try {
81142
+ await fs2.access(skillsDir);
81143
+ } catch {
81144
+ return;
81145
+ }
81146
+ const files = await walk(skillsDir);
81147
+ for (const filePath of files) {
81148
+ const relativePath = path2.relative(skillsDir, filePath);
81149
+ const targetPath = path2.join(targetSkillsDir, relativePath);
81150
+ let content = await fs2.readFile(filePath, "utf-8");
81151
+ try {
81152
+ content = this.stubGenerator.render(content, context);
81153
+ } catch {}
81154
+ await this.writeFile(context.targetDir, targetPath, content);
81155
+ }
81114
81156
  }
81115
81157
  async applyOverlays(context) {
81116
81158
  const profile = context.profile;
@@ -83314,6 +83356,8 @@ export class ${name}ServiceProvider extends ServiceProvider {
83314
83356
  return `export default {
83315
83357
  name: process.env.APP_NAME ?? '${context.name}',
83316
83358
  env: process.env.APP_ENV ?? 'development',
83359
+ port: Number.parseInt(process.env.PORT ?? '3000', 10),
83360
+ VIEW_DIR: process.env.VIEW_DIR ?? 'src/views',
83317
83361
  debug: process.env.APP_DEBUG === 'true',
83318
83362
  url: process.env.APP_URL ?? 'http://localhost:3000',
83319
83363
  }
@@ -83960,6 +84004,16 @@ export default {
83960
84004
  */
83961
84005
  env: process.env.APP_ENV ?? 'development',
83962
84006
 
84007
+ /**
84008
+ * Application port
84009
+ */
84010
+ port: Number.parseInt(process.env.PORT ?? '3000', 10),
84011
+
84012
+ /**
84013
+ * View directory
84014
+ */
84015
+ VIEW_DIR: process.env.VIEW_DIR ?? 'src/views',
84016
+
83963
84017
  /**
83964
84018
  * Debug mode
83965
84019
  */
@@ -84083,8 +84137,7 @@ export default {
84083
84137
  */
84084
84138
  providers: {
84085
84139
  users: {
84086
- driver: 'database',
84087
- table: 'users',
84140
+ driver: 'callback', // Custom callback provider
84088
84141
  },
84089
84142
  },
84090
84143
  }
@@ -85332,6 +85385,8 @@ class ActionDomainGenerator extends BaseGenerator {
85332
85385
  return `export default {
85333
85386
  name: process.env.APP_NAME ?? '${context.name}',
85334
85387
  env: process.env.APP_ENV ?? 'development',
85388
+ port: Number.parseInt(process.env.PORT ?? '3000', 10),
85389
+ VIEW_DIR: process.env.VIEW_DIR ?? 'src/views',
85335
85390
  debug: process.env.APP_DEBUG === 'true',
85336
85391
  url: process.env.APP_URL ?? 'http://localhost:3000',
85337
85392
  key: process.env.APP_KEY,
@@ -85649,6 +85704,115 @@ Created with \u2764\uFE0F using Gravito Framework
85649
85704
  }
85650
85705
  }
85651
85706
 
85707
+ // ../scaffold/src/generators/StandaloneEngineGenerator.ts
85708
+ class StandaloneEngineGenerator extends BaseGenerator {
85709
+ get architectureType() {
85710
+ return "standalone-engine";
85711
+ }
85712
+ get displayName() {
85713
+ return "Standalone Engine";
85714
+ }
85715
+ get description() {
85716
+ return "High-performance pure Gravito Engine (minimal)";
85717
+ }
85718
+ getDirectoryStructure(context) {
85719
+ return [
85720
+ {
85721
+ type: "directory",
85722
+ name: "src",
85723
+ children: [
85724
+ {
85725
+ type: "file",
85726
+ name: "index.ts",
85727
+ content: this.getIndexContent()
85728
+ }
85729
+ ]
85730
+ },
85731
+ {
85732
+ type: "file",
85733
+ name: "README.md",
85734
+ content: this.getReadmeContent(context)
85735
+ }
85736
+ ];
85737
+ }
85738
+ async generateCommonFiles(context) {
85739
+ await this.writeFile(context.targetDir, "package.json", this.generatePackageJson(context));
85740
+ await this.writeFile(context.targetDir, "tsconfig.json", this.generateTsConfig());
85741
+ await this.writeFile(context.targetDir, ".gitignore", this.generateGitignore());
85742
+ }
85743
+ generatePackageJson(context) {
85744
+ const pkg = {
85745
+ name: context.nameKebabCase,
85746
+ version: "0.1.0",
85747
+ type: "module",
85748
+ scripts: {
85749
+ dev: "bun run --watch src/index.ts",
85750
+ build: "bun build ./src/index.ts --outdir ./dist --target bun",
85751
+ start: "bun run dist/index.js",
85752
+ test: "bun test"
85753
+ },
85754
+ dependencies: {
85755
+ "@gravito/core": "^1.1.0"
85756
+ },
85757
+ devDependencies: {
85758
+ "bun-types": "latest",
85759
+ typescript: "^5.0.0"
85760
+ }
85761
+ };
85762
+ return JSON.stringify(pkg, null, 2);
85763
+ }
85764
+ generateArchitectureDoc(_context) {
85765
+ return "";
85766
+ }
85767
+ getIndexContent() {
85768
+ return `import { Gravito } from '@gravito/core/engine'
85769
+
85770
+ const app = new Gravito()
85771
+
85772
+ // Basic Route
85773
+ app.get('/', (c) => c.text('Hello Gravito Engine!'))
85774
+
85775
+ // JSON Response
85776
+ app.get('/json', (c) => c.json({ message: 'High Performance' }))
85777
+
85778
+ // Path Parameters
85779
+ app.get('/user/:name', (c) => {
85780
+ const name = c.req.param('name')
85781
+ return c.text(\`Hello \${name}\`)
85782
+ })
85783
+
85784
+ export default app
85785
+ `;
85786
+ }
85787
+ getReadmeContent(context) {
85788
+ return `# ${context.name}
85789
+
85790
+ A high-performance web application powered by Gravito Engine.
85791
+
85792
+ ## Getting Started
85793
+
85794
+ ### Install Dependencies
85795
+
85796
+ \`\`\`bash
85797
+ bun install
85798
+ \`\`\`
85799
+
85800
+ ### Run Development Server
85801
+
85802
+ \`\`\`bash
85803
+ bun run dev
85804
+ \`\`\`
85805
+
85806
+ ### Production Build
85807
+
85808
+ \`\`\`bash
85809
+ bun run build
85810
+ bun start
85811
+ \`\`\`
85812
+ `;
85813
+ }
85814
+ }
85815
+
85652
85816
  // ../scaffold/src/Scaffold.ts
85653
85817
  var __dirname = "/Users/carl/Dev/Carl/gravito-core/packages/scaffold/src";
85654
85818
 
@@ -85681,6 +85845,11 @@ class Scaffold {
85681
85845
  name: "Action Domain",
85682
85846
  description: "Single Action Controllers pattern for high-clarity APIs"
85683
85847
  },
85848
+ {
85849
+ type: "standalone-engine",
85850
+ name: "Standalone Engine",
85851
+ description: "High-performance pure Gravito Engine (minimal)"
85852
+ },
85684
85853
  {
85685
85854
  type: "satellite",
85686
85855
  name: "Gravito Satellite",
@@ -85738,6 +85907,8 @@ class Scaffold {
85738
85907
  return new ActionDomainGenerator(config);
85739
85908
  case "satellite":
85740
85909
  return new SatelliteGenerator(config);
85910
+ case "standalone-engine":
85911
+ return new StandaloneEngineGenerator(config);
85741
85912
  default:
85742
85913
  throw new Error(`Unknown architecture type: ${type}`);
85743
85914
  }
@@ -85761,7 +85932,7 @@ import { confirm, note, spinner } from "@clack/prompts";
85761
85932
  // ../core/package.json
85762
85933
  var package_default = {
85763
85934
  name: "@gravito/core",
85764
- version: "1.0.0",
85935
+ version: "1.2.0",
85765
85936
  description: "",
85766
85937
  module: "./dist/index.js",
85767
85938
  main: "./dist/index.cjs",
@@ -85777,6 +85948,11 @@ var package_default = {
85777
85948
  types: "./dist/compat.d.ts",
85778
85949
  import: "./dist/compat.js",
85779
85950
  require: "./dist/compat.cjs"
85951
+ },
85952
+ "./engine": {
85953
+ types: "./dist/engine/index.d.ts",
85954
+ import: "./dist/engine/index.js",
85955
+ require: "./dist/engine/index.cjs"
85780
85956
  }
85781
85957
  },
85782
85958
  files: [
@@ -85833,6 +86009,36 @@ class PhotonRequestWrapper {
85833
86009
  constructor(photonCtx) {
85834
86010
  this.photonCtx = photonCtx;
85835
86011
  }
86012
+ static create(photonCtx) {
86013
+ const instance = new PhotonRequestWrapper(photonCtx);
86014
+ return new Proxy(instance, {
86015
+ get(target, prop, receiver) {
86016
+ if (prop in target) {
86017
+ const value = Reflect.get(target, prop, receiver);
86018
+ if (typeof value === "function") {
86019
+ return value.bind(target);
86020
+ }
86021
+ return value;
86022
+ }
86023
+ const nativeReq = target.photonCtx.req;
86024
+ if (prop in nativeReq) {
86025
+ const value = nativeReq[prop];
86026
+ if (typeof value === "function") {
86027
+ return value.bind(nativeReq);
86028
+ }
86029
+ return value;
86030
+ }
86031
+ return;
86032
+ },
86033
+ set(target, prop, value) {
86034
+ if (prop in target) {
86035
+ return Reflect.set(target, prop, value);
86036
+ }
86037
+ target.photonCtx.req[prop] = value;
86038
+ return true;
86039
+ }
86040
+ });
86041
+ }
85836
86042
  get url() {
85837
86043
  return this.photonCtx.req.url;
85838
86044
  }
@@ -85894,7 +86100,7 @@ class PhotonContextWrapper {
85894
86100
  _req;
85895
86101
  constructor(photonCtx) {
85896
86102
  this.photonCtx = photonCtx;
85897
- this._req = new PhotonRequestWrapper(photonCtx);
86103
+ this._req = PhotonRequestWrapper.create(photonCtx);
85898
86104
  }
85899
86105
  static create(photonCtx) {
85900
86106
  const instance = new PhotonContextWrapper(photonCtx);
@@ -86001,7 +86207,7 @@ function toPhotonMiddleware(middleware) {
86001
86207
  return async (c, next) => {
86002
86208
  const ctx = PhotonContextWrapper.create(c);
86003
86209
  const gravitoNext = async () => {
86004
- await next();
86210
+ return await next();
86005
86211
  };
86006
86212
  return middleware(ctx, gravitoNext);
86007
86213
  };
@@ -87659,20 +87865,20 @@ class RouteGroup {
87659
87865
  group(callback) {
87660
87866
  callback(this);
87661
87867
  }
87662
- get(path4, requestOrHandler, handler) {
87663
- return this.router.req("get", path4, requestOrHandler, handler, this.options);
87868
+ get(path4, requestOrHandlerOrMiddleware, handler) {
87869
+ return this.router.req("get", path4, requestOrHandlerOrMiddleware, handler, this.options);
87664
87870
  }
87665
- post(path4, requestOrHandler, handler) {
87666
- return this.router.req("post", path4, requestOrHandler, handler, this.options);
87871
+ post(path4, requestOrHandlerOrMiddleware, handler) {
87872
+ return this.router.req("post", path4, requestOrHandlerOrMiddleware, handler, this.options);
87667
87873
  }
87668
- put(path4, requestOrHandler, handler) {
87669
- return this.router.req("put", path4, requestOrHandler, handler, this.options);
87874
+ put(path4, requestOrHandlerOrMiddleware, handler) {
87875
+ return this.router.req("put", path4, requestOrHandlerOrMiddleware, handler, this.options);
87670
87876
  }
87671
- delete(path4, requestOrHandler, handler) {
87672
- return this.router.req("delete", path4, requestOrHandler, handler, this.options);
87877
+ delete(path4, requestOrHandlerOrMiddleware, handler) {
87878
+ return this.router.req("delete", path4, requestOrHandlerOrMiddleware, handler, this.options);
87673
87879
  }
87674
- patch(path4, requestOrHandler, handler) {
87675
- return this.router.req("patch", path4, requestOrHandler, handler, this.options);
87880
+ patch(path4, requestOrHandlerOrMiddleware, handler) {
87881
+ return this.router.req("patch", path4, requestOrHandlerOrMiddleware, handler, this.options);
87676
87882
  }
87677
87883
  resource(name, controller, options = {}) {
87678
87884
  const actions = [
@@ -87817,20 +88023,20 @@ class Router {
87817
88023
  middleware(...handlers) {
87818
88024
  return new RouteGroup(this, { middleware: handlers.flat() });
87819
88025
  }
87820
- get(path4, requestOrHandler, handler) {
87821
- return this.req("get", path4, requestOrHandler, handler);
88026
+ get(path4, requestOrHandlerOrMiddleware, handler) {
88027
+ return this.req("get", path4, requestOrHandlerOrMiddleware, handler);
87822
88028
  }
87823
- post(path4, requestOrHandler, handler) {
87824
- return this.req("post", path4, requestOrHandler, handler);
88029
+ post(path4, requestOrHandlerOrMiddleware, handler) {
88030
+ return this.req("post", path4, requestOrHandlerOrMiddleware, handler);
87825
88031
  }
87826
- put(path4, requestOrHandler, handler) {
87827
- return this.req("put", path4, requestOrHandler, handler);
88032
+ put(path4, requestOrHandlerOrMiddleware, handler) {
88033
+ return this.req("put", path4, requestOrHandlerOrMiddleware, handler);
87828
88034
  }
87829
- delete(path4, requestOrHandler, handler) {
87830
- return this.req("delete", path4, requestOrHandler, handler);
88035
+ delete(path4, requestOrHandlerOrMiddleware, handler) {
88036
+ return this.req("delete", path4, requestOrHandlerOrMiddleware, handler);
87831
88037
  }
87832
- patch(path4, requestOrHandler, handler) {
87833
- return this.req("patch", path4, requestOrHandler, handler);
88038
+ patch(path4, requestOrHandlerOrMiddleware, handler) {
88039
+ return this.req("patch", path4, requestOrHandlerOrMiddleware, handler);
87834
88040
  }
87835
88041
  resource(name, controller, options = {}) {
87836
88042
  const actions = [
@@ -87870,17 +88076,25 @@ class Router {
87870
88076
  }
87871
88077
  }
87872
88078
  }
87873
- req(method, path4, requestOrHandler, handler, options = {}) {
88079
+ req(method, path4, requestOrHandlerOrMiddleware, handler, options = {}) {
87874
88080
  const fullPath = (options.prefix || "") + path4;
87875
88081
  let formRequestMiddleware = null;
88082
+ let routeMiddleware = [];
87876
88083
  let finalRouteHandler;
87877
88084
  if (handler !== undefined) {
87878
- if (isFormRequestClass(requestOrHandler)) {
87879
- formRequestMiddleware = formRequestToMiddleware(requestOrHandler);
88085
+ if (isFormRequestClass(requestOrHandlerOrMiddleware)) {
88086
+ formRequestMiddleware = formRequestToMiddleware(requestOrHandlerOrMiddleware);
88087
+ } else {
88088
+ const middleware = requestOrHandlerOrMiddleware;
88089
+ if (Array.isArray(middleware)) {
88090
+ routeMiddleware = middleware;
88091
+ } else {
88092
+ routeMiddleware = [middleware];
88093
+ }
87880
88094
  }
87881
88095
  finalRouteHandler = handler;
87882
88096
  } else {
87883
- finalRouteHandler = requestOrHandler;
88097
+ finalRouteHandler = requestOrHandlerOrMiddleware;
87884
88098
  }
87885
88099
  let resolvedHandler;
87886
88100
  if (Array.isArray(finalRouteHandler)) {
@@ -87896,6 +88110,9 @@ class Router {
87896
88110
  if (formRequestMiddleware) {
87897
88111
  handlers.push(formRequestMiddleware);
87898
88112
  }
88113
+ if (routeMiddleware.length > 0) {
88114
+ handlers.push(...routeMiddleware);
88115
+ }
87899
88116
  handlers.push(resolvedHandler);
87900
88117
  if (options.domain) {
87901
88118
  const domainCheck = async (c, next) => {
@@ -88106,8 +88323,7 @@ class PlanetCore {
88106
88323
  const cookieJar = new CookieJar(this.encrypter);
88107
88324
  c.set("cookieJar", cookieJar);
88108
88325
  c.route = (name, params, query) => this.router.url(name, params, query);
88109
- await next();
88110
- return;
88326
+ return await next();
88111
88327
  });
88112
88328
  this.router = new Router(this);
88113
88329
  this.adapter.onError(async (err, c) => {
@@ -88444,6 +88660,655 @@ class ServiceProvider {
88444
88660
  return Array.from(ServiceProvider.publishables.keys());
88445
88661
  }
88446
88662
  }
88663
+ // ../core/src/engine/AOTRouter.ts
88664
+ class AOTRouter {
88665
+ staticRoutes = new Map;
88666
+ dynamicRouter = new RadixRouter;
88667
+ globalMiddleware = [];
88668
+ pathMiddleware = new Map;
88669
+ add(method, path4, handler, middleware = []) {
88670
+ const normalizedMethod = method.toLowerCase();
88671
+ if (this.isStaticPath(path4)) {
88672
+ const key = `${normalizedMethod}:${path4}`;
88673
+ this.staticRoutes.set(key, { handler, middleware });
88674
+ } else {
88675
+ const wrappedHandler = handler;
88676
+ this.dynamicRouter.add(normalizedMethod, path4, [wrappedHandler]);
88677
+ if (middleware.length > 0) {
88678
+ this.pathMiddleware.set(`${normalizedMethod}:${path4}`, middleware);
88679
+ }
88680
+ }
88681
+ }
88682
+ use(...middleware) {
88683
+ this.globalMiddleware.push(...middleware);
88684
+ }
88685
+ usePattern(pattern, ...middleware) {
88686
+ const existing = this.pathMiddleware.get(pattern) ?? [];
88687
+ this.pathMiddleware.set(pattern, [...existing, ...middleware]);
88688
+ }
88689
+ match(method, path4) {
88690
+ const normalizedMethod = method.toLowerCase();
88691
+ const staticKey = `${normalizedMethod}:${path4}`;
88692
+ const staticRoute = this.staticRoutes.get(staticKey);
88693
+ if (staticRoute) {
88694
+ return {
88695
+ handler: staticRoute.handler,
88696
+ params: {},
88697
+ middleware: this.collectMiddleware(path4, staticRoute.middleware)
88698
+ };
88699
+ }
88700
+ const match2 = this.dynamicRouter.match(normalizedMethod, path4);
88701
+ if (match2 && match2.handlers.length > 0) {
88702
+ const handler = match2.handlers[0];
88703
+ const routeKey = this.findDynamicRouteKey(normalizedMethod, path4);
88704
+ const routeMiddleware = routeKey ? this.pathMiddleware.get(routeKey) ?? [] : [];
88705
+ return {
88706
+ handler,
88707
+ params: match2.params,
88708
+ middleware: this.collectMiddleware(path4, routeMiddleware)
88709
+ };
88710
+ }
88711
+ return {
88712
+ handler: null,
88713
+ params: {},
88714
+ middleware: []
88715
+ };
88716
+ }
88717
+ collectMiddlewarePublic(path4, routeMiddleware) {
88718
+ return this.collectMiddleware(path4, routeMiddleware);
88719
+ }
88720
+ collectMiddleware(path4, routeMiddleware) {
88721
+ if (this.globalMiddleware.length === 0 && this.pathMiddleware.size === 0 && routeMiddleware.length === 0) {
88722
+ return [];
88723
+ }
88724
+ const middleware = [];
88725
+ if (this.globalMiddleware.length > 0) {
88726
+ middleware.push(...this.globalMiddleware);
88727
+ }
88728
+ if (this.pathMiddleware.size > 0) {
88729
+ for (const [pattern, mw] of this.pathMiddleware) {
88730
+ if (pattern.includes(":"))
88731
+ continue;
88732
+ if (this.matchPattern(pattern, path4)) {
88733
+ middleware.push(...mw);
88734
+ }
88735
+ }
88736
+ }
88737
+ if (routeMiddleware.length > 0) {
88738
+ middleware.push(...routeMiddleware);
88739
+ }
88740
+ return middleware;
88741
+ }
88742
+ isStaticPath(path4) {
88743
+ return !path4.includes(":") && !path4.includes("*");
88744
+ }
88745
+ matchPattern(pattern, path4) {
88746
+ if (pattern === "*")
88747
+ return true;
88748
+ if (pattern === path4)
88749
+ return true;
88750
+ if (pattern.endsWith("/*")) {
88751
+ const prefix = pattern.slice(0, -2);
88752
+ return path4.startsWith(prefix);
88753
+ }
88754
+ return false;
88755
+ }
88756
+ findDynamicRouteKey(method, _path) {
88757
+ for (const key of this.pathMiddleware.keys()) {
88758
+ if (key.startsWith(`${method}:`)) {
88759
+ return key;
88760
+ }
88761
+ }
88762
+ return null;
88763
+ }
88764
+ getRoutes() {
88765
+ const routes = [];
88766
+ for (const key of this.staticRoutes.keys()) {
88767
+ const [method, path4] = key.split(":");
88768
+ routes.push({ method, path: path4, type: "static" });
88769
+ }
88770
+ return routes;
88771
+ }
88772
+ }
88773
+
88774
+ // ../core/src/engine/analyzer.ts
88775
+ function analyzeHandler(handler) {
88776
+ const source = handler.toString();
88777
+ return {
88778
+ usesHeaders: source.includes(".header(") || source.includes(".header)") || source.includes(".headers(") || source.includes(".headers)"),
88779
+ usesQuery: source.includes(".query(") || source.includes(".query)") || source.includes(".queries(") || source.includes(".queries)"),
88780
+ usesBody: source.includes(".json()") || source.includes(".text()") || source.includes(".formData()") || source.includes(".body"),
88781
+ usesParams: source.includes(".param(") || source.includes(".param)") || source.includes(".params(") || source.includes(".params)"),
88782
+ isAsync: source.includes("async") || source.includes("await")
88783
+ };
88784
+ }
88785
+ function getOptimalContextType(analysis) {
88786
+ if (analysis.usesHeaders) {
88787
+ return "fast";
88788
+ }
88789
+ if (!analysis.usesQuery && !analysis.usesBody && !analysis.usesParams) {
88790
+ return "minimal";
88791
+ }
88792
+ if (!analysis.usesQuery && !analysis.usesBody && analysis.usesParams) {
88793
+ return "minimal";
88794
+ }
88795
+ if (analysis.usesBody) {
88796
+ return "full";
88797
+ }
88798
+ return "fast";
88799
+ }
88800
+
88801
+ // ../core/src/engine/FastContext.ts
88802
+ class FastRequestImpl {
88803
+ _request;
88804
+ _params;
88805
+ _url = new URL("http://localhost");
88806
+ _query = null;
88807
+ _headers = null;
88808
+ reset(request, params = {}) {
88809
+ this._request = request;
88810
+ this._params = params;
88811
+ this._url.href = request.url;
88812
+ this._query = null;
88813
+ this._headers = null;
88814
+ }
88815
+ get url() {
88816
+ return this._request.url;
88817
+ }
88818
+ get method() {
88819
+ return this._request.method;
88820
+ }
88821
+ get path() {
88822
+ return this._url.pathname;
88823
+ }
88824
+ param(name) {
88825
+ return this._params[name];
88826
+ }
88827
+ params() {
88828
+ return { ...this._params };
88829
+ }
88830
+ query(name) {
88831
+ if (!this._query) {
88832
+ this._query = this._url.searchParams;
88833
+ }
88834
+ return this._query.get(name) ?? undefined;
88835
+ }
88836
+ queries() {
88837
+ if (!this._query) {
88838
+ this._query = this._url.searchParams;
88839
+ }
88840
+ const result = {};
88841
+ for (const [key, value] of this._query.entries()) {
88842
+ const existing = result[key];
88843
+ if (existing === undefined) {
88844
+ result[key] = value;
88845
+ } else if (Array.isArray(existing)) {
88846
+ existing.push(value);
88847
+ } else {
88848
+ result[key] = [existing, value];
88849
+ }
88850
+ }
88851
+ return result;
88852
+ }
88853
+ header(name) {
88854
+ return this._request.headers.get(name) ?? undefined;
88855
+ }
88856
+ headers() {
88857
+ if (!this._headers) {
88858
+ this._headers = {};
88859
+ for (const [key, value] of this._request.headers.entries()) {
88860
+ this._headers[key] = value;
88861
+ }
88862
+ }
88863
+ return { ...this._headers };
88864
+ }
88865
+ async json() {
88866
+ return this._request.json();
88867
+ }
88868
+ async text() {
88869
+ return this._request.text();
88870
+ }
88871
+ async formData() {
88872
+ return this._request.formData();
88873
+ }
88874
+ get raw() {
88875
+ return this._request;
88876
+ }
88877
+ }
88878
+
88879
+ class FastContext {
88880
+ _req = new FastRequestImpl;
88881
+ _headers = new Headers;
88882
+ reset(request, params = {}) {
88883
+ this._req.reset(request, params);
88884
+ this._headers = new Headers;
88885
+ return this;
88886
+ }
88887
+ get req() {
88888
+ return this._req;
88889
+ }
88890
+ json(data2, status = 200) {
88891
+ this._headers.set("Content-Type", "application/json; charset=utf-8");
88892
+ return new Response(JSON.stringify(data2), {
88893
+ status,
88894
+ headers: this._headers
88895
+ });
88896
+ }
88897
+ text(text, status = 200) {
88898
+ this._headers.set("Content-Type", "text/plain; charset=utf-8");
88899
+ return new Response(text, {
88900
+ status,
88901
+ headers: this._headers
88902
+ });
88903
+ }
88904
+ html(html, status = 200) {
88905
+ this._headers.set("Content-Type", "text/html; charset=utf-8");
88906
+ return new Response(html, {
88907
+ status,
88908
+ headers: this._headers
88909
+ });
88910
+ }
88911
+ redirect(url, status = 302) {
88912
+ this._headers.set("Location", url);
88913
+ return new Response(null, {
88914
+ status,
88915
+ headers: this._headers
88916
+ });
88917
+ }
88918
+ body(data2, status = 200) {
88919
+ return new Response(data2, {
88920
+ status,
88921
+ headers: this._headers
88922
+ });
88923
+ }
88924
+ header(name, value) {
88925
+ this._headers.set(name, value);
88926
+ }
88927
+ status(_code) {}
88928
+ }
88929
+
88930
+ // ../core/src/engine/MinimalContext.ts
88931
+ class MinimalRequest {
88932
+ _request;
88933
+ _params;
88934
+ _path;
88935
+ constructor(_request, _params, _path) {
88936
+ this._request = _request;
88937
+ this._params = _params;
88938
+ this._path = _path;
88939
+ }
88940
+ get url() {
88941
+ return this._request.url;
88942
+ }
88943
+ get method() {
88944
+ return this._request.method;
88945
+ }
88946
+ get path() {
88947
+ return this._path;
88948
+ }
88949
+ param(name) {
88950
+ return this._params[name];
88951
+ }
88952
+ params() {
88953
+ return { ...this._params };
88954
+ }
88955
+ query(name) {
88956
+ const url = new URL(this._request.url);
88957
+ return url.searchParams.get(name) ?? undefined;
88958
+ }
88959
+ queries() {
88960
+ const url = new URL(this._request.url);
88961
+ const result = {};
88962
+ for (const [key, value] of url.searchParams.entries()) {
88963
+ const existing = result[key];
88964
+ if (existing === undefined) {
88965
+ result[key] = value;
88966
+ } else if (Array.isArray(existing)) {
88967
+ existing.push(value);
88968
+ } else {
88969
+ result[key] = [existing, value];
88970
+ }
88971
+ }
88972
+ return result;
88973
+ }
88974
+ header(name) {
88975
+ return this._request.headers.get(name) ?? undefined;
88976
+ }
88977
+ headers() {
88978
+ const result = {};
88979
+ for (const [key, value] of this._request.headers.entries()) {
88980
+ result[key] = value;
88981
+ }
88982
+ return result;
88983
+ }
88984
+ async json() {
88985
+ return this._request.json();
88986
+ }
88987
+ async text() {
88988
+ return this._request.text();
88989
+ }
88990
+ async formData() {
88991
+ return this._request.formData();
88992
+ }
88993
+ get raw() {
88994
+ return this._request;
88995
+ }
88996
+ }
88997
+
88998
+ class MinimalContext {
88999
+ _req;
89000
+ constructor(request, params, path4) {
89001
+ this._req = new MinimalRequest(request, params, path4);
89002
+ }
89003
+ get req() {
89004
+ return this._req;
89005
+ }
89006
+ json(data2, status = 200) {
89007
+ return new Response(JSON.stringify(data2), {
89008
+ status,
89009
+ headers: { "Content-Type": "application/json; charset=utf-8" }
89010
+ });
89011
+ }
89012
+ text(text, status = 200) {
89013
+ return new Response(text, {
89014
+ status,
89015
+ headers: { "Content-Type": "text/plain; charset=utf-8" }
89016
+ });
89017
+ }
89018
+ html(html, status = 200) {
89019
+ return new Response(html, {
89020
+ status,
89021
+ headers: { "Content-Type": "text/html; charset=utf-8" }
89022
+ });
89023
+ }
89024
+ redirect(url, status = 302) {
89025
+ return new Response(null, {
89026
+ status,
89027
+ headers: { Location: url }
89028
+ });
89029
+ }
89030
+ body(data2, status = 200) {
89031
+ return new Response(data2, { status });
89032
+ }
89033
+ header(_name, _value) {
89034
+ console.warn("MinimalContext.header() is a no-op. Use FastContext for custom headers.");
89035
+ }
89036
+ status(_code) {}
89037
+ reset(_request, _params) {
89038
+ throw new Error("MinimalContext does not support reset. Create a new instance instead.");
89039
+ }
89040
+ }
89041
+
89042
+ // ../core/src/engine/path.ts
89043
+ function extractPath(url) {
89044
+ const protocolEnd = url.indexOf("://");
89045
+ const searchStart = protocolEnd === -1 ? 0 : protocolEnd + 3;
89046
+ const pathStart = url.indexOf("/", searchStart);
89047
+ if (pathStart === -1) {
89048
+ return "/";
89049
+ }
89050
+ const queryStart = url.indexOf("?", pathStart);
89051
+ if (queryStart === -1) {
89052
+ return url.slice(pathStart);
89053
+ }
89054
+ return url.slice(pathStart, queryStart);
89055
+ }
89056
+
89057
+ // ../core/src/engine/pool.ts
89058
+ class ObjectPool {
89059
+ pool = [];
89060
+ factory;
89061
+ reset;
89062
+ maxSize;
89063
+ constructor(factory, reset, maxSize = 256) {
89064
+ this.factory = factory;
89065
+ this.reset = reset;
89066
+ this.maxSize = maxSize;
89067
+ }
89068
+ acquire() {
89069
+ const obj = this.pool.pop();
89070
+ if (obj !== undefined) {
89071
+ return obj;
89072
+ }
89073
+ return this.factory();
89074
+ }
89075
+ release(obj) {
89076
+ if (this.pool.length < this.maxSize) {
89077
+ this.reset(obj);
89078
+ this.pool.push(obj);
89079
+ }
89080
+ }
89081
+ clear() {
89082
+ this.pool = [];
89083
+ }
89084
+ get size() {
89085
+ return this.pool.length;
89086
+ }
89087
+ get capacity() {
89088
+ return this.maxSize;
89089
+ }
89090
+ prewarm(count) {
89091
+ const targetSize = Math.min(count, this.maxSize);
89092
+ while (this.pool.length < targetSize) {
89093
+ const obj = this.factory();
89094
+ this.reset(obj);
89095
+ this.pool.push(obj);
89096
+ }
89097
+ }
89098
+ }
89099
+
89100
+ // ../core/src/engine/Gravito.ts
89101
+ class Gravito {
89102
+ router = new AOTRouter;
89103
+ contextPool;
89104
+ errorHandler;
89105
+ notFoundHandler;
89106
+ staticRoutes;
89107
+ isPureStaticApp = true;
89108
+ constructor(options = {}) {
89109
+ const poolSize = options.poolSize ?? 256;
89110
+ this.contextPool = new ObjectPool(() => new FastContext, (ctx) => ctx.reset(new Request("http://localhost")), poolSize);
89111
+ this.contextPool.prewarm(Math.min(32, poolSize));
89112
+ if (options.onError) {
89113
+ this.errorHandler = options.onError;
89114
+ }
89115
+ if (options.onNotFound) {
89116
+ this.notFoundHandler = options.onNotFound;
89117
+ }
89118
+ this.compileRoutes();
89119
+ }
89120
+ get(path4, ...handlers) {
89121
+ return this.addRoute("get", path4, handlers);
89122
+ }
89123
+ post(path4, ...handlers) {
89124
+ return this.addRoute("post", path4, handlers);
89125
+ }
89126
+ put(path4, ...handlers) {
89127
+ return this.addRoute("put", path4, handlers);
89128
+ }
89129
+ delete(path4, ...handlers) {
89130
+ return this.addRoute("delete", path4, handlers);
89131
+ }
89132
+ patch(path4, ...handlers) {
89133
+ return this.addRoute("patch", path4, handlers);
89134
+ }
89135
+ options(path4, ...handlers) {
89136
+ return this.addRoute("options", path4, handlers);
89137
+ }
89138
+ head(path4, ...handlers) {
89139
+ return this.addRoute("head", path4, handlers);
89140
+ }
89141
+ all(path4, ...handlers) {
89142
+ const methods = ["get", "post", "put", "delete", "patch", "options", "head"];
89143
+ for (const method of methods) {
89144
+ this.addRoute(method, path4, handlers);
89145
+ }
89146
+ return this;
89147
+ }
89148
+ use(pathOrMiddleware, ...middleware) {
89149
+ this.isPureStaticApp = false;
89150
+ if (typeof pathOrMiddleware === "string") {
89151
+ this.router.usePattern(pathOrMiddleware, ...middleware);
89152
+ } else {
89153
+ this.router.use(pathOrMiddleware, ...middleware);
89154
+ }
89155
+ return this;
89156
+ }
89157
+ route(_path, _app) {
89158
+ console.warn("route() method is not yet fully implemented");
89159
+ return this;
89160
+ }
89161
+ onError(handler) {
89162
+ this.errorHandler = handler;
89163
+ return this;
89164
+ }
89165
+ notFound(handler) {
89166
+ this.notFoundHandler = handler;
89167
+ return this;
89168
+ }
89169
+ fetch = (request) => {
89170
+ const path4 = extractPath(request.url);
89171
+ const method = request.method.toLowerCase();
89172
+ const staticKey = `${method}:${path4}`;
89173
+ const staticRoute = this.staticRoutes.get(staticKey);
89174
+ if (staticRoute) {
89175
+ if (staticRoute.useMinimal) {
89176
+ const ctx = new MinimalContext(request, {}, path4);
89177
+ try {
89178
+ const result = staticRoute.handler(ctx);
89179
+ if (result instanceof Response) {
89180
+ return result;
89181
+ }
89182
+ return result;
89183
+ } catch (error) {
89184
+ return this.handleErrorSync(error, request, path4);
89185
+ }
89186
+ }
89187
+ return this.handleWithMiddleware(request, path4, staticRoute);
89188
+ }
89189
+ return this.handleDynamicRoute(request, method, path4);
89190
+ };
89191
+ async handleWithMiddleware(request, path4, route) {
89192
+ const ctx = this.contextPool.acquire();
89193
+ try {
89194
+ ctx.reset(request, {});
89195
+ const middleware = this.collectMiddlewareForPath(path4, route.middleware);
89196
+ if (middleware.length === 0) {
89197
+ return await route.handler(ctx);
89198
+ }
89199
+ return await this.executeMiddleware(ctx, middleware, route.handler);
89200
+ } catch (error) {
89201
+ return await this.handleError(error, ctx);
89202
+ } finally {
89203
+ this.contextPool.release(ctx);
89204
+ }
89205
+ }
89206
+ handleDynamicRoute(request, method, path4) {
89207
+ const match2 = this.router.match(method.toUpperCase(), path4);
89208
+ if (!match2.handler) {
89209
+ return this.handleNotFoundSync(request, path4);
89210
+ }
89211
+ const ctx = this.contextPool.acquire();
89212
+ const execute = async () => {
89213
+ try {
89214
+ ctx.reset(request, match2.params);
89215
+ if (match2.middleware.length === 0) {
89216
+ return await match2.handler(ctx);
89217
+ }
89218
+ return await this.executeMiddleware(ctx, match2.middleware, match2.handler);
89219
+ } catch (error) {
89220
+ return await this.handleError(error, ctx);
89221
+ } finally {
89222
+ this.contextPool.release(ctx);
89223
+ }
89224
+ };
89225
+ return execute();
89226
+ }
89227
+ handleErrorSync(error, request, path4) {
89228
+ if (this.errorHandler) {
89229
+ const ctx = new MinimalContext(request, {}, path4);
89230
+ const result = this.errorHandler(error, ctx);
89231
+ if (result instanceof Response) {
89232
+ return result;
89233
+ }
89234
+ return result;
89235
+ }
89236
+ console.error("Unhandled error:", error);
89237
+ return new Response(JSON.stringify({
89238
+ error: "Internal Server Error",
89239
+ message: error.message
89240
+ }), {
89241
+ status: 500,
89242
+ headers: { "Content-Type": "application/json" }
89243
+ });
89244
+ }
89245
+ handleNotFoundSync(request, path4) {
89246
+ if (this.notFoundHandler) {
89247
+ const ctx = new MinimalContext(request, {}, path4);
89248
+ const result = this.notFoundHandler(ctx);
89249
+ if (result instanceof Response) {
89250
+ return result;
89251
+ }
89252
+ return result;
89253
+ }
89254
+ return new Response(JSON.stringify({ error: "Not Found" }), {
89255
+ status: 404,
89256
+ headers: { "Content-Type": "application/json" }
89257
+ });
89258
+ }
89259
+ collectMiddlewareForPath(path4, routeMiddleware) {
89260
+ if (this.router.globalMiddleware.length === 0 && this.router.pathMiddleware.size === 0) {
89261
+ return routeMiddleware;
89262
+ }
89263
+ return this.router.collectMiddlewarePublic(path4, routeMiddleware);
89264
+ }
89265
+ compileRoutes() {
89266
+ this.staticRoutes = this.router.staticRoutes;
89267
+ const hasGlobalMiddleware = this.router.globalMiddleware.length > 0;
89268
+ const hasPathMiddleware = this.router.pathMiddleware.size > 0;
89269
+ this.isPureStaticApp = !hasGlobalMiddleware && !hasPathMiddleware;
89270
+ for (const [_key, route] of this.staticRoutes) {
89271
+ const analysis = analyzeHandler(route.handler);
89272
+ const optimalType = getOptimalContextType(analysis);
89273
+ route.useMinimal = this.isPureStaticApp && route.middleware.length === 0 && optimalType === "minimal";
89274
+ }
89275
+ }
89276
+ addRoute(method, path4, handlers) {
89277
+ if (handlers.length === 0) {
89278
+ throw new Error(`No handler provided for ${method.toUpperCase()} ${path4}`);
89279
+ }
89280
+ const handler = handlers[handlers.length - 1];
89281
+ const middleware = handlers.slice(0, -1);
89282
+ this.router.add(method, path4, handler, middleware);
89283
+ this.compileRoutes();
89284
+ return this;
89285
+ }
89286
+ async executeMiddleware(ctx, middleware, handler) {
89287
+ let index = 0;
89288
+ const next = async () => {
89289
+ if (index < middleware.length) {
89290
+ const mw = middleware[index++];
89291
+ return await mw(ctx, next);
89292
+ }
89293
+ return;
89294
+ };
89295
+ const result = await next();
89296
+ if (result instanceof Response) {
89297
+ return result;
89298
+ }
89299
+ return await handler(ctx);
89300
+ }
89301
+ async handleError(error, ctx) {
89302
+ if (this.errorHandler) {
89303
+ return await this.errorHandler(error, ctx);
89304
+ }
89305
+ console.error("Unhandled error:", error);
89306
+ return ctx.json({
89307
+ error: "Internal Server Error",
89308
+ message: error.message
89309
+ }, 500);
89310
+ }
89311
+ }
88447
89312
  // ../core/src/index.ts
88448
89313
  var VERSION = package_default.version;
88449
89314
 
@@ -88993,6 +89858,11 @@ async function initCommand(options = {}) {
88993
89858
  label: "\uD83C\uDFDB\uFE0F Domain-Driven Design (DDD)",
88994
89859
  hint: "\u5B8C\u6574\u7684 DDD \u67B6\u69CB\uFF0C\u5305\u542B Modules\u3001Bounded Contexts"
88995
89860
  },
89861
+ {
89862
+ value: "standalone-engine",
89863
+ label: "\uD83D\uDE80 Standalone Engine",
89864
+ hint: "\u7D14\u6DE8\u7684\u9AD8\u6027\u80FD\u5F15\u64CE\uFF0C\u7121\u6846\u67B6\u4F9D\u8CF4 (Pure High-Performance Engine)"
89865
+ },
88996
89866
  {
88997
89867
  value: "action-domain",
88998
89868
  label: "\u26A1 Action-Domain-Responder (ADR)",
@@ -89106,7 +89976,8 @@ async function initCommand(options = {}) {
89106
89976
  clean: "\uD83E\uDDC5 Clean Architecture",
89107
89977
  ddd: "\uD83C\uDFDB\uFE0F Domain-Driven Design",
89108
89978
  satellite: "\uD83D\uDEF0\uFE0F Satellite Service",
89109
- "action-domain": "\u26A1 Action-Domain-Responder"
89979
+ "action-domain": "\u26A1 Action-Domain-Responder",
89980
+ "standalone-engine": "\uD83D\uDE80 Standalone Engine"
89110
89981
  };
89111
89982
  note2(`\u5C08\u6848\u540D\u7A31: ${pc3.cyan(projectName)}
89112
89983
  \u67B6\u69CB\u6A21\u5F0F: ${pc3.green(archLabels[architecture])}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/pulse",
3
- "version": "1.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "The official CLI for Gravito Galaxy Architecture. Scaffold projects and manage your universe.",
5
5
  "bin": {
6
6
  "gravito": "bin/gravito.mjs"