@awsless/awsless 0.0.34 → 0.0.36

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
@@ -998,7 +998,145 @@ var hasOnFailure = (config) => {
998
998
  };
999
999
 
1000
1000
  // src/plugins/function.ts
1001
+ import { camelCase as camelCase2 } from "change-case";
1002
+
1003
+ // src/util/path.ts
1004
+ import { lstat } from "fs/promises";
1005
+ import { join, normalize } from "path";
1006
+ var root = process.cwd();
1007
+ var directories = {
1008
+ root,
1009
+ get output() {
1010
+ return join(this.root, ".awsless");
1011
+ },
1012
+ get cache() {
1013
+ return join(this.output, "cache");
1014
+ },
1015
+ get asset() {
1016
+ return join(this.output, "asset");
1017
+ },
1018
+ get types() {
1019
+ return join(this.output, "types");
1020
+ },
1021
+ get template() {
1022
+ return join(this.output, "template");
1023
+ }
1024
+ };
1025
+ var setRoot = (path = root) => {
1026
+ directories.root = path;
1027
+ };
1028
+ var findRootDir = async (path, configFile, level = 5) => {
1029
+ if (!level) {
1030
+ throw new TypeError("No awsless project found");
1031
+ }
1032
+ const file = join(path, configFile);
1033
+ const exists = await fileExist(file);
1034
+ if (exists) {
1035
+ return path;
1036
+ }
1037
+ return findRootDir(normalize(join(path, "..")), configFile, level - 1);
1038
+ };
1039
+ var fileExist = async (file) => {
1040
+ try {
1041
+ const stat = await lstat(file);
1042
+ if (stat.isFile()) {
1043
+ return true;
1044
+ }
1045
+ } catch (error) {
1046
+ }
1047
+ return false;
1048
+ };
1049
+
1050
+ // src/plugins/function.ts
1051
+ import { relative as relative2 } from "path";
1052
+
1053
+ // src/util/type-gen.ts
1054
+ import { mkdir, writeFile } from "fs/promises";
1055
+ import { join as join2, relative } from "path";
1001
1056
  import { camelCase } from "change-case";
1057
+ var generateResourceTypes = async (config) => {
1058
+ const plugins = [
1059
+ ...defaultPlugins,
1060
+ ...config.plugins || []
1061
+ ];
1062
+ const files = [];
1063
+ for (const plugin of plugins) {
1064
+ const code = plugin.onTypeGen?.({ config });
1065
+ if (code) {
1066
+ const file = join2(directories.types, `${plugin.name}.d.ts`);
1067
+ files.push(relative(directories.root, file));
1068
+ await mkdir(directories.types, { recursive: true });
1069
+ await writeFile(file, code);
1070
+ }
1071
+ }
1072
+ if (files.length) {
1073
+ const code = files.map((file) => `/// <reference path='${file}' />`).join("\n");
1074
+ await writeFile(join2(directories.root, `awsless.d.ts`), code);
1075
+ }
1076
+ };
1077
+ var TypeGen = class {
1078
+ constructor(module, interfaceName) {
1079
+ this.module = module;
1080
+ this.interfaceName = interfaceName;
1081
+ }
1082
+ codes = /* @__PURE__ */ new Set();
1083
+ types = /* @__PURE__ */ new Map();
1084
+ imports = /* @__PURE__ */ new Map();
1085
+ addImport(varName, path) {
1086
+ this.imports.set(varName, path);
1087
+ return this;
1088
+ }
1089
+ addCode(code) {
1090
+ this.codes.add(code);
1091
+ return this;
1092
+ }
1093
+ addType(name, type) {
1094
+ if (type) {
1095
+ this.types.set(name, type);
1096
+ }
1097
+ return this;
1098
+ }
1099
+ toString() {
1100
+ if (this.types.size === 0) {
1101
+ return;
1102
+ }
1103
+ const imports = Array.from(this.imports.entries()).map(([varName, path]) => {
1104
+ return `import ${camelCase(varName)} from '${path}'`;
1105
+ }).join("\n");
1106
+ return [
1107
+ imports,
1108
+ ...Array.from(this.codes),
1109
+ `declare module '${this.module}' {`,
1110
+ ` interface ${this.interfaceName} {`,
1111
+ ...Array.from(this.types.entries()).map(([propName, type]) => {
1112
+ return ` readonly ${camelCase(propName)}: ${type}`;
1113
+ }),
1114
+ ` }`,
1115
+ `}`
1116
+ ].join("\n");
1117
+ }
1118
+ };
1119
+ var TypeObject = class {
1120
+ types = /* @__PURE__ */ new Map();
1121
+ addType(name, type) {
1122
+ this.types.set(name, type);
1123
+ return this;
1124
+ }
1125
+ toString() {
1126
+ if (!this.types.size) {
1127
+ return "";
1128
+ }
1129
+ return [
1130
+ "{",
1131
+ ...Array.from(this.types.entries()).map(([propName, type]) => {
1132
+ return ` readonly ${camelCase(propName)}: ${type}`;
1133
+ }),
1134
+ " }"
1135
+ ].join("\n");
1136
+ }
1137
+ };
1138
+
1139
+ // src/plugins/function.ts
1002
1140
  var MemorySizeSchema = SizeSchema.refine(sizeMin(Size.megaBytes(128)), "Minimum memory size is 128 MB").refine(sizeMax(Size.gigaBytes(10)), "Minimum memory size is 10 GB");
