@awsless/awsless 0.0.119 → 0.0.121

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
@@ -3427,7 +3427,7 @@ var graphqlPlugin = definePlugin({
3427
3427
  }).array()
3428
3428
  }),
3429
3429
  async onTypeGen({ config: config2, write }) {
3430
- const types2 = new TypeGen("@awsless/awsless");
3430
+ const types2 = new TypeGen("@awsless/awsless/client");
3431
3431
  const resources = new TypeObject(1);
3432
3432
  const apis = /* @__PURE__ */ new Map();
3433
3433
  for (const stack of config2.stacks) {
@@ -4550,7 +4550,7 @@ var httpPlugin = definePlugin({
4550
4550
  }).array()
4551
4551
  }),
4552
4552
  async onTypeGen({ config: config2, write }) {
4553
- const types2 = new TypeGen("@awsless/awsless");
4553
+ const types2 = new TypeGen("@awsless/awsless/client");
4554
4554
  const resources = new TypeObject(1);
4555
4555
  const api = {};
4556
4556
  for (const stack of config2.stacks) {
@@ -0,0 +1,40 @@
1
+ interface HTTP {
2
+ }
3
+ type Method = 'GET' | 'POST';
4
+ type Path = string;
5
+ type Params = Record<string, string | number>;
6
+ type Query = Record<string, string>;
7
+ type Body = unknown;
8
+ type Route = {
9
+ param?: Params;
10
+ query?: Query;
11
+ body?: Body;
12
+ response: unknown;
13
+ };
14
+ type Routes = Record<Path, Route>;
15
+ type Schema = Partial<Record<Method, Routes>>;
16
+ type GetRoute<S extends Schema, M extends keyof S, P extends keyof S[M]> = S[M] extends Routes ? S[M][P] : never;
17
+ type Props<R extends Route> = {
18
+ headers?: Record<string, string>;
19
+ params?: R['param'] extends Params ? R['param'] : never;
20
+ query?: R['query'] extends Query ? R['query'] : never;
21
+ body?: R['body'] extends Body ? R['body'] : never;
22
+ };
23
+ type HttpFetcher = (props: {
24
+ method: Method;
25
+ path: Path;
26
+ headers: Headers;
27
+ query?: Query;
28
+ body?: Body;
29
+ }) => unknown;
30
+ declare const createHttpFetcher: (host: string) => HttpFetcher;
31
+ declare const createHttpClient: <S extends Partial<Record<Method, Routes>>>(fetcher: HttpFetcher) => {
32
+ 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"]>;
33
+ 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"]>;
34
+ 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"]>;
35
+ };
36
+
37
+ interface GraphQL {
38
+ }
39
+
40
+ export { GraphQL, HTTP, HttpFetcher, createHttpClient, createHttpFetcher };
package/dist/client.js ADDED
@@ -0,0 +1,46 @@
1
+ // src/node/http.ts
2
+ var createHttpFetcher = (host) => {
3
+ return async ({ method, path, headers, body, query }) => {
4
+ const url = new URL(host, path);
5
+ if (query) {
6
+ for (const [key, value] of Object.entries(query)) {
7
+ url.searchParams.set(key, value);
8
+ }
9
+ }
10
+ headers.set("content-type", "application/json");
11
+ const response = await fetch(url, {
12
+ method,
13
+ headers,
14
+ body: body ? JSON.stringify(body) : void 0
15
+ });
16
+ const result = await response.json();
17
+ return result;
18
+ };
19
+ };
20
+ var createHttpClient = (fetcher) => {
21
+ const fetch2 = (method, routeKey, props) => {
22
+ const path = routeKey.replaceAll(/{([a-z0-1-]+)}/, (key) => {
23
+ return props?.params?.[key.substring(1, key.length - 1)].toString() ?? "";
24
+ });
25
+ return fetcher({
26
+ headers: new Headers(props?.headers),
27
+ query: props?.query,
28
+ body: props?.body,
29
+ method,
30
+ path
31
+ });
32
+ };
33
+ return {
34
+ fetch: fetch2,
35
+ get(routeKey, props) {
36
+ return fetch2("GET", routeKey, props);
37
+ },
38
+ post(routeKey, props) {
39
+ return fetch2("POST", routeKey, props);
40
+ }
41
+ };
42
+ };
43
+ export {
44
+ createHttpClient,
45
+ createHttpFetcher
46
+ };
package/dist/index.d.ts CHANGED
@@ -11254,50 +11254,16 @@ interface StoreResources {
11254
11254
  }
11255
11255
  declare const Store: StoreResources;
11256
11256
 
11257
+ declare const getConfigName: (name: string) => string;
11258
+ interface ConfigResources {
11259
+ }
11260
+ declare const Config: ConfigResources;
11261
+
11257
11262
  declare const getSearchName: <N extends string, S extends string = "stack">(name: N, stack?: S) => `app-${S}-${N}`;
11258
11263
  interface SearchResources {
11259
11264
  }
11260
11265
  declare const Search: SearchResources;
11261
11266
 
11262
- interface HTTP {
11263
- }
11264
- type Method = 'GET' | 'POST';
11265
- type Path = string;
11266
- type Params = Record<string, string | number>;
11267
- type Query = Record<string, string>;
11268
- type Body = unknown;
11269
- type Route = {
11270
- param?: Params;
11271
- query?: Query;
11272
- body?: Body;
11273
- response: unknown;
11274
- };
11275
- type Routes = Record<Path, Route>;
11276
- type Schema = Partial<Record<Method, Routes>>;
11277
- type GetRoute<S extends Schema, M extends keyof S, P extends keyof S[M]> = S[M] extends Routes ? S[M][P] : never;
11278
- type Props<R extends Route> = {
11279
- headers?: Record<string, string>;
11280
- params?: R['param'] extends Params ? R['param'] : never;
11281
- query?: R['query'] extends Query ? R['query'] : never;
11282
- body?: R['body'] extends Body ? R['body'] : never;
11283
- };
11284
- type HttpFetcher = (props: {
11285
- method: Method;
11286
- path: Path;
11287
- headers: Headers;
11288
- query?: Query;
11289
- body?: Body;
11290
- }) => unknown;
11291
- declare const createHttpFetcher: (host: string) => HttpFetcher;
11292
- declare const createHttpClient: <S extends Partial<Record<Method, Routes>>>(fetcher: HttpFetcher) => {
11293
- 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"]>;
11294
- 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"]>;
11295
- 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"]>;
11296
- };
11297
-
11298
- interface GraphQL {
11299
- }
11300
-
11301
11267
  type FunctionProps<H extends Handler<S>, S extends BaseSchema> = {
11302
11268
  handle: H;
11303
11269
  schema?: S;
@@ -12158,4 +12124,4 @@ declare const defineStackConfig: (config: StackConfig) => StackConfig$1 | (Stack
12158
12124
  });
12159
12125
  declare const defineAppConfig: (config: AppConfig | AppConfigFactory<AppConfig>) => CombinedDefaultPluginsConfigInput | AppConfigFactory<CombinedDefaultPluginsConfigInput>;
12160
12126
 
12161
- export { APP, AppConfig, Auth, AuthResources, Cache, CacheResources, 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, getFunctionName, getGlobalResourceName, getLocalResourceName, getQueueName, getSearchName, getStoreName, getTableName, getTopicName, mockFunction, mockQueue, mockTopic, queue, topic };
12127
+ 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
@@ -1,12 +1,18 @@
1
1
  import {
2
2
  definePlugin
3
3
  } from "./chunk-PFTL6L4F.js";
4
- import {
5
- APP,
6
- STACK,
7
- getGlobalResourceName,
8
- getLocalResourceName
9
- } from "./chunk-UB7WT657.js";
4
+
5
+ // src/node/resource.ts
6
+ import { paramCase } from "change-case";
7
+ var APP = process.env.APP || "app";
8
+ var STACK = process.env.STACK || "stack";
9
+ var STAGE = process.env.STAGE || "stage";
10
+ var getLocalResourceName = (name, stack = STACK) => {
11
+ return `${APP}-${paramCase(stack)}-${paramCase(name)}`;
12
+ };
13
+ var getGlobalResourceName = (name) => {
14
+ return `${APP}-${paramCase(name)}`;
15
+ };
10
16
 
11
17
  // src/node/function.ts
12
18
  import { invoke } from "@awsless/lambda";
@@ -191,6 +197,49 @@ var Store = /* @__PURE__ */ createProxy((stack) => {
191
197
  });
192
198
  });
