@awsless/awsless 0.0.190 → 0.0.192

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.
Files changed (2) hide show
  1. package/dist/bin.js +77 -87
  2. package/package.json +6 -6
package/dist/bin.js CHANGED
@@ -2415,9 +2415,12 @@ var configFeature = defineFeature({
2415
2415
  await ctx.write("config.d.ts", gen, true);
2416
2416
  },
2417
2417
  onStack(ctx) {
2418
- const configs = ctx.stackConfig.configs;
2418
+ const configs = ctx.stackConfig.configs ?? [];
2419
+ for (const name of configs) {
2420
+ ctx.registerConfig(name);
2421
+ }
2419
2422
  ctx.onFunction(({ lambda, policy }) => {
2420
- if (configs && configs.length) {
2423
+ if (configs.length) {
2421
2424
  lambda.addEnvironment("CONFIG", configs.join(","));
2422
2425
  policy.addStatement({
2423
2426
  actions: [
@@ -2513,7 +2516,7 @@ var functionFeature = defineFeature({
2513
2516
  import { paramCase as paramCase5 } from "change-case";
2514
2517
  import { mergeTypeDefs } from "@graphql-tools/merge";
2515
2518
  import { generate } from "@awsless/graphql";
2516
- import { buildSchema, isObjectType, print } from "graphql";
2519
+ import { buildSchema, print } from "graphql";
2517
2520
  import { readFile as readFile5 } from "fs/promises";
2518
2521
  import { Asset as Asset2, Node as Node6, aws as aws6 } from "@awsless/formation";
2519
2522
 
@@ -2748,28 +2751,10 @@ var graphqlFeature = defineFeature({
2748
2751
  onApp(ctx) {
2749
2752
  for (const [id, props] of Object.entries(ctx.appConfig.defaults.graphql ?? {})) {
2750
2753
  const group = new Node6(ctx.base, "graphql", id);
2751
- const role = new aws6.iam.Role(group, "role", {
2752
- assumedBy: "appsync.amazonaws.com",
2753
- policies: [
2754
- {
2755
- name: "merge-policy",
2756
- statements: [
2757
- {
2758
- actions: [
2759
- //
2760
- "appsync:StartSchemaMerge",
2761
- "appsync:SourceGraphQL"
2762
- ],
2763
- resources: [`arn:aws:appsync:${ctx.appConfig.region}:${ctx.accountId}:apis/*`]
2764
- }
2765
- ]
2766
- }
2767
- ]
2768
- });
2754
+ const name = formatGlobalResourceName(ctx.app.name, "graphql", id);
2769
2755
  const api = new aws6.appsync.GraphQLApi(group, "api", {
2770
- name: formatGlobalResourceName(ctx.app.name, "graphql", id),
2771
- type: "merged",
2772
- role: role.arn,
2756
+ name,
2757
+ type: "graphql",
2773
2758
  auth: {
2774
2759
  default: props.auth ? {
2775
2760
  type: "cognito",
@@ -2781,6 +2766,32 @@ var graphqlFeature = defineFeature({
2781
2766
  }
2782
2767
  });
2783
2768
  ctx.shared.set(`graphql-${id}-id`, api.id);
2769
+ ctx.registerBuild("graphql-schema", name, async (build3) => {
2770
+ const sources = [];
2771
+ const fingers = [];
2772
+ for (const stack of ctx.stackConfigs) {
2773
+ const file = stack.graphql?.[id]?.schema;
2774
+ if (file) {
2775
+ const source = await readFile5(file, "utf8");
2776
+ const finger2 = createHash4("sha1").update(source).digest("hex");
2777
+ sources.push(source);
2778
+ fingers.push(finger2);
2779
+ }
2780
+ }
2781
+ const finger = createHash4("sha1").update(sources.sort().join(" ")).digest("hex");
2782
+ return build3(finger, async (write) => {
2783
+ const defs = mergeTypeDefs([scalarSchema, baseSchema, ...sources]);
2784
+ const output = print(defs);
2785
+ await write("schema.gql", output);
2786
+ return {
2787
+ size: formatByteSize(Buffer.from(output).byteLength)
2788
+ };
2789
+ });
2790
+ });
2791
+ new aws6.appsync.GraphQLSchema(group, "schema", {
2792
+ apiId: api.id,
2793
+ definition: Asset2.fromFile(getBuildPath("graphql-schema", name, "schema.gql"))
2794
+ });
2784
2795
  if (props.resolver) {
2785
2796
  ctx.registerBuild("graphql-resolver", id, async (build3) => {
2786
2797
  const resolver = props.resolver;
@@ -2831,57 +2842,11 @@ var graphqlFeature = defineFeature({
2831
2842
  );
2832
2843
  }
2833
2844
  const group = new Node6(ctx.stack, "graphql", id);
2834
- const name = formatLocalResourceName(ctx.app.name, ctx.stack.name, "graphql", id);
2835
- const api = new aws6.appsync.GraphQLApi(group, "api", {
2836
- name,
2837
- // visibility: false,
2838
- auth: {
2839
- default: {
2840
- type: "iam"
2841
- }
2842
- }
2843
- });
2844
- ctx.registerBuild("graphql-schema", name, async (build3) => {
2845
- const source = await readFile5(props.schema, "utf8");
2846
- const finger = createHash4("sha1").update(source).digest("hex");
2847
- return build3(finger, async (write) => {
2848
- const defs = mergeTypeDefs([scalarSchema, baseSchema, source]);
2849
- const output = print(defs);
2850
- const schema2 = buildSchema(output);
2851
- for (const [typeName, fields] of Object.entries(props.resolvers ?? {})) {
2852
- const type = schema2.getType(typeName);
2853
- if (!type || !isObjectType(type)) {
2854
- throw new FileError(props.schema, `GraphQL schema type doesn't exist: ${typeName}`);
2855
- }
2856
- const typeFields = type.getFields();
2857
- for (const fieldName of Object.keys(fields ?? {})) {
2858
- if (!(fieldName in typeFields)) {
2859
- throw new FileError(
2860
- props.schema,
2861
- `GraphQL schema field doesn't exist: ${typeName}.${fieldName}`
2862
- );
2863
- }
2864
- }
2865
- }
2866
- await write("schema.gql", output);
2867
- return {
2868
- size: formatByteSize(Buffer.from(source).byteLength)
2869
- };
2870
- });
2871
- });
2872
- const schema = new aws6.appsync.GraphQLSchema(group, "schema", {
2873
- apiId: api.id,
2874
- definition: Asset2.fromFile(getBuildPath("graphql-schema", name, "schema.gql"))
2875
- });
2876
- const association = new aws6.appsync.SourceApiAssociation(group, "association", {
2877
- mergedApiId: ctx.shared.get(`graphql-${id}-id`),
2878
- sourceApiId: api.id
2879
- });
2880
- association.dependsOn(schema);
2845
+ const apiId = ctx.shared.get(`graphql-${id}-id`);
2881
2846
  for (const [typeName, fields] of Object.entries(props.resolvers ?? {})) {
2882
2847
  for (const [fieldName, props2] of Object.entries(fields ?? {})) {
2883
- const name2 = `${typeName}__${fieldName}`;
2884
- const resolverGroup = new Node6(group, "resolver", name2);
2848
+ const name = `${typeName}__${fieldName}`;
2849
+ const resolverGroup = new Node6(group, "resolver", name);
2885
2850
  const entryId = paramCase5(`${id}-${typeName}-${fieldName}`);
2886
2851
  const { lambda } = createLambdaFunction(resolverGroup, ctx, `graphql`, entryId, {
2887
2852
  ...props2.consumer,
@@ -2902,10 +2867,10 @@ var graphqlFeature = defineFeature({
2902
2867
  ]
2903
2868
  });
2904
2869
  const source = new aws6.appsync.DataSource(resolverGroup, "source", {
2905
- apiId: api.id,
2906
- type: "lambda",
2907
- name: name2,
2870
+ apiId,
2871
+ name,
2908
2872
  role: role.arn,
2873
+ type: "lambda",
2909
2874
  functionArn: lambda.arn
2910
2875
  });
2911
2876
  let code = Asset2.fromString(defaultResolver);
@@ -2915,19 +2880,18 @@ var graphqlFeature = defineFeature({
2915
2880
  code = Asset2.fromFile(getBuildPath("graphql-resolver", id, "resolver.js"));
2916
2881
  }
2917
2882
  const config2 = new aws6.appsync.FunctionConfiguration(resolverGroup, "config", {
2918
- apiId: api.id,
2919
- name: name2,
2883
+ apiId,
2884
+ name,
2920
2885
  code,
2921
2886
  dataSourceName: source.name
2922
2887
  });
2923
- const resolver = new aws6.appsync.Resolver(resolverGroup, "resolver", {
2924
- apiId: api.id,
2888
+ new aws6.appsync.Resolver(resolverGroup, "resolver", {
2889
+ apiId,
2925
2890
  typeName,
2926
2891
  fieldName,
2927
2892
  functions: [config2.id],
2928
2893
  code
2929
2894
  });
2930
- resolver.dependsOn(schema);
2931
2895
  }
2932
2896
  }
2933
2897
  }
@@ -3962,6 +3926,7 @@ var createApp = (props, filters = []) => {
3962
3926
  const app = new App(props.appConfig.name);
3963
3927
  const base = new Stack(app, "base");
3964
3928
  const shared = new SharedData();
3929
+ const configs = /* @__PURE__ */ new Set();
3965
3930
  const tests = [];
3966
3931
  const builders = [];
3967
3932
  const allFunctions = [];
@@ -4015,6 +3980,9 @@ var createApp = (props, filters = []) => {
4015
3980
  },
4016
3981
  registerBuild(type, name, builder) {
4017
3982
  builders.push({ type, name, builder });
3983
+ },
3984
+ registerConfig(name) {
3985
+ configs.add(name);
4018
3986
  }
4019
3987
  });
4020
3988
  }
@@ -4033,6 +4001,7 @@ var createApp = (props, filters = []) => {
4033
4001
  app,
4034
4002
  base,
4035
4003
  tests,
4004
+ configs,
4036
4005
  builders
4037
4006
  // deploymentLine,
4038
4007
  };
@@ -4123,7 +4092,7 @@ var get = (program2) => {
4123
4092
  note2(
4124
4093
  list({
4125
4094
  Name: chalk4.magenta(name),
4126
- Value: value ?? color.error("(empty)")
4095
+ Value: value ?? color.warning("(empty)")
4127
4096
  })
4128
4097
  );
4129
4098
  });
@@ -4160,8 +4129,11 @@ import { log as log7, spinner as spinner5 } from "@clack/prompts";
4160
4129
  import chalk5 from "chalk";
4161
4130
  var list2 = (program2) => {
4162
4131
  program2.command("list").description(`List all config value's`).action(async () => {
4163
- await layout("config list", async ({ appConfig }) => {
4132
+ await layout("config list", async ({ appConfig, stackConfigs }) => {
4133
+ const region = appConfig.region;
4164
4134
  const credentials = getCredentials(appConfig.profile);
4135
+ const accountId = await getAccountId(credentials, region);
4136
+ const { configs } = createApp({ appConfig, stackConfigs, accountId });
4165
4137
  const params = new SsmStore({
4166
4138
  credentials,
4167
4139
  appConfig
@@ -4170,11 +4142,25 @@ var list2 = (program2) => {
4170
4142
  spin.start("Loading config parameters");
4171
4143
  const values = await params.list();
4172
4144
  spin.stop("Done loading config values.");
4173
- if (Object.keys(values).length > 0) {
4145
+ const requiredValues = [...configs].map((key) => {
4146
+ if (typeof values[key] !== "undefined") {
4147
+ return [chalk5.magenta(key), values[key]];
4148
+ } else {
4149
+ return [chalk5.magenta(key), color.warning("(empty)")];
4150
+ }
4151
+ });
4152
+ const unsusedValues = Object.entries(values).map(([key, value]) => {
4153
+ if (!configs.has(key)) {
4154
+ return [chalk5.magenta(key), `${value} ${color.error("(unused)")}`];
4155
+ }
4156
+ return void 0;
4157
+ }).filter(Boolean);
4158
+ const allValues = [...requiredValues, ...unsusedValues];
4159
+ if (requiredValues.length > 0) {
4174
4160
  console.log(
4175
4161
  table({
4176
4162
  head: ["name", "value"],
4177
- body: Object.entries(values).map(([k, v]) => [chalk5.magenta(k), v])
4163
+ body: allValues
4178
4164
  })
4179
4165
  );
4180
4166
  } else {
@@ -4204,7 +4190,7 @@ import { confirm as confirm3 } from "@clack/prompts";
4204
4190
  import { WorkSpace, aws as aws18, local } from "@awsless/formation";
4205
4191
  import { minutes as minutes4 } from "@awsless/duration";
4206
4192
  import { dirname as dirname8, join as join9 } from "path";
4207
- import { mkdir as mkdir2, readFile as readFile6, writeFile as writeFile2 } from "fs/promises";
4193
+ import { mkdir as mkdir2, readFile as readFile6, rm, writeFile as writeFile2 } from "fs/promises";
4208
4194
  var createWorkSpace = (props) => {
4209
4195
  const lockProvider = new aws18.dynamodb.LockProvider({
4210
4196
  ...props,
@@ -4233,7 +4219,11 @@ var pullRemoteState = async (app, stateProvider) => {
4233
4219
  const file = join9(directories.state, `${app.urn}.json`);
4234
4220
  const state2 = await stateProvider.get(app.urn);
4235
4221
  await mkdir2(dirname8(file), { recursive: true });
4236
- await writeFile2(file, JSON.stringify(state2, void 0, 2));
4222
+ if (typeof state2 === "undefined") {
4223
+ await rm(file);
4224
+ } else {
4225
+ await writeFile2(file, JSON.stringify(state2, void 0, 2));
4226
+ }
4237
4227
  };
4238
4228
  var pushRemoteState = async (app, stateProvider) => {
4239
4229
  const file = join9(directories.state, `${app.urn}.json`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/awsless",
3
- "version": "0.0.190",
3
+ "version": "0.0.192",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -28,14 +28,14 @@
28
28
  }
29
29
  },
30
30
  "peerDependencies": {
31
- "@awsless/redis": "^0.0.12",
32
- "@awsless/s3": "^0.0.10",
33
31
  "@awsless/lambda": "^0.0.18",
32
+ "@awsless/redis": "^0.0.12",
34
33
  "@awsless/sns": "^0.0.7",
35
34
  "@awsless/sqs": "^0.0.7",
36
- "@awsless/ssm": "^0.0.7",
37
35
  "@awsless/validate": "^0.0.13",
38
- "@awsless/weak-cache": "^0.0.1"
36
+ "@awsless/s3": "^0.0.10",
37
+ "@awsless/weak-cache": "^0.0.1",
38
+ "@awsless/ssm": "^0.0.7"
39
39
  },
40
40
  "dependencies": {
41
41
  "@aws-appsync/utils": "^1.5.0",
@@ -97,10 +97,10 @@
97
97
  "zod": "^3.21.4",
98
98
  "zod-to-json-schema": "^3.22.3",
99
99
  "@awsless/duration": "^0.0.1",
100
+ "@awsless/graphql": "^0.0.9",
100
101
  "@awsless/formation": "^0.0.13",
101
102
  "@awsless/size": "^0.0.1",
102
103
  "@awsless/validate": "^0.0.13",
103
- "@awsless/graphql": "^0.0.9",
104
104
  "@awsless/code": "^0.0.10"
105
105
  },
106
106
  "scripts": {