1003
1141
  var TimeoutSchema = DurationSchema.refine(durationMin(Duration.seconds(10)), "Minimum timeout duration is 10 seconds").refine(durationMax(Duration.minutes(15)), "Maximum timeout duration is 15 minutes");
1004
1142
  var EphemeralStorageSizeSchema = SizeSchema.refine(sizeMin(Size.megaBytes(512)), "Minimum ephemeral storage size is 512 MB").refine(sizeMax(Size.gigaBytes(10)), "Minimum ephemeral storage size is 10 GB");
@@ -1133,48 +1271,33 @@ var schema = z6.object({
1133
1271
  ).optional()
1134
1272
  }).array()
1135
1273
  });
1274
+ var typeGenCode = `
1275
+ import { InvokeOptions } from '@awsless/lambda'
1276
+
1277
+ type Invoke<Name extends string, Func extends (...args: any[]) => any> = {
1278
+ name: Name
1279
+ invoke: (event: Parameters<Func>[0], options?: Omit<InvokeOptions, 'name' | 'payload'>) => ReturnType<Func>
1280
+ async: (event: Parameters<Func>[0], options?: Omit<InvokeOptions, 'name' | 'payload' | 'type'>) => ReturnType<Func>
1281
+ }`;
1136
1282
  var functionPlugin = definePlugin({
1137
1283
  name: "function",
1138
1284
  schema,
1139
1285
  onTypeGen({ config }) {
1140
- const imports = [];
1141
- const props = [];
1286
+ const types2 = new TypeGen("@awsless/awsless", "FunctionResources");
1287
+ types2.addCode(typeGenCode);
1142
1288
  for (const stack of config.stacks) {
1143
- const functions = [];
1289
+ const list3 = new TypeObject();
1144
1290
  for (const [name, fileOrProps] of Object.entries(stack.functions || {})) {
1145
- const varName = camelCase(`${stack.name}-${name}`);
1291
+ const varName = camelCase2(`${stack.name}-${name}`);
1292
+ const funcName = formatName(`${config.name}-${stack.name}-${name}`);
1146
1293
  const file = typeof fileOrProps === "string" ? fileOrProps : fileOrProps.file;
1147
- imports.push(`import ${varName} from '${file}'`);
1148
- functions.push(` readonly ${camelCase(name)}: Invoke<typeof ${varName}>`);
1149
- }
1150
- if (functions.length > 0) {
1151
- props.push(` readonly ${camelCase(stack.name)}: {
1152
- ${functions.join("\n")}
1153
- }`);
1294
+ const relFile = relative2(directories.types, file);
1295
+ types2.addImport(varName, relFile);
1296
+ list3.addType(name, `Invoke<'${funcName}', typeof ${varName}>`);
1154
1297
  }
1298
+ types2.addType(stack.name, list3.toString());
1155
1299
  }
1156
- if (imports.length === 0) {
1157
- return;
1158
- }
1159
- return (
1160
- /* TS */
1161
- `
1162
- ${imports.join("\n")}
1163
-
1164
- import { InvokeOptions } from '@awsless/lambda'
1165
-
1166
- type Options = Omit<InvokeOptions, 'name' | 'payload'>
1167
-
1168
- type Invoke<Func extends (...args: any[]) => any> = {
1169
- (event: Parameters<Func>[0], options?: Options): ReturnType<Func>
1170
- }
1171
-
1172
- declare module '@awsless/awsless' {
1173
- interface FunctionResources {
1174
- ${props.join("\n")}
1175
- }
1176
- }`
1177
- );
1300
+ return types2.toString();
1178
1301
  },
1179
1302
  onStack(ctx) {
1180
1303
  const { config, stack } = ctx;
@@ -1575,6 +1698,18 @@ var queuePlugin = definePlugin({
1575
1698
  ).optional()
1576
1699
  }).array()
1577
1700
  }),