193
199
 
200
+ // src/node/config.ts
201
+ import { ssm } from "@awsless/ssm";
202
+ import { paramCase as paramCase2 } from "change-case";
203
+ var getConfigName = (name) => {
204
+ return `/.awsless/${APP}/${name}`;
205
+ };
206
+ var TEST = process.env.NODE_ENV === "test";
207
+ var CONFIGS = process.env.CONFIG;
208
+ var loadConfigData = /* @__NO_SIDE_EFFECTS__ */ async () => {
209
+ if (!TEST && CONFIGS) {
210
+ const keys = CONFIGS.split(",");
211
+ if (keys.length > 0) {
212
+ const paths = {};
213
+ for (const key of keys) {
214
+ paths[key] = getConfigName(key);
215
+ }
216
+ return ssm(paths);
217
+ }
218
+ }
219
+ return {};
220
+ };
221
+ var data = await /* @__PURE__ */ loadConfigData();
222
+ var Config = /* @__PURE__ */ new Proxy(
223
+ {},
224
+ {
225
+ get(_, name) {
226
+ const key = paramCase2(name);
227
+ const value = data[key];
228
+ if (typeof value === "undefined") {
229
+ throw new Error(
230
+ `The "${name}" config value hasn't been set yet. ${TEST ? `Use "Config.${name} = 'VAlUE'" to define your mock value.` : `Define access to the desired config value inside your awsless stack file.`}`
231
+ );
232
+ }
233
+ return value;
234
+ },
235
+ set(_, name, value) {
236
+ const key = paramCase2(name);
237
+ data[key] = value;
238
+ return true;
239
+ }
240
+ }
241
+ );
242
+
194
243
  // src/node/search.ts
