@graphql-codegen/typescript-enum-array 2.2.1-alpha-20220805095358-8b7e687d1 → 2.3.0

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/cjs/index.js CHANGED
@@ -12,7 +12,7 @@ function getEnumTypeMap(schema) {
12
12
  }
13
13
  return result;
14
14
  }
15
- function buildArrayDefinition(e) {
15
+ function buildArrayDefinition(e, constArrays) {
16
16
  const upperName = e.name
17
17
  .replace(/[A-Z]/g, letter => `_${letter}`)
18
18
  .slice(1)
@@ -21,7 +21,12 @@ function buildArrayDefinition(e) {
21
21
  .getValues()
22
22
  .map(v => `'${v.value}'`)
23
23
  .join(', ');
24
- return `export const ${upperName}: ${e.name}[] = [${values}];`;
24
+ if (constArrays) {
25
+ return `export const ${upperName} = [${values}] as const;`;
26
+ }
27
+ else {
28
+ return `export const ${upperName}: ${e.name}[] = [${values}];`;
29
+ }
25
30
  }
26
31
  function buildImportStatement(enums, importFrom) {
27
32
  const names = Object.values(enums).map(e => e.name);
@@ -29,7 +34,7 @@ function buildImportStatement(enums, importFrom) {
29
34
  }
30
35
  const plugin = (schema, _documents, config) => {
31
36
  const enums = getEnumTypeMap(schema);
32
- const content = enums.map(buildArrayDefinition).join('\n');
37
+ const content = enums.map(e => { var _a; return buildArrayDefinition(e, (_a = config.constArrays) !== null && _a !== void 0 ? _a : false); }).join('\n');
33
38
  const result = { content };
34
39
  if (config.importFrom) {
35
40
  result['prepend'] = buildImportStatement(enums, config.importFrom);
package/esm/index.js CHANGED
@@ -9,7 +9,7 @@ function getEnumTypeMap(schema) {
9
9
  }
10
10
  return result;
11
11
  }
12
- function buildArrayDefinition(e) {
12
+ function buildArrayDefinition(e, constArrays) {
13
13
  const upperName = e.name
14
14
  .replace(/[A-Z]/g, letter => `_${letter}`)
15
15
  .slice(1)
@@ -18,7 +18,12 @@ function buildArrayDefinition(e) {
18
18
  .getValues()
19
19
  .map(v => `'${v.value}'`)
20
20
  .join(', ');
21
- return `export const ${upperName}: ${e.name}[] = [${values}];`;
21
+ if (constArrays) {
22
+ return `export const ${upperName} = [${values}] as const;`;
23
+ }
24
+ else {
25
+ return `export const ${upperName}: ${e.name}[] = [${values}];`;
26
+ }
22
27
  }
23
28
  function buildImportStatement(enums, importFrom) {
24
29
  const names = Object.values(enums).map(e => e.name);
@@ -26,7 +31,7 @@ function buildImportStatement(enums, importFrom) {
26
31
  }
27
32
  export const plugin = (schema, _documents, config) => {
28
33
  const enums = getEnumTypeMap(schema);
29
- const content = enums.map(buildArrayDefinition).join('\n');
34
+ const content = enums.map(e => { var _a; return buildArrayDefinition(e, (_a = config.constArrays) !== null && _a !== void 0 ? _a : false); }).join('\n');
30
35
  const result = { content };
31
36
  if (config.importFrom) {
32
37
  result['prepend'] = buildImportStatement(enums, config.importFrom);
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-enum-array",
3
- "version": "2.2.1-alpha-20220805095358-8b7e687d1",
3
+ "version": "2.3.0",
4
4
  "description": "GraphQL Code Generator plugin for adding const array",
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
7
7
  },
8
8
  "dependencies": {
9
- "@graphql-codegen/plugin-helpers": "2.6.2-alpha-20220805095358-8b7e687d1",
9
+ "@graphql-codegen/plugin-helpers": "^3.0.0",
10
10
  "tslib": "~2.4.0"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/dotansimha/graphql-code-generator.git",
14
+ "url": "https://github.com/dotansimha/graphql-code-generator-community.git",
15
15
  "directory": "packages/plugins/typescript/enum-array"
16
16
  },
17
17
  "license": "MIT",
@@ -4,4 +4,8 @@ export interface EnumArrayPluginConfig {
4
4
  * if not given, omit import statement.
5
5
  */
6
6
  importFrom?: string;
7
+ /**
8
+ * @description generate the arrays as const. Defaults to false
9
+ */
10
+ constArrays?: boolean;
7
11
  }
@@ -4,4 +4,8 @@ export interface EnumArrayPluginConfig {
4
4
  * if not given, omit import statement.
5
5
  */
6
6
  importFrom?: string;
7
+ /**
8
+ * @description generate the arrays as const. Defaults to false
9
+ */
10
+ constArrays?: boolean;
7
11
  }