@ozanarslan/corpus 0.1.1 → 0.1.3

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
@@ -39,6 +39,7 @@ export type CookieOptions = {
39
39
  };
40
40
  export type CookiesInit = CookiesAbstract | CookieOptions | CookieOptions[];
41
41
  declare abstract class CookiesAbstract {
42
+ protected abstract map: Bun.CookieMap | Map<string, string>;
42
43
  abstract set(opts: CookieOptions): void;
43
44
  abstract get(name: string): string | null;
44
45
  abstract has(name: string): boolean;
@@ -52,11 +53,12 @@ declare abstract class CookiesAbstract {
52
53
  abstract keys(): Array<string>;
53
54
  abstract toSetCookieHeaders(): Array<string>;
54
55
  abstract setMany(optsArr: Array<CookieOptions>): void;
55
- applyInit(init: CookiesInit): void;
56
+ protected applyInit(init?: CookiesInit): void;
56
57
  }
57
- export declare class Cookies extends CookiesAbstract {
58
- private instance;
58
+ declare class CookiesUsingBun extends CookiesAbstract {
59
59
  constructor(init?: CookiesInit);
60
+ protected map: Bun.CookieMap;
61
+ toSetCookieHeaders(): Array<string>;
60
62
  set(opts: CookieOptions): void;
61
63
  setMany(optsArr: Array<CookieOptions>): void;
62
64
  get(name: string): string | null;
@@ -69,7 +71,8 @@ export declare class Cookies extends CookiesAbstract {
69
71
  ]>;
70
72
  values(): Array<string>;
71
73
  keys(): Array<string>;
72
- toSetCookieHeaders(): Array<string>;
74
+ }
75
+ export declare class Cookies extends CookiesUsingBun {
73
76
  }
74
77
  export type ValueOf<T> = T[keyof T];
75
78
  /** Just some common headers. */
@@ -602,13 +605,14 @@ declare abstract class ControllerAbstract {
602
605
  export type FileWalkerFile = {
603
606
  text(): Promise<string>;
604
607
  };
605
- export declare class FileWalker {
606
- private static instance;
608
+ declare class FileWalkerUsingBun {
607
609
  static read(address: string): Promise<string | null>;
608
610
  static exists(address: string): Promise<boolean>;
609
611
  static getExtension(address: string): string;
610
612
  static find(address: string): Promise<FileWalkerFile | null>;
611
613
  }
614
+ export declare class FileWalker extends FileWalkerUsingBun {
615
+ }
612
616
  declare class HttpError extends Error {
613
617
  message: string;
614
618
  status: Status;
@@ -774,15 +778,18 @@ declare abstract class ServerAbstract implements ServerInterface {
774
778
  protected handleNotFound: RequestHandler;
775
779
  protected handleMethodNotAllowed: RequestHandler;
776
780
  }
781
+ declare class ServerUsingBun extends ServerAbstract {
782
+ private app;
783
+ constructor();
784
+ serve(options: ServeOptions): void;
785
+ close(): Promise<void>;
786
+ private createApp;
787
+ }
777
788
  /**
778
789
  * Server is the entrypoint to the app. It must be initialized before registering routes and middlewares.
779
790
  * ".listen()" to start listening.
780
791
  */
781
- export declare class Server extends ServerAbstract {
782
- private instance;
783
- constructor();
784
- serve(options: ServeOptions): void;
785
- close(): Promise<void>;
792
+ export declare class Server extends ServerUsingBun {
786
793
  }
787
794
  declare class MiddlewareRegistry {
788
795
  private readonly map;
package/dist/index.js CHANGED
@@ -168973,6 +168973,8 @@ var CommonHeaders = {
168973
168973
  // src/Cookies/CookiesAbstract.ts
168974
168974
  class CookiesAbstract {
168975
168975
  applyInit(init) {
168976
+ if (!init)
168977
+ return;
168976
168978
  if (init instanceof CookiesAbstract) {
168977
168979
  for (const name of init.keys()) {
168978
168980
  const value = init.get(name) ?? "";
@@ -168992,9 +168994,7 @@ class CookiesAbstract {
168992
168994
  class CookiesUsingBun extends CookiesAbstract {
168993
168995
  constructor(init) {
168994
168996
  super();
168995
- if (init) {
168996
- this.applyInit(init);
168997
- }
168997
+ this.applyInit(init);
168998
168998
  }
168999
168999
  map = new Bun.CookieMap;
169000
169000
  toSetCookieHeaders() {
@@ -169032,42 +169032,7 @@ class CookiesUsingBun extends CookiesAbstract {
169032
169032
  }
169033
169033
 
169034
169034
  // src/Cookies/Cookies.ts
169035
- class Cookies extends CookiesAbstract {
169036
- instance;
169037
- constructor(init) {
169038
- super();
169039
- this.instance = new CookiesUsingBun(init);
169040
- }
169041
- set(opts) {
169042
- return this.instance.set(opts);
169043
- }
169044
- setMany(optsArr) {
169045
- return this.instance.setMany(optsArr);
169046
- }
169047
- get(name) {
169048
- return this.instance.get(name);
169049
- }
169050
- has(name) {
169051
- return this.instance.has(name);
169052
- }
169053
- get count() {
169054
- return this.instance.count;
169055
- }
169056
- delete(name) {
169057
- return this.instance.delete(name);
169058
- }
169059
- entries() {
169060
- return this.instance.entries();
169061
- }
169062
- values() {
169063
- return this.instance.values();
169064
- }
169065
- keys() {
169066
- return this.instance.keys();
169067
- }
169068
- toSetCookieHeaders() {
169069
- return this.instance.toSetCookieHeaders();
169070
- }
169035
+ class Cookies extends CookiesUsingBun {
169071
169036
  }
169072
169037
 
169073
169038
  // src/Headers/HttpHeaders.ts
@@ -169577,13 +169542,9 @@ class Route extends RouteAbstract {
169577
169542
  }
169578
169543
  }
169579
169544
 
169580
- // src/FileWalker/FileWalkerAbstract.ts
169581
- class FileWalkerAbstract {
169582
- }
169583
-
169584
169545
  // src/FileWalker/FileWalkerUsingBun.ts
169585
- class FileWalkerUsingBun extends FileWalkerAbstract {
169586
- async read(address) {
169546
+ class FileWalkerUsingBun {
169547
+ static async read(address) {
169587
169548
  try {
169588
169549
  const file = await this.find(address);
169589
169550
  if (!file)
@@ -169593,13 +169554,13 @@ class FileWalkerUsingBun extends FileWalkerAbstract {
169593
169554
  return null;
169594
169555
  }
169595
169556
  }
169596
- async exists(address) {
169557
+ static async exists(address) {
169597
169558
  return await this.find(address) !== null;
169598
169559
  }
169599
- getExtension(address) {
169560
+ static getExtension(address) {
169600
169561
  return address.split(".").pop() ?? "txt";
169601
169562
  }
169602
- async find(address) {
169563
+ static async find(address) {
169603
169564
  const file = Bun.file(address);
169604
169565
  const exists = await file.exists();
169605
169566
  if (exists) {
@@ -169610,20 +169571,7 @@ class FileWalkerUsingBun extends FileWalkerAbstract {
169610
169571
  }
169611
169572
 
169612
169573
  // src/FileWalker/FileWalker.ts
169613
- class FileWalker {
169614
- static instance = new FileWalkerUsingBun;
169615
- static read(address) {
169616
- return this.instance.read(address);
169617
- }
169618
- static exists(address) {
169619
- return this.instance.exists(address);
169620
- }
169621
- static getExtension(address) {
169622
- return this.instance.getExtension(address);
169623
- }
169624
- static find(address) {
169625
- return this.instance.find(address);
169626
- }
169574
+ class FileWalker extends FileWalkerUsingBun {
169627
169575
  }
169628
169576
 
169629
169577
  // src/JS/JS.ts
@@ -170311,11 +170259,20 @@ class ServerAbstract {
170311
170259
  // src/Server/ServerUsingBun.ts
170312
170260
  class ServerUsingBun extends ServerAbstract {
170313
170261
  app;
170262
+ constructor() {
170263
+ super();
170264
+ setRouterInstance(new Router);
170265
+ }
170314
170266
  serve(options) {
170315
170267
  this.app = this.createApp(options);
170316
170268
  }
170317
170269
  async close() {
170270
+ await this.handleBeforeClose?.();
170271
+ console.log("Closing...");
170318
170272
  await this.app?.stop();
170273
+ if (Config.nodeEnv !== "test") {
170274
+ process.exit(0);
170275
+ }
170319
170276
  }
170320
170277
  createApp(options) {
170321
170278
  return Bun.serve({
@@ -170327,20 +170284,7 @@ class ServerUsingBun extends ServerAbstract {
170327
170284
  }
170328
170285
 
170329
170286
  // src/Server/Server.ts
170330
- class Server extends ServerAbstract {
170331
- instance = new ServerUsingBun;
170332
- constructor() {
170333
- super();
170334
- setRouterInstance(new Router);
170335
- }
170336
- serve(options) {
170337
- return this.instance.serve(options);
170338
- }
170339
- async close() {
170340
- await this.handleBeforeClose?.();
170341
- console.log("Closing...");
170342
- return await this.instance.close();
170343
- }
170287
+ class Server extends ServerUsingBun {
170344
170288
  }
170345
170289
  // src/index.ts
170346
170290
  var RouterInstance;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ozanarslan/corpus",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.1.1",
5
+ "version": "0.1.3",
6
6
  "description": "Small Typescript backend framework with only core utilities",
7
7
  "author": "Ozan Arslan <ozanarslanwork@gmail.com>",
8
8
  "license": "MIT",