@awsless/awsless 0.0.91 → 0.0.93

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
@@ -1244,10 +1244,7 @@ import { mkdir, writeFile } from "fs/promises";
1244
1244
  import { join as join3, relative } from "path";
1245
1245
  import { camelCase, constantCase as constantCase3 } from "change-case";
1246
1246
  var generateResourceTypes = async (config) => {
1247
- const plugins = [
1248
- ...defaultPlugins,
1249
- ...config.plugins || []
1250
- ];
1247
+ const plugins = [...defaultPlugins, ...config.plugins || []];
1251
1248
  const files = [];
1252
1249
  for (const plugin of plugins) {
1253
1250
  const code = plugin.onTypeGen?.({ config });
@@ -1264,13 +1261,11 @@ var generateResourceTypes = async (config) => {
1264
1261
  }
1265
1262
  };
1266
1263
  var TypeGen = class {
1267
- constructor(module, interfaceName, readonly = true) {
1264
+ constructor(module) {
1268
1265
  this.module = module;
1269
- this.interfaceName = interfaceName;
1270
- this.readonly = readonly;
1271
1266
  }
1272
1267
  codes = /* @__PURE__ */ new Set();
1273
- types = /* @__PURE__ */ new Map();
1268
+ interfaces = /* @__PURE__ */ new Map();
1274
1269
  imports = /* @__PURE__ */ new Map();
1275
1270
  addImport(varName, path) {
1276
1271
  this.imports.set(varName, path);
@@ -1280,48 +1275,49 @@ var TypeGen = class {
1280
1275
  this.codes.add(code);
1281
1276
  return this;
1282
1277
  }
1283
- addType(name, type) {
1284
- if (type) {
1285
- this.types.set(camelCase(name), type);
1286
- }
1287
- return this;
1288
- }
1289
- addConst(name, type) {
1290
- if (type) {
1291
- this.types.set(constantCase3(name), type);
1278
+ addInterface(name, type) {
1279
+ const value = type.toString();
1280
+ if (value) {
1281
+ this.interfaces.set(name, value);
1292
1282
  }
1293
1283
  return this;
1294
1284
  }
1285
+ // addConst(name: string, type: string) {
1286
+ // if (type) {
1287
+ // this.types.set(constantCase(name), type)
1288
+ // }
1289
+ // return this
1290
+ // }
1295
1291
  toString() {
1296
- if (this.types.size === 0) {
1292
+ if (this.interfaces.size === 0) {
1297
1293
  return;
1298
1294
  }
1299
1295
  const lines = [];
1300
1296
  if (this.imports.size > 0) {
1301
- lines.push(...[
1302
- "// Imports",
1303
- ...Array.from(this.imports.entries()).map(([varName, path]) => {
1304
- return `import ${camelCase(varName)} from '${path}'`;
1305
- }),
1306
- ""
1307
- ]);
1297
+ lines.push(
1298
+ ...[
1299
+ "// Imports",
1300
+ ...Array.from(this.imports.entries()).map(([varName, path]) => {
1301
+ return `import ${camelCase(varName)} from '${path}'`;
1302
+ }),
1303
+ ""
1304
+ ]
1305
+ );
1308
1306
  }
1309
1307
  if (this.codes.size > 0) {
1310
- lines.push(...[
1311
- "// Types",
1312
- ...Array.from(this.codes).map((v) => v.trim()),
1313
- ""
1314
- ]);
1308
+ lines.push(...["// Types", ...Array.from(this.codes).map((v) => v.trim()), ""]);
1315
1309
  }
1316
1310
  return [
1317
1311
  ...lines,
1318
1312
  "// Extend module",
1319
1313
  `declare module '${this.module}' {`,
1320
- ` interface ${this.interfaceName} {`,
1321
- ...Array.from(this.types.entries()).map(([propName, type]) => {
1322
- return ` ${this.readonly ? "readonly " : ""}${propName}: ${type}`;
1323
- }),
1324
- ` }`,
1314
+ Array.from(this.interfaces).map(([name, type]) => {
1315
+ return ` interface ${name} ${type}`;
1316
+ }).join("\n\n"),
1317
+ // ...Array.from(this.types.entries()).map(([propName, type]) => { // `\tinterface ${this.interfaceName} {`,
1318
+ // return `\t\t${this.readonly ? 'readonly ' : ''}${propName}: ${type}`
1319
+ // }),
1320
+ // `\t}`,
1325
1321
  `}`,
1326
1322
  "",
1327
1323
  "// Export fix",
@@ -1330,10 +1326,15 @@ var TypeGen = class {
1330
1326
  }
1331
1327
  };
1332
1328
  var TypeObject = class {
1329
+ constructor(level, readonly = true) {
1330
+ this.level = level;
1331
+ this.readonly = readonly;
1332
+ }
1333
1333
  types = /* @__PURE__ */ new Map();
1334
1334
  addType(name, type) {
1335
- if (type) {
1336
- this.types.set(camelCase(name), type);
1335
+ const value = type.toString();
1336
+ if (value) {
1337
+ this.types.set(camelCase(name), value);
1337
1338
  }
1338
1339
  return this;
1339
1340
  }
@@ -1350,9 +1351,16 @@ var TypeObject = class {
1350
1351
  return [
1351
1352
  "{",
1352
1353
  ...Array.from(this.types.entries()).map(([propName, type]) => {
1353
- return ` readonly ${propName}: ${type}`;
1354
+ return [
1355
+ " ".repeat(this.level + 1),
1356
+ this.readonly ? "readonly" : "",
1357
+ " ",
1358
+ propName,
1359
+ ": ",
1360
+ type
1361
+ ].join("");
1354
1362
  }),
1355
- " }"
1363
+ `${" ".repeat(this.level)}}`
1356
1364
  ].join("\n");
1357
1365
  }
1358
1366
  };
@@ -1564,30 +1572,51 @@ var schema = z6.object({
1564
1572
  });
1565
1573
  var typeGenCode = `
1566
1574
  import { InvokeOptions, InvokeResponse } from '@awsless/lambda'
1575
+ import type { Mock } from 'vitest'
1576
+
1577
+ type Func = (...args: any[]) => any
1567
1578
 
1568
- type Invoke<Name extends string, Func extends (...args: any[]) => any> = {
1579
+ type Invoke<Name extends string, F extends Func> = {
1569
1580
  readonly name: Name
1570
- readonly async: (payload: Parameters<Func>[0], options?: Omit<InvokeOptions, 'name' | 'payload' | 'type'>) => InvokeResponse<Func>
1571
- (payload: Parameters<Func>[0], options?: Omit<InvokeOptions, 'name' | 'payload'>): InvokeResponse<Func>
1572
- }`;
1581
+ readonly async: (payload: Parameters<F>[0], options?: Omit<InvokeOptions, 'name' | 'payload' | 'type'>) => InvokeResponse<F>
1582
+ (payload: Parameters<F>[0], options?: Omit<InvokeOptions, 'name' | 'payload'>): InvokeResponse<F>
1583
+ }
1584
+
1585
+ type Response<F extends Func> = Partial<Awaited<InvokeResponse<F>>>
1586
+ type MockHandle<F extends Func> = (payload: Parameters<F>[0]) => Response<F> | void
1587
+ type MockHandleOrResponse<F extends Func> = MockHandle<F> | Response<F>
1588
+ type MockBuilder<F extends Func> = (handleOrResponse?: MockHandleOrResponse<F>) => void
1589
+ `;
1573
1590
  var functionPlugin = definePlugin({
1574
1591
  name: "function",
1575
1592
  schema,
1576
1593
  onTypeGen({ config }) {
1577
- const types2 = new TypeGen("@awsless/awsless", "FunctionResources");
1578
- types2.addCode(typeGenCode);
1594
+ const types2 = new TypeGen("@awsless/awsless");
1595
+ const resources = new TypeObject(1);
1596
+ const mocks = new TypeObject(1);
1597
+ const mockResponses = new TypeObject(1);
1579
1598
  for (const stack of config.stacks) {
1580
- const list3 = new TypeObject();
1599
+ const resource = new TypeObject(2);
1600
+ const mock = new TypeObject(2);
1601
+ const mockResponse = new TypeObject(2);
1581
1602
  for (const [name, fileOrProps] of Object.entries(stack.functions || {})) {
1582
1603
  const varName = camelCase2(`${stack.name}-${name}`);
1583
1604
  const funcName = formatName(`${config.name}-${stack.name}-${name}`);
1584
1605
  const file = typeof fileOrProps === "string" ? fileOrProps : fileOrProps.file;
1585
1606
  const relFile = relative2(directories.types, file);
1586
1607
  types2.addImport(varName, relFile);
1587
- list3.addType(name, `Invoke<'${funcName}', typeof ${varName}>`);
1608
+ resource.addType(name, `Invoke<'${funcName}', typeof ${varName}>`);
1609
+ mock.addType(name, `MockBuilder<typeof ${varName}>`);
1610
+ mockResponse.addType(name, `Mock`);
1588
1611
  }
1589
- types2.addType(stack.name, list3.toString());
1612
+ mocks.addType(stack.name, mock);
1613
+ resources.addType(stack.name, resource);
1614
+ mockResponses.addType(stack.name, mockResponse);
1590
1615
  }
1616
+ types2.addCode(typeGenCode);
1617
+ types2.addInterface("FunctionResources", resources);
1618
+ types2.addInterface("FunctionMock", mocks);
1619
+ types2.addInterface("FunctionMockResponses", mockResponses);
1591
1620
  return types2.toString();
1592
1621
  },
1593
1622
  onStack(ctx) {
@@ -1830,24 +1859,48 @@ var SqsEventSource = class extends Group {
1830
1859
  // src/plugins/queue.ts
1831
1860
  import { camelCase as camelCase3, constantCase as constantCase5 } from "change-case";
1832
1861
  import { relative as relative3 } from "path";
1833
- var RetentionPeriodSchema = DurationSchema.refine(durationMin(Duration.minutes(1)), "Minimum retention period is 1 minute").refine(durationMax(Duration.days(14)), "Maximum retention period is 14 days");
1834
- var VisibilityTimeoutSchema = DurationSchema.refine(durationMax(Duration.hours(12)), "Maximum visibility timeout is 12 hours");
1835
- var DeliveryDelaySchema = DurationSchema.refine(durationMax(Duration.minutes(15)), "Maximum delivery delay is 15 minutes");
1836
- var ReceiveMessageWaitTimeSchema = DurationSchema.refine(durationMin(Duration.seconds(1)), "Minimum receive message wait time is 1 second").refine(durationMax(Duration.seconds(20)), "Maximum receive message wait time is 20 seconds");
1837
- var MaxMessageSizeSchema = SizeSchema.refine(sizeMin(Size.kiloBytes(1)), "Minimum max message size is 1 KB").refine(sizeMax(Size.kiloBytes(256)), "Maximum max message size is 256 KB");
1862
+ var RetentionPeriodSchema = DurationSchema.refine(
1863
+ durationMin(Duration.minutes(1)),
1864
+ "Minimum retention period is 1 minute"
1865
+ ).refine(durationMax(Duration.days(14)), "Maximum retention period is 14 days");
1866
+ var VisibilityTimeoutSchema = DurationSchema.refine(
1867
+ durationMax(Duration.hours(12)),
1868
+ "Maximum visibility timeout is 12 hours"
1869
+ );
1870
+ var DeliveryDelaySchema = DurationSchema.refine(
1871
+ durationMax(Duration.minutes(15)),
1872
+ "Maximum delivery delay is 15 minutes"
1873
+ );
1874
+ var ReceiveMessageWaitTimeSchema = DurationSchema.refine(
1875
+ durationMin(Duration.seconds(1)),
1876
+ "Minimum receive message wait time is 1 second"
1877
+ ).refine(durationMax(Duration.seconds(20)), "Maximum receive message wait time is 20 seconds");
1878
+ var MaxMessageSizeSchema = SizeSchema.refine(
1879
+ sizeMin(Size.kiloBytes(1)),
1880
+ "Minimum max message size is 1 KB"
1881
+ ).refine(sizeMax(Size.kiloBytes(256)), "Maximum max message size is 256 KB");
1838
1882
  var BatchSizeSchema = z8.number().int().min(1, "Minimum batch size is 1").max(1e4, "Maximum batch size is 10000");
1839
1883
  var MaxConcurrencySchema = z8.number().int().min(2, "Minimum max concurrency is 2").max(1e3, "Maximum max concurrency is 1000");
1840
- var MaxBatchingWindow = DurationSchema.refine(durationMax(Duration.minutes(5)), "Maximum max batching window is 5 minutes");
1884
+ var MaxBatchingWindow = DurationSchema.refine(
1885
+ durationMax(Duration.minutes(5)),
1886
+ "Maximum max batching window is 5 minutes"
1887
+ );
1841
1888
  var typeGenCode2 = `
1842
1889
  import { SendMessageOptions, SendMessageBatchOptions, BatchItem } from '@awsless/sqs'
1890
+ import type { Mock } from 'vitest'
1843
1891
 
1844
- type Payload<Func extends (...args: any[]) => any> = Parameters<Func>[0]['Records'][number]['body']
1892
+ type Func = (...args: any[]) => any
1893
+ type Payload<F extends Func> = Parameters<F>[0]['Records'][number]['body']
1845
1894
 
1846
- type Send<Name extends string, Func extends (...args: any[]) => any> = {
1895
+ type Send<Name extends string, F extends Func> = {
1847
1896
  readonly name: Name
1848
- readonly batch(items:BatchItem<Payload<Func>>[], options?:Omit<SendMessageBatchOptions, 'queue' | 'items'>): Promise<void>
1849
- (payload: Payload<Func>, options?: Omit<SendMessageOptions, 'queue' | 'payload'>): Promise<void>
1850
- }`;
1897
+ readonly batch(items:BatchItem<Payload<F>>[], options?:Omit<SendMessageBatchOptions, 'queue' | 'items'>): Promise<void>
1898
+ (payload: Payload<F>, options?: Omit<SendMessageOptions, 'queue' | 'payload'>): Promise<void>
1899
+ }
1900
+
1901
+ type MockHandle<F extends Func> = (payload: Parameters<F>[0]) => void
1902
+ type MockBuilder<F extends Func> = (handle?: MockHandle<F>) => void
1903
+ `;
1851
1904
  var queuePlugin = definePlugin({
1852
1905
  name: "queue",
1853
1906
  schema: z8.object({
@@ -1948,21 +2001,33 @@ var queuePlugin = definePlugin({
1948
2001
  }).array()
1949
2002
  }),
1950
2003
  onTypeGen({ config }) {
1951
- const types2 = new TypeGen("@awsless/awsless", "QueueResources");
1952
- types2.addCode(typeGenCode2);
2004
+ const gen = new TypeGen("@awsless/awsless");
2005
+ const resources = new TypeObject(1);
2006
+ const mocks = new TypeObject(1);
2007
+ const mockResponses = new TypeObject(1);
1953
2008
  for (const stack of config.stacks) {
1954
- const list3 = new TypeObject();
2009
+ const resource = new TypeObject(2);
2010
+ const mock = new TypeObject(2);
2011
+ const mockResponse = new TypeObject(2);
1955
2012
  for (const [name, fileOrProps] of Object.entries(stack.queues || {})) {
1956
2013
  const varName = camelCase3(`${stack.name}-${name}`);
1957
2014
  const queueName = formatName(`${config.name}-${stack.name}-${name}`);
1958
2015
  const file = typeof fileOrProps === "string" ? fileOrProps : typeof fileOrProps.consumer === "string" ? fileOrProps.consumer : fileOrProps.consumer.file;
1959
2016
  const relFile = relative3(directories.types, file);
1960
- types2.addImport(varName, relFile);
1961
- list3.addType(name, `Send<'${queueName}', typeof ${varName}>`);
2017
+ gen.addImport(varName, relFile);
2018
+ mock.addType(name, `MockBuilder<typeof ${varName}>`);
2019
+ resource.addType(name, `Send<'${queueName}', typeof ${varName}>`);
2020
+ mockResponse.addType(name, `Mock`);
1962
2021
  }
1963
- types2.addType(stack.name, list3.toString());
2022
+ mocks.addType(stack.name, mock);
2023
+ resources.addType(stack.name, resource);
2024
+ mockResponses.addType(stack.name, mockResponse);
1964
2025
  }
1965
- return types2.toString();
2026
+ gen.addCode(typeGenCode2);
2027
+ gen.addInterface("QueueResources", resources);
2028
+ gen.addInterface("QueueMock", mocks);
2029
+ gen.addInterface("QueueMockResponses", mockResponses);
2030
+ return gen.toString();
1966
2031
  },
1967
2032
  onStack(ctx) {
1968
2033
  const { stack, config, stackConfig, bind } = ctx;
@@ -2236,16 +2301,18 @@ var tablePlugin = definePlugin({
2236
2301
  }).array()
2237
2302
  }),
2238
2303
  onTypeGen({ config }) {
2239
- const types2 = new TypeGen("@awsless/awsless", "TableResources");
2304
+ const gen = new TypeGen("@awsless/awsless");
2305
+ const resources = new TypeObject(1);
2240
2306
  for (const stack of config.stacks) {
2241
- const list3 = new TypeObject();
2307
+ const list3 = new TypeObject(2);
2242
2308
  for (const name of Object.keys(stack.tables || {})) {
2243
2309
  const tableName = formatName(`${config.name}-${stack.name}-${name}`);
2244
2310
  list3.addType(name, `'${tableName}'`);
2245
2311
  }
2246
- types2.addType(stack.name, list3.toString());
2312
+ resources.addType(stack.name, list3);
2247
2313
  }
2248
- return types2.toString();
2314
+ gen.addInterface("TableResources", resources);
2315
+ return gen.toString();
2249
2316
  },
2250
2317
  onStack(ctx) {
2251
2318
  const { config, stack, stackConfig, bind } = ctx;
@@ -2368,16 +2435,18 @@ var storePlugin = definePlugin({
2368
2435
  }).array()
2369
2436
  }),
2370
2437
  onTypeGen({ config }) {
2371
- const types2 = new TypeGen("@awsless/awsless", "StoreResources");
2438
+ const gen = new TypeGen("@awsless/awsless");
2439
+ const resources = new TypeObject(1);
2372
2440
  for (const stack of config.stacks) {
2373
- const list3 = new TypeObject();
2441
+ const list3 = new TypeObject(2);
2374
2442
  for (const name of stack.stores || []) {
2375
2443
  const storeName = formatName(`${config.name}-${stack.name}-${name}`);
2376
2444
  list3.addType(name, `{ readonly name: '${storeName}' }`);
2377
2445
  }
2378
- types2.addType(stack.name, list3.toString());
2446
+ resources.addType(stack.name, list3);
2379
2447
  }
2380
- return types2.toString();
2448
+ gen.addInterface("StoreResources", resources);
2449
+ return gen.toString();
2381
2450
  },
2382
2451
  onStack({ config, stack, stackConfig, bootstrap: bootstrap2, bind }) {
2383
2452
  for (const id of stackConfig.stores || []) {
@@ -2477,13 +2546,20 @@ var isEmail = (value) => {
2477
2546
  };
2478
2547
 
2479
2548
  // src/plugins/topic.ts
2549
+ import { paramCase as paramCase4 } from "change-case";
2550
+ var TopicNameSchema = z12.string().min(3).max(256).regex(/^[a-z0-9\-]+$/i, "Invalid topic name").transform((value) => paramCase4(value));
2480
2551
  var typeGenCode3 = `
2481
- import { PublishOptions } from '@awsless/sns'
2552
+ import type { PublishOptions } from '@awsless/sns'
2553
+ import type { Mock } from 'vitest'
2482
2554
 
2483
2555
  type Publish<Name extends string> = {
2484
2556
  readonly name: Name
2485
2557
  (payload: unknown, options?: Omit<PublishOptions, 'topic' | 'payload'>): Promise<void>
2486
- }`;
2558
+ }
2559
+
2560
+ type MockHandle = (payload: unknown) => void
2561
+ type MockBuilder = (handle?: MockHandle) => void
2562
+ `;
2487
2563
  var topicPlugin = definePlugin({
2488
2564
  name: "topic",
2489
2565
  schema: z12.object({
@@ -2494,7 +2570,7 @@ var topicPlugin = definePlugin({
2494
2570
  * topics: [ 'TOPIC_NAME' ]
2495
2571
  * }
2496
2572
  */
2497
- topics: z12.array(ResourceIdSchema).refine((topics) => {
2573
+ topics: z12.array(TopicNameSchema).refine((topics) => {
2498
2574
  return topics.length === new Set(topics).size;
2499
2575
  }, "Must be a list of unique topic names").optional(),
2500
2576
  /** Define the events to subscribe too in your stack.
@@ -2509,7 +2585,7 @@ var topicPlugin = definePlugin({
2509
2585
  * }
2510
2586
  * }
2511
2587
  */
2512
- subscribers: z12.record(ResourceIdSchema, z12.union([EmailSchema, FunctionSchema])).optional()
2588
+ subscribers: z12.record(TopicNameSchema, z12.union([EmailSchema, FunctionSchema])).optional()
2513
2589
  }).array().superRefine((stacks, ctx) => {
2514
2590
  const topics = [];
2515
2591
  for (const stack of stacks) {
@@ -2530,14 +2606,22 @@ var topicPlugin = definePlugin({
2530
2606
  })
2531
2607
  }),
2532
2608
  onTypeGen({ config }) {
2533
- const gen = new TypeGen("@awsless/awsless", "TopicResources");
2534
- gen.addCode(typeGenCode3);
2609
+ const gen = new TypeGen("@awsless/awsless");
2610
+ const resources = new TypeObject(1);
2611
+ const mocks = new TypeObject(1);
2612
+ const mockResponses = new TypeObject(1);
2535
2613
  for (const stack of config.stacks) {
2536
2614
  for (const topic of stack.topics || []) {
2537
2615
  const name = formatName(`${config.name}-${topic}`);
2538
- gen.addType(topic, `Publish<'${name}'>`);
2616
+ mockResponses.addType(topic, "Mock");
2617
+ resources.addType(topic, `Publish<'${name}'>`);
2618
+ mocks.addType(topic, `MockBuilder`);
2539
2619
  }
2540
2620
  }
2621
+ gen.addCode(typeGenCode3);
2622
+ gen.addInterface("TopicResources", resources);
2623
+ gen.addInterface("TopicMock", mocks);
2624
+ gen.addInterface("TopicMockResponses", mockResponses);
2541
2625
  return gen.toString();
2542
2626
  },
2543
2627
  onApp({ config, bootstrap: bootstrap2 }) {
@@ -2717,7 +2801,7 @@ var toArray = (value) => {
2717
2801
  };
2718
2802
 
2719
2803
  // src/plugins/graphql.ts
2720
- import { paramCase as paramCase4 } from "change-case";
2804
+ import { paramCase as paramCase5 } from "change-case";
2721
2805
 
2722
2806
  // src/formation/resource/appsync/graphql-api.ts
2723
2807
  var GraphQLApi = class extends Resource {
@@ -3279,7 +3363,7 @@ var graphqlPlugin = definePlugin({
3279
3363
  for (const [typeName, fields] of Object.entries(props.resolvers || {})) {
3280
3364
  for (const [fieldName, resolverProps] of Object.entries(fields || {})) {
3281
3365
  const props2 = isFunctionProps(resolverProps) ? { consumer: resolverProps } : resolverProps;
3282
- const entryId = paramCase4(`${id}-${typeName}-${fieldName}`);
3366
+ const entryId = paramCase5(`${id}-${typeName}-${fieldName}`);
3283
3367
  const lambda = toLambdaFunction(ctx, `graphql-${entryId}`, props2.consumer);
3284
3368
  const resolver = props2.resolver ?? defaultProps?.resolver;
3285
3369
  let code = defaultResolver;
@@ -4419,15 +4503,17 @@ var searchPlugin = definePlugin({
4419
4503
  }).array()
4420
4504
  }),
4421
4505
  onTypeGen({ config }) {
4422
- const gen = new TypeGen("@awsless/awsless", "SearchResources");
4506
+ const gen = new TypeGen("@awsless/awsless");
4507
+ const resources = new TypeObject(1);
4423
4508
  for (const stack of config.stacks) {
4424
- const list3 = new TypeObject();
4509
+ const list3 = new TypeObject(2);
4425
4510
  for (const id of stack.searchs || []) {
4426
4511
  const name = formatName(`${config.name}-${stack.name}-${id}`);
4427
4512
  list3.addType(name, `{ readonly name: '${name}' }`);
4428
4513
  }
4429
- gen.addType(stack.name, list3.toString());
4514
+ resources.addType(stack.name, list3);
4430
4515
  }
4516
+ gen.addInterface("SearchResources", resources);
4431
4517
  return gen.toString();
4432
4518
  },
4433
4519
  onStack({ config, stack, stackConfig, bind }) {
@@ -4571,15 +4657,17 @@ var cachePlugin = definePlugin({
4571
4657
  }).array()
4572
4658
  }),
4573
4659
  onTypeGen({ config }) {
4574
- const gen = new TypeGen("@awsless/awsless", "CacheResources");
4575
- gen.addCode(typeGenCode4);
4660
+ const gen = new TypeGen("@awsless/awsless");
4661
+ const resources = new TypeObject(1);
4576
4662
  for (const stack of config.stacks) {
4577
- const list3 = new TypeObject();
4663
+ const resource = new TypeObject(2);
4578
4664
  for (const name of Object.keys(stack.caches || {})) {
4579
- list3.addType(name, `Command`);
4665
+ resource.addType(name, `Command`);
4580
4666
  }
4581
- gen.addType(stack.name, list3.toString());
4667
+ resources.addType(stack.name, resource);
4582
4668
  }
4669
+ gen.addCode(typeGenCode4);
4670
+ gen.addInterface("CacheResources", resources);
4583
4671
  return gen.toString();
4584
4672
  },
4585
4673
  onStack({ config, stack, stackConfig, bootstrap: bootstrap2, bind }) {
@@ -4967,7 +5055,7 @@ var Params = class {
4967
5055
  };
4968
5056
 
4969
5057
  // src/plugins/config.ts
4970
- import { paramCase as paramCase5 } from "change-case";
5058
+ import { paramCase as paramCase6 } from "change-case";
4971
5059
  var ConfigNameSchema = z23.string().regex(/[a-z0-9\-]/g, "Invalid config name");
4972
5060
  var configPlugin = definePlugin({
4973
5061
  name: "config",
@@ -4993,13 +5081,15 @@ var configPlugin = definePlugin({
4993
5081
  }).array()
4994
5082
  }),
4995
5083
  onTypeGen({ config }) {
4996
- const types2 = new TypeGen("@awsless/awsless", "ConfigResources", false);
5084
+ const gen = new TypeGen("@awsless/awsless");
5085
+ const resources = new TypeObject(0, false);
4997
5086
  for (const stack of config.stacks) {
4998
5087
  for (const name of stack.configs || []) {
4999
- types2.addConst(name, "string");
5088
+ resources.addConst(name, "string");
5000
5089
  }
5001
5090
  }
5002
- return types2.toString();
5091
+ gen.addInterface("ConfigResources", resources.toString());
5092
+ return gen.toString();
5003
5093
  },
5004
5094
  onStack({ bind, config, stackConfig }) {
5005
5095
  const configs = stackConfig.configs;
@@ -5012,7 +5102,7 @@ var configPlugin = definePlugin({
5012
5102
  return formatArn({
5013
5103
  service: "ssm",
5014
5104
  resource: "parameter",
5015
- resourceName: configParameterPrefix(config) + "/" + paramCase5(name),
5105
+ resourceName: configParameterPrefix(config) + "/" + paramCase6(name),
5016
5106
  seperator: ""
5017
5107
  });
5018
5108
  })
@@ -6184,14 +6274,16 @@ var authPlugin = definePlugin({
6184
6274
  }).array()
6185
6275
  }),
6186
6276
  onTypeGen({ config }) {
6187
- const gen = new TypeGen("@awsless/awsless", "AuthResources");
6277
+ const gen = new TypeGen("@awsless/awsless");
6278
+ const resources = new TypeObject(1);
6188
6279
  for (const name of Object.keys(config.defaults.auth)) {
6189
6280
  const authName = formatName(`${config.name}-${name}`);
6190
- gen.addType(
6281
+ resources.addType(
6191
6282
  name,
6192
6283
  `{ readonly name: '${authName}', readonly userPoolId: string, readonly clientId: string }`
6193
6284
  );
6194
6285
  }
6286
+ gen.addInterface("AuthResources", resources);
6195
6287
  return gen.toString();
6196
6288
  },
6197
6289
  onStack({ bootstrap: bootstrap2, stackConfig, bind }) {
@@ -7490,7 +7582,7 @@ var shouldDeployBootstrap = async (client, stack) => {
7490
7582
  // src/formation/client.ts
7491
7583
  import { CloudFormationClient, CreateStackCommand, DeleteStackCommand, DescribeStackEventsCommand, DescribeStacksCommand, GetTemplateCommand, OnFailure, TemplateStage, UpdateStackCommand, ValidateTemplateCommand, waitUntilStackCreateComplete, waitUntilStackDeleteComplete, waitUntilStackUpdateComplete } from "@aws-sdk/client-cloudformation";
7492
7584
  import { S3Client, PutObjectCommand, ObjectCannedACL, StorageClass } from "@aws-sdk/client-s3";
7493
- import { paramCase as paramCase6 } from "change-case";
7585
+ import { paramCase as paramCase7 } from "change-case";
7494
7586
  var StackClient = class {
7495
7587
  constructor(app, account, region, credentials) {
7496
7588
  this.app = app;
@@ -7523,7 +7615,7 @@ var StackClient = class {
7523
7615
  };
7524
7616
  }
7525
7617
  stackName(stackName) {
7526
- return paramCase6(`${this.app.name}-${stackName}`);
7618
+ return paramCase7(`${this.app.name}-${stackName}`);
7527
7619
  }
7528
7620
  tags(stack) {
7529
7621
  const tags = [];
package/dist/index.d.ts CHANGED
@@ -11270,6 +11270,24 @@ type CronProps<H extends Handler<S>, S extends BaseSchema> = {
11270
11270
  };
11271
11271
  declare const cron: <H extends Handler<S>, S extends BaseSchema<any, any>>(props: CronProps<H, S>) => (event: _awsless_lambda.Input<S>, context?: _awsless_lambda.LambdaContext | undefined) => Promise<ReturnType<H>>;
11272
11272
 
11273
+ interface FunctionMock {
11274
+ }
11275
+ interface FunctionMockResponse {
11276
+ }
11277
+ declare const mockFunction: (cb: (mock: FunctionMock) => void) => FunctionMockResponse;
11278
+
11279
+ interface TopicMock {
11280
+ }
11281
+ interface TopicMockResponse {
11282
+ }
11283
+ declare const mockTopic: (cb: (mock: TopicMock) => void) => TopicMockResponse;
11284
+
11285
+ interface QueueMock {
11286
+ }
11287
+ interface QueueMockResponse {
11288
+ }
11289
+ declare const mockQueue: (cb: (mock: QueueMock) => void) => QueueMockResponse;
11290
+
11273
11291
  type AppConfig = CombinedDefaultPluginsConfigInput;
11274
11292
  type StackConfig = CombinedDefaultPluginsConfigInput['stacks'][number];
11275
11293
  declare const defineStackConfig: (config: StackConfig) => StackConfig$1 | (StackConfig$1 & {
@@ -12071,4 +12089,4 @@ declare const defineStackConfig: (config: StackConfig) => StackConfig$1 | (Stack
12071
12089
  });
12072
12090
  declare const defineAppConfig: (config: AppConfig | AppConfigFactory<AppConfig>) => CombinedDefaultPluginsConfigInput | AppConfigFactory<CombinedDefaultPluginsConfigInput>;
12073
12091
 
12074
- export { APP, AppConfig, Auth, AuthResources, Cache, CacheResources, Config, ConfigResources, CronProps, Fn, Function, FunctionProps, FunctionResources, Plugin, Queue, QueueProps, QueueResources, STACK, Search, SearchResources, StackConfig, Store, StoreResources, Table, TableResources, Topic, TopicProps, TopicResources, cron, defineAppConfig, definePlugin, defineStackConfig, func, getAuthName, getAuthProps, getCacheProps, getConfigName, getFunctionName, getGlobalResourceName, getLocalResourceName, getQueueName, getSearchName, getStoreName, getTableName, getTopicName, queue, topic };
12092
+ export { APP, AppConfig, Auth, AuthResources, Cache, CacheResources, Config, ConfigResources, CronProps, Fn, Function, FunctionMock, FunctionMockResponse, FunctionProps, FunctionResources, 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, topic };
package/dist/index.js CHANGED
@@ -275,6 +275,65 @@ var cron = (props) => {
275
275
  });
276
276
  };
277
277
 
278
+ // src/node/mock/function.ts
279
+ import { mockLambda } from "@awsless/lambda";
280
+ var mockFunction = (cb) => {
281
+ const list = {};
282
+ const mock = createProxy((stack) => {
283
+ return createProxy((name) => {
284
+ return (handleOrResponse) => {
285
+ const handle = typeof handleOrResponse === "function" ? handleOrResponse : () => handleOrResponse;
286
+ list[getFunctionName(stack, name)] = handle;
287
+ };
288
+ });
289
+ });
290
+ cb(mock);
291
+ const result = mockLambda(list);
292
+ return createProxy((stack) => {
293
+ return createProxy((name) => {
294
+ return result[getFunctionName(stack, name)];
295
+ });
296
+ });
297
+ };
298
+
299
+ // src/node/mock/topic.ts
300
+ import { mockSQS } from "@awsless/sqs";
301
+ var mockTopic = (cb) => {
302
+ const list = {};
303
+ const mock = createProxy((name) => {
304
+ return (handle) => {
305
+ list[getTopicName(name)] = handle ?? (() => {
306
+ });
307
+ };
308
+ });
309
+ cb(mock);
310
+ const result = mockSQS(list);
311
+ return createProxy((name) => {
312
+ return result[getTopicName(name)];
313
+ });
314
+ };
315
+
316
+ // src/node/mock/queue.ts
317
+ import { mockSQS as mockSQS2 } from "@awsless/sqs";
318
+ var mockQueue = (cb) => {
319
+ const list = {};
320
+ const mock = createProxy((stack) => {
321
+ return createProxy((name) => {
322
+ return (handle) => {
323
+ list[getQueueName(stack, name)] = handle ?? (() => {
324
+ });
325
+ };
326
+ });
327
+ });
328
+ cb(mock);
329
+ const result = mockSQS2(list);
330
+ return createProxy((stack) => {
331
+ return createProxy((name) => {
332
+ return result[getQueueName(stack, name)];
333
+ });
334
+ });
335
+ };
336
+
278
337
  // src/index.ts
279
338
  var defineStackConfig = (config) => config;
280
339
  var defineAppConfig = (config) => config;
@@ -308,6 +367,9 @@ export {
308
367
  getStoreName,
309
368
  getTableName,
310
369
  getTopicName,
370
+ mockFunction,
371
+ mockQueue,
372
+ mockTopic,
311
373
  queue,
312
374
  topic
313
375
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.91",
3
+ "version": "0.0.93",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -24,12 +24,12 @@
24
24
  }
25
25
  },
26
26
  "peerDependencies": {
27
- "@awsless/validate": "^0.0.6",
28
27
  "@awsless/lambda": "^0.0.13",
29
28
  "@awsless/redis": "^0.0.8",
30
29
  "@awsless/sns": "^0.0.7",
31
30
  "@awsless/sqs": "^0.0.7",
32
- "@awsless/ssm": "^0.0.7"
31
+ "@awsless/ssm": "^0.0.7",
32
+ "@awsless/validate": "^0.0.6"
33
33
  },
34
34
  "dependencies": {
35
35
  "@aws-appsync/utils": "^1.5.0",