195
244
  var getSearchName = getLocalResourceName;
196
245
  var Search = /* @__PURE__ */ createProxy((stack) => {
@@ -201,49 +250,6 @@ var Search = /* @__PURE__ */ createProxy((stack) => {
201
250
  });
202
251
  });
203
252
 
204
- // src/node/http.ts
205
- var createHttpFetcher = (host) => {
206
- return async ({ method, path, headers, body, query }) => {
207
- const url = new URL(host, path);
208
- if (query) {
209
- for (const [key, value] of Object.entries(query)) {
210
- url.searchParams.set(key, value);
211
- }
212
- }
213
- headers.set("content-type", "application/json");
214
- const response = await fetch(url, {
215
- method,
216
- headers,
217
- body: body ? JSON.stringify(body) : void 0
218
- });
219
- const result = await response.json();
220
- return result;
221
- };
222
- };
223
- var createHttpClient = (fetcher) => {
224
- const fetch2 = (method, routeKey, props) => {
225
- const path = routeKey.replaceAll(/{([a-z0-1-]+)}/, (key) => {
226
- return props?.params?.[key.substring(1, key.length - 1)].toString() ?? "";
227
- });
228
- return fetcher({
229
- headers: new Headers(props?.headers),
230
- query: props?.query,
231
- body: props?.body,
232
- method,
233
- path
234
- });
235
- };
236
- return {
237
- fetch: fetch2,
238
- get(routeKey, props) {
239
- return fetch2("GET", routeKey, props);
240
- },
241
- post(routeKey, props) {
242
- return fetch2("POST", routeKey, props);
243
- }
244
- };
245
- };
246
-
247
253
  // src/node/handle/function.ts
248
254
  import { lambda } from "@awsless/lambda";
