@salesforce/plugin-custom-metadata 1.0.11 → 2.0.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +23 -7
  2. package/LICENSE.txt +2 -2
  3. package/README.md +153 -149
  4. package/lib/commands/force/cmdt/create.d.ts +12 -6
  5. package/lib/commands/force/cmdt/create.js +80 -82
  6. package/lib/commands/force/cmdt/create.js.map +1 -1
  7. package/lib/commands/force/cmdt/field/create.d.ts +10 -5
  8. package/lib/commands/force/cmdt/field/create.js +98 -90
  9. package/lib/commands/force/cmdt/field/create.js.map +1 -1
  10. package/lib/commands/force/cmdt/generate.d.ts +12 -8
  11. package/lib/commands/force/cmdt/generate.js +199 -257
  12. package/lib/commands/force/cmdt/generate.js.map +1 -1
  13. package/lib/commands/force/cmdt/record/create.d.ts +20 -9
  14. package/lib/commands/force/cmdt/record/create.js +123 -125
  15. package/lib/commands/force/cmdt/record/create.js.map +1 -1
  16. package/lib/commands/force/cmdt/record/insert.d.ts +7 -7
  17. package/lib/commands/force/cmdt/record/insert.js +97 -109
  18. package/lib/commands/force/cmdt/record/insert.js.map +1 -1
  19. package/lib/index.js +3 -3
  20. package/lib/lib/helpers/createUtil.d.ts +10 -6
  21. package/lib/lib/helpers/createUtil.js +50 -98
  22. package/lib/lib/helpers/createUtil.js.map +1 -1
  23. package/lib/lib/helpers/fileWriter.d.ts +13 -11
  24. package/lib/lib/helpers/fileWriter.js +19 -27
  25. package/lib/lib/helpers/fileWriter.js.map +1 -1
  26. package/lib/lib/helpers/metadataUtil.d.ts +25 -51
  27. package/lib/lib/helpers/metadataUtil.js +58 -127
  28. package/lib/lib/helpers/metadataUtil.js.map +1 -1
  29. package/lib/lib/helpers/validationUtil.d.ts +25 -26
  30. package/lib/lib/helpers/validationUtil.js +69 -43
  31. package/lib/lib/helpers/validationUtil.js.map +1 -1
  32. package/lib/lib/interfaces/createConfig.d.ts +3 -2
  33. package/lib/lib/interfaces/createConfig.js +3 -3
  34. package/lib/lib/templates/templates.d.ts +10 -99
  35. package/lib/lib/templates/templates.js +52 -40
  36. package/lib/lib/templates/templates.js.map +1 -1
  37. package/messages/createField.json +22 -31
  38. package/messages/generate.json +38 -51
  39. package/messages/template.json +2 -2
  40. package/messages/validation.json +5 -0
  41. package/oclif.manifest.json +1 -1
  42. package/package.json +57 -46
  43. package/lib/lib/interfaces/customField.d.ts +0 -7
  44. package/lib/lib/interfaces/customField.js +0 -9
  45. package/lib/lib/interfaces/customField.js.map +0 -1
  46. package/lib/lib/interfaces/errorMessage.d.ts +0 -4
  47. package/lib/lib/interfaces/errorMessage.js +0 -9
  48. package/lib/lib/interfaces/errorMessage.js.map +0 -1
  49. package/lib/lib/interfaces/record.d.ts +0 -3
  50. package/lib/lib/interfaces/record.js +0 -9
  51. package/lib/lib/interfaces/record.js.map +0 -1
  52. package/lib/lib/interfaces/saveResults.d.ts +0 -5
  53. package/lib/lib/interfaces/saveResults.js +0 -9
  54. package/lib/lib/interfaces/saveResults.js.map +0 -1
