@awsless/awsless 0.0.113 → 0.0.114

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/bin.js CHANGED
@@ -3399,6 +3399,8 @@ var graphqlPlugin = definePlugin({
3399
3399
  ).optional()
3400
3400
  }).array()
3401
3401
  }),
3402
+ onTypeGen({ config: config2 }) {
3403
+ },
3402
3404
  onApp(ctx) {
3403
3405
  const { config: config2, bootstrap: bootstrap2 } = ctx;
3404
3406
  const apis = /* @__PURE__ */ new Set();
@@ -4511,11 +4513,20 @@ var httpPlugin = definePlugin({
4511
4513
  }
4512
4514
  resources.addType(id, idType);
4513
4515
  }
4514
- types2.addCode(`type Query<F> = Parameters<F>[0]['request']['query']`);
4515
- types2.addCode(`type Body<F> = Parameters<F>[0]['request']['body']`);
4516
- types2.addCode(`type Response<F> = Awaited<ReturnType<F>>`);
4517
- types2.addCode(`type Route<F, P> = { param: P, query: Query<F>, body: Body<F>, response: Response<F> }`);
4518
- types2.addInterface("Http", resources);
4516
+ const code = [
4517
+ `import { InvokeResponse } from '@awsless/lambda'`,
4518
+ `type Function = (...args: any) => any`,
4519
+ `type Event<F extends Function> = Parameters<F>[0]`,
4520
+ `type RequestWithQuery = { request: { queryStringParameters: any } }`,
4521
+ `type RequestWithBody = { request: { body: any } }`,
4522
+ `type ResponseWithBody = { statusCode: number, body: any }`,
4523
+ `type Query<F extends Function> = Event<F> extends RequestWithQuery ? Event<F>['request']['queryStringParameters'] : never`,
4524
+ `type Body<F extends Function> = Event<F> extends RequestWithBody ? Exclude<Event<F>['request']['body'], string> : never`,
4525
+ `type Response<F extends Function> = Awaited<InvokeResponse<F>> extends ResponseWithBody ? Promise<Awaited<InvokeResponse<F>>['body']> : Promise<never>`,
4526
+ `type Route<F extends Function, P> = { param: P; query: Query<F>; body: Body<F>; response: Response<F> }`
4527
+ ];
4528
+ code.map((code2) => types2.addCode(code2));
4529
+ types2.addInterface("HTTP", resources);
4519
4530
  return types2.toString();
4520
4531
  },
