@graphql-codegen/c-sharp-common 1.0.0 → 1.1.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
@@ -6,3 +6,4 @@ tslib_1.__exportStar(require("./scalars.js"), exports);
6
6
  tslib_1.__exportStar(require("./utils.js"), exports);
7
7
  tslib_1.__exportStar(require("./c-sharp-field-types.js"), exports);
8
8
  tslib_1.__exportStar(require("./keywords.js"), exports);
9
+ tslib_1.__exportStar(require("./member-naming.js"), exports);
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMemberNamingFunction = void 0;
4
+ const change_case_all_1 = require("change-case-all");
5
+ /**
6
+ * @description Get the member naming function based on the provided configuration.
7
+ * @param rawConfig Config to decide which concrete naming function to return. Fallback to camelCase if not provided.
8
+ * @returns
9
+ */
10
+ function getMemberNamingFunction(rawConfig) {
11
+ switch (rawConfig.memberNameConvention) {
12
+ case 'camelCase':
13
+ return (input) => (0, change_case_all_1.camelCase)(typeof input === 'string' ? input : input.value);
14
+ case 'pascalCase':
15
+ return (input) => (0, change_case_all_1.pascalCase)(typeof input === 'string' ? input : input.value);
16
+ default:
17
+ return (input) => (0, change_case_all_1.camelCase)(typeof input === 'string' ? input : input.value);
18
+ }
19
+ }
20
+ exports.getMemberNamingFunction = getMemberNamingFunction;
package/cjs/scalars.js CHANGED
@@ -2,12 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.csharpValueTypes = exports.C_SHARP_SCALARS = void 0;
4
4
  exports.C_SHARP_SCALARS = {
5
- ID: 'string',
6
- String: 'string',
7
- Boolean: 'bool',
8
- Int: 'int',
9
- Float: 'double',
10
- Date: 'DateTime',
5
+ ID: {
6
+ input: 'string',
7
+ output: 'string',
8
+ },
9
+ String: {
10
+ input: 'string',
11
+ output: 'string',
12
+ },
13
+ Boolean: {
14
+ input: 'bool',
15
+ output: 'bool',
16
+ },
17
+ Int: {
18
+ input: 'int',
19
+ output: 'int',
20
+ },
21
+ Float: {
22
+ input: 'double',
23
+ output: 'double',
24
+ },
25
+ Date: {
26
+ input: 'DateTime',
27
+ output: 'DateTime',
28
+ },
11
29
  };