1701
+ onTypeGen({ config }) {
1702
+ const types2 = new TypeGen("@awsless/awsless", "QueueResources");
1703
+ for (const stack of config.stacks) {
1704
+ const list3 = new TypeObject();
1705
+ for (const name of Object.keys(stack.queues || {})) {
1706
+ const queueName = formatName(`${config.name}-${stack.name}-${name}`);
1707
+ list3.addType(name, `{ name: '${queueName}' }`);
1708
+ }
1709
+ types2.addType(stack.name, list3.toString());
1710
+ }
1711
+ return types2.toString();
1712
+ },
1578
1713
  onStack(ctx) {
1579
1714
  const { stack, config, stackConfig, bind } = ctx;
1580
1715
  for (const [id, functionOrProps] of Object.entries(stackConfig.queues || {})) {
@@ -1848,6 +1983,18 @@ var tablePlugin = definePlugin({
1848
1983
  ).optional()
1849
1984
  }).array()
1850
1985
  }),
1986
+ onTypeGen({ config }) {
1987
+ const types2 = new TypeGen("@awsless/awsless", "TableResources");
1988
+ for (const stack of config.stacks) {
1989
+ const list3 = new TypeObject();
1990
+ for (const name of Object.keys(stack.tables || {})) {
1991
+ const tableName = formatName(`${config.name}-${stack.name}-${name}`);
1992
+ list3.addType(name, `{ name: '${tableName}' }`);
1993
+ }
1994
+ types2.addType(stack.name, list3.toString());
1995
+ }
1996
+ return types2.toString();
1997
+ },
1851
1998
  onStack(ctx) {
1852
1999
  const { config, stack, stackConfig, bind } = ctx;
1853
2000
  for (const [id, props] of Object.entries(stackConfig.tables || {})) {
@@ -2034,6 +2181,16 @@ var topicPlugin = definePlugin({
2034
2181
  topics: z11.record(ResourceIdSchema, FunctionSchema).optional()
2035
2182
  }).array()
2036
2183
  }),
