@awsless/awsless 0.0.113 → 0.0.115

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
@@ -1333,20 +1333,29 @@ import { relative as relative2 } from "path";
1333
1333
 
1334
1334
  // src/util/type-gen.ts
1335
1335
  import { mkdir, writeFile } from "fs/promises";
1336
- import { join as join4, relative } from "path";
1336
+ import { dirname as dirname3, join as join4, relative } from "path";
1337
1337
  import { camelCase, constantCase as constantCase3 } from "change-case";
1338
1338
  var generateResourceTypes = async (config2) => {
1339
1339
  const plugins = [...defaultPlugins, ...config2.plugins || []];
1340
1340
  const files = [];
1341
- for (const plugin of plugins) {
1342
- const code = plugin.onTypeGen?.({ config: config2 });
1343
- if (code) {
1344
- const file = join4(directories.types, `${plugin.name}.d.ts`);
1345
- files.push(relative(directories.root, file));
1346
- await mkdir(directories.types, { recursive: true });
1347
- await writeFile(file, code);
1348
- }
1349
- }
1341
+ await Promise.all(
1342
+ plugins.map((plugin) => {
1343
+ return plugin.onTypeGen?.({
1344
+ config: config2,
1345
+ async write(file, data, include = false) {
1346
+ const code = data?.toString("utf8");
1347
+ const path = join4(directories.types, file);
1348
+ if (code) {
1349
+ if (include) {
1350
+ files.push(relative(directories.root, path));
1351
+ }
1352
+ await mkdir(dirname3(path), { recursive: true });
1353
+ await writeFile(path, code);
1354
+ }
1355
+ }
1356
+ });
1357
+ })
1358
+ );
1350
1359
  if (files.length) {
1351
1360
  const code = files.map((file) => `/// <reference path='${file}' />`).join("\n");
1352
1361
  await writeFile(join4(directories.root, `awsless.d.ts`), code);
@@ -1390,7 +1399,10 @@ var TypeGen = class {
1390
1399
  ...[
1391
1400
  "// Imports",
1392
1401
  ...Array.from(this.imports.entries()).map(([varName, path]) => {
1393
- return `import ${camelCase(varName)} from '${path}'`;
1402
+ if (typeof varName === "string") {
1403
+ return `import ${camelCase(varName)} from '${path}'`;
1404
+ }
1405
+ return `import { ${Object.entries(varName).map(([key, alias]) => `${key} as ${camelCase(alias)}`).join(", ")} } from '${path}'`;
1394
1406
  }),
1395
1407
  ""
1396
1408
  ]
@@ -1685,7 +1697,7 @@ type MockObject<F extends Func> = Mock<Parameters<F>, ReturnType<F>>
1685
1697
  var functionPlugin = definePlugin({
1686
1698
  name: "function",
1687
1699
  schema,
1688
- onTypeGen({ config: config2 }) {
1700
+ async onTypeGen({ config: config2, write }) {
1689
1701
  const types2 = new TypeGen("@awsless/awsless");
1690
1702
  const resources = new TypeObject(1);
1691
1703
  const mocks = new TypeObject(1);
@@ -1712,7 +1724,7 @@ var functionPlugin = definePlugin({
1712
1724
  types2.addInterface("FunctionResources", resources);
1713
1725
  types2.addInterface("FunctionMock", mocks);
1714
1726
  types2.addInterface("FunctionMockResponse", mockResponses);
1715
- return types2.toString();
1727
+ await write("function.d.ts", types2, true);
1716
1728
  },
1717
1729
  onStack(ctx) {
1718
1730
  const { config: config2, stack } = ctx;
@@ -2096,7 +2108,7 @@ var queuePlugin = definePlugin({
2096
2108
  ).optional()
2097
2109
  }).array()
2098
2110
  }),
2099
- onTypeGen({ config: config2 }) {
2111
+ async onTypeGen({ config: config2, write }) {
2100
2112
  const gen = new TypeGen("@awsless/awsless");
2101
2113
  const resources = new TypeObject(1);
2102
2114
  const mocks = new TypeObject(1);
@@ -2123,7 +2135,7 @@ var queuePlugin = definePlugin({
2123
2135
  gen.addInterface("QueueResources", resources);
2124
2136
  gen.addInterface("QueueMock", mocks);
2125
2137
  gen.addInterface("QueueMockResponse", mockResponses);
2126
- return gen.toString();
2138
+ await write("queue.d.ts", gen, true);
2127
2139
  },
2128
2140
  onStack(ctx) {
2129
2141
  const { stack, config: config2, stackConfig, bind } = ctx;
@@ -2396,7 +2408,7 @@ var tablePlugin = definePlugin({
2396
2408
  ).optional()
2397
2409
  }).array()
2398
2410
  }),
2399
- onTypeGen({ config: config2 }) {
2411
+ async onTypeGen({ config: config2, write }) {
2400
2412
  const gen = new TypeGen("@awsless/awsless");
2401
2413
  const resources = new TypeObject(1);
2402
2414
  for (const stack of config2.stacks) {
@@ -2408,7 +2420,7 @@ var tablePlugin = definePlugin({
2408
2420
  resources.addType(stack.name, list3);
2409
2421
  }
2410
2422
  gen.addInterface("TableResources", resources);
2411
- return gen.toString();
2423
+ await write("table.d.ts", gen, true);
2412
2424
  },
2413
2425
  onStack(ctx) {
2414
2426
  const { config: config2, stack, stackConfig, bind } = ctx;
@@ -2530,7 +2542,7 @@ var storePlugin = definePlugin({
2530
2542
  stores: z10.array(ResourceIdSchema).optional()
2531
2543
  }).array()
2532
2544
  }),
2533
- onTypeGen({ config: config2 }) {
2545
+ async onTypeGen({ config: config2, write }) {
2534
2546
  const gen = new TypeGen("@awsless/awsless");
2535
2547
  const resources = new TypeObject(1);
2536
2548
  for (const stack of config2.stacks) {
@@ -2542,7 +2554,7 @@ var storePlugin = definePlugin({
2542
2554
  resources.addType(stack.name, list3);
2543
2555
  }
2544
2556
  gen.addInterface("StoreResources", resources);
2545
- return gen.toString();
2557
+ await write("store.d.ts", gen, true);
2546
2558
  },
2547
2559
  onStack({ config: config2, stack, stackConfig, bootstrap: bootstrap2, bind }) {
2548
2560
  for (const id of stackConfig.stores || []) {
@@ -2701,7 +2713,7 @@ var topicPlugin = definePlugin({
2701
2713
  }
2702
2714
  })
2703
2715
  }),
2704
- onTypeGen({ config: config2 }) {
2716
+ async onTypeGen({ config: config2, write }) {
2705
2717
  const gen = new TypeGen("@awsless/awsless");
2706
2718
  const resources = new TypeObject(1);
2707
2719
  const mocks = new TypeObject(1);
@@ -2718,7 +2730,7 @@ var topicPlugin = definePlugin({
2718
2730
  gen.addInterface("TopicResources", resources);
2719
2731
  gen.addInterface("TopicMock", mocks);
2720
2732
  gen.addInterface("TopicMockResponse", mockResponses);
2721
- return gen.toString();
2733
+ await write("topic.d.ts", gen, true);
2722
2734
  },
2723
2735
  onApp({ config: config2, bootstrap: bootstrap2 }) {
2724
2736
  for (const stack of config2.stacks) {
@@ -3070,7 +3082,7 @@ import { swc as swc2, minify as swcMinify2 } from "rollup-plugin-swc3";
3070
3082
  import json2 from "@rollup/plugin-json";
3071
3083
  import commonjs2 from "@rollup/plugin-commonjs";
3072
3084
  import nodeResolve2 from "@rollup/plugin-node-resolve";
3073
- import { dirname as dirname3 } from "path";
3085
+ import { dirname as dirname4 } from "path";
3074
3086
  var rollupResolver = ({ minify = true } = {}) => {
3075
3087
  return async (input) => {
3076
3088
  const bundle = await rollup2({
@@ -3093,7 +3105,7 @@ var rollupResolver = ({ minify = true } = {}) => {
3093
3105
  // minify,
3094
3106
  // module: true,
3095
3107
  jsc: {
3096
- baseUrl: dirname3(input),
3108
+ baseUrl: dirname4(input),
3097
3109
  minify: { sourceMap: true }
3098
3110
  },
3099
3111
  sourceMaps: true
@@ -3341,6 +3353,10 @@ var DomainNameApiAssociation = class extends Resource {
3341
3353
 
3342
3354
  // src/plugins/graphql.ts
3343
3355
  import { basename as basename2 } from "path";
3356
+ import { mergeTypeDefs as mergeTypeDefs2 } from "@graphql-tools/merge";
3357
+ import { generate } from "@awsless/graphql";
3358
+ import { buildSchema, print as print2 } from "graphql";
3359
+ import { readFile as readFile4 } from "fs/promises";
3344
3360
  var defaultResolver = Code2.fromInline(
3345
3361
  "graphql-default-resolver",
3346
3362
  `
@@ -3357,6 +3373,17 @@ export function response(ctx) {
3357
3373
  `
3358
3374
  );
3359
3375
  var resolverCache = /* @__PURE__ */ new Map();
3376
+ var scalarSchema = `
3377
+ scalar AWSDate
3378
+ scalar AWSTime
3379
+ scalar AWSDateTime
3380
+ scalar AWSTimestamp
3381
+ scalar AWSEmail
3382
+ scalar AWSJSON
3383
+ scalar AWSURL
3384
+ scalar AWSPhone
3385
+ scalar AWSIPAddress
3386
+ `;
3360
3387
  var graphqlPlugin = definePlugin({
3361
3388
  name: "graphql",
3362
3389
  schema: z15.object({
@@ -3399,6 +3426,52 @@ var graphqlPlugin = definePlugin({
3399
3426
  ).optional()
3400
3427
  }).array()
3401
3428
  }),
3429
+ async onTypeGen({ config: config2, write }) {
3430
+ const types2 = new TypeGen("@awsless/awsless");
3431
+ const resources = new TypeObject(1);
3432
+ const apis = /* @__PURE__ */ new Map();
3433
+ for (const stack of config2.stacks) {
3434
+ for (const id of Object.keys(stack.graphql || {})) {
3435
+ apis.set(id, []);
3436
+ }
3437
+ }
3438
+ for (const stack of config2.stacks) {
3439
+ for (const [id, props] of Object.entries(stack.graphql || {})) {
3440
+ if (props.schema) {
3441
+ apis.get(id)?.push(...[props.schema].flat());
3442
+ }
3443
+ }
3444
+ }
3445
+ for (const [id, files] of apis) {
3446
+ const sources = await Promise.all(
3447
+ files.map((file) => {
3448
+ return readFile4(file, "utf8");
3449
+ })
3450
+ );
3451
+ if (sources.length) {
3452
+ const defs = mergeTypeDefs2([scalarSchema, ...sources]);
3453
+ const schema2 = buildSchema(print2(defs));
3454
+ const output = generate(schema2, {
3455
+ scalarTypes: {
3456
+ AWSDate: "string",
3457
+ AWSTime: "string",
3458
+ AWSDateTime: "string",
3459
+ AWSTimestamp: "number",
3460
+ AWSEmail: "string",
3461
+ AWSJSON: "string",
3462
+ AWSURL: "string",
3463
+ AWSPhone: "string",
3464
+ AWSIPAddress: "string"
3465
+ }
3466
+ });
3467
+ await write(`graphql/${id}.d.ts`, output);
3468
+ types2.addImport({ Schema: id }, `./graphql/${id}.d.ts`);
3469
+ resources.addConst(id, id);
3470
+ }
3471
+ }
3472
+ types2.addInterface("GraphQL", resources);
3473
+ await write("graphql.d.ts", types2, true);
3474
+ },
3402
3475
  onApp(ctx) {
3403
3476
  const { config: config2, bootstrap: bootstrap2 } = ctx;
3404
3477
  const apis = /* @__PURE__ */ new Set();
@@ -4476,7 +4549,7 @@ var httpPlugin = definePlugin({
4476
4549
  http: z18.record(ResourceIdSchema, z18.record(RouteSchema, FunctionSchema)).optional()
4477
4550
  }).array()
4478
4551
  }),
4479
- onTypeGen({ config: config2 }) {
4552
+ async onTypeGen({ config: config2, write }) {
4480
4553
  const types2 = new TypeGen("@awsless/awsless");
4481
4554
  const resources = new TypeObject(1);
4482
4555
  const api = {};
@@ -4511,12 +4584,21 @@ var httpPlugin = definePlugin({
4511
4584
  }
4512
4585
  resources.addType(id, idType);
4513
4586
  }
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);
4519
- return types2.toString();
4587
+ const code = [
4588
+ `import { InvokeResponse } from '@awsless/lambda'`,
4589
+ `type Function = (...args: any) => any`,
4590
+ `type Event<F extends Function> = Parameters<F>[0]`,
4591
+ `type RequestWithQuery = { request: { queryStringParameters: any } }`,
4592
+ `type RequestWithBody = { request: { body: any } }`,
4593
+ `type ResponseWithBody = { statusCode: number, body: any }`,
4594
+ `type Query<F extends Function> = Event<F> extends RequestWithQuery ? Event<F>['request']['queryStringParameters'] : never`,
4595
+ `type Body<F extends Function> = Event<F> extends RequestWithBody ? Exclude<Event<F>['request']['body'], string> : never`,
4596
+ `type Response<F extends Function> = Awaited<InvokeResponse<F>> extends ResponseWithBody ? Promise<Awaited<InvokeResponse<F>>['body']> : Promise<never>`,
4597
+ `type Route<F extends Function, P> = { param: P; query: Query<F>; body: Body<F>; response: Response<F> }`
4598
+ ];
4599
+ code.map((code2) => types2.addCode(code2));
4600
+ types2.addInterface("HTTP", resources);
4601
+ await write("http.d.ts", types2, true);
4520
4602
  },
4521
4603
  onApp({ config: config2, bootstrap: bootstrap2 }) {
4522
4604
  if (Object.keys(config2.defaults?.http || {}).length === 0) {
@@ -4643,7 +4725,7 @@ var searchPlugin = definePlugin({
4643
4725
  searchs: z19.array(ResourceIdSchema).optional()
4644
4726
  }).array()
4645
4727
  }),
4646
- onTypeGen({ config: config2 }) {
4728
+ async onTypeGen({ config: config2, write }) {
4647
4729
  const gen = new TypeGen("@awsless/awsless");
4648
4730
  const resources = new TypeObject(1);
4649
4731
  for (const stack of config2.stacks) {
@@ -4655,7 +4737,7 @@ var searchPlugin = definePlugin({
4655
4737
  resources.addType(stack.name, list3);
4656
4738
  }
4657
4739
  gen.addInterface("SearchResources", resources);
4658
- return gen.toString();
4740
+ await write("search.d.ts", gen, true);
4659
4741
  },
4660
4742
  onStack({ config: config2, stack, stackConfig, bind }) {
4661
4743
  for (const id of stackConfig.searchs || []) {
@@ -4797,7 +4879,7 @@ var cachePlugin = definePlugin({
4797
4879
  ).optional()
4798
4880
  }).array()
4799
4881
  }),
4800
- onTypeGen({ config: config2 }) {
4882
+ async onTypeGen({ config: config2, write }) {
4801
4883
  const gen = new TypeGen("@awsless/awsless");
4802
4884
  const resources = new TypeObject(1);
4803
4885
  for (const stack of config2.stacks) {
@@ -4809,7 +4891,7 @@ var cachePlugin = definePlugin({
4809
4891
  }
4810
4892
  gen.addCode(typeGenCode4);
4811
4893
  gen.addInterface("CacheResources", resources);
4812
- return gen.toString();
4894
+ await write("cache.d.ts", gen, true);
4813
4895
  },
4814
4896
  onStack({ config: config2, stack, stackConfig, bootstrap: bootstrap2, bind }) {
4815
4897
  for (const [id, props] of Object.entries(stackConfig.caches || {})) {
@@ -5221,7 +5303,7 @@ var configPlugin = definePlugin({
5221
5303
  configs: z23.array(ConfigNameSchema).optional()
5222
5304
  }).array()
5223
5305
  }),
5224
- onTypeGen({ config: config2 }) {
5306
+ async onTypeGen({ config: config2, write }) {
5225
5307
  const gen = new TypeGen("@awsless/awsless");
5226
5308
  const resources = new TypeObject(0, false);
5227
5309
  for (const stack of config2.stacks) {
@@ -5230,7 +5312,7 @@ var configPlugin = definePlugin({
5230
5312
  }
5231
5313
  }
5232
5314
  gen.addInterface("ConfigResources", resources.toString());
5233
- return gen.toString();
5315
+ await write("config.d.ts", gen, true);
5234
5316
  },
5235
5317
  onStack({ bind, config: config2, stackConfig }) {
5236
5318
  const configs = stackConfig.configs;
@@ -6412,7 +6494,7 @@ var authPlugin = definePlugin({
6412
6494
  ).optional()
6413
6495
  }).array()
6414
6496
  }),
6415
- onTypeGen({ config: config2 }) {
6497
+ async onTypeGen({ config: config2, write }) {
6416
6498
  const gen = new TypeGen("@awsless/awsless");
6417
6499
  const resources = new TypeObject(1);
6418
6500
  for (const name of Object.keys(config2.defaults.auth)) {
@@ -6423,7 +6505,7 @@ var authPlugin = definePlugin({
6423
6505
  );
6424
6506
  }
6425
6507
  gen.addInterface("AuthResources", resources);
6426
- return gen.toString();
6508
+ await write("auth.d.ts", gen, true);
6427
6509
  },
6428
6510
  onStack({ bootstrap: bootstrap2, stackConfig, bind }) {
6429
6511
  for (const [id, props] of Object.entries(stackConfig.auth ?? {})) {
@@ -6785,7 +6867,7 @@ import { rollup as rollup3, watch } from "rollup";
6785
6867
  import { swc as swc3 } from "rollup-plugin-swc3";
6786
6868
  import replace from "rollup-plugin-replace";
6787
6869
  import { EventIterator } from "event-iterator";
6788
- import { dirname as dirname4, join as join6 } from "path";
6870
+ import { dirname as dirname5, join as join6 } from "path";
6789
6871
  import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
6790
6872
  var importFile = async (path) => {
6791
6873
  const bundle = await rollup3({
@@ -6796,13 +6878,13 @@ var importFile = async (path) => {
6796
6878
  plugins: [
6797
6879
  // @ts-ignore
6798
6880
  replace({
6799
- __dirname: (id) => `'${dirname4(id)}'`
6881
+ __dirname: (id) => `'${dirname5(id)}'`
6800
6882
  // 'defineStackConfig({': (id: string) => `defineStackConfig({ cwd: '${dirname(id)}',`,
6801
6883
  }),
6802
6884
  swc3({
6803
6885
  minify: false,
6804
6886
  jsc: {
6805
- baseUrl: dirname4(path)
6887
+ baseUrl: dirname5(path)
6806
6888
  }
6807
6889
  })
6808
6890
  ]
@@ -6833,13 +6915,13 @@ var watchFile = (path) => {
6833
6915
  plugins: [
6834
6916
  // @ts-ignore
6835
6917
  replace({
6836
- __dirname: (id) => `'${dirname4(id)}'`
6918
+ __dirname: (id) => `'${dirname5(id)}'`
6837
6919
  // 'defineStackConfig({': (id: string) => `defineStackConfig({ cwd: '${dirname(id)}',`,
6838
6920
  }),
6839
6921
  swc3({
6840
6922
  minify: false,
6841
6923
  jsc: {
6842
- baseUrl: dirname4(path)
6924
+ baseUrl: dirname5(path)
6843
6925
  }
6844
6926
  })
6845
6927
  ]
@@ -7541,7 +7623,7 @@ var layout = async (cb) => {
7541
7623
  };
7542
7624
 
7543
7625
  // src/cli/ui/complex/builder.ts
7544
- import { mkdir as mkdir3, readFile as readFile4, writeFile as writeFile3 } from "fs/promises";
7626
+ import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
7545
7627
 
7546
7628
  // src/cli/ui/layout/flex-line.ts
7547
7629
  var stripEscapeCode = (str) => {
@@ -7564,7 +7646,7 @@ var flexLine = (term, left, right, reserveSpace = 0) => {
7564
7646
  };
7565
7647
 
7566
7648
  // src/cli/ui/complex/builder.ts
7567
- import { dirname as dirname5, join as join8 } from "path";
7649
+ import { dirname as dirname6, join as join8 } from "path";
7568
7650
  var assetBuilder = (app) => {
7569
7651
  return async (term) => {
7570
7652
  const assets = [];
@@ -7636,7 +7718,7 @@ var assetBuilder = (app) => {
7636
7718
  const getFingerPrint = async () => {
7637
7719
  let value;
7638
7720
  try {
7639
- value = await readFile4(getFullPath("FINGER_PRINT"), "utf8");
7721
+ value = await readFile5(getFullPath("FINGER_PRINT"), "utf8");
7640
7722
  } catch (_) {
7641
7723
  return void 0;
7642
7724
  }
@@ -7650,12 +7732,12 @@ var assetBuilder = (app) => {
7650
7732
  return;
7651
7733
  }
7652
7734
  const file = getFullPath("FINGER_PRINT");
7653
- const basepath = dirname5(file);
7735
+ const basepath = dirname6(file);
7654
7736
  await mkdir3(basepath, { recursive: true });
7655
7737
  await writeFile3(file, fingerprint);
7656
7738
  await cb(async (file2, data2) => {
7657
7739
  const fullpath = getFullPath(file2);
7658
- const basepath2 = dirname5(fullpath);
7740
+ const basepath2 = dirname6(fullpath);
7659
7741
  await mkdir3(basepath2, { recursive: true });
7660
7742
  await writeFile3(fullpath, data2);
7661
7743
  });
@@ -7667,7 +7749,7 @@ var assetBuilder = (app) => {
7667
7749
  }
7668
7750
  return Promise.all(
7669
7751
  files.map((file) => {
7670
- return readFile4(getFullPath(file));
7752
+ return readFile5(getFullPath(file));
7671
7753
  })
7672
7754
  );
7673
7755
  }
@@ -8258,7 +8340,7 @@ var status = (program2) => {
8258
8340
  };
8259
8341
 
8260
8342
  // src/cli/ui/complex/publisher.ts
8261
- import { readFile as readFile5 } from "fs/promises";
8343
+ import { readFile as readFile6 } from "fs/promises";
8262
8344
  import { join as join10 } from "path";
8263
8345
  import { GetObjectCommand, ObjectCannedACL as ObjectCannedACL2, PutObjectCommand as PutObjectCommand2, S3Client as S3Client2, StorageClass as StorageClass2 } from "@aws-sdk/client-s3";
8264
8346
  var assetPublisher = (config2, app) => {
@@ -8278,13 +8360,13 @@ var assetPublisher = (config2, app) => {
8278
8360
  };
8279
8361
  await asset.publish?.({
8280
8362
  async read(fingerprint, files) {
8281
- const prev = await readFile5(getFullPath("FINGER_PRINT"), "utf8");
8363
+ const prev = await readFile6(getFullPath("FINGER_PRINT"), "utf8");
8282
8364
  if (prev !== fingerprint) {
8283
8365
  throw new TypeError(`Outdated fingerprint: ${fingerprint}`);
8284
8366
  }
8285
8367
  return Promise.all(
8286
8368
  files.map((file) => {
8287
- return readFile5(getFullPath(file));
8369
+ return readFile6(getFullPath(file));
8288
8370
  })
8289
8371
  );
8290
8372
  },
@@ -8346,7 +8428,7 @@ import commonjs3 from "@rollup/plugin-commonjs";
8346
8428
  import nodeResolve3 from "@rollup/plugin-node-resolve";
8347
8429
  import { swc as swc4 } from "rollup-plugin-swc3";
8348
8430
  import { getSuites, getTests } from "@vitest/runner/utils";
8349
- import { basename as basename3, dirname as dirname6, extname as extname2, join as join11, relative as relative5 } from "path";
8431
+ import { basename as basename3, dirname as dirname7, extname as extname2, join as join11, relative as relative5 } from "path";
8350
8432
 
8351
8433
  // src/cli/ui/layout/text-box.ts
8352
8434
  import wrapAnsi3 from "wrap-ansi";
@@ -8356,7 +8438,7 @@ var textWrap = (text, width, { indent = 0, skipFirstLine = false, ...rest } = {}
8356
8438
  };
8357
8439
 
8358
8440
  // src/cli/ui/complex/tester.ts
8359
- import { mkdir as mkdir6, readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
8441
+ import { mkdir as mkdir6, readFile as readFile7, writeFile as writeFile5 } from "fs/promises";
8360
8442
  import json3 from "@rollup/plugin-json";
8361
8443
  var CustomReporter = class {
8362
8444
  interval;
@@ -8439,7 +8521,7 @@ var singleTester = (stack, dir, filters) => {
8439
8521
  return path;
8440
8522
  }
8441
8523
  const name = basename3(rel, ext);
8442
- const base = dirname6(rel);
8524
+ const base = dirname7(rel);
8443
8525
  const start = base === "." ? "" : style.placeholder(base + "/");
8444
8526
  return `${start}${name}${style.placeholder(ext)}`;
8445
8527
  };
@@ -8551,7 +8633,7 @@ var singleTester = (stack, dir, filters) => {
8551
8633
  const line2 = new Signal([]);
8552
8634
  term.out.write(line2);
8553
8635
  if (exists && !process.env.NO_CACHE) {
8554
- const raw = await readFile6(file, { encoding: "utf8" });
8636
+ const raw = await readFile7(file, { encoding: "utf8" });
8555
8637
  const data2 = JSON.parse(raw);
8556
8638
  if (data2.fingerprint === fingerprint) {
8557
8639
  line2.set(formatOutput({ ...data2, width: term.out.width(), duration: timer(), cached: true }));
package/dist/index.d.ts CHANGED
@@ -11149,6 +11149,28 @@ declare class Function$1 extends Resource {
11149
11149
 
11150
11150
  type Binding = (lambda: Function$1) => void;
11151
11151
 
11152
+ declare class TypeGen {
11153
+ readonly module: string;
11154
+ protected codes: Set<string>;
11155
+ protected interfaces: Map<string, string>;
11156
+ protected imports: Map<string | Record<string, string>, string>;
11157
+ constructor(module: string);
11158
+ addImport(varName: string | Record<string, string>, path: string): this;
11159
+ addCode(code: string): this;
11160
+ addInterface(name: string, type: string | TypeObject): this;
11161
+ toString(): string | undefined;
11162
+ }
11163
+ declare class TypeObject {
11164
+ readonly level: number;
11165
+ readonly readonly: boolean;
11166
+ protected types: Map<string, string>;
11167
+ constructor(level: number, readonly?: boolean);
11168
+ add(name: string, type: string | TypeObject): this;
11169
+ addType(name: string, type: string | TypeObject): this;
11170
+ addConst(name: string, type: string | TypeObject): this;
11171
+ toString(): string;
11172
+ }
11173
+
11152
11174
  type ExtendedConfigOutput<S extends AnyZodObject | undefined = undefined> = S extends AnyZodObject ? BaseConfig & z.output<S> : BaseConfig;
11153
11175
  type ExtendedConfigInput<S extends AnyZodObject | undefined = undefined> = S extends AnyZodObject ? AppConfigInput & z.input<S> : AppConfigInput;
11154
11176
  type StackContext<S extends AnyZodObject | undefined = undefined> = {
@@ -11171,13 +11193,14 @@ type AppContext<S extends AnyZodObject | undefined = undefined> = {
11171
11193
  };
11172
11194
  type TypeGenContext<S extends AnyZodObject | undefined = undefined> = {
11173
11195
  config: ExtendedConfigOutput<S>;
11196
+ write: (file: string, data?: TypeGen | Buffer | string, include?: boolean) => Promise<void>;
11174
11197
  };
11175
11198
  type Plugin<S extends AnyZodObject | undefined = undefined> = {
11176
11199
  name: string;
11177
11200
  schema?: S;
11178
11201
  onApp?: (context: AppContext<S>) => void;
11179
11202
  onStack?: (context: StackContext<S>) => void;
11180
- onTypeGen?: (context: TypeGenContext<S>) => string | void;
11203
+ onTypeGen?: (context: TypeGenContext<S>) => void | Promise<void>;
11181
11204
  };
11182
11205
  declare const definePlugin: <S extends AnyZodObject | undefined = undefined>(plugin: Plugin<S>) => Plugin<S>;
11183
11206
 
@@ -11241,7 +11264,7 @@ interface SearchResources {
11241
11264
  }
11242
11265
  declare const Search: SearchResources;
11243
11266
 
11244
- interface Http {
11267
+ interface HTTP {
11245
11268
  }
11246
11269
  type Method = 'GET' | 'POST';
11247
11270
  type Path = string;
@@ -11263,20 +11286,21 @@ type Props<R extends Route> = {
11263
11286
  query?: R['query'] extends Query ? R['query'] : never;
11264
11287
  body?: R['body'] extends Body ? R['body'] : never;
11265
11288
  };
11266
- type HttpClientHandle = (props: {
11289
+ type HttpFetcher = (props: {
11267
11290
  method: Method;
11268
11291
  path: Path;
11269
11292
  headers: Headers;
11270
11293
  query?: Query;
11271
11294
  body?: Body;
11272
11295
  }) => 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"]>;
11296
+ declare const createHttpFetcher: (host: string) => HttpFetcher;
11297
+ declare const createHttpClient: <S extends Partial<Record<Method, Routes>>>(fetcher: HttpFetcher) => {
11298
+ 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"]>;
11299
+ 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"]>;
11300
+ 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"]>;
11301
+ };
11302
+
11303
+ interface GraphQL {
11280
11304
  }
11281
11305
 
11282
11306
  type FunctionProps<H extends Handler<S>, S extends BaseSchema> = {
@@ -12139,4 +12163,4 @@ declare const defineStackConfig: (config: StackConfig) => StackConfig$1 | (Stack
12139
12163
  });
12140
12164
  declare const defineAppConfig: (config: AppConfig | AppConfigFactory<AppConfig>) => CombinedDefaultPluginsConfigInput | AppConfigFactory<CombinedDefaultPluginsConfigInput>;
12141
12165
 
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 };
12166
+ export { APP, AppConfig, Auth, AuthResources, Cache, CacheResources, Config, ConfigResources, CronProps, Fn, Function, FunctionMock, FunctionMockResponse, FunctionProps, FunctionResources, GraphQL, 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.115",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -24,13 +24,13 @@
24
24
  }
25
25
  },
26
26
  "peerDependencies": {
27
- "@awsless/lambda": "^0.0.14",
27
+ "@awsless/redis": "^0.0.8",
28
28
  "@awsless/sns": "^0.0.7",
29
29
  "@awsless/sqs": "^0.0.7",
30
- "@awsless/redis": "^0.0.8",
30
+ "@awsless/ssm": "^0.0.7",
31
31
  "@awsless/validate": "^0.0.10",
32
- "@awsless/weak-cache": "^0.0.1",
33
- "@awsless/ssm": "^0.0.7"
32
+ "@awsless/lambda": "^0.0.14",
33
+ "@awsless/weak-cache": "^0.0.1"
34
34
  },
35
35
  "dependencies": {
36
36
  "@aws-appsync/utils": "^1.5.0",
@@ -78,6 +78,7 @@
78
78
  "vitest": "^0.34.6",
79
79
  "wrap-ansi": "^8.1.0",
80
80
  "zod": "^3.21.4",
81
+ "@awsless/graphql": "^0.0.1",
81
82
  "@awsless/code": "^0.0.10"
82
83
  },
83
84
  "scripts": {