tspace-spear 1.2.5-beta.2 → 1.2.5-beta.4

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.
@@ -10,7 +10,7 @@ type RequestInput<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMetho
10
10
  query?: RequestQuery<TRoutes, TPath, TMethod>;
11
11
  files?: RequestFiles<TRoutes, TPath, TMethod>;
12
12
  };
13
- export declare class ApiClient<TRoutes extends AnyRoutes = AppRoutes> {
13
+ declare class ApiClient<TRoutes extends AnyRoutes = AppRoutes> {
14
14
  private baseURL;
15
15
  constructor(baseURL: string);
16
16
  protected request<TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]>(method: TMethod, path: TPath, input?: RequestInput<TRoutes, TPath, TMethod>): Promise<ResponseType<TRoutes, TPath, TMethod>>;
@@ -20,4 +20,5 @@ export declare class ApiClient<TRoutes extends AnyRoutes = AppRoutes> {
20
20
  patch<TPath extends RoutesWithMethod<TRoutes, "PATCH">>(path: TPath, input: RequestInput<TRoutes, TPath, "PATCH">): Promise<ResponseType<TRoutes, TPath, "PATCH">>;
21
21
  delete<TPath extends RoutesWithMethod<TRoutes, "DELETE">>(path: TPath, input?: RequestInput<TRoutes, TPath, "DELETE">): Promise<ResponseType<TRoutes, TPath, "DELETE">>;
22
22
  }
23
- export {};
23
+ export { ApiClient };
24
+ export default ApiClient;
@@ -7,7 +7,21 @@ class ApiClient {
7
7
  this.baseURL = baseURL;
8
8
  }
9
9
  async request(method, path, input) {
10
- const url = this.baseURL + String(path);
10
+ let url = this.baseURL + path;
11
+ //@ts-ignore
12
+ if (input?.params) {
13
+ //@ts-ignore
14
+ const params = input.params;
15
+ for (const key in params) {
16
+ url = url.replace(`:${key}`, encodeURIComponent(params[key]));
17
+ }
18
+ }
19
+ if (input?.query) {
20
+ const queryString = new URLSearchParams(input.query).toString();
21
+ if (queryString) {
22
+ url += `?${queryString}`;
23
+ }
24
+ }
11
25
  const res = await fetch(url, {
12
26
  method: method,
13
27
  headers: {
@@ -48,4 +62,5 @@ class ApiClient {
48
62
  }
49
63
  }
50
64
  exports.ApiClient = ApiClient;
65
+ exports.default = ApiClient;
51
66
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/client/index.ts"],"names":[],"mappings":";;;AAmEA,MAAa,SAAS;IAIZ,OAAO,CAAS;IAExB,YAAY,OAAe;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,OAAO,CAIrB,MAAe,EACf,IAAW,EACX,KAIC;QAQD,MAAM,GAAG,GACP,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAE9B,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAC3B,MAAM,EAAE,MAAgB;YAExB,OAAO,EAAE;gBACP,cAAc,EACZ,kBAAkB;aACrB;YAED,IAAI,EAAE,KAAK,EAAE,IAAI;gBACf,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC5B,CAAC,CAAC,SAAS;SACd,CAAC,CAAC;QAEH,MAAM,WAAW,GACf,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAElC,MAAM,MAAM,GACV,WAAW,EAAE,QAAQ,CACnB,kBAAkB,CACnB,CAAC;QAEJ,MAAM,IAAI,GAAG,MAAM;YACjB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE;YAClB,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAErB,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CACb,IAAI,EAAE,OAAO;gBACX,IAAI,EAAE,KAAK;gBACX,CAAC,OAAO,IAAI,KAAK,QAAQ;oBACvB,CAAC,CAAC,IAAI;oBACN,CAAC,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAC5B,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,GAAG,CAMd,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,IAAI,CAMf,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,MAAM,EACN,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,GAAG,CAMd,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,KAAK,CAMhB,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,OAAO,EACP,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,MAAM,CAMjB,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,QAAQ,EACR,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;CACF;AAxKD,8BAwKC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/client/index.ts"],"names":[],"mappings":";;;AAkCA,MAAM,SAAS;IAGL,OAAO,CAAS;IAExB,YAAY,OAAe;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,OAAO,CAIrB,MAAe,EACf,IAAW,EACX,KAIC;QASC,IAAI,GAAG,GAAG,IAAI,CAAC,OAAO,GAAI,IAAe,CAAA;QAEzC,YAAY;QACZ,IAAI,KAAK,EAAE,MAAM,EAAE,CAAC;YAClB,YAAY;YACZ,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;YAE3B,KAAK,MAA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O,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,GAAG,CAMd,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,IAAI,CAMf,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,MAAM,EACN,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,GAAG,CAMd,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,KAAK,EACL,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,KAAK,CAMhB,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,OAAO,EACP,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,MAAM,CAMjB,IAAW,EACX,KAIC;QAED,OAAO,IAAI,CAAC,OAAO,CACjB,QAAQ,EACR,IAAI,EACJ,KAAK,CACN,CAAC;IACJ,CAAC;CACF;AAEQ,8BAAS;AAClB,kBAAe,SAAS,CAAC"}
@@ -97,10 +97,7 @@ export interface AppRoutes {
97
97
  "/dogs": {
98
98
  GET: {
99
99
  params: never;
100
- query: {
101
- id: string;
102
- name?: string;
103
- };
100
+ query: never;
104
101
  body: Record<string, any>;
105
102
  files: never;
106
103
  response: Promise<{
@@ -130,7 +127,10 @@ export interface AppRoutes {
130
127
  params: {
131
128
  id: string;
132
129
  };
133
- query: never;
130
+ query: {
131
+ id: string;
132
+ name?: string;
133
+ };
134
134
  body: Record<string, any>;
135
135
  files: never;
136
136
  response: Promise<{
@@ -139,6 +139,18 @@ export interface AppRoutes {
139
139
  };
140
140
  }>;
141
141
  };
142
+ DELETE: {
143
+ params: {
144
+ id: string;
145
+ };
146
+ query: never;
147
+ body: Record<string, any>;
148
+ files: never;
149
+ response: Promise<{
150
+ message: string;
151
+ id: number;
152
+ }>;
153
+ };
142
154
  };
143
155
  }
144
156
  export type AppRoute = keyof AppRoutes;
@@ -8,5 +8,4 @@ export * from './core/decorators';
8
8
  export * from './core/types';
9
9
  export * from './core/server';
10
10
  export * from './core/server/router';
11
- export * from './core/client';
12
11
  export default Spear;
package/dist/lib/index.js CHANGED
@@ -27,6 +27,5 @@ __exportStar(require("./core/decorators"), exports);
27
27
  __exportStar(require("./core/types"), exports);
28
28
  __exportStar(require("./core/server"), exports);
29
29
  __exportStar(require("./core/server/router"), exports);
30
- __exportStar(require("./core/client"), exports);
31
30
  exports.default = server_1.default;
32
31
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;IAII;AACJ,2DAAkC;AAElC,oDAAkC;AAClC,+CAA6B;AAC7B,gDAA8B;AAC9B,uDAAqC;AACrC,gDAA6B;AAE7B,kBAAe,gBAAK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;IAII;AACJ,2DAAkC;AAElC,oDAAkC;AAClC,+CAA6B;AAC7B,gDAA8B;AAC9B,uDAAqC;AAErC,kBAAe,gBAAK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tspace-spear",
3
- "version": "1.2.5-beta.2",
3
+ "version": "1.2.5-beta.4",
4
4
  "description": "tspace-spear is a lightweight, high-performance API framework for Node.js that leverages the native HTTP server and supports uWebSockets.js (C++) for maximum speed and efficiency.",
5
5
  "main": "./dist/lib/index.js",
6
6
  "types": "./dist/lib/index.d.ts",
@@ -47,17 +47,14 @@
47
47
  },
48
48
  "exports": {
49
49
  ".": {
50
- "types": "./dist/index.d.ts",
51
- "import": "./dist/index.js"
50
+ "types": "./dist/lib/index.d.ts",
51
+ "import": "./dist/lib/index.js",
52
+ "require": "./dist/lib/index.js"
52
53
  },
53
-
54
54
  "./client": {
55
- "types": "./dist/client/index.d.ts",
56
- "import": "./dist/client/index.js"
57
- },
58
- "./server": {
59
- "types": "./dist/server/index.d.ts",
60
- "import": "./dist/server/index.js"
55
+ "types": "./dist/lib/core/client/index.d.ts",
56
+ "import": "./dist/lib/core/client/index.js",
57
+ "require": "./dist/lib/core/client/index.js"
61
58
  }
62
59
  },
63
60
  "engines": {