2184
+ onTypeGen({ config }) {
2185
+ const gen = new TypeGen("@awsless/awsless", "TopicResources");
2186
+ for (const stack of config.stacks) {
2187
+ for (const topic of Object.keys(stack.topics || {})) {
2188
+ const name = formatName(`${config.name}-${topic}`);
2189
+ gen.addType(topic, `{ name: '${name}' }`);
2190
+ }
2191
+ }
2192
+ return gen.toString();
2193
+ },
2037
2194
  onApp({ config, bootstrap: bootstrap2, bind }) {
2038
2195
  const allTopicNames = config.stacks.map((stack) => {
2039
2196
  return Object.keys(stack.topics || {});
@@ -4088,7 +4245,7 @@ var toApp = async (config, filters) => {
4088
4245
  };
4089
4246
 
4090
4247
  // src/config.ts
4091
- import { join as join3 } from "path";
4248
+ import { join as join4 } from "path";
4092
4249
 
4093
4250
  // src/util/account.ts
4094
4251
  import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
@@ -4172,60 +4329,12 @@ var AppSchema = z23.object({
4172
4329
  });
4173
4330
 
4174
4331
  // src/util/import.ts
4175
- import { rollup as rollup2 } from "rollup";
4332
+ import { rollup as rollup2, watch } from "rollup";
4176
4333
  import { swc as swc2 } from "rollup-plugin-swc3";
4177
4334
  import replace from "rollup-plugin-replace";
4178
- import { dirname as dirname2, join as join2 } from "path";
4179
- import { mkdir, writeFile } from "fs/promises";
4180
-
4181
- // src/util/path.ts
4182
- import { lstat } from "fs/promises";
4183
- import { join, normalize } from "path";
4184
- var root = process.cwd();
4185
- var directories = {
4186
- root,
4187
- get output() {
4188
- return join(this.root, ".awsless");
4189
- },
4190
- get cache() {
4191
- return join(this.output, "cache");
4192
- },
4193
- get asset() {
4194
- return join(this.output, "asset");
4195
- },
4196
- get types() {
4197
- return join(this.output, "types");
4198
- },
4199
- get template() {
4200
- return join(this.output, "template");
4201
- }
4202
- };
4203
- var setRoot = (path = root) => {
4204
- directories.root = path;
4205
- };
4206
- var findRootDir = async (path, configFile, level = 5) => {
4207
- if (!level) {
4208
- throw new TypeError("No awsless project found");
4209
- }
4210
- const file = join(path, configFile);
4211
- const exists = await fileExist(file);
4212
- if (exists) {
4213
- return path;
4214
- }
4215
- return findRootDir(normalize(join(path, "..")), configFile, level - 1);
4216
- };
4217
- var fileExist = async (file) => {
4218
- try {
4219
- const stat = await lstat(file);
4220
- if (stat.isFile()) {
4221
- return true;
4222
- }
4223
- } catch (error) {
4224
- }
4225
- return false;
4226
- };
4227
-
4228
- // src/util/import.ts
4335
+ import { EventIterator } from "event-iterator";
4336
+ import { dirname as dirname2, join as join3 } from "path";
4337
+ import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
4229
4338
  var importFile = async (path) => {
4230
4339
  const bundle = await rollup2({
4231
4340
  input: path,
@@ -4244,18 +4353,73 @@ var importFile = async (path) => {
4244
4353
  })
4245
4354
  ]
4246
4355
  });
4247
- const outputFile = join2(directories.cache, "config.js");
4356
+ const outputFile = join3(directories.cache, "config.js");
4248
4357
  const result = await bundle.generate({
4249
4358
  format: "esm",
4250
4359
  exports: "default"
4251
4360
  });
4252
4361
  const output = result.output[0];
4253
4362
  const code = output.code;
4254
- await mkdir(directories.cache, { recursive: true });
4255
- await writeFile(outputFile, code);
4363
+ await mkdir2(directories.cache, { recursive: true });
4364
+ await writeFile2(outputFile, code);
4256
4365
  debug("Save config file:", style.info(outputFile));
4257
4366
  return import(outputFile);
4258
4367
  };
4368
+ var watchFile = (path) => {
4369
+ return new EventIterator((queue2) => {
4370
+ const watcher = watch({
4371
+ watch: {
4372
+ skipWrite: true
4373
+ },
4374
+ input: path,
4375
+ onwarn: (error) => {
4376
+ debugError(error.message);
4377
+ },
4378
+ plugins: [
4379
+ replace({
4380
+ __dirname: (id) => `'${dirname2(id)}'`
4381
+ }),
4382
+ swc2({
4383
+ minify: false,
4384
+ jsc: {
4385
+ baseUrl: dirname2(path)
4386
+ }
4387
+ })
4388
+ ]
4389
+ });
4390
+ let resume;
4391
+ queue2.on("lowWater", () => {
4392
+ resume?.(true);
4393
+ });
4394
+ watcher.on("close", queue2.stop);
4395
+ watcher.on("event", async (event) => {
4396
+ if (event.code === "ERROR") {
4397
+ queue2.fail(new Error(event.error.message));
4398
+ }
4399
+ if (event.code === "BUNDLE_END") {
4400
+ const result = await event.result.generate({
4401
+ format: "esm",
4402
+ exports: "default"
4403
+ });
4404
+ event.result.close();
4405
+ const output = result.output[0];
4406
+ const code = output.code;
4407
+ const outputFile = join3(directories.cache, "config.js");
4408
+ await mkdir2(directories.cache, { recursive: true });
4409
+ await writeFile2(outputFile, code);
4410
+ debug("Save config file:", style.info(outputFile));
4411
+ const config = await import(`${outputFile}?${Date.now()}`);
4412
+ queue2.push(config);
4413
+ }
4414
+ });
4415
+ return () => {
4416
+ watcher.close();
4417
+ };
4418
+ }, {
4419
+ highWaterMark: 1,
4420
+ lowWaterMark: 0
4421
+ });
4422
+ };
4259
4423
 
4260
4424
  // src/config.ts
4261
4425
  var importConfig = async (options) => {
@@ -4265,7 +4429,7 @@ var importConfig = async (options) => {
4265
4429
  setRoot(root2);
4266
4430
  debug("CWD:", style.info(root2));
4267
4431
  debug("Import config file");
4268
- const fileName = join3(root2, configFile);
4432
+ const fileName = join4(root2, configFile);
4269
4433
  const module = await importFile(fileName);
4270
4434
  const appConfig = typeof module.default === "function" ? await module.default(options) : module.default;
4271
4435
  debug("Validate config file");
@@ -4291,6 +4455,40 @@ var importConfig = async (options) => {
4291
4455
  credentials
4292
4456
  };
4293
4457
  };
4458
+ var watchConfig = async function* (options) {
4459
+ debug("Find the root directory");
4460
+ const configFile = options.configFile || "awsless.config.ts";
4461
+ const root2 = await findRootDir(process.cwd(), configFile);
4462
+ setRoot(root2);
4463
+ debug("CWD:", style.info(root2));
4464
+ debug("Import config file");
4465
+ const fileName = join4(root2, configFile);
4466
+ for await (const module of watchFile(fileName)) {
4467
+ const appConfig = typeof module.default === "function" ? await module.default(options) : module.default;
4468
+ debug("Validate config file");
4469
+ const plugins = [
4470
+ ...defaultPlugins,
4471
+ ...appConfig.plugins || []
4472
+ ];
4473
+ let schema2 = AppSchema;
4474
+ for (const plugin of plugins) {
4475
+ if (plugin.schema) {
4476
+ schema2 = schema2.and(plugin.schema);
4477
+ }
4478
+ }
4479
+ const config = await schema2.parseAsync(appConfig);
4480
+ debug("Load credentials", style.info(config.profile));
4481
+ const credentials = getCredentials(config.profile);
4482
+ debug("Load AWS account ID");
4483
+ const account = await getAccountId(credentials, config.region);
4484
+ debug("Account ID:", style.info(account));
4485
+ yield {
4486
+ ...config,
4487
+ account,
4488
+ credentials
4489
+ };
4490
+ }
4491
+ };
4294
4492
 
4295
4493
  // src/cli/ui/layout/basic.ts
4296
4494
  var br = () => {
@@ -4766,7 +4964,7 @@ var layout = async (cb) => {
4766
4964
  };
4767
4965
 
4768
4966
  // src/cli/ui/complex/builder.ts
4769
- import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
4967
+ import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
4770
4968
 
4771
4969
  // src/cli/ui/layout/flex-line.ts
4772
4970
  var stripEscapeCode = (str) => {
@@ -4789,7 +4987,7 @@ var flexLine = (term, left, right, reserveSpace = 0) => {
4789
4987
  };
4790
4988
 
4791
4989
  // src/cli/ui/complex/builder.ts
4792
- import { dirname as dirname3, join as join4 } from "path";
4990
+ import { dirname as dirname3, join as join5 } from "path";
4793
4991
  var assetBuilder = (app) => {
4794
4992
  return async (term) => {
4795
4993
  const assets = [];
@@ -4852,10 +5050,10 @@ var assetBuilder = (app) => {
4852
5050
  try {
4853
5051
  const data = await asset.build({
4854
5052
  async write(file, data2) {
4855
- const fullpath = join4(directories.asset, asset.type, app.name, stack.name, asset.id, file);
5053
+ const fullpath = join5(directories.asset, asset.type, app.name, stack.name, asset.id, file);
4856
5054
  const basepath = dirname3(fullpath);
4857
- await mkdir2(basepath, { recursive: true });
4858
- await writeFile2(fullpath, data2);
5055
+ await mkdir3(basepath, { recursive: true });
5056
+ await writeFile3(fullpath, data2);
4859
5057
  }
4860
5058
  });
4861
5059
  details.set({
@@ -4879,7 +5077,7 @@ var assetBuilder = (app) => {
4879
5077
  };
4880
5078
 
4881
5079
  // src/util/cleanup.ts
4882
- import { mkdir as mkdir3, rm } from "fs/promises";
5080
+ import { mkdir as mkdir4, rm } from "fs/promises";
4883
5081
  var cleanUp = async () => {
4884
5082
  debug("Clean up template, cache, and asset files");
4885
5083
  const paths = [
@@ -4893,45 +5091,28 @@ var cleanUp = async () => {
4893
5091
  force: true,
4894
5092
  maxRetries: 2
4895
5093
  })));
4896
- await Promise.all(paths.map((path) => mkdir3(path, {
5094
+ await Promise.all(paths.map((path) => mkdir4(path, {
4897
5095
  recursive: true
4898
5096
  })));
4899
5097
  };
4900
5098
 
4901
5099
  // src/cli/ui/complex/template.ts
4902
- import { mkdir as mkdir4, writeFile as writeFile3 } from "fs/promises";
4903
- import { join as join5 } from "path";
5100
+ import { mkdir as mkdir5, writeFile as writeFile4 } from "fs/promises";
5101
+ import { join as join6 } from "path";
4904
5102
  var templateBuilder = (app) => {
4905
5103
  return async (term) => {
4906
5104
  const done = term.out.write(loadingDialog("Building stack templates..."));
4907
5105
  await Promise.all(app.stacks.map(async (stack) => {
4908
5106
  const template = stack.toString(true);
4909
- const path = join5(directories.template, app.name);
4910
- const file = join5(path, `${stack.name}.json`);
4911
- await mkdir4(path, { recursive: true });
4912
- await writeFile3(file, template);
5107
+ const path = join6(directories.template, app.name);
5108
+ const file = join6(path, `${stack.name}.json`);
5109
+ await mkdir5(path, { recursive: true });
5110
+ await writeFile4(file, template);
4913
5111
  }));
4914
5112
  done("Done building stack templates");
4915
5113
  };
4916
5114
  };
4917
5115
 
4918
- // src/util/type-gen.ts
4919
- import { mkdir as mkdir5, writeFile as writeFile4 } from "fs/promises";
4920
- import { join as join6 } from "path";
4921
- var generateResourceTypes = async (config) => {
4922
- const plugins = [
4923
- ...defaultPlugins,
4924
- ...config.plugins || []
4925
- ];
4926
- for (const plugin of plugins) {
4927
- const code = plugin.onTypeGen?.({ config });
4928
- if (code) {
4929
- await mkdir5(directories.types, { recursive: true });
4930
- await writeFile4(join6(directories.types, `${plugin.name}.d.ts`), code);
4931
- }
4932
- }
4933
- };
4934
-
4935
5116
  // src/cli/ui/complex/types.ts
4936
5117
  var typesGenerator = (config) => {
4937
5118
  return async (term) => {
@@ -5723,6 +5904,19 @@ var types = (program2) => {
5723
5904
  });
5724
5905
  };
5725
5906
 
5907
+ // src/cli/command/dev.ts
5908
+ var dev = (program2) => {
5909
+ program2.command("dev").description("Start the development service").action(async () => {
5910
+ await layout(async (_, write) => {
5911
+ const options = program2.optsWithGlobals();
5912
+ for await (const config of watchConfig(options)) {
5913
+ await cleanUp();
5914
+ await write(typesGenerator(config));
5915
+ }
5916
+ });
5917
+ });
5918
+ };
5919
+
5726
5920
  // src/cli/program.ts
5727
5921
  var program = new Command();
5728
5922
  program.name(logo().join("").replace(/\s+/, ""));
@@ -5744,6 +5938,7 @@ var commands2 = [
5744
5938
  types,
5745
5939
  build,
5746
5940
  deploy,
5941
+ dev,
5747
5942
  secrets,
5748
5943
  test
5749
5944
  // diff,
package/dist/index.cjs CHANGED
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Function: () => Function,
24
+ Queue: () => Queue,
24
25
  Table: () => Table,
26
+ Topic: () => Topic,
25
27
  defineAppConfig: () => defineAppConfig,
26
28
  definePlugin: () => definePlugin,
27
29
  defineStackConfig: () => defineStackConfig,
@@ -46,15 +48,13 @@ var import_change_case = require("change-case");
46
48
  var APP = process.env.APP || "app";
47
49
  var STACK = process.env.STACK || "stack";
48
50
  var getLocalResourceName = (name, stack = STACK) => {
49
- return `${APP}--${(0, import_change_case.paramCase)(stack)}--${(0, import_change_case.paramCase)(name)}`;
51
+ return `${APP}-${(0, import_change_case.paramCase)(stack)}-${(0, import_change_case.paramCase)(name)}`;
50
52
  };
51
53
  var getGlobalResourceName = (name) => {
52
- return `${APP}--${(0, import_change_case.paramCase)(name)}`;
54
+ return `${APP}-${(0, import_change_case.paramCase)(name)}`;
53
55
  };
54
56
  var getSearchName = getLocalResourceName;
55
57
  var getStoreName = getLocalResourceName;
56
- var getQueueName = getLocalResourceName;
57
- var getTopicName = getGlobalResourceName;
58
58
  var getSecretName = (name) => {
59
59
  return `/.awsless/${APP}/${name}`;
60
60
  };
@@ -86,14 +86,26 @@ var createProxy = (cb) => {
86
86
  var getFunctionName = (stack, name) => {
87
87
  return getLocalResourceName(name, stack);
88
88
  };
89
- var Function = createProxy((stack) => {
90
- return createProxy((name) => {
91
- return (event, options = {}) => {
92
- return (0, import_lambda.invoke)({
93
- ...options,
94
- name: getFunctionName(stack, name),
95
- payload: event
96
- });
89
+ var Function = createProxy((stackName) => {
90
+ return createProxy((funcName) => {
91
+ const name = getFunctionName(stackName, funcName);
92
+ return {
93
+ name,
94
+ invoke(payload, options = {}) {
95
+ return (0, import_lambda.invoke)({
96
+ ...options,
97
+ name,
98
+ payload
99
+ });
100
+ },
101
+ async(payload, options = {}) {
102
+ return (0, import_lambda.invoke)({
103
+ ...options,
104
+ name,
105
+ payload,
106
+ type: "Event"
107
+ });
108
+ }
97
109
  };
98
110
  });
99
111
  });
@@ -102,7 +114,33 @@ var Function = createProxy((stack) => {
102
114
  var getTableName = getLocalResourceName;
103
115
  var Table = createProxy((stack) => {
104
116
  return createProxy((name) => {
105
- return getTableName(name, stack);
117
+ return {
118
+ name: getTableName(name, stack)
119
+ };
120
+ });
121
+ });
122
+
123
+ // src/node/topic.ts
124
+ var getTopicName = getGlobalResourceName;
125
+ var Topic = createProxy((topic) => {
126
+ const name = getTopicName(topic);
127
+ return {
128
+ name
129
+ // publish(payload:unknown) {
130
+ // }
131
+ };
132
+ });
133
+
134
+ // src/node/queue.ts
135
+ var getQueueName = getLocalResourceName;
136
+ var Queue = createProxy((stack) => {
137
+ return createProxy((queue) => {
138
+ const name = getQueueName(queue, stack);
139
+ return {
140
+ name
141
+ // sendMessage(payload:unknown) {
142
+ // }
143
+ };
106
144
  });
107
145
  });
108
146
 
@@ -116,7 +154,9 @@ var defineAppConfig = (config) => {
116
154
  // Annotate the CommonJS export names for ESM import in node:
117
155
  0 && (module.exports = {
118
156
  Function,
157
+ Queue,
119
158
  Table,
159
+ Topic,
120
160
  defineAppConfig,
121
161
  definePlugin,
122
162
  defineStackConfig,