12
30
  exports.csharpValueTypes = [
13
31
  'bool',
package/esm/index.js CHANGED
@@ -3,3 +3,4 @@ export * from './scalars.js';
3
3
  export * from './utils.js';
4
4
  export * from './c-sharp-field-types.js';
5
5
  export * from './keywords.js';
6
+ export * from './member-naming.js';
@@ -0,0 +1,16 @@
1
+ import { camelCase, pascalCase } from 'change-case-all';
2
+ /**
3
+ * @description Get the member naming function based on the provided configuration.
4
+ * @param rawConfig Config to decide which concrete naming function to return. Fallback to camelCase if not provided.
5
+ * @returns
6
+ */
7
+ export function getMemberNamingFunction(rawConfig) {
8
+ switch (rawConfig.memberNameConvention) {
9
+ case 'camelCase':
10
+ return (input) => camelCase(typeof input === 'string' ? input : input.value);
11
+ case 'pascalCase':
12
+ return (input) => pascalCase(typeof input === 'string' ? input : input.value);
13
+ default:
14
+ return (input) => camelCase(typeof input === 'string' ? input : input.value);
15
+ }
16
+ }
package/esm/scalars.js CHANGED
@@ -1,10 +1,28 @@
1
1
  export const C_SHARP_SCALARS = {
2
- ID: 'string',
3
- String: 'string',
4
- Boolean: 'bool',
5
- Int: 'int',
6
- Float: 'double',
7
- Date: 'DateTime',
2
+ ID: {
3
+ input: 'string',
4
+ output: 'string',
5
+ },
6
+ String: {
7
+ input: 'string',
8
+ output: 'string',
9
+ },
10
+ Boolean: {
11
+ input: 'bool',
12
+ output: 'bool',
13
+ },
14
+ Int: {
15
+ input: 'int',
16
+ output: 'int',
17
+ },
18
+ Float: {
19
+ input: 'double',
20
+ output: 'double',
21
+ },
22
+ Date: {
23
+ input: 'DateTime',
24
+ output: 'DateTime',
25
+ },
8
26
  };
9
27
  export const csharpValueTypes = [
10
28
  'bool',
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@graphql-codegen/c-sharp-common",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
7
7
  "graphql-tag": "2.12.6"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-codegen/plugin-helpers": "^3.0.0",
11
- "@graphql-codegen/visitor-plugin-common": "^2.12.1",
10
+ "@graphql-codegen/plugin-helpers": "^5.0.4",
11
+ "@graphql-codegen/visitor-plugin-common": "^5.3.1",
12
12
  "auto-bind": "~4.0.0",
13
13
  "change-case-all": "1.0.15",
14
14
  "tslib": "~2.6.0"
@@ -3,3 +3,4 @@ export * from './scalars.cjs';
3
3
  export * from './utils.cjs';
4
4
  export * from './c-sharp-field-types.cjs';
5
5
  export * from './keywords.cjs';
6
+ export * from './member-naming.cjs';
@@ -3,3 +3,4 @@ export * from './scalars.js';
3
3
  export * from './utils.js';
4
4
  export * from './c-sharp-field-types.js';
5
5
  export * from './keywords.js';
6
+ export * from './member-naming.js';
@@ -0,0 +1,19 @@
1
+ import { NameNode } from 'graphql';
2
+ /**
3
+ * @description Configuration for member naming conventions.
4
+ */
5
+ export type MemberNameConventionConfig = {
6
+ memberNameConvention?: 'camelCase' | 'pascalCase';
7
+ };
8
+ type MemberNamingFunctionInput = string | NameNode;
9
+ /**
10
+ * @description Type func signature of a function is responsible for transforming the name of a member (property, method) to a valid C# identifier.
11
+ */
12
+ export type MemberNamingFn = (nameOrNameNode: MemberNamingFunctionInput) => string;
13
+ /**
14
+ * @description Get the member naming function based on the provided configuration.
15
+ * @param rawConfig Config to decide which concrete naming function to return. Fallback to camelCase if not provided.
16
+ * @returns
17
+ */
18
+ export declare function getMemberNamingFunction(rawConfig: MemberNameConventionConfig): MemberNamingFn;
19
+ export {};
@@ -0,0 +1,19 @@
1
+ import { NameNode } from 'graphql';
2
+ /**
3
+ * @description Configuration for member naming conventions.
4
+ */
5
+ export type MemberNameConventionConfig = {
6
+ memberNameConvention?: 'camelCase' | 'pascalCase';
7
+ };
8
+ type MemberNamingFunctionInput = string | NameNode;
9
+ /**
10
+ * @description Type func signature of a function is responsible for transforming the name of a member (property, method) to a valid C# identifier.
11
+ */
12
+ export type MemberNamingFn = (nameOrNameNode: MemberNamingFunctionInput) => string;
13
+ /**
14
+ * @description Get the member naming function based on the provided configuration.
15
+ * @param rawConfig Config to decide which concrete naming function to return. Fallback to camelCase if not provided.
16
+ * @returns
17
+ */
18
+ export declare function getMemberNamingFunction(rawConfig: MemberNameConventionConfig): MemberNamingFn;
19
+ export {};
@@ -1,9 +1,3 @@
1
- export declare const C_SHARP_SCALARS: {
2
- ID: string;
3
- String: string;
4
- Boolean: string;
5
- Int: string;
6
- Float: string;
7
- Date: string;
8
- };
1
+ import { NormalizedScalarsMap } from '@graphql-codegen/visitor-plugin-common';
2
+ export declare const C_SHARP_SCALARS: NormalizedScalarsMap;
9
3
  export declare const csharpValueTypes: string[];
@@ -1,9 +1,3 @@
1
- export declare const C_SHARP_SCALARS: {
2
- ID: string;
3
- String: string;
4
- Boolean: string;
5
- Int: string;
6
- Float: string;
7
- Date: string;
8
- };
1
+ import { NormalizedScalarsMap } from '@graphql-codegen/visitor-plugin-common';
2
+ export declare const C_SHARP_SCALARS: NormalizedScalarsMap;
9
3
  export declare const csharpValueTypes: string[];