249
255
  var func = (props) => {
@@ -349,6 +355,7 @@ export {
349
355
  APP,
350
356
  Auth,
351
357
  Cache,
358
+ Config,
352
359
  Fn,
353
360
  Function,
354
361
  Queue,
@@ -357,8 +364,6 @@ export {
357
364
  Store,
358
365
  Table,
359
366
  Topic,
360
- createHttpClient,
361
- createHttpFetcher,
362
367
  cron,
363
368
  defineAppConfig,
364
369
  definePlugin,
@@ -367,6 +372,7 @@ export {
367
372
  getAuthName,
368
373
  getAuthProps,
369
374
  getCacheProps,
375
+ getConfigName,
370
376
  getFunctionName,
371
377
  getGlobalResourceName,
372
378
  getLocalResourceName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.119",
3
+ "version": "0.0.121",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -22,16 +22,16 @@
22
22
  "import": "./dist/index.js",
23
23
  "types": "./dist/index.d.ts"
24
24
  },
25
- "./config": {
26
- "import": "./dist/node/config.js",
27
- "types": "./dist/node/config.d.ts"
25
+ "./client": {
26
+ "import": "./dist/client.js",
27
+ "types": "./dist/client.d.ts"
28
28
  }
29
29
  },
30
30
  "peerDependencies": {
31
- "@awsless/lambda": "^0.0.15",
32
31
  "@awsless/redis": "^0.0.8",
33
- "@awsless/sns": "^0.0.7",
34
32
  "@awsless/sqs": "^0.0.7",
33
+ "@awsless/lambda": "^0.0.15",
34
+ "@awsless/sns": "^0.0.7",
35
35
  "@awsless/ssm": "^0.0.7",
36
36
  "@awsless/validate": "^0.0.10",
37
37
  "@awsless/weak-cache": "^0.0.1"
@@ -89,7 +89,7 @@
89
89
  "test": "pnpm code test",
90
90
  "term": "zsh -c 'node dist/bin.js ${*} --config-file=./test/_data/config.ts' --",
91
91
  "berm": "zsh -c 'pnpm build; pnpm build-features; node dist/bin.js ${*} --config-file=./test/_data/config.ts' --",
92
- "build": "pnpm tsup src/index.ts src/bin.ts src/node/config.ts --format esm --dts --clean",
92
+ "build": "pnpm tsup src/index.ts src/bin.ts src/client.ts --format esm --dts --clean",
93
93
  "build-features": "node ./features/build.js",
94
94
  "prepublish": "if pnpm test schema; then pnpm build; pnpm build-features; else exit; fi"
95
95
  }
@@ -1,18 +0,0 @@
1
- // src/node/resource.ts
2
- import { paramCase } from "change-case";
3
- var APP = process.env.APP || "app";
4
- var STACK = process.env.STACK || "stack";
5
- var STAGE = process.env.STAGE || "stage";
6
- var getLocalResourceName = (name, stack = STACK) => {
7
- return `${APP}-${paramCase(stack)}-${paramCase(name)}`;
8
- };
9
- var getGlobalResourceName = (name) => {
10
- return `${APP}-${paramCase(name)}`;
11
- };
12
-
13
- export {
14
- APP,
15
- STACK,
16
- getLocalResourceName,
17
- getGlobalResourceName
18
- };
@@ -1,6 +0,0 @@
1
- declare const getConfigName: (name: string) => string;
2
- interface ConfigResources {
3
- }
4
- declare const Config: ConfigResources;
5
-
6
- export { Config, ConfigResources, getConfigName };
@@ -1,50 +0,0 @@
1
- import {
2
- APP
3
- } from "../chunk-UB7WT657.js";
4
-
5
- // src/node/config.ts
6
- import { ssm } from "@awsless/ssm";
7
- import { paramCase } from "change-case";
8
- var getConfigName = (name) => {
9
- return `/.awsless/${APP}/${name}`;
10
- };
11
- var TEST = process.env.NODE_ENV === "test";
12
- var CONFIGS = process.env.CONFIG;
13
- var loadConfigData = /* @__NO_SIDE_EFFECTS__ */ async () => {
14
- if (!TEST && CONFIGS) {
15
- const keys = CONFIGS.split(",");
16
- if (keys.length > 0) {
17
- const paths = {};
18
- for (const key of keys) {
19
- paths[key] = getConfigName(key);
20
- }
21
- return ssm(paths);
22
- }
23
- }
24
- return {};
25
- };
26
- var data = await /* @__PURE__ */ loadConfigData();
27
- var Config = /* @__PURE__ */ new Proxy(
28
- {},
29
- {
30
- get(_, name) {
31
- const key = paramCase(name);
32
- const value = data[key];
33
- if (typeof value === "undefined") {
34
- throw new Error(
35
- `The "${name}" config value hasn't been set yet. ${TEST ? `Use "Config.${name} = 'VAlUE'" to define your mock value.` : `Define access to the desired config value inside your awsless stack file.`}`
36
- );
37
- }
38
- return value;
39
- },
40
- set(_, name, value) {
41
- const key = paramCase(name);
42
- data[key] = value;
43
- return true;
44
- }
45
- }
46
- );
47
- export {
48
- Config,
49
- getConfigName
50
- };