4521
4532
  onApp({ config: config2, bootstrap: bootstrap2 }) {
package/dist/index.d.ts CHANGED
@@ -11241,7 +11241,7 @@ interface SearchResources {
11241
11241
  }
11242
11242
  declare const Search: SearchResources;
11243
11243
 
11244
- interface Http {
11244
+ interface HTTP {
11245
11245
  }
11246
11246
  type Method = 'GET' | 'POST';
11247
11247
  type Path = string;
@@ -11263,21 +11263,19 @@ type Props<R extends Route> = {
11263
11263
  query?: R['query'] extends Query ? R['query'] : never;
11264
11264
  body?: R['body'] extends Body ? R['body'] : never;
11265
11265
  };
11266
- type HttpClientHandle = (props: {
11266
+ type HttpFetcher = (props: {
11267
11267
  method: Method;
11268
11268
  path: Path;
11269
11269
  headers: Headers;
11270
11270
  query?: Query;
11271
11271
  body?: Body;
11272
11272
  }) => unknown;
11273
- declare const simpleHttpHandler: (host: string) => HttpClientHandle;
11274
- declare class HttpClient<S extends Schema> {
11275
- private handle;
11276
- constructor(handle: HttpClientHandle);
11277
- fetch<M extends keyof S, P extends keyof S[M]>(method: M, routeKey: Extract<P, string>, props?: Props<GetRoute<S, M, P>>): Promise<GetRoute<S, M, P>["response"]>;
11278
- get<P extends keyof S['GET']>(routeKey: Extract<P, string>, props?: Props<GetRoute<S, 'GET', P>>): Promise<GetRoute<S, "GET", P>["response"]>;
11279
- post<P extends keyof S['POST']>(routeKey: Extract<P, string>, props?: Props<GetRoute<S, 'POST', P>>): Promise<GetRoute<S, "POST", P>["response"]>;
11280
- }
11273
+ declare const createHttpFetcher: (host: string) => HttpFetcher;
11274
+ declare const createHttpClient: <S extends Partial<Record<Method, Routes>>>(fetcher: HttpFetcher) => {
11275
+ fetch: <M extends keyof S, P extends keyof S[M]>(method: M, routeKey: Extract<P, string>, props?: Props<GetRoute<S, M, P>> | undefined) => Promise<GetRoute<S, M, P>["response"]>;
11276
+ get<P_1 extends keyof S["GET"]>(routeKey: Extract<P_1, string>, props?: Props<GetRoute<S, "GET", P_1>> | undefined): Promise<GetRoute<S, "GET", P_1>["response"]>;
11277
+ post<P_2 extends keyof S["POST"]>(routeKey: Extract<P_2, string>, props?: Props<GetRoute<S, "POST", P_2>> | undefined): Promise<GetRoute<S, "POST", P_2>["response"]>;
11278
+ };
11281
11279
 
11282
11280
  type FunctionProps<H extends Handler<S>, S extends BaseSchema> = {
11283
11281
  handle: H;
@@ -12139,4 +12137,4 @@ declare const defineStackConfig: (config: StackConfig) => StackConfig$1 | (Stack
12139
12137
  });
12140
12138
  declare const defineAppConfig: (config: AppConfig | AppConfigFactory<AppConfig>) => CombinedDefaultPluginsConfigInput | AppConfigFactory<CombinedDefaultPluginsConfigInput>;
12141
12139
 
12142
- export { APP, AppConfig, Auth, AuthResources, Cache, CacheResources, Config, ConfigResources, CronProps, Fn, Function, FunctionMock, FunctionMockResponse, FunctionProps, FunctionResources, Http, HttpClient, HttpClientHandle, Plugin, Queue, QueueMock, QueueMockResponse, QueueProps, QueueResources, STACK, Search, SearchResources, StackConfig, Store, StoreResources, Table, TableResources, Topic, TopicMock, TopicMockResponse, TopicProps, TopicResources, cron, defineAppConfig, definePlugin, defineStackConfig, func, getAuthName, getAuthProps, getCacheProps, getConfigName, getFunctionName, getGlobalResourceName, getLocalResourceName, getQueueName, getSearchName, getStoreName, getTableName, getTopicName, mockFunction, mockQueue, mockTopic, queue, simpleHttpHandler, topic };
12140
+ export { APP, AppConfig, Auth, AuthResources, Cache, CacheResources, Config, ConfigResources, CronProps, Fn, Function, FunctionMock, FunctionMockResponse, FunctionProps, FunctionResources, HTTP, HttpFetcher, Plugin, Queue, QueueMock, QueueMockResponse, QueueProps, QueueResources, STACK, Search, SearchResources, StackConfig, Store, StoreResources, Table, TableResources, Topic, TopicMock, TopicMockResponse, TopicProps, TopicResources, createHttpClient, createHttpFetcher, cron, defineAppConfig, definePlugin, defineStackConfig, func, getAuthName, getAuthProps, getCacheProps, getConfigName, getFunctionName, getGlobalResourceName, getLocalResourceName, getQueueName, getSearchName, getStoreName, getTableName, getTopicName, mockFunction, mockQueue, mockTopic, queue, topic };
package/dist/index.js CHANGED
@@ -251,7 +251,7 @@ var Search = /* @__PURE__ */ createProxy((stack) => {
251
251
  });
252
252
 
253
253
  // src/node/http.ts
254
- var simpleHttpHandler = (host) => {
254
+ var createHttpFetcher = (host) => {
255
255
  return async ({ method, path, headers, body, query }) => {
256
256
  const url = new URL(host, path);
257
257
  if (query) {
@@ -269,28 +269,28 @@ var simpleHttpHandler = (host) => {
269
269
  return result;
270
270
  };
271
271
  };
272
- var HttpClient = class {
273
- constructor(handle) {
274
- this.handle = handle;
275
- }
276
- fetch(method, routeKey, props) {
272
+ var createHttpClient = (fetcher) => {
273
+ const fetch2 = (method, routeKey, props) => {
277
274
  const path = routeKey.replaceAll(/{([a-z0-1-]+)}/, (key) => {
278
275
  return props?.params?.[key.substring(1, key.length - 1)].toString() ?? "";
279
276
  });
280
- return this.handle({
277
+ return fetcher({
281
278
  headers: new Headers(props?.headers),
282
279
  query: props?.query,
283
280
  body: props?.body,
284
281
  method,
285
282
  path
286
283
  });
287
- }
288
- get(routeKey, props) {
289
- return this.fetch("GET", routeKey, props);
290
- }
291
- post(routeKey, props) {
292
- return this.fetch("POST", routeKey, props);
293
- }
284
+ };
285
+ return {
286
+ fetch: fetch2,
287
+ get(routeKey, props) {
288
+ return fetch2("GET", routeKey, props);
289
+ },
290
+ post(routeKey, props) {
291
+ return fetch2("POST", routeKey, props);
292
+ }
293
+ };
294
294
  };
295
295
 
296
296
  // src/node/handle/function.ts
@@ -401,13 +401,14 @@ export {
401
401
  Config,
402
402
  Fn,
403
403
  Function,
404
- HttpClient,
405
404
  Queue,
406
405
  STACK,
407
406
  Search,
408
407
  Store,
409
408
  Table,
410
409
  Topic,
410
+ createHttpClient,
411
+ createHttpFetcher,
411
412
  cron,
412
413
  defineAppConfig,
413
414
  definePlugin,
@@ -429,6 +430,5 @@ export {
429
430
  mockQueue,
430
431
  mockTopic,
431
432
  queue,
432
- simpleHttpHandler,
433
433
  topic
434
434
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.113",
3
+ "version": "0.0.114",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -25,12 +25,12 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@awsless/lambda": "^0.0.14",
28
+ "@awsless/redis": "^0.0.8",
28
29
  "@awsless/sns": "^0.0.7",
29
30
  "@awsless/sqs": "^0.0.7",
30
- "@awsless/redis": "^0.0.8",
31
+ "@awsless/ssm": "^0.0.7",
31
32
  "@awsless/validate": "^0.0.10",
32
- "@awsless/weak-cache": "^0.0.1",
33
- "@awsless/ssm": "^0.0.7"
33
+ "@awsless/weak-cache": "^0.0.1"
34
34
  },
35
35
  "dependencies": {
36
36
  "@aws-appsync/utils": "^1.5.0",