@@ -1,134 +1,65 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2018-2020, salesforce.com, inc.
3
+ * Copyright (c) 2020, salesforce.com, inc.
4
4
  * All rights reserved.
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MetadataUtil = void 0;
10
- const ts_types_1 = require("@salesforce/ts-types");
11
- class MetadataUtil {
12
- constructor(connection) {
13
- this.conn = connection;
14
- }
15
- /**
16
- * Returns a describe object from the API name you specify
17
- *
18
- * @param objName API name of the object
19
- * @returns Promise - JSON representation of the describe object
20
- */
21
- async describeObj(objName) {
22
- const result = await this.conn.metadata.read('CustomObject', objName, (err, meta) => {
23
- if (err) {
24
- const errorResponse = { errorCode: '', errorMessage: '' };
25
- errorResponse.errorCode = err.name;
26
- errorResponse.errorMessage = err.message;
27
- return errorResponse;
28
- }
29
- return meta;
30
- });
31
- return ts_types_1.toAnyJson(result);
32
- }
33
- /**
34
- * Returns an array of object records from a SOQL query
35
- *
36
- * @param soqlStr String representation of the SOQL query
37
- * @returns Promise - Array of records in JSON format
38
- */
39
- async queryObject(soqlStr) {
40
- const result = await this.conn.query(soqlStr, {}, (err, meta) => {
41
- if (err) {
42
- const errorResponse = { errorCode: '', errorMessage: '' };
43
- errorResponse.errorCode = err.name;
44
- errorResponse.errorMessage = err.message;
45
- return errorResponse;
46
- }
47
- return meta;
48
- });
49
- return ts_types_1.toAnyJson(result);
50
- }
51
- /**
52
- * Returns an array of object records
53
- *
54
- * @param describeResult object describe result
55
- * @returns Promise - Promise - Array of records in JSON format
56
- */
57
- async queryRecords(describeResult) {
58
- const query = await this._getSoqlQuery(describeResult['fields'], describeResult['fullName']);
59
- const queryResult = await this.queryObject(query);
60
- return ts_types_1.toAnyJson(queryResult);
61
- }
62
- /**
63
- * Returns describe object for the field API name from the Object API name you specify
64
- *
65
- * @param objDescribe describe object JSON
66
- * @param fieldName API name of the field to query
67
- * @returns Promise - Promise - record in JSON format
68
- */
69
- describeField(objDescribe, fieldName) {
70
- const fieldsDescribe = objDescribe['fields'];
71
- let fieldsDescribeResult;
72
- fieldsDescribe.map(field => {
73
- if (field.fullName === fieldName) {
74
- fieldsDescribeResult = field;
75
- }
76
- });
77
- return fieldsDescribeResult;
78
- }
79
- /**
80
- * Returns describe object for all fields from the object API name you specify
81
- *
82
- * @param objDescribe object describe JSON
83
- * @returns Promise - Promise - record in JSON format
84
- */
85
- describeObjFields(objDescribe) {
86
- const fieldsDescribe = objDescribe['fields'];
87
- return fieldsDescribe;
88
- }
89
- /**
90
- * Returns true if the object name you specify is a list type custom setting
91
- *
92
- * @param objName API name of the object to query
93
- * @returns boolean
94
- */
95
- validCustomSettingType(objDescribe) {
96
- if (objDescribe['customSettingsType'] === 'List' && objDescribe['visibility'] === 'Public') {
97
- return true;
9
+ exports.cleanQueryResponse = exports.describeObjFields = exports.validCustomSettingType = exports.describeField = void 0;
10
+ /**
11
+ * Returns describe object for the field API name from the Object API name you specify
12
+ *
13
+ * @param objDescribe describe object JSON
14
+ * @param fieldName API name of the field to query
15
+ * @returns Promise - Promise - record in JSON format
16
+ */
17
+ const describeField = (objDescribe, fieldName) => {
18
+ return (0, exports.describeObjFields)(objDescribe).find((field) => field.fullName === fieldName);
19
+ };
20
+ exports.describeField = describeField;
21
+ /**
22
+ * Returns true if the object name you specify is a list type custom setting
23
+ *
24
+ * @param objName object describe JSON
25
+ * @returns boolean
26
+ */
27
+ const validCustomSettingType = (objDescribe) => objDescribe.customSettingsType === 'List' && objDescribe.visibility === 'Public';
28
+ exports.validCustomSettingType = validCustomSettingType;
29
+ /**
30
+ * Returns describe object for all fields from the object API name you specify
31
+ *
32
+ * @param objDescribe object describe JSON
33
+ * @returns Promise - Promise - record in JSON format
34
+ */
35
+ const describeObjFields = (objDescribe) => {
36
+ return objDescribe.fields;
37
+ };
38
+ exports.describeObjFields = describeObjFields;
39
+ const cleanQueryResponse = (sObjectRecord, objectDescribe) => {
40
+ return Object.fromEntries(Object.entries(sObjectRecord)
41
+ .filter(([fieldName]) => fieldName !== 'attributes' && fieldName !== 'Name')
42
+ .flatMap(([fieldName, value]) => {
43
+ const fieldDescribe = (0, exports.describeField)(objectDescribe, fieldName);
44
+ // everything but location returns as is
45
+ if (fieldDescribe.type !== 'Location') {
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
47
+ return [[fieldName, value]];
48
+ }
49
+ const fieldValue = JSON.stringify(value);
50
+ if (fieldValue.includes('latitude') || fieldValue.includes('longitude')) {
51
+ return [
52
+ [`Lat_${fieldName}`, fieldValue.slice(fieldValue.indexOf(':') + 1, fieldValue.indexOf(','))],
53
+ [`Long_${fieldName}`, fieldValue.slice(fieldValue.lastIndexOf(':') + 1, fieldValue.indexOf('}'))],
54
+ ];
55
+ }
56
+ else {
57
+ return [
58
+ [`Lat_${fieldName}`, ''],
59
+ [`Long_${fieldName}`, ''],
60
+ ];
98
61
  }
99
- return false;
100
- }
101
- cleanQueryResponse(sObjecRecord, objectDescribe) {
102
- const record = {};
103
- Object.keys(sObjecRecord).forEach(fieldName => {
104
- if (fieldName !== 'attributes' && fieldName !== 'Name') {
105
- const fieldDescribe = this.describeField(objectDescribe, fieldName);
106
- const fieldType = fieldDescribe['type'];
107
- const fieldValue = JSON.stringify(sObjecRecord[fieldName]);
108
- if (fieldType === 'Location') {
109
- if (fieldValue.includes('latitude') || fieldValue.includes('longitude')) {
110
- record['Lat_' + fieldName] = fieldValue.slice(fieldValue.indexOf(':') + 1, fieldValue.indexOf(','));
111
- record['Long_' + fieldName] = fieldValue.slice(fieldValue.lastIndexOf(':') + 1, fieldValue.indexOf('}'));
112
- }
113
- else {
114
- record['Lat_' + fieldName] = '';
115
- record['Long_' + fieldName] = '';
116
- }
117
- }
118
- else {
119
- record[fieldName] = sObjecRecord[fieldName];
120
- }
121
- }
122
- });
123
- return record;
124
- }
125
- _getSoqlQuery(arr, objName) {
126
- const fieldNames = arr.map(field => {
127
- return field.fullName;
128
- }).join(',');
129
- // Added Name hardcoded as Name field is not retreived as part of object describe.
130
- return `SELECT Name, ${fieldNames} FROM ${objName}`;
131
- }
132
- }
133
- exports.MetadataUtil = MetadataUtil;
62
+ }));
63
+ };
64
+ exports.cleanQueryResponse = cleanQueryResponse;
134
65
  //# sourceMappingURL=metadataUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadataUtil.js","sourceRoot":"","sources":["../../../src/lib/helpers/metadataUtil.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,mDAA0D;AAG1D,MAAa,YAAY;IAGvB,YAAY,UAA2B;QACrC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;IAC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,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;YACvE,OAAO;gBACL,CAAC,OAAO,SAAS,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC5F,CAAC,QAAQ,SAAS,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;aAClG,CAAC;SACH;aAAM;YACL,OAAO;gBACL,CAAC,OAAO,SAAS,EAAE,EAAE,EAAE,CAAC;gBACxB,CAAC,QAAQ,SAAS,EAAE,EAAE,EAAE,CAAC;aAC1B,CAAC;SACH;IACH,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,kBAAkB,sBAyB7B"}
@@ -1,26 +1,25 @@
1
- export declare class ValidationUtil {
2
- /**
3
- * Returns true if the fieldname is a valid api name
4
- *
5
- * @param fieldName API name of the object
6
- */
7
- validateAPIName(fieldName: any): boolean;
8
- /**
9
- * Returns true if the fieldname is a valid metadata object name
10
- *
11
- * @param fieldName API name of the field
12
- */
13
- validateMetadataTypeName(typeName: any): boolean;
14
- /**
15
- * Returns true if the fieldname is a valid metadata record name
16
- *
17
- * @param fieldName record name of a metadata record
18
- */
19
- validateMetadataRecordName(typeName: any): boolean;
20
- /**
21
- * Returns true if name is below 40 characters
22
- *
23
- * @param name label name or plural label
24
- */
25
- validateLessThanForty(name: any): boolean;
26
- }
1
+ /**
2
+ * Returns true if the name is a valid api name for an sobject/field
3
+ *
4
+ * @param name API name of the object
5
+ */
6
+ export declare const validateAPIName: (name: string, message?: string) => string;
7
+ /**
8
+ * Returns true if the fieldname is a valid metadata object name
9
+ *
10
+ * @param fieldName API name of the field
11
+ */
12
+ export declare const validateMetadataTypeName: (typeName: string) => string;
13
+ export declare const isValidMetadataRecordName: (recordName: string) => boolean;
14
+ /**
15
+ * Returns true if the fieldname is a valid metadata record name
16
+ *
17
+ * @param fieldName record name of a metadata record
18
+ */
19
+ export declare const validateMetadataRecordName: (typeName: string) => string;
20
+ /**
21
+ * Returns true if name is below 40 characters
22
+ *
23
+ * @param name label name or plural label
24
+ */
25
+ export declare const validateLessThanForty: (name: string, message: string) => string;
@@ -1,52 +1,78 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateLessThanForty = exports.validateMetadataRecordName = exports.isValidMetadataRecordName = exports.validateMetadataTypeName = exports.validateAPIName = void 0;
2
4
  /*
3
- * Copyright (c) 2018-2020, salesforce.com, inc.
5
+ * Copyright (c) 2020, salesforce.com, inc.
4
6
  * All rights reserved.
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
9
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ValidationUtil = void 0;
10
- class ValidationUtil {
11
- /**
12
- * Returns true if the fieldname is a valid api name
13
- *
14
- * @param fieldName API name of the object
15
- */
16
- validateAPIName(fieldName) {
17
- // trimming the __c from the field during character count since it does not count towards the limit
18
- // Regex makes sure that the field name is alpha numeric, doesn't end in an underscore
19
- // and optionally if it ends in __c
20
- return fieldName.replace('__c', '').replace('__C', '').length <= 40 && /^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*(__[cC])?$/.test(fieldName);
10
+ const core_1 = require("@salesforce/core");
11
+ core_1.Messages.importMessagesDirectory(__dirname);
12
+ const messages = core_1.Messages.load('@salesforce/plugin-custom-metadata', 'validation', [
13
+ 'sobjectnameFlagError',
14
+ 'invalidCMDTApiName',
15
+ 'notAValidRecordNameError',
16
+ ]);
17
+ /**
18
+ * Returns true if the name is a valid api name for an sobject/field
19
+ *
20
+ * @param name API name of the object
21
+ */
22
+ const validateAPIName = (name, message) => {
23
+ // trimming the __c from the field during character count since it does not count towards the limit
24
+ // Regex makes sure that the field name is alpha numeric, doesn't end in an underscore
25
+ // and optionally if it ends in __c
26
+ const cleanedValue = name.replace('__c', '').replace('__C', '');
27
+ if (cleanedValue.length > 40 || !/^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*(__[cC])?$/.test(cleanedValue)) {
28
+ throw new core_1.SfError(message !== null && message !== void 0 ? message : messages.getMessage('sobjectnameFlagError', [name]));
21
29
  }
22
- /**
23
- * Returns true if the fieldname is a valid metadata object name
24
- *
25
- * @param fieldName API name of the field
26
- */
27
- validateMetadataTypeName(typeName) {
28
- // trimming the __mdt from the field during character count since it does not count towards the limit
29
- // Regex makes sure that the field name is alpha numeric, doesn't end in an underscore
30
- // and optionally if it ends in __mdt
31
- return typeName.replace('__mdt', '').length <= 40 && /^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*(__mdt)?$/.test(typeName);
30
+ return name;
31
+ };
32
+ exports.validateAPIName = validateAPIName;
33
+ /**
34
+ * Returns true if the fieldname is a valid metadata object name
35
+ *
36
+ * @param fieldName API name of the field
37
+ */
38
+ const validateMetadataTypeName = (typeName) => {
39
+ // trimming the __mdt from the field during character count since it does not count towards the limit
40
+ // Regex makes sure that the field name is alpha numeric, doesn't end in an underscore
41
+ // and optionally if it ends in __mdt
42
+ const trimmedValue = typeName.replace(/__mdt$/gi, '');
43
+ if (trimmedValue.length > 40 || !/^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*(__[mdtT])?$/.test(trimmedValue)) {
44
+ throw new core_1.SfError(messages.getMessage('invalidCMDTApiName', [typeName]));
32
45
  }
33
- /**
34
- * Returns true if the fieldname is a valid metadata record name
35
- *
36
- * @param fieldName record name of a metadata record
37
- */
38
- validateMetadataRecordName(typeName) {
39
- // Regex makes sure that the field name is alpha numeric, doesn't end in an underscore
40
- return typeName.length <= 40 && /^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$/.test(typeName);
46
+ return trimmedValue;
47
+ };
48
+ exports.validateMetadataTypeName = validateMetadataTypeName;
49
+ const isValidMetadataRecordName = (recordName) => {
50
+ return recordName.length <= 40 && /^[a-zA-Z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$/.test(recordName);
51
+ };
52
+ exports.isValidMetadataRecordName = isValidMetadataRecordName;
53
+ /**
54
+ * Returns true if the fieldname is a valid metadata record name
55
+ *
56
+ * @param fieldName record name of a metadata record
57
+ */
58
+ const validateMetadataRecordName = (typeName) => {
59
+ // Regex makes sure that the field name is alpha numeric, doesn't end in an underscore
60
+ if (!(0, exports.isValidMetadataRecordName)(typeName)) {
61
+ throw new core_1.SfError(messages.getMessage('notAValidRecordNameError', [typeName]));
41
62
  }
42
- /**
43
- * Returns true if name is below 40 characters
44
- *
45
- * @param name label name or plural label
46
- */
47
- validateLessThanForty(name) {
48
- return name.length <= 40;
63
+ return typeName;
64
+ };
65
+ exports.validateMetadataRecordName = validateMetadataRecordName;
66
+ /**
67
+ * Returns true if name is below 40 characters
68
+ *
69
+ * @param name label name or plural label
70
+ */
71
+ const validateLessThanForty = (name, message) => {
72
+ if (name.length > 40) {
73
+ throw new core_1.SfError(message);
49
74
  }
50
- }
51
- exports.ValidationUtil = ValidationUtil;
75
+ return name;
76
+ };
77
+ exports.validateLessThanForty = validateLessThanForty;
52
78
  //# sourceMappingURL=validationUtil.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validationUtil.js","sourceRoot":"","sources":["../../../src/lib/helpers/validationUtil.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,MAAa,cAAc;IAEvB;;;;OAIG;IACI,eAAe,CAAC,SAAS;QAC5B,mGAAmG;QACnG,sFAAsF;QACtF,mCAAmC;QACnC,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,E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AAClB,CAAC,CAAC;AANW,QAAA,0BAA0B,8BAMrC;AAEF;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CAAC,IAAY,EAAE,OAAe,EAAU,EAAE;IAC7E,IAAI,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE;QACpB,MAAM,IAAI,cAAO,CAAC,OAAO,CAAC,CAAC;KAC5B;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AALW,QAAA,qBAAqB,yBAKhC"}
@@ -1,4 +1,5 @@
1
- import { CustomField } from './customField';
1
+ import { Record } from 'jsforce';
2
+ import { CustomField } from 'jsforce/api/metadata';
2
3
  export interface CreateConfig {
3
4
  typename: string;
4
5
  recordname: string;
@@ -6,7 +7,7 @@ export interface CreateConfig {
6
7
  inputdir: string;
7
8
  outputdir: string;
8
9
  protected?: boolean;
9
- varargs?: object;
10
+ varargs?: Record;
10
11
  fileData?: CustomField[];
11
12
  ignorefields?: boolean;
12
13
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2018-2020, salesforce.com, inc.
3
+ * Copyright (c) 2020, salesforce.com, inc.
4
4
  * All rights reserved.
5
- * SPDX-License-Identifier: BSD-3-Clause
6
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  //# sourceMappingURL=createConfig.js.map
@@ -1,112 +1,24 @@
1
+ import { CustomField } from 'jsforce/api/metadata';
1
2
  export declare class Templates {
2
3
  /**
3
4
  * Using the given data and visibility, creates the body of a type metadata file
5
+ *
4
6
  * @param data
5
7
  * @param visibility
6
8
  */
7
- createObjectXML(data: any, visibility: any): string;
9
+ createObjectXML({ label, pluralLabel }: {
10
+ label: string;
11
+ pluralLabel: string;
12
+ }, visibility: string): string;
8
13
  /**
9
14
  * Using the given data and defaultToString, creates the body for a field file.
15
+ *
10
16
  * @param data Record details
11
17
  * @param defaultToString If the defaultToString set type to Text for unsupported field types
12
18
  */
13
- createFieldXML(data: any, defaultToString: boolean): string;
14
- createDefaultTypeStructure(fullName: string, type: string, label: string, picklistValues: string[], decimalplaces?: number): {
15
- fullName: string;
16
- defaultValue: string;
17
- type: "Checkbox";
18
- label: string;
19
- unique?: undefined;
20
- precision?: undefined;
21
- scale?: undefined;
22
- valueSet?: undefined;
23
- length?: undefined;
24
- visibleLines?: undefined;
25
- } | {
26
- fullName: string;
27
- type: "Email";
28
- label: string;
29
- unique: string;
30
- defaultValue?: undefined;
31
- precision?: undefined;
32
- scale?: undefined;
33
- valueSet?: undefined;
34
- length?: undefined;
35
- visibleLines?: undefined;
36
- } | {
37
- fullName: string;
38
- type: "Number";
39
- label: string;
40
- precision: number;
41
- scale: number;
42
- unique: string;
43
- defaultValue?: undefined;
44
- valueSet?: undefined;
45
- length?: undefined;
46
- visibleLines?: undefined;
47
- } | {
48
- fullName: string;
49
- type: "Percent";
50
- label: string;
51
- precision: number;
52
- scale: number;
53
- defaultValue?: undefined;
54
- unique?: undefined;
55
- valueSet?: undefined;
56
- length?: undefined;
57
- visibleLines?: undefined;
58
- } | {
59
- fullName: string;
60
- type: "Picklist";
61
- label: string;
62
- valueSet: {
63
- restricted: string;
64
- valueSetDefinition: {
65
- sorted: string;
66
- value: any[];
67
- };
68
- };
69
- defaultValue?: undefined;
70
- unique?: undefined;
71
- precision?: undefined;
72
- scale?: undefined;
73
- length?: undefined;
74
- visibleLines?: undefined;
75
- } | {
76
- fullName: string;
77
- type: "Text";
78
- label: string;
79
- unique: string;
80
- length: string;
81
- defaultValue?: undefined;
82
- precision?: undefined;
83
- scale?: undefined;
84
- valueSet?: undefined;
85
- visibleLines?: undefined;
86
- } | {
87
- fullName: string;
88
- type: "LongTextArea";
89
- label: string;
90
- length: string;
91
- visibleLines: number;
92
- defaultValue?: undefined;
93
- unique?: undefined;
94
- precision?: undefined;
95
- scale?: undefined;
96
- valueSet?: undefined;
97
- } | {
98
- fullName: string;
99
- type: string;
100
- label: string;
101
- defaultValue?: undefined;
102
- unique?: undefined;
103
- precision?: undefined;
104
- scale?: undefined;
105
- valueSet?: undefined;
106
- length?: undefined;
107
- visibleLines?: undefined;
108
- };
109
- canConvert(type: any): boolean;
19
+ createFieldXML(data: CustomField, defaultToString: boolean): string;
20
+ createDefaultTypeStructure(fullName: string, type: string, label: string, picklistValues: string[], decimalplaces?: number): CustomField;
21
+ canConvert(type: string): boolean;
110
22
  private getType;
111
23
  private getConvertType;
112
24
  private getFullName;
@@ -122,5 +34,4 @@ export declare class Templates {
122
34
  private getVisibleLines;
123
35
  private getDefaultValue;
124
36
  private getValueSet;
125
- private createPicklistValues;
126
37
  }