autoforce 0.1.1
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/LICENSE +21 -0
- package/README.md +30 -0
- package/lib/auto.d.ts +3 -0
- package/lib/auto.js +103 -0
- package/lib/helpers/class.d.ts +12 -0
- package/lib/helpers/class.js +233 -0
- package/lib/helpers/color.d.ts +3 -0
- package/lib/helpers/color.js +47 -0
- package/lib/helpers/connect.d.ts +16 -0
- package/lib/helpers/connect.js +261 -0
- package/lib/helpers/context.d.ts +80 -0
- package/lib/helpers/context.js +488 -0
- package/lib/helpers/github-graphql.d.ts +76 -0
- package/lib/helpers/github-graphql.js +363 -0
- package/lib/helpers/gitlab-graphql.d.ts +19 -0
- package/lib/helpers/gitlab-graphql.js +78 -0
- package/lib/helpers/lwc.d.ts +3 -0
- package/lib/helpers/lwc.js +69 -0
- package/lib/helpers/merge.d.ts +1 -0
- package/lib/helpers/merge.js +81 -0
- package/lib/helpers/metadata.d.ts +30 -0
- package/lib/helpers/metadata.js +119 -0
- package/lib/helpers/object.d.ts +3 -0
- package/lib/helpers/object.js +133 -0
- package/lib/helpers/openai.d.ts +1 -0
- package/lib/helpers/openai.js +53 -0
- package/lib/helpers/taskFunctions.d.ts +14 -0
- package/lib/helpers/taskFunctions.js +479 -0
- package/lib/helpers/tasks.d.ts +12 -0
- package/lib/helpers/tasks.js +241 -0
- package/lib/helpers/template.d.ts +14 -0
- package/lib/helpers/template.js +86 -0
- package/lib/helpers/util.d.ts +31 -0
- package/lib/helpers/util.js +85 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/package.json +55 -0
@@ -0,0 +1,119 @@
|
|
1
|
+
import objectHelper from "./object.js";
|
2
|
+
import classHelper from "./class.js";
|
3
|
+
import lwcHelper from "./lwc.js";
|
4
|
+
// Logica especificas de cada componente
|
5
|
+
const helpers = {
|
6
|
+
objects: objectHelper,
|
7
|
+
classes: classHelper,
|
8
|
+
lwc: lwcHelper
|
9
|
+
};
|
10
|
+
export default helpers;
|
11
|
+
/*
|
12
|
+
import context from "./context.js";
|
13
|
+
import { DOCS_FOLDER } from "./util.js";
|
14
|
+
import type { DocumentationModule, IProcessInfo, IMetadataNode, IMetadataComponentNode } from "../types/auto.js";
|
15
|
+
function getMetadataFromContext(components: string[]) {
|
16
|
+
return getMetadataArray(context.getProcessMetadata(), components);
|
17
|
+
}
|
18
|
+
|
19
|
+
function mergeArray(baseArray: string[], newArray: string[]) {
|
20
|
+
if (!Array.isArray(newArray) && !Array.isArray(baseArray)) {
|
21
|
+
return [];
|
22
|
+
}
|
23
|
+
// Si el new esta vacio
|
24
|
+
if (!Array.isArray(newArray) || newArray.length == 0) {
|
25
|
+
return baseArray;
|
26
|
+
}
|
27
|
+
// Si el base esta vacio
|
28
|
+
if (!Array.isArray(baseArray) || baseArray.length == 0) {
|
29
|
+
return newArray;
|
30
|
+
}
|
31
|
+
// Sino filtra y concatena
|
32
|
+
const notIncludeInBaseArray = (a:string) => baseArray.indexOf(a) === -1;
|
33
|
+
return baseArray.concat(newArray.filter(notIncludeInBaseArray));
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
function getMetadataArray(metadata: IProcessInfo[], props: string[]) {
|
38
|
+
const mergeObject = (root: IMetadataNode, childs: IMetadataNode[]) => {
|
39
|
+
for (const item of childs) {
|
40
|
+
for (const key of props as (keyof IMetadataComponentNode)[]) {
|
41
|
+
root[key] = mergeArray(root[key], item[key]);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return root;
|
45
|
+
};
|
46
|
+
const getItemsFromTree = (node: IMetadataNode, parentPath = '') => {
|
47
|
+
const items: IMetadataNode[] = [];
|
48
|
+
if (Array.isArray(node)) {
|
49
|
+
for (const item of node) {
|
50
|
+
items.push(...getItemsFromTree(item, parentPath));
|
51
|
+
}
|
52
|
+
} else {
|
53
|
+
const folder = node.hasChilds ? node.folder : node.name;
|
54
|
+
node.path = parentPath ? `${parentPath}/${folder}` : folder;
|
55
|
+
if (node.hasChilds) {
|
56
|
+
// Borra el childs, pero le deja hasChilds en true para saber si es una hoja del arbol
|
57
|
+
const { childs, ...itemToAdd } = node;
|
58
|
+
itemToAdd.hasChilds = true;
|
59
|
+
const childItems = getItemsFromTree(childs, node.path);
|
60
|
+
items.push(mergeObject(itemToAdd, childItems));
|
61
|
+
items.push(...childItems);
|
62
|
+
} else {
|
63
|
+
items.push(node);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return items;
|
67
|
+
};
|
68
|
+
|
69
|
+
return getItemsFromTree({ folder: DOCS_FOLDER, childs: metadata });
|
70
|
+
}
|
71
|
+
|
72
|
+
export async function execute() {
|
73
|
+
const components = Object.keys(helpers);
|
74
|
+
const nodes = getMetadataFromContext(components);
|
75
|
+
|
76
|
+
for (const node of nodes) {
|
77
|
+
for (const component of components) {
|
78
|
+
const filename = node.hasChilds
|
79
|
+
? `${node.path}/intro.md`
|
80
|
+
: `${node.path}/${node.name}.md`;
|
81
|
+
const items = node[component];
|
82
|
+
if (items?.length > 0) {
|
83
|
+
const helper = helpers[component];
|
84
|
+
await helper.execute(items, filename, node.path);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
*/
|
93
|
+
/**
|
94
|
+
* example json
|
95
|
+
*
|
96
|
+
"process-name": {
|
97
|
+
"classes": string:[],
|
98
|
+
"objects": string:[]
|
99
|
+
},
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
[
|
104
|
+
{
|
105
|
+
"name": "modulo",
|
106
|
+
"description": "descripcion del modulo",
|
107
|
+
"components": [
|
108
|
+
{
|
109
|
+
"name": "",
|
110
|
+
"description": "descripcion del item",
|
111
|
+
"path": "folder-name-only",
|
112
|
+
"objects": [ "", ""],
|
113
|
+
"classes": [ "", ""],
|
114
|
+
"lwc": [ "", ""]
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
]
|
119
|
+
*/
|
@@ -0,0 +1,133 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
import sf from "./connect.js";
|
11
|
+
import templateGenerator from "./template.js";
|
12
|
+
const templateEngine = templateGenerator("dictionary", "md");
|
13
|
+
import { sortByLabel, DICTIONARY_FOLDER, DOCS_FOLDER, } from "./util.js";
|
14
|
+
function getMetadata(objetos) {
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
16
|
+
try {
|
17
|
+
yield sf.connect();
|
18
|
+
const objects = yield sf.customObjects(objetos);
|
19
|
+
return Array.isArray(objects) ? objects : [objects];
|
20
|
+
}
|
21
|
+
catch (e) {
|
22
|
+
console.error(e);
|
23
|
+
}
|
24
|
+
return [];
|
25
|
+
});
|
26
|
+
}
|
27
|
+
function descriptionFormula() {
|
28
|
+
var _a;
|
29
|
+
return (_a = this.description) === null || _a === void 0 ? void 0 : _a.replaceAll(/[\n\r]/g, "<br/>");
|
30
|
+
}
|
31
|
+
function isManaged() {
|
32
|
+
return this.fullName.split("__").length == 3;
|
33
|
+
}
|
34
|
+
function isMetadataFormula() {
|
35
|
+
var _a;
|
36
|
+
return ((_a = this.fullName) === null || _a === void 0 ? void 0 : _a.endsWith("__mdt")) || this.customSettingsType;
|
37
|
+
}
|
38
|
+
function attributesFormula() {
|
39
|
+
const attributes = [];
|
40
|
+
// Object Attributes
|
41
|
+
if (this.enableHistory === "true") {
|
42
|
+
attributes.push(``);
|
43
|
+
}
|
44
|
+
// "enableActivities": "true",
|
45
|
+
// "enableBulkApi": "true",
|
46
|
+
// "enableChangeDataCapture": "false",
|
47
|
+
// "enableFeeds": "false",
|
48
|
+
// "enableHistory": "true",
|
49
|
+
// "enableReports": "true",
|
50
|
+
// "enableSearch": "false",
|
51
|
+
// "enableSharing": "true",
|
52
|
+
// "enableStreamingApi": "true",
|
53
|
+
// "externalSharingModel": "Private",
|
54
|
+
// Field Attributes
|
55
|
+
if (this.required === "true") {
|
56
|
+
attributes.push(``);
|
57
|
+
}
|
58
|
+
if (this.trackHistory === "true") {
|
59
|
+
attributes.push(``);
|
60
|
+
}
|
61
|
+
// if ( this.inlineHelpText ) {
|
62
|
+
// attributes.push( `` );
|
63
|
+
// }
|
64
|
+
if (this.externalId === "true") {
|
65
|
+
attributes.push(``);
|
66
|
+
}
|
67
|
+
if (this.encrypted === "true") {
|
68
|
+
attributes.push(``);
|
69
|
+
}
|
70
|
+
return attributes.join(" ");
|
71
|
+
}
|
72
|
+
function typeFormula() {
|
73
|
+
if (this.formula) {
|
74
|
+
return `Formula(${this.type})`;
|
75
|
+
}
|
76
|
+
if (this.type === "Lookup" || this.type === "MasterDetail") {
|
77
|
+
return `[Lookup a ${this.referenceTo}](/diccionarios/objects/${this.referenceTo})`;
|
78
|
+
}
|
79
|
+
if (this.length || this.precision) {
|
80
|
+
const longitud = (this.length || this.precision) +
|
81
|
+
(this.scale && this.scale > 0 ? "." + this.scale : "");
|
82
|
+
return `${this.type}(${longitud})`;
|
83
|
+
}
|
84
|
+
return this.type;
|
85
|
+
}
|
86
|
+
function getObjects(files) {
|
87
|
+
const items = new Set();
|
88
|
+
for (const file of files) {
|
89
|
+
let desde = file.indexOf("/objects/");
|
90
|
+
if (desde !== -1) {
|
91
|
+
desde += 9; // se desplaza hasta el proximo slash
|
92
|
+
const hasta = file.indexOf("/", desde + 1);
|
93
|
+
const objectName = file.substring(desde, hasta);
|
94
|
+
items.add(objectName);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
return [...items.values()];
|
98
|
+
}
|
99
|
+
function executeObjects(items, filename, folder) {
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
101
|
+
if (items.length === 0) {
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
// Busca la metadata
|
105
|
+
const contexts = yield getMetadata(items);
|
106
|
+
if (!contexts || contexts.length === 0) {
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
// Arma el diccionario de cada Objeto
|
110
|
+
templateEngine.read("object");
|
111
|
+
for (const context of contexts) {
|
112
|
+
if (context.fullName) {
|
113
|
+
templateEngine.render(context, {
|
114
|
+
helpers: { isManaged, descriptionFormula, typeFormula, attributesFormula }
|
115
|
+
});
|
116
|
+
templateEngine.save(context.fullName, DICTIONARY_FOLDER + "/objects");
|
117
|
+
}
|
118
|
+
}
|
119
|
+
// Arma el documento indice del grupo de objetos
|
120
|
+
contexts.sort(sortByLabel);
|
121
|
+
templateEngine.read("objects");
|
122
|
+
const objectContext = { objects: contexts };
|
123
|
+
templateEngine.render(objectContext, {
|
124
|
+
helpers: { isManaged, isMetadataFormula, attributesFormula }
|
125
|
+
});
|
126
|
+
templateEngine.save(filename, DOCS_FOLDER + "/" + folder);
|
127
|
+
});
|
128
|
+
}
|
129
|
+
const objectModule = {
|
130
|
+
getItems: getObjects,
|
131
|
+
execute: executeObjects
|
132
|
+
};
|
133
|
+
export default objectModule;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function getCommitMessage(): Promise<string | null>;
|
@@ -0,0 +1,53 @@
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8
|
+
});
|
9
|
+
};
|
10
|
+
import OpenAI from 'openai';
|
11
|
+
const client = new OpenAI({
|
12
|
+
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
|
13
|
+
});
|
14
|
+
export function getCommitMessage() {
|
15
|
+
var _a;
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
17
|
+
if (process.env['OPENAI_API_KEY']) {
|
18
|
+
const params = {
|
19
|
+
messages: [{ role: 'user', content: 'Say this is a test' }],
|
20
|
+
model: 'gpt-3.5-turbo',
|
21
|
+
};
|
22
|
+
const chatCompletion = yield client.chat.completions.create(params);
|
23
|
+
return (_a = chatCompletion.choices[0].message) === null || _a === void 0 ? void 0 : _a.content;
|
24
|
+
}
|
25
|
+
return null;
|
26
|
+
});
|
27
|
+
}
|
28
|
+
/*
|
29
|
+
// getCommitMessage();
|
30
|
+
{
|
31
|
+
model,
|
32
|
+
messages: [
|
33
|
+
{
|
34
|
+
role: 'system',
|
35
|
+
content: generatePrompt(locale, maxLength, type),
|
36
|
+
},
|
37
|
+
{
|
38
|
+
role: 'user',
|
39
|
+
content: diff,
|
40
|
+
},
|
41
|
+
],
|
42
|
+
temperature: 0.7,
|
43
|
+
top_p: 1,
|
44
|
+
frequency_penalty: 0,
|
45
|
+
presence_penalty: 0,
|
46
|
+
max_tokens: 200,
|
47
|
+
stream: false,
|
48
|
+
n: completions,
|
49
|
+
},
|
50
|
+
timeout,
|
51
|
+
proxy
|
52
|
+
);
|
53
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import type { IStepCommand, IStepFunction } from "../types/helpers/tasks.js";
|
2
|
+
import { AnyValue } from "../types/auto.js";
|
3
|
+
export declare function executeCommand(step: IStepCommand): Promise<boolean>;
|
4
|
+
export declare function validateCommand(step: IStepCommand): boolean;
|
5
|
+
export declare function validateFunction(step: IStepFunction): boolean;
|
6
|
+
export declare function getCurrentOrganization(): OrganizationInfo;
|
7
|
+
export declare function getOrganizationObject(alias: string, type?: string): OrganizationInfo;
|
8
|
+
export declare function getTargetOrg(): string;
|
9
|
+
export declare function getBranchName(): string;
|
10
|
+
export declare function executeFunction(step: IStepFunction): Promise<boolean>;
|
11
|
+
export declare function executeShell(command: string): string;
|
12
|
+
export declare const taskFunctions: {
|
13
|
+
[s: string]: AnyValue;
|
14
